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: 33:
34: class Mage_Adminhtml_Block_Sales_Order_Creditmemo_View extends Mage_Adminhtml_Block_Widget_Form_Container
35: {
36:
37: 38: 39: 40:
41: public function __construct()
42: {
43: $this->_objectId = 'creditmemo_id';
44: $this->_controller = 'sales_order_creditmemo';
45: $this->_mode = 'view';
46:
47: parent::__construct();
48:
49: $this->_removeButton('save');
50: $this->_removeButton('reset');
51: $this->_removeButton('delete');
52:
53: if ($this->getCreditmemo()->canCancel()) {
54: $this->_addButton('cancel', array(
55: 'label' => Mage::helper('sales')->__('Cancel'),
56: 'class' => 'delete',
57: 'onclick' => 'setLocation(\''.$this->getCancelUrl().'\')'
58: )
59: );
60: }
61:
62: if ($this->_isAllowedAction('emails')) {
63: $this->addButton('send_notification', array(
64: 'label' => Mage::helper('sales')->__('Send Email'),
65: 'onclick' => 'confirmSetLocation(\''
66: . Mage::helper('sales')->__('Are you sure you want to send Creditmemo email to customer?')
67: . '\', \'' . $this->getEmailUrl() . '\')'
68: ));
69: }
70:
71: if ($this->getCreditmemo()->canRefund()) {
72: $this->_addButton('refund', array(
73: 'label' => Mage::helper('sales')->__('Refund'),
74: 'class' => 'save',
75: 'onclick' => 'setLocation(\''.$this->getRefundUrl().'\')'
76: )
77: );
78: }
79:
80: if ($this->getCreditmemo()->canVoid()) {
81: $this->_addButton('void', array(
82: 'label' => Mage::helper('sales')->__('Void'),
83: 'class' => 'save',
84: 'onclick' => 'setLocation(\''.$this->getVoidUrl().'\')'
85: )
86: );
87: }
88:
89: if ($this->getCreditmemo()->getId()) {
90: $this->_addButton('print', array(
91: 'label' => Mage::helper('sales')->__('Print'),
92: 'class' => 'save',
93: 'onclick' => 'setLocation(\''.$this->getPrintUrl().'\')'
94: )
95: );
96: }
97: }
98:
99: 100: 101: 102: 103:
104: public function getCreditmemo()
105: {
106: return Mage::registry('current_creditmemo');
107: }
108:
109: 110: 111: 112: 113:
114: public function ()
115: {
116: if ($this->getCreditmemo()->getEmailSent()) {
117: $emailSent = Mage::helper('sales')->__('the credit memo email was sent');
118: }
119: else {
120: $emailSent = Mage::helper('sales')->__('the credit memo email is not sent');
121: }
122: return Mage::helper('sales')->__('Credit Memo #%1$s | %3$s | %2$s (%4$s)', $this->getCreditmemo()->getIncrementId(), $this->formatDate($this->getCreditmemo()->getCreatedAtDate(), 'medium', true), $this->getCreditmemo()->getStateName(), $emailSent);
123: }
124:
125: 126: 127: 128: 129:
130: public function getBackUrl()
131: {
132: return $this->getUrl(
133: '*/sales_order/view',
134: array(
135: 'order_id' => $this->getCreditmemo()->getOrderId(),
136: 'active_tab'=> 'order_creditmemos'
137: ));
138: }
139:
140: 141: 142: 143: 144:
145: public function getCaptureUrl()
146: {
147: return $this->getUrl('*/*/capture', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
148: }
149:
150: 151: 152: 153: 154:
155: public function getVoidUrl()
156: {
157: return $this->getUrl('*/*/void', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
158: }
159:
160: 161: 162: 163: 164:
165: public function getCancelUrl()
166: {
167: return $this->getUrl('*/*/cancel', array('creditmemo_id'=>$this->getCreditmemo()->getId()));
168: }
169:
170: 171: 172: 173: 174:
175: public function getEmailUrl()
176: {
177: return $this->getUrl('*/*/email', array(
178: 'creditmemo_id' => $this->getCreditmemo()->getId(),
179: 'order_id' => $this->getCreditmemo()->getOrderId()
180: ));
181: }
182:
183: 184: 185: 186: 187:
188: public function getPrintUrl()
189: {
190: return $this->getUrl('*/*/print', array(
191: 'creditmemo_id' => $this->getCreditmemo()->getId()
192: ));
193: }
194:
195: 196: 197: 198: 199:
200: public function updateBackButtonUrl($flag)
201: {
202: if ($flag) {
203: if ($this->getCreditmemo()->getBackUrl()) {
204: return $this->_updateButton(
205: 'back',
206: 'onclick',
207: 'setLocation(\'' . $this->getCreditmemo()->getBackUrl() . '\')'
208: );
209: }
210:
211: return $this->_updateButton(
212: 'back',
213: 'onclick',
214: 'setLocation(\'' . $this->getUrl('*/sales_creditmemo/') . '\')'
215: );
216: }
217: return $this;
218: }
219:
220: 221: 222: 223: 224: 225:
226: public function _isAllowedAction($action)
227: {
228: return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/' . $action);
229: }
230: }
231: