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';
43 use CommonSignedObject;
45 public $fields = array(
46 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
47 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
48 '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),
49 'fk_contrat' => array(
'type' =>
'integer',
'label' =>
'Fk contrat',
'enabled' =>
'$conf->contrat->enabled',
'visible' => -1,
'position' => 25),
50 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
51 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
52 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
53 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
54 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
55 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
56 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
57 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
58 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 65),
59 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
60 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
61 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
62 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
63 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
64 'duree' => array(
'type' =>
'integer',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
65 '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')),
66 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
67 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
68 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
69 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 120),
70 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
71 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
72 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
73 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Fk statut',
'enabled' => 1,
'visible' => -1,
'position' => 500),
79 public $element =
'fichinter';
84 public $table_element =
'fichinter';
89 public $table_element_line =
'fichinterdet';
94 public $picto =
'intervention';
159 public $fk_contrat = 0;
164 public $fk_project = 0;
175 public $extraparams = array();
180 public $lines = array();
206 public $date_delivery;
212 public $user_author_id;
237 $sql =
"SELECT count(fi.rowid) as nb";
238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
239 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
240 if (!$user->hasRight(
'societe',
'client',
'voir')) {
241 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
242 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
245 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
247 $resql = $this->db->query($sql);
249 while ($obj = $this->db->fetch_object($resql)) {
250 $this->nb[
"interventions"] = $obj->nb;
252 $this->db->free($resql);
256 $this->error = $this->db->error();
268 public function create($user, $notrigger = 0)
270 global $conf, $langs;
277 if (!empty($this->ref)) {
280 $this->error =
'ErrorRefAlreadyExists';
281 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
282 $this->db->rollback();
286 if (!is_numeric($this->duration)) {
289 if (isset($this->ref_client)) {
290 $this->ref_client = trim($this->ref_client);
293 if ($this->socid <= 0) {
294 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
295 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
300 $result = $soc->fetch($this->socid);
306 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
310 $sql .=
", ref_client";
312 $sql .=
", fk_user_author";
313 $sql .=
", fk_user_modif";
314 $sql .=
", description";
315 $sql .=
", model_pdf";
316 $sql .=
", fk_projet";
317 $sql .=
", fk_contrat";
318 $sql .=
", fk_statut";
319 $sql .=
", signed_status";
320 $sql .=
", note_private";
321 $sql .=
", note_public";
324 $sql .= $this->socid;
325 $sql .=
", '".$this->db->idate($now).
"'";
326 $sql .=
", '".$this->db->escape($this->ref).
"'";
327 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
328 $sql .=
", ".((int) $conf->entity);
329 $sql .=
", ".((int) $user->id);
330 $sql .=
", ".((int) $user->id);
331 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
332 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
333 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
334 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
335 $sql .=
", ".((int) $this->statut);
336 $sql .=
", ".($this->signed_status);
337 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
338 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
341 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
342 $result = $this->db->query($sql);
344 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
347 $this->ref =
'(PROV'.$this->id.
')';
348 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
350 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
351 $resql = $this->db->query($sql);
365 if (!$error && $this->origin && $this->origin_id) {
373 if (!$error && !$notrigger) {
375 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
386 $this->db->rollback();
387 $this->error = implode(
',', $this->errors);
388 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
392 $this->error = $this->db->error();
393 $this->db->rollback();
405 public function update($user, $notrigger = 0)
409 if (!is_numeric($this->duration)) {
412 if (!
dol_strlen((
string) $this->fk_project)) {
413 $this->fk_project = 0;
415 if (isset($this->ref_client)) {
416 $this->ref_client = trim($this->ref_client);
423 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
424 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
425 $sql .=
", duree = ".((int) $this->duration);
426 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
427 $sql .=
", fk_projet = ".((int) $this->fk_project);
428 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
429 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
430 $sql .=
", fk_user_modif = ".((int) $user->id);
431 $sql .=
" WHERE rowid = ".((int) $this->
id);
433 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
434 if ($this->db->query($sql)) {
442 if (!$error && !$notrigger) {
444 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
447 $this->db->rollback();
456 $this->error = $this->db->error();
457 $this->db->rollback();
469 public function fetch($rowid, $ref =
'')
471 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
472 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
473 $sql .=
" f.date_valid as datev,";
474 $sql .=
" f.tms as datem,";
475 $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";
476 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
478 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
479 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
481 $sql .=
" WHERE f.rowid = ".((int) $rowid);
484 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
485 $resql = $this->db->query($sql);
487 if ($this->db->num_rows($resql)) {
488 $obj = $this->db->fetch_object($resql);
490 $this->
id = $obj->rowid;
491 $this->
ref = $obj->ref;
492 $this->ref_client = $obj->ref_client;
494 $this->socid = $obj->fk_soc;
495 $this->
status = $obj->status;
496 $this->statut = $obj->status;
497 $this->signed_status = $obj->signed_status;
498 $this->duration = $obj->duree;
499 $this->datec = $this->db->jdate($obj->datec);
500 $this->dateo = $this->db->jdate($obj->dateo);
501 $this->datee = $this->db->jdate($obj->datee);
502 $this->datet = $this->db->jdate($obj->datet);
503 $this->datev = $this->db->jdate($obj->datev);
504 $this->datem = $this->db->jdate($obj->datem);
505 $this->fk_project = $obj->fk_project;
506 $this->note_public = $obj->note_public;
507 $this->note_private = $obj->note_private;
508 $this->model_pdf = $obj->model_pdf;
509 $this->fk_contrat = $obj->fk_contrat;
510 $this->entity = $obj->entity;
512 $this->user_creation_id = $obj->fk_user_author;
514 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
516 $this->last_main_doc = $obj->last_main_doc;
528 $this->db->free($resql);
534 $this->error = $this->db->lasterror();
550 if ($this->statut <= self::STATUS_DRAFT) {
554 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
560 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
561 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
562 $sql .=
" WHERE rowid = ".((int) $this->
id);
564 $resql = $this->db->query($sql);
568 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
579 $this->db->rollback();
583 $this->db->rollback();
584 $this->error = $this->db->lasterror();
599 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
603 if ($this->
status != self::STATUS_VALIDATED) {
609 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
617 $sql .=
" SET fk_statut = 1";
618 $sql .=
", ref = '".$this->db->escape($num).
"'";
619 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
620 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
621 $sql .=
" WHERE rowid = ".((int) $this->
id);
622 $sql .=
" AND entity = ".((int) $this->entity);
624 $sql .=
" AND fk_statut = 0";
626 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
627 $resql = $this->db->query($sql);
633 if (!$error && !$notrigger) {
635 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
643 $this->oldref = $this->ref;
646 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
647 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
650 $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).
"'";
651 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
652 $resql = $this->db->query($sql);
655 $this->error = $this->db->lasterror();
657 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
658 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
659 $resql = $this->db->query($sql);
662 $this->error = $this->db->lasterror();
668 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
669 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
670 if (!$error && file_exists($dirsource)) {
671 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
673 if (@rename($dirsource, $dirdest)) {
676 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
677 foreach ($listoffiles as $fileentry) {
678 $dirsource = $fileentry[
'name'];
679 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
680 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
681 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
682 @rename($dirsource, $dirdest);
694 $this->date_validation = $now;
698 $this->db->rollback();
699 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
720 if ($this->statut == self::STATUS_CLOSED) {
727 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
728 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
729 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
730 $sql .=
" fk_user_modif = " . ((int) $user->id);
731 $sql .=
" WHERE rowid = " . ((int) $this->
id);
733 $sql .=
" AND entity = " . ((int) $conf->entity);
735 if ($this->db->query($sql)) {
738 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
750 $this->db->rollback();
754 $this->error = $this->db->lasterror();
755 $this->db->rollback();
770 $this->author =
new User($this->db);
771 $this->author->fetch($this->user_creation_id);
773 $thm = $this->author->thm;
775 foreach ($this->lines as $line) {
776 $amount += ($line->duration / 60 / 60 * (float) $thm);
794 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
798 $outputlangs->load(
"interventions");
803 if (!empty($this->model_pdf)) {
804 $modele = $this->model_pdf;
810 $modelpath =
"core/modules/fichinter/doc/";
812 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
823 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
839 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
840 $langs->load(
"interventions");
841 $langs->load(
"propal");
845 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
849 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
853 $statuscode =
'status'.$status;
854 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
855 $statuscode =
'status6';
859 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
860 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
862 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
875 $langs->load(
'interventions');
878 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
879 if (isset($this->
status)) {
880 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
882 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
897 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
899 global $conf, $langs, $hookmanager;
901 if (!empty($conf->dol_no_mouse_hover)) {
908 'objecttype' => $this->element,
911 $classfortooltip =
'classfortooltip';
914 $classfortooltip =
'classforajaxtooltip';
915 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
921 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
923 if ($option !==
'nolink') {
925 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
926 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
927 $add_save_lastsearch_values = 1;
929 if ($add_save_lastsearch_values) {
930 $url .=
'&save_lastsearch_values=1';
935 if (empty($notooltip)) {
937 $label = $langs->trans(
"ShowIntervention");
938 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
940 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
941 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
943 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
946 if ($option ==
'nolink' || empty($url)) {
947 $linkstart =
'<span';
949 $linkstart =
'<a href="'.$url.
'"';
951 $linkstart .= $linkclose.
'>';
952 if ($option ==
'nolink' || empty($url)) {
953 $linkend =
'</span>';
958 $result .= $linkstart;
960 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
963 if ($withpicto != 2) {
964 $result .= $this->ref;
970 $hookmanager->initHooks(array(
'interventiondao'));
971 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
972 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
974 $result = $hookmanager->resPrint;
976 $result .= $hookmanager->resPrint;
992 global $conf, $db, $langs;
993 $langs->load(
"interventions");
1002 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1004 foreach ($dirmodels as $reldir) {
1008 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1016 $obj =
new $classname();
1017 '@phan-var-force ModeleNumRefFicheinter $obj';
1019 $numref = $obj->getNextValue($soc, $this);
1021 if ($numref !=
"") {
1028 $langs->load(
"errors");
1029 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1042 $sql =
"SELECT f.rowid,";
1043 $sql .=
" f.datec,";
1044 $sql .=
" f.tms as date_modification,";
1045 $sql .=
" f.date_valid as datev,";
1046 $sql .=
" f.fk_user_author,";
1047 $sql .=
" f.fk_user_modif as fk_user_modification,";
1048 $sql .=
" f.fk_user_valid";
1049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1050 $sql .=
" WHERE f.rowid = ".((int) $id);
1052 $resql = $this->db->query($sql);
1054 if ($this->db->num_rows($resql)) {
1055 $obj = $this->db->fetch_object($resql);
1057 $this->
id = $obj->rowid;
1059 $this->date_creation = $this->db->jdate($obj->datec);
1060 $this->date_modification = $this->db->jdate($obj->date_modification);
1061 $this->date_validation = $this->db->jdate($obj->datev);
1063 $this->user_creation_id = $obj->fk_user_author;
1064 $this->user_validation_id = $obj->fk_user_valid;
1065 $this->user_modification_id = $obj->fk_user_modification;
1067 $this->db->free($resql);
1080 public function delete(
User $user, $notrigger = 0)
1082 global $conf, $langs;
1083 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1089 if (!$error && !$notrigger) {
1091 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1094 $this->db->rollback();
1112 $this->error =
'ErrorFailToDeleteLinkedContact';
1118 $main = MAIN_DB_PREFIX.
'fichinterdet';
1119 $ef = $main.
"_extrafields";
1120 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1122 $resql = $this->db->query($sql);
1129 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1130 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1132 $resql = $this->db->query($sql);
1148 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1149 $sql .=
" WHERE rowid = ".((int) $this->
id);
1152 $resql = $this->db->query($sql);
1165 if ($conf->ficheinter->dir_output) {
1166 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1167 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1168 if (file_exists($file)) {
1172 $langs->load(
"errors");
1173 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1177 if (file_exists($dir)) {
1179 $langs->load(
"errors");
1180 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1188 $this->db->commit();
1191 $this->db->rollback();
1207 if ($user->hasRight(
'ficheinter',
'creer')) {
1208 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1209 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1210 $sql .=
" WHERE rowid = ".((int) $this->
id);
1211 $sql .=
" AND fk_statut = 0";
1213 if ($this->db->query($sql)) {
1214 $this->date_delivery = $date_delivery;
1217 $this->error = $this->db->error();
1218 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1237 if ($user->hasRight(
'ficheinter',
'creer')) {
1238 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1239 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1240 $sql .=
" fk_user_modif = ".((int) $user->id);
1241 $sql .=
" WHERE rowid = ".((int) $this->
id);
1243 if ($this->db->query($sql)) {
1247 $this->error = $this->db->error();
1248 dol_syslog(
"Fichinter::set_description Erreur SQL");
1268 if ($user->hasRight(
'ficheinter',
'creer')) {
1269 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1270 $sql .=
" SET fk_contrat = ".((int) $contractid);
1271 $sql .=
" WHERE rowid = ".((int) $this->
id);
1273 if ($this->db->query($sql)) {
1274 $this->fk_contrat = $contractid;
1277 $this->error = $this->db->error();
1296 global $hookmanager;
1303 foreach ($this->lines as $line) {
1304 $line->fetch_optionals();
1308 $objFrom = clone $this;
1311 if (!empty($socid) && $socid != $this->socid) {
1312 $objsoc =
new Societe($this->db);
1314 if ($objsoc->fetch($socid) > 0) {
1315 $this->socid = $objsoc->id;
1318 $this->fk_project = 0;
1319 $this->fk_delivery_address = 0;
1331 $this->user_author_id = $user->id;
1332 $this->user_validation_id = 0;
1333 $this->date_creation =
'';
1334 $this->date_validation =
'';
1336 $this->ref_client =
'';
1339 $this->context[
'createfromclone'] =
'createfromclone';
1340 $result = $this->
create($user);
1347 foreach ($this->lines as $line) {
1348 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1352 if (is_object($hookmanager)) {
1353 $parameters = array(
'objFrom' => $objFrom);
1355 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1363 unset($this->context[
'createfromclone']);
1367 $this->db->commit();
1370 $this->db->rollback();
1387 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1389 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1391 if ($this->
status == self::STATUS_DRAFT) {
1397 $line->fk_fichinter = $fichinterid;
1398 $line->desc = $desc;
1399 $line->date = $date_intervention;
1400 $line->datei = $date_intervention;
1401 $line->duration = $duration;
1403 if (is_array($array_options) && count($array_options) > 0) {
1404 $line->array_options = $array_options;
1407 $result = $line->insert($user);
1410 $this->db->commit();
1413 $this->error = $this->db->error();
1414 $this->db->rollback();
1438 $this->
ref =
'SPECIMEN';
1439 $this->ref_client =
'SPECIMEN CLIENT';
1440 $this->specimen = 1;
1442 $this->datec = $now;
1443 $this->note_private =
'Private note';
1444 $this->note_public =
'SPECIMEN';
1445 $this->duration = 0;
1448 while ($xnbp < $nbp) {
1450 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1451 $line->date = ($now - 3600 * (1 + $xnbp));
1452 $line->datei = ($now - 3600 * (1 + $xnbp));
1453 $line->duration = 600;
1454 $line->fk_fichinter = 0;
1455 $this->lines[$xnbp] = $line;
1458 $this->duration += $line->duration;
1473 $this->lines = array();
1475 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1476 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1477 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1478 $sql .=
" ORDER BY rang ASC, date ASC";
1480 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1482 $resql = $this->db->query($sql);
1484 $num = $this->db->num_rows($resql);
1487 $objp = $this->db->fetch_object($resql);
1490 $line->id = $objp->rowid;
1491 $line->fk_fichinter = $objp->fk_fichinter;
1492 $line->desc = $objp->description;
1493 $line->duration = $objp->duree;
1495 $line->qty = round($objp->duree / 3600, 2);
1496 $line->date = $this->db->jdate($objp->date);
1497 $line->datei = $this->db->jdate($objp->date);
1498 $line->rang = $objp->rang;
1499 $line->product_type = 1;
1500 $line->fetch_optionals();
1502 $this->lines[$i] = $line;
1505 $this->db->free($resql);
1509 $this->error = $this->db->error();
1542 if ($user->hasRight(
'ficheinter',
'creer')) {
1549 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1550 $sql .=
" WHERE rowid = ".((int) $this->
id);
1552 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1553 $resql = $this->db->query($sql);
1555 $this->errors[] = $this->db->error();
1560 $this->ref_client = $ref_client;
1563 if (!$notrigger && empty($error)) {
1565 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1573 $this->db->commit();
1576 foreach ($this->errors as $errmsg) {
1577 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1578 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1580 $this->db->rollback();
1599 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1601 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1602 $return .=
'<div class="info-box info-box-sm">';
1603 $return .=
'<span class="info-box-icon bg-infobox-action">';
1605 $return .=
'</span>';
1606 $return .=
'<div class="info-box-content">';
1607 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1608 if ($selected >= 0) {
1609 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1611 if (!empty($arraydata[
'thirdparty'])) {
1612 $tmpthirdparty = $arraydata[
'thirdparty'];
1613 '@phan-var-force Societe $tmpthirdparty';
1614 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1616 if (property_exists($this,
'duration')) {
1617 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1619 if (method_exists($this,
'getLibStatut')) {
1620 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1622 $return .=
'</div>';
1623 $return .=
'</div>';
1624 $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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
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 clickable 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.
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_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 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.