18 $this->taxClassManagement->getTaxClassId(
$item->getTaxClassKey())
20 $rate = $this->calculationTool->getRate($taxRateRequest);
21 $storeRate = $storeRate = $this->calculationTool->getStoreRate($taxRateRequest, $this->storeId);
23 $discountTaxCompensationAmount = 0;
24 $applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
25 $discountAmount =
$item->getDiscountAmount();
28 $priceInclTax = $this->calculationTool->round(
$item->getUnitPrice());
29 $rowTotalInclTax = $priceInclTax * $quantity;
32 $rowTotalInclTax = $priceInclTax * $quantity;
34 $rowTaxExact = $this->calculationTool->calcTaxAmount($rowTotalInclTax,
$rate,
true,
false);
36 if ($applyTaxAfterDiscount) {
40 $rowTotal = $rowTotalInclTax - $rowTax;
41 $price = $rowTotal / $quantity;
47 if ($applyTaxAfterDiscount) {
49 $taxableAmount = max($rowTotalInclTax - $discountAmount, 0);
50 $rowTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
60 self::KEY_REGULAR_DELTA_ROUNDING,
65 $discountTaxCompensationAmount = $rowTax - $rowTaxAfterDiscount;
66 $rowTax = $rowTaxAfterDiscount;
71 $appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);
72 $appliedTaxes = $this->getAppliedTaxes($rowTax,
$rate, $appliedRates);
74 return $this->taxDetailsItemDataObjectFactory->create()
75 ->setCode(
$item->getCode())
76 ->setType(
$item->getType())
79 ->setPriceInclTax($priceInclTax)
80 ->setRowTotal($rowTotal)
81 ->setRowTotalInclTax($rowTotalInclTax)
82 ->setDiscountTaxCompensationAmount($discountTaxCompensationAmount)
83 ->setAssociatedItemCode(
$item->getAssociatedItemCode())
84 ->setTaxPercent(
$rate)
85 ->setAppliedTaxes($appliedTaxes);
94 $this->taxClassManagement->getTaxClassId(
$item->getTaxClassKey())
96 $rate = $this->calculationTool->getRate($taxRateRequest);
97 $appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);
99 $applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
100 $discountAmount =
$item->getDiscountAmount();
101 $discountTaxCompensationAmount = 0;
104 $price = $this->calculationTool->round(
$item->getUnitPrice());
105 $rowTotal =
$price * $quantity;
107 $rowTaxesBeforeDiscount = [];
110 foreach ($appliedRates as $appliedRate) {
111 $taxId = $appliedRate[
'id'];
113 $rowTaxPerRate = $this->calculationTool->calcTaxAmount($rowTotal,
$taxRate,
false,
false);
115 if ($applyTaxAfterDiscount) {
118 $rowTaxPerRate = $this->
roundAmount($rowTaxPerRate, $taxId,
false, $deltaRoundingType, $round,
$item);
119 $rowTaxAfterDiscount = $rowTaxPerRate;
122 if ($applyTaxAfterDiscount) {
124 $taxableAmount = max($rowTotal - $discountAmount, 0);
125 $rowTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
132 $rowTaxAfterDiscount,
135 self::KEY_REGULAR_DELTA_ROUNDING,
140 $appliedTaxes[$taxId] = $this->getAppliedTax(
141 $rowTaxAfterDiscount,
145 $rowTaxes[] = $rowTaxAfterDiscount;
146 $rowTaxesBeforeDiscount[] = $rowTaxPerRate;
148 $rowTax = array_sum($rowTaxes);
149 $rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount);
150 $rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount;
151 $priceInclTax = $rowTotalInclTax / $quantity;
154 $priceInclTax = $this->calculationTool->round($priceInclTax);
157 return $this->taxDetailsItemDataObjectFactory->create()
158 ->setCode(
$item->getCode())
159 ->setType(
$item->getType())
162 ->setPriceInclTax($priceInclTax)
163 ->setRowTotal($rowTotal)
164 ->setRowTotalInclTax($rowTotalInclTax)
165 ->setDiscountTaxCompensationAmount($discountTaxCompensationAmount)
166 ->setAssociatedItemCode(
$item->getAssociatedItemCode())
167 ->setTaxPercent(
$rate)
168 ->setAppliedTaxes($appliedTaxes);
186 $type = self::KEY_REGULAR_DELTA_ROUNDING,
calculateWithTaxInPrice(QuoteDetailsItemInterface $item, $quantity, $round=true)
calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $quantity, $round=true)
const KEY_TAX_BEFORE_DISCOUNT_DELTA_ROUNDING
roundAmount( $amount, $rate=null, $direction=null, $type=self::KEY_REGULAR_DELTA_ROUNDING, $round=true, $item=null)
const KEY_REGULAR_DELTA_ROUNDING
isSameRateAsStore($rate, $storeRate)
calculatePriceInclTax($storePriceInclTax, $storeRate, $customerRate, $round=true)