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 //----------------------------------------------------------------------------------------
33 if ($ret = context_restore()) {
34 if(isset($ret['supplier_id']))
35 $_POST['supplier_id'] = $ret['supplier_id'];
37 if (isset($_POST['_supplier_id_editor'])) {
38 context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'],
39 array( 'supplier_id', 'bank_account', 'DatePaid', 'ref', 'amount',
40 'discount', 'memo_') );
42 if (isset($_POST['_DatePaid_changed'])) {
43 $Ajax->activate('_ex_rate');
45 //----------------------------------------------------------------------------------------
47 if (isset($_GET['AddedID']))
49 $payment_id = $_GET['AddedID'];
51 display_notification_centered( _("Payment has been sucessfully entered"));
53 display_note(get_gl_view_str(22, $payment_id, _("View the GL &Journal Entries for this Payment")));
55 hyperlink_params($path_to_root . "/purchasing/allocations/supplier_allocate.php", _("&Allocate this Payment"), "trans_no=$payment_id&trans_type=22");
57 hyperlink_params($_SERVER['PHP_SELF'], _("Enter another supplier &payment"), "supplier_id=" . $_POST['supplier_id']);
59 display_footer_exit();
62 //----------------------------------------------------------------------------------------
64 function display_controls()
67 start_form(false, true);
69 if (!isset($_POST['supplier_id']))
70 $_POST['supplier_id'] = get_global_supplier(false);
71 if (!isset($_POST['DatePaid']))
73 $_POST['DatePaid'] = Today();
74 if (!is_date_in_fiscalyear($_POST['DatePaid']))
75 $_POST['DatePaid'] = end_fiscalyear();
77 start_table($table_style2, 5, 7);
78 echo "<tr><td valign=top>"; // outer table
82 bank_accounts_list_row(_("From Bank Account:"), 'bank_account', null, true);
84 amount_row(_("Amount of Payment:"), 'amount');
85 amount_row(_("Amount of Discount:"), 'discount');
87 date_row(_("Date Paid") . ":", 'DatePaid', '', null, 0, 0, 0, null, true);
90 echo "</td><td valign=top class='tableseparator'>"; // outer table
93 supplier_list_row(_("Payment To:"), 'supplier_id', null, false, true);
95 set_global_supplier($_POST['supplier_id']);
97 $supplier_currency = get_supplier_currency($_POST['supplier_id']);
98 $bank_currency = get_bank_account_currency($_POST['bank_account']);
99 if ($bank_currency != $supplier_currency)
101 exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
104 ref_row(_("Reference:"), 'ref', '', references::get_next(22));
106 text_row(_("Memo:"), 'memo_', null, 52,50);
111 end_table(1); // outer table
113 submit_center('ProcessSuppPayment',_("Enter Payment"), true, '', true);
115 if ($bank_currency != $supplier_currency)
117 display_note(_("The amount and discount are in the bank account's currency."), 2, 0);
123 //----------------------------------------------------------------------------------------
125 function check_inputs()
127 if ($_POST['amount'] == "")
129 $_POST['amount'] = price_format(0);
132 if (!check_num('amount', 0))
134 display_error(_("The entered amount is invalid or less than zero."));
139 if ($_POST['discount'] == "")
141 $_POST['discount'] = 0;
144 if (!check_num('discount', 0))
146 display_error(_("The entered discount is invalid or less than zero."));
151 if (input_num('amount') - input_num('discount') <= 0)
153 display_error(_("The total of the amount and the discount negative. Please enter positive values."));
158 if (!is_date($_POST['DatePaid']))
160 display_error(_("The entered date is invalid."));
161 set_focus('DatePaid');
164 elseif (!is_date_in_fiscalyear($_POST['DatePaid']))
166 display_error(_("The entered date is not in fiscal year."));
167 set_focus('DatePaid');
170 if (!references::is_valid($_POST['ref']))
172 display_error(_("You must enter a reference."));
177 if (!is_new_reference($_POST['ref'], 22))
179 display_error(_("The entered reference is already in use."));
187 //----------------------------------------------------------------------------------------
189 function handle_add_payment()
191 $payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
192 $_POST['bank_account'], input_num('amount'), input_num('discount'),
193 $_POST['ref'], $_POST['memo_']);
195 //unset($_POST['supplier_id']);
196 unset($_POST['bank_account']);
197 unset($_POST['DatePaid']);
198 unset($_POST['currency']);
199 unset($_POST['memo_']);
200 unset($_POST['amount']);
201 unset($_POST['discount']);
202 unset($_POST['ProcessSuppPayment']);
204 meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_id&supplier_id=".$_POST['supplier_id']);
207 //----------------------------------------------------------------------------------------
209 if (isset($_POST['ProcessSuppPayment']))
211 /*First off check for valid inputs */
212 if (check_inputs() == true)
214 handle_add_payment();