12
12
class Weee extends \Magento \Sales \Model \Order \Invoice \Total \AbstractTotal
13
13
{
14
14
/**
15
- * Weee data
15
+ * Weee data object
16
16
*
17
17
* @var WeeeHelper
18
18
*/
@@ -174,6 +174,18 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
174
174
$ baseTotalWeeeAmountInclTax += $ baseWeeeAmountInclTax ;
175
175
}
176
176
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
+
177
189
$ allowedTax = $ order ->getTaxAmount () - $ order ->getTaxInvoiced () - $ invoice ->getTaxAmount ();
178
190
$ allowedBaseTax = $ order ->getBaseTaxAmount () - $ order ->getBaseTaxInvoiced () - $ invoice ->getBaseTaxAmount ();
179
191
$ totalWeeeTaxAmount = min ($ totalWeeeTaxAmount , $ allowedTax );
@@ -196,15 +208,9 @@ public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
196
208
$ invoice ->setBaseSubtotal ($ invoice ->getBaseSubtotal () + $ baseTotalWeeeAmount );
197
209
}
198
210
199
- if (!$ invoice ->isLast ()) {
200
211
// need to add the Weee amounts including all their taxes
201
212
$ invoice ->setSubtotalInclTax ($ invoice ->getSubtotalInclTax () + $ totalWeeeAmountInclTax );
202
213
$ 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
- }
208
214
209
215
$ invoice ->setGrandTotal ($ invoice ->getGrandTotal () + $ totalWeeeAmount + $ totalWeeeTaxAmount );
210
216
$ invoice ->setBaseGrandTotal ($ invoice ->getBaseGrandTotal () + $ baseTotalWeeeAmount + $ baseTotalWeeeTaxAmount );
0 commit comments