public function __construct()
 {
     $this->bootstrap = true;
     $this->table = 'order';
     $this->className = 'Order';
     $this->lang = false;
     $this->addRowAction('view');
     $this->context = Context::getContext();
     $this->list_no_link = true;
     $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0;
     // status à appliquer
     $this->generate_order_state = Configuration::get('ERP_GENERATE_ORDER_STATE');
     $this->generate_order_state_to = Configuration::get('ERP_GENERATE_ORDER_STATE_TO');
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->override_folder = $this->template_path;
     // build query
     $this->_select = 'a.id_order as checkbox,a.id_order as action, CONCAT(c.`firstname`, \' \', c.`lastname`) AS `customer`, c.`email`';
     $this->_where = 'AND a.current_state = ' . (int) $this->generate_order_state;
     $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`) ';
     $this->_orderBy = 'id_order';
     $this->_orderWay = 'DESC';
     $this->fields_list = array('checkbox' => array('title' => $this->l('Choice'), 'align' => 'center', 'width' => 25, 'havingFilter' => 'false', 'orderby' => false, 'search' => false, 'callback' => 'isOrderSelected'), 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'customer' => array('title' => $this->l('Customer name'), 'havingFilter' => true), 'email' => array('title' => $this->l('Email'), 'havingFilter' => true), 'total_products' => array('title' => $this->l('Total TE without shipping'), 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true), 'total_shipping_tax_incl' => array('title' => $this->l('Shipping'), 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true));
     parent::__construct();
     $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     // send var to template
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code)));
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
 }
 public function __construct()
 {
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
     parent::__construct();
     $this->bootstrap = true;
     // Base columns
     $this->baseColumns = array('ids' => array('title' => $this->l('#'), 'width' => 20, 'search' => false, 'class' => 'ids'), 'EAN' => array('title' => 'EAN', 'width' => 100, 'search' => false, 'havingFilter' => true), 'name' => array('title' => $this->l('Name'), 'align' => 'left', 'width' => 200, 'search' => false, 'havingFilter' => true), 'physical_quantity' => array('title' => $this->l('Physical quantity'), 'width' => 50, 'align' => 'center', 'search' => false, 'class' => 'physical_quantity text-center'), 'usable_quantity' => array('title' => $this->l('Usable quantity'), 'width' => 50, 'align' => 'center', 'search' => false, 'class' => 'usable_quantity text-center'));
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
     $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0;
     $this->context->smarty->assign(array('transfers' => ''));
     // message to downloas file after transfer
     if (Tools::isSubmit('validate_transfer') && (Tools::isSubmit('ids_mvt') || Tools::isSubmit('ids_mvt_csv'))) {
         $link = new Link();
         $link = $link->getAdminLink("AdminStockTransfer", true);
         if (Tools::isSubmit('ids_mvt')) {
             $ids_mvt = Tools::getValue('ids_mvt');
             if (!empty($ids_mvt)) {
                 $url_get_pdf = $link . '&action=generateTransferPDF&ids_mvt=' . $ids_mvt;
                 $url_get_pdf .= '&stockA=' . Tools::getValue('id_warehouse_src') . '&stockB=' . Tools::getValue('id_warehouse_dst');
                 $this->confirmations[] = $this->l('The stock has been transferred successfully.') . '' . '<br/>&nbsp;<a href="' . $url_get_pdf . '">' . '<b>' . $this->l('Download PDF transfer') . '</b></a>';
             }
         }
         if (Tools::isSubmit('ids_mvt_csv')) {
             $ids_mvt_csv = Tools::getValue('ids_mvt_csv');
             $url_get_csv = $link . '&get_csv_transfer&ids_mvt_csv=' . $ids_mvt_csv;
             $url_get_csv .= '&id_warehouse_src=' . Tools::getValue('id_warehouse_src') . '&id_warehouse_dst=' . Tools::getValue('id_warehouse_dst');
             if (!empty($ids_mvt_csv)) {
                 $this->confirmations[] = '<br />&nbsp;<a target="_blank" href="' . $url_get_csv . '" alt="csv_file"><b>' . $this->l('Download CSV transfer') . '</b></a>';
             }
         }
     }
 }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->table = 'erpip_inventory_product';
     $this->className = 'InventoryProduct';
     $this->list_no_link = true;
     $this->id_container = Tools::isSubmit('id_container') ? Tools::getValue('id_container') : (int) ErpInventory::getFirstId();
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedStock'));
     parent::__construct();
     $this->fields_list = array('warehouse' => array('title' => $this->l('Warehouse')), 'id_product' => array('title' => $this->l('Id product')), 'id_product_attribute' => array('title' => $this->l('Id product attribute')), 'reference' => array('title' => $this->l('SKU')), 'first_supplier_ref' => array('title' => $this->l('Supplier references'), 'search' => false), 'product_name' => array('title' => $this->l('product name'), 'search' => false), 'qte_before' => array('title' => $this->l('Quantity before inventory')), 'qte_after' => array('title' => $this->l('Quantity after inventory')), 'reason' => array('title' => $this->l('Movement reason'), 'filter_key' => 'smrl!name'), 'gap' => array('title' => $this->l('Stock Gap'), 'search' => false));
 }
 public function __construct()
 {
     $this->bootstrap = true;
     $this->table = 'product';
     $this->className = 'Product';
     $this->list_no_link = true;
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     parent::__construct();
     // Get the stock manager type and send it to template
     $this->advanced_stock_management = $this->tpl_list_vars['advanced_stock_management'] = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminInventory'));
     $this->advanced_stock_token = Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $this->context->employee->id);
     $this->product_token = Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) $this->context->employee->id);
     $this->mvt_stock_reason = ErpStockMvtReason::getStockMvtReasons((int) $this->context->language->id);
     $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
     // JMA
     // Record get variables cookies id_warehouse, areaFilter and subareaFilter for Ajax
     if (!Tools::isSubmit('ajax')) {
         $this->setCookie('id_warehouse', Tools::isSubmit('id_warehouse') ? Tools::getValue('id_warehouse') : self::getFirstWarehouse());
         $this->setCookie('areaFilter', Tools::getValue('areaFilter'));
         $this->setCookie('subareaFilter', Tools::getValue('subareaFilter'));
     }
     // Buidl product array
     $global = array('id_product' => array('title' => 'ID', 'width' => 10, 'search' => false, 'class' => 'id_product'), 'picture' => array('title' => $this->l('Picture'), 'align' => 'center', 'image' => 'p', 'width' => 70, 'orderby' => false, 'filter' => false, 'search' => false), 'category_name' => array('title' => $this->l('Category'), 'search' => false, 'callback' => 'renderCategoryNameColumn'), 'reference' => array('title' => $this->l('SKU'), 'search' => false), 'first_supplier_ref' => array('title' => $this->l('Supplier reference'), 'search' => false, 'callback' => 'renderFirstSupplierRefColumn'), 'product_name' => array('title' => $this->l('Label'), 'search' => false, 'callback' => 'renderNameColumn'));
     // if advanced stock manager is inactif, only show the usable quantity in shop
     if (!$this->advanced_stock_management) {
         $quantity = array('quantity' => array('title' => $this->l('Quantity'), 'width' => 50, 'search' => false, 'class' => 'quantity', 'orderby' => false));
         $global = array_merge((array) $global, (array) $quantity);
     } else {
         $quantity = array('physical_quantity' => array('title' => $this->l('Physical quantity'), 'width' => 50, 'search' => false, 'class' => 'physical_quantity', 'orderby' => false), 'location' => array('title' => $this->l('Location'), 'width' => 200, 'search' => false, 'orderby' => false, 'callback' => 'renderLocationColumn'));
         $global = array_merge((array) $global, (array) $quantity);
     }
     $edit = array('mvt_reason' => array('title' => $this->l('Movement reason'), 'width' => 50, 'search' => false, 'orderby' => false, 'callback' => 'renderMvtReasonColumn'), 'new_quantity' => array('title' => $this->l('Found quantity'), 'width' => 50, 'hint' => $this->l('What you actually have'), 'search' => false, 'orderby' => false, 'callback' => 'renderColumnNewQuantity'));
     $this->fields_list = array_merge((array) $global, (array) $edit);
     // if we already have inventory values recorded, send them (pagination & filters)
     if (Tools::isSubmit('inventory_values') && Tools::getValue('inventory_values') != '') {
         $this->context->smarty->assign(array('inventory_values' => Tools::getValue('inventory_values')));
     } else {
         $this->context->smarty->assign(array('inventory_values' => ''));
     }
     // if we get stock gap values already recorded, send them (pagination & filters)
     if (Tools::isSubmit('gap_values') && Tools::getValue('gap_values') != '') {
         $this->context->smarty->assign(array('gap_values' => Tools::getValue('gap_values')));
     } else {
         $this->context->smarty->assign(array('gap_values' => ''));
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->bootstrap = true;
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0;
     // Get the type of active stock management and send to tpl
     $this->advanced_stock_management = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedStock'));
     $this->product_token = Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) $this->context->employee->id);
     $this->erp_zone_token = Tools::getAdminToken('AdminErpZone' . (int) Tab::getIdFromClassName('AdminErpZone') . (int) $this->context->employee->id);
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
 }
 public function __construct()
 {
     $this->table = 'supplier';
     $this->className = 'Supplier';
     $this->addRowAction('view');
     $this->addRowAction('edit');
     $this->addRowAction('delete');
     $this->allow_export = true;
     // template path for avdanced supply ordr
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
     $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selection'), 'confirm' => $this->l('Delete selected items?')));
     $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products, email';
     $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'product_supplier` ps ON (a.`id_supplier` = ps.`id_supplier`)';
     $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'erpip_supplier` es ON (a.`id_supplier` = es.`id_supplier`)';
     $this->_group = 'GROUP BY a.`id_supplier`';
     $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su');
     $this->fields_list = array('id_supplier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'logo' => array('title' => $this->l('Logo'), 'width' => 150, 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false), 'name' => array('title' => $this->l('Name'), 'width' => 'auto'), 'email' => array('title' => $this->l('Email'), 'width' => 'auto'), 'products' => array('title' => $this->l('Number of products'), 'width' => 70, 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true), 'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false));
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
     parent::__construct();
 }
 public function __construct()
 {
     $this->table = 'erpip_zone';
     $this->className = 'ErpZone';
     $this->lang = false;
     $this->context = Context::getContext();
     if (_PS_VERSION_ < 1.6) {
         $this->no_link = true;
     } else {
         $this->list_no_link = true;
     }
     $this->addRowAction('view');
     $this->addRowAction('edit');
     $this->addRowAction('delete');
     // template path
     $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
     $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selection'), 'confirm' => $this->l('Delete selected items?')));
     $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0;
     $this->_select = ' IFNULL(ez.name, \'' . $this->l('Home') . '\') as parent_name, w.name as warehouse_name, w.id_warehouse';
     $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'erpip_zone` as ez ON (ez.`id_erpip_zone` = a.`id_parent`)';
     $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'warehouse` as w ON (w.`id_warehouse` = a.`id_warehouse`)';
     if (Tools::isSubmit('id_erpip_zone') && (int) Tools::getValue('id_erpip_zone') > 0 || Tools::isSubmit('id_parent') && (int) Tools::getValue('id_parent') > 0) {
         $id_erpip_zone = (int) Tools::getValue('id_erpip_zone') > 0 ? (int) Tools::getValue('id_erpip_zone') : (int) Tools::getValue('id_parent');
         $this->_where .= ' AND a.id_parent = ' . $id_erpip_zone;
         $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA : ');
         $this->toolbar_title .= implode(' > ', array_reverse(ErpZone::getZoneBreadcrumbs($id_erpip_zone)));
     } else {
         $this->_where .= ' AND a.id_parent = 0';
         $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA : Home zones');
     }
     $this->fields_list = array('id_erpip_zone' => array('title' => $this->l('ID'), 'width' => '30', 'remove_onclick' => true), 'name' => array('title' => $this->l('Zone name'), 'width' => 'auto', 'filter_key' => 'a!name', 'remove_onclick' => true), 'parent_name' => array('title' => $this->l('Parent zone'), 'width' => 'auto', 'search' => false, 'remove_onclick' => true), 'warehouse_name' => array('title' => $this->l('Warehouse'), 'width' => 'auto', 'filter_key' => 'w!name', 'remove_onclick' => true), 'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'remove_onclick' => true));
     $this->context->smarty->assign(array('template_path' => $this->template_path, 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code)));
     // get controller status
     $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
     parent::__construct();
 }
    public function __construct()
    {
        $this->table = 'order';
        $this->className = 'Order';
        $this->lang = false;
        $this->addRowAction('view');
        $this->explicitSelect = true;
        $this->allow_export = true;
        $this->deleted = false;
        $this->context = Context::getContext();
        $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
        $this->bulk_actions = array('-' => array('text' => $this->l('-')));
        // template path
        $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/';
        $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA');
        $this->_select = '
		a.id_currency,
		a.id_order AS id_pdf,
		a.id_order AS quickView,
		CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`,
		osl.`name` AS `osname`,
		os.`color`,
		IF((SELECT COUNT(so.id_order) FROM `' . _DB_PREFIX_ . 'orders` so WHERE so.id_customer = a.id_customer) > 1, 0, 1) as new ';
        // additional select
        $this->_select .= '
		, ca.id_carrier as carrier_id,
		SUM(d.product_weight * d.product_quantity) as poid, a.id_order as document,
		GROUP_CONCAT(d.product_id, "-",d.product_attribute_id, "-", d.product_quantity, "-", a.id_order SEPARATOR " ") as stock ';
        $this->_join = '
		LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`)
		LEFT JOIN `' . _DB_PREFIX_ . 'order_state` os ON (os.`id_order_state` = a.`current_state`)
		LEFT JOIN `' . _DB_PREFIX_ . 'order_state_lang` osl ON (os.`id_order_state` = osl.`id_order_state`
		AND osl.`id_lang` = ' . (int) $this->context->language->id . ')';
        // additional join
        $this->_join .= '
		LEFT JOIN `' . _DB_PREFIX_ . 'carrier` ca ON (ca.`id_carrier` = a.`id_carrier`)
		LEFT JOIN `' . _DB_PREFIX_ . 'order_detail` d ON ( d.`id_order` = a.`id_order`)';
        $this->_group = 'GROUP BY a.id_order';
        $this->_orderBy = 'id_order';
        $this->_orderWay = 'DESC';
        $statuses_array = array();
        $statuses = ErpOrderState::getOrderStates((int) $this->context->language->id);
        foreach ($statuses as $status) {
            $statuses_array[$status['id_order_state']] = $status['name'];
        }
        // get carrier list
        $carrier_array = $this->getListCarrier();
        if (_PS_VERSION_ < 1.6) {
            $this->no_link = true;
        } else {
            $this->list_no_link = true;
        }
        $this->fields_list = array('quickView' => array('title' => $this->l('Quick View'), 'align' => 'center', 'width' => 20, 'search' => false, 'orderby' => false, 'callback' => 'renderQuickViewColumn', 'remove_onclick' => true), 'id_order' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 40, 'remove_onclick' => true), 'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 65, 'remove_onclick' => true), 'stock' => array('title' => $this->l('Stock'), 'width' => 20, 'align' => 'center', 'search' => false, 'orderby' => false, 'callback' => 'getStock', 'remove_onclick' => true), 'carrier_id' => array('title' => $this->l('Carrier'), 'width' => 70, 'type' => 'select', 'list' => $carrier_array, 'filter_key' => 'ca!id_carrier', 'filter_type' => 'int', 'align' => 'center', 'callback' => 'getCarrierImage', 'remove_onclick' => true), 'document' => array('title' => $this->l('Document'), 'width' => 30, 'align' => 'center', 'search' => false, 'orderby' => false, 'havingFilter' => false, 'callback' => 'getLastDocument', 'remove_onclick' => true), 'new' => array('title' => $this->l('New'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'tmpTableFilter' => true, 'icon' => array(0 => 'blank.gif', 1 => array('src' => 'note.png', 'alt' => $this->l('First customer order'))), 'orderby' => false, 'remove_onclick' => true), 'customer' => array('title' => $this->l('Customer'), 'havingFilter' => true, 'width' => 100, 'remove_onclick' => true), 'total_paid_tax_incl' => array('title' => $this->l('Total'), 'width' => 70, 'align' => 'right', 'prefix' => '<b>', 'suffix' => '</b>', 'type' => 'price', 'currency' => true, 'remove_onclick' => true), 'payment' => array('title' => $this->l('Payment'), 'remove_onclick' => true, 'width' => 100, 'remove_onclick' => true), 'osname' => array('title' => $this->l('Status'), 'color' => 'color', 'width' => 220, 'type' => 'select', 'list' => $statuses_array, 'filter_key' => 'os!id_order_state', 'filter_type' => 'int', 'remove_onclick' => true, 'callback' => 'getStatutsListe'), 'date_add' => array('title' => $this->l('Date'), 'width' => 130, 'align' => 'right', 'type' => 'datetime', 'filter_key' => 'a!date_add', 'remove_onclick' => true));
        //$this->shopLinkType = 'shop';
        //$this->shopShareDatas = Shop::SHARE_ORDER;
        if (Tools::isSubmit('id_order')) {
            // Save context (in order to apply cart rule)
            $order = new ErpOrder((int) Tools::getValue('id_order'));
            if (!Validate::isLoadedObject($order)) {
                throw new PrestaShopException($this->l('Cannot load Order object'));
            }
            $this->context->cart = new Cart($order->id_cart);
            $this->context->customer = new Customer($order->id_customer);
        }
        // get controller status
        $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder'));
        parent::__construct();
    }
