dolibarr 24.0.1
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 AssetDepreciationOptions $assetdepreciationoptions
38';
39
40// Protection to avoid direct call of template
41if (empty($object) || !is_object($object)) {
42 print "Error, template page can't be called as URL";
43 exit(1);
44}
45
46
47if (!is_object($form)) {
48 $form = new Form($db);
49}
50
51
52?>
53<!-- BEGIN PHP TEMPLATE depreciation_options_view.tpl.php -->
54<?php
55
56if (!is_array($parameters)) {
57 $parameters = array();
58}
59if (empty($parameters['assetdepreciationoptions'])) {
60 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
61}
62$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
63print $hookmanager->resPrint;
64if ($reshook < 0) {
65 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66}
67
68if (empty($reshook)) {
69 $class_type = get_class($object) == 'Asset' ? 0 : 1;
70
71 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
72 if (!empty($mode_info['enabled_field'])) {
73 $info = explode(':', $mode_info['enabled_field']);
74 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
75 continue;
76 }
77 }
78
79 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
80
81 $width = "pull-left";
82 print '<table class="liste centpercent '. $width .'" id="block_' . $mode_key . '">' . "\n";
83 print '<tr class="liste_titre"><td colspan="5">'.$langs->trans($mode_info['label']).'</td></tr>';
84 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
85 foreach ($mode_info['fields'] as $field_key => $field_info) {
86 if (!empty($field_info['enabled_field'])) {
87 $info = explode(':', $field_info['enabled_field']);
88 if (empty($assetdepreciationoptions->deprecation_options[$info[0]][$info[1]]) || $assetdepreciationoptions->deprecation_options[$info[0]][$info[1]] != $info[2]) {
89 continue;
90 }
91 }
92 // Discard if extrafield is a hidden field on form
93 $isVisibleAbs = array_key_exists('visible', $field_info) ? abs((int) $field_info['visible']) : 0;
94 if (!in_array($isVisibleAbs, array(1, 3, 4, 5))) {
95 continue;
96 }
97 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
98 continue; // We don't want this field
99 }
100 // This loop walks the raw definition of the fields, not the one filtered by
101 // setInfosForMode(), so the fields reserved to an asset must be discarded here too
102 if (!empty($field_info['only_on_asset']) && !empty($class_type)) {
103 continue;
104 }
105 $key = $mode_key . '_' . $field_key;
106 $value = $assetdepreciationoptions->deprecation_options[$mode_key][$field_key] ?? null;
107
108 print '<tr class="field_' . $key . '" id="block_' . $mode_key . '"><td';
109 print ' class="' . (empty($field_info['tdcss']) ? 'titlefieldmiddle' : $field_info['tdcss']) . ' fieldname_' . $key;
110 if ($field_info['type'] == 'text' || $field_info['type'] == 'html') {
111 print ' tdtop';
112 }
113 print '">';
114 if (!empty($field_info['help'])) {
115 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
116 } else {
117 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
118 print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
119 } else {
120 print $langs->trans($field_info['label']);
121 }
122 }
123 print '</td>';
124 print '<td class="valuefield fieldname_' . $key;
125 if ($field_info['type'] == 'text') {
126 print ' wordbreak';
127 }
128 if (!empty($field_info['cssview'])) {
129 print ' ' . $field_info['cssview'];
130 }
131 print '">';
132 if (in_array($field_info['type'], array('text', 'html'))) {
133 print '<div class="longmessagecut">';
134 }
135 if ($field_key == 'lang') {
136 $langs->load("languages");
137 $labellang = ($value ? $langs->trans('Language_' . $value) : '');
138 print picto_from_langcode($value, 'class="paddingrightonly saturatemedium opacitylow"');
139 print $labellang;
140 } else {
141 if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 2) {
142 $out = $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
143 print showValueWithClipboardCPButton($out, 0, $out);
144 } else {
145 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $mode_key . '_', 0);
146 }
147 }
148 if (in_array($field_info['type'], array('text', 'html'))) {
149 print '</div>';
150 }
151 print '</td>';
152 print '</tr>';
153 }
154 print '</table>';
155 print '<div class="clearboth"></div>';
156 print '<br>';
157 }
158}
159
160?>
161<!-- 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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
verifCond($strToEvaluate, $onlysimplestring='1')
Verify if condition in string is ok or not.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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).
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...