From 1f64b09430aadb5e7670bc5c8973b1b77b33519d Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller Date: Thu, 21 Oct 2021 18:07:54 +0200 Subject: [PATCH 1/4] WIP : fix inventory scan --- htdocs/core/class/html.formother.class.php | 5 +- htdocs/langs/en_US/productbatch.lang | 3 +- htdocs/langs/fr_FR/productbatch.lang | 2 +- .../product/inventory/ajax/ajax.inventory.php | 47 ---------- .../inventory/ajax/searchfrombarcode.php | 54 +++++++++++ htdocs/product/inventory/inventory.php | 94 +++++++++---------- 6 files changed, 108 insertions(+), 97 deletions(-) delete mode 100644 htdocs/product/inventory/ajax/ajax.inventory.php create mode 100644 htdocs/product/inventory/ajax/searchfrombarcode.php diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 99ee1b6af9b..1d8dd1db08e 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -77,7 +77,10 @@ class FormOther $out .= ' Scan a product barcode
'; $out .= ' Scan a product lot or serial number
'; - $out .= $langs->trans("QtyToAddAfterBarcodeScan").'
'; + $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan","tmphtml"); + $htmltoreplaceby = ''; + $stringaddbarcode = str_replace("tmphtml",$htmltoreplaceby,$stringaddbarcode); + $out .= $stringaddbarcode.'
'; $out .= ''; /*print '
'.$langs->trans("or").'
'; diff --git a/htdocs/langs/en_US/productbatch.lang b/htdocs/langs/en_US/productbatch.lang index 71e44e8f281..dd1e0ea4027 100644 --- a/htdocs/langs/en_US/productbatch.lang +++ b/htdocs/langs/en_US/productbatch.lang @@ -30,7 +30,7 @@ ManageLotMask=Custom mask CustomMasks=Option to define a different numbering mask for each product BatchLotNumberingModules=Numbering rule for automatic generation of lot number BatchSerialNumberingModules=Numbering rule for automatic generation of serial number (for products with property 1 unique lot/serial for each product) -QtyToAddAfterBarcodeScan=Qty to add for each barcode/lot/serial scanned +QtyToAddAfterBarcodeScan=Qty to %s for each barcode/lot/serial scanned LifeTime=Life span (in days) EndOfLife=End of life ManufacturingDate=Manufacturing date @@ -42,3 +42,4 @@ HideLots=Hide lots #Traceability - qc status OutOfOrder=Out of order InWorkingOrder=In working order +ToReplace=Replace \ No newline at end of file diff --git a/htdocs/langs/fr_FR/productbatch.lang b/htdocs/langs/fr_FR/productbatch.lang index ccd5e43d3d7..bcef04e75ed 100644 --- a/htdocs/langs/fr_FR/productbatch.lang +++ b/htdocs/langs/fr_FR/productbatch.lang @@ -30,7 +30,7 @@ ManageLotMask=Masque personnalisé CustomMasks=Option pour définir un masque de numérotation différent pour chaque produit BatchLotNumberingModules=Règle de numérotation pour la génération automatique de numéro de lot BatchSerialNumberingModules=Règle de numérotation pour la génération automatique de numéro de série (pour les produits avec propriété 1 lot/série unique pour chaque produit) -QtyToAddAfterBarcodeScan=Quantité à ajouter pour chaque code à barres/lot/série scanné +QtyToAddAfterBarcodeScan=Quantité à %s pour chaque code à barres/lot/série scanné LifeTime=Durée de vie (en jours) EndOfLife=Fin d'utilisation ManufacturingDate=Date de fabrication diff --git a/htdocs/product/inventory/ajax/ajax.inventory.php b/htdocs/product/inventory/ajax/ajax.inventory.php deleted file mode 100644 index 920607f4c1e..00000000000 --- a/htdocs/product/inventory/ajax/ajax.inventory.php +++ /dev/null @@ -1,47 +0,0 @@ -rights->stock->creer)) { - echo -1; exit; - } - - $fk_det_inventory = GETPOST('fk_det_inventory'); - - $det = new InventoryLine($db); - if ($det->fetch($fk_det_inventory)) { - $det->qty_view += GETPOST('qty'); - $res = $det->update($user); - - echo $det->qty_view; - } else { - echo -2; - } - - break; - - case 'pmp': - if (empty($user->rights->stock->creer) || empty($user->rights->stock->changePMP)) { - echo -1; exit; - } - - $fk_det_inventory = GETPOST('fk_det_inventory'); - - $det = new InventoryLine($db); - if ($det->fetch($fk_det_inventory)) { - $det->new_pmp = price2num(GETPOST('pmp')); - $det->update($user); - - echo $det->new_pmp; - } else { - echo -2; - } - - break; -} diff --git a/htdocs/product/inventory/ajax/searchfrombarcode.php b/htdocs/product/inventory/ajax/searchfrombarcode.php new file mode 100644 index 00000000000..259aa5999f6 --- /dev/null +++ b/htdocs/product/inventory/ajax/searchfrombarcode.php @@ -0,0 +1,54 @@ +. + */ + +/** + * \file /htdocs/product/inventory/ajax/searchfrombarcode.php + * \brief File to make Ajax action on product and stock + */ + +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (!defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +// Do not check anti CSRF attack test +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +// If there is no need to load and show top and left menu +if (!defined("NOLOGIN")) { + define("NOLOGIN", '1'); +} +if (!defined('NOIPCHECK')) { + define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +} +if (!defined('NOBROWSERNOTIF')) { + define('NOBROWSERNOTIF', '1'); +} +require '../../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; + diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 9a4d61209ba..9445e7896c6 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -542,6 +542,7 @@ if ($object->id > 0) { print ''; } include DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $formother = new FormOther($db); - print $formother->getHTMLScannerForm(); + print $formother->getHTMLScannerForm("barcodescannerjs"); } //Call method to undo changes in real qty From 4d2b96d0294cf9fbf36fb08df277368f22762e13 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller Date: Thu, 21 Oct 2021 18:08:20 +0200 Subject: [PATCH 2/4] fix inventory scan --- htdocs/core/class/html.formother.class.php | 4 ++-- htdocs/product/inventory/ajax/searchfrombarcode.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 1d8dd1db08e..d1f50889182 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -77,9 +77,9 @@ class FormOther $out .= ' Scan a product barcode
'; $out .= ' Scan a product lot or serial number
'; - $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan","tmphtml"); + $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml"); $htmltoreplaceby = ''; - $stringaddbarcode = str_replace("tmphtml",$htmltoreplaceby,$stringaddbarcode); + $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode); $out .= $stringaddbarcode.'
'; $out .= ''; diff --git a/htdocs/product/inventory/ajax/searchfrombarcode.php b/htdocs/product/inventory/ajax/searchfrombarcode.php index 259aa5999f6..7ee9d2b6be9 100644 --- a/htdocs/product/inventory/ajax/searchfrombarcode.php +++ b/htdocs/product/inventory/ajax/searchfrombarcode.php @@ -51,4 +51,3 @@ if (!defined('NOBROWSERNOTIF')) { } require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; - From 56ff2412c1712c39d3ecee14b2fd22ed107eb46c Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller Date: Fri, 22 Oct 2021 16:39:42 +0200 Subject: [PATCH 3/4] start code to searchfrmbarcode --- .../inventory/ajax/searchfrombarcode.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/htdocs/product/inventory/ajax/searchfrombarcode.php b/htdocs/product/inventory/ajax/searchfrombarcode.php index 7ee9d2b6be9..73b1943f4c7 100644 --- a/htdocs/product/inventory/ajax/searchfrombarcode.php +++ b/htdocs/product/inventory/ajax/searchfrombarcode.php @@ -51,3 +51,29 @@ if (!defined('NOBROWSERNOTIF')) { } require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; + +$action = GETPOST("action", "alpha"); +$barcode = GETPOST("barcode", "aZ09"); +$response = ""; +$fk_entrepot = -1; +if ($action == "existbarcode" && !empty($barcode)) { + $sql = "SELECT *"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps JOIN ".MAIN_DB_PREFIX."product as p ON ps.fk_product = p.rowid"; + " WHERE p.barcode = '".$db->escape($barcode)."'"; + $result = $db->query($sql); + if ($result) { + $objecttab = $db->fetch_row($resql); + $nbline = $db->num_rows($resql); + for ($i=0; $i < $nbline; $i++) { + if ($fk_entrepot != $objecttab[$i]) { + // code... + } + } + } else { + $response = "No results found for barcode"; + } +} else { + $response = "Error on action"; +} + +echo $response; From ae78bed41d6ca6de523859676a6eaba37fb6fce6 Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller Date: Sat, 23 Oct 2021 14:36:31 +0200 Subject: [PATCH 4/4] call to ajax file --- htdocs/product/inventory/inventory.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index 9445e7896c6..f2702fbc0db 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -600,6 +600,16 @@ if ($object->id > 0) { function barcodeserialforproduct(textarray,tabproduct,barcodeproductqty,selectaddorreplace,mode,autodetect=false){ textarray.forEach(function(element,index){ + $.ajax({ url: \''.DOL_URL_ROOT.'/product/inventory/ajax/searchfrombarcode.php\', + data: { "action":"existbarcode","barcode":element}, + type: \'POST\', + success: function(response) { + console.log("test+1"); + }, + error : function(output) { + console.error("Error on Fetch of KM articles"); + }, + }); console.log("Product "+(index+=1)+": "+element); BarCodeDoesNotExist=0; tabproduct.forEach(product => {