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