dolibarr 25.0.0-alpha
subtotal_create.tpl.php
1<?php
2/* Copyright (C) 2014-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
35'
36@phan-var-force CommonObject $this
37@phan-var-force Propal|Commande|Facture|FactureRec|Expedition|SupplierProposal|CommandeFournisseur|FactureFournisseur $object
38@phan-var-force ?array<int,string> $depth_array
39@phan-var-force ?array<string,string> $titles
40@phan-var-force string $type
41';
42
43$depth_array = $depth_array ?? array();
44$titles = $titles ?? array();
45
46if ($type == 'subtotal' && empty($titles)) {
47 setEventMessages("NoTitleError", null, 'errors');
48 return;
49}
50
51$formquestion = array();
52
53if ($type == 'title') {
54 $formquestion = array();
55
56 $predefinedtitles = $object->getPredefinedTitles();
57 if (!empty($predefinedtitles)) {
58 // The visible option label is exactly the title to insert, so read it from the selected
59 // option (already escaped by selectarray, decoded by the browser) instead of shipping a map.
60 $formquestion[] = array(
61 'type' => 'select',
62 'name' => 'subtotalpredefinedtitle',
63 'label' => $langs->trans("PredefinedTitle"),
64 'values' => $predefinedtitles,
65 'select_show_empty' => 1,
66 'moreattr' => 'onchange="var o = this.options[this.selectedIndex]; if (o.value && o.value != \'-1\') { jQuery(\'#subtotallinedesc\').val(o.text); }"',
67 );
68 }
69
70 $formquestion = array_merge($formquestion, array(
71 array('type' => 'text', 'name' => 'subtotallinedesc', 'label' => $langs->trans("SubtotalLineDesc"), 'moreattr' => 'placeholder="' . $langs->trans("Description") . '"'),
72 array('type' => 'select', 'name' => 'subtotallinelevel', 'label' => $langs->trans("SubtotalLineLevel"), 'values' => $depth_array, 'default' => 1, 'select_show_empty' => 0),
73 array('type' => 'checkbox', 'value' => true, 'name' => 'titleshowuponpdf', 'label' => $langs->trans("ShowUPOnPDF")),
74 array('type' => 'checkbox', 'value' => true, 'name' => 'titleshowtotalexludingvatonpdf', 'label' => $langs->trans("ShowTotalExludingVATOnPDF")),
75 array('type' => 'checkbox', 'value' => false, 'name' => 'titleforcepagebreak', 'label' => $langs->trans("ForcePageBreak")),
76 ));
77} elseif ($type == 'subtotal') {
78 $formquestion = array(
79 array('type' => 'select', 'name' => 'subtotaltitleline', 'label' => $langs->trans("CorrespondingTitleLine"), 'values' => $titles, 'select_show_empty' => 0),
80 array('type' => 'hidden', 'value' => true, 'name' => 'subtotalshowtotalexludingvatonpdf', 'label' => $langs->trans("ShowTotalExludingVATOnPDF")),
81 );
82} elseif ($type == 'text') {
83 $formquestion = array();
84
85 $predefinedtexts = $object->getPredefinedTexts();
86 if (!empty($predefinedtexts)) {
87 $predefinedtextvalues = array();
88 $predefinedtextsmap = array();
89 foreach ($predefinedtexts as $rowid => $text) {
90 $predefinedtextvalues[$rowid] = $text['label'];
91 $predefinedtextsmap[$rowid] = $text['content'];
92 }
93 print '<script>var subtotalPredefinedTextsMap = ' . json_encode($predefinedtextsmap, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) . ';</script>';
94 $formquestion[] = array(
95 'type' => 'select',
96 'name' => 'subtotalpredefinedtext',
97 'label' => $langs->trans("PredefinedText"),
98 'values' => $predefinedtextvalues,
99 'select_show_empty' => 1,
100 'moreattr' => 'onchange="var v = subtotalPredefinedTextsMap[jQuery(this).val()]; if (v !== undefined) { jQuery(\'#subtotaltextcontent\').val(v); }"',
101 );
102 }
103
104 $formquestion[] = array('type' => 'textarea', 'name' => 'subtotaltextcontent', 'label' => $langs->trans("SubtotalTextContent"), 'morecss' => 'quatrevingtpercent', 'moreattr' => 'rows="4"');
105}
106
107$page = $_SERVER["PHP_SELF"];
108
109if ($object->element == 'facture') {
110 $page .= '?facid=' . $object->id;
111} elseif (in_array($object->element, $object::$ALLOWED_TYPES)) { // @phan-suppress-current-line PhanUndeclaredStaticProperty
112 $page .= '?id=' . $object->id;
113}
114
115$form_title = $type == 'title' ? $langs->trans('AddTitleLine') : $langs->trans('AddSubtotalLine');
116
117print $form->formconfirm($page, $form_title, '', 'confirm_add' . $type . 'line', $formquestion, 'yes', 1);
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100