Example #1
0
 /**
  * Collect snap gift card account totals for credit memo
  *
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @return $this
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     if ($order->getBaseSnapCardsAmount() && $order->getBaseSnapCardsInvoiced() != 0) {
         $gcaLeft = $order->getBaseSnapCardsInvoiced() - $order->getBaseSnapCardsRefunded();
         $used = 0;
         $baseUsed = 0;
         if ($gcaLeft >= $creditmemo->getBaseGrandTotal()) {
             $baseUsed = $creditmemo->getBaseGrandTotal();
             $used = $creditmemo->getGrandTotal();
             $creditmemo->setBaseGrandTotal(0);
             $creditmemo->setGrandTotal(0);
             $creditmemo->setAllowZeroGrandTotal(true);
         } else {
             $baseUsed = $order->getBaseSnapCardsInvoiced() - $order->getBaseSnapCardsRefunded();
             $used = $order->getSnapCardsInvoiced() - $order->getSnapCardsRefunded();
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseUsed);
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $used);
         }
         $creditmemo->setBaseSnapCardsAmount($baseUsed);
         $creditmemo->setSnapCardsAmount($used);
     }
     $creditmemo->setBaseCustomerBalanceReturnMax($creditmemo->getBaseCustomerBalanceReturnMax() + $creditmemo->getBaseSnapCardsAmount());
     $creditmemo->setCustomerBalanceReturnMax($creditmemo->getCustomerBalanceReturnMax() + $creditmemo->getSnapCardsAmount());
     $creditmemo->setCustomerBalanceReturnMax($creditmemo->getCustomerBalanceReturnMax() + $creditmemo->getGrandTotal());
     return $this;
 }
 /**
  * Collect customer balance totals for credit memo
  *
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @return Enterprise_CustomerBalance_Model_Total_Creditmemo_Customerbalance
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setBsCustomerBalTotalRefunded(0);
     $creditmemo->setCustomerBalTotalRefunded(0);
     $creditmemo->setBaseCustomerBalanceReturnMax(0);
     $creditmemo->setCustomerBalanceReturnMax(0);
     if (!Mage::helper('enterprise_customerbalance')->isEnabled()) {
         return $this;
     }
     $order = $creditmemo->getOrder();
     if ($order->getBaseCustomerBalanceAmount() && $order->getBaseCustomerBalanceInvoiced() != 0) {
         $cbLeft = $order->getBaseCustomerBalanceInvoiced() - $order->getBaseCustomerBalanceRefunded();
         $used = 0;
         $baseUsed = 0;
         if ($cbLeft >= $creditmemo->getBaseGrandTotal()) {
             $baseUsed = $creditmemo->getBaseGrandTotal();
             $used = $creditmemo->getGrandTotal();
             $creditmemo->setBaseGrandTotal(0);
             $creditmemo->setGrandTotal(0);
             $creditmemo->setAllowZeroGrandTotal(true);
         } else {
             $baseUsed = $order->getBaseCustomerBalanceInvoiced() - $order->getBaseCustomerBalanceRefunded();
             $used = $order->getCustomerBalanceInvoiced() - $order->getCustomerBalanceRefunded();
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseUsed);
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $used);
         }
         $creditmemo->setBaseCustomerBalanceAmount($baseUsed);
         $creditmemo->setCustomerBalanceAmount($used);
     }
     $creditmemo->setBaseCustomerBalanceReturnMax($creditmemo->getBaseCustomerBalanceReturnMax() + $creditmemo->getBaseGrandTotal());
     $creditmemo->setBaseCustomerBalanceReturnMax($creditmemo->getBaseCustomerBalanceReturnMax() + $creditmemo->getBaseCustomerBalanceAmount());
     $creditmemo->setCustomerBalanceReturnMax($creditmemo->getCustomerBalanceReturnMax() + $creditmemo->getCustomerBalanceAmount());
     return $this;
 }
Example #3
0
 /**
  * Collect reward totals for credit memo
  *
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @return Enterprise_Reward_Model_Total_Creditmemo_Reward
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $rewardCurrecnyAmountLeft = $order->getRewardCurrencyAmountInvoiced() - $order->getRewardCurrencyAmountRefunded();
     $baseRewardCurrecnyAmountLeft = $order->getBaseRewardCurrencyAmountInvoiced() - $order->getBaseRewardCurrencyAmountRefunded();
     if ($order->getBaseRewardCurrencyAmount() && $baseRewardCurrecnyAmountLeft > 0) {
         if ($baseRewardCurrecnyAmountLeft >= $creditmemo->getBaseGrandTotal()) {
             $rewardCurrecnyAmountLeft = $creditmemo->getGrandTotal();
             $baseRewardCurrecnyAmountLeft = $creditmemo->getBaseGrandTotal();
             $creditmemo->setGrandTotal(0);
             $creditmemo->setBaseGrandTotal(0);
             $creditmemo->setAllowZeroGrandTotal(true);
         } else {
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $rewardCurrecnyAmountLeft);
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseRewardCurrecnyAmountLeft);
         }
         $pointValue = $order->getRewardPointsBalance() / $order->getBaseRewardCurrencyAmount();
         $rewardPointsBalance = $baseRewardCurrecnyAmountLeft * ceil($pointValue);
         $rewardPointsBalanceLeft = $order->getRewardPointsBalance() - $order->getRewardPointsBalanceRefunded();
         if ($rewardPointsBalance > $rewardPointsBalanceLeft) {
             $rewardPointsBalance = $rewardPointsBalanceLeft;
         }
         $creditmemo->setRewardPointsBalance($rewardPointsBalance);
         $creditmemo->setRewardCurrencyAmount($rewardCurrecnyAmountLeft);
         $creditmemo->setBaseRewardCurrencyAmount($baseRewardCurrecnyAmountLeft);
     }
     return $this;
 }
Example #4
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $baseDiscount = 0;
     $discount = 0;
     $order = $creditmemo->getOrder();
     $baseOrderDiscount = $order->getBaseAffiliateCredit();
     $orderDiscount = $order->getAffiliateCredit();
     if ($creditmemo->getBaseGrandTotal() < 0.0001 || $baseOrderDiscount >= 0) {
         return $this;
     }
     $baseInvoicedDiscount = 0;
     $invoicedDiscount = 0;
     foreach ($order->getCreditmemosCollection() as $_creditmemo) {
         $baseInvoicedDiscount += $_creditmemo->getBaseAffiliateCredit();
         $invoicedDiscount += $_creditmemo->getAffiliateCredit();
     }
     $baseOrderTotal = $order->getBaseGrandTotal() - $baseOrderDiscount;
     $baseDiscount = $baseOrderDiscount * $creditmemo->getBaseGrandTotal() / $baseOrderTotal;
     $discount = $orderDiscount * $creditmemo->getBaseGrandTotal() / $baseOrderTotal;
     if ($baseDiscount < $baseOrderDiscount) {
         $baseDiscount = $baseOrderDiscount;
         $discount = $orderDiscount;
     }
     if ($baseDiscount) {
         $baseDiscount = Mage::app()->getStore()->roundPrice($baseDiscount);
         $discount = Mage::app()->getStore()->roundPrice($discount);
         $creditmemo->setBaseAffiliateCredit($baseDiscount);
         $creditmemo->setAffiliateCredit($discount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseDiscount);
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $discount);
         $creditmemo->setAllowZeroGrandTotal(true);
     }
     return $this;
 }
Example #5
0
 /**
  * Collect reward total for invoice
  *
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @return Rewards_Model_Sales_Invoice_Total
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->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, $creditmemo->getGrandTotal());
     $acc_diff_base = min($acc_diff_base, $creditmemo->getBaseGrandTotal());
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $acc_diff);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $acc_diff_base);
     return $this;
 }
Example #6
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         $orderItemTax = $item->getOrderItem()->getTaxAmount();
         $baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
         $orderItemQty = $item->getOrderItem()->getQtyOrdered();
         if ($orderItemTax && $orderItemQty) {
             $tax = $orderItemTax * $item->getQty() / $orderItemQty;
             $baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
             $tax = $creditmemo->getStore()->roundPrice($tax);
             $baseTax = $creditmemo->getStore()->roundPrice($baseTax);
             $item->setTaxAmount($tax);
             $item->setBaseTaxAmount($baseTax);
             $totalTax += $tax;
             $baseTotalTax += $baseTax;
         }
     }
     $creditmemo->setTaxAmount($totalTax);
     $creditmemo->setBaseTaxAmount($baseTotalTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #7
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     if (!$creditmemo->getInvoice() || !$creditmemo->getInvoice()->getId()) {
         return;
     }
     $order = $creditmemo->getOrder();
     if ($order->getWebposCash() < 0.0001 || $order->getGrandTotal() < 0.0001) {
         return;
     }
     $ratio = $creditmemo->getGrandTotal() / $order->getGrandTotal();
     $cash = $order->getWebposCash() * $ratio;
     $baseCash = $order->getWebposBaseCash() * $ratio;
     $maxcash = $order->getWebposCash();
     $maxbaseCash = $order->getWebposBaseCash();
     foreach ($order->getCreditmemosCollection() as $existedCreditmemo) {
         if ($maxcash > 0.0001) {
             $maxcash -= $existedCreditmemo->getWebposCash();
             $maxbaseCash -= $existedCreditmemo->getWebposBaseCash();
         }
     }
     if ($cash > $maxcash) {
         $cash = $maxcash;
         $baseCash = $maxbaseCash;
     }
     if ($cash > 0.0001) {
         $creditmemo->setWebposCash($cash)->setWebposBaseCash($baseCash);
         if ($creditmemo->getGrandTotal() <= $cash) {
             $creditmemo->setBaseGrandTotal(0.0)->setGrandTotal(0.0);
         } else {
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $cash)->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseCash);
         }
     }
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $allowedAmount = $order->getShippingAmount() - $order->getShippingRefunded();
     $baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
     /**
      * Check if shipping amount was specified (from invoice or another source).
      * Using has magic method to allow setting 0 as shipping amount.
      */
     if ($creditmemo->hasBaseShippingAmount()) {
         $baseShippingAmount = Mage::app()->getStore()->roundPrice($creditmemo->getBaseShippingAmount());
         if ($baseShippingAmount < $baseAllowedAmount) {
             $shippingAmount = $allowedAmount * $baseShippingAmount / $baseAllowedAmount;
             $shippingAmount = Mage::app()->getStore()->roundPrice($shippingAmount);
         } elseif ($baseShippingAmount == $baseAllowedAmount) {
             $shippingAmount = $allowedAmount;
         } else {
             $baseAllowedAmount = $order->formatBasePrice($baseAllowedAmount);
             Mage::throwException(Mage::helper('sales')->__('Maximum shipping amount allowed to refound is: %s', $baseAllowedAmount));
         }
     } else {
         $baseShippingAmount = $baseAllowedAmount;
         $shippingAmount = $allowedAmount;
     }
     $creditmemo->setShippingAmount($shippingAmount);
     $creditmemo->setBaseShippingAmount($baseShippingAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $shippingAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseShippingAmount);
     return $this;
 }
