Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20450: Fix invoice math for partial payments. #10222

Merged
merged 4 commits into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CRM/Contribute/Form/AdditionalPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ public function preProcess() {
}
$this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();

$enitityType = NULL;
$enitityType = 'contribution';
$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);
Expand All @@ -118,7 +117,7 @@ public function preProcess() {
$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'];
Expand Down
17 changes: 14 additions & 3 deletions CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,20 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
$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) {
Expand Down Expand Up @@ -420,6 +430,7 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
'defaultCurrency' => $config->defaultCurrency,
'amount' => $contribution->total_amount,
'amountDue' => $amountDue,
'amountPaid' => $amountPaid,
'invoice_date' => $invoiceDate,
'dueDate' => $dueDate,
'notes' => CRM_Utils_Array::value('notes', $prefixValue),
Expand Down
Loading