From: Pratik Joshi Date: Mon, 13 Jan 2014 14:15:49 +0000 (+0530) Subject: CRM-13965 : view transactions popup, payment information block X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=29c61b58f9a2982084ef566700f7ca977484c116;p=civicrm-core.git CRM-13965 : view transactions popup, payment information block --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index ab95cf0209..20a1fe5479 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3141,4 +3141,49 @@ WHERE eft.financial_trxn_id = {$trxnId} } CRM_Activity_BAO_Activity::create($activityParams); } + + function getPaymentInfo($id, $component, $getTrxnInfo = FALSE) { + if ($component == 'event') { + $entity = 'participant'; + $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $id, 'contribution_id', 'participant_id'); + } + $total = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); + $baseTrxnId = $total['trxn_id']; + $total = $total['total_amount']; + $paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE); + + $info['total'] = $total; + $info['paid'] = $total - $paymentBalance; + $info['balance'] = $paymentBalance; + $info['id'] = $id; + $info['component'] = $component; + + if ($getTrxnInfo) { + $sql = " +SELECT ft.total_amount, con.financial_type_id, ft.payment_instrument_id, ft.trxn_date, ft.trxn_id, ft.status_id +FROM civicrm_contribution con + LEFT JOIN civicrm_entity_financial_trxn eft ON (eft.entity_id = con.id AND eft.entity_table = 'civicrm_contribution') + LEFT JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id +WHERE ft.id != {$baseTrxnId} AND con.id = {$contributionId} +"; + $resultDAO = CRM_Core_DAO::executeQuery($sql); + + $rows = array(); + while($resultDAO->fetch()) { + $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); + $statuses = CRM_Contribute_PseudoConstant::contributionStatus(); + $financialTypes = CRM_Contribute_PseudoConstant::financialType(); + $rows[] = array( + 'total_amount' => $resultDAO->total_amount, + 'financial_type' => $financialTypes[$resultDAO->financial_type_id], + 'payment_instrument' => $paymentInstrument[$resultDAO->payment_instrument_id], + 'receive_date' => $resultDAO->trxn_date, + 'trxn_id' => $resultDAO->trxn_id, + 'status' => $statuses[$resultDAO->status_id], + ); + } + $info['transaction'] = $rows; + } + return $info; + } } \ No newline at end of file diff --git a/CRM/Contribute/Form/AdditionalPayment.php b/CRM/Contribute/Form/AdditionalPayment.php index a3b81456a9..3dc003ac85 100644 --- a/CRM/Contribute/Form/AdditionalPayment.php +++ b/CRM/Contribute/Form/AdditionalPayment.php @@ -334,7 +334,7 @@ class CRM_Contribute_Form_AdditionalPayment extends CRM_Contribute_Form_Abstract } $statusMsg = ts('The payment record has been processed.'); - if (CRM_Utils_Array::value('is_email_receipt', $this->_$submittedValues) && $sendReceipt) { + if (CRM_Utils_Array::value('is_email_receipt', $submittedValues) && $sendReceipt) { $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.'); } CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); diff --git a/CRM/Contribute/xml/Menu/Contribute.xml b/CRM/Contribute/xml/Menu/Contribute.xml index 8feecab941..7fd6301f76 100644 --- a/CRM/Contribute/xml/Menu/Contribute.xml +++ b/CRM/Contribute/xml/Menu/Contribute.xml @@ -291,4 +291,13 @@ CRM_Financial_Form_Export 610 - + + civicrm/payment/view + View Payment + CRM_Contribute_Page_PaymentInfo + action=view + access CiviContribute + 1 + CiviContribute + + \ No newline at end of file diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index d2421c59f8..e0b2100fcf 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -83,7 +83,10 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn { return $trxn; } - static function getBalanceTrxnAmt($contributionId, $contributionFinancialTypeId) { + static function getBalanceTrxnAmt($contributionId, $contributionFinancialTypeId = NULL) { + if (!$contributionFinancialTypeId) { + $contributionFinancialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'financial_type_id'); + } $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"; @@ -395,7 +398,7 @@ WHERE ceft.entity_id = %1"; * return @array : payment type => amount * payment type : 'amount_owed' or 'refund_due' */ - static function getPartialPaymentWithType($entityId, $entityName = 'pariticpant') { + static function getPartialPaymentWithType($entityId, $entityName = 'pariticpant', $returnType = TRUE) { $value = NULL; if (empty($entityName)) { return $value; @@ -436,12 +439,15 @@ WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFina "; $ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt); - $paymentVal = $lineItemTotal - $ftTotalAmt; - if ($paymentVal < 0) { - $value['refund_due'] = $paymentVal; - } - elseif ($paymentVal > 0) { - $value['amount_owed'] = $paymentVal; + $value = $paymentVal = $lineItemTotal - $ftTotalAmt; + if ($returnType) { + $value = array(); + if ($paymentVal < 0) { + $value['refund_due'] = $paymentVal; + } + elseif ($paymentVal > 0) { + $value['amount_owed'] = $paymentVal; + } } } } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index e51342fde2..8aa7a382b4 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -228,8 +228,17 @@ class CRM_Event_Form_Participant extends CRM_Contact_Form_Task { else { $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); } + $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); if ($this->_id) { + $this->assign('participantId', $this->_id); + $feePaymentBlock = FALSE; + $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_id, 'status_id', 'id'); + + if (in_array($participantStatuses[$statusId], array('Partially paid', 'Pending refund'))) { + $feePaymentBlock = TRUE; + } + $this->assign('feePaymentBlock', $feePaymentBlock); $this->_paymentId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'id', 'participant_id' ); @@ -255,8 +264,7 @@ class CRM_Event_Form_Participant extends CRM_Contact_Form_Task { $this->assign('eventNameCustomDataTypeID', $this->_eventNameCustomDataTypeID); $this->assign('eventTypeCustomDataTypeID', $this->_eventTypeCustomDataTypeID); - $partiallyPaidStatusId = CRM_Event_PseudoConstant::participantStatus(); - $partiallyPaidStatusId = array_search('Partially paid', $partiallyPaidStatusId); + $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses); $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId); if ($this->_mode) { @@ -669,6 +677,9 @@ SELECT civicrm_custom_group.name as name, * @access public */ public function buildQuickForm() { + if ($this->_action == CRM_Core_Action::UPDATE) { + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + } if ($this->_showFeeBlock) { return CRM_Event_Form_EventFees::buildQuickForm($this); } diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index 2f5973dd64..e4c76163bd 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -165,9 +165,11 @@ {/literal} {/if} + {if $participantId and $feePaymentBlock} + {include file="CRM/Contribute/Page/PaymentInfo.tpl" show='event-payment'} + {/if} {include file="CRM/Event/Form/EventFees.tpl"} - -{elseif $cdType } +{elseif $cdType} {include file="CRM/Custom/Form/CustomData.tpl"} {else} {if $participantMode == 'test' } @@ -289,7 +291,15 @@ {ts}Source for this registration (if applicable).{/ts} - + {if $participantId and $feePaymentBlock} + + + + {* this is where the payment info is shown using CRM/Contribute/Page/PaymentInfo.tpl tpl*} + + +
{ts}Fees{/ts}
+ {/if} {* Fee block (EventFees.tpl) is injected here when an event is selected. *}