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 * Copyright (C) 2024 José <jose.martinez@pichinov.com>
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. Need to have the following variables defined:
20 * $object (asset, assetmodel, ...)
21 * $assetaccountancycodes
22 * $action
23 * $conf
24 * $langs
25 *
26 * $parameters
27 */
28
29// Protection to avoid direct call of template
30if (empty($object) || !is_object($object)) {
31 print "Error, template page can't be called as URL";
32 exit(1);
33}
34
35if (!is_object($form)) {
36 $form = new Form($db);
37}
38
39if (!isset($formadmin) || !is_object($formadmin)) {
40 require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php';
41 $formadmin = new FormAdmin($db);
42}
43
44
45?>
46<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
47<?php
48
49if (!is_array($parameters)) {
50 $parameters = array();
51}
52$enabled_field_info = array();
53if (empty($parameters['enabled_field_info'])) {
54 $parameters['enabled_field_info'] = &$enabled_field_info;
55}
56if (empty($parameters['assetdepreciationoptions'])) {
57 $parameters['assetdepreciationoptions'] = &$assetdepreciationoptions;
58}
59$reshook = $hookmanager->executeHooks('formAssetDeprecationOptions', $parameters, $object, $action);
60print $hookmanager->resPrint;
61if ($reshook < 0) {
62 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
63}
64
65if (empty($reshook)) {
66 $class_type = get_class($object) == 'Asset' ? 0 : 1;
67 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
68 if (!empty($mode_info['enabled_field'])) {
69 $info = explode(':', $mode_info['enabled_field']);
70 $enabled_field_info[] = array(
71 'mode_key' => $info[0],
72 'field_key' => $info[1],
73 'value' => $info[2],
74 'target' => 'block_' . $mode_key,
75 );
76 }
77
78 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
79 $prefix_html_name = $mode_key . '_';
80 $width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
81 print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
82 print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
83 if ($mode_key == "economic") {
84 print '<hr>';
85 }
86 $mode_info['fields'] = dol_sort_array($mode_info['fields'], 'position');
87 foreach ($mode_info['fields'] as $field_key => $field_info) {
88 // Discard if extrafield is a hidden field on form
89 if (abs($field_info['visible']) != 1 && abs($field_info['visible']) != 3 && abs($field_info['visible']) != 4) {
90 continue;
91 }
92 if (array_key_exists('enabled', $field_info) && isset($field_info['enabled']) && !verifCond($field_info['enabled'])) {
93 continue; // We don't want this field
94 }
95
96
97 $html_name = $prefix_html_name . $field_key;
98 if (!empty($field_info['enabled_field'])) {
99 $info = explode(':', $field_info['enabled_field']);
100 $enabled_field_info[] = array(
101 'mode_key' => $info[0],
102 'field_key' => $info[1],
103 'value' => $info[2],
104 'target' => 'field_' . $html_name,
105 );
106 }
107
108 $more_class = '';
109 if (!empty($field_info['required'])) {
110 $more_class .= 'width40p fieldrequired';
111 }
112 if (isset($val['type']) && preg_match('/^(text|html)/', $val['type'])) {
113 $more_class .= ' tdtop';
114 }
115
116 print '<tr class="field_' . $html_name . '" id="field_' . $html_name . '"><td';
117 print ' class="' . $more_class . '">';
118 if (!empty($field_info['help'])) {
119 print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
120 } else {
121 print $langs->trans($field_info['label']);
122 }
123 print '</td>';
124 print '<td class="valuefieldcreate">';
125 if (!empty($field_info['picto'])) {
126 print img_picto('', $field_info['picto'], '', 0, 0, 0, '', 'pictofixedwidth');
127 }
128 if (in_array($field_info['type'], array('int', 'integer'))) {
129 $value = GETPOSTISSET($html_name) ? GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
130 } elseif ($field_info['type'] == 'double') {
131 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name, 'alphanohtml')) : $assetdepreciationoptions->$field_key;
132 } elseif (preg_match('/^(text|html)/', $field_info['type'])) {
133 $tmparray = explode(':', $field_info['type']);
134 if (!empty($tmparray[1])) {
135 $check = $tmparray[1];
136 } else {
137 $check = 'restricthtml';
138 }
139 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
140 } elseif ($field_info['type'] == 'price') {
141 $value = GETPOSTISSET($html_name) ? price2num(GETPOST($html_name)) : ($assetdepreciationoptions->$field_key ? price2num($assetdepreciationoptions->$field_key) : (!empty($field_info['default']) ? dol_eval($field_info['default'], 1) : 0));
142 } elseif ($field_key == 'lang') {
143 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'aZ09') : $assetdepreciationoptions->lang;
144 } else {
145 $value = GETPOSTISSET($html_name) ? GETPOST($html_name, 'alpha') : $assetdepreciationoptions->$field_key;
146 }
147 if (!empty($field_info['noteditable'])) {
148 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
149 } else {
150 if ($field_key == 'lang') {
151 print img_picto('', 'language', 'class="pictofixedwidth"');
152 print $formadmin->select_language($value, $html_name, 0, null, 1, 0, 0, 'minwidth300', 2);
153 } else {
154 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value, '', '', $prefix_html_name, 0);
155 }
156 }
157 print '</td>';
158 print '</tr>';
159 }
160 print '</table>';
161 }
162 print '<div class="clearboth"></div>';
163}
164
165if (!empty($enabled_field_info)) {
166 $enabled_field_info = json_encode($enabled_field_info);
167 print <<<SCRIPT
168<script type="text/javascript">
169 jQuery(document).ready(function () {
170 var enabled_field_info = $enabled_field_info;
171
172 // Init fields
173 enabled_field_info.map(function(info) {
174 var html_name = info.mode_key + '_' + info.field_key;
175 var source = $('#' + html_name);
176 if (!(source.length > 0)) source = $('[name="' + html_name + '"]');
177 if (source.length > 0) {
178 source.attr('data-asset-enabled-field-value', info.value);
179 source.attr('data-asset-enabled-field-target', info.target);
180 updateEnabledField(source);
181 source.on('change click', function() {
182 updateEnabledField(jQuery(this));
183 });
184 }
185 });
186
187 function updateEnabledField(_this) {
188 var value = _this.attr('data-asset-enabled-field-value');
189 var target_name = _this.attr('data-asset-enabled-field-target');
190
191 // for block mode
192 var target = $('table#' + target_name);
193
194 // for field
195 if (!(target.length > 0)) {
196 target = $('#' + target_name);
197 if (!(target.length > 0)) target = $('[name="' + target_name + '"]');
198 if (target.length > 0) target = target.closest('tr');
199 }
200
201 if (target.length > 0) {
202 var source_value = _this.attr('type') == 'checkbox' ? (_this.is(':checked') ? 1 : 0) : _this.val();
203
204 if (source_value != value) {
205 target.hide();
206 } else {
207 target.show();
208 }
209 }
210 }
211 });
212</script>
213SCRIPT;
214}
215
216?>
217<!-- 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_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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