Copyright notes at top op every source file
[fa-stable.git] / js / budget.js
1 /**********************************************************************
2     Copyright (C) FrontAccounting, LLC.
3         Released under the terms of the GNU Affero General Public License,
4         AGPL, as published by the Free Software Foundation, either version 
5         3 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/agpl-3.0.html>.
10 ***********************************************************************/
11 function focus_budget(i) {
12     save_focus(i);
13         i.setAttribute('_last', get_amount(i.name));
14 }
15
16 function blur_budget(i) {
17         var amount = get_amount(i.name);
18         var total = get_amount('Total', 1);
19         
20         if(amount<0) amount = 0;                
21         price_format(i.name, amount, 0);
22         price_format('Total', total+amount-i.getAttribute('_last'), 0, 1, 1);
23 }
24
25
26 var budget_calc = {
27         '.amount': function(e) {
28                 e.onblur = function() {
29                         blur_budget(this);
30                   };
31                 e.onfocus = function() {
32                         focus_budget(this);
33                 };
34         }
35 }
36
37 Behaviour.register(budget_calc);