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."));
39 set_focus('from_date');
42 if (!is_date($_POST['to_date']))
44 display_error( _("Invalid END date in fiscal year."));
48 if (date1_greater_date2($from, $_POST['to_date']))
50 display_error( _("BEGIN date bigger than END date."));
51 set_focus('from_date');
57 //---------------------------------------------------------------------------------------------
59 function handle_submit()
66 if (isset($selected_id))
68 update_fiscalyear($_POST['from_date'], $_POST['closed']);
72 add_fiscalyear($_POST['from_date'], $_POST['to_date'], $_POST['closed']);
78 //---------------------------------------------------------------------------------------------
80 function check_can_delete($todate)
84 // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
85 $from = date2sql($selected_id);
86 $to = date2sql($todate);
87 $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'";
88 $result = db_query($sql, "could not query gl_trans master");
89 $myrow = db_fetch_row($result);
92 display_error(_("Cannot delete this fiscal year because items have been created referring to it."));
99 //---------------------------------------------------------------------------------------------
101 function handle_delete($todate)
105 if (!check_can_delete($todate))
107 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
109 delete_fiscalyear($selected_id);
111 meta_forward($_SERVER['PHP_SELF']);
114 //---------------------------------------------------------------------------------------------
116 function display_fiscalyears()
120 $company_year = get_company_pref('f_year');
122 $result = get_all_fiscalyears();
124 start_table($table_style);
126 $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
130 while ($myrow=db_fetch($result))
132 if ($myrow['id'] == $company_year)
134 start_row("class='stockmankobg'");
137 alt_table_row_color($k);
139 $from = sql2date($myrow["begin"]);
140 $to = sql2date($myrow["end"]);
141 if ($myrow["closed"] == 0)
143 $closed_text = _("No");
147 $closed_text = _("Yes");
151 label_cell($closed_text);
152 edit_link_cell("selected_id=" . urlencode($from));
153 if ($myrow["id"] != $company_year)
154 delete_link_cell("selected_id=" . urlencode($from) . "&to_date=" . urlencode($to) . "&delete=1");
159 display_note(_("The marked fiscal year is the current fiscal year which cannot be deleted."), 0, 0, "class='currentfg'");
162 //---------------------------------------------------------------------------------------------
164 function display_fiscalyear_edit($selected_id)
166 global $table_style2;
169 start_table($table_style2);
173 $myrow = get_fiscalyear($selected_id);
175 $_POST['from_date'] = sql2date($myrow["begin"]);
176 $_POST['to_date'] = sql2date($myrow["end"]);
177 $_POST['closed'] = $myrow["closed"];
178 hidden('selected_id', $selected_id);
179 hidden('from_date', $_POST['from_date']);
180 hidden('to_date', $_POST['to_date']);
181 label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
182 label_row(_("Fiscal Year End:"), $_POST['to_date']);
186 date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001);
187 date_row(_("Fiscal Year End:"), 'to_date', '', null, 0, 0, 1001);
190 yesno_list_row(_("Is Closed:"), 'closed', null, "", "", false);
194 submit_add_or_update_center(!isset($selected_id));
199 //---------------------------------------------------------------------------------------------
201 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
205 meta_forward($_SERVER['PHP_SELF']);
209 //---------------------------------------------------------------------------------------------
211 if (isset($_GET['delete']))
213 handle_delete($_GET['to_date']);
216 //---------------------------------------------------------------------------------------------
218 display_fiscalyears();
220 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Fiscal Year"));
222 display_fiscalyear_edit($selected_id);
224 //---------------------------------------------------------------------------------------------