Skip to content

Commit

Permalink
Merge pull request #10803 from jitendrapurohit/CRM-20913-sync-ov
Browse files Browse the repository at this point in the history
CRM-20913 use pledge option group for pledge payments
  • Loading branch information
eileenmcnaughton authored Aug 2, 2017
2 parents 10a1f94 + 771b9ef commit a4ba5f5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 49 deletions.
22 changes: 11 additions & 11 deletions CRM/Pledge/BAO/PledgePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,28 @@ public static function getPledgePayments($pledgeId) {
*/
public static function create($params) {
$transaction = new CRM_Core_Transaction();
$contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$overdueStatusID = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_PledgePayment', 'status_id', 'Overdue');
$pendingStatusId = CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_PledgePayment', 'status_id', 'Pending');

//calculate the scheduled date for every installment
$now = date('Ymd') . '000000';
$statues = $prevScheduledDate = array();
$prevScheduledDate[1] = CRM_Utils_Date::processDate($params['scheduled_date']);

if (CRM_Utils_Date::overdue($prevScheduledDate[1], $now)) {
$statues[1] = array_search('Overdue', $contributionStatus);
$statues[1] = $overdueStatusID;
}
else {
$statues[1] = array_search('Pending', $contributionStatus);
$statues[1] = $pendingStatusId;
}

for ($i = 1; $i < $params['installments']; $i++) {
$prevScheduledDate[$i + 1] = self::calculateNextScheduledDate($params, $i);
if (CRM_Utils_Date::overdue($prevScheduledDate[$i + 1], $now)) {
$statues[$i + 1] = array_search('Overdue', $contributionStatus);
$statues[$i + 1] = $overdueStatusID;
}
else {
$statues[$i + 1] = array_search('Pending', $contributionStatus);
$statues[$i + 1] = $pendingStatusId;
}
}

Expand Down Expand Up @@ -605,14 +606,12 @@ public static function calculateNextScheduledDate(&$params, $paymentNo, $basePay
*/
public static function calculatePledgeStatus($pledgeId) {
$paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$pledgeStatusTypes = CRM_Core_OptionGroup::values('pledge_status',
FALSE, FALSE, FALSE, NULL, 'name', TRUE
);
$pledgeStatusTypes = CRM_Pledge_BAO_Pledge::buildOptions('status_id', 'validate');

//return if the pledge is cancelled.
$currentPledgeStatus = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'status_id', 'id', TRUE);
if ($currentPledgeStatus == array_search('Cancelled', $pledgeStatusTypes)) {
return $currentPledgeStatus;
$currentPledgeStatusId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'status_id', 'id', TRUE);
if ($currentPledgeStatusId == array_search('Cancelled', $pledgeStatusTypes)) {
return $currentPledgeStatusId;
}

// retrieve all pledge payments for this particular pledge
Expand Down Expand Up @@ -901,6 +900,7 @@ public static function adjustPledgePayment($pledgeID, $actualAmount, $pledgeSche
public static function buildOptions($fieldName, $context = NULL, $props = array()) {
$result = parent::buildOptions($fieldName, $context, $props);
if ($fieldName == 'status_id') {
$result = CRM_Pledge_BAO_Pledge::buildOptions($fieldName, $context, $props);
$result = array_diff($result, array('Failed', 'In Progress'));
}
return $result;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Upgrade/Incremental/sql/4.7.24.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ INSERT INTO `civicrm_option_value` (`option_group_id`, {localize field='label'}`
(@option_group_id_ps, {localize}'{ts escape="sql"}Pending{/ts}'{/localize} , 2, 'Pending', NULL, 2),
(@option_group_id_ps, {localize}'{ts escape="sql"}Cancelled{/ts}'{/localize} , 3, 'Cancelled', NULL, 3),
(@option_group_id_ps, {localize}'{ts escape="sql"}In Progress{/ts}'{/localize}, 4, 'In Progress', NULL, 4),
(@option_group_id_ps, {localize}'{ts escape="sql"}Overdue{/ts}'{/localize} , 5, 'Overdue', NULL, 5);
(@option_group_id_ps, {localize}'{ts escape="sql"}Overdue{/ts}'{/localize} , 6, 'Overdue', NULL, 5);
58 changes: 29 additions & 29 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions tests/phpunit/api/v3/PledgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,8 @@ public function testGetOverduePledge() {
'start_date' => 'first saturday of march last year',
);
$this->_pledge = $this->callAPISuccess('pledge', 'create', array_merge($this->_params, $overdueParams));
$pledgeStatuses = CRM_Core_OptionGroup::values('pledge_status',
FALSE, FALSE, FALSE, NULL, 'name'
);
$params = array(
'pledge_status_id' => array_search('Overdue', $pledgeStatuses),
);
$result = $this->callAPISuccess('pledge', 'get', $params);

$result = $this->callAPISuccess('pledge', 'get', array('status_id' => 'Overdue'));
$emptyResult = $this->callAPISuccess('pledge', 'get', array(
'pledge_status_id' => '1',
));
Expand Down
2 changes: 1 addition & 1 deletion xml/templates/civicrm_data.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ VALUES
(@option_group_id_ps, '{ts escape="sql"}Pending{/ts}' , 2, 'Pending' , NULL, 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_ps, '{ts escape="sql"}Cancelled{/ts}' , 3, 'Cancelled' , NULL, 0, NULL, 3, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_ps, '{ts escape="sql"}In Progress{/ts}', 4, 'In Progress', NULL, 0, NULL, 4, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_ps, '{ts escape="sql"}Overdue{/ts}' , 5, 'Overdue' , NULL, 0, NULL, 5, NULL, 0, 1, 1, NULL, NULL, NULL);
(@option_group_id_ps, '{ts escape="sql"}Overdue{/ts}' , 6, 'Overdue' , NULL, 0, NULL, 5, NULL, 0, 1, 1, NULL, NULL, NULL);

-- financial accounts
SELECT @opval := value FROM civicrm_option_value WHERE name = 'Revenue' and option_group_id = @option_group_id_fat;
Expand Down

0 comments on commit a4ba5f5

Please sign in to comment.