-$sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.into_stock_location,
- ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference,
- ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name,
- Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue,
- Sum(".TB_PREF."purch_order_details.delivery_date < '" . $today. "'
- AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received)) As OverDue
- FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
- WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
- AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
- AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location
- AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
-
-if (isset($order_number) && $order_number != "")
-{
- $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
-}
-else
-{
-
- $data_after = date2sql($_POST['OrdersAfterDate']);
- $data_before = date2sql($_POST['OrdersToDate']);
-
- $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
- $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$data_before'";
-
- if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
- {
- $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
- }
-
- if (isset($selected_stock_item))
- {
- $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
- }
-} //end not order number selected
-
-$sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";