1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31:
32: class Mage_Adminhtml_Controller_Sales_Invoice extends Mage_Adminhtml_Controller_Action
33: {
34: 35: 36: 37:
38: protected function _construct()
39: {
40: $this->setUsedModuleName('Mage_Sales');
41: }
42:
43: 44: 45: 46: 47:
48: protected function _initAction()
49: {
50: $this->loadLayout()
51: ->_setActiveMenu('sales/order')
52: ->_addBreadcrumb($this->__('Sales'), $this->__('Sales'))
53: ->_addBreadcrumb($this->__('Invoices'),$this->__('Invoices'));
54: return $this;
55: }
56:
57: 58: 59:
60: public function gridAction()
61: {
62: $this->loadLayout();
63: $this->getResponse()->setBody(
64: $this->getLayout()->createBlock('adminhtml/sales_invoice_grid')->toHtml()
65: );
66: }
67:
68: 69: 70:
71: public function indexAction()
72: {
73: $this->_title($this->__('Sales'))->_title($this->__('Invoices'));
74:
75: $this->_initAction()
76: ->_addContent($this->getLayout()->createBlock('adminhtml/sales_invoice'))
77: ->renderLayout();
78: }
79:
80: 81: 82:
83: public function viewAction()
84: {
85: if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
86: $this->_forward('view', 'sales_order_invoice', null, array('come_from'=>'invoice'));
87: } else {
88: $this->_forward('noRoute');
89: }
90: }
91:
92: 93: 94:
95: public function emailAction()
96: {
97: if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
98: if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
99: $invoice->sendEmail();
100: $historyItem = Mage::getResourceModel('sales/order_status_history_collection')
101: ->getUnnotifiedForInstance($invoice, Mage_Sales_Model_Order_Invoice::HISTORY_ENTITY_NAME);
102: if ($historyItem) {
103: $historyItem->setIsCustomerNotified(1);
104: $historyItem->save();
105: }
106: $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message has been sent.'));
107: $this->_redirect('*/sales_invoice/view', array(
108: 'order_id' => $invoice->getOrder()->getId(),
109: 'invoice_id'=> $invoiceId,
110: ));
111: }
112: }
113: }
114:
115: public function printAction()
116: {
117: if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
118: if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
119: $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
120: $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
121: '.pdf', $pdf->render(), 'application/pdf');
122: }
123: }
124: else {
125: $this->_forward('noRoute');
126: }
127: }
128:
129: public function pdfinvoicesAction(){
130: $invoicesIds = $this->getRequest()->getPost('invoice_ids');
131: if (!empty($invoicesIds)) {
132: $invoices = Mage::getResourceModel('sales/order_invoice_collection')
133: ->addAttributeToSelect('*')
134: ->addAttributeToFilter('entity_id', array('in' => $invoicesIds))
135: ->load();
136: if (!isset($pdf)){
137: $pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
138: } else {
139: $pages = Mage::getModel('sales/order_pdf_invoice')->getPdf($invoices);
140: $pdf->pages = array_merge ($pdf->pages, $pages->pages);
141: }
142:
143: return $this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
144: '.pdf', $pdf->render(), 'application/pdf');
145: }
146: $this->_redirect('*/*/');
147: }
148:
149: protected function _isAllowed()
150: {
151: return Mage::getSingleton('admin/session')->isAllowed('sales/invoice');
152: }
153:
154: }
155: