5 include($path_to_root . "/includes/session.inc");
7 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
10 if ($use_popup_windows)
11 $js .= get_js_open_window(900, 500);
12 page(_("Search Outstanding Purchase Orders"), false, false, "", $js);
14 if (isset($_GET['order_number']))
16 $_POST['order_number'] = $_GET['order_number'];
19 //---------------------------------------------------------------------------------------------
21 start_form(false, true);
23 start_table("class='tablestyle_noborder'");
25 ref_cells(_("#:"), 'order_number');
27 date_cells(_("from:"), 'OrdersAfterDate', null, -30);
28 date_cells(_("to:"), 'OrdersToDate');
30 locations_list_cells(_("Location:"), 'StockLocation', null, true);
32 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
34 submit_cells('SearchOrders', _("Search"));
40 //---------------------------------------------------------------------------------------------
42 if (isset($_POST['order_number']) && ($_POST['order_number'] != ""))
44 $order_number = $_POST['order_number'];
47 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
48 ($_POST['SelectStockFromList'] != $all_items))
50 $selected_stock_item = $_POST['SelectStockFromList'];
54 unset($selected_stock_item);
57 $today = date2sql(Today());
59 //figure out the sql required from the inputs available
60 $sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.into_stock_location,
61 ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference,
62 ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name,
63 Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue,
64 Sum(".TB_PREF."purch_order_details.delivery_date < '" . $today. "'
65 AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received)) As OverDue
66 FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
67 WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
68 AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
69 AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location
70 AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
72 if (isset($order_number) && $order_number != "")
74 $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
79 $data_after = date2sql($_POST['OrdersAfterDate']);
80 $data_before = date2sql($_POST['OrdersToDate']);
82 $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
83 $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$data_before'";
85 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
87 $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
90 if (isset($selected_stock_item))
92 $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
94 } //end not order number selected
96 $sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
98 $result = db_query($sql,"No orders were returned");
100 /*show a table of the orders returned by the sql */
102 start_table("$table_style colspan=7 width=80%");
104 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
105 $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
106 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"));
108 $th = array(_("#"), _("Reference"), _("Supplier"),
109 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"));
114 $k = 0; //row colour counter
115 $overdue_items = false;
116 while ($myrow = db_fetch($result))
119 if ($myrow["OverDue"] == 1)
121 start_row("class='overduebg'");
122 $overdue_items = true;
126 alt_table_row_color($k);
129 $modify = "$path_to_root/purchasing/po_entry_items.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
130 $receive = "$path_to_root/purchasing/po_receive_items.php?" . SID . "PONumber=" . $myrow["order_no"];
132 $date = sql2date($myrow["ord_date"]);
134 label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
135 label_cell($myrow["reference"]);
136 label_cell($myrow["supp_name"]);
137 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
138 label_cell($myrow["location_name"]);
139 label_cell($myrow["requisition_no"]);
141 label_cell($myrow["curr_code"]);
142 amount_cell($myrow["OrderValue"]);
143 label_cell("<a href=$modify>" . _("Edit") . "</a>");
144 label_cell("<a href=$receive>" . _("Receive") . "</a>");
153 //end of page full new headings if
160 display_note(_("Marked orders have overdue items."), 0, 1, "class='overduefg'");