Example #1
0
 /**
  * Collect reward total for invoice
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Enterprise_Reward_Model_Total_Invoice_Reward
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $rewardCurrecnyAmountLeft = $order->getRewardCurrencyAmount() - $order->getRewardCurrencyAmountInvoiced();
     $baseRewardCurrecnyAmountLeft = $order->getBaseRewardCurrencyAmount() - $order->getBaseRewardCurrencyAmountInvoiced();
     if ($order->getBaseRewardCurrencyAmount() && $baseRewardCurrecnyAmountLeft > 0) {
         if ($baseRewardCurrecnyAmountLeft < $invoice->getBaseGrandTotal()) {
             $invoice->setGrandTotal($invoice->getGrandTotal() - $rewardCurrecnyAmountLeft);
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseRewardCurrecnyAmountLeft);
         } else {
             $rewardCurrecnyAmountLeft = $invoice->getGrandTotal();
             $baseRewardCurrecnyAmountLeft = $invoice->getBaseGrandTotal();
             $invoice->setGrandTotal(0);
             $invoice->setBaseGrandTotal(0);
         }
         $pointValue = $order->getRewardPointsBalance() / $order->getBaseRewardCurrencyAmount();
         $rewardPointsBalance = $baseRewardCurrecnyAmountLeft * ceil($pointValue);
         $rewardPointsBalanceLeft = $order->getRewardPointsBalance() - $order->getRewardPointsBalanceInvoiced();
         if ($rewardPointsBalance > $rewardPointsBalanceLeft) {
             $rewardPointsBalance = $rewardPointsBalanceLeft;
         }
         $invoice->setRewardPointsBalance($rewardPointsBalance);
         $invoice->setRewardCurrencyAmount($rewardCurrecnyAmountLeft);
         $invoice->setBaseRewardCurrencyAmount($baseRewardCurrecnyAmountLeft);
     }
     return $this;
 }
 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->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseChargeTax);
     $invoice->setTaxAmount($invoice->getTaxAmount() + $chargeTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
     $invoice->setPaymentCharge($paymentCharge);
     $invoice->setBasePaymentCharge($basePaymentCharge);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
     return $this;
 }
 /**
  * Collect customer balance totals for invoice
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Enterprise_CustomerBalance_Model_Total_Invoice_Customerbalance
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     if (!Mage::helper('enterprise_customerbalance')->isEnabled()) {
         return $this;
     }
     $order = $invoice->getOrder();
     if ($order->getBaseCustomerBalanceAmount() && $order->getBaseCustomerBalanceInvoiced() != $order->getBaseCustomerBalanceAmount()) {
         $gcaLeft = $order->getBaseCustomerBalanceAmount() - $order->getBaseCustomerBalanceInvoiced();
         $used = 0;
         $baseUsed = 0;
         if ($gcaLeft >= $invoice->getBaseGrandTotal()) {
             $baseUsed = $invoice->getBaseGrandTotal();
             $used = $invoice->getGrandTotal();
             $invoice->setBaseGrandTotal(0);
             $invoice->setGrandTotal(0);
         } else {
             $baseUsed = $order->getBaseCustomerBalanceAmount() - $order->getBaseCustomerBalanceInvoiced();
             $used = $order->getCustomerBalanceAmount() - $order->getCustomerBalanceInvoiced();
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseUsed);
             $invoice->setGrandTotal($invoice->getGrandTotal() - $used);
         }
         $invoice->setBaseCustomerBalanceAmount($baseUsed);
         $invoice->setCustomerBalanceAmount($used);
     }
     return $this;
 }
Example #4
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if ($order->getCustomercreditDiscount() < 0.0001) {
         return;
     }
     if ($invoice->isLast()) {
         $baseDiscount = $order->getBaseCustomercreditDiscount();
         $discount = $order->getCustomercreditDiscount();
         foreach ($order->getInvoiceCollection() as $existedInvoice) {
             if ($baseDiscount > 0.0001) {
                 $baseDiscount -= $existedInvoice->getBaseCustomercreditDiscount();
                 $discount -= $existedInvoice->getCustomercreditDiscount();
             }
         }
     } else {
         $orderData = $order->getData();
         $invoiceData = $invoice->getData();
         if ($invoiceData['shipping_incl_tax']) {
             $ratio = ($invoiceData['subtotal_incl_tax'] + $invoiceData['shipping_incl_tax']) / ($orderData['subtotal_incl_tax'] + $orderData['shipping_incl_tax']);
         } else {
             $ratio = $invoiceData['subtotal_incl_tax'] / ($orderData['subtotal_incl_tax'] + $orderData['shipping_incl_tax']);
         }
         $baseDiscount = $order->getBaseCustomercreditDiscount() * $ratio;
         $discount = $order->getCustomercreditDiscount() * $ratio;
         $maxBaseDiscount = $order->getBaseCustomercreditDiscount();
         $maxDiscount = $order->getCustomercreditDiscount();
         foreach ($order->getInvoiceCollection() as $existedInvoice) {
             if ($maxBaseDiscount > 0.0001) {
                 $maxBaseDiscount -= $existedInvoice->getBaseCustomercreditDiscount();
                 $maxDiscount -= $existedInvoice->getCustomercreditDiscount();
             }
         }
         if ($baseDiscount > $maxBaseDiscount) {
             $baseDiscount = $maxBaseDiscount;
             $discount = $maxDiscount;
         }
     }
     if ($baseDiscount > 0.0001) {
         if ($invoice->getBaseGrandTotal() <= $baseDiscount) {
             $invoice->setBaseCustomercreditDiscount($invoice->getBaseGrandTotal());
             $invoice->setCustomercreditDiscount($invoice->getGrandTotal());
             $invoice->setBaseGrandTotal(0.0);
             $invoice->setGrandTotal(0.0);
         } else {
             $invoice->setBaseCustomercreditDiscount($baseDiscount);
             $invoice->setCustomercreditDiscount($discount);
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseDiscount);
             $invoice->setGrandTotal($invoice->getGrandTotal() - $discount);
         }
     }
 }
Example #5
0
 /**
  * Collect reward total for invoice
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Rewards_Model_Sales_Invoice_Total
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if (!$order->getHasSpentPoints()) {
         return $this;
     }
     list($acc_diff, $acc_diff_base) = $this->getAccumulatedDiscounts($order);
     //@nelkaake -a 12/01/11: This will help us make sure we never go below $0
     $acc_diff = min($acc_diff, $invoice->getGrandTotal());
     $acc_diff_base = min($acc_diff_base, $invoice->getBaseGrandTotal());
     $invoice->setGrandTotal($invoice->getGrandTotal() - $acc_diff);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $acc_diff_base);
     return $this;
 }
Example #6
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if ($order->getPayment()->getMethodInstance()->getCode() != 'cashondelivery') {
         return $this;
     }
     if (!$order->getCodFee()) {
         return $this;
     }
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
         if ($previusInvoice->getCodAmount() && !$previusInvoice->isCanceled()) {
             $includeCodTax = false;
         }
     }
     $baseCodFee = $order->getBaseCodFee();
     $baseCodFeeInvoiced = $order->getBaseCodFeeInvoiced();
     $baseInvoiceTotal = $invoice->getBaseGrandTotal();
     $codFee = $order->getCodFee();
     $codFeeInvoiced = $order->getCodFeeInvoiced();
     $invoiceTotal = $invoice->getGrandTotal();
     if (!$baseCodFee || $baseCodFeeInvoiced == $baseCodFee) {
         return $this;
     }
     $baseCodFeeToInvoice = $baseCodFee - $baseCodFeeInvoiced;
     $codFeeToInvoice = $codFee - $codFeeInvoiced;
     $baseInvoiceTotal = $baseInvoiceTotal + $baseCodFeeToInvoice;
     $invoiceTotal = $invoiceTotal + $codFeeToInvoice;
     $invoice->setBaseGrandTotal($baseInvoiceTotal);
     $invoice->setGrandTotal($invoiceTotal);
     $invoice->setBaseCodFee($baseCodFeeToInvoice);
     $invoice->setCodFee($codFeeToInvoice);
     $order->setBaseCodFeeInvoiced($baseCodFeeInvoiced + $baseCodFeeToInvoice);
     $order->setCodFeeInvoiced($codFeeInvoiced + $codFeeToInvoice);
     return $this;
 }
Example #7
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setGomageGiftWrapAmount(0);
     $invoice->setBaseGomageGiftWrapAmount(0);
     $totalGomageGiftWrapAmount = 0;
     $baseTotalGomageGiftWrapAmount = 0;
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $orderItem = $item->getOrderItem();
         $orderItemGomageGiftWrap = (double) $orderItem->getGomageGiftWrapAmount();
         $baseOrderItemGomageGiftWrap = (double) $orderItem->getBaseGomageGiftWrapAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemGomageGiftWrap && $orderItemQty) {
             $GomageGiftWrap = $orderItemGomageGiftWrap * $item->getQty() / $orderItemQty;
             $baseGomageGiftWrap = $baseOrderItemGomageGiftWrap * $item->getQty() / $orderItemQty;
             $GomageGiftWrap = $invoice->getStore()->roundPrice($GomageGiftWrap);
             $baseGomageGiftWrap = $invoice->getStore()->roundPrice($baseGomageGiftWrap);
             $item->setGomageGiftWrapAmount($GomageGiftWrap);
             $item->setBaseGomageGiftWrapAmount($baseGomageGiftWrap);
             $totalGomageGiftWrapAmount += $GomageGiftWrap;
             $baseTotalGomageGiftWrapAmount += $baseGomageGiftWrap;
         }
     }
     $invoice->setGomageGiftWrapAmount($totalGomageGiftWrapAmount);
     $invoice->setBaseGomageGiftWrapAmount($baseTotalGomageGiftWrapAmount);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $totalGomageGiftWrapAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseTotalGomageGiftWrapAmount);
     return $this;
 }
Example #8
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;
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setData('zitec_dpd_cashondelivery_surcharge', 0);
     $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', 0);
     $invoice->setData('zitec_dpd_cashondelivery_surcharge_tax', 0);
     $invoice->setData('base_zitec_dpd_cashondelivery_surcharge_tax', 0);
     $order = $invoice->getOrder();
     $amount = $order->getData('zitec_dpd_cashondelivery_surcharge');
     if ($amount) {
         // We look at the bills to see if it has already claimed the COD surcharge.
         foreach ($order->getInvoiceCollection() as $previousInvoice) {
             /* @var $previousInvoice Mage_Sales_Model_Order_Invoice */
             if (!$previousInvoice->isCanceled() && $previousInvoice->getData('base_zitec_dpd_cashondelivery_surcharge')) {
                 return $this;
             }
         }
         $invoice->setData('zitec_dpd_cashondelivery_surcharge', $amount);
         $baseAmount = $order->getData('base_zitec_dpd_cashondelivery_surcharge');
         $invoice->setData('base_zitec_dpd_cashondelivery_surcharge', $baseAmount);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);
         // NB. We do not add taxes grand total here.
         // Are added Zitec_Dpd_Model_Sales_Order_Invoice_Total_Tax.
     }
     return $this;
 }
