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, CommonSubtotal;
51 public $TRIGGER_PREFIX =
'FICHINTER';
53 public $fields = array(
54 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
55 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
56 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'position' => 20),
57 'fk_contrat' => array(
'type' =>
'integer:Contrat:contrat/class/contrat.class.php',
'label' =>
'Contract',
'enabled' =>
'isModEnabled("contract")',
'visible' => -1,
'position' => 25),
58 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
59 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
60 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
61 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
62 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
63 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
64 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
65 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
66 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 65),
67 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
68 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
69 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
70 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
71 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
72 'duree' => array(
'type' =>
'integer',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
73 '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')),
74 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
75 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
76 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
77 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 120),
78 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
79 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
80 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
81 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
87 public $element =
'fichinter';
92 public $fk_element =
'fk_fichinter';
97 public $table_element =
'fichinter';
102 public $table_element_line =
'fichinterdet';
107 public $class_element_line =
'FichinterLigne';
112 public $picto =
'intervention';
183 public $fk_contrat = 0;
199 public $extraparams = array();
204 public $lines = array();
231 public $date_delivery;
237 public $delivery_date_receipt;
243 public $user_author_id;
268 $sql =
"SELECT count(fi.rowid) as nb";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
271 if (!$user->hasRight(
'societe',
'client',
'voir')) {
272 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
273 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
276 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
278 $resql = $this->db->query($sql);
280 while ($obj = $this->db->fetch_object($resql)) {
281 $this->nb[
"interventions"] = $obj->nb;
283 $this->db->free($resql);
287 $this->error = $this->db->error();
299 public function create($user, $notrigger = 0)
306 if (!empty($this->ref)) {
309 $this->error =
'ErrorRefAlreadyExists';
310 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
311 $this->db->rollback();
315 if (!is_numeric($this->duration)) {
318 if (!empty($this->ref_client)) {
319 $this->ref_client = trim($this->ref_client);
322 if ($this->socid <= 0) {
323 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
324 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
330 $result = $soc->fetch($this->socid);
336 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
340 $sql .=
", ref_client";
342 $sql .=
", fk_user_author";
343 $sql .=
", fk_user_modif";
344 $sql .=
", description";
345 $sql .=
", model_pdf";
346 $sql .=
", fk_projet";
347 $sql .=
", fk_contrat";
348 $sql .=
", fk_statut";
349 $sql .=
", signed_status";
350 $sql .=
", note_private";
351 $sql .=
", note_public";
354 $sql .= $this->socid;
355 $sql .=
", '".$this->db->idate($now).
"'";
356 $sql .=
", '".$this->db->escape($this->ref).
"'";
357 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
358 $sql .=
", ".((int) $this->entity);
359 $sql .=
", ".((int) $user->id);
360 $sql .=
", ".((int) $user->id);
361 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
362 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
363 $sql .=
", ".((int) $this->fk_project > 0 ? ((
int) $this->fk_project) : 0);
364 $sql .=
", ".((int) $this->fk_contrat > 0 ? ((
int) $this->fk_contrat) : 0);
365 $sql .=
", ".((int) $this->
status);
366 $sql .=
", ".((int) $this->signed_status);
367 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
368 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
371 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
372 $result = $this->db->query($sql);
374 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
377 $this->ref =
'(PROV'.$this->id.
')';
378 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
380 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
381 $resql = $this->db->query($sql);
395 if (!$error && $this->origin && $this->origin_id) {
403 if (!$error && !$notrigger) {
405 $result = $this->call_trigger(
'FICHINTER_CREATE', $user);
416 $this->db->rollback();
417 $this->error = implode(
',', $this->errors);
418 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
422 $this->error = $this->db->error();
423 $this->db->rollback();
435 public function update($user, $notrigger = 0)
439 if (!is_numeric($this->duration)) {
442 if (!
dol_strlen((
string) $this->fk_project)) {
443 $this->fk_project = 0;
445 if (!empty($this->ref_client)) {
446 $this->ref_client = trim($this->ref_client);
453 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
454 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
455 $sql .=
", duree = ".((int) $this->duration);
456 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
457 if ((
int) $this->fk_project > 0) {
458 $sql .=
", fk_projet = ".((int) $this->fk_project);
460 if (isset($this->datec)) {
461 $sql .=
", datec = ".($this->datec ?
"'".$this->db->idate($this->datec).
"'" :
"null");
463 if (isset($this->datev)) {
464 $sql .=
", date_valid = ".($this->datev ?
"'".$this->db->idate($this->datev).
"'" :
"null");
466 if (isset($this->datet)) {
467 $sql .=
", datet = ".($this->datet ?
"'".$this->db->idate($this->datet).
"'" :
"null");
469 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
470 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
471 $sql .=
", fk_user_modif = ".((int) $user->id);
472 $sql .=
" WHERE rowid = ".((int) $this->
id);
474 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
475 if ($this->db->query($sql)) {
481 if (!$error && !$notrigger) {
483 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
486 $this->db->rollback();
495 $this->error = $this->db->error();
496 $this->db->rollback();
509 public function fetch($rowid, $ref =
'', $ref_ext =
'')
511 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
512 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
513 $sql .=
" f.date_valid as datev,";
514 $sql .=
" f.tms as datem,";
515 $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";
516 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
517 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
519 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
520 } elseif ($ref_ext) {
521 $sql .=
" AND f.ref_ext = '".$this->db->escape($ref_ext).
"'";
523 $sql .=
" AND f.rowid = ".((int) $rowid);
526 $resql = $this->db->query($sql);
528 if ($this->db->num_rows($resql)) {
529 $obj = $this->db->fetch_object($resql);
531 $this->
id = $obj->rowid;
532 $this->
ref = $obj->ref;
533 $this->ref_client = $obj->ref_client;
535 $this->socid = $obj->fk_soc;
536 $this->
status = $obj->status;
537 $this->statut = $obj->status;
538 $this->signed_status = $obj->signed_status;
539 $this->duration = $obj->duree;
540 $this->datec = $this->db->jdate($obj->datec);
541 $this->dateo = $this->db->jdate($obj->dateo);
542 $this->datee = $this->db->jdate($obj->datee);
543 $this->datet = $this->db->jdate($obj->datet);
544 $this->datev = $this->db->jdate($obj->datev);
545 $this->datem = $this->db->jdate($obj->datem);
546 $this->fk_project = $obj->fk_project;
547 $this->note_public = $obj->note_public;
548 $this->note_private = $obj->note_private;
549 $this->model_pdf = $obj->model_pdf;
550 $this->fk_contrat = $obj->fk_contrat;
551 $this->entity = $obj->entity;
553 $this->user_creation_id = $obj->fk_user_author;
555 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
557 $this->last_main_doc = $obj->last_main_doc;
569 $this->db->free($resql);
575 $this->error = $this->db->lasterror();
591 if ($this->
status <= self::STATUS_DRAFT) {
595 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
601 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
602 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
603 $sql .=
" WHERE rowid = ".((int) $this->
id);
605 $resql = $this->db->query($sql);
608 $result = $this->call_trigger(
'FICHINTER_UNVALIDATE', $user);
619 $this->db->rollback();
623 $this->db->rollback();
624 $this->error = $this->db->lasterror();
639 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
643 if ($this->
status != self::STATUS_VALIDATED) {
649 if ((preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
652 $num = (string) $this->
ref;
656 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
657 $sql .=
" SET fk_statut = 1";
658 $sql .=
", ref = '".$this->db->escape($num).
"'";
659 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
660 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
661 $sql .=
" WHERE rowid = ".((int) $this->
id);
662 $sql .=
" AND entity = ".((int) $this->entity);
664 $sql .=
" AND fk_statut = 0";
666 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
667 $resql = $this->db->query($sql);
673 if (!$error && !$notrigger) {
675 $result = $this->call_trigger(
'FICHINTER_VALIDATE', $user);
683 $this->oldref = $this->ref;
686 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
687 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
690 $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).
"'";
691 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
692 $resql = $this->db->query($sql);
695 $this->error = $this->db->lasterror();
697 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
698 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
699 $resql = $this->db->query($sql);
702 $this->error = $this->db->lasterror();
708 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
709 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
710 if (!$error && file_exists($dirsource)) {
711 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
713 if (@rename($dirsource, $dirdest)) {
716 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
717 foreach ($listoffiles as $fileentry) {
718 $dirsource = $fileentry[
'name'];
719 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
720 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
721 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
722 @rename($dirsource, $dirdest);
734 $this->date_validation = $now;
738 $this->db->rollback();
739 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
760 if ($this->
status == self::STATUS_CLOSED) {
767 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
768 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
769 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
770 $sql .=
" fk_user_modif = " . ((int) $user->id);
771 $sql .=
" WHERE rowid = " . ((int) $this->
id);
773 $sql .=
" AND entity = " . ((int) $conf->entity);
775 if ($this->db->query($sql)) {
778 $result = $this->call_trigger(
'FICHINTER_CLOSE', $user);
791 $this->db->rollback();
795 $this->error = $this->db->lasterror();
796 $this->db->rollback();
811 $this->author =
new User($this->db);
812 $this->author->fetch($this->user_creation_id);
814 $thm = $this->author->thm;
816 foreach ($this->lines as $line) {
817 $amount += ($line->duration / 60 / 60 * (float) $thm);
835 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
839 $outputlangs->load(
"interventions");
844 if (!empty($this->model_pdf)) {
845 $modele = $this->model_pdf;
851 $modelpath =
"core/modules/fichinter/doc/";
853 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
864 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
880 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
881 $langs->load(
"interventions");
882 $langs->load(
"propal");
886 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
890 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
894 $statuscode =
'status'.$status;
895 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
896 $statuscode =
'status6';
900 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
901 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
903 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
916 $langs->load(
'interventions');
919 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
920 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
921 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
936 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
938 global $conf, $langs, $hookmanager;
940 if (!empty($conf->dol_no_mouse_hover)) {
947 'objecttype' => $this->element,
950 $classfortooltip =
'classfortooltip';
953 $classfortooltip =
'classforajaxtooltip';
954 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
960 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
962 if ($option !==
'nolink') {
964 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
965 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
966 $add_save_lastsearch_values = 1;
968 if ($add_save_lastsearch_values) {
969 $url .=
'&save_lastsearch_values=1';
974 if (empty($notooltip)) {
976 $label = $langs->trans(
"ShowIntervention");
977 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
979 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
980 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
982 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
985 if ($option ==
'nolink') {
986 $linkstart =
'<span';
988 $linkstart =
'<a href="'.$url.
'"';
990 $linkstart .= $linkclose.
'>';
991 if ($option ==
'nolink') {
992 $linkend =
'</span>';
997 $result .= $linkstart;
999 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1002 if ($withpicto != 2) {
1003 $result .= $this->ref;
1006 $result .= $linkend;
1009 $hookmanager->initHooks(array(
'interventiondao'));
1010 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1011 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1013 $result = $hookmanager->resPrint;
1015 $result .= $hookmanager->resPrint;
1031 global $conf, $db, $langs;
1032 $langs->load(
"interventions");
1041 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1043 foreach ($dirmodels as $reldir) {
1047 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1055 $obj =
new $classname();
1056 '@phan-var-force ModeleNumRefFicheinter $obj';
1058 $numref = $obj->getNextValue($soc, $this);
1060 if ($numref !=
"") {
1067 $langs->load(
"errors");
1068 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1081 $sql =
"SELECT f.rowid,";
1082 $sql .=
" f.datec,";
1083 $sql .=
" f.tms as date_modification,";
1084 $sql .=
" f.date_valid as datev,";
1085 $sql .=
" f.fk_user_author,";
1086 $sql .=
" f.fk_user_modif as fk_user_modification,";
1087 $sql .=
" f.fk_user_valid";
1088 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1089 $sql .=
" WHERE f.rowid = ".((int) $id);
1091 $resql = $this->db->query($sql);
1093 if ($this->db->num_rows($resql)) {
1094 $obj = $this->db->fetch_object($resql);
1096 $this->
id = $obj->rowid;
1098 $this->date_creation = $this->db->jdate($obj->datec);
1099 $this->date_modification = $this->db->jdate($obj->date_modification);
1100 $this->date_validation = $this->db->jdate($obj->datev);
1102 $this->user_creation_id = $obj->fk_user_author;
1103 $this->user_validation_id = $obj->fk_user_valid;
1104 $this->user_modification_id = $obj->fk_user_modification;
1106 $this->db->free($resql);
1119 public function delete(
User $user, $notrigger = 0)
1121 global $conf, $langs;
1122 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1130 $result = $this->call_trigger(
'FICHINTER_DELETE', $user);
1133 $this->db->rollback();
1149 $this->error =
'ErrorFailToDeleteLinkedContact';
1155 $main = MAIN_DB_PREFIX.
'fichinterdet';
1156 $ef = $main.
"_extrafields";
1157 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1159 $resql = $this->db->query($sql);
1166 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1167 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1169 $resql = $this->db->query($sql);
1185 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1186 $sql .=
" WHERE rowid = ".((int) $this->
id);
1189 $resql = $this->db->query($sql);
1202 if ($conf->ficheinter->dir_output) {
1203 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1204 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1205 if (file_exists($file)) {
1209 $langs->load(
"errors");
1210 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1214 if (file_exists($dir)) {
1216 $langs->load(
"errors");
1217 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1225 $this->db->commit();
1228 $this->db->rollback();
1244 if ($user->hasRight(
'ficheinter',
'creer')) {
1245 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1246 $sql .=
" SET datei = '".$this->db->idate($delivery_date_receipt).
"'";
1247 $sql .=
" WHERE rowid = ".((int) $this->
id);
1248 $sql .=
" AND fk_statut = 0";
1250 if ($this->db->query($sql)) {
1251 $this->date_delivery = $delivery_date_receipt;
1252 $this->delivery_date_receipt = $delivery_date_receipt;
1255 $this->error = $this->db->error();
1256 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1275 if ($user->hasRight(
'ficheinter',
'creer')) {
1276 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1277 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1278 $sql .=
" fk_user_modif = ".((int) $user->id);
1279 $sql .=
" WHERE rowid = ".((int) $this->
id);
1281 if ($this->db->query($sql)) {
1285 $this->error = $this->db->error();
1286 dol_syslog(
"Fichinter::set_description Erreur SQL");
1306 if ($user->hasRight(
'ficheinter',
'creer')) {
1307 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1308 $sql .=
" SET fk_contrat = ".((int) $contractid);
1309 $sql .=
" WHERE rowid = ".((int) $this->
id);
1311 if ($this->db->query($sql)) {
1312 $this->fk_contrat = $contractid;
1315 $this->error = $this->db->error();
1336 global $hookmanager, $langs;
1337 $langs->load(
"errors");
1344 foreach ($this->lines as $line) {
1345 $line->fetch_optionals();
1349 $objFrom = clone $this;
1352 if (!empty($socid) && $socid != $this->socid) {
1353 $objsoc =
new Societe($this->db);
1355 if ($objsoc->fetch($socid) > 0) {
1356 $this->socid = $objsoc->id;
1359 $this->fk_project = 0;
1360 $this->fk_delivery_address = 0;
1372 $this->user_author_id = $user->id;
1373 $this->user_validation_id = 0;
1374 $this->date_creation =
'';
1375 $this->date_validation =
'';
1377 $this->ref_client =
'';
1379 if (!$clone_notes) {
1380 $this->note_private =
'';
1381 $this->note_public =
'';
1385 $this->context[
'createfromclone'] =
'createfromclone';
1386 $result = $this->
create($user);
1393 foreach ($this->lines as $line) {
1394 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1398 if (is_object($hookmanager)) {
1399 $parameters = array(
'objFrom' => $objFrom);
1401 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1410 if ($clone_contacts) {
1411 foreach (array(
'internal',
'external') as $source) {
1412 $tab = $objFrom->liste_contact(-1, $source);
1413 if (is_array($tab) && count($tab) > 0) {
1414 foreach ($tab as $contacttoadd) {
1416 $contacttoadd[
'id'],
1417 $contacttoadd[
'code'],
1418 $contacttoadd[
'source']
1420 if ($this->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1421 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1423 } elseif ($retAddContact < 0) {
1427 } elseif ($tab < 0) {
1428 $this->error .= $objFrom->error;
1434 unset($this->context[
'createfromclone']);
1438 $this->db->commit();
1441 $this->db->rollback();
1461 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [], $type = 0, $rang = -1, $special_code = 0)
1463 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration, $type, $rang, $special_code");
1465 if ($this->
status == self::STATUS_DRAFT) {
1471 $line->fk_fichinter = $fichinterid;
1472 $line->desc = $desc;
1473 $line->date = $date_intervention;
1474 $line->datei = $date_intervention;
1475 $line->duration = $duration;
1476 $line->product_type = $type;
1477 $line->rang = $rang;
1478 $line->special_code = $special_code;
1481 if (is_array($array_options) && count($array_options) > 0) {
1482 $line->array_options = $array_options;
1485 $result = $line->insert($user);
1488 $this->db->commit();
1491 $this->error = $this->db->error();
1492 $this->db->rollback();
1516 $this->
ref =
'SPECIMEN';
1517 $this->ref_client =
'SPECIMEN CLIENT';
1518 $this->specimen = 1;
1520 $this->datec = $now;
1521 $this->note_private =
'Private note';
1522 $this->note_public =
'SPECIMEN';
1523 $this->duration = 0;
1524 $this->user_creation_id = 1;
1527 while ($xnbp < $nbp) {
1529 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1530 $line->date = ($now - 3600 * (1 + $xnbp));
1531 $line->datei = ($now - 3600 * (1 + $xnbp));
1532 $line->duration = 600;
1533 $line->fk_fichinter = 0;
1534 $this->lines[$xnbp] = $line;
1537 $this->duration += $line->duration;
1552 $this->lines = array();
1554 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams";
1555 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1556 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1557 $sql .=
" ORDER BY rang ASC, date ASC";
1559 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1561 $resql = $this->db->query($sql);
1563 $num = $this->db->num_rows($resql);
1566 $objp = $this->db->fetch_object($resql);
1569 $line->id = $objp->rowid;
1570 $line->fk_fichinter = $objp->fk_fichinter;
1571 $line->desc = $objp->description;
1572 $line->duration = $objp->duree;
1574 $line->qty = round($objp->duree / 3600, 2);
1575 $line->date = $this->db->jdate($objp->date);
1576 $line->datei = $this->db->jdate($objp->date);
1577 $line->rang = $objp->rang;
1578 $line->product_type = 1;
1579 $line->fetch_optionals();
1581 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1583 $this->lines[$i] = $line;
1586 $this->db->free($resql);
1590 $this->error = $this->db->error();
1623 if ($user->hasRight(
'ficheinter',
'creer')) {
1630 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1631 $sql .=
" WHERE rowid = ".((int) $this->
id);
1633 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1634 $resql = $this->db->query($sql);
1636 $this->errors[] = $this->db->error();
1641 $this->ref_client = $ref_client;
1644 if (!$notrigger && empty($error)) {
1646 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
1654 $this->db->commit();
1657 foreach ($this->errors as $errmsg) {
1658 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1659 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1661 $this->db->rollback();
1676 public function getKanbanView($option =
'', $arraydata =
null)
1680 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1682 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1683 $return .=
'<div class="info-box info-box-sm">';
1684 $return .=
'<span class="info-box-icon bg-infobox-action">';
1686 $return .=
'</span>';
1687 $return .=
'<div class="info-box-content">';
1688 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
1689 if ($selected >= 0) {
1690 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1692 if (!empty($arraydata[
'thirdparty'])) {
1693 $tmpthirdparty = $arraydata[
'thirdparty'];
1694 '@phan-var-force Societe $tmpthirdparty';
1696 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1698 if (!empty($this->duration)) {
1699 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1701 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1702 $return .=
'</div>';
1703 $return .=
'</div>';
1704 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
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.
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.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
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.
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.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.