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']);
79 $Ajax->activate('summary');
81 //-----------------------------------------------------------------------------
83 function systype_name($row)
85 return systypes::name($row["type"]);
88 function trans_view($row)
90 return get_trans_view_str($row["type"], $row["trans_no"]);
93 function show_details($row)
95 $person = $row["person_id"];
98 if (($row["type"] == 13) || ($row["type"] == 11))
100 $cust_row = get_customer_details_from_trans($row["type"], $row["trans_no"]);
102 if (strlen($cust_row['name']) > 0)
103 $person = $cust_row['name'] . " (" . $cust_row['br_name'] . ")";
106 elseif ($row["type"] == 25 || $row['type'] == 21)
108 // get the supplier name
109 $sql = "SELECT supp_name FROM ".TB_PREF."suppliers WHERE supplier_id = '" . $row["person_id"] . "'";
110 $supp_result = db_query($sql,"check failed");
112 $supp_row = db_fetch($supp_result);
114 if (strlen($supp_row['supp_name']) > 0)
115 $person = $supp_row['supp_name'];
117 elseif ($row["type"] == systypes::location_transfer() || $row["type"] == systypes::inventory_adjustment())
119 // get the adjustment type
120 $movement_type = get_movement_type($row["person_id"]);
121 $person = $movement_type["name"];
123 elseif ($row["type"]==systypes::work_order() || $row["type"] == 28 ||
134 function qty_in($row)
137 return $q <= 0 ? '' : $q;
140 function qty_out($row)
143 return $q <= 0 ? '' : $q;
146 function show_qoh($row)
148 $qoh =& $_SESSION['qoh'];
153 function before_status($pager)
156 array( "<b>"._("Quantity on hand before") . " " . $_POST['AfterDate']
157 .':'."</b>", "align='right' colspan=5");
158 if($pager->sum['beg']>=0) {
159 $r[] = array (number_format2($pager->sum['beg'], $pager->sum['dec']),
161 $r[] = array(" ");
163 $r[] = array(" ");
164 $r[] = array (number_format2($pager->sum['beg'], $pager->sum['dec']),
170 function after_status($pager)
173 array( "<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']
174 .':'."</b>", "align='right' colspan=5");
175 if($pager->sum['end']>=0) {
176 $r[] = array (number_format2($pager->sum['end'], $pager->sum['dec']),
178 $r[] = array(" ", "colspan=2");
180 $r[] = array(" ", "colspan=2");
181 $r[] = array (number_format2($pager->sum['end'], $pager->sum['dec']),
186 //-----------------------------------------------------------------------------
188 $before_date = date2sql($_POST['BeforeDate']);
189 $after_date = date2sql($_POST['AfterDate']);
198 FROM ".TB_PREF."stock_moves
199 WHERE loc_code='" . $_POST['StockLocation'] . "'
200 AND tran_date >= '". $after_date . "'
201 AND tran_date <= '" . $before_date . "'
202 AND stock_id = '" . $_POST['stock_id'] . "'";
205 _("Type") => array('fun'=>'systype_name' ),
206 _("#") => array('fun'=>'trans_view' ),
208 _("Date") => array('date', 'ord'=>'desc'),
209 _("Detail") => array('fun'=>'show_details' ),
210 _("Quantity In") => array('type'=>'amount', 'dec'=> $item_dec, 'insert'=>true,'fun'=>'qty_in' ),
211 _("Quantity Out") => array('type'=>'amount', 'dec'=> $item_dec,'insert'=>true,'fun'=>'qty_out' ),
212 // _("Quantity On Hand") => array('insert'=>true,'type'=>'amount', 'fun'=>'show_qoh' )
215 $table =& new_db_pager('doc_tbl', $sql, $cols);
216 $table->set_header('before_status');
217 $table->set_footer('after_status');
219 if (!$table->ready) // new sql query - update summary
220 get_summary(&$table);
224 display_db_pager($table);