diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 6037f6c77c9..a3cac080ab5 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -448,41 +448,73 @@ jQuery(document).ready(function() {
setforpredef();
jQuery('#trlinefordates').show();
});
+
+ /* Sur changemenr de produit, on recharge la liste des prix fournisseur */
$("#idprod, #idprodfournprice").change(function()
{
setforpredef();
jQuery('#trlinefordates').show();
- rights->margins->creer) { ?>
+ rights->margins->creer)
+ {
+ $langs->load('stocks');
+ ?>
/* Code for margin */
$("#fournprice_predef options").remove();
$("#fournprice_predef").hide();
$("#buying_price").val("").show();
+ /* Call post to load content of combo list fournprice_predef */
$.post('/fourn/ajax/getSupplierPrices.php', { 'idprod': $(this).val() }, function(data) {
if (data && data.length > 0)
{
var options = '';
+ var defaultkey = '';
+ var defaultprice = '';
var i = 0;
$(data).each(function() {
- i++;
- options += '';
+ if (this.id != 'pmpprice')
+ {
+ i++;
+ options += '';
+ }
+ if (this.id == 'pmpprice')
+ {
+ if (this.price > 0 && 1 == 1) { defaultkey = this.id; defaultprice = this.price; }
+ options += '';
+ }
});
- options += '';
- $("#buying_price").hide();
+ options += '';
+
+ /* alert(defaultkey+' '+defaultprice); */
$("#fournprice_predef").html(options).show();
+ $("#fournprice_predef").val(defaultkey);
+
+ /* At loading, no product are yet selected, so we hide field of buying_price */
+ $("#buying_price").hide();
+
+ /* Define default price at loading */
+ var defaultprice = $("#fournprice_predef").find('option:selected').attr("price");
+ $("#buying_price").val(defaultprice);
+
$("#fournprice_predef").change(function() {
- var selval = $(this).find('option:selected').attr("price");
- if (selval)
- $("#buying_price").val(selval).hide();
- else
- $('#buying_price').show();
- });
+ /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
+ var linevalue=$(this).find('option:selected').val();
+ var pricevalue = $(this).find('option:selected').attr("price");
+ if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
+ $("#buying_price").val(pricevalue).hide(); /* We set value then hide field */
+ }
+ if (linevalue == 'inputprice') {
+ $('#buying_price').show();
+ }
+ if (linevalue == 'pmpprice') {
+ $("#buying_price").val(pricevalue);
+ $('#buying_price').hide();
+ }
+ });
}
},
'json');
diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php
index cdff85ccde0..907e34f8d35 100755
--- a/htdocs/fourn/ajax/getSupplierPrices.php
+++ b/htdocs/fourn/ajax/getSupplierPrices.php
@@ -17,7 +17,7 @@
/**
* \file /htdocs/fourn/ajax/getSupplierPrices.php
- * \brief File to return Ajax response on get supplier prices
+ * \brief File to return an Ajax response to get a supplier prices
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
@@ -119,6 +119,11 @@ if (! empty($idprod))
$db->free($result);
}
}
+
+ // Add price for pmp
+ $price=123;
+ $prices[] = array("id" => 'pmpprice', "price" => $price, "label" => $langs->trans("PMPValueShort").': '.price($price,0,$langs,0,0,-1,$conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price,0,$langs,0,0,-1,$conf->currency));
+
}
echo json_encode($prices);