Beispiel #1
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;
 }
Beispiel #2
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;
 }
Beispiel #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;
 }
 public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
 {
     // Changed By Adam 22/09/2014
     if (!Mage::helper('affiliateplus')->isAffiliateModuleEnabled()) {
         return $this;
     }
     $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->getBaseSubtotalInclTax();
     // - $baseOrderDiscount;
     $baseDiscount = $baseOrderDiscount * $creditmemo->getBaseSubtotalInclTax() / $baseOrderTotal;
     $discount = $orderDiscount * $creditmemo->getBaseSubtotalInclTax() / $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;
 }
Beispiel #6
0
 protected function _attachTotals(Mage_Sales_Model_Order_Creditmemo $creditMemo, $mode)
 {
     $total = $creditMemo->getGrandTotal();
     $baseTotal = $creditMemo->getBaseGrandTotal();
     $order = $creditMemo->getOrder();
     $order->setForcedCanCreditmemo(false);
     if ($mode == AW_Giftcard_Model_Source_Giftcard_Config_Refund::ALLOW_AFTER_REAL_MONEY_VALUE || $mode == AW_Giftcard_Model_Source_Giftcard_Config_Refund::NOT_ALLOW_VALUE) {
         $_needBaseMoneyToRefund = abs($order->getBaseTotalPaid() - $order->getBaseTotalRefunded());
         $_needMoneyToRefund = abs($order->getTotalPaid() - $order->getTotalRefunded());
         $total = $creditMemo->getGrandTotal() - $_needMoneyToRefund;
         $baseTotal = $creditMemo->getBaseGrandTotal() - $_needBaseMoneyToRefund;
     }
     if ($total <= 0 || $baseTotal <= 0) {
         return $this;
     }
     $baseTotalGiftcardAmount = 0;
     $totalGiftcardAmount = 0;
     $creditmemoGiftCards = array();
     if (null === $creditMemo->getId()) {
         $invoiceGiftCards = Mage::helper('aw_giftcard/totals')->getInvoicedGiftCardsByOrderId($creditMemo->getOrder()->getId());
         foreach ($invoiceGiftCards as $invoiceCard) {
             $_baseGiftcardAmount = $invoiceCard->getBaseGiftcardAmount();
             $_giftcardAmount = $invoiceCard->getGiftcardAmount();
             $creditmemoItems = Mage::helper('aw_giftcard/totals')->getAllCreditmemoForGiftCard($creditMemo->getOrder()->getId(), $invoiceCard->getGiftcardId());
             if (count($creditmemoItems) > 0) {
                 foreach ($creditmemoItems as $creditmemoGiftcard) {
                     $_baseGiftcardAmount -= $creditmemoGiftcard->getBaseGiftcardAmount();
                     $_giftcardAmount -= $creditmemoGiftcard->getGiftcardAmount();
                 }
             }
             $baseCardUsedAmount = $_baseGiftcardAmount;
             if ($_baseGiftcardAmount >= $baseTotal) {
                 $baseCardUsedAmount = $baseTotal;
             }
             $baseTotal -= $baseCardUsedAmount;
             $cardUsedAmount = $_giftcardAmount;
             if ($_giftcardAmount >= $total) {
                 $cardUsedAmount = $total;
             }
             $total -= $cardUsedAmount;
             $_baseGiftcardAmount = round($baseCardUsedAmount, 4);
             $_giftcardAmount = round($cardUsedAmount, 4);
             $baseTotalGiftcardAmount += $_baseGiftcardAmount;
             $totalGiftcardAmount += $_giftcardAmount;
             $_creditmemoCard = new Varien_Object($invoiceCard->getData());
             $_creditmemoCard->setBaseGiftcardAmount($_baseGiftcardAmount)->setGiftcardAmount($_giftcardAmount);
             array_push($creditmemoGiftCards, $_creditmemoCard);
         }
     }
     if (null !== $creditMemo->getId() && $creditMemo->getAwGiftCards()) {
         $creditmemoGiftCards = $creditMemo->getAwGiftCards();
         foreach ($creditmemoGiftCards as $creditmemoCard) {
             $baseTotalGiftcardAmount += $creditmemoCard->getBaseGiftcardAmount();
             $totalGiftcardAmount += $creditmemoCard->getGiftcardAmount();
         }
     }
     if (count($creditmemoGiftCards) > 0) {
         $creditMemo->setAllowZeroGrandTotal(true);
     }
     $creditMemo->setAwGiftCards($creditmemoGiftCards)->setBaseAwGiftCardsAmount($baseTotalGiftcardAmount)->setAwGiftCardsAmount($totalGiftcardAmount)->setBaseGrandTotal($creditMemo->getBaseGrandTotal() - $baseTotalGiftcardAmount)->setGrandTotal($creditMemo->getGrandTotal() - $totalGiftcardAmount);
     return $this;
 }