<body> in eigene Zeile (für späteres entfernen)
[kivitendo-erp.git] / templates / webpages / generic / calculate_qty.html
1 [%- USE T8 %]
2 [%- USE HTML %]
3 <body onload="[%- onload %]">
4
5  <form name="Form">
6
7   <input type="hidden" name="input_name" value="[% HTML.escape(input_name) %]">
8   <input type="hidden" name="input_id" value="[% HTML.escape(input_id) %]">
9
10   <table width="100%">
11    <tr>
12     <th class="listtop">[% title %]</th>
13    </tr>
14    <tr height="5"></tr>
15
16    <tr><td>[% 'Please insert object dimensions below.' | $T8 %]</td></tr>
17
18    <tr>
19     <td>
20
21      <table>
22       <tr class="listheading">
23        [% FOREACH col = HEADER %]
24         <th nowrap class="listheading">[% col.column_title %]</a></th>
25        [% END %]
26       </tr>
27
28       [% FOREACH row = VARIABLES %]
29        <tr class="listrow[% loop.count % 2 %]">
30         <td>[% HTML.escape(row.description) %]:</td><td><input id="[% row.name %]" name="[% row.name %]" value=""></td>
31         <td>[% HTML.escape(row.unit) %]</td>
32        </tr>
33       [% END %]
34      </table>
35
36     </td>
37    </tr>
38   </table>
39  <button type="button" onclick="calculate_qty()">[% 'Calculate' | $T8 %]</button>
40  </form>
41
42  <script type="text/javascript">
43    function calculate_qty() {
44 [%- FOREACH row = VARIABLES %]
45      var [% row.name %] = parse_amount('[% myconfig.numberformat %]', document.getElementsByName("[% row.name %]")[0].value);
46 [%- END %]
47      var result = [% formel %];
48      result = number_format(result, 2, '[% myconfig.numberformat %]');
49      window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
50      self.close();
51    }
52
53    function parse_amount(numberformat, amount) {
54      if (numberformat == '1.000,00' || numberformat == '1000,00')
55        amount = amount.replace(/\./g, "").replace(/,/, ".");
56      if (numberformat == "1'000.00")
57        amount = amount.replace(/\'/g, '');
58      return amount.replace(/,/g, '');
59    }
60
61    function number_format(number, precision, numberformat) {
62      number = Math.round( number * Math.pow(10, precision) ) / Math.pow(10, precision);
63      var nf     = numberformat.replace(/\d/g, '').split('').reverse();
64      var sep    = nf[0];
65      var th_sep = nf[1];
66
67      str_number = number+"";
68      arr_int = str_number.split(".");
69      if(!arr_int[0]) arr_int[0] = "0";
70      if(!arr_int[1]) arr_int[1] = "";
71      if(arr_int[1].length < precision) {
72        nachkomma = arr_int[1];
73        for(i=arr_int[1].length+1; i <= precision; i++) {
74          nachkomma += "0";
75        }
76        arr_int[1] = nachkomma;
77      }
78      if(th_sep != "" && arr_int[0].length > 3) {
79        raw_arr_int = arr_int[0];
80        arr_int[0] = "";
81        for(j = 3; j < raw_arr_int.length ; j+=3) {
82          arr_int[0] = th_sep + raw_arr_int.slice(raw_arr_int.length - j, raw_arr_int.length - j + 3) +  arr_int[0] + "";
83        }
84        str_first = raw_arr_int.substr(0, (raw_arr_int.length % 3 == 0) ? 3 : (raw_arr_int.length % 3));
85        arr_int[0] = str_first + arr_int[0];
86      }
87      return arr_int[0] + sep + arr_int[1];
88    }
89  </script>
90
91 </body>
92 </html>