From a168b222cb4f6f562af143d60d0d0de525dcc7d9 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 9 Oct 2019 13:26:09 +0200 Subject: [PATCH] [REF] remove call to deprecated function getPartialPaymentType basically just calls CRM_Contribute_BAO_Contribution::getContributionBalance & then returns the balance in a different array key depending on the value. This switches to calling it directly & completes the work of removing all calls to it & more heavily deprecating it --- CRM/Contribute/Form/AdditionalPayment.php | 20 +++++++++---------- CRM/Core/BAO/FinancialTrxn.php | 1 + .../CRM/Core/BAO/FinancialTrxnTest.php | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index fdb7c478f3..e6aceaa3dd 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -108,18 +108,18 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->_fromEmails['from_email_id'] = CRM_Core_BAO_Email::getFromEmail(); } - $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType); $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE); + $paymentAmt = CRM_Contribute_BAO_Contribution::getContributionBalance($this->_id); $this->_amtPaid = $paymentDetails['paid']; $this->_amtTotal = $paymentDetails['total']; - if (!empty($paymentInfo['refund_due'])) { - $paymentAmt = $this->_refund = $paymentInfo['refund_due']; + if ($paymentAmt < 0) { + $this->_refund = $paymentAmt; $this->_paymentType = 'refund'; } - elseif (!empty($paymentInfo['amount_owed'])) { - $paymentAmt = $this->_owed = $paymentInfo['amount_owed']; + elseif ($paymentAmt > 0) { + $this->_owed = $paymentAmt; $this->_paymentType = 'owed'; } else { @@ -520,18 +520,18 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract if (!empty($params['contribution_id'])) { $this->_contributionId = $params['contribution_id']; - $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_contributionId, $entityType); $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_contributionId, $entityType, FALSE, TRUE); + $paymentAmount = CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId); $this->_amtPaid = $paymentDetails['paid']; $this->_amtTotal = $paymentDetails['total']; - if (!empty($paymentInfo['refund_due'])) { - $this->_refund = $paymentInfo['refund_due']; + if ($paymentAmount < 0) { + $this->_refund = $paymentAmount; $this->_paymentType = 'refund'; } - elseif (!empty($paymentInfo['amount_owed'])) { - $this->_owed = $paymentInfo['amount_owed']; + elseif ($paymentAmount > 0) { + $this->_owed = $paymentAmount; $this->_paymentType = 'owed'; } } diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index b02538e429..995fb6403a 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -454,6 +454,7 @@ WHERE ceft.entity_id = %1"; * @return array */ public static function getPartialPaymentWithType($entityId, $entityName = 'participant', $lineItemTotal = NULL) { + CRM_Core_Error::deprecatedFunctionWarning('CRM_Contribute_BAO_Contribution::getContributionBalance'); $value = NULL; if (empty($entityName)) { return $value; diff --git a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php index ee66811b23..b8fc1773f7 100644 --- a/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php +++ b/tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php @@ -247,9 +247,9 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { } /** - * Test getPartialPaymentWithType function. + * Test testGetContributionBalance function. */ - public function testGetPartialPaymentWithType() { + public function testGetContributionBalance() { //create the contribution that isn't paid yet $contactId = $this->individualCreate(); $params = [ @@ -270,7 +270,7 @@ class CRM_Core_BAO_FinancialTrxnTest extends CiviUnitTestCase { ]; $this->callAPISuccess('Payment', 'create', $params); //amount owed should be one cent - $amountOwed = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($contribution['id'], 'contribution')['amount_owed']; + $amountOwed = CRM_Contribute_BAO_Contribution::getContributionBalance($contribution['id']); $this->assertTrue(0.01 == $amountOwed, 'Amount does not match'); } -- 2.25.1