6 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/includes/date_functions.inc");
9 include_once($path_to_root . "/includes/ui.inc");
11 if ($use_popup_windows)
12 $js .= get_js_open_window(800, 500);
14 $js .= get_js_date_picker();
16 if (isset($_GET['outstanding_only']) && $_GET['outstanding_only'])
18 $outstanding_only = 1;
19 page(_("Search Outstanding Dimensions"), false, false, "", $js);
23 $outstanding_only = 0;
24 page(_("Search Dimensions"), false, false, "", $js);
26 //-----------------------------------------------------------------------------------
29 if (get_post('SearchOrders'))
31 $Ajax->activate('dim_table');
32 } elseif (get_post('_OrderNumber_changed'))
34 $disable = get_post('OrderNumber') !== '';
36 $Ajax->addDisable(true, 'FromDate', $disable);
37 $Ajax->addDisable(true, 'ToDate', $disable);
38 $Ajax->addDisable(true, 'type_', $disable);
39 $Ajax->addDisable(true, 'OverdueOnly', $disable);
40 $Ajax->addDisable(true, 'OpenOnly', $disable);
43 // $Ajax->addFocus(true, 'OrderNumber');
44 set_focus('OrderNumber');
46 // $Ajax->addFocus(true, 'StockLocation');
49 $Ajax->activate('dim_table');
52 //--------------------------------------------------------------------------------------
54 if (isset($_GET["stock_id"]))
55 $_POST['SelectedStockItem'] = $_GET["stock_id"];
57 //--------------------------------------------------------------------------------------
59 start_form(false, true, $_SERVER['PHP_SELF'] ."?outstanding_only=" . $outstanding_only . SID);
61 start_table("class='tablestyle_noborder'");
64 ref_cells(_("Reference:"), 'OrderNumber', '',null, '', true);
66 number_list_cells(_("Type"), 'type_', null, 1, 2, _("All"));
67 date_cells(_("From:"), 'FromDate', '', null, 0, 0, -5);
68 date_cells(_("To:"), 'ToDate');
70 check_cells( _("Only Overdue:"), 'OverdueOnly', null);
72 if (!$outstanding_only)
74 check_cells( _("Only Open:"), 'OpenOnly', null);
77 $_POST['OpenOnly'] = 1;
79 submit_cells('SearchOrders', _("Search"), '', '', true);
86 $dim = get_company_pref('use_dimension');
88 $sql = "SELECT * FROM ".TB_PREF."dimensions WHERE id > 0";
90 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
92 $sql .= " AND reference LIKE '%". $_POST['OrderNumber'] . "%'";
96 $sql .= " AND type_=1";
98 if (isset($_POST['OpenOnly']))
100 $sql .= " AND closed=0";
103 if (isset($_POST['type_']) && ($_POST['type_'] > 0))
105 $sql .= " AND type_=" . $_POST['type_'];
108 if (isset($_POST['OverdueOnly']))
110 $today = date2sql(Today());
112 $sql .= " AND due_date < '$today' ";
115 $sql .= " AND date_ >= '" . date2sql($_POST['FromDate']) . "'
116 AND date_ <= '" . date2sql($_POST['ToDate']) . "'";
118 $sql .= " ORDER BY due_date";
120 $result = db_query($sql,"could not query dimensions");
122 div_start('dim_table');
123 start_table("$table_style width=80%");
125 if (!$outstanding_only)
126 $th = array(_("#"), _("Reference"), _("Name"), _("Type"), _("Date"),
127 _("Due Date"), _("Closed"), _("Balance"));
129 $th = array(_("#"), _("Reference"), _("Name"), _("Type"), _("Date"),
130 _("Due Date"), _("Balance"));
135 while ($myrow = db_fetch($result))
137 $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE tran_date >= '" .
138 date2sql($_POST['FromDate']) . "' AND
139 tran_date <= '" . date2sql($_POST['ToDate']) . "' AND (dimension_id = " .
140 $myrow['id']." OR dimension2_id = " .$myrow['id'].")";
141 $res = db_query($sql, "Transactions could not be calculated");
142 $row = db_fetch_row($res);
146 $row_text = "class='oddrow'";
151 $row_text = "class='evenrow'";
155 // check if it's an overdue work order
156 if (date_diff(Today(), sql2date($myrow["due_date"]), "d") > 0)
158 $row_text = "class='overduebg'";
161 start_row($row_text);
163 $mpage = $path_to_root . "/dimensions/dimension_entry.php?" . SID . "trans_no=" . $myrow["id"];
165 label_cell(get_dimensions_trans_view_str(systypes::dimension(), $myrow["id"]));
166 label_cell(get_dimensions_trans_view_str(systypes::dimension(), $myrow["id"], $myrow["reference"]));
167 label_cell($myrow["name"]);
168 label_cell($myrow["type_"]);
169 label_cell(sql2date($myrow["date_"]));
170 label_cell(sql2date($myrow["due_date"]));
171 if (!$outstanding_only)
172 label_cell(($myrow["closed"] ? _("Yes") : _("No")));
173 amount_cell($row[0]);
175 label_cell($myrow["closed"] == 0 ? ("<a href='$mpage'>" . _("Edit") . "</a>") :'');
184 //end of page full new headings if
190 //---------------------------------------------------------------------------------