dolibarr 19.0.3
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 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
34
35
40{
41 public $element = 'fichinterrec';
42 public $table_element = 'fichinter_rec';
43 public $table_element_line = 'fichinterdet_rec';
44
48 public $fk_element = 'fk_fichinter';
49
53 protected $table_ref_field = 'title';
54
58 public $picto = 'intervention';
59
60
64 public $title;
65 public $number;
66 public $date;
67 public $amount;
68 public $tva;
69 public $total;
70
74 public $auto_validate;
75
79 public $frequency;
80
81 public $id_origin;
82
86 public $unit_frequency;
87
91 public $propalid;
92
93 public $date_last_gen;
94 public $date_when;
95
99 public $nb_gen_done;
100
104 public $nb_gen_max;
105
109 public $rang;
110 public $special_code;
111
112 public $usenewprice = 0;
113
119 public function __construct($db)
120 {
121 $this->db = $db;
122
123 //status dans l'ordre de l'intervention
124 $this->labelStatus[0] = 'Draft';
125 $this->labelStatus[1] = 'Closed';
126
127 $this->labelStatusShort[0] = 'Draft';
128 $this->labelStatusShort[1] = 'Closed';
129 }
130
137 public function getLibStatut($mode = 0)
138 {
139 return $this->LibStatut($this->status, $mode);
140 }
141
142
150 public function create($user, $notrigger = 0)
151 {
152 global $conf;
153
154 $error = 0;
155 $now = dol_now();
156
157 // Clean parameters
158 $this->title = trim($this->title);
159 $this->description = trim($this->description);
160
161
162 $this->db->begin();
163
164 // Load fichinter model
165 $fichintsrc = new Fichinter($this->db);
166
167 $result = $fichintsrc->fetch($this->id_origin);
168 if ($result > 0) {
169 $result = $fichintsrc->fetch_lines(); // to get all lines
170 }
171
172 if ($result > 0) {
173 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter_rec (";
174 $sql .= "title";
175 $sql .= ", fk_soc";
176 $sql .= ", entity";
177 $sql .= ", datec";
178 $sql .= ", duree";
179 $sql .= ", description";
180 $sql .= ", note_private";
181 $sql .= ", note_public";
182 $sql .= ", fk_user_author";
183 $sql .= ", fk_projet";
184 $sql .= ", fk_contrat";
185 $sql .= ", modelpdf";
186 $sql .= ", frequency";
187 $sql .= ", unit_frequency";
188 $sql .= ", date_when";
189 $sql .= ", date_last_gen";
190 $sql .= ", nb_gen_done";
191 $sql .= ", nb_gen_max";
192 // $sql.= ", auto_validate";
193 $sql .= ") VALUES (";
194 $sql .= "'".$this->db->escape($this->title)."'";
195 $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : 'null');
196 $sql .= ", ".((int) $conf->entity);
197 $sql .= ", '".$this->db->idate($now)."'";
198 $sql .= ", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) : '0');
199 $sql .= ", ".(!empty($this->description) ? ("'".$this->db->escape($this->description)."'") : "null");
200 $sql .= ", ".(!empty($fichintsrc->note_private) ? ("'".$this->db->escape($fichintsrc->note_private)."'") : "null");
201 $sql .= ", ".(!empty($fichintsrc->note_public) ? ("'".$this->db->escape($fichintsrc->note_public)."'") : "null");
202 $sql .= ", ".((int) $user->id);
203 // si c'est la même société on conserve les liens vers le projet et le contrat
204 if ($this->socid == $fichintsrc->socid) {
205 $sql .= ", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) : "null");
206 $sql .= ", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) : "null");
207 } else {
208 $sql .= ", null, null";
209 }
210
211 $sql .= ", ".(!empty($fichintsrc->model_pdf) ? "'".$this->db->escape($fichintsrc->model_pdf)."'" : "''");
212
213 // Frequency
214 $sql .= ", ".(!empty($this->frequency) ? ((int) $this->frequency) : "null");
215 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
216 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'null');
217 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'null');
218 $sql .= ", 0"; // we start at 0
219 $sql .= ", ".((int) $this->nb_gen_max);
220 // $sql.= ", ".$this->auto_validate;
221 $sql .= ")";
222
223 if ($this->db->query($sql)) {
224 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
225
226 /*
227 * Lines
228 */
229 $num = count($fichintsrc->lines);
230 for ($i = 0; $i < $num; $i++) {
231 //var_dump($fichintsrc->lines[$i]);
232 $result_insert = $this->addline(
233 $fichintsrc->lines[$i]->desc,
234 $fichintsrc->lines[$i]->duration,
235 $fichintsrc->lines[$i]->date,
236 $fichintsrc->lines[$i]->rang,
237 $fichintsrc->lines[$i]->subprice,
238 $fichintsrc->lines[$i]->qty,
239 $fichintsrc->lines[$i]->tva_tx,
240 $fichintsrc->lines[$i]->fk_product,
241 $fichintsrc->lines[$i]->remise_percent,
242 'HT',
243 0,
244 '',
245 0,
246 $fichintsrc->lines[$i]->product_type,
247 $fichintsrc->lines[$i]->special_code,
248 !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label : "",
249 $fichintsrc->lines[$i]->fk_unit
250 );
251
252 if ($result_insert < 0) {
253 $error++;
254 }
255 }
256
257 if ($error) {
258 $this->db->rollback();
259 return -1;
260 } else {
261 $this->db->commit();
262 return $this->id;
263 }
264 } else {
265 $this->error = $this->db->error().' sql='.$sql;
266 $this->db->rollback();
267 return -2;
268 }
269 } else {
270 $this->db->rollback();
271 return -1;
272 }
273 }
274
275
284 public function fetch($rowid = 0, $ref = '', $ref_ext = '')
285 {
286 $sql = 'SELECT f.title as title, f.fk_soc';
287 $sql .= ', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
288 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
289 $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
290 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
291 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter_rec as f';
292 if ($rowid > 0) {
293 $sql .= " WHERE f.rowid = ".((int) $rowid);
294 } elseif ($ref) {
295 $sql .= " WHERE f.title = '".$this->db->escape($ref)."'";
296 }
297
298 dol_syslog(get_class($this)."::fetch rowid=".$rowid, LOG_DEBUG);
299
300 $result = $this->db->query($sql);
301 if ($result) {
302 if ($this->db->num_rows($result)) {
303 $obj = $this->db->fetch_object($result);
304
305 $this->id = $rowid;
306 $this->title = $obj->title;
307 $this->ref = $obj->title;
308 $this->description = $obj->description;
309 $this->datec = $obj->datec;
310 $this->duration = $obj->duree;
311 $this->socid = $obj->fk_soc;
312 $this->status = 0;
313 $this->statut = 0; // deprecated
314 $this->fk_project = $obj->fk_projet;
315 $this->fk_contrat = $obj->fk_contrat;
316 $this->note_private = $obj->note_private;
317 $this->note_public = $obj->note_public;
318 $this->user_author = $obj->fk_user_author;
319 $this->model_pdf = empty($obj->model_pdf) ? "" : $obj->model_pdf;
320 $this->rang = !empty($obj->rang) ? $obj->rang : "";
321 $this->special_code = !empty($obj->special_code) ? $obj->special_code : "";
322 $this->frequency = $obj->frequency;
323 $this->unit_frequency = $obj->unit_frequency;
324 $this->date_when = $this->db->jdate($obj->date_when);
325 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
326 $this->nb_gen_done = $obj->nb_gen_done;
327 $this->nb_gen_max = $obj->nb_gen_max;
328 $this->auto_validate = $obj->auto_validate;
329
330 // Lines
331 $result = $this->fetch_lines();
332 if ($result < 0) {
333 $this->error = $this->db->error();
334 return -3;
335 }
336 return 1;
337 } else {
338 $this->error = 'Interventional with id '.$rowid.' not found sql='.$sql;
339 dol_syslog(get_class($this).'::Fetch Error '.$this->error, LOG_ERR);
340 return -2;
341 }
342 } else {
343 $this->error = $this->db->error();
344 return -1;
345 }
346 }
347
348
349 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
356 public function fetch_lines($sall = 0)
357 {
358 // phpcs:enable
359 $this->lines = array();
360
361 $sql = 'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
362 $sql .= ' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
363 $sql .= ' l.total_ht, l.total_tva, l.total_ttc,';
364 $sql .= ' l.rang, l.special_code,';
365 $sql .= ' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
366 $sql .= ' p.label as product_label, p.description as product_desc';
367 $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet_rec as l';
368 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
369 $sql .= ' WHERE l.fk_fichinter = '.((int) $this->id);
370
371 dol_syslog('FichinterRec::fetch_lines', LOG_DEBUG);
372
373 $result = $this->db->query($sql);
374 if ($result) {
375 $num = $this->db->num_rows($result);
376 $i = 0;
377 while ($i < $num) {
378 $objp = $this->db->fetch_object($result);
379
380 $line = new FichinterLigne($this->db);
381 $line->id = $objp->rowid;
382 $line->label = $objp->custom_label; // Label line
383 $line->desc = $objp->description; // Description line
384 $line->product_type = $objp->product_type; // Type of line
385 $line->product_ref = $objp->product_ref; // Ref product
386 $line->product_label = $objp->product_label; // Label product
387 $line->product_desc = $objp->product_desc; // Description product
388 $line->fk_product_type = $objp->fk_product_type; // Type in product
389 $line->qty = $objp->qty;
390 $line->duree = $objp->duree;
391 $line->duration = $objp->duree;
392 $line->date = $objp->date;
393 $line->subprice = $objp->subprice;
394 $line->tva_tx = $objp->tva_tx;
395 $line->remise_percent = $objp->remise_percent;
396 $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except : "";
397 $line->fk_product = $objp->fk_product;
398 $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits : "";
399 $line->total_ht = $objp->total_ht;
400 $line->total_tva = $objp->total_tva;
401 $line->total_ttc = $objp->total_ttc;
402 $line->rang = $objp->rang;
403 $line->special_code = $objp->special_code;
404 $line->fk_unit = $objp->fk_unit;
405
406 $this->lines[$i] = $line;
407
408 $i++;
409 }
410
411 $this->db->free($result);
412 return 1;
413 } else {
414 $this->error = $this->db->error();
415 return -3;
416 }
417 }
418
419
427 public function delete(User $user, $notrigger = 0)
428 {
429 $rowid = $this->id;
430
431 dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
432
433 $error = 0;
434 $this->db->begin();
435
436 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
437 dol_syslog($sql);
438 if ($this->db->query($sql)) {
439 $sql = "DELETE FROM ".MAIN_DB_PREFIX."fichinter_rec WHERE rowid = ".((int) $rowid);
440 dol_syslog($sql);
441 if (!$this->db->query($sql)) {
442 $this->error = $this->db->lasterror();
443 $error = -1;
444 }
445 } else {
446 $this->error = $this->db->lasterror();
447 $error = -2;
448 }
449
450 if (!$error) {
451 $this->db->commit();
452 return 1;
453 } else {
454 $this->db->rollback();
455 return $error;
456 }
457 }
458
459
482 public function addline($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 = '', $pu_ttc = 0, $type = 0, $special_code = 0, $label = '', $fk_unit = null)
483 {
484 global $mysoc;
485
486 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
487
488 // Check parameters
489 if ($type < 0) {
490 $this->error = 'Bad value for parameter type';
491 return -1;
492 }
493
494 if ($this->status == self::STATUS_DRAFT) {
495 // Clean parameters
496 $remise_percent = price2num($remise_percent);
497 $qty = price2num($qty);
498 if (!$qty) {
499 $qty = 1;
500 }
501 if (!$info_bits) {
502 $info_bits = 0;
503 }
504 $pu_ht = price2num($pu_ht);
505 $pu_ttc = price2num($pu_ttc);
506 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
507 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
508 }
509
510 if ($price_base_type == 'HT') {
511 $pu = $pu_ht;
512 } else {
513 $pu = $pu_ttc;
514 }
515
516 // Calcul du total TTC et de la TVA pour la ligne a partir de
517 // qty, pu, remise_percent et txtva
518 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
519 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
520 $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
521
522 $total_ht = $tabprice[0];
523 $total_tva = $tabprice[1];
524 $total_ttc = $tabprice[2];
525
526 $pu_ht = $tabprice[3];
527
528 $product_type = $type;
529 if ($fk_product) {
530 $product = new Product($this->db);
531 $result = $product->fetch($fk_product);
532 $product_type = $product->type;
533 }
534
535 $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinterdet_rec (";
536 $sql .= "fk_fichinter";
537 $sql .= ", label";
538 $sql .= ", description";
539 $sql .= ", date";
540 $sql .= ", duree";
541 //$sql.= ", price";
542 //$sql.= ", qty";
543 //$sql.= ", tva_tx";
544 $sql .= ", fk_product";
545 $sql .= ", product_type";
546 $sql .= ", remise_percent";
547 $sql .= ", subprice";
548 $sql .= ", total_ht";
549 $sql .= ", total_tva";
550 $sql .= ", total_ttc";
551 $sql .= ", rang";
552 //$sql.= ", special_code";
553 $sql .= ", fk_unit";
554 $sql .= ") VALUES (";
555 $sql .= (int) $this->id;
556 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
557 $sql .= ", ".(!empty($desc) ? "'".$this->db->escape($desc)."'" : "null");
558 $sql .= ", ".(!empty($date) ? "'".$this->db->idate($date)."'" : "null");
559 $sql .= ", ".$duration;
560 //$sql.= ", ".price2num($pu_ht);
561 //$sql.= ", ".(!empty($qty)? $qty :(!empty($duration)? $duration :"null"));
562 //$sql.= ", ".price2num($txtva);
563 $sql .= ", ".(!empty($fk_product) ? $fk_product : "null");
564 $sql .= ", ".$product_type;
565 $sql .= ", ".(!empty($remise_percent) ? $remise_percent : "null");
566 $sql.= ", '".price2num($pu_ht)."'";
567 $sql .= ", '".price2num($total_ht)."'";
568 $sql .= ", '".price2num($total_tva)."'";
569 $sql .= ", '".price2num($total_ttc)."'";
570 $sql .= ", ".(int) $rang;
571 //$sql.= ", ".$special_code;
572 $sql .= ", ".(!empty($fk_unit) ? $fk_unit : "null");
573 $sql .= ")";
574
575 dol_syslog(get_class($this)."::addline", LOG_DEBUG);
576 if ($this->db->query($sql)) {
577 return 1;
578 } else {
579 $this->error = $this->db->lasterror();
580 return -1;
581 }
582 } else {
583 $this->error = 'Bad status of recurring intervention. Must be draft status to allow addition of lines';
584 return -1;
585 }
586 }
587
588
589 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
598 public function set_auto($user, $freq, $courant)
599 {
600 // phpcs:enable
601 if ($user->hasRight('fichinter', 'creer')) {
602 $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter_rec ";
603 $sql .= " SET frequency='".$this->db->escape($freq)."'";
604 $sql .= ", date_last_gen='".$this->db->escape($courant)."'";
605 $sql .= " WHERE rowid = ".((int) $this->id);
606
607 $resql = $this->db->query($sql);
608
609 if ($resql) {
610 $this->frequency = $freq;
611 $this->date_last_gen = $courant;
612 return 0;
613 } else {
614 dol_print_error($this->db);
615 return -1;
616 }
617 } else {
618 return -2;
619 }
620 }
621
632 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '')
633 {
634 global $langs, $hookmanager;
635
636 $result = '';
637 $label = $langs->trans("ShowInterventionModel").': '.$this->ref;
638
639 $url = DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$this->id;
640
641 if ($short) {
642 return $url;
643 }
644
645 $picto = 'intervention';
646
647 $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
648 $linkend = '</a>';
649
650 if ($withpicto) {
651 $result .= $link.img_object($label, $picto, 'class="classfortooltip"').$linkend;
652 }
653 if ($withpicto && $withpicto != 2) {
654 $result .= ' ';
655 }
656 if ($withpicto != 2) {
657 $result .= $link.$this->ref.$linkend;
658 }
659 global $action;
660 $hookmanager->initHooks(array($this->element . 'dao'));
661 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
662 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
663 if ($reshook > 0) {
664 $result = $hookmanager->resPrint;
665 } else {
666 $result .= $hookmanager->resPrint;
667 }
668 return $result;
669 }
670
671
679 public function initAsSpecimen()
680 {
681 //$now = dol_now();
682 //$arraynow = dol_getdate($now);
683 //$nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
684
685 parent::initAsSpecimen();
686
687 $this->usenewprice = 1;
688 }
689
698 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
699 {
700 $tables = array('fichinter_rec');
701
702 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
703 }
704
713 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
714 {
715 $tables = array(
716 'fichinterdet_rec'
717 );
718
719 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
720 }
721
729 public function setFrequencyAndUnit($frequency, $unit)
730 {
731 if (!$this->table_element) {
732 dol_syslog(get_class($this)."::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
733 return -1;
734 }
735
736 if (!empty($frequency) && empty($unit)) {
737 dol_syslog(get_class($this)."::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
738 return -2;
739 }
740
741 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
742 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
743 if (!empty($unit)) {
744 $sql .= ', unit_frequency = "'.$this->db->escape($unit).'"';
745 }
746 $sql .= " WHERE rowid = ".((int) $this->id);
747
748 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
749 if ($this->db->query($sql)) {
750 $this->frequency = $frequency;
751 if (!empty($unit)) {
752 $this->unit_frequency = $unit;
753 }
754 return 1;
755 } else {
756 dol_print_error($this->db);
757 return -1;
758 }
759 }
760
768 public function setNextDate($date, $increment_nb_gen_done = 0)
769 {
770 if (!$this->table_element) {
771 dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
772 return -1;
773 }
774 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
775 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
776 if ($increment_nb_gen_done > 0) {
777 $sql .= ', nb_gen_done = nb_gen_done + 1';
778 }
779 $sql .= " WHERE rowid = ".((int) $this->id);
780
781 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
782 if ($this->db->query($sql)) {
783 $this->date_when = $date;
784 if ($increment_nb_gen_done > 0) {
785 $this->nb_gen_done++;
786 }
787 return 1;
788 } else {
789 dol_print_error($this->db);
790 return -1;
791 }
792 }
793
800 public function setMaxPeriod($nb)
801 {
802 if (!$this->table_element) {
803 dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
804 return -1;
805 }
806
807 if (empty($nb)) {
808 $nb = 0;
809 }
810
811 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
812 $sql .= ' SET nb_gen_max = '.((int) $nb);
813 $sql .= ' WHERE rowid = '.((int) $this->id);
814
815 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
816 if ($this->db->query($sql)) {
817 $this->nb_gen_max = $nb;
818 return 1;
819 } else {
820 dol_print_error($this->db);
821 return -1;
822 }
823 }
824
831 public function setAutoValidate($validate)
832 {
833 if (!$this->table_element) {
834 dol_syslog(get_class($this)."::setAutoValidate called with property table_element not defined", LOG_ERR);
835 return -1;
836 }
837
838 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
839 $sql .= ' SET auto_validate = '.((int) $validate);
840 $sql .= ' WHERE rowid = '.((int) $this->id);
841
842 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
843 if ($this->db->query($sql)) {
844 $this->auto_validate = $validate;
845 return 1;
846 } else {
847 dol_print_error($this->db);
848 return -1;
849 }
850 }
851
857 public function updateNbGenDone()
858 {
859 if (!$this->table_element) {
860 dol_syslog(get_class($this)."::updateNbGenDone called with property table_element not defined", LOG_ERR);
861 return -1;
862 }
863
864 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
865 $sql .= ' SET nb_gen_done = nb_gen_done + 1';
866 $sql .= ' , date_last_gen = now()';
867 // si on et arrivé à la fin des génération
868 if ($this->nb_gen_max == $this->nb_gen_done + 1) {
869 $sql .= ' , statut = 1';
870 }
871
872 $sql .= " WHERE rowid = ".((int) $this->id);
873
874 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
875 if ($this->db->query($sql)) {
876 $this->nb_gen_done = $this->nb_gen_done + 1;
877 $this->nb_gen_done = dol_now();
878 return 1;
879 } else {
880 dol_print_error($this->db);
881 return -1;
882 }
883 }
884}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$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.
Classe de gestion des factures recurrentes/Modeles.
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.
addline($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='', $pu_ttc=0, $type=0, $special_code=0, $label='', $fk_unit=null)
Add a line to fichinter rec.
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.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926
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:86