Esempio n. 1
0
    /**
     * AdminController::renderList() override
     * @see AdminController::renderList()
     */
    public function renderList()
    {
        // removes toolbar btn
        $this->toolbar_btn = array();
        // overrides select
        $this->_select = '
			CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name,
			CONCAT(a.employee_lastname, \' \', a.employee_firstname) as employee,
			mrl.name as reason,
			stock.reference as product_reference,
			stock.ean13 as product_ean13,
			stock.upc as product_upc,
			w.id_currency as id_currency,
			w.name as warehouse_name';
        // overrides join
        $this->_join = 'INNER JOIN ' . _DB_PREFIX_ . 'stock stock ON a.id_stock = stock.id_stock
							LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (
								stock.id_product = pl.id_product
								AND pl.id_lang = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('pl') . '
							)
							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) $this->context->language->id . '
							)
							LEFT JOIN `' . _DB_PREFIX_ . 'warehouse` w ON (w.id_warehouse = stock.id_warehouse)
							LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute)
							LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (
								al.id_attribute = pac.id_attribute
								AND pac.id_product_attribute <> 0
								AND al.id_lang = ' . (int) $this->context->language->id . '
							)';
        // overrides group
        $this->_group = 'GROUP BY a.id_stock_mvt';
        // overrides where depending on the warehouse
        $id_warehouse = (int) $this->getCurrentWarehouseId();
        if ($id_warehouse > 0) {
            $this->_where = ' AND w.id_warehouse = ' . $id_warehouse;
            self::$currentIndex .= '&id_warehouse=' . $id_warehouse;
        }
        // sets the current warehouse
        $this->tpl_list_vars['current_warehouse'] = $this->getCurrentWarehouseId();
        // sets the list of warehouses
        $warehouses = Warehouse::getWarehouses(true);
        array_unshift($warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
        $this->tpl_list_vars['list_warehouses'] = $warehouses;
        // sets toolbar
        $this->initToolbar();
        // renders list
        $list = parent::renderList();
        // if export requested
        if (Tools::isSubmit('csv')) {
            if (count($this->_list) > 0) {
                $this->renderCSV();
                die;
            } else {
                $this->displayWarning($this->l('There is nothing to export as a CSV.'));
            }
        }
        return $list;
    }
 public function renderForm()
 {
     $warehouses = Warehouse::getWarehouses();
     $this->fields_form = array('legend' => array('title' => $this->l('States'), 'icon' => 'icon-globe'), 'input' => array(array('type' => 'text', 'label' => 'Название', 'name' => 'name', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Порядок сортировки', 'name' => 'sort', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Стоимость доставки в разделе декор', 'name' => 'price_decor', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Стоимость доставки обычная', 'name' => 'price_main', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Адрес склада', 'name' => 'address_warehouse', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => 'Режим работы', 'name' => 'mode', 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'switch', 'label' => 'Главный', 'name' => 'is_main', 'required' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />'))), array('type' => 'switch', 'label' => 'Московская обл', 'name' => 'is_msk', 'required' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'active_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />')))), 'submit' => array('title' => $this->l('Save')));
     //                foreach ($warehouses as $warehous){
     //                    $this->fields_form['input'][] = array(
     //                        'type' => 'text',
     //                        'label' => 'Время доставки со скдада '.$warehous['name'],
     //                        'name' => 'distance_'.$warehous['id_warehouse'],
     //                        'hint' => 'Время доставки в днях',
     //                    );
     //                    $this->fields_form['input'][] = array(
     //                        'type' => 'text',
     //                        'label' => 'Стоимость доставки со склада '.$warehous['name'],
     //                        'name' => 'price_'.$warehous['id_warehouse'],
     //                        'hint' => 'Стоимость доставки в рублях',
     //                    );
     //                    if(!empty($this->object->id_city)){
     //                        $fields_value = Db::getInstance()->getRow("SELECT distance,price FROM "._DB_PREFIX_."city_warehous
     //                            WHERE id_warehouse={$warehous['id_warehouse']} AND id_city={$this->object->id_city}");
     //
     //                        $this->fields_value['distance_'.$warehous['id_warehouse']] = isset($fields_value['distance']) ? $fields_value['distance'] : '';
     //                        $this->fields_value['price_'.$warehous['id_warehouse']] = isset($fields_value['price']) ? $fields_value['price'] : '';
     //                    }
     //                }
     return parent::renderForm();
 }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->className = 'Configuration';
     $this->table = 'configuration';
     parent::__construct();
     $warehouse_list = Warehouse::getWarehouses();
     $warehouse_no = array(array('id_warehouse' => 0, 'name' => $this->l('No default warehouse (default setting)')));
     $warehouse_list = array_merge($warehouse_no, $warehouse_list);
     $this->fields_options = array('products' => array('title' => $this->l('Products (general)'), 'fields' => array('PS_CATALOG_MODE' => array('title' => $this->l('Catalog mode'), 'hint' => $this->l('When active, all shopping features will be disabled.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_COMPARATOR_MAX_ITEM' => array('title' => $this->l('Product comparison'), 'hint' => $this->l('Set the maximum number of products that can be selected for comparison. Set to "0" to disable this feature.'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), 'PS_NB_DAYS_NEW_PRODUCT' => array('title' => $this->l('Number of days for which the product is considered \'new\''), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), 'PS_CART_REDIRECT' => array('title' => $this->l('Redirect after adding product to cart'), 'hint' => $this->l('Only for non-AJAX versions of the cart.'), 'cast' => 'intval', 'show' => true, 'required' => false, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Previous page'), 1 => $this->l('Cart summary'))), 'PS_PRODUCT_SHORT_DESC_LIMIT' => array('title' => $this->l('Max size of short description'), 'hint' => $this->l('Set the maximum size of product short description (in characters).'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'suffix' => $this->l('characters')), 'PS_QTY_DISCOUNT_ON_COMBINATION' => array('title' => $this->l('Quantity discounts based on'), 'hint' => $this->l('How to calculate quantity discounts.'), 'cast' => 'intval', 'show' => true, 'required' => false, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Products'), 1 => $this->l('Combinations'))), 'PS_FORCE_FRIENDLY_PRODUCT' => array('title' => $this->l('Force update of friendly URL'), 'hint' => $this->l('When active, friendly URL will be updated on every save.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'))), 'order_by_pagination' => array('title' => $this->l('Pagination'), 'fields' => array('PS_PRODUCTS_PER_PAGE' => array('title' => $this->l('Products per page'), 'hint' => $this->l('Number of products displayed per page. Default is 10.'), 'validation' => 'isUnsignedInt', 'cast' => 'intval', 'type' => 'text'), 'PS_PRODUCTS_ORDER_BY' => array('title' => $this->l('Default order by'), 'hint' => $this->l('The order in which products are displayed in the product list.'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Product name')), array('id' => '1', 'name' => $this->l('Product price')), array('id' => '2', 'name' => $this->l('Product add date')), array('id' => '3', 'name' => $this->l('Product modified date')), array('id' => '4', 'name' => $this->l('Position inside category')), array('id' => '5', 'name' => $this->l('Manufacturer')), array('id' => '6', 'name' => $this->l('Product quantity')), array('id' => '7', 'name' => $this->l('Product reference'))), 'identifier' => 'id'), 'PS_PRODUCTS_ORDER_WAY' => array('title' => $this->l('Default order method'), 'hint' => $this->l('Default order method for product list.'), 'type' => 'select', 'list' => array(array('id' => '0', 'name' => $this->l('Ascending')), array('id' => '1', 'name' => $this->l('Descending'))), 'identifier' => 'id')), 'submit' => array('title' => $this->l('Save'))), 'fo_product_page' => array('title' => $this->l('Product page'), 'fields' => array('PS_DISPLAY_QTIES' => array('title' => $this->l('Display available quantities on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_LAST_QTIES' => array('title' => $this->l('Display remaining quantities when the quantity is lower than'), 'hint' => $this->l('Set to "0" to disable this feature.'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text'), 'PS_DISPLAY_JQZOOM' => array('title' => $this->l('Enable JqZoom instead of Fancybox on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_DISP_UNAVAILABLE_ATTR' => array('title' => $this->l('Display unavailable product attributes on the product page'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_ATTRIBUTE_CATEGORY_DISPLAY' => array('title' => $this->l('Display the "add to cart" button when a product has attributes'), 'hint' => $this->l('Display or hide the "add to cart" button on category pages for products that have attributes forcing customers to see product details.'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_ATTRIBUTE_ANCHOR_SEPARATOR' => array('title' => $this->l('Separator of attribute anchor on the product links'), 'type' => 'select', 'list' => array(array('id' => '-', 'name' => '-'), array('id' => ',', 'name' => ',')), 'identifier' => 'id'), 'PS_DISPLAY_DISCOUNT_PRICE' => array('title' => $this->l('Display discounted price'), 'desc' => $this->l('In the volume discounts board, display the new price with the applied discount instead of showing the discount (ie. "-5%").'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'))), 'stock' => array('title' => $this->l('Products stock'), 'fields' => array('PS_ORDER_OUT_OF_STOCK' => array('title' => $this->l('Allow ordering of out-of-stock products'), 'hint' => $this->l('By default, the Add to Cart button is hidden when a product is unavailable. You can choose to have it displayed in all cases.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool'), 'PS_STOCK_MANAGEMENT' => array('title' => $this->l('Enable stock management'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'js' => array('on' => 'onchange="stockManagementActivationAuthorization()"', 'off' => 'onchange="stockManagementActivationAuthorization()"')), 'PS_ADVANCED_STOCK_MANAGEMENT' => array('title' => $this->l('Enable advanced stock management'), 'hint' => $this->l('Allows you to manage physical stock, warehouses and supply orders in a new Stock menu.'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL, 'js' => array('on' => 'onchange="advancedStockManagementActivationAuthorization()"', 'off' => 'onchange="advancedStockManagementActivationAuthorization()"')), 'PS_FORCE_ASM_NEW_PRODUCT' => array('title' => $this->l('New products use advanced stock management'), 'hint' => $this->l('New products will automatically use advanced stock management and depends on stock, but no warehouse will be selected'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => false, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), 'PS_DEFAULT_WAREHOUSE_NEW_PRODUCT' => array('title' => $this->l('Default warehouse on new products'), 'hint' => $this->l('Automatically set a default warehouse when new product is created'), 'type' => 'select', 'list' => $warehouse_list, 'identifier' => 'id_warehouse'), 'PS_PACK_STOCK_TYPE' => array('title' => $this->l('Default pack stock management'), 'type' => 'select', 'list' => array(array('pack_stock' => 0, 'name' => $this->l('Decrement pack only.')), array('pack_stock' => 1, 'name' => $this->l('Decrement products in pack only.')), array('pack_stock' => 2, 'name' => $this->l('Decrement both.'))), 'identifier' => 'pack_stock')), 'bottom' => '<script type="text/javascript">stockManagementActivationAuthorization();advancedStockManagementActivationAuthorization();</script>', 'submit' => array('title' => $this->l('Save'))));
 }
 public function __construct()
 {
     $this->context = Context::getContext();
     $this->table = 'stock';
     $this->className = 'Stock';
     $this->lang = false;
     $this->multishop_context = Shop::CONTEXT_ALL;
     $this->fields_list = array('reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 200, 'havingFilter' => true), 'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 100), 'upc' => array('title' => $this->l('UPC'), 'align' => 'center', 'width' => 100), 'name' => array('title' => $this->l('Name'), 'havingFilter' => true), 'price_te' => array('title' => $this->l('Price (tax excl.)'), 'width' => 150, 'orderby' => true, 'search' => false, 'type' => 'price', 'currency' => true), 'valuation' => array('title' => $this->l('Valuation'), 'width' => 150, 'orderby' => true, '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' => 80, 'orderby' => true, 'search' => false), 'usable_quantity' => array('title' => $this->l('Usable quantity'), 'width' => 80, 'orderby' => true, 'search' => false), 'real_quantity' => array('title' => $this->l('Real quantity'), 'width' => 80, 'orderby' => true, 'search' => false, 'hint' => $this->l('Pysical qty (usable) - Clients orders + Supply Orders')));
     $this->addRowAction('details');
     $this->stock_instant_state_warehouses = Warehouse::getWarehouses(true);
     array_unshift($this->stock_instant_state_warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
     parent::__construct();
 }
 /**
  * AdminController::renderForm() override
  * @see AdminController::renderForm()
  */
 public function renderForm()
 {
     // gets the product
     $id_product = (int) Tools::getValue('id_product');
     $id_product_attribute = (int) Tools::getValue('id_product_attribute');
     // gets warehouses
     $warehouses_add = Warehouse::getWarehouses(true);
     $warehouses_remove = Warehouse::getWarehousesByProductId($id_product, $id_product_attribute);
     // displays warning if no warehouses
     if (!$warehouses_add) {
         $this->displayWarning($this->l('You must choose a warehouses before adding stock. See Stock/Warehouses'));
     }
     //get currencies list
     $currencies = Currency::getCurrencies();
     $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
     $default_currency = Currency::getCurrency($id_default_currency);
     if ($default_currency) {
         $currencies = array_merge(array($default_currency, '-'), $currencies);
     }
     // switch, in order to display the form corresponding to the current action
     switch ($this->display) {
         case 'addstock':
             // gets the last stock mvt for this product, so we can display the last unit price te and the last quantity added
             $last_sm_unit_price_te = $this->l('N/A');
             $last_sm_quantity = 0;
             $last_sm_quantity_is_usable = -1;
             $last_sm = StockMvt::getLastPositiveStockMvt($id_product, $id_product_attribute);
             // if there is a stock mvt
             if ($last_sm != false) {
                 $last_sm_currency = new Currency((int) $last_sm['id_currency']);
                 $last_sm_quantity = (int) $last_sm['physical_quantity'];
                 $last_sm_quantity_is_usable = (int) $last_sm['is_usable'];
                 if (Validate::isLoadedObject($last_sm_currency)) {
                     $last_sm_unit_price_te = Tools::displayPrice((double) $last_sm['price_te'], $last_sm_currency);
                 }
             }
             $this->displayInformation($this->l('Rolling over the quantity and price fields will give you the details about the last stock movement.'));
             // fields in the form
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Add a product to your stock.'), 'image' => '../img/admin/add_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('UPC:'), 'name' => 'upc', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to add:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to add'), 'hint' => sprintf($this->l('Last physical quantity added : %s (%s)'), $last_sm_quantity > 0 ? $last_sm_quantity : $this->l('N/A'), $last_sm_quantity > 0 ? $last_sm_quantity_is_usable >= 0 ? $this->l('Usable') : $this->l('Not usable') : $this->l('N/A'))), array('type' => 'radio', 'label' => $this->l('Usable for sale?'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this quantity ready to be displayed in your shop, or is it reserved in the warehouse for other purposes?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Please select the warehouse that you\'ll be adding products to. ')), array('type' => 'text', 'label' => $this->l('Unit price (tax excl.):'), 'name' => 'price', 'required' => true, 'size' => 10, 'maxlength' => 10, 'desc' => $this->l('Unit purchase price or unit manufacturing cost for this product (tax excl.)'), 'hint' => sprintf($this->l('Last unit price (tax excl.): %s'), $last_sm_unit_price_te)), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'desc' => $this->l('The currency associated to the product unit price.')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_TO')), 1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Add to stock'), 'class' => 'button'));
             $this->fields_value['usable'] = 1;
             break;
         case 'removestock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Remove the product from your stock.'), 'image' => '../img/admin/remove_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to remove:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Physical quantity to remove')), array('type' => 'radio', 'label' => $this->l('Usable for sale:'), 'name' => 'usable', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want to remove this quantity from the usable quantity (yes) or the physical quantity (no)?')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to remove the product from.')), array('type' => 'select', 'label' => $this->l('Label:'), 'name' => 'id_stock_mvt_reason', 'required' => true, 'options' => array('query' => StockMvtReason::getStockMvtReasonsWithFilter($this->context->language->id, array(Configuration::get('PS_STOCK_MVT_TRANSFER_FROM')), -1), 'id' => 'id_stock_mvt_reason', 'name' => 'name'), 'desc' => $this->l('Label used in stock movements'))), 'submit' => array('title' => $this->l('Remove from stock'), 'class' => 'button'));
             break;
         case 'transferstock':
             $this->fields_form[]['form'] = array('legend' => array('title' => $this->l('Transfer a product from one warehouse to another'), 'image' => '../img/admin/transfer_stock.png'), 'input' => array(array('type' => 'hidden', 'name' => 'is_post'), array('type' => 'hidden', 'name' => 'id_product'), array('type' => 'hidden', 'name' => 'id_product_attribute'), array('type' => 'hidden', 'name' => 'check'), array('type' => 'text', 'label' => $this->l('Product reference:'), 'name' => 'reference', 'size' => 30, 'disabled' => true), array('type' => 'text', 'label' => $this->l('EAN13:'), 'name' => 'ean13', 'size' => 15, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 75, 'disabled' => true), array('type' => 'text', 'label' => $this->l('Quantity to transfer:'), 'name' => 'quantity', 'size' => 10, 'maxlength' => 6, 'required' => true, 'desc' => $this->l('Quantity to transfer:')), array('type' => 'select', 'label' => $this->l('Source Warehouse:'), 'name' => 'id_warehouse_from', 'required' => true, 'options' => array('query' => $warehouses_remove, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to transfer the product from.')), array('type' => 'radio', 'label' => $this->l('Is this product usable in your source warehouse?'), 'name' => 'usable_from', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Is this the usable quantity for sale?')), array('type' => 'select', 'label' => $this->l('Destination warehouse:'), 'name' => 'id_warehouse_to', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Select the warehouse you\'d like to transfer your product(s) to. ')), array('type' => 'radio', 'label' => $this->l('Is this product for sale in your destination warehouse?'), 'name' => 'usable_to', 'required' => true, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))), 'desc' => $this->l('Do you want it to be for sale/useable?'))), 'submit' => array('title' => $this->l('Transfer'), 'class' => 'button'));
             break;
     }
     $this->initToolbar();
 }
 public function __construct()
 {
     $this->context = Context::getContext();
     $this->table = 'product';
     $this->className = 'Product';
     $this->lang = true;
     $this->colorOnBackground = true;
     $this->multishop_context = Shop::CONTEXT_ALL;
     $this->fields_list = array('reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 200, 'filter_key' => 'a!reference'), 'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 100, 'filter_key' => 'a!ean13'), 'upc' => array('title' => $this->l('UPC'), 'align' => 'center', 'width' => 100, 'filter_key' => 'a!upc'), 'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'), 'qty_sold' => array('title' => $this->l('Quantity sold'), 'width' => 160, 'orderby' => false, 'search' => false, 'hint' => $this->l('Quantity sold during the defined period.')), 'coverage' => array('title' => $this->l('Coverage'), 'width' => 160, 'orderby' => false, 'search' => false, 'hint' => $this->l('Days left before your stock runs out.')), 'stock' => array('title' => $this->l('Quantity'), 'width' => 80, 'orderby' => false, 'search' => false, 'hint' => $this->l('Physical (usable) quantity.')));
     // pre-defines coverage periods
     $this->stock_cover_periods = array($this->l('One week') => 7, $this->l('Two weeks') => 14, $this->l('Three weeks') => 21, $this->l('One month') => 31, $this->l('Six months') => 186, $this->l('One year') => 365);
     // gets the list of warehouses available
     $this->stock_cover_warehouses = Warehouse::getWarehouses(true);
     // gets the final list of warehouses
     array_unshift($this->stock_cover_warehouses, array('id_warehouse' => -1, 'name' => $this->l('All Warehouses')));
     parent::__construct();
 }
