From b29eb7605df438ab222f1f741d220b145da2f059 Mon Sep 17 00:00:00 2001 From: Jamie McClelland Date: Mon, 30 Jun 2014 13:16:23 -0400 Subject: [PATCH] CRM-14881 - avoid error when saving contribution made by authnet 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index e2623bfc34..4063922d82 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -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'); } } -- 2.25.1