Fix: margin calculation from % when we enter a free product.
This commit is contained in:
parent
2bac66fd52
commit
3776f7b146
@ -72,8 +72,8 @@ if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES))
|
|||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php
|
<?php
|
||||||
if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) echo '<td align="right">'.$langs->trans('MarginRate').'</td>';
|
if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARGIN_RATES)) echo '<td align="right"><span class="np_marginRate">'.$langs->trans('MarginRate').'</span></td>';
|
||||||
if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) echo '<td align="right">'.$langs->trans('MarkRate').'</td>';
|
if ($user->rights->margins->creer && ! empty($conf->global->DISPLAY_MARK_RATES)) echo '<td align="right"><span class="np_markRate">'.$langs->trans('MarkRate').'</span></td>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<td colspan="<?php echo $colspan; ?>"> </td>
|
<td colspan="<?php echo $colspan; ?>"> </td>
|
||||||
@ -226,12 +226,12 @@ else {
|
|||||||
{
|
{
|
||||||
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
|
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
|
||||||
{
|
{
|
||||||
echo '<td align="right" class="nowrap"><input type="text" size="2" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'"><span class="hideonsmartphone">%</span></td>';
|
echo '<td align="right" class="nowrap"><input type="text" size="2" id="np_marginRate" name="np_marginRate" value="'.(isset($_POST["np_marginRate"])?$_POST["np_marginRate"]:'').'"><span class="np_marginRate hideonsmartphone">%</span></td>';
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
}
|
}
|
||||||
if (! empty($conf->global->DISPLAY_MARK_RATES))
|
if (! empty($conf->global->DISPLAY_MARK_RATES))
|
||||||
{
|
{
|
||||||
echo '<td align="right" class="nowrap"><input type="text" size="2" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'"><span class="hideonsmartphone">%</span></td>';
|
echo '<td align="right" class="nowrap"><input type="text" size="2" id="np_markRate" name="np_markRate" value="'.(isset($_POST["np_markRate"])?$_POST["np_markRate"]:'').'"><span class="np_markRate hideonsmartphone">%</span></td>';
|
||||||
$coldisplay++;
|
$coldisplay++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ else {
|
|||||||
<input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
|
<input type="submit" class="button" value="<?php echo $langs->trans('Add'); ?>" name="addline" id="addline">
|
||||||
</td>
|
</td>
|
||||||
<?php
|
<?php
|
||||||
//Line extrafield
|
// Line extrafield
|
||||||
if (!empty($extrafieldsline)) {
|
if (!empty($extrafieldsline)) {
|
||||||
if ($this->table_element_line=='commandedet') {
|
if ($this->table_element_line=='commandedet') {
|
||||||
$newline = new OrderLine($this->db);
|
$newline = new OrderLine($this->db);
|
||||||
@ -344,6 +344,7 @@ if (! empty($usemargins) && $user->rights->margins->creer)
|
|||||||
var rate = $("input[name='"+npRate+"']:first");
|
var rate = $("input[name='"+npRate+"']:first");
|
||||||
if (rate.val() == '')
|
if (rate.val() == '')
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (! $.isNumeric(rate.val().replace(',','.')))
|
if (! $.isNumeric(rate.val().replace(',','.')))
|
||||||
{
|
{
|
||||||
alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
|
alert('<?php echo dol_escape_js($langs->trans("rateMustBeNumeric")); ?>');
|
||||||
@ -362,14 +363,16 @@ if (! empty($usemargins) && $user->rights->margins->creer)
|
|||||||
var price = 0;
|
var price = 0;
|
||||||
remisejs=price2numjs(remise.val());
|
remisejs=price2numjs(remise.val());
|
||||||
|
|
||||||
if (remisejs != 100)
|
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());
|
||||||
ratejs=price2numjs(rate.val());
|
ratejs=price2numjs(rate.val());
|
||||||
|
|
||||||
if (npRate == "marginRate")
|
if (npRate == "np_marginRate")
|
||||||
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
|
price = ((bpjs * (1 + ratejs / 100)) / (1 - remisejs / 100));
|
||||||
else if (npRate == "markRate")
|
else if (npRate == "np_markRate")
|
||||||
price = ((bpjs / (1 - ratejs / 100)) / (1 - remisejs / 100));
|
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
|
||||||
@ -381,6 +384,8 @@ if (! empty($usemargins) && $user->rights->margins->creer)
|
|||||||
/* Function similar to price2num in PHP */
|
/* Function similar to price2num in PHP */
|
||||||
function price2numjs(num)
|
function price2numjs(num)
|
||||||
{
|
{
|
||||||
|
if (num == '') return '';
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
$dec=','; $thousand=' ';
|
$dec=','; $thousand=' ';
|
||||||
if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->transnoentitiesnoconv("SeparatorDecimal");
|
if ($langs->transnoentitiesnoconv("SeparatorDecimal") != "SeparatorDecimal") $dec=$langs->transnoentitiesnoconv("SeparatorDecimal");
|
||||||
@ -497,6 +502,10 @@ function setforfree() {
|
|||||||
jQuery("#title_vat").show();
|
jQuery("#title_vat").show();
|
||||||
jQuery("#title_up_ht").show();
|
jQuery("#title_up_ht").show();
|
||||||
jQuery("#title_up_ttc").show();
|
jQuery("#title_up_ttc").show();
|
||||||
|
jQuery("#np_marginRate").show(); // May no exists
|
||||||
|
jQuery("#np_markRate").show(); // May no exists
|
||||||
|
jQuery(".np_marginRate").show(); // May no exists
|
||||||
|
jQuery(".np_markRate").show(); // May no exists
|
||||||
}
|
}
|
||||||
function setforpredef() {
|
function setforpredef() {
|
||||||
jQuery("#select_type").val(-1);
|
jQuery("#select_type").val(-1);
|
||||||
@ -509,6 +518,10 @@ function setforpredef() {
|
|||||||
jQuery("#title_vat").hide();
|
jQuery("#title_vat").hide();
|
||||||
jQuery("#title_up_ht").hide();
|
jQuery("#title_up_ht").hide();
|
||||||
jQuery("#title_up_ttc").hide();
|
jQuery("#title_up_ttc").hide();
|
||||||
|
jQuery("#np_marginRate").hide(); // May no exists
|
||||||
|
jQuery("#np_markRate").hide(); // May no exists
|
||||||
|
jQuery(".np_marginRate").hide(); // May no exists
|
||||||
|
jQuery(".np_markRate").hide(); // May no exists
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user