public function postProcess()
 {
     // Export PDF
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateInvoicesPDF3') {
         $this->processGenerateInvoicesPDF3();
     }
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateDeliverySlipsPDF2') {
         $this->processGenerateDeliverySlipsPDF2();
     }
     parent::postProcess();
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     $this->is_editing_order = false;
     // Checks access
     if (Tools::isSubmit('submitAddsupply_order') && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError($this->l('You do not have permission to add a supply order.'));
     }
     if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) {
         $this->errors[] = Tools::displayError($this->l('You do not have permission to edit an order.'));
     }
     // Trick to use both Supply Order as template and actual orders
     if (Tools::isSubmit('is_template')) {
         $_GET['mod'] = 'template';
     }
     // checks if supply order reference is unique
     if (Tools::isSubmit('reference')) {
         // gets the reference
         $ref = pSQL(Tools::getValue('reference'));
         if (Tools::getValue('id_supply_order') != 0 && SupplyOrder::getReferenceById((int) Tools::getValue('id_supply_order')) != $ref) {
             if ((int) SupplyOrder::exists($ref) != 0) {
                 $this->errors[] = Tools::displayError($this->l('The reference has to be unique.'));
             }
         } else {
             if (Tools::getValue('id_supply_order') == 0 && (int) SupplyOrder::exists($ref) != 0) {
                 $this->errors[] = Tools::displayError($this->l('The reference has to be unique.'));
             }
         }
     }
     if ($this->errors) {
         return;
     }
     // Global checks when add / update a supply order
     if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) {
         $this->action = 'save';
         $this->is_editing_order = true;
         // get supplier ID
         $id_supplier = (int) Tools::getValue('id_supplier', 0);
         if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) {
             $this->errors[] = Tools::displayError($this->l('The selected supplier is not valid.'));
         }
         // get warehouse id
         $id_warehouse = (int) Tools::getValue('id_warehouse', 0);
         if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) {
             $this->errors[] = Tools::displayError($this->l('The selected warehouse is not valid.'));
         }
         // get currency id
         $id_currency = (int) Tools::getValue('id_currency', 0);
         if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) {
             $this->errors[] = Tools::displayError($this->l('The selected currency is not valid.'));
         }
         // get delivery date
         $delivery_expected = new DateTime(pSQL(Tools::getValue('date_delivery_expected')));
         // converts date to timestamp
         if ($delivery_expected <= new DateTime('yesterday')) {
             $this->errors[] = Tools::displayError($this->l('The date you specified cannot be in the past.'));
         }
         // gets threshold
         $quantity_threshold = Tools::getValue('load_products');
         if (is_numeric($quantity_threshold)) {
             $quantity_threshold = (int) $quantity_threshold;
         } else {
             $quantity_threshold = null;
         }
         if (!count($this->errors)) {
             // forces date for templates
             if (Tools::isSubmit('is_template') && !Tools::getValue('date_delivery_expected')) {
                 $_POST['date_delivery_expected'] = date('Y-m-d h:i:s');
             }
             // specify initial state
             $_POST['id_supply_order_state'] = 1;
             //defaut creation state
             // specify global reference currency
             $_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id;
             // specify supplier name
             $_POST['supplier_name'] = Supplier::getNameById($id_supplier);
             //specific discount check
             $_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0));
         }
         // manage each associated product
         $this->manageOrderProducts();
         // if the threshold is defined and we are saving the order
         if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) {
             $this->loadProducts((int) $quantity_threshold);
         }
         //--ERP informations
         // updates/creates erp_supplier_order if it does not exist
         if (Tools::isSubmit('id_erpip_supply_order') && (int) Tools::getValue('id_erpip_supply_order') > 0) {
             $erp_supplier_order = new ErpSupplyOrder((int) Tools::getValue('id_erpip_supply_order'));
         } else {
             $erp_supplier_order = new ErpSupplyOrder();
         }
         // creates erp_supplier_order
         $erp_supplier_order->escompte = Tools::getValue('escompte', null);
         $erp_supplier_order->global_discount_amount = Tools::getValue('global_discount_type', null);
         $erp_supplier_order->global_discount_type = Tools::getValue('global_discount_type', null);
         $erp_supplier_order->shipping_amount = Tools::getValue('shipping_amount', null);
         $erp_supplier_order->description = Tools::getValue('description', null);
         $validation = $erp_supplier_order->validateController();
         // checks erp_supplier_order validity
         if (count($validation) > 0) {
             foreach ($validation as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError('The ErpIllicopresta Supplier Order is not correct. Please make sure all of the required fields are completed.');
         } else {
             if (Tools::isSubmit('id_erpip_supply_order') && Tools::getValue('id_erpip_supply_order') > 0) {
                 $erp_supplier_order->update();
             } else {
                 $erp_supplier_order->save();
                 $_POST['id_erpip_supply_order'] = $erp_supplier_order->id;
             }
         }
     }
     // Manage state change
     if (Tools::isSubmit('submitChangestate') && Tools::isSubmit('id_supply_order') && Tools::isSubmit('id_supply_order_state')) {
         if ($this->tabAccess['edit'] != '1') {
             $this->errors[] = Tools::displayError($this->l('You do not have permission to change the order status.'));
         }
         // get state ID
         $id_state = (int) Tools::getValue('id_supply_order_state', 0);
         if ($id_state <= 0) {
             $this->errors[] = Tools::displayError($this->l('The selected supply order status is not valid.'));
         }
         // get supply order ID
         $id_supply_order = (int) Tools::getValue('id_supply_order', 0);
         if ($id_supply_order <= 0) {
             $this->errors[] = Tools::displayError($this->l('The supply order ID is not valid.'));
         }
         if (!count($this->errors)) {
             // try to load supply order
             $supply_order = new SupplyOrder($id_supply_order);
             if (Validate::isLoadedObject($supply_order)) {
                 // get valid available possible states for this order
                 $states = SupplyOrderState::getSupplyOrderStates($supply_order->id_supply_order_state);
                 foreach ($states as $state) {
                     // if state is valid, change it in the order
                     if ($id_state == $state['id_supply_order_state']) {
                         $new_state = new SupplyOrderState($id_state);
                         $old_state = new SupplyOrderState($supply_order->id_supply_order_state);
                         // special case of validate state - check if there are products in the order and the required state is not an enclosed state
                         if ($supply_order->isEditable() && !$supply_order->hasEntries() && !$new_state->enclosed) {
                             $this->errors[] = Tools::displayError($this->l('It is not possible to change the status of this order because you did not order any product.'));
                         }
                         if (!count($this->errors)) {
                             // send mail to supplier with supply order
                             if ($this->sendMailOnValidateSupplyOrder($supply_order)) {
                                 $supply_order->id_supply_order_state = $state['id_supply_order_state'];
                                 if ($supply_order->save()) {
                                     //-ERP information
                                     // save erp_supply_order additionale information
                                     // loads current erp_supplier` informationfor this supplier - if possible
                                     $erp_supply_order = null;
                                     if (isset($supply_order->id)) {
                                         $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId((int) $supply_order->id);
                                         if ($id_erpip_supply_order > 0) {
                                             $erp_supply_order = new ErpSupplyOrder((int) $id_erpip_supply_order);
                                         } else {
                                             $erp_supply_order = new ErpSupplyOrder();
                                         }
                                     }
                                     if ($erp_supply_order != null) {
                                         if (Tools::isSubmit('date_to_invoice')) {
                                             $erp_supply_order->date_to_invoice = Tools::getValue('date_to_invoice', '000-00-00');
                                         }
                                         if (Tools::isSubmit('invoice_number')) {
                                             $erp_supply_order->invoice_number = Tools::getValue('invoice_number', '');
                                         }
                                         $erp_supply_order->id_supply_order = $supply_order->id;
                                         $erp_supply_order->save();
                                     }
                                     // if pending_receipt,
                                     // or if the order is being canceled,
                                     // synchronizes StockAvailable
                                     if ($new_state->pending_receipt && !$new_state->receipt_state || $old_state->receipt_state && $new_state->enclosed && !$new_state->receipt_state) {
                                         $supply_order_details = $supply_order->getEntries();
                                         $products_done = array();
                                         foreach ($supply_order_details as $supply_order_detail) {
                                             if (!in_array($supply_order_detail['id_product'], $products_done)) {
                                                 StockAvailable::synchronize($supply_order_detail['id_product']);
                                                 $products_done[] = $supply_order_detail['id_product'];
                                             }
                                         }
                                     }
                                     $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
                                     $redirect = self::$currentIndex . '&token=' . $token;
                                     $this->redirect_after = $redirect . '&conf=5';
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError($this->l('The selected supplier is not valid.'));
             }
         }
     }
     // get id_supplier
     $id_supply_order = (int) Tools::getValue('id_supply_order', null);
     $supply_order = new SupplyOrder($id_supply_order);
     $erp_supplier_order = new ErpSupplyOrder($id_supply_order);
     $this->context->smarty->assign(array('supplier_id' => $supply_order->id_supplier, 'currency' => new CurrencyCore((int) $supply_order->id_currency), 'random' => rand(99999, 150000), 'template_path' => $this->template_path, 'controller_status' => $this->controller_status, 'supply_order_description' => $erp_supplier_order->description));
     $this->getFilters();
     //-ErpIllicopresta
     // Fixed bug : different variable available according Prestashop version
     //      1.5.4.1 => submitFiltersupply_order_detail
     //      1.5.5.0 => submitFiltersupply_order
     // Add an OR to take into account this two version
     // updates receipt
     if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order') && (Tools::isSubmit('submitFiltersupply_order') || Tools::isSubmit('submitFiltersupply_order_detail'))) {
         $this->postProcessUpdateReceipt();
     }
     // use template to create a supply order
     if (Tools::isSubmit('create_supply_order') && Tools::isSubmit('id_supply_order')) {
         $this->postProcessCopyFromTemplate();
     }
     // Export PDF of supply order
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyOrderFormPDF') {
         $this->processGenerateSupplyOrderFormPDF();
     }
     // Export PDF of receiving slip
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyReceivingSlipFormPDF') {
         $this->processGenerateSupplyReceivingSlipFormPDF();
     }
     if (!count($this->errors) && $this->is_editing_order || !$this->is_editing_order) {
         parent::postProcess();
     }
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     if (Tools::isSubmit('export_csv')) {
         $this->renderCSV();
     }
     // checks access
     if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError($this->l('You do not have permission to add suppliers.'));
         return parent::postProcess();
     }
     if (Tools::isSubmit('submitAdd' . $this->table)) {
         if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) {
             return;
         }
         // updates/creates address if it does not exist
         if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) {
             $address = new Address((int) Tools::getValue('id_address'));
         } else {
             $address = new Address();
         }
         // creates address
         $address->alias = Tools::getValue('name', null);
         $address->lastname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->firstname = 'supplier';
         // skip problem with numeric characters in supplier name
         $address->address1 = Tools::getValue('address', null);
         $address->address2 = Tools::getValue('address2', null);
         $address->postcode = Tools::getValue('postcode', null);
         $address->phone = Tools::getValue('phone', null);
         $address->id_country = Tools::getValue('id_country', null);
         $address->id_state = Tools::getValue('id_state', null);
         $address->city = Tools::getValue('city', null);
         $validation = $address->validateController();
         // checks address validity
         if (count($validation) > 0) {
             foreach ($validation as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError($this->l('The address is not correct. Please make sure all of the required fields are completed.'));
         } else {
             if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) {
                 $address->update();
             } else {
                 $address->save();
                 $_POST['id_address'] = $address->id;
             }
         }
         //--ERP informations
         // updates/creates erp_supplier if it does not exist
         if (Tools::isSubmit('id_erpip_supplier') && (int) Tools::getValue('id_erpip_supplier') > 0) {
             $erp_supplier = new ErpSupplier((int) Tools::getValue('id_erpip_supplier'));
         } else {
             $erp_supplier = new ErpSupplier();
         }
         // creates erp_supplier
         $erp_supplier->email = Tools::getValue('email', null);
         $erp_supplier->fax = Tools::getValue('fax', null);
         $erp_supplier->franco_amount = Tools::getValue('franco_amount', null);
         $erp_supplier->discount_amount = Tools::getValue('discount_amount', null);
         $erp_supplier->shipping_amount = Tools::getValue('shipping_amount', null);
         $erp_supplier->escompte = Tools::getValue('escompte', null);
         $erp_supplier->delivery_time = Tools::getValue('delivery_time', null);
         $erp_supplier->account_number_accounting = Tools::getValue('account_number_accounting', null);
         $validation2 = $erp_supplier->validateController();
         //print_r($validation2);
         // checks erp_supplier validity
         if (count($validation2) > 0) {
             foreach ($validation2 as $item) {
                 $this->errors[] = $item;
             }
             $this->errors[] = Tools::displayError($this->l('The ErpIllicopresta Supplier is not correct. Please make sure all of the required fields are completed.'));
         } else {
             if (Tools::isSubmit('id_erpip_supplier') && Tools::getValue('id_erpip_supplier') > 0) {
                 $erp_supplier->update();
             } else {
                 $erp_supplier->save();
                 $_POST['id_erpip_supplier'] = $erp_supplier->id;
             }
         }
         return parent::postProcess();
     } else {
         if (Tools::isSubmit('delete' . $this->table)) {
             if (!($obj = $this->loadObject(true))) {
                 return;
             } else {
                 if (SupplyOrder::supplierHasPendingOrders($obj->id)) {
                     $this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.');
                 } else {
                     //delete all product_supplier linked to this supplier
                     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'product_supplier` WHERE `id_supplier`=' . (int) $obj->id);
                     $id_address = Address::getAddressIdBySupplierId($obj->id);
                     $address = new Address($id_address);
                     if (Validate::isLoadedObject($address)) {
                         $address->deleted = 1;
                         $address->save();
                     }
                     //delete erp supplier
                     $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($obj->id);
                     $erp_supplier = new ErpSupplier($id_erpip_supplier);
                     if (Validate::isLoadedObject($erp_supplier)) {
                         $erp_supplier->delete();
                     }
                     return parent::postProcess();
                 }
             }
         } else {
             return parent::postProcess();
         }
     }
 }
 public function postProcess()
 {
     // record all order unselected
     $this->saveUnselectedOrders();
     // Export PDF of supply order
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyOrderFormPDF') {
         $this->processGenerateSupplyOrderFormPDF();
     }
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     parent::postProcess();
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     if (Tools::isSubmit('exist') && Tools::getValue('exist') == 'true') {
         $this->errors[] = $this->l('This area already exists in this warehouse !');
     }
     // checks access
     if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError('You do not have permission to add zone.');
         return parent::postProcess();
     }
     if (Tools::isSubmit('export_csv')) {
         $this->renderCSV();
     }
     return parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitFilterconfiguration')) {
         // get an array with first paramettre id_product, second paramettre id_product attribute, third area
         // fourth id_wharehouse_product_location, fifth id_erpip_warhouse_product_location
         $areas = Tools::getValue('data_location');
         if (!empty($areas) && is_array($areas)) {
             foreach ($areas as $id_product => $product) {
                 foreach ($product as $id_attribute => $attribute) {
                     // data already exists in warehouse product location table
                     if (!empty($attribute['id_warehouse_product_location']) && $attribute['id_warehouse_product_location'] != '0') {
                         $warehouse = new WarehouseProductLocationCore((int) $attribute['id_warehouse_product_location']);
                     } else {
                         $warehouse = new WarehouseProductLocationCore();
                         $warehouse->id_product = (int) $id_product;
                         $warehouse->id_product_attribute = (int) $id_attribute;
                         $warehouse->id_warehouse = (int) Tools::getValue('id_warehouse');
                     }
                     //save location
                     $warehouse->location = empty($attribute['location']) ? null : $attribute['location'];
                     $warehouse->save();
                     // data not exists in ERP warehouse product location table
                     if ($attribute['id_erpip_warehouse_product_location'] == '0') {
                         $erp_warehouse = new ErpWarehouseProductLocation();
                     } else {
                         $erp_warehouse = new ErpWarehouseProductLocation((int) $attribute['id_erpip_warehouse_product_location']);
                     }
                     // save area and sub area
                     $erp_warehouse->id_warehouse_product_location = (int) $warehouse->id;
                     $erp_warehouse->id_zone_parent = empty($attribute['area']) ? null : (int) $attribute['area'];
                     //id_zone_parent  = area
                     $erp_warehouse->id_zone = empty($attribute['sub_area']) ? null : (int) $attribute['sub_area'];
                     //id_zone = sub_area
                     $erp_warehouse->save();
                 }
             }
             $this->confirmations[] = $this->l('Locations updated successfully');
         }
     }
     if (Tools::isSubmit('createImageStock')) {
         // list of stock images
         $images = Tools::getValue('images');
         if (!empty($images) && is_array($images)) {
             foreach ($images as $image) {
                 //if isset id_image then this is the selected images stock
                 if (isset($image['id_stock_image'])) {
                     $stock_image = new StockImage();
                     $stock_image->createImage((int) $image['id_stock_image'], $image['name_stock_image']);
                     break;
                 }
             }
         }
     }
     //Display Information or confirmation message / error of end of inventory
     switch (Tools::getValue('submitFilterstock')) {
         case 0:
             $this->displayInformation($this->l('You may create a new stock image or select an older one'));
             break;
         case 1:
             $this->confirmations[] = $this->l('New image saved');
             break;
         case 2:
             $this->errors[] = Tools::displayError('Error while handling products');
             break;
         default:
             $this->displayInformation($this->l('You may create a new stock image or select an older one'));
             break;
     }
     // Stock image selection
     $this->context->smarty->assign(array('images' => StockImage::getStockImages(), 'pack' => ERP_SLOT_IPTIMEMACHINE, 'id_warehouse' => Tools::getValue('id_warehouse')));
     $this->getCurrentValue('id_image');
     // Get context link and display toolbar
     $this->context_link = $this->context->link;
     $this->initToolbar();
     $this->initPageHeaderToolbar();
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     return parent::postProcess();
 }
 public function postProcess()
 {
     require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php';
     $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path));
     // Export CSV
     if (Tools::isSubmit('export_csv')) {
         $this->renderCSV();
     }
     parent::postProcess();
 }
 public function postProcess()
 {
     //create manual inventory
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'submitCreateInventory') {
         $this->processCreateInventory();
     } else {
         if (isset($_FILES['file']) && Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'submitCreateInventoryFromCsv') {
             // ASA - Security Audit
             $_FILES['file']['name'] = str_replace("", "", $_FILES['file']['name']);
             // get extention file
             $file_extension = strrchr($_FILES['file']['name'], '.');
             // allowed exention
             $allowed_extensions = array('.csv');
             $file_name = basename($_FILES['file']['name']);
             if (!in_array($file_extension, $allowed_extensions)) {
                 $this->errors[] = Tools::displayError($this->l('The uploaded file is not a CSV !'));
                 return;
             }
             // max file size
             $max_file_size = 1048576;
             //1 Mo
             //file size
             $file_size = filesize($_FILES['file']['tmp_name']);
             if ($file_size > $max_file_size) {
                 $this->errors[] = Tools::displayError($this->l('Your CSV file should not weight more than 1Mo !'));
                 return;
             }
             // if error
             if (!empty($_FILES['file']['error'])) {
                 switch ($_FILES['file']['error']) {
                     case UPLOAD_ERR_INI_SIZE:
                         $this->errors[] = Tools::displayError($this->l('The uploaded file exceeds the upload_max_filesize directive in php.ini. If your server configuration allows it, you may add a directive in your .htaccess.'));
                         break;
                     case UPLOAD_ERR_FORM_SIZE:
                         $this->errors[] = Tools::displayError($this->l('The uploaded file exceeds the post_max_size directive in php.ini.
                                                                                 If your server configuration allows it, you may add a directive in your .htaccess, for example:')) . '<br/><a target="_blank" href="' . $this->context->link->getAdminLink('AdminMeta') . '" >
                                                 <code>php_value post_max_size 20M</code> ' . ($this->errors[] = Tools::displayError($this->l('(click to open "Generators" page)')) . '</a>');
                         break;
                     case UPLOAD_ERR_PARTIAL:
                         $this->errors[] = Tools::displayError($this->l('The uploaded file was only partially uploaded. Please try again.'));
                         break;
                     case UPLOAD_ERR_NO_FILE:
                         $this->errors[] = Tools::displayError($this->l('No file was uploaded'));
                         break;
                 }
             }
             // if no error
             if (count($this->errors) == 0) {
                 //we format file name
                 // $file_name = strtr($file_name,
                 // 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
                 // 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
                 $file_name = Tools::replaceAccentedChars($file_name);
                 $file_name = preg_replace('/([^.a-z0-9]+)/i', '-', $file_name);
                 $file_name = str_replace('.csv', '-' . date('Y_m_d_his') . '.csv', $file_name);
                 // try to upload
                 if (@move_uploaded_file($_FILES['file']['tmp_name'], _PS_MODULE_DIR_ . 'erpillicopresta/imports/' . $file_name)) {
                     $directory = explode("_", Tools::getValue('id_inventory'));
                     $id_erpip_inventory = $directory[0];
                     // if directory has only one element, mean it s a new directory and we get the name in the dedicated field
                     if (count($directory) > 1) {
                         $name = $directory[1];
                     } else {
                         $name = Tools::getValue('new_inventory');
                     }
                     $id_warehouse = Tools::getValue('selected_warehouse');
                     $id_employee = $this->context->employee->id;
                     $firstname = $this->context->employee->firstname;
                     $lastname = $this->context->employee->lastname;
                     $inventory_values = '';
                     /* ------------------ TREATMENT CSV ------------*/
                     // 2 - open file
                     $handle = $this->openCsvFile($file_name);
                     // 3 - Browse file
                     $i = 0;
                     while ($data = fgetcsv($handle, 0, ";")) {
                         // 4 - reconstruct inventory_values
                         /*
                         $id_product = $data[0];
                         $id_product_attribute = $data[1];
                         $area = $data[5];
                         $subarea = $data[6];
                         $location = $data[7];
                         $physical_quantity = $data[8];
                         $found_quantity = $data[9];
                         */
                         //idproduct==6|idproductattribute==0|idreason==109|area==null|subarea==null|location==|physicalquantity==61|foundquantity==20_
                         // don't use the first line : headers
                         if ($i > 0) {
                             $inventory_values .= 'idproduct==' . $data[0] . '|';
                             $inventory_values .= 'idproductattribute==' . $data[1] . '|';
                             //$inventory_values .= 'idreason==|area=='.$data[-1].'|';
                             $inventory_values .= 'area==' . $data[5] . '|';
                             $inventory_values .= 'subarea==' . $data[6] . '|';
                             $inventory_values .= 'location==' . $data[7] . '|';
                             if (isset($data[8])) {
                                 $inventory_values .= 'physicalquantity==' . $data[8] . '|';
                             }
                             if (isset($data[9])) {
                                 $inventory_values .= 'foundquantity==' . (int) $data[9] . '_';
                             }
                         }
                         $i++;
                     }
                     // 5 - prepare inventory
                     $this->id_erpip_inventory = $id_erpip_inventory;
                     $this->name = $name;
                     $this->id_warehouse = $id_warehouse;
                     $this->id_employee = $id_employee;
                     $this->firstname = $firstname;
                     $this->lastname = $lastname;
                     $this->advanced_stock_management = $this->advanced_stock_management;
                     $this->inventory_values = $inventory_values;
                     $this->createContainer();
                 } else {
                     $this->errors[] = $this->l('An error occurred while uploading and copying the file. Please try again or contact the customer service.');
                 }
             }
         }
     }
     // Export CSV
     if (Tools::isSubmit('export_csv')) {
         $this->renderCSV();
     }
     // Export PDF
     if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateInventoryPDF') {
         $this->processGenerateInventoryPDF();
     }
     parent::postProcess();
 }