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