dolibarr 21.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 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 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 $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 = $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, 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 $this->lines[$i] = $line;
417
418 $i++;
419 }
420
421 $this->db->free($result);
422 return 1;
423 } else {
424 $this->error = $this->db->error();
425 return -3;
426 }
427 }
428
429
437 public function delete(User $user, $notrigger = 0)
438 {
439 $rowid = $this->id;
440
441 dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
442
443 $error = 0;
444 $this->db->begin();
445
446 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
447 dol_syslog($sql);
448 if ($this->db->query($sql)) {
449 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
450 dol_syslog($sql);
451 if (!$this->db->query($sql)) {
452 $this->error = $this->db->lasterror();
453 $error = -1;
454 }
455 } else {
456 $this->error = $this->db->lasterror();
457 $error = -2;
458 }
459
460 if (!$error) {
461 $this->db->commit();
462 return 1;
463 } else {
464 $this->db->rollback();
465 return $error;
466 }
467 }
468
469
492 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)
493 {
494 global $mysoc;
495
496 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
497
498 // Check parameters
499 if ($type < 0) {
500 $this->error = 'Bad value for parameter type';
501 return -1;
502 }
503
504 if ($this->status == self::STATUS_DRAFT) {
505 // Clean parameters
506 $remise_percent = price2num($remise_percent);
507 $qty = price2num($qty);
508 if (!$qty) {
509 $qty = 1;
510 }
511 if (!$info_bits) {
512 $info_bits = 0;
513 }
514 $pu_ht = price2num($pu_ht);
515 $pu_ttc = price2num($pu_ttc);
516 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
517 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
518 }
519
520 if ($price_base_type == 'HT') {
521 $pu = $pu_ht;
522 } else {
523 $pu = $pu_ttc;
524 }
525
526 // Calcul du total TTC et de la TVA pour la ligne a partir de
527 // qty, pu, remise_percent et txtva
528 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
529 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
530 $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
531
532 $total_ht = $tabprice[0];
533 $total_tva = $tabprice[1];
534 $total_ttc = $tabprice[2];
535
536 $pu_ht = $tabprice[3];
537
538 $product_type = $type;
539 if ($fk_product) {
540 $product = new Product($this->db);
541 $result = $product->fetch($fk_product);
542 $product_type = $product->type;
543 }
544
545 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
546 $sql .= "fk_fichinter";
547 $sql .= ", label";
548 $sql .= ", description";
549 $sql .= ", date";
550 $sql .= ", duree";
551 //$sql.= ", price";
552 //$sql.= ", qty";
553 //$sql.= ", tva_tx";
554 $sql .= ", fk_product";
555 $sql .= ", product_type";
556 $sql .= ", remise_percent";
557 $sql .= ", subprice";
558 $sql .= ", total_ht";
559 $sql .= ", total_tva";
560 $sql .= ", total_ttc";
561 $sql .= ", rang";
562 //$sql.= ", special_code";
563 $sql .= ", fk_unit";
564 $sql .= ") VALUES (";
565 $sql .= (int) $this->id;
566 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
567 $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
568 $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
569 $sql .= ", ".$duration;
570 //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
571 //$sql.= ", ".price2num($txtva);
572 $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
573 $sql .= ", ".$product_type;
574 $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
575 $sql .= ", '".price2num($pu_ht)."'";
576 $sql .= ", '".price2num($total_ht)."'";
577 $sql .= ", '".price2num($total_tva)."'";
578 $sql .= ", '".price2num($total_ttc)."'";
579 $sql .= ", ".(int) $rang;
580 //$sql.= ", ".$special_code;
581 $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
582 $sql .= ")";
583
584 dol_syslog(get_class($this)."::addLineRec", LOG_DEBUG);
585 if ($this->db->query($sql)) {
586 return 1;
587 } else {
588 $this->error = $this->db->lasterror();
589 return -1;
590 }
591 } else {
592 $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
593 return -1;
594 }
595 }
596
597
598 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
607 public function set_auto($user, $freq, $courant)
608 {
609 // phpcs:enable
610 if ($user->hasRight('fichinter', 'creer')) {
611 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
612 $sql .= " SET frequency='".$this->db->escape($freq)."'";
613 $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
614 $sql .= " WHERE rowid = ".((int) $this->id);
615
616 $resql = $this->db->query($sql);
617
618 if ($resql) {
619 $this->frequency = $freq;
620 $this->date_last_gen = $courant;
621 return 0;
622 } else {
623 dol_print_error($this->db);
624 return -1;
625 }
626 } else {
627 return -2;
628 }
629 }
630
641 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
642 {
643 global $action, $langs, $hookmanager;
644
645 $result = '';
646 $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
647
648 $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
649
650 if ($short) {
651 return $url;
652 }
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, $this->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
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
676 return $result;
677 }
678
679
687 public function initAsSpecimen()
688 {
689 //$now = dol_now();
690 //$arraynow = dol_getdate($now);
691 //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
692
693 parent::initAsSpecimen();
694
695 $this->usenewprice = 1;
696
697 return 1;
698 }
699
708 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
709 {
710 $tables = array('fichinter_rec');
711
712 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
713 }
714
723 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
724 {
725 $tables = array(
726 'fichinterdet_rec'
727 );
728
729 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
730 }
731
739 public function setFrequencyAndUnit($frequency, $unit)
740 {
741 if (!$this->table_element) {
742 dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
743 return -1;
744 }
745
746 if (!empty($frequency) && empty($unit)) {
747 dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
748 return -2;
749 }
750
751 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
752 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
753 if (!empty($unit)) {
754 $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
755 }
756 $sql .= " WHERE rowid = ".((int) $this->id);
757
758 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
759 if ($this->db->query($sql)) {
760 $this->frequency = $frequency;
761 if (!empty($unit)) {
762 $this->unit_frequency = $unit;
763 }
764 return 1;
765 } else {
766 dol_print_error($this->db);
767 return -1;
768 }
769 }
770
778 public function setNextDate($date, $increment_nb_gen_done = 0)
779 {
780 if (!$this->table_element) {
781 dol_syslog(get_class($this)."::setNextDate was called on object with property table_element not defined", LOG_ERR);
782 return -1;
783 }
784 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
785 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
786 if ($increment_nb_gen_done > 0) {
787 $sql .= ', nb_gen_done = nb_gen_done + 1';
788 }
789 $sql .= " WHERE rowid = ".((int) $this->id);
790
791 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
792 if ($this->db->query($sql)) {
793 $this->date_when = $date;
794 if ($increment_nb_gen_done > 0) {
795 $this->nb_gen_done++;
796 }
797 return 1;
798 } else {
799 dol_print_error($this->db);
800 return -1;
801 }
802 }
803
810 public function setMaxPeriod($nb)
811 {
812 if (!$this->table_element) {
813 dol_syslog(get_class($this)."::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
814 return -1;
815 }
816
817 if (empty($nb)) {
818 $nb = 0;
819 }
820
821 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
822 $sql .= ' SET nb_gen_max = '.((int) $nb);
823 $sql .= ' WHERE rowid = '.((int) $this->id);
824
825 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
826 if ($this->db->query($sql)) {
827 $this->nb_gen_max = $nb;
828 return 1;
829 } else {
830 dol_print_error($this->db);
831 return -1;
832 }
833 }
834
841 public function setAutoValidate($validate)
842 {
843 if (!$this->table_element) {
844 dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
845 return -1;
846 }
847
848 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
849 $sql .= ' SET auto_validate = '.((int) $validate);
850 $sql .= ' WHERE rowid = '.((int) $this->id);
851
852 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
853 if ($this->db->query($sql)) {
854 $this->auto_validate = $validate;
855 return 1;
856 } else {
857 dol_print_error($this->db);
858 return -1;
859 }
860 }
861
867 public function updateNbGenDone()
868 {
869 if (!$this->table_element) {
870 dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
871 return -1;
872 }
873
874 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
875 $sql .= ' SET nb_gen_done = nb_gen_done + 1';
876 $sql .= ' , date_last_gen = now()';
877 // si on et arrivé à la fin des génération
878 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
879 $sql .= ' , status = 1';
880 }
881
882 $sql .= " WHERE rowid = ".((int) $this->id);
883
884 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
885 if ($this->db->query($sql)) {
886 $this->nb_gen_done++;
887 $this->date_last_gen = dol_now();
888 //$this->date_when = ...
889 return 1;
890 } else {
891 dol_print_error($this->db);
892 return -1;
893 }
894 }
895}
$object ref
Definition info.php:89
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:171
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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:90