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