/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $errors = CRM_Financial_BAO_FinancialType::del($this->_id); if (!empty($errors)) { CRM_Core_Error::statusBounce($errors['error_message'], CRM_Utils_System::url('civicrm/admin/financial/financialType', "reset=1&action=browse"), ts('Cannot Delete')); } CRM_Core_Session::setStatus(ts('Selected financial type has been deleted.'), ts('Record Deleted'), 'success'); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['financialType'] = $this->_id; } $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); if ($this->_action & CRM_Core_Action::UPDATE) { $url = CRM_Utils_System::url('civicrm/admin/financial/financialType', 'reset=1&action=browse'); CRM_Core_Session::setStatus(ts('The financial type "%1" has been updated.', array(1 => $financialType->name)), ts('Saved'), 'success'); } else { $url = CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', 'reset=1&action=browse&aid=' . $financialType->id); $statusArray = array(1 => $financialType->name, 2 => $financialType->name, 3 => CRM_Utils_Array::value(0, $financialType->titles), 4 => CRM_Utils_Array::value(1, $financialType->titles), 5 => CRM_Utils_Array::value(2, $financialType->titles)); if (empty($financialType->titles)) { $text = ts('Your Financial "%1" Type has been created and assigned to an existing financial account with the same title. You should review the assigned account and determine whether additional account relationships are needed.', $statusArray); } else { $text = ts('Your Financial "%1" Type has been created, along with a corresponding income account "%2". That income account, along with standard financial accounts "%3", "%4" and "%5" have been linked to the financial type. You may edit or replace those relationships here.', $statusArray); } CRM_Core_Session::setStatus($text, ts('Saved'), 'success', array('expires' => 0)); } $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }
/** * Check method del() */ public function testdel() { $params = array('name' => 'Donations', 'is_deductible' => 0, 'is_active' => 1); $ids = array(); $contributionType = CRM_Financial_BAO_FinancialType::add($params, $ids); CRM_Financial_BAO_FinancialType::del($contributionType->id); $params = array('id' => $contributionType->id); $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); }
/** * Check method getFinancialAccount() */ public function testRetrieve() { $params = array('name' => 'TestFinancialAccount_3', 'is_deductible' => 0, 'is_active' => 1, 'is_reserved' => 0); $ids = array(); $financialAccount = CRM_Financial_BAO_FinancialAccount::add($params, $ids); $params['name'] = 'test_financialType3'; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $financialParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $financialType->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $financialAccount->id); CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, $ids); $defaults = array(); $financialAccountType = CRM_Financial_BAO_FinancialTypeAccount::retrieve($financialParams, $defaults); $this->assertEquals($financialAccountType['entity_id'], $financialType->id, 'Verify Entity Id.'); $this->assertEquals($financialAccountType['financial_account_id'], $financialAccount->id, 'Verify Financial Account Id.'); }
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); }
/** * 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 getAccountingCode() */ public function testGetAccountingCode() { $params = array('name' => 'Donations', 'is_active' => 1, 'is_reserved' => 0); $ids = array(); $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); $financialAccountid = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialAccount', 'Donations', 'id', 'name'); CRM_Core_DAO::setFieldValue('CRM_Financial_DAO_FinancialAccount', $financialAccountid, 'accounting_code', '4800'); $accountingCode = CRM_Financial_BAO_FinancialAccount::getAccountingCode($financialType->id); $this->assertEquals($accountingCode, 4800, 'Verify accounting code.'); }
/** * Function to process the form * * @access public * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $errors = CRM_Financial_BAO_FinancialType::del($this->_id); if (!empty($errors)) { $message = ts('This item cannot be deleted.') . $errors['error_message']; CRM_Core_Session::setStatus($message); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/financial/financialType', "reset=1&action=browse")); } CRM_Core_Session::setStatus(ts('Selected financial type has been deleted.')); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['financialType'] = $this->_id; } $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); if ($this->_action & CRM_Core_Action::UPDATE) { $url = CRM_Utils_System::url('civicrm/admin/financial/financialType', 'reset=1&action=browse'); CRM_Core_Session::setStatus(ts('The financial type \'%1\' has been saved.', array(1 => $financialType->name))); } else { $url = CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', 'reset=1&action=browse&aid=' . $financialType->id); $statusArray = array(1 => $financialType->name, 2 => $financialType->name, 3 => $financialType->titles[0], 4 => $financialType->titles[1], 5 => $financialType->titles[2]); CRM_Core_Session::setStatus(ts('Your Financial \'%1\' Type has been created, along with a corresponding income account \'%2\'. That income account, along with standard financial accounts \'%3\', \'%4\' and \'%5\' have been linked to the financial type. You may edit or replace those relationships here.', $statusArray)); } $session = CRM_Core_Session::singleton(); $session->replaceUserContext($url); } }