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) {
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)
576 $this->db->rollback();
591 public function delete(
User $user, $notrigger = 0)
593 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_economic WHERE fk_asset = '.((int) $this->
id);
594 $this->db->query($sql);
596 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_codes_fiscal WHERE fk_asset = '.((int) $this->
id);
597 $this->db->query($sql);
599 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_fiscal WHERE fk_asset = '.((int) $this->
id);
600 $this->db->query($sql);
602 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation_options_economic WHERE fk_asset = '.((int) $this->
id);
603 $this->db->query($sql);
605 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'asset_depreciation WHERE fk_asset = '.((int) $this->
id);
606 $this->db->query($sql);
622 $langs->load(
'assets');
625 $this->
id = $this->
id > 0 ? $this->id : 0;
626 $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
630 if (empty($this->
id)) {
631 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
634 if (empty($this->fk_asset_model)) {
635 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetModel") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
646 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
648 $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
650 $this->error = $options_model->error;
651 $this->errors = $options_model->errors;
653 } elseif ($result > 0) {
655 $result = $options->fetchDeprecationOptions($this->
id);
657 $this->error = $options->error;
658 $this->errors = $options->errors;
663 foreach ($options_model->deprecation_options as $mode_key => $fields) {
664 foreach ($fields as $field_key => $value) {
665 $options->deprecation_options[$mode_key][$field_key] = $value;
669 $result = $options->updateDeprecationOptions($user, $this->
id, 0, $notrigger);
671 $this->error = $options->error;
672 $this->errors = $options->errors;
681 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
683 $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
685 $this->error = $accountancy_codes_model->error;
686 $this->errors = $accountancy_codes_model->errors;
688 } elseif ($result > 0) {
690 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
692 $this->error = $accountancy_codes->error;
693 $this->errors = $accountancy_codes->errors;
698 foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
699 foreach ($fields as $field_key => $value) {
700 $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
704 $result = $accountancy_codes->updateAccountancyCodes($user, $this->
id, 0, $notrigger);
706 $this->error = $accountancy_codes->error;
707 $this->errors = $accountancy_codes->errors;
715 $this->db->rollback();
731 $langs->load(
'assets');
732 $this->depreciation_lines = array();
735 $this->
id = $this->
id > 0 ? $this->id : 0;
739 if (empty($this->
id)) {
740 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
762 $sql =
"SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
763 $sql .=
", " . $this->db->ifsql(
'iab.fk_docdet IS NOT NULL',
'1',
'0') .
" AS bookkeeping";
764 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
765 $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";
766 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
767 $sql .=
" ORDER BY ad.depreciation_date ASC";
769 $resql = $this->db->query($sql);
771 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
775 while ($obj = $this->db->fetch_object($resql)) {
776 if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
777 $this->depreciation_lines[$obj->depreciation_mode] = array();
779 $this->depreciation_lines[$obj->depreciation_mode][] = array(
782 'depreciation_date' => $this->db->jdate($obj->depreciation_date),
783 'depreciation_ht' => $obj->depreciation_ht,
784 'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
785 'bookkeeping' => $obj->bookkeeping,
800 $langs->load(
'assets');
803 $this->
id = $this->
id > 0 ? $this->id : 0;
807 if (empty($this->
id)) {
808 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
829 $sql =
"SELECT COUNT(*) AS has_bookkeeping";
830 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
831 $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";
832 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
833 $sql .=
" AND iab.fk_docdet IS NOT NULL";
835 $resql = $this->db->query($sql);
837 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
841 if ($obj = $this->db->fetch_object($resql)) {
842 return $obj->has_bookkeeping > 0 ? 1 : 0;
860 public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
863 $langs->load(
'assets');
866 $this->
id = $this->
id > 0 ? $this->id : 0;
867 $mode = strtolower(trim($mode));
869 $accountancy_code_debit = trim($accountancy_code_debit);
870 $accountancy_code_credit = trim($accountancy_code_credit);
874 if (empty($this->
id)) {
875 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
882 $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)";
883 $sql .=
" VALUES ( ";
884 $sql .=
" " . (int) $this->
id;
885 $sql .=
", '" . $this->db->escape($mode) .
"'";
886 $sql .=
", '" . $this->db->escape($ref) .
"'";
887 $sql .=
", '" . $this->db->idate($depreciation_date) .
"'";
888 $sql .=
", " . (float) $depreciation_ht;
889 $sql .=
", " . (float) $cumulative_depreciation_ht;
890 $sql .=
", '" . $this->db->escape($accountancy_code_debit) .
"'";
891 $sql .=
", '" . $this->db->escape($accountancy_code_credit) .
"'";
894 $resql = $this->db->query($sql);
896 $this->errors[] = $langs->trans(
'AssetErrorAddDepreciationLine') .
': ' . $this->db->lasterror();
910 global
$conf, $langs;
911 $langs->load(
'assets');
914 $this->
id = $this->
id > 0 ? $this->id : 0;
918 if (empty($this->
id)) {
919 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
926 if (! empty($this->not_depreciated)) {
932 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
934 $result = $options->fetchDeprecationOptions($this->
id);
936 $this->error = $options->error;
937 $this->errors = $options->errors;
943 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
945 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
947 $this->error = $accountancy_codes->error;
948 $this->errors = $accountancy_codes->errors;
956 foreach ($options->deprecation_options as $mode_key => $fields) {
957 $modes[$mode_key] = $this->db->escape($mode_key);
959 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
960 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
961 $sql .=
" AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode(
"', '", $modes)) .
"')";
963 $resql = $this->db->query($sql);
965 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
971 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
972 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
975 $init_fiscal_period_start = $dates[
'date_start'];
976 $init_fiscal_period_end = $dates[
'date_end'];
977 if (empty($init_fiscal_period_start) || empty($init_fiscal_period_end)) {
978 $pastmonthyear = $dates[
'pastmonthyear'];
979 $pastmonth = $dates[
'pastmonth'];
980 $init_fiscal_period_start =
dol_get_first_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
981 $init_fiscal_period_end =
dol_get_last_day((
int) $pastmonthyear, (
int) $pastmonth,
false);
984 foreach ($options->deprecation_options as $mode_key => $fields) {
1005 $sql =
"SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
1006 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
1007 $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";
1008 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
1009 $sql .=
" AND ad.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
1010 $sql .=
" AND iab.fk_docdet IS NOT NULL";
1011 $sql .=
" ORDER BY ad.depreciation_date DESC";
1014 $resql = $this->db->query($sql);
1016 $this->errors[] = $langs->trans(
'AssetErrorFetchMaxDepreciationDateForMode', $mode_key) .
': ' . $this->db->lasterror();
1020 $last_depreciation_date =
'';
1021 $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
1022 if ($obj = $this->db->fetch_object($resql)) {
1023 $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
1024 $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
1028 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1029 $sql .=
" SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
1030 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1031 $resql = $this->db->query($sql);
1033 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1039 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1040 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
1041 $sql .=
" AND depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
1042 $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)";
1043 if ($last_depreciation_date !==
"") {
1044 $sql .=
" AND ref <> ''";
1046 $resql = $this->db->query($sql);
1048 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
1054 $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
1055 $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');
1056 $depreciation_amount = $fields[
'amount_base_depreciation_ht'];
1057 if ($fields[
'duration_type'] == 2) {
1058 $fiscal_period_start = $depreciation_date_start;
1059 $fiscal_period_end = $depreciation_date_start;
1060 } elseif ($fields[
'duration_type'] == 1) {
1061 $date_temp =
dol_getdate((
int) $depreciation_date_start);
1062 $fiscal_period_start =
dol_get_first_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1063 $fiscal_period_end =
dol_get_last_day($date_temp[
'year'], $date_temp[
'mon'],
false);
1065 $fiscal_period_start = $init_fiscal_period_start;
1066 $fiscal_period_end = $init_fiscal_period_end;
1068 $cumulative_depreciation_ht = (float) $last_cumulative_depreciation_ht;
1069 $depreciation_period_amount = $depreciation_amount - (float) $this->reversal_amount_ht;
1070 $start_date = $depreciation_date_start;
1071 $disposal_date = isset($this->disposal_date) && $this->disposal_date !==
"" ? $this->disposal_date :
"";
1072 $finish_date = $disposal_date !==
"" ? $disposal_date : $depreciation_date_end;
1073 $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_debit'];
1074 $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key];
1075 $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_credit'];
1076 $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key];
1080 if ($last_depreciation_date ===
"" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
1081 if (is_numeric($this->reversal_date)) {
1082 if ($this->reversal_date < $fiscal_period_start) {
1083 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
1088 if (empty($this->reversal_amount_ht)) {
1089 $this->errors[] = $langs->trans(
'AssetErrorReversalAmountNotProvidedForMode', $mode_key);
1094 $start_date = $this->reversal_date;
1095 $result = $this->
addDepreciationLine($mode_key,
'', $start_date, (
float) $this->reversal_amount_ht, (
float) $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1101 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotProvidedForMode', $mode_key);
1109 $nb_days_in_year =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_YEAR', 360);
1110 $nb_days_in_month =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_MONTH', 30);
1111 $period_amount = (float) ($fields[
'duration'] > 0 ?
price2num($depreciation_period_amount / $fields[
'duration'],
'MT') : 0);
1112 $first_period_found =
false;
1114 $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
1116 $ref_date_format =
"%Y" . ($fields[
'duration_type'] == 1 || $fields[
'duration_type'] == 2 ?
'-%m' :
'') . ($fields[
'duration_type'] == 2 ?
'-%d' :
'');
1120 $max_loop = $fields[
'duration'] + 2;
1124 if ($idx_loop > $max_loop) {
1128 if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1130 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1134 $first_period_found =
true;
1136 $period_begin =
dol_print_date($fiscal_period_start, $ref_date_format);
1137 $period_end =
dol_print_date($fiscal_period_end, $ref_date_format);
1138 $ref = $period_begin . ($period_begin != $period_end ?
' - ' . $period_end :
'');
1139 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1140 $ref .=
' - ' . $langs->transnoentitiesnoconv(
'AssetDisposal');
1143 $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1144 $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1145 if ($fields[
'duration_type'] == 2) {
1146 $depreciation_ht = $period_amount;
1147 } elseif ($fields[
'duration_type'] == 1) {
1148 $nb_days = min($nb_days_in_month,
num_between_day($begin_date, $end_date, 1));
1149 if ($nb_days >= 28) {
1151 if ($date_temp[
'mon'] == 2) {
1155 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_month,
'MT');
1158 if (($nb_days_real > 366) || (
num_between_day($fiscal_period_start, $fiscal_period_end, 1) < $nb_days_in_year)) {
1159 $nb_days = $nb_days_real;
1161 $nb_days = min($nb_days_in_year, $nb_days_real);
1163 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_year,
'MT');
1166 if ($idx_loop < $max_loop) {
1167 $depreciation_ht = ceil($depreciation_ht);
1171 if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) {
1172 $depreciation_ht = (float)
price2num($depreciation_amount - (
float) $cumulative_depreciation_ht,
'MT');
1173 $cumulative_depreciation_ht = $depreciation_amount;
1175 $cumulative_depreciation_ht += $depreciation_ht;
1178 $result = $this->
addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, (
float) $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1188 if ($fields[
'duration_type'] == 0) {
1192 if ($next_fy !==
null) {
1194 $fiscal_period_start = $next_fy[
'date_start'];
1195 $fiscal_period_end = $next_fy[
'date_end'];
1199 $current_fy_start_parts =
dol_getdate($fiscal_period_start);
1207 } elseif ($fields[
'duration_type'] == 1) {
1210 $fiscal_period_end = $fiscal_period_start;
1212 $last_period_date = $disposal_date !==
"" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1213 }
while ($fiscal_period_start < $last_period_date);
1222 $this->db->rollback();
1225 $this->db->commit();
1239 $langs->load(
'assets');
1242 $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1246 if (empty($asset_depreciation_id)) {
1247 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetDepreciation") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
1256 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
1261 $sql =
"SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1262 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1263 $sql .=
" WHERE rowid = " . (int) $asset_depreciation_id;
1264 $resql = $this->db->query($sql);
1266 $this->errors[] = $langs->trans(
'AssetErrorFetchCumulativeDepreciation') .
': ' . $this->db->lasterror();
1269 if ($obj = $this->db->fetch_object($resql)) {
1270 $mode_key = $obj->depreciation_mode;
1271 if (!empty($options->deprecation_options_fields[$mode_key])) {
1272 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1273 $sql .=
" SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1274 $sql .=
" WHERE fk_asset = " . (int) $obj->fk_asset;
1275 $resql = $this->db->query($sql);
1277 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1285 $this->db->rollback();
1288 $this->db->commit();
1301 public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1303 global
$conf, $langs;
1306 if ($this->
status == self::STATUS_DISPOSED) {
1312 $required_fields = array(
'disposal_date',
'disposal_date',
'fk_disposal_type');
1313 foreach ($required_fields as $field) {
1314 $this->fields[$field][
'notnull'] = 1;
1316 $result = $this->
update($user, 1);
1317 foreach ($required_fields as $field) {
1318 $this->fields[$field][
'notnull'] = 0;
1321 if ($disposal_invoice_id > 0) {
1324 $result = $this->
setStatusCommon($user, self::STATUS_DISPOSED, $notrigger,
'ASSET_DISPOSED');
1331 $this->db->rollback();
1333 $this->db->commit();
1338 if (method_exists($this,
'generateDocument')) {
1339 global $hidedetails, $hidedesc, $hideref;
1340 $outputlangs = $langs;
1343 $newlang =
GETPOST(
'lang_id',
'aZ09');
1346 $newlang = $this->thirdparty->default_lang;
1348 if (!empty($newlang)) {
1350 $outputlangs->setDefaultLang($newlang);
1352 $model = $this->model_pdf;
1353 $ret = $this->
fetch($this->
id);
1355 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1369 public function reopen($user, $notrigger = 0)
1371 global
$conf, $langs;
1374 if ($this->
status != self::STATUS_DISPOSED) {
1381 $this->disposal_date =
null;
1382 $this->disposal_amount_ht =
null;
1383 $this->fk_disposal_type =
null;
1384 $this->disposal_depreciated = 0;
1385 $this->disposal_subject_to_vat = 0;
1386 $result = $this->
update($user, 1);
1389 $result = $this->
setStatusCommon($user, self::STATUS_VALIDATED, $notrigger,
'ASSET_REOPEN');
1396 $this->db->rollback();
1398 $this->db->commit();
1403 if (method_exists($this,
'generateDocument')) {
1404 global $hidedetails, $hidedesc, $hideref;
1405 $outputlangs = $langs;
1408 $newlang =
GETPOST(
'lang_id',
'aZ09');
1411 $newlang = $this->thirdparty->default_lang;
1413 if (!empty($newlang)) {
1415 $outputlangs->setDefaultLang($newlang);
1417 $model = $this->model_pdf;
1418 $ret = $this->
fetch($this->
id);
1420 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1438 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1440 global $db,
$conf, $langs, $hookmanager;
1442 global $menumanager;
1444 if (!empty(
$conf->dol_no_mouse_hover)) {
1450 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Asset").
'</u>';
1451 if (isset($this->
status)) {
1452 $label .=
' '.$this->getLibStatut(5);
1455 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1457 $url =
dol_buildpath(
'/asset/card.php', 1).
'?id='.$this->id;
1459 if ($option !=
'nolink') {
1461 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1462 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1463 $add_save_lastsearch_values = 1;
1465 if ($add_save_lastsearch_values) {
1466 $url .=
'&save_lastsearch_values=1';
1471 if (empty($notooltip)) {
1473 $label = $langs->trans(
"ShowAsset");
1474 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1476 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
1477 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1479 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1482 if ($option ==
'nolink') {
1483 $linkstart =
'<span';
1485 $linkstart =
'<a href="'.$url.
'"';
1487 $linkstart .= $linkclose.
'>';
1488 if ($option ==
'nolink') {
1489 $linkend =
'</span>';
1494 $result .= $linkstart;
1496 if (empty($this->showphoto_on_popup)) {
1498 $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);
1502 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1504 list($class, $module) = explode(
'@', $this->picto);
1507 $filename = $filearray[0][
'name'];
1508 if (!empty($filename)) {
1509 $pospoint = strpos($filearray[0][
'name'],
'.');
1511 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
1512 if (!
getDolGlobalString(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
1513 $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>';
1515 $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>';
1518 $result .=
'</div>';
1520 $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);
1525 if ($withpicto != 2) {
1527 if ($option ==
'label') {
1528 $name = $this->label;
1529 } elseif ($option ==
'with_label') {
1530 $name .=
' - ' . $this->label;
1535 $result .= $linkend;
1539 $hookmanager->initHooks(array($this->element .
'dao'));
1540 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1541 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1543 $result = $hookmanager->resPrint;
1545 $result .= $hookmanager->resPrint;
1583 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1586 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1587 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1588 $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1589 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInDraft');
1590 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1591 $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1594 $statusType =
'status'.$status;
1595 if ($status == self::STATUS_VALIDATED) {
1596 $statusType =
'status4';
1598 if ($status == self::STATUS_DISPOSED) {
1599 $statusType =
'status6';
1602 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1613 $sql =
"SELECT rowid, date_creation as datec, tms as datem, date_valid as datev,";
1614 $sql .=
" fk_user_creat, fk_user_modif, fk_user_valid";
1615 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
1616 $sql .=
" WHERE t.rowid = ".((int) $id);
1618 $result = $this->db->query($sql);
1620 if ($this->db->num_rows($result)) {
1621 $obj = $this->db->fetch_object($result);
1622 $this->
id = $obj->rowid;
1624 $this->user_creation_id = $obj->fk_user_creat;
1625 $this->user_modification_id = $obj->fk_user_modif;
1626 $this->user_validation_id = $obj->fk_user_valid;
1627 $this->date_creation = $this->db->jdate($obj->datec);
1628 $this->date_modification = $this->db->jdate($obj->datem);
1629 $this->date_validation = $this->db->jdate($obj->datev);
1632 $this->db->free($result);
1660 global $langs,
$conf;
1661 $langs->load(
"assets");
1664 $conf->global->ASSET_ASSET_ADDON =
'mod_asset_standard';
1674 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1675 foreach ($dirmodels as $reldir) {
1679 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1687 if (class_exists($classname)) {
1688 $obj =
new $classname();
1690 '@phan-var-force ModeleNumRefAsset $obj';
1692 $numref = $obj->getNextValue($this);
1694 if ($numref !=
'' && $numref !=
'-1') {
1697 $this->error = $obj->error;
1702 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1706 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
1722 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1727 if ($this->
status == self::STATUS_VALIDATED) {
1728 dol_syslog(get_class($this).
"::validate action abandoned: already validated", LOG_WARNING);
1737 if ( (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1745 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1746 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1747 $sql .=
" status = ".self::STATUS_VALIDATED.
",";
1748 $sql .=
" date_valid='".$this->db->idate($now).
"',";
1749 $sql .=
" fk_user_valid = ".((int) $user->id);
1750 $sql .=
" WHERE rowid = ".((int) $this->
id);
1752 dol_syslog(get_class($this).
"::validate()", LOG_DEBUG);
1753 $resql = $this->db->query($sql);
1756 $this->error = $this->db->lasterror();
1760 if (!$error && !$notrigger) {
1762 $result = $this->
call_trigger(
'ASSET_VALIDATE', $user);
1770 $this->oldref = $this->ref;
1773 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1775 $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).
"'";
1776 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'bom/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1777 $resql = $this->db->query($sql);
1780 $this->error = $this->db->lasterror();
1782 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'asset/".$this->db->escape($this->newref).
"'";
1783 $sql .=
" WHERE filepath = 'asset/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1784 $resql = $this->db->query($sql);
1787 $this->error = $this->db->lasterror();
1793 $dirsource =
$conf->asset->dir_output.
'/'.$oldref;
1794 $dirdest =
$conf->asset->dir_output.
'/'.$newref;
1795 if (!$error && file_exists($dirsource)) {
1796 dol_syslog(get_class($this).
"::validate() rename dir ".$dirsource.
" into ".$dirdest);
1798 if (@rename($dirsource, $dirdest)) {
1801 $listoffiles =
dol_dir_list(
$conf->asset->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1802 foreach ($listoffiles as $fileentry) {
1803 $dirsource = $fileentry[
'name'];
1804 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1805 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1806 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1807 @rename($dirsource, $dirdest);
1817 $this->
status = self::STATUS_VALIDATED;
1821 $this->db->commit();
1824 $this->db->rollback();
1839 if ($this->
status <= self::STATUS_DRAFT) {
1843 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