Ajax additions.
[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 check_db_has_bank_trans_types(_("There are no bank transfer types defined in the system."));
23
24 //----------------------------------------------------------------------------------------
25
26 if (isset($_GET['AddedID'])) 
27 {
28         $trans_no = $_GET['AddedID'];
29         $trans_type = systypes::bank_transfer();
30
31         display_notification_centered( _("Transfer has been entered"));
32
33         display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL Journal Entries for this Transfer")));
34
35         hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Transfer"));
36
37         safeExit();
38 }
39
40 //----------------------------------------------------------------------------------------
41
42 function gl_payment_controls()
43 {
44         global $table_style2;
45         $home_currency = get_company_currency();
46
47         start_form(false, true);
48
49         start_table($table_style2, 5, 7);
50         echo "<tr><td valign=top>"; // outer table
51
52         echo "<table>";
53         bank_accounts_list_row(_("From Account:"), 'FromBankAccount', null, true);
54
55     bank_accounts_list_row(_("To Account:"), 'ToBankAccount', null, true);
56
57     date_row(_("Transfer Date:"), 'DatePaid');
58
59         $from_currency = get_bank_account_currency($_POST['FromBankAccount']);
60         $to_currency = get_bank_account_currency($_POST['ToBankAccount']);
61         if ($from_currency != "" && $to_currency != "" && $from_currency != $to_currency) 
62         {
63                 amount_row(_("Amount:"), 'amount', null, null, $from_currency);
64
65                 exchange_rate_display($from_currency, $to_currency, $_POST['DatePaid']);
66         } 
67         else 
68         {
69                 amount_row(_("Amount:"), 'amount');
70         }
71
72         echo "</table>";
73         echo "</td><td valign=top class='tableseparator'>"; // outer table
74         echo "<table>";
75
76         bank_trans_types_list_row(_("Transfer Type:"), 'TransferType', null);
77
78     ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_transfer()));
79
80     textarea_row(_("Memo:"), 'memo_', null, 40,4);
81
82         end_table(1);
83
84         echo "</td></tr>";
85         end_table(1); // outer table
86
87     submit_center('AddPayment',_("Enter Transfer"), true, '', true);
88
89         end_form();
90 }
91
92 //----------------------------------------------------------------------------------------
93
94 function check_valid_entries()
95 {
96         if (!is_date($_POST['DatePaid'])) 
97         {
98                 display_error(_("The entered date is invalid."));
99                 set_focus('DatePaid');
100                 return false;
101         }
102         if (!is_date_in_fiscalyear($_POST['DatePaid']))
103         {
104                 display_error(_("The entered date is not in fiscal year."));
105                 set_focus('DatePaid');
106                 return false;
107         }
108
109         if (!check_num('amount', 0)) 
110         {
111                 display_error(_("The entered amount is invalid or less than zero."));
112                 set_focus('amount');
113                 return false;
114         }
115
116         if (!references::is_valid($_POST['ref'])) 
117         {
118                 display_error(_("You must enter a reference."));
119                 set_focus('ref');
120                 return false;
121         }
122
123         if (!is_new_reference($_POST['ref'], systypes::bank_transfer())) 
124         {
125                 display_error(_("The entered reference is already in use."));
126                 set_focus('ref');
127                 return false;
128         }
129
130         if ($_POST['FromBankAccount'] == $_POST['ToBankAccount']) 
131         {
132                 display_error(_("The source and destination bank accouts cannot be the same."));
133                 set_focus('ToBankAccount');
134                 return false;
135         }
136
137     return true;
138 }
139
140 //----------------------------------------------------------------------------------------
141
142 function handle_add_deposit()
143 {
144         global $path_to_root;
145
146         $trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
147                 $_POST['DatePaid'], input_num('amount'),
148                 $_POST['TransferType'], $_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 ?>