*** empty log message ***
[fa-stable.git] / purchasing / inquiry / po_search_completed.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
8 $js = "";
9 if ($use_popup_windows)
10         $js .= get_js_open_window(900, 500);
11 page(_("Search Purchase Orders"), false, false, "", $js);
12
13 if (isset($_GET['order_number']))
14 {
15         $order_number = $_GET['order_number'];
16 }
17
18 //---------------------------------------------------------------------------------------------
19
20 start_form(false, true);
21
22 start_table("class='tablestyle_noborder'");
23 start_row();
24 ref_cells(_("#:"), 'order_number');
25
26 date_cells(_("from:"), 'OrdersAfterDate', null, -30);
27 date_cells(_("to:"), 'OrdersToDate');
28
29 locations_list_cells(_("into location:"), 'StockLocation', null, true);
30
31 stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
32
33 submit_cells('SearchOrders', _("Search"));
34 end_row();
35 end_table();
36
37 end_form();
38
39 //---------------------------------------------------------------------------------------------
40
41 if (isset($_POST['order_number']))
42 {
43         $order_number = $_POST['order_number'];
44 }
45
46 if (isset($_POST['SelectStockFromList']) &&     ($_POST['SelectStockFromList'] != "") &&
47         ($_POST['SelectStockFromList'] != reserved_words::get_all()))
48 {
49         $selected_stock_item = $_POST['SelectStockFromList'];
50
51 else 
52 {
53         unset($selected_stock_item);
54 }
55
56 //---------------------------------------------------------------------------------------------
57
58 //figure out the sql required from the inputs available
59 $sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.into_stock_location,
60         ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference, ".TB_PREF."locations.location_name,
61         ".TB_PREF."suppliers.curr_code, Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue
62         FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
63         WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
64         AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
65         AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location ";
66
67 if (isset($order_number) && $order_number != "") 
68 {
69         $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
70
71 else 
72 {
73
74         $data_after = date2sql($_POST['OrdersAfterDate']);
75         $date_before = date2sql($_POST['OrdersToDate']);
76
77         $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
78         $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$date_before'";
79
80         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all()) 
81         {
82                 $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
83         }
84         if (isset($selected_stock_item)) 
85         {
86                 $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
87         }
88
89 } //end not order number selected
90
91 $sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
92
93 $result = db_query($sql,"No orders were returned");
94
95 start_table("$table_style colspan=7 width=80%");
96
97 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
98         $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
99                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"));
100 else            
101         $th = array(_("#"), _("Reference"), _("Supplier"), 
102                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"));
103
104 table_header($th);
105
106 $j = 1;
107 $k = 0; //row colour counter
108 while ($myrow = db_fetch($result)) 
109 {
110
111         alt_table_row_color($k);
112
113         $date = sql2date($myrow["ord_date"]);
114
115         label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
116         label_cell($myrow["reference"]);
117         label_cell($myrow["supp_name"]);
118         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
119                 label_cell($myrow["location_name"]);
120         label_cell($myrow["requisition_no"]);
121         label_cell($date);
122         label_cell($myrow["curr_code"]);
123         amount_cell($myrow["OrderValue"]);
124         end_row();
125
126         $j++;
127         if ($j == 12)
128         {
129                 $j = 1;
130                 table_header($th);
131         }
132 }
133
134 end_table(2);
135
136 //---------------------------------------------------------------------------------------------------
137
138 end_page();
139 ?>