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;
189 public $mode_reglement_code;
194 public $mode_reglement;
201 public $deposit_percent;
207 public $extraparams = array();
212 public $lines = array();
219 public $labelStatus = array();
220 public $labelStatusShort = array();
235 public $fk_multicurrency;
240 public $multicurrency_code;
244 public $multicurrency_tx;
248 public $multicurrency_total_ht;
252 public $multicurrency_total_tva;
256 public $multicurrency_total_ttc;
258 public $fields = array(
259 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
260 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
297 public function __construct($db, $socid = 0, $supplier_proposalid = 0)
301 $this->ismultientitymanaged = 1;
302 $this->socid = $socid;
303 $this->
id = $supplier_proposalid;
318 public function add_product($idproduct, $qty, $remise_percent = 0)
327 dol_syslog(get_class($this).
"::add_product $idproduct, $qty, $remise_percent");
328 if ($idproduct > 0) {
330 $prod->fetch($idproduct);
332 $productdesc =
$prod->description;
336 if (empty($tva_tx)) {
344 $price =
$prod->multiprices[$this->thirdparty->price_level];
346 $price =
$prod->price;
351 $line->fk_product = $idproduct;
352 $line->desc = $productdesc;
354 $line->subprice = $price;
355 $line->remise_percent = $remise_percent;
356 $line->tva_tx = $tva_tx;
358 $this->lines[] = $line;
376 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
377 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
382 $result = $remise->fetch($idremise);
385 if ($remise->fk_facture) {
386 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
387 $this->db->rollback();
392 $supplier_proposalligne->fk_supplier_proposal = $this->id;
393 $supplier_proposalligne->fk_remise_except = $remise->id;
394 $supplier_proposalligne->desc = $remise->description;
395 $supplier_proposalligne->tva_tx = $remise->tva_tx;
396 $supplier_proposalligne->localtax1_tx = $remise->localtax1_tx;
397 $supplier_proposalligne->localtax1_type = $remise->localtax1_type;
398 $supplier_proposalligne->localtax2_tx = $remise->localtax1_tx;
399 $supplier_proposalligne->localtax2_type = $remise->localtax1_type;
400 $supplier_proposalligne->subprice = -(float) $remise->amount_ht;
401 $supplier_proposalligne->fk_product = 0;
402 $supplier_proposalligne->qty = 1;
403 $supplier_proposalligne->remise_percent = 0;
404 $supplier_proposalligne->rang = -1;
405 $supplier_proposalligne->info_bits = 2;
407 $supplier_proposalligne->total_ht = -(float) $remise->amount_ht;
408 $supplier_proposalligne->total_tva = -(float) $remise->amount_tva;
409 $supplier_proposalligne->total_ttc = -(float) $remise->amount_ttc;
410 $supplier_proposalligne->total_localtax1 = -(float) $remise->total_localtax1;
411 $supplier_proposalligne->total_localtax2 = -(float) $remise->total_localtax2;
413 $result = $supplier_proposalligne->insert();
420 $this->db->rollback();
425 $this->db->rollback();
429 $this->db->rollback();
470 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)
474 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");
475 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
478 if (empty($remise_percent)) {
484 if (empty($info_bits)) {
490 if (empty($fk_parent_line) || $fk_parent_line < 0) {
497 $remise_percent =
price2num($remise_percent);
501 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
507 if ($price_base_type ==
'HT') {
518 if ($this->
status == self::STATUS_DRAFT) {
521 if ($fk_product > 0) {
522 if (
getDolGlobalInt(
'SUPPLIER_PROPOSAL_WITH_PREDEFINED_PRICES_ONLY') == 1) {
524 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" fk_fournprice=".$fk_fournprice.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
526 if ($productsupplier->fetch($fk_product) > 0) {
527 $product_type = $productsupplier->type;
528 $label = $productsupplier->label;
529 $fk_prod_fourn_price = $fk_fournprice;
534 $result = $productsupplier->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', $this->socid);
536 $pu = $productsupplier->fourn_pu;
537 $ref_supplier = $productsupplier->ref_supplier;
539 if ($remise_percent == 0 && $productsupplier->remise_percent != 0) {
540 $remise_percent = $productsupplier->remise_percent;
544 $langs->load(
"errors");
545 $this->error =
"Ref ".$productsupplier->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
546 $this->db->rollback();
547 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
553 $langs->load(
"errors");
554 $this->error =
"Ref ".$productsupplier->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
555 $this->db->rollback();
556 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
561 $this->db->rollback();
562 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
567 $this->db->rollback();
576 $prod->get_buyprice(($fk_fournprice > 0 ? (
int) $fk_fournprice : 0), (
float) $qty, $fk_product,
'none', $this->socid);
579 if ($newqty != $qty) {
581 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
586 if (!empty(
$prod->fourn_qty) && (
float) $qty > 0 && (
float) $qty < (
float)
$prod->fourn_qty) {
587 if (!empty(
$prod->packaging) && (
float)
price2num(fmod((
float)
$prod->fourn_qty, (
float)
$prod->packaging),
'MS')) {
588 $coeff = intval((
float)
$prod->fourn_qty / (
float)
$prod->packaging) + 1;
589 $qty = (float)
price2num((
float)
$prod->packaging * $coeff,
'MS');
591 $qty = (float)
$prod->fourn_qty;
593 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
597 $product_type = $type;
609 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
610 $vat_src_code = $reg[1];
611 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
614 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
621 (
float) $remise_percent,
623 (
float) $txlocaltax1,
624 (
float) $txlocaltax2,
632 (
float) $this->multicurrency_tx,
635 $total_ht = $tabprice[0];
636 $total_tva = $tabprice[1];
637 $total_ttc = $tabprice[2];
638 $total_localtax1 = $tabprice[9];
639 $total_localtax2 = $tabprice[10];
640 $pu = $pu_ht = $tabprice[3];
643 $multicurrency_total_ht = $tabprice[16];
644 $multicurrency_total_tva = $tabprice[17];
645 $multicurrency_total_ttc = $tabprice[18];
646 $pu_ht_devise = $tabprice[19];
650 if ($ranktouse == -1) {
651 $rangmax = $this->
line_max($fk_parent_line);
652 $ranktouse = $rangmax + 1;
658 $this->line->fk_supplier_proposal = $this->id;
659 $this->line->label = $label;
660 $this->line->desc = $desc;
661 $this->line->qty = $qty;
663 $this->line->vat_src_code = $vat_src_code;
664 $this->line->tva_tx = $txtva;
665 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
666 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
667 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
668 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
669 $this->line->fk_product = $fk_product;
670 $this->line->remise_percent = $remise_percent;
671 $this->line->subprice = (float) $pu_ht;
673 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
674 $this->line->rang = $ranktouse;
675 $this->line->info_bits = $info_bits;
676 $this->line->total_ht = (float) $total_ht;
677 $this->line->total_tva = (float) $total_tva;
678 $this->line->total_localtax1 = (float) $total_localtax1;
679 $this->line->total_localtax2 = (float) $total_localtax2;
680 $this->line->total_ttc = (float) $total_ttc;
681 $this->line->product_type = $type;
682 $this->line->special_code = $special_code;
683 $this->line->fk_parent_line = $fk_parent_line;
684 $this->line->fk_unit = $fk_unit;
685 $this->line->origin = $origin;
686 $this->line->origin_type = $origin;
687 $this->line->origin_id = $origin_id;
688 $this->line->ref_fourn = $this->db->escape($ref_supplier);
690 $this->line->date_end = $date_end;
693 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
695 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
697 $productFournisseur->find_min_price_product_fournisseur($fk_product);
698 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
700 $this->line->fk_fournprice = ($fk_fournprice > 0 ? $fk_fournprice : 0);
702 $this->line->pa_ht = $pa_ht;
706 $this->line->fk_multicurrency = $this->fk_multicurrency;
707 $this->line->multicurrency_code = $this->multicurrency_code;
708 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
709 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
710 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
711 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
714 if (empty($qty) && empty($special_code)) {
715 $this->line->special_code = 3;
718 if (is_array($array_options) && count($array_options) > 0) {
719 $this->line->array_options = $array_options;
722 $result = $this->line->insert();
725 if (!empty($fk_parent_line)) {
727 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
728 $linecount = count($this->lines);
729 for ($ii = $ranktouse; $ii <= $linecount; $ii++) {
735 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
738 return $this->line->id;
740 $this->db->rollback();
745 $this->db->rollback();
749 $this->error =
'BadStatusOfObjectToAddLine';
781 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)
786 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
790 dol_syslog(get_class($this).
"::updateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits");
791 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
794 $remise_percent =
price2num($remise_percent);
797 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
803 if (empty($qty) && empty($special_code)) {
806 if (!empty($qty) && $special_code == 3) {
822 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
823 $vat_src_code = $reg[1];
824 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
827 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
835 if ($tmpline->fetch($rowid) > 0 && $tmpline->fk_product > 0) {
838 $prod->get_buyprice(($fk_fournprice > 0 ? (
int) $fk_fournprice : (int) $tmpline->fk_fournprice), (float) $qty, $tmpline->fk_product,
'none', $this->socid);
841 if ($newqty != $qty) {
843 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
851 (
float) $remise_percent,
853 (
float) $txlocaltax1,
854 (
float) $txlocaltax2,
862 (
float) $this->multicurrency_tx,
865 $total_ht = $tabprice[0];
866 $total_tva = $tabprice[1];
867 $total_ttc = $tabprice[2];
868 $total_localtax1 = $tabprice[9];
869 $total_localtax2 = $tabprice[10];
870 $pu_ht = $tabprice[3];
871 $pu_tva = $tabprice[4];
872 $pu_ttc = $tabprice[5];
875 $multicurrency_total_ht = $tabprice[16];
876 $multicurrency_total_tva = $tabprice[17];
877 $multicurrency_total_ttc = $tabprice[18];
878 $pu_ht_devise = $tabprice[19];
882 $line->fetch($rowid);
883 $line->fetch_optionals();
885 $fk_product = $line->fk_product;
888 $staticline = clone $line;
890 $line->oldline = $staticline;
892 $this->line->context = $this->context;
895 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
896 $rangmax = $this->
line_max($fk_parent_line);
897 $this->line->rang = $rangmax + 1;
900 $this->line->id = $rowid;
901 $this->line->label = $label;
902 $this->line->desc = $desc;
903 $this->line->qty = $qty;
904 $this->line->product_type = $type;
906 $this->line->vat_src_code = $vat_src_code;
907 $this->line->tva_tx = $txtva;
908 $this->line->localtax1_tx = $txlocaltax1;
909 $this->line->localtax2_tx = $txlocaltax2;
910 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
911 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
912 $this->line->remise_percent = $remise_percent;
913 $this->line->subprice = (float) $pu_ht;
915 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
916 $this->line->info_bits = $info_bits;
917 $this->line->total_ht = (float) $total_ht;
918 $this->line->total_tva = (float) $total_tva;
919 $this->line->total_localtax1 = (float) $total_localtax1;
920 $this->line->total_localtax2 = (float) $total_localtax2;
921 $this->line->total_ttc = (float) $total_ttc;
922 $this->line->special_code = $special_code;
923 $this->line->fk_parent_line = $fk_parent_line;
924 $this->line->skip_update_total = $skip_update_total;
925 $this->line->ref_fourn = $ref_supplier;
926 $this->line->fk_unit = $fk_unit;
929 if (!empty($fk_product) && $fk_product > 0 && empty($fk_fournprice) && empty($pa_ht)) {
931 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
933 $productFournisseur->find_min_price_product_fournisseur($fk_product);
934 $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
936 $this->line->fk_fournprice = $fk_fournprice;
938 $this->line->pa_ht = $pa_ht;
940 if (is_array($array_options) && count($array_options) > 0) {
942 foreach ($array_options as $key => $value) {
943 $this->line->array_options[$key] = $array_options[$key];
948 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
949 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
950 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
951 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
953 $result = $this->line->update();
956 if (!empty($fk_parent_line)) {
965 $this->error = $this->db->error();
966 $this->db->rollback();
970 dol_syslog(get_class($this).
"::updateline Erreur -2 SupplierProposal en mode incompatible pour cette action");
990 $line->fetch($lineid);
992 if ($this->
id > 0 && (
int) $line->fk_supplier_proposal !== (
int) $this->id) {
993 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
997 if ($line->delete($user) > 0) {
1018 public function create($user, $notrigger = 0)
1030 $this->error =
"Failed to fetch company";
1031 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1034 if (!empty($this->
ref)) {
1037 $this->error =
'ErrorRefAlreadyExists';
1038 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1039 $this->db->rollback();
1045 $delivery_date = $this->delivery_date;
1048 if (!empty($this->multicurrency_code)) {
1051 if (empty($this->fk_multicurrency)) {
1053 $this->fk_multicurrency = 0;
1054 $this->multicurrency_tx = 1;
1060 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"supplier_proposal (";
1063 $sql .=
", total_tva";
1064 $sql .=
", total_ttc";
1067 $sql .=
", fk_user_author";
1068 $sql .=
", note_private";
1069 $sql .=
", note_public";
1070 $sql .=
", model_pdf";
1071 $sql .=
", fk_cond_reglement";
1072 $sql .=
", deposit_percent";
1073 $sql .=
", fk_mode_reglement";
1074 $sql .=
", fk_account";
1075 $sql .=
", date_livraison";
1076 $sql .=
", fk_shipping_method";
1077 $sql .=
", fk_projet";
1079 $sql .=
", fk_multicurrency";
1080 $sql .=
", multicurrency_code";
1081 $sql .=
", multicurrency_tx";
1083 $sql .=
" VALUES (";
1084 $sql .= ((int) $this->socid);
1088 $sql .=
", '".$this->db->idate($now).
"'";
1089 $sql .=
", '(PROV)'";
1090 $sql .=
", ".($user->id > 0 ? ((int) $user->id) :
"null");
1091 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1092 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1093 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1094 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'NULL');
1095 $sql .=
", ".(!empty($this->deposit_percent) ?
"'" . $this->db->escape($this->deposit_percent) .
"'" :
'NULL');
1096 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'NULL');
1097 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1098 $sql .=
", ".(isDolTms($delivery_date) ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1099 $sql .=
", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
'NULL');
1100 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1101 $sql .=
", ".((int)
$conf->entity);
1102 $sql .=
", ".((int) $this->fk_multicurrency);
1103 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1104 $sql .=
", ".((float) $this->multicurrency_tx);
1107 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1108 $resql = $this->db->query($sql);
1110 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"supplier_proposal");
1113 $this->
ref =
'(PROV'.$this->id.
')';
1114 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"supplier_proposal SET ref='".$this->db->escape($this->
ref).
"' WHERE rowid=".((int) $this->
id);
1116 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1117 $resql = $this->db->query($sql);
1122 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1123 $this->linked_objects = $this->linkedObjectsIds;
1127 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1128 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1129 if (is_array($tmp_origin_id)) {
1130 foreach ($tmp_origin_id as $origin_id) {
1133 dol_print_error($this->db);
1145 $fk_parent_line = 0;
1146 $num = count($this->lines);
1148 for ($i = 0; $i < $num; $i++) {
1149 if (!is_object($this->lines[$i])) {
1153 foreach ($this->lines[$i] as $key => $val) {
1154 $lineobj->$key = $val;
1156 $this->lines[$i] = $lineobj;
1160 if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
1161 $fk_parent_line = 0;
1165 $line_price_base_type = $this->lines[$i]->getPriceBaseType();
1167 $this->lines[$i]->desc,
1168 (
float) $this->lines[$i]->subprice,
1169 $this->lines[$i]->qty,
1170 $this->lines[$i]->tva_tx,
1171 $this->lines[$i]->localtax1_tx,
1172 $this->lines[$i]->localtax2_tx,
1173 $this->lines[$i]->fk_product,
1174 $this->lines[$i]->remise_percent,
1175 $line_price_base_type,
1176 (
float) $this->lines[$i]->subprice_ttc,
1178 $this->lines[$i]->product_type,
1179 $this->lines[$i]->rang,
1180 $this->lines[$i]->special_code,
1182 $this->lines[$i]->fk_fournprice,
1183 $this->lines[$i]->pa_ht,
1184 empty($this->lines[$i]->label) ?
'' : $this->lines[$i]->label,
1185 $this->lines[$i]->array_options,
1186 $this->lines[$i]->ref_fourn,
1187 $this->lines[$i]->fk_unit,
1188 'supplier_proposal',
1189 $this->lines[$i]->rowid
1194 $this->error = $this->db->error;
1195 dol_print_error($this->db);
1199 if ($result > 0 && $this->lines[$i]->product_type == 9) {
1200 $fk_parent_line = $result;
1219 if (!$error && !$notrigger) {
1221 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_CREATE', $user);
1228 $this->error = $this->db->lasterror();
1233 $this->error = $this->db->lasterror();
1238 $this->db->commit();
1239 dol_syslog(get_class($this).
"::create done id=".$this->
id);
1242 $this->db->rollback();
1246 $this->error = $this->db->lasterror();
1247 $this->db->rollback();
1261 global $hookmanager;
1269 foreach ($this->lines as $line) {
1270 $line->fetch_optionals();
1274 $objFrom = clone $this;
1276 $objsoc =
new Societe($this->db);
1279 if (!empty($fromid) && $fromid != $this->socid) {
1280 if ($objsoc->fetch($fromid) > 0) {
1281 $this->socid = $objsoc->id;
1282 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1283 $this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent : 0);
1284 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1285 unset($this->fk_project);
1290 $objsoc->fetch($this->socid);
1297 if (!
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON') || !is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/supplier_proposal/" .
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON').
".php")) {
1298 $this->error =
'ErrorSetupNotComplete';
1303 $this->user_author_id = $user->id;
1304 $this->user_validation_id = 0;
1308 require_once DOL_DOCUMENT_ROOT.
"/core/modules/supplier_proposal/" .
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON').
'.php';
1310 $modSupplierProposal =
new $obj();
1311 '@phan-var-force ModeleNumRefSupplierProposal $modSupplierProposal';
1312 $this->
ref = $modSupplierProposal->getNextValue($objsoc, $this);
1315 $this->context[
'createfromclone'] =
'createfromclone';
1316 $result = $this->
create($user);
1323 if (is_object($hookmanager)) {
1324 $parameters = array(
'objFrom' => $objFrom);
1326 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1334 unset($this->context[
'createfromclone']);
1338 $this->db->commit();
1341 $this->db->rollback();
1353 public function fetch($rowid, $ref =
'')
1355 $sql =
"SELECT p.rowid, p.entity, p.ref, p.fk_soc as socid";
1356 $sql .=
", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht";
1357 $sql .=
", p.datec, GREATEST(p.tms, pef.tms) as date_modification";
1358 $sql .=
", p.date_valid as datev";
1359 $sql .=
", p.date_livraison as delivery_date";
1360 $sql .=
", p.model_pdf, p.extraparams";
1361 $sql .=
", p.note_private, p.note_public";
1362 $sql .=
", p.fk_projet as fk_project, p.fk_statut as status";
1363 $sql .=
", p.fk_user_author, p.fk_user_modif, p.fk_user_valid, p.fk_user_cloture";
1364 $sql .=
", p.fk_cond_reglement";
1365 $sql .=
", p.fk_mode_reglement";
1366 $sql .=
', p.fk_account';
1367 $sql .=
", p.fk_shipping_method";
1368 $sql .=
", p.last_main_doc";
1369 $sql .=
", p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc";
1370 $sql .=
", c.label as statut_label";
1371 $sql .=
", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
1372 $sql .=
", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
1373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_propalst as c, ".MAIN_DB_PREFIX.
"supplier_proposal as p";
1374 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"supplier_proposal_extrafields as pef ON pef.fk_object=p.rowid";
1375 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as cp ON p.fk_mode_reglement = cp.id';
1376 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as cr ON p.fk_cond_reglement = cr.rowid';
1377 $sql .=
" WHERE p.fk_statut = c.id";
1378 $sql .=
" AND p.entity IN (".getEntity(
'supplier_proposal').
")";
1380 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
1382 $sql .=
" AND p.rowid = ".((int) $rowid);
1385 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
1386 $resql = $this->db->query($sql);
1388 if ($this->db->num_rows($resql)) {
1389 $obj = $this->db->fetch_object($resql);
1391 $this->
id = $obj->rowid;
1392 $this->entity = $obj->entity;
1394 $this->
ref = $obj->ref;
1395 $this->total_ht = $obj->total_ht;
1396 $this->total_tva = $obj->total_tva;
1397 $this->total_localtax1 = $obj->localtax1;
1398 $this->total_localtax2 = $obj->localtax2;
1399 $this->total_ttc = $obj->total_ttc;
1400 $this->socid = $obj->socid;
1401 $this->fk_project = $obj->fk_project;
1402 $this->model_pdf = $obj->model_pdf;
1403 $this->note = $obj->note_private;
1404 $this->note_private = $obj->note_private;
1405 $this->note_public = $obj->note_public;
1406 $this->statut = (int) $obj->status;
1407 $this->
status = (int) $obj->status;
1408 $this->datec = $this->db->jdate($obj->datec);
1409 $this->datev = $this->db->jdate($obj->datev);
1410 $this->date_creation = $this->db->jdate($obj->datec);
1411 $this->date_modification = $this->db->jdate($obj->date_modification);
1412 $this->
date = $this->date_creation;
1413 $this->date_validation = $this->db->jdate($obj->datev);
1414 $this->delivery_date = $this->db->jdate($obj->delivery_date);
1415 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
1417 $this->last_main_doc = $obj->last_main_doc;
1418 $this->mode_reglement_id = $obj->fk_mode_reglement;
1419 $this->mode_reglement_code = $obj->mode_reglement_code;
1420 $this->mode_reglement = $obj->mode_reglement;
1421 $this->deposit_percent = $obj->deposit_percent;
1422 $this->fk_account = ($obj->fk_account > 0) ? $obj->fk_account :
null;
1423 $this->cond_reglement_id = $obj->fk_cond_reglement;
1424 $this->cond_reglement_code = $obj->cond_reglement_code;
1425 $this->cond_reglement = $obj->cond_reglement;
1426 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
1428 $this->extraparams = (array) (!empty($obj->extraparams) ? json_decode($obj->extraparams,
true) : array());
1430 $this->user_author_id = $obj->fk_user_author;
1431 $this->user_modification_id = $obj->fk_user_modif;
1432 $this->user_validation_id = $obj->fk_user_valid;
1433 $this->user_closing_id = $obj->fk_user_cloture;
1436 $this->fk_multicurrency = $obj->fk_multicurrency;
1437 $this->multicurrency_code = $obj->multicurrency_code;
1438 $this->multicurrency_tx = $obj->multicurrency_tx;
1439 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
1440 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
1441 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
1443 $this->db->free($resql);
1449 $this->lines = array();
1452 $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,";
1453 $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,";
1454 $sql .=
' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
1455 $sql .=
' d.ref_fourn as ref_produit_fourn, d.extraparams,';
1456 $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';
1457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"supplier_proposaldet as d";
1458 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON d.fk_product = p.rowid";
1459 $sql .=
" WHERE d.fk_supplier_proposal = ".((int) $this->
id);
1460 $sql .=
" ORDER by d.rang";
1462 $result = $this->db->query($sql);
1464 $num = $this->db->num_rows($result);
1468 $objp = $this->db->fetch_object($result);
1472 $line->rowid = $objp->rowid;
1473 $line->id = $objp->rowid;
1474 $line->fk_supplier_proposal = $objp->fk_supplier_proposal;
1475 $line->fk_parent_line = $objp->fk_parent_line;
1476 $line->product_type = $objp->product_type;
1477 $line->label = $objp->custom_label;
1478 $line->desc = $objp->description;
1479 $line->qty = $objp->qty;
1480 $line->tva_tx = $objp->tva_tx;
1481 $line->localtax1_tx = $objp->localtax1_tx;
1482 $line->localtax2_tx = $objp->localtax2_tx;
1483 $line->subprice = $objp->subprice;
1484 $line->subprice_ttc = $objp->subprice_ttc;
1485 $line->fk_remise_except = $objp->fk_remise_except;
1486 $line->remise_percent = $objp->remise_percent;
1488 $line->info_bits = $objp->info_bits;
1489 $line->total_ht = $objp->total_ht;
1490 $line->total_tva = $objp->total_tva;
1491 $line->total_localtax1 = $objp->total_localtax1;
1492 $line->total_localtax2 = $objp->total_localtax2;
1493 $line->total_ttc = $objp->total_ttc;
1494 $line->fk_fournprice = $objp->fk_fournprice;
1495 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
1496 $line->pa_ht = $marginInfos[0];
1497 $line->marge_tx = $marginInfos[1];
1498 $line->marque_tx = $marginInfos[2];
1499 $line->special_code = $objp->special_code;
1500 $line->rang = $objp->rang;
1502 $line->fk_product = $objp->fk_product;
1504 $line->ref = $objp->product_ref;
1505 $line->product_ref = $objp->product_ref;
1506 $line->libelle = $objp->product_label;
1507 $line->product_label = $objp->product_label;
1508 $line->product_desc = $objp->product_desc;
1509 $line->fk_product_type = $objp->fk_product_type;
1511 $line->ref_fourn = $objp->ref_produit_fourn;
1513 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
1516 $line->fk_multicurrency = $objp->fk_multicurrency;
1517 $line->multicurrency_code = $objp->multicurrency_code;
1518 $line->multicurrency_subprice = $objp->multicurrency_subprice;
1519 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
1520 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
1521 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
1522 $line->fk_unit = $objp->fk_unit;
1524 $line->fetch_optionals();
1526 $this->lines[$i] = $line;
1530 $this->db->free($result);
1532 $this->error = $this->db->error();
1539 $this->error =
"Record Not Found";
1542 $this->error = $this->db->error();
1554 public function valid($user, $notrigger = 0)
1556 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1563 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'supplier_proposal',
'creer'))
1564 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'supplier_proposal',
'validate_advance'))) {
1568 $soc =
new Societe($this->db);
1569 $result = $soc->fetch($this->socid);
1575 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
1579 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1580 $num = $this->getNextNumRef($soc);
1582 $num = (string) $this->
ref;
1586 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal";
1587 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
1588 $sql .=
" fk_statut = 1, date_valid='".$this->db->idate($now).
"', fk_user_valid=".((int) $user->id);
1589 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
1591 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
1592 $resql = $this->db->query($sql);
1594 dol_print_error($this->db);
1599 if (!$error && !$notrigger) {
1601 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_VALIDATE', $user);
1609 $this->oldref = $this->ref;
1612 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
1614 $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).
"'";
1615 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'supplier_proposal/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1616 $resql = $this->db->query($sql);
1619 $this->error = $this->db->lasterror();
1621 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'supplier_proposal/".$this->db->escape($this->newref).
"'";
1622 $sql .=
" WHERE filepath = 'supplier_proposal/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
1623 $resql = $this->db->query($sql);
1626 $this->error = $this->db->lasterror();
1632 $dirsource =
$conf->supplier_proposal->dir_output.
'/'.$oldref;
1633 $dirdest =
$conf->supplier_proposal->dir_output.
'/'.$newref;
1634 if (!$error && file_exists($dirsource)) {
1635 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
1636 if (@rename($dirsource, $dirdest)) {
1639 $listoffiles =
dol_dir_list(
$conf->supplier_proposal->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
1640 foreach ($listoffiles as $fileentry) {
1641 $dirsource = $fileentry[
'name'];
1642 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
1643 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
1644 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
1645 @rename($dirsource, $dirdest);
1654 $this->user_validation_id = $user->id;
1655 $this->datev = $now;
1656 $this->date_validation = $now;
1659 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1660 if ($result < 0 && $result != -2) {
1665 $this->db->commit();
1668 $this->db->rollback();
1672 dol_syslog(
"You don't have permission to validate supplier proposal", LOG_WARNING);
1701 if ($user->hasRight(
'supplier_proposal',
'creer')) {
1702 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal ";
1703 $sql .=
" SET date_livraison = ".(isDolTms($delivery_date) ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
1704 $sql .=
" WHERE rowid = ".((int) $this->
id);
1706 if ($this->db->query($sql)) {
1707 $this->delivery_date = $delivery_date;
1710 $this->error = $this->db->error();
1711 dol_syslog(get_class($this).
"::setDeliveryDate Erreur SQL");
1728 public function reopen($user, $status, $note =
'', $notrigger = 0)
1732 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal";
1733 $sql .=
" SET fk_statut = ".((int) $status).
",";
1734 if (!empty($note)) {
1735 $sql .=
" note_private = '".$this->db->escape($note).
"',";
1737 $sql .=
" date_cloture = NULL, fk_user_cloture = NULL";
1738 $sql .=
" WHERE rowid = ".((int) $this->
id);
1742 dol_syslog(get_class($this).
"::reopen", LOG_DEBUG);
1743 $resql = $this->db->query($sql);
1746 $this->errors[] =
"Error ".$this->db->lasterror();
1751 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_REOPEN', $user);
1761 if (!empty($this->errors)) {
1762 foreach ($this->errors as $errmsg) {
1763 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1764 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1767 $this->db->rollback();
1770 $this->statut = $status;
1773 $this->db->commit();
1789 global $langs,
$conf;
1799 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal";
1800 $sql .=
" SET fk_statut = ".((int) $status).
", note_private = '".$this->db->escape($note).
"', date_cloture='".$this->db->idate($now).
"', fk_user_cloture=".((int) $user->id);
1801 $sql .=
" WHERE rowid = ".((int) $this->
id);
1803 $resql = $this->db->query($sql);
1805 $this->statut = $status;
1808 $modelpdf =
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED', (empty($this->model_pdf) ?
'' : $this->model_pdf));
1809 $triggerName =
'PROPOSAL_SUPPLIER_CLOSE_REFUSED';
1812 $triggerName =
'PROPOSAL_SUPPLIER_CLOSE_SIGNED';
1813 $modelpdf =
getDolGlobalString(
'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL', (empty($this->model_pdf) ?
'' : $this->model_pdf));
1820 $triggerName =
'PROPOSAL_SUPPLIER_CLASSIFY_BILLED';
1825 $outputlangs = $langs;
1828 $newlang = (
GETPOST(
'lang_id',
'aZ09') ?
GETPOST(
'lang_id',
'aZ09') : $this->thirdparty->default_lang);
1829 $outputlangs->setDefaultLang($newlang);
1832 $this->
generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1836 $result = $this->call_trigger($triggerName, $user);
1843 $this->db->commit();
1846 $this->db->rollback();
1850 $this->error = $this->db->lasterror();
1851 $this->errors[] = $this->db->lasterror();
1852 $this->db->rollback();
1865 dol_syslog(get_class($this).
"::updateOrCreatePriceFournisseur", LOG_DEBUG);
1867 foreach ($this->lines as $product) {
1868 if ($product->subprice <= 0) {
1873 $multicurrency_tx = 1;
1874 $fk_multicurrency = 0;
1876 if (empty($this->thirdparty)) {
1880 $ref_fourn = $product->ref_fourn;
1881 if (empty($ref_fourn)) {
1882 $ref_fourn = $product->ref_supplier;
1884 if (
isModEnabled(
"multicurrency") && !empty($product->multicurrency_code)) {
1887 $productsupplier->id = $product->fk_product;
1889 $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);
1905 $price =
price2num($product->subprice * $product->qty,
'MU');
1906 $unitPrice =
price2num($product->subprice,
'MU');
1908 $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);
1910 $resql = $this->db->query($sql);
1912 $this->error = $this->db->error();
1913 $this->db->rollback();
1928 $price =
price2num($product->subprice * $product->qty,
'MU');
1930 $unitPrice =
price2num($product->subprice,
'MU');
1934 $sanitized_values = array(
1935 "'".$this->db->idate($now).
"'",
1936 (
int) $product->fk_product,
1937 (
int) $this->thirdparty->id,
1938 "'".$this->db->escape($product->ref_fourn).
"'",
1942 (
float) $product->tva_tx,
1946 if (!empty($product->multicurrency_code)) {
1947 include_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
1949 $multicurrency->fetch(0, $product->multicurrency_code);
1950 if (!empty($multicurrency->id)) {
1951 $sanitized_values[] = (int) $multicurrency->id;
1952 $sanitized_values[] =
"'".$this->db->escape($product->multicurrency_code).
"'";
1953 $sanitized_values[] = (float) $product->multicurrency_subprice;
1954 $sanitized_values[] = (float) $product->multicurrency_total_ht;
1955 $sanitized_values[] = (float) $multicurrency->rate->rate;
1957 for ($i = 0; $i < 5; $i++) {
1958 $sanitized_values[] =
'NULL';
1964 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'product_fournisseur_price ';
1965 $sql .=
'(datec, fk_product, fk_soc, ref_fourn, price, quantity, unitprice, tva_tx, fk_user';
1966 if (
isModEnabled(
"multicurrency") && !empty($product->multicurrency_code)) {
1967 $sql .=
',fk_multicurrency, multicurrency_code, multicurrency_unitprice, multicurrency_price, multicurrency_tx';
1969 $sql .=
') VALUES ('.implode(
',', $sanitized_values).
')';
1971 $resql = $this->db->query($sql);
1973 $this->error = $this->db->error();
1974 $this->db->rollback();
1992 if ($this->
status == self::STATUS_DRAFT) {
1993 dol_syslog(get_class($this).
"::setDraft already draft status", LOG_WARNING);
1997 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposal";
1998 $sql .=
" SET fk_statut = ".self::STATUS_DRAFT;
1999 $sql .=
" WHERE rowid = ".((int) $this->
id);
2001 if ($this->db->query($sql)) {
2003 $this->oldcopy = clone $this;
2008 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_UNVALIDATE', $user);
2017 $this->db->commit();
2020 $this->db->rollback();
2043 public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'p.datec', $sortorder =
'DESC')
2051 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2052 $search_sale = $user->id;
2055 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2056 $sql .=
" p.rowid as supplier_proposalid, p.fk_statut, p.total_ht, p.ref, p.remise, ";
2057 $sql .=
" p.datep as dp, p.fin_validite as datelimite";
2058 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.
"supplier_proposal as p, ".MAIN_DB_PREFIX.
"c_propalst as c";
2059 $sql .=
" WHERE p.entity IN (".getEntity(
'supplier_proposal').
")";
2060 $sql .=
" AND p.fk_soc = s.rowid";
2061 $sql .=
" AND p.fk_statut = c.id";
2063 $sql .=
" AND s.rowid = ".((int) $socid);
2066 $sql .=
" AND p.fk_statut = 0";
2068 if ($notcurrentuser > 0) {
2069 $sql .=
" AND p.fk_user_author <> ".((int) $user->id);
2072 if ($search_sale && $search_sale !=
'-1') {
2073 if ($search_sale == -2) {
2074 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
2075 } elseif ($search_sale > 0) {
2076 $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).
")";
2079 $sql .= $this->db->order($sortfield, $sortorder);
2080 $sql .= $this->db->plimit($limit, $offset);
2082 $result = $this->db->query($sql);
2084 $num = $this->db->num_rows($result);
2088 $obj = $this->db->fetch_object($result);
2090 if ($shortlist == 1) {
2091 $ga[$obj->supplier_proposalid] = $obj->ref;
2092 } elseif ($shortlist == 2) {
2093 $ga[$obj->supplier_proposalid] = $obj->ref.
' ('.$obj->name.
')';
2095 $ga[$i][
'id'] = $obj->supplier_proposalid;
2096 $ga[$i][
'ref'] = $obj->ref;
2097 $ga[$i][
'name'] = $obj->name;
2105 dol_print_error($this->db);
2117 public function delete($user, $notrigger = 0)
2120 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2128 $result = $this->call_trigger(
'PROPOSAL_SUPPLIER_DELETE', $user);
2137 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_proposal";
2138 $sql .=
" WHERE fk_supplier_proposal = ".((int) $this->
id);
2140 $result = $this->db->query($sql);
2143 $this->error = $this->db->lasterror();
2144 $this->errors[] = $this->error;
2149 $sanitized_main = MAIN_DB_PREFIX.
'supplier_proposaldet';
2150 $sanitized_ef = $sanitized_main.
"_extrafields";
2151 $sqlef =
"DELETE FROM $sanitized_ef WHERE fk_object IN (SELECT rowid FROM $sanitized_main WHERE fk_supplier_proposal = ".((int) $this->
id).
")";
2152 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"supplier_proposaldet WHERE fk_supplier_proposal = ".((int) $this->
id);
2153 if ($this->db->query($sql)) {
2154 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"supplier_proposal WHERE rowid = ".((int) $this->
id);
2155 if ($this->db->query($sqlef) && $this->db->query($sql)) {
2169 if ($conf->supplier_proposal->dir_output && !empty($this->
ref)) {
2170 $dir =
$conf->supplier_proposal->dir_output.
"/".$ref;
2171 $file = $dir.
"/".$ref.
".pdf";
2172 if (file_exists($file)) {
2176 $this->error =
'ErrorFailToDeleteFile';
2177 $this->errors = array(
'ErrorFailToDeleteFile');
2178 $this->db->rollback();
2182 if (file_exists($dir)) {
2185 $this->error =
'ErrorFailToDeleteDir';
2186 $this->errors = array(
'ErrorFailToDeleteDir');
2187 $this->db->rollback();
2200 dol_syslog(get_class($this).
"::delete erreur ".$errorflag.
" ".$this->error, LOG_ERR);
2205 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
2206 $this->db->commit();
2209 $this->error = $this->db->lasterror();
2210 $this->db->rollback();
2214 $this->error = $this->db->lasterror();
2215 $this->db->rollback();
2219 $this->error = $this->db->lasterror();
2220 $this->db->rollback();
2224 $this->db->rollback();
2237 $sql =
"SELECT c.rowid, GREATEST(c.tms, cef.tms) as date_modification,";
2238 $sql .=
" c.datec as date_creation, c.date_valid as date_validation, c.date_cloture as date_closure,";
2239 $sql .=
" c.fk_user_author, c.fk_user_modif, c.fk_user_valid, c.fk_user_cloture";
2240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"supplier_proposal as c";
2241 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"supplier_proposal_extrafields as cef ON cef.fk_object=c.rowid";
2242 $sql .=
" WHERE c.rowid = ".((int) $id);
2244 $result = $this->db->query($sql);
2247 if ($this->db->num_rows($result)) {
2248 $obj = $this->db->fetch_object($result);
2250 $this->
id = $obj->rowid;
2252 $this->date_creation = $this->db->jdate($obj->date_creation);
2253 $this->date_modification = empty($obj->date_modification) ?
'' : $this->db->jdate($obj->date_modification);
2254 $this->date_validation = $this->db->jdate($obj->date_validation);
2255 $this->date_cloture = $this->db->jdate($obj->date_closure);
2257 $this->user_creation_id = $obj->fk_user_author;
2258 $this->user_modification_id = $obj->fk_user_modif;
2259 $this->user_validation_id = $obj->fk_user_valid;
2260 $this->user_closing_id = $obj->fk_user_cloture;
2262 $this->db->free($result);
2264 dol_print_error($this->db);
2293 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2295 $langs->load(
"supplier_proposal");
2296 $this->labelStatus[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusDraft");
2297 $this->labelStatus[
self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusValidated");
2298 $this->labelStatus[
self::STATUS_SIGNED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusSigned");
2299 $this->labelStatus[
self::STATUS_NOTSIGNED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusNotSigned");
2300 $this->labelStatus[
self::STATUS_CLOSE] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusClosed");
2301 $this->labelStatusShort[
self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusDraftShort");
2302 $this->labelStatusShort[
self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusValidatedShort");
2303 $this->labelStatusShort[
self::STATUS_SIGNED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusSignedShort");
2304 $this->labelStatusShort[
self::STATUS_NOTSIGNED] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusNotSignedShort");
2305 $this->labelStatusShort[
self::STATUS_CLOSE] = $langs->transnoentitiesnoconv(
"SupplierProposalStatusClosedShort");
2309 if ($status == self::STATUS_DRAFT) {
2310 $statusnew =
'status0';
2311 } elseif ($status == self::STATUS_VALIDATED) {
2312 $statusnew =
'status1';
2313 } elseif ($status == self::STATUS_SIGNED) {
2314 $statusnew =
'status4';
2315 } elseif ($status == self::STATUS_NOTSIGNED) {
2316 $statusnew =
'status9';
2317 } elseif ($status == self::STATUS_CLOSE) {
2318 $statusnew =
'status6';
2321 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusnew, $mode);
2336 global
$conf, $langs;
2343 if ($mode ==
'opened') {
2344 $delay_warning = !empty(
$conf->supplier_proposal->cloture->warning_delay) ?
$conf->supplier_proposal->cloture->warning_delay : 0;
2346 if ($mode ==
'signed') {
2347 $delay_warning = !empty(
$conf->supplier_proposal->facturation->warning_delay) ?
$conf->supplier_proposal->facturation->warning_delay : 0;
2353 $sql =
"SELECT COUNT(p.rowid) as nb,";
2354 if ($mode ==
'opened') {
2355 $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";
2357 $sql .=
" 0 as nblate";
2359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"supplier_proposal as p";
2360 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2361 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2362 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2365 $sql .= $clause.
" p.entity IN (".
getEntity(
'supplier_proposal').
")";
2366 if ($mode ==
'opened') {
2367 $sql .=
" AND p.fk_statut = 1";
2369 if ($mode ==
'signed') {
2370 $sql .=
" AND p.fk_statut = 2";
2373 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2376 $resql = $this->db->query($sql);
2378 $label = $labelShort =
'';
2380 if ($mode ==
'opened') {
2382 $label = $langs->trans(
"SupplierProposalsToClose");
2383 $labelShort = $langs->trans(
"ToAcceptRefuse");
2385 if ($mode ==
'signed') {
2387 $label = $langs->trans(
"SupplierProposalsToProcess");
2388 $labelShort = $langs->trans(
"ToClose");
2392 $response->warning_delay = $delay_warning / 60 / 60 / 24;
2393 $response->label = $label;
2394 $response->labelShort = $labelShort;
2395 $response->url = DOL_URL_ROOT.
'/supplier_proposal/list.php?search_status='.$status;
2396 $response->img = img_object(
'',
"propal");
2400 $obj = $this->db->fetch_object($resql);
2402 $response->nbtodo = (int) $obj->nb;
2403 $response->nbtodolate = (int) $obj->nblate;
2407 $this->error = $this->db->lasterror();
2423 global
$conf, $langs;
2428 $sql =
"SELECT rowid";
2429 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
2430 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
2431 if (array_key_exists(
'tobuy', $param)) {
2432 $sql .=
" AND tobuy = ".((int) $param[
'tobuy']);
2434 $sql .= $this->db->plimit(100);
2436 $resql = $this->db->query($sql);
2438 $num_prods = $this->db->num_rows($resql);
2440 while ($i < $num_prods) {
2442 $row = $this->db->fetch_row($resql);
2443 $prodids[$i] = $row[0];
2449 $this->
ref =
'SPECIMEN';
2450 $this->ref_supplier =
'NEMICEPS';
2451 $this->specimen = 1;
2454 $this->cond_reglement_id = 1;
2455 $this->cond_reglement_code =
'RECEP';
2456 $this->mode_reglement_id = 7;
2457 $this->mode_reglement_code =
'CHQ';
2458 $this->note_public =
'This is a comment (public)';
2459 $this->note_private =
'This is a comment (private)';
2461 $this->multicurrency_tx = 1;
2467 while ($xnbp < $nbp) {
2469 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
2471 $line->subprice = 100;
2472 $line->tva_tx = 19.6;
2473 $line->localtax1_tx = 0;
2474 $line->localtax2_tx = 0;
2476 $line->total_ht = 50;
2477 $line->total_ttc = 59.8;
2478 $line->total_tva = 9.8;
2479 $line->remise_percent = 50;
2481 $line->total_ht = 100;
2482 $line->total_ttc = 119.6;
2483 $line->total_tva = 19.6;
2484 $line->remise_percent = 00;
2487 if ($num_prods > 0) {
2488 $prodid = mt_rand(1, $num_prods);
2489 $line->fk_product = $prodids[$prodid];
2492 $this->lines[$xnbp] = $line;
2494 $this->total_ht += $line->total_ht;
2495 $this->total_tva += $line->total_tva;
2496 $this->total_ttc += $line->total_ttc;
2513 $this->nb = array();
2516 $sql =
"SELECT count(p.rowid) as nb";
2517 $sql .=
" FROM ".MAIN_DB_PREFIX.
"supplier_proposal as p";
2518 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2519 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2520 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2521 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2524 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'supplier_proposal').
")";
2526 $resql = $this->db->query($sql);
2529 while ($obj = $this->db->fetch_object($resql)) {
2530 $this->nb[
"supplier_proposals"] = $obj->nb;
2532 $this->db->free($resql);
2535 dol_print_error($this->db);
2536 $this->error = $this->db->lasterror();
2549 public function getNextNumRef($soc)
2551 global
$conf, $db, $langs;
2552 $langs->load(
"supplier_proposal");
2561 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2562 foreach ($dirmodels as $reldir) {
2563 $dir =
dol_buildpath($reldir.
"core/modules/supplier_proposal/");
2566 $mybool = ((bool) @include_once $dir.$file) || $mybool;
2570 dol_print_error(
null,
"Failed to include file ".$file);
2574 $obj =
new $classname();
2575 '@phan-var-force ModeleNumRefSupplierProposal $obj';
2578 $numref = $obj->getNextValue($soc, $this);
2580 if ($numref !=
"") {
2583 $this->error = $obj->error;
2587 $langs->load(
"errors");
2588 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"SupplierProposal"));
2601 global
$conf, $langs;
2603 $langs->load(
'supplier_proposal');
2606 return [
'optimize' => $langs->trans(
"ShowSupplierProposal")];
2612 $datas[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"SupplierProposal").
'</u>';
2613 if (isset($this->
status)) {
2614 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
2616 if (!empty($this->
ref)) {
2617 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
2619 if (!empty($this->ref_fourn)) {
2620 $datas[
'ref_supplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_fourn;
2622 if (empty($params[
'nofetch'])) {
2623 $langs->load(
'companies');
2624 if (empty($this->thirdparty)) {
2627 if (is_object($this->thirdparty)) {
2628 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
2631 if (!empty($this->total_ht)) {
2632 $datas[
'amount_ht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
getDolCurrency());
2634 if (!empty($this->total_tva)) {
2635 $datas[
'amount_vat'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
getDolCurrency());
2637 if (!empty($this->total_ttc)) {
2638 $datas[
'amount_ttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
getDolCurrency());
2655 public function getNomUrl($withpicto = 0, $option =
'', $get_params =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
2657 global $langs,
$conf, $user, $hookmanager;
2659 if (!empty(
$conf->dol_no_mouse_hover)) {
2667 'objecttype' => $this->element,
2668 'option' => $option,
2670 $classfortooltip =
'classfortooltip';
2673 $classfortooltip =
'classforajaxtooltip';
2674 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2680 if ($option ==
'') {
2681 $url = DOL_URL_ROOT.
'/supplier_proposal/card.php?id='.$this->
id.$get_params;
2683 if ($option ==
'document') {
2684 $url = DOL_URL_ROOT.
'/supplier_proposal/document.php?id='.$this->
id.$get_params;
2687 if ($option !==
'nolink') {
2689 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2690 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2691 $add_save_lastsearch_values = 1;
2693 if ($add_save_lastsearch_values) {
2694 $url .=
'&save_lastsearch_values=1';
2699 if (empty($notooltip) && $user->hasRight(
'propal',
'lire')) {
2701 $label = $langs->trans(
"ShowSupplierProposal");
2702 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2704 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2705 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
2708 $linkstart =
'<a href="'.$url.
'"';
2709 $linkstart .= $linkclose.
'>';
2712 $result .= $linkstart;
2714 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
2716 if ($withpicto != 2) {
2717 $result .= $this->ref;
2719 $result .= $linkend;
2721 if ($addlinktonotes) {
2722 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
2725 $result .=
' <span class="note inline-block">';
2726 $result .=
'<a href="'.DOL_URL_ROOT.
'/supplier_proposal/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
2727 $result .= img_picto(
'',
'note');
2731 $result .=
'</span>';
2735 $hookmanager->initHooks(array($this->element .
'dao'));
2736 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2737 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2739 $result = $hookmanager->resPrint;
2741 $result .= $hookmanager->resPrint;
2755 $sql =
'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,';
2756 $sql .=
' pt.qty, pt.tva_tx, pt.vat_src_code, pt.remise_percent, pt.subprice, pt.info_bits,';
2757 $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,';
2758 $sql .=
' pt.product_type, pt.rang, pt.fk_parent_line, pt.extraparams,';
2759 $sql .=
' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
2760 $sql .=
' p.description as product_desc, pt.ref_fourn as ref_supplier,';
2761 $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';
2762 $sql .=
' FROM '.MAIN_DB_PREFIX.
'supplier_proposaldet as pt';
2763 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON pt.fk_product=p.rowid';
2764 $sql .=
' WHERE pt.fk_supplier_proposal = '.((int) $this->
id);
2765 $sql .=
' ORDER BY pt.rang ASC, pt.rowid';
2767 dol_syslog(get_class($this).
'::getLinesArray', LOG_DEBUG);
2768 $resql = $this->db->query($sql);
2770 $num = $this->db->num_rows($resql);
2774 $obj = $this->db->fetch_object($resql);
2777 $this->lines[$i]->id = $obj->rowid;
2778 $this->lines[$i]->rowid = $obj->rowid;
2780 $this->lines[$i]->label = $obj->custom_label;
2781 $this->lines[$i]->description = $obj->description;
2782 $this->lines[$i]->desc = $obj->description;
2784 $this->lines[$i]->fk_product = $obj->fk_product;
2785 $this->lines[$i]->ref = $obj->ref;
2786 $this->lines[$i]->product_label = $obj->product_label;
2787 $this->lines[$i]->product_desc = $obj->product_desc;
2788 $this->lines[$i]->fk_product_type = $obj->fk_product_type;
2789 $this->lines[$i]->product_type = $obj->product_type;
2790 $this->lines[$i]->qty = $obj->qty;
2791 $this->lines[$i]->subprice = $obj->subprice;
2792 $this->lines[$i]->fk_remise_except = $obj->fk_remise_except;
2793 $this->lines[$i]->remise_percent = $obj->remise_percent;
2794 $this->lines[$i]->tva_tx = $obj->tva_tx;
2795 $this->lines[$i]->vat_src_code = $obj->vat_src_code;
2796 $this->lines[$i]->info_bits = $obj->info_bits;
2797 $this->lines[$i]->total_ht = $obj->total_ht;
2798 $this->lines[$i]->total_tva = $obj->total_tva;
2799 $this->lines[$i]->total_ttc = $obj->total_ttc;
2800 $this->lines[$i]->fk_fournprice = $obj->fk_fournprice;
2801 $marginInfos =
getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->lines[$i]->fk_fournprice, $obj->pa_ht);
2802 $this->lines[$i]->pa_ht = $marginInfos[0];
2803 $this->lines[$i]->marge_tx = $marginInfos[1];
2804 $this->lines[$i]->marque_tx = $marginInfos[2];
2805 $this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
2806 $this->lines[$i]->special_code = $obj->special_code;
2807 $this->lines[$i]->rang = $obj->rang;
2809 $this->lines[$i]->ref_fourn = $obj->ref_supplier;
2810 $this->lines[$i]->ref_supplier = $obj->ref_supplier;
2813 $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency;
2814 $this->lines[$i]->multicurrency_code = $obj->multicurrency_code;
2815 $this->lines[$i]->multicurrency_subprice = $obj->multicurrency_subprice;
2816 $this->lines[$i]->multicurrency_total_ht = $obj->multicurrency_total_ht;
2817 $this->lines[$i]->multicurrency_total_tva = $obj->multicurrency_total_tva;
2818 $this->lines[$i]->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2819 $this->lines[$i]->fk_unit = $obj->fk_unit;
2820 $this->lines[$i]->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
2822 $this->lines[$i]->fetch_optionals();
2826 $this->db->free($resql);
2830 $this->error = $this->db->error();
2846 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2850 $langs->load(
"supplier_proposal");
2851 $outputlangs->load(
"products");
2856 if ($this->model_pdf) {
2857 $modele = $this->model_pdf;
2863 if (empty($modele)) {
2867 $modelpath =
"core/modules/supplier_proposal/doc/";
2869 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2901 'supplier_proposaldet'
2919 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2921 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2922 $return .=
'<div class="info-box info-box-sm">';
2923 $return .=
'<span class="info-box-icon bg-infobox-action">';
2924 $return .= img_picto(
'', $this->picto);
2926 $return .=
'</span>';
2927 $return .=
'<div class="info-box-content">';
2928 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2929 if ($selected >= 0) {
2930 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2932 if (property_exists($this,
'socid')) {
2933 $return .=
'<span class="info-box-ref"> | '.$this->socid.
'</span>';
2935 if (property_exists($this,
'delivery_date')) {
2936 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->delivery_date).
'</span>';
2938 if (property_exists($this,
'total_ttc')) {
2939 $return .=
'<br><span class="opacitymedium" >'.$langs->trans(
"AmountHT").
' : </span><span class="info-box-label amount">'.
price($this->total_ttc).
'</span>';
2941 if (method_exists($this,
'getLibStatut')) {
2942 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
2944 $return .=
'</div>';
2945 $return .=
'</div>';
2946 $return .=
'</div>';
2962 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2963 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_PROPOSAL);
2986 public $element =
'supplier_proposaldet';
2991 public $table_element =
'supplier_proposaldet';
3016 public $fk_supplier_proposal;
3021 public $fk_parent_line;
3038 public $fk_product_type;
3057 public $vat_src_code;
3062 public $remise_percent;
3067 public $fk_remise_except;
3077 public $fk_fournprice;
3095 public $special_code;
3103 public $info_bits = 0;
3141 public $product_ref;
3154 public $product_label;
3166 public $product_desc;
3171 public $localtax1_tx;
3175 public $localtax2_tx;
3179 public $localtax1_type;
3183 public $localtax2_type;
3187 public $total_localtax1;
3191 public $total_localtax2;
3196 public $skip_update_total;
3205 public $ref_supplier;
3211 public $fk_multicurrency;
3216 public $multicurrency_code;
3220 public $multicurrency_subprice;
3224 public $multicurrency_total_ht;
3228 public $multicurrency_total_tva;
3232 public $multicurrency_total_ttc;
3252 $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,';
3253 $sql .=
' pd.date_start, pd.date_end,';
3254 $sql .=
' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice, pd.subprice_ttc,';
3255 $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,';
3256 $sql .=
' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
3257 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3258 $sql .=
' pd.product_type, pd.ref_fourn as ref_produit_fourn, pd.extraparams,';
3259 $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';
3260 $sql .=
' FROM '.MAIN_DB_PREFIX.
'supplier_proposaldet as pd';
3261 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON pd.fk_product = p.rowid';
3262 $sql .=
' WHERE pd.rowid = '.((int) $rowid);
3264 $result = $this->db->query($sql);
3266 if ($objp = $this->db->fetch_object($result)) {
3267 $this->
id = $objp->rowid;
3268 $this->fk_supplier_proposal = $objp->fk_supplier_proposal;
3269 $this->fk_parent_line = $objp->fk_parent_line;
3270 $this->label = $objp->custom_label;
3271 $this->desc = $objp->description;
3272 $this->qty = $objp->qty;
3274 $this->subprice = $objp->subprice;
3275 $this->subprice_ttc = $objp->subprice_ttc;
3277 $this->tva_tx = $objp->tva_tx;
3278 $this->remise_percent = $objp->remise_percent;
3279 $this->fk_remise_except = $objp->fk_remise_except;
3280 $this->fk_product = $objp->fk_product;
3281 $this->info_bits = $objp->info_bits;
3282 $this->date_start = $this->db->jdate($objp->date_start);
3283 $this->date_end = $this->db->jdate($objp->date_end);
3285 $this->total_ht = $objp->total_ht;
3286 $this->total_tva = $objp->total_tva;
3287 $this->total_ttc = $objp->total_ttc;
3289 $this->fk_fournprice = $objp->fk_fournprice;
3291 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
3292 $this->pa_ht = $marginInfos[0];
3293 $this->marge_tx = $marginInfos[1];
3294 $this->marque_tx = $marginInfos[2];
3296 $this->special_code = $objp->special_code;
3297 $this->product_type = $objp->product_type;
3298 $this->rang = $objp->rang;
3300 $this->product_ref = $objp->product_ref;
3301 $this->product_label = $objp->product_label;
3302 $this->product_desc = $objp->product_desc;
3304 $this->ref_fourn = $objp->ref_produit_fourn;
3306 $this->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
3309 $this->fk_multicurrency = $objp->fk_multicurrency;
3310 $this->multicurrency_code = $objp->multicurrency_code;
3311 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3312 $this->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
3313 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3314 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3315 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3316 $this->fk_unit = $objp->fk_unit;
3318 $this->db->free($result);
3323 dol_print_error($this->db);
3340 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3343 if (empty($this->tva_tx)) {
3346 if (empty($this->vat_src_code)) {
3347 $this->vat_src_code =
'';
3349 if (empty($this->localtax1_tx)) {
3350 $this->localtax1_tx = 0;
3352 if (empty($this->localtax2_tx)) {
3353 $this->localtax2_tx = 0;
3355 if (empty($this->localtax1_type)) {
3356 $this->localtax1_type =
'';
3358 if (empty($this->localtax2_type)) {
3359 $this->localtax2_type =
'';
3361 if (empty($this->total_localtax1)) {
3362 $this->total_localtax1 = 0;
3364 if (empty($this->total_localtax2)) {
3365 $this->total_localtax2 = 0;
3367 if (empty($this->rang)) {
3370 if (empty($this->remise_percent)) {
3371 $this->remise_percent = 0;
3373 if (empty($this->info_bits)) {
3374 $this->info_bits = 0;
3376 if (empty($this->special_code)) {
3377 $this->special_code = 0;
3379 if (empty($this->fk_parent_line)) {
3380 $this->fk_parent_line = 0;
3382 if (empty($this->fk_fournprice)) {
3383 $this->fk_fournprice = 0;
3385 if (empty($this->fk_unit)) {
3388 if (empty($this->subprice)) {
3389 $this->subprice = 0;
3392 if (empty($this->pa_ht)) {
3397 if ($this->pa_ht == 0) {
3398 $result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3402 $this->pa_ht = $result;
3407 if ($this->product_type < 0) {
3414 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'supplier_proposaldet';
3415 $sql .=
' (fk_supplier_proposal, fk_parent_line, label, description, fk_product, product_type,';
3416 $sql .=
' date_start, date_end,';
3417 $sql .=
' fk_remise_except, qty, tva_tx, vat_src_code, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
3418 $sql .=
' subprice, subprice_ttc, remise_percent, ';
3419 $sql .=
' info_bits, ';
3420 $sql .=
' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
3421 $sql .=
' ref_fourn,';
3422 $sql .=
' fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_subprice_ttc, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc, fk_unit)';
3423 $sql .=
" VALUES (".((int) $this->fk_supplier_proposal).
",";
3424 $sql .=
" ".($this->fk_parent_line > 0 ? ((int) $this->fk_parent_line) :
"null").
",";
3425 $sql .=
" ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null").
",";
3426 $sql .=
" '".$this->db->escape($this->desc).
"',";
3427 $sql .=
" ".($this->fk_product ? ((int) $this->fk_product) :
"null").
",";
3428 $sql .=
" ".((int) $this->product_type).
",";
3429 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3430 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3431 $sql .=
" ".($this->fk_remise_except ? ((int) $this->fk_remise_except) :
"null").
",";
3432 $sql .=
" ".(float)
price2num($this->qty,
'MS').
",";
3433 $sql .=
" ".(float)
price2num($this->tva_tx).
",";
3434 $sql .=
" '".$this->db->escape($this->vat_src_code).
"',";
3435 $sql .=
" ".(float)
price2num($this->localtax1_tx).
",";
3436 $sql .=
" ".(float)
price2num($this->localtax2_tx).
",";
3437 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3438 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3439 $sql .=
" ".(float)
price2num($this->subprice,
'MU') .
",";
3440 $sql .=
" ".(float)
price2num($this->subprice_ttc,
'MU') .
",";
3441 $sql .=
" ".((float) $this->remise_percent).
",";
3442 $sql .=
" ".(isset($this->info_bits) ? ((int) $this->info_bits) :
"null").
",";
3443 $sql .=
" ".(float)
price2num($this->total_ht,
'MT').
",";
3444 $sql .=
" ".(float)
price2num($this->total_tva,
'MT').
",";
3445 $sql .=
" ".(float)
price2num($this->total_localtax1,
'MT').
",";
3446 $sql .=
" ".(float)
price2num($this->total_localtax2,
'MT').
",";
3447 $sql .=
" ".(float)
price2num($this->total_ttc,
'MT').
",";
3448 $sql .=
" ".(!empty($this->fk_fournprice) ? ((int) $this->fk_fournprice) :
"null").
",";
3449 $sql .=
" ".(isset($this->pa_ht) ? (float)
price2num($this->pa_ht,
'MU') :
"null").
",";
3450 $sql .=
' '.((int) $this->special_code).
',';
3451 $sql .=
' '.((int) $this->rang).
',';
3452 $sql .=
" '".$this->db->escape($this->ref_fourn).
"'";
3453 $sql .=
", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) :
'null');
3454 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3455 $sql .=
", ".(float)
price2num($this->multicurrency_subprice,
'CU');
3456 $sql .=
", ".(float)
price2num($this->multicurrency_subprice_ttc,
'CU');
3457 $sql .=
", ".(float)
price2num($this->multicurrency_total_ht,
'CT');
3458 $sql .=
", ".(float)
price2num($this->multicurrency_total_tva,
'CT');
3459 $sql .=
", ".(float)
price2num($this->multicurrency_total_ttc,
'CT');
3460 $sql .=
", ".($this->fk_unit ? ((int) $this->fk_unit) :
'null');
3463 dol_syslog(get_class($this).
'::insert', LOG_DEBUG);
3464 $resql = $this->db->query($sql);
3466 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'supplier_proposaldet');
3475 if (!$error && !$notrigger) {
3477 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_INSERT', $user);
3479 $this->db->rollback();
3485 $this->db->commit();
3488 $this->error = $this->db->error().
" sql=".$sql;
3489 $this->db->rollback();
3500 public function delete($user)
3506 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"supplier_proposaldet";
3507 $sql .=
" WHERE rowid = ".((int) $this->
id);
3509 if ($this->db->query($sql)) {
3515 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
3520 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_DELETE', $user);
3522 $this->db->rollback();
3527 $this->db->commit();
3531 $this->error = $this->db->error().
" sql=".$sql;
3532 $this->db->rollback();
3550 if (empty($this->tva_tx)) {
3553 if (empty($this->localtax1_tx)) {
3554 $this->localtax1_tx = 0;
3556 if (empty($this->localtax2_tx)) {
3557 $this->localtax2_tx = 0;
3559 if (empty($this->total_localtax1)) {
3560 $this->total_localtax1 = 0;
3562 if (empty($this->total_localtax2)) {
3563 $this->total_localtax2 = 0;
3565 if (empty($this->localtax1_type)) {
3566 $this->localtax1_type =
'';
3568 if (empty($this->localtax2_type)) {
3569 $this->localtax2_type =
'';
3571 if (empty($this->marque_tx)) {
3572 $this->marque_tx = 0;
3574 if (empty($this->marge_tx)) {
3575 $this->marge_tx = 0;
3577 if (empty($this->remise_percent)) {
3578 $this->remise_percent = 0;
3580 if (empty($this->info_bits)) {
3581 $this->info_bits = 0;
3583 if (empty($this->special_code)) {
3584 $this->special_code = 0;
3586 if (empty($this->fk_parent_line)) {
3587 $this->fk_parent_line = 0;
3589 if (empty($this->fk_fournprice)) {
3590 $this->fk_fournprice = 0;
3592 if (empty($this->fk_unit)) {
3595 if (empty($this->subprice)) {
3596 $this->subprice = 0;
3599 if (empty($this->pa_ht)) {
3604 if ($this->pa_ht == 0) {
3605 $result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product, $this->qty);
3609 $this->pa_ht = $result;
3616 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposaldet SET";
3617 $sql .=
" description = '".$this->db->escape($this->desc).
"'";
3618 $sql .=
" , label = ".(!empty($this->label) ?
"'".$this->db->escape($this->label).
"'" :
"null");
3619 $sql .=
" , product_type = ".((int) $this->product_type);
3620 $sql .=
" , date_start = ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3621 $sql .=
" , date_end = ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3622 $sql .=
" , tva_tx = '".price2num($this->tva_tx).
"'";
3623 $sql .=
" , localtax1_tx = ".(float)
price2num($this->localtax1_tx);
3624 $sql .=
" , localtax2_tx = ".(float)
price2num($this->localtax2_tx);
3625 $sql .=
" , localtax1_type = '".$this->db->escape($this->localtax1_type).
"'";
3626 $sql .=
" , localtax2_type = '".$this->db->escape($this->localtax2_type).
"'";
3627 $sql .=
" , qty = ".(float)
price2num($this->qty);
3628 $sql .=
" , subprice = ".(float)
price2num($this->subprice);
3629 $sql .=
" , subprice_ttc = ".(float)
price2num($this->subprice_ttc);
3630 $sql .=
" , remise_percent = ".(float)
price2num($this->remise_percent);
3631 $sql .=
" , info_bits = ".((int) $this->info_bits);
3632 if (empty($this->skip_update_total)) {
3633 $sql .=
" , total_ht = ".(float)
price2num($this->total_ht);
3634 $sql .=
" , total_tva = ".(float)
price2num($this->total_tva);
3635 $sql .=
" , total_ttc = ".(float)
price2num($this->total_ttc);
3636 $sql .=
" , total_localtax1 = ".(float)
price2num($this->total_localtax1);
3637 $sql .=
" , total_localtax2 = ".(float)
price2num($this->total_localtax2);
3639 $sql .=
" , fk_product_fournisseur_price = ".(!empty($this->fk_fournprice) ?
"'".$this->db->escape((
string) $this->fk_fournprice).
"'" :
"null");
3640 $sql .=
" , buy_price_ht = ".(float)
price2num($this->pa_ht);
3641 $sql .=
" , special_code = ".((int) $this->special_code);
3642 $sql .=
" , fk_parent_line = ".($this->fk_parent_line > 0 ? ((int) $this->fk_parent_line) :
"null");
3643 if (!empty($this->rang)) {
3644 $sql .=
", rang = ".((int) $this->rang);
3646 $sql .=
" , ref_fourn = ".(!empty($this->ref_fourn) ?
"'".$this->db->escape($this->ref_fourn).
"'" :
"null");
3647 $sql .=
" , fk_unit = ".($this->fk_unit ? (int) $this->fk_unit :
'null');
3650 $sql .=
" , multicurrency_subprice = ".(float)
price2num($this->multicurrency_subprice);
3651 $sql .=
" , multicurrency_subprice_ttc = ".(float)
price2num($this->multicurrency_subprice_ttc);
3652 $sql .=
" , multicurrency_total_ht = ".(float)
price2num($this->multicurrency_total_ht);
3653 $sql .=
" , multicurrency_total_tva = ".(float)
price2num($this->multicurrency_total_tva);
3654 $sql .=
" , multicurrency_total_ttc = ".(float)
price2num($this->multicurrency_total_ttc);
3656 $sql .=
" WHERE rowid = ".((int) $this->
id);
3658 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3659 $resql = $this->db->query($sql);
3668 if (!$error && !$notrigger) {
3670 $result = $this->call_trigger(
'LINESUPPLIER_PROPOSAL_MODIFY', $user);
3672 $this->db->rollback();
3678 $this->db->commit();
3681 $this->error = $this->db->error();
3682 $this->db->rollback();
3700 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"supplier_proposaldet SET";
3701 $sql .=
" total_ht = ".(float)
price2num($this->total_ht,
'MT');
3702 $sql .=
",total_tva = ".(float)
price2num($this->total_tva,
'MT');
3703 $sql .=
",total_ttc = ".(float)
price2num($this->total_ttc,
'MT');
3704 $sql .=
" WHERE rowid = ".((int) $this->
id);
3706 dol_syslog(
"SupplierProposalLine::update_total", LOG_DEBUG);
3708 $resql = $this->db->query($sql);
3710 $this->db->commit();
3713 $this->error = $this->db->error();
3714 $this->db->rollback();
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.
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.
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.
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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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