Example #9
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setPaymentCharge(0);
     $creditmemo->setBasePaymentCharge(0);
     $paymentCharge = $creditmemo->getOrder()->getPaymentCharge();
     $basePaymentCharge = $creditmemo->getOrder()->getBasePaymentCharge();
     // we moeten de btw meenemen in de berekening
     $paymentMethod = $creditmemo->getOrder()->getPayment()->getMethod();
     $taxClass = Mage::helper('pay_payment')->getPaymentChargeTaxClass($paymentMethod);
     $storeId = Mage::app()->getStore()->getId();
     $taxCalculationModel = Mage::getSingleton('tax/calculation');
     $request = $taxCalculationModel->getRateRequest($creditmemo->getOrder()->getShippingAddress(), $creditmemo->getOrder()->getBillingAddress(), null, $storeId);
     $request->setStore(Mage::app()->getStore());
     $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass));
     if ($rate > 0) {
         $baseChargeTax = round($creditmemo->getBasePaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
         $chargeTax = round($creditmemo->getPaymentCharge() / (1 + $rate / 100) * ($rate / 100), 2);
     } else {
         $baseChargeTax = 0;
         $chargeTax = 0;
     }
     $creditmemo->setPaymentCharge($paymentCharge);
     $creditmemo->setBasePaymentCharge($basePaymentCharge);
     $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseChargeTax);
     $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $chargeTax);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $creditmemo->getPaymentCharge());
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $creditmemo->getBasePaymentCharge());
     return $this;
 }
