dolibarr 25.0.0-alpha
depreciation_options_view.tpl.php
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024 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 *
19 * Show extrafields. It also shows fields from hook formAssetAccountancyCode.
20 */
21
34'
35@phan-var-force ?Form $form
36@phan-var-force HookManager $hookmanager
37@phan-var-force array<string,mixed> $parameters
38@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
39';
40
41// Protection to avoid direct call of template
42if (empty($object) || !is_object($object)) {
43 print "Error, template page can't be called as URL";
44 exit(1);
45}
46
47
48if (!is_object($form)) {
49 $form = new Form($db);
50}
51
52
53?>
54<!-- BEGIN PHP TEMPLATE depreciation_options_view.tpl.php -->
55<?php
56
57if (!is_array($parameters)) {
58 $parameters = array();
59}
60if (empty($parameters['assetdepreciationoptions'])) {
61 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
62}
63$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
64print $hookmanager->resPrint;
65if ($reshook < 0) {
66 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
67}
68
69if (empty($reshook)) {
70 $class_type = get_class($object) == 'Asset' ? 0 : 1;
71
72 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
73 if (!empty($mode_info['enabled_field'])) {
74 $info = explode(':', $mode_info['enabled_field']);
75 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
76 continue;
77 }
78 }
79
80 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
81
82 $width = "pull-left";
83 print '<table class="liste centpercent '. $width .'" id="block_' . $mode_key . '">' . "\n";
84 print '<tr class="liste_titre"><td colspan="5">'.$langs->trans($mode_info['label']).'</td></tr>';
85 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
86 foreach ($mode_info['fields'] as $field_key => $field_info) {
87 if (!empty($field_info['enabled_field'])) {
88 $info = explode(':', $field_info['enabled_field']);
89 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
90 continue;
91 }
92 }
93 // Discard if extrafield is a hidden field on form
94 $isVisibleAbs = array_key_exists('visible', $field_info) ? abs((int) $field_info['visible']) : 0;
95 if (!in_array($isVisibleAbs, array(1, 3, 4, 5))) {
96 continue;
97 }
98 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
99 continue; // We don't want this field
100 }
101 // This loop walks the raw definition of the fields, not the one filtered by
102 // setInfosForMode(), so the fields reserved to an asset must be discarded here too
103 if (!empty($field_info['only_on_asset']) && !empty($class_type)) {
104 continue;
105 }
106 $key = $mode_key . '_' . $field_key;
107 $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key] ?? null;
108
109 print '<tr class="field_' . $key . '" id="block_' . $mode_key . '"><td';
110 print ' class="' . (empty($field_info['tdcss']) ? 'titlefieldmiddle' : $field_info['tdcss']) . ' fieldname_' . $key;
111 if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
112 print ' tdtop';
113 }
114 print '">';
115 if (!empty($field_info['help'])) {
116 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
117 } else {
118 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
119 print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
120 } else {
121 print $langs->trans($field_info['label']);
122 }
123 }
124 print '</td>';
125 print '<td class="valuefield fieldname_' . $key;
126 if ($field_info['type'] == 'text') {
127 print ' wordbreak';
128 }
129 if (!empty($field_info['cssview'])) {
130 print ' ' . $field_info['cssview'];
131 }
132 print '">';
133 if (in_array($field_info['type'], array('text', 'html'))) {
134 print '<div class="longmessagecut">';
135 }
136 if ($field_key == 'rate') {
137 // The rate is provided by the core, by getRate(), and has no column in the table. It is
138 // declared with a 'computed' expression, which routes showOutputField() to dol_eval().
139 // dol_eval() then refuses getRate(), absent from $dolibarr_main_restrict_eval_methods,
140 // and every asset shows "Bad string syntax to evaluate ..." instead of its rate.
141 print $assetdepreciationoptions->getRate($mode_key);
142 } elseif ($field_key == 'lang') {
143 $langs->load("languages");
144 $labellang = ($value ? $langs->trans('Language_' . $value) : '');
145 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
146 print $labellang;
147 } else {
148 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
149 $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
150 print showValueWithClipboardCPButton($out, 0, $out);
151 } else {
152 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
153 }
154 }
155 if (in_array($field_info['type'], array('text', 'html'))) {
156 print '</div>';
157 }
158 print '</td>';
159 print '</tr>';
160 }
161 print '</table>';
162 print '<div class="clearboth"></div>';
163 print '<br>';
164 }
165}
166
167?>
168<!-- END PHP TEMPLATE depreciation_options_view.tpl.php -->
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage generation of HTML components Only common components must be here.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).