Example #10
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if (!preg_match('/^capayable/', $order->getPayment()->getMethodInstance()->getCode())) {
         return $this;
     }
     if (!$order->getCapayableFee()) {
         return $this;
     }
     foreach ($invoice->getOrder()->getInvoiceCollection() as $prevInvoice) {
         if ($prevInvoice->getCapayableFeeAmount() && !$prevInvoice->isCanceled()) {
             $includeFeeTax = FALSE;
         }
     }
     $basePaymentFee = $order->getBaseCapayableFee();
     $basePaymentFeeInvoiced = $order->getBaseCapayableFeeInvoiced();
     $baseInvoiceTotal = $invoice->getBaseGrandTotal();
     $paymentFee = $order->getCapayableFee();
     $paymentFeeInvoiced = $order->getCapayableFeeInvoiced();
     $invoiceTotal = $invoice->getGrandTotal();
     if (!$basePaymentFee || $basePaymentFeeInvoiced == $basePaymentFee) {
         return $this;
     }
     $basePaymentFeeToInvoice = $basePaymentFee - $basePaymentFeeInvoiced;
     $paymentFeeToInvoice = $paymentFee - $paymentFeeInvoiced;
     $baseInvoiceTotal = $baseInvoiceTotal + $basePaymentFeeToInvoice;
     $invoiceTotal = $invoiceTotal + $paymentFeeToInvoice;
     $invoice->setBaseGrandTotal($baseInvoiceTotal);
     $invoice->setGrandTotal($invoiceTotal);
     $invoice->setBaseCapayableFee($basePaymentFeeToInvoice);
     $invoice->setCapayableFee($paymentFeeToInvoice);
     $order->setBaseCapayableFeeInvoiced($basePaymentFeeInvoiced + $basePaymentFeeToInvoice);
     $order->setCapayableFeeInvoiced($paymentFeeInvoiced + $paymentFeeToInvoice);
     return $this;
 }
