// CRM-11516
if ($this->_gName == 'payment_instrument') {
- $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' "));
+ $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
$financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
$this->add('select', 'financial_account_id', ts('Financial Account'),
$optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
// CRM-11516
if (CRM_Utils_Array::value('financial_account_id', $params)) {
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$params = array(
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue->id,
}
// CRM-11516
if ($this->_gName == 'payment_instrument') {
- $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' "));
+ $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
$financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
$this->add('select', 'financial_account_id', ts('Financial Account'),
// CRM-11516
if (CRM_Utils_Array::value('financial_account_id', $params)) {
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$params = array(
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue->id,
);
// Financial Account of account type asset CRM-11515
- $accountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' "));
+ $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' ");
$financialAccount = CRM_Contribute_PseudoConstant::financialAccount(NULL, key($accountType));
if ($fcount = count($financialAccount)) {
$this->assign('financialAccount', $fcount);
//CRM-11515
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$params = array(
'entity_table' => 'civicrm_payment_processor',
'entity_id' => $dao->id,
!(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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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)) {
//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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' ")));
+ $incomeTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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) {
$params['trxnParams']['to_financial_account_id'] = NULL;
$params['trxnParams']['total_amount'] = - $params['total_amount'];
}
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
$params['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType(
$financialTypeID, $relationTypeId);
}
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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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) {
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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND label IN ('Premiums Inventory Account is', 'Cost of Sales Account is')"));
+ $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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);
*/
static function recordFees($params) {
- $expenseTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Expense Account is' ")));
+ $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
$domainId = CRM_Core_Config::domainID();
$amount = 0;
if (CRM_Utils_Array::value('prevContribution', $params)) {
*/
private static $extensions;
+ /**
+ * Financial Account Type
+ * @var array
+ * @static
+ */
+ private static $accountOptionValues;
+
/**
* Low-level option getter, rarely accessed directly.
* NOTE: Rather than calling this function directly use CRM_*_BAO_*::buildOptions()
* if true, the results are reversed
* - grouping boolean if true, return the value in 'grouping' column (currently unsupported for tables other than option_value)
* - localize boolean if true, localize the results before returning
- * - condition string|array add condition(s) to the sql query
+ * - condition string|array add condition(s) to the sql query - will be concatenated using 'AND'
* - keyColumn string the column to use for 'id'
* - labelColumn string the column to use for 'label'
* - orderColumn string the column to use for sorting, defaults to 'weight' column if one exists, else defaults to labelColumn
$flip,
$params['grouping'],
$params['localize'],
- $params['condition'],
+ $params['condition'] ? ' AND ' . implode(' AND ', (array) $params['condition']) : NULL,
$params['labelColumn'] ? $params['labelColumn'] : 'label',
$params['onlyActive'],
$params['fresh'],
return self::$extensions;
}
+ /**
+ * Get all options values
+ *
+ * The static array option values is returned
+ *
+ * @access public
+ * @static
+ *
+ * @param boolean $optionGroupName - get All Option Group values- default is to get only active ones.
+ *
+ * @return array - array reference of all Option Group Name
+ *
+ */
+ public static function accountOptionValues($optionGroupName, $id = null, $condition = null) {
+ $cacheKey = $optionGroupName . '_' . $condition;
+ if (empty(self::$accountOptionValues[$cacheKey])) {
+ self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, false, false, false, $condition);
+ }
+ if ($id) {
+ return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]);
+ }
+
+ return self::$accountOptionValues[$cacheKey];
+ }
+
/**
* Fetch the list of active extensions of type 'module'
*
$params = array(1 => array($priceSetId, 'Integer'),
2 => array($feeLevel, 'String'));
$mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Discounts Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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'])) {
* @static
*/
static function getAccountingCode($financialTypeId) {
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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'
// Financial Type
$financialType = CRM_Contribute_PseudoConstant::financialType();
$revenueFinancialType = array();
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
CRM_Core_PseudoConstant::populate(
$revenueFinancialType,
'CRM_Financial_DAO_EntityFinancialAccount',
// 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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$values = array(
'entity_table' => 'civicrm_payment_processor',
'entity_id' => $processor->id,
3 => array($cancelledStatus, 'Integer')
);
- $accountType = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', array('condition' => " AND v.name = 'Asset' ")));
+ $accountType = key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name = 'Asset' "));
$query = "
SELECT id
FROM civicrm_financial_account
$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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Income Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
$financialParams = array(
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
$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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Expense Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
$financialParams = array(
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
$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::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$financialParams = array(
'entity_table' => 'civicrm_financial_type',
'entity_id' => $financialType->id,
'value' => $paymentInstrumentValue,
);
$optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults);
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$financialParams = array(
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue->id,
$this->assertEquals( $financialAccountId, $financialAccount->id, 'Verify Payment Instrument');
}
-}
+}
\ No newline at end of file
'id' => $trxn['financial_trxn_id'],
);
if ($context == 'payLater') {
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Accounts Receivable Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " 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),
'version' => 3,
);
$optionValue = civicrm_api('option_value', 'create', $optionParams);
- $relationTypeId = key(CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', array('condition' => " AND v.name LIKE 'Asset Account is' ")));
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
$financialParams = array(
'entity_table' => 'civicrm_option_value',
'entity_id' => $optionValue['id'],