diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 24dc4cef0c6..301d26333cc 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -252,4 +252,4 @@ InfoTemplateImport=Uploaded file needs to have this format (* are mandatory fiel LabelOfInventoryMovemement=Inventory %s ReOpen=Reopen ConfirmFinish=Confirm closing - +ObjectNotFound=%s not found \ No newline at end of file diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index 0627a6a1cf7..aac4d66fc88 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -315,7 +315,7 @@ if ($action == 'importCSV' && !empty($user->rights->stock->mouvement->creer)) { $importcsv->import_open_file($fullpath); $labelsrecord = $importcsv->import_read_record(); - if ($nblinesrecord <= 1) { + if ($nblinesrecord < 1) { setEventMessages($langs->trans("BadNumberOfLinesMustHaveAtLeastOneLinePlusTitle"), null, 'errors'); } else { $i=0; @@ -329,28 +329,46 @@ if ($action == 'importCSV' && !empty($user->rights->stock->mouvement->creer)) { continue; } //var_dump($data); - + $formproduct = new FormProduct($db); + $productstatic = new Product($db); + $warehousestatics = new Entrepot($db); + $warehousestatict = new Entrepot($db); $tmp_id_sw = $data[$i][0]['val']; $tmp_id_tw = $data[$i][1]['val']; $tmp_id_product = $data[$i][2]['val']; $tmp_qty = $data[$i][3]['val']; $tmp_batch = $data[$i][4]['val']; - // TODO If product is a ref (not numeric or starts with "ref:..."), retreive the id of product from the ref + if (!is_numeric($tmp_id_product)) { + $result = fetchref($productstatic, $tmp_id_product); + $tmp_id_product = $result; + $data[$i][2]['val'] = $result; + } if (!($tmp_id_product > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors'); } - // TODO If warehouse is a ref (not numeric or starts with "ref:..."), retreive the id of product from the ref + + if (!is_numeric($tmp_id_sw)) { + $result = fetchref($warehousestatics, $tmp_id_sw); + $tmp_id_sw = $result; + $data[$i][0]['val'] = $result; + } if (!($tmp_id_sw > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors'); } - // TODO If warehouse is a ref (not numeric or starts with "ref:..."), retreive the id of product from the ref + + if (!is_numeric($tmp_id_tw)) { + $result = fetchref($warehousestatict, $tmp_id_tw); + $tmp_id_tw = $result; + $data[$i][1]['val'] = $result; + } if (!($tmp_id_tw > 0)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors'); } + if ($tmp_id_sw > 0 && $tmp_id_tw == $tmp_id_sw) { $error++; $langs->load("errors"); @@ -585,24 +603,39 @@ foreach ($listofdata as $key => $val) { $warehousestatics->fetch($val['id_sw']); $warehousestatict->fetch($val['id_tw']); - print '