From 5d4ee51f340ba85f144cc293b9d2fdfa3e165a00 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 26 Apr 2016 18:43:01 +0530 Subject: [PATCH] CRM-18471: format money custom field additional fixes minor fixes minor fix --- CRM/Core/BAO/CustomField.php | 10 ++++++++++ tests/phpunit/CRM/Core/BAO/CustomQueryTest.php | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 13d0568151..f91e8cc9e2 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1250,6 +1250,16 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { case 'TextArea': $display = nl2br($display); break; + + case 'Text': + if ($field['data_type'] == 'Money' && isset($value)) { + //$value can also be an array(while using IN operator from search builder or api). + foreach ((array) $value as $val) { + $disp[] = CRM_Utils_Money::format($val); + } + $display = implode(', ', $disp); + } + break; } return $display; } diff --git a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php index 26629efcaf..b738467ac3 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomQueryTest.php @@ -121,6 +121,11 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { "civicrm_value_testsearchcus_1." . strtolower($type) . "_field_{$customField['id']} BETWEEN \"$from\" AND \"$to\"", $queryObj->_where[0][0] ); + //CRM-18471 - display qill as '$ amount' for money + if ($type == 'Money') { + $from = "$ $from"; + $to = "$ $to"; + } $this->assertEquals($queryObj->_qill[0][0], "$type field BETWEEN $from, $to"); } } @@ -150,7 +155,7 @@ class CRM_Core_BAO_CustomQueryTest extends CiviUnitTestCase { $customFieldName = 'custom_' . $customField['id']; $expectedValue = ($isDate) ? '"20150606235959"' : (($type == 'Money') ? $data : "\"$data\""); - $expectedQillValue = ($isDate) ? "'June 6th, 2015 11:59 PM'" : $data; + $expectedQillValue = ($isDate) ? "'June 6th, 2015 11:59 PM'" : (($type == 'Money') ? "$ $data" : $data); // Assigning the relevant form value to be within a custom key is normally done in // build field params. It would be better if it were all done in convertFormValues -- 2.25.1