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