31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
40 public $fields = array(
41 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
42 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>15),
43 '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),
44 'fk_contrat' =>array(
'type'=>
'integer',
'label'=>
'Fk contrat',
'enabled'=>
'$conf->contrat->enabled',
'visible'=>-1,
'position'=>25),
45 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>30),
46 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
47 'ref_client' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefCustomer',
'enabled'=>1,
'visible'=>-1,
'position'=>36),
48 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
49 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>45),
50 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
51 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
52 'datei' =>array(
'type'=>
'date',
'label'=>
'Datei',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
53 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
54 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>70),
55 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
56 'dateo' =>array(
'type'=>
'date',
'label'=>
'Dateo',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
57 'datee' =>array(
'type'=>
'date',
'label'=>
'Datee',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
58 'datet' =>array(
'type'=>
'date',
'label'=>
'Datet',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
59 'duree' =>array(
'type'=>
'double',
'label'=>
'Duree',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
60 'description' =>array(
'type'=>
'html',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'showoncombobox'=>2),
61 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
62 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>115),
63 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>120),
64 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'Last main doc',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
65 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>130),
66 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
67 'fk_statut' =>array(
'type'=>
'integer',
'label'=>
'Fk statut',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
73 public $element =
'fichinter';
78 public $table_element =
'fichinter';
83 public $fk_element =
'fk_fichinter';
88 public $table_element_line =
'fichinterdet';
93 public $picto =
'intervention';
144 public $fk_contrat = 0;
149 public $fk_project = 0;
160 public $extraparams = array();
165 public $lines = array();
191 public $date_delivery;
197 public $user_author_id;
224 $sql =
"SELECT count(fi.rowid) as nb";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
226 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
227 if (!$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
228 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
229 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
232 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
234 $resql = $this->db->query($sql);
236 while ($obj = $this->db->fetch_object($resql)) {
237 $this->nb[
"interventions"] = $obj->nb;
239 $this->db->free($resql);
243 $this->error = $this->db->error();
255 public function create($user, $notrigger = 0)
257 global $conf, $langs;
264 if (!empty($this->ref)) {
267 $this->error =
'ErrorRefAlreadyExists';
268 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
269 $this->db->rollback();
273 if (!is_numeric($this->duration)) {
276 if (isset($this->ref_client)) {
277 $this->ref_client = trim($this->ref_client);
280 if ($this->socid <= 0) {
281 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
282 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
287 $result = $soc->fetch($this->socid);
293 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
297 $sql .=
", ref_client";
299 $sql .=
", fk_user_author";
300 $sql .=
", fk_user_modif";
301 $sql .=
", description";
302 $sql .=
", model_pdf";
303 $sql .=
", fk_projet";
304 $sql .=
", fk_contrat";
305 $sql .=
", fk_statut";
306 $sql .=
", note_private";
307 $sql .=
", note_public";
310 $sql .= $this->socid;
311 $sql .=
", '".$this->db->idate($now).
"'";
312 $sql .=
", '".$this->db->escape($this->ref).
"'";
313 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
314 $sql .=
", ".((int) $conf->entity);
315 $sql .=
", ".((int) $user->id);
316 $sql .=
", ".((int) $user->id);
317 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
318 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
319 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
320 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
321 $sql .=
", ".((int) $this->
statut);
322 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
323 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
326 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
327 $result = $this->db->query($sql);
329 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
332 $this->ref =
'(PROV'.$this->id.
')';
333 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
335 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
336 $resql = $this->db->query($sql);
350 if (!$error && $this->origin && $this->origin_id) {
358 if (!$error && !$notrigger) {
360 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
371 $this->db->rollback();
372 $this->error = join(
',', $this->errors);
373 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
377 $this->error = $this->db->error();
378 $this->db->rollback();
390 public function update($user, $notrigger = 0)
394 if (!is_numeric($this->duration)) {
398 $this->fk_project = 0;
400 if (isset($this->ref_client)) {
401 $this->ref_client = trim($this->ref_client);
408 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
409 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
410 $sql .=
", duree = ".((int) $this->duration);
411 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
412 $sql .=
", fk_projet = ".((int) $this->fk_project);
413 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
414 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
415 $sql .=
", fk_user_modif = ".((int) $user->id);
416 $sql .=
" WHERE rowid = ".((int) $this->
id);
418 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
419 if ($this->db->query($sql)) {
427 if (!$error && !$notrigger) {
429 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
432 $this->db->rollback();
441 $this->error = $this->db->error();
442 $this->db->rollback();
454 public function fetch($rowid, $ref =
'')
456 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status,";
457 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
458 $sql .=
" f.date_valid as datev,";
459 $sql .=
" f.tms as datem,";
460 $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";
461 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
463 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
464 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
466 $sql .=
" WHERE f.rowid = ".((int) $rowid);
469 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
470 $resql = $this->db->query($sql);
472 if ($this->db->num_rows($resql)) {
473 $obj = $this->db->fetch_object($resql);
475 $this->
id = $obj->rowid;
476 $this->
ref = $obj->ref;
477 $this->ref_client = $obj->ref_client;
479 $this->socid = $obj->fk_soc;
480 $this->
status = $obj->status;
481 $this->
statut = $obj->status;
482 $this->duration = $obj->duree;
483 $this->datec = $this->db->jdate($obj->datec);
484 $this->dateo = $this->db->jdate($obj->dateo);
485 $this->datee = $this->db->jdate($obj->datee);
486 $this->datet = $this->db->jdate($obj->datet);
487 $this->datev = $this->db->jdate($obj->datev);
488 $this->datem = $this->db->jdate($obj->datem);
489 $this->fk_project = $obj->fk_project;
490 $this->note_public = $obj->note_public;
491 $this->note_private = $obj->note_private;
492 $this->model_pdf = $obj->model_pdf;
493 $this->fk_contrat = $obj->fk_contrat;
494 $this->entity = $obj->entity;
496 $this->user_creation_id = $obj->fk_user_author;
498 $this->extraparams = (array) json_decode($obj->extraparams,
true);
500 $this->last_main_doc = $obj->last_main_doc;
512 $this->db->free($resql);
518 $this->error = $this->db->lasterror();
534 if ($this->
statut <= self::STATUS_DRAFT) {
538 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
544 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
545 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
546 $sql .=
" WHERE rowid = ".((int) $this->
id);
548 $resql = $this->db->query($sql);
552 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
563 $this->db->rollback();
567 $this->db->rollback();
568 $this->error = $this->db->lasterror();
583 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
587 if ($this->
status != self::STATUS_VALIDATED) {
593 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
600 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
601 $sql .=
" SET fk_statut = 1";
602 $sql .=
", ref = '".$this->db->escape($num).
"'";
603 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
604 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
605 $sql .=
" WHERE rowid = ".((int) $this->
id);
606 $sql .=
" AND entity = ".((int) $this->entity);
608 $sql .=
" AND fk_statut = 0";
610 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
611 $resql = $this->db->query($sql);
617 if (!$error && !$notrigger) {
619 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
627 $this->oldref = $this->ref;
630 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
631 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
634 $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).
"'";
635 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
636 $resql = $this->db->query($sql);
639 $this->error = $this->db->lasterror();
641 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
642 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
643 $resql = $this->db->query($sql);
646 $this->error = $this->db->lasterror();
652 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
653 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
654 if (!$error && file_exists($dirsource)) {
655 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
657 if (@rename($dirsource, $dirdest)) {
660 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
661 foreach ($listoffiles as $fileentry) {
662 $dirsource = $fileentry[
'name'];
663 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
664 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
665 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
666 @rename($dirsource, $dirdest);
678 $this->date_validation = $now;
682 $this->db->rollback();
683 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
704 if ($this->
statut == self::STATUS_CLOSED) {
711 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
712 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
713 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
714 $sql .=
" fk_user_modif = " . ((int) $user->id);
715 $sql .=
" WHERE rowid = " . ((int) $this->
id);
717 $sql .=
" AND entity = " . ((int) $conf->entity);
719 if ($this->db->query($sql)) {
722 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
734 $this->db->rollback();
738 $this->error = $this->db->lasterror();
739 $this->db->rollback();
754 $this->author =
new User($this->db);
755 $this->author->fetch($this->user_creation_id);
757 $thm = $this->author->thm;
759 foreach ($this->lines as $line) {
760 $amount += ($line->duration / 60 / 60 * $thm);
778 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
782 $outputlangs->load(
"interventions");
787 if (!empty($this->model_pdf)) {
788 $modele = $this->model_pdf;
790 $modele = $conf->global->FICHEINTER_ADDON_PDF;
794 $modelpath =
"core/modules/fichinter/doc/";
796 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
822 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
824 $langs->load(
"fichinter");
828 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
832 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
836 $statuscode =
'status'.$status;
837 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
838 $statuscode =
'status6';
840 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statuscode, $mode);
852 global $conf, $langs;
854 $langs->load(
'fichinter');
857 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
858 if (isset($this->
status)) {
859 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
861 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
876 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
878 global $conf, $langs, $hookmanager;
880 if (!empty($conf->dol_no_mouse_hover)) {
887 'objecttype' => $this->element,
890 $classfortooltip =
'classfortooltip';
893 $classfortooltip =
'classforajaxtooltip';
894 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
900 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
902 if ($option !==
'nolink') {
904 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
905 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
906 $add_save_lastsearch_values = 1;
908 if ($add_save_lastsearch_values) {
909 $url .=
'&save_lastsearch_values=1';
914 if (empty($notooltip)) {
916 $label = $langs->trans(
"ShowIntervention");
917 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
919 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
920 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
922 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
925 if ($option ==
'nolink' || empty($url)) {
926 $linkstart =
'<span';
928 $linkstart =
'<a href="'.$url.
'"';
930 $linkstart .= $linkclose.
'>';
931 if ($option ==
'nolink' || empty($url)) {
932 $linkend =
'</span>';
937 $result .= $linkstart;
939 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
942 if ($withpicto != 2) {
943 $result .= $this->ref;
949 $hookmanager->initHooks(array(
'interventiondao'));
950 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
951 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
953 $result = $hookmanager->resPrint;
955 $result .= $hookmanager->resPrint;
971 global $conf, $db, $langs;
972 $langs->load(
"interventions");
981 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
983 foreach ($dirmodels as $reldir) {
987 $mybool |= @include_once $dir.$file;
990 if ($mybool ===
false) {
995 $obj =
new $classname();
997 $numref = $obj->getNextValue($soc, $this);
1006 $langs->load(
"errors");
1007 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1020 $sql =
"SELECT f.rowid,";
1021 $sql .=
" f.datec,";
1022 $sql .=
" f.tms as date_modification,";
1023 $sql .=
" f.date_valid as datev,";
1024 $sql .=
" f.fk_user_author,";
1025 $sql .=
" f.fk_user_modif as fk_user_modification,";
1026 $sql .=
" f.fk_user_valid";
1027 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1028 $sql .=
" WHERE f.rowid = ".((int) $id);
1030 $resql = $this->db->query($sql);
1032 if ($this->db->num_rows($resql)) {
1033 $obj = $this->db->fetch_object($resql);
1035 $this->
id = $obj->rowid;
1037 $this->date_creation = $this->db->jdate($obj->datec);
1038 $this->date_modification = $this->db->jdate($obj->date_modification);
1039 $this->date_validation = $this->db->jdate($obj->datev);
1041 $this->user_creation_id = $obj->fk_user_author;
1042 $this->user_validation_id = $obj->fk_user_valid;
1043 $this->user_modification_id = $obj->fk_user_modification;
1045 $this->db->free($resql);
1058 public function delete(
User $user, $notrigger = 0)
1060 global $conf, $langs;
1061 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1067 if (!$error && !$notrigger) {
1069 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1072 $this->db->rollback();
1090 $this->error =
'ErrorFailToDeleteLinkedContact';
1096 $main = MAIN_DB_PREFIX.
'fichinterdet';
1097 $ef = $main.
"_extrafields";
1098 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".((int) $this->
id).
")";
1100 $resql = $this->db->query($sql);
1107 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1108 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1110 $resql = $this->db->query($sql);
1126 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1127 $sql .=
" WHERE rowid = ".((int) $this->
id);
1130 $resql = $this->db->query($sql);
1143 if ($conf->ficheinter->dir_output) {
1144 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1145 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1146 if (file_exists($file)) {
1150 $langs->load(
"errors");
1151 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1155 if (file_exists($dir)) {
1157 $langs->load(
"errors");
1158 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1166 $this->db->commit();
1169 $this->db->rollback();
1185 if ($user->hasRight(
'ficheinter',
'creer')) {
1186 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1187 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1188 $sql .=
" WHERE rowid = ".((int) $this->
id);
1189 $sql .=
" AND fk_statut = 0";
1191 if ($this->db->query($sql)) {
1192 $this->date_delivery = $date_delivery;
1195 $this->error = $this->db->error();
1196 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1215 if ($user->hasRight(
'ficheinter',
'creer')) {
1216 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1217 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1218 $sql .=
" fk_user_modif = ".$user->id;
1219 $sql .=
" WHERE rowid = ".((int) $this->
id);
1221 if ($this->db->query($sql)) {
1225 $this->error = $this->db->error();
1226 dol_syslog(
"Fichinter::set_description Erreur SQL");
1246 if ($user->hasRight(
'ficheinter',
'creer')) {
1247 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1248 $sql .=
" SET fk_contrat = ".((int) $contractid);
1249 $sql .=
" WHERE rowid = ".((int) $this->
id);
1251 if ($this->db->query($sql)) {
1252 $this->fk_contrat = $contractid;
1255 $this->error = $this->db->error();
1274 global $hookmanager;
1281 foreach ($this->lines as $line) {
1282 $line->fetch_optionals();
1286 $objFrom = clone $this;
1289 if (!empty($socid) && $socid != $this->socid) {
1290 $objsoc =
new Societe($this->db);
1292 if ($objsoc->fetch($socid) > 0) {
1293 $this->socid = $objsoc->id;
1296 $this->fk_project =
'';
1297 $this->fk_delivery_address =
'';
1309 $this->user_author_id = $user->id;
1310 $this->user_validation_id = 0;
1311 $this->date_creation =
'';
1312 $this->date_validation =
'';
1314 $this->ref_client =
'';
1317 $this->context[
'createfromclone'] =
'createfromclone';
1318 $result = $this->
create($user);
1325 foreach ($this->lines as $line) {
1326 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1330 if (is_object($hookmanager)) {
1331 $parameters = array(
'objFrom'=>$objFrom);
1333 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1341 unset($this->context[
'createfromclone']);
1345 $this->db->commit();
1348 $this->db->rollback();
1365 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1367 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1369 if ($this->
status == self::STATUS_DRAFT) {
1375 $line->fk_fichinter = $fichinterid;
1376 $line->desc = $desc;
1377 $line->date = $date_intervention;
1378 $line->datei = $date_intervention;
1379 $line->duration = $duration;
1381 if (is_array($array_options) && count($array_options) > 0) {
1382 $line->array_options = $array_options;
1385 $result = $line->insert($user);
1388 $this->db->commit();
1391 $this->error = $this->db->error();
1392 $this->db->rollback();
1416 $this->
ref =
'SPECIMEN';
1417 $this->ref_client =
'SPECIMEN CLIENT';
1418 $this->specimen = 1;
1420 $this->datec = $now;
1421 $this->note_private =
'Private note';
1422 $this->note_public =
'SPECIMEN';
1423 $this->duration = 0;
1426 while ($xnbp < $nbp) {
1428 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1429 $line->date = ($now - 3600 * (1 + $xnbp));
1430 $line->datei = ($now - 3600 * (1 + $xnbp));
1431 $line->duration = 600;
1432 $line->fk_fichinter = 0;
1433 $this->lines[$xnbp] = $line;
1436 $this->duration += $line->duration;
1449 $this->lines = array();
1451 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1452 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1453 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1454 $sql .=
" ORDER BY rang ASC, date ASC";
1456 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1458 $resql = $this->db->query($sql);
1460 $num = $this->db->num_rows($resql);
1463 $objp = $this->db->fetch_object($resql);
1466 $line->id = $objp->rowid;
1467 $line->fk_fichinter = $objp->fk_fichinter;
1468 $line->desc = $objp->description;
1469 $line->duration = $objp->duree;
1471 $line->qty = round($objp->duree / 3600, 2);
1472 $line->date = $this->db->jdate($objp->date);
1473 $line->datei = $this->db->jdate($objp->date);
1474 $line->rang = $objp->rang;
1475 $line->product_type = 1;
1476 $line->fetch_optionals();
1478 $this->lines[$i] = $line;
1481 $this->db->free($resql);
1485 $this->error = $this->db->error();
1518 if ($user->hasRight(
'ficheinter',
'creer')) {
1525 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1526 $sql .=
" WHERE rowid = ".((int) $this->
id);
1528 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1529 $resql = $this->db->query($sql);
1531 $this->errors[] = $this->db->error();
1536 $this->ref_client = $ref_client;
1539 if (!$notrigger && empty($error)) {
1541 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1549 $this->db->commit();
1552 foreach ($this->errors as $errmsg) {
1553 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1554 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1556 $this->db->rollback();
1575 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1577 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1578 $return .=
'<div class="info-box info-box-sm">';
1579 $return .=
'<span class="info-box-icon bg-infobox-action">';
1581 $return .=
'</span>';
1582 $return .=
'<div class="info-box-content">';
1583 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1584 if ($selected >= 0) {
1585 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1587 if (!empty($arraydata[
'thirdparty'])) {
1588 $tmpthirdparty = $arraydata[
'thirdparty'];
1589 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1591 if (property_exists($this,
'duration')) {
1592 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1594 if (method_exists($this,
'getLibStatut')) {
1595 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1597 $return .=
'</div>';
1598 $return .=
'</div>';
1599 $return .=
'</div>';
1623 public $fk_fichinter;
1645 public $element =
'fichinterdet';
1650 public $table_element =
'fichinterdet';
1655 public $fk_element =
'fk_fichinter';
1677 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1679 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date';
1680 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1681 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
1683 $resql = $this->db->query($sql);
1685 $objp = $this->db->fetch_object($resql);
1686 $this->
rowid = $objp->rowid;
1687 $this->
id = $objp->rowid;
1688 $this->fk_fichinter = $objp->fk_fichinter;
1689 $this->date = $this->db->jdate($objp->date);
1690 $this->datei = $this->db->jdate($objp->date);
1691 $this->desc = $objp->description;
1692 $this->duration = $objp->duree;
1693 $this->rang = $objp->rang;
1695 $this->db->free($resql);
1701 $this->error = $this->db->error().
' sql='.$sql;
1713 public function insert($user, $notrigger = 0)
1717 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1719 if (empty($this->date) && !empty($this->datei)) {
1720 $this->date = $this->datei;
1725 $rangToUse = $this->rang;
1726 if ($rangToUse == -1) {
1728 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1729 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
1730 $resql = $this->db->query($sql);
1732 $obj = $this->db->fetch_object($resql);
1733 $rangToUse = $obj->max + 1;
1736 $this->db->rollback();
1742 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1743 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1744 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
1745 $sql .=
" '".$this->db->escape($this->desc).
"',";
1746 $sql .=
" '".$this->db->idate($this->date).
"',";
1747 $sql .=
" ".((int) $this->duration).
",";
1748 $sql .=
' '.((int) $rangToUse);
1751 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1752 $resql = $this->db->query($sql);
1754 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1755 $this->
rowid = $this->id;
1768 $this->rang = $rangToUse;
1772 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1781 $this->db->commit();
1784 $this->db->rollback();
1788 $this->error = $this->db->error().
" sql=".$sql;
1789 $this->db->rollback();
1802 public function update($user, $notrigger = 0)
1806 if (empty($this->date) && !empty($this->datei)) {
1807 $this->date = $this->datei;
1813 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1814 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
1815 $sql .=
" date = '".$this->db->idate($this->date).
"',";
1816 $sql .=
" duree = ".((int) $this->duration).
",";
1817 $sql .=
" rang = ".((int) $this->rang);
1818 $sql .=
" WHERE rowid = ".((int) $this->
id);
1820 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1821 $resql = $this->db->query($sql);
1834 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
1843 $this->db->commit();
1846 $this->error = $this->db->lasterror();
1847 $this->db->rollback();
1851 $this->error = $this->db->lasterror();
1852 $this->db->rollback();
1870 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1872 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
1874 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1875 $resql = $this->db->query($sql);
1877 $obj = $this->db->fetch_object($resql);
1878 $total_duration = 0;
1879 if (!empty($obj->total_duration)) {
1880 $total_duration = $obj->total_duration;
1883 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1884 $sql .=
" SET duree = ".((int) $total_duration);
1885 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
1886 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
1887 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
1889 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1890 $resql = $this->db->query($sql);
1892 $this->db->commit();
1895 $this->error = $this->db->error();
1896 $this->db->rollback();
1900 $this->error = $this->db->error();
1901 $this->db->rollback();
1917 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1924 $this->db->rollback();
1928 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
1929 $resql = $this->db->query($sql);
1936 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1939 $this->db->rollback();
1945 $this->db->commit();
1948 $this->db->rollback();
1952 $this->error = $this->db->error().
" sql=".$sql;
1953 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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 an object id/ref exists If you don't need/want to instantiate object and just need to know if o...
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.
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.
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)
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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clicable name (with picto eventually)
load_state_board()
Load indicators into this->nb for board.
__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.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
deleteline($user, $notrigger=0)
Delete a intervention line.
__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($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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
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 right right takeposterminal SELECT e rowid
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut