Fixed many minor bugs, new ones as well as debtor_trans related.
[fa-stable.git] / sales / inquiry / customer_allocation_inquiry.php
index f8cc1afc04de81fa44aa78697e573d765b5fefd8..5606cbf83df1f5c45328f87fa5787170d9f272f5 100644 (file)
@@ -55,14 +55,16 @@ function get_transactions()
 
     $sql = "SELECT ".TB_PREF."debtor_trans.*,
                ".TB_PREF."debtors_master.name AS CustName, ".TB_PREF."debtors_master.curr_code AS CustCurrCode,
-       (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount)
+       (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
+       .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount)
                AS TotalAmount,
                ".TB_PREF."debtor_trans.alloc AS Allocated,
                ((".TB_PREF."debtor_trans.type = 10)
                AND ".TB_PREF."debtor_trans.due_date < '" . date2sql(Today()) . "') AS OverDue
        FROM ".TB_PREF."debtor_trans, ".TB_PREF."debtors_master
        WHERE ".TB_PREF."debtors_master.debtor_no = ".TB_PREF."debtor_trans.debtor_no
-                       AND (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount != 0)
+                       AND (".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
+                       .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount != 0)
                AND ".TB_PREF."debtor_trans.tran_date >= '$data_after'
                AND ".TB_PREF."debtor_trans.tran_date <= '$date_to'";
 
@@ -71,24 +73,26 @@ function get_transactions()
 
        if (isset($_POST['filterType']) && $_POST['filterType'] != reserved_words::get_all())
        {
-               if ($_POST['filterType'] == '1' || $_POST['filterType'] == '2') 
+               if ($_POST['filterType'] == '1' || $_POST['filterType'] == '2')
                {
                        $sql .= " AND ".TB_PREF."debtor_trans.type = 10 ";
-               } 
-               elseif ($_POST['filterType'] == '3') 
+               }
+               elseif ($_POST['filterType'] == '3')
                {
                        $sql .= " AND ".TB_PREF."debtor_trans.type = " . systypes::cust_payment();
-               } 
-               elseif ($_POST['filterType'] == '4') 
+               }
+               elseif ($_POST['filterType'] == '4')
                {
                        $sql .= " AND ".TB_PREF."debtor_trans.type = 11 ";
                }
 
-       if ($_POST['filterType'] == '2') 
+       if ($_POST['filterType'] == '2')
        {
                $today =  date2sql(Today());
                $sql .= " AND ".TB_PREF."debtor_trans.due_date < '$today'
-                               AND (round(abs(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) > 0) ";
+                               AND (round(abs(".TB_PREF."debtor_trans.ov_amount + "
+                               .TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + "
+                               .TB_PREF."debtor_trans.ov_freight_tax + ".TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) > 0) ";
        }
        }else
        {
@@ -96,9 +100,11 @@ function get_transactions()
        }
 
 
-       if (!check_value('showSettled')) 
+       if (!check_value('showSettled'))
        {
-               $sql .= " AND (round(abs(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + ".TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) != 0) ";
+               $sql .= " AND (round(abs(".TB_PREF."debtor_trans.ov_amount + ".TB_PREF."debtor_trans.ov_gst + "
+               .TB_PREF."debtor_trans.ov_freight + ".TB_PREF."debtor_trans.ov_freight_tax + "
+               .TB_PREF."debtor_trans.ov_discount) - ".TB_PREF."debtor_trans.alloc,6) != 0) ";
        }
 
     $sql .= " ORDER BY ".TB_PREF."debtor_trans.tran_date";
@@ -134,14 +140,14 @@ table_header($th);
 $j = 1;
 $k = 0; //row colour counter
 $over_due = false;
-while ($myrow = db_fetch($result)) 
+while ($myrow = db_fetch($result))
 {
 
        if ($myrow['OverDue'] == 1 && (abs($myrow["TotalAmount"]) - $myrow["Allocated"] != 0))
        {
                start_row("class='overduebg'");
                $over_due = true;
-       } 
+       }
        else
                alt_table_row_color($k);
 
@@ -160,20 +166,20 @@ while ($myrow = db_fetch($result))
 
        if ($myrow["type"] == 10)
                $due_date_str = sql2date($myrow["due_date"]);
-       elseif ($myrow["type"] == 11 && $myrow['TotalAmount'] < 0) 
+       elseif ($myrow["type"] == 11 && $myrow['TotalAmount'] > 0)
        {
                /*its a credit note which could have an allocation */
                $allocations_str = $allocations;
 
-       } 
-       elseif ($myrow["type"] == systypes::cust_payment() && 
-               ($myrow['TotalAmount'] + $myrow['Allocated']) < 0) 
+       }
+       elseif ($myrow["type"] == systypes::cust_payment() &&
+               ($myrow['TotalAmount'] + $myrow['Allocated']) > 0)
        {
                /*its a receipt  which could have an allocation*/
                $allocations_str = $allocations;
 
-       } 
-       elseif ($myrow["type"] == systypes::cust_payment() && $myrow['TotalAmount'] > 0) 
+       }
+       elseif ($myrow["type"] == systypes::cust_payment() && $myrow['TotalAmount'] < 0)
        {
                /*its a negative receipt */
        }
@@ -189,7 +195,7 @@ while ($myrow = db_fetch($result))
        {
                label_cell($myrow["CustName"]);
                label_cell($myrow["CustCurrCode"]);
-       }       
+       }
        display_debit_or_credit_cells($myrow["TotalAmount"]);
        amount_cell(abs($myrow["Allocated"]));
        amount_cell(abs($myrow["TotalAmount"]) - $myrow["Allocated"]);
@@ -211,7 +217,7 @@ while ($myrow = db_fetch($result))
 end_table(1);
 if ($over_due)
        display_note(_("Marked items are overdue."), 0, 1, "class='overduefg'");
-       
+
 end_page();
 
 ?>