/** * Delete financial Types. * * @param int $financialTypeAccountId * @param int $accountId * */ public static function del($financialTypeAccountId, $accountId = NULL) { // check if financial type is present $check = FALSE; $relationValues = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship'); $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'entity_id'); // check dependencies // FIXME more table containing financial_type_id to come $dependency = array(array('Contribute', 'Contribution'), array('Contribute', 'ContributionPage'), array('Member', 'MembershipType'), array('Price', 'PriceFieldValue'), array('Grant', 'Grant'), array('Contribute', 'PremiumsProduct'), array('Contribute', 'Product'), array('Price', 'LineItem')); foreach ($dependency as $name) { $daoString = 'CRM_' . $name[0] . '_DAO_' . $name[1]; $dao = new $daoString(); $dao->financial_type_id = $financialTypeId; if ($dao->find(TRUE)) { $check = TRUE; break; } } if ($check) { if ($name[1] == 'PremiumsProduct' || $name[1] == 'Product') { CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship while the Financial Type is used for a Premium.', array(1 => $relationValues[$financialTypeAccountId]))); } else { $accountRelationShipId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'account_relationship'); CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NULL, 'error'); } return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}")); } // delete from financial Type table $financialType = new CRM_Financial_DAO_EntityFinancialAccount(); $financialType->id = $financialTypeAccountId; $financialType->find(TRUE); $financialType->delete(); CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete the account of type: %1.', array(1 => $relationValues[$financialType->account_relationship]))); }
/** * Function to delete financial Types * * @param int $contributionTypeId * @static */ static function del($financialTypeId) { $financialType = new CRM_Financial_DAO_FinancialType(); $financialType->id = $financialTypeId; $financialType->find(true); // tables to ingore checks for financial_type_id $ignoreTables = array('CRM_Financial_DAO_EntityFinancialAccount'); //TODO: if (!$financialType->find(true)) { // ensure that we have no objects that have an FK to this financial type id TODO: that cannot be null $occurrences = $financialType->findReferences(); if ($occurrences) { $tables = array(); foreach ($occurrences as $occurence) { $className = get_class($occurence); if (!in_array($className, $ignoreTables)) { $tables[] = $className; } } if (!empty($tables)) { $message = ts('The following tables have an entry for this financial type: %1', array('%1' => implode(', ', $tables))); $errors = array(); $errors['is_error'] = 1; $errors['error_message'] = $message; return $errors; } } //delete from financial Type table $financialType->delete(); $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount(); $entityFinancialType->entity_id = $financialTypeId; $entityFinancialType->entity_table = 'civicrm_financial_type'; $entityFinancialType->delete(); return FALSE; }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['entity_financial_account'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * @param string $name */ public function financialAccountDelete($name) { $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->name = $name; if ($financialAccount->find(TRUE)) { $entityFinancialType = new CRM_Financial_DAO_EntityFinancialAccount(); $entityFinancialType->financial_account_id = $financialAccount->id; $entityFinancialType->delete(); $financialAccount->delete(); } }
/** * 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; } }