Merge pull request #1641 from PalanteJon/CRM-13396
[civicrm-core.git] / CRM / Contribute / Form / SoftCredit.php
index ea22b5e93f4e53ad21a6649d5a65589348ddee30..bb1686d410d347519054efe5f363f036ca2bcb35 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -65,7 +65,7 @@ class CRM_Contribute_Form_SoftCredit {
     for ($rowNumber = 1; $rowNumber <= $item_count; $rowNumber++) {
       CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, $prefix);
 
-      $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'));
+      $form->addMoney("{$prefix}amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE);
       if (!empty($form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id'])) {
         $form->add('hidden', "{$prefix}id[{$rowNumber}]",
           $form->_softCreditInfo['soft_credit'][$rowNumber]['soft_credit_id']);
@@ -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])) {