5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/admin/db/company_db.inc");
9 include_once($path_to_root . "/includes/ui.inc");
12 $js .= get_js_date_picker();
13 page(_("Fiscal Years"), false, false, "", $js);
15 //---------------------------------------------------------------------------------------------
17 if (isset($_GET['selected_id']))
19 $selected_id = $_GET['selected_id'];
21 elseif (isset($_POST['selected_id']))
23 $selected_id = $_POST['selected_id'];
28 //---------------------------------------------------------------------------------------------
32 if (!isset($selected_id))
33 $from = $_POST['from_date'];
38 display_error( _("Invalid BEGIN date in fiscal year."));
41 if (!is_date($_POST['to_date']))
43 display_error( _("Invalid END date in fiscal year."));
46 if (date1_greater_date2($from, $_POST['to_date']))
48 display_error( _("BEGIN date bigger than END date."));
54 //---------------------------------------------------------------------------------------------
56 function handle_submit()
63 if (isset($selected_id))
65 update_fiscalyear($_POST['from_date'], $_POST['closed']);
69 add_fiscalyear($_POST['from_date'], $_POST['to_date'], $_POST['closed']);
75 //---------------------------------------------------------------------------------------------
77 function check_can_delete($todate)
81 // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
82 $from = date2sql($selected_id);
83 $to = date2sql($todate);
84 $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'";
85 $result = db_query($sql, "could not query gl_trans master");
86 $myrow = db_fetch_row($result);
89 display_error(_("Cannot delete this fiscal year because items have been created referring to it."));
96 //---------------------------------------------------------------------------------------------
98 function handle_delete($todate)
102 if (!check_can_delete($todate))
104 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
106 delete_fiscalyear($selected_id);
108 meta_forward($_SERVER['PHP_SELF']);
111 //---------------------------------------------------------------------------------------------
113 function display_fiscalyears()
117 $company_year = get_company_pref('f_year');
119 $result = get_all_fiscalyears();
121 start_table($table_style);
123 $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
127 while ($myrow=db_fetch($result))
129 if ($myrow['id'] == $company_year)
131 start_row("class='stockmankobg'");
134 alt_table_row_color($k);
136 $from = sql2date($myrow["begin"]);
137 $to = sql2date($myrow["end"]);
138 if ($myrow["closed"] == 0)
140 $closed_text = _("No");
144 $closed_text = _("Yes");
148 label_cell($closed_text);
149 edit_link_cell("selected_id=" . urlencode($from));
150 if ($myrow["id"] != $company_year)
151 delete_link_cell("selected_id=" . urlencode($from) . "&to_date=" . urlencode($to) . "&delete=1");
156 display_note(_("The marked fiscal year is the current fiscal year which cannot be deleted."), 0, 0, "class='currentfg'");
159 //---------------------------------------------------------------------------------------------
161 function display_fiscalyear_edit($selected_id)
163 global $table_style2;
166 start_table($table_style2);
170 $myrow = get_fiscalyear($selected_id);
172 $_POST['from_date'] = sql2date($myrow["begin"]);
173 $_POST['to_date'] = sql2date($myrow["end"]);
174 $_POST['closed'] = $myrow["closed"];
175 hidden('selected_id', $selected_id);
176 hidden('from_date', $_POST['from_date']);
177 hidden('to_date', $_POST['to_date']);
178 label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
179 label_row(_("Fiscal Year End:"), $_POST['to_date']);
183 date_row(_("Fiscal Year Begin:"), 'from_date', null, 0, 0, 1001);
184 date_row(_("Fiscal Year End:"), 'to_date', null, 0, 0, 1001);
187 yesno_list_row(_("Is Closed:"), 'closed', null, "", "", false);
191 submit_add_or_update_center(!isset($selected_id));
196 //---------------------------------------------------------------------------------------------
198 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
202 meta_forward($_SERVER['PHP_SELF']);
206 //---------------------------------------------------------------------------------------------
208 if (isset($_GET['delete']))
210 handle_delete($_GET['to_date']);
213 //---------------------------------------------------------------------------------------------
215 display_fiscalyears();
217 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Fiscal Year"));
219 display_fiscalyear_edit($selected_id);
221 //---------------------------------------------------------------------------------------------