dolibarr 25.0.0-alpha
fichinterrec.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
5 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2016-2018 Charlie Benke <charlie@patas-monkey.com>
10 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
11 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
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';
37
38
43{
44 public $element = 'fichinterrec';
45 public $table_element = 'fichinter_rec';
46 public $table_element_line = 'fichinterdet_rec';
47
52 public $TRIGGER_PREFIX = 'FICHINTERREC';
53
57 protected $table_ref_field = 'title';
58
62 public $picto = 'intervention';
63
67 public $title;
68
72 public $auto_validate;
73
77 public $frequency;
78
82 public $id_origin;
83
87 public $unit_frequency;
88
92 public $propalid;
93
97 public $date_last_gen;
98
102 public $date_when;
103
107 public $nb_gen_done;
108
112 public $nb_gen_max;
113
117 public $rang;
118
122 public $special_code;
123
127 public $usenewprice = 0;
128
134 public function __construct($db)
135 {
136 $this->db = $db;
137
138 // status in intervention order
139 $this->labelStatus[0] = 'Draft';
140 $this->labelStatus[1] = 'Closed';
141
142 $this->labelStatusShort[0] = 'Draft';
143 $this->labelStatusShort[1] = 'Closed';
144 }
145
152 public function getLibStatut($mode = 0)
153 {
154 return $this->LibStatut($this->status, $mode);
155 }
156
157
165 public function create($user, $notrigger = 0)
166 {
167 global $conf;
168
169 $error = 0;
170 $now = dol_now();
171
172 // Clean parameters
173 $this->title = trim($this->title);
174 $this->description = trim($this->description);
175
176
177 $this->db->begin();
178
179 // Load fichinter model
180 $fichintsrc = new Fichinter($this->db);
181
182 $result = $fichintsrc->fetch($this->id_origin);
183 if ($result > 0) {
184 $result = $fichintsrc->fetch_lines(); // to get all lines
185 }
186
187 if ($result > 0) {
188 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
189 $sql .= "title";
190 $sql .= ", fk_soc";
191 $sql .= ", entity";
192 $sql .= ", datec";
193 $sql .= ", duree";
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";
207 // $sql.= ", auto_validate";
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');
214 $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
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);
218 // If the company is the same, keep the links to the project and the contract
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");
222 } else {
223 $sql .= ", null, null";
224 }
225
226 $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
227
228 // Frequency
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');
233 $sql .= ", 0"; // we start at 0
234 $sql .= ", ".((int) $this->nb_gen_max);
235 // $sql.= ", ".$this->auto_validate;
236 $sql .= ")";
237
238 if ($this->db->query($sql)) {
239 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
240
241 /*
242 * Lines
243 */
244 $num = count($fichintsrc->lines);
245 for ($i = 0; $i < $num; $i++) {
246 $result_insert = $this->addLineRec(
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,
256 'HT',
257 0,
258 0,
259 0,
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
264 );
265
266 if ($result_insert < 0) {
267 $error++;
268 }
269 }
270
271 if (!$error && !$notrigger) {
272 // Call trigger
273 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_CREATE', $user);
274 if ($result < 0) {
275 $error++;
276 }
277 // End call triggers
278 }
279
280 if ($error) {
281 $this->db->rollback();
282 return -1;
283 } else {
284 $this->db->commit();
285 return $this->id;
286 }
287 } else {
288 $this->error = $this->db->error().' sql='.$sql;
289 $this->db->rollback();
290 return -2;
291 }
292 } else {
293 $this->db->rollback();
294 return -1;
295 }
296 }
297
298
307 public function fetch($rowid = 0, $ref = '', $ref_ext = '')
308 {
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';
316 if ($rowid > 0) {
317 $sql .= " WHERE f.rowid = ".((int) $rowid);
318 } elseif ($ref) {
319 $sql .= " WHERE f.title = '".$this->db->escape($ref)."'";
320 }
321
322 dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
323
324 $result = $this->db->query($sql);
325 if ($result) {
326 if ($this->db->num_rows($result)) {
327 $obj = $this->db->fetch_object($result);
328
329 $this->id = $rowid;
330 $this->title = $obj->title;
331 $this->ref = $obj->title;
332 $this->description = $obj->description;
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; // deprecated
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;
353
354 // Lines
355 $result = $this->fetch_lines();
356 if ($result < 0) {
357 $this->error = $this->db->error();
358 return -3;
359 }
360 return 1;
361 } else {
362 $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
363 dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
364 return -2;
365 }
366 } else {
367 $this->error = $this->db->error();
368 return -1;
369 }
370 }
371
372
373 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
380 public function fetch_lines($sall = 0)
381 {
382 // phpcs:enable
383 $this->lines = array();
384
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);
394
395 dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
396
397 $result = $this->db->query($sql);
398 if ($result) {
399 $num = $this->db->num_rows($result);
400 $i = 0;
401 while ($i < $num) {
402 $objp = $this->db->fetch_object($result);
403
404 $line = new FichinterLigne($this->db);
405 $line->id = $objp->rowid;
406 $line->label = $objp->custom_label; // Label line
407 $line->desc = $objp->description; // Description line
408 $line->product_type = $objp->product_type; // Type of line
409 $line->product_ref = $objp->product_ref; // Ref product
410 $line->product_label = $objp->product_label; // Label product
411 $line->product_desc = $objp->product_desc; // Description product
412 $line->fk_product_type = $objp->fk_product_type; // Type in product
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;
429
430 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
431
432 $this->lines[$i] = $line;
433
434 $i++;
435 }
436
437 $this->db->free($result);
438 return 1;
439 } else {
440 $this->error = $this->db->error();
441 return -3;
442 }
443 }
444
445
453 public function delete(User $user, $notrigger = 0)
454 {
455 $rowid = $this->id;
456
457 dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
458
459 $error = 0;
460 $this->db->begin();
461
462 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
463 dol_syslog($sql);
464 if ($this->db->query($sql)) {
465 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
466 dol_syslog($sql);
467 if (!$this->db->query($sql)) {
468 $this->error = $this->db->lasterror();
469 $error = -1;
470 }
471 } else {
472 $this->error = $this->db->lasterror();
473 $error = -2;
474 }
475
476 if (!$error && !$notrigger) {
477 // Call trigger
478 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_DELETE', $user);
479 if ($result < 0) {
480 $error = -3;
481 }
482 // End call triggers
483 }
484
485 if (!$error) {
486 $this->db->commit();
487 return 1;
488 } else {
489 $this->db->rollback();
490 return $error;
491 }
492 }
493
494
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)
518 {
519 global $mysoc;
520
521 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
522
523 // Check parameters
524 if ($type < 0) {
525 $this->error = 'Bad value for parameter type';
526 return -1;
527 }
528
529 if ($this->status == self::STATUS_DRAFT) {
530 // Clean parameters
531 $remise_percent = price2num($remise_percent);
532 $qty = price2num($qty);
533 if (!$qty) {
534 $qty = 1;
535 }
536 if (!$info_bits) {
537 $info_bits = 0;
538 }
539 $pu_ht = price2num($pu_ht);
540 $pu_ttc = price2num($pu_ttc);
541 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
542 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
543 }
544
545 if ($price_base_type == 'HT') {
546 $pu = $pu_ht;
547 } else {
548 $pu = $pu_ttc;
549 }
550
551 // Calculation of the gross total (TTC) and VAT for the line from qty, pu, remise_percent and txtva
552 // VERY IMPORTANT: It's at the time of line insertion that we must store the net, VAT, and gross amounts,
553 // and this is done at the line level, which has its own VAT rate
554 $tabprice = calcul_price_total($qty, (float) $pu, (float) $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
555
556 $total_ht = $tabprice[0];
557 $total_tva = $tabprice[1];
558 $total_ttc = $tabprice[2];
559
560 $pu_ht = $tabprice[3];
561
562 $product_type = $type;
563 if ($fk_product) {
564 $product = new Product($this->db);
565 $result = $product->fetch($fk_product);
566 $product_type = $product->type;
567 }
568
569 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
570 $sql .= "fk_fichinter";
571 $sql .= ", label";
572 $sql .= ", description";
573 $sql .= ", date";
574 $sql .= ", duree";
575 //$sql.= ", price";
576 //$sql.= ", qty";
577 //$sql.= ", tva_tx";
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";
585 $sql .= ", rang";
586 //$sql.= ", special_code";
587 $sql .= ", fk_unit";
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);
594 //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
595 //$sql.= ", ".price2num($txtva);
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;
604 //$sql.= ", ".$special_code;
605 $sql .= ", ".(!empty($fk_unit) ? ((int) $fk_unit) : "null");
606 $sql .= ")";
607
608 dol_syslog(get_class($this)."::addLineRec", LOG_DEBUG);
609 if ($this->db->query($sql)) {
610 return 1;
611 } else {
612 $this->error = $this->db->lasterror();
613 return -1;
614 }
615 } else {
616 $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
617 return -1;
618 }
619 }
620
621
622 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
632 public function set_auto($user, $freq, $courant, $notrigger = 0)
633 {
634 // phpcs:enable
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);
640
641 $resql = $this->db->query($sql);
642
643 if ($resql) {
644 $this->frequency = $freq;
645 $this->date_last_gen = $courant;
646
647 if (!$notrigger) {
648 // Call trigger
649 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
650 if ($result < 0) {
651 return -1;
652 }
653 // End call triggers
654 }
655
656 return 0;
657 } else {
658 dol_print_error($this->db);
659 return -1;
660 }
661 } else {
662 return -2;
663 }
664 }
665
676 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
677 {
678 global $action, $langs, $hookmanager;
679
680 $result = '';
681 $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
682
683 $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
684
685 if ($short) {
686 return $url;
687 }
688
689 $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
690 $linkend = '</a>';
691
692 if ($withpicto) {
693 $result .= $link.img_object($label, $this->picto, 'class="classfortooltip"').$linkend;
694 }
695 if ($withpicto && $withpicto != 2) {
696 $result .= ' ';
697 }
698 if ($withpicto != 2) {
699 $result .= $link.$this->ref.$linkend;
700 }
701
702 $hookmanager->initHooks(array($this->element . 'dao'));
703 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
704 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
705 if ($reshook > 0) {
706 $result = $hookmanager->resPrint;
707 } else {
708 $result .= $hookmanager->resPrint;
709 }
710
711 return $result;
712 }
713
714
722 public function initAsSpecimen()
723 {
724 //$now = dol_now();
725 //$arraynow = dol_getdate($now);
726 //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
727
728 parent::initAsSpecimen();
729
730 $this->usenewprice = 1;
731
732 return 1;
733 }
734
743 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
744 {
745 $tables = array('fichinter_rec');
746
747 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
748 }
749
758 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
759 {
760 $tables = array(
761 'fichinterdet_rec'
762 );
763
764 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
765 }
766
775 public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
776 {
777 global $user;
778
779 if (!$this->table_element) {
780 dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
781 return -1;
782 }
783
784 if (!empty($frequency) && empty($unit)) {
785 dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
786 return -2;
787 }
788
789 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
790 $sql .= ' SET frequency = '.($frequency ? $this->db->escape((string) $frequency) : 'null');
791 if (!empty($unit)) {
792 $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
793 }
794 $sql .= " WHERE rowid = ".((int) $this->id);
795
796 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
797 if ($this->db->query($sql)) {
798 $this->frequency = $frequency;
799 if (!empty($unit)) {
800 $this->unit_frequency = $unit;
801 }
802
803 if (!$notrigger) {
804 // Call trigger
805 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
806 if ($result < 0) {
807 return -1;
808 }
809 // End call triggers
810 }
811
812 return 1;
813 } else {
814 dol_print_error($this->db);
815 return -1;
816 }
817 }
818
827 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
828 {
829 global $user;
830
831 if (!$this->table_element) {
832 dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
833 return -1;
834 }
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';
839 }
840 $sql .= " WHERE rowid = ".((int) $this->id);
841
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++;
847 }
848
849 if (!$notrigger) {
850 // Call trigger
851 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
852 if ($result < 0) {
853 return -1;
854 }
855 // End call triggers
856 }
857
858 return 1;
859 } else {
860 dol_print_error($this->db);
861 return -1;
862 }
863 }
864
872 public function setMaxPeriod($nb, $notrigger = 0)
873 {
874 global $user;
875
876 if (!$this->table_element) {
877 dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
878 return -1;
879 }
880
881 if (empty($nb)) {
882 $nb = 0;
883 }
884
885 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
886 $sql .= ' SET nb_gen_max = '.((int) $nb);
887 $sql .= ' WHERE rowid = '.((int) $this->id);
888
889 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
890 if ($this->db->query($sql)) {
891 $this->nb_gen_max = $nb;
892
893 if (!$notrigger) {
894 // Call trigger
895 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
896 if ($result < 0) {
897 return -1;
898 }
899 // End call triggers
900 }
901
902 return 1;
903 } else {
904 dol_print_error($this->db);
905 return -1;
906 }
907 }
908
916 public function setAutoValidate($validate, $notrigger = 0)
917 {
918 global $user;
919
920 if (!$this->table_element) {
921 dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
922 return -1;
923 }
924
925 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
926 $sql .= ' SET auto_validate = '.((int) $validate);
927 $sql .= ' WHERE rowid = '.((int) $this->id);
928
929 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
930 if ($this->db->query($sql)) {
931 $this->auto_validate = $validate;
932
933 if (!$notrigger) {
934 // Call trigger
935 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
936 if ($result < 0) {
937 return -1;
938 }
939 // End call triggers
940 }
941
942 return 1;
943 } else {
944 dol_print_error($this->db);
945 return -1;
946 }
947 }
948
955 public function updateNbGenDone($notrigger = 0)
956 {
957 global $user;
958
959 if (!$this->table_element) {
960 dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
961 return -1;
962 }
963
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()';
967 // if we have reached the end of the generation cycle
968 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
969 $sql .= ' , status = 1';
970 }
971
972 $sql .= " WHERE rowid = ".((int) $this->id);
973
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();
978 //$this->date_when = ...
979
980 if (!$notrigger) {
981 // Call trigger
982 $result = $this->call_trigger($this->TRIGGER_PREFIX.'_MODIFY', $user);
983 if ($result < 0) {
984 return -1;
985 }
986 // End call triggers
987 }
988
989 return 1;
990 } else {
991 dol_print_error($this->db);
992 return -1;
993 }
994 }
995}
$object ref
Definition info.php:90
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...
Definition index.php:169
global $mysoc
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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...
Definition html.lib.php:172
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.
Definition price.lib.php:90