From f832530918d3810fceb27332545eb1782468b48c Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Mon, 23 Dec 2013 21:01:20 +0530 Subject: [PATCH] CRM-13964 : post process working --- CRM/Contribute/BAO/Contribution.php | 21 ++++++++++++++++++++- CRM/Event/Form/Participant.php | 17 +++++++++++++---- CRM/Financial/BAO/FinancialItem.php | 3 +++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index c6e1efea20..585b745cd9 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -144,6 +144,14 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); } + // CRM-13964 partial payment + if (empty($contributionID)) { + if ($partialAmtTotal = CRM_Utils_Array('partial_amount_total', $params) + && $partialAmtPay = CRM_Utils_Array('partial_amount_pay', $params)) { + $params['total_amount'] = $partialAmtTotal; + $params['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name'); + } + } if ($contributionID) { CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params); } @@ -2524,6 +2532,16 @@ WHERE contribution_id = %1 "; $update = TRUE; } + $statusId = $params['contribution']->contribution_status_id; + // CRM-13964 partial payment + if (CRM_Utils_Array::value('contribution_status_id', $params) != array_search('Partially Paid', $contributionStatuses) + && $partialAmtTotal = CRM_Utils_Array('partial_amount_total', $params) + && $partialAmtPay = CRM_Utils_Array('partial_amount_pay', $params)) { + $params['total_amount'] = $partialAmtPay; + $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); + // new creation of financial trasaction for the balance amount + } + // build line item array if its not set in $params if (!CRM_Utils_Array::value('line_item', $params) || $additionalParticipantId) { CRM_Price_BAO_LineItem::getLineItemArray($params, $entityID, str_replace('civicrm_', '', $entityTable)); @@ -2552,6 +2570,7 @@ WHERE contribution_id = %1 "; if (!isset($totalAmount) && CRM_Utils_Array::value('prevContribution', $params)) { $totalAmount = $params['total_amount'] = $params['prevContribution']->total_amount; } + //build financial transaction params $trxnParams = array( 'contribution_id' => $params['contribution']->id, @@ -2562,7 +2581,7 @@ WHERE contribution_id = %1 "; 'net_amount' => CRM_Utils_Array::value('net_amount', $params), 'currency' => $params['contribution']->currency, 'trxn_id' => $params['contribution']->trxn_id, - 'status_id' => $params['contribution']->contribution_status_id, + 'status_id' => $statusId, 'payment_instrument_id' => $params['contribution']->payment_instrument_id, 'check_number' => CRM_Utils_Array::value('check_number', $params), ); diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 4b9eb2184f..f0919c9c56 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1465,6 +1465,15 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) { $contributionParams['is_pay_later'] = 1; } + + // CRM-13964 partial_payment_total + if ($params['fee_amount'] > $params['total_amount']) { + // the owed amount + $contributionParams['partial_payment_total'] = $params['fee_amount']; + // the actual amount paid + $contributionParams['partial_amount_pay'] = $params['total_amount']; + } + if ($this->_single) { if (empty($ids)) { $ids = array(); @@ -1513,10 +1522,10 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); foreach ($this->_lineItem as $key => $value) { if (is_array($value) && $value != 'skip') { foreach ($value as $lineKey => $line) { - //10117 update the line items for participants if contribution amount is recorded - if ($this->_quickConfig && CRM_Utils_Array::value('total_amount', $params )) { - $line['unit_price'] = $line['line_total'] = $params['total_amount']; - } + /* //10117 update the line items for participants if contribution amount is recorded */ + /* if ($this->_quickConfig && CRM_Utils_Array::value('total_amount', $params )) { */ + /* $line['unit_price'] = $line['line_total'] = $params['total_amount']; */ + /* } */ $lineItem[$this->_priceSetId][$lineKey] = $line; } CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant'); diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 5e618f3840..84a5d33064 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -85,6 +85,9 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem { elseif ($contribution->contribution_status_id == array_search('Pending', $contributionStatuses)) { $itemStatus = array_search('Unpaid', $financialItemStatus); } + elseif ($contribution->contribution_status_id == array_search('Partially paid', $contributionStatuses)) { + $itemStatus = array_search('Partially paid', $financialItemStatus); + } $params = array( 'transaction_date' => CRM_Utils_Date::isoToMysql($contribution->receive_date), 'contact_id' => $contribution->contact_id, -- 2.25.1