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:Contrat:contrat/class/contrat.class.php',
'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' =>
'RefExt',
'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';
165 public $fk_contrat = 0;
181 public $extraparams = array();
186 public $lines = array();
213 public $date_delivery;
219 public $delivery_date_receipt;
225 public $user_author_id;
250 $sql =
"SELECT count(fi.rowid) as nb";
251 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
252 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
253 if (!$user->hasRight(
'societe',
'client',
'voir')) {
254 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
255 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
258 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
260 $resql = $this->db->query($sql);
262 while ($obj = $this->db->fetch_object($resql)) {
263 $this->nb[
"interventions"] = $obj->nb;
265 $this->db->free($resql);
269 $this->error = $this->db->error();
281 public function create($user, $notrigger = 0)
283 global
$conf, $langs;
290 if (!empty($this->ref)) {
293 $this->error =
'ErrorRefAlreadyExists';
294 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
295 $this->db->rollback();
299 if (!is_numeric($this->duration)) {
302 if (isset($this->ref_client)) {
303 $this->ref_client = trim($this->ref_client);
306 if ($this->socid <= 0) {
307 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
308 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
314 $result = $soc->fetch($this->socid);
320 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
324 $sql .=
", ref_client";
326 $sql .=
", fk_user_author";
327 $sql .=
", fk_user_modif";
328 $sql .=
", description";
329 $sql .=
", model_pdf";
330 $sql .=
", fk_projet";
331 $sql .=
", fk_contrat";
332 $sql .=
", fk_statut";
333 $sql .=
", signed_status";
334 $sql .=
", note_private";
335 $sql .=
", note_public";
338 $sql .= $this->socid;
339 $sql .=
", '".$this->db->idate($now).
"'";
340 $sql .=
", '".$this->db->escape($this->ref).
"'";
341 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
342 $sql .=
", ".((int) $this->entity);
343 $sql .=
", ".((int) $user->id);
344 $sql .=
", ".((int) $user->id);
345 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
346 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
347 $sql .=
", ".((int) $this->fk_project > 0 ? ((
int) $this->fk_project) : 0);
348 $sql .=
", ".((int) $this->fk_contrat > 0 ? ((
int) $this->fk_contrat) : 0);
349 $sql .=
", ".((int) $this->
status);
350 $sql .=
", ".((int) $this->signed_status);
351 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
352 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
355 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
356 $result = $this->db->query($sql);
358 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
361 $this->ref =
'(PROV'.$this->id.
')';
362 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
364 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
365 $resql = $this->db->query($sql);
379 if (!$error && $this->origin && $this->origin_id) {
387 if (!$error && !$notrigger) {
389 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
400 $this->db->rollback();
401 $this->error = implode(
',', $this->errors);
402 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
406 $this->error = $this->db->error();
407 $this->db->rollback();
419 public function update($user, $notrigger = 0)
423 if (!is_numeric($this->duration)) {
426 if (!
dol_strlen((
string) $this->fk_project)) {
427 $this->fk_project = 0;
429 if (isset($this->ref_client)) {
430 $this->ref_client = trim($this->ref_client);
437 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
438 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
439 $sql .=
", duree = ".((int) $this->duration);
440 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
441 if ((
int) $this->fk_project > 0) {
442 $sql .=
", fk_projet = ".((int) $this->fk_project);
444 if (isset($this->datec)) {
445 $sql .=
", datec = ".($this->datec ?
"'".$this->db->idate($this->datec).
"'" :
"null");
447 if (isset($this->datev)) {
448 $sql .=
", date_valid = ".($this->datev ?
"'".$this->db->idate($this->datev).
"'" :
"null");
450 if (isset($this->datet)) {
451 $sql .=
", datet = ".($this->datet ?
"'".$this->db->idate($this->datet).
"'" :
"null");
453 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
454 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
455 $sql .=
", fk_user_modif = ".((int) $user->id);
456 $sql .=
" WHERE rowid = ".((int) $this->
id);
458 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
459 if ($this->db->query($sql)) {
467 if (!$error && !$notrigger) {
469 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
472 $this->db->rollback();
481 $this->error = $this->db->error();
482 $this->db->rollback();
495 public function fetch($rowid, $ref =
'', $ref_ext =
'')
497 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
498 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
499 $sql .=
" f.date_valid as datev,";
500 $sql .=
" f.tms as datem,";
501 $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";
502 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
503 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
505 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
506 } elseif ($ref_ext) {
507 $sql .=
" AND f.ref_ext = '".$this->db->escape($ref_ext).
"'";
509 $sql .=
" AND f.rowid = ".((int) $rowid);
512 $resql = $this->db->query($sql);
514 if ($this->db->num_rows($resql)) {
515 $obj = $this->db->fetch_object($resql);
517 $this->
id = $obj->rowid;
518 $this->
ref = $obj->ref;
519 $this->ref_client = $obj->ref_client;
521 $this->socid = $obj->fk_soc;
522 $this->
status = $obj->status;
523 $this->statut = $obj->status;
524 $this->signed_status = $obj->signed_status;
525 $this->duration = $obj->duree;
526 $this->datec = $this->db->jdate($obj->datec);
527 $this->dateo = $this->db->jdate($obj->dateo);
528 $this->datee = $this->db->jdate($obj->datee);
529 $this->datet = $this->db->jdate($obj->datet);
530 $this->datev = $this->db->jdate($obj->datev);
531 $this->datem = $this->db->jdate($obj->datem);
532 $this->fk_project = $obj->fk_project;
533 $this->note_public = $obj->note_public;
534 $this->note_private = $obj->note_private;
535 $this->model_pdf = $obj->model_pdf;
536 $this->fk_contrat = $obj->fk_contrat;
537 $this->entity = $obj->entity;
539 $this->user_creation_id = $obj->fk_user_author;
541 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
543 $this->last_main_doc = $obj->last_main_doc;
555 $this->db->free($resql);
561 $this->error = $this->db->lasterror();
577 if ($this->
status <= self::STATUS_DRAFT) {
581 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
587 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
588 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
589 $sql .=
" WHERE rowid = ".((int) $this->
id);
591 $resql = $this->db->query($sql);
595 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
607 $this->db->rollback();
611 $this->db->rollback();
612 $this->error = $this->db->lasterror();
627 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
631 if ($this->
status != self::STATUS_VALIDATED) {
637 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
644 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
645 $sql .=
" SET fk_statut = 1";
646 $sql .=
", ref = '".$this->db->escape($num).
"'";
647 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
648 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
649 $sql .=
" WHERE rowid = ".((int) $this->
id);
650 $sql .=
" AND entity = ".((int) $this->entity);
652 $sql .=
" AND fk_statut = 0";
654 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
655 $resql = $this->db->query($sql);
661 if (!$error && !$notrigger) {
663 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
671 $this->oldref = $this->ref;
674 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
675 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
678 $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).
"'";
679 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
680 $resql = $this->db->query($sql);
683 $this->error = $this->db->lasterror();
685 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
686 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
687 $resql = $this->db->query($sql);
690 $this->error = $this->db->lasterror();
696 $dirsource =
$conf->ficheinter->dir_output.
'/'.$oldref;
697 $dirdest =
$conf->ficheinter->dir_output.
'/'.$newref;
698 if (!$error && file_exists($dirsource)) {
699 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
701 if (@rename($dirsource, $dirdest)) {
704 $listoffiles =
dol_dir_list(
$conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
705 foreach ($listoffiles as $fileentry) {
706 $dirsource = $fileentry[
'name'];
707 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
708 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
709 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
710 @rename($dirsource, $dirdest);
722 $this->date_validation = $now;
726 $this->db->rollback();
727 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
748 if ($this->
status == self::STATUS_CLOSED) {
755 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
756 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
757 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
758 $sql .=
" fk_user_modif = " . ((int) $user->id);
759 $sql .=
" WHERE rowid = " . ((int) $this->
id);
761 $sql .=
" AND entity = " . ((int)
$conf->entity);
763 if ($this->db->query($sql)) {
766 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
779 $this->db->rollback();
783 $this->error = $this->db->lasterror();
784 $this->db->rollback();
799 $this->author =
new User($this->db);
800 $this->author->fetch($this->user_creation_id);
802 $thm = $this->author->thm;
804 foreach ($this->lines as $line) {
805 $amount += ($line->duration / 60 / 60 * (float) $thm);
823 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
827 $outputlangs->load(
"interventions");
832 if (!empty($this->model_pdf)) {
833 $modele = $this->model_pdf;
839 $modelpath =
"core/modules/fichinter/doc/";
841 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
852 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
868 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
869 $langs->load(
"interventions");
870 $langs->load(
"propal");
874 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
878 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
882 $statuscode =
'status'.$status;
883 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
884 $statuscode =
'status6';
888 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
889 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
891 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
904 $langs->load(
'interventions');
907 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
908 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
909 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
924 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
926 global
$conf, $langs, $hookmanager;
928 if (!empty(
$conf->dol_no_mouse_hover)) {
935 'objecttype' => $this->element,
938 $classfortooltip =
'classfortooltip';
941 $classfortooltip =
'classforajaxtooltip';
942 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
948 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
950 if ($option !==
'nolink') {
952 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
953 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
954 $add_save_lastsearch_values = 1;
956 if ($add_save_lastsearch_values) {
957 $url .=
'&save_lastsearch_values=1';
962 if (empty($notooltip)) {
964 $label = $langs->trans(
"ShowIntervention");
965 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
967 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
968 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
970 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
973 if ($option ==
'nolink' || empty($url)) {
974 $linkstart =
'<span';
976 $linkstart =
'<a href="'.$url.
'"';
978 $linkstart .= $linkclose.
'>';
979 if ($option ==
'nolink' || empty($url)) {
980 $linkend =
'</span>';
985 $result .= $linkstart;
987 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
990 if ($withpicto != 2) {
991 $result .= $this->ref;
997 $hookmanager->initHooks(array(
'interventiondao'));
998 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
999 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1001 $result = $hookmanager->resPrint;
1003 $result .= $hookmanager->resPrint;
1019 global
$conf, $db, $langs;
1020 $langs->load(
"interventions");
1029 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1031 foreach ($dirmodels as $reldir) {
1035 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1043 $obj =
new $classname();
1044 '@phan-var-force ModeleNumRefFicheinter $obj';
1046 $numref = $obj->getNextValue($soc, $this);
1048 if ($numref !=
"") {
1055 $langs->load(
"errors");
1056 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1069 $sql =
"SELECT f.rowid,";
1070 $sql .=
" f.datec,";
1071 $sql .=
" f.tms as date_modification,";
1072 $sql .=
" f.date_valid as datev,";
1073 $sql .=
" f.fk_user_author,";
1074 $sql .=
" f.fk_user_modif as fk_user_modification,";
1075 $sql .=
" f.fk_user_valid";
1076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1077 $sql .=
" WHERE f.rowid = ".((int) $id);
1079 $resql = $this->db->query($sql);
1081 if ($this->db->num_rows($resql)) {
1082 $obj = $this->db->fetch_object($resql);
1084 $this->
id = $obj->rowid;
1086 $this->date_creation = $this->db->jdate($obj->datec);
1087 $this->date_modification = $this->db->jdate($obj->date_modification);
1088 $this->date_validation = $this->db->jdate($obj->datev);
1090 $this->user_creation_id = $obj->fk_user_author;
1091 $this->user_validation_id = $obj->fk_user_valid;
1092 $this->user_modification_id = $obj->fk_user_modification;
1094 $this->db->free($resql);
1107 public function delete(
User $user, $notrigger = 0)
1109 global
$conf, $langs;
1110 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1116 if (!$error && !$notrigger) {
1118 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1121 $this->db->rollback();
1139 $this->error =
'ErrorFailToDeleteLinkedContact';
1145 $main = MAIN_DB_PREFIX.
'fichinterdet';
1146 $ef = $main.
"_extrafields";
1147 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1149 $resql = $this->db->query($sql);
1156 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1157 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1159 $resql = $this->db->query($sql);
1175 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1176 $sql .=
" WHERE rowid = ".((int) $this->
id);
1179 $resql = $this->db->query($sql);
1192 if ($conf->ficheinter->dir_output) {
1193 $dir =
$conf->ficheinter->dir_output.
"/".$fichinterref;
1194 $file =
$conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1195 if (file_exists($file)) {
1199 $langs->load(
"errors");
1200 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1204 if (file_exists($dir)) {
1206 $langs->load(
"errors");
1207 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1215 $this->db->commit();
1218 $this->db->rollback();
1234 if ($user->hasRight(
'ficheinter',
'creer')) {
1235 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1236 $sql .=
" SET datei = '".$this->db->idate($delivery_date_receipt).
"'";
1237 $sql .=
" WHERE rowid = ".((int) $this->
id);
1238 $sql .=
" AND fk_statut = 0";
1240 if ($this->db->query($sql)) {
1241 $this->date_delivery = $delivery_date_receipt;
1242 $this->delivery_date_receipt = $delivery_date_receipt;
1245 $this->error = $this->db->error();
1246 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1265 if ($user->hasRight(
'ficheinter',
'creer')) {
1266 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1267 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1268 $sql .=
" fk_user_modif = ".((int) $user->id);
1269 $sql .=
" WHERE rowid = ".((int) $this->
id);
1271 if ($this->db->query($sql)) {
1275 $this->error = $this->db->error();
1276 dol_syslog(
"Fichinter::set_description Erreur SQL");
1296 if ($user->hasRight(
'ficheinter',
'creer')) {
1297 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1298 $sql .=
" SET fk_contrat = ".((int) $contractid);
1299 $sql .=
" WHERE rowid = ".((int) $this->
id);
1301 if ($this->db->query($sql)) {
1302 $this->fk_contrat = $contractid;
1305 $this->error = $this->db->error();
1326 global $hookmanager, $langs;
1327 $langs->load(
"errors");
1334 foreach ($this->lines as $line) {
1335 $line->fetch_optionals();
1339 $objFrom = clone $this;
1342 if (!empty($socid) && $socid != $this->socid) {
1343 $objsoc =
new Societe($this->db);
1345 if ($objsoc->fetch($socid) > 0) {
1346 $this->socid = $objsoc->id;
1349 $this->fk_project = 0;
1350 $this->fk_delivery_address = 0;
1362 $this->user_author_id = $user->id;
1363 $this->user_validation_id = 0;
1364 $this->date_creation =
'';
1365 $this->date_validation =
'';
1367 $this->ref_client =
'';
1369 if (!$clone_notes) {
1370 $this->note_private =
'';
1371 $this->note_public =
'';
1375 $this->context[
'createfromclone'] =
'createfromclone';
1376 $result = $this->
create($user);
1383 foreach ($this->lines as $line) {
1384 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1388 if (is_object($hookmanager)) {
1389 $parameters = array(
'objFrom' => $objFrom);
1391 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1400 if ($clone_contacts) {
1401 foreach (array(
'internal',
'external') as $source) {
1402 $tab = $objFrom->liste_contact(-1, $source);
1403 if (is_array($tab) && count($tab) > 0) {
1404 foreach ($tab as $contacttoadd) {
1406 $contacttoadd[
'id'],
1407 $contacttoadd[
'code'],
1408 $contacttoadd[
'source']
1410 if ($this->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1411 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1413 } elseif ($retAddContact < 0) {
1417 } elseif ($tab < 0) {
1418 $this->error .= $objFrom->error;
1424 unset($this->context[
'createfromclone']);
1428 $this->db->commit();
1431 $this->db->rollback();
1448 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1450 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1452 if ($this->
status == self::STATUS_DRAFT) {
1458 $line->fk_fichinter = $fichinterid;
1459 $line->desc = $desc;
1460 $line->date = $date_intervention;
1461 $line->datei = $date_intervention;
1462 $line->duration = $duration;
1464 if (is_array($array_options) && count($array_options) > 0) {
1465 $line->array_options = $array_options;
1468 $result = $line->insert($user);
1471 $this->db->commit();
1474 $this->error = $this->db->error();
1475 $this->db->rollback();
1499 $this->
ref =
'SPECIMEN';
1500 $this->ref_client =
'SPECIMEN CLIENT';
1501 $this->specimen = 1;
1503 $this->datec = $now;
1504 $this->note_private =
'Private note';
1505 $this->note_public =
'SPECIMEN';
1506 $this->duration = 0;
1509 while ($xnbp < $nbp) {
1511 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1512 $line->date = ($now - 3600 * (1 + $xnbp));
1513 $line->datei = ($now - 3600 * (1 + $xnbp));
1514 $line->duration = 600;
1515 $line->fk_fichinter = 0;
1516 $this->lines[$xnbp] = $line;
1519 $this->duration += $line->duration;
1534 $this->lines = array();
1536 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams";
1537 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1538 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1539 $sql .=
" ORDER BY rang ASC, date ASC";
1541 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1543 $resql = $this->db->query($sql);
1545 $num = $this->db->num_rows($resql);
1548 $objp = $this->db->fetch_object($resql);
1551 $line->id = $objp->rowid;
1552 $line->fk_fichinter = $objp->fk_fichinter;
1553 $line->desc = $objp->description;
1554 $line->duration = $objp->duree;
1556 $line->qty = round($objp->duree / 3600, 2);
1557 $line->date = $this->db->jdate($objp->date);
1558 $line->datei = $this->db->jdate($objp->date);
1559 $line->rang = $objp->rang;
1560 $line->product_type = 1;
1561 $line->fetch_optionals();
1563 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1565 $this->lines[$i] = $line;
1568 $this->db->free($resql);
1572 $this->error = $this->db->error();
1605 if ($user->hasRight(
'ficheinter',
'creer')) {
1612 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1613 $sql .=
" WHERE rowid = ".((int) $this->
id);
1615 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1616 $resql = $this->db->query($sql);
1618 $this->errors[] = $this->db->error();
1623 $this->ref_client = $ref_client;
1626 if (!$notrigger && empty($error)) {
1628 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1636 $this->db->commit();
1639 foreach ($this->errors as $errmsg) {
1640 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1641 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1643 $this->db->rollback();
1662 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1664 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1665 $return .=
'<div class="info-box info-box-sm">';
1666 $return .=
'<span class="info-box-icon bg-infobox-action">';
1668 $return .=
'</span>';
1669 $return .=
'<div class="info-box-content">';
1670 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1671 if ($selected >= 0) {
1672 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1674 if (!empty($arraydata[
'thirdparty'])) {
1675 $tmpthirdparty = $arraydata[
'thirdparty'];
1676 '@phan-var-force Societe $tmpthirdparty';
1677 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1679 if (property_exists($this,
'duration')) {
1680 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1682 if (method_exists($this,
'getLibStatut')) {
1683 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1685 $return .=
'</div>';
1686 $return .=
'</div>';
1687 $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.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage Dolibarr database access.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
createFromClone(User $user, $socid=0, $clone_contacts=false, $clone_notes=false)
Load an object from its id and create a new one in database.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setClose($user, $notrigger=0)
Close intervention.
const STATUS_DRAFT
Draft status.
create($user, $notrigger=0)
Create an intervention into data base.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
set_date_delivery($user, $delivery_date_receipt)
Defines a delivery date of the receipt of intervention.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
fetch($rowid, $ref='', $ref_ext='')
Fetch a intervention.
const STATUS_CLOSED
Closed.
setDraft($user)
Set status to draft.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
getAmount()
Returns amount based on user thm.
setRefClient($user, $ref_client, $notrigger=0)
Set customer reference number.
set_contrat($user, $contractid)
Link intervention to a contract.
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
loadStateBoard()
Load indicators into this->nb for board.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load information on object.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...