diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang
index bb18c960aae..449c1598ec8 100644
--- a/htdocs/langs/en_US/stocks.lang
+++ b/htdocs/langs/en_US/stocks.lang
@@ -247,7 +247,8 @@ UpdateByScaningLot=Update by scan (lot|serial barcode)
DisableStockChangeOfSubProduct=Deactivate the stock change for all the subproducts of this Kit during this movement.
ImportFromCSV=Import CSV list of movement
ChooseFileToImport=Upload file then click on the %s icon to select file as source import file...
-InfoTemplateImport=Uploaded file needs to have this format (* are mandatory fields) : Product_id* | Source_Warehouse_id* | Target_Warehouse_id* | Quantity* | Batch_id
+OrSelectAStockMovementFileToImport=Or select a stock movement file to import
+InfoTemplateImport=Uploaded file needs to have this format (* are mandatory fields):
Source_Warehouse_id* | Target_Warehouse_id* | Product_id* | Quantity* | Lot/serial number
CSV character separator must be %s
LabelOfInventoryMovemement=Inventory %s
ReOpen=Reopen
ConfirmFinish=Confirm closing
diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php
index a89e234acfb..bf1291ac428 100644
--- a/htdocs/product/stock/massstockmove.php
+++ b/htdocs/product/stock/massstockmove.php
@@ -86,21 +86,7 @@ if (!empty($_SESSION['massstockmove'])) {
* Actions
*/
-
-if (GETPOST('sendit') && !empty($conf->global->MAIN_UPLOAD_DOC)) {
- dol_mkdir($conf->stock->dir_temp);
- $nowyearmonth = dol_print_date(dol_now(), '%Y%m%d%H%M%S');
-
- $fullpath = $conf->stock->dir_temp."/".$nowyearmonth.'-'.$_FILES['userfile']['name'];
- if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath, 1) > 0) {
- dol_syslog("File ".$fullpath." was added for import");
- } else {
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
- }
-}
-
-if ($action == 'addline') {
+if ($action == 'addline' && !empty($user->rights->stock->mouvement->creer)) {
if (!($id_product > 0)) {
$error++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
@@ -162,7 +148,7 @@ if ($action == 'addline') {
}
}
-if ($action == 'delline' && $idline != '') {
+if ($action == 'delline' && $idline != '' && !empty($user->rights->stock->mouvement->creer)) {
if (!empty($listofdata[$idline])) {
unset($listofdata[$idline]);
}
@@ -173,7 +159,7 @@ if ($action == 'delline' && $idline != '') {
}
}
-if ($action == 'createmovements') {
+if ($action == 'createmovements' && !empty($user->rights->stock->mouvement->creer)) {
$error = 0;
if (!GETPOST("label")) {
@@ -308,75 +294,107 @@ if ($action == 'createmovements') {
}
}
-if ($action == 'importCSV') {
- $importcsv = new ImportCsv($db, 'massstocklist');
- $dir = $conf->stock->dir_temp;
- $fullpath = $dir.'/'.$filetoimport;
- $nblinesrecord = $importcsv->import_get_nb_of_lines($fullpath)-1;
- $importcsv->import_open_file($fullpath);
- $labelsrecord = $importcsv->import_read_record();
- $i=0;
- $data = array();
- while ($i < $nblinesrecord) {
- $data[] = $importcsv->import_read_record();
- $id_product = $data[$i][0]['val'];
- $id_sw = $data[$i][1]['val'];
- $id_tw = $data[$i][2]['val'];
- $qty = $data[$i][3]['val'];
- $batch = $data[$i][4]['val'];
+if ($action == 'importCSV' && !empty($user->rights->stock->mouvement->creer)) {
+ dol_mkdir($conf->stock->dir_temp);
+ $nowyearmonth = dol_print_date(dol_now(), '%Y%m%d%H%M%S');
- if (!($id_product > 0)) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), null, 'errors');
- }
- if (!($id_sw > 0)) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseSource")), null, 'errors');
- }
- if (!($id_tw > 0)) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
- }
- if ($id_sw > 0 && $id_tw == $id_sw) {
- $error++;
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
- }
- if (!$qty) {
- $error++;
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
- }
+ $fullpath = $conf->stock->dir_temp."/".$user->id.'-csvfiletotimport.csv';
+ if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $fullpath, 1) > 0) {
+ dol_syslog("File ".$fullpath." was added for import");
+ } else {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
+ }
- // Check a batch number is provided if product need it
- if (!$error) {
- $producttmp = new Product($db);
- $producttmp->fetch($id_product);
- if ($producttmp->hasbatch()) {
- if (empty($batch)) {
+ if (!$error) {
+ $importcsv = new ImportCsv($db, 'massstocklist');
+ //print $importcsv->separator;
+
+ $nblinesrecord = $importcsv->import_get_nb_of_lines($fullpath)-1;
+ $importcsv->import_open_file($fullpath);
+ $labelsrecord = $importcsv->import_read_record();
+
+ if ($nblinesrecord <= 1) {
+ setEventMessages($langs->trans("BadNumberOfLinesMustHaveAtLeastOneLinePlusTitle"), null, 'errors');
+ } else {
+ $i=0;
+ $data = array();
+ while (($i < $nblinesrecord) && !$error) {
+ $data[] = $importcsv->import_read_record();
+ if (count($data[$i]) == 1) {
+ // Only 1 empty line
+ unset($data);
+ $i++;
+ continue;
+ }
+ //var_dump($data);
+
+ $id_sw = $data[$i][0]['val'];
+ $id_tw = $data[$i][1]['val'];
+ $id_product = $data[$i][2]['val'];
+ $qty = $data[$i][3]['val'];
+ $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 (!($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 (!($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 (!($id_tw > 0)) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WarehouseTarget")), null, 'errors');
+ }
+ if ($id_sw > 0 && $id_tw == $id_sw) {
$error++;
$langs->load("errors");
- setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
+ setEventMessages($langs->trans("ErrorWarehouseMustDiffers"), null, 'errors');
+ }
+ if (!$qty) {
+ $error++;
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
+ }
+
+ // Check a batch number is provided if product need it
+ if (!$error) {
+ $producttmp = new Product($db);
+ $producttmp->fetch($id_product);
+ if ($producttmp->hasbatch()) {
+ if (empty($batch)) {
+ $error++;
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorTryToMakeMoveOnProductRequiringBatchData", $producttmp->ref), null, 'errors');
+ }
+ }
+ }
+
+ $i++;
+ }
+
+ if (!$error) {
+ foreach ($data as $key => $value) {
+ if (count(array_keys($listofdata)) > 0) {
+ $id = max(array_keys($listofdata)) + 1;
+ } else {
+ $id = 1;
+ }
+ $id_product = $data[$key][0]['val'];
+ $id_sw = $data[$key][1]['val'];
+ $id_tw = $data[$key][2]['val'];
+ $qty = $data[$key][3]['val'];
+ $batch = $data[$key][4]['val'];
+ $listofdata[$key] = array('id'=>$key, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch);
}
}
}
+ }
- $i++;
- }
- if (!$error) {
- foreach ($data as $key => $value) {
- if (count(array_keys($listofdata)) > 0) {
- $id = max(array_keys($listofdata)) + 1;
- } else {
- $id = 1;
- }
- $id_product = $data[$key][0]['val'];
- $id_sw = $data[$key][1]['val'];
- $id_tw = $data[$key][2]['val'];
- $qty = $data[$key][3]['val'];
- $batch = $data[$key][4]['val'];
- $listofdata[$key] = array('id'=>$key, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw, 'batch'=>$batch);
- }
- }
$_SESSION['massstockmove'] = json_encode($listofdata);
}
@@ -401,6 +419,8 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') {
Header('Location: '.$_SERVER["PHP_SELF"]);
exit;
}
+
+
/*
* View
*/
@@ -426,119 +446,18 @@ $buttonrecord = $langs->trans("RecordMovement");
$titletoaddnoent = $langs->transnoentitiesnoconv("Select");
$buttonrecordnoent = $langs->transnoentitiesnoconv("RecordMovement");
print ''.$langs->trans("SelectProductInAndOutWareHouse", $titletoaddnoent, $buttonrecordnoent).'
';
-print '
'."\n";
-
-// Form to add a line
-print '