Cleanup in db_pager get_sql and testing it.
[fa-stable.git] / sales / includes / db / sales_order_db.inc
index 6ac1e9ddb02b04e658f56480cd8c725d79bc5e9f..e851f747ecab892c10cd9a643463456c45707963 100644 (file)
@@ -464,8 +464,8 @@ function get_branch_to_order($customer_id, $branch_id) {
        OutstandingOnly
        PrepaidOrders
 */
-function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_no, $filter, 
-       $stock_item=null, $from='', $to='', $ref='', $location='', $customer_id=ALL_TEXT)
+function get_sql_for_sales_orders_view($trans_type, $trans_no, $filter, 
+       $stock_item='', $from='', $to='', $ref='', $location=ALL_TEXT, $customer_id=ALL_TEXT)
 {
 
        $sql = "SELECT 
@@ -515,8 +515,7 @@ function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_n
        elseif ($ref != "")
        {
                // search orders with reference like 
-               $number_like = "%".$ref."%";
-               $sql .= " AND sorder.reference LIKE ".db_escape($number_like);
+               $sql .= " AND sorder.reference LIKE ".db_escape('%' . $ref . '%');
 //                             ." GROUP BY sorder.order_no";
        }
        else    // ... or select inquiry constraints
@@ -533,13 +532,13 @@ function get_sql_for_sales_orders_view($selected_customer, $trans_type, $trans_n
                if ($trans_type == ST_SALESQUOTE && !check_value('show_all'))
                        $sql .= " AND sorder.delivery_date >= '".date2sql(Today())."' AND line.qty_sent=0"; // show only outstanding, not realized quotes
 
-               if ($selected_customer != -1)
-                       $sql .= " AND sorder.debtor_no=".db_escape($selected_customer);
+               //if ($selected_customer != -1)
+               //      $sql .= " AND sorder.debtor_no=".db_escape($selected_customer);
 
-               if (isset($stock_item))
+               if ($stock_item != ALL_TEXT)
                        $sql .= " AND line.stk_code=".db_escape($stock_item);
 
-               if ($location)
+               if ($location != ALL_TEXT)
                        $sql .= " AND sorder.from_stk_loc = ".db_escape($location);
 
                if ($filter=='OutstandingOnly')