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 =
'fichinterdet_rec';
48 public $fk_element =
'fk_fichinter';
58 public $picto =
'intervention';
75 public $date_last_gen;
94 public $usenewprice = 0;
106 $this->statuts[0] =
'Draft';
107 $this->statuts[1] =
'Closed';
109 $this->statuts_short[0] =
'Draft';
110 $this->statuts_short[1] =
'Closed';
112 $this->statuts_logo[0] =
'statut0';
113 $this->statuts_logo[1] =
'statut1';
124 return $this->
LibStatut($this->statut, $mode);
135 public function create($user, $notrigger = 0)
143 $this->title = trim($this->title);
152 $result = $fichintsrc->fetch($this->id_origin);
153 $result = $fichintsrc->fetch_lines();
158 $this->brouillon = 1;
160 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinter_rec (";
166 $sql .=
", description";
167 $sql .=
", note_private";
168 $sql .=
", note_public";
169 $sql .=
", fk_user_author";
170 $sql .=
", fk_projet";
171 $sql .=
", fk_contrat";
172 $sql .=
", modelpdf";
174 $sql .=
", frequency";
175 $sql .=
", unit_frequency";
176 $sql .=
", date_when";
177 $sql .=
", date_last_gen";
178 $sql .=
", nb_gen_done";
179 $sql .=
", nb_gen_max";
182 $sql .=
") VALUES (";
183 $sql .=
"'".$this->db->escape($this->title).
"'";
184 $sql .=
", ".($this->socid > 0 ? ((int) $this->socid) :
'null');
185 $sql .=
", ".((int) $conf->entity);
186 $sql .=
", '".$this->db->idate($now).
"'";
187 $sql .=
", ".(!empty($fichintsrc->duration) ? ((int) $fichintsrc->duration) :
'0');
189 $sql .=
", ".(!empty($fichintsrc->note_private) ? (
"'".$this->db->escape($fichintsrc->note_private).
"'") :
"null");
190 $sql .=
", ".(!empty($fichintsrc->note_public) ? (
"'".$this->db->escape($fichintsrc->note_public).
"'") :
"null");
191 $sql .=
", ".((int) $user->id);
193 if ($this->socid == $fichintsrc->socid) {
194 $sql .=
", ".(!empty($fichintsrc->fk_project) ? ((int) $fichintsrc->fk_project) :
"null");
195 $sql .=
", ".(!empty($fichintsrc->fk_contrat) ? ((int) $fichintsrc->fk_contrat) :
"null");
197 $sql .=
", null, null";
200 $sql .=
", ".(!empty($fichintsrc->model_pdf) ?
"'".$this->db->escape($fichintsrc->model_pdf).
"'" :
"''");
203 $sql .=
", ".(!empty($this->frequency) ? ((int) $this->frequency) :
"null");
204 $sql .=
", '".$this->db->escape($this->unit_frequency).
"'";
205 $sql .=
", ".(!empty($this->date_when) ?
"'".$this->db->idate($this->date_when).
"'" :
'null');
206 $sql .=
", ".(!empty($this->date_last_gen) ?
"'".$this->db->idate($this->date_last_gen).
"'" :
'null');
208 $sql .=
", ".((int) $this->nb_gen_max);
212 if ($this->
db->query($sql)) {
213 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
218 $num = count($fichintsrc->lines);
219 for ($i = 0; $i < $num; $i++) {
221 $result_insert = $this->
addline(
222 $fichintsrc->lines[$i]->desc,
223 $fichintsrc->lines[$i]->duration,
224 $fichintsrc->lines[$i]->date,
225 $fichintsrc->lines[$i]->rang,
226 $fichintsrc->lines[$i]->subprice,
227 $fichintsrc->lines[$i]->qty,
228 $fichintsrc->lines[$i]->tva_tx,
229 $fichintsrc->lines[$i]->fk_product,
230 $fichintsrc->lines[$i]->remise_percent,
235 $fichintsrc->lines[$i]->product_type,
236 $fichintsrc->lines[$i]->special_code,
237 !empty($fichintsrc->lines[$i]->label) ? $fichintsrc->lines[$i]->label :
"",
238 $fichintsrc->lines[$i]->fk_unit
241 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';
281 $sql .=
" WHERE f.rowid = ".((int) $rowid);
283 $sql .=
" WHERE f.titre = '".$this->db->escape($ref).
"'";
286 dol_syslog(get_class($this).
"::fetch rowid=".$rowid, LOG_DEBUG);
288 $result = $this->
db->query($sql);
290 if ($this->
db->num_rows($result)) {
291 $obj = $this->
db->fetch_object($result);
294 $this->titre = $obj->title;
295 $this->title = $obj->title;
296 $this->
ref = $obj->title;
298 $this->datec = $obj->datec;
299 $this->duration = $obj->duree;
300 $this->socid = $obj->fk_soc;
302 $this->fk_project = $obj->fk_projet;
303 $this->fk_contrat = $obj->fk_contrat;
304 $this->note_private = $obj->note_private;
305 $this->note_public = $obj->note_public;
306 $this->user_author = $obj->fk_user_author;
307 $this->model_pdf = !empty($obj->model_pdf) ? $obj->model_pdf :
"";
308 $this->modelpdf = !empty($obj->model_pdf) ? $obj->model_pdf :
"";
309 $this->rang = !empty($obj->rang) ? $obj->rang :
"";
310 $this->special_code = !empty($obj->special_code) ? $obj->special_code :
"";
311 $this->frequency = $obj->frequency;
312 $this->unit_frequency = $obj->unit_frequency;
313 $this->date_when = $this->
db->jdate($obj->date_when);
314 $this->date_last_gen = $this->
db->jdate($obj->date_last_gen);
315 $this->nb_gen_done = $obj->nb_gen_done;
316 $this->nb_gen_max = $obj->nb_gen_max;
317 $this->auto_validate = $obj->auto_validate;
319 $this->brouillon = 1;
324 $this->error = $this->
db->error();
329 $this->error =
'Interventional with id '.$rowid.
' not found sql='.$sql;
330 dol_syslog(get_class($this).
'::Fetch Error '.$this->error, LOG_ERR);
334 $this->error = $this->
db->error();
350 $this->lines = array();
352 $sql =
'SELECT l.rowid, l.fk_product, l.product_type as product_type, l.label as custom_label, l.description,';
353 $sql .=
' l.price, l.qty, l.tva_tx, l.remise_percent, l.subprice, l.duree, l.date,';
354 $sql .=
' l.total_ht, l.total_tva, l.total_ttc,';
355 $sql .=
' l.rang, l.special_code,';
356 $sql .=
' l.fk_unit, p.ref as product_ref, p.fk_product_type as fk_product_type,';
357 $sql .=
' p.label as product_label, p.description as product_desc';
358 $sql .=
' FROM '.MAIN_DB_PREFIX.
'fichinterdet_rec as l';
359 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
360 $sql .=
' WHERE l.fk_fichinter = '.((int) $this->
id);
362 dol_syslog(
'FichinterRec::fetch_lines', LOG_DEBUG);
364 $result = $this->
db->query($sql);
366 $num = $this->
db->num_rows($result);
369 $objp = $this->
db->fetch_object($result);
372 $line->id = $objp->rowid;
373 $line->label = $objp->custom_label;
374 $line->desc = $objp->description;
375 $line->product_type = $objp->product_type;
376 $line->product_ref = $objp->product_ref;
377 $line->product_label = $objp->product_label;
378 $line->product_desc = $objp->product_desc;
379 $line->fk_product_type = $objp->fk_product_type;
380 $line->qty = $objp->qty;
381 $line->duree = $objp->duree;
382 $line->duration = $objp->duree;
383 $line->date = $objp->date;
384 $line->subprice = $objp->subprice;
385 $line->tva_tx = $objp->tva_tx;
386 $line->remise_percent = $objp->remise_percent;
387 $line->fk_remise_except = !empty($objp->fk_remise_except) ? $objp->fk_remise_except :
"";
388 $line->fk_product = $objp->fk_product;
389 $line->info_bits = !empty($objp->info_bits) ? $objp->info_bits :
"";
390 $line->total_ht = $objp->total_ht;
391 $line->total_tva = $objp->total_tva;
392 $line->total_ttc = $objp->total_ttc;
393 $line->rang = $objp->rang;
394 $line->special_code = $objp->special_code;
395 $line->fk_unit = $objp->fk_unit;
397 $this->lines[$i] = $line;
402 $this->
db->free($result);
405 $this->error = $this->
db->error();
419 public function delete($rowid = 0, $notrigger = 0, $idwarehouse = -1)
425 dol_syslog(get_class($this).
"::delete rowid=".$rowid, LOG_DEBUG);
430 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinterdet_rec WHERE fk_fichinter = ".((int) $rowid);
432 if ($this->
db->query($sql)) {
433 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"fichinter_rec WHERE rowid = ".((int) $rowid);
435 if (!$this->
db->query($sql)) {
436 $this->error = $this->
db->lasterror();
440 $this->error = $this->
db->lasterror();
448 $this->
db->rollback();
476 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)
480 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
487 if ($this->brouillon) {
489 $remise_percent =
price2num($remise_percent);
499 if (!preg_match(
'/\((.*)\)/', $txtva)) {
503 if ($price_base_type ==
'HT') {
513 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, 0, $price_base_type, $info_bits, $type, $mysoc);
515 $total_ht = $tabprice[0];
516 $total_tva = $tabprice[1];
517 $total_ttc = $tabprice[2];
519 $pu_ht = $tabprice[3];
521 $product_type = $type;
524 $result = $product->fetch($fk_product);
525 $product_type = $product->type;
528 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"fichinterdet_rec (";
529 $sql .=
"fk_fichinter";
531 $sql .=
", description";
537 $sql .=
", fk_product";
538 $sql .=
", product_type";
539 $sql .=
", remise_percent";
540 $sql .=
", subprice";
541 $sql .=
", total_ht";
542 $sql .=
", total_tva";
543 $sql .=
", total_ttc";
547 $sql .=
") VALUES (";
548 $sql .= (int) $this->
id;
549 $sql .=
", ".(!empty($label) ?
"'".$this->db->escape($label).
"'" :
"null");
550 $sql .=
", ".(!empty($desc) ?
"'".$this->db->escape($desc).
"'" :
"null");
551 $sql .=
", ".(!empty($date) ?
"'".$this->db->idate($date).
"'" :
"null");
552 $sql .=
", ".$duration;
556 $sql .=
", ".(!empty($fk_product) ? $fk_product :
"null");
557 $sql .=
", ".$product_type;
558 $sql .=
", ".(!empty($remise_percent) ? $remise_percent :
"null");
559 $sql.=
", '".price2num($pu_ht).
"'";
560 $sql .=
", '".price2num($total_ht).
"'";
561 $sql .=
", '".price2num($total_tva).
"'";
562 $sql .=
", '".price2num($total_ttc).
"'";
563 $sql .=
", ".(int)
$rang;
565 $sql .=
", ".(!empty($fk_unit) ? $fk_unit :
"null");
568 dol_syslog(get_class($this).
"::addline", LOG_DEBUG);
569 if ($this->
db->query($sql)) {
572 $this->error = $this->
db->lasterror();
591 if ($user->rights->fichinter->creer) {
592 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"fichinter_rec ";
593 $sql .=
" SET frequency='".$this->db->escape($freq).
"'";
594 $sql .=
", date_last_gen='".$this->db->escape($courant).
"'";
595 $sql .=
" WHERE rowid = ".((int) $this->
id);
600 $this->frequency = $freq;
601 $this->date_last_gen = $courant;
622 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $moretitle =
'')
624 global $langs, $hookmanager;
627 $label = $langs->trans(
"ShowInterventionModel").
': '.$this->ref;
629 $url = DOL_URL_ROOT.
'/fichinter/card-rec.php?id='.$this->id;
635 $picto =
'intervention';
637 $link =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
641 $result .= $link.img_object($label, $picto,
'class="classfortooltip"').$linkend;
643 if ($withpicto && $withpicto != 2) {
646 if ($withpicto != 2) {
647 $result .= $link.$this->ref.$linkend;
650 $hookmanager->initHooks(array($this->element .
'dao'));
651 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
652 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
654 $result = $hookmanager->resPrint;
656 $result .= $hookmanager->resPrint;
672 global $user, $langs, $conf;
676 $nownotime =
dol_mktime(0, 0, 0, $arraynow[
'mon'], $arraynow[
'mday'], $arraynow[
'year']);
678 parent::initAsSpecimen($option);
680 $this->usenewprice = 1;
693 $tables = array(
'fichinter_rec');
724 if (!$this->table_element) {
725 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with table_element not defined", LOG_ERR);
729 if (!empty($frequency) && empty($unit)) {
730 dol_syslog(get_class($this).
"::setFrequencyAndUnit called with frequency defined but unit not ", LOG_ERR);
734 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
735 $sql .=
' SET frequency = '.($frequency ? $this->
db->escape($frequency) :
'null');
737 $sql .=
', unit_frequency = "'.$this->db->escape($unit).
'"';
739 $sql .=
" WHERE rowid = ".((int) $this->
id);
741 dol_syslog(get_class($this).
"::setFrequencyAndUnit", LOG_DEBUG);
742 if ($this->
db->query($sql)) {
743 $this->frequency = $frequency;
745 $this->unit_frequency = $unit;
763 if (!$this->table_element) {
764 dol_syslog(get_class($this).
"::setNextDate was called on objet with property table_element not defined", LOG_ERR);
767 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
768 $sql .=
" SET date_when = ".($date ?
"'".$this->db->idate($date).
"'" :
"null");
769 if ($increment_nb_gen_done > 0) {
770 $sql .=
', nb_gen_done = nb_gen_done + 1';
772 $sql .=
" WHERE rowid = ".((int) $this->
id);
774 dol_syslog(get_class($this).
"::setNextDate", LOG_DEBUG);
775 if ($this->
db->query($sql)) {
776 $this->date_when = $date;
777 if ($increment_nb_gen_done > 0) {
778 $this->nb_gen_done++;
795 if (!$this->table_element) {
796 dol_syslog(get_class($this).
"::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
804 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
805 $sql .=
' SET nb_gen_max = '.((int) $nb);
806 $sql .=
' WHERE rowid = '.((int) $this->
id);
808 dol_syslog(get_class($this).
"::setMaxPeriod", LOG_DEBUG);
809 if ($this->
db->query($sql)) {
810 $this->nb_gen_max = $nb;
826 if (!$this->table_element) {
827 dol_syslog(get_class($this).
"::setAutoValidate called with property table_element not defined", LOG_ERR);
831 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
832 $sql .=
' SET auto_validate = '.((int) $validate);
833 $sql .=
' WHERE rowid = '.((int) $this->
id);
835 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
836 if ($this->
db->query($sql)) {
837 $this->auto_validate = $validate;
852 if (!$this->table_element) {
853 dol_syslog(get_class($this).
"::updateNbGenDone called with property table_element not defined", LOG_ERR);
857 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
858 $sql .=
' SET nb_gen_done = nb_gen_done + 1';
859 $sql .=
' , date_last_gen = now()';
861 if ($this->nb_gen_max == $this->nb_gen_done + 1) {
862 $sql .=
' , statut = 1';
865 $sql .=
" WHERE rowid = ".((int) $this->
id);
867 dol_syslog(get_class($this).
"::setAutoValidate", LOG_DEBUG);
868 if ($this->
db->query($sql)) {
869 $this->nb_gen_done = $this->nb_gen_done + 1;
870 $this->nb_gen_done =
dol_now();
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty 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.
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.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
create($user, $notrigger=0)
Create a predefined fichinter.
initAsSpecimen($option='')
Initialise an instance with random values.
getLibStatut($mode=0)
Returns the label status.
__construct($db)
Constructor.
set_auto($user, $freq, $courant)
Rend la fichinter automatique.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
print *****$script_file(".$version.") pid cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
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.
$conf db
API class for accounts.