From: Pradeep Nayak Date: Wed, 27 Jul 2016 12:55:32 +0000 (+0530) Subject: CRM-16189, updated function to throw exception in BAO and catch in form level X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9603974919118462a1b513e33a1526e933a90b69;p=civicrm-core.git CRM-16189, updated function to throw exception in BAO and catch in form level ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8ffd1c011d..092e8875e8 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -178,10 +178,8 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { } // CRM-16189 - 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); - } + CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID); + if ($contributionID) { CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params); } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 94f9bb5ae1..7d65913dd7 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1009,9 +1009,12 @@ 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 - if (CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self->_priceSet['fields'])) { + try { + CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($fields, $self->_id, $self->_priceSet['fields']); + } + catch (CRM_Core_Exception $e) { $errors['financial_type_id'] = ' '; - $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['_qf_default'] = $e->getMessage(); } $errors = array_merge($errors, $softErrors); return $errors; diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index f02a4716ef..aea07d410f 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -401,19 +401,25 @@ LIMIT 1"; } } $deferredFinancialType = self::getDeferredFinancialType(); + $isError = FALSE; if (!empty($lineItems)) { foreach ($lineItems as $lineItem) { foreach ($lineItem as $items) { if (!array_key_exists($items['financial_type_id'], $deferredFinancialType)) { - return TRUE; + $isError = TRUE; } } } } elseif (!array_key_exists($financialTypeID, $deferredFinancialType)) { - return TRUE; + $isError = TRUE; } - return FALSE; + + if ($isError) { + $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); + } + return $isError; } /**