Added supplier search in Outstanding Purchase Orders and Purchase Orders Inquiry.
[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 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 ***********************************************************************/
12 $page_security = 'SA_SUPPTRANSVIEW';
13 $path_to_root="../..";
14 include_once($path_to_root . "/includes/db_pager.inc");
15 include_once($path_to_root . "/includes/session.inc");
16
17 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
18 include_once($path_to_root . "/reporting/includes/reporting.inc");
19 if (!@$_GET['popup'])
20 {
21         $js = "";
22         if ($use_popup_windows)
23                 $js .= get_js_open_window(900, 500);
24         if ($use_date_picker)
25                 $js .= get_js_date_picker();
26         page(_($help_context = "Search Purchase Orders"), false, false, "", $js);
27 }
28 if (isset($_GET['order_number']))
29 {
30         $order_number = $_GET['order_number'];
31 }
32
33 //-----------------------------------------------------------------------------------
34 // Ajax updates
35 //
36 if (get_post('SearchOrders')) 
37 {
38         $Ajax->activate('orders_tbl');
39 } elseif (get_post('_order_number_changed')) 
40 {
41         $disable = get_post('order_number') !== '';
42
43         $Ajax->addDisable(true, 'OrdersAfterDate', $disable);
44         $Ajax->addDisable(true, 'OrdersToDate', $disable);
45         $Ajax->addDisable(true, 'StockLocation', $disable);
46         $Ajax->addDisable(true, '_SelectStockFromList_edit', $disable);
47         $Ajax->addDisable(true, 'SelectStockFromList', $disable);
48
49         if ($disable) {
50                 $Ajax->addFocus(true, 'order_number');
51         } else
52                 $Ajax->addFocus(true, 'OrdersAfterDate');
53
54         $Ajax->activate('orders_tbl');
55 }
56 //---------------------------------------------------------------------------------------------
57
58 if (!@$_GET['popup'])
59         start_form();
60
61 start_table(TABLESTYLE_NOBORDER);
62 start_row();
63 ref_cells(_("#:"), 'order_number', '',null, '', true);
64
65 date_cells(_("from:"), 'OrdersAfterDate', '', null, -30);
66 date_cells(_("to:"), 'OrdersToDate');
67
68 locations_list_cells(_("into location:"), 'StockLocation', null, true);
69 end_row();
70 end_table();
71
72 start_table(TABLESTYLE_NOBORDER);
73 start_row();
74
75 stock_items_list_cells(_("for item:"), 'SelectStockFromList', null, true);
76
77 if (!@$_GET['popup'])
78         supplier_list_cells(_("Select a supplier: "), 'supplier_id', null, true, true);
79
80 submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
81 end_row();
82 end_table(1);
83 //---------------------------------------------------------------------------------------------
84 if (isset($_POST['order_number']))
85 {
86         $order_number = $_POST['order_number'];
87 }
88
89 if (isset($_POST['SelectStockFromList']) &&     ($_POST['SelectStockFromList'] != "") &&
90         ($_POST['SelectStockFromList'] != ALL_TEXT))
91 {
92         $selected_stock_item = $_POST['SelectStockFromList'];
93 }
94 else
95 {
96         unset($selected_stock_item);
97 }
98
99 //---------------------------------------------------------------------------------------------
100 function trans_view($trans)
101 {
102         return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
103 }
104
105 function edit_link($row) 
106 {
107         if (@$_GET['popup'])
108                 return '';
109         return pager_link( _("Edit"),
110                 "/purchasing/po_entry_items.php?" . SID 
111                 . "ModifyOrderNumber=" . $row["order_no"], ICON_EDIT);
112 }
113
114 function prt_link($row)
115 {
116         return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
117 }
118
119 //---------------------------------------------------------------------------------------------
120
121 $sql = get_sql_for_po_search_completed(!@$_GET['popup'] ? $_POST['supplier_id'] : ALL_TEXT);
122
123 $cols = array(
124                 _("#") => array('fun'=>'trans_view', 'ord'=>''), 
125                 _("Reference"), 
126                 _("Supplier") => array('ord'=>''),
127                 _("Location"),
128                 _("Supplier's Reference"), 
129                 _("Order Date") => array('name'=>'ord_date', 'type'=>'date', 'ord'=>'desc'),
130                 _("Currency") => array('align'=>'center'), 
131                 _("Order Total") => 'amount',
132                 array('insert'=>true, 'fun'=>'edit_link'),
133                 array('insert'=>true, 'fun'=>'prt_link'),
134 );
135
136 if (get_post('StockLocation') != $all_items) {
137         $cols[_("Location")] = 'skip';
138 }
139 //---------------------------------------------------------------------------------------------------
140
141 $table =& new_db_pager('orders_tbl', $sql, $cols);
142
143 $table->width = "80%";
144
145 display_db_pager($table);
146
147 if (!@$_GET['popup'])
148 {
149         end_form();
150         end_page();
151 }       
152 ?>