From 449b5e65d6c77b02f3010a0a8888a8e42b36cfe3 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Tue, 11 Feb 2020 15:18:49 +0000 Subject: [PATCH] Count refunds when calculating amount due for an invoice --- CRM/Contribute/Form/Task/Invoice.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 9ff683534c..54171aba75 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -286,24 +286,13 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { $invoiceDate = date("F j, Y"); $dueDate = date('F j, Y', strtotime($contributionReceiveDate . "+" . $prefixValue['due_date'] . "" . $prefixValue['due_date_period'])); - $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribID); - - $resultPayments = civicrm_api3('Payment', 'get', [ - 'sequential' => 1, - 'contribution_id' => $contribID, - ]); - $amountPaid = 0; - foreach ($resultPayments['values'] as $singlePayment) { - // Only count payments that have been (status =) completed. - if ($singlePayment['status_id'] == 1) { - $amountPaid += $singlePayment['total_amount']; - } - } + $amountPaid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($contribID, TRUE); $amountDue = ($input['amount'] - $amountPaid); // retrieving the subtotal and sum of same tax_rate $dataArray = []; $subTotal = 0; + $lineItem = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribID); foreach ($lineItem as $taxRate) { if (isset($dataArray[(string) $taxRate['tax_rate']])) { $dataArray[(string) $taxRate['tax_rate']] = $dataArray[(string) $taxRate['tax_rate']] + CRM_Utils_Array::value('tax_amount', $taxRate); -- 2.25.1