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:
35: class Mage_Adminhtml_Block_Sales_Order_Invoice_Create_Items extends Mage_Adminhtml_Block_Sales_Items_Abstract
36: {
37: protected $_disableSubmitButton = false;
38:
39: 40: 41: 42: 43:
44: protected function _beforeToHtml()
45: {
46: $onclick = "submitAndReloadArea($('invoice_item_container'),'".$this->getUpdateUrl()."')";
47: $this->setChild(
48: 'update_button',
49: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
50: 'class' => 'update-button',
51: 'label' => Mage::helper('sales')->__('Update Qty\'s'),
52: 'onclick' => $onclick,
53: ))
54: );
55: $this->_disableSubmitButton = true;
56: $_submitButtonClass = ' disabled';
57: foreach ($this->getInvoice()->getAllItems() as $item) {
58: 59: 60:
61: if ($item->getQty()) {
62: $this->_disableSubmitButton = false;
63: $_submitButtonClass = '';
64: break;
65: }
66: }
67: if ($this->getOrder()->getForcedDoShipmentWithInvoice()) {
68: $_submitLabel = Mage::helper('sales')->__('Submit Invoice and Shipment');
69: } else {
70: $_submitLabel = Mage::helper('sales')->__('Submit Invoice');
71: }
72: $this->setChild(
73: 'submit_button',
74: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
75: 'label' => $_submitLabel,
76: 'class' => 'save submit-button' . $_submitButtonClass,
77: 'onclick' => 'disableElements(\'submit-button\');$(\'edit_form\').submit()',
78: 'disabled' => $this->_disableSubmitButton
79: ))
80: );
81:
82: return parent::_prepareLayout();
83: }
84:
85: 86: 87: 88: 89:
90: public function getDisableSubmitButton()
91: {
92: return $this->_disableSubmitButton;
93: }
94:
95: 96: 97: 98: 99:
100: public function getOrder()
101: {
102: return $this->getInvoice()->getOrder();
103: }
104:
105: 106: 107: 108: 109:
110: public function getSource()
111: {
112: return $this->getInvoice();
113: }
114:
115: 116: 117: 118: 119:
120: public function getInvoice()
121: {
122: return Mage::registry('current_invoice');
123: }
124:
125: 126: 127: 128: 129:
130: public function getOrderTotalData()
131: {
132: return array();
133: }
134:
135: 136: 137: 138: 139:
140: public function getOrderTotalbarData()
141: {
142: $totalbarData = array();
143: $this->setPriceDataObject($this->getInvoice()->getOrder());
144: $totalbarData[] = array(Mage::helper('sales')->__('Paid Amount'), $this->displayPriceAttribute('amount_paid'), false);
145: $totalbarData[] = array(Mage::helper('sales')->__('Refund Amount'), $this->displayPriceAttribute('amount_refunded'), false);
146: $totalbarData[] = array(Mage::helper('sales')->__('Shipping Amount'), $this->displayPriceAttribute('shipping_captured'), false);
147: $totalbarData[] = array(Mage::helper('sales')->__('Shipping Refund'), $this->displayPriceAttribute('shipping_refunded'), false);
148: $totalbarData[] = array(Mage::helper('sales')->__('Order Grand Total'), $this->displayPriceAttribute('grand_total'), true);
149:
150: return $totalbarData;
151: }
152:
153: public function formatPrice($price)
154: {
155: return $this->getInvoice()->getOrder()->formatPrice($price);
156: }
157:
158: public function getUpdateButtonHtml()
159: {
160: return $this->getChildHtml('update_button');
161: }
162:
163: public function getUpdateUrl()
164: {
165: return $this->getUrl('*/*/updateQty', array('order_id'=>$this->getInvoice()->getOrderId()));
166: }
167:
168: 169: 170: 171: 172:
173: public function canCreateShipment()
174: {
175: foreach ($this->getInvoice()->getAllItems() as $item) {
176: if ($item->getOrderItem()->getQtyToShip()) {
177: return true;
178: }
179: }
180: return false;
181: }
182:
183: public function canEditQty()
184: {
185: if ($this->getInvoice()->getOrder()->getPayment()->canCapture()) {
186: return $this->getInvoice()->getOrder()->getPayment()->canCapturePartial();
187: }
188: return true;
189: }
190:
191: 192: 193: 194:
195: public function isCaptureAllowed()
196: {
197: return Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/capture');
198: }
199:
200: 201: 202: 203:
204: public function canCapture()
205: {
206: return $this->getInvoice()->canCapture();
207: }
208:
209: 210: 211: 212:
213: public function isGatewayUsed()
214: {
215: return $this->getInvoice()->getOrder()->getPayment()->getMethodInstance()->isGateway();
216: }
217:
218: public function canSendInvoiceEmail()
219: {
220: return Mage::helper('sales')->canSendNewInvoiceEmail($this->getOrder()->getStore()->getId());
221: }
222: }
223: