From 5471eacc1bb69cc4db6b48ff2dd9c6548ddcae19 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 18 Jan 2018 22:30:55 +1300 Subject: [PATCH] CRM-17647 fix for currency on batch entry --- CRM/Batch/Form/Entry.php | 10 ++++++---- tests/phpunit/CRM/Batch/Form/EntryTest.php | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 9f32025154..d53b4deee7 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -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); diff --git a/tests/phpunit/CRM/Batch/Form/EntryTest.php b/tests/phpunit/CRM/Batch/Form/EntryTest.php index 97a08f6927..816bc8af38 100644 --- a/tests/phpunit/CRM/Batch/Form/EntryTest.php +++ b/tests/phpunit/CRM/Batch/Form/EntryTest.php @@ -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, -- 2.25.1