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 ***********************************************************************/
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/data_checks.inc");
20 include_once($path_to_root . "/gl/includes/gl_db.inc");
21 include_once($path_to_root . "/gl/includes/gl_ui.inc");
24 if ($use_popup_windows)
25 $js .= get_js_open_window(800, 500);
27 $js .= get_js_date_picker();
28 page(_("Transfer between Bank Accounts"), false, false, "", $js);
30 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
32 //----------------------------------------------------------------------------------------
34 if (isset($_GET['AddedID']))
36 $trans_no = $_GET['AddedID'];
37 $trans_type = systypes::bank_transfer();
39 display_notification_centered( _("Transfer has been entered"));
41 display_note(get_gl_view_str($trans_type, $trans_no, _("&View the GL Journal Entries for this Transfer")));
43 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter &Another Transfer"));
48 if (isset($_POST['_DatePaid_changed'])) {
49 $Ajax->activate('_ex_rate');
52 //----------------------------------------------------------------------------------------
54 function gl_payment_controls()
57 $home_currency = get_company_currency();
61 start_table($table_style2, 5, 7);
62 echo "<tr><td valign=top>"; // outer table
65 bank_accounts_list_row(_("From Account:"), 'FromBankAccount', null, true);
67 bank_accounts_list_row(_("To Account:"), 'ToBankAccount', null, true);
69 date_row(_("Transfer Date:"), 'DatePaid', '', null, 0, 0, 0, null, true);
71 $from_currency = get_bank_account_currency($_POST['FromBankAccount']);
72 $to_currency = get_bank_account_currency($_POST['ToBankAccount']);
73 if ($from_currency != "" && $to_currency != "" && $from_currency != $to_currency)
75 amount_row(_("Amount:"), 'amount', null, null, $from_currency);
77 exchange_rate_display($from_currency, $to_currency, $_POST['DatePaid']);
81 amount_row(_("Amount:"), 'amount');
85 echo "</td><td valign=top class='tableseparator'>"; // outer table
88 ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_transfer()));
90 textarea_row(_("Memo:"), 'memo_', null, 40,4);
95 end_table(1); // outer table
97 submit_center('AddPayment',_("Enter Transfer"), true, '', 'default');
102 //----------------------------------------------------------------------------------------
104 function check_valid_entries()
106 if (!is_date($_POST['DatePaid']))
108 display_error(_("The entered date is invalid."));
109 set_focus('DatePaid');
112 if (!is_date_in_fiscalyear($_POST['DatePaid']))
114 display_error(_("The entered date is not in fiscal year."));
115 set_focus('DatePaid');
119 if (!check_num('amount', 0))
121 display_error(_("The entered amount is invalid or less than zero."));
126 if (!references::is_valid($_POST['ref']))
128 display_error(_("You must enter a reference."));
133 if (!is_new_reference($_POST['ref'], systypes::bank_transfer()))
135 display_error(_("The entered reference is already in use."));
140 if ($_POST['FromBankAccount'] == $_POST['ToBankAccount'])
142 display_error(_("The source and destination bank accouts cannot be the same."));
143 set_focus('ToBankAccount');
150 //----------------------------------------------------------------------------------------
152 function handle_add_deposit()
154 $trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
155 $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_']);
157 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
160 //----------------------------------------------------------------------------------------
169 //----------------------------------------------------------------------------------------
171 if (isset($_POST['AddPayment']))
173 if (check_valid_entries() == true)
175 handle_add_deposit();
180 gl_payment_controls();