Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / dimensions / inquiry / search_dimensions.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_DIMTRANSVIEW';
13 $path_to_root="../..";
14
15 include($path_to_root . "/includes/db_pager.inc");
16 include_once($path_to_root . "/includes/session.inc");
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/reporting/includes/reporting.inc");
21 $js = "";
22 if ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if (user_use_date_picker())
25         $js .= get_js_date_picker();
26
27 if (isset($_GET['outstanding_only']) && $_GET['outstanding_only'])
28 {
29         $outstanding_only = 1;
30         page(_($help_context = "Search Outstanding Dimensions"), false, false, "", $js);
31 }
32 else
33 {
34         $outstanding_only = 0;
35         page(_($help_context = "Search Dimensions"), false, false, "", $js);
36 }
37 //-----------------------------------------------------------------------------------
38 // Ajax updates
39 //
40 if (get_post('SearchOrders'))
41 {
42         $Ajax->activate('dim_table');
43 } elseif (get_post('_OrderNumber_changed'))
44 {
45         $disable = get_post('OrderNumber') !== '';
46
47         $Ajax->addDisable(true, 'FromDate', $disable);
48         $Ajax->addDisable(true, 'ToDate', $disable);
49         $Ajax->addDisable(true, 'type_', $disable);
50         $Ajax->addDisable(true, 'OverdueOnly', $disable);
51         $Ajax->addDisable(true, 'OpenOnly', $disable);
52
53         if ($disable) {
54                 set_focus('OrderNumber');
55         } else
56                 set_focus('type_');
57
58         $Ajax->activate('dim_table');
59 }
60
61 //--------------------------------------------------------------------------------------
62
63 if (isset($_GET["stock_id"]))
64         $_POST['SelectedStockItem'] = $_GET["stock_id"];
65
66 //--------------------------------------------------------------------------------------
67
68 start_form(false, false, $_SERVER['PHP_SELF'] ."?outstanding_only=$outstanding_only");
69
70 start_table(TABLESTYLE_NOBORDER);
71 start_row();
72
73 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
74
75 number_list_cells(_("Type"), 'type_', null, 1, 2, _("All"));
76 date_cells(_("From:"), 'FromDate', '', null, 0, 0, -5);
77 date_cells(_("To:"), 'ToDate');
78
79 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
80
81 if (!$outstanding_only)
82 {
83         check_cells( _("Only Open:"), 'OpenOnly', null);
84 }
85 else
86         $_POST['OpenOnly'] = 1;
87
88 submit_cells('SearchOrders', _("Search"), '', '', 'default');
89
90 end_row();
91 end_table();
92
93 $dim = get_company_pref('use_dimension');
94
95 function view_link($row) 
96 {
97         return get_dimensions_trans_view_str(ST_DIMENSION, $row["id"]);
98 }
99
100 function sum_dimension($row) 
101 {
102         return get_dimension_balance($row['id'], $_POST['FromDate'], $_POST['ToDate']); 
103 }
104
105 function is_closed($row)
106 {
107         return $row['closed'] ? _('Yes') : _('No');
108 }
109
110 function is_overdue($row)
111 {
112         return date_diff2(Today(), sql2date($row["due_date"]), "d") > 0;
113 }
114
115 function edit_link($row)
116 {
117         return pager_link(_("Edit"),
118                         "/dimensions/dimension_entry.php?trans_no=" . $row["id"], ICON_EDIT);
119 }
120
121 function prt_link($row)
122 {
123         return print_document_link($row['id'], _("Print"), true, ST_DIMENSION, ICON_PRINT);
124 }
125
126
127 $sql = get_sql_for_search_dimensions($dim, $_POST['FromDate'], $_POST['ToDate'],
128         $_POST['OrderNumber'], $_POST['type_'], check_value('OpenOnly'), check_value('OverdueOnly'));
129
130 $cols = array(
131         _("#") => array('fun'=>'view_link'), 
132         _("Reference"), 
133         _("Name"), 
134         _("Type"), 
135         _("Date") =>'date',
136         _("Due Date") => array('name'=>'due_date', 'type'=>'date', 'ord'=>'asc'), 
137         _("Closed") => array('fun'=>'is_closed'),
138         _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'sum_dimension'),
139         array('insert'=>true, 'fun'=>'edit_link'),
140         array('insert'=>true, 'fun'=>'prt_link')
141 );
142
143 if ($outstanding_only) {
144         $cols[_("Closed")] = 'skip';
145 }
146
147 $table =& new_db_pager('dim_tbl', $sql, $cols);
148 $table->set_marker('is_overdue', _("Marked dimensions are overdue."));
149
150 $table->width = "80%";
151
152 display_db_pager($table);
153
154 end_form();
155 end_page();
156