87e82c71daed0f1e7f6686fabe59091db54794e8
[fa-stable.git] / gl / bank_transfer.php
1 <?php
2
3 $path_to_root="..";
4 $page_security = 5;
5
6 include_once($path_to_root . "/includes/session.inc");
7
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/data_checks.inc");
10
11 include_once($path_to_root . "/gl/includes/gl_db.inc");
12 include_once($path_to_root . "/gl/includes/gl_ui.inc");
13
14 $js = "";
15 if ($use_popup_windows)
16         $js .= get_js_open_window(800, 500);
17 if ($use_date_picker)
18         $js .= get_js_date_picker();
19 page(_("Transfer between Bank Accounts"), false, false, "", $js);
20
21 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
22
23 //----------------------------------------------------------------------------------------
24
25 if (isset($_GET['AddedID'])) 
26 {
27         $trans_no = $_GET['AddedID'];
28         $trans_type = systypes::bank_transfer();
29
30         display_notification_centered( _("Transfer has been entered"));
31
32         display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Journal Entries for this Transfer")));
33
34         hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter &Another Transfer"));
35
36         safeExit();
37 }
38
39 if (isset($_POST['_DatePaid_changed'])) {
40         $Ajax->activate('_ex_rate');
41 }
42
43 //----------------------------------------------------------------------------------------
44
45 function gl_payment_controls()
46 {
47         global $table_style2;
48         $home_currency = get_company_currency();
49
50         start_form(false, true);
51
52         start_table($table_style2, 5, 7);
53         echo "<tr><td valign=top>"; // outer table
54
55         echo "<table>";
56         bank_accounts_list_row(_("From Account:"), 'FromBankAccount', null, true);
57
58     bank_accounts_list_row(_("To Account:"), 'ToBankAccount', null, true);
59
60     date_row(_("Transfer Date:"), 'DatePaid', '', null, 0, 0, 0, null, true);
61
62         $from_currency = get_bank_account_currency($_POST['FromBankAccount']);
63         $to_currency = get_bank_account_currency($_POST['ToBankAccount']);
64         if ($from_currency != "" && $to_currency != "" && $from_currency != $to_currency) 
65         {
66                 amount_row(_("Amount:"), 'amount', null, null, $from_currency);
67
68                 exchange_rate_display($from_currency, $to_currency, $_POST['DatePaid']);
69         } 
70         else 
71         {
72                 amount_row(_("Amount:"), 'amount');
73         }
74
75         echo "</table>";
76         echo "</td><td valign=top class='tableseparator'>"; // outer table
77         echo "<table>";
78
79     ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_transfer()));
80
81     textarea_row(_("Memo:"), 'memo_', null, 40,4);
82
83         end_table(1);
84
85         echo "</td></tr>";
86         end_table(1); // outer table
87
88     submit_center('AddPayment',_("Enter Transfer"), true, '', true);
89
90         end_form();
91 }
92
93 //----------------------------------------------------------------------------------------
94
95 function check_valid_entries()
96 {
97         if (!is_date($_POST['DatePaid'])) 
98         {
99                 display_error(_("The entered date is invalid."));
100                 set_focus('DatePaid');
101                 return false;
102         }
103         if (!is_date_in_fiscalyear($_POST['DatePaid']))
104         {
105                 display_error(_("The entered date is not in fiscal year."));
106                 set_focus('DatePaid');
107                 return false;
108         }
109
110         if (!check_num('amount', 0)) 
111         {
112                 display_error(_("The entered amount is invalid or less than zero."));
113                 set_focus('amount');
114                 return false;
115         }
116
117         if (!references::is_valid($_POST['ref'])) 
118         {
119                 display_error(_("You must enter a reference."));
120                 set_focus('ref');
121                 return false;
122         }
123
124         if (!is_new_reference($_POST['ref'], systypes::bank_transfer())) 
125         {
126                 display_error(_("The entered reference is already in use."));
127                 set_focus('ref');
128                 return false;
129         }
130
131         if ($_POST['FromBankAccount'] == $_POST['ToBankAccount']) 
132         {
133                 display_error(_("The source and destination bank accouts cannot be the same."));
134                 set_focus('ToBankAccount');
135                 return false;
136         }
137
138     return true;
139 }
140
141 //----------------------------------------------------------------------------------------
142
143 function handle_add_deposit()
144 {
145         global $path_to_root;
146
147         $trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
148                 $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_']);
149
150         meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
151 }
152
153 //----------------------------------------------------------------------------------------
154
155 function safeExit()
156 {
157         global $path_to_root;
158         echo "<br><br>";
159         end_page();
160         exit;
161 }
162
163 //----------------------------------------------------------------------------------------
164
165 if (isset($_POST['AddPayment']))
166 {
167         if (check_valid_entries() == true) 
168         {
169                 handle_add_deposit();
170                 safeExit();
171         }
172 }
173
174 gl_payment_controls();
175
176 end_page();
177 ?>