diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index aab0a8375da3..e4ec1597137a 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -239,7 +239,7 @@ public function postProcess() { $feeBlock = $this->_values['fee']; $lineItems = $this->_values['line_items']; - CRM_Price_BAO_LineItem::changeFeeSelections($params, $this->_participantId, 'participant', $this->_contributionId, $feeBlock, $lineItems, $this->_paidAmount); + CRM_Price_BAO_LineItem::changeFeeSelections($params, $this->_participantId, 'participant', $this->_contributionId, $feeBlock, $lineItems); $this->contributionAmt = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $this->_contributionId, 'total_amount'); // email sending if (!empty($params['send_receipt'])) { diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index e6f5c984ee69..dfba06582f2e 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1741,8 +1741,7 @@ protected function updateContributionOnMembershipTypeChange($inputParams, $membe // add price field information in $inputParams self::addPriceFieldByMembershipType($inputParams, $priceSetDetails['fields'], $membership->membership_type_id); - // paid amount - $paidAmount = CRM_Utils_Array::value('paid', CRM_Contribute_BAO_Contribution::getPaymentInfo($membership->id, 'membership')); + // update related contribution and financial records CRM_Price_BAO_LineItem::changeFeeSelections( $inputParams, @@ -1750,7 +1749,7 @@ protected function updateContributionOnMembershipTypeChange($inputParams, $membe 'membership', $contributionID, $priceSetDetails['fields'], - $lineItems, $paidAmount + $lineItems ); CRM_Core_Session::setStatus(ts('Associated contribution is updated on membership type change.'), ts('Success'), 'success'); } diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index 2b782e48f804..dd4f1cae6a78 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -614,7 +614,6 @@ public static function getLineItemArray(&$params, $entityId = NULL, $entityTable * @param int $contributionId * @param $feeBlock * @param array $lineItems - * @param $paidAmount * */ public static function changeFeeSelections( @@ -623,8 +622,7 @@ public static function changeFeeSelections( $entity, $contributionId, $feeBlock, - $lineItems, - $paidAmount + $lineItems ) { $entityTable = "civicrm_" . $entity; CRM_Price_BAO_PriceSet::processAmount($feeBlock, @@ -716,7 +714,7 @@ public static function changeFeeSelections( if (!empty($amountLevel)) { $updateAmountLevel = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amountLevel) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR; } - $trxn = $lineItemObj->_recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount, $updateAmountLevel); + $trxn = $lineItemObj->_recordAdjustedAmt($updatedAmount, $contributionId, $taxAmount, $updateAmountLevel); $contributionCompletedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Completed'); if (!empty($financialItemsArray)) { @@ -1094,13 +1092,9 @@ protected function _getRelatedCancelFinancialTrxn($financialItemID) { * * @return bool|\CRM_Core_BAO_FinancialTrxn */ - protected function _recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL) { - $pendingAmount = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); - $pendingAmount = CRM_Utils_Array::value('total_amount', $pendingAmount, 0); + protected function _recordAdjustedAmt($updatedAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL) { + $paidAmount = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contributionId); $balanceAmt = $updatedAmount - $paidAmount; - if ($paidAmount != $pendingAmount) { - $balanceAmt -= $pendingAmount; - } $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses); diff --git a/tests/phpunit/CRM/Event/BAO/CRM19273Test.php b/tests/phpunit/CRM/Event/BAO/CRM19273Test.php index 0675353f7c44..bf2e215bc929 100644 --- a/tests/phpunit/CRM/Event/BAO/CRM19273Test.php +++ b/tests/phpunit/CRM/Event/BAO/CRM19273Test.php @@ -245,6 +245,20 @@ public function testCRM19273() { } + /** + * CRM-21245: Test that Contribution status doesn't changed to 'Pending Refund' from 'Partially Paid' if the partially paid amount is lower then newly selected fee amount + */ + public function testCRM21245() { + $this->registerParticipantAndPay(50); + $partiallyPaidContribuitonStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'); + $this->assertEquals( $this->callAPISuccessGetValue('Contribution', array('id' => $this->contributionID, 'return' => 'contribution_status_id')), $partiallyPaidContribuitonStatus); + + $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->assertEquals($this->callAPISuccessGetValue('Contribution', array('id' => $this->_contributionId, 'return' => 'contribution_status_id')), $partiallyPaidContribuitonStatus); + } + /** * Test that proper financial items are recorded for cancelled line items */