From 87ad884ae1fac8b90640e1f9b2fa4b59ece35dd6 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 27 Jan 2015 14:59:14 +1300 Subject: [PATCH] CRM-15798 function extraction on membership date calculation this is part of a big rebase to clean up PR for CRM-15798 post code-cleanup & it going stale --- CRM/Member/BAO/MembershipType.php | 110 +++++++++++++++++------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index b5f4dd3eec..1f51e3f63a 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -77,7 +77,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { * Value we want to set the is_active field. * * @return Object - * DAO object on sucess, null otherwise + * DAO object on success, null otherwise */ public static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', $id, 'is_active', $is_active); @@ -287,9 +287,9 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { * * @param int $membershipTypeId * Membership type id. - * @param date $joinDate + * @param string $joinDate * Member since ( in mysql date format ). - * @param date $startDate + * @param string $startDate * Start date ( in mysql date format ). * @param null $endDate * @param int $numRenewTerms @@ -348,46 +348,8 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { 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, - strlen($membershipTypeDetails['fixed_period_rollover_day']) - 2 - ); - $rolloverDay = substr($membershipTypeDetails['fixed_period_rollover_day'], -2); - - $fixedRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year)); - - //CRM-7825 -membership date rules are : - //1. Membership should not be start in future. - //2. rollover window should be subset of membership window. - - //store original fixed start date as per current year. $actualStartDate = $fixedStartDate; - - //store original fixed rollover date as per current year. - $actualRolloverDate = $fixedRolloverDate; - - //get the fixed end date here. - $dateParts = explode('-', $actualStartDate); - $fixedEndDate = date('Y-m-d', mktime(0, 0, 0, - $dateParts[1], - $dateParts[2] - 1, - $dateParts[0] + ($numRenewTerms * $membershipTypeDetails['duration_interval']) - )); - - //make sure rollover window should be - //subset of membership period window. - if ($fixedEndDate < $actualRolloverDate) { - $actualRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year - 1)); - } - if ($actualRolloverDate < $actualStartDate) { - $actualRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year + 1)); - } - - //do check signup is in rollover window. - if ($actualRolloverDate <= $joinDate) { - $fixed_period_rollover = TRUE; - } + $fixed_period_rollover = self::isDuringFixedAnnualRolloverPeriod($joinDate, $numRenewTerms, $membershipTypeDetails, $year, $fixedStartDate); if (!$startDate) { $startDate = $actualStartDate; @@ -466,6 +428,62 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { return $membershipDates; } + /** + * Does this membership start between the rollover date and the start of the next period + * (in which case they will get an extra membership period) + * ie if annual memberships run June - May & the rollover is in May memberships between + * May and June will return TRUE and between June and May will return FALSE + * + * @param string $startDate start date of current membership period + * @param integer $numRenewTerms + * @param array $membershipTypeDetails + * @param integer $year + * @param $fixedStartDate + * @return bool is this in the window where the membership gets an extra part-period added + */ + protected static function isDuringFixedAnnualRolloverPeriod($startDate, $numRenewTerms, $membershipTypeDetails, $year, $fixedStartDate) { + + $rolloverMonth = substr($membershipTypeDetails['fixed_period_rollover_day'], 0, + strlen($membershipTypeDetails['fixed_period_rollover_day']) - 2 + ); + $rolloverDay = substr($membershipTypeDetails['fixed_period_rollover_day'], -2); + + $fixedRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year)); + + //CRM-7825 -membership date rules are : + //1. Membership should not be start in future. + //2. rollover window should be subset of membership window. + + //store original fixed start date as per current year. + $actualStartDate = $fixedStartDate; + + //store original fixed rollover date as per current year. + $actualRolloverDate = $fixedRolloverDate; + + //get the fixed end date here. + $dateParts = explode('-', $actualStartDate); + $fixedEndDate = date('Y-m-d', mktime(0, 0, 0, + $dateParts[1], + $dateParts[2] - 1, + $dateParts[0] + ($numRenewTerms * $membershipTypeDetails['duration_interval']) + )); + + //make sure rollover window should be + //subset of membership period window. + if ($fixedEndDate < $actualRolloverDate) { + $actualRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year - 1)); + } + if ($actualRolloverDate < $actualStartDate) { + $actualRolloverDate = date('Y-m-d', mktime(0, 0, 0, $rolloverMonth, $rolloverDay, $year + 1)); + } + + //do check signup is in rollover window. + if ($actualRolloverDate <= $startDate) { + return TRUE; + } + return FALSE; + } + /** * Calculate start date and end date for renewal membership * @@ -623,7 +641,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { } /** - * The function returns all the Organization for all membershiptypes . + * The function returns all the Organization for all membershipTypes . * * @param int $membershipTypeId * @@ -646,7 +664,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { } /** - * Funtion to retrieve organization and associated membership + * Function to retrieve organization and associated membership * types * * @return array @@ -756,9 +774,9 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { * This function updates all price field value for quick config * price set which has membership type * - * @param int $membershipTypeId membership type id + * @param int $membershipTypeId membership type id * - * @param array $params + * @param array $params */ public static function updateAllPriceFieldValue($membershipTypeId, $params) { if (!empty($params['minimum_fee'])) { -- 2.25.1