diff --git a/admin/infrastructuresetup.php b/admin/infrastructuresetup.php index 1d5b68d..ef270b9 100644 --- a/admin/infrastructuresetup.php +++ b/admin/infrastructuresetup.php @@ -248,11 +248,11 @@ function infrastructureResetSelect2Width($container) { infrastructure_print_subTitle(4, 'InfrastructureSetupForExtrafields'); $metas = ['class' => 'flat infrastructurewidth270 infrastructurefontsizeinherit']; $num = infrastructure_print_input('INFRASTRUCTURE_ALLOW_EXTRAFIELDS_ON_TITLE', 'on_off', $langs->trans('InfrastructureAllowExtrafieldsOnTitle'), '', [], 2, 1, '', $num); - $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_PROPALDET', $extrafields->fetch_name_optionals_label('propaldet'), $propalSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); + $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_PROPALDET', getVisibleExtrafields('propaldet'), $propalSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); $num = infrastructure_print_input('', 'select', $langs->trans('InfrastructureListOfExtrafieldsPropaldet'), '', $metas, 1, 2, '', $num); - $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_COMMANDEDET', $extrafields->fetch_name_optionals_label('commandedet'), $orderSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); + $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_COMMANDEDET', getVisibleExtrafields('commandedet'), $orderSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); $num = infrastructure_print_input('', 'select', $langs->trans('InfrastructureListOfExtrafieldsCommandedet'), '', $metas, 1, 2, '', $num); - $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_FACTUREDET', $extrafields->fetch_name_optionals_label('facturedet'), $invoiceSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); + $metas = $form->multiselectarray('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_FACTUREDET', getVisibleExtrafields('facturedet'), $invoiceSelected, 0, 0, 'flat infrastructurewidth270 infrastructurefontsizeinherit', 0, 0, '', '', ''); $num = infrastructure_print_input('', 'select', $langs->trans('InfrastructureListOfExtrafieldsFacturedet'), '', $metas, 1, 2, '', $num); // num = 10 infrastructure_print_subTitle(4, 'InfrastructureSetupForShipping'); diff --git a/class/actions_infrastructure.class.php b/class/actions_infrastructure.class.php index 6f2d28f..faf2197 100644 --- a/class/actions_infrastructure.class.php +++ b/class/actions_infrastructure.class.php @@ -360,9 +360,7 @@ public function formBuilddocOptions($parameters, &$object, &$action, HookManager if (($object instanceof Propal && getDolGlobalString('INFRASTRUCTURE_PROPAL_ADD_RECAP')) || ($object instanceof Commande && getDolGlobalString('INFRASTRUCTURE_COMMANDE_ADD_RECAP')) || ($object instanceof Facture && getDolGlobalString('INFRASTRUCTURE_INVOICE_ADD_RECAP')) || - ($object instanceof FactureRec && getDolGlobalString('INFRASTRUCTURE_INVOICE_ADD_RECAP')) || - ($object instanceof CommandeFournisseur && getDolGlobalString('INFRASTRUCTURE_COMMANDE_ADD_RECAP')) || - ($object instanceof FactureFournisseur && getDolGlobalString('INFRASTRUCTURE_INVOICE_ADD_RECAP'))) + ($object instanceof FactureRec && getDolGlobalString('INFRASTRUCTURE_INVOICE_ADD_RECAP'))) { $this->resprints .= ' diff --git a/class/infrastructure.class.php b/class/infrastructure.class.php index 0fd656e..48a9618 100644 --- a/class/infrastructure.class.php +++ b/class/infrastructure.class.php @@ -146,18 +146,17 @@ static function showQtyForObjectLine($line, $show_by_default = false) */ static function addInfrastructureLine(&$object, $label, $qty, $rang=-1, $desc = '') { - $res = 0; - $desc = ''; - $TNotElements = ['invoice_supplier', 'order_supplier']; + $res = 0; + $desc = ''; + $TNotElements = ['invoice_supplier', 'order_supplier']; if ($qty == 50 && !in_array($object->element, $TNotElements)) { - $desc = $label; - $label = ''; + $desc = $label; + $label = ''; } if ($object->element=='facture') { $res = $object->addline($desc, 0, $qty, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT', 0, 9, $rang, TInfrastructure::getModuleNumber(), '', 0, 0, null, 0, $label); } elseif ($object->element=='invoice_supplier') { - $object->special_code = TInfrastructure::getModuleNumber(); - $res = $object->addline($label, 0, 0, 0, 0, $qty, 0, 0, 0, 0, 0, 0, 'HT', 9, $rang, false, [], null, 0, 0, '', TInfrastructure::getModuleNumber()); + $res = $object->addline($label, 0, 0, 0, 0, $qty, 0, 0, 0, 0, 0, 0, 'HT', 9, $rang, false, [], null, 0, 0, '', TInfrastructure::getModuleNumber()); } elseif ($object->element=='propal') { $res = $object->addline($desc, 0, $qty, 0, 0, 0, 0, 0, 'HT', 0, 0, 9, $rang, TInfrastructure::getModuleNumber(), 0, 0, 0, $label); } elseif ($object->element=='supplier_proposal') { @@ -165,10 +164,9 @@ static function addInfrastructureLine(&$object, $label, $qty, $rang=-1, $desc = } elseif ($object->element=='commande') { $res = $object->addline($desc, 0, $qty, 0, 0, 0, 0, 0, 0, 0, 'HT', 0, '', '', 9, $rang, TInfrastructure::getModuleNumber(), 0, null, 0, $label); } elseif ($object->element=='order_supplier') { - $object->special_code = TInfrastructure::getModuleNumber(); // à garder pour la rétrocompatibilité - $res = $object->addline($label, 0, $qty, 0, 0, 0, 0, 0, '', 0, 'HT', 0, 9, 0, false, null, null, 0, null, 0, '', 0, -1, TInfrastructure::getModuleNumber()); + $res = $object->addline($label, 0, $qty, 0, 0, 0, 0, 0, '', 0, 'HT', 0, 9, 0, false, null, null, 0, null, 0, '', 0, $rang, TInfrastructure::getModuleNumber()); } elseif ($object->element=='facturerec') { - $res = $object->addline($desc, 0, $qty, 0, 0, 0, 0, 0, 'HT', 0, '', 0, 9, $rang, TInfrastructure::getModuleNumber(), $label); + $res = $object->addline($desc, 0, $qty, 0, 0, 0, 0, 0, 'HT', 0, '', 0, 9, $rang, TInfrastructure::getModuleNumber(), $label); } self::generateDoc($object); return $res; diff --git a/core/lib/infrastructure.lib.php b/core/lib/infrastructure.lib.php index b276cb5..2d3844c 100644 --- a/core/lib/infrastructure.lib.php +++ b/core/lib/infrastructure.lib.php @@ -101,6 +101,26 @@ function infrastructure_addNumerotation(&$object) } } + /** + * List extrafields with "list"(Visible field) attribute > 0 for a given element type (propaldet, commandedet, ...) + * + * @param string $elementtype Element type (propaldet, commandedet, facturedet, ...) + * @return array List of extrafields [fieldname => label] + */ + function getVisibleExtrafields($elementtype) { + global $db; + + $extrafields = new ExtraFields($db); + $all = $extrafields->fetch_name_optionals_label($elementtype); + $list = []; + foreach ($all as $key => $label) { + if ((int) ($extrafields->attributes[$elementtype]['list'][$key] ?? 0) > 0) { + $list[$key] = $label; + } + } + return $list; + } + /** * Ajax block order JS * @@ -229,10 +249,10 @@ function infrastructure_billOrdersAddCheckBoxForTitleBlocks() ob_start(); $jsConf = ['langs' => ['AddTitleBlocFromOrdersToInvoice' => $langs->trans('InfrastructureAddTitleBlocFromOrderstoinvoice'), - 'AddShippingListToTile' => $langs->trans('InfrastructureAddShippingListToTile'), - 'InfrastructureOptions' => $langs->trans('InfrastructureOptions'), - 'UseHiddenConfToAutoCheck' => $langs->trans('InfrastructureUseHiddenConfToAutoCheck'), - ], + 'AddShippingListToTile' => $langs->trans('InfrastructureAddShippingListToTile'), + 'InfrastructureOptions' => $langs->trans('InfrastructureOptions'), + 'UseHiddenConfToAutoCheck' => $langs->trans('InfrastructureUseHiddenConfToAutoCheck'), + ], 'isModShippingEnable' => isModEnabled('expedition'), 'INFRASTRUCTURE_DEFAULT_CHECK_SHIPPING_LIST_FOR_TITLE_DESC' => getDolGlobalInt('INFRASTRUCTURE_DEFAULT_CHECK_SHIPPING_LIST_FOR_TITLE_DESC') ]; @@ -753,15 +773,11 @@ function infrastructure_updateInfrastructureLine(&$object, &$line) } // TODO ajouter la partie fournisseur if (!empty($TKey)) { - $extrafields = new ExtraFields($object->db); - $extrafields->fetch_name_optionals_label($line->element); - $TPost = $extrafields->getOptionalsFromPost($line->element, '', 'infrastructure_'); - $TLine = TInfrastructure::getLinesFromTitleId($object, $line->id); + $TLine = TInfrastructure::getLinesFromTitleId($object, $line->id); foreach ($TLine as $object_line) { foreach ($TKey as $key) { - // TODO remove "true" - if (isset($TPost['infrastructure_options_'.$key])) { - $object_line->array_options['options_'.$key] = $TPost['infrastructure_options_'.$key]; + if (array_key_exists('options_'.$key, $line->array_options)) { + $object_line->array_options['options_'.$key] = $line->array_options['options_'.$key]; } } $object_line->insertExtraFields(); @@ -781,14 +797,20 @@ function infrastructure_updateInfrastructureBloc($object, $line) { global $langs; - $infrastructure_tva_tx = $infrastructure_tva_tx_init = GETPOST('infrastructure_tva_tx', 'int'); - $infrastructure_progress = $infrastructure_progress_init = GETPOST('infrastructure_progress', 'int'); - $array_options = $line->array_options; - $showBlockExtrafields = GETPOST('showBlockExtrafields', 'aZ09'); + $infrastructure_tva_tx = $infrastructure_tva_tx_init = GETPOST('infrastructure_tva_tx', 'int'); + $infrastructure_progress = $infrastructure_progress_init = GETPOST('infrastructure_progress', 'int'); + $array_options = $line->array_options; + $showBlockExtrafields = GETPOST('showBlockExtrafields', 'aZ09'); if ($infrastructure_tva_tx != '' || $infrastructure_progress != '' || (!empty($showBlockExtrafields) && !empty($array_options))) { $error_progress = $nb_progress_update = $nb_progress_not_updated = 0; - $TLine = TInfrastructure::getLinesFromTitleId($object, $line->id); + $parentTitleId = $line->id; + $TLine = TInfrastructure::getLinesFromTitleId($object, $line->id, true); + // Clés propres au module infrastructure — ne pas les propager aux titres enfants + $infrastructureOwnKeys = ['options_show_total_ht', 'options_show_reduc', 'options_infrastructure_show_qty', 'options_hideblock', 'options_show_table_header_before', 'options_print_as_list', 'options_print_condensed', 'options_infrastructure_ol']; foreach ($TLine as &$line) { + if ($line->id == $parentTitleId || TInfrastructure::isTotal($line)) { + continue; // Ignorer le titre parent lui-même et les sous-totaux + } if (!TInfrastructure::isModInfrastructureLine($line)) { $infrastructure_tva_tx = $infrastructure_tva_tx_init; // ré-init car la variable peut évoluer if (!empty($showBlockExtrafields)) { @@ -815,6 +837,14 @@ function infrastructure_updateInfrastructureBloc($object, $line) } else { $error_updated_line++; } + } elseif (TInfrastructure::isTitle($line) && !empty($showBlockExtrafields) && !empty($array_options)) { + // Titre enfant : propager uniquement les extrafields non gérés par infrastructure + foreach ($array_options as $optKey => $optVal) { + if (!in_array($optKey, $infrastructureOwnKeys)) { + $line->array_options[$optKey] = $optVal; + } + } + $line->insertExtraFields(); } } if ($nb_progress_not_updated > 0) { diff --git a/core/tpl/infrastructureline_edit.tpl.php b/core/tpl/infrastructureline_edit.tpl.php index e6e80ae..cd90a06 100644 --- a/core/tpl/infrastructureline_edit.tpl.php +++ b/core/tpl/infrastructureline_edit.tpl.php @@ -190,31 +190,9 @@ if (getDolGlobalString('FCKEDITOR_ENABLE_DETAILS_FULL')) { $toolbarname = 'dolibarr_notes'; } + echo '
'; $doleditor = new DolEditor('line-description', $line->description, '', 100, $toolbarname, '', false, true, $cked_enabled, $nbrows, '98%', (bool) $readonlyForSituation); $doleditor->Create(); - $TKey = null; - if ($line->element == 'propaldet') { - $TKey = explode(',', getDolGlobalString('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_PROPALDET')); - } elseif ($line->element == 'commandedet') { - $TKey = explode(',', getDolGlobalString('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_COMMANDEDET')); - } elseif ($line->element == 'facturedet') { - $TKey = explode(',', getDolGlobalString('INFRASTRUCTURE_LIST_OF_EXTRAFIELDS_FACTUREDET')); - } - // TODO ajouter la partie fournisseur - if (!empty($TKey)) { - $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($object->table_element_line); - if (!empty($extrafields->attributes[$line->element]['param'])) { - foreach ($extrafields->attributes[$line->element]['param'] as $code => $val) { - if (in_array($code, $TKey) && $extrafields->attributes[$line->element]['list'][$code] > 0) { - print '
- '; - print $extrafields->showInputField($code, $line->array_options['options_'.$code], '', '', 'infrastructure_', '', 0, $object->table_element_line); - print '
'; - } - } - } - } } ?> \ No newline at end of file diff --git a/core/tpl/infrastructureline_row_document.tpl.php b/core/tpl/infrastructureline_row_document.tpl.php index c789361..e2b6910 100644 --- a/core/tpl/infrastructureline_row_document.tpl.php +++ b/core/tpl/infrastructureline_row_document.tpl.php @@ -252,15 +252,15 @@ fetch_name_optionals_label($object->table_element_line); $mode = $action === 'editline' && $line->rowid == GETPOST('lineid', 'int') ? 'edit' : 'view'; $ex_element = $line->element; $line->element = 'tr_extrafield_title '.$line->element; // Pour pouvoir manipuler ces tr $isExtraSelected = false; + $bgBrightness = colorLighten(getDolGlobalString('INFRASTRUCTURE_TITLE_BACKGROUND_COLOR'), 25); $colspan += 5; - print $line->showOptionals($extrafieldsline, $mode, ['style' => ' style="background:#eeffee;" ', 'colspan' => $colspan]); foreach ($line->array_options as $option) { if (!empty($option) && $option != "-1") { $isExtraSelected = true; @@ -268,7 +268,8 @@ } } if ($mode === 'edit') { - ?> + print $line->showOptionals($extrafieldsline, $mode, ['style' => ' style="background:'.$bgBrightness.';color:'.getDolGlobalString('INFRASTRUCTURE_TITLE_COLOR').';" ', 'colspan' => $colspan]); + ?>