Example #10
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setGomageGiftWrapAmount(0);
     $creditmemo->setBaseGomageGiftWrapAmount(0);
     $order = $creditmemo->getOrder();
     $totalGomageGiftWrapAmount = 0;
     $baseTotalGomageGiftWrapAmount = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $orderItemGomageGiftWrap = (double) $item->getOrderItem()->getGomageGiftWrapAmount();
         $baseOrderItemGomageGiftWrap = (double) $item->getOrderItem()->getBaseGomageGiftWrapAmount();
         $orderItemQty = $item->getOrderItem()->getQtyOrdered();
         if ($orderItemGomageGiftWrap && $orderItemQty) {
             $GomageGiftWrap = $orderItemGomageGiftWrap * $item->getQty() / $orderItemQty;
             $baseGomageGiftWrap = $baseOrderItemGomageGiftWrap * $item->getQty() / $orderItemQty;
             $GomageGiftWrap = $creditmemo->getStore()->roundPrice($GomageGiftWrap);
             $baseGomageGiftWrap = $creditmemo->getStore()->roundPrice($baseGomageGiftWrap);
             $item->setGomageGiftWrapAmount($GomageGiftWrap);
             $item->setBaseGomageGiftWrapAmount($baseGomageGiftWrap);
             $totalGomageGiftWrapAmount += $GomageGiftWrap;
             $baseTotalGomageGiftWrapAmount += $baseGomageGiftWrap;
         }
     }
     $creditmemo->setGomageGiftWrapAmount($totalGomageGiftWrapAmount);
     $creditmemo->setBaseGomageGiftWrapAmount($baseTotalGomageGiftWrapAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalGomageGiftWrapAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalGomageGiftWrapAmount);
     return $this;
 }
