Skip to content

Commit

Permalink
Add PMP into selection of buy price.
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jan 13, 2015
1 parent e6d016c commit 8b3faf4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
64 changes: 48 additions & 16 deletions htdocs/core/tpl/objectline_create.tpl.php
Expand Up @@ -448,41 +448,73 @@ function price2numjs(num)
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');
Expand Down
7 changes: 6 additions & 1 deletion htdocs/fourn/ajax/getSupplierPrices.php
Expand Up @@ -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
Expand Down Expand Up @@ -119,6 +119,11 @@
$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);
Expand Down

0 comments on commit 8b3faf4

Please sign in to comment.