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/banking.inc");
11 include_once($path_to_root . "/sales/includes/sales_db.inc");
13 include_once($path_to_root . "/includes/ui.inc");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(800, 500);
18 $js .= get_js_date_picker();
20 page(_("Inventory Item Movement"), false, false, "", $js);
21 //------------------------------------------------------------------------------------------------
23 check_db_has_stock_items(_("There are no items defined in the system."));
25 if (isset($_GET['stock_id']))
27 $_POST['stock_id'] = $_GET['stock_id'];
30 start_form(false, true);
32 if (!isset($_POST['stock_id']))
33 $_POST['stock_id'] = get_global_stock_item();
35 start_table("class='tablestyle_noborder'");
37 stock_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
39 locations_list_cells(_("From Location:"), 'StockLocation', null);
41 date_cells(_("From:"), 'AfterDate', '', null, -30);
42 date_cells(_("To:"), 'BeforeDate');
44 submit_cells('ShowMoves',_("Show Movements"),'',_('Refresh Inquiry'), true);
48 set_global_stock_item($_POST['stock_id']);
49 $item_dec = get_qty_dec($_POST['stock_id']);
51 // Get summary displayed in headewr and footer.
53 function get_summary(&$table)
55 global $Ajax, $item_dec;
59 Sum(IF(qty>0, qty, 0)) as in_qty,
60 Sum(IF(qty<0, -qty, 0)) as out_qty
61 FROM ".TB_PREF."stock_moves
62 WHERE loc_code='" . $_POST['StockLocation'] . "'
63 AND tran_date >= '". date2sql($_POST['AfterDate']) . "'
64 AND tran_date <= '" . date2sql($_POST['BeforeDate']) . "'
65 AND stock_id = '" . $_POST['stock_id'] . "'";
67 $result = db_query($sql, "cannot retrieve stock moves");
69 $qty = db_fetch($result);
71 $sum['beg'] = get_qoh_on_date($_POST['stock_id'], $_POST['StockLocation'],
72 add_days($_POST['AfterDate'], -1));
73 $sum['in'] = $qty['in_qty'];
74 $sum['out'] = $qty['out_qty'];
75 $sum['end'] = $sum['beg'] + $qty['sum'];
76 $sum['dec'] = $item_dec = get_qty_dec($_POST['stock_id']);
80 //-----------------------------------------------------------------------------
82 function systype_name($row)
84 return systypes::name($row["type"]);
87 function trans_view($row)
89 return get_trans_view_str($row["type"], $row["trans_no"]);
92 function show_details($row)
94 $person = $row["person_id"];
97 if (($row["type"] == 13) || ($row["type"] == 11))
99 $cust_row = get_customer_details_from_trans($row["type"], $row["trans_no"]);
101 if (strlen($cust_row['name']) > 0)
102 $person = $cust_row['name'] . " (" . $cust_row['br_name'] . ")";
105 elseif ($row["type"] == 25 || $row['type'] == 21)
107 // get the supplier name
108 $sql = "SELECT supp_name FROM ".TB_PREF."suppliers WHERE supplier_id = '" . $row["person_id"] . "'";
109 $supp_result = db_query($sql,"check failed");
111 $supp_row = db_fetch($supp_result);
113 if (strlen($supp_row['supp_name']) > 0)
114 $person = $supp_row['supp_name'];
116 elseif ($row["type"] == systypes::location_transfer() || $row["type"] == systypes::inventory_adjustment())
118 // get the adjustment type
119 $movement_type = get_movement_type($row["person_id"]);
120 $person = $movement_type["name"];
122 elseif ($row["type"]==systypes::work_order() || $row["type"] == 28 ||
133 function qty_in($row)
136 return $q <= 0 ? '' : $q;
139 function qty_out($row)
142 return $q <= 0 ? '' : $q;
145 function show_qoh($row)
147 $qoh =& $_SESSION['qoh'];
152 function before_status($pager)
155 array( "<b>"._("Quantity on hand before") . " " . $_POST['AfterDate']
156 .':'."</b>", "align='right' colspan=5");
157 if($pager->sum['beg']>=0) {
158 $r[] = array (number_format2($pager->sum['beg'], $pager->sum['dec']),
160 $r[] = array(" ");
162 $r[] = array(" ");
163 $r[] = array (number_format2($pager->sum['beg'], $pager->sum['dec']),
169 function after_status($pager)
172 array( "<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']
173 .':'."</b>", "align='right' colspan=5");
174 if($pager->sum['end']>=0) {
175 $r[] = array (number_format2($pager->sum['end'], $pager->sum['dec']),
177 $r[] = array(" ");
179 $r[] = array(" ");
180 $r[] = array (number_format2($pager->sum['end'], $pager->sum['dec']),
185 //-----------------------------------------------------------------------------
187 $before_date = date2sql($_POST['BeforeDate']);
188 $after_date = date2sql($_POST['AfterDate']);
197 FROM ".TB_PREF."stock_moves
198 WHERE loc_code='" . $_POST['StockLocation'] . "'
199 AND tran_date >= '". $after_date . "'
200 AND tran_date <= '" . $before_date . "'
201 AND stock_id = '" . $_POST['stock_id'] . "'";
204 _("Type") => array('fun'=>'systype_name' ),
205 _("#") => array('fun'=>'trans_view' ),
207 _("Date") => array('date', 'ord'=>'desc'),
208 _("Detail") => array('fun'=>'show_details' ),
209 _("Quantity In") => array('type'=>'qty', 'dec'=> $item_dec, 'insert'=>true,'fun'=>'qty_in' ),
210 _("Quantity Out") => array('type'=>'qty', 'dec'=> $item_dec,'insert'=>true,'fun'=>'qty_out' ),
211 // _("Quantity On Hand") => array('insert'=>true,'type'=>'amount', 'fun'=>'show_qoh' )
214 $table =& new_db_pager('doc_tbl', $sql, $cols);
215 $table->set_header('before_status');
216 $table->set_footer('after_status');
218 if (!$table->ready) // new sql query - update summary
221 if (get_post('ShowMoves')) {
222 $table->set_sql($sql);
223 $table->set_columns($cols);
227 display_db_pager($table);