Example #11
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $cm)
 {
     $order = $cm->getOrder();
     if ($order->getPayment()->getMethodInstance()->getCode() != 'cashondelivery') {
         return $this;
     }
     $baseCmTotal = $cm->getBaseGrandTotal();
     $cmTotal = $cm->getGrandTotal();
     $baseCodFeeCredited = $order->getBaseCodFeeCredited();
     $codFeeCredited = $order->getCodFeeCredited();
     $baseCodFeeInvoiced = $order->getBaseCodFeeInvoiced();
     $codFeeInvoiced = $order->getCodFeeInvoiced();
     if ($cm->getInvoice()) {
         $invoice = $cm->getInvoice();
         $baseCodFeeToCredit = $invoice->getBaseCodFee();
         $codFeeToCredit = $invoice->getCodFee();
     } else {
         $baseCodFeeToCredit = $baseCodFeeInvoiced;
         $codFeeToCredit = $codFeeInvoiced;
     }
     if (!$baseCodFeeToCredit > 0) {
         return $this;
     }
     // Subtracting invoiced COD fee from Credit memo total
     //$cm->setBaseGrandTotal($baseCmTotal-$baseCodFeeToCredit);
     //$cm->setGrandTotal($cmTotal-$codFeeToCredit);
     //$cm->setBaseCodFee($baseCodFeeToCredit);
     //$cm->setCodFee($codFeeToCredit);
     //$order->setBaseCodFeeCredited($baseCodFeeCredited+$baseCodFeeToCredit);
     //$order->setCodFeeCredited($codFeeCredited+$baseCodFeeToCredit);
     return $this;
 }
