CRM-17647 fix for currency on batch entry
authoreileen <emcnaughton@wikimedia.org>
Thu, 18 Jan 2018 09:30:55 +0000 (22:30 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 18 Jan 2018 09:31:32 +0000 (22:31 +1300)
CRM/Batch/Form/Entry.php
tests/phpunit/CRM/Batch/Form/EntryTest.php

index 9f320251544cd2aca5940f13b0dfd9e29f90d560..d53b4deee740b7fd62de84bf80e42f3aecb645cc 100644 (file)
@@ -135,11 +135,9 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
     }
     elseif ($this->_batchInfo['type_id'] == $batchTypes['Membership']) {
       CRM_Utils_System::setTitle(ts('Batch Data Entry for Memberships'));
-      $customFields = CRM_Core_BAO_CustomField::getFields('Membership');
     }
     elseif ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment']) {
       CRM_Utils_System::setTitle(ts('Batch Data Entry for Pledge Payments'));
-      $customFields = CRM_Core_BAO_CustomField::getFields('Contribution');
     }
     $this->_fields = array();
     $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW);
@@ -187,7 +185,6 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
 
     $this->assign('rowCount', $this->_batchInfo['item_count'] + 1);
 
-    $fileFieldExists = FALSE;
     $preserveDefaultsArray = array(
       'first_name',
       'last_name',
@@ -198,7 +195,6 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
 
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $contactReturnProperties = array();
-    $config = CRM_Core_Config::singleton();
 
     for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) {
       $this->addEntityRef("primary_contact_id[{$rowNumber}]", '', array(
@@ -633,6 +629,11 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
       // @todo - most of the wrangling in this function is because the api is not being used, especially date stuff.
       $customFields = array();
       foreach ($params['field'] as $key => $value) {
+        foreach ($value as $fieldKey => $fieldValue) {
+          if (isset($this->_fields[$fieldKey]) && $this->_fields[$fieldKey]['data_type'] === 'Money') {
+            $value[$fieldKey] = CRM_Utils_Rule::cleanMoney($fieldValue);
+          }
+        }
         // if contact is not selected we should skip the row
         if (empty($params['primary_contact_id'][$key])) {
           continue;
@@ -790,6 +791,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
 
           // make contribution entry
           $contrbutionParams = array_merge($value, array('membership_id' => $membership->id));
+          $contrbutionParams['skipCleanMoney'] = TRUE;
           // @todo - calling this from here is pretty hacky since it is called from membership.create anyway
           // This form should set the correct params & not call this fn directly.
           CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams);
index 97a08f692754c0cba2c779feccf7e952c3ede14b..816bc8af3899bf92932405634514d6fc03491210 100644 (file)
@@ -83,7 +83,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
     $params = array(
       'name' => $this->_membershipTypeName,
       'description' => NULL,
-      'minimum_fee' => 10,
+      'minimum_fee' => 1500,
       'duration_unit' => 'year',
       'member_of_contact_id' => $this->_orgContactID,
       'period_type' => 'fixed',
@@ -156,9 +156,18 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
 
   /**
    *  Test Import.
+   *
+   * @param string $thousandSeparator
+   *
+   * @dataProvider getThousandSeparators
    */
-  public function testProcessMembership() {
+  public function testProcessMembership($thousandSeparator) {
+    $this->setCurrencySeparators($thousandSeparator);
+
     $form = new CRM_Batch_Form_Entry();
+    $profileID = $this->callAPISuccessGetValue('UFGroup', ['return' => 'id', 'name' => 'membership_batch_entry']);
+    $form->_fields = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::VIEW);
+
     $params = $this->getMembershipData();
     $this->assertTrue($form->testProcessMembership($params));
     $result = $this->callAPISuccess('membership', 'get', array());
@@ -184,6 +193,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
         'return' => 'line_total',
 
       )), $contribution['total_amount']);
+      $this->assertEquals(1500, $contribution['total_amount']);
       $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
     }
   }
@@ -273,7 +283,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
           'membership_end_date' => NULL,
           'membership_source' => NULL,
           'financial_type' => 2,
-          'total_amount' => 1,
+          'total_amount' => $this->formatMoneyInput(1500),
           'receive_date' => '2013-07-24',
           'receive_date_time' => NULL,
           'payment_instrument' => 1,
@@ -288,7 +298,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
           'membership_end_date' => NULL,
           'membership_source' => NULL,
           'financial_type' => 2,
-          'total_amount' => 1,
+          'total_amount' => $this->formatMoneyInput(1500),
           'receive_date' => '2013-07-17',
           'receive_date_time' => NULL,
           'payment_instrument' => NULL,
@@ -304,7 +314,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
           'membership_end_date' => '2013-12-01',
           'membership_source' => NULL,
           'financial_type' => 2,
-          'total_amount' => 1,
+          'total_amount' => $this->formatMoneyInput(1500),
           'receive_date' => '2013-07-17',
           'receive_date_time' => NULL,
           'payment_instrument' => NULL,