Ejemplo n.º 1
0
 public function invoiceView(Varien_Event_Observer $observer)
 {
     $block = $observer->getBlock();
     $invoice = $observer->getInvoice();
     if (strpos($invoice->getOrder()->getPayment()->getMethodInstance()->getCode(), 'saferpaycw') === 0) {
         $transaction = Mage::helper('SaferpayCw')->loadTransactionByOrder($invoice->getOrder()->getId());
         if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/edit') && $invoice->canCapture() && $transaction->getTransactionObject()->isCapturePossible() && $transaction->getTransactionObject()->isPartialCapturePossible()) {
             $block->addButton('edit', array('label' => Mage::helper('sales')->__('Edit'), 'class' => 'go', 'onclick' => 'setLocation(\'' . $block->getUrl('*/editsaferpaycw/index', array('invoice_id' => $invoice->getId())) . '\')'));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Add the invoice comments
  *
  * @param  Varien_Event_Observer $observer observer object
  *
  * @return FireGento_Pdf_Model_Observer
  */
 public function addInvoiceComments(Varien_Event_Observer $observer)
 {
     if (!Mage::getStoreConfigFlag('sales_pdf/invoice/show_comments')) {
         return $this;
     }
     /** @var Mage_Sales_Model_Order_Invoice $invoice */
     $invoice = $observer->getInvoice();
     /** @var Mage_Sales_Model_Resource_Order_Invoice_Comment_Collection $commentsCollection */
     $commentsCollection = $invoice->getCommentsCollection();
     $commentsCollection->addVisibleOnFrontFilter();
     $result = $observer->getResult();
     $notes = $result->getNotes();
     foreach ($commentsCollection as $comment) {
         /** @var $comment Mage_Sales_Model_Order_Invoice_Comment */
         $notes[] = $comment->getComment();
     }
     $result->setNotes($notes);
     return $this;
 }
 /**
  * @param Varien_Event_Observer $observer
  * @var Mage_Sales_Model_Order_Invoice $invoice
  */
 public function applySerialToOrderItem(Varien_Event_Observer $observer)
 {
     $invoice = $observer->getInvoice();
     $order = Mage::getModel('sales/order')->load($invoice->getOrderId());
     if (!($order->getVolumeLicense() != 0 && $order->getParentOrderId() == NULL)) {
         if ($invoice instanceof Mage_Sales_Model_Order_Invoice) {
             $downloadableHelper = Mage::helper('ecodes/downloadable');
             foreach ($invoice->getAllItems() as $invoiceItem) {
                 if (Mage::getModel('catalog/product')->load($invoiceItem->getProductId())->getSerialRequired()) {
                     $orderItem = Mage::getModel('sales/order_item')->load($invoiceItem->getOrderItemId());
                     $downloadableCollection = Mage::getModel('ecodes/downloadable')->getCollection();
                     $downloadableCollection->assignSerials($orderItem);
                     $serialsAdded = $downloadableCollection->getInfo('serials_added');
                     $numSerialsNotAssigned = $downloadableCollection->getInfo('num_serials_not_assigned');
                     $message = $downloadableHelper->generateSerialsAssignedHistoryComment($serialsAdded, $numSerialsNotAssigned, true);
                     if ($message) {
                         $this->getSession()->addSuccess($message);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function salesOrderPaymentCapture(Varien_Event_Observer $event)
 {
     /** @var $payment Mage_Sales_Model_Order_Payment */
     $payment = $event->getPayment();
     $invoice = $event->getInvoice();
     if ($payment->getMethodInstance() instanceof Netresearch_OPS_Model_Payment_Abstract) {
         $payment->setInvoice($invoice);
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Event fired when invoice is paid
  * @param Varien_Event_Observer $observer
  *
  * @return $this
  */
 public function convertToOrder(Varien_Event_Observer $observer)
 {
     /** @var $order Mage_Sales_Model_Order */
     $order = $observer->getInvoice()->getOrder();
     $statusOrder = $observer->getInvoice()->getOrder()->getStatus();
     $statusArr = explode(',', Mage::getStoreConfig(ITwebexperts_Payperrentals_Helper_Config::XML_PATH_RESERVED_STATUSES));
     if (!Mage::helper('payperrentals/config')->reserveInventoryNoInvoice() || Mage::helper('payperrentals/config')->reserveByStatus() && !in_array($statusOrder, $statusArr)) {
         $items = $observer->getInvoice()->getOrder()->getItemsCollection();
         ITwebexperts_Payperrentals_Helper_Data::reserveOrder($items, $order);
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * Catches magento event 'sales_order_invoice_save_before'
  *
  * @param Varien_Event_Observer $observer
  */
 public function sendConfirmInvoiceRequest(Varien_Event_Observer $observer)
 {
     $invoice = $observer->getInvoice();
     $paymentMethod = $invoice->getOrder()->getPayment()->getMethod();
     if ($this->getHelper()->isBillpayPayment($paymentMethod)) {
         // Is there a cleaner way to access the post data within a model?
         $data = Mage::app()->getRequest()->getPost('invoice');
         $delayInDays = 0;
         if (is_array($data) && array_key_exists('billpay_delay', $data)) {
             $delayInDays = $data['billpay_delay'];
         }
         $result = $this->getHelper()->sendConfirmInvoiceRequest($invoice, $paymentMethod, $delayInDays, true);
         $order = $invoice->getOrder();
         // Store bank account in database
         $this->setBankAccountData($order, $result);
         if ($this->getHelper()->isBillpayRatPayment($paymentMethod)) {
             $info = $order->getPayment()->getMethodInstance()->getInfoInstance();
             // Store due dates in database for hire purchase
             if (is_array($result['dues']) && count($result['dues']) > 0) {
                 $serializedDuesWithDates = $this->getCalculation()->getSerializedDues($result['dues']);
                 $info->setBillpayRateDues($serializedDuesWithDates);
             } else {
                 $this->getLog()->logError("No due dates found for hire purchase order after invoiceCreated request");
             }
         }
         // Send copy of invoice mail to billpay
         if ($this->getHelper()->getConfigData('settings/send_invoice_mail_copy', $invoice->getStoreId())) {
             try {
                 $this->sendInvoiceCopy($invoice);
                 $this->getLog()->logDebug('Successfully sent copy of invoice mail to billpay');
             } catch (Exception $e) {
                 $this->getLog()->logError('Error sending copy of invoice mail to billpay');
                 $this->getLog()->logException($e);
             }
         }
         // Add comment to status history
         $comment = $this->getHelper()->__('billpay_activated_successully');
         if ($delayInDays > 0) {
             $comment .= ' (+' . $delayInDays . ' ' . $this->getHelper()->__('billpay_activated_days') . ')';
         }
         $order->addStatusToHistory($order->getStatus(), $comment, false);
         $invoice->addComment($comment, false);
     }
 }