dolibarr 18.0.6
facture-rec.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2017-2020 Frédéric France <frederic.france@netlogic.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
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.'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35
36
41{
42 const TRIGGER_PREFIX = 'BILLREC';
46 public $element = 'facturerec';
47
51 public $table_element = 'facture_rec';
52
56 public $table_element_line = 'facturedet_rec';
57
61 public $fk_element = 'fk_facture';
62
66 public $picto = 'bill';
67
71 public $entity;
72
76 protected $table_ref_field = 'titre';
77
81 public $title;
82
87 public $titre;
88
89 public $socid;
90 public $number;
91 public $date;
92 public $remise;
93 public $remise_absolue;
94 public $remise_percent;
95
100 public $total;
101
106 public $tva;
107
108 public $date_last_gen;
109 public $date_when;
110 public $nb_gen_done;
111 public $nb_gen_max;
112
113 public $user_author;
114
118 public $frequency;
119
123 public $unit_frequency;
124
125 public $rang;
126 public $special_code;
127
128 public $usenewprice = 0;
129
130 public $date_lim_reglement;
131 public $cond_reglement_code; // Code in llx_c_paiement
132 public $mode_reglement_code; // Code in llx_c_paiement
133
134 public $fk_multicurrency;
135 public $multicurrency_code;
136 public $multicurrency_tx;
137 public $multicurrency_total_ht;
138 public $multicurrency_total_tva;
139 public $multicurrency_total_ttc;
140
141 public $suspended; // status
142
143 public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
144 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
145
150 public $brouillon;
151
152
177 // BEGIN MODULEBUILDER PROPERTIES
181 public $fields = array(
182 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
183 'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15),
184 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20, 'index'=>1),
185 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>25),
186 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
187 //'amount' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35),
188 'remise' =>array('type'=>'double', 'label'=>'Remise', 'enabled'=>1, 'visible'=>-1, 'position'=>40),
189 //'remise_percent' =>array('type'=>'double', 'label'=>'Remise percent', 'enabled'=>1, 'visible'=>-1, 'position'=>45),
190 //'remise_absolue' =>array('type'=>'double', 'label'=>'Remise absolue', 'enabled'=>1, 'visible'=>-1, 'position'=>50),
191 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1),
192 'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1),
193 'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1),
194 'total_ht' =>array('type'=>'double(24,8)', 'label'=>'Total', 'enabled'=>1, 'visible'=>-1, 'position'=>70, 'isameasure'=>1),
195 'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>75, 'isameasure'=>1),
196 'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
197 'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Fk projet', 'enabled'=>"isModEnabled('project')", 'visible'=>-1, 'position'=>85),
198 'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Fk cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
199 'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'Fk mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
200 'date_lim_reglement' =>array('type'=>'date', 'label'=>'Date lim reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
201 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>105),
202 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>110),
203 'modelpdf' =>array('type'=>'varchar(255)', 'label'=>'Modelpdf', 'enabled'=>1, 'visible'=>-1, 'position'=>115),
204 'date_when' =>array('type'=>'datetime', 'label'=>'Date when', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
205 'date_last_gen' =>array('type'=>'datetime', 'label'=>'Date last gen', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
206 'nb_gen_done' =>array('type'=>'integer', 'label'=>'Nb gen done', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
207 'nb_gen_max' =>array('type'=>'integer', 'label'=>'Nb gen max', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
208 'frequency' =>array('type'=>'integer', 'label'=>'Frequency', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
209 'unit_frequency' =>array('type'=>'varchar(2)', 'label'=>'UnitFrequency', 'enabled'=>1, 'visible'=>-1, 'position'=>152),
210 'usenewprice' =>array('type'=>'integer', 'label'=>'UseNewPrice', 'enabled'=>1, 'visible'=>0, 'position'=>155),
211 'revenuestamp' =>array('type'=>'double(24,8)', 'label'=>'RevenueStamp', 'enabled'=>1, 'visible'=>-1, 'position'=>160, 'isameasure'=>1),
212 'auto_validate' =>array('type'=>'integer', 'label'=>'Auto validate', 'enabled'=>1, 'visible'=>-1, 'position'=>165),
213 'generate_pdf' =>array('type'=>'integer', 'label'=>'Generate pdf', 'enabled'=>1, 'visible'=>-1, 'position'=>170),
214 'fk_account' =>array('type'=>'integer', 'label'=>'Fk account', 'enabled'=>'isModEnabled("banque")', 'visible'=>-1, 'position'=>175),
215 'fk_multicurrency' =>array('type'=>'integer', 'label'=>'Fk multicurrency', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
216 'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'Multicurrency code', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
217 'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency tx', 'enabled'=>1, 'visible'=>-1, 'position'=>190, 'isameasure'=>1),
218 'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ht', 'enabled'=>1, 'visible'=>-1, 'position'=>195, 'isameasure'=>1),
219 'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total tva', 'enabled'=>1, 'visible'=>-1, 'position'=>200, 'isameasure'=>1),
220 'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>205, 'isameasure'=>1),
221 'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>210),
222 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>215),
223 'suspended' =>array('type'=>'integer', 'label'=>'Suspended', 'enabled'=>1, 'visible'=>-1, 'position'=>225),
224 );
225 // END MODULEBUILDER PROPERTIES
226
227 const STATUS_NOTSUSPENDED = 0;
228 const STATUS_SUSPENDED = 1;
229
230
231
237 public function __construct(DoliDB $db)
238 {
239 $this->db = $db;
240 }
241
250 public function create($user, $facid, $notrigger = 0)
251 {
252 global $conf;
253
254 $error = 0;
255 $now = dol_now();
256
257 // Clean parameters
258 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
259 $this->title = trim($this->title);
260 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
261 if (empty($this->suspended)) {
262 $this->suspended = 0;
263 }
264
265 // No frequency defined then no next date to execution
266 if (empty($this->frequency)) {
267 $this->frequency = 0;
268 $this->date_when = null;
269 }
270
271 $this->frequency = abs($this->frequency);
272 $this->nb_gen_done = 0;
273 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
274 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
275 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
276
277 $this->db->begin();
278
279 // Charge facture modele
280 $facsrc = new Facture($this->db);
281 $result = $facsrc->fetch($facid);
282 if ($result > 0) {
283 // On positionne en mode brouillon la facture
284 $this->brouillon = 1;
285 $this->fk_soc = $facsrc->socid;
286
287 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
288 $sql .= "titre";
289 $sql .= ", fk_soc";
290 $sql .= ", entity";
291 $sql .= ", datec";
292 $sql .= ", amount";
293 $sql .= ", remise";
294 $sql .= ", note_private";
295 $sql .= ", note_public";
296 $sql .= ", modelpdf";
297 $sql .= ", fk_user_author";
298 $sql .= ", fk_projet";
299 $sql .= ", fk_account";
300 $sql .= ", fk_cond_reglement";
301 $sql .= ", fk_mode_reglement";
302 $sql .= ", usenewprice";
303 $sql .= ", frequency";
304 $sql .= ", unit_frequency";
305 $sql .= ", date_when";
306 $sql .= ", date_last_gen";
307 $sql .= ", nb_gen_done";
308 $sql .= ", nb_gen_max";
309 $sql .= ", auto_validate";
310 $sql .= ", generate_pdf";
311 $sql .= ", fk_multicurrency";
312 $sql .= ", multicurrency_code";
313 $sql .= ", multicurrency_tx";
314 $sql .= ", suspended";
315 $sql .= ") VALUES (";
316 $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
317 $sql .= ", ".((int) $this->fk_soc);
318 $sql .= ", ".((int) $conf->entity);
319 $sql .= ", '".$this->db->idate($now)."'";
320 $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
321 $sql .= ", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) : '0');
322 $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
323 $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
324 $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL");
325 $sql .= ", ".((int) $user->id);
326 $sql .= ", ".(!empty($this->fk_project) ? ((int) $this->fk_project) : "null");
327 $sql .= ", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) : "null");
328 $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
329 $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
330 $sql .= ", ".((int) $this->usenewprice);
331 $sql .= ", ".((int) $this->frequency);
332 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
333 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
334 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
335 $sql .= ", ".((int) $this->nb_gen_done);
336 $sql .= ", ".((int) $this->nb_gen_max);
337 $sql .= ", ".((int) $this->auto_validate);
338 $sql .= ", ".((int) $this->generate_pdf);
339 $sql .= ", ".((int) $facsrc->fk_multicurrency);
340 $sql .= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
341 $sql .= ", ".((float) $facsrc->multicurrency_tx);
342 $sql .= ", ".((int) $this->suspended);
343 $sql .= ")";
344
345 if ($this->db->query($sql)) {
346 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
347
348 // Fields used into addline later
349 $this->fk_multicurrency = $facsrc->fk_multicurrency;
350 $this->multicurrency_code = $facsrc->multicurrency_code;
351 $this->multicurrency_tx = $facsrc->multicurrency_tx;
352
353 // Add lines
354 $num = count($facsrc->lines);
355 for ($i = 0; $i < $num; $i++) {
356 $tva_tx = $facsrc->lines[$i]->tva_tx;
357 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
358 $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
359 }
360
361 $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START');
362 $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END');
363
364 $result_insert = $this->addline(
365 $facsrc->lines[$i]->desc,
366 $facsrc->lines[$i]->subprice,
367 $facsrc->lines[$i]->qty,
368 $tva_tx,
369 $facsrc->lines[$i]->localtax1_tx,
370 $facsrc->lines[$i]->localtax2_tx,
371 $facsrc->lines[$i]->fk_product,
372 $facsrc->lines[$i]->remise_percent,
373 'HT',
374 $facsrc->lines[$i]->info_bits,
375 '',
376 0,
377 $facsrc->lines[$i]->product_type,
378 $facsrc->lines[$i]->rang,
379 $facsrc->lines[$i]->special_code,
380 $facsrc->lines[$i]->label,
381 $facsrc->lines[$i]->fk_unit,
382 $facsrc->lines[$i]->multicurrency_subprice,
383 $default_start_fill,
384 $default_end_fill,
385 null,
386 $facsrc->lines[$i]->pa_ht
387 );
388
389 if ($result_insert < 0) {
390 $error++;
391 } else {
392 $objectline = new FactureLigneRec($this->db);
393
394 $result2 = $objectline->fetch($result_insert);
395 if ($result2 > 0) {
396 // Extrafields
397 if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
398 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
399 $objectline->array_options = $facsrc->lines[$i]->array_options;
400 }
401
402 $result = $objectline->insertExtraFields();
403 if ($result < 0) {
404 $error++;
405 }
406 } elseif ($result2 < 0) {
407 $this->errors[] = $objectline->error;
408 $error++;
409 }
410 }
411 }
412
413 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
414 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
415 }
416
417 // Add object linked
418 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
419 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
420 if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...))
421 foreach ($tmp_origin_id as $origin_id) {
422 $ret = $this->add_object_linked($origin, $origin_id);
423 if (!$ret) {
424 $this->error = $this->db->lasterror();
425 $error++;
426 }
427 }
428 } else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
429 {
430 $origin_id = $tmp_origin_id;
431 $ret = $this->add_object_linked($origin, $origin_id);
432 if (!$ret) {
433 $this->error = $this->db->lasterror();
434 $error++;
435 }
436 }
437 }
438 }
439
440 if (!$error) {
441 $result = $this->insertExtraFields();
442 if ($result < 0) {
443 $error++;
444 }
445 }
446
447 if (!$error && !$notrigger) {
448 // Call trigger
449 $result = $this->call_trigger('BILLREC_CREATE', $user);
450 if ($result < 0) {
451 $this->db->rollback();
452 return -2;
453 }
454 // End call triggers
455 }
456
457 if ($error) {
458 $this->db->rollback();
459 return -3;
460 } else {
461 $this->db->commit();
462 return $this->id;
463 }
464 } else {
465 $this->error = $this->db->lasterror();
466 $this->db->rollback();
467 return -2;
468 }
469 } else {
470 $this->db->rollback();
471 return -1;
472 }
473 }
474
475
483 public function update(User $user, $notrigger = 0)
484 {
485 $error = 0;
486
487 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET";
488 $sql .= " entity = ".((int) $this->entity).",";
489 $sql .= " titre = '".$this->db->escape($this->title)."',";
490 $sql .= " suspended = ".((int) $this->suspended).",";
491 $sql .= " fk_soc = ".((int) $this->socid).",";
492 $sql .= " total_tva = ".((float) $this->total_tva).",";
493 $sql .= " localtax1 = ".((float) $this->total_localtax1).",";
494 $sql .= " localtax2 = ".((float) $this->total_localtax2).",";
495 $sql .= " total_ht = ".((float) $this->total_ht).",";
496 $sql .= " total_ttc = ".((float) $this->total_ttc).",";
497 $sql .= " remise_percent = ".((float) $this->remise_percent);
498 // TODO Add missing fields
499 $sql .= " WHERE rowid = ".((int) $this->id);
500
501 $this->db->begin();
502
503 dol_syslog(get_class($this)."::update", LOG_DEBUG);
504
505 $resql = $this->db->query($sql);
506 if ($resql) {
507 if (!$error) {
508 $result = $this->insertExtraFields();
509 if ($result < 0) {
510 $error++;
511 }
512 }
513
514 if (!$error && !$notrigger) {
515 // Call trigger
516 $result = $this->call_trigger('BILLREC_MODIFY', $user);
517 if ($result < 0) {
518 $this->db->rollback();
519 return -2;
520 }
521 // End call triggers
522 }
523 $this->db->commit();
524 return 1;
525 } else {
526 $this->error = $this->db->lasterror();
527 $this->db->rollback();
528 return -1;
529 }
530 }
531
540 public function fetch($rowid, $ref = '', $ref_ext = '')
541 {
542 dol_syslog('FactureRec::fetch', LOG_DEBUG);
543
544 $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
545 $sql .= ', f.remise_percent, f.remise_absolue, f.remise';
546 $sql .= ', f.date_lim_reglement as dlr';
547 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
548 $sql .= ', f.modelpdf as model_pdf';
549 $sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
550 $sql .= ', f.fk_account';
551 $sql .= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
552 $sql .= ', f.generate_pdf';
553 $sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
554 $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
555 $sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
556 //$sql.= ', el.fk_source';
557 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
558 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
559 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
560 //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
561 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
562 if ($rowid) {
563 $sql .= ' AND f.rowid = '.((int) $rowid);
564 } elseif ($ref) {
565 $sql .= " AND f.titre = '".$this->db->escape($ref)."'";
566 } else {
567 $sql .= ' AND f.rowid = 0';
568 }
569 /* This field are not used for template invoice
570 if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
571 */
572
573 $result = $this->db->query($sql);
574 if ($result) {
575 if ($this->db->num_rows($result)) {
576 $obj = $this->db->fetch_object($result);
577
578 $this->id = $obj->rowid;
579 $this->entity = $obj->entity;
580 $this->titre = $obj->title; // deprecated
581 $this->title = $obj->title;
582 $this->ref = $obj->title;
583 $this->suspended = $obj->suspended;
584 $this->remise_percent = $obj->remise_percent;
585 $this->remise_absolue = $obj->remise_absolue;
586 $this->remise = $obj->remise;
587 $this->total_ht = $obj->total_ht;
588 $this->total_tva = $obj->total_tva;
589 $this->total_localtax1 = $obj->localtax1;
590 $this->total_localtax2 = $obj->localtax2;
591 $this->total_ttc = $obj->total_ttc;
592 $this->socid = $obj->fk_soc;
593 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
594 $this->mode_reglement_id = $obj->fk_mode_reglement;
595 $this->mode_reglement_code = $obj->mode_reglement_code;
596 $this->mode_reglement = $obj->mode_reglement_libelle;
597 $this->cond_reglement_id = $obj->fk_cond_reglement;
598 $this->cond_reglement_code = $obj->cond_reglement_code;
599 $this->cond_reglement = $obj->cond_reglement_libelle;
600 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
601 $this->fk_project = $obj->fk_project;
602 $this->fk_account = $obj->fk_account;
603 $this->note_private = $obj->note_private;
604 $this->note_public = $obj->note_public;
605 $this->user_author = $obj->fk_user_author;
606 $this->modelpdf = $obj->model_pdf; // deprecated
607 $this->model_pdf = $obj->model_pdf;
608 //$this->special_code = $obj->special_code;
609 $this->frequency = $obj->frequency;
610 $this->unit_frequency = $obj->unit_frequency;
611 $this->date_when = $this->db->jdate($obj->date_when);
612 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
613 $this->nb_gen_done = $obj->nb_gen_done;
614 $this->nb_gen_max = $obj->nb_gen_max;
615 $this->usenewprice = $obj->usenewprice;
616 $this->auto_validate = $obj->auto_validate;
617 $this->generate_pdf = $obj->generate_pdf;
618
619 // Multicurrency
620 $this->fk_multicurrency = $obj->fk_multicurrency;
621 $this->multicurrency_code = $obj->multicurrency_code;
622 $this->multicurrency_tx = $obj->multicurrency_tx;
623 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
624 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
625 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
626
627 if ($this->statut == self::STATUS_DRAFT) {
628 $this->brouillon = 1;
629 }
630
631 // Retrieve all extrafield
632 // fetch optionals attributes and labels
633 $this->fetch_optionals();
634
635 /*
636 * Lines
637 */
638 $result = $this->fetch_lines();
639 if ($result < 0) {
640 $this->error = $this->db->lasterror();
641 return -3;
642 }
643 return 1;
644 } else {
645 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
646 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
647 return -2;
648 }
649 } else {
650 $this->error = $this->db->error();
651 return -1;
652 }
653 }
654
655
661 public function getLinesArray()
662 {
663 return $this->fetch_lines();
664 }
665
666
667 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
673 public function fetch_lines()
674 {
675 // phpcs:enable
676
677 $this->lines = array();
678
679 dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
680
681 $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
682 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
683 $sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,';
684 $sql .= ' l.rang, l.special_code,';
685 $sql .= ' l.fk_unit, l.fk_contract_line,';
686 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
687 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
688 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
689 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
690 $sql .= ' WHERE l.fk_facture = '.((int) $this->id);
691 $sql .= ' ORDER BY l.rang';
692
693 $result = $this->db->query($sql);
694 if ($result) {
695 $num = $this->db->num_rows($result);
696 $i = 0;
697 while ($i < $num) {
698 $objp = $this->db->fetch_object($result);
699 $line = new FactureLigneRec($this->db);
700
701 $line->id = $objp->rowid;
702 $line->rowid = $objp->rowid;
703 $line->desc = $objp->description; // Description line
704 $line->description = $objp->description; // Description line
705 $line->ref = $objp->product_ref; // Ref product
706 $line->product_ref = $objp->product_ref; // Ref product
707 $line->libelle = $objp->product_label; // deprecated
708 $line->product_label = $objp->product_label; // Label product
709 $line->product_desc = $objp->product_desc; // Description product
710 $line->product_type = $objp->product_type; // Type of line
711 $line->fk_product_type = $objp->fk_product_type; // Type of product
712 $line->qty = $objp->qty;
713 $line->subprice = $objp->subprice;
714
715 $line->label = $objp->custom_label; // @deprecated
716
717 $line->vat_src_code = $objp->vat_src_code;
718 $line->tva_tx = $objp->tva_tx;
719 $line->localtax1_tx = $objp->localtax1_tx;
720 $line->localtax2_tx = $objp->localtax2_tx;
721 $line->localtax1_type = $objp->localtax1_type;
722 $line->localtax2_type = $objp->localtax2_type;
723 $line->remise_percent = $objp->remise_percent;
724 //$line->fk_remise_except = $objp->fk_remise_except;
725 $line->fk_product = $objp->fk_product;
726 $line->date_start_fill = $objp->date_start_fill;
727 $line->date_end_fill = $objp->date_end_fill;
728 $line->info_bits = $objp->info_bits;
729 $line->total_ht = $objp->total_ht;
730 $line->total_tva = $objp->total_tva;
731 $line->total_ttc = $objp->total_ttc;
732
733 //$line->code_ventilation = $objp->fk_code_ventilation;
734
735 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
736 $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
737
738 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
739
740 $line->buyprice = $marginInfos[0];
741 $line->pa_ht = $marginInfos[0]; // For backward compatibility
742 $line->marge_tx = $marginInfos[1];
743 $line->marque_tx = $marginInfos[2];
744 $line->rang = $objp->rang;
745 $line->special_code = $objp->special_code;
746 $line->fk_unit = $objp->fk_unit;
747 $line->fk_contract_line = $objp->fk_contract_line;
748
749 // Ne plus utiliser
750 $line->price = $objp->price;
751 $line->remise = $objp->remise;
752
753 $line->fetch_optionals();
754
755 // Multicurrency
756 $line->fk_multicurrency = $objp->fk_multicurrency;
757 $line->multicurrency_code = $objp->multicurrency_code;
758 $line->multicurrency_subprice = $objp->multicurrency_subprice;
759 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
760 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
761 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
762
763 $this->lines[$i] = $line;
764
765 $i++;
766 }
767
768 $this->db->free($result);
769 return 1;
770 } else {
771 $this->error = $this->db->lasterror();
772 return -3;
773 }
774 }
775
776
785 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
786 {
787 $rowid = $this->id;
788
789 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
790
791 $error = 0;
792 $this->db->begin();
793
794 $main = MAIN_DB_PREFIX.'facturedet_rec';
795 $ef = $main."_extrafields";
796
797 $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")";
798 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".((int) $rowid);
799
800 if ($this->db->query($sqlef) && $this->db->query($sql)) {
801 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".((int) $rowid);
802 dol_syslog($sql);
803 if ($this->db->query($sql)) {
804 // Delete linked object
805 $res = $this->deleteObjectLinked();
806 if ($res < 0) {
807 $error = -3;
808 }
809 // Delete extrafields
810 $res = $this->deleteExtraFields();
811 if ($res < 0) {
812 $error = -4;
813 }
814 } else {
815 $this->error = $this->db->lasterror();
816 $error = -1;
817 }
818 } else {
819 $this->error = $this->db->lasterror();
820 $error = -2;
821 }
822 if (!$error && !$notrigger) {
823 // Call trigger
824 $result = $this->call_trigger('BILLREC_DELETE', $user);
825 if ($result < 0) {
826 $error++;
827 }
828 // End call triggers
829 }
830 if (!$error) {
831 $this->db->commit();
832 return 1;
833 } else {
834 $this->db->rollback();
835 return $error;
836 }
837 }
838
839
867 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = '', $pu_ttc = 0, $type = 0, $rang = -1, $special_code = 0, $label = '', $fk_unit = null, $pu_ht_devise = 0, $date_start_fill = 0, $date_end_fill = 0, $fk_fournprice = null, $pa_ht = 0)
868 {
869 global $mysoc;
870
871 $facid = $this->id;
872
873 dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise,date_start_fill=$date_start_fill,date_end_fill=$date_end_fill,pa_ht=$pa_ht", LOG_DEBUG);
874 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
875
876 // Check parameters
877 if ($type < 0) {
878 return -1;
879 }
880
881 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
882
883 // Clean vat code
884 $reg = array();
885 $vat_src_code = '';
886 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
887 $vat_src_code = $reg[1];
888 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
889 }
890
891 if ($this->brouillon) {
892 // Clean parameters
893 $remise_percent = price2num($remise_percent);
894 if (empty($remise_percent)) {
895 $remise_percent = 0;
896 }
897 $qty = price2num($qty);
898 $pu_ht = price2num($pu_ht);
899 $pu_ttc = price2num($pu_ttc);
900 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
901 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
902 }
903 $txlocaltax1 = price2num($txlocaltax1);
904 $txlocaltax2 = price2num($txlocaltax2);
905 if (empty($txtva)) {
906 $txtva = 0;
907 }
908 if (empty($txlocaltax1)) {
909 $txlocaltax1 = 0;
910 }
911 if (empty($txlocaltax2)) {
912 $txlocaltax2 = 0;
913 }
914 if (empty($info_bits)) {
915 $info_bits = 0;
916 }
917
918 if ($price_base_type == 'HT') {
919 $pu = $pu_ht;
920 } else {
921 $pu = $pu_ttc;
922 }
923
924 // Calcul du total TTC et de la TVA pour la ligne a partir de
925 // qty, pu, remise_percent et txtva
926 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
927 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
928
929 $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
930 $total_ht = $tabprice[0];
931 $total_tva = $tabprice[1];
932 $total_ttc = $tabprice[2];
933 $total_localtax1 = $tabprice[9];
934 $total_localtax2 = $tabprice[10];
935 $pu_ht = $tabprice[3];
936
937 // MultiCurrency
938 $multicurrency_total_ht = $tabprice[16];
939 $multicurrency_total_tva = $tabprice[17];
940 $multicurrency_total_ttc = $tabprice[18];
941 $pu_ht_devise = $tabprice[19];
942
943 $product_type = $type;
944 if ($fk_product) {
945 $product = new Product($this->db);
946 $result = $product->fetch($fk_product);
947 $product_type = $product->type;
948 }
949
950 // Rank to use
951 $ranktouse = $rang;
952 if ($ranktouse == -1) {
953 $rangmax = $this->line_max(0);
954 $ranktouse = $rangmax + 1;
955 }
956
957 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
958 $sql .= "fk_facture";
959 $sql .= ", label";
960 $sql .= ", description";
961 $sql .= ", price";
962 $sql .= ", qty";
963 $sql .= ", tva_tx";
964 $sql .= ", vat_src_code";
965 $sql .= ", localtax1_tx";
966 $sql .= ", localtax1_type";
967 $sql .= ", localtax2_tx";
968 $sql .= ", localtax2_type";
969 $sql .= ", fk_product";
970 $sql .= ", product_type";
971 $sql .= ", remise_percent";
972 $sql .= ", subprice";
973 $sql .= ", remise";
974 $sql .= ", total_ht";
975 $sql .= ", total_tva";
976 $sql .= ", total_localtax1";
977 $sql .= ", total_localtax2";
978 $sql .= ", total_ttc";
979 $sql .= ", date_start_fill";
980 $sql .= ", date_end_fill";
981 $sql .= ", fk_product_fournisseur_price";
982 $sql .= ", buy_price_ht";
983 $sql .= ", info_bits";
984 $sql .= ", rang";
985 $sql .= ", special_code";
986 $sql .= ", fk_unit";
987 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
988 $sql .= ") VALUES (";
989 $sql .= " ".((int) $facid);
990 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
991 $sql .= ", '".$this->db->escape($desc)."'";
992 $sql .= ", ".price2num($pu_ht);
993 $sql .= ", ".price2num($qty);
994 $sql .= ", ".price2num($txtva);
995 $sql .= ", '".$this->db->escape($vat_src_code)."'";
996 $sql .= ", ".price2num($txlocaltax1);
997 $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
998 $sql .= ", ".price2num($txlocaltax2);
999 $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
1000 $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1001 $sql .= ", ".((int) $product_type);
1002 $sql .= ", ".price2num($remise_percent);
1003 $sql .= ", ".price2num($pu_ht);
1004 $sql .= ", null";
1005 $sql .= ", ".price2num($total_ht);
1006 $sql .= ", ".price2num($total_tva);
1007 $sql .= ", ".price2num($total_localtax1);
1008 $sql .= ", ".price2num($total_localtax2);
1009 $sql .= ", ".price2num($total_ttc);
1010 $sql .= ", ".(int) $date_start_fill;
1011 $sql .= ", ".(int) $date_end_fill;
1012 $sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1013 $sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
1014 $sql .= ", ".((int) $info_bits);
1015 $sql .= ", ".((int) $ranktouse);
1016 $sql .= ", ".((int) $special_code);
1017 $sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
1018 $sql .= ", ".(int) $this->fk_multicurrency;
1019 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1020 $sql .= ", ".price2num($pu_ht_devise, 'CU');
1021 $sql .= ", ".price2num($multicurrency_total_ht, 'CT');
1022 $sql .= ", ".price2num($multicurrency_total_tva, 'CT');
1023 $sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
1024 $sql .= ")";
1025
1026 dol_syslog(get_class($this)."::addline", LOG_DEBUG);
1027 if ($this->db->query($sql)) {
1028 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
1029 $this->id = $facid;
1030 $this->update_price(1);
1031 return $lineId;
1032 } else {
1033 $this->error = $this->db->lasterror();
1034 return -1;
1035 }
1036 } else {
1037 $this->error = 'Recurring Invoice is suspended. adding lines not allowed.';
1038
1039 return -1;
1040 }
1041 }
1042
1072 public function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $info_bits = 0, $fk_remise_except = '', $pu_ttc = 0, $type = 0, $rang = -1, $special_code = 0, $label = '', $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $date_start_fill = 0, $date_end_fill = 0, $fk_fournprice = null, $pa_ht = 0)
1073 {
1074 global $mysoc;
1075
1076 $facid = $this->id;
1077
1078 dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, type=$type, fk_unit=$fk_unit, pu_ht_devise=$pu_ht_devise", LOG_DEBUG);
1079 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1080
1081 // Clean parameters
1082 if (empty($remise_percent)) {
1083 $remise_percent = 0;
1084 }
1085
1086 // Check parameters
1087 if ($type < 0) {
1088 return -1;
1089 }
1090
1091 if ($this->brouillon) {
1092 // Clean parameters
1093 $remise_percent = price2num($remise_percent);
1094 $qty = price2num($qty);
1095 if (empty($info_bits)) {
1096 $info_bits = 0;
1097 }
1098 $pu_ht = price2num($pu_ht);
1099 $pu_ttc = price2num($pu_ttc);
1100 $pu_ht_devise = price2num($pu_ht_devise);
1101 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
1102 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1103 }
1104 $txlocaltax1 = price2num($txlocaltax1);
1105 $txlocaltax2 = price2num($txlocaltax2);
1106 if (empty($txlocaltax1)) {
1107 $txlocaltax1 = 0;
1108 }
1109 if (empty($txlocaltax2)) {
1110 $txlocaltax2 = 0;
1111 }
1112
1113 if (empty($this->multicurrency_subprice)) {
1114 $this->multicurrency_subprice = 0;
1115 }
1116 if (empty($this->multicurrency_total_ht)) {
1117 $this->multicurrency_total_ht = 0;
1118 }
1119 if (empty($this->multicurrency_total_tva)) {
1120 $this->multicurrency_total_tva = 0;
1121 }
1122 if (empty($this->multicurrency_total_ttc)) {
1123 $this->multicurrency_total_ttc = 0;
1124 }
1125
1126 if ($price_base_type == 'HT') {
1127 $pu = $pu_ht;
1128 } else {
1129 $pu = $pu_ttc;
1130 }
1131
1132 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1133 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1134 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1135
1136 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1137
1138 // Clean vat code
1139 $vat_src_code = '';
1140 $reg = array();
1141 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1142 $vat_src_code = $reg[1];
1143 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1144 }
1145
1146 $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
1147
1148 $total_ht = $tabprice[0];
1149 $total_tva = $tabprice[1];
1150 $total_ttc = $tabprice[2];
1151 $total_localtax1 = $tabprice[9];
1152 $total_localtax2 = $tabprice[10];
1153 $pu_ht = $tabprice[3];
1154 $pu_tva = $tabprice[4];
1155 $pu_ttc = $tabprice[5];
1156
1157 // MultiCurrency
1158 $multicurrency_total_ht = $tabprice[16];
1159 $multicurrency_total_tva = $tabprice[17];
1160 $multicurrency_total_ttc = $tabprice[18];
1161 $pu_ht_devise = $tabprice[19];
1162
1163 $product_type = $type;
1164 if ($fk_product) {
1165 $product = new Product($this->db);
1166 $result = $product->fetch($fk_product);
1167 $product_type = $product->type;
1168 }
1169
1170 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
1171 $sql .= "fk_facture = ".((int) $facid);
1172 $sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1173 $sql .= ", description='".$this->db->escape($desc)."'";
1174 $sql .= ", price=".price2num($pu_ht);
1175 $sql .= ", qty=".price2num($qty);
1176 $sql .= ", tva_tx=".price2num($txtva);
1177 $sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
1178 $sql .= ", localtax1_tx=".((float) $txlocaltax1);
1179 $sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
1180 $sql .= ", localtax2_tx=".((float) $txlocaltax2);
1181 $sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
1182 $sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1183 $sql .= ", product_type=".((int) $product_type);
1184 $sql .= ", remise_percent='".price2num($remise_percent)."'";
1185 $sql .= ", subprice='".price2num($pu_ht)."'";
1186 $sql .= ", total_ht='".price2num($total_ht)."'";
1187 $sql .= ", total_tva='".price2num($total_tva)."'";
1188 $sql .= ", total_localtax1='".price2num($total_localtax1)."'";
1189 $sql .= ", total_localtax2='".price2num($total_localtax2)."'";
1190 $sql .= ", total_ttc='".price2num($total_ttc)."'";
1191 $sql .= ", date_start_fill=".((int) $date_start_fill);
1192 $sql .= ", date_end_fill=".((int) $date_end_fill);
1193 $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1194 $sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
1195 $sql .= ", info_bits=".((int) $info_bits);
1196 $sql .= ", rang=".((int) $rang);
1197 $sql .= ", special_code=".((int) $special_code);
1198 $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
1199 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1200 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1201 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1202 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1203 $sql .= " WHERE rowid = ".((int) $rowid);
1204
1205 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1206 if ($this->db->query($sql)) {
1207 $this->id = $facid;
1208 $this->update_price(1);
1209 return 1;
1210 } else {
1211 $this->error = $this->db->lasterror();
1212 return -1;
1213 }
1214 }
1215 return -1;
1216 }
1217
1218
1224 public function getNextDate()
1225 {
1226 if (empty($this->date_when)) {
1227 return false;
1228 }
1229 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1230 }
1231
1237 public function isMaxNbGenReached()
1238 {
1239 $ret = false;
1240 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1241 $ret = true;
1242 }
1243 return $ret;
1244 }
1245
1252 public function strikeIfMaxNbGenReached($ret)
1253 {
1254 // Special case to strike the date
1255 return ($this->isMaxNbGenReached() ? '<strike>' : '').$ret.($this->isMaxNbGenReached() ? '</strike>' : '');
1256 }
1257
1269 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
1270 {
1271 global $conf, $langs, $db, $user, $hookmanager;
1272
1273 $error = 0;
1274 $nb_create = 0;
1275
1276 // Load translation files required by the page
1277 $langs->loadLangs(array("main", "bills"));
1278
1279 $now = dol_now();
1280 $tmparray = dol_getdate($now);
1281 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1282
1283 $this->output = null;
1284
1285 dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
1286
1287 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1288 $sql .= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1289 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1290 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1291 $sql .= ' AND suspended = 0';
1292 $sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1293 if ($restrictioninvoiceid > 0) {
1294 $sql .= ' AND rowid = '.((int) $restrictioninvoiceid);
1295 }
1296 $sql .= $this->db->order('entity', 'ASC');
1297 //print $sql;exit;
1298 $parameters = array(
1299 'restrictioninvoiceid' => $restrictioninvoiceid,
1300 'forcevalidation' => $forcevalidation,
1301 );
1302 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1303
1304 $resql = $this->db->query($sql);
1305 if ($resql) {
1306 $i = 0;
1307 $num = $this->db->num_rows($resql);
1308
1309 if ($num) {
1310 $this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1311 } else {
1312 $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1313 }
1314
1315 $saventity = $conf->entity;
1316
1317 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1318 $line = $this->db->fetch_object($resql);
1319
1320 $this->db->begin();
1321
1322 $invoiceidgenerated = 0;
1323
1324 $facture = null;
1325 $facturerec = new FactureRec($this->db);
1326 $facturerec->fetch($line->rowid);
1327
1328 if ($facturerec->id > 0) {
1329 // Set entity context
1330 $conf->entity = $facturerec->entity;
1331
1332 dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1333
1334 $facture = new Facture($this->db);
1335 $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1336 $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1337
1338 $facture->type = self::TYPE_STANDARD;
1339 $facture->brouillon = 1;
1340 $facture->statut = self::STATUS_DRAFT;
1341 $facture->status = self::STATUS_DRAFT;
1342 $facture->date = (empty($facturerec->date_when) ? $now : $facturerec->date_when); // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
1343 $facture->socid = $facturerec->socid;
1344 if (!empty($facturerec->fk_multicurrency)) {
1345 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1346 $facture->multicurrency_code = $facturerec->multicurrency_code;
1347 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1348 }
1349
1350 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1351 foreach ($facturerec->array_options as $key => $value) {
1352 if (isset($facture->array_options[$key])) {
1353 $facture->array_options[$key] = $value;
1354 }
1355 }
1356 }
1357
1358 $invoiceidgenerated = $facture->create($user);
1359 if ($invoiceidgenerated <= 0) {
1360 $this->errors = $facture->errors;
1361 $this->error = $facture->error;
1362 $error++;
1363 }
1364
1365
1366 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1367 $result = $facture->validate($user);
1368 if ($result <= 0) {
1369 $this->errors = $facture->errors;
1370 $this->error = $facture->error;
1371 $error++;
1372 }
1373 }
1374 if (!$error && $facturerec->generate_pdf) {
1375 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1376 $facture->fetch($facture->id);
1377 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1378 if ($result <= 0) {
1379 $this->errors = $facture->errors;
1380 $this->error = $facture->error;
1381 $error++;
1382 }
1383 }
1384 if (!$error && !$notrigger) {
1385 // Call trigger
1386 $result = $facturerec->call_trigger('BILLREC_CREATEBILL', $user);
1387 if ($result < 0) {
1388 $this->errors = $facturerec->errors;
1389 $this->error = $facturerec->error;
1390 $error++;
1391 }
1392 // End call triggers
1393 }
1394 } else {
1395 $error++;
1396 $this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1397 $this->errors[] = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1398 dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1399 }
1400
1401 if (!$error && $invoiceidgenerated >= 0) {
1402 $this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1403 dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1404 $nb_create++;
1405 $this->output .= $langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1406 } else {
1407 $this->output .= $langs->trans("InvoiceGeneratedFromTemplateError", $facture->ref, $facturerec->ref, $this->error)."\n";
1408 $this->db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1409 }
1410
1411 $parameters = array(
1412 'cpt' => $i,
1413 'total' => $num,
1414 'errorCount' => $error,
1415 'invoiceidgenerated' => $invoiceidgenerated,
1416 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1417 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1418 );
1419 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
1420
1421 $i++;
1422 }
1423
1424 $conf->entity = $saventity; // Restore entity context
1425 } else {
1426 dol_print_error($this->db);
1427 }
1428
1429 $this->output = trim($this->output);
1430
1431 return $error ? $error : 0;
1432 }
1433
1446 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = '', $save_lastsearch_value = -1)
1447 {
1448 global $langs, $hookmanager;
1449
1450 $result = '';
1451
1452 $label = '<u>'.$langs->trans("RepeatableInvoice").'</u>';
1453 if (!empty($this->ref)) {
1454 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1455 }
1456 if ($this->frequency > 0) {
1457 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1458 }
1459 if (!empty($this->date_last_gen)) {
1460 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1461 }
1462 if ($this->frequency > 0) {
1463 if (!empty($this->date_when)) {
1464 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1465 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1466 if (!empty($this->suspended)) {
1467 $label .= ' ('.$langs->trans("Disabled").')';
1468 }
1469 }
1470 }
1471
1472 $url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
1473
1474 if ($short) {
1475 return $url;
1476 }
1477
1478 if ($option != 'nolink') {
1479 // Add param to save lastsearch_values or not
1480 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1481 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1482 $add_save_lastsearch_values = 1;
1483 }
1484 if ($add_save_lastsearch_values) {
1485 $url .= '&save_lastsearch_values=1';
1486 }
1487 }
1488
1489 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1490 $linkend = '</a>';
1491
1492 $result .= $linkstart;
1493 if ($withpicto) {
1494 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1495 }
1496 if ($withpicto != 2) {
1497 $result .= $this->ref;
1498 }
1499 $result .= $linkend;
1500 global $action;
1501 $hookmanager->initHooks(array($this->element . 'dao'));
1502 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1503 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1504 if ($reshook > 0) {
1505 $result = $hookmanager->resPrint;
1506 } else {
1507 $result .= $hookmanager->resPrint;
1508 }
1509 return $result;
1510 }
1511
1519 public function getLibStatut($mode = 0, $alreadypaid = -1)
1520 {
1521 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1522 }
1523
1524 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1535 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1536 {
1537 // phpcs:enable
1538 global $langs;
1539 $langs->load('bills');
1540
1541 $labelStatus = $langs->transnoentitiesnoconv('Active');
1542 $statusType = 'status0';
1543
1544 //print "$recur,$status,$mode,$alreadypaid,$type";
1545 if ($mode == 0) {
1546 if ($recur) {
1547 if ($status == self::STATUS_SUSPENDED) {
1548 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1549 } else {
1550 $labelStatus = $langs->transnoentitiesnoconv('Active');
1551 }
1552 } else {
1553 if ($status == self::STATUS_SUSPENDED) {
1554 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1555 } else {
1556 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1557 }
1558 }
1559 } elseif ($mode == 1) {
1560 $prefix = 'Short';
1561 if ($recur) {
1562 if ($status == self::STATUS_SUSPENDED) {
1563 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1564 } else {
1565 $labelStatus = $langs->transnoentitiesnoconv('Active');
1566 }
1567 } else {
1568 if ($status == self::STATUS_SUSPENDED) {
1569 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1570 } else {
1571 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1572 }
1573 }
1574 } elseif ($mode == 2) {
1575 if ($recur) {
1576 if ($status == self::STATUS_SUSPENDED) {
1577 $statusType = 'status6';
1578 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1579 } else {
1580 $statusType = 'status4';
1581 $labelStatus = $langs->transnoentitiesnoconv('Active');
1582 }
1583 } else {
1584 if ($status == self::STATUS_SUSPENDED) {
1585 $statusType = 'status6';
1586 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1587 } else {
1588 $statusType = 'status0';
1589 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1590 }
1591 }
1592 } elseif ($mode == 3) {
1593 if ($recur) {
1594 $prefix = 'Short';
1595 if ($status == self::STATUS_SUSPENDED) {
1596 $statusType = 'status6';
1597 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1598 } else {
1599 $statusType = 'status4';
1600 $labelStatus = $langs->transnoentitiesnoconv('Active');
1601 }
1602 } else {
1603 if ($status == self::STATUS_SUSPENDED) {
1604 $statusType = 'status6';
1605 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1606 } else {
1607 $statusType = 'status0';
1608 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1609 }
1610 }
1611 } elseif ($mode == 4) {
1612 $prefix = '';
1613 if ($recur) {
1614 if ($status == self::STATUS_SUSPENDED) {
1615 $statusType = 'status6';
1616 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1617 } else {
1618 $statusType = 'status4';
1619 $labelStatus = $langs->transnoentitiesnoconv('Active');
1620 }
1621 } else {
1622 if ($status == self::STATUS_SUSPENDED) {
1623 $statusType = 'status6';
1624 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1625 } else {
1626 $statusType = 'status0';
1627 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1628 }
1629 }
1630 } elseif ($mode == 5 || $mode == 6) {
1631 $prefix = '';
1632 if ($mode == 5) {
1633 $prefix = 'Short';
1634 }
1635 if ($recur) {
1636 if ($status == self::STATUS_SUSPENDED) {
1637 $statusType = 'status6';
1638 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1639 } else {
1640 $statusType = 'status4';
1641 $labelStatus = $langs->transnoentitiesnoconv('Active');
1642 }
1643 } else {
1644 if ($status == self::STATUS_SUSPENDED) {
1645 $statusType = 'status6';
1646 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1647 } else {
1648 $statusType = 'status0';
1649 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1650 }
1651 }
1652 }
1653
1654 $labelStatusShort = $labelStatus;
1655
1656 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1657 }
1658
1667 public function initAsSpecimen($option = '')
1668 {
1669 global $user, $langs, $conf;
1670
1671 $now = dol_now();
1672 $arraynow = dol_getdate($now);
1673 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1674
1675 // Load array of products prodids
1676 $num_prods = 0;
1677 $prodids = array();
1678
1679 $sql = "SELECT rowid";
1680 $sql .= " FROM ".MAIN_DB_PREFIX."product";
1681 $sql .= " WHERE entity IN (".getEntity('product').")";
1682 $sql .= $this->db->plimit(100);
1683
1684 $resql = $this->db->query($sql);
1685 if ($resql) {
1686 $num_prods = $this->db->num_rows($resql);
1687 $i = 0;
1688 while ($i < $num_prods) {
1689 $i++;
1690 $row = $this->db->fetch_row($resql);
1691 $prodids[$i] = $row[0];
1692 }
1693 }
1694
1695 // Initialize parameters
1696 $this->id = 0;
1697 $this->ref = 'SPECIMEN';
1698 $this->title = 'SPECIMEN';
1699 $this->specimen = 1;
1700 $this->socid = 1;
1701 $this->date = $nownotime;
1702 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1703 $this->cond_reglement_id = 1;
1704 $this->cond_reglement_code = 'RECEP';
1705 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1706 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1707 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1708 $this->note_public = 'This is a comment (public)';
1709 $this->note_private = 'This is a comment (private)';
1710 $this->note = 'This is a comment (private)';
1711 $this->fk_incoterms = 0;
1712 $this->location_incoterms = '';
1713
1714 if (empty($option) || $option != 'nolines') {
1715 // Lines
1716 $nbp = 5;
1717 $xnbp = 0;
1718 while ($xnbp < $nbp) {
1719 $line = new FactureLigne($this->db);
1720 $line->desc = $langs->trans("Description")." ".$xnbp;
1721 $line->qty = 1;
1722 $line->subprice = 100;
1723 $line->tva_tx = 19.6;
1724 $line->localtax1_tx = 0;
1725 $line->localtax2_tx = 0;
1726 $line->remise_percent = 0;
1727 if ($xnbp == 1) { // Qty is negative (product line)
1728 $prodid = mt_rand(1, $num_prods);
1729 $line->fk_product = $prodids[$prodid];
1730 $line->qty = -1;
1731 $line->total_ht = -100;
1732 $line->total_ttc = -119.6;
1733 $line->total_tva = -19.6;
1734 } elseif ($xnbp == 2) { // UP is negative (free line)
1735 $line->subprice = -100;
1736 $line->total_ht = -100;
1737 $line->total_ttc = -119.6;
1738 $line->total_tva = -19.6;
1739 $line->remise_percent = 0;
1740 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1741 $prodid = mt_rand(1, $num_prods);
1742 $line->fk_product = $prodids[$prodid];
1743 $line->total_ht = 50;
1744 $line->total_ttc = 59.8;
1745 $line->total_tva = 9.8;
1746 $line->remise_percent = 50;
1747 } else // (product line)
1748 {
1749 $prodid = mt_rand(1, $num_prods);
1750 $line->fk_product = $prodids[$prodid];
1751 $line->total_ht = 100;
1752 $line->total_ttc = 119.6;
1753 $line->total_tva = 19.6;
1754 $line->remise_percent = 00;
1755 }
1756
1757 $this->lines[$xnbp] = $line;
1758 $xnbp++;
1759
1760 $this->total_ht += $line->total_ht;
1761 $this->total_tva += $line->total_tva;
1762 $this->total_ttc += $line->total_ttc;
1763 }
1764 $this->revenuestamp = 0;
1765
1766 // Add a line "offered"
1767 $line = new FactureLigne($this->db);
1768 $line->desc = $langs->trans("Description")." (offered line)";
1769 $line->qty = 1;
1770 $line->subprice = 100;
1771 $line->tva_tx = 19.6;
1772 $line->localtax1_tx = 0;
1773 $line->localtax2_tx = 0;
1774 $line->remise_percent = 100;
1775 $line->total_ht = 0;
1776 $line->total_ttc = 0; // 90 * 1.196
1777 $line->total_tva = 0;
1778 $prodid = mt_rand(1, $num_prods);
1779 $line->fk_product = $prodids[$prodid];
1780
1781 $this->lines[$xnbp] = $line;
1782 $xnbp++;
1783 }
1784
1785 $this->usenewprice = 0;
1786 }
1787
1796 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1797 {
1798 $tables = array(
1799 'facture_rec'
1800 );
1801
1802 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1803 }
1804
1813 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1814 {
1815 $tables = array(
1816 'facturedet_rec'
1817 );
1818
1819 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1820 }
1821
1830 public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
1831 {
1832 global $user;
1833
1834 if (!$this->table_element) {
1835 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1836 return -1;
1837 }
1838
1839 if (!empty($frequency) && empty($unit)) {
1840 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1841 return -2;
1842 }
1843
1844 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1845 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
1846 if (!empty($unit)) {
1847 $sql .= ', unit_frequency = \''.$this->db->escape($unit).'\'';
1848 }
1849 $sql .= " WHERE rowid = ".((int) $this->id);
1850
1851 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
1852 if ($this->db->query($sql)) {
1853 $this->frequency = $frequency;
1854 if (!empty($unit)) {
1855 $this->unit_frequency = $unit;
1856 }
1857
1858 if (!$notrigger) {
1859 // Call trigger
1860 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1861 if ($result < 0) {
1862 return $result;
1863 }
1864 // End call triggers
1865 }
1866
1867 return 1;
1868 } else {
1869 dol_print_error($this->db);
1870 return -1;
1871 }
1872 }
1873
1882 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1883 {
1884
1885 global $user;
1886
1887 if (!$this->table_element) {
1888 dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1889 return -1;
1890 }
1891 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1892 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
1893 if ($increment_nb_gen_done > 0) {
1894 $sql .= ', nb_gen_done = nb_gen_done + 1';
1895 }
1896 $sql .= " WHERE rowid = ".((int) $this->id);
1897
1898 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
1899 if ($this->db->query($sql)) {
1900 $this->date_when = $date;
1901 if ($increment_nb_gen_done > 0) {
1902 $this->nb_gen_done++;
1903 }
1904
1905 if (!$notrigger) {
1906 // Call trigger
1907 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1908 if ($result < 0) {
1909 return $result;
1910 }
1911 // End call triggers
1912 }
1913 return 1;
1914 } else {
1915 dol_print_error($this->db);
1916 return -1;
1917 }
1918 }
1919
1927 public function setMaxPeriod($nb, $notrigger = 0)
1928 {
1929
1930 global $user;
1931
1932 if (!$this->table_element) {
1933 dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1934 return -1;
1935 }
1936
1937 if (empty($nb)) {
1938 $nb = 0;
1939 }
1940
1941 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1942 $sql .= ' SET nb_gen_max = '.((int) $nb);
1943 $sql .= " WHERE rowid = ".((int) $this->id);
1944
1945 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
1946 if ($this->db->query($sql)) {
1947 $this->nb_gen_max = $nb;
1948
1949 if (!$notrigger) {
1950 // Call trigger
1951 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1952 if ($result < 0) {
1953 return $result;
1954 }
1955 // End call triggers
1956 }
1957
1958 return 1;
1959 } else {
1960 dol_print_error($this->db);
1961 return -1;
1962 }
1963 }
1964
1972 public function setAutoValidate($validate, $notrigger = 0)
1973 {
1974 global $user;
1975
1976 if (!$this->table_element) {
1977 dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
1978 return -1;
1979 }
1980
1981 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1982 $sql .= ' SET auto_validate = '.((int) $validate);
1983 $sql .= " WHERE rowid = ".((int) $this->id);
1984
1985 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
1986 if ($this->db->query($sql)) {
1987 $this->auto_validate = $validate;
1988
1989 if (!$notrigger) {
1990 // Call trigger
1991 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1992 if ($result < 0) {
1993 return $result;
1994 }
1995 // End call triggers
1996 }
1997
1998 return 1;
1999 } else {
2000 dol_print_error($this->db);
2001 return -1;
2002 }
2003 }
2004
2012 public function setGeneratePdf($validate, $notrigger = 0)
2013 {
2014 global $user;
2015
2016 if (!$this->table_element) {
2017 dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2018 return -1;
2019 }
2020
2021 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2022 $sql .= ' SET generate_pdf = '.((int) $validate);
2023 $sql .= " WHERE rowid = ".((int) $this->id);
2024
2025 dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
2026 if ($this->db->query($sql)) {
2027 $this->generate_pdf = $validate;
2028
2029 if (!$notrigger) {
2030 // Call trigger
2031 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2032 if ($result < 0) {
2033 return $result;
2034 }
2035 // End call triggers
2036 }
2037
2038 return 1;
2039 } else {
2040 dol_print_error($this->db);
2041 return -1;
2042 }
2043 }
2044
2052 public function setModelPdf($model, $notrigger = 0)
2053 {
2054 global $user;
2055 if (!$this->table_element) {
2056 dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2057 return -1;
2058 }
2059
2060 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2061 $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
2062 $sql .= " WHERE rowid = ".((int) $this->id);
2063
2064 dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
2065 if ($this->db->query($sql)) {
2066 $this->model_pdf = $model;
2067
2068 if (!$notrigger) {
2069 // Call trigger
2070 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2071 if ($result < 0) {
2072 return $result;
2073 }
2074 // End call triggers
2075 }
2076
2077 return 1;
2078 } else {
2079 dol_print_error($this->db);
2080 return -1;
2081 }
2082 }
2083}
2084
2085
2086
2092{
2096 public $element = 'facturedetrec';
2097
2101 public $table_element = 'facturedet_rec';
2102
2103
2104 public $fk_product_fournisseur_price;
2105 public $fk_fournprice; // For backward compatibility
2106
2107 public $rang;
2108 //public $situation_percent; // Not supported on recurring invoice line
2109
2110 public $desc;
2111 public $description;
2112
2113 public $fk_product_type; // Use instead product_type
2114
2115 public $fk_contract_line;
2116
2117
2125 public function delete(User $user, $notrigger = false)
2126 {
2127 $error = 0;
2128
2129 $this->db->begin();
2130
2131 if (!$error) {
2132 if (!$notrigger) {
2133 // Call triggers
2134 $result = $this->call_trigger('LINEBILLREC_DELETE', $user);
2135 if ($result < 0) {
2136 $error++;
2137 } // Do also here what you must do to rollback action if trigger fail
2138 // End call triggers
2139 }
2140 }
2141
2142 if (!$error) {
2143 $result = $this->deleteExtraFields();
2144 if ($result < 0) {
2145 $error++;
2146 }
2147 }
2148
2149 if (!$error) {
2150 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id);
2151
2152 $res = $this->db->query($sql);
2153 if (!$res) {
2154 $error++;
2155 $this->errors[] = $this->db->lasterror();
2156 }
2157 }
2158
2159 // Commit or rollback
2160 if ($error) {
2161 $this->db->rollback();
2162 return -1;
2163 } else {
2164 $this->db->commit();
2165 return 1;
2166 }
2167 }
2168
2169
2176 public function fetch($rowid)
2177 {
2178 $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,';
2179 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2180 $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2181 $sql .= ' l.rang, l.special_code,';
2182 $sql .= ' l.fk_unit, l.fk_contract_line,';
2183 $sql .= ' l.import_key, l.fk_multicurrency,';
2184 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2185 $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
2186 $sql .= ' l.fk_user_author, l.fk_user_modif,';
2187 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2188 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
2189 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2190 $sql .= ' WHERE l.rowid = '.((int) $rowid);
2191 $sql .= ' ORDER BY l.rang';
2192
2193 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2194 $result = $this->db->query($sql);
2195 if ($result) {
2196 $objp = $this->db->fetch_object($result);
2197
2198 $this->id = $objp->rowid;
2199 $this->label = $objp->custom_label; // Label line
2200 $this->desc = $objp->description; // Description line
2201 $this->description = $objp->description; // Description line
2202 $this->product_type = $objp->product_type; // Type of line
2203 $this->ref = $objp->product_ref; // Ref product
2204 $this->product_ref = $objp->product_ref; // Ref product
2205 $this->libelle = $objp->product_label; // deprecated
2206 $this->product_label = $objp->product_label; // Label product
2207 $this->product_desc = $objp->product_desc; // Description product
2208 $this->fk_product_type = $objp->fk_product_type; // Type of product
2209 $this->qty = $objp->qty;
2210 $this->price = $objp->price;
2211 $this->subprice = $objp->subprice;
2212 $this->fk_facture = $objp->fk_facture;
2213 $this->vat_src_code = $objp->vat_src_code;
2214 $this->tva_tx = $objp->tva_tx;
2215 $this->localtax1_tx = $objp->localtax1_tx;
2216 $this->localtax2_tx = $objp->localtax2_tx;
2217 $this->localtax1_type = $objp->localtax1_type;
2218 $this->localtax2_type = $objp->localtax2_type;
2219 $this->remise_percent = $objp->remise_percent;
2220 //$this->fk_remise_except = $objp->fk_remise_except;
2221 $this->fk_product = $objp->fk_product;
2222 $this->date_start_fill = $objp->date_start_fill;
2223 $this->date_end_fill = $objp->date_end_fill;
2224 $this->info_bits = $objp->info_bits;
2225 $this->total_ht = $objp->total_ht;
2226 $this->total_tva = $objp->total_tva;
2227 $this->total_ttc = $objp->total_ttc;
2228 //$this->code_ventilation = $objp->fk_code_ventilation;
2229 $this->rang = $objp->rang;
2230 $this->special_code = $objp->special_code;
2231 $this->fk_unit = $objp->fk_unit;
2232 $this->fk_contract_line = $objp->fk_contract_line;
2233 $this->import_key = $objp->import_key;
2234 $this->fk_multicurrency = $objp->fk_multicurrency;
2235 $this->multicurrency_code = $objp->multicurrency_code;
2236 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2237 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2238 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2239 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2240
2241 $this->buy_price_ht = $objp->buy_price_ht;
2242
2243 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2244 $this->fk_user_author = $objp->fk_user_author;
2245 $this->fk_user_modif = $objp->fk_user_modif;
2246
2247 $this->db->free($result);
2248 return 1;
2249 } else {
2250 $this->error = $this->db->lasterror();
2251 return -3;
2252 }
2253 }
2254
2255
2263 public function update(User $user, $notrigger = 0)
2264 {
2265 global $conf;
2266
2267 $error = 0;
2268
2269 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2270
2271 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
2272 $sql .= " fk_facture = ".((int) $this->fk_facture);
2273 $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
2274 $sql .= ", description='".$this->db->escape($this->desc)."'";
2275 $sql .= ", price=".price2num($this->price);
2276 $sql .= ", qty=".price2num($this->qty);
2277 $sql .= ", tva_tx=".price2num($this->tva_tx);
2278 $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
2279 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
2280 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
2281 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
2282 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
2283 $sql .= ", fk_product=".($this->fk_product > 0 ? $this->fk_product : "null");
2284 $sql .= ", product_type=".((int) $this->product_type);
2285 $sql .= ", remise_percent=".price2num($this->remise_percent);
2286 $sql .= ", subprice=".price2num($this->subprice);
2287 $sql .= ", info_bits=".price2num($this->info_bits);
2288 $sql .= ", date_start_fill=".(int) $this->date_start_fill;
2289 $sql .= ", date_end_fill=".(int) $this->date_end_fill;
2290 if (empty($this->skip_update_total)) {
2291 $sql .= ", total_ht=".price2num($this->total_ht);
2292 $sql .= ", total_tva=".price2num($this->total_tva);
2293 $sql .= ", total_localtax1=".price2num($this->total_localtax1);
2294 $sql .= ", total_localtax2=".price2num($this->total_localtax2);
2295 $sql .= ", total_ttc=".price2num($this->total_ttc);
2296 }
2297 $sql .= ", rang=".((int) $this->rang);
2298 $sql .= ", special_code=".((int) $this->special_code);
2299 $sql .= ", fk_unit=".($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : "null");
2300 $sql .= ", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line : "null");
2301 $sql .= " WHERE rowid = ".((int) $this->id);
2302
2303 $this->db->begin();
2304
2305 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
2306
2307 $resql = $this->db->query($sql);
2308 if ($resql) {
2309 if (!$error) {
2310 $result = $this->insertExtraFields();
2311 if ($result < 0) {
2312 $error++;
2313 }
2314 }
2315
2316 if (!$error && !$notrigger) {
2317 // Call trigger
2318 $result = $this->call_trigger('LINEBILLREC_MODIFY', $user);
2319 if ($result < 0) {
2320 $error++;
2321 }
2322 // End call triggers
2323 }
2324
2325 if ($error) {
2326 $this->db->rollback();
2327 return -2;
2328 } else {
2329 $this->db->commit();
2330 return 1;
2331 }
2332 } else {
2333 $this->error = $this->db->lasterror();
2334 $this->db->rollback();
2335 return -2;
2336 }
2337 }
2338}
$object ref
Definition info.php:78
Superclass for invoices classes.
const TYPE_STANDARD
Standard invoice.
calculate_date_lim_reglement($cond_reglement=0)
Returns an invoice payment deadline based on the invoice settlement conditions and billing date.
const STATUS_DRAFT
Draft status.
Parent class of all other business classes for details of elements (invoices, contracts,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
deleteExtraFields()
Delete all extra fields values for the current object.
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.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage invoices.
Class to manage invoice lines.
Class to manage invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
create($user, $facid, $notrigger=0)
Create a predefined invoice.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
fetch_lines()
Get lines of template invoices into this->lines.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0)
Add a line to invoice.
getLinesArray()
Create an array of invoice lines.
updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $date_start_fill=0, $date_end_fill=0, $fk_fournprice=null, $pa_ht=0)
Update a line to invoice.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
isMaxNbGenReached()
Return if maximum number of generation is reached.
setModelPdf($model, $notrigger=0)
Update the model for documents.
__construct(DoliDB $db)
Constructor.
setNextDate($date, $increment_nb_gen_done=0, $notrigger=0)
Update the next date of execution.
setAutoValidate($validate, $notrigger=0)
Update the auto validate flag of invoice.
initAsSpecimen($option='')
Initialise an instance with random values.
setMaxPeriod($nb, $notrigger=0)
Update the maximum period.
update(User $user, $notrigger=0)
Update a line invoice_rec.
fetch($rowid, $ref='', $ref_ext='')
Load object and lines.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
setGeneratePdf($validate, $notrigger=0)
Update the auto generate documents.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
getNextDate()
Return the next date of.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0, $notrigger=0)
Create all recurrents invoices (for all entities if multicompany is used).
Class to manage products or services.
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
Definition index.php:152
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:123
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.
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...
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
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.
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...
getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
Return an array with margins information of a line.
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.
Definition price.lib.php:86
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120