Fix error when mark rate is 100% and buying price is 0, no way to
recalculate the unit price. Fix cancel button was disabled if mark rate was not valid Fix if mark rate is a number with space, does not hang.
This commit is contained in:
parent
a21b015cbb
commit
aaa639a3ab
@ -23,7 +23,7 @@
|
|||||||
* $object (invoice, order, ...)
|
* $object (invoice, order, ...)
|
||||||
* $conf
|
* $conf
|
||||||
* $langs
|
* $langs
|
||||||
* $seller, $nuyer
|
* $seller, $buyer
|
||||||
* $dateSelector
|
* $dateSelector
|
||||||
* $forceall (0 by default, 1 for supplier invoices/orders)
|
* $forceall (0 by default, 1 for supplier invoices/orders)
|
||||||
* $senderissupplier (0 by default, 1 for supplier invoices/orders)
|
* $senderissupplier (0 by default, 1 for supplier invoices/orders)
|
||||||
@ -259,6 +259,7 @@ if (! empty($conf->margin->enabled))
|
|||||||
|
|
||||||
/* Init field buying_price and fournprice */
|
/* Init field buying_price and fournprice */
|
||||||
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
|
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
|
||||||
|
console.log(data);
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
var options = '';
|
var options = '';
|
||||||
var trouve=false;
|
var trouve=false;
|
||||||
@ -302,9 +303,10 @@ if (! empty($conf->margin->enabled))
|
|||||||
$('#savelinebutton').click(function (e) {
|
$('#savelinebutton').click(function (e) {
|
||||||
return checkEditLine(e, "np_marginRate");
|
return checkEditLine(e, "np_marginRate");
|
||||||
});
|
});
|
||||||
|
/* Disabled. We must be able to click on button 'cancel'. Check must be done only on button 'save'.
|
||||||
$("input[name='np_marginRate']:first").blur(function(e) {
|
$("input[name='np_marginRate']:first").blur(function(e) {
|
||||||
return checkEditLine(e, "np_marginRate");
|
return checkEditLine(e, "np_marginRate");
|
||||||
});
|
});*/
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
if (! empty($conf->global->DISPLAY_MARK_RATES))
|
if (! empty($conf->global->DISPLAY_MARK_RATES))
|
||||||
@ -313,9 +315,10 @@ if (! empty($conf->margin->enabled))
|
|||||||
$('#savelinebutton').click(function (e) {
|
$('#savelinebutton').click(function (e) {
|
||||||
return checkEditLine(e, "np_markRate");
|
return checkEditLine(e, "np_markRate");
|
||||||
});
|
});
|
||||||
|
/* Disabled. We must be able to click on button 'cancel'. Check must be done only on button 'save'.
|
||||||
$("input[name='np_markRate']:first").blur(function(e) {
|
$("input[name='np_markRate']:first").blur(function(e) {
|
||||||
return checkEditLine(e, "np_markRate");
|
return checkEditLine(e, "np_markRate");
|
||||||
});
|
});*/
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@ -323,7 +326,7 @@ if (! empty($conf->margin->enabled))
|
|||||||
|
|
||||||
|
|
||||||
/* If margin rate field empty, do nothing. */
|
/* If margin rate field empty, do nothing. */
|
||||||
/* Force content of price_ht to 0 or if a discount is set recalculate it from margin rate */
|
/* Force content of price_ht to 0 or if a discount is set, recalculate it from margin rate */
|
||||||
function checkEditLine(e, npRate)
|
function checkEditLine(e, npRate)
|
||||||
{
|
{
|
||||||
var buying_price = $("input[name='buying_price']:first");
|
var buying_price = $("input[name='buying_price']:first");
|
||||||
@ -332,16 +335,16 @@ if (! empty($conf->margin->enabled))
|
|||||||
var rate = $("input[name='"+npRate+"']:first");
|
var rate = $("input[name='"+npRate+"']:first");
|
||||||
if (rate.val() == '' || (typeof rate.val()) == 'undefined' ) return true;
|
if (rate.val() == '' || (typeof rate.val()) == 'undefined' ) return true;
|
||||||
|
|
||||||
if (! $.isNumeric(rate.val().replace(',','.')))
|
if (! $.isNumeric(rate.val().replace(' ','').replace(',','.')))
|
||||||
{
|
{
|
||||||
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>');
|
alert('<?php echo $langs->transnoentitiesnoconv("rateMustBeNumeric"); ?>');
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setTimeout(function () { rate.focus() }, 50);
|
setTimeout(function () { rate.focus() }, 50);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (npRate == "np_markRate" && rate.val() >= 100)
|
if (npRate == "np_markRate" && rate.val() >= 100)
|
||||||
{
|
{
|
||||||
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
|
alert('<?php echo $langs->transnoentitiesnoconv("markRateShouldBeLesserThan100"); ?>');
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setTimeout(function () { rate.focus() }, 50);
|
setTimeout(function () { rate.focus() }, 50);
|
||||||
return false;
|
return false;
|
||||||
@ -354,14 +357,20 @@ if (! empty($conf->margin->enabled))
|
|||||||
{
|
{
|
||||||
bpjs=price2numjs(buying_price.val());
|
bpjs=price2numjs(buying_price.val());
|
||||||
ratejs=price2numjs(rate.val());
|
ratejs=price2numjs(rate.val());
|
||||||
|
|
||||||
/* console.log(npRate+" - "+bpjs+" - "+ratejs); */
|
/* console.log(npRate+" - "+bpjs+" - "+ratejs); */
|
||||||
|
|
||||||
if (npRate == "np_marginRate")
|
if (npRate == "np_marginRate")
|
||||||
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
|
price = ((bpjs * (1 + (ratejs / 100))) / (1 - remisejs / 100));
|
||||||
else if (npRate == "np_markRate")
|
else if (npRate == "np_markRate")
|
||||||
price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
|
{
|
||||||
|
if (ratejs != 100)
|
||||||
|
{
|
||||||
|
price = ((bpjs / (1 - (ratejs / 100))) / (1 - remisejs / 100));
|
||||||
|
}
|
||||||
|
else price=$("input[name='price_ht']:first").val();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* console.log("new price ht = "+price); */
|
||||||
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
|
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user