CRM-21756: Freeze total amount field on Edit Contribution if related to membership...
authordeb.monish <monish.deb@jmaconsulting.biz>
Wed, 7 Mar 2018 14:03:27 +0000 (19:33 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Wed, 7 Mar 2018 14:03:27 +0000 (19:33 +0530)
CRM/Contribute/Form/Contribution.php
templates/CRM/Contribute/Form/Contribution.tpl
templates/CRM/Contribute/Page/Tab.hlp

index 1a3ac14f9aff00583935d207d3fee9303e380e8d..8bc4c44c07416a7007c4505851a197bc600f9786 100644 (file)
@@ -646,6 +646,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
 
     $component = 'contribution';
+    $componentDetails = [];
     if ($this->_id) {
       $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
       if (CRM_Utils_Array::value('membership', $componentDetails)) {
@@ -712,7 +713,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
       // and if we already have line items for that participant. CRM-5095
       if ($buildPriceSet && $this->_id) {
-        $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
           $this->_id,
           'id',
@@ -811,23 +811,24 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       )
     );
 
-    // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
-    // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
-    if ($this->_id && ($this->_values['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'))) {
-      if ($totalAmount) {
-        $totalAmount->freeze();
-      }
-      $paymentInstrument->freeze();
-      $trxnId->freeze();
-      $financialType->freeze();
-    }
-
     // if contribution is related to membership or participant freeze Financial Type, Amount
-    if ($this->_id && isset($this->_values['tax_amount'])) {
+    if ($this->_id) {
       $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
-      if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
+      $isCancelledStatus = ($this->_values['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'));
+
+      if (CRM_Utils_Array::value('membership', $componentDetails) ||
+        CRM_Utils_Array::value('participant', $componentDetails) ||
+        // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
+        // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
+        $isCancelledStatus
+      ) {
         if ($totalAmount) {
           $totalAmount->freeze();
+          $this->getElement('currency')->freeze();
+        }
+        if ($isCancelledStatus) {
+          $paymentInstrument->freeze();
+          $trxnId->freeze();
         }
         $financialType->freeze();
         $this->assign('freezeFinancialType', TRUE);
index 9f47e46eaead9a61523a0acbcbb18b573326e1cc..da7bb1bb8f985fbd72bd20891e929af017ea9eec 100644 (file)
@@ -97,6 +97,9 @@
       <td class="label">{$form.total_amount.label}</td>
       <td {$valueStyle}>
         <span id='totalAmount'>{$form.currency.html|crmAddClass:eight}&nbsp;{$form.total_amount.html|crmAddClass:eight}</span>
+        {if $freezeFinancialType}
+          {help id="id-total_amount"}
+        {/if}
         {if !$payNow}
           {if $hasPriceSets}
             <span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
index 435c41e4fa5d5406597ae71f5f9972edee45f203..630a0fb4c753d1c96316c3e30d91d8a6945138c6 100644 (file)
 {ts}Optional identifier for the contribution source (campaign name, event, mailer, etc.).{/ts}
 {/htxt}
 
+{htxt id="id-total_amount-title"}
+  {ts}Total Amount{/ts}
+{/htxt}
+{htxt id="id-total_amount"}
+{ts 1='target="_blank" href="https://civicrm.org/extensions/line-item-editor"'}You are not allowed to change the total amount as it will lead to incorrect line item entries. You can either delete or recreate or install <a %1>Line Item Editor</a>.{/ts}
+{/htxt}
+
 {htxt id="id-financial_type-title"}
   {ts}Financial Type{/ts}
 {/htxt}
@@ -78,7 +85,7 @@
 <p>
 {ts}When contributions are made via a Personal Campaign Page a soft credit (of type 'Personal Campaign Page') is automatically created and assigned to the 'owner' of the the Personal Campaign Page.{/ts}
 </p>
-{/htxt} 
+{/htxt}
 
 {htxt id="adjust-payment-amount-title"}
   {ts}Payment Amount{/ts}