From f7e2bf4719994d44718f6cc9a8152629d1af4c20 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 27 Jul 2016 19:59:31 +0530 Subject: [PATCH] CRM-16189, called exception in BAO and catched at form level ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Event/BAO/Event.php | 5 +---- CRM/Event/Form/ManageEvent/Fee.php | 8 +++++--- CRM/Financial/BAO/FinancialAccount.php | 2 +- CRM/Member/BAO/MembershipType.php | 9 ++++----- CRM/Member/Form/MembershipType.php | 8 +++++--- CRM/Price/BAO/PriceFieldValue.php | 13 ++++++------- CRM/Price/BAO/PriceSet.php | 9 +++------ CRM/Price/Form/Field.php | 16 ++++++++++------ CRM/Price/Form/Option.php | 8 +++++--- CRM/Price/Form/Set.php | 8 +++++--- 10 files changed, 45 insertions(+), 41 deletions(-) diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 539eb64d41..7fc34e205a 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -97,10 +97,7 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { // CRM-16189 if (!empty($params['financial_type_id'])) { - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']); - if ($isError) { - throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. 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')); - } + CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']); } $event = new CRM_Event_DAO_Event(); diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index c86240e146..b235f9b0ee 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -522,9 +522,11 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { } } // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($values['financial_type_id']); - if ($isError) { - $errors['financial_type_id'] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($values['financial_type_id']); + } + catch (CRM_Core_Exception $e) { + $errors['financial_type_id'] = $e->getMessage(); } return empty($errors) ? TRUE : $errors; } diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 2ec3a4db40..ba39a1350e 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -450,7 +450,7 @@ LIMIT 1"; } $deferredFinancialType = self::getDeferredFinancialType(); if (!array_key_exists($financialTypeId, $deferredFinancialType)) { - return TRUE; + throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. 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')); } return FALSE; } diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index 1d29b8e7aa..322a03521f 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -107,11 +107,10 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { } // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType( - CRM_Utils_Array::value('financial_type_id', $params) - ); - if ($isError) { - throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. 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')); + if (!empty($params['financial_type_id'])) { + CRM_Financial_BAO_FinancialAccount::validateFinancialType( + $params['financial_type_id'] + ); } // action is taken depending upon the mode diff --git a/CRM/Member/Form/MembershipType.php b/CRM/Member/Form/MembershipType.php index 3cd0264a46..baee601fb3 100644 --- a/CRM/Member/Form/MembershipType.php +++ b/CRM/Member/Form/MembershipType.php @@ -283,9 +283,11 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { } // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']); - if ($isError) { - $errors['financial_type_id'] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']); + } + catch (CRM_Core_Exception $e) { + $errors['financial_type_id'] = $e->getMessage(); } return empty($errors) ? TRUE : $errors; diff --git a/CRM/Price/BAO/PriceFieldValue.php b/CRM/Price/BAO/PriceFieldValue.php index 9a6fdf979c..d3ed23c70f 100644 --- a/CRM/Price/BAO/PriceFieldValue.php +++ b/CRM/Price/BAO/PriceFieldValue.php @@ -66,13 +66,12 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue { if (!$priceFieldID) { $priceFieldID = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $id, 'price_field_id'); } - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType( - CRM_Utils_Array::value('financial_type_id', $params), - $priceFieldID, - 'PriceField' - ); - if ($isError) { - throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. 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')); + if (!empty($params['financial_type_id'])) { + CRM_Financial_BAO_FinancialAccount::validateFinancialType( + $params['financial_type_id'], + $priceFieldID, + 'PriceField' + ); } if (!empty($params['is_default'])) { $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1'; diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 74e3e5da46..4b2922c51c 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -79,14 +79,11 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { $priceSetID = CRM_Utils_Array::value('id', $params); } // CRM-16189 - if ($validatePriceSet) { - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType( - CRM_Utils_Array::value('financial_type_id', $params), + if ($validatePriceSet && !empty($params['financial_type_id'])) { + CRM_Financial_BAO_FinancialAccount::validateFinancialType( + $params['financial_type_id'], $priceSetID ); - if ($isError) { - throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. 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')); - } } $priceSetBAO = new CRM_Price_BAO_PriceSet(); $priceSetBAO->copyValues($params); diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index 57c4f09d47..2e0fb425a6 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -409,9 +409,11 @@ class CRM_Price_Form_Field extends CRM_Core_Form { } else { // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_sid); - if ($isError) { - $errors['financial_type_id'] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_sid); + } + catch (CRM_Core_Exception $e) { + $errors['financial_type_id'] = $e->getMessage(); } } } @@ -531,9 +533,11 @@ class CRM_Price_Form_Field extends CRM_Core_Form { $_flagOption = $_emptyRow = 0; // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['option_financial_type_id'][$index], $form->_fid, 'PriceField'); - if ($isError) { - $errors["option_financial_type_id[{$index}]"] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['option_financial_type_id'][$index], $form->_fid, 'PriceField'); + } + catch(CRM_Core_Exception $e) { + $errors["option_financial_type_id[{$index}]"] = $e->getMessage(); } } diff --git a/CRM/Price/Form/Option.php b/CRM/Price/Form/Option.php index e61012232f..81b994f4ce 100644 --- a/CRM/Price/Form/Option.php +++ b/CRM/Price/Form/Option.php @@ -286,9 +286,11 @@ class CRM_Price_Form_Option extends CRM_Core_Form { $errors['count'] = ts('Participant count can not be greater than max participants.'); } // CRM-16189 - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_fid, 'PriceField'); - if ($isError) { - $errors['financial_type_id'] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_fid, 'PriceField'); + } + catch (CRM_Core_Exception $e) { + $errors['financial_type_id'] = $e->getMessage(); } return empty($errors) ? TRUE : $errors; } diff --git a/CRM/Price/Form/Set.php b/CRM/Price/Form/Set.php index b78bc7de04..90d9be60fd 100644 --- a/CRM/Price/Form/Set.php +++ b/CRM/Price/Form/Set.php @@ -107,9 +107,11 @@ class CRM_Price_Form_Set extends CRM_Core_Form { && (array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $fields['extends']) || array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $fields['extends'])) ) { - $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id']); - if ($isError) { - $errors['financial_type_id'] = ts('Deferred revenue account is not configured for selected financial type. 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'); + try { + CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id']); + } + catch (CRM_Core_Exception $e) { + $errors['financial_type_id'] = $e->getMessage(); } } return empty($errors) ? TRUE : $errors; -- 2.25.1