5 include_once($path_to_root . "/includes/session.inc");
7 include_once($path_to_root . "/includes/date_functions.inc");
8 include_once($path_to_root . "/includes/ui.inc");
9 include_once($path_to_root . "/includes/banking.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
14 if ($use_popup_windows)
15 $js .= get_js_open_window(900, 500);
17 $js .= get_js_date_picker();
18 page(_("Supplier Payment Entry"), false, false, "", $js);
21 if (isset($_GET['supplier_id']))
23 $_POST['supplier_id'] = $_GET['supplier_id'];
26 //----------------------------------------------------------------------------------------
28 check_db_has_suppliers(_("There are no suppliers defined in the system."));
30 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
32 check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
34 //----------------------------------------------------------------------------------------
36 if (isset($_GET['AddedID']))
38 $payment_id = $_GET['AddedID'];
40 display_notification_centered( _("Payment has been sucessfully entered"));
42 display_note(get_gl_view_str(22, $payment_id, _("View the GL Journal Entries for this Payment")));
45 hyperlink_params($path_to_root . "/purchasing/allocations/supplier_allocate.php", _("Allocate this Payment"), "trans_no=$payment_id&trans_type=22");
48 hyperlink_params($_SERVER['PHP_SELF'], _("Enter another supplier payment"), "supplier_id=" . $_POST['supplier_id']);
50 echo "</center><br><br>";
56 //----------------------------------------------------------------------------------------
58 function display_controls()
61 start_form(false, true);
63 if (!isset($_POST['supplier_id']))
64 $_POST['supplier_id'] = get_global_supplier(false);
65 if (!isset($_POST['DatePaid']))
67 $_POST['DatePaid'] = Today();
68 if (!is_date_in_fiscalyear($_POST['DatePaid']))
69 $_POST['DatePaid'] = end_fiscalyear();
71 start_table($table_style2, 5, 7);
72 echo "<tr><td valign=top>"; // outer table
76 bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
78 amount_row(_("Amount of Payment:"), 'amount');
79 amount_row(_("Amount of Discount:"), 'discount');
81 date_row(_("Date Paid") . ":", 'DatePaid');
84 echo "</td><td valign=top class='tableseparator'>"; // outer table
87 supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
89 set_global_supplier($_POST['supplier_id']);
91 $supplier_currency = get_supplier_currency($_POST['supplier_id']);
92 $bank_currency = get_bank_account_currency($_POST['bank_account']);
93 if ($bank_currency != $supplier_currency)
95 exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
98 bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
100 ref_row(_("Reference:"), 'ref', references::get_next(22));
102 text_row(_("Memo:"), 'memo_', null, 52,50);
107 end_table(1); // outer table
109 submit_center('ProcessSuppPayment',_("Enter Payment"));
111 if ($bank_currency != $supplier_currency)
113 display_note(_("The amount and discount are in the bank account's currency."), 2, 0);
119 //----------------------------------------------------------------------------------------
121 function check_inputs()
123 if ($_POST['amount'] == "")
125 $_POST['amount'] = 0;
128 if (!is_numeric($_POST['amount']) || $_POST['amount'] < 0)
130 display_error(_("The entered amount is invalid or less than zero."));
134 if ($_POST['discount'] == "")
136 $_POST['discount'] = 0;
139 if (!is_numeric($_POST['discount']) OR $_POST['discount'] < 0)
141 display_error(_("The entered discount is invalid or less than zero."));
145 if ($_POST['amount'] - $_POST['discount'] <= 0)
147 display_error(_("The total of the amount and the discount negative. Please enter positive values."));
151 if (!is_date($_POST['DatePaid']))
153 display_error(_("The entered date is invalid."));
156 elseif (!is_date_in_fiscalyear($_POST['DatePaid']))
158 display_error(_("The entered date is not in fiscal year."));
161 if (!references::is_valid($_POST['ref']))
163 display_error(_("You must enter a reference."));
167 if (!is_new_reference($_POST['ref'], 22))
169 display_error(_("The entered reference is already in use."));
176 //----------------------------------------------------------------------------------------
178 function handle_add_payment()
180 $payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
181 $_POST['PaymentType'], $_POST['bank_account'],
182 $_POST['amount'], $_POST['discount'], $_POST['ref'], $_POST['memo_']);
184 //unset($_POST['supplier_id']);
185 unset($_POST['bank_account']);
186 unset($_POST['DatePaid']);
187 unset($_POST['PaymentType']);
188 unset($_POST['currency']);
189 unset($_POST['memo_']);
190 unset($_POST['amount']);
191 unset($_POST['discount']);
192 unset($_POST['ProcessSuppPayment']);
194 meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_id&supplier_id=".$_POST['supplier_id']);
197 //----------------------------------------------------------------------------------------
199 if (isset($_POST['ProcessSuppPayment']))
201 /*First off check for valid inputs */
202 if (check_inputs() == true)
204 handle_add_payment();