12 class Weee extends \Magento\Sales\Model\Order\Invoice\Total\AbstractTotal
41 Json $serializer =
null 43 $this->_weeeData = $weeeData;
45 parent::__construct(
$data);
63 $baseTotalWeeeAmount = 0;
64 $totalWeeeAmountInclTax = 0;
65 $baseTotalWeeeAmountInclTax = 0;
66 $totalWeeeTaxAmount = 0;
67 $baseTotalWeeeTaxAmount = 0;
78 $ratio =
$item->getQty() / $orderItemQty;
80 $orderItemWeeeAmount =
$orderItem->getWeeeTaxAppliedRowAmount();
81 $orderItemBaseWeeeAmount =
$orderItem->getBaseWeeeTaxAppliedRowAmnt();
82 $weeeAmount =
$invoice->roundPrice($orderItemWeeeAmount * $ratio);
83 $baseWeeeAmount =
$invoice->roundPrice($orderItemBaseWeeeAmount * $ratio,
'base');
85 $orderItemWeeeInclTax = $this->_weeeData->getRowWeeeTaxInclTax(
$orderItem);
86 $orderItemBaseWeeeInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax(
$orderItem);
87 $weeeAmountInclTax =
$invoice->roundPrice($orderItemWeeeInclTax * $ratio);
88 $baseWeeeAmountInclTax =
$invoice->roundPrice($orderItemBaseWeeeInclTax * $ratio,
'base');
90 $orderItemWeeeTax = $orderItemWeeeInclTax - $orderItemWeeeAmount;
91 $itemWeeeTax = $weeeAmountInclTax - $weeeAmount;
92 $itemBaseWeeeTax = $baseWeeeAmountInclTax - $baseWeeeAmount;
94 if (
$item->isLast()) {
95 $weeeAmount = $orderItemWeeeAmount - $this->_weeeData->getWeeeAmountInvoiced(
$orderItem);
97 $orderItemBaseWeeeAmount - $this->_weeeData->getBaseWeeeAmountInvoiced(
$orderItem);
98 $itemWeeeTax = $orderItemWeeeTax - $this->_weeeData->getWeeeTaxAmountInvoiced(
$orderItem);
100 $orderItemWeeeTax - $this->_weeeData->getBaseWeeeTaxAmountInvoiced(
$orderItem);
103 $totalWeeeTaxAmount += $itemWeeeTax;
104 $baseTotalWeeeTaxAmount += $itemBaseWeeeTax;
108 if ($orderItemWeeeTax != 0) {
110 if (
$item->getTaxRatio()) {
111 $taxRatio = $this->serializer->unserialize(
$item->getTaxRatio());
114 $item->setTaxRatio($this->serializer->serialize($taxRatio));
117 $item->setWeeeTaxAppliedRowAmount($weeeAmount);
118 $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmount);
120 $applied = $this->_weeeData->getApplied(
$orderItem);
121 foreach ($applied as $one) {
122 $title = (string)$one[
'title'];
123 $one[
'base_row_amount'] =
$invoice->roundPrice($one[
'base_row_amount'] * $ratio,
$title.
'_base');
124 $one[
'row_amount'] =
$invoice->roundPrice($one[
'row_amount'] * $ratio,
$title);
125 $one[
'base_row_amount_incl_tax'] =
$invoice->roundPrice(
126 $one[
'base_row_amount_incl_tax'] * $ratio,
129 $one[
'row_amount_incl_tax'] =
$invoice->roundPrice($one[
'row_amount_incl_tax'] * $ratio,
$title);
131 $newApplied[] = $one;
133 $this->_weeeData->setApplied(
$item, $newApplied);
137 $applied = $this->_weeeData->getApplied(
$orderItem);
138 foreach ($applied as $one) {
139 if (isset($one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED])) {
140 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] =
141 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] + $baseWeeeAmount;
143 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $baseWeeeAmount;
145 if (isset($one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED])) {
146 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] =
147 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] + $weeeAmount;
149 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $weeeAmount;
151 if (isset($one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED])) {
152 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] =
153 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] + $itemWeeeTax;
155 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $itemWeeeTax;
157 if (isset($one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED])) {
158 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] =
159 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] + $itemBaseWeeeTax;
161 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $itemBaseWeeeTax;
163 $newApplied[] = $one;
165 $this->_weeeData->setApplied(
$orderItem, $newApplied);
167 $item->setWeeeTaxRowDisposition(
$item->getWeeeTaxDisposition() *
$item->getQty());
168 $item->setBaseWeeeTaxRowDisposition(
$item->getBaseWeeeTaxDisposition() *
$item->getQty());
170 $totalWeeeAmount += $weeeAmount;
171 $baseTotalWeeeAmount += $baseWeeeAmount;
173 $totalWeeeAmountInclTax += $weeeAmountInclTax;
174 $baseTotalWeeeAmountInclTax += $baseWeeeAmountInclTax;
178 $allowedBaseTax =
$order->getBaseTaxAmount() -
$order->getBaseTaxInvoiced() -
$invoice->getBaseTaxAmount();
179 $totalWeeeTaxAmount = min($totalWeeeTaxAmount, $allowedTax);
180 $baseTotalWeeeTaxAmount = min($baseTotalWeeeTaxAmount, $allowedBaseTax);
183 $invoice->setBaseTaxAmount(
$invoice->getBaseTaxAmount() + $baseTotalWeeeTaxAmount);
186 if ($this->_weeeData->includeInSubtotal(
$store)) {
188 $allowedSubtotal =
$order->getSubtotal() -
$order->getSubtotalInvoiced() -
$invoice->getSubtotal();
189 $allowedBaseSubtotal =
$order->getBaseSubtotal() -
190 $order->getBaseSubtotalInvoiced() -
192 $totalWeeeAmount = min($allowedSubtotal, $totalWeeeAmount);
193 $baseTotalWeeeAmount = min($allowedBaseSubtotal, $baseTotalWeeeAmount);
196 $invoice->setBaseSubtotal(
$invoice->getBaseSubtotal() + $baseTotalWeeeAmount);
201 $invoice->setSubtotalInclTax(
$invoice->getSubtotalInclTax() + $totalWeeeAmountInclTax);
202 $invoice->setBaseSubtotalInclTax(
$invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmountInclTax);
205 $invoice->setSubtotalInclTax(
$invoice->getSubtotalInclTax() + $totalWeeeAmount);
206 $invoice->setBaseSubtotalInclTax(
$invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmount);
209 $invoice->setGrandTotal(
$invoice->getGrandTotal() + $totalWeeeAmount + $totalWeeeTaxAmount);
210 $invoice->setBaseGrandTotal(
$invoice->getBaseGrandTotal() + $baseTotalWeeeAmount + $baseTotalWeeeTaxAmount);
collect(\Magento\Sales\Model\Order\Invoice $invoice)
__construct(WeeeHelper $weeeData, array $data=[], Json $serializer=null)