From 74e4c3c202054569193151c4efbe2be50bad6d24 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 28 Feb 2019 15:33:19 +1300 Subject: [PATCH] Decommision getPartialPaymentTrxn function This function is only called from one place in the code & also from a test. It is misleading as it implies a 'get' when it actually does an update and it groups functionality in a way that doesn't make sense from the calling code pov In this commit the function is removed and the lines are directly copied to the calling function, as preparation for cleaning up the calling function --- CRM/Core/BAO/FinancialTrxn.php | 20 ------------------- CRM/Financial/BAO/Payment.php | 9 ++++++++- .../CRM/Core/BAO/FinancialTrxnTest.php | 12 ++++++++--- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index f893a94260..f6ec9f6c65 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -506,26 +506,6 @@ WHERE ceft.entity_id = %1"; ]); } - /** - * Function records partial payment, complete's contribution if payment is fully paid - * and returns latest payment ie financial trxn - * - * @param array $contribution - * @param array $params - * - * @return \CRM_Financial_DAO_FinancialTrxn - */ - public static function getPartialPaymentTrxn($contribution, $params) { - $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); - $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); - $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); - $cmp = bccomp($total, $paid, 5); - if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount - civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); - } - return $trxn; - } - /** * Get revenue amount for membership. * diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 1e3e0518aa..a5d4ea4de3 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -79,7 +79,14 @@ class CRM_Financial_BAO_Payment { } } if (!$fullyPaidPayLater) { - $trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params); + $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); + $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); + $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); + $cmp = bccomp($total, $paid, 5); + if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount + civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + } + if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) { foreach ($params['line_item'] as $values) { foreach ($values as $id => $amount) { diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index e09a2db940..94de1d4d10 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -106,9 +106,9 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { } /** - * Test getPartialPaymentTrxn function. + * Tests the lines of code that used to be in the getPartialPaymentTrxn fn. */ - public function testGetPartialPaymentTrxn() { + public function testGetExPartialPaymentTrxn() { $contributionTest = new CRM_Contribute_BAO_ContributionTest(); list($lineItems, $contribution) = $contributionTest->addParticipantWithContribution(); $contribution = (array) $contribution; @@ -116,7 +116,13 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { 'contribution_id' => $contribution['id'], 'total_amount' => 100.00, ); - $trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params); + $trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params); + $paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']); + $total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount'); + $cmp = bccomp($total, $paid, 5); + if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount + civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id'])); + } $this->assertEquals('100.00', $trxn->total_amount, 'Amount does not match.'); -- 2.25.1