[0004904] Customer Credit Note: fixed invalid inventory GL postings for service items.
[fa-stable.git] / gl / manage / close_period.php
1 <?php
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
13 $page_security = 'SA_GLCLOSE';
14 $path_to_root = "../..";
15 include_once($path_to_root . "/includes/session.inc");
16
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/banking.inc");
20 include_once($path_to_root . "/admin/db/fiscalyears_db.inc");
21
22 $js = "";
23 if (user_use_date_picker())
24         $js .= get_js_date_picker();
25 page(_($help_context = "Closing GL Transactions"), false, false, "", $js);
26
27 //---------------------------------------------------------------------------------------------
28 function check_data()
29 {
30         global $SysPrefs;
31         
32         if (!is_date($_POST['date']) || date1_greater_date2($_POST['date'], Today()))
33         {
34                 display_error( _("The entered date is invalid."));
35                 set_focus('date');
36                 return false;
37         }
38         if (!is_date_in_fiscalyears($_POST['date'], false))
39         {
40                 display_error(_("Selected date is not in fiscal year or the year is closed."));
41                 set_focus('date');
42                 return false;
43         }
44         if (date1_greater_date2(sql2date(get_company_pref('gl_closing_date')), $_POST['date']))
45         {
46                 if (!$SysPrefs->allow_gl_reopen) {
47                         display_error(_("The entered date is earlier than date already selected as closing date."));
48                         set_focus('date');
49                         return false;
50                 } elseif (!user_check_access('SA_GLREOPEN')) {
51                         display_error(_("You are not allowed to reopen already closed transactions."));
52                         set_focus('date');
53                         return false;
54                 }
55         }
56         return true;
57 }
58
59 //---------------------------------------------------------------------------------------------
60
61 function handle_submit()
62 {
63         if (!check_data())
64                 return;
65
66         if (!close_transactions($_POST['date']))
67         {
68                 display_notification(
69                         sprintf( _("All transactions resulting in GL accounts changes up to %s has been closed for further edition."),
70                         sql2date(get_company_pref('gl_closing_date'))) );
71         }
72
73 }
74
75
76 //---------------------------------------------------------------------------------------------
77
78 function clear_data()
79 {
80         unset($_POST['date_']);
81 }
82
83 //---------------------------------------------------------------------------------------------
84
85 if (get_post('submit'))
86         handle_submit();
87 else
88         display_note(_("Using this feature you can prevent entering new transactions <br>
89         and disable edition of already entered transactions up to specified date.<br>
90         Only transactions which can generate GL postings are subject to the constraint."));
91
92 //---------------------------------------------------------------------------------------------
93
94 br(1);
95 start_form();
96 start_table(TABLESTYLE2);
97 if (!isset($_POST['date'])) {
98         $cdate = sql2date(get_company_pref('gl_closing_date'));
99         $_POST['date'] = $cdate ;// ? end_month(add_months($cdate, 1)) : Today();
100 }
101 date_row(_("End date of closing period:"), 'date');
102 end_table(1);
103
104 submit_center('submit', _("Close Transactions"), true, false);
105 end_form();
106
107 end_page();
108