31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereportline.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_ik.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
45 public $element =
'expensereport';
50 public $table_element =
'expensereport';
55 public $table_element_line =
'expensereport_det';
60 public $class_element_line =
'ExpenseReportLine';
65 public $fk_element =
'fk_expensereport';
70 public $picto =
'trip';
75 public $lines = array();
95 public $date_approbation;
105 public $user_approve_id;
125 public $fk_c_paiement;
130 public $modepaymentid;
141 public $user_paid_infos;
146 public $user_author_infos;
151 public $user_validator_infos;
156 public $rule_warning_message;
169 public $fk_user_creat;
174 public $fk_user_author;
185 public $fk_user_modif;
196 public $detail_refuse;
201 public $fk_user_refuse;
212 public $detail_cancel;
217 public $fk_user_cancel;
222 public $fk_user_validator;
241 public $fk_user_valid;
246 public $user_valid_infos;
252 public $date_approve;
257 public $fk_user_approve;
300 public $fields = array(
301 'rowid' => array(
'type' =>
'integer',
'label' =>
'ID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
302 'ref' => array(
'type' =>
'varchar(50)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 15),
303 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 20),
304 'ref_number_int' => array(
'type' =>
'integer',
'label' =>
'Ref number int',
'enabled' => 1,
'visible' => -1,
'position' => 25),
305 'ref_ext' => array(
'type' =>
'integer',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 30),
306 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ht',
'enabled' => 1,
'visible' => -1,
'position' => 35),
307 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Total tva',
'enabled' => 1,
'visible' => -1,
'position' => 40),
308 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax1',
'enabled' => 1,
'visible' => -1,
'position' => 45),
309 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'Localtax2',
'enabled' => 1,
'visible' => -1,
'position' => 50),
310 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 55),
311 'date_debut' => array(
'type' =>
'date',
'label' =>
'Date debut',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 60),
312 'date_fin' => array(
'type' =>
'date',
'label' =>
'Date fin',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 65),
313 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'Date valid',
'enabled' => 1,
'visible' => -1,
'position' => 75),
314 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'Date approve',
'enabled' => 1,
'visible' => -1,
'position' => 80),
315 'date_refuse' => array(
'type' =>
'datetime',
'label' =>
'Date refuse',
'enabled' => 1,
'visible' => -1,
'position' => 85),
316 'date_cancel' => array(
'type' =>
'datetime',
'label' =>
'Date cancel',
'enabled' => 1,
'visible' => -1,
'position' => 90),
317 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 100),
318 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -1,
'position' => 105),
319 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 110),
320 'fk_user_validator' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 115),
321 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'ApprovedBy',
'enabled' => 1,
'visible' => -1,
'position' => 120),
322 'fk_user_refuse' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'REFUSEUR',
'enabled' => 1,
'visible' => -1,
'position' => 125),
323 'fk_user_cancel' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'CANCEL_USER',
'enabled' => 1,
'visible' => -1,
'position' => 130),
324 'fk_c_paiement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 140),
325 'paid' => array(
'type' =>
'integer',
'label' =>
'Paid',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 145),
326 'note_public' => array(
'type' =>
'html',
'label' =>
'Note public',
'enabled' => 1,
'visible' => 0,
'position' => 150),
327 'note_private' => array(
'type' =>
'html',
'label' =>
'Note private',
'enabled' => 1,
'visible' => 0,
'position' => 155),
328 'detail_refuse' => array(
'type' =>
'varchar(255)',
'label' =>
'Detail refuse',
'enabled' => 1,
'visible' => -1,
'position' => 160),
329 'detail_cancel' => array(
'type' =>
'varchar(255)',
'label' =>
'Detail cancel',
'enabled' => 1,
'visible' => -1,
'position' => 165),
330 'integration_compta' => array(
'type' =>
'integer',
'label' =>
'Integration compta',
'enabled' => 1,
'visible' => -1,
'position' => 170),
331 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' => 1,
'visible' => -1,
'position' => 175),
332 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Currency',
'enabled' => 1,
'visible' => -1,
'position' => 185),
333 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Multicurrency code',
'enabled' => 1,
'visible' => -1,
'position' => 190),
334 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency tx',
'enabled' => 1,
'visible' => -1,
'position' => 195),
335 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ht',
'enabled' => 1,
'visible' => -1,
'position' => 200),
336 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total tva',
'enabled' => 1,
'visible' => -1,
'position' => 205),
337 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'Multicurrency total ttc',
'enabled' => 1,
'visible' => -1,
'position' => 210),
338 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 220),
339 'date_create' => array(
'type' =>
'datetime',
'label' =>
'Date create',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 300),
340 'tms' => array(
'type' =>
'timestamp',
'label' =>
'Tms',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 305),
341 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -1,
'position' => 1000),
342 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 1010),
343 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 500),
355 $this->total_ttc = 0;
356 $this->total_tva = 0;
357 $this->total_localtax1 = 0;
358 $this->total_localtax2 = 0;
359 $this->localtax1 = 0;
360 $this->localtax2 = 0;
361 $this->modepaymentid = 0;
364 $this->labelStatusShort = array(0 =>
'Draft', 2 =>
'Validated', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
365 $this->labelStatus = array(0 =>
'Draft', 2 =>
'ValidatedWaitingApproval', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
367 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
377 public function create($user, $notrigger = 0)
379 global
$conf, $langs;
386 if (empty($this->date_debut) || empty($this->date_fin)) {
387 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Date'));
391 $fuserid = $this->fk_user_author;
392 if (empty($fuserid)) {
393 $fuserid = $user->id;
398 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
401 $sql .=
",total_ttc";
402 $sql .=
",total_tva";
403 $sql .=
",date_debut";
405 $sql .=
",date_create";
406 $sql .=
",fk_user_creat";
407 $sql .=
",fk_user_author";
408 $sql .=
",fk_user_validator";
409 $sql .=
",fk_user_approve";
410 $sql .=
",fk_user_modif";
411 $sql .=
",fk_statut";
412 $sql .=
",fk_c_paiement";
414 $sql .=
",note_public";
415 $sql .=
",note_private";
419 $sql .=
", ".price2num($this->total_ht,
'MT');
420 $sql .=
", ".price2num($this->total_ttc,
'MT');
421 $sql .=
", ".price2num($this->total_tva,
'MT');
422 $sql .=
", '".$this->db->idate($this->date_debut).
"'";
423 $sql .=
", '".$this->db->idate($this->date_fin).
"'";
424 $sql .=
", '".$this->db->idate($now).
"'";
425 $sql .=
", ".((int) $user->id);
426 $sql .=
", ".((int) $fuserid);
427 $sql .=
", ".($this->fk_user_validator > 0 ? ((int) $this->fk_user_validator) :
"null");
428 $sql .=
", ".($this->fk_user_approve > 0 ? ((int) $this->fk_user_approve) :
"null");
429 $sql .=
", ".($this->fk_user_modif > 0 ? ((int) $this->fk_user_modif) :
"null");
430 $sql .=
", ".($this->fk_statut > 1 ? ((int) $this->fk_statut) : 0);
431 $sql .=
", ".($this->modepaymentid ? ((int) $this->modepaymentid) :
"null");
433 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
434 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
435 $sql .=
", ".((int)
$conf->entity);
438 $result = $this->db->query($sql);
440 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
441 $this->
ref =
'(PROV'.$this->id.
')';
443 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
444 $resql = $this->db->query($sql);
446 $this->error = $this->db->lasterror();
451 if (is_array($this->lines) && count($this->lines) > 0) {
452 foreach ($this->lines as $line) {
455 if (!is_object($line)) {
456 $line = (object) $line;
458 $newndfline->fk_expensereport = $line->fk_expensereport;
459 $newndfline->fk_c_type_fees = $line->fk_c_type_fees;
460 $newndfline->fk_project = $line->fk_project;
461 $newndfline->vatrate = $line->vatrate;
462 $newndfline->vat_src_code = $line->vat_src_code;
463 $newndfline->localtax1_tx = $line->localtax1_tx;
464 $newndfline->localtax2_tx = $line->localtax2_tx;
465 $newndfline->localtax1_type = $line->localtax1_type;
466 $newndfline->localtax2_type = $line->localtax2_type;
467 $newndfline->comments = $line->comments;
468 $newndfline->qty = $line->qty;
469 $newndfline->value_unit = $line->value_unit;
470 $newndfline->total_ht = $line->total_ht;
471 $newndfline->total_ttc = $line->total_ttc;
472 $newndfline->total_tva = $line->total_tva;
473 $newndfline->total_localtax1 = $line->total_localtax1;
474 $newndfline->total_localtax2 = $line->total_localtax2;
475 $newndfline->date = $line->date;
476 $newndfline->rule_warning_message = $line->rule_warning_message;
477 $newndfline->fk_c_exp_tax_cat = $line->fk_c_exp_tax_cat;
478 $newndfline->fk_ecm_files = $line->fk_ecm_files;
483 $newndfline->fk_expensereport = $this->id;
484 $result = $newndfline->insert();
486 $this->error = $newndfline->error;
487 $this->errors = $newndfline->errors;
507 $result = $this->call_trigger(
'EXPENSE_REPORT_CREATE', $user);
519 $this->db->rollback();
523 $this->db->rollback();
527 dol_syslog(get_class($this).
"::create error ".$this->error, LOG_ERR);
528 $this->db->rollback();
532 $this->error = $this->db->lasterror().
" sql=".$sql;
533 $this->db->rollback();
551 if (empty($fk_user_author)) {
552 $fk_user_author = $user->id;
562 $objFrom = clone $this;
567 $this->fk_statut = 0;
570 $this->fk_user_creat = $user->id;
571 $this->fk_user_author = $fk_user_author;
572 $this->fk_user_valid = 0;
573 $this->fk_user_approve = 0;
574 $this->date_create =
'';
575 $this->date_creation =
'';
576 $this->date_validation =
'';
577 $this->date_approve =
'';
580 if (is_array($this->lines) && count($this->lines) > 0) {
581 foreach ($this->lines as $key => $line) {
582 $this->lines[$key]->fk_ecm_files = 0;
587 $this->context[
'createfromclone'] =
'createfromclone';
588 $result = $this->
create($user);
595 if (is_object($hookmanager)) {
596 $parameters = array(
'objFrom' => $objFrom);
598 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
606 unset($this->context[
'createfromclone']);
613 $this->db->rollback();
627 public function update($user, $notrigger = 0, $userofexpensereport =
null)
632 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
633 $sql .=
" total_ht = ".((float) $this->total_ht);
634 $sql .=
" , total_ttc = ".((float) $this->total_ttc);
635 $sql .=
" , total_tva = ".((float) $this->total_tva);
636 if (!empty($this->date_create)) {
637 $sql .=
" , date_create = '".$this->db->idate($this->date_create).
"'";
639 $sql .=
" , date_debut = '".$this->db->idate($this->date_debut).
"'";
640 $sql .=
" , date_fin = '".$this->db->idate($this->date_fin).
"'";
641 if ($userofexpensereport && is_object($userofexpensereport)) {
642 $sql .=
" , fk_user_author = ".($userofexpensereport->id > 0 ? (int) $userofexpensereport->id :
"null");
644 $sql .=
" , fk_user_validator = ".($this->fk_user_validator > 0 ? (int) $this->fk_user_validator :
"null");
645 $sql .=
" , fk_user_valid = ".($this->fk_user_valid > 0 ? (int) $this->fk_user_valid :
"null");
646 $sql .=
" , fk_user_approve = ".($this->fk_user_approve > 0 ? (int) $this->fk_user_approve :
"null");
647 $sql .=
" , fk_user_modif = ".((int) $user->id);
648 $sql .=
" , fk_statut = ".($this->fk_statut >= 0 ? (int) $this->fk_statut : 0);
649 $sql .=
" , fk_c_paiement = ".($this->fk_c_paiement > 0 ? (int) $this->fk_c_paiement :
"null");
650 $sql .=
" , note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"''");
651 $sql .=
" , note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"''");
652 $sql .=
" , detail_refuse = ".(!empty($this->detail_refuse) ?
"'".$this->db->escape($this->detail_refuse).
"'" :
"''");
653 $sql .=
" WHERE rowid = ".((int) $this->
id);
655 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
656 $result = $this->db->query($sql);
663 if (!$error && !$notrigger) {
665 $result = $this->call_trigger(
'EXPENSE_REPORT_MODIFY', $user);
676 $this->db->rollback();
677 $this->error = $this->db->error();
681 $this->db->rollback();
682 $this->error = $this->db->error();
694 public function fetch($id, $ref =
'')
696 $sql =
"SELECT d.rowid, d.entity, d.ref, d.note_public, d.note_private,";
697 $sql .=
" d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,";
698 $sql .=
" d.date_refuse, d.date_cancel,";
699 $sql .=
" d.total_ht, d.total_ttc, d.total_tva,";
700 $sql .=
" d.localtax1 as total_localtax1, d.localtax2 as total_localtax2,";
701 $sql .=
" d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,";
702 $sql .=
" d.fk_user_creat, d.fk_user_author, d.fk_user_modif, d.fk_user_validator,";
703 $sql .=
" d.fk_user_valid, d.fk_user_approve,";
704 $sql .=
" d.fk_statut as status, d.fk_c_paiement, d.paid";
705 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as d";
707 $sql .=
" WHERE d.ref = '".$this->db->escape($ref).
"'";
708 $sql .=
" AND d.entity IN (".getEntity(
'expensereport').
")";
710 $sql .=
" WHERE d.rowid = ".((int) $id);
714 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
715 $resql = $this->db->query($sql);
717 $obj = $this->db->fetch_object($resql);
719 $this->
id = $obj->rowid;
720 $this->
ref = $obj->ref;
722 $this->entity = $obj->entity;
724 $this->total_ht = $obj->total_ht;
725 $this->total_tva = $obj->total_tva;
726 $this->total_ttc = $obj->total_ttc;
727 $this->localtax1 = $obj->total_localtax1;
728 $this->localtax2 = $obj->total_localtax2;
729 $this->total_localtax1 = $obj->total_localtax1;
730 $this->total_localtax2 = $obj->total_localtax2;
732 $this->note_public = $obj->note_public;
733 $this->note_private = $obj->note_private;
734 $this->detail_refuse = $obj->detail_refuse;
735 $this->detail_cancel = $obj->detail_cancel;
737 $this->date_debut = $this->db->jdate($obj->date_debut);
738 $this->date_fin = $this->db->jdate($obj->date_fin);
739 $this->date_valid = $this->db->jdate($obj->date_valid);
740 $this->date_approve = $this->db->jdate($obj->date_approve);
741 $this->date_create = $this->db->jdate($obj->date_create);
742 $this->date_modif = $this->db->jdate($obj->date_modif);
743 $this->date_refuse = $this->db->jdate($obj->date_refuse);
744 $this->date_cancel = $this->db->jdate($obj->date_cancel);
746 $this->fk_user_creat = $obj->fk_user_creat;
747 $this->fk_user_author = $obj->fk_user_author;
748 $this->fk_user_modif = $obj->fk_user_modif;
749 $this->fk_user_validator = $obj->fk_user_validator;
750 $this->fk_user_valid = $obj->fk_user_valid;
751 $this->fk_user_refuse = $obj->fk_user_refuse;
752 $this->fk_user_cancel = $obj->fk_user_cancel;
753 $this->fk_user_approve = $obj->fk_user_approve;
755 $user_author =
new User($this->db);
756 if ($this->fk_user_author > 0) {
757 $user_author->fetch($this->fk_user_author);
760 $this->user_author_infos =
dolGetFirstLastname($user_author->firstname, $user_author->lastname);
762 $user_approver =
new User($this->db);
763 if ($this->fk_user_approve > 0) {
764 $user_approver->fetch($this->fk_user_approve);
765 } elseif ($this->fk_user_validator > 0) {
766 $user_approver->fetch($this->fk_user_validator);
768 $this->user_validator_infos =
dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
770 $this->fk_statut = (int) $obj->status;
771 $this->
status = (int) $obj->status;
772 $this->fk_c_paiement = $obj->fk_c_paiement;
773 $this->paid = $obj->paid;
775 if ($this->
status == self::STATUS_APPROVED || $this->
status == self::STATUS_CLOSED) {
776 $user_valid =
new User($this->db);
777 if ($this->fk_user_valid > 0) {
778 $user_valid->fetch($this->fk_user_valid);
780 $this->user_valid_infos =
dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
792 $this->error = $this->db->lasterror();
808 public function set_paid($id, $fuser, $notrigger = 0)
811 dol_syslog(get_class($this).
"::set_paid is deprecated, use setPaid instead", LOG_NOTICE);
812 return $this->
setPaid($id, $fuser, $notrigger);
823 public function setPaid($id, $fuser, $notrigger = 0)
828 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport";
829 $sql .=
" SET fk_statut = ".self::STATUS_CLOSED.
", paid = 1";
832 dol_syslog(get_class($this).
"::setPaid", LOG_DEBUG);
833 $resql = $this->db->query($sql);
835 if ($this->db->affected_rows($resql)) {
838 $result = $this->call_trigger(
'EXPENSE_REPORT_PAID', $fuser);
854 $this->db->rollback();
855 $this->error = $this->db->error();
863 $this->db->rollback();
864 dol_print_error($this->db);
887 $note = preg_replace(
'/(?:<br\s*\/?>|<\/(?:p|div|li)>)/i',
"\n", (
string) $this->note_public);
904 $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]);
905 $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
907 $statuslogo = array(0 =>
'status0', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
909 $statusType = $statuslogo[$status];
911 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
925 $sql =
"SELECT f.rowid,";
926 $sql .=
" f.date_create as datec,";
927 $sql .=
" f.tms as date_modification,";
928 $sql .=
" f.date_valid as datev,";
929 $sql .=
" f.date_approve as datea,";
930 $sql .=
" f.fk_user_creat as fk_user_creation,";
931 $sql .=
" f.fk_user_author as fk_user_author,";
932 $sql .=
" f.fk_user_modif as fk_user_modification,";
933 $sql .=
" f.fk_user_valid,";
934 $sql .=
" f.fk_user_approve";
935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as f";
936 $sql .=
" WHERE f.rowid = ".((int) $id);
937 $sql .=
" AND f.entity = ".((int)
$conf->entity);
941 $resql = $this->db->query($sql);
943 if ($this->db->num_rows($resql)) {
944 $obj = $this->db->fetch_object($resql);
946 $this->
id = $obj->rowid;
948 $this->date_creation = $this->db->jdate($obj->datec);
949 $this->date_modification = $this->db->jdate($obj->date_modification);
950 $this->date_validation = $this->db->jdate($obj->datev);
951 $this->date_approbation = $this->db->jdate($obj->datea);
953 $this->user_creation_id = $obj->fk_user_author;
954 $this->user_creation_id = $obj->fk_user_creation;
955 $this->user_validation_id = $obj->fk_user_valid;
956 $this->user_modification_id = $obj->fk_user_modification;
957 $this->user_approve_id = $obj->fk_user_approve;
959 $this->db->free($resql);
961 dol_print_error($this->db);
976 global $user, $langs;
982 $this->
ref =
'SPECIMEN';
985 $this->date_create = $now;
986 $this->date_debut = $now;
987 $this->date_fin = $now;
988 $this->date_valid = $now;
989 $this->date_approve = $now;
995 $this->fk_user_author = $user->id;
996 $this->fk_user_validator = $user->id;
997 $this->fk_user_valid = $user->id;
998 $this->fk_user_approve = $user->id;
1000 $this->note_private =
'Private note';
1001 $this->note_public =
'SPECIMEN';
1004 while ($xnbp < $nbp) {
1006 $line->comments = $langs->trans(
"Comment").
" ".$xnbp;
1007 $line->date = ($now - 3600 * (1 + $xnbp));
1008 $line->total_ht = 100;
1009 $line->total_tva = 20;
1010 $line->total_ttc = 120;
1012 $line->vatrate = 20;
1013 $line->value_unit = 120;
1014 $line->fk_expensereport = 0;
1015 $line->type_fees_code =
'TRA';
1016 $line->fk_c_type_fees = $type_fees_id;
1018 $line->projet_ref =
'ABC';
1020 $this->lines[$xnbp] = $line;
1023 $this->total_ht += $line->total_ht;
1024 $this->total_tva += $line->total_tva;
1025 $this->total_ttc += $line->total_ttc;
1044 $langs->load(
'trips');
1046 if ($user->hasRight(
'expensereport',
'lire')) {
1047 $sql =
"SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc";
1048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as de";
1049 $sql .=
" WHERE de.fk_projet = ".((int) $projectid);
1051 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1052 $result = $this->db->query($sql);
1054 $num = $this->db->num_rows($result);
1060 $objp = $this->db->fetch_object($result);
1062 $sql2 =
"SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut as status";
1063 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d";
1064 $sql2 .=
" WHERE d.rowid = ".((int) $objp->fk_expensereport);
1066 $result2 = $this->db->query($sql2);
1067 $obj = $this->db->fetch_object($result2);
1069 $objp->fk_user_author = $obj->fk_user_author;
1070 $objp->ref = $obj->ref;
1071 $objp->fk_c_expensereport_status = $obj->status;
1072 $objp->rowid = $obj->rowid;
1074 $total_HT += $objp->total_ht;
1075 $total_TTC += $objp->total_ttc;
1076 $author =
new User($this->db);
1077 $author->fetch($objp->fk_user_author);
1081 print
'<a href="'.dolBuildUrl(DOL_URL_ROOT.
'/expensereport/card.php', [
'id' => $objp->rowid]).
'">'.$objp->ref_num.
'</a>';
1083 print
'<td class="center">'.dol_print_date($objp->date,
'day').
'</td>';
1084 print
'<td>'.$author->getNomUrl(1).
'</td>';
1085 print
'<td>'.$objp->comments.
'</td>';
1086 print
'<td class="right">'.price($objp->total_ht).
'</td>';
1087 print
'<td class="right">'.price($objp->total_ttc).
'</td>';
1088 print
'<td class="right">';
1090 switch ($objp->fk_c_expensereport_status) {
1092 print img_picto($langs->trans(
'StatusOrderCanceled'),
'statut5');
1095 print $langs->trans(
'Draft').
' '.img_picto($langs->trans(
'Draft'),
'statut0');
1098 print $langs->trans(
'TripForValid').
' '.img_picto($langs->trans(
'TripForValid'),
'statut3');
1101 print $langs->trans(
'TripForPaid').
' '.img_picto($langs->trans(
'TripForPaid'),
'statut3');
1104 print $langs->trans(
'TripPaid').
' '.img_picto($langs->trans(
'TripPaid'),
'statut4');
1121 print
'<tr class="liste_total"><td colspan="4">'.$langs->trans(
"Number").
': '.$i.
'</td>';
1122 print
'<td class="right" width="100">'.$langs->trans(
"TotalHT").
' : '.
price($total_HT).
'</td>';
1123 print
'<td class="right" width="100">'.$langs->trans(
"TotalTTC").
' : '.
price($total_TTC).
'</td>';
1124 print
'<td> </td>';
1127 $this->error = $this->db->lasterror();
1144 $this->lines = array();
1146 $sql =
' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date, de.rang,';
1147 $sql .=
" de.".$this->db->sanitize($this->fk_element).
", de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project,";
1148 $sql .=
' de.tva_tx, de.vat_src_code,';
1149 $sql .=
' de.localtax1_tx, de.localtax2_tx, de.localtax1_type, de.localtax2_type,';
1150 $sql .=
' de.fk_ecm_files,';
1151 $sql .=
' de.total_ht, de.total_tva, de.total_ttc,';
1152 $sql .=
' de.total_localtax1, de.total_localtax2, de.rule_warning_message,';
1153 $sql .=
' ctf.code as code_type_fees, ctf.label as label_type_fees, ctf.accountancy_code as accountancy_code_type_fees,';
1154 $sql .=
' p.ref as ref_projet, p.title as title_projet';
1155 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->db->sanitize($this->table_element_line).
' as de';
1156 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
1157 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as p ON de.fk_projet = p.rowid';
1158 $sql .=
" WHERE de.".$this->db->sanitize($this->fk_element).
" = ".((int) $this->
id);
1160 $sql .=
' ORDER BY de.rang ASC, de.rowid ASC';
1162 $sql .=
' ORDER BY de.rang ASC, de.date ASC';
1165 $resql = $this->db->query($sql);
1167 $num = $this->db->num_rows($resql);
1170 $objp = $this->db->fetch_object($resql);
1174 $deplig->rowid = $objp->rowid;
1175 $deplig->id = $objp->rowid;
1176 $deplig->comments = $objp->comments;
1177 $deplig->qty = $objp->qty;
1178 $deplig->value_unit = $objp->value_unit;
1179 $deplig->date = $objp->date;
1180 $deplig->dates = $this->db->jdate($objp->date);
1182 $deplig->fk_expensereport = $objp->fk_expensereport;
1183 $deplig->fk_c_type_fees = $objp->fk_c_type_fees;
1184 $deplig->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat;
1185 $deplig->fk_projet = $objp->fk_project;
1186 $deplig->fk_project = $objp->fk_project;
1187 $deplig->fk_ecm_files = $objp->fk_ecm_files;
1189 $deplig->total_ht = $objp->total_ht;
1190 $deplig->total_tva = $objp->total_tva;
1191 $deplig->total_ttc = $objp->total_ttc;
1192 $deplig->total_localtax1 = $objp->total_localtax1;
1193 $deplig->total_localtax2 = $objp->total_localtax2;
1195 $deplig->type_fees_code = empty($objp->code_type_fees) ?
'TF_OTHER' : $objp->code_type_fees;
1196 $deplig->type_fees_libelle = $objp->label_type_fees;
1197 $deplig->type_fees_accountancy_code = $objp->accountancy_code_type_fees;
1199 $deplig->tva_tx = $objp->tva_tx;
1200 $deplig->vatrate = $objp->tva_tx;
1201 $deplig->vat_src_code = $objp->vat_src_code;
1202 $deplig->localtax1_tx = $objp->localtax1_tx;
1203 $deplig->localtax2_tx = $objp->localtax2_tx;
1204 $deplig->localtax1_type = $objp->localtax1_type;
1205 $deplig->localtax2_type = $objp->localtax2_type;
1207 $deplig->projet_ref = $objp->ref_projet;
1208 $deplig->projet_title = $objp->title_projet;
1210 $deplig->rule_warning_message = $objp->rule_warning_message;
1212 $deplig->rang = $objp->rang;
1214 $this->lines[$i] = $deplig;
1218 $this->db->free($resql);
1221 $this->error = $this->db->lasterror();
1222 dol_syslog(get_class($this).
"::fetch_lines: Error ".$this->error, LOG_ERR);
1235 public function delete($user =
null, $notrigger = 0)
1238 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1243 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"payment_expensereport WHERE fk_expensereport = ".((int) $this->
id);
1244 $resql = $this->db->query($sql);
1246 $this->error = $this->db->lasterror();
1249 $obj = $this->db->fetch_object($resql);
1250 if ($obj && $obj->nb > 0) {
1251 $this->error =
'ErrorRecordHasChildren';
1259 $result = $this->call_trigger(
'EXPENSE_REPORT_DELETE', $user);
1267 if (!$error && !empty($this->table_element_line)) {
1268 $tabletodelete = $this->table_element_line;
1270 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
1271 if (!$this->db->query($sql)) {
1273 $this->error = $this->db->lasterror();
1274 $this->errors[] = $this->error;
1275 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1300 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1306 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
1307 $res = $this->db->query($sql);
1310 $this->error = $this->db->lasterror();
1311 $this->errors[] = $this->error;
1312 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1328 if ($conf->expensereport->multidir_output[$this->entity] && !empty($this->
ref)) {
1329 $dir =
$conf->expensereport->multidir_output[$this->entity].
"/".$ref;
1330 $file = $dir.
"/".$ref.
".pdf";
1331 if (file_exists($file)) {
1335 $this->error =
'ErrorFailToDeleteFile';
1336 $this->errors[] = $this->error;
1337 $this->db->rollback();
1341 if (file_exists($dir)) {
1344 $this->error =
'ErrorFailToDeleteDir';
1345 $this->errors[] = $this->error;
1346 $this->db->rollback();
1354 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
1355 $this->db->commit();
1358 $this->db->rollback();
1372 global
$conf, $langs, $user;
1378 if ($this->
status == self::STATUS_VALIDATED) {
1379 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
1383 $this->date_valid = $now;
1386 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1389 $num = (string) $this->
ref;
1391 if (empty($num) || $num < 0) {
1400 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1401 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1402 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
1403 $sql .=
" date_valid = '".$this->db->idate($this->date_valid).
"',";
1404 $sql .=
" fk_user_valid = ".((int) $user->id);
1405 $sql .=
" WHERE rowid = ".((int) $this->
id);
1407 $resql = $this->db->query($sql);
1411 $result = $this->call_trigger(
'EXPENSE_REPORT_VALIDATE', $fuser);
1419 $this->oldref = $this->ref;
1422 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1423 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1426 $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).
"'";
1427 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'expensereport/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $this->entity);
1428 $resql = $this->db->query($sql);
1431 $this->error = $this->db->lasterror();
1433 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'expensereport/".$this->db->escape($this->newref).
"'";
1434 $sql .=
" WHERE filepath = 'expensereport/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1435 $resql = $this->db->query($sql);
1438 $this->error = $this->db->lasterror();
1444 $dirsource =
$conf->expensereport->multidir_output[$this->entity].
'/'.$oldref;
1445 $dirdest =
$conf->expensereport->multidir_output[$this->entity].
'/'.$newref;
1446 if (!$error && file_exists($dirsource)) {
1447 dol_syslog(get_class($this).
"::setValidate() rename dir ".$dirsource.
" into ".$dirdest);
1449 if (@rename($dirsource, $dirdest)) {
1452 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1453 foreach ($listoffiles as $fileentry) {
1454 $dirsource = $fileentry[
'name'];
1455 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1456 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1457 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1458 @rename($dirsource, $dirdest);
1471 if (empty($error)) {
1472 $this->db->commit();
1475 $this->db->rollback();
1476 $this->error = $this->db->error();
1480 $this->db->rollback();
1481 $this->error = $this->db->lasterror();
1497 $sql =
'SELECT date_debut';
1498 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element;
1499 $sql .=
" WHERE rowid = ".((int) $this->
id);
1501 $result = $this->db->query($sql);
1503 $objp = $this->db->fetch_object($result);
1505 $this->date_debut = $this->db->jdate($objp->date_debut);
1507 if ($this->
status != self::STATUS_VALIDATED) {
1508 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1509 $sql .=
" SET fk_statut = ".((int) self::STATUS_VALIDATED);
1510 $sql .=
" WHERE rowid = ".((int) $this->
id);
1512 dol_syslog(get_class($this).
"::set_save_from_refuse", LOG_DEBUG);
1514 if ($this->db->query($sql)) {
1517 $this->error = $this->db->lasterror();
1521 dol_syslog(get_class($this).
"::set_save_from_refuse expensereport already with save status", LOG_WARNING);
1539 if ($this->
status != self::STATUS_APPROVED) {
1541 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1542 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"', fk_statut = ".((int) self::STATUS_APPROVED).
", fk_user_approve = ".((int) $fuser->id).
",";
1543 $sql .=
" date_approve='".$this->db->idate($now).
"'";
1544 $sql .=
" WHERE rowid = ".((int) $this->
id);
1545 if ($this->db->query($sql)) {
1547 $this->date_approve = $now;
1548 $this->fk_user_approve = $fuser->id;
1551 $result = $this->call_trigger(
'EXPENSE_REPORT_APPROVE', $fuser);
1559 if (empty($error)) {
1560 $this->db->commit();
1563 $this->db->rollback();
1564 $this->error = $this->db->error();
1568 $this->db->rollback();
1569 $this->error = $this->db->lasterror();
1573 dol_syslog(get_class($this).
"::setApproved expensereport already with approve status", LOG_WARNING);
1587 public function setDeny($fuser, $details, $notrigger = 0)
1593 if ($this->
status != self::STATUS_REFUSED) {
1594 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1595 $sql .=
" SET ref = '".$this->db->escape($this->
ref).
"', fk_statut = ".self::STATUS_REFUSED.
", fk_user_refuse = ".((int) $fuser->id).
",";
1596 $sql .=
" date_refuse='".$this->db->idate($now).
"',";
1597 $sql .=
" detail_refuse='".$this->db->escape($details).
"',";
1598 $sql .=
" fk_user_approve = NULL";
1599 $sql .=
" WHERE rowid = ".((int) $this->
id);
1600 if ($this->db->query($sql)) {
1601 $this->fk_statut = 99;
1603 $this->fk_user_refuse = $fuser->id;
1604 $this->detail_refuse = $details;
1605 $this->date_refuse = $now;
1609 $result = $this->call_trigger(
'EXPENSE_REPORT_DENY', $fuser);
1617 if (empty($error)) {
1618 $this->db->commit();
1621 $this->db->rollback();
1622 $this->error = $this->db->error();
1626 $this->db->rollback();
1627 $this->error = $this->db->lasterror();
1631 dol_syslog(get_class($this).
"::setDeny expensereport already with refuse status", LOG_WARNING);
1650 dol_syslog(get_class($this).
"::set_unpaid is deprecated, use setUnpaid instead", LOG_NOTICE);
1651 return $this->
setUnpaid($fuser, $notrigger);
1668 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1669 $sql .=
" SET paid = 0, fk_statut = ".self::STATUS_APPROVED;
1670 $sql .=
" WHERE rowid = ".((int) $this->
id);
1672 dol_syslog(get_class($this).
"::set_unpaid", LOG_DEBUG);
1674 if ($this->db->query($sql)) {
1677 $result = $this->call_trigger(
'EXPENSE_REPORT_UNPAID', $fuser);
1685 if (empty($error)) {
1686 $this->db->commit();
1689 $this->db->rollback();
1690 $this->error = $this->db->error();
1694 $this->db->rollback();
1695 $this->error = $this->db->error();
1699 dol_syslog(get_class($this).
"::set_unpaid expensereport already with unpaid status", LOG_WARNING);
1718 $this->date_cancel =
dol_now();
1719 if ($this->
status != self::STATUS_CANCELED) {
1722 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1723 $sql .=
" SET fk_statut = ".((int) self::STATUS_CANCELED).
", fk_user_cancel = ".((int) $fuser->id);
1724 $sql .=
", date_cancel = '".$this->db->idate($this->date_cancel).
"'";
1725 $sql .=
", detail_cancel = '".$this->db->escape($detail).
"'";
1726 $sql .=
" WHERE rowid = ".((int) $this->
id);
1728 dol_syslog(get_class($this).
"::set_cancel", LOG_DEBUG);
1730 if ($this->db->query($sql)) {
1733 $result = $this->call_trigger(
'EXPENSE_REPORT_CANCEL', $fuser);
1741 if (empty($error)) {
1742 $this->db->commit();
1745 $this->db->rollback();
1746 $this->error = $this->db->error();
1750 $this->db->rollback();
1751 $this->error = $this->db->error();
1755 dol_syslog(get_class($this).
"::set_cancel expensereport already with cancel status", LOG_WARNING);
1767 global $langs,
$conf;
1768 $langs->load(
"trips");
1777 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1778 foreach ($dirmodels as $reldir) {
1779 $dir =
dol_buildpath($reldir.
"core/modules/expensereport/");
1782 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1786 dol_print_error(
null,
"Failed to include file ".$file);
1790 $obj =
new $classname();
1791 '@phan-var-force ModeleNumRefExpenseReport $obj';
1792 $numref = $obj->getNextValue($this);
1794 if ($numref !=
"") {
1797 $this->error = $obj->error;
1798 $this->errors = $obj->errors;
1803 $this->error =
"Error_EXPENSEREPORT_ADDON_NotDefined";
1816 global
$conf, $langs;
1818 $langs->load(
'trips');
1820 $nofetch = !empty($params[
'nofetch']);
1821 $moretitle = $params[
'moretitle'] ??
'';
1824 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ExpenseReport").
'</u>';
1825 if (isset($this->
status)) {
1826 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1829 $datas[
'picto'] .=
' - '.$moretitle;
1831 if (!empty($this->
ref)) {
1832 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1834 if (!empty($this->total_ht)) {
1835 $datas[
'total_ht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1837 if (!empty($this->total_tva)) {
1838 $datas[
'total_tva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1840 if (!empty($this->total_ttc)) {
1841 $datas[
'total_ttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1859 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1861 global $langs, $hookmanager;
1865 $baseurl = DOL_URL_ROOT.
'/expensereport/card.php';
1866 $query = [
'id' => $this->id];
1874 'objecttype' => $this->element,
1875 'option' => $option,
1876 'moretitle' => $moretitle,
1879 $classfortooltip =
'classfortooltip';
1882 $classfortooltip =
'classforajaxtooltip';
1883 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1889 if ($option !=
'nolink') {
1891 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1892 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1893 $add_save_lastsearch_values = 1;
1895 if ($add_save_lastsearch_values) {
1896 $query += [
'save_lastsearch_values' => 1];
1907 if (empty($notooltip)) {
1909 $label = $langs->trans(
"ShowExpenseReport");
1910 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1912 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1913 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1916 $linkstart =
'<a href="'.$url.
'"';
1917 $linkstart .= $linkclose.
'>';
1920 $result .= $linkstart;
1922 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1924 if ($withpicto != 2) {
1925 $result .= ($max ?
dol_trunc($ref, $max) : $ref);
1927 $result .= $linkend;
1930 $hookmanager->initHooks(array($this->element .
'dao'));
1931 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1932 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1934 $result = $hookmanager->resPrint;
1936 $result .= $hookmanager->resPrint;
1952 $this->total_ht += (float) $ligne_total_ht;
1953 $this->total_tva += (float) $ligne_total_tva;
1954 $this->total_ttc += $this->total_tva;
1956 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1957 $sql .=
" total_ht = ".((float) $this->total_ht);
1958 $sql .=
" , total_ttc = ".((float) $this->total_ttc);
1959 $sql .=
" , total_tva = ".((float) $this->total_tva);
1960 $sql .=
" WHERE rowid = ".((int) $this->
id);
1962 $result = $this->db->query($sql);
1966 $this->error = $this->db->error();
1986 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)
1990 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);
1992 if ($this->
status == self::STATUS_DRAFT || $this->
status == self::STATUS_REFUSED) {
1996 if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) {
1997 $fk_c_type_fees = 0;
1999 if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
2000 $fk_c_exp_tax_cat = 0;
2002 if (empty($vatrate) || $vatrate < 0) {
2008 if (empty($fk_project)) {
2013 if (!preg_match(
'/\s*\((.*)\)/', $vatrate)) {
2024 $seller->tva_assuj = 1;
2025 $buyer =
new Societe($this->db);
2031 if (preg_match(
'/\s*\((.*)\)/', $vatrate, $reg)) {
2032 $vat_src_code = $reg[1];
2033 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2035 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
2037 $tmp =
calcul_price_total($qty, (
float) $up, 0, (
float)
price2num($vatrate), -1, -1, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
2039 $this->line->value_unit = $up;
2041 $this->line->vat_src_code = $vat_src_code;
2042 $this->line->vatrate =
price2num($vatrate);
2043 $this->line->localtax1_tx = $localtaxes_type[1];
2044 $this->line->localtax2_tx = $localtaxes_type[3];
2045 $this->line->localtax1_type = $localtaxes_type[0];
2046 $this->line->localtax2_type = $localtaxes_type[2];
2048 $this->line->total_ttc = (float) $tmp[2];
2049 $this->line->total_ht = (float) $tmp[0];
2050 $this->line->total_tva = (float) $tmp[1];
2051 $this->line->total_localtax1 = (float) $tmp[9];
2052 $this->line->total_localtax2 = (float) $tmp[10];
2054 $this->line->fk_expensereport = $this->id;
2055 $this->line->qty = $qty;
2056 $this->line->date = $date;
2057 $this->line->fk_c_type_fees = $fk_c_type_fees;
2058 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
2059 $this->line->comments = $comments;
2060 $this->line->fk_projet = $fk_project;
2061 $this->line->fk_project = $fk_project;
2063 $this->line->fk_ecm_files = $fk_ecm_files;
2068 $result = $this->line->insert(0,
true);
2072 $this->db->commit();
2073 return $this->line->id;
2075 $this->db->rollback();
2079 $this->error = $this->line->error;
2080 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2081 $this->db->rollback();
2085 dol_syslog(get_class($this).
"::addline status of expense report must be Draft to allow use of ->addline()", LOG_ERR);
2086 $this->error =
'ErrorExpenseNotDraftAndNotRefused';
2102 $langs->load(
'trips');
2105 if (!is_object($seller)) {
2107 $seller->tva_assuj = 1;
2111 $rulestocheck = $expensereportrule->getAllRule($this->line->fk_c_type_fees, $this->line->date, $this->fk_user_author);
2114 $rule_warning_message_tab = array();
2116 $current_total_ttc = $this->line->total_ttc;
2117 $new_current_total_ttc = $this->line->total_ttc;
2120 foreach ($rulestocheck as $rule) {
2121 if (in_array($rule->code_expense_rules_type, array(
'EX_DAY',
'EX_MON',
'EX_YEA'))) {
2122 $amount_to_test = $this->line->getExpAmount($rule, $this->fk_user_author, $rule->code_expense_rules_type);
2124 $amount_to_test = $current_total_ttc;
2127 $amount_to_test = $amount_to_test - $current_total_ttc + $new_current_total_ttc;
2129 if ($amount_to_test > $rule->amount) {
2132 if ($rule->restrictive) {
2133 $this->error =
'ExpenseReportConstraintViolationError';
2134 $this->errors[] = $this->error;
2136 $new_current_total_ttc -= $amount_to_test - $rule->amount;
2137 $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));
2139 $this->error =
'ExpenseReportConstraintViolationWarning';
2140 $this->errors[] = $this->error;
2142 $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));
2149 $this->line->rule_warning_message = implode(
'\n', $rule_warning_message_tab);
2151 if ($violation > 0) {
2152 $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);
2154 $this->line->value_unit = $tmp[5];
2155 $this->line->total_ttc = (float) $tmp[2];
2156 $this->line->total_ht = (float) $tmp[0];
2157 $this->line->total_tva = (float) $tmp[1];
2158 $this->line->total_localtax1 = (float) $tmp[9];
2159 $this->line->total_localtax2 = (float) $tmp[10];
2182 $userauthor =
new User($this->db);
2183 if ($userauthor->fetch($this->fk_user_author) <= 0) {
2184 $this->error =
'ErrorCantFetchUser';
2185 $this->errors[] =
'ErrorCantFetchUser';
2190 if (!is_object($seller)) {
2192 $seller->tva_assuj = 1;
2196 $range = $expenseik->getRangeByUser($userauthor, $this->line->fk_c_exp_tax_cat);
2198 if (empty($range)) {
2199 $this->error =
'ErrorNoRangeAvailable';
2200 $this->errors[] =
'ErrorNoRangeAvailable';
2205 $ikoffset = $range->ikoffset;
2207 $ikoffset = $range->ikoffset / 12;
2212 $new_up = $range->coef + ($ikoffset / $this->line->qty);
2213 $tmp =
calcul_price_total($this->line->qty, $new_up, 0, $this->line->vatrate, 0, 0, 0,
'TTC', 0, $type, $seller);
2215 $this->line->value_unit = $tmp[5];
2216 $this->line->total_ttc = (float) $tmp[2];
2217 $this->line->total_ht = (float) $tmp[0];
2218 $this->line->total_tva = (float) $tmp[1];
2219 $this->line->total_localtax1 = (float) $tmp[9];
2220 $this->line->total_localtax2 = (float) $tmp[10];
2235 $sql =
'SELECT e.rowid FROM '.MAIN_DB_PREFIX.
'expensereport e';
2236 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"expensereport_det d ON (e.rowid = d.fk_expensereport)";
2237 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = 'EX_KME')";
2238 $sql .=
" WHERE e.fk_user_author = ".(int) $this->fk_user_author;
2239 $sql .=
" AND YEAR(d.date) = '".dol_print_date($this->line->date,
'%Y').
"' AND MONTH(d.date) = '".
dol_print_date($this->line->date,
'%m').
"'";
2240 if (!empty($this->line->id)) {
2241 $sql .=
' AND d.rowid <> '.((int) $this->line->id);
2244 dol_syslog(get_class($this).
"::offsetAlreadyGiven");
2245 $resql = $this->db->query($sql);
2247 $num = $this->db->num_rows($resql);
2252 dol_print_error($this->db);
2275 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)
2280 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2284 if ($this->
status == self::STATUS_DRAFT || $this->
status == self::STATUS_REFUSED) {
2292 $seller->tva_assuj = 1;
2293 $seller->localtax1_assuj =
$mysoc->localtax1_assuj;
2294 $seller->localtax2_assuj =
$mysoc->localtax1_assuj;
2295 $buyer =
new Societe($this->db);
2302 if (preg_match(
'/\((.*)\)/', (
string) $vatrate, $reg)) {
2303 $vat_src_code = $reg[1];
2304 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', (
string) $vatrate);
2306 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
2308 $tmp =
calcul_price_total($qty, $value_unit, 0, (
float)
price2num($vatrate), -1, -1, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
2312 $tx_tva = 1 + (float) $vatrate / 100;
2315 $this->line->comments = $comments;
2316 $this->line->qty = $qty;
2317 $this->line->value_unit = $value_unit;
2318 $this->line->date = $date;
2320 $this->line->fk_expensereport = $expensereport_id;
2321 $this->line->fk_c_type_fees = $type_fees_id;
2322 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
2323 $this->line->fk_projet = $projet_id;
2324 $this->line->fk_project = $projet_id;
2326 $this->line->vat_src_code = $vat_src_code;
2327 $this->line->vatrate =
price2num($vatrate);
2328 $this->line->localtax1_tx = $localtaxes_type[1];
2329 $this->line->localtax2_tx = $localtaxes_type[3];
2330 $this->line->localtax1_type = $localtaxes_type[0];
2331 $this->line->localtax2_type = $localtaxes_type[2];
2333 $this->line->total_ttc = (float) $tmp[2];
2334 $this->line->total_ht = (float) $tmp[0];
2335 $this->line->total_tva = (float) $tmp[1];
2336 $this->line->total_localtax1 = (float) $tmp[9];
2337 $this->line->total_localtax2 = (float) $tmp[10];
2339 $this->line->fk_ecm_files = $fk_ecm_files;
2341 $this->line->id = ((int) $rowid);
2344 $sql =
"SELECT c.code as code_type_fees, c.label as label_type_fees";
2345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as c";
2346 $sql .=
" WHERE c.id = ".((int) $type_fees_id);
2347 $resql = $this->db->query($sql);
2349 $objp_fees = $this->db->fetch_object($resql);
2350 $this->line->type_fees_code = $objp_fees->code_type_fees;
2351 $this->line->type_fees_libelle = $objp_fees->label_type_fees;
2352 $this->db->free($resql);
2355 if ($projet_id > 0) {
2357 $sql =
"SELECT p.ref as ref_projet, p.title as title_projet";
2358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2359 $sql .=
" WHERE p.rowid = ".((int) $projet_id);
2360 $resql = $this->db->query($sql);
2362 if ($this->db->num_rows($resql) > 0) {
2363 $objp_projet = $this->db->fetch_object($resql);
2364 $this->line->projet_ref = $objp_projet->ref_projet;
2365 $this->line->projet_title = $objp_projet->title_projet;
2367 $this->db->free($resql);
2373 $result = $this->line->update($user, $notrigger);
2379 $this->db->commit();
2382 $this->error = $this->line->error;
2383 $this->errors = $this->line->errors;
2384 $this->db->rollback();
2400 public function deleteLine($rowid, $fuser =
null, $notrigger = 0)
2404 if ($this->
id > 0) {
2406 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
2407 $sql .=
" WHERE rowid = ".((int) $rowid).
" AND fk_expensereport = ".((int) $this->
id);
2408 $resql = $this->db->query($sql);
2409 if (!$resql || !$this->db->num_rows($resql)) {
2410 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2419 $result = $this->call_trigger(
'EXPENSE_REPORT_DET_DELETE', $fuser);
2426 $sql =
' DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2427 $sql .=
' WHERE rowid = '.((int) $rowid);
2429 dol_syslog(get_class($this).
"::deleteline sql=".$sql);
2430 $result = $this->db->query($sql);
2432 if (!$result || $error > 0) {
2433 $this->error = $this->db->error();
2434 dol_syslog(get_class($this).
"::deleteline Error ".$this->error, LOG_ERR);
2435 $this->db->rollback();
2441 $this->db->commit();
2458 $sql =
"SELECT rowid, date_debut, date_fin";
2459 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2460 $sql .=
" WHERE entity = ".((int)
$conf->entity);
2461 $sql .=
" AND fk_user_author = ".((int) $fuser->id);
2462 $sql .=
" AND (date_fin >= '".$this->db->idate($startDate).
"' AND date_debut <= '".$this->db->idate($endDate).
"')";
2464 $row = $this->db->getRow($sql);
2466 if ($row ===
false) {
2467 $this->error = $this->db->lasterror();
2468 dol_syslog(__CLASS__.
"::". __METHOD__.
" Error ".$this->error, LOG_ERR);
2472 return $row->rowid ?? 0;
2486 $users_validator = array();
2488 $sql =
"SELECT DISTINCT ur.fk_user";
2489 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2490 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2492 $sql .=
" SELECT DISTINCT ugu.fk_user";
2493 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2494 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2497 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport sql=".$sql);
2498 $result = $this->db->query($sql);
2500 $num_rows = $this->db->num_rows($result);
2502 while ($i < $num_rows) {
2503 $objp = $this->db->fetch_object($result);
2504 array_push($users_validator, $objp->fk_user);
2507 return $users_validator;
2509 $this->error = $this->db->lasterror();
2510 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport Error ".$this->error, LOG_ERR);
2526 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2528 $outputlangs->load(
"trips");
2531 if (!empty($this->model_pdf)) {
2532 $modele = $this->model_pdf;
2538 if (!empty($modele)) {
2539 $modelpath =
"core/modules/expensereport/doc/";
2541 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2557 $sql =
"SELECT id, code, label";
2558 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
2559 $sql .=
" WHERE active = ".((int) $active);
2560 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
2561 $result = $this->db->query($sql);
2563 $num = $this->db->num_rows($result);
2566 $obj = $this->db->fetch_object($result);
2567 $ret[$obj->code] = (($langs->transnoentitiesnoconv($obj->code) != $obj->code) ? $langs->transnoentitiesnoconv($obj->code) : $obj->label);
2571 dol_print_error($this->db);
2585 $this->nb = array();
2587 $sql =
"SELECT count(ex.rowid) as nb";
2588 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2589 $sql .=
" WHERE ex.fk_statut > 0";
2590 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2591 if (!$user->hasRight(
'expensereport',
'readall')) {
2592 $userchildids = $user->getAllChildIds(1);
2593 $sql .=
" AND (ex.fk_user_author IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2594 $sql .=
" OR ex.fk_user_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2597 $resql = $this->db->query($sql);
2599 while ($obj = $this->db->fetch_object($resql)) {
2600 $this->nb[
"expensereports"] = $obj->nb;
2602 $this->db->free($resql);
2605 dol_print_error($this->db);
2606 $this->error = $this->db->error();
2622 global
$conf, $langs;
2629 $warning_delay = ($option ==
'toapprove' ?
$conf->expensereport->approve->warning_delay :
$conf->expensereport->payment->warning_delay);
2634 $sql =
"SELECT COUNT(ex.rowid) as nb,";
2635 $sql .=
" SUM(CASE WHEN ex.date_valid IS NULL OR ex.date_valid < '".$this->db->idate($now - $warning_delay).
"' THEN 1 ELSE 0 END) as nblate";
2636 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2637 if ($option ==
'toapprove') {
2638 $sql .=
" WHERE ex.fk_statut = ".self::STATUS_VALIDATED;
2640 $sql .=
" WHERE ex.fk_statut = ".self::STATUS_APPROVED;
2642 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2643 if (!$user->hasRight(
'expensereport',
'readall')) {
2644 $userchildids = $user->getAllChildIds(1);
2645 $sql .=
" AND (ex.fk_user_author IN (".$this->db->sanitize(implode(
',', $userchildids)).
")";
2646 $sql .=
" OR ex.fk_user_validator IN (".$this->db->sanitize(implode(
',', $userchildids)).
"))";
2649 $resql = $this->db->query($sql);
2651 $langs->load(
"trips");
2654 if ($option ==
'toapprove') {
2655 $response->warning_delay =
$conf->expensereport->approve->warning_delay / 60 / 60 / 24;
2656 $response->label = $langs->trans(
"ExpenseReportsToApprove");
2657 $response->labelShort = $langs->trans(
"ToApprove");
2658 $response->url =
dolBuildUrl(DOL_URL_ROOT.
'/expensereport/list.php', [
'mainmenu' =>
'hrm',
'statut' => self::STATUS_VALIDATED]);
2660 $response->warning_delay =
$conf->expensereport->payment->warning_delay / 60 / 60 / 24;
2661 $response->label = $langs->trans(
"ExpenseReportsToPay");
2662 $response->labelShort = $langs->trans(
"StatusToPay");
2663 $response->url =
dolBuildUrl(DOL_URL_ROOT.
'/expensereport/list.php', [
'mainmenu' =>
'hrm',
'statut' => self::STATUS_APPROVED]);
2665 $response->img = img_object(
'',
"trip");
2667 $obj = $this->db->fetch_object($resql);
2669 $response->nbtodo = (int) $obj->nb;
2670 $response->nbtodolate = (int) $obj->nblate;
2675 dol_print_error($this->db);
2676 $this->error = $this->db->error();
2692 if ($option ==
'toapprove' && $this->
status != 2) {
2695 if ($option ==
'topay' && $this->
status != 5) {
2700 $warning_delay = (int) ($option ==
'toapprove' ?
$conf->expensereport->approve->warning_delay :
$conf->expensereport->payment->warning_delay);
2701 if ($warning_delay <= 0) {
2705 return (!empty($this->datevalid) ? $this->datevalid : $this->date_valid) < ($now - $warning_delay);
2716 $alreadydispatched = 0;
2718 $type =
'expense_report';
2720 $sql =
" SELECT ".($mode ?
'DISTINCT piece_num' :
'COUNT(ab.rowid)').
" as nb";
2721 $sql .=
" FROM ".MAIN_DB_PREFIX.
"accounting_bookkeeping as ab WHERE ab.doc_type = '".$this->db->escape($type).
"' AND ab.fk_doc = ".((int) $this->
id);
2722 $resql = $this->db->query($sql);
2724 $obj = $this->db->fetch_object($resql);
2726 $alreadydispatched = $obj->nb;
2729 $this->error = $this->db->lasterror();
2733 if ($alreadydispatched) {
2734 return $alreadydispatched;
2746 $table =
'payment_expensereport';
2747 $field =
'fk_expensereport';
2749 $sql =
'SELECT sum(amount) as amount';
2750 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
2751 $sql .=
" WHERE ".$this->db->sanitize($field).
" = ".((int) $this->
id);
2753 dol_syslog(get_class($this).
"::getSumPayments", LOG_DEBUG);
2754 $resql = $this->db->query($sql);
2756 $obj = $this->db->fetch_object($resql);
2757 $this->db->free($resql);
2758 return (empty($obj->amount) ? 0 : $obj->amount);
2760 $this->error = $this->db->lasterror();
2775 global $langs,
$conf;
2783 $this->error = $langs->trans(
'ErrorBadParameterCat');
2788 $this->error = $langs->trans(
'ErrorBadParameterQty');
2792 $currentUser =
new User($this->db);
2793 $currentUser->fetch($this->fk_user);
2794 $currentUser->loadRights(
'expensereport');
2798 $sql =
" SELECT r.range_ik, t.ikoffset, t.coef";
2799 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_ik t";
2800 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_exp_tax_range r ON r.rowid = t.fk_range";
2801 $sql .=
" WHERE t.fk_c_exp_tax_cat = ".(int) $fk_cat;
2802 $sql .=
" ORDER BY r.range_ik ASC";
2804 dol_syslog(
"expenseReport::computeTotalkm sql=".$sql, LOG_DEBUG);
2806 $result = $this->db->query($sql);
2809 if (
getDolGlobalInt(
'EXPENSEREPORT_CALCULATE_MILEAGE_EXPENSE_COEFFICIENT_ON_CURRENT_YEAR')) {
2811 $sql =
" SELECT count(n.qty) as cumul FROM ".MAIN_DB_PREFIX.
"expensereport_det n";
2812 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"expensereport e ON e.rowid = n.fk_expensereport";
2813 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_type_fees tf ON tf.id = n.fk_c_type_fees";
2814 $sql .=
" WHERE e.fk_user_author = ".(int) $this->fk_user_author;
2815 $sql .=
" AND YEAR(n.date) = ".(int) $arrayDate[
'year'];
2816 $sql .=
" AND tf.code = 'EX_KME' ";
2819 $resql = $this->db->query($sql);
2822 $obj = $this->db->fetch_object($resql);
2823 $cumulYearQty = $obj->cumul;
2826 $qty += (float) $cumulYearQty;
2829 $num = $this->db->num_rows($result);
2832 for ($i = 0; $i < $num; $i++) {
2833 $obj = $this->db->fetch_object($result);
2837 '@phan-var-force Object[] $ranges';
2839 for ($i = 0; $i < $num; $i++) {
2840 if ($i < ($num - 1)) {
2842 if ($qty > $ranges[$i]->range_ik && $qty < $ranges[$i + 1]->range_ik) {
2843 $coef = $ranges[$i]->coef;
2844 $offset = $ranges[$i]->ikoffset;
2847 if ($qty > $ranges[$i]->range_ik) {
2848 $coef = $ranges[$i]->coef;
2849 $offset = $ranges[$i]->ikoffset;
2856 $this->error = $langs->trans(
'TaxUndefinedForThisCategory');
2860 $this->error = $this->db->error().
" sql=".$sql;
2877 if ($arraydata ===
null) {
2878 $arraydata = array();
2881 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2883 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2884 $return .=
'<div class="info-box info-box-sm">';
2885 $return .=
'<span class="info-box-icon bg-infobox-action">';
2886 $return .= img_picto(
'', $this->picto);
2887 $return .=
'</span>';
2888 $return .=
'<div class="info-box-content">';
2889 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(1) .
'</span>';
2890 if ($selected >= 0) {
2891 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2893 if (array_key_exists(
'userauthor', $arraydata) && $arraydata[
'userauthor'] instanceof
User) {
2894 $return .=
'<br><span class="info-box-label">'.$arraydata[
'userauthor']->getNomUrl(-1).
'</span>';
2897 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->date_debut,
'day').
'</span>';
2898 $return .=
' <span class="opacitymedium">'.$langs->trans(
"To").
'</span> ';
2899 $return .=
'<span class="info-box-label">'.dol_print_date($this->date_fin,
'day').
'</span>';
2901 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2902 $return .=
'</div>';
2903 $return .=
'</div>';
2904 $return .=
'</div>';
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
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.
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...
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.
deleteLine($rowid, $fuser=null, $notrigger=0)
deleteline
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
getVentilExportCompta($mode=0)
Return if object was dispatched into bookkeeping.
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.
periodExists(User $fuser, $startDate, $endDate)
periodExists
setDeny($fuser, $details, $notrigger=0)
setDeny
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.
getSummary()
Return a short summary of the public note.
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.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
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.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.