1dae7eeda932ef74c57889866f7b394691ff2f4c
[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['AddedID'])) 
26 {
27         $trans_no = $_GET['AddedID'];
28         $JE = $_GET['JE'];
29         $trans_type = ST_JOURNAL;
30
31         if ($trans_no == 0)
32                 display_notification_centered( _("No Revaluation was needed"));
33         else
34         {
35                 display_notification_centered( _("Transfer has been entered"));
36
37                 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Journal Entries for this Transfer")));
38         }
39         if ($JE > 0)
40                 display_notification_centered(sprintf(_("%d Journal Entries for AR/AP accounts have been added"), $JE));
41
42         //display_footer_exit();
43 }
44
45
46 //---------------------------------------------------------------------------------------------
47 function check_data()
48 {
49         if (!is_date($_POST['date']))
50         {
51                 display_error( _("The entered date is invalid."));
52                 set_focus('date');
53                 return false;
54         }
55         if (!is_date_in_fiscalyear($_POST['date']))
56         {
57                 display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
58                 set_focus('date');
59                 return false;
60         }
61         if (!check_reference($_POST['ref'], ST_JOURNAL))
62         {
63                 set_focus('ref');
64                 return false;
65         }
66
67         return true;
68 }
69
70 //---------------------------------------------------------------------------------------------
71
72 function handle_submit()
73 {
74         if (!check_data())
75                 return;
76
77         $trans = add_exchange_variation_all($_POST['date'], $_POST['ref'], $_POST['memo_']);
78
79         meta_forward($_SERVER['PHP_SELF'], "AddedID=".$trans[0]."&JE=".$trans[1]);
80         //clear_data();
81 }
82
83
84 //---------------------------------------------------------------------------------------------
85
86 function display_reval()
87 {
88         global $Refs;
89         start_form();
90         start_table(TABLESTYLE2);
91
92         if (!isset($_POST['date']))
93                 $_POST['date'] = Today();
94     date_row(_("Date for Revaluation:"), 'date', '', null, 0, 0, 0, null, true);
95     ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_JOURNAL, null, $_POST['date']), false, ST_JOURNAL);
96     textarea_row(_("Memo:"), 'memo_', null, 40,4);
97         end_table(1);
98
99         submit_center('submit', _("Revaluate Currencies"), true, false);
100         end_form();
101 }
102
103 //---------------------------------------------------------------------------------------------
104
105 function clear_data()
106 {
107         unset($_POST['date_']);
108         unset($_POST['memo_']);
109 }
110
111 //---------------------------------------------------------------------------------------------
112
113 if (get_post('submit'))
114         handle_submit();
115
116 //---------------------------------------------------------------------------------------------
117
118 display_reval();
119
120 end_page();
121