dolibarr 19.0.4
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 * Copyright (C) 2023 Nick Fragoulis
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 */
25
32require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36
37
42{
43 const TRIGGER_PREFIX = 'BILLREC';
47 public $element = 'facturerec';
48
52 public $table_element = 'facture_rec';
53
57 public $table_element_line = 'facturedet_rec';
58
62 public $fk_element = 'fk_facture';
63
67 public $picto = 'bill';
68
72 public $entity;
73
77 protected $table_ref_field = 'titre';
78
82 public $title;
83
88 public $titre;
89
93 public $multicurrency_subprice;
94 public $socid;
95 public $number;
96 public $date;
97 //public $remise;
98 //public $remise_absolue;
99 //public $remise_percent;
100
105 public $total;
106
111 public $tva;
112
113 public $date_last_gen;
114 public $date_when;
115 public $nb_gen_done;
116 public $nb_gen_max;
117
118 public $user_author;
119
123 public $frequency;
124
128 public $unit_frequency;
129
130 public $rang;
131 public $special_code;
132
133 public $usenewprice = 0;
134
135 public $date_lim_reglement;
136 public $cond_reglement_code; // Code in llx_c_paiement
137 public $mode_reglement_code; // Code in llx_c_paiement
138
139 public $fk_multicurrency;
140 public $multicurrency_code;
141 public $multicurrency_tx;
142 public $multicurrency_total_ht;
143 public $multicurrency_total_tva;
144 public $multicurrency_total_ttc;
145
146 public $suspended; // status
147
148 public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
149 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
150
151
176 // BEGIN MODULEBUILDER PROPERTIES
180 public $fields = array(
181 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
182 'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15),
183 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20, 'index'=>1),
184 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>25),
185 'subtype' =>array('type'=>'smallint(6)', 'label'=>'InvoiceSubtype', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
186 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>35),
187 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1),
188 'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1),
189 'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1),
190 'total_ht' =>array('type'=>'double(24,8)', 'label'=>'Total', 'enabled'=>1, 'visible'=>-1, 'position'=>70, 'isameasure'=>1),
191 'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>75, 'isameasure'=>1),
192 'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
193 '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),
194 'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Fk cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
195 'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'Fk mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
196 'date_lim_reglement' =>array('type'=>'date', 'label'=>'Date lim reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
197 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>105),
198 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>110),
199 'modelpdf' =>array('type'=>'varchar(255)', 'label'=>'Modelpdf', 'enabled'=>1, 'visible'=>-1, 'position'=>115),
200 'date_when' =>array('type'=>'datetime', 'label'=>'Date when', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
201 'date_last_gen' =>array('type'=>'datetime', 'label'=>'Date last gen', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
202 'nb_gen_done' =>array('type'=>'integer', 'label'=>'Nb gen done', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
203 'nb_gen_max' =>array('type'=>'integer', 'label'=>'Nb gen max', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
204 'frequency' =>array('type'=>'integer', 'label'=>'Frequency', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
205 'unit_frequency' =>array('type'=>'varchar(2)', 'label'=>'UnitFrequency', 'enabled'=>1, 'visible'=>-1, 'position'=>152),
206 'usenewprice' =>array('type'=>'integer', 'label'=>'UseNewPrice', 'enabled'=>1, 'visible'=>0, 'position'=>155),
207 'revenuestamp' =>array('type'=>'double(24,8)', 'label'=>'RevenueStamp', 'enabled'=>1, 'visible'=>-1, 'position'=>160, 'isameasure'=>1),
208 'auto_validate' =>array('type'=>'integer', 'label'=>'Auto validate', 'enabled'=>1, 'visible'=>-1, 'position'=>165),
209 'generate_pdf' =>array('type'=>'integer', 'label'=>'Generate pdf', 'enabled'=>1, 'visible'=>-1, 'position'=>170),
210 'fk_account' =>array('type'=>'integer', 'label'=>'Fk account', 'enabled'=>'isModEnabled("banque")', 'visible'=>-1, 'position'=>175),
211 'fk_multicurrency' =>array('type'=>'integer', 'label'=>'Fk multicurrency', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
212 'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'Multicurrency code', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
213 'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency tx', 'enabled'=>1, 'visible'=>-1, 'position'=>190, 'isameasure'=>1),
214 'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ht', 'enabled'=>1, 'visible'=>-1, 'position'=>195, 'isameasure'=>1),
215 'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total tva', 'enabled'=>1, 'visible'=>-1, 'position'=>200, 'isameasure'=>1),
216 'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>205, 'isameasure'=>1),
217 'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>210),
218 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>215),
219 'suspended' =>array('type'=>'integer', 'label'=>'Suspended', 'enabled'=>1, 'visible'=>-1, 'position'=>225),
220 );
221 // END MODULEBUILDER PROPERTIES
222
223 const STATUS_NOTSUSPENDED = 0;
224 const STATUS_SUSPENDED = 1;
225
226
227
233 public function __construct(DoliDB $db)
234 {
235 $this->db = $db;
236 }
237
247 public function create($user, $facid, $notrigger = 0, $onlylines = array())
248 {
249 global $conf;
250
251 $error = 0;
252 $now = dol_now();
253
254 // Clean parameters
255 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
256 $this->title = trim($this->title);
257 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
258 if (empty($this->suspended)) {
259 $this->suspended = 0;
260 }
261
262 // No frequency defined then no next date to execution
263 if (empty($this->frequency)) {
264 $this->frequency = 0;
265 $this->date_when = null;
266 }
267
268 $this->frequency = abs($this->frequency);
269 $this->nb_gen_done = 0;
270 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
271 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
272 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
273
274 $this->db->begin();
275
276 // Load invoice template
277 $facsrc = new Facture($this->db);
278 $result = $facsrc->fetch($facid);
279 if ($result > 0) {
280 $this->socid = $facsrc->socid;
281
282 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
283 $sql .= "titre";
284 $sql .= ", fk_soc";
285 $sql .= ", subtype";
286 $sql .= ", entity";
287 $sql .= ", datec";
288 $sql .= ", amount";
289 //$sql .= ", remise";
290 $sql .= ", note_private";
291 $sql .= ", note_public";
292 $sql .= ", modelpdf";
293 $sql .= ", fk_user_author";
294 $sql .= ", fk_projet";
295 $sql .= ", fk_account";
296 $sql .= ", fk_cond_reglement";
297 $sql .= ", fk_mode_reglement";
298 $sql .= ", usenewprice";
299 $sql .= ", frequency";
300 $sql .= ", unit_frequency";
301 $sql .= ", date_when";
302 $sql .= ", date_last_gen";
303 $sql .= ", nb_gen_done";
304 $sql .= ", nb_gen_max";
305 $sql .= ", auto_validate";
306 $sql .= ", generate_pdf";
307 $sql .= ", fk_multicurrency";
308 $sql .= ", multicurrency_code";
309 $sql .= ", multicurrency_tx";
310 $sql .= ", suspended";
311 $sql .= ") VALUES (";
312 $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
313 $sql .= ", ".((int) $this->socid);
314 $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
315 $sql .= ", ".((int) $conf->entity);
316 $sql .= ", '".$this->db->idate($now)."'";
317 $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
318 //$sql .= ", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) : '0');
319 $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
320 $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
321 $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL");
322 $sql .= ", ".((int) $user->id);
323 $sql .= ", ".(!empty($this->fk_project) ? ((int) $this->fk_project) : "null");
324 $sql .= ", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) : "null");
325 $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
326 $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
327 $sql .= ", ".((int) $this->usenewprice);
328 $sql .= ", ".((int) $this->frequency);
329 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
330 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
331 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
332 $sql .= ", ".((int) $this->nb_gen_done);
333 $sql .= ", ".((int) $this->nb_gen_max);
334 $sql .= ", ".((int) $this->auto_validate);
335 $sql .= ", ".((int) $this->generate_pdf);
336 $sql .= ", ".((int) $facsrc->fk_multicurrency);
337 $sql .= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
338 $sql .= ", ".((float) $facsrc->multicurrency_tx);
339 $sql .= ", ".((int) $this->suspended);
340 $sql .= ")";
341
342 if ($this->db->query($sql)) {
343 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
344
345 // Fields used into addline later
346 $this->fk_multicurrency = $facsrc->fk_multicurrency;
347 $this->multicurrency_code = $facsrc->multicurrency_code;
348 $this->multicurrency_tx = $facsrc->multicurrency_tx;
349
350 // Add lines
351 $fk_parent_line = 0;
352
353 $num = count($facsrc->lines);
354 for ($i = 0; $i < $num; $i++) {
355 if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
356 continue; // Skip unselected lines
357 }
358
359 // Reset fk_parent_line for no child products and special product
360 if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) {
361 $fk_parent_line = 0;
362 }
363
364 $tva_tx = $facsrc->lines[$i]->tva_tx;
365 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
366 $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
367 }
368
369 $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START');
370 $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END');
371
372 $result_insert = $this->addline(
373 $facsrc->lines[$i]->desc,
374 $facsrc->lines[$i]->subprice,
375 $facsrc->lines[$i]->qty,
376 $tva_tx,
377 $facsrc->lines[$i]->localtax1_tx,
378 $facsrc->lines[$i]->localtax2_tx,
379 $facsrc->lines[$i]->fk_product,
380 $facsrc->lines[$i]->remise_percent,
381 'HT',
382 $facsrc->lines[$i]->info_bits,
383 '',
384 0,
385 $facsrc->lines[$i]->product_type,
386 $facsrc->lines[$i]->rang,
387 $facsrc->lines[$i]->special_code,
388 $facsrc->lines[$i]->label,
389 $facsrc->lines[$i]->fk_unit,
390 $facsrc->lines[$i]->multicurrency_subprice,
391 $default_start_fill,
392 $default_end_fill,
393 null,
394 $facsrc->lines[$i]->pa_ht,
395 $fk_parent_line
396 );
397
398 // Defined the new fk_parent_line
399 if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) {
400 $fk_parent_line = $result_insert;
401 }
402
403 if ($result_insert < 0) {
404 $error++;
405 } else {
406 $objectline = new FactureLigneRec($this->db);
407
408 $result2 = $objectline->fetch($result_insert);
409 if ($result2 > 0) {
410 // Extrafields
411 if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
412 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
413 $objectline->array_options = $facsrc->lines[$i]->array_options;
414 }
415
416 $result = $objectline->insertExtraFields();
417 if ($result < 0) {
418 $error++;
419 }
420 } elseif ($result2 < 0) {
421 $this->errors[] = $objectline->error;
422 $error++;
423 }
424 }
425 }
426
427 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
428 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
429 }
430
431 // Add object linked
432 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
433 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
434 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, ...))
435 foreach ($tmp_origin_id as $origin_id) {
436 $ret = $this->add_object_linked($origin, $origin_id);
437 if (!$ret) {
438 $this->error = $this->db->lasterror();
439 $error++;
440 }
441 }
442 } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
443 $origin_id = $tmp_origin_id;
444 $ret = $this->add_object_linked($origin, $origin_id);
445 if (!$ret) {
446 $this->error = $this->db->lasterror();
447 $error++;
448 }
449 }
450 }
451 }
452
453 if (!$error) {
454 $result = $this->insertExtraFields();
455 if ($result < 0) {
456 $error++;
457 }
458 }
459
460 if (!$error && !$notrigger) {
461 // Call trigger
462 $result = $this->call_trigger('BILLREC_CREATE', $user);
463 if ($result < 0) {
464 $this->db->rollback();
465 return -2;
466 }
467 // End call triggers
468 }
469
470 if ($error) {
471 $this->db->rollback();
472 return -3;
473 } else {
474 $this->db->commit();
475 return $this->id;
476 }
477 } else {
478 $this->error = $this->db->lasterror();
479 $this->db->rollback();
480 return -2;
481 }
482 } else {
483 $this->db->rollback();
484 return -1;
485 }
486 }
487
488
496 public function update(User $user, $notrigger = 0)
497 {
498 $error = 0;
499
500 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET";
501 $sql .= " entity = ".((int) $this->entity).",";
502 $sql .= " titre = '".$this->db->escape($this->title)."',";
503 $sql .= " suspended = ".((int) $this->suspended).",";
504 $sql .= " fk_soc = ".((int) $this->socid).",";
505 $sql .= " total_tva = ".((float) $this->total_tva).",";
506 $sql .= " localtax1 = ".((float) $this->total_localtax1).",";
507 $sql .= " localtax2 = ".((float) $this->total_localtax2).",";
508 $sql .= " total_ht = ".((float) $this->total_ht).",";
509 $sql .= " total_ttc = ".((float) $this->total_ttc);
510 // TODO Add missing fields
511 $sql .= " WHERE rowid = ".((int) $this->id);
512
513 $this->db->begin();
514
515 dol_syslog(get_class($this)."::update", LOG_DEBUG);
516
517 $resql = $this->db->query($sql);
518 if ($resql) {
519 if (!$error) {
520 $result = $this->insertExtraFields();
521 if ($result < 0) {
522 $error++;
523 }
524 }
525
526 if (!$error && !$notrigger) {
527 // Call trigger
528 $result = $this->call_trigger('BILLREC_MODIFY', $user);
529 if ($result < 0) {
530 $this->db->rollback();
531 return -2;
532 }
533 // End call triggers
534 }
535 $this->db->commit();
536 return 1;
537 } else {
538 $this->error = $this->db->lasterror();
539 $this->db->rollback();
540 return -1;
541 }
542 }
543
554 public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nolines = 0)
555 {
556 dol_syslog('FactureRec::fetch', LOG_DEBUG);
557
558 $sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.subtype, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
559 $sql .= ', f.date_lim_reglement as dlr';
560 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
561 $sql .= ', f.modelpdf as model_pdf';
562 $sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
563 $sql .= ', f.fk_account';
564 $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';
565 $sql .= ', f.generate_pdf';
566 $sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
567 $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
568 $sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
569 //$sql.= ', el.fk_source';
570 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
571 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
572 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
573 //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
574 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
575 if ($rowid) {
576 $sql .= ' AND f.rowid = '.((int) $rowid);
577 } elseif ($ref) {
578 $sql .= " AND f.titre = '".$this->db->escape($ref)."'";
579 } else {
580 $sql .= ' AND f.rowid = 0';
581 }
582 /* This field are not used for template invoice
583 if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
584 */
585
586 $result = $this->db->query($sql);
587 if ($result) {
588 if ($this->db->num_rows($result)) {
589 $obj = $this->db->fetch_object($result);
590
591 $this->id = $obj->rowid;
592 $this->entity = $obj->entity;
593 $this->titre = $obj->title; // deprecated
594 $this->title = $obj->title;
595 $this->ref = $obj->title;
596 $this->subtype = $obj->subtype;
597 $this->suspended = $obj->suspended;
598 $this->total_ht = $obj->total_ht;
599 $this->total_tva = $obj->total_tva;
600 $this->total_localtax1 = $obj->localtax1;
601 $this->total_localtax2 = $obj->localtax2;
602 $this->total_ttc = $obj->total_ttc;
603 $this->socid = $obj->fk_soc;
604 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
605 $this->mode_reglement_id = $obj->fk_mode_reglement;
606 $this->mode_reglement_code = $obj->mode_reglement_code;
607 $this->mode_reglement = $obj->mode_reglement_libelle;
608 $this->cond_reglement_id = $obj->fk_cond_reglement;
609 $this->cond_reglement_code = $obj->cond_reglement_code;
610 $this->cond_reglement = $obj->cond_reglement_libelle;
611 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
612 $this->fk_project = $obj->fk_project;
613 $this->fk_account = $obj->fk_account;
614 $this->note_private = $obj->note_private;
615 $this->note_public = $obj->note_public;
616 $this->user_author = $obj->fk_user_author;
617 $this->model_pdf = $obj->model_pdf;
618 //$this->special_code = $obj->special_code;
619 $this->frequency = $obj->frequency;
620 $this->unit_frequency = $obj->unit_frequency;
621 $this->date_when = $this->db->jdate($obj->date_when);
622 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
623 $this->nb_gen_done = $obj->nb_gen_done;
624 $this->nb_gen_max = $obj->nb_gen_max;
625 $this->usenewprice = $obj->usenewprice;
626 $this->auto_validate = $obj->auto_validate;
627 $this->generate_pdf = $obj->generate_pdf;
628
629 // Multicurrency
630 $this->fk_multicurrency = $obj->fk_multicurrency;
631 $this->multicurrency_code = $obj->multicurrency_code;
632 $this->multicurrency_tx = $obj->multicurrency_tx;
633 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
634 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
635 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
636
637 // Retrieve all extrafield
638 // fetch optionals attributes and labels
639 if (empty($noextrafields)) {
640 $result = $this->fetch_optionals();
641 if ($result < 0) {
642 $this->error = $this->db->lasterror();
643 return -4;
644 }
645 }
646
647 // Retreive lines
648 if (empty($nolines)) {
649 $result = $this->fetch_lines();
650 if ($result < 0) {
651 $this->error = $this->db->lasterror();
652 return -3;
653 }
654 }
655
656 return 1;
657 } else {
658 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
659 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
660 return -2;
661 }
662 } else {
663 $this->error = $this->db->error();
664 return -1;
665 }
666 }
667
668
674 public function getLinesArray()
675 {
676 return $this->fetch_lines();
677 }
678
679
680 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
686 public function fetch_lines()
687 {
688 // phpcs:enable
689
690 $this->lines = array();
691
692 dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
693
694 $sql = 'SELECT l.rowid, l.fk_facture, l.fk_product, l.fk_parent_line, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
695 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
696 $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,';
697 $sql .= ' l.rang, l.special_code,';
698 $sql .= ' l.fk_unit, l.fk_contract_line,';
699 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
700 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
701 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
702 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
703 $sql .= ' WHERE l.fk_facture = '.((int) $this->id);
704 $sql .= ' ORDER BY l.rang';
705
706 $result = $this->db->query($sql);
707 if ($result) {
708 $num = $this->db->num_rows($result);
709 $i = 0;
710 while ($i < $num) {
711 $objp = $this->db->fetch_object($result);
712 $line = new FactureLigneRec($this->db);
713
714 $line->id = $objp->rowid;
715 $line->rowid = $objp->rowid;
716 $line->fk_facture = $objp->fk_facture;
717 $line->fk_parent_line = $objp->fk_parent_line;
718 $line->desc = $objp->description; // Description line
719 $line->description = $objp->description; // Description line
720 $line->ref = $objp->product_ref; // Ref product
721 $line->product_ref = $objp->product_ref; // Ref product
722 $line->libelle = $objp->product_label; // deprecated
723 $line->product_label = $objp->product_label; // Label product
724 $line->product_desc = $objp->product_desc; // Description product
725 $line->product_type = $objp->product_type; // Type of line
726 $line->fk_product_type = $objp->fk_product_type; // Type of product
727 $line->qty = $objp->qty;
728 $line->subprice = $objp->subprice;
729
730 $line->label = $objp->custom_label; // @deprecated
731
732 $line->vat_src_code = $objp->vat_src_code;
733 $line->tva_tx = $objp->tva_tx;
734 $line->localtax1_tx = $objp->localtax1_tx;
735 $line->localtax2_tx = $objp->localtax2_tx;
736 $line->localtax1_type = $objp->localtax1_type;
737 $line->localtax2_type = $objp->localtax2_type;
738 $line->remise_percent = $objp->remise_percent;
739 //$line->fk_remise_except = $objp->fk_remise_except;
740 $line->fk_product = $objp->fk_product;
741 $line->date_start_fill = $objp->date_start_fill;
742 $line->date_end_fill = $objp->date_end_fill;
743 $line->info_bits = $objp->info_bits;
744 $line->total_ht = $objp->total_ht;
745 $line->total_tva = $objp->total_tva;
746 $line->total_ttc = $objp->total_ttc;
747
748 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
749 $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
750
751 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
752
753 $line->buyprice = $marginInfos[0];
754 $line->pa_ht = $marginInfos[0]; // For backward compatibility
755 $line->marge_tx = $marginInfos[1];
756 $line->marque_tx = $marginInfos[2];
757 $line->rang = $objp->rang;
758 $line->special_code = $objp->special_code;
759 $line->fk_unit = $objp->fk_unit;
760 $line->fk_contract_line = $objp->fk_contract_line;
761
762 // Ne plus utiliser
763 $line->price = $objp->price;
764 $line->remise = $objp->remise;
765
766 $line->fetch_optionals();
767
768 // Multicurrency
769 $line->fk_multicurrency = $objp->fk_multicurrency;
770 $line->multicurrency_code = $objp->multicurrency_code;
771 $line->multicurrency_subprice = $objp->multicurrency_subprice;
772 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
773 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
774 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
775
776 $this->lines[$i] = $line;
777
778 $i++;
779 }
780
781 $this->db->free($result);
782 return 1;
783 } else {
784 $this->error = $this->db->lasterror();
785 return -3;
786 }
787 }
788
789
798 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
799 {
800 $rowid = $this->id;
801
802 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
803
804 $error = 0;
805 $this->db->begin();
806
807 $main = MAIN_DB_PREFIX.'facturedet_rec';
808 $ef = $main."_extrafields";
809
810 $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")";
811 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".((int) $rowid);
812
813 if ($this->db->query($sqlef) && $this->db->query($sql)) {
814 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".((int) $rowid);
815 dol_syslog($sql);
816 if ($this->db->query($sql)) {
817 // Delete linked object
818 $res = $this->deleteObjectLinked();
819 if ($res < 0) {
820 $error = -3;
821 }
822 // Delete extrafields
823 $res = $this->deleteExtraFields();
824 if ($res < 0) {
825 $error = -4;
826 }
827 } else {
828 $this->error = $this->db->lasterror();
829 $error = -1;
830 }
831 } else {
832 $this->error = $this->db->lasterror();
833 $error = -2;
834 }
835 if (!$error && !$notrigger) {
836 // Call trigger
837 $result = $this->call_trigger('BILLREC_DELETE', $user);
838 if ($result < 0) {
839 $error++;
840 }
841 // End call triggers
842 }
843 if (!$error) {
844 $this->db->commit();
845 return 1;
846 } else {
847 $this->db->rollback();
848 return $error;
849 }
850 }
851
852
881 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 = 0, $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, $fk_parent_line = 0)
882 {
883 global $mysoc;
884
885 $facid = $this->id;
886
887 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);
888 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
889
890 // Check parameters
891 if ($type < 0) {
892 return -1;
893 }
894
895 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
896
897 // Clean vat code
898 $reg = array();
899 $vat_src_code = '';
900 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
901 $vat_src_code = $reg[1];
902 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
903 }
904
905
906 // Clean parameters
907 $remise_percent = price2num($remise_percent);
908 if (empty($remise_percent)) {
909 $remise_percent = 0;
910 }
911 $qty = price2num($qty);
912 $pu_ht = price2num($pu_ht);
913 $pu_ttc = price2num($pu_ttc);
914 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
915 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
916 }
917 $txlocaltax1 = price2num($txlocaltax1);
918 $txlocaltax2 = price2num($txlocaltax2);
919 if (empty($txtva)) {
920 $txtva = 0;
921 }
922 if (empty($txlocaltax1)) {
923 $txlocaltax1 = 0;
924 }
925 if (empty($txlocaltax2)) {
926 $txlocaltax2 = 0;
927 }
928 if (empty($info_bits)) {
929 $info_bits = 0;
930 }
931
932 if ($price_base_type == 'HT') {
933 $pu = $pu_ht;
934 } else {
935 $pu = $pu_ttc;
936 }
937
938 // Calcul du total TTC et de la TVA pour la ligne a partir de
939 // qty, pu, remise_percent et txtva
940 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
941 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
942
943 $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);
944 $total_ht = $tabprice[0];
945 $total_tva = $tabprice[1];
946 $total_ttc = $tabprice[2];
947 $total_localtax1 = $tabprice[9];
948 $total_localtax2 = $tabprice[10];
949 $pu_ht = $tabprice[3];
950
951 // MultiCurrency
952 $multicurrency_total_ht = $tabprice[16];
953 $multicurrency_total_tva = $tabprice[17];
954 $multicurrency_total_ttc = $tabprice[18];
955 $pu_ht_devise = $tabprice[19];
956
957 $product_type = $type;
958 if ($fk_product) {
959 $product = new Product($this->db);
960 $result = $product->fetch($fk_product);
961 $product_type = $product->type;
962 }
963
964 if (empty($fk_parent_line) || $fk_parent_line < 0) {
965 $fk_parent_line = 0;
966 }
967
968 // Rank to use
969 $ranktouse = $rang;
970 if ($ranktouse == -1) {
971 $rangmax = $this->line_max(0);
972 $ranktouse = $rangmax + 1;
973 }
974
975 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
976 $sql .= "fk_facture";
977 $sql .= ", fk_parent_line";
978 $sql .= ", label";
979 $sql .= ", description";
980 $sql .= ", price";
981 $sql .= ", qty";
982 $sql .= ", tva_tx";
983 $sql .= ", vat_src_code";
984 $sql .= ", localtax1_tx";
985 $sql .= ", localtax1_type";
986 $sql .= ", localtax2_tx";
987 $sql .= ", localtax2_type";
988 $sql .= ", fk_product";
989 $sql .= ", product_type";
990 $sql .= ", remise_percent";
991 $sql .= ", subprice";
992 $sql .= ", remise";
993 $sql .= ", total_ht";
994 $sql .= ", total_tva";
995 $sql .= ", total_localtax1";
996 $sql .= ", total_localtax2";
997 $sql .= ", total_ttc";
998 $sql .= ", date_start_fill";
999 $sql .= ", date_end_fill";
1000 $sql .= ", fk_product_fournisseur_price";
1001 $sql .= ", buy_price_ht";
1002 $sql .= ", info_bits";
1003 $sql .= ", rang";
1004 $sql .= ", special_code";
1005 $sql .= ", fk_unit";
1006 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1007 $sql .= ") VALUES (";
1008 $sql .= " ".((int) $facid);
1009 $sql .= ", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1010 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1011 $sql .= ", '".$this->db->escape($desc)."'";
1012 $sql .= ", ".price2num($pu_ht);
1013 $sql .= ", ".price2num($qty);
1014 $sql .= ", ".price2num($txtva);
1015 $sql .= ", '".$this->db->escape($vat_src_code)."'";
1016 $sql .= ", ".price2num($txlocaltax1);
1017 $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
1018 $sql .= ", ".price2num($txlocaltax2);
1019 $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
1020 $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1021 $sql .= ", ".((int) $product_type);
1022 $sql .= ", ".price2num($remise_percent);
1023 $sql .= ", ".price2num($pu_ht);
1024 $sql .= ", null";
1025 $sql .= ", ".price2num($total_ht);
1026 $sql .= ", ".price2num($total_tva);
1027 $sql .= ", ".price2num($total_localtax1);
1028 $sql .= ", ".price2num($total_localtax2);
1029 $sql .= ", ".price2num($total_ttc);
1030 $sql .= ", ".(int) $date_start_fill;
1031 $sql .= ", ".(int) $date_end_fill;
1032 $sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1033 $sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
1034 $sql .= ", ".((int) $info_bits);
1035 $sql .= ", ".((int) $ranktouse);
1036 $sql .= ", ".((int) $special_code);
1037 $sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
1038 $sql .= ", ".(int) $this->fk_multicurrency;
1039 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1040 $sql .= ", ".price2num($pu_ht_devise, 'CU');
1041 $sql .= ", ".price2num($multicurrency_total_ht, 'CT');
1042 $sql .= ", ".price2num($multicurrency_total_tva, 'CT');
1043 $sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
1044 $sql .= ")";
1045
1046 dol_syslog(get_class($this)."::addline", LOG_DEBUG);
1047 if ($this->db->query($sql)) {
1048 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
1049 $this->id = $facid;
1050 $this->update_price(1);
1051 return $lineId;
1052 } else {
1053 $this->error = $this->db->lasterror();
1054 return -1;
1055 }
1056 }
1057
1088 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 = 0, $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, $fk_parent_line = 0)
1089 {
1090 global $mysoc;
1091
1092 $facid = $this->id;
1093
1094 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);
1095 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1096
1097 // Clean parameters
1098 if (empty($remise_percent)) {
1099 $remise_percent = 0;
1100 }
1101
1102 // Check parameters
1103 if ($type < 0) {
1104 return -1;
1105 }
1106
1107 // Clean parameters
1108 $remise_percent = price2num($remise_percent);
1109 $qty = price2num($qty);
1110 if (empty($info_bits)) {
1111 $info_bits = 0;
1112 }
1113 $pu_ht = price2num($pu_ht);
1114 $pu_ttc = price2num($pu_ttc);
1115 $pu_ht_devise = price2num($pu_ht_devise);
1116 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
1117 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1118 }
1119 $txlocaltax1 = price2num($txlocaltax1);
1120 $txlocaltax2 = price2num($txlocaltax2);
1121 if (empty($txlocaltax1)) {
1122 $txlocaltax1 = 0;
1123 }
1124 if (empty($txlocaltax2)) {
1125 $txlocaltax2 = 0;
1126 }
1127
1128 if (empty($this->multicurrency_subprice)) {
1129 $this->multicurrency_subprice = 0;
1130 }
1131 if (empty($this->multicurrency_total_ht)) {
1132 $this->multicurrency_total_ht = 0;
1133 }
1134 if (empty($this->multicurrency_total_tva)) {
1135 $this->multicurrency_total_tva = 0;
1136 }
1137 if (empty($this->multicurrency_total_ttc)) {
1138 $this->multicurrency_total_ttc = 0;
1139 }
1140
1141 if ($price_base_type == 'HT') {
1142 $pu = $pu_ht;
1143 } else {
1144 $pu = $pu_ttc;
1145 }
1146
1147 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1148 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1149 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1150
1151 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1152
1153 // Clean vat code
1154 $vat_src_code = '';
1155 $reg = array();
1156 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1157 $vat_src_code = $reg[1];
1158 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1159 }
1160
1161 $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);
1162
1163 $total_ht = $tabprice[0];
1164 $total_tva = $tabprice[1];
1165 $total_ttc = $tabprice[2];
1166 $total_localtax1 = $tabprice[9];
1167 $total_localtax2 = $tabprice[10];
1168 $pu_ht = $tabprice[3];
1169 $pu_tva = $tabprice[4];
1170 $pu_ttc = $tabprice[5];
1171
1172 // MultiCurrency
1173 $multicurrency_total_ht = $tabprice[16];
1174 $multicurrency_total_tva = $tabprice[17];
1175 $multicurrency_total_ttc = $tabprice[18];
1176 $pu_ht_devise = $tabprice[19];
1177
1178 $product_type = $type;
1179 if ($fk_product) {
1180 $product = new Product($this->db);
1181 $result = $product->fetch($fk_product);
1182 $product_type = $product->type;
1183 }
1184
1185 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1186 $fk_parent_line = 0;
1187 }
1188
1189 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
1190 $sql .= "fk_facture = ".((int) $facid);
1191 $sql .= ", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1192 $sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1193 $sql .= ", description='".$this->db->escape($desc)."'";
1194 $sql .= ", price=".price2num($pu_ht);
1195 $sql .= ", qty=".price2num($qty);
1196 $sql .= ", tva_tx=".price2num($txtva);
1197 $sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
1198 $sql .= ", localtax1_tx=".((float) $txlocaltax1);
1199 $sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
1200 $sql .= ", localtax2_tx=".((float) $txlocaltax2);
1201 $sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
1202 $sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1203 $sql .= ", product_type=".((int) $product_type);
1204 $sql .= ", remise_percent='".price2num($remise_percent)."'";
1205 $sql .= ", subprice='".price2num($pu_ht)."'";
1206 $sql .= ", total_ht='".price2num($total_ht)."'";
1207 $sql .= ", total_tva='".price2num($total_tva)."'";
1208 $sql .= ", total_localtax1='".price2num($total_localtax1)."'";
1209 $sql .= ", total_localtax2='".price2num($total_localtax2)."'";
1210 $sql .= ", total_ttc='".price2num($total_ttc)."'";
1211 $sql .= ", date_start_fill=".((int) $date_start_fill);
1212 $sql .= ", date_end_fill=".((int) $date_end_fill);
1213 $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1214 $sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
1215 $sql .= ", info_bits=".((int) $info_bits);
1216 $sql .= ", rang=".((int) $rang);
1217 $sql .= ", special_code=".((int) $special_code);
1218 $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
1219 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1220 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1221 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1222 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1223 $sql .= " WHERE rowid = ".((int) $rowid);
1224
1225 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1226 if ($this->db->query($sql)) {
1227 $this->id = $facid;
1228 $this->update_price(1);
1229 return 1;
1230 } else {
1231 $this->error = $this->db->lasterror();
1232 return -1;
1233 }
1234 }
1235
1236
1242 public function getNextDate()
1243 {
1244 if (empty($this->date_when)) {
1245 return false;
1246 }
1247 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1248 }
1249
1255 public function isMaxNbGenReached()
1256 {
1257 $ret = false;
1258 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1259 $ret = true;
1260 }
1261 return $ret;
1262 }
1263
1270 public function strikeIfMaxNbGenReached($ret)
1271 {
1272 // Special case to strike the date
1273 return ($this->isMaxNbGenReached() ? '<strike>' : '').$ret.($this->isMaxNbGenReached() ? '</strike>' : '');
1274 }
1275
1287 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
1288 {
1289 global $conf, $langs, $db, $user, $hookmanager;
1290
1291 $error = 0;
1292 $nb_create = 0;
1293
1294 // Load translation files required by the page
1295 $langs->loadLangs(array("main", "bills"));
1296
1297 $now = dol_now();
1298 $tmparray = dol_getdate($now);
1299 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1300
1301 $this->output = null;
1302
1303 dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
1304
1305 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1306 $sql .= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1307 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1308 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1309 $sql .= ' AND suspended = 0';
1310 $sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1311 if ($restrictioninvoiceid > 0) {
1312 $sql .= ' AND rowid = '.((int) $restrictioninvoiceid);
1313 }
1314 $sql .= $this->db->order('entity', 'ASC');
1315 //print $sql;exit;
1316 $parameters = array(
1317 'restrictioninvoiceid' => $restrictioninvoiceid,
1318 'forcevalidation' => $forcevalidation,
1319 );
1320 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1321
1322 $resql = $this->db->query($sql);
1323 if ($resql) {
1324 $i = 0;
1325 $num = $this->db->num_rows($resql);
1326
1327 if ($num) {
1328 $this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1329 } else {
1330 $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1331 }
1332
1333 $saventity = $conf->entity;
1334
1335 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1336 $line = $this->db->fetch_object($resql);
1337
1338 $this->db->begin();
1339
1340 $invoiceidgenerated = 0;
1341
1342 $facture = null;
1343 $facturerec = new FactureRec($this->db);
1344 $facturerec->fetch($line->rowid);
1345
1346 if ($facturerec->id > 0) {
1347 // Set entity context
1348 $conf->entity = $facturerec->entity;
1349
1350 dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1351
1352 $facture = new Facture($this->db);
1353 $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1354 $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1355
1356 $facture->type = self::TYPE_STANDARD;
1357 $facture->subtype = $facturerec->subtype;
1358 $facture->statut = self::STATUS_DRAFT; // deprecated
1359 $facture->status = self::STATUS_DRAFT;
1360 $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.
1361 $facture->socid = $facturerec->socid;
1362 if (!empty($facturerec->fk_multicurrency)) {
1363 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1364 $facture->multicurrency_code = $facturerec->multicurrency_code;
1365 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1366 }
1367
1368 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1369 foreach ($facturerec->array_options as $key => $value) {
1370 if (isset($facture->array_options[$key])) {
1371 $facture->array_options[$key] = $value;
1372 }
1373 }
1374 }
1375
1376 $invoiceidgenerated = $facture->create($user);
1377 if ($invoiceidgenerated <= 0) {
1378 $this->errors = $facture->errors;
1379 $this->error = $facture->error;
1380 $error++;
1381 }
1382
1383
1384 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1385 $result = $facture->validate($user);
1386 if ($result <= 0) {
1387 $this->errors = $facture->errors;
1388 $this->error = $facture->error;
1389 $error++;
1390 }
1391 }
1392 if (!$error && $facturerec->generate_pdf) {
1393 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1394 $facture->fetch($facture->id);
1395 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1396 if ($result <= 0) {
1397 $this->errors = $facture->errors;
1398 $this->error = $facture->error;
1399 $error++;
1400 }
1401 }
1402 if (!$error && !$notrigger) {
1403 // Call trigger
1404 $result = $facturerec->call_trigger('BILLREC_CREATEBILL', $user);
1405 if ($result < 0) {
1406 $this->errors = $facturerec->errors;
1407 $this->error = $facturerec->error;
1408 $error++;
1409 }
1410 // End call triggers
1411 }
1412 } else {
1413 $error++;
1414 $this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1415 $this->errors[] = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1416 dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1417 }
1418
1419 if (!$error && $invoiceidgenerated >= 0) {
1420 $this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1421 dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1422 $nb_create++;
1423 $this->output .= $langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1424 } else {
1425 $this->output .= $langs->trans("InvoiceGeneratedFromTemplateError", $facture->ref, $facturerec->ref, $this->error)."\n";
1426 $this->db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1427 }
1428
1429 $parameters = array(
1430 'cpt' => $i,
1431 'total' => $num,
1432 'errorCount' => $error,
1433 'invoiceidgenerated' => $invoiceidgenerated,
1434 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1435 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1436 );
1437 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
1438
1439 $i++;
1440 }
1441
1442 $conf->entity = $saventity; // Restore entity context
1443 } else {
1444 dol_print_error($this->db);
1445 }
1446
1447 $this->output = trim($this->output);
1448
1449 return $error ? $error : 0;
1450 }
1451
1464 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
1465 {
1466 global $langs, $hookmanager;
1467
1468 $result = '';
1469
1470 $label = '<u>'.$langs->trans("RepeatableInvoice").'</u>';
1471 if (!empty($this->ref)) {
1472 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1473 }
1474 if ($this->frequency > 0) {
1475 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1476 }
1477 if (!empty($this->date_last_gen)) {
1478 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1479 }
1480 if ($this->frequency > 0) {
1481 if (!empty($this->date_when)) {
1482 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1483 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1484 if (!empty($this->suspended)) {
1485 $label .= ' ('.$langs->trans("Disabled").')';
1486 }
1487 }
1488 }
1489
1490 $url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
1491
1492 if ($short) {
1493 return $url;
1494 }
1495
1496 if ($option != 'nolink') {
1497 // Add param to save lastsearch_values or not
1498 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1499 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1500 $add_save_lastsearch_values = 1;
1501 }
1502 if ($add_save_lastsearch_values) {
1503 $url .= '&save_lastsearch_values=1';
1504 }
1505 }
1506
1507 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1508 $linkend = '</a>';
1509
1510 $result .= $linkstart;
1511 if ($withpicto) {
1512 $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);
1513 }
1514 if ($withpicto != 2) {
1515 $result .= $this->ref;
1516 }
1517 $result .= $linkend;
1518 global $action;
1519 $hookmanager->initHooks(array($this->element . 'dao'));
1520 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1521 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1522 if ($reshook > 0) {
1523 $result = $hookmanager->resPrint;
1524 } else {
1525 $result .= $hookmanager->resPrint;
1526 }
1527 return $result;
1528 }
1529
1537 public function getLibStatut($mode = 0, $alreadypaid = -1)
1538 {
1539 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1540 }
1541
1542 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1553 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1554 {
1555 // phpcs:enable
1556 global $langs;
1557 $langs->load('bills');
1558
1559 $labelStatus = $langs->transnoentitiesnoconv('Active');
1560 $statusType = 'status0';
1561
1562 //print "$recur,$status,$mode,$alreadypaid,$type";
1563 if ($mode == 0) {
1564 if ($recur) {
1565 if ($status == self::STATUS_SUSPENDED) {
1566 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1567 } else {
1568 $labelStatus = $langs->transnoentitiesnoconv('Active');
1569 }
1570 } else {
1571 if ($status == self::STATUS_SUSPENDED) {
1572 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1573 } else {
1574 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1575 }
1576 }
1577 } elseif ($mode == 1) {
1578 $prefix = 'Short';
1579 if ($recur) {
1580 if ($status == self::STATUS_SUSPENDED) {
1581 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1582 } else {
1583 $labelStatus = $langs->transnoentitiesnoconv('Active');
1584 }
1585 } else {
1586 if ($status == self::STATUS_SUSPENDED) {
1587 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1588 } else {
1589 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1590 }
1591 }
1592 } elseif ($mode == 2) {
1593 if ($recur) {
1594 if ($status == self::STATUS_SUSPENDED) {
1595 $statusType = 'status6';
1596 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1597 } else {
1598 $statusType = 'status4';
1599 $labelStatus = $langs->transnoentitiesnoconv('Active');
1600 }
1601 } else {
1602 if ($status == self::STATUS_SUSPENDED) {
1603 $statusType = 'status6';
1604 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1605 } else {
1606 $statusType = 'status0';
1607 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1608 }
1609 }
1610 } elseif ($mode == 3) {
1611 if ($recur) {
1612 $prefix = 'Short';
1613 if ($status == self::STATUS_SUSPENDED) {
1614 $statusType = 'status6';
1615 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1616 } else {
1617 $statusType = 'status4';
1618 $labelStatus = $langs->transnoentitiesnoconv('Active');
1619 }
1620 } else {
1621 if ($status == self::STATUS_SUSPENDED) {
1622 $statusType = 'status6';
1623 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1624 } else {
1625 $statusType = 'status0';
1626 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1627 }
1628 }
1629 } elseif ($mode == 4) {
1630 $prefix = '';
1631 if ($recur) {
1632 if ($status == self::STATUS_SUSPENDED) {
1633 $statusType = 'status6';
1634 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1635 } else {
1636 $statusType = 'status4';
1637 $labelStatus = $langs->transnoentitiesnoconv('Active');
1638 }
1639 } else {
1640 if ($status == self::STATUS_SUSPENDED) {
1641 $statusType = 'status6';
1642 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1643 } else {
1644 $statusType = 'status0';
1645 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1646 }
1647 }
1648 } elseif ($mode == 5 || $mode == 6) {
1649 $prefix = '';
1650 if ($mode == 5) {
1651 $prefix = 'Short';
1652 }
1653 if ($recur) {
1654 if ($status == self::STATUS_SUSPENDED) {
1655 $statusType = 'status6';
1656 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1657 } else {
1658 $statusType = 'status4';
1659 $labelStatus = $langs->transnoentitiesnoconv('Active');
1660 }
1661 } else {
1662 if ($status == self::STATUS_SUSPENDED) {
1663 $statusType = 'status6';
1664 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1665 } else {
1666 $statusType = 'status0';
1667 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1668 }
1669 }
1670 }
1671
1672 $labelStatusShort = $labelStatus;
1673
1674 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1675 }
1676
1684 public function getNextNumRef($soc, $mode = 'next')
1685 {
1686 // Not used for recurring invoices
1687 return '';
1688 }
1689
1696 public function info($id)
1697 {
1698 $sql = 'SELECT c.rowid, datec, tms as datem,';
1699 $sql .= ' fk_user_author, fk_user_modif';
1700 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as c';
1701 $sql .= ' WHERE c.rowid = '.((int) $id);
1702
1703 $result = $this->db->query($sql);
1704 if ($result) {
1705 if ($this->db->num_rows($result)) {
1706 $obj = $this->db->fetch_object($result);
1707
1708 $this->id = $obj->rowid;
1709
1710 $this->user_creation_id = $obj->fk_user_author;
1711 $this->user_modification_id = $obj->fk_user_modif;
1712 $this->date_creation = $this->db->jdate($obj->datec);
1713 $this->date_modification = $this->db->jdate($obj->datem);
1714 }
1715 $this->db->free($result);
1716 } else {
1717 dol_print_error($this->db);
1718 }
1719 }
1720
1729 public function initAsSpecimen($option = '')
1730 {
1731 global $langs;
1732
1733 $now = dol_now();
1734 $arraynow = dol_getdate($now);
1735 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1736
1737 // Load array of products prodids
1738 $num_prods = 0;
1739 $prodids = array();
1740
1741 $sql = "SELECT rowid";
1742 $sql .= " FROM ".MAIN_DB_PREFIX."product";
1743 $sql .= " WHERE entity IN (".getEntity('product').")";
1744 $sql .= $this->db->plimit(100);
1745
1746 $resql = $this->db->query($sql);
1747 if ($resql) {
1748 $num_prods = $this->db->num_rows($resql);
1749 $i = 0;
1750 while ($i < $num_prods) {
1751 $i++;
1752 $row = $this->db->fetch_row($resql);
1753 $prodids[$i] = $row[0];
1754 }
1755 }
1756
1757 // Initialize parameters
1758 $this->id = 0;
1759 $this->ref = 'SPECIMEN';
1760 $this->title = 'SPECIMEN';
1761 $this->specimen = 1;
1762 $this->socid = 1;
1763 $this->date = $nownotime;
1764 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1765 $this->cond_reglement_id = 1;
1766 $this->cond_reglement_code = 'RECEP';
1767 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1768 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1769 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1770 $this->note_public = 'This is a comment (public)';
1771 $this->note_private = 'This is a comment (private)';
1772 $this->note = 'This is a comment (private)';
1773 $this->fk_incoterms = 0;
1774 $this->location_incoterms = '';
1775
1776 if (empty($option) || $option != 'nolines') {
1777 // Lines
1778 $nbp = 5;
1779 $xnbp = 0;
1780 while ($xnbp < $nbp) {
1781 $line = new FactureLigne($this->db);
1782 $line->desc = $langs->trans("Description")." ".$xnbp;
1783 $line->qty = 1;
1784 $line->subprice = 100;
1785 $line->tva_tx = 19.6;
1786 $line->localtax1_tx = 0;
1787 $line->localtax2_tx = 0;
1788 $line->remise_percent = 0;
1789 if ($xnbp == 1) { // Qty is negative (product line)
1790 $prodid = mt_rand(1, $num_prods);
1791 $line->fk_product = $prodids[$prodid];
1792 $line->qty = -1;
1793 $line->total_ht = -100;
1794 $line->total_ttc = -119.6;
1795 $line->total_tva = -19.6;
1796 } elseif ($xnbp == 2) { // UP is negative (free line)
1797 $line->subprice = -100;
1798 $line->total_ht = -100;
1799 $line->total_ttc = -119.6;
1800 $line->total_tva = -19.6;
1801 $line->remise_percent = 0;
1802 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1803 $prodid = mt_rand(1, $num_prods);
1804 $line->fk_product = $prodids[$prodid];
1805 $line->total_ht = 50;
1806 $line->total_ttc = 59.8;
1807 $line->total_tva = 9.8;
1808 $line->remise_percent = 50;
1809 } else { // (product line)
1810 $prodid = mt_rand(1, $num_prods);
1811 $line->fk_product = $prodids[$prodid];
1812 $line->total_ht = 100;
1813 $line->total_ttc = 119.6;
1814 $line->total_tva = 19.6;
1815 $line->remise_percent = 00;
1816 }
1817
1818 $this->lines[$xnbp] = $line;
1819 $xnbp++;
1820
1821 $this->total_ht += $line->total_ht;
1822 $this->total_tva += $line->total_tva;
1823 $this->total_ttc += $line->total_ttc;
1824 }
1825 $this->revenuestamp = 0;
1826
1827 // Add a line "offered"
1828 $line = new FactureLigne($this->db);
1829 $line->desc = $langs->trans("Description")." (offered line)";
1830 $line->qty = 1;
1831 $line->subprice = 100;
1832 $line->tva_tx = 19.6;
1833 $line->localtax1_tx = 0;
1834 $line->localtax2_tx = 0;
1835 $line->remise_percent = 100;
1836 $line->total_ht = 0;
1837 $line->total_ttc = 0; // 90 * 1.196
1838 $line->total_tva = 0;
1839 $prodid = mt_rand(1, $num_prods);
1840 $line->fk_product = $prodids[$prodid];
1841
1842 $this->lines[$xnbp] = $line;
1843 $xnbp++;
1844 }
1845
1846 $this->usenewprice = 0;
1847 }
1848
1857 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1858 {
1859 $tables = array(
1860 'facture_rec'
1861 );
1862
1863 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1864 }
1865
1874 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
1875 {
1876 $tables = array(
1877 'facturedet_rec'
1878 );
1879
1880 return CommonObject::commonReplaceProduct($dbs, $origin_id, $dest_id, $tables);
1881 }
1882
1891 public function setFrequencyAndUnit($frequency, $unit, $notrigger = 0)
1892 {
1893 global $user;
1894
1895 if (!$this->table_element) {
1896 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined", LOG_ERR);
1897 return -1;
1898 }
1899
1900 if (!empty($frequency) && empty($unit)) {
1901 dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined", LOG_ERR);
1902 return -2;
1903 }
1904
1905 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1906 $sql .= ' SET frequency = '.($frequency ? $this->db->escape($frequency) : 'null');
1907 if (!empty($unit)) {
1908 $sql .= ', unit_frequency = \''.$this->db->escape($unit).'\'';
1909 }
1910 $sql .= " WHERE rowid = ".((int) $this->id);
1911
1912 dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
1913 if ($this->db->query($sql)) {
1914 $this->frequency = $frequency;
1915 if (!empty($unit)) {
1916 $this->unit_frequency = $unit;
1917 }
1918
1919 if (!$notrigger) {
1920 // Call trigger
1921 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1922 if ($result < 0) {
1923 return $result;
1924 }
1925 // End call triggers
1926 }
1927
1928 return 1;
1929 } else {
1930 dol_print_error($this->db);
1931 return -1;
1932 }
1933 }
1934
1943 public function setNextDate($date, $increment_nb_gen_done = 0, $notrigger = 0)
1944 {
1945 global $user;
1946
1947 if (!$this->table_element) {
1948 dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined", LOG_ERR);
1949 return -1;
1950 }
1951 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
1952 $sql .= " SET date_when = ".($date ? "'".$this->db->idate($date)."'" : "null");
1953 if ($increment_nb_gen_done > 0) {
1954 $sql .= ', nb_gen_done = nb_gen_done + 1';
1955 }
1956 $sql .= " WHERE rowid = ".((int) $this->id);
1957
1958 dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
1959 if ($this->db->query($sql)) {
1960 $this->date_when = $date;
1961 if ($increment_nb_gen_done > 0) {
1962 $this->nb_gen_done++;
1963 }
1964
1965 if (!$notrigger) {
1966 // Call trigger
1967 $result = $this->call_trigger('BILLREC_MODIFY', $user);
1968 if ($result < 0) {
1969 return $result;
1970 }
1971 // End call triggers
1972 }
1973 return 1;
1974 } else {
1975 dol_print_error($this->db);
1976 return -1;
1977 }
1978 }
1979
1987 public function setMaxPeriod($nb, $notrigger = 0)
1988 {
1989 global $user;
1990
1991 if (!$this->table_element) {
1992 dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined", LOG_ERR);
1993 return -1;
1994 }
1995
1996 if (empty($nb)) {
1997 $nb = 0;
1998 }
1999
2000 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2001 $sql .= ' SET nb_gen_max = '.((int) $nb);
2002 $sql .= " WHERE rowid = ".((int) $this->id);
2003
2004 dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
2005 if ($this->db->query($sql)) {
2006 $this->nb_gen_max = $nb;
2007
2008 if (!$notrigger) {
2009 // Call trigger
2010 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2011 if ($result < 0) {
2012 return $result;
2013 }
2014 // End call triggers
2015 }
2016
2017 return 1;
2018 } else {
2019 dol_print_error($this->db);
2020 return -1;
2021 }
2022 }
2023
2031 public function setAutoValidate($validate, $notrigger = 0)
2032 {
2033 global $user;
2034
2035 if (!$this->table_element) {
2036 dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined", LOG_ERR);
2037 return -1;
2038 }
2039
2040 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2041 $sql .= ' SET auto_validate = '.((int) $validate);
2042 $sql .= " WHERE rowid = ".((int) $this->id);
2043
2044 dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
2045 if ($this->db->query($sql)) {
2046 $this->auto_validate = $validate;
2047
2048 if (!$notrigger) {
2049 // Call trigger
2050 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2051 if ($result < 0) {
2052 return $result;
2053 }
2054 // End call triggers
2055 }
2056
2057 return 1;
2058 } else {
2059 dol_print_error($this->db);
2060 return -1;
2061 }
2062 }
2063
2071 public function setGeneratePdf($validate, $notrigger = 0)
2072 {
2073 global $user;
2074
2075 if (!$this->table_element) {
2076 dol_syslog(get_class($this)."::setGeneratePdf was called on objet with property table_element not defined", LOG_ERR);
2077 return -1;
2078 }
2079
2080 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2081 $sql .= ' SET generate_pdf = '.((int) $validate);
2082 $sql .= " WHERE rowid = ".((int) $this->id);
2083
2084 dol_syslog(get_class($this)."::setGeneratePdf", LOG_DEBUG);
2085 if ($this->db->query($sql)) {
2086 $this->generate_pdf = $validate;
2087
2088 if (!$notrigger) {
2089 // Call trigger
2090 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2091 if ($result < 0) {
2092 return $result;
2093 }
2094 // End call triggers
2095 }
2096
2097 return 1;
2098 } else {
2099 dol_print_error($this->db);
2100 return -1;
2101 }
2102 }
2103
2111 public function setModelPdf($model, $notrigger = 0)
2112 {
2113 global $user;
2114 if (!$this->table_element) {
2115 dol_syslog(get_class($this)."::setModelPdf was called on objet with property table_element not defined", LOG_ERR);
2116 return -1;
2117 }
2118
2119 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2120 $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
2121 $sql .= " WHERE rowid = ".((int) $this->id);
2122
2123 dol_syslog(get_class($this)."::setModelPdf", LOG_DEBUG);
2124 if ($this->db->query($sql)) {
2125 $this->model_pdf = $model;
2126
2127 if (!$notrigger) {
2128 // Call trigger
2129 $result = $this->call_trigger('BILLREC_MODIFY', $user);
2130 if ($result < 0) {
2131 return $result;
2132 }
2133 // End call triggers
2134 }
2135
2136 return 1;
2137 } else {
2138 dol_print_error($this->db);
2139 return -1;
2140 }
2141 }
2142}
2143
2144
2145
2151{
2155 public $element = 'facturedetrec';
2156
2160 public $table_element = 'facturedet_rec';
2161
2167
2168 public $fk_product_fournisseur_price;
2169 public $fk_fournprice; // For backward compatibility
2170
2171 public $rang;
2172 //public $situation_percent; // Not supported on recurring invoice line
2173
2174 public $desc;
2175 public $description;
2176
2177 public $fk_product_type; // Use instead product_type
2178
2179 public $fk_contract_line;
2180
2181
2189 public function delete(User $user, $notrigger = 0)
2190 {
2191 $error = 0;
2192
2193 $this->db->begin();
2194
2195 if (!$error) {
2196 if (!$notrigger) {
2197 // Call triggers
2198 $result = $this->call_trigger('LINEBILLREC_DELETE', $user);
2199 if ($result < 0) {
2200 $error++;
2201 } // Do also here what you must do to rollback action if trigger fail
2202 // End call triggers
2203 }
2204 }
2205
2206 if (!$error) {
2207 $result = $this->deleteExtraFields();
2208 if ($result < 0) {
2209 $error++;
2210 }
2211 }
2212
2213 if (!$error) {
2214 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id);
2215
2216 $res = $this->db->query($sql);
2217 if (!$res) {
2218 $error++;
2219 $this->errors[] = $this->db->lasterror();
2220 }
2221 }
2222
2223 // Commit or rollback
2224 if ($error) {
2225 $this->db->rollback();
2226 return -1;
2227 } else {
2228 $this->db->commit();
2229 return 1;
2230 }
2231 }
2232
2233
2240 public function fetch($rowid)
2241 {
2242 $sql = 'SELECT l.rowid, l.fk_facture, l.fk_parent_line, 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,';
2243 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2244 $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2245 $sql .= ' l.rang, l.special_code,';
2246 $sql .= ' l.fk_unit, l.fk_contract_line,';
2247 $sql .= ' l.import_key, l.fk_multicurrency,';
2248 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2249 $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
2250 $sql .= ' l.fk_user_author, l.fk_user_modif,';
2251 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2252 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
2253 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2254 $sql .= ' WHERE l.rowid = '.((int) $rowid);
2255 $sql .= ' ORDER BY l.rang';
2256
2257 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2258 $result = $this->db->query($sql);
2259 if ($result) {
2260 $objp = $this->db->fetch_object($result);
2261
2262 $this->id = $objp->rowid;
2263 $this->fk_facture = $objp->fk_facture;
2264 $this->fk_parent_line = $objp->fk_parent_line;
2265 $this->label = $objp->custom_label; // Label line
2266 $this->desc = $objp->description; // Description line
2267 $this->description = $objp->description; // Description line
2268 $this->product_type = $objp->product_type; // Type of line
2269 $this->ref = $objp->product_ref; // Ref product
2270 $this->product_ref = $objp->product_ref; // Ref product
2271 $this->libelle = $objp->product_label; // deprecated
2272 $this->product_label = $objp->product_label; // Label product
2273 $this->product_desc = $objp->product_desc; // Description product
2274 $this->fk_product_type = $objp->fk_product_type; // Type of product
2275 $this->qty = $objp->qty;
2276 $this->price = $objp->price;
2277 $this->subprice = $objp->subprice;
2278 $this->vat_src_code = $objp->vat_src_code;
2279 $this->tva_tx = $objp->tva_tx;
2280 $this->localtax1_tx = $objp->localtax1_tx;
2281 $this->localtax2_tx = $objp->localtax2_tx;
2282 $this->localtax1_type = $objp->localtax1_type;
2283 $this->localtax2_type = $objp->localtax2_type;
2284 $this->remise_percent = $objp->remise_percent;
2285 //$this->fk_remise_except = $objp->fk_remise_except;
2286 $this->fk_product = $objp->fk_product;
2287 $this->date_start_fill = $objp->date_start_fill;
2288 $this->date_end_fill = $objp->date_end_fill;
2289 $this->info_bits = $objp->info_bits;
2290 $this->total_ht = $objp->total_ht;
2291 $this->total_tva = $objp->total_tva;
2292 $this->total_ttc = $objp->total_ttc;
2293
2294 $this->rang = $objp->rang;
2295 $this->special_code = $objp->special_code;
2296 $this->fk_unit = $objp->fk_unit;
2297 $this->fk_contract_line = $objp->fk_contract_line;
2298 $this->import_key = $objp->import_key;
2299 $this->fk_multicurrency = $objp->fk_multicurrency;
2300 $this->multicurrency_code = $objp->multicurrency_code;
2301 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2302 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2303 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2304 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2305
2306 $this->buy_price_ht = $objp->buy_price_ht;
2307
2308 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2309 $this->fk_user_author = $objp->fk_user_author;
2310 $this->fk_user_modif = $objp->fk_user_modif;
2311
2312 $this->db->free($result);
2313 return 1;
2314 } else {
2315 $this->error = $this->db->lasterror();
2316 return -3;
2317 }
2318 }
2319
2320
2328 public function update(User $user, $notrigger = 0)
2329 {
2330 global $conf;
2331
2332 $error = 0;
2333
2334 // Clean parameters
2335 if (empty($this->fk_parent_line)) {
2336 $this->fk_parent_line = 0;
2337 }
2338
2339 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2340
2341 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
2342 $sql .= " fk_facture = ".((int) $this->fk_facture);
2343 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
2344 $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
2345 $sql .= ", description='".$this->db->escape($this->desc)."'";
2346 $sql .= ", price=".price2num($this->price);
2347 $sql .= ", qty=".price2num($this->qty);
2348 $sql .= ", tva_tx=".price2num($this->tva_tx);
2349 $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
2350 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
2351 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
2352 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
2353 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
2354 $sql .= ", fk_product=".($this->fk_product > 0 ? $this->fk_product : "null");
2355 $sql .= ", product_type=".((int) $this->product_type);
2356 $sql .= ", remise_percent=".price2num($this->remise_percent);
2357 $sql .= ", subprice=".price2num($this->subprice);
2358 $sql .= ", info_bits=".price2num($this->info_bits);
2359 $sql .= ", date_start_fill=".(int) $this->date_start_fill;
2360 $sql .= ", date_end_fill=".(int) $this->date_end_fill;
2361 if (empty($this->skip_update_total)) {
2362 $sql .= ", total_ht=".price2num($this->total_ht);
2363 $sql .= ", total_tva=".price2num($this->total_tva);
2364 $sql .= ", total_localtax1=".price2num($this->total_localtax1);
2365 $sql .= ", total_localtax2=".price2num($this->total_localtax2);
2366 $sql .= ", total_ttc=".price2num($this->total_ttc);
2367 }
2368 $sql .= ", rang=".((int) $this->rang);
2369 $sql .= ", special_code=".((int) $this->special_code);
2370 $sql .= ", fk_unit=".($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : "null");
2371 $sql .= ", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line : "null");
2372 $sql .= " WHERE rowid = ".((int) $this->id);
2373
2374 $this->db->begin();
2375
2376 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
2377
2378 $resql = $this->db->query($sql);
2379 if ($resql) {
2380 if (!$error) {
2381 $result = $this->insertExtraFields();
2382 if ($result < 0) {
2383 $error++;
2384 }
2385 }
2386
2387 if (!$error && !$notrigger) {
2388 // Call trigger
2389 $result = $this->call_trigger('LINEBILLREC_MODIFY', $user);
2390 if ($result < 0) {
2391 $error++;
2392 }
2393 // End call triggers
2394 }
2395
2396 if ($error) {
2397 $this->db->rollback();
2398 return -2;
2399 } else {
2400 $this->db->commit();
2401 return 1;
2402 }
2403 } else {
2404 $this->error = $this->db->lasterror();
2405 $this->db->rollback();
2406 return -2;
2407 }
2408 }
2409}
$object ref
Definition info.php:79
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=0, $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.
$fk_parent_line
Id parent line.
fetch($rowid)
Get line of template invoice.
$fk_facture
From llx_facturedet_rec Id facture.
update(User $user, $notrigger=0)
Update a line to invoice_rec.
Class to manage invoice templates.
setFrequencyAndUnit($frequency, $unit, $notrigger=0)
Update frequency and unit.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
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=0, $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, $fk_parent_line=0)
Add a line to invoice.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
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=0, $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, $fk_parent_line=0)
Update a line to invoice.
fetch_lines()
Get lines of template invoices into this->lines.
info($id)
Load miscellaneous information for tab "Info".
getLinesArray()
Create an array of invoice lines.
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=0, $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.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
__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.
create($user, $facid, $notrigger=0, $onlylines=array())
Create a predefined invoice.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
fetch($rowid, $ref='', $ref_ext='', $noextrafields=0, $nolines=0)
Load object and lines.
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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 a 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:121