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_Creditmemo 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->__('Credit Memos'),$this->__('Credit Memos'));
54: return $this;
55: }
56:
57: 58: 59:
60: public function indexAction()
61: {
62: $this->_initAction()
63: ->_addContent($this->getLayout()->createBlock('adminhtml/sales_creditmemo'))
64: ->renderLayout();
65: }
66:
67: 68: 69:
70: public function viewAction()
71: {
72: if ($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) {
73: $this->_forward('view', 'sales_order_creditmemo', null, array('come_from' => 'sales_creditmemo'));
74: } else {
75: $this->_forward('noRoute');
76: }
77: }
78:
79: 80: 81:
82: public function emailAction()
83: {
84: if ($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) {
85: if ($creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId)) {
86: $creditmemo->sendEmail();
87: $historyItem = Mage::getResourceModel('sales/order_status_history_collection')
88: ->getUnnotifiedForInstance($creditmemo, Mage_Sales_Model_Order_Creditmemo::HISTORY_ENTITY_NAME);
89: if ($historyItem) {
90: $historyItem->setIsCustomerNotified(1);
91: $historyItem->save();
92: }
93:
94: $this->_getSession()->addSuccess(Mage::helper('sales')->__('The message was sent.'));
95: $this->_redirect('*/sales_order_creditmemo/view', array(
96: 'creditmemo_id' => $creditmemoId
97: ));
98: }
99: }
100: }
101:
102: public function pdfcreditmemosAction(){
103: $creditmemosIds = $this->getRequest()->getPost('creditmemo_ids');
104: if (!empty($creditmemosIds)) {
105: $invoices = Mage::getResourceModel('sales/order_creditmemo_collection')
106: ->addAttributeToSelect('*')
107: ->addAttributeToFilter('entity_id', array('in' => $creditmemosIds))
108: ->load();
109: if (!isset($pdf)){
110: $pdf = Mage::getModel('sales/order_pdf_creditmemo')->getPdf($invoices);
111: } else {
112: $pages = Mage::getModel('sales/order_pdf_creditmemo')->getPdf($invoices);
113: $pdf->pages = array_merge ($pdf->pages, $pages->pages);
114: }
115:
116: return $this->_prepareDownloadResponse('creditmemo'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
117: '.pdf', $pdf->render(), 'application/pdf');
118: }
119: $this->_redirect('*/*/');
120: }
121:
122: public function printAction()
123: {
124:
125: if ($creditmemoId = $this->getRequest()->getParam('creditmemo_id')) {
126: if ($creditmemo = Mage::getModel('sales/order_creditmemo')->load($creditmemoId)) {
127: $pdf = Mage::getModel('sales/order_pdf_creditmemo')->getPdf(array($creditmemo));
128: $this->_prepareDownloadResponse('creditmemo'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
129: '.pdf', $pdf->render(), 'application/pdf');
130: }
131: }
132: else {
133: $this->_forward('noRoute');
134: }
135: }
136:
137: protected function _isAllowed()
138: {
139: return Mage::getSingleton('admin/session')->isAllowed('sales/creditmemo');
140: }
141: }
142: