loadLayout() ->_setActiveMenu('sales/manage') ->_addBreadcrumb(('Custom Orders'), ('Custom Orders')) ->_addBreadcrumb(('Manage Custom Orders'), ('Manage Custom Orders')); return $this; } /** * Index action */ public function indexAction() { if(Mage::getStoreConfig('custominvoice_section/main_group/module_enable')!= '1'){ return $this->_forward('noRoute'); } $this->_title($this->__('Custom Orders')) ->_title($this->__('Manage Orders')); $this->_initAction(); $this->renderLayout(); } public function newAction() { $this->_forward('edit'); } public function editAction() { if(Mage::getStoreConfig('custominvoice_section/main_group/module_enable')!= '1'){ return $this->_forward('noRoute'); } $this->_title($this->__('Invoice')) ->_title($this->__('Manage Invoice')); $model = Mage::getModel('orange35_custominvoicesgenerator/order'); $invoiceId = $this->getRequest()->getParam('id'); if ($invoiceId) { $model->load($invoiceId); if (!$model->getId()) { $this->_getSession()->addError('Order does not exist.'); return $this->_redirect('*/*/'); } $breadCrumb = 'Edit Invoice'; } else { $this->_title('New Invoice'); $breadCrumb = 'New Invoice'; } $this->_initAction()->_addBreadcrumb($breadCrumb, $breadCrumb); $data = Mage::getSingleton('adminhtml/session')->getFormData(true); if (!empty($data)) { $model->addData($data); } Mage::register('order_item', $model); $this->renderLayout(); } public function saveAction() { if(Mage::getStoreConfig('custominvoice_section/main_group/module_enable')!= '1'){ return $this->_forward('noRoute'); } $redirectPath = '*/*'; $redirectParams = array(); $data = $this->getRequest()->getPost(); if ($data) { $data = $this->_filterPostData($data); $model = Mage::getModel('orange35_custominvoicesgenerator/order'); $invoiceId = $data['order_id']; if ($invoiceId) { $model->load($invoiceId); } $model->setData('description', $data['description']); $model->setData('amount', $data['amount']); try { $hasError = false; $model->save(); $this->_getSession()->addSuccess('Invoice been saved.'); if ($this->getRequest()->getParam('back')) { $redirectPath = '*/*/edit'; $redirectParams = array('id' => $model->getId()); } } catch (Mage_Core_Exception $e) { $hasError = true; $this->_getSession()->addError($e->getMessage()); } catch (Exception $e) { $hasError = true; $this->_getSession()->addException($e, 'An error occurred while saving the Invoice.'); } if ($hasError) { $this->_getSession()->setFormData($data); $redirectPath = '*/*/edit'; $redirectParams = array('id' => $this->getRequest()->getParam('id')); } } $this->_redirect($redirectPath, $redirectParams); } public function deleteAction(){ if(Mage::getStoreConfig('custominvoice_section/main_group/module_enable')!= '1'){ return $this->_forward('noRoute'); } $invoiceId = $this->getRequest()->getParam('id'); if ($invoiceId) { $model = Mage::getModel('orange35_custominvoicesgenerator/order'); $model->load($invoiceId); if (!$model->getId()) { $this->_getSession()->addError('Invoice does not exist.'); return $this->_redirect('*/*/'); } elseif($model->delete()) { $this->_getSession()->addSuccess('Invoice have been removed.'); return $this->_redirect('*/*/'); } } $this->_getSession()->addError('Invoice does not exist.'); return $this->_redirect('*/*/'); } protected function _filterPostData($data) { $data = $this->_filterDates($data, array('date')); return $data; } }