public function getCustomListInstantStock()
    {
        $this->context = Context::getContext();
        $this->lang = false;
        $this->multishop_context = Shop::CONTEXT_ALL;
        $this->list_no_link = true;
        $this->show_toolbar = true;
        // retrieving the type of inventory management and send to template
        $this->advanced_stock_management = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
        $this->context->smarty->assign(array('advanced_stock_management' => $this->advanced_stock_management));
        // smarty values
        $this->context->smarty->assign(array('advanced_stock_management' => $this->advanced_stock_management, 'warehouses' => Warehouse::getWarehouses(), 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'suppliers' => Supplier::getSuppliers(), 'manufacturers' => Manufacturer::getManufacturers(), 'controller_status' => $this->controller_status, 'quantity_filter' => 0, 'tokens' => array(array('value' => '=', 'label' => $this->l('Equal')), array('value' => '>', 'label' => $this->l('Strictly greater than')), array('value' => '<', 'label' => $this->l('Strictly less than'))), 'list' => 'first'));
        // if advanced stock, we work in stock table
        if ($this->advanced_stock_management) {
            $this->table = 'product';
            $this->className = 'Product';
            $this->identifier = 'id_product';
            $this->_orderBy = 'id_product';
            // determination of the warehouse, if no selected warehouse, select the first
            if (($id_warehouse = $this->getCurrentValue('id_warehouse')) == false) {
                $id_warehouse = -1;
            }
            $this->fields_list = array('ids' => array('title' => $this->l('#'), 'search' => false), 'name' => array('title' => $this->l('Name'), 'havingFilter' => true, 'width' => 200, 'callback' => 'renderNameColumn'), 'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 50, 'havingFilter' => true), 'first_supplier_ref' => array('title' => $this->l('Supplier reference'), 'search' => false, 'callback' => 'renderFirstSupplierRefColumn'), 'category_name' => array('title' => $this->l('Categorie'), 'search' => false, 'callback' => 'renderCategoryNameColumn'), 'manufacturer' => array('title' => $this->l('Manufacturer'), 'search' => false), 'first_supplier_price' => array('title' => $this->l('Supplier price'), 'width' => 80, 'orderby' => true, 'search' => false, 'align' => 'right', 'callback' => 'renderSupplierPriceColumn'), 'price' => array('title' => $this->l('Price(te)'), 'width' => 80, 'orderby' => true, 'search' => false, 'type' => 'price', 'align' => 'right'), 'price_ttc' => array('title' => $this->l('Price(ti)'), 'width' => 80, 'type' => 'price', 'search' => false, 'align' => 'right', 'orderby' => false), 'valuation' => array('title' => $this->l('Valuation'), 'width' => 150, 'orderby' => false, 'search' => false, 'type' => 'price', 'currency' => true, 'hint' => $this->l('Total value of the physical quantity. The sum (for all prices) is not available for all warehouses, please filter by warehouse.')), 'physical_quantity' => array('title' => $this->l('Physical quantity'), 'width' => 50, 'search' => false, 'align' => 'right'), 'usable_quantity' => array('title' => $this->l('Usable quantity'), 'width' => 50, 'search' => false, 'align' => 'right'), 'real_quantity' => array('title' => $this->l('Real quantity'), 'width' => 50, 'align' => 'right', 'hint' => $this->l('Physical quantity (usable) - Customer orders + suppliers orders'), 'search' => false, 'orderby' => false), 'advanced_stock_management' => array('title' => $this->l('Stock management'), 'width' => 70, 'align' => 'center', 'hint' => $this->l('Adv stock mgt ? (Product->Quantities)'), 'search' => false, 'callback' => 'renderAdvancedStockManagementColumn'));
            if ($this->controller_status) {
                $this->fields_list = array_merge($this->fields_list, array('id_product' => array('title' => $this->l('Location'), 'width' => 70, 'align' => 'center', 'search' => false, 'class' => 'location_column', 'callback' => 'renderLocationColumn', 'orderby' => false)));
            }
            // building query
            $this->_select = '  IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name,
                                            IFNULL(CONCAT(a.id_product, ";", pa.id_product_attribute), a.id_product) as ids,
                                           ps.product_supplier_reference as first_supplier_ref,
                                           ps.product_supplier_price_te as first_supplier_price,
                                           w.id_currency, 
                                           cl.name as category_name, 
                                           m.name as manufacturer, 
                                           if (pa.wholesale_price = 0.000000, a.wholesale_price, pa.wholesale_price) as wholesale_price,
                                           IFNULL(pa.reference, a.reference) as reference,
                                           pa.price as price_attribute, 
                                           a.price as price_product, 
                                           a.id_tax_rules_group, 
                                           IFNULL(pa.id_product_attribute, 0) as id_product_attribute,
                                           wpl.id_warehouse_product_location, 
                                           ewpl.id_erpip_warehouse_product_location,
                                           area.id_erpip_zone as id_area, 
                                           area.name as area_name, 
                                           sub_area.id_erpip_zone as id_sub_area, 
                                           sub_area.name as sub_area_name, 
                                           wpl.location as location';
            $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa ON a.id_product = pa.id_product ';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
					a.id_product = pl.id_product
					AND pl.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.id_product_attribute = pa.id_product_attribute)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute` atr ON (atr.id_attribute = pac.id_attribute)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (
					al.id_attribute = pac.id_attribute
					AND al.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (
					agl.id_attribute_group = atr.id_attribute_group
					AND agl.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'stock s ON (a.id_product = s.id_product AND s.id_product_attribute = IFNULL(pa.id_product_attribute, 0)';
            //Si le filtre par entrepôt a été sélectionné, alors il ne faut prendre les quantités que dans cet entrepôt
            if ($id_warehouse != -1) {
                $this->_join .= 'AND s.id_warehouse = ' . $id_warehouse;
            }
            $this->_join .= ') ';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'warehouse_product_location wpl ON (wpl.id_product = a.id_product AND wpl.id_product_attribute = IFNULL(pa.id_product_attribute, 0)) ';
            if ($id_warehouse != -1) {
                $this->_join .= ' AND wpl.id_warehouse=' . $id_warehouse . ' ';
            }
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'erpip_warehouse_product_location ewpl ON wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location ';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone area ON area.id_erpip_zone = ewpl.id_zone_parent ';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone sub_area ON sub_area.id_erpip_zone = ewpl.id_zone ';
            $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'warehouse` w ON (w.id_warehouse = s.id_warehouse) ';
            $this->_join .= 'INNER JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (a.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $this->context->language->id . ')';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON m.id_manufacturer = a.id_manufacturer ';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'product_supplier ps ON
                                        ps.id_product = a.id_product 
                                        AND ps.id_product_attribute = IFNULL(pa.id_product_attribute,0) ';
            $this->context->smarty->assign(array('sub_title' => $this->l('List of products available in stock')));
            // SPECIFIC FILTER
            $area = $this->getCurrentValue('area');
            $subarea = $this->getCurrentValue('subarea');
            if ($id_warehouse > 0) {
                // treatment of filters
                $this->context->smarty->assign(array('areas' => ErpZone::getZonesName($id_warehouse), 'sub_areas' => $area ? ErpZone::getZonesName($id_warehouse, 'sub_area', $area) : array(), 'id_warehouse' => $id_warehouse));
            }
            // If area and sub area specified, filter on warehouse, area and subarea
            if ($area != false && $subarea != false) {
                $this->_where .= ' AND (s.id_warehouse = ' . $id_warehouse . ' OR wpl.id_warehouse=' . $id_warehouse . ') 
                                                AND area.id_erpip_zone = "' . (int) $area . '" AND sub_area.id_erpip_zone = ' . (int) $subarea;
            } elseif ($area != false) {
                $this->_where .= ' AND (s.id_warehouse = ' . $id_warehouse . ' OR wpl.id_warehouse=' . $id_warehouse . ') 
                                                AND area.id_erpip_zone = ' . (int) $area;
            } else {
                // if id = -1 :no filter because all warehouse
                if ($id_warehouse != -1) {
                    $this->_where .= ' AND (s.id_warehouse = ' . $id_warehouse . ' OR wpl.id_warehouse=' . $id_warehouse . ')';
                }
            }
            // filtering Table quantity
            $table_quantity = 'physical_quantity';
            $table_stock = "s";
        } else {
            $this->table = 'stock_available';
            $this->className = 'StockAvailable';
            $this->identifier = 'id_stock_available';
            $this->_orderBy = 'id_product';
            $this->fields_list = array('ids' => array('title' => '#', 'search' => false), 'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 50, 'havingFilter' => true), 'first_supplier_ref' => array('title' => $this->l('Supplier reference'), 'search' => false, 'callback' => 'renderFirstSupplierRefColumn'), 'name' => array('title' => $this->l('Name'), 'havingFilter' => true), 'category_name' => array('title' => $this->l('Category'), 'search' => false, 'callback' => 'renderCategoryNameColumn'), 'manufacturer' => array('title' => $this->l('Manufacturer'), 'search' => false), 'wholesale_price' => array('title' => $this->l('Supplier price'), 'width' => 80, 'orderby' => true, 'search' => false, 'align' => 'right'), 'price' => array('title' => $this->l('Price (te)'), 'width' => 80, 'orderby' => true, 'search' => false, 'align' => 'right', 'type' => 'decimal', 'suffix' => '€'), 'price_ttc' => array('title' => $this->l('Price (ti)'), 'width' => 80, 'search' => false, 'type' => 'price', 'align' => 'right', 'orderby' => false), 'quantity' => array('title' => $this->l('Quantity'), 'width' => 50, 'align' => 'right', 'search' => false, 'filter_key' => 'a!quantity'));
            // building query
            $this->_select = '
					IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name,
					pl.name as id_currency, if (a.id_product_attribute = 0, a.id_product, CONCAT(a.id_product, ";", a.id_product_attribute)) as ids,

							(
								SELECT ps.product_supplier_reference
								FROM ' . _DB_PREFIX_ . 'product_supplier ps
								WHERE ps.id_product = a.id_product
								AND ps.id_product_attribute = a.id_product_attribute
								LIMIT 1
							)as first_supplier_ref, cl.name as category_name, m.name as manufacturer, pa.price as price_attribute, p.price as price_product,
							IFNULL((p.price + pa.price), p.price) as price, if (pa.wholesale_price = 0.000000, p.wholesale_price, pa.wholesale_price) as wholesale_price,
							IFNULL(pa.reference, p.reference) as reference, p.id_tax_rules_group';
            $this->_group = 'GROUP BY a.id_product, a.id_product_attribute';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
					a.id_product = pl.id_product
					AND pl.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.id_product_attribute = a.id_product_attribute)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.id_product_attribute = a.id_product_attribute)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute` atr ON (atr.id_attribute = pac.id_attribute)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (
					al.id_attribute = pac.id_attribute
					AND al.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (
					agl.id_attribute_group = atr.id_attribute_group
					AND agl.id_lang = ' . (int) $this->context->language->id . '
			)';
            $this->_join .= 'INNER JOIN ' . _DB_PREFIX_ . 'product p ON a.id_product = p.id_product ';
            $this->_join .= 'INNER JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (p.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $this->context->language->id . ')';
            $this->_join .= 'LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON m.id_manufacturer = p.id_manufacturer ';
            $this->context->smarty->assign(array('sub_title' => $this->l('List of products available in stock')));
            // filtering Table quantity
            $table_quantity = 'quantity';
            $table_stock = "a";
        }
        // FILTERS
        // category filter
        if (($id_category = $this->getCurrentValue('id_category')) != false) {
            $this->_where .= ' AND a.id_product IN (
						SELECT cp.id_product
						FROM ' . _DB_PREFIX_ . 'category_product cp
						WHERE cp.id_category = ' . $id_category . '
						)';
        }
        // supplier filter
        if (($id_supplier = $this->getCurrentValue('id_supplier')) != false) {
            $this->_where .= ' AND a.id_product IN (
						SELECT ps.id_product
						FROM ' . _DB_PREFIX_ . 'product_supplier ps
						WHERE ps.id_supplier = ' . $id_supplier . '
						)';
        }
        // manufacturer filter
        if (($id_manufacturer = $this->getCurrentValue('id_manufacturer')) != false) {
            $this->_where .= ' AND m.id_manufacturer = ' . $id_manufacturer;
        }
        // quantity filter
        if (($moreless = $this->getCurrentValue('moreless')) != false) {
            // quantity
            $quantity = (int) Tools::getValue('quantity_filter');
            if ($quantity < 0) {
                $this->displayWarning($this->l('The quantity filter has not been taken into account because the comparison quantity must be positive or null.'));
            } elseif (!in_array($moreless, array('=', '>', '<'))) {
                $this->displayWarning($this->l('To filter by quantity, the allowed operators are : ">", "=" and "<" !'));
            } else {
                //If filter by warehouse not used, then we check the addition of quantity of the warehouses
                //Therefore we modify the selection in the request to calculate its sum
                //Then we replace where condition by group by having
                //(In this case no need to force to 0 quantity not definied cause Sum manage it)
                if (!$this->advanced_stock_management) {
                    $id_warehouse = -1;
                }
                if ($id_warehouse == -1) {
                    $this->_select .= ', SUM(distinct ' . $table_stock . '.' . $table_quantity . ') as sum_quantity ';
                    $this->_group .= ' HAVING sum_quantity ' . $moreless . $quantity;
                } else {
                    $this->_where .= ' AND (' . $table_stock . '.' . $table_quantity . ' ' . $moreless . ' ' . $quantity;
                    if ($moreless == '=' && $quantity == 0 || $moreless == "<" && $quantity > 0) {
                        $this->_where .= ' OR  ' . $table_stock . '.' . $table_quantity . ' IS NULL)';
                    } else {
                        $this->_where .= ')';
                    }
                }
            }
        }
        $this->context->smarty->assign(array('ps_version_sup_1550' => version_compare(_PS_VERSION_, '1.5.5.0', '>=')));
        $list = $this->renderList();
        return $list;
    }
Пример #2
0
 public function beforeAdd($object)
 {
     $area = ErpZone::getZoneByNameAndWarehouse($object->name, $object->id_warehouse);
     if (count($area) == 0) {
         return parent::beforeAdd($object);
     } else {
         Tools::redirectAdmin($this->context->link->getAdminLink('AdminErpZone') . '&exist=true');
     }
 }
    public function renderList()
    {
        $this->toolbar_title = $this->l('Products list');
        if (Tools::isSubmit('id_display')) {
            self::$currentIndex .= '&id_display=' . (int) Tools::getValue('id_display');
        }
        if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != '-1') {
            self::$currentIndex .= '&id_warehouse=' . (int) Tools::getValue('id_warehouse');
        }
        if (Tools::isSubmit('areaFilter')) {
            self::$currentIndex .= '&areaFilter=' . Tools::getValue('areaFilter');
        }
        if (Tools::isSubmit('subareaFilter')) {
            self::$currentIndex .= '&subareaFilter=' . Tools::getValue('subareaFilter');
        }
        if (Tools::isSubmit('id_category') && Tools::getValue('id_category') != '-1') {
            self::$currentIndex .= '&id_category=' . (int) Tools::getValue('id_category');
        }
        if (Tools::isSubmit('id_supplier') && Tools::getValue('id_supplier') != '-1') {
            self::$currentIndex .= '&id_supplier=' . (int) Tools::getValue('id_supplier');
        }
        if (Tools::isSubmit('id_manufacturer') && Tools::getValue('id_manufacturer') != '-1') {
            self::$currentIndex .= '&id_manufacturer=' . (int) Tools::getValue('id_manufacturer');
        }
        // Get display type
        $id_display = $this->getCurrentValue('id_display');
        // qubquery : return the first provider reference for principal product
        $this->_select = '
				cl.name as category_name,
				i.id_image,
				a.id_product as mvt_reason,
                                area.name as area_name, 
                                sub_area.name as sub_area_name, 
                                wpl.location as location,
				a.id_product as new_quantity,
				(
					SELECT ps.product_supplier_reference
					FROM ' . _DB_PREFIX_ . 'product_supplier ps
					WHERE ps.id_product = a.id_product
					AND ps.id_product_attribute = 0
					LIMIT 1
				)as first_supplier_ref,
                                (
                                    EXISTS(SELECT pa.id_product FROM ' . _DB_PREFIX_ . 'product_attribute pa WHERE pa.id_product = a.id_product LIMIT 1)
                                ) 
                                as have_attribute,
                                ';
        $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.id_product = a.id_product)' . 'INNER JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (a.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->context->language->id . ')
                                 INNER JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (a.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $this->context->language->id . ')
                                 LEFT JOIN ' . _DB_PREFIX_ . 'image i ON a.id_product = i.id_product ';
        $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'warehouse_product_location wpl ON (wpl.id_product = a.id_product AND wpl.id_product_attribute = IFNULL(pa.id_product_attribute, 0))';
        $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_warehouse_product_location ewpl ON wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location ';
        $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone area ON area.id_erpip_zone = ewpl.id_zone_parent ';
        $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone sub_area ON sub_area.id_erpip_zone = ewpl.id_zone ';
        // Render 1 : mix products and declination to sort by area
        if ($id_display == 1) {
            $this->_select .= 'IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as product_name,
                                        IFNULL((CONCAT(a.id_product, ";", pa.id_product_attribute)), a.id_product) as id_product,';
            $this->_join .= '
                            LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.id_product_attribute = pa.id_product_attribute)
                            LEFT JOIN `' . _DB_PREFIX_ . 'attribute` atr ON (atr.id_attribute = pac.id_attribute)
                            LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = ' . (int) $this->context->language->id . ')
                            LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = ' . (int) $this->context->language->id . ')
                            ';
        } else {
            $this->_select .= 'pl.name as product_name,';
        }
        $this->tpl_list_vars['advanced_stock_token'] = $this->advanced_stock_token;
        // FILTERS
        // Init filters variables
        $this->tpl_list_vars['id_category'] = -1;
        $this->tpl_list_vars['id_supplier'] = -1;
        $this->tpl_list_vars['id_manufacturer'] = -1;
        $this->tpl_list_vars['id_warehouse'] = -1;
        $this->tpl_list_vars['areaFilter'] = -1;
        $this->tpl_list_vars['subareaFilter'] = -1;
        $this->tpl_list_vars['id_display'] = 0;
        // Add additional filters
        $this->tpl_list_vars['warehouses'] = Warehouse::getWarehouses();
        $this->tpl_list_vars['categories'] = Category::getSimpleCategories((int) $this->context->language->id);
        $this->tpl_list_vars['suppliers'] = Supplier::getSuppliers();
        $this->tpl_list_vars['manufacturers'] = Manufacturer::getManufacturers();
        $this->tpl_list_vars['controller_status'] = $this->controller_status;
        // Get inventory containers
        $this->tpl_list_vars['containers'] = ErpInventory::getContainers();
        // get conf stock gap
        $this->tpl_list_vars['gap_stock'] = Configuration::getGlobalValue('ERP_GAP_STOCK');
        require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
        $this->tpl_list_vars['erp_feature'] = ErpFeature::getFeaturesWithToken($this->context->language->iso_code);
        $this->tpl_list_vars['template_path'] = $this->template_path;
        // get default inventory reasons
        if ($this->context->language->iso_code == 'fr') {
            $this->tpl_list_vars['reason_increase'] = ErpStockMvtReason::existsByName('Augmentation d\'inventaire');
            $this->tpl_list_vars['reason_decrease'] = ErpStockMvtReason::existsByName('Diminution d\'inventaire');
        } else {
            $this->tpl_list_vars['reason_increase'] = ErpStockMvtReason::existsByName('Increase of inventory');
            $this->tpl_list_vars['reason_decrease'] = ErpStockMvtReason::existsByName('Decrease of inventory');
        }
        // specify advanced stock manager or not
        if ($this->advanced_stock_management) {
            // Get the selected warehouse, if there's not, get the first one
            if (($id_warehouse = $this->getCurrentValue('id_warehouse')) == false) {
                $id_warehouse = $this->getCookie('id_warehouse');
                $this->tpl_list_vars['id_warehouse'] = $id_warehouse;
            }
            // filters warehouse location
            $area = $this->getCurrentValue('areaFilter');
            $subarea = $this->getCurrentValue('subareaFilter');
            $this->tpl_list_vars['areas'] = ErpZone::getZonesName($id_warehouse);
            $this->tpl_list_vars['sub_areas'] = $area ? ErpZone::getZonesName($id_warehouse, 'sub_area', $area) : array();
            // if an area AND an under area are specified, we filter the area and the under area for the specified area
            if ($area != false && $subarea != false) {
                $this->_where .= ' AND wpl.id_warehouse = ' . (int) $id_warehouse . '
                                                AND area.id_erpip_zone = "' . (int) $area . '" AND sub_area.id_erpip_zone = ' . (int) $subarea;
                $this->_group = 'GROUP BY a.id_product';
            } elseif ($area != false) {
                $this->_where .= ' AND wpl.id_warehouse=' . (int) $id_warehouse . ' AND area.id_erpip_zone = ' . (int) $area;
                //$this->_where .= ' AND area.id_erpip_zone = '.(int)$area;
                if ($id_display == 1) {
                    $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute';
                } else {
                    $this->_group = 'GROUP BY a.id_product';
                }
            } else {
                $this->_where .= ' AND wpl.id_warehouse = ' . (int) $id_warehouse;
                if ($id_display == 1) {
                    $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute';
                } else {
                    $this->_group = 'GROUP BY a.id_product';
                }
            }
        } else {
            if ($id_display == 1) {
                $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute';
            } else {
                $this->_group = 'GROUP BY a.id_product';
            }
        }
        // filter the query with applied filters
        //category filter
        if (($id_category = $this->getCurrentValue('id_category')) != false) {
            $this->_where .= ' AND a.id_product IN (
                                    SELECT cp.id_product
                                    FROM ' . _DB_PREFIX_ . 'category_product cp
                                    WHERE cp.id_category = ' . (int) $id_category . '
                            )';
        }
        // provider filter
        if (($id_supplier = $this->getCurrentValue('id_supplier')) != false) {
            $this->_where .= ' AND a.id_product IN (
                                SELECT ps.id_product
                                FROM ' . _DB_PREFIX_ . 'product_supplier ps
                                WHERE ps.id_supplier = ' . (int) $id_supplier . '
                        )';
        }
        // Brand filter
        if (($id_manufacturer = $this->getCurrentValue('id_manufacturer')) != false) {
            $this->_where .= ' AND a.id_manufacturer = ' . (int) $id_manufacturer;
        }
        $this->displayInformation($this->l('Be careful, if you are using advanced [respectively simple] stock management, only products using advanced [respectively simple] stock management will be exported.'));
        $this->displayInformation($this->l('In advanced sotck managment, products that are not stocked in a warehouse will not appear.'));
        // Show information or confirm message / error at the end of the inventory
        /*switch(Tools::getValue('submitFilterproduct'))
        		{
        			case 0:
        				$this->displayInformation($this->l('New inventory'));
        			break;
        			case 1:
        				$this->confirmations[] = $this->l('Inventory completed');
        			break;
        			case 2:
        				$this->errors[] = Tools::displayError('There has been a problem while handling products');
        			break;
        			default:
        				$this->displayInformation($this->l('New inventory'));
        			break;
        		}*/
        // Add plugin simple tooltip
        $this->addJqueryPlugin('cluetip', _MODULE_DIR_ . 'erpillicopresta/js/cluetip/');
        // add jquery dialog
        $this->addJqueryUI('ui.dialog');
        // add plugin validity
        $this->addJqueryPlugin('validity.min', _MODULE_DIR_ . 'erpillicopresta/js/validity/');
        // Load JS
        $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/inventory_tools.js');
        $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/inventory.js');
        // Load CSS
        $this->addCSS(_MODULE_DIR_ . 'erpillicopresta/css/jquery.validity.css');
        $this->addCSS(_MODULE_DIR_ . 'erpillicopresta/css/jquery.cluetip.css');
        $list = parent::renderList();
        return $list;
    }