public function ajaxGetProductsForSupplyOrder()
    {
        require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpSupplyOrderClasses.php';
        require_once _PS_MODULE_DIR_ . 'erpillicopresta/erpillicopresta.php';
        /* manage advanced stock */
        $stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
        $sales_forecast_type = Configuration::get('ERP_SALES_FORECAST_CHOICE');
        $id_supplier = (int) Tools::getValue('id_supplier', false);
        $id_currency = (int) Tools::getValue('id_currency', false);
        $id_categorie = (int) Tools::getValue('id_categorie', false);
        $id_manufacturer = (int) Tools::getValue('id_manufacturer', false);
        $id_warehouse = (int) Tools::getValue('id_warehouse', null);
        $existing_ids = Tools::getValue('ids');
        //$token_get_product      = Tools::getValue('token');
        $products = ErpSupplyOrderClasses::searchProduct($id_supplier, $id_categorie, $id_manufacturer, $id_currency);
        if (!empty($products)) {
            $advanced_stock_token = Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $this->context->employee->id);
            foreach ($products as $product) {
                // If product already in destination array, continue
                if (strrpos($existing_ids, $product['id']) !== false) {
                    continue;
                }
                $ids = explode('_', $product['id']);
                $id_product = $ids[0];
                $id_product_attribute = $ids[1];
                // If the advanced stock manager is activated
                if ($stock_management_active == '1') {
                    // Get the physical and usable quantities
                    $query = new DbQuery();
                    $query->select('physical_quantity');
                    $query->select('usable_quantity');
                    $query->from('stock');
                    $query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute);
                    $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
                    /* the two quantities */
                    $physical_quantity = (int) $res['physical_quantity'];
                    $usable_quantity = (int) $res['usable_quantity'];
                    // The real quantity depends of the warehouse
                    $manager = StockManagerFactory::getManager();
                    $product['stock'] = $real_quantity = (int) $manager->getProductRealQuantities($id_product, $id_product_attribute, $id_warehouse, true);
                } else {
                    // get the free quantities
                    $product['stock'] = $usable_quantity = (int) Product::getQuantity($id_product, $id_product_attribute);
                }
                /*  TAX */
                /*  Get the current tax */
                $query = new DbQuery();
                $query->select('rate');
                $query->from('tax', 't');
                $query->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax');
                $query->innerJoin('product', 'p', 'p.id_tax_rules_group = tr.id_tax_rules_group');
                $query->where('p.id_product = ' . (int) $id_product);
                $query->where('tr.id_country IN (SELECT id_country
                                                FROM ' . _DB_PREFIX_ . 'address
                                                WHERE id_supplier = ' . (int) $id_supplier . ')');
                $product['tax_rate'] = round(Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query), 1);
                $prices = ErpSupplyOrderClasses::getWholesalePrice((int) $id_product, (int) $id_product_attribute, (int) $id_supplier);
                $product['unit_price_te'] = Tools::convertPriceFull($prices, new Currency((int) $id_currency));
                // sales quantity for X rolling month
                $quantity_sales = ErpSupplyOrderClasses::getQuantitySales((int) $id_product, (int) $id_product_attribute);
                // if sale forecast is activ
                if ($sales_forecast_type != 0) {
                    // if we use the 6 month rolling method
                    if ($sales_forecast_type == 1) {
                        $sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecasts($id_product, $id_product_attribute), 1);
                    } else {
                        $sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecastsByPeriod($id_product, $id_product_attribute), 1);
                    }
                } else {
                    $sales_forecasts = 'NA';
                }
                // Sales gain
                $sales_gains = ErpSupplyOrderClasses::getProductSalesGains($id_product, $id_product_attribute);
                // Prepare the hidden json foreach line
                $product['comment'] = '';
                $product_json = Tools::jsonEncode($product);
                echo '<tr>
                                        <td class="product_json hide">' . $product_json . '</td>
                                        <td><input type="checkbox" class="select_product" name="select_product"/></td>
                                        <td>' . $product['supplier_reference'] . '</td>
                                        <td>' . $product['reference'] . '</td>
                                        <td>
                                                         <a href="#" class="cluetip-supply-price" title="' . $this->l('Supplier Price') . '"
                                                                                        rel="index.php?controller=AdminAdvancedStock&ajax=1&id_product=' . $id_product . '&id_product_attribute=' . $id_product_attribute . '&id_currency=' . $id_currency . '&task=getProductSupplierPrice&token=' . $advanced_stock_token . '" >
                                                                                                                           <img src="themes/default/img/icon-search.png">
                                                        </a>
                                                        ' . $product['name'] . '
                                        </td>';
                if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
                    echo '<td align="center"> <p style="background-color:' . ErpSupplyOrderClasses::getStockLevelColor($real_quantity) . '; width:16px; height:16px"></p> </td>';
                }
                echo '<td align="center">' . $usable_quantity . '</td>
                                        ' . ($stock_management_active == '1' ? '
                                                                        <td align="center">' . $physical_quantity . '</td>
                                                                        <td align="center">' . $real_quantity . '</td>' : '') . '';
                if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
                    echo '<td align="center">' . $quantity_sales . '</td>
                                                <td align="center">' . $sales_gains . '</td>';
                    if (Configuration::get('ERP_SALES_FORECAST_CHOICE') != 0) {
                        echo '<td>' . $sales_forecasts . '</td>';
                    }
                }
                echo '<td align="center"><input type="text" class="quantity_ordered" size="2" /></td>
                                        <td align="center"> <input type="text" name="comment" class="comment"/></td>
                                        
				</tr>';
            }
        } else {
            echo '<div class="list-empty-msg">
				<i class="icon-warning-sign list-empty-icon"></i>
				' . $this->l('No product found !') . '
			</div>';
        }
    }
 public function gestockLevelColor($real_quantity)
 {
     return '<span class="stock_level_color" style="background-color:' . ErpSupplyOrderClasses::getStockLevelColor($real_quantity) . '"></span> ';
 }
 public function processGenerateSupplyOrderFormPDF()
 {
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/pdf/HTMLTemplateErpSupplyOrderForm.php';
     // generate multiple supply order PDF
     if (Tools::isSubmit('print_pdf_bulk')) {
         $supply_order_collection = array();
         foreach (explode(',', Tools::getValue('supply_order_created')) as $id_supply_order) {
             if (is_array($supply_order = ErpSupplyOrderClasses::getSupplyOrderCollection((int) $id_supply_order))) {
                 $supply_order_collection = array_merge($supply_order, $supply_order_collection);
             }
         }
         if (!count($supply_order_collection)) {
             die($this->errors[] = Tools::displayError('No supply order was found.'));
         }
         //$this->generatePDF( $supply_order_collection , PDF::TEMPLATE_SUPPLY_ORDER_FORM);
         $pdf = new PDF($supply_order_collection, 'ErpSupplyOrderForm', Context::getContext()->smarty);
         $pdf->render();
     }
 }