dolibarr 24.0.0-beta
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-2025 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024-2025 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
51 protected $table_ref_field = 'title';
52
56 public $picto = 'intervention';
57
61 public $title;
62
66 public $auto_validate;
67
71 public $frequency;
72
76 public $id_origin;
77
81 public $unit_frequency;
82
86 public $propalid;
87
91 public $date_last_gen;
92
96 public $date_when;
97
101 public $nb_gen_done;
102
106 public $nb_gen_max;
107
111 public $rang;
112
116 public $special_code;
117
121 public $usenewprice = 0;
122
128 public function __construct($db)
129 {
130 $this->db = $db;
131
132 //status dans l'ordre de l'intervention
133 $this->labelStatus[0] = 'Draft';
134 $this->labelStatus[1] = 'Closed';
135
136 $this->labelStatusShort[0] = 'Draft';
137 $this->labelStatusShort[1] = 'Closed';
138 }
139
146 public function getLibStatut($mode = 0)
147 {
148 return $this->LibStatut($this->status, $mode);
149 }
150
151
159 public function create($user, $notrigger = 0)
160 {
161 global $conf;
162
163 $error = 0;
164 $now = dol_now();
165
166 // Clean parameters
167 $this->title = trim($this->title);
168 $this->description = trim($this->description);
169
170
171 $this->db->begin();
172
173 // Load fichinter model
174 $fichintsrc = new Fichinter($this->db);
175
176 $result = $fichintsrc->fetch($this->id_origin);
177 if ($result > 0) {
178 $result = $fichintsrc->fetch_lines(); // to get all lines
179 }
180
181 if ($result > 0) {
182 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
183 $sql .= "title";
184 $sql .= ", fk_soc";
185 $sql .= ", entity";
186 $sql .= ", datec";
187 $sql .= ", duree";
188 $sql .= ", description";
189 $sql .= ", note_private";
190 $sql .= ", note_public";
191 $sql .= ", fk_user_author";
192 $sql .= ", fk_projet";
193 $sql .= ", fk_contrat";
194 $sql .= ", modelpdf";
195 $sql .= ", frequency";
196 $sql .= ", unit_frequency";
197 $sql .= ", date_when";
198 $sql .= ", date_last_gen";
199 $sql .= ", nb_gen_done";
200 $sql .= ", nb_gen_max";
201 // $sql.= ", auto_validate";
202 $sql .= ") VALUES (";
203 $sql .= "'".$this->db->escape($this->title)."'";
204 $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null');
205 $sql .= ", ".((int) $conf->entity);
206 $sql .= ", '".$this->db->idate($now)."'";
207 $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0');
208 $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
209 $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null");
210 $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null");
211 $sql .= ", ".((int) $user->id);
212 // If the company is the same, keep the links to the project and the contract
213 if ($this->socid == $fichintsrc->socid) {
214 $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null");
215 $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null");
216 } else {
217 $sql .= ", null, null";
218 }
219
220 $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
221
222 // Frequency
223 $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null");
224 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
225 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null');
226 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null');
227 $sql .= ", 0"; // we start at 0
228 $sql .= ", ".((int) $this->nb_gen_max);
229 // $sql.= ", ".$this->auto_validate;
230 $sql .= ")";
231
232 if ($this->db->query($sql)) {
233 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
234
235 /*
236 * Lines
237 */
238 $num = count($fichintsrc->lines);
239 for ($i = 0; $i < $num; $i++) {
240 //var_dump($fichintsrc->lines[$i]);
241 $result_insert = $this->addLineRec(
242 $fichintsrc->lines[$i]->desc,
243 $fichintsrc->lines[$i]->duration,
244 $fichintsrc->lines[$i]->date,
245 $fichintsrc->lines[$i]->rang,
246 $fichintsrc->lines[$i]->subprice,
247 $fichintsrc->lines[$i]->qty,
248 $fichintsrc->lines[$i]->tva_tx,
249 $fichintsrc->lines[$i]->fk_product,
250 $fichintsrc->lines[$i]->remise_percent,
251 'HT',
252 0,
253 0,
254 0,
255 $fichintsrc->lines[$i]->product_type,
256 $fichintsrc->lines[$i]->special_code,
257 !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label : "",
258 (string) $fichintsrc->lines[$i]->fk_unit
259 );
260
261 if ($result_insert < 0) {
262 $error++;
263 }
264 }
265
266 if ($error) {
267 $this->db->rollback();
268 return -1;
269 } else {
270 $this->db->commit();
271 return $this->id;
272 }
273 } else {
274 $this->error = $this->db->error().' sql='.$sql;
275 $this->db->rollback();
276 return -2;
277 }
278 } else {
279 $this->db->rollback();
280 return -1;
281 }
282 }
283
284
293 public function fetch($rowid = 0, $ref = '', $ref_ext = '')
294 {
295 $sql = 'SELECT f.title, f.fk_soc';
296 $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
297 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
298 $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
299 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
300 $sql .= ', f.status';
301 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f';
302 if ($rowid > 0) {
303 $sql .= " WHERE f.rowid = ".((int) $rowid);
304 } elseif ($ref) {
305 $sql .= " WHERE f.title = '".$this->db->escape($ref)."'";
306 }
307
308 dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
309
310 $result = $this->db->query($sql);
311 if ($result) {
312 if ($this->db->num_rows($result)) {
313 $obj = $this->db->fetch_object($result);
314
315 $this->id = $rowid;
316 $this->title = $obj->title;
317 $this->ref = $obj->title;
318 $this->description = $obj->description;
319 $this->datec = $obj->datec;
320 $this->duration = $obj->duree;
321 $this->socid = $obj->fk_soc;
322 $this->status = $obj->status;
323 $this->statut = $obj->status; // deprecated
324 $this->fk_project = $obj->fk_projet;
325 $this->fk_contrat = $obj->fk_contrat;
326 $this->note_private = $obj->note_private;
327 $this->note_public = $obj->note_public;
328 $this->user_author_id = $obj->fk_user_author;
329 $this->model_pdf = empty($obj->model_pdf) ? "" : $obj->model_pdf;
330 $this->rang = !empty($obj->rang) ? $obj->rang : "";
331 $this->special_code = !empty($obj->special_code) ? $obj->special_code : "";
332 $this->frequency = $obj->frequency;
333 $this->unit_frequency = $obj->unit_frequency;
334 $this->date_when = $this->db->jdate($obj->date_when);
335 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
336 $this->nb_gen_done = $obj->nb_gen_done;
337 $this->nb_gen_max = $obj->nb_gen_max;
338 $this->auto_validate = $obj->auto_validate;
339
340 // Lines
341 $result = $this->fetch_lines();
342 if ($result < 0) {
343 $this->error = $this->db->error();
344 return -3;
345 }
346 return 1;
347 } else {
348 $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
349 dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
350 return -2;
351 }
352 } else {
353 $this->error = $this->db->error();
354 return -1;
355 }
356 }
357
358
359 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
366 public function fetch_lines($sall = 0)
367 {
368 // phpcs:enable
369 $this->lines = array();
370
371 $sql = 'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
372 $sql .= ' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
373 $sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
374 $sql .= ' l.rang, l.special_code,';
375 $sql .= ' l.fk_unit, l.extraparams, p.ref as product_ref, p.fk_product_type as fk_product_type,';
376 $sql .= ' p.label as product_label, p.description as product_desc';
377 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l';
378 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
379 $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
380
381 dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
382
383 $result = $this->db->query($sql);
384 if ($result) {
385 $num = $this->db->num_rows($result);
386 $i = 0;
387 while ($i < $num) {
388 $objp = $this->db->fetch_object($result);
389
390 $line = new FichinterLigne($this->db);
391 $line->id = $objp->rowid;
392 $line->label = $objp->custom_label; // Label line
393 $line->desc = $objp->description; // Description line
394 $line->product_type = $objp->product_type; // Type of line
395 $line->product_ref = $objp->product_ref; // Ref product
396 $line->product_label = $objp->product_label; // Label product
397 $line->product_desc = $objp->product_desc; // Description product
398 $line->fk_product_type = $objp->fk_product_type; // Type in product
399 $line->qty = $objp->qty;
400 $line->duree = $objp->duree;
401 $line->duration = $objp->duree;
402 $line->date = $objp->date;
403 $line->subprice = $objp->subprice;
404 $line->tva_tx = $objp->tva_tx;
405 $line->remise_percent = $objp->remise_percent;
406 $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except : "";
407 $line->fk_product = $objp->fk_product;
408 $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits : "";
409 $line->total_ht = $objp->total_ht;
410 $line->total_tva = $objp->total_tva;
411 $line->total_ttc = $objp->total_ttc;
412 $line->rang = $objp->rang;
413 $line->special_code = $objp->special_code;
414 $line->fk_unit = $objp->fk_unit;
415
416 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
417
418 $this->lines[$i] = $line;
419
420 $i++;
421 }
422
423 $this->db->free($result);
424 return 1;
425 } else {
426 $this->error = $this->db->error();
427 return -3;
428 }
429 }
430
431
439 public function delete(User $user, $notrigger = 0)
440 {
441 $rowid = $this->id;
442
443 dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
444
445 $error = 0;
446 $this->db->begin();
447
448 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
449 dol_syslog($sql);
450 if ($this->db->query($sql)) {
451 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
452 dol_syslog($sql);
453 if (!$this->db->query($sql)) {
454 $this->error = $this->db->lasterror();
455 $error = -1;
456 }
457 } else {
458 $this->error = $this->db->lasterror();
459 $error = -2;
460 }
461
462 if (!$error) {
463 $this->db->commit();
464 return 1;
465 } else {
466 $this->db->rollback();
467 return $error;
468 }
469 }
470
471
494 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)
495 {
496 global $mysoc;
497
498 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
499
500 // Check parameters
501 if ($type < 0) {
502 $this->error = 'Bad value for parameter type';
503 return -1;
504 }
505
506 if ($this->status == self::STATUS_DRAFT) {
507 // Clean parameters
508 $remise_percent = price2num($remise_percent);
509 $qty = price2num($qty);
510 if (!$qty) {
511 $qty = 1;
512 }
513 if (!$info_bits) {
514 $info_bits = 0;
515 }
516 $pu_ht = price2num($pu_ht);
517 $pu_ttc = price2num($pu_ttc);
518 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
519 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
520 }
521
522 if ($price_base_type == 'HT') {
523 $pu = $pu_ht;
524 } else {
525 $pu = $pu_ttc;
526 }
527
528 // Calculation of the gross total (TTC) and VAT for the line from qty, pu, remise_percent and txtva
529 // VERY IMPORTANT: It's at the time of line insertion that we must store the net, VAT, and gross amounts,
530 // and this is done at the line level, which has its own VAT rate
531 $tabprice = calcul_price_total($qty, (float) $pu, (float) $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
532
533 $total_ht = $tabprice[0];
534 $total_tva = $tabprice[1];
535 $total_ttc = $tabprice[2];
536
537 $pu_ht = $tabprice[3];
538
539 $product_type = $type;
540 if ($fk_product) {
541 $product = new Product($this->db);
542 $result = $product->fetch($fk_product);
543 $product_type = $product->type;
544 }
545
546 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
547 $sql .= "fk_fichinter";
548 $sql .= ", label";
549 $sql .= ", description";
550 $sql .= ", date";
551 $sql .= ", duree";
552 //$sql.= ", price";
553 //$sql.= ", qty";
554 //$sql.= ", tva_tx";
555 $sql .= ", fk_product";
556 $sql .= ", product_type";
557 $sql .= ", remise_percent";
558 $sql .= ", subprice";
559 $sql .= ", total_ht";
560 $sql .= ", total_tva";
561 $sql .= ", total_ttc";
562 $sql .= ", rang";
563 //$sql.= ", special_code";
564 $sql .= ", fk_unit";
565 $sql .= ") VALUES (";
566 $sql .= (int) $this->id;
567 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
568 $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
569 $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
570 $sql .= ", ".((int) $duration);
571 //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
572 //$sql.= ", ".price2num($txtva);
573 $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
574 $sql .= ", ".((int) $product_type);
575 $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
576 $sql .= ", '".price2num($pu_ht)."'";
577 $sql .= ", '".price2num($total_ht)."'";
578 $sql .= ", '".price2num($total_tva)."'";
579 $sql .= ", '".price2num($total_ttc)."'";
580 $sql .= ", ".(int) $rang;
581 //$sql.= ", ".$special_code;
582 $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
583 $sql .= ")";
584
585 dol_syslog(get_class($this)."::addLineRec", LOG_DEBUG);
586 if ($this->db->query($sql)) {
587 return 1;
588 } else {
589 $this->error = $this->db->lasterror();
590 return -1;
591 }
592 } else {
593 $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
594 return -1;
595 }
596 }
597
598
599 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
608 public function set_auto($user, $freq, $courant)
609 {
610 // phpcs:enable
611 if ($user->hasRight('fichinter', 'creer')) {
612 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
613 $sql .= " SET frequency='".$this->db->escape((string) $freq)."'";
614 $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
615 $sql .= " WHERE rowid = ".((int) $this->id);
616
617 $resql = $this->db->query($sql);
618
619 if ($resql) {
620 $this->frequency = $freq;
621 $this->date_last_gen = $courant;
622 return 0;
623 } else {
624 dol_print_error($this->db);
625 return -1;
626 }
627 } else {
628 return -2;
629 }
630 }
631
642 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
643 {
644 global $action, $langs, $hookmanager;
645
646 $result = '';
647 $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
648
649 $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
650
651 if ($short) {
652 return $url;
653 }
654
655 $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
656 $linkend = '</a>';
657
658 if ($withpicto) {
659 $result .= $link.img_object($label, $this->picto, 'class="classfortooltip"').$linkend;
660 }
661 if ($withpicto && $withpicto != 2) {
662 $result .= ' ';
663 }
664 if ($withpicto != 2) {
665 $result .= $link.$this->ref.$linkend;
666 }
667
668 $hookmanager->initHooks(array($this->element . 'dao'));
669 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
670 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
671 if ($reshook > 0) {
672 $result = $hookmanager->resPrint;
673 } else {
674 $result .= $hookmanager->resPrint;
675 }
676
677 return $result;
678 }
679
680
688 public function initAsSpecimen()
689 {
690 //$now = dol_now();
691 //$arraynow = dol_getdate($now);
692 //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
693
694 parent::initAsSpecimen();
695
696 $this->usenewprice = 1;
697
698 return 1;
699 }
700
709 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
710 {
711 $tables = array('fichinter_rec');
712
713 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
714 }
715
724 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
725 {
726 $tables = array(
727 'fichinterdet_rec'
728 );
729
730 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
731 }
732
740 public function setFrequencyAndUnit($frequency, $unit)
741 {
742 if (!$this->table_element) {
743 dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
744 return -1;
745 }
746
747 if (!empty($frequency) && empty($unit)) {
748 dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
749 return -2;
750 }
751
752 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
753 $sql .= ' SET frequency = '.($frequency ? $this->db->escape((string) $frequency) : 'null');
754 if (!empty($unit)) {
755 $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
756 }
757 $sql .= " WHERE rowid = ".((int) $this->id);
758
759 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
760 if ($this->db->query($sql)) {
761 $this->frequency = $frequency;
762 if (!empty($unit)) {
763 $this->unit_frequency = $unit;
764 }
765 return 1;
766 } else {
767 dol_print_error($this->db);
768 return -1;
769 }
770 }
771
779 public function setNextDate($date, $increment_nb_gen_done = 0)
780 {
781 if (!$this->table_element) {
782 dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
783 return -1;
784 }
785 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
786 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
787 if ($increment_nb_gen_done > 0) {
788 $sql .= ', nb_gen_done = nb_gen_done + 1';
789 }
790 $sql .= " WHERE rowid = ".((int) $this->id);
791
792 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
793 if ($this->db->query($sql)) {
794 $this->date_when = $date;
795 if ($increment_nb_gen_done > 0) {
796 $this->nb_gen_done++;
797 }
798 return 1;
799 } else {
800 dol_print_error($this->db);
801 return -1;
802 }
803 }
804
811 public function setMaxPeriod($nb)
812 {
813 if (!$this->table_element) {
814 dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
815 return -1;
816 }
817
818 if (empty($nb)) {
819 $nb = 0;
820 }
821
822 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
823 $sql .= ' SET nb_gen_max = '.((int) $nb);
824 $sql .= ' WHERE rowid = '.((int) $this->id);
825
826 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
827 if ($this->db->query($sql)) {
828 $this->nb_gen_max = $nb;
829 return 1;
830 } else {
831 dol_print_error($this->db);
832 return -1;
833 }
834 }
835
842 public function setAutoValidate($validate)
843 {
844 if (!$this->table_element) {
845 dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
846 return -1;
847 }
848
849 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
850 $sql .= ' SET auto_validate = '.((int) $validate);
851 $sql .= ' WHERE rowid = '.((int) $this->id);
852
853 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
854 if ($this->db->query($sql)) {
855 $this->auto_validate = $validate;
856 return 1;
857 } else {
858 dol_print_error($this->db);
859 return -1;
860 }
861 }
862
868 public function updateNbGenDone()
869 {
870 if (!$this->table_element) {
871 dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
872 return -1;
873 }
874
875 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
876 $sql .= ' SET nb_gen_done = nb_gen_done + 1';
877 $sql .= ' , date_last_gen = now()';
878 // si on et arrivé à la fin des génération
879 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
880 $sql .= ' , status = 1';
881 }
882
883 $sql .= " WHERE rowid = ".((int) $this->id);
884
885 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
886 if ($this->db->query($sql)) {
887 $this->nb_gen_done++;
888 $this->date_last_gen = dol_now();
889 //$this->date_when = ...
890 return 1;
891 } else {
892 dol_print_error($this->db);
893 return -1;
894 }
895 }
896}
$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.
setMaxPeriod($nb)
Update the maximum period.
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='')
Return clickable name (with picto eventually)
updateNbGenDone()
Update the Number of Generation Done.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
create($user, $notrigger=0)
Create a predefined fichinter.
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.
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
setAutoValidate($validate)
Update the auto validate fichinter.
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
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:168
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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
buildzip.php
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $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