Example #1
0
 /**
  * Set entity
  *
  * @param Mage_Sales_Model_Order_Invoice|Mage_Sales_Model_Order_Creditmemo $object
  * @return $this
  */
 public function setEntity($object)
 {
     $this->setEntityId($object->getId());
     $this->setEntityIncrementId($object->getIncrementId());
     $this->setStoreId($object->getStoreId());
     return $this;
 }
Example #2
0
 /**
  * Check is processed refund
  * 
  * @param \Mage_Sales_Model_Order_Creditmemo $creditmemo
  * @param string $itemId
  * @return boolean
  */
 public function isProcessedRefund($creditmemo, $itemId)
 {
     $whRefund = Mage::getModel('inventoryplus/warehouse_refund')->loadByCreditmemoId($creditmemo->getId())->addFieldToFilter('item_id', $itemId)->getFirstItem();
     if ($whRefund->getId()) {
         return true;
     }
     return false;
 }
Example #3
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;
 }