/** * Check method del() */ public function testdel() { $params = array('name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1); $ids = array(); $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids); CRM_Financial_BAO_FinancialAccount::del($contributionType->id); $params = array('id' => $contributionType->id); $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { parent::preProcess(); if ($this->_id) { $params = array('id' => $this->_id); $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, CRM_Core_DAO::$_nullArray); $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); if ($financialAccount->financial_account_type_id == array_search('Asset', $financialAccountType) && strtolower($financialAccount->account_type_code) == 'ar' && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType))) { $this->_isARFlag = TRUE; if ($this->_action & CRM_Core_Action::DELETE) { $msg = ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance)."); CRM_Core_Error::statusBounce($msg); } } } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { parent::preProcess(); if ($this->_id) { $params = array('id' => $this->_id); $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, CRM_Core_DAO::$_nullArray); $financialAccountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type'); if ($financialAccount->financial_account_type_id == array_search('Asset', $financialAccountType) && strtolower($financialAccount->account_type_code) == 'ar' && !CRM_Financial_BAO_FinancialAccount::getARAccounts($this->_id, array_search('Asset', $financialAccountType))) { $this->_isARFlag = TRUE; if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_Session::setStatus(ts("The selected financial account cannot be deleted because at least one Accounts Receivable type account is required (to ensure that accounting transactions are in balance)."), '', 'error'); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialAccount', "reset=1&action=browse")); } } } }
/** * Browse all Financial Type Account data * * @return void * @access public * @static */ function browse() { // get all Financial Type Account data sorted by weight $financialType = array(); $params = array(); $dao = new CRM_Financial_DAO_EntityFinancialAccount(); $params['entity_id'] = $this->_aid; $params['entity_table'] = 'civicrm_financial_type'; if ($this->_aid) { $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::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()) { $financialType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]); $params = array('id' => $dao->financial_account_id); $defaults = array(); $financialAccount = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); if (!empty($financialAccount)) { $financialType[$dao->id]['financial_account'] = $financialAccount->name; $financialType[$dao->id]['accounting_code'] = $financialAccount->accounting_code; $financialType[$dao->id]['account_type_code'] = $financialAccount->account_type_code; $financialType[$dao->id]['is_active'] = $financialAccount->is_active; if (!empty($financialAccount->contact_id)) { $financialType[$dao->id]['owned_by'] = CRM_Contact_BAO_Contact::displayName($financialAccount->contact_id); } if (!empty($financialAccount->financial_account_type_id)) { $optionGroupName = 'financial_account_type'; $financialType[$dao->id]['financial_account_type'] = CRM_Utils_Array::value($financialAccount->financial_account_type_id, $financialAccountType); } if (!empty($dao->account_relationship)) { $optionGroupName = 'account_relationship'; $financialType[$dao->id]['account_relationship'] = CRM_Utils_Array::value($dao->account_relationship, $accountRelationship); } } // form all action links $action = array_sum(array_keys($this->links())); $links = self::links(); //CRM-12492 if ($dao->account_relationship == $relationTypeId) { unset($links[CRM_Core_Action::DELETE]); } $financialType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id, 'aid' => $dao->entity_id), ts('more'), FALSE, 'financialTypeAccount.manage.action', 'FinancialTypeAccount', $dao->id); } $this->assign('rows', $financialType); $this->assign('aid', $this->_aid); $this->assign('financialTypeTitle', $this->_title); } else { CRM_Core_Error::fatal(); return null; } }