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