From 7b0f3f68c9aaeffec2f57af1160efaabf7a5abcb Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Wed, 28 May 2008 20:33:11 +0000 Subject: [PATCH] More bugs related to debtor_trans changes (positive amounts) --- CHANGELOG.txt | 7 ++ gl/includes/db/gl_db_banking.inc | 2 + sales/allocations/customer_allocate.php | 3 +- sales/includes/db/custalloc_db.inc | 64 ++++++++++--------- sales/inquiry/customer_allocation_inquiry.php | 8 ++- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 00a7f459..03fc9b2e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,13 @@ Legend: ! -> Note $ -> Affected files +28-May-2008 Joe Hunt +# More bugs related to debtor_trans changes (positive amounts) +$ /gl/includes/db/gl_db_banking.inc + /sales/allocations/customer_allocate.php + /sales/includes/db/custalloc_db.inc + /sales/inquiry/customer_allocation_inquiry.php + 27-May-2008 Joe Hunt # Changed more files with new html/css. $ /includes/page/header.inc diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index 46c81faf..4711baba 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -67,6 +67,8 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_, // convert to customer currency $cust_amount = exchange_from_to($total_amount, $currency, get_customer_currency($person_id), $date_); + // we need to negate it too + $cust_amount = -$cust_amount; $trans_no = write_customer_trans($trans_type, 0, $person_id, $person_detail_id, $date_, $ref, $cust_amount); diff --git a/sales/allocations/customer_allocate.php b/sales/allocations/customer_allocate.php index 74c0573e..a3784720 100644 --- a/sales/allocations/customer_allocate.php +++ b/sales/allocations/customer_allocate.php @@ -168,6 +168,7 @@ function get_allocations_for_transaction($type, $trans_no) sql2date($myrow["tran_date"]), sql2date($myrow["due_date"]), $myrow["Total"], $myrow["alloc"] - $myrow["amt"], $myrow["amt"]); } + } //-------------------------------------------------------------------------------- @@ -200,7 +201,7 @@ function edit_allocations_for_transaction($type, $trans_no) foreach ($_SESSION['alloc']->allocs as $allocn_item) { - alt_table_row_color($k); + alt_table_row_color($k); label_cell(systypes::name($allocn_item->type)); label_cell(get_trans_view_str($allocn_item->type, $allocn_item->type_no)); diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index 88e86745..9dfae6e8 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -2,14 +2,14 @@ //---------------------------------------------------------------------------------------- -function add_cust_allocation($amount, $trans_type_from, $trans_no_from, +function add_cust_allocation($amount, $trans_type_from, $trans_no_from, $trans_type_to, $trans_no_to) { $sql = "INSERT INTO ".TB_PREF."cust_allocations ( - amt, date_alloc, - trans_type_from, trans_no_from, trans_no_to, trans_type_to) + amt, date_alloc, + trans_type_from, trans_no_from, trans_no_to, trans_type_to) VALUES ($amount, Now(), $trans_type_from, $trans_no_from, $trans_no_to, $trans_type_to)"; - + db_query($sql, "A customer allocation could not be added to the database"); } @@ -26,12 +26,12 @@ function delete_cust_allocation($trans_id) function get_DebtorTrans_allocation_balance($trans_type, $trans_no) { - - $sql = "SELECT (ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc) AS BalToAllocate + + $sql = "SELECT (ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc) AS BalToAllocate FROM ".TB_PREF."debtor_trans WHERE trans_no=$trans_no AND type=$trans_type"; $result = db_query($sql,"calculate the allocation"); - $myrow = db_fetch_row($result); - + $myrow = db_fetch_row($result); + return $myrow[0]; } @@ -56,26 +56,26 @@ function void_cust_allocations($type, $type_no) function clear_cust_alloctions($type, $type_no) { // clear any allocations for this transaction - $sql = "SELECT * FROM ".TB_PREF."cust_allocations - WHERE (trans_type_from=$type AND trans_no_from=$type_no) + $sql = "SELECT * FROM ".TB_PREF."cust_allocations + WHERE (trans_type_from=$type AND trans_no_from=$type_no) OR (trans_type_to=$type AND trans_no_to=$type_no)"; $result = db_query($sql, "could not void debtor transactions for type=$type and trans_no=$type_no"); - + while ($row = db_fetch($result)) { $sql = "UPDATE ".TB_PREF."debtor_trans SET alloc=alloc - " . $row['amt'] . " - WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ") + WHERE (type= " . $row['trans_type_from'] . " AND trans_no=" . $row['trans_no_from'] . ") OR (type=" . $row['trans_type_to'] . " AND trans_no=" . $row['trans_no_to'] . ")"; - db_query($sql, "could not clear allocation"); + db_query($sql, "could not clear allocation"); } - + // remove any allocations for this transaction - $sql = "DELETE FROM ".TB_PREF."cust_allocations - WHERE (trans_type_from=$type AND trans_no_from=$type_no) + $sql = "DELETE FROM ".TB_PREF."cust_allocations + WHERE (trans_type_from=$type AND trans_no_from=$type_no) OR (trans_type_to=$type AND trans_no_to=$type_no)"; - - db_query($sql, "could not void debtor transactions for type=$type and trans_no=$type_no"); + + db_query($sql, "could not void debtor transactions for type=$type and trans_no=$type_no"); } //------------------------------------------------------------------------------------------------------------- @@ -83,38 +83,40 @@ function clear_cust_alloctions($type, $type_no) function get_allocatable_from_cust_transactions($customer_id, $settled) { $settled_sql = ""; - if (!$settled) + if (!$settled) { $settled_sql = " AND (round(ov_amount+ov_gst+ov_freight+ov_freight_tax-ov_discount-alloc,6) > 0)"; } $cust_sql = ""; if ($customer_id != null) $cust_sql = " AND ".TB_PREF."debtor_trans.debtor_no = $customer_id"; - - return get_customer_transactions("round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) <= 0 AS settled", - "(type=12 OR type=11) AND (".TB_PREF."debtor_trans.ov_amount > 0) " . $settled_sql . $cust_sql); + + return get_customer_transactions("round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) <= 0 AS settled", + "(type=12 OR type=11 OR type=2) AND (".TB_PREF."debtor_trans.ov_amount > 0) " . $settled_sql . $cust_sql); } //------------------------------------------------------------------------------------------------------------- function get_allocatable_to_cust_transactions($customer_id, $trans_no=null, $type=null) -{ - if ($trans_no != null and $type != null) +{ + if ($trans_no != null and $type != null) { - return get_customer_transactions("amt", "".TB_PREF."debtor_trans.trans_no = ".TB_PREF."cust_allocations.trans_no_to + return get_customer_transactions("amt", "".TB_PREF."debtor_trans.trans_no = ".TB_PREF."cust_allocations.trans_no_to AND ".TB_PREF."debtor_trans.type = ".TB_PREF."cust_allocations.trans_type_to AND ".TB_PREF."cust_allocations.trans_no_from=$trans_no - AND ".TB_PREF."cust_allocations.trans_type_from=$type - AND ".TB_PREF."debtor_trans.debtor_no=$customer_id", - "".TB_PREF."cust_allocations"); - } - else + AND ".TB_PREF."cust_allocations.trans_type_from=$type + AND ".TB_PREF."debtor_trans.debtor_no=$customer_id", + "".TB_PREF."cust_allocations"); + } + else { return get_customer_transactions(null, "round(ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount-alloc,6) > 0 AND ".TB_PREF."debtor_trans.type != " . systypes::cust_payment() . " + AND ".TB_PREF."debtor_trans.type != " . systypes::bank_deposit() . " + AND ".TB_PREF."debtor_trans.type != 11 AND ".TB_PREF."debtor_trans.type != 13 AND ".TB_PREF."debtor_trans.debtor_no=$customer_id"); - } + } } diff --git a/sales/inquiry/customer_allocation_inquiry.php b/sales/inquiry/customer_allocation_inquiry.php index 5606cbf8..b0252561 100644 --- a/sales/inquiry/customer_allocation_inquiry.php +++ b/sales/inquiry/customer_allocation_inquiry.php @@ -172,8 +172,8 @@ while ($myrow = db_fetch($result)) $allocations_str = $allocations; } - elseif ($myrow["type"] == systypes::cust_payment() && - ($myrow['TotalAmount'] + $myrow['Allocated']) > 0) + elseif (($myrow["type"] == systypes::cust_payment() || $myrow["type"] == systypes::bank_deposit()) && + ($myrow['TotalAmount'] - $myrow['Allocated']) > 0) { /*its a receipt which could have an allocation*/ $allocations_str = $allocations; @@ -196,7 +196,9 @@ while ($myrow = db_fetch($result)) label_cell($myrow["CustName"]); label_cell($myrow["CustCurrCode"]); } - display_debit_or_credit_cells($myrow["TotalAmount"]); + display_debit_or_credit_cells( + $myrow['type']==11 || $myrow['type']==12 || $myrow['type']==2 ? + -$myrow["TotalAmount"] : $myrow["TotalAmount"]); amount_cell(abs($myrow["Allocated"])); amount_cell(abs($myrow["TotalAmount"]) - $myrow["Allocated"]); label_cell($allocations_str); -- 2.30.2