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