$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");
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');
//-------------------------------------------------------------------------------------
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));
$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)
{
}
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();
--- /dev/null
+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);