'membership_id' => $membership->id,
'contribution_recur_id' => $contributionRecurID,
]);
- //Remove `tax_amount` if it is not calculated.
- // ?? WHY - I haven't been able to figure out...
- if (CRM_Utils_Array::value('tax_amount', $temporaryParams) === 0.0) {
- unset($temporaryParams['tax_amount']);
- }
CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
}
public function testgetSalesTaxFinancialAccounts() {
$this->enableTaxAndInvoicing();
$financialType = $this->createFinancialType();
- $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+ $financialAccount = $this->addTaxAccountToFinancialType($financialType['id']);
$expectedResult = [$financialAccount->financial_account_id => $financialAccount->financial_account_id];
$financialType = $this->createFinancialType();
- $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+ $financialAccount = $this->addTaxAccountToFinancialType($financialType['id']);
$expectedResult[$financialAccount->financial_account_id] = $financialAccount->financial_account_id;
$salesTaxFinancialAccount = CRM_Contribute_BAO_Contribution::getSalesTaxFinancialAccounts();
$this->assertTrue(($salesTaxFinancialAccount == $expectedResult), 'Function returned wrong values.');
$contactId = $this->individualCreate();
$this->enableTaxAndInvoicing();
$financialType = $this->createFinancialType();
- $financialAccount = $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+ $financialAccount = $this->addTaxAccountToFinancialType($financialType['id']);
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit([
public function testSubmitSaleTax($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
+ $this->addTaxAccountToFinancialType($this->_financialTypeId);
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit([
*/
public function testSubmitWithOutSaleTax() {
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
+ $this->addTaxAccountToFinancialType($this->_financialTypeId);
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit([
public function testReSubmitSaleTax($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
- list($form, $contribution) = $this->doInitialSubmit();
+ $this->addTaxAccountToFinancialType($this->_financialTypeId);
+ [$form, $contribution] = $this->doInitialSubmit();
$this->assertEquals(11000, $contribution['total_amount']);
$this->assertEquals(1000, $contribution['tax_amount']);
$this->assertEquals(11000, $contribution['net_amount']);
public function testReSubmitSaleTaxAlteredAmount($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount($this->_financialTypeId);
- list($form, $contribution) = $this->doInitialSubmit();
+ $this->addTaxAccountToFinancialType($this->_financialTypeId);
+ [$form, $contribution] = $this->doInitialSubmit();
$mut = new CiviMailUtils($this, TRUE);
// Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same:
$this->setCurrencySeparators($thousandSeparator);
$contactId = $this->individualCreate();
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount(1);
+ $this->addTaxAccountToFinancialType(1);
$form = new CRM_Contribute_Form_Contribution();
$form->testSubmit([
'total_amount' => 100,
*/
use Civi\Api4\Contact;
+use Civi\Api4\LineItem;
/**
* Test CRM_Member_Form_Membership functions.
*/
public function testSubmitWithTax() {
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount($this->financialTypeID);
+ $this->addTaxAccountToFinancialType($this->financialTypeID);
$form = $this->getForm();
$form->testSubmit(array_merge($this->getBaseSubmitParams(), [
'total_amount' => '50.00',
$this->assertEquals(4.55, $contribution['tax_amount']);
}
+ /**
+ * Test submitting with tax enabled but a rate of zero.
+ *
+ * https://lab.civicrm.org/dev/core/-/issues/2024
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+ public function testSubmitWithTaxOfZero() {
+ $this->enableTaxAndInvoicing();
+ $this->addTaxAccountToFinancialType($this->financialTypeID, ['tax_rate' => 0]);
+ $form = $this->getForm();
+ $form->testSubmit(array_merge($this->getBaseSubmitParams(), [
+ 'total_amount' => '50.00',
+ ]));
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId, 'is_test' => TRUE, 'return' => ['total_amount', 'tax_amount']]);
+ $this->assertEquals(50, $contribution['total_amount']);
+ $this->assertEquals(0, $contribution['tax_amount']);
+ $lines = LineItem::get()->addWhere('contribution_id', '=', $contribution['id'])->execute();
+ $this->assertCount(1, $lines);
+ }
+
/**
* Test the submit function of the membership form.
*
'return' => ['tax_amount', 'trxn_id'],
]);
$this->assertEquals($contribution['trxn_id'], 777);
- $this->assertEquals(NULL, $contribution['tax_amount']);
+ $this->assertEquals(0.00, $contribution['tax_amount']);
$this->callAPISuccessGetCount('LineItem', [
'entity_id' => $membership['id'],
*/
public function testLineItemAmountOnSalesTax() {
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount(2);
+ $this->addTaxAccountToFinancialType(2);
$form = $this->getForm();
$form->preProcess();
$this->mut = new CiviMailUtils($this, TRUE);
}
/**
- * Add Sales Tax relation for financial type with financial account.
+ * Add Sales Tax Account for the financial type.
*
* @param int $financialTypeId
*
- * @return obj
+ * @param array $accountParams
+ *
+ * @return CRM_Financial_DAO_EntityFinancialAccount
+ * @throws \CRM_Core_Exception
*/
- protected function relationForFinancialTypeWithFinancialAccount($financialTypeId) {
- $params = [
+ protected function addTaxAccountToFinancialType(int $financialTypeId, $accountParams = []) {
+ $params = array_merge([
'name' => 'Sales tax account ' . substr(sha1(rand()), 0, 4),
'financial_account_type_id' => key(CRM_Core_PseudoConstant::accountOptionValues('financial_account_type', NULL, " AND v.name LIKE 'Liability' ")),
'is_deductible' => 1,
'is_tax' => 1,
'tax_rate' => 10,
'is_active' => 1,
- ];
+ ], $accountParams);
$account = CRM_Financial_BAO_FinancialAccount::add($params);
$entityParams = [
'entity_table' => 'civicrm_financial_type',
];
// set tax rate (as 10) for provided financial type ID to static variable, later used to fetch tax rates of all financial types
- \Civi::$statics['CRM_Core_PseudoConstant']['taxRates'][$financialTypeId] = 10;
+ \Civi::$statics['CRM_Core_PseudoConstant']['taxRates'][$financialTypeId] = $params['tax_rate'];
//CRM-20313: As per unique index added in civicrm_entity_financial_account table,
// first check if there's any record on basis of unique key (entity_table, account_relationship, entity_id)
$financialType = $this->createFinancialType();
$financialTypeId = $financialType['id'];
// This function sets the Tax Rate at 10% - it currently has no way to pass Tax Rate into it - so let's work with 10%
- $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+ $this->addTaxAccountToFinancialType($financialType['id']);
$this->setUpContributionPage();
$submitParams = [
'is_reserved' => 0,
'is_active' => 1,
]);
- $this->relationForFinancialTypeWithFinancialAccount($financialType['id']);
+ $this->addTaxAccountToFinancialType($financialType['id']);
$contribution = $this->setUpRepeatTransaction(
[],
'single',
*/
public function enableSalesTaxOnFinancialType($type) {
$this->enableTaxAndInvoicing();
- $this->relationForFinancialTypeWithFinancialAccount(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', $type));
+ $this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', $type));
}
/**