32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
41 public $fields = array(
42 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
43 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
44 '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),
45 'fk_contrat' => array(
'type' =>
'integer',
'label' =>
'Fk contrat',
'enabled' =>
'$conf->contrat->enabled',
'visible' => -1,
'position' => 25),
46 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
47 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
48 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
49 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
50 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
51 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
52 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
53 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
54 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 65),
55 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
56 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
57 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
58 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
59 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
60 'duree' => array(
'type' =>
'double',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
61 'signed_status' => array(
'type' =>
'smallint(6)',
'label' =>
'SignedStatus',
'enabled' => 1,
'visible' => -1,
'position' => 101,
'arrayofkeyval' => array(0 =>
'NoSignature', 1 =>
'SignedSender', 2 =>
'SignedReceiver', 9 =>
'SignedAll')),
62 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
63 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
64 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
65 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 120),
66 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
67 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
68 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
69 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Fk statut',
'enabled' => 1,
'visible' => -1,
'position' => 500),
75 public $element =
'fichinter';
80 public $table_element =
'fichinter';
85 public $fk_element =
'fk_fichinter';
90 public $table_element_line =
'fichinterdet';
95 public $picto =
'intervention';
142 public $signed_status = 0;
152 public $fk_contrat = 0;
157 public $fk_project = 0;
168 public $extraparams = array();
173 public $lines = array();
221 public $date_delivery;
227 public $user_author_id;
252 $sql =
"SELECT count(fi.rowid) as nb";
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
254 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
255 if (!$user->hasRight(
'societe',
'client',
'voir')) {
256 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
257 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
260 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
262 $resql = $this->db->query($sql);
264 while ($obj = $this->db->fetch_object($resql)) {
265 $this->nb[
"interventions"] = $obj->nb;
267 $this->db->free($resql);
271 $this->error = $this->db->error();
283 public function create($user, $notrigger = 0)
285 global $conf, $langs;
292 if (!empty($this->ref)) {
295 $this->error =
'ErrorRefAlreadyExists';
296 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
297 $this->db->rollback();
301 if (!is_numeric($this->duration)) {
304 if (isset($this->ref_client)) {
305 $this->ref_client = trim($this->ref_client);
308 if ($this->socid <= 0) {
309 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
310 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
315 $result = $soc->fetch($this->socid);
321 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
325 $sql .=
", ref_client";
327 $sql .=
", fk_user_author";
328 $sql .=
", fk_user_modif";
329 $sql .=
", description";
330 $sql .=
", model_pdf";
331 $sql .=
", fk_projet";
332 $sql .=
", fk_contrat";
333 $sql .=
", fk_statut";
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) $conf->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 .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
348 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
349 $sql .=
", ".((int) $this->
statut);
350 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
351 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
354 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
355 $result = $this->db->query($sql);
357 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
360 $this->ref =
'(PROV'.$this->id.
')';
361 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
363 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
364 $resql = $this->db->query($sql);
378 if (!$error && $this->origin && $this->origin_id) {
386 if (!$error && !$notrigger) {
388 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
399 $this->db->rollback();
400 $this->error = implode(
',', $this->errors);
401 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
405 $this->error = $this->db->error();
406 $this->db->rollback();
418 public function update($user, $notrigger = 0)
422 if (!is_numeric($this->duration)) {
426 $this->fk_project = 0;
428 if (isset($this->ref_client)) {
429 $this->ref_client = trim($this->ref_client);
436 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
437 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
438 $sql .=
", duree = ".((int) $this->duration);
439 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
440 $sql .=
", fk_projet = ".((int) $this->fk_project);
441 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
442 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
443 $sql .=
", fk_user_modif = ".((int) $user->id);
444 $sql .=
" WHERE rowid = ".((int) $this->
id);
446 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
447 if ($this->db->query($sql)) {
455 if (!$error && !$notrigger) {
457 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
460 $this->db->rollback();
469 $this->error = $this->db->error();
470 $this->db->rollback();
482 public function fetch($rowid, $ref =
'')
484 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status,";
485 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
486 $sql .=
" f.date_valid as datev,";
487 $sql .=
" f.tms as datem,";
488 $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";
489 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
491 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
492 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
494 $sql .=
" WHERE f.rowid = ".((int) $rowid);
497 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
498 $resql = $this->db->query($sql);
500 if ($this->db->num_rows($resql)) {
501 $obj = $this->db->fetch_object($resql);
503 $this->
id = $obj->rowid;
504 $this->
ref = $obj->ref;
505 $this->ref_client = $obj->ref_client;
507 $this->socid = $obj->fk_soc;
508 $this->
status = $obj->status;
509 $this->
statut = $obj->status;
510 $this->duration = $obj->duree;
511 $this->datec = $this->db->jdate($obj->datec);
512 $this->dateo = $this->db->jdate($obj->dateo);
513 $this->datee = $this->db->jdate($obj->datee);
514 $this->datet = $this->db->jdate($obj->datet);
515 $this->datev = $this->db->jdate($obj->datev);
516 $this->datem = $this->db->jdate($obj->datem);
517 $this->fk_project = $obj->fk_project;
518 $this->note_public = $obj->note_public;
519 $this->note_private = $obj->note_private;
520 $this->model_pdf = $obj->model_pdf;
521 $this->fk_contrat = $obj->fk_contrat;
522 $this->entity = $obj->entity;
524 $this->user_creation_id = $obj->fk_user_author;
526 $this->extraparams = (array) json_decode($obj->extraparams,
true);
528 $this->last_main_doc = $obj->last_main_doc;
540 $this->db->free($resql);
546 $this->error = $this->db->lasterror();
562 if ($this->
statut <= self::STATUS_DRAFT) {
566 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
572 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
573 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
574 $sql .=
" WHERE rowid = ".((int) $this->
id);
576 $resql = $this->db->query($sql);
580 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
591 $this->db->rollback();
595 $this->db->rollback();
596 $this->error = $this->db->lasterror();
611 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
615 if ($this->
status != self::STATUS_VALIDATED) {
621 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
628 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
629 $sql .=
" SET fk_statut = 1";
630 $sql .=
", ref = '".$this->db->escape($num).
"'";
631 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
632 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
633 $sql .=
" WHERE rowid = ".((int) $this->
id);
634 $sql .=
" AND entity = ".((int) $this->entity);
636 $sql .=
" AND fk_statut = 0";
638 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
639 $resql = $this->db->query($sql);
645 if (!$error && !$notrigger) {
647 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
655 $this->oldref = $this->ref;
658 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
659 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
662 $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).
"'";
663 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
664 $resql = $this->db->query($sql);
667 $this->error = $this->db->lasterror();
669 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
670 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
671 $resql = $this->db->query($sql);
674 $this->error = $this->db->lasterror();
680 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
681 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
682 if (!$error && file_exists($dirsource)) {
683 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
685 if (@rename($dirsource, $dirdest)) {
688 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
689 foreach ($listoffiles as $fileentry) {
690 $dirsource = $fileentry[
'name'];
691 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
692 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
693 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
694 @rename($dirsource, $dirdest);
706 $this->date_validation = $now;
710 $this->db->rollback();
711 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
732 if ($this->
statut == self::STATUS_CLOSED) {
739 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
740 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
741 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
742 $sql .=
" fk_user_modif = " . ((int) $user->id);
743 $sql .=
" WHERE rowid = " . ((int) $this->
id);
745 $sql .=
" AND entity = " . ((int) $conf->entity);
747 if ($this->db->query($sql)) {
750 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
762 $this->db->rollback();
766 $this->error = $this->db->lasterror();
767 $this->db->rollback();
782 $this->author =
new User($this->db);
783 $this->author->fetch($this->user_creation_id);
785 $thm = $this->author->thm;
787 foreach ($this->lines as $line) {
788 $amount += ($line->duration / 60 / 60 * (float) $thm);
806 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
810 $outputlangs->load(
"interventions");
815 if (!empty($this->model_pdf)) {
816 $modele = $this->model_pdf;
822 $modelpath =
"core/modules/fichinter/doc/";
824 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
850 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
852 $langs->load(
"fichinter");
856 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
860 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
864 $statuscode =
'status'.$status;
865 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
866 $statuscode =
'status6';
868 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statuscode, $mode);
880 global $conf, $langs;
882 $langs->load(
'fichinter');
885 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
886 if (isset($this->
status)) {
887 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
889 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
904 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
906 global $conf, $langs, $hookmanager;
908 if (!empty($conf->dol_no_mouse_hover)) {
915 'objecttype' => $this->element,
918 $classfortooltip =
'classfortooltip';
921 $classfortooltip =
'classforajaxtooltip';
922 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
928 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
930 if ($option !==
'nolink') {
932 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
933 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
934 $add_save_lastsearch_values = 1;
936 if ($add_save_lastsearch_values) {
937 $url .=
'&save_lastsearch_values=1';
942 if (empty($notooltip)) {
944 $label = $langs->trans(
"ShowIntervention");
945 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
947 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
948 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
950 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
953 if ($option ==
'nolink' || empty($url)) {
954 $linkstart =
'<span';
956 $linkstart =
'<a href="'.$url.
'"';
958 $linkstart .= $linkclose.
'>';
959 if ($option ==
'nolink' || empty($url)) {
960 $linkend =
'</span>';
965 $result .= $linkstart;
967 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
970 if ($withpicto != 2) {
971 $result .= $this->ref;
977 $hookmanager->initHooks(array(
'interventiondao'));
978 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
979 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
981 $result = $hookmanager->resPrint;
983 $result .= $hookmanager->resPrint;
999 global $conf, $db, $langs;
1000 $langs->load(
"interventions");
1009 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1011 foreach ($dirmodels as $reldir) {
1015 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1018 if ($mybool ===
false) {
1023 $obj =
new $classname();
1025 $numref = $obj->getNextValue($soc, $this);
1027 if ($numref !=
"") {
1034 $langs->load(
"errors");
1035 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1048 $sql =
"SELECT f.rowid,";
1049 $sql .=
" f.datec,";
1050 $sql .=
" f.tms as date_modification,";
1051 $sql .=
" f.date_valid as datev,";
1052 $sql .=
" f.fk_user_author,";
1053 $sql .=
" f.fk_user_modif as fk_user_modification,";
1054 $sql .=
" f.fk_user_valid";
1055 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1056 $sql .=
" WHERE f.rowid = ".((int) $id);
1058 $resql = $this->db->query($sql);
1060 if ($this->db->num_rows($resql)) {
1061 $obj = $this->db->fetch_object($resql);
1063 $this->
id = $obj->rowid;
1065 $this->date_creation = $this->db->jdate($obj->datec);
1066 $this->date_modification = $this->db->jdate($obj->date_modification);
1067 $this->date_validation = $this->db->jdate($obj->datev);
1069 $this->user_creation_id = $obj->fk_user_author;
1070 $this->user_validation_id = $obj->fk_user_valid;
1071 $this->user_modification_id = $obj->fk_user_modification;
1073 $this->db->free($resql);
1086 public function delete(
User $user, $notrigger = 0)
1088 global $conf, $langs;
1089 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1095 if (!$error && !$notrigger) {
1097 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1100 $this->db->rollback();
1118 $this->error =
'ErrorFailToDeleteLinkedContact';
1124 $main = MAIN_DB_PREFIX.
'fichinterdet';
1125 $ef = $main.
"_extrafields";
1126 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".((int) $this->
id).
")";
1128 $resql = $this->db->query($sql);
1135 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1136 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1138 $resql = $this->db->query($sql);
1154 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1155 $sql .=
" WHERE rowid = ".((int) $this->
id);
1158 $resql = $this->db->query($sql);
1171 if ($conf->ficheinter->dir_output) {
1172 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1173 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1174 if (file_exists($file)) {
1178 $langs->load(
"errors");
1179 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1183 if (file_exists($dir)) {
1185 $langs->load(
"errors");
1186 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1194 $this->db->commit();
1197 $this->db->rollback();
1213 if ($user->hasRight(
'ficheinter',
'creer')) {
1214 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1215 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1216 $sql .=
" WHERE rowid = ".((int) $this->
id);
1217 $sql .=
" AND fk_statut = 0";
1219 if ($this->db->query($sql)) {
1220 $this->date_delivery = $date_delivery;
1223 $this->error = $this->db->error();
1224 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1243 if ($user->hasRight(
'ficheinter',
'creer')) {
1244 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1245 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1246 $sql .=
" fk_user_modif = ".$user->id;
1247 $sql .=
" WHERE rowid = ".((int) $this->
id);
1249 if ($this->db->query($sql)) {
1253 $this->error = $this->db->error();
1254 dol_syslog(
"Fichinter::set_description Erreur SQL");
1274 if ($user->hasRight(
'ficheinter',
'creer')) {
1275 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1276 $sql .=
" SET fk_contrat = ".((int) $contractid);
1277 $sql .=
" WHERE rowid = ".((int) $this->
id);
1279 if ($this->db->query($sql)) {
1280 $this->fk_contrat = $contractid;
1283 $this->error = $this->db->error();
1302 global $hookmanager;
1309 foreach ($this->lines as $line) {
1310 $line->fetch_optionals();
1314 $objFrom = clone $this;
1317 if (!empty($socid) && $socid != $this->socid) {
1318 $objsoc =
new Societe($this->db);
1320 if ($objsoc->fetch($socid) > 0) {
1321 $this->socid = $objsoc->id;
1324 $this->fk_project = 0;
1325 $this->fk_delivery_address = 0;
1337 $this->user_author_id = $user->id;
1338 $this->user_validation_id = 0;
1339 $this->date_creation =
'';
1340 $this->date_validation =
'';
1342 $this->ref_client =
'';
1345 $this->context[
'createfromclone'] =
'createfromclone';
1346 $result = $this->
create($user);
1353 foreach ($this->lines as $line) {
1354 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1358 if (is_object($hookmanager)) {
1359 $parameters = array(
'objFrom' => $objFrom);
1361 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1369 unset($this->context[
'createfromclone']);
1373 $this->db->commit();
1376 $this->db->rollback();
1393 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1395 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1397 if ($this->
status == self::STATUS_DRAFT) {
1403 $line->fk_fichinter = $fichinterid;
1404 $line->desc = $desc;
1405 $line->date = $date_intervention;
1406 $line->datei = $date_intervention;
1407 $line->duration = $duration;
1409 if (is_array($array_options) && count($array_options) > 0) {
1410 $line->array_options = $array_options;
1413 $result = $line->insert($user);
1416 $this->db->commit();
1419 $this->error = $this->db->error();
1420 $this->db->rollback();
1444 $this->
ref =
'SPECIMEN';
1445 $this->ref_client =
'SPECIMEN CLIENT';
1446 $this->specimen = 1;
1448 $this->datec = $now;
1449 $this->note_private =
'Private note';
1450 $this->note_public =
'SPECIMEN';
1451 $this->duration = 0;
1454 while ($xnbp < $nbp) {
1456 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1457 $line->date = ($now - 3600 * (1 + $xnbp));
1458 $line->datei = ($now - 3600 * (1 + $xnbp));
1459 $line->duration = 600;
1460 $line->fk_fichinter = 0;
1461 $this->lines[$xnbp] = $line;
1464 $this->duration += $line->duration;
1479 $this->lines = array();
1481 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1482 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1483 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1484 $sql .=
" ORDER BY rang ASC, date ASC";
1486 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1488 $resql = $this->db->query($sql);
1490 $num = $this->db->num_rows($resql);
1493 $objp = $this->db->fetch_object($resql);
1496 $line->id = $objp->rowid;
1497 $line->fk_fichinter = $objp->fk_fichinter;
1498 $line->desc = $objp->description;
1499 $line->duration = $objp->duree;
1501 $line->qty = round($objp->duree / 3600, 2);
1502 $line->date = $this->db->jdate($objp->date);
1503 $line->datei = $this->db->jdate($objp->date);
1504 $line->rang = $objp->rang;
1505 $line->product_type = 1;
1506 $line->fetch_optionals();
1508 $this->lines[$i] = $line;
1511 $this->db->free($resql);
1515 $this->error = $this->db->error();
1548 if ($user->hasRight(
'ficheinter',
'creer')) {
1555 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1556 $sql .=
" WHERE rowid = ".((int) $this->
id);
1558 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1559 $resql = $this->db->query($sql);
1561 $this->errors[] = $this->db->error();
1566 $this->ref_client = $ref_client;
1569 if (!$notrigger && empty($error)) {
1571 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1579 $this->db->commit();
1582 foreach ($this->errors as $errmsg) {
1583 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1584 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1586 $this->db->rollback();
1605 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1607 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1608 $return .=
'<div class="info-box info-box-sm">';
1609 $return .=
'<span class="info-box-icon bg-infobox-action">';
1611 $return .=
'</span>';
1612 $return .=
'<div class="info-box-content">';
1613 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1614 if ($selected >= 0) {
1615 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1617 if (!empty($arraydata[
'thirdparty'])) {
1618 $tmpthirdparty = $arraydata[
'thirdparty'];
1619 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1621 if (property_exists($this,
'duration')) {
1622 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1624 if (method_exists($this,
'getLibStatut')) {
1625 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1627 $return .=
'</div>';
1628 $return .=
'</div>';
1629 $return .=
'</div>';
1667 public $fk_fichinter;
1694 public $element =
'fichinterdet';
1699 public $table_element =
'fichinterdet';
1704 public $fk_element =
'fk_fichinter';
1726 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1728 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date';
1729 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1730 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
1732 $resql = $this->db->query($sql);
1734 $objp = $this->db->fetch_object($resql);
1735 $this->
rowid = $objp->rowid;
1736 $this->
id = $objp->rowid;
1737 $this->fk_fichinter = $objp->fk_fichinter;
1738 $this->date = $this->db->jdate($objp->date);
1739 $this->datei = $this->db->jdate($objp->date);
1740 $this->desc = $objp->description;
1741 $this->duration = $objp->duree;
1742 $this->rang = $objp->rang;
1744 $this->db->free($resql);
1750 $this->error = $this->db->error().
' sql='.$sql;
1762 public function insert($user, $notrigger = 0)
1766 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1768 if (empty($this->date) && !empty($this->datei)) {
1769 $this->date = $this->datei;
1774 $rangToUse = $this->rang;
1775 if ($rangToUse == -1) {
1777 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1778 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
1779 $resql = $this->db->query($sql);
1781 $obj = $this->db->fetch_object($resql);
1782 $rangToUse = $obj->max + 1;
1785 $this->db->rollback();
1791 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1792 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1793 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
1794 $sql .=
" '".$this->db->escape($this->desc).
"',";
1795 $sql .=
" '".$this->db->idate($this->date).
"',";
1796 $sql .=
" ".((int) $this->duration).
",";
1797 $sql .=
' '.((int) $rangToUse);
1800 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1801 $resql = $this->db->query($sql);
1803 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1804 $this->
rowid = $this->id;
1817 $this->rang = $rangToUse;
1821 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1830 $this->db->commit();
1833 $this->db->rollback();
1837 $this->error = $this->db->error().
" sql=".$sql;
1838 $this->db->rollback();
1851 public function update($user, $notrigger = 0)
1855 if (empty($this->date) && !empty($this->datei)) {
1856 $this->date = $this->datei;
1862 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1863 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
1864 $sql .=
" date = '".$this->db->idate($this->date).
"',";
1865 $sql .=
" duree = ".((int) $this->duration).
",";
1866 $sql .=
" rang = ".((int) $this->rang);
1867 $sql .=
" WHERE rowid = ".((int) $this->
id);
1869 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1870 $resql = $this->db->query($sql);
1883 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
1892 $this->db->commit();
1895 $this->error = $this->db->lasterror();
1896 $this->db->rollback();
1900 $this->error = $this->db->lasterror();
1901 $this->db->rollback();
1919 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1920 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1921 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
1923 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1924 $resql = $this->db->query($sql);
1926 $obj = $this->db->fetch_object($resql);
1927 $total_duration = 0;
1928 if (!empty($obj->total_duration)) {
1929 $total_duration = $obj->total_duration;
1932 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1933 $sql .=
" SET duree = ".((int) $total_duration);
1934 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
1935 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
1936 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
1938 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1939 $resql = $this->db->query($sql);
1941 $this->db->commit();
1944 $this->error = $this->db->error();
1945 $this->db->rollback();
1949 $this->error = $this->db->error();
1950 $this->db->rollback();
1966 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1973 $this->db->rollback();
1977 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
1978 $resql = $this->db->query($sql);
1985 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1988 $this->db->rollback();
1994 $this->db->commit();
1997 $this->db->rollback();
2001 $this->error = $this->db->error().
" sql=".$sql;
2002 $this->db->rollback();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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.
setSignedStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a signed status.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage interventions.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
const STATUS_SIGNED_RECEIVER
Signed by receiver.
const STATUS_SIGNED_ALL
Signed by all.
setClose($user, $notrigger=0)
Close intervention.
set_date_delivery($user, $date_delivery)
Defines a delivery date of intervention.
const STATUS_DRAFT
Draft status.
create($user, $notrigger=0)
Create an intervention into data base.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
setSignedStatus(User $user, int $status=0, int $notrigger=0, $triggercode='')
Set signed status.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
const STATUS_CLOSED
Closed.
setDraft($user)
Set status to draft.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
getAmount()
Returns amount based on user thm.
fetch($rowid, $ref='')
Fetch a intervention.
setRefClient($user, $ref_client, $notrigger=0)
Set customer reference number.
set_contrat($user, $contractid)
Link intervention to a contract.
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
loadStateBoard()
Load indicators into this->nb for board.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clicable name (with picto eventually)
const STATUS_SIGNED_SENDER
Signed by sender.
__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.
const STATUS_NO_SIGNATURE
No signature.
Class to manage intervention lines.
deleteLine($user, $notrigger=0)
Delete a intervention line.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert the line into database.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid