1 /**********************************************************************
2 Copyright (C) FrontAccounting, LLC.
3 Released under the terms of the GNU General Public License, GPL,
4 as published by the Free Software Foundation, either version 3
5 of the License, or (at your option) any later version.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ***********************************************************************/
11 function focus_alloc(i) {
13 i.setAttribute('_last', get_amount(i.name));
16 function blur_alloc(i) {
17 var id = i.name.substr(6)
18 var unallocated = get_amount('un_allocated'+id)
19 var cur = Math.max(Math.min(get_amount(i.name), unallocated, get_amount('left_to_allocate',1)+parseFloat(i.getAttribute('_last'))), 0)
21 price_format(i.name, cur, user.pdec);
22 price_format('left'+id, unallocated-cur, user.pdec, 1);
26 function update_totals() {
30 for (var i=0; i<docs.length; i++) {
31 amount += get_amount('amount'+docs[i])
32 if (document.getElementsByName('early_disc'+docs[i])[0].checked
33 && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i])))
34 discount += get_amount('early_disc'+docs[i]);
36 price_format('left_to_allocate', Math.abs(get_amount('total',1)-(amount-discount)), user.pdec, 1,1);
37 price_format('total_allocated', amount-discount, user.pdec, 1, 1);
38 price_format('total_discount', discount, user.pdec, 1, 1);
42 function allocate_all(doc) {
43 var unallocated = get_amount('un_allocated'+doc);
44 var cur = Math.min(unallocated, get_amount('left_to_allocate',1))
45 price_format('amount'+doc, cur, user.pdec);
46 price_format('left'+doc, 0, user.pdec, 1);
51 function allocate_none(doc) {
52 var unallocated = get_amount('un_allocated'+doc);
53 price_format('amount'+doc, 0, user.pdec);
54 price_format('left'+doc, unallocated, user.pdec, 1);
59 '.amount': function(e) {
60 e.onblur = function() {
63 e.onfocus = function() {
67 '.check':function(e) {
68 e.onclick = function() {
74 Behaviour.register(allocations);