8b9d1b35c959d7bb1110cc404486d3ef2e975ff8
[fa-stable.git] / dimensions / inquiry / search_dimensions.php
1 <?php
2
3 $page_security = 2;
4 $path_to_root="../..";
5
6 include_once($path_to_root . "/includes/session.inc");
7
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10 $js = "";
11 if ($use_popup_windows)
12         $js .= get_js_open_window(800, 500);
13 if ($use_date_picker)
14         $js .= get_js_date_picker();
15
16 if (isset($_GET['outstanding_only']) && $_GET['outstanding_only'])
17 {
18         $outstanding_only = 1;
19         page(_("Search Outstanding Dimensions"), false, false, "", $js);
20 }
21 else
22 {
23         $outstanding_only = 0;
24         page(_("Search Dimensions"), false, false, "", $js);
25 }
26
27 //--------------------------------------------------------------------------------------
28
29 if (isset($_GET["stock_id"]))
30         $_POST['SelectedStockItem'] = $_GET["stock_id"];
31
32 //--------------------------------------------------------------------------------------
33
34 start_form(false, true, $_SERVER['PHP_SELF'] ."?outstanding_only=" . $outstanding_only . SID);
35
36 start_table("class='tablestyle_noborder'");
37 start_row();
38
39 ref_cells(_("Reference:"), 'OrderNumber', null);
40
41 number_list_cells(_("Type"), 'type_', null, 0, 2);
42 date_cells(_("From:"), 'FromDate', null, 0, 0, -5);
43 date_cells(_("To:"), 'ToDate');
44
45 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
46
47 if (!$outstanding_only)
48 {
49         check_cells( _("Only Open:"), 'OpenOnly', null);
50 }
51 else
52         $_POST['OpenOnly'] = 1;
53
54 submit_cells('SearchOrders', _("Search"));
55
56 end_row();
57 end_table();
58
59 end_form();
60
61 $dim = get_company_pref('use_dimension');
62
63 $sql = "SELECT * FROM ".TB_PREF."dimensions WHERE id > 0";
64
65 if ($dim == 1)
66         $sql .= " AND type_=1";
67
68 if (isset($_POST['OpenOnly']))
69 {
70         $sql .= " AND closed=0";
71 }
72
73 if (isset($_POST['type_']) && ($_POST['type_'] > 0))
74 {
75         $sql .= " AND type_=" . $_POST['type_'];
76 }
77
78 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
79 {
80         $sql .= " AND reference LIKE '%". $_POST['OrderNumber'] . "%'";
81 }
82
83 if (isset($_POST['OverdueOnly']))
84 {
85         $today = date2sql(Today());
86
87         $sql .= " AND due_date < '$today' ";
88 }
89
90 $sql .= " AND date_ >= '" . date2sql($_POST['FromDate']) . "'
91         AND date_ <= '" . date2sql($_POST['ToDate']) . "'";
92
93 $sql .= " ORDER BY due_date";
94
95 $result = db_query($sql,"could not query dimensions");
96
97 start_table("$table_style width=80%");
98
99 if (!$outstanding_only)
100         $th = array(_("#"), _("Reference"), _("Name"), _("Type"), _("Date"),
101                 _("Due Date"), _("Closed"), _("Balance"));
102 else
103         $th = array(_("#"), _("Reference"), _("Name"), _("Type"), _("Date"),
104                 _("Due Date"), _("Balance"));
105 table_header($th);
106 $j = 1;
107 $k = 0;
108
109 while ($myrow = db_fetch($result))
110 {
111         $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE tran_date >= '" .
112                 date2sql($_POST['FromDate']) . "' AND
113                 tran_date <= '" . date2sql($_POST['ToDate']) . "' AND dimension_id = " .
114                 $myrow['id'];
115         $res = db_query($sql, "Transactions could not be calculated");
116         $row = db_fetch_row($res);
117
118         if ($k == 1)
119         {
120                 $row_text = "class='oddrow'";
121                 $k = 0;
122         }
123         else
124         {
125                 $row_text = "class='evenrow'";
126                 $k++;
127         }
128
129         // check if it's an overdue work order
130         if (date_diff(Today(), sql2date($myrow["due_date"]), "d") > 0)
131         {
132                 $row_text = "class='overduebg'";
133         }
134
135         start_row($row_text);
136
137         $mpage = $path_to_root . "/dimensions/dimension_entry.php?" . SID . "trans_no=" . $myrow["id"];
138
139         label_cell(get_dimensions_trans_view_str(systypes::dimension(), $myrow["id"]));
140         label_cell(get_dimensions_trans_view_str(systypes::dimension(), $myrow["id"], $myrow["reference"]));
141         label_cell($myrow["name"]);
142         label_cell($myrow["type_"]);
143         label_cell(sql2date($myrow["date_"]));
144         label_cell(sql2date($myrow["due_date"]));
145         if (!$outstanding_only)
146                 label_cell(($myrow["closed"] ? _("Yes") : _("No")));
147         amount_cell($row[0]);
148         if ($myrow["closed"] == 0)
149                 label_cell("<a href='$mpage'>" . _("Edit") . "</a>");
150         end_row();
151
152         $j++;
153         If ($j == 12)
154         {
155                 $j = 1;
156                 table_header($th);
157         }
158         //end of page full new headings if
159 }
160 //end of while loop
161
162 end_table(1);
163
164 //---------------------------------------------------------------------------------
165
166 end_page();
167
168 ?>