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'=>
'$conf->societe->enabled',
'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'=>
'text',
'label'=>
'Description',
'enabled'=>1,
'visible'=>-1,
'position'=>105,
'showoncombobox'=>2),
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),
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').
")";
223 while ($obj = $this->
db->fetch_object(
$resql)) {
224 $this->nb[
"interventions"] = $obj->nb;
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);
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 ";
396 $sql .=
"description = '".$this->db->escape($this->
description).
"'";
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);
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;
505 $this->error = $this->
db->lasterror();
518 global $langs, $conf;
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);
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);
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;
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);
680 $this->author =
new User($db);
681 $this->author->fetch($this->user_creation);
683 $thm = $this->author->thm;
685 foreach ($this->lines as $line) {
686 $amount += ($line->duration / 60 / 60 * $thm);
704 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
708 $outputlangs->load(
"interventions");
713 if (!empty($this->model_pdf)) {
714 $modele = $this->model_pdf;
715 } elseif (!empty($this->modelpdf)) {
716 $modele = $this->modelpdf;
717 } elseif (!empty($conf->global->FICHEINTER_ADDON_PDF)) {
718 $modele = $conf->global->FICHEINTER_ADDON_PDF;
722 $modelpath =
"core/modules/fichinter/doc/";
724 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
735 return $this->
LibStatut((isset($this->statut) ? $this->statut : $this->status), $mode);
750 if (empty($this->statuts) || empty($this->statuts_short) || empty($this->statuts_logo)) {
752 $langs->load(
"fichinter");
756 $this->statuts[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
760 $this->statuts_short[
self::STATUS_BILLED] = $langs->transnoentitiesnoconv(
'StatusInterInvoiced');
768 return dolGetStatus($this->statuts[$status], $this->statuts_short[$status],
'', $this->statuts_logo[$status], $mode);
780 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1)
782 global $conf, $langs, $hookmanager;
786 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Intervention").
'</u>';
787 if (isset($this->status)) {
788 $label .=
' '.$this->getLibStatut(5);
790 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
792 $url = DOL_URL_ROOT.
'/fichinter/card.php?id='.$this->id;
794 if ($option !==
'nolink') {
796 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
797 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
798 $add_save_lastsearch_values = 1;
800 if ($add_save_lastsearch_values) {
801 $url .=
'&save_lastsearch_values=1';
806 if (empty($notooltip)) {
807 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
808 $label = $langs->trans(
"ShowIntervention");
809 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
811 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
812 $linkclose .=
' class="classfortooltip"';
822 $linkstart =
'<a href="'.$url.
'"';
823 $linkstart .= $linkclose.
'>';
826 $result .= $linkstart;
828 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
830 if ($withpicto != 2) {
831 $result .= $this->ref;
836 $hookmanager->initHooks(array(
'interventiondao'));
837 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
838 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
840 $result = $hookmanager->resPrint;
842 $result .= $hookmanager->resPrint;
858 global $conf, $db, $langs;
859 $langs->load(
"interventions");
861 if (!empty($conf->global->FICHEINTER_ADDON)) {
864 $file =
"mod_".$conf->global->FICHEINTER_ADDON.
".php";
865 $classname =
"mod_".$conf->global->FICHEINTER_ADDON;
868 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
870 foreach ($dirmodels as $reldir) {
874 $mybool |= @include_once $dir.$file;
877 if ($mybool ===
false) {
882 $obj =
new $classname();
884 $numref = $obj->getNextValue($soc, $this);
893 $langs->load(
"errors");
894 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_FICHEINTER_ADDON_NotDefined");
909 $sql =
"SELECT f.rowid,";
911 $sql .=
" f.tms as date_modification,";
912 $sql .=
" f.date_valid as datev,";
913 $sql .=
" f.fk_user_author,";
914 $sql .=
" f.fk_user_modif as fk_user_modification,";
915 $sql .=
" f.fk_user_valid";
916 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinter as f";
917 $sql .=
" WHERE f.rowid = ".((int) $id);
922 $obj = $this->
db->fetch_object(
$resql);
924 $this->
id = $obj->rowid;
926 $this->date_creation = $this->
db->jdate($obj->datec);
927 $this->date_modification = $this->
db->jdate($obj->date_modification);
928 $this->date_validation = $this->
db->jdate($obj->datev);
930 $cuser =
new User($this->
db);
931 $cuser->fetch($obj->fk_user_author);
932 $this->user_creation = $cuser;
934 if ($obj->fk_user_valid) {
935 $vuser =
new User($this->
db);
936 $vuser->fetch($obj->fk_user_valid);
937 $this->user_validation = $vuser;
939 if ($obj->fk_user_modification) {
940 $muser =
new User($this->
db);
941 $muser->fetch($obj->fk_user_modification);
942 $this->user_modification = $muser;
958 public function delete(
User $user, $notrigger = 0)
960 global $conf, $langs;
961 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
967 if (!$error && !$notrigger) {
969 $result = $this->
call_trigger(
'FICHINTER_DELETE', $user);
971 $error++; $this->
db->rollback();
return -1;
988 $this->error =
'ErrorFailToDeleteLinkedContact';
994 $main = MAIN_DB_PREFIX.
'fichinterdet';
995 $ef = $main.
"_extrafields";
996 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_fichinter = ".((int) $this->
id).
")";
1005 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1006 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1024 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter";
1025 $sql .=
" WHERE rowid = ".((int) $this->
id);
1040 if ($conf->ficheinter->dir_output) {
1041 $dir = $conf->ficheinter->dir_output.
"/".$fichinterref;
1042 $file = $conf->ficheinter->dir_output.
"/".$fichinterref.
"/".$fichinterref.
".pdf";
1043 if (file_exists($file)) {
1047 $langs->load(
"errors");
1048 $this->error = $langs->trans(
"ErrorFailToDeleteFile", $file);
1052 if (file_exists($dir)) {
1054 $langs->load(
"errors");
1055 $this->error = $langs->trans(
"ErrorFailToDeleteDir", $dir);
1063 $this->
db->commit();
1066 $this->
db->rollback();
1084 if ($user->rights->ficheinter->creer) {
1085 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1086 $sql .=
" SET datei = '".$this->db->idate($date_delivery).
"'";
1087 $sql .=
" WHERE rowid = ".((int) $this->
id);
1088 $sql .=
" AND fk_statut = 0";
1090 if ($this->
db->query($sql)) {
1091 $this->date_delivery = $date_delivery;
1094 $this->error = $this->
db->error();
1095 dol_syslog(
"Fichinter::set_date_delivery Erreur SQL");
1114 if ($user->rights->ficheinter->creer) {
1115 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1116 $sql .=
" SET description = '".$this->db->escape($description).
"',";
1117 $sql .=
" fk_user_modif = ".$user->id;
1118 $sql .=
" WHERE rowid = ".((int) $this->
id);
1120 if ($this->
db->query($sql)) {
1124 $this->error = $this->
db->error();
1125 dol_syslog(
"Fichinter::set_description Erreur SQL");
1145 if ($user->rights->ficheinter->creer) {
1146 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter ";
1147 $sql .=
" SET fk_contrat = ".((int) $contractid);
1148 $sql .=
" WHERE rowid = ".((int) $this->
id);
1150 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();
1184 $objFrom = clone $this;
1187 if (!empty($socid) && $socid != $this->socid) {
1190 if ($objsoc->fetch($socid) > 0) {
1191 $this->socid = $objsoc->id;
1194 $this->fk_project =
'';
1195 $this->fk_delivery_address =
'';
1206 $this->user_author_id = $user->id;
1207 $this->user_valid = 0;
1208 $this->date_creation =
'';
1209 $this->date_validation =
'';
1210 $this->ref_client =
'';
1213 $this->context[
'createfromclone'] =
'createfromclone';
1214 $result = $this->
create($user);
1221 foreach ($this->lines as $line) {
1222 $this->
addline($user, $this->
id, $line->desc, $line->datei, $line->duration, $line->array_options);
1226 if (is_object($hookmanager)) {
1227 $parameters = array(
'objFrom'=>$objFrom);
1229 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1236 unset($this->context[
'createfromclone']);
1240 $this->
db->commit();
1243 $this->
db->rollback();
1260 public function addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options =
'')
1262 dol_syslog(get_class($this).
"::addline $fichinterid, $desc, $date_intervention, $duration");
1264 if ($this->statut == 0) {
1270 $line->fk_fichinter = $fichinterid;
1271 $line->desc = $desc;
1272 $line->date = $date_intervention;
1273 $line->datei = $date_intervention;
1274 $line->duration = $duration;
1276 if (is_array($array_options) && count($array_options) > 0) {
1277 $line->array_options = $array_options;
1280 $result = $line->insert($user);
1283 $this->
db->commit();
1286 $this->error = $this->
db->error();
1287 $this->
db->rollback();
1309 $this->
ref =
'SPECIMEN';
1310 $this->ref_client =
'SPECIMEN CLIENT';
1311 $this->specimen = 1;
1313 $this->datec = $now;
1314 $this->note_private =
'Private note';
1315 $this->note_public =
'SPECIMEN';
1316 $this->duration = 0;
1319 while ($xnbp < $nbp) {
1321 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
1322 $line->date = ($now - 3600 * (1 + $xnbp));
1323 $line->datei = ($now - 3600 * (1 + $xnbp));
1324 $line->duration = 600;
1325 $line->fk_fichinter = 0;
1326 $this->lines[$xnbp] = $line;
1329 $this->duration += $line->duration;
1342 $this->lines = array();
1344 $sql =
"SELECT rowid, fk_fichinter, description, duree, date, rang";
1345 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1346 $sql .=
" WHERE fk_fichinter = ".((int) $this->
id);
1347 $sql .=
" ORDER BY rang ASC, date ASC";
1349 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
1353 $num = $this->
db->num_rows(
$resql);
1356 $objp = $this->
db->fetch_object(
$resql);
1359 $line->id = $objp->rowid;
1360 $line->fk_fichinter = $objp->fk_fichinter;
1361 $line->desc = $objp->description;
1362 $line->duration = $objp->duree;
1364 $line->qty = round($objp->duree / 3600, 2);
1365 $line->date = $this->
db->jdate($objp->date);
1366 $line->datei = $this->
db->jdate($objp->date);
1367 $line->rang = $objp->rang;
1368 $line->product_type = 1;
1369 $line->fetch_optionals();
1371 $this->lines[$i] = $line;
1378 $this->error = $this->
db->error();
1411 if (!empty($user->rights->ficheinter->creer)) {
1418 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET ref_client = ".(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
1419 $sql .=
" WHERE rowid = ".((int) $this->
id);
1421 dol_syslog(__METHOD__.
' $this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
1424 $this->errors[] = $this->
db->error();
1429 $this->ref_client = $ref_client;
1432 if (!$notrigger && empty($error)) {
1434 $result = $this->
call_trigger(
'FICHINTER_MODIFY', $user);
1442 $this->
db->commit();
1445 foreach ($this->errors as $errmsg) {
1446 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
1447 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1449 $this->
db->rollback();
1477 public $fk_fichinter;
1499 public $element =
'fichinterdet';
1504 public $table_element =
'fichinterdet';
1509 public $fk_element =
'fk_fichinter';
1531 $sql =
'SELECT ft.rowid, ft.fk_fichinter, ft.description, ft.duree, ft.rang, ft.date';
1532 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet as ft';
1533 $sql .=
' WHERE ft.rowid = '.((int) $rowid);
1535 dol_syslog(
"FichinterLigne::fetch", LOG_DEBUG);
1536 $result = $this->
db->query($sql);
1538 $objp = $this->
db->fetch_object($result);
1539 $this->
rowid = $objp->rowid;
1540 $this->
id = $objp->rowid;
1541 $this->fk_fichinter = $objp->fk_fichinter;
1542 $this->date = $this->
db->jdate($objp->date);
1543 $this->datei = $this->
db->jdate($objp->date);
1544 $this->desc = $objp->description;
1545 $this->duration = $objp->duree;
1546 $this->rang = $objp->rang;
1548 $this->
db->free($result);
1551 $this->error = $this->
db->error().
' sql='.$sql;
1563 public function insert($user, $notrigger = 0)
1565 global $langs, $conf;
1569 dol_syslog(
"FichinterLigne::insert rang=".$this->rang);
1571 if (empty($this->date) && !empty($this->datei)) {
1572 $this->date = $this->datei;
1577 $rangToUse = $this->rang;
1578 if ($rangToUse == -1) {
1580 $sql =
'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.
'fichinterdet';
1581 $sql .=
' WHERE fk_fichinter = '.((int) $this->fk_fichinter);
1584 $obj = $this->
db->fetch_object(
$resql);
1585 $rangToUse = $obj->max + 1;
1588 $this->
db->rollback();
1594 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'fichinterdet';
1595 $sql .=
' (fk_fichinter, description, date, duree, rang)';
1596 $sql .=
" VALUES (".((int) $this->fk_fichinter).
",";
1597 $sql .=
" '".$this->db->escape($this->desc).
"',";
1598 $sql .=
" '".$this->db->idate($this->date).
"',";
1599 $sql .=
" ".((int) $this->duration).
",";
1600 $sql .=
' '.((int) $rangToUse);
1603 dol_syslog(
"FichinterLigne::insert", LOG_DEBUG);
1606 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'fichinterdet');
1607 $this->
rowid = $this->id;
1620 $this->rang = $rangToUse;
1624 $result = $this->
call_trigger(
'LINEFICHINTER_CREATE', $user);
1633 $this->
db->commit();
1636 $this->
db->rollback();
1640 $this->error = $this->
db->error().
" sql=".$sql;
1641 $this->
db->rollback();
1654 public function update($user, $notrigger = 0)
1656 global $langs, $conf;
1660 if (empty($this->date) && !empty($this->datei)) {
1661 $this->date = $this->datei;
1667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinterdet SET";
1668 $sql .=
" description = '".$this->db->escape($this->desc).
"',";
1669 $sql .=
" date = '".$this->db->idate($this->date).
"',";
1670 $sql .=
" duree = ".((int) $this->duration).
",";
1671 $sql .=
" rang = ".((int) $this->rang);
1672 $sql .=
" WHERE rowid = ".((int) $this->
id);
1674 dol_syslog(
"FichinterLigne::update", LOG_DEBUG);
1688 $result = $this->
call_trigger(
'LINEFICHINTER_MODIFY', $user);
1697 $this->
db->commit();
1700 $this->error = $this->
db->lasterror();
1701 $this->
db->rollback();
1705 $this->error = $this->
db->lasterror();
1706 $this->
db->rollback();
1724 $sql =
"SELECT SUM(duree) as total_duration, min(date) as dateo, max(date) as datee ";
1725 $sql .=
" FROM ".MAIN_DB_PREFIX.
"fichinterdet";
1726 $sql .=
" WHERE fk_fichinter=".((int) $this->fk_fichinter);
1728 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1731 $obj = $this->
db->fetch_object(
$resql);
1732 $total_duration = 0;
1733 if (!empty($obj->total_duration)) {
1734 $total_duration = $obj->total_duration;
1737 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter";
1738 $sql .=
" SET duree = ".((int) $total_duration);
1739 $sql .=
" , dateo = ".(!empty($obj->dateo) ?
"'".$this->db->idate($obj->dateo).
"'" :
"null");
1740 $sql .=
" , datee = ".(!empty($obj->datee) ?
"'".$this->db->idate($obj->datee).
"'" :
"null");
1741 $sql .=
" WHERE rowid = ".((int) $this->fk_fichinter);
1743 dol_syslog(
"FichinterLigne::update_total", LOG_DEBUG);
1746 $this->
db->commit();
1749 $this->error = $this->
db->error();
1750 $this->
db->rollback();
1754 $this->error = $this->
db->error();
1755 $this->
db->rollback();
1769 global $langs, $conf;
1773 if ($this->statut == 0) {
1774 dol_syslog(get_class($this).
"::deleteline lineid=".$this->
id);
1780 $this->
db->rollback();
1784 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet WHERE rowid = ".((int) $this->
id);
1792 $result = $this->
call_trigger(
'LINEFICHINTER_DELETE', $user);
1794 $error++; $this->
db->rollback();
return -1;
1799 $this->
db->commit();
1802 $this->
db->rollback();
1806 $this->error = $this->
db->error().
" sql=".$sql;
1807 $this->
db->rollback();
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.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check an object id/ref exists If you don't need/want to instantiate object and just need to know if o...
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Dolibarr database access.
Class to manage interventions.
const STATUS_BILLED
Billed.
addline($user, $fichinterid, $desc, $date_intervention, $duration, $array_options='')
Adding a line of intervention into data base.
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.
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.
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.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
LibStatut($status, $mode=0)
Returns the label of a status.
setValid($user, $notrigger=0)
Validate a intervention.
load_state_board()
Load indicators into this->nb for board.
__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.
fetch($rowid)
Retrieve the line of intervention.
update_total()
Update total duration into llx_fichinter.
update($user, $notrigger=0)
Update intervention into database.
deleteline($user, $notrigger=0)
Delete a intervention line.
__construct($db)
Constructor.
insert($user, $notrigger=0)
Insert the line into database.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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($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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
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_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
$conf db
API class for accounts.