Skip to content

Commit

Permalink
CRM-16189 Changed return type from string to bool and updated functions
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189
  • Loading branch information
Edzelopez committed Jul 6, 2016
1 parent 15aac0f commit 3d0cc8f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ public static function add(&$params, $ids = array()) {
}

// 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) {
Expand Down
5 changes: 2 additions & 3 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,9 @@ public static function formRule($fields, $files, $self) {
$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;
Expand Down
7 changes: 3 additions & 4 deletions CRM/Financial/BAO/FinancialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static function validateFinancialAccount($financialAccountId, $financialA
*
* @param obj $form
*
* @return string
* @return bool
*
*/
public static function checkFinancialTypeHasDeferred($params, $contributionID = NULL, $form = NULL) {
Expand All @@ -380,7 +380,6 @@ public static function checkFinancialTypeHasDeferred($params, $contributionID =
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) {
Expand All @@ -403,13 +402,13 @@ public static function checkFinancialTypeHasDeferred($params, $contributionID =
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;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ public function testcheckFinancialTypeHasDeferred() {
);
$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.");
}

/**
Expand Down

0 comments on commit 3d0cc8f

Please sign in to comment.