dolibarr 25.0.0-alpha
supplier_proposal.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
6 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
8 * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
9 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
10 * Copyright (C) 2010-2018 Philippe Grand <philippe.grand@atoo-net.com>
11 * Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
12 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
13 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
14 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
15 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
16 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
17 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
18 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
19 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
20 * Copyright (C) 2026 Vincent de Grandpré <vincent@de-grandpre.quebec>
21 * Copyright (C) 2026 Lionel Vessiller <lvessiller@open-dsi.fr>
22 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
23 * Copyright (C) 2026 Nick Fragoulis
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 3 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <https://www.gnu.org/licenses/>.
37 */
38
44require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
46require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
47require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
48require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
51require_once DOL_DOCUMENT_ROOT.'/subtotals/class/commonsubtotal.class.php';
56{
57 use CommonIncoterm;
58 use CommonSubtotal;
59
63 public $element = 'supplier_proposal';
64
68 public $table_element = 'supplier_proposal';
69
73 public $table_element_line = 'supplier_proposaldet';
74
78 public $class_element_line = 'SupplierProposalLine';
82 public $fk_element = 'fk_supplier_proposal';
83
87 public $picto = 'supplier_proposal';
88
93 public $restrictiononfksoc = 1;
94
98 protected $table_ref_field = 'ref';
99
103 public $socid; // Id client
104
110 public $author;
111
115 public $ref_fourn;
119 public $ref_supplier;
120
125 public $statut; // 0 (draft), 1 (validated), 2 (signed), 3 (not signed), 4 (processed/billed)
126
130 public $date;
131
135 public $delivery_date;
136
142 public $datec;
143
149 public $datev;
150
154 public $user_author_id;
155
161 public $price;
162
168 public $tva;
169
175 public $total;
176
180 public $cond_reglement_code;
184 public $cond_reglement_doc; // label doc
188 public $cond_reglement_label;
189
193 public $mode_reglement_code;
198 public $mode_reglement;
199
205 public $deposit_percent;
206
207
211 public $extraparams = array();
212
216 public $lines = array();
217
221 public $line;
222
223 public $labelStatus = array();
224 public $labelStatusShort = array();
225
229 public $nbtodo;
233 public $nbtodolate;
234
235 // Multicurrency
239 public $fk_multicurrency;
240
244 public $multicurrency_code;
248 public $multicurrency_tx;
252 public $multicurrency_total_ht;
256 public $multicurrency_total_tva;
260 public $multicurrency_total_ttc;
261
262 public $fields = array(
263 'ref' => array('type' => 'varchar(255)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'showoncombobox' => 1, 'position' => 25, 'searchall' => 1),
264 'note_public' => array('type' => 'html', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 750, 'searchall' => 1),
265 );
266
270 const STATUS_DRAFT = 0;
271
276
280 const STATUS_SIGNED = 2;
281
286
290 const STATUS_CLOSE = 4;
291
292
293
301 public function __construct($db, $socid = 0, $supplier_proposalid = 0)
302 {
303 $this->db = $db;
304
305 $this->ismultientitymanaged = 1;
306 $this->socid = $socid;
307 $this->id = $supplier_proposalid;
308 }
309
310
311 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
322 public function add_product($idproduct, $qty, $remise_percent = 0)
323 {
324 // phpcs:enable
325 global $mysoc;
326
327 if (!$qty) {
328 $qty = 1;
329 }
330
331 dol_syslog(get_class($this)."::add_product $idproduct, $qty, $remise_percent");
332 if ($idproduct > 0) {
333 $prod = new Product($this->db);
334 $prod->fetch($idproduct);
335
336 $productdesc = $prod->description;
337
338 $tva_tx = get_default_tva($mysoc, $this->thirdparty, $prod->id);
339 $tva_npr = get_default_npr($mysoc, $this->thirdparty, $prod->id);
340 if (empty($tva_tx)) {
341 $tva_npr = 0;
342 }
343 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $this->thirdparty, $tva_npr);
344 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $this->thirdparty, $tva_npr);
345
346 // multiprix
347 if (getDolGlobalString('PRODUIT_MULTIPRICES') && $this->thirdparty->price_level) {
348 $price = $prod->multiprices[$this->thirdparty->price_level];
349 } else {
350 $price = $prod->price;
351 }
352
353 $line = new SupplierProposalLine($this->db);
354
355 $line->fk_product = $idproduct;
356 $line->desc = $productdesc;
357 $line->qty = $qty;
358 $line->subprice = $price;
359 $line->remise_percent = $remise_percent;
360 $line->tva_tx = $tva_tx;
361
362 $this->lines[] = $line;
363 return 1;
364 }
365 return -1;
366 }
367
368 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
375 public function insert_discount($idremise)
376 {
377 // phpcs:enable
378 global $langs;
379
380 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
381 include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
382
383 $this->db->begin();
384
385 $remise = new DiscountAbsolute($this->db);
386 $result = $remise->fetch($idremise);
387
388 if ($result > 0) {
389 if ($remise->fk_facture) { // Protection against multiple submission
390 $this->error = $langs->trans("ErrorDiscountAlreadyUsed");
391 $this->db->rollback();
392 return -5;
393 }
394
395 $supplier_proposalligne = new SupplierProposalLine($this->db);
396 $supplier_proposalligne->fk_supplier_proposal = $this->id;
397 $supplier_proposalligne->fk_remise_except = $remise->id;
398 $supplier_proposalligne->desc = $remise->description; // Description of the proposal line
399 $supplier_proposalligne->tva_tx = $remise->tva_tx;
400 $supplier_proposalligne->localtax1_tx = $remise->localtax1_tx;
401 $supplier_proposalligne->localtax1_type = $remise->localtax1_type;
402 $supplier_proposalligne->localtax2_tx = $remise->localtax1_tx;
403 $supplier_proposalligne->localtax2_type = $remise->localtax1_type;
404 $supplier_proposalligne->subprice = -(float) $remise->amount_ht;
405 $supplier_proposalligne->fk_product = 0; // Predefined Product ID
406 $supplier_proposalligne->qty = 1;
407 $supplier_proposalligne->remise_percent = 0;
408 $supplier_proposalligne->rang = -1;
409 $supplier_proposalligne->info_bits = 2;
410
411 $supplier_proposalligne->total_ht = -(float) $remise->amount_ht;
412 $supplier_proposalligne->total_tva = -(float) $remise->amount_tva;
413 $supplier_proposalligne->total_ttc = -(float) $remise->amount_ttc;
414 $supplier_proposalligne->total_localtax1 = -(float) $remise->total_localtax1;
415 $supplier_proposalligne->total_localtax2 = -(float) $remise->total_localtax2;
416
417 $result = $supplier_proposalligne->insert();
418 if ($result > 0) {
419 $result = $this->update_price(1);
420 if ($result > 0) {
421 $this->db->commit();
422 return 1;
423 } else {
424 $this->db->rollback();
425 return -1;
426 }
427 } else {
428 $this->setErrorsFromObject($supplier_proposalligne);
429 $this->db->rollback();
430 return -2;
431 }
432 } else {
433 $this->db->rollback();
434 return -2;
435 }
436 }
437
474 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_options = [], $ref_supplier = '', $fk_unit = 0, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $date_start = 0, $date_end = 0)
475 {
476 global $mysoc, $langs;
477
478 dol_syslog(get_class($this)."::addline supplier_proposalid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type");
479 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
480
481 // Clean parameters
482 if (empty($remise_percent)) {
483 $remise_percent = 0;
484 }
485 if (empty($qty)) {
486 $qty = 0;
487 }
488 if (empty($info_bits)) {
489 $info_bits = 0;
490 }
491 if (empty($rang)) {
492 $rang = 0;
493 }
494 if (empty($fk_parent_line) || $fk_parent_line < 0) {
495 $fk_parent_line = 0;
496 }
497 if (empty($pu_ht)) {
498 $pu_ht = 0;
499 }
500
501 $remise_percent = price2num($remise_percent);
502 $qty = (float) price2num($qty);
503 $pu_ht = price2num($pu_ht);
504 $pu_ttc = price2num($pu_ttc);
505 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
506 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
507 }
508 $txlocaltax1 = price2num($txlocaltax1);
509 $txlocaltax2 = price2num($txlocaltax2);
510 $pa_ht = price2num($pa_ht);
511 if ($price_base_type == 'HT') {
512 $pu = $pu_ht;
513 } else {
514 $pu = $pu_ttc;
515 }
516
517 // Check parameters
518 if ($type < 0) {
519 return -1;
520 }
521
522 if ($this->status == self::STATUS_DRAFT) {
523 $this->db->begin();
524
525 if ($fk_product > 0) {
526 if (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') == 1) { // Not the common case
527 // Check quantity is enough
528 dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." fk_fournprice=".$fk_fournprice." qty=".$qty." ref_supplier=".$ref_supplier);
529 $productsupplier = new ProductFournisseur($this->db);
530 if ($productsupplier->fetch($fk_product) > 0) {
531 $product_type = $productsupplier->type;
532 $label = $productsupplier->label;
533 $fk_prod_fourn_price = $fk_fournprice;
534
535 // We use 'none' instead of $ref_supplier, because fourn_ref may not exists anymore. So we will take the first supplier price ok.
536 // If we want a dedicated supplier price, we must provide $fk_prod_fourn_price.
537 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
538 $result = $productsupplier->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->socid); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$ref_supplier/$this->socid
539 if ($result > 0) {
540 $pu = $productsupplier->fourn_pu; // Unit price supplier price set by get_buyprice
541 $ref_supplier = $productsupplier->ref_supplier; // Ref supplier price set by get_buyprice
542 // is remise percent not keyed but present for the product we add it
543 if ($remise_percent == 0 && $productsupplier->remise_percent != 0) {
544 $remise_percent = $productsupplier->remise_percent;
545 }
546 }
547 if ($result == 0) { // If result == 0, we failed to found the supplier reference price
548 $langs->load("errors");
549 $this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
550 $this->db->rollback();
551 dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price");
552 //$pu = $productsupplier->fourn_pu; // We do not overwrite unit price
553 //$ref = $productsupplier_fourn; // We do not overwrite ref supplier price
554 return -1;
555 }
556 if ($result == -1) {
557 $langs->load("errors");
558 $this->error = "Ref ".$productsupplier->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier");
559 $this->db->rollback();
560 dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG);
561 return -1;
562 }
563 if ($result < -1) {
564 $this->setErrorsFromObject($productsupplier);
565 $this->db->rollback();
566 dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR);
567 return -1;
568 }
569 } else {
570 $this->setErrorsFromObject($productsupplier);
571 $this->db->rollback();
572 return -1;
573 }
574 }
575
576 // Predefine quantity according to packaging (same rule as for supplier orders)
577 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
578 $prod = new Product($this->db);
579 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
580 $prod->get_buyprice(($fk_fournprice > 0 ? (int) $fk_fournprice : 0), (float) $qty, $fk_product, 'none', $this->socid);
581
582 $newqty = $this->roundQtyToPackaging($qty, $prod->packaging);
583 if ($newqty != $qty) {
584 $qty = $newqty;
585 setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'warnings');
586 }
587
588 // Enforce the supplier minimum purchase quantity on top of packaging rounding: if the line is below
589 // the supplier minimum, round the minimum itself up to the next packaging multiple.
590 if (!empty($prod->fourn_qty) && (float) $qty > 0 && (float) $qty < (float) $prod->fourn_qty) { // A negative quantity (return) is not concerned by the minimum purchase quantity
591 if (!empty($prod->packaging) && (float) price2num(fmod((float) $prod->fourn_qty, (float) $prod->packaging), 'MS')) {
592 $coeff = intval((float) $prod->fourn_qty / (float) $prod->packaging) + 1;
593 $qty = (float) price2num((float) $prod->packaging * $coeff, 'MS');
594 } else {
595 $qty = (float) $prod->fourn_qty;
596 }
597 setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'mesgs');
598 }
599 }
600 } else {
601 $product_type = $type;
602 }
603
604 // Calculation of the gross total (TTC) and VAT for the line from qty, pu, remise_percent and txtva
605 // VERY IMPORTANT: It's at the time of line insertion that we must store the net, VAT, and gross amounts,
606 // and this is done at the line level, which has its own VAT rate
607
608 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
609
610 // Clean vat code
611 $reg = array();
612 $vat_src_code = '';
613 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
614 $vat_src_code = $reg[1];
615 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
616 }
617
618 if (isModEnabled("multicurrency") && $pu_ht_devise > 0) {
619 $pu = 0;
620 }
621
622 $tabprice = calcul_price_total(
623 $qty,
624 $pu,
625 (float) $remise_percent,
626 $txtva,
627 (float) $txlocaltax1,
628 (float) $txlocaltax2,
629 0,
630 $price_base_type,
631 $info_bits,
632 $type,
633 $this->thirdparty,
634 $localtaxes_type,
635 100,
636 (float) $this->multicurrency_tx,
637 $pu_ht_devise,
638 $this->multicurrency_code
639 );
640 $total_ht = $tabprice[0];
641 $total_tva = $tabprice[1];
642 $total_ttc = $tabprice[2];
643 $total_localtax1 = $tabprice[9];
644 $total_localtax2 = $tabprice[10];
645 $pu = $pu_ht = $tabprice[3];
646
647 // MultiCurrency
648 $multicurrency_total_ht = $tabprice[16];
649 $multicurrency_total_tva = $tabprice[17];
650 $multicurrency_total_ttc = $tabprice[18];
651 $pu_ht_devise = $tabprice[19];
652
653 // Rang to use
654 $ranktouse = $rang;
655 if ($ranktouse == -1) {
656 $rangmax = $this->line_max($fk_parent_line);
657 $ranktouse = $rangmax + 1;
658 }
659
660 // Insert line
661 $this->line = new SupplierProposalLine($this->db);
662
663 $this->line->fk_supplier_proposal = $this->id;
664 $this->line->label = $label;
665 $this->line->desc = $desc;
666 $this->line->qty = $qty;
667
668 $this->line->vat_src_code = $vat_src_code;
669 $this->line->tva_tx = $txtva;
670 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
671 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
672 $this->line->localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0];
673 $this->line->localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2];
674 $this->line->fk_product = $fk_product;
675 $this->line->remise_percent = $remise_percent;
676 $this->line->subprice = (float) $pu_ht;
677 // Persist the original entry mode of the line so updateline() can preserve it later.
678 $this->line->subprice_ttc = ($price_base_type === 'TTC') ? (float) $pu_ttc : 0;
679 $this->line->rang = $ranktouse;
680 $this->line->info_bits = $info_bits;
681 $this->line->total_ht = (float) $total_ht;
682 $this->line->total_tva = (float) $total_tva;
683 $this->line->total_localtax1 = (float) $total_localtax1;
684 $this->line->total_localtax2 = (float) $total_localtax2;
685 $this->line->total_ttc = (float) $total_ttc;
686 $this->line->product_type = $type;
687 $this->line->special_code = $special_code;
688 $this->line->fk_parent_line = $fk_parent_line;
689 $this->line->fk_unit = $fk_unit;
690 $this->line->origin = $origin;
691 $this->line->origin_type = $origin;
692 $this->line->origin_id = $origin_id;
693 $this->line->ref_fourn = $this->db->escape($ref_supplier);
694 $this->line->date_start = $date_start;
695 $this->line->date_end = $date_end;
696
697 // infos merge
698 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
699 // When fk_fournprice is 0, we take the lowest buying price
700 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
701 $productFournisseur = new ProductFournisseur($this->db);
702 $productFournisseur->find_min_price_product_fournisseur($fk_product);
703 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
704 } else {
705 $this->line->fk_fournprice = ($fk_fournprice > 0 ? $fk_fournprice : 0); // If fk_fournprice is -1, we will not use fk_fournprice
706 }
707 $this->line->pa_ht = $pa_ht;
708 //var_dump($this->line->fk_fournprice);exit;
709
710 // Multicurrency
711 $this->line->fk_multicurrency = $this->fk_multicurrency;
712 $this->line->multicurrency_code = $this->multicurrency_code;
713 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
714 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
715 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
716 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
717
718 // Set the proposal line as optional
719 if (empty($qty) && empty($special_code)) {
720 $this->line->special_code = 3;
721 }
722
723 if (is_array($array_options) && count($array_options) > 0) {
724 $this->line->array_options = $array_options;
725 }
726
727 $result = $this->line->insert();
728 if ($result > 0) {
729 // Reorder if child line
730 if (!empty($fk_parent_line)) {
731 $this->line_order(true, 'DESC');
732 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines
733 $linecount = count($this->lines);
734 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
735 $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1);
736 }
737 }
738
739 // Update denormalized information at the present proposal level
740 $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode.
741 if ($result > 0) {
742 $this->db->commit();
743 return $this->line->id;
744 } else {
745 $this->db->rollback();
746 return -1;
747 }
748 } else {
749 $this->setErrorsFromObject($this->line);
750 $this->db->rollback();
751 return -2;
752 }
753 } else {
754 $this->error = 'BadStatusOfObjectToAddLine';
755 return -5;
756 }
757 }
758
759
786 public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_options = [], $ref_supplier = '', $fk_unit = 0, $pu_ht_devise = 0)
787 {
788 global $mysoc, $langs;
789
790 if (!$this->isLineOfObject($rowid)) {
791 $this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
792 return -1;
793 }
794
795 dol_syslog(get_class($this)."::updateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
796 include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
797
798 // Clean parameters
799 $remise_percent = price2num($remise_percent);
800 $qty = (float) price2num($qty);
801 $pu = price2num($pu);
802 if (!preg_match('/\‍((.*)\‍)/', (string) $txtva)) {
803 $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
804 }
805 $txlocaltax1 = price2num($txlocaltax1);
806 $txlocaltax2 = price2num($txlocaltax2);
807 $pa_ht = price2num($pa_ht);
808 if (empty($qty) && empty($special_code)) {
809 $special_code = 3; // Set option tag
810 }
811 if (!empty($qty) && $special_code == 3) {
812 $special_code = 0; // Remove option tag
813 }
814
815 if ($this->status == 0) {
816 $this->db->begin();
817
818 // Calculation of the gross total (TTC) and VAT for the line from qty, pu, remise_percent and txtva
819 // VERY IMPORTANT: It's at the time of line insertion that we must store the net, VAT, and gross amounts,
820 // and this is done at the line level, which has its own VAT rate
821
822 $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
823
824 // Clean vat code
825 $reg = array();
826 $vat_src_code = '';
827 if (preg_match('/\‍((.*)\‍)/', $txtva, $reg)) {
828 $vat_src_code = $reg[1];
829 $txtva = preg_replace('/\s*\‍(.*\‍)/', '', $txtva); // Remove code into vatrate.
830 }
831
832 if (isModEnabled("multicurrency") && $pu_ht_devise > 0) {
833 $pu = 0;
834 }
835
836 // Round the quantity to the packaging before computing the amounts of the line,
837 // else the line is saved with the rounded quantity but with the amounts of the quantity before rounding
838 if (getDolGlobalString('PRODUCT_USE_SUPPLIER_PACKAGING')) {
839 $tmpline = new SupplierProposalLine($this->db);
840 if ($tmpline->fetch($rowid) > 0 && $tmpline->fk_product > 0) {
841 $prod = new Product($this->db);
842 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
843 $prod->get_buyprice(($fk_fournprice > 0 ? (int) $fk_fournprice : (int) $tmpline->fk_fournprice), (float) $qty, $tmpline->fk_product, 'none', $this->socid);
844
845 $newqty = $this->roundQtyToPackaging($qty, $prod->packaging);
846 if ($newqty != $qty) {
847 $qty = $newqty;
848 setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'warnings');
849 }
850 }
851 }
852
853 $tabprice = calcul_price_total(
854 $qty,
855 $pu,
856 (float) $remise_percent,
857 $txtva,
858 (float) $txlocaltax1,
859 (float) $txlocaltax2,
860 0,
861 $price_base_type,
862 $info_bits,
863 $type,
864 $this->thirdparty,
865 $localtaxes_type,
866 100,
867 (float) $this->multicurrency_tx,
868 $pu_ht_devise,
869 $this->multicurrency_code
870 );
871 $total_ht = $tabprice[0];
872 $total_tva = $tabprice[1];
873 $total_ttc = $tabprice[2];
874 $total_localtax1 = $tabprice[9];
875 $total_localtax2 = $tabprice[10];
876 $pu_ht = $tabprice[3];
877 $pu_tva = $tabprice[4];
878 $pu_ttc = $tabprice[5];
879
880 // MultiCurrency
881 $multicurrency_total_ht = $tabprice[16];
882 $multicurrency_total_tva = $tabprice[17];
883 $multicurrency_total_ttc = $tabprice[18];
884 $pu_ht_devise = $tabprice[19];
885
886 // Fetch current line from the database and then clone the object and set it in $oldline property
887 $line = new SupplierProposalLine($this->db);
888 $line->fetch($rowid);
889 $line->fetch_optionals();
890
891 $fk_product = $line->fk_product;
892
893 // Stock previous line records
894 $staticline = clone $line;
895
896 $line->oldline = $staticline;
897 $this->line = $line;
898 $this->line->context = $this->context;
899
900 // Reorder if fk_parent_line change
901 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
902 $rangmax = $this->line_max($fk_parent_line);
903 $this->line->rang = $rangmax + 1;
904 }
905
906 $this->line->id = $rowid;
907 $this->line->label = $label;
908 $this->line->desc = $desc;
909 $this->line->qty = $qty;
910 $this->line->product_type = $type;
911
912 $this->line->vat_src_code = $vat_src_code;
913 $this->line->tva_tx = $txtva;
914 $this->line->localtax1_tx = $txlocaltax1;
915 $this->line->localtax2_tx = $txlocaltax2;
916 $this->line->localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0];
917 $this->line->localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2];
918 $this->line->remise_percent = $remise_percent;
919 $this->line->subprice = (float) $pu_ht;
920 // Persist the original entry mode of the line so a no-op edit can preserve it later.
921 $this->line->subprice_ttc = ($price_base_type === 'TTC') ? (float) $pu_ttc : 0;
922 $this->line->info_bits = $info_bits;
923 $this->line->total_ht = (float) $total_ht;
924 $this->line->total_tva = (float) $total_tva;
925 $this->line->total_localtax1 = (float) $total_localtax1;
926 $this->line->total_localtax2 = (float) $total_localtax2;
927 $this->line->total_ttc = (float) $total_ttc;
928 $this->line->special_code = $special_code;
929 $this->line->fk_parent_line = $fk_parent_line;
930 $this->line->skip_update_total = $skip_update_total;
931 $this->line->ref_fourn = $ref_supplier;
932 $this->line->fk_unit = $fk_unit;
933
934 // infos merge
935 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
936 // by external module, take lowest buying price
937 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
938 $productFournisseur = new ProductFournisseur($this->db);
939 $productFournisseur->find_min_price_product_fournisseur($fk_product);
940 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
941 } else {
942 $this->line->fk_fournprice = $fk_fournprice;
943 }
944 $this->line->pa_ht = $pa_ht;
945
946 if (is_array($array_options) && count($array_options) > 0) {
947 // We replace values in this->line->array_options only for entries defined into $array_options
948 foreach ($array_options as $key => $value) {
949 $this->line->array_options[$key] = $array_options[$key];
950 }
951 }
952
953 // Multicurrency
954 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
955 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
956 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
957 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
958
959 $result = $this->line->update();
960 if ($result > 0) {
961 // Reorder if child line
962 if (!empty($fk_parent_line)) {
963 $this->line_order(true, 'DESC');
964 }
965
966 $this->update_price(1);
967
968 $this->db->commit();
969 return $result;
970 } else {
971 $this->error = $this->db->error();
972 $this->db->rollback();
973 return -1;
974 }
975 } else {
976 dol_syslog(get_class($this)."::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
977 return -2;
978 }
979 }
980
981
988 public function deleteLine($lineid)
989 {
990 global $user;
991
992 if ($this->status == 0) {
993 $line = new SupplierProposalLine($this->db);
994
995 // For triggers
996 $line->fetch($lineid);
997
998 if ($this->id > 0 && (int) $line->fk_supplier_proposal !== (int) $this->id) {
999 $this->error = 'ErrorLineIDDoesNotMatchWithObjectID';
1000 return -1;
1001 }
1002
1003 if ($line->delete($user) > 0) {
1004 $this->update_price(1);
1005
1006 return 1;
1007 } else {
1008 return -1;
1009 }
1010 } else {
1011 return -2;
1012 }
1013 }
1014
1015
1024 public function create($user, $notrigger = 0)
1025 {
1026 global $conf, $mysoc, $hookmanager;
1027 $error = 0;
1028
1029 $now = dol_now();
1030
1031 dol_syslog(get_class($this)."::create");
1032
1033 // Check parameters
1034 $result = $this->fetch_thirdparty();
1035 if ($result < 0) {
1036 $this->error = "Failed to fetch company";
1037 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
1038 return -3;
1039 }
1040 if (!empty($this->ref)) { // We check that ref is not already used
1041 $result = self::isExistingObject($this->element, 0, $this->ref); // Check ref is not yet used
1042 if ($result > 0) {
1043 $this->error = 'ErrorRefAlreadyExists';
1044 dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING);
1045 $this->db->rollback();
1046 return -1;
1047 }
1048 }
1049
1050 // Set tmp vars
1051 $delivery_date = $this->delivery_date;
1052
1053 // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if no rate was provided)
1054 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1055 list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $now);
1056 } elseif (!empty($this->multicurrency_code)) {
1057 $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
1058 }
1059 if (empty($this->fk_multicurrency)) {
1060 $this->multicurrency_code = getDolCurrency();
1061 $this->fk_multicurrency = 0;
1062 $this->multicurrency_tx = 1;
1063 }
1064
1065 $this->db->begin();
1066
1067 // Insert into database
1068 $sql = "INSERT INTO ".MAIN_DB_PREFIX."supplier_proposal (";
1069 $sql .= "fk_soc";
1070 $sql .= ", price";
1071 $sql .= ", total_tva";
1072 $sql .= ", total_ttc";
1073 $sql .= ", datec";
1074 $sql .= ", ref";
1075 $sql .= ", fk_user_author";
1076 $sql .= ", note_private";
1077 $sql .= ", note_public";
1078 $sql .= ", model_pdf";
1079 $sql .= ", fk_cond_reglement";
1080 $sql .= ", deposit_percent";
1081 $sql .= ", fk_mode_reglement";
1082 $sql .= ", fk_account";
1083 $sql .= ", date_livraison";
1084 $sql .= ", fk_shipping_method";
1085 $sql .= ", fk_projet";
1086 $sql .= ", entity";
1087 $sql .= ", fk_multicurrency";
1088 $sql .= ", multicurrency_code";
1089 $sql .= ", multicurrency_tx";
1090 $sql .= ") ";
1091 $sql .= " VALUES (";
1092 $sql .= ((int) $this->socid);
1093 $sql .= ", 0";
1094 $sql .= ", 0";
1095 $sql .= ", 0";
1096 $sql .= ", '".$this->db->idate($now)."'";
1097 $sql .= ", '(PROV)'";
1098 $sql .= ", ".($user->id > 0 ? ((int) $user->id) : "null");
1099 $sql .= ", '".$this->db->escape((string) $this->note_private)."'";
1100 $sql .= ", '".$this->db->escape((string) $this->note_public)."'";
1101 $sql .= ", '".$this->db->escape($this->model_pdf)."'";
1102 $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : 'NULL');
1103 $sql .= ", ".(!empty($this->deposit_percent) ? "'" . $this->db->escape($this->deposit_percent) . "'" : 'NULL');
1104 $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : 'NULL');
1105 $sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL');
1106 $sql .= ", ".(isDolTms($delivery_date) ? "'".$this->db->idate($delivery_date)."'" : "null");
1107 $sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : 'NULL');
1108 $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
1109 $sql .= ", ".((int) $conf->entity);
1110 $sql .= ", ".((int) $this->fk_multicurrency);
1111 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
1112 $sql .= ", ".((float) $this->multicurrency_tx);
1113 $sql .= ")";
1114
1115 dol_syslog(get_class($this)."::create", LOG_DEBUG);
1116 $resql = $this->db->query($sql);
1117 if ($resql) {
1118 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."supplier_proposal");
1119
1120 if ($this->id) {
1121 $this->ref = '(PROV'.$this->id.')';
1122 $sql = 'UPDATE '.MAIN_DB_PREFIX."supplier_proposal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".((int) $this->id);
1123
1124 dol_syslog(get_class($this)."::create", LOG_DEBUG);
1125 $resql = $this->db->query($sql);
1126 if (!$resql) {
1127 $error++;
1128 }
1129
1130 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects
1131 $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds
1132 }
1133
1134 // Add object linked
1135 if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1136 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1137 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, ...))
1138 foreach ($tmp_origin_id as $origin_id) {
1139 $ret = $this->add_object_linked($origin, $origin_id);
1140 if (!$ret) {
1141 dol_print_error($this->db);
1142 $error++;
1143 }
1144 }
1145 }
1146 }
1147 }
1148
1149 /*
1150 * Insert products details into database
1151 */
1152 if (!$error) {
1153 $fk_parent_line = 0;
1154 $num = count($this->lines);
1155
1156 for ($i = 0; $i < $num; $i++) {
1157 if (!is_object($this->lines[$i])) { // Lines coming from the REST API are plain arrays
1158 // Build a real line object: the code below calls methods on it
1159 // (getPriceBaseType), which an array cannot answer.
1160 $lineobj = new SupplierProposalLine($this->db);
1161 foreach ($this->lines[$i] as $key => $val) {
1162 $lineobj->$key = $val;
1163 }
1164 $this->lines[$i] = $lineobj;
1165 }
1166
1167 // Reset fk_parent_line for no child products and special product
1168 if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
1169 $fk_parent_line = 0;
1170 }
1171
1172 // Preserve the original entry mode of the line so the total is computed from the typed value (no rounding drift).
1173 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
1174 $result = $this->addline(
1175 $this->lines[$i]->desc,
1176 (float) $this->lines[$i]->subprice,
1177 $this->lines[$i]->qty,
1178 $this->lines[$i]->tva_tx,
1179 $this->lines[$i]->localtax1_tx,
1180 $this->lines[$i]->localtax2_tx,
1181 $this->lines[$i]->fk_product,
1182 $this->lines[$i]->remise_percent,
1183 $line_price_base_type,
1184 (float) $this->lines[$i]->subprice_ttc,
1185 0,
1186 $this->lines[$i]->product_type,
1187 $this->lines[$i]->rang,
1188 $this->lines[$i]->special_code,
1189 $fk_parent_line,
1190 $this->lines[$i]->fk_fournprice,
1191 $this->lines[$i]->pa_ht,
1192 empty($this->lines[$i]->label) ? '' : $this->lines[$i]->label, // deprecated
1193 $this->lines[$i]->array_options,
1194 $this->lines[$i]->ref_fourn,
1195 $this->lines[$i]->fk_unit,
1196 'supplier_proposal',
1197 $this->lines[$i]->rowid
1198 );
1199
1200 if ($result < 0) {
1201 $error++;
1202 $this->error = $this->db->error;
1203 dol_print_error($this->db);
1204 break;
1205 }
1206 // Defined the new fk_parent_line
1207 if ($result > 0 && $this->lines[$i]->product_type == 9) {
1208 $fk_parent_line = $result;
1209 }
1210 }
1211 }
1212
1213 if (!$error) {
1214 // Update denormalized data
1215 $resql = $this->update_price(1);
1216 if ($resql) {
1217 $action = 'update';
1218
1219 // Actions on extra fields
1220 if (!$error) {
1221 $result = $this->insertExtraFields();
1222 if ($result < 0) {
1223 $error++;
1224 }
1225 }
1226
1227 if (!$error && !$notrigger) {
1228 // Call trigger
1229 $result = $this->call_trigger('PROPOSAL_SUPPLIER_CREATE', $user);
1230 if ($result < 0) {
1231 $error++;
1232 }
1233 // End call triggers
1234 }
1235 } else {
1236 $this->error = $this->db->lasterror();
1237 $error++;
1238 }
1239 }
1240 } else {
1241 $this->error = $this->db->lasterror();
1242 $error++;
1243 }
1244
1245 if (!$error) {
1246 $this->db->commit();
1247 dol_syslog(get_class($this)."::create done id=".$this->id);
1248 return $this->id;
1249 } else {
1250 $this->db->rollback();
1251 return -2;
1252 }
1253 } else {
1254 $this->error = $this->db->lasterror();
1255 $this->db->rollback();
1256 return -1;
1257 }
1258 }
1259
1267 public function createFromClone(User $user, $fromid = 0)
1268 {
1269 global $hookmanager;
1270
1271 $error = 0;
1272 $now = dol_now();
1273
1274 $this->db->begin();
1275
1276 // get extrafields so they will be clone
1277 foreach ($this->lines as $line) {
1278 $line->fetch_optionals();
1279 }
1280
1281 // Load source object
1282 $objFrom = clone $this;
1283
1284 $objsoc = new Societe($this->db);
1285
1286 // Change socid if needed
1287 if (!empty($fromid) && $fromid != $this->socid) {
1288 if ($objsoc->fetch($fromid) > 0) {
1289 $this->socid = $objsoc->id;
1290 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1291 $this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent : 0);
1292 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1293 unset($this->fk_project);
1294 }
1295
1296 // TODO Change product price if multi-prices
1297 } else {
1298 $objsoc->fetch($this->socid);
1299 }
1300
1301 $this->id = 0;
1302 $this->status = 0;
1303 $this->statut = 0;
1304
1305 if (!getDolGlobalString('SUPPLIER_PROPOSAL_ADDON') || !is_readable(DOL_DOCUMENT_ROOT."/core/modules/supplier_proposal/" . getDolGlobalString('SUPPLIER_PROPOSAL_ADDON').".php")) {
1306 $this->error = 'ErrorSetupNotComplete';
1307 return -1;
1308 }
1309
1310 // Clear fields
1311 $this->user_author_id = $user->id;
1312 $this->user_validation_id = 0;
1313 $this->date = $now;
1314
1315 // Set ref
1316 require_once DOL_DOCUMENT_ROOT."/core/modules/supplier_proposal/" . getDolGlobalString('SUPPLIER_PROPOSAL_ADDON').'.php';
1317 $obj = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON');
1318 $modSupplierProposal = new $obj();
1319 '@phan-var-force ModeleNumRefSupplierProposal $modSupplierProposal';
1320 $this->ref = $modSupplierProposal->getNextValue($objsoc, $this);
1321
1322 // Create clone
1323 $this->context['createfromclone'] = 'createfromclone';
1324 $result = $this->create($user);
1325 if ($result < 0) {
1326 $error++;
1327 }
1328
1329 if (!$error) {
1330 // Hook of thirdparty module
1331 if (is_object($hookmanager)) {
1332 $parameters = array('objFrom' => $objFrom);
1333 $action = '';
1334 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1335 if ($reshook < 0) {
1336 $this->setErrorsFromObject($hookmanager);
1337 $error++;
1338 }
1339 }
1340 }
1341
1342 unset($this->context['createfromclone']);
1343
1344 // End
1345 if (!$error) {
1346 $this->db->commit();
1347 return $this->id;
1348 } else {
1349 $this->db->rollback();
1350 return -1;
1351 }
1352 }
1353
1361 public function fetch($rowid, $ref = '')
1362 {
1363 $sql = "SELECT p.rowid, p.entity, p.ref, p.fk_soc as socid";
1364 $sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1365 $sql .= ", p.datec, GREATEST(p.tms, COALESCE(pef.tms, p.tms)) as date_modification";
1366 $sql .= ", p.date_valid as datev";
1367 $sql .= ", p.date_livraison as delivery_date";
1368 $sql .= ", p.model_pdf, p.extraparams";
1369 $sql .= ", p.note_private, p.note_public";
1370 $sql .= ", p.fk_projet as fk_project, p.fk_statut as status";
1371 $sql .= ", p.fk_user_author, p.fk_user_modif, p.fk_user_valid, p.fk_user_cloture";
1372 $sql .= ", p.fk_cond_reglement";
1373 $sql .= ", p.fk_mode_reglement";
1374 $sql .= ', p.fk_account';
1375 $sql .= ", p.fk_shipping_method";
1376 $sql .= ", p.last_main_doc";
1377 $sql .= ", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1378 $sql .= ", c.label as statut_label";
1379 $sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1380 $sql .= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1381 $sql .= " FROM ".MAIN_DB_PREFIX."c_propalst as c, ".MAIN_DB_PREFIX."supplier_proposal as p";
1382 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."supplier_proposal_extrafields as pef ON pef.fk_object=p.rowid";
1383 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as cp ON p.fk_mode_reglement = cp.id';
1384 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid';
1385 $sql .= " WHERE p.fk_statut = c.id";
1386 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
1387 if ($ref) {
1388 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
1389 } else {
1390 $sql .= " AND p.rowid = ".((int) $rowid);
1391 }
1392
1393 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
1394 $resql = $this->db->query($sql);
1395 if ($resql) {
1396 if ($this->db->num_rows($resql)) {
1397 $obj = $this->db->fetch_object($resql);
1398
1399 $this->id = $obj->rowid;
1400 $this->entity = $obj->entity;
1401
1402 $this->ref = $obj->ref;
1403 $this->total_ht = $obj->total_ht;
1404 $this->total_tva = $obj->total_tva;
1405 $this->total_localtax1 = $obj->localtax1;
1406 $this->total_localtax2 = $obj->localtax2;
1407 $this->total_ttc = $obj->total_ttc;
1408 $this->socid = $obj->socid;
1409 $this->fk_project = $obj->fk_project;
1410 $this->model_pdf = $obj->model_pdf;
1411 $this->note = $obj->note_private; // TODO deprecated
1412 $this->note_private = $obj->note_private;
1413 $this->note_public = $obj->note_public;
1414 $this->statut = (int) $obj->status;
1415 $this->status = (int) $obj->status;
1416 $this->datec = $this->db->jdate($obj->datec); // TODO deprecated
1417 $this->datev = $this->db->jdate($obj->datev); // TODO deprecated
1418 $this->date_creation = $this->db->jdate($obj->datec); // Creation date
1419 $this->date_modification = $this->db->jdate($obj->date_modification); // Modification date
1420 $this->date = $this->date_creation;
1421 $this->date_validation = $this->db->jdate($obj->datev); // Validation date
1422 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1423 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1424
1425 $this->last_main_doc = $obj->last_main_doc;
1426 $this->mode_reglement_id = $obj->fk_mode_reglement;
1427 $this->mode_reglement_code = $obj->mode_reglement_code;
1428 $this->mode_reglement = $obj->mode_reglement;
1429 $this->deposit_percent = $obj->deposit_percent;
1430 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account : null;
1431 $this->cond_reglement_id = $obj->fk_cond_reglement;
1432 $this->cond_reglement_code = $obj->cond_reglement_code;
1433 $this->cond_reglement = $obj->cond_reglement;
1434 $this->cond_reglement_label = $obj->cond_reglement;
1435 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1436
1437 $this->extraparams = (array) (!empty($obj->extraparams) ? json_decode($obj->extraparams, true) : array());
1438
1439 $this->user_author_id = $obj->fk_user_author;
1440 $this->user_modification_id = $obj->fk_user_modif;
1441 $this->user_validation_id = $obj->fk_user_valid;
1442 $this->user_closing_id = $obj->fk_user_cloture;
1443
1444 // Multicurrency
1445 $this->fk_multicurrency = $obj->fk_multicurrency;
1446 $this->multicurrency_code = $obj->multicurrency_code;
1447 $this->multicurrency_tx = $obj->multicurrency_tx;
1448 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1449 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1450 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1451
1452 $this->db->free($resql);
1453
1454 // Retrieve all extrafield
1455 // fetch optionals attributes and labels
1456 $this->fetch_optionals();
1457
1458 $this->lines = array();
1459
1460 // Lines of supplier proposals
1461 $sql = "SELECT d.rowid, d.fk_supplier_proposal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.subprice_ttc, d.fk_product,";
1462 $sql .= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
1463 $sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1464 $sql .= ' d.ref_fourn as ref_produit_fourn, d.extraparams,';
1465 $sql .= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc, d.fk_unit';
1466 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d";
1467 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON d.fk_product = p.rowid";
1468 $sql .= " WHERE d.fk_supplier_proposal = ".((int) $this->id);
1469 $sql .= " ORDER by d.rang";
1470
1471 $result = $this->db->query($sql);
1472 if ($result) {
1473 $num = $this->db->num_rows($result);
1474 $i = 0;
1475
1476 while ($i < $num) {
1477 $objp = $this->db->fetch_object($result);
1478
1479 $line = new SupplierProposalLine($this->db);
1480
1481 $line->rowid = $objp->rowid; // deprecated
1482 $line->id = $objp->rowid;
1483 $line->fk_supplier_proposal = $objp->fk_supplier_proposal;
1484 $line->fk_parent_line = $objp->fk_parent_line;
1485 $line->product_type = $objp->product_type;
1486 $line->label = $objp->custom_label;
1487 $line->desc = $objp->description; // Description of the line
1488 $line->qty = $objp->qty;
1489 $line->tva_tx = $objp->tva_tx;
1490 $line->localtax1_tx = $objp->localtax1_tx;
1491 $line->localtax2_tx = $objp->localtax2_tx;
1492 $line->subprice = $objp->subprice;
1493 $line->subprice_ttc = $objp->subprice_ttc;
1494 $line->fk_remise_except = $objp->fk_remise_except;
1495 $line->remise_percent = $objp->remise_percent;
1496
1497 $line->info_bits = $objp->info_bits;
1498 $line->total_ht = $objp->total_ht;
1499 $line->total_tva = $objp->total_tva;
1500 $line->total_localtax1 = $objp->total_localtax1;
1501 $line->total_localtax2 = $objp->total_localtax2;
1502 $line->total_ttc = $objp->total_ttc;
1503 $line->fk_fournprice = $objp->fk_fournprice;
1504 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1505 $line->pa_ht = $marginInfos[0];
1506 $line->marge_tx = $marginInfos[1];
1507 $line->marque_tx = $marginInfos[2];
1508 $line->special_code = $objp->special_code;
1509 $line->rang = $objp->rang;
1510
1511 $line->fk_product = $objp->fk_product;
1512
1513 $line->ref = $objp->product_ref; // deprecated
1514 $line->product_ref = $objp->product_ref;
1515 $line->libelle = $objp->product_label; // deprecated
1516 $line->product_label = $objp->product_label;
1517 $line->product_desc = $objp->product_desc; // Description produit
1518 $line->fk_product_type = $objp->fk_product_type;
1519
1520 $line->ref_fourn = $objp->ref_produit_fourn;
1521
1522 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
1523
1524 // Multicurrency
1525 $line->fk_multicurrency = $objp->fk_multicurrency;
1526 $line->multicurrency_code = $objp->multicurrency_code;
1527 $line->multicurrency_subprice = $objp->multicurrency_subprice;
1528 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
1529 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
1530 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
1531 $line->fk_unit = $objp->fk_unit;
1532
1533 $line->fetch_optionals();
1534
1535 $this->lines[$i] = $line;
1536
1537 $i++;
1538 }
1539 $this->db->free($result);
1540 } else {
1541 $this->error = $this->db->error();
1542 return -1;
1543 }
1544
1545 return 1;
1546 }
1547
1548 $this->error = "Record Not Found";
1549 return 0;
1550 } else {
1551 $this->error = $this->db->error();
1552 return -1;
1553 }
1554 }
1555
1563 public function update($user, $notrigger = 0)
1564 {
1565 $error = 0;
1566
1567 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal SET";
1568 $sql .= " fk_projet = ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
1569 $sql .= ", fk_cond_reglement = ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
1570 $sql .= ", fk_mode_reglement = ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
1571 $sql .= ", fk_account = ".($this->fk_account > 0 ? ((int) $this->fk_account) : "null");
1572 $sql .= ", fk_shipping_method = ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null");
1573 $sql .= ", date_livraison = ".($this->delivery_date ? "'".$this->db->idate($this->delivery_date)."'" : "null");
1574 $sql .= ", note_private = ".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
1575 $sql .= ", note_public = ".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
1576 $sql .= ", model_pdf = ".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null");
1577 $sql .= ", fk_user_modif = ".((int) $user->id);
1578 $sql .= " WHERE rowid = ".((int) $this->id);
1579
1580 $this->db->begin();
1581
1582 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1583 $resql = $this->db->query($sql);
1584 if (!$resql) {
1585 $error++;
1586 $this->errors[] = "Error ".$this->db->lasterror();
1587 }
1588
1589 if (!$error) {
1590 $result = $this->insertExtraFields();
1591 if ($result < 0) {
1592 $error++;
1593 }
1594 }
1595
1596 if (!$error && !$notrigger) {
1597 // Call trigger
1598 $result = $this->call_trigger('PROPOSAL_SUPPLIER_MODIFY', $user);
1599 if ($result < 0) {
1600 $error++;
1601 }
1602 // End call triggers
1603 }
1604
1605 if ($error) {
1606 $this->error = implode(', ', $this->errors);
1607 $this->db->rollback();
1608 return -1 * $error;
1609 }
1610
1611 $this->db->commit();
1612 return 1;
1613 }
1614
1622 public function valid($user, $notrigger = 0)
1623 {
1624 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1625
1626 global $conf;
1627
1628 $error = 0;
1629 $now = dol_now();
1630
1631 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('supplier_proposal', 'creer'))
1632 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('supplier_proposal', 'validate_advance'))) {
1633 $this->db->begin();
1634
1635 // Numbering module definition
1636 $soc = new Societe($this->db);
1637 $result = $soc->fetch($this->socid);
1638
1639 if ($result < 0) {
1640 return -1;
1641 }
1642 if (!getDolGlobalBool('SUPPLIER_PROPOSAL_NOCHECK_ONBUY_PRODUCTS_ONVALID') && !$this->checkActiveProductInLines('onbuy')) {
1643 dol_syslog(get_class($this)."::valid checkActiveProductInLines ".$this->error, LOG_INFO);
1644 return -1;
1645 }
1646 // Define new ref
1647 if (preg_match('/^[\‍(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
1648 $num = $this->getNextNumRef($soc);
1649 } else {
1650 $num = (string) $this->ref;
1651 }
1652 $this->newref = dol_sanitizeFileName($num);
1653
1654 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1655 $sql .= " SET ref = '".$this->db->escape($num)."',";
1656 $sql .= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".((int) $user->id);
1657 $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = 0";
1658
1659 dol_syslog(get_class($this)."::valid", LOG_DEBUG);
1660 $resql = $this->db->query($sql);
1661 if (!$resql) {
1662 dol_print_error($this->db);
1663 $error++;
1664 }
1665
1666 // Trigger calls
1667 if (!$error && !$notrigger) {
1668 // Call trigger
1669 $result = $this->call_trigger('PROPOSAL_SUPPLIER_VALIDATE', $user);
1670 if ($result < 0) {
1671 $error++;
1672 }
1673 // End call triggers
1674 }
1675
1676 if (!$error) {
1677 $this->oldref = $this->ref;
1678
1679 // Rename directory if dir was a temporary ref
1680 if (preg_match('/^[\‍(]?PROV/i', $this->ref)) {
1681 // Now we rename also files into index
1682 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'supplier_proposal/".$this->db->escape($this->newref)."'";
1683 $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'supplier_proposal/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
1684 $resql = $this->db->query($sql);
1685 if (!$resql) {
1686 $error++;
1687 $this->error = $this->db->lasterror();
1688 }
1689 $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'supplier_proposal/".$this->db->escape($this->newref)."'";
1690 $sql .= " WHERE filepath = 'supplier_proposal/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
1691 $resql = $this->db->query($sql);
1692 if (!$resql) {
1693 $error++;
1694 $this->error = $this->db->lasterror();
1695 }
1696
1697 // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
1698 $oldref = dol_sanitizeFileName($this->ref);
1699 $newref = dol_sanitizeFileName($num);
1700 $dirsource = $conf->supplier_proposal->dir_output.'/'.$oldref;
1701 $dirdest = $conf->supplier_proposal->dir_output.'/'.$newref;
1702 if (!$error && file_exists($dirsource)) {
1703 dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
1704 if (@rename($dirsource, $dirdest)) {
1705 dol_syslog("Rename ok");
1706 // Rename docs starting with $oldref with $newref
1707 $listoffiles = dol_dir_list($conf->supplier_proposal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
1708 foreach ($listoffiles as $fileentry) {
1709 $dirsource = $fileentry['name'];
1710 $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
1711 $dirsource = $fileentry['path'].'/'.$dirsource;
1712 $dirdest = $fileentry['path'].'/'.$dirdest;
1713 @rename($dirsource, $dirdest);
1714 }
1715 }
1716 }
1717 }
1718
1719 $this->ref = $num;
1720 $this->statut = self::STATUS_VALIDATED;
1722 $this->user_validation_id = $user->id;
1723 $this->datev = $now;
1724 $this->date_validation = $now;
1725
1726 if (getDolGlobalString('SUPPLIER_PROPOSAL_AUTOADD_USER_CONTACT')) {
1727 $result = $this->add_contact($user->id, 'SALESREPFOLL', 'internal', 1);
1728 if ($result < 0 && $result != -2) { // -2 means already exists
1729 $error++;
1730 }
1731 }
1732
1733 $this->db->commit();
1734 return 1;
1735 } else {
1736 $this->db->rollback();
1737 return -1;
1738 }
1739 } else {
1740 dol_syslog("You don't have permission to validate supplier proposal", LOG_WARNING);
1741 return -2;
1742 }
1743 }
1744
1745 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1754 public function set_date_livraison($user, $delivery_date)
1755 {
1756 // phpcs:enable
1757 return $this->setDeliveryDate($user, $delivery_date);
1758 }
1759
1767 public function setDeliveryDate($user, $delivery_date)
1768 {
1769 if ($user->hasRight('supplier_proposal', 'creer')) {
1770 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal ";
1771 $sql .= " SET date_livraison = ".(isDolTms($delivery_date) ? "'".$this->db->idate($delivery_date)."'" : 'null');
1772 $sql .= " WHERE rowid = ".((int) $this->id);
1773
1774 if ($this->db->query($sql)) {
1775 $this->delivery_date = $delivery_date;
1776 return 1;
1777 } else {
1778 $this->error = $this->db->error();
1779 dol_syslog(get_class($this)."::setDeliveryDate Erreur SQL");
1780 return -1;
1781 }
1782 }
1783 return 0;
1784 }
1785
1786
1796 public function reopen($user, $status, $note = '', $notrigger = 0)
1797 {
1798 $error = 0;
1799
1800 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1801 $sql .= " SET fk_statut = ".((int) $status).",";
1802 if (!empty($note)) {
1803 $sql .= " note_private = '".$this->db->escape($note)."',";
1804 }
1805 $sql .= " date_cloture = NULL, fk_user_cloture = NULL";
1806 $sql .= " WHERE rowid = ".((int) $this->id);
1807
1808 $this->db->begin();
1809
1810 dol_syslog(get_class($this)."::reopen", LOG_DEBUG);
1811 $resql = $this->db->query($sql);
1812 if (!$resql) {
1813 $error++;
1814 $this->errors[] = "Error ".$this->db->lasterror();
1815 }
1816 if (!$error) {
1817 if (!$notrigger) {
1818 // Call trigger
1819 $result = $this->call_trigger('PROPOSAL_SUPPLIER_REOPEN', $user);
1820 if ($result < 0) {
1821 $error++;
1822 }
1823 // End call triggers
1824 }
1825 }
1826
1827 // Commit or rollback
1828 if ($error) {
1829 if (!empty($this->errors)) {
1830 foreach ($this->errors as $errmsg) {
1831 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
1832 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1833 }
1834 }
1835 $this->db->rollback();
1836 return -1 * $error;
1837 } else {
1838 $this->statut = $status;
1839 $this->status = $status;
1840
1841 $this->db->commit();
1842 return 1;
1843 }
1844 }
1845
1846
1855 public function cloture($user, $status, $note)
1856 {
1857 global $langs, $conf;
1858 $hidedetails = 0;
1859 $hidedesc = 0;
1860 $hideref = 0;
1861
1862 $error = 0;
1863 $now = dol_now();
1864
1865 $this->db->begin();
1866
1867 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
1868 $sql .= " SET fk_statut = ".((int) $status).", note_private = '".$this->db->escape($note)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".((int) $user->id);
1869 $sql .= " WHERE rowid = ".((int) $this->id);
1870
1871 $resql = $this->db->query($sql);
1872 if ($resql) {
1873 $this->statut = $status;
1874 $this->status = $status;
1875
1876 $modelpdf = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED', (empty($this->model_pdf) ? '' : $this->model_pdf));
1877 $triggerName = 'PROPOSAL_SUPPLIER_CLOSE_REFUSED';
1878
1879 if ($status == 2) {
1880 $triggerName = 'PROPOSAL_SUPPLIER_CLOSE_SIGNED';
1881 $modelpdf = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL', (empty($this->model_pdf) ? '' : $this->model_pdf));
1882
1883 if (getDolGlobalString('SUPPLIER_PROPOSAL_UPDATE_PRICE_ON_SUPPlIER_PROPOSAL')) { // TODO This option was not tested correctly. Error if product ref does not exists
1884 $result = $this->updateOrCreatePriceFournisseur($user);
1885 }
1886 }
1887 if ($status == 4) {
1888 $triggerName = 'PROPOSAL_SUPPLIER_CLASSIFY_BILLED';
1889 }
1890
1891 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1892 // Define output language
1893 $outputlangs = $langs;
1894 if (getDolGlobalInt('MAIN_MULTILANGS')) {
1895 $outputlangs = new Translate("", $conf);
1896 $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang);
1897 $outputlangs->setDefaultLang($newlang);
1898 }
1899
1900 $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1901 }
1902
1903 // Call trigger
1904 $result = $this->call_trigger($triggerName, $user);
1905 if ($result < 0) {
1906 $error++;
1907 }
1908 // End call triggers
1909
1910 if (!$error) {
1911 $this->db->commit();
1912 return 1;
1913 } else {
1914 $this->db->rollback();
1915 return -1;
1916 }
1917 } else {
1918 $this->error = $this->db->lasterror();
1919 $this->errors[] = $this->db->lasterror();
1920 $this->db->rollback();
1921 return -1;
1922 }
1923 }
1924
1931 public function updateOrCreatePriceFournisseur($user)
1932 {
1933 dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
1934
1935 foreach ($this->lines as $product) {
1936 if ($product->subprice <= 0) {
1937 continue;
1938 }
1939 $productsupplier = new ProductFournisseur($this->db);
1940
1941 $multicurrency_tx = 1;
1942 $fk_multicurrency = 0;
1943
1944 if (empty($this->thirdparty)) {
1945 $this->fetch_thirdparty();
1946 }
1947
1948 $ref_fourn = $product->ref_fourn;
1949 if (empty($ref_fourn)) {
1950 $ref_fourn = $product->ref_supplier;
1951 }
1952 if (isModEnabled("multicurrency") && !empty($product->multicurrency_code)) {
1953 list($fk_multicurrency, $multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $product->multicurrency_code);
1954 }
1955 $productsupplier->id = $product->fk_product;
1956
1957 $productsupplier->update_buyprice($product->qty, $product->total_ht, $user, 'HT', $this->thirdparty, 0, $ref_fourn, $product->tva_tx, 0, 0, 0, $product->info_bits, 0, '', array(), '', $product->multicurrency_total_ht, 'HT', $multicurrency_tx, $product->multicurrency_code, '', '', 0);
1958 }
1959
1960 return 1;
1961 }
1962
1971 public function updatePriceFournisseur($idProductFournPrice, $product, $user)
1972 {
1973 $price = price2num($product->subprice * $product->qty, 'MU');
1974 $unitPrice = price2num($product->subprice, 'MU');
1975
1976 $sql = 'UPDATE '.MAIN_DB_PREFIX.'product_fournisseur_price SET '.(!empty($product->ref_fourn) ? 'ref_fourn = "'.$this->db->escape($product->ref_fourn).'", ' : '').' price ='.((float) $price).', unitprice ='.((float) $unitPrice).' WHERE rowid = '.((int) $idProductFournPrice);
1977
1978 $resql = $this->db->query($sql);
1979 if (!$resql) {
1980 $this->error = $this->db->error();
1981 $this->db->rollback();
1982 return -1;
1983 }
1984 return 1;
1985 }
1986
1994 public function createPriceFournisseur($product, $user)
1995 {
1996 $price = price2num($product->subprice * $product->qty, 'MU');
1997 $qty = price2num($product->qty);
1998 $unitPrice = price2num($product->subprice, 'MU');
1999
2000 $now = dol_now();
2001
2002 $sanitized_values = array(
2003 "'".$this->db->idate($now)."'",
2004 (int) $product->fk_product,
2005 (int) $this->thirdparty->id,
2006 "'".$this->db->escape($product->ref_fourn)."'",
2007 (float) $price,
2008 (float) $qty,
2009 (float) $unitPrice,
2010 (float) $product->tva_tx,
2011 (int) $user->id
2012 );
2013 if (isModEnabled("multicurrency")) {
2014 if (!empty($product->multicurrency_code)) {
2015 include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
2016 $multicurrency = new MultiCurrency($this->db); //need to fetch because empty fk_multicurrency and rate
2017 $multicurrency->fetch(0, $product->multicurrency_code);
2018 if (!empty($multicurrency->id)) {
2019 $sanitized_values[] = (int) $multicurrency->id;
2020 $sanitized_values[] = "'".$this->db->escape($product->multicurrency_code)."'";
2021 $sanitized_values[] = (float) $product->multicurrency_subprice;
2022 $sanitized_values[] = (float) $product->multicurrency_total_ht;
2023 $sanitized_values[] = (float) $multicurrency->rate->rate;
2024 } else {
2025 for ($i = 0; $i < 5; $i++) {
2026 $sanitized_values[] = 'NULL';
2027 }
2028 }
2029 }
2030 }
2031
2032 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_fournisseur_price ';
2033 $sql .= '(datec, fk_product, fk_soc, ref_fourn, price, quantity, unitprice, tva_tx, fk_user';
2034 if (isModEnabled("multicurrency") && !empty($product->multicurrency_code)) {
2035 $sql .= ',fk_multicurrency, multicurrency_code, multicurrency_unitprice, multicurrency_price, multicurrency_tx';
2036 }
2037 $sql .= ') VALUES ('.implode(',', $sanitized_values).')';
2038
2039 $resql = $this->db->query($sql);
2040 if (!$resql) {
2041 $this->error = $this->db->error();
2042 $this->db->rollback();
2043 return -1;
2044 }
2045 return 1;
2046 }
2047
2048 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2055 public function setDraft($user)
2056 {
2057 // phpcs:enable
2058 $error = 0;
2059
2060 if ($this->status == self::STATUS_DRAFT) {
2061 dol_syslog(get_class($this)."::setDraft already draft status", LOG_WARNING);
2062 return 0;
2063 }
2064
2065 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal";
2066 $sql .= " SET fk_statut = ".self::STATUS_DRAFT;
2067 $sql .= " WHERE rowid = ".((int) $this->id);
2068
2069 if ($this->db->query($sql)) {
2070 if (!$error) {
2071 $this->oldcopy = clone $this;
2072 }
2073
2074 if (!$error) {
2075 // Call trigger
2076 $result = $this->call_trigger('PROPOSAL_SUPPLIER_UNVALIDATE', $user);
2077 if ($result < 0) {
2078 $error++;
2079 }
2080 }
2081
2082 if (!$error) {
2083 $this->status = self::STATUS_DRAFT;
2084 $this->statut = self::STATUS_DRAFT; // deprecated
2085 $this->db->commit();
2086 return 1;
2087 } else {
2088 $this->db->rollback();
2089 return -1;
2090 }
2091 } else {
2092 return -1;
2093 }
2094 }
2095
2096
2097 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2111 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datec', $sortorder = 'DESC')
2112 {
2113 // phpcs:enable
2114 global $user;
2115
2116 $ga = array();
2117
2118 $search_sale = 0;
2119 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
2120 $search_sale = $user->id;
2121 }
2122
2123 $sql = "SELECT s.rowid, s.nom as name, s.client,";
2124 $sql .= " p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2125 $sql .= " p.datep as dp, p.fin_validite as datelimite";
2126 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."c_propalst as c";
2127 $sql .= " WHERE p.entity IN (".getEntity('supplier_proposal').")";
2128 $sql .= " AND p.fk_soc = s.rowid";
2129 $sql .= " AND p.fk_statut = c.id";
2130 if ($socid) {
2131 $sql .= " AND s.rowid = ".((int) $socid);
2132 }
2133 if ($draft) {
2134 $sql .= " AND p.fk_statut = 0";
2135 }
2136 if ($notcurrentuser > 0) {
2137 $sql .= " AND p.fk_user_author <> ".((int) $user->id);
2138 }
2139 // Search on sale representative
2140 if ($search_sale && $search_sale != '-1') {
2141 if ($search_sale == -2) {
2142 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
2143 } elseif ($search_sale > 0) {
2144 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
2145 }
2146 }
2147 $sql .= $this->db->order($sortfield, $sortorder);
2148 $sql .= $this->db->plimit($limit, $offset);
2149
2150 $result = $this->db->query($sql);
2151 if ($result) {
2152 $num = $this->db->num_rows($result);
2153 if ($num) {
2154 $i = 0;
2155 while ($i < $num) {
2156 $obj = $this->db->fetch_object($result);
2157
2158 if ($shortlist == 1) {
2159 $ga[$obj->supplier_proposalid] = $obj->ref;
2160 } elseif ($shortlist == 2) {
2161 $ga[$obj->supplier_proposalid] = $obj->ref.' ('.$obj->name.')';
2162 } else {
2163 $ga[$i]['id'] = $obj->supplier_proposalid;
2164 $ga[$i]['ref'] = $obj->ref;
2165 $ga[$i]['name'] = $obj->name;
2166 }
2167
2168 $i++;
2169 }
2170 }
2171 return $ga;
2172 } else {
2173 dol_print_error($this->db);
2174 return -1;
2175 }
2176 }
2177
2185 public function delete($user, $notrigger = 0)
2186 {
2187 global $conf;
2188 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2189
2190 $error = 0;
2191
2192 $this->db->begin();
2193
2194 if (!$notrigger) {
2195 // Call trigger
2196 $result = $this->call_trigger('PROPOSAL_SUPPLIER_DELETE', $user);
2197 if ($result < 0) {
2198 $error++;
2199 }
2200 // End call triggers
2201 }
2202
2203 // Remove linked categories.
2204 if (!$error) {
2205 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_supplier_proposal";
2206 $sql .= " WHERE fk_supplier_proposal = ".((int) $this->id);
2207
2208 $result = $this->db->query($sql);
2209 if (!$result) {
2210 $error++;
2211 $this->error = $this->db->lasterror();
2212 $this->errors[] = $this->error;
2213 }
2214 }
2215
2216 if (!$error) {
2217 $sanitized_main = MAIN_DB_PREFIX.'supplier_proposaldet';
2218 $sanitized_ef = $sanitized_main."_extrafields";
2219 $sqlef = "DELETE FROM $sanitized_ef WHERE fk_object IN (SELECT rowid FROM $sanitized_main WHERE fk_supplier_proposal = ".((int) $this->id).")";
2220 $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet WHERE fk_supplier_proposal = ".((int) $this->id);
2221 if ($this->db->query($sql)) {
2222 $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposal WHERE rowid = ".((int) $this->id);
2223 if ($this->db->query($sqlef) && $this->db->query($sql)) {
2224 // Delete linked object
2225 $res = $this->deleteObjectLinked();
2226 if ($res < 0) {
2227 $error++;
2228 }
2229
2230 if (!$error) {
2231 // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive
2232 $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive
2233 $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive
2234
2235 // We remove directory
2236 $ref = dol_sanitizeFileName($this->ref);
2237 if ($conf->supplier_proposal->dir_output && !empty($this->ref)) {
2238 $dir = $conf->supplier_proposal->dir_output."/".$ref;
2239 $file = $dir."/".$ref.".pdf";
2240 if (file_exists($file)) {
2241 dol_delete_preview($this);
2242
2243 if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers
2244 $this->error = 'ErrorFailToDeleteFile';
2245 $this->errors = array('ErrorFailToDeleteFile');
2246 $this->db->rollback();
2247 return 0;
2248 }
2249 }
2250 if (file_exists($dir)) {
2251 $res = @dol_delete_dir_recursive($dir);
2252 if (!$res) {
2253 $this->error = 'ErrorFailToDeleteDir';
2254 $this->errors = array('ErrorFailToDeleteDir');
2255 $this->db->rollback();
2256 return 0;
2257 }
2258 }
2259 }
2260 }
2261
2262 // Removed extrafields
2263 if (!$error) {
2264 $result = $this->deleteExtraFields();
2265 if ($result < 0) {
2266 $error++;
2267 $errorflag = -4;
2268 dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
2269 }
2270 }
2271
2272 if (!$error) {
2273 dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG);
2274 $this->db->commit();
2275 return 1;
2276 } else {
2277 $this->error = $this->db->lasterror();
2278 $this->db->rollback();
2279 return 0;
2280 }
2281 } else {
2282 $this->error = $this->db->lasterror();
2283 $this->db->rollback();
2284 return -3;
2285 }
2286 } else {
2287 $this->error = $this->db->lasterror();
2288 $this->db->rollback();
2289 return -2;
2290 }
2291 } else {
2292 $this->db->rollback();
2293 return -1;
2294 }
2295 }
2296
2303 public function info($id)
2304 {
2305 $sql = "SELECT c.rowid, GREATEST(c.tms, COALESCE(cef.tms, c.tms)) as date_modification,";
2306 $sql .= " c.datec as date_creation, c.date_valid as date_validation, c.date_cloture as date_closure,";
2307 $sql .= " c.fk_user_author, c.fk_user_modif, c.fk_user_valid, c.fk_user_cloture";
2308 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
2309 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."supplier_proposal_extrafields as cef ON cef.fk_object=c.rowid";
2310 $sql .= " WHERE c.rowid = ".((int) $id);
2311
2312 $result = $this->db->query($sql);
2313
2314 if ($result) {
2315 if ($this->db->num_rows($result)) {
2316 $obj = $this->db->fetch_object($result);
2317
2318 $this->id = $obj->rowid;
2319
2320 $this->date_creation = $this->db->jdate($obj->date_creation);
2321 $this->date_modification = empty($obj->date_modification) ? '' : $this->db->jdate($obj->date_modification);
2322 $this->date_validation = $this->db->jdate($obj->date_validation);
2323 $this->date_cloture = $this->db->jdate($obj->date_closure);
2324
2325 $this->user_creation_id = $obj->fk_user_author;
2326 $this->user_modification_id = $obj->fk_user_modif;
2327 $this->user_validation_id = $obj->fk_user_valid;
2328 $this->user_closing_id = $obj->fk_user_cloture;
2329 }
2330 $this->db->free($result);
2331 } else {
2332 dol_print_error($this->db);
2333 }
2334 }
2335
2336
2343 public function getLibStatut($mode = 0)
2344 {
2345 return $this->LibStatut((isset($this->status) ? $this->status : $this->statut), $mode);
2346 }
2347
2348 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2356 public function LibStatut($status, $mode = 1)
2357 {
2358 // phpcs:enable
2359
2360 // Init/load array of translation of status
2361 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2362 global $langs;
2363 $langs->load("supplier_proposal");
2364 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv("SupplierProposalStatusDraft");
2365 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv("SupplierProposalStatusValidated");
2366 $this->labelStatus[self::STATUS_SIGNED] = $langs->transnoentitiesnoconv("SupplierProposalStatusSigned");
2367 $this->labelStatus[self::STATUS_NOTSIGNED] = $langs->transnoentitiesnoconv("SupplierProposalStatusNotSigned");
2368 $this->labelStatus[self::STATUS_CLOSE] = $langs->transnoentitiesnoconv("SupplierProposalStatusClosed");
2369 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv("SupplierProposalStatusDraftShort");
2370 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv("SupplierProposalStatusValidatedShort");
2371 $this->labelStatusShort[self::STATUS_SIGNED] = $langs->transnoentitiesnoconv("SupplierProposalStatusSignedShort");
2372 $this->labelStatusShort[self::STATUS_NOTSIGNED] = $langs->transnoentitiesnoconv("SupplierProposalStatusNotSignedShort");
2373 $this->labelStatusShort[self::STATUS_CLOSE] = $langs->transnoentitiesnoconv("SupplierProposalStatusClosedShort");
2374 }
2375
2376 $statusnew = '';
2377 if ($status == self::STATUS_DRAFT) {
2378 $statusnew = 'status0';
2379 } elseif ($status == self::STATUS_VALIDATED) {
2380 $statusnew = 'status1';
2381 } elseif ($status == self::STATUS_SIGNED) {
2382 $statusnew = 'status4';
2383 } elseif ($status == self::STATUS_NOTSIGNED) {
2384 $statusnew = 'status9';
2385 } elseif ($status == self::STATUS_CLOSE) {
2386 $statusnew = 'status6';
2387 }
2388
2389 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusnew, $mode);
2390 }
2391
2392
2393 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2401 public function load_board($user, $mode)
2402 {
2403 // phpcs:enable
2404 global $conf, $langs;
2405
2406 $now = dol_now();
2407
2408 $clause = " WHERE";
2409
2410 $delay_warning = 0;
2411 if ($mode == 'opened') {
2412 $delay_warning = !empty($conf->supplier_proposal->cloture->warning_delay) ? $conf->supplier_proposal->cloture->warning_delay : 0;
2413 }
2414 if ($mode == 'signed') {
2415 $delay_warning = !empty($conf->supplier_proposal->facturation->warning_delay) ? $conf->supplier_proposal->facturation->warning_delay : 0;
2416 }
2417
2418 // The count and the number of late proposals are computed by the database instead of reading every proposal. An open
2419 // proposal is late when its closing date is before now minus the warning delay (a proposal without closing date was
2420 // counted as late, this is kept); nothing is late in the 'signed' mode.
2421 $sql = "SELECT COUNT(p.rowid) as nb,";
2422 if ($mode == 'opened') {
2423 $sql .= " SUM(CASE WHEN p.date_cloture IS NULL OR p.date_cloture < '".$this->db->idate($now - $delay_warning)."' THEN 1 ELSE 0 END) as nblate";
2424 } else {
2425 $sql .= " 0 as nblate";
2426 }
2427 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2428 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
2429 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2430 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
2431 $clause = " AND";
2432 }
2433 $sql .= $clause." p.entity IN (".getEntity('supplier_proposal').")";
2434 if ($mode == 'opened') {
2435 $sql .= " AND p.fk_statut = 1";
2436 }
2437 if ($mode == 'signed') {
2438 $sql .= " AND p.fk_statut = 2";
2439 }
2440 if ($user->socid) {
2441 $sql .= " AND p.fk_soc = ".((int) $user->socid);
2442 }
2443
2444 $resql = $this->db->query($sql);
2445 if ($resql) {
2446 $label = $labelShort = '';
2447 $status = '';
2448 if ($mode == 'opened') {
2449 $status = self::STATUS_VALIDATED;
2450 $label = $langs->trans("SupplierProposalsToClose");
2451 $labelShort = $langs->trans("ToAcceptRefuse");
2452 }
2453 if ($mode == 'signed') {
2454 $status = self::STATUS_SIGNED;
2455 $label = $langs->trans("SupplierProposalsToProcess"); // May be billed or ordered
2456 $labelShort = $langs->trans("ToClose");
2457 }
2458
2459 $response = new WorkboardResponse();
2460 $response->warning_delay = $delay_warning / 60 / 60 / 24;
2461 $response->label = $label;
2462 $response->labelShort = $labelShort;
2463 $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?search_status='.$status;
2464 $response->img = img_object('', "propal");
2465
2466 // This assignment in condition is not a bug. It allows walking the results.
2467 // TODO Definir regle des propales a facturer en retard (mode 'signed')
2468 $obj = $this->db->fetch_object($resql);
2469 if ($obj) {
2470 $response->nbtodo = (int) $obj->nb;
2471 $response->nbtodolate = (int) $obj->nblate;
2472 }
2473 return $response;
2474 } else {
2475 $this->error = $this->db->lasterror();
2476 return -1;
2477 }
2478 }
2479
2480
2489 public function initAsSpecimen($param = array())
2490 {
2491 global $conf, $langs;
2492
2493 // Load array of products prodids
2494 $num_prods = 0;
2495 $prodids = array();
2496 $sql = "SELECT rowid";
2497 $sql .= " FROM ".MAIN_DB_PREFIX."product";
2498 $sql .= " WHERE entity IN (".getEntity('product').")";
2499 if (array_key_exists('tobuy', $param)) {
2500 $sql .= " AND tobuy = ".((int) $param['tobuy']);
2501 }
2502 $sql .= $this->db->plimit(100);
2503
2504 $resql = $this->db->query($sql);
2505 if ($resql) {
2506 $num_prods = $this->db->num_rows($resql);
2507 $i = 0;
2508 while ($i < $num_prods) {
2509 $i++;
2510 $row = $this->db->fetch_row($resql);
2511 $prodids[$i] = $row[0];
2512 }
2513 }
2514
2515 // Initialise parameters
2516 $this->id = 0;
2517 $this->ref = 'SPECIMEN';
2518 $this->ref_supplier = 'NEMICEPS';
2519 $this->specimen = 1;
2520 $this->socid = 1;
2521 $this->date = dol_now();
2522 $this->cond_reglement_id = 1;
2523 $this->cond_reglement_code = 'RECEP';
2524 $this->mode_reglement_id = 7;
2525 $this->mode_reglement_code = 'CHQ';
2526 $this->note_public = 'This is a comment (public)';
2527 $this->note_private = 'This is a comment (private)';
2528
2529 $this->multicurrency_tx = 1;
2530 $this->multicurrency_code = getDolCurrency();
2531
2532 // Lines
2533 $nbp = min(1000, GETPOSTINT('nblines') ? GETPOSTINT('nblines') : 5); // We can force the nb of lines to test from command line (but not more than 1000)
2534 $xnbp = 0;
2535 while ($xnbp < $nbp) {
2536 $line = new SupplierProposalLine($this->db);
2537 $line->desc = $langs->trans("Description")." ".$xnbp;
2538 $line->qty = 1;
2539 $line->subprice = 100;
2540 $line->tva_tx = 19.6;
2541 $line->localtax1_tx = 0;
2542 $line->localtax2_tx = 0;
2543 if ($xnbp == 2) {
2544 $line->total_ht = 50;
2545 $line->total_ttc = 59.8;
2546 $line->total_tva = 9.8;
2547 $line->remise_percent = 50;
2548 } else {
2549 $line->total_ht = 100;
2550 $line->total_ttc = 119.6;
2551 $line->total_tva = 19.6;
2552 $line->remise_percent = 00;
2553 }
2554
2555 if ($num_prods > 0) {
2556 $prodid = mt_rand(1, $num_prods);
2557 $line->fk_product = $prodids[$prodid];
2558 }
2559
2560 $this->lines[$xnbp] = $line;
2561
2562 $this->total_ht += $line->total_ht;
2563 $this->total_tva += $line->total_tva;
2564 $this->total_ttc += $line->total_ttc;
2565
2566 $xnbp++;
2567 }
2568
2569 return 1;
2570 }
2571
2577 public function loadStateBoard()
2578 {
2579 global $user;
2580
2581 $this->nb = array();
2582 $clause = "WHERE";
2583
2584 $sql = "SELECT count(p.rowid) as nb";
2585 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p";
2586 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2587 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
2588 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2589 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
2590 $clause = "AND";
2591 }
2592 $sql .= " ".$clause." p.entity IN (".getEntity('supplier_proposal').")";
2593
2594 $resql = $this->db->query($sql);
2595 if ($resql) {
2596 // This assignment in condition is not a bug. It allows walking the results.
2597 while ($obj = $this->db->fetch_object($resql)) {
2598 $this->nb["supplier_proposals"] = $obj->nb;
2599 }
2600 $this->db->free($resql);
2601 return 1;
2602 } else {
2603 dol_print_error($this->db);
2604 $this->error = $this->db->lasterror();
2605 return -1;
2606 }
2607 }
2608
2609
2617 public function getNextNumRef($soc)
2618 {
2619 global $conf, $db, $langs;
2620 $langs->load("supplier_proposal");
2621
2622 if (getDolGlobalString('SUPPLIER_PROPOSAL_ADDON')) {
2623 $mybool = false;
2624
2625 $file = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON') . ".php";
2626 $classname = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON');
2627
2628 // Include file with class
2629 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
2630 foreach ($dirmodels as $reldir) {
2631 $dir = dol_buildpath($reldir."core/modules/supplier_proposal/");
2632
2633 // Load file with numbering class (if found)
2634 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2635 }
2636
2637 if (!$mybool) {
2638 dol_print_error(null, "Failed to include file ".$file);
2639 return '';
2640 }
2641
2642 $obj = new $classname();
2643 '@phan-var-force ModeleNumRefSupplierProposal $obj';
2645 $numref = "";
2646 $numref = $obj->getNextValue($soc, $this);
2647
2648 if ($numref != "") {
2649 return $numref;
2650 } else {
2651 $this->error = $obj->error;
2652 return "";
2653 }
2654 } else {
2655 $langs->load("errors");
2656 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("SupplierProposal"));
2657 return "";
2658 }
2659 }
2660
2667 public function getTooltipContentArray($params)
2668 {
2669 global $conf, $langs;
2670
2671 $langs->load('supplier_proposal');
2672
2673 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2674 return ['optimize' => $langs->trans("ShowSupplierProposal")];
2675 }
2676
2677 //$option = $params['option'] ?? '';
2678 $datas = [];
2679
2680 $datas['picto'] = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("SupplierProposal").'</u>';
2681 if (isset($this->status)) {
2682 $datas['picto'] .= ' '.$this->getLibStatut(5);
2683 }
2684 if (!empty($this->ref)) {
2685 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
2686 }
2687 if (!empty($this->ref_fourn)) {
2688 $datas['ref_supplier'] = '<br><b>'.$langs->trans('RefSupplier').':</b> '.$this->ref_fourn;
2689 }
2690 if (empty($params['nofetch'])) {
2691 $langs->load('companies');
2692 if (empty($this->thirdparty)) {
2693 $this->fetch_thirdparty();
2694 }
2695 if (is_object($this->thirdparty)) {
2696 $datas['supplier'] = '<br><b>'.$langs->trans('Supplier').':</b> '.$this->thirdparty->getNomUrl(1, '', 0, 1);
2697 }
2698 }
2699 if (!empty($this->total_ht)) {
2700 $datas['amount_ht'] = '<br><b>'.$langs->trans('AmountHT').':</b> '.price($this->total_ht, 0, $langs, 0, -1, -1, getDolCurrency());
2701 }
2702 if (!empty($this->total_tva)) {
2703 $datas['amount_vat'] = '<br><b>'.$langs->trans('VAT').':</b> '.price($this->total_tva, 0, $langs, 0, -1, -1, getDolCurrency());
2704 }
2705 if (!empty($this->total_ttc)) {
2706 $datas['amount_ttc'] = '<br><b>'.$langs->trans('AmountTTC').':</b> '.price($this->total_ttc, 0, $langs, 0, -1, -1, getDolCurrency());
2707 }
2708
2709 return $datas;
2710 }
2711
2723 public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2724 {
2725 global $langs, $conf, $user, $hookmanager;
2726
2727 if (!empty($conf->dol_no_mouse_hover)) {
2728 $notooltip = 1; // Force disable tooltips
2729 }
2730
2731 $url = '';
2732 $result = '';
2733 $params = [
2734 'id' => $this->id,
2735 'objecttype' => $this->element,
2736 'option' => $option,
2737 ];
2738 $classfortooltip = 'classfortooltip';
2739 $dataparams = '';
2740 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2741 $classfortooltip = 'classforajaxtooltip';
2742 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
2743 $label = '';
2744 } else {
2745 $label = $this->getTooltipContent($params);
2746 }
2747
2748 if ($option == '') {
2749 $url = DOL_URL_ROOT.'/supplier_proposal/card.php?id='.$this->id.$get_params;
2750 }
2751 if ($option == 'document') {
2752 $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id.$get_params;
2753 }
2754
2755 if ($option !== 'nolink') {
2756 // Add param to save lastsearch_values or not
2757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2758 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
2759 $add_save_lastsearch_values = 1;
2760 }
2761 if ($add_save_lastsearch_values) {
2762 $url .= '&save_lastsearch_values=1';
2763 }
2764 }
2765
2766 $linkclose = '';
2767 if (empty($notooltip) && $user->hasRight('propal', 'lire')) {
2768 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2769 $label = $langs->trans("ShowSupplierProposal");
2770 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
2771 }
2772 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
2773 $linkclose .= $dataparams.' class="'.$classfortooltip.'"';
2774 }
2775
2776 $linkstart = '<a href="'.$url.'"';
2777 $linkstart .= $linkclose.'>';
2778 $linkend = '</a>';
2779
2780 $result .= $linkstart;
2781 if ($withpicto) {
2782 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
2783 }
2784 if ($withpicto != 2) {
2785 $result .= $this->ref;
2786 }
2787 $result .= $linkend;
2788
2789 if ($addlinktonotes) {
2790 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2791 if ($txttoshow) {
2792 $notetoshow = $langs->trans("ViewPrivateNote").':<br>'.dol_string_nohtmltag($txttoshow, 1);
2793 $result .= ' <span class="note inline-block">';
2794 $result .= '<a href="'.DOL_URL_ROOT.'/supplier_proposal/note.php?id='.$this->id.'" class="classfortooltip" title="'.dol_escape_htmltag($notetoshow).'">';
2795 $result .= img_picto('', 'note');
2796 $result .= '</a>';
2797 //$result.=img_picto($langs->trans("ViewNote"),'object_generic');
2798 //$result.='</a>';
2799 $result .= '</span>';
2800 }
2801 }
2802 global $action;
2803 $hookmanager->initHooks(array($this->element . 'dao'));
2804 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
2805 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2806 if ($reshook > 0) {
2807 $result = $hookmanager->resPrint;
2808 } else {
2809 $result .= $hookmanager->resPrint;
2810 }
2811 return $result;
2812 }
2813
2821 {
2822 global $mysoc;
2823
2824 $context = parent::getObjectLinesDisplayContext();
2825 // The supplier is the seller, an empty third party is used if it is not loaded (same as a failed fetch in the card)
2826 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
2827 $context['seller'] = (is_object($this->thirdparty) ? $this->thirdparty : new Societe($this->db));
2828 $context['buyer'] = $mysoc;
2829 $context['dateSelector'] = 0;
2830 $context['forceall'] = 1;
2831 $context['inputalsopricewithtax'] = 1;
2832 // 2 is same than 1 but disable test on minimum qty
2833 $context['senderissupplier'] = (getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') ? getDolGlobalInt('SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') : 2);
2834
2835 return $context;
2836 }
2837
2843 public function getLinesArray()
2844 {
2845 // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal
2846
2847 $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
2848 $sql .= ' pt.qty, pt.tva_tx, pt.vat_src_code, pt.remise_percent, pt.subprice, pt.info_bits,';
2849 $sql .= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
2850 $sql .= ' pt.product_type, pt.rang, pt.fk_parent_line, pt.extraparams,';
2851 $sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2852 $sql .= ' p.description as product_desc, pt.ref_fourn as ref_supplier,';
2853 $sql .= ' pt.fk_multicurrency, pt.multicurrency_code, pt.multicurrency_subprice, pt.multicurrency_total_ht, pt.multicurrency_total_tva, pt.multicurrency_total_ttc, pt.fk_unit';
2854 $sql .= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pt';
2855 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
2856 $sql .= ' WHERE pt.fk_supplier_proposal = '.((int) $this->id);
2857 $sql .= ' ORDER BY pt.rang ASC, pt.rowid';
2858
2859 dol_syslog(get_class($this).'::getLinesArray', LOG_DEBUG);
2860 $resql = $this->db->query($sql);
2861 if ($resql) {
2862 $num = $this->db->num_rows($resql);
2863 $i = 0;
2864
2865 while ($i < $num) {
2866 $obj = $this->db->fetch_object($resql);
2867
2868 $this->lines[$i] = new SupplierProposalLine($this->db);
2869 $this->lines[$i]->id = $obj->rowid; // for backward compatibility
2870 $this->lines[$i]->rowid = $obj->rowid;
2871
2872 $this->lines[$i]->label = $obj->custom_label;
2873 $this->lines[$i]->description = $obj->description; // deprecated
2874 $this->lines[$i]->desc = $obj->description;
2875
2876 $this->lines[$i]->fk_product = $obj->fk_product;
2877 $this->lines[$i]->ref = $obj->ref;
2878 $this->lines[$i]->product_label = $obj->product_label;
2879 $this->lines[$i]->product_desc = $obj->product_desc;
2880 $this->lines[$i]->fk_product_type = $obj->fk_product_type; // deprecated
2881 $this->lines[$i]->product_type = $obj->product_type;
2882 $this->lines[$i]->qty = $obj->qty;
2883 $this->lines[$i]->subprice = $obj->subprice;
2884 $this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
2885 $this->lines[$i]->remise_percent = $obj->remise_percent;
2886 $this->lines[$i]->tva_tx = $obj->tva_tx;
2887 $this->lines[$i]->vat_src_code = $obj->vat_src_code;
2888 $this->lines[$i]->info_bits = $obj->info_bits;
2889 $this->lines[$i]->total_ht = $obj->total_ht;
2890 $this->lines[$i]->total_tva = $obj->total_tva;
2891 $this->lines[$i]->total_ttc = $obj->total_ttc;
2892 $this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
2893 $marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
2894 $this->lines[$i]->pa_ht = $marginInfos[0];
2895 $this->lines[$i]->marge_tx = $marginInfos[1];
2896 $this->lines[$i]->marque_tx = $marginInfos[2];
2897 $this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
2898 $this->lines[$i]->special_code = $obj->special_code;
2899 $this->lines[$i]->rang = $obj->rang;
2900
2901 $this->lines[$i]->ref_fourn = $obj->ref_supplier; // deprecated
2902 $this->lines[$i]->ref_supplier = $obj->ref_supplier;
2903
2904 // Multicurrency
2905 $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency;
2906 $this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
2907 $this->lines[$i]->multicurrency_subprice = $obj->multicurrency_subprice;
2908 $this->lines[$i]->multicurrency_total_ht = $obj->multicurrency_total_ht;
2909 $this->lines[$i]->multicurrency_total_tva = $obj->multicurrency_total_tva;
2910 $this->lines[$i]->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2911 $this->lines[$i]->fk_unit = $obj->fk_unit;
2912 $this->lines[$i]->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array();
2913
2914 $this->lines[$i]->fetch_optionals();
2915
2916 $i++;
2917 }
2918 $this->db->free($resql);
2919
2920 return 1;
2921 } else {
2922 $this->error = $this->db->error();
2923 return -1;
2924 }
2925 }
2926
2938 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2939 {
2940 global $langs;
2941
2942 $langs->load("supplier_proposal");
2943 $outputlangs->load("products");
2944
2945 if (!dol_strlen($modele)) {
2946 $modele = ''; // On supplier documents, template can be empty( no doc generated in this case)
2947
2948 if ($this->model_pdf) {
2949 $modele = $this->model_pdf;
2950 } elseif (getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF')) {
2951 $modele = getDolGlobalString('SUPPLIER_PROPOSAL_ADDON_PDF');
2952 }
2953 }
2954
2955 if (empty($modele)) {
2956 return 1;
2957 }
2958
2959 $modelpath = "core/modules/supplier_proposal/doc/";
2960
2961 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2962 }
2963
2964
2973 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2974 {
2975 $tables = array(
2976 'supplier_proposal'
2977 );
2978
2979 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2980 }
2981
2990 public static function replaceProduct(DoliDB $db, $origin_id, $dest_id)
2991 {
2992 $tables = array(
2993 'supplier_proposaldet'
2994 );
2995
2996 return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables);
2997 }
2998
2999
3007 public function getKanbanView($option = '', $arraydata = null)
3008 {
3009 global $langs;
3010
3011 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3012
3013 $return = '<div class="box-flex-item box-flex-grow-zero">';
3014 $return .= '<div class="info-box info-box-sm">';
3015 $return .= '<span class="info-box-icon bg-infobox-action">';
3016 $return .= img_picto('', $this->picto);
3017 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
3018 $return .= '</span>';
3019 $return .= '<div class="info-box-content">';
3020 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
3021 if ($selected >= 0) {
3022 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
3023 }
3024 if (property_exists($this, 'socid')) {
3025 $return .= '<span class="info-box-ref"> | '.$this->socid.'</span>';
3026 }
3027 if (property_exists($this, 'delivery_date')) {
3028 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label">'.dol_print_date($this->delivery_date).'</span>';
3029 }
3030 if (property_exists($this, 'total_ttc')) {
3031 $return .= '<br><span class="opacitymedium" >'.$langs->trans("AmountHT").' : </span><span class="info-box-label amount">'.price($this->total_ttc).'</span>';
3032 }
3033 if (method_exists($this, 'getLibStatut')) {
3034 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
3035 }
3036 $return .= '</div>';
3037 $return .= '</div>';
3038 $return .= '</div>';
3039 return $return;
3040 }
3041
3052 public function setCategories($categories)
3053 {
3054 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3055 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_PROPOSAL);
3056 }
3057}
3058
3059
3064{
3068 public $db;
3069
3073 public $error = '';
3074
3078 public $element = 'supplier_proposaldet';
3079
3083 public $table_element = 'supplier_proposaldet';
3084
3088 public $parent_element = 'supplier_proposal';
3089
3093 public $fk_parent_attribute = 'fk_supplier_proposal';
3094
3098 public $oldline;
3099
3103 public $id;
3104
3108 public $fk_supplier_proposal;
3109
3113 public $fk_parent_line;
3114
3118 public $desc; // Description of the line
3119
3123 public $fk_product; // Predefined Product ID
3124
3130 public $fk_product_type;
3136 public $product_type = Product::TYPE_PRODUCT;
3137
3141 public $qty;
3145 public $tva_tx;
3149 public $vat_src_code;
3150
3154 public $remise_percent;
3155
3159 public $fk_remise_except;
3160
3164 public $rang = 0;
3165
3169 public $fk_fournprice;
3170
3174 public $pa_ht;
3178 public $marge_tx;
3182 public $marque_tx;
3183
3187 public $special_code; // Tag for special lines (exclusive tags)
3188 // 1: frais de port
3189 // 2: ecotaxe
3190 // 3: option line (when qty = 0)
3191
3195 public $info_bits = 0; // Liste d'options cumulables:
3196 // Bit 0: 0 if TVA normal - 1 if TVA NPR
3197 // Bit 1: 0 normal line - 1 if fixed reduction
3198
3202 public $total_ht; // Line Net Total (HT), including all quantity and the line discount
3206 public $total_tva; // Line Net Total (VAT), including all quantity and the line discount
3210 public $total_ttc; // Line Net Total (TTC), including all quantity and the line discount
3211
3215 public $date_start;
3219 public $date_end;
3220
3221 // From llx_product
3227 public $ref;
3228
3233 public $product_ref;
3234
3240 public $libelle;
3241
3246 public $product_label;
3247
3252 public $label;
3253
3258 public $product_desc;
3259
3263 public $localtax1_tx; // Local tax 1
3267 public $localtax2_tx; // Local tax 2
3271 public $localtax1_type; // Local tax 1 type
3275 public $localtax2_type; // Local tax 2 type
3279 public $total_localtax1; // Line total local tax 1
3283 public $total_localtax2; // Line total local tax 2
3284
3288 public $skip_update_total; // Skip update price total for special lines
3289
3293 public $ref_fourn;
3297 public $ref_supplier;
3298
3299 // Multicurrency
3303 public $fk_multicurrency;
3304
3308 public $multicurrency_code;
3312 public $multicurrency_subprice;
3316 public $multicurrency_total_ht;
3320 public $multicurrency_total_tva;
3324 public $multicurrency_total_ttc;
3325
3331 public function __construct($db)
3332 {
3333 $this->db = $db;
3334 }
3335
3342 public function fetch($rowid)
3343 {
3344 $sql = 'SELECT pd.rowid, pd.fk_supplier_proposal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
3345 $sql .= ' pd.date_start, pd.date_end,';
3346 $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice, pd.subprice_ttc,';
3347 $sql .= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
3348 $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
3349 $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3350 $sql .= ' pd.product_type, pd.ref_fourn as ref_produit_fourn, pd.extraparams,';
3351 $sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_subprice_ttc, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc, pd.fk_unit';
3352 $sql .= ' FROM '.MAIN_DB_PREFIX.'supplier_proposaldet as pd';
3353 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
3354 $sql .= ' WHERE pd.rowid = '.((int) $rowid);
3355
3356 $result = $this->db->query($sql);
3357 if ($result) {
3358 if ($objp = $this->db->fetch_object($result)) {
3359 $this->id = $objp->rowid;
3360 $this->fk_supplier_proposal = $objp->fk_supplier_proposal;
3361 $this->fk_parent_line = $objp->fk_parent_line;
3362 $this->label = $objp->custom_label;
3363 $this->desc = $objp->description;
3364 $this->qty = $objp->qty;
3365
3366 $this->subprice = $objp->subprice;
3367 $this->subprice_ttc = $objp->subprice_ttc;
3368
3369 $this->tva_tx = $objp->tva_tx;
3370 $this->remise_percent = $objp->remise_percent;
3371 $this->fk_remise_except = $objp->fk_remise_except;
3372 $this->fk_product = $objp->fk_product;
3373 $this->info_bits = $objp->info_bits;
3374 $this->date_start = $this->db->jdate($objp->date_start);
3375 $this->date_end = $this->db->jdate($objp->date_end);
3376
3377 $this->total_ht = $objp->total_ht;
3378 $this->total_tva = $objp->total_tva;
3379 $this->total_ttc = $objp->total_ttc;
3380
3381 $this->fk_fournprice = $objp->fk_fournprice;
3382
3383 $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
3384 $this->pa_ht = $marginInfos[0];
3385 $this->marge_tx = $marginInfos[1];
3386 $this->marque_tx = $marginInfos[2];
3387
3388 $this->special_code = $objp->special_code;
3389 $this->product_type = $objp->product_type;
3390 $this->rang = $objp->rang;
3391
3392 $this->product_ref = $objp->product_ref;
3393 $this->product_label = $objp->product_label;
3394 $this->product_desc = $objp->product_desc;
3395
3396 $this->ref_fourn = $objp->ref_produit_fourn;
3397
3398 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams, true) : array();
3399
3400 // Multicurrency
3401 $this->fk_multicurrency = $objp->fk_multicurrency;
3402 $this->multicurrency_code = $objp->multicurrency_code;
3403 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3404 $this->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
3405 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3406 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3407 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3408 $this->fk_unit = $objp->fk_unit;
3409
3410 $this->db->free($result);
3411 return 1;
3412 }
3413 return 0;
3414 } else {
3415 dol_print_error($this->db);
3416 return -1;
3417 }
3418 }
3419
3426 public function insert($notrigger = 0)
3427 {
3428 global $user;
3429
3430 $error = 0;
3431
3432 dol_syslog(get_class($this)."::insert rang=".$this->rang);
3433
3434 // Clean parameters
3435 if (empty($this->tva_tx)) {
3436 $this->tva_tx = 0;
3437 }
3438 if (empty($this->vat_src_code)) {
3439 $this->vat_src_code = '';
3440 }
3441 if (empty($this->localtax1_tx)) {
3442 $this->localtax1_tx = 0;
3443 }
3444 if (empty($this->localtax2_tx)) {
3445 $this->localtax2_tx = 0;
3446 }
3447 if (empty($this->localtax1_type)) {
3448 $this->localtax1_type = '';
3449 }
3450 if (empty($this->localtax2_type)) {
3451 $this->localtax2_type = '';
3452 }
3453 if (empty($this->total_localtax1)) {
3454 $this->total_localtax1 = 0;
3455 }
3456 if (empty($this->total_localtax2)) {
3457 $this->total_localtax2 = 0;
3458 }
3459 if (empty($this->rang)) {
3460 $this->rang = 0;
3461 }
3462 if (empty($this->remise_percent)) {
3463 $this->remise_percent = 0;
3464 }
3465 if (empty($this->info_bits)) {
3466 $this->info_bits = 0;
3467 }
3468 if (empty($this->special_code)) {
3469 $this->special_code = 0;
3470 }
3471 if (empty($this->fk_parent_line)) {
3472 $this->fk_parent_line = 0;
3473 }
3474 if (empty($this->fk_fournprice)) {
3475 $this->fk_fournprice = 0;
3476 }
3477 if (empty($this->fk_unit)) {
3478 $this->fk_unit = 0;
3479 }
3480 if (empty($this->subprice)) {
3481 $this->subprice = 0;
3482 }
3483
3484 if (empty($this->pa_ht)) {
3485 $this->pa_ht = 0;
3486 }
3487
3488 // if buy price not defined, define buyprice as configured in margin admin
3489 if ($this->pa_ht == 0) {
3490 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3491 if ($result < 0) {
3492 return $result;
3493 } else {
3494 $this->pa_ht = $result;
3495 }
3496 }
3497
3498 // Check parameters
3499 if ($this->product_type < 0) {
3500 return -1;
3501 }
3502
3503 $this->db->begin();
3504
3505 // Insert line into database
3506 $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'supplier_proposaldet';
3507 $sql .= ' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
3508 $sql .= ' date_start, date_end,';
3509 $sql .= ' fk_remise_except, qty, tva_tx, vat_src_code, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
3510 $sql .= ' subprice, subprice_ttc, remise_percent, ';
3511 $sql .= ' info_bits, ';
3512 $sql .= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
3513 $sql .= ' ref_fourn,';
3514 $sql .= ' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_subprice_ttc, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
3515 $sql .= " VALUES (".((int) $this->fk_supplier_proposal).",";
3516 $sql .= " ".($this->fk_parent_line > 0 ? ((int) $this->fk_parent_line) : "null").",";
3517 $sql .= " ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null").",";
3518 $sql .= " '".$this->db->escape($this->desc)."',";
3519 $sql .= " ".($this->fk_product ? ((int) $this->fk_product) : "null").",";
3520 $sql .= " ".((int) $this->product_type).",";
3521 $sql .= " ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null").",";
3522 $sql .= " ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null").",";
3523 $sql .= " ".($this->fk_remise_except ? ((int) $this->fk_remise_except) : "null").",";
3524 $sql .= " ".(float) price2num($this->qty, 'MS').",";
3525 $sql .= " ".(float) price2num($this->tva_tx).",";
3526 $sql .= " '".$this->db->escape($this->vat_src_code)."',";
3527 $sql .= " ".(float) price2num($this->localtax1_tx).",";
3528 $sql .= " ".(float) price2num($this->localtax2_tx).",";
3529 $sql .= " '".$this->db->escape($this->localtax1_type)."',";
3530 $sql .= " '".$this->db->escape($this->localtax2_type)."',";
3531 $sql .= " ".(float) price2num($this->subprice, 'MU') .",";
3532 $sql .= " ".(float) price2num($this->subprice_ttc, 'MU') .",";
3533 $sql .= " ".((float) $this->remise_percent).",";
3534 $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").",";
3535 $sql .= " ".(float) price2num($this->total_ht, 'MT').",";
3536 $sql .= " ".(float) price2num($this->total_tva, 'MT').",";
3537 $sql .= " ".(float) price2num($this->total_localtax1, 'MT').",";
3538 $sql .= " ".(float) price2num($this->total_localtax2, 'MT').",";
3539 $sql .= " ".(float) price2num($this->total_ttc, 'MT').",";
3540 $sql .= " ".(!empty($this->fk_fournprice) ? ((int) $this->fk_fournprice) : "null").",";
3541 $sql .= " ".(isset($this->pa_ht) ? (float) price2num($this->pa_ht, 'MU') : "null").",";
3542 $sql .= ' '.((int) $this->special_code).',';
3543 $sql .= ' '.((int) $this->rang).',';
3544 $sql .= " '".$this->db->escape($this->ref_fourn)."'";
3545 $sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null');
3546 $sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
3547 $sql .= ", ".(float) price2num($this->multicurrency_subprice, 'CU');
3548 $sql .= ", ".(float) price2num($this->multicurrency_subprice_ttc, 'CU');
3549 $sql .= ", ".(float) price2num($this->multicurrency_total_ht, 'CT');
3550 $sql .= ", ".(float) price2num($this->multicurrency_total_tva, 'CT');
3551 $sql .= ", ".(float) price2num($this->multicurrency_total_ttc, 'CT');
3552 $sql .= ", ".($this->fk_unit ? ((int) $this->fk_unit) : 'null');
3553 $sql .= ')';
3554
3555 dol_syslog(get_class($this).'::insert', LOG_DEBUG);
3556 $resql = $this->db->query($sql);
3557 if ($resql) {
3558 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet');
3559
3560 if (!$error) {
3561 $result = $this->insertExtraFields();
3562 if ($result < 0) {
3563 $error++;
3564 }
3565 }
3566
3567 if (!$error && !$notrigger) {
3568 // Call trigger
3569 $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_INSERT', $user);
3570 if ($result < 0) {
3571 $this->db->rollback();
3572 return -1;
3573 }
3574 // End call triggers
3575 }
3576
3577 $this->db->commit();
3578 return 1;
3579 } else {
3580 $this->error = $this->db->error()." sql=".$sql;
3581 $this->db->rollback();
3582 return -1;
3583 }
3584 }
3585
3592 public function delete($user)
3593 {
3594 $error = 0;
3595
3596 $this->db->begin();
3597
3598 $sql = "DELETE FROM ".MAIN_DB_PREFIX."supplier_proposaldet";
3599 $sql .= " WHERE rowid = ".((int) $this->id);
3600
3601 if ($this->db->query($sql)) {
3602 // Remove extrafields
3603 if (!$error) {
3604 $result = $this->deleteExtraFields();
3605 if ($result < 0) {
3606 $error++;
3607 dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
3608 }
3609 }
3610
3611 // Call trigger
3612 $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_DELETE', $user);
3613 if ($result < 0) {
3614 $this->db->rollback();
3615 return -1;
3616 }
3617 // End call triggers
3618
3619 $this->db->commit();
3620
3621 return 1;
3622 } else {
3623 $this->error = $this->db->error()." sql=".$sql;
3624 $this->db->rollback();
3625 return -1;
3626 }
3627 }
3628
3635 public function update($notrigger = 0)
3636 {
3637 global $user;
3638
3639 $error = 0;
3640
3641 // Clean parameters
3642 if (empty($this->tva_tx)) {
3643 $this->tva_tx = 0;
3644 }
3645 if (empty($this->localtax1_tx)) {
3646 $this->localtax1_tx = 0;
3647 }
3648 if (empty($this->localtax2_tx)) {
3649 $this->localtax2_tx = 0;
3650 }
3651 if (empty($this->total_localtax1)) {
3652 $this->total_localtax1 = 0;
3653 }
3654 if (empty($this->total_localtax2)) {
3655 $this->total_localtax2 = 0;
3656 }
3657 if (empty($this->localtax1_type)) {
3658 $this->localtax1_type = '';
3659 }
3660 if (empty($this->localtax2_type)) {
3661 $this->localtax2_type = '';
3662 }
3663 if (empty($this->marque_tx)) {
3664 $this->marque_tx = 0;
3665 }
3666 if (empty($this->marge_tx)) {
3667 $this->marge_tx = 0;
3668 }
3669 if (empty($this->remise_percent)) {
3670 $this->remise_percent = 0;
3671 }
3672 if (empty($this->info_bits)) {
3673 $this->info_bits = 0;
3674 }
3675 if (empty($this->special_code)) {
3676 $this->special_code = 0;
3677 }
3678 if (empty($this->fk_parent_line)) {
3679 $this->fk_parent_line = 0;
3680 }
3681 if (empty($this->fk_fournprice)) {
3682 $this->fk_fournprice = 0;
3683 }
3684 if (empty($this->fk_unit)) {
3685 $this->fk_unit = 0;
3686 }
3687 if (empty($this->subprice)) {
3688 $this->subprice = 0;
3689 }
3690
3691 if (empty($this->pa_ht)) {
3692 $this->pa_ht = 0;
3693 }
3694
3695 // if buy price not defined, define buyprice as configured in margin admin
3696 if ($this->pa_ht == 0) {
3697 $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3698 if ($result < 0) {
3699 return $result;
3700 } else {
3701 $this->pa_ht = $result;
3702 }
3703 }
3704
3705 $this->db->begin();
3706
3707 // Update line in database
3708 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3709 $sql .= " description = '".$this->db->escape($this->desc)."'";
3710 $sql .= " , label = ".(!empty($this->label) ? "'".$this->db->escape($this->label)."'" : "null");
3711 $sql .= " , product_type = ".((int) $this->product_type);
3712 $sql .= " , date_start = ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null");
3713 $sql .= " , date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
3714 $sql .= " , tva_tx = '".price2num($this->tva_tx)."'";
3715 $sql .= " , localtax1_tx = ".(float) price2num($this->localtax1_tx);
3716 $sql .= " , localtax2_tx = ".(float) price2num($this->localtax2_tx);
3717 $sql .= " , localtax1_type = '".$this->db->escape($this->localtax1_type)."'";
3718 $sql .= " , localtax2_type = '".$this->db->escape($this->localtax2_type)."'";
3719 $sql .= " , qty = ".(float) price2num($this->qty);
3720 $sql .= " , subprice = ".(float) price2num($this->subprice);
3721 $sql .= " , subprice_ttc = ".(float) price2num($this->subprice_ttc);
3722 $sql .= " , remise_percent = ".(float) price2num($this->remise_percent);
3723 $sql .= " , info_bits = ".((int) $this->info_bits);
3724 if (empty($this->skip_update_total)) {
3725 $sql .= " , total_ht = ".(float) price2num($this->total_ht);
3726 $sql .= " , total_tva = ".(float) price2num($this->total_tva);
3727 $sql .= " , total_ttc = ".(float) price2num($this->total_ttc);
3728 $sql .= " , total_localtax1 = ".(float) price2num($this->total_localtax1);
3729 $sql .= " , total_localtax2 = ".(float) price2num($this->total_localtax2);
3730 }
3731 $sql .= " , fk_product_fournisseur_price = ".(!empty($this->fk_fournprice) ? "'".$this->db->escape((string) $this->fk_fournprice)."'" : "null");
3732 $sql .= " , buy_price_ht = ".(float) price2num($this->pa_ht);
3733 $sql .= " , special_code = ".((int) $this->special_code);
3734 $sql .= " , fk_parent_line = ".($this->fk_parent_line > 0 ? ((int) $this->fk_parent_line) : "null");
3735 if (!empty($this->rang)) {
3736 $sql .= ", rang = ".((int) $this->rang);
3737 }
3738 $sql .= " , ref_fourn = ".(!empty($this->ref_fourn) ? "'".$this->db->escape($this->ref_fourn)."'" : "null");
3739 $sql .= " , fk_unit = ".($this->fk_unit ? (int) $this->fk_unit : 'null');
3740
3741 // Multicurrency
3742 $sql .= " , multicurrency_subprice = ".(float) price2num($this->multicurrency_subprice);
3743 $sql .= " , multicurrency_subprice_ttc = ".(float) price2num($this->multicurrency_subprice_ttc);
3744 $sql .= " , multicurrency_total_ht = ".(float) price2num($this->multicurrency_total_ht);
3745 $sql .= " , multicurrency_total_tva = ".(float) price2num($this->multicurrency_total_tva);
3746 $sql .= " , multicurrency_total_ttc = ".(float) price2num($this->multicurrency_total_ttc);
3747
3748 $sql .= " WHERE rowid = ".((int) $this->id);
3749
3750 dol_syslog(get_class($this)."::update", LOG_DEBUG);
3751 $resql = $this->db->query($sql);
3752 if ($resql) {
3753 if (!$error) {
3754 $result = $this->insertExtraFields();
3755 if ($result < 0) {
3756 $error++;
3757 }
3758 }
3759
3760 if (!$error && !$notrigger) {
3761 // Call trigger
3762 $result = $this->call_trigger('LINESUPPLIER_PROPOSAL_MODIFY', $user);
3763 if ($result < 0) {
3764 $this->db->rollback();
3765 return -1;
3766 }
3767 // End call triggers
3768 }
3769
3770 $this->db->commit();
3771 return 1;
3772 } else {
3773 $this->error = $this->db->error();
3774 $this->db->rollback();
3775 return -2;
3776 }
3777 }
3778
3779 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3786 public function update_total()
3787 {
3788 // phpcs:enable
3789 $this->db->begin();
3790
3791 // Update line in database
3792 $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposaldet SET";
3793 $sql .= " total_ht = ".(float) price2num($this->total_ht, 'MT');
3794 $sql .= ",total_tva = ".(float) price2num($this->total_tva, 'MT');
3795 $sql .= ",total_ttc = ".(float) price2num($this->total_ttc, 'MT');
3796 $sql .= " WHERE rowid = ".((int) $this->id);
3797
3798 dol_syslog("SupplierProposalLine::update_total", LOG_DEBUG);
3799
3800 $resql = $this->db->query($sql);
3801 if ($resql) {
3802 $this->db->commit();
3803 return 1;
3804 } else {
3805 $this->error = $this->db->error();
3806 $this->db->rollback();
3807 return -2;
3808 }
3809 }
3810}
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
getTooltipContent($params)
getTooltipContent
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.
roundQtyToPackaging($qty, $packaging)
Round a quantity up to the next multiple of a packaging quantity (options PRODUCT_USE_CUSTOMER_PACKAG...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
checkActiveProductInLines($status='onsale')
Check if all products have the right status (on sale, on buy) called during validation of propal,...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0, $qty=0)
Get buy price to use for margin calculation.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage absolute discounts.
Class to manage Dolibarr database access.
Class Currency.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage price ask supplier.
updatePriceFournisseur($idProductFournPrice, $product, $user)
Update ProductFournisseur.
updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $array_options=[], $ref_supplier='', $fk_unit=0, $pu_ht_devise=0)
Update a proposal line.
cloture($user, $status, $note)
Close the askprice.
initAsSpecimen($param=array())
Initialise an instance with random values.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $pu_ttc=0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='', $array_options=[], $ref_supplier='', $fk_unit=0, $origin='', $origin_id=0, $pu_ht_devise=0, $date_start=0, $date_end=0)
Add a proposal line into database (linked to product/service or not) The parameters are already suppo...
info($id)
Object SupplierProposal Information.
create($user, $notrigger=0)
Create commercial proposal into database this->ref can be set or empty.
insert_discount($idremise)
Adding line of fixed discount in the proposal in DB.
getObjectLinesDisplayContext()
Return the display context of the lines, as defined by the card before printObjectLines() and formAdd...
reopen($user, $status, $note='', $notrigger=0)
Reopen the commercial proposal.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
fetch($rowid, $ref='')
Load a proposal from database and its lines array.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
createFromClone(User $user, $fromid=0)
Load an object from its id and create a new one in database.
const STATUS_NOTSIGNED
Not signed quote, canceled.
const STATUS_DRAFT
Draft status.
liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datec', $sortorder='DESC')
Return list of askprice (eventually filtered on user) into an array.
update($user, $notrigger=0)
Update the header fields of the price request that can be edited without a dedicated action.
setDeliveryDate($user, $delivery_date)
Set delivery date.
__construct($db, $socid=0, $supplier_proposalid=0)
Constructor.
LibStatut($status, $mode=1)
Return label of a status (draft, validated, ...)
setCategories($categories)
Sets object to supplied categories.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
updateOrCreatePriceFournisseur($user)
Add or update supplier price according to result of proposal.
loadStateBoard()
Load indicator this->nb of global stats widget.
deleteLine($lineid)
Delete detail line.
const STATUS_VALIDATED
Validated status.
createPriceFournisseur($product, $user)
Create Price Fournisseur.
getLibStatut($mode=0)
Return label of status of proposal (draft, validated, ...)
add_product($idproduct, $qty, $remise_percent=0)
Add line into array ->lines.
set_date_livraison($user, $delivery_date)
Set delivery date.
const STATUS_SIGNED
Signed quote.
getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clickable link of object (with eventually picto)
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
getTooltipContentArray($params)
getTooltipContentArray
valid($user, $notrigger=0)
Set status to validated.
const STATUS_CLOSE
Billed or closed/processed quote.
getLinesArray()
Retrieve an array of supplier proposal lines.
setDraft($user)
Set draft status.
Class to manage supplier_proposal lines.
fetch($rowid)
Retrieve the propal line object.
insert($notrigger=0)
Insert object line propal in database.
update_total()
Update DB line fields total_xxx Used by migration.
update($notrigger=0)
Update propal line object into DB.
__construct($db)
Class line Constructor.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
dol_delete_preview($object)
Delete all preview files linked to object instance.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
Definition price.lib.php:90
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date
Definition receipt.php:492