From 52d479ee2b7713f6c31daf86d690a78193b62e28 Mon Sep 17 00:00:00 2001 From: Edsel Date: Tue, 5 Jul 2016 15:27:53 +0530 Subject: [PATCH] CRM-16189 Changed return type from string to bool and updated functions ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Contribute/BAO/Contribution.php | 4 ++-- CRM/Contribute/Form/Contribution.php | 5 ++--- CRM/Financial/BAO/FinancialAccount.php | 7 +++---- tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php | 3 +-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 1c75fa693a..8ffd1c011d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -178,8 +178,8 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } // CRM-16189 - $error = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID); - if ($error) { + if (CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID)) { + $error = ts('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts'); throw new CRM_Core_Exception($error); } if ($contributionID) { diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 998a30440a..2d833b7977 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1009,10 +1009,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $errors['revenue_recognition_date'] = ts('Month and Year are required field for Revenue Recognition.'); } // CRM-16189 - $errorMessage = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self); - if ($errorMessage) { + if (CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self)) { $errors['financial_type_id'] = ' '; - $errors['_qf_default'] = $errorMessage; + $errors['_qf_default'] = ts('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts'); } $errors = array_merge($errors, $softErrors); return $errors; diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index f3aecbf4d0..3a69abde0e 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -366,7 +366,7 @@ LIMIT 1"; * * @param obj $form * - * @return string + * @return bool * */ public static function checkFinancialTypeHasDeferred($params, $contributionID = NULL, $form = NULL) { @@ -380,7 +380,6 @@ LIMIT 1"; return FALSE; } - $message = ts('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts'); $lineItems = CRM_Utils_Array::value('line_item', $params); $financialTypeID = CRM_Utils_Array::value('financial_type_id', $params); if (!$financialTypeID) { @@ -403,13 +402,13 @@ LIMIT 1"; foreach ($lineItems as $lineItem) { foreach ($lineItem as $items) { if (!array_key_exists($items['financial_type_id'], $deferredFinancialType)) { - return $message; + return TRUE; } } } } elseif (!array_key_exists($financialTypeID, $deferredFinancialType)) { - return $message; + return TRUE; } return FALSE; } diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php index 1a987f1e95..8ff81eb7bc 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php @@ -282,8 +282,7 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase { ); $contribution = CRM_Contribute_BAO_Contribution::create($params); $valid = CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contribution->id); - $message = "Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts"; - $this->assertEquals($valid, $message, "The messages do not match"); + $this->assertTrue($valid, "This should have been true."); } /** -- 2.25.1