40@phan-var-force Conf $conf
41@phan-var-force DoliDB $db
42@phan-var-force ?Form $form
43@phan-var-force HookManager $hookmanager
44@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
45@phan-var-force Translate $langs
46@phan-var-force ?array<array{mode_key:string,field_key:string,value:string,target:string}> $enabled_field_info
51 print
"Error, template page can't be called as URL";
55if (!is_object($form)) {
56 $form =
new Form($db);
59if (!isset($formadmin) || !is_object($formadmin)) {
60 require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formadmin.class.php';
66<!-- BEGIN PHP TEMPLATE depreciation_options_edit.tpl.php -->
69if (!is_array($parameters)) {
70 $parameters = array();
72$enabled_field_info = array();
73if (empty($parameters[
'enabled_field_info'])) {
74 $parameters[
'enabled_field_info'] = &$enabled_field_info;
76if (empty($parameters[
'assetdepreciationoptions'])) {
77 $parameters[
'assetdepreciationoptions'] = &$assetdepreciationoptions;
79$reshook = $hookmanager->executeHooks(
'formAssetDeprecationOptions', $parameters,
$object, $action);
80print $hookmanager->resPrint;
86 $class_type = get_class(
$object) ==
'Asset' ? 0 : 1;
87 foreach ($assetdepreciationoptions->deprecation_options_fields as $mode_key => $mode_info) {
88 if (!empty($mode_info[
'enabled_field'])) {
89 $info = explode(
':', $mode_info[
'enabled_field']);
90 $enabled_field_info[] = array(
91 'mode_key' => $info[0],
92 'field_key' => $info[1],
94 'target' =>
'block_' . $mode_key,
98 $assetdepreciationoptions->setInfosForMode($mode_key, $class_type,
true);
99 $prefix_html_name = $mode_key .
'_';
100 $width = ($mode_key ==
"economic") ?
"width50p pull-left" :
"width50p";
101 print
'<table class="border '. $width .
'" id="block_' . $mode_key .
'">' .
"\n";
102 print
'<tr><td class="info-box-title">'.$langs->trans($mode_info[
'label']).
'</td></tr>';
103 if ($mode_key ==
"economic") {
106 $mode_info[
'fields'] =
dol_sort_array($mode_info[
'fields'],
'position');
107 foreach ($mode_info[
'fields'] as $field_key => $field_info) {
109 if (abs($field_info[
'visible']) != 1 && abs($field_info[
'visible']) != 3 && abs($field_info[
'visible']) != 4) {
112 if (array_key_exists(
'enabled', $field_info) && isset($field_info[
'enabled']) && !
verifCond($field_info[
'enabled'])) {
117 $html_name = $prefix_html_name . $field_key;
118 if (!empty($field_info[
'enabled_field'])) {
119 $info = explode(
':', $field_info[
'enabled_field']);
120 $enabled_field_info[] = array(
121 'mode_key' => $info[0],
122 'field_key' => $info[1],
124 'target' =>
'field_' . $html_name,
129 if (!empty($field_info[
'required'])) {
130 $more_class .=
'width40p fieldrequired';
132 if (isset($val[
'type']) && preg_match(
'/^(text|html)/', $val[
'type'])) {
133 $more_class .=
' tdtop';
136 print
'<tr class="field_' . $html_name .
'" id="field_' . $html_name .
'"><td';
137 print
' class="' . $more_class .
'">';
138 if (!empty($field_info[
'help'])) {
139 print $form->textwithpicto($langs->trans($field_info[
'label']), $langs->trans($field_info[
'help']));
141 print $langs->trans($field_info[
'label']);
144 print
'<td class="valuefieldcreate">';
145 if (!empty($field_info[
'picto'])) {
146 print
img_picto(
'', $field_info[
'picto'],
'', 0, 0, 0,
'',
'pictofixedwidth');
148 if (in_array($field_info[
'type'], array(
'int',
'integer'))) {
149 $value = GETPOSTISSET($html_name) ?
GETPOSTINT($html_name) : $assetdepreciationoptions->$field_key;
150 } elseif ($field_info[
'type'] ==
'double') {
151 $value = GETPOSTISSET($html_name) ?
price2num(
GETPOST($html_name,
'alphanohtml')) : $assetdepreciationoptions->$field_key;
152 } elseif (preg_match(
'/^(text|html)/', $field_info[
'type'])) {
153 $tmparray = explode(
':', $field_info[
'type']);
154 if (!empty($tmparray[1])) {
155 $check = $tmparray[1];
157 $check =
'restricthtml';
159 $value = GETPOSTISSET($html_name) ?
GETPOST($html_name, $check) : $assetdepreciationoptions->$field_key;
160 } elseif ($field_info[
'type'] ==
'price') {
161 $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));
162 } elseif ($field_key ==
'lang') {
163 $value = GETPOSTISSET($html_name) ?
GETPOST($html_name,
'aZ09') : $assetdepreciationoptions->lang;
165 $value = GETPOSTISSET($html_name) ?
GETPOST($html_name,
'alpha') : $assetdepreciationoptions->$field_key;
167 if (!empty($field_info[
'noteditable'])) {
168 print $assetdepreciationoptions->showOutputField($field_info, $field_key, $value,
'',
'', $prefix_html_name, 0);
170 if ($field_key ==
'lang') {
171 print
img_picto(
'',
'language',
'class="pictofixedwidth"');
172 print $formadmin->select_language($value, $html_name, 0,
null, 1, 0, 0,
'minwidth300', 2);
174 print $assetdepreciationoptions->showInputField($field_info, $field_key, $value,
'',
'', $prefix_html_name, 0);
182 print
'<div class="clearboth"></div>';
185if (!empty($enabled_field_info)) {
186 $enabled_field_info = json_encode($enabled_field_info);
188<script
type=
"text/javascript">
189 jQuery(document).ready(
function () {
190 var enabled_field_info = $enabled_field_info;
193 enabled_field_info.map(
function(info) {
194 var html_name = info.mode_key +
'_' + info.field_key;
195 var source = $(
'#' + html_name);
196 if (!(source.length > 0)) source = $(
'[name="' + html_name +
'"]');
197 if (source.length > 0) {
198 source.attr(
'data-asset-enabled-field-value', info.value);
199 source.attr(
'data-asset-enabled-field-target', info.target);
200 updateEnabledField(source);
201 source.on(
'change click',
function() {
202 updateEnabledField(jQuery(
this));
207 function updateEnabledField(_this) {
208 var value = _this.attr(
'data-asset-enabled-field-value');
209 var target_name = _this.attr(
'data-asset-enabled-field-target');
212 var target = $(
'table#' + target_name);
215 if (!(target.length > 0)) {
216 target = $(
'#' + target_name);
217 if (!(target.length > 0)) target = $(
'[name="' + target_name +
'"]');
218 if (target.length > 0) target = target.closest(
'tr');
221 if (target.length > 0) {
222 var source_value = _this.attr(
'type') ==
'checkbox' ? (_this.is(
':checked') ? 1 : 0) : _this.val();
224 if (source_value != value) {
237<!-- END PHP TEMPLATE depreciation_options_edit.tpl.php -->
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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