Example #11
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;
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $baseDiscount = 0;
     $discount = 0;
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $orderItem = $item->getOrderItem();
         $orderItemDiscount = (double) $orderItem->getAffiliateplusAmount();
         $baseOrderItemDiscount = (double) $orderItem->getBaseAffiliateplusAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemDiscount && $orderItemQty) {
             $discount -= $orderItemDiscount * $item->getQty() / $orderItemQty;
             $baseDiscount -= $baseOrderItemDiscount * $item->getQty() / $orderItemQty;
         }
     }
     if (!floatval($baseDiscount)) {
         $order = $invoice->getOrder();
         $baseDiscount = $order->getBaseAffiliateplusDiscount();
         $discount = $order->getAffiliateplusDiscount();
     }
     if (floatval($baseDiscount)) {
         $baseDiscount = Mage::app()->getStore()->roundPrice($baseDiscount);
         $discount = Mage::app()->getStore()->roundPrice($discount);
         $invoice->setBaseAffiliateplusDiscount($baseDiscount);
         $invoice->setAffiliateplusDiscount($discount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseDiscount);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $discount);
     }
     return $this;
 }
Example #13
0
 /**
  * @param Mage_Sales_Model_Order_Invoice $invoice
  *
  * @return $this
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     /**
      * The COD fee is always added to the first invoice, so if this order already has invoices, we don't have to add
      * anything.
      */
     if ($order->hasInvoices()) {
         return $this;
     }
     /**
      * Get the COD fee amounts.
      */
     $fee = $order->getBuckarooFee();
     $baseFee = $order->getBaseBuckarooFee();
     /**
      * If no COD fee is set, there is nothing to add/
      */
     if ($fee < 0.01 || $baseFee < 0.01) {
         return $this;
     }
     /**
      * Add the COD fee amounts to the invoice and update the amounts for the order.
      */
     $grandTotal = $invoice->getGrandTotal();
     $baseGrandTotal = $invoice->getBaseGrandTotal();
     $invoice->setBuckarooFee($fee)->setBaseBuckarooFee($baseFee)->setGrandTotal($grandTotal + $fee)->setBaseGrandTotal($baseGrandTotal + $baseFee);
     $order->setBuckarooFeeInvoiced($fee)->setBaseBuckarooFeeInvoiced($baseFee);
     return $this;
 }
