billing setup queue need to check the period of time.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 3 May 2018 20:49:50 +0000 (16:49 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 3 May 2018 20:49:50 +0000 (16:49 -0400)
Could be month or week.

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

index 5c4c642..ce3e2a0 100644 (file)
@@ -574,13 +574,28 @@ class GlmBillingSupport
      * @param int     $days   Days before or after
      * @param boolean $before Boolean: true -> before, false -> after
      */
-    public function getAccountsRenewing( $days, $before = true )
+    public function getAccountsRenewing( $count, $interval, $before = true )
     {
         $curDate = date( 'Y-m-d' );
+        switch ( $interval ) {
+        case '40':
+            $period = 'YEAR';
+            break;
+        case '30':
+            $period = 'MONTH';
+            break;
+        case '20':
+            $period = 'WEEK';
+            break;
+        case '10':
+        default:
+            $period = 'DAY';
+            break;
+        }
         return $this->wpdb->get_results(
             "SELECT *
                FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
-              WHERE renewal_date + INTERVAL 1 YEAR " . ($before ? '-' : '+' ) . " INTERVAL $days DAY = '$curDate'
+              WHERE renewal_date + INTERVAL 1 YEAR " . ($before ? '-' : '+' ) . " INTERVAL $count $period = '$curDate'
                 AND archived <> true",
             ARRAY_A
         );
index a4d1374..76738ce 100644 (file)
@@ -87,7 +87,7 @@ class GlmMembersAdmin_ajax_billingSetupQueue
                 $before = true;
                 break;
             }
-            $accounts = $billingSupport->getAccountsRenewing( $notice['send_date_number'], $before );
+            $accounts = $billingSupport->getAccountsRenewing( $notice['send_date_number'], $notice['send_date_period'], $before );
             echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
             // return false;
             if ( isset( $accounts ) && is_array( $accounts ) && !empty( $accounts ) ) {