From 7611ae7123cf09aa527ab9a24ad779c0be932df9 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Thu, 2 May 2013 21:43:48 -0700 Subject: [PATCH] Refactored out of CRM_Core_PseudoConstant: accountOptionValues(). CRM-12464 ---------------------------------------- * CRM-12464: Search improvements in 4.4 http://issues.civicrm.org/jira/browse/CRM-12464 ---------------------------------------- * CRM-12464: http://issues.civicrm.org/jira/browse/CRM-12464 * CRM-12464:: http://issues.civicrm.org/jira/browse/CRM-12464: --- CRM/Admin/Form/OptionValue.php | 4 +- CRM/Admin/Form/Options.php | 4 +- CRM/Admin/Form/PaymentProcessor.php | 4 +- CRM/Batch/BAO/Batch.php | 2 +- CRM/Batch/Form/Entry.php | 2 - CRM/Contribute/BAO/Contribution.php | 9 ++--- CRM/Core/BAO/FinancialTrxn.php | 4 +- CRM/Event/BAO/Participant.php | 2 +- CRM/Financial/BAO/FinancialAccount.php | 2 +- CRM/Financial/BAO/FinancialItem.php | 2 +- CRM/Financial/BAO/FinancialType.php | 2 +- CRM/Financial/BAO/FinancialTypeAccount.php | 2 +- CRM/Financial/BAO/PaymentProcessor.php | 2 +- CRM/Financial/Form/Export.php | 2 +- CRM/Financial/Form/FinancialAccount.php | 2 +- CRM/Financial/Form/FinancialBatch.php | 4 +- CRM/Financial/Form/FinancialTypeAccount.php | 5 +-- CRM/Financial/Page/AJAX.php | 6 +-- CRM/Financial/Page/FinancialAccount.php | 2 +- CRM/Financial/Page/FinancialTypeAccount.php | 4 +- CRM/Upgrade/Incremental/php/FourThree.php | 6 +-- tests/phpunit/CRM/Core/PseudoConstantTest.php | 40 +++++++++++++++++++ .../BAO/FinancialTypeAccountTest.php | 8 ++-- tests/phpunit/api/v3/ContributionTest.php | 4 +- .../Financial/EntityFinancialAccount.xml | 8 ++++ xml/schema/Financial/FinancialAccount.xml | 3 ++ xml/schema/Financial/FinancialItem.xml | 8 ++++ xml/schema/Financial/FinancialTrxn.xml | 10 +++++ 28 files changed, 109 insertions(+), 44 deletions(-) diff --git a/CRM/Admin/Form/OptionValue.php b/CRM/Admin/Form/OptionValue.php index 9cd7e54a4f..5aab18f425 100644 --- a/CRM/Admin/Form/OptionValue.php +++ b/CRM/Admin/Form/OptionValue.php @@ -162,7 +162,7 @@ class CRM_Admin_Form_OptionValue extends CRM_Admin_Form { // CRM-11516 if ($this->_gName == 'payment_instrument') { - $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "); + $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' ")); $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType)); $this->add('select', 'financial_account_id', ts('Financial Account'), @@ -272,7 +272,7 @@ class CRM_Admin_Form_OptionValue extends CRM_Admin_Form { $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); // CRM-11516 if (CRM_Utils_Array::value('financial_account_id', $params)) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $params = array( 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 32ae6c12f8..9924d0cca0 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -190,7 +190,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { } // CRM-11516 if ($this->_gName == 'payment_instrument') { - $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "); + $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' ")); $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType)); $this->add('select', 'financial_account_id', ts('Financial Account'), @@ -405,7 +405,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { // CRM-11516 if (CRM_Utils_Array::value('financial_account_id', $params)) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $params = array( 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, diff --git a/CRM/Admin/Form/PaymentProcessor.php b/CRM/Admin/Form/PaymentProcessor.php index bc34146d0e..7a24c53f20 100644 --- a/CRM/Admin/Form/PaymentProcessor.php +++ b/CRM/Admin/Form/PaymentProcessor.php @@ -189,7 +189,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { ); // Financial Account of account type asset CRM-11515 - $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "); + $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' ")); $financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType)); if ($fcount = count($financialAccount)) { $this->assign('financialAccount', $fcount); @@ -380,7 +380,7 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form { //CRM-11515 - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $params = array( 'entity_table' => 'civicrm_payment_processor', 'entity_id' => $dao->id, diff --git a/CRM/Batch/BAO/Batch.php b/CRM/Batch/BAO/Batch.php index 706e4b93f1..040794be27 100644 --- a/CRM/Batch/BAO/Batch.php +++ b/CRM/Batch/BAO/Batch.php @@ -596,7 +596,7 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch { } static function closeReOpen($batchIds = array(), $status) { - $batchStatus = CRM_Core_PseudoConstant::accountOptionValues( 'batch_status' ); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $params['status_id'] = CRM_Utils_Array::key( $status, $batchStatus ); $session = CRM_Core_Session::singleton( ); $params['modified_date'] = date('YmdHis'); diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index 2bdd049f2a..ecf467447f 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -366,8 +366,6 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { $this->_priceSet = current(CRM_Price_BAO_Set::getSetDetail($priceSetId)); $fieldID = key($this->_priceSet['fields']); - $assetRelation = key(CRM_CORE_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); - if (isset($params['field'])) { foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6e56b0c763..aa589ef12e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2505,7 +2505,7 @@ WHERE contribution_id = %1 "; !(CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses) && !$params['contribution']->is_pay_later)) { $skipRecords = TRUE; if (CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Pending', $contributionStatuses)) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' "))); $params['to_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); } elseif (CRM_Utils_Array::value('payment_processor', $params)) { @@ -2597,7 +2597,7 @@ WHERE contribution_id = %1 "; //if financial type is changed if (CRM_Utils_Array::value('financial_type_id', $params) && $params['contribution']->financial_type_id != $params['prevContribution']->financial_type_id) { - $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); + $incomeTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' "))); $oldFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $incomeTypeId); $newFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $incomeTypeId); if ($oldFinancialAccount != $newFinancialAccount) { @@ -2689,8 +2689,7 @@ WHERE contribution_id = %1 "; $params['trxnParams']['to_financial_account_id'] = NULL; $params['trxnParams']['total_amount'] = - $params['total_amount']; } - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, - " AND v.name LIKE 'Accounts Receivable Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' "))); $params['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType( $financialTypeID, $relationTypeId); } @@ -2700,7 +2699,7 @@ WHERE contribution_id = %1 "; if ($params['prevContribution']->payment_instrument_id != null && $params['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatus) && $params['contribution']->contribution_status_id == array_search('Pending', $contributionStatus)) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' "))); $params['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id'], $relationTypeId); } elseif ($params['prevContribution']->payment_instrument_id != null) { diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 95a675df66..90827d7d33 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -286,7 +286,7 @@ WHERE ceft.entity_id = %1"; if (CRM_Utils_Array::value('cost', $params)) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $financialAccountType = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id']); - $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND label IN ('Premiums Inventory Account is', 'Cost of Sales Account is')"); + $accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND label IN ('Premiums Inventory Account is', 'Cost of Sales Account is')")); $toFinancialAccount = CRM_Utils_Array::value('isDeleted', $params) ? 'Premiums Inventory Account is' : 'Cost of Sales Account is'; $fromFinancialAccount = CRM_Utils_Array::value('isDeleted', $params) ? 'Cost of Sales Account is': 'Premiums Inventory Account is'; $accountRelationship = array_flip($accountRelationship); @@ -329,7 +329,7 @@ WHERE ceft.entity_id = %1"; */ static function recordFees($params) { - $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); + $expenseTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Expense Account is' "))); $domainId = CRM_Core_Config::domainID(); $amount = 0; if (CRM_Utils_Array::value('prevContribution', $params)) { diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 134e56e3e8..a0c77f3b80 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1745,7 +1745,7 @@ WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2"; $params = array(1 => array($priceSetId, 'Integer'), 2 => array($feeLevel, 'String')); $mainAmount = CRM_Core_DAO::singleValueQuery($query, $params); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Discounts Account is' "))); $contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType( $contributionParams['contribution']->financial_type_id, $relationTypeId); if (CRM_Utils_Array::value('from_financial_account_id', $contributionParams['trxnParams'])) { diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 9c53bf618e..dec66f2ee9 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -159,7 +159,7 @@ class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAcco * @static */ static function getAccountingCode($financialTypeId) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' "))); $query = "SELECT cfa.accounting_code FROM civicrm_financial_type cft LEFT JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cft.id AND cefa.entity_table = 'civicrm_financial_type' diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 6db9134a47..76d1fff87b 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -78,7 +78,7 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem { */ static function add($lineItem, $contribution) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - $financialItemStatus = CRM_Core_PseudoConstant::accountOptionValues('financial_item_status'); + $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); if ($contribution->contribution_status_id == array_search('Completed', $contributionStatuses)) { $itemStatus = array_search('Paid', $financialItemStatus); } diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index 197474f4d6..f90af7732d 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -171,7 +171,7 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { // Financial Type $financialType = CRM_Contribute_PseudoConstant::financialType(); $revenueFinancialType = array(); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' "))); CRM_Core_PseudoConstant::populate( $revenueFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', diff --git a/CRM/Financial/BAO/FinancialTypeAccount.php b/CRM/Financial/BAO/FinancialTypeAccount.php index d4e74c0f6c..e542d00161 100644 --- a/CRM/Financial/BAO/FinancialTypeAccount.php +++ b/CRM/Financial/BAO/FinancialTypeAccount.php @@ -112,7 +112,7 @@ class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFin static function del($financialTypeAccountId, $accountId = null) { //checking if financial type is present $check = false; - $relationValues = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); $financialTypeId = CRM_Core_DAO::getFieldValue( 'CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id' ); //check dependencies diff --git a/CRM/Financial/BAO/PaymentProcessor.php b/CRM/Financial/BAO/PaymentProcessor.php index e536683819..2e3da2a8af 100644 --- a/CRM/Financial/BAO/PaymentProcessor.php +++ b/CRM/Financial/BAO/PaymentProcessor.php @@ -69,7 +69,7 @@ class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProces // CRM-11826, add entry in civicrm_entity_financial_account // if financial_account_id is not NULL if (CRM_Utils_Array::value('financial_account_id', $params)) { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $values = array( 'entity_table' => 'civicrm_payment_processor', 'entity_id' => $processor->id, diff --git a/CRM/Financial/Form/Export.php b/CRM/Financial/Form/Export.php index 99a4cca314..b9b989a10a 100644 --- a/CRM/Financial/Form/Export.php +++ b/CRM/Financial/Form/Export.php @@ -95,7 +95,7 @@ class CRM_Financial_Form_Export extends CRM_Core_Form { $this->_batchIds = $this->_id; } - $allBatchStatus = CRM_Core_PseudoConstant::accountOptionValues('batch_status'); + $allBatchStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $this->_exportStatusId = CRM_Utils_Array::key('Exported', $allBatchStatus); //check if batch status is valid, do not allow exported batches to export again diff --git a/CRM/Financial/Form/FinancialAccount.php b/CRM/Financial/Form/FinancialAccount.php index c418a31580..a970104d97 100644 --- a/CRM/Financial/Form/FinancialAccount.php +++ b/CRM/Financial/Form/FinancialAccount.php @@ -114,7 +114,7 @@ class CRM_Financial_Form_FinancialAccount extends CRM_Contribute_Form { $element->freeze(); } - $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); + $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); if (!empty($financialAccountType)) { $element = $this->add('select', 'financial_account_type_id', ts('Financial Account Type'), array('' => '- select -') + $financialAccountType, TRUE); diff --git a/CRM/Financial/Form/FinancialBatch.php b/CRM/Financial/Form/FinancialBatch.php index a06021dcc9..48da6bebe5 100644 --- a/CRM/Financial/Form/FinancialBatch.php +++ b/CRM/Financial/Form/FinancialBatch.php @@ -121,7 +121,7 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form { ); if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) { - $batchStatus = CRM_Core_PseudoConstant::accountOptionValues('batch_status'); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); //unset exported status $exportedStatusId = CRM_Utils_Array::key('Exported', $batchStatus ); @@ -210,7 +210,7 @@ class CRM_Financial_Form_FinancialBatch extends CRM_Contribute_Form { $session = CRM_Core_Session::singleton(); $ids = array(); $params = $this->exportValues(); - $batchStatus = CRM_Core_PseudoConstant::accountOptionValues('batch_status'); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); if ($this->_id) { $ids['batchID'] = $this->_id; $params['id'] = $this->_id; diff --git a/CRM/Financial/Form/FinancialTypeAccount.php b/CRM/Financial/Form/FinancialTypeAccount.php index 28644ffd4f..ca03b6d748 100644 --- a/CRM/Financial/Form/FinancialTypeAccount.php +++ b/CRM/Financial/Form/FinancialTypeAccount.php @@ -162,7 +162,7 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form { //hidden field to catch the field id in profile $this->add('hidden', 'account_type_id', $this->_id); } - $AccountTypeRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + $AccountTypeRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); if (!empty($AccountTypeRelationship)) { $element = $this->add('select', 'account_relationship', @@ -255,8 +255,7 @@ class CRM_Financial_Form_FinancialTypeAccount extends CRM_Contribute_Form { $errorMsg = array(); $errorFlag = FALSE; if ($self->_action == CRM_Core_Action::DELETE) { - $groupName = 'account_relationship'; - $relationValues = CRM_Core_PseudoConstant::accountOptionValues($groupName); + $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); if (CRM_Utils_Array::value('financial_account_id', $values) != 'select') { if ($relationValues[$values['account_relationship']] == 'Premiums Inventory Account is' || $relationValues[$values['account_relationship']] == 'Cost of Sales Account is') { $premiumsProduct = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PremiumsProduct', $values['financial_type_id'], 'product_id', 'financial_type_id'); diff --git a/CRM/Financial/Page/AJAX.php b/CRM/Financial/Page/AJAX.php index 5913e692aa..35ac51084c 100644 --- a/CRM/Financial/Page/AJAX.php +++ b/CRM/Financial/Page/AJAX.php @@ -98,7 +98,7 @@ class CRM_Financial_Page_AJAX { } if ($_GET['_value'] == 'select') { - $result = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + $result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); } else { $financialAccountType = array( @@ -108,7 +108,7 @@ class CRM_Financial_Page_AJAX { '4' => array(7), //cost of sales ); $financialAccountTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', $_GET['_value'], 'financial_account_type_id'); - $result = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + $result = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); } $elements = array( @@ -216,7 +216,7 @@ class CRM_Financial_Page_AJAX { case 'reopen': $status = $op == 'close' ? 'Closed' : 'Open'; $ids['batchID'] = $recordID; - $batchStatus = CRM_Core_PseudoConstant::accountOptionValues('batch_status'); + $batchStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $params['status_id'] = CRM_Utils_Array::key($status, $batchStatus); $session = CRM_Core_Session::singleton(); $params['modified_date'] = date('YmdHis'); diff --git a/CRM/Financial/Page/FinancialAccount.php b/CRM/Financial/Page/FinancialAccount.php index 5581502b3d..2f2e3eb541 100644 --- a/CRM/Financial/Page/FinancialAccount.php +++ b/CRM/Financial/Page/FinancialAccount.php @@ -133,7 +133,7 @@ class CRM_Financial_Page_FinancialAccount extends CRM_Core_Page_Basic { $dao = new CRM_Financial_DAO_FinancialAccount(); $dao->orderBy('financial_account_type_id, name'); $dao->find(); - $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); + $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); while ($dao->fetch()) { $contributionType[$dao->id] = array(); diff --git a/CRM/Financial/Page/FinancialTypeAccount.php b/CRM/Financial/Page/FinancialTypeAccount.php index ac1685f68a..82f1e78e5c 100644 --- a/CRM/Financial/Page/FinancialTypeAccount.php +++ b/CRM/Financial/Page/FinancialTypeAccount.php @@ -137,8 +137,8 @@ class CRM_Financial_Page_FinancialTypeAccount extends CRM_Core_Page { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $this->_title = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $this->_aid, 'name'); CRM_Utils_System::setTitle($this->_title .' - '.ts( 'Assigned Financial Accounts')); - $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); - $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship'); + $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); + $accountRelationship = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); $dao->copyValues($params); $dao->find(); while ($dao->fetch()) { diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php index 29798f0b09..fef9495b36 100644 --- a/CRM/Upgrade/Incremental/php/FourThree.php +++ b/CRM/Upgrade/Incremental/php/FourThree.php @@ -390,7 +390,7 @@ AND ceft.entity_table = 'civicrm_contribution' 3 => array($cancelledStatus, 'Integer') ); - $accountType = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ")); + $accountType = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' "))); $query = " SELECT id FROM civicrm_financial_account @@ -399,14 +399,14 @@ AND financial_account_type_id = {$accountType} "; $financialAccountId = CRM_Core_DAO::singleValueQuery($query); - $accountRelationsips = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL); + $accountRelationsips = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); $accountsReceivableAccount = array_search('Accounts Receivable Account is', $accountRelationsips); $incomeAccountIs = array_search('Income Account is', $accountRelationsips); $assetAccountIs = array_search('Asset Account is', $accountRelationsips); $expenseAccountIs = array_search('Expense Account is', $accountRelationsips); - $financialItemStatus = CRM_Core_PseudoConstant::accountOptionValues('financial_item_status'); + $financialItemStatus = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialItem', 'status_id'); $unpaidStatus = array_search('Unpaid', $financialItemStatus); $paidStatus = array_search('Paid', $financialItemStatus); diff --git a/tests/phpunit/CRM/Core/PseudoConstantTest.php b/tests/phpunit/CRM/Core/PseudoConstantTest.php index 6e56febaff..e47eacfc06 100644 --- a/tests/phpunit/CRM/Core/PseudoConstantTest.php +++ b/tests/phpunit/CRM/Core/PseudoConstantTest.php @@ -68,6 +68,46 @@ class CRM_Core_PseudoConstantTest extends CiviUnitTestCase { * - max: integer (default = 10) maximum number of option values expected. */ $fields = array( + 'CRM_Financial_DAO_EntityFinancialAccount' => array( + array( + 'fieldName' => 'financial_account_id', + 'sample' => 'Member Dues', + 'max' => 15, + ), + array( + 'fieldName' => 'account_relationship', + 'sample' => 'Income Account is', + ), + ), + 'CRM_Financial_DAO_FinancialItem' => array( + array( + 'fieldName' => 'status_id', + 'sample' => 'Partially paid', + ), + array( + 'fieldName' => 'financial_account_id', + 'sample' => 'Accounts Receivable', + 'max' => 15, + ), + ), + 'CRM_Financial_DAO_FinancialTrxn' => array( + array( + 'fieldName' => 'from_financial_account_id', + 'sample' => 'Accounts Receivable', + 'max' => 15, + ), + array( + 'fieldName' => 'to_financial_account_id', + 'sample' => 'Accounts Receivable', + 'max' => 15, + ), + ), + 'CRM_Financial_DAO_FinancialAccount' => array( + array( + 'fieldName' => 'financial_account_type_id', + 'sample' => 'Cost of Sales', + ), + ), 'CRM_Event_DAO_Participant' => array( array( 'fieldName' => 'fee_currency', diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php index f889bdc9a8..3ade5e6b3e 100755 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeAccountTest.php @@ -58,7 +58,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $params['name'] = 'test_financialType1'; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' "))); $financialParams = array( 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, @@ -93,7 +93,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $params['name'] = 'test_financialType2'; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Expense Account is' "))); $financialParams = array( 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, @@ -121,7 +121,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $params['name'] = 'test_financialType3'; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $financialParams = array( 'entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, @@ -182,7 +182,7 @@ class CRM_Financial_BAO_FinancialTypeAccountTest extends CiviUnitTestCase { 'value' => $paymentInstrumentValue, ); $optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $financialParams = array( 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 3ab0882576..a2a69e789e 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -1525,7 +1525,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'id' => $trxn['financial_trxn_id'], ); if ($context == 'payLater') { - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' "))); $compareParams = array( 'status_id' => 1, 'from_financial_account_id' => CRM_Contribute_PseudoConstant::financialAccountType($contribution['financial_type_id'], $relationTypeId), @@ -1589,7 +1589,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { 'version' => 3, ); $optionValue = civicrm_api('option_value', 'create', $optionParams); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); + $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' "))); $financialParams = array( 'entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue['id'], diff --git a/xml/schema/Financial/EntityFinancialAccount.xml b/xml/schema/Financial/EntityFinancialAccount.xml index edd95ff798..e9273bb442 100755 --- a/xml/schema/Financial/EntityFinancialAccount.xml +++ b/xml/schema/Financial/EntityFinancialAccount.xml @@ -45,6 +45,9 @@ true 4.3 FK to a new civicrm_option_value (account_relationship) + + account_relationship + financial_account_id @@ -52,6 +55,11 @@ true 4.3 FK to the financial_account_id + + civicrm_financial_account
+ id + name +
financial_account_id diff --git a/xml/schema/Financial/FinancialAccount.xml b/xml/schema/Financial/FinancialAccount.xml index 8c0fc0c681..4895591596 100644 --- a/xml/schema/Financial/FinancialAccount.xml +++ b/xml/schema/Financial/FinancialAccount.xml @@ -54,6 +54,9 @@ 3 4.3 pseudo FK into civicrm_option_value. + + financial_account_type + accounting_code diff --git a/xml/schema/Financial/FinancialItem.xml b/xml/schema/Financial/FinancialItem.xml index 586b1c2eda..3e0c3ef104 100644 --- a/xml/schema/Financial/FinancialItem.xml +++ b/xml/schema/Financial/FinancialItem.xml @@ -85,6 +85,11 @@ int unsigned FK to civicrm_financial_account 4.3 + + civicrm_financial_account
+ id + name +
financial_account_id @@ -98,6 +103,9 @@ int unsigned Payment status: test, paid, part_paid, unpaid (if empty assume unpaid) 4.3 + + financial_item_status + entity_table diff --git a/xml/schema/Financial/FinancialTrxn.xml b/xml/schema/Financial/FinancialTrxn.xml index edea2e076a..36d21e0b82 100755 --- a/xml/schema/Financial/FinancialTrxn.xml +++ b/xml/schema/Financial/FinancialTrxn.xml @@ -49,6 +49,11 @@ int unsigned FK to financial_account table. 4.3 + + civicrm_financial_account
+ id + name +
from_financial_account_id @@ -61,6 +66,11 @@ int unsigned FK to financial_financial_account table. 4.3 + + civicrm_financial_account
+ id + name +
to_financial_account_id -- 2.25.1