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';
44 public $element =
'fichinterrec';
45 public $table_element =
'fichinter_rec';
46 public $table_element_line =
'fichinterdet_rec';
56 public $picto =
'intervention';
66 public $auto_validate;
81 public $unit_frequency;
91 public $date_last_gen;
116 public $special_code;
121 public $usenewprice = 0;
133 $this->labelStatus[0] =
'Draft';
134 $this->labelStatus[1] =
'Closed';
136 $this->labelStatusShort[0] =
'Draft';
137 $this->labelStatusShort[1] =
'Closed';
159 public function create($user, $notrigger = 0)
167 $this->title = trim($this->title);
176 $result = $fichintsrc->fetch($this->id_origin);
178 $result = $fichintsrc->fetch_lines();
182 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
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";
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');
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);
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");
217 $sql .=
", null, null";
220 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
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');
228 $sql .=
", ".((int) $this->nb_gen_max);
232 if ($this->db->query($sql)) {
233 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
238 $num = count($fichintsrc->lines);
239 for ($i = 0; $i < $num; $i++) {
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,
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
261 if ($result_insert < 0) {
267 $this->db->rollback();
274 $this->error = $this->db->error().
' sql='.$sql;
275 $this->db->rollback();
279 $this->db->rollback();
293 public function fetch($rowid = 0, $ref =
'', $ref_ext =
'')
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';
303 $sql .=
" WHERE f.rowid = ".((int) $rowid);
305 $sql .=
" WHERE f.title = '".$this->db->escape($ref).
"'";
308 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
310 $result = $this->db->query($sql);
312 if ($this->db->num_rows($result)) {
313 $obj = $this->db->fetch_object($result);
316 $this->title = $obj->title;
317 $this->
ref = $obj->title;
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;
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;
343 $this->error = $this->db->error();
348 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
349 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
353 $this->error = $this->db->error();
369 $this->lines = array();
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);
381 dol_syslog(
'FichinterRec::fetch_lines', LOG_DEBUG);
383 $result = $this->db->query($sql);
385 $num = $this->db->num_rows($result);
388 $objp = $this->db->fetch_object($result);
391 $line->id = $objp->rowid;
392 $line->label = $objp->custom_label;
393 $line->desc = $objp->description;
394 $line->product_type = $objp->product_type;
395 $line->product_ref = $objp->product_ref;
396 $line->product_label = $objp->product_label;
397 $line->product_desc = $objp->product_desc;
398 $line->fk_product_type = $objp->fk_product_type;
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;
416 $this->lines[$i] = $line;
421 $this->db->free($result);
424 $this->error = $this->db->error();
437 public function delete(
User $user, $notrigger = 0)
441 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
446 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
448 if ($this->db->query($sql)) {
449 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".((int) $rowid);
451 if (!$this->db->query($sql)) {
452 $this->error = $this->db->lasterror();
456 $this->error = $this->db->lasterror();
464 $this->db->rollback();
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)
496 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
500 $this->error =
'Bad value for parameter type';
504 if ($this->
status == self::STATUS_DRAFT) {
506 $remise_percent =
price2num($remise_percent);
516 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
520 if ($price_base_type ==
'HT') {
530 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
532 $total_ht = $tabprice[0];
533 $total_tva = $tabprice[1];
534 $total_ttc = $tabprice[2];
536 $pu_ht = $tabprice[3];
538 $product_type = $type;
540 $product =
new Product($this->db);
541 $result = $product->fetch($fk_product);
542 $product_type = $product->type;
545 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
546 $sql .=
"fk_fichinter";
548 $sql .=
", description";
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";
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;
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;
581 $sql .=
", ".(!empty($fk_unit) ? $fk_unit :
"null");
584 dol_syslog(get_class($this).
"::addLineRec", LOG_DEBUG);
585 if ($this->db->query($sql)) {
588 $this->error = $this->db->lasterror();
592 $this->error =
'Bad status of recurring intervention. Must be draft status to allow addition of lines';
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);
616 $resql = $this->db->query($sql);
619 $this->frequency = $freq;
620 $this->date_last_gen = $courant;
641 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
643 global $langs, $hookmanager;
646 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
648 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
654 $picto =
'intervention';
656 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
660 $result .= $link.img_object($label, $picto,
'class="classfortooltip"').$linkend;
662 if ($withpicto && $withpicto != 2) {
665 if ($withpicto != 2) {
666 $result .= $link.$this->ref.$linkend;
669 $hookmanager->initHooks(array($this->element .
'dao'));
670 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
671 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
673 $result = $hookmanager->resPrint;
675 $result .= $hookmanager->resPrint;
694 parent::initAsSpecimen();
696 $this->usenewprice = 1;
711 $tables = array(
'fichinter_rec');
742 if (!$this->table_element) {
743 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
747 if (!empty($frequency) && empty($unit)) {
748 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
752 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
753 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
755 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
757 $sql .=
" WHERE rowid = ".((int) $this->
id);
759 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
760 if ($this->db->query($sql)) {
761 $this->frequency = $frequency;
763 $this->unit_frequency = $unit;
781 if (!$this->table_element) {
782 dol_syslog(get_class($this).
"::setNextDate was called on object with property table_element not defined", LOG_ERR);
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';
790 $sql .=
" WHERE rowid = ".((int) $this->
id);
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++;
813 if (!$this->table_element) {
814 dol_syslog(get_class($this).
"::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
822 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
823 $sql .=
' SET nb_gen_max = '.((int) $nb);
824 $sql .=
' WHERE rowid = '.((int) $this->
id);
826 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
827 if ($this->db->query($sql)) {
828 $this->nb_gen_max = $nb;
844 if (!$this->table_element) {
845 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
849 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
850 $sql .=
' SET auto_validate = '.((int) $validate);
851 $sql .=
' WHERE rowid = '.((int) $this->
id);
853 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
854 if ($this->db->query($sql)) {
855 $this->auto_validate = $validate;
870 if (!$this->table_element) {
871 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
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()';
879 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
880 $sql .=
' , status = 1';
883 $sql .=
" WHERE rowid = ".((int) $this->
id);
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();
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...
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.