CRM-13786 Applying updated patch from Karin which fixes the calculation of start...
authorDave Greenberg <dave@civicrm.org>
Wed, 20 Nov 2013 23:34:39 +0000 (15:34 -0800)
committerDave Greenberg <dave@civicrm.org>
Wed, 20 Nov 2013 23:34:39 +0000 (15:34 -0800)
----------------------------------------
* 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

index e6e25b40ef62cb31deb3a83e077c812051d7ee41..05fb74ed21cf981c8e45c45fde00a2ce11f328e8 100644 (file)
@@ -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,