From: Steve Sutton Date: Tue, 3 Sep 2019 12:27:12 +0000 (-0400) Subject: Correction on renewal date reset X-Git-Tag: v1.0.35^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=9c9d05a6a60803a66d41ac2f2963e581e5cba85b;p=WP-Plugins%2Fglm-member-db-billing.git Correction on renewal date reset Always keep the same day and month of previous renewal date. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 7fc9d7c..83bb600 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1536,9 +1536,35 @@ class GlmBillingSupport */ public function updateAccountRenewalDate( $account ) { + $days_after_expired = $this->config['days_after_expired']; + $days_before_renewal = $this->config['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 ( $test_renewal_date->getTimestamp() < $earliest_date->getTimestamp() ) { + // Adjust the year. + $new_renewal_date = ( date( 'Y' ) - 1 ) . $the_rest; + } + $this->wpdb->update( GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', - array( 'renewal_date' => date( 'Y-m-d' ) ), + array( 'renewal_date' => $new_renewal_date ), array( 'id' => $account ), array( '%s' ), array( '%d' ) diff --git a/index.php b/index.php index d1bd2f9..347a6a4 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Members Billing * Plugin URI: http://www.gaslightmedia.com/ * Description: This is glmAssociate Billing Module - * Version: 1.0.34 + * Version: 1.0.35 * Author: Gaslight Media * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +19,7 @@ * @package glmMembersBillingAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.0.34 + * @version 1.0.35 */ /* @@ -37,7 +37,7 @@ * 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.34'); +define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.35'); // Database Version define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26');