1212class Weee extends \Magento \Sales \Model \Order \Invoice \Total \AbstractTotal
1313{
1414 /**
15- * Weee data
15+ * Weee data object
1616 *
1717 * @var WeeeHelper
1818 */
@@ -174,6 +174,18 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
174174 $ baseTotalWeeeAmountInclTax += $ baseWeeeAmountInclTax ;
175175 }
176176
177+ // If FPT is configured to be included in the subtotal,
178+ // we need to subtract it from the subtotal and the grand total,
179+ // as Collect function from Catalog module knows nothing about FPT and that it is already included in Subtotal
180+ if ($ invoice ->isLast () && $ this ->_weeeData ->includeInSubtotal ($ store )) {
181+ $ invoice ->setSubtotal ($ invoice ->getSubtotal () - $ totalWeeeAmount );
182+ $ invoice ->setBaseSubtotal ($ invoice ->getBaseSubtotal () - $ baseTotalWeeeAmount );
183+ $ invoice ->setGrandTotal ($ invoice ->getGrandTotal () - $ totalWeeeAmountInclTax );
184+ $ invoice ->setBaseGrandTotal ($ invoice ->getBaseGrandTotal () - $ baseTotalWeeeAmountInclTax );
185+ $ invoice ->setTaxAmount ($ invoice ->getTaxAmount () - $ totalWeeeTaxAmount );
186+ $ invoice ->setBaseTaxAmount ($ invoice ->getBaseTaxAmount () - $ baseTotalWeeeTaxAmount );
187+ }
188+
177189 $ allowedTax = $ order ->getTaxAmount () - $ order ->getTaxInvoiced () - $ invoice ->getTaxAmount ();
178190 $ allowedBaseTax = $ order ->getBaseTaxAmount () - $ order ->getBaseTaxInvoiced () - $ invoice ->getBaseTaxAmount ();
179191 $ totalWeeeTaxAmount = min ($ totalWeeeTaxAmount , $ allowedTax );
@@ -196,15 +208,9 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
196208 $ invoice ->setBaseSubtotal ($ invoice ->getBaseSubtotal () + $ baseTotalWeeeAmount );
197209 }
198210
199- if (!$ invoice ->isLast ()) {
200211 // need to add the Weee amounts including all their taxes
201212 $ invoice ->setSubtotalInclTax ($ invoice ->getSubtotalInclTax () + $ totalWeeeAmountInclTax );
202213 $ invoice ->setBaseSubtotalInclTax ($ invoice ->getBaseSubtotalInclTax () + $ baseTotalWeeeAmountInclTax );
203- } else {
204- // since the Subtotal Incl Tax line will already have the taxes on Weee, just add the non-taxable amounts
205- $ invoice ->setSubtotalInclTax ($ invoice ->getSubtotalInclTax () + $ totalWeeeAmount );
206- $ invoice ->setBaseSubtotalInclTax ($ invoice ->getBaseSubtotalInclTax () + $ baseTotalWeeeAmount );
207- }
208214
209215 $ invoice ->setGrandTotal ($ invoice ->getGrandTotal () + $ totalWeeeAmount + $ totalWeeeTaxAmount );
210216 $ invoice ->setBaseGrandTotal ($ invoice ->getBaseGrandTotal () + $ baseTotalWeeeAmount + $ baseTotalWeeeTaxAmount );
0 commit comments