30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
40 public $fields = array(
41 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
42 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
43 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Fk projet',
'enabled'=>1,
'visible'=>-1,
'position'=>20),
44 'fk_contrat' =>array(
'type'=>
'integer',
'label'=>
'Fk contrat',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
45 'ref' =>array(
'type'=>
'varchar(30)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'showoncombobox'=>1,
'position'=>30),
46 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
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'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'showoncombobox'=>1),
61 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
62 'note_public' =>array(
'type'=>
'text',
'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),
71 public $element =
'fichinter';
76 public $table_element =
'fichinter';
81 public $fk_element =
'fk_fichinter';
86 public $table_element_line =
'fichinterdet';
91 public $picto =
'intervention';
142 public $fk_contrat = 0;
147 public $fk_project = 0;
152 public $extraparams = array();
157 public $lines = array();
204 $sql =
"SELECT count(fi.rowid) as nb";
205 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as fi";
206 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON fi.fk_soc = s.rowid";
207 if (!$user->rights->societe->client->voir && !$user->socid)
209 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
210 $sql .=
" WHERE sc.fk_user = ".$user->id;
213 $sql .=
" ".$clause.
" fi.entity IN (".
getEntity(
'intervention').
")";
218 while ($obj = $this->
db->fetch_object(
$resql))
220 $this->nb[
"interventions"] = $obj->nb;
226 $this->error = $this->
db->error();
238 public function create($user, $notrigger = 0)
240 global $conf, $langs;
244 dol_syslog(get_class($this).
"::create ref=".$this->ref);
247 if (!empty($this->ref))
249 $result = self::isExistingObject($this->element, 0, $this->ref);
252 $this->error =
'ErrorRefAlreadyExists';
253 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
254 $this->
db->rollback();
258 if (!is_numeric($this->duration)) $this->duration = 0;
260 if ($this->socid <= 0)
262 $this->error =
'ErrorBadParameterForFunc';
263 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
268 $result = $soc->fetch($this->socid);
274 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter (";
279 $sql .=
", fk_user_author";
280 $sql .=
", fk_user_modif";
281 $sql .=
", description";
282 $sql .=
", model_pdf";
283 $sql .=
", fk_projet";
284 $sql .=
", fk_contrat";
285 $sql .=
", fk_statut";
286 $sql .=
", note_private";
287 $sql .=
", note_public";
290 $sql .= $this->socid;
291 $sql .=
", '".$this->db->idate($now).
"'";
292 $sql .=
", '".$this->db->escape($this->ref).
"'";
293 $sql .=
", ".$conf->entity;
294 $sql .=
", ".$user->id;
295 $sql .=
", ".$user->id;
296 $sql .=
", ".($this->description ?
"'".$this->db->escape($this->
description).
"'" :
"null");
297 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
298 $sql .=
", ".($this->fk_project ? $this->fk_project : 0);
299 $sql .=
", ".($this->fk_contrat ? $this->fk_contrat : 0);
300 $sql .=
", ".$this->statut;
301 $sql .=
", ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
302 $sql .=
", ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
305 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
306 $result = $this->
db->query($sql);
309 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"fichinter");
313 $this->ref =
'(PROV'.$this->id.
')';
314 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"fichinter SET ref='".$this->
db->escape($this->ref).
"' WHERE rowid=".$this->id;
316 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
331 if (!$error && $this->origin && $this->origin_id)
338 if (!$error && !$notrigger)
341 $result = $this->
call_trigger(
'FICHINTER_CREATE', $user);
342 if ($result < 0) { $error++; }
350 $this->
db->rollback();
351 $this->error = join(
',', $this->errors);
352 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
356 $this->error = $this->
db->error();
357 $this->
db->rollback();
369 public function update($user, $notrigger = 0)
373 if (!is_numeric($this->duration)) {
377 $this->fk_project = 0;
384 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter SET ";
385 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
386 $sql .=
", duree = ".$this->duration;
387 $sql .=
", fk_projet = ".$this->fk_project;
388 $sql .=
", note_private = ".($this->note_private ?
"'".$this->db->escape($this->note_private).
"'" :
"null");
389 $sql .=
", note_public = ".($this->note_public ?
"'".$this->db->escape($this->note_public).
"'" :
"null");
390 $sql .=
", fk_user_modif = ".$user->id;
391 $sql .=
" WHERE rowid = ".$this->id;
393 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
394 if ($this->
db->query($sql))
405 if (!$error && !$notrigger)
408 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
409 if ($result < 0) { $error++; $this->
db->rollback();
return -1; }
416 $this->error = $this->
db->error();
417 $this->
db->rollback();
429 public function fetch($rowid, $ref =
'')
431 $sql =
"SELECT f.rowid, f.ref, f.description, f.fk_soc, f.fk_statut,";
432 $sql .=
" f.datec, f.dateo, f.datee, f.datet, f.fk_user_author,";
433 $sql .=
" f.date_valid as datev,";
434 $sql .=
" f.tms as datem,";
435 $sql .=
" f.duree, f.fk_projet as fk_project, f.note_public, f.note_private, f.model_pdf, f.extraparams, fk_contrat";
436 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
438 $sql .=
" WHERE f.entity IN (".getEntity(
'intervention').
")";
439 $sql .=
" AND f.ref='".$this->db->escape($ref).
"'";
440 }
else $sql .=
" WHERE f.rowid=".$rowid;
442 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
448 $obj = $this->
db->fetch_object(
$resql);
450 $this->
id = $obj->rowid;
451 $this->ref = $obj->ref;
453 $this->socid = $obj->fk_soc;
454 $this->
statut = $obj->fk_statut;
455 $this->duration = $obj->duree;
456 $this->datec = $this->
db->jdate($obj->datec);
457 $this->dateo = $this->
db->jdate($obj->dateo);
458 $this->datee = $this->
db->jdate($obj->datee);
459 $this->datet = $this->
db->jdate($obj->datet);
460 $this->datev = $this->
db->jdate($obj->datev);
461 $this->datem = $this->
db->jdate($obj->datem);
462 $this->fk_project = $obj->fk_project;
463 $this->note_public = $obj->note_public;
464 $this->note_private = $obj->note_private;
465 $this->model_pdf = $obj->model_pdf;
466 $this->modelpdf = $obj->model_pdf;
467 $this->fk_contrat = $obj->fk_contrat;
469 $this->user_creation = $obj->fk_user_author;
471 $this->extraparams = (array) json_decode($obj->extraparams,
true);
473 if ($this->
statut == 0) $this->brouillon = 1;
490 $this->error = $this->
db->lasterror();
503 global $langs, $conf;
508 if ($this->
statut <= self::STATUS_DRAFT)
513 dol_syslog(get_class($this).
"::setDraft", LOG_DEBUG);
517 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
518 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
519 $sql .=
" WHERE rowid = ".$this->id;
525 $this->oldcopy = clone $this;
530 $result = $this->
call_trigger(
'FICHINTER_UNVALIDATE', $user);
531 if ($result < 0) $error++;
535 $this->
statut = self::STATUS_DRAFT;
539 $this->
db->rollback();
543 $this->
db->rollback();
544 $this->error = $this->
db->lasterror();
559 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
570 if (!$error && (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref)))
578 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
579 $sql .=
" SET fk_statut = 1";
580 $sql .=
", ref = '".$num.
"'";
581 $sql .=
", date_valid = '".$this->db->idate($now).
"'";
582 $sql .=
", fk_user_valid = ".$user->id;
583 $sql .=
" WHERE rowid = ".$this->id;
584 $sql .=
" AND entity = ".$conf->entity;
585 $sql .=
" AND fk_statut = 0";
587 dol_syslog(get_class($this).
"::setValid", LOG_DEBUG);
595 if (!$error && !$notrigger)
598 $result = $this->
call_trigger(
'FICHINTER_VALIDATE', $user);
599 if ($result < 0) { $error++; }
605 $this->oldref = $this->ref;
608 if (preg_match(
'/^[\(]?PROV/i', $this->ref))
610 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
613 $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).
"'";
614 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'ficheinter/".$this->
db->escape($this->ref).
"' and entity = ".$conf->entity;
616 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
621 $dirsource = $conf->ficheinter->dir_output.
'/'.$oldref;
622 $dirdest = $conf->ficheinter->dir_output.
'/'.$newref;
623 if (!$error && file_exists($dirsource))
625 dol_syslog(get_class($this).
"::setValid rename dir ".$dirsource.
" into ".$dirdest);
627 if (@rename($dirsource, $dirdest))
631 $listoffiles =
dol_dir_list($conf->ficheinter->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
632 foreach ($listoffiles as $fileentry)
634 $dirsource = $fileentry[
'name'];
635 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
636 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
637 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
638 @rename($dirsource, $dirdest);
650 $this->brouillon = 0;
651 $this->date_validation = $now;
655 $this->
db->rollback();
656 dol_syslog(get_class($this).
"::setValid ".$this->error, LOG_ERR);
673 $this->author =
new User($db);
674 $this->author->fetch($this->user_creation);
676 $thm = $this->author->thm;
678 foreach ($this->lines as $line) {
679 $amount += ($line->duration / 60 / 60 * $thm);
697 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
701 $outputlangs->load(
"interventions");
706 if (!empty($this->model_pdf)) {
707 $modele = $this->model_pdf;
708 } elseif (!empty($this->modelpdf)) {
709 $modele = $this->modelpdf;
710 } elseif (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
711 $modele = $conf->global->FICHEINTER_ADDON_PDF;
715 $modelpath =
"core/modules/fichinter/doc/";
717 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
743 if (empty($this->statuts) || empty($this->statuts_short) || empty($this->statuts_logo))
746 $langs->load(
"fichinter");
748 $this->statuts[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
749 $this->statuts[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
750 $this->statuts[self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
751 $this->statuts[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Done');
752 $this->statuts_short[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'Draft');
753 $this->statuts_short[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'Validated');
754 $this->statuts_short[self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
755 $this->statuts_short[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'Done');
756 $this->statuts_logo[self::STATUS_DRAFT] =
'status0';
757 $this->statuts_logo[self::STATUS_VALIDATED] =
'status1';
758 $this->statuts_logo[self::STATUS_BILLED] =
'status6';
759 $this->statuts_logo[self::STATUS_CLOSED] =
'status6';
762 return dolGetStatus($this->statuts[$status], $this->statuts_short[$status],
'', $this->statuts_logo[$status], $mode);
774 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1)
776 global $conf, $langs, $hookmanager;
780 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
781 if (isset($this->status)) {
782 $label .=
' '.$this->getLibStatut(5);
784 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
786 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
788 if ($option !==
'nolink')
791 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
792 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
793 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
797 if (empty($notooltip))
799 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
801 $label = $langs->trans(
"ShowIntervention");
802 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
804 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
805 $linkclose .=
' class="classfortooltip"';
815 $linkstart =
'<a href="'.$url.
'"';
816 $linkstart .= $linkclose.
'>';
819 $result .= $linkstart;
820 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
821 if ($withpicto != 2) $result .= $this->ref;
825 $hookmanager->initHooks(array(
'interventiondao'));
826 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
827 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
828 if ($reshook > 0) $result = $hookmanager->resPrint;
829 else $result .= $hookmanager->resPrint;
844 global $conf, $db, $langs;
845 $langs->load(
"interventions");
847 if (!empty($conf->global->FICHEINTER_ADDON))
851 $file =
"mod_".$conf->global->FICHEINTER_ADDON.
".php";
852 $classname =
"mod_".$conf->global->FICHEINTER_ADDON;
855 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
857 foreach ($dirmodels as $reldir) {
861 $mybool |= @include_once $dir.$file;
864 if ($mybool ===
false) {
869 $obj =
new $classname();
871 $numref = $obj->getNextValue($soc, $this);
881 $langs->load(
"errors");
882 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
897 $sql =
"SELECT f.rowid,";
899 $sql .=
" f.tms as date_modification,";
900 $sql .=
" f.date_valid as datev,";
901 $sql .=
" f.fk_user_author,";
902 $sql .=
" f.fk_user_modif as fk_user_modification,";
903 $sql .=
" f.fk_user_valid";
904 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
905 $sql .=
" WHERE f.rowid = ".$id;
912 $obj = $this->
db->fetch_object(
$resql);
914 $this->
id = $obj->rowid;
916 $this->date_creation = $this->
db->jdate($obj->datec);
917 $this->date_modification = $this->
db->jdate($obj->date_modification);
918 $this->date_validation = $this->
db->jdate($obj->datev);
920 $cuser =
new User($this->
db);
921 $cuser->fetch($obj->fk_user_author);
922 $this->user_creation = $cuser;
924 if ($obj->fk_user_valid)
926 $vuser =
new User($this->
db);
927 $vuser->fetch($obj->fk_user_valid);
928 $this->user_validation = $vuser;
930 if ($obj->fk_user_modification)
932 $muser =
new User($this->
db);
933 $muser->fetch($obj->fk_user_modification);
934 $this->user_modification = $muser;
950 public function delete($user, $notrigger = 0)
952 global $conf, $langs;
953 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
959 if (!$error && !$notrigger)
962 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
963 if ($result < 0) { $error++; $this->
db->rollback();
return -1; }
971 if ($res < 0) $error++;
980 $this->error =
'ErrorFailToDeleteLinkedContact';
986 $main = MAIN_DB_PREFIX.
'fichinterdet';
987 $ef = $main.
"_extrafields";
988 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".$this->id.
")";
996 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
997 $sql .=
" WHERE fk_fichinter = ".$this->id;
1007 if ($res < 0) $error++;
1013 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1014 $sql .=
" WHERE rowid = ".$this->id;
1028 if ($conf->ficheinter->dir_output)
1030 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1031 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1032 if (file_exists($file))
1038 $langs->load(
"errors");
1039 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1043 if (file_exists($dir))
1047 $langs->load(
"errors");
1048 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1057 $this->
db->commit();
1060 $this->
db->rollback();
1078 if ($user->rights->ficheinter->creer)
1080 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1081 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1082 $sql .=
" WHERE rowid = ".$this->id;
1083 $sql .=
" AND fk_statut = 0";
1085 if ($this->
db->query($sql))
1087 $this->date_delivery = $date_delivery;
1090 $this->error = $this->
db->error();
1091 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1110 if ($user->rights->ficheinter->creer)
1112 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1113 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1114 $sql .=
" fk_user_modif = ".$user->id;
1115 $sql .=
" WHERE rowid = ".$this->id;
1117 if ($this->
db->query($sql))
1122 $this->error = $this->
db->error();
1123 dol_syslog(
"Fichinter::set_description Erreur SQL");
1143 if ($user->rights->ficheinter->creer)
1145 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1146 $sql .=
" SET fk_contrat = ".((int) $contractid);
1147 $sql .=
" WHERE rowid = ".$this->id;
1149 if ($this->
db->query($sql))
1151 $this->fk_contrat = $contractid;
1154 $this->error = $this->
db->error();
1172 global $hookmanager;
1179 foreach ($this->lines as $line)
1180 $line->fetch_optionals();
1183 $objFrom = clone $this;
1186 if (!empty($socid) && $socid != $this->socid)
1190 if ($objsoc->fetch($socid) > 0)
1192 $this->socid = $objsoc->id;
1195 $this->fk_project =
'';
1196 $this->fk_delivery_address =
'';
1207 $this->user_author_id = $user->id;
1208 $this->user_valid =
'';
1209 $this->date_creation =
'';
1210 $this->date_validation =
'';
1211 $this->ref_client =
'';
1214 $this->context[
'createfromclone'] =
'createfromclone';
1215 $result = $this->
create($user);
1216 if ($result < 0) $error++;
1221 foreach ($this->lines as $line)
1223 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration);
1227 if (is_object($hookmanager))
1229 $parameters = array(
'objFrom'=>$objFrom);
1231 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1232 if ($reshook < 0) $error++;
1236 unset($this->context[
'createfromclone']);
1241 $this->
db->commit();
1244 $this->
db->rollback();
1261 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options =
'')
1263 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1272 $line->fk_fichinter = $fichinterid;
1273 $line->desc = $desc;
1274 $line->datei = $date_intervention;
1275 $line->duration = $duration;
1277 if (is_array($array_options) && count($array_options) > 0) {
1278 $line->array_options = $array_options;
1281 $result = $line->insert($user);
1285 $this->
db->commit();
1288 $this->error = $this->
db->error();
1289 $this->
db->rollback();
1305 global $user, $langs, $conf;
1311 $this->ref =
'SPECIMEN';
1312 $this->specimen = 1;
1314 $this->datec = $now;
1315 $this->note_private =
'Private note';
1316 $this->note_public =
'SPECIMEN';
1317 $this->duration = 0;
1320 while ($xnbp < $nbp)
1323 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1324 $line->datei = ($now - 3600 * (1 + $xnbp));
1325 $line->duration = 600;
1326 $line->fk_fichinter = 0;
1327 $this->lines[$xnbp] = $line;
1330 $this->duration += $line->duration;
1343 $this->lines = array();
1345 $sql =
'SELECT rowid, fk_fichinter, description, duree, date, rang';
1346 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1347 $sql .=
' WHERE fk_fichinter = '.$this->id.
' ORDER BY rang ASC, date ASC';
1349 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1353 $num = $this->
db->num_rows(
$resql);
1357 $objp = $this->
db->fetch_object(
$resql);
1360 $line->id = $objp->rowid;
1361 $line->fk_fichinter = $objp->fk_fichinter;
1362 $line->desc = $objp->description;
1363 $line->duration = $objp->duree;
1365 $line->qty = round($objp->duree / 3600, 2);
1366 $line->date = $this->
db->jdate($objp->date);
1367 $line->datei = $this->
db->jdate($objp->date);
1368 $line->rang = $objp->rang;
1369 $line->product_type = 1;
1370 $line->fetch_optionals();
1372 $this->lines[$i] = $line;
1380 $this->error = $this->
db->error();
1422 public $fk_fichinter;
1432 public $element =
'fichinterdet';
1437 public $table_element =
'fichinterdet';
1442 public $fk_element =
'fk_fichinter';
1462 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang,';
1463 $sql .=
' ft.date as datei';
1464 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1465 $sql .=
' WHERE ft.rowid = '.$rowid;
1467 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1468 $result = $this->
db->query($sql);
1471 $objp = $this->
db->fetch_object($result);
1472 $this->
rowid = $objp->rowid;
1473 $this->
id = $objp->rowid;
1474 $this->fk_fichinter = $objp->fk_fichinter;
1475 $this->datei = $this->
db->jdate($objp->datei);
1476 $this->desc = $objp->description;
1477 $this->duration = $objp->duree;
1478 $this->rang = $objp->rang;
1480 $this->
db->free($result);
1483 $this->error = $this->
db->error().
' sql='.$sql;
1495 public function insert($user, $notrigger = 0)
1497 global $langs, $conf;
1501 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1505 $rangToUse = $this->rang;
1506 if ($rangToUse == -1)
1509 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1510 $sql .=
' WHERE fk_fichinter ='.$this->fk_fichinter;
1514 $obj = $this->
db->fetch_object(
$resql);
1515 $rangToUse = $obj->max + 1;
1518 $this->
db->rollback();
1524 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1525 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1526 $sql .=
" VALUES (".$this->fk_fichinter.
",";
1527 $sql .=
" '".$this->db->escape($this->desc).
"',";
1528 $sql .=
" '".$this->db->idate($this->datei).
"',";
1529 $sql .=
" ".$this->duration.
",";
1530 $sql .=
' '.$rangToUse;
1533 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1537 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1538 $this->
rowid = $this->id;
1554 $this->rang = $rangToUse;
1559 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1560 if ($result < 0) { $error++; }
1566 $this->
db->commit();
1569 $this->
db->rollback();
1573 $this->error = $this->
db->error().
" sql=".$sql;
1574 $this->
db->rollback();
1587 public function update($user, $notrigger = 0)
1589 global $langs, $conf;
1596 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1597 $sql .=
" description='".$this->db->escape($this->desc).
"'";
1598 $sql .=
",date='".$this->db->idate($this->datei).
"'";
1599 $sql .=
",duree=".$this->duration;
1600 $sql .=
",rang='".$this->db->escape($this->rang).
"'";
1601 $sql .=
" WHERE rowid = ".$this->id;
1603 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1622 $result = $this->
call_trigger(
'LINEFICHINTER_UPDATE', $user);
1623 if ($result < 0) { $error++; }
1630 $this->
db->commit();
1633 $this->error = $this->
db->lasterror();
1634 $this->
db->rollback();
1638 $this->error = $this->
db->lasterror();
1639 $this->
db->rollback();
1657 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1658 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1659 $sql .=
" WHERE fk_fichinter=".$this->fk_fichinter;
1661 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1665 $obj = $this->
db->fetch_object(
$resql);
1666 $total_duration = 0;
1667 if (!empty($obj->total_duration)) $total_duration = $obj->total_duration;
1669 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1670 $sql .=
" SET duree = ".$total_duration;
1671 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->idate($obj->dateo).
"'" :
"null");
1672 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->idate($obj->datee).
"'" :
"null");
1673 $sql .=
" WHERE rowid = ".$this->fk_fichinter;
1675 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1679 $this->
db->commit();
1682 $this->error = $this->
db->error();
1683 $this->
db->rollback();
1687 $this->error = $this->
db->error();
1688 $this->
db->rollback();
1702 global $langs, $conf;
1708 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1714 $this->
db->rollback();
1718 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".$this->id;
1729 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1730 if ($result < 0) { $error++; $this->
db->rollback();
return -1; }
1734 $this->
db->commit();
1737 $this->
db->rollback();
1741 $this->error = $this->
db->error().
" sql=".$sql;
1742 $this->
db->rollback();
getLibStatut($mode=0)
Returns the label status.
getAmount()
Returns amount based on user thm.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
info($id)
Load information on object.
setDraft($user)
Set status to draft.
deleteline($user, $notrigger=0)
Delete a intervention line.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options= '')
Adding a line of intervention into data base.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
create($user, $notrigger=0)
Create an intervention into data base.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
dol_delete_preview($object)
Delete all preview files linked to object instance.
delete_linked_contact($source= '', $code= '')
Delete all links between an object $this and all its contacts.
Class to manage Dolibarr users.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
Class to manage Dolibarr database access.
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
update($user, $notrigger=0)
Update an intervention.
const STATUS_DRAFT
Draft status.
set_date_delivery($user, $date_delivery)
Defines a delivery date of intervention.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
const STATUS_VALIDATED
Validated status.
getNextNumRef($soc)
Returns the next non used reference of intervention depending on the module numbering assets within F...
$conf db
API class for accounts.
initAsSpecimen()
Initialise an instance with random values.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
__construct($db)
Constructor.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
set_contrat($user, $contractid)
Link intervention to a contract.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
update($user, $notrigger=0)
Update intervention into database.
deleteEcmFiles($mode=0)
Delete related files of object in database.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
set_description($user, $description)
Define the label of the intervention.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=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)
Remove a file or several files with a mask.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
const STATUS_CLOSED
Closed.
fetch_lines()
Load array lines ->lines.
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...
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '')
Delete all links between an object $this.
LibStatut($status, $mode=0)
Returns the label of a status.
print $_SERVER["PHP_SELF"]
Edit parameters.
setValid($user, $notrigger=0)
Validate a intervention.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage intervention lines.
insert($user, $notrigger=0)
Insert the line into database.
const STATUS_BILLED
Billed.
update_total()
Update total duration into llx_fichinter.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
fetch($rowid)
Retrieve the line of intervention.
load_state_board()
Load indicators into this->nb for board.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
getNomUrl($withpicto=0, $option= '', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
fetch($rowid, $ref= '')
Fetch a intervention.