コード例 #1
0
 /**
  * Add the financial types.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Reference array contains the id.
  *
  * @return object
  */
 public static function add(&$params, &$ids = NULL)
 {
     // action is taken depending upon the mode
     $financialTypeAccount = new CRM_Financial_DAO_EntityFinancialAccount();
     if ($params['entity_table'] != 'civicrm_financial_type') {
         $financialTypeAccount->entity_id = $params['entity_id'];
         $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->copyValues($params);
     $financialTypeAccount->save();
     return $financialTypeAccount;
 }
コード例 #2
0
 /**
  * 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;
     }
 }