mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
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, ...)
|
||||
* $conf
|
||||
* $langs
|
||||
* $seller, $nuyer
|
||||
* $seller, $buyer
|
||||
* $dateSelector
|
||||
* $forceall (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 */
|
||||
$.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) {
|
||||
var options = '';
|
||||
var trouve=false;
|
||||
|
|
@ -302,9 +303,10 @@ if (! empty($conf->margin->enabled))
|
|||
$('#savelinebutton').click(function (e) {
|
||||
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) {
|
||||
return checkEditLine(e, "np_marginRate");
|
||||
});
|
||||
});*/
|
||||
<?php
|
||||
}
|
||||
if (! empty($conf->global->DISPLAY_MARK_RATES))
|
||||
|
|
@ -313,9 +315,10 @@ if (! empty($conf->margin->enabled))
|
|||
$('#savelinebutton').click(function (e) {
|
||||
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) {
|
||||
return checkEditLine(e, "np_markRate");
|
||||
});
|
||||
});*/
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
|
@ -323,7 +326,7 @@ if (! empty($conf->margin->enabled))
|
|||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
var buying_price = $("input[name='buying_price']:first");
|
||||
|
|
@ -332,16 +335,16 @@ if (! empty($conf->margin->enabled))
|
|||
var rate = $("input[name='"+npRate+"']:first");
|
||||
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();
|
||||
setTimeout(function () { rate.focus() }, 50);
|
||||
return false;
|
||||
}
|
||||
if (npRate == "np_markRate" && rate.val() >= 100)
|
||||
{
|
||||
alert('<?php echo $langs->trans("markRateShouldBeLesserThan100"); ?>');
|
||||
alert('<?php echo $langs->transnoentitiesnoconv("markRateShouldBeLesserThan100"); ?>');
|
||||
e.stopPropagation();
|
||||
setTimeout(function () { rate.focus() }, 50);
|
||||
return false;
|
||||
|
|
@ -354,14 +357,20 @@ if (! empty($conf->margin->enabled))
|
|||
{
|
||||
bpjs=price2numjs(buying_price.val());
|
||||
ratejs=price2numjs(rate.val());
|
||||
|
||||
/* console.log(npRate+" - "+bpjs+" - "+ratejs); */
|
||||
|
||||
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")
|
||||
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
|
||||
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user