From f7660a394456b4c72f57d8ae4047fcf81e23a3c5 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Wed, 20 Nov 2013 15:34:39 -0800 Subject: [PATCH] CRM-13786 Applying updated patch from Karin which fixes the calculation of start date and edndate for fixed memberships. All related BAO, api and Form unit tests passing now. ---------------------------------------- * CRM-13786: Membership End Date not calculated properly for fixed period MembershipTypes http://issues.civicrm.org/jira/browse/CRM-13786 --- CRM/Member/BAO/MembershipType.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index e6e25b40ef..05fb74ed21 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -306,6 +306,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { $toDay = explode('-', (empty($startDate) ? $joinDate : $startDate)); $year = $toDay[0]; $month = $toDay[1]; + $day = $toDay[2]; if ($membershipTypeDetails['duration_unit'] == 'year') { @@ -315,7 +316,12 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { ); $startDay = substr($membershipTypeDetails['fixed_period_start_day'], -2); - $fixedStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year)); + if (date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year)) <= date('Y-m-d', mktime(0, 0, 0, $month, $day, $year))) { + $fixedStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year)); + } + else { + $fixedStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year - 1)); + } //get start rollover day $rolloverMonth = substr($membershipTypeDetails['fixed_period_rollover_day'], 0, @@ -335,13 +341,6 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { //store original fixed rollover date as per current year. $actualRolloverDate = $fixedRolloverDate; - //make sure membership should not start in future. - if (!empty($startDate)) { - if ($startDate < $actualStartDate) { - $actualStartDate = date('Y-m-d', mktime(0, 0, 0, $startMonth, $startDay, $year - 1)); - } - } - //get the fixed end date here. $dateParts = explode('-', $actualStartDate); $fixedEndDate = date('Y-m-d', mktime(0, 0, 0, -- 2.25.1