From aac57c29762a0ea5af8b7f22c117caabab28af51 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Sat, 11 Jan 2014 11:16:07 +0530 Subject: [PATCH] CRM-13965, CRM-13964 : improvements and proper redirections --- CRM/Contribute/BAO/Contribution.php | 7 +++++- CRM/Contribute/Form/AdditionalPayment.php | 15 ++++++++++++ CRM/Event/Form/Participant.php | 28 ++++++++++++++--------- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index d10ba45b53..ab95cf0209 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3021,6 +3021,7 @@ WHERE contribution_id = %1 "; $params['skipLineItem'] = TRUE; $params['partial_payment_total'] = $contributionDAO->total_amount; $params['partial_amount_pay'] = $trxnsData['total_amount']; + $trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis'); // record the entry $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); @@ -3051,7 +3052,11 @@ WHERE eft.entity_table = 'civicrm_contribution' $contributionUpdate['id'] = $contributionId; $contributionUpdate['contribution_status_id'] = $statusId; $contributionUpdate['skipLineItem'] = TRUE; - $contributionDetails = self::add($contributionUpdate); + // note : not using the self::add method, + // the reason because it performs 'status change' related code execution for financial records + // which in 'Partial Paid' => 'Completed' is not useful, instead specific financial record updates + // are coded below i.e. just updating financial_item status to 'Paid' + $contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId); if ($participantId) { // update participant status diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index 2ed214ed9c..a3b81456a9 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -314,6 +314,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $participantId = $this->_id; } $submittedValues = $this->controller->exportValues($this->_name); + $submittedValues['trxn_date'] = CRM_Utils_Date::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']); if ($this->_mode) { // process credit card @@ -331,6 +332,17 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $this->fromEmailId = $submittedValues['from_email_address']; $sendReceipt = self::emailReceipt($this, $submittedValues); } + + $statusMsg = ts('The payment record has been processed.'); + if (CRM_Utils_Array::value('is_email_receipt', $this->_$submittedValues) && $sendReceipt) { + $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.'); + } + CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); + + $session = CRM_Core_Session::singleton(); + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$this->_contactId}&selectedChild=participant" + )); } } @@ -521,6 +533,9 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.'); } CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success'); + $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', + "reset=1&cid={$this->_contactId}&selectedChild=participant" + )); } } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index a4b6d1d80e..e51342fde2 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1058,6 +1058,7 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); return; } + $participantStatus = CRM_Event_PseudoConstant::participantStatus(); // set the contact, when contact is selected if (CRM_Utils_Array::value('contact_select_id', $params)) { $this->_contactId = $params['contact_select_id'][1]; @@ -1126,7 +1127,8 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); $params['fee_level'] = $params['amount_level']; $contributionParams['total_amount'] = $params['amount']; - if ($this->_quickConfig && CRM_Utils_Array::value('total_amount', $params)) { + if ($this->_quickConfig && CRM_Utils_Array::value('total_amount', $params) + && $params['status_id'] != array_search('Partially paid', $participantStatus)) { $params['fee_amount'] = $params['total_amount']; } else { //fix for CRM-3086 @@ -1467,12 +1469,14 @@ loadCampaign( {$this->_eID}, {$eventCampaigns} ); $contributionParams['is_pay_later'] = 1; } - // CRM-13964 partial_payment_total - if ($amountOwed > $params['total_amount']) { - // the owed amount - $contributionParams['partial_payment_total'] = $amountOwed; - // the actual amount paid - $contributionParams['partial_amount_pay'] = $params['total_amount']; + if ($params['status_id'] == array_search('Partially paid', $participantStatus)) { + // CRM-13964 partial_payment_total + if ($amountOwed > $params['total_amount']) { + // the owed amount + $contributionParams['partial_payment_total'] = $amountOwed; + // the actual amount paid + $contributionParams['partial_amount_pay'] = $params['total_amount']; + } } if ($this->_single) { if (empty($ids)) { @@ -1522,10 +1526,12 @@ 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 ) + && $params['status_id'] != array_search('Partially paid', $participantStatus) + ) { + $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'); -- 2.25.1