Skip to content

Commit

Permalink
Merge pull request #8226 from jitendrapurohit/CRM-18000
Browse files Browse the repository at this point in the history
CRM-18000: Membership Batch Data Entry: Renewal not working
  • Loading branch information
monishdeb committed Apr 26, 2016
2 parents d8a0b05 + 55d094e commit a67e012
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ private function processMembership(&$params) {

foreach ($dateTypes as $dateField => $dateVariable) {
$$dateVariable = CRM_Utils_Date::processDate($value[$dateField]);
$fDate[$dateField] = CRM_Utils_Array::value($dateField, $value);
}

$calcDates = array();
Expand Down Expand Up @@ -806,12 +807,16 @@ private function processMembership(&$params) {
}
}
foreach (array('join_date', 'start_date', 'end_date') as $dateType) {
$formDates[$dateType] = CRM_Utils_Array::value($dateType, $value);
//CRM-18000 - ignore $dateType if its not explicitly passed
if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) {
$formDates[$dateType] = CRM_Utils_Array::value($dateType, $value);
}
}
$membershipSource = CRM_Utils_Array::value('source', $value);
list($membership) = CRM_Member_BAO_Membership::renewMembership(
$value['contact_id'], $value['membership_type_id'], FALSE,
NULL, NULL, $value['custom'], NULL, NULL, FALSE,
//$numTerms should be default to 1.
NULL, NULL, $value['custom'], 1, NULL, FALSE,
NULL, $membershipSource, $isPayLater, $campaignId, $formDates
);

Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/CRM/Batch/Form/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ public function setUp() {
$membershipType = $this->callAPISuccess('membership_type', 'create', $params);
$this->_membershipTypeID = $membershipType['id'];

$this->_orgContactID2 = $this->organizationCreate();
$params = array(
'name' => 'General',
'duration_unit' => 'year',
'duration_interval' => 1,
'period_type' => 'rolling',
'member_of_contact_id' => $this->_orgContactID2,
'domain_id' => 1,
'financial_type_id' => 1,
'is_active' => 1,
'sequential' => 1,
'visibility' => 'Public',
);
$membershipType2 = $this->callAPISuccess('membership_type', 'create', $params);
$this->_membershipTypeID2 = $membershipType2['id'];

$this->_membershipStatusID = $this->membershipStatusCreate('test status');
$this->_contactID = $this->individualCreate();
$contact2Params = array(
Expand Down Expand Up @@ -188,6 +204,50 @@ public function testProcessContribution() {
}
}

/**
* CRM-18000 - Test start_date, end_date after renewal
*/
public function testMembershipRenewalDates() {
$form = new CRM_Batch_Form_Entry();
foreach (array($this->_contactID, $this->_contactID2) as $contactID) {
$membershipParams = array(
'membership_type_id' => $this->_membershipTypeID2,
'contact_id' => $contactID,
'start_date' => "01/01/2015",
'join_date' => "01/01/2010",
'end_date' => "12/31/2015",
);
$this->contactMembershipCreate($membershipParams);
}

$params = $this->getMembershipData();
//ensure membership renewal
$params['member_option'] = array(
1 => 2,
2 => 2,
);
$params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2);
$params['field'][1]['receive_date'] = date('Y-m-d');

// explicitly specify start and end dates
$params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2, 1 => $this->_membershipTypeID2);
$params['field'][2]['membership_start_date'] = "04/01/2016";
$params['field'][2]['membership_end_date'] = "03/31/2017";
$params['field'][2]['receive_date'] = "04/01/2016";

$this->assertTrue($form->testProcessMembership($params));
$result = $this->callAPISuccess('membership', 'get', array());

// renewal dates should be from current if start_date and end_date is passed as NULL
$this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']);
$endDate = date("Y-m-d", strtotime(date("Y-m-d") . " +1 year -1 day"));
$this->assertEquals($endDate, $result['values'][1]['end_date']);

// verify if the modified dates asserts with the dates passed above
$this->assertEquals('2016-04-01', $result['values'][2]['start_date']);
$this->assertEquals('2017-03-31', $result['values'][2]['end_date']);
}

/**
* Data provider for test process membership.
* @return array
Expand Down

0 comments on commit a67e012

Please sign in to comment.