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';
63 public $element =
'supplier_proposal';
68 public $table_element =
'supplier_proposal';
73 public $table_element_line =
'supplier_proposaldet';
78 public $class_element_line =
'SupplierProposalLine';
82 public $fk_element =
'fk_supplier_proposal';
87 public $picto =
'supplier_proposal';
93 public $restrictiononfksoc = 1;
119 public $ref_supplier;
135 public $delivery_date;
154 public $user_author_id;
180 public $cond_reglement_code;
184 public $cond_reglement_doc;
188 public $cond_reglement_label;
193 public $mode_reglement_code;
198 public $mode_reglement;
205 public $deposit_percent;
211 public $extraparams = array();
216 public $lines = array();
223 public $labelStatus = array();
224 public $labelStatusShort = array();
239 public $fk_multicurrency;
244 public $multicurrency_code;
248 public $multicurrency_tx;
252 public $multicurrency_total_ht;
256 public $multicurrency_total_tva;
260 public $multicurrency_total_ttc;
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),
301 public function __construct($db, $socid = 0, $supplier_proposalid = 0)
305 $this->ismultientitymanaged = 1;
306 $this->socid = $socid;
307 $this->
id = $supplier_proposalid;
322 public function add_product($idproduct, $qty, $remise_percent = 0)
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);
336 $productdesc = $prod->description;
340 if (empty($tva_tx)) {
348 $price = $prod->multiprices[$this->thirdparty->price_level];
350 $price = $prod->price;
355 $line->fk_product = $idproduct;
356 $line->desc = $productdesc;
358 $line->subprice = $price;
359 $line->remise_percent = $remise_percent;
360 $line->tva_tx = $tva_tx;
362 $this->lines[] = $line;
380 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
381 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
386 $result = $remise->fetch($idremise);
389 if ($remise->fk_facture) {
390 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
391 $this->db->rollback();
396 $supplier_proposalligne->fk_supplier_proposal = $this->id;
397 $supplier_proposalligne->fk_remise_except = $remise->id;
398 $supplier_proposalligne->desc = $remise->description;
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;
406 $supplier_proposalligne->qty = 1;
407 $supplier_proposalligne->remise_percent = 0;
408 $supplier_proposalligne->rang = -1;
409 $supplier_proposalligne->info_bits = 2;
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;
417 $result = $supplier_proposalligne->insert();
424 $this->db->rollback();
429 $this->db->rollback();
433 $this->db->rollback();
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)
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';
482 if (empty($remise_percent)) {
488 if (empty($info_bits)) {
494 if (empty($fk_parent_line) || $fk_parent_line < 0) {
501 $remise_percent =
price2num($remise_percent);
505 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
511 if ($price_base_type ==
'HT') {
522 if ($this->
status == self::STATUS_DRAFT) {
525 if ($fk_product > 0) {
526 if (
getDolGlobalInt(
'SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') == 1) {
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);
530 if ($productsupplier->fetch($fk_product) > 0) {
531 $product_type = $productsupplier->type;
532 $label = $productsupplier->label;
533 $fk_prod_fourn_price = $fk_fournprice;
538 $result = $productsupplier->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', $this->socid);
540 $pu = $productsupplier->fourn_pu;
541 $ref_supplier = $productsupplier->ref_supplier;
543 if ($remise_percent == 0 && $productsupplier->remise_percent != 0) {
544 $remise_percent = $productsupplier->remise_percent;
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");
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);
565 $this->db->rollback();
566 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
571 $this->db->rollback();
578 $prod =
new Product($this->db);
580 $prod->get_buyprice(($fk_fournprice > 0 ? (
int) $fk_fournprice : 0), (
float) $qty, $fk_product,
'none', $this->socid);
583 if ($newqty != $qty) {
585 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
590 if (!empty($prod->fourn_qty) && (
float) $qty > 0 && (
float) $qty < (
float) $prod->fourn_qty) {
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');
595 $qty = (float) $prod->fourn_qty;
597 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
601 $product_type = $type;
613 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
614 $vat_src_code = $reg[1];
615 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
618 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
625 (
float) $remise_percent,
627 (
float) $txlocaltax1,
628 (
float) $txlocaltax2,
636 (
float) $this->multicurrency_tx,
638 $this->multicurrency_code
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];
648 $multicurrency_total_ht = $tabprice[16];
649 $multicurrency_total_tva = $tabprice[17];
650 $multicurrency_total_ttc = $tabprice[18];
651 $pu_ht_devise = $tabprice[19];
655 if ($ranktouse == -1) {
656 $rangmax = $this->
line_max($fk_parent_line);
657 $ranktouse = $rangmax + 1;
663 $this->line->fk_supplier_proposal = $this->id;
664 $this->line->label = $label;
665 $this->line->desc = $desc;
666 $this->line->qty = $qty;
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;
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);
695 $this->line->date_end = $date_end;
698 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
700 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
702 $productFournisseur->find_min_price_product_fournisseur($fk_product);
703 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
705 $this->line->fk_fournprice = ($fk_fournprice > 0 ? $fk_fournprice : 0);
707 $this->line->pa_ht = $pa_ht;
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;
719 if (empty($qty) && empty($special_code)) {
720 $this->line->special_code = 3;
723 if (is_array($array_options) && count($array_options) > 0) {
724 $this->line->array_options = $array_options;
727 $result = $this->line->insert();
730 if (!empty($fk_parent_line)) {
732 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
733 $linecount = count($this->lines);
734 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
740 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
743 return $this->line->id;
745 $this->db->rollback();
750 $this->db->rollback();
754 $this->error =
'BadStatusOfObjectToAddLine';
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)
791 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
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';
799 $remise_percent =
price2num($remise_percent);
802 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
808 if (empty($qty) && empty($special_code)) {
811 if (!empty($qty) && $special_code == 3) {
827 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
828 $vat_src_code = $reg[1];
829 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
832 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
840 if ($tmpline->fetch($rowid) > 0 && $tmpline->fk_product > 0) {
841 $prod =
new Product($this->db);
843 $prod->get_buyprice(($fk_fournprice > 0 ? (
int) $fk_fournprice : (int) $tmpline->fk_fournprice), (float) $qty, $tmpline->fk_product,
'none', $this->socid);
846 if ($newqty != $qty) {
848 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
856 (
float) $remise_percent,
858 (
float) $txlocaltax1,
859 (
float) $txlocaltax2,
867 (
float) $this->multicurrency_tx,
869 $this->multicurrency_code
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];
881 $multicurrency_total_ht = $tabprice[16];
882 $multicurrency_total_tva = $tabprice[17];
883 $multicurrency_total_ttc = $tabprice[18];
884 $pu_ht_devise = $tabprice[19];
888 $line->fetch($rowid);
889 $line->fetch_optionals();
891 $fk_product = $line->fk_product;
894 $staticline = clone $line;
896 $line->oldline = $staticline;
898 $this->line->context = $this->context;
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;
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;
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;
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;
935 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
937 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
939 $productFournisseur->find_min_price_product_fournisseur($fk_product);
940 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
942 $this->line->fk_fournprice = $fk_fournprice;
944 $this->line->pa_ht = $pa_ht;
946 if (is_array($array_options) && count($array_options) > 0) {
948 foreach ($array_options as $key => $value) {
949 $this->line->array_options[$key] = $array_options[$key];
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;
959 $result = $this->line->update();
962 if (!empty($fk_parent_line)) {
971 $this->error = $this->db->error();
972 $this->db->rollback();
976 dol_syslog(get_class($this).
"::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
996 $line->fetch($lineid);
998 if ($this->
id > 0 && (
int) $line->fk_supplier_proposal !== (
int) $this->id) {
999 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
1003 if ($line->delete($user) > 0) {
1024 public function create($user, $notrigger = 0)
1036 $this->error =
"Failed to fetch company";
1037 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1040 if (!empty($this->
ref)) {
1043 $this->error =
'ErrorRefAlreadyExists';
1044 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1045 $this->db->rollback();
1051 $delivery_date = $this->delivery_date;
1054 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1056 } elseif (!empty($this->multicurrency_code)) {
1059 if (empty($this->fk_multicurrency)) {
1061 $this->fk_multicurrency = 0;
1062 $this->multicurrency_tx = 1;
1068 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"supplier_proposal (";
1071 $sql .=
", total_tva";
1072 $sql .=
", total_ttc";
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";
1087 $sql .=
", fk_multicurrency";
1088 $sql .=
", multicurrency_code";
1089 $sql .=
", multicurrency_tx";
1091 $sql .=
" VALUES (";
1092 $sql .= ((int) $this->socid);
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);
1115 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1116 $resql = $this->db->query($sql);
1118 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"supplier_proposal");
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);
1124 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1125 $resql = $this->db->query($sql);
1130 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1131 $this->linked_objects = $this->linkedObjectsIds;
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)) {
1138 foreach ($tmp_origin_id as $origin_id) {
1141 dol_print_error($this->db);
1153 $fk_parent_line = 0;
1154 $num = count($this->lines);
1156 for ($i = 0; $i < $num; $i++) {
1157 if (!is_object($this->lines[$i])) {
1161 foreach ($this->lines[$i] as $key => $val) {
1162 $lineobj->$key = $val;
1164 $this->lines[$i] = $lineobj;
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;
1173 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
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,
1186 $this->lines[$i]->product_type,
1187 $this->lines[$i]->rang,
1188 $this->lines[$i]->special_code,
1190 $this->lines[$i]->fk_fournprice,
1191 $this->lines[$i]->pa_ht,
1192 empty($this->lines[$i]->label) ?
'' : $this->lines[$i]->label,
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
1202 $this->error = $this->db->error;
1203 dol_print_error($this->db);
1207 if ($result > 0 && $this->lines[$i]->product_type == 9) {
1208 $fk_parent_line = $result;
1227 if (!$error && !$notrigger) {
1229 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_CREATE', $user);
1236 $this->error = $this->db->lasterror();
1241 $this->error = $this->db->lasterror();
1246 $this->db->commit();
1247 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1250 $this->db->rollback();
1254 $this->error = $this->db->lasterror();
1255 $this->db->rollback();
1269 global $hookmanager;
1277 foreach ($this->lines as $line) {
1278 $line->fetch_optionals();
1282 $objFrom = clone $this;
1284 $objsoc =
new Societe($this->db);
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);
1298 $objsoc->fetch($this->socid);
1305 if (!
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON') || !is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/supplier_proposal/" .
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON').
".php")) {
1306 $this->error =
'ErrorSetupNotComplete';
1311 $this->user_author_id = $user->id;
1312 $this->user_validation_id = 0;
1316 require_once DOL_DOCUMENT_ROOT.
"/core/modules/supplier_proposal/" .
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON').
'.php';
1318 $modSupplierProposal =
new $obj();
1319 '@phan-var-force ModeleNumRefSupplierProposal $modSupplierProposal';
1320 $this->
ref = $modSupplierProposal->getNextValue($objsoc, $this);
1323 $this->context[
'createfromclone'] =
'createfromclone';
1324 $result = $this->
create($user);
1331 if (is_object($hookmanager)) {
1332 $parameters = array(
'objFrom' => $objFrom);
1334 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1342 unset($this->context[
'createfromclone']);
1346 $this->db->commit();
1349 $this->db->rollback();
1361 public function fetch($rowid, $ref =
'')
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').
")";
1388 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
1390 $sql .=
" AND p.rowid = ".((int) $rowid);
1393 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1394 $resql = $this->db->query($sql);
1396 if ($this->db->num_rows($resql)) {
1397 $obj = $this->db->fetch_object($resql);
1399 $this->
id = $obj->rowid;
1400 $this->entity = $obj->entity;
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;
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);
1417 $this->datev = $this->db->jdate($obj->datev);
1418 $this->date_creation = $this->db->jdate($obj->datec);
1419 $this->date_modification = $this->db->jdate($obj->date_modification);
1420 $this->
date = $this->date_creation;
1421 $this->date_validation = $this->db->jdate($obj->datev);
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;
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;
1437 $this->extraparams = (array) (!empty($obj->extraparams) ? json_decode($obj->extraparams,
true) : array());
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;
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;
1452 $this->db->free($resql);
1458 $this->lines = array();
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";
1471 $result = $this->db->query($sql);
1473 $num = $this->db->num_rows($result);
1477 $objp = $this->db->fetch_object($result);
1481 $line->rowid = $objp->rowid;
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;
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;
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;
1511 $line->fk_product = $objp->fk_product;
1513 $line->ref = $objp->product_ref;
1514 $line->product_ref = $objp->product_ref;
1515 $line->libelle = $objp->product_label;
1516 $line->product_label = $objp->product_label;
1517 $line->product_desc = $objp->product_desc;
1518 $line->fk_product_type = $objp->fk_product_type;
1520 $line->ref_fourn = $objp->ref_produit_fourn;
1522 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
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;
1533 $line->fetch_optionals();
1535 $this->lines[$i] = $line;
1539 $this->db->free($result);
1541 $this->error = $this->db->error();
1548 $this->error =
"Record Not Found";
1551 $this->error = $this->db->error();
1563 public function update($user, $notrigger = 0)
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);
1582 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1583 $resql = $this->db->query($sql);
1586 $this->errors[] =
"Error ".$this->db->lasterror();
1596 if (!$error && !$notrigger) {
1598 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_MODIFY', $user);
1606 $this->error = implode(
', ', $this->errors);
1607 $this->db->rollback();
1611 $this->db->commit();
1622 public function valid($user, $notrigger = 0)
1624 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1631 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'supplier_proposal',
'creer'))
1632 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'supplier_proposal',
'validate_advance'))) {
1636 $soc =
new Societe($this->db);
1637 $result = $soc->fetch($this->socid);
1643 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
1647 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1648 $num = $this->getNextNumRef($soc);
1650 $num = (string) $this->
ref;
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";
1659 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
1660 $resql = $this->db->query($sql);
1662 dol_print_error($this->db);
1667 if (!$error && !$notrigger) {
1669 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_VALIDATE', $user);
1677 $this->oldref = $this->ref;
1680 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
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);
1687 $this->error = $this->db->lasterror();
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);
1694 $this->error = $this->db->lasterror();
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)) {
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);
1722 $this->user_validation_id = $user->id;
1723 $this->datev = $now;
1724 $this->date_validation = $now;
1727 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1728 if ($result < 0 && $result != -2) {
1733 $this->db->commit();
1736 $this->db->rollback();
1740 dol_syslog(
"You don't have permission to validate supplier proposal", LOG_WARNING);
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);
1774 if ($this->db->query($sql)) {
1775 $this->delivery_date = $delivery_date;
1778 $this->error = $this->db->error();
1779 dol_syslog(get_class($this).
"::setDeliveryDate Erreur SQL");
1796 public function reopen($user, $status, $note =
'', $notrigger = 0)
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).
"',";
1805 $sql .=
" date_cloture = NULL, fk_user_cloture = NULL";
1806 $sql .=
" WHERE rowid = ".((int) $this->
id);
1810 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
1811 $resql = $this->db->query($sql);
1814 $this->errors[] =
"Error ".$this->db->lasterror();
1819 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_REOPEN', $user);
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);
1835 $this->db->rollback();
1838 $this->statut = $status;
1841 $this->db->commit();
1857 global $langs,
$conf;
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);
1871 $resql = $this->db->query($sql);
1873 $this->statut = $status;
1876 $modelpdf =
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED', (empty($this->model_pdf) ?
'' : $this->model_pdf));
1877 $triggerName =
'PROPOSAL_SUPPLIER_CLOSE_REFUSED';
1880 $triggerName =
'PROPOSAL_SUPPLIER_CLOSE_SIGNED';
1881 $modelpdf =
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL', (empty($this->model_pdf) ?
'' : $this->model_pdf));
1888 $triggerName =
'PROPOSAL_SUPPLIER_CLASSIFY_BILLED';
1893 $outputlangs = $langs;
1896 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
1897 $outputlangs->setDefaultLang($newlang);
1900 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1904 $result = $this->call_trigger($triggerName, $user);
1911 $this->db->commit();
1914 $this->db->rollback();
1918 $this->error = $this->db->lasterror();
1919 $this->errors[] = $this->db->lasterror();
1920 $this->db->rollback();
1933 dol_syslog(get_class($this).
"::updateOrCreatePriceFournisseur", LOG_DEBUG);
1935 foreach ($this->lines as $product) {
1936 if ($product->subprice <= 0) {
1941 $multicurrency_tx = 1;
1942 $fk_multicurrency = 0;
1944 if (empty($this->thirdparty)) {
1948 $ref_fourn = $product->ref_fourn;
1949 if (empty($ref_fourn)) {
1950 $ref_fourn = $product->ref_supplier;
1952 if (
isModEnabled(
"multicurrency") && !empty($product->multicurrency_code)) {
1955 $productsupplier->id = $product->fk_product;
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);
1973 $price =
price2num($product->subprice * $product->qty,
'MU');
1974 $unitPrice =
price2num($product->subprice,
'MU');
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);
1978 $resql = $this->db->query($sql);
1980 $this->error = $this->db->error();
1981 $this->db->rollback();
1996 $price =
price2num($product->subprice * $product->qty,
'MU');
1998 $unitPrice =
price2num($product->subprice,
'MU');
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).
"'",
2010 (
float) $product->tva_tx,
2014 if (!empty($product->multicurrency_code)) {
2015 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
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;
2025 for ($i = 0; $i < 5; $i++) {
2026 $sanitized_values[] =
'NULL';
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';
2037 $sql .=
') VALUES ('.implode(
',', $sanitized_values).
')';
2039 $resql = $this->db->query($sql);
2041 $this->error = $this->db->error();
2042 $this->db->rollback();
2060 if ($this->
status == self::STATUS_DRAFT) {
2061 dol_syslog(get_class($this).
"::setDraft already draft status", LOG_WARNING);
2065 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal";
2066 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
2067 $sql .=
" WHERE rowid = ".((int) $this->
id);
2069 if ($this->db->query($sql)) {
2071 $this->oldcopy = clone $this;
2076 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_UNVALIDATE', $user);
2085 $this->db->commit();
2088 $this->db->rollback();
2111 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datec', $sortorder =
'DESC')
2119 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2120 $search_sale = $user->id;
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";
2131 $sql .=
" AND s.rowid = ".((int) $socid);
2134 $sql .=
" AND p.fk_statut = 0";
2136 if ($notcurrentuser > 0) {
2137 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
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).
")";
2147 $sql .= $this->db->order($sortfield, $sortorder);
2148 $sql .= $this->db->plimit($limit, $offset);
2150 $result = $this->db->query($sql);
2152 $num = $this->db->num_rows($result);
2156 $obj = $this->db->fetch_object($result);
2158 if ($shortlist == 1) {
2159 $ga[$obj->supplier_proposalid] = $obj->ref;
2160 } elseif ($shortlist == 2) {
2161 $ga[$obj->supplier_proposalid] = $obj->ref.
' ('.$obj->name.
')';
2163 $ga[$i][
'id'] = $obj->supplier_proposalid;
2164 $ga[$i][
'ref'] = $obj->ref;
2165 $ga[$i][
'name'] = $obj->name;
2173 dol_print_error($this->db);
2185 public function delete($user, $notrigger = 0)
2188 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2196 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_DELETE', $user);
2205 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_proposal";
2206 $sql .=
" WHERE fk_supplier_proposal = ".((int) $this->
id);
2208 $result = $this->db->query($sql);
2211 $this->error = $this->db->lasterror();
2212 $this->errors[] = $this->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)) {
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)) {
2244 $this->error =
'ErrorFailToDeleteFile';
2245 $this->errors = array(
'ErrorFailToDeleteFile');
2246 $this->db->rollback();
2250 if (file_exists($dir)) {
2253 $this->error =
'ErrorFailToDeleteDir';
2254 $this->errors = array(
'ErrorFailToDeleteDir');
2255 $this->db->rollback();
2268 dol_syslog(get_class($this).
"::delete erreur ".$errorflag.
" ".$this->error, LOG_ERR);
2273 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
2274 $this->db->commit();
2277 $this->error = $this->db->lasterror();
2278 $this->db->rollback();
2282 $this->error = $this->db->lasterror();
2283 $this->db->rollback();
2287 $this->error = $this->db->lasterror();
2288 $this->db->rollback();
2292 $this->db->rollback();
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);
2312 $result = $this->db->query($sql);
2315 if ($this->db->num_rows($result)) {
2316 $obj = $this->db->fetch_object($result);
2318 $this->
id = $obj->rowid;
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);
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;
2330 $this->db->free($result);
2332 dol_print_error($this->db);
2361 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
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");
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';
2389 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusnew, $mode);
2404 global
$conf, $langs;
2411 if ($mode ==
'opened') {
2412 $delay_warning = !empty(
$conf->supplier_proposal->cloture->warning_delay) ?
$conf->supplier_proposal->cloture->warning_delay : 0;
2414 if ($mode ==
'signed') {
2415 $delay_warning = !empty(
$conf->supplier_proposal->facturation->warning_delay) ?
$conf->supplier_proposal->facturation->warning_delay : 0;
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";
2425 $sql .=
" 0 as nblate";
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);
2433 $sql .= $clause.
" p.entity IN (".
getEntity(
'supplier_proposal').
")";
2434 if ($mode ==
'opened') {
2435 $sql .=
" AND p.fk_statut = 1";
2437 if ($mode ==
'signed') {
2438 $sql .=
" AND p.fk_statut = 2";
2441 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2444 $resql = $this->db->query($sql);
2446 $label = $labelShort =
'';
2448 if ($mode ==
'opened') {
2450 $label = $langs->trans(
"SupplierProposalsToClose");
2451 $labelShort = $langs->trans(
"ToAcceptRefuse");
2453 if ($mode ==
'signed') {
2455 $label = $langs->trans(
"SupplierProposalsToProcess");
2456 $labelShort = $langs->trans(
"ToClose");
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");
2468 $obj = $this->db->fetch_object($resql);
2470 $response->nbtodo = (int) $obj->nb;
2471 $response->nbtodolate = (int) $obj->nblate;
2475 $this->error = $this->db->lasterror();
2491 global
$conf, $langs;
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']);
2502 $sql .= $this->db->plimit(100);
2504 $resql = $this->db->query($sql);
2506 $num_prods = $this->db->num_rows($resql);
2508 while ($i < $num_prods) {
2510 $row = $this->db->fetch_row($resql);
2511 $prodids[$i] = $row[0];
2517 $this->
ref =
'SPECIMEN';
2518 $this->ref_supplier =
'NEMICEPS';
2519 $this->specimen = 1;
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)';
2529 $this->multicurrency_tx = 1;
2535 while ($xnbp < $nbp) {
2537 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
2539 $line->subprice = 100;
2540 $line->tva_tx = 19.6;
2541 $line->localtax1_tx = 0;
2542 $line->localtax2_tx = 0;
2544 $line->total_ht = 50;
2545 $line->total_ttc = 59.8;
2546 $line->total_tva = 9.8;
2547 $line->remise_percent = 50;
2549 $line->total_ht = 100;
2550 $line->total_ttc = 119.6;
2551 $line->total_tva = 19.6;
2552 $line->remise_percent = 00;
2555 if ($num_prods > 0) {
2556 $prodid = mt_rand(1, $num_prods);
2557 $line->fk_product = $prodids[$prodid];
2560 $this->lines[$xnbp] = $line;
2562 $this->total_ht += $line->total_ht;
2563 $this->total_tva += $line->total_tva;
2564 $this->total_ttc += $line->total_ttc;
2581 $this->nb = array();
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);
2592 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'supplier_proposal').
")";
2594 $resql = $this->db->query($sql);
2597 while ($obj = $this->db->fetch_object($resql)) {
2598 $this->nb[
"supplier_proposals"] = $obj->nb;
2600 $this->db->free($resql);
2603 dol_print_error($this->db);
2604 $this->error = $this->db->lasterror();
2617 public function getNextNumRef($soc)
2619 global
$conf, $db, $langs;
2620 $langs->load(
"supplier_proposal");
2629 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2630 foreach ($dirmodels as $reldir) {
2631 $dir =
dol_buildpath($reldir.
"core/modules/supplier_proposal/");
2634 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2638 dol_print_error(
null,
"Failed to include file ".$file);
2642 $obj =
new $classname();
2643 '@phan-var-force ModeleNumRefSupplierProposal $obj';
2646 $numref = $obj->getNextValue($soc, $this);
2648 if ($numref !=
"") {
2651 $this->error = $obj->error;
2655 $langs->load(
"errors");
2656 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"SupplierProposal"));
2669 global
$conf, $langs;
2671 $langs->load(
'supplier_proposal');
2674 return [
'optimize' => $langs->trans(
"ShowSupplierProposal")];
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);
2684 if (!empty($this->
ref)) {
2685 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2687 if (!empty($this->ref_fourn)) {
2688 $datas[
'ref_supplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_fourn;
2690 if (empty($params[
'nofetch'])) {
2691 $langs->load(
'companies');
2692 if (empty($this->thirdparty)) {
2695 if (is_object($this->thirdparty)) {
2696 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
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());
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());
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());
2723 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2725 global $langs,
$conf, $user, $hookmanager;
2727 if (!empty(
$conf->dol_no_mouse_hover)) {
2735 'objecttype' => $this->element,
2736 'option' => $option,
2738 $classfortooltip =
'classfortooltip';
2741 $classfortooltip =
'classforajaxtooltip';
2742 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2748 if ($option ==
'') {
2749 $url = DOL_URL_ROOT.
'/supplier_proposal/card.php?id='.$this->
id.$get_params;
2751 if ($option ==
'document') {
2752 $url = DOL_URL_ROOT.
'/supplier_proposal/document.php?id='.$this->
id.$get_params;
2755 if ($option !==
'nolink') {
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;
2761 if ($add_save_lastsearch_values) {
2762 $url .=
'&save_lastsearch_values=1';
2767 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
2769 $label = $langs->trans(
"ShowSupplierProposal");
2770 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2772 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2773 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2776 $linkstart =
'<a href="'.$url.
'"';
2777 $linkstart .= $linkclose.
'>';
2780 $result .= $linkstart;
2782 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
2784 if ($withpicto != 2) {
2785 $result .= $this->ref;
2787 $result .= $linkend;
2789 if ($addlinktonotes) {
2790 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
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');
2799 $result .=
'</span>';
2803 $hookmanager->initHooks(array($this->element .
'dao'));
2804 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2805 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2807 $result = $hookmanager->resPrint;
2809 $result .= $hookmanager->resPrint;
2824 $context = parent::getObjectLinesDisplayContext();
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;
2833 $context[
'senderissupplier'] = (
getDolGlobalInt(
'SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') ?
getDolGlobalInt(
'SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') : 2);
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';
2859 dol_syslog(get_class($this).
'::getLinesArray', LOG_DEBUG);
2860 $resql = $this->db->query($sql);
2862 $num = $this->db->num_rows($resql);
2866 $obj = $this->db->fetch_object($resql);
2869 $this->lines[$i]->id = $obj->rowid;
2870 $this->lines[$i]->rowid = $obj->rowid;
2872 $this->lines[$i]->label = $obj->custom_label;
2873 $this->lines[$i]->description = $obj->description;
2874 $this->lines[$i]->desc = $obj->description;
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;
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;
2901 $this->lines[$i]->ref_fourn = $obj->ref_supplier;
2902 $this->lines[$i]->ref_supplier = $obj->ref_supplier;
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();
2914 $this->lines[$i]->fetch_optionals();
2918 $this->db->free($resql);
2922 $this->error = $this->db->error();
2938 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2942 $langs->load(
"supplier_proposal");
2943 $outputlangs->load(
"products");
2948 if ($this->model_pdf) {
2949 $modele = $this->model_pdf;
2955 if (empty($modele)) {
2959 $modelpath =
"core/modules/supplier_proposal/doc/";
2961 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2993 'supplier_proposaldet'
3011 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
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);
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"' :
'').
'>';
3024 if (property_exists($this,
'socid')) {
3025 $return .=
'<span class="info-box-ref"> | '.$this->socid.
'</span>';
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>';
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>';
3033 if (method_exists($this,
'getLibStatut')) {
3034 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3036 $return .=
'</div>';
3037 $return .=
'</div>';
3038 $return .=
'</div>';
3054 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3055 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_PROPOSAL);
3078 public $element =
'supplier_proposaldet';
3083 public $table_element =
'supplier_proposaldet';
3108 public $fk_supplier_proposal;
3113 public $fk_parent_line;
3130 public $fk_product_type;
3149 public $vat_src_code;
3154 public $remise_percent;
3159 public $fk_remise_except;
3169 public $fk_fournprice;
3187 public $special_code;
3195 public $info_bits = 0;
3233 public $product_ref;
3246 public $product_label;
3258 public $product_desc;
3263 public $localtax1_tx;
3267 public $localtax2_tx;
3271 public $localtax1_type;
3275 public $localtax2_type;
3279 public $total_localtax1;
3283 public $total_localtax2;
3288 public $skip_update_total;
3297 public $ref_supplier;
3303 public $fk_multicurrency;
3308 public $multicurrency_code;
3312 public $multicurrency_subprice;
3316 public $multicurrency_total_ht;
3320 public $multicurrency_total_tva;
3324 public $multicurrency_total_ttc;
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);
3356 $result = $this->db->query($sql);
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;
3366 $this->subprice = $objp->subprice;
3367 $this->subprice_ttc = $objp->subprice_ttc;
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);
3377 $this->total_ht = $objp->total_ht;
3378 $this->total_tva = $objp->total_tva;
3379 $this->total_ttc = $objp->total_ttc;
3381 $this->fk_fournprice = $objp->fk_fournprice;
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];
3388 $this->special_code = $objp->special_code;
3389 $this->product_type = $objp->product_type;
3390 $this->rang = $objp->rang;
3392 $this->product_ref = $objp->product_ref;
3393 $this->product_label = $objp->product_label;
3394 $this->product_desc = $objp->product_desc;
3396 $this->ref_fourn = $objp->ref_produit_fourn;
3398 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
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;
3410 $this->db->free($result);
3415 dol_print_error($this->db);
3432 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3435 if (empty($this->tva_tx)) {
3438 if (empty($this->vat_src_code)) {
3439 $this->vat_src_code =
'';
3441 if (empty($this->localtax1_tx)) {
3442 $this->localtax1_tx = 0;
3444 if (empty($this->localtax2_tx)) {
3445 $this->localtax2_tx = 0;
3447 if (empty($this->localtax1_type)) {
3448 $this->localtax1_type =
'';
3450 if (empty($this->localtax2_type)) {
3451 $this->localtax2_type =
'';
3453 if (empty($this->total_localtax1)) {
3454 $this->total_localtax1 = 0;
3456 if (empty($this->total_localtax2)) {
3457 $this->total_localtax2 = 0;
3459 if (empty($this->rang)) {
3462 if (empty($this->remise_percent)) {
3463 $this->remise_percent = 0;
3465 if (empty($this->info_bits)) {
3466 $this->info_bits = 0;
3468 if (empty($this->special_code)) {
3469 $this->special_code = 0;
3471 if (empty($this->fk_parent_line)) {
3472 $this->fk_parent_line = 0;
3474 if (empty($this->fk_fournprice)) {
3475 $this->fk_fournprice = 0;
3477 if (empty($this->fk_unit)) {
3480 if (empty($this->subprice)) {
3481 $this->subprice = 0;
3484 if (empty($this->pa_ht)) {
3489 if ($this->pa_ht == 0) {
3490 $result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3494 $this->pa_ht = $result;
3499 if ($this->product_type < 0) {
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');
3555 dol_syslog(get_class($this).
'::insert', LOG_DEBUG);
3556 $resql = $this->db->query($sql);
3558 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'supplier_proposaldet');
3567 if (!$error && !$notrigger) {
3569 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_INSERT', $user);
3571 $this->db->rollback();
3577 $this->db->commit();
3580 $this->error = $this->db->error().
" sql=".$sql;
3581 $this->db->rollback();
3592 public function delete($user)
3598 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"supplier_proposaldet";
3599 $sql .=
" WHERE rowid = ".((int) $this->
id);
3601 if ($this->db->query($sql)) {
3607 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
3612 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_DELETE', $user);
3614 $this->db->rollback();
3619 $this->db->commit();
3623 $this->error = $this->db->error().
" sql=".$sql;
3624 $this->db->rollback();
3642 if (empty($this->tva_tx)) {
3645 if (empty($this->localtax1_tx)) {
3646 $this->localtax1_tx = 0;
3648 if (empty($this->localtax2_tx)) {
3649 $this->localtax2_tx = 0;
3651 if (empty($this->total_localtax1)) {
3652 $this->total_localtax1 = 0;
3654 if (empty($this->total_localtax2)) {
3655 $this->total_localtax2 = 0;
3657 if (empty($this->localtax1_type)) {
3658 $this->localtax1_type =
'';
3660 if (empty($this->localtax2_type)) {
3661 $this->localtax2_type =
'';
3663 if (empty($this->marque_tx)) {
3664 $this->marque_tx = 0;
3666 if (empty($this->marge_tx)) {
3667 $this->marge_tx = 0;
3669 if (empty($this->remise_percent)) {
3670 $this->remise_percent = 0;
3672 if (empty($this->info_bits)) {
3673 $this->info_bits = 0;
3675 if (empty($this->special_code)) {
3676 $this->special_code = 0;
3678 if (empty($this->fk_parent_line)) {
3679 $this->fk_parent_line = 0;
3681 if (empty($this->fk_fournprice)) {
3682 $this->fk_fournprice = 0;
3684 if (empty($this->fk_unit)) {
3687 if (empty($this->subprice)) {
3688 $this->subprice = 0;
3691 if (empty($this->pa_ht)) {
3696 if ($this->pa_ht == 0) {
3697 $result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3701 $this->pa_ht = $result;
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);
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);
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');
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);
3748 $sql .=
" WHERE rowid = ".((int) $this->
id);
3750 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3751 $resql = $this->db->query($sql);
3760 if (!$error && !$notrigger) {
3762 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_MODIFY', $user);
3764 $this->db->rollback();
3770 $this->db->commit();
3773 $this->error = $this->db->error();
3774 $this->db->rollback();
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);
3798 dol_syslog(
"SupplierProposalLine::update_total", LOG_DEBUG);
3800 $resql = $this->db->query($sql);
3802 $this->db->commit();
3805 $this->error = $this->db->error();
3806 $this->db->rollback();
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.
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...
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.
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)
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.
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