From 2582866fbe96f8d4b4725b78c533f79747127210 Mon Sep 17 00:00:00 2001 From: x Date: Wed, 19 Apr 2023 12:08:12 +0200 Subject: [PATCH 1/7] Add bom and mo line : add fk_defauult_workstation info --- htdocs/bom/bom_card.php | 9 ++++++++- htdocs/bom/class/bom.class.php | 4 +++- htdocs/mrp/class/mo.class.php | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index e27cd0a2e1c..14a165315f4 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -170,6 +170,13 @@ if (empty($reshook)) { $disable_stock_change = GETPOST('disable_stock_change', 'int'); $efficiency = price2num(GETPOST('efficiency', 'alpha')); $fk_unit = GETPOST('fk_unit', 'alphanohtml'); + + if(!empty($idprod)){ + $product = new Product($db); + $res = $product->fetch($idprod); + if($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; + } + if ($qty == '') { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; @@ -206,7 +213,7 @@ if (empty($reshook)) { } } - $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options); + $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options, $fk_default_workstation); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index e10139f3711..397537b8612 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -572,7 +572,7 @@ class BOM extends CommonObject * @param array $array_options extrafields array * @return int <0 if KO, Id of created object if OK */ - public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '', $array_options = 0) + public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '', $array_options = 0, $fk_default_workstation = null) { global $mysoc, $conf, $langs, $user; @@ -641,6 +641,7 @@ class BOM extends CommonObject $this->line->import_key = $import_key; $this->line->position = $rankToUse; $this->line->fk_unit = $fk_unit; + $this->line->fk_default_workstation = $fk_default_workstation; if (is_array($array_options) && count($array_options) > 0) { $this->line->array_options = $array_options; @@ -1670,6 +1671,7 @@ class BOMLine extends CommonObjectLine 'fk_unit' => array('type'=>'integer', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'position'=>120, 'notnull'=>-1,), 'position' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'default'=>0, 'position'=>200, 'notnull'=>1,), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,), + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>25) ); /** diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index f7587daf331..20eb3a94704 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -741,6 +741,7 @@ class Mo extends CommonObject $moline->position = $line->position; $moline->qty_frozen = $line->qty_frozen; $moline->disable_stock_change = $line->disable_stock_change; + if(!empty($line->fk_default_workstation)) $moline->fk_default_workstation = $line->fk_default_workstation; $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { @@ -1720,6 +1721,7 @@ class MoLine extends CommonObjectLine 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>170), 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>180), + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25), ); public $rowid; From ff33e3c367b1fbb53ea4df3400422ecdc8b2524c Mon Sep 17 00:00:00 2001 From: x Date: Wed, 19 Apr 2023 12:17:04 +0200 Subject: [PATCH 2/7] Add line mo : fk_default_workstation --- htdocs/mrp/mo_production.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index ac0aa60a647..a6f4a241f2f 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -169,6 +169,12 @@ if (empty($reshook)) { $moline->origin_type = 'free'; // free consume line $moline->position = 0; + if(!empty($moline->fk_product)){ + $product = new Product($db); + $product->fetch($moline->fk_product); + if($product->type == Product::TYPE_SERVICE) $moline->fk_default_workstation = $product->fk_default_workstation; + } + $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { $error++; From fde16f42c9a7483be4cff6745c78ae5e11ee804d Mon Sep 17 00:00:00 2001 From: x Date: Wed, 19 Apr 2023 12:23:48 +0200 Subject: [PATCH 3/7] Clean fields mo and bom fk_default_workstation --- htdocs/bom/class/bom.class.php | 2 +- htdocs/mrp/class/mo.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 397537b8612..933d27e3f6a 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -1671,7 +1671,7 @@ class BOMLine extends CommonObjectLine 'fk_unit' => array('type'=>'integer', 'label'=>'Unit', 'enabled'=>1, 'visible'=>1, 'position'=>120, 'notnull'=>-1,), 'position' => array('type'=>'integer', 'label'=>'Rank', 'enabled'=>1, 'visible'=>0, 'default'=>0, 'position'=>200, 'notnull'=>1,), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>1000, 'notnull'=>-1,), - 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>25) + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>1050) ); /** diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 20eb3a94704..fd0559c3d34 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1721,7 +1721,7 @@ class MoLine extends CommonObjectLine 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>170), 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>180), - 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>25), + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>185) ); public $rowid; From a5c4ec5dcfc221c6e73f3768dec6b7731a1a0fca Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 19 Apr 2023 16:22:47 +0000 Subject: [PATCH 4/7] Fixing style errors. --- htdocs/bom/bom_card.php | 4 ++-- htdocs/mrp/class/mo.class.php | 4 ++-- htdocs/mrp/mo_production.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 14a165315f4..dde7789f840 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -171,10 +171,10 @@ if (empty($reshook)) { $efficiency = price2num(GETPOST('efficiency', 'alpha')); $fk_unit = GETPOST('fk_unit', 'alphanohtml'); - if(!empty($idprod)){ + if (!empty($idprod)) { $product = new Product($db); $res = $product->fetch($idprod); - if($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; + if ($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; } if ($qty == '') { diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index fd0559c3d34..5892c34f72f 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -741,7 +741,7 @@ class Mo extends CommonObject $moline->position = $line->position; $moline->qty_frozen = $line->qty_frozen; $moline->disable_stock_change = $line->disable_stock_change; - if(!empty($line->fk_default_workstation)) $moline->fk_default_workstation = $line->fk_default_workstation; + if (!empty($line->fk_default_workstation)) $moline->fk_default_workstation = $line->fk_default_workstation; $resultline = $moline->create($user, false); // Never use triggers here if ($resultline <= 0) { @@ -1721,7 +1721,7 @@ class MoLine extends CommonObjectLine 'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>170), 'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModification', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-1, 'position'=>180), - 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>185) + 'fk_default_workstation' =>array('type'=>'integer', 'label'=>'DefaultWorkstation', 'enabled'=>1, 'visible'=>1, 'notnull'=>0, 'position'=>185) ); public $rowid; diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index a6f4a241f2f..49a094b89e4 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -169,10 +169,10 @@ if (empty($reshook)) { $moline->origin_type = 'free'; // free consume line $moline->position = 0; - if(!empty($moline->fk_product)){ + if (!empty($moline->fk_product)) { $product = new Product($db); $product->fetch($moline->fk_product); - if($product->type == Product::TYPE_SERVICE) $moline->fk_default_workstation = $product->fk_default_workstation; + if ($product->type == Product::TYPE_SERVICE) $moline->fk_default_workstation = $product->fk_default_workstation; } $resultline = $moline->create($user, false); // Never use triggers here From dd5c61d9f2adeced4cf761583f589ca220b657d2 Mon Sep 17 00:00:00 2001 From: x Date: Thu, 20 Apr 2023 09:57:49 +0200 Subject: [PATCH 5/7] Bom : Display workstation of line --- htdocs/bom/bom_card.php | 2 +- htdocs/bom/tpl/objectline_view.tpl.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 14a165315f4..001d5fa3c05 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -171,7 +171,7 @@ if (empty($reshook)) { $efficiency = price2num(GETPOST('efficiency', 'alpha')); $fk_unit = GETPOST('fk_unit', 'alphanohtml'); - if(!empty($idprod)){ + if(!empty($idprod) && $conf->workstation->enabled){ $product = new Product($db); $res = $product->fetch($idprod); if($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation; diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index d000118e1b9..cfe63286339 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -158,9 +158,10 @@ if ($filtertype != 1) { // Work station if (isModEnabled('workstation')) { $workstation = new Workstation($object->db); - $res = $workstation->fetch($tmpproduct->fk_default_workstation); + $fk_default_workstation = (!empty($line->fk_default_workstation)) ? $line->fk_default_workstation : $tmpproduct->fk_default_workstation; + $res = $workstation->fetch($fk_default_workstation); - print ''; + print ''; $coldisplay++; if ($res > 0) echo $workstation->getNomUrl(); print ''; From 8643495361c1ffaf95c8edde5d8484cffc8c5d55 Mon Sep 17 00:00:00 2001 From: x Date: Thu, 20 Apr 2023 10:19:43 +0200 Subject: [PATCH 6/7] BOM : Display only Default Workstation of line --- htdocs/bom/tpl/objectline_view.tpl.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index cfe63286339..6463f45fbb0 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -158,8 +158,7 @@ if ($filtertype != 1) { // Work station if (isModEnabled('workstation')) { $workstation = new Workstation($object->db); - $fk_default_workstation = (!empty($line->fk_default_workstation)) ? $line->fk_default_workstation : $tmpproduct->fk_default_workstation; - $res = $workstation->fetch($fk_default_workstation); + $res = $workstation->fetch($line->fk_default_workstation); print ''; $coldisplay++; From b4d4b96dc434ecac10565245c82494a003803cfc Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 26 Apr 2023 09:10:37 +0000 Subject: [PATCH 7/7] Fixing style errors. --- htdocs/bom/bom_card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 5eaec818d0f..b1db4a5c824 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -171,7 +171,7 @@ if (empty($reshook)) { $efficiency = price2num(GETPOST('efficiency', 'alpha')); $fk_unit = GETPOST('fk_unit', 'alphanohtml'); - if(!empty($idprod) && $conf->workstation->enabled){ + if (!empty($idprod) && $conf->workstation->enabled) { $product = new Product($db); $res = $product->fetch($idprod); if ($res > 0 && $product->type == Product::TYPE_SERVICE) $fk_default_workstation = $product->fk_default_workstation;