CRM-13965 : view transactions popup, payment information block
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Mon, 13 Jan 2014 14:15:49 +0000 (19:45 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 16 Jan 2014 01:43:17 +0000 (07:13 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Form/AdditionalPayment.php
CRM/Contribute/xml/Menu/Contribute.xml
CRM/Core/BAO/FinancialTrxn.php
CRM/Event/Form/Participant.php
templates/CRM/Event/Form/Participant.tpl

index ab95cf02094b4bb4e357d6cb8e7fa1a70c4a24b7..20a1fe547937674b225c0431dae99c47a92c9387 100644 (file)
@@ -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
index a3b81456a978e2aa12ac49a2a39dc3ffa3859268..3dc003ac85ec1462b71296acd87bc65d3f9aee25 100644 (file)
@@ -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');
index 8feecab9411693bb4a39453ad3e06922e7137821..7fd6301f7640cae117f9d4f4e9b52acf0f5f612e 100644 (file)
     <page_callback>CRM_Financial_Form_Export</page_callback>
     <weight>610</weight>
   </item>
-</menu>
+  <item>
+    <path>civicrm/payment/view</path>
+    <title>View Payment</title>
+    <page_callback>CRM_Contribute_Page_PaymentInfo</page_callback>
+    <path_arguments>action=view</path_arguments>
+    <access_arguments>access CiviContribute</access_arguments>
+    <page_type>1</page_type>
+    <component>CiviContribute</component>
+  </item>
+</menu>
\ No newline at end of file
index d2421c59f87c3234b24ab907d2295c46b47cd1d9..e0b2100fcf10d84c87c6506c0831fc5963e45e3b 100644 (file)
@@ -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;
+          }
         }
       }
     }
index e51342fde26d0f106e088170f67f521c26e12a8b..8aa7a382b4047744adc5aada92e0390b4e371846 100644 (file)
@@ -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);
     }
index 2f5973dd640ce9989f2eeb559784de448415de18..e4c76163bd4bc6a7306148ddd9c5881258d96bb0 100644 (file)
   </script>
   {/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' }
             <span class="description">{ts}Source for this registration (if applicable).{/ts}</span></td>
           </tr>
         </table>
-
+       {if $participantId and $feePaymentBlock}
+        <table class='form-layout'>
+          <tr>
+            <td class='label'>{ts}Fees{/ts}</td>
+            {* this is where the payment info is shown using CRM/Contribute/Page/PaymentInfo.tpl tpl*}
+            <td id='payment-info'></td>
+          </tr>
+         </table>
+        {/if}
       {* Fee block (EventFees.tpl) is injected here when an event is selected. *}
         <div id="feeBlock"></div>
         <fieldset>