From 0689c15ca065e4f288b365f79740a639ef508943 Mon Sep 17 00:00:00 2001 From: Ravish Nair Date: Wed, 12 Jun 2013 20:13:49 +0530 Subject: [PATCH] -- CRM-12653 some more fixes ---------------------------------------- * CRM-12653: Add Soft Credit Amount Field to Batch Data Entry http://issues.civicrm.org/jira/browse/CRM-12653 --- CRM/Batch/Form/Entry.php | 6 +++--- CRM/Contribute/Form/Contribution.php | 5 +++-- CRM/Contribute/Form/SoftCredit.php | 5 +++-- templates/CRM/Batch/Form/Entry.tpl | 2 +- templates/CRM/Contribute/Form/SoftCredit.js | 6 ++++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index f7f9ef5b12..58c85a9788 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -239,7 +239,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $errors["soft_credit_amount[$key]"] = ts('Please enter the soft credit amount'); } if (CRM_Utils_Array::value($key, $params['soft_credit_amount']) - && (CRM_Utils_Array::value($key, $params['soft_credit_amount']) > CRM_Utils_Rule::cleanMoney($value['total_amount']))) { + && CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value($key, $params['soft_credit_amount'])) > CRM_Utils_Rule::cleanMoney($value['total_amount'])) { $errors["soft_credit_amount[$key]"] = ts('Soft credit amount should not be greater than the total amount'); } @@ -390,7 +390,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { //build soft credit params if (CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id']) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_select_id'][$key]; - $value['soft_credit'][$key]['amount'] = $params['soft_credit_amount'][$key]; + $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); } $value['custom'] = CRM_Core_BAO_CustomField::postProcess($value, @@ -604,7 +604,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { // handle soft credit if (CRM_Utils_Array::value($key, $params['soft_credit_contact_select_id']) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_select_id'][$key]; - $value['soft_credit'][$key]['amount'] = $params['soft_credit_amount'][$key]; + $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); } if ( CRM_Utils_Array::value('receive_date', $value) ) { diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 0a3a160967..b951b772b3 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -170,8 +170,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return; } + $config = CRM_Core_Config::singleton(); $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js'); + $resources->addSetting(array('monetaryThousandSeparator' => $config->monetaryThousandSeparator)); $this->_formType = CRM_Utils_Array::value('formType', $_GET); @@ -232,7 +234,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP return; } - $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && !$this->_formType) { $this->preProcessPledge(); } @@ -1092,7 +1093,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP foreach ($submittedValues['soft_credit_contact_select_id'] as $key => $val) { if ($val && $submittedValues['soft_credit_amount'][$key]) { $softParams[$key]['contact_id'] = $val; - $softParams[$key]['amount'] = $submittedValues['soft_credit_amount'][$key]; + $softParams[$key]['amount'] = CRM_Utils_Rule::cleanMoney($submittedValues['soft_credit_amount'][$key]); if (!empty($submittedValues['soft_credit_id'][$key])) { $softIDs[] = $softParams[$key]['id'] = $submittedValues['soft_credit_id'][$key]; } diff --git a/CRM/Contribute/Form/SoftCredit.php b/CRM/Contribute/Form/SoftCredit.php index 40e5658c86..e57d8623bd 100644 --- a/CRM/Contribute/Form/SoftCredit.php +++ b/CRM/Contribute/Form/SoftCredit.php @@ -103,7 +103,7 @@ class CRM_Contribute_Form_SoftCredit { static function setDefaultValues(&$defaults, &$form) { if (!empty($form->_softCreditInfo['soft_credit'])) { foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) { - $defaults["soft_credit_amount[$key]"] = $value['amount']; + $defaults["soft_credit_amount[$key]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a'); $defaults["soft_credit_contact_select_id[$key]"] = $value['contact_id']; } } @@ -150,7 +150,8 @@ class CRM_Contribute_Form_SoftCredit { if ($repeat[$fields['soft_credit_contact_select_id'][$key]] > 1) { $errors["soft_credit_contact_select_id[$key]"] = ts('You cannot enter multiple soft credits for the same contact.'); } - if ($fields['soft_credit_amount'][$key] && ($fields['soft_credit_amount'][$key] > $fields['total_amount'])) { + if ($fields['soft_credit_amount'][$key] + && (CRM_Utils_Rule::cleanMoney($fields['soft_credit_amount'][$key]) > CRM_Utils_Rule::cleanMoney($fields['total_amount']))) { $errors["soft_credit_amount[$key]"] = ts('Soft credit amount cannot be more than the total amount.'); } if (empty($fields['soft_credit_amount'][$key])) { diff --git a/templates/CRM/Batch/Form/Entry.tpl b/templates/CRM/Batch/Form/Entry.tpl index b730f558a9..7031ab00e5 100644 --- a/templates/CRM/Batch/Form/Entry.tpl +++ b/templates/CRM/Batch/Form/Entry.tpl @@ -99,7 +99,7 @@ cj('input[name^="soft_credit_contact["]').change(function(){ var rowNum = cj(this).attr('id').replace('soft_credit_contact_',''); - var totalAmount = Number(cj('#field_'+rowNum+'_total_amount').val().replace(',','')); + var totalAmount = cj('#field_'+rowNum+'_total_amount').val(); //assign total amount as default soft credit amount cj('#soft_credit_amount_'+ rowNum).val(totalAmount); }); diff --git a/templates/CRM/Contribute/Form/SoftCredit.js b/templates/CRM/Contribute/Form/SoftCredit.js index 1ae27c2358..42225066be 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.js +++ b/templates/CRM/Contribute/Form/SoftCredit.js @@ -59,11 +59,13 @@ cj(function($) { $('input[name^="soft_credit_contact["]').change(function(){ var rowNum = $(this).attr('id').replace('soft_credit_contact_',''); - var totalAmount = Number($('#total_amount').val().replace(',','')); + var totalAmount = $('#total_amount').val(); //assign total amount as default soft credit amount $('#soft_credit_amount_'+ rowNum).val(totalAmount); + var thousandMarker = CRM.monetaryThousandSeparator; + totalAmount = Number(totalAmount.replace(thousandMarker,'')); if (rowNum > 1) { - var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val()); + var scAmount = Number($('#soft_credit_amount_'+ (rowNum - 1)).val().replace(thousandMarker,'')); if (scAmount < totalAmount) { //if user enters less than the total amount and adds another soft credit row, //the soft credit amount default will be left empty -- 2.25.1