dolibarr  18.0.0-alpha
asset.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.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 
25 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
26 
30 class Asset extends CommonObject
31 {
35  public $module = 'asset';
36 
40  public $element = 'asset';
41 
45  public $table_element = 'asset';
46 
51  public $ismultientitymanaged = 1;
52 
56  public $isextrafieldmanaged = 1;
57 
61  public $picto = 'asset';
62 
63  const STATUS_DRAFT = 0; // In progress
64  const STATUS_DISPOSED = 9; // Disposed
65 
97  public $fields=array(
98  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>'1', 'position'=>1, 'notnull'=>1, 'visible'=>0, 'noteditable'=>'1', 'index'=>1, 'css'=>'left', 'comment'=>"Id"),
99  'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>'1', 'position'=>20, 'notnull'=>1, 'visible'=>1, 'noteditable'=>'0', 'index'=>1, 'searchall'=>1, 'showoncombobox'=>'1', 'validate'=>'1', 'comment'=>"Reference of object"),
100  'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'showoncombobox'=>'2', 'validate'=>'1',),
101  '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'=>40, 'notnull'=>0, 'visible'=>1, 'index'=>1, 'validate'=>'1',),
102  'qty' => array('type'=>'real', 'label'=>'Qty', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>0, 'default'=>'1', 'isameasure'=>'1', 'css'=>'maxwidth75imp', 'validate'=>'1',),
103  'acquisition_type' => array('type'=>'smallint', 'label'=>'AssetAcquisitionType', 'enabled'=>'1', 'position'=>60, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('0'=>'AssetAcquisitionTypeNew', '1'=>'AssetAcquisitionTypeOccasion'), 'validate'=>'1',),
104  'asset_type' => array('type'=>'smallint', 'label'=>'AssetType', 'enabled'=>'1', 'position'=>70, 'notnull'=>1, 'visible'=>1, 'arrayofkeyval'=>array('0'=>'AssetTypeIntangible', '1'=>'AssetTypeTangible', '2'=>'AssetTypeInProgress', '3'=>'AssetTypeFinancial'), 'validate'=>'1',),
105  'not_depreciated' => array('type'=>'boolean', 'label'=>'AssetNotDepreciated', 'enabled'=>'1', 'position'=>80, 'notnull'=>0, 'default'=>'0', 'visible'=>1, 'validate'=>'1',),
106  'date_acquisition' => array('type'=>'date', 'label'=>'AssetDateAcquisition', 'enabled'=>'1', 'position'=>90, 'notnull'=>1, 'visible'=>1,),
107  'date_start' => array('type'=>'date', 'label'=>'AssetDateStart', 'enabled'=>'1', 'position'=>100, 'notnull'=>0, 'visible'=>-1,),
108  'acquisition_value_ht' => array('type'=>'price', 'label'=>'AssetAcquisitionValueHT', 'enabled'=>'1', 'position'=>110, 'notnull'=>1, 'visible'=>1, 'isameasure'=>'1', 'validate'=>'1',),
109  'recovered_vat' => array('type'=>'price', 'label'=>'AssetRecoveredVAT', 'enabled'=>'1', 'position'=>120, 'notnull'=>0, 'visible'=>1, 'isameasure'=>'1', 'validate'=>'1',),
110  'reversal_date' => array('type'=>'date', 'label'=>'AssetReversalDate', 'enabled'=>'1', 'position'=>130, 'notnull'=>0, 'visible'=>1,),
111  'reversal_amount_ht' => array('type'=>'price', 'label'=>'AssetReversalAmountHT', 'enabled'=>'1', 'position'=>140, 'notnull'=>0, 'visible'=>1, 'isameasure'=>'1', 'validate'=>'1',),
112  'disposal_date' => array('type'=>'date', 'label'=>'AssetDisposalDate', 'enabled'=>'1', 'position'=>200, 'notnull'=>0, 'visible'=>-2,),
113  'disposal_amount_ht' => array('type'=>'price', 'label'=>'AssetDisposalAmount', 'enabled'=>'1', 'position'=>210, 'notnull'=>0, 'visible'=>-2, 'default'=>'0', 'isameasure'=>'1', 'validate'=>'1',),
114  'fk_disposal_type' => array('type'=>'sellist:c_asset_disposal_type:label:rowid::active=1', 'label'=>'AssetDisposalType', 'enabled'=>'1', 'position'=>220, 'notnull'=>0, 'visible'=>-2, 'index'=>1, 'validate'=>'1',),
115  'disposal_depreciated' => array('type'=>'boolean', 'label'=>'AssetDisposalDepreciated', 'enabled'=>'1', 'position'=>230, 'notnull'=>0, 'default'=>'0', 'visible'=>-2, 'validate'=>'1',),
116  'disposal_subject_to_vat' => array('type'=>'boolean', 'label'=>'AssetDisposalSubjectToVat', 'enabled'=>'1', 'position'=>240, 'notnull'=>0, 'default'=>'0', 'visible'=>-2, 'validate'=>'1',),
117  'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>300, 'notnull'=>0, 'visible'=>0, 'validate'=>'1',),
118  'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>301, 'notnull'=>0, 'visible'=>0, 'validate'=>'1',),
119  'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-2,),
120  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2,),
121  'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>510, 'notnull'=>1, 'visible'=>-2, 'foreignkey'=>'user.rowid',),
122  'fk_user_modif' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>'1', 'position'=>511, 'notnull'=>-1, 'visible'=>-2,),
123  'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>0,),
124  'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,),
125  'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,),
126  'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'default'=>'0', 'visible'=>2, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Validated', '9'=>'Canceled'), 'validate'=>'1',),
127  );
128  public $rowid;
129  public $ref;
130  public $label;
131  public $fk_asset_model;
132  public $reversal_amount_ht;
133  public $acquisition_value_ht;
134  public $recovered_vat;
135  public $reversal_date;
136  public $date_acquisition;
137  public $date_start;
138  public $qty;
139  public $acquisition_type;
140  public $asset_type;
141  public $not_depreciated;
142  public $disposal_date;
143  public $disposal_amount_ht;
144  public $fk_disposal_type;
145  public $disposal_depreciated;
146  public $disposal_subject_to_vat;
147  public $supplier_invoice_id;
148  public $note_public;
149  public $note_private;
150  public $date_creation;
151  public $tms;
152  public $fk_user_creat;
153  public $fk_user_modif;
154  public $last_main_doc;
155  public $import_key;
156  public $model_pdf;
157  public $status;
158  public $user_cloture_id;
159 
163  public $oldcopy;
164 
165  // /**
166  // * @var string Field with ID of parent key if this object has a parent
167  // */
168  // public $fk_element = 'fk_asset';
169  // /**
170  // * @var array List of child tables. To test if we can delete object.
171  // */
172  // protected $childtables = array();
173  // /**
174  // * @var array List of child tables. To know object to delete on cascade.
175  // * If name matches '@ClassNAme:FilePathClass;ParentFkFieldName' it will
176  // * call method deleteByParentField(parentId, ParentFkFieldName) to fetch and delete child object
177  // */
178  // protected $childtablesoncascade = array('asset_assetdet');
179 
183  public $asset_depreciation_options;
187  public $depreciation_lines = array();
188 
194  public function __construct(DoliDB $db)
195  {
196  global $conf, $langs;
197 
198  $this->db = $db;
199 
200  if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
201  $this->fields['rowid']['visible'] = 0;
202  }
203  if (!isModEnabled('multicompany') && isset($this->fields['entity'])) {
204  $this->fields['entity']['enabled'] = 0;
205  }
206 
207  // Unset fields that are disabled
208  foreach ($this->fields as $key => $val) {
209  if (isset($val['enabled']) && empty($val['enabled'])) {
210  unset($this->fields[$key]);
211  }
212  }
213 
214  // Translate some data of arrayofkeyval
215  if (is_object($langs)) {
216  foreach ($this->fields as $key => $val) {
217  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
218  foreach ($val['arrayofkeyval'] as $key2 => $val2) {
219  $this->fields[$key]['arrayofkeyval'][$key2] = $langs->trans($val2);
220  }
221  }
222  }
223  }
224  }
225 
233  public function create(User $user, $notrigger = false)
234  {
235  if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition;
236 
237  $this->db->begin();
238 
239  $result = $result_create = $this->createCommon($user, $notrigger);
240  if ($result > 0 && $this->fk_asset_model > 0) $result = $this->setDataFromAssetModel($user, $notrigger);
241  if ($result > 0) {
242  if ($this->supplier_invoice_id > 0) $this->add_object_linked('invoice_supplier', $this->supplier_invoice_id);
243  }
244 
245  if ($result < 0) {
246  $this->db->rollback();
247  } else {
248  $this->db->commit();
249  }
250 
251  return $result > 0 ? $result_create : $result;
252  }
253 
261  public function createFromClone(User $user, $fromid)
262  {
263  global $langs, $extrafields;
264  $error = 0;
265 
266  dol_syslog(__METHOD__, LOG_DEBUG);
267 
268  // $object = new self($this->db);
269  //
270  // $this->db->begin();
271  //
272  // // Load source object
273  // $result = $object->fetchCommon($fromid);
274  // if ($result > 0 && !empty($object->table_element_line)) {
275  // $object->fetchLines();
276  // }
277  //
278  // // get lines so they will be clone
279  // //foreach($this->lines as $line)
280  // // $line->fetch_optionals();
281  //
282  // // Reset some properties
283  // unset($object->id);
284  // unset($object->fk_user_creat);
285  // unset($object->import_key);
286  //
287  // // Clear fields
288  // if (property_exists($object, 'ref')) {
289  // $object->ref = empty($this->fields['ref']['default']) ? "Copy_Of_".$object->ref : $this->fields['ref']['default'];
290  // }
291  // if (property_exists($object, 'label')) {
292  // $object->label = empty($this->fields['label']['default']) ? $langs->trans("CopyOf")." ".$object->label : $this->fields['label']['default'];
293  // }
294  // if (property_exists($object, 'status')) {
295  // $object->status = self::STATUS_DRAFT;
296  // }
297  // if (property_exists($object, 'date_creation')) {
298  // $object->date_creation = dol_now();
299  // }
300  // if (property_exists($object, 'date_modification')) {
301  // $object->date_modification = null;
302  // }
303  // // ...
304  // // Clear extrafields that are unique
305  // if (is_array($object->array_options) && count($object->array_options) > 0) {
306  // $extrafields->fetch_name_optionals_label($this->table_element);
307  // foreach ($object->array_options as $key => $option) {
308  // $shortkey = preg_replace('/options_/', '', $key);
309  // if (!empty($extrafields->attributes[$this->table_element]['unique'][$shortkey])) {
310  // //var_dump($key); var_dump($clonedObj->array_options[$key]); exit;
311  // unset($object->array_options[$key]);
312  // }
313  // }
314  // }
315  //
316  // // Create clone
317  // $object->context['createfromclone'] = 'createfromclone';
318  // $result = $object->createCommon($user);
319  // if ($result < 0) {
320  // $error++;
321  // $this->error = $object->error;
322  // $this->errors = $object->errors;
323  // }
324  //
325  // if (!$error) {
326  // // copy internal contacts
327  // if ($this->copy_linked_contact($object, 'internal') < 0) {
328  // $error++;
329  // }
330  // }
331  //
332  // if (!$error) {
333  // // copy external contacts if same company
334  // if (property_exists($this, 'fk_soc') && $this->fk_soc == $object->socid) {
335  // if ($this->copy_linked_contact($object, 'external') < 0) {
336  // $error++;
337  // }
338  // }
339  // }
340  //
341  // unset($object->context['createfromclone']);
342  //
343  // // End
344  // if (!$error) {
345  // $this->db->commit();
346  // return $object;
347  // } else {
348  // $this->db->rollback();
349  // return -1;
350  // }
351  return -1;
352  }
353 
361  public function fetch($id, $ref = null)
362  {
363  $result = $this->fetchCommon($id, $ref);
364  if ($result > 0) {
365  if (!empty($this->table_element_line)) $this->fetchLines();
366 
367  $res = $this->hasDepreciationLinesInBookkeeping();
368  if ($res < 0) {
369  return -1;
370  } elseif ($res > 0) {
371  $this->fields['date_acquisition']['noteditable'] = '1';
372  $this->fields['date_start']['noteditable'] = '1';
373  $this->fields['acquisition_value_ht']['noteditable'] = '1';
374  $this->fields['recovered_vat']['noteditable'] = '1';
375  $this->fields['reversal_date']['noteditable'] = '1';
376  $this->fields['reversal_amount_ht']['noteditable'] = '1';
377  }
378  }
379  return $result;
380  }
381 
387  public function fetchLines()
388  {
389  $this->lines = array();
390 
391  return 1;
392  }
393 
394 
406  public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
407  {
408  global $conf;
409 
410  dol_syslog(__METHOD__, LOG_DEBUG);
411 
412  $records = array();
413 
414  $sql = "SELECT ";
415  $sql .= $this->getFieldList('t');
416  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
417  if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
418  $sql .= " WHERE t.entity IN (".getEntity($this->element).")";
419  } else {
420  $sql .= " WHERE 1 = 1";
421  }
422  // Manage filter
423  $sqlwhere = array();
424  if (count($filter) > 0) {
425  foreach ($filter as $key => $value) {
426  if ($key == 't.rowid') {
427  $sqlwhere[] = $key." = ".((int) $value);
428  } elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
429  $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
430  } elseif ($key == 'customsql') {
431  $sqlwhere[] = $value;
432  } elseif (strpos($value, '%') === false) {
433  $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
434  } else {
435  $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
436  }
437  }
438  }
439  if (count($sqlwhere) > 0) {
440  $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")";
441  }
442 
443  if (!empty($sortfield)) {
444  $sql .= $this->db->order($sortfield, $sortorder);
445  }
446  if (!empty($limit)) {
447  $sql .= $this->db->plimit($limit, $offset);
448  }
449 
450  $resql = $this->db->query($sql);
451  if ($resql) {
452  $num = $this->db->num_rows($resql);
453  $i = 0;
454  while ($i < ($limit ? min($limit, $num) : $num)) {
455  $obj = $this->db->fetch_object($resql);
456 
457  $record = new self($this->db);
458  $record->setVarsFromFetchObj($obj);
459 
460  $records[$record->id] = $record;
461 
462  $i++;
463  }
464  $this->db->free($resql);
465 
466  return $records;
467  } else {
468  $this->errors[] = 'Error '.$this->db->lasterror();
469  dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
470 
471  return -1;
472  }
473  }
474 
482  public function update(User $user, $notrigger = false)
483  {
484  if (!isset($this->date_start) || $this->date_start === "") $this->date_start = $this->date_acquisition;
485 
486  $this->db->begin();
487 
488  $result = $this->updateCommon($user, $notrigger);
489  if ($result > 0 && $this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model) {
490  $result = $this->setDataFromAssetModel($user, $notrigger);
491  }
492  if ($result > 0 && (
493  $this->date_start != $this->oldcopy->date_start ||
494  $this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
495  $this->reversal_date != $this->oldcopy->reversal_date ||
496  $this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
497  ($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
498  )
499  ) {
500  $result = $this->calculationDepreciation();
501  }
502 
503  if ($result < 0) {
504  $this->db->rollback();
505  } else {
506  $this->db->commit();
507  }
508 
509  return $result;
510  }
511 
519  public function delete(User $user, $notrigger = false)
520  {
521  return $this->deleteCommon($user, $notrigger);
522  //return $this->deleteCommon($user, $notrigger, 1);
523  }
524 
532  public function setDataFromAssetModel(User $user, $notrigger = false)
533  {
534  global $langs;
535  $langs->load('assets');
536 
537  // Clean parameters
538  $this->id = $this->id > 0 ? $this->id : 0;
539  $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
540 
541  // Check parameters
542  $error = 0;
543  if (empty($this->id)) {
544  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
545  $error++;
546  }
547  if (empty($this->fk_asset_model)) {
548  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetModel") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
549  $error++;
550  }
551  if ($error) {
552  return -1;
553  }
554 
555  $this->db->begin();
556 
557  // Get depreciation options
558  //---------------------------
559  require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
560  $options_model = new AssetDepreciationOptions($this->db);
561  $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
562  if ($result < 0) {
563  $this->error = $options_model->error;
564  $this->errors = $options_model->errors;
565  $error++;
566  } elseif ($result > 0) {
567  $options = new AssetDepreciationOptions($this->db);
568  $result = $options->fetchDeprecationOptions($this->id);
569  if ($result < 0) {
570  $this->error = $options->error;
571  $this->errors = $options->errors;
572  $error++;
573  }
574 
575  if (!$error) {
576  foreach ($options_model->deprecation_options as $mode_key => $fields) {
577  foreach ($fields as $field_key => $value) {
578  $options->deprecation_options[$mode_key][$field_key] = $value;
579  }
580  }
581 
582  $result = $options->updateDeprecationOptions($user, $this->id, 0, $notrigger);
583  if ($result < 0) {
584  $this->error = $options->error;
585  $this->errors = $options->errors;
586  $error++;
587  }
588  }
589  }
590 
591  // Get accountancy codes
592  //---------------------------
593  if (!$error) {
594  require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
595  $accountancy_codes_model = new AssetAccountancyCodes($this->db);
596  $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
597  if ($result < 0) {
598  $this->error = $accountancy_codes_model->error;
599  $this->errors = $accountancy_codes_model->errors;
600  $error++;
601  } elseif ($result > 0) {
602  $accountancy_codes = new AssetAccountancyCodes($this->db);
603  $result = $accountancy_codes->fetchAccountancyCodes($this->id);
604  if ($result < 0) {
605  $this->error = $accountancy_codes->error;
606  $this->errors = $accountancy_codes->errors;
607  $error++;
608  }
609 
610  if (!$error) {
611  foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
612  foreach ($fields as $field_key => $value) {
613  $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
614  }
615  }
616 
617  $result = $accountancy_codes->updateAccountancyCodes($user, $this->id, 0, $notrigger);
618  if ($result < 0) {
619  $this->error = $accountancy_codes->error;
620  $this->errors = $accountancy_codes->errors;
621  $error++;
622  }
623  }
624  }
625  }
626 
627  if ($error) {
628  $this->db->rollback();
629  return -1;
630  } else {
631  $this->db->commit();
632  return 1;
633  }
634  }
635 
641  public function fetchDepreciationLines()
642  {
643  global $langs;
644  $langs->load('assets');
645  $this->depreciation_lines = array();
646 
647  // Clean parameters
648  $this->id = $this->id > 0 ? $this->id : 0;
649 
650  // Check parameters
651  $error = 0;
652  if (empty($this->id)) {
653  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
654  $error++;
655  }
656  if ($error) {
657  return -1;
658  }
659 
660  // Old request with 'WITH'
661  /*
662  $sql = "WITH in_accounting_bookkeeping(fk_docdet) AS (";
663  $sql .= " SELECT DISTINCT fk_docdet";
664  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
665  $sql .= " WHERE doc_type = 'asset'";
666  $sql .= ")";
667  $sql .= "SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
668  $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0) . " AS bookkeeping";
669  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
670  $sql .= " LEFT JOIN in_accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid";
671  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
672  $sql .= " ORDER BY ad.depreciation_date ASC";
673  */
674 
675  $sql = "SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
676  $sql .= ", " . $this->db->ifsql('iab.fk_docdet IS NOT NULL', 1, 0) . " AS bookkeeping";
677  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
678  $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid";
679  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
680  $sql .= " ORDER BY ad.depreciation_date ASC";
681 
682  $resql = $this->db->query($sql);
683  if (!$resql) {
684  $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines') . ': ' . $this->db->lasterror();
685  return -1;
686  }
687 
688  while ($obj = $this->db->fetch_object($resql)) {
689  if (!isset($this->depreciation_lines[$obj->depreciation_mode])) $this->depreciation_lines[$obj->depreciation_mode] = array();
690  $this->depreciation_lines[$obj->depreciation_mode][] = array(
691  'id' => $obj->rowid,
692  'ref' => $obj->ref,
693  'depreciation_date' => $this->db->jdate($obj->depreciation_date),
694  'depreciation_ht' => $obj->depreciation_ht,
695  'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
696  'bookkeeping' => $obj->bookkeeping,
697  );
698  }
699 
700  return 1;
701  }
702 
709  {
710  global $langs;
711  $langs->load('assets');
712 
713  // Clean parameters
714  $this->id = $this->id > 0 ? $this->id : 0;
715 
716  // Check parameters
717  $error = 0;
718  if (empty($this->id)) {
719  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
720  $error++;
721  }
722  if ($error) {
723  return -1;
724  }
725 
726  // Old request with 'WITH'
727  /*
728  $sql = "WITH in_accounting_bookkeeping(fk_docdet) AS (";
729  $sql .= " SELECT DISTINCT fk_docdet";
730  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
731  $sql .= " WHERE doc_type = 'asset'";
732  $sql .= ")";
733  $sql .= "SELECT COUNT(*) AS has_bookkeeping";
734  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
735  $sql .= " LEFT JOIN in_accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid";
736  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
737  $sql .= " AND iab.fk_docdet IS NOT NULL";
738  */
739 
740  $sql = "SELECT COUNT(*) AS has_bookkeeping";
741  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
742  $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid";
743  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
744  $sql .= " AND iab.fk_docdet IS NOT NULL";
745 
746  $resql = $this->db->query($sql);
747  if (!$resql) {
748  $this->errors[] = $langs->trans('AssetErrorFetchDepreciationLines') . ': ' . $this->db->lasterror();
749  return -1;
750  }
751 
752  if ($obj = $this->db->fetch_object($resql)) {
753  return $obj->has_bookkeeping > 0 ? 1 : 0;
754  }
755 
756  return 0;
757  }
758 
771  public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
772  {
773  global $langs;
774  $langs->load('assets');
775 
776  // Clean parameters
777  $this->id = $this->id > 0 ? $this->id : 0;
778  $mode = strtolower(trim($mode));
779  $ref = trim($ref);
780  $accountancy_code_debit = trim($accountancy_code_debit);
781  $accountancy_code_credit = trim($accountancy_code_credit);
782 
783  // Check parameters
784  $error = 0;
785  if (empty($this->id)) {
786  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
787  $error++;
788  }
789  if ($error) {
790  return -1;
791  }
792 
793  $sql = "INSERT INTO " . MAIN_DB_PREFIX . "asset_depreciation(fk_asset, depreciation_mode, ref, depreciation_date, depreciation_ht, cumulative_depreciation_ht, accountancy_code_debit, accountancy_code_credit)";
794  $sql .= " VALUES ( ";
795  $sql .= " " . (int) $this->id;
796  $sql .= ", '" . $this->db->escape($mode) . "'";
797  $sql .= ", '" . $this->db->escape($ref) . "'";
798  $sql .= ", '" . $this->db->idate($depreciation_date) . "'";
799  $sql .= ", " . (double) $depreciation_ht;
800  $sql .= ", " . (double) $cumulative_depreciation_ht;
801  $sql .= ", '" . $this->db->escape($accountancy_code_debit) . "'";
802  $sql .= ", '" . $this->db->escape($accountancy_code_credit) . "'";
803  $sql .= ")";
804 
805  $resql = $this->db->query($sql);
806  if (!$resql) {
807  $this->errors[] = $langs->trans('AssetErrorAddDepreciationLine') . ': ' . $this->db->lasterror();
808  return -1;
809  }
810 
811  return 1;
812  }
813 
819  public function calculationDepreciation()
820  {
821  global $conf, $langs;
822  $langs->load('assets');
823 
824  // Clean parameters
825  $this->id = $this->id > 0 ? $this->id : 0;
826 
827  // Check parameters
828  $error = 0;
829  if (empty($this->id)) {
830  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Asset") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
831  $error++;
832  }
833  if ($error) {
834  return -1;
835  }
836 
837  // Get depreciation options
838  //---------------------------
839  require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
840  $options = new AssetDepreciationOptions($this->db);
841  $result = $options->fetchDeprecationOptions($this->id);
842  if ($result < 0) {
843  $this->error = $options->error;
844  $this->errors = $options->errors;
845  return -1;
846  }
847 
848  // Get accountancy codes
849  //---------------------------
850  require_once DOL_DOCUMENT_ROOT . '/asset/class/assetaccountancycodes.class.php';
851  $accountancy_codes = new AssetAccountancyCodes($this->db);
852  $result = $accountancy_codes->fetchAccountancyCodes($this->id);
853  if ($result < 0) {
854  $this->error = $accountancy_codes->error;
855  $this->errors = $accountancy_codes->errors;
856  return -1;
857  }
858 
859  $this->db->begin();
860 
861  // Delete old lines
862  $modes = array();
863  foreach ($options->deprecation_options as $mode_key => $fields) {
864  $modes[$mode_key] = $this->db->escape($mode_key);
865  }
866  $sql = "DELETE FROM " . MAIN_DB_PREFIX . "asset_depreciation";
867  $sql .= " WHERE fk_asset = " . (int) $this->id;
868  $sql .= " AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode("', '", $modes)) . "')";
869 
870  $resql = $this->db->query($sql);
871  if (!$resql) {
872  $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror();
873  $error++;
874  }
875 
876  if (!$error) {
877  // Get fiscal period
878  require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
879  require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
880  $dates = getDefaultDatesForTransfer();
881  $init_fiscal_period_start = $dates['date_start'];
882  $init_fiscal_period_end = $dates['date_end'];
883  if (empty($init_fiscal_period_start) || empty($init_fiscal_period_end)) {
884  $pastmonthyear = $dates['pastmonthyear'];
885  $pastmonth = $dates['pastmonth'];
886  $init_fiscal_period_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
887  $init_fiscal_period_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
888  }
889 
890  foreach ($options->deprecation_options as $mode_key => $fields) {
891  // Get last depreciation lines save in bookkeeping
892  //-----------------------------------------------------
893 
894  // Old request with 'WITH'
895  /*
896  $sql = "WITH in_accounting_bookkeeping(fk_docdet) AS (";
897  $sql .= " SELECT fk_docdet";
898  $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping";
899  $sql .= " WHERE doc_type = 'asset'";
900  $sql .= ")";
901  $sql .= "SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
902  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
903  $sql .= " LEFT JOIN in_accounting_bookkeeping as iab ON iab.fk_docdet = ad.rowid";
904  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
905  $sql .= " AND ad.depreciation_mode = '" . $this->db->escape($mode_key) . "'";
906  $sql .= " AND iab.fk_docdet IS NOT NULL";
907  $sql .= " ORDER BY ad.depreciation_date DESC";
908  $sql .= " LIMIT 1";
909  */
910 
911  $sql = "SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
912  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation AS ad";
913  $sql .= " LEFT JOIN (SELECT DISTINCT fk_docdet FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping WHERE doc_type = 'asset') AS iab ON iab.fk_docdet = ad.rowid";
914  $sql .= " WHERE ad.fk_asset = " . (int) $this->id;
915  $sql .= " AND ad.depreciation_mode = '" . $this->db->escape($mode_key) . "'";
916  $sql .= " AND iab.fk_docdet IS NOT NULL";
917  $sql .= " ORDER BY ad.depreciation_date DESC";
918  $sql .= " LIMIT 1";
919 
920  $resql = $this->db->query($sql);
921  if (!$resql) {
922  $this->errors[] = $langs->trans('AssetErrorFetchMaxDepreciationDateForMode', $mode_key) . ': ' . $this->db->lasterror();
923  $error++;
924  break;
925  }
926  $last_depreciation_date = '';
927  $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
928  if ($obj = $this->db->fetch_object($resql)) {
929  $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
930  $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
931  }
932 
933  // Set last cumulative depreciation
934  $sql = "UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key]['table'];
935  $sql .= " SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
936  $sql .= " WHERE fk_asset = " . (int) $this->id;
937  $resql = $this->db->query($sql);
938  if (!$resql) {
939  $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation') . ': ' . $this->db->lasterror();
940  $error++;
941  break;
942  }
943 
944  // Delete old lines
945  $sql = "DELETE " . MAIN_DB_PREFIX . "asset_depreciation FROM " . MAIN_DB_PREFIX . "asset_depreciation";
946  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab ON ab.doc_type = 'asset' AND ab.fk_docdet = " . MAIN_DB_PREFIX . "asset_depreciation.rowid";
947  $sql .= " WHERE " . MAIN_DB_PREFIX . "asset_depreciation.fk_asset = " . (int) $this->id;
948  $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.depreciation_mode = '" . $this->db->escape($mode_key) . "'";
949  $sql .= " AND ab.fk_docdet IS NULL";
950  if ($last_depreciation_date !== "") $sql .= " AND " . MAIN_DB_PREFIX . "asset_depreciation.ref != ''";
951  $resql = $this->db->query($sql);
952  if (!$resql) {
953  $this->errors[] = $langs->trans('AssetErrorClearDepreciationLines') . ': ' . $this->db->lasterror();
954  $error++;
955  break;
956  }
957 
958  // Get depreciation period
959  $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
960  $depreciation_date_end = dol_time_plus_duree($depreciation_date_start, $fields['duration'], $fields['duration_type'] == 1 ? 'm' : ($fields['duration_type'] == 2 ? 'd' : 'y'));
961  $depreciation_amount = $fields['amount_base_depreciation_ht'];
962  if ($fields['duration_type'] == 2) { // Daily
963  $fiscal_period_start = $depreciation_date_start;
964  $fiscal_period_end = $depreciation_date_start;
965  } elseif ($fields['duration_type'] == 1) { // Monthly
966  $date_temp = dol_getdate($depreciation_date_start);
967  $fiscal_period_start = dol_get_first_day($date_temp['year'], $date_temp['mon'], false);
968  $fiscal_period_end = dol_get_last_day($date_temp['year'], $date_temp['mon'], false);
969  } else { // Annually
970  $fiscal_period_start = $init_fiscal_period_start;
971  $fiscal_period_end = $init_fiscal_period_end;
972  }
973  $cumulative_depreciation_ht = $last_cumulative_depreciation_ht;
974  $depreciation_period_amount = $depreciation_amount - $this->reversal_amount_ht;
975  $start_date = $depreciation_date_start;
976  $disposal_date = isset($this->disposal_date) && $this->disposal_date !== "" ? $this->disposal_date : "";
977  $finish_date = $disposal_date !== "" ? $disposal_date : $depreciation_date_end;
978  $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key]['depreciation_debit'];
979  $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key];
980  $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key]['depreciation_credit'];
981  $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key];
982 
983  // Reversal depreciation line
984  //-----------------------------------------------------
985  if ($last_depreciation_date === "" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
986  if (is_numeric($this->reversal_date)) {
987  if ($this->reversal_date < $fiscal_period_start) {
988  $this->errors[] = $langs->trans('AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
989  $error++;
990  break;
991  }
992 
993  if (empty($this->reversal_amount_ht)) {
994  $this->errors[] = $langs->trans('AssetErrorReversalAmountNotProvidedForMode', $mode_key);
995  $error++;
996  break;
997  }
998 
999  $start_date = $this->reversal_date;
1000  $result = $this->addDepreciationLine($mode_key, '', $start_date, $this->reversal_amount_ht, $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1001  if ($result < 0) {
1002  $error++;
1003  break;
1004  }
1005  } else {
1006  $this->errors[] = $langs->trans('AssetErrorReversalDateNotProvidedForMode', $mode_key);
1007  $error++;
1008  break;
1009  }
1010  }
1011 
1012  // futures depreciation lines
1013  //-----------------------------------------------------
1014  $nb_days_in_year = !empty($conf->global->ASSET_DEPRECIATION_DURATION_PER_YEAR) ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_YEAR : 365;
1015  $nb_days_in_month = !empty($conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH) ? $conf->global->ASSET_DEPRECIATION_DURATION_PER_MONTH : 30;
1016  $period_amount = (double) price2num($depreciation_period_amount / $fields['duration'], 'MT');
1017  $first_period_found = false;
1018  $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
1019 
1020  $ref_date_format = "%Y" . ($fields['duration_type'] == 1 || $fields['duration_type'] == 2 ? '-%m' : '') . ($fields['duration_type'] == 2 ? '-%d' : '');
1021 
1022  // Loop security
1023  $idx_loop = 0;
1024  $max_loop = $fields['duration'] + 2;
1025  do {
1026  // Loop security
1027  $idx_loop++;
1028  if ($idx_loop > $max_loop) break;
1029 
1030  if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1031  // Disposal not depreciated
1032  if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1033  break;
1034  }
1035 
1036  $first_period_found = true;
1037 
1038  $period_begin = dol_print_date($fiscal_period_start, $ref_date_format);
1039  $period_end = dol_print_date($fiscal_period_end, $ref_date_format);
1040  $ref = $period_begin . ($period_begin != $period_end ? ' - ' . $period_end : '');
1041  if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1042  $ref .= ' - ' . $langs->transnoentitiesnoconv('AssetDisposal');
1043  }
1044 
1045  $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1046  $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1047  if ($fields['duration_type'] == 2) { // Daily
1048  $depreciation_ht = $period_amount;
1049  } elseif ($fields['duration_type'] == 1) { // Monthly
1050  $nb_days = min($nb_days_in_month, num_between_day($begin_date, $end_date, 1));
1051  if ($nb_days >= 28) {
1052  $date_temp = dol_getdate($begin_date);
1053  if ($date_temp['mon'] == 2) {
1054  $nb_days = 30;
1055  }
1056  }
1057  $depreciation_ht = (double) price2num($period_amount * $nb_days / $nb_days_in_month, 'MT');
1058  } else { // Annually
1059  $nb_days = min($nb_days_in_year, num_between_day($begin_date, $end_date, 1));
1060  $depreciation_ht = (double) price2num($period_amount * $nb_days / $nb_days_in_year, 'MT');
1061  }
1062 
1063  if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) { // last period
1064  $depreciation_ht = (double) price2num($depreciation_amount - $cumulative_depreciation_ht, 'MT');
1065  $cumulative_depreciation_ht = $depreciation_amount;
1066  } else {
1067  $cumulative_depreciation_ht += $depreciation_ht;
1068  }
1069 
1070  $result = $this->addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1071  if ($result < 0) {
1072  $error++;
1073  break;
1074  }
1075  }
1076 
1077  // Next fiscal period (+1 day/month/year)
1078  $fiscal_period_start = dol_time_plus_duree($fiscal_period_end, 1, 'd');
1079  if ($fields['duration_type'] == 2) { // Daily
1080  $fiscal_period_end = $fiscal_period_start;
1081  } elseif ($fields['duration_type'] == 1) { // Monthly
1082  $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'm'), -1, 'd');
1083  } else { // Annually
1084  $fiscal_period_end = dol_time_plus_duree(dol_time_plus_duree($fiscal_period_start, 1, 'y'), -1, 'd');
1085  }
1086  $last_period_date = $disposal_date !== "" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1087  } while ($fiscal_period_start < $last_period_date);
1088 
1089  if ($error) {
1090  break;
1091  }
1092  }
1093  }
1094 
1095  if ($error) {
1096  $this->db->rollback();
1097  return -1;
1098  } else {
1099  $this->db->commit();
1100  return 1;
1101  }
1102  }
1103 
1110  public function setLastCumulativeDepreciation($asset_depreciation_id)
1111  {
1112  global $langs;
1113  $langs->load('assets');
1114 
1115  // Clean parameters
1116  $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1117 
1118  // Check parameters
1119  $error = 0;
1120  if (empty($asset_depreciation_id)) {
1121  $this->errors[] = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AssetDepreciation") . ' (' . $langs->transnoentitiesnoconv("TechnicalID") . ')');
1122  $error++;
1123  }
1124  if ($error) {
1125  return -1;
1126  }
1127 
1128  $this->db->begin();
1129 
1130  require_once DOL_DOCUMENT_ROOT . '/asset/class/assetdepreciationoptions.class.php';
1131  $options = new AssetDepreciationOptions($this->db);
1132 
1133  // Get last depreciation lines save in bookkeeping
1134  //-----------------------------------------------------
1135  $sql = "SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1136  $sql .= " FROM " . MAIN_DB_PREFIX . "asset_depreciation";
1137  $sql .= " WHERE rowid = " . (int) $asset_depreciation_id;
1138  $resql = $this->db->query($sql);
1139  if (!$resql) {
1140  $this->errors[] = $langs->trans('AssetErrorFetchCumulativeDepreciation') . ': ' . $this->db->lasterror();
1141  $error++;
1142  } else {
1143  if ($obj = $this->db->fetch_object($resql)) {
1144  $mode_key = $obj->depreciation_mode;
1145  if (!empty($options->deprecation_options_fields[$mode_key])) {
1146  $sql = "UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key]['table'];
1147  $sql .= " SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1148  $sql .= " WHERE fk_asset = " . (int) $obj->fk_asset;
1149  $resql = $this->db->query($sql);
1150  if (!$resql) {
1151  $this->errors[] = $langs->trans('AssetErrorSetLastCumulativeDepreciation') . ': ' . $this->db->lasterror();
1152  $error++;
1153  }
1154  }
1155  }
1156  }
1157 
1158  if ($error) {
1159  $this->db->rollback();
1160  return -1;
1161  } else {
1162  $this->db->commit();
1163  return 1;
1164  }
1165  }
1166 
1175  public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1176  {
1177  global $conf, $langs;
1178 
1179  // Protection
1180  if ($this->status != self::STATUS_DRAFT || $this->status == self::STATUS_DISPOSED) {
1181  return 0;
1182  }
1183 
1184  $this->db->begin();
1185 
1186  $required_fields = array('disposal_date', 'disposal_date', 'fk_disposal_type');
1187  foreach ($required_fields as $field) {
1188  $this->fields[$field]['notnull'] = 1;
1189  }
1190  $result = $this->update($user, 1);
1191  foreach ($required_fields as $field) {
1192  $this->fields[$field]['notnull'] = 0;
1193  }
1194  if ($result > 0) {
1195  if ($disposal_invoice_id > 0) $this->add_object_linked('facture', $disposal_invoice_id);
1196  $result = $this->setStatusCommon($user, self::STATUS_DISPOSED, $notrigger, 'ASSET_DISPOSED');
1197  }
1198  if ($result > 0) $result = $this->calculationDepreciation();
1199 
1200  if ($result < 0) {
1201  $this->db->rollback();
1202  } else {
1203  $this->db->commit();
1204  }
1205 
1206  // Define output language
1207  if ($result > 0 && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1208  if (method_exists($this, 'generateDocument')) {
1209  global $hidedetails, $hidedesc, $hideref;
1210  $outputlangs = $langs;
1211  $newlang = '';
1212  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1213  $newlang = GETPOST('lang_id', 'aZ09');
1214  }
1215  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1216  $newlang = $this->thirdparty->default_lang;
1217  }
1218  if (!empty($newlang)) {
1219  $outputlangs = new Translate("", $conf);
1220  $outputlangs->setDefaultLang($newlang);
1221  }
1222  $model = $this->model_pdf;
1223  $ret = $this->fetch($this->id); // Reload to get new records
1224 
1225  $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1226  }
1227  }
1228 
1229  return $result;
1230  }
1231 
1239  public function reopen($user, $notrigger = 0)
1240  {
1241  global $conf, $langs;
1242 
1243  // Protection
1244  if ($this->status != self::STATUS_DISPOSED || $this->status == self::STATUS_DRAFT) {
1245  return 0;
1246  }
1247 
1248 
1249  $this->db->begin();
1250 
1251  $this->disposal_date = null;
1252  $this->disposal_amount_ht = null;
1253  $this->fk_disposal_type = null;
1254  $this->disposal_depreciated = null;
1255  $this->disposal_subject_to_vat = null;
1256  $result = $this->update($user, 1);
1257  if ($result > 0) {
1258  $this->deleteObjectLinked(null, 'facture');
1259  $result = $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'ASSET_REOPEN');
1260  }
1261  if ($result > 0) $result = $this->calculationDepreciation();
1262 
1263  if ($result < 0) {
1264  $this->db->rollback();
1265  } else {
1266  $this->db->commit();
1267  }
1268 
1269  // Define output language
1270  if ($result > 0 && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1271  if (method_exists($this, 'generateDocument')) {
1272  global $hidedetails, $hidedesc, $hideref;
1273  $outputlangs = $langs;
1274  $newlang = '';
1275  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1276  $newlang = GETPOST('lang_id', 'aZ09');
1277  }
1278  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1279  $newlang = $this->thirdparty->default_lang;
1280  }
1281  if (!empty($newlang)) {
1282  $outputlangs = new Translate("", $conf);
1283  $outputlangs->setDefaultLang($newlang);
1284  }
1285  $model = $this->model_pdf;
1286  $ret = $this->fetch($this->id); // Reload to get new records
1287 
1288  $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1289  }
1290  }
1291 
1292  return $result;
1293  }
1294 
1306  public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1307  {
1308  global $db, $conf, $langs, $hookmanager;
1309  global $dolibarr_main_authentication, $dolibarr_main_demo;
1310  global $menumanager;
1311 
1312  if (!empty($conf->dol_no_mouse_hover)) {
1313  $notooltip = 1; // Force disable tooltips
1314  }
1315 
1316  $result = '';
1317 
1318  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Asset").'</u>';
1319  if (isset($this->status)) {
1320  $label .= ' '.$this->getLibStatut(5);
1321  }
1322  $label .= '<br>';
1323  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
1324 
1325  $url = dol_buildpath('/asset/card.php', 1).'?id='.$this->id;
1326 
1327  if ($option != 'nolink') {
1328  // Add param to save lastsearch_values or not
1329  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1330  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1331  $add_save_lastsearch_values = 1;
1332  }
1333  if ($add_save_lastsearch_values) {
1334  $url .= '&save_lastsearch_values=1';
1335  }
1336  }
1337 
1338  $linkclose = '';
1339  if (empty($notooltip)) {
1340  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1341  $label = $langs->trans("ShowAsset");
1342  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1343  }
1344  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1345  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1346  } else {
1347  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1348  }
1349 
1350  if ($option == 'nolink') {
1351  $linkstart = '<span';
1352  } else {
1353  $linkstart = '<a href="'.$url.'"';
1354  }
1355  $linkstart .= $linkclose.'>';
1356  if ($option == 'nolink') {
1357  $linkend = '</span>';
1358  } else {
1359  $linkend = '</a>';
1360  }
1361 
1362  $result .= $linkstart;
1363 
1364  if (empty($this->showphoto_on_popup)) {
1365  if ($withpicto) {
1366  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1367  }
1368  } else {
1369  if ($withpicto) {
1370  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1371 
1372  list($class, $module) = explode('@', $this->picto);
1373  $upload_dir = $conf->$module->multidir_output[$conf->entity]."/$class/".dol_sanitizeFileName($this->ref);
1374  $filearray = dol_dir_list($upload_dir, "files");
1375  $filename = $filearray[0]['name'];
1376  if (!empty($filename)) {
1377  $pospoint = strpos($filearray[0]['name'], '.');
1378 
1379  $pathtophoto = $class.'/'.$this->ref.'/thumbs/'.substr($filename, 0, $pospoint).'_mini'.substr($filename, $pospoint);
1380  if (empty($conf->global->{strtoupper($module.'_'.$class).'_FORMATLISTPHOTOSASUSERS'})) {
1381  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.'" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div></div>';
1382  } else {
1383  $result .= '<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$module.'&entity='.$conf->entity.'&file='.urlencode($pathtophoto).'"></div>';
1384  }
1385 
1386  $result .= '</div>';
1387  } else {
1388  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1389  }
1390  }
1391  }
1392 
1393  if ($withpicto != 2) {
1394  $name = $this->ref;
1395  if ($option == 'label') $name = $this->label;
1396  elseif ($option == 'with_label') $name .= ' - ' . $this->label;
1397  $result .= dol_escape_htmltag($maxlen ? dol_trunc($name, $maxlen) : $name);
1398  }
1399 
1400  $result .= $linkend;
1401  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1402 
1403  global $action;
1404  $hookmanager->initHooks(array($this->element . 'dao'));
1405  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1406  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1407  if ($reshook > 0) {
1408  $result = $hookmanager->resPrint;
1409  } else {
1410  $result .= $hookmanager->resPrint;
1411  }
1412  return $result;
1413  }
1414 
1421  public function getLabelStatus($mode = 0)
1422  {
1423  return $this->LibStatut($this->status, $mode);
1424  }
1425 
1432  public function getLibStatut($mode = 0)
1433  {
1434  return $this->LibStatut($this->status, $mode);
1435  }
1436 
1437  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1445  public function LibStatut($status, $mode = 0)
1446  {
1447  // phpcs:enable
1448  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1449  global $langs;
1450  //$langs->load("asset@asset");
1451  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('AssetInProgress');
1452  $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv('AssetDisposed');
1453  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('AssetInProgress');
1454  $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv('AssetDisposed');
1455  }
1456 
1457  $statusType = 'status4';
1458  if ($status == self::STATUS_DISPOSED) {
1459  $statusType = 'status6';
1460  }
1461 
1462  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1463  }
1464 
1471  public function info($id)
1472  {
1473  $sql = "SELECT rowid, date_creation as datec, tms as datem,";
1474  $sql .= " fk_user_creat, fk_user_modif";
1475  $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
1476  $sql .= " WHERE t.rowid = ".((int) $id);
1477 
1478  $result = $this->db->query($sql);
1479  if ($result) {
1480  if ($this->db->num_rows($result)) {
1481  $obj = $this->db->fetch_object($result);
1482  $this->id = $obj->rowid;
1483 
1484  $this->user_creation_id = $obj->fk_user_author;
1485  $this->user_validation_id = $obj->fk_user_valid;
1486  $this->user_cloture_id = $obj->fk_user_cloture;
1487  $this->date_creation = $this->db->jdate($obj->datec);
1488  $this->date_modification = $this->db->jdate($obj->datem);
1489  $this->date_validation = $this->db->jdate($obj->datev);
1490  }
1491 
1492  $this->db->free($result);
1493  } else {
1494  dol_print_error($this->db);
1495  }
1496  }
1497 
1504  public function initAsSpecimen()
1505  {
1506  // Set here init that are not commonf fields
1507  // $this->property1 = ...
1508  // $this->property2 = ...
1509 
1510  $this->initAsSpecimenCommon();
1511  }
1512 
1518  public function getLinesArray()
1519  {
1520  $this->lines = array();
1521 
1522  return $this->lines;
1523  }
1524 
1530  public function getNextNumRef()
1531  {
1532  global $langs, $conf;
1533  $langs->load("asset@asset");
1534 
1535  if (empty($conf->global->ASSET_ASSET_ADDON)) {
1536  $conf->global->ASSET_ASSET_ADDON = 'mod_asset_standard';
1537  }
1538 
1539  if (!empty($conf->global->ASSET_ASSET_ADDON)) {
1540  $mybool = false;
1541 
1542  $file = $conf->global->ASSET_ASSET_ADDON.".php";
1543  $classname = $conf->global->ASSET_ASSET_ADDON;
1544 
1545  // Include file with class
1546  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1547  foreach ($dirmodels as $reldir) {
1548  $dir = dol_buildpath($reldir."core/modules/asset/");
1549 
1550  // Load file with numbering class (if found)
1551  $mybool |= @include_once $dir.$file;
1552  }
1553 
1554  if ($mybool === false) {
1555  dol_print_error('', "Failed to include file ".$file);
1556  return '';
1557  }
1558 
1559  if (class_exists($classname)) {
1560  $obj = new $classname();
1561  $numref = $obj->getNextValue($this);
1562 
1563  if ($numref != '' && $numref != '-1') {
1564  return $numref;
1565  } else {
1566  $this->error = $obj->error;
1567  //dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error);
1568  return "";
1569  }
1570  } else {
1571  print $langs->trans("Error")." ".$langs->trans("ClassNotFound").' '.$classname;
1572  return "";
1573  }
1574  } else {
1575  print $langs->trans("ErrorNumberingModuleNotSetup", $this->element);
1576  return "";
1577  }
1578  }
1579 
1591  // public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
1592  // {
1593  // global $conf, $langs;
1594  //
1595  // $result = 0;
1596  // $includedocgeneration = 1;
1597  //
1598  // $langs->load("asset@asset");
1599  //
1600  // if (!dol_strlen($modele)) {
1601  // $modele = 'standard_asset';
1602  //
1603  // if (!empty($this->model_pdf)) {
1604  // $modele = $this->model_pdf;
1605  // } elseif (!empty($conf->global->ASSET_ADDON_PDF)) {
1606  // $modele = $conf->global->ASSET_ADDON_PDF;
1607  // }
1608  // }
1609  //
1610  // $modelpath = "core/modules/asset/doc/";
1611  //
1612  // if ($includedocgeneration && !empty($modele)) {
1613  // $result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1614  // }
1615  //
1616  // return $result;
1617  // }
1618 }
Asset\fetchDepreciationLines
fetchDepreciationLines()
Fetch depreciation lines for each mode in $this->depreciation_lines (sort by depreciation date)
Definition: asset.class.php:641
CommonObject\deleteCommon
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
Definition: commonobject.class.php:9643
Asset
Class for Asset.
Definition: asset.class.php:30
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2816
CommonObject\setStatusCommon
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
Definition: commonobject.class.php:9921
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1504
CommonObject\fetchCommon
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
Definition: commonobject.class.php:9433
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3950
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
Asset\getNomUrl
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: asset.class.php:1306
AssetAccountancyCodes
Class for AssetAccountancyCodes.
Definition: assetaccountancycodes.class.php:29
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
Asset\info
info($id)
Load the info information in the object.
Definition: asset.class.php:1471
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1072
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
Asset\update
update(User $user, $notrigger=false)
Update object into database.
Definition: asset.class.php:482
Asset\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: asset.class.php:1432
CommonObject\deleteObjectLinked
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
Definition: commonobject.class.php:4275
Asset\createFromClone
createFromClone(User $user, $fromid)
Clone an object into another one.
Definition: asset.class.php:261
CommonObject\initAsSpecimenCommon
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: commonobject.class.php:9971
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
Asset\getLinesArray
getLinesArray()
Create an array of lines.
Definition: asset.class.php:1518
CommonObject\createCommon
createCommon(User $user, $notrigger=false)
Create object into database.
Definition: commonobject.class.php:9266
Asset\calculationDepreciation
calculationDepreciation()
Calculation depreciation lines (reversal and future) for each mode.
Definition: asset.class.php:819
Asset\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: asset.class.php:1504
Asset\getLabelStatus
getLabelStatus($mode=0)
Return the label of the status.
Definition: asset.class.php:1421
Asset\dispose
dispose($user, $disposal_invoice_id, $notrigger=0)
Set dispose status.
Definition: asset.class.php:1175
AssetDepreciationOptions
Class for AssetDepreciationOptions.
Definition: assetdepreciationoptions.class.php:29
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
Asset\LibStatut
LibStatut($status, $mode=0)
Return the status.
Definition: asset.class.php:1445
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:576
num_between_day
num_between_day($timestampStart, $timestampEnd, $lastday=0)
Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 201...
Definition: date.lib.php:989
CommonObject\updateCommon
updateCommon(User $user, $notrigger=false)
Update object into database.
Definition: commonobject.class.php:9539
Asset\setLastCumulativeDepreciation
setLastCumulativeDepreciation($asset_depreciation_id)
Set last cumulative depreciation for each mode.
Definition: asset.class.php:1110
Asset\reopen
reopen($user, $notrigger=0)
Set back to validated status.
Definition: asset.class.php:1239
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:595
Asset\addDepreciationLine
addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
Add depreciation line for a mode.
Definition: asset.class.php:771
Asset\fetchAll
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
Definition: asset.class.php:406
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
ref
$object ref
Definition: info.php:78
Asset\fetchLines
fetchLines()
Load object lines in memory from the database.
Definition: asset.class.php:387
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Asset\__construct
__construct(DoliDB $db)
Constructor.
Definition: asset.class.php:194
CommonObject\add_object_linked
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
Definition: commonobject.class.php:3865
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10767
Asset\create
create(User $user, $notrigger=false)
Create object into database.
Definition: asset.class.php:233
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4361
Asset\getNextNumRef
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Definition: asset.class.php:1530
Asset\setDataFromAssetModel
setDataFromAssetModel(User $user, $notrigger=false)
Set asset model.
Definition: asset.class.php:532
getDefaultDatesForTransfer
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
Definition: accounting.lib.php:273
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
CommonObject\getFieldList
getFieldList($alias='')
Function to concat keys of fields.
Definition: commonobject.class.php:9218
Asset\fetch
fetch($id, $ref=null)
Load object in memory from the database.
Definition: asset.class.php:361
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25
Asset\hasDepreciationLinesInBookkeeping
hasDepreciationLinesInBookkeeping()
If has depreciation lines in bookkeeping.
Definition: asset.class.php:708