From 128be63f9ae68744f37eae8072f95d0f524f86b4 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 30 Jul 2019 13:48:24 +0200 Subject: [PATCH] Early payment discount option moved from branch to payment terms. --- admin/payment_terms.php | 41 +++++++--- includes/ui/allocation_cart.inc | 82 ++++++++++++------- includes/ui/ui_input.inc | 6 +- js/allocate.js | 20 +++++ js/payalloc.js | 42 ++++++---- purchasing/includes/db/suppalloc_db.inc | 25 +++--- purchasing/includes/ui/invoice_ui.inc | 4 +- purchasing/includes/ui/po_ui.inc | 5 +- .../allocations/customer_allocation_main.php | 8 +- sales/customer_payments.php | 19 +++-- sales/includes/cart_class.inc | 4 +- sales/includes/db/custalloc_db.inc | 18 ++-- sales/includes/db/customers_db.inc | 12 ++- sales/includes/db/sales_invoice_db.inc | 5 +- sales/includes/db/sales_order_db.inc | 1 - sales/includes/sales_db.inc | 6 +- sales/includes/ui/sales_order_ui.inc | 2 +- sales/manage/customers.php | 13 +-- sql/en_US-demo.sql | 5 +- sql/en_US-new.sql | 1 - 20 files changed, 198 insertions(+), 121 deletions(-) diff --git a/admin/payment_terms.php b/admin/payment_terms.php index 1412c372..56f6652c 100644 --- a/admin/payment_terms.php +++ b/admin/payment_terms.php @@ -38,21 +38,36 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') display_error( _("The Terms description must be entered.")); set_focus('terms'); } - - if ($_POST['DayNumber'] == '') - $_POST['DayNumber'] = 0; + $early_days = input_num('early_days', 0); + if ($early_days) { + if ($early_days >= $_POST['DayNumber']) { + $input_error = 1; + display_error(_("Early payment days option should be shorter that payment term days.")); + set_focus('early_days'); + } else if (!check_num('early_discount', 0, 100) or input_num('early_discount') == 0) + { + $input_error = 1; + display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0.")); + set_focus('early_discount'); + } + } else { + if (input_num('early_discount', 0)) { + $input_error = 1; + display_error(_("Early payment days option should be positive and less than payment term days.")); + set_focus('early_days'); + } + } if ($input_error != 1) { - if ($selected_id != -1) { - update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0)); + update_payment_terms($selected_id, get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days); $note = _('Selected payment terms have been updated'); } else { - add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0)); + add_payment_terms(get_post('terms'), get_post('type'), input_num('DayNumber', 0), input_num('early_discount')/100, $early_days); $note = _('New payment terms have been added'); } //run the sql from either of the above possibilites @@ -98,7 +113,7 @@ $result = get_payment_terms_all(check_value('show_inactive')); start_form(); start_table(TABLESTYLE); -$th = array(_("Description"), _("Type"), _("Due After/Days"), "", ""); +$th = array(_("Description"), _("Type"), _("Due After/Days"), _("Early payment discount"),"", ""); inactive_control_column($th); table_header($th); @@ -106,10 +121,13 @@ $k = 0; //row colour counter while ($myrow = db_fetch($result)) { $days = $myrow['days']; + $percent = $myrow['early_discount']; + alt_table_row_color($k); label_cell($myrow["terms"]); label_cell($pterm_types[$myrow['type']]); label_cell($myrow['type'] == PTT_DAYS ? "$days "._("days") : ($myrow['type'] == PTT_FOLLOWING ? $days : _("N/A"))); + label_cell(in_array($myrow['type'], array(PTT_FOLLOWING, PTT_DAYS)) ? ($percent==0 ? _("None") : ($percent*100).'/'.$myrow['early_days']) : _("N/A")); inactive_control_cell($myrow["id"], $myrow["inactive"], 'payment_terms', "id"); edit_button_cell("Edit".$myrow["id"], _("Edit")); delete_button_cell("Delete".$myrow["id"], _("Delete")); @@ -138,6 +156,8 @@ if ($selected_id != -1) $_POST['terms'] = $myrow["terms"]; $_POST['type'] = $myrow['type']; $_POST['DayNumber'] = $myrow['days']; + $_POST['early_discount'] = $myrow['early_discount']*100; + $_POST['early_days'] = $myrow['early_days']; } hidden('selected_id', $selected_id); } @@ -146,9 +166,11 @@ text_row(_("Terms Description:"), 'terms', null, 40, 40); payment_type_list_row(_("Payment type:"), 'type', null, true); -if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS))) +if ( in_array(get_post('type'), array(PTT_FOLLOWING, PTT_DAYS))) { text_row_ex(_("Days (Or Day In Following Month):"), 'DayNumber', 3); -else + small_amount_row(_("Days of early payment discount option:"), 'early_days', null, null, _('days'), 0); + small_amount_row(_("Early payment discount percent:"), 'early_discount', null, null, _('%'), 1); +} else hidden('DayNumber', 0); end_table(1); @@ -159,4 +181,3 @@ submit_add_or_update_center($selected_id == -1, '', 'both'); end_form(); end_page(); - diff --git a/includes/ui/allocation_cart.inc b/includes/ui/allocation_cart.inc index b45110b3..0596e2b2 100644 --- a/includes/ui/allocation_cart.inc +++ b/includes/ui/allocation_cart.inc @@ -52,12 +52,12 @@ class allocation } function add_item($type, $type_no, $date_, $due_date, $amount, $amount_allocated, - $current_allocated, $ref) + $current_allocated, $ref, $early_discount=0, $early_days=0) { if (floatcmp($amount, 0)) { $this->allocs[count($this->allocs)] = new allocation_item($type, $type_no, - $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref); + $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); return true; } else @@ -67,12 +67,12 @@ class allocation } function update_item($index, $type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref) + $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) { if (floatcmp($amount, 0)) { $this->allocs[$index] = new allocation_item($type, $type_no, - $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref); + $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); return true; } else @@ -82,7 +82,7 @@ class allocation } function add_or_update_item($type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref) + $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) { for ($i = 0; $i < count($this->allocs); $i++) { @@ -90,11 +90,11 @@ class allocation if (($item->type == $type) && ($item->type_no == $type_no)) { return $this->update_item($i, $type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref); + $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); } } return $this->add_item($type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref); + $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); } // @@ -152,8 +152,8 @@ class allocation sql2date($myrow["due_date"]), $myrow["Total"], // trans total $myrow["alloc"], // trans total allocated - 0, - $myrow["reference"]); // this allocation + 0, // this allocation + $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]); } } if ($this->trans_no == 0) return; // this is new payment @@ -175,7 +175,7 @@ class allocation sql2date($myrow["tran_date"]), sql2date($myrow["due_date"]), $myrow["Total"], - $myrow["alloc"] - $myrow["amt"], $myrow["amt"], $myrow["reference"]); + $myrow["alloc"] - $myrow["amt"], $myrow["amt"], $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]); } } // @@ -210,10 +210,11 @@ class allocation } else { add_cust_allocation($amount, $this->type, $this->trans_no, - $alloc_item->type, $alloc_item->type_no, $this->person_id, $this->date_); + $alloc_item->type, $alloc_item->type_no, $this->person_id, $this->date_); update_debtor_trans_allocation($alloc_item->type, $alloc_item->type_no, $this->person_id); } + // Exchange Variations Joe Hunt 2008-09-20 //////////////////// if ($alloc_item->type != ST_SALESORDER && !@$no_exchange_variations && $alloc_item->type != ST_PURCHORDER && $alloc_item->type != ST_JOURNAL && $this->type != ST_JOURNAL) @@ -253,9 +254,11 @@ class allocation_item var $ref; var $current_allocated; + var $early_discount; // nominal early payment discount according to payment terms + var $early_days; // days for early payment function __construct($type, $type_no, $date_, $due_date, $amount, - $amount_allocated, $current_allocated, $ref) + $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) { $this->type = $type; @@ -269,16 +272,18 @@ class allocation_item $this->amount = $amount; $this->amount_allocated = $amount_allocated; $this->current_allocated = $current_allocated; + $this->early_discount = $early_discount; + $this->early_days = $early_days; } } //-------------------------------------------------------------------------------- -function show_allocatable($show_totals) { +function show_allocatable($reallocation) { global $systypes_array; - $k = $total_allocated = 0; + $k = $total_allocated = $total_discount = 0; $cart = $_SESSION['alloc']; $supp_ref = in_array($cart->type, array(ST_SUPPCREDIT, ST_SUPPAYMENT, ST_BANKPAYMENT)); @@ -288,14 +293,14 @@ function show_allocatable($show_totals) { display_heading(sprintf(_("Allocated amounts in %s:"), $cart->person_curr)); start_table(TABLESTYLE, "width='60%'"); $th = array(_("Transaction Type"), _("#"), $supp_ref ? _("Supplier Ref"): _("Ref"), _("Date"), _("Due Date"), _("Amount"), - _("Other Allocations"), _("Left to Allocate"), _("This Allocation"),'',''); + _("Other Allocations"), _("Left to Allocate"), _("Early Payment Discount"), _("This Allocation"),'',''); table_header($th); - + $doc_ids = array(); foreach ($cart->allocs as $id => $alloc_item) { - if (floatcmp(abs($alloc_item->amount), $alloc_item->amount_allocated)) - { + $doc_ids[] = $id; + $early_discount = $alloc_item->early_discount != 0 && !date1_greater_date2($cart->date_, add_days($alloc_item->date_, $alloc_item->early_days)); alt_table_row_color($k); label_cell($systypes_array[$alloc_item->type]); label_cell(get_trans_view_str($alloc_item->type, $alloc_item->type_no), "nowrap align='right'"); @@ -306,23 +311,41 @@ function show_allocatable($show_totals) { amount_cell($alloc_item->amount_allocated); $_POST['amount' . $id] = price_format($alloc_item->current_allocated); - + $un_allocated = round((abs($alloc_item->amount) - $alloc_item->amount_allocated), 6); amount_cell($un_allocated, false,'', 'maxval'.$id); - amount_cells(null, "amount" . $id);//, input_num('amount' . $id)); - label_cell("" - . _("All") . ""); - label_cell("" - . _("None") . "".hidden("un_allocated" . $id, - price_format($un_allocated), false)); + if ($early_discount) { + $discount = price_format($alloc_item->early_discount*abs($alloc_item->amount)); + + if ($reallocation) + label_cell($discount, 'align=center'); + else + check_cells(null, 'early_disc'.$id, $discount, false, false, 'align=center'); + $total_discount += $discount; + } else { + label_cell(_("N/A"), 'align=center'); hidden('early_disc'.$id, 0); + } + amount_cells(null, "amount" . $id); + if (0) { + label_cells('', '', '', 'colspan=2'); + } else { + label_cell("" + . _("All") . ""); + label_cell("" + . _("None") . "".hidden("un_allocated" . $id, + price_format($un_allocated), false)); + } end_row(); $total_allocated += input_num('amount' . $id); - } } - if ($show_totals) { + add_js_source('var docs=['.implode(',', $doc_ids).']'); + if ($reallocation) { label_row(_("Total Allocated"), price_format($total_allocated), - "colspan=8 align=right", "align=right id='total_allocated'", 3); + "colspan=9 align=right", "align=right id='total_allocated'", 3); + + label_row(_("Total Discount"), price_format($total_discount), + "colspan=9 align=right", "align=right id='total_discount'", 3); $amount = abs($cart->amount); @@ -335,7 +358,7 @@ function show_allocatable($show_totals) { $font1 = $font2 = ""; $left_to_allocate = price_format($amount - $total_allocated); label_row(_("Left to Allocate"), $font1 . $left_to_allocate . $font2, - "colspan=8 align=right", "nowrap align=right id='left_to_allocate'", + "colspan=9 align=right", "nowrap align=right id='left_to_allocate'", 3); } end_table(1); @@ -405,3 +428,4 @@ function get_inv_allocations($trans_no, $trans_type, $person_id) } return $allocs; } + diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 59a3676e..3c2d83e0 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -373,9 +373,9 @@ function checkbox($label, $name, $value=null, $submit_on_change=false, $title=fa if ($value === null) $value = get_post($name,0); - $str .= "\n"; diff --git a/js/allocate.js b/js/allocate.js index 707bdf8e..a47e8b02 100644 --- a/js/allocate.js +++ b/js/allocate.js @@ -29,6 +29,21 @@ function blur_alloc(i) { price_format('total_allocated', total, user.pdec, 1, 1); } +function update_totals() { + var amount = 0; + var discount = 0; + + for (var i=0; i 0 + $sql .= " WHERE round(ov_amount+ov_gst+ov_discount-alloc,6) > 0 AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")"; - $sql .= " GROUP BY type, trans_no"; } + if ($supplier_id) + $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); + + $orders = get_allocatable_purch_orders($supplier_id, $trans_no, $type); $sql = "($sql ORDER BY trans_no) \nUNION \n($orders)"; diff --git a/purchasing/includes/ui/invoice_ui.inc b/purchasing/includes/ui/invoice_ui.inc index 1b7fb663..e677cf3a 100644 --- a/purchasing/includes/ui/invoice_ui.inc +++ b/purchasing/includes/ui/invoice_ui.inc @@ -132,10 +132,10 @@ function invoice_header(&$supp_trans) $Ajax->activate('due_date'); } - date_row(_("Due Date") . ":", 'due_date'); - label_row(_("Terms:"), $supp_trans->terms['description']); + date_row(_("Due Date") . ":", 'due_date'); + if (get_company_pref('use_dimension')) dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1); diff --git a/purchasing/includes/ui/po_ui.inc b/purchasing/includes/ui/po_ui.inc index 092e801c..ccef48c3 100644 --- a/purchasing/includes/ui/po_ui.inc +++ b/purchasing/includes/ui/po_ui.inc @@ -171,6 +171,8 @@ function display_po_header(&$order) table_section(2); + label_row(_("Terms:"), $order->terms['description']); + if ($order->trans_type==ST_SUPPINVOICE) date_row(_("Due Date:"), 'due_date', '', false, 0, 0, 0, null, true); @@ -180,10 +182,9 @@ function display_po_header(&$order) dimensions_list_row(_('Dimension').':', 'dimension', null, true, _('Default'), false, 1); if (get_company_pref('use_dimension') == 2) dimensions_list_row(_('Dimension 2').':', 'dimension2', null, true, _('Default'), false, 2); - locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true, $order->fixed_asset); table_section(3); - + locations_list_row(_("Receive Into:"), 'StkLocation', null, false, true, $order->fixed_asset); if (!isset($_POST['StkLocation']) || $_POST['StkLocation'] == "" || isset($_POST['_StkLocation_update']) || !isset($_POST['delivery_address']) || $_POST['delivery_address'] == "") diff --git a/sales/allocations/customer_allocation_main.php b/sales/allocations/customer_allocation_main.php index 56d4312f..b08d8548 100644 --- a/sales/allocations/customer_allocation_main.php +++ b/sales/allocations/customer_allocation_main.php @@ -32,6 +32,7 @@ if (!isset($_POST['customer_id'])) echo "
" . _("Select a customer: ") . "  "; echo customer_list('customer_id', $_POST['customer_id'], true, true); echo "
"; + check(_("Show Settled Items:"), 'ShowSettled', null, true); echo "


