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")));
44 hyperlink_params($path_to_root . "/purchasing/allocations/supplier_allocate.php", _("Allocate this Payment"), "trans_no=$payment_id&trans_type=22");
46 hyperlink_params($_SERVER['PHP_SELF'], _("Enter another supplier payment"), "supplier_id=" . $_POST['supplier_id']);
48 display_footer_exit();
51 //----------------------------------------------------------------------------------------
53 function display_controls()
56 start_form(false, true);
58 if (!isset($_POST['supplier_id']))
59 $_POST['supplier_id'] = get_global_supplier(false);
60 if (!isset($_POST['DatePaid']))
62 $_POST['DatePaid'] = Today();
63 if (!is_date_in_fiscalyear($_POST['DatePaid']))
64 $_POST['DatePaid'] = end_fiscalyear();
66 start_table($table_style2, 5, 7);
67 echo "<tr><td valign=top>"; // outer table
71 bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
73 amount_row(_("Amount of Payment:"), 'amount');
74 amount_row(_("Amount of Discount:"), 'discount');
76 date_row(_("Date Paid") . ":", 'DatePaid');
79 echo "</td><td valign=top class='tableseparator'>"; // outer table
82 supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
84 set_global_supplier($_POST['supplier_id']);
86 $supplier_currency = get_supplier_currency($_POST['supplier_id']);
87 $bank_currency = get_bank_account_currency($_POST['bank_account']);
88 if ($bank_currency != $supplier_currency)
90 exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
93 bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
95 ref_row(_("Reference:"), 'ref', '', references::get_next(22));
97 text_row(_("Memo:"), 'memo_', null, 52,50);
102 end_table(1); // outer table
104 submit_center('ProcessSuppPayment',_("Enter Payment"), true, '', true);
106 if ($bank_currency != $supplier_currency)
108 display_note(_("The amount and discount are in the bank account's currency."), 2, 0);
114 //----------------------------------------------------------------------------------------
116 function check_inputs()
118 if ($_POST['amount'] == "")
120 $_POST['amount'] = price_format(0);
123 if (!check_num('amount', 0))
125 display_error(_("The entered amount is invalid or less than zero."));
130 if ($_POST['discount'] == "")
132 $_POST['discount'] = 0;
135 if (!check_num('discount', 0))
137 display_error(_("The entered discount is invalid or less than zero."));
142 if (input_num('amount') - input_num('discount') <= 0)
144 display_error(_("The total of the amount and the discount negative. Please enter positive values."));
149 if (!is_date($_POST['DatePaid']))
151 display_error(_("The entered date is invalid."));
152 set_focus('DatePaid');
155 elseif (!is_date_in_fiscalyear($_POST['DatePaid']))
157 display_error(_("The entered date is not in fiscal year."));
158 set_focus('DatePaid');
161 if (!references::is_valid($_POST['ref']))
163 display_error(_("You must enter a reference."));
168 if (!is_new_reference($_POST['ref'], 22))
170 display_error(_("The entered reference is already in use."));
178 //----------------------------------------------------------------------------------------
180 function handle_add_payment()
182 $payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
183 $_POST['PaymentType'], $_POST['bank_account'],
184 input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_']);
186 //unset($_POST['supplier_id']);
187 unset($_POST['bank_account']);
188 unset($_POST['DatePaid']);
189 unset($_POST['PaymentType']);
190 unset($_POST['currency']);
191 unset($_POST['memo_']);
192 unset($_POST['amount']);
193 unset($_POST['discount']);
194 unset($_POST['ProcessSuppPayment']);
196 meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_id&supplier_id=".$_POST['supplier_id']);
199 //----------------------------------------------------------------------------------------
201 if (isset($_POST['ProcessSuppPayment']))
203 /*First off check for valid inputs */
204 if (check_inputs() == true)
206 handle_add_payment();