/** * Fetch object based on array of properties. * * @param array $params * (reference ) an assoc array of name/value pairs. * @param array $defaults * (reference ) an assoc array to hold the flattened values. * * @return CRM_Financial_BAO_FinancialAccount */ public static function retrieve(&$params, &$defaults) { $financialAccount = new CRM_Financial_DAO_FinancialAccount(); $financialAccount->copyValues($params); if ($financialAccount->find(TRUE)) { CRM_Core_DAO::storeValues($financialAccount, $defaults); return $financialAccount; } return NULL; }
/** * Browse all custom data groups. * * * @return void * @access public * @static */ function browse() { // get all custom groups sorted by weight $contributionType = array(); $dao = new CRM_Financial_DAO_FinancialAccount(); $dao->orderBy('financial_account_type_id, name'); $dao->find(); $financialAccountType = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id'); while ($dao->fetch()) { $contributionType[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $contributionType[$dao->id]); $contributionType[$dao->id]['financial_account_type_id'] = $financialAccountType[$dao->financial_account_type_id]; // form all action links $action = array_sum(array_keys($this->links())); // update enable/disable links depending on if it is is_reserved or is_active if ($dao->is_reserved) { continue; } else { if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } } $contributionType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'financialAccount.manage.action', 'FinancialAccount', $dao->id); } $this->assign('rows', $contributionType); }
/** * @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(); } }
/** * Add the financial types. * * @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 = array(1 => array($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(); if (!empty($params['id'])) { $financialAccount->id = $params['id']; $financialAccount->find(TRUE); } $financialAccount->copyValues($params); //CRM-16189 $accountType = CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name IN ('Liability', 'Asset') "); if (empty($params['id']) && !CRM_Utils_Array::value($financialAccount->financial_account_type_id, $accountType)) { $financialAccount->opening_balance = $financialAccount->current_period_opening_balance = '0.00'; } $financialAccount->save(); return $financialAccount; }