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 simple_page_mode(true);
16 //---------------------------------------------------------------------------------------------
20 if (!is_date($_POST['from_date']))
22 display_error( _("Invalid BEGIN date in fiscal year."));
23 set_focus('from_date');
26 if (!is_date($_POST['to_date']))
28 display_error( _("Invalid END date in fiscal year."));
32 if (date1_greater_date2($_POST['from_date'], $_POST['to_date']))
34 display_error( _("BEGIN date bigger than END date."));
35 set_focus('from_date');
41 //---------------------------------------------------------------------------------------------
43 function handle_submit()
45 global $selected_id, $Mode;
50 if ($selected_id != -1)
52 update_fiscalyear($_POST['from_date'], $_POST['closed']);
53 display_notification(_('Selected fiscal year has been updated'));
57 add_fiscalyear($_POST['from_date'], $_POST['to_date'], $_POST['closed']);
58 display_notification(_('New fiscal year has been added'));
63 //---------------------------------------------------------------------------------------------
65 function check_can_delete($selected_id)
67 $myrow = get_fiscalyear($selected_id);
68 // PREVENT DELETES IF DEPENDENT RECORDS IN gl_trans
69 $from = $myrow['begin'];
71 $sql= "SELECT COUNT(*) FROM ".TB_PREF."gl_trans WHERE tran_date >= '$from' AND tran_date <= '$to'";
72 $result = db_query($sql, "could not query gl_trans master");
73 $myrow = db_fetch_row($result);
76 display_error(_("Cannot delete this fiscal year because items have been created referring to it."));
83 //---------------------------------------------------------------------------------------------
85 function handle_delete()
87 global $selected_id, $Mode;
89 if (!check_can_delete($selected_id))
91 //only delete if used in neither customer or supplier, comp prefs, bank trans accounts
93 delete_fiscalyear($selected_id);
94 display_notification(_('Selected fiscal year has been deleted'));
98 //---------------------------------------------------------------------------------------------
100 function display_fiscalyears()
104 $company_year = get_company_pref('f_year');
106 $result = get_all_fiscalyears();
108 start_table($table_style);
110 $th = array(_("Fiscal Year Begin"), _("Fiscal Year End"), _("Closed"), "", "");
114 while ($myrow=db_fetch($result))
116 if ($myrow['id'] == $company_year)
118 start_row("class='stockmankobg'");
121 alt_table_row_color($k);
123 $from = sql2date($myrow["begin"]);
124 $to = sql2date($myrow["end"]);
125 if ($myrow["closed"] == 0)
127 $closed_text = _("No");
131 $closed_text = _("Yes");
135 label_cell($closed_text);
136 edit_button_cell("Edit".$myrow['id'], _("Edit"));
137 if ($myrow["id"] != $company_year)
138 edit_button_cell("Delete".$myrow['id'], _("Delete"));
144 display_note(_("The marked fiscal year is the current fiscal year which cannot be deleted."), 0, 0, "class='currentfg'");
147 //---------------------------------------------------------------------------------------------
149 function display_fiscalyear_edit($selected_id)
151 global $table_style2, $Mode;
154 start_table($table_style2);
156 if ($selected_id != -1)
160 $myrow = get_fiscalyear($selected_id);
162 $_POST['from_date'] = sql2date($myrow["begin"]);
163 $_POST['to_date'] = sql2date($myrow["end"]);
164 $_POST['closed'] = $myrow["closed"];
168 label_row(_("Fiscal Year Begin:"), $_POST['from_date']);
169 label_row(_("Fiscal Year End:"), $_POST['to_date']);
173 date_row(_("Fiscal Year Begin:"), 'from_date', '', null, 0, 0, 1001);
174 date_row(_("Fiscal Year End:"), 'to_date', '', null, 0, 0, 1001);
176 hidden('selected_id', $selected_id);
178 yesno_list_row(_("Is Closed:"), 'closed', null, "", "", false);
182 submit_add_or_update_center($selected_id == -1, '', true);
187 //---------------------------------------------------------------------------------------------
189 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
194 //---------------------------------------------------------------------------------------------
196 if ($Mode == 'Delete')
199 handle_delete($selected_id);
202 if ($Mode == 'RESET')
206 //---------------------------------------------------------------------------------------------
208 display_fiscalyears();
212 display_fiscalyear_edit($selected_id);
214 //---------------------------------------------------------------------------------------------