From 8140ff095ab46a381e99fc301eca5b80af5340b3 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 1 Jul 2008 21:17:21 +0000 Subject: [PATCH] Added client side calculations for budget --- gl/gl_budget.php | 40 +++++++++++++++++++++++++--------------- js/budget.js | 27 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 js/budget.js diff --git a/gl/gl_budget.php b/gl/gl_budget.php index b1a7cae5..b503a61c 100644 --- a/gl/gl_budget.php +++ b/gl/gl_budget.php @@ -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(""._("Total").""); - label_cell("".number_format2($total, 0)."", 'align=right'); + label_cell(number_format2($total, 0), 'align=right style="font-weight:bold"', 'Total'); if ($showdims) label_cell("".number_format2($btotal, 0)."", "nowrap align=right"); label_cell("".number_format2($ltotal, 0)."", "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(); diff --git a/js/budget.js b/js/budget.js new file mode 100644 index 00000000..92902323 --- /dev/null +++ b/js/budget.js @@ -0,0 +1,27 @@ +function focus_budget(i) { + save_focus(i); + i.setAttribute('_last', get_amount(i.name)); +} + +function blur_budget(i) { + var amount = get_amount(i.name); + var total = get_amount('Total', 1); + + if(amount<0) amount = 0; + price_format(i.name, amount, 0); + price_format('Total', total+amount-i.getAttribute('_last'), 0, 1, 1); +} + + +var budget_calc = { + '.amount': function(e) { + e.onblur = function() { + blur_budget(this); + }; + e.onfocus = function() { + focus_budget(this); + }; + } +} + +Behaviour.register(budget_calc); -- 2.30.2