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))) {
638 if (empty($this->thirdparty)) {
647 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
648 $sql .=
" SET fk_statut = 1";
649 $sql .=
", ref = '".$this->db->escape($num).
"'";
650 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
651 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
652 $sql .=
" WHERE rowid = ".((int) $this->
id);
653 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
655 $sql .=
" AND fk_statut = 0";
657 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
658 $resql = $this->db->query($sql);
664 if (!$error && !$notrigger) {
666 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
674 $this->oldref = $this->ref;
677 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
678 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
681 $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).
"'";
682 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
683 $resql = $this->db->query($sql);
686 $this->error = $this->db->lasterror();
688 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
689 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
690 $resql = $this->db->query($sql);
693 $this->error = $this->db->lasterror();
699 $dirsource =
$conf->ficheinter->dir_output.
'/'.$oldref;
700 $dirdest =
$conf->ficheinter->dir_output.
'/'.$newref;
701 if (!$error && file_exists($dirsource)) {
702 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
704 if (@rename($dirsource, $dirdest)) {
707 $listoffiles =
dol_dir_list(
$conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
708 foreach ($listoffiles as $fileentry) {
709 $dirsource = $fileentry[
'name'];
710 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
711 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
712 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
713 @rename($dirsource, $dirdest);
725 $this->date_validation = $now;
729 $this->db->rollback();
730 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
751 if ($this->
status == self::STATUS_CLOSED) {
758 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
759 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
760 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
761 $sql .=
" fk_user_modif = " . ((int) $user->id);
762 $sql .=
" WHERE rowid = " . ((int) $this->
id);
764 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
766 if ($this->db->query($sql)) {
769 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
782 $this->db->rollback();
786 $this->error = $this->db->lasterror();
787 $this->db->rollback();
802 $this->author =
new User($this->db);
803 $this->author->fetch($this->user_creation_id);
805 $thm = $this->author->thm;
807 foreach ($this->lines as $line) {
808 $amount += ($line->duration / 60 / 60 * (float) $thm);
826 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
830 $outputlangs->load(
"interventions");
835 if (!empty($this->model_pdf)) {
836 $modele = $this->model_pdf;
842 $modelpath =
"core/modules/fichinter/doc/";
844 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
855 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
871 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
872 $langs->load(
"interventions");
873 $langs->load(
"propal");
877 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
881 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
885 $statuscode =
'status'.$status;
886 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
887 $statuscode =
'status6';
891 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
892 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
894 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
907 $langs->load(
'interventions');
910 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
911 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
912 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
927 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
929 global
$conf, $langs, $hookmanager;
931 if (!empty(
$conf->dol_no_mouse_hover)) {
938 'objecttype' => $this->element,
941 $classfortooltip =
'classfortooltip';
944 $classfortooltip =
'classforajaxtooltip';
945 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
951 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
953 if ($option !==
'nolink') {
955 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
956 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
957 $add_save_lastsearch_values = 1;
959 if ($add_save_lastsearch_values) {
960 $url .=
'&save_lastsearch_values=1';
965 if (empty($notooltip)) {
967 $label = $langs->trans(
"ShowIntervention");
968 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
970 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
971 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
973 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
976 if ($option ==
'nolink' || empty($url)) {
977 $linkstart =
'<span';
979 $linkstart =
'<a href="'.$url.
'"';
981 $linkstart .= $linkclose.
'>';
982 if ($option ==
'nolink' || empty($url)) {
983 $linkend =
'</span>';
988 $result .= $linkstart;
990 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
993 if ($withpicto != 2) {
994 $result .= $this->ref;
1000 $hookmanager->initHooks(array(
'interventiondao'));
1001 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1002 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1004 $result = $hookmanager->resPrint;
1006 $result .= $hookmanager->resPrint;
1022 global
$conf, $db, $langs;
1023 $langs->load(
"interventions");
1032 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1034 foreach ($dirmodels as $reldir) {
1038 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1046 $obj =
new $classname();
1047 '@phan-var-force ModeleNumRefFicheinter $obj';
1049 $numref = $obj->getNextValue($soc, $this);
1051 if ($numref !=
"") {
1058 $langs->load(
"errors");
1059 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1072 $sql =
"SELECT f.rowid,";
1073 $sql .=
" f.datec,";
1074 $sql .=
" f.tms as date_modification,";
1075 $sql .=
" f.date_valid as datev,";
1076 $sql .=
" f.fk_user_author,";
1077 $sql .=
" f.fk_user_modif as fk_user_modification,";
1078 $sql .=
" f.fk_user_valid";
1079 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1080 $sql .=
" WHERE f.rowid = ".((int) $id);
1082 $resql = $this->db->query($sql);
1084 if ($this->db->num_rows($resql)) {
1085 $obj = $this->db->fetch_object($resql);
1087 $this->
id = $obj->rowid;
1089 $this->date_creation = $this->db->jdate($obj->datec);
1090 $this->date_modification = $this->db->jdate($obj->date_modification);
1091 $this->date_validation = $this->db->jdate($obj->datev);
1093 $this->user_creation_id = $obj->fk_user_author;
1094 $this->user_validation_id = $obj->fk_user_valid;
1095 $this->user_modification_id = $obj->fk_user_modification;
1097 $this->db->free($resql);
1110 public function delete(
User $user, $notrigger = 0)
1112 global
$conf, $langs;
1113 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1119 if (!$error && !$notrigger) {
1121 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1124 $this->db->rollback();
1142 $this->error =
'ErrorFailToDeleteLinkedContact';
1148 $main = MAIN_DB_PREFIX.
'fichinterdet';
1149 $ef = $main.
"_extrafields";
1150 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1152 $resql = $this->db->query($sql);
1159 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1160 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1162 $resql = $this->db->query($sql);
1178 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1179 $sql .=
" WHERE rowid = ".((int) $this->
id);
1182 $resql = $this->db->query($sql);
1195 if ($conf->ficheinter->dir_output && !empty($fichinterref)) {
1196 $dir =
$conf->ficheinter->dir_output.
"/".$fichinterref;
1197 $file =
$conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1198 if (file_exists($file)) {
1202 $langs->load(
"errors");
1203 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1207 if (file_exists($dir)) {
1209 $langs->load(
"errors");
1210 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1218 $this->db->commit();
1221 $this->db->rollback();
1237 if ($user->hasRight(
'ficheinter',
'creer')) {
1238 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1239 $sql .=
" SET datei = '".$this->db->idate($delivery_date_receipt).
"'";
1240 $sql .=
" WHERE rowid = ".((int) $this->
id);
1241 $sql .=
" AND fk_statut = 0";
1243 if ($this->db->query($sql)) {
1244 $this->date_delivery = $delivery_date_receipt;
1245 $this->delivery_date_receipt = $delivery_date_receipt;
1248 $this->error = $this->db->error();
1249 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1268 if ($user->hasRight(
'ficheinter',
'creer')) {
1269 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1270 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1271 $sql .=
" fk_user_modif = ".((int) $user->id);
1272 $sql .=
" WHERE rowid = ".((int) $this->
id);
1274 if ($this->db->query($sql)) {
1278 $this->error = $this->db->error();
1279 dol_syslog(
"Fichinter::set_description Erreur SQL");
1299 if ($user->hasRight(
'ficheinter',
'creer')) {
1300 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1301 $sql .=
" SET fk_contrat = ".((int) $contractid);
1302 $sql .=
" WHERE rowid = ".((int) $this->
id);
1304 if ($this->db->query($sql)) {
1305 $this->fk_contrat = $contractid;
1308 $this->error = $this->db->error();
1329 global $hookmanager, $langs;
1330 $langs->load(
"errors");
1337 foreach ($this->lines as $line) {
1338 $line->fetch_optionals();
1342 $objFrom = clone $this;
1345 if (!empty($socid) && $socid != $this->socid) {
1346 $objsoc =
new Societe($this->db);
1348 if ($objsoc->fetch($socid) > 0) {
1349 $this->socid = $objsoc->id;
1352 $this->fk_project = 0;
1353 $this->fk_delivery_address = 0;
1365 $this->user_author_id = $user->id;
1366 $this->user_validation_id = 0;
1367 $this->date_creation =
'';
1368 $this->date_validation =
'';
1370 $this->ref_client =
'';
1372 if (!$clone_notes) {
1373 $this->note_private =
'';
1374 $this->note_public =
'';
1378 $this->context[
'createfromclone'] =
'createfromclone';
1379 $result = $this->
create($user);
1386 foreach ($this->lines as $line) {
1387 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1391 if (is_object($hookmanager)) {
1392 $parameters = array(
'objFrom' => $objFrom);
1394 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1403 if ($clone_contacts) {
1404 foreach (array(
'internal',
'external') as $source) {
1405 $tab = $objFrom->liste_contact(-1, $source);
1406 if (is_array($tab) && count($tab) > 0) {
1407 foreach ($tab as $contacttoadd) {
1409 $contacttoadd[
'id'],
1410 $contacttoadd[
'code'],
1411 $contacttoadd[
'source']
1413 if ($this->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1414 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1416 } elseif ($retAddContact < 0) {
1420 } elseif ($tab < 0) {
1421 $this->error .= $objFrom->error;
1427 unset($this->context[
'createfromclone']);
1431 $this->db->commit();
1434 $this->db->rollback();
1451 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1453 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1455 if ($this->
status == self::STATUS_DRAFT) {
1461 $line->fk_fichinter = $fichinterid;
1462 $line->desc = $desc;
1463 $line->date = $date_intervention;
1464 $line->datei = $date_intervention;
1465 $line->duration = $duration;
1467 if (is_array($array_options) && count($array_options) > 0) {
1468 $line->array_options = $array_options;
1471 $result = $line->insert($user);
1474 $this->db->commit();
1477 $this->error = $this->db->error();
1478 $this->db->rollback();
1502 $this->
ref =
'SPECIMEN';
1503 $this->ref_client =
'SPECIMEN CLIENT';
1504 $this->specimen = 1;
1506 $this->datec = $now;
1507 $this->note_private =
'Private note';
1508 $this->note_public =
'SPECIMEN';
1509 $this->duration = 0;
1512 while ($xnbp < $nbp) {
1514 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1515 $line->date = ($now - 3600 * (1 + $xnbp));
1516 $line->datei = ($now - 3600 * (1 + $xnbp));
1517 $line->duration = 600;
1518 $line->fk_fichinter = 0;
1519 $this->lines[$xnbp] = $line;
1522 $this->duration += $line->duration;
1537 $this->lines = array();
1539 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams";
1540 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1541 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1542 $sql .=
" ORDER BY rang ASC, date ASC";
1544 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1546 $resql = $this->db->query($sql);
1548 $num = $this->db->num_rows($resql);
1551 $objp = $this->db->fetch_object($resql);
1554 $line->id = $objp->rowid;
1555 $line->fk_fichinter = $objp->fk_fichinter;
1556 $line->desc = $objp->description;
1557 $line->duration = $objp->duree;
1559 $line->qty = round($objp->duree / 3600, 2);
1560 $line->date = $this->db->jdate($objp->date);
1561 $line->datei = $this->db->jdate($objp->date);
1562 $line->rang = $objp->rang;
1563 $line->product_type = 1;
1564 $line->fetch_optionals();
1566 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1568 $this->lines[$i] = $line;
1571 $this->db->free($resql);
1575 $this->error = $this->db->error();
1608 if ($user->hasRight(
'ficheinter',
'creer')) {
1615 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1616 $sql .=
" WHERE rowid = ".((int) $this->
id);
1618 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1619 $resql = $this->db->query($sql);
1621 $this->errors[] = $this->db->error();
1626 $this->ref_client = $ref_client;
1629 if (!$notrigger && empty($error)) {
1631 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1639 $this->db->commit();
1642 foreach ($this->errors as $errmsg) {
1643 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1644 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1646 $this->db->rollback();
1665 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1667 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1668 $return .=
'<div class="info-box info-box-sm">';
1669 $return .=
'<span class="info-box-icon bg-infobox-action">';
1671 $return .=
'</span>';
1672 $return .=
'<div class="info-box-content">';
1673 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1674 if ($selected >= 0) {
1675 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1677 if (!empty($arraydata[
'thirdparty'])) {
1678 $tmpthirdparty = $arraydata[
'thirdparty'];
1679 '@phan-var-force Societe $tmpthirdparty';
1680 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1682 if (property_exists($this,
'duration')) {
1683 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1685 if (method_exists($this,
'getLibStatut')) {
1686 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1688 $return .=
'</div>';
1689 $return .=
'</div>';
1690 $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.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
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...