3e239d8e9eec6ddd67a27bc63b877d885e3ac632
[fa-stable.git] / purchasing / inquiry / po_search_completed.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 2;
13 $path_to_root="../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include($path_to_root . "/includes/session.inc");
16
17 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
19 $js = "";
20 if ($use_popup_windows)
21         $js .= get_js_open_window(900, 500);
22 if ($use_date_picker)
23         $js .= get_js_date_picker();
24 page(_("Search Purchase Orders"), false, false, "", $js);
25
26 if (isset($_GET['order_number']))
27 {
28         $order_number = $_GET['order_number'];
29 }
30
31 //-----------------------------------------------------------------------------------
32 // Ajax updates
33 //
34 if (get_post('SearchOrders')) 
35 {
36         $Ajax->activate('orders_tbl');
37 } elseif (get_post('_order_number_changed')) 
38 {
39         $disable = get_post('order_number') !== '';
40
41         $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
42         $Ajax->addDisable(true, 'OrdersToDate', $disable);
43         $Ajax->addDisable(true, 'StockLocation', $disable);
44         $Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
45         $Ajax->addDisable(true, 'SelectStockFromList', $disable);
46
47         if ($disable) {
48                 $Ajax->addFocus(true, 'order_number');
49         } else
50                 $Ajax->addFocus(true, 'OrdersAfterDate');
51
52         $Ajax->activate('orders_tbl');
53 }
54 //---------------------------------------------------------------------------------------------
55
56 start_form(false, true);
57
58 start_table("class='tablestyle_noborder'");
59 start_row();
60 ref_cells(_("#:"), 'order_number', '',null, '', true);
61
62 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
63 date_cells(_("to:"), 'OrdersToDate');
64
65 locations_list_cells(_("into location:"), 'StockLocation', null, true);
66
67 stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
68
69 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), true);
70 end_row();
71 end_table();
72 end_form();
73 //---------------------------------------------------------------------------------------------
74 if (isset($_POST['order_number']))
75 {
76         $order_number = $_POST['order_number'];
77 }
78
79 if (isset($_POST['SelectStockFromList']) &&     ($_POST['SelectStockFromList'] != "") &&
80         ($_POST['SelectStockFromList'] != reserved_words::get_all()))
81 {
82         $selected_stock_item = $_POST['SelectStockFromList'];
83 }
84 else
85 {
86         unset($selected_stock_item);
87 }
88
89 //---------------------------------------------------------------------------------------------
90 function trans_view($trans)
91 {
92         return get_trans_view_str(systypes::po(), $trans["order_no"]);
93 }
94
95 function prt_link($row)
96 {
97         return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
98 }
99
100 //---------------------------------------------------------------------------------------------
101
102 $sql = "SELECT 
103         porder.order_no, 
104         porder.reference, 
105         supplier.supp_name, 
106         location.location_name,
107         porder.requisition_no, 
108         porder.ord_date, 
109         supplier.curr_code, 
110         Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
111         porder.into_stock_location
112         FROM ".TB_PREF."purch_orders as porder, "
113                 .TB_PREF."purch_order_details as line, "
114                 .TB_PREF."suppliers as supplier, "
115                 .TB_PREF."locations as location
116         WHERE porder.order_no = line.order_no
117         AND porder.supplier_id = supplier.supplier_id
118         AND location.loc_code = porder.into_stock_location ";
119
120 if (isset($order_number) && $order_number != "")
121 {
122         $sql .= "AND porder.reference LIKE '%". $order_number . "%'";
123 }
124 else
125 {
126
127         $data_after = date2sql($_POST['OrdersAfterDate']);
128         $date_before = date2sql($_POST['OrdersToDate']);
129
130         $sql .= " AND porder.ord_date >= '$data_after'";
131         $sql .= " AND porder.ord_date <= '$date_before'";
132
133         if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
134         {
135                 $sql .= " AND porder.into_stock_location = '". $_POST['StockLocation'] . "' ";
136         }
137         if (isset($selected_stock_item))
138         {
139                 $sql .= " AND line.item_code='". $selected_stock_item ."' ";
140         }
141
142 } //end not order number selected
143
144 $sql .= " GROUP BY porder.order_no";
145
146 $cols = array(
147                 _("#") => array('fun'=>'trans_view', 'ord'=>''), 
148                 _("Reference"), 
149                 _("Supplier") => array('ord'=>''),
150                 _("Location"),
151                 _("Supplier's Reference"), 
152                 _("Order Date") => array('name'=>'ord_date', 'type'=>'date', 'ord'=>'desc'),
153                 _("Currency") => array('align'=>'center'), 
154                 _("Order Total") => 'amount',
155                 array('insert'=>true, 'fun'=>'prt_link'),
156 );
157
158 if (get_post('StockLocation') != $all_items) {
159         $cols[_("Location")] = 'skip';
160 }
161 //---------------------------------------------------------------------------------------------------
162
163 $table =& new_db_pager('orders_tbl', $sql, $cols);
164
165 if (get_post('SearchOrders')) {
166         $table->set_sql($sql);
167         $table->set_columns($cols);
168 }
169 $table->width = "80%";
170 start_form();
171
172 display_db_pager($table);
173
174 end_form();
175 end_page();
176 ?>