From 4deaa6ba6e084655989c30cfb7d9dd307408c7dc Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sun, 11 Aug 2019 18:04:41 +0200 Subject: [PATCH] Customer Payment, Supplier Payment: early discount support. --- includes/ui/allocation_cart.inc | 105 +++++++----------- includes/ui/ui_view.inc | 10 +- js/allocate.js | 50 +++------ js/payalloc.js | 26 ++--- purchasing/allocations/supplier_allocate.php | 14 +-- .../allocations/supplier_allocation_main.php | 6 + purchasing/includes/db/suppalloc_db.inc | 63 ++++++----- purchasing/includes/purchasing_db.inc | 21 ++++ purchasing/supplier_payment.php | 25 +---- reporting/rep112.php | 2 +- reporting/rep210.php | 2 +- sales/allocations/customer_allocate.php | 13 +-- .../allocations/customer_allocation_main.php | 7 +- sales/customer_payments.php | 20 +--- sales/includes/db/custalloc_db.inc | 104 ++++++++--------- sales/includes/sales_db.inc | 7 +- sql/alter2.5.sql | 19 ++++ sql/en_US-demo.sql | 10 +- sql/en_US-new.sql | 2 + 19 files changed, 246 insertions(+), 260 deletions(-) diff --git a/includes/ui/allocation_cart.inc b/includes/ui/allocation_cart.inc index 0596e2b2..10ce525f 100644 --- a/includes/ui/allocation_cart.inc +++ b/includes/ui/allocation_cart.inc @@ -52,13 +52,13 @@ class allocation } function add_item($type, $type_no, $date_, $due_date, $amount, $amount_allocated, - $current_allocated, $ref, $early_discount=0, $early_days=0) + $current_allocated, $ref, $early_discount=0, $early_days=0, $discount=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, $early_discount, $early_days); - return true; + $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days, $discount); + return $this->allocs[count($this->allocs)-1]; } else { @@ -67,13 +67,13 @@ class allocation } function update_item($index, $type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) + $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0, $discount=0) { if (floatcmp($amount, 0)) { $this->allocs[$index] = new allocation_item($type, $type_no, - $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); - return true; + $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days, $discount); + return $this->allocs[$index]; } else { @@ -82,7 +82,7 @@ class allocation } function add_or_update_item($type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) + $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0, $discount=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, $early_discount, $early_days); + $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days, $discount); } } return $this->add_item($type, $type_no, $date_, $due_date, - $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days); + $amount, $amount_allocated, $current_allocated, $ref, $early_discount, $early_days, $discount); } // @@ -134,49 +134,27 @@ class allocation $this->amount = $trans["Total"]; } } - /* Now populate the array of possible (and previous actual) allocations - for this customer/supplier. First get the transactions that have - outstanding balances ie Total-alloc >0 */ + /* Now populate the array of possible (and previous actual) allocations for this customer/supplier. + First get the transactions that have outstanding balances ie Total-alloc >0 */ $this->allocs = array(); if ($this->person_id) { if ($this->person_type==PT_SUPPLIER) - $trans_items = get_allocatable_to_supp_transactions($this->person_id); + $trans_items = get_allocatable_to_supp_transactions($this->person_id, $this->trans_no, $this->type); else - $trans_items = get_allocatable_to_cust_transactions($this->person_id); + $trans_items = get_allocatable_to_cust_transactions($this->person_id, $this->trans_no, $this->type); + while ($myrow = db_fetch($trans_items)) { - $this->add_item($myrow["type"], $myrow["trans_no"], + $this->add_or_update_item ($myrow["type"], $myrow["trans_no"], sql2date($myrow["tran_date"]), sql2date($myrow["due_date"]), - $myrow["Total"], // trans total - $myrow["alloc"], // trans total allocated - 0, // this allocation - $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]); + $myrow["Total"], $myrow["alloc"]-$myrow["amt"], $myrow["amt"], + $myrow["reference"], + $myrow["early_discount"], $myrow["early_days"], $myrow["discount"]); } } - if ($this->trans_no == 0) return; // this is new payment - - /* Now get trans that might have previously been allocated to by this trans - NB existing entries where still some of the trans outstanding entered from - above logic will be overwritten with the prev alloc detail below */ - - if ($this->person_type==PT_SUPPLIER) - $trans_items = get_allocatable_to_supp_transactions($this->person_id, - $this->trans_no, $this->type); - else - $trans_items = get_allocatable_to_cust_transactions($this->person_id, - $this->trans_no, $this->type); - - while ($myrow = db_fetch($trans_items)) - { - $this->add_or_update_item ($myrow["type"], $myrow["trans_no"], - sql2date($myrow["tran_date"]), - sql2date($myrow["due_date"]), - $myrow["Total"], - $myrow["alloc"] - $myrow["amt"], $myrow["amt"], $myrow["reference"], $myrow["early_discount"], $myrow["early_days"]); - } } // // Update allocations in database. @@ -204,13 +182,13 @@ class allocation if ($this->person_type == PT_SUPPLIER) { add_supp_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_, round2($alloc_item->early_discount*abs($alloc_item->amount), user_price_dec())); update_supp_trans_allocation($alloc_item->type, $alloc_item->type_no, $this->person_id); } 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_, round2($alloc_item->early_discount*abs($alloc_item->amount), user_price_dec())); update_debtor_trans_allocation($alloc_item->type, $alloc_item->type_no, $this->person_id); } @@ -256,6 +234,7 @@ class allocation_item var $current_allocated; var $early_discount; // nominal early payment discount according to payment terms var $early_days; // days for early payment + var $discount_confirmed = false; function __construct($type, $type_no, $date_, $due_date, $amount, $amount_allocated, $current_allocated, $ref, $early_discount=0, $early_days=0) @@ -275,6 +254,11 @@ class allocation_item $this->early_discount = $early_discount; $this->early_days = $early_days; } + + function confirm_discount($confirmed) + { + $this->discount_confirmed = $confirmed; + } } //-------------------------------------------------------------------------------- @@ -313,28 +297,22 @@ function show_allocatable($reallocation) { $_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); - 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'); + amount_cell($un_allocated-$alloc_item->current_allocated, false,'', 'left'.$id); + + if ($early_discount) { + $discount = round2($alloc_item->early_discount*abs($alloc_item->amount),user_price_dec()); + check_cells(null, 'early_disc'.$id, price_format($discount), false, false, 'align=center'); $total_discount += $discount; } else { - label_cell(_("N/A"), 'align=center'); hidden('early_disc'.$id, 0); + label_cell(_("N/A"), 'align=center', 'early_disc'.$id); 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)); - } + + label_cell("" + . _("All") . ""); + label_cell("" + . _("None") . "".hidden("un_allocated".$id, price_format($un_allocated), false)); end_row(); $total_allocated += input_num('amount' . $id); @@ -371,7 +349,7 @@ function check_allocations() { global $SysPrefs; - $total_allocated = 0; + $total_allocated = $discount=0; for ($counter = 0; $counter < get_post("TotalNumberOfAllocs"); $counter++) { @@ -397,11 +375,14 @@ function check_allocations() $_SESSION['alloc']->allocs[$counter]->current_allocated = input_num('amount' . $counter); $total_allocated += input_num('amount' . $counter); - } + $_SESSION['alloc']->allocs[$counter]->discount_confirmed = check_value('early_disc'.$counter) != 0; + $discount += check_value('early_disc'.$counter) + ? round2($_SESSION['alloc']->allocs[$counter]->early_discount*input_num('amount' . $counter), user_price_dec()) : 0; + } $amount = abs($_SESSION['alloc']->amount); - if ($total_allocated - ($amount + input_num('discount')) > $SysPrefs->allocation_settled_allowance()) + if ($total_allocated - ($amount + $discount) > $SysPrefs->allocation_settled_allowance()) { display_error(_("These allocations cannot be processed because the amount allocated is more than the total amount left to allocate.")); return false; diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 88435a71..40c4966a 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -563,10 +563,8 @@ function display_allocations($alloc_result, $total, $title, $show_summary=true) label_cell(sql2date($alloc_row['tran_date'])); $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec()); $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec()); - if ($alloc_row['type'] == ST_SUPPAYMENT || $alloc_row['type'] == ST_BANKPAYMENT || $alloc_row['type'] == ST_SUPPCREDIT) - $alloc_row['Total'] = -$alloc_row['Total']; - amount_cell($alloc_row['Total']); - amount_cell($alloc_row['Total'] - $alloc_row['alloc']); + amount_cell(abs($alloc_row['Total'])); + amount_cell(abs($alloc_row['Total']) - $alloc_row['alloc']); amount_cell($alloc_row['amt']); end_row(); @@ -594,11 +592,11 @@ function display_allocations_from($person_type, $person_id, $type, $type_no, $to switch ($person_type) { case PT_CUSTOMER : - $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type); + $alloc_result = get_allocatable_to_cust_transactions(0, $type_no, $type); display_allocations($alloc_result, $total, _("Allocations")); return; case PT_SUPPLIER : - $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type); + $alloc_result = get_allocatable_to_supp_transactions(0, $type_no, $type); display_allocations($alloc_result, $total, _("Allocations")); return; } diff --git a/js/allocate.js b/js/allocate.js index a47e8b02..01a6bcd1 100644 --- a/js/allocate.js +++ b/js/allocate.js @@ -14,19 +14,13 @@ function focus_alloc(i) { } function blur_alloc(i) { - - var last = +i.getAttribute('_last') - var left = get_amount('left_to_allocate', 1); - var cur = Math.min(get_amount(i.name), get_amount('maxval'+i.name.substr(6), 1), last+left) + var id = i.name.substr(6) + var unallocated = get_amount('un_allocated'+id) + var cur = Math.max(Math.min(get_amount(i.name), unallocated, get_amount('left_to_allocate',1)+parseFloat(i.getAttribute('_last'))), 0) price_format(i.name, cur, user.pdec); - change = cur-last; - - var total = get_amount('total_allocated', 1)+change; - left -= change; - - price_format('left_to_allocate', left, user.pdec, 1, 1); - price_format('total_allocated', total, user.pdec, 1, 1); + price_format('left'+id, unallocated-cur, user.pdec, 1); + update_totals() } function update_totals() { @@ -39,36 +33,26 @@ function update_totals() { && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i]))) discount += get_amount('early_disc'+docs[i]); } - price_format('amount', amount-discount, user.pdec); - price_format('discount', discount, user.pdec); - + price_format('left_to_allocate', Math.abs(get_amount('total',1)-(amount-discount)), user.pdec, 1,1); + price_format('total_allocated', amount-discount, user.pdec, 1, 1); + price_format('total_discount', discount, user.pdec, 1, 1); } + function allocate_all(doc) { - var amount = get_amount('amount'+doc); var unallocated = get_amount('un_allocated'+doc); - var total = get_amount('total_allocated', 1); - var left = get_amount('left_to_allocate', 1); - total -= (amount-unallocated); - left += (amount-unallocated); - amount = unallocated; - if(left<0) { - total += left; - amount += left; - left = 0; - } - price_format('amount'+doc, amount, user.pdec); - price_format('left_to_allocate', left, user.pdec, 1,1); - price_format('total_allocated', total, user.pdec, 1, 1); + var cur = Math.min(unallocated, get_amount('left_to_allocate',1)) + price_format('amount'+doc, cur, user.pdec); + price_format('left'+doc, 0, user.pdec, 1); + update_totals(); + } function allocate_none(doc) { - amount = get_amount('amount'+doc); - left = get_amount('left_to_allocate', 1); - total = get_amount('total_allocated', 1); - price_format('left_to_allocate',amount+left, user.pdec, 1, 1); + var unallocated = get_amount('un_allocated'+doc); price_format('amount'+doc, 0, user.pdec); - price_format('total_allocated', total-amount, user.pdec, 1, 1); + price_format('left'+doc, unallocated, user.pdec, 1); + update_totals(); } var allocations = { diff --git a/js/payalloc.js b/js/payalloc.js index 1ea07986..d633a3cf 100644 --- a/js/payalloc.js +++ b/js/payalloc.js @@ -14,20 +14,14 @@ function focus_alloc(i) { } function blur_alloc(i) { - var change = get_amount(i.name); - - if (i.name != 'amount' && i.name != 'charge' && i.name != 'discount') - change = Math.min(change, get_amount('maxval'+i.name.substr(6), 1)) + var id = i.name.substr(6) + var unallocated = get_amount('un_allocated'+id); - price_format(i.name, change, user.pdec); - if (i.name != 'amount' && i.name != 'charge') { - if (change<0) change = 0; - change = change-i.getAttribute('_last'); - if (i.name == 'discount') change = -change; + var cur = Math.max(Math.min(get_amount(i.name), unallocated), 0); - var total = get_amount('amount')+change; - price_format('amount', total, user.pdec, 0); - } + price_format(i.name, cur, user.pdec); + price_format('left'+id, unallocated-cur, user.pdec, 1); + update_totals() } function update_totals() { @@ -40,19 +34,23 @@ function update_totals() { && (get_amount('un_allocated'+docs[i]) == get_amount('amount'+docs[i]))) discount += get_amount('early_disc'+docs[i]); } + console.info(discount); price_format('amount', amount-discount, user.pdec); - price_format('discount', discount, user.pdec); + price_format('discount', discount, user.pdec, 1); } function allocate_all(doc) { - var unallocated = get_amount('maxval'+doc, 1); + var unallocated = get_amount('un_allocated'+doc); price_format('amount'+doc, unallocated, user.pdec); + price_format('left'+doc, 0, user.pdec, 1); update_totals(); } function allocate_none(doc) { + var unallocated = get_amount('un_allocated'+doc); price_format('amount'+doc, 0, user.pdec); + price_format('left'+doc, unallocated, user.pdec, 1); update_totals(); } diff --git a/purchasing/allocations/supplier_allocate.php b/purchasing/allocations/supplier_allocate.php index 10942e7a..14632d7d 100644 --- a/purchasing/allocations/supplier_allocate.php +++ b/purchasing/allocations/supplier_allocate.php @@ -55,15 +55,13 @@ function edit_allocations_for_transaction($type, $trans_no) display_heading2(_("Date:") . " " . $cart->date_ . ""); - display_heading2(_("Total:"). " " . price_format(-$cart->bank_amount).' '.$cart->currency.""); - if (floatcmp($cart->bank_amount, $cart->amount)) - { - $total = _("Amount ot be settled:") . " " . price_format(-$cart->amount).' '.$cart->person_curr.""; - if ($cart->currency != $cart->person_curr) - $total .= sprintf(" (%s %s/%s)", exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr); - display_heading2($total); - } + display_heading2(_("Total:"). " " . price_format(-$cart->bank_amount).' '.$cart->currency.""); + + $total = _("Amount ot be settled:") . " " . ''.price_format(-$cart->amount).' '.$cart->person_curr.""; + if ($cart->currency != $cart->person_curr) + $total .= sprintf(" (%s %s/%s)", exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr); + display_heading2($total); echo "
"; div_start('alloc_tbl'); diff --git a/purchasing/allocations/supplier_allocation_main.php b/purchasing/allocations/supplier_allocation_main.php index 9d1cb8d9..09610785 100644 --- a/purchasing/allocations/supplier_allocation_main.php +++ b/purchasing/allocations/supplier_allocation_main.php @@ -88,6 +88,12 @@ function check_settled($row) } +$all_settled = !db_num_rows(get_allocatable_to_supp_transactions(get_post('supplier_id'))); +if ($all_settled) + display_note(''. + ($supplier_id ? _("There is no unsettled transactions for this supplier.") + :_("There is no unsettled transactions.")).'

