From 1010c4e166e68367762429630a69ec1c5d9254b4 Mon Sep 17 00:00:00 2001 From: Pratik Joshi Date: Thu, 6 Mar 2014 21:16:30 +0530 Subject: [PATCH] CRM-13965 : improvement; CRM-13973 : done with all handling except for email receipt --- CRM/Contribute/BAO/Contribution.php | 9 +++-- CRM/Contribute/Page/PaymentInfo.php | 2 +- CRM/Core/BAO/FinancialTrxn.php | 6 +++- CRM/Event/Form/ParticipantFeeSelection.php | 12 +++---- .../payment_or_refund_notification_html.tpl | 4 +++ .../Event/Form/ParticipantFeeSelection.tpl | 34 +++++++++++++------ .../payment_or_refund_notification_html.tpl | 4 +++ 7 files changed, 48 insertions(+), 23 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 83b8a79f41..fe8205db5a 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3034,6 +3034,8 @@ WHERE eft.financial_trxn_id = {$trxnId} $trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis'); $trxnsData['total_amount'] = - $trxnsData['total_amount']; + $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); + $trxnsData['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionDAO->financial_type_id, $relationTypeId); $trxnsData['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name'); // record the entry $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); @@ -3124,21 +3126,22 @@ WHERE eft.financial_trxn_id = {$trxnId} CRM_Activity_BAO_Activity::create($activityParams); } - function getPaymentInfo($id, $component, $getTrxnInfo = FALSE) { + function getPaymentInfo($id, $component, $getTrxnInfo = FALSE, $usingLineTotal = FALSE) { if ($component == 'event') { $entity = 'participant'; $entityTable = 'civicrm_participant'; $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); } $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); - $baseTrxnId = NULL; - if (empty($total)) { + $baseTrxnId = !empty($total['trxn_id']) ? $total['trxn_id'] : NULL; + if (empty($total) || $usingLineTotal) { $total = CRM_Price_BAO_LineItem::getLineTotal($id, $entityTable); } else { $baseTrxnId = $total['trxn_id']; $total = $total['total_amount']; } + $paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total); $info['total'] = $total; $info['paid'] = $total - $paymentBalance; diff --git a/CRM/Contribute/Page/PaymentInfo.php b/CRM/Contribute/Page/PaymentInfo.php index fe8ce148aa..4f8fc8291c 100644 --- a/CRM/Contribute/Page/PaymentInfo.php +++ b/CRM/Contribute/Page/PaymentInfo.php @@ -48,7 +48,7 @@ class CRM_Contribute_Page_PaymentInfo extends CRM_Core_Page { function browse() { $getTrxnInfo = $this->_context == 'transaction' ? TRUE : FALSE; - $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, $getTrxnInfo); + $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, $getTrxnInfo, TRUE); if ($this->_context == 'payment_info') { $this->assign('paymentInfo', $paymentInfo); } diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 22bc181640..48015b0b92 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -90,8 +90,10 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($contributionFinancialTypeId, $relationTypeId); $q = "SELECT ft.id, ft.total_amount FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON (eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution') WHERE eft.entity_id = %1 AND ft.to_financial_account_id = %2"; + $p[1] = array($contributionId, 'Integer'); $p[2] = array($toFinancialAccount, 'Integer'); + $balanceAmtDAO = CRM_Core_DAO::executeQuery($q, $p); $ret = array(); while($balanceAmtDAO->fetch()) { @@ -410,6 +412,8 @@ WHERE ceft.entity_id = %1"; if ($contributionId && $financialTypeId) { $statusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'); + $refundStatusId = CRM_Core_OptionGroup::getValue('contribution_status', 'Refunded', 'name'); + $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $relationTypeId); @@ -423,7 +427,7 @@ FROM civicrm_financial_trxn ft LEFT JOIN civicrm_contribution c ON (eft.entity_id = c.id) LEFT JOIN civicrm_participant_payment pp ON (pp.contribution_id = c.id) WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFinancialAccount} - AND ft.status_id = {$statusId} + AND ft.status_id IN ({$statusId}, {$refundStatusId}) "; $ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt); $value = 0; diff --git a/CRM/Event/Form/ParticipantFeeSelection.php b/CRM/Event/Form/ParticipantFeeSelection.php index c5eb229956..9126b4aff8 100644 --- a/CRM/Event/Form/ParticipantFeeSelection.php +++ b/CRM/Event/Form/ParticipantFeeSelection.php @@ -94,7 +94,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event'); $this->_paidAmount = $paymentInfo['paid']; $this->assign('paymentInfo', $paymentInfo); - CRM_Core_Resources::singleton()->addSetting(array('feePaid' => $this->_paidAmount)); + $this->assign('feePaid', $this->_paidAmount); $title = "Change selections for {$this->_contributorDisplayName}"; if ($title) { @@ -128,11 +128,9 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); $statuses = CRM_Event_PseudoConstant::participantStatus(); - CRM_Core_Resources::singleton()->addSetting(array( - 'partiallyPaid' => array_search('Partially paid', $statuses), - 'pendingRefund' => array_search('Pending refund', $statuses), - 'participantStatus' => $this->_participantStatus - )); + $this->assign('partiallyPaid', array_search('Partially paid', $statuses)); + $this->assign('pendingRefund', array_search('Pending refund', $statuses)); + $this->assign('participantStatus', $this->_participantStatus); $config = CRM_Core_Config::singleton(); $this->assign('currencySymbol', $config->defaultCurrencySymbol); @@ -232,7 +230,7 @@ class CRM_Event_Form_ParticipantFeeSelection extends CRM_Core_Form { $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('upload', 'new')) { $session = CRM_Core_Session::singleton(); - $session->replaceUserContext(CRM_Utils_System::url('civicrm/payment/add', + $session->pushUserContext(CRM_Utils_System::url('civicrm/payment/add', "reset=1&action=add&component=event&id={$this->_participantId}&cid={$this->_contactId}" )); } diff --git a/CRM/Upgrade/4.5.alpha1.msg_template/message_templates/payment_or_refund_notification_html.tpl b/CRM/Upgrade/4.5.alpha1.msg_template/message_templates/payment_or_refund_notification_html.tpl index d69b32ff7d..450cacdb81 100644 --- a/CRM/Upgrade/4.5.alpha1.msg_template/message_templates/payment_or_refund_notification_html.tpl +++ b/CRM/Upgrade/4.5.alpha1.msg_template/message_templates/payment_or_refund_notification_html.tpl @@ -48,12 +48,16 @@ {$totalAmount|crmMoney} + + {ts}You Paid{/ts} {$totalPaid|crmMoney} + + {ts}Refund Amount{/ts} diff --git a/templates/CRM/Event/Form/ParticipantFeeSelection.tpl b/templates/CRM/Event/Form/ParticipantFeeSelection.tpl index 97ca631c9a..ad48babf26 100644 --- a/templates/CRM/Event/Form/ParticipantFeeSelection.tpl +++ b/templates/CRM/Event/Form/ParticipantFeeSelection.tpl @@ -40,21 +40,27 @@ function display(totalfee) { // populate the balance amount div // change the status selections according to updated selections - populatebalanceFee(totalEventFee); + populatebalanceFee(totalfee); } function populatebalanceFee(updatedAmt) { + // assign statuses + var partiallyPaid = {/literal}{$partiallyPaid}{literal}; + var pendingRefund = {/literal}{$pendingRefund}{literal}; + var participantStatus = {/literal}{$participantStatus}{literal}; + var feePaid = {/literal}{$feePaid}{literal}; + // calculate the balance amount using total paid and updated amount - var balanceAmt = updatedAmt - CRM.feePaid; + var balanceAmt = updatedAmt - feePaid; // change the status selections according to updated selections if (balanceAmt > 0) { - cj('#status_id').val(CRM.partiallyPaid); + cj('#status_id').val(partiallyPaid); } else if(balanceAmt < 0) { - cj('#status_id').val(CRM.pendingRefund); + cj('#status_id').val(pendingRefund); } else if(balanceAmt == 0) { - cj('#status_id').val(CRM.participantStatus); + cj('#status_id').val(participantStatus); } balanceAmt = formatMoney(balanceAmt, 2, seperator, thousandMarker); @@ -62,16 +68,22 @@ function populatebalanceFee(updatedAmt) { } cj(function(){ + // assign statuses + var partiallyPaid = {/literal}{$partiallyPaid}{literal}; + var pendingRefund = {/literal}{$pendingRefund}{literal}; + var participantStatus = {/literal}{$participantStatus}{literal}; + var feePaid = {/literal}{$feePaid}{literal}; + var updatedFeeUnFormatted = cj('#pricevalue').text(); var updatedAmt = parseFloat(updatedFeeUnFormatted.replace(/[^0-9-.]/g, '')); - var balanceAmt = updatedAmt - CRM.feePaid; + var balanceAmt = updatedAmt - feePaid; // change the status selections according to updated selections if (balanceAmt > 0) { - cj('#status_id').val(CRM.partiallyPaid); + cj('#status_id').val(partiallyPaid); } else if(balanceAmt < 0) { - cj('#status_id').val(CRM.pendingRefund); + cj('#status_id').val(pendingRefund); } }); @@ -117,7 +129,7 @@ cj(function(){
{ts}Updated Fee(s){/ts}
{ts}Total Paid{/ts}
- @@ -188,13 +200,13 @@ cj(function($){ var balanceFee = cj('#balance-fee').text(); balanceFee = parseFloat(balanceFee.replace(/[^0-9-.]/g, '')); - if (balanceFee > 0 && statusId != CRM.partiallyPaid) { + if (balanceFee > 0 && statusId != partiallyPaid) { var result = confirm('Balance is owing for the updated selections. Expected participant status is \'Partially paid\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries.'); if (result == false) { e.preventDefault(); } } - else if (balanceFee < 0 && statusId != CRM.pendingRefund) { + else if (balanceFee < 0 && statusId != pendingRefund) { var result = confirm('Balance is overpaid for the updated selections. Expected participant status is \'Pending refund\'. Are you sure you want to set the participant status to ' + statusLabel + ' ? Click OK to continue, Cancel to change your entries'); if (result == false) { e.preventDefault(); diff --git a/xml/templates/message_templates/payment_or_refund_notification_html.tpl b/xml/templates/message_templates/payment_or_refund_notification_html.tpl index d69b32ff7d..450cacdb81 100644 --- a/xml/templates/message_templates/payment_or_refund_notification_html.tpl +++ b/xml/templates/message_templates/payment_or_refund_notification_html.tpl @@ -48,12 +48,16 @@ {$totalAmount|crmMoney} + + {ts}You Paid{/ts} {$totalPaid|crmMoney} + + {ts}Refund Amount{/ts} -- 2.25.1