require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpStockMvt.php';
require_once _PS_MODULE_DIR_ . 'erpillicopresta/erpillicopresta.php';
require_once _PS_MODULE_DIR_ . 'erpillicopresta/config/Licence.php';
$cookie = new Cookie('psAdmin');
$context = Context::getContext();
$employee = new Employee($cookie->id_employee);
$context->employee = $employee;
$erpip = new ErpIllicopresta();
$token = Tools::getValue('token');
/* check Token */
if (!Tools::isSubmit('token') || $token != Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminSupplyOrders' . (int) Tab::getIdFromClassName('AdminSupplyOrders') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminStockTransfer' . (int) Tab::getIdFromClassName('AdminStockTransfer') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminInventory' . (int) Tab::getIdFromClassName('AdminInventory') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminStockGap' . (int) Tab::getIdFromClassName('AdminStockGap') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminAdvancedOrder' . (int) Tab::getIdFromClassName('AdminAdvancedOrder') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminAdvancedSupplyOrder' . (int) Tab::getIdFromClassName('AdminAdvancedSupplyOrder') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $cookie->id_employee) && $token != Tools::getAdminToken('AdminERP' . (int) Tab::getIdFromClassName('AdminERP') . (int) $cookie->id_employee) || Tools::getValue('task') === false) {
    exit('ERROR');
}
switch (Tools::getValue('task')) {
    case 'updateOrderStatus':
        if (Configuration::get($erpip->getControllerStatusName('ADVANCEDORDER')) == STATUS1 && Tools::getValue('action') == 'masse' && count(Tools::getValue('idOrder')) > ERP_ORDERFR) {
            $erp_orderfr = array('free_limitation_msg' => sprintf($erpip->l('You are using a free version of 1-Click ERP which limits the order change state to %d orders.'), ERP_ORDERFR));
            print Tools::jsonEncode($erp_orderfr);
            exit;
        } else {
            if (Tools::isSubmit('idOrder') && Tools::isSubmit('idState') && Tools::isSubmit('action') && Tools::isSubmit('id_employee')) {
                $retour = null;
                $id_employee = (int) Tools::getValue('id_employee');
                require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/order/ErpOrder.php';
                set_error_handler(array('ErpOrder', 'ErpOrdersAjaxErrorHandler'));
                switch (Tools::getValue('action')) {
                    case 'unique':
                        $retour = array('res' => false, 'newColor' => null);
                        $currOrder = new ErpOrder((int) Tools::getValue('idOrder'));
                        $currOrder->setCurrentState((int) Tools::getValue('idState'), (int) $id_employee);
                        $currOrder = new ErpOrder((int) Tools::getValue('idOrder'));
    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>';
        }
    }