[0005239] Revaluation of Currency Accounts: removed sparse reference field, fixed...
[fa-stable.git] / gl / manage / revaluate_currencies.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 $page_security = 'SA_EXCHANGERATE';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/ui.inc");
18 include_once($path_to_root . "/includes/banking.inc");
19
20 $js = "";
21 if (user_use_date_picker())
22         $js .= get_js_date_picker();
23 page(_($help_context = "Revaluation of Currency Accounts"), false, false, "", $js);
24
25 if (isset($_GET['BA'])) 
26 {
27         $BA = $_GET['BA'];
28         $JE = $_GET['JE'];
29
30         if ($BA != 0 || $JE !=0)
31         {
32                 display_notification_centered(sprintf(_("%d Journal Entries for Bank Accounts have been added"), $BA));
33                 display_notification_centered(sprintf(_("%d Journal Entries for AR/AP accounts have been added"), $JE));
34         }
35         else
36                 display_notification_centered( _("No revaluation was needed."));
37 }
38
39
40 //---------------------------------------------------------------------------------------------
41 function check_data()
42 {
43         if (!is_date($_POST['date']))
44         {
45                 display_error( _("The entered date is invalid."));
46                 set_focus('date');
47                 return false;
48         }
49         if (!is_date_in_fiscalyear($_POST['date']))
50         {
51                 display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
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         $trans = add_exchange_variation_all($_POST['date'], $_POST['memo_']);
67
68         meta_forward($_SERVER['PHP_SELF'], "BA=".$trans[0]."&JE=".$trans[1]);
69         //clear_data();
70 }
71
72
73 //---------------------------------------------------------------------------------------------
74
75 function display_reval()
76 {
77         start_form();
78         start_table(TABLESTYLE2);
79
80         if (!isset($_POST['date']))
81                 $_POST['date'] = Today();
82     date_row(_("Date for Revaluation:"), 'date', '', null, 0, 0, 0, null, true);
83     textarea_row(_("Memo:"), 'memo_', null, 40,4);
84         end_table(1);
85
86         submit_center('submit', _("Revaluate Currencies"), true, false);
87         end_form();
88 }
89
90 //---------------------------------------------------------------------------------------------
91
92 function clear_data()
93 {
94         unset($_POST['date_']);
95         unset($_POST['memo_']);
96 }
97
98 //---------------------------------------------------------------------------------------------
99
100 if (get_post('submit'))
101         handle_submit();
102
103 //---------------------------------------------------------------------------------------------
104
105 display_reval();
106
107 end_page();
108