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