5 include_once($path_to_root . "/includes/session.inc");
6 include_once($path_to_root . "/includes/date_functions.inc");
7 include_once($path_to_root . "/includes/ui.inc");
8 include_once($path_to_root . "/includes/banking.inc");
9 include_once($path_to_root . "/includes/data_checks.inc");
10 include_once($path_to_root . "/sales/includes/sales_db.inc");
13 if ($use_popup_windows) {
14 $js .= get_js_open_window(900, 500);
16 if ($use_date_picker) {
17 $js .= get_js_date_picker();
19 page(_("Customer Payment Entry"), false, false, "", $js);
21 //----------------------------------------------------------------------------------------------
23 check_db_has_customers(_("There are no customers defined in the system."));
25 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
27 check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
29 //----------------------------------------------------------------------------------------
31 if (isset($_GET['AddedID'])) {
32 $payment_no = $_GET['AddedID'];
34 display_notification_centered(_("The customer payment has been successfully entered."));
36 display_note(get_gl_view_str(12, $payment_no, _("View the GL Journal Entries for this Customer Payment")));
38 hyperlink_params($path_to_root . "/sales/allocations/customer_allocate.php", _("Allocate this Customer Payment"), "trans_no=$payment_no&trans_type=12");
40 hyperlink_no_params($path_to_root . "/sales/customer_payments.php", _("Enter Another Customer Payment"));
46 //----------------------------------------------------------------------------------------------
48 function can_process()
50 if (!isset($_POST['DateBanked']) || !is_date($_POST['DateBanked'])) {
51 display_error(_("The entered date is invalid. Please enter a valid date for the payment."));
53 } elseif (!is_date_in_fiscalyear($_POST['DateBanked'])) {
54 display_error(_("The entered date is not in fiscal year."));
58 if (!references::is_valid($_POST['ref'])) {
59 display_error(_("You must enter a reference."));
63 if (!is_new_reference($_POST['ref'], 12)) {
64 display_error(_("The entered reference is already in use."));
68 if ((!is_numeric($_POST['amount']) || $_POST['amount'] < 0)) {
69 display_error(_("The entered amount is invalid or negative and cannot be processed."));
73 if (!isset($_POST['discount']) || ($_POST['discount'] == "")) {
74 $_POST['discount'] = 0;
77 if (!is_numeric($_POST['discount'])) {
78 display_error(_("The entered discount is not a valid number."));
82 if (($_POST['amount'] - $_POST['discount'] <= 0)) {
83 display_error(_("The balance of the amount and discout is zero or negative. Please enter valid amounts."));
90 //----------------------------------------------------------------------------------------------
93 if (isset($_POST['AddPaymentItem'])) {
96 unset($_POST['AddPaymentItem']);
100 //----------------------------------------------------------------------------------------------
102 if (isset($_POST['AddPaymentItem'])) {
103 $payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
104 $_POST['bank_account'], $_POST['DateBanked'], $_POST['ReceiptType'], $_POST['ref'],
105 $_POST['amount'], $_POST['discount'], $_POST['memo_']);
107 meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
110 //----------------------------------------------------------------------------------------------
112 function read_customer_data()
114 $sql = "SELECT ".TB_PREF."debtors_master.pymt_discount,
115 ".TB_PREF."credit_status.dissallow_invoices
116 FROM ".TB_PREF."debtors_master, ".TB_PREF."credit_status
117 WHERE ".TB_PREF."debtors_master.credit_status = ".TB_PREF."credit_status.id
118 AND ".TB_PREF."debtors_master.debtor_no = '" . $_POST['customer_id'] . "'";
120 $result = db_query($sql, "could not query customers");
122 $myrow = db_fetch($result);
124 $_POST['HoldAccount'] = $myrow["dissallow_invoices"];
125 $_POST['pymt_discount'] = $myrow["pymt_discount"];
126 $_POST['ref'] = references::get_next(12);
129 //-------------------------------------------------------------------------------------------------
131 function display_item_form()
133 global $table_style2;
134 start_table($table_style2, 5, 7);
135 echo "<tr><td valign=top>"; // outer table
139 if (!isset($_POST['customer_id']))
140 $_POST['customer_id'] = get_global_customer(false);
141 if (!isset($_POST['DateBanked'])) {
142 $_POST['DateBanked'] = Today();
143 if (!is_date_in_fiscalyear($_POST['DateBanked'])) {
144 $_POST['DateBanked'] = end_fiscalyear();
147 customer_list_row(_("From Customer:"), 'customer_id', null, false, true);
149 if (db_customer_has_branches($_POST['customer_id'])) {
150 customer_branches_list_row(_("Branch:"), $_POST['customer_id'], 'BranchID', null, false, true, true);
152 hidden('BranchID', reserved_words::get_any_numeric());
155 read_customer_data();
157 set_global_customer($_POST['customer_id']);
159 if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0) {
160 echo "</table></table>";
161 display_note(_("This customer account is on hold."), 0, 0, "class='redfb'");
163 $display_discount_percent = number_format2($_POST['pymt_discount']*100,user_price_dec()) . "%";
165 amount_row(_("Amount:"), 'amount');
167 amount_row(_("Amount of Discount:"), 'discount');
169 label_row(_("Customer prompt payment discount :"), $display_discount_percent);
171 date_row(_("Date of Deposit:"), 'DateBanked');
174 echo "</td><td valign=top class='tableseparator'>"; // outer table
177 bank_accounts_list_row(_("Into Bank Account:"), 'bank_account', null, true);
179 $cust_currency = get_customer_currency($_POST['customer_id']);
180 $bank_currency = get_bank_account_currency($_POST['bank_account']);
182 if ($cust_currency != $bank_currency) {
183 exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
186 bank_trans_types_list_row(_("Type:"), 'ReceiptType', null);
188 text_row(_("Reference:"), 'ref', null, 20, 40);
190 textarea_row(_("Memo:"), 'memo_', null, 22, 4);
195 end_table(); // outer table
197 if ($cust_currency != $bank_currency)
198 display_note(_("Amount and discount are in customer's currency."));
202 submit_center('AddPaymentItem', _("Add Payment"));
208 //----------------------------------------------------------------------------------------------