From: jitendrapurohit Date: Wed, 4 Jan 2017 10:50:42 +0000 (+0530) Subject: CRM-19803 test to check owed/refund details in view payments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=426023f78a51ca2db7bc6f7e6a3b88a37240a5cf;p=civicrm-core.git CRM-19803 test to check owed/refund details in view payments --- diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index aaf9e5d224..25347945cd 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1920,6 +1920,7 @@ WHERE civicrm_participant.contact_id = {$contactID} AND $submittedFields = implode(', ', $submittedFieldId); $submittedFieldValues = implode(', ', $submittedFieldValueIds); } + $financialItemsArray = array(); if (!empty($submittedFields) && !empty($submittedFieldValues)) { $updateLineItem = "UPDATE civicrm_line_item li INNER JOIN civicrm_financial_item fi @@ -1945,7 +1946,6 @@ GROUP BY li.entity_table, li.entity_id, price_field_value_id, fi.id $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); $updateFinancialItemInfoValues = array(); - $financialItemsArray = array(); while ($updateFinancialItemInfoDAO->fetch()) { $updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO; $updateFinancialItemInfoValues['transaction_date'] = date('YmdHis'); @@ -2093,6 +2093,7 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI FROM civicrm_line_item WHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND qty > 0)"; $getUpdatedLineItemsDAO = CRM_Core_DAO::executeQuery($getUpdatedLineItems); + $line = array(); while ($getUpdatedLineItemsDAO->fetch()) { $line[$getUpdatedLineItemsDAO->price_field_value_id] = $getUpdatedLineItemsDAO->label . ' - ' . (float) $getUpdatedLineItemsDAO->qty; } diff --git a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php index 864b914ce5..d22cf982cb 100644 --- a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php @@ -49,6 +49,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { 'civicrm_line_item', 'civicrm_financial_item', 'civicrm_financial_trxn', + 'civicrm_price_set', 'civicrm_entity_financial_trxn', ), TRUE @@ -118,12 +119,22 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); $feeBlock = CRM_Utils_Array::value('fields', $priceSet); $params['price_2'] = $feeTotal; + $tempParams = $params; + $templineItems = $lineItem; CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItem ); $lineItemVal[$priceSetId] = $lineItem; CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant'); - return array($participant, $contribution); + + return array( + 'participant' => $participant, + 'contribution' => $contribution, + 'lineItem' => $templineItems, + 'params' => $tempParams, + 'feeBlock' => $feeBlock, + 'priceSetId' => $priceSetId, + ); } /** @@ -133,7 +144,8 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $feeAmt = 100; $amtPaid = 60; $balance = $feeAmt - $amtPaid; - list($participant, $contribution) = $this->addParticipantWithPayment($feeAmt, $amtPaid); + $result = $this->addParticipantWithPayment($feeAmt, $amtPaid); + extract($result); $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event'); // amount checking @@ -146,4 +158,42 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $this->assertEquals($contribution->contribution_status_id, 8, 'Status record is not proper for contribution'); } + /** + * Test owed/refund info is listed on view payments. + */ + public function testTransactionInfo() { + $feeAmt = 100; + $amtPaid = 80; + $result = $this->addParticipantWithPayment($feeAmt, $amtPaid); + extract($result); + + //Complete the partial payment. + $submittedValues = array( + 'total_amount' => 20, + 'payment_instrument_id' => 3, + ); + CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contribution->id, $submittedValues, 'owed', $participant['id']); + + //Change selection to a lower amount. + $params['price_2'] = 50; + CRM_Event_BAO_Participant::changeFeeSelections($params, $participant['id'], $contribution->id, $feeBlock, $lineItem, $feeAmt, $priceSetId); + + //Record a refund of the remaining amount. + $submittedValues['total_amount'] = 50; + CRM_Contribute_BAO_Contribution::recordAdditionalPayment($contribution->id, $submittedValues, 'refund', $participant['id']); + $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($participant['id'], 'event', TRUE); + $transaction = $paymentInfo['transaction']; + + //Assert all transaction(owed and refund) are listed on view payments. + $this->assertEquals(count($transaction), 3, 'Transaction Details is not proper'); + $this->assertEquals($transaction[0]['total_amount'], 80.00); + $this->assertEquals($transaction[0]['status'], 'Completed'); + + $this->assertEquals($transaction[1]['total_amount'], 20.00); + $this->assertEquals($transaction[1]['status'], 'Completed'); + + $this->assertEquals($transaction[2]['total_amount'], -50.00); + $this->assertEquals($transaction[2]['status'], 'Refunded'); + } + }