Example #1
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setPaymentCharge(0);
     $invoice->setBasePaymentCharge(0);
     $paymentCharge = $invoice->getOrder()->getPaymentCharge();
     $basePaymentCharge = $invoice->getOrder()->getBasePaymentCharge();
     // we moeten de btw meenemen in de berekening
     $paymentMethod = $invoice->getOrder()->getPayment()->getMethod();
     $taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
     $storeId = Mage::app()->getStore()->getId();
     $taxCalculationModel = Mage::getSingleton('tax/calculation');
     $request = $taxCalculationModel->getRateRequest($invoice->getOrder()->getShippingAddress(), $invoice->getOrder()->getBillingAddress(), null, $storeId);
     $request->setStore(Mage::app()->getStore());
     $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
     if ($rate > 0) {
         $baseChargeTax = round($invoice->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
         $chargeTax = round($invoice->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
     } else {
         $baseChargeTax = 0;
         $chargeTax = 0;
     }
     $invoice->setPaymentCharge($paymentCharge);
     $invoice->setBasePaymentCharge($basePaymentCharge);
     $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseChargeTax);
     $invoice->setTaxAmount($invoice->getTaxAmount() + $chargeTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
     return $this;
 }
Example #2
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $store = $invoice->getStore();
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemQty) {
             if ($orderItem->isDummy()) {
                 continue;
             }
             $weeeTaxAmount = $item->getWeeeTaxAppliedAmount() * $item->getQty();
             $baseWeeeTaxAmount = $item->getBaseWeeeTaxAppliedAmount() * $item->getQty();
             $item->setWeeeTaxAppliedRowAmount($weeeTaxAmount);
             $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeTaxAmount);
             $newApplied = array();
             $applied = Mage::helper('weee')->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;
             }
             Mage::helper('weee')->setApplied($item, $newApplied);
             $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
             $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
             $totalTax += $weeeTaxAmount;
             $baseTotalTax += $baseWeeeTaxAmount;
         }
     }
     /*
      * Add FPT to totals
      * Notice that we check restriction on allowed tax, because
      * a) for last invoice we don't need to collect FPT - it is automatically collected by subtotal/tax collector,
      * that adds whole remaining (not invoiced) subtotal/tax value, so fpt is automatically included into it
      * b) FPT tax is included into order subtotal/tax value, so after multiple invoices with partial item quantities
      * it can happen that other collector will take some FPT value from shared subtotal/tax order value
      */
     $order = $invoice->getOrder();
     if (Mage::helper('weee')->includeInSubtotal($store)) {
         $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);
     } else {
         $allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced() - $invoice->getTaxAmount();
         $allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $invoice->getBaseTaxAmount();
         $totalTax = min($allowedTax, $totalTax);
         $baseTotalTax = min($allowedBaseTax, $baseTotalTax);
         $invoice->setTaxAmount($invoice->getTaxAmount() + $totalTax);
         $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTotalTax);
     }
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #3
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemTax = $orderItem->getTaxAmount();
         $baseOrderItemTax = $orderItem->getBaseTaxAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemTax && $orderItemQty) {
             /**
              * Resolve rounding problems
              */
             if ($item->isLast()) {
                 $tax = $orderItemTax - $orderItem->getTaxInvoiced();
                 $baseTax = $baseOrderItemTax - $orderItem->getBaseTaxInvoiced();
             } else {
                 $tax = $orderItemTax * $item->getQty() / $orderItemQty;
                 $baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
                 $tax = $invoice->getStore()->roundPrice($tax);
                 $baseTax = $invoice->getStore()->roundPrice($baseTax);
             }
             $item->setTaxAmount($tax);
             $item->setBaseTaxAmount($baseTax);
             $totalTax += $tax;
             $baseTotalTax += $baseTax;
         }
     }
     $invoice->setTaxAmount($totalTax);
     $invoice->setBaseTaxAmount($baseTotalTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #4
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setSveaPaymentFeeAmount(0);
     $invoice->setBaseSveaPaymentFeeAmount(0);
     $invoice->setSveaPaymentFeeTaxAmount(0);
     $invoice->setBaseSveaPaymentFeeTaxAmount(0);
     $invoice->setSveaPaymentFeeInclTax(0);
     $invoice->setBaseSveaPaymentFeeInclTax(0);
     $orderPaymentFeeAmount = $invoice->getOrder()->getSveaPaymentFeeAmount();
     $baseOrderPaymentFeeAmount = $invoice->getOrder()->getBaseSveaPaymentFeeAmount();
     $paymentFeeInclTax = $invoice->getOrder()->getSveaPaymentFeeInclTax();
     $basePaymentFeeInclTax = $invoice->getOrder()->getBaseSveaPaymentFeeInclTax();
     if ($orderPaymentFeeAmount) {
         foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
             if ($previousInvoice->getSveaPaymentFeeAmount() && !$previousInvoice->isCanceled()) {
                 // Payment fee has already been invoiced
                 return $this;
             }
         }
         $invoice->setSveaPaymentFeeAmount($orderPaymentFeeAmount);
         $invoice->setBaseSveaPaymentFeeAmount($baseOrderPaymentFeeAmount);
         $invoice->setSveaPaymentFeeTaxAmount($invoice->getOrder()->getSveaPaymentFeeTaxAmount());
         $invoice->setBaseSveaPaymentFeeTaxAmount($invoice->getOrder()->getBaseSveaPaymentFeeTaxAmount());
         $invoice->setSveaPaymentFeeInclTax($paymentFeeInclTax);
         $invoice->setBaseSveaPaymentFeeInclTax($basePaymentFeeInclTax);
         $subtotal = $invoice->getSubtotal();
         $baseSubtotal = $invoice->getBaseSubtotal();
         $subtotalInclTax = $invoice->getSubtotalInclTax();
         $baseSubtotalInclTax = $invoice->getBaseSubtotalInclTax();
         $grandTotal = $invoice->getGrandTotal() + $orderPaymentFeeAmount;
         $baseGrandTotal = $invoice->getBaseGrandTotal() + $baseOrderPaymentFeeAmount;
         $totalTax = $invoice->getTaxAmount();
         $baseTotalTax = $invoice->getBaseTaxAmount();
         if ($invoice->isLast()) {
             $subtotalInclTax -= $invoice->getOrder()->getSveaPaymentFeeTaxAmount();
             $baseSubtotalInclTax -= $invoice->getOrder()->getBaseSveaPaymentFeeTaxAmount();
         } else {
             $totalTax += $invoice->getOrder()->getSveaPaymentFeeTaxAmount();
             $baseTotalTax += $invoice->getOrder()->getBaseSveaPaymentFeeTaxAmount();
             $subtotalInclTax += $invoice->getOrder()->getSveaPaymentFeeTaxAmount();
             $baseSubtotalInclTax += $invoice->getOrder()->getBaseSveaPaymentFeeTaxAmount();
             $grandTotal += $invoice->getOrder()->getSveaPaymentFeeTaxAmount();
             $baseGrandTotal += $invoice->getOrder()->getBaseSveaPaymentFeeTaxAmount();
         }
         $invoice->setSubtotal($subtotal);
         $invoice->setBaseSubtotal($baseSubtotal);
         $invoice->setSubtotalInclTax($subtotalInclTax);
         $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
         $invoice->setTaxAmount($totalTax);
         $invoice->setBaseTaxAmount($baseTotalTax);
         $invoice->setGrandTotal($grandTotal);
         $invoice->setBaseGrandTotal($baseGrandTotal);
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemTax = $orderItem->getTaxAmount();
         $baseOrderItemTax = $orderItem->getBaseTaxAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemTax && $orderItemQty) {
             if ($item->getOrderItem()->isDummy()) {
                 continue;
             }
             /**
              * Resolve rounding problems
              */
             if ($item->isLast()) {
                 $tax = $orderItemTax - $orderItem->getTaxInvoiced();
                 $baseTax = $baseOrderItemTax - $orderItem->getBaseTaxInvoiced();
             } else {
                 $tax = $orderItemTax * $item->getQty() / $orderItemQty;
                 $baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
                 $tax = $invoice->getStore()->roundPrice($tax);
                 $baseTax = $invoice->getStore()->roundPrice($baseTax);
             }
             $item->setTaxAmount($tax);
             $item->setBaseTaxAmount($baseTax);
             $totalTax += $tax;
             $baseTotalTax += $baseTax;
         }
     }
     $includeShippingTax = true;
     /**
      * Check shipping amount in previus invoices
      */
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
         if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
             $includeShippingTax = false;
         }
     }
     if ($includeShippingTax) {
         $totalTax += $invoice->getOrder()->getShippingTaxAmount();
         $baseTotalTax += $invoice->getOrder()->getBaseShippingTaxAmount();
         $invoice->setShippingTaxAmount($invoice->getOrder()->getShippingTaxAmount());
         $invoice->setBaseShippingTaxAmount($invoice->getOrder()->getBaseShippingTaxAmount());
     }
     $invoice->setTaxAmount($totalTax);
     $invoice->setBaseTaxAmount($baseTotalTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $codTax = 0;
     $baseCodTax = 0;
     $order = $invoice->getOrder();
     $includeCodTax = true;
     if ($order->getPayment()->getMethodInstance()->getCode() != 'phoenix_cashondelivery') {
         return $this;
     }
     /**
      * Check Cod amount in previus invoices
      */
     foreach ($order->getInvoiceCollection() as $previousInvoice) {
         if ($previousInvoice->getCodFee() && !$previousInvoice->isCanceled()) {
             $includeCodTax = false;
         }
     }
     if ($includeCodTax) {
         $codTax = $order->getCodTaxAmount();
         $baseCodTax = $order->getBaseCodTaxAmount();
         $invoice->setCodTaxAmount($order->getCodTaxAmount());
         $invoice->setBaseCodTaxAmount($order->getBaseCodTaxAmount());
         $invoice->getOrder()->setCodTaxAmountInvoiced($codTax);
         $invoice->getOrder()->setBaseCodTaxAmountInvoiced($baseCodTax);
     }
     /**
      * Not isLast() invoice case handling
      * totalTax adjustment
      * check Mage_Sales_Model_Order_Invoice_Total_Tax::collect()
      */
     $allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced();
     $allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced();
     $totalTax = $invoice->getTaxAmount();
     $baseTotalTax = $invoice->getBaseTaxAmount();
     if (!$invoice->isLast() && $allowedTax > $totalTax) {
         $newTotalTax = min($allowedTax, $totalTax + $codTax);
         $newBaseTotalTax = min($allowedBaseTax, $baseTotalTax + $baseCodTax);
         $invoice->setTaxAmount($newTotalTax);
         $invoice->setBaseTaxAmount($newBaseTotalTax);
         $invoice->setGrandTotal($invoice->getGrandTotal() - $totalTax + $newTotalTax);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalTax + $newBaseTotalTax);
     }
     return $this;
 }
