32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $fields = array(
42 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
43 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
44 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Fk projet',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'position' => 20),
45 'fk_contrat' => array(
'type' =>
'integer',
'label' =>
'Fk contrat',
'enabled' =>
'$conf->contrat->enabled',
'visible' => -1,
'position' => 25),
46 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
47 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
48 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
49 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
50 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
51 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
52 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
53 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
54 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 65),
55 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
56 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
57 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
58 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
59 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
60 'duree' => array(
'type' =>
'double',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
61 'signed_status' => array(
'type' =>
'smallint(6)',
'label' =>
'SignedStatus',
'enabled' => 1,
'visible' => -1,
'position' => 101,
'arrayofkeyval' => array(0 =>
'NoSignature', 1 =>
'SignedSender', 2 =>
'SignedReceiver', 9 =>
'SignedAll')),
62 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
63 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
64 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
65 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 120),
66 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
67 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
68 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
69 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Fk statut',
'enabled' => 1,
'visible' => -1,
'position' => 500),
75 public $element =
'fichinter';
80 public $table_element =
'fichinter';
85 public $fk_element =
'fk_fichinter';
90 public $table_element_line =
'fichinterdet';
95 public $picto =
'intervention';
153 public $signed_status = 0;
163 public $fk_contrat = 0;
168 public $fk_project = 0;
179 public $extraparams = array();
184 public $lines = array();
232 public $date_delivery;
238 public $user_author_id;
263 $sql =
"SELECT count(fi.rowid) as nb";
264 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
265 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
266 if (!$user->hasRight(
'societe',
'client',
'voir')) {
267 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
268 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
271 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
273 $resql = $this->db->query($sql);
275 while ($obj = $this->db->fetch_object($resql)) {
276 $this->nb[
"interventions"] = $obj->nb;
278 $this->db->free($resql);
282 $this->error = $this->db->error();
294 public function create($user, $notrigger = 0)
296 global $conf, $langs;
303 if (!empty($this->ref)) {
306 $this->error =
'ErrorRefAlreadyExists';
307 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
308 $this->db->rollback();
312 if (!is_numeric($this->duration)) {
315 if (isset($this->ref_client)) {
316 $this->ref_client = trim($this->ref_client);
319 if ($this->socid <= 0) {
320 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
321 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
326 $result = $soc->fetch($this->socid);
332 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
336 $sql .=
", ref_client";
338 $sql .=
", fk_user_author";
339 $sql .=
", fk_user_modif";
340 $sql .=
", description";
341 $sql .=
", model_pdf";
342 $sql .=
", fk_projet";
343 $sql .=
", fk_contrat";
344 $sql .=
", fk_statut";
345 $sql .=
", note_private";
346 $sql .=
", note_public";
349 $sql .= $this->socid;
350 $sql .=
", '".$this->db->idate($now).
"'";
351 $sql .=
", '".$this->db->escape($this->ref).
"'";
352 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
353 $sql .=
", ".((int) $conf->entity);
354 $sql .=
", ".((int) $user->id);
355 $sql .=
", ".((int) $user->id);
356 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
357 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
358 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
359 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
360 $sql .=
", ".((int) $this->
statut);
361 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
362 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
365 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
366 $result = $this->db->query($sql);
368 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
371 $this->ref =
'(PROV'.$this->id.
')';
372 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
374 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
375 $resql = $this->db->query($sql);
389 if (!$error && $this->origin && $this->origin_id) {
397 if (!$error && !$notrigger) {
399 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
410 $this->db->rollback();
411 $this->error = implode(
',', $this->errors);
412 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
416 $this->error = $this->db->error();
417 $this->db->rollback();
429 public function update($user, $notrigger = 0)
433 if (!is_numeric($this->duration)) {
437 $this->fk_project = 0;
439 if (isset($this->ref_client)) {
440 $this->ref_client = trim($this->ref_client);
447 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
448 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
449 $sql .=
", duree = ".((int) $this->duration);
450 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
451 $sql .=
", fk_projet = ".((int) $this->fk_project);
452 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
453 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
454 $sql .=
", fk_user_modif = ".((int) $user->id);
455 $sql .=
" WHERE rowid = ".((int) $this->
id);
457 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
458 if ($this->db->query($sql)) {
466 if (!$error && !$notrigger) {
468 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
471 $this->db->rollback();
480 $this->error = $this->db->error();
481 $this->db->rollback();
493 public function fetch($rowid, $ref =
'')
495 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status,";
496 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
497 $sql .=
" f.date_valid as datev,";
498 $sql .=
" f.tms as datem,";
499 $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";
500 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
502 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
503 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
505 $sql .=
" WHERE f.rowid = ".((int) $rowid);
508 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
509 $resql = $this->db->query($sql);
511 if ($this->db->num_rows($resql)) {
512 $obj = $this->db->fetch_object($resql);
514 $this->
id = $obj->rowid;
515 $this->
ref = $obj->ref;
516 $this->ref_client = $obj->ref_client;
518 $this->socid = $obj->fk_soc;
519 $this->
status = $obj->status;
520 $this->
statut = $obj->status;
521 $this->duration = $obj->duree;
522 $this->datec = $this->db->jdate($obj->datec);
523 $this->dateo = $this->db->jdate($obj->dateo);
524 $this->datee = $this->db->jdate($obj->datee);
525 $this->datet = $this->db->jdate($obj->datet);
526 $this->datev = $this->db->jdate($obj->datev);
527 $this->datem = $this->db->jdate($obj->datem);
528 $this->fk_project = $obj->fk_project;
529 $this->note_public = $obj->note_public;
530 $this->note_private = $obj->note_private;
531 $this->model_pdf = $obj->model_pdf;
532 $this->fk_contrat = $obj->fk_contrat;
533 $this->entity = $obj->entity;
535 $this->user_creation_id = $obj->fk_user_author;
537 $this->extraparams = (array) json_decode($obj->extraparams,
true);
539 $this->last_main_doc = $obj->last_main_doc;
551 $this->db->free($resql);
557 $this->error = $this->db->lasterror();
573 if ($this->
statut <= self::STATUS_DRAFT) {
577 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
583 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
584 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
585 $sql .=
" WHERE rowid = ".((int) $this->
id);
587 $resql = $this->db->query($sql);
591 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
602 $this->db->rollback();
606 $this->db->rollback();
607 $this->error = $this->db->lasterror();
622 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
626 if ($this->
status != self::STATUS_VALIDATED) {
632 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
639 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
640 $sql .=
" SET fk_statut = 1";
641 $sql .=
", ref = '".$this->db->escape($num).
"'";
642 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
643 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
644 $sql .=
" WHERE rowid = ".((int) $this->
id);
645 $sql .=
" AND entity = ".((int) $this->entity);
647 $sql .=
" AND fk_statut = 0";
649 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
650 $resql = $this->db->query($sql);
656 if (!$error && !$notrigger) {
658 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
666 $this->oldref = $this->ref;
669 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
670 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
673 $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).
"'";
674 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
675 $resql = $this->db->query($sql);
678 $this->error = $this->db->lasterror();
680 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
681 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
682 $resql = $this->db->query($sql);
685 $this->error = $this->db->lasterror();
691 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
692 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
693 if (!$error && file_exists($dirsource)) {
694 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
696 if (@rename($dirsource, $dirdest)) {
699 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
700 foreach ($listoffiles as $fileentry) {
701 $dirsource = $fileentry[
'name'];
702 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
703 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
704 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
705 @rename($dirsource, $dirdest);
717 $this->date_validation = $now;
721 $this->db->rollback();
722 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
743 if ($this->
statut == self::STATUS_CLOSED) {
750 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
751 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
752 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
753 $sql .=
" fk_user_modif = " . ((int) $user->id);
754 $sql .=
" WHERE rowid = " . ((int) $this->
id);
756 $sql .=
" AND entity = " . ((int) $conf->entity);
758 if ($this->db->query($sql)) {
761 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
773 $this->db->rollback();
777 $this->error = $this->db->lasterror();
778 $this->db->rollback();
793 $this->author =
new User($this->db);
794 $this->author->fetch($this->user_creation_id);
796 $thm = $this->author->thm;
798 foreach ($this->lines as $line) {
799 $amount += ($line->duration / 60 / 60 * (float) $thm);
817 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
821 $outputlangs->load(
"interventions");
826 if (!empty($this->model_pdf)) {
827 $modele = $this->model_pdf;
833 $modelpath =
"core/modules/fichinter/doc/";
835 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
861 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
863 $langs->load(
"fichinter");
867 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
871 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
875 $statuscode =
'status'.$status;
876 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
877 $statuscode =
'status6';
879 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statuscode, $mode);
891 global $conf, $langs;
893 $langs->load(
'fichinter');
896 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
897 if (isset($this->
status)) {
898 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
900 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
915 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
917 global $conf, $langs, $hookmanager;
919 if (!empty($conf->dol_no_mouse_hover)) {
926 'objecttype' => $this->element,
929 $classfortooltip =
'classfortooltip';
932 $classfortooltip =
'classforajaxtooltip';
933 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
939 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
941 if ($option !==
'nolink') {
943 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
944 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
945 $add_save_lastsearch_values = 1;
947 if ($add_save_lastsearch_values) {
948 $url .=
'&save_lastsearch_values=1';
953 if (empty($notooltip)) {
955 $label = $langs->trans(
"ShowIntervention");
956 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
958 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
959 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
961 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
964 if ($option ==
'nolink' || empty($url)) {
965 $linkstart =
'<span';
967 $linkstart =
'<a href="'.$url.
'"';
969 $linkstart .= $linkclose.
'>';
970 if ($option ==
'nolink' || empty($url)) {
971 $linkend =
'</span>';
976 $result .= $linkstart;
978 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
981 if ($withpicto != 2) {
982 $result .= $this->ref;
988 $hookmanager->initHooks(array(
'interventiondao'));
989 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
990 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
992 $result = $hookmanager->resPrint;
994 $result .= $hookmanager->resPrint;
1010 global $conf, $db, $langs;
1011 $langs->load(
"interventions");
1020 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1022 foreach ($dirmodels as $reldir) {
1026 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1029 if ($mybool ===
false) {
1034 $obj =
new $classname();
1036 $numref = $obj->getNextValue($soc, $this);
1038 if ($numref !=
"") {
1045 $langs->load(
"errors");
1046 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1059 $sql =
"SELECT f.rowid,";
1060 $sql .=
" f.datec,";
1061 $sql .=
" f.tms as date_modification,";
1062 $sql .=
" f.date_valid as datev,";
1063 $sql .=
" f.fk_user_author,";
1064 $sql .=
" f.fk_user_modif as fk_user_modification,";
1065 $sql .=
" f.fk_user_valid";
1066 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1067 $sql .=
" WHERE f.rowid = ".((int) $id);
1069 $resql = $this->db->query($sql);
1071 if ($this->db->num_rows($resql)) {
1072 $obj = $this->db->fetch_object($resql);
1074 $this->
id = $obj->rowid;
1076 $this->date_creation = $this->db->jdate($obj->datec);
1077 $this->date_modification = $this->db->jdate($obj->date_modification);
1078 $this->date_validation = $this->db->jdate($obj->datev);
1080 $this->user_creation_id = $obj->fk_user_author;
1081 $this->user_validation_id = $obj->fk_user_valid;
1082 $this->user_modification_id = $obj->fk_user_modification;
1084 $this->db->free($resql);
1097 public function delete(
User $user, $notrigger = 0)
1099 global $conf, $langs;
1100 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1106 if (!$error && !$notrigger) {
1108 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1111 $this->db->rollback();
1129 $this->error =
'ErrorFailToDeleteLinkedContact';
1135 $main = MAIN_DB_PREFIX.
'fichinterdet';
1136 $ef = $main.
"_extrafields";
1137 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".((int) $this->
id).
")";
1139 $resql = $this->db->query($sql);
1146 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1147 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1149 $resql = $this->db->query($sql);
1165 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1166 $sql .=
" WHERE rowid = ".((int) $this->
id);
1169 $resql = $this->db->query($sql);
1182 if ($conf->ficheinter->dir_output) {
1183 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1184 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1185 if (file_exists($file)) {
1189 $langs->load(
"errors");
1190 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1194 if (file_exists($dir)) {
1196 $langs->load(
"errors");
1197 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1205 $this->db->commit();
1208 $this->db->rollback();
1224 if ($user->hasRight(
'ficheinter',
'creer')) {
1225 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1226 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1227 $sql .=
" WHERE rowid = ".((int) $this->
id);
1228 $sql .=
" AND fk_statut = 0";
1230 if ($this->db->query($sql)) {
1231 $this->date_delivery = $date_delivery;
1234 $this->error = $this->db->error();
1235 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1254 if ($user->hasRight(
'ficheinter',
'creer')) {
1255 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1256 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1257 $sql .=
" fk_user_modif = ".$user->id;
1258 $sql .=
" WHERE rowid = ".((int) $this->
id);
1260 if ($this->db->query($sql)) {
1264 $this->error = $this->db->error();
1265 dol_syslog(
"Fichinter::set_description Erreur SQL");
1285 if ($user->hasRight(
'ficheinter',
'creer')) {
1286 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1287 $sql .=
" SET fk_contrat = ".((int) $contractid);
1288 $sql .=
" WHERE rowid = ".((int) $this->
id);
1290 if ($this->db->query($sql)) {
1291 $this->fk_contrat = $contractid;
1294 $this->error = $this->db->error();
1313 global $hookmanager;
1320 foreach ($this->lines as $line) {
1321 $line->fetch_optionals();
1325 $objFrom = clone $this;
1328 if (!empty($socid) && $socid != $this->socid) {
1329 $objsoc =
new Societe($this->db);
1331 if ($objsoc->fetch($socid) > 0) {
1332 $this->socid = $objsoc->id;
1335 $this->fk_project = 0;
1336 $this->fk_delivery_address = 0;
1348 $this->user_author_id = $user->id;
1349 $this->user_validation_id = 0;
1350 $this->date_creation =
'';
1351 $this->date_validation =
'';
1353 $this->ref_client =
'';
1356 $this->context[
'createfromclone'] =
'createfromclone';
1357 $result = $this->
create($user);
1364 foreach ($this->lines as $line) {
1365 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1369 if (is_object($hookmanager)) {
1370 $parameters = array(
'objFrom' => $objFrom);
1372 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1380 unset($this->context[
'createfromclone']);
1384 $this->db->commit();
1387 $this->db->rollback();
1404 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1406 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1408 if ($this->
status == self::STATUS_DRAFT) {
1414 $line->fk_fichinter = $fichinterid;
1415 $line->desc = $desc;
1416 $line->date = $date_intervention;
1417 $line->datei = $date_intervention;
1418 $line->duration = $duration;
1420 if (is_array($array_options) && count($array_options) > 0) {
1421 $line->array_options = $array_options;
1424 $result = $line->insert($user);
1427 $this->db->commit();
1430 $this->error = $this->db->error();
1431 $this->db->rollback();
1455 $this->
ref =
'SPECIMEN';
1456 $this->ref_client =
'SPECIMEN CLIENT';
1457 $this->specimen = 1;
1459 $this->datec = $now;
1460 $this->note_private =
'Private note';
1461 $this->note_public =
'SPECIMEN';
1462 $this->duration = 0;
1465 while ($xnbp < $nbp) {
1467 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1468 $line->date = ($now - 3600 * (1 + $xnbp));
1469 $line->datei = ($now - 3600 * (1 + $xnbp));
1470 $line->duration = 600;
1471 $line->fk_fichinter = 0;
1472 $this->lines[$xnbp] = $line;
1475 $this->duration += $line->duration;
1490 $this->lines = array();
1492 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1493 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1494 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1495 $sql .=
" ORDER BY rang ASC, date ASC";
1497 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1499 $resql = $this->db->query($sql);
1501 $num = $this->db->num_rows($resql);
1504 $objp = $this->db->fetch_object($resql);
1507 $line->id = $objp->rowid;
1508 $line->fk_fichinter = $objp->fk_fichinter;
1509 $line->desc = $objp->description;
1510 $line->duration = $objp->duree;
1512 $line->qty = round($objp->duree / 3600, 2);
1513 $line->date = $this->db->jdate($objp->date);
1514 $line->datei = $this->db->jdate($objp->date);
1515 $line->rang = $objp->rang;
1516 $line->product_type = 1;
1517 $line->fetch_optionals();
1519 $this->lines[$i] = $line;
1522 $this->db->free($resql);
1526 $this->error = $this->db->error();
1559 if ($user->hasRight(
'ficheinter',
'creer')) {
1566 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1567 $sql .=
" WHERE rowid = ".((int) $this->
id);
1569 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1570 $resql = $this->db->query($sql);
1572 $this->errors[] = $this->db->error();
1577 $this->ref_client = $ref_client;
1580 if (!$notrigger && empty($error)) {
1582 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1590 $this->db->commit();
1593 foreach ($this->errors as $errmsg) {
1594 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1595 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1597 $this->db->rollback();
1616 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1618 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1619 $return .=
'<div class="info-box info-box-sm">';
1620 $return .=
'<span class="info-box-icon bg-infobox-action">';
1622 $return .=
'</span>';
1623 $return .=
'<div class="info-box-content">';
1624 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1625 if ($selected >= 0) {
1626 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1628 if (!empty($arraydata[
'thirdparty'])) {
1629 $tmpthirdparty = $arraydata[
'thirdparty'];
1630 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1632 if (property_exists($this,
'duration')) {
1633 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1635 if (method_exists($this,
'getLibStatut')) {
1636 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1638 $return .=
'</div>';
1639 $return .=
'</div>';
1640 $return .=
'</div>';
1678 public $fk_fichinter;
1705 public $element =
'fichinterdet';
1710 public $table_element =
'fichinterdet';
1715 public $fk_element =
'fk_fichinter';
1737 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1739 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date';
1740 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1741 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
1743 $resql = $this->db->query($sql);
1745 $objp = $this->db->fetch_object($resql);
1746 $this->
rowid = $objp->rowid;
1747 $this->
id = $objp->rowid;
1748 $this->fk_fichinter = $objp->fk_fichinter;
1749 $this->date = $this->db->jdate($objp->date);
1750 $this->datei = $this->db->jdate($objp->date);
1751 $this->desc = $objp->description;
1752 $this->duration = $objp->duree;
1753 $this->rang = $objp->rang;
1755 $this->db->free($resql);
1761 $this->error = $this->db->error().
' sql='.$sql;
1773 public function insert($user, $notrigger = 0)
1777 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1779 if (empty($this->date) && !empty($this->datei)) {
1780 $this->date = $this->datei;
1785 $rangToUse = $this->rang;
1786 if ($rangToUse == -1) {
1788 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1789 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
1790 $resql = $this->db->query($sql);
1792 $obj = $this->db->fetch_object($resql);
1793 $rangToUse = $obj->max + 1;
1796 $this->db->rollback();
1802 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1803 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1804 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
1805 $sql .=
" '".$this->db->escape($this->desc).
"',";
1806 $sql .=
" '".$this->db->idate($this->date).
"',";
1807 $sql .=
" ".((int) $this->duration).
",";
1808 $sql .=
' '.((int) $rangToUse);
1811 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1812 $resql = $this->db->query($sql);
1814 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1815 $this->
rowid = $this->id;
1828 $this->rang = $rangToUse;
1832 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1841 $this->db->commit();
1844 $this->db->rollback();
1848 $this->error = $this->db->error().
" sql=".$sql;
1849 $this->db->rollback();
1862 public function update($user, $notrigger = 0)
1866 if (empty($this->date) && !empty($this->datei)) {
1867 $this->date = $this->datei;
1873 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1874 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
1875 $sql .=
" date = '".$this->db->idate($this->date).
"',";
1876 $sql .=
" duree = ".((int) $this->duration).
",";
1877 $sql .=
" rang = ".((int) $this->rang);
1878 $sql .=
" WHERE rowid = ".((int) $this->
id);
1880 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1881 $resql = $this->db->query($sql);
1894 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
1903 $this->db->commit();
1906 $this->error = $this->db->lasterror();
1907 $this->db->rollback();
1911 $this->error = $this->db->lasterror();
1912 $this->db->rollback();
1930 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1931 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1932 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
1934 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1935 $resql = $this->db->query($sql);
1937 $obj = $this->db->fetch_object($resql);
1938 $total_duration = 0;
1939 if (!empty($obj->total_duration)) {
1940 $total_duration = $obj->total_duration;
1943 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1944 $sql .=
" SET duree = ".((int) $total_duration);
1945 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
1946 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
1947 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
1949 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1950 $resql = $this->db->query($sql);
1952 $this->db->commit();
1955 $this->error = $this->db->error();
1956 $this->db->rollback();
1960 $this->error = $this->db->error();
1961 $this->db->rollback();
1977 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1984 $this->db->rollback();
1988 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
1989 $resql = $this->db->query($sql);
1996 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1999 $this->db->rollback();
2005 $this->db->commit();
2008 $this->db->rollback();
2012 $this->error = $this->db->error().
" sql=".$sql;
2013 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
setSignedStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a signed status.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage interventions.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
const STATUS_SIGNED_RECEIVER
Signed by receiver.
const STATUS_SIGNED_ALL
Signed by all.
setClose($user, $notrigger=0)
Close intervention.
set_date_delivery($user, $date_delivery)
Defines a delivery date of 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
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
setSignedStatus(User $user, int $status=0, int $notrigger=0, $triggercode='')
Set signed status.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
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.
fetch($rowid, $ref='')
Fetch a intervention.
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 clicable name (with picto eventually)
const STATUS_SIGNED_SENDER
Signed by sender.
__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.
const STATUS_NO_SIGNATURE
No signature.
Class to manage intervention lines.
deleteLine($user, $notrigger=0)
Delete a intervention line.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert the line into database.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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 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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid