dolibarr 21.0.0-alpha
depreciation_options_edit.tpl.php
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Show extrafields. It also shows fields from hook formAssetAccountancyCode. Need to have the following variables defined:
19 * $object (asset, assetmodel, ...)
20 * $assetaccountancycodes
21 * $action
22 * $conf
23 * $langs
24 *
25 * $parameters
26 */
27
28// Protection to avoid direct call of template
29if (empty($object) || !is_object($object)) {
30 print "Error, template page can't be called as URL";
31 exit(1);
32}
33
34if (!is_object($form)) {
35 $form = new Form($db);
36}
37
38if (!isset($formadmin) || !is_object($formadmin)) {
39 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
40 $formadmin = new FormAdmin($db);
41}
42
43
44?>
45<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
46<?php
47
48if (!is_array($parameters)) {
49 $parameters = array();
50}
51$enabled_field_info = array();
52if (empty($parameters['enabled_field_info'])) {
53 $parameters['enabled_field_info'] = &$enabled_field_info;
54}
55if (empty($parameters['assetdepreciationoptions'])) {
56 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
57}
58$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
59print $hookmanager->resPrint;
60if ($reshook < 0) {
61 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
62}
63
64if (empty($reshook)) {
65 $class_type = get_class($object) == 'Asset' ? 0 : 1;
66 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
67 if (!empty($mode_info['enabled_field'])) {
68 $info = explode(':', $mode_info['enabled_field']);
69 $enabled_field_info[] = array(
70 'mode_key' => $info[0],
71 'field_key' => $info[1],
72 'value' => $info[2],
73 'target' => 'block_' . $mode_key,
74 );
75 }
76
77 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
78 $prefix_html_name = $mode_key . '_';
79 $width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
80 print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
81 print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
82 if ($mode_key == "economic") {
83 print '<hr>';
84 }
85 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
86 foreach ($mode_info['fields'] as $field_key => $field_info) {
87 // Discard if extrafield is a hidden field on form
88 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
89 continue;
90 }
91 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
92 continue; // We don't want this field
93 }
94
95
96 $html_name = $prefix_html_name . $field_key;
97 if (!empty($field_info['enabled_field'])) {
98 $info = explode(':', $field_info['enabled_field']);
99 $enabled_field_info[] = array(
100 'mode_key' => $info[0],
101 'field_key' => $info[1],
102 'value' => $info[2],
103 'target' => 'field_' . $html_name,
104 );
105 }
106
107 $more_class = '';
108 if (!empty($field_info['required'])) {
109 $more_class .= 'width40p fieldrequired';
110 }
111 if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
112 $more_class .= ' tdtop';
113 }
114
115 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
116 print ' class="' . $more_class . '">';
117 if (!empty($field_info['help'])) {
118 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
119 } else {
120 print $langs->trans($field_info['label']);
121 }
122 print '</td>';
123 print '<td class="valuefieldcreate">';
124 if (!empty($field_info['picto'])) {
125 print img_picto('', $field_info['picto'], '', 0, 0, 0, '', 'pictofixedwidth');
126 }
127 if (in_array($field_info['type'], array('int', 'integer'))) {
128 $value = GETPOSTISSET($html_name) ? GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
129 } elseif ($field_info['type'] == 'double') {
130 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
131 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
132 $tmparray = explode(':', $field_info['type']);
133 if (!empty($tmparray[1])) {
134 $check = $tmparray[1];
135 } else {
136 $check = 'restricthtml';
137 }
138 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
139 } elseif ($field_info['type'] == 'price') {
140 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? $field_info['default'] : 0));
141 } elseif ($field_key == 'lang') {
142 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : $assetdepreciationoptions->lang;
143 } else {
144 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
145 }
146 if (!empty($field_info['noteditable'])) {
147 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
148 } else {
149 if ($field_key == 'lang') {
150 print img_picto('', 'language', 'class="pictofixedwidth"');
151 print $formadmin->select_language($value, $html_name, 0, null, 1, 0, 0, 'minwidth300', 2);
152 } else {
153 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
154 }
155 }
156 print '</td>';
157 print '</tr>';
158 }
159 print '</table>';
160 }
161 print '<div class="clearboth"></div>';
162}
163
164if (!empty($enabled_field_info)) {
165 $enabled_field_info = json_encode($enabled_field_info);
166 print <<<SCRIPT
167<script type="text/javascript">
168 jQuery(document).ready(function () {
169 var enabled_field_info = $enabled_field_info;
170
171 // Init fields
172 enabled_field_info.map(function(info) {
173 var html_name = info.mode_key + '_' + info.field_key;
174 var source = $('#' + html_name);
175 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
176 if (source.length > 0) {
177 source.attr('data-asset-enabled-field-value', info.value);
178 source.attr('data-asset-enabled-field-target', info.target);
179 updateEnabledField(source);
180 source.on('change click', function() {
181 updateEnabledField(jQuery(this));
182 });
183 }
184 });
185
186 function updateEnabledField(_this) {
187 var value = _this.attr('data-asset-enabled-field-value');
188 var target_name = _this.attr('data-asset-enabled-field-target');
189
190 // for block mode
191 var target = $('table#' + target_name);
192
193 // for field
194 if (!(target.length > 0)) {
195 target = $('#' + target_name);
196 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
197 if (target.length > 0) target = target.closest('tr');
198 }
199
200 if (target.length > 0) {
201 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
202
203 if (source_value != value) {
204 target.hide();
205 } else {
206 target.show();
207 }
208 }
209 }
210 });
211</script>
212SCRIPT;
213}
214
215?>
216<!-- END PHP TEMPLATE depreciation_options_edit.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to generate html code for admin pages.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137