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';
35require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
45 use CommonSignedObject;
52 public $TRIGGER_PREFIX =
'FICHINTER';
54 public $fields = array(
55 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
56 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
57 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'position' => 20),
58 'fk_contrat' => array(
'type' =>
'integer:Contrat:contrat/class/contrat.class.php',
'label' =>
'Contract',
'enabled' =>
'isModEnabled("contract")',
'visible' => -1,
'position' => 25),
59 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
60 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
61 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
62 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
63 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
64 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
65 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
66 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
67 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 65),
68 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
69 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
70 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
71 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
72 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
73 'duree' => array(
'type' =>
'integer',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
74 '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')),
75 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
76 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
77 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
78 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 120),
79 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
80 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
81 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
82 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
88 public $element =
'fichinter';
93 public $fk_element =
'fk_fichinter';
98 public $table_element =
'fichinter';
103 public $table_element_line =
'fichinterdet';
108 public $class_element_line =
'FichinterLigne';
113 public $picto =
'intervention';
184 public $fk_contrat = 0;
200 public $extraparams = array();
205 public $lines = array();
232 public $date_delivery;
238 public $delivery_date_receipt;
244 public $user_author_id;
269 $sql =
"SELECT count(fi.rowid) as nb";
270 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
271 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
272 if (!$user->hasRight(
'societe',
'client',
'voir')) {
273 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
274 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
277 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
279 $resql = $this->db->query($sql);
281 while ($obj = $this->db->fetch_object($resql)) {
282 $this->nb[
"interventions"] = $obj->nb;
284 $this->db->free($resql);
288 $this->error = $this->db->error();
300 public function create($user, $notrigger = 0)
307 if (!empty($this->ref)) {
310 $this->error =
'ErrorRefAlreadyExists';
311 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
312 $this->db->rollback();
316 if (!is_numeric($this->duration)) {
319 if (!empty($this->ref_client)) {
320 $this->ref_client = trim($this->ref_client);
323 if ($this->socid <= 0) {
324 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
325 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
331 $result = $soc->fetch($this->socid);
337 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
341 $sql .=
", ref_client";
343 $sql .=
", fk_user_author";
344 $sql .=
", fk_user_modif";
345 $sql .=
", description";
346 $sql .=
", model_pdf";
347 $sql .=
", fk_projet";
348 $sql .=
", fk_contrat";
349 $sql .=
", fk_statut";
350 $sql .=
", signed_status";
351 $sql .=
", note_private";
352 $sql .=
", note_public";
355 $sql .= ((int) $this->socid);
356 $sql .=
", '".$this->db->idate($now).
"'";
357 $sql .=
", '".$this->db->escape($this->ref).
"'";
358 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
359 $sql .=
", ".((int) $this->entity);
360 $sql .=
", ".((int) $user->id);
361 $sql .=
", ".((int) $user->id);
362 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
363 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
364 $sql .=
", ".((int) $this->fk_project > 0 ? ((
int) $this->fk_project) : 0);
365 $sql .=
", ".((int) $this->fk_contrat > 0 ? ((
int) $this->fk_contrat) : 0);
366 $sql .=
", ".((int) $this->
status);
367 $sql .=
", ".((int) $this->signed_status);
368 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
369 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
372 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
373 $result = $this->db->query($sql);
375 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
378 $this->ref =
'(PROV'.$this->id.
')';
379 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
381 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
382 $resql = $this->db->query($sql);
396 if (!$error && $this->origin && $this->origin_id) {
404 if (!$error && !$notrigger) {
406 $result = $this->call_trigger(
'FICHINTER_CREATE', $user);
417 $this->db->rollback();
418 $this->error = implode(
',', $this->errors);
419 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
423 $this->error = $this->db->error();
424 $this->db->rollback();
436 public function update($user, $notrigger = 0)
440 if (!is_numeric($this->duration)) {
443 if (!
dol_strlen((
string) $this->fk_project)) {
444 $this->fk_project = 0;
446 if (!empty($this->ref_client)) {
447 $this->ref_client = trim($this->ref_client);
454 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
455 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
456 $sql .=
", duree = ".((int) $this->duration);
457 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
458 if ((
int) $this->fk_project > 0) {
459 $sql .=
", fk_projet = ".((int) $this->fk_project);
461 if (isset($this->datec)) {
462 $sql .=
", datec = ".($this->datec ?
"'".$this->db->idate($this->datec).
"'" :
"null");
464 if (isset($this->datev)) {
465 $sql .=
", date_valid = ".($this->datev ?
"'".$this->db->idate($this->datev).
"'" :
"null");
467 if (isset($this->datet)) {
468 $sql .=
", datet = ".($this->datet ?
"'".$this->db->idate($this->datet).
"'" :
"null");
470 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
471 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
472 $sql .=
", fk_user_modif = ".((int) $user->id);
473 $sql .=
" WHERE rowid = ".((int) $this->
id);
475 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
476 if ($this->db->query($sql)) {
482 if (!$error && !$notrigger) {
484 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
487 $this->db->rollback();
496 $this->error = $this->db->error();
497 $this->db->rollback();
510 public function fetch($rowid, $ref =
'', $ref_ext =
'')
512 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
513 $sql .=
" f.datec, f.dateo, f.datee, f.datet,";
514 $sql .=
" f.date_valid as datev,";
515 $sql .=
" f.tms as datem,";
516 $sql .=
" f.fk_user_author, f.fk_user_modif,";
517 $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";
518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
519 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
521 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
522 } elseif ($ref_ext) {
523 $sql .=
" AND f.ref_ext = '".$this->db->escape($ref_ext).
"'";
525 $sql .=
" AND f.rowid = ".((int) $rowid);
528 $resql = $this->db->query($sql);
530 if ($this->db->num_rows($resql)) {
531 $obj = $this->db->fetch_object($resql);
533 $this->
id = $obj->rowid;
534 $this->
ref = $obj->ref;
535 $this->ref_client = $obj->ref_client;
537 $this->socid = $obj->fk_soc;
538 $this->
status = $obj->status;
539 $this->statut = $obj->status;
540 $this->signed_status = $obj->signed_status;
541 $this->duration = $obj->duree;
542 $this->datec = $this->db->jdate($obj->datec);
543 $this->dateo = $this->db->jdate($obj->dateo);
544 $this->datee = $this->db->jdate($obj->datee);
545 $this->datet = $this->db->jdate($obj->datet);
546 $this->datev = $this->db->jdate($obj->datev);
547 $this->datem = $this->db->jdate($obj->datem);
548 $this->fk_project = $obj->fk_project;
549 $this->note_public = $obj->note_public;
550 $this->note_private = $obj->note_private;
551 $this->model_pdf = $obj->model_pdf;
552 $this->fk_contrat = $obj->fk_contrat;
553 $this->entity = $obj->entity;
555 $this->user_author_id = $this->user_creation_id = $obj->fk_user_author;
556 $this->user_modification_id = $obj->fk_user_modif;
558 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
560 $this->last_main_doc = $obj->last_main_doc;
572 $this->db->free($resql);
578 $this->error = $this->db->lasterror();
594 if ($this->
status <= self::STATUS_DRAFT) {
598 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
604 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
605 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
606 $sql .=
" WHERE rowid = ".((int) $this->
id);
608 $resql = $this->db->query($sql);
611 $result = $this->call_trigger(
'FICHINTER_UNVALIDATE', $user);
622 $this->db->rollback();
626 $this->db->rollback();
627 $this->error = $this->db->lasterror();
642 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
646 if ($this->
status != self::STATUS_VALIDATED) {
652 if ((preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
653 if (empty($this->thirdparty)) {
662 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
663 $sql .=
" SET fk_statut = 1";
664 $sql .=
", ref = '".$this->db->escape($num).
"'";
665 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
666 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
667 $sql .=
" WHERE rowid = ".((int) $this->
id);
668 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
670 $sql .=
" AND fk_statut = 0";
672 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
673 $resql = $this->db->query($sql);
679 if (!$error && !$notrigger) {
681 $result = $this->call_trigger(
'FICHINTER_VALIDATE', $user);
689 $this->oldref = $this->ref;
692 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
693 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
696 $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).
"'";
697 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
698 $resql = $this->db->query($sql);
701 $this->error = $this->db->lasterror();
703 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
704 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
705 $resql = $this->db->query($sql);
708 $this->error = $this->db->lasterror();
714 $dirsource =
$conf->ficheinter->dir_output.
'/'.$oldref;
715 $dirdest =
$conf->ficheinter->dir_output.
'/'.$newref;
716 if (!$error && file_exists($dirsource)) {
717 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
719 if (@rename($dirsource, $dirdest)) {
722 $listoffiles =
dol_dir_list(
$conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
723 foreach ($listoffiles as $fileentry) {
724 $dirsource = $fileentry[
'name'];
725 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
726 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
727 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
728 @rename($dirsource, $dirdest);
740 $this->date_validation = $now;
744 $this->db->rollback();
745 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
766 if ($this->
status == self::STATUS_CLOSED) {
773 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
774 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
775 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
776 $sql .=
" fk_user_modif = " . ((int) $user->id);
777 $sql .=
" WHERE rowid = " . ((int) $this->
id);
779 $sql .=
" AND entity IN (".getEntity(
'intervention').
")";
781 if ($this->db->query($sql)) {
784 $result = $this->call_trigger(
'FICHINTER_CLOSE', $user);
797 $this->db->rollback();
801 $this->error = $this->db->lasterror();
802 $this->db->rollback();
817 $this->author =
new User($this->db);
818 $this->author->fetch($this->user_creation_id);
820 $thm = $this->author->thm;
822 foreach ($this->lines as $line) {
823 $amount += ($line->duration / 60 / 60 * (float) $thm);
841 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
845 $outputlangs->load(
"interventions");
850 if (!empty($this->model_pdf)) {
851 $modele = $this->model_pdf;
857 $modelpath =
"core/modules/fichinter/doc/";
859 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
870 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
886 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
887 $langs->load(
"interventions");
888 $langs->load(
"propal");
892 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
896 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
900 $statuscode =
'status'.$status;
901 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
902 $statuscode =
'status6';
906 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
907 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
909 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
922 $langs->load(
'interventions');
925 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
926 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
927 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
942 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
944 global
$conf, $langs, $hookmanager;
946 if (!empty(
$conf->dol_no_mouse_hover)) {
953 'objecttype' => $this->element,
956 $classfortooltip =
'classfortooltip';
959 $classfortooltip =
'classforajaxtooltip';
960 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
966 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
968 if ($option !==
'nolink') {
970 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
971 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
972 $add_save_lastsearch_values = 1;
974 if ($add_save_lastsearch_values) {
975 $url .=
'&save_lastsearch_values=1';
980 if (empty($notooltip)) {
982 $label = $langs->trans(
"ShowIntervention");
983 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
985 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
986 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
988 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
991 if ($option ==
'nolink') {
992 $linkstart =
'<span';
994 $linkstart =
'<a href="'.$url.
'"';
996 $linkstart .= $linkclose.
'>';
997 if ($option ==
'nolink') {
998 $linkend =
'</span>';
1003 $result .= $linkstart;
1005 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1008 if ($withpicto != 2) {
1009 $result .= $this->ref;
1012 $result .= $linkend;
1015 $hookmanager->initHooks(array(
'interventiondao'));
1016 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1017 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1019 $result = $hookmanager->resPrint;
1021 $result .= $hookmanager->resPrint;
1037 global
$conf, $db, $langs;
1038 $langs->load(
"interventions");
1047 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1049 foreach ($dirmodels as $reldir) {
1053 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1061 $obj =
new $classname();
1062 '@phan-var-force ModeleNumRefFicheinter $obj';
1064 $numref = $obj->getNextValue($soc, $this);
1066 if ($numref !=
"") {
1073 $langs->load(
"errors");
1074 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1087 $sql =
"SELECT f.rowid,";
1088 $sql .=
" f.datec,";
1089 $sql .=
" f.tms as date_modification,";
1090 $sql .=
" f.date_valid as datev,";
1091 $sql .=
" f.fk_user_author,";
1092 $sql .=
" f.fk_user_modif as fk_user_modification,";
1093 $sql .=
" f.fk_user_valid";
1094 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1095 $sql .=
" WHERE f.rowid = ".((int) $id);
1097 $resql = $this->db->query($sql);
1099 if ($this->db->num_rows($resql)) {
1100 $obj = $this->db->fetch_object($resql);
1102 $this->
id = $obj->rowid;
1104 $this->date_creation = $this->db->jdate($obj->datec);
1105 $this->date_modification = $this->db->jdate($obj->date_modification);
1106 $this->date_validation = $this->db->jdate($obj->datev);
1108 $this->user_creation_id = $obj->fk_user_author;
1109 $this->user_validation_id = $obj->fk_user_valid;
1110 $this->user_modification_id = $obj->fk_user_modification;
1112 $this->db->free($resql);
1125 public function delete(
User $user, $notrigger = 0)
1127 global
$conf, $langs;
1128 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1136 $result = $this->call_trigger(
'FICHINTER_DELETE', $user);
1139 $this->db->rollback();
1155 $this->error =
'ErrorFailToDeleteLinkedContact';
1161 $main = MAIN_DB_PREFIX.
'fichinterdet';
1162 $ef = $main.
"_extrafields";
1163 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1165 $resql = $this->db->query($sql);
1172 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1173 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1175 $resql = $this->db->query($sql);
1191 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1192 $sql .=
" WHERE rowid = ".((int) $this->
id);
1195 $resql = $this->db->query($sql);
1208 if ($conf->ficheinter->dir_output && !empty($fichinterref)) {
1209 $dir =
$conf->ficheinter->dir_output.
"/".$fichinterref;
1210 $file =
$conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1211 if (file_exists($file)) {
1215 $langs->load(
"errors");
1216 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1220 if (file_exists($dir)) {
1222 $langs->load(
"errors");
1223 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1231 $this->db->commit();
1234 $this->db->rollback();
1250 if ($user->hasRight(
'ficheinter',
'creer')) {
1251 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1252 $sql .=
" SET datei = '".$this->db->idate($delivery_date_receipt).
"'";
1253 $sql .=
" WHERE rowid = ".((int) $this->
id);
1254 $sql .=
" AND fk_statut = 0";
1256 if ($this->db->query($sql)) {
1257 $this->date_delivery = $delivery_date_receipt;
1258 $this->delivery_date_receipt = $delivery_date_receipt;
1261 $this->error = $this->db->error();
1262 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1281 if ($user->hasRight(
'ficheinter',
'creer')) {
1282 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1283 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1284 $sql .=
" fk_user_modif = ".((int) $user->id);
1285 $sql .=
" WHERE rowid = ".((int) $this->
id);
1287 if ($this->db->query($sql)) {
1291 $this->error = $this->db->error();
1292 dol_syslog(
"Fichinter::set_description Erreur SQL");
1312 if ($user->hasRight(
'ficheinter',
'creer')) {
1313 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1314 $sql .=
" SET fk_contrat = ".((int) $contractid);
1315 $sql .=
" WHERE rowid = ".((int) $this->
id);
1317 if ($this->db->query($sql)) {
1318 $this->fk_contrat = $contractid;
1321 $this->error = $this->db->error();
1342 global $hookmanager, $langs;
1343 $langs->load(
"errors");
1350 foreach ($this->lines as $line) {
1351 $line->fetch_optionals();
1355 $objFrom = clone $this;
1358 if (!empty($socid) && $socid != $this->socid) {
1359 $objsoc =
new Societe($this->db);
1361 if ($objsoc->fetch($socid) > 0) {
1362 $this->socid = $objsoc->id;
1365 $this->fk_project = 0;
1366 $this->fk_delivery_address = 0;
1378 $this->user_author_id = $user->id;
1379 $this->user_validation_id = 0;
1380 $this->date_creation =
'';
1381 $this->date_validation =
'';
1382 $this->signed_status = 0;
1384 $this->ref_client =
'';
1386 if (!$clone_notes) {
1387 $this->note_private =
'';
1388 $this->note_public =
'';
1392 $this->context[
'createfromclone'] =
'createfromclone';
1393 $result = $this->
create($user);
1400 foreach ($this->lines as $line) {
1401 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1405 if (is_object($hookmanager)) {
1406 $parameters = array(
'objFrom' => $objFrom);
1408 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1417 if ($clone_contacts) {
1418 foreach (array(
'internal',
'external') as $source) {
1419 $tab = $objFrom->liste_contact(-1, $source);
1420 if (is_array($tab) && count($tab) > 0) {
1421 foreach ($tab as $contacttoadd) {
1423 $contacttoadd[
'id'],
1424 $contacttoadd[
'code'],
1425 $contacttoadd[
'source']
1427 if ($this->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1428 $this->error .= $langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType");
1430 } elseif ($retAddContact < 0) {
1434 } elseif ($tab < 0) {
1435 $this->error .= $objFrom->error;
1441 unset($this->context[
'createfromclone']);
1445 $this->db->commit();
1448 $this->db->rollback();
1468 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [], $type = 0, $rang = -1, $special_code = 0)
1470 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration, $type, $rang, $special_code");
1472 if ($this->
status == self::STATUS_DRAFT) {
1478 $line->fk_fichinter = $fichinterid;
1479 $line->desc = $desc;
1480 $line->date = $date_intervention;
1481 $line->datei = $date_intervention;
1482 $line->duration = $duration;
1483 $line->product_type = $type;
1484 $line->rang = $rang;
1485 $line->special_code = $special_code;
1488 if (is_array($array_options) && count($array_options) > 0) {
1489 $line->array_options = $array_options;
1492 $result = $line->insert($user);
1495 $this->db->commit();
1498 $this->error = $this->db->error();
1499 $this->db->rollback();
1523 $this->
ref =
'SPECIMEN';
1524 $this->ref_client =
'SPECIMEN CLIENT';
1525 $this->specimen = 1;
1527 $this->datec = $now;
1528 $this->note_private =
'Private note';
1529 $this->note_public =
'SPECIMEN';
1530 $this->duration = 0;
1531 $this->user_creation_id = 1;
1534 while ($xnbp < $nbp) {
1536 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1537 $line->date = ($now - 3600 * (1 + $xnbp));
1538 $line->datei = ($now - 3600 * (1 + $xnbp));
1539 $line->duration = 600;
1540 $line->fk_fichinter = 0;
1541 $this->lines[$xnbp] = $line;
1544 $this->duration += $line->duration;
1559 $this->lines = array();
1561 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang, extraparams";
1562 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1563 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1564 $sql .=
" ORDER BY rang ASC, date ASC";
1566 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1568 $resql = $this->db->query($sql);
1570 $num = $this->db->num_rows($resql);
1573 $objp = $this->db->fetch_object($resql);
1576 $line->id = $objp->rowid;
1577 $line->fk_fichinter = $objp->fk_fichinter;
1578 $line->desc = $objp->description;
1579 $line->duration = $objp->duree;
1581 $line->qty = round($objp->duree / 3600, 2);
1582 $line->date = $this->db->jdate($objp->date);
1583 $line->datei = $this->db->jdate($objp->date);
1584 $line->rang = $objp->rang;
1585 $line->product_type = 1;
1586 $line->fetch_optionals();
1588 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1590 $this->lines[$i] = $line;
1593 $this->db->free($resql);
1597 $this->error = $this->db->error();
1631 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1632 return parent::setCategoriesCommon($categories, Categorie::TYPE_FICHINTER);
1646 if ($user->hasRight(
'ficheinter',
'creer')) {
1653 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1654 $sql .=
" WHERE rowid = ".((int) $this->
id);
1656 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1657 $resql = $this->db->query($sql);
1659 $this->errors[] = $this->db->error();
1664 $this->ref_client = $ref_client;
1667 if (!$notrigger && empty($error)) {
1669 $result = $this->call_trigger(
'FICHINTER_MODIFY', $user);
1677 $this->db->commit();
1680 foreach ($this->errors as $errmsg) {
1681 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1682 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1684 $this->db->rollback();
1699 public function getKanbanView($option =
'', $arraydata =
null)
1703 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1705 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1706 $return .=
'<div class="info-box info-box-sm">';
1707 $return .=
'<span class="info-box-icon bg-infobox-action">';
1709 $return .=
'</span>';
1710 $return .=
'<div class="info-box-content">';
1711 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl() .
'</span>';
1712 if ($selected >= 0) {
1713 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1715 if (!empty($arraydata[
'thirdparty'])) {
1716 $tmpthirdparty = $arraydata[
'thirdparty'];
1717 '@phan-var-force Societe $tmpthirdparty';
1719 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1721 if (!empty($this->duration)) {
1722 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1724 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1725 $return .=
'</div>';
1726 $return .=
'</div>';
1727 $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.
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.
setCategories($categories)
Sets object to given categories.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
set_date_delivery($user, $delivery_date_receipt)
Defines a delivery date of the receipt of intervention.
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.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[], $type=0, $rang=-1, $special_code=0)
Adding a line of intervention into data base.
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.
dol_now($mode='gmt')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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($srcobject, $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...
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php