Merge branch '10.0' of git@github.com:Dolibarr/dolibarr.git into 11.0

This commit is contained in:
Laurent Destailleur 2020-10-02 14:43:54 +02:00
commit cee28d0253

View File

@ -302,6 +302,77 @@ if (!empty($extrafields))
<script type="text/javascript">
<?php
if (! empty($usemargins) && $user->rights->margins->creer)
{
?>
/* Some js test when we click on button "Add" */
jQuery(document).ready(function() {
<?php
if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { ?>
$("input[name='np_marginRate']:first").blur(function(e) {
return checkFreeLine(e, "np_marginRate");
});
<?php
}
if (! empty($conf->global->DISPLAY_MARK_RATES)) { ?>
$("input[name='np_markRate']:first").blur(function(e) {
return checkFreeLine(e, "np_markRate");
});
<?php
}
?>
});
/* TODO This does not work for number with thousand separator that is , */
function checkFreeLine(e, npRate)
{
var buying_price = $("input[name='buying_price']:first");
var remise = $("input[name='remise_percent']:first");
var rate = $("input[name='"+npRate+"']:first");
if (rate.val() == '')
return true;
var ratejs = price2numjs(rate.val());
if (! $.isNumeric(ratejs))
{
alert('<?php echo dol_escape_js($langs->transnoentities("rateMustBeNumeric")); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
if (npRate == "np_markRate" && rate.val() >= 100)
{
alert('<?php echo dol_escape_js($langs->transnoentities("markRateShouldBeLesserThan100")); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}
var price = 0;
remisejs=price2numjs(remise.val());
if (remisejs != 100) // If a discount not 100 or no discount
{
if (remisejs == '') remisejs=0;
bpjs=price2numjs(buying_price.val());
ratejs=price2numjs(rate.val());
if (npRate == "np_marginRate")
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
else if (npRate == "np_markRate")
price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
}
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value
return true;
}
<?php
}
?>
jQuery(document).ready(function()
{
jQuery("#price_ht").keyup(function(event) {