$financialTypeAccount->find(TRUE);
}
$financialTypeAccount->copyValues($params);
- $valid = self::validateRelationship($financialTypeAccount);
- if (!$valid) {
- return FALSE;
- }
+ self::validateRelationship($financialTypeAccount);
$financialTypeAccount->save();
return $financialTypeAccount;
}
* @param int $financialTypeAccountId
* @param int $accountId
*
- * @return bool
*/
public static function del($financialTypeAccountId, $accountId = NULL) {
// check if financial type is present
*
* @param obj $financialTypeAccount of CRM_Financial_DAO_EntityFinancialAccount
*
+ * @throws CRM_Core_Exception
*/
public static function validateRelationship($financialTypeAccount) {
$financialAccountLinks = CRM_Financial_BAO_FinancialAccount::getfinancialAccountRelations();
$params = array(
1 => $accountRelationships[$financialTypeAccount->account_relationship],
);
- CRM_Core_Session::setStatus(ts('This financial account cannot have \'%1\' relationship.', $params), ts('Error'), 'error');
- return FALSE;
+ throw new CRM_Core_Exception(ts("This financial account cannot have '%1' relationship.", $params));
}
- return TRUE;
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$params['entity_id'] = $this->_aid;
}
- $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids);
- if ($financialTypeAccount) {
- CRM_Core_Session::setStatus(ts('The financial type Account has been saved.'));
+ try {
+ $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids);
}
+ catch (CRM_Core_Exception $e) {
+ CRM_Core_Error::statusBounce($e->getMessage());
+ }
+ CRM_Core_Session::setStatus(ts('The financial type Account has been saved.'));
}
$buttonName = $this->controller->getButtonName();
$financialAccountType->entity_id = array_search('Member Dues', $financialType);
$financialAccountType->account_relationship = array_search('Credit/Contra Revenue Account is', $accountRelationships);
$financialAccountType->financial_account_id = array_search('Liability', $financialAccount);
- $valid = CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType);
- $this->assertFalse($valid);
+ try {
+ CRM_Financial_BAO_FinancialTypeAccount::validateRelationship($financialAccountType);
+ $this->fail("Missed expected exception");
+ }
+ catch (Exception $e) {
+ $this->assertTrue(TRUE, 'Received expected exception');
+ $this->assertEquals($e->getMessage(), "This financial account cannot have 'Credit/Contra Revenue Account is' relationship.");
+ }
}
/**