Example #12
0
 /**
  * Collect the order total
  *
  * @param object $creditmemo The Creditmemo instance to collect from
  *
  * @return Mage_Sales_Model_Order_Creditmemo_Total_Abstract
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $method = $creditmemo->getOrder()->getPayment()->getMethodInstance();
     if (substr($method->getCode(), 0, 5) != 'sisow') {
         return $this;
     }
     $info = $method->getInfoInstance();
     if (!$info) {
         return $this;
     }
     $invoiceFee = $info->getAdditionalInformation('invoice_fee');
     $baseInvoiceFee = $info->getAdditionalInformation('base_invoice_fee');
     if (!$invoiceFee) {
         return $this;
     }
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseInvoiceFee);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $invoiceFee);
     $creditmemo->setBaseInvoiceFee($baseInvoiceFee);
     $creditmemo->setInvoiceFee($invoiceFee);
     $tax = $info->getAdditionalInformation('invoice_tax_amount');
     $baseTax = $info->getAdditionalInformation('base_invoice_tax_amount');
     if (!$tax) {
         return $this;
     }
     $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTax);
     $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $tax);
     return $this;
 }
Example #13
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setDiscountAmount(0);
     $creditmemo->setBaseDiscountAmount(0);
     $totalDiscountAmount = 0;
     $baseTotalDiscountAmount = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         $orderItemDiscount = (double) $item->getOrderItem()->getDiscountAmount();
         $baseOrderItemDiscount = (double) $item->getOrderItem()->getBaseDiscountAmount();
         $orderItemQty = $item->getOrderItem()->getQtyOrdered();
         if ($orderItemDiscount && $orderItemQty) {
             $discount = $orderItemDiscount * $item->getQty() / $orderItemQty;
             $baseDiscount = $baseOrderItemDiscount * $item->getQty() / $orderItemQty;
             $discount = $creditmemo->getStore()->roundPrice($discount);
             $baseDiscount = $creditmemo->getStore()->roundPrice($baseDiscount);
             $item->setDiscountAmount($discount);
             $item->setBaseDiscountAmount($baseDiscount);
             $totalDiscountAmount += $discount;
             $baseTotalDiscountAmount += $baseDiscount;
         }
     }
     $creditmemo->setDiscountAmount($totalDiscountAmount);
     $creditmemo->setBaseDiscountAmount($baseTotalDiscountAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $totalDiscountAmount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $baseTotalDiscountAmount);
     return $this;
 }
Example #14
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $order->getDesconto());
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $order->getBaseDesconto());
     return $this;
 }
Example #15
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $baseDiscount = 0;
     $discount = 0;
     foreach ($creditmemo->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 = $creditmemo->getOrder();
         $baseDiscount = $order->getBaseAffiliateplusDiscount();
         $discount = $order->getAffiliateplusDiscount();
     }
     if (floatval($baseDiscount)) {
         $baseDiscount = Mage::app()->getStore()->roundPrice($baseDiscount);
         $discount = Mage::app()->getStore()->roundPrice($discount);
         $creditmemo->setBaseAffiliateplusDiscount($baseDiscount);
         $creditmemo->setAffiliateplusDiscount($discount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseDiscount);
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $discount);
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $shippingTaxAmount = 0;
     $baseShippingTaxAmount = 0;
     $totalTax = 0;
     $baseTotalTax = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $orderItemTax = $item->getOrderItem()->getTaxAmount();
         $baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
         $orderItemQty = $item->getOrderItem()->getQtyOrdered();
         if ($orderItemTax && $orderItemQty) {
             $tax = $orderItemTax * $item->getQty() / $orderItemQty;
             $baseTax = $baseOrderItemTax * $item->getQty() / $orderItemQty;
             $tax = $creditmemo->getStore()->roundPrice($tax);
             $baseTax = $creditmemo->getStore()->roundPrice($baseTax);
             $item->setTaxAmount($tax);
             $item->setBaseTaxAmount($baseTax);
             $totalTax += $tax;
             $baseTotalTax += $baseTax;
         }
     }
     if ($invoice = $creditmemo->getInvoice()) {
         $totalTax += $invoice->getShippingTaxAmount();
         $baseTotalTax += $invoice->getBaseShippingTaxAmount();
         $creditmemo->setShippingTaxAmount($invoice->getShippingTaxAmount());
         $creditmemo->setBaseShippingTaxAmount($invoice->getBaseShippingTaxAmount());
     } else {
         $shippingAmount = $creditmemo->getOrder()->getBaseShippingAmount();
         $shippingRefundedAmount = $creditmemo->getOrder()->getBaseShippingRefunded();
         $shippingTaxAmount = 0;
         $baseShippingTaxAmount = 0;
         if ($shippingAmount - $shippingRefundedAmount > $creditmemo->getShippingAmount()) {
             $shippingTaxAmount = $creditmemo->getShippingAmount() * ($creditmemo->getOrder()->getShippingTaxAmount() / $shippingAmount);
             $baseShippingTaxAmount = $creditmemo->getBaseShippingAmount() * ($creditmemo->getOrder()->getBaseShippingTaxAmount() / $shippingAmount);
             $shippingTaxAmount = $creditmemo->getStore()->roundPrice($shippingTaxAmount);
             $baseShippingTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingTaxAmount);
         } elseif ($shippingAmount - $shippingRefundedAmount == $creditmemo->getShippingAmount()) {
             $shippingTaxAmount = $creditmemo->getOrder()->getShippingTaxAmount() - $creditmemo->getOrder()->getShippingTaxRefunded();
             $baseShippingTaxAmount = $creditmemo->getOrder()->getBaseShippingTaxAmount() - $creditmemo->getOrder()->getBaseShippingTaxRefunded();
         }
         $totalTax += $shippingTaxAmount;
         $baseTotalTax += $baseShippingTaxAmount;
     }
     $tmpBaseTotalTax = $baseTotalTax - ($creditmemo->getOrder()->getBaseTaxRefunded() - $creditmemo->getOrder()->getBaseShippingTaxRefunded());
     if ($tmpBaseTotalTax < 0) {
         $baseTotalTax = 0;
         $totalTax = 0;
     }
     $creditmemo->setTaxAmount($totalTax);
     $creditmemo->setBaseTaxAmount($baseTotalTax);
     $creditmemo->setShippingTaxAmount($shippingTaxAmount);
     $creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #17
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $amount = $this->_giftWrapAmount($creditmemo->getOrder());
     $creditmemo->setGiftWrapAmount($amount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $amount);
     return $this;
 }
Example #18
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $store = $creditmemo->getStore();
     $totalTax = 0;
     $baseTotalTax = 0;
     $weeeTaxAmount = 0;
     $baseWeeeTaxAmount = 0;
     foreach ($creditmemo->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         if ($orderItem->isDummy()) {
             continue;
         }
         $orderItemQty = $orderItem->getQtyOrdered();
         $weeeRowDiscountAmount = $orderItem->getDiscountAppliedForWeeeTax();
         $weeeDiscountAmount = $creditmemo->roundPrice($weeeRowDiscountAmount / $orderItemQty * $item->getQty(), 'regular', true);
         $baseWeeeRowDiscountAmount = $orderItem->getBaseDiscountAppliedForWeeeTax();
         $baseWeeeDiscountAmount = $creditmemo->roundPrice($baseWeeeRowDiscountAmount / $orderItemQty * $item->getQty(), 'base', true);
         $weeeAmountExclTax = (Mage::helper('weee')->getWeeeTaxInclTax($item) - Mage::helper('weee')->getTotalTaxAppliedForWeeeTax($item)) * $item->getQty();
         $totalTax += $weeeAmountExclTax - $weeeDiscountAmount;
         $baseWeeeAmountExclTax = (Mage::helper('weee')->getBaseWeeeTaxInclTax($item) - Mage::helper('weee')->getBaseTotalTaxAppliedForWeeeTax($item)) * $item->getQty();
         $baseTotalTax += $baseWeeeAmountExclTax - $baseWeeeDiscountAmount;
         $item->setWeeeTaxAppliedRowAmount($weeeAmountExclTax);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmountExclTax);
         $weeeTaxAmount += Mage::helper('weee')->getWeeeTaxInclTax($item) * $item->getQty();
         $baseWeeeTaxAmount += Mage::helper('weee')->getBaseWeeeTaxInclTax($item) * $item->getQty();
         $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();
             $one['weee_discount'] = $weeeDiscountAmount;
             $one['base_weee_discount'] = $baseWeeeDiscountAmount;
             $newApplied[] = $one;
         }
         Mage::helper('weee')->setApplied($item, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
     }
     /*
      * please refer the description in weee - invoice section for reasoning
      */
     if (Mage::helper('weee')->includeInSubtotal($store)) {
         $creditmemo->setSubtotal($creditmemo->getSubtotal() + $totalTax);
         $creditmemo->setBaseSubtotal($creditmemo->getBaseSubtotal() + $baseTotalTax);
     } else {
         $creditmemo->setTaxAmount($creditmemo->getTaxAmount() + $totalTax);
         $creditmemo->setBaseTaxAmount($creditmemo->getBaseTaxAmount() + $baseTotalTax);
     }
     //Increment the subtotal
     $creditmemo->setSubtotalInclTax($creditmemo->getSubtotalInclTax() + $weeeTaxAmount);
     $creditmemo->setBaseSubtotalInclTax($creditmemo->getBaseSubtotalInclTax() + $baseWeeeTaxAmount);
     //Increment the grand total
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
     return $this;
 }
