예제 #1
0
 /**
  * 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.');
 }
 public function setUp()
 {
     parent::setUp();
     $this->_individualId = $this->individualCreate();
     $this->_orgId = $this->organizationCreate(NULL);
     $this->params = array('title' => "Test Contribution Page" . substr(sha1(rand()), 0, 7), 'financial_type_id' => 1, 'payment_processor' => 1, 'currency' => 'NZD', 'goal_amount' => 350, 'is_pay_later' => 1, 'pay_later_text' => 'I will pay later', 'pay_later_receipt' => "I will pay later", 'is_monetary' => TRUE, 'is_billing_required' => TRUE);
     $this->_priceSetParams = array('name' => 'tax_contribution' . substr(sha1(rand()), 0, 7), 'title' => 'contributiontax' . substr(sha1(rand()), 0, 7), 'is_active' => 1, 'help_pre' => "Where does your goat sleep", 'help_post' => "thank you for your time", 'extends' => 2, 'financial_type_id' => 3, 'is_quick_config' => 0, 'is_reserved' => 0);
     // Financial Account with 20% tax rate
     $financialAccountSetparams = array('name' => 'vat full taxrate account' . substr(sha1(rand()), 0, 7), 'contact_id' => $this->_orgId, 'financial_account_type_id' => 2, 'is_tax' => 1, 'tax_rate' => 20.0, 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0);
     $financialAccount = $this->callAPISuccess('financial_account', 'create', $financialAccountSetparams);
     $this->financialAccountId = $financialAccount['id'];
     // Financial type having 'Sales Tax Account is' with liability financail account
     $financialType = array('name' => 'grassvariety1' . substr(sha1(rand()), 0, 7), 'is_reserved' => 0, 'is_active' => 1);
     $priceField = $this->callAPISuccess('financial_type', 'create', $financialType);
     $this->financialtypeID = $priceField['id'];
     $financialRelationParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $this->financialtypeID, 'account_relationship' => 10, 'financial_account_id' => $this->financialAccountId);
     $financialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationParams);
     // Financial type with 5% tax rate
     $financialAccHalftax = array('name' => 'vat half taxrate account' . substr(sha1(rand()), 0, 7), 'contact_id' => $this->_orgId, 'financial_account_type_id' => 2, 'is_tax' => 1, 'tax_rate' => 5.0, 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0);
     $halfFinancialAccount = CRM_Financial_BAO_FinancialAccount::add($financialAccHalftax);
     $this->halfFinancialAccId = $halfFinancialAccount->id;
     $halfFinancialtypeHalftax = array('name' => 'grassvariety2' . substr(sha1(rand()), 0, 7), 'is_reserved' => 0, 'is_active' => 1);
     $halfFinancialType = CRM_Financial_BAO_FinancialType::add($halfFinancialtypeHalftax);
     $this->halfFinancialTypeId = $halfFinancialType->id;
     $financialRelationHalftax = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $this->halfFinancialTypeId, 'account_relationship' => 10, 'financial_account_id' => $this->halfFinancialAccId);
     $halfFinancialRelation = CRM_Financial_BAO_FinancialTypeAccount::add($financialRelationHalftax);
     // Enable component contribute setting
     $contributeSetting = array('invoicing' => 1, 'invoice_prefix' => 'INV_', 'credit_notes_prefix' => 'CN_', 'due_date' => 10, 'due_date_period' => 'days', 'notes' => '', 'is_email_pdf' => 1, 'tax_term' => 'Sales Tax', 'tax_display_settings' => 'Inclusive');
     $setInvoiceSettings = CRM_Core_BAO_Setting::setItem($contributeSetting, CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     // Payment Processor
     $paymentProceParams = array('domain_id' => 1, 'name' => 'dummy' . substr(sha1(rand()), 0, 7), 'payment_processor_type_id' => 10, 'financial_account_id' => 12, 'is_active' => 1, 'is_default' => 1, 'user_name' => 'dummy', 'url_site' => 'http://dummy.com', 'url_recur' => 'http://dummyrecur.com', 'class_name' => 'Payment_Dummy', 'billing_mode' => 1, 'is_recur' => 1, 'payment_type' => 1);
     $result = $this->callAPISuccess('payment_processor', 'create', $paymentProceParams);
     $this->_ids['paymentProcessID'] = $result['id'];
     require_once 'api/v3/examples/PaymentProcessor/Create.php';
     $this->assertAPISuccess($result);
 }
 /**
  * Create default entity financial accounts
  * for financial type
  * CRM-12470
  *
  * @param $financialType
  *
  * @return array
  */
 public static function createDefaultFinancialAccounts($financialType)
 {
     $titles = array();
     $financialAccountTypeID = CRM_Core_OptionGroup::values('financial_account_type', FALSE, FALSE, FALSE, NULL, 'name');
     $accountRelationship = CRM_Core_OptionGroup::values('account_relationship', FALSE, FALSE, FALSE, NULL, 'name');
     $relationships = array(array_search('Accounts Receivable Account is', $accountRelationship) => array_search('Asset', $financialAccountTypeID), array_search('Expense Account is', $accountRelationship) => array_search('Expenses', $financialAccountTypeID), array_search('Cost of Sales Account is', $accountRelationship) => array_search('Cost of Sales', $financialAccountTypeID), array_search('Income Account is', $accountRelationship) => array_search('Revenue', $financialAccountTypeID));
     $dao = CRM_Core_DAO::executeQuery('SELECT id, financial_account_type_id FROM civicrm_financial_account WHERE name LIKE %1', array(1 => array($financialType->name, 'String')));
     $dao->fetch();
     $existingFinancialAccount = array();
     if (!$dao->N) {
         $params = array('name' => $financialType->name, 'contact_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', CRM_Core_Config::domainID(), 'contact_id'), 'financial_account_type_id' => array_search('Revenue', $financialAccountTypeID), 'description' => $financialType->description, 'account_type_code' => 'INC', 'is_active' => 1);
         $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, CRM_Core_DAO::$_nullArray);
     } else {
         $existingFinancialAccount[$dao->financial_account_type_id] = $dao->id;
     }
     $params = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id);
     foreach ($relationships as $key => $value) {
         if (!array_key_exists($value, $existingFinancialAccount)) {
             if ($accountRelationship[$key] == 'Accounts Receivable Account is') {
                 $params['financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Accounts Receivable', 'id', 'name');
                 if (!empty($params['financial_account_id'])) {
                     $titles[] = 'Accounts Receivable';
                 } else {
                     $query = "SELECT financial_account_id, name FROM civicrm_entity_financial_account\n            LEFT JOIN civicrm_financial_account ON civicrm_financial_account.id = civicrm_entity_financial_account.financial_account_id\n            WHERE account_relationship = {$key} AND entity_table = 'civicrm_financial_type' LIMIT 1";
                     $dao = CRM_Core_DAO::executeQuery($query);
                     $dao->fetch();
                     $params['financial_account_id'] = $dao->financial_account_id;
                     $titles[] = $dao->name;
                 }
             } elseif ($accountRelationship[$key] == 'Income Account is' && empty($existingFinancialAccount)) {
                 $params['financial_account_id'] = $financialAccount->id;
             } else {
                 $query = "SELECT id, name FROM civicrm_financial_account WHERE is_default = 1 AND financial_account_type_id = {$value}";
                 $dao = CRM_Core_DAO::executeQuery($query);
                 $dao->fetch();
                 $params['financial_account_id'] = $dao->id;
                 $titles[] = $dao->name;
             }
         } else {
             $params['financial_account_id'] = $existingFinancialAccount[$value];
             $titles[] = $financialType->name;
         }
         $params['account_relationship'] = $key;
         self::add($params);
     }
     if (!empty($existingFinancialAccount)) {
         $titles = array();
     }
     return $titles;
 }
