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';
51 public $fk_element =
'fk_fichinter';
61 public $picto =
'intervention';
77 public $auto_validate;
89 public $unit_frequency;
96 public $date_last_gen;
117 public $special_code;
119 public $usenewprice = 0;
131 $this->labelStatus[0] =
'Draft';
132 $this->labelStatus[1] =
'Closed';
134 $this->labelStatusShort[0] =
'Draft';
135 $this->labelStatusShort[1] =
'Closed';
157 public function create($user, $notrigger = 0)
165 $this->title = trim($this->title);
174 $result = $fichintsrc->fetch($this->id_origin);
176 $result = $fichintsrc->fetch_lines();
180 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
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";
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');
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);
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");
215 $sql .=
", null, null";
218 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
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');
226 $sql .=
", ".((int) $this->nb_gen_max);
230 if ($this->db->query($sql)) {
231 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
236 $num = count($fichintsrc->lines);
237 for ($i = 0; $i < $num; $i++) {
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,
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
259 if ($result_insert < 0) {
265 $this->db->rollback();
272 $this->error = $this->db->error().
' sql='.$sql;
273 $this->db->rollback();
277 $this->db->rollback();
291 public function fetch($rowid = 0, $ref =
'', $ref_ext =
'')
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';
301 $sql .=
" WHERE f.rowid = ".((int) $rowid);
303 $sql .=
" WHERE f.title = '".$this->db->escape($ref).
"'";
306 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
308 $result = $this->db->query($sql);
310 if ($this->db->num_rows($result)) {
311 $obj = $this->db->fetch_object($result);
314 $this->title = $obj->title;
315 $this->
ref = $obj->title;
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;
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;
341 $this->error = $this->db->error();
346 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
347 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
351 $this->error = $this->db->error();
367 $this->lines = array();
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);
379 dol_syslog(
'FichinterRec::fetch_lines', LOG_DEBUG);
381 $result = $this->db->query($sql);
383 $num = $this->db->num_rows($result);
386 $objp = $this->db->fetch_object($result);
389 $line->id = $objp->rowid;
390 $line->label = $objp->custom_label;
391 $line->desc = $objp->description;
392 $line->product_type = $objp->product_type;
393 $line->product_ref = $objp->product_ref;
394 $line->product_label = $objp->product_label;
395 $line->product_desc = $objp->product_desc;
396 $line->fk_product_type = $objp->fk_product_type;
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;
414 $this->lines[$i] = $line;
419 $this->db->free($result);
422 $this->error = $this->db->error();
435 public function delete(
User $user, $notrigger = 0)
439 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
444 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
446 if ($this->db->query($sql)) {
447 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".((int) $rowid);
449 if (!$this->db->query($sql)) {
450 $this->error = $this->db->lasterror();
454 $this->error = $this->db->lasterror();
462 $this->db->rollback();
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)
494 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
498 $this->error =
'Bad value for parameter type';
502 if ($this->
status == self::STATUS_DRAFT) {
504 $remise_percent =
price2num($remise_percent);
514 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
518 if ($price_base_type ==
'HT') {
528 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
530 $total_ht = $tabprice[0];
531 $total_tva = $tabprice[1];
532 $total_ttc = $tabprice[2];
534 $pu_ht = $tabprice[3];
536 $product_type = $type;
538 $product =
new Product($this->db);
539 $result = $product->fetch($fk_product);
540 $product_type = $product->type;
543 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
544 $sql .=
"fk_fichinter";
546 $sql .=
", description";
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";
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;
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;
579 $sql .=
", ".(!empty($fk_unit) ? $fk_unit :
"null");
582 dol_syslog(get_class($this).
"::addLineRec", LOG_DEBUG);
583 if ($this->db->query($sql)) {
586 $this->error = $this->db->lasterror();
590 $this->error =
'Bad status of recurring intervention. Must be draft status to allow addition of lines';
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);
614 $resql = $this->db->query($sql);
617 $this->frequency = $freq;
618 $this->date_last_gen = $courant;
639 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
641 global $langs, $hookmanager;
644 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
646 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
652 $picto =
'intervention';
654 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
658 $result .= $link.img_object($label, $picto,
'class="classfortooltip"').$linkend;
660 if ($withpicto && $withpicto != 2) {
663 if ($withpicto != 2) {
664 $result .= $link.$this->ref.$linkend;
667 $hookmanager->initHooks(array($this->element .
'dao'));
668 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
669 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
671 $result = $hookmanager->resPrint;
673 $result .= $hookmanager->resPrint;
692 parent::initAsSpecimen();
694 $this->usenewprice = 1;
709 $tables = array(
'fichinter_rec');
740 if (!$this->table_element) {
741 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
745 if (!empty($frequency) && empty($unit)) {
746 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
750 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
751 $sql .=
' SET frequency = '.($frequency ? $this->db->escape($frequency) :
'null');
753 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
755 $sql .=
" WHERE rowid = ".((int) $this->
id);
757 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
758 if ($this->db->query($sql)) {
759 $this->frequency = $frequency;
761 $this->unit_frequency = $unit;
779 if (!$this->table_element) {
780 dol_syslog(get_class($this).
"::setNextDate was called on object with property table_element not defined", LOG_ERR);
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';
788 $sql .=
" WHERE rowid = ".((int) $this->
id);
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++;
811 if (!$this->table_element) {
812 dol_syslog(get_class($this).
"::setMaxPeriod was called on object with property table_element not defined", LOG_ERR);
820 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
821 $sql .=
' SET nb_gen_max = '.((int) $nb);
822 $sql .=
' WHERE rowid = '.((int) $this->
id);
824 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
825 if ($this->db->query($sql)) {
826 $this->nb_gen_max = $nb;
842 if (!$this->table_element) {
843 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
847 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
848 $sql .=
' SET auto_validate = '.((int) $validate);
849 $sql .=
' WHERE rowid = '.((int) $this->
id);
851 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
852 if ($this->db->query($sql)) {
853 $this->auto_validate = $validate;
868 if (!$this->table_element) {
869 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
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()';
877 if ($this->nb_gen_max <= $this->nb_gen_done + 1) {
878 $sql .=
' , status = 1';
881 $sql .=
" WHERE rowid = ".((int) $this->
id);
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();
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...
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.
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