28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_ik.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
40 public $element =
'expensereport';
45 public $table_element =
'expensereport';
50 public $table_element_line =
'expensereport_det';
55 public $fk_element =
'fk_expensereport';
60 public $picto =
'trip';
62 public $lines = array();
85 public $fk_c_paiement;
88 public $user_author_infos;
89 public $user_validator_infos;
91 public $rule_warning_message;
97 public $fk_user_author;
101 public $fk_user_modif;
105 public $detail_refuse;
106 public $fk_user_refuse;
110 public $detail_cancel;
111 public $fk_user_cancel;
113 public $fk_user_validator;
117 public $fk_user_valid;
118 public $user_valid_infos;
121 public $date_approve;
122 public $fk_user_approve;
125 public $user_paid_infos;
159 public $fields = array(
160 'rowid' =>array(
'type'=>
'integer',
'label'=>
'ID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
161 'ref' =>array(
'type'=>
'varchar(50)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>15),
162 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>20),
163 'ref_number_int' =>array(
'type'=>
'integer',
'label'=>
'Ref number int',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
164 'ref_ext' =>array(
'type'=>
'integer',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>-1,
'position'=>30),
165 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>35),
166 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
167 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
168 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
169 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
170 'date_debut' =>array(
'type'=>
'date',
'label'=>
'Date debut',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>60),
171 'date_fin' =>array(
'type'=>
'date',
'label'=>
'Date fin',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>65),
172 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'Date valid',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
173 'date_approve' =>array(
'type'=>
'datetime',
'label'=>
'Date approve',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
174 'date_refuse' =>array(
'type'=>
'datetime',
'label'=>
'Date refuse',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
175 'date_cancel' =>array(
'type'=>
'datetime',
'label'=>
'Date cancel',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
176 'fk_user_author' =>array(
'type'=>
'integer',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>100),
177 'fk_user_modif' =>array(
'type'=>
'integer',
'label'=>
'Fk user modif',
'enabled'=>1,
'visible'=>-1,
'position'=>105),
178 'fk_user_valid' =>array(
'type'=>
'integer',
'label'=>
'Fk user valid',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
179 'fk_user_validator' =>array(
'type'=>
'integer',
'label'=>
'Fk user validator',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
180 'fk_user_approve' =>array(
'type'=>
'integer',
'label'=>
'Fk user approve',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
181 'fk_user_refuse' =>array(
'type'=>
'integer',
'label'=>
'Fk user refuse',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
182 'fk_user_cancel' =>array(
'type'=>
'integer',
'label'=>
'Fk user cancel',
'enabled'=>1,
'visible'=>-1,
'position'=>130),
183 'fk_c_paiement' =>array(
'type'=>
'integer',
'label'=>
'Fk c paiement',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
184 'paid' =>array(
'type'=>
'integer',
'label'=>
'Paid',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>145),
185 'note_public' =>array(
'type'=>
'text',
'label'=>
'Note public',
'enabled'=>1,
'visible'=>0,
'position'=>150),
186 'note_private' =>array(
'type'=>
'text',
'label'=>
'Note private',
'enabled'=>1,
'visible'=>0,
'position'=>155),
187 'detail_refuse' =>array(
'type'=>
'varchar(255)',
'label'=>
'Detail refuse',
'enabled'=>1,
'visible'=>-1,
'position'=>160),
188 'detail_cancel' =>array(
'type'=>
'varchar(255)',
'label'=>
'Detail cancel',
'enabled'=>1,
'visible'=>-1,
'position'=>165),
189 'integration_compta' =>array(
'type'=>
'integer',
'label'=>
'Integration compta',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
190 'fk_bank_account' =>array(
'type'=>
'integer',
'label'=>
'Fk bank account',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
191 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>185),
192 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Multicurrency code',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
193 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency tx',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
194 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ht',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
195 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total tva',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
196 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'Multicurrency total ttc',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
197 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>220),
198 'date_create' =>array(
'type'=>
'datetime',
'label'=>
'Date create',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>300),
199 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'Tms',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>305),
200 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-1,
'position'=>1000),
201 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>1010),
202 'fk_statut' =>array(
'type'=>
'integer',
'label'=>
'Fk statut',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>500),
214 $this->total_ttc = 0;
215 $this->total_tva = 0;
216 $this->modepaymentid = 0;
219 $this->statuts_short = array(0 =>
'Draft', 2 =>
'Validated', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
220 $this->statuts = array(0 =>
'Draft', 2 =>
'ValidatedWaitingApproval', 4 =>
'Canceled', 5 =>
'Approved', 6 =>
'Paid', 99 =>
'Refused');
221 $this->statuts_logo = array(0 =>
'status0', 2 =>
'status1', 4 =>
'status6', 5 =>
'status4', 6 =>
'status6', 99 =>
'status5');
231 public function create($user, $notrigger = 0)
233 global $conf, $langs;
240 if (empty($this->date_debut) || empty($this->date_fin))
242 $this->error = $langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
'Date'));
246 $fuserid = $this->fk_user_author;
247 if (empty($fuserid)) $fuserid = $user->id;
251 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
254 $sql .=
",total_ttc";
255 $sql .=
",total_tva";
256 $sql .=
",date_debut";
258 $sql .=
",date_create";
259 $sql .=
",fk_user_creat";
260 $sql .=
",fk_user_author";
261 $sql .=
",fk_user_validator";
262 $sql .=
",fk_user_approve";
263 $sql .=
",fk_user_modif";
264 $sql .=
",fk_statut";
265 $sql .=
",fk_c_paiement";
267 $sql .=
",note_public";
268 $sql .=
",note_private";
272 $sql .=
", ".$this->total_ht;
273 $sql .=
", ".$this->total_ttc;
274 $sql .=
", ".$this->total_tva;
275 $sql .=
", '".$this->db->idate($this->date_debut).
"'";
276 $sql .=
", '".$this->db->idate($this->date_fin).
"'";
277 $sql .=
", '".$this->db->idate($now).
"'";
278 $sql .=
", ".$user->id;
279 $sql .=
", ".$fuserid;
280 $sql .=
", ".($this->fk_user_validator > 0 ? $this->fk_user_validator :
"null");
281 $sql .=
", ".($this->fk_user_approve > 0 ? $this->fk_user_approve :
"null");
282 $sql .=
", ".($this->fk_user_modif > 0 ? $this->fk_user_modif :
"null");
283 $sql .=
", ".($this->fk_statut > 1 ? $this->fk_statut : 0);
284 $sql .=
", ".($this->modepaymentid ? $this->modepaymentid :
"null");
286 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
287 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
288 $sql .=
", ".$conf->entity;
291 $result = $this->
db->query($sql);
294 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
295 $this->ref =
'(PROV'.$this->id.
')';
297 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->
db->escape($this->ref).
"' WHERE rowid=".$this->id;
301 $this->error = $this->
db->lasterror();
307 if (is_array($this->lines) && count($this->lines) > 0)
309 foreach ($this->lines as $line)
313 if (!is_object($line)) {
314 $line = (object) $line;
316 $newndfline->fk_expensereport = $line->fk_expensereport;
317 $newndfline->fk_c_type_fees = $line->fk_c_type_fees;
318 $newndfline->fk_project = $line->fk_project;
319 $newndfline->vatrate = $line->vatrate;
320 $newndfline->vat_src_code = $line->vat_src_code;
321 $newndfline->comments = $line->comments;
322 $newndfline->qty = $line->qty;
323 $newndfline->value_unit = $line->value_unit;
324 $newndfline->total_ht = $line->total_ht;
325 $newndfline->total_ttc = $line->total_ttc;
326 $newndfline->total_tva = $line->total_tva;
327 $newndfline->date = $line->date;
328 $newndfline->rule_warning_message = $line->rule_warning_message;
329 $newndfline->fk_c_exp_tax_cat = $line->fk_c_exp_tax_cat;
330 $newndfline->fk_ecm_files = $line->fk_ecm_files;
335 $newndfline->fk_expensereport = $this->id;
336 $result = $newndfline->insert();
339 $this->error = $newndfline->error;
340 $this->errors = $newndfline->errors;
351 if ($result < 0) $error++;
362 $result = $this->
call_trigger(
'EXPENSE_REPORT_CREATE', $user);
375 $this->
db->rollback();
379 $this->
db->rollback();
383 dol_syslog(get_class($this).
"::create error ".$this->error, LOG_ERR);
384 $this->
db->rollback();
388 $this->error = $this->
db->lasterror().
" sql=".$sql;
389 $this->
db->rollback();
408 if (empty($fk_user_author)) $fk_user_author = $user->id;
417 $objFrom = clone $this;
422 $this->fk_statut = 0;
425 $this->fk_user_creat = $user->id;
426 $this->fk_user_author = $fk_user_author;
427 $this->fk_user_valid =
'';
428 $this->date_create =
'';
429 $this->date_creation =
'';
430 $this->date_validation =
'';
433 if (is_array($this->lines) && count($this->lines) > 0)
435 foreach ($this->lines as $key => $line)
437 $this->lines[$key]->fk_ecm_files = 0;
442 $this->context[
'createfromclone'] =
'createfromclone';
443 $result = $this->
create($user);
444 if ($result < 0) $error++;
449 if (is_object($hookmanager))
451 $parameters = array(
'objFrom'=>$objFrom);
453 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
454 if ($reshook < 0) $error++;
458 unset($this->context[
'createfromclone']);
466 $this->
db->rollback();
480 public function update($user, $notrigger = 0, $userofexpensereport = null)
487 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
488 $sql .=
" total_ht = ".$this->total_ht;
489 $sql .=
" , total_ttc = ".$this->total_ttc;
490 $sql .=
" , total_tva = ".$this->total_tva;
491 $sql .=
" , date_debut = '".$this->db->idate($this->date_debut).
"'";
492 $sql .=
" , date_fin = '".$this->db->idate($this->date_fin).
"'";
493 if ($userofexpensereport && is_object($userofexpensereport))
495 $sql .=
" , fk_user_author = ".($userofexpensereport->id > 0 ? $userofexpensereport->id :
"null");
497 $sql .=
" , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator :
"null");
498 $sql .=
" , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid :
"null");
499 $sql .=
" , fk_user_approve = ".($this->fk_user_approve > 0 ? $this->fk_user_approve :
"null");
500 $sql .=
" , fk_user_modif = ".$user->id;
501 $sql .=
" , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut :
'0');
502 $sql .=
" , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement :
"null");
503 $sql .=
" , note_public = ".(!empty($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"''");
504 $sql .=
" , note_private = ".(!empty($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"''");
505 $sql .=
" , detail_refuse = ".(!empty($this->detail_refuse) ?
"'".$this->db->escape($this->detail_refuse).
"'" :
"''");
506 $sql .=
" WHERE rowid = ".$this->id;
508 dol_syslog(get_class($this).
"::update sql=".$sql, LOG_DEBUG);
509 $result = $this->
db->query($sql);
515 $result = $this->
call_trigger(
'EXPENSE_REPORT_UPDATE', $user);
528 $this->
db->rollback();
529 $this->error = $this->
db->error();
533 $this->
db->rollback();
534 $this->error = $this->
db->error();
546 public function fetch($id, $ref =
'')
550 $sql =
"SELECT d.rowid, d.entity, d.ref, d.note_public, d.note_private,";
551 $sql .=
" d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,";
552 $sql .=
" d.date_refuse, d.date_cancel,";
553 $sql .=
" d.total_ht, d.total_ttc, d.total_tva,";
554 $sql .=
" d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve,";
555 $sql .=
" d.fk_user_creat, d.fk_user_author, d.fk_user_modif, d.fk_user_validator,";
556 $sql .=
" d.fk_user_valid, d.fk_user_approve,";
557 $sql .=
" d.fk_statut as status, d.fk_c_paiement, d.paid";
558 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as d";
559 if ($ref) $sql .=
" WHERE d.ref = '".$this->db->escape($ref).
"'";
560 else $sql .=
" WHERE d.rowid = ".$id;
563 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
567 $obj = $this->
db->fetch_object(
$resql);
570 $this->
id = $obj->rowid;
571 $this->ref = $obj->ref;
573 $this->entity = $obj->entity;
575 $this->total_ht = $obj->total_ht;
576 $this->total_tva = $obj->total_tva;
577 $this->total_ttc = $obj->total_ttc;
578 $this->note_public = $obj->note_public;
579 $this->note_private = $obj->note_private;
580 $this->detail_refuse = $obj->detail_refuse;
581 $this->detail_cancel = $obj->detail_cancel;
583 $this->date_debut = $this->
db->jdate($obj->date_debut);
584 $this->date_fin = $this->
db->jdate($obj->date_fin);
585 $this->date_valid = $this->
db->jdate($obj->date_valid);
586 $this->date_approve = $this->
db->jdate($obj->date_approve);
587 $this->date_create = $this->
db->jdate($obj->date_create);
588 $this->date_modif = $this->
db->jdate($obj->date_modif);
589 $this->date_refuse = $this->
db->jdate($obj->date_refuse);
590 $this->date_cancel = $this->
db->jdate($obj->date_cancel);
592 $this->fk_user_creat = $obj->fk_user_creat;
593 $this->fk_user_author = $obj->fk_user_author;
594 $this->fk_user_modif = $obj->fk_user_modif;
595 $this->fk_user_validator = $obj->fk_user_validator;
596 $this->fk_user_valid = $obj->fk_user_valid;
597 $this->fk_user_refuse = $obj->fk_user_refuse;
598 $this->fk_user_cancel = $obj->fk_user_cancel;
599 $this->fk_user_approve = $obj->fk_user_approve;
601 $user_author =
new User($this->
db);
602 if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author);
604 $this->user_author_infos =
dolGetFirstLastname($user_author->firstname, $user_author->lastname);
606 $user_approver =
new User($this->
db);
607 if ($this->fk_user_approve > 0) $user_approver->fetch($this->fk_user_approve);
608 elseif ($this->fk_user_validator > 0) $user_approver->fetch($this->fk_user_validator);
609 $this->user_validator_infos =
dolGetFirstLastname($user_approver->firstname, $user_approver->lastname);
611 $this->fk_statut = $obj->status;
612 $this->status = $obj->status;
613 $this->fk_c_paiement = $obj->fk_c_paiement;
614 $this->paid = $obj->paid;
618 $user_valid =
new User($this->
db);
619 if ($this->fk_user_valid > 0) $user_valid->fetch($this->fk_user_valid);
620 $this->user_valid_infos =
dolGetFirstLastname($user_valid->firstname, $user_valid->lastname);
632 $this->error = $this->
db->lasterror();
646 public function set_paid($id, $fuser, $notrigger = 0)
652 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport";
653 $sql .=
" SET fk_statut = ".self::STATUS_CLOSED.
", paid=1";
654 $sql .=
" WHERE rowid = ".$id.
" AND fk_statut = ".self::STATUS_APPROVED;
656 dol_syslog(get_class($this).
"::set_paid sql=".$sql, LOG_DEBUG);
660 if ($this->
db->affected_rows(
$resql))
665 $result = $this->
call_trigger(
'EXPENSE_REPORT_PAID', $fuser);
678 $this->
db->rollback();
679 $this->error = $this->
db->error();
687 $this->
db->rollback();
701 return $this->
LibStatut($this->status, $mode);
717 $labelStatus = $langs->transnoentitiesnoconv($this->statuts[$status]);
718 $labelStatusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
720 $statusType = $this->statuts_logo[$status];
722 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
736 $sql =
"SELECT f.rowid,";
737 $sql .=
" f.date_create as datec,";
738 $sql .=
" f.tms as date_modification,";
739 $sql .=
" f.date_valid as datev,";
740 $sql .=
" f.date_approve as datea,";
741 $sql .=
" f.fk_user_creat as fk_user_creation,";
742 $sql .=
" f.fk_user_modif as fk_user_modification,";
743 $sql .=
" f.fk_user_valid,";
744 $sql .=
" f.fk_user_approve";
745 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as f";
746 $sql .=
" WHERE f.rowid = ".$id;
747 $sql .=
" AND f.entity = ".$conf->entity;
754 $obj = $this->
db->fetch_object(
$resql);
756 $this->
id = $obj->rowid;
758 $this->date_creation = $this->
db->jdate($obj->datec);
759 $this->date_modification = $this->
db->jdate($obj->date_modification);
760 $this->date_validation = $this->
db->jdate($obj->datev);
761 $this->date_approbation = $this->
db->jdate($obj->datea);
763 $cuser =
new User($this->
db);
764 $cuser->fetch($obj->fk_user_author);
765 $this->user_creation = $cuser;
767 if ($obj->fk_user_creation)
769 $cuser =
new User($this->
db);
770 $cuser->fetch($obj->fk_user_creation);
771 $this->user_creation = $cuser;
773 if ($obj->fk_user_valid)
775 $vuser =
new User($this->
db);
776 $vuser->fetch($obj->fk_user_valid);
777 $this->user_validation = $vuser;
779 if ($obj->fk_user_modification)
781 $muser =
new User($this->
db);
782 $muser->fetch($obj->fk_user_modification);
783 $this->user_modification = $muser;
785 if ($obj->fk_user_approve)
787 $auser =
new User($this->
db);
788 $auser->fetch($obj->fk_user_approve);
789 $this->user_approve = $auser;
809 global $user, $langs, $conf;
815 $this->ref =
'SPECIMEN';
818 $this->date_create = $now;
819 $this->date_debut = $now;
820 $this->date_fin = $now;
821 $this->date_valid = $now;
822 $this->date_approve = $now;
827 $this->fk_statut = 5;
829 $this->fk_user_author = $user->id;
830 $this->fk_user_validator = $user->id;
831 $this->fk_user_valid = $user->id;
832 $this->fk_user_approve = $user->id;
834 $this->note_private =
'Private note';
835 $this->note_public =
'SPECIMEN';
838 while ($xnbp < $nbp) {
840 $line->comments = $langs->trans(
"Comment").
" ".$xnbp;
841 $line->date = ($now - 3600 * (1 + $xnbp));
842 $line->total_ht = 100;
843 $line->total_tva = 20;
844 $line->total_ttc = 120;
847 $line->value_unit = 120;
848 $line->fk_expensereport = 0;
849 $line->type_fees_code =
'TRA';
850 $line->fk_c_type_fees = $type_fees_id;
852 $line->projet_ref =
'ABC';
854 $this->lines[$xnbp] = $line;
857 $this->total_ht += $line->total_ht;
858 $this->total_tva += $line->total_tva;
859 $this->total_ttc += $line->total_ttc;
874 global $conf, $db, $langs;
876 $langs->load(
'trips');
878 if ($user->rights->expensereport->lire) {
879 $sql =
"SELECT de.fk_expensereport, de.date, de.comments, de.total_ht, de.total_ttc";
880 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport_det as de";
881 $sql .=
" WHERE de.fk_projet = ".$projectid;
883 dol_syslog(get_class($this).
"::fetch sql=".$sql, LOG_DEBUG);
884 $result = $this->
db->query($sql);
887 $num = $this->
db->num_rows($result);
894 $objp = $this->
db->fetch_object($result);
896 $sql2 =
"SELECT d.rowid, d.fk_user_author, d.ref, d.fk_statut as status";
897 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as d";
898 $sql2 .=
" WHERE d.rowid = ".((int) $objp->fk_expensereport);
900 $result2 = $this->
db->query($sql2);
901 $obj = $this->
db->fetch_object($result2);
903 $objp->fk_user_author = $obj->fk_user_author;
904 $objp->ref = $obj->ref;
905 $objp->fk_c_expensereport_status = $obj->status;
906 $objp->rowid = $obj->rowid;
908 $total_HT = $total_HT + $objp->total_ht;
909 $total_TTC = $total_TTC + $objp->total_ttc;
910 $author =
new User($this->
db);
911 $author->fetch($objp->fk_user_author);
914 print '<td><a href="'.DOL_URL_ROOT.
'/expensereport/card.php?id='.$objp->rowid.
'">'.$objp->ref_num.
'</a></td>';
915 print '<td class="center">'.dol_print_date($objp->date,
'day').
'</td>';
916 print '<td>'.$author->getNomUrl(1).
'</td>';
917 print '<td>'.$objp->comments.
'</td>';
918 print '<td class="right">'.price($objp->total_ht).
'</td>';
919 print '<td class="right">'.price($objp->total_ttc).
'</td>';
920 print '<td class="right">';
922 switch ($objp->fk_c_expensereport_status) {
927 print $langs->trans(
'Draft').
' '.
img_picto($langs->trans(
'Draft'),
'statut0');
930 print $langs->trans(
'TripForValid').
' '.
img_picto($langs->trans(
'TripForValid'),
'statut3');
933 print $langs->trans(
'TripForPaid').
' '.
img_picto($langs->trans(
'TripForPaid'),
'statut3');
936 print $langs->trans(
'TripPaid').
' '.
img_picto($langs->trans(
'TripPaid'),
'statut4');
953 print '<tr class="liste_total"><td colspan="4">'.$langs->trans(
"Number").
': '.$i.
'</td>';
954 print '<td class="right" width="100">'.$langs->trans(
"TotalHT").
' : '.
price($total_HT).
'</td>';
955 print '<td class="right" width="100">'.$langs->trans(
"TotalTTC").
' : '.
price($total_TTC).
'</td>';
956 print '<td> </td>';
959 $this->error = $this->
db->lasterror();
974 $sql =
'SELECT tt.total_ht, tt.total_ttc, tt.total_tva';
975 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as tt';
976 $sql .=
' WHERE tt.'.$this->fk_element.
' = '.$id;
978 $total_ht = 0; $total_tva = 0; $total_ttc = 0;
980 $result = $this->
db->query($sql);
983 $num = $this->
db->num_rows($result);
986 $objp = $this->
db->fetch_object($result);
987 $total_ht += $objp->total_ht;
988 $total_tva += $objp->total_tva;
992 $total_ttc = $total_ht + $total_tva;
993 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
994 $sql .=
" total_ht = ".$total_ht;
995 $sql .=
" , total_ttc = ".$total_ttc;
996 $sql .=
" , total_tva = ".$total_tva;
997 $sql .=
" WHERE rowid = ".$id;
998 $result = $this->
db->query($sql);
1000 $this->
db->free($result);
1003 $this->error = $this->
db->lasterror();
1004 dol_syslog(get_class($this).
"::recalculer: Error ".$this->error, LOG_ERR);
1008 $this->error = $this->
db->lasterror();
1009 dol_syslog(get_class($this).
"::recalculer: Error ".$this->error, LOG_ERR);
1025 $this->lines = array();
1027 $sql =
' SELECT de.rowid, de.comments, de.qty, de.value_unit, de.date, de.rang,';
1028 $sql .=
' de.'.$this->fk_element.
', de.fk_c_type_fees, de.fk_c_exp_tax_cat, de.fk_projet as fk_project, de.tva_tx, de.fk_ecm_files,';
1029 $sql .=
' de.total_ht, de.total_tva, de.total_ttc,';
1030 $sql .=
' ctf.code as code_type_fees, ctf.label as libelle_type_fees,';
1031 $sql .=
' p.ref as ref_projet, p.title as title_projet';
1032 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as de';
1033 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id';
1034 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as p ON de.fk_projet = p.rowid';
1035 $sql .=
' WHERE de.'.$this->fk_element.
' = '.$this->id;
1036 if (!empty($conf->global->EXPENSEREPORT_LINES_SORTED_BY_ROWID))
1038 $sql .=
' ORDER BY de.rang ASC, de.rowid ASC';
1040 $sql .=
' ORDER BY de.rang ASC, de.date ASC';
1046 $num = $this->
db->num_rows(
$resql);
1050 $objp = $this->
db->fetch_object(
$resql);
1054 $deplig->rowid = $objp->rowid;
1055 $deplig->id = $objp->rowid;
1056 $deplig->comments = $objp->comments;
1057 $deplig->qty = $objp->qty;
1058 $deplig->value_unit = $objp->value_unit;
1059 $deplig->date = $objp->date;
1060 $deplig->dates = $this->
db->jdate($objp->date);
1062 $deplig->fk_expensereport = $objp->fk_expensereport;
1063 $deplig->fk_c_type_fees = $objp->fk_c_type_fees;
1064 $deplig->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat;
1065 $deplig->fk_projet = $objp->fk_project;
1066 $deplig->fk_project = $objp->fk_project;
1067 $deplig->fk_ecm_files = $objp->fk_ecm_files;
1069 $deplig->total_ht = $objp->total_ht;
1070 $deplig->total_tva = $objp->total_tva;
1071 $deplig->total_ttc = $objp->total_ttc;
1073 $deplig->type_fees_code = empty($objp->code_type_fees) ?
'TF_OTHER' : $objp->code_type_fees;
1074 $deplig->type_fees_libelle = $objp->libelle_type_fees;
1075 $deplig->tva_tx = $objp->tva_tx;
1076 $deplig->vatrate = $objp->tva_tx;
1077 $deplig->projet_ref = $objp->ref_projet;
1078 $deplig->projet_title = $objp->title_projet;
1080 $deplig->rang = $objp->rang;
1082 $this->lines[$i] = $deplig;
1089 $this->error = $this->
db->lasterror();
1090 dol_syslog(get_class($this).
"::fetch_lines: Error ".$this->error, LOG_ERR);
1103 public function delete(
User $user = null, $notrigger =
false)
1106 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1114 $result = $this->
call_trigger(
'EXPENSEREPORT_DELETE', $user);
1115 if ($result < 0) { $error++; }
1120 if (!$error && !empty($this->table_element_line)) {
1121 $tabletodelete = $this->table_element_line;
1123 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".$this->id;
1124 if (!$this->
db->query($sql)) {
1126 $this->error = $this->
db->lasterror();
1127 $this->errors[] = $this->error;
1128 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1135 if ($res < 0) $error++;
1141 if ($res < 0) $error++;
1149 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1155 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".$this->id;
1156 $res = $this->
db->query($sql);
1159 $this->error = $this->
db->lasterror();
1160 $this->errors[] = $this->error;
1161 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
1176 if ($conf->expensereport->multidir_output[$this->entity] && !empty($this->ref)) {
1177 $dir = $conf->expensereport->multidir_output[$this->entity].
"/".$ref;
1178 $file = $dir.
"/".$ref.
".pdf";
1179 if (file_exists($file)) {
1183 $this->error =
'ErrorFailToDeleteFile';
1184 $this->errors[] = $this->error;
1185 $this->
db->rollback();
1189 if (file_exists($dir)) {
1192 $this->error =
'ErrorFailToDeleteDir';
1193 $this->errors[] = $this->error;
1194 $this->
db->rollback();
1202 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
1203 $this->
db->commit();
1206 $this->
db->rollback();
1220 global $conf, $langs, $user;
1226 if ($this->status == self::STATUS_VALIDATED)
1228 dol_syslog(get_class($this).
"::valid action abandonned: already validated", LOG_WARNING);
1232 $this->date_valid = $now;
1235 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref)))
1241 if (empty($num) || $num < 0)
return -1;
1248 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1249 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1250 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
1251 $sql .=
" date_valid='".$this->db->idate($this->date_valid).
"',";
1252 $sql .=
" fk_user_valid = ".$user->id;
1253 $sql .=
" WHERE rowid = ".$this->id;
1258 if (!$error && !$notrigger)
1261 $result = $this->
call_trigger(
'EXPENSE_REPORT_VALIDATE', $fuser);
1270 $this->oldref = $this->ref;
1273 if (preg_match(
'/^[\(]?PROV/i', $this->ref))
1275 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1278 $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).
"'";
1279 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'expensereport/".$this->
db->escape($this->ref).
"' and entity = ".$conf->entity;
1281 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
1286 $dirsource = $conf->expensereport->dir_output.
'/'.$oldref;
1287 $dirdest = $conf->expensereport->dir_output.
'/'.$newref;
1288 if (!$error && file_exists($dirsource))
1290 dol_syslog(get_class($this).
"::setValidate() rename dir ".$dirsource.
" into ".$dirdest);
1292 if (@rename($dirsource, $dirdest))
1296 $listoffiles =
dol_dir_list($conf->expensereport->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1297 foreach ($listoffiles as $fileentry)
1299 $dirsource = $fileentry[
'name'];
1300 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1301 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1302 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1303 @rename($dirsource, $dirdest);
1314 $this->status = self::STATUS_VALIDATED;
1319 $this->
db->commit();
1322 $this->
db->rollback();
1323 $this->error = $this->
db->error();
1327 $this->
db->rollback();
1328 $this->error = $this->
db->lasterror();
1343 global $conf, $langs;
1346 $sql =
'SELECT date_debut';
1347 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element;
1348 $sql .=
' WHERE rowid = '.$this->id;
1350 $result = $this->
db->query($sql);
1352 $objp = $this->
db->fetch_object($result);
1354 $this->date_debut = $this->
db->jdate($objp->date_debut);
1356 if ($this->status != self::STATUS_VALIDATED)
1358 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1359 $sql .=
" SET fk_statut = ".self::STATUS_VALIDATED;
1360 $sql .=
' WHERE rowid = '.$this->id;
1362 dol_syslog(get_class($this).
"::set_save_from_refuse sql=".$sql, LOG_DEBUG);
1364 if ($this->
db->query($sql))
1368 $this->error = $this->
db->lasterror();
1372 dol_syslog(get_class($this).
"::set_save_from_refuse expensereport already with save status", LOG_WARNING);
1389 $this->date_approve = $now;
1390 if ($this->status != self::STATUS_APPROVED)
1394 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1395 $sql .=
" SET ref = '".$this->db->escape($this->ref).
"', fk_statut = ".self::STATUS_APPROVED.
", fk_user_approve = ".$fuser->id.
",";
1396 $sql .=
" date_approve='".$this->db->idate($this->date_approve).
"'";
1397 $sql .=
' WHERE rowid = '.$this->id;
1398 if ($this->
db->query($sql))
1403 $result = $this->
call_trigger(
'EXPENSE_REPORT_APPROVE', $fuser);
1413 $this->
db->commit();
1416 $this->
db->rollback();
1417 $this->error = $this->
db->error();
1421 $this->
db->rollback();
1422 $this->error = $this->
db->lasterror();
1426 dol_syslog(get_class($this).
"::setApproved expensereport already with approve status", LOG_WARNING);
1440 public function setDeny($fuser, $details, $notrigger = 0)
1446 if ($this->status != self::STATUS_REFUSED)
1448 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1449 $sql .=
" SET ref = '".$this->db->escape($this->ref).
"', fk_statut = ".self::STATUS_REFUSED.
", fk_user_refuse = ".$fuser->id.
",";
1450 $sql .=
" date_refuse='".$this->db->idate($now).
"',";
1451 $sql .=
" detail_refuse='".$this->db->escape($details).
"',";
1452 $sql .=
" fk_user_approve = NULL";
1453 $sql .=
' WHERE rowid = '.$this->id;
1454 if ($this->
db->query($sql))
1456 $this->fk_statut = 99;
1458 $this->fk_user_refuse = $fuser->id;
1459 $this->detail_refuse = $details;
1460 $this->date_refuse = $now;
1465 $result = $this->
call_trigger(
'EXPENSE_REPORT_DENY', $fuser);
1475 $this->
db->commit();
1478 $this->
db->rollback();
1479 $this->error = $this->
db->error();
1483 $this->
db->rollback();
1484 $this->error = $this->
db->lasterror();
1488 dol_syslog(get_class($this).
"::setDeny expensereport already with refuse status", LOG_WARNING);
1509 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1510 $sql .=
" SET paid = 0, fk_statut = ".self::STATUS_APPROVED;
1511 $sql .=
' WHERE rowid = '.$this->id;
1513 dol_syslog(get_class($this).
"::set_unpaid sql=".$sql, LOG_DEBUG);
1515 if ($this->
db->query($sql))
1520 $result = $this->
call_trigger(
'EXPENSE_REPORT_UNPAID', $fuser);
1530 $this->
db->commit();
1533 $this->
db->rollback();
1534 $this->error = $this->
db->error();
1538 $this->
db->rollback();
1539 $this->error = $this->
db->error();
1543 dol_syslog(get_class($this).
"::set_unpaid expensereport already with unpaid status", LOG_WARNING);
1560 $this->date_cancel = $this->
db->idate(
dol_now());
1561 if ($this->status != self::STATUS_CANCELED)
1565 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1566 $sql .=
" SET fk_statut = ".self::STATUS_CANCELED.
", fk_user_cancel = ".$fuser->id;
1567 $sql .=
", date_cancel='".$this->db->idate($this->date_cancel).
"'";
1568 $sql .=
" ,detail_cancel='".$this->db->escape($detail).
"'";
1569 $sql .=
' WHERE rowid = '.$this->id;
1571 dol_syslog(get_class($this).
"::set_cancel sql=".$sql, LOG_DEBUG);
1573 if ($this->
db->query($sql))
1578 $result = $this->
call_trigger(
'EXPENSE_REPORT_CANCEL', $fuser);
1588 $this->
db->commit();
1591 $this->
db->rollback();
1592 $this->error = $this->
db->error();
1596 $this->
db->rollback();
1597 $this->error = $this->
db->error();
1601 dol_syslog(get_class($this).
"::set_cancel expensereport already with cancel status", LOG_WARNING);
1612 global $langs, $conf;
1613 $langs->load(
"trips");
1615 if (!empty($conf->global->EXPENSEREPORT_ADDON))
1619 $file = $conf->global->EXPENSEREPORT_ADDON.
".php";
1620 $classname = $conf->global->EXPENSEREPORT_ADDON;
1623 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1624 foreach ($dirmodels as $reldir)
1626 $dir =
dol_buildpath($reldir.
"core/modules/expensereport/");
1629 $mybool |= @include_once $dir.$file;
1632 if ($mybool ===
false) {
1637 $obj =
new $classname();
1638 $numref = $obj->getNextValue($this);
1644 $this->error = $obj->error;
1645 $this->errors = $obj->errors;
1650 $this->error =
"Error_EXPENSEREPORT_ADDON_NotDefined";
1666 public function getNomUrl($withpicto = 0, $max = 0, $short = 0, $moretitle =
'', $notooltip = 0, $save_lastsearch_value = -1)
1668 global $langs, $conf;
1672 $url = DOL_URL_ROOT.
'/expensereport/card.php?id='.$this->id;
1674 if ($short)
return $url;
1676 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ExpenseReport").
'</u>';
1677 if (isset($this->status)) {
1678 $label .=
' '.$this->getLibStatut(5);
1680 if (!empty($this->ref))
1681 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1682 if (!empty($this->total_ht))
1683 $label .=
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1684 if (!empty($this->total_tva))
1685 $label .=
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1686 if (!empty($this->total_ttc))
1687 $label .=
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1688 if ($moretitle) $label .=
' - '.$moretitle;
1693 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1694 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1695 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1699 if (empty($ref)) $ref = $this->
id;
1702 if (empty($notooltip))
1704 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1706 $label = $langs->trans(
"ShowExpenseReport");
1707 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1709 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1710 $linkclose .=
' class="classfortooltip"';
1713 $linkstart =
'<a href="'.$url.
'"';
1714 $linkstart .= $linkclose.
'>';
1717 $result .= $linkstart;
1718 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1719 if ($withpicto != 2) $result .= ($max ?
dol_trunc($ref, $max) : $ref);
1720 $result .= $linkend;
1736 $this->total_ht = $this->total_ht + $ligne_total_ht;
1737 $this->total_tva = $this->total_tva + $ligne_total_tva;
1738 $this->total_ttc = $this->total_ht + $this->total_tva;
1740 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1741 $sql .=
" total_ht = ".$this->total_ht;
1742 $sql .=
" , total_ttc = ".$this->total_ttc;
1743 $sql .=
" , total_tva = ".$this->total_tva;
1744 $sql .=
" WHERE rowid = ".$this->id;
1746 $result = $this->
db->query($sql);
1750 $this->error = $this->
db->error();
1766 $this->total_ht = $this->total_ht - $ligne_total_ht;
1767 $this->total_tva = $this->total_tva - $ligne_total_tva;
1768 $this->total_ttc = $this->total_ht + $this->total_tva;
1770 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1771 $sql .=
" total_ht = ".$this->total_ht;
1772 $sql .=
" , total_ttc = ".$this->total_ttc;
1773 $sql .=
" , total_tva = ".$this->total_tva;
1774 $sql .=
" WHERE rowid = ".$this->id;
1776 $result = $this->
db->query($sql);
1780 $this->error = $this->
db->error();
1800 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)
1802 global $conf, $langs, $mysoc;
1804 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);
1806 if ($this->status == self::STATUS_DRAFT)
1808 if (empty($qty)) $qty = 0;
1809 if (empty($fk_c_type_fees) || $fk_c_type_fees < 0) $fk_c_type_fees = 0;
1810 if (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) $fk_c_exp_tax_cat = 0;
1811 if (empty($vatrate) || $vatrate < 0) $vatrate = 0;
1812 if (empty($date)) $date =
'';
1813 if (empty($fk_project)) $fk_project = 0;
1816 if (!preg_match(
'/\s*\((.*)\)/', $vatrate)) {
1829 if (preg_match(
'/\s*\((.*)\)/', $vatrate, $reg))
1831 $vat_src_code = $reg[1];
1832 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
1834 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
1838 $tmp =
calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
1840 $this->line->value_unit = $up;
1841 $this->line->vat_src_code = $vat_src_code;
1842 $this->line->vatrate =
price2num($vatrate);
1843 $this->line->total_ttc = $tmp[2];
1844 $this->line->total_ht = $tmp[0];
1845 $this->line->total_tva = $tmp[1];
1847 $this->line->fk_expensereport = $this->id;
1848 $this->line->qty = $qty;
1849 $this->line->date = $date;
1850 $this->line->fk_c_type_fees = $fk_c_type_fees;
1851 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
1852 $this->line->comments = $comments;
1853 $this->line->fk_projet = $fk_project;
1854 $this->line->fk_project = $fk_project;
1856 $this->line->fk_ecm_files = $fk_ecm_files;
1861 $result = $this->line->insert(0,
true);
1867 $this->
db->commit();
1868 return $this->line->id;
1870 $this->
db->rollback();
1874 $this->error = $this->line->error;
1875 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
1876 $this->
db->rollback();
1880 dol_syslog(get_class($this).
"::addline status of expense report must be Draft to allow use of ->addline()", LOG_ERR);
1881 $this->error =
'ErrorExpenseNotDraft';
1895 global $user, $conf, $db, $langs;
1897 $langs->load(
'trips');
1899 if (empty($conf->global->MAIN_USE_EXPENSE_RULE))
return true;
1904 $rule_warning_message_tab = array();
1906 $current_total_ttc = $this->line->total_ttc;
1907 $new_current_total_ttc = $this->line->total_ttc;
1910 foreach ($rulestocheck as $rule)
1912 if (in_array($rule->code_expense_rules_type, array(
'EX_DAY',
'EX_MON',
'EX_YEA'))) $amount_to_test = $this->line->getExpAmount($rule, $this->fk_user_author, $rule->code_expense_rules_type);
1913 else $amount_to_test = $current_total_ttc;
1915 $amount_to_test = $amount_to_test - $current_total_ttc + $new_current_total_ttc;
1917 if ($amount_to_test > $rule->amount)
1921 if ($rule->restrictive)
1923 $this->error =
'ExpenseReportConstraintViolationError';
1924 $this->errors[] = $this->error;
1926 $new_current_total_ttc -= $amount_to_test - $rule->amount;
1927 $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), $langs->trans(
'by'.$rule->code_expense_rules_type,
price($new_current_total_ttc, 0, $langs, 1, -1, -1, $conf->currency)));
1929 $this->error =
'ExpenseReportConstraintViolationWarning';
1930 $this->errors[] = $this->error;
1932 $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), $langs->trans(
'nolimitby'.$rule->code_expense_rules_type));
1939 $this->line->rule_warning_message = implode(
'\n', $rule_warning_message_tab);
1943 $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);
1945 $this->line->value_unit = $tmp[5];
1946 $this->line->total_ttc = $tmp[2];
1947 $this->line->total_ht = $tmp[0];
1948 $this->line->total_tva = $tmp[1];
1963 if (empty($conf->global->MAIN_USE_EXPENSE_IK))
return false;
1965 $userauthor =
new User($this->
db);
1966 if ($userauthor->fetch($this->fk_user_author) <= 0)
1968 $this->error =
'ErrorCantFetchUser';
1969 $this->errors[] =
'ErrorCantFetchUser';
1977 $this->error =
'ErrorNoRangeAvailable';
1978 $this->errors[] =
'ErrorNoRangeAvailable';
1982 if (!empty($conf->global->MAIN_EXPENSE_APPLY_ENTIRE_OFFSET)) $ikoffset = $range->ikoffset;
1983 else $ikoffset = $range->ikoffset / 12;
1988 $new_up = $range->coef + ($ikoffset / $this->line->qty);
1989 $tmp =
calcul_price_total($this->line->qty, $new_up, 0, $this->line->vatrate, 0, 0, 0,
'TTC', 0, $type, $seller);
1991 $this->line->value_unit = $tmp[5];
1992 $this->line->total_ttc = $tmp[2];
1993 $this->line->total_ht = $tmp[0];
1994 $this->line->total_tva = $tmp[1];
2009 $sql =
'SELECT e.rowid FROM '.MAIN_DB_PREFIX.
'expensereport e';
2010 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'expensereport_det d ON (e.rowid = d.fk_expensereport)';
2011 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'c_type_fees f ON (d.fk_c_type_fees = f.id AND f.code = "EX_KME")';
2012 $sql .=
' WHERE e.fk_user_author = '.(int) $this->fk_user_author;
2013 $sql .=
' AND YEAR(d.date) = "'.dol_print_date($this->line->date,
'%Y').
'" AND MONTH(d.date) = "'.
dol_print_date($this->line->date,
'%m').
'"';
2014 if (!empty($this->line->id)) $sql .=
' AND d.rowid <> '.$this->line->id;
2016 dol_syslog(get_class($this).
"::offsetAlreadyGiven sql=".$sql);
2020 $num = $this->
db->num_rows(
$resql);
2021 if ($num > 0)
return true;
2045 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)
2047 global $user, $mysoc;
2049 if ($this->status == self::STATUS_DRAFT || $this->status == self::STATUS_REFUSED)
2064 if (preg_match(
'/\((.*)\)/', $vatrate, $reg))
2066 $vat_src_code = $reg[1];
2067 $vatrate = preg_replace(
'/\s*\(.*\)/',
'', $vatrate);
2069 $vatrate = preg_replace(
'/\*/',
'', $vatrate);
2071 $tmp =
calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0,
'TTC', 0, $type, $seller, $localtaxes_type);
2076 $tx_tva = $vatrate / 100;
2077 $tx_tva = $tx_tva + 1;
2080 $this->line->comments = $comments;
2081 $this->line->qty = $qty;
2082 $this->line->value_unit = $value_unit;
2083 $this->line->date = $date;
2085 $this->line->fk_expensereport = $expensereport_id;
2086 $this->line->fk_c_type_fees = $type_fees_id;
2087 $this->line->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
2088 $this->line->fk_projet = $projet_id;
2089 $this->line->fk_project = $projet_id;
2091 $this->line->vat_src_code = $vat_src_code;
2092 $this->line->vatrate =
price2num($vatrate);
2093 $this->line->total_ttc = $tmp[2];
2094 $this->line->total_ht = $tmp[0];
2095 $this->line->total_tva = $tmp[1];
2096 $this->line->localtax1_tx = $localtaxes_type[1];
2097 $this->line->localtax2_tx = $localtaxes_type[3];
2098 $this->line->localtax1_type = $localtaxes_type[0];
2099 $this->line->localtax2_type = $localtaxes_type[2];
2101 $this->line->fk_ecm_files = $fk_ecm_files;
2103 $this->line->id = $rowid;
2106 $sql =
"SELECT c.code as code_type_fees, c.label as libelle_type_fees";
2107 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as c";
2108 $sql .=
" WHERE c.id = ".$type_fees_id;
2112 $objp_fees = $this->
db->fetch_object(
$resql);
2113 $this->line->type_fees_code = $objp_fees->code_type_fees;
2114 $this->line->type_fees_libelle = $objp_fees->libelle_type_fees;
2119 $sql =
"SELECT p.ref as ref_projet, p.title as title_projet";
2120 $sql .=
" FROM ".MAIN_DB_PREFIX.
"projet as p";
2121 $sql .=
" WHERE p.rowid = ".$projet_id;
2124 $objp_projet = $this->
db->fetch_object(
$resql);
2125 $this->line->projet_ref = $objp_projet->ref_projet;
2126 $this->line->projet_title = $objp_projet->title_projet;
2133 $result = $this->line->update($user);
2136 $this->
db->commit();
2139 $this->error = $this->line->error;
2140 $this->errors = $this->line->errors;
2141 $this->
db->rollback();
2158 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element_line;
2159 $sql .=
' WHERE rowid = '.$rowid;
2161 dol_syslog(get_class($this).
"::deleteline sql=".$sql);
2162 $result = $this->
db->query($sql);
2165 $this->error = $this->
db->error();
2166 dol_syslog(get_class($this).
"::deleteline Error ".$this->error, LOG_ERR);
2167 $this->
db->rollback();
2171 $this->
db->commit();
2188 $sql =
"SELECT rowid, date_debut, date_fin";
2189 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element;
2190 $sql .=
" WHERE fk_user_author = '{$fuser->id}'";
2192 dol_syslog(get_class($this).
"::periode_existe sql=".$sql);
2193 $result = $this->
db->query($sql);
2195 $num_rows = $this->
db->num_rows($result); $i = 0;
2199 $date_d_form = $date_debut;
2200 $date_f_form = $date_fin;
2204 while ($i < $num_rows)
2206 $objp = $this->
db->fetch_object($result);
2208 $date_d_req = $this->
db->jdate($objp->date_debut);
2209 $date_f_req = $this->
db->jdate($objp->date_fin);
2211 if (!($date_f_form < $date_d_req || $date_d_form > $date_f_req)) $existe =
true;
2216 if ($existe)
return 1;
2222 $this->error = $this->
db->lasterror();
2223 dol_syslog(get_class($this).
"::periode_existe Error ".$this->error, LOG_ERR);
2239 $users_validator = array();
2241 $sql =
"SELECT DISTINCT ur.fk_user";
2242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2243 $sql .=
" WHERE ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2245 $sql .=
" SELECT DISTINCT ugu.fk_user";
2246 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_user as ugu, ".MAIN_DB_PREFIX.
"usergroup_rights as ur, ".MAIN_DB_PREFIX.
"rights_def as rd";
2247 $sql .=
" WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'";
2250 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport sql=".$sql);
2251 $result = $this->
db->query($sql);
2254 $num_rows = $this->
db->num_rows($result); $i = 0;
2255 while ($i < $num_rows)
2257 $objp = $this->
db->fetch_object($result);
2258 array_push($users_validator, $objp->fk_user);
2261 return $users_validator;
2263 $this->error = $this->
db->lasterror();
2264 dol_syslog(get_class($this).
"::fetch_users_approver_expensereport Error ".$this->error, LOG_ERR);
2280 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2284 $outputlangs->load(
"trips");
2287 if (!empty($this->model_pdf)) {
2288 $modele = $this->model_pdf;
2289 } elseif (!empty($this->modelpdf)) {
2290 $modele = $this->modelpdf;
2291 } elseif (!empty($conf->global->EXPENSEREPORT_ADDON_PDF)) {
2292 $modele = $conf->global->EXPENSEREPORT_ADDON_PDF;
2296 if (!empty($modele)) {
2297 $modelpath =
"core/modules/expensereport/doc/";
2299 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2315 $sql =
"SELECT id, code, label";
2316 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees";
2317 $sql .=
" WHERE active = ".$active;
2318 dol_syslog(get_class($this).
"::listOfTypes", LOG_DEBUG);
2319 $result = $this->
db->query($sql);
2322 $num = $this->
db->num_rows($result);
2326 $obj = $this->
db->fetch_object($result);
2327 $ret[$obj->code] = (($langs->transnoentitiesnoconv($obj->code) != $obj->code) ? $langs->transnoentitiesnoconv($obj->code) : $obj->label);
2345 global $conf, $user;
2347 $this->nb = array();
2349 $sql =
"SELECT count(ex.rowid) as nb";
2350 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2351 $sql .=
" WHERE ex.fk_statut > 0";
2352 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2353 if (empty($user->rights->expensereport->readall))
2355 $userchildids = $user->getAllChildIds(1);
2356 $sql .=
" AND (ex.fk_user_author IN (".join(
',', $userchildids).
")";
2357 $sql .=
" OR ex.fk_user_validator IN (".join(
',', $userchildids).
"))";
2362 while ($obj = $this->
db->fetch_object(
$resql)) {
2363 $this->nb[
"expensereports"] = $obj->nb;
2369 $this->error = $this->
db->error();
2385 global $conf, $langs;
2387 if ($user->socid)
return -1;
2391 $sql =
"SELECT ex.rowid, ex.date_valid";
2392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"expensereport as ex";
2393 if ($option ==
'toapprove') $sql .=
" WHERE ex.fk_statut = ".self::STATUS_VALIDATED;
2394 else $sql .=
" WHERE ex.fk_statut = ".self::STATUS_APPROVED;
2395 $sql .=
" AND ex.entity IN (".getEntity(
'expensereport').
")";
2396 if (empty($user->rights->expensereport->readall))
2398 $userchildids = $user->getAllChildIds(1);
2399 $sql .=
" AND (ex.fk_user_author IN (".join(
',', $userchildids).
")";
2400 $sql .=
" OR ex.fk_user_validator IN (".join(
',', $userchildids).
"))";
2406 $langs->load(
"trips");
2409 if ($option ==
'toapprove')
2411 $response->warning_delay = $conf->expensereport->approve->warning_delay / 60 / 60 / 24;
2412 $response->label = $langs->trans(
"ExpenseReportsToApprove");
2413 $response->labelShort = $langs->trans(
"ToApprove");
2414 $response->url = DOL_URL_ROOT.
'/expensereport/list.php?mainmenu=hrm&statut='.self::STATUS_VALIDATED;
2416 $response->warning_delay = $conf->expensereport->payment->warning_delay / 60 / 60 / 24;
2417 $response->label = $langs->trans(
"ExpenseReportsToPay");
2418 $response->labelShort = $langs->trans(
"StatusToPay");
2419 $response->url = DOL_URL_ROOT.
'/expensereport/list.php?mainmenu=hrm&statut='.self::STATUS_APPROVED;
2423 while ($obj = $this->
db->fetch_object(
$resql))
2425 $response->nbtodo++;
2427 if ($option ==
'toapprove')
2429 if ($this->
db->jdate($obj->date_valid) < ($now - $conf->expensereport->approve->warning_delay)) {
2430 $response->nbtodolate++;
2433 if ($this->
db->jdate($obj->date_valid) < ($now - $conf->expensereport->payment->warning_delay)) {
2434 $response->nbtodolate++;
2442 $this->error = $this->
db->error();
2458 if ($option ==
'toapprove' && $this->status != 2)
return false;
2459 if ($option ==
'topay' && $this->status != 5)
return false;
2462 if ($option ==
'toapprove') {
2463 return ($this->datevalid ? $this->datevalid : $this->date_valid) < ($now - $conf->expensereport->approve->warning_delay);
2465 return ($this->datevalid ? $this->datevalid : $this->date_valid) < ($now - $conf->expensereport->payment->warning_delay);
2476 $alreadydispatched = 0;
2478 $type =
'expense_report';
2480 $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 = ".$this->id;
2484 $obj = $this->
db->fetch_object(
$resql);
2487 $alreadydispatched = $obj->nb;
2490 $this->error = $this->
db->lasterror();
2494 if ($alreadydispatched)
2508 $table =
'payment_expensereport';
2509 $field =
'fk_expensereport';
2511 $sql =
'SELECT sum(amount) as amount';
2512 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
2513 $sql .=
' WHERE '.$field.
' = '.$this->id;
2515 dol_syslog(get_class($this).
"::getSumPayments", LOG_DEBUG);
2519 $obj = $this->
db->fetch_object(
$resql);
2521 return (empty($obj->amount) ? 0 : $obj->amount);
2523 $this->error = $this->
db->lasterror();
2558 public $fk_c_type_fees;
2563 public $fk_c_exp_tax_cat;
2573 public $fk_expensereport;
2575 public $type_fees_code;
2576 public $type_fees_libelle;
2579 public $projet_title;
2589 public $fk_ecm_files;
2610 $sql =
'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_c_exp_tax_cat, fde.fk_projet as fk_project, fde.date,';
2611 $sql .=
' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc, fde.fk_ecm_files,';
2612 $sql .=
' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
2613 $sql .=
' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
2614 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport_det as fde';
2615 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id';
2616 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pjt ON fde.fk_projet=pjt.rowid';
2617 $sql .=
' WHERE fde.rowid = '.$rowid;
2619 $result = $this->
db->query($sql);
2623 $objp = $this->
db->fetch_object($result);
2625 $this->
rowid = $objp->rowid;
2626 $this->
id = $objp->rowid;
2627 $this->ref = $objp->ref;
2628 $this->fk_expensereport = $objp->fk_expensereport;
2629 $this->comments = $objp->comments;
2630 $this->qty = $objp->qty;
2631 $this->date = $objp->date;
2632 $this->dates = $this->
db->jdate($objp->date);
2633 $this->value_unit = $objp->value_unit;
2634 $this->fk_c_type_fees = $objp->fk_c_type_fees;
2635 $this->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat;
2636 $this->fk_projet = $objp->fk_project;
2637 $this->fk_project = $objp->fk_project;
2638 $this->type_fees_code = $objp->type_fees_code;
2639 $this->type_fees_libelle = $objp->type_fees_libelle;
2640 $this->projet_ref = $objp->projet_ref;
2641 $this->projet_title = $objp->projet_title;
2642 $this->
vatrate = $objp->vatrate;
2643 $this->vat_src_code = $objp->vat_src_code;
2644 $this->total_ht = $objp->total_ht;
2645 $this->total_tva = $objp->total_tva;
2646 $this->total_ttc = $objp->total_ttc;
2647 $this->fk_ecm_files = $objp->fk_ecm_files;
2649 $this->
db->free($result);
2662 public function insert($notrigger = 0, $fromaddline =
false)
2664 global $langs, $user, $conf;
2668 dol_syslog(
"ExpenseReportLine::Insert", LOG_DEBUG);
2671 $this->comments = trim($this->comments);
2672 if (empty($this->value_unit)) $this->value_unit = 0;
2675 if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0;
2679 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'expensereport_det';
2680 $sql .=
' (fk_expensereport, fk_c_type_fees, fk_projet,';
2681 $sql .=
' tva_tx, vat_src_code, comments, qty, value_unit, total_ht, total_tva, total_ttc, date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)';
2682 $sql .=
" VALUES (".$this->db->escape($this->fk_expensereport).
",";
2683 $sql .=
" ".$this->db->escape($this->fk_c_type_fees).
",";
2684 $sql .=
" ".$this->db->escape((!empty($this->fk_project) && $this->fk_project > 0) ? $this->fk_project : ((!empty($this->fk_projet) && $this->fk_projet > 0) ? $this->fk_projet :
'null')).
",";
2685 $sql .=
" ".$this->db->escape($this->
vatrate).
",";
2686 $sql .=
" '".$this->db->escape(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"',";
2687 $sql .=
" '".$this->db->escape($this->comments).
"',";
2688 $sql .=
" ".$this->db->escape($this->qty).
",";
2689 $sql .=
" ".$this->db->escape($this->value_unit).
",";
2690 $sql .=
" ".$this->db->escape($this->total_ht).
",";
2691 $sql .=
" ".$this->db->escape($this->total_tva).
",";
2692 $sql .=
" ".$this->db->escape($this->total_ttc).
",";
2693 $sql .=
" '".$this->db->idate($this->date).
"',";
2694 $sql .=
" ".(empty($this->rule_warning_message) ?
'null' :
"'".$this->db->escape($this->rule_warning_message).
"'").
",";
2695 $sql .=
" ".$this->db->escape($this->fk_c_exp_tax_cat).
",";
2696 $sql .=
" ".($this->fk_ecm_files > 0 ? $this->fk_ecm_files :
'null');
2702 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'expensereport_det');
2707 $tmpparent->fetch($this->fk_expensereport);
2708 $result = $tmpparent->update_price();
2712 $this->error = $tmpparent->error;
2713 $this->errors = $tmpparent->errors;
2722 $this->
db->commit();
2725 $this->error = $this->
db->lasterror();
2726 dol_syslog(
"ExpenseReportLine::insert Error ".$this->error, LOG_ERR);
2727 $this->
db->rollback();
2744 $sql =
'SELECT SUM(d.total_ttc) as total_amount';
2745 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport_det d';
2746 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'expensereport e ON (d.fk_expensereport = e.rowid)';
2747 $sql .=
' WHERE e.fk_user_author = '.$fk_user;
2748 if (!empty($this->
id)) $sql .=
' AND d.rowid <> '.$this->id;
2749 $sql .=
' AND d.fk_c_type_fees = '.$rule->fk_c_type_fees;
2750 if ($mode ==
'day' || $mode ==
'EX_DAY') $sql .=
' AND d.date = \''.dol_print_date($this->date,
'%Y-%m-%d').
'\'';
2751 elseif ($mode ==
'mon' || $mode ==
'EX_MON') $sql .=
' AND DATE_FORMAT(d.date, \'%Y-%m\') = \''.dol_print_date($this->date,
'%Y-%m').
'\'';
2752 elseif ($mode ==
'year' || $mode ==
'EX_YEA') $sql .=
' AND DATE_FORMAT(d.date, \'%Y\') = \''.dol_print_date($this->date,
'%Y').
'\'';
2754 dol_syslog(
'ExpenseReportLine::getExpAmount');
2759 $num = $this->
db->num_rows(
$resql);
2762 $obj = $this->
db->fetch_object(
$resql);
2763 $amount = (double) $obj->total_amount;
2769 return $amount + $this->total_ttc;
2780 global $langs, $conf;
2785 $this->comments = trim($this->comments);
2787 $this->value_unit =
price2num($this->value_unit);
2788 if (empty($this->fk_c_exp_tax_cat)) $this->fk_c_exp_tax_cat = 0;
2793 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport_det SET";
2794 $sql .=
" comments='".$this->db->escape($this->comments).
"'";
2795 $sql .=
",value_unit=".$this->db->escape($this->value_unit);
2796 $sql .=
",qty=".$this->db->escape($this->qty);
2797 $sql .=
",date='".$this->db->idate($this->date).
"'";
2798 $sql .=
",total_ht=".$this->db->escape($this->total_ht).
"";
2799 $sql .=
",total_tva=".$this->db->escape($this->total_tva).
"";
2800 $sql .=
",total_ttc=".$this->db->escape($this->total_ttc).
"";
2801 $sql .=
",tva_tx=".$this->db->escape($this->
vatrate);
2802 $sql .=
",vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
2803 $sql .=
",rule_warning_message='".$this->db->escape($this->rule_warning_message).
"'";
2804 $sql .=
",fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat);
2805 $sql .=
",fk_ecm_files=".($this->fk_ecm_files > 0 ? $this->fk_ecm_files :
'null');
2806 if ($this->fk_c_type_fees) $sql .=
",fk_c_type_fees=".$this->db->escape($this->fk_c_type_fees);
2807 else $sql .=
",fk_c_type_fees=null";
2808 if ($this->fk_project > 0) $sql .=
",fk_projet=".$this->db->escape($this->fk_project);
2809 else $sql .=
",fk_projet=null";
2810 $sql .=
" WHERE rowid = ".$this->db->escape($this->
rowid ? $this->
rowid : $this->
id);
2812 dol_syslog(
"ExpenseReportLine::update sql=".$sql);
2818 $result = $tmpparent->fetch($this->fk_expensereport);
2821 $result = $tmpparent->update_price();
2825 $this->error = $tmpparent->error;
2826 $this->errors = $tmpparent->errors;
2830 $this->error = $tmpparent->error;
2831 $this->errors = $tmpparent->errors;
2840 $this->
db->commit();
2843 $this->error = $this->
db->lasterror();
2844 dol_syslog(
"ExpenseReportLine::update Error ".$this->error, LOG_ERR);
2845 $this->
db->rollback();
createFromClone(User $user, $fk_user_author)
Load an object from its id and create a new one in database.
getNextNumRef()
Return next reference of expense report not already used.
const STATUS_APPROVED
Classified approved.
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)
Update an expense report line.
const STATUS_VALIDATED
Validated (need to be paid)
LibStatut($status, $mode=0)
Returns the label of a status.
info($id)
Load information on object.
Class of expense report details lines.
static getRangeByUser(User $userauthor, $fk_c_exp_tax_cat)
Return an array of ranges for a user.
__construct($db)
Constructor.
applyOffset()
Method to apply the offset if needed.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
dol_now($mode= 'auto')
Return date for now.
getVentilExportCompta()
Return if object was dispatched into bookkeeping.
dol_delete_preview($object)
Delete all preview files linked to object instance.
Class to manage inventories.
delete_linked_contact($source= '', $code= '')
Delete all links between an object $this and all its contacts.
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.
Class to manage Dolibarr users.
const STATUS_CLOSED
Classified paid.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
setDeny($fuser, $details, $notrigger=0)
setDeny
const STATUS_CANCELED
Classified canceled.
fetch($rowid)
Fetch record for expense report detailed line.
periode_existe($fuser, $date_debut, $date_fin)
periode_existe
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
deleteline($rowid, $fuser= '')
deleteline
$conf db
API class for accounts.
const STATUS_REFUSED
Classified refused.
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...
set_unpaid($fuser, $notrigger=0)
set_unpaid
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
fetch_line_by_project($projectid, $user= '')
fetch_line_by_project
setValidate($fuser, $notrigger=0)
Set to status validate.
Class to manage third parties objects (customers, suppliers, prospects...)
update_totaux_del($ligne_total_ht, $ligne_total_tva)
Update total of an expense report when you delete a line.
checkRules($type=0, $seller= '')
Check constraint of rules and update price if needed.
update(User $user)
Update line.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
update_totaux_add($ligne_total_ht, $ligne_total_tva)
Update total of an expense report when you add a line.
load_board($user, $option= 'topay')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
fetch_users_approver_expensereport()
Return list of people with permission to validate expense reports.
getSumPayments()
Return amount of payments already done.
deleteEcmFiles($mode=0)
Delete related files of object in database.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
initAsSpecimen()
Initialise an instance with random values.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
set_paid($id, $fuser, $notrigger=0)
Classify the expense report as paid.
getExpAmount(ExpenseReportRule $rule, $fk_user, $mode= 'day')
Function to get total amount in expense reports for a same rule.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Class to manage Trips and Expenses.
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...
listOfTypes($active=1)
List of types.
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)
addline
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '')
Delete all links between an object $this.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
print $_SERVER["PHP_SELF"]
Edit parameters.
setApproved($fuser, $notrigger=0)
Set status to approved.
hasDelay($option)
Return if an expense report is late or not.
load_state_board()
Charge indicateurs this->nb pour le tableau de bord.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
set_cancel($fuser, $detail, $notrigger=0)
set_cancel
create($user, $notrigger=0)
Create object in database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk accordign to template module.
insert($notrigger=0, $fromaddline=false)
Insert a line of expense report.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
update($user, $notrigger=0, $userofexpensereport=null)
update
getNomUrl($withpicto=0, $max=0, $short=0, $moretitle= '', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
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.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
offsetAlreadyGiven()
If the sql find any rows then the ikoffset is already given (ikoffset is applied at the first expense...
__construct($db)
Constructor.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
static getAllRule($fk_c_type_fees= '', $date= '', $fk_user= '')
Return all rules or filtered by something.
recalculer($id)
recalculer TODO Replace this with call to update_price if not already done
update_price($exclspec=0, $roundingadjust= 'none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines)...
getLibStatut($mode=0)
Returns the label status.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
const STATUS_DRAFT
Draft status.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
set_save_from_refuse($fuser)
set_save_from_refuse
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.