27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $module =
'asset';
42 public $element =
'asset';
47 public $table_element =
'asset';
52 public $picto =
'asset';
54 const STATUS_DRAFT = 0;
55 const STATUS_DISPOSED = 9;
88 public $fields = array(
89 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'visible' => 0,
'noteditable' => 1,
'index' => 1,
'css' =>
'left',
'comment' =>
"Id"),
90 'ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 20,
'notnull' => 1,
'visible' => 1,
'noteditable' => 0,
'index' => 1,
'searchall' => 1,
'showoncombobox' => 1,
'validate' => 1,
'comment' =>
"Reference of object"),
91 'label' => array(
'type' =>
'varchar(255)',
'label' =>
'Label',
'enabled' => 1,
'position' => 30,
'notnull' => 1,
'visible' => 1,
'searchall' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'showoncombobox' =>
'2',
'validate' => 1,),
92 '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,),
93 'qty' => array(
'type' =>
'real',
'label' =>
'Qty',
'enabled' => 1,
'position' => 50,
'notnull' => 1,
'visible' => 0,
'default' =>
'1',
'isameasure' => 1,
'css' =>
'maxwidth75imp',
'validate' => 1,),
94 'acquisition_type' => array(
'type' =>
'smallint',
'label' =>
'AssetAcquisitionType',
'enabled' => 1,
'position' => 60,
'notnull' => 1,
'visible' => 1,
'arrayofkeyval' => array(
'0' =>
'AssetAcquisitionTypeNew',
'1' =>
'AssetAcquisitionTypeOccasion'),
'validate' => 1,),
95 '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,),
96 'not_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetNotDepreciated',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'default' =>
'0',
'visible' => 1,
'validate' => 1,),
97 'date_acquisition' => array(
'type' =>
'date',
'label' =>
'AssetDateAcquisition',
'enabled' => 1,
'position' => 90,
'notnull' => 1,
'visible' => 1,),
98 'date_start' => array(
'type' =>
'date',
'label' =>
'AssetDateStart',
'enabled' => 1,
'position' => 100,
'notnull' => 0,
'visible' => -1,),
99 'acquisition_value_ht' => array(
'type' =>
'price',
'label' =>
'AssetAcquisitionValueHT',
'enabled' => 1,
'position' => 110,
'notnull' => 1,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
100 'recovered_vat' => array(
'type' =>
'price',
'label' =>
'AssetRecoveredVAT',
'enabled' => 1,
'position' => 120,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
101 'reversal_date' => array(
'type' =>
'date',
'label' =>
'AssetReversalDate',
'enabled' => 1,
'position' => 130,
'notnull' => 0,
'visible' => 1,),
102 'reversal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetReversalAmountHT',
'enabled' => 1,
'position' => 140,
'notnull' => 0,
'visible' => 1,
'isameasure' => 1,
'validate' => 1,),
103 'disposal_date' => array(
'type' =>
'date',
'label' =>
'AssetDisposalDate',
'enabled' => 1,
'position' => 200,
'notnull' => 0,
'visible' => -2,),
104 'disposal_amount_ht' => array(
'type' =>
'price',
'label' =>
'AssetDisposalAmount',
'enabled' => 1,
'position' => 210,
'notnull' => 0,
'visible' => -2,
'default' =>
'0',
'isameasure' => 1,
'validate' => 1,),
105 '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,),
106 'disposal_depreciated' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalDepreciated',
'enabled' => 1,
'position' => 230,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
107 'disposal_subject_to_vat' => array(
'type' =>
'boolean',
'label' =>
'AssetDisposalSubjectToVat',
'enabled' => 1,
'position' => 240,
'notnull' => 0,
'default' =>
'0',
'visible' => -2,
'validate' => 1,),
108 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'position' => 300,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
109 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'position' => 301,
'notnull' => 0,
'visible' => 0,
'validate' => 1,),
110 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'visible' => -2,),
111 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 501,
'notnull' => 0,
'visible' => -2,),
112 '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',),
113 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'position' => 511,
'notnull' => -1,
'visible' => -2,),
114 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'position' => 600,
'notnull' => 0,
'visible' => 0,),
115 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 1000,
'notnull' => -1,
'visible' => -2,),
116 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'position' => 1010,
'notnull' => -1,
'visible' => 0,),
117 '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,),
122 public $fk_asset_model;
123 public $reversal_amount_ht;
124 public $acquisition_value_ht;
125 public $recovered_vat;
126 public $reversal_date;
127 public $date_acquisition;
130 public $acquisition_type;
132 public $not_depreciated;
133 public $disposal_date;
134 public $disposal_amount_ht;
135 public $fk_disposal_type;
136 public $disposal_depreciated;
137 public $disposal_subject_to_vat;
138 public $supplier_invoice_id;
140 public $note_private;
141 public $fk_user_creat;
142 public $fk_user_modif;
143 public $last_main_doc;
157 public $asset_depreciation_options;
158 public $asset_accountancy_codes;
162 public $depreciation_lines = array();
171 global $conf, $langs;
175 $this->ismultientitymanaged = 1;
176 $this->isextrafieldmanaged = 1;
179 $this->fields[
'rowid'][
'visible'] = 0;
181 if (!isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
182 $this->fields[
'entity'][
'enabled'] = 0;
186 foreach ($this->fields as $key => $val) {
187 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
188 unset($this->fields[$key]);
193 if (is_object($langs)) {
194 foreach ($this->fields as $key => $val) {
195 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
196 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
197 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
213 if (!isset($this->date_start) || $this->date_start ===
"") {
214 $this->date_start = $this->date_acquisition;
219 $result = $result_create = $this->
createCommon($user, $notrigger);
220 if ($result > 0 && $this->fk_asset_model > 0) {
224 if ($this->supplier_invoice_id > 0) {
230 $this->db->rollback();
235 return $result > 0 ? $result_create : $result;
247 global $langs, $extrafields;
345 public function fetch($id, $ref =
null)
349 if (!empty($this->table_element_line)) {
356 } elseif ($res > 0) {
357 $this->fields[
'date_acquisition'][
'noteditable'] =
'1';
358 $this->fields[
'date_start'][
'noteditable'] =
'1';
359 $this->fields[
'acquisition_value_ht'][
'noteditable'] =
'1';
360 $this->fields[
'recovered_vat'][
'noteditable'] =
'1';
361 $this->fields[
'reversal_date'][
'noteditable'] =
'1';
362 $this->fields[
'reversal_amount_ht'][
'noteditable'] =
'1';
375 $this->lines = array();
393 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND')
401 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
402 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
403 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
405 $sql .=
" WHERE 1 = 1";
412 $this->errors[] = $errormessage;
413 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
418 if (!empty($sortfield)) {
419 $sql .= $this->db->order($sortfield, $sortorder);
421 if (!empty($limit)) {
422 $sql .= $this->db->plimit($limit, $offset);
425 $resql = $this->db->query($sql);
427 $num = $this->db->num_rows($resql);
429 while ($i < ($limit ? min($limit, $num) : $num)) {
430 $obj = $this->db->fetch_object($resql);
432 $record =
new self($this->db);
433 $record->setVarsFromFetchObj($obj);
435 $records[$record->id] = $record;
439 $this->db->free($resql);
443 $this->errors[] =
'Error '.$this->db->lasterror();
444 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
459 if (!isset($this->date_start) || $this->date_start ===
"") {
460 $this->date_start = $this->date_acquisition;
466 if ($result > 0 && $this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model) {
470 $this->date_start != $this->oldcopy->date_start ||
471 $this->acquisition_value_ht != $this->oldcopy->acquisition_value_ht ||
472 $this->reversal_date != $this->oldcopy->reversal_date ||
473 $this->reversal_amount_ht != $this->oldcopy->reversal_amount_ht ||
474 ($this->fk_asset_model > 0 && $this->fk_asset_model != $this->oldcopy->fk_asset_model)
481 $this->db->rollback();
496 public function delete(
User $user, $notrigger = 0)
512 $langs->load(
'assets');
515 $this->
id = $this->
id > 0 ? $this->id : 0;
516 $this->fk_asset_model = $this->fk_asset_model > 0 ? $this->fk_asset_model : 0;
520 if (empty($this->
id)) {
521 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
524 if (empty($this->fk_asset_model)) {
525 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetModel") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
536 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
538 $result = $options_model->fetchDeprecationOptions(0, $this->fk_asset_model);
540 $this->error = $options_model->error;
541 $this->errors = $options_model->errors;
543 } elseif ($result > 0) {
545 $result = $options->fetchDeprecationOptions($this->
id);
547 $this->error = $options->error;
548 $this->errors = $options->errors;
553 foreach ($options_model->deprecation_options as $mode_key => $fields) {
554 foreach ($fields as $field_key => $value) {
555 $options->deprecation_options[$mode_key][$field_key] = $value;
559 $result = $options->updateDeprecationOptions($user, $this->
id, 0, $notrigger);
561 $this->error = $options->error;
562 $this->errors = $options->errors;
571 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
573 $result = $accountancy_codes_model->fetchAccountancyCodes(0, $this->fk_asset_model);
575 $this->error = $accountancy_codes_model->error;
576 $this->errors = $accountancy_codes_model->errors;
578 } elseif ($result > 0) {
580 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
582 $this->error = $accountancy_codes->error;
583 $this->errors = $accountancy_codes->errors;
588 foreach ($accountancy_codes_model->accountancy_codes as $mode_key => $fields) {
589 foreach ($fields as $field_key => $value) {
590 $accountancy_codes->accountancy_codes[$mode_key][$field_key] = $value;
594 $result = $accountancy_codes->updateAccountancyCodes($user, $this->
id, 0, $notrigger);
596 $this->error = $accountancy_codes->error;
597 $this->errors = $accountancy_codes->errors;
605 $this->db->rollback();
621 $langs->load(
'assets');
622 $this->depreciation_lines = array();
625 $this->
id = $this->
id > 0 ? $this->id : 0;
629 if (empty($this->
id)) {
630 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
652 $sql =
"SELECT ad.rowid, ad.depreciation_mode, ad.ref, ad.depreciation_date, ad.depreciation_ht, ad.cumulative_depreciation_ht";
653 $sql .=
", " . $this->db->ifsql(
'iab.fk_docdet IS NOT NULL', 1, 0) .
" AS bookkeeping";
654 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
655 $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";
656 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
657 $sql .=
" ORDER BY ad.depreciation_date ASC";
659 $resql = $this->db->query($sql);
661 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
665 while ($obj = $this->db->fetch_object($resql)) {
666 if (!isset($this->depreciation_lines[$obj->depreciation_mode])) {
667 $this->depreciation_lines[$obj->depreciation_mode] = array();
669 $this->depreciation_lines[$obj->depreciation_mode][] = array(
672 'depreciation_date' => $this->db->jdate($obj->depreciation_date),
673 'depreciation_ht' => $obj->depreciation_ht,
674 'cumulative_depreciation_ht' => $obj->cumulative_depreciation_ht,
675 'bookkeeping' => $obj->bookkeeping,
690 $langs->load(
'assets');
693 $this->
id = $this->
id > 0 ? $this->id : 0;
697 if (empty($this->
id)) {
698 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
719 $sql =
"SELECT COUNT(*) AS has_bookkeeping";
720 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
721 $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";
722 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
723 $sql .=
" AND iab.fk_docdet IS NOT NULL";
725 $resql = $this->db->query($sql);
727 $this->errors[] = $langs->trans(
'AssetErrorFetchDepreciationLines') .
': ' . $this->db->lasterror();
731 if ($obj = $this->db->fetch_object($resql)) {
732 return $obj->has_bookkeeping > 0 ? 1 : 0;
750 public function addDepreciationLine($mode, $ref, $depreciation_date, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_debit, $accountancy_code_credit)
753 $langs->load(
'assets');
756 $this->
id = $this->
id > 0 ? $this->id : 0;
757 $mode = strtolower(trim($mode));
759 $accountancy_code_debit = trim($accountancy_code_debit);
760 $accountancy_code_credit = trim($accountancy_code_credit);
764 if (empty($this->
id)) {
765 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
772 $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)";
773 $sql .=
" VALUES ( ";
774 $sql .=
" " . (int) $this->
id;
775 $sql .=
", '" . $this->db->escape($mode) .
"'";
776 $sql .=
", '" . $this->db->escape($ref) .
"'";
777 $sql .=
", '" . $this->db->idate($depreciation_date) .
"'";
778 $sql .=
", " . (float) $depreciation_ht;
779 $sql .=
", " . (float) $cumulative_depreciation_ht;
780 $sql .=
", '" . $this->db->escape($accountancy_code_debit) .
"'";
781 $sql .=
", '" . $this->db->escape($accountancy_code_credit) .
"'";
784 $resql = $this->db->query($sql);
786 $this->errors[] = $langs->trans(
'AssetErrorAddDepreciationLine') .
': ' . $this->db->lasterror();
800 global $conf, $langs;
801 $langs->load(
'assets');
804 $this->
id = $this->
id > 0 ? $this->id : 0;
808 if (empty($this->
id)) {
809 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Asset") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
818 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
820 $result = $options->fetchDeprecationOptions($this->
id);
822 $this->error = $options->error;
823 $this->errors = $options->errors;
829 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetaccountancycodes.class.php';
831 $result = $accountancy_codes->fetchAccountancyCodes($this->
id);
833 $this->error = $accountancy_codes->error;
834 $this->errors = $accountancy_codes->errors;
842 foreach ($options->deprecation_options as $mode_key => $fields) {
843 $modes[$mode_key] = $this->db->escape($mode_key);
845 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
846 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
847 $sql .=
" AND depreciation_mode NOT IN ('" . $this->db->sanitize(implode(
"', '", $modes)) .
"')";
849 $resql = $this->db->query($sql);
851 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
857 require_once DOL_DOCUMENT_ROOT .
'/core/lib/date.lib.php';
858 require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
859 $dates =
getCurrentPeriodOfFiscalYear($this->db, $conf, $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition);
860 $init_fiscal_period_start = $dates[
'date_start'];
861 $init_fiscal_period_end = $dates[
'date_end'];
862 if (empty($init_fiscal_period_start) || empty($init_fiscal_period_end)) {
863 $pastmonthyear = $dates[
'pastmonthyear'];
864 $pastmonth = $dates[
'pastmonth'];
865 $init_fiscal_period_start =
dol_get_first_day($pastmonthyear, $pastmonth,
false);
866 $init_fiscal_period_end =
dol_get_last_day($pastmonthyear, $pastmonth,
false);
869 foreach ($options->deprecation_options as $mode_key => $fields) {
890 $sql =
"SELECT ad.depreciation_date, ad.cumulative_depreciation_ht";
891 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation AS ad";
892 $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";
893 $sql .=
" WHERE ad.fk_asset = " . (int) $this->
id;
894 $sql .=
" AND ad.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
895 $sql .=
" AND iab.fk_docdet IS NOT NULL";
896 $sql .=
" ORDER BY ad.depreciation_date DESC";
899 $resql = $this->db->query($sql);
901 $this->errors[] = $langs->trans(
'AssetErrorFetchMaxDepreciationDateForMode', $mode_key) .
': ' . $this->db->lasterror();
905 $last_depreciation_date =
'';
906 $last_cumulative_depreciation_ht = $this->reversal_amount_ht;
907 if ($obj = $this->db->fetch_object($resql)) {
908 $last_depreciation_date = $this->db->jdate($obj->depreciation_date);
909 $last_cumulative_depreciation_ht = $obj->cumulative_depreciation_ht;
913 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
914 $sql .=
" SET total_amount_last_depreciation_ht = " . (empty($last_cumulative_depreciation_ht) ? 0 : $last_cumulative_depreciation_ht);
915 $sql .=
" WHERE fk_asset = " . (int) $this->
id;
916 $resql = $this->db->query($sql);
918 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
924 $sql =
"DELETE " . MAIN_DB_PREFIX .
"asset_depreciation FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
925 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"accounting_bookkeeping as ab ON ab.doc_type = 'asset' AND ab.fk_docdet = " . MAIN_DB_PREFIX .
"asset_depreciation.rowid";
926 $sql .=
" WHERE " . MAIN_DB_PREFIX .
"asset_depreciation.fk_asset = " . (int) $this->
id;
927 $sql .=
" AND " . MAIN_DB_PREFIX .
"asset_depreciation.depreciation_mode = '" . $this->db->escape($mode_key) .
"'";
928 $sql .=
" AND ab.fk_docdet IS NULL";
929 if ($last_depreciation_date !==
"") {
930 $sql .=
" AND " . MAIN_DB_PREFIX .
"asset_depreciation.ref != ''";
932 $resql = $this->db->query($sql);
934 $this->errors[] = $langs->trans(
'AssetErrorClearDepreciationLines') .
': ' . $this->db->lasterror();
940 $depreciation_date_start = $this->date_start > $this->date_acquisition ? $this->date_start : $this->date_acquisition;
941 $depreciation_date_end =
dol_time_plus_duree($depreciation_date_start, $fields[
'duration'], $fields[
'duration_type'] == 1 ?
'm' : ($fields[
'duration_type'] == 2 ?
'd' :
'y'));
942 $depreciation_amount = $fields[
'amount_base_depreciation_ht'];
943 if ($fields[
'duration_type'] == 2) {
944 $fiscal_period_start = $depreciation_date_start;
945 $fiscal_period_end = $depreciation_date_start;
946 } elseif ($fields[
'duration_type'] == 1) {
947 $date_temp =
dol_getdate($depreciation_date_start);
948 $fiscal_period_start =
dol_get_first_day($date_temp[
'year'], $date_temp[
'mon'],
false);
949 $fiscal_period_end =
dol_get_last_day($date_temp[
'year'], $date_temp[
'mon'],
false);
951 $fiscal_period_start = $init_fiscal_period_start;
952 $fiscal_period_end = $init_fiscal_period_end;
954 $cumulative_depreciation_ht = $last_cumulative_depreciation_ht;
955 $depreciation_period_amount = $depreciation_amount - $this->reversal_amount_ht;
956 $start_date = $depreciation_date_start;
957 $disposal_date = isset($this->disposal_date) && $this->disposal_date !==
"" ? $this->disposal_date :
"";
958 $finish_date = $disposal_date !==
"" ? $disposal_date : $depreciation_date_end;
959 $accountancy_code_depreciation_debit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_debit'];
960 $accountancy_code_depreciation_debit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_debit_key];
961 $accountancy_code_depreciation_credit_key = $accountancy_codes->accountancy_codes_fields[$mode_key][
'depreciation_credit'];
962 $accountancy_code_credit = $accountancy_codes->accountancy_codes[$mode_key][$accountancy_code_depreciation_credit_key];
966 if ($last_depreciation_date ===
"" && ($depreciation_date_start < $fiscal_period_start || is_numeric($this->reversal_date))) {
967 if (is_numeric($this->reversal_date)) {
968 if ($this->reversal_date < $fiscal_period_start) {
969 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotGreaterThanCurrentBeginFiscalDateForMode', $mode_key);
974 if (empty($this->reversal_amount_ht)) {
975 $this->errors[] = $langs->trans(
'AssetErrorReversalAmountNotProvidedForMode', $mode_key);
980 $start_date = $this->reversal_date;
981 $result = $this->
addDepreciationLine($mode_key,
'', $start_date, $this->reversal_amount_ht, $this->reversal_amount_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
987 $this->errors[] = $langs->trans(
'AssetErrorReversalDateNotProvidedForMode', $mode_key);
995 $nb_days_in_year =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_YEAR', 360);
996 $nb_days_in_month =
getDolGlobalInt(
'ASSET_DEPRECIATION_DURATION_PER_MONTH', 30);
997 $period_amount = (float)
price2num($depreciation_period_amount / $fields[
'duration'],
'MT');
998 $first_period_found =
false;
1000 $first_period_date = isset($begin_period) && $begin_period > $fiscal_period_start ? $begin_period : $fiscal_period_start;
1002 $ref_date_format =
"%Y" . ($fields[
'duration_type'] == 1 || $fields[
'duration_type'] == 2 ?
'-%m' :
'') . ($fields[
'duration_type'] == 2 ?
'-%d' :
'');
1006 $max_loop = $fields[
'duration'] + 2;
1010 if ($idx_loop > $max_loop) {
1014 if ($last_depreciation_date < $fiscal_period_end && ($first_period_date <= $start_date || $first_period_found)) {
1016 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end && empty($this->disposal_depreciated)) {
1020 $first_period_found =
true;
1022 $period_begin =
dol_print_date($fiscal_period_start, $ref_date_format);
1023 $period_end =
dol_print_date($fiscal_period_end, $ref_date_format);
1024 $ref = $period_begin . ($period_begin != $period_end ?
' - ' . $period_end :
'');
1025 if ($fiscal_period_start <= $disposal_date && $disposal_date <= $fiscal_period_end) {
1026 $ref .=
' - ' . $langs->transnoentitiesnoconv(
'AssetDisposal');
1029 $begin_date = $fiscal_period_start < $start_date && $start_date <= $fiscal_period_end ? $start_date : $fiscal_period_start;
1030 $end_date = $fiscal_period_start < $finish_date && $finish_date <= $fiscal_period_end ? $finish_date : $fiscal_period_end;
1031 if ($fields[
'duration_type'] == 2) {
1032 $depreciation_ht = $period_amount;
1033 } elseif ($fields[
'duration_type'] == 1) {
1034 $nb_days = min($nb_days_in_month,
num_between_day($begin_date, $end_date, 1));
1035 if ($nb_days >= 28) {
1037 if ($date_temp[
'mon'] == 2) {
1041 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_month,
'MT');
1043 $nb_days = min($nb_days_in_year,
num_between_day($begin_date, $end_date, 1));
1044 $depreciation_ht = (float)
price2num($period_amount * $nb_days / $nb_days_in_year,
'MT');
1047 if ($fiscal_period_start <= $depreciation_date_end && $depreciation_date_end <= $fiscal_period_end) {
1048 $depreciation_ht = (float)
price2num($depreciation_amount - $cumulative_depreciation_ht,
'MT');
1049 $cumulative_depreciation_ht = $depreciation_amount;
1051 $cumulative_depreciation_ht += $depreciation_ht;
1054 $result = $this->
addDepreciationLine($mode_key, $ref, $fiscal_period_end, $depreciation_ht, $cumulative_depreciation_ht, $accountancy_code_depreciation_debit, $accountancy_code_credit);
1063 if ($fields[
'duration_type'] == 2) {
1064 $fiscal_period_end = $fiscal_period_start;
1065 } elseif ($fields[
'duration_type'] == 1) {
1070 $last_period_date = $disposal_date !==
"" && $disposal_date < $depreciation_date_end ? $disposal_date : $depreciation_date_end;
1071 }
while ($fiscal_period_start < $last_period_date);
1080 $this->db->rollback();
1083 $this->db->commit();
1097 $langs->load(
'assets');
1100 $asset_depreciation_id = $asset_depreciation_id > 0 ? $asset_depreciation_id : 0;
1104 if (empty($asset_depreciation_id)) {
1105 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AssetDepreciation") .
' (' . $langs->transnoentitiesnoconv(
"TechnicalID") .
')');
1114 require_once DOL_DOCUMENT_ROOT .
'/asset/class/assetdepreciationoptions.class.php';
1119 $sql =
"SELECT fk_asset, depreciation_mode, cumulative_depreciation_ht";
1120 $sql .=
" FROM " . MAIN_DB_PREFIX .
"asset_depreciation";
1121 $sql .=
" WHERE rowid = " . (int) $asset_depreciation_id;
1122 $resql = $this->db->query($sql);
1124 $this->errors[] = $langs->trans(
'AssetErrorFetchCumulativeDepreciation') .
': ' . $this->db->lasterror();
1127 if ($obj = $this->db->fetch_object($resql)) {
1128 $mode_key = $obj->depreciation_mode;
1129 if (!empty($options->deprecation_options_fields[$mode_key])) {
1130 $sql =
"UPDATE " . MAIN_DB_PREFIX . $options->deprecation_options_fields[$mode_key][
'table'];
1131 $sql .=
" SET total_amount_last_depreciation_ht = " . $obj->cumulative_depreciation_ht;
1132 $sql .=
" WHERE fk_asset = " . (int) $obj->fk_asset;
1133 $resql = $this->db->query($sql);
1135 $this->errors[] = $langs->trans(
'AssetErrorSetLastCumulativeDepreciation') .
': ' . $this->db->lasterror();
1143 $this->db->rollback();
1146 $this->db->commit();
1159 public function dispose($user, $disposal_invoice_id, $notrigger = 0)
1161 global $conf, $langs;
1164 if ($this->
status != self::STATUS_DRAFT || $this->
status == self::STATUS_DISPOSED) {
1170 $required_fields = array(
'disposal_date',
'disposal_date',
'fk_disposal_type');
1171 foreach ($required_fields as $field) {
1172 $this->fields[$field][
'notnull'] = 1;
1174 $result = $this->
update($user, 1);
1175 foreach ($required_fields as $field) {
1176 $this->fields[$field][
'notnull'] = 0;
1179 if ($disposal_invoice_id > 0) {
1182 $result = $this->
setStatusCommon($user, self::STATUS_DISPOSED, $notrigger,
'ASSET_DISPOSED');
1189 $this->db->rollback();
1191 $this->db->commit();
1196 if (method_exists($this,
'generateDocument')) {
1197 global $hidedetails, $hidedesc, $hideref;
1198 $outputlangs = $langs;
1201 $newlang =
GETPOST(
'lang_id',
'aZ09');
1204 $newlang = $this->thirdparty->default_lang;
1206 if (!empty($newlang)) {
1207 $outputlangs =
new Translate(
"", $conf);
1208 $outputlangs->setDefaultLang($newlang);
1210 $model = $this->model_pdf;
1211 $ret = $this->
fetch($this->
id);
1213 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1227 public function reopen($user, $notrigger = 0)
1229 global $conf, $langs;
1232 if ($this->
status != self::STATUS_DISPOSED || $this->
status == self::STATUS_DRAFT) {
1239 $this->disposal_date =
null;
1240 $this->disposal_amount_ht =
null;
1241 $this->fk_disposal_type =
null;
1242 $this->disposal_depreciated =
null;
1243 $this->disposal_subject_to_vat =
null;
1244 $result = $this->
update($user, 1);
1247 $result = $this->
setStatusCommon($user, self::STATUS_DRAFT, $notrigger,
'ASSET_REOPEN');
1254 $this->db->rollback();
1256 $this->db->commit();
1261 if (method_exists($this,
'generateDocument')) {
1262 global $hidedetails, $hidedesc, $hideref;
1263 $outputlangs = $langs;
1266 $newlang =
GETPOST(
'lang_id',
'aZ09');
1269 $newlang = $this->thirdparty->default_lang;
1271 if (!empty($newlang)) {
1272 $outputlangs =
new Translate(
"", $conf);
1273 $outputlangs->setDefaultLang($newlang);
1275 $model = $this->model_pdf;
1276 $ret = $this->
fetch($this->
id);
1278 $this->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1296 public function getNomUrl($withpicto = 0, $option =
'', $maxlen = 0, $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1298 global $db, $conf, $langs, $hookmanager;
1299 global $dolibarr_main_authentication, $dolibarr_main_demo;
1300 global $menumanager;
1302 if (!empty($conf->dol_no_mouse_hover)) {
1308 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"Asset").
'</u>';
1309 if (isset($this->
status)) {
1310 $label .=
' '.$this->getLibStatut(5);
1313 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1315 $url =
dol_buildpath(
'/asset/card.php', 1).
'?id='.$this->id;
1317 if ($option !=
'nolink') {
1319 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1320 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1321 $add_save_lastsearch_values = 1;
1323 if ($add_save_lastsearch_values) {
1324 $url .=
'&save_lastsearch_values=1';
1329 if (empty($notooltip)) {
1331 $label = $langs->trans(
"ShowAsset");
1332 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1334 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1335 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1337 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1340 if ($option ==
'nolink') {
1341 $linkstart =
'<span';
1343 $linkstart =
'<a href="'.$url.
'"';
1345 $linkstart .= $linkclose.
'>';
1346 if ($option ==
'nolink') {
1347 $linkend =
'</span>';
1352 $result .= $linkstart;
1354 if (empty($this->showphoto_on_popup)) {
1356 $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);
1360 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1362 list($class, $module) = explode(
'@', $this->picto);
1365 $filename = $filearray[0][
'name'];
1366 if (!empty($filename)) {
1367 $pospoint = strpos($filearray[0][
'name'],
'.');
1369 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
1370 if (!
getDolGlobalString(strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS')) {
1371 $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>';
1373 $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>';
1376 $result .=
'</div>';
1378 $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);
1383 if ($withpicto != 2) {
1385 if ($option ==
'label') {
1386 $name = $this->label;
1387 } elseif ($option ==
'with_label') {
1388 $name .=
' - ' . $this->label;
1393 $result .= $linkend;
1397 $hookmanager->initHooks(array($this->element .
'dao'));
1398 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1399 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1401 $result = $hookmanager->resPrint;
1403 $result .= $hookmanager->resPrint;
1441 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1444 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1445 $this->labelStatus[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1446 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'AssetInProgress');
1447 $this->labelStatusShort[self::STATUS_DISPOSED] = $langs->transnoentitiesnoconv(
'AssetDisposed');
1450 $statusType =
'status4';
1451 if ($status == self::STATUS_DISPOSED) {
1452 $statusType =
'status6';
1455 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1466 $sql =
"SELECT rowid, date_creation as datec, tms as datem,";
1467 $sql .=
" fk_user_creat, fk_user_modif";
1468 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
1469 $sql .=
" WHERE t.rowid = ".((int) $id);
1471 $result = $this->db->query($sql);
1473 if ($this->db->num_rows($result)) {
1474 $obj = $this->db->fetch_object($result);
1475 $this->
id = $obj->rowid;
1477 $this->user_creation_id = $obj->fk_user_creat;
1478 $this->user_modification_id = $obj->fk_user_modif;
1479 $this->date_creation = $this->db->jdate($obj->datec);
1480 $this->date_modification = $this->db->jdate($obj->datem);
1483 $this->db->free($result);
1511 $this->lines = array();
1513 return $this->lines;
1523 global $langs, $conf;
1524 $langs->load(
"assets");
1527 $conf->global->ASSET_ASSET_ADDON =
'mod_asset_standard';
1537 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1538 foreach ($dirmodels as $reldir) {
1542 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1545 if ($mybool ===
false) {
1550 if (class_exists($classname)) {
1551 $obj =
new $classname();
1552 $numref = $obj->getNextValue($this);
1554 if ($numref !=
'' && $numref !=
'-1') {
1557 $this->error = $obj->error;
1562 print $langs->trans(
"Error").
" ".$langs->trans(
"ClassNotFound").
' '.$classname;
1566 print $langs->trans(
"ErrorNumberingModuleNotSetup", $this->element);
getCurrentPeriodOfFiscalYear($db, $conf, $from_time=null)
Get current period of fiscal year.
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
getLinesArray()
Create an array of lines.
dispose($user, $disposal_invoice_id, $notrigger=0)
Set dispose status.
createFromClone(User $user, $fromid)
Clone an object into another one.
calculationDepreciation()
Calculation depreciation lines (reversal and future) for each mode.
fetchLines()
Load object lines in memory from the database.
__construct(DoliDB $db)
Constructor.
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.
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.
Class to manage Dolibarr database access.
Class to manage translations.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
num_between_day($timestampStart, $timestampEnd, $lastday=0)
Function to return number of days between two dates (date must be UTC date !) Example: 2012-01-01 201...
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_dir_list($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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return 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...