Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: for avoid division by 0 #4239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions htdocs/core/tpl/objectline_create.tpl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
/* Copyright (C) 2010-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
Expand Down Expand Up @@ -352,35 +352,36 @@ function checkFreeLine(e, npRate)

if (! $.isNumeric(rate.val().replace(',','.')))
{
alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
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->trans("markRateShouldBeLesserThan100")); ?>');
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 == '') remisejs=0;

if (remisejs != 100) // If a discount not 100 or no discount
{
if (remisejs == '') remisejs=0;
bpjs=price2numjs(buying_price.val());

bpjs=price2numjs(buying_price.val());
if (bpjs > 0 && remisejs != 100) // If buying_price and a discount not 100 or no discount
{
var price = 0;
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
}
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value

return true;
}
Expand Down
17 changes: 10 additions & 7 deletions htdocs/core/tpl/objectline_edit.tpl.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
/* Copyright (C) 2010-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
Expand Down Expand Up @@ -282,25 +282,27 @@ function checkEditLine(e, npRate)

if (! $.isNumeric(rate.val().replace(',','.')))
{
alert('<?php echo $langs->trans("rateMustBeNumeric"); ?>');
alert('<?php echo $langs->transnoentities("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->transnoentities("markRateShouldBeLesserThan100"); ?>');
e.stopPropagation();
setTimeout(function () { rate.focus() }, 50);
return false;
}

var price = 0;
remisejs=price2numjs(remise.val());
if (remisejs == '') remisejs=0;

if (remisejs != 100)
bpjs=price2numjs(buying_price.val());

if (bpjs > 0 && remisejs != 100) // If buying_price and a discount not 100 or no discount
{
bpjs=price2numjs(buying_price.val());
var price = 0;
ratejs=price2numjs(rate.val());

/* console.log(npRate+" - "+bpjs+" - "+ratejs); */
Expand All @@ -309,8 +311,9 @@ function checkEditLine(e, npRate)
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
}
$("input[name='price_ht']:first").val(price); // TODO Must use a function like php price to have here a formated value

return true;
}
Expand Down