28require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $module =
'asset';
43 public $element =
'asset';
48 public $table_element =
'asset';
53 public $picto =
'asset';
59 public $fk_element =
'fk_asset';
67 protected $childtablesoncascade = array(
68 '@AssetAccountancyCodes:/asset/class/assetaccountancycodes.class.php:fk_asset',
69 '@AssetAccountancyCodesFiscal:/asset/class/assetaccountancycodesfiscal.class.php:fk_asset'
73 const STATUS_DRAFT = 0;
74 const STATUS_VALIDATED = 1;
75 const STATUS_DISPOSED = 9;
108 public $fields = array(
109 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'css' =>
'left',
'comment' =>
"Id"),
110 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 5),
111 'ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 20,
'notnull' => 1,
'visible' => 4,
'noteditable' => 0,
'default' =>
'(PROV)',
'index' => 1,
'searchall' => 1,
'showoncombobox' => 1,
'validate' => 1,
'comment' =>
"Reference of object",
"css" =>
"maxwidth150"),
112 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'position' => 30,
'notnull' => 1,
'visible' => 1,
'searchall' => 1,
'csslist' =>
'tdoverflowmax125',
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' => 2,
'validate' => 1,),
113 '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,
'csslist' =>
'tdoverflowmax75',
'css' =>
'maxwidth300'),
114 'qty' => array(
'type' =>
'real',
'label' =>
'Qty',
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => 0,
'default' =>
'1',
'isameasure' => 1,
'css' =>
'maxwidth75imp',
'validate' => 1,),
115 'acquisition_type' => array(
'type' =>
'smallint',
'label' =>
'AssetAcquisitionType',
'enabled' => 1,
'position' => 60,
'notnull' => 1,
'visible' => 1,
'arrayofkeyval' => array(0 =>
'AssetAcquisitionTypeNew', 1 =>
'AssetAcquisitionTypeOccasion'),
'validate' => 1,
'csslist' =>
'tdoverflowmax75'),
116 '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,
'csslist' =>
'tdoverflowmax75'),
117 'not_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetNotDepreciated',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'default' =>
'0',
'visible' => 1,
'validate' => 1,
'csslist' =>
'maxwidth50 tdoverflowmax50',
'css' =>
'maxwidth50imp'),
118 'date_acquisition' => array(
'type' =>
'date',
'label' =>
'AssetDateAcquisition',
'enabled' => 1,
'position' => 90,
'notnull' => 1,
'visible' => 1,),
119 'date_start' => array(
'type' =>
'date',
'label' =>
'AssetDateStart',
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => -1,),
120 'acquisition_value_ht' => array(
'type' =>
'price',
'label' =>
'AssetAcquisitionValueHT',
'enabled' => 1,
'position' => 110,
'notnull' => 1,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
121 'recovered_vat' => array(
'type' =>
'price',
'label' =>
'AssetRecoveredVAT',
'enabled' => 1,
'position' => 120,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
122 'reversal_date' => array(
'type' =>
'date',
'label' =>
'AssetReversalDate',
'enabled' => 1,
'position' => 130,
'notnull' => 0,
'visible' => 1,),
123 'reversal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetReversalAmountHT',
'enabled' => 1,
'position' => 140,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,
'csslist' =>
'maxwidth50'),
124 'disposal_date' => array(
'type' =>
'date',
'label' =>
'AssetDisposalDate',
'enabled' => 1,
'position' => 200,
'notnull' => 0,
'visible' => -2,),
125 'disposal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetDisposalAmount',
'enabled' => 1,
'position' => 210,
'notnull' => 0,
'visible' => -2,
'default' =>
'0',
'isameasure' => 1,
'validate' => 1,),
126 '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,),
127 'disposal_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalDepreciated',
'enabled' => 1,
'position' => 230,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
128 'disposal_subject_to_vat' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalSubjectToVat',
'enabled' => 1,
'position' => 240,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
129 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'position' => 300,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
130 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'position' => 301,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
131 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'visible' => -2,),
132 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 501,
'notnull' => 0,
'visible' => -2,),
133 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -2,
'position' => 502,
'notnull' => 0,),
134 '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',),
135 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
136 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'picto' =>
'user',
'enabled' => 1,
'visible' => -2,
'position' => 512,
'notnull' => 0,
'csslist' =>
'tdoverflowmax100'),
137 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'position' => 600,
'notnull' => 0,
'visible' => 0,),
138 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 1000,
'notnull' => -1,
'visible' => -2,),
139 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'position' => 1010,
'notnull' => -1,
'visible' => 0,),
140 '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,),
158 public $fk_asset_model;
162 public $reversal_amount_ht;
166 public $acquisition_value_ht;
170 public $recovered_vat;
174 public $reversal_date;
178 public $date_acquisition;
190 public $acquisition_type;
198 public $not_depreciated;
202 public $disposal_date;
206 public $disposal_amount_ht;
210 public $fk_disposal_type;
214 public $disposal_depreciated;
218 public $disposal_subject_to_vat;
222 public $supplier_invoice_id;
230 public $note_private;
238 public $fk_user_creat;
242 public $fk_user_modif;
246 public $fk_user_valid;
250 public $last_main_doc;
269 public $asset_depreciation_options;
274 public $asset_accountancy_codes;
279 public $depreciation_lines = array();
293 $this->ismultientitymanaged = 1;
294 $this->isextrafieldmanaged = 1;
297 $this->fields[
'rowid'][
'visible'] = 0;
299 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
300 $this->fields[
'entity'][
'enabled'] = 0;
304 foreach ($this->fields as $key => $val) {
305 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
306 unset($this->fields[$key]);
311 if (is_object($langs)) {
312 foreach ($this->fields as $key => $val) {
313 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
314 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
315 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
331 if (!isset($this->date_start) || $this->date_start ===
"") {
332 $this->date_start = $this->date_acquisition;
337 $result = $result_create = $this->
createCommon($user, $notrigger);
338 if ($result > 0 && $this->fk_asset_model > 0) {
342 if ($this->supplier_invoice_id > 0) {
348 $this->db->rollback();
353 return $result > 0 ? $result_create : $result;
458 public function fetch($id, $ref =
null)
465 } elseif ($res > 0) {
466 $this->fields[
'date_acquisition'][
'noteditable'] = 1;
467 $this->fields[
'date_start'][
'noteditable'] = 1;
468 $this->fields[
'acquisition_value_ht'][
'noteditable'] = 1;
469 $this->fields[
'recovered_vat'][
'noteditable'] = 1;
470 $this->fields[
'reversal_date'][
'noteditable'] = 1;
471 $this->fields[
'reversal_amount_ht'][
'noteditable'] = 1;
491 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
499 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
500 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
501 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
503 $sql .=
" WHERE 1 = 1";
510 $this->errors[] = $errormessage;
511 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
516 if (!empty($sortfield)) {
517 $sql .= $this->db->order($sortfield, $sortorder);
519 if (!empty($limit)) {
520 $sql .= $this->db->plimit($limit, $offset);
523 $resql = $this->db->query($sql);
525 $num = $this->db->num_rows($resql);
527 while ($i < ($limit ? min($limit, $num) : $num)) {
528 $obj = $this->db->fetch_object($resql);
530 $record =
new self($this->db);
531 $record->setVarsFromFetchObj($obj);
533 $records[$record->id] = $record;
537 $this->db->free($resql);
541 $this->errors[] =
'Error '.$this->db->lasterror();
542 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
557 if (!isset($this->date_start) || $this->date_start ===
"") {
558 $this->date_start = $this->date_acquisition;
564 if ($result > 0 && $this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model) {
567 if ($result > 0 && is_object($this->oldcopy) && (
568 $this->date_start != $this->oldcopy->date_start ||
569 $this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
570 $this->reversal_date != $this->oldcopy->reversal_date ||
571 $this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
572 ($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
578 $this->db->rollback();
593 public function delete(
User $user, $notrigger = 0)
595 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_economic WHERE fk_asset = '.((int) $this->
id);
596 $this->db->query($sql);
598 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_fiscal WHERE fk_asset = '.((int) $this->
id);
599 $this->db->query($sql);
601 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_fiscal WHERE fk_asset = '.((int) $this->
id);
602 $this->db->query($sql);
604 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_economic WHERE fk_asset = '.((int) $this->
id);
605 $this->db->query($sql);
607 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation WHERE fk_asset = '.((int) $this->
id);
608 $this->db->query($sql);
624 $langs->load(
'assets');
627 $this->
id = $this->
id > 0 ? $this->id : 0;
628 $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
632 if (empty($this->
id)) {
633 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
636 if (empty($this->fk_asset_model)) {
637 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetModel") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
648 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
650 $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
652 $this->error = $options_model->error;
653 $this->errors = $options_model->errors;
655 } elseif ($result > 0) {
657 $result = $options->fetchDeprecationOptions($this->
id);
659 $this->error = $options->error;
660 $this->errors = $options->errors;
665 foreach ($options_model->deprecation_options as $mode_key => $fields) {
666 foreach ($fields as $field_key => $value) {
667 $options->deprecation_options[$mode_key][$field_key] = $value;
671 $result = $options->updateDeprecationOptions($user, $this->
id, 0, $notrigger);
673 $this->error = $options->error;
674 $this->errors = $options->errors;
683 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
685 $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
687 $this->error = $accountancy_codes_model->error;
688 $this->errors = $accountancy_codes_model->errors;
690 } elseif ($result > 0) {
692 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
694 $this->error = $accountancy_codes->error;
695 $this->errors = $accountancy_codes->errors;
700 foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
701 foreach ($fields as $field_key => $value) {
702 $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
706 $result = $accountancy_codes->updateAccountancyCodes($user, $this->
id, 0, $notrigger);
708 $this->error = $accountancy_codes->error;
709 $this->errors = $accountancy_codes->errors;
717 $this->db->rollback();
733 $langs->load(
'assets');
734 $this->depreciation_lines = array();
737 $this->
id = $this->
id > 0 ? $this->id : 0;
741 if (empty($this->
id)) {
742 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
749 $sql =
"SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht,";
750 $sql .=
" " . $this->db->ifsql(
'EXISTS (SELECT fk_docdet FROM ' . MAIN_DB_PREFIX .
'accounting_bookkeeping as ab WHERE ab.doc_type = \'asset\' AND ab.fk_docdet = ad.rowid)',
'1',
'0') .
" AS bookkeeping";
751 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
752 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
753 $sql .=
" ORDER BY ad.depreciation_date ASC";
755 $resql = $this->db->query($sql);
757 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
761 while ($obj = $this->db->fetch_object($resql)) {
762 if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
763 $this->depreciation_lines[$obj->depreciation_mode] = array();
765 $this->depreciation_lines[$obj->depreciation_mode][] = array(
768 'depreciation_date' => $this->db->jdate($obj->depreciation_date),
769 'depreciation_ht' => $obj->depreciation_ht,
770 'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
771 'bookkeeping' => $obj->bookkeeping,
786 $langs->load(
'assets');
789 $this->
id = $this->
id > 0 ? $this->id : 0;
793 if (empty($this->
id)) {
794 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
815 $sql =
"SELECT COUNT(*) AS has_bookkeeping";
816 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
817 $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";
818 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
819 $sql .=
" AND iab.fk_docdet IS NOT NULL";
821 $resql = $this->db->query($sql);
823 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
827 if ($obj = $this->db->fetch_object($resql)) {
828 return $obj->has_bookkeeping > 0 ? 1 : 0;
846 public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
849 $langs->load(
'assets');
852 $this->
id = $this->
id > 0 ? $this->id : 0;
853 $mode = strtolower(trim($mode));
855 $accountancy_code_debit = trim($accountancy_code_debit);
856 $accountancy_code_credit = trim($accountancy_code_credit);
860 if (empty($this->
id)) {
861 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
868 $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)";
869 $sql .=
" VALUES ( ";
870 $sql .=
" " . (int) $this->
id;
871 $sql .=
", '" . $this->db->escape($mode) .
"'";
872 $sql .=
", '" . $this->db->escape($ref) .
"'";
873 $sql .=
", '" . $this->db->idate($depreciation_date) .
"'";
874 $sql .=
", " . (float) $depreciation_ht;
875 $sql .=
", " . (float) $cumulative_depreciation_ht;
876 $sql .=
", '" . $this->db->escape($accountancy_code_debit) .
"'";
877 $sql .=
", '" . $this->db->escape($accountancy_code_credit) .
"'";
880 $resql = $this->db->query($sql);
882 $this->errors[] = $langs->trans(
'AssetErrorAddDepreciationLine') .
': ' . $this->db->lasterror();
896 global $conf, $langs;
897 $langs->load(
'assets');
900 $this->
id = $this->
id > 0 ? $this->id : 0;
904 if (empty($this->
id)) {
905 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
912 if (! empty($this->not_depreciated)) {
918 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
920 $result = $options->fetchDeprecationOptions($this->
id);
922 $this->error = $options->error;
923 $this->errors = $options->errors;
929 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
931 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
933 $this->error = $accountancy_codes->error;
934 $this->errors = $accountancy_codes->errors;
942 foreach ($options->deprecation_options as $mode_key => $fields) {
943 $modes[$mode_key] = $this->db->escape($mode_key);
945 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
946 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
947 $sql .=
" AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode(
"', '", $modes)) .
"')";
949 $resql = $this->db->query($sql);
951 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
957 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
958 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
961 $dates =
getCurrentPeriodOfFiscalYear($this->db, $conf, $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition);
962 $init_fiscal_period_start = $dates[
'date_start'];
963 $init_fiscal_period_end = $dates[
'date_end'];
973 foreach ($options->deprecation_options as $mode_key => $fields) {
994 $sql =
"SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
995 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
996 $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";
997 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
998 $sql .=
" AND ad.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
999 $sql .=
" AND iab.fk_docdet IS NOT NULL";
1000 $sql .=
" ORDER BY ad.depreciation_date DESC";
1003 $resql = $this->db->query($sql);
1005 $this->errors[] = $langs->trans(
'AssetErrorFetchMaxDepreciationDateForMode', $mode_key) .
': ' . $this->db->lasterror();
1009 $last_depreciation_date =
'';
1010 $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
1011 if ($obj = $this->db->fetch_object($resql)) {
1012 $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
1013 $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
1017 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1018 $sql .=
" SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
1019 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1020 $resql = $this->db->query($sql);
1022 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1028 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1029 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1030 $sql .=
" AND depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
1031 $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)";
1032 if ($last_depreciation_date !==
"") {
1033 $sql .=
" AND ref <> ''";
1035 $resql = $this->db->query($sql);
1037 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
1043 $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
1044 $depreciation_date_end =
dol_time_plus_duree(
dol_time_plus_duree((
int) $depreciation_date_start, (
float) $fields[
'duration'], $fields[
'duration_type'] == 1 ?
'm' : ($fields[
'duration_type'] == 2 ?
'd' :
'y')), -1,
'd');
1045 $depreciation_amount = $fields[
'amount_base_depreciation_ht'];
1046 if ($fields[
'duration_type'] == 2) {
1047 $fiscal_period_start = $depreciation_date_start;
1048 $fiscal_period_end = $depreciation_date_start;
1049 } elseif ($fields[
'duration_type'] == 1) {
1050 $date_temp =
dol_getdate((
int) $depreciation_date_start);
1051 $fiscal_period_start =
dol_get_first_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1052 $fiscal_period_end =
dol_get_last_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1054 $fiscal_period_start = $init_fiscal_period_start;
1055 $fiscal_period_end = $init_fiscal_period_end;
1057 $cumulative_depreciation_ht = (float) $last_cumulative_depreciation_ht;
1058 $depreciation_period_amount = $depreciation_amount - (float) $this->reversal_amount_ht;
1059 $start_date = $depreciation_date_start;
1060 $disposal_date = isset($this->disposal_date) && $this->disposal_date !==
"" ? $this->disposal_date :
"";
1061 $finish_date = $disposal_date !==
"" ? $disposal_date : $depreciation_date_end;
1062 $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_debit'];
1063 $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key] ??
'';
1064 $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_credit'];
1065 $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key] ??
'';
1069 if ($last_depreciation_date ===
"" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
1070 if (is_numeric($this->reversal_date)) {
1071 if ($this->reversal_date < $fiscal_period_start) {
1072 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
1077 if (empty($this->reversal_amount_ht)) {
1078 $this->errors[] = $langs->trans(
'AssetErrorReversalAmountNotProvidedForMode', $mode_key);
1083 $start_date = $this->reversal_date;
1084 $result = $this->
addDepreciationLine($mode_key,
'', $start_date, (
float) $this->reversal_amount_ht, (
float) $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1090 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotProvidedForMode', $mode_key);
1098 $nb_days_in_year =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_YEAR', 360);
1099 $nb_days_in_month =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_MONTH', 30);
1100 $period_amount = (float) ($fields[
'duration'] > 0 ?
price2num($depreciation_period_amount / $fields[
'duration'],
'MT') : 0);
1101 $first_period_found =
false;
1104 $first_period_date = $fiscal_period_start;
1106 $ref_date_format =
"%Y" . ($fields[
'duration_type'] == 1 || $fields[
'duration_type'] == 2 ?
'-%m' :
'') . ($fields[
'duration_type'] == 2 ?
'-%d' :
'');
1110 $max_loop = $fields[
'duration'] + 2;
1114 if ($idx_loop > $max_loop) {
1118 if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1120 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1124 $first_period_found =
true;
1126 $period_begin =
dol_print_date($fiscal_period_start, $ref_date_format);
1127 $period_end =
dol_print_date($fiscal_period_end, $ref_date_format);
1128 $ref = $period_begin . ($period_begin != $period_end ?
' - ' . $period_end :
'');
1129 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1130 $ref .=
' - ' . $langs->transnoentitiesnoconv(
'AssetDisposal');
1133 $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1134 $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1135 if ($fields[
'duration_type'] == 2) {
1136 $depreciation_ht = $period_amount;
1137 } elseif ($fields[
'duration_type'] == 1) {
1138 $nb_days = min($nb_days_in_month,
num_between_day($begin_date, $end_date, 1));
1139 if ($nb_days >= 28) {
1141 if ($date_temp[
'mon'] == 2) {
1145 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_month,
'MT');
1148 if (($nb_days_real > 366) || (
num_between_day($fiscal_period_start, $fiscal_period_end, 1) < $nb_days_in_year)) {
1149 $nb_days = $nb_days_real;
1151 $nb_days = min($nb_days_in_year, $nb_days_real);
1153 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_year,
'MT');
1156 if ($idx_loop < $max_loop) {
1157 $depreciation_ht = ceil($depreciation_ht);
1161 if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) {
1162 $depreciation_ht = (float)
price2num($depreciation_amount - (
float) $cumulative_depreciation_ht,
'MT');
1163 $cumulative_depreciation_ht = $depreciation_amount;
1165 $cumulative_depreciation_ht += $depreciation_ht;
1168 $result = $this->
addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, (
float) $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1178 if ($fields[
'duration_type'] == 0) {
1182 if ($next_fy !==
null) {
1184 $fiscal_period_start = $next_fy[
'date_start'];
1185 $fiscal_period_end = $next_fy[
'date_end'];
1189 $current_fy_start_parts =
dol_getdate($fiscal_period_start);
1197 } elseif ($fields[
'duration_type'] == 1) {
1200 $fiscal_period_end = $fiscal_period_start;
1202 $last_period_date = $disposal_date !==
"" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1203 }
while ($fiscal_period_start < $last_period_date);
1212 $this->db->rollback();
1215 $this->db->commit();
1229 $langs->load(
'assets');
1232 $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1236 if (empty($asset_depreciation_id)) {
1237 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetDepreciation") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
1246 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
1251 $sql =
"SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1252 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1253 $sql .=
" WHERE rowid = " . (int) $asset_depreciation_id;
1254 $resql = $this->db->query($sql);
1256 $this->errors[] = $langs->trans(
'AssetErrorFetchCumulativeDepreciation') .
': ' . $this->db->lasterror();
1259 if ($obj = $this->db->fetch_object($resql)) {
1260 $mode_key = $obj->depreciation_mode;
1261 if (!empty($options->deprecation_options_fields[$mode_key])) {
1262 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1263 $sql .=
" SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1264 $sql .=
" WHERE fk_asset = " . (int) $obj->fk_asset;
1265 $resql = $this->db->query($sql);
1267 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1275 $this->db->rollback();
1278 $this->db->commit();
1291 public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1293 global $conf, $langs;
1296 if ($this->
status == self::STATUS_DISPOSED) {
1302 $required_fields = array(
'disposal_date',
'disposal_date',
'fk_disposal_type');
1303 foreach ($required_fields as $field) {
1304 $this->fields[$field][
'notnull'] = 1;
1306 $result = $this->
update($user, 1);
1307 foreach ($required_fields as $field) {
1308 $this->fields[$field][
'notnull'] = 0;
1311 if ($disposal_invoice_id > 0) {
1314 $result = $this->
setStatusCommon($user, self::STATUS_DISPOSED, $notrigger,
'ASSET_DISPOSED');
1321 $this->db->rollback();
1323 $this->db->commit();
1328 if (method_exists($this,
'generateDocument')) {
1329 global $hidedetails, $hidedesc, $hideref;
1330 $outputlangs = $langs;
1333 $newlang =
GETPOST(
'lang_id',
'aZ09');
1335 if (!empty($newlang)) {
1336 $outputlangs =
new Translate(
"", $conf);
1337 $outputlangs->setDefaultLang($newlang);
1339 $model = $this->model_pdf;
1340 $ret = $this->
fetch($this->
id);
1342 $this->
generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1356 public function reopen($user, $notrigger = 0)
1358 global $conf, $langs;
1361 if ($this->
status != self::STATUS_DISPOSED) {
1368 $this->disposal_date =
null;
1369 $this->disposal_amount_ht =
null;
1370 $this->fk_disposal_type =
null;
1371 $this->disposal_depreciated = 0;
1372 $this->disposal_subject_to_vat = 0;
1373 $result = $this->
update($user, 1);
1376 $result = $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'ASSET_REOPEN');
1383 $this->db->rollback();
1385 $this->db->commit();
1390 if (method_exists($this,
'generateDocument')) {
1391 global $hidedetails, $hidedesc, $hideref;
1392 $outputlangs = $langs;
1395 $newlang =
GETPOST(
'lang_id',
'aZ09');
1397 if (!empty($newlang)) {
1398 $outputlangs =
new Translate(
"", $conf);
1399 $outputlangs->setDefaultLang($newlang);
1401 $model = $this->model_pdf;
1402 $ret = $this->
fetch($this->
id);
1404 $this->
generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1422 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1424 global $db, $conf, $langs, $hookmanager;
1425 global $dolibarr_main_authentication, $dolibarr_main_demo;
1426 global $menumanager;
1428 if (!empty($conf->dol_no_mouse_hover)) {
1434 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Asset").
'</u>';
1435 if (isset($this->
status)) {
1436 $label .=
' '.$this->getLibStatut(5);
1439 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1441 $url =
dol_buildpath(
'/asset/card.php', 1).
'?id='.$this->id;
1443 if ($option !=
'nolink') {
1445 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1446 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1447 $add_save_lastsearch_values = 1;
1449 if ($add_save_lastsearch_values) {
1450 $url .=
'&save_lastsearch_values=1';
1455 if (empty($notooltip)) {
1457 $label = $langs->trans(
"ShowAsset");
1458 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1460 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1461 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1463 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1466 if ($option ==
'nolink') {
1467 $linkstart =
'<span';
1469 $linkstart =
'<a href="'.$url.
'"';
1471 $linkstart .= $linkclose.
'>';
1472 if ($option ==
'nolink') {
1473 $linkend =
'</span>';
1478 $result .= $linkstart;
1480 if (empty($this->showphoto_on_popup)) {
1482 $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);
1486 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1488 list($class, $module) = explode(
'@', $this->picto);
1491 $filename = $filearray[0][
'name'];
1492 if (!empty($filename)) {
1493 $pospoint = strpos($filearray[0][
'name'],
'.');
1495 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
1496 if (!
getDolGlobalString(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
1497 $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>';
1499 $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>';
1502 $result .=
'</div>';
1504 $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);
1509 if ($withpicto != 2) {
1511 if ($option ==
'label') {
1512 $name = $this->label;
1513 } elseif ($option ==
'with_label') {
1514 $name .=
' - ' . $this->label;
1519 $result .= $linkend;
1523 $hookmanager->initHooks(array($this->element .
'dao'));
1524 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1525 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1527 $result = $hookmanager->resPrint;
1529 $result .= $hookmanager->resPrint;
1567 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1570 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1571 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1572 $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1573 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1574 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1575 $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1578 $statusType =
'status'.$status;
1579 if ($status == self::STATUS_VALIDATED) {
1580 $statusType =
'status4';
1582 if ($status == self::STATUS_DISPOSED) {
1583 $statusType =
'status6';
1586 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1597 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_valid as datev,";
1598 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
1599 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
1600 $sql .=
" WHERE t.rowid = ".((int) $id);
1602 $result = $this->db->query($sql);
1604 if ($this->db->num_rows($result)) {
1605 $obj = $this->db->fetch_object($result);
1606 $this->
id = $obj->rowid;
1608 $this->user_creation_id = $obj->fk_user_creat;
1609 $this->user_modification_id = $obj->fk_user_modif;
1610 $this->user_validation_id = $obj->fk_user_valid;
1611 $this->date_creation = $this->db->jdate($obj->datec);
1612 $this->date_modification = $this->db->jdate($obj->datem);
1613 $this->date_validation = $this->db->jdate($obj->datev);
1616 $this->db->free($result);
1648 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
1652 $langs->load(
"assets");
1655 $modele =
'standard_asset';
1657 if ($this->model_pdf) {
1658 $modele = $this->model_pdf;
1664 $modelpath =
"core/modules/asset/doc/";
1666 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1674 public function getNextNumRef()
1676 global $langs, $conf;
1677 $langs->load(
"assets");
1680 $conf->global->ASSET_ASSET_ADDON =
'mod_asset_standard';
1690 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1691 foreach ($dirmodels as $reldir) {
1695 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1703 if (class_exists($classname)) {
1704 $obj =
new $classname();
1706 '@phan-var-force ModeleNumRefAsset $obj';
1709 $numref = $obj->getNextValue($this);
1711 if ($numref !=
'' && $numref !=
'-1') {
1714 $this->error = $obj->error;
1719 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1723 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1739 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1744 if ($this->
status == self::STATUS_VALIDATED) {
1745 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
1754 if ( (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1755 $num = $this->getNextNumRef();
1757 $num = (string) $this->
ref;
1762 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1763 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1764 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1765 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1766 $sql .=
" fk_user_valid = ".((int) $user->id);
1767 $sql .=
" WHERE rowid = ".((int) $this->
id);
1769 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1770 $resql = $this->db->query($sql);
1773 $this->error = $this->db->lasterror();
1777 if (!$error && !$notrigger) {
1779 $result = $this->call_trigger(
'ASSET_VALIDATE', $user);
1787 $this->oldref = $this->ref;
1790 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1792 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'asset/".$this->db->escape($this->newref).
"'";
1793 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1794 $resql = $this->db->query($sql);
1797 $this->error = $this->db->lasterror();
1799 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'asset/".$this->db->escape($this->newref).
"'";
1800 $sql .=
" WHERE filepath = 'asset/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1801 $resql = $this->db->query($sql);
1804 $this->error = $this->db->lasterror();
1810 $dirsource = $conf->asset->dir_output.
'/'.$oldref;
1811 $dirdest = $conf->asset->dir_output.
'/'.$newref;
1812 if (!$error && file_exists($dirsource)) {
1813 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1815 if (@rename($dirsource, $dirdest)) {
1818 $listoffiles =
dol_dir_list($conf->asset->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1819 foreach ($listoffiles as $fileentry) {
1820 $dirsource = $fileentry[
'name'];
1821 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1822 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1823 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1824 @rename($dirsource, $dirdest);
1834 $this->
status = self::STATUS_VALIDATED;
1838 $this->db->commit();
1841 $this->db->rollback();
1856 if ($this->
status <= self::STATUS_DRAFT) {
1860 return $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'ASSET_UNVALIDATE');
getCurrentPeriodOfFiscalYear($db, $conf, $from_time=null, $gm='tzserver', $withenddateonly=1)
Get current period of fiscal year?
getNextFiscalYear($db, $after_date, $gm='tzserver')
Get next fiscal year period after a given date.
Class for AssetAccountancyCodes.
Class for AssetDepreciationOptions.
getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
hasDepreciationLinesInBookkeeping()
If has depreciation lines in bookkeeping.
setDraft($user, $notrigger=0)
Set draft status.
dispose($user, $disposal_invoice_id, $notrigger=0)
Set dispose status.
validate($user, $notrigger=0)
Validate asset.
createFromClone(User $user, $fromid)
Clone an object into another one.
calculationDepreciation()
Calculation depreciation lines (reversal and future) for each mode.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=0)
Create object into database.
info($id)
Load the info information in the object.
getLabelStatus($mode=0)
Return the label of the status.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the 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 if disposed 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.
update(User $user, $notrigger=0)
Update object into database.
setDataFromAssetModel(User $user, $notrigger=0)
Set asset model.
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.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
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=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
updateCommon(User $user, $notrigger=0)
Update object into database.
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.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
dol_dir_list($utf8_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.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...