* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminStockMvt extends AdminTab { public function __construct() { $this->table = 'stock_mvt'; $this->className = 'StockMvt'; $this->edit = false; $this->delete = false; $this->view = true; $this->fieldsDisplay = array( 'id_stock_mvt' => array('title' => $this->l('ID'), 'width' => 40), 'product_name' => array('title' => $this->l('Product Name'), 'width' => 250, 'havingFilter' => true), 'quantity' => array('title' => $this->l('Quantity'), 'width' => 40), 'reason' => array('title' => $this->l('Reason'), 'width' => 250), 'id_order' => array('title' => $this->l('ID Order'), 'width' => 40), 'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true), ); global $cookie; $this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (a.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.') LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$cookie->id_lang.') LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = a.id_product_attribute) LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$cookie->id_lang.')'; $this->_group = 'GROUP BY a.id_stock_mvt'; parent::__construct(); } public function postProcess() { global $cookie; if (Tools::isSubmit('rebuildStock')) StockMvt::addMissingMvt((int)$cookie->id_employee, false); return parent::postProcess(); } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $dl = 'name'; echo '
'.($obj->id ? '' : '').'
'.$this->l('Stock Movement').'
'; foreach ($this->_languages as $language) echo '
*
'; $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $dl, 'name'); echo '
 
 
'; echo '
'; } public function viewstock_mvt() { global $cookie; $stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt')); $product = new Product((int)$stockMvt->id_product, true, (int)$cookie->id_lang); $movements = $product->getStockMvts((int)$cookie->id_lang); echo '

'.$this->l('Stock Movements for').' '.$product->name.'

'; $irow = 0; foreach ($movements AS $k => $mvt) { echo ' '; } echo '
'.$this->l('ID').' '.$this->l('Product Name').' '.$this->l('Quantity').' '.$this->l('Reason').' '.$this->l('Employee').' '.$this->l('Order').' '.$this->l('Date').'
'.$mvt['id_stock_mvt'].' '.$mvt['product_name'].' '.$mvt['quantity'].' '.$mvt['reason'].' '.$mvt['employee'].' #'.$mvt['id_order'].' '.Tools::displayDate($mvt['date_add'], (int)($cookie->id_lang)).'
'; } public function display() { global $currentIndex, $cookie; $old_post = false; if (!isset($_GET['addstock_mvt_reason']) OR (Tools::isSubmit('submitAddstock_mvt_reason') AND Tools::getValue('id_stock_mvt_reason'))) { if (isset($_POST)) { $old_post = $_POST; } echo '

'.$this->l('Stock movement history').'

'; parent::display(); if (!isset($_GET['view'.$this->table])) echo '

'; } if (isset($_GET['view'.$this->table])) return; if ($old_post) $_POST = $old_post; $this->table = 'stock_mvt_reason'; $this->className = 'StockMvtReason'; $this->identifier = 'id_stock_mvt_reason'; $this->edit = true; $this->delete = true; $this->lang = true; $this->add = true; $this->view = false; $this->_listSkipDelete = array(1,2,3,4); $this->_defaultOrderBy = $this->identifier; $this->fieldsDisplay = array('id_stock_mvt_reason' => array('title' => $this->l('ID'), 'width' => 40), 'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false), 'name' => array('title' => $this->l('Name'), 'width' => 500)); $reasons = StockMvtReason::getStockMvtReasons((int)$cookie->id_lang); $this->_fieldsOptions = array('PS_STOCK_MVT_REASON_DEFAULT' => array('title' => $this->l('Default Stock Movement reason:'), 'cast' => 'intval', 'type' => 'select', 'list' => $reasons, 'identifier' => 'id_stock_mvt_reason')); unset($this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter); echo '

'.$this->l('Stock movement reason').'

'; $this->postProcess(); return parent::display(); } }