Example #1
0
 /**
  * Collect invoice subtotal
  *
  * @param   Mage_Sales_Model_Order_Invoice $invoice
  * @return  Mage_Sales_Model_Order_Invoice_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $subtotal = 0;
     $baseSubtotal = 0;
     $subtotalInclTax = 0;
     $baseSubtotalInclTax = 0;
     $order = $invoice->getOrder();
     foreach ($invoice->getAllItems() as $item) {
         $item->calcRowTotal();
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
         $subtotalInclTax += $item->getRowTotalInclTax();
         $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
     }
     $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
     $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
     if ($invoice->isLast()) {
         $subtotal = $allowedSubtotal;
         $baseSubtotal = $baseAllowedSubtotal;
     } else {
         $subtotal = min($allowedSubtotal, $subtotal);
         $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setSubtotalInclTax($subtotalInclTax);
     $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     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
 /**
  * Collect invoice subtotal
  *
  * @param   Mage_Sales_Model_Order_Invoice $invoice
  * @return  Mage_Sales_Model_Order_Invoice_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $subtotal = 0;
     $baseSubtotal = 0;
     $subtotalInclTax = 0;
     $baseSubtotalInclTax = 0;
     $order = $invoice->getOrder();
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $item->calcRowTotal();
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
         $subtotalInclTax += $item->getRowTotalInclTax();
         $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
     }
     $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
     $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
     $allowedSubtotalInclTax = $allowedSubtotal + $order->getHiddenTaxAmount() + $order->getTaxAmount() - $order->getTaxInvoiced() - $order->getHiddenTaxInvoiced();
     $baseAllowedSubtotalInclTax = $baseAllowedSubtotal + $order->getBaseHiddenTaxAmount() + $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $order->getBaseHiddenTaxInvoiced();
     /**
      * Check if shipping tax calculation is included to current invoice.
      */
     $includeShippingTax = true;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
         if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
             $includeShippingTax = false;
             break;
         }
     }
     if ($includeShippingTax) {
         $allowedSubtotalInclTax -= $order->getShippingTaxAmount();
         $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
     } else {
         $allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
         $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
     }
     if ($invoice->isLast()) {
         $subtotal = $allowedSubtotal;
         $baseSubtotal = $baseAllowedSubtotal;
         $subtotalInclTax = $allowedSubtotalInclTax;
         $baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
     } else {
         $subtotal = min($allowedSubtotal, $subtotal);
         $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
         $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
         $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setSubtotalInclTax($subtotalInclTax);
     $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     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;
 }
Example #5
0
 /**
  * Collect invoice subtotal
  *
  * @param   Mage_Sales_Model_Order_Invoice $invoice
  * @return  Mage_Sales_Model_Order_Invoice_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $subtotal = 0;
     $baseSubtotal = 0;
     foreach ($invoice->getAllItems() as $item) {
         $item->calcRowTotal();
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     return $this;
 }
Example #6
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 #7
0
 /**
  * Collect invoice subtotal
  *
  * @param   Mage_Sales_Model_Order_Invoice $invoice
  * @return  Mage_Sales_Model_Order_Invoice_Total_Subtotal
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     /// Below is the original magento code instead of marked lines
     $subtotal = 0;
     $baseSubtotal = 0;
     $subtotalInclTax = 0;
     $baseSubtotalInclTax = 0;
     $totalWeeeDiscount = 0;
     $totalBaseWeeeDiscount = 0;
     $order = $invoice->getOrder();
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $item->calcRowTotal();
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
         $subtotalInclTax += $item->getRowTotalInclTax();
         $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
         $totalWeeeDiscount += $item->getOrderItem()->getDiscountAppliedForWeeeTax();
         $totalBaseWeeeDiscount += $item->getOrderItem()->getBaseDiscountAppliedForWeeeTax();
     }
     ///// Changes!!! Deducted refunded amount from allowed subtotal
     $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced() + $order->getSubtotalRefunded();
     $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced() + $order->getBaseSubtotalRefunded();
     $allowedSubtotalInclTax = $allowedSubtotal + $order->getHiddenTaxAmount() + $totalWeeeDiscount + $order->getTaxAmount() - $order->getTaxInvoiced() - $order->getHiddenTaxInvoiced() + $order->getTaxRefunded() + $order->getHiddenTaxRefunded();
     $baseAllowedSubtotalInclTax = $baseAllowedSubtotal + $order->getBaseHiddenTaxAmount() + $totalBaseWeeeDiscount + $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $order->getBaseHiddenTaxInvoiced() + $order->getBaseTaxRefunded() + $order->getBaseHiddenTaxRefunded();
     /**
      * Check if shipping tax calculation is included to current invoice.
      */
     $includeShippingTax = true;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
         if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
             $includeShippingTax = false;
             break;
         }
     }
     if ($includeShippingTax) {
         $allowedSubtotalInclTax -= $order->getShippingTaxAmount();
         $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
     } else {
         $allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
         $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
     }
     if ($invoice->isLast()) {
         $subtotal = $allowedSubtotal;
         $baseSubtotal = $baseAllowedSubtotal;
         $subtotalInclTax = $allowedSubtotalInclTax;
         $baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
     } else {
         $subtotal = min($allowedSubtotal, $subtotal);
         $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
         $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
         $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setSubtotalInclTax($subtotalInclTax);
     $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     return $this;
 }