32require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinterligne.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/commonsignedobject.class.php';
43 use CommonSignedObject;
45 public $fields = array(
46 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
47 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 15),
48 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Fk projet',
'enabled' =>
'isModEnabled("project")',
'visible' => -1,
'position' => 20),
49 'fk_contrat' => array(
'type' =>
'integer',
'label' =>
'Fk contrat',
'enabled' =>
'$conf->contrat->enabled',
'visible' => -1,
'position' => 25),
50 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 30),
51 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
52 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 36),
53 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 40,
'index' => 1),
54 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 45),
55 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -1,
'position' => 50),
56 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 55),
57 'datei' => array(
'type' =>
'date',
'label' =>
'Datei',
'enabled' => 1,
'visible' => -1,
'position' => 60),
58 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fk user author',
'enabled' => 1,
'visible' => -1,
'position' => 65),
59 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 70),
60 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 75),
61 'dateo' => array(
'type' =>
'date',
'label' =>
'Dateo',
'enabled' => 1,
'visible' => -1,
'position' => 85),
62 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 90),
63 'datet' => array(
'type' =>
'date',
'label' =>
'Datet',
'enabled' => 1,
'visible' => -1,
'position' => 95),
64 'duree' => array(
'type' =>
'integer',
'label' =>
'Duree',
'enabled' => 1,
'visible' => -1,
'position' => 100),
65 'signed_status' => array(
'type' =>
'smallint(6)',
'label' =>
'SignedStatus',
'enabled' => 1,
'visible' => -1,
'position' => 101,
'arrayofkeyval' => array(0 =>
'NoSignature', 1 =>
'SignedSender', 2 =>
'SignedReceiver', 3 =>
'SignedReceiverOnline', 9 =>
'SignedAll')),
66 'description' => array(
'type' =>
'html',
'label' =>
'Description',
'enabled' => 1,
'visible' => -1,
'position' => 105,
'showoncombobox' => 2),
67 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 110),
68 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 115),
69 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'Model pdf',
'enabled' => 1,
'visible' => 0,
'position' => 120),
70 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'Last main doc',
'enabled' => 1,
'visible' => -1,
'position' => 125),
71 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 130),
72 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 135),
73 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Fk statut',
'enabled' => 1,
'visible' => -1,
'position' => 500),
79 public $element =
'fichinter';
84 public $table_element =
'fichinter';
89 public $table_element_line =
'fichinterdet';
94 public $picto =
'intervention';
159 public $fk_contrat = 0;
164 public $fk_project = 0;
175 public $extraparams = array();
180 public $lines = array();
206 public $date_delivery;
212 public $user_author_id;
237 $sql =
"SELECT count(fi.rowid) as nb";
238 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
239 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
240 if (!$user->hasRight(
'societe',
'client',
'voir')) {
241 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
242 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
245 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
247 $resql = $this->db->query($sql);
249 while ($obj = $this->db->fetch_object($resql)) {
250 $this->nb[
"interventions"] = $obj->nb;
252 $this->db->free($resql);
256 $this->error = $this->db->error();
268 public function create($user, $notrigger = 0)
270 global
$conf, $langs;
277 if (!empty($this->ref)) {
280 $this->error =
'ErrorRefAlreadyExists';
281 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
282 $this->db->rollback();
286 if (!is_numeric($this->duration)) {
289 if (isset($this->ref_client)) {
290 $this->ref_client = trim($this->ref_client);
293 if ($this->socid <= 0) {
294 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
295 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
301 $result = $soc->fetch($this->socid);
307 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
311 $sql .=
", ref_client";
313 $sql .=
", fk_user_author";
314 $sql .=
", fk_user_modif";
315 $sql .=
", description";
316 $sql .=
", model_pdf";
317 $sql .=
", fk_projet";
318 $sql .=
", fk_contrat";
319 $sql .=
", fk_statut";
320 $sql .=
", signed_status";
321 $sql .=
", note_private";
322 $sql .=
", note_public";
325 $sql .= $this->socid;
326 $sql .=
", '".$this->db->idate($now).
"'";
327 $sql .=
", '".$this->db->escape($this->ref).
"'";
328 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
329 $sql .=
", ".((int) $this->entity);
330 $sql .=
", ".((int) $user->id);
331 $sql .=
", ".((int) $user->id);
332 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
333 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
334 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
335 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
336 $sql .=
", ".((int) $this->statut);
337 $sql .=
", ".($this->signed_status);
338 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
339 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
342 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
343 $result = $this->db->query($sql);
345 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
348 $this->ref =
'(PROV'.$this->id.
')';
349 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
351 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
352 $resql = $this->db->query($sql);
366 if (!$error && $this->origin && $this->origin_id) {
374 if (!$error && !$notrigger) {
376 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
387 $this->db->rollback();
388 $this->error = implode(
',', $this->errors);
389 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
393 $this->error = $this->db->error();
394 $this->db->rollback();
406 public function update($user, $notrigger = 0)
410 if (!is_numeric($this->duration)) {
413 if (!
dol_strlen((
string) $this->fk_project)) {
414 $this->fk_project = 0;
416 if (isset($this->ref_client)) {
417 $this->ref_client = trim($this->ref_client);
424 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
425 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
426 $sql .=
", duree = ".((int) $this->duration);
427 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
428 $sql .=
", fk_projet = ".((int) $this->fk_project);
429 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
430 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
431 $sql .=
", fk_user_modif = ".((int) $user->id);
432 $sql .=
" WHERE rowid = ".((int) $this->
id);
434 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
435 if ($this->db->query($sql)) {
443 if (!$error && !$notrigger) {
445 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
448 $this->db->rollback();
457 $this->error = $this->db->error();
458 $this->db->rollback();
470 public function fetch($rowid, $ref =
'')
472 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut as status, f.signed_status,";
473 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
474 $sql .=
" f.date_valid as datev,";
475 $sql .=
" f.tms as datem,";
476 $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";
477 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
479 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
480 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
482 $sql .=
" WHERE f.rowid = ".((int) $rowid);
485 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
486 $resql = $this->db->query($sql);
488 if ($this->db->num_rows($resql)) {
489 $obj = $this->db->fetch_object($resql);
491 $this->
id = $obj->rowid;
492 $this->
ref = $obj->ref;
493 $this->ref_client = $obj->ref_client;
495 $this->socid = $obj->fk_soc;
496 $this->
status = $obj->status;
497 $this->statut = $obj->status;
498 $this->signed_status = $obj->signed_status;
499 $this->duration = $obj->duree;
500 $this->datec = $this->db->jdate($obj->datec);
501 $this->dateo = $this->db->jdate($obj->dateo);
502 $this->datee = $this->db->jdate($obj->datee);
503 $this->datet = $this->db->jdate($obj->datet);
504 $this->datev = $this->db->jdate($obj->datev);
505 $this->datem = $this->db->jdate($obj->datem);
506 $this->fk_project = $obj->fk_project;
507 $this->note_public = $obj->note_public;
508 $this->note_private = $obj->note_private;
509 $this->model_pdf = $obj->model_pdf;
510 $this->fk_contrat = $obj->fk_contrat;
511 $this->entity = $obj->entity;
513 $this->user_creation_id = $obj->fk_user_author;
515 $this->extraparams = is_null($obj->extraparams) ? [] : (array) json_decode($obj->extraparams,
true);
517 $this->last_main_doc = $obj->last_main_doc;
529 $this->db->free($resql);
535 $this->error = $this->db->lasterror();
551 if ($this->statut <= self::STATUS_DRAFT) {
555 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
561 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
562 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
563 $sql .=
" WHERE rowid = ".((int) $this->
id);
565 $resql = $this->db->query($sql);
569 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
580 $this->db->rollback();
584 $this->db->rollback();
585 $this->error = $this->db->lasterror();
600 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
604 if ($this->
status != self::STATUS_VALIDATED) {
610 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
617 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
618 $sql .=
" SET fk_statut = 1";
619 $sql .=
", ref = '".$this->db->escape($num).
"'";
620 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
621 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
622 $sql .=
" WHERE rowid = ".((int) $this->
id);
623 $sql .=
" AND entity = ".((int) $this->entity);
625 $sql .=
" AND fk_statut = 0";
627 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
628 $resql = $this->db->query($sql);
634 if (!$error && !$notrigger) {
636 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
644 $this->oldref = $this->ref;
647 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
648 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
651 $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).
"'";
652 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".((int) $this->entity);
653 $resql = $this->db->query($sql);
656 $this->error = $this->db->lasterror();
658 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'ficheinter/".$this->db->escape($this->newref).
"'";
659 $sql .=
" WHERE filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
660 $resql = $this->db->query($sql);
663 $this->error = $this->db->lasterror();
669 $dirsource =
$conf->ficheinter->dir_output.
'/'.$oldref;
670 $dirdest =
$conf->ficheinter->dir_output.
'/'.$newref;
671 if (!$error && file_exists($dirsource)) {
672 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
674 if (@rename($dirsource, $dirdest)) {
677 $listoffiles =
dol_dir_list(
$conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
678 foreach ($listoffiles as $fileentry) {
679 $dirsource = $fileentry[
'name'];
680 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
681 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
682 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
683 @rename($dirsource, $dirdest);
695 $this->date_validation = $now;
699 $this->db->rollback();
700 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
721 if ($this->statut == self::STATUS_CLOSED) {
728 $sql =
'UPDATE ' . MAIN_DB_PREFIX . $this->table_element;
729 $sql .=
' SET fk_statut = ' . self::STATUS_CLOSED .
',';
730 $sql .=
" datet = '" . $this->db->idate($now) .
"',";
731 $sql .=
" fk_user_modif = " . ((int) $user->id);
732 $sql .=
" WHERE rowid = " . ((int) $this->
id);
734 $sql .=
" AND entity = " . ((int)
$conf->entity);
736 if ($this->db->query($sql)) {
739 $result = $this->
call_trigger(
'FICHINTER_CLOSE', $user);
751 $this->db->rollback();
755 $this->error = $this->db->lasterror();
756 $this->db->rollback();
771 $this->author =
new User($this->db);
772 $this->author->fetch($this->user_creation_id);
774 $thm = $this->author->thm;
776 foreach ($this->lines as $line) {
777 $amount += ($line->duration / 60 / 60 * (float) $thm);
795 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
799 $outputlangs->load(
"interventions");
804 if (!empty($this->model_pdf)) {
805 $modele = $this->model_pdf;
811 $modelpath =
"core/modules/fichinter/doc/";
813 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
824 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
840 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
841 $langs->load(
"interventions");
842 $langs->load(
"propal");
846 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
850 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
854 $statuscode =
'status'.$status;
855 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
856 $statuscode =
'status6';
860 $status_label = $this->signed_status ? $this->labelStatus[$status] . $signed_label : $this->labelStatus[$status];
861 $status_label_short = $this->signed_status ? $this->labelStatusShort[$status] . $signed_label : $this->labelStatusShort[$status];
863 return dolGetStatus($status_label, $status_label_short,
'', $statuscode, $mode);
876 $langs->load(
'interventions');
879 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"ShowIntervention").
'</u>';
880 if (isset($this->
status)) {
881 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
883 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
898 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $morecss =
'')
900 global
$conf, $langs, $hookmanager;
902 if (!empty(
$conf->dol_no_mouse_hover)) {
909 'objecttype' => $this->element,
912 $classfortooltip =
'classfortooltip';
915 $classfortooltip =
'classforajaxtooltip';
916 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
922 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
924 if ($option !==
'nolink') {
926 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
927 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
928 $add_save_lastsearch_values = 1;
930 if ($add_save_lastsearch_values) {
931 $url .=
'&save_lastsearch_values=1';
936 if (empty($notooltip)) {
938 $label = $langs->trans(
"ShowIntervention");
939 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
941 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
942 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
944 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
947 if ($option ==
'nolink' || empty($url)) {
948 $linkstart =
'<span';
950 $linkstart =
'<a href="'.$url.
'"';
952 $linkstart .= $linkclose.
'>';
953 if ($option ==
'nolink' || empty($url)) {
954 $linkend =
'</span>';
959 $result .= $linkstart;
961 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
964 if ($withpicto != 2) {
965 $result .= $this->ref;
971 $hookmanager->initHooks(array(
'interventiondao'));
972 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
973 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
975 $result = $hookmanager->resPrint;
977 $result .= $hookmanager->resPrint;
993 global
$conf, $db, $langs;
994 $langs->load(
"interventions");
1003 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1005 foreach ($dirmodels as $reldir) {
1009 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1017 $obj =
new $classname();
1018 '@phan-var-force ModeleNumRefFicheinter $obj';
1020 $numref = $obj->getNextValue($soc, $this);
1022 if ($numref !=
"") {
1029 $langs->load(
"errors");
1030 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
1043 $sql =
"SELECT f.rowid,";
1044 $sql .=
" f.datec,";
1045 $sql .=
" f.tms as date_modification,";
1046 $sql .=
" f.date_valid as datev,";
1047 $sql .=
" f.fk_user_author,";
1048 $sql .=
" f.fk_user_modif as fk_user_modification,";
1049 $sql .=
" f.fk_user_valid";
1050 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
1051 $sql .=
" WHERE f.rowid = ".((int) $id);
1053 $resql = $this->db->query($sql);
1055 if ($this->db->num_rows($resql)) {
1056 $obj = $this->db->fetch_object($resql);
1058 $this->
id = $obj->rowid;
1060 $this->date_creation = $this->db->jdate($obj->datec);
1061 $this->date_modification = $this->db->jdate($obj->date_modification);
1062 $this->date_validation = $this->db->jdate($obj->datev);
1064 $this->user_creation_id = $obj->fk_user_author;
1065 $this->user_validation_id = $obj->fk_user_valid;
1066 $this->user_modification_id = $obj->fk_user_modification;
1068 $this->db->free($resql);
1081 public function delete(
User $user, $notrigger = 0)
1083 global
$conf, $langs;
1084 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1090 if (!$error && !$notrigger) {
1092 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
1095 $this->db->rollback();
1113 $this->error =
'ErrorFailToDeleteLinkedContact';
1119 $main = MAIN_DB_PREFIX.
'fichinterdet';
1120 $ef = $main.
"_extrafields";
1121 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_fichinter = ".((int) $this->
id).
")";
1123 $resql = $this->db->query($sql);
1130 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1131 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1133 $resql = $this->db->query($sql);
1149 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1150 $sql .=
" WHERE rowid = ".((int) $this->
id);
1153 $resql = $this->db->query($sql);
1166 if ($conf->ficheinter->dir_output) {
1167 $dir =
$conf->ficheinter->dir_output.
"/".$fichinterref;
1168 $file =
$conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1169 if (file_exists($file)) {
1173 $langs->load(
"errors");
1174 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1178 if (file_exists($dir)) {
1180 $langs->load(
"errors");
1181 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1189 $this->db->commit();
1192 $this->db->rollback();
1208 if ($user->hasRight(
'ficheinter',
'creer')) {
1209 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1210 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1211 $sql .=
" WHERE rowid = ".((int) $this->
id);
1212 $sql .=
" AND fk_statut = 0";
1214 if ($this->db->query($sql)) {
1215 $this->date_delivery = $date_delivery;
1218 $this->error = $this->db->error();
1219 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1238 if ($user->hasRight(
'ficheinter',
'creer')) {
1239 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1240 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1241 $sql .=
" fk_user_modif = ".((int) $user->id);
1242 $sql .=
" WHERE rowid = ".((int) $this->
id);
1244 if ($this->db->query($sql)) {
1248 $this->error = $this->db->error();
1249 dol_syslog(
"Fichinter::set_description Erreur SQL");
1269 if ($user->hasRight(
'ficheinter',
'creer')) {
1270 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1271 $sql .=
" SET fk_contrat = ".((int) $contractid);
1272 $sql .=
" WHERE rowid = ".((int) $this->
id);
1274 if ($this->db->query($sql)) {
1275 $this->fk_contrat = $contractid;
1278 $this->error = $this->db->error();
1297 global $hookmanager;
1304 foreach ($this->lines as $line) {
1305 $line->fetch_optionals();
1309 $objFrom = clone $this;
1312 if (!empty($socid) && $socid != $this->socid) {
1313 $objsoc =
new Societe($this->db);
1315 if ($objsoc->fetch($socid) > 0) {
1316 $this->socid = $objsoc->id;
1319 $this->fk_project = 0;
1320 $this->fk_delivery_address = 0;
1332 $this->user_author_id = $user->id;
1333 $this->user_validation_id = 0;
1334 $this->date_creation =
'';
1335 $this->date_validation =
'';
1337 $this->ref_client =
'';
1340 $this->context[
'createfromclone'] =
'createfromclone';
1341 $result = $this->
create($user);
1348 foreach ($this->lines as $line) {
1349 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1353 if (is_object($hookmanager)) {
1354 $parameters = array(
'objFrom' => $objFrom);
1356 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1364 unset($this->context[
'createfromclone']);
1368 $this->db->commit();
1371 $this->db->rollback();
1388 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options = [])
1390 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1392 if ($this->
status == self::STATUS_DRAFT) {
1398 $line->fk_fichinter = $fichinterid;
1399 $line->desc = $desc;
1400 $line->date = $date_intervention;
1401 $line->datei = $date_intervention;
1402 $line->duration = $duration;
1404 if (is_array($array_options) && count($array_options) > 0) {
1405 $line->array_options = $array_options;
1408 $result = $line->insert($user);
1411 $this->db->commit();
1414 $this->error = $this->db->error();
1415 $this->db->rollback();
1439 $this->
ref =
'SPECIMEN';
1440 $this->ref_client =
'SPECIMEN CLIENT';
1441 $this->specimen = 1;
1443 $this->datec = $now;
1444 $this->note_private =
'Private note';
1445 $this->note_public =
'SPECIMEN';
1446 $this->duration = 0;
1449 while ($xnbp < $nbp) {
1451 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1452 $line->date = ($now - 3600 * (1 + $xnbp));
1453 $line->datei = ($now - 3600 * (1 + $xnbp));
1454 $line->duration = 600;
1455 $line->fk_fichinter = 0;
1456 $this->lines[$xnbp] = $line;
1459 $this->duration += $line->duration;
1474 $this->lines = array();
1476 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1477 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1478 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1479 $sql .=
" ORDER BY rang ASC, date ASC";
1481 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1483 $resql = $this->db->query($sql);
1485 $num = $this->db->num_rows($resql);
1488 $objp = $this->db->fetch_object($resql);
1491 $line->id = $objp->rowid;
1492 $line->fk_fichinter = $objp->fk_fichinter;
1493 $line->desc = $objp->description;
1494 $line->duration = $objp->duree;
1496 $line->qty = round($objp->duree / 3600, 2);
1497 $line->date = $this->db->jdate($objp->date);
1498 $line->datei = $this->db->jdate($objp->date);
1499 $line->rang = $objp->rang;
1500 $line->product_type = 1;
1501 $line->fetch_optionals();
1503 $this->lines[$i] = $line;
1506 $this->db->free($resql);
1510 $this->error = $this->db->error();
1543 if ($user->hasRight(
'ficheinter',
'creer')) {
1550 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1551 $sql .=
" WHERE rowid = ".((int) $this->
id);
1553 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1554 $resql = $this->db->query($sql);
1556 $this->errors[] = $this->db->error();
1561 $this->ref_client = $ref_client;
1564 if (!$notrigger && empty($error)) {
1566 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1574 $this->db->commit();
1577 foreach ($this->errors as $errmsg) {
1578 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1579 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1581 $this->db->rollback();
1600 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1602 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1603 $return .=
'<div class="info-box info-box-sm">';
1604 $return .=
'<span class="info-box-icon bg-infobox-action">';
1606 $return .=
'</span>';
1607 $return .=
'<div class="info-box-content">';
1608 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1609 if ($selected >= 0) {
1610 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1612 if (!empty($arraydata[
'thirdparty'])) {
1613 $tmpthirdparty = $arraydata[
'thirdparty'];
1614 '@phan-var-force Societe $tmpthirdparty';
1615 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1617 if (property_exists($this,
'duration')) {
1618 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1620 if (method_exists($this,
'getLibStatut')) {
1621 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
1623 $return .=
'</div>';
1624 $return .=
'</div>';
1625 $return .=
'</div>';
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteEcmFiles($mode=0)
Delete related files of object in database.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
const STATUS_BILLED
Billed.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode=0)
Returns the label status.
update($user, $notrigger=0)
Update an intervention.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setClose($user, $notrigger=0)
Close intervention.
set_date_delivery($user, $date_delivery)
Defines a delivery date of intervention.
const STATUS_DRAFT
Draft status.
create($user, $notrigger=0)
Create an intervention into data base.
set_description($user, $description)
Define the label of the intervention.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options=[])
Adding a line of intervention into data base.
const STATUS_VALIDATED
Validated status.
const STATUS_CLOSED
Closed.
setDraft($user)
Set status to draft.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
getAmount()
Returns amount based on user thm.
fetch($rowid, $ref='')
Fetch a intervention.
setRefClient($user, $ref_client, $notrigger=0)
Set customer reference number.
set_contrat($user, $contractid)
Link intervention to a contract.
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
loadStateBoard()
Load indicators into this->nb for board.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $morecss='')
Return clickable name (with picto eventually)
__construct($db)
Constructor.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
info($id)
Load information on object.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getLibSignedStatus(int $mode=0)
Returns the label for signed status.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
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.
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...