Merge tag 'v1.0.37' into develop
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 30 Sep 2019 17:36:18 +0000 (13:36 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 30 Sep 2019 17:36:18 +0000 (13:36 -0400)
Version 1.0.37

1  2 
classes/billingSupport.php
index.php

@@@ -1782,50 -1536,28 +1782,46 @@@ class GlmBillingSuppor
       */
      public function updateAccountRenewalDate( $account )
      {
 +        // Get billing Settings for the renewal dates.
 +        $renewal_day_static  = $this->config['settings']['renewal_day_static'];
 +        $renewal_day         = $this->config['settings']['renewal_day'];
 +        $renewal_month       = $this->config['settings']['renewal_month'];
          $days_after_expired  = $this->config['settings']['days_after_expired'];
          $days_before_renewal = $this->config['settings']['days_before_renewal'];
 -        // Grab current renewal date
 -        $current_renewal_date = $this->wpdb->get_var(
 -            $this->wpdb->prepare(
 -                "SELECT renewal_date
 -                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
 -                 WHERE id = %d",
 -                $account
 -            )
 -        );
 -        if ( $current_renewal_date ) {
 -            $renewal_date = new DateTime( $current_renewal_date );
 -            // Get earliest date this one can renewal with.
 -            $earliest_date = $renewal_date->modify( '-' . $days_before_renewal . ' days + 1 year' );
 -            $year_part = substr( $current_renewal_date, 0, 4 );
 -            $the_rest  = substr( $current_renewal_date, 4 );
 -            // Adjust the year to current year
 -            $new_renewal_date = date( 'Y' ) . $the_rest;
 -            $test_renewal_date = new DateTime( $new_renewal_date );
 +        if ( $renewal_day_static ) {
 +            // If the renewal days are alway the same then use that date.
 +            $new_renewal_date = date(
 +                'Y-m-d',
 +                mktime(
 +                    0, 0, 0,
 +                    $renewal_day_static,
 +                    $renewal_month,
 +                    date( 'Y' )
 +                )
 +            );
          } else {
 -            $new_renewal_date = date( 'Y-m-d' );
 +            // Calculate the renewal date base on last renewal date.
 +            // Grab current renewal date
 +            $current_renewal_date = $this->wpdb->get_var(
 +                $this->wpdb->prepare(
 +                    "SELECT renewal_date
 +                      FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
 +                     WHERE id = %d",
 +                    $account
 +                )
 +            );
 +            if ( $current_renewal_date ) {
 +                $renewal_date = new DateTime( $current_renewal_date );
 +                // Get earliest date this one can renewal with.
 +                $earliest_date = $renewal_date->modify( '-' . $days_before_renewal . ' days + 1 year' );
 +                $year_part = substr( $current_renewal_date, 0, 4 );
 +                $the_rest  = substr( $current_renewal_date, 4 );
 +                // Adjust the year to current year
 +                $new_renewal_date = date( 'Y' ) . $the_rest;
 +                $test_renewal_date = new DateTime( $new_renewal_date );
-                 if ( $test_renewal_date->getTimestamp() < $earliest_date->getTimestamp() ) {
-                     // Adjust the year.
-                     $new_renewal_date = ( date( 'Y' ) - 1 ) . $the_rest;
-                 }
 +            } else {
 +                $new_renewal_date = date( 'Y-m-d' );
 +            }
          }
  
          $this->wpdb->update(
diff --cc index.php
+++ b/index.php
   *  so that we're sure the other add-ons see an up to date
   *  version from this plugin.
   */
- define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.36');
+ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.37');
  
  // Database Version
 -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26');
 +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.40');
  
  // This is the minimum version of the GLM Members DB plugin require for this plugin.
  define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0');