From 8f4f19cade99782fb7a6c6f4fe2431110afc6d2e Mon Sep 17 00:00:00 2001 From: KarinG Date: Wed, 19 Apr 2017 18:54:45 -0600 Subject: [PATCH] Fix invoice math for partial payments. --- CRM/Contribute/Form/AdditionalPayment.php | 8 ++++---- CRM/Contribute/Form/Task/Invoice.php | 17 ++++++++++++++--- .../contribution_invoice_receipt_html.tpl | 13 +++++++------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 5f41e672d1..84cef14a5d 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -105,10 +105,10 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail(); - $enitityType = NULL; - $enitityType = 'contribution'; + $entityType = NULL; + $entityType = 'contribution'; if ($this->_component == 'event') { - $enitityType = 'participant'; + $entityType = 'participant'; $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id'); $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id'); $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId); @@ -118,7 +118,7 @@ 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, $enitityType); + $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $entityType); $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE); $this->_amtPaid = $paymentDetails['paid']; diff --git a/CRM/Contribute/Form/Task/Invoice.php b/CRM/Contribute/Form/Task/Invoice.php index 2d9bf6807f..071b88c665 100644 --- a/CRM/Contribute/Form/Task/Invoice.php +++ b/CRM/Contribute/Form/Task/Invoice.php @@ -327,10 +327,20 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { $lineItem = CRM_Price_BAO_LineItem::getLineItems($eid, 'participant', NULL, TRUE, FALSE, TRUE); } - //TO DO: Need to do changes for partially paid to display amount due on PDF invoice - $amountDue = ($input['amount'] - $input['amount']); + $resultPayments = civicrm_api3('Payment', 'get', array( + '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']; + } + } + $amountDue = ($input['amount'] - $amountPaid); - // retreiving the subtotal and sum of same tax_rate + // retrieving the subtotal and sum of same tax_rate $dataArray = array(); $subTotal = 0; foreach ($lineItem as $entity_id => $taxRate) { @@ -420,6 +430,7 @@ class CRM_Contribute_Form_Task_Invoice extends CRM_Contribute_Form_Task { 'defaultCurrency' => $config->defaultCurrency, 'amount' => $contribution->total_amount, 'amountDue' => $amountDue, + 'amountPaid'=> $amountPaid, 'invoice_date' => $invoiceDate, 'dueDate' => $dueDate, 'notes' => CRM_Utils_Array::value('notes', $prefixValue), diff --git a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl index 66c222b70e..a938ca349d 100644 --- a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl @@ -101,7 +101,7 @@ {$value.label} {else} {$value.field_title} - {$value.label} - {/if} + {/if} {if $value.description}
{$value.description|truncate:30:"..."}
{/if} @@ -143,6 +143,7 @@ {ts 1=$defaultCurrency}TOTAL %1{/ts} {$amount|crmMoney:$currency} + {if $is_pay_later == 0} @@ -155,7 +156,7 @@ {/if} - {$amount|crmMoney:$currency} + {$amountPaid|crmMoney:$currency} @@ -307,7 +308,7 @@ {$source} - + {if $domain_phone}{$domain_phone}{/if} @@ -317,9 +318,9 @@ - + {if $domain_email}{$domain_email}{/if} - + @@ -348,7 +349,7 @@ {$value.label} {else} {$value.field_title} - {$value.label} - {/if} + {/if} {if $value.description}
{$value.description|truncate:30:"..."}
{/if} -- 2.25.1