Skip to content

Commit

Permalink
Merge pull request #10390 from JMAConsulting/CRM-20611
Browse files Browse the repository at this point in the history
CRM-20611: fix financial records of cancelled line_items on event fee  change selection
  • Loading branch information
colemanw authored Jun 16, 2017
2 parents 9d7051f + aa84923 commit 9d1b2a8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3936,7 +3936,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
}
}
elseif ($paymentType == 'refund') {
$trxnsData['total_amount'] = -$trxnsData['total_amount'];
$trxnsData['total_amount'] = $trxnsData['net_amount'] = -$trxnsData['total_amount'];
$trxnsData['from_financial_account_id'] = $arAccountId;
$trxnsData['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded');
// record the entry
Expand All @@ -3954,11 +3954,16 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionDAO->id);
if (!empty($lineItems)) {
foreach ($lineItems as $lineItemId => $lineItemValue) {
// don't record financial item for cancelled line-item
if ($lineItemValue['qty'] == 0) {
continue;
}
$paid = $lineItemValue['line_total'] * ($financialTrxn->total_amount / $contributionDAO->total_amount);
$addFinancialEntry = array(
'transaction_date' => $financialTrxn->trxn_date,
'contact_id' => $contributionDAO->contact_id,
'amount' => round($paid, 2),
'currency' => $contributionDAO->currency,
'status_id' => array_search('Paid', $financialItemStatus),
'entity_id' => $lineItemId,
'entity_table' => 'civicrm_line_item',
Expand Down
1 change: 1 addition & 0 deletions CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,7 @@ public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contribut
'from_financial_account_id' => NULL,
'to_financial_account_id' => $toFinancialAccount,
'total_amount' => $balanceAmt,
'net_amount' => $balanceAmt,
'status_id' => $completedStatusId,
'payment_instrument_id' => $updatedContribution->payment_instrument_id,
'contribution_id' => $updatedContribution->id,
Expand Down
45 changes: 45 additions & 0 deletions tests/phpunit/CRM/Event/BAO/CRM19273Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,51 @@ public function testCRM19273() {

CRM_Event_BAO_Participant::changeFeeSelections($PSparams, $this->participantID, $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee, $this->_priceSetID);
$this->balanceCheck($this->_veryExpensive);

}

/**
* Test that proper financial items are recorded for cancelled line items
*/
public function testCRM20611() {
$PSparams['price_1'] = 1;
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant');
CRM_Event_BAO_Participant::changeFeeSelections($PSparams, $this->participantID, $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee, $this->_priceSetID);
$this->balanceCheck($this->_expensiveFee);

$PSparams['price_1'] = 2;
$lineItem = CRM_Price_BAO_LineItem::getLineItems($this->participantID, 'participant');
CRM_Event_BAO_Participant::changeFeeSelections($PSparams, $this->participantID, $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee, $this->_priceSetID);
$this->balanceCheck($this->_cheapFee);

//Complete the refund payment.
$submittedValues = array(
'total_amount' => 120,
'payment_instrument_id' => 3,
);
CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, 'refund', $this->participantID);

// retrieve the cancelled line-item information
$cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', array(
'entity_table' => 'civicrm_participant',
'entity_id' => $this->participantID,
'qty' => 0,
));
// retrieve the related financial lin-items
$financialItems = $this->callAPISuccess('FinancialItem', 'Get', array(
'entity_id' => $cancelledLineItem['id'],
'entity_table' => 'civicrm_line_item',
));
$this->assertEquals($financialItems['count'], 2, 'Financial Items for Cancelled fee is not proper');

$contributionCompletedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$expectedAmount = 100.00;
foreach ($financialItems['values'] as $id => $financialItem) {
$this->assertEquals($expectedAmount, $financialItem['amount']);
$this->assertNotEmpty($financialItem['financial_account_id']);
$this->assertEquals($contributionCompletedStatusID, $financialItem['status_id']);
$expectedAmount = -$expectedAmount;
}
}

}

0 comments on commit 9d1b2a8

Please sign in to comment.