30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
39 public $fields = array(
40 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
41 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>-1,
'notnull'=>1,
'position'=>15),
42 '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),
43 'fk_contrat' =>array(
'type'=>
'integer',
'label'=>
'Fk contrat',
'enabled'=>
'$conf->contrat->enabled',
'visible'=>-1,
'position'=>25),
44 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>30),
45 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
46 'ref_client' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefCustomer',
'enabled'=>1,
'visible'=>-1,
'position'=>36),
47 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>40,
'index'=>1),
48 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>45),
49 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
50 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
51 'datei' =>array(
'type'=>
'date',
'label'=>
'Datei',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
52 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
53 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>70),
54 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
55 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Fk statut',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
56 'dateo' =>array(
'type'=>
'date',
'label'=>
'Dateo',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
57 'datee' =>array(
'type'=>
'date',
'label'=>
'Datee',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
58 'datet' =>array(
'type'=>
'date',
'label'=>
'Datet',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
59 'duree' =>array(
'type'=>
'double',
'label'=>
'Duree',
'enabled'=>1,
'visible'=>-1,
'position'=>100),
60 'description' =>array(
'type'=>
'html',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'showoncombobox'=>2),
61 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
62 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>115),
63 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>120),
64 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'Last main doc',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
65 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>130),
66 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>135),
72 public $element =
'fichinter';
77 public $table_element =
'fichinter';
82 public $fk_element =
'fk_fichinter';
87 public $table_element_line =
'fichinterdet';
92 public $picto =
'intervention';
143 public $fk_contrat = 0;
148 public $fk_project = 0;
159 public $extraparams = array();
164 public $lines = array();
211 $sql =
"SELECT count(fi.rowid) as nb";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
213 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
214 if (empty($user->rights->societe->client->voir) && !$user->socid) {
215 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
216 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
219 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
221 $resql = $this->db->query(
$sql);
223 while ($obj = $this->db->fetch_object($resql)) {
224 $this->nb[
"interventions"] = $obj->nb;
226 $this->db->free($resql);
230 $this->error = $this->db->error();
242 public function create($user, $notrigger = 0)
244 global $conf, $langs;
251 if (!empty($this->ref)) {
254 $this->error =
'ErrorRefAlreadyExists';
255 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
256 $this->db->rollback();
260 if (!is_numeric($this->duration)) {
263 if (isset($this->ref_client)) {
264 $this->ref_client = trim($this->ref_client);
267 if ($this->socid <= 0) {
268 $this->error =
'ErrorFicheinterCompanyDoesNotExist';
269 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
274 $result = $soc->fetch($this->socid);
280 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
284 $sql .=
", ref_client";
286 $sql .=
", fk_user_author";
287 $sql .=
", fk_user_modif";
288 $sql .=
", description";
289 $sql .=
", model_pdf";
290 $sql .=
", fk_projet";
291 $sql .=
", fk_contrat";
292 $sql .=
", fk_statut";
293 $sql .=
", note_private";
294 $sql .=
", note_public";
297 $sql .= $this->socid;
298 $sql .=
", '".$this->db->idate($now).
"'";
299 $sql .=
", '".$this->db->escape($this->ref).
"'";
300 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
301 $sql .=
", ".((int) $conf->entity);
302 $sql .=
", ".((int) $user->id);
303 $sql .=
", ".((int) $user->id);
304 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
305 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
306 $sql .=
", ".($this->fk_project ? ((int) $this->fk_project) : 0);
307 $sql .=
", ".($this->fk_contrat ? ((int) $this->fk_contrat) : 0);
308 $sql .=
", ".((int) $this->statut);
309 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
310 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
313 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
314 $result = $this->db->query(
$sql);
316 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
319 $this->ref =
'(PROV'.$this->id.
')';
320 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->db->escape($this->ref).
"' WHERE rowid=".((int) $this->
id);
322 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
323 $resql = $this->db->query(
$sql);
337 if (!$error && $this->origin && $this->origin_id) {
345 if (!$error && !$notrigger) {
347 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
358 $this->db->rollback();
359 $this->error = join(
',', $this->errors);
360 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
364 $this->error = $this->db->error();
365 $this->db->rollback();
377 public function update($user, $notrigger = 0)
381 if (!is_numeric($this->duration)) {
385 $this->fk_project = 0;
387 if (isset($this->ref_client)) {
388 $this->ref_client = trim($this->ref_client);
395 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
397 $sql .=
", duree = ".((int) $this->duration);
398 $sql .=
", ref_client = ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
399 $sql .=
", fk_projet = ".((int) $this->fk_project);
400 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
401 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
402 $sql .=
", fk_user_modif = ".((int) $user->id);
403 $sql .=
" WHERE rowid = ".((int) $this->
id);
405 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
406 if ($this->db->query(
$sql)) {
414 if (!$error && !$notrigger) {
416 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
418 $error++; $this->db->rollback();
return -1;
426 $this->error = $this->db->error();
427 $this->db->rollback();
439 public function fetch($rowid, $ref =
'')
441 $sql =
"SELECT f.rowid, f.ref, f.ref_client, f.description, f.fk_soc, f.fk_statut,";
442 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
443 $sql .=
" f.date_valid as datev,";
444 $sql .=
" f.tms as datem,";
445 $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";
446 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
448 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
449 $sql .=
" AND f.ref = '".$this->db->escape($ref).
"'";
451 $sql .=
" WHERE f.rowid = ".((int) $rowid);
454 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
455 $resql = $this->db->query(
$sql);
457 if ($this->db->num_rows($resql)) {
458 $obj = $this->db->fetch_object($resql);
460 $this->
id = $obj->rowid;
461 $this->
ref = $obj->ref;
462 $this->ref_client = $obj->ref_client;
464 $this->socid = $obj->fk_soc;
465 $this->statut = $obj->fk_statut;
466 $this->duration = $obj->duree;
467 $this->datec = $this->db->jdate($obj->datec);
468 $this->dateo = $this->db->jdate($obj->dateo);
469 $this->datee = $this->db->jdate($obj->datee);
470 $this->datet = $this->db->jdate($obj->datet);
471 $this->datev = $this->db->jdate($obj->datev);
472 $this->datem = $this->db->jdate($obj->datem);
473 $this->fk_project = $obj->fk_project;
474 $this->note_public = $obj->note_public;
475 $this->note_private = $obj->note_private;
476 $this->model_pdf = $obj->model_pdf;
477 $this->modelpdf = $obj->model_pdf;
478 $this->fk_contrat = $obj->fk_contrat;
479 $this->entity = $obj->entity;
481 $this->user_creation = $obj->fk_user_author;
483 $this->extraparams = (array) json_decode($obj->extraparams,
true);
485 $this->last_main_doc = $obj->last_main_doc;
487 if ($this->statut == 0) {
488 $this->brouillon = 1;
501 $this->db->free($resql);
507 $this->error = $this->db->lasterror();
523 if ($this->statut <= self::STATUS_DRAFT) {
527 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
533 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
534 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
535 $sql .=
" WHERE rowid = ".((int) $this->
id);
537 $resql = $this->db->query(
$sql);
541 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
552 $this->db->rollback();
556 $this->db->rollback();
557 $this->error = $this->db->lasterror();
572 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
576 if ($this->statut != 1) {
582 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
589 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
590 $sql .=
" SET fk_statut = 1";
591 $sql .=
", ref = '".$this->db->escape($num).
"'";
592 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
593 $sql .=
", fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null");
594 $sql .=
" WHERE rowid = ".((int) $this->
id);
595 $sql .=
" AND entity = ".((int) $conf->entity);
596 $sql .=
" AND fk_statut = 0";
598 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
599 $resql = $this->db->query(
$sql);
605 if (!$error && !$notrigger) {
607 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
615 $this->oldref = $this->ref;
618 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
619 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
622 $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).
"'";
623 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'ficheinter/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
624 $resql = $this->db->query(
$sql);
626 $error++; $this->error = $this->db->lasterror();
632 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
633 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
634 if (!$error && file_exists($dirsource)) {
635 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
637 if (@rename($dirsource, $dirdest)) {
640 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
641 foreach ($listoffiles as $fileentry) {
642 $dirsource = $fileentry[
'name'];
643 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
644 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
645 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
646 @rename($dirsource, $dirdest);
657 $this->brouillon = 0;
658 $this->date_validation = $now;
662 $this->db->rollback();
663 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
682 $this->author =
new User($db);
683 $this->author->fetch($this->user_creation);
685 $thm = $this->author->thm;
687 foreach ($this->lines as $line) {
688 $amount += ($line->duration / 60 / 60 * $thm);
706 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
710 $outputlangs->load(
"interventions");
715 if (!empty($this->model_pdf)) {
716 $modele = $this->model_pdf;
717 } elseif (!empty($this->modelpdf)) {
718 $modele = $this->modelpdf;
719 } elseif (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
720 $modele = $conf->global->FICHEINTER_ADDON_PDF;
724 $modelpath =
"core/modules/fichinter/doc/";
726 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
737 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
752 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
754 $langs->load(
"fichinter");
758 $this->labelStatus[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
762 $this->labelStatusShort[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
766 $statuscode =
'status'.$status;
767 if ($status == self::STATUS_BILLED || $status == self::STATUS_CLOSED) {
768 $statuscode =
'status6';
770 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statuscode, $mode);
782 global $conf, $langs;
784 $langs->load(
'fichinter');
787 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
788 if (isset($this->status)) {
789 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
791 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
805 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1)
807 global $conf, $langs, $hookmanager;
812 'objecttype' => $this->element,
814 $classfortooltip =
'classfortooltip';
817 $classfortooltip =
'classforajaxtooltip';
818 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
824 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
826 if ($option !==
'nolink') {
828 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
829 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
830 $add_save_lastsearch_values = 1;
832 if ($add_save_lastsearch_values) {
833 $url .=
'&save_lastsearch_values=1';
838 if (empty($notooltip)) {
839 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
840 $label = $langs->trans(
"ShowIntervention");
841 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
843 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
844 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
847 $linkstart =
'<a href="'.$url.
'"';
848 $linkstart .= $linkclose.
'>';
851 $result .= $linkstart;
853 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
855 if ($withpicto != 2) {
856 $result .= $this->ref;
861 $hookmanager->initHooks(array(
'interventiondao'));
862 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
863 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
865 $result = $hookmanager->resPrint;
867 $result .= $hookmanager->resPrint;
883 global $conf, $db, $langs;
884 $langs->load(
"interventions");
886 if (!empty($conf->global->FICHEINTER_ADDON)) {
889 $file =
"mod_".$conf->global->FICHEINTER_ADDON.
".php";
890 $classname =
"mod_".$conf->global->FICHEINTER_ADDON;
893 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
895 foreach ($dirmodels as $reldir) {
899 $mybool |= @include_once $dir.$file;
902 if ($mybool ===
false) {
907 $obj =
new $classname();
909 $numref = $obj->getNextValue($soc, $this);
918 $langs->load(
"errors");
919 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
932 $sql =
"SELECT f.rowid,";
934 $sql .=
" f.tms as date_modification,";
935 $sql .=
" f.date_valid as datev,";
936 $sql .=
" f.fk_user_author,";
937 $sql .=
" f.fk_user_modif as fk_user_modification,";
938 $sql .=
" f.fk_user_valid";
939 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
940 $sql .=
" WHERE f.rowid = ".((int) $id);
942 $resql = $this->db->query(
$sql);
944 if ($this->db->num_rows($resql)) {
945 $obj = $this->db->fetch_object($resql);
947 $this->
id = $obj->rowid;
949 $this->date_creation = $this->db->jdate($obj->datec);
950 $this->date_modification = $this->db->jdate($obj->date_modification);
951 $this->date_validation = $this->db->jdate($obj->datev);
953 $cuser =
new User($this->db);
954 $cuser->fetch($obj->fk_user_author);
955 $this->user_creation = $cuser;
957 if ($obj->fk_user_valid) {
958 $vuser =
new User($this->db);
959 $vuser->fetch($obj->fk_user_valid);
960 $this->user_validation = $vuser;
962 if ($obj->fk_user_modification) {
963 $muser =
new User($this->db);
964 $muser->fetch($obj->fk_user_modification);
965 $this->user_modification = $muser;
968 $this->db->free($resql);
981 public function delete(
User $user, $notrigger = 0)
983 global $conf, $langs;
984 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
990 if (!$error && !$notrigger) {
992 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
994 $error++; $this->db->rollback();
return -1;
1011 $this->error =
'ErrorFailToDeleteLinkedContact';
1017 $main = MAIN_DB_PREFIX.
'fichinterdet';
1018 $ef = $main.
"_extrafields";
1019 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".((int) $this->
id).
")";
1021 $resql = $this->db->query(
$sql);
1028 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1029 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1031 $resql = $this->db->query(
$sql);
1047 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1048 $sql .=
" WHERE rowid = ".((int) $this->
id);
1051 $resql = $this->db->query(
$sql);
1063 if ($conf->ficheinter->dir_output) {
1064 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1065 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1066 if (file_exists($file)) {
1070 $langs->load(
"errors");
1071 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1075 if (file_exists($dir)) {
1077 $langs->load(
"errors");
1078 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1086 $this->db->commit();
1089 $this->db->rollback();
1105 if ($user->rights->ficheinter->creer) {
1106 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1107 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1108 $sql .=
" WHERE rowid = ".((int) $this->
id);
1109 $sql .=
" AND fk_statut = 0";
1111 if ($this->db->query(
$sql)) {
1112 $this->date_delivery = $date_delivery;
1115 $this->error = $this->db->error();
1116 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1135 if ($user->rights->ficheinter->creer) {
1136 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1137 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1138 $sql .=
" fk_user_modif = ".$user->id;
1139 $sql .=
" WHERE rowid = ".((int) $this->
id);
1141 if ($this->db->query(
$sql)) {
1145 $this->error = $this->db->error();
1146 dol_syslog(
"Fichinter::set_description Erreur SQL");
1166 if ($user->rights->ficheinter->creer) {
1167 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1168 $sql .=
" SET fk_contrat = ".((int) $contractid);
1169 $sql .=
" WHERE rowid = ".((int) $this->
id);
1171 if ($this->db->query(
$sql)) {
1172 $this->fk_contrat = $contractid;
1175 $this->error = $this->db->error();
1194 global $hookmanager;
1201 foreach ($this->lines as $line) {
1202 $line->fetch_optionals();
1206 $objFrom = clone $this;
1209 if (!empty($socid) && $socid != $this->socid) {
1210 $objsoc =
new Societe($this->db);
1212 if ($objsoc->fetch($socid) > 0) {
1213 $this->socid = $objsoc->id;
1216 $this->fk_project =
'';
1217 $this->fk_delivery_address =
'';
1228 $this->user_author_id = $user->id;
1229 $this->user_valid = 0;
1230 $this->date_creation =
'';
1231 $this->date_validation =
'';
1232 $this->ref_client =
'';
1235 $this->context[
'createfromclone'] =
'createfromclone';
1236 $result = $this->
create($user);
1243 foreach ($this->lines as $line) {
1244 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1248 if (is_object($hookmanager)) {
1249 $parameters = array(
'objFrom'=>$objFrom);
1251 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1259 unset($this->context[
'createfromclone']);
1263 $this->db->commit();
1266 $this->db->rollback();
1283 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options =
'')
1285 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1287 if ($this->statut == self::STATUS_DRAFT) {
1293 $line->fk_fichinter = $fichinterid;
1294 $line->desc = $desc;
1295 $line->date = $date_intervention;
1296 $line->datei = $date_intervention;
1297 $line->duration = $duration;
1299 if (is_array($array_options) && count($array_options) > 0) {
1300 $line->array_options = $array_options;
1303 $result = $line->insert($user);
1306 $this->db->commit();
1309 $this->error = $this->db->error();
1310 $this->db->rollback();
1334 $this->
ref =
'SPECIMEN';
1335 $this->ref_client =
'SPECIMEN CLIENT';
1336 $this->specimen = 1;
1338 $this->datec = $now;
1339 $this->note_private =
'Private note';
1340 $this->note_public =
'SPECIMEN';
1341 $this->duration = 0;
1344 while ($xnbp < $nbp) {
1346 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1347 $line->date = ($now - 3600 * (1 + $xnbp));
1348 $line->datei = ($now - 3600 * (1 + $xnbp));
1349 $line->duration = 600;
1350 $line->fk_fichinter = 0;
1351 $this->lines[$xnbp] = $line;
1354 $this->duration += $line->duration;
1367 $this->lines = array();
1369 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1370 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1371 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1372 $sql .=
" ORDER BY rang ASC, date ASC";
1374 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1376 $resql = $this->db->query(
$sql);
1378 $num = $this->db->num_rows($resql);
1381 $objp = $this->db->fetch_object($resql);
1384 $line->id = $objp->rowid;
1385 $line->fk_fichinter = $objp->fk_fichinter;
1386 $line->desc = $objp->description;
1387 $line->duration = $objp->duree;
1389 $line->qty = round($objp->duree / 3600, 2);
1390 $line->date = $this->db->jdate($objp->date);
1391 $line->datei = $this->db->jdate($objp->date);
1392 $line->rang = $objp->rang;
1393 $line->product_type = 1;
1394 $line->fetch_optionals();
1396 $this->lines[$i] = $line;
1399 $this->db->free($resql);
1403 $this->error = $this->db->error();
1436 if (!empty($user->rights->ficheinter->creer)) {
1443 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1444 $sql .=
" WHERE rowid = ".((int) $this->
id);
1446 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1447 $resql = $this->db->query(
$sql);
1449 $this->errors[] = $this->db->error();
1454 $this->ref_client = $ref_client;
1457 if (!$notrigger && empty($error)) {
1459 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1467 $this->db->commit();
1470 foreach ($this->errors as $errmsg) {
1471 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1472 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1474 $this->db->rollback();
1493 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
1495 $return =
'<div class="box-flex-item box-flex-grow-zero">';
1496 $return .=
'<div class="info-box info-box-sm">';
1497 $return .=
'<span class="info-box-icon bg-infobox-action">';
1499 $return .=
'</span>';
1500 $return .=
'<div class="info-box-content">';
1501 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
1502 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
1503 if (!empty($arraydata[
'thirdparty'])) {
1504 $tmpthirdparty = $arraydata[
'thirdparty'];
1505 $return .=
'<br><span class="info-box-label">'.$tmpthirdparty->getNomUrl(1).
'</span>';
1507 if (property_exists($this,
'duration')) {
1508 $return .=
'<br><span class="info-box-label ">'.$langs->trans(
"Duration").
' : '.
convertSecondToTime($this->duration,
'allhourmin').
'</span>';
1510 if (method_exists($this,
'getLibStatut')) {
1511 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
1513 $return .=
'</div>';
1514 $return .=
'</div>';
1515 $return .=
'</div>';
1539 public $fk_fichinter;
1561 public $element =
'fichinterdet';
1566 public $table_element =
'fichinterdet';
1571 public $fk_element =
'fk_fichinter';
1593 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1595 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date';
1596 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1597 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
1599 $resql = $this->db->query(
$sql);
1601 $objp = $this->db->fetch_object($resql);
1602 $this->
rowid = $objp->rowid;
1603 $this->
id = $objp->rowid;
1604 $this->fk_fichinter = $objp->fk_fichinter;
1605 $this->date = $this->db->jdate($objp->date);
1606 $this->datei = $this->db->jdate($objp->date);
1607 $this->desc = $objp->description;
1608 $this->duration = $objp->duree;
1609 $this->rang = $objp->rang;
1611 $this->db->free($resql);
1617 $this->error = $this->db->error().
' sql='.
$sql;
1629 public function insert($user, $notrigger = 0)
1633 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1635 if (empty($this->date) && !empty($this->datei)) {
1636 $this->date = $this->datei;
1641 $rangToUse = $this->rang;
1642 if ($rangToUse == -1) {
1644 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1645 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
1646 $resql = $this->db->query(
$sql);
1648 $obj = $this->db->fetch_object($resql);
1649 $rangToUse = $obj->max + 1;
1652 $this->db->rollback();
1658 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1659 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1660 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
1661 $sql .=
" '".$this->db->escape($this->desc).
"',";
1662 $sql .=
" '".$this->db->idate($this->date).
"',";
1663 $sql .=
" ".((int) $this->duration).
",";
1664 $sql .=
' '.((int) $rangToUse);
1667 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1668 $resql = $this->db->query(
$sql);
1670 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1671 $this->
rowid = $this->id;
1684 $this->rang = $rangToUse;
1688 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1697 $this->db->commit();
1700 $this->db->rollback();
1704 $this->error = $this->db->error().
" sql=".
$sql;
1705 $this->db->rollback();
1718 public function update($user, $notrigger = 0)
1722 if (empty($this->date) && !empty($this->datei)) {
1723 $this->date = $this->datei;
1729 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1730 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
1731 $sql .=
" date = '".$this->db->idate($this->date).
"',";
1732 $sql .=
" duree = ".((int) $this->duration).
",";
1733 $sql .=
" rang = ".((int) $this->rang);
1734 $sql .=
" WHERE rowid = ".((int) $this->
id);
1736 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1737 $resql = $this->db->query(
$sql);
1750 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
1759 $this->db->commit();
1762 $this->error = $this->db->lasterror();
1763 $this->db->rollback();
1767 $this->error = $this->db->lasterror();
1768 $this->db->rollback();
1786 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1787 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1788 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
1790 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1791 $resql = $this->db->query(
$sql);
1793 $obj = $this->db->fetch_object($resql);
1794 $total_duration = 0;
1795 if (!empty($obj->total_duration)) {
1796 $total_duration = $obj->total_duration;
1799 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1800 $sql .=
" SET duree = ".((int) $total_duration);
1801 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->escape($obj->dateo).
"'" :
"null");
1802 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->escape($obj->datee).
"'" :
"null");
1803 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
1805 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1806 $resql = $this->db->query(
$sql);
1808 $this->db->commit();
1811 $this->error = $this->db->error();
1812 $this->db->rollback();
1816 $this->error = $this->db->error();
1817 $this->db->rollback();
1831 global $langs, $conf;
1835 if ($this->statut == 0) {
1836 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1842 $this->db->rollback();
1846 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
1847 $resql = $this->db->query(
$sql);
1854 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1856 $error++; $this->db->rollback();
return -1;
1861 $this->db->commit();
1864 $this->db->rollback();
1868 $this->error = $this->db->error().
" sql=".
$sql;
1869 $this->db->rollback();