Esempio n. 1
0
 /**
  * Collect Weee amounts for the credit memo
  *
  * @param Creditmemo $creditmemo
  * @return $this
  */
 public function collect(Creditmemo $creditmemo)
 {
     $store = $creditmemo->getStore();
     $totalTax = 0;
     $baseTotalTax = 0;
     $weeeTaxAmount = 0;
     $baseWeeeTaxAmount = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $weeeAmountExclTax = ($this->_weeeData->getWeeeTaxInclTax($item) - $this->_weeeData->getTotalTaxAppliedForWeeeTax($item)) * $item->getQty();
         $totalTax += $weeeAmountExclTax;
         $baseWeeeAmountExclTax = ($this->_weeeData->getBaseWeeeTaxInclTax($item) - $this->_weeeData->getBaseTotalTaxAppliedForWeeeTax($item)) * $item->getQty();
         $baseTotalTax += $baseWeeeAmountExclTax;
         $item->setWeeeTaxAppliedRowAmount($weeeAmountExclTax);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmountExclTax);
         $weeeTaxAmount += $this->_weeeData->getWeeeTaxInclTax($item) * $item->getQty();
         $baseWeeeTaxAmount += $this->_weeeData->getBaseWeeeTaxInclTax($item) * $item->getQty();
         $newApplied = array();
         $applied = $this->_weeeData->getApplied($item);
         foreach ($applied as $one) {
             $one['base_row_amount'] = $one['base_amount'] * $item->getQty();
             $one['row_amount'] = $one['amount'] * $item->getQty();
             $one['base_row_amount_incl_tax'] = $one['base_amount_incl_tax'] * $item->getQty();
             $one['row_amount_incl_tax'] = $one['amount_incl_tax'] * $item->getQty();
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($item, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
     }
     if ($this->_weeeData->includeInSubtotal($store)) {
         $creditmemo->setSubtotal($creditmemo->getSubtotal() + $totalTax);
         $creditmemo->setBaseSubtotal($creditmemo->getBaseSubtotal() + $baseTotalTax);
     }
     $creditmemo->setSubtotalInclTax($creditmemo->getSubtotalInclTax() + $weeeTaxAmount);
     $creditmemo->setBaseSubtotalInclTax($creditmemo->getBaseSubtotalInclTax() + $baseWeeeTaxAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Esempio n. 2
0
 /**
  * Reset information about FPT for shopping cart item
  *
  * @param   \Magento\Sales\Model\Quote\Item\AbstractItem $item
  * @return  void
  */
 protected function _resetItemData($item)
 {
     $this->weeeData->setApplied($item, array());
     $item->setBaseWeeeTaxDisposition(0);
     $item->setWeeeTaxDisposition(0);
     $item->setBaseWeeeTaxRowDisposition(0);
     $item->setWeeeTaxRowDisposition(0);
     $item->setBaseWeeeTaxAppliedAmount(0);
     $item->setBaseWeeeTaxAppliedRowAmnt(0);
     $item->setWeeeTaxAppliedAmount(0);
     $item->setWeeeTaxAppliedRowAmount(0);
 }
Esempio n. 3
0
 /**
  * Reset information about Tax and Wee on FPT for shopping cart item
  *
  * @param   \Magento\Quote\Model\Quote\Item\AbstractItem $item
  * @return  void
  */
 protected function resetItemData($item)
 {
     $this->weeeData->setApplied($item, []);
     $item->setAssociatedTaxables([]);
     $item->setBaseWeeeTaxDisposition(0);
     $item->setWeeeTaxDisposition(0);
     $item->setBaseWeeeTaxRowDisposition(0);
     $item->setWeeeTaxRowDisposition(0);
     $item->setBaseWeeeTaxAppliedAmount(0);
     $item->setBaseWeeeTaxAppliedRowAmnt(0);
     $item->setWeeeTaxAppliedAmount(0);
     $item->setWeeeTaxAppliedRowAmount(0);
 }
Esempio n. 4
0
 /**
  * Collect Weee amounts for the credit memo
  *
  * @param  Creditmemo $creditmemo
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function collect(Creditmemo $creditmemo)
 {
     $store = $creditmemo->getStore();
     $totalWeeeAmount = 0;
     $baseTotalWeeeAmount = 0;
     $totalWeeeAmountInclTax = 0;
     $baseTotalWeeeAmountInclTax = 0;
     $totalTaxAmount = 0;
     $baseTotalTaxAmount = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() < 0) {
             continue;
         }
         $ratio = $item->getQty() / $orderItemQty;
         $orderItemWeeeAmountExclTax = $orderItem->getWeeeTaxAppliedRowAmount();
         $orderItemBaseWeeeAmountExclTax = $orderItem->getBaseWeeeTaxAppliedRowAmnt();
         $weeeAmountExclTax = $creditmemo->roundPrice($orderItemWeeeAmountExclTax * $ratio);
         $baseWeeeAmountExclTax = $creditmemo->roundPrice($orderItemBaseWeeeAmountExclTax * $ratio, 'base');
         $orderItemWeeeAmountInclTax = $this->_weeeData->getRowWeeeTaxInclTax($orderItem);
         $orderItemBaseWeeeAmountInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax($orderItem);
         $weeeAmountInclTax = $creditmemo->roundPrice($orderItemWeeeAmountInclTax * $ratio);
         $baseWeeeAmountInclTax = $creditmemo->roundPrice($orderItemBaseWeeeAmountInclTax * $ratio, 'base');
         $itemTaxAmount = $weeeAmountInclTax - $weeeAmountExclTax;
         $itemBaseTaxAmount = $baseWeeeAmountInclTax - $baseWeeeAmountExclTax;
         $weeeAmountAvailable = $this->_weeeData->getWeeeAmountInvoiced($orderItem) - $this->_weeeData->getWeeeAmountRefunded($orderItem);
         $baseWeeeAmountAvailable = $this->_weeeData->getBaseWeeeAmountInvoiced($orderItem) - $this->_weeeData->getBaseWeeeAmountRefunded($orderItem);
         $weeeTaxAmountAvailable = $this->_weeeData->getWeeeTaxAmountInvoiced($orderItem) - $this->_weeeData->getWeeeTaxAmountRefunded($orderItem);
         $baseWeeeTaxAmountAvailable = $this->_weeeData->getBaseWeeeTaxAmountInvoiced($orderItem) - $this->_weeeData->getBaseWeeeTaxAmountRefunded($orderItem);
         if ($item->isLast()) {
             $weeeAmountExclTax = $weeeAmountAvailable;
             $baseWeeeAmountExclTax = $baseWeeeAmountAvailable;
             $itemTaxAmount = $weeeTaxAmountAvailable;
             $itemBaseTaxAmount = $baseWeeeTaxAmountAvailable;
         } else {
             $weeeAmountExclTax = min($weeeAmountExclTax, $weeeAmountAvailable);
             $baseWeeeAmountExclTax = min($baseWeeeAmountExclTax, $baseWeeeAmountAvailable);
             $itemTaxAmount = min($itemTaxAmount, $weeeTaxAmountAvailable);
             $itemBaseTaxAmount = min($itemBaseTaxAmount, $baseWeeeTaxAmountAvailable);
         }
         $totalWeeeAmount += $weeeAmountExclTax;
         $baseTotalWeeeAmount += $baseWeeeAmountExclTax;
         $item->setWeeeTaxAppliedRowAmount($weeeAmountExclTax);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmountExclTax);
         $totalTaxAmount += $itemTaxAmount;
         $baseTotalTaxAmount += $itemBaseTaxAmount;
         //Set the ratio of the tax amount in invoice item compared to tax amount in order item
         //This information is needed to calculate tax per tax rate later
         $orderItemTaxAmount = $orderItemWeeeAmountInclTax - $orderItemWeeeAmountExclTax;
         if ($orderItemTaxAmount != 0) {
             $taxRatio = [];
             if ($item->getTaxRatio()) {
                 $taxRatio = unserialize($item->getTaxRatio());
             }
             $taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemTaxAmount / $orderItemTaxAmount;
             $item->setTaxRatio(serialize($taxRatio));
         }
         $totalWeeeAmountInclTax += $weeeAmountInclTax;
         $baseTotalWeeeAmountInclTax += $baseWeeeAmountInclTax;
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             $title = (string) $one['title'];
             $one['base_row_amount'] = $creditmemo->roundPrice($one['base_row_amount'] * $ratio, $title . '_base');
             $one['row_amount'] = $creditmemo->roundPrice($one['row_amount'] * $ratio, $title);
             $one['base_row_amount_incl_tax'] = $creditmemo->roundPrice($one['base_row_amount_incl_tax'] * $ratio, $title . '_base');
             $one['row_amount_incl_tax'] = $creditmemo->roundPrice($one['row_amount_incl_tax'] * $ratio, $title);
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($item, $newApplied);
         // Update order item
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED] = $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED] + $baseWeeeAmountExclTax;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_REFUNDED] = $baseWeeeAmountExclTax;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED])) {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED] = $one[WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED] + $weeeAmountExclTax;
             } else {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_REFUNDED] = $weeeAmountExclTax;
             }
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED] = $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED] + $itemBaseTaxAmount;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_REFUNDED] = $itemBaseTaxAmount;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED])) {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED] = $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED] + $itemTaxAmount;
             } else {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_REFUNDED] = $itemTaxAmount;
             }
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($orderItem, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
     }
     if ($this->_weeeData->includeInSubtotal($store)) {
         $creditmemo->setSubtotal($creditmemo->getSubtotal() + $totalWeeeAmount);
         $creditmemo->setBaseSubtotal($creditmemo->getBaseSubtotal() + $baseTotalWeeeAmount);
     }
     $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $totalTaxAmount);
     $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTotalTaxAmount);
     $creditmemo->setSubtotalInclTax($creditmemo->getSubtotalInclTax() + $totalWeeeAmountInclTax);
     $creditmemo->setBaseSubtotalInclTax($creditmemo->getBaseSubtotalInclTax() + $baseTotalWeeeAmountInclTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalWeeeAmount + $totalTaxAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalWeeeAmount + $baseTotalTaxAmount);
     return $this;
 }
Esempio n. 5
0
 /**
  * Collect Weee amounts for the invoice
  *
  * @param  \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $store = $invoice->getStore();
     $order = $invoice->getOrder();
     $totalWeeeAmount = 0;
     $baseTotalWeeeAmount = 0;
     $totalWeeeAmountInclTax = 0;
     $baseTotalWeeeAmountInclTax = 0;
     $totalWeeeTaxAmount = 0;
     $baseTotalWeeeTaxAmount = 0;
     /** @var \Magento\Sales\Model\Order\Invoice\Item $item */
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() <= 0) {
             continue;
         }
         $ratio = $item->getQty() / $orderItemQty;
         $orderItemWeeeAmount = $orderItem->getWeeeTaxAppliedRowAmount();
         $orderItemBaseWeeeAmount = $orderItem->getBaseWeeeTaxAppliedRowAmnt();
         $weeeAmount = $invoice->roundPrice($orderItemWeeeAmount * $ratio);
         $baseWeeeAmount = $invoice->roundPrice($orderItemBaseWeeeAmount * $ratio, 'base');
         $orderItemWeeeInclTax = $this->_weeeData->getRowWeeeTaxInclTax($orderItem);
         $orderItemBaseWeeeInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax($orderItem);
         $weeeAmountInclTax = $invoice->roundPrice($orderItemWeeeInclTax * $ratio);
         $baseWeeeAmountInclTax = $invoice->roundPrice($orderItemBaseWeeeInclTax * $ratio, 'base');
         $orderItemWeeeTax = $orderItemWeeeInclTax - $orderItemWeeeAmount;
         $itemWeeeTax = $weeeAmountInclTax - $weeeAmount;
         $itemBaseWeeeTax = $baseWeeeAmountInclTax - $baseWeeeAmount;
         if ($item->isLast()) {
             $weeeAmount = $orderItemWeeeAmount - $this->_weeeData->getWeeeAmountInvoiced($orderItem);
             $baseWeeeAmount = $orderItemBaseWeeeAmount - $this->_weeeData->getBaseWeeeAmountInvoiced($orderItem);
             $itemWeeeTax = $orderItemWeeeTax - $this->_weeeData->getWeeeTaxAmountInvoiced($orderItem);
             $itemBaseWeeeTax = $orderItemWeeeTax - $this->_weeeData->getBaseWeeeTaxAmountInvoiced($orderItem);
         }
         $totalWeeeTaxAmount += $itemWeeeTax;
         $baseTotalWeeeTaxAmount += $itemBaseWeeeTax;
         //Set the ratio of the tax amount in invoice item compared to tax amount in order item
         //This information is needed to calculate tax per tax rate later
         if ($orderItemWeeeTax != 0) {
             $taxRatio = [];
             if ($item->getTaxRatio()) {
                 $taxRatio = unserialize($item->getTaxRatio());
             }
             $taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemWeeeTax / $orderItemWeeeTax;
             $item->setTaxRatio(serialize($taxRatio));
         }
         $item->setWeeeTaxAppliedRowAmount($weeeAmount);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmount);
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             $title = (string) $one['title'];
             $one['base_row_amount'] = $invoice->roundPrice($one['base_row_amount'] * $ratio, $title . '_base');
             $one['row_amount'] = $invoice->roundPrice($one['row_amount'] * $ratio, $title);
             $one['base_row_amount_incl_tax'] = $invoice->roundPrice($one['base_row_amount_incl_tax'] * $ratio, $title . '_base');
             $one['row_amount_incl_tax'] = $invoice->roundPrice($one['row_amount_incl_tax'] * $ratio, $title);
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($item, $newApplied);
         //Update order item
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] + $baseWeeeAmount;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $baseWeeeAmount;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] + $weeeAmount;
             } else {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $weeeAmount;
             }
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] + $itemWeeeTax;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $itemWeeeTax;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] + $itemBaseWeeeTax;
             } else {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $itemBaseWeeeTax;
             }
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($orderItem, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
         $totalWeeeAmount += $weeeAmount;
         $baseTotalWeeeAmount += $baseWeeeAmount;
         $totalWeeeAmountInclTax += $weeeAmountInclTax;
         $baseTotalWeeeAmountInclTax += $baseWeeeAmountInclTax;
     }
     $allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced() - $invoice->getTaxAmount();
     $allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $invoice->getBaseTaxAmount();
     $totalWeeeTaxAmount = min($totalWeeeTaxAmount, $allowedTax);
     $baseTotalWeeeTaxAmount = min($baseTotalWeeeTaxAmount, $allowedBaseTax);
     $invoice->setTaxAmount($invoice->getTaxAmount() + $totalWeeeTaxAmount);
     $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTotalWeeeTaxAmount);
     // Add FPT to subtotal and grand total
     if ($this->_weeeData->includeInSubtotal($store)) {
         $order = $invoice->getOrder();
         $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced() - $invoice->getSubtotal();
         $allowedBaseSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced() - $invoice->getBaseSubtotal();
         $totalWeeeAmount = min($allowedSubtotal, $totalWeeeAmount);
         $baseTotalWeeeAmount = min($allowedBaseSubtotal, $baseTotalWeeeAmount);
         $invoice->setSubtotal($invoice->getSubtotal() + $totalWeeeAmount);
         $invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalWeeeAmount);
     }
     if (!$invoice->isLast()) {
         // need to add the Weee amounts including all their taxes
         $invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $totalWeeeAmountInclTax);
         $invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmountInclTax);
     } else {
         // since the Subtotal Incl Tax line will already have the taxes on Weee, just add the non-taxable amounts
         $invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $totalWeeeAmount);
         $invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseTotalWeeeAmount);
     }
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalWeeeAmount + $totalWeeeTaxAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalWeeeAmount + $baseTotalWeeeTaxAmount);
     return $this;
 }
