+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016 |
+ | Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Financial_BAO_FinancialTypeAccount extends CRM_Financial_DAO_EntityFinancialAccount {
$financialTypeAccount->entity_table = $params['entity_table'];
$financialTypeAccount->find(TRUE);
}
- else {
- $financialTypeAccount->id = CRM_Utils_Array::value('entityFinancialAccount', $ids);
- }
if (!empty($ids['entityFinancialAccount'])) {
$financialTypeAccount->id = $ids['entityFinancialAccount'];
+ $financialTypeAccount->find(TRUE);
}
$financialTypeAccount->copyValues($params);
+ self::validateRelationship($financialTypeAccount);
$financialTypeAccount->save();
return $financialTypeAccount;
}
CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete the account of type: %1.', array(1 => $relationValues[$financialType->account_relationship])));
}
- /**
- * Get Financial Account Name.
- *
- * @param int $entityId
- *
- * @param string $entityTable
- *
- * @param string $columnName
- * Column to fetch.
- *
- * @return null|string
- */
- public static function getFinancialAccount($entityId, $entityTable, $columnName = 'name') {
- $join = $columnName == 'name' ? 'LEFT JOIN civicrm_financial_account ON civicrm_entity_financial_account.financial_account_id = civicrm_financial_account.id' : NULL;
- $query = "
-SELECT {$columnName}
-FROM civicrm_entity_financial_account
-{$join}
-WHERE entity_table = %1
-AND entity_id = %2";
-
- $params = array(
- 1 => array($entityTable, 'String'),
- 2 => array($entityId, 'Integer'),
- );
- return CRM_Core_DAO::singleValueQuery($query, $params);
- }
-
/**
* Financial Account for payment instrument.
*
'account_type_code' => 'INC',
'is_active' => 1,
);
- $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, CRM_Core_DAO::$_nullArray);
+ $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
}
else {
$existingFinancialAccount[$dao->financial_account_type_id] = $dao->id;
return $titles;
}
+ /**
+ * Validate account relationship with financial account type
+ *
+ * @param obj $financialTypeAccount of CRM_Financial_DAO_EntityFinancialAccount
+ *
+ */
+ 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));
+ }
+ }
+
}