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 '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"),
111 '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,),
112 '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'),
113 'qty' => array(
'type' =>
'real',
'label' =>
'Qty',
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => 0,
'default' =>
'1',
'isameasure' => 1,
'css' =>
'maxwidth75imp',
'validate' => 1,),
114 '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'),
115 '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'),
116 'not_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetNotDepreciated',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'default' =>
'0',
'visible' => 1,
'validate' => 1,
'csslist' =>
'maxwidth50 tdoverflowmax50',
'css' =>
'maxwidth50imp'),
117 'date_acquisition' => array(
'type' =>
'date',
'label' =>
'AssetDateAcquisition',
'enabled' => 1,
'position' => 90,
'notnull' => 1,
'visible' => 1,),
118 'date_start' => array(
'type' =>
'date',
'label' =>
'AssetDateStart',
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => -1,),
119 'acquisition_value_ht' => array(
'type' =>
'price',
'label' =>
'AssetAcquisitionValueHT',
'enabled' => 1,
'position' => 110,
'notnull' => 1,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
120 'recovered_vat' => array(
'type' =>
'price',
'label' =>
'AssetRecoveredVAT',
'enabled' => 1,
'position' => 120,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
121 'reversal_date' => array(
'type' =>
'date',
'label' =>
'AssetReversalDate',
'enabled' => 1,
'position' => 130,
'notnull' => 0,
'visible' => 1,),
122 'reversal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetReversalAmountHT',
'enabled' => 1,
'position' => 140,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,
'csslist' =>
'maxwidth50'),
123 'disposal_date' => array(
'type' =>
'date',
'label' =>
'AssetDisposalDate',
'enabled' => 1,
'position' => 200,
'notnull' => 0,
'visible' => -2,),
124 'disposal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetDisposalAmount',
'enabled' => 1,
'position' => 210,
'notnull' => 0,
'visible' => -2,
'default' =>
'0',
'isameasure' => 1,
'validate' => 1,),
125 '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,),
126 'disposal_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalDepreciated',
'enabled' => 1,
'position' => 230,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
127 'disposal_subject_to_vat' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalSubjectToVat',
'enabled' => 1,
'position' => 240,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
128 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'position' => 300,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
129 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'position' => 301,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
130 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'visible' => -2,),
131 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 501,
'notnull' => 0,
'visible' => -2,),
132 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -2,
'position' => 502,
'notnull' => 0,),
133 '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',),
134 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
135 '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'),
136 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'position' => 600,
'notnull' => 0,
'visible' => 0,),
137 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 1000,
'notnull' => -1,
'visible' => -2,),
138 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'position' => 1010,
'notnull' => -1,
'visible' => 0,),
139 '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,),
157 public $fk_asset_model;
161 public $reversal_amount_ht;
165 public $acquisition_value_ht;
169 public $recovered_vat;
173 public $reversal_date;
177 public $date_acquisition;
189 public $acquisition_type;
197 public $not_depreciated;
201 public $disposal_date;
205 public $disposal_amount_ht;
209 public $fk_disposal_type;
213 public $disposal_depreciated;
217 public $disposal_subject_to_vat;
221 public $supplier_invoice_id;
229 public $note_private;
237 public $fk_user_creat;
241 public $fk_user_modif;
245 public $fk_user_valid;
249 public $last_main_doc;
266 public $asset_depreciation_options;
271 public $asset_accountancy_codes;
276 public $depreciation_lines = array();
290 $this->ismultientitymanaged = 1;
291 $this->isextrafieldmanaged = 1;
294 $this->fields[
'rowid'][
'visible'] = 0;
296 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
297 $this->fields[
'entity'][
'enabled'] = 0;
301 foreach ($this->fields as $key => $val) {
302 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
303 unset($this->fields[$key]);
308 if (is_object($langs)) {
309 foreach ($this->fields as $key => $val) {
310 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
311 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
312 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
328 if (!isset($this->date_start) || $this->date_start ===
"") {
329 $this->date_start = $this->date_acquisition;
334 $result = $result_create = $this->
createCommon($user, $notrigger);
335 if ($result > 0 && $this->fk_asset_model > 0) {
339 if ($this->supplier_invoice_id > 0) {
345 $this->db->rollback();
350 return $result > 0 ? $result_create : $result;
362 global $langs, $extrafields;
455 public function fetch($id, $ref =
null)
462 } elseif ($res > 0) {
463 $this->fields[
'date_acquisition'][
'noteditable'] = 1;
464 $this->fields[
'date_start'][
'noteditable'] = 1;
465 $this->fields[
'acquisition_value_ht'][
'noteditable'] = 1;
466 $this->fields[
'recovered_vat'][
'noteditable'] = 1;
467 $this->fields[
'reversal_date'][
'noteditable'] = 1;
468 $this->fields[
'reversal_amount_ht'][
'noteditable'] = 1;
488 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
496 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
497 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
498 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
500 $sql .=
" WHERE 1 = 1";
507 $this->errors[] = $errormessage;
508 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
513 if (!empty($sortfield)) {
514 $sql .= $this->db->order($sortfield, $sortorder);
516 if (!empty($limit)) {
517 $sql .= $this->db->plimit($limit, $offset);
520 $resql = $this->db->query($sql);
522 $num = $this->db->num_rows($resql);
524 while ($i < ($limit ? min($limit, $num) : $num)) {
525 $obj = $this->db->fetch_object($resql);
527 $record =
new self($this->db);
528 $record->setVarsFromFetchObj($obj);
530 $records[$record->id] = $record;
534 $this->db->free($resql);
538 $this->errors[] =
'Error '.$this->db->lasterror();
539 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
554 if (!isset($this->date_start) || $this->date_start ===
"") {
555 $this->date_start = $this->date_acquisition;
561 if ($result > 0 && $this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model) {
564 if ($result > 0 && is_object($this->oldcopy) && (
565 $this->date_start != $this->oldcopy->date_start ||
566 $this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
567 $this->reversal_date != $this->oldcopy->reversal_date ||
568 $this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
569 ($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
575 $this->db->rollback();
590 public function delete(
User $user, $notrigger = 0)
592 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_economic WHERE fk_asset = '.((int) $this->
id);
593 $this->db->query($sql);
595 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_fiscal WHERE fk_asset = '.((int) $this->
id);
596 $this->db->query($sql);
598 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_fiscal WHERE fk_asset = '.((int) $this->
id);
599 $this->db->query($sql);
601 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_economic WHERE fk_asset = '.((int) $this->
id);
602 $this->db->query($sql);
604 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation WHERE fk_asset = '.((int) $this->
id);
605 $this->db->query($sql);
621 $langs->load(
'assets');
624 $this->
id = $this->
id > 0 ? $this->id : 0;
625 $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
629 if (empty($this->
id)) {
630 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
633 if (empty($this->fk_asset_model)) {
634 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetModel") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
645 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
647 $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
649 $this->error = $options_model->error;
650 $this->errors = $options_model->errors;
652 } elseif ($result > 0) {
654 $result = $options->fetchDeprecationOptions($this->
id);
656 $this->error = $options->error;
657 $this->errors = $options->errors;
662 foreach ($options_model->deprecation_options as $mode_key => $fields) {
663 foreach ($fields as $field_key => $value) {
664 $options->deprecation_options[$mode_key][$field_key] = $value;
668 $result = $options->updateDeprecationOptions($user, $this->
id, 0, $notrigger);
670 $this->error = $options->error;
671 $this->errors = $options->errors;
680 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
682 $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
684 $this->error = $accountancy_codes_model->error;
685 $this->errors = $accountancy_codes_model->errors;
687 } elseif ($result > 0) {
689 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
691 $this->error = $accountancy_codes->error;
692 $this->errors = $accountancy_codes->errors;
697 foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
698 foreach ($fields as $field_key => $value) {
699 $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
703 $result = $accountancy_codes->updateAccountancyCodes($user, $this->
id, 0, $notrigger);
705 $this->error = $accountancy_codes->error;
706 $this->errors = $accountancy_codes->errors;
714 $this->db->rollback();
730 $langs->load(
'assets');
731 $this->depreciation_lines = array();
734 $this->
id = $this->
id > 0 ? $this->id : 0;
738 if (empty($this->
id)) {
739 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
761 $sql =
"SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
762 $sql .=
", " . $this->db->ifsql(
'iab.fk_docdet IS NOT NULL',
'1',
'0') .
" AS bookkeeping";
763 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
764 $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";
765 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
766 $sql .=
" ORDER BY ad.depreciation_date ASC";
768 $resql = $this->db->query($sql);
770 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
774 while ($obj = $this->db->fetch_object($resql)) {
775 if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
776 $this->depreciation_lines[$obj->depreciation_mode] = array();
778 $this->depreciation_lines[$obj->depreciation_mode][] = array(
781 'depreciation_date' => $this->db->jdate($obj->depreciation_date),
782 'depreciation_ht' => $obj->depreciation_ht,
783 'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
784 'bookkeeping' => $obj->bookkeeping,
799 $langs->load(
'assets');
802 $this->
id = $this->
id > 0 ? $this->id : 0;
806 if (empty($this->
id)) {
807 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
828 $sql =
"SELECT COUNT(*) AS has_bookkeeping";
829 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
830 $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";
831 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
832 $sql .=
" AND iab.fk_docdet IS NOT NULL";
834 $resql = $this->db->query($sql);
836 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
840 if ($obj = $this->db->fetch_object($resql)) {
841 return $obj->has_bookkeeping > 0 ? 1 : 0;
859 public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
862 $langs->load(
'assets');
865 $this->
id = $this->
id > 0 ? $this->id : 0;
866 $mode = strtolower(trim($mode));
868 $accountancy_code_debit = trim($accountancy_code_debit);
869 $accountancy_code_credit = trim($accountancy_code_credit);
873 if (empty($this->
id)) {
874 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
881 $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)";
882 $sql .=
" VALUES ( ";
883 $sql .=
" " . (int) $this->
id;
884 $sql .=
", '" . $this->db->escape($mode) .
"'";
885 $sql .=
", '" . $this->db->escape($ref) .
"'";
886 $sql .=
", '" . $this->db->idate($depreciation_date) .
"'";
887 $sql .=
", " . (float) $depreciation_ht;
888 $sql .=
", " . (float) $cumulative_depreciation_ht;
889 $sql .=
", '" . $this->db->escape($accountancy_code_debit) .
"'";
890 $sql .=
", '" . $this->db->escape($accountancy_code_credit) .
"'";
893 $resql = $this->db->query($sql);
895 $this->errors[] = $langs->trans(
'AssetErrorAddDepreciationLine') .
': ' . $this->db->lasterror();
909 global
$conf, $langs;
910 $langs->load(
'assets');
913 $this->
id = $this->
id > 0 ? $this->id : 0;
917 if (empty($this->
id)) {
918 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
925 if (! empty($this->not_depreciated)) {
931 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
933 $result = $options->fetchDeprecationOptions($this->
id);
935 $this->error = $options->error;
936 $this->errors = $options->errors;
942 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
944 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
946 $this->error = $accountancy_codes->error;
947 $this->errors = $accountancy_codes->errors;
955 foreach ($options->deprecation_options as $mode_key => $fields) {
956 $modes[$mode_key] = $this->db->escape($mode_key);
958 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
959 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
960 $sql .=
" AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode(
"', '", $modes)) .
"')";
962 $resql = $this->db->query($sql);
964 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
970 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
971 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
974 $init_fiscal_period_start = $dates[
'date_start'];
975 $init_fiscal_period_end = $dates[
'date_end'];
976 if (empty($init_fiscal_period_start) || empty($init_fiscal_period_end)) {
977 $pastmonthyear = $dates[
'pastmonthyear'];
978 $pastmonth = $dates[
'pastmonth'];
979 $init_fiscal_period_start =
dol_get_first_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
980 $init_fiscal_period_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
983 foreach ($options->deprecation_options as $mode_key => $fields) {
1004 $sql =
"SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
1005 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
1006 $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";
1007 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
1008 $sql .=
" AND ad.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
1009 $sql .=
" AND iab.fk_docdet IS NOT NULL";
1010 $sql .=
" ORDER BY ad.depreciation_date DESC";
1013 $resql = $this->db->query($sql);
1015 $this->errors[] = $langs->trans(
'AssetErrorFetchMaxDepreciationDateForMode', $mode_key) .
': ' . $this->db->lasterror();
1019 $last_depreciation_date =
'';
1020 $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
1021 if ($obj = $this->db->fetch_object($resql)) {
1022 $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
1023 $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
1027 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1028 $sql .=
" SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
1029 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1030 $resql = $this->db->query($sql);
1032 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1038 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1039 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1040 $sql .=
" AND depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
1041 $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)";
1042 if ($last_depreciation_date !==
"") {
1043 $sql .=
" AND ref <> ''";
1045 $resql = $this->db->query($sql);
1047 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
1053 $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
1054 $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');
1055 $depreciation_amount = $fields[
'amount_base_depreciation_ht'];
1056 if ($fields[
'duration_type'] == 2) {
1057 $fiscal_period_start = $depreciation_date_start;
1058 $fiscal_period_end = $depreciation_date_start;
1059 } elseif ($fields[
'duration_type'] == 1) {
1060 $date_temp =
dol_getdate((
int) $depreciation_date_start);
1061 $fiscal_period_start =
dol_get_first_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1062 $fiscal_period_end =
dol_get_last_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1064 $fiscal_period_start = $init_fiscal_period_start;
1065 $fiscal_period_end = $init_fiscal_period_end;
1067 $cumulative_depreciation_ht = (float) $last_cumulative_depreciation_ht;
1068 $depreciation_period_amount = $depreciation_amount - (float) $this->reversal_amount_ht;
1069 $start_date = $depreciation_date_start;
1070 $disposal_date = isset($this->disposal_date) && $this->disposal_date !==
"" ? $this->disposal_date :
"";
1071 $finish_date = $disposal_date !==
"" ? $disposal_date : $depreciation_date_end;
1072 $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_debit'];
1073 $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key] ??
'';
1074 $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_credit'];
1075 $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key] ??
'';
1079 if ($last_depreciation_date ===
"" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
1080 if (is_numeric($this->reversal_date)) {
1081 if ($this->reversal_date < $fiscal_period_start) {
1082 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
1087 if (empty($this->reversal_amount_ht)) {
1088 $this->errors[] = $langs->trans(
'AssetErrorReversalAmountNotProvidedForMode', $mode_key);
1093 $start_date = $this->reversal_date;
1094 $result = $this->
addDepreciationLine($mode_key,
'', $start_date, (
float) $this->reversal_amount_ht, (
float) $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1100 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotProvidedForMode', $mode_key);
1108 $nb_days_in_year =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_YEAR', 360);
1109 $nb_days_in_month =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_MONTH', 30);
1110 $period_amount = (float) ($fields[
'duration'] > 0 ?
price2num($depreciation_period_amount / $fields[
'duration'],
'MT') : 0);
1111 $first_period_found =
false;
1113 $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
1115 $ref_date_format =
"%Y" . ($fields[
'duration_type'] == 1 || $fields[
'duration_type'] == 2 ?
'-%m' :
'') . ($fields[
'duration_type'] == 2 ?
'-%d' :
'');
1119 $max_loop = $fields[
'duration'] + 2;
1123 if ($idx_loop > $max_loop) {
1127 if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1129 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1133 $first_period_found =
true;
1135 $period_begin =
dol_print_date($fiscal_period_start, $ref_date_format);
1136 $period_end =
dol_print_date($fiscal_period_end, $ref_date_format);
1137 $ref = $period_begin . ($period_begin != $period_end ?
' - ' . $period_end :
'');
1138 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1139 $ref .=
' - ' . $langs->transnoentitiesnoconv(
'AssetDisposal');
1142 $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1143 $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1144 if ($fields[
'duration_type'] == 2) {
1145 $depreciation_ht = $period_amount;
1146 } elseif ($fields[
'duration_type'] == 1) {
1147 $nb_days = min($nb_days_in_month,
num_between_day($begin_date, $end_date, 1));
1148 if ($nb_days >= 28) {
1150 if ($date_temp[
'mon'] == 2) {
1154 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_month,
'MT');
1157 if (($nb_days_real > 366) || (
num_between_day($fiscal_period_start, $fiscal_period_end, 1) < $nb_days_in_year)) {
1158 $nb_days = $nb_days_real;
1160 $nb_days = min($nb_days_in_year, $nb_days_real);
1162 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_year,
'MT');
1165 if ($idx_loop < $max_loop) {
1166 $depreciation_ht = ceil($depreciation_ht);
1170 if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) {
1171 $depreciation_ht = (float)
price2num($depreciation_amount - (
float) $cumulative_depreciation_ht,
'MT');
1172 $cumulative_depreciation_ht = $depreciation_amount;
1174 $cumulative_depreciation_ht += $depreciation_ht;
1177 $result = $this->
addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, (
float) $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1187 if ($fields[
'duration_type'] == 0) {
1191 if ($next_fy !==
null) {
1193 $fiscal_period_start = $next_fy[
'date_start'];
1194 $fiscal_period_end = $next_fy[
'date_end'];
1198 $current_fy_start_parts =
dol_getdate($fiscal_period_start);
1206 } elseif ($fields[
'duration_type'] == 1) {
1209 $fiscal_period_end = $fiscal_period_start;
1211 $last_period_date = $disposal_date !==
"" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1212 }
while ($fiscal_period_start < $last_period_date);
1221 $this->db->rollback();
1224 $this->db->commit();
1238 $langs->load(
'assets');
1241 $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1245 if (empty($asset_depreciation_id)) {
1246 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetDepreciation") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
1255 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
1260 $sql =
"SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1261 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1262 $sql .=
" WHERE rowid = " . (int) $asset_depreciation_id;
1263 $resql = $this->db->query($sql);
1265 $this->errors[] = $langs->trans(
'AssetErrorFetchCumulativeDepreciation') .
': ' . $this->db->lasterror();
1268 if ($obj = $this->db->fetch_object($resql)) {
1269 $mode_key = $obj->depreciation_mode;
1270 if (!empty($options->deprecation_options_fields[$mode_key])) {
1271 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1272 $sql .=
" SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1273 $sql .=
" WHERE fk_asset = " . (int) $obj->fk_asset;
1274 $resql = $this->db->query($sql);
1276 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1284 $this->db->rollback();
1287 $this->db->commit();
1300 public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1302 global
$conf, $langs;
1305 if ($this->
status == self::STATUS_DISPOSED) {
1311 $required_fields = array(
'disposal_date',
'disposal_date',
'fk_disposal_type');
1312 foreach ($required_fields as $field) {
1313 $this->fields[$field][
'notnull'] = 1;
1315 $result = $this->
update($user, 1);
1316 foreach ($required_fields as $field) {
1317 $this->fields[$field][
'notnull'] = 0;
1320 if ($disposal_invoice_id > 0) {
1323 $result = $this->
setStatusCommon($user, self::STATUS_DISPOSED, $notrigger,
'ASSET_DISPOSED');
1330 $this->db->rollback();
1332 $this->db->commit();
1337 if (method_exists($this,
'generateDocument')) {
1338 global $hidedetails, $hidedesc, $hideref;
1339 $outputlangs = $langs;
1342 $newlang =
GETPOST(
'lang_id',
'aZ09');
1345 $newlang = $this->thirdparty->default_lang;
1347 if (!empty($newlang)) {
1349 $outputlangs->setDefaultLang($newlang);
1351 $model = $this->model_pdf;
1352 $ret = $this->
fetch($this->
id);
1354 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1368 public function reopen($user, $notrigger = 0)
1370 global
$conf, $langs;
1373 if ($this->
status != self::STATUS_DISPOSED) {
1380 $this->disposal_date =
null;
1381 $this->disposal_amount_ht =
null;
1382 $this->fk_disposal_type =
null;
1383 $this->disposal_depreciated = 0;
1384 $this->disposal_subject_to_vat = 0;
1385 $result = $this->
update($user, 1);
1388 $result = $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'ASSET_REOPEN');
1395 $this->db->rollback();
1397 $this->db->commit();
1402 if (method_exists($this,
'generateDocument')) {
1403 global $hidedetails, $hidedesc, $hideref;
1404 $outputlangs = $langs;
1407 $newlang =
GETPOST(
'lang_id',
'aZ09');
1410 $newlang = $this->thirdparty->default_lang;
1412 if (!empty($newlang)) {
1414 $outputlangs->setDefaultLang($newlang);
1416 $model = $this->model_pdf;
1417 $ret = $this->
fetch($this->
id);
1419 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1437 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1439 global $db,
$conf, $langs, $hookmanager;
1441 global $menumanager;
1443 if (!empty(
$conf->dol_no_mouse_hover)) {
1449 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Asset").
'</u>';
1450 if (isset($this->
status)) {
1451 $label .=
' '.$this->getLibStatut(5);
1454 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1456 $url =
dol_buildpath(
'/asset/card.php', 1).
'?id='.$this->id;
1458 if ($option !=
'nolink') {
1460 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1461 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1462 $add_save_lastsearch_values = 1;
1464 if ($add_save_lastsearch_values) {
1465 $url .=
'&save_lastsearch_values=1';
1470 if (empty($notooltip)) {
1472 $label = $langs->trans(
"ShowAsset");
1473 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1475 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1476 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1478 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1481 if ($option ==
'nolink') {
1482 $linkstart =
'<span';
1484 $linkstart =
'<a href="'.$url.
'"';
1486 $linkstart .= $linkclose.
'>';
1487 if ($option ==
'nolink') {
1488 $linkend =
'</span>';
1493 $result .= $linkstart;
1495 if (empty($this->showphoto_on_popup)) {
1497 $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);
1501 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1503 list($class, $module) = explode(
'@', $this->picto);
1506 $filename = $filearray[0][
'name'];
1507 if (!empty($filename)) {
1508 $pospoint = strpos($filearray[0][
'name'],
'.');
1510 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
1511 if (!
getDolGlobalString(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
1512 $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>';
1514 $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>';
1517 $result .=
'</div>';
1519 $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);
1524 if ($withpicto != 2) {
1526 if ($option ==
'label') {
1527 $name = $this->label;
1528 } elseif ($option ==
'with_label') {
1529 $name .=
' - ' . $this->label;
1534 $result .= $linkend;
1538 $hookmanager->initHooks(array($this->element .
'dao'));
1539 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1540 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1542 $result = $hookmanager->resPrint;
1544 $result .= $hookmanager->resPrint;
1582 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1585 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1586 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1587 $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1588 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1589 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1590 $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1593 $statusType =
'status'.$status;
1594 if ($status == self::STATUS_VALIDATED) {
1595 $statusType =
'status4';
1597 if ($status == self::STATUS_DISPOSED) {
1598 $statusType =
'status6';
1601 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1612 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_valid as datev,";
1613 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
1614 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
1615 $sql .=
" WHERE t.rowid = ".((int) $id);
1617 $result = $this->db->query($sql);
1619 if ($this->db->num_rows($result)) {
1620 $obj = $this->db->fetch_object($result);
1621 $this->
id = $obj->rowid;
1623 $this->user_creation_id = $obj->fk_user_creat;
1624 $this->user_modification_id = $obj->fk_user_modif;
1625 $this->user_validation_id = $obj->fk_user_valid;
1626 $this->date_creation = $this->db->jdate($obj->datec);
1627 $this->date_modification = $this->db->jdate($obj->datem);
1628 $this->date_validation = $this->db->jdate($obj->datev);
1631 $this->db->free($result);
1659 global $langs,
$conf;
1660 $langs->load(
"assets");
1663 $conf->global->ASSET_ASSET_ADDON =
'mod_asset_standard';
1673 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1674 foreach ($dirmodels as $reldir) {
1678 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1686 if (class_exists($classname)) {
1687 $obj =
new $classname();
1689 '@phan-var-force ModeleNumRefAsset $obj';
1691 $numref = $obj->getNextValue($this);
1693 if ($numref !=
'' && $numref !=
'-1') {
1696 $this->error = $obj->error;
1701 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1705 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1721 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1726 if ($this->
status == self::STATUS_VALIDATED) {
1727 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
1736 if ( (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1744 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1745 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1746 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1747 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1748 $sql .=
" fk_user_valid = ".((int) $user->id);
1749 $sql .=
" WHERE rowid = ".((int) $this->
id);
1751 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1752 $resql = $this->db->query($sql);
1755 $this->error = $this->db->lasterror();
1759 if (!$error && !$notrigger) {
1761 $result = $this->
call_trigger(
'ASSET_VALIDATE', $user);
1769 $this->oldref = $this->ref;
1772 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1774 $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).
"'";
1775 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1776 $resql = $this->db->query($sql);
1779 $this->error = $this->db->lasterror();
1781 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'asset/".$this->db->escape($this->newref).
"'";
1782 $sql .=
" WHERE filepath = 'asset/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1783 $resql = $this->db->query($sql);
1786 $this->error = $this->db->lasterror();
1792 $dirsource =
$conf->asset->dir_output.
'/'.$oldref;
1793 $dirdest =
$conf->asset->dir_output.
'/'.$newref;
1794 if (!$error && file_exists($dirsource)) {
1795 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1797 if (@rename($dirsource, $dirdest)) {
1800 $listoffiles =
dol_dir_list(
$conf->asset->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1801 foreach ($listoffiles as $fileentry) {
1802 $dirsource = $fileentry[
'name'];
1803 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1804 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1805 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1806 @rename($dirsource, $dirdest);
1816 $this->
status = self::STATUS_VALIDATED;
1820 $this->db->commit();
1823 $this->db->rollback();
1838 if ($this->
status <= self::STATUS_DRAFT) {
1842 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.
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.
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=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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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_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($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.
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)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
global $dolibarr_main_demo