5 include($path_to_root . "/includes/session.inc");
7 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
8 include_once($path_to_root . "/reporting/includes/reporting.inc");
11 if ($use_popup_windows)
12 $js .= get_js_open_window(900, 500);
14 $js .= get_js_date_picker();
15 page(_("Search Outstanding Purchase Orders"), false, false, "", $js);
17 if (isset($_GET['order_number']))
19 $_POST['order_number'] = $_GET['order_number'];
21 //-----------------------------------------------------------------------------------
24 if (get_post('SearchOrders'))
26 $Ajax->activate('orders_tbl');
27 } elseif (get_post('_order_number_changed'))
29 $disable = get_post('order_number') !== '';
31 $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
32 $Ajax->addDisable(true, 'OrdersToDate', $disable);
33 $Ajax->addDisable(true, 'StockLocation', $disable);
34 $Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
35 $Ajax->addDisable(true, 'SelectStockFromList', $disable);
38 $Ajax->addFocus(true, 'order_number');
40 $Ajax->addFocus(true, 'OrdersAfterDate');
42 $Ajax->activate('orders_tbl');
46 //---------------------------------------------------------------------------------------------
48 start_form(false, true);
50 start_table("class='tablestyle_noborder'");
52 ref_cells(_("#:"), 'order_number', '',null, '', true);
54 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
55 date_cells(_("to:"), 'OrdersToDate');
57 locations_list_cells(_("Location:"), 'StockLocation', null, true);
59 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
61 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
67 //---------------------------------------------------------------------------------------------
69 if (isset($_POST['order_number']) && ($_POST['order_number'] != ""))
71 $order_number = $_POST['order_number'];
74 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
75 ($_POST['SelectStockFromList'] != $all_items))
77 $selected_stock_item = $_POST['SelectStockFromList'];
81 unset($selected_stock_item);
84 $today = date2sql(Today());
86 //figure out the sql required from the inputs available
87 $sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.into_stock_location,
88 ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference,
89 ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name,
90 Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue,
91 Sum(".TB_PREF."purch_order_details.delivery_date < '" . $today. "'
92 AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received)) As OverDue
93 FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
94 WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
95 AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
96 AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location
97 AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
99 if (isset($order_number) && $order_number != "")
101 $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
106 $data_after = date2sql($_POST['OrdersAfterDate']);
107 $data_before = date2sql($_POST['OrdersToDate']);
109 $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
110 $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$data_before'";
112 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
114 $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
117 if (isset($selected_stock_item))
119 $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
121 } //end not order number selected
123 $sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
125 $result = db_query($sql,"No orders were returned");
127 /*show a table of the orders returned by the sql */
129 div_start('orders_tbl');
130 start_table("$table_style colspan=7 width=80%");
132 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
133 $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
134 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
136 $th = array(_("#"), _("Reference"), _("Supplier"),
137 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
142 $k = 0; //row colour counter
143 $overdue_items = false;
144 while ($myrow = db_fetch($result))
147 if ($myrow["OverDue"] == 1)
149 start_row("class='overduebg'");
150 $overdue_items = true;
154 alt_table_row_color($k);
157 $modify = "$path_to_root/purchasing/po_entry_items.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
158 $receive = "$path_to_root/purchasing/po_receive_items.php?" . SID . "PONumber=" . $myrow["order_no"];
160 $date = sql2date($myrow["ord_date"]);
162 label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
163 label_cell($myrow["reference"]);
164 label_cell($myrow["supp_name"]);
165 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
166 label_cell($myrow["location_name"]);
167 label_cell($myrow["requisition_no"]);
169 label_cell($myrow["curr_code"]);
170 amount_cell($myrow["OrderValue"]);
171 label_cell("<a href=$modify>" . _("Edit") . "</a>");
172 label_cell(print_document_link($myrow['order_no'], _("Print"), true, 18));
173 label_cell("<a href=$receive>" . _("Receive") . "</a>");
182 //end of page full new headings if
189 display_note(_("Marked orders have overdue items."), 0, 1, "class='overduefg'");