Esempio n. 7
0
 public function initFormWarehouses($obj)
 {
     $data = $this->createTemplate($this->tpl_form);
     if ($obj->id) {
         if ($this->product_exists_in_shop) {
             // Get all id_product_attribute
             $attributes = $obj->getAttributesResume($this->context->language->id);
             if (empty($attributes)) {
                 $attributes[] = array('id_product' => $obj->id, 'id_product_attribute' => 0, 'attribute_designation' => '');
             }
             $product_designation = array();
             foreach ($attributes as $attribute) {
                 $product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id] . ' - ' . $attribute['attribute_designation'], ' - ');
             }
             // Get all available warehouses
             $warehouses = Warehouse::getWarehouses(true);
             // Get already associated warehouses
             $associated_warehouses_collection = WarehouseProductLocation::getCollection($obj->id);
             $data->assign(array('attributes' => $attributes, 'warehouses' => $warehouses, 'associated_warehouses' => $associated_warehouses_collection, 'product_designation' => $product_designation, 'product' => $obj, 'link' => $this->context->link, 'token' => $this->token));
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before managing warehouses.'));
         }
     } else {
         $this->displayWarning($this->l('You must save this product before managing warehouses.'));
     }
     $this->tpl_form_vars['custom_form'] = $data->fetch();
 }
 public function process()
 {
     // check if session is active
     $session = new Session($this->sessionId);
     if ($session->sessionId > 0) {
         // update session
         $session->update();
         // process restricted functions
         switch ($this->f) {
             case 'checkLogin':
                 return Login::checkLogin($session->sessionId);
             case 'getSession':
                 return $session;
             case 'getWarehouse':
                 if (isset($this->data->update)) {
                     $warehouse = new Warehouse($session->warehouseId, $this->data->update);
                 } else {
                     $warehouse = new Warehouse($session->warehouseId);
                 }
                 $warehouse->dMail = $warehouse->getMail();
                 $warehouse->dDisableLocationLess = $warehouse->isLocationLessDisabled();
                 $warehouse->dDisablePaletteLess = $warehouse->isPaletteLessDisabled();
                 return $warehouse;
             case 'editWarehouse':
                 if (!$session->restricted) {
                     $data = $this->data;
                     $warehouse = new Warehouse($session->warehouseId);
                     // update warehouse data
                     if (isset($data->name)) {
                         $warehouse->name = $data->name;
                     }
                     if (isset($data->description)) {
                         $warehouse->description = $data->description;
                     }
                     if (isset($data->country)) {
                         $warehouse->country = $data->country;
                     }
                     if (isset($data->city)) {
                         $warehouse->city = $data->city;
                     }
                     if (isset($data->password)) {
                         $warehouse->setPassword($data->password);
                     }
                     if (isset($data->passwordRestricted)) {
                         $warehouse->setPasswordRestricted($data->passwordRestricted);
                     }
                     if (isset($data->mail)) {
                         $warehouse->setMail($data->mail);
                     }
                     if (isset($data->disableLocationLess)) {
                         $warehouse->setDisableLocationLess($data->disableLocationLess);
                     }
                     if (isset($data->disablePaletteLess)) {
                         $warehouse->setDisablePaletteLess($data->disablePaletteLess);
                     }
                     // update database entry
                     return $warehouse->edit();
                 }
                 break;
             case 'deleteWarehouse':
                 if (!$session->restricted) {
                     $warehouse = new Warehouse($session->warehouseId);
                     if ($warehouse->id > 0 && $warehouse->delete()) {
                         return $session->destroy();
                     }
                 }
                 break;
             case 'addCategory':
                 if (!$session->restricted && isset($this->data->name)) {
                     $category = new Category(null, $session->warehouseId);
                     $category->name = $this->data->name;
                     if (isset($this->data->parent)) {
                         $category->parent = $this->data->parent;
                     }
                     if ($category->edit()) {
                         return $category->id;
                     }
                 }
                 break;
             case 'getCategory':
                 if (isset($this->data->id) && isset($this->data->update)) {
                     return new Category($this->data->id, $session->warehouseId, $this->data->update);
                 } elseif (isset($this->data->id)) {
                     return new Category($this->data->id, $session->warehouseId);
                 }
                 break;
             case 'deleteCategory':
                 if (!$session->restricted && isset($this->data->id)) {
                     $category = new Category($this->data->id, $session->warehouseId);
                     return $category->delete();
                 }
                 break;
             case 'editCategory':
                 if (isset($this->data->id)) {
                     $data = $this->data;
                     $category = new Category($this->data->id, $session->warehouseId);
                     if (!$session->restricted) {
                         if (isset($data->name)) {
                             $category->name = $data->name;
                         }
                         if (isset($data->parent)) {
                             $category->parent = $data->parent;
                         }
                         if (isset($data->male)) {
                             $category->male = $data->male;
                         }
                         if (isset($data->female)) {
                             $category->female = $data->female;
                         }
                         if (isset($data->children)) {
                             $category->children = $data->children;
                         }
                         if (isset($data->baby)) {
                             $category->baby = $data->baby;
                         }
                         if (isset($data->summer)) {
                             $category->summer = $data->summer;
                         }
                         if (isset($data->winter)) {
                             $category->winter = $data->winter;
                         }
                     }
                     if (isset($data->demand)) {
                         $category->demand = $data->demand;
                     }
                     if (isset($data->weight)) {
                         $category->weight = $data->weight;
                     }
                     return $category->edit();
                 }
                 break;
             case 'getCategories':
                 if (isset($this->data->parent)) {
                     return Category::getCategories($session->warehouseId, $this->data->parent);
                 } else {
                     return Category::getCategories($session->warehouseId);
                 }
             case 'addLocation':
                 if (!$session->restricted && isset($this->data->name)) {
                     $location = new Location(null, $session->warehouseId);
                     $location->name = $this->data->name;
                     if ($location->edit()) {
                         return $location->id;
                     }
                     return true;
                 }
                 break;
             case 'getLocation':
                 if (isset($this->data->id) && isset($this->data->update)) {
                     return new Location($this->data->id, $session->warehouseId, $this->data->update);
                 } elseif (isset($this->data->id)) {
                     return new Location($this->data->id, $session->warehouseId);
                 }
                 break;
             case 'deleteLocation':
                 if (!$session->restricted && isset($this->data->id)) {
                     $location = new Location($this->data->id, $session->warehouseId);
                     return $location->delete();
                 }
                 break;
             case 'editLocation':
                 if (!$session->restricted && isset($this->data->id) && isset($this->data->name)) {
                     $location = new Location($this->data->id, $session->warehouseId);
                     $location->name = $this->data->name;
                     return $location->edit();
                 }
                 break;
             case 'getLocations':
                 return Location::getLocations($session->warehouseId);
             case 'addPalette':
                 $palette = new Palette(null, $session->warehouseId);
                 if (isset($this->data->locationId)) {
                     $palette->locationId = $this->data->locationId;
                 }
                 if ($palette->edit()) {
                     return $palette->id;
                 }
                 break;
             case 'getPalette':
                 if (isset($this->data->id) && isset($this->data->update)) {
                     return new Palette($this->data->id, $session->warehouseId, $this->data->update);
                 } elseif (isset($this->data->id)) {
                     return new Palette($this->data->id, $session->warehouseId);
                 }
                 break;
             case 'deletePalette':
                 if (isset($this->data->id)) {
                     $palette = new Palette($this->data->id, $session->warehouseId);
                     return $palette->delete();
                 }
                 break;
             case 'editPalette':
                 if (isset($this->data->id)) {
                     $palette = new Palette($this->data->id, $session->warehouseId);
                     if (isset($this->data->locationId)) {
                         $palette->locationId = $this->data->locationId;
                     }
                     return $palette->edit();
                 }
                 break;
             case 'getPalettes':
                 return Palette::getPalettes($session->warehouseId);
             case 'getCarton':
                 if (isset($this->data->id) && isset($this->data->update)) {
                     return new Carton($this->data->id, $session->warehouseId, null, null, $this->data->update);
                 } elseif (isset($this->data->id)) {
                     return new Carton($this->data->id, $session->warehouseId);
                 }
                 break;
             case 'addCarton':
                 $locationId = null;
                 $paletteId = null;
                 if (isset($this->data->location)) {
                     $locationId = $this->data->location;
                 }
                 if (isset($this->data->palette)) {
                     $paletteId = $this->data->palette;
                 }
                 $carton = new Carton(null, $session->warehouseId, $locationId, $paletteId);
                 return $carton->id;
             case 'deleteCarton':
                 if (isset($this->data->id)) {
                     $carton = new Carton($this->data->id, $session->warehouseId);
                     return $carton->delete();
                 }
                 break;
             case 'editCarton':
                 if (isset($this->data->id)) {
                     $carton = new Carton($this->data->id, $session->warehouseId);
                     if (isset($this->data->location)) {
                         $carton->locationId = $this->data->location;
                     } else {
                         $carton->locationId = null;
                     }
                     if (isset($this->data->palette)) {
                         $carton->paletteId = $this->data->palette;
                     } else {
                         $carton->paletteId = null;
                     }
                     return $carton->edit();
                 }
                 break;
             case 'addArticle':
                 if (isset($this->data->carton) && isset($this->data->category) && isset($this->data->amount)) {
                     return Stock::addArticle($this->data->carton, $this->data->category, isset($this->data->male) ? $this->data->male : false, isset($this->data->female) ? $this->data->female : false, isset($this->data->children) ? $this->data->children : false, isset($this->data->baby) ? $this->data->baby : false, isset($this->data->winter) ? $this->data->winter : false, isset($this->data->summer) ? $this->data->summer : false, $this->data->amount >= 0 ? $this->data->amount : 0, $this->data->amount < 0 ? $this->data->amount : 0);
                 }
                 break;
             case 'getStock':
                 return Stock::getStock($session->warehouseId, isset($this->data->carton) ? $this->data->carton : null, isset($this->data->category) ? $this->data->category : null, isset($this->data->palette) ? $this->data->palette : null, isset($this->data->location) ? $this->data->location : null, isset($this->data->male) ? $this->data->male : false, isset($this->data->female) ? $this->data->female : false, isset($this->data->children) ? $this->data->children : false, isset($this->data->baby) ? $this->data->male : false, isset($this->data->summer) ? $this->data->male : false, isset($this->data->winter) ? $this->data->male : false, isset($this->data->details) ? $this->data->details : false);
             case 'getBarcodeUri':
                 if (isset($this->data->text)) {
                     // create barcode object
                     $bc = new Barcode39($this->data->text);
                     if (isset($this->data->textSize)) {
                         $bc->barcode_text_size = $this->data->textSize;
                     }
                     if (isset($this->data->barThin)) {
                         $bc->barcode_bar_thin = $this->data->barThin;
                     }
                     if (isset($this->data->barThick)) {
                         $bc->barcode_bar_thick = $this->data->barThick;
                     }
                     // generate barcode image
                     $img = "barcode_" . mt_rand(0, 100) . ".png";
                     $bc->draw($img);
                     // get data uri
                     $uri = Barcode39::getDataURI($img);
                     unlink($img);
                     return $uri;
                 }
                 break;
         }
     } else {
         // process unrestricted function
         switch ($this->f) {
             case 'getActiveSessions':
                 return Session::getActiveSessionsNumber();
             case 'getWarehouses':
                 return Warehouse::getWarehouses();
             case 'addWarehouse':
                 $data = $this->data;
                 if (isset($data->name) && isset($data->description) && isset($data->country) && isset($data->city) && isset($data->password) && isset($data->mail)) {
                     $warehouse = new Warehouse();
                     Log::debug('new warehouse' . $warehouse->id);
                     $warehouse->name = $data->name;
                     $warehouse->description = $data->description;
                     $warehouse->country = $data->country;
                     $warehouse->city = $data->city;
                     $warehouse->setPassword($data->password);
                     $warehouse->setMail($data->mail);
                     return $warehouse->edit();
                 }
                 break;
             case 'getCountries':
                 return getCountries();
                 break;
             case 'getCountryCode':
                 $data = $this->data;
                 if (isset($data->name)) {
                     return getCountryCode(null, $data->name);
                 }
                 return false;
         }
     }
     return false;
 }
 public function renderForm()
 {
     // loads current warehouse
     if (!$this->loadObject(true)) {
         return;
     }
     // get the current warehouse areas
     $zones = ErpZone::getZonesByWarehouse(Tools::getValue('id_warehouse'));
     array_unshift($zones, array('name' => $this->l('Home'), 'id_erpip_zone' => 0));
     // gets warehouses
     $warehouses_add = Warehouse::getWarehouses(true);
     // displays warning if no warehouses
     if (!$warehouses_add) {
         $this->displayWarning($this->l('You must choose a warehouse before adding areas. See Stock/Warehouses'));
     }
     // Default values
     if (Tools::isSubmit('id_zone_parent') && Tools::getValue('id_zone_parent') != '') {
         $this->fields_value['id_parent'] = Tools::getValue('id_zone_parent');
     }
     if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != '') {
         $this->fields_value['id_warehouse'] = Tools::getValue('id_warehouse');
     }
     $this->fields_value['active'] = true;
     // form fields définition
     // Name
     $base = array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'size' => 40, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'));
     // warehouse
     // select warehouse only if create area level 1
     if (Tools::getValue('id_zone_parent') == '' && Tools::getValue('id_warehouse') == '') {
         $warehouse = array(array('type' => 'select', 'label' => $this->l('Warehouse'), 'name' => 'id_warehouse', 'class' => 'chosen', 'required' => true, 'options' => array('query' => $warehouses_add, 'id' => 'id_warehouse', 'name' => 'name')));
     } else {
         $warehouse = array(array('type' => 'text', 'label' => $this->l('Warehouse'), 'name' => 'warehouse_name', 'disabled' => true, 'size' => 40, 'required' => true), array('type' => 'hidden', 'name' => 'id_warehouse', 'required' => true));
     }
     // Show area (level1) and select active/inactive
     // If we re on an create area (lvl1) --> set used variables by helperform on home (force to create a new area)
     if (Tools::getValue('id_parent') == '' && Tools::getValue('id_zone_parent') == '') {
         $_GET['zone_name'] = 'Accueil';
         $_GET['id_parent'] = '0';
     }
     $areaAndActive = array(array('type' => 'text', 'label' => $this->l('Parent zone'), 'name' => 'zone_name', 'disabled' => true, 'size' => 40, 'required' => true), array('type' => 'hidden', 'name' => 'id_parent', 'required' => true), array('type' => $this->is_1_6 ? 'switch' : 'radio', 'label' => $this->l('Enable:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))));
     // full form
     $this->fields_form = array('legend' => array('title' => $this->l('Add or edit an area'), 'image' => '../img/admin/suppliers.gif'), 'input' => array_merge($base, $warehouse, $areaAndActive), 'submit' => array('title' => $this->l('   Save   ')));
     return parent::renderForm();
 }
 public function postProcess()
 {
     // Warehouse
     $warehouses = Warehouse::getWarehouses(true);
     // if we already pick a warehouse source and location, we filter on twice to not display selections of the other
     if (Tools::isSubmit('warehouseA') && Tools::getValue('warehouseA') != -1 && Tools::isSubmit('warehouseB') && Tools::getValue('warehouseB') != -1) {
         $warehouseA = Tools::getValue('warehouseA');
         $warehouseB = Tools::getValue('warehouseB');
         $warehousesA = array();
         $warehousesB = array();
         foreach ($warehouses as $warehouse) {
             if ($warehouse['id_warehouse'] != $warehouseA) {
                 array_push($warehousesB, $warehouse);
             }
             if ($warehouse['id_warehouse'] != $warehouseB) {
                 array_push($warehousesA, $warehouse);
             }
         }
     } elseif (Tools::isSubmit('warehouseA') && Tools::getValue('warehouseA') != -1) {
         $warehouseA = Tools::getValue('warehouseA');
         $warehousesB = array();
         foreach ($warehouses as $warehouse) {
             if ($warehouse['id_warehouse'] != $warehouseA) {
                 array_push($warehousesB, $warehouse);
             }
         }
         $warehousesA = $warehouses;
         // Restaure B list on no selection
         $this->context->smarty->assign(array('warehouseB' => -1));
     } elseif (Tools::isSubmit('warehouseB') && Tools::getValue('warehouseB') != -1) {
         $warehouseB = Tools::getValue('warehouseB');
         $warehousesA = array();
         foreach ($warehouses as $warehouse) {
             if ($warehouse['id_warehouse'] != $warehouseB) {
                 array_push($warehousesA, $warehouse);
             }
         }
         $warehousesB = $warehouses;
     } else {
         $warehousesA = $warehouses;
         $warehousesB = $warehouses;
     }
     // validate_transfer
     if (Tools::isSubmit('validate_transfer')) {
         $transfer_ok = false;
         if (Tools::isSubmit('id_stockA') && Tools::isSubmit('id_stockB') && Tools::isSubmit('id_employee') && Tools::isSubmit('firstname') && Tools::isSubmit('lastname') && Tools::isSubmit('values')) {
             // After transfert, delete cookies to get a blank display
             if (Tools::isSubmit('deleteCookie')) {
                 $cookie = new Cookie('psAdmin');
                 $cookie->warehouseA = '';
                 $cookie->warehouseB = '';
             }
             /*  Initialisation */
             $ids_mvt = array();
             // Call the helper "traducteur" of the chain transfert
             require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/helpers/StockTransferHelper.php';
             require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpStock.php';
             $values = StockTransferHelper::getTransfertDataAsArray(Tools::getValue('values'));
             /* For each movement recorded */
             foreach ($values as $value) {
                 $id_product = $value['id_product'];
                 $id_product_attribute = $value['id_product_attribute'];
                 $transfer_quantity = $value['quantity'];
                 $id_stock_s1 = $value['id_stock_s1'];
                 $id_stock_s2 = $value['id_stock_s2'];
                 if (empty($id_stock_s1)) {
                     $this->errors[] = 'Error while updating the stock for a product : stock id missing !';
                     return true;
                 }
                 // update stock un warehouse A (source)
                 $stock = new ErpStock((int) $id_stock_s1);
                 $stock->physical_quantity -= $transfer_quantity;
                 $stock->usable_quantity -= $transfer_quantity;
                 if ($stock->physical_quantity < 0) {
                     $stock->physical_quantity = 0;
                 }
                 if ($stock->usable_quantity < 0) {
                     $stock->usable_quantity = 0;
                 }
                 /*  Update Stock */
                 if ($stock->update()) {
                     /*  Movment A to B */
                     $stock_mvt = new ErpStockMvt();
                     $stock_mvt->id_stock = $stock->id;
                     $stock_mvt->id_order = 0;
                     $stock_mvt->id_supply_order = 0;
                     $stock_mvt->id_stock_mvt_reason = 6;
                     $stock_mvt->id_employee = Tools::getValue('id_employee');
                     $stock_mvt->employee_firstname = Tools::getValue('firstname');
                     $stock_mvt->employee_lastname = Tools::getValue('lastname');
                     $stock_mvt->price_te = $stock->getPriceTe();
                     $stock_mvt->current_wa = $stock->getPriceTe();
                     $stock_mvt->sign = -1;
                     $stock_mvt->physical_quantity = $transfer_quantity;
                     // if movment OK, update stock in B warehouse (location)
                     if ($stock_mvt->add(true)) {
                         // add id movment stock generated (useful to generate the warehouse delivery notice)
                         array_push($ids_mvt, $stock_mvt->getLastId());
                         if ((int) $id_stock_s2 > 0) {
                             $stock_s2 = new ErpStock((int) $id_stock_s2);
                             $stock_s2->physical_quantity += $transfer_quantity;
                             $stock_s2->usable_quantity += $transfer_quantity;
                         } else {
                             require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/ErpProduct.php';
                             //get product information
                             $product_stock = new ProductCore((int) $id_product, (int) $id_product_attribute);
                             // stock not existe we add row in stock table
                             $stock_s2 = new ErpStock();
                             $stock_s2->physical_quantity += $transfer_quantity;
                             $stock_s2->usable_quantity += $transfer_quantity;
                             $stock_s2->id_product = (int) $id_product;
                             $stock_s2->id_product_attribute = (int) $id_product_attribute;
                             $stock_s2->id_warehouse = (int) Tools::getValue('id_stockB');
                             $stock_s2->price_te = $product_stock->wholesale_price;
                             $stock_s2->ean13 = $product_stock->ean13;
                             $stock_s2->upc = $product_stock->upc;
                         }
                         /*  of OK, movment from B to A */
                         if ($stock_s2->save()) {
                             $stock_mvt->id_stock = $stock_s2->id;
                             $stock_mvt->id_stock_mvt_reason = 7;
                             $stock_mvt->sign = 1;
                             // add id movment stock generated (useful to generate warehouse inter delivery)
                             if ($stock_mvt->add(true)) {
                                 array_push($ids_mvt, $stock_mvt->getLastId());
                             } else {
                                 $this->errors[] = 'Error while updating the stock for a product';
                             }
                         } else {
                             $this->errors[] = 'Error while updating the stock for a product';
                         }
                     } else {
                         $this->errors[] = 'Error while updating the stock for a product';
                     }
                 } else {
                     $this->errors[] = 'Error while updating the stock for a product';
                 }
                 // synchronize availbale stock ::quantity
                 StockAvailable::synchronize($id_product);
             }
             $ids_mvt = implode('|', $ids_mvt);
             // we reset values
             $transfer_ok = true;
         }
     }
     // transfer is ok, we redirect the user to home page of transfer
     if (Tools::isSubmit('validate_transfer') && isset($transfer_ok) && $transfer_ok) {
         $url_redirect = self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminStockTransfer');
         $url_redirect .= '&validate_transfer&ids_mvt=' . $ids_mvt . '&ids_mvt_csv=' . Tools::getValue('ids_mvt_csv');
         $url_redirect .= '&id_warehouse_src=' . Tools::getValue('id_warehouse_src') . '&id_warehouse_dst=' . Tools::getValue('id_warehouse_dst');
         Tools::redirectAdmin($url_redirect);
     }
     if (Tools::isSubmit('ids_mvt_csv') && Tools::isSubmit('get_csv_transfer')) {
         $this->renderCSV();
     }
     // Generate PDF of tranfert
     if (Tools::isSubmit('ids_mvt') && Tools::isSubmit('action') && Tools::getValue('action') == 'generateTransferPDF') {
         $this->processGenerateTransferPDF();
     }
     // to get erp feature list
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     // send warehouse liste to template
     $this->context->smarty->assign(array('warehousesA' => $warehousesA, 'warehousesB' => $warehousesB, 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'suppliers' => Supplier::getSuppliers(), 'manufacturers' => Manufacturer::getManufacturers(), 'id_category' => -1, 'id_supplier' => -1, 'id_manufacturer' => -1, 'name_or_ean' => '', 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
 }
 /**
  * AdminController::renderForm() override
  * @see AdminController::renderForm()
  */
 public function renderForm()
 {
     if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitUpdatesupply_order')) {
         if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('submitAddsupply_order')) {
             $this->toolbar_title = $this->l('Stock: Create a new supply order');
         }
         $update = false;
         if (Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitUpdatesupply_order')) {
             $this->toolbar_title = $this->l('Stock: Manage supply orders');
             $update = true;
         }
         if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) {
             $this->toolbar_title .= ' (' . $this->l('template') . ')';
         }
         $this->addJqueryUI('ui.datepicker');
         //get warehouses list
         $warehouses = Warehouse::getWarehouses(true);
         // displays warning if there are no warehouses
         if (!$warehouses) {
             $this->displayWarning($this->l('You must have at least one warehouse. See Stock/Warehouses'));
         }
         //get currencies list
         $currencies = Currency::getCurrencies(false, true, true);
         //get suppliers list
         $suppliers = array_unique(Supplier::getSuppliers(), SORT_REGULAR);
         //get languages list
         $languages = Language::getLanguages(true);
         $this->fields_form = array('legend' => array('title' => $this->l('Order information'), 'icon' => 'icon-pencil'), 'input' => array(array('type' => 'text', 'label' => $this->l('Reference'), 'name' => 'reference', 'required' => true, 'hint' => $this->l('The reference number for your order.')), array('type' => 'select', 'label' => $this->l('Supplier'), 'name' => 'id_supplier', 'required' => true, 'options' => array('query' => $suppliers, 'id' => 'id_supplier', 'name' => 'name'), 'hint' => array($this->l('Select the supplier you\'ll be purchasing from.'), $this->l('Warning: All products already added to the order will be removed.'))), array('type' => 'select', 'label' => $this->l('Warehouse'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses, 'id' => 'id_warehouse', 'name' => 'name'), 'hint' => $this->l('Which warehouse will the order be sent to?')), array('type' => 'select', 'label' => $this->l('Currency'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'hint' => array($this->l('The currency of the order.'), $this->l('Warning: All products already added to the order will be removed.'))), array('type' => 'select', 'label' => $this->l('Order Language'), 'name' => 'id_lang', 'required' => true, 'options' => array('query' => $languages, 'id' => 'id_lang', 'name' => 'name'), 'hint' => $this->l('The language of the order.')), array('type' => 'text', 'label' => $this->l('Global discount percentage'), 'name' => 'discount_rate', 'required' => false, 'hint' => $this->l('This is the global discount percentage for the order.')), array('type' => 'text', 'label' => $this->l('Automatically load products'), 'name' => 'load_products', 'required' => false, 'hint' => array($this->l('This will reset the order.'), $this->l('If a value specified, each of your current product (from the selected supplier and warehouse) with a quantity lower than or equal to this value will be loaded. This means that PrestaShop will pre-fill this order with the products that are low on quantity.')))), 'submit' => !$update ? array('title' => $this->l('Save order')) : array(), 'buttons' => !$update ? array('save-and-stay' => array('title' => $this->l('Save order and stay'), 'name' => 'submitAddsupply_orderAndStay', 'type' => 'submit', 'class' => 'btn btn-default pull-right', 'icon' => 'process-icon-save')) : array());
         if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) {
             $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'is_template');
             $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'date_delivery_expected');
         } else {
             $this->fields_form['input'][] = array('type' => 'date', 'label' => $this->l('Expected delivery date'), 'name' => 'date_delivery_expected', 'required' => true, 'desc' => $this->l('The expected delivery date for this order is...'));
         }
         //specific discount display
         if (isset($this->object->discount_rate)) {
             $this->object->discount_rate = Tools::ps_round($this->object->discount_rate, 4);
         }
         //specific date display
         if (isset($this->object->date_delivery_expected)) {
             $date = explode(' ', $this->object->date_delivery_expected);
             if ($date) {
                 $this->object->date_delivery_expected = $date[0];
             }
         }
         $this->displayInformation($this->l('If you wish to order products, they have to be available for the specified supplier/warehouse.') . ' ' . $this->l('See Catalog/Products/[Your Product]/Suppliers & Warehouses.') . '<br />' . $this->l('Changing the currency or the supplier will reset the order.') . '<br />' . '<br />' . $this->l('Please note that you can only order from one supplier at a time.'));
         return parent::renderForm();
     }
 }
