Exemplo n.º 1
0
                         */
                        if ($is_canceled) {
                            /* Get info mvt_stock initial */
                            $query = 'SELECT * FROM ' . _DB_PREFIX_ . 'stock_mvt WHERE id_stock_mvt = ' . (int) Tools::getValue('id_stock_mvt');
                            $initial_stock_mvt = DB::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
                            /*  If we have informations about the wtock mvt to cancel */
                            if (count($initial_stock_mvt) > 0) {
                                /* Update Quantity  supply_order_detail */
                                $query = 'UPDATE ' . _DB_PREFIX_ . 'supply_order_detail
										 SET quantity_received = (quantity_received - ' . intval(Tools::getValue('quantity')) . ')
										 WHERE id_supply_order_detail = ' . intval(Tools::getValue('id_supply_order_detail'));
                                $update_supply_order = DB::getInstance(_PS_USE_SQL_SLAVE_)->execute($query);
                                /* If supply_order_detail successfully updated */
                                if ($update_supply_order) {
                                    /* stock update */
                                    $stock = new ErpStock($initial_stock_mvt[0]['id_stock']);
                                    $stock->physical_quantity -= Tools::getValue('quantity');
                                    $stock->usable_quantity -= Tools::getValue('quantity');
                                    /* If stock  update ok .. */
                                    if ($stock->update()) {
                                        /*  Synchro of stocks */
                                        StockAvailable::synchronize($stock->id_product);
                                        /*  Add stock mvt reason if not exists (lang non installed at the module installation) */
                                        $query = 'SELECT * FROM ' . _DB_PREFIX_ . 'stock_mvt_reason_lang WHERE id_stock_mvt_reason = ' . (int) Configuration::get('ERP_RECEPTION_CANCELING_ID') . ' AND id_lang = ' . (int) Context::getContext()->language->id;
                                        $results = Db::getInstance()->ExecuteS($query);
                                        if ($results <= 0) {
                                            Db::getInstance()->insert(_DB_PREFIX_ . 'stock_mvt_reason_lang', array('id_stock_mvt_reason' => Configuration::get('ERP_RECEPTION_CANCELING_ID'), 'id_lang' => (int) Context::getContext()->language->id, 'name' => $erpip->l('Reception cancelling')));
                                        }
                                        /* Opposite stock Mvt creation */
                                        $stock_mvt = new ErpStockMvt();
                                        $stock_mvt->id_stock = $initial_stock_mvt[0]['id_stock'];
    public function getDataGeneration()
    {
        $datas = array();
        $order_to_change_state = array();
        $saved_product = array();
        $datas_quantity = array();
        $customer_concerned = array();
        $concerned_id_order_detail = array();
        $orders = Db::getInstance()->executeS('
		SELECT a.id_order
		FROM `' . _DB_PREFIX_ . 'orders` a
		LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`)
		WHERE a.current_state = ' . (int) $this->generate_order_state . '
		ORDER BY a.`id_order` DESC');
        $unselected_orders_array = array();
        /* if (isset( $this->context->cookie->unselected_orders) && !empty( $this->context->cookie->unselected_orders))
        		{
        			  $unselected_orders_array = Tools::unSerialize( $this->context->cookie->unselected_orders);
        		} */
        if (Tools::getValue('unselected_orders_list', false)) {
            $unselected_orders_array = explode(',', Tools::getValue('unselected_orders_list'));
            $unselected_orders_array = array_map('trim', $unselected_orders_array);
        }
        if (!empty($orders)) {
            foreach ($orders as $order) {
                $id_order = (int) $order['id_order'];
                if (!in_array($id_order, $unselected_orders_array)) {
                    $order = new Order((int) $id_order);
                    if (!Validate::isLoadedObject($order)) {
                        throw new PrestaShopException('object oder simulate can\'t be loaded');
                    }
                    $order_details = $order->getOrderDetailList();
                    if (!empty($order_details)) {
                        $order_to_change_state[] = (int) $id_order;
                        foreach ($order_details as $order_detail) {
                            $id_supplier = 0;
                            $product_key = $order_detail['product_id'] . '_' . $order_detail['product_attribute_id'];
                            $product = new Product($order_detail['product_id'], $order_detail['product_attribute_id']);
                            // update selling price to purchase price
                            $order_detail['unit_price_tax_excl'] = ErpStock::getWholesalePrice($order_detail['product_id'], $order_detail['product_attribute_id']);
                            $order_detail['tax_rate'] = Tax::getProductTaxRate($order_detail['product_id']);
                            $order_detail['unit_price_tax_incl'] = $order_detail['unit_price_tax_excl'] * (1 + (double) $order_detail['tax_rate'] / 100);
                            if (empty($product->id_supplier)) {
                                // Get already associated suppliers
                                $associated_suppliers = new Collection('ProductSupplierCore');
                                $associated_suppliers->where('id_product', '=', (int) $product->id);
                                $associated_suppliers->groupBy('id_supplier');
                                foreach ($associated_suppliers as $associated_supplier) {
                                    $id_supplier = $associated_supplier->id_supplier;
                                }
                            } else {
                                $id_supplier = $product->id_supplier;
                            }
                            if (isset($saved_product[$product_key])) {
                                $datas_quantity[$product_key] += $order_detail['product_quantity'];
                                $customer_concerned[$product_key][] = $order->id_customer;
                                $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $order_detail['total_product_quantity'] = $datas_quantity[$product_key];
                                $order_detail['customer_concerned'] = $customer_concerned[$product_key];
                                $order_detail['concerned_id_order_detail'] = $concerned_id_order_detail[$product_key];
                                $datas[$id_supplier][$product_key] = $order_detail;
                            } else {
                                $product_quantity = $order_detail['product_quantity'];
                                $order_detail['total_product_quantity'] = $product_quantity;
                                $order_detail['customer_concerned'][] = $order->id_customer;
                                $order_detail['concerned_id_order_detail'][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $datas[$id_supplier][$product_key] = $order_detail;
                                $datas_quantity[$product_key] = $product_quantity;
                                $customer_concerned[$product_key][] = $order->id_customer;
                                $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $saved_product[$product_key] = true;
                            }
                        }
                    }
                }
            }
        }
        $data_return = array();
        foreach ($datas as $id_supplier => $data) {
            if ($id_supplier > 0) {
                $product_list = array();
                foreach ($data as $product_key => $product_info) {
                    $customer_concerned = '';
                    $customer_concerned_arr = array_unique($product_info['customer_concerned']);
                    foreach ($customer_concerned_arr as $id_customer) {
                        $customer = new Customer($id_customer);
                        $customer_concerned .= $customer->lastname . ' ' . $customer->firstname . ', ';
                    }
                    $total_te = $product_info['unit_price_tax_excl'] * $product_info['total_product_quantity'];
                    $total_ti = $product_info['unit_price_tax_incl'] * $product_info['total_product_quantity'];
                    $product_info['total_price_tax_excl'] = Tools::displayPrice($total_te);
                    $product_info['total_price_tax_incl'] = Tools::displayPrice($total_ti);
                    $product_info['unit_price_tax_excl'] = $product_info['unit_price_tax_excl'];
                    $product_info['customer_concerned'] = Tools::substr($customer_concerned, 0, Tools::strlen($customer_concerned) - 2);
                    $product_info['customer_id'] = $customer_concerned_arr;
                    $product_list[] = $product_info;
                }
                $data_return[$id_supplier] = $product_list;
            }
        }
        // for the order, get the orders list that the statuts should be update in provider order
        if ($this->display == 'ordering') {
            return array('data_return' => $data_return, 'order_to_change_state' => $order_to_change_state);
        } else {
            return $data_return;
        }
    }
 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));
 }
Exemplo n.º 4
0
 public function createImage($id_stock_image, $name_stock_image)
 {
     // First deleting image and linked stock lines
     if ($id_stock_image != -1) {
         $this->id_stock_image = trim($id_stock_image);
         $this->id = $this->id_stock_image;
         // delete image is Ok, we delete the product lines associated
         if ($this->delete()) {
             $id_images = StockImageContent::getImageContentIdsByIdImage($this->id);
             foreach ($id_images as $id_image) {
                 $image_content = new StockImageContent();
                 $image_content->id_stock_image_content = $id_image['id_stock_image_content'];
                 $image_content->id = $image_content->id_stock_image_content;
                 $image_content->delete();
             }
         }
     }
     // CREATE NEW IMAGE
     $this->id_stock_image = '';
     $this->name = $name_stock_image;
     $this->type_stock = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
     // Create stock image container
     if ($this->add(true)) {
         // For each product in stock, getting necessary informations
         $products = ErpStock::getAllProductInStock($this->type_stock, (int) Tools::getValue('id_warehouse'));
         // Saving
         foreach ($products as $product) {
             $product['id_stock_image'] = $this->getLastId();
             $this->createStockImageContent($product);
         }
     }
 }
 public function ajaxGetProductSupplierPrice()
 {
     //  If we have called the script with a term to search
     if (Tools::isSubmit('id_product') && Tools::isSubmit('id_product_attribute')) {
         require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/ErpProductSupplier.php';
         $id_product = Tools::getValue('id_product');
         $id_product_attribute = Tools::getValue('id_product_attribute');
         //$id_currency = Tools::getValue('id_currency', false) ? Tools::getValue('id_currency') : 1;
         /*  Price for all suppliers for the product */
         $supplier_prices = ErpProductSupplier::getAllProductSupplierPrice($id_product, $id_product_attribute, true);
         if (!empty($supplier_prices)) {
             echo '<table class="table">';
             foreach ($supplier_prices as $price) {
                 /*  If supplier price  = 0 we take the basic one */
                 if ($price['product_supplier_price_te'] == '0.000000') {
                     $supplier_price = ErpStock::getWholesalePrice($id_product, $id_product_attribute);
                 } else {
                     $supplier_price = $price['product_supplier_price_te'];
                 }
                 /*  writing of the HTML table */
                 echo '<tr>
                                                 <td>' . $price['supplier_name'] . ' : </td>
                                                 <td> &nbsp; ' . number_format($supplier_price, 2, '.', ' ') . '€</td>
                                             </tr>';
             }
             echo '</table>';
         } else {
             echo $this->l('No price found for this product!');
         }
     }
     die;
 }
 public function productHandler($product)
 {
     if (empty($product['idproduct'])) {
         $this->errors[] = Tools::displayError($this->l('Error : the id of the product is missing !'));
         return false;
     }
     $inventory_product = new InventoryProduct();
     $inventory_product->id_erpip_inventory = self::$id_erpip_inventory_static;
     $inventory_product->id_product = $product['idproduct'];
     $inventory_product->id_product_attribute = $product['idproductattribute'];
     $inventory_product->qte_before = !isset($product['physicalquantity']) || $product['physicalquantity'] == '' ? 0 : $product['physicalquantity'];
     $inventory_product->qte_after = !isset($product['foundquantity']) || $product['foundquantity'] == '' ? 0 : (int) $product['foundquantity'];
     $inventory_product->id_warehouse = Tools::isSubmit('id_warehouse') ? (int) Tools::getValue('id_warehouse') : -1;
     // if not mvt reason chosen => depend of quanities, select increate or decrease
     if (!isset($product['idreason']) || $product['idreason'] == '') {
         if ($inventory_product->qte_before <= $inventory_product->qte_after) {
             $inventory_product->id_mvt_reason = 1;
         } else {
             $inventory_product->id_mvt_reason = 2;
         }
     } else {
         $inventory_product->id_mvt_reason = $product['idreason'];
     }
     // Gireg:
     // only treat products that match to stock manager selected :
     // Products in advanced stock manager if we re in advanced stock manager
     // Or product in non advanced stock manager, if we are in non advanced stock manager
     if ($this->advanced_stock_management == StockAvailable::dependsOnStock((int) $product['idproduct'])) {
         // If record inventory line --> update stock
         if ($inventory_product->add()) {
             // if advanced stock manager
             if ($this->advanced_stock_management == 1) {
                 $stock = new ErpStock();
                 $stock->id_product = $product['idproduct'];
                 $stock->id_product_attribute = $product['idproductattribute'];
                 $stock->id_warehouse = $this->id_warehouse;
                 $stock->physical_quantity = !isset($product['foundquantity']) || $product['foundquantity'] == '' ? 0 : (int) $product['foundquantity'];
                 $stock->usable_quantity = !isset($product['foundquantity']) || $product['foundquantity'] == '' ? 0 : (int) $product['foundquantity'];
                 // get reference price
                 $price = $stock->getPriceTe();
                 // if $price is false, we dont have stock for this product. si quantity is lower than stock, set price to 0
                 if (isset($product['foundquantity']) && (int) $product['foundquantity'] < $product['physicalquantity'] || ($price = false)) {
                     $price = 0;
                 }
                 $stock->price_te = $price;
                 // if we already have a stock line for this production, we update else we insert
                 if ($stock->id = $stock->getStockId()) {
                     $maj_stock = $stock->update();
                 } else {
                     $maj_stock = $stock->add();
                 }
             } else {
                 $maj_stock = StockAvailable::setQuantity($product['idproduct'], $product['idproductattribute'], (int) $product['foundquantity']);
                 if (is_null($maj_stock)) {
                     $maj_stock = true;
                 }
             }
             // if update stock ok --> update location
             if ($maj_stock) {
                 // no stock change if advanced stock inactive
                 if ($this->advanced_stock_management == 1) {
                     require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpWarehouseProductLocation.php';
                     $wpl_id = ErpWarehouseProductLocationClass::getWarehouseProductLocationId($product['idproduct'], $product['idproductattribute']);
                     $warehouse_location = new ErpWarehouseProductLocationClass($wpl_id);
                     $warehouse_location->id_product = $product['idproduct'];
                     $warehouse_location->id_product_attribute = $product['idproductattribute'];
                     $warehouse_location->id_warehouse = $this->id_warehouse;
                     /*if ($product['area'] != '--')
                               $warehouse_location->zone = $product['area'];
                       if ($product['subarea'] != '--')
                               $warehouse_location->sous_zone = $product['subarea'];*/
                     $warehouse_location->location = $product['location'];
                     $warehouse_location->id_warehouse_product_location = $wpl_id;
                     // if update location ok & advanced stock active -> generate stock movement
                     if ($warehouse_location->update()) {
                         //echo 'Maj location OK';
                         // No stock movement if advanced stock inactive
                         if ($this->advanced_stock_management == 1) {
                             $stock_mvt = new ErpStockMvt();
                             $stock_mvt->id_stock = $stock->id;
                             $stock_mvt->id_order = 0;
                             $stock_mvt->id_supply_order = 0;
                             // if not mvt reason selected => depend of quantity to increase or decrease
                             if (!isset($product['idreason']) || $product['idreason'] == '') {
                                 if ($inventory_product->qte_before <= $inventory_product->qte_after) {
                                     $stock_mvt->id_stock_mvt_reason = 1;
                                 } else {
                                     $stock_mvt->id_stock_mvt_reason = 2;
                                 }
                             } else {
                                 $stock_mvt->id_stock_mvt_reason = $product['idreason'];
                             }
                             $stock_mvt->id_employee = $this->id_employee;
                             $stock_mvt->employee_firstname = $this->firstname;
                             $stock_mvt->employee_lastname = $this->lastname;
                             $stock_mvt->price_te = $price;
                             $stock_mvt->current_wa = $price;
                             // Récupération du sign (flèche up / down)
                             // Get sign (arrow up/down)
                             if (isset($product['foundquantity']) && ((int) $product['foundquantity'] >= (int) $product['physicalquantity'] || (int) $product['foundquantity'] == 0)) {
                                 $stock_mvt->sign = 1;
                             } else {
                                 $stock_mvt->sign = -1;
                             }
                             // calculate the quantity movement of stock
                             $foundquantity = !isset($product['foundquantity']) || $product['foundquantity'] == '' ? 0 : (int) $product['foundquantity'];
                             $physicalquantity = !isset($product['physicalquantity']) || $product['physicalquantity'] == '' ? 0 : (int) $product['physicalquantity'];
                             $mvt = abs($foundquantity - $physicalquantity);
                             $stock_mvt->physical_quantity = $mvt;
                             // Synchronise available stock
                             if ($stock_mvt->add(true)) {
                                 StockAvailable::synchronize($product['idproduct']);
                             } else {
                                 $this->errors[] = Tools::displayError($this->l('Error while inserting stock movement. Please try again.'));
                             }
                         } else {
                             $this->errors[] = Tools::displayError($this->l('No stock movement. You need to activate the advanced stock management in Preference > Products'));
                         }
                     } else {
                         $this->errors[] = Tools::displayError($this->l('Error while updating product location'));
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError($this->l('Error while updating stock'));
             }
         } else {
             $this->errors[] = Tools::displayError($this->l('Error while inserting product inventory row'));
         }
     }
 }