2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 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/gpl-3.0.html>.
11 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/db_pager.inc");
15 include($path_to_root . "/includes/session.inc");
17 include($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
20 if ($use_popup_windows)
21 $js .= get_js_open_window(900, 500);
23 $js .= get_js_date_picker();
24 page(_("Search Purchase Orders"), false, false, "", $js);
26 if (isset($_GET['order_number']))
28 $order_number = $_GET['order_number'];
31 //-----------------------------------------------------------------------------------
34 if (get_post('SearchOrders'))
36 $Ajax->activate('orders_tbl');
37 } elseif (get_post('_order_number_changed'))
39 $disable = get_post('order_number') !== '';
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);
48 $Ajax->addFocus(true, 'order_number');
50 $Ajax->addFocus(true, 'OrdersAfterDate');
52 $Ajax->activate('orders_tbl');
54 //---------------------------------------------------------------------------------------------
58 start_table("class='tablestyle_noborder'");
60 ref_cells(_("#:"), 'order_number', '',null, '', true);
62 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
63 date_cells(_("to:"), 'OrdersToDate');
65 locations_list_cells(_("into location:"), 'StockLocation', null, true);
67 stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
69 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
73 //---------------------------------------------------------------------------------------------
74 if (isset($_POST['order_number']))
76 $order_number = $_POST['order_number'];
79 if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
80 ($_POST['SelectStockFromList'] != reserved_words::get_all()))
82 $selected_stock_item = $_POST['SelectStockFromList'];
86 unset($selected_stock_item);
89 //---------------------------------------------------------------------------------------------
90 function trans_view($trans)
92 return get_trans_view_str(systypes::po(), $trans["order_no"]);
95 function edit_link($row)
97 return pager_link( _("Edit"),
98 "/purchasing/po_entry_items.php?" . SID
99 . "ModifyOrderNumber=" . $row["order_no"], ICON_EDIT);
102 function prt_link($row)
104 return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
107 //---------------------------------------------------------------------------------------------
113 location.location_name,
114 porder.requisition_no,
117 Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
118 porder.into_stock_location
119 FROM ".TB_PREF."purch_orders as porder, "
120 .TB_PREF."purch_order_details as line, "
121 .TB_PREF."suppliers as supplier, "
122 .TB_PREF."locations as location
123 WHERE porder.order_no = line.order_no
124 AND porder.supplier_id = supplier.supplier_id
125 AND location.loc_code = porder.into_stock_location ";
127 if (isset($order_number) && $order_number != "")
129 $sql .= "AND porder.reference LIKE '%". $order_number . "%'";
134 $data_after = date2sql($_POST['OrdersAfterDate']);
135 $date_before = date2sql($_POST['OrdersToDate']);
137 $sql .= " AND porder.ord_date >= '$data_after'";
138 $sql .= " AND porder.ord_date <= '$date_before'";
140 if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != reserved_words::get_all())
142 $sql .= " AND porder.into_stock_location = '". $_POST['StockLocation'] . "' ";
144 if (isset($selected_stock_item))
146 $sql .= " AND line.item_code='". $selected_stock_item ."' ";
149 } //end not order number selected
151 $sql .= " GROUP BY porder.order_no";
154 _("#") => array('fun'=>'trans_view', 'ord'=>''),
156 _("Supplier") => array('ord'=>''),
158 _("Supplier's Reference"),
159 _("Order Date") => array('name'=>'ord_date', 'type'=>'date', 'ord'=>'desc'),
160 _("Currency") => array('align'=>'center'),
161 _("Order Total") => 'amount',
162 array('insert'=>true, 'fun'=>'edit_link'),
163 array('insert'=>true, 'fun'=>'prt_link'),
166 if (get_post('StockLocation') != $all_items) {
167 $cols[_("Location")] = 'skip';
169 //---------------------------------------------------------------------------------------------------
171 $table =& new_db_pager('orders_tbl', $sql, $cols);
173 if (get_post('SearchOrders')) {
174 $table->set_sql($sql);
175 $table->set_columns($cols);
177 $table->width = "80%";
180 display_db_pager($table);