From d5f0fe6c105d8ecd2a8d91c6e547bdef06c57eaa Mon Sep 17 00:00:00 2001 From: atm-lena Date: Fri, 21 Jan 2022 10:55:06 +0100 Subject: [PATCH 01/28] OF consumption batch select : wip --- htdocs/mrp/mo_production.php | 5 ++- .../product/class/html.formproduct.class.php | 38 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index bc1a0457325..efe922a304a 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1023,8 +1023,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; if ($tmpproduct->status_batch) { $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : ''); - print ''; - print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', ''); +// print ''; + print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, 1, ''); +// print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); } print ''; } diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index da10faa4f34..c6365935fb8 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -626,13 +626,13 @@ class FormProduct { global $conf, $langs; - dol_syslog(get_class($this)."::selectLotDataList $htmlname, $empty, $fk_product, $fk_entrepot,$objectLines", LOG_DEBUG); + dol_syslog(get_class($this) . "::selectLotDataList $htmlname, $empty, $fk_product, $fk_entrepot,$objectLines", LOG_DEBUG); $out = ''; $productIdArray = array(); if (!is_array($objectLines) || !count($objectLines)) { if (!empty($fk_product) && $fk_product > 0) { - $productIdArray[] = (int) $fk_product; + $productIdArray[] = (int)$fk_product; } } else { foreach ($objectLines as $line) { @@ -644,26 +644,44 @@ class FormProduct $nboflot = $this->loadLotStock($productIdArray); - $out .= ''; + $out .= ''; return $out; } From 378473ca1f96429c6422b68d363cf2f96b983fa5 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Fri, 21 Jan 2022 12:21:47 +0100 Subject: [PATCH 02/28] OF Consumption batch select : WIP --- htdocs/mrp/mo_production.php | 3 +- .../product/class/html.formproduct.class.php | 42 ++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index efe922a304a..ce35b526025 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -184,6 +184,7 @@ if (empty($reshook)) { $pos = 0; // Process line to consume foreach ($object->lines as $line) { + if ($line->role == 'toconsume') { $tmpproduct = new Product($db); $tmpproduct->fetch($line->fk_product); @@ -1024,7 +1025,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($tmpproduct->status_batch) { $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : ''); // print ''; - print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, 1, ''); + print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 1, $line->fk_product, ''); // print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); } print ''; diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index c6365935fb8..d357383df23 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -622,7 +622,7 @@ class FormProduct * @param array $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all. * @return string HTML datalist */ - public function selectLotDataList($htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array()) + public function selectLotDataList($htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $forcecombo = 0, $events = array(), $morecss = 'minwidth200', $disabled = 0, $selected = '', $empty_label = '') { global $conf, $langs; @@ -644,7 +644,16 @@ class FormProduct $nboflot = $this->loadLotStock($productIdArray); + if ($conf->use_javascript_ajax && !$forcecombo) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $comboenhancement = ajax_combobox($htmlname, $events); + $out .= $comboenhancement; + } + $out .= ''; + // Qty print ''; @@ -1022,8 +1024,9 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea element.change(function(){ + var element = $(this); - console.log($(this).val()); + var product_element_name = element.attr('name').replace('idwarehouse', 'product'); $.ajax({ type: "POST", @@ -1031,11 +1034,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea data: { action: "updateselectbatchbywarehouse", warehouse_id: $(this).val(), - fk_product : fk_product ?> + product_id: $("input[name='"+product_element_name+"']").val() } }).done(function( data ) { - var element2 = $("#id.'-'.$i ?>"); + var element2_name = element.attr('name').replace('idwarehouse', 'batch'); + var element2 = $("select[name*='"+element2_name+"']"); element2.empty(); @@ -1082,10 +1086,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea - - stock->enabled) { print ''; @@ -1081,49 +1031,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); } print ''; - - ?> - - - - id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; print ''; + + ?> + + + + Date: Tue, 25 Jan 2022 12:33:28 +0100 Subject: [PATCH 06/28] WIP --- htdocs/mrp/mo_production.php | 56 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 5a7de44e7bd..c74f286323d 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1332,13 +1332,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea //Lorsqu'un entrepôt est sélectionné, on propose seulement les numéro de séries qui sont disponibles dans celui-ci //TODO : revoir requête sql de l'interface pour les cas suivants : si entrepôt sélectionné, alors quantité des nums individuel, sinon quantité globale function updateselectbatchbywarehouse() { - var element = $("select[name*='idwarehouse']"); element.change(function () { - var element = $(this); + var element2_name = element.attr('name').replace('idwarehouse', 'batch'); + var element2 = $("select[name*='" + element2_name + "']"); + var product_element_name = element.attr('name').replace('idwarehouse', 'product'); $.ajax({ @@ -1351,9 +1352,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } }).done(function (data) { - console.log(data); - var element2_name = element.attr('name').replace('idwarehouse', 'batch'); - var element2 = $("select[name*='" + element2_name + "']"); + console.log(data) + var selected = element2.val(); element2.empty(); @@ -1366,10 +1366,20 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $.each(data, function (key, value) { - element2.append($(''; + } else { + var option =''; + } + + element2.append(option); + }); }); @@ -1386,6 +1396,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea var element = $(this); + var element2_name = element.attr('name').replace('batch', 'idwarehouse'); + var element2 = $("select[name*='" + element2_name + "']"); + + var selected = element2.val(); + + if(selected != -1){ + return; + } + var product_element_name = element.attr('name').replace('batch', 'product'); $.ajax({ @@ -1398,24 +1417,11 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } }).done(function (data) { - var element2_name = element.attr('name').replace('batch', 'idwarehouse'); - var element2 = $("select[name*='" + element2_name + "']"); - - element2.empty(); - var data = JSON.parse(data); - element2.append($(''; return $out; } From f5446e0801ce5d0307acc19c35df8d7c0f3a58ee Mon Sep 17 00:00:00 2001 From: atm-lena Date: Tue, 25 Jan 2022 17:23:48 +0100 Subject: [PATCH 09/28] Clean --- htdocs/product/class/html.formproduct.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index ce4681db7ba..da10faa4f34 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -622,7 +622,7 @@ class FormProduct * @param array $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all. * @return string HTML datalist */ - public function selectLotDataList($htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $forcecombo = 0, $events = array(), $morecss = 'minwidth200', $disabled = 0, $selected = '', $empty_label = '') + public function selectLotDataList($htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array()) { global $conf, $langs; From 25e8a2c75833f29a3003127aeac3a0ddb306a74b Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 26 Jan 2022 09:40:15 +0100 Subject: [PATCH 10/28] Ajout interface.php --- htdocs/mrp/ajax/interface.php | 86 +++++++++++++++++++ htdocs/mrp/mo_production.php | 9 +- .../product/class/html.formproduct.class.php | 2 +- 3 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 htdocs/mrp/ajax/interface.php diff --git a/htdocs/mrp/ajax/interface.php b/htdocs/mrp/ajax/interface.php new file mode 100644 index 00000000000..b91cfc34c13 --- /dev/null +++ b/htdocs/mrp/ajax/interface.php @@ -0,0 +1,86 @@ + 0) $sql .= " AND fk_entrepot = '" . $warehouse_id . "'"; + $sql .= " ORDER BY e.ref, pb.batch"; + + $resql = $db->query($sql); + + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + $TRes[$obj->batch] += $obj->qty; + } + } + + print json_encode($TRes); +} elseif($action == 'updateselectwarehousebybatch'){ + + $res = 0; + + $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty"; + $sql .= " FROM " . MAIN_DB_PREFIX . "product_batch as pb"; + $sql .= " JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.rowid = pb.fk_product_stock"; + $sql .= " JOIN " . MAIN_DB_PREFIX . "entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (" . getEntity('stock') . ")"; + $sql .= " WHERE ps.fk_product = '" . $fk_product . "'"; + if ($batch_id > 0) $sql.= " AND pb.batch = '" . $batch_id . "'"; + $sql .= " ORDER BY e.ref, pb.batch"; + + $resql = $db->query($sql); + + if($resql){ + if($db->num_rows($resql) == 1){ + $obj = $db->fetch_object($resql); + $res = $obj->fk_entrepot; + } + } + + print json_encode($res); + +} + + + diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index a9d56c1a850..cfb1616e751 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -1027,8 +1027,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($tmpproduct->status_batch) { $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : ''); print ''; - print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 1, $line->fk_product, ''); -// print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); + print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');// print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); } print ''; } @@ -1357,7 +1356,6 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea }).done(function (data) { selectbatch.empty(); - $('input[name*='+selectbatch_name+']').val(''); var data = JSON.parse(data); @@ -1381,11 +1379,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } selectbatch.append(option); - }); - }); - }); } @@ -1420,14 +1415,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea } }).done(function (data) { - console.log(data); var data = JSON.parse(data); if(data != 0){ selectwarehouse.val(data).change(); } }); - }); } diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index da10faa4f34..b9a01af1666 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -659,7 +659,7 @@ class FormProduct if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) { $label = $arraytypes['entrepot_label'].' - '; $label .= $arraytypes['batch']; - $out .= ''; + $out .= ''; } } } From ccacf2e89aee64b9f16a070d7546027266cd2311 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Wed, 26 Jan 2022 09:49:06 +0100 Subject: [PATCH 11/28] Clean code --- htdocs/mrp/ajax/interface.php | 6 +----- htdocs/mrp/mo_production.php | 16 ++++------------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/htdocs/mrp/ajax/interface.php b/htdocs/mrp/ajax/interface.php index b91cfc34c13..45709b81ac0 100644 --- a/htdocs/mrp/ajax/interface.php +++ b/htdocs/mrp/ajax/interface.php @@ -1,16 +1,12 @@ id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($tmpproduct->status_batch) { $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : ''); print ''; - print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');// print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product); + print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', ''); } print ''; } @@ -1324,25 +1324,23 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea - Date: Tue, 4 Apr 2023 23:35:42 +0200 Subject: [PATCH 28/28] Update interface.php --- htdocs/mrp/ajax/interface.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/mrp/ajax/interface.php b/htdocs/mrp/ajax/interface.php index 4822294a95c..195c9a570bd 100644 --- a/htdocs/mrp/ajax/interface.php +++ b/htdocs/mrp/ajax/interface.php @@ -23,15 +23,24 @@ if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } -global $db, $langs; - require '../../main.inc.php'; // Load $user and permissions $warehouse_id = GETPOST('warehouse_id', 'int'); $batch = GETPOST('batch', 'alphanohtml'); $fk_product = GETPOST('product_id', 'int'); $action = GETPOST('action', 'alphanohtml'); -$permissiontoproduce = GETPOST('permissiontoproduce', 'int'); + +$result = restrictedArea($user, 'mrp'); + +$permissiontoproduce = $user->rights->mrp->write; + + + +/* + * View + */ + +top_httphead("application/json"); if ($action == 'updateselectbatchbywarehouse' && $permissiontoproduce) { $TRes = array(); @@ -57,7 +66,6 @@ if ($action == 'updateselectbatchbywarehouse' && $permissiontoproduce) { } echo json_encode($TRes); - exit(); } elseif ($action == 'updateselectwarehousebybatch' && $permissiontoproduce) { $res = 0; @@ -79,5 +87,4 @@ if ($action == 'updateselectbatchbywarehouse' && $permissiontoproduce) { } echo json_encode($res); - exit(); }