5 include_once($path_to_root . "/includes/session.inc");
7 page(_("Fiscal Years"));
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/admin/db/company_db.inc");
11 include_once($path_to_root . "/includes/ui.inc");
13 //---------------------------------------------------------------------------------------------
15 if (isset($_GET['selected_id']))
17 $selected_id = $_GET['selected_id'];
19 elseif (isset($_POST['selected_id']))
21 $selected_id = $_POST['selected_id'];
26 //---------------------------------------------------------------------------------------------
30 if (!isset($selected_id))
31 $from = $_POST['from_date'];
36 display_error( _("Invalid BEGIN date in fiscal year."));
39 if (!is_date($_POST['to_date']))
41 display_error( _("Invalid END date in fiscal year."));
44 if (date1_greater_date2($from, $_POST['to_date']))
46 display_error( _("BEGIN date bigger than END date."));
52 //---------------------------------------------------------------------------------------------
54 function handle_submit()
61 if (isset($selected_id))
63 update_fiscalyear($_POST['from_date'], $_POST['closed']);
67 add_fiscalyear($_POST['from_date'], $_POST['to_date'], $_POST['closed']);
73 //---------------------------------------------------------------------------------------------
75 function check_can_delete($todate)
79 // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
80 $from = date2sql($selected_id);
81 $to = date2sql($todate);
82 $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'";
83 $result = db_query($sql, "could not query gl_trans master");
84 $myrow = db_fetch_row($result);
87 display_error(_("Cannot delete this fiscal year because items have been created referring to it."));
94 //---------------------------------------------------------------------------------------------
96 function handle_delete($todate)
100 if (!check_can_delete($todate))
102 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
104 delete_fiscalyear($selected_id);
106 meta_forward($_SERVER['PHP_SELF']);
109 //---------------------------------------------------------------------------------------------
111 function display_fiscalyears()
115 $company_year = get_company_pref('f_year');
117 $result = get_all_fiscalyears();
119 start_table($table_style);
121 $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
125 while ($myrow=db_fetch($result))
127 if ($myrow['id'] == $company_year)
129 start_row("class='stockmankobg'");
132 alt_table_row_color($k);
134 $from = sql2date($myrow["begin"]);
135 $to = sql2date($myrow["end"]);
136 if ($myrow["closed"] == 0)
138 $closed_text = _("No");
142 $closed_text = _("Yes");
146 label_cell($closed_text);
147 edit_link_cell("selected_id=" . urlencode($from));
148 if ($myrow["id"] != $company_year)
149 delete_link_cell("selected_id=" . urlencode($from) . "&to_date=" . urlencode($to) . "&delete=1");
154 display_note(_("The marked fiscal year is the current fiscal year which cannot be deleted."), 0, 0, "class='currentfg'");
157 //---------------------------------------------------------------------------------------------
159 function display_fiscalyear_edit($selected_id)
161 global $table_style2;
164 start_table($table_style2);
168 $myrow = get_fiscalyear($selected_id);
170 $_POST['from_date'] = sql2date($myrow["begin"]);
171 $_POST['to_date'] = sql2date($myrow["end"]);
172 $_POST['closed'] = $myrow["closed"];
173 hidden('selected_id', $selected_id);
174 hidden('from_date', $_POST['from_date']);
175 hidden('to_date', $_POST['to_date']);
176 label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
177 label_row(_("Fiscal Year End:"), $_POST['to_date']);
181 text_row(_("Fiscal Year Begin:"), 'from_date', null, 15, 10);
182 text_row(_("Fiscal Year End:"), 'to_date', null, 15, 10);
185 yesno_list_row(_("Is Closed:"), 'closed', null, "", "", false);
189 submit_add_or_update_center(!isset($selected_id));
194 //---------------------------------------------------------------------------------------------
196 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
200 meta_forward($_SERVER['PHP_SELF']);
204 //---------------------------------------------------------------------------------------------
206 if (isset($_GET['delete']))
208 handle_delete($_GET['to_date']);
211 //---------------------------------------------------------------------------------------------
213 display_fiscalyears();
215 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter a New Fiscal Year"));
217 display_fiscalyear_edit($selected_id);
219 //---------------------------------------------------------------------------------------------