Esempio n. 6
0
 /**
  * Collect Weee amounts for the invoice
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $store = $invoice->getStore();
     $totalTax = 0;
     $baseTotalTax = 0;
     $weeeInclTax = 0;
     $baseWeeeInclTax = 0;
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if (!$orderItemQty || $orderItem->isDummy()) {
             continue;
         }
         $weeeTaxAmount = $item->getWeeeTaxAppliedAmount() * $item->getQty();
         $baseWeeeTaxAmount = $item->getBaseWeeeTaxAppliedAmount() * $item->getQty();
         $weeeTaxAmountInclTax = $this->_weeeData->getWeeeTaxInclTax($item) * $item->getQty();
         $baseWeeeTaxAmountInclTax = $this->_weeeData->getBaseWeeeTaxInclTax($item) * $item->getQty();
         $item->setWeeeTaxAppliedRowAmount($weeeTaxAmount);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeTaxAmount);
         $newApplied = array();
         $applied = $this->_weeeData->getApplied($item);
         foreach ($applied as $one) {
             $one['base_row_amount'] = $one['base_amount'] * $item->getQty();
             $one['row_amount'] = $one['amount'] * $item->getQty();
             $one['base_row_amount_incl_tax'] = $one['base_amount_incl_tax'] * $item->getQty();
             $one['row_amount_incl_tax'] = $one['amount_incl_tax'] * $item->getQty();
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($item, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
         $totalTax += $weeeTaxAmount;
         $baseTotalTax += $baseWeeeTaxAmount;
         $weeeInclTax += $weeeTaxAmountInclTax;
         $baseWeeeInclTax += $baseWeeeTaxAmountInclTax;
     }
     // Add FPT to subtotal and grand total
     if ($this->_weeeData->includeInSubtotal($store)) {
         $order = $invoice->getOrder();
         $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced() - $invoice->getSubtotal();
         $allowedBaseSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced() - $invoice->getBaseSubtotal();
         $totalTax = min($allowedSubtotal, $totalTax);
         $baseTotalTax = min($allowedBaseSubtotal, $baseTotalTax);
         $invoice->setSubtotal($invoice->getSubtotal() + $totalTax);
         $invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalTax);
     }
     $useWeeeInclTax = true;
     if ($this->_weeeData->isTaxIncluded($store) && $invoice->isLast()) {
         $useWeeeInclTax = false;
     }
     if ($useWeeeInclTax) {
         // need to add the Weee amounts including all their taxes
         $invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $weeeInclTax);
         $invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseWeeeInclTax);
     } else {
         // since the Subtotal Incl Tax line will already have the taxes on Weee, just add the non-taxable amounts
         $invoice->setSubtotalInclTax($invoice->getSubtotalInclTax() + $totalTax);
         $invoice->setBaseSubtotalInclTax($invoice->getBaseSubtotalInclTax() + $baseTotalTax);
     }
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }