From 990e1daf641fb4d194717b02d94b5c1820e039bc Mon Sep 17 00:00:00 2001 From: Christian Humpel Date: Sat, 3 Dec 2022 13:55:30 +0100 Subject: [PATCH 1/8] Fix #23089 correct typing error. --- htdocs/product/stock/replenish.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index be7f006d5a0..d1644623ce1 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -465,7 +465,7 @@ if ($usevirtualstock) { $sqlProductionToConsume .= " ".MAIN_DB_PREFIX."mrp_production as mp5"; $sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")"; $sqlProductionToConsume .= " AND mp5.fk_product = p.rowid"; - $sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consummed')"; + $sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consumed')"; $sqlProductionToConsume .= " AND mm5.status IN (1,2))"; $sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL From 1d39a1e1e9423875d95c56f50242694f1c71e2c5 Mon Sep 17 00:00:00 2001 From: Christian Humpel Date: Sat, 3 Dec 2022 22:16:30 +0100 Subject: [PATCH 2/8] Fix #23092 Add 'ref_supplier' on VAT updating. --- htdocs/fourn/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 1df6c37736b..f559c31a89f 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -419,7 +419,7 @@ if (empty($reshook)) { $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); foreach ($object->lines as $line) { - $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); + $result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier); } } elseif ($action == 'addline' && $usercancreate) { $db->begin(); From 118787934c9fe1f7b7269f359cf9766dbf712277 Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Mon, 5 Dec 2022 00:29:04 +0100 Subject: [PATCH 3/8] fix #23099 : pass massaction to hook instead of action --- htdocs/core/tpl/massactions_pre.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index dc0a9d4bb8c..973ffe3123a 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -197,7 +197,7 @@ $parameters = array( 'uploaddir' => isset($uploaddir) ? $uploaddir : null ); -$reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action); +$reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $massaction); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } else { From 51ab2fe3b17e94d6dabb6a19e8513194f42a3e40 Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Mon, 5 Dec 2022 00:32:01 +0100 Subject: [PATCH 4/8] better fix to be more close to doMassActions --- htdocs/core/tpl/massactions_pre.tpl.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 973ffe3123a..88d1c812388 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -194,10 +194,11 @@ if ($massaction == 'presend') { // Allow Pre-Mass-Action hook (eg for confirmation dialog) $parameters = array( 'toselect' => $toselect, - 'uploaddir' => isset($uploaddir) ? $uploaddir : null + 'uploaddir' => isset($uploaddir) ? $uploaddir : null, + 'massaction' => $massaction ); -$reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $massaction); +$reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } else { From a300f3cfeb5755986224eee774a77823c126ab2b Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Mon, 5 Dec 2022 00:35:06 +0100 Subject: [PATCH 5/8] to be develop compatible --- htdocs/core/tpl/massactions_pre.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 88d1c812388..db959acd0b0 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -193,7 +193,7 @@ if ($massaction == 'presend') { } // Allow Pre-Mass-Action hook (eg for confirmation dialog) $parameters = array( - 'toselect' => $toselect, + 'toselect' => isset($toselect) ? $toselect : array(), 'uploaddir' => isset($uploaddir) ? $uploaddir : null, 'massaction' => $massaction ); From cf02d33ab09fae2461f2a8431f9e95b0148cb4e1 Mon Sep 17 00:00:00 2001 From: kkhelifa Date: Mon, 5 Dec 2022 11:11:18 +0100 Subject: [PATCH 6/8] NEW: Replace event title by the email subject if option activated --- htdocs/core/actions_massactions.inc.php | 3 +++ htdocs/core/actions_sendmails.inc.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index dced78b6c3c..ec2ecabcf0d 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -592,6 +592,9 @@ if (!$error && $massaction == 'confirm_presend') { $objectobj2->actionmsg2 = $actionmsg2; // Short text $objectobj2->fk_element = $objid2; $objectobj2->elementtype = $objectobj2->element; + if (!empty($conf->global->MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT)) { + $objectobj2->actionmsg2 = $subjectreplaced; // Short text + } $triggername = strtoupper(get_class($objectobj2)).'_SENTBYMAIL'; if ($triggername == 'SOCIETE_SENTBYMAIL') { diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 772d2b7ed5d..4f7580bb8ca 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -382,6 +382,9 @@ if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPO $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) $object->actionmsg = $message; // Long text $object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...); + if (!empty($conf->global->MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT)) { + $object->actionmsg2 = $subject; // Short text + } $object->trackid = $trackid; $object->fk_element = $object->id; From 816fea753ec3b7bd260ca0650e18fb9533693562 Mon Sep 17 00:00:00 2001 From: atm-lena Date: Mon, 5 Dec 2022 12:30:26 +0100 Subject: [PATCH 7/8] Extrafields BomLine --- htdocs/admin/bomline_extrafields.php | 114 +++++++++++++++++++++++ htdocs/bom/bom_card.php | 29 +++++- htdocs/bom/class/bom.class.php | 19 +++- htdocs/bom/lib/bom.lib.php | 5 + htdocs/bom/tpl/objectline_create.tpl.php | 11 +++ htdocs/bom/tpl/objectline_edit.tpl.php | 14 ++- htdocs/bom/tpl/objectline_view.tpl.php | 17 ++-- 7 files changed, 194 insertions(+), 15 deletions(-) create mode 100644 htdocs/admin/bomline_extrafields.php diff --git a/htdocs/admin/bomline_extrafields.php b/htdocs/admin/bomline_extrafields.php new file mode 100644 index 00000000000..1a21f052b84 --- /dev/null +++ b/htdocs/admin/bomline_extrafields.php @@ -0,0 +1,114 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2015 Jean-François Ferry + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/admin/bomline_extrafields.php + * \ingroup bom + * \brief Page to setup extra fields of BOM + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT . '/bom/lib/bom.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array('mrp', 'admin')); + +$extrafields = new ExtraFields($db); +$form = new Form($db); + +// List of supported format +$tmptype2label = ExtraFields::$type2label; +$type2label = array(''); +foreach ($tmptype2label as $key => $val) { + $type2label[$key] = $langs->transnoentitiesnoconv($val); +} + +$action = GETPOST('action', 'aZ09'); +$attrname = GETPOST('attrname', 'alpha'); +$elementtype = 'bom_bomline'; + +if (!$user->admin) { + accessforbidden(); +} + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php'; + + +/* + * View + */ + +$help_url = ''; +llxHeader('', $langs->trans("BOMLinesSetup"), $help_url); + + +$linkback = '' . $langs->trans("BackToModuleList") . ''; +print load_fiche_titre($langs->trans("BOMLinesSetup"), $linkback, 'title_setup'); + + +$head = bomAdminPrepareHead(); + +print dol_get_fiche_head($head, 'bomline_extrafields', $langs->trans("ExtraFields"), -1, 'account'); + +require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_view.tpl.php'; + +print dol_get_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') { + print '"; +} + + +/* + * Creation of an optional field + */ +if ($action == 'create') { + print '
'; + print load_fiche_titre($langs->trans('NewAttribute')); + + require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_add.tpl.php'; +} + +/* + * Edition of an optional field + */ +if ($action == 'edit' && !empty($attrname)) { + print "
"; + print load_fiche_titre($langs->trans("FieldEdition", $attrname)); + + require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_edit.tpl.php'; +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 89705c25ec5..8fb47f325cc 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -151,6 +151,7 @@ if (empty($reshook)) { if ($action == 'addline' && $user->rights->bom->write) { $langs->load('errors'); $error = 0; + $predef = ''; // Set if we used free entry or predefined product $bom_child_id = (int) GETPOST('bom_id', 'int'); @@ -194,7 +195,19 @@ if (empty($reshook)) { } if (!$error) { - $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit); + + // Extrafields + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_".$key]); + } + } + + $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -231,10 +244,22 @@ if (empty($reshook)) { } if (!$error) { + + // Extrafields + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_".$key]); + } + } + $bomline = new BOMLine($db); $bomline->fetch($lineid); - $result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key, $fk_unit); + $result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key, $fk_unit, $array_options); 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 d15de486560..cd5b119cabf 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -568,9 +568,10 @@ class BOM extends CommonObject * @param int $fk_bom_child Id of BOM Child * @param string $import_key Import Key * @param string $fk_unit Unit + * @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 = '') + 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) { global $mysoc, $conf, $langs, $user; @@ -640,6 +641,10 @@ class BOM extends CommonObject $this->line->position = $rankToUse; $this->line->fk_unit = $fk_unit; + if (is_array($array_options) && count($array_options) > 0) { + $this->line->array_options = $array_options; + } + $result = $this->line->create($user); if ($result > 0) { @@ -668,10 +673,11 @@ class BOM extends CommonObject * @param float $efficiency Efficiency in MO * @param int $position Position of BOM-Line in BOM-Lines * @param string $import_key Import Key - * @param int $fk_unit Unit of line + * @param int $fk_unit Unit of line + * @param array $array_options extrafields array * @return int <0 if KO, Id of updated BOM-Line if OK */ - public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null, $fk_unit = 0) + public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null, $fk_unit = 0, $array_options = 0) { global $mysoc, $conf, $langs, $user; @@ -745,6 +751,13 @@ class BOM extends CommonObject $this->line->fk_unit = $fk_unit; } + if (is_array($array_options) && count($array_options) > 0) { + // We replace values in this->line->array_options only for entries defined into $array_options + foreach ($array_options as $key => $value) { + $this->line->array_options[$key] = $array_options[$key]; + } + } + $result = $this->line->update($user); if ($result > 0) { diff --git a/htdocs/bom/lib/bom.lib.php b/htdocs/bom/lib/bom.lib.php index df06986362f..8d827ba09aa 100644 --- a/htdocs/bom/lib/bom.lib.php +++ b/htdocs/bom/lib/bom.lib.php @@ -46,6 +46,11 @@ function bomAdminPrepareHead() $head[$h][2] = 'bom_extrafields'; $h++; + $head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php"; + $head[$h][1] = $langs->trans("ExtraFieldsLines"); + $head[$h][2] = 'bomline_extrafields'; + $h++; + // Show more tabs from modules // Entries must be declared in modules descriptor with line //$this->tabs = array( diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php index 0243928116e..e644c7813e7 100644 --- a/htdocs/bom/tpl/objectline_create.tpl.php +++ b/htdocs/bom/tpl/objectline_create.tpl.php @@ -126,6 +126,17 @@ if (!empty($conf->global->BOM_SUB_BOM) && $filtertype!=1) { // TODO Add component to select a BOM $form->select_bom(); } + +if (is_object($objectline)) { + $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line'); + + if (!empty($temps)) { + print '
'; + print $temps; + print '
'; + } +} + print ''; diff --git a/htdocs/bom/tpl/objectline_edit.tpl.php b/htdocs/bom/tpl/objectline_edit.tpl.php index 0ce88fa359c..88463996ebc 100644 --- a/htdocs/bom/tpl/objectline_edit.tpl.php +++ b/htdocs/bom/tpl/objectline_edit.tpl.php @@ -93,6 +93,16 @@ if (is_object($hookmanager)) { $reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action); } +//Line extrafield +if (is_object($objectline) && !empty($extrafields)) { + $temps = $line->showOptionals($extrafields, 'edit', array('class'=>'tredited'), '', '', 1, 'line'); + if (!empty($temps)) { + print '
'; + print $temps; + print '
'; + } +} + print ''; /*if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines @@ -160,8 +170,4 @@ print '\n"; diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index e4636081655..b7087b27288 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -100,6 +100,17 @@ if ($tmpbom->id > 0) { print $tmpproduct->getNomUrl(1); print ' - '.$tmpproduct->label; } + +// Line extrafield +if (!empty($extrafields)) { + $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line'); + if (!empty($temps)) { + print '
'; + print $temps; + print '
'; + } +} + print ''; print ''; @@ -309,10 +320,4 @@ if ($total_cost > 0) { showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1, 'line'); -} - print "\n"; From d522e96744e5a9c69ca7a8f9edba72e5f081ed20 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 5 Dec 2022 11:33:44 +0000 Subject: [PATCH 8/8] Fixing style errors. --- htdocs/bom/bom_card.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 8fb47f325cc..333b6232f9f 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -195,7 +195,6 @@ if (empty($reshook)) { } if (!$error) { - // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); @@ -244,7 +243,6 @@ if (empty($reshook)) { } if (!$error) { - // Extrafields $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);