From ccaca683b639f35c7b26bdb6703095fe5f0ffb9d Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 15 Jun 2016 20:17:53 +0530 Subject: [PATCH] CRM-16189, added function to validate relationship between financial account and financial type ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Financial/BAO/FinancialTypeAccount.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index c34235e6e2..bc1f36da0d 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -297,4 +297,23 @@ WHERE cog.name = 'payment_instrument' "; return $titles; } + /** + * Validate account relationship with financial account type + * + * @param $financialTypeAccount obj + * + * @return Bool + */ + public static function validateRelationship($financialTypeAccount) { + $financialAccountLinks = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations(); + $financialAccountType = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $financialTypeAccount->financial_account_id, 'financial_account_type_id'); + if (CRM_Utils_Array::value($financialTypeAccount->account_relationship, $financialAccountLinks) != $financialAccountType) { + $accountRelationships = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); + $params = array( + 1 => $accountRelationships[$financialTypeAccount->account_relationship], + ); + throw new Exception(ts("This financial account cannot have '%1' relationship.", $params)); + } + } + } -- 2.25.1