25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $module =
'asset';
40 public $element =
'asset';
45 public $table_element =
'asset';
51 public $ismultientitymanaged = 1;
56 public $isextrafieldmanaged = 1;
61 public $picto =
'asset';
63 const STATUS_DRAFT = 0;
64 const STATUS_DISPOSED = 9;
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',),
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;
139 public $acquisition_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;
149 public $note_private;
150 public $date_creation;
152 public $fk_user_creat;
153 public $fk_user_modif;
154 public $last_main_doc;
168 public $asset_depreciation_options;
172 public $depreciation_lines = array();
181 global $conf, $langs;
186 $this->fields[
'rowid'][
'visible'] = 0;
188 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
189 $this->fields[
'entity'][
'enabled'] = 0;
193 foreach ($this->fields as $key => $val) {
194 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
195 unset($this->fields[$key]);
200 if (is_object($langs)) {
201 foreach ($this->fields as $key => $val) {
202 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
203 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
204 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
220 if (!isset($this->date_start) || $this->date_start ===
"") {
221 $this->date_start = $this->date_acquisition;
226 $result = $result_create = $this->
createCommon($user, $notrigger);
227 if ($result > 0 && $this->fk_asset_model > 0) {
231 if ($this->supplier_invoice_id > 0) {
237 $this->db->rollback();
242 return $result > 0 ? $result_create : $result;
254 global $langs, $extrafields;
352 public function fetch($id, $ref =
null)
356 if (!empty($this->table_element_line)) {
363 } elseif ($res > 0) {
364 $this->fields[
'date_acquisition'][
'noteditable'] =
'1';
365 $this->fields[
'date_start'][
'noteditable'] =
'1';
366 $this->fields[
'acquisition_value_ht'][
'noteditable'] =
'1';
367 $this->fields[
'recovered_vat'][
'noteditable'] =
'1';
368 $this->fields[
'reversal_date'][
'noteditable'] =
'1';
369 $this->fields[
'reversal_amount_ht'][
'noteditable'] =
'1';
382 $this->lines = array();
399 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
409 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
410 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
411 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
413 $sql .=
" WHERE 1 = 1";
417 if (count($filter) > 0) {
418 foreach ($filter as $key => $value) {
419 if ($key ==
't.rowid') {
420 $sqlwhere[] = $key.
" = ".((int) $value);
421 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
422 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
423 } elseif ($key ==
'customsql') {
424 $sqlwhere[] = $value;
425 } elseif (strpos($value,
'%') ===
false) {
426 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
428 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
432 if (count($sqlwhere) > 0) {
433 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
436 if (!empty($sortfield)) {
437 $sql .= $this->db->order($sortfield, $sortorder);
439 if (!empty($limit)) {
440 $sql .= $this->db->plimit($limit, $offset);
443 $resql = $this->db->query($sql);
445 $num = $this->db->num_rows($resql);
447 while ($i < ($limit ? min($limit, $num) : $num)) {
448 $obj = $this->db->fetch_object($resql);
450 $record =
new self($this->db);
451 $record->setVarsFromFetchObj($obj);
453 $records[$record->id] = $record;
457 $this->db->free($resql);
461 $this->errors[] =
'Error '.$this->db->lasterror();
462 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
477 if (!isset($this->date_start) || $this->date_start ===
"") {
478 $this->date_start = $this->date_acquisition;
484 if ($result > 0 && $this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model) {
488 $this->date_start != $this->oldcopy->date_start ||
489 $this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
490 $this->reversal_date != $this->oldcopy->reversal_date ||
491 $this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
492 ($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
499 $this->db->rollback();
514 public function delete(
User $user, $notrigger =
false)
530 $langs->load(
'assets');
533 $this->
id = $this->
id > 0 ? $this->id : 0;
534 $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
538 if (empty($this->
id)) {
539 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
542 if (empty($this->fk_asset_model)) {
543 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetModel") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
554 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
556 $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
558 $this->error = $options_model->error;
559 $this->errors = $options_model->errors;
561 } elseif ($result > 0) {
563 $result = $options->fetchDeprecationOptions($this->
id);
565 $this->error = $options->error;
566 $this->errors = $options->errors;
571 foreach ($options_model->deprecation_options as $mode_key => $fields) {
572 foreach ($fields as $field_key => $value) {
573 $options->deprecation_options[$mode_key][$field_key] = $value;
577 $result = $options->updateDeprecationOptions($user, $this->
id, 0, $notrigger);
579 $this->error = $options->error;
580 $this->errors = $options->errors;
589 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
591 $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
593 $this->error = $accountancy_codes_model->error;
594 $this->errors = $accountancy_codes_model->errors;
596 } elseif ($result > 0) {
598 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
600 $this->error = $accountancy_codes->error;
601 $this->errors = $accountancy_codes->errors;
606 foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
607 foreach ($fields as $field_key => $value) {
608 $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
612 $result = $accountancy_codes->updateAccountancyCodes($user, $this->
id, 0, $notrigger);
614 $this->error = $accountancy_codes->error;
615 $this->errors = $accountancy_codes->errors;
623 $this->db->rollback();
639 $langs->load(
'assets');
640 $this->depreciation_lines = array();
643 $this->
id = $this->
id > 0 ? $this->id : 0;
647 if (empty($this->
id)) {
648 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
670 $sql =
"SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
671 $sql .=
", " . $this->db->ifsql(
'iab.fk_docdet IS NOT NULL', 1, 0) .
" AS bookkeeping";
672 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
673 $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";
674 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
675 $sql .=
" ORDER BY ad.depreciation_date ASC";
677 $resql = $this->db->query($sql);
679 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
683 while ($obj = $this->db->fetch_object($resql)) {
684 if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
685 $this->depreciation_lines[$obj->depreciation_mode] = array();
687 $this->depreciation_lines[$obj->depreciation_mode][] = array(
690 'depreciation_date' => $this->db->jdate($obj->depreciation_date),
691 'depreciation_ht' => $obj->depreciation_ht,
692 'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
693 'bookkeeping' => $obj->bookkeeping,
708 $langs->load(
'assets');
711 $this->
id = $this->
id > 0 ? $this->id : 0;
715 if (empty($this->
id)) {
716 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
737 $sql =
"SELECT COUNT(*) AS has_bookkeeping";
738 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
739 $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";
740 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
741 $sql .=
" AND iab.fk_docdet IS NOT NULL";
743 $resql = $this->db->query($sql);
745 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
749 if ($obj = $this->db->fetch_object($resql)) {
750 return $obj->has_bookkeeping > 0 ? 1 : 0;
768 public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
771 $langs->load(
'assets');
774 $this->
id = $this->
id > 0 ? $this->id : 0;
775 $mode = strtolower(trim($mode));
777 $accountancy_code_debit = trim($accountancy_code_debit);
778 $accountancy_code_credit = trim($accountancy_code_credit);
782 if (empty($this->
id)) {
783 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
790 $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)";
791 $sql .=
" VALUES ( ";
792 $sql .=
" " . (int) $this->
id;
793 $sql .=
", '" . $this->db->escape($mode) .
"'";
794 $sql .=
", '" . $this->db->escape($ref) .
"'";
795 $sql .=
", '" . $this->db->idate($depreciation_date) .
"'";
796 $sql .=
", " . (float) $depreciation_ht;
797 $sql .=
", " . (float) $cumulative_depreciation_ht;
798 $sql .=
", '" . $this->db->escape($accountancy_code_debit) .
"'";
799 $sql .=
", '" . $this->db->escape($accountancy_code_credit) .
"'";
802 $resql = $this->db->query($sql);
804 $this->errors[] = $langs->trans(
'AssetErrorAddDepreciationLine') .
': ' . $this->db->lasterror();
818 global $conf, $langs;
819 $langs->load(
'assets');
822 $this->
id = $this->
id > 0 ? $this->id : 0;
826 if (empty($this->
id)) {
827 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
836 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
838 $result = $options->fetchDeprecationOptions($this->
id);
840 $this->error = $options->error;
841 $this->errors = $options->errors;
847 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
849 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
851 $this->error = $accountancy_codes->error;
852 $this->errors = $accountancy_codes->errors;
860 foreach ($options->deprecation_options as $mode_key => $fields) {
861 $modes[$mode_key] = $this->db->escape($mode_key);
863 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
864 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
865 $sql .=
" AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode(
"', '", $modes)) .
"')";
867 $resql = $this->db->query($sql);
869 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
875 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
876 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
877 $dates =
getCurrentPeriodOfFiscalYear($this->db, $conf, $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition);
878 $init_fiscal_period_start = $dates[
'date_start'];
879 $init_fiscal_period_end = $dates[
'date_end'];
880 if (empty($init_fiscal_period_start) || empty($init_fiscal_period_end)) {
881 $pastmonthyear = $dates[
'pastmonthyear'];
882 $pastmonth = $dates[
'pastmonth'];
883 $init_fiscal_period_start =
dol_get_first_day($pastmonthyear, $pastmonth,
false);
884 $init_fiscal_period_end =
dol_get_last_day($pastmonthyear, $pastmonth,
false);
887 foreach ($options->deprecation_options as $mode_key => $fields) {
908 $sql =
"SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
909 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
910 $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";
911 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
912 $sql .=
" AND ad.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
913 $sql .=
" AND iab.fk_docdet IS NOT NULL";
914 $sql .=
" ORDER BY ad.depreciation_date DESC";
917 $resql = $this->db->query($sql);
919 $this->errors[] = $langs->trans(
'AssetErrorFetchMaxDepreciationDateForMode', $mode_key) .
': ' . $this->db->lasterror();
923 $last_depreciation_date =
'';
924 $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
925 if ($obj = $this->db->fetch_object($resql)) {
926 $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
927 $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
931 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
932 $sql .=
" SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
933 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
934 $resql = $this->db->query($sql);
936 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
942 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
943 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
944 $sql .=
" AND depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
945 $sql .=
" AND NOT EXISTS (SELECT fk_docdet FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping WHERE doc_type = 'asset' AND fk_docdet = " . MAIN_DB_PREFIX .
"asset_depreciation.rowid)";
946 if ($last_depreciation_date !==
"") {
947 $sql .=
" AND ref <> ''";
949 $resql = $this->db->query($sql);
951 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
957 $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
958 $depreciation_date_end =
dol_time_plus_duree($depreciation_date_start, $fields[
'duration'], $fields[
'duration_type'] == 1 ?
'm' : ($fields[
'duration_type'] == 2 ?
'd' :
'y'));
959 $depreciation_amount = $fields[
'amount_base_depreciation_ht'];
960 if ($fields[
'duration_type'] == 2) {
961 $fiscal_period_start = $depreciation_date_start;
962 $fiscal_period_end = $depreciation_date_start;
963 } elseif ($fields[
'duration_type'] == 1) {
964 $date_temp =
dol_getdate($depreciation_date_start);
965 $fiscal_period_start =
dol_get_first_day($date_temp[
'year'], $date_temp[
'mon'],
false);
966 $fiscal_period_end =
dol_get_last_day($date_temp[
'year'], $date_temp[
'mon'],
false);
968 $fiscal_period_start = $init_fiscal_period_start;
969 $fiscal_period_end = $init_fiscal_period_end;
971 $cumulative_depreciation_ht = $last_cumulative_depreciation_ht;
972 $depreciation_period_amount = $depreciation_amount - $this->reversal_amount_ht;
973 $start_date = $depreciation_date_start;
974 $disposal_date = isset($this->disposal_date) && $this->disposal_date !==
"" ? $this->disposal_date :
"";
975 $finish_date = $disposal_date !==
"" ? $disposal_date : $depreciation_date_end;
976 $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_debit'];
977 $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key];
978 $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_credit'];
979 $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key];
983 if ($last_depreciation_date ===
"" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
984 if (is_numeric($this->reversal_date)) {
985 if ($this->reversal_date < $fiscal_period_start) {
986 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
991 if (empty($this->reversal_amount_ht)) {
992 $this->errors[] = $langs->trans(
'AssetErrorReversalAmountNotProvidedForMode', $mode_key);
997 $start_date = $this->reversal_date;
998 $result = $this->
addDepreciationLine($mode_key,
'', $start_date, $this->reversal_amount_ht, $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1004 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotProvidedForMode', $mode_key);
1012 $nb_days_in_year =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_YEAR', 365);
1013 $nb_days_in_month =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_MONTH', 30);
1014 $period_amount = (float) ($fields[
'duration'] > 0 ?
price2num($depreciation_period_amount / $fields[
'duration'],
'MT') : 0);
1015 $first_period_found =
false;
1018 $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
1020 $ref_date_format =
"%Y" . ($fields[
'duration_type'] == 1 || $fields[
'duration_type'] == 2 ?
'-%m' :
'') . ($fields[
'duration_type'] == 2 ?
'-%d' :
'');
1024 $max_loop = $fields[
'duration'] + 2;
1028 if ($idx_loop > $max_loop) {
1032 if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1034 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1038 $first_period_found =
true;
1040 $period_begin =
dol_print_date($fiscal_period_start, $ref_date_format);
1041 $period_end =
dol_print_date($fiscal_period_end, $ref_date_format);
1042 $ref = $period_begin . ($period_begin != $period_end ?
' - ' . $period_end :
'');
1043 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1044 $ref .=
' - ' . $langs->transnoentitiesnoconv(
'AssetDisposal');
1047 $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1048 $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1049 if ($fields[
'duration_type'] == 2) {
1050 $depreciation_ht = $period_amount;
1051 } elseif ($fields[
'duration_type'] == 1) {
1052 $nb_days = min($nb_days_in_month,
num_between_day($begin_date, $end_date, 1));
1053 if ($nb_days >= 28) {
1055 if ($date_temp[
'mon'] == 2) {
1059 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_month,
'MT');
1061 $nb_days = min($nb_days_in_year,
num_between_day($begin_date, $end_date, 1));
1062 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_year,
'MT');
1065 if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) {
1066 $depreciation_ht = (float)
price2num($depreciation_amount - $cumulative_depreciation_ht,
'MT');
1067 $cumulative_depreciation_ht = $depreciation_amount;
1069 $cumulative_depreciation_ht += $depreciation_ht;
1072 $result = $this->
addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1081 if ($fields[
'duration_type'] == 2) {
1082 $fiscal_period_end = $fiscal_period_start;
1083 } elseif ($fields[
'duration_type'] == 1) {
1088 $last_period_date = $disposal_date !==
"" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1089 }
while ($fiscal_period_start < $last_period_date);
1098 $this->db->rollback();
1101 $this->db->commit();
1115 $langs->load(
'assets');
1118 $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1122 if (empty($asset_depreciation_id)) {
1123 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetDepreciation") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
1132 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
1137 $sql =
"SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1138 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1139 $sql .=
" WHERE rowid = " . (int) $asset_depreciation_id;
1140 $resql = $this->db->query($sql);
1142 $this->errors[] = $langs->trans(
'AssetErrorFetchCumulativeDepreciation') .
': ' . $this->db->lasterror();
1145 if ($obj = $this->db->fetch_object($resql)) {
1146 $mode_key = $obj->depreciation_mode;
1147 if (!empty($options->deprecation_options_fields[$mode_key])) {
1148 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1149 $sql .=
" SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1150 $sql .=
" WHERE fk_asset = " . (int) $obj->fk_asset;
1151 $resql = $this->db->query($sql);
1153 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1161 $this->db->rollback();
1164 $this->db->commit();
1177 public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1179 global $conf, $langs;
1182 if ($this->
status != self::STATUS_DRAFT || $this->
status == self::STATUS_DISPOSED) {
1188 $required_fields = array(
'disposal_date',
'disposal_date',
'fk_disposal_type');
1189 foreach ($required_fields as $field) {
1190 $this->fields[$field][
'notnull'] = 1;
1192 $result = $this->
update($user, 1);
1193 foreach ($required_fields as $field) {
1194 $this->fields[$field][
'notnull'] = 0;
1197 if ($disposal_invoice_id > 0) {
1200 $result = $this->
setStatusCommon($user, self::STATUS_DISPOSED, $notrigger,
'ASSET_DISPOSED');
1207 $this->db->rollback();
1209 $this->db->commit();
1214 if (method_exists($this,
'generateDocument')) {
1215 global $hidedetails, $hidedesc, $hideref;
1216 $outputlangs = $langs;
1219 $newlang =
GETPOST(
'lang_id',
'aZ09');
1222 $newlang = $this->thirdparty->default_lang;
1224 if (!empty($newlang)) {
1225 $outputlangs =
new Translate(
"", $conf);
1226 $outputlangs->setDefaultLang($newlang);
1228 $model = $this->model_pdf;
1229 $ret = $this->
fetch($this->
id);
1231 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1245 public function reopen($user, $notrigger = 0)
1247 global $conf, $langs;
1250 if ($this->
status != self::STATUS_DISPOSED || $this->
status == self::STATUS_DRAFT) {
1257 $this->disposal_date =
null;
1258 $this->disposal_amount_ht =
null;
1259 $this->fk_disposal_type =
null;
1260 $this->disposal_depreciated =
null;
1261 $this->disposal_subject_to_vat =
null;
1262 $result = $this->
update($user, 1);
1265 $result = $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'ASSET_REOPEN');
1272 $this->db->rollback();
1274 $this->db->commit();
1279 if (method_exists($this,
'generateDocument')) {
1280 global $hidedetails, $hidedesc, $hideref;
1281 $outputlangs = $langs;
1284 $newlang =
GETPOST(
'lang_id',
'aZ09');
1287 $newlang = $this->thirdparty->default_lang;
1289 if (!empty($newlang)) {
1290 $outputlangs =
new Translate(
"", $conf);
1291 $outputlangs->setDefaultLang($newlang);
1293 $model = $this->model_pdf;
1294 $ret = $this->
fetch($this->
id);
1296 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1314 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1316 global $db, $conf, $langs, $hookmanager;
1317 global $dolibarr_main_authentication, $dolibarr_main_demo;
1318 global $menumanager;
1320 if (!empty($conf->dol_no_mouse_hover)) {
1326 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Asset").
'</u>';
1327 if (isset($this->
status)) {
1328 $label .=
' '.$this->getLibStatut(5);
1331 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1333 $url =
dol_buildpath(
'/asset/card.php', 1).
'?id='.$this->id;
1335 if ($option !=
'nolink') {
1337 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1338 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1339 $add_save_lastsearch_values = 1;
1341 if ($add_save_lastsearch_values) {
1342 $url .=
'&save_lastsearch_values=1';
1347 if (empty($notooltip)) {
1349 $label = $langs->trans(
"ShowAsset");
1350 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1352 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1353 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1355 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1358 if ($option ==
'nolink') {
1359 $linkstart =
'<span';
1361 $linkstart =
'<a href="'.$url.
'"';
1363 $linkstart .= $linkclose.
'>';
1364 if ($option ==
'nolink') {
1365 $linkend =
'</span>';
1370 $result .= $linkstart;
1372 if (empty($this->showphoto_on_popup)) {
1374 $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);
1378 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1380 list($class, $module) = explode(
'@', $this->picto);
1383 $filename = $filearray[0][
'name'];
1384 if (!empty($filename)) {
1385 $pospoint = strpos($filearray[0][
'name'],
'.');
1387 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
1388 if (!
getDolGlobalString(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
1389 $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>';
1391 $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>';
1394 $result .=
'</div>';
1396 $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);
1401 if ($withpicto != 2) {
1403 if ($option ==
'label') {
1404 $name = $this->label;
1405 } elseif ($option ==
'with_label') {
1406 $name .=
' - ' . $this->label;
1411 $result .= $linkend;
1415 $hookmanager->initHooks(array($this->element .
'dao'));
1416 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1417 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1419 $result = $hookmanager->resPrint;
1421 $result .= $hookmanager->resPrint;
1459 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1462 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1463 $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1464 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1465 $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1468 $statusType =
'status4';
1469 if ($status == self::STATUS_DISPOSED) {
1470 $statusType =
'status6';
1473 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1484 $sql =
"SELECT rowid, date_creation as datec, tms as datem,";
1485 $sql .=
" fk_user_creat, fk_user_modif";
1486 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
1487 $sql .=
" WHERE t.rowid = ".((int) $id);
1489 $result = $this->db->query($sql);
1491 if ($this->db->num_rows($result)) {
1492 $obj = $this->db->fetch_object($result);
1493 $this->
id = $obj->rowid;
1495 $this->user_creation_id = $obj->fk_user_creat;
1496 $this->user_modification_id = $obj->fk_user_modif;
1497 $this->date_creation = $this->db->jdate($obj->datec);
1498 $this->date_modification = $this->db->jdate($obj->datem);
1501 $this->db->free($result);
1529 $this->lines = array();
1531 return $this->lines;
1541 global $langs, $conf;
1542 $langs->load(
"assets");
1545 $conf->global->ASSET_ASSET_ADDON =
'mod_asset_standard';
1552 $classname = $conf->global->ASSET_ASSET_ADDON;
1555 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1556 foreach ($dirmodels as $reldir) {
1560 $mybool |= @include_once $dir.$file;
1563 if ($mybool ===
false) {
1568 if (class_exists($classname)) {
1569 $obj =
new $classname();
1570 $numref = $obj->getNextValue($this);
1572 if ($numref !=
'' && $numref !=
'-1') {
1575 $this->error = $obj->error;
1580 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1584 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
getCurrentPeriodOfFiscalYear($db, $conf, $from_time=null)
Get current period of fiscal year.
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Class for AssetAccountancyCodes.
Class for AssetDepreciationOptions.
create(User $user, $notrigger=false)
Create object into database.
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
hasDepreciationLinesInBookkeeping()
If has depreciation lines in bookkeeping.
getLinesArray()
Create an array of lines.
dispose($user, $disposal_invoice_id, $notrigger=0)
Set dispose status.
createFromClone(User $user, $fromid)
Clone an object into another one.
calculationDepreciation()
Calculation depreciation lines (reversal and future) for each mode.
fetchLines()
Load object lines in memory from the database.
__construct(DoliDB $db)
Constructor.
info($id)
Load the info information in the object.
getLabelStatus($mode=0)
Return the label of the status.
update(User $user, $notrigger=false)
Update object into database.
fetch($id, $ref=null)
Load object in memory from the database.
LibStatut($status, $mode=0)
Return the status.
reopen($user, $notrigger=0)
Set back to validated status.
getLibStatut($mode=0)
Return the label of the status.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
Add depreciation line for a mode.
fetchDepreciationLines()
Fetch depreciation lines for each mode in $this->depreciation_lines (sort by depreciation date)
setLastCumulativeDepreciation($asset_depreciation_id)
Set last cumulative depreciation for each mode.
setDataFromAssetModel(User $user, $notrigger=false)
Set asset model.
getNextNumRef()
Returns the reference to the following non used object depending on the active numbering module.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
updateCommon(User $user, $notrigger=false)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
Class to manage Dolibarr database access.
Class to manage translations.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...