dolibarr 21.0.0-alpha
fournisseur.facture-rec.class.php
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) 2024 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2023-2024 Nick Fragoulis
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/notify.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37
38
43{
44 const TRIGGER_PREFIX = 'SUPPLIERBILLREC';
48 public $element = 'invoice_supplier_rec';
49
53 public $table_element = 'facture_fourn_rec';
54
58 public $table_element_line = 'facture_fourn_det_rec';
59
63 public $fk_element = 'fk_facture_fourn';
64
68 public $picto = 'bill';
69
73 protected $table_ref_field = 'titre';
74
79 public $titre;
83 public $title;
84
85 public $ref_supplier;
86 public $socid;
87
92 public $fk_soc;
93
94 public $suspended; // status
95
100 public $libelle;
104 public $label;
105
110 public $amount;
115 public $remise;
116
117 public $vat_src_code;
118 public $localtax1;
119 public $localtax2;
120
121 public $user_author;
122 public $user_modif;
123 public $fk_project;
124
125 public $mode_reglement_id;
126 public $mode_reglement_code;
127 public $cond_reglement_code;
128 public $cond_reglement_doc;
129 public $cond_reglement_id;
130
134 public $date_lim_reglement;
135
136 public $usenewprice = 0;
137 public $frequency;
138 public $unit_frequency;
139 public $date_when;
140 public $date_last_gen;
141
145 public $nb_gen_done;
146
150 public $nb_gen_max;
151
155 public $auto_validate; //
156 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
157
162 public $lines = array();
163
164
165 /* Override fields in CommonObject
166 public $entity;
167 public $total_ht;
168 public $total_tva;
169 public $total_ttc;
170 public $fk_account;
171 public $mode_reglement;
172 public $cond_reglement;
173 public $note_public;
174 public $note_private;
175 */
176
201 // BEGIN MODULEBUILDER PROPERTIES
205 public $fields = array(
206 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
207 'titre' => array('type' => 'varchar(100)', 'label' => 'Titre', 'enabled' => 1, 'showoncombobox' => 1, 'visible' => -1, 'position' => 15),
208 'ref_supplier' => array('type' => 'varchar(180)', 'label' => 'RefSupplier', 'enabled' => 1, 'showoncombobox' => 1, 'visible' => -1, 'position' => 20),
209 'entity' => array('type' => 'integer', 'label' => 'Entity', 'default' => '1', 'enabled' => 1, 'visible' => -2, 'notnull' => 1, 'position' => 25, 'index' => 1),
210 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 'isModEnabled("societe")', 'visible' => -1, 'notnull' => 1, 'position' => 30),
211 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'position' => 35),
212 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 40),
213 'suspended' => array('type' => 'integer', 'label' => 'Suspended', 'enabled' => 1, 'visible' => -1, 'position' => 225),
214 'libelle' => array('type' => 'varchar(100)', 'label' => 'Libelle', 'enabled' => 1, 'showoncombobox' => 0, 'visible' => -1, 'position' => 15),
215
216 'localtax1' => array('type' => 'double(24,8)', 'label' => 'Localtax1', 'enabled' => 1, 'visible' => -1, 'position' => 60, 'isameasure' => 1),
217 'localtax2' => array('type' => 'double(24,8)', 'label' => 'Localtax2', 'enabled' => 1, 'visible' => -1, 'position' => 65, 'isameasure' => 1),
218 'total_ht' => array('type' => 'double(24,8)', 'label' => 'Total', 'enabled' => 1, 'visible' => -1, 'position' => 70, 'isameasure' => 1),
219 'total_tva' => array('type' => 'double(24,8)', 'label' => 'Tva', 'enabled' => 1, 'visible' => -1, 'position' => 55, 'isameasure' => 1),
220 'total_ttc' => array('type' => 'double(24,8)', 'label' => 'Total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 75, 'isameasure' => 1),
221
222 'fk_user_author' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'Fk user author', 'enabled' => 1, 'visible' => -1, 'position' => 80),
223 'fk_user_modif' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'enabled' => 1, 'visible' => -2, 'notnull' => -1, 'position' => 210),
224 '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),
225 'fk_account' => array('type' => 'integer', 'label' => 'Fk account', 'enabled' => 'isModEnabled("bank")', 'visible' => -1, 'position' => 175),
226 'fk_cond_reglement' => array('type' => 'integer', 'label' => 'Fk cond reglement', 'enabled' => 1, 'visible' => -1, 'position' => 90),
227 'fk_mode_reglement' => array('type' => 'integer', 'label' => 'Fk mode reglement', 'enabled' => 1, 'visible' => -1, 'position' => 95),
228 'date_lim_reglement' => array('type' => 'date', 'label' => 'Date lim reglement', 'enabled' => 1, 'visible' => -1, 'position' => 100),
229
230 'note_private' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 105),
231 'note_public' => array('type' => 'html', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 110),
232 'modelpdf' => array('type' => 'varchar(255)', 'label' => 'Modelpdf', 'enabled' => 1, 'visible' => -1, 'position' => 115),
233
234 'fk_multicurrency' => array('type' => 'integer', 'label' => 'Fk multicurrency', 'enabled' => 1, 'visible' => -1, 'position' => 180),
235 'multicurrency_code' => array('type' => 'varchar(255)', 'label' => 'Multicurrency code', 'enabled' => 1, 'visible' => -1, 'position' => 185),
236 'multicurrency_tx' => array('type' => 'double(24,8)', 'label' => 'Multicurrency tx', 'enabled' => 1, 'visible' => -1, 'position' => 190, 'isameasure' => 1),
237 'multicurrency_total_ht' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ht', 'enabled' => 1, 'visible' => -1, 'position' => 195, 'isameasure' => 1),
238 'multicurrency_total_tva' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total tva', 'enabled' => 1, 'visible' => -1, 'position' => 200, 'isameasure' => 1),
239 'multicurrency_total_ttc' => array('type' => 'double(24,8)', 'label' => 'Multicurrency total ttc', 'enabled' => 1, 'visible' => -1, 'position' => 205, 'isameasure' => 1),
240
241 'usenewprice' => array('type' => 'integer', 'label' => 'UseNewPrice', 'enabled' => 1, 'visible' => 0, 'position' => 155),
242 'frequency' => array('type' => 'integer', 'label' => 'Frequency', 'enabled' => 1, 'visible' => -1, 'position' => 150),
243 'unit_frequency' => array('type' => 'varchar(2)', 'label' => 'Unit frequency', 'enabled' => 1, 'visible' => -1, 'position' => 125),
244
245 'date_when' => array('type' => 'datetime', 'label' => 'Date when', 'enabled' => 1, 'visible' => -1, 'position' => 130),
246 'date_last_gen' => array('type' => 'datetime', 'label' => 'Date last gen', 'enabled' => 1, 'visible' => -1, 'position' => 135),
247 'nb_gen_done' => array('type' => 'integer', 'label' => 'Nb gen done', 'enabled' => 1, 'visible' => -1, 'position' => 140),
248 'nb_gen_max' => array('type' => 'integer', 'label' => 'Nb gen max', 'enabled' => 1, 'visible' => -1, 'position' => 145),
249 'revenuestamp' => array('type' => 'double(24,8)', 'label' => 'RevenueStamp', 'enabled' => 1, 'visible' => -1, 'position' => 160, 'isameasure' => 1),
250 'auto_validate' => array('type' => 'integer', 'label' => 'Auto validate', 'enabled' => 1, 'visible' => -1, 'position' => 165),
251 'generate_pdf' => array('type' => 'integer', 'label' => 'Generate pdf', 'enabled' => 1, 'visible' => -1, 'position' => 170),
252 );
253 // END MODULEBUILDER PROPERTIES
254
255 const STATUS_NOTSUSPENDED = 0;
256 const STATUS_SUSPENDED = 1;
257
258
259
265 public function __construct($db)
266 {
267 $this->db = $db;
268 }
269
278 public function create($user, $facFournId, $notrigger = 0)
279 {
280 global $conf;
281
282 $error = 0;
283 $now = dol_now();
284
285 // Clean parameters
286 $this->titre = empty($this->titre) ? '' : $this->titre; // deprecated
287 $this->title = empty($this->title) ? '' : $this->title;
288 $keyforref = $this->table_ref_field;
289 $this->ref = $this->$keyforref;
290 $this->ref_supplier = empty($this->ref_supplier) ? '' : $this->ref_supplier;
291 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
292 $this->suspended = empty($this->suspended) ? 0 : $this->suspended;
293 // No frequency defined then no next date to execution
294 if (empty($this->frequency)) {
295 $this->frequency = 0;
296 $this->date_when = null;
297 }
298 $this->frequency = abs($this->frequency);
299 $this->nb_gen_done = 0;
300 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
301 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
302 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
303
304 $this->db->begin();
305
306 // On charge la facture fournisseur depuis laquelle on crée la facture fournisseur modèle
307 $facfourn_src = new FactureFournisseur($this->db);
308 $result = $facfourn_src->fetch($facFournId);
309 if ($result > 0) {
310 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_rec (';
311 $sql .= 'titre';
312 $sql .= ", subtype";
313 $sql .= ', ref_supplier';
314 $sql .= ', entity';
315 $sql .= ', fk_soc';
316 $sql .= ', datec';
317 $sql .= ', suspended';
318 $sql .= ', libelle';
319 $sql .= ', total_ttc';
320 $sql .= ', fk_user_author';
321 $sql .= ', fk_projet';
322 $sql .= ', fk_account';
323 $sql .= ', fk_cond_reglement';
324 $sql .= ', fk_mode_reglement';
325 $sql .= ', date_lim_reglement';
326 $sql .= ', note_private';
327 $sql .= ', note_public';
328 $sql .= ', modelpdf';
329 $sql .= ', fk_multicurrency';
330 $sql .= ', multicurrency_code';
331 $sql .= ', multicurrency_tx';
332 $sql .= ', usenewprice';
333 $sql .= ', frequency';
334 $sql .= ', unit_frequency';
335 $sql .= ', date_when';
336 $sql .= ', date_last_gen';
337 $sql .= ', nb_gen_done';
338 $sql .= ', nb_gen_max';
339 $sql .= ', auto_validate';
340 $sql .= ', generate_pdf';
341 $sql .= ') VALUES (';
342 $sql .= "'".$this->db->escape($this->title)."'";
343 $sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
344 $sql .= ", '".$this->db->escape($this->ref_supplier)."'";
345 $sql .= ", ".((int) $conf->entity);
346 $sql .= ", ".((int) $facfourn_src->socid);
347 $sql .= ", '".$this->db->idate($now)."'";
348 $sql .= ", ".((int) $this->suspended);
349 $sql .= ", '".$this->db->escape($this->libelle)."'";
350 $sql .= ", " .(!empty($facfourn_src->total_ttc) ? (float) $facfourn_src->total_ttc : '0'); // amount
351 $sql .= ", " .((int) $user->id);
352 $sql .= ", " .(!empty($this->fk_project) ? ((int) $this->fk_project) : 'NULL');
353 $sql .= ", " .(!empty($facfourn_src->fk_account) ? ((int) $facfourn_src->fk_account) : 'NULL');
354 $sql .= ", " .($this->cond_reglement_id > 0 ? (int) $this->cond_reglement_id : 'NULL');
355 $sql .= ", " .($this->mode_reglement_id > 0 ? (int) $this->mode_reglement_id : 'NULL');
356 $sql .= ", ".($facfourn_src->date_echeance > 0 ? "'".$this->db->idate($facfourn_src->date_echeance)."'" : 'NULL'); // date_lim_reglement
357 $sql .= ", " .(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : 'NULL');
358 $sql .= ", " .(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : 'NULL');
359 $sql .= ", " .(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : 'NULL');
360 $sql .= ", " . (int) $facfourn_src->fk_multicurrency;
361 $sql .= ", '".$this->db->escape($facfourn_src->multicurrency_code)."'";
362 $sql .= ", " . (float) $facfourn_src->multicurrency_tx;
363 $sql .= ", " . (int) $this->usenewprice;
364 $sql .= ", " . (int) $this->frequency;
365 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
366 $sql .= ", " .(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
367 $sql .= ", " .(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
368 $sql .= ", " . (int) $this->nb_gen_done;
369 $sql .= ", " . (int) $this->nb_gen_max;
370 $sql .= ", " . (int) $this->auto_validate;
371 $sql .= ", " . (int) $this->generate_pdf;
372 $sql .= ')';
373
374 if ($this->db->query($sql)) {
375 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX. 'facture_fourn_rec');
376
377 // Fields used into addline later
378 $this->fk_multicurrency = $facfourn_src->fk_multicurrency;
379
380 $this->multicurrency_code = $facfourn_src->multicurrency_code;
381 $this->multicurrency_tx = $facfourn_src->multicurrency_tx;
382
383 // Add lines
384 $num = count($facfourn_src->lines);
385 for ($i = 0; $i < $num; $i++) {
386 $tva_tx = $facfourn_src->lines[$i]->tva_tx;
387 if (!empty($facfourn_src->lines[$i]->vat_src_code) && !preg_match('/\‍(/', (string) $tva_tx)) {
388 $tva_tx .= ' ('.$facfourn_src->lines[$i]->vat_src_code.')';
389 }
390
391 $result_insert = $this->addline(
392 $facfourn_src->lines[$i]->fk_product,
393 $facfourn_src->lines[$i]->ref_supplier,
394 $facfourn_src->lines[$i]->product_label,
395 $facfourn_src->lines[$i]->desc ? $facfourn_src->lines[$i]->desc : $facfourn_src->lines[$i]->description,
396 $facfourn_src->lines[$i]->pu_ht,
397 $facfourn_src->lines[$i]->pu_ttc,
398 $facfourn_src->lines[$i]->qty,
399 $facfourn_src->lines[$i]->remise_percent,
400 $tva_tx,
401 $facfourn_src->lines[$i]->localtax1_tx,
402 $facfourn_src->lines[$i]->localtax2_tx,
403 'HT',
404 $facfourn_src->lines[$i]->product_type,
405 $facfourn_src->lines[$i]->date_start,
406 $facfourn_src->lines[$i]->date_end,
407 $facfourn_src->lines[$i]->info_bits,
408 $facfourn_src->lines[$i]->special_code,
409 $facfourn_src->lines[$i]->rang,
410 $facfourn_src->lines[$i]->fk_unit
411 );
412
413 if ($result_insert < 0) {
414 $error++;
415 } else {
416 $objectline = new FactureFournisseurLigneRec($this->db);
417
418 $result2 = $objectline->fetch($result_insert);
419 if ($result2 > 0) {
420 // Extrafields
421 if (method_exists($facfourn_src->lines[$i], 'fetch_optionals')) {
422 $facfourn_src->lines[$i]->fetch_optionals($facfourn_src->lines[$i]->id);
423 $objectline->array_options = $facfourn_src->lines[$i]->array_options;
424 }
425
426 $result = $objectline->insertExtraFields();
427 if ($result < 0) {
428 $error++;
429 }
430 } elseif ($result2 < 0) {
431 $this->errors[] = $objectline->error;
432 $error++;
433 }
434 }
435 }
436
437 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
438 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
439 }
440
441 // Add object linked
442 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
443 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
444 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, ...))
445 foreach ($tmp_origin_id as $origin_id) {
446 $ret = $this->add_object_linked($origin, $origin_id);
447 if (!$ret) {
448 $this->error = $this->db->lasterror();
449 $error++;
450 }
451 }
452 } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
453 $origin_id = $tmp_origin_id;
454 $ret = $this->add_object_linked($origin, $origin_id);
455 if (!$ret) {
456 $this->error = $this->db->lasterror();
457 $error++;
458 }
459 }
460 }
461 }
462
463 if (!$error) {
464 $result = $this->insertExtraFields();
465 if ($result < 0) {
466 $error++;
467 }
468 }
469
470 if (!$error && !$notrigger) {
471 // Call trigger
472 $result = $this->call_trigger('SUPPLIERBILLREC_CREATE', $user);
473 if ($result < 0) {
474 $this->db->rollback();
475 return -2;
476 }
477 // End call triggers
478 }
479
480 if ($error) {
481 $this->db->rollback();
482 return -3;
483 } else {
484 $this->db->commit();
485 return $this->id;
486 }
487 } else {
488 $this->error = $this->db->lasterror();
489 $this->db->rollback();
490 return -2;
491 }
492 } else {
493 $this->db->rollback();
494 return -1;
495 }
496 }
497
498
506 public function update(User $user, $notrigger = 0)
507 {
508 $error = 0;
509
510 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_rec SET";
511 $sql .= " titre = '" . (!empty($this->title) ? $this->db->escape($this->title) : "")."'," ;
512 $sql .= " subtype=".(isset($this->subtype) ? $this->db->escape($this->subtype) : "null").",";
513 $sql .= " ref_supplier = '". (!empty($this->ref_supplier) ? $this->db->escape($this->ref_supplier) : "")."',";
514 $sql .= " entity = ". (!empty($this->entity) ? ((int) $this->entity) : 1) . ',';
515 if (!empty($this->socid) && $this->socid > 0) {
516 $sql .= " fk_soc = ". ((int) $this->socid). ',';
517 } elseif (!empty($this->fk_soc) && $this->fk_soc > 0) { // For backward compatibility
518 $sql .= " fk_soc = ". ((int) $this->fk_soc). ',';
519 }
520 $sql .= " suspended = ". (!empty($this->suspended) ? ((int) $this->suspended) : 0) . ',';
521 $sql .= " libelle = ". (!empty($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : 'NULL') . ",";
522 $sql .= " vat_src_code = ". (!empty($this->vat_src_code) ? "'".$this->db->escape($this->vat_src_code)."'" : 'NULL') . ',';
523 $sql .= " localtax1 = ". (!empty($this->localtax1) ? ((float) $this->localtax1) : 0.00) . ',';
524 $sql .= " localtax2 = ". (!empty($this->localtax2) ? ((float) $this->localtax2) : 0.00) . ',';
525 $sql .= " total_ht = ". (!empty($this->total_ht) ? ((float) $this->total_ht) : 0.00) . ',';
526 $sql .= " total_tva = ". (!empty($this->total_tva) ? ((float) $this->total_tva) : 0.00) . ',';
527 $sql .= " total_ttc = ". (!empty($this->total_ttc) ? ((float) $this->total_ttc) : 0.00) . ',';
528 $sql .= " fk_user_modif = ". ((int) $user->id) . ',';
529 $sql .= " fk_projet = ". (!empty($this->fk_project) ? ((int) $this->fk_project) : 'NULL') . ',';
530 $sql .= " fk_account = ". (!empty($this->fk_account) ? ((int) $this->fk_account) : 'NULL') . ',';
531 $sql .= " fk_mode_reglement = ". (!empty($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) : 'NULL') . ',';
532 $sql .= " fk_cond_reglement = ". (!empty($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) : 'NULL') . ',';
533 $sql .= " date_lim_reglement = ". (!empty($this->date_lim_reglement) ? "'".$this->db->idate($this->date_lim_reglement)."'" : 'NULL') . ',';
534 $sql .= " note_private = '". (!empty($this->note_private) ? $this->db->escape($this->note_private) : '') . "',";
535 $sql .= " note_public = '". (!empty($this->note_public) ? $this->db->escape($this->note_public) : '') . "',";
536 $sql .= " modelpdf = ". (!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : 'NULL') . ",";
537 $sql .= " fk_multicurrency = ". (!empty($this->fk_multicurrency) ? ((int) $this->fk_multicurrency) : 'NULL') . ',';
538 $sql .= " multicurrency_code = ". (!empty($this->multicurrency_code) ? "'".$this->db->escape($this->multicurrency_code)."'" : 'NULL') . ",";
539 $sql .= " multicurrency_tx = ". (!empty($this->multicurrency_tx) ? ((float) $this->multicurrency_tx) : 1) . ',';
540 $sql .= " multicurrency_total_ht = ". (!empty($this->multicurrency_total_ht) ? ((float) $this->multicurrency_total_ht) : 0.00) . ',';
541 $sql .= " multicurrency_total_tva = ". (!empty($this->multicurrency_total_tva) ? ((float) $this->multicurrency_total_tva) : 0.00) . ',';
542 $sql .= " multicurrency_total_ttc = ". (!empty($this->multicurrency_total_ttc) ? ((float) $this->multicurrency_total_ttc) : 0.00) . ',';
543 $sql .= " usenewprice = ". (!empty($this->usenewprice) ? ((int) $this->usenewprice) : 0) . ',';
544 $sql .= " frequency = ". (!empty($this->frequency) ? ((int) $this->frequency) : 0). ',';
545 $sql .= " unit_frequency = '". (!empty($this->unit_frequency) ? $this->db->escape($this->unit_frequency) : ''). "',";
546 $sql .= " date_when = ". (!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL') . ',';
547 $sql .= " date_last_gen = ". (!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL') . ',';
548 $sql .= " nb_gen_done = ". (!empty($this->nb_gen_done) ? ((int) $this->nb_gen_done) : 0) . ',';
549 $sql .= " nb_gen_max = ". (!empty($this->nb_gen_max) ? ((int) $this->nb_gen_max) : 0) . ',';
550 $sql .= " auto_validate = ". (!empty($this->auto_validate) ? ((int) $this->auto_validate) : 0);
551 $sql .= " WHERE rowid = ". (int) $this->id;
552
553 $this->db->begin();
554
555 dol_syslog(get_class($this)."::update", LOG_DEBUG);
556 $resql = $this->db->query($sql);
557 if ($resql) {
558 if (!$error) {
559 $result = $this->insertExtraFields();
560 if ($result < 0) {
561 $error++;
562 }
563 }
564
565 if (!$error && !$notrigger) {
566 // Call trigger
567 $result = $this->call_trigger('SUPPLIERBILLREC_MODIFY', $user);
568 if ($result < 0) {
569 $this->db->rollback();
570 return -2;
571 }
572 // End call triggers
573 }
574 $this->db->commit();
575 return 1;
576 } else {
577 $this->error = $this->db->lasterror();
578 $this->db->rollback();
579 return -2;
580 }
581 }
582
591 public function fetch($rowid, $ref = '', $ref_ext = '')
592 {
593 $sql = 'SELECT f.rowid, f.titre as title, f.subtype, f.ref_supplier, f.entity, f.fk_soc';
594 $sql .= ', f.datec, f.tms, f.suspended';
595 $sql .= ', f.libelle as label';
596 $sql .= ', f.vat_src_code, f.localtax1, f.localtax2';
597 $sql .= ', f.total_tva, f.total_ht, f.total_ttc';
598 $sql .= ', f.fk_user_author, f.fk_user_modif';
599 $sql .= ', f.fk_projet as fk_project, f.fk_account';
600 $sql .= ', f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
601 $sql .= ', f.fk_cond_reglement, c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
602 $sql .= ', f.date_lim_reglement';
603 $sql .= ', f.note_private, f.note_public, f.modelpdf as model_pdf';
604 $sql .= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc';
605 $sql .= ', f.usenewprice, f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.auto_validate';
606 $sql .= ', f.generate_pdf';
607 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_rec as f';
608 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
609 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
610 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
611 if ($rowid) {
612 $sql .= ' AND f.rowid='. (int) $rowid;
613 } elseif ($ref) {
614 $sql .= " AND f.titre='".$this->db->escape($ref)."'";
615 } else {
616 $sql .= ' AND f.rowid = 0';
617 }
618
619 $result = $this->db->query($sql);
620 if ($result) {
621 if ($this->db->num_rows($result)) {
622 $obj = $this->db->fetch_object($result);
623
624 $keyforref = $this->table_ref_field;
625
626 $this->id = $obj->rowid;
627 $this->titre = $obj->title;
628 $this->title = $obj->title;
629 $this->subtype = $obj->subtype;
630 $this->ref = $obj->title;
631 $this->ref_supplier = $obj->ref_supplier;
632 $this->entity = $obj->entity;
633 $this->socid = $obj->fk_soc;
634 $this->date_creation = $obj->datec;
635 $this->date_modification = $obj->tms;
636 $this->suspended = $obj->suspended;
637 $this->libelle = $obj->label;
638 $this->label = $obj->label;
639 $this->vat_src_code = $obj->vat_src_code;
640 $this->total_localtax1 = $obj->localtax1;
641 $this->total_localtax2 = $obj->localtax2;
642 $this->total_ht = $obj->total_ht;
643 $this->total_tva = $obj->total_tva;
644 $this->total_ttc = $obj->total_ttc;
645 $this->user_author = $obj->fk_user_author;
646 $this->user_modif = $obj->fk_user_modif;
647 $this->fk_project = $obj->fk_project;
648 $this->fk_account = $obj->fk_account;
649 $this->mode_reglement_id = $obj->fk_mode_reglement;
650 $this->mode_reglement_code = $obj->mode_reglement_code;
651 $this->mode_reglement = $obj->mode_reglement_libelle;
652 $this->cond_reglement_id = $obj->fk_cond_reglement;
653 $this->cond_reglement_code = $obj->cond_reglement_code;
654 $this->cond_reglement = $obj->cond_reglement_libelle;
655 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
656 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
657 $this->note_private = $obj->note_private;
658 $this->note_public = $obj->note_public;
659 $this->model_pdf = $obj->model_pdf;
660
661 // Multicurrency
662 $this->fk_multicurrency = $obj->fk_multicurrency;
663 $this->multicurrency_code = $obj->multicurrency_code;
664 $this->multicurrency_tx = $obj->multicurrency_tx;
665 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
666 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
667 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
668
669 $this->usenewprice = $obj->usenewprice;
670 $this->frequency = $obj->frequency;
671 $this->unit_frequency = $obj->unit_frequency;
672 $this->date_when = $this->db->jdate($obj->date_when);
673 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
674 $this->nb_gen_done = $obj->nb_gen_done;
675 $this->nb_gen_max = $obj->nb_gen_max;
676 $this->auto_validate = $obj->auto_validate;
677 $this->generate_pdf = $obj->generate_pdf;
678
679 // Retrieve all extrafield
680 // fetch optionals attributes and labels
681 $this->fetch_optionals();
682
683 /*
684 * Lines
685 */
686 $result = $this->fetch_lines();
687 if ($result < 0) {
688 $this->error = $this->db->lasterror();
689 return -3;
690 }
691 return 1;
692 } else {
693 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
694 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
695 return -2;
696 }
697 } else {
698 $this->error = $this->db->error();
699 return -1;
700 }
701 }
702
703
709 public function getLinesArray()
710 {
711 return $this->fetch_lines();
712 }
713
714 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
720 public function fetch_lines()
721 {
722 // phpcs:enable
723 $this->lines = array();
724
725 // Retrieve all extrafield for line
726 // fetch optionals attributes and labels
727 /*if (!is_object($extrafields)) {
728 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
729 $extrafields = new ExtraFields($this->db);
730 }
731 $extrafields->fetch_name_optionals_label($this->table_element_line, true);
732 */
733
734 $sql = 'SELECT l.rowid,';
735 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product, l.ref, l.label, l.description as line_desc,';
736 $sql .= ' l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except, l.vat_src_code, l.tva_tx,';
737 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type,';
738 $sql .= ' l.total_ht, l.total_tva, l.total_ttc, total_localtax1, total_localtax2,';
739 $sql .= ' l.product_type, l.date_start, l.date_end,';
740 $sql .= ' l.info_bits, l.special_code, l.rang,';
741 $sql .= ' l.fk_unit, l.import_key, l.fk_user_author, l.fk_user_modif,';
742 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
743 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
744 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
745 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
746 $sql .= ' WHERE l.fk_facture_fourn = '. (int) $this->id;
747 $sql .= ' ORDER BY l.rang';
748
749 dol_syslog('FactureFournisseurRec::fetch_lines', LOG_DEBUG);
750
751 $result = $this->db->query($sql);
752 if ($result) {
753 $num = $this->db->num_rows($result);
754 $i = 0;
755 while ($i < $num) {
756 $objp = $this->db->fetch_object($result);
757
758 $line = new FactureFournisseurLigneRec($this->db);
759
760 $line->id = $objp->rowid;
761 $line->fk_facture_fourn = $objp->fk_facture_fourn;
762 $line->fk_parent = $objp->fk_parent_line;
763 $line->fk_product = $objp->fk_product;
764 $line->ref_supplier = $objp->ref;
765 $line->label = $objp->label;
766 $line->description = $objp->line_desc;
767 $line->desc = $objp->line_desc;
768 $line->pu_ht = $objp->pu_ht;
769 $line->pu_ttc = $objp->pu_ttc;
770 $line->qty = $objp->qty;
771 $line->remise_percent = $objp->remise_percent;
772 $line->fk_remise_except = $objp->fk_remise_except;
773 $line->vat_src_code = $objp->vat_src_code;
774 $line->tva_tx = $objp->tva_tx;
775 $line->localtax1_tx = $objp->localtax1_tx;
776 $line->localtax1_type = $objp->localtax1_type;
777 $line->localtax2_tx = $objp->localtax2_tx;
778 $line->localtax2_type = $objp->localtax2_type;
779 $line->total_ht = $objp->total_ht;
780 $line->total_tva = $objp->total_tva;
781 $line->total_localtax1 = $objp->total_localtax1;
782 $line->total_localtax2 = $objp->total_localtax2;
783 $line->total_ttc = $objp->total_ttc;
784 $line->product_type = $objp->product_type;
785 $line->date_start = $objp->date_start;
786 $line->date_end = $objp->date_end;
787 $line->info_bits = $objp->info_bits ;
788 $line->special_code = $objp->special_code;
789 $line->rang = $objp->rang;
790 $line->fk_unit = $objp->fk_unit;
791 $line->import_key = $objp->import_key;
792 $line->fk_user_author = $objp->fk_user_author;
793 $line->fk_user_modif = $objp->fk_user_modif;
794 $line->fk_multicurrency = $objp->fk_multicurrency;
795 $line->multicurrency_code = $objp->multicurrency_code;
796 $line->multicurrency_subprice = $objp->multicurrency_subprice;
797 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
798 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
799 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
800
801 $line->fetch_optionals();
802
803 $this->lines[$i] = $line;
804
805 $i++;
806 }
807
808 $this->db->free($result);
809 return 1;
810 } else {
811 $this->error = $this->db->lasterror();
812 return -3;
813 }
814 }
815
816
825 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
826 {
827 $rowid = $this->id;
828
829 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
830
831 $error = 0;
832 $this->db->begin();
833
834 $main = MAIN_DB_PREFIX.'facture_fourn_det_rec';
835 $ef = $main."_extrafields";
836
837 $sqlef = "DELETE FROM ".$ef." WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture_fourn = ". (int) $rowid .")";
838 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det_rec WHERE fk_facture_fourn = ". (int) $rowid;
839
840 if ($this->db->query($sqlef) && $this->db->query($sql)) {
841 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_rec WHERE rowid = ". (int) $rowid;
842 dol_syslog($sql);
843 if ($this->db->query($sql)) {
844 // Delete linked object
845 $res = $this->deleteObjectLinked();
846 if ($res < 0) {
847 $error = -3;
848 }
849 // Delete extrafields
850 $res = $this->deleteExtraFields();
851 if ($res < 0) {
852 $error = -4;
853 }
854 } else {
855 $this->error = $this->db->lasterror();
856 $error = -1;
857 }
858 } else {
859 $this->error = $this->db->lasterror();
860 $error = -2;
861 }
862 if (!$error && !$notrigger) {
863 // Call trigger
864 $result = $this->call_trigger('SUPPLIERBILLREC_DELETE', $user);
865 if ($result < 0) {
866 $error++;
867 }
868 // End call triggers
869 }
870 if (! $error) {
871 $this->db->commit();
872 return 1;
873 } else {
874 $this->db->rollback();
875 return $error;
876 }
877 }
878
905 public function addline($fk_product, $ref, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $type = 0, $date_start = 0, $date_end = 0, $info_bits = 0, $special_code = 0, $rang = -1, $fk_unit = null, $pu_ht_devise = 0)
906 {
907 global $mysoc, $user;
908
909 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
910
911 $facid = $this->id; //Supplier invoice template ID linked to
912
913 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,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,date_end_fill=$date_end", LOG_DEBUG);
914
915 // Check if object of the line is product or service
916 if ($type < 0) {
917 return -1;
918 }
919
920 if ($this->suspended == self::STATUS_NOTSUSPENDED) {
921 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
922
923 // Clean vat code
924 $reg = array();
925 $vat_src_code = '';
926 if (preg_match('/\‍((.*)\‍)/', (string) $txtva, $reg)) {
927 $vat_src_code = $reg[1];
928 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', (string) $txtva); // Remove code into vatrate.
929 }
930
931 // Clean parameters
932 $fk_product = empty($fk_product) ? 0 : $fk_product;
933 $label = empty($label) ? '' : $label;
934 $remise_percent = empty($remise_percent) ? 0 : price2num($remise_percent);
935 $qty = price2num($qty);
936 $pu_ht = price2num($pu_ht);
937 $pu_ttc = price2num($pu_ttc);
938 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
939 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
940 }
941 $txlocaltax1 = price2num($txlocaltax1);
942 $txlocaltax2 = price2num($txlocaltax2);
943 $txtva = !empty($txtva) ? $txtva : 0;
944 $txlocaltax1 = !empty($txlocaltax1) ? $txlocaltax1 : 0;
945 $txlocaltax2 = !empty($txlocaltax2) ? $txlocaltax2 : 0;
946 $info_bits = !empty($info_bits) ? $info_bits : 0;
947 $info_bits = !empty($info_bits) ? $info_bits : 0;
948 $pu = $price_base_type == 'HT' ? $pu_ht : $pu_ttc;
949
950 // Calcul du total TTC et de la TVA pour la ligne a partir de qty, pu, remise_percent et txtva
951 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
952 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
953
954 $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);
955 $total_ht = $tabprice[0];
956 $total_tva = $tabprice[1];
957 $total_ttc = $tabprice[2];
958 $total_localtax1 = $tabprice[9];
959 $total_localtax2 = $tabprice[10];
960 $pu_ht = $tabprice[3];
961
962 // MultiCurrency
963 $multicurrency_total_ht = $tabprice[16];
964 $multicurrency_total_tva = $tabprice[17];
965 $multicurrency_total_ttc = $tabprice[18];
966 $pu_ht_devise = $tabprice[19];
967
968 $this->db->begin();
969 $product_type = $type;
970 if ($fk_product) {
971 $product = new Product($this->db);
972 $result = $product->fetch($fk_product);
973 if ($result < 0) {
974 return -1;
975 }
976 $product_type = $product->type;
977 if (empty($label)) {
978 $label = $product->label;
979 }
980 }
981
982 $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec (';
983 $sql .= 'fk_facture_fourn';
984 $sql .= ', fk_product';
985 $sql .= ', ref';
986 $sql .= ', label';
987 $sql .= ', description';
988 $sql .= ', pu_ht';
989 $sql .= ', pu_ttc';
990 $sql .= ', qty';
991 $sql .= ', remise_percent';
992 $sql .= ', fk_remise_except';
993 $sql .= ', vat_src_code';
994 $sql .= ', tva_tx';
995 $sql .= ', localtax1_tx';
996 $sql .= ', localtax1_type';
997 $sql .= ', localtax2_tx';
998 $sql .= ', localtax2_type';
999 $sql .= ', total_ht';
1000 $sql .= ', total_tva';
1001 $sql .= ', total_localtax1';
1002 $sql .= ', total_localtax2';
1003 $sql .= ', total_ttc';
1004 $sql .= ', product_type';
1005 $sql .= ', date_start';
1006 $sql .= ', date_end';
1007 $sql .= ', info_bits';
1008 $sql .= ', special_code';
1009 $sql .= ', rang';
1010 $sql .= ', fk_unit';
1011 $sql .= ', fk_user_author';
1012 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
1013 $sql .= ') VALUES (';
1014 $sql .= ' ' . (int) $facid; // source supplier invoice id
1015 $sql .= ', ' . (!empty($fk_product) ? "'" . $this->db->escape($fk_product) . "'" : 'null');
1016 $sql .= ', ' . (!empty($ref) ? "'" . $this->db->escape($ref) . "'" : 'null');
1017 $sql .= ', ' . (!empty($label) ? "'" . $this->db->escape($label) . "'" : 'null');
1018 $sql .= ", '" . $this->db->escape($desc) . "'";
1019 $sql .= ', ' . price2num($pu_ht);
1020 $sql .= ', ' . price2num($pu_ttc);
1021 $sql .= ', ' . price2num($qty);
1022 $sql .= ', ' . price2num($remise_percent);
1023 $sql .= ', null';
1024 $sql .= ", '" . $this->db->escape($vat_src_code) . "'";
1025 $sql .= ', ' . price2num($txtva);
1026 $sql .= ', ' . price2num($txlocaltax1);
1027 $sql .= ", '" . $this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '') . "'";
1028 $sql .= ', ' . price2num($txlocaltax2);
1029 $sql .= ", '" . $this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '') . "'";
1030 $sql .= ', ' . price2num($total_ht);
1031 $sql .= ', ' . price2num($total_tva);
1032 $sql .= ', ' . price2num($total_localtax1);
1033 $sql .= ', ' . price2num($total_localtax2);
1034 $sql .= ', ' . price2num($total_ttc);
1035 $sql .= ', ' . (int) $product_type;
1036 $sql .= ', ' . ($date_start > 0 ? (int) $date_start : 'NULL');
1037 $sql .= ', ' . ($date_end > 0 ? (int) $date_end : 'NULL');
1038 $sql .= ', ' . (int) $info_bits;
1039 $sql .= ', ' . (int) $special_code;
1040 $sql .= ', ' . (int) $rang;
1041 $sql .= ', ' . ($fk_unit ? (int) $fk_unit : 'NULL');
1042 $sql .= ', ' . (int) $user->id;
1043 $sql .= ', ' . (int) $this->fk_multicurrency;
1044 $sql .= ", '" . $this->db->escape($this->multicurrency_code) . "'";
1045 $sql .= ', ' . price2num($pu_ht_devise, 'CU');
1046 $sql .= ', ' . price2num($multicurrency_total_ht, 'CT');
1047 $sql .= ', ' . price2num($multicurrency_total_tva, 'CT');
1048 $sql .= ', ' . price2num($multicurrency_total_ttc, 'CT');
1049 $sql .= ')';
1050
1051 dol_syslog(get_class($this). '::addline', LOG_DEBUG);
1052 if ($this->db->query($sql)) {
1053 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX. 'facture_fourn_det_rec');
1054 $this->update_price();
1055 $this->id = $facid;
1056 $this->db->commit();
1057 return $lineId;
1058 } else {
1059 $this->db->rollback();
1060 $this->error = $this->db->lasterror();
1061
1062 return -1;
1063 }
1064 } else {
1065 $this->error = 'Recurring Invoice is suspended. adding lines not allowed.';
1066
1067 return -1;
1068 }
1069 }
1070
1098 public function updateline($rowid, $fk_product, $ref, $label, $desc, $pu_ht, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $type = 0, $date_start = 0, $date_end = 0, $info_bits = 0, $special_code = 0, $rang = -1, $fk_unit = null, $pu_ht_devise = 0, $pu_ttc = 0)
1099 {
1100 global $mysoc, $user;
1101
1102 $facid = $this->id;
1103
1104 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, price_base_type=$price_base_type, pu_ttc=$pu_ttc, type=$type, fk_unit=$fk_unit, pu_ht_devise=$pu_ht_devise", LOG_DEBUG);
1105 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1106
1107 // Check parameters
1108 if ($type < 0) {
1109 return -1;
1110 }
1111
1112 if ($this->status == self::STATUS_SUSPENDED) {
1113 // Clean parameters
1114 $fk_product = empty($fk_product) ? 0 : $fk_product;
1115 $label = empty($label) ? '' : $label;
1116 $remise_percent = empty($remise_percent) ? 0 : price2num($remise_percent);
1117 $qty = price2num($qty);
1118 $info_bits = empty($info_bits) ? 0 : $info_bits;
1119 $pu_ht = price2num($pu_ht);
1120 $pu_ttc = price2num($pu_ttc);
1121 $pu_ht_devise = price2num($pu_ht_devise);
1122
1123 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
1124 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1125 }
1126
1127 $txlocaltax1 = empty($txlocaltax1) ? 0 : price2num($txlocaltax1);
1128 $txlocaltax2 = empty($txlocaltax2) ? 0 : price2num($txlocaltax2);
1129 $this->multicurrency_total_ht = empty($this->multicurrency_total_ht) ? 0 : $this->multicurrency_total_ht;
1130 $this->multicurrency_total_tva = empty($this->multicurrency_total_tva) ? 0 : $this->multicurrency_total_tva;
1131 $this->multicurrency_total_ttc = empty($this->multicurrency_total_ttc) ? 0 : $this->multicurrency_total_ttc;
1132
1133 $pu = $price_base_type == 'HT' ? $pu_ht : $pu_ttc;
1134
1135
1136 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1137 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1138 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1139
1140 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1141
1142 // Clean vat code
1143 $vat_src_code = '';
1144 $reg = array();
1145 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1146 $vat_src_code = $reg[1];
1147 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1148 }
1149
1150 $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);
1151
1152 $total_ht = $tabprice[0];
1153 $total_tva = $tabprice[1];
1154 $total_ttc = $tabprice[2];
1155 $total_localtax1 = $tabprice[9];
1156 $total_localtax2 = $tabprice[10];
1157 $pu_ht = $tabprice[3];
1158 $pu_tva = $tabprice[4];
1159 $pu_ttc = $tabprice[5];
1160
1161 // MultiCurrency
1162 $multicurrency_total_ht = $tabprice[16];
1163 $multicurrency_total_tva = $tabprice[17];
1164 $multicurrency_total_ttc = $tabprice[18];
1165 $pu_ht_devise = $tabprice[19];
1166
1167 $product_type = $type;
1168 if ($fk_product) {
1169 $product = new Product($this->db);
1170 $result = $product->fetch($fk_product);
1171 $product_type = $product->type;
1172 }
1173
1174 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
1175 $sql .= ' fk_facture_fourn = ' . ((int) $facid);
1176 $sql .= ', fk_product = ' . ($fk_product > 0 ? ((int) $fk_product) : 'null');
1177 $sql .= ", ref = '" . $this->db->escape($ref) . "'";
1178 $sql .= ", label = '" . $this->db->escape($label) . "'";
1179 $sql .= ", description = '" . $this->db->escape($desc) . "'";
1180 $sql .= ', pu_ht = ' . price2num($pu_ht);
1181 $sql .= ', qty = ' . price2num($qty);
1182 $sql .= ", remise_percent = '" . price2num($remise_percent) . "'";
1183 $sql .= ", vat_src_code = '" . $this->db->escape($vat_src_code) . "'";
1184 $sql .= ', tva_tx = ' . price2num($txtva);
1185 $sql .= ', localtax1_tx = ' . (float) $txlocaltax1;
1186 $sql .= ", localtax1_type = '" . $this->db->escape($localtaxes_type[0]) . "'";
1187 $sql .= ', localtax2_tx = ' . (float) $txlocaltax2;
1188 $sql .= ", localtax2_type = '" . $this->db->escape($localtaxes_type[2]) . "'";
1189 $sql .= ", total_ht = '" . price2num($total_ht) . "'";
1190 $sql .= ", total_tva = '" . price2num($total_tva) . "'";
1191 $sql .= ", total_localtax1 = '" . price2num($total_localtax1) . "'";
1192 $sql .= ", total_localtax2 = '" . price2num($total_localtax2) . "'";
1193 $sql .= ", total_ttc = '" . price2num($total_ttc) . "'";
1194 $sql .= ', product_type = ' . (int) $product_type;
1195 $sql .= ', date_start = ' . (empty($date_start) ? 'NULL' : (int) $date_start);
1196 $sql .= ', date_end = ' . (empty($date_end) ? 'NULL' : (int) $date_end);
1197 $sql .= ', info_bits = ' . (int) $info_bits;
1198 $sql .= ', special_code = ' . (int) $special_code;
1199 $sql .= ', rang = ' . (int) $rang;
1200 $sql .= ', fk_unit = ' . ($fk_unit ? "'" . $this->db->escape($fk_unit) . "'" : 'null');
1201 $sql .= ', fk_user_modif = ' . (int) $user;
1202 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1203 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1204 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1205 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1206 $sql .= ' WHERE rowid = ' . (int) $rowid;
1207
1208 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
1209 if ($this->db->query($sql)) {
1210 $this->id = $facid;
1211 $this->update_price();
1212 return 1;
1213 } else {
1214 $this->error = $this->db->lasterror();
1215 return -1;
1216 }
1217 }
1218 return 0;
1219 }
1220
1221
1229 public function getNextNumRef($soc, $mode = 'next')
1230 {
1231 // Not used for recurring invoices
1232 return '';
1233 }
1234
1240 public function getNextDate()
1241 {
1242 if (empty($this->date_when)) {
1243 return false;
1244 }
1245 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1246 }
1247
1253 public function isMaxNbGenReached()
1254 {
1255 $ret = false;
1256 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1257 $ret = true;
1258 }
1259 return $ret;
1260 }
1261
1268 public function strikeIfMaxNbGenReached($ret)
1269 {
1270 // Special case to strike the date
1271 return ($this->isMaxNbGenReached() ? '<strike>' : '').$ret.($this->isMaxNbGenReached() ? '</strike>' : '');
1272 }
1273
1284 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0)
1285 {
1286 global $conf, $langs, $db, $user, $hookmanager;
1287
1288 $error = 0;
1289 $nb_create = 0;
1290
1291 // Load translation files required by the page
1292 $langs->loadLangs(array('main', 'bills'));
1293
1294 $now = dol_now();
1295 $tmparray = dol_getdate($now);
1296 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1297
1298 dol_syslog('createRecurringInvoices restrictioninvoiceid=' .$restrictioninvoiceid. ' forcevalidation=' .$forcevalidation);
1299
1300 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_fourn_rec';
1301 $sql .= ' WHERE frequency > 0'; // A recurring supplier invoice is an invoice with a frequency
1302 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1303 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1304 $sql .= ' AND suspended = 0';
1305 $sql .= ' AND entity = '. (int) $conf->entity; // MUST STAY = $conf->entity here
1306 if ($restrictioninvoiceid > 0) {
1307 $sql .= ' AND rowid = '. (int) $restrictioninvoiceid;
1308 }
1309 $sql .= $this->db->order('entity', 'ASC');
1310 //print $sql;exit;
1311 $parameters = array(
1312 'restrictioninvoiceid' => $restrictioninvoiceid,
1313 'forcevalidation' => $forcevalidation,
1314 );
1315 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1316
1317 $resql = $this->db->query($sql);
1318 if ($resql) {
1319 $i = 0;
1320 $num = $this->db->num_rows($resql);
1321
1322 if ($num) {
1323 $this->output .= $langs->trans('FoundXQualifiedRecurringInvoiceTemplate', $num)."\n";
1324 } else {
1325 $this->output .= $langs->trans('NoQualifiedRecurringInvoiceTemplateFound');
1326 }
1327
1328 $saventity = $conf->entity;
1329 $laststep = "None";
1330
1331 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1332 $line = $this->db->fetch_object($resql);
1333
1334 $this->db->begin();
1335
1336 $invoiceidgenerated = 0;
1337
1338 $new_fac_fourn = null;
1339 $facturerec = new FactureFournisseurRec($this->db);
1340 $laststep = "Fetch {$line->rowid}";
1341 $facturerec->fetch($line->rowid);
1342
1343 if ($facturerec->id > 0) {
1344 // Set entity context
1345 $conf->entity = $facturerec->entity;
1346
1347 dol_syslog('createRecurringInvoices Process invoice template id=' .$facturerec->id. ', ref=' .$facturerec->ref. ', entity=' .$facturerec->entity);
1348
1349 $new_fac_fourn = new FactureFournisseur($this->db);
1350 $new_fac_fourn->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1351 $new_fac_fourn->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1352
1353 $new_fac_fourn->type = self::TYPE_STANDARD;
1354 $new_fac_fourn->subtype = $facturerec->subtype;
1355 $new_fac_fourn->statut = self::STATUS_DRAFT; // deprecated
1356 $new_fac_fourn->status = self::STATUS_DRAFT;
1357 $new_fac_fourn->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.
1358 $new_fac_fourn->socid = $facturerec->socid;
1359 $new_fac_fourn->lines = $facturerec->lines;
1360 $new_fac_fourn->ref_supplier = $facturerec->ref_supplier;
1361 $new_fac_fourn->model_pdf = $facturerec->model_pdf;
1362 $new_fac_fourn->fk_project = $facturerec->fk_project;
1363 $new_fac_fourn->label = $facturerec->label;
1364 $new_fac_fourn->libelle = $facturerec->label; // deprecated
1365
1366 $invoiceidgenerated = $new_fac_fourn->create($user);
1367 $laststep = "Create invoiceidgenerated $invoiceidgenerated";
1368 if ($invoiceidgenerated <= 0) {
1369 $this->errors = $new_fac_fourn->errors;
1370 $this->error = $new_fac_fourn->error;
1371 $error++;
1372 }
1373 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1374 $result = $new_fac_fourn->validate($user);
1375 $laststep = "Validate by user {$user->login}";
1376 if ($result <= 0) {
1377 $this->errors = $new_fac_fourn->errors;
1378 $this->error = $new_fac_fourn->error;
1379 $error++;
1380 }
1381 }
1382
1383 if (!$error && $facturerec->generate_pdf) {
1384 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1385 $laststep = "Refresh ".$new_fac_fourn->id;
1386 $new_fac_fourn->fetch($new_fac_fourn->id);
1387 $laststep = "GenerateDocument ".$new_fac_fourn->id;
1388 $result = $new_fac_fourn->generateDocument($facturerec->model_pdf, $langs);
1389 if ($result < 0) {
1390 $this->errors = $new_fac_fourn->errors;
1391 $this->error = $new_fac_fourn->error;
1392 $error++;
1393 }
1394 }
1395 } else {
1396 $error++;
1397 $this->error = 'Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity."\n";
1398 $this->errors[] = 'Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity;
1399 dol_syslog('createRecurringInvoices Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity);
1400 }
1401
1402 if (!$error && $invoiceidgenerated >= 0) {
1403 $facturerec->nb_gen_done++;
1404 $facturerec->date_last_gen = dol_now();
1405 $facturerec->date_when = $facturerec->getNextDate();
1406 $facturerec->update($user);
1407 $this->db->commit('createRecurringInvoices Process invoice template id=' .$facturerec->id. ', title=' .$facturerec->title);
1408 dol_syslog('createRecurringInvoices Process invoice template ' .$facturerec->title. ' is finished with a success generation');
1409 $nb_create++;
1410 $this->output .= $langs->trans('InvoiceGeneratedFromTemplate', $new_fac_fourn->ref, $facturerec->title)."\n";
1411 } else {
1412 $this->db->rollback('createRecurringInvoices Process invoice template error='.$error.' invoiceidgenerated='.$invoiceidgenerated.' LastStep='.$laststep.' id=' .$facturerec->id. ', title=' .$facturerec->title);
1413 }
1414
1415 $parameters = array(
1416 'cpt' => $i,
1417 'total' => $num,
1418 'errorCount' => $error,
1419 'invoiceidgenerated' => $invoiceidgenerated,
1420 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1421 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1422 );
1423 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $new_fac_fourn); // note: $facture can be modified by hooks (warning: $facture can be null)
1424
1425 $i++;
1426 }
1427
1428 $conf->entity = $saventity; // Restore entity context
1429 } else {
1430 dol_print_error($this->db);
1431 }
1432
1433 $this->output = trim($this->output);
1434
1435 return $error ? $error : 0;
1436 }
1437
1450 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
1451 {
1452 global $langs, $hookmanager;
1453
1454 $result = '';
1455
1456 $label = '<u>'.$langs->trans('RepeatableInvoice').'</u>';
1457 if (!empty($this->ref)) {
1458 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1459 }
1460 if ($this->frequency > 0) {
1461 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1462 }
1463 if (!empty($this->date_last_gen)) {
1464 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1465 }
1466 if ($this->frequency > 0) {
1467 if (!empty($this->date_when)) {
1468 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1469 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1470 if (!empty($this->suspended)) {
1471 $label .= ' ('.$langs->trans('Disabled').')';
1472 }
1473 }
1474 }
1475
1476 $url = DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$this->id;
1477
1478 if ($short) {
1479 return $url;
1480 }
1481
1482 if ($option != 'nolink') {
1483 // Add param to save lastsearch_values or not
1484 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1485 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER['PHP_SELF'])) {
1486 $add_save_lastsearch_values = 1;
1487 }
1488 if ($add_save_lastsearch_values) {
1489 $url .= '&save_lastsearch_values=1';
1490 }
1491 }
1492
1493 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1494 $linkend = '</a>';
1495
1496 $result .= $linkstart;
1497 if ($withpicto) {
1498 $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);
1499 }
1500 if ($withpicto != 2) {
1501 $result .= $this->ref;
1502 }
1503 $result .= $linkend;
1504 global $action;
1505 $hookmanager->initHooks(array($this->element . 'dao'));
1506 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1507 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1508 if ($reshook > 0) {
1509 $result = $hookmanager->resPrint;
1510 } else {
1511 $result .= $hookmanager->resPrint;
1512 }
1513 return $result;
1514 }
1515
1523 public function getLibStatut($mode = 0, $alreadypaid = -1)
1524 {
1525 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1526 }
1527
1528 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1539 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1540 {
1541 // phpcs:enable
1542 global $langs;
1543 $langs->load('bills');
1544
1545 $labelStatus = $langs->transnoentitiesnoconv('Active');
1546 $statusType = 'status0';
1547
1548 //print "$recur,$status,$mode,$alreadypaid,$type";
1549 if ($mode == 0) {
1550 if ($recur) {
1551 if ($status == self::STATUS_SUSPENDED) {
1552 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1553 } else {
1554 $labelStatus = $langs->transnoentitiesnoconv('Active');
1555 }
1556 } else {
1557 if ($status == self::STATUS_SUSPENDED) {
1558 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1559 } else {
1560 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1561 }
1562 }
1563 } elseif ($mode == 1) {
1564 $prefix = 'Short';
1565 if ($recur) {
1566 if ($status == self::STATUS_SUSPENDED) {
1567 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1568 } else {
1569 $labelStatus = $langs->transnoentitiesnoconv('Active');
1570 }
1571 } else {
1572 if ($status == self::STATUS_SUSPENDED) {
1573 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1574 } else {
1575 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1576 }
1577 }
1578 } elseif ($mode == 2) {
1579 if ($recur) {
1580 if ($status == self::STATUS_SUSPENDED) {
1581 $statusType = 'status6';
1582 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1583 } else {
1584 $statusType = 'status4';
1585 $labelStatus = $langs->transnoentitiesnoconv('Active');
1586 }
1587 } else {
1588 if ($status == self::STATUS_SUSPENDED) {
1589 $statusType = 'status6';
1590 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1591 } else {
1592 $statusType = 'status0';
1593 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1594 }
1595 }
1596 } elseif ($mode == 3) {
1597 if ($recur) {
1598 $prefix = 'Short';
1599 if ($status == self::STATUS_SUSPENDED) {
1600 $statusType = 'status6';
1601 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1602 } else {
1603 $statusType = 'status4';
1604 $labelStatus = $langs->transnoentitiesnoconv('Active');
1605 }
1606 } else {
1607 if ($status == self::STATUS_SUSPENDED) {
1608 $statusType = 'status6';
1609 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1610 } else {
1611 $statusType = 'status0';
1612 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1613 }
1614 }
1615 } elseif ($mode == 4) {
1616 $prefix = '';
1617 if ($recur) {
1618 if ($status == self::STATUS_SUSPENDED) {
1619 $statusType = 'status6';
1620 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1621 } else {
1622 $statusType = 'status4';
1623 $labelStatus = $langs->transnoentitiesnoconv('Active');
1624 }
1625 } else {
1626 if ($status == self::STATUS_SUSPENDED) {
1627 $statusType = 'status6';
1628 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1629 } else {
1630 $statusType = 'status0';
1631 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1632 }
1633 }
1634 } elseif ($mode == 5 || $mode == 6) {
1635 $prefix = '';
1636 if ($mode == 5) {
1637 $prefix = 'Short';
1638 }
1639 if ($recur) {
1640 if ($status == self::STATUS_SUSPENDED) {
1641 $statusType = 'status6';
1642 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1643 } else {
1644 $statusType = 'status4';
1645 $labelStatus = $langs->transnoentitiesnoconv('Active');
1646 }
1647 } else {
1648 if ($status == self::STATUS_SUSPENDED) {
1649 $statusType = 'status6';
1650 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1651 } else {
1652 $statusType = 'status0';
1653 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1654 }
1655 }
1656 }
1657
1658 $labelStatusShort = $labelStatus;
1659
1660 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1661 }
1662
1671 public function initAsSpecimen($option = '')
1672 {
1673 global $user, $langs, $conf;
1674
1675 $now = dol_now();
1676 $arraynow = dol_getdate($now);
1677 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1678
1679 // Load array of products prodids
1680 $num_prods = 0;
1681 $prodids = array();
1682
1683 $sql = 'SELECT rowid';
1684 $sql .= ' FROM ' .MAIN_DB_PREFIX. 'product';
1685 $sql .= ' WHERE entity IN (' .getEntity('product'). ')';
1686 $sql .= $this->db->plimit(100);
1687
1688 $resql = $this->db->query($sql);
1689 if ($resql) {
1690 $num_prods = $this->db->num_rows($resql);
1691 $i = 0;
1692 while ($i < $num_prods) {
1693 $i++;
1694 $row = $this->db->fetch_row($resql);
1695 $prodids[$i] = $row[0];
1696 }
1697 }
1698
1699 // Initialize parameters
1700 $this->id = 0;
1701 $this->ref = 'SPECIMEN';
1702 $this->title = 'SPECIMEN';
1703 $this->specimen = 1;
1704 $this->socid = 1;
1705 $this->date = $nownotime;
1706 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1707 $this->cond_reglement_id = 1;
1708 $this->cond_reglement_code = 'RECEP';
1709 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1710 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1711 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1712 $this->note_public = 'This is a comment (public)';
1713 $this->note_private = 'This is a comment (private)';
1714 $this->note = 'This is a comment (private)';
1715 $this->fk_incoterms = 0;
1716 $this->location_incoterms = '';
1717
1718 if (empty($option) || $option != 'nolines') {
1719 // Lines
1720 $nbp = 5;
1721 $xnbp = 0;
1722 while ($xnbp < $nbp) {
1723 $line = new FactureLigne($this->db);
1724 $line->desc = $langs->trans('Description'). ' ' .$xnbp;
1725 $line->qty = 1;
1726 $line->subprice = 100;
1727 $line->tva_tx = 19.6;
1728 $line->localtax1_tx = 0;
1729 $line->localtax2_tx = 0;
1730 $line->remise_percent = 0;
1731 if ($xnbp == 1) { // Qty is negative (product line)
1732 $prodid = mt_rand(1, $num_prods);
1733 $line->fk_product = $prodids[$prodid];
1734 $line->qty = -1;
1735 $line->total_ht = -100;
1736 $line->total_ttc = -119.6;
1737 $line->total_tva = -19.6;
1738 } elseif ($xnbp == 2) { // UP is negative (free line)
1739 $line->subprice = -100;
1740 $line->total_ht = -100;
1741 $line->total_ttc = -119.6;
1742 $line->total_tva = -19.6;
1743 $line->remise_percent = 0;
1744 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1745 $prodid = mt_rand(1, $num_prods);
1746 $line->fk_product = $prodids[$prodid];
1747 $line->total_ht = 50;
1748 $line->total_ttc = 59.8;
1749 $line->total_tva = 9.8;
1750 $line->remise_percent = 50;
1751 } else { // (product line)
1752 $prodid = mt_rand(1, $num_prods);
1753 $line->fk_product = $prodids[$prodid];
1754 $line->total_ht = 100;
1755 $line->total_ttc = 119.6;
1756 $line->total_tva = 19.6;
1757 $line->remise_percent = 00;
1758 }
1759
1760 $this->lines[$xnbp] = $line;
1761 $xnbp++;
1762
1763 $this->total_ht += $line->total_ht;
1764 $this->total_tva += $line->total_tva;
1765 $this->total_ttc += $line->total_ttc;
1766 }
1767 $this->revenuestamp = 0;
1768
1769 // Add a line "offered"
1770 $line = new FactureLigne($this->db);
1771 $line->desc = $langs->trans('Description'). ' (offered line)';
1772 $line->qty = 1;
1773 $line->subprice = 100;
1774 $line->tva_tx = 19.6;
1775 $line->localtax1_tx = 0;
1776 $line->localtax2_tx = 0;
1777 $line->remise_percent = 100;
1778 $line->total_ht = 0;
1779 $line->total_ttc = 0; // 90 * 1.196
1780 $line->total_tva = 0;
1781 $prodid = mt_rand(1, $num_prods);
1782 $line->fk_product = $prodids[$prodid];
1783
1784 $this->lines[$xnbp] = $line;
1785 $xnbp++;
1786 }
1787
1788 $this->usenewprice = 0;
1789
1790 return 1;
1791 }
1792
1801 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1802 {
1803 $tables = array(
1804 'facture_fourn_rec'
1805 );
1806
1807 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1808 }
1809
1817 public function setFrequencyAndUnit($frequency, $unit)
1818 {
1819 if (!$this->table_element) {
1820 dol_syslog(get_class($this). '::setFrequencyAndUnit was called on object with property table_element not defined', LOG_ERR);
1821 return -1;
1822 }
1823
1824 if (!empty($frequency) && empty($unit)) {
1825 dol_syslog(get_class($this). '::setFrequencyAndUnit was called on object with params frequency defined but unit not defined', LOG_ERR);
1826 return -2;
1827 }
1828
1829 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1830 $sql .= " SET frequency = ".($frequency ? ((int) $frequency) : "NULL");
1831 if (!empty($unit)) {
1832 $sql .= ", unit_frequency = '".$this->db->escape($unit)."'";
1833 }
1834 $sql .= " WHERE rowid = ".((int) $this->id);
1835
1836 dol_syslog(get_class($this).'::setFrequencyAndUnit', LOG_DEBUG);
1837
1838 if ($this->db->query($sql)) {
1839 $this->frequency = $frequency;
1840 if (!empty($unit)) {
1841 $this->unit_frequency = $unit;
1842 }
1843 return 1;
1844 } else {
1845 $this->error = $this->db->lasterror();
1846 return -1;
1847 }
1848 }
1849
1857 public function setNextDate($date, $increment_nb_gen_done = 0)
1858 {
1859 if (!$this->table_element) {
1860 dol_syslog(get_class($this).'::setNextDate was called on object with property table_element not defined', LOG_ERR);
1861 return -1;
1862 }
1863 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1864 $sql .= " SET date_when = " .($date ? "'".$this->db->idate($date)."'" : "NULL");
1865 if ($increment_nb_gen_done > 0) {
1866 $sql .= ", nb_gen_done = nb_gen_done + 1";
1867 }
1868 $sql .= " WHERE rowid = " . (int) $this->id;
1869
1870 dol_syslog(get_class($this).'::setNextDate', LOG_DEBUG);
1871
1872 if ($this->db->query($sql)) {
1873 $this->date_when = $date;
1874 if ($increment_nb_gen_done > 0) {
1875 $this->nb_gen_done++;
1876 }
1877 return 1;
1878 } else {
1879 $this->error = $this->db->lasterror();
1880 return -1;
1881 }
1882 }
1883
1890 public function setMaxPeriod($nb)
1891 {
1892 if (!$this->table_element) {
1893 dol_syslog(get_class($this).'::setMaxPeriod was called on object with property table_element not defined', LOG_ERR);
1894 return -1;
1895 }
1896
1897 if (empty($nb)) {
1898 $nb = 0;
1899 }
1900
1901 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1902 $sql .= " SET nb_gen_max = ". (int) $nb;
1903 $sql .= " WHERE rowid = " . (int) $this->id;
1904
1905 dol_syslog(get_class($this).'::setMaxPeriod', LOG_DEBUG);
1906
1907 if ($this->db->query($sql)) {
1908 $this->nb_gen_max = $nb;
1909 return 1;
1910 } else {
1911 dol_print_error($this->db);
1912 return -1;
1913 }
1914 }
1915
1922 public function setAutoValidate($validate)
1923 {
1924 if (!$this->table_element) {
1925 dol_syslog(get_class($this).'::setAutoValidate was called on object with property table_element not defined', LOG_ERR);
1926 return -1;
1927 }
1928
1929 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1930 $sql .= " SET auto_validate = ".((int) $validate);
1931 $sql .= " WHERE rowid = " . (int) $this->id;
1932
1933 dol_syslog(get_class($this).'::setAutoValidate', LOG_DEBUG);
1934
1935 if ($this->db->query($sql)) {
1936 $this->auto_validate = $validate;
1937 return 1;
1938 } else {
1939 dol_print_error($this->db);
1940 return -1;
1941 }
1942 }
1943
1950 public function setGeneratePdf($validate)
1951 {
1952 if (!$this->table_element) {
1953 dol_syslog(get_class($this).'::setGeneratePdf was called on object with property table_element not defined', LOG_ERR);
1954 return -1;
1955 }
1956
1957 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1958 $sql .= " SET generate_pdf = ". (int) $validate;
1959 $sql .= " WHERE rowid = " . (int) $this->id;
1960
1961 dol_syslog(get_class($this).'::setGeneratePdf', LOG_DEBUG);
1962
1963 if ($this->db->query($sql)) {
1964 $this->generate_pdf = $validate;
1965 return 1;
1966 } else {
1967 dol_print_error($this->db);
1968 return -1;
1969 }
1970 }
1971
1978 public function setModelPdf($model)
1979 {
1980 if (!$this->table_element) {
1981 dol_syslog(get_class($this).'::setModelPdf was called on object with property table_element not defined', LOG_ERR);
1982 return -1;
1983 }
1984
1985 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1986 $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
1987 $sql .= " WHERE rowid = " . (int) $this->id;
1988
1989 dol_syslog(get_class($this).'::setModelPdf', LOG_DEBUG);
1990
1991 if ($this->db->query($sql)) {
1992 $this->model_pdf = $model;
1993 return 1;
1994 } else {
1995 dol_print_error($this->db);
1996 return -1;
1997 }
1998 }
1999}
2000
2001
2002
2008{
2012 public $element = 'invoice_supplier_det_rec';
2013
2017 public $table_element = 'facture_fourn_det_rec';
2018
2019 public $fk_facture_fourn;
2020 public $fk_parent;
2021 public $fk_product;
2022 public $ref_supplier;
2023 public $label;
2028 public $pu_ht;
2029 public $pu_ttc;
2030
2034 public $qty;
2035 public $remise_percent;
2036 public $fk_remise_except;
2037 public $vat_src_code;
2038 public $tva_tx;
2039 public $localtax1_tx;
2040 public $localtax1_type;
2041 public $localtax2_tx;
2042 public $localtax2_type;
2043
2044 public $product_type;
2045 public $date_start;
2046 public $date_end;
2047 public $info_bits;
2048
2052 public $special_code;
2053 public $rang;
2054
2055 public $fk_user_author;
2056 public $fk_user_modif;
2057
2058
2066 public function delete(User $user, $notrigger = 0)
2067 {
2068 $error = 0;
2069 $this->db->begin();
2070
2071 if (! $error) {
2072 if (! $notrigger) {
2073 // Call triggers
2074 $result = $this->call_trigger('LINESUPPLIERBILLREC_DELETE', $user);
2075 if ($result < 0) {
2076 $error++;
2077 } // Do also here what you must do to rollback action if trigger fail
2078 // End call triggers
2079 }
2080 }
2081
2082 if (! $error) {
2083 $result = $this->deleteExtraFields();
2084 if ($result < 0) {
2085 $error++;
2086 }
2087 }
2088
2089 if (! $error) {
2090 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE rowid=' . (int) $this->id;
2091
2092 $res = $this->db->query($sql);
2093 if ($res === false) {
2094 $error++;
2095 $this->errors[] = $this->db->lasterror();
2096 }
2097 }
2098
2099 // Commit or rollback
2100 if ($error) {
2101 $this->db->rollback();
2102 return -1;
2103 } else {
2104 $this->db->commit();
2105 return 1;
2106 }
2107 }
2108
2109
2116 public function fetch($rowid)
2117 {
2118 $sql = 'SELECT l.rowid,';
2119 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product,';
2120 $sql .= ' l.ref as ref_supplier, l.label, l.description as line_desc, l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except,';
2121 $sql .= ' l.vat_src_code, l.tva_tx, l.localtax1_tx, l.localtax1_type, l.localtax2_tx, l.localtax2_type,';
2122 $sql .= ' l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc,';
2123 $sql .= ' l.product_type, l.date_start, l.date_end,';
2124 $sql .= ' l.info_bits, l.special_code, l.rang, l.fk_unit, l.import_key,';
2125 $sql .= ' l.fk_user_author, l.fk_user_modif, l.fk_multicurrency,';
2126 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2127 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2128 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
2129 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2130 $sql .= ' WHERE l.rowid = '. (int) $rowid;
2131 $sql .= ' ORDER BY l.rang';
2132
2133 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2134 $result = $this->db->query($sql);
2135 if ($result) {
2136 $objp = $this->db->fetch_object($result);
2137
2138 $this->id = $objp->rowid;
2139 $this->fk_facture_fourn = $objp->fk_facture_fourn;
2140 $this->fk_parent = $objp->fk_parent_line;
2141 $this->fk_product = $objp->fk_product;
2142 $this->ref_supplier = $objp->ref_supplier;
2143 $this->label = $objp->label;
2144 $this->description = $objp->line_desc;
2145 $this->desc = $objp->line_desc;
2146 $this->pu_ht = $objp->pu_ht;
2147 $this->pu_ttc = $objp->pu_ttc;
2148 $this->qty = $objp->qty;
2149 $this->remise_percent = $objp->remise_percent;
2150 $this->fk_remise_except = $objp->fk_remise_except;
2151 $this->vat_src_code = $objp->vat_src_code;
2152 $this->tva_tx = $objp->tva_tx;
2153 $this->localtax1_tx = $objp->localtax1_tx;
2154 $this->localtax1_type = $objp->localtax1_type;
2155 $this->localtax2_tx = $objp->localtax2_tx;
2156 $this->localtax2_type = $objp->localtax2_type;
2157 $this->total_ht = $objp->total_ht;
2158 $this->total_tva = $objp->total_tva;
2159 $this->total_localtax1 = $objp->total_localtax1;
2160 $this->total_localtax2 = $objp->total_localtax2;
2161 $this->total_ttc = $objp->total_ttc;
2162 $this->product_type = $objp->product_type;
2163 $this->date_start = $objp->date_start;
2164 $this->date_end = $objp->date_end;
2165 $this->info_bits = $objp->info_bits;
2166 $this->special_code = $objp->special_code;
2167 $this->rang = $objp->rang;
2168 $this->fk_unit = $objp->fk_unit;
2169 $this->import_key = $objp->import_key;
2170 $this->fk_user_author = $objp->fk_user_author;
2171 $this->fk_user_modif = $objp->fk_user_modif;
2172 $this->fk_multicurrency = $objp->fk_multicurrency;
2173 $this->multicurrency_code = $objp->multicurrency_code;
2174 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2175 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2176 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2177 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2178
2179 $this->db->free($result);
2180 return 1;
2181 } else {
2182 $this->error = $this->db->lasterror();
2183 return -3;
2184 }
2185 }
2186
2187
2195 public function update(User $user, $notrigger = 0)
2196 {
2197 global $conf;
2198
2199 $error = 0;
2200
2201 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2202
2203 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
2204 $sql .= ' fk_facture_fourn = ' . (int) $this->fk_facture_fourn;
2205 $sql .= ', fk_parent_line = ' . (int) $this->fk_parent;
2206 $sql .= ', fk_product = ' . (int) $this->fk_product;
2207 $sql .= ', ref = ' . (!empty($this->ref) ? "'" . $this->db->escape($this->ref) . "'" : 'NULL');
2208 $sql .= ", label = " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : 'NULL');
2209 $sql .= ", description = '" . $this->db->escape($this->desc ? $this->desc : $this->description) . "'";
2210 $sql .= ', pu_ht = ' . price2num($this->pu_ht);
2211 $sql .= ', pu_ttc = ' . price2num($this->pu_ttc);
2212 $sql .= ', qty = ' . price2num($this->qty);
2213 $sql .= ", remise_percent = '" . price2num($this->remise_percent) . "'";
2214 $sql .= ', fk_remise_except = ' . (int) $this->fk_remise_except;
2215 $sql .= ", vat_src_code = '" . $this->db->escape($this->vat_src_code) . "'";
2216 $sql .= ', tva_tx = ' . price2num($this->tva_tx);
2217 $sql .= ', localtax1_tx = ' . price2num($this->localtax1_tx);
2218 $sql .= ", localtax1_type = '" . $this->db->escape($this->localtax1_type) . "'";
2219 $sql .= ', localtax2_tx = ' . price2num($this->localtax2_tx);
2220 $sql .= ", localtax2_type = '" . $this->db->escape($this->localtax2_type) . "'";
2221 if (empty($this->skip_update_total)) {
2222 $sql .= ', total_ht = ' . price2num($this->total_ht);
2223 $sql .= ', total_tva = ' . price2num($this->total_tva);
2224 $sql .= ', total_localtax1 = ' . price2num($this->total_localtax1);
2225 $sql .= ', total_localtax2 = ' . price2num($this->total_localtax2);
2226 $sql .= ', total_ttc = ' . price2num($this->total_ttc);
2227 }
2228 $sql .= ', product_type = ' . (int) $this->product_type;
2229 $sql .= ', date_start = ' . (int) $this->date_start;
2230 $sql .= ', date_end = ' . (int) $this->date_end;
2231 $sql .= ", info_bits = " . ((int) $this->info_bits);
2232 $sql .= ', special_code =' . (int) $this->special_code;
2233 $sql .= ', rang = ' . (int) $this->rang;
2234 $sql .= ', fk_unit = ' .($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : 'null');
2235 $sql .= ', fk_user_modif = ' . (int) $user->id;
2236 $sql .= ' WHERE rowid = ' . (int) $this->id;
2237
2238 $this->db->begin();
2239
2240 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
2241 $resql = $this->db->query($sql);
2242 if ($resql) {
2243 if (!$error) {
2244 $result = $this->insertExtraFields();
2245 if ($result < 0) {
2246 $error++;
2247 }
2248 }
2249
2250 if (!$error && !$notrigger) {
2251 // Call trigger
2252 $result = $this->call_trigger('LINESUPPLIERBILLREC_MODIFY', $user);
2253 if ($result < 0) {
2254 $error++;
2255 }
2256 // End call triggers
2257 }
2258
2259 if ($error) {
2260 $this->db->rollback();
2261 return -2;
2262 } else {
2263 $this->db->commit();
2264 return 1;
2265 }
2266 } else {
2267 $this->error = $this->db->lasterror();
2268 $this->db->rollback();
2269 return -2;
2270 }
2271 }
2272}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$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.
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 suppliers invoices.
Class to manage supplier invoice lines of templates.
fetch($rowid)
Get line of template invoice.
update(User $user, $notrigger=0)
Update a line to supplier invoice template .
Class to manage invoice templates.
setModelPdf($model)
Update the model for documents.
fetch($rowid, $ref='', $ref_ext='')
Load object and lines.
strikeIfMaxNbGenReached($ret)
Format string to output with by striking the string if max number of generation was reached.
setFrequencyAndUnit($frequency, $unit)
Update frequency and unit.
getNextNumRef($soc, $mode='next')
Return next reference of invoice not already used (or last reference)
create($user, $facFournId, $notrigger=0)
Create a predefined supplier invoice.
setGeneratePdf($validate)
Update the auto generate documents.
getLinesArray()
Create an array of invoice lines.
initAsSpecimen($option='')
Initialise an instance with random values.
LibStatut($recur, $status, $mode=0, $alreadypaid=-1, $type=0)
Return label of a status.
updateline($rowid, $fk_product, $ref, $label, $desc, $pu_ht, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $type=0, $date_start=0, $date_end=0, $info_bits=0, $special_code=0, $rang=-1, $fk_unit=null, $pu_ht_devise=0, $pu_ttc=0)
Update a line to supplier invoice template.
isMaxNbGenReached()
Return if maximum number of generation is reached.
setAutoValidate($validate)
Update the auto validate flag of invoice.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getNextDate()
Return the next date of.
fetch_lines()
Get lines of template invoices into this->lines.
getLibStatut($mode=0, $alreadypaid=-1)
Return label of object status.
setNextDate($date, $increment_nb_gen_done=0)
Update the next date of execution.
setMaxPeriod($nb)
Update the maximum period.
createRecurringInvoices($restrictioninvoiceid=0, $forcevalidation=0)
Create all recurrents supplier invoices (for all entities if multicompany is used).
update(User $user, $notrigger=0)
Update fourn_invoice_rec.
addline($fk_product, $ref, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $type=0, $date_start=0, $date_end=0, $info_bits=0, $special_code=0, $rang=-1, $fk_unit=null, $pu_ht_devise=0)
Add a line to recursive supplier invoice.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $moretitle='', $notooltip=0, $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
Class to manage invoice lines.
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:124
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)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
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_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...
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:139