Example #19
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     if (Mage::helper('customfee')->canApply()) {
         $amount = $this->getFeeAmount($creditmemo->getSubtotal());
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $amount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $amount);
     }
     return $this;
 }
Example #20
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $invoice)
 {
     $order = $invoice->getOrder();
     $myTotal = $order->getJurosAmount();
     $baseMyTotal = $order->getBaseJurosAmount();
     $invoice->setGrandTotal($invoice->getGrandTotal() + $myTotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseMyTotal);
     return $this;
 }
Example #21
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setSveaPaymentFeeAmount(0);
     $creditmemo->setBaseSveaPaymentFeeAmount(0);
     $creditmemo->setSveaPaymentFeeTaxAmount(0);
     $creditmemo->setBaseSveaPaymentFeeTaxAmount(0);
     $creditmemo->setSveaPaymentFeeInclTax(0);
     $creditmemo->setBaseSveaPaymentFeeInclTax(0);
     $order = $creditmemo->getOrder();
     if (!$order->getSveaPaymentFeeAmount()) {
         return $this;
     }
     $paymentFeeAmount = 0;
     $basePaymentFeeAmount = 0;
     $paymentFeeTaxAmount = 0;
     $basePaymentFeeTaxAmount = 0;
     $paymentFeeTaxInclTax = 0;
     $grandTotal = $creditmemo->getGrandTotal();
     $baseGrandTotal = $creditmemo->getBaseGrandTotal();
     $taxAmount = $creditmemo->getTaxAmount();
     $baseTaxAmount = $creditmemo->getBaseTaxAmount();
     if ($invoice = $creditmemo->getInvoice()) {
         if ($invoice->getSveaPaymentFeeAmount()) {
             // Refund specific invoice
             $source = $invoice;
         }
     } else {
         if (!$order->getSveaPaymentFeeRefunded()) {
             // Refund from order values
             $source = $order;
         }
     }
     if (isset($source)) {
         $paymentFeeAmount = $source->getSveaPaymentFeeAmount();
         $basePaymentFeeAmount = $source->getBaseSveaPaymentFeeAmount();
         $paymentFeeTaxAmount = $source->getSveaPaymentFeeTaxAmount();
         $basePaymentFeeTaxAmount = $source->getBaseSveaPaymentFeeTaxAmount();
         $paymentFeeTaxInclTax = $source->getSveaPaymentFeeInclTax();
         $basePaymentFeeInclTax = $source->getBaseSveaPaymentFeeInclTax();
     }
     $taxAmount += $paymentFeeTaxAmount;
     $baseTaxAmount += $basePaymentFeeTaxAmount;
     $grandTotal += $paymentFeeTaxInclTax;
     $baseGrandTotal += $basePaymentFeeInclTax;
     $creditmemo->setSveaPaymentFeeAmount($paymentFeeAmount);
     $creditmemo->setBaseSveaPaymentFeeAmount($basePaymentFeeAmount);
     $creditmemo->setSveaPaymentFeeTaxAmount($paymentFeeTaxAmount);
     $creditmemo->setBaseSveaPaymentFeeTaxAmount($basePaymentFeeTaxAmount);
     $creditmemo->setSveaPaymentFeeInclTax($paymentFeeTaxInclTax);
     $creditmemo->setBaseSveaPaymentFeeInclTax($basePaymentFeeInclTax);
     $creditmemo->setTaxAmount($taxAmount);
     $creditmemo->setBaseTaxAmount($baseTaxAmount);
     $creditmemo->setGrandTotal($grandTotal);
     $creditmemo->setBaseGrandTotal($baseGrandTotal);
     return $this;
 }
