19 $type = self::KEY_REGULAR_DELTA_ROUNDING,
23 if (
$item->getAssociatedItemCode()) {
39 $this->taxClassManagement->getTaxClassId(
$item->getTaxClassKey())
41 $rate = $this->calculationTool->getRate($taxRateRequest);
42 $storeRate = $storeRate = $this->calculationTool->getStoreRate($taxRateRequest, $this->storeId);
45 $applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
46 $priceInclTax = $this->calculationTool->round(
$item->getUnitPrice());
50 $uniTax = $this->calculationTool->calcTaxAmount($priceInclTax,
$rate,
true,
false);
52 if ($applyTaxAfterDiscount) {
56 $price = $priceInclTax - $uniTax;
59 $discountTaxCompensationAmount = 0;
60 $discountAmount =
$item->getDiscountAmount();
61 if ($applyTaxAfterDiscount) {
63 $unitDiscountAmount = $discountAmount / $quantity;
64 $taxableAmount = max($priceInclTax - $unitDiscountAmount, 0);
65 $unitTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
72 $unitTaxAfterDiscount,
75 self::KEY_REGULAR_DELTA_ROUNDING,
81 $unitDiscountTaxCompensationAmount = $uniTax - $unitTaxAfterDiscount;
82 $discountTaxCompensationAmount = $unitDiscountTaxCompensationAmount * $quantity;
83 $uniTax = $unitTaxAfterDiscount;
85 $rowTax = $uniTax * $quantity;
89 $appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);
90 $appliedTaxes = $this->getAppliedTaxes($rowTax,
$rate, $appliedRates);
92 return $this->taxDetailsItemDataObjectFactory->create()
93 ->setCode(
$item->getCode())
94 ->setType(
$item->getType())
97 ->setPriceInclTax($priceInclTax)
98 ->setRowTotal(
$price * $quantity)
99 ->setRowTotalInclTax($priceInclTax * $quantity)
100 ->setDiscountTaxCompensationAmount($discountTaxCompensationAmount)
101 ->setAssociatedItemCode(
$item->getAssociatedItemCode())
102 ->setTaxPercent(
$rate)
103 ->setAppliedTaxes($appliedTaxes);
112 $this->taxClassManagement->getTaxClassId(
$item->getTaxClassKey())
114 $rate = $this->calculationTool->getRate($taxRateRequest);
115 $appliedRates = $this->calculationTool->getAppliedRates($taxRateRequest);
117 $applyTaxAfterDiscount = $this->config->applyTaxAfterDiscount($this->storeId);
118 $discountAmount =
$item->getDiscountAmount();
119 $discountTaxCompensationAmount = 0;
122 $price = $this->calculationTool->round(
$item->getUnitPrice());
124 $unitTaxesBeforeDiscount = [];
127 foreach ($appliedRates as $appliedRate) {
128 $taxId = $appliedRate[
'id'];
130 $unitTaxPerRate = $this->calculationTool->calcTaxAmount(
$price,
$taxRate,
false,
false);
132 if ($applyTaxAfterDiscount) {
135 $unitTaxPerRate = $this->
roundAmount($unitTaxPerRate, $taxId,
false, $deltaRoundingType, $round,
$item);
136 $unitTaxAfterDiscount = $unitTaxPerRate;
139 if ($applyTaxAfterDiscount) {
141 $unitDiscountAmount = $discountAmount / $quantity;
142 $taxableAmount = max(
$price - $unitDiscountAmount, 0);
143 $unitTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
150 $unitTaxAfterDiscount,
153 self::KEY_REGULAR_DELTA_ROUNDING,
158 $appliedTaxes[$taxId] = $this->getAppliedTax(
159 $unitTaxAfterDiscount * $quantity,
163 $unitTaxes[] = $unitTaxAfterDiscount;
164 $unitTaxesBeforeDiscount[] = $unitTaxPerRate;
166 $unitTax = array_sum($unitTaxes);
167 $unitTaxBeforeDiscount = array_sum($unitTaxesBeforeDiscount);
169 $rowTax = $unitTax * $quantity;
170 $priceInclTax =
$price + $unitTaxBeforeDiscount;
172 return $this->taxDetailsItemDataObjectFactory->create()
173 ->setCode(
$item->getCode())
174 ->setType(
$item->getType())
177 ->setPriceInclTax($priceInclTax)
178 ->setRowTotal(
$price * $quantity)
179 ->setRowTotalInclTax($priceInclTax * $quantity)
180 ->setDiscountTaxCompensationAmount($discountTaxCompensationAmount)
181 ->setAssociatedItemCode(
$item->getAssociatedItemCode())
182 ->setTaxPercent(
$rate)
183 ->setAppliedTaxes($appliedTaxes);
calculateWithTaxInPrice(QuoteDetailsItemInterface $item, $quantity, $round=true)
const KEY_TAX_BEFORE_DISCOUNT_DELTA_ROUNDING
const KEY_REGULAR_DELTA_ROUNDING
isSameRateAsStore($rate, $storeRate)
roundAmount( $amount, $rate=null, $direction=null, $type=self::KEY_REGULAR_DELTA_ROUNDING, $round=true, $item=null)
deltaRound($price, $rate, $direction, $type=self::KEY_REGULAR_DELTA_ROUNDING, $round=true)
calculateWithTaxNotInPrice(QuoteDetailsItemInterface $item, $quantity, $round=true)
calculatePriceInclTax($storePriceInclTax, $storeRate, $customerRate, $round=true)