More bugs related to debtor_trans changes (positive amounts)
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 28 May 2008 20:33:11 +0000 (20:33 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 28 May 2008 20:33:11 +0000 (20:33 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_banking.inc
sales/allocations/customer_allocate.php
sales/includes/db/custalloc_db.inc
sales/inquiry/customer_allocation_inquiry.php

index 00a7f459f1a198be8bf0a6375e8e64d448a11b46..03fc9b2e16eafc2f3650e6d26042068969cba839 100644 (file)
@@ -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
index 46c81faf3dde2f955802cdaec2a880a905602a16..4711babae0765b4f500aa34c0caa701c419e5ab4 100644 (file)
@@ -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);
index 74c0573ebbc9356f78e80354d4c695a4faa06fa6..a37847201cd270783c4b7b50f67789ab306577a5 100644 (file)
@@ -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));
index 88e867459cad62b09bdf404c6563012066b0f5fe..9dfae6e8fa0234d2a0360f0d07b1dbca60c2a82b 100644 (file)
@@ -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");
-       }                                                                                                                       
+       }
 }
 
 
index 5606cbf83df1f5c45328f87fa5787170d9f272f5..b02525612cdc0945fdd145f1ec92f8907667f0af 100644 (file)
@@ -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);