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_Creditmemo_Create_Items extends Mage_Adminhtml_Block_Sales_Items_Abstract
36: {
37: protected $_canReturnToStock;
38: 39: 40: 41: 42:
43: protected function _prepareLayout()
44: {
45: $onclick = "submitAndReloadArea($('creditmemo_item_container'),'".$this->getUpdateUrl()."')";
46: $this->setChild(
47: 'update_button',
48: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
49: 'label' => Mage::helper('sales')->__('Update Qty\'s'),
50: 'class' => 'update-button',
51: 'onclick' => $onclick,
52: ))
53: );
54:
55: if ($this->getCreditmemo()->canRefund()) {
56: if ($this->getCreditmemo()->getInvoice() && $this->getCreditmemo()->getInvoice()->getTransactionId()) {
57: $this->setChild(
58: 'submit_button',
59: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
60: 'label' => Mage::helper('sales')->__('Refund'),
61: 'class' => 'save submit-button',
62: 'onclick' => 'disableElements(\'submit-button\');submitCreditMemo()',
63: ))
64: );
65: }
66: $this->setChild(
67: 'submit_offline',
68: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
69: 'label' => Mage::helper('sales')->__('Refund Offline'),
70: 'class' => 'save submit-button',
71: 'onclick' => 'disableElements(\'submit-button\');submitCreditMemoOffline()',
72: ))
73: );
74:
75: }
76: else {
77: $this->setChild(
78: 'submit_button',
79: $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
80: 'label' => Mage::helper('sales')->__('Refund Offline'),
81: 'class' => 'save submit-button',
82: 'onclick' => 'disableElements(\'submit-button\');submitCreditMemoOffline()',
83: ))
84: );
85: }
86:
87: return parent::_prepareLayout();
88: }
89:
90: 91: 92: 93: 94:
95: public function getOrder()
96: {
97: return $this->getCreditmemo()->getOrder();
98: }
99:
100: 101: 102: 103: 104:
105: public function getSource()
106: {
107: return $this->getCreditmemo();
108: }
109:
110: 111: 112: 113: 114:
115: public function getOrderTotalData()
116: {
117: return array();
118: }
119:
120: 121: 122: 123: 124:
125: public function getOrderTotalbarData()
126: {
127: $totalbarData = array();
128: $this->setPriceDataObject($this->getOrder());
129: $totalbarData[] = array(Mage::helper('sales')->__('Paid Amount'), $this->displayPriceAttribute('total_invoiced'), false);
130: $totalbarData[] = array(Mage::helper('sales')->__('Refund Amount'), $this->displayPriceAttribute('total_refunded'), false);
131: $totalbarData[] = array(Mage::helper('sales')->__('Shipping Amount'), $this->displayPriceAttribute('shipping_invoiced'), false);
132: $totalbarData[] = array(Mage::helper('sales')->__('Shipping Refund'), $this->displayPriceAttribute('shipping_refunded'), false);
133: $totalbarData[] = array(Mage::helper('sales')->__('Order Grand Total'), $this->displayPriceAttribute('grand_total'), true);
134:
135: return $totalbarData;
136: }
137:
138: 139: 140: 141: 142:
143: public function getCreditmemo()
144: {
145: return Mage::registry('current_creditmemo');
146: }
147:
148: public function canEditQty()
149: {
150: if ($this->getCreditmemo()->getOrder()->getPayment()->canRefund()) {
151: return $this->getCreditmemo()->getOrder()->getPayment()->canRefundPartialPerInvoice();
152: }
153: return true;
154: }
155:
156: public function getUpdateButtonHtml()
157: {
158: return $this->getChildHtml('update_button');
159: }
160:
161: public function getUpdateUrl()
162: {
163: return $this->getUrl('*/*/updateQty', array(
164: 'order_id'=>$this->getCreditmemo()->getOrderId(),
165: 'invoice_id'=>$this->getRequest()->getParam('invoice_id', null),
166: ));
167: }
168:
169: public function canReturnToStock()
170: {
171: $canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT);
172: if (Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT)) {
173: return true;
174: } else {
175: return false;
176: }
177: }
178:
179: 180: 181: 182:
183: public function canReturnItemsToStock()
184: {
185: if (is_null($this->_canReturnToStock)) {
186: if ($this->_canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT)) {
187: $canReturnToStock = false;
188: foreach ($this->getCreditmemo()->getAllItems() as $item) {
189: $product = Mage::getModel('catalog/product')->load($item->getOrderItem()->getProductId());
190: if ( $product->getId() && $product->getStockItem()->getManageStock() ) {
191: $item->setCanReturnToStock($canReturnToStock = true);
192: } else {
193: $item->setCanReturnToStock(false);
194: }
195: }
196: $this->getCreditmemo()->getOrder()->setCanReturnToStock($this->_canReturnToStock = $canReturnToStock);
197: }
198: }
199: return $this->_canReturnToStock;
200: }
201:
202: public function canSendCreditmemoEmail()
203: {
204: return Mage::helper('sales')->canSendNewCreditmemoEmail($this->getOrder()->getStore()->getId());
205: }
206: }
207: