Added client side calculations for budget
[fa-stable.git] / gl / gl_budget.php
index b1a7cae559c603a99d3140aeff06e9692116cdaf..b503a61c5f3db15fccafdad1cfa6c7ad81796b9c 100644 (file)
@@ -4,6 +4,8 @@ $page_security = 10;
 $path_to_root="..";
 include($path_to_root . "/includes/session.inc");
 
+add_js_file('budget.js');
+
 page(_("Budget Entry"));
 
 include($path_to_root . "/includes/ui.inc");
@@ -84,7 +86,10 @@ if (isset($_POST['add']) || isset($_POST['delete']))
                display_notification_centered(_("The Budget has been deleted."));
        
        //meta_forward($_SERVER['PHP_SELF']);           
+       $Ajax->activate('budget_tbl');
 }      
+if (isset($_POST['submit']) || isset($_POST['update']))
+       $Ajax->activate('budget_tbl');
 
 //-------------------------------------------------------------------------------------
 
@@ -115,8 +120,9 @@ if (db_has_gl_accounts())
                hidden('dim1', 0);
                hidden('dim2', 0);
        }
-       submit_row('submit', _("Get"));
+       submit_row('submit', _("Get"), true, '', '', true);
        end_table(1);
+       div_start('budget_tbl');
        start_table($table_style2);
        $showdims = (($dim == 1 && $_POST['dim1'] == 0) || 
                ($dim == 2 && $_POST['dim1'] == 0 && $_POST['dim2'] == 0));
@@ -126,24 +132,26 @@ if (db_has_gl_accounts())
                $th = array(_("Period"), _("Amount"), _("Last Year"));
        table_header($th);      
        $year = $_POST['fyear'];
-       $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year";
+       if (get_post('update') == '') {
+               $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year";
 
-       $result = db_query($sql, "could not get current fiscal year");
+               $result = db_query($sql, "could not get current fiscal year");
 
-       $fyear = db_fetch($result);
-       $begin = sql2date($fyear['begin']);
-       $end = sql2date($fyear['end']);
-       hidden('begin', $begin);
-       hidden('end', $end);
+               $fyear = db_fetch($result);
+               $_POST['begin'] = sql2date($fyear['begin']);
+               $_POST['end'] = sql2date($fyear['end']);
+       }
+       hidden('begin');
+       hidden('end');
        $total = $btotal = $ltotal = 0;
-       for ($i = 0, $date_ = $begin; date1_greater_date2($end, $date_); $i++)
+       for ($i = 0, $date_ = $_POST['begin']; date1_greater_date2($_POST['end'], $date_); $i++)
        {
                start_row();
-               $_POST['amount'.$i] = number_format2(get_only_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0); 
+               if (get_post('update') == '')
+                       $_POST['amount'.$i] = number_format2(get_only_budget_trans_from_to(
+                               $date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0); 
                
                label_cell($date_);     
-               if (!isset($_POST['amount'.$i]))
-                       $_POST['amount'.$i] = '0';
                amount_cells(null, 'amount'.$i, null, 15, null, 0);
                if ($showdims)
                {
@@ -160,14 +168,16 @@ if (db_has_gl_accounts())
        }
        start_row();
        label_cell("<b>"._("Total")."</b>");
-       label_cell("<b>".number_format2($total, 0)."</b>", 'align=right');
+       label_cell(number_format2($total, 0), 'align=right style="font-weight:bold"', 'Total');
        if ($showdims)
                label_cell("<b>".number_format2($btotal, 0)."</b>", "nowrap align=right");
        label_cell("<b>".number_format2($ltotal, 0)."</b>", "nowrap align=right");
        end_row();
        end_table(1);
-       submit_center_first('add', _("Save"));
-       submit_center_last('delete', _("Delete"));
+       div_end();
+       submit_center_first('update', _("Update"), '', null);
+       submit('add', _("Save"), true, '', true);
+       submit_center_last('delete', _("Delete"), '', true);
 } 
 end_form();