2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_ITEMSTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
16 include_once($path_to_root . "/includes/date_functions.inc");
17 include_once($path_to_root . "/includes/banking.inc");
18 include_once($path_to_root . "/sales/includes/sales_db.inc");
20 include_once($path_to_root . "/includes/ui.inc");
24 if ($use_popup_windows)
25 $js .= get_js_open_window(800, 500);
27 $js .= get_js_date_picker();
28 page(_($help_context = "Inventory Item Movement"), @$_GET['popup'], false, "", $js);
30 //------------------------------------------------------------------------------------------------
32 check_db_has_stock_items(_("There are no items defined in the system."));
34 if(get_post('ShowMoves'))
36 $Ajax->activate('doc_tbl');
39 if (isset($_GET['stock_id']))
41 $_POST['stock_id'] = $_GET['stock_id'];
47 if (!isset($_POST['stock_id']))
48 $_POST['stock_id'] = get_global_stock_item();
50 start_table(TABLESTYLE_NOBORDER);
53 stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
57 start_table(TABLESTYLE_NOBORDER);
60 locations_list_cells(_("From Location:"), 'StockLocation', null);
62 date_cells(_("From:"), 'AfterDate', '', null, -30);
63 date_cells(_("To:"), 'BeforeDate');
65 submit_cells('ShowMoves',_("Show Movements"),'',_('Refresh Inquiry'), 'default');
71 set_global_stock_item($_POST['stock_id']);
73 $before_date = date2sql($_POST['BeforeDate']);
74 $after_date = date2sql($_POST['AfterDate']);
76 $result = get_stock_movements($_POST['stock_id'], $_POST['StockLocation'],
77 $_POST['BeforeDate'], $_POST['AfterDate']);
80 start_table(TABLESTYLE);
81 $th = array(_("Type"), _("#"), _("Reference"), _("Date"), _("Detail"),
82 _("Quantity In"), _("Quantity Out"), _("Quantity On Hand"));
86 $before_qty = get_stock_movements_before($_POST['stock_id'], $_POST['StockLocation'], $_POST['AfterDate']);
88 $after_qty = $before_qty;
91 if (!isset($before_qty_row[0]))
93 $after_qty = $before_qty = 0;
96 start_row("class='inquirybg'");
97 label_cell("<b>"._("Quantity on hand before") . " " . $_POST['AfterDate']."</b>", "align=center colspan=5");
98 label_cell(" ", "colspan=2");
99 $dec = get_qty_dec($_POST['stock_id']);
100 qty_cell($before_qty, false, $dec);
104 $k = 0; //row colour counter
109 while ($myrow = db_fetch($result))
112 alt_table_row_color($k);
114 $trandate = sql2date($myrow["tran_date"]);
116 $type_name = $systypes_array[$myrow["type"]];
118 if ($myrow["qty"] > 0)
120 $quantity_formatted = number_format2($myrow["qty"], $dec);
121 $total_in += $myrow["qty"];
125 $quantity_formatted = number_format2(-$myrow["qty"], $dec);
126 $total_out += -$myrow["qty"];
128 $after_qty += $myrow["qty"];
130 label_cell($type_name);
132 label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]));
134 label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"], $myrow["reference"]));
135 label_cell($trandate);
137 $person = $myrow["person_id"];
140 if (($myrow["type"] == ST_CUSTDELIVERY) || ($myrow["type"] == ST_CUSTCREDIT))
142 $cust_row = get_customer_details_from_trans($myrow["type"], $myrow["trans_no"]);
144 if (strlen($cust_row['name']) > 0)
145 $person = $cust_row['name'] . " (" . $cust_row['br_name'] . ")";
148 elseif ($myrow["type"] == ST_SUPPRECEIVE || $myrow['type'] == ST_SUPPCREDIT)
150 // get the supplier name
151 $supp_name = get_supplier_name($myrow["person_id"]);
153 if (strlen($supp_name) > 0)
154 $person = $supp_name;
156 elseif ($myrow["type"] == ST_LOCTRANSFER || $myrow["type"] == ST_INVADJUST)
158 // get the adjustment type
159 $movement_type = get_movement_type($myrow["person_id"]);
160 $person = $movement_type["name"];
162 elseif ($myrow["type"]==ST_WORKORDER || $myrow["type"] == ST_MANUISSUE ||
163 $myrow["type"] == ST_MANURECEIVE)
170 label_cell((($myrow["qty"] >= 0) ? $quantity_formatted : ""), "nowrap align=right");
171 label_cell((($myrow["qty"] < 0) ? $quantity_formatted : ""), "nowrap align=right");
172 qty_cell($after_qty, false, $dec);
180 //end of page full new headings if
184 start_row("class='inquirybg'");
185 label_cell("<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']."</b>", "align=center colspan=5");
186 qty_cell($total_in, false, $dec);
187 qty_cell($total_out, false, $dec);
188 qty_cell($after_qty, false, $dec);
193 if (!@$_GET['popup'])
194 end_page(@$_GET['popup'], false, false);