Example #14
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $invoice->setGrandTotal($invoice->getGrandTotal() + $order->getInterest());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $order->getBaseInterest());
     return $this;
 }
Example #15
0
 /**
  * collect discout total for invoice
  * 
  * - on payment method "sofortrechnung" discount will invoice on first invoice complete including canceled items
  * 
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @return Mage_Sales_Model_Order_Invoice_Total_Discount
  * @see app/code/core/Mage/Sales/Model/Order/Invoice/Total/Mage_Sales_Model_Order_Invoice_Total_Discount::collect()
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     // special case for modified sofortrechnung
     if ($invoice->getOrder()->getPayment()->getMethod() == "sofortrechnung") {
         // special special case if configurable product  is in basket
         $hackDiff = 0;
         $enableDiff = false;
         $discountTax = 100;
         foreach ($invoice->getOrder()->getAllVisibleItems() as $item) {
             $enableDiff = $enableDiff || $item->product_type == 'configurable';
             if ($item->getTaxPercent() > 0) {
                 // tax of discount is min of cart-items
                 $discountTax = min($item->getTaxPercent(), $discountTax);
             }
         }
         $totalDiscountAmount = -$invoice->getOrder()->getDiscountInvoiced() - $invoice->getOrder()->getDiscountAmount();
         $baseTotalDiscountAmount = -$invoice->getOrder()->getBaseDiscountInvoiced() - $invoice->getOrder()->getBaseDiscountAmount();
         $invoice->setDiscountAmount(-$totalDiscountAmount);
         $invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
         if ($enableDiff) {
             $hackDiff = $totalDiscountAmount - $totalDiscountAmount * (100 / ($discountTax + 100));
         }
         $invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount + $hackDiff);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount + $hackDiff);
         return $this;
     }
     return parent::collect($invoice);
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setShippingAmount(0);
     $invoice->setBaseShippingAmount(0);
     $orderShippingAmount = $invoice->getOrder()->getShippingAmount();
     $baseOrderShippingAmount = $invoice->getOrder()->getBaseShippingAmount();
     $shippingInclTax = $invoice->getOrder()->getShippingInclTax();
     $baseShippingInclTax = $invoice->getOrder()->getBaseShippingInclTax();
     if ($orderShippingAmount) {
         /**
          * Check shipping amount in previus invoices
          */
         foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
             if ($previusInvoice->getShippingAmount() && !$previusInvoice->isCanceled()) {
                 return $this;
             }
         }
         $invoice->setShippingAmount($orderShippingAmount);
         $invoice->setBaseShippingAmount($baseOrderShippingAmount);
         $invoice->setShippingInclTax($shippingInclTax);
         $invoice->setBaseShippingInclTax($baseShippingInclTax);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $orderShippingAmount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseOrderShippingAmount);
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setPaymentCharge(0);
     $invoice->setBasePaymentCharge(0);
     /*$hasInvoices = $invoice->getOrder()->hasInvoices();
             $paymentMethod = $invoice->getOrder()->getPayment()->getMethod();
             if ($paymentMethod) { //&& !$hasInvoices
             	$chargeType = Mage::getStoreConfig('payment/'.strval($paymentMethod).'/charge_type');
             	$chargeValue = Mage::getStoreConfig('payment/'.strval($paymentMethod).'/charge_value');
             	if ($chargeValue) {
             		if ($chargeType=="percentage") {
             			$subTotal = $invoice->getSubtotal();
             			$amount = $subTotal * intval($chargeValue) / 100;
             		}
             		else {
             			$amount = intval($chargeValue);
             		}
                 	$invoice->setPaymentCharge($amount);
                 	$invoice->setBasePaymentCharge($amount);
             	}
             }
     
             $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
     		*/
     $amount = $invoice->getOrder()->getPaymentCharge();
     $invoice->setPaymentCharge($amount);
     $amount = $invoice->getOrder()->getBasePaymentCharge();
     $invoice->setBasePaymentCharge($amount);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getPaymentCharge());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBasePaymentCharge());
     return $this;
 }
