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';
41 public $element =
'fichinterrec';
42 public $table_element =
'fichinter_rec';
43 public $table_element_line =
'fichinterdet_rec';
48 public $fk_element =
'fk_fichinter';
58 public $picto =
'intervention';
74 public $auto_validate;
86 public $unit_frequency;
93 public $date_last_gen;
110 public $special_code;
112 public $usenewprice = 0;
124 $this->labelStatus[0] =
'Draft';
125 $this->labelStatus[1] =
'Closed';
127 $this->labelStatusShort[0] =
'Draft';
128 $this->labelStatusShort[1] =
'Closed';
150 public function create($user, $notrigger = 0)
158 $this->title = trim($this->title);
167 $result = $fichintsrc->fetch($this->id_origin);
169 $result = $fichintsrc->fetch_lines();
173 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
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";
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');
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);
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");
208 $sql .=
", null, null";
211 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
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');
219 $sql .=
", ".((int) $this->nb_gen_max);
223 if ($this->db->query($sql)) {
224 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
229 $num = count($fichintsrc->lines);
230 for ($i = 0; $i < $num; $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,
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
252 if ($result_insert < 0) {
258 $this->db->rollback();
265 $this->error = $this->db->error().
' sql='.$sql;
266 $this->db->rollback();
270 $this->db->rollback();
284 public function fetch($rowid = 0, $ref =
'', $ref_ext =
'')
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';
293 $sql .=
" WHERE f.rowid = ".((int) $rowid);
295 $sql .=
" WHERE f.title = '".$this->db->escape($ref).
"'";
298 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
300 $result = $this->db->query($sql);
302 if ($this->db->num_rows($result)) {
303 $obj = $this->db->fetch_object($result);
306 $this->title = $obj->title;
307 $this->
ref = $obj->title;
309 $this->datec = $obj->datec;
310 $this->duration = $obj->duree;
311 $this->socid = $obj->fk_soc;
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;
333 $this->error = $this->db->error();
338 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
339 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
343 $this->error = $this->db->error();
359 $this->lines = array();
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);
371 dol_syslog(
'FichinterRec::fetch_lines', LOG_DEBUG);
373 $result = $this->db->query($sql);
375 $num = $this->db->num_rows($result);
378 $objp = $this->db->fetch_object($result);
381 $line->id = $objp->rowid;
382 $line->label = $objp->custom_label;
383 $line->desc = $objp->description;
384 $line->product_type = $objp->product_type;
385 $line->product_ref = $objp->product_ref;
386 $line->product_label = $objp->product_label;
387 $line->product_desc = $objp->product_desc;
388 $line->fk_product_type = $objp->fk_product_type;
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;
406 $this->lines[$i] = $line;
411 $this->db->free($result);
414 $this->error = $this->db->error();
427 public function delete(
User $user, $notrigger = 0)
431 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
436 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
438 if ($this->db->query($sql)) {
439 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".((int) $rowid);
441 if (!$this->db->query($sql)) {
442 $this->error = $this->db->lasterror();
446 $this->error = $this->db->lasterror();
454 $this->db->rollback();
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)
486 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
490 $this->error =
'Bad value for parameter type';
494 if ($this->
status == self::STATUS_DRAFT) {
496 $remise_percent =
price2num($remise_percent);
506 if (!preg_match(
'/\((.*)\)/', $txtva)) {
510 if ($price_base_type ==
'HT') {
520 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
522 $total_ht = $tabprice[0];
523 $total_tva = $tabprice[1];
524 $total_ttc = $tabprice[2];
526 $pu_ht = $tabprice[3];
528 $product_type = $type;
530 $product =
new Product($this->db);
531 $result = $product->fetch($fk_product);
532 $product_type = $product->type;
535 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
536 $sql .=
"fk_fichinter";
538 $sql .=
", description";
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";
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;
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;
572 $sql .=
", ".(!empty($fk_unit) ? $fk_unit :
"null");
575 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
576 if ($this->db->query($sql)) {
579 $this->error = $this->db->lasterror();
583 $this->error =
'Bad status of recurring intervention. Must be draft status to allow addition of lines';
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);
607 $resql = $this->db->query($sql);
610 $this->frequency = $freq;
611 $this->date_last_gen = $courant;
632 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
634 global $langs, $hookmanager;
637 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
639 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
645 $picto =
'intervention';
647 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
651 $result .= $link.img_object($label, $picto,
'class="classfortooltip"').$linkend;
653 if ($withpicto && $withpicto != 2) {
656 if ($withpicto != 2) {
657 $result .= $link.$this->ref.$linkend;
660 $hookmanager->initHooks(array($this->element .
'dao'));
661 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
662 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
664 $result = $hookmanager->resPrint;
666 $result .= $hookmanager->resPrint;
685 parent::initAsSpecimen();
687 $this->usenewprice = 1;
700 $tables = array(
'fichinter_rec');
731 if (!$this->table_element) {
732 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
736 if (!empty($frequency) && empty($unit)) {
737 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
741 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
742 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
744 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
746 $sql .=
" WHERE rowid = ".((int) $this->
id);
748 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
749 if ($this->db->query($sql)) {
750 $this->frequency = $frequency;
752 $this->unit_frequency = $unit;
770 if (!$this->table_element) {
771 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
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';
779 $sql .=
" WHERE rowid = ".((int) $this->
id);
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++;
802 if (!$this->table_element) {
803 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
811 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
812 $sql .=
' SET nb_gen_max = '.((int) $nb);
813 $sql .=
' WHERE rowid = '.((int) $this->
id);
815 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
816 if ($this->db->query($sql)) {
817 $this->nb_gen_max = $nb;
833 if (!$this->table_element) {
834 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
838 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
839 $sql .=
' SET auto_validate = '.((int) $validate);
840 $sql .=
' WHERE rowid = '.((int) $this->
id);
842 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
843 if ($this->db->query($sql)) {
844 $this->auto_validate = $validate;
859 if (!$this->table_element) {
860 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
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()';
868 if ($this->nb_gen_max == $this->nb_gen_done + 1) {
869 $sql .=
' , statut = 1';
872 $sql .=
" WHERE rowid = ".((int) $this->
id);
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();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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
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.