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