Example #22
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     if ($order->getMoneyBase() && $order->getCurrentMoney()) {
         $money = $order->getMoneyBase();
         $currentMoney = $order->getCurrentMoney();
         if ($creditmemo->getBaseGrandTotal() + $money < 0) {
             $creditmemo->setMoneyBase(-$creditmemo->getBaseGrandTotal());
             $creditmemo->setCurrentMoney(-$creditmemo->getGrandTotal());
             $creditmemo->setBaseGrandTotal(0);
             $creditmemo->setGrandTotal(0);
         } else {
             $creditmemo->setMoneyBase($money);
             $creditmemo->setCurrentMoney($currentMoney);
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $money);
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $currentMoney);
         }
     }
 }
Example #23
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order_id = $creditmemo->getOrderId();
     $order = Mage::getModel('sales/order')->load($order_id);
     $creditmemo->setFeeAmount($order->getFeeAmount());
     $creditmemo->setBaseFeeAmount($order->getBaseFeeAmount());
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $creditmemo->getFeeAmount());
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $creditmemo->getBaseFeeAmount());
     return $this;
 }
Example #24
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     if ($order->getOfferDiscount() && $order->getBaseOfferDiscount()) {
         $baseOfferDiscount = $order->getBaseOfferDiscount();
         $offerDiscount = $order->getOfferDiscount();
         if ($creditmemo->getBaseGrandTotal() + $baseOfferDiscount < 0) {
             $creditmemo->getBaseOfferDiscount(-$creditmemo->getBaseGrandTotal());
             $creditmemo->getOfferDiscount(-$creditmemo->getGrandTotal());
             $creditmemo->setBaseGrandTotal(0);
             $creditmemo->setGrandTotal(0);
         } else {
             $creditmemo->getBaseOfferDiscount($baseOfferDiscount);
             $creditmemo->getOfferDiscount($offerDiscount);
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseOfferDiscount);
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $offerDiscount);
         }
     }
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setWebposDiscountAmount(0);
     $orderWebposDiscount = $creditmemo->getOrder()->getWebposDiscountAmount();
     if ($orderWebposDiscount) {
         $creditmemo->setWebposDiscountAmount($orderWebposDiscount);
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() - $orderWebposDiscount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() - $orderWebposDiscount);
     }
     return $this;
 }
