dolibarr 19.0.4
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-2020 Frédéric France <frederic.france@netlogic.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35
36
41{
42 const TRIGGER_PREFIX = 'SUPPLIERBILLREC';
46 public $element = 'invoice_supplier_rec';
47
51 public $table_element = 'facture_fourn_rec';
52
56 public $table_element_line = 'facture_fourn_det_rec';
57
61 public $fk_element = 'fk_facture_fourn';
62
66 public $picto = 'bill';
67
71 protected $table_ref_field = 'titre';
72
77 public $titre;
81 public $title;
82
83 public $ref_supplier;
84 public $socid;
85
89 public $fk_soc;
90
91 public $suspended; // status
92
97 public $libelle;
101 public $label;
102
107 public $amount;
112 public $remise;
113
114 public $vat_src_code;
115 public $localtax1;
116 public $localtax2;
117
118 public $user_author;
119 public $user_modif;
120 public $fk_project;
121
122 public $mode_reglement_id;
123 public $mode_reglement_code;
124 public $cond_reglement_code;
125 public $cond_reglement_doc;
126 public $cond_reglement_id;
127
128 public $date_lim_reglement;
129
130 public $usenewprice = 0;
131 public $frequency;
132 public $unit_frequency;
133 public $date_when;
134 public $date_last_gen;
135 public $nb_gen_done;
136 public $nb_gen_max;
137 public $auto_validate; // 0 to create in draft, 1 to create and validate the new invoice
138 public $generate_pdf; // 1 to generate PDF on invoice generation (default)
139
140 public $model_pdf;
141
146 public $lines = array();
147
148
149 /* Override fields in CommonObject
150 public $entity;
151 public $date_creation;
152 public $date_modification;
153 public $total_ht;
154 public $total_tva;
155 public $total_ttc;
156 public $fk_account;
157 public $mode_reglement;
158 public $cond_reglement;
159 public $note_public;
160 public $note_private;
161 */
162
187 // BEGIN MODULEBUILDER PROPERTIES
191 public $fields = array(
192 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),
193 'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15),
194 'ref_supplier' =>array('type'=>'varchar(180)', 'label'=>'RefSupplier', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>20),
195 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25, 'index'=>1),
196 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>30),
197 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>35),
198 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>40),
199 'suspended' =>array('type'=>'integer', 'label'=>'Suspended', 'enabled'=>1, 'visible'=>-1, 'position'=>225),
200 'libelle' =>array('type'=>'varchar(100)', 'label'=>'Libelle', 'enabled'=>1, 'showoncombobox' => 0, 'visible'=>-1, 'position'=>15),
201
202 'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1),
203 'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1),
204 'total_ht' =>array('type'=>'double(24,8)', 'label'=>'Total', 'enabled'=>1, 'visible'=>-1, 'position'=>70, 'isameasure'=>1),
205 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1),
206 'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>75, 'isameasure'=>1),
207
208 'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>80),
209 'fk_user_modif' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>210),
210 '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),
211 'fk_account' =>array('type'=>'integer', 'label'=>'Fk account', 'enabled'=>'isModEnabled("banque")', 'visible'=>-1, 'position'=>175),
212 'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Fk cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>90),
213 'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'Fk mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>95),
214 'date_lim_reglement' =>array('type'=>'date', 'label'=>'Date lim reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>100),
215
216 'note_private' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>105),
217 'note_public' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>110),
218 'modelpdf' =>array('type'=>'varchar(255)', 'label'=>'Modelpdf', 'enabled'=>1, 'visible'=>-1, 'position'=>115),
219
220 'fk_multicurrency' =>array('type'=>'integer', 'label'=>'Fk multicurrency', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
221 'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'Multicurrency code', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
222 'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency tx', 'enabled'=>1, 'visible'=>-1, 'position'=>190, 'isameasure'=>1),
223 'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ht', 'enabled'=>1, 'visible'=>-1, 'position'=>195, 'isameasure'=>1),
224 'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total tva', 'enabled'=>1, 'visible'=>-1, 'position'=>200, 'isameasure'=>1),
225 'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'Multicurrency total ttc', 'enabled'=>1, 'visible'=>-1, 'position'=>205, 'isameasure'=>1),
226
227 'usenewprice' =>array('type'=>'integer', 'label'=>'UseNewPrice', 'enabled'=>1, 'visible'=>0, 'position'=>155),
228 'frequency' =>array('type'=>'integer', 'label'=>'Frequency', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
229 'unit_frequency' =>array('type'=>'varchar(2)', 'label'=>'Unit frequency', 'enabled'=>1, 'visible'=>-1, 'position'=>125),
230
231 'date_when' =>array('type'=>'datetime', 'label'=>'Date when', 'enabled'=>1, 'visible'=>-1, 'position'=>130),
232 'date_last_gen' =>array('type'=>'datetime', 'label'=>'Date last gen', 'enabled'=>1, 'visible'=>-1, 'position'=>135),
233 'nb_gen_done' =>array('type'=>'integer', 'label'=>'Nb gen done', 'enabled'=>1, 'visible'=>-1, 'position'=>140),
234 'nb_gen_max' =>array('type'=>'integer', 'label'=>'Nb gen max', 'enabled'=>1, 'visible'=>-1, 'position'=>145),
235 'revenuestamp' =>array('type'=>'double(24,8)', 'label'=>'RevenueStamp', 'enabled'=>1, 'visible'=>-1, 'position'=>160, 'isameasure'=>1),
236 'auto_validate' =>array('type'=>'integer', 'label'=>'Auto validate', 'enabled'=>1, 'visible'=>-1, 'position'=>165),
237 'generate_pdf' =>array('type'=>'integer', 'label'=>'Generate pdf', 'enabled'=>1, 'visible'=>-1, 'position'=>170),
238
239 );
240 // END MODULEBUILDER PROPERTIES
241
242 const STATUS_NOTSUSPENDED = 0;
243 const STATUS_SUSPENDED = 1;
244
245
246
252 public function __construct($db)
253 {
254 $this->db = $db;
255 }
256
265 public function create($user, $facFournId, $notrigger = 0)
266 {
267 global $conf;
268
269 $error = 0;
270 $now = dol_now();
271
272 // Clean parameters
273 $this->titre = empty($this->titre) ? '' : $this->titre; // deprecated
274 $this->title = empty($this->title) ? '' : $this->title;
275 $keyforref = $this->table_ref_field;
276 $this->ref = $this->$keyforref;
277 $this->ref_supplier = empty($this->ref_supplier) ? '' : $this->ref_supplier;
278 $this->usenewprice = empty($this->usenewprice) ? 0 : $this->usenewprice;
279 $this->suspended = empty($this->suspended) ? 0 : $this->suspended;
280 // No frequency defined then no next date to execution
281 if (empty($this->frequency)) {
282 $this->frequency = 0;
283 $this->date_when = null;
284 }
285 $this->frequency = abs($this->frequency);
286 $this->nb_gen_done = 0;
287 $this->nb_gen_max = empty($this->nb_gen_max) ? 0 : $this->nb_gen_max;
288 $this->auto_validate = empty($this->auto_validate) ? 0 : $this->auto_validate;
289 $this->generate_pdf = empty($this->generate_pdf) ? 0 : $this->generate_pdf;
290
291 $this->db->begin();
292
293 // On charge la facture fournisseur depuis laquelle on crée la facture fournisseur modèle
294 $facfourn_src = new FactureFournisseur($this->db);
295 $result = $facfourn_src->fetch($facFournId);
296 if ($result > 0) {
297 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_rec (';
298 $sql .= 'titre';
299 $sql .= ', ref_supplier';
300 $sql .= ', entity';
301 $sql .= ', fk_soc';
302 $sql .= ', datec';
303 $sql .= ', suspended';
304 $sql .= ', libelle';
305 $sql .= ', total_ttc';
306 $sql .= ', fk_user_author';
307 $sql .= ', fk_projet';
308 $sql .= ', fk_account';
309 $sql .= ', fk_cond_reglement';
310 $sql .= ', fk_mode_reglement';
311 $sql .= ', date_lim_reglement';
312 $sql .= ', note_private';
313 $sql .= ', note_public';
314 $sql .= ', modelpdf';
315 $sql .= ', fk_multicurrency';
316 $sql .= ', multicurrency_code';
317 $sql .= ', multicurrency_tx';
318 $sql .= ', usenewprice';
319 $sql .= ', frequency';
320 $sql .= ', unit_frequency';
321 $sql .= ', date_when';
322 $sql .= ', date_last_gen';
323 $sql .= ', nb_gen_done';
324 $sql .= ', nb_gen_max';
325 $sql .= ', auto_validate';
326 $sql .= ', generate_pdf';
327 $sql .= ') VALUES (';
328 $sql .= "'".$this->db->escape($this->title)."'";
329 $sql .= ", '".$this->db->escape($this->ref_supplier)."'";
330 $sql .= ", ".((int) $conf->entity);
331 $sql .= ", ".((int) $facfourn_src->socid);
332 $sql .= ", '".$this->db->idate($now)."'";
333 $sql .= ", ".((int) $this->suspended);
334 $sql .= ", '".$this->db->escape($this->libelle)."'";
335 $sql .= ", " .(!empty($facfourn_src->total_ttc) ? (float) $facfourn_src->total_ttc : '0'); // amount
336 $sql .= ", " .((int) $user->id);
337 $sql .= ", " .(!empty($this->fk_project) ? ((int) $this->fk_project) : 'NULL');
338 $sql .= ", " .(!empty($facfourn_src->fk_account) ? ((int) $facfourn_src->fk_account) : 'NULL');
339 $sql .= ", " .($this->cond_reglement_id > 0 ? (int) $this->cond_reglement_id : 'NULL');
340 $sql .= ", " .($this->mode_reglement_id > 0 ? (int) $this->mode_reglement_id : 'NULL');
341 $sql .= ", ".($facfourn_src->date_echeance > 0 ? "'".$this->db->idate($facfourn_src->date_echeance)."'" : 'NULL'); // date_lim_reglement
342 $sql .= ", " .(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : 'NULL');
343 $sql .= ", " .(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : 'NULL');
344 $sql .= ", " .(!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : 'NULL');
345 $sql .= ", " . (int) $facfourn_src->fk_multicurrency;
346 $sql .= ", '".$this->db->escape($facfourn_src->multicurrency_code)."'";
347 $sql .= ", " . (float) $facfourn_src->multicurrency_tx;
348 $sql .= ", " . (int) $this->usenewprice;
349 $sql .= ", " . (int) $this->frequency;
350 $sql .= ", '".$this->db->escape($this->unit_frequency)."'";
351 $sql .= ", " .(!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL');
352 $sql .= ", " .(!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL');
353 $sql .= ", " . (int) $this->nb_gen_done;
354 $sql .= ", " . (int) $this->nb_gen_max;
355 $sql .= ", " . (int) $this->auto_validate;
356 $sql .= ", " . (int) $this->generate_pdf;
357 $sql .= ')';
358
359 if ($this->db->query($sql)) {
360 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX. 'facture_fourn_rec');
361
362 // Fields used into addline later
363 $this->fk_multicurrency = $facfourn_src->fk_multicurrency;
364
365 $this->multicurrency_code = $facfourn_src->multicurrency_code;
366 $this->multicurrency_tx = $facfourn_src->multicurrency_tx;
367
368 // Add lines
369 $num = count($facfourn_src->lines);
370 for ($i = 0; $i < $num; $i++) {
371 $tva_tx = $facfourn_src->lines[$i]->tva_tx;
372 if (!empty($facfourn_src->lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
373 $tva_tx .= ' ('.$facfourn_src->lines[$i]->vat_src_code.')';
374 }
375
376 $result_insert = $this->addline(
377 $facfourn_src->lines[$i]->fk_product,
378 $facfourn_src->lines[$i]->ref_supplier,
379 $facfourn_src->lines[$i]->label,
380 $facfourn_src->lines[$i]->description,
381 $facfourn_src->lines[$i]->pu_ht,
382 $facfourn_src->lines[$i]->pu_ttc,
383 $facfourn_src->lines[$i]->qty,
384 $facfourn_src->lines[$i]->remise_percent,
385 $tva_tx,
386 $facfourn_src->lines[$i]->localtax1_tx,
387 $facfourn_src->lines[$i]->localtax2_tx,
388 'HT',
389 $facfourn_src->lines[$i]->product_type,
390 $facfourn_src->lines[$i]->date_start,
391 $facfourn_src->lines[$i]->date_end,
392 $facfourn_src->lines[$i]->info_bits,
393 $facfourn_src->lines[$i]->special_code,
394 $facfourn_src->lines[$i]->rang,
395 $facfourn_src->lines[$i]->fk_unit
396 );
397
398 if ($result_insert < 0) {
399 $error++;
400 } else {
401 $objectline = new FactureFournisseurLigneRec($this->db);
402
403 $result2 = $objectline->fetch($result_insert);
404 if ($result2 > 0) {
405 // Extrafields
406 if (method_exists($facfourn_src->lines[$i], 'fetch_optionals')) {
407 $facfourn_src->lines[$i]->fetch_optionals($facfourn_src->lines[$i]->id);
408 $objectline->array_options = $facfourn_src->lines[$i]->array_options;
409 }
410
411 $result = $objectline->insertExtraFields();
412 if ($result < 0) {
413 $error++;
414 }
415 } elseif ($result2 < 0) {
416 $this->errors[] = $objectline->error;
417 $error++;
418 }
419 }
420 }
421
422 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
423 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
424 }
425
426 // Add object linked
427 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
428 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
429 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, ...))
430 foreach ($tmp_origin_id as $origin_id) {
431 $ret = $this->add_object_linked($origin, $origin_id);
432 if (!$ret) {
433 $this->error = $this->db->lasterror();
434 $error++;
435 }
436 }
437 } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1))
438 $origin_id = $tmp_origin_id;
439 $ret = $this->add_object_linked($origin, $origin_id);
440 if (!$ret) {
441 $this->error = $this->db->lasterror();
442 $error++;
443 }
444 }
445 }
446 }
447
448 if (!$error) {
449 $result = $this->insertExtraFields();
450 if ($result < 0) {
451 $error++;
452 }
453 }
454
455 if (!$error && !$notrigger) {
456 // Call trigger
457 $result = $this->call_trigger('SUPPLIERBILLREC_CREATE', $user);
458 if ($result < 0) {
459 $this->db->rollback();
460 return -2;
461 }
462 // End call triggers
463 }
464
465 if ($error) {
466 $this->db->rollback();
467 return -3;
468 } else {
469 $this->db->commit();
470 return $this->id;
471 }
472 } else {
473 $this->error = $this->db->lasterror();
474 $this->db->rollback();
475 return -2;
476 }
477 } else {
478 $this->db->rollback();
479 return -1;
480 }
481 }
482
483
491 public function update(User $user, $notrigger = 0)
492 {
493 $error = 0;
494
495 $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_rec SET";
496 $sql .= " titre = '" . (!empty($this->title) ? $this->db->escape($this->title) : "")."'," ;
497 $sql .= " ref_supplier = '". (!empty($this->ref_supplier) ? $this->db->escape($this->ref_supplier) : "")."',";
498 $sql .= " entity = ". (!empty($this->entity) ? ((int) $this->entity) : 1) . ',';
499 if (!empty($this->socid) && $this->socid > 0) {
500 $sql .= " fk_soc = ". ((int) $this->socid). ',';
501 } elseif (!empty($this->fk_soc) && $this->fk_soc > 0) { // For backward compatibility
502 $sql .= " fk_soc = ". ((int) $this->fk_soc). ',';
503 }
504 $sql .= " suspended = ". (!empty($this->suspended) ? ((int) $this->suspended) : 0) . ',';
505 $sql .= " libelle = ". (!empty($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : 'NULL') . ",";
506 $sql .= " vat_src_code = ". (!empty($this->vat_src_code) ? "'".$this->db->escape($this->vat_src_code)."'" : 'NULL') . ',';
507 $sql .= " localtax1 = ". (!empty($this->localtax1) ? ((float) $this->localtax1) : 0.00) . ',';
508 $sql .= " localtax2 = ". (!empty($this->localtax2) ? ((float) $this->localtax2) : 0.00) . ',';
509 $sql .= " total_ht = ". (!empty($this->total_ht) ? ((float) $this->total_ht) : 0.00) . ',';
510 $sql .= " total_tva = ". (!empty($this->total_tva) ? ((float) $this->total_tva) : 0.00) . ',';
511 $sql .= " total_ttc = ". (!empty($this->total_ttc) ? ((float) $this->total_ttc) : 0.00) . ',';
512 $sql .= " fk_user_modif = ". ((int) $user->id) . ',';
513 $sql .= " fk_projet = ". (!empty($this->fk_project) ? ((int) $this->fk_project) : 'NULL') . ',';
514 $sql .= " fk_account = ". (!empty($this->fk_account) ? ((int) $this->fk_account) : 'NULL') . ',';
515 $sql .= " fk_mode_reglement = ". (!empty($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) : 'NULL') . ',';
516 $sql .= " fk_cond_reglement = ". (!empty($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) : 'NULL') . ',';
517 $sql .= " date_lim_reglement = ". (!empty($this->date_lim_reglement) ? "'".$this->db->idate($this->date_lim_reglement)."'" : 'NULL') . ',';
518 $sql .= " note_private = '". (!empty($this->note_private) ? $this->db->escape($this->note_private) : '') . "',";
519 $sql .= " note_public = '". (!empty($this->note_public) ? $this->db->escape($this->note_public) : '') . "',";
520 $sql .= " modelpdf = ". (!empty($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : 'NULL') . ",";
521 $sql .= " fk_multicurrency = ". (!empty($this->fk_multicurrency) ? ((int) $this->fk_multicurrency) : 'NULL') . ',';
522 $sql .= " multicurrency_code = ". (!empty($this->multicurrency_code) ? "'".$this->db->escape($this->multicurrency_code)."'" : 'NULL') . ",";
523 $sql .= " multicurrency_tx = ". (!empty($this->multicurrency_tx) ? ((float) $this->multicurrency_tx) : 1) . ',';
524 $sql .= " multicurrency_total_ht = ". (!empty($this->multicurrency_total_ht) ? ((float) $this->multicurrency_total_ht) : 0.00) . ',';
525 $sql .= " multicurrency_total_tva = ". (!empty($this->multicurrency_total_tva) ? ((float) $this->multicurrency_total_tva) : 0.00) . ',';
526 $sql .= " multicurrency_total_ttc = ". (!empty($this->multicurrency_total_ttc) ? ((float) $this->multicurrency_total_ttc) : 0.00) . ',';
527 $sql .= " usenewprice = ". (!empty($this->usenewprice) ? ((int) $this->usenewprice) : 0) . ',';
528 $sql .= " frequency = ". (!empty($this->frequency) ? ((int) $this->frequency) : 0). ',';
529 $sql .= " unit_frequency = '". (!empty($this->unit_frequency) ? $this->db->escape($this->unit_frequency) : ''). "',";
530 $sql .= " date_when = ". (!empty($this->date_when) ? "'".$this->db->idate($this->date_when)."'" : 'NULL') . ',';
531 $sql .= " date_last_gen = ". (!empty($this->date_last_gen) ? "'".$this->db->idate($this->date_last_gen)."'" : 'NULL') . ',';
532 $sql .= " nb_gen_done = ". (!empty($this->nb_gen_done) ? ((int) $this->nb_gen_done) : 0) . ',';
533 $sql .= " nb_gen_max = ". (!empty($this->nb_gen_max) ? ((int) $this->nb_gen_max) : 0) . ',';
534 $sql .= " auto_validate = ". (!empty($this->auto_validate) ? ((int) $this->auto_validate) : 0);
535 $sql .= " WHERE rowid = ". (int) $this->id;
536
537 $this->db->begin();
538
539 dol_syslog(get_class($this)."::update", LOG_DEBUG);
540 $resql = $this->db->query($sql);
541 if ($resql) {
542 if (!$error) {
543 $result = $this->insertExtraFields();
544 if ($result < 0) {
545 $error++;
546 }
547 }
548
549 if (!$error && !$notrigger) {
550 // Call trigger
551 $result = $this->call_trigger('SUPPLIERBILLREC_MODIFY', $user);
552 if ($result < 0) {
553 $this->db->rollback();
554 return -2;
555 }
556 // End call triggers
557 }
558 $this->db->commit();
559 return 1;
560 } else {
561 $this->error = $this->db->lasterror();
562 $this->db->rollback();
563 return -2;
564 }
565 }
566
575 public function fetch($rowid, $ref = '', $ref_ext = '')
576 {
577 $sql = 'SELECT f.rowid, f.titre as title, f.ref_supplier, f.entity, f.fk_soc';
578 $sql .= ', f.datec, f.tms, f.suspended';
579 $sql .= ', f.libelle as label';
580 $sql .= ', f.vat_src_code, f.localtax1, f.localtax2';
581 $sql .= ', f.total_tva, f.total_ht, f.total_ttc';
582 $sql .= ', f.fk_user_author, f.fk_user_modif';
583 $sql .= ', f.fk_projet as fk_project, f.fk_account';
584 $sql .= ', f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
585 $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';
586 $sql .= ', f.date_lim_reglement';
587 $sql .= ', f.note_private, f.note_public, f.modelpdf as model_pdf';
588 $sql .= ', f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc';
589 $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';
590 $sql .= ', f.generate_pdf';
591 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_rec as f';
592 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid';
593 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id';
594 $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')';
595 if ($rowid) {
596 $sql .= ' AND f.rowid='. (int) $rowid;
597 } elseif ($ref) {
598 $sql .= " AND f.titre='".$this->db->escape($ref)."'";
599 } else {
600 $sql .= ' AND f.rowid = 0';
601 }
602
603 $result = $this->db->query($sql);
604 if ($result) {
605 if ($this->db->num_rows($result)) {
606 $obj = $this->db->fetch_object($result);
607
608 $keyforref = $this->table_ref_field;
609
610 $this->id = $obj->rowid;
611 $this->titre = $obj->title;
612 $this->title = $obj->title;
613 $this->ref = $obj->title;
614 $this->ref_supplier = $obj->ref_supplier;
615 $this->entity = $obj->entity;
616 $this->socid = $obj->fk_soc;
617 $this->date_creation = $obj->datec;
618 $this->date_modification = $obj->tms;
619 $this->suspended = $obj->suspended;
620 $this->libelle = $obj->label;
621 $this->label = $obj->label;
622 $this->vat_src_code = $obj->vat_src_code;
623 $this->total_localtax1 = $obj->localtax1;
624 $this->total_localtax2 = $obj->localtax2;
625 $this->total_ht = $obj->total_ht;
626 $this->total_tva = $obj->total_tva;
627 $this->total_ttc = $obj->total_ttc;
628 $this->user_author = $obj->fk_user_author;
629 $this->user_modif = $obj->fk_user_modif;
630 $this->fk_project = $obj->fk_project;
631 $this->fk_account = $obj->fk_account;
632 $this->mode_reglement_id = $obj->fk_mode_reglement;
633 $this->mode_reglement_code = $obj->mode_reglement_code;
634 $this->mode_reglement = $obj->mode_reglement_libelle;
635 $this->cond_reglement_id = $obj->fk_cond_reglement;
636 $this->cond_reglement_code = $obj->cond_reglement_code;
637 $this->cond_reglement = $obj->cond_reglement_libelle;
638 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
639 $this->date_lim_reglement = $this->db->jdate($obj->date_lim_reglement);
640 $this->note_private = $obj->note_private;
641 $this->note_public = $obj->note_public;
642 $this->model_pdf = $obj->model_pdf;
643
644 // Multicurrency
645 $this->fk_multicurrency = $obj->fk_multicurrency;
646 $this->multicurrency_code = $obj->multicurrency_code;
647 $this->multicurrency_tx = $obj->multicurrency_tx;
648 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
649 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
650 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
651
652 $this->usenewprice = $obj->usenewprice;
653 $this->frequency = $obj->frequency;
654 $this->unit_frequency = $obj->unit_frequency;
655 $this->date_when = $this->db->jdate($obj->date_when);
656 $this->date_last_gen = $this->db->jdate($obj->date_last_gen);
657 $this->nb_gen_done = $obj->nb_gen_done;
658 $this->nb_gen_max = $obj->nb_gen_max;
659 $this->auto_validate = $obj->auto_validate;
660 $this->generate_pdf = $obj->generate_pdf;
661
662 // Retrieve all extrafield
663 // fetch optionals attributes and labels
664 $this->fetch_optionals();
665
666 /*
667 * Lines
668 */
669 $result = $this->fetch_lines();
670 if ($result < 0) {
671 $this->error = $this->db->lasterror();
672 return -3;
673 }
674 return 1;
675 } else {
676 $this->error = 'Bill with id '.$rowid.' or ref '.$ref.' not found';
677 dol_syslog('Facture::Fetch Error '.$this->error, LOG_ERR);
678 return -2;
679 }
680 } else {
681 $this->error = $this->db->error();
682 return -1;
683 }
684 }
685
686
692 public function getLinesArray()
693 {
694 return $this->fetch_lines();
695 }
696
697 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
703 public function fetch_lines()
704 {
705 // phpcs:enable
706 $this->lines = array();
707
708 // Retrieve all extrafield for line
709 // fetch optionals attributes and labels
710 /*if (!is_object($extrafields)) {
711 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
712 $extrafields = new ExtraFields($this->db);
713 }
714 $extrafields->fetch_name_optionals_label($this->table_element_line, true);
715 */
716
717 $sql = 'SELECT l.rowid,';
718 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product, l.ref as ref_supplier, l.label, l.description,';
719 $sql .= ' l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except, l.vat_src_code, l.tva_tx,';
720 $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type,';
721 $sql .= ' l.total_ht, l.total_tva, l.total_ttc, total_localtax1, total_localtax2,';
722 $sql .= ' l.product_type, l.date_start, l.date_end,';
723 $sql .= ' l.info_bits, l.special_code, l.rang,';
724 $sql .= ' l.fk_unit, l.import_key, l.fk_user_author, l.fk_user_modif,';
725 $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
726 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
727 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
728 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
729 $sql .= ' WHERE l.fk_facture_fourn = '. (int) $this->id;
730 $sql .= ' ORDER BY l.rang';
731
732 dol_syslog('FactureFournisseurRec::fetch_lines', LOG_DEBUG);
733
734 $result = $this->db->query($sql);
735 if ($result) {
736 $num = $this->db->num_rows($result);
737 $i = 0;
738 while ($i < $num) {
739 $objp = $this->db->fetch_object($result);
740
741 $line = new FactureFournisseurLigneRec($this->db);
742
743 $line->id = $objp->rowid;
744 $line->fk_facture_fourn = $objp->fk_facture_fourn;
745 $line->fk_parent = $objp->fk_parent_line;
746 $line->fk_product = $objp->fk_product;
747 $line->ref = $objp->product_ref; // Ref of product
748 $line->product_ref = $objp->product_ref; // Ref of product
749 $line->product_label = $objp->product_label;
750 $line->product_desc = $objp->product_desc;
751 $line->ref_supplier = $objp->ref_supplier;
752 $line->label = $objp->label;
753 $line->description = $objp->description;
754 $line->pu_ht = $objp->pu_ht;
755 $line->subprice = $objp->pu_ht;
756 $line->pu_ttc = $objp->pu_ttc;
757 $line->qty = $objp->qty;
758 $line->remise_percent = $objp->remise_percent;
759 $line->fk_remise_except = $objp->fk_remise_except;
760 $line->vat_src_code = $objp->vat_src_code;
761 $line->tva_tx = $objp->tva_tx;
762 $line->localtax1_tx = $objp->localtax1_tx;
763 $line->localtax1_type = $objp->localtax1_type;
764 $line->localtax2_tx = $objp->localtax2_tx;
765 $line->localtax2_type = $objp->localtax2_type;
766 $line->total_ht = $objp->total_ht;
767 $line->total_tva = $objp->total_tva;
768 $line->total_localtax1 = $objp->total_localtax1;
769 $line->total_localtax2 = $objp->total_localtax2;
770 $line->total_ttc = $objp->total_ttc;
771 $line->product_type = $objp->product_type;
772 $line->date_start = $this->db->jdate($objp->date_start);
773 $line->date_end = $this->db->jdate($objp->date_end);
774 $line->info_bits = $objp->info_bits ;
775 $line->special_code = $objp->special_code;
776 $line->rang = $objp->rang;
777 $line->fk_unit = $objp->fk_unit;
778 $line->import_key = $objp->import_key;
779 $line->fk_user_author = $objp->fk_user_author;
780 $line->fk_user_modif = $objp->fk_user_modif;
781 $line->fk_multicurrency = $objp->fk_multicurrency;
782 $line->multicurrency_code = $objp->multicurrency_code;
783 $line->multicurrency_subprice = $objp->multicurrency_subprice;
784 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
785 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
786 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
787
788 $line->fetch_optionals();
789
790 $this->lines[$i] = $line;
791
792 $i++;
793 }
794
795 $this->db->free($result);
796 return 1;
797 } else {
798 $this->error = $this->db->lasterror();
799 return -3;
800 }
801 }
802
803
812 public function delete(User $user, $notrigger = 0, $idwarehouse = -1)
813 {
814 $rowid = $this->id;
815
816 dol_syslog(get_class($this)."::delete rowid=".((int) $rowid), LOG_DEBUG);
817
818 $error = 0;
819 $this->db->begin();
820
821 $main = MAIN_DB_PREFIX.'facture_fourn_det_rec';
822 $ef = $main."_extrafields";
823
824 $sqlef = "DELETE FROM ".$ef." WHERE fk_object IN (SELECT rowid FROM ".$main." WHERE fk_facture_fourn = ". (int) $rowid .")";
825 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_det_rec WHERE fk_facture_fourn = ". (int) $rowid;
826
827 if ($this->db->query($sqlef) && $this->db->query($sql)) {
828 $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_fourn_rec WHERE rowid = ". (int) $rowid;
829 dol_syslog($sql);
830 if ($this->db->query($sql)) {
831 // Delete linked object
832 $res = $this->deleteObjectLinked();
833 if ($res < 0) {
834 $error = -3;
835 }
836 // Delete extrafields
837 $res = $this->deleteExtraFields();
838 if ($res < 0) {
839 $error = -4;
840 }
841 } else {
842 $this->error = $this->db->lasterror();
843 $error = -1;
844 }
845 } else {
846 $this->error = $this->db->lasterror();
847 $error = -2;
848 }
849 if (!$error && !$notrigger) {
850 // Call trigger
851 $result = $this->call_trigger('SUPPLIERBILLREC_DELETE', $user);
852 if ($result < 0) {
853 $error++;
854 }
855 // End call triggers
856 }
857 if (! $error) {
858 $this->db->commit();
859 return 1;
860 } else {
861 $this->db->rollback();
862 return $error;
863 }
864 }
865
892 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)
893 {
894 global $mysoc, $user;
895
896 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
897
898 $facid = $this->id; //Supplier invoice template ID linked to
899
900 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);
901
902 // Check if object of the line is product or service
903 if ($type < 0) {
904 return -1;
905 }
906
907 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
908
909 // Clean vat code
910 $reg = array();
911 $vat_src_code = '';
912 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
913 $vat_src_code = $reg[1];
914 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
915 }
916
917 // Clean parameters
918 $fk_product = empty($fk_product) ? 0 : $fk_product;
919 $label = empty($label) ? '' : $label;
920 $remise_percent = empty($remise_percent) ? 0 : price2num($remise_percent);
921 $qty = price2num($qty);
922 $pu_ht = price2num($pu_ht);
923 $pu_ttc = price2num($pu_ttc);
924 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
925 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
926 }
927 $txlocaltax1 = price2num($txlocaltax1);
928 $txlocaltax2 = price2num($txlocaltax2);
929 $txtva = !empty($txtva) ? $txtva : 0;
930 $txlocaltax1 = !empty($txlocaltax1) ? $txlocaltax1 : 0;
931 $txlocaltax2 = !empty($txlocaltax2) ? $txlocaltax2 : 0;
932 $info_bits = !empty($info_bits) ? $info_bits : 0;
933 $info_bits = !empty($info_bits) ? $info_bits : 0;
934 $pu = $price_base_type == 'HT' ? $pu_ht : $pu_ttc;
935
936 // Calcul du total TTC et de la TVA pour la ligne a partir de qty, pu, remise_percent et txtva
937 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
938 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
939
940 $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);
941 $total_ht = $tabprice[0];
942 $total_tva = $tabprice[1];
943 $total_ttc = $tabprice[2];
944 $total_localtax1 = $tabprice[9];
945 $total_localtax2 = $tabprice[10];
946 $pu_ht = $tabprice[3];
947
948 // MultiCurrency
949 $multicurrency_total_ht = $tabprice[16];
950 $multicurrency_total_tva = $tabprice[17];
951 $multicurrency_total_ttc = $tabprice[18];
952 $pu_ht_devise = $tabprice[19];
953
954 $this->db->begin();
955 $product_type = $type;
956 if ($fk_product) {
957 $product = new Product($this->db);
958 $result = $product->fetch($fk_product);
959 if ($result < 0) {
960 return -1;
961 }
962 $product_type = $product->type;
963 if (empty($label)) {
964 $label = $product->label;
965 }
966 }
967
968 $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec (';
969 $sql .= 'fk_facture_fourn';
970 $sql .= ', fk_product';
971 $sql .= ', ref';
972 $sql .= ', label';
973 $sql .= ', description';
974 $sql .= ', pu_ht';
975 $sql .= ', pu_ttc';
976 $sql .= ', qty';
977 $sql .= ', remise_percent';
978 $sql .= ', fk_remise_except';
979 $sql .= ', vat_src_code';
980 $sql .= ', tva_tx';
981 $sql .= ', localtax1_tx';
982 $sql .= ', localtax1_type';
983 $sql .= ', localtax2_tx';
984 $sql .= ', localtax2_type';
985 $sql .= ', total_ht';
986 $sql .= ', total_tva';
987 $sql .= ', total_localtax1';
988 $sql .= ', total_localtax2';
989 $sql .= ', total_ttc';
990 $sql .= ', product_type';
991 $sql .= ', date_start';
992 $sql .= ', date_end';
993 $sql .= ', info_bits';
994 $sql .= ', special_code';
995 $sql .= ', rang';
996 $sql .= ', fk_unit';
997 $sql .= ', fk_user_author';
998 $sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
999 $sql .= ') VALUES (';
1000 $sql .= ' ' . (int) $facid; // source supplier invoice id
1001 $sql .= ', ' . (!empty($fk_product) ? "'" . $this->db->escape($fk_product) . "'" : 'null');
1002 $sql .= ', ' . (!empty($ref) ? "'" . $this->db->escape($ref) . "'" : 'null');
1003 $sql .= ', ' . (!empty($label) ? "'" . $this->db->escape($label) . "'" : 'null');
1004 $sql .= ", '" . $this->db->escape($desc) . "'";
1005 $sql .= ', ' . price2num($pu_ht);
1006 $sql .= ', ' . price2num($pu_ttc);
1007 $sql .= ', ' . price2num($qty);
1008 $sql .= ', ' . price2num($remise_percent);
1009 $sql .= ', null';
1010 $sql .= ", '" . $this->db->escape($vat_src_code) . "'";
1011 $sql .= ', ' . price2num($txtva);
1012 $sql .= ', ' . price2num($txlocaltax1);
1013 $sql .= ", '" . $this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '') . "'";
1014 $sql .= ', ' . price2num($txlocaltax2);
1015 $sql .= ", '" . $this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '') . "'";
1016 $sql .= ', ' . price2num($total_ht);
1017 $sql .= ', ' . price2num($total_tva);
1018 $sql .= ', ' . price2num($total_localtax1);
1019 $sql .= ', ' . price2num($total_localtax2);
1020 $sql .= ', ' . price2num($total_ttc);
1021 $sql .= ', ' . (int) $product_type;
1022 $sql .= ', ' . ($date_start > 0 ? (int) $date_start : 'NULL');
1023 $sql .= ', ' . ($date_end > 0 ? (int) $date_end : 'NULL');
1024 $sql .= ', ' . (int) $info_bits;
1025 $sql .= ', ' . (int) $special_code;
1026 $sql .= ', ' . (int) $rang;
1027 $sql .= ', ' . ($fk_unit ? (int) $fk_unit : 'NULL');
1028 $sql .= ', ' . (int) $user->id;
1029 $sql .= ', ' . (int) $this->fk_multicurrency;
1030 $sql .= ", '" . $this->db->escape($this->multicurrency_code) . "'";
1031 $sql .= ', ' . price2num($pu_ht_devise, 'CU');
1032 $sql .= ', ' . price2num($multicurrency_total_ht, 'CT');
1033 $sql .= ', ' . price2num($multicurrency_total_tva, 'CT');
1034 $sql .= ', ' . price2num($multicurrency_total_ttc, 'CT');
1035 $sql .= ')';
1036
1037 dol_syslog(get_class($this). '::addline', LOG_DEBUG);
1038 if ($this->db->query($sql)) {
1039 $lineId = $this->db->last_insert_id(MAIN_DB_PREFIX. 'facture_fourn_det_rec');
1040 $this->update_price();
1041 $this->id = $facid;
1042 $this->db->commit();
1043 return $lineId;
1044 } else {
1045 $this->db->rollback();
1046 $this->error = $this->db->lasterror();
1047
1048 return -1;
1049 }
1050 }
1051
1079 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)
1080 {
1081 global $mysoc, $user;
1082
1083 $facid = $this->id;
1084
1085 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);
1086 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
1087
1088 // Check parameters
1089 if ($type < 0) {
1090 return -1;
1091 }
1092
1093 // Clean parameters
1094 $fk_product = empty($fk_product) ? 0 : $fk_product;
1095 $label = empty($label) ? '' : $label;
1096 $remise_percent = empty($remise_percent) ? 0 : price2num($remise_percent);
1097 $qty = price2num($qty);
1098 $info_bits = empty($info_bits) ? 0 : $info_bits;
1099 $pu_ht = price2num($pu_ht);
1100 $pu_ttc = price2num($pu_ttc);
1101 $pu_ht_devise = price2num($pu_ht_devise);
1102
1103 if (!preg_match('/\‍((.*)\‍)/', $txtva)) {
1104 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
1105 }
1106
1107 $txlocaltax1 = empty($txlocaltax1) ? 0 : price2num($txlocaltax1);
1108 $txlocaltax2 = empty($txlocaltax2) ? 0 : price2num($txlocaltax2);
1109 $this->multicurrency_total_ht = empty($this->multicurrency_total_ht) ? 0 : $this->multicurrency_total_ht;
1110 $this->multicurrency_total_tva = empty($this->multicurrency_total_tva) ? 0 : $this->multicurrency_total_tva;
1111 $this->multicurrency_total_ttc = empty($this->multicurrency_total_ttc) ? 0 : $this->multicurrency_total_ttc;
1112
1113 $pu = $price_base_type == 'HT' ? $pu_ht : $pu_ttc;
1114
1115
1116 // Calculate total with, without tax and tax from qty, pu, remise_percent and txtva
1117 // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
1118 // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
1119
1120 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
1121
1122 // Clean vat code
1123 $vat_src_code = '';
1124 $reg = array();
1125 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
1126 $vat_src_code = $reg[1];
1127 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
1128 }
1129
1130 $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);
1131
1132 $total_ht = $tabprice[0];
1133 $total_tva = $tabprice[1];
1134 $total_ttc = $tabprice[2];
1135 $total_localtax1 = $tabprice[9];
1136 $total_localtax2 = $tabprice[10];
1137 $pu_ht = $tabprice[3];
1138 $pu_tva = $tabprice[4];
1139 $pu_ttc = $tabprice[5];
1140
1141 // MultiCurrency
1142 $multicurrency_total_ht = $tabprice[16];
1143 $multicurrency_total_tva = $tabprice[17];
1144 $multicurrency_total_ttc = $tabprice[18];
1145 $pu_ht_devise = $tabprice[19];
1146
1147 $product_type = $type;
1148 if ($fk_product) {
1149 $product = new Product($this->db);
1150 $result = $product->fetch($fk_product);
1151 $product_type = $product->type;
1152 }
1153
1154 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
1155 $sql .= ' fk_facture_fourn = ' . ((int) $facid);
1156 $sql .= ', fk_product = ' . ($fk_product > 0 ? ((int) $fk_product) : 'null');
1157 $sql .= ", ref = '" . $this->db->escape($ref) . "'";
1158 $sql .= ", label = '" . $this->db->escape($label) . "'";
1159 $sql .= ", description = '" . $this->db->escape($desc) . "'";
1160 $sql .= ', pu_ht = ' . price2num($pu_ht);
1161 $sql .= ', qty = ' . price2num($qty);
1162 $sql .= ", remise_percent = '" . price2num($remise_percent) . "'";
1163 $sql .= ", vat_src_code = '" . $this->db->escape($vat_src_code) . "'";
1164 $sql .= ', tva_tx = ' . price2num($txtva);
1165 $sql .= ', localtax1_tx = ' . (float) $txlocaltax1;
1166 $sql .= ", localtax1_type = '" . $this->db->escape($localtaxes_type[0]) . "'";
1167 $sql .= ', localtax2_tx = ' . (float) $txlocaltax2;
1168 $sql .= ", localtax2_type = '" . $this->db->escape($localtaxes_type[2]) . "'";
1169 $sql .= ", total_ht = '" . price2num($total_ht) . "'";
1170 $sql .= ", total_tva = '" . price2num($total_tva) . "'";
1171 $sql .= ", total_localtax1 = '" . price2num($total_localtax1) . "'";
1172 $sql .= ", total_localtax2 = '" . price2num($total_localtax2) . "'";
1173 $sql .= ", total_ttc = '" . price2num($total_ttc) . "'";
1174 $sql .= ', product_type = ' . (int) $product_type;
1175 $sql .= ', date_start = ' . (empty($date_start) ? 'NULL' : (int) $date_start);
1176 $sql .= ', date_end = ' . (empty($date_end) ? 'NULL' : (int) $date_end);
1177 $sql .= ', info_bits = ' . (int) $info_bits;
1178 $sql .= ', special_code = ' . (int) $special_code;
1179 $sql .= ', rang = ' . (int) $rang;
1180 $sql .= ', fk_unit = ' . ($fk_unit ? "'" . $this->db->escape($fk_unit) . "'" : 'null');
1181 $sql .= ', fk_user_modif = ' . (int) $user;
1182 $sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
1183 $sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
1184 $sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
1185 $sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
1186 $sql .= ' WHERE rowid = ' . (int) $rowid;
1187
1188 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
1189 if ($this->db->query($sql)) {
1190 $this->id = $facid;
1191 $this->update_price();
1192 return 1;
1193 } else {
1194 $this->error = $this->db->lasterror();
1195 return -1;
1196 }
1197 }
1198
1199
1207 public function getNextNumRef($soc, $mode = 'next')
1208 {
1209 // Not used for recurring invoices
1210 return '';
1211 }
1212
1218 public function getNextDate()
1219 {
1220 if (empty($this->date_when)) {
1221 return false;
1222 }
1223 return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
1224 }
1225
1231 public function isMaxNbGenReached()
1232 {
1233 $ret = false;
1234 if ($this->nb_gen_max > 0 && ($this->nb_gen_done >= $this->nb_gen_max)) {
1235 $ret = true;
1236 }
1237 return $ret;
1238 }
1239
1246 public function strikeIfMaxNbGenReached($ret)
1247 {
1248 // Special case to strike the date
1249 return ($this->isMaxNbGenReached() ? '<strike>' : '').$ret.($this->isMaxNbGenReached() ? '</strike>' : '');
1250 }
1251
1262 public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidation = 0)
1263 {
1264 global $conf, $langs, $db, $user, $hookmanager;
1265
1266 $error = 0;
1267 $nb_create = 0;
1268
1269 // Load translation files required by the page
1270 $langs->loadLangs(array('main', 'bills'));
1271
1272 $now = dol_now();
1273 $tmparray = dol_getdate($now);
1274 $today = dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year']); // Today is last second of current day
1275
1276 dol_syslog('createRecurringInvoices restrictioninvoiceid=' .$restrictioninvoiceid. ' forcevalidation=' .$forcevalidation);
1277
1278 $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_fourn_rec';
1279 $sql .= ' WHERE frequency > 0'; // A recurring supplier invoice is an invoice with a frequency
1280 $sql .= " AND (date_when IS NULL OR date_when <= '".$this->db->idate($today)."')";
1281 $sql .= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
1282 $sql .= ' AND suspended = 0';
1283 $sql .= ' AND entity = '. (int) $conf->entity; // MUST STAY = $conf->entity here
1284 if ($restrictioninvoiceid > 0) {
1285 $sql .= ' AND rowid = '. (int) $restrictioninvoiceid;
1286 }
1287 $sql .= $this->db->order('entity', 'ASC');
1288 //print $sql;exit;
1289 $parameters = array(
1290 'restrictioninvoiceid' => $restrictioninvoiceid,
1291 'forcevalidation' => $forcevalidation,
1292 );
1293 $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks
1294
1295 $resql = $this->db->query($sql);
1296 if ($resql) {
1297 $i = 0;
1298 $num = $this->db->num_rows($resql);
1299
1300 if ($num) {
1301 $this->output .= $langs->trans('FoundXQualifiedRecurringInvoiceTemplate', $num)."\n";
1302 } else {
1303 $this->output .= $langs->trans('NoQualifiedRecurringInvoiceTemplateFound');
1304 }
1305
1306 $saventity = $conf->entity;
1307 $laststep="None";
1308
1309 while ($i < $num) { // Loop on each template invoice. If $num = 0, test is false at first pass.
1310 $line = $this->db->fetch_object($resql);
1311
1312 $this->db->begin();
1313
1314 $invoiceidgenerated = 0;
1315
1316 $new_fac_fourn = null;
1317 $facturerec = new FactureFournisseurRec($this->db);
1318 $laststep="Fetch {$line->rowid}";
1319 $facturerec->fetch($line->rowid);
1320
1321 if ($facturerec->id > 0) {
1322 // Set entity context
1323 $conf->entity = $facturerec->entity;
1324
1325 dol_syslog('createRecurringInvoices Process invoice template id=' .$facturerec->id. ', ref=' .$facturerec->ref. ', entity=' .$facturerec->entity);
1326
1327 $new_fac_fourn = new FactureFournisseur($this->db);
1328 $new_fac_fourn->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
1329 $new_fac_fourn->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
1330
1331 $new_fac_fourn->type = self::TYPE_STANDARD;
1332 $new_fac_fourn->statut = self::STATUS_DRAFT; // deprecated
1333 $new_fac_fourn->status = self::STATUS_DRAFT;
1334 $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.
1335 $new_fac_fourn->socid = $facturerec->socid;
1336 $new_fac_fourn->lines = $facturerec->lines;
1337 $new_fac_fourn->ref_supplier = $facturerec->ref_supplier;
1338 $new_fac_fourn->model_pdf = $facturerec->model_pdf;
1339 $new_fac_fourn->fk_project = $facturerec->fk_project;
1340 $new_fac_fourn->label = $facturerec->label;
1341 $new_fac_fourn->libelle = $facturerec->label; // deprecated
1342
1343 $invoiceidgenerated = $new_fac_fourn->create($user);
1344 $laststep="Create invoiceidgenerated $invoiceidgenerated";
1345 if ($invoiceidgenerated <= 0) {
1346 $this->errors = $new_fac_fourn->errors;
1347 $this->error = $new_fac_fourn->error;
1348 $error++;
1349 }
1350 if (!$error && ($facturerec->auto_validate || $forcevalidation)) {
1351 $result = $new_fac_fourn->validate($user);
1352 $laststep = "Validate by user {$user->login}";
1353 if ($result <= 0) {
1354 $this->errors = $new_fac_fourn->errors;
1355 $this->error = $new_fac_fourn->error;
1356 $error++;
1357 }
1358 }
1359
1360 if (!$error && $facturerec->generate_pdf) {
1361 // We refresh the object in order to have all necessary data (like date_lim_reglement)
1362 $laststep = "Refresh ".$new_fac_fourn->id;
1363 $new_fac_fourn->fetch($new_fac_fourn->id);
1364 $laststep = "GenerateDocument ".$new_fac_fourn->id;
1365 $result = $new_fac_fourn->generateDocument($facturerec->model_pdf, $langs);
1366 if ($result < 0) {
1367 $this->errors = $new_fac_fourn->errors;
1368 $this->error = $new_fac_fourn->error;
1369 $error++;
1370 }
1371 }
1372 } else {
1373 $error++;
1374 $this->error = 'Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity."\n";
1375 $this->errors[] = 'Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity;
1376 dol_syslog('createRecurringInvoices Failed to load invoice template with id=' .$line->rowid. ', entity=' .$conf->entity);
1377 }
1378
1379 if (!$error && $invoiceidgenerated >= 0) {
1380 $facturerec->nb_gen_done++;
1381 $facturerec->date_last_gen = dol_now();
1382 $facturerec->date_when= $facturerec->getNextDate();
1383 $facturerec->update($user);
1384 $this->db->commit('createRecurringInvoices Process invoice template id=' .$facturerec->id. ', title=' .$facturerec->title);
1385 dol_syslog('createRecurringInvoices Process invoice template ' .$facturerec->title. ' is finished with a success generation');
1386 $nb_create++;
1387 $this->output .= $langs->trans('InvoiceGeneratedFromTemplate', $new_fac_fourn->ref, $facturerec->title)."\n";
1388 } else {
1389 $this->db->rollback('createRecurringInvoices Process invoice template error='.$error.' invoiceidgenerated='.$invoiceidgenerated.' LastStep='.$laststep.' id=' .$facturerec->id. ', title=' .$facturerec->title);
1390 }
1391
1392 $parameters = array(
1393 'cpt' => $i,
1394 'total' => $num,
1395 'errorCount' => $error,
1396 'invoiceidgenerated' => $invoiceidgenerated,
1397 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks.
1398 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks.
1399 );
1400 $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $new_fac_fourn); // note: $facture can be modified by hooks (warning: $facture can be null)
1401
1402 $i++;
1403 }
1404
1405 $conf->entity = $saventity; // Restore entity context
1406 } else {
1407 dol_print_error($this->db);
1408 }
1409
1410 $this->output = trim($this->output);
1411
1412 return $error ? $error : 0;
1413 }
1414
1427 public function getNomUrl($withpicto = 0, $option = '', $max = 0, $short = 0, $moretitle = '', $notooltip = 0, $save_lastsearch_value = -1)
1428 {
1429 global $langs, $hookmanager;
1430
1431 $result = '';
1432
1433 $label = '<u>'.$langs->trans('RepeatableInvoice').'</u>';
1434 if (!empty($this->ref)) {
1435 $label .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1436 }
1437 if ($this->frequency > 0) {
1438 $label .= '<br><b>'.$langs->trans('Frequency').':</b> '.$langs->trans('FrequencyPer_'.$this->unit_frequency, $this->frequency);
1439 }
1440 if (!empty($this->date_last_gen)) {
1441 $label .= '<br><b>'.$langs->trans('DateLastGeneration').':</b> '.dol_print_date($this->date_last_gen, 'dayhour');
1442 }
1443 if ($this->frequency > 0) {
1444 if (!empty($this->date_when)) {
1445 $label .= '<br><b>'.$langs->trans('NextDateToExecution').':</b> ';
1446 $label .= (empty($this->suspended) ? '' : '<strike>').dol_print_date($this->date_when, 'day').(empty($this->suspended) ? '' : '</strike>'); // No hour for this property
1447 if (!empty($this->suspended)) {
1448 $label .= ' ('.$langs->trans('Disabled').')';
1449 }
1450 }
1451 }
1452
1453 $url = DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$this->id;
1454
1455 if ($short) {
1456 return $url;
1457 }
1458
1459 if ($option != 'nolink') {
1460 // Add param to save lastsearch_values or not
1461 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1462 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER['PHP_SELF'])) {
1463 $add_save_lastsearch_values = 1;
1464 }
1465 if ($add_save_lastsearch_values) {
1466 $url .= '&save_lastsearch_values=1';
1467 }
1468 }
1469
1470 $linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1471 $linkend = '</a>';
1472
1473 $result .= $linkstart;
1474 if ($withpicto) {
1475 $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);
1476 }
1477 if ($withpicto != 2) {
1478 $result .= $this->ref;
1479 }
1480 $result .= $linkend;
1481 global $action;
1482 $hookmanager->initHooks(array($this->element . 'dao'));
1483 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1484 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1485 if ($reshook > 0) {
1486 $result = $hookmanager->resPrint;
1487 } else {
1488 $result .= $hookmanager->resPrint;
1489 }
1490 return $result;
1491 }
1492
1500 public function getLibStatut($mode = 0, $alreadypaid = -1)
1501 {
1502 return $this->LibStatut($this->frequency ? 1 : 0, $this->suspended, $mode, $alreadypaid, empty($this->type) ? 0 : $this->type);
1503 }
1504
1505 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1516 public function LibStatut($recur, $status, $mode = 0, $alreadypaid = -1, $type = 0)
1517 {
1518 // phpcs:enable
1519 global $langs;
1520 $langs->load('bills');
1521
1522 $labelStatus = $langs->transnoentitiesnoconv('Active');
1523 $statusType = 'status0';
1524
1525 //print "$recur,$status,$mode,$alreadypaid,$type";
1526 if ($mode == 0) {
1527 if ($recur) {
1528 if ($status == self::STATUS_SUSPENDED) {
1529 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1530 } else {
1531 $labelStatus = $langs->transnoentitiesnoconv('Active');
1532 }
1533 } else {
1534 if ($status == self::STATUS_SUSPENDED) {
1535 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1536 } else {
1537 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1538 }
1539 }
1540 } elseif ($mode == 1) {
1541 $prefix = 'Short';
1542 if ($recur) {
1543 if ($status == self::STATUS_SUSPENDED) {
1544 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1545 } else {
1546 $labelStatus = $langs->transnoentitiesnoconv('Active');
1547 }
1548 } else {
1549 if ($status == self::STATUS_SUSPENDED) {
1550 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1551 } else {
1552 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1553 }
1554 }
1555 } elseif ($mode == 2) {
1556 if ($recur) {
1557 if ($status == self::STATUS_SUSPENDED) {
1558 $statusType = 'status6';
1559 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1560 } else {
1561 $statusType = 'status4';
1562 $labelStatus = $langs->transnoentitiesnoconv('Active');
1563 }
1564 } else {
1565 if ($status == self::STATUS_SUSPENDED) {
1566 $statusType = 'status6';
1567 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1568 } else {
1569 $statusType = 'status0';
1570 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1571 }
1572 }
1573 } elseif ($mode == 3) {
1574 if ($recur) {
1575 $prefix = 'Short';
1576 if ($status == self::STATUS_SUSPENDED) {
1577 $statusType = 'status6';
1578 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1579 } else {
1580 $statusType = 'status4';
1581 $labelStatus = $langs->transnoentitiesnoconv('Active');
1582 }
1583 } else {
1584 if ($status == self::STATUS_SUSPENDED) {
1585 $statusType = 'status6';
1586 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1587 } else {
1588 $statusType = 'status0';
1589 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1590 }
1591 }
1592 } elseif ($mode == 4) {
1593 $prefix = '';
1594 if ($recur) {
1595 if ($status == self::STATUS_SUSPENDED) {
1596 $statusType = 'status6';
1597 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1598 } else {
1599 $statusType = 'status4';
1600 $labelStatus = $langs->transnoentitiesnoconv('Active');
1601 }
1602 } else {
1603 if ($status == self::STATUS_SUSPENDED) {
1604 $statusType = 'status6';
1605 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1606 } else {
1607 $statusType = 'status0';
1608 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1609 }
1610 }
1611 } elseif ($mode == 5 || $mode == 6) {
1612 $prefix = '';
1613 if ($mode == 5) {
1614 $prefix = 'Short';
1615 }
1616 if ($recur) {
1617 if ($status == self::STATUS_SUSPENDED) {
1618 $statusType = 'status6';
1619 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1620 } else {
1621 $statusType = 'status4';
1622 $labelStatus = $langs->transnoentitiesnoconv('Active');
1623 }
1624 } else {
1625 if ($status == self::STATUS_SUSPENDED) {
1626 $statusType = 'status6';
1627 $labelStatus = $langs->transnoentitiesnoconv('Disabled');
1628 } else {
1629 $statusType = 'status0';
1630 $labelStatus = $langs->transnoentitiesnoconv('Draft');
1631 }
1632 }
1633 }
1634
1635 $labelStatusShort = $labelStatus;
1636
1637 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1638 }
1639
1648 public function initAsSpecimen($option = '')
1649 {
1650 global $user, $langs, $conf;
1651
1652 $now = dol_now();
1653 $arraynow = dol_getdate($now);
1654 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1655
1656 // Load array of products prodids
1657 $num_prods = 0;
1658 $prodids = array();
1659
1660 $sql = 'SELECT rowid';
1661 $sql .= ' FROM ' .MAIN_DB_PREFIX. 'product';
1662 $sql .= ' WHERE entity IN (' .getEntity('product'). ')';
1663 $sql .= $this->db->plimit(100);
1664
1665 $resql = $this->db->query($sql);
1666 if ($resql) {
1667 $num_prods = $this->db->num_rows($resql);
1668 $i = 0;
1669 while ($i < $num_prods) {
1670 $i++;
1671 $row = $this->db->fetch_row($resql);
1672 $prodids[$i] = $row[0];
1673 }
1674 }
1675
1676 // Initialize parameters
1677 $this->id = 0;
1678 $this->ref = 'SPECIMEN';
1679 $this->title = 'SPECIMEN';
1680 $this->specimen = 1;
1681 $this->socid = 1;
1682 $this->date = $nownotime;
1683 $this->date_lim_reglement = $nownotime + 3600 * 24 * 30;
1684 $this->cond_reglement_id = 1;
1685 $this->cond_reglement_code = 'RECEP';
1686 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
1687 $this->mode_reglement_id = 0; // Not forced to show payment mode CHQ + VIR
1688 $this->mode_reglement_code = ''; // Not forced to show payment mode CHQ + VIR
1689 $this->note_public = 'This is a comment (public)';
1690 $this->note_private = 'This is a comment (private)';
1691 $this->note = 'This is a comment (private)';
1692 $this->fk_incoterms = 0;
1693 $this->location_incoterms = '';
1694
1695 if (empty($option) || $option != 'nolines') {
1696 // Lines
1697 $nbp = 5;
1698 $xnbp = 0;
1699 while ($xnbp < $nbp) {
1700 $line = new FactureLigne($this->db);
1701 $line->desc = $langs->trans('Description'). ' ' .$xnbp;
1702 $line->qty = 1;
1703 $line->subprice = 100;
1704 $line->tva_tx = 19.6;
1705 $line->localtax1_tx = 0;
1706 $line->localtax2_tx = 0;
1707 $line->remise_percent = 0;
1708 if ($xnbp == 1) { // Qty is negative (product line)
1709 $prodid = mt_rand(1, $num_prods);
1710 $line->fk_product = $prodids[$prodid];
1711 $line->qty = -1;
1712 $line->total_ht = -100;
1713 $line->total_ttc = -119.6;
1714 $line->total_tva = -19.6;
1715 } elseif ($xnbp == 2) { // UP is negative (free line)
1716 $line->subprice = -100;
1717 $line->total_ht = -100;
1718 $line->total_ttc = -119.6;
1719 $line->total_tva = -19.6;
1720 $line->remise_percent = 0;
1721 } elseif ($xnbp == 3) { // Discount is 50% (product line)
1722 $prodid = mt_rand(1, $num_prods);
1723 $line->fk_product = $prodids[$prodid];
1724 $line->total_ht = 50;
1725 $line->total_ttc = 59.8;
1726 $line->total_tva = 9.8;
1727 $line->remise_percent = 50;
1728 } else { // (product line)
1729 $prodid = mt_rand(1, $num_prods);
1730 $line->fk_product = $prodids[$prodid];
1731 $line->total_ht = 100;
1732 $line->total_ttc = 119.6;
1733 $line->total_tva = 19.6;
1734 $line->remise_percent = 00;
1735 }
1736
1737 $this->lines[$xnbp] = $line;
1738 $xnbp++;
1739
1740 $this->total_ht += $line->total_ht;
1741 $this->total_tva += $line->total_tva;
1742 $this->total_ttc += $line->total_ttc;
1743 }
1744 $this->revenuestamp = 0;
1745
1746 // Add a line "offered"
1747 $line = new FactureLigne($this->db);
1748 $line->desc = $langs->trans('Description'). ' (offered line)';
1749 $line->qty = 1;
1750 $line->subprice = 100;
1751 $line->tva_tx = 19.6;
1752 $line->localtax1_tx = 0;
1753 $line->localtax2_tx = 0;
1754 $line->remise_percent = 100;
1755 $line->total_ht = 0;
1756 $line->total_ttc = 0; // 90 * 1.196
1757 $line->total_tva = 0;
1758 $prodid = mt_rand(1, $num_prods);
1759 $line->fk_product = $prodids[$prodid];
1760
1761 $this->lines[$xnbp] = $line;
1762 $xnbp++;
1763 }
1764
1765 $this->usenewprice = 0;
1766 }
1767
1776 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
1777 {
1778 $tables = array(
1779 'facture_fourn_rec'
1780 );
1781
1782 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
1783 }
1784
1792 public function setFrequencyAndUnit($frequency, $unit)
1793 {
1794 if (!$this->table_element) {
1795 dol_syslog(get_class($this). '::setFrequencyAndUnit was called on objet with property table_element not defined', LOG_ERR);
1796 return -1;
1797 }
1798
1799 if (!empty($frequency) && empty($unit)) {
1800 dol_syslog(get_class($this). '::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined', LOG_ERR);
1801 return -2;
1802 }
1803
1804 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1805 $sql .= " SET frequency = ".($frequency ? ((int) $frequency) : "NULL");
1806 if (!empty($unit)) {
1807 $sql .= ", unit_frequency = '".$this->db->escape($unit)."'";
1808 }
1809 $sql .= " WHERE rowid = ".((int) $this->id);
1810
1811 dol_syslog(get_class($this).'::setFrequencyAndUnit', LOG_DEBUG);
1812
1813 if ($this->db->query($sql)) {
1814 $this->frequency = $frequency;
1815 if (!empty($unit)) {
1816 $this->unit_frequency = $unit;
1817 }
1818 return 1;
1819 } else {
1820 $this->error = $this->db->lasterror();
1821 return -1;
1822 }
1823 }
1824
1832 public function setNextDate($date, $increment_nb_gen_done = 0)
1833 {
1834 if (!$this->table_element) {
1835 dol_syslog(get_class($this).'::setNextDate was called on objet with property table_element not defined', LOG_ERR);
1836 return -1;
1837 }
1838 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1839 $sql .= " SET date_when = " .($date ? "'".$this->db->idate($date)."'" : "NULL");
1840 if ($increment_nb_gen_done > 0) {
1841 $sql .= ", nb_gen_done = nb_gen_done + 1";
1842 }
1843 $sql .= " WHERE rowid = " . (int) $this->id;
1844
1845 dol_syslog(get_class($this).'::setNextDate', LOG_DEBUG);
1846
1847 if ($this->db->query($sql)) {
1848 $this->date_when = $date;
1849 if ($increment_nb_gen_done > 0) {
1850 $this->nb_gen_done++;
1851 }
1852 return 1;
1853 } else {
1854 $this->error = $this->db->lasterror();
1855 return -1;
1856 }
1857 }
1858
1865 public function setMaxPeriod($nb)
1866 {
1867 if (!$this->table_element) {
1868 dol_syslog(get_class($this).'::setMaxPeriod was called on objet with property table_element not defined', LOG_ERR);
1869 return -1;
1870 }
1871
1872 if (empty($nb)) {
1873 $nb = 0;
1874 }
1875
1876 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1877 $sql .= " SET nb_gen_max = ". (int) $nb;
1878 $sql .= " WHERE rowid = " . (int) $this->id;
1879
1880 dol_syslog(get_class($this).'::setMaxPeriod', LOG_DEBUG);
1881
1882 if ($this->db->query($sql)) {
1883 $this->nb_gen_max = $nb;
1884 return 1;
1885 } else {
1886 dol_print_error($this->db);
1887 return -1;
1888 }
1889 }
1890
1897 public function setAutoValidate($validate)
1898 {
1899 if (!$this->table_element) {
1900 dol_syslog(get_class($this).'::setAutoValidate was called on objet with property table_element not defined', LOG_ERR);
1901 return -1;
1902 }
1903
1904 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1905 $sql .= " SET auto_validate = ".((int) $validate);
1906 $sql .= " WHERE rowid = " . (int) $this->id;
1907
1908 dol_syslog(get_class($this).'::setAutoValidate', LOG_DEBUG);
1909
1910 if ($this->db->query($sql)) {
1911 $this->auto_validate = $validate;
1912 return 1;
1913 } else {
1914 dol_print_error($this->db);
1915 return -1;
1916 }
1917 }
1918
1925 public function setGeneratePdf($validate)
1926 {
1927 if (!$this->table_element) {
1928 dol_syslog(get_class($this).'::setGeneratePdf was called on objet with property table_element not defined', LOG_ERR);
1929 return -1;
1930 }
1931
1932 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1933 $sql .= " SET generate_pdf = ". (int) $validate;
1934 $sql .= " WHERE rowid = " . (int) $this->id;
1935
1936 dol_syslog(get_class($this).'::setGeneratePdf', LOG_DEBUG);
1937
1938 if ($this->db->query($sql)) {
1939 $this->generate_pdf = $validate;
1940 return 1;
1941 } else {
1942 dol_print_error($this->db);
1943 return -1;
1944 }
1945 }
1946
1953 public function setModelPdf($model)
1954 {
1955 if (!$this->table_element) {
1956 dol_syslog(get_class($this).'::setModelPdf was called on objet with property table_element not defined', LOG_ERR);
1957 return -1;
1958 }
1959
1960 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1961 $sql .= " SET modelpdf = '".$this->db->escape($model)."'";
1962 $sql .= " WHERE rowid = " . (int) $this->id;
1963
1964 dol_syslog(get_class($this).'::setModelPdf', LOG_DEBUG);
1965
1966 if ($this->db->query($sql)) {
1967 $this->model_pdf = $model;
1968 return 1;
1969 } else {
1970 dol_print_error($this->db);
1971 return -1;
1972 }
1973 }
1974}
1975
1976
1977
1983{
1987 public $element = 'invoice_supplier_det_rec';
1988
1992 public $table_element = 'facture_fourn_det_rec';
1993
1994 public $fk_facture_fourn;
1995 public $fk_parent;
1996 public $fk_product;
1997 public $ref_supplier;
1998 public $label;
1999 public $description;
2000 public $pu_ht;
2001 public $pu_ttc;
2002 public $qty;
2003 public $remise_percent;
2004 public $fk_remise_except;
2005 public $vat_src_code;
2006 public $tva_tx;
2007 public $localtax1_tx;
2008 public $localtax1_type;
2009 public $localtax2_tx;
2010 public $localtax2_type;
2011
2012 public $product_type;
2013 public $date_start;
2014 public $date_end;
2015 public $info_bits;
2016 public $special_code;
2017 public $rang;
2018
2019 public $fk_user_author;
2020 public $fk_user_modif;
2021
2022
2030 public function delete(User $user, $notrigger = 0)
2031 {
2032 $error = 0;
2033 $this->db->begin();
2034
2035 if (! $error) {
2036 if (! $notrigger) {
2037 // Call triggers
2038 $result = $this->call_trigger('LINESUPPLIERBILLREC_DELETE', $user);
2039 if ($result < 0) {
2040 $error++;
2041 } // Do also here what you must do to rollback action if trigger fail
2042 // End call triggers
2043 }
2044 }
2045
2046 if (! $error) {
2047 $result = $this->deleteExtraFields();
2048 if ($result < 0) {
2049 $error++;
2050 }
2051 }
2052
2053 if (! $error) {
2054 $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element . ' WHERE rowid=' . (int) $this->id;
2055
2056 $res = $this->db->query($sql);
2057 if ($res === false) {
2058 $error++;
2059 $this->errors[] = $this->db->lasterror();
2060 }
2061 }
2062
2063 // Commit or rollback
2064 if ($error) {
2065 $this->db->rollback();
2066 return -1;
2067 } else {
2068 $this->db->commit();
2069 return 1;
2070 }
2071 }
2072
2073
2080 public function fetch($rowid)
2081 {
2082 $sql = 'SELECT l.rowid,';
2083 $sql .= ' l.fk_facture_fourn, l.fk_parent_line, l.fk_product,';
2084 $sql .= ' l.ref as ref_supplier, l.label, l.description, l.pu_ht, l.pu_ttc, l.qty, l.remise_percent, l.fk_remise_except,';
2085 $sql .= ' l.vat_src_code, l.tva_tx, l.localtax1_tx, l.localtax1_type, l.localtax2_tx, l.localtax2_type,';
2086 $sql .= ' l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc,';
2087 $sql .= ' l.product_type, l.date_start, l.date_end,';
2088 $sql .= ' l.info_bits, l.special_code, l.rang, l.fk_unit, l.import_key,';
2089 $sql .= ' l.fk_user_author, l.fk_user_modif, l.fk_multicurrency,';
2090 $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2091 $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
2092 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det_rec as l';
2093 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
2094 $sql .= ' WHERE l.rowid = '. (int) $rowid;
2095 $sql .= ' ORDER BY l.rang';
2096
2097 dol_syslog('FactureRec::fetch', LOG_DEBUG);
2098 $result = $this->db->query($sql);
2099 if ($result) {
2100 $objp = $this->db->fetch_object($result);
2101
2102 $this->id = $objp->rowid;
2103 $this->fk_facture_fourn = $objp->fk_facture_fourn;
2104 $this->fk_parent = $objp->fk_parent_line;
2105 $this->fk_product = $objp->fk_product;
2106 $this->ref_supplier = $objp->ref_supplier;
2107 $this->label = $objp->label;
2108 $this->description = $objp->description;
2109 $this->pu_ht = $objp->pu_ht;
2110 $this->pu_ttc = $objp->pu_ttc;
2111 $this->qty = $objp->qty;
2112 $this->remise_percent = $objp->remise_percent;
2113 $this->fk_remise_except = $objp->fk_remise_except;
2114 $this->vat_src_code = $objp->vat_src_code;
2115 $this->tva_tx = $objp->tva_tx;
2116 $this->localtax1_tx = $objp->localtax1_tx;
2117 $this->localtax1_type = $objp->localtax1_type;
2118 $this->localtax2_tx = $objp->localtax2_tx;
2119 $this->localtax2_type = $objp->localtax2_type;
2120 $this->total_ht = $objp->total_ht;
2121 $this->total_tva = $objp->total_tva;
2122 $this->total_localtax1 = $objp->total_localtax1;
2123 $this->total_localtax2 = $objp->total_localtax2;
2124 $this->total_ttc = $objp->total_ttc;
2125 $this->product_type = $objp->product_type;
2126 $this->date_start = $this->db->jdate($objp->date_start);
2127 $this->date_end = $this->db->jdate($objp->date_end);
2128 $this->info_bits = $objp->info_bits;
2129 $this->special_code = $objp->special_code;
2130 $this->rang = $objp->rang;
2131 $this->fk_unit = $objp->fk_unit;
2132 $this->import_key = $objp->import_key;
2133 $this->fk_user_author = $objp->fk_user_author;
2134 $this->fk_user_modif = $objp->fk_user_modif;
2135 $this->fk_multicurrency = $objp->fk_multicurrency;
2136 $this->multicurrency_code = $objp->multicurrency_code;
2137 $this->multicurrency_subprice = $objp->multicurrency_subprice;
2138 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
2139 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
2140 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2141
2142 $this->db->free($result);
2143 return 1;
2144 } else {
2145 $this->error = $this->db->lasterror();
2146 return -3;
2147 }
2148 }
2149
2150
2158 public function update(User $user, $notrigger = 0)
2159 {
2160 global $conf;
2161
2162 $error = 0;
2163
2164 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
2165
2166 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture_fourn_det_rec SET';
2167 $sql .= ' fk_facture_fourn = ' . (int) $this->fk_facture_fourn;
2168 $sql .= ', fk_parent_line = ' . (int) $this->fk_parent;
2169 $sql .= ', fk_product = ' . (int) $this->fk_product;
2170 $sql .= ', ref = ' . (!empty($this->ref) ? "'" . $this->db->escape($this->ref) . "'" : 'NULL');
2171 $sql .= ", label = " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : 'NULL');
2172 $sql .= ", description = '" . $this->db->escape($this->description) . "'";
2173 $sql .= ', pu_ht = ' . price2num($this->pu_ht);
2174 $sql .= ', pu_ttc = ' . price2num($this->pu_ttc);
2175 $sql .= ', qty = ' . price2num($this->qty);
2176 $sql .= ", remise_percent = '" . price2num($this->remise_percent) . "'";
2177 $sql .= ', fk_remise_except = ' . (int) $this->fk_remise_except;
2178 $sql .= ", vat_src_code = '" . $this->db->escape($this->vat_src_code) . "'";
2179 $sql .= ', tva_tx = ' . price2num($this->tva_tx);
2180 $sql .= ', localtax1_tx = ' . price2num($this->localtax1_tx);
2181 $sql .= ", localtax1_type = '" . $this->db->escape($this->localtax1_type) . "'";
2182 $sql .= ', localtax2_tx = ' . price2num($this->localtax2_tx);
2183 $sql .= ", localtax2_type = '" . $this->db->escape($this->localtax2_type) . "'";
2184 if (empty($this->skip_update_total)) {
2185 $sql .= ', total_ht = ' . price2num($this->total_ht);
2186 $sql .= ', total_tva = ' . price2num($this->total_tva);
2187 $sql .= ', total_localtax1 = ' . price2num($this->total_localtax1);
2188 $sql .= ', total_localtax2 = ' . price2num($this->total_localtax2);
2189 $sql .= ', total_ttc = ' . price2num($this->total_ttc);
2190 }
2191 $sql .= ', product_type = ' . (int) $this->product_type;
2192 $sql .= ', date_start = ' . (int) $this->date_start;
2193 $sql .= ', date_end = ' . (int) $this->date_end;
2194 $sql .= ", info_bits = " . ((int) $this->info_bits);
2195 $sql .= ', special_code =' . (int) $this->special_code;
2196 $sql .= ', rang = ' . (int) $this->rang;
2197 $sql .= ', fk_unit = ' .($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'" : 'null');
2198 $sql .= ', fk_user_modif = ' . (int) $user->id;
2199 $sql .= ' WHERE rowid = ' . (int) $this->id;
2200
2201 $this->db->begin();
2202
2203 dol_syslog(get_class($this). '::updateline', LOG_DEBUG);
2204 $resql = $this->db->query($sql);
2205 if ($resql) {
2206 if (!$error) {
2207 $result = $this->insertExtraFields();
2208 if ($result < 0) {
2209 $error++;
2210 }
2211 }
2212
2213 if (!$error && !$notrigger) {
2214 // Call trigger
2215 $result = $this->call_trigger('LINESUPPLIERBILLREC_MODIFY', $user);
2216 if ($result < 0) {
2217 $error++;
2218 }
2219 // End call triggers
2220 }
2221
2222 if ($error) {
2223 $this->db->rollback();
2224 return -2;
2225 } else {
2226 $this->db->commit();
2227 return 1;
2228 }
2229 } else {
2230 $this->error = $this->db->lasterror();
2231 $this->db->rollback();
2232 return -2;
2233 }
2234 }
2235}
$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.
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.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
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: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)
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.
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...
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