- var total = get_amount('total_allocated', 1);
- var left = get_amount('left_to_allocate', 1);
- total -= (amount-unallocated);
- left += (amount-unallocated);
- amount = unallocated;
- if(left<0) {
- total += left;
- amount += left;
- left = 0;
- }
- price_format('amount'+doc, amount, user.pdec);
- price_format('left_to_allocate', left, user.pdec, 1,1);
- price_format('total_allocated', total, user.pdec, 1, 1);
+ var cur = Math.min(unallocated, get_amount('left_to_allocate',1))
+ price_format('amount'+doc, cur, user.pdec);
+ price_format('left'+doc, 0, user.pdec, 1);
+ update_totals();
+