dolibarr 18.0.6
assetdepreciationoptions.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2021 Open-Dsi <support@open-dsi.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
25
30{
34 public $table_element = '';
35
69 public $fields = array();
70
75 public $deprecation_options_fields = array(
76 'economic' => array(
77 'label' => 'AssetDepreciationOptionEconomic',
78 'table' => 'asset_depreciation_options_economic',
79 'fields' => array(
80 'depreciation_type' => array('type'=>'smallint', 'label'=>'AssetDepreciationOptionDepreciationType', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'arrayofkeyval'=>array('0'=>'AssetDepreciationOptionDepreciationTypeLinear', '1'=>'AssetDepreciationOptionDepreciationTypeDegressive', '2'=>'AssetDepreciationOptionDepreciationTypeExceptional'), 'validate'=>'1',),
81 'degressive_coefficient' => array('type'=>'double(24,8)', 'label'=>'AssetDepreciationOptionDegressiveRate', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1','enabled_field' => 'economic:depreciation_type:1'),
82 'duration' => array('type'=>'integer', 'label'=>'AssetDepreciationOptionDuration', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
83 'duration_type' => array('type'=>'smallint', 'label'=>'AssetDepreciationOptionDurationType', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'arrayofkeyval'=>array('0'=>'AssetDepreciationOptionDurationTypeAnnual', '1'=>'AssetDepreciationOptionDurationTypeMonthly'/*, '2'=>'AssetDepreciationOptionDurationTypeDaily'*/), 'validate'=>'1',),
84 'rate' => array('type'=>'double(24,8)', 'label'=>'AssetDepreciationOptionRate', 'enabled'=>'1', 'position'=>50, 'visible'=>3, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1', 'computed' => '$object->asset_depreciation_options->getRate("economic")',),
85 'accelerated_depreciation_option' => array('type'=>'boolean', 'label'=>'AssetDepreciationOptionAcceleratedDepreciation', 'enabled'=>'1', 'position'=>60, 'column_break' => true, 'notnull'=>0, 'default'=>'0', 'visible'=>1, 'validate'=>'1',),
86 'amount_base_depreciation_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionAmountBaseDepreciationHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>90, 'notnull'=>0, 'required'=>1, 'visible'=>1, 'default'=>'$object->reversal_amount_ht > 0 ? $object->reversal_amount_ht : $object->acquisition_value_ht', 'isameasure'=>'1', 'validate'=>'1',),
87 'amount_base_deductible_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionAmountBaseDeductibleHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>100, 'notnull'=>0, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
88 'total_amount_last_depreciation_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionTotalAmountLastDepreciationHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>110, 'noteditable'=> 1, 'notnull'=>0, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
89 ),
90 ),
91 'accelerated_depreciation' => array(
92 'label' => 'AssetDepreciationOptionAcceleratedDepreciation',
93 'table' => 'asset_depreciation_options_fiscal',
94 'enabled_field' => 'economic:accelerated_depreciation_option:1',
95 'fields' => array(
96 'depreciation_type' => array('type'=>'smallint', 'label'=>'AssetDepreciationOptionDepreciationType', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'arrayofkeyval'=>array('0'=>'AssetDepreciationOptionDepreciationTypeLinear', '1'=>'AssetDepreciationOptionDepreciationTypeDegressive', '2'=>'AssetDepreciationOptionDepreciationTypeExceptional'), 'validate'=>'1',),
97 'degressive_coefficient' => array('type'=>'double(24,8)', 'label'=>'AssetDepreciationOptionDegressiveRate', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1','enabled_field' => 'accelerated_depreciation:depreciation_type:1'),
98 'duration' => array('type'=>'integer', 'label'=>'AssetDepreciationOptionDuration', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
99 'duration_type' => array('type'=>'smallint', 'label'=>'AssetDepreciationOptionDurationType', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>1, 'default'=>'0', 'arrayofkeyval'=>array('0'=>'AssetDepreciationOptionDurationTypeAnnual', '1'=>'AssetDepreciationOptionDurationTypeMonthly'/*, '2'=>'AssetDepreciationOptionDurationTypeDaily'*/), 'validate'=>'1',),
100 'rate' => array('type'=>'double(24,8)', 'label'=>'AssetDepreciationOptionRate', 'enabled'=>'1', 'position'=>50, 'visible'=>3, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1', 'computed' => '$object->asset_depreciation_options->getRate("accelerated_depreciation")',),
101 'amount_base_depreciation_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionAmountBaseDepreciationHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>80, 'column_break' => true, 'notnull'=>0, 'required'=>1, 'visible'=>1, 'default'=>'$object->reversal_amount_ht > 0 ? $object->reversal_amount_ht : $object->acquisition_value_ht', 'isameasure'=>'1', 'validate'=>'1',),
102 'amount_base_deductible_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionAmountBaseDeductibleHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>90, 'notnull'=>0, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
103 'total_amount_last_depreciation_ht' => array('type'=>'price', 'label'=>'AssetDepreciationOptionTotalAmountLastDepreciationHT', 'enabled'=>'isset($object)&&get_class($object)=="Asset"', 'only_on_asset'=>1, 'position'=>100, 'noteditable'=> 1, 'notnull'=>0, 'visible'=>1, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
104 ),
105 ),
106 );
107 public $fk_asset;
108 public $fk_asset_model;
109 public $tms;
110 public $fk_user_modif;
111
115 public $deprecation_options = array();
116
122 public function __construct(DoliDB $db)
123 {
124 global $langs;
125 $this->db = $db;
126
127 // Translate some data of arrayofkeyval
128 if (is_object($langs)) {
129 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
130 if (!empty($mode_info['fields']) && is_array($mode_info['fields'])) {
131 foreach ($mode_info['fields'] as $field_key => $field_info) {
132 if (!empty($field_info['arrayofkeyval']) && is_array($field_info['arrayofkeyval'])) {
133 foreach ($field_info['arrayofkeyval'] as $key => $val) {
134 $this->deprecation_options_fields[$mode_key]['fields'][$field_key]['arrayofkeyval'][$key] = $langs->trans($val);
135 }
136 }
137 }
138 }
139 }
140 }
141 }
142
151 public function setInfosForMode($mode, $class_type = 0, $all_field = false)
152 {
153 // Clean parameters
154 $mode = strtolower(trim($mode));
155
156 if (!empty($this->deprecation_options_fields[$mode])) {
157 $this->table_element = $this->deprecation_options_fields[$mode]['table'];
158 $this->fields = $this->deprecation_options_fields[$mode]['fields'];
159 foreach ($this->fields as $field_key => $field_info) {
160 if ((!empty($field_info['computed']) && !$all_field) || (!empty($field_info['only_on_asset']) && !empty($class_type))) {
161 unset($this->fields[$field_key]);
162 continue;
163 }
164
165 // Unset required option (notnull) if field disabled
166 if (!empty($field_info['enabled_field'])) {
167 $info = explode(':', $field_info['enabled_field']);
168 if ($this->deprecation_options[$info[0]][$info[1]] != $info[2] && isset($this->fields[$field_key]['notnull'])) {
169 unset($this->fields[$field_key]['notnull']);
170 }
171 }
172 // Set value of the field in the object (for createCommon and setDeprecationOptionsFromPost functions)
173 $this->{$field_key} = $this->deprecation_options[$mode][$field_key];
174 }
175
176 $this->fields['rowid'] = array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id");
177 if (empty($class_type)) {
178 $this->fields['fk_asset'] = array('type' => 'integer:Asset:asset/class/asset.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label' => 'Asset', 'enabled' => '1', 'position' => 0, 'notnull' => 0, 'visible' => 0, 'index' => 1, 'validate' => '1',);
179 } else {
180 $this->fields['fk_asset_model'] = array('type' => 'integer:AssetModel:asset/class/assetmodel.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'label' => 'AssetModel', 'enabled' => '1', 'position' => 0, 'notnull' => 0, 'visible' => 0, 'index' => 1, 'validate' => '1',);
181 }
182 $this->fields['tms'] = array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 501, 'notnull' => 0, 'visible' => 0,);
183 $this->fields['fk_user_modif'] = array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => '1', 'position' => 511, 'notnull' => -1, 'visible' => 0,);
184 }
185
186 return 1;
187 }
188
195 public function setDeprecationOptionsFromPost($class_type = 0)
196 {
197 global $conf, $langs;
198
199 $error = 0;
200
201 $deprecation_options = array();
202 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
203 $this->setInfosForMode($mode_key, $class_type);
204
205 foreach ($mode_info['fields'] as $field_key => $field_info) {
206 if (!empty($field_info['computed'])) {
207 continue;
208 }
209
210 $html_name = $mode_key . '_' . $field_key;
211 if ($field_info['type'] == 'duration') {
212 if (GETPOST($html_name . 'hour') == '' && GETPOST($html_name . 'min') == '') {
213 continue; // The field was not submited to be saved
214 }
215 } else {
216 if (!GETPOSTISSET($html_name)) {
217 continue; // The field was not submited to be saved
218 }
219 }
220 // Ignore special fields
221 if (in_array($field_key, array('rowid', 'entity', 'import_key'))) {
222 continue;
223 }
224 if (in_array($field_key, array('date_creation', 'tms', 'fk_user_creat', 'fk_user_modif'))) {
225 if (!in_array(abs($field_info['visible']), array(1, 3))) {
226 continue; // Only 1 and 3 that are case to create
227 }
228 }
229
230 // Set value to insert
231 if (in_array($field_info['type'], array('text', 'html'))) {
232 $value = GETPOST($html_name, 'restricthtml');
233 } elseif ($field_info['type'] == 'date') {
234 $value = dol_mktime(12, 0, 0, GETPOST($html_name . 'month', 'int'), GETPOST($html_name . 'day', 'int'), GETPOST($html_name . 'year', 'int')); // for date without hour, we use gmt
235 } elseif ($field_info['type'] == 'datetime') {
236 $value = dol_mktime(GETPOST($html_name . 'hour', 'int'), GETPOST($html_name . 'min', 'int'), GETPOST($html_name . 'sec', 'int'), GETPOST($html_name . 'month', 'int'), GETPOST($html_name . 'day', 'int'), GETPOST($html_name . 'year', 'int'), 'tzuserrel');
237 } elseif ($field_info['type'] == 'duration') {
238 $value = 60 * 60 * GETPOST($html_name . 'hour', 'int') + 60 * GETPOST($html_name . 'min', 'int');
239 } elseif (preg_match('/^(integer|price|real|double)/', $field_info['type'])) {
240 $value = price2num(GETPOST($html_name, 'alphanohtml')); // To fix decimal separator according to lang setup
241 } elseif ($field_info['type'] == 'boolean') {
242 $value = ((GETPOST($html_name) == '1' || GETPOST($html_name) == 'on') ? 1 : 0);
243 } elseif ($field_info['type'] == 'reference') {
244 // todo to check
245 $tmparraykey = array(); //array_keys($object->param_list);
246 $value = $tmparraykey[GETPOST($html_name)] . ',' . GETPOST($html_name . '2');
247 } else {
248 if ($field_key == 'lang') {
249 $value = GETPOST($html_name, 'aZ09') ? GETPOST($html_name, 'aZ09') : "";
250 } else {
251 $value = GETPOST($html_name, 'alphanohtml');
252 }
253 }
254 if (preg_match('/^integer:/i', $field_info['type']) && $value == '-1') {
255 $value = ''; // This is an implicit foreign key field
256 }
257 if (!empty($field_info['foreignkey']) && $value == '-1') {
258 $value = ''; // This is an explicit foreign key field
259 }
260
261 //var_dump($field_key.' '.$value.' '.$field_info['type']);
262 $field_value = $value;
263 if ($field_info['notnull'] > 0 && $field_value == '' && !is_null($field_info['default']) && $field_info['default'] == '(PROV)') {
264 $field_value = '(PROV)';
265 } elseif ((!empty($field_info['required']) || $field_info['notnull'] > 0) && $field_value == '' && !empty($field_info['default'])) {
266 $field_value = dol_eval($field_info['default'], 1);
267 }
268 if ($field_info['notnull'] > 0 && $field_value == '' && is_null($field_info['default'])) {
269 $error++;
270 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($field_info['label'])), null, 'errors');
271 }
272 $deprecation_options[$mode_key][$field_key] = $field_value;
273
274 // Validation of fields values
275 if ($conf->global->MAIN_FEATURE_LEVEL >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) {
276 if (!$error && !empty($field_info['validate']) && is_callable(array($this, 'validateField'))) {
277 if (!$this->validateField($mode_info['fields'], $field_key, $value)) {
278 $error++;
279 }
280 }
281 }
282 }
283 }
284 // Unset not enabled modes
285 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
286 if (!empty($mode_info['enabled_field'])) {
287 $info = explode(':', $mode_info['enabled_field']);
288 if ($deprecation_options[$info[0]][$info[1]] != $info[2]) {
289 unset($deprecation_options[$info[0]][$info[1]]);
290 }
291 }
292 }
293 $this->deprecation_options = $deprecation_options;
294
295 if ($error) {
296 return -1;
297 } else {
298 return 1;
299 }
300 }
301
309 public function fetchDeprecationOptions($asset_id = 0, $asset_model_id = 0)
310 {
311 global $langs, $hookmanager;
312 dol_syslog(__METHOD__ . " asset_id=$asset_id, asset_model_id=$asset_model_id");
313
314 $error = 0;
315 $this->errors = array();
316 $this->deprecation_options = array();
317
318 // Clean parameters
319 $asset_id = $asset_id > 0 ? $asset_id : 0;
320 $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0;
321
322 $hookmanager->initHooks(array('assetdepreciationoptionsdao'));
323 $parameters = array('asset_id' => $asset_id, 'asset_model_id' => $asset_model_id);
324 $reshook = $hookmanager->executeHooks('fetchDepreciationOptions', $parameters, $this); // Note that $action and $object may have been modified by some hooks
325 if (!empty($reshook)) {
326 return $reshook;
327 }
328
329 // Check parameters
330 if (empty($asset_id) && empty($asset_model_id)) {
331 $this->errors[] = $langs->trans('AssetErrorAssetOrAssetModelIDNotProvide');
332 $error++;
333 }
334 if ($error) {
335 dol_syslog(__METHOD__ . " Error check parameters: " . $this->errorsToString(), LOG_ERR);
336 return -1;
337 }
338
339 $class_type = $asset_id > 0 ? 0 : 1;
340 $deprecation_options = array();
341 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
342 $this->setInfosForMode($mode_key, $class_type);
343
344 $result = $this->fetchCommon(0, '', " AND " . ($asset_id > 0 ? " fk_asset = " . (int) $asset_id : " fk_asset_model = " . (int) $asset_model_id));
345 if ($result < 0) {
346 $this->errors = array_merge(array($langs->trans('AssetErrorFetchDepreciationOptionsForMode', $mode_key) . ':'), $this->errors);
347 $error++;
348 } elseif ($result > 0) {
349 foreach ($this->fields as $field_key => $field_info) {
350 if (in_array($field_key, array('rowid', 'fk_asset', 'fk_asset_model', 'tms', 'fk_user_modif'))) continue;
351 $deprecation_options[$mode_key][$field_key] = $this->{$field_key};
352 }
353 }
354 }
355 // Unset not enabled modes
356 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
357 if (!empty($mode_info['enabled_field'])) {
358 $info = explode(':', $mode_info['enabled_field']);
359 if ($deprecation_options[$info[0]][$info[1]] != $info[2]) {
360 unset($deprecation_options[$info[0]][$info[1]]);
361 }
362 }
363 }
364
365 if ($error) {
366 dol_syslog(__METHOD__ . " Error fetch accountancy codes: " . $this->errorsToString(), LOG_ERR);
367 return -1;
368 } else {
369 $this->deprecation_options = $deprecation_options;
370 return 1;
371 }
372 }
373
381 {
382 global $hookmanager;
383 dol_syslog(__METHOD__ . " mode=$mode");
384
385 $this->errors = array();
386
387 // Clean parameters
388 $mode = strtolower(trim($mode));
389
390 $hookmanager->initHooks(array('assetdepreciationoptionsdao'));
391 $parameters = array('mode' => $mode);
392 $reshook = $hookmanager->executeHooks('getGeneralDepreciationInfoForMode', $parameters, $this); // Note that $action and $object may have been modified by some hooks
393 if ($reshook < 0) {
394 return $reshook;
395 } elseif ($reshook > 0) {
396 return $hookmanager->resArray;
397 }
398
399 $duration_type_list = $this->deprecation_options_fields[$mode]['fields']['duration_type']['arrayofkeyval'];
400
401 return array(
402 'base_depreciation_ht' => $this->deprecation_options[$mode]['amount_base_depreciation_ht'],
403 'duration' => $this->deprecation_options[$mode]['duration'],
404 'duration_type' => $duration_type_list[$this->deprecation_options[$mode]['duration_type']],
405 'rate' => $this->getRate($mode),
406 );
407 }
408
418 public function updateDeprecationOptions($user, $asset_id = 0, $asset_model_id = 0, $notrigger = 0)
419 {
420 global $langs, $hookmanager;
421 dol_syslog(__METHOD__ . " user_id=".$user->id.", asset_id=".$asset_id.", asset_model_id=".$asset_model_id.", notrigger=".$notrigger);
422
423 $error = 0;
424 $this->errors = array();
425
426 // Clean parameters
427 $asset_id = $asset_id > 0 ? $asset_id : 0;
428 $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0;
429
430 $hookmanager->initHooks(array('assetdepreciationoptionsdao'));
431 $parameters = array('user' => $user, 'asset_id' => $asset_id, 'asset_model_id' => $asset_model_id);
432 $reshook = $hookmanager->executeHooks('updateDepreciationOptions', $parameters, $this); // Note that $action and $object may have been modified by some hooks
433 if (!empty($reshook)) {
434 return $reshook;
435 }
436
437 // Check parameters
438 if (empty($asset_id) && empty($asset_model_id)) {
439 $this->errors[] = $langs->trans('AssetErrorAssetOrAssetModelIDNotProvide');
440 $error++;
441 }
442 if ($error) {
443 dol_syslog(__METHOD__ . " Error check parameters: " . $this->errorsToString(), LOG_ERR);
444 return -1;
445 }
446
447 $this->db->begin();
448
449 if ($asset_id > 0) {
450 $this->fk_asset = $asset_id;
451 $class_type = 0;
452 } else {
453 $this->fk_asset_model = $asset_model_id;
454 $class_type = 1;
455 }
456 $this->tms = dol_now();
457 $this->fk_user_modif = $user->id;
458
459 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
460 // Delete old accountancy codes
461 $sql = "DELETE FROM " . MAIN_DB_PREFIX . $mode_info['table'];
462 $sql .= " WHERE " . ($asset_id > 0 ? " fk_asset = " . (int) $asset_id : " fk_asset_model = " . (int) $asset_model_id);
463 $resql = $this->db->query($sql);
464 if (!$resql) {
465 $this->errors[] = $langs->trans('AssetErrorDeleteDepreciationOptionsForMode', $mode_key) . ': ' . $this->db->lasterror();
466 $error++;
467 }
468
469 if (!$error && !empty($this->deprecation_options[$mode_key])) {
470 if (!empty($mode_info['enabled_field'])) {
471 $info = explode(':', $mode_info['enabled_field']);
472 if ($this->deprecation_options[$info[0]][$info[1]] != $info[2]) {
473 continue;
474 }
475 }
476
477 $this->setInfosForMode($mode_key, $class_type);
478
479 $result = $this->createCommon($user, 1);
480 if ($result < 0) {
481 $this->errors = array_merge(array($langs->trans('AssetErrorInsertDepreciationOptionsForMode', $mode_key) . ':'), $this->errors);
482 $error++;
483 }
484 }
485 }
486
487 if (!$error && $this->fk_asset > 0) {
488 // Calculation of depreciation lines (reversal and future)
489 require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
490 $asset = new Asset($this->db);
491 $result = $asset->fetch($this->fk_asset);
492 if ($result > 0) $result = $asset->calculationDepreciation();
493 if ($result < 0) {
494 $this->errors[] = $langs->trans('AssetErrorCalculationDepreciationLines');
495 $this->errors[] = $asset->errorsToString();
496 $error++;
497 }
498 }
499
500 if (!$error && !$notrigger) {
501 // Call trigger
502 $result = $this->call_trigger('ASSET_DEPRECIATION_OPTIONS_MODIFY', $user);
503 if ($result < 0) {
504 $error++;
505 }
506 // End call triggers
507 }
508
509 if ($error) {
510 $this->db->rollback();
511 return -1;
512 } else {
513 $this->db->commit();
514 return 1;
515 }
516 }
517
524 public function getRate($mode)
525 {
526 $duration = $this->deprecation_options[$mode]["duration"] > 0 ? $this->deprecation_options[$mode]["duration"] : 0;
527 $duration_type = $this->deprecation_options[$mode]["duration_type"] > 0 ? $this->deprecation_options[$mode]["duration_type"] : 0;
528
529 return price(price2num($duration > 0 ? (100 * ($duration_type == 1 ? 12 : 1) / $duration) : 0, 2));
530 }
531}
Class for AssetDepreciationOptions.
updateDeprecationOptions($user, $asset_id=0, $asset_model_id=0, $notrigger=0)
Update deprecation options of a asset or a asset model.
getGeneralDepreciationInfoForMode($mode)
get general depreciation info for a mode (used in depreciation card)
setDeprecationOptionsFromPost($class_type=0)
Fill deprecation_options property of object (using for data sent by forms)
setInfosForMode($mode, $class_type=0, $all_field=false)
Set object infos for a mode.
fetchDeprecationOptions($asset_id=0, $asset_model_id=0)
Load deprecation options of a asset or a asset model.
Class for Asset.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
errorsToString()
Method to output saved errors.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.