30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereportline.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_ik.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
44 public $element =
'expensereport';
49 public $table_element =
'expensereport';
54 public $table_element_line =
'expensereport_det';
59 public $fk_element =
'fk_expensereport';
64 public $picto =
'trip';
69 public $lines = array();
89 public $date_approbation;
99 public $user_approve_id;
119 public $fk_c_paiement;
124 public $modepaymentid;
135 public $user_paid_infos;
140 public $user_author_infos;
145 public $user_validator_infos;
150 public $rule_warning_message;
163 public $fk_user_creat;
168 public $fk_user_author;
179 public $fk_user_modif;
190 public $detail_refuse;
195 public $fk_user_refuse;
206 public $detail_cancel;
211 public $fk_user_cancel;
216 public $fk_user_validator;
235 public $fk_user_valid;
240 public $user_valid_infos;
246 public $date_approve;
251 public $fk_user_approve;
294 public $fields = array(
295 'rowid' => array(
'type' =>
'integer',
'label' =>
'ID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
296 'ref' => array(
'type' =>
'varchar(50)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 15),
297 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 20),
298 'ref_number_int' => array(
'type' =>
'integer',
'label' =>
'Ref number int',
'enabled' => 1,
'visible' => -1,
'position' => 25),
299 'ref_ext' => array(
'type' =>
'integer',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 30),
300 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ht',
'enabled' => 1,
'visible' => -1,
'position' => 35),
301 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Total tva',
'enabled' => 1,
'visible' => -1,
'position' => 40),
302 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 45),
303 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 50),
304 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 55),
305 'date_debut' => array(
'type' =>
'date',
'label' =>
'Date debut',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 60),
306 'date_fin' => array(
'type' =>
'date',
'label' =>
'Date fin',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 65),
307 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'Date valid',
'enabled' => 1,
'visible' => -1,
'position' => 75),
308 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'Date approve',
'enabled' => 1,
'visible' => -1,
'position' => 80),
309 'date_refuse' => array(
'type' =>
'datetime',
'label' =>
'Date refuse',
'enabled' => 1,
'visible' => -1,
'position' => 85),
310 'date_cancel' => array(
'type' =>
'datetime',
'label' =>
'Date cancel',
'enabled' => 1,
'visible' => -1,
'position' => 90),
311 'fk_user_author' => array(
'type' =>
'integer',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 100),
312 'fk_user_modif' => array(
'type' =>
'integer',
'label' =>
'Fk user modif',
'enabled' => 1,
'visible' => -1,
'position' => 105),
313 'fk_user_valid' => array(
'type' =>
'integer',
'label' =>
'Fk user valid',
'enabled' => 1,
'visible' => -1,
'position' => 110),
314 'fk_user_validator' => array(
'type' =>
'integer',
'label' =>
'Fk user validator',
'enabled' => 1,
'visible' => -1,
'position' => 115),
315 'fk_user_approve' => array(
'type' =>
'integer',
'label' =>
'Fk user approve',
'enabled' => 1,
'visible' => -1,
'position' => 120),
316 'fk_user_refuse' => array(
'type' =>
'integer',
'label' =>
'Fk user refuse',
'enabled' => 1,
'visible' => -1,
'position' => 125),
317 'fk_user_cancel' => array(
'type' =>
'integer',
'label' =>
'Fk user cancel',
'enabled' => 1,
'visible' => -1,
'position' => 130),
318 'fk_c_paiement' => array(
'type' =>
'integer',
'label' =>
'Fk c paiement',
'enabled' => 1,
'visible' => -1,
'position' => 140),
319 'paid' => array(
'type' =>
'integer',
'label' =>
'Paid',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 145),
320 'note_public' => array(
'type' =>
'html',
'label' =>
'Note public',
'enabled' => 1,
'visible' => 0,
'position' => 150),
321 'note_private' => array(
'type' =>
'html',
'label' =>
'Note private',
'enabled' => 1,
'visible' => 0,
'position' => 155),
322 'detail_refuse' => array(
'type' =>
'varchar(255)',
'label' =>
'Detail refuse',
'enabled' => 1,
'visible' => -1,
'position' => 160),
323 'detail_cancel' => array(
'type' =>
'varchar(255)',
'label' =>
'Detail cancel',
'enabled' => 1,
'visible' => -1,
'position' => 165),
324 'integration_compta' => array(
'type' =>
'integer',
'label' =>
'Integration compta',
'enabled' => 1,
'visible' => -1,
'position' => 170),
325 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fk bank account',
'enabled' => 1,
'visible' => -1,
'position' => 175),
326 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
327 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 190),
328 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency tx',
'enabled' => 1,
'visible' => -1,
'position' => 195),
329 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ht',
'enabled' => 1,
'visible' => -1,
'position' => 200),
330 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total tva',
'enabled' => 1,
'visible' => -1,
'position' => 205),
331 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 210),
332 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 220),
333 'date_create' => array(
'type' =>
'datetime',
'label' =>
'Date create',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 300),
334 'tms' => array(
'type' =>
'timestamp',
'label' =>
'Tms',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 305),
335 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 1000),
336 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 1010),
337 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Fk statut',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
349 $this->total_ttc = 0;
350 $this->total_tva = 0;
351 $this->total_localtax1 = 0;
352 $this->total_localtax2 = 0;
353 $this->localtax1 = 0;
354 $this->localtax2 = 0;
355 $this->modepaymentid = 0;
358 $this->labelStatusShort = array(0 =>
'Draft', 2 =>
'Validated', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
359 $this->labelStatus = array(0 =>
'Draft', 2 =>
'ValidatedWaitingApproval', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
361 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
371 public function create($user, $notrigger = 0)
373 global
$conf, $langs;
380 if (empty($this->date_debut) || empty($this->date_fin)) {
381 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Date'));
385 $fuserid = $this->fk_user_author;
386 if (empty($fuserid)) {
387 $fuserid = $user->id;
392 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
395 $sql .=
",total_ttc";
396 $sql .=
",total_tva";
397 $sql .=
",date_debut";
399 $sql .=
",date_create";
400 $sql .=
",fk_user_creat";
401 $sql .=
",fk_user_author";
402 $sql .=
",fk_user_validator";
403 $sql .=
",fk_user_approve";
404 $sql .=
",fk_user_modif";
405 $sql .=
",fk_statut";
406 $sql .=
",fk_c_paiement";
408 $sql .=
",note_public";
409 $sql .=
",note_private";
413 $sql .=
", ".price2num($this->total_ht,
'MT');
414 $sql .=
", ".price2num($this->total_ttc,
'MT');
415 $sql .=
", ".price2num($this->total_tva,
'MT');
416 $sql .=
", '".$this->db->idate($this->date_debut).
"'";
417 $sql .=
", '".$this->db->idate($this->date_fin).
"'";
418 $sql .=
", '".$this->db->idate($now).
"'";
419 $sql .=
", ".((int) $user->id);
420 $sql .=
", ".((int) $fuserid);
421 $sql .=
", ".($this->fk_user_validator > 0 ? ((int) $this->fk_user_validator) :
"null");
422 $sql .=
", ".($this->fk_user_approve > 0 ? ((int) $this->fk_user_approve) :
"null");
423 $sql .=
", ".($this->fk_user_modif > 0 ? ((int) $this->fk_user_modif) :
"null");
424 $sql .=
", ".($this->fk_statut > 1 ? ((int) $this->fk_statut) : 0);
425 $sql .=
", ".($this->modepaymentid ? ((int) $this->modepaymentid) :
"null");
427 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
428 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
429 $sql .=
", ".((int)
$conf->entity);
432 $result = $this->db->query($sql);
434 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
435 $this->
ref =
'(PROV'.$this->id.
')';
437 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
438 $resql = $this->db->query($sql);
440 $this->error = $this->db->lasterror();
445 if (is_array($this->lines) && count($this->lines) > 0) {
446 foreach ($this->lines as $line) {
449 if (!is_object($line)) {
450 $line = (object) $line;
452 $newndfline->fk_expensereport = $line->fk_expensereport;
453 $newndfline->fk_c_type_fees = $line->fk_c_type_fees;
454 $newndfline->fk_project = $line->fk_project;
455 $newndfline->vatrate = $line->vatrate;
456 $newndfline->vat_src_code = $line->vat_src_code;
457 $newndfline->localtax1_tx = $line->localtax1_tx;
458 $newndfline->localtax2_tx = $line->localtax2_tx;
459 $newndfline->localtax1_type = $line->localtax1_type;
460 $newndfline->localtax2_type = $line->localtax2_type;
461 $newndfline->comments = $line->comments;
462 $newndfline->qty = $line->qty;
463 $newndfline->value_unit = $line->value_unit;
464 $newndfline->total_ht = $line->total_ht;
465 $newndfline->total_ttc = $line->total_ttc;
466 $newndfline->total_tva = $line->total_tva;
467 $newndfline->total_localtax1 = $line->total_localtax1;
468 $newndfline->total_localtax2 = $line->total_localtax2;
469 $newndfline->date = $line->date;
470 $newndfline->rule_warning_message = $line->rule_warning_message;
471 $newndfline->fk_c_exp_tax_cat = $line->fk_c_exp_tax_cat;
472 $newndfline->fk_ecm_files = $line->fk_ecm_files;
477 $newndfline->fk_expensereport = $this->id;
478 $result = $newndfline->insert();
480 $this->error = $newndfline->error;
481 $this->errors = $newndfline->errors;
501 $result = $this->
call_trigger(
'EXPENSE_REPORT_CREATE', $user);
513 $this->db->rollback();
517 $this->db->rollback();
521 dol_syslog(get_class($this).
"::create error ".$this->error, LOG_ERR);
522 $this->db->rollback();
526 $this->error = $this->db->lasterror().
" sql=".$sql;
527 $this->db->rollback();
545 if (empty($fk_user_author)) {
546 $fk_user_author = $user->id;
556 $objFrom = clone $this;
561 $this->fk_statut = 0;
564 $this->fk_user_creat = $user->id;
565 $this->fk_user_author = $fk_user_author;
566 $this->fk_user_valid = 0;
567 $this->date_create =
'';
568 $this->date_creation =
'';
569 $this->date_validation =
'';
572 if (is_array($this->lines) && count($this->lines) > 0) {
573 foreach ($this->lines as $key => $line) {
574 $this->lines[$key]->fk_ecm_files = 0;
579 $this->context[
'createfromclone'] =
'createfromclone';
580 $result = $this->
create($user);
587 if (is_object($hookmanager)) {
588 $parameters = array(
'objFrom' => $objFrom);
590 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
598 unset($this->context[
'createfromclone']);
605 $this->db->rollback();
619 public function update($user, $notrigger = 0, $userofexpensereport =
null)
624 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
625 $sql .=
" total_ht = ".((float) $this->total_ht);
626 $sql .=
" , total_ttc = ".((float) $this->total_ttc);
627 $sql .=
" , total_tva = ".((float) $this->total_tva);
628 $sql .=
" , date_debut = '".$this->db->idate($this->date_debut).
"'";
629 $sql .=
" , date_fin = '".$this->db->idate($this->date_fin).
"'";
630 if ($userofexpensereport && is_object($userofexpensereport)) {
631 $sql .=
" , fk_user_author = ".($userofexpensereport->id > 0 ? $userofexpensereport->id :
"null");
633 $sql .=
" , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator :
"null");
634 $sql .=
" , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid :
"null");
635 $sql .=
" , fk_user_approve = ".($this->fk_user_approve > 0 ? $this->fk_user_approve :
"null");
636 $sql .=
" , fk_user_modif = ".((int) $user->id);
637 $sql .=
" , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut :
'0');
638 $sql .=
" , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement :
"null");
639 $sql .=
" , note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"''");
640 $sql .=
" , note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"''");
641 $sql .=
" , detail_refuse = ".(!empty($this->detail_refuse) ?
"'".$this->db->escape($this->detail_refuse).
"'" :
"''");
642 $sql .=
" WHERE rowid = ".((int) $this->
id);
644 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
645 $result = $this->db->query($sql);
652 if (!$error && !$notrigger) {
654 $result = $this->
call_trigger(
'EXPENSE_REPORT_MODIFY', $user);
665 $this->db->rollback();
666 $this->error = $this->db->error();
670 $this->db->rollback();
671 $this->error = $this->db->error();
683 public function fetch($id, $ref =
'')
685 $sql =
"SELECT d.rowid, d.entity, d.ref, d.note_public, d.note_private,";
686 $sql .=
" d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,";
687 $sql .=
" d.date_refuse, d.date_cancel,";
688 $sql .=
" d.total_ht, d.total_ttc, d.total_tva,";
689 $sql .=
" d.localtax1 as total_localtax1, d.localtax2 as total_localtax2,";
690 $sql .=
" d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,";
691 $sql .=
" d.fk_user_creat, d.fk_user_author, d.fk_user_modif, d.fk_user_validator,";
692 $sql .=
" d.fk_user_valid, d.fk_user_approve,";
693 $sql .=
" d.fk_statut as status, d.fk_c_paiement, d.paid";
694 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as d";
696 $sql .=
" WHERE d.ref = '".$this->db->escape($ref).
"'";
697 $sql .=
" AND d.entity IN (".getEntity(
'expensereport').
")";
699 $sql .=
" WHERE d.rowid = ".((int) $id);
703 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
704 $resql = $this->db->query($sql);
706 $obj = $this->db->fetch_object($resql);
708 $this->
id = $obj->rowid;
709 $this->
ref = $obj->ref;
711 $this->entity = $obj->entity;
713 $this->total_ht = $obj->total_ht;
714 $this->total_tva = $obj->total_tva;
715 $this->total_ttc = $obj->total_ttc;
716 $this->localtax1 = $obj->total_localtax1;
717 $this->localtax2 = $obj->total_localtax2;
718 $this->total_localtax1 = $obj->total_localtax1;
719 $this->total_localtax2 = $obj->total_localtax2;
721 $this->note_public = $obj->note_public;
722 $this->note_private = $obj->note_private;
723 $this->detail_refuse = $obj->detail_refuse;
724 $this->detail_cancel = $obj->detail_cancel;
726 $this->date_debut = $this->db->jdate($obj->date_debut);
727 $this->date_fin = $this->db->jdate($obj->date_fin);
728 $this->date_valid = $this->db->jdate($obj->date_valid);
729 $this->date_approve = $this->db->jdate($obj->date_approve);
730 $this->date_create = $this->db->jdate($obj->date_create);
731 $this->date_modif = $this->db->jdate($obj->date_modif);
732 $this->date_refuse = $this->db->jdate($obj->date_refuse);
733 $this->date_cancel = $this->db->jdate($obj->date_cancel);
735 $this->fk_user_creat = $obj->fk_user_creat;
736 $this->fk_user_author = $obj->fk_user_author;
737 $this->fk_user_modif = $obj->fk_user_modif;
738 $this->fk_user_validator = $obj->fk_user_validator;
739 $this->fk_user_valid = $obj->fk_user_valid;
740 $this->fk_user_refuse = $obj->fk_user_refuse;
741 $this->fk_user_cancel = $obj->fk_user_cancel;
742 $this->fk_user_approve = $obj->fk_user_approve;
744 $user_author =
new User($this->db);
745 if ($this->fk_user_author > 0) {
746 $user_author->fetch($this->fk_user_author);
749 $this->user_author_infos =
dolGetFirstLastname($user_author->firstname, $user_author->lastname);
751 $user_approver =
new User($this->db);
752 if ($this->fk_user_approve > 0) {
753 $user_approver->fetch($this->fk_user_approve);
754 } elseif ($this->fk_user_validator > 0) {
755 $user_approver->fetch($this->fk_user_validator);
757 $this->user_validator_infos =
dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
759 $this->fk_statut = (int) $obj->status;
760 $this->
status = (int) $obj->status;
761 $this->fk_c_paiement = $obj->fk_c_paiement;
762 $this->paid = $obj->paid;
764 if ($this->
status == self::STATUS_APPROVED || $this->
status == self::STATUS_CLOSED) {
765 $user_valid =
new User($this->db);
766 if ($this->fk_user_valid > 0) {
767 $user_valid->fetch($this->fk_user_valid);
769 $this->user_valid_infos =
dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
781 $this->error = $this->db->lasterror();
797 public function set_paid($id, $fuser, $notrigger = 0)
800 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
801 return $this->
setPaid($id, $fuser, $notrigger);
812 public function setPaid($id, $fuser, $notrigger = 0)
817 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport";
818 $sql .=
" SET fk_statut = ".self::STATUS_CLOSED.
", paid=1";
821 dol_syslog(get_class($this).
"::setPaid", LOG_DEBUG);
822 $resql = $this->db->query($sql);
824 if ($this->db->affected_rows($resql)) {
827 $result = $this->
call_trigger(
'EXPENSE_REPORT_PAID', $fuser);
839 $this->db->rollback();
840 $this->error = $this->db->error();
848 $this->db->rollback();
878 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
879 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
881 $statuslogo = array(0 =>
'status0', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
883 $statusType = $statuslogo[$status];
885 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
899 $sql =
"SELECT f.rowid,";
900 $sql .=
" f.date_create as datec,";
901 $sql .=
" f.tms as date_modification,";
902 $sql .=
" f.date_valid as datev,";
903 $sql .=
" f.date_approve as datea,";
904 $sql .=
" f.fk_user_creat as fk_user_creation,";
905 $sql .=
" f.fk_user_author as fk_user_author,";
906 $sql .=
" f.fk_user_modif as fk_user_modification,";
907 $sql .=
" f.fk_user_valid,";
908 $sql .=
" f.fk_user_approve";
909 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as f";
910 $sql .=
" WHERE f.rowid = ".((int) $id);
911 $sql .=
" AND f.entity = ".$conf->entity;
915 $resql = $this->db->query($sql);
917 if ($this->db->num_rows($resql)) {
918 $obj = $this->db->fetch_object($resql);
920 $this->
id = $obj->rowid;
922 $this->date_creation = $this->db->jdate($obj->datec);
923 $this->date_modification = $this->db->jdate($obj->date_modification);
924 $this->date_validation = $this->db->jdate($obj->datev);
925 $this->date_approbation = $this->db->jdate($obj->datea);
927 $this->user_creation_id = $obj->fk_user_author;
928 $this->user_creation_id = $obj->fk_user_creation;
929 $this->user_validation_id = $obj->fk_user_valid;
930 $this->user_modification_id = $obj->fk_user_modification;
931 $this->user_approve_id = $obj->fk_user_approve;
933 $this->db->free($resql);
950 global $user, $langs;
956 $this->
ref =
'SPECIMEN';
959 $this->date_create = $now;
960 $this->date_debut = $now;
961 $this->date_fin = $now;
962 $this->date_valid = $now;
963 $this->date_approve = $now;
969 $this->fk_user_author = $user->id;
970 $this->fk_user_validator = $user->id;
971 $this->fk_user_valid = $user->id;
972 $this->fk_user_approve = $user->id;
974 $this->note_private =
'Private note';
975 $this->note_public =
'SPECIMEN';
978 while ($xnbp < $nbp) {
980 $line->comments = $langs->trans(
"Comment").
" ".$xnbp;
981 $line->date = ($now - 3600 * (1 + $xnbp));
982 $line->total_ht = 100;
983 $line->total_tva = 20;
984 $line->total_ttc = 120;
987 $line->value_unit = 120;
988 $line->fk_expensereport = 0;
989 $line->type_fees_code =
'TRA';
990 $line->fk_c_type_fees = $type_fees_id;
992 $line->projet_ref =
'ABC';
994 $this->lines[$xnbp] = $line;
997 $this->total_ht += $line->total_ht;
998 $this->total_tva += $line->total_tva;
999 $this->total_ttc += $line->total_ttc;
1018 $langs->load(
'trips');
1020 if ($user->hasRight(
'expensereport',
'lire')) {
1021 $sql =
"SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc";
1022 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as de";
1023 $sql .=
" WHERE de.fk_projet = ".((int) $projectid);
1025 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1026 $result = $this->db->query($sql);
1028 $num = $this->db->num_rows($result);
1034 $objp = $this->db->fetch_object($result);
1036 $sql2 =
"SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut as status";
1037 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d";
1038 $sql2 .=
" WHERE d.rowid = ".((int) $objp->fk_expensereport);
1040 $result2 = $this->db->query($sql2);
1041 $obj = $this->db->fetch_object($result2);
1043 $objp->fk_user_author = $obj->fk_user_author;
1044 $objp->ref = $obj->ref;
1045 $objp->fk_c_expensereport_status = $obj->status;
1046 $objp->rowid = $obj->rowid;
1048 $total_HT += $objp->total_ht;
1049 $total_TTC += $objp->total_ttc;
1050 $author =
new User($this->db);
1051 $author->fetch($objp->fk_user_author);
1054 print
'<td><a href="'.DOL_URL_ROOT.
'/expensereport/card.php?id='.$objp->rowid.
'">'.$objp->ref_num.
'</a></td>';
1055 print
'<td class="center">'.dol_print_date($objp->date,
'day').
'</td>';
1056 print
'<td>'.$author->getNomUrl(1).
'</td>';
1057 print
'<td>'.$objp->comments.
'</td>';
1058 print
'<td class="right">'.price($objp->total_ht).
'</td>';
1059 print
'<td class="right">'.price($objp->total_ttc).
'</td>';
1060 print
'<td class="right">';
1062 switch ($objp->fk_c_expensereport_status) {
1064 print
img_picto($langs->trans(
'StatusOrderCanceled'),
'statut5');
1067 print $langs->trans(
'Draft').
' '.
img_picto($langs->trans(
'Draft'),
'statut0');
1070 print $langs->trans(
'TripForValid').
' '.
img_picto($langs->trans(
'TripForValid'),
'statut3');
1073 print $langs->trans(
'TripForPaid').
' '.
img_picto($langs->trans(
'TripForPaid'),
'statut3');
1076 print $langs->trans(
'TripPaid').
' '.
img_picto($langs->trans(
'TripPaid'),
'statut4');
1093 print
'<tr class="liste_total"><td colspan="4">'.$langs->trans(
"Number").
': '.$i.
'</td>';
1094 print
'<td class="right" width="100">'.$langs->trans(
"TotalHT").
' : '.
price($total_HT).
'</td>';
1095 print
'<td class="right" width="100">'.$langs->trans(
"TotalTTC").
' : '.
price($total_TTC).
'</td>';
1096 print
'<td> </td>';
1099 $this->error = $this->db->lasterror();
1116 $this->lines = array();
1118 $sql =
' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date, de.rang,';
1119 $sql .=
" de.".$this->fk_element.
", de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project,";
1120 $sql .=
' de.tva_tx, de.vat_src_code,';
1121 $sql .=
' de.localtax1_tx, de.localtax2_tx, de.localtax1_type, de.localtax2_type,';
1122 $sql .=
' de.fk_ecm_files,';
1123 $sql .=
' de.total_ht, de.total_tva, de.total_ttc,';
1124 $sql .=
' de.total_localtax1, de.total_localtax2, de.rule_warning_message,';
1125 $sql .=
' ctf.code as code_type_fees, ctf.label as label_type_fees, ctf.accountancy_code as accountancy_code_type_fees,';
1126 $sql .=
' p.ref as ref_projet, p.title as title_projet';
1127 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as de';
1128 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
1129 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as p ON de.fk_projet = p.rowid';
1130 $sql .=
" WHERE de.".$this->fk_element.
" = ".((int) $this->
id);
1132 $sql .=
' ORDER BY de.rang ASC, de.rowid ASC';
1134 $sql .=
' ORDER BY de.rang ASC, de.date ASC';
1137 $resql = $this->db->query($sql);
1139 $num = $this->db->num_rows($resql);
1142 $objp = $this->db->fetch_object($resql);
1146 $deplig->rowid = $objp->rowid;
1147 $deplig->id = $objp->rowid;
1148 $deplig->comments = $objp->comments;
1149 $deplig->qty = $objp->qty;
1150 $deplig->value_unit = $objp->value_unit;
1151 $deplig->date = $objp->date;
1152 $deplig->dates = $this->db->jdate($objp->date);
1154 $deplig->fk_expensereport = $objp->fk_expensereport;
1155 $deplig->fk_c_type_fees = $objp->fk_c_type_fees;
1156 $deplig->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat;
1157 $deplig->fk_projet = $objp->fk_project;
1158 $deplig->fk_project = $objp->fk_project;
1159 $deplig->fk_ecm_files = $objp->fk_ecm_files;
1161 $deplig->total_ht = $objp->total_ht;
1162 $deplig->total_tva = $objp->total_tva;
1163 $deplig->total_ttc = $objp->total_ttc;
1164 $deplig->total_localtax1 = $objp->total_localtax1;
1165 $deplig->total_localtax2 = $objp->total_localtax2;
1167 $deplig->type_fees_code = empty($objp->code_type_fees) ?
'TF_OTHER' : $objp->code_type_fees;
1168 $deplig->type_fees_libelle = $objp->label_type_fees;
1169 $deplig->type_fees_accountancy_code = $objp->accountancy_code_type_fees;
1171 $deplig->tva_tx = $objp->tva_tx;
1172 $deplig->vatrate = $objp->tva_tx;
1173 $deplig->vat_src_code = $objp->vat_src_code;
1174 $deplig->localtax1_tx = $objp->localtax1_tx;
1175 $deplig->localtax2_tx = $objp->localtax2_tx;
1176 $deplig->localtax1_type = $objp->localtax1_type;
1177 $deplig->localtax2_type = $objp->localtax2_type;
1179 $deplig->projet_ref = $objp->ref_projet;
1180 $deplig->projet_title = $objp->title_projet;
1182 $deplig->rule_warning_message = $objp->rule_warning_message;
1184 $deplig->rang = $objp->rang;
1186 $this->lines[$i] = $deplig;
1190 $this->db->free($resql);
1193 $this->error = $this->db->lasterror();
1194 dol_syslog(get_class($this).
"::fetch_lines: Error ".$this->error, LOG_ERR);
1207 public function delete($user =
null, $notrigger = 0)
1210 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1218 $result = $this->
call_trigger(
'EXPENSE_REPORT_DELETE', $user);
1226 if (!$error && !empty($this->table_element_line)) {
1227 $tabletodelete = $this->table_element_line;
1229 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
1230 if (!$this->db->query($sql)) {
1232 $this->error = $this->db->lasterror();
1233 $this->errors[] = $this->error;
1234 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1259 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1265 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
1266 $res = $this->db->query($sql);
1269 $this->error = $this->db->lasterror();
1270 $this->errors[] = $this->error;
1271 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1287 if ($conf->expensereport->multidir_output[$this->entity] && !empty($this->
ref)) {
1288 $dir =
$conf->expensereport->multidir_output[$this->entity].
"/".$ref;
1289 $file = $dir.
"/".$ref.
".pdf";
1290 if (file_exists($file)) {
1294 $this->error =
'ErrorFailToDeleteFile';
1295 $this->errors[] = $this->error;
1296 $this->db->rollback();
1300 if (file_exists($dir)) {
1303 $this->error =
'ErrorFailToDeleteDir';
1304 $this->errors[] = $this->error;
1305 $this->db->rollback();
1313 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
1314 $this->db->commit();
1317 $this->db->rollback();
1331 global
$conf, $langs, $user;
1337 if ($this->
status == self::STATUS_VALIDATED) {
1338 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
1342 $this->date_valid = $now;
1345 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
1350 if (empty($num) || $num < 0) {
1359 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1360 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1361 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
1362 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1363 $sql .=
" fk_user_valid = ".((int) $user->id);
1364 $sql .=
" WHERE rowid = ".((int) $this->
id);
1366 $resql = $this->db->query($sql);
1368 if (!$error && !$notrigger) {
1370 $result = $this->
call_trigger(
'EXPENSE_REPORT_VALIDATE', $fuser);
1378 $this->oldref = $this->ref;
1381 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1382 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1385 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'expensereport/".$this->db->escape($this->newref).
"'";
1386 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expensereport/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $this->entity);
1387 $resql = $this->db->query($sql);
1390 $this->error = $this->db->lasterror();
1392 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expensereport/".$this->db->escape($this->newref).
"'";
1393 $sql .=
" WHERE filepath = 'expensereport/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
1394 $resql = $this->db->query($sql);
1397 $this->error = $this->db->lasterror();
1403 $dirsource =
$conf->expensereport->multidir_output[$this->entity].
'/'.$oldref;
1404 $dirdest =
$conf->expensereport->multidir_output[$this->entity].
'/'.$newref;
1405 if (!$error && file_exists($dirsource)) {
1406 dol_syslog(get_class($this).
"::setValidate() rename dir ".$dirsource.
" into ".$dirdest);
1408 if (@rename($dirsource, $dirdest)) {
1411 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1412 foreach ($listoffiles as $fileentry) {
1413 $dirsource = $fileentry[
'name'];
1414 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1415 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1416 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1417 @rename($dirsource, $dirdest);
1430 if (empty($error)) {
1431 $this->db->commit();
1434 $this->db->rollback();
1435 $this->error = $this->db->error();
1439 $this->db->rollback();
1440 $this->error = $this->db->lasterror();
1456 $sql =
'SELECT date_debut';
1457 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element;
1458 $sql .=
" WHERE rowid = ".((int) $this->
id);
1460 $result = $this->db->query($sql);
1462 $objp = $this->db->fetch_object($result);
1464 $this->date_debut = $this->db->jdate($objp->date_debut);
1466 if ($this->
status != self::STATUS_VALIDATED) {
1467 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1468 $sql .=
" SET fk_statut = ".self::STATUS_VALIDATED;
1469 $sql .=
" WHERE rowid = ".((int) $this->
id);
1471 dol_syslog(get_class($this).
"::set_save_from_refuse", LOG_DEBUG);
1473 if ($this->db->query($sql)) {
1476 $this->error = $this->db->lasterror();
1480 dol_syslog(get_class($this).
"::set_save_from_refuse expensereport already with save status", LOG_WARNING);
1499 $this->date_approve = $now;
1500 if ($this->
status != self::STATUS_APPROVED) {
1503 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1504 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"', fk_statut = ".self::STATUS_APPROVED.
", fk_user_approve = ".((int) $fuser->id).
",";
1505 $sql .=
" date_approve='".$this->db->idate($this->date_approve).
"'";
1506 $sql .=
" WHERE rowid = ".((int) $this->
id);
1507 if ($this->db->query($sql)) {
1510 $result = $this->
call_trigger(
'EXPENSE_REPORT_APPROVE', $fuser);
1518 if (empty($error)) {
1519 $this->db->commit();
1522 $this->db->rollback();
1523 $this->error = $this->db->error();
1527 $this->db->rollback();
1528 $this->error = $this->db->lasterror();
1532 dol_syslog(get_class($this).
"::setApproved expensereport already with approve status", LOG_WARNING);
1546 public function setDeny($fuser, $details, $notrigger = 0)
1552 if ($this->
status != self::STATUS_REFUSED) {
1553 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1554 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"', fk_statut = ".self::STATUS_REFUSED.
", fk_user_refuse = ".((int) $fuser->id).
",";
1555 $sql .=
" date_refuse='".$this->db->idate($now).
"',";
1556 $sql .=
" detail_refuse='".$this->db->escape($details).
"',";
1557 $sql .=
" fk_user_approve = NULL";
1558 $sql .=
" WHERE rowid = ".((int) $this->
id);
1559 if ($this->db->query($sql)) {
1560 $this->fk_statut = 99;
1562 $this->fk_user_refuse = $fuser->id;
1563 $this->detail_refuse = $details;
1564 $this->date_refuse = $now;
1568 $result = $this->
call_trigger(
'EXPENSE_REPORT_DENY', $fuser);
1576 if (empty($error)) {
1577 $this->db->commit();
1580 $this->db->rollback();
1581 $this->error = $this->db->error();
1585 $this->db->rollback();
1586 $this->error = $this->db->lasterror();
1590 dol_syslog(get_class($this).
"::setDeny expensereport already with refuse status", LOG_WARNING);
1609 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1610 return $this->
setUnpaid($fuser, $notrigger);
1627 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1628 $sql .=
" SET paid = 0, fk_statut = ".self::STATUS_APPROVED;
1629 $sql .=
" WHERE rowid = ".((int) $this->
id);
1631 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1633 if ($this->db->query($sql)) {
1636 $result = $this->
call_trigger(
'EXPENSE_REPORT_UNPAID', $fuser);
1644 if (empty($error)) {
1645 $this->db->commit();
1648 $this->db->rollback();
1649 $this->error = $this->db->error();
1653 $this->db->rollback();
1654 $this->error = $this->db->error();
1658 dol_syslog(get_class($this).
"::set_unpaid expensereport already with unpaid status", LOG_WARNING);
1677 $this->date_cancel = $this->db->idate(
dol_now());
1678 if ($this->
status != self::STATUS_CANCELED) {
1681 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1682 $sql .=
" SET fk_statut = ".self::STATUS_CANCELED.
", fk_user_cancel = ".((int) $fuser->id);
1683 $sql .=
", date_cancel='".$this->db->idate($this->date_cancel).
"'";
1684 $sql .=
", detail_cancel='".$this->db->escape($detail).
"'";
1685 $sql .=
" WHERE rowid = ".((int) $this->
id);
1687 dol_syslog(get_class($this).
"::set_cancel", LOG_DEBUG);
1689 if ($this->db->query($sql)) {
1692 $result = $this->
call_trigger(
'EXPENSE_REPORT_CANCEL', $fuser);
1700 if (empty($error)) {
1701 $this->db->commit();
1704 $this->db->rollback();
1705 $this->error = $this->db->error();
1709 $this->db->rollback();
1710 $this->error = $this->db->error();
1714 dol_syslog(get_class($this).
"::set_cancel expensereport already with cancel status", LOG_WARNING);
1726 global $langs,
$conf;
1727 $langs->load(
"trips");
1736 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1737 foreach ($dirmodels as $reldir) {
1738 $dir =
dol_buildpath($reldir.
"core/modules/expensereport/");
1741 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1749 $obj =
new $classname();
1750 '@phan-var-force ModeleNumRefExpenseReport $obj';
1751 $numref = $obj->getNextValue($this);
1753 if ($numref !=
"") {
1756 $this->error = $obj->error;
1757 $this->errors = $obj->errors;
1762 $this->error =
"Error_EXPENSEREPORT_ADDON_NotDefined";
1775 global
$conf, $langs;
1777 $langs->load(
'trips');
1779 $nofetch = !empty($params[
'nofetch']);
1780 $moretitle = $params[
'moretitle'] ??
'';
1783 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ExpenseReport").
'</u>';
1784 if (isset($this->
status)) {
1785 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1788 $datas[
'picto'] .=
' - '.$moretitle;
1790 if (!empty($this->
ref)) {
1791 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1793 if (!empty($this->total_ht)) {
1794 $datas[
'total_ht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1796 if (!empty($this->total_tva)) {
1797 $datas[
'total_tva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1799 if (!empty($this->total_ttc)) {
1800 $datas[
'total_ttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1818 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1820 global $langs, $hookmanager;
1824 $url = DOL_URL_ROOT.
'/expensereport/card.php?id='.$this->id;
1832 'objecttype' => $this->element,
1833 'option' => $option,
1834 'moretitle' => $moretitle,
1837 $classfortooltip =
'classfortooltip';
1840 $classfortooltip =
'classforajaxtooltip';
1841 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1847 if ($option !=
'nolink') {
1849 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1850 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1851 $add_save_lastsearch_values = 1;
1853 if ($add_save_lastsearch_values) {
1854 $url .=
'&save_lastsearch_values=1';
1864 if (empty($notooltip)) {
1866 $label = $langs->trans(
"ShowExpenseReport");
1867 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1869 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1870 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1873 $linkstart =
'<a href="'.$url.
'"';
1874 $linkstart .= $linkclose.
'>';
1877 $result .= $linkstart;
1879 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1881 if ($withpicto != 2) {
1882 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
1884 $result .= $linkend;
1887 $hookmanager->initHooks(array($this->element .
'dao'));
1888 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1889 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1891 $result = $hookmanager->resPrint;
1893 $result .= $hookmanager->resPrint;
1909 $this->total_ht += (float) $ligne_total_ht;
1910 $this->total_tva += (float) $ligne_total_tva;
1911 $this->total_ttc += $this->total_tva;
1913 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1914 $sql .=
" total_ht = ".((float) $this->total_ht);
1915 $sql .=
" , total_ttc = ".((float) $this->total_ttc);
1916 $sql .=
" , total_tva = ".((float) $this->total_tva);
1917 $sql .=
" WHERE rowid = ".((int) $this->
id);
1919 $result = $this->db->query($sql);
1923 $this->error = $this->db->error();
1943 public function addline($qty = 0, $up = 0, $fk_c_type_fees = 0, $vatrate = 0, $date =
'', $comments =
'', $fk_project = 0, $fk_c_exp_tax_cat = 0, $type = 0, $fk_ecm_files = 0)
1945 global $langs, $mysoc;
1947 dol_syslog(get_class($this).
"::addline qty=$qty, up=$up, fk_c_type_fees=$fk_c_type_fees, vatrate=$vatrate, date=$date, fk_project=$fk_project, type=$type, comments=$comments", LOG_DEBUG);
1949 if ($this->
status == self::STATUS_DRAFT || $this->
status == self::STATUS_REFUSED) {
1953 if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) {
1954 $fk_c_type_fees = 0;
1956 if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
1957 $fk_c_exp_tax_cat = 0;
1959 if (empty($vatrate) || $vatrate < 0) {
1965 if (empty($fk_project)) {
1970 if (!preg_match(
'/\s*\((.*)\)/', $vatrate)) {
1981 $seller->tva_assuj = 1;
1982 $buyer =
new Societe($this->db);
1988 if (preg_match(
'/\s*\((.*)\)/', $vatrate, $reg)) {
1989 $vat_src_code = $reg[1];
1990 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
1992 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
1994 $tmp =
calcul_price_total($qty, $up, 0, (
float)
price2num($vatrate), -1, -1, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
1996 $this->line->value_unit = $up;
1998 $this->line->vat_src_code = $vat_src_code;
1999 $this->line->vatrate =
price2num($vatrate);
2000 $this->line->localtax1_tx = $localtaxes_type[1];
2001 $this->line->localtax2_tx = $localtaxes_type[3];
2002 $this->line->localtax1_type = $localtaxes_type[0];
2003 $this->line->localtax2_type = $localtaxes_type[2];
2005 $this->line->total_ttc = (float) $tmp[2];
2006 $this->line->total_ht = (float) $tmp[0];
2007 $this->line->total_tva = (float) $tmp[1];
2008 $this->line->total_localtax1 = (float) $tmp[9];
2009 $this->line->total_localtax2 = (float) $tmp[10];
2011 $this->line->fk_expensereport = $this->id;
2012 $this->line->qty = $qty;
2013 $this->line->date = $date;
2014 $this->line->fk_c_type_fees = $fk_c_type_fees;
2015 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
2016 $this->line->comments = $comments;
2017 $this->line->fk_projet = $fk_project;
2018 $this->line->fk_project = $fk_project;
2020 $this->line->fk_ecm_files = $fk_ecm_files;
2025 $result = $this->line->insert(0,
true);
2029 $this->db->commit();
2030 return $this->line->id;
2032 $this->db->rollback();
2036 $this->error = $this->line->error;
2037 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2038 $this->db->rollback();
2042 dol_syslog(get_class($this).
"::addline status of expense report must be Draft to allow use of ->addline()", LOG_ERR);
2043 $this->error =
'ErrorExpenseNotDraftAndNotRefused';
2057 global
$conf, $db, $langs, $mysoc;
2059 $langs->load(
'trips');
2062 if (!is_object($seller)) {
2064 $seller->tva_assuj = 1;
2068 $rulestocheck = $expensereportrule->getAllRule($this->line->fk_c_type_fees, $this->line->date, $this->fk_user_author);
2071 $rule_warning_message_tab = array();
2073 $current_total_ttc = $this->line->total_ttc;
2074 $new_current_total_ttc = $this->line->total_ttc;
2077 foreach ($rulestocheck as $rule) {
2078 if (in_array($rule->code_expense_rules_type, array(
'EX_DAY',
'EX_MON',
'EX_YEA'))) {
2079 $amount_to_test = $this->line->getExpAmount($rule, $this->fk_user_author, $rule->code_expense_rules_type);
2081 $amount_to_test = $current_total_ttc;
2084 $amount_to_test = $amount_to_test - $current_total_ttc + $new_current_total_ttc;
2086 if ($amount_to_test > $rule->amount) {
2089 if ($rule->restrictive) {
2090 $this->error =
'ExpenseReportConstraintViolationError';
2091 $this->errors[] = $this->error;
2093 $new_current_total_ttc -= $amount_to_test - $rule->amount;
2094 $rule_warning_message_tab[] = $langs->trans(
'ExpenseReportConstraintViolationError', $rule->id,
price($amount_to_test, 0, $langs, 1, -1, -1,
$conf->currency),
price($rule->amount, 0, $langs, 1, -1, -1,
$conf->currency));
2096 $this->error =
'ExpenseReportConstraintViolationWarning';
2097 $this->errors[] = $this->error;
2099 $rule_warning_message_tab[] = $langs->trans(
'ExpenseReportConstraintViolationWarning', $rule->id,
price($amount_to_test, 0, $langs, 1, -1, -1,
$conf->currency),
price($rule->amount, 0, $langs, 1, -1, -1,
$conf->currency));
2106 $this->line->rule_warning_message = implode(
'\n', $rule_warning_message_tab);
2108 if ($violation > 0) {
2109 $tmp =
calcul_price_total($this->line->qty, $new_current_total_ttc / $this->line->qty, 0, $this->line->vatrate, 0, 0, 0,
'TTC', 0, $type, $seller);
2111 $this->line->value_unit = $tmp[5];
2112 $this->line->total_ttc = (float) $tmp[2];
2113 $this->line->total_ht = (float) $tmp[0];
2114 $this->line->total_tva = (float) $tmp[1];
2115 $this->line->total_localtax1 = (float) $tmp[9];
2116 $this->line->total_localtax2 = (float) $tmp[10];
2139 $userauthor =
new User($this->db);
2140 if ($userauthor->fetch($this->fk_user_author) <= 0) {
2141 $this->error =
'ErrorCantFetchUser';
2142 $this->errors[] =
'ErrorCantFetchUser';
2147 if (!is_object($seller)) {
2149 $seller->tva_assuj = 1;
2153 $range = $expenseik->getRangeByUser($userauthor, $this->line->fk_c_exp_tax_cat);
2155 if (empty($range)) {
2156 $this->error =
'ErrorNoRangeAvailable';
2157 $this->errors[] =
'ErrorNoRangeAvailable';
2162 $ikoffset = $range->ikoffset;
2164 $ikoffset = $range->ikoffset / 12;
2169 $new_up = $range->coef + ($ikoffset / $this->line->qty);
2170 $tmp =
calcul_price_total($this->line->qty, $new_up, 0, $this->line->vatrate, 0, 0, 0,
'TTC', 0, $type, $seller);
2172 $this->line->value_unit = $tmp[5];
2173 $this->line->total_ttc = (float) $tmp[2];
2174 $this->line->total_ht = (float) $tmp[0];
2175 $this->line->total_tva = (float) $tmp[1];
2176 $this->line->total_localtax1 = (float) $tmp[9];
2177 $this->line->total_localtax2 = (float) $tmp[10];
2192 $sql =
'SELECT e.rowid FROM '.MAIN_DB_PREFIX.
'expensereport e';
2193 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport_det d ON (e.rowid = d.fk_expensereport)";
2194 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = 'EX_KME')";
2195 $sql .=
" WHERE e.fk_user_author = ".(int) $this->fk_user_author;
2196 $sql .=
" AND YEAR(d.date) = '".dol_print_date($this->line->date,
'%Y').
"' AND MONTH(d.date) = '".
dol_print_date($this->line->date,
'%m').
"'";
2197 if (!empty($this->line->id)) {
2198 $sql .=
' AND d.rowid <> '.((int) $this->line->id);
2201 dol_syslog(get_class($this).
"::offsetAlreadyGiven");
2202 $resql = $this->db->query($sql);
2204 $num = $this->db->num_rows($resql);
2232 public function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat = 0, $fk_ecm_files = 0, $notrigger = 0)
2234 global $user, $mysoc;
2236 if ($this->
status == self::STATUS_DRAFT || $this->
status == self::STATUS_REFUSED) {
2244 $seller->tva_assuj = 1;
2245 $seller->localtax1_assuj = $mysoc->localtax1_assuj;
2246 $seller->localtax2_assuj = $mysoc->localtax1_assuj;
2247 $buyer =
new Societe($this->db);
2254 if (preg_match(
'/\((.*)\)/', (
string) $vatrate, $reg)) {
2255 $vat_src_code = $reg[1];
2256 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', (
string) $vatrate);
2258 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
2260 $tmp =
calcul_price_total($qty, $value_unit, 0, (
float)
price2num($vatrate), -1, -1, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
2264 $tx_tva = 1 + (float) $vatrate / 100;
2267 $this->line->comments = $comments;
2268 $this->line->qty = $qty;
2269 $this->line->value_unit = $value_unit;
2270 $this->line->date = $date;
2272 $this->line->fk_expensereport = $expensereport_id;
2273 $this->line->fk_c_type_fees = $type_fees_id;
2274 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
2275 $this->line->fk_projet = $projet_id;
2276 $this->line->fk_project = $projet_id;
2278 $this->line->vat_src_code = $vat_src_code;
2279 $this->line->vatrate =
price2num($vatrate);
2280 $this->line->localtax1_tx = $localtaxes_type[1];
2281 $this->line->localtax2_tx = $localtaxes_type[3];
2282 $this->line->localtax1_type = $localtaxes_type[0];
2283 $this->line->localtax2_type = $localtaxes_type[2];
2285 $this->line->total_ttc = (float) $tmp[2];
2286 $this->line->total_ht = (float) $tmp[0];
2287 $this->line->total_tva = (float) $tmp[1];
2288 $this->line->total_localtax1 = (float) $tmp[9];
2289 $this->line->total_localtax2 = (float) $tmp[10];
2291 $this->line->fk_ecm_files = $fk_ecm_files;
2293 $this->line->id = ((int) $rowid);
2296 $sql =
"SELECT c.code as code_type_fees, c.label as label_type_fees";
2297 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as c";
2298 $sql .=
" WHERE c.id = ".((int) $type_fees_id);
2299 $resql = $this->db->query($sql);
2301 $objp_fees = $this->db->fetch_object($resql);
2302 $this->line->type_fees_code = $objp_fees->code_type_fees;
2303 $this->line->type_fees_libelle = $objp_fees->label_type_fees;
2304 $this->db->free($resql);
2308 $sql =
"SELECT p.ref as ref_projet, p.title as title_projet";
2309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2310 $sql .=
" WHERE p.rowid = ".((int) $projet_id);
2311 $resql = $this->db->query($sql);
2313 $objp_projet = $this->db->fetch_object($resql);
2314 $this->line->projet_ref = $objp_projet->ref_projet;
2315 $this->line->projet_title = $objp_projet->title_projet;
2316 $this->db->free($resql);
2322 $result = $this->line->update($user, $notrigger);
2328 $this->db->commit();
2331 $this->error = $this->line->error;
2332 $this->errors = $this->line->errors;
2333 $this->db->rollback();
2357 $result = $this->
call_trigger(
'EXPENSE_REPORT_DET_DELETE', $fuser);
2364 $sql =
' DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2365 $sql .=
' WHERE rowid = '.((int) $rowid);
2367 dol_syslog(get_class($this).
"::deleteline sql=".$sql);
2368 $result = $this->db->query($sql);
2370 if (!$result || $error > 0) {
2371 $this->error = $this->db->error();
2372 dol_syslog(get_class($this).
"::deleteline Error ".$this->error, LOG_ERR);
2373 $this->db->rollback();
2379 $this->db->commit();
2396 $sql =
"SELECT rowid, date_debut, date_fin";
2397 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2398 $sql .=
" WHERE entity = ".((int)
$conf->entity);
2399 $sql .=
" AND fk_user_author = ".((int) $fuser->id);
2401 dol_syslog(get_class($this).
"::periodExists sql=".$sql);
2402 $result = $this->db->query($sql);
2404 $num_rows = $this->db->num_rows($result);
2407 if ($num_rows > 0) {
2408 $date_d_form = $date_debut;
2409 $date_f_form = $date_fin;
2411 while ($i < $num_rows) {
2412 $objp = $this->db->fetch_object($result);
2414 $date_d_req = $this->db->jdate($objp->date_debut);
2415 $date_f_req = $this->db->jdate($objp->date_fin);
2417 if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) {
2418 return $objp->rowid;
2429 $this->error = $this->db->lasterror();
2430 dol_syslog(get_class($this).
"::periodExists Error ".$this->error, LOG_ERR);
2446 $users_validator = array();
2448 $sql =
"SELECT DISTINCT ur.fk_user";
2449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2450 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2452 $sql .=
" SELECT DISTINCT ugu.fk_user";
2453 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2454 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2457 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport sql=".$sql);
2458 $result = $this->db->query($sql);
2460 $num_rows = $this->db->num_rows($result);
2462 while ($i < $num_rows) {
2463 $objp = $this->db->fetch_object($result);
2464 array_push($users_validator, $objp->fk_user);
2467 return $users_validator;
2469 $this->error = $this->db->lasterror();
2470 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport Error ".$this->error, LOG_ERR);
2486 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2488 $outputlangs->load(
"trips");
2491 if (!empty($this->model_pdf)) {
2492 $modele = $this->model_pdf;
2498 if (!empty($modele)) {
2499 $modelpath =
"core/modules/expensereport/doc/";
2501 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2517 $sql =
"SELECT id, code, label";
2518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
2519 $sql .=
" WHERE active = ".((int) $active);
2520 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
2521 $result = $this->db->query($sql);
2523 $num = $this->db->num_rows($result);
2526 $obj = $this->db->fetch_object($result);
2527 $ret[$obj->code] = (($langs->transnoentitiesnoconv($obj->code) != $obj->code) ? $langs->transnoentitiesnoconv($obj->code) : $obj->label);
2545 $this->nb = array();
2547 $sql =
"SELECT count(ex.rowid) as nb";
2548 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2549 $sql .=
" WHERE ex.fk_statut > 0";
2550 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2551 if (!$user->hasRight(
'expensereport',
'readall')) {
2552 $userchildids = $user->getAllChildIds(1);
2553 $sql .=
" AND (ex.fk_user_author IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2554 $sql .=
" OR ex.fk_user_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2557 $resql = $this->db->query($sql);
2559 while ($obj = $this->db->fetch_object($resql)) {
2560 $this->nb[
"expensereports"] = $obj->nb;
2562 $this->db->free($resql);
2566 $this->error = $this->db->error();
2582 global
$conf, $langs;
2590 $sql =
"SELECT ex.rowid, ex.date_valid";
2591 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2592 if ($option ==
'toapprove') {
2593 $sql .=
" WHERE ex.fk_statut = ".self::STATUS_VALIDATED;
2595 $sql .=
" WHERE ex.fk_statut = ".self::STATUS_APPROVED;
2597 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2598 if (!$user->hasRight(
'expensereport',
'readall')) {
2599 $userchildids = $user->getAllChildIds(1);
2600 $sql .=
" AND (ex.fk_user_author IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2601 $sql .=
" OR ex.fk_user_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2604 $resql = $this->db->query($sql);
2606 $langs->load(
"trips");
2609 if ($option ==
'toapprove') {
2610 $response->warning_delay =
$conf->expensereport->approve->warning_delay / 60 / 60 / 24;
2611 $response->label = $langs->trans(
"ExpenseReportsToApprove");
2612 $response->labelShort = $langs->trans(
"ToApprove");
2615 $response->warning_delay =
$conf->expensereport->payment->warning_delay / 60 / 60 / 24;
2616 $response->label = $langs->trans(
"ExpenseReportsToPay");
2617 $response->labelShort = $langs->trans(
"StatusToPay");
2618 $response->url = DOL_URL_ROOT.
'/expensereport/list.php?mainmenu=hrm&statut='.
self::STATUS_APPROVED;
2622 while ($obj = $this->db->fetch_object($resql)) {
2623 $response->nbtodo++;
2625 if ($option ==
'toapprove') {
2626 if ($this->db->jdate($obj->date_valid) < ($now -
$conf->expensereport->approve->warning_delay)) {
2627 $response->nbtodolate++;
2630 if ($this->db->jdate($obj->date_valid) < ($now -
$conf->expensereport->payment->warning_delay)) {
2631 $response->nbtodolate++;
2639 $this->error = $this->db->error();
2655 if ($option ==
'toapprove' && $this->
status != 2) {
2658 if ($option ==
'topay' && $this->
status != 5) {
2663 if ($option ==
'toapprove') {
2664 return (!empty($this->datevalid) ? $this->datevalid : $this->date_valid) < ($now -
$conf->expensereport->approve->warning_delay);
2666 return (!empty($this->datevalid) ? $this->datevalid : $this->date_valid) < ($now -
$conf->expensereport->payment->warning_delay);
2677 $alreadydispatched = 0;
2679 $type =
'expense_report';
2681 $sql =
" SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->
id);
2682 $resql = $this->db->query($sql);
2684 $obj = $this->db->fetch_object($resql);
2686 $alreadydispatched = $obj->nb;
2689 $this->error = $this->db->lasterror();
2693 if ($alreadydispatched) {
2706 $table =
'payment_expensereport';
2707 $field =
'fk_expensereport';
2709 $sql =
'SELECT sum(amount) as amount';
2710 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
2711 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
2713 dol_syslog(get_class($this).
"::getSumPayments", LOG_DEBUG);
2714 $resql = $this->db->query($sql);
2716 $obj = $this->db->fetch_object($resql);
2717 $this->db->free($resql);
2718 return (empty($obj->amount) ? 0 : $obj->amount);
2720 $this->error = $this->db->lasterror();
2735 global $langs, $db,
$conf;
2743 $this->error = $langs->trans(
'ErrorBadParameterCat');
2748 $this->error = $langs->trans(
'ErrorBadParameterQty');
2752 $currentUser =
new User($db);
2753 $currentUser->fetch($this->fk_user);
2754 $currentUser->loadRights(
'expensereport');
2758 $sql =
" SELECT r.range_ik, t.ikoffset, t.coef";
2759 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_ik t";
2760 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_exp_tax_range r ON r.rowid = t.fk_range";
2761 $sql .=
" WHERE t.fk_c_exp_tax_cat = ".(int) $fk_cat;
2762 $sql .=
" ORDER BY r.range_ik ASC";
2764 dol_syslog(
"expenseReport::computeTotalkm sql=".$sql, LOG_DEBUG);
2766 $result = $this->db->query($sql);
2769 if (
$conf->global->EXPENSEREPORT_CALCULATE_MILEAGE_EXPENSE_COEFFICIENT_ON_CURRENT_YEAR) {
2771 $sql =
" SELECT count(n.qty) as cumul FROM ".MAIN_DB_PREFIX.
"expensereport_det n";
2772 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport e ON e.rowid = n.fk_expensereport";
2773 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees tf ON tf.id = n.fk_c_type_fees";
2774 $sql .=
" WHERE e.fk_user_author = ".(int) $this->fk_user_author;
2775 $sql .=
" AND YEAR(n.date) = ".(int) $arrayDate[
'year'];
2776 $sql .=
" AND tf.code = 'EX_KME' ";
2779 $resql = $this->db->query($sql);
2782 $obj = $this->db->fetch_object($resql);
2783 $cumulYearQty = $obj->cumul;
2786 $qty += (float) $cumulYearQty;
2789 $num = $this->db->num_rows($result);
2792 for ($i = 0; $i < $num; $i++) {
2793 $obj = $this->db->fetch_object($result);
2797 '@phan-var-force Object[] $ranges';
2799 for ($i = 0; $i < $num; $i++) {
2800 if ($i < ($num - 1)) {
2802 if ($qty > $ranges[$i]->range_ik && $qty < $ranges[$i + 1]->range_ik) {
2803 $coef = $ranges[$i]->coef;
2804 $offset = $ranges[$i]->ikoffset;
2807 if ($qty > $ranges[$i]->range_ik) {
2808 $coef = $ranges[$i]->coef;
2809 $offset = $ranges[$i]->ikoffset;
2816 $this->error = $langs->trans(
'TaxUndefinedForThisCategory');
2820 $this->error = $this->db->error().
" sql=".$sql;
2837 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2839 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2840 $return .=
'<div class="info-box info-box-sm">';
2841 $return .=
'<span class="info-box-icon bg-infobox-action">';
2843 $return .=
'</span>';
2844 $return .=
'<div class="info-box-content">';
2845 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2846 if ($selected >= 0) {
2847 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2849 if (array_key_exists(
'userauthor', $arraydata) && $arraydata[
'userauthor'] instanceof
User) {
2850 $return .=
'<br><span class="info-box-label">'.$arraydata[
'userauthor']->getNomUrl(-1).
'</span>';
2852 if (property_exists($this,
'date_debut') && property_exists($this,
'date_fin')) {
2853 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->date_debut,
'day').
'</span>';
2854 $return .=
' <span class="opacitymedium">'.$langs->trans(
"To").
'</span> ';
2855 $return .=
'<span class="info-box-label">'.dol_print_date($this->date_fin,
'day').
'</span>';
2857 if (method_exists($this,
'getLibStatut')) {
2858 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2860 $return .=
'</div>';
2861 $return .=
'</div>';
2862 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Trips and Expenses.
setPaid($id, $fuser, $notrigger=0)
Classify the expense report as paid.
loadStateBoard()
Load the indicators this->nb for the state board.
__construct($db)
Constructor.
checkRules($type=0, $seller='')
Check constraint of rules and update price if needed.
updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id, $fk_c_exp_tax_cat=0, $fk_ecm_files=0, $notrigger=0)
Update an expense report line.
getNextNumRef()
Return next reference of expense report not already used.
createFromClone(User $user, $fk_user_author)
Load an object from its id and create a new one in database.
addline($qty=0, $up=0, $fk_c_type_fees=0, $vatrate=0, $date='', $comments='', $fk_project=0, $fk_c_exp_tax_cat=0, $type=0, $fk_ecm_files=0)
Add expense report line.
const STATUS_DRAFT
Draft status.
computeTotalKm($fk_cat, $qty, $tva)
Compute the cost of the kilometers expense based on the number of kilometers and the vehicle category...
periodExists($fuser, $date_debut, $date_fin)
periodExists
offsetAlreadyGiven()
If the sql find any rows then the ikoffset is already given (ikoffset is applied at the first expense...
listOfTypes($active=1)
List of types.
const STATUS_APPROVED
Classified approved.
set_save_from_refuse($fuser)
set_save_from_refuse
setValidate($fuser, $notrigger=0)
Set to status validate.
getSumPayments()
Return amount of payments already done.
getLibStatut($mode=0)
Returns the label status.
set_cancel($fuser, $detail, $notrigger=0)
set_cancel
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1)
Return clickable name (with picto eventually)
set_unpaid($fuser, $notrigger=0)
set_unpaid
info($id)
Load information on object.
getTooltipContentArray($params)
getTooltipContentArray
hasDelay($option)
Return if an expense report is late or not.
applyOffset($type=0, $seller='')
Method to apply the offset if needed.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
deleteLine($rowid, $fuser='', $notrigger=0)
deleteline
setDeny($fuser, $details, $notrigger=0)
setDeny
getVentilExportCompta()
Return if object was dispatched into bookkeeping.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with optional picto)
update($user, $notrigger=0, $userofexpensereport=null)
update
const STATUS_VALIDATED
Validated (need to be paid)
create($user, $notrigger=0)
Create object in database.
load_board($user, $option='topay')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
set_paid($id, $fuser, $notrigger=0)
Classify the expense report as paid.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
initAsSpecimen()
Initialise an instance with random values.
fetch_users_approver_expensereport()
Return list of people with permission to validate expense reports.
setApproved($fuser, $notrigger=0)
Set status to approved.
LibStatut($status, $mode=0)
Returns the label of a status.
setUnpaid($fuser, $notrigger=0)
set_unpaid
fetch_line_by_project($projectid, $user)
fetch_line_by_project
update_totaux_add($ligne_total_ht, $ligne_total_tva)
Update total of an expense report when you add a line.
Class to manage inventories.
Class of expense report details lines.
Class to manage inventories.
Class to manage third parties objects (customers, suppliers, prospects...)
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_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
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).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.