00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Adminhtml_Block_Sales_Items_Abstract extends Mage_Adminhtml_Block_Template
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045 protected $_itemRenders = array();
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 protected $_columnRenders = array();
00056
00057
00058
00059
00060
00061 protected function _construct()
00062 {
00063 $this->addColumnRender('qty', 'adminhtml/sales_items_column_qty', 'sales/items/column/qty.phtml');
00064 $this->addColumnRender('name', 'adminhtml/sales_items_column_name', 'sales/items/column/name.phtml');
00065 parent::_construct();
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 public function addItemRender($type, $block, $template)
00077 {
00078 $this->_itemRenders[$type] = array(
00079 'block' => $block,
00080 'template' => $template,
00081 'renderer' => null
00082 );
00083 return $this;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 public function addColumnRender($column, $block, $template, $type=null)
00095 {
00096 if (!is_null($type)) {
00097 $column .= '_' . $type;
00098 }
00099 $this->_columnRenders[$column] = array(
00100 'block' => $block,
00101 'template' => $template,
00102 'renderer' => null
00103 );
00104 return $this;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113 public function getItemRenderer($type)
00114 {
00115 if (!isset($this->_itemRenders[$type])) {
00116 $type = 'default';
00117 }
00118 if (is_null($this->_itemRenders[$type]['renderer'])) {
00119 $this->_itemRenders[$type]['renderer'] = $this->getLayout()
00120 ->createBlock($this->_itemRenders[$type]['block'])
00121 ->setTemplate($this->_itemRenders[$type]['template']);
00122 foreach ($this->_columnRenders as $columnType=>$renderer) {
00123 $this->_itemRenders[$type]['renderer']->addColumnRender($columnType, $renderer['block'], $renderer['template']);
00124 }
00125 }
00126 return $this->_itemRenders[$type]['renderer'];
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136 public function getColumnRenderer($column, $compositePart='')
00137 {
00138 if (isset($this->_columnRenders[$column . '_' . $compositePart])) {
00139 $column .= '_' . $compositePart;
00140 }
00141 if (!isset($this->_columnRenders[$column])) {
00142 return false;
00143 }
00144 if (is_null($this->_columnRenders[$column]['renderer'])) {
00145 $this->_columnRenders[$column]['renderer'] = $this->getLayout()
00146 ->createBlock($this->_columnRenders[$column]['block'])
00147 ->setTemplate($this->_columnRenders[$column]['template'])
00148 ->setRenderedBlock($this);
00149 }
00150 return $this->_columnRenders[$column]['renderer'];
00151 }
00152
00153
00154
00155
00156
00157
00158
00159 public function getItemHtml(Varien_Object $item)
00160 {
00161 if ($item->getOrderItem()) {
00162 $type = $item->getOrderItem()->getProductType();
00163 } else {
00164 $type = $item->getProductType();
00165 }
00166
00167 return $this->getItemRenderer($type)
00168 ->setItem($item)
00169 ->toHtml();
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 public function getColumnHtml(Varien_Object $item, $column, $field = null)
00181 {
00182 if ($item->getOrderItem()) {
00183 $block = $this->getColumnRenderer($column, $item->getOrderItem()->getProductType());
00184 } else {
00185 $block = $this->getColumnRenderer($column, $item->getProductType());
00186 }
00187
00188 if ($block) {
00189 $block->setItem($item);
00190 if (!is_null($field)) {
00191 $block->setField($field);
00192 }
00193 return $block->toHtml();
00194 }
00195 return ' ';
00196 }
00197
00198 public function getCreditmemo()
00199 {
00200 return Mage::registry('current_creditmemo');
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212 public function getOrder()
00213 {
00214 if ($this->hasOrder()) {
00215 return $this->getData('order');
00216 }
00217 if (Mage::registry('current_order')) {
00218 return Mage::registry('current_order');
00219 }
00220 if (Mage::registry('order')) {
00221 return Mage::registry('order');
00222 }
00223 if ($this->getInvoice())
00224 {
00225 return $this->getInvoice()->getOrder();
00226 }
00227 if ($this->getCreditmemo())
00228 {
00229 return $this->getCreditmemo()->getOrder();
00230 }
00231 if ($this->getItem()->getOrder())
00232 {
00233 return $this->getItem()->getOrder();
00234 }
00235
00236 Mage::throwException(Mage::helper('sales')->__('Can\'t get order instance'));
00237 }
00238
00239
00240
00241
00242
00243
00244 public function getPriceDataObject()
00245 {
00246 $obj = $this->getData('price_data_object');
00247 if (is_null($obj)) {
00248 return $this->getOrder();
00249 }
00250 return $obj;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 public function displayPriceAttribute($code, $strong = false, $separator = '<br />')
00262 {
00263 return $this->displayPrices(
00264 $this->getPriceDataObject()->getData('base_'.$code),
00265 $this->getPriceDataObject()->getData($code),
00266 $strong,
00267 $separator
00268 );
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 public function displayPrices($basePrice, $price, $strong = false, $separator = '<br />')
00281 {
00282 if ($this->getOrder()->isCurrencyDifferent()) {
00283 $res = '';
00284 $res.= $this->getOrder()->formatBasePrice($basePrice);
00285 $res.= $separator;
00286 $res.= $this->getOrder()->formatPrice($price, true);
00287 }
00288 else {
00289 $res = $this->getOrder()->formatPrice($price);
00290 if ($strong) {
00291 $res = '<strong>'.$res.'</strong>';
00292 }
00293 }
00294 return $res;
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 public function displayPriceInclTax(Varien_Object $item)
00304 {
00305 $qty = ($item->getQtyOrdered() ? $item->getQtyOrdered() : ($item->getQty() ? $item->getQty() : 1));
00306 $baseTax = ($item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0));
00307 $tax = ($item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0));
00308
00309 return $this->displayPrices(
00310 $this->getOrder()->getStore()->roundPrice($item->getBasePrice()+$baseTax/$qty),
00311 $this->getOrder()->getStore()->roundPrice($item->getPrice()+$tax/$qty)
00312 );
00313 }
00314
00315
00316
00317
00318
00319
00320
00321 public function displaySubtotalInclTax($item)
00322 {
00323 $baseTax = ($item->getTaxBeforeDiscount() ? $item->getTaxBeforeDiscount() : ($item->getTaxAmount() ? $item->getTaxAmount() : 0));
00324 $tax = ($item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : ($item->getBaseTaxAmount() ? $item->getBaseTaxAmount() : 0));
00325
00326 return $this->displayPrices(
00327 $item->getBaseRowTotal()+$baseTax,
00328 $item->getRowTotal()+$tax
00329 );
00330 }
00331
00332
00333
00334
00335
00336
00337
00338 public function displayTaxCalculation(Varien_Object $item)
00339 {
00340 if ($item->getTaxPercent() && $item->getTaxString() == '') {
00341 $percents = array($item->getTaxPercent());
00342 } else if ($item->getTaxString()) {
00343 $percents = explode(Mage_Tax_Model_Config::CALCULATION_STRING_SEPARATOR, $item->getTaxString());
00344 } else {
00345 return '0%';
00346 }
00347
00348 foreach ($percents as &$percent) {
00349 $percent = sprintf('%.2f%%', $percent);
00350 }
00351 return implode(' + ', $percents);
00352 }
00353
00354
00355
00356
00357
00358
00359
00360 public function displayTaxPercent(Varien_Object $item)
00361 {
00362 if ($item->getTaxPercent()) {
00363 return sprintf('%s%%', $item->getTaxPercent() + 0);
00364 } else {
00365 return '0%';
00366 }
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 public function canCreateShipment()
00379 {
00380 foreach ($this->getInvoice()->getAllItems() as $item) {
00381 if ($item->getOrderItem()->getQtyToShip()) {
00382 return true;
00383 }
00384 }
00385 return false;
00386 }
00387
00388
00389
00390
00391
00392
00393 public function canEditQty()
00394 {
00395
00396
00397
00398
00399 if ($this->getOrder()->getForcedDoShipmentWithInvoice()
00400 && ($this->canShipPartially($this->getOrder()) || $this->canShipPartiallyItem($this->getOrder()))
00401 ) {
00402 return false;
00403 }
00404 if ($this->getOrder()->getPayment()->canCapture()) {
00405 return $this->getOrder()->getPayment()->canCapturePartial();
00406 }
00407 return true;
00408 }
00409
00410 public function canCapture()
00411 {
00412 if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/capture')) {
00413 return $this->getInvoice()->canCapture();
00414 }
00415 return false;
00416 }
00417
00418 public function formatPrice($price)
00419 {
00420 return $this->getOrder()->formatPrice($price);
00421 }
00422
00423
00424
00425
00426
00427
00428 public function getSource()
00429 {
00430 return $this->getInvoice();
00431 }
00432
00433
00434
00435
00436
00437
00438 public function getInvoice()
00439 {
00440 return Mage::registry('current_invoice');
00441 }
00442
00443
00444
00445
00446
00447 public function canReturnToStock() {
00448 $canReturnToStock = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT);
00449 if (Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_CAN_SUBTRACT)) {
00450 return true;
00451 } else {
00452 return false;
00453 }
00454 }
00455
00456
00457
00458
00459
00460
00461
00462 public function canShipPartially($order = null)
00463 {
00464 if (is_null($order) || !$order instanceof Mage_Sales_Model_Order) {
00465 $order = Mage::registry('current_shipment')->getOrder();
00466 }
00467 $value = $order->getCanShipPartially();
00468 if (!is_null($value) && !$value) {
00469 return false;
00470 }
00471 return true;
00472 }
00473
00474
00475
00476
00477
00478
00479
00480 public function canShipPartiallyItem($order = null)
00481 {
00482 if (is_null($order) || !$order instanceof Mage_Sales_Model_Order) {
00483 $order = Mage::registry('current_shipment')->getOrder();
00484 }
00485 $value = $order->getCanShipPartiallyItem();
00486 if (!is_null($value) && !$value) {
00487 return false;
00488 }
00489 return true;
00490 }
00491
00492 public function isShipmentRegular()
00493 {
00494 if (!$this->canShipPartiallyItem() || !$this->canShipPartially()) {
00495 return false;
00496 }
00497 return true;
00498 }
00499
00500 }