/**
* Add the financial types.
*
+ * @deprecated
* @param array $params
- * Reference array contains the values submitted by the form.
*
* @return CRM_Financial_DAO_FinancialAccount
*/
- public static function add(&$params) {
- if (empty($params['id'])) {
- $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
- $params['is_deductible'] = CRM_Utils_Array::value('is_deductible', $params, FALSE);
- $params['is_tax'] = CRM_Utils_Array::value('is_tax', $params, FALSE);
- $params['is_header_account'] = CRM_Utils_Array::value('is_header_account', $params, FALSE);
- $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
- }
- if (!empty($params['id'])
- && !empty($params['financial_account_type_id'])
- && CRM_Financial_BAO_FinancialAccount::validateFinancialAccount(
- $params['id'],
- $params['financial_account_type_id']
- )
- ) {
- throw new CRM_Core_Exception(ts('You cannot change the account type since this financial account refers to a financial item having an account type of Revenue/Liability.'));
- }
- if (!empty($params['is_default'])) {
- $query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1';
- $queryParams = [1 => [$params['financial_account_type_id'], 'Integer']];
- CRM_Core_DAO::executeQuery($query, $queryParams);
- }
-
- // action is taken depending upon the mode
- $financialAccount = new CRM_Financial_DAO_FinancialAccount();
-
- // invoke pre hook
- $op = 'create';
- if (!empty($params['id'])) {
- $op = 'edit';
- }
- CRM_Utils_Hook::pre($op, 'FinancialAccount', CRM_Utils_Array::value('id', $params), $params);
-
- if (!empty($params['id'])) {
- $financialAccount->id = $params['id'];
- $financialAccount->find(TRUE);
- }
-
- $financialAccount->copyValues($params);
- $financialAccount->save();
-
- if (!empty($params['custom']) && is_array($params['custom'])) {
- CRM_Core_BAO_CustomValueTable::store($params['custom'], static::$_tableName, $financialAccount->id, $op);
- }
-
- // invoke post hook
- $op = 'create';
- if (!empty($params['id'])) {
- $op = 'edit';
- }
- CRM_Utils_Hook::post($op, 'FinancialAccount', $financialAccount->id, $financialAccount);
- CRM_Core_PseudoConstant::flush();
-
- return $financialAccount;
+ public static function add($params) {
+ return self::writeRecord($params);
}
/**
*
* @deprecated
* @param int $financialAccountId
+ *
+ * @return bool
*/
public static function del($financialAccountId) {
try {
}
}
}
+ if ($event->action === 'create' || $event->action === 'edit') {
+ $params = $event->params;
+ if (!empty($params['id'])
+ && !empty($params['financial_account_type_id'])
+ && CRM_Financial_BAO_FinancialAccount::validateFinancialAccount(
+ $params['id'],
+ $params['financial_account_type_id']
+ )
+ ) {
+ throw new CRM_Core_Exception(ts('You cannot change the account type since this financial account refers to a financial item having an account type of Revenue/Liability.'));
+ }
+ if (!empty($params['is_default'])) {
+ if (empty($params['financial_account_type_id'])) {
+ $params['financial_account_type_id'] = CRM_Core_DAO::getFieldValue(__CLASS__, $params['id'], 'financial_account_type_id');
+ }
+ $query = 'UPDATE civicrm_financial_account SET is_default = 0 WHERE financial_account_type_id = %1';
+ $queryParams = [1 => [$params['financial_account_type_id'], 'Integer']];
+ CRM_Core_DAO::executeQuery($query, $queryParams);
+ }
+ }
+ }
+
+ /**
+ * Callback for hook_civicrm_post().
+ * @param \Civi\Core\Event\PostEvent $event
+ */
+ public static function self_hook_civicrm_post(\Civi\Core\Event\PostEvent $event) {
+ CRM_Core_PseudoConstant::flush();
}
/**
*
* Generated from xml/schema/CRM/Financial/FinancialAccount.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:ae32a35de5bc66a8e230b5595b77810f)
+ * (GenCodeChecksum:bbb54fc9abdb9f5187f84b0b4eadb53e)
*/
/**
/**
* Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
/**
* Is this account tax-deductible?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
/**
* Is this account for taxes?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
/**
* Is this a predefined system object?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
/**
* Is this property active?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
/**
* Is this account the default one (or default tax one) for its financial_account_type?
*
- * @var bool|string|null
+ * @var bool|string
* (SQL type: tinyint)
* Note that values will be retrieved from the database as a string.
*/
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Header Financial Account?'),
'description' => ts('Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_header_account',
'default' => '0',
'table_name' => 'civicrm_financial_account',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Deductible Financial Account?'),
'description' => ts('Is this account tax-deductible?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_deductible',
- 'default' => '1',
+ 'default' => '0',
'table_name' => 'civicrm_financial_account',
'entity' => 'FinancialAccount',
'bao' => 'CRM_Financial_BAO_FinancialAccount',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Tax Financial Account?'),
'description' => ts('Is this account for taxes?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_tax',
'default' => '0',
'table_name' => 'civicrm_financial_account',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Reserved Financial Account?'),
'description' => ts('Is this a predefined system object?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_reserved',
+ 'default' => '0',
'table_name' => 'civicrm_financial_account',
'entity' => 'FinancialAccount',
'bao' => 'CRM_Financial_BAO_FinancialAccount',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Financial Account is Active'),
'description' => ts('Is this property active?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_active',
+ 'default' => '1',
'table_name' => 'civicrm_financial_account',
'entity' => 'FinancialAccount',
'bao' => 'CRM_Financial_BAO_FinancialAccount',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Default Financial Account'),
'description' => ts('Is this account the default one (or default tax one) for its financial_account_type?'),
+ 'required' => TRUE,
'where' => 'civicrm_financial_account.is_default',
+ 'default' => '0',
'table_name' => 'civicrm_financial_account',
'entity' => 'FinancialAccount',
'bao' => 'CRM_Financial_BAO_FinancialAccount',
'is_pay_later' => "DEFAULT 0",
'is_template' => "DEFAULT 0 COMMENT 'Shows this is a template for recurring contributions.'",
],
+ 'civicrm_financial_account' => [
+ 'is_header_account' => "DEFAULT 0 COMMENT 'Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?'",
+ 'is_deductible' => "DEFAULT 0 COMMENT 'Is this account tax-deductible?'",
+ 'is_tax' => "DEFAULT 0 COMMENT 'Is this account for taxes?'",
+ 'is_reserved' => "DEFAULT 0 COMMENT 'Is this a predefined system object?'",
+ 'is_active' => "DEFAULT 1 COMMENT 'Is this property active?'",
+ 'is_default' => "DEFAULT 0 COMMENT 'Is this account the default one (or default tax one) for its financial_account_type?'",
+ ],
];
/**
<type>boolean</type>
<title>Header Financial Account?</title>
<default>0</default>
+ <required>true</required>
<comment>Is this a header account which does not allow transactions to be posted against it directly, but only to its sub-accounts?</comment>
<add>4.3</add>
</field>
<name>is_deductible</name>
<type>boolean</type>
<title>Deductible Financial Account?</title>
- <default>1</default>
+ <default>0</default>
+ <required>true</required>
<comment>Is this account tax-deductible?</comment>
<add>4.3</add>
</field>
<type>boolean</type>
<title>Tax Financial Account?</title>
<default>0</default>
+ <required>true</required>
<comment>Is this account for taxes?</comment>
<add>4.3</add>
</field>
<type>boolean</type>
<title>Reserved Financial Account?</title>
<comment>Is this a predefined system object?</comment>
+ <default>0</default>
+ <required>true</required>
<add>4.3</add>
</field>
<field>
<type>boolean</type>
<title>Financial Account is Active</title>
<comment>Is this property active?</comment>
+ <default>1</default>
+ <required>true</required>
<add>4.3</add>
</field>
<field>
<type>boolean</type>
<title>Default Financial Account</title>
<comment>Is this account the default one (or default tax one) for its financial_account_type?</comment>
+ <default>0</default>
+ <required>true</required>
<add>4.3</add>
</field>
<index>