Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / templates / webpages / generic / calculate_qty.html
index 035caa6..6b37127 100644 (file)
@@ -1,11 +1,9 @@
 [%- USE T8 %]
 [%- USE HTML %]
-<h1>[% title %]</h1>
-
- <form name="Form">
+ <form name="CalcQtyForm" id="calc_qty_form_id">
 
   <input type="hidden" name="input_name" value="[% HTML.escape(input_name) %]">
-  <input type="hidden" name="input_id" value="[% HTML.escape(input_id) %]">
+  <input type="hidden" name="input_id"   value="[% HTML.escape(input_id) %]">
 
   <table width="100%">
    <tr><td>[% 'Please insert object dimensions below.' | $T8 %]</td></tr>
  <script type="text/javascript">
    function calculate_qty() {
 [%- FOREACH row = VARIABLES %]
-     var [% row.name %] = parse_amount('[% myconfig.numberformat %]', document.getElementsByName("[% row.name %]")[0].value);
+     var [% row.name %] = kivi.parse_amount($('#calc_qty_form_id #[% row.name %]').val());
 [%- END %]
      var result = [% formel %];
-     result = number_format(result, 2, '[% myconfig.numberformat %]');
-     window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
-     self.close();
-   }
-
-   function parse_amount(numberformat, amount) {
-     if (numberformat == '1.000,00' || numberformat == '1000,00')
-       amount = amount.replace(/\./g, "").replace(/,/, ".");
-     if (numberformat == "1'000.00")
-       amount = amount.replace(/\'/g, '');
-     return amount.replace(/,/g, '');
-   }
-
-   function number_format(number, precision, numberformat) {
-     number = Math.round( number * Math.pow(10, precision) ) / Math.pow(10, precision);
-     var nf     = numberformat.replace(/\d/g, '').split('').reverse();
-     var sep    = nf[0];
-     var th_sep = nf[1];
-
-     str_number = number+"";
-     arr_int = str_number.split(".");
-     if(!arr_int[0]) arr_int[0] = "0";
-     if(!arr_int[1]) arr_int[1] = "";
-     if(arr_int[1].length < precision) {
-       nachkomma = arr_int[1];
-       for(i=arr_int[1].length+1; i <= precision; i++) {
-         nachkomma += "0";
-       }
-       arr_int[1] = nachkomma;
-     }
-     if(th_sep != "" && arr_int[0].length > 3) {
-       raw_arr_int = arr_int[0];
-       arr_int[0] = "";
-       for(j = 3; j < raw_arr_int.length ; j+=3) {
-         arr_int[0] = th_sep + raw_arr_int.slice(raw_arr_int.length - j, raw_arr_int.length - j + 3) +  arr_int[0] + "";
-       }
-       str_first = raw_arr_int.substr(0, (raw_arr_int.length % 3 == 0) ? 3 : (raw_arr_int.length % 3));
-       arr_int[0] = str_first + arr_int[0];
+     result = kivi.format_amount(result, 2);
+     if (document.CalcQtyForm.input_id.value) {
+       document.getElementById(document.CalcQtyForm.input_id.value).value = result;
+     } else {
+       document.getElementsByName(document.CalcQtyForm.input_name.value)[0].value = result;
      }
-     return arr_int[0] + sep + arr_int[1];
+     $('#calc_qty_dialog').dialog('close');
    }
- </script>
 
+ </script>