CRM-13965 : improvement; CRM-13973 : done with all handling except for email receipt
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 6 Mar 2014 15:46:30 +0000 (21:16 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Thu, 6 Mar 2014 15:46:30 +0000 (21:16 +0530)
CRM/Contribute/BAO/Contribution.php
CRM/Contribute/Page/PaymentInfo.php
CRM/Core/BAO/FinancialTrxn.php
CRM/Event/Form/ParticipantFeeSelection.php
CRM/Upgrade/4.5.alpha1.msg_template/message_templates/payment_or_refund_notification_html.tpl
templates/CRM/Event/Form/ParticipantFeeSelection.tpl
xml/templates/message_templates/payment_or_refund_notification_html.tpl

index 83b8a79f4110ed1718f854757425399e210c288e..fe8205db5a3e4c75ebf693b1c9ca4d7aea646381 100644 (file)
@@ -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;
index fe8ce148aaf32427ad32cf88c5c1ee45e7133884..4f8fc8291c4664b939450e3ffc12fd6df3cf5885 100644 (file)
@@ -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);
     }
index 22bc1816401b41698692cb4f5fd852c6baed1a10..48015b0b9282d1055473e1f880e7237004f545a3 100644 (file)
@@ -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;
index c5eb229956f7eced7c4d63777971463582bcdca7..9126b4aff841ee5bd86e8bfad6692613ffaab012 100644 (file)
@@ -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}"
         ));
     }
index d69b32ff7dba9ca3850e56f51c1730e9e9522e8e..450cacdb818e028dd816e33add166099648b7f63 100644 (file)
     <td {$valueStyle}>
       {$totalAmount|crmMoney}
     </td>
+  </tr>
+  <tr>
     <td {$labelStyle}>
       {ts}You Paid{/ts}
     </td>
     <td {$valueStyle}>
       {$totalPaid|crmMoney}
     </td>
+  </tr>
+  <tr>
     <td {$labelStyle}>
       {ts}Refund Amount{/ts}
     </td>
index 97ca631c9aa8d27367e72c7cb3d420569540d703..ad48babf26c60af647457d5bc43084623a4b6284 100644 (file)
@@ -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(){
          <div class='crm-section'> 
          <div class='label'>{ts}Updated Fee(s){/ts}</div><div id="pricevalue" class='content updated-fee'></div>
          <div class='label'>{ts}Total Paid{/ts}</div>
-         <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment/view" q="action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
+         <div class='content'><a class='action-item' href='{crmURL p="civicrm/payment" q="view=transaction&action=browse&cid=`$contactId`&id=`$paymentInfo.id`&component=`$paymentInfo.component`&context=transaction"}'>{$paymentInfo.paid|crmMoney}<br/>>> view payments</a>
          </div>
          <div class='label'><strong>{ts}Balance Owed{/ts}</strong></div><div class='content'><strong id='balance-fee'></strong></div>
           </div>
@@ -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();
index d69b32ff7dba9ca3850e56f51c1730e9e9522e8e..450cacdb818e028dd816e33add166099648b7f63 100644 (file)
     <td {$valueStyle}>
       {$totalAmount|crmMoney}
     </td>
+  </tr>
+  <tr>
     <td {$labelStyle}>
       {ts}You Paid{/ts}
     </td>
     <td {$valueStyle}>
       {$totalPaid|crmMoney}
     </td>
+  </tr>
+  <tr>
     <td {$labelStyle}>
       {ts}Refund Amount{/ts}
     </td>