Update for cron task
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 3 Apr 2018 20:15:46 +0000 (16:15 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 3 Apr 2018 20:15:46 +0000 (16:15 -0400)
update cron task to get accounts by renewal dates.

classes/billingSupport.php
models/admin/ajax/setupQueue.php

index 4d67f73..84c42bc 100644 (file)
@@ -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
      *
index be12d8b..fec9a79 100644 (file)
@@ -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 '<pre>$unpaid_invoices: ' . print_r( $unpaid_invoices, true ) . '</pre>';
+        //$unpaid_invoices = $billingSupport->getUnPaidInvoices();
+        //echo '<pre>$unpaid_invoices: ' . print_r( $unpaid_invoices, true ) . '</pre>';
+
+        foreach ( $notifications as $notice ) {
+            echo '<pre>$notice: ' . print_r( $notice, true ) . '</pre>';
+        }
 
         // Loop through the invoices and for each one see if any notices are to be sent out.
         $currentDate = new DateTime();
         echo '<pre>$currentDate: ' . print_r( $currentDate, true ) . '</pre>';
-        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 '<p>Before</p>';
-                    $dueDate->modify(
-                        '-' . $notice['send_date_number'] . ' '.
-                        $this->config['send_date_period'][$notice['send_date_period']] .
-                        (($notice['send_date_number'] > 1) ? 's': '')
-                    );
-                    echo '<pre>$dueDate: ' . print_r( $dueDate, true ) . '</pre>';
-                    $diff = $dueDate->diff( $currentDate );
-                    // When the diff is 0 days then the notice needs to go out.
-
-                    $days_from = $diff->format( '%a' );
-                    echo '<pre>$days_from: ' . print_r( $days_from, true ) . '</pre>';
-                    // 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 '<p>After</p>';
-                    $dueDate->modify(
-                        '+' . $notice['send_date_number'] . ' '.
-                        $this->config['send_date_period'][$notice['send_date_period']] .
-                        (($notice['send_date_number'] > 1) ? 's': '')
-                    );
-                    echo '<pre>$dueDate: ' . print_r( $dueDate, true ) . '</pre>';
-                    $diff = $dueDate->diff( $currentDate );
-                    $days_from = $diff->format( '%a' );
-                    echo '<pre>$days_from: ' . print_r( $days_from, true ) . '</pre>';
-                    // 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 '<p>Before</p>';
+        //             $dueDate->modify(
+        //                 '-' . $notice['send_date_number'] . ' '.
+        //                 $this->config['send_date_period'][$notice['send_date_period']] .
+        //                 (($notice['send_date_number'] > 1) ? 's': '')
+        //             );
+        //             echo '<pre>$dueDate: ' . print_r( $dueDate, true ) . '</pre>';
+        //             $diff = $dueDate->diff( $currentDate );
+        //             // When the diff is 0 days then the notice needs to go out.
+        //
+        //             $days_from = $diff->format( '%a' );
+        //             echo '<pre>$days_from: ' . print_r( $days_from, true ) . '</pre>';
+        //             // 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 '<p>After</p>';
+        //             $dueDate->modify(
+        //                 '+' . $notice['send_date_number'] . ' '.
+        //                 $this->config['send_date_period'][$notice['send_date_period']] .
+        //                 (($notice['send_date_number'] > 1) ? 's': '')
+        //             );
+        //             echo '<pre>$dueDate: ' . print_r( $dueDate, true ) . '</pre>';
+        //             $diff = $dueDate->diff( $currentDate );
+        //             $days_from = $diff->format( '%a' );
+        //             echo '<pre>$days_from: ' . print_r( $days_from, true ) . '</pre>';
+        //             // 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();
     }