Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 050ff50a

Von Sven Schöling vor fast 14 Jahren hinzugefügt

  • ID 050ff50a42716bdc0a31d4b948752cf3a3b675e0
  • Vorgänger c22f33d9
  • Nachfolger 79855851

Formeln sollten das eingestellte Zahlenformat benutzen.

Fix zu Bug 1483.

Unterschiede anzeigen:

templates/webpages/generic/calculate_qty.html
39 39
 </form>
40 40

  
41 41
 <script type="text/javascript">
42
  <!--//
43
      function calculate_qty() {
44
        [% FOREACH row = VARIABLES %]
45
        var [% row.name %] = document.getElementsByName("[% row.name %]")[0].value.replace(/,/g, ".");
46
       [% END %]
47
        var result = [% formel %];
48
        result = number_format(result, 2, ",", ".");
49
        window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
50
        self.close();
51
      }
52
      //-->
42
   function calculate_qty() {
43
[%- FOREACH row = VARIABLES %]
44
     var [% row.name %] = parse_amount('[% myconfig.numberformat %]', document.getElementsByName("[% row.name %]")[0].value);
45
[%- END %]
46
     var result = [% formel %];
47
     result = number_format(result, 2, '[% myconfig.numberformat %]');
48
     window.opener.document.getElementsByName(document.Form.input_name.value)[0].value = result;
49
     self.close();
50
   }
51

  
52
   function parse_amount(numberformat, amount) {
53
     if (numberformat == '1.000,00' || numberformat == '1000,00')
54
       amount = amount.replace(/\./g, "").replace(/,/, ".");
55
     if (numberformat == "1'000.00")
56
       amount = amount.replace(/\'/g, '');
57
     return amount.replace(/,/g, '');
58
   }
53 59

  
54
function /*out: String*/ number_format( /* in: float   */ number, 
55
                                        /* in: integer */ laenge, 
56
                                        /* in: String  */ sep, 
57
                                        /* in: String  */ th_sep ) {
60
   function number_format(number, precision, numberformat) {
61
     number = Math.round( number * Math.pow(10, precision) ) / Math.pow(10, precision);
62
     var nf     = numberformat.replace(/\d/g, '').split('').reverse();
63
     var sep    = nf[0];
64
     var th_sep = nf[1];
58 65

  
59
  number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
60
  str_number = number+"";
61
  arr_int = str_number.split(".");
62
  if(!arr_int[0]) arr_int[0] = "0";
63
  if(!arr_int[1]) arr_int[1] = "";
64
  if(arr_int[1].length < laenge){
65
    nachkomma = arr_int[1];
66
    for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
67
    arr_int[1] = nachkomma;
68
  }
69
  if(th_sep != "" && arr_int[0].length > 3){
70
    Begriff = arr_int[0];
71
    arr_int[0] = "";
72
    for(j = 3; j < Begriff.length ; j+=3){
73
      Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
74
      arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
75
    }
76
    str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
77
    arr_int[0] = str_first + arr_int[0];
78
  }
79
  return arr_int[0]+sep+arr_int[1];
80
}
66
     str_number = number+"";
67
     arr_int = str_number.split(".");
68
     if(!arr_int[0]) arr_int[0] = "0";
69
     if(!arr_int[1]) arr_int[1] = "";
70
     if(arr_int[1].length < precision) {
71
       nachkomma = arr_int[1];
72
       for(i=arr_int[1].length+1; i <= precision; i++) {
73
         nachkomma += "0";
74
       }
75
       arr_int[1] = nachkomma;
76
     }
77
     if(th_sep != "" && arr_int[0].length > 3) {
78
       raw_arr_int = arr_int[0];
79
       arr_int[0] = "";
80
       for(j = 3; j < raw_arr_int.length ; j+=3) {
81
         arr_int[0] = th_sep + raw_arr_int.slice(raw_arr_int.length - j, raw_arr_int.length - j + 3) +  arr_int[0] + "";
82
       }
83
       str_first = raw_arr_int.substr(0, (raw_arr_int.length % 3 == 0) ? 3 : (raw_arr_int.length % 3));
84
       arr_int[0] = str_first + arr_int[0];
85
     }
86
     return arr_int[0] + sep + arr_int[1];
87
   }
81 88
 </script>
82 89

  
83 90
</body>

Auch abrufbar als: Unified diff