Example #18
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 #19
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $initAmount = $invoice->getOrder()->getSubscriptionInitAmount();
     $baseInitAmount = $invoice->getOrder()->getBaseSubscriptionInitAmount();
     $invoice->setGrandTotal($invoice->getGrandTotal() + $initAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseInitAmount);
     return $this;
 }
Example #20
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $amount = number_format($order->getGiftCardValue(), 2);
     $invoice->setGrandTotal($invoice->getGrandTotal() - $amount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $amount);
     return $this;
 }
Example #21
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $amount = $this->_giftWrapAmount($invoice->getOrder());
     $invoice->setGiftWrapAmount($amount);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);
     return $this;
 }
Example #22
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setDiscountAmount(0);
     $invoice->setBaseDiscountAmount(0);
     $totalDiscountAmount = 0;
     $baseTotalDiscountAmount = 0;
     /**
      * Checking if shipping discount was added in previous invoices.
      * So basically if we have invoice with positive discount and it
      * was not canceled we don't add shipping discount to this one.
      */
     $addShippingDicount = true;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previusInvoice) {
         if ($previusInvoice->getDiscountAmount()) {
             $addShippingDicount = false;
         }
     }
     if ($addShippingDicount) {
         $totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
         $baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
     }
     /** @var $item Mage_Sales_Model_Order_Invoice_Item */
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         if ($orderItem->isDummy()) {
             continue;
         }
         $orderItemDiscount = (double) $orderItem->getDiscountAmount();
         $baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemDiscount && $orderItemQty) {
             /**
              * Resolve rounding problems
              *
              * We dont want to include the weee discount amount as the right amount
              * is added when calculating the taxes.
              *
              * Also the subtotal is without weee
              */
             $discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
             $baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
             if (!$item->isLast()) {
                 $activeQty = $orderItemQty - $orderItem->getQtyInvoiced();
                 $discount = $invoice->roundPrice($discount / $activeQty * $item->getQty(), 'regular', true);
                 $baseDiscount = $invoice->roundPrice($baseDiscount / $activeQty * $item->getQty(), 'base', true);
             }
             $item->setDiscountAmount($discount);
             $item->setBaseDiscountAmount($baseDiscount);
             $totalDiscountAmount += $discount;
             $baseTotalDiscountAmount += $baseDiscount;
         }
     }
     $invoice->setDiscountAmount(-$totalDiscountAmount);
     $invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
     $invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
     return $this;
 }
