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(); setforpredef();
jQuery('#trlinefordates').show(); jQuery('#trlinefordates').show();
}); });
/* Sur changemenr de produit, on recharge la liste des prix fournisseur */
$("#idprod, #idprodfournprice").change(function() $("#idprod, #idprodfournprice").change(function()
{ {
setforpredef(); setforpredef();
jQuery('#trlinefordates').show(); 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 */ /* Code for margin */
$("#fournprice_predef options").remove(); $("#fournprice_predef options").remove();
$("#fournprice_predef").hide(); $("#fournprice_predef").hide();
$("#buying_price").val("").show(); $("#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) { $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', { 'idprod': $(this).val() }, function(data) {
if (data && data.length > 0) if (data && data.length > 0)
{ {
var options = ''; var options = '';
var defaultkey = '';
var defaultprice = '';
var i = 0; var i = 0;
$(data).each(function() { $(data).each(function() {
i++; if (this.id != 'pmpprice')
options += '<option value="'+this.id+'" price="'+this.price+'"'; {
if (i == 1) { i++;
options += ' selected'; options += '<option value="'+this.id+'" price="'+this.price+'"';
$("#buying_price").val(this.price); if (this.price > 0 && i == 1) { defaultkey = this.id; defaultprice = this.price; }
} options += '>'+this.label+'</option>';
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>'; options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
$("#buying_price").hide();
/* alert(defaultkey+' '+defaultprice); */
$("#fournprice_predef").html(options).show(); $("#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() { $("#fournprice_predef").change(function() {
var selval = $(this).find('option:selected').attr("price"); /* Hide field buying_price according to choice into list (if 'inputprice' or not) */
if (selval) var linevalue=$(this).find('option:selected').val();
$("#buying_price").val(selval).hide(); var pricevalue = $(this).find('option:selected').attr("price");
else if (linevalue != 'inputprice' && linevalue != 'pmpprice') {
$('#buying_price').show(); $("#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'); 'json');

View File

@ -17,7 +17,7 @@
/** /**
* \file /htdocs/fourn/ajax/getSupplierPrices.php * \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 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
@ -119,6 +119,11 @@ if (! empty($idprod))
$db->free($result); $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); echo json_encode($prices);