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