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