"; @@ -65,7 +66,9 @@ function trans_view($trans) function alloc_link($row) { - return pager_link(_("Allocate"), + global $all_settled; + + return ($row['settled']&&!get_post('ShowSettled')) || (!$row['settled'] && $all_settled) ? '' : pager_link(_("Allocate"), "/sales/allocations/customer_allocate.php?trans_no=" .$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_ALLOC); } @@ -85,6 +88,9 @@ function check_settled($row) return $row['settled'] == 1; } +$all_settled = !db_num_rows(get_allocatable_to_cust_transactions($customer_id)); +if ($all_settled) + display_note(''._("There is no unsettled transactions for this customer.").''); $sql = get_allocatable_from_cust_sql($customer_id, $settled); diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 30d5151c..1d23a382 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -89,12 +89,21 @@ if (!isset($_POST['customer_id'])) { $_POST['bank_account'] = $dflt_act['id']; } if (!isset($_POST['DateBanked'])) { - $_POST['DateBanked'] = new_doc_date(); + $_SESSION['alloc']->date_ =$_POST['DateBanked'] = new_doc_date(); if (!is_date_in_fiscalyear($_POST['DateBanked'])) { $_POST['DateBanked'] = end_fiscalyear(); } } +if (get_post('_DateBanked_changed')) { + if (!is_date($_POST['DateBanked'])) { + display_error(_("The entered date is invalid. Please enter a valid date for the payment.")); + set_focus('DateBanked'); + } else { + $_SESSION['alloc']->date_ = get_post('DateBanked'); + $Ajax->activate('_page_body'); + } +} if (isset($_GET['AddedID'])) { $payment_no = $_GET['AddedID']; @@ -240,8 +249,8 @@ if (get_post('AddPaymentItem') && can_process()) { $new_pmt = !$_SESSION['alloc']->trans_no; $payment_no = save_cust_payment($_SESSION['alloc'], get_post('customer_id'), get_post('BranchID'), get_post('bank_account'), - get_post('DateBanked'), get_post('ref'), input_num('amount'), input_num('discount'), get_post('memo_'), - input_num('charge'), input_num('bank_amount', input_num('amount'))); + get_post('DateBanked'), get_post('ref'), input_num('amount'), input_num('discount'), get_post('memo_'), + input_num('charge'), input_num('bank_amount', input_num('amount'))); unset($_SESSION['alloc']); meta_forward($_SERVER['PHP_SELF'], $new_pmt ? "AddedID=$payment_no" : "UpdatedID=$payment_no"); @@ -256,7 +265,6 @@ function read_customer_data() $myrow = get_customer_habit($_POST['customer_id']); $_POST['HoldAccount'] = $myrow["dissallow_invoices"]; - $_POST['pymt_discount'] = $myrow["pymt_discount"]; // To support Edit feature // If page is called first time and New entry fetch the nex reference number if (!$_SESSION['alloc']->trans_no && !isset($_POST['charge'])) @@ -338,7 +346,6 @@ read_customer_data(); set_global_customer($_POST['customer_id']); if (isset($_POST['HoldAccount']) && $_POST['HoldAccount'] != 0) display_warning(_("This customer account is on hold.")); -$display_discount_percent = percent_format($_POST['pymt_discount']*100) . "%"; table_section(2); @@ -369,8 +376,6 @@ div_end(); start_table(TABLESTYLE, "width='60%'"); -label_row(_("Customer prompt payment discount :"), $display_discount_percent); - amount_row(_("Amount of Discount:"), 'discount', null, '', $cust_currency); amount_row(_("Amount:"), 'amount', null, '', $cust_currency); diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 6f1d3a79..611194bf 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -66,7 +66,6 @@ class Cart var $pos; // user assigned POS var $cash_account; var $account_name; - var $cash_discount; // not used as of FA 2.1 var $dimension_id; var $dimension2_id; var $payment; @@ -344,7 +343,7 @@ class Cart return $ret; } - function set_customer($customer_id, $customer_name, $currency, $discount, $payment, $cdiscount=0) + function set_customer($customer_id, $customer_name, $currency, $discount, $payment) { $this->customer_name = $customer_name; $this->customer_id = $customer_id; @@ -352,7 +351,6 @@ class Cart $this->customer_currency = $currency; $this->payment = $payment; $this->payment_terms = get_payment_terms($payment); - $this->cash_discount = $cdiscount; if ($this->payment_terms['type'] == PTT_CASH) { $this->Location = $this->pos['pos_location']; diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index a1f6a61c..d66615ee 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -119,12 +119,12 @@ function get_allocatable_from_cust_sql($customer_id=null, $settled) .TB_PREF."debtor_trans as trans, " .TB_PREF."debtors_master as debtor" ." WHERE trans.debtor_no=debtor.debtor_no - AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 0)) + AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount+ov_discount > 0)) OR (type=".ST_CUSTCREDIT. " AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0) OR (type=".ST_JOURNAL. " AND (trans.ov_amount < 0)))"; if (!$settled) - $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) > 0)"; + $sql .= " AND (round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0)"; if ($customer_id != null) $sql .= " AND trans.debtor_no = ".db_escape($customer_id); @@ -148,9 +148,12 @@ function get_allocatable_sales_orders($customer_id = null, $trans_no=null, $type sorder.version, amt, sorder.debtor_no, - sorder.branch_code + sorder.branch_code, + pmt.early_days, + pmt.early_discount FROM ".TB_PREF."sales_orders as sorder LEFT JOIN ".TB_PREF."debtors_master as debtor ON sorder.debtor_no = debtor.debtor_no + LEFT JOIN ".TB_PREF."payment_terms as pmt ON sorder.payment_terms=pmt.id LEFT JOIN ".TB_PREF."cust_allocations as alloc ON sorder.order_no = alloc.trans_no_to AND sorder.trans_type = alloc.trans_type_to AND alloc.person_id=sorder.debtor_no LEFT JOIN (SELECT order_, sum(prep_amount) amount FROM ".TB_PREF."debtor_trans dt @@ -191,10 +194,13 @@ function get_allocatable_to_cust_transactions($customer_id = null, $trans_no=nul trans.version, amt, trans.debtor_no, - trans.branch_code + trans.branch_code, + pmt.early_days, + pmt.early_discount FROM ".TB_PREF."debtor_trans as trans LEFT JOIN ".TB_PREF."cust_allocations as alloc - ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.debtor_no," + ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.debtor_no + LEFT JOIN ".TB_PREF."payment_terms as pmt ON trans.payment_terms=pmt.id," .TB_PREF."debtors_master as debtor WHERE trans.debtor_no=debtor.debtor_no"; @@ -218,9 +224,11 @@ function get_allocatable_to_cust_transactions($customer_id = null, $trans_no=nul OR trans.type = '". ST_JOURNAL."' AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0 + AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>alloc OR trans.type = '". ST_BANKPAYMENT."' AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0 + AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>alloc )"; $sql .= " GROUP BY type, trans_no"; } diff --git a/sales/includes/db/customers_db.inc b/sales/includes/db/customers_db.inc index 0e47a974..e7a57deb 100644 --- a/sales/includes/db/customers_db.inc +++ b/sales/includes/db/customers_db.inc @@ -11,24 +11,23 @@ ***********************************************************************/ function add_customer($CustName, $cust_ref, $address, $tax_id, $curr_code, - $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount, + $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $credit_limit, $sales_type, $notes) { $sql = "INSERT INTO ".TB_PREF."debtors_master (name, debtor_ref, address, tax_id, dimension_id, dimension2_id, curr_code, credit_status, payment_terms, discount, - pymt_discount,credit_limit, sales_type, notes) VALUES (" + credit_limit, sales_type, notes) VALUES (" .db_escape($CustName) .", " .db_escape($cust_ref) .", " .db_escape($address) . ", " . db_escape($tax_id) . "," .db_escape($dimension_id) . ", " .db_escape($dimension2_id) . ", ".db_escape($curr_code) . ", - " . db_escape($credit_status) . ", ".db_escape($payment_terms) . ", " . $discount . ", - " . $pymt_discount . ", " . $credit_limit + " . db_escape($credit_status) .", " . db_escape($payment_terms) .", " . $discount . "," . $credit_limit .", ".db_escape($sales_type).", ".db_escape($notes) . ")"; db_query($sql,"The customer could not be added"); } function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id, $curr_code, - $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $pymt_discount, + $dimension_id, $dimension2_id, $credit_status, $payment_terms, $discount, $credit_limit, $sales_type, $notes) { $sql = "UPDATE ".TB_PREF."debtors_master SET name=" . db_escape($CustName) . ", @@ -41,7 +40,6 @@ function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id, credit_status=".db_escape($credit_status) . ", payment_terms=".db_escape($payment_terms) . ", discount=" . $discount . ", - pymt_discount=" . $pymt_discount . ", credit_limit=" . $credit_limit . ", sales_type = ".db_escape($sales_type) . ", notes=".db_escape($notes) ." @@ -133,7 +131,7 @@ function get_customer_name($customer_id) function get_customer_habit($customer_id) { - $sql = "SELECT debtor.pymt_discount, credit_status.dissallow_invoices + $sql = "SELECT credit_status.dissallow_invoices FROM ".TB_PREF."debtors_master debtor," .TB_PREF."credit_status credit_status WHERE debtor.credit_status = credit_status.id diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 9b9ab467..f1c72672 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -188,10 +188,7 @@ function write_sales_invoice(&$invoice) $amount = $items_total + $items_added_tax + $invoice->freight_cost + $freight_added_tax; - // to use debtors.pmt_discount on cash sale: - // extend invoice entry page with final amount after discount - // and change line below. - $discount = 0; // $invoice->cash_discount*$amount; + $discount = 0; $pmtno = write_customer_payment(0, $invoice->customer_id, $invoice->Branch, $invoice->pos['pos_account'], $date_, $Refs->get_next(ST_CUSTPAYMENT, null, array('customer' => $invoice->customer_id, diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 3296c591..f4d18625 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -419,7 +419,6 @@ function get_customer_to_order($customer_id) { cust.curr_code, cust.discount, cust.payment_terms, - cust.pymt_discount, cust.credit_limit - Sum(IFNULL(IF(trans.type IN(".implode(',', array(ST_CUSTCREDIT, ST_CUSTPAYMENT, ST_BANKDEPOSIT))."), -1, 1) * (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount),0)) as cur_credit FROM ".TB_PREF."debtors_master cust diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index e870b833..6cad00f1 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -465,7 +465,7 @@ function write_recurrent_invoice($invoice_id, $description, $order_no, $debtor_n } function write_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status, - $payment_terms, $discount, $pymt_discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area, + $payment_terms, $discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area, $tax_group, $location, $address, $ship_via, $notes, $bank_account, $address, $phone, $phone2, $fax, $email) { global $SysPrefs; @@ -474,13 +474,13 @@ function write_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code if ($customer_id) { update_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status, - $payment_terms, $discount/100, $pymt_discount/100, $credit_limit, $sales_type, $notes, $inactive); + $payment_terms, $discount/100, $credit_limit, $sales_type, $notes, $inactive); update_record_status($customer_id, $inactive, 'debtors_master', 'debtor_no'); } else { add_customer($name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status, $payment_terms, - $discount / 100, $pymt_discount / 100, $credit_limit, $sales_type, $notes); + $discount / 100, $credit_limit, $sales_type, $notes); $customer_id = db_insert_id(); diff --git a/sales/includes/ui/sales_order_ui.inc b/sales/includes/ui/sales_order_ui.inc index 49c39b87..2d9be2dc 100644 --- a/sales/includes/ui/sales_order_ui.inc +++ b/sales/includes/ui/sales_order_ui.inc @@ -85,7 +85,7 @@ function get_customer_details_to_order(&$order, $customer_id, $branch_id) $deliver = $myrow['address']; // in case no branch address use company address $order->set_customer($customer_id, $name, $myrow['curr_code'], - $myrow['discount'], $myrow['payment_terms'], $myrow['pymt_discount']); + $myrow['discount'], $myrow['payment_terms']); // the sales type determines the price list to be used by default $order->set_sales_type($myrow['salestype'], $myrow['sales_type'], $myrow['tax_included'], diff --git a/sales/manage/customers.php b/sales/manage/customers.php index e51e4b48..4ac790c6 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -58,13 +58,6 @@ function can_process() return false; } - if (!check_num('pymt_discount', 0, 100)) - { - display_error(_("The payment discount must be numeric and is expected to be less than 100% and greater than or equal to 0.")); - set_focus('pymt_discount'); - return false; - } - if (!check_num('discount', 0, 100)) { display_error(_("The discount percentage must be numeric and is expected to be less than 100% and greater than or equal to 0.")); @@ -87,7 +80,7 @@ function handle_submit(&$selected_id) $_POST['customer_id'] = write_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'], $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'], - $_POST['credit_status'], $_POST['payment_terms'], input_num('discount'), input_num('pymt_discount'), + $_POST['credit_status'], $_POST['payment_terms'], input_num('discount'), input_num('credit_limit'), $_POST['sales_type'], $_POST['notes'], @$_POST['inactive'], get_post('salesman'), get_post('area'), get_post('tax_group_id'), get_post('location'), get_post('address'), get_post('ship_via'), get_post('notes'), get_post('bank_account'), get_post('address'), get_post('phone'), get_post('phone2'), get_post('fax'), get_post('email')); @@ -175,7 +168,7 @@ function customer_settings($selected_id) $_POST['credit_status'] = -1; $_POST['payment_terms'] = $_POST['notes'] = ''; - $_POST['discount'] = $_POST['pymt_discount'] = percent_format(0); + $_POST['discount'] = percent_format(0); $_POST['credit_limit'] = price_format($SysPrefs->default_credit_limit()); } } @@ -194,7 +187,6 @@ function customer_settings($selected_id) $_POST['credit_status'] = $myrow["credit_status"]; $_POST['payment_terms'] = $myrow["payment_terms"]; $_POST['discount'] = percent_format($myrow["discount"] * 100); - $_POST['pymt_discount'] = percent_format($myrow["pymt_discount"] * 100); $_POST['credit_limit'] = price_format($myrow["credit_limit"]); $_POST['notes'] = $myrow["notes"]; $_POST['inactive'] = $myrow["inactive"]; @@ -240,7 +232,6 @@ function customer_settings($selected_id) table_section_title(_("Sales")); percent_row(_("Discount Percent:"), 'discount', $_POST['discount']); - percent_row(_("Prompt Payment Discount Percent:"), 'pymt_discount', $_POST['pymt_discount']); amount_row(_("Credit Limit:"), 'credit_limit', $_POST['credit_limit']); payment_terms_list_row(_("Payment Terms:"), 'payment_terms', $_POST['payment_terms']); diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 94496c80..b1e7c9ed 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -698,7 +698,6 @@ CREATE TABLE `0_debtors_master` ( `credit_status` int(11) NOT NULL DEFAULT '0', `payment_terms` int(11) DEFAULT NULL, `discount` double NOT NULL DEFAULT '0', - `pymt_discount` double NOT NULL DEFAULT '0', `credit_limit` float NOT NULL DEFAULT '1000', `notes` tinytext NOT NULL, `inactive` tinyint(1) NOT NULL DEFAULT '0', @@ -710,8 +709,8 @@ CREATE TABLE `0_debtors_master` ( -- Data of table `0_debtors_master` -- INSERT INTO `0_debtors_master` VALUES -('1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '123456789', 'USD', '1', '0', '0', '1', '4', '0', '0', '1000', '', '0'), -('2', 'MoneyMaker Ltd.', 'MoneyMaker', 'N/A', '54354333', 'EUR', '1', '1', '0', '1', '1', '0', '0', '1000', '', '0'); +('1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '123456789', 'USD', '1', '0', '0', '1', '4', '0', '1000', '', '0'), +('2', 'MoneyMaker Ltd.', 'MoneyMaker', 'N/A', '54354333', 'EUR', '1', '1', '0', '1', '1', '0', '1000', '', '0'); -- Structure of table `0_dimensions` -- diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 9d25c8b8..e1f378d6 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -582,7 +582,6 @@ CREATE TABLE `0_debtors_master` ( `credit_status` int(11) NOT NULL DEFAULT '0', `payment_terms` int(11) DEFAULT NULL, `discount` double NOT NULL DEFAULT '0', - `pymt_discount` double NOT NULL DEFAULT '0', `credit_limit` float NOT NULL DEFAULT '1000', `notes` tinytext NOT NULL, `inactive` tinyint(1) NOT NULL DEFAULT '0', -- 2.30.2