dolibarr 20.0.5
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-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2023 Nick Fragoulis
11 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33require_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
36require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38
39
44{
45 const TRIGGER_PREFIX = 'BILLREC';
49 public $element = 'facturerec';
50
54 public $table_element = 'facture_rec';
55
59 public $table_element_line = 'facturedet_rec';
60
64 public $fk_element = 'fk_facture';
65
69 public $picto = 'bill';
70
74 public $entity;
75
79 protected $table_ref_field = 'titre';
80
84 public $title;
85
90 public $titre;
91
95 public $multicurrency_subprice;
96 public $socid;
97 public $number;
98 public $date;
99 //public $remise;
100 //public $remise_absolue;
101 //public $remise_percent;
102
107 public $total;
108
113 public $tva;
114
115 public $date_last_gen;
116 public $date_when;
117 public $nb_gen_done;
118 public $nb_gen_max;
119
120 public $user_author;
121
125 public $frequency;
126
130 public $unit_frequency;
131
132 public $rang;
133
137 public $special_code;
138
139 public $usenewprice = 0;
140
144 public $date_lim_reglement;
145 public $cond_reglement_code; // Code in llx_c_paiement
146 public $mode_reglement_code; // Code in llx_c_paiement
147
148 public $fk_multicurrency;
149 public $multicurrency_code;
150 public $multicurrency_tx;
151 public $multicurrency_total_ht;
152 public $multicurrency_total_tva;
153 public $multicurrency_total_ttc;
154
155 public $suspended; // status
156
157 public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
158 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
159
160
185 // BEGIN MODULEBUILDER PROPERTIES
189 public $fields = array(
190 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
191 'titre' => array('type' => 'varchar(100)', 'label' => 'Titre', 'enabled' => 1, 'showoncombobox' => 1, 'visible' => -1, 'position' => 15),
192 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 20, 'index' => 1),
193 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'notnull' => 1, 'position' => 25),
194 'subtype' => array('type' => 'smallint(6)', 'label' => 'InvoiceSubtype', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 30),
195 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 35),
196 'total_tva' => array('type' => 'double(24,8)', 'label' => 'Tva', 'enabled' => 1, 'visible' => -1, 'position' => 55, 'isameasure' => 1),
197 'localtax1' => array('type' => 'double(24,8)', 'label' => 'Localtax1', 'enabled' => 1, 'visible' => -1, 'position' => 60, 'isameasure' => 1),
198 'localtax2' => array('type' => 'double(24,8)', 'label' => 'Localtax2', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'isameasure' => 1),
199 'total_ht' => array('type' => 'double(24,8)', 'label' => 'Total', 'enabled' => 1, 'visible' => -1, 'position' => 70, 'isameasure' => 1),
200 'total_ttc' => array('type' => 'double(24,8)', 'label' => 'Total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 75, 'isameasure' => 1),
201 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 80),
202 '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),
203 'fk_cond_reglement' => array('type' => 'integer', 'label' => 'Fk cond reglement', 'enabled' => 1, 'visible' => -1, 'position' => 90),
204 'fk_mode_reglement' => array('type' => 'integer', 'label' => 'Fk mode reglement', 'enabled' => 1, 'visible' => -1, 'position' => 95),
205 'date_lim_reglement' => array('type' => 'date', 'label' => 'Date lim reglement', 'enabled' => 1, 'visible' => -1, 'position' => 100),
206 'note_private' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 105),
207 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 110),
208 'modelpdf' => array('type' => 'varchar(255)', 'label' => 'Modelpdf', 'enabled' => 1, 'visible' => -1, 'position' => 115),
209 'date_when' => array('type' => 'datetime', 'label' => 'Date when', 'enabled' => 1, 'visible' => -1, 'position' => 130),
210 'date_last_gen' => array('type' => 'datetime', 'label' => 'Date last gen', 'enabled' => 1, 'visible' => -1, 'position' => 135),
211 'nb_gen_done' => array('type' => 'integer', 'label' => 'Nb gen done', 'enabled' => 1, 'visible' => -1, 'position' => 140),
212 'nb_gen_max' => array('type' => 'integer', 'label' => 'Nb gen max', 'enabled' => 1, 'visible' => -1, 'position' => 145),
213 'frequency' => array('type' => 'integer', 'label' => 'Frequency', 'enabled' => 1, 'visible' => -1, 'position' => 150),
214 'unit_frequency' => array('type' => 'varchar(2)', 'label' => 'UnitFrequency', 'enabled' => 1, 'visible' => -1, 'position' => 152),
215 'usenewprice' => array('type' => 'integer', 'label' => 'UseNewPrice', 'enabled' => 1, 'visible' => 0, 'position' => 155),
216 'revenuestamp' => array('type' => 'double(24,8)', 'label' => 'RevenueStamp', 'enabled' => 1, 'visible' => -1, 'position' => 160, 'isameasure' => 1),
217 'auto_validate' => array('type' => 'integer', 'label' => 'Auto validate', 'enabled' => 1, 'visible' => -1, 'position' => 165),
218 'generate_pdf' => array('type' => 'integer', 'label' => 'Generate pdf', 'enabled' => 1, 'visible' => -1, 'position' => 170),
219 'fk_account' => array('type' => 'integer', 'label' => 'Fk account', 'enabled' => 'isModEnabled("bank")', 'visible' => -1, 'position' => 175),
220 'fk_multicurrency' => array('type' => 'integer', 'label' => 'Fk multicurrency', 'enabled' => 1, 'visible' => -1, 'position' => 180),
221 'multicurrency_code' => array('type' => 'varchar(255)', 'label' => 'Multicurrency code', 'enabled' => 1, 'visible' => -1, 'position' => 185),
222 'multicurrency_tx' => array('type' => 'double(24,8)', 'label' => 'Multicurrency tx', 'enabled' => 1, 'visible' => -1, 'position' => 190, 'isameasure' => 1),
223 'multicurrency_total_ht' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ht', 'enabled' => 1, 'visible' => -1, 'position' => 195, 'isameasure' => 1),
224 'multicurrency_total_tva' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total tva', 'enabled' => 1, 'visible' => -1, 'position' => 200, 'isameasure' => 1),
225 'multicurrency_total_ttc' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 205, 'isameasure' => 1),
226 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 210),
227 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 215),
228 'suspended' => array('type' => 'integer', 'label' => 'Suspended', 'enabled' => 1, 'visible' => -1, 'position' => 225),
229 );
230 // END MODULEBUILDER PROPERTIES
231
232 const STATUS_NOTSUSPENDED = 0;
233 const STATUS_SUSPENDED = 1;
234
235
236
242 public function __construct(DoliDB $db)
243 {
244 $this->db = $db;
245 }
246
256 public function create($user, $facid, $notrigger = 0, $onlylines = array())
257 {
258 global $conf;
259
260 $error = 0;
261 $now = dol_now();
262
263 // Clean parameters
264 $this->titre = trim(isset($this->titre) ? $this->titre : $this->title); // deprecated
265 $this->title = trim($this->title);
266 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
267 if (empty($this->suspended)) {
268 $this->suspended = 0;
269 }
270
271 // No frequency defined then no next date to execution
272 if (empty($this->frequency)) {
273 $this->frequency = 0;
274 $this->date_when = null;
275 }
276
277 $this->frequency = abs($this->frequency);
278 $this->nb_gen_done = 0;
279 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
280 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
281 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
282
283 $this->db->begin();
284
285 // Load invoice template
286 $facsrc = new Facture($this->db);
287 $result = $facsrc->fetch($facid);
288 if ($result > 0) {
289 $this->socid = $facsrc->socid;
290
291 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
292 $sql .= "titre";
293 $sql .= ", fk_soc";
294 $sql .= ", subtype";
295 $sql .= ", entity";
296 $sql .= ", datec";
297 $sql .= ", amount";
298 //$sql .= ", remise";
299 $sql .= ", note_private";
300 $sql .= ", note_public";
301 $sql .= ", modelpdf";
302 $sql .= ", fk_user_author";
303 $sql .= ", fk_projet";
304 $sql .= ", fk_account";
305 $sql .= ", fk_cond_reglement";
306 $sql .= ", fk_mode_reglement";
307 $sql .= ", usenewprice";
308 $sql .= ", frequency";
309 $sql .= ", unit_frequency";
310 $sql .= ", date_when";
311 $sql .= ", date_last_gen";
312 $sql .= ", nb_gen_done";
313 $sql .= ", nb_gen_max";
314 $sql .= ", auto_validate";
315 $sql .= ", generate_pdf";
316 $sql .= ", fk_multicurrency";
317 $sql .= ", multicurrency_code";
318 $sql .= ", multicurrency_tx";
319 $sql .= ", suspended";
320 $sql .= ") VALUES (";
321 $sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
322 $sql .= ", ".((int) $this->socid);
323 $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
324 $sql .= ", ".((int) $conf->entity);
325 $sql .= ", '".$this->db->idate($now)."'";
326 $sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
327 //$sql .= ", ".(!empty($facsrc->remise_absolue) ? ((float) $this->remise_absolue) : '0');
328 $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL");
329 $sql .= ", ".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL");
330 $sql .= ", ".(!empty($this->model_pdf) ? ("'".$this->db->escape($this->model_pdf)."'") : "NULL");
331 $sql .= ", ".((int) $user->id);
332 $sql .= ", ".(!empty($this->fk_project) ? ((int) $this->fk_project) : "null");
333 $sql .= ", ".(!empty($facsrc->fk_account) ? ((int) $facsrc->fk_account) : "null");
334 $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
335 $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
336 $sql .= ", ".((int) $this->usenewprice);
337 $sql .= ", ".((int) $this->frequency);
338 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
339 $sql .= ", ".(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
340 $sql .= ", ".(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
341 $sql .= ", ".((int) $this->nb_gen_done);
342 $sql .= ", ".((int) $this->nb_gen_max);
343 $sql .= ", ".((int) $this->auto_validate);
344 $sql .= ", ".((int) $this->generate_pdf);
345 $sql .= ", ".((int) $facsrc->fk_multicurrency);
346 $sql .= ", '".$this->db->escape($facsrc->multicurrency_code)."'";
347 $sql .= ", ".((float) $facsrc->multicurrency_tx);
348 $sql .= ", ".((int) $this->suspended);
349 $sql .= ")";
350
351 if ($this->db->query($sql)) {
352 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."facture_rec");
353
354 // Fields used into addline later
355 $this->fk_multicurrency = $facsrc->fk_multicurrency;
356 $this->multicurrency_code = $facsrc->multicurrency_code;
357 $this->multicurrency_tx = $facsrc->multicurrency_tx;
358
359 // Add lines
360 $fk_parent_line = 0;
361
362 $num = count($facsrc->lines);
363 for ($i = 0; $i < $num; $i++) {
364 if (!empty($onlylines) && !in_array($facsrc->lines[$i]->id, $onlylines)) {
365 continue; // Skip unselected lines
366 }
367
368 // Reset fk_parent_line for no child products and special product
369 if (($facsrc->lines[$i]->product_type != 9 && empty($facsrc->lines[$i]->fk_parent_line)) || $facsrc->lines[$i]->product_type == 9) {
370 $fk_parent_line = 0;
371 }
372
373 $tva_tx = $facsrc->lines[$i]->tva_tx;
374 if (!empty($facsrc->lines[$i]->vat_src_code) && !preg_match('/\‍(/', (string) $tva_tx)) {
375 $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')';
376 }
377
378 $default_start_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_START');
379 $default_end_fill = getDolGlobalInt('INVOICEREC_SET_AUTOFILL_DATE_END');
380
381 $result_insert = $this->addline(
382 $facsrc->lines[$i]->desc,
383 $facsrc->lines[$i]->subprice,
384 $facsrc->lines[$i]->qty,
385 $tva_tx,
386 $facsrc->lines[$i]->localtax1_tx,
387 $facsrc->lines[$i]->localtax2_tx,
388 $facsrc->lines[$i]->fk_product,
389 $facsrc->lines[$i]->remise_percent,
390 'HT',
391 $facsrc->lines[$i]->info_bits,
392 '',
393 0,
394 $facsrc->lines[$i]->product_type,
395 $facsrc->lines[$i]->rang,
396 $facsrc->lines[$i]->special_code,
397 $facsrc->lines[$i]->label,
398 $facsrc->lines[$i]->fk_unit,
399 $facsrc->lines[$i]->multicurrency_subprice,
400 $default_start_fill,
401 $default_end_fill,
402 null,
403 $facsrc->lines[$i]->pa_ht,
404 $fk_parent_line
405 );
406
407 // Defined the new fk_parent_line
408 if ($result_insert > 0 && $facsrc->lines[$i]->product_type == 9) {
409 $fk_parent_line = $result_insert;
410 }
411
412 if ($result_insert < 0) {
413 $error++;
414 } else {
415 $objectline = new FactureLigneRec($this->db);
416
417 $result2 = $objectline->fetch($result_insert);
418 if ($result2 > 0) {
419 // Extrafields
420 if (method_exists($facsrc->lines[$i], 'fetch_optionals')) {
421 $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id);
422 $objectline->array_options = $facsrc->lines[$i]->array_options;
423 }
424
425 $result = $objectline->insertExtraFields();
426 if ($result < 0) {
427 $error++;
428 }
429 } elseif ($result2 < 0) {
430 $this->errors[] = $objectline->error;
431 $error++;
432 }
433 }
434 }
435
436 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
437 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
438 }
439
440 // Add object linked
441 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
442 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
443 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, ...))
444 foreach ($tmp_origin_id as $origin_id) {
445 $ret = $this->add_object_linked($origin, $origin_id);
446 if (!$ret) {
447 $this->error = $this->db->lasterror();
448 $error++;
449 }
450 }
451 } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
452 $origin_id = $tmp_origin_id;
453 $ret = $this->add_object_linked($origin, $origin_id);
454 if (!$ret) {
455 $this->error = $this->db->lasterror();
456 $error++;
457 }
458 }
459 }
460 }
461
462 if (!$error) {
463 $result = $this->insertExtraFields();
464 if ($result < 0) {
465 $error++;
466 }
467 }
468
469 if (!$error && !$notrigger) {
470 // Call trigger
471 $result = $this->call_trigger('BILLREC_CREATE', $user);
472 if ($result < 0) {
473 $this->db->rollback();
474 return -2;
475 }
476 // End call triggers
477 }
478
479 if ($error) {
480 $this->db->rollback();
481 return -3;
482 } else {
483 $this->db->commit();
484 return $this->id;
485 }
486 } else {
487 $this->error = $this->db->lasterror();
488 $this->db->rollback();
489 return -2;
490 }
491 } else {
492 $this->db->rollback();
493 return -1;
494 }
495 }
496
497
505 public function update(User $user, $notrigger = 0)
506 {
507 $error = 0;
508
509 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET";
510 $sql .= " entity = ".((int) $this->entity).",";
511 $sql .= " titre = '".$this->db->escape($this->title)."',";
512 $sql .= " suspended = ".((int) $this->suspended).",";
513 $sql .= " fk_soc = ".((int) $this->socid).",";
514 $sql .= " total_tva = ".((float) $this->total_tva).",";
515 $sql .= " localtax1 = ".((float) $this->total_localtax1).",";
516 $sql .= " localtax2 = ".((float) $this->total_localtax2).",";
517 $sql .= " total_ht = ".((float) $this->total_ht).",";
518 $sql .= " total_ttc = ".((float) $this->total_ttc);
519 // TODO Add missing fields
520 $sql .= " WHERE rowid = ".((int) $this->id);
521
522 $this->db->begin();
523
524 dol_syslog(get_class($this)."::update", LOG_DEBUG);
525
526 $resql = $this->db->query($sql);
527 if ($resql) {
528 if (!$error) {
529 $result = $this->insertExtraFields();
530 if ($result < 0) {
531 $error++;
532 }
533 }
534
535 if (!$error && !$notrigger) {
536 // Call trigger
537 $result = $this->call_trigger('BILLREC_MODIFY', $user);
538 if ($result < 0) {
539 $this->db->rollback();
540 return -2;
541 }
542 // End call triggers
543 }
544 $this->db->commit();
545 return 1;
546 } else {
547 $this->error = $this->db->lasterror();
548 $this->db->rollback();
549 return -1;
550 }
551 }
552
563 public function fetch($rowid, $ref = '', $ref_ext = '', $noextrafields = 0, $nolines = 0)
564 {
565 dol_syslog('FactureRec::fetch', LOG_DEBUG);
566
567 $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';
568 $sql .= ', f.date_lim_reglement as dlr';
569 $sql .= ', f.note_private, f.note_public, f.fk_user_author';
570 $sql .= ', f.modelpdf as model_pdf';
571 $sql .= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project';
572 $sql .= ', f.fk_account';
573 $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';
574 $sql .= ', f.generate_pdf';
575 $sql .= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc";
576 $sql .= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
577 $sql .= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
578 //$sql.= ', el.fk_source';
579 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as f';
580 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
581 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
582 //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'";
583 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
584 if ($rowid) {
585 $sql .= ' AND f.rowid = '.((int) $rowid);
586 } elseif ($ref) {
587 $sql .= " AND f.titre = '".$this->db->escape($ref)."'";
588 } else {
589 $sql .= ' AND f.rowid = 0';
590 }
591 /* This field are not used for template invoice
592 if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
593 */
594
595 $result = $this->db->query($sql);
596 if ($result) {
597 if ($this->db->num_rows($result)) {
598 $obj = $this->db->fetch_object($result);
599
600 $this->id = $obj->rowid;
601 $this->entity = $obj->entity;
602 $this->titre = $obj->title; // deprecated
603 $this->title = $obj->title;
604 $this->ref = $obj->title;
605 $this->subtype = $obj->subtype;
606 $this->suspended = $obj->suspended;
607 $this->total_ht = $obj->total_ht;
608 $this->total_tva = $obj->total_tva;
609 $this->total_localtax1 = $obj->localtax1;
610 $this->total_localtax2 = $obj->localtax2;
611 $this->total_ttc = $obj->total_ttc;
612 $this->socid = $obj->fk_soc;
613 $this->date_lim_reglement = $this->db->jdate($obj->dlr);
614 $this->mode_reglement_id = $obj->fk_mode_reglement;
615 $this->mode_reglement_code = $obj->mode_reglement_code;
616 $this->mode_reglement = $obj->mode_reglement_libelle;
617 $this->cond_reglement_id = $obj->fk_cond_reglement;
618 $this->cond_reglement_code = $obj->cond_reglement_code;
619 $this->cond_reglement = $obj->cond_reglement_libelle;
620 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
621 $this->fk_project = $obj->fk_project;
622 $this->fk_account = $obj->fk_account;
623 $this->note_private = $obj->note_private;
624 $this->note_public = $obj->note_public;
625 $this->user_author = $obj->fk_user_author;
626 $this->model_pdf = $obj->model_pdf;
627 //$this->special_code = $obj->special_code;
628 $this->frequency = $obj->frequency;
629 $this->unit_frequency = $obj->unit_frequency;
630 $this->date_when = $this->db->jdate($obj->date_when);
631 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
632 $this->nb_gen_done = $obj->nb_gen_done;
633 $this->nb_gen_max = $obj->nb_gen_max;
634 $this->usenewprice = $obj->usenewprice;
635 $this->auto_validate = $obj->auto_validate;
636 $this->generate_pdf = $obj->generate_pdf;
637
638 // Multicurrency
639 $this->fk_multicurrency = $obj->fk_multicurrency;
640 $this->multicurrency_code = $obj->multicurrency_code;
641 $this->multicurrency_tx = $obj->multicurrency_tx;
642 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
643 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
644 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
645
646 // Retrieve all extrafield
647 // fetch optionals attributes and labels
648 if (empty($noextrafields)) {
649 $result = $this->fetch_optionals();
650 if ($result < 0) {
651 $this->error = $this->db->lasterror();
652 return -4;
653 }
654 }
655
656 // Retrieve lines
657 if (empty($nolines)) {
658 $result = $this->fetch_lines();
659 if ($result < 0) {
660 $this->error = $this->db->lasterror();
661 return -3;
662 }
663 }
664
665 return 1;
666 } else {
667 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
668 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
669 return -2;
670 }
671 } else {
672 $this->error = $this->db->error();
673 return -1;
674 }
675 }
676
677
683 public function getLinesArray()
684 {
685 return $this->fetch_lines();
686 }
687
688
689 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
695 public function fetch_lines()
696 {
697 // phpcs:enable
698
699 $this->lines = array();
700
701 dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
702
703 $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, ';
704 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
705 $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,';
706 $sql .= ' l.rang, l.special_code,';
707 $sql .= ' l.fk_unit, l.fk_contract_line,';
708 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
709 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
710 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
711 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
712 $sql .= ' WHERE l.fk_facture = '.((int) $this->id);
713 $sql .= ' ORDER BY l.rang';
714
715 $result = $this->db->query($sql);
716 if ($result) {
717 $num = $this->db->num_rows($result);
718 $i = 0;
719 while ($i < $num) {
720 $objp = $this->db->fetch_object($result);
721 $line = new FactureLigneRec($this->db);
722
723 $line->id = $objp->rowid;
724 $line->rowid = $objp->rowid;
725 $line->fk_facture = $objp->fk_facture;
726 $line->fk_parent_line = $objp->fk_parent_line;
727 $line->desc = $objp->description; // Description line
728 $line->description = $objp->description; // Description line
729 $line->ref = $objp->product_ref; // Ref product
730 $line->product_ref = $objp->product_ref; // Ref product
731 $line->libelle = $objp->product_label; // deprecated
732 $line->product_label = $objp->product_label; // Label product
733 $line->product_desc = $objp->product_desc; // Description product
734 $line->product_type = $objp->product_type; // Type of line
735 $line->fk_product_type = $objp->fk_product_type; // Type of product
736 $line->qty = $objp->qty;
737 $line->subprice = $objp->subprice;
738
739 $line->label = $objp->custom_label; // @deprecated
740
741 $line->vat_src_code = $objp->vat_src_code;
742 $line->tva_tx = $objp->tva_tx;
743 $line->localtax1_tx = $objp->localtax1_tx;
744 $line->localtax2_tx = $objp->localtax2_tx;
745 $line->localtax1_type = $objp->localtax1_type;
746 $line->localtax2_type = $objp->localtax2_type;
747 $line->remise_percent = $objp->remise_percent;
748 //$line->fk_remise_except = $objp->fk_remise_except;
749 $line->fk_product = $objp->fk_product;
750 $line->date_start_fill = $objp->date_start_fill;
751 $line->date_end_fill = $objp->date_end_fill;
752 $line->info_bits = $objp->info_bits;
753 $line->total_ht = $objp->total_ht;
754 $line->total_tva = $objp->total_tva;
755 $line->total_ttc = $objp->total_ttc;
756
757 $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
758 $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility
759
760 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht);
761
762 $line->buyprice = $marginInfos[0];
763 $line->pa_ht = $marginInfos[0]; // For backward compatibility
764 $line->marge_tx = $marginInfos[1];
765 $line->marque_tx = $marginInfos[2];
766 $line->rang = $objp->rang;
767 $line->special_code = $objp->special_code;
768 $line->fk_unit = $objp->fk_unit;
769 $line->fk_contract_line = $objp->fk_contract_line;
770
771 // Ne plus utiliser
772 $line->price = $objp->price;
773 $line->remise = $objp->remise;
774
775 $line->fetch_optionals();
776
777 // Multicurrency
778 $line->fk_multicurrency = $objp->fk_multicurrency;
779 $line->multicurrency_code = $objp->multicurrency_code;
780 $line->multicurrency_subprice = $objp->multicurrency_subprice;
781 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
782 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
783 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
784
785 $this->lines[$i] = $line;
786
787 $i++;
788 }
789
790 $this->db->free($result);
791 return 1;
792 } else {
793 $this->error = $this->db->lasterror();
794 return -3;
795 }
796 }
797
798
807 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
808 {
809 $rowid = $this->id;
810
811 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
812
813 $error = 0;
814 $this->db->begin();
815
816 $main = MAIN_DB_PREFIX.'facturedet_rec';
817 $ef = $main."_extrafields";
818
819 $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture = ".((int) $rowid).")";
820 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".((int) $rowid);
821
822 if ($this->db->query($sqlef) && $this->db->query($sql)) {
823 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".((int) $rowid);
824 dol_syslog($sql);
825 if ($this->db->query($sql)) {
826 // Delete linked object
827 $res = $this->deleteObjectLinked();
828 if ($res < 0) {
829 $error = -3;
830 }
831 // Delete extrafields
832 $res = $this->deleteExtraFields();
833 if ($res < 0) {
834 $error = -4;
835 }
836 } else {
837 $this->error = $this->db->lasterror();
838 $error = -1;
839 }
840 } else {
841 $this->error = $this->db->lasterror();
842 $error = -2;
843 }
844 if (!$error && !$notrigger) {
845 // Call trigger
846 $result = $this->call_trigger('BILLREC_DELETE', $user);
847 if ($result < 0) {
848 $error++;
849 }
850 // End call triggers
851 }
852 if (!$error) {
853 $this->db->commit();
854 return 1;
855 } else {
856 $this->db->rollback();
857 return $error;
858 }
859 }
860
861
890 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)
891 {
892 global $mysoc;
893
894 $facid = $this->id;
895
896 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);
897 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
898
899 // Check parameters
900 if ($type < 0) {
901 return -1;
902 }
903
904 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
905
906 // Clean vat code
907 $reg = array();
908 $vat_src_code = '';
909 if (preg_match('/\‍((.*)\‍)/', (string) $txtva, $reg)) {
910 $vat_src_code = $reg[1];
911 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', (string) $txtva); // Remove code from vatrate.
912 }
913
914
915 // Clean parameters
916 $remise_percent = price2num($remise_percent);
917 if (empty($remise_percent)) {
918 $remise_percent = 0;
919 }
920 $qty = price2num($qty);
921 $pu_ht = price2num($pu_ht);
922 $pu_ttc = price2num($pu_ttc);
923 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
924 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
925 }
926 $txlocaltax1 = price2num($txlocaltax1);
927 $txlocaltax2 = price2num($txlocaltax2);
928 if (empty($txtva)) {
929 $txtva = 0;
930 }
931 if (empty($txlocaltax1)) {
932 $txlocaltax1 = 0;
933 }
934 if (empty($txlocaltax2)) {
935 $txlocaltax2 = 0;
936 }
937 if (empty($info_bits)) {
938 $info_bits = 0;
939 }
940
941 if ($price_base_type == 'HT') {
942 $pu = $pu_ht;
943 } else {
944 $pu = $pu_ttc;
945 }
946
947 // Calcul du total TTC et de la TVA pour la ligne a partir de
948 // qty, pu, remise_percent et txtva
949 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
950 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
951
952 $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);
953 $total_ht = $tabprice[0];
954 $total_tva = $tabprice[1];
955 $total_ttc = $tabprice[2];
956 $total_localtax1 = $tabprice[9];
957 $total_localtax2 = $tabprice[10];
958 $pu_ht = $tabprice[3];
959
960 // MultiCurrency
961 $multicurrency_total_ht = $tabprice[16];
962 $multicurrency_total_tva = $tabprice[17];
963 $multicurrency_total_ttc = $tabprice[18];
964 $pu_ht_devise = $tabprice[19];
965
966 $product_type = $type;
967 if ($fk_product) {
968 $product = new Product($this->db);
969 $result = $product->fetch($fk_product);
970 $product_type = $product->type;
971 }
972
973 if (empty($fk_parent_line) || $fk_parent_line < 0) {
974 $fk_parent_line = 0;
975 }
976
977 // Rank to use
978 $ranktouse = $rang;
979 if ($ranktouse == -1) {
980 $rangmax = $this->line_max(0);
981 $ranktouse = $rangmax + 1;
982 }
983
984 $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
985 $sql .= "fk_facture";
986 $sql .= ", fk_parent_line";
987 $sql .= ", label";
988 $sql .= ", description";
989 $sql .= ", price";
990 $sql .= ", qty";
991 $sql .= ", tva_tx";
992 $sql .= ", vat_src_code";
993 $sql .= ", localtax1_tx";
994 $sql .= ", localtax1_type";
995 $sql .= ", localtax2_tx";
996 $sql .= ", localtax2_type";
997 $sql .= ", fk_product";
998 $sql .= ", product_type";
999 $sql .= ", remise_percent";
1000 $sql .= ", subprice";
1001 $sql .= ", remise";
1002 $sql .= ", total_ht";
1003 $sql .= ", total_tva";
1004 $sql .= ", total_localtax1";
1005 $sql .= ", total_localtax2";
1006 $sql .= ", total_ttc";
1007 $sql .= ", date_start_fill";
1008 $sql .= ", date_end_fill";
1009 $sql .= ", fk_product_fournisseur_price";
1010 $sql .= ", buy_price_ht";
1011 $sql .= ", info_bits";
1012 $sql .= ", rang";
1013 $sql .= ", special_code";
1014 $sql .= ", fk_unit";
1015 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1016 $sql .= ") VALUES (";
1017 $sql .= " ".((int) $facid);
1018 $sql .= ", ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1019 $sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1020 $sql .= ", '".$this->db->escape($desc)."'";
1021 $sql .= ", ".price2num($pu_ht);
1022 $sql .= ", ".price2num($qty);
1023 $sql .= ", ".price2num($txtva);
1024 $sql .= ", '".$this->db->escape($vat_src_code)."'";
1025 $sql .= ", ".price2num($txlocaltax1);
1026 $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
1027 $sql .= ", ".price2num($txlocaltax2);
1028 $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
1029 $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1030 $sql .= ", ".((int) $product_type);
1031 $sql .= ", ".price2num($remise_percent);
1032 $sql .= ", ".price2num($pu_ht);
1033 $sql .= ", null";
1034 $sql .= ", ".price2num($total_ht);
1035 $sql .= ", ".price2num($total_tva);
1036 $sql .= ", ".price2num($total_localtax1);
1037 $sql .= ", ".price2num($total_localtax2);
1038 $sql .= ", ".price2num($total_ttc);
1039 $sql .= ", ".(int) $date_start_fill;
1040 $sql .= ", ".(int) $date_end_fill;
1041 $sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1042 $sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
1043 $sql .= ", ".((int) $info_bits);
1044 $sql .= ", ".((int) $ranktouse);
1045 $sql .= ", ".((int) $special_code);
1046 $sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
1047 $sql .= ", ".(int) $this->fk_multicurrency;
1048 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1049 $sql .= ", ".price2num($pu_ht_devise, 'CU');
1050 $sql .= ", ".price2num($multicurrency_total_ht, 'CT');
1051 $sql .= ", ".price2num($multicurrency_total_tva, 'CT');
1052 $sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
1053 $sql .= ")";
1054
1055 dol_syslog(get_class($this)."::addline", LOG_DEBUG);
1056 if ($this->db->query($sql)) {
1057 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
1058 $this->id = $facid;
1059 $this->update_price(1);
1060 return $lineId;
1061 } else {
1062 $this->error = $this->db->lasterror();
1063 return -1;
1064 }
1065 }
1066
1097 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)
1098 {
1099 global $mysoc;
1100
1101 $facid = $this->id;
1102
1103 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);
1104 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1105
1106 // Clean parameters
1107 if (empty($remise_percent)) {
1108 $remise_percent = 0;
1109 }
1110
1111 // Check parameters
1112 if ($type < 0) {
1113 return -1;
1114 }
1115
1116 // Clean parameters
1117 $remise_percent = price2num($remise_percent);
1118 $qty = price2num($qty);
1119 if (empty($info_bits)) {
1120 $info_bits = 0;
1121 }
1122 $pu_ht = price2num($pu_ht);
1123 $pu_ttc = price2num($pu_ttc);
1124 $pu_ht_devise = price2num($pu_ht_devise);
1125 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
1126 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1127 }
1128 $txlocaltax1 = price2num($txlocaltax1);
1129 $txlocaltax2 = price2num($txlocaltax2);
1130 if (empty($txlocaltax1)) {
1131 $txlocaltax1 = 0;
1132 }
1133 if (empty($txlocaltax2)) {
1134 $txlocaltax2 = 0;
1135 }
1136
1137 if (empty($this->multicurrency_subprice)) {
1138 $this->multicurrency_subprice = 0;
1139 }
1140 if (empty($this->multicurrency_total_ht)) {
1141 $this->multicurrency_total_ht = 0;
1142 }
1143 if (empty($this->multicurrency_total_tva)) {
1144 $this->multicurrency_total_tva = 0;
1145 }
1146 if (empty($this->multicurrency_total_ttc)) {
1147 $this->multicurrency_total_ttc = 0;
1148 }
1149
1150 if ($price_base_type == 'HT') {
1151 $pu = $pu_ht;
1152 } else {
1153 $pu = $pu_ttc;
1154 }
1155
1156 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1157 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1158 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1159
1160 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1161
1162 // Clean vat code
1163 $vat_src_code = '';
1164 $reg = array();
1165 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1166 $vat_src_code = $reg[1];
1167 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1168 }
1169
1170 $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);
1171
1172 $total_ht = $tabprice[0];
1173 $total_tva = $tabprice[1];
1174 $total_ttc = $tabprice[2];
1175 $total_localtax1 = $tabprice[9];
1176 $total_localtax2 = $tabprice[10];
1177 $pu_ht = $tabprice[3];
1178 $pu_tva = $tabprice[4];
1179 $pu_ttc = $tabprice[5];
1180
1181 // MultiCurrency
1182 $multicurrency_total_ht = $tabprice[16];
1183 $multicurrency_total_tva = $tabprice[17];
1184 $multicurrency_total_ttc = $tabprice[18];
1185 $pu_ht_devise = $tabprice[19];
1186
1187 $product_type = $type;
1188 if ($fk_product) {
1189 $product = new Product($this->db);
1190 $result = $product->fetch($fk_product);
1191 $product_type = $product->type;
1192 }
1193
1194 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1195 $fk_parent_line = 0;
1196 }
1197
1198 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
1199 $sql .= "fk_facture = ".((int) $facid);
1200 $sql .= ", fk_parent_line = ".($fk_parent_line > 0 ? ((int) $fk_parent_line) : "null");
1201 $sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
1202 $sql .= ", description='".$this->db->escape($desc)."'";
1203 $sql .= ", price=".price2num($pu_ht);
1204 $sql .= ", qty=".price2num($qty);
1205 $sql .= ", tva_tx=".price2num($txtva);
1206 $sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
1207 $sql .= ", localtax1_tx=".((float) $txlocaltax1);
1208 $sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
1209 $sql .= ", localtax2_tx=".((float) $txlocaltax2);
1210 $sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
1211 $sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
1212 $sql .= ", product_type=".((int) $product_type);
1213 $sql .= ", remise_percent='".price2num($remise_percent)."'";
1214 $sql .= ", subprice='".price2num($pu_ht)."'";
1215 $sql .= ", total_ht='".price2num($total_ht)."'";
1216 $sql .= ", total_tva='".price2num($total_tva)."'";
1217 $sql .= ", total_localtax1='".price2num($total_localtax1)."'";
1218 $sql .= ", total_localtax2='".price2num($total_localtax2)."'";
1219 $sql .= ", total_ttc='".price2num($total_ttc)."'";
1220 $sql .= ", date_start_fill=".((int) $date_start_fill);
1221 $sql .= ", date_end_fill=".((int) $date_end_fill);
1222 $sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
1223 $sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
1224 $sql .= ", info_bits=".((int) $info_bits);
1225 $sql .= ", rang=".((int) $rang);
1226 $sql .= ", special_code=".((int) $special_code);
1227 $sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
1228 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1229 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1230 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1231 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1232 $sql .= " WHERE rowid = ".((int) $rowid);
1233
1234 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
1235 if ($this->db->query($sql)) {
1236 $this->id = $facid;
1237 $this->update_price(1);
1238 return 1;
1239 } else {
1240 $this->error = $this->db->lasterror();
1241 return -1;
1242 }
1243 }
1244
1245
1251 public function getNextDate()
1252 {
1253 if (empty($this->date_when)) {
1254 return false;
1255 }
1256 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1257 }
1258
1264 public function isMaxNbGenReached()
1265 {
1266 $ret = false;
1267 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1268 $ret = true;
1269 }
1270 return $ret;
1271 }
1272
1279 public function strikeIfMaxNbGenReached($ret)
1280 {
1281 return $this->isMaxNbGenReached() ? '<strike>'.$ret.'</strike>' : $ret;
1282 }
1283
1295 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0, $notrigger = 0)
1296 {
1297 global $conf, $langs, $db, $user, $hookmanager;
1298
1299 $error = 0;
1300 $nb_create = 0;
1301
1302 // Load translation files required by the page
1303 $langs->loadLangs(array("main", "bills"));
1304
1305 $now = dol_now();
1306 $tmparray = dol_getdate($now);
1307 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1308
1309 $this->output = '';
1310
1311 dol_syslog("createRecurringInvoices restrictioninvoiceid=".$restrictioninvoiceid." forcevalidation=".$forcevalidation);
1312
1313 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
1314 $sql .= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
1315 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1316 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1317 $sql .= ' AND suspended = 0';
1318 $sql .= ' AND entity = '.$conf->entity; // MUST STAY = $conf->entity here
1319 if ($restrictioninvoiceid > 0) {
1320 $sql .= ' AND rowid = '.((int) $restrictioninvoiceid);
1321 }
1322 $sql .= $this->db->order('entity', 'ASC');
1323 //print $sql;exit;
1324 $parameters = array(
1325 'restrictioninvoiceid' => $restrictioninvoiceid,
1326 'forcevalidation' => $forcevalidation,
1327 );
1328 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1329
1330 $resql = $this->db->query($sql);
1331 if ($resql) {
1332 $i = 0;
1333 $num = $this->db->num_rows($resql);
1334
1335 if ($num) {
1336 $this->output .= $langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
1337 } else {
1338 $this->output .= $langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
1339 }
1340
1341 $saventity = $conf->entity;
1342
1343 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1344 $line = $this->db->fetch_object($resql);
1345
1346 $this->db->begin();
1347
1348 $invoiceidgenerated = 0;
1349
1350 $facture = null;
1351 $facturerec = new FactureRec($this->db);
1352 $facturerec->fetch($line->rowid);
1353
1354 if ($facturerec->id > 0) {
1355 // Set entity context
1356 $conf->entity = $facturerec->entity;
1357
1358 dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
1359
1360 $facture = new Facture($this->db);
1361 $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1362 $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1363
1364 $facture->type = self::TYPE_STANDARD;
1365 $facture->subtype = $facturerec->subtype;
1366 $facture->statut = self::STATUS_DRAFT; // deprecated
1367 $facture->status = self::STATUS_DRAFT;
1368 $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.
1369 $facture->socid = $facturerec->socid;
1370 if (!empty($facturerec->fk_multicurrency)) {
1371 $facture->fk_multicurrency = $facturerec->fk_multicurrency;
1372 $facture->multicurrency_code = $facturerec->multicurrency_code;
1373 $facture->multicurrency_tx = $facturerec->multicurrency_tx;
1374 }
1375
1376 if (isset($facture->array_options) && isset($facturerec->array_options)) {
1377 foreach ($facturerec->array_options as $key => $value) {
1378 if (isset($facture->array_options[$key])) {
1379 $facture->array_options[$key] = $value;
1380 }
1381 }
1382 }
1383
1384 $invoiceidgenerated = $facture->create($user);
1385 if ($invoiceidgenerated <= 0) {
1386 $this->errors = $facture->errors;
1387 $this->error = $facture->error;
1388 $error++;
1389 }
1390
1391
1392 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1393 $result = $facture->validate($user);
1394 if ($result <= 0) {
1395 $this->errors = $facture->errors;
1396 $this->error = $facture->error;
1397 $error++;
1398 }
1399 }
1400 if (!$error && $facturerec->generate_pdf) {
1401 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1402 $facture->fetch($facture->id);
1403 $result = $facture->generateDocument($facturerec->model_pdf, $langs);
1404 if ($result <= 0) {
1405 $this->errors = $facture->errors;
1406 $this->error = $facture->error;
1407 $error++;
1408 }
1409 }
1410 } else {
1411 $error++;
1412 $this->error = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity."\n";
1413 $this->errors[] = "Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity;
1414 dol_syslog("createRecurringInvoices Failed to load invoice template with id=".$line->rowid.", entity=".$conf->entity);
1415 }
1416
1417 if (!$error && $invoiceidgenerated >= 0) {
1418 $this->db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1419 dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
1420 $nb_create++;
1421 $this->output .= $langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
1422 } else {
1423 $this->output .= $langs->trans("InvoiceGeneratedFromTemplateError", $facture->ref, $facturerec->ref, $this->error)."\n";
1424 $this->db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
1425 }
1426
1427 $parameters = array(
1428 'cpt' => $i,
1429 'total' => $num,
1430 'errorCount' => $error,
1431 'invoiceidgenerated' => $invoiceidgenerated,
1432 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1433 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1434 );
1435 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null)
1436
1437 $i++;
1438 }
1439
1440 $conf->entity = $saventity; // Restore entity context
1441 } else {
1442 dol_print_error($this->db);
1443 }
1444
1445 $this->output = trim($this->output);
1446
1447 return $error ? $error : 0;
1448 }
1449
1462 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
1463 {
1464 global $langs, $hookmanager;
1465
1466 $result = '';
1467
1468 $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("RepeatableInvoice").'</u>';
1469 if (!empty($this->ref)) {
1470 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1471 }
1472 if ($this->frequency > 0) {
1473 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1474 }
1475 if (!empty($this->date_last_gen)) {
1476 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1477 }
1478 if ($this->frequency > 0) {
1479 if (!empty($this->date_when)) {
1480 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1481 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1482 if (!empty($this->suspended)) {
1483 $label .= ' ('.$langs->trans("Disabled").')';
1484 }
1485 }
1486 }
1487
1488 $url = DOL_URL_ROOT.'/compta/facture/card-rec.php?facid='.$this->id;
1489
1490 if ($short) {
1491 return $url;
1492 }
1493
1494 if ($option != 'nolink') {
1495 // Add param to save lastsearch_values or not
1496 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1497 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1498 $add_save_lastsearch_values = 1;
1499 }
1500 if ($add_save_lastsearch_values) {
1501 $url .= '&save_lastsearch_values=1';
1502 }
1503 }
1504
1505 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1506 $linkend = '</a>';
1507
1508 $result .= $linkstart;
1509 if ($withpicto) {
1510 $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);
1511 }
1512 if ($withpicto != 2) {
1513 $result .= dol_trunc($this->ref, $max);
1514 }
1515 $result .= $linkend;
1516 global $action;
1517 $hookmanager->initHooks(array($this->element . 'dao'));
1518 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1519 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1520 if ($reshook > 0) {
1521 $result = $hookmanager->resPrint;
1522 } else {
1523 $result .= $hookmanager->resPrint;
1524 }
1525 return $result;
1526 }
1527
1535 public function getLibStatut($mode = 0, $alreadypaid = -1)
1536 {
1537 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1538 }
1539
1540 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1551 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1552 {
1553 // phpcs:enable
1554 global $langs;
1555 $langs->load('bills');
1556
1557 $labelStatus = $langs->transnoentitiesnoconv('Active');
1558 $statusType = 'status0';
1559
1560 //print "$recur,$status,$mode,$alreadypaid,$type";
1561 if ($mode == 0) {
1562 if ($recur) {
1563 if ($status == self::STATUS_SUSPENDED) {
1564 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1565 } else {
1566 $labelStatus = $langs->transnoentitiesnoconv('Active');
1567 }
1568 } else {
1569 if ($status == self::STATUS_SUSPENDED) {
1570 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1571 } else {
1572 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1573 }
1574 }
1575 } elseif ($mode == 1) {
1576 $prefix = 'Short';
1577 if ($recur) {
1578 if ($status == self::STATUS_SUSPENDED) {
1579 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1580 } else {
1581 $labelStatus = $langs->transnoentitiesnoconv('Active');
1582 }
1583 } else {
1584 if ($status == self::STATUS_SUSPENDED) {
1585 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1586 } else {
1587 $labelStatus = $langs->transnoentitiesnoconv("Draft");
1588 }
1589 }
1590 } elseif ($mode == 2) {
1591 if ($recur) {
1592 if ($status == self::STATUS_SUSPENDED) {
1593 $statusType = 'status6';
1594 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1595 } else {
1596 $statusType = 'status4';
1597 $labelStatus = $langs->transnoentitiesnoconv('Active');
1598 }
1599 } else {
1600 if ($status == self::STATUS_SUSPENDED) {
1601 $statusType = 'status6';
1602 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1603 } else {
1604 $statusType = 'status0';
1605 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1606 }
1607 }
1608 } elseif ($mode == 3) {
1609 if ($recur) {
1610 $prefix = 'Short';
1611 if ($status == self::STATUS_SUSPENDED) {
1612 $statusType = 'status6';
1613 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1614 } else {
1615 $statusType = 'status4';
1616 $labelStatus = $langs->transnoentitiesnoconv('Active');
1617 }
1618 } else {
1619 if ($status == self::STATUS_SUSPENDED) {
1620 $statusType = 'status6';
1621 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1622 } else {
1623 $statusType = 'status0';
1624 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1625 }
1626 }
1627 } elseif ($mode == 4) {
1628 $prefix = '';
1629 if ($recur) {
1630 if ($status == self::STATUS_SUSPENDED) {
1631 $statusType = 'status6';
1632 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1633 } else {
1634 $statusType = 'status4';
1635 $labelStatus = $langs->transnoentitiesnoconv('Active');
1636 }
1637 } else {
1638 if ($status == self::STATUS_SUSPENDED) {
1639 $statusType = 'status6';
1640 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1641 } else {
1642 $statusType = 'status0';
1643 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1644 }
1645 }
1646 } elseif ($mode == 5 || $mode == 6) {
1647 $prefix = '';
1648 if ($mode == 5) {
1649 $prefix = 'Short';
1650 }
1651 if ($recur) {
1652 if ($status == self::STATUS_SUSPENDED) {
1653 $statusType = 'status6';
1654 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1655 } else {
1656 $statusType = 'status4';
1657 $labelStatus = $langs->transnoentitiesnoconv('Active');
1658 }
1659 } else {
1660 if ($status == self::STATUS_SUSPENDED) {
1661 $statusType = 'status6';
1662 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1663 } else {
1664 $statusType = 'status0';
1665 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1666 }
1667 }
1668 }
1669
1670 $labelStatusShort = $labelStatus;
1671
1672 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1673 }
1674
1682 public function getNextNumRef($soc, $mode = 'next')
1683 {
1684 // Not used for recurring invoices
1685 return '';
1686 }
1687
1694 public function info($id)
1695 {
1696 $sql = 'SELECT c.rowid, datec, tms as datem,';
1697 $sql .= ' fk_user_author, fk_user_modif';
1698 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_rec as c';
1699 $sql .= ' WHERE c.rowid = '.((int) $id);
1700
1701 $result = $this->db->query($sql);
1702 if ($result) {
1703 if ($this->db->num_rows($result)) {
1704 $obj = $this->db->fetch_object($result);
1705
1706 $this->id = $obj->rowid;
1707
1708 $this->user_creation_id = $obj->fk_user_author;
1709 $this->user_modification_id = $obj->fk_user_modif;
1710 $this->date_creation = $this->db->jdate($obj->datec);
1711 $this->date_modification = $this->db->jdate($obj->datem);
1712 }
1713 $this->db->free($result);
1714 } else {
1715 dol_print_error($this->db);
1716 }
1717 }
1718
1727 public function initAsSpecimen($option = '')
1728 {
1729 global $langs;
1730
1731 $now = dol_now();
1732 $arraynow = dol_getdate($now);
1733 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1734
1735 // Load array of products prodids
1736 $num_prods = 0;
1737 $prodids = array();
1738
1739 $sql = "SELECT rowid";
1740 $sql .= " FROM ".MAIN_DB_PREFIX."product";
1741 $sql .= " WHERE entity IN (".getEntity('product').")";
1742 $sql .= $this->db->plimit(100);
1743
1744 $resql = $this->db->query($sql);
1745 if ($resql) {
1746 $num_prods = $this->db->num_rows($resql);
1747 $i = 0;
1748 while ($i < $num_prods) {
1749 $i++;
1750 $row = $this->db->fetch_row($resql);
1751 $prodids[$i] = $row[0];
1752 }
1753 }
1754
1755 // Initialize parameters
1756 $this->id = 0;
1757 $this->ref = 'SPECIMEN';
1758 $this->title = 'SPECIMEN';
1759 $this->specimen = 1;
1760 $this->socid = 1;
1761 $this->date = $nownotime;
1762 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1763 $this->cond_reglement_id = 1;
1764 $this->cond_reglement_code = 'RECEP';
1765 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1766 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1767 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1768 $this->note_public = 'This is a comment (public)';
1769 $this->note_private = 'This is a comment (private)';
1770 $this->note = 'This is a comment (private)';
1771 $this->fk_incoterms = 0;
1772 $this->location_incoterms = '';
1773
1774 if (empty($option) || $option != 'nolines') {
1775 // Lines
1776 $nbp = 5;
1777 $xnbp = 0;
1778 while ($xnbp < $nbp) {
1779 $line = new FactureLigne($this->db);
1780 $line->desc = $langs->trans("Description")." ".$xnbp;
1781 $line->qty = 1;
1782 $line->subprice = 100;
1783 $line->tva_tx = 19.6;
1784 $line->localtax1_tx = 0;
1785 $line->localtax2_tx = 0;
1786 $line->remise_percent = 0;
1787 if ($xnbp == 1) { // Qty is negative (product line)
1788 $prodid = mt_rand(1, $num_prods);
1789 $line->fk_product = $prodids[$prodid];
1790 $line->qty = -1;
1791 $line->total_ht = -100;
1792 $line->total_ttc = -119.6;
1793 $line->total_tva = -19.6;
1794 } elseif ($xnbp == 2) { // UP is negative (free line)
1795 $line->subprice = -100;
1796 $line->total_ht = -100;
1797 $line->total_ttc = -119.6;
1798 $line->total_tva = -19.6;
1799 $line->remise_percent = 0;
1800 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1801 $prodid = mt_rand(1, $num_prods);
1802 $line->fk_product = $prodids[$prodid];
1803 $line->total_ht = 50;
1804 $line->total_ttc = 59.8;
1805 $line->total_tva = 9.8;
1806 $line->remise_percent = 50;
1807 } else { // (product line)
1808 $prodid = mt_rand(1, $num_prods);
1809 $line->fk_product = $prodids[$prodid];
1810 $line->total_ht = 100;
1811 $line->total_ttc = 119.6;
1812 $line->total_tva = 19.6;
1813 $line->remise_percent = 00;
1814 }
1815
1816 $this->lines[$xnbp] = $line;
1817 $xnbp++;
1818
1819 $this->total_ht += $line->total_ht;
1820 $this->total_tva += $line->total_tva;
1821 $this->total_ttc += $line->total_ttc;
1822 }
1823 $this->revenuestamp = 0;
1824
1825 // Add a line "offered"
1826 $line = new FactureLigne($this->db);
1827 $line->desc = $langs->trans("Description")." (offered line)";
1828 $line->qty = 1;
1829 $line->subprice = 100;
1830 $line->tva_tx = 19.6;
1831 $line->localtax1_tx = 0;
1832 $line->localtax2_tx = 0;
1833 $line->remise_percent = 100;
1834 $line->total_ht = 0;
1835 $line->total_ttc = 0; // 90 * 1.196
1836 $line->total_tva = 0;
1837 $prodid = mt_rand(1, $num_prods);
1838 $line->fk_product = $prodids[$prodid];
1839
1840 $this->lines[$xnbp] = $line;
1841 $xnbp++;
1842 }
1843
1844 $this->usenewprice = 0;
1845
1846 return 1;
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 object 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 object 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 object 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 object 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 object 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 object 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 object 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
2165 public $parent_element = 'facturerec';
2166
2170 public $fk_parent_attribute = 'fk_facture';
2171
2177
2178 public $fk_product_fournisseur_price;
2179 public $fk_fournprice; // For backward compatibility
2180
2181 public $rang;
2182 //public $situation_percent; // Not supported on recurring invoice line
2183
2184 public $desc;
2185 public $description;
2186
2187 public $fk_product_type; // Use instead product_type
2188
2189 public $fk_contract_line;
2190
2191
2199 public function delete(User $user, $notrigger = 0)
2200 {
2201 $error = 0;
2202
2203 $this->db->begin();
2204
2205 if (!$error) {
2206 if (!$notrigger) {
2207 // Call triggers
2208 $result = $this->call_trigger('LINEBILLREC_DELETE', $user);
2209 if ($result < 0) {
2210 $error++;
2211 } // Do also here what you must do to rollback action if trigger fail
2212 // End call triggers
2213 }
2214 }
2215
2216 if (!$error) {
2217 $result = $this->deleteExtraFields();
2218 if ($result < 0) {
2219 $error++;
2220 }
2221 }
2222
2223 if (!$error) {
2224 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id);
2225
2226 $res = $this->db->query($sql);
2227 if (!$res) {
2228 $error++;
2229 $this->errors[] = $this->db->lasterror();
2230 }
2231 }
2232
2233 // Commit or rollback
2234 if ($error) {
2235 $this->db->rollback();
2236 return -1;
2237 } else {
2238 $this->db->commit();
2239 return 1;
2240 }
2241 }
2242
2243
2250 public function fetch($rowid)
2251 {
2252 $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,';
2253 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
2254 $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
2255 $sql .= ' l.rang, l.special_code,';
2256 $sql .= ' l.fk_unit, l.fk_contract_line,';
2257 $sql .= ' l.import_key, l.fk_multicurrency,';
2258 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2259 $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,';
2260 $sql .= ' l.fk_user_author, l.fk_user_modif,';
2261 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2262 $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
2263 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2264 $sql .= ' WHERE l.rowid = '.((int) $rowid);
2265 $sql .= ' ORDER BY l.rang';
2266
2267 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2268 $result = $this->db->query($sql);
2269 if ($result) {
2270 $objp = $this->db->fetch_object($result);
2271
2272 $this->id = $objp->rowid;
2273 $this->fk_facture = $objp->fk_facture;
2274 $this->fk_parent_line = $objp->fk_parent_line;
2275 $this->label = $objp->custom_label; // Label line
2276 $this->desc = $objp->description; // Description line
2277 $this->description = $objp->description; // Description line
2278 $this->product_type = $objp->product_type; // Type of line
2279 $this->ref = $objp->product_ref; // Ref product
2280 $this->product_ref = $objp->product_ref; // Ref product
2281 $this->libelle = $objp->product_label; // deprecated
2282 $this->product_label = $objp->product_label; // Label product
2283 $this->product_desc = $objp->product_desc; // Description product
2284 $this->fk_product_type = $objp->fk_product_type; // Type of product
2285 $this->qty = $objp->qty;
2286 $this->price = $objp->price;
2287 $this->subprice = $objp->subprice;
2288 $this->vat_src_code = $objp->vat_src_code;
2289 $this->tva_tx = $objp->tva_tx;
2290 $this->localtax1_tx = $objp->localtax1_tx;
2291 $this->localtax2_tx = $objp->localtax2_tx;
2292 $this->localtax1_type = $objp->localtax1_type;
2293 $this->localtax2_type = $objp->localtax2_type;
2294 $this->remise_percent = $objp->remise_percent;
2295 //$this->fk_remise_except = $objp->fk_remise_except;
2296 $this->fk_product = $objp->fk_product;
2297 $this->date_start_fill = $objp->date_start_fill;
2298 $this->date_end_fill = $objp->date_end_fill;
2299 $this->info_bits = $objp->info_bits;
2300 $this->total_ht = $objp->total_ht;
2301 $this->total_tva = $objp->total_tva;
2302 $this->total_ttc = $objp->total_ttc;
2303
2304 $this->rang = $objp->rang;
2305 $this->special_code = $objp->special_code;
2306 $this->fk_unit = $objp->fk_unit;
2307 $this->fk_contract_line = $objp->fk_contract_line;
2308 $this->import_key = $objp->import_key;
2309 $this->fk_multicurrency = $objp->fk_multicurrency;
2310 $this->multicurrency_code = $objp->multicurrency_code;
2311 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2312 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2313 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2314 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2315
2316 $this->buy_price_ht = $objp->buy_price_ht;
2317
2318 $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price;
2319 $this->fk_user_author = $objp->fk_user_author;
2320 $this->fk_user_modif = $objp->fk_user_modif;
2321
2322 $this->db->free($result);
2323 return 1;
2324 } else {
2325 $this->error = $this->db->lasterror();
2326 return -3;
2327 }
2328 }
2329
2330
2338 public function update(User $user, $notrigger = 0)
2339 {
2340 global $conf;
2341
2342 $error = 0;
2343
2344 // Clean parameters
2345 if (empty($this->fk_parent_line)) {
2346 $this->fk_parent_line = 0;
2347 }
2348
2349 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2350
2351 $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET";
2352 $sql .= " fk_facture = ".((int) $this->fk_facture);
2353 $sql .= ", fk_parent_line=".($this->fk_parent_line > 0 ? $this->fk_parent_line : "null");
2354 $sql .= ", label=".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
2355 $sql .= ", description='".$this->db->escape($this->desc)."'";
2356 $sql .= ", price=".price2num($this->price);
2357 $sql .= ", qty=".price2num($this->qty);
2358 $sql .= ", tva_tx=".price2num($this->tva_tx);
2359 $sql .= ", vat_src_code='".$this->db->escape($this->vat_src_code)."'";
2360 $sql .= ", localtax1_tx=".price2num($this->localtax1_tx);
2361 $sql .= ", localtax1_type='".$this->db->escape($this->localtax1_type)."'";
2362 $sql .= ", localtax2_tx=".price2num($this->localtax2_tx);
2363 $sql .= ", localtax2_type='".$this->db->escape($this->localtax2_type)."'";
2364 $sql .= ", fk_product=".($this->fk_product > 0 ? $this->fk_product : "null");
2365 $sql .= ", product_type=".((int) $this->product_type);
2366 $sql .= ", remise_percent=".price2num($this->remise_percent);
2367 $sql .= ", subprice=".price2num($this->subprice);
2368 $sql .= ", info_bits=".price2num($this->info_bits);
2369 $sql .= ", date_start_fill=".(int) $this->date_start_fill;
2370 $sql .= ", date_end_fill=".(int) $this->date_end_fill;
2371 if (empty($this->skip_update_total)) {
2372 $sql .= ", total_ht=".price2num($this->total_ht);
2373 $sql .= ", total_tva=".price2num($this->total_tva);
2374 $sql .= ", total_localtax1=".price2num($this->total_localtax1);
2375 $sql .= ", total_localtax2=".price2num($this->total_localtax2);
2376 $sql .= ", total_ttc=".price2num($this->total_ttc);
2377 }
2378 $sql .= ", rang=".((int) $this->rang);
2379 $sql .= ", special_code=".((int) $this->special_code);
2380 $sql .= ", fk_unit=".($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : "null");
2381 $sql .= ", fk_contract_line=".($this->fk_contract_line ? $this->fk_contract_line : "null");
2382 $sql .= " WHERE rowid = ".((int) $this->id);
2383
2384 $this->db->begin();
2385
2386 dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
2387
2388 $resql = $this->db->query($sql);
2389 if ($resql) {
2390 if (!$error) {
2391 $result = $this->insertExtraFields();
2392 if ($result < 0) {
2393 $error++;
2394 }
2395 }
2396
2397 if (!$error && !$notrigger) {
2398 // Call trigger
2399 $result = $this->call_trigger('LINEBILLREC_MODIFY', $user);
2400 if ($result < 0) {
2401 $error++;
2402 }
2403 // End call triggers
2404 }
2405
2406 if ($error) {
2407 $this->db->rollback();
2408 return -2;
2409 } else {
2410 $this->db->commit();
2411 return 1;
2412 }
2413 } else {
2414 $this->error = $this->db->lasterror();
2415 $this->db->rollback();
2416 return -2;
2417 }
2418 }
2419}
$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...
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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.
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 information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
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($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
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:88
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137