CRM-14881 - avoid error when saving contribution made by authnet
authorJamie McClelland <jm@mayfirst.org>
Mon, 30 Jun 2014 17:16:23 +0000 (13:16 -0400)
committerJamie McClelland <jm@mayfirst.org>
Mon, 30 Jun 2014 17:16:23 +0000 (13:16 -0400)
We should only check the sum of the fee and net if there is a fee
and/or net that is not equal to 0.00.

----------------------------------------
* CRM-14881: Cannot edit contribution created by authorize.net recurring contribution
  https://issues.civicrm.org/jira/browse/CRM-14881

CRM/Contribute/Form/Contribution.php

index e2623bfc340229fc5c8cfd3089f1d4b267043371..4063922d822e594c1b40df98d1e84f35b3e12f0d 100644 (file)
@@ -952,10 +952,24 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
-
-    if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
-      $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
-      if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
+   
+    // If we have a net amount or fee amount that is NOT set to 0.00, then ensure
+    // that the net_amount + the fee_amount is equal to the total amount.
+    $total_amount = NULL;
+    if(!empty($fields['total_amount']) && $fields['total_amount'] != '0.00') {
+      $total_amount = $fields['total_amount'];
+    }
+    $fee_amount = NULL;
+    if(!empty($fields['fee_amount']) && $fields['fee_amount'] != '0.00') {
+      $fee_amount = $fields['fee_amount'];
+    }
+    $net_amount = NULL;
+    if(!empty($fields['net_amount']) && $fields['net_amount'] != '0.00') {
+      $net_amount = $fields['net_amount'];
+    }
+    if ($total_amount && ($net_amount || $fee_amount)) {
+      $sum = CRM_Utils_Rule::cleanMoney($net_amount) + CRM_Utils_Rule::cleanMoney($fee_amount);
+      if (CRM_Utils_Rule::cleanMoney($total_amount) != $sum) {
         $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
       }
     }