diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php
index 5f4c83a1a71..6e1c3c687f9 100644
--- a/htdocs/core/tpl/objectline_add.tpl.php
+++ b/htdocs/core/tpl/objectline_add.tpl.php
@@ -41,17 +41,31 @@ if (! empty($conf->margin->enabled)) {
?>
>
|
@@ -491,11 +514,7 @@ $(document).ready(function() {
});
-});
-
-
margin->enabled)) { ?>
-
+ var npRate = null;
+global->DISPLAY_MARGIN_RATES)) { ?>
+ npRate = "np_marginRate";
+ global->DISPLAY_MARK_RATES)) { ?>
+ npRate = "np_markRate";
+
+
+$("form#addproduct").submit(function(e) {
+ if (npRate) return checkFreeLine(e, npRate);
+ else return true;
+});
+if (npRate == 'np_marginRate') {
+ $("input[name='np_marginRate']:first").blur(function(e) {
+ return checkFreeLine(e, npRate);
+ });
+}
+else {
+ if (npRate == 'np_markRate') {
+ $("input[name='np_markRate']:first").blur(function(e) {
+ return checkFreeLine(e, npRate);
+ });
+ }
+}
+
+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('trans("rateMustBeNumeric"); ?>');
+ e.stopPropagation();
+ setTimeout(function () { rate.focus() }, 50);
+ return false;
+ }
+ if (npRate == "np_markRate" && rate.val() >= 100)
+ {
+ alert('trans("markRateShouldBeLesserThan100"); ?>');
+ e.stopPropagation();
+ setTimeout(function () { rate.focus() }, 50);
+ return false;
+ }
+
+ var np_price = 0;
+ if (remise.val().replace(',','.') != 100)
+ {
+ if (npRate == "np_marginRate")
+ np_price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
+ else {
+ if (npRate == "np_markRate")
+ np_price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
+ }
+ }
+ $("input[name='price_ht']:first").val(formatFloat(np_price));
+ update_price('price_ht', 'price_ttc');
+
+ return true;
+}
+function roundFloat(num) {
+ var main_max_dec_shown = global->MAIN_MAX_DECIMALS_SHOWN; ?>;
+ var main_rounding = global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
+
+ var amount = num.toString().replace(',','.'); // should be useless
+ var nbdec = 0;
+ var rounding = main_rounding;
+ var pos = amount.indexOf('.');
+ var decpart = '';
+ if (pos >= 0)
+ decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale
+ nbdec = decpart.length;
+ if (nbdec > rounding)
+ rounding = nbdec;
+ // Si on depasse max
+ if (rounding > main_max_dec_shown)
+ {
+ rounding = main_max_dec_shown;
+ }
+ //amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors
+ return parseFloat(amount).toFixed(rounding);
+}
+
+function formatFloat(num) {
+ return roundFloat(num).replace('.', ',');
+}
+});
+
+
diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php
index 328964bc0df..ac05f71b901 100644
--- a/htdocs/core/tpl/objectline_edit.tpl.php
+++ b/htdocs/core/tpl/objectline_edit.tpl.php
@@ -28,7 +28,7 @@
?>
- |
margin->enabled)) { ?>
-
-
-
- |
-
+
+
+
+ |
+ rights->margins->creer) {
+ if (! empty($conf->global->DISPLAY_MARGIN_RATES))
+ {
+ $margin_rate = (isset($_POST["marginRate"])?$_POST["marginRate"]:(($line->pa_ht == 0)?'':price($line->marge_tx)));
+ echo '% | ';
+ $coldisplay++;
+ }
+ elseif (! empty($conf->global->DISPLAY_MARK_RATES))
+ {
+ $mark_rate = (isset($_POST["markRate"])?$_POST["markRate"]:price($line->marque_tx));
+ echo '% | ';
+ $coldisplay++;
+ }
+ }
+ } ?>
">
@@ -386,5 +400,96 @@ $(document).ready(function() {
}, 'json');
});
+ var npRate = null;
+global->DISPLAY_MARGIN_RATES)) { ?>
+ npRate = "marginRate";
+ global->DISPLAY_MARK_RATES)) { ?>
+ npRate = "markRate";
+
+
+$("form#editproduct").submit(function(e) {
+ if (npRate) return checkEditLine(e, npRate);
+ else return true;
+});
+if (npRate == 'marginRate') {
+ $("input[name='marginRate']:first").blur(function(e) {
+ return checkEditLine(e, npRate);
+ });
+}
+else {
+ if (npRate == 'markRate') {
+ $("input[name='markRate']:first").blur(function(e) {
+ return checkEditLine(e, npRate);
+ });
+ }
+}
+
+function checkEditLine(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('trans("rateMustBeNumeric"); ?>');
+ e.stopPropagation();
+ setTimeout(function () { rate.focus() }, 50);
+ return false;
+ }
+ if (npRate == "markRate" && rate.val() >= 100)
+ {
+ alert('trans("markRateShouldBeLesserThan100"); ?>');
+ e.stopPropagation();
+ setTimeout(function () { rate.focus() }, 50);
+ return false;
+ }
+
+ var price = 0;
+ if (remise.val().replace(',','.') != 100)
+ {
+ if (npRate == "marginRate")
+ price = ((buying_price.val().replace(',','.') * (1 + rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
+ else {
+ if (npRate == "markRate")
+ price = ((buying_price.val().replace(',','.') / (1 - rate.val().replace(',','.') / 100)) / (1 - remise.val().replace(',','.') / 100));
+ }
+ }
+ $("input[name='price_ht']:first").val(formatFloat(price));
+
+ return true;
+}
+function roundFloat(num) {
+ var main_max_dec_shown = global->MAIN_MAX_DECIMALS_SHOWN; ?>;
+ var main_rounding = global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); ?>;
+
+ var amount = num.toString().replace(',','.'); // should be useless
+ var nbdec = 0;
+ var rounding = main_rounding;
+ var pos = amount.indexOf('.');
+ var decpart = '';
+ if (pos >= 0)
+ decpart = amount.substr(pos+1).replace('/0+$/i',''); // Supprime les 0 de fin de partie decimale
+ nbdec = decpart.length;
+ if (nbdec > rounding)
+ rounding = nbdec;
+ // Si on depasse max
+ if (rounding > main_max_dec_shown)
+ {
+ rounding = main_max_dec_shown;
+ }
+ //amount = parseFloat(amount) + (1 / Math.pow(100, rounding)); // to avoid floating-point errors
+ return parseFloat(amount).toFixed(rounding);
+}
+
+function formatFloat(num) {
+ return roundFloat(num).replace('.', ',');
+}
+
|