Fixed focus after error display.
[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 // Ajax updates
23 //
24 if (get_post('SearchOrders')) 
25 {
26         $Ajax->activate('orders_tbl');
27 } elseif (get_post('_order_number_changed')) 
28 {
29         $disable = get_post('order_number') !== '';
30
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);
36
37         if ($disable) {
38                 $Ajax->addFocus(true, 'order_number');
39         } else
40                 $Ajax->addFocus(true, 'OrdersAfterDate');
41
42         $Ajax->activate('orders_tbl');
43 }
44 //---------------------------------------------------------------------------------------------
45
46 start_form(false, true);
47
48 start_table("class='tablestyle_noborder'");
49 start_row();
50 ref_cells(_("#:"), 'order_number', '',null, '', true);
51
52 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
53 date_cells(_("to:"), 'OrdersToDate');
54
55 locations_list_cells(_("into location:"), 'StockLocation', null, true);
56
57 stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
58
59 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
60 end_row();
61 end_table();
62
63 end_form();
64
65 //---------------------------------------------------------------------------------------------
66
67 if (isset($_POST['order_number']))
68 {
69         $order_number = $_POST['order_number'];
70 }
71
72 if (isset($_POST['SelectStockFromList']) &&     ($_POST['SelectStockFromList'] != "") &&
73         ($_POST['SelectStockFromList'] != reserved_words::get_all()))
74 {
75         $selected_stock_item = $_POST['SelectStockFromList'];
76 }
77 else
78 {
79         unset($selected_stock_item);
80 }
81
82 //---------------------------------------------------------------------------------------------
83
84 //figure out the sql required from the inputs available
85 $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,
86         ".TB_PREF."purch_orders.requisition_no, ".TB_PREF."purch_orders.reference, ".TB_PREF."locations.location_name,
87         ".TB_PREF."suppliers.curr_code, Sum(".TB_PREF."purch_order_details.unit_price*".TB_PREF."purch_order_details.quantity_ordered) AS OrderValue
88         FROM ".TB_PREF."purch_orders, ".TB_PREF."purch_order_details, ".TB_PREF."suppliers, ".TB_PREF."locations
89         WHERE ".TB_PREF."purch_orders.order_no = ".TB_PREF."purch_order_details.order_no
90         AND ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
91         AND ".TB_PREF."locations.loc_code = ".TB_PREF."purch_orders.into_stock_location ";
92
93 if (isset($order_number) && $order_number != "")
94 {
95         $sql .= "AND ".TB_PREF."purch_orders.reference LIKE '%". $order_number . "%'";
96 }
97 else
98 {
99
100         $data_after = date2sql($_POST['OrdersAfterDate']);
101         $date_before = date2sql($_POST['OrdersToDate']);
102
103         $sql .= " AND ".TB_PREF."purch_orders.ord_date >= '$data_after'";
104         $sql .= " AND ".TB_PREF."purch_orders.ord_date <= '$date_before'";
105
106         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
107         {
108                 $sql .= " AND ".TB_PREF."purch_orders.into_stock_location = '". $_POST['StockLocation'] . "' ";
109         }
110         if (isset($selected_stock_item))
111         {
112                 $sql .= " AND ".TB_PREF."purch_order_details.item_code='". $selected_stock_item ."' ";
113         }
114
115 } //end not order number selected
116
117 $sql .= " GROUP BY ".TB_PREF."purch_orders.order_no";
118
119 $result = db_query($sql,"No orders were returned");
120
121 div_start('orders_tbl');
122 start_table("$table_style colspan=7 width=80%");
123
124 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
125         $th = array(_("#"), _("Reference"), _("Supplier"), _("Location"),
126                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"");
127 else
128         $th = array(_("#"), _("Reference"), _("Supplier"),
129                 _("Supplier's Reference"), _("Order Date"), _("Currency"), _("Order Total"),"");
130
131 table_header($th);
132
133 $j = 1;
134 $k = 0; //row colour counter
135 while ($myrow = db_fetch($result))
136 {
137
138         alt_table_row_color($k);
139
140         $date = sql2date($myrow["ord_date"]);
141
142         label_cell(get_trans_view_str(systypes::po(), $myrow["order_no"]));
143         label_cell($myrow["reference"]);
144         label_cell($myrow["supp_name"]);
145         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] == reserved_words::get_all())
146                 label_cell($myrow["location_name"]);
147         label_cell($myrow["requisition_no"]);
148         label_cell($date);
149         label_cell($myrow["curr_code"]);
150         amount_cell($myrow["OrderValue"]);
151         label_cell(print_document_link($myrow['order_no'], _("Print"), true, 18));
152         end_row();
153
154         $j++;
155         if ($j == 12)
156         {
157                 $j = 1;
158                 table_header($th);
159         }
160 }
161
162 end_table(2);
163 div_end();
164 //---------------------------------------------------------------------------------------------------
165
166 end_page();
167 ?>