CRM-17647 fix another instance of mishandling thousand separators
authoreileen <emcnaughton@wikimedia.org>
Wed, 7 Feb 2018 08:08:28 +0000 (21:08 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 8 Feb 2018 05:17:38 +0000 (18:17 +1300)
CRM/Batch/Form/Entry.php
tests/phpunit/CRM/Batch/Form/EntryTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index 62ea793b1e055fcc943355af90e386dd64b853f7..1934bcc60f6e623e0ff9b57c348e68936e4c7954 100644 (file)
@@ -82,6 +82,15 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
    */
   public $_fields = array();
 
+  /**
+   * Monetary fields that may be submitted.
+   *
+   * These should get a standardised format in the beginPostProcess function.
+   *
+   * These fields are common to many forms. Some may override this.
+   */
+  protected $submittableMoneyFields = ['total_amount', 'net_amount', 'non_deductible_amount', 'fee_amount'];
+
   /**
    * Build all the data structures needed to build the form.
    */
@@ -443,6 +452,14 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
    */
   private function processContribution(&$params) {
 
+    foreach ($this->submittableMoneyFields as $moneyField) {
+      foreach ($params['field'] as $index => $fieldValues) {
+        if (isset($fieldValues[$moneyField])) {
+          $params['field'][$index][$moneyField] = CRM_Utils_Rule::cleanMoney($params['field'][$index][$moneyField]);
+        }
+      }
+    }
+    $params['actualBatchTotal'] = CRM_Utils_Rule::cleanMoney($params['actualBatchTotal']);
     // get the price set associated with offline contribution record.
     $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
     $this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
@@ -540,6 +557,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
           }
         }
         $value['line_item'] = $lineItem;
+        $value['skipCleanMoney'] = TRUE;
         //finally call contribution create for all the magic
         $contribution = CRM_Contribute_BAO_Contribution::create($value);
         $batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
index 816bc8af3899bf92932405634514d6fc03491210..fbb7a4389bf3b4f6332a11bba409d0c56919f1b6 100644 (file)
@@ -200,8 +200,13 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
 
   /**
    *  Test Contribution Import.
+   *
+   * @param $thousandSeparator
+   *
+   * @dataProvider getThousandSeparators
    */
-  public function testProcessContribution() {
+  public function testProcessContribution($thousandSeparator) {
+    $this->setCurrencySeparators($thousandSeparator);
     $this->offsetDefaultPriceSet();
     $form = new CRM_Batch_Form_Entry();
     $params = $this->getContributionData();
@@ -330,9 +335,11 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
   }
 
   /**
+   * @param $thousandSeparator
+   *
    * @return array
    */
-  public function getContributionData() {
+  public function getContributionData($thousandSeparator = '.') {
     return array(
       //'batch_id' => 4,
       'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
@@ -344,7 +351,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
       'field' => array(
         1 => array(
           'financial_type' => 1,
-          'total_amount' => 15,
+          'total_amount' =>  $this->formatMoneyInput(1500.15),
           'receive_date' => '2013-07-24',
           'receive_date_time' => NULL,
           'payment_instrument' => 1,
@@ -353,7 +360,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
         ),
         2 => array(
           'financial_type' => 1,
-          'total_amount' => 15,
+          'total_amount' => $this->formatMoneyInput(1500.15),
           'receive_date' => '2013-07-24',
           'receive_date_time' => NULL,
           'payment_instrument' => 1,
@@ -361,7 +368,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
           'contribution_status_id' => 1,
         ),
       ),
-      'actualBatchTotal' => 30,
+      'actualBatchTotal' => $this->formatMoneyInput(3000.30),
 
     );
   }
index adaba859a61055febcd6f43353130e6ed5f44eea..e391913537fc7cdb0c4a87064a0cc4c9304b64b4 100644 (file)
@@ -2594,7 +2594,8 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
   }
 
   public function restoreDefaultPriceSetConfig() {
-    CRM_Core_DAO::executeQuery('DELETE FROM civicrm_price_set WHERE id > 2');
+    CRM_Core_DAO::executeQuery("DELETE FROM civicrm_price_set WHERE name NOT IN('default_contribution_amount', 'default_membership_type_amount')");
+    CRM_Core_DAO::executeQuery("UPDATE civicrm_price_set SET id = 1 WHERE name ='default_contribution_amount'");
     CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field` (`id`, `price_set_id`, `name`, `label`, `html_type`, `is_enter_qty`, `help_pre`, `help_post`, `weight`, `is_display_amounts`, `options_per_line`, `is_active`, `is_required`, `active_on`, `expire_on`, `javascript`, `visibility_id`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', 'Text', 0, NULL, NULL, 1, 1, 1, 1, 1, NULL, NULL, NULL, 1)");
     CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field_value` (`id`, `price_field_id`, `name`, `label`, `description`, `amount`, `count`, `max_value`, `weight`, `membership_type_id`, `membership_num_terms`, `is_default`, `is_active`, `financial_type_id`, `non_deductible_amount`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', NULL, '1', NULL, NULL, 1, NULL, NULL, 0, 1, 1, 0.00)");
   }