Example #26
0
 public function collect(Mage_Sales_Model_Order_Creditmemo $invoice)
 {
     $order = $invoice->getOrder();
     $amount = $order->getMspCashondelivery();
     $baseAmount = $order->getMspBaseCashondelivery();
     $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseAmount);
     $invoice->setMspCashondelivery($amount);
     $invoice->setMspBaseCashondelivery($baseAmount);
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     return $this;
     $order = $creditmemo->getOrder();
     $orderDiscountTotal = $order->getDiscountTotal();
     if ($orderDiscountTotal) {
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $orderDiscountTotal);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $orderDiscountTotal);
     }
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setPaymentCharge(0);
     $creditmemo->setBasePaymentCharge(0);
     $amount = $creditmemo->getOrder()->getPaymentCharge();
     $creditmemo->setPaymentCharge($amount);
     $amount = $creditmemo->getOrder()->getBasePaymentCharge();
     $creditmemo->setBasePaymentCharge($amount);
     $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $creditmemo->getPaymentCharge());
     $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $creditmemo->getBasePaymentCharge());
     return $this;
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $creditmemo->setWebposGiftwrapAmount(0);
     $orderGiftwrapAmount = $creditmemo->getOrder()->getWebposGiftwrapAmount();
     $baseOrderShippingAmount = $creditmemo->getOrder()->getWebposGiftwrapAmount();
     if ($orderGiftwrapAmount) {
         $creditmemo->setWebposGiftwrapAmount($orderGiftwrapAmount);
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $orderGiftwrapAmount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $orderGiftwrapAmount);
     }
     return $this;
 }
Example #30
0
File: Fee.php Project: mrphang/Fee
 /**
  * Collect credit memo total
  *
  * @param Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @return Magentix_Fee_Model_Sales_Order_Total_Creditmemo_Fee
  */
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     $order = $creditmemo->getOrder();
     if ($order->getFeeAmountInvoiced() > 0) {
         $feeAmountLeft = $order->getFeeAmountInvoiced() - $order->getFeeAmountRefunded();
         $basefeeAmountLeft = $order->getBaseFeeAmountInvoiced() - $order->getBaseFeeAmountRefunded();
         if ($basefeeAmountLeft > 0) {
             $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $feeAmountLeft);
             $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $basefeeAmountLeft);
             $creditmemo->setFeeAmount($feeAmountLeft);
             $creditmemo->setBaseFeeAmount($basefeeAmountLeft);
         }
     } else {
         $feeAmount = $order->getFeeAmountInvoiced();
         $basefeeAmount = $order->getBaseFeeAmountInvoiced();
         $creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $feeAmount);
         $creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $basefeeAmount);
         $creditmemo->setFeeAmount($feeAmount);
         $creditmemo->setBaseFeeAmount($basefeeAmount);
     }
     return $this;
 }