Esempio n. 12
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!$this->errors) {
         if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
             $this->product->quantity = 0;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         /* Получаем остатки по складам и передаем в Smarty 
          * TODO - вынести в отдельный модуль
          * TODO - если надо, добавить обработку атрибутов (товары, отличающиеся цветом, размером и т.д.)
          * TODO - real_quantity - количество, в котором есть будущие поставки. Если это не нужно, считать по-другому
          */
         $all_warehouses = Warehouse::getWarehouses(true);
         if ($all_warehouses) {
             $wh_stock = array();
             //ppp($all_warehouses);
             foreach ($all_warehouses as $warehouse) {
                 $id_warehouse = $warehouse['id_warehouse'];
                 $warehouse = new Warehouse($id_warehouse);
                 $manager = StockManagerFactory::getManager();
                 $real_quantity = $manager->getProductRealQuantities((int) $this->product->id, 0, $id_warehouse, true);
                 $wh_stock[$id_warehouse]['real_quantity'] = $real_quantity;
                 /*
                 ppp("остаток: ");
                 ppp($real_quantity);
                 */
                 $address = new Address($warehouse->id_address);
                 $wh_stock[$id_warehouse]['country'] = $address->country;
                 $wh_stock[$id_warehouse]['address1'] = $address->address1;
                 $wh_stock[$id_warehouse]['address2'] = $address->address2;
                 $wh_stock[$id_warehouse]['postcode'] = $address->postcode;
                 $wh_stock[$id_warehouse]['city'] = $address->city;
                 $wh_stock[$id_warehouse]['phone'] = $address->phone;
                 //ppp($address);
             }
             $this->context->smarty->assign('wh_stock', $wh_stock);
         }
         /* Конец получения остатков по складам */
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } else {
             if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
             }
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE')));
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }
Esempio n. 13
0
 public static function synchronize($id_product, $order_id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     if (Pack::isPack($id_product)) {
         if (Validate::isLoadedObject($product = new Product((int) $id_product))) {
             if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
                 $products_pack = Pack::getItems($id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
                 foreach ($products_pack as $product_pack) {
                     StockAvailable::synchronize($product_pack->id, $order_id_shop);
                 }
             }
         } else {
             return false;
         }
     }
     $ids_warehouse = Warehouse::getWarehousesGroupedByShops();
     if ($order_id_shop !== null) {
         $order_warehouses = array();
         $wh = Warehouse::getWarehouses(false, (int) $order_id_shop);
         foreach ($wh as $warehouse) {
             $order_warehouses[] = $warehouse['id_warehouse'];
         }
     }
     $ids_product_attribute = array();
     foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute) {
         $ids_product_attribute[] = $id_product_attribute['id_product_attribute'];
     }
     $out_of_stock = StockAvailable::outOfStock($id_product);
     $manager = StockManagerFactory::getManager();
     foreach ($ids_warehouse as $id_shop => $warehouses) {
         if (StockAvailable::dependsOnStock($id_product, $id_shop)) {
             $product_quantity = 0;
             if (empty($ids_product_attribute)) {
                 $allowed_warehouse_for_product = WareHouse::getProductWarehouseList((int) $id_product, 0, (int) $id_shop);
                 $allowed_warehouse_for_product_clean = array();
                 foreach ($allowed_warehouse_for_product as $warehouse) {
                     $allowed_warehouse_for_product_clean[] = (int) $warehouse['id_warehouse'];
                 }
                 $allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
                 if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
                     continue;
                 }
                 $product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
                 Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => 0, 'quantity' => $product_quantity));
             } else {
                 foreach ($ids_product_attribute as $id_product_attribute) {
                     $allowed_warehouse_for_combination = WareHouse::getProductWarehouseList((int) $id_product, (int) $id_product_attribute, (int) $id_shop);
                     $allowed_warehouse_for_combination_clean = array();
                     foreach ($allowed_warehouse_for_combination as $warehouse) {
                         $allowed_warehouse_for_combination_clean[] = (int) $warehouse['id_warehouse'];
                     }
                     $allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
                     if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
                         continue;
                     }
                     $quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
                     $query = new DbQuery();
                     $query->select('COUNT(*)');
                     $query->from('stock_available');
                     $query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
                     if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
                         $query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
                         Db::getInstance()->update($query['table'], $query['data'], $query['where']);
                     } else {
                         $query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array('depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute), 'quantity', $quantity));
                         StockAvailable::addSqlShopParams($query['data']);
                         Db::getInstance()->insert($query['table'], $query['data']);
                     }
                     $product_quantity += $quantity;
                     Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
                 }
             }
             $query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $id_shop));
             Db::getInstance()->update($query['table'], $query['data'], $query['where']);
         }
     }
     if (count($ids_warehouse) == 0 && StockAvailable::dependsOnStock((int) $id_product)) {
         Db::getInstance()->update('stock_available', array('quantity' => 0, 'quantity_remainder' => 0), 'id_product = ' . (int) $id_product);
     }
     Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*');
 }
    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;
    }
 public function renderDetails()
 {
     if (Tools::isSubmit('id_product')) {
         // override attributes
         $this->identifier = 'id_product_attribute';
         $this->list_id = 'product_attribute';
         $this->lang = false;
         $this->addRowAction('addstock');
         $this->addRowAction('removestock');
         if (count(Warehouse::getWarehouses()) > 1) {
             $this->addRowAction('transferstock');
         }
         // no link on list rows
         $this->list_no_link = true;
         // inits toolbar
         $this->toolbar_btn = array();
         // get current lang id
         $lang_id = (int) $this->context->language->id;
         // Get product id
         $product_id = (int) Tools::getValue('id_product');
         // Load product attributes with sql override
         $this->table = 'product_attribute';
         $this->list_id = 'product_attribute';
         $this->_select = 'a.id_product_attribute as id, a.id_product, a.reference, a.ean13, a.upc';
         $this->_where = 'AND a.id_product = ' . $product_id;
         $this->_group = 'GROUP BY a.id_product_attribute';
         $this->fields_list = array('reference' => array('title' => $this->l('Product reference'), 'filter_key' => 'a!reference'), 'ean13' => array('title' => $this->l('EAN-13 or JAN barcode'), 'filter_key' => 'a!ean13'), 'upc' => array('title' => $this->l('UPC barcode'), 'filter_key' => 'a!upc'), 'name' => array('title' => $this->l('Name'), 'orderby' => false, 'filter' => false, 'search' => false), 'stock' => array('title' => $this->l('Quantity'), 'orderby' => false, 'filter' => false, 'search' => false, 'class' => 'fixed-width-sm', 'align' => 'center', 'hint' => $this->l('Quantitity total for all warehouses.')));
         self::$currentIndex = self::$currentIndex . '&id_product=' . (int) $product_id . '&detailsproduct';
         $this->processFilter();
         return parent::renderList();
     }
 }
 /**
  * AdminController::initContent() override
  * @see AdminController::initContent()
  */
 public function initContent()
 {
     $this->addJqueryUI('ui.dialog');
     $this->addjqueryPlugin('cluetip');
     $this->addJqueryUI('ui.datepicker');
     $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/advanced_supply_order.js');
     $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/advanced_supply_order_tools.js');
     if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
         $this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You need to activate advanced stock management prior to using this feature. (Preferences/Products/Products Stock)');
         return false;
     }
     // displays warning if there are no warehouses
     if (!Warehouse::getWarehouses(true)) {
         $this->warnings[md5('PS_ADVANCED_STOCK_MANAGEMENT')] = $this->l('You must have at least one warehouse. See Stock/Warehouses');
         return false;
     }
     // Manage the add stock form
     if (Tools::isSubmit('changestate')) {
         $this->initChangeStateContent();
     } elseif (Tools::isSubmit('update_receipt') && Tools::isSubmit('id_supply_order')) {
         $this->initUpdateReceiptContent();
     } elseif (Tools::isSubmit('viewsupply_order') && Tools::isSubmit('id_supply_order')) {
         $this->action = 'view';
         $this->display = 'view';
         parent::initContent();
     } elseif (Tools::isSubmit('updatesupply_order')) {
         $this->initUpdateSupplyOrderContent();
     } else {
         parent::initContent();
     }
 }
 public function initSimulateContent()
 {
     $this->show_toolbar = false;
     // change the display type in order to add specific actions to
     $this->display = 'simulate';
     if ($this->is_1_6) {
         $this->initPageHeaderToolbar();
     }
     $this->initToolbar();
     $result = $this->renderProductSimulationList();
     $this->context->smarty->assign(array('content' => $result['content'], 'nbr_commande_genere' => $result['nbr_commande_genere'], 'show_toolbar ' => 'true', 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->l('1 Click ERP ILLICOPRESTA'), 'toolbar_scroll' => $this->toolbar_scroll, 'token' => $this->token, 'warehouses' => Warehouse::getWarehouses(true), 'id_default_currency' => Configuration::get('PS_CURRENCY_DEFAULT'), 'current_date' => date('Y-m-d'), 'url_post' => self::$currentIndex . '&token=' . $this->token, 'url_post_ordering' => $this->context->link->getAdminLink('AdminGenerateSupplyOrders') . '&submitOrdering'));
     $this->createTemplate('simulate.tpl');
     $this->template = 'simulate.tpl';
 }
 /**
  * AdminController::renderForm() override
  * @see AdminController::renderForm()
  */
 public function renderForm()
 {
     if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitUpdatesupply_order')) {
         if (Tools::isSubmit('addsupply_order') || Tools::isSubmit('submitAddsupply_order')) {
             $this->toolbar_title = $this->l('Stock: Create a new supply order');
         }
         if (Tools::isSubmit('updatesupply_order') || Tools::isSubmit('submitUpdatesupply_order')) {
             $this->toolbar_title = $this->l('Stock: Manage supply orders');
         }
         if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) {
             $this->toolbar_title .= ' (' . $this->l('template') . ')';
         }
         $this->addJqueryUI('ui.datepicker');
         //get warehouses list
         $warehouses = Warehouse::getWarehouses(true);
         // displays warning if there are no warehouses
         if (!$warehouses) {
             $this->displayWarning($this->l('You must have at least one warehouse. See Stock/Warehouses'));
         }
         //get currencies list
         $currencies = Currency::getCurrencies();
         $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT');
         $default_currency = Currency::getCurrency($id_default_currency);
         if ($default_currency) {
             $currencies = array_merge(array($default_currency, '-'), $currencies);
         }
         //get suppliers list
         $suppliers = Supplier::getSuppliers();
         //get languages list
         $languages = Language::getLanguages(true);
         $id_default_lang = Configuration::get('PS_LANG_DEFAULT');
         $default_lang = Language::getLanguage($id_default_lang);
         if ($default_lang) {
             $languages = array_merge(array($default_lang, '-'), $languages);
         }
         $this->fields_form = array('legend' => array('title' => $this->l('Order information'), 'image' => '../img/admin/edit.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Reference:'), 'name' => 'reference', 'size' => 50, 'required' => true, 'desc' => $this->l('Here\'s the reference number for your order.')), array('type' => 'select', 'label' => $this->l('Supplier:'), 'name' => 'id_supplier', 'required' => true, 'options' => array('query' => $suppliers, 'id' => 'id_supplier', 'name' => 'name'), 'desc' => $this->l('Select the supplier you\'ll be purchasing from.'), 'hint' => $this->l('Warning: All products already added to the order will be removed.')), array('type' => 'select', 'label' => $this->l('Warehouse:'), 'name' => 'id_warehouse', 'required' => true, 'options' => array('query' => $warehouses, 'id' => 'id_warehouse', 'name' => 'name'), 'desc' => $this->l('Which warehouse will the order be sent to?')), array('type' => 'select', 'label' => $this->l('Currency:'), 'name' => 'id_currency', 'required' => true, 'options' => array('query' => $currencies, 'id' => 'id_currency', 'name' => 'name'), 'desc' => $this->l('The currency of the order.'), 'hint' => $this->l('Warning: All products already added to the order will be removed.')), array('type' => 'select', 'label' => $this->l('Order Language:'), 'name' => 'id_lang', 'required' => true, 'options' => array('query' => $languages, 'id' => 'id_lang', 'name' => 'name'), 'desc' => $this->l('The language of the order.')), array('type' => 'text', 'label' => $this->l('Global discount rate (%):'), 'name' => 'discount_rate', 'size' => 10, 'required' => true, 'desc' => $this->l('This is the global discount rate in percent for the order.')), array('type' => 'text', 'label' => $this->l('Automatically load products:'), 'name' => 'load_products', 'size' => 10, 'required' => false, 'hint' => $this->l('This will reset the order'), 'desc' => $this->l('If specified, each product quantity less than or equal to this value will be loaded.'))), 'submit' => array('title' => $this->l('Save order')));
         if (Tools::isSubmit('mod') && Tools::getValue('mod') === 'template' || $this->object->is_template) {
             $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'is_template');
             $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'date_delivery_expected');
         } else {
             $this->fields_form['input'][] = array('type' => 'date', 'label' => $this->l('Expected delivery date:'), 'name' => 'date_delivery_expected', 'size' => 10, 'required' => true, 'desc' => $this->l('The expected delivery date for this order is...'));
         }
         //specific discount display
         if (isset($this->object->discount_rate)) {
             $this->object->discount_rate = Tools::ps_round($this->object->discount_rate, 4);
         }
         //specific date display
         if (isset($this->object->date_delivery_expected)) {
             $date = explode(' ', $this->object->date_delivery_expected);
             if ($date) {
                 $this->object->date_delivery_expected = $date[0];
             }
         }
         $this->displayInformation($this->l('If you wish to order products, they have to be available for the specified supplier/warehouse.') . ' ' . $this->l('See Catalog/Products/Your Product/Suppliers & Warehouses') . '<br />' . $this->l('Changing the currency or the supplier will reset the order.') . '<br />' . '<br />' . $this->l('Please note that you can only order from one supplier at a time.'));
         return parent::renderForm();
     }
 }
