Skip to content

Commit

Permalink
CRM-17151 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Oct 20, 2017
1 parent c996fa0 commit eb9e473
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 224 deletions.
33 changes: 22 additions & 11 deletions CRM/Price/BAO/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,17 +1061,22 @@ protected function _updateEntityRecordOnChangeFeeSelection($inputParams, $entity
*
*/
protected function _getRelatedCancelFinancialTrxn($financialItemID) {
$financialTrxn = civicrm_api3('EntityFinancialTrxn', 'getsingle', array(
'entity_table' => 'civicrm_financial_item',
'entity_id' => $financialItemID,
'options' => array(
'sort' => 'id DESC',
'limit' => 1,
),
'api.FinancialTrxn.getsingle' => array(
'id' => "\$value.financial_trxn_id",
),
));
try {
$financialTrxn = civicrm_api3('EntityFinancialTrxn', 'getsingle', array(
'entity_table' => 'civicrm_financial_item',
'entity_id' => $financialItemID,
'options' => array(
'sort' => 'id DESC',
'limit' => 1,
),
'api.FinancialTrxn.getsingle' => array(
'id' => "\$value.financial_trxn_id",
),
));
}
catch (CiviCRM_API3_Exception $e) {
return array();
}

$financialTrxn = array_merge($financialTrxn['api.FinancialTrxn.getsingle'], array(
'trxn_date' => date('YmdHis'),
Expand Down Expand Up @@ -1152,6 +1157,12 @@ protected function _recordAdjustedAmt($updatedAmount, $contributionId, $taxAmoun
);
$adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
}
// CRM-17151: Update the contribution status to completed if balance is zero,
// because due to sucessive fee change will leave the related contribution status incorrect
else {
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'contribution_status_id', $completedStatusId);
}

return $adjustedTrxn;
}

Expand Down
213 changes: 0 additions & 213 deletions tests/phpunit/CRM/Event/BAO/CRM17151Test.php

This file was deleted.

20 changes: 20 additions & 0 deletions tests/phpunit/CRM/Event/BAO/CRM19273Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,24 @@ public function testCRM20611() {
}
}

public function testCRM17151() {
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
$completedStatusId = array_search('Completed', $contributionStatuses);
$this->assertDBCompareValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'contribution_status_id', 'id', $completedStatusId, 'Payment t be completed');
$priceSetParams['price_1'] = 2;
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
$this->assertDBCompareValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'contribution_status_id', 'id', $pendingRefundStatusId, 'Contribution must be refunding');
$priceSetParams['price_1'] = 1;
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
$this->assertDBCompareValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'contribution_status_id', 'id', $completedStatusId, 'Contribution must, after complete payment be in state completed');
$priceSetParams['price_1'] = 3;
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
$this->assertDBCompareValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'contribution_status_id', 'id', $partiallyPaidStatusId, 'Partial Paid');
}

}

0 comments on commit eb9e473

Please sign in to comment.