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