34require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
44 public $element =
'fichinterrec';
45 public $table_element =
'fichinter_rec';
46 public $table_element_line =
'fichinterdet_rec';
52 public $TRIGGER_PREFIX =
'FICHINTERREC';
62 public $picto =
'intervention';
72 public $auto_validate;
87 public $unit_frequency;
97 public $date_last_gen;
122 public $special_code;
127 public $usenewprice = 0;
139 $this->labelStatus[0] =
'Draft';
140 $this->labelStatus[1] =
'Closed';
142 $this->labelStatusShort[0] =
'Draft';
143 $this->labelStatusShort[1] =
'Closed';
165 public function create($user, $notrigger = 0)
173 $this->title = trim($this->title);
182 $result = $fichintsrc->fetch($this->id_origin);
184 $result = $fichintsrc->fetch_lines();
188 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
194 $sql .=
", description";
195 $sql .=
", note_private";
196 $sql .=
", note_public";
197 $sql .=
", fk_user_author";
198 $sql .=
", fk_projet";
199 $sql .=
", fk_contrat";
200 $sql .=
", modelpdf";
201 $sql .=
", frequency";
202 $sql .=
", unit_frequency";
203 $sql .=
", date_when";
204 $sql .=
", date_last_gen";
205 $sql .=
", nb_gen_done";
206 $sql .=
", nb_gen_max";
208 $sql .=
") VALUES (";
209 $sql .=
"'".$this->db->escape($this->title).
"'";
210 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
'null');
211 $sql .=
", ".((int)
$conf->entity);
212 $sql .=
", '".$this->db->idate($now).
"'";
213 $sql .=
", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) :
'0');
215 $sql .=
", ".(!empty($fichintsrc->note_private) ? (
"'".$this->db->escape($fichintsrc->note_private).
"'") :
"null");
216 $sql .=
", ".(!empty($fichintsrc->note_public) ? (
"'".$this->db->escape($fichintsrc->note_public).
"'") :
"null");
217 $sql .=
", ".((int) $user->id);
219 if ($this->socid == $fichintsrc->socid) {
220 $sql .=
", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) :
"null");
221 $sql .=
", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) :
"null");
223 $sql .=
", null, null";
226 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
229 $sql .=
", ".(!empty($this->frequency) ? ((int) $this->frequency) :
"null");
230 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
231 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'null');
232 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'null');
234 $sql .=
", ".((int) $this->nb_gen_max);
238 if ($this->db->query($sql)) {
239 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
244 $num = count($fichintsrc->lines);
245 for ($i = 0; $i < $num; $i++) {
247 $fichintsrc->lines[$i]->desc,
248 $fichintsrc->lines[$i]->duration,
249 $fichintsrc->lines[$i]->date,
250 $fichintsrc->lines[$i]->rang,
251 $fichintsrc->lines[$i]->subprice,
252 $fichintsrc->lines[$i]->qty,
253 $fichintsrc->lines[$i]->tva_tx,
254 $fichintsrc->lines[$i]->fk_product,
255 $fichintsrc->lines[$i]->remise_percent,
260 $fichintsrc->lines[$i]->product_type,
261 $fichintsrc->lines[$i]->special_code,
262 !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label :
"",
263 (
string) $fichintsrc->lines[$i]->fk_unit
266 if ($result_insert < 0) {
271 if (!$error && !$notrigger) {
273 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_CREATE', $user);
281 $this->db->rollback();
288 $this->error = $this->db->error().
' sql='.$sql;
289 $this->db->rollback();
293 $this->db->rollback();
307 public function fetch($rowid = 0, $ref =
'', $ref_ext =
'')
309 $sql =
'SELECT f.title, f.fk_soc';
310 $sql .=
', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
311 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
312 $sql .=
', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
313 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
314 $sql .=
', f.status';
315 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinter_rec as f';
317 $sql .=
" WHERE f.rowid = ".((int) $rowid);
319 $sql .=
" WHERE f.title = '".$this->db->escape($ref).
"'";
322 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
324 $result = $this->db->query($sql);
326 if ($this->db->num_rows($result)) {
327 $obj = $this->db->fetch_object($result);
330 $this->title = $obj->title;
331 $this->
ref = $obj->title;
333 $this->datec = $obj->datec;
334 $this->duration = $obj->duree;
335 $this->socid = $obj->fk_soc;
336 $this->
status = $obj->status;
337 $this->statut = $obj->status;
338 $this->fk_project = $obj->fk_projet;
339 $this->fk_contrat = $obj->fk_contrat;
340 $this->note_private = $obj->note_private;
341 $this->note_public = $obj->note_public;
342 $this->user_author_id = $obj->fk_user_author;
343 $this->model_pdf = empty($obj->model_pdf) ?
"" : $obj->model_pdf;
344 $this->rang = !empty($obj->rang) ? $obj->rang :
"";
345 $this->special_code = !empty($obj->special_code) ? $obj->special_code :
"";
346 $this->frequency = $obj->frequency;
347 $this->unit_frequency = $obj->unit_frequency;
348 $this->date_when = $this->db->jdate($obj->date_when);
349 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
350 $this->nb_gen_done = $obj->nb_gen_done;
351 $this->nb_gen_max = $obj->nb_gen_max;
352 $this->auto_validate = $obj->auto_validate;
357 $this->error = $this->db->error();
362 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
363 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
367 $this->error = $this->db->error();
383 $this->lines = array();
385 $sql =
'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
386 $sql .=
' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
387 $sql .=
' l.total_ht, l.total_tva, l.total_ttc,';
388 $sql .=
' l.rang, l.special_code,';
389 $sql .=
' l.fk_unit, l.extraparams, p.ref as product_ref, p.fk_product_type as fk_product_type,';
390 $sql .=
' p.label as product_label, p.description as product_desc';
391 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet_rec as l';
392 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
393 $sql .=
' WHERE l.fk_fichinter = '.((int) $this->
id);
395 dol_syslog(
'FichinterRec::fetch_lines', LOG_DEBUG);
397 $result = $this->db->query($sql);
399 $num = $this->db->num_rows($result);
402 $objp = $this->db->fetch_object($result);
405 $line->id = $objp->rowid;
406 $line->label = $objp->custom_label;
407 $line->desc = $objp->description;
408 $line->product_type = $objp->product_type;
409 $line->product_ref = $objp->product_ref;
410 $line->product_label = $objp->product_label;
411 $line->product_desc = $objp->product_desc;
412 $line->fk_product_type = $objp->fk_product_type;
413 $line->qty = $objp->qty;
414 $line->duree = $objp->duree;
415 $line->duration = $objp->duree;
416 $line->date = $objp->date;
417 $line->subprice = $objp->subprice;
418 $line->tva_tx = $objp->tva_tx;
419 $line->remise_percent = $objp->remise_percent;
420 $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except :
"";
421 $line->fk_product = $objp->fk_product;
422 $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits :
"";
423 $line->total_ht = $objp->total_ht;
424 $line->total_tva = $objp->total_tva;
425 $line->total_ttc = $objp->total_ttc;
426 $line->rang = $objp->rang;
427 $line->special_code = $objp->special_code;
428 $line->fk_unit = $objp->fk_unit;
430 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
432 $this->lines[$i] = $line;
437 $this->db->free($result);
440 $this->error = $this->db->error();
453 public function delete(
User $user, $notrigger = 0)
457 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
462 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
464 if ($this->db->query($sql)) {
465 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".((int) $rowid);
467 if (!$this->db->query($sql)) {
468 $this->error = $this->db->lasterror();
472 $this->error = $this->db->lasterror();
476 if (!$error && !$notrigger) {
478 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_DELETE', $user);
489 $this->db->rollback();
517 public function addLineRec($desc, $duration, $date, $rang = -1, $pu_ht = 0, $qty = 0, $txtva = 0, $fk_product = 0, $remise_percent = 0, $price_base_type =
'HT', $info_bits = 0, $fk_remise_except = 0, $pu_ttc = 0, $type = 0, $special_code = 0, $label =
'', $fk_unit =
null)
521 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
525 $this->error =
'Bad value for parameter type';
529 if ($this->
status == self::STATUS_DRAFT) {
531 $remise_percent =
price2num($remise_percent);
541 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
545 if ($price_base_type ==
'HT') {
554 $tabprice =
calcul_price_total($qty, (
float) $pu, (
float) $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type,
$mysoc);
556 $total_ht = $tabprice[0];
557 $total_tva = $tabprice[1];
558 $total_ttc = $tabprice[2];
560 $pu_ht = $tabprice[3];
562 $product_type = $type;
564 $product =
new Product($this->db);
565 $result = $product->fetch($fk_product);
566 $product_type = $product->type;
569 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
570 $sql .=
"fk_fichinter";
572 $sql .=
", description";
578 $sql .=
", fk_product";
579 $sql .=
", product_type";
580 $sql .=
", remise_percent";
581 $sql .=
", subprice";
582 $sql .=
", total_ht";
583 $sql .=
", total_tva";
584 $sql .=
", total_ttc";
588 $sql .=
") VALUES (";
589 $sql .= (int) $this->
id;
590 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
591 $sql .=
", ".(!empty($desc) ?
"'".$this->db->escape($desc).
"'" :
"null");
592 $sql .=
", ".(!empty($date) ?
"'".$this->db->idate($date).
"'" :
"null");
593 $sql .=
", ".((int) $duration);
596 $sql .=
", ".(!empty($fk_product) ? ((int) $fk_product) :
"null");
597 $sql .=
", ".((int) $product_type);
598 $sql .=
", ".(!empty($remise_percent) ? ((float) $remise_percent) :
"null");
599 $sql .=
", '".price2num($pu_ht).
"'";
600 $sql .=
", '".price2num($total_ht).
"'";
601 $sql .=
", '".price2num($total_tva).
"'";
602 $sql .=
", '".price2num($total_ttc).
"'";
603 $sql .=
", ".(int) $rang;
605 $sql .=
", ".(!empty($fk_unit) ? ((int) $fk_unit) :
"null");
608 dol_syslog(get_class($this).
"::addLineRec", LOG_DEBUG);
609 if ($this->db->query($sql)) {
612 $this->error = $this->db->lasterror();
616 $this->error =
'Bad status of recurring intervention. Must be draft status to allow addition of lines';
632 public function set_auto($user, $freq, $courant, $notrigger = 0)
635 if ($user->hasRight(
'fichinter',
'creer')) {
636 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter_rec ";
637 $sql .=
" SET frequency='".$this->db->escape((
string) $freq).
"'";
638 $sql .=
", date_last_gen='".$this->db->escape($courant).
"'";
639 $sql .=
" WHERE rowid = ".((int) $this->
id);
641 $resql = $this->db->query($sql);
644 $this->frequency = $freq;
645 $this->date_last_gen = $courant;
649 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
676 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
678 global $action, $langs, $hookmanager;
681 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
683 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
689 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
693 $result .= $link.img_object($label, $this->picto,
'class="classfortooltip"').$linkend;
695 if ($withpicto && $withpicto != 2) {
698 if ($withpicto != 2) {
699 $result .= $link.$this->ref.$linkend;
702 $hookmanager->initHooks(array($this->element .
'dao'));
703 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
704 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
706 $result = $hookmanager->resPrint;
708 $result .= $hookmanager->resPrint;
728 parent::initAsSpecimen();
730 $this->usenewprice = 1;
745 $tables = array(
'fichinter_rec');
779 if (!$this->table_element) {
780 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
784 if (!empty($frequency) && empty($unit)) {
785 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
789 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
790 $sql .=
' SET frequency = '.($frequency ? $this->db->escape((
string) $frequency) :
'null');
792 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
794 $sql .=
" WHERE rowid = ".((int) $this->
id);
796 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
797 if ($this->db->query($sql)) {
798 $this->frequency = $frequency;
800 $this->unit_frequency = $unit;
805 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
827 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
831 if (!$this->table_element) {
832 dol_syslog(get_class($this).
"::setNextDate was called on object with property table_element not defined", LOG_ERR);
835 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
836 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
837 if ($increment_nb_gen_done > 0) {
838 $sql .=
', nb_gen_done = nb_gen_done + 1';
840 $sql .=
" WHERE rowid = ".((int) $this->
id);
842 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
843 if ($this->db->query($sql)) {
844 $this->date_when = $date;
845 if ($increment_nb_gen_done > 0) {
846 $this->nb_gen_done++;
851 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
876 if (!$this->table_element) {
877 dol_syslog(get_class($this).
"::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
885 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
886 $sql .=
' SET nb_gen_max = '.((int) $nb);
887 $sql .=
' WHERE rowid = '.((int) $this->
id);
889 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
890 if ($this->db->query($sql)) {
891 $this->nb_gen_max = $nb;
895 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
920 if (!$this->table_element) {
921 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
925 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
926 $sql .=
' SET auto_validate = '.((int) $validate);
927 $sql .=
' WHERE rowid = '.((int) $this->
id);
929 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
930 if ($this->db->query($sql)) {
931 $this->auto_validate = $validate;
935 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
959 if (!$this->table_element) {
960 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
964 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
965 $sql .=
' SET nb_gen_done = nb_gen_done + 1';
966 $sql .=
' , date_last_gen = now()';
968 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
969 $sql .=
' , status = 1';
972 $sql .=
" WHERE rowid = ".((int) $this->
id);
974 dol_syslog(get_class($this).
"::updateNbGenDone", LOG_DEBUG);
975 if ($this->db->query($sql)) {
976 $this->nb_gen_done++;
977 $this->date_last_gen =
dol_now();
982 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_MODIFY', $user);
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
Class to manage Dolibarr database access.
LibStatut($status, $mode=0)
Returns the label of a status.
fetch_lines()
Load array lines ->lines.
Class to manage intervention lines.
Class to manage recurring interventions.
fetch($rowid=0, $ref='', $ref_ext='')
Get the template of intervention object and lines.
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='')
Return clickable name (with picto eventually)
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
set_auto($user, $freq, $courant, $notrigger=0)
Rend la fichinter automatique.
create($user, $notrigger=0)
Create a predefined fichinter.
updateNbGenDone($notrigger=0)
Update the Number of Generation Done.
getLibStatut($mode=0)
Returns the label status.
__construct($db)
Constructor.
addLineRec($desc, $duration, $date, $rang=-1, $pu_ht=0, $qty=0, $txtva=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except=0, $pu_ttc=0, $type=0, $special_code=0, $label='', $fk_unit=null)
Add line to a recurring intervention.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
setAutoValidate($validate, $notrigger=0)
Update the auto validate fichinter.
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
Class to manage products or services.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.