FIX #3661 Margin is not selected correctly when adding a product
This commit is contained in:
parent
826cc6db1b
commit
77371af35a
@ -171,6 +171,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log("ajax_autocompleter new value selected, we trigger change");
|
||||
$("#search_'.$htmlname.'").trigger("change"); // To tell that input text field was modified
|
||||
}
|
||||
,delay: 500
|
||||
|
||||
@ -489,6 +489,7 @@ jQuery(document).ready(function() {
|
||||
});
|
||||
|
||||
$("#prod_entry_mode_predef").on( "click", function() {
|
||||
console.log("click prod_entry_mode_predef");
|
||||
setforpredef();
|
||||
jQuery('#trlinefordates').show();
|
||||
});
|
||||
@ -496,6 +497,7 @@ jQuery(document).ready(function() {
|
||||
/* When changing predefined product, we reload list of supplier prices */
|
||||
$("#idprod, #idprodfournprice").change(function()
|
||||
{
|
||||
console.log("change #idprod, #idprodfournprice, conf->global->MARGIN_TYPE=<?php echo $conf->global->MARGIN_TYPE ?>");
|
||||
setforpredef();
|
||||
jQuery('#trlinefordates').show();
|
||||
|
||||
@ -516,6 +518,7 @@ jQuery(document).ready(function() {
|
||||
var options = '';
|
||||
var defaultkey = '';
|
||||
var defaultprice = '';
|
||||
var bestpricefound = 0;
|
||||
var i = 0;
|
||||
$(data).each(function() {
|
||||
if (this.id != 'pmpprice')
|
||||
@ -523,24 +526,23 @@ jQuery(document).ready(function() {
|
||||
i++;
|
||||
|
||||
// If margin is calculated on best supplier price, we set it by defaut (but only if value is not 0)
|
||||
var defaultbuyprice = '<?php echo ((isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')?'bestsupplierprice':''); ?>';
|
||||
if (i == 1 && this.price > 0 && 'bestsupplierprice' == defaultbuyprice) { defaultkey = this.id; defaultprice = this.price; }
|
||||
|
||||
options += '<option value="'+this.id+'" price="'+this.price+'"';
|
||||
if (this.price > 0 && i == 1) { defaultkey = this.id; defaultprice = this.price; }
|
||||
options += '>'+this.label+'</option>';
|
||||
var defaultbuyprice = '<?php echo ((isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1')?'bestsupplierprice':''); ?>'; // We set here default value to use
|
||||
console.log(this.id+" "+this.price+" "+defaultbuyprice+" "+(this.price > 0));
|
||||
if (bestpricefound == 0 && this.price > 0 && 'bestsupplierprice' == defaultbuyprice) { defaultkey = this.id; defaultprice = this.price; bestpricefound=1; } // bestpricefound is used to take the first price > 0
|
||||
}
|
||||
if (this.id == 'pmpprice')
|
||||
{
|
||||
// If margin is calculated on PMP, we set it by defaut (but only if value is not 0)
|
||||
var defaultbuyprice = '<?php echo ((isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')?'pmp':''); ?>';
|
||||
console.log(this.id+" "+this.price+" "+defaultbuyprice);
|
||||
if (this.price > 0 && 'pmp' == defaultbuyprice) { defaultkey = this.id; defaultprice = this.price; }
|
||||
|
||||
options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
|
||||
}
|
||||
options += '<option value="'+this.id+'" price="'+this.price+'">'+this.label+'</option>';
|
||||
});
|
||||
options += '<option value="inputprice" price="'+defaultprice+'"><?php echo $langs->trans("InputPrice"); ?></option>';
|
||||
|
||||
console.log("defaultkey="+defaultkey);
|
||||
|
||||
$("#fournprice_predef").html(options).show();
|
||||
if (defaultkey != '')
|
||||
{
|
||||
@ -555,6 +557,7 @@ jQuery(document).ready(function() {
|
||||
$("#buying_price").val(Math.round(defaultprice,<?php print ($conf->global->MAIN_MAX_DECIMALS_UNIT ? $conf->global->MAIN_MAX_DECIMALS_UNIT : 5); ?>));
|
||||
|
||||
$("#fournprice_predef").change(function() {
|
||||
console.log("change on fournprice_predef");
|
||||
/* 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");
|
||||
|
||||
@ -38,7 +38,7 @@ $langs->load('stocks');
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
*/
|
||||
|
||||
top_httphead();
|
||||
|
||||
@ -59,7 +59,7 @@ if ($idprod > 0)
|
||||
$sql.= " WHERE pfp.fk_product = ".$idprod;
|
||||
$sql.= " AND p.tobuy = 1";
|
||||
$sql.= " AND s.fournisseur = 1";
|
||||
$sql.= " ORDER BY s.nom, pfp.ref_fourn DESC";
|
||||
$sql.= " ORDER BY pfp.unitprice, s.nom, pfp.ref_fourn DESC"; // Best price first
|
||||
|
||||
dol_syslog("Ajax::getSupplierPrices", LOG_DEBUG);
|
||||
$result=$db->query($sql);
|
||||
@ -117,7 +117,7 @@ if ($idprod > 0)
|
||||
$label = price($price,0,$langs,0,0,-1,$conf->currency)."/".$langs->trans("Unit");
|
||||
if ($objp->ref_fourn) $label.=' ('.$objp->ref_fourn.')';
|
||||
|
||||
$prices[] = array("id" => $objp->idprodfournprice, "price" => price($price,0,'',0), "label" => $label, "title" => $title);
|
||||
$prices[] = array("id" => $objp->idprodfournprice, "price" => price2num($price,0,'',0), "label" => $label, "title" => $title); // For price field, we must use price2num(), for label or title, price()
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user