31 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
41 public $element =
'fichinterrec';
42 public $table_element =
'fichinter_rec';
43 public $table_element_line =
'fichinter_rec';
48 public $fk_element =
'fk_fichinter';
58 public $picto =
'intervention';
76 public $date_last_gen;
95 public $usenewprice = 0;
107 $this->statuts[0] =
'Draft';
108 $this->statuts[1] =
'Closed';
110 $this->statuts_short[0] =
'Draft';
111 $this->statuts_short[1] =
'Closed';
113 $this->statuts_logo[0] =
'statut0';
114 $this->statuts_logo[1] =
'statut1';
136 public function create($user, $notrigger = 0)
144 $this->title = trim($this->title);
153 $result = $fichintsrc->fetch($this->id_origin);
154 $result = $fichintsrc->fetch_lines(1);
159 $this->brouillon = 1;
161 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
167 $sql .=
", description";
168 $sql .=
", note_private";
169 $sql .=
", note_public";
170 $sql .=
", fk_user_author";
171 $sql .=
", fk_projet";
172 $sql .=
", fk_contrat";
173 $sql .=
", modelpdf";
175 $sql .=
", frequency";
176 $sql .=
", unit_frequency";
177 $sql .=
", date_when";
178 $sql .=
", date_last_gen";
179 $sql .=
", nb_gen_done";
180 $sql .=
", nb_gen_max";
183 $sql .=
") VALUES (";
184 $sql .=
"'".$this->db->escape($this->title).
"'";
185 $sql .=
", ".($this->socid > 0 ? $this->socid :
'null');
186 $sql .=
", ".$conf->entity;
187 $sql .=
", '".$this->db->idate($now).
"'";
188 $sql .=
", ".(!empty($fichintsrc->duration) ? $fichintsrc->duration :
'0');
190 $sql .=
", ".(!empty($fichintsrc->note_private) ? (
"'".$this->db->escape($fichintsrc->note_private).
"'") :
"null");
191 $sql .=
", ".(!empty($fichintsrc->note_public) ? (
"'".$this->db->escape($fichintsrc->note_public).
"'") :
"null");
192 $sql .=
", ".$user->id;
194 if ($this->socid == $fichintsrc->socid) {
195 $sql .=
", ".(!empty($fichintsrc->fk_project) ? $fichintsrc->fk_project :
"null");
196 $sql .=
", ".(!empty($fichintsrc->fk_contrat) ? $fichintsrc->fk_contrat :
"null");
198 $sql .=
", null, null";
201 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
204 $sql .=
", ".(!empty($this->frequency) ? $this->frequency :
"null");
205 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
206 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'null');
207 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'null');
209 $sql .=
", ".$this->nb_gen_max;
213 if ($this->
db->query($sql)) {
214 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
219 $num = count($fichintsrc->lines);
220 for ($i = 0; $i < $num; $i++) {
222 $result_insert = $this->
addline(
223 $fichintsrc->lines[$i]->desc,
224 $fichintsrc->lines[$i]->duration,
225 $fichintsrc->lines[$i]->datei,
226 $fichintsrc->lines[$i]->rang,
227 $fichintsrc->lines[$i]->subprice,
228 $fichintsrc->lines[$i]->qty,
229 $fichintsrc->lines[$i]->tva_tx,
230 $fichintsrc->lines[$i]->fk_product,
231 $fichintsrc->lines[$i]->remise_percent,
236 $fichintsrc->lines[$i]->product_type,
237 $fichintsrc->lines[$i]->special_code,
238 $fichintsrc->lines[$i]->label,
239 $fichintsrc->lines[$i]->fk_unit
242 if ($result_insert < 0)
247 $this->
db->rollback();
253 $this->error = $this->
db->error().
' sql='.$sql;
254 $this->
db->rollback();
258 $this->
db->rollback();
272 public function fetch($rowid = 0, $ref =
'', $ref_ext =
'')
274 $sql =
'SELECT f.titre as title, f.fk_soc';
275 $sql .=
', f.datec, f.duree, f.fk_projet, f.fk_contrat, f.description';
276 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
277 $sql .=
', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
278 $sql .=
', f.note_private, f.note_public, f.fk_user_author';
279 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinter_rec as f';
280 if ($rowid > 0) $sql .=
' WHERE f.rowid='.$rowid;
281 elseif ($ref) $sql .=
" WHERE f.titre='".$this->db->escape($ref).
"'";
283 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
285 $result = $this->
db->query($sql);
287 if ($this->
db->num_rows($result)) {
288 $obj = $this->
db->fetch_object($result);
291 $this->titre = $obj->title;
292 $this->title = $obj->title;
293 $this->ref = $obj->title;
295 $this->datec = $obj->datec;
296 $this->duration = $obj->duree;
297 $this->socid = $obj->fk_soc;
299 $this->fk_project = $obj->fk_projet;
300 $this->fk_contrat = $obj->fk_contrat;
301 $this->note_private = $obj->note_private;
302 $this->note_public = $obj->note_public;
303 $this->user_author = $obj->fk_user_author;
304 $this->model_pdf = $obj->model_pdf;
305 $this->modelpdf = $obj->model_pdf;
306 $this->rang = $obj->rang;
307 $this->special_code = $obj->special_code;
308 $this->frequency = $obj->frequency;
309 $this->unit_frequency = $obj->unit_frequency;
310 $this->date_when = $this->
db->jdate($obj->date_when);
311 $this->date_last_gen = $this->
db->jdate($obj->date_last_gen);
312 $this->nb_gen_done = $obj->nb_gen_done;
313 $this->nb_gen_max = $obj->nb_gen_max;
314 $this->auto_validate = $obj->auto_validate;
316 $this->brouillon = 1;
321 $this->error = $this->
db->error();
326 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
327 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
331 $this->error = $this->
db->error();
347 $sql =
'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, ';
348 $sql .=
' l.price, l.qty, l.tva_tx, l.remise, l.remise_percent, l.subprice, l.duree, ';
349 $sql .=
' l.total_ht, l.total_tva, l.total_ttc,';
350 $sql .=
' l.rang, l.special_code,';
351 $sql .=
' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
352 $sql .=
' p.label as product_label, p.description as product_desc';
353 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet_rec as l';
354 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
355 $sql .=
' WHERE l.fk_fichinter = '.$this->id;
357 dol_syslog(
'FichInter-rec::fetch_lines', LOG_DEBUG);
358 $result = $this->
db->query($sql);
360 $num = $this->
db->num_rows($result);
363 $objp = $this->
db->fetch_object($result);
366 $line->id = $objp->rowid;
367 $line->label = $objp->custom_label;
368 $line->desc = $objp->description;
369 $line->product_type = $objp->product_type;
370 $line->product_ref = $objp->product_ref;
371 $line->product_label = $objp->product_label;
372 $line->product_desc = $objp->product_desc;
373 $line->fk_product_type = $objp->fk_product_type;
374 $line->qty = $objp->qty;
375 $line->duree = $objp->duree;
376 $line->duration = $objp->duree;
377 $line->datei = $objp->date;
378 $line->subprice = $objp->subprice;
379 $line->tva_tx = $objp->tva_tx;
380 $line->remise_percent = $objp->remise_percent;
381 $line->fk_remise_except = $objp->fk_remise_except;
382 $line->fk_product = $objp->fk_product;
383 $line->date_start = $objp->date_start;
384 $line->date_end = $objp->date_end;
385 $line->date_start = $objp->date_start;
386 $line->date_end = $objp->date_end;
387 $line->info_bits = $objp->info_bits;
388 $line->total_ht = $objp->total_ht;
389 $line->total_tva = $objp->total_tva;
390 $line->total_ttc = $objp->total_ttc;
391 $line->code_ventilation = $objp->fk_code_ventilation;
392 $line->rang = $objp->rang;
393 $line->special_code = $objp->special_code;
394 $line->fk_unit = $objp->fk_unit;
397 $line->price = $objp->price;
398 $line->remise = $objp->remise;
400 $this->lines[$i] = $line;
405 $this->
db->free($result);
408 $this->error = $this->
db->error();
422 public function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1)
424 if (empty($rowid)) $rowid = $this->
id;
426 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
431 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".$rowid;
433 if ($this->
db->query($sql)) {
434 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".$rowid;
436 if (!$this->
db->query($sql)) {
437 $this->error = $this->
db->lasterror();
441 $this->error = $this->
db->lasterror();
449 $this->
db->rollback();
477 public function addline($desc, $duration, $datei,
$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)
481 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
484 if ($type < 0)
return -1;
486 if ($this->brouillon) {
488 $remise_percent =
price2num($remise_percent);
491 if (!$info_bits) $info_bits = 0;
494 if (!preg_match(
'/\((.*)\)/', $txtva)) {
498 if ($price_base_type ==
'HT') {
508 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
510 $total_ht = $tabprice[0];
511 $total_tva = $tabprice[1];
512 $total_ttc = $tabprice[2];
514 $product_type = $type;
517 $result = $product->fetch($fk_product);
518 $product_type = $product->type;
521 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
522 $sql .=
"fk_fichinter";
524 $sql .=
", description";
530 $sql .=
", fk_product";
531 $sql .=
", product_type";
532 $sql .=
", remise_percent";
535 $sql .=
", total_ht";
536 $sql .=
", total_tva";
537 $sql .=
", total_ttc";
541 $sql .=
") VALUES (";
542 $sql .= (int) $this->
id;
543 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
544 $sql .=
", ".(!empty($desc) ?
"'".$this->db->escape($desc).
"'" :
"null");
545 $sql .=
", ".(!empty($datei) ?
"'".$this->db->idate($datei).
"'" :
"null");
546 $sql .=
", ".$duration;
550 $sql .=
", ".(!empty($fk_product) ? $fk_product :
"null");
551 $sql .=
", ".$product_type;
552 $sql .=
", ".(!empty($remise_percent) ? $remise_percent :
"null");
555 $sql .=
", '".price2num($total_ht).
"'";
556 $sql .=
", '".price2num($total_tva).
"'";
557 $sql .=
", '".price2num($total_ttc).
"'";
558 $sql .=
", ".(int)
$rang;
560 $sql .=
", ".(!empty($fk_unit) ? $fk_unit :
"null");
563 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
564 if ($this->
db->query($sql)) {
567 $this->error = $this->
db->lasterror();
586 if ($user->rights->fichinter->creer) {
587 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter_rec ";
588 $sql .=
" SET frequency='".$this->db->escape($freq).
"'";
589 $sql .=
", date_last_gen='".$this->db->escape($courant).
"'";
590 $sql .=
" WHERE rowid = ".$this->id;
595 $this->frequency = $freq;
596 $this->date_last_gen = $courant;
617 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
622 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
624 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
626 if ($short)
return $url;
628 $picto =
'intervention';
630 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
634 $result .= $link.img_object($label, $picto,
'class="classfortooltip"').$linkend;
636 if ($withpicto && $withpicto != 2) {
639 if ($withpicto != 2) {
640 $result .= $link.$this->ref.$linkend;
656 global $user, $langs, $conf;
660 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
662 parent::initAsSpecimen($option);
664 $this->usenewprice = 1;
677 $tables = array(
'fichinter_rec');
692 if (!$this->table_element) {
693 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
697 if (!empty($frequency) && empty($unit)) {
698 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
702 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
703 $sql .=
' SET frequency = '.($frequency ? $this->
db->escape($frequency) :
'null');
705 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
707 $sql .=
' WHERE rowid = '.$this->id;
709 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
710 if ($this->
db->query($sql)) {
711 $this->frequency = $frequency;
712 if (!empty($unit)) $this->unit_frequency = $unit;
729 if (!$this->table_element) {
730 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
733 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
734 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
735 if ($increment_nb_gen_done > 0) $sql .=
', nb_gen_done = nb_gen_done + 1';
736 $sql .=
' WHERE rowid = '.$this->id;
738 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
739 if ($this->
db->query($sql)) {
740 $this->date_when = $date;
741 if ($increment_nb_gen_done > 0) $this->nb_gen_done++;
757 if (!$this->table_element) {
758 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
762 if (empty($nb)) $nb = 0;
764 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
765 $sql .=
' SET nb_gen_max = '.$nb;
766 $sql .=
' WHERE rowid = '.$this->id;
768 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
769 if ($this->
db->query($sql)) {
770 $this->nb_gen_max = $nb;
786 if (!$this->table_element) {
787 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
791 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
792 $sql .=
' SET auto_validate = '.$validate;
793 $sql .=
' WHERE rowid = '.$this->id;
795 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
796 if ($this->
db->query($sql)) {
797 $this->auto_validate = $validate;
812 if (!$this->table_element) {
813 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
817 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
818 $sql .=
' SET nb_gen_done = nb_gen_done + 1';
819 $sql .=
' , date_last_gen = now()';
821 if ($this->nb_gen_max == $this->nb_gen_done + 1)
822 $sql .=
' , statut = 1';
824 $sql .=
' WHERE rowid = '.$this->id;
826 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
827 if ($this->
db->query($sql)) {
828 $this->nb_gen_done = $this->nb_gen_done + 1;
829 $this->nb_gen_done =
dol_now();
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
getLibStatut($mode=0)
Returns the label status.
create($user, $notrigger=0)
Create a predefined fichinter.
</td > param sortfield sortorder printFieldListOption< tdclass="liste_titremaxwidthsearchright"></td ></tr >< trclass="liste_titre">< inputtype="checkbox"onClick="toggle(this)"/> Ref p ref Label p label Duration p duration center DesiredStock p desiredstock right StockLimitShort p seuil_stock_alerte right stock_physique right stock_real_warehouse right Ordered right StockToBuy right SupplierRef right param sortfield sortorder printFieldListTitle warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow StockTooLow help help help< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"> stock</td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Class to manage products or services.
Class to manage interventions.
dol_now($mode= 'auto')
Return date for now.
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.
Class to manage Dolibarr database access.
getNomUrl($withpicto=0, $option= '', $max=0, $short=0, $moretitle= '')
Return clicable name (with picto eventually)
addline($desc, $duration, $datei, $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.
$conf db
API class for accounts.
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
setAutoValidate($validate)
Update the auto validate fichinter.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
__construct($db)
Constructor.
fetch_lines()
Load array lines ->lines.
LibStatut($status, $mode=0)
Returns the label of a status.
updateNbGenDone()
Update the Number of Generation Done.
Class to manage intervention lines.
Classe de gestion des factures recurrentes/Modeles.
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
setMaxPeriod($nb)
Update the maximum period.
fetch($rowid=0, $ref= '', $ref_ext= '')
Get the template of intervention object and lines.
initAsSpecimen($option= '')
Initialise an instance with random values.
fetch_lines($sall=0)
Load all lines of template of intervention into this->lines.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...