From: Steve Sutton Date: Tue, 3 Apr 2018 20:15:46 +0000 (-0400) Subject: Update for cron task X-Git-Tag: v1.0.0^2~78 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=5f2d18377f0d251aed730465644b7cc6aff380fc;p=WP-Plugins%2Fglm-member-db-billing.git Update for cron task update cron task to get accounts by renewal dates. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 4d67f73..84c42bc 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -538,6 +538,22 @@ class GlmBillingSupport ); } + /** + * Get all accounts with renewal dates on days before or after number of days. + * + * @param int $days Days before or after + * @param boolean $before Boolean: true -> before, false -> after + */ + public function getAccountsRenewing( $days, $before = true ) + { + $curDate = date( 'Y-m-d' ); + return $this->wpdb->get_results( + "SELECT * + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE renewal_date + INTERVAL 1 YEAR " . ($before ? '-' : '+' ) . " $days DAY <= '$curDate'" + ); + } + /** * getUnPaidInvoices * diff --git a/models/admin/ajax/setupQueue.php b/models/admin/ajax/setupQueue.php index be12d8b..fec9a79 100644 --- a/models/admin/ajax/setupQueue.php +++ b/models/admin/ajax/setupQueue.php @@ -76,63 +76,67 @@ class GlmMembersAdmin_ajax_setupQueue // Get all invoices that are unpaid. $billingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - $unpaid_invoices = $billingSupport->getUnPaidInvoices(); - echo '
$unpaid_invoices: ' . print_r( $unpaid_invoices, true ) . '
'; + //$unpaid_invoices = $billingSupport->getUnPaidInvoices(); + //echo '
$unpaid_invoices: ' . print_r( $unpaid_invoices, true ) . '
'; + + foreach ( $notifications as $notice ) { + echo '
$notice: ' . print_r( $notice, true ) . '
'; + } // Loop through the invoices and for each one see if any notices are to be sent out. $currentDate = new DateTime(); echo '
$currentDate: ' . print_r( $currentDate, true ) . '
'; - foreach ( $unpaid_invoices as $invoice ) { - $due_date = $invoice['due_date']; - - // Loop through the notifications and see if this unpaid one is due. - foreach ( $notifications as $notice ) { - // Need due date set in this loop each time. - $dueDate = new DateTime( $due_date ); - // Is this before or after - switch ( $notice['send_date_when'] ) { - case $this->config['send_date_when_numb']['Before']: - echo '

Before

'; - $dueDate->modify( - '-' . $notice['send_date_number'] . ' '. - $this->config['send_date_period'][$notice['send_date_period']] . - (($notice['send_date_number'] > 1) ? 's': '') - ); - echo '
$dueDate: ' . print_r( $dueDate, true ) . '
'; - $diff = $dueDate->diff( $currentDate ); - // When the diff is 0 days then the notice needs to go out. - - $days_from = $diff->format( '%a' ); - echo '
$days_from: ' . print_r( $days_from, true ) . '
'; - // Check to see if this date occurs today. - if ( $days_from === '0' ) { - // Add the notice id and account id to the queue - $Notifications->queueNotice( $notice['id'], $invoice['account'] ); - } - - break; - case $this->config['send_date_when_numb']['After']: - echo '

After

'; - $dueDate->modify( - '+' . $notice['send_date_number'] . ' '. - $this->config['send_date_period'][$notice['send_date_period']] . - (($notice['send_date_number'] > 1) ? 's': '') - ); - echo '
$dueDate: ' . print_r( $dueDate, true ) . '
'; - $diff = $dueDate->diff( $currentDate ); - $days_from = $diff->format( '%a' ); - echo '
$days_from: ' . print_r( $days_from, true ) . '
'; - // Check to see if this date occurs today. - if ( $days_from === '0' ) { - // Create the notice email - $Notifications->queueNotice( $notice['id'], $invoice['account'] ); - } - break; - default: - break; - } - } - } + // foreach ( $unpaid_invoices as $invoice ) { + // $due_date = $invoice['due_date']; + // + // // Loop through the notifications and see if this unpaid one is due. + // foreach ( $notifications as $notice ) { + // // Need due date set in this loop each time. + // $dueDate = new DateTime( $due_date ); + // // Is this before or after + // switch ( $notice['send_date_when'] ) { + // case $this->config['send_date_when_numb']['Before']: + // echo '

Before

'; + // $dueDate->modify( + // '-' . $notice['send_date_number'] . ' '. + // $this->config['send_date_period'][$notice['send_date_period']] . + // (($notice['send_date_number'] > 1) ? 's': '') + // ); + // echo '
$dueDate: ' . print_r( $dueDate, true ) . '
'; + // $diff = $dueDate->diff( $currentDate ); + // // When the diff is 0 days then the notice needs to go out. + // + // $days_from = $diff->format( '%a' ); + // echo '
$days_from: ' . print_r( $days_from, true ) . '
'; + // // Check to see if this date occurs today. + // if ( $days_from === '0' ) { + // // Add the notice id and account id to the queue + // $Notifications->queueNotice( $notice['id'], $invoice['account'] ); + // } + // + // break; + // case $this->config['send_date_when_numb']['After']: + // echo '

After

'; + // $dueDate->modify( + // '+' . $notice['send_date_number'] . ' '. + // $this->config['send_date_period'][$notice['send_date_period']] . + // (($notice['send_date_number'] > 1) ? 's': '') + // ); + // echo '
$dueDate: ' . print_r( $dueDate, true ) . '
'; + // $diff = $dueDate->diff( $currentDate ); + // $days_from = $diff->format( '%a' ); + // echo '
$days_from: ' . print_r( $days_from, true ) . '
'; + // // Check to see if this date occurs today. + // if ( $days_from === '0' ) { + // // Create the notice email + // $Notifications->queueNotice( $notice['id'], $invoice['account'] ); + // } + // break; + // default: + // break; + // } + // } + // } wp_die(); }