Skip to content

Commit

Permalink
Correction for double tax calculation when working with multiple tax …
Browse files Browse the repository at this point in the history
…calculation plugins
  • Loading branch information
Sergey committed Feb 7, 2025
1 parent 8efae94 commit 681e9f8
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 11 deletions.
Empty file modified Api/Data/OrdersDataContainerInterface.php
100755 → 100644
Empty file.
Empty file modified Api/Data/OrdersDataInterface.php
100755 → 100644
Empty file.
Empty file modified Api/OrdersRepositoryInterface.php
100755 → 100644
Empty file.
Empty file modified Helper/Data.php
100755 → 100644
Empty file.
Empty file modified Model/Orders.php
100755 → 100644
Empty file.
Empty file modified Model/OrdersData.php
100755 → 100644
Empty file.
Empty file modified Model/OrdersDataContainer.php
100755 → 100644
Empty file.
Empty file modified Model/OrdersRepository.php
100755 → 100644
Empty file.
Empty file modified Model/ResourceModel/Orders.php
100755 → 100644
Empty file.
Empty file modified Model/ResourceModel/Orders/Collection.php
100755 → 100644
Empty file.
46 changes: 37 additions & 9 deletions Observer/ChangeTaxTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,55 @@ private function applyTaxDataToQuote($quote, $vatData, $observer)
$tax = 0;
$items = $quote->getItemsCollection();

$appliedItemsTaxAmount = 0; // tax amount for all qty
$appliedItemsBaseTaxAmount = 0; // tax amount for all qty

foreach ($vatData as $data) {
foreach ($items as $item) {
if ($item->getProductId() == $data->transaction_id) {
$item->setTaxAmount($data->tax_amount);

$appliedItemTaxAmount = ((float)$item->getTaxPercent() / 100) * $item->getPrice(); // tax amount per 1 item
$appliedItemBaseTaxAmount = ((float)$item->getTaxPercent() / 100) * $item->getBasePrice(); // tax amount per 1 item

$item->setTaxPercent($data->tax_rate);
$item->setTaxAmount($data->tax_amount);
$item->setBaseTaxAmount($data->tax_amount);
$item->setPriceInclTax($item->getPriceInclTax() - $appliedItemTaxAmount + $data->tax_amount / $item->getQty());
$item->setBasePriceInclTax($item->getBasePriceInclTax() - $appliedItemBaseTaxAmount + $data->tax_amount / $item->getQty());
$item->setRowTotalInclTax($item->getPriceInclTax() * $item->getQty());
$item->setBaseRowTotalInclTax($item->getBasePriceInclTax() * $item->getQty());
$item->setAppliedTaxes([]);

$appliedItemsTaxAmount += $appliedItemTaxAmount;
$appliedItemsBaseTaxAmount += $appliedItemBaseTaxAmount;

break;
}
}
$tax += $data->tax_amount;
}

$quote->setTaxAmount($tax);
$quote->setBaseTaxAmount($tax);
$quote->setGrandTotal($quote->getGrandTotal() + $tax);
$quote->setBaseGrandTotal($quote->getBaseGrandTotal() + $tax);
$quote->setGrandTotal($quote->getGrandTotal() - $appliedItemsTaxAmount + $tax);
$quote->setBaseGrandTotal($quote->getBaseGrandTotal() - $appliedItemsBaseTaxAmount + $tax);
$quote->setTotalsCollectedFlag(false);


/* totals */
$total = $observer->getTotal();
$total->addTotalAmount('tax', $tax);
$total->addBaseTotalAmount('tax', $tax);
$total->setGrandTotal((float)$total->getGrandTotal() + $tax);
$total->setBaseGrandTotal((float)$total->getBaseGrandTotal() + $tax);

// get previously applied Tax
$appliedTotalTaxAmount = (float)$total->getTaxAmount();
$appliedTotalBaseTaxAmount = (float)$total->getBaseTaxAmount();

$total->setAppliedTaxes([]);
$total->setItemsAppliedTaxes([]);
$total->setTaxAmount($tax);
$total->setBaseTaxAmount($tax);

$total->setSubtotalInclTax($total->getSubtotalInclTax() - $appliedTotalTaxAmount + $tax);
$total->setBaseSubtotalTotalInclTax($total->getBaseSubtotalTotalInclTax() - $appliedTotalBaseTaxAmount + $tax);
$total->setBaseSubtotalInclTax($total->getBaseSubtotalInclTax() - $appliedTotalBaseTaxAmount + $tax);
$total->setGrandTotal($total->getGrandTotal() - $appliedTotalTaxAmount + $tax);
$total->setBaseGrandTotal($total->getBaseGrandTotal() - $appliedTotalBaseTaxAmount + $tax);
}
}
Empty file modified README.md
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vatcompliance/module-vatcompliance",
"description": "Lovat Api Sales Module for Magento 2",
"type": "magento2-module",
"version": "1.0.14",
"version": "1.1.0",
"license": "OSL-3.0",
"require": {
"php": ">=7.2",
Expand Down
Empty file modified etc/acl.xml
100755 → 100644
Empty file.
Empty file modified etc/db_schema.xml
100755 → 100644
Empty file.
Empty file modified etc/di.xml
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion etc/module.xml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Lovat_Api" setup_version="1.0.14"/>
<module name="Lovat_Api" setup_version="1.1.0"/>
</config>
Empty file modified etc/webapi.xml
100755 → 100644
Empty file.
Empty file modified registration.php
100755 → 100644
Empty file.

0 comments on commit 681e9f8

Please sign in to comment.