From: Steve Sutton Date: Wed, 14 Mar 2018 12:29:14 +0000 (-0400) Subject: Update account next anniversary date. X-Git-Tag: v1.0.0^2~150 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=208de3a73979fccb278416d1f54bc7a1a8c94dcf;p=WP-Plugins%2Fglm-member-db-billing.git Update account next anniversary date. Fix date calculation for next occurrence of anniversary date. --- diff --git a/classes/data/dataAccounts.php b/classes/data/dataAccounts.php index 763ce68..df0b4cf 100644 --- a/classes/data/dataAccounts.php +++ b/classes/data/dataAccounts.php @@ -258,16 +258,26 @@ class GlmDataAccounts extends GlmDataAbstract public function entryPostProcessing($r, $a) { // Setup the accounts anniversary date + $current_date = mktime( 0, 0, 0, date( 'd' ), date( 'n' ), date( 'Y' ) ); if ( $r['anniversary_date'] ) { // Need to find the next (current) date for this account's // anniversary - $anniversary_date = new DateTime( $r['anniversary_date']['mysql_date'] ); - if ( $r['anniversary_date']['timestamp'] > time() ) { + if ( $r['anniversary_date']['timestamp'] >= time() ) { $r['next_anniversary_date'] = $r['anniversary_date']['date']; } else { - // Add one year to the anniversary date - $anniversary_date->modify('+1 year'); - $r['next_anniversary_date'] = $anniversary_date->format('m/d/Y'); + // Need to get the next occurrence of the date. + $anniversary = strtotime( $r['anniversary_date']['mysql_date'] ); + // Make the year current year. + $year = date( 'Y' ); + // If the month and day have already occurred then add a year. + $test_date = mktime( 0, 0, 0, date( 'n', $anniversary ), date( 'd', $anniversary ), $year ); + if ( $test_date <= $current_date ) { + $test_date = mktime( 0, 0, 0, date( 'n', $anniversary ), date( 'd', $anniversary ), $year ); + } + $r['next_anniversary_date'] = date( 'm/d/Y', $test_date); + // $anniversary_date = new DateTime( $r['anniversary_date']['mysql_date'] ); + // $anniversary_date->modify('+1 year'); + // $r['next_anniversary_date'] = $anniversary_date->format('m/d/Y'); } } return $r;