Example #23
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $amount = $order->getMspCashondelivery();
     $baseAmount = $order->getMspBaseCashondelivery();
     $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseAmount);
     return $this;
 }
Example #24
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $feeAmountLeft = $order->getFeeAmount() - $order->getFeeAmountInvoiced();
     $baseFeeAmountLeft = $order->getBaseFeeAmount() - $order->getBaseFeeAmountInvoiced();
     if (abs($baseFeeAmountLeft) < $invoice->getBaseGrandTotal()) {
         $invoice->setGrandTotal($invoice->getGrandTotal() + $feeAmountLeft);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseFeeAmountLeft);
     } else {
         $feeAmountLeft = $invoice->getGrandTotal() * -1;
         $baseFeeAmountLeft = $invoice->getBaseGrandTotal() * -1;
         $invoice->setGrandTotal(0);
         $invoice->setBaseGrandTotal(0);
     }
     $invoice->setFeeAmount($feeAmountLeft);
     $invoice->setBaseFeeAmount($baseFeeAmountLeft);
     return $this;
 }
Example #25
0
 /**
  * @param Mage_Sales_Model_Order_Invoice $invoice
  *
  * @return $this
  */
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     /**
      * The COD fee tax is always added to the first invoice, so if this order already has invoices, we don't have to
      * add anything.
      */
     if ($order->hasInvoices()) {
         return $this;
     }
     /**
      * Get the COD fee tax amounts.
      */
     $feeTax = $order->getBuckarooFeeTax();
     $baseFeeTax = $order->getBaseBuckarooFeeTax();
     /**
      * If no COD fee tax is set, there is nothing to add/
      */
     if ($feeTax < 0.01 || $baseFeeTax < 0.01) {
         return $this;
     }
     /**
      * Add the COD fee tax amounts to the invoice.
      */
     $invoice->setBuckarooFeeTax($feeTax)->setBaseBuckarooFeeTax($baseFeeTax)->setTaxAmount($invoice->getTaxAmount() + $feeTax)->setBaseTaxAmount($invoice->getBaseTaxAmount() + $baseFeeTax);
     /**
      * For all versions except 1.13.0.X and 1.8.0.X we need to add the Payment fee tax to the grand total amounts.
      */
     $helper = Mage::helper('buckaroo3extended');
     //fix for Magento 1.6.2.0 for showing correctly taxes in the order totals
     if (!$helper->isEnterprise() && version_compare(Mage::getVersion(), '1.6.2.0', '==')) {
         $grandTotal = $invoice->getGrandTotal();
         $baseGrandTotal = $invoice->getBaseGrandTotal();
     } else {
         $grandTotal = $invoice->getGrandTotal() + $feeTax;
         $baseGrandTotal = $invoice->getBaseGrandTotal() + $baseFeeTax;
     }
     $invoice->setGrandTotal($grandTotal)->setBaseGrandTotal($baseGrandTotal);
     /**
      * Update the order's COD fee tax amounts.
      */
     $order->setBuckarooFeeTaxInvoiced($feeTax)->setBaseBuckarooFeeTaxInvoiced($baseFeeTax);
     return $this;
 }
