From 9481e23e6d03f39f7d9e745f86bd1be5f703b96d Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Fri, 13 Oct 2017 16:10:17 +0200 Subject: [PATCH] A bug in Customer Allocations fixed. --- sales/allocations/customer_allocate.php | 7 ++++++- sales/allocations/customer_allocation_main.php | 9 +++++++-- sales/includes/db/custalloc_db.inc | 7 ++++--- sales/inquiry/customer_allocation_inquiry.php | 2 +- sales/inquiry/customer_inquiry.php | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sales/allocations/customer_allocate.php b/sales/allocations/customer_allocate.php index ab3a3001..8c051386 100644 --- a/sales/allocations/customer_allocate.php +++ b/sales/allocations/customer_allocate.php @@ -46,7 +46,12 @@ function edit_allocations_for_transaction($type, $trans_no) global $systypes_array; $cart = $_SESSION['alloc']; - + + if ($cart->type == ST_JOURNAL && $cart->bank_amount < 0) + { + $cart->bank_amount = -$cart->bank_amount; + $cart->amount = -$cart->amount; + } display_heading(sprintf(_("Allocation of %s # %d"), $systypes_array[$cart->type], $cart->trans_no)); display_heading($cart->person_name); diff --git a/sales/allocations/customer_allocation_main.php b/sales/allocations/customer_allocation_main.php index 5059735f..56d4312f 100644 --- a/sales/allocations/customer_allocation_main.php +++ b/sales/allocations/customer_allocation_main.php @@ -70,9 +70,14 @@ function alloc_link($row) .$row["trans_no"] . "&trans_type=" . $row["type"]. "&debtor_no=" . $row["debtor_no"], ICON_ALLOC); } +function amount_total($row) +{ + return price_format($row['type'] == ST_JOURNAL && $row["Total"] < 0 ? -$row["Total"] : $row["Total"]); +} + function amount_left($row) { - return price_format($row["Total"]-$row["alloc"]); + return price_format(($row['type'] == ST_JOURNAL && $row["Total"] < 0 ? -$row["Total"] : $row["Total"])-$row["alloc"]); } function check_settled($row) @@ -90,7 +95,7 @@ $cols = array( _("Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>'asc'), _("Customer") => array('ord'=>''), _("Currency") => array('align'=>'center'), - _("Total") => 'amount', + _("Total") => array('align'=>'right','fun'=>'amount_total'), _("Left to Allocate") => array('align'=>'right','insert'=>true, 'fun'=>'amount_left'), array('insert'=>true, 'fun'=>'alloc_link') ); diff --git a/sales/includes/db/custalloc_db.inc b/sales/includes/db/custalloc_db.inc index 42eaff59..ec7c3afb 100644 --- a/sales/includes/db/custalloc_db.inc +++ b/sales/includes/db/custalloc_db.inc @@ -119,8 +119,9 @@ 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))" - ." OR ( (type=".ST_CUSTCREDIT. " OR type=".ST_JOURNAL. ") AND (ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount)>0))"; + AND (((type=".ST_CUSTPAYMENT." OR type=".ST_BANKDEPOSIT.") AND (trans.ov_amount > 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)"; @@ -216,7 +217,7 @@ function get_allocatable_to_cust_transactions($customer_id = null, $trans_no=nul 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>0 OR trans.type = '". ST_BANKPAYMENT."' AND ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount>0 diff --git a/sales/inquiry/customer_allocation_inquiry.php b/sales/inquiry/customer_allocation_inquiry.php index 2bd2d58e..5630f04d 100644 --- a/sales/inquiry/customer_allocation_inquiry.php +++ b/sales/inquiry/customer_allocation_inquiry.php @@ -87,7 +87,7 @@ function due_date($row) function fmt_balance($row) { - return $row["TotalAmount"] - $row["Allocated"]; + return ($row["type"] == ST_JOURNAL && $row["TotalAmount"] < 0 ? -$row["TotalAmount"] : $row["TotalAmount"]) - $row["Allocated"]; } function alloc_link($row) diff --git a/sales/inquiry/customer_inquiry.php b/sales/inquiry/customer_inquiry.php index e93f1d43..184e7e3b 100644 --- a/sales/inquiry/customer_inquiry.php +++ b/sales/inquiry/customer_inquiry.php @@ -138,7 +138,7 @@ function gl_view($row) function fmt_amount($row) { $value = - $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT || $row['type']==ST_JOURNAL ? + $row['type']==ST_CUSTCREDIT || $row['type']==ST_CUSTPAYMENT || $row['type']==ST_BANKDEPOSIT ? -$row["TotalAmount"] : $row["TotalAmount"]; return price_format($value); } -- 2.30.2