Early payment discount option moved from branch to payment terms.
[fa-stable.git] / js / allocate.js
index 707bdf8ef841afd4ff4c9fc94a7d2aa45ccffc13..a47e8b02d2e629146988b9d170d79e0c3dbc8db9 100644 (file)
@@ -29,6 +29,21 @@ function blur_alloc(i) {
        price_format('total_allocated', total, user.pdec, 1, 1);
 }
 
+function update_totals() {
+       var amount = 0;
+       var discount = 0;
+
+       for (var i=0; i<docs.length; i++) {
+               amount += get_amount('amount'+docs[i])
+               if (document.getElementsByName('early_disc'+docs[i])[0].checked 
+                       && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i])))
+                               discount += get_amount('early_disc'+docs[i]);
+       }
+       price_format('amount', amount-discount, user.pdec);
+       price_format('discount', discount, user.pdec);
+       
+}
+
 function allocate_all(doc) {
        var amount = get_amount('amount'+doc);
        var unallocated = get_amount('un_allocated'+doc);
@@ -64,6 +79,11 @@ var allocations = {
                e.onfocus = function() {
                        focus_alloc(this);
                };
+       },
+       '.check':function(e) {
+               e.onclick = function() {
+                       update_totals();
+               }
        }
 }