예제 #4
0
 /**
  * Process the form submission.
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Financial_BAO_FinancialAccount::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.'));
     } else {
         $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['contributionType'] = $this->_id;
         }
         $contributionType = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
         CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $contributionType->name)));
     }
 }
 /**
  * check method getInstrumentFinancialAccount()
  */
 function testGetInstrumentFinancialAccount()
 {
     $paymentInstrumentValue = 1;
     $params = array('name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1);
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids);
     $optionParams = array('name' => 'Credit Card', 'value' => $paymentInstrumentValue);
     $optionValue = CRM_Core_BAO_OptionValue::retrieve($optionParams, $defaults);
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' "));
     $financialParams = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id);
     CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids);
     $financialAccountId = CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($paymentInstrumentValue);
     $this->assertEquals($financialAccountId, $financialAccount->id, 'Verify Payment Instrument');
 }
 /**
  * Function to create Financial Account.
  *
  * @param string $financialAccountType
  *
  * @param string $relationType
  *
  * @return array
  *   obj CRM_Financial_DAO_FinancialAccount, obj CRM_Financial_DAO_FinancialType, obj CRM_Financial_DAO_EntityFinancialAccount
  */
 public function createFinancialAccount($financialAccountType, $relationType = NULL)
 {
     $params = array('labelColumn' => 'name');
     $relationTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_EntityFinancialAccount', 'account_relationship', $params);
     $financialAccountTypes = CRM_Core_PseudoConstant::get('CRM_Financial_DAO_FinancialAccount', 'financial_account_type_id', $params);
     $params = array('name' => 'TestFinancialAccount_' . rand(), 'contact_id' => 1, 'is_deductible' => 0, 'is_active' => 1, 'is_reserved' => 0, 'financial_account_type_id' => array_search($financialAccountType, $financialAccountTypes));
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
     $financialType = $financialAccountType = NULL;
     if ($relationType) {
         $params['name'] = 'test_financialType1';
         $financialType = CRM_Financial_BAO_FinancialType::add($params);
         $financialParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, 'account_relationship' => array_search($relationType, $relationTypes), 'financial_account_id' => $financialAccount->id);
         $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::add($financialParams);
     }
     return array($financialAccount, $financialType, $financialAccountType);
 }
 /**
  * check method del()
  */
 function testCreateEntityTrxn()
 {
     $fParams = array('name' => 'Donations' . substr(sha1(rand()), 0, 7), 'is_deductible' => 0, 'is_active' => 1);
     $amount = 200;
     $ids = array();
     $financialAccount = CRM_Financial_BAO_FinancialAccount::add($fParams, $ids);
     $financialTrxn = new CRM_Financial_DAO_FinancialTrxn();
     $financialTrxn->to_financial_account_id = $financialAccount->id;
     $financialTrxn->total_amount = $amount;
     $financialTrxn->save();
     $params = array('entity_table' => 'civicrm_contribution', 'entity_id' => 1, 'financial_trxn_id' => $financialTrxn->id, 'amount' => $amount);
     $entityTrxn = CRM_Financial_BAO_FinancialItem::createEntityTrxn($params);
     $entityResult = $this->assertDBNotNull('CRM_Financial_DAO_EntityFinancialTrxn', $financialTrxn->id, 'amount', 'financial_trxn_id', 'Database check on added entity financial trxn record.');
     $this->assertEquals($entityResult, $amount, 'Verify Amount for Financial Item');
     return $entityTrxn;
 }
예제 #8
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Financial_BAO_FinancialAccount::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Financial Account has been deleted.'));
     } else {
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $params['id'] = $this->_id;
         }
         $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params);
         CRM_Core_Session::setStatus(ts('The Financial Account \'%1\' has been saved.', array(1 => $financialAccount->name)), ts('Saved'), 'success');
     }
 }