static function create($params) { // FIXME Reconcile with CRM_Admin_Form_PaymentProcessor::updatePaymentProcessor $processor = new CRM_Financial_DAO_PaymentProcessor(); $processor->copyValues($params); $ppTypeDAO = new CRM_Financial_DAO_PaymentProcessorType(); $ppTypeDAO->id = $params['payment_processor_type_id']; if (!$ppTypeDAO->find(TRUE)) { CRM_Core_Error::fatal(ts('Could not find payment processor meta information')); } // also copy meta fields from the info DAO $processor->is_recur = $ppTypeDAO->is_recur; $processor->billing_mode = $ppTypeDAO->billing_mode; $processor->class_name = $ppTypeDAO->class_name; $processor->payment_type = $ppTypeDAO->payment_type; $processor->save(); // CRM-11826, add entry in civicrm_entity_financial_account // if financial_account_id is not NULL if (CRM_Utils_Array::value('financial_account_id', $params)) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $values = array('entity_table' => 'civicrm_payment_processor', 'entity_id' => $processor->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($values); } return $processor; }
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); }
/** * Save a payment processor. * * @param $values * @param int $domainID * @param $test * * @return void */ public function updatePaymentProcessor(&$values, $domainID, $test) { $dao = new CRM_Financial_DAO_PaymentProcessor(); $dao->id = $test ? $this->_testID : $this->_id; $dao->domain_id = $domainID; $dao->is_test = $test; $dao->is_default = CRM_Utils_Array::value('is_default', $values, 0); $dao->is_active = CRM_Utils_Array::value('is_active', $values, 0); $dao->name = $values['name']; $dao->description = $values['description']; $dao->payment_processor_type_id = $values['payment_processor_type_id']; foreach ($this->_fields as $field) { $fieldName = $test ? "test_{$field['name']}" : $field['name']; $dao->{$field['name']} = trim(CRM_Utils_Array::value($fieldName, $values)); if (empty($dao->{$field['name']})) { $dao->{$field['name']} = 'null'; } } // also copy meta fields from the info DAO $dao->is_recur = $this->_ppDAO->is_recur; $dao->billing_mode = $this->_ppDAO->billing_mode; $dao->class_name = $this->_ppDAO->class_name; $dao->payment_type = $this->_ppDAO->payment_type; $dao->save(); //CRM-11515 $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $params = array('entity_table' => 'civicrm_payment_processor', 'entity_id' => $dao->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $values['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($params); }
/** * @return mixed */ public function _addPaymentInstrument() { $gId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'payment_instrument', 'id', 'name'); $optionParams = array('option_group_id' => $gId, 'label' => 'Test Card', 'name' => 'Test Card', 'value' => '6', 'weight' => '6', 'is_active' => 1); $optionValue = $this->callAPISuccess('option_value', 'create', $optionParams); $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' => 7); CRM_Financial_BAO_FinancialTypeAccount::add($financialParams, CRM_Core_DAO::$_nullArray); $this->assertNotEmpty($optionValue['values'][$optionValue['id']]['value']); return $optionValue['values'][$optionValue['id']]['value']; }
/** * 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 process the form * * @access public * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Financial_BAO_FinancialTypeAccount::del($this->_id, $this->_aid); CRM_Core_Session::setStatus(ts('Selected financial type account 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['entityFinancialAccount'] = $this->_id; } if ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE) { $params['financial_account_id'] = $this->_submitValues['financial_account_id']; } $params['entity_table'] = 'civicrm_financial_type'; if ($this->_action & CRM_Core_Action::ADD) { $params['entity_id'] = $this->_aid; } $financialTypeAccount = CRM_Financial_BAO_FinancialTypeAccount::add($params, $ids); CRM_Core_Session::setStatus(ts('The financial type Account has been saved.')); } $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another Financial Account Type.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=add&aid={$this->_aid}")); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$this->_aid}")); } }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $fieldValues = array('option_group_id' => $this->_gid); $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_OptionValue', $this->_id, $fieldValues); if (CRM_Core_BAO_OptionValue::del($this->_id)) { if ($this->_gName == 'phone_type') { CRM_Core_BAO_Phone::setOptionToNull(CRM_Utils_Array::value('value', $this->_defaultValues)); } CRM_Core_Session::setStatus(ts('Selected %1 type has been deleted.', array(1 => $this->_gLabel)), ts('Record Deleted'), 'success'); } else { CRM_Core_Session::setStatus(ts('Selected %1 type has not been deleted.', array(1 => $this->_gLabel)), ts('Sorry'), 'error'); CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues); } } else { $params = $ids = array(); $params = $this->exportValues(); // allow multiple defaults within group. $allowMultiDefaults = array('email_greeting', 'postal_greeting', 'addressee', 'from_email_address'); if (in_array($this->_gName, $allowMultiDefaults)) { if ($this->_gName == 'from_email_address') { $params['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); } elseif ($filter = CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = $filter; $params['reset_default_for'] = array('filter' => "0, " . $params['filter']); } //make sure we should has to have space, CRM-6977 if ($this->_gName == 'from_email_address') { $params['label'] = str_replace('"<', '" <', $params['label']); } } // set value of filter if not present in params if ($this->_id && !array_key_exists('filter', $params)) { if ($this->_gName == 'participant_role') { $params['filter'] = 0; } else { $params['filter'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_id, 'filter', 'id'); } } $groupParams = array('name' => $this->_gName); $optionValue = CRM_Core_OptionValue::addOptionValue($params, $groupParams, $this->_action, $this->_id); // CRM-11516 if (!empty($params['financial_account_id'])) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($params); } CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', array(1 => $this->_gLabel, 2 => $optionValue->label)), ts('Saved'), 'success'); } }
/** * 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); }
public function testGetTaxRates() { $contact = $this->createLoggedInUser(); $financialType = $this->callAPISuccess('financial_type', 'create', array('name' => 'Test taxable financial Type', 'is_reserved' => 0, 'is_active' => 1)); $financialAccount = $this->callAPISuccess('financial_account', 'create', array('name' => 'Test Tax financial account ', 'contact_id' => $contact, 'financial_account_type_id' => 2, 'is_tax' => 1, 'tax_rate' => 5.0, 'is_reserved' => 0, 'is_active' => 1, 'is_default' => 0)); $financialTypeId = $financialType['id']; $financialAccountId = $financialAccount['id']; $financialAccountParams = array('entity_table' => 'civicrm_financial_type', 'entity_id' => $financialTypeId, 'account_relationship' => 10, 'financial_account_id' => $financialAccountId); CRM_Financial_BAO_FinancialTypeAccount::add($financialAccountParams); $taxRates = CRM_Core_PseudoConstant::getTaxRates(); $this->assertEquals('5.00', $taxRates[$financialType['id']]); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { CRM_Utils_System::flushCache(); $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_OptionValue::del($this->_id); CRM_Core_Session::setStatus(ts('Selected option value has been deleted.'), ts('Record Deleted'), 'success'); } else { $params = $ids = array(); // store the submitted values in an array $params = $this->exportValues(); $params['option_group_id'] = $this->_gid; if ($this->_action & CRM_Core_Action::UPDATE) { $ids['optionValue'] = $this->_id; } //set defaultGreeting option in params to save default value as per contactOption-defaultValue mapping if (CRM_Utils_Array::value('contactOptions', $params)) { $params['filter'] = CRM_Utils_Array::value('contactOptions', $params); $params['defaultGreeting'] = 1; } $optionValue = CRM_Core_BAO_OptionValue::add($params, $ids); // CRM-11516 if (CRM_Utils_Array::value('financial_account_id', $params)) { $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Asset Account is' ")); $params = array('entity_table' => 'civicrm_option_value', 'entity_id' => $optionValue->id, 'account_relationship' => $relationTypeId, 'financial_account_id' => $params['financial_account_id']); CRM_Financial_BAO_FinancialTypeAccount::add($params); } CRM_Core_Session::setStatus(ts('The Option Value \'%1\' has been saved.', array(1 => $optionValue->label)), ts('Saved'), 'success'); } }