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