Esempio n. 19
0
 /**
  * For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity
  *
  * @param int $id_product
  */
 public static function synchronize($id_product, $order_id_shop = null)
 {
     if (!Validate::isUnsignedId($id_product)) {
         return false;
     }
     // gets warehouse ids grouped by shops
     $ids_warehouse = Warehouse::getWarehousesGroupedByShops();
     if ($order_id_shop !== null) {
         $order_warehouses = array();
         $wh = Warehouse::getWarehouses(false, (int) $order_id_shop);
         foreach ($wh as $warehouse) {
             $order_warehouses[] = $warehouse['id_warehouse'];
         }
     }
     // gets all product attributes ids
     $ids_product_attribute = array();
     foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute) {
         $ids_product_attribute[] = $id_product_attribute['id_product_attribute'];
     }
     // Allow to order the product when out of stock?
     $out_of_stock = StockAvailable::outOfStock($id_product);
     $manager = StockManagerFactory::getManager();
     // loops on $ids_warehouse to synchronize quantities
     foreach ($ids_warehouse as $id_shop => $warehouses) {
         // first, checks if the product depends on stock for the given shop $id_shop
         if (StockAvailable::dependsOnStock($id_product, $id_shop)) {
             // init quantity
             $product_quantity = 0;
             // if it's a simple product
             if (empty($ids_product_attribute)) {
                 $allowed_warehouse_for_product = WareHouse::getProductWarehouseList((int) $id_product, 0, (int) $id_shop);
                 $allowed_warehouse_for_product_clean = array();
                 foreach ($allowed_warehouse_for_product as $warehouse) {
                     $allowed_warehouse_for_product_clean[] = (int) $warehouse['id_warehouse'];
                 }
                 $allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
                 if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
                     continue;
                 }
                 $product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
             } else {
                 foreach ($ids_product_attribute as $id_product_attribute) {
                     $allowed_warehouse_for_combination = WareHouse::getProductWarehouseList((int) $id_product, (int) $id_product_attribute, (int) $id_shop);
                     $allowed_warehouse_for_combination_clean = array();
                     foreach ($allowed_warehouse_for_combination as $warehouse) {
                         $allowed_warehouse_for_combination_clean[] = (int) $warehouse['id_warehouse'];
                     }
                     $allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
                     if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
                         continue;
                     }
                     $quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
                     $query = new DbQuery();
                     $query->select('COUNT(*)');
                     $query->from('stock_available');
                     $query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
                     if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
                         $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
                         Db::getInstance()->update($query['table'], $query['data'], $query['where']);
                     } else {
                         $query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity, 'depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute));
                         StockAvailable::addSqlShopParams($query['data']);
                         Db::getInstance()->insert($query['table'], $query['data']);
                     }
                     $product_quantity += $quantity;
                     Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
                 }
             }
             // updates
             // if $id_product has attributes, it also updates the sum for all attributes
             $query = array('table' => 'stock_available', 'data' => array('quantity' => $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $id_shop));
             Db::getInstance()->update($query['table'], $query['data'], $query['where']);
         }
     }
     // In case there are no warehouses, removes product from StockAvailable
     if (count($ids_warehouse) == 0) {
         Db::getInstance()->update('stock_available', array('quantity' => 0), 'id_product = ' . (int) $id_product);
     }
 }
    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;
    }