Feature 5740: On prepaid Sales Orders, Have a "Receive Customer Payment" option on...
[fa-stable.git] / sales / includes / db / sales_order_db.inc
index f2c62840cc8d7fb7ef9c34789a6136a0295b3d9d..a8be2045f062878dc77b9b87f93c87292792c63f 100644 (file)
@@ -465,7 +465,7 @@ function get_branch_to_order($customer_id, $branch_id) {
        PrepaidOrders
 */
 function get_sql_for_sales_orders_view($trans_type, $trans_no, $filter, 
-       $stock_item='', $from='', $to='', $ref='', $location=ALL_TEXT, $customer_id=ALL_TEXT, $show_voided = 0)
+       $stock_item='', $from='', $to='', $ref='', $location=ALL_TEXT, $customer_id=ALL_TEXT, $show_voided = 0, $by_delivery=0, $no_auto=0)
 {
     if ($filter=='OutstandingOnly')
         $order_value = 'Sum(line.unit_price*(line.quantity-line.qty_sent)*(1-line.discount_percent))+freight_cost';
@@ -530,10 +530,12 @@ function get_sql_for_sales_orders_view($trans_type, $trans_no, $filter,
                {
                        $date_after = date2sql($from);
                        $date_before = date2sql($to);
-
-                       $sql .=  " AND sorder.ord_date >= '$date_after'"
-                                       ." AND sorder.ord_date <= '$date_before'";
+                       $by_date = $by_delivery ? 'delivery_date' : 'ord_date';
+                       $sql .=  " AND sorder.$by_date >= '$date_after'"
+                                       ." AND sorder.$by_date <= '$date_before'";
                }
+               if ($no_auto)
+                   $sql .= " AND sorder.reference != 'auto'";
        }
                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