FIX update margins rates on object line edit
This commit is contained in:
parent
04be66eab7
commit
39a422ef94
@ -303,6 +303,76 @@ if (!empty($extrafieldsline))
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<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;
|
||||||
|
|
||||||
|
if (! $.isNumeric(rate.val().replace(',','.')))
|
||||||
|
{
|
||||||
|
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(document).ready(function()
|
||||||
{
|
{
|
||||||
jQuery("#price_ht").keyup(function(event) {
|
jQuery("#price_ht").keyup(function(event) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user