Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-17647 fix for currency on batch entry #11549

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,9 @@ public function buildQuickForm() {
}
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);
Expand Down Expand Up @@ -187,7 +185,6 @@ public function buildQuickForm() {

$this->assign('rowCount', $this->_batchInfo['item_count'] + 1);

$fileFieldExists = FALSE;
$preserveDefaultsArray = array(
'first_name',
'last_name',
Expand All @@ -198,7 +195,6 @@ public function buildQuickForm() {

$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(
Expand Down Expand Up @@ -633,6 +629,11 @@ private function processMembership(&$params) {
// @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;
Expand Down Expand Up @@ -790,6 +791,7 @@ private function processMembership(&$params) {

// 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);
Expand Down
20 changes: 15 additions & 5 deletions tests/phpunit/CRM/Batch/Form/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setUp() {
$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',
Expand Down Expand Up @@ -156,9 +156,18 @@ public function tearDown() {

/**
* 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());
Expand All @@ -184,6 +193,7 @@ public function testProcessMembership() {
'return' => 'line_total',

)), $contribution['total_amount']);
$this->assertEquals(1500, $contribution['total_amount']);
$this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
}
}
Expand Down Expand Up @@ -273,7 +283,7 @@ public function getMembershipData() {
'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,
Expand All @@ -288,7 +298,7 @@ public function getMembershipData() {
'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,
Expand All @@ -304,7 +314,7 @@ public function getMembershipData() {
'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,
Expand Down