Added print document options in inquiries.
[fa-stable.git] / purchasing / inquiry / po_search.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
10 $js = "";
11 if ($use_popup_windows)
12         $js .= get_js_open_window(900, 500);
13 if ($use_date_picker)
14         $js .= get_js_date_picker();
15 page(_("Search Outstanding Purchase Orders"), false, false, "", $js);
16
17 if (isset($_GET['order_number']))
18 {
19         $_POST['order_number'] = $_GET['order_number'];
20 }
21
22 //---------------------------------------------------------------------------------------------
23
24 start_form(false, true);
25
26 start_table("class='tablestyle_noborder'");
27 start_row();
28 ref_cells(_("#:"), 'order_number');
29
30 date_cells(_("from:"), 'OrdersAfterDate', null, -30);
31 date_cells(_("to:"), 'OrdersToDate');
32
33 locations_list_cells(_("Location:"), 'StockLocation', null, true);
34
35 stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true);
36
37 submit_cells('SearchOrders', _("Search"));
38 end_row();
39 end_table();
40
41 end_form();
42
43 //---------------------------------------------------------------------------------------------
44
45 if (isset($_POST['order_number']) && ($_POST['order_number'] != ""))
46 {
47         $order_number = $_POST['order_number'];
48 }
49
50 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
51         ($_POST['SelectStockFromList'] != $all_items))
52 {
53         $selected_stock_item = $_POST['SelectStockFromList'];
54 }
55 else
56 {
57         unset($selected_stock_item);
58 }
59
60 $today = date2sql(Today());
61
62 //figure out the sql required from the inputs available
63 $sql = "SELECT ".TB_PREF."purch_orders.order_no, ".TB_PREF."suppliers.supp_name, ".TB_PREF."purch_orders.into_stock_location,
64         ".TB_PREF."purch_orders.ord_date, ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference,
65         ".TB_PREF."suppliers.curr_code, ".TB_PREF."locations.location_name,
66         Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue,
67         Sum(".TB_PREF."purch_order_details.delivery_date < '" . $today. "'
68         AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received)) As OverDue
69         FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
70         WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
71         AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
72         AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location
73         AND (".TB_PREF."purch_order_details.quantity_ordered > ".TB_PREF."purch_order_details.quantity_received) ";
74
75 if (isset($order_number) && $order_number != "")
76 {
77         $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
78 }
79 else
80 {
81
82         $data_after = date2sql($_POST['OrdersAfterDate']);
83         $data_before = date2sql($_POST['OrdersToDate']);
84
85         $sql .= "  AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
86         $sql .= "  AND ".TB_PREF."purch_orders.ord_date <= '$data_before'";
87
88         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
89         {
90                 $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
91         }
92
93         if (isset($selected_stock_item))
94         {
95                 $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
96         }
97 } //end not order number selected
98
99 $sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
100
101 $result = db_query($sql,"No orders were returned");
102
103 print_hidden_script(18);
104
105 /*show a table of the orders returned by the sql */
106
107 start_table("$table_style colspan=7 width=80%");
108
109 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
110         $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
111                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
112 else
113         $th = array(_("#"), _("Reference"), _("Supplier"),
114                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"","","");
115
116 table_header($th);
117
118 $j = 1;
119 $k = 0; //row colour counter
120 $overdue_items = false;
121 while ($myrow = db_fetch($result))
122 {
123
124         if ($myrow["OverDue"] == 1)
125         {
126                  start_row("class='overduebg'");
127                  $overdue_items = true;
128         }
129         else
130         {
131                 alt_table_row_color($k);
132         }
133
134         $modify = "$path_to_root/purchasing/po_entry_items.php?" . SID . "ModifyOrderNumber=" . $myrow["order_no"];
135         $receive = "$path_to_root/purchasing/po_receive_items.php?" . SID . "PONumber=" . $myrow["order_no"];
136
137         $date = sql2date($myrow["ord_date"]);
138
139         label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
140         label_cell($myrow["reference"]);
141         label_cell($myrow["supp_name"]);
142         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == $all_items)
143                 label_cell($myrow["location_name"]);
144         label_cell($myrow["requisition_no"]);
145         label_cell($date);
146         label_cell($myrow["curr_code"]);
147         amount_cell($myrow["OrderValue"]);
148         label_cell("<a href=$modify>" . _("Edit") . "</a>");
149         label_cell(print_document_link($myrow['order_no'], _("Print")));
150         label_cell("<a href=$receive>" . _("Receive") . "</a>");
151         end_row();
152
153         $j++;
154         If ($j == 12)
155         {
156                 $j = 1;
157                 table_header($th);
158         }
159 //end of page full new headings if
160 }
161 //end of while loop
162
163 end_table();
164
165 if ($overdue_items)
166         display_note(_("Marked orders have overdue items."), 0, 1, "class='overduefg'");
167
168 end_page();
169 ?>