32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinterligne.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsignedobject.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
45 use CommonSignedObject;
52 public $TRIGGER_PREFIX =
'FICHINTER';
54 public $fields = array(
55 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
56 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
57 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'position' => 20),
58 'fk_contrat' => array(
'type' =>
'integer:Contrat:contrat/class/contrat.class.php',
'label' =>
'Contract',
'enabled' =>
'isModEnabled("contract")',
'visible' => -1,
'position' => 25),
59 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
60 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
61 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
62 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
63 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
64 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
65 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
66 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
67 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 65),
68 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
69 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
70 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
71 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
72 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
73 'duree' => array(
'type' =>
'integer',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
74 'signed_status' => array(
'type' =>
'smallint(6)',
'label' =>
'SignedStatus',
'enabled' => 1,
'visible' => -1,
'position' => 101,
'arrayofkeyval' => array(0 =>
'NoSignature', 1 =>
'SignedSender', 2 =>
'SignedReceiver', 3 =>
'SignedReceiverOnline', 9 =>
'SignedAll')),
75 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
76 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
77 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
78 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 120),
79 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
80 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
81 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
82 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
88 public $element =
'fichinter';
93 public $fk_element =
'fk_fichinter';
98 public $table_element =
'fichinter';
103 public $table_element_line =
'fichinterdet';
108 public $class_element_line =
'FichinterLigne';
113 public $picto =
'intervention';
184 public $fk_contrat = 0;
200 public $extraparams = array();
205 public $lines = array();
237 public $date_delivery;
243 public $delivery_date_receipt;
249 public $user_author_id;
274 $sql =
"SELECT count(fi.rowid) as nb";
275 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
276 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
277 if (!$user->hasRight(
'societe',
'client',
'voir')) {
278 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
279 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
282 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
284 $resql = $this->db->query($sql);
286 while ($obj = $this->db->fetch_object($resql)) {
287 $this->nb[
"interventions"] = $obj->nb;
289 $this->db->free($resql);
292 dol_print_error($this->db);
293 $this->error = $this->db->error();
305 public function create($user, $notrigger = 0)
312 if (!empty($this->ref)) {
315 $this->error =
'ErrorRefAlreadyExists';
316 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
317 $this->db->rollback();
321 if (!is_numeric($this->duration)) {
324 if (!empty($this->ref_client)) {
325 $this->ref_client = trim($this->ref_client);
328 if ($this->socid <= 0) {
329 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
330 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
336 $result = $soc->fetch($this->socid);
342 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
346 $sql .=
", ref_client";
348 $sql .=
", fk_user_author";
349 $sql .=
", fk_user_modif";
350 $sql .=
", description";
351 $sql .=
", model_pdf";
352 $sql .=
", fk_projet";
353 $sql .=
", fk_contrat";
354 $sql .=
", fk_statut";
355 $sql .=
", signed_status";
356 $sql .=
", note_private";
357 $sql .=
", note_public";
360 $sql .= ((int) $this->socid);
361 $sql .=
", '".$this->db->idate($now).
"'";
362 $sql .=
", '".$this->db->escape($this->ref).
"'";
363 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
364 $sql .=
", ".((int) $this->entity);
365 $sql .=
", ".((int) $user->id);
366 $sql .=
", ".((int) $user->id);
367 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
368 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
369 $sql .=
", ".((int) $this->fk_project > 0 ? ((
int) $this->fk_project) : 0);
370 $sql .=
", ".((int) $this->fk_contrat > 0 ? ((
int) $this->fk_contrat) : 0);
371 $sql .=
", ".((int) $this->
status);
372 $sql .=
", ".((int) $this->signed_status);
373 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
374 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
377 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
378 $result = $this->db->query($sql);
380 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
383 $this->ref =
'(PROV'.$this->id.
')';
384 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
386 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
387 $resql = $this->db->query($sql);
401 if (!$error && $this->origin && $this->origin_id) {
404 dol_print_error($this->db);
409 if (!$error && !$notrigger) {
411 $result = $this->call_trigger(
'FICHINTER_CREATE', $user);
422 $this->db->rollback();
423 $this->error = implode(
',', $this->errors);
424 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
428 $this->error = $this->db->error();
429 $this->db->rollback();
441 public function update($user, $notrigger = 0)
445 if (!is_numeric($this->duration)) {
448 if (!
dol_strlen((
string) $this->fk_project)) {
449 $this->fk_project = 0;
451 if (!empty($this->ref_client)) {
452 $this->ref_client = trim($this->ref_client);
459 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
460 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
461 $sql .=
", duree = ".((int) $this->duration);
462 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
463 if ((
int) $this->fk_project > 0) {
464 $sql .=
", fk_projet = ".((int) $this->fk_project);
466 if (isset($this->datec)) {
467 $sql .=
", datec = ".($this->datec ?
"'".$this->db->idate($this->datec).
"'" :
"null");
469 if (isset($this->datev)) {
470 $sql .=
", date_valid = ".($this->datev ?
"'".$this->db->idate($this->datev).
"'" :
"null");
472 if (isset($this->datet)) {
473 $sql .=
", datet = ".($this->datet ?
"'".$this->db->idate($this->datet).
"'" :
"null");
475 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
476 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
477 $sql .=
", fk_user_modif = ".((int) $user->id);
478 $sql .=
" WHERE rowid = ".((int) $this->
id);
480 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
481 if ($this->db->query($sql)) {
487 if (!$error && !$notrigger) {
489 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
492 $this->db->rollback();
501 $this->error = $this->db->error();
502 $this->db->rollback();
515 public function fetch($rowid, $ref =
'', $ref_ext =
'')
517 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
518 $sql .=
" f.datec, f.dateo, f.datee, f.datet,";
519 $sql .=
" f.date_valid as datev,";
520 $sql .=
" f.tms as datem,";
521 $sql .=
" f.fk_user_author, f.fk_user_modif,";
522 $sql .=
" f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.last_main_doc, f.extraparams, fk_contrat, f.entity as entity";
523 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
524 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
526 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
527 } elseif ($ref_ext) {
528 $sql .=
" AND f.ref_ext = '".$this->db->escape($ref_ext).
"'";
530 $sql .=
" AND f.rowid = ".((int) $rowid);
533 $resql = $this->db->query($sql);
535 if ($this->db->num_rows($resql)) {
536 $obj = $this->db->fetch_object($resql);
538 $this->
id = $obj->rowid;
539 $this->
ref = $obj->ref;
540 $this->ref_client = $obj->ref_client;
542 $this->socid = $obj->fk_soc;
543 $this->
status = $obj->status;
544 $this->statut = $obj->status;
545 $this->signed_status = $obj->signed_status;
546 $this->duration = $obj->duree;
547 $this->datec = $this->db->jdate($obj->datec);
548 $this->dateo = $this->db->jdate($obj->dateo);
549 $this->datee = $this->db->jdate($obj->datee);
550 $this->datet = $this->db->jdate($obj->datet);
551 $this->datev = $this->db->jdate($obj->datev);
552 $this->datem = $this->db->jdate($obj->datem);
553 $this->fk_project = $obj->fk_project;
554 $this->note_public = $obj->note_public;
555 $this->note_private = $obj->note_private;
556 $this->model_pdf = $obj->model_pdf;
557 $this->fk_contrat = $obj->fk_contrat;
558 $this->entity = $obj->entity;
560 $this->user_author_id = $this->user_creation_id = $obj->fk_user_author;
561 $this->user_modification_id = $obj->fk_user_modif;
563 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
565 $this->last_main_doc = $obj->last_main_doc;
577 $this->db->free($resql);
583 $this->error = $this->db->lasterror();
599 if ($this->
status <= self::STATUS_DRAFT) {
603 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
609 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
610 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
611 $sql .=
" WHERE rowid = ".((int) $this->
id);
613 $resql = $this->db->query($sql);
616 $result = $this->call_trigger(
'FICHINTER_UNVALIDATE', $user);
627 $this->db->rollback();
631 $this->db->rollback();
632 $this->error = $this->db->lasterror();
647 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
651 if ($this->
status != self::STATUS_VALIDATED) {
657 if ((preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
658 if (empty($this->thirdparty)) {
663 $num = (string) $this->
ref;
667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
668 $sql .=
" SET fk_statut = 1";
669 $sql .=
", ref = '".$this->db->escape($num).
"'";
670 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
671 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
672 $sql .=
" WHERE rowid = ".((int) $this->
id);
673 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
675 $sql .=
" AND fk_statut = 0";
677 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
678 $resql = $this->db->query($sql);
680 dol_print_error($this->db);
684 if (!$error && !$notrigger) {
686 $result = $this->call_trigger(
'FICHINTER_VALIDATE', $user);
694 $this->oldref = $this->ref;
697 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
698 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
701 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
702 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
703 $resql = $this->db->query($sql);
706 $this->error = $this->db->lasterror();
708 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
709 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
710 $resql = $this->db->query($sql);
713 $this->error = $this->db->lasterror();
719 $dirsource =
$conf->ficheinter->dir_output.
'/'.$oldref;
720 $dirdest =
$conf->ficheinter->dir_output.
'/'.$newref;
721 if (!$error && file_exists($dirsource)) {
722 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
724 if (@rename($dirsource, $dirdest)) {
727 $listoffiles =
dol_dir_list(
$conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
728 foreach ($listoffiles as $fileentry) {
729 $dirsource = $fileentry[
'name'];
730 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
731 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
732 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
733 @rename($dirsource, $dirdest);
745 $this->date_validation = $now;
749 $this->db->rollback();
750 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
769 if ($this->
status == self::STATUS_CANCELED) {
775 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
776 $sql .=
" SET fk_statut = ".self::STATUS_CANCELED.
",";
777 $sql .=
" fk_user_modif = ".((int) $user->id);
778 $sql .=
" WHERE rowid = ".((int) $this->
id);
779 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
780 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
782 dol_syslog(get_class($this).
"::setCanceled", LOG_DEBUG);
783 if ($this->db->query($sql)) {
786 $result = $this->call_trigger(
'FICHINTER_CANCEL', $user);
799 foreach ($this->errors as $errmsg) {
800 dol_syslog(get_class($this).
"::setCanceled ".$errmsg, LOG_ERR);
801 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
803 $this->db->rollback();
807 $this->error = $this->db->error();
808 $this->db->rollback();
827 if ($this->statut != self::STATUS_CANCELED && $this->statut != self::STATUS_CLOSED) {
828 dol_syslog(get_class($this).
"::setReopen intervention has not status closed or canceled", LOG_WARNING);
834 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'fichinter';
835 $sql .=
' SET fk_statut='.self::STATUS_VALIDATED;
836 $sql .=
", fk_user_modif = ".((int) $user->id);
837 $sql .=
" WHERE rowid = ".((int) $this->
id);
839 dol_syslog(get_class($this).
"::setReopen", LOG_DEBUG);
840 $resql = $this->db->query($sql);
844 $result = $this->call_trigger(
'FICHINTER_REOPEN', $user);
852 $this->error = $this->db->lasterror();
853 dol_print_error($this->db);
864 foreach ($this->errors as $errmsg) {
865 dol_syslog(get_class($this).
"::setReopen ".$errmsg, LOG_ERR);
866 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
868 $this->db->rollback();
886 if ($this->
status == self::STATUS_CLOSED) {
893 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
894 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
895 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
896 $sql .=
" fk_user_modif = " . ((int) $user->id);
897 $sql .=
" WHERE rowid = " . ((int) $this->
id);
899 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
901 if ($this->db->query($sql)) {
904 $result = $this->call_trigger(
'FICHINTER_CLOSE', $user);
917 $this->db->rollback();
921 $this->error = $this->db->lasterror();
922 $this->db->rollback();
937 $this->author =
new User($this->db);
938 $this->author->fetch($this->user_creation_id);
940 $thm = $this->author->thm;
942 foreach ($this->lines as $line) {
943 $amount += ($line->duration / 60 / 60 * (float) $thm);
961 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
965 $outputlangs->load(
"interventions");
970 if (!empty($this->model_pdf)) {
971 $modele = $this->model_pdf;
977 $modelpath =
"core/modules/fichinter/doc/";
979 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
990 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
1006 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1007 $langs->load(
"interventions");
1008 $langs->load(
"propal");
1012 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
1015 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
1017 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
1022 $statuscode =
'status'.$status;
1023 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
1024 $statuscode =
'status6';
1028 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
1029 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
1031 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
1044 $langs->load(
'interventions');
1047 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
1048 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1049 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1064 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
1066 global
$conf, $langs, $hookmanager;
1068 if (!empty(
$conf->dol_no_mouse_hover)) {
1075 'objecttype' => $this->element,
1076 'option' => $option,
1078 $classfortooltip =
'classfortooltip';
1081 $classfortooltip =
'classforajaxtooltip';
1082 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1088 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
1090 if ($option !==
'nolink') {
1092 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1093 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1094 $add_save_lastsearch_values = 1;
1096 if ($add_save_lastsearch_values) {
1097 $url .=
'&save_lastsearch_values=1';
1102 if (empty($notooltip)) {
1104 $label = $langs->trans(
"ShowIntervention");
1105 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1107 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1108 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1110 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1113 if ($option ==
'nolink') {
1114 $linkstart =
'<span';
1116 $linkstart =
'<a href="'.$url.
'"';
1118 $linkstart .= $linkclose.
'>';
1119 if ($option ==
'nolink') {
1120 $linkend =
'</span>';
1125 $result .= $linkstart;
1127 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1130 if ($withpicto != 2) {
1131 $result .= $this->ref;
1134 $result .= $linkend;
1137 $hookmanager->initHooks(array(
'interventiondao'));
1138 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1139 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1141 $result = $hookmanager->resPrint;
1143 $result .= $hookmanager->resPrint;
1159 global
$conf, $db, $langs;
1160 $langs->load(
"interventions");
1169 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1171 foreach ($dirmodels as $reldir) {
1175 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1179 dol_print_error(
null,
"Failed to include file ".$file);
1183 $obj =
new $classname();
1184 '@phan-var-force ModeleNumRefFicheinter $obj';
1186 $numref = $obj->getNextValue($soc, $this);
1188 if ($numref !=
"") {
1191 dol_print_error($db,
"Fichinter::getNextNumRef ".$obj->error);
1195 $langs->load(
"errors");
1196 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1209 $sql =
"SELECT f.rowid,";
1210 $sql .=
" f.datec,";
1211 $sql .=
" f.tms as date_modification,";
1212 $sql .=
" f.date_valid as datev,";
1213 $sql .=
" f.fk_user_author,";
1214 $sql .=
" f.fk_user_modif as fk_user_modification,";
1215 $sql .=
" f.fk_user_valid";
1216 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1217 $sql .=
" WHERE f.rowid = ".((int) $id);
1219 $resql = $this->db->query($sql);
1221 if ($this->db->num_rows($resql)) {
1222 $obj = $this->db->fetch_object($resql);
1224 $this->
id = $obj->rowid;
1226 $this->date_creation = $this->db->jdate($obj->datec);
1227 $this->date_modification = $this->db->jdate($obj->date_modification);
1228 $this->date_validation = $this->db->jdate($obj->datev);
1230 $this->user_creation_id = $obj->fk_user_author;
1231 $this->user_validation_id = $obj->fk_user_valid;
1232 $this->user_modification_id = $obj->fk_user_modification;
1234 $this->db->free($resql);
1236 dol_print_error($this->db);
1247 public function delete(
User $user, $notrigger = 0)
1249 global
$conf, $langs;
1250 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1258 $result = $this->call_trigger(
'FICHINTER_DELETE', $user);
1261 $this->db->rollback();
1277 $this->error =
'ErrorFailToDeleteLinkedContact';
1283 $main = MAIN_DB_PREFIX.
'fichinterdet';
1284 $ef = $main.
"_extrafields";
1285 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1287 $resql = $this->db->query($sql);
1294 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1295 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1297 $resql = $this->db->query($sql);
1313 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1314 $sql .=
" WHERE rowid = ".((int) $this->
id);
1317 $resql = $this->db->query($sql);
1330 if ($conf->ficheinter->dir_output && !empty($fichinterref)) {
1331 $dir =
$conf->ficheinter->dir_output.
"/".$fichinterref;
1332 $file =
$conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1333 if (file_exists($file)) {
1337 $langs->load(
"errors");
1338 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1342 if (file_exists($dir)) {
1344 $langs->load(
"errors");
1345 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1353 $this->db->commit();
1356 $this->db->rollback();
1372 if ($user->hasRight(
'ficheinter',
'creer')) {
1375 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1376 $sql .=
" SET datei = '".$this->db->idate($delivery_date_receipt).
"'";
1377 $sql .=
" WHERE rowid = ".((int) $this->
id);
1378 $sql .=
" AND fk_statut = 0";
1380 if ($this->db->query($sql)) {
1381 $this->date_delivery = $delivery_date_receipt;
1382 $this->delivery_date_receipt = $delivery_date_receipt;
1384 $result = $this->call_trigger($this->TRIGGER_PREFIX .
'_MODIFY', $user);
1386 $this->db->rollback();
1390 $this->db->commit();
1393 $this->error = $this->db->error();
1394 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1395 $this->db->rollback();
1414 if ($user->hasRight(
'ficheinter',
'creer')) {
1417 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1418 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1419 $sql .=
" fk_user_modif = ".((int) $user->id);
1420 $sql .=
" WHERE rowid = ".((int) $this->
id);
1422 if ($this->db->query($sql)) {
1425 $result = $this->call_trigger($this->TRIGGER_PREFIX .
'_MODIFY', $user);
1427 $this->db->rollback();
1431 $this->db->commit();
1434 $this->error = $this->db->error();
1435 dol_syslog(
"Fichinter::set_description Erreur SQL");
1436 $this->db->rollback();
1456 if ($user->hasRight(
'ficheinter',
'creer')) {
1459 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1460 $sql .=
" SET fk_contrat = ".((int) $contractid);
1461 $sql .=
" WHERE rowid = ".((int) $this->
id);
1463 if ($this->db->query($sql)) {
1464 $this->fk_contrat = $contractid;
1466 $result = $this->call_trigger($this->TRIGGER_PREFIX .
'_MODIFY', $user);
1468 $this->db->rollback();
1472 $this->db->commit();
1475 $this->error = $this->db->error();
1476 $this->db->rollback();
1497 global $hookmanager, $langs;
1498 $langs->load(
"errors");
1505 foreach ($this->lines as $line) {
1506 $line->fetch_optionals();
1510 $objFrom = clone $this;
1513 if (!empty($socid) && $socid != $this->socid) {
1514 $objsoc =
new Societe($this->db);
1516 if ($objsoc->fetch($socid) > 0) {
1517 $this->socid = $objsoc->id;
1520 $this->fk_project = 0;
1521 $this->fk_delivery_address = 0;
1533 $this->user_author_id = $user->id;
1534 $this->user_validation_id = 0;
1535 $this->date_creation =
'';
1536 $this->date_validation =
'';
1537 $this->signed_status = 0;
1539 $this->ref_client =
'';
1541 if (!$clone_notes) {
1542 $this->note_private =
'';
1543 $this->note_public =
'';
1547 $this->context[
'createfromclone'] =
'createfromclone';
1548 $result = $this->
create($user);
1555 foreach ($this->lines as $line) {
1556 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1560 if (is_object($hookmanager)) {
1561 $parameters = array(
'objFrom' => $objFrom);
1563 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1572 if ($clone_contacts) {
1573 foreach (array(
'internal',
'external') as $source) {
1574 $tab = $objFrom->liste_contact(-1, $source);
1575 if (is_array($tab) && count($tab) > 0) {
1576 foreach ($tab as $contacttoadd) {
1578 $contacttoadd[
'id'],
1579 $contacttoadd[
'code'],
1580 $contacttoadd[
'source']
1582 if ($this->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1583 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1585 } elseif ($retAddContact < 0) {
1589 } elseif ($tab < 0) {
1590 $this->error .= $objFrom->error;
1596 unset($this->context[
'createfromclone']);
1600 $this->db->commit();
1603 $this->db->rollback();
1623 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [], $type = 0, $rang = -1, $special_code = 0)
1625 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration, $type, $rang, $special_code");
1627 if ($this->
status == self::STATUS_DRAFT) {
1633 $line->fk_fichinter = $fichinterid;
1634 $line->desc = $desc;
1635 $line->date = $date_intervention;
1636 $line->datei = $date_intervention;
1637 $line->duration = $duration;
1638 $line->product_type = $type;
1639 $line->rang = $rang;
1640 $line->special_code = $special_code;
1643 if (is_array($array_options) && count($array_options) > 0) {
1644 $line->array_options = $array_options;
1647 $result = $line->insert($user);
1650 $this->db->commit();
1653 $this->error = $this->db->error();
1654 $this->db->rollback();
1678 $this->
ref =
'SPECIMEN';
1679 $this->ref_client =
'SPECIMEN CLIENT';
1680 $this->specimen = 1;
1682 $this->datec = $now;
1683 $this->note_private =
'Private note';
1684 $this->note_public =
'SPECIMEN';
1685 $this->duration = 0;
1686 $this->user_creation_id = 1;
1689 while ($xnbp < $nbp) {
1691 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1692 $line->date = ($now - 3600 * (1 + $xnbp));
1693 $line->datei = ($now - 3600 * (1 + $xnbp));
1694 $line->duration = 600;
1695 $line->fk_fichinter = 0;
1696 $this->lines[$xnbp] = $line;
1699 $this->duration += $line->duration;
1714 $this->lines = array();
1716 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams, special_code";
1717 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1718 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1719 $sql .=
" ORDER BY rang ASC, date ASC";
1721 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1723 $resql = $this->db->query($sql);
1725 $num = $this->db->num_rows($resql);
1728 $objp = $this->db->fetch_object($resql);
1731 $line->id = $objp->rowid;
1732 $line->fk_fichinter = $objp->fk_fichinter;
1733 $line->desc = $objp->description;
1734 $line->duration = $objp->duree;
1735 $line->special_code = (int) ($objp->special_code ?? 0);
1736 if ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
1738 $line->qty = (int) $objp->duree;
1741 $line->qty = round($objp->duree / 3600, 2);
1743 $line->date = $this->db->jdate($objp->date);
1744 $line->datei = $this->db->jdate($objp->date);
1745 $line->rang = $objp->rang;
1746 $line->product_type = 1;
1747 $line->fetch_optionals();
1749 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1751 $this->lines[$i] = $line;
1754 $this->db->free($resql);
1758 $this->error = $this->db->error();
1792 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1793 return parent::setCategoriesCommon($categories, Categorie::TYPE_FICHINTER);
1807 if ($user->hasRight(
'ficheinter',
'creer')) {
1814 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1815 $sql .=
" WHERE rowid = ".((int) $this->
id);
1817 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1818 $resql = $this->db->query($sql);
1820 $this->errors[] = $this->db->error();
1825 $this->ref_client = $ref_client;
1828 if (!$notrigger && empty($error)) {
1830 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
1838 $this->db->commit();
1841 foreach ($this->errors as $errmsg) {
1842 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1843 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1845 $this->db->rollback();
1860 public function getKanbanView($option =
'', $arraydata =
null)
1864 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1866 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1867 $return .=
'<div class="info-box info-box-sm">';
1868 $return .=
'<span class="info-box-icon bg-infobox-action">';
1869 $return .= img_picto(
'', $this->picto);
1870 $return .=
'</span>';
1871 $return .=
'<div class="info-box-content">';
1872 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
1873 if ($selected >= 0) {
1874 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1876 if (!empty($arraydata[
'thirdparty'])) {
1877 $tmpthirdparty = $arraydata[
'thirdparty'];
1878 '@phan-var-force Societe $tmpthirdparty';
1880 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1882 if (!empty($this->duration)) {
1883 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1885 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1886 $return .=
'</div>';
1887 $return .=
'</div>';
1888 $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.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage Dolibarr database access.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
createFromClone(User $user, $socid=0, $clone_contacts=false, $clone_notes=false)
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setClose($user, $notrigger=0)
Close intervention.
const STATUS_DRAFT
Draft status.
create($user, $notrigger=0)
Create an intervention into data base.
setCategories($categories)
Sets object to given categories.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
const STATUS_CANCELED
Canceled status.
set_date_delivery($user, $delivery_date_receipt)
Defines a delivery date of the receipt of intervention.
const STATUS_VALIDATED
Validated status.
fetch($rowid, $ref='', $ref_ext='')
Fetch a intervention.
setReopen($user, $notrigger=0)
Tag the intervention as validated (opened) Function used when the intervention is reopened after bein...
const STATUS_CLOSED
Closed.
setDraft($user)
Set status to draft.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
getAmount()
Returns amount based on user thm.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[], $type=0, $rang=-1, $special_code=0)
Adding a line of intervention into data base.
setRefClient($user, $ref_client, $notrigger=0)
Set customer reference number.
set_contrat($user, $contractid)
Link intervention to a contract.
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
loadStateBoard()
Load indicators into this->nb for board.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load information on object.
setCanceled($user, $notrigger=0)
Cancel an intervention.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
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...
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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.
setEntity($currentobject)
Set entity id to use when to create an object.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.