diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index b68193a207828a5a09e9ff8c9fd5794c7e25d747..9e9eb792a79a427aba9edaf7fd2b457a769fee4b 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -195,6 +195,8 @@ class Product extends CommonObject var $buyprice; public $fourn_pu; + public $fourn_price_base_type; + /** * @deprecated * @see ref_supplier @@ -1314,7 +1316,7 @@ class Product extends CommonObject * This also set some properties on product like ->buyprice, ->fourn_pu, ... * * @param int $prodfournprice Id du tarif = rowid table product_fournisseur_price - * @param double $qty Quantity asked + * @param double $qty Quantity asked or -1 to get first entry found * @param int $product_id Filter on a particular product id * @param string $fourn_ref Filter on a supplier ref. 'none' to exclude ref in search. * @return int <-1 if KO, -1 if qty not enough, 0 if OK but nothing found, id_product if OK and found. May also initialize some properties like (->ref_supplier, buyprice, fourn_pu, vatrate_supplier...) @@ -1337,7 +1339,7 @@ class Product extends CommonObject if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj && $obj->quantity > 0) // If found + if ($obj && $obj->quantity > 0) // If we found a supplier prices from the id of supplier price { if (!empty($conf->dynamicprices->enabled) && !empty($obj->fk_supplier_price_expression)) { @@ -1355,7 +1357,8 @@ class Product extends CommonObject } } $this->buyprice = $obj->price; // deprecated - $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id + $this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product of supplier + $this->fourn_price_base_type = 'HT'; // Price base type $this->ref_fourn = $obj->ref_fourn; // deprecated $this->ref_supplier = $obj->ref_fourn; // Ref supplier $this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier @@ -1397,8 +1400,9 @@ class Product extends CommonObject } } $this->buyprice = $obj->price; // deprecated - $this->fourn_qty = $obj->quantity; // min quantity for price - $this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id + $this->fourn_qty = $obj->quantity; // min quantity for price for a virtual supplier + $this->fourn_pu = $obj->price / $obj->quantity; // Unit price of product for a virtual supplier + $this->fourn_price_base_type = 'HT'; // Price base type for a virtual supplier $this->ref_fourn = $obj->ref_supplier; // deprecated $this->ref_supplier = $obj->ref_supplier; // Ref supplier $this->vatrate_supplier = $obj->tva_tx; // Vat ref supplier diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 4bd141da1a7e97daf3eb27c59525d118d403ee02..ac98de73c4711c53246a9232112d9af2b5b8d5d1 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -596,7 +596,8 @@ if (empty($reshook)) if (preg_match('/^idprod_([0-9]+)$/',GETPOST('idprodfournprice'), $reg)) { $idprod=$reg[1]; - // Call to init properties of $productsupplier + $res=$productsupplier->fetch($idprod); + // Call to init properties of $productsupplier // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price $productsupplier->get_buyprice(0, -1, $idprod, 'none'); // We force qty to -1 to be sure to find if a supplier price exist } @@ -604,37 +605,35 @@ if (empty($reshook)) { //$idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat. $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), -1); // We force qty to -1 to be sure to find if a supplier price exist + $res=$productsupplier->fetch($idprod); } - if ($idprod > 0) { - $res=$productsupplier->fetch($idprod); - + $pu_ht = $productsupplier->fourn_pu; + $price_base_type = $productsupplier->fourn_price_base_type; + $type = $productsupplier->type; $label = $productsupplier->label; - $desc = $productsupplier->description; if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc); - $type = $productsupplier->type; - $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice')); $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice')); if (empty($tva_tx)) $tva_npr=0; $localtax1_tx= get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr); $localtax2_tx= get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr); - + $result=$object->addline( $desc, - $productsupplier->fourn_pu, + $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $productsupplier->id, $remise_percent, - $type, - $productsupplier->price_ttc, + $price_base_type, + $pu_ttc, $tva_npr, $type, -1, @@ -646,6 +645,7 @@ if (empty($reshook)) $array_options, $ref_fourn ); + //var_dump($tva_tx);var_dump($productsupplier->fourn_pu);var_dump($price_base_type);exit; } if ($idprod == -99 || $idprod == 0) {