dolibarr 19.0.4
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 (getDolGlobalInt('MAIN_FEATURE_LEVEL') >= 1 || getDolGlobalString('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'))) {
351 continue;
352 }
353 $deprecation_options[$mode_key][$field_key] = $this->{$field_key};
354 }
355 }
356 }
357 // Unset not enabled modes
358 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
359 if (!empty($mode_info['enabled_field'])) {
360 $info = explode(':', $mode_info['enabled_field']);
361 if ($deprecation_options[$info[0]][$info[1]] != $info[2]) {
362 unset($deprecation_options[$info[0]][$info[1]]);
363 }
364 }
365 }
366
367 if ($error) {
368 dol_syslog(__METHOD__ . " Error fetch accountancy codes: " . $this->errorsToString(), LOG_ERR);
369 return -1;
370 } else {
371 $this->deprecation_options = $deprecation_options;
372 return 1;
373 }
374 }
375
383 {
384 global $hookmanager;
385 dol_syslog(__METHOD__ . " mode=$mode");
386
387 $this->errors = array();
388
389 // Clean parameters
390 $mode = strtolower(trim($mode));
391
392 $hookmanager->initHooks(array('assetdepreciationoptionsdao'));
393 $parameters = array('mode' => $mode);
394 $reshook = $hookmanager->executeHooks('getGeneralDepreciationInfoForMode', $parameters, $this); // Note that $action and $object may have been modified by some hooks
395 if ($reshook < 0) {
396 return $reshook;
397 } elseif ($reshook > 0) {
398 return $hookmanager->resArray;
399 }
400
401 $duration_type_list = $this->deprecation_options_fields[$mode]['fields']['duration_type']['arrayofkeyval'];
402
403 return array(
404 'base_depreciation_ht' => $this->deprecation_options[$mode]['amount_base_depreciation_ht'],
405 'duration' => $this->deprecation_options[$mode]['duration'],
406 'duration_type' => $duration_type_list[$this->deprecation_options[$mode]['duration_type']],
407 'rate' => $this->getRate($mode),
408 );
409 }
410
420 public function updateDeprecationOptions($user, $asset_id = 0, $asset_model_id = 0, $notrigger = 0)
421 {
422 global $langs, $hookmanager;
423 dol_syslog(__METHOD__ . " user_id=".$user->id.", asset_id=".$asset_id.", asset_model_id=".$asset_model_id.", notrigger=".$notrigger);
424
425 $error = 0;
426 $this->errors = array();
427
428 // Clean parameters
429 $asset_id = $asset_id > 0 ? $asset_id : 0;
430 $asset_model_id = $asset_model_id > 0 ? $asset_model_id : 0;
431
432 $hookmanager->initHooks(array('assetdepreciationoptionsdao'));
433 $parameters = array('user' => $user, 'asset_id' => $asset_id, 'asset_model_id' => $asset_model_id);
434 $reshook = $hookmanager->executeHooks('updateDepreciationOptions', $parameters, $this); // Note that $action and $object may have been modified by some hooks
435 if (!empty($reshook)) {
436 return $reshook;
437 }
438
439 // Check parameters
440 if (empty($asset_id) && empty($asset_model_id)) {
441 $this->errors[] = $langs->trans('AssetErrorAssetOrAssetModelIDNotProvide');
442 $error++;
443 }
444 if ($error) {
445 dol_syslog(__METHOD__ . " Error check parameters: " . $this->errorsToString(), LOG_ERR);
446 return -1;
447 }
448
449 $this->db->begin();
450
451 if ($asset_id > 0) {
452 $this->fk_asset = $asset_id;
453 $class_type = 0;
454 } else {
455 $this->fk_asset_model = $asset_model_id;
456 $class_type = 1;
457 }
458 $this->tms = dol_now();
459 $this->fk_user_modif = $user->id;
460
461 foreach ($this->deprecation_options_fields as $mode_key => $mode_info) {
462 // Delete old accountancy codes
463 $sql = "DELETE FROM " . MAIN_DB_PREFIX . $mode_info['table'];
464 $sql .= " WHERE " . ($asset_id > 0 ? " fk_asset = " . (int) $asset_id : " fk_asset_model = " . (int) $asset_model_id);
465 $resql = $this->db->query($sql);
466 if (!$resql) {
467 $this->errors[] = $langs->trans('AssetErrorDeleteDepreciationOptionsForMode', $mode_key) . ': ' . $this->db->lasterror();
468 $error++;
469 }
470
471 if (!$error && !empty($this->deprecation_options[$mode_key])) {
472 if (!empty($mode_info['enabled_field'])) {
473 $info = explode(':', $mode_info['enabled_field']);
474 if ($this->deprecation_options[$info[0]][$info[1]] != $info[2]) {
475 continue;
476 }
477 }
478
479 $this->setInfosForMode($mode_key, $class_type);
480
481 $result = $this->createCommon($user, 1);
482 if ($result < 0) {
483 $this->errors = array_merge(array($langs->trans('AssetErrorInsertDepreciationOptionsForMode', $mode_key) . ':'), $this->errors);
484 $error++;
485 }
486 }
487 }
488
489 if (!$error && $this->fk_asset > 0) {
490 // Calculation of depreciation lines (reversal and future)
491 require_once DOL_DOCUMENT_ROOT . '/asset/class/asset.class.php';
492 $asset = new Asset($this->db);
493 $result = $asset->fetch($this->fk_asset);
494 if ($result > 0) {
495 $result = $asset->calculationDepreciation();
496 }
497 if ($result < 0) {
498 $this->errors[] = $langs->trans('AssetErrorCalculationDepreciationLines');
499 $this->errors[] = $asset->errorsToString();
500 $error++;
501 }
502 }
503
504 if (!$error && !$notrigger) {
505 // Call trigger
506 $result = $this->call_trigger('ASSET_DEPRECIATION_OPTIONS_MODIFY', $user);
507 if ($result < 0) {
508 $error++;
509 }
510 // End call triggers
511 }
512
513 if ($error) {
514 $this->db->rollback();
515 return -1;
516 } else {
517 $this->db->commit();
518 return 1;
519 }
520 }
521
528 public function getRate($mode)
529 {
530 $duration = $this->deprecation_options[$mode]["duration"] > 0 ? $this->deprecation_options[$mode]["duration"] : 0;
531 $duration_type = $this->deprecation_options[$mode]["duration_type"] > 0 ? $this->deprecation_options[$mode]["duration_type"] : 0;
532
533 return price(price2num($duration > 0 ? (100 * ($duration_type == 1 ? 12 : 1) / $duration) : 0, 2));
534 }
535}
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.
createCommon(User $user, $notrigger=false)
Create object into database.
errorsToString()
Method to output saved errors.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.