2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_BUDGETENTRY';
14 include_once($path_to_root . "/includes/session.inc");
16 add_js_file('budget.js');
18 page(_($help_context = "Budget Entry"));
20 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22 include_once($path_to_root . "/includes/data_checks.inc");
23 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
26 check_db_has_gl_account_groups(_("There are no account groups defined. Please define at least one account group before entering accounts."));
28 //-------------------------------------------------------------------------------------
30 if (isset($_POST['add']) || isset($_POST['delete']))
34 for ($i = 0, $da = $_POST['begin']; date1_greater_date2($_POST['end'], $da); $i++)
36 if (isset($_POST['add']))
37 add_update_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2'], input_num('amount'.$i));
39 delete_gl_budget_trans($da, $_POST['account'], $_POST['dim1'], $_POST['dim2']);
40 $da = add_months($da, 1);
44 if (isset($_POST['add']))
45 display_notification_centered(_("The Budget has been saved."));
47 display_notification_centered(_("The Budget has been deleted."));
49 $Ajax->activate('budget_tbl');
51 if (isset($_POST['submit']) || isset($_POST['update']))
52 $Ajax->activate('budget_tbl');
54 //-------------------------------------------------------------------------------------
58 if (db_has_gl_accounts())
60 $dim = get_company_pref('use_dimension');
61 start_table(TABLESTYLE2);
62 fiscalyears_list_row(_("Fiscal Year:"), 'fyear', null);
63 gl_all_accounts_list_row(_("Account Code:"), 'account', null);
64 if (!isset($_POST['dim1']))
66 if (!isset($_POST['dim2']))
70 dimensions_list_row(_("Dimension")." 1", 'dim1', $_POST['dim1'], true, null, false, 1);
71 dimensions_list_row(_("Dimension")." 2", 'dim2', $_POST['dim2'], true, null, false, 2);
75 dimensions_list_row(_("Dimension"), 'dim1', $_POST['dim1'], true, null, false, 1);
83 submit_row('submit', _("Get"), true, '', '', true);
85 div_start('budget_tbl');
86 start_table(TABLESTYLE2);
87 $showdims = (($dim == 1 && $_POST['dim1'] == 0) ||
88 ($dim == 2 && $_POST['dim1'] == 0 && $_POST['dim2'] == 0));
90 $th = array(_("Period"), _("Amount"), _("Dim. incl."), _("Last Year"));
92 $th = array(_("Period"), _("Amount"), _("Last Year"));
94 $year = $_POST['fyear'];
95 if (get_post('update') == '') {
96 $fyear = get_fiscalyear($year);
97 $_POST['begin'] = sql2date($fyear['begin']);
98 $_POST['end'] = sql2date($fyear['end']);
102 $total = $btotal = $ltotal = 0;
103 for ($i = 0, $date_ = $_POST['begin']; date1_greater_date2($_POST['end'], $date_); $i++)
106 if (get_post('update') == '')
107 $_POST['amount'.$i] = number_format2(get_only_budget_trans_from_to(
108 $date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0);
111 amount_cells(null, 'amount'.$i, null, 15, null, 0);
114 $d = get_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']);
115 label_cell(number_format2($d, 0), "nowrap align=right");
118 $lamount = get_gl_trans_from_to(add_years($date_, -1), add_years(end_month($date_), -1), $_POST['account'], $_POST['dim1'], $_POST['dim2']);
119 $total += input_num('amount'.$i);
121 label_cell(number_format2($lamount, 0), "nowrap align=right");
122 $date_ = add_months($date_, 1);
126 label_cell("<b>"._("Total")."</b>");
127 label_cell(number_format2($total, 0), 'align=right style="font-weight:bold"', 'Total');
129 label_cell("<b>".number_format2($btotal, 0)."</b>", "nowrap align=right");
130 label_cell("<b>".number_format2($ltotal, 0)."</b>", "nowrap align=right");
134 submit_center_first('update', _("Update"), '', null);
135 submit('add', _("Save"), true, '', 'default');
136 submit_center_last('delete', _("Delete"), '', true);