From ae7b8e7f5e3fcfddfe53897b8aed462aeaf70429 Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 6 Jan 2021 15:15:51 +0100 Subject: [PATCH 1/5] Fix unit selection on object edit line --- htdocs/core/class/html.form.class.php | 5 ++++- htdocs/core/tpl/objectline_edit.tpl.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6f2cbcd1955..97c26954bf7 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3892,7 +3892,7 @@ class Form * @param int $showempty Add a nempty line * @return string HTML select */ - public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0) + public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0, $unit_type = false) { global $langs; @@ -3902,6 +3902,9 @@ class Form $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; $sql .= ' WHERE active > 0'; + if(!empty($unit_type)){ + $sql .= ' AND unit_type = "'.$this->db->escape($unit_type).'" '; + } $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index bc6b87a3353..4546cb7d089 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -191,9 +191,20 @@ $coldisplay++; global->PRODUCT_USE_UNITS)) { + $unit_type = false; + // limit unit select to unit type + if(!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){ + if(!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; + $cUnit = new CUnits($line->db); + if($cUnit->fetch($line->fk_unit) > 0){ + if(!empty($cUnit->unit_type)){ + $unit_type = $cUnit->unit_type; + } + } + } $coldisplay++; print ''; - print $form->selectUnits($line->fk_unit, "units"); + print $form->selectUnits($line->fk_unit, "units", 0, $unit_type); print ''; } ?> From dd19da66b27778a8612cf1192a404bf0e61c649d Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 6 Jan 2021 17:33:19 +0100 Subject: [PATCH 2/5] fix stickler --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/tpl/objectline_edit.tpl.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 97c26954bf7..7d74276ce90 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3902,7 +3902,7 @@ class Form $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; $sql .= ' WHERE active > 0'; - if(!empty($unit_type)){ + if (!empty($unit_type)){ $sql .= ' AND unit_type = "'.$this->db->escape($unit_type).'" '; } diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 4546cb7d089..a59ab4b881a 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -194,10 +194,10 @@ $coldisplay++; $unit_type = false; // limit unit select to unit type if(!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){ - if(!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; + if (!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; $cUnit = new CUnits($line->db); - if($cUnit->fetch($line->fk_unit) > 0){ - if(!empty($cUnit->unit_type)){ + if ($cUnit->fetch($line->fk_unit) > 0){ + if (!empty($cUnit->unit_type)){ $unit_type = $cUnit->unit_type; } } From 7fb0eb575689f6c32da85806c454b757cf15ac3d Mon Sep 17 00:00:00 2001 From: ATM john Date: Wed, 6 Jan 2021 17:34:04 +0100 Subject: [PATCH 3/5] fix stickler --- htdocs/core/tpl/objectline_edit.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index a59ab4b881a..88dfa07e028 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -193,7 +193,7 @@ $coldisplay++; { $unit_type = false; // limit unit select to unit type - if(!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){ + if (!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){ if (!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; $cUnit = new CUnits($line->db); if ($cUnit->fetch($line->fk_unit) > 0){ From 312f11d7b3fae7a79265215f6b0ec45899fcee8c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jan 2021 10:30:11 +0100 Subject: [PATCH 4/5] Update objectline_edit.tpl.php --- htdocs/core/tpl/objectline_edit.tpl.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index 88dfa07e028..d524fe22bf8 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -189,15 +189,14 @@ $coldisplay++; global->PRODUCT_USE_UNITS)) - { + if (!empty($conf->global->PRODUCT_USE_UNITS)) { $unit_type = false; // limit unit select to unit type - if (!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)){ - if (!class_exists('CUnits')) include_once DOL_DOCUMENT_ROOT . '/core/class/cunits.class.php'; + if (!empty($line->fk_unit) && empty($conf->global->MAIN_EDIT_LINE_ALLOW_ALL_UNIT_TYPE)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php'; $cUnit = new CUnits($line->db); - if ($cUnit->fetch($line->fk_unit) > 0){ - if (!empty($cUnit->unit_type)){ + if ($cUnit->fetch($line->fk_unit) > 0) { + if (!empty($cUnit->unit_type)) { $unit_type = $cUnit->unit_type; } } From c2855d4d71d213b45624af9f6ca3d90da7f6a646 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 7 Jan 2021 10:32:23 +0100 Subject: [PATCH 5/5] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7d74276ce90..99dd80a8b2d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3890,9 +3890,10 @@ class Form * @param string $selected Preselected Unit ID * @param string $htmlname Select name * @param int $showempty Add a nempty line + * @param string $unit_type Restrict to one given unit type * @return string HTML select */ - public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0, $unit_type = false) + public function selectUnits($selected = '', $htmlname = 'units', $showempty = 0, $unit_type = '') { global $langs; @@ -3902,8 +3903,8 @@ class Form $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; $sql .= ' WHERE active > 0'; - if (!empty($unit_type)){ - $sql .= ' AND unit_type = "'.$this->db->escape($unit_type).'" '; + if (!empty($unit_type)) { + $sql .= " AND unit_type = '".$this->db->escape($unit_type)."'"; } $resql = $this->db->query($sql);