Example #26
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if ($order->getMoneyBase() && $order->getCurrentMoney()) {
         $money = $order->getMoneyBase();
         $currentMoney = $order->getCurrentMoney();
         if ($invoice->getBaseGrandTotal() + $money < 0) {
             $invoice->setMoneyBase(-$invoice->getBaseGrandTotal());
             $invoice->setCurrentMoney(-$invoice->getGrandTotal());
             $invoice->setBaseGrandTotal(0);
             $invoice->setGrandTotal(0);
         } else {
             $invoice->setMoneyBase($money);
             $invoice->setCurrentMoney($currentMoney);
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $money);
             $invoice->setGrandTotal($invoice->getGrandTotal() + $currentMoney);
         }
     }
 }
Example #27
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $creditpointAmountLeft = $order->getCreditpointAmount() - $order->getCreditpointAmountInvoiced();
     $basecreditpointAmountLeft = $order->getBaseCreditpointAmount() - $order->getBaseCreditpointAmountInvoiced();
     if (abs($basecreditpointAmountLeft) < $invoice->getBaseGrandTotal()) {
         //customer redeemed discount so we are subtracting the value from total
         $invoice->setGrandTotal($invoice->getGrandTotal() - $creditpointAmountLeft);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $basecreditpointAmountLeft);
     } else {
         $creditpointAmountLeft = $invoice->getGrandTotal() * -1;
         $basecreditpointAmountLeft = $invoice->getBaseGrandTotal() * -1;
         $invoice->setGrandTotal(0);
         $invoice->setBaseGrandTotal(0);
     }
     $invoice->setCreditpointAmount($creditpointAmountLeft);
     $invoice->setBaseCreditpointAmount($basecreditpointAmountLeft);
     return $this;
 }
Example #28
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $orderDiscountTotal = $order->getDiscountTotal();
     if ($orderDiscountTotal && count($order->getInvoiceCollection()) == 0) {
         $invoice->setGrandTotal($invoice->getGrandTotal() + $orderDiscountTotal);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $orderDiscountTotal);
     }
     return $this;
 }
Example #29
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order = $invoice->getOrder();
     if ($order->getOfferDiscount() && $order->getBaseOfferDiscount()) {
         $baseOfferDiscount = $order->getBaseOfferDiscount();
         $offerDiscount = $order->getOfferDiscount();
         if ($invoice->getBaseGrandTotal() + $baseOfferDiscount < 0) {
             $invoice->getBaseOfferDiscount(-$invoice->getBaseGrandTotal());
             $invoice->getOfferDiscount(-$invoice->getGrandTotal());
             $invoice->setBaseGrandTotal(0);
             $invoice->setGrandTotal(0);
         } else {
             $invoice->getBaseOfferDiscount($baseOfferDiscount);
             $invoice->getOfferDiscount($offerDiscount);
             $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseOfferDiscount);
             $invoice->setGrandTotal($invoice->getGrandTotal() + $offerDiscount);
         }
     }
 }
Example #30
0
 public function collect(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $order_id = $invoice->getOrderId();
     $order = Mage::getModel('sales/order')->load($order_id);
     $invoice->setFeeAmount($order->getFeeAmount());
     $invoice->setBaseFeeAmount($order->getBaseFeeAmount());
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getFeeAmount());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getBaseFeeAmount());
     return $this;
 }