'); + $sql = get_allocatable_from_supp_sql($supplier_id, $settled); $cols = array( diff --git a/purchasing/includes/db/suppalloc_db.inc b/purchasing/includes/db/suppalloc_db.inc index c8ad5c46..e24c6d46 100644 --- a/purchasing/includes/db/suppalloc_db.inc +++ b/purchasing/includes/db/suppalloc_db.inc @@ -12,13 +12,13 @@ //---------------------------------------------------------------------------------------- function add_supp_allocation($amount, $trans_type_from, $trans_no_from, - $trans_type_to, $trans_no_to, $person_id, $date_) + $trans_type_to, $trans_no_to, $person_id, $date_, $discount=0) { $date = date2sql($date_); $sql = "INSERT INTO ".TB_PREF."supp_allocations ( - amt, date_alloc, + amt, discount, date_alloc, trans_type_from, trans_no_from, trans_no_to, trans_type_to, person_id) - VALUES (".db_escape($amount).", '$date', " + VALUES (".db_escape($amount).",".db_escape($discount).", '$date', " .db_escape($trans_type_from).", ".db_escape($trans_no_from).", " .db_escape($trans_no_to).", ".db_escape($trans_type_to).", ".db_escape($person_id).")"; @@ -31,7 +31,7 @@ function add_supp_allocation($amount, $trans_type_from, $trans_no_from, function delete_supp_allocation($trans_id) { $sql = "DELETE FROM ".TB_PREF."supp_allocations WHERE id = ".db_escape($trans_id); - db_query($sql, "The existing allocation $trans_id could not be deleted"); + return db_query($sql, "The existing allocation $trans_id could not be deleted"); } //---------------------------------------------------------------------------------------- @@ -130,7 +130,7 @@ function get_allocatable_from_supp_sql($supplier_id=null, $settled) return $sql; } -function get_allocatable_purch_orders($supplier_id = null, $trans_no=null, $type=null) +function get_allocatable_purch_orders($supplier_id, $trans_no=null, $type=null) { $due_dates = "SELECT order_no, MIN(delivery_date) as date FROM ".TB_PREF."purch_order_details det @@ -147,7 +147,8 @@ function get_allocatable_purch_orders($supplier_id = null, $trans_no=null, $type porder.alloc, due_dates.date as due_date, supplier.address, - amt, + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.amt, 0) amt" : "alloc.amt").", + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.discount, 0) discount" : "alloc.discount").", supp_reference as supp_ref, 0, 0 FROM ".TB_PREF."purch_orders as porder @@ -158,25 +159,29 @@ function get_allocatable_purch_orders($supplier_id = null, $trans_no=null, $type LEFT JOIN ($due_dates) due_dates ON due_dates.order_no=porder.order_no WHERE total>0"; - if ($trans_no != null and $type != null) - { - $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." - AND alloc.trans_type_from=".db_escape($type); - } - else - { - $sql .= " AND ISNULL(grn.purch_order_no)"; // only sales orders no yet received - } + $sql .= " AND ( ISNULL(grn.purch_order_no)" // only orders no yet received + ."OR (alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type)."))"; + if ($supplier_id) $sql .= " AND porder.supplier_id=".db_escape($supplier_id); + elseif (isset($trans_no) && isset($type)) + $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type); $sql .= " GROUP BY porder.order_no, grn.purch_order_no"; return $sql; } + //------------------------------------------------------------------------------------------------------------- +// +// Returns all allocatable purchase transactions including all settled with selected payment. +// +// 1. not fully settled; supplier_id!=0, trans_no/type!=null (for trans edition) +// 2. for given transaction; supplier_id=null, trans_no/type!=null (for transaction view) +// 3. for supplier, not fully settled supplier_id!=0, trans_no/type=null (non fully settled documents for supplier exists) +// 4. for all suppliers, not fully settled supplier_id==0, trans_no/type=null (any non fully settled documents exists) -function get_allocatable_to_supp_transactions($supplier_id=null, $trans_no=null, $type=null) +function get_allocatable_to_supp_transactions($supplier_id, $trans_no=null, $type=null) { $sql = "SELECT trans.type, @@ -189,7 +194,8 @@ function get_allocatable_to_supp_transactions($supplier_id=null, $trans_no=null, trans.alloc, trans.due_date, trans.supplier_id, - amt, + IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.amt, 0) amt, + IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.discount, 0) discount, supp_reference, pmt.early_days, pmt.early_discount @@ -200,25 +206,22 @@ function get_allocatable_to_supp_transactions($supplier_id=null, $trans_no=null, LEFT JOIN ".TB_PREF."supp_allocations as alloc ON trans.trans_no = alloc.trans_no_to AND trans.type = alloc.trans_type_to AND alloc.person_id=trans.supplier_id"; - if ($trans_no != null and $type != null) - { - $sql .= " WHERE alloc.trans_no_from=".db_escape($trans_no)." - AND alloc.trans_type_from=".db_escape($type); - } - else - { - $sql .= " WHERE round(ov_amount+ov_gst+ov_discount-alloc,6) > 0 - AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")"; - } + $sql .= " WHERE ( + (round(ov_amount+ov_gst+ov_discount-alloc,6) > 0 + AND trans.type NOT IN (".implode(',',array(ST_SUPPAYMENT, ST_BANKPAYMENT)).")) + OR (alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type)."))"; if ($supplier_id) - $sql .= " AND supplier.supplier_id=".db_escape($supplier_id); + $sql .= " AND trans.supplier_id=".db_escape($supplier_id); + elseif (isset($trans_no) && isset($type)) + $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type); + $sql .= " GROUP BY type, trans_no"; // avoids row multiplication for journal entry containing multiply suppliers $orders = get_allocatable_purch_orders($supplier_id, $trans_no, $type); - $sql = "($sql ORDER BY trans_no) \nUNION \n($orders)"; + $sql = "($sql) \nUNION \n($orders) ORDER BY amt, due_date"; - return db_query($sql." ORDER BY due_date", "Cannot retreive alloc to transactions"); + return db_query($sql, "Cannot retreive alloc to transactions"); } //------------------------------------------------------------------------------------------------------------- diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index f7fe7a5d..fa8b3a49 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -262,3 +262,24 @@ function write_supp_allocation($cart) return $result; } +function save_supp_payment($cart, $supplier_id, $bank_account, $trans_date, $ref, $amount, $memo, $charge, $bank_amount) +{ + begin_transaction(__FUNCTION__, func_get_args()); + + $discount = 0; + foreach($cart->allocs as $alloc) + if ($alloc->discount_confirmed) + $discount += $alloc->early_discount*$alloc->amount; + + $payment_no = write_supp_payment($cart->trans_no, $supplier_id, $bank_account, $trans_date, $ref, $amount, + $discount, $memo, $charge, $bank_amount); + + $cart->trans_no = $payment_no; + $cart->date_ = $trans_date; + $cart->write(); + + commit_transaction(); + + return $payment_no; +} + diff --git a/purchasing/supplier_payment.php b/purchasing/supplier_payment.php index c7bedf4d..899e2afd 100644 --- a/purchasing/supplier_payment.php +++ b/purchasing/supplier_payment.php @@ -161,19 +161,6 @@ function check_inputs() } } - if (@$_POST['discount'] == "") - { - $_POST['discount'] = 0; - } - - if (!check_num('discount', 0)) - { - display_error(_("The entered discount is invalid or less than zero.")); - set_focus('amount'); - return false; - } - - //if (input_num('amount') - input_num('discount') <= 0) if (input_num('amount') <= 0) { display_error(_("The total of the amount and the discount is zero or negative. Please enter positive values.")); @@ -232,15 +219,11 @@ function check_inputs() function handle_add_payment() { - $payment_id = write_supp_payment(0, $_POST['supplier_id'], $_POST['bank_account'], - $_POST['DatePaid'], $_POST['ref'], input_num('amount'), input_num('discount'), $_POST['memo_'], + $payment_id = save_supp_payment($_SESSION['alloc'], $_POST['supplier_id'], $_POST['bank_account'], + $_POST['DatePaid'], $_POST['ref'], input_num('amount'), $_POST['memo_'], input_num('charge'), input_num('bank_amount', input_num('amount'))); new_doc_date($_POST['DatePaid']); - $_SESSION['alloc']->trans_no = $payment_id; - $_SESSION['alloc']->date_ = $_POST['DatePaid']; - $_SESSION['alloc']->write(); - unset($_POST['bank_account']); unset($_POST['DatePaid']); unset($_POST['currency']); @@ -326,11 +309,13 @@ start_form(); div_end(); start_table(TABLESTYLE, "width='60%'"); - amount_row(_("Amount of Discount:"), 'discount', null, '', $supplier_currency); + label_row(_("Total Discount:"), price_format(input_num('discount')), '', '', 0, 'discount'); amount_row(_("Amount of Payment:"), 'amount', null, '', $supplier_currency); textarea_row(_("Memo:"), 'memo_', null, 22, 4); end_table(1); + hidden('discount', null); + submit_center('ProcessSuppPayment',_("Enter Payment"), true, '', 'default'); end_form(); diff --git a/reporting/rep112.php b/reporting/rep112.php index aaaf783c..6f0cf987 100644 --- a/reporting/rep112.php +++ b/reporting/rep112.php @@ -120,7 +120,7 @@ function print_receipts() $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_CUSTPAYMENT, $contacts); $rep->SetHeaderType('Header2'); $rep->NewPage(); - $result = get_allocatable_to_cust_transactions($myrow['debtor_no'], $myrow['trans_no'], $myrow['type']); + $result = get_allocatable_to_cust_transactions(0, $myrow['trans_no'], $myrow['type']); $doctype = ST_CUSTPAYMENT; diff --git a/reporting/rep210.php b/reporting/rep210.php index 98b4a9b0..c204000e 100644 --- a/reporting/rep210.php +++ b/reporting/rep210.php @@ -119,7 +119,7 @@ function print_remittances() $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_SUPPAYMENT, $contacts); $rep->SetHeaderType('Header2'); $rep->NewPage(); - $result = get_allocatable_to_supp_transactions($myrow['supplier_id'], $myrow['trans_no'], $myrow['type']); + $result = get_allocatable_to_supp_transactions(0, $myrow['trans_no'], $myrow['type']); $doctype = ST_SUPPAYMENT; diff --git a/sales/allocations/customer_allocate.php b/sales/allocations/customer_allocate.php index 68a1ff43..50e9d6e6 100644 --- a/sales/allocations/customer_allocate.php +++ b/sales/allocations/customer_allocate.php @@ -56,15 +56,14 @@ function edit_allocations_for_transaction($type, $trans_no) display_heading($cart->person_name); display_heading2(_("Date:") . " " . $cart->date_ . ""); - display_heading2(_("Total:"). " " . price_format($cart->bank_amount).' '.$cart->currency.""); if (floatcmp($cart->bank_amount, $cart->amount)) - { - $total = _("Amount ot be settled:") . " " . price_format($cart->amount).' '.$cart->person_curr.""; - if ($cart->currency != $cart->person_curr) - $total .= sprintf(" (%s %s/%s)", exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr); - display_heading2($total); - } + display_heading2(_("Total:"). " " . price_format($cart->bank_amount).' '.$cart->currency.""); + + $total = _("Amount to be settled:") . " " . ''.price_format($cart->amount).' '.$cart->person_curr.""; + if ($cart->currency != $cart->person_curr) + $total .= sprintf(" (%s %s/%s)", exrate_format($cart->bank_amount/$cart->amount), $cart->currency, $cart->person_curr); + display_heading2($total); echo "
"; diff --git a/sales/allocations/customer_allocation_main.php b/sales/allocations/customer_allocation_main.php index b08d8548..8d0c33a2 100644 --- a/sales/allocations/customer_allocation_main.php +++ b/sales/allocations/customer_allocation_main.php @@ -68,7 +68,7 @@ function alloc_link($row) { global $all_settled; - return ($row['settled']&&!get_post('ShowSettled')) || (!$row['settled'] && $all_settled) ? '' : pager_link(_("Allocate"), + return pager_link(_("Allocate"), "/sales/allocations/customer_allocate.php?trans_no=" .$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_ALLOC); } @@ -89,8 +89,11 @@ function check_settled($row) } $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.").''); + display_note(''. + ($customer_id ? _("There is no unsettled transactions for this customer.") + :_("There is no unsettled transactions.")).'

'); $sql = get_allocatable_from_cust_sql($customer_id, $settled); diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 1d23a382..68b0c624 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -198,20 +198,9 @@ function can_process() } } - if (@$_POST['discount'] == "") - { - $_POST['discount'] = 0; - } - - if (!check_num('discount')) { - display_error(_("The entered discount is not a valid number.")); - set_focus('discount'); - return false; - } - if (input_num('amount') <= 0) { display_error(_("The balance of the amount and discount is zero or negative. Please enter valid amounts.")); - set_focus('discount'); + set_focus('amount'); return false; } @@ -249,7 +238,7 @@ 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_'), + get_post('DateBanked'), get_post('ref'), input_num('amount'), get_post('memo_'), input_num('charge'), input_num('bank_amount', input_num('amount'))); unset($_SESSION['alloc']); @@ -305,6 +294,7 @@ if (isset($_GET['trans_no']) && $_GET['trans_no'] > 0 ) } } + //---------------------------------------------------------------------------------------------- $new = !$_SESSION['alloc']->trans_no; start_form(); @@ -376,13 +366,15 @@ div_end(); start_table(TABLESTYLE, "width='60%'"); -amount_row(_("Amount of Discount:"), 'discount', null, '', $cust_currency); +label_row(_("Total Discount:"), price_format(input_num('discount')), '','', 0, 'discount'); amount_row(_("Amount:"), 'amount', null, '', $cust_currency); textarea_row(_("Memo:"), 'memo_', null, 22, 4); end_table(1); +hidden('discount', null); + if ($new) submit_center('AddPaymentItem', _("Add Payment"), true, '', 'default'); else diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index d66615ee..79fa504d 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -12,13 +12,14 @@ //---------------------------------------------------------------------------------------- function add_cust_allocation($amount, $trans_type_from, $trans_no_from, - $trans_type_to, $trans_no_to, $person_id, $date_) + $trans_type_to, $trans_no_to, $person_id, $date_, $discount=0) { $date = date2sql($date_); $sql = "INSERT INTO ".TB_PREF."cust_allocations ( - amt, date_alloc, + amt, discount, date_alloc, trans_type_from, trans_no_from, trans_no_to, trans_type_to, person_id) - VALUES ($amount, '$date', ".db_escape($trans_type_from).", ".db_escape($trans_no_from).", ".db_escape($trans_no_to) + VALUES (".db_escape($amount).",".db_escape($discount).", '$date', " + .db_escape($trans_type_from).", ".db_escape($trans_no_from).", ".db_escape($trans_no_to) .", ".db_escape($trans_type_to).", ".db_escape($person_id).")"; db_query($sql, "A customer allocation could not be added to the database"); @@ -114,9 +115,10 @@ function get_allocatable_from_cust_sql($customer_id=null, $settled) trans.version, round(abs(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc),6) <= 0 AS settled, trans.debtor_no - FROM " - .TB_PREF."debtor_trans as trans, " + .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," .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+ov_discount > 0)) @@ -128,11 +130,11 @@ function get_allocatable_from_cust_sql($customer_id=null, $settled) if ($customer_id != null) $sql .= " AND trans.debtor_no = ".db_escape($customer_id); - + $sql .= " GROUP BY trans_no, type"; return $sql; } -function get_allocatable_sales_orders($customer_id = null, $trans_no=null, $type=null) +function get_allocatable_sales_orders($customer_id, $trans_no=null, $type=null) { $sql = "SELECT sorder.trans_type as type, @@ -146,7 +148,8 @@ function get_allocatable_sales_orders($customer_id = null, $trans_no=null, $type sorder.delivery_date as due_date, debtor.address, sorder.version, - amt, + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.amt, 0) amt" : "alloc.amt").", + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.discount, 0) discount" : "alloc.discount").", sorder.debtor_no, sorder.branch_code, pmt.early_days, @@ -160,25 +163,29 @@ function get_allocatable_sales_orders($customer_id = null, $trans_no=null, $type WHERE prep_amount>0 AND dt.type=".ST_SALESINVOICE." GROUP BY order_) as invoiced ON sorder.order_no = invoiced.order_ WHERE sorder.trans_type=".ST_SALESORDER; - if ($trans_no != null and $type != null) - { - $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." - AND alloc.trans_type_from=".db_escape($type); - } - else - { - $sql .= " AND round(sorder.prep_amount)>0 and Total>0"; // only sales orders with prepayment level set and no yet fully invoiced - } + $sql .= " AND ((round(sorder.prep_amount)>0 and Total>0)" // only sales orders with prepayment level set and no yet fully invoiced + ." OR (alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type)."))"; + if ($customer_id) $sql .= " AND sorder.debtor_no=".db_escape($customer_id); + elseif (isset($trans_no) && isset($type)) + $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type); $sql .= " GROUP BY sorder.order_no"; return $sql; } + //------------------------------------------------------------------------------------------------------------- +// +// Returns all allocatable sales transactions including all settled with selected payment. +// +// 1. not fully settled; customer_id!=0, trans_no/type!=null (for trans edition) +// 2. for given transaction; customer_id=null, trans_no/type!=null (for transaction view) +// 3. for customer, not fully settled customer_id!=0, trans_no/type=null (non fully settled documents for customer exists) +// 4. for all customers, not fully settled customer_id==0, trans_no/type=null (any non fully settled documents exists) -function get_allocatable_to_cust_transactions($customer_id = null, $trans_no=null, $type=null) +function get_allocatable_to_cust_transactions($customer_id, $trans_no=null, $type=null) { $sql = "SELECT trans.type, @@ -187,54 +194,36 @@ function get_allocatable_to_cust_transactions($customer_id = null, $trans_no=nul trans.tran_date, debtor.name AS DebtorName, debtor.curr_code, - IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount) AS Total, - trans.alloc, + trans.debtor_no, + trans.branch_code, trans.due_date, debtor.address, trans.version, - amt, - trans.debtor_no, - trans.branch_code, + IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount) AS Total, + trans.alloc, + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.amt, 0) amt" : "alloc.amt").", + ".(isset($trans_no) ? "IF(alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . ", alloc.discount, 0) discount" : "alloc.discount").", 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 - 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"; + 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 + LEFT JOIN ".TB_PREF."payment_terms as pmt ON trans.payment_terms=pmt.id + LEFT JOIN ".TB_PREF."debtors_master as debtor ON trans.debtor_no=debtor.debtor_no"; + + $sql .= " WHERE (round(IF(trans.type IN(".ST_CUSTCREDIT.",".ST_BANKDEPOSIT.",".ST_CUSTPAYMENT."),-1,IF(trans.type=".ST_CUSTDELIVERY.",0,1))" + ."*IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-IFNULL(alloc,0),6) > 0 + OR (alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type) . "))"; + if ($customer_id) $sql .= " AND trans.debtor_no=".db_escape($customer_id); + elseif (isset($trans_no) && isset($type)) + $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." AND alloc.trans_type_from=".db_escape($type); - if ($trans_no != null and $type != null) - { - $sql .= " AND alloc.trans_no_from=".db_escape($trans_no)." - AND alloc.trans_type_from=".db_escape($type); - } - else - { - $sql .= " - AND ( - trans.type='".ST_SALESINVOICE."' - AND round(IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0 - OR - trans.type='". ST_CUSTCREDIT."' - AND round(-IF(prep_amount, prep_amount, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)-alloc,6) > 0 - 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"; - } + $sql .= " GROUP BY type, trans_no"; // avoids row multiplication for journal entry containing multiply customers $orders = get_allocatable_sales_orders($customer_id, $trans_no, $type); - $sql = "($sql ORDER BY trans_no) \nUNION \n($orders)"; + $sql = "($sql) \nUNION \n($orders) ORDER BY amt, due_date"; return db_query($sql, "Cannot retreive alloc to transactions"); } @@ -256,7 +245,8 @@ function get_allocatable_from_cust_transactions($customer_id, $trans_no=null, $t trans.due_date, debtor.address, trans.version, - amt, + alloc.amt, + alloc.discount, trans.debtor_no FROM ".TB_PREF."debtor_trans as trans," .TB_PREF."debtors_master as debtor," diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 6cad00f1..348d69fd 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -388,10 +388,15 @@ function write_sales_trans($cart, $policy = 0) } function save_cust_payment($cart, $customer_id, $branch_id, - $bank_account, $trans_date, $ref, $amount, $discount, $memo, $charge, $bank_amount) + $bank_account, $trans_date, $ref, $amount, $memo, $charge, $bank_amount) { begin_transaction(__FUNCTION__, func_get_args()); + $discount = 0; + foreach($cart->allocs as $alloc) + if ($alloc->discount_confirmed) + $discount += $alloc->early_discount*$alloc->amount; + $payment_no = write_customer_payment($cart->trans_no, $customer_id, $branch_id, $bank_account, $trans_date, $ref, $amount, $discount, $memo, 0, $charge, $bank_amount); diff --git a/sql/alter2.5.sql b/sql/alter2.5.sql index dc3a8f61..bc8c1de4 100644 --- a/sql/alter2.5.sql +++ b/sql/alter2.5.sql @@ -81,3 +81,22 @@ ALTER TABLE `0_payment_terms` CHANGE COLUMN `days_before_due` `days` int(11) NOT ALTER TABLE `0_payment_terms` DROP COLUMN `day_in_following_month`; ALTER TABLE `0_payment_terms` ADD COLUMN `early_discount` double NOT NULL DEFAULT '0' AFTER `days`; ALTER TABLE `0_payment_terms` ADD COLUMN `early_days` int(11) NOT NULL DEFAULT '0' AFTER `early_discount`; + +ALTER TABLE `0_cust_allocations` ADD COLUMN `discount` double unsigned DEFAULT '0' AFTER `amt`; +ALTER TABLE `0_supp_allocations` ADD COLUMN `discount` double unsigned DEFAULT '0' AFTER `amt`; + +# please define and set payment terms with discount manually per customer when needed +ALTER TABLE `0_debtors_master` DROP COLUMN `pymt_discount`; + +# this update works only for single pay for invoice discounts, so may need additional manual fixes in more complex cases +UPDATE `0_cust_allocations` ca + LEFT JOIN `0_debtor_trans` pay ON pay.`type`=ca.`trans_type_from` AND pay.`trans_no`=ca.`trans_no_from` + LEFT JOIN `0_debtor_trans` trans ON trans.`type`=ca.`trans_type_to` AND trans.`trans_no`=ca.`trans_no_to` +SET ca.discount=pay.ov_discount + WHERE pay.ov_discount != 0 AND pay.ov_amount+pay.ov_discount = trans.ov_amount+trans.ov_gst+trans.ov_freight+trans.ov_freight_tax; + +UPDATE `0_supp_allocations` sa + LEFT JOIN `0_supp_trans` pay ON pay.`type`=sa.`trans_type_from` AND pay.`trans_no`=sa.`trans_no_from` + LEFT JOIN `0_supp_trans` trans ON trans.`type`=sa.`trans_type_to` AND trans.`trans_no`=sa.`trans_no_to` +SET sa.discount=pay.ov_discount + WHERE pay.ov_discount != 0 AND pay.ov_amount+pay.ov_discount = trans.ov_amount+trans.ov_gst; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 43fc5110..18b69707 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -524,6 +524,7 @@ CREATE TABLE `0_cust_allocations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) DEFAULT NULL, `amt` double unsigned DEFAULT NULL, + `discount` double unsigned DEFAULT '0', `date_alloc` date NOT NULL DEFAULT '0000-00-00', `trans_no_from` int(11) DEFAULT NULL, `trans_type_from` int(11) DEFAULT NULL, @@ -538,10 +539,10 @@ CREATE TABLE `0_cust_allocations` ( -- Data of table `0_cust_allocations` -- INSERT INTO `0_cust_allocations` VALUES -('1', '1', '6240', '2018-05-10', '1', '12', '1', '10'), -('2', '1', '300', '2018-05-07', '2', '12', '2', '10'), -('3', '1', '0', '2018-05-07', '3', '12', '4', '10'), -('4', '1', '1250', '2019-01-21', '4', '12', '5', '10'); +('1', '1', '6240', '0', '2018-05-10', '1', '12', '1', '10'), +('2', '1', '300', '0', '2018-05-07', '2', '12', '2', '10'), +('3', '1', '0', '0', '2018-05-07', '3', '12', '4', '10'), +('4', '1', '1250', '0', '2019-01-21', '4', '12', '5', '10'); -- Structure of table `0_cust_branch` -- @@ -1740,6 +1741,7 @@ CREATE TABLE `0_supp_allocations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) DEFAULT NULL, `amt` double unsigned DEFAULT NULL, + `discount` double unsigned DEFAULT '0', `date_alloc` date NOT NULL DEFAULT '0000-00-00', `trans_no_from` int(11) DEFAULT NULL, `trans_type_from` int(11) DEFAULT NULL, diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 30a44cd8..e5a50316 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -450,6 +450,7 @@ CREATE TABLE `0_cust_allocations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) DEFAULT NULL, `amt` double unsigned DEFAULT NULL, + `discount` double unsigned DEFAULT '0', `date_alloc` date NOT NULL DEFAULT '0000-00-00', `trans_no_from` int(11) DEFAULT NULL, `trans_type_from` int(11) DEFAULT NULL, @@ -1426,6 +1427,7 @@ CREATE TABLE `0_supp_allocations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) DEFAULT NULL, `amt` double unsigned DEFAULT NULL, + `discount` double unsigned DEFAULT '0', `date_alloc` date NOT NULL DEFAULT '0000-00-00', `trans_no_from` int(11) DEFAULT NULL, `trans_type_from` int(11) DEFAULT NULL, -- 2.30.2