dolibarr 20.0.2
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 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2024 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 public $fk_element = 'fk_fichinter';
52
56 protected $table_ref_field = 'title';
57
61 public $picto = 'intervention';
62
63
67 public $title;
68 public $number;
69 public $date;
70 public $amount;
71 public $tva;
72 public $total;
73
77 public $auto_validate;
78
82 public $frequency;
83
84 public $id_origin;
85
89 public $unit_frequency;
90
94 public $propalid;
95
96 public $date_last_gen;
97 public $date_when;
98
102 public $nb_gen_done;
103
107 public $nb_gen_max;
108
112 public $rang;
113
117 public $special_code;
118
119 public $usenewprice = 0;
120
126 public function __construct($db)
127 {
128 $this->db = $db;
129
130 //status dans l'ordre de l'intervention
131 $this->labelStatus[0] = 'Draft';
132 $this->labelStatus[1] = 'Closed';
133
134 $this->labelStatusShort[0] = 'Draft';
135 $this->labelStatusShort[1] = 'Closed';
136 }
137
144 public function getLibStatut($mode = 0)
145 {
146 return $this->LibStatut($this->status, $mode);
147 }
148
149
157 public function create($user, $notrigger = 0)
158 {
159 global $conf;
160
161 $error = 0;
162 $now = dol_now();
163
164 // Clean parameters
165 $this->title = trim($this->title);
166 $this->description = trim($this->description);
167
168
169 $this->db->begin();
170
171 // Load fichinter model
172 $fichintsrc = new Fichinter($this->db);
173
174 $result = $fichintsrc->fetch($this->id_origin);
175 if ($result > 0) {
176 $result = $fichintsrc->fetch_lines(); // to get all lines
177 }
178
179 if ($result > 0) {
180 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
181 $sql .= "title";
182 $sql .= ", fk_soc";
183 $sql .= ", entity";
184 $sql .= ", datec";
185 $sql .= ", duree";
186 $sql .= ", description";
187 $sql .= ", note_private";
188 $sql .= ", note_public";
189 $sql .= ", fk_user_author";
190 $sql .= ", fk_projet";
191 $sql .= ", fk_contrat";
192 $sql .= ", modelpdf";
193 $sql .= ", frequency";
194 $sql .= ", unit_frequency";
195 $sql .= ", date_when";
196 $sql .= ", date_last_gen";
197 $sql .= ", nb_gen_done";
198 $sql .= ", nb_gen_max";
199 // $sql.= ", auto_validate";
200 $sql .= ") VALUES (";
201 $sql .= "'".$this->db->escape($this->title)."'";
202 $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null');
203 $sql .= ", ".((int) $conf->entity);
204 $sql .= ", '".$this->db->idate($now)."'";
205 $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0');
206 $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
207 $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null");
208 $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null");
209 $sql .= ", ".((int) $user->id);
210 // si c'est la même société on conserve les liens vers le projet et le contrat
211 if ($this->socid == $fichintsrc->socid) {
212 $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null");
213 $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null");
214 } else {
215 $sql .= ", null, null";
216 }
217
218 $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
219
220 // Frequency
221 $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null");
222 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
223 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null');
224 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null');
225 $sql .= ", 0"; // we start at 0
226 $sql .= ", ".((int) $this->nb_gen_max);
227 // $sql.= ", ".$this->auto_validate;
228 $sql .= ")";
229
230 if ($this->db->query($sql)) {
231 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
232
233 /*
234 * Lines
235 */
236 $num = count($fichintsrc->lines);
237 for ($i = 0; $i < $num; $i++) {
238 //var_dump($fichintsrc->lines[$i]);
239 $result_insert = $this->addLineRec(
240 $fichintsrc->lines[$i]->desc,
241 $fichintsrc->lines[$i]->duration,
242 $fichintsrc->lines[$i]->date,
243 $fichintsrc->lines[$i]->rang,
244 $fichintsrc->lines[$i]->subprice,
245 $fichintsrc->lines[$i]->qty,
246 $fichintsrc->lines[$i]->tva_tx,
247 $fichintsrc->lines[$i]->fk_product,
248 $fichintsrc->lines[$i]->remise_percent,
249 'HT',
250 0,
251 '',
252 0,
253 $fichintsrc->lines[$i]->product_type,
254 $fichintsrc->lines[$i]->special_code,
255 !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label : "",
256 $fichintsrc->lines[$i]->fk_unit
257 );
258
259 if ($result_insert < 0) {
260 $error++;
261 }
262 }
263
264 if ($error) {
265 $this->db->rollback();
266 return -1;
267 } else {
268 $this->db->commit();
269 return $this->id;
270 }
271 } else {
272 $this->error = $this->db->error().' sql='.$sql;
273 $this->db->rollback();
274 return -2;
275 }
276 } else {
277 $this->db->rollback();
278 return -1;
279 }
280 }
281
282
291 public function fetch($rowid = 0, $ref = '', $ref_ext = '')
292 {
293 $sql = 'SELECT f.title, f.fk_soc';
294 $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
295 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
296 $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
297 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
298 $sql .= ', f.status';
299 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f';
300 if ($rowid > 0) {
301 $sql .= " WHERE f.rowid = ".((int) $rowid);
302 } elseif ($ref) {
303 $sql .= " WHERE f.title = '".$this->db->escape($ref)."'";
304 }
305
306 dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
307
308 $result = $this->db->query($sql);
309 if ($result) {
310 if ($this->db->num_rows($result)) {
311 $obj = $this->db->fetch_object($result);
312
313 $this->id = $rowid;
314 $this->title = $obj->title;
315 $this->ref = $obj->title;
316 $this->description = $obj->description;
317 $this->datec = $obj->datec;
318 $this->duration = $obj->duree;
319 $this->socid = $obj->fk_soc;
320 $this->status = $obj->status;
321 $this->statut = $obj->status; // deprecated
322 $this->fk_project = $obj->fk_projet;
323 $this->fk_contrat = $obj->fk_contrat;
324 $this->note_private = $obj->note_private;
325 $this->note_public = $obj->note_public;
326 $this->user_author = $obj->fk_user_author;
327 $this->model_pdf = empty($obj->model_pdf) ? "" : $obj->model_pdf;
328 $this->rang = !empty($obj->rang) ? $obj->rang : "";
329 $this->special_code = !empty($obj->special_code) ? $obj->special_code : "";
330 $this->frequency = $obj->frequency;
331 $this->unit_frequency = $obj->unit_frequency;
332 $this->date_when = $this->db->jdate($obj->date_when);
333 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
334 $this->nb_gen_done = $obj->nb_gen_done;
335 $this->nb_gen_max = $obj->nb_gen_max;
336 $this->auto_validate = $obj->auto_validate;
337
338 // Lines
339 $result = $this->fetch_lines();
340 if ($result < 0) {
341 $this->error = $this->db->error();
342 return -3;
343 }
344 return 1;
345 } else {
346 $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
347 dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
348 return -2;
349 }
350 } else {
351 $this->error = $this->db->error();
352 return -1;
353 }
354 }
355
356
357 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
364 public function fetch_lines($sall = 0)
365 {
366 // phpcs:enable
367 $this->lines = array();
368
369 $sql = 'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
370 $sql .= ' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
371 $sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
372 $sql .= ' l.rang, l.special_code,';
373 $sql .= ' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
374 $sql .= ' p.label as product_label, p.description as product_desc';
375 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l';
376 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
377 $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
378
379 dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
380
381 $result = $this->db->query($sql);
382 if ($result) {
383 $num = $this->db->num_rows($result);
384 $i = 0;
385 while ($i < $num) {
386 $objp = $this->db->fetch_object($result);
387
388 $line = new FichinterLigne($this->db);
389 $line->id = $objp->rowid;
390 $line->label = $objp->custom_label; // Label line
391 $line->desc = $objp->description; // Description line
392 $line->product_type = $objp->product_type; // Type of line
393 $line->product_ref = $objp->product_ref; // Ref product
394 $line->product_label = $objp->product_label; // Label product
395 $line->product_desc = $objp->product_desc; // Description product
396 $line->fk_product_type = $objp->fk_product_type; // Type in product
397 $line->qty = $objp->qty;
398 $line->duree = $objp->duree;
399 $line->duration = $objp->duree;
400 $line->date = $objp->date;
401 $line->subprice = $objp->subprice;
402 $line->tva_tx = $objp->tva_tx;
403 $line->remise_percent = $objp->remise_percent;
404 $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except : "";
405 $line->fk_product = $objp->fk_product;
406 $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits : "";
407 $line->total_ht = $objp->total_ht;
408 $line->total_tva = $objp->total_tva;
409 $line->total_ttc = $objp->total_ttc;
410 $line->rang = $objp->rang;
411 $line->special_code = $objp->special_code;
412 $line->fk_unit = $objp->fk_unit;
413
414 $this->lines[$i] = $line;
415
416 $i++;
417 }
418
419 $this->db->free($result);
420 return 1;
421 } else {
422 $this->error = $this->db->error();
423 return -3;
424 }
425 }
426
427
435 public function delete(User $user, $notrigger = 0)
436 {
437 $rowid = $this->id;
438
439 dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
440
441 $error = 0;
442 $this->db->begin();
443
444 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
445 dol_syslog($sql);
446 if ($this->db->query($sql)) {
447 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
448 dol_syslog($sql);
449 if (!$this->db->query($sql)) {
450 $this->error = $this->db->lasterror();
451 $error = -1;
452 }
453 } else {
454 $this->error = $this->db->lasterror();
455 $error = -2;
456 }
457
458 if (!$error) {
459 $this->db->commit();
460 return 1;
461 } else {
462 $this->db->rollback();
463 return $error;
464 }
465 }
466
467
490 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)
491 {
492 global $mysoc;
493
494 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
495
496 // Check parameters
497 if ($type < 0) {
498 $this->error = 'Bad value for parameter type';
499 return -1;
500 }
501
502 if ($this->status == self::STATUS_DRAFT) {
503 // Clean parameters
504 $remise_percent = price2num($remise_percent);
505 $qty = price2num($qty);
506 if (!$qty) {
507 $qty = 1;
508 }
509 if (!$info_bits) {
510 $info_bits = 0;
511 }
512 $pu_ht = price2num($pu_ht);
513 $pu_ttc = price2num($pu_ttc);
514 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
515 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
516 }
517
518 if ($price_base_type == 'HT') {
519 $pu = $pu_ht;
520 } else {
521 $pu = $pu_ttc;
522 }
523
524 // Calcul du total TTC et de la TVA pour la ligne a partir de
525 // qty, pu, remise_percent et txtva
526 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
527 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
528 $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
529
530 $total_ht = $tabprice[0];
531 $total_tva = $tabprice[1];
532 $total_ttc = $tabprice[2];
533
534 $pu_ht = $tabprice[3];
535
536 $product_type = $type;
537 if ($fk_product) {
538 $product = new Product($this->db);
539 $result = $product->fetch($fk_product);
540 $product_type = $product->type;
541 }
542
543 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
544 $sql .= "fk_fichinter";
545 $sql .= ", label";
546 $sql .= ", description";
547 $sql .= ", date";
548 $sql .= ", duree";
549 //$sql.= ", price";
550 //$sql.= ", qty";
551 //$sql.= ", tva_tx";
552 $sql .= ", fk_product";
553 $sql .= ", product_type";
554 $sql .= ", remise_percent";
555 $sql .= ", subprice";
556 $sql .= ", total_ht";
557 $sql .= ", total_tva";
558 $sql .= ", total_ttc";
559 $sql .= ", rang";
560 //$sql.= ", special_code";
561 $sql .= ", fk_unit";
562 $sql .= ") VALUES (";
563 $sql .= (int) $this->id;
564 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
565 $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
566 $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
567 $sql .= ", ".$duration;
568 //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
569 //$sql.= ", ".price2num($txtva);
570 $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
571 $sql .= ", ".$product_type;
572 $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
573 $sql .= ", '".price2num($pu_ht)."'";
574 $sql .= ", '".price2num($total_ht)."'";
575 $sql .= ", '".price2num($total_tva)."'";
576 $sql .= ", '".price2num($total_ttc)."'";
577 $sql .= ", ".(int) $rang;
578 //$sql.= ", ".$special_code;
579 $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
580 $sql .= ")";
581
582 dol_syslog(get_class($this)."::addLineRec", LOG_DEBUG);
583 if ($this->db->query($sql)) {
584 return 1;
585 } else {
586 $this->error = $this->db->lasterror();
587 return -1;
588 }
589 } else {
590 $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
591 return -1;
592 }
593 }
594
595
596 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
605 public function set_auto($user, $freq, $courant)
606 {
607 // phpcs:enable
608 if ($user->hasRight('fichinter', 'creer')) {
609 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
610 $sql .= " SET frequency='".$this->db->escape($freq)."'";
611 $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
612 $sql .= " WHERE rowid = ".((int) $this->id);
613
614 $resql = $this->db->query($sql);
615
616 if ($resql) {
617 $this->frequency = $freq;
618 $this->date_last_gen = $courant;
619 return 0;
620 } else {
621 dol_print_error($this->db);
622 return -1;
623 }
624 } else {
625 return -2;
626 }
627 }
628
639 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
640 {
641 global $langs, $hookmanager;
642
643 $result = '';
644 $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
645
646 $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
647
648 if ($short) {
649 return $url;
650 }
651
652 $picto = 'intervention';
653
654 $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
655 $linkend = '</a>';
656
657 if ($withpicto) {
658 $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend;
659 }
660 if ($withpicto && $withpicto != 2) {
661 $result .= ' ';
662 }
663 if ($withpicto != 2) {
664 $result .= $link.$this->ref.$linkend;
665 }
666 global $action;
667 $hookmanager->initHooks(array($this->element . 'dao'));
668 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
669 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
670 if ($reshook > 0) {
671 $result = $hookmanager->resPrint;
672 } else {
673 $result .= $hookmanager->resPrint;
674 }
675 return $result;
676 }
677
678
686 public function initAsSpecimen()
687 {
688 //$now = dol_now();
689 //$arraynow = dol_getdate($now);
690 //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
691
692 parent::initAsSpecimen();
693
694 $this->usenewprice = 1;
695
696 return 1;
697 }
698
707 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
708 {
709 $tables = array('fichinter_rec');
710
711 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
712 }
713
722 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
723 {
724 $tables = array(
725 'fichinterdet_rec'
726 );
727
728 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
729 }
730
738 public function setFrequencyAndUnit($frequency, $unit)
739 {
740 if (!$this->table_element) {
741 dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
742 return -1;
743 }
744
745 if (!empty($frequency) && empty($unit)) {
746 dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
747 return -2;
748 }
749
750 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
751 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
752 if (!empty($unit)) {
753 $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
754 }
755 $sql .= " WHERE rowid = ".((int) $this->id);
756
757 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
758 if ($this->db->query($sql)) {
759 $this->frequency = $frequency;
760 if (!empty($unit)) {
761 $this->unit_frequency = $unit;
762 }
763 return 1;
764 } else {
765 dol_print_error($this->db);
766 return -1;
767 }
768 }
769
777 public function setNextDate($date, $increment_nb_gen_done = 0)
778 {
779 if (!$this->table_element) {
780 dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
781 return -1;
782 }
783 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
784 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
785 if ($increment_nb_gen_done > 0) {
786 $sql .= ', nb_gen_done = nb_gen_done + 1';
787 }
788 $sql .= " WHERE rowid = ".((int) $this->id);
789
790 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
791 if ($this->db->query($sql)) {
792 $this->date_when = $date;
793 if ($increment_nb_gen_done > 0) {
794 $this->nb_gen_done++;
795 }
796 return 1;
797 } else {
798 dol_print_error($this->db);
799 return -1;
800 }
801 }
802
809 public function setMaxPeriod($nb)
810 {
811 if (!$this->table_element) {
812 dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
813 return -1;
814 }
815
816 if (empty($nb)) {
817 $nb = 0;
818 }
819
820 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
821 $sql .= ' SET nb_gen_max = '.((int) $nb);
822 $sql .= ' WHERE rowid = '.((int) $this->id);
823
824 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
825 if ($this->db->query($sql)) {
826 $this->nb_gen_max = $nb;
827 return 1;
828 } else {
829 dol_print_error($this->db);
830 return -1;
831 }
832 }
833
840 public function setAutoValidate($validate)
841 {
842 if (!$this->table_element) {
843 dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
844 return -1;
845 }
846
847 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
848 $sql .= ' SET auto_validate = '.((int) $validate);
849 $sql .= ' WHERE rowid = '.((int) $this->id);
850
851 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
852 if ($this->db->query($sql)) {
853 $this->auto_validate = $validate;
854 return 1;
855 } else {
856 dol_print_error($this->db);
857 return -1;
858 }
859 }
860
866 public function updateNbGenDone()
867 {
868 if (!$this->table_element) {
869 dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
870 return -1;
871 }
872
873 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
874 $sql .= ' SET nb_gen_done = nb_gen_done + 1';
875 $sql .= ' , date_last_gen = now()';
876 // si on et arrivé à la fin des génération
877 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
878 $sql .= ' , status = 1';
879 }
880
881 $sql .= " WHERE rowid = ".((int) $this->id);
882
883 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
884 if ($this->db->query($sql)) {
885 $this->nb_gen_done++;
886 $this->date_last_gen = dol_now();
887 //$this->date_when = ...
888 return 1;
889 } else {
890 dol_print_error($this->db);
891 return -1;
892 }
893 }
894}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
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.
Class to manage interventions.
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 clicable 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 $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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
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...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:88
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:2010