6 include($path_to_root . "/includes/db_pager.inc");
7 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/ui.inc");
12 if ($use_popup_windows)
13 $js .= get_js_open_window(800, 500);
15 $js .= get_js_date_picker();
17 if (isset($_GET['outstanding_only']) && $_GET['outstanding_only'])
19 $outstanding_only = 1;
20 page(_("Search Outstanding Dimensions"), false, false, "", $js);
24 $outstanding_only = 0;
25 page(_("Search Dimensions"), false, false, "", $js);
27 //-----------------------------------------------------------------------------------
30 if (get_post('SearchOrders'))
32 $Ajax->activate('dim_table');
33 } elseif (get_post('_OrderNumber_changed'))
35 $disable = get_post('OrderNumber') !== '';
37 $Ajax->addDisable(true, 'FromDate', $disable);
38 $Ajax->addDisable(true, 'ToDate', $disable);
39 $Ajax->addDisable(true, 'type_', $disable);
40 $Ajax->addDisable(true, 'OverdueOnly', $disable);
41 $Ajax->addDisable(true, 'OpenOnly', $disable);
44 // $Ajax->addFocus(true, 'OrderNumber');
45 set_focus('OrderNumber');
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 function view_link($row)
90 return get_dimensions_trans_view_str(systypes::dimension(), $row["id"]);
93 function is_closed($row)
95 return $row['closed'] ? _('Yes') : _('No');
98 function sum_dimension($row)
100 $sql = "SELECT SUM(amount) FROM ".TB_PREF."gl_trans WHERE tran_date >= '" .
101 date2sql($_POST['FromDate']) . "' AND
102 tran_date <= '" . date2sql($_POST['ToDate']) . "' AND (dimension_id = " .
103 $row['id']." OR dimension2_id = " .$row['id'].")";
104 $res = db_query($sql, "Sum of transactions could not be calculated");
105 $row = db_fetch_row($res);
110 function is_overdue($row)
112 return date_diff(Today(), sql2date($row["due_date"]), "d") > 0;
115 function edit_link($row)
117 return $row["closed"] ? '' :
118 pager_link(_("Edit"),
119 "/dimensions/dimension_entry.php?trans_no=" . $row["id"]);
122 $sql = "SELECT dim.id,
129 FROM ".TB_PREF."dimensions as dim WHERE id > 0";
131 if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
133 $sql .= " AND reference LIKE '%". $_POST['OrderNumber'] . "%'";
137 $sql .= " AND type_=1";
139 if (isset($_POST['OpenOnly']))
141 $sql .= " AND closed=0";
144 if (isset($_POST['type_']) && ($_POST['type_'] > 0))
146 $sql .= " AND type_=" . $_POST['type_'];
149 if (isset($_POST['OverdueOnly']))
151 $today = date2sql(Today());
153 $sql .= " AND due_date < '$today' ";
156 $sql .= " AND date_ >= '" . date2sql($_POST['FromDate']) . "'
157 AND date_ <= '" . date2sql($_POST['ToDate']) . "'";
161 _("#") => array('fun'=>'view_link'),
166 _("Due Date") => array('date', 'ord'=>'asc'),
167 _("Closed") => array('fun'=>'is_closed'),
168 _("Balance") => array('type'=>'amount', 'insert'=>true, 'fun'=>'sum_dimension'),
169 array('insert'=>true, 'fun'=>'edit_link')
172 if ($outstanding_only) {
173 $cols[_("Closed")] = 'skip';
176 $table =& new_db_pager('dim_tbl', $sql, $cols);
177 $table->set_marker('is_overdue', _("Marked dimensions are overdue."));
181 display_db_pager($table);