Example #7
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $store = $invoice->getStore();
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemQty) {
             if ($orderItem->isDummy()) {
                 continue;
             }
             $weeeTaxAmount = $item->getWeeeTaxAppliedAmount() * $item->getQty();
             $baseWeeeTaxAmount = $item->getBaseWeeeTaxAppliedAmount() * $item->getQty();
             $item->setWeeeTaxAppliedRowAmount($weeeTaxAmount);
             $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeTaxAmount);
             $newApplied = array();
             $applied = Mage::helper('weee')->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;
             }
             Mage::helper('weee')->setApplied($item, $newApplied);
             $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
             $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
             $totalTax += $weeeTaxAmount;
             $baseTotalTax += $baseWeeeTaxAmount;
         }
     }
     if (Mage::helper('weee')->includeInSubtotal($store)) {
         $invoice->setSubtotal($invoice->getSubtotal() + $totalTax);
         $invoice->setBaseSubtotal($invoice->getBaseSubtotal() + $baseTotalTax);
     } else {
         $invoice->setTaxAmount($invoice->getTaxAmount() + $totalTax);
         $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTotalTax);
     }
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalTax);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #8
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $feeTax = 0;
     $baseFeeTax = 0;
     $order = $invoice->getOrder();
     $includeFeeTax = TRUE;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $prevInvoice) {
         if ($prevInvoice->getCapayableFee() && !$prevInvoice->isCanceled()) {
             $includeFeeTax = FALSE;
         }
     }
     if ($includeFeeTax) {
         $feeTax += $invoice->getOrder()->getCapayableFeeTaxAmount();
         $baseFeeTax += $invoice->getOrder()->getBaseCapayableFeeTaxAmount();
         $invoice->setCapayableFeeTaxAmount($invoice->getOrder()->getCapayableFeeTaxAmount());
         $invoice->setBaseCapayableFeeTaxAmount($invoice->getOrder()->getBaseCapayableFeeTaxAmount());
         $invoice->getOrder()->setCapayableFeeTaxAmountInvoiced($feeTax);
         $invoice->getOrder()->setBaseCapayableFeeTaxAmountInvoiced($baseFeeTax);
     }
     /**
      * Not isLast() invoice case handling
      * totalTax adjustment
      * check Mage_Sales_Model_Order_Invoice_Total_Tax::collect()
      */
     $allowedTax = $order->getTaxAmount() - $order->getTaxInvoiced();
     $allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced();
     $totalTax = $invoice->getTaxAmount();
     $baseTotalTax = $invoice->getBaseTaxAmount();
     if (!$invoice->isLast() && $allowedTax > $totalTax) {
         $newTotalTax = min($allowedTax, $totalTax + $feeTax);
         $newBaseTotalTax = min($allowedBaseTax, $baseTotalTax + $baseFeeTax);
         $invoice->setTaxAmount($newTotalTax);
         $invoice->setBaseTaxAmount($newBaseTotalTax);
         $invoice->setGrandTotal($invoice->getGrandTotal() - $totalTax + $newTotalTax);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalTax + $newBaseTotalTax);
     }
     return $this;
 }
 /**
  * Collect gift wrapping tax totals
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Enterprise_GiftWrapping_Model_Total_Invoice_Tax_Giftwrapping
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     /**
      * Wrapping for items
      */
     $invoiced = 0;
     $baseInvoiced = 0;
     foreach ($invoice->getAllItems() as $invoiceItem) {
         if (!$invoiceItem->getQty() || $invoiceItem->getQty() == 0) {
             continue;
         }
         $orderItem = $invoiceItem->getOrderItem();
         if ($orderItem->getGwId() && $orderItem->getGwBaseTaxAmount() && $orderItem->getGwBaseTaxAmount() != $orderItem->getGwBaseTaxAmountInvoiced()) {
             $orderItem->setGwBaseTaxAmountInvoiced($orderItem->getGwBaseTaxAmount());
             $orderItem->setGwTaxAmountInvoiced($orderItem->getGwTaxAmount());
             $baseInvoiced += $orderItem->getGwBaseTaxAmount();
             $invoiced += $orderItem->getGwTaxAmount();
         }
     }
     if ($invoiced > 0 || $baseInvoiced > 0) {
         $order->setGwItemsBaseTaxInvoiced($order->getGwItemsBaseTaxInvoiced() + $baseInvoiced);
         $order->setGwItemsTaxInvoiced($order->getGwItemsTaxInvoiced() + $invoiced);
         $invoice->setGwItemsBaseTaxAmount($baseInvoiced);
         $invoice->setGwItemsTaxAmount($invoiced);
     }
     /**
      * Wrapping for order
      */
     if ($order->getGwId() && $order->getGwBaseTaxAmount() && $order->getGwBaseTaxAmount() != $order->getGwBaseTaxAmountInvoiced()) {
         $order->setGwBaseTaxAmountInvoiced($order->getGwBaseTaxAmount());
         $order->setGwTaxAmountInvoiced($order->getGwTaxAmount());
         $invoice->setGwBaseTaxAmount($order->getGwBaseTaxAmount());
         $invoice->setGwTaxAmount($order->getGwTaxAmount());
     }
     /**
      * Printed card
      */
     if ($order->getGwAddCard() && $order->getGwCardBaseTaxAmount() && $order->getGwCardBaseTaxAmount() != $order->getGwCardBaseTaxInvoiced()) {
         $order->setGwCardBaseTaxInvoiced($order->getGwCardBaseTaxAmount());
         $order->setGwCardTaxInvoiced($order->getGwCardTaxAmount());
         $invoice->setGwCardBaseTaxAmount($order->getGwCardBaseTaxAmount());
         $invoice->setGwCardTaxAmount($order->getGwCardTaxAmount());
     }
     if (!$invoice->isLast()) {
         $baseTaxAmount = $invoice->getGwItemsBaseTaxAmount() + $invoice->getGwBaseTaxAmount() + $invoice->getGwCardBaseTaxAmount();
         $taxAmount = $invoice->getGwItemsTaxAmount() + $invoice->getGwTaxAmount() + $invoice->getGwCardTaxAmount();
         $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseTaxAmount);
         $invoice->setTaxAmount($invoice->getTaxAmount() + $taxAmount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTaxAmount);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $taxAmount);
     }
     return $this;
 }
Example #10
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setTaxAmount($invoice->getTaxAmount() + $invoice->getPaymentFeeTax());
     $invoice->setBaseTaxAmount($invoice->getBaseTaxAmount() + $invoice->getBasePaymentFeeTax());
     return $this;
 }