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);
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