Merge branch 'develop' of github.com:Dolibarr/dolibarr into develop

This commit is contained in:
Laurent Destailleur 2015-01-13 16:16:28 +01:00
commit a324afa3e5
2 changed files with 54 additions and 17 deletions

View File

@ -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();
<?php if (! empty($usemargins) && $user->rights->margins->creer) { ?>
<?php
if (! empty($usemargins) && $user->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('<?php echo DOL_URL_ROOT; ?>/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 += '<option value="'+this.id+'" price="'+this.price+'"';
if (i == 1) {
options += ' selected';
$("#buying_price").val(this.price);
}
options += '>'+this.label+'</option>';
if (this.id != 'pmpprice')
{
i++;
options += '<option value="'+this.id+'" price="'+this.price+'"';
if (this.price > 0 && i == 1) { defaultkey = this.id; defaultprice = this.price; }
options += '>'+this.label+'</option>';
}
if (this.id == 'pmpprice')
{
if (this.price > 0 && 1 == 1) { defaultkey = this.id; defaultprice = this.price; }
options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
}
});
options += '<option value=""><?php echo $langs->trans("InputPrice"); ?></option>';
$("#buying_price").hide();
options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
/* 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');

View File

@ -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);