Rerun of implemented Selectable Print Orientation (Portrait, Landscape) for all repor...
[fa-stable.git] / inventory / inquiry / stock_movements.php
1 <?php
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");
15
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");
19
20 include_once($path_to_root . "/includes/ui.inc");
21 $js = "";
22 if ($use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if ($use_date_picker)
25         $js .= get_js_date_picker();
26 page(_($help_context = "Inventory Item Movement"), @$_GET['popup'], false, "", $js);
27 //------------------------------------------------------------------------------------------------
28
29 check_db_has_stock_items(_("There are no items defined in the system."));
30
31 if(get_post('ShowMoves'))
32 {
33         $Ajax->activate('doc_tbl');
34 }
35
36 if (isset($_GET['stock_id']))
37 {
38         $_POST['stock_id'] = $_GET['stock_id'];
39 }
40
41 start_form();
42
43 if (!isset($_POST['stock_id']))
44         $_POST['stock_id'] = get_global_stock_item();
45
46 start_table(TABLESTYLE_NOBORDER);
47 start_row();
48 if (!$page_nested)
49         stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
50 end_row();
51 end_table();
52
53 start_table(TABLESTYLE_NOBORDER);
54 start_row();
55
56 locations_list_cells(_("From Location:"), 'StockLocation', null);
57
58 date_cells(_("From:"), 'AfterDate', '', null, -$_SESSION["wa_current_user"]->prefs->transaction_days());
59 date_cells(_("To:"), 'BeforeDate');
60
61 submit_cells('ShowMoves',_("Show Movements"),'',_('Refresh Inquiry'), 'default');
62 end_row();
63 end_table();
64 if (!@$_GET['popup'])
65         end_form();
66
67 set_global_stock_item($_POST['stock_id']);
68
69 $before_date = date2sql($_POST['BeforeDate']);
70 $after_date = date2sql($_POST['AfterDate']);
71
72 $result = get_stock_movements($_POST['stock_id'], $_POST['StockLocation'],
73         $_POST['BeforeDate'], $_POST['AfterDate']);
74
75 div_start('doc_tbl');
76 start_table(TABLESTYLE);
77 $th = array(_("Type"), _("#"), _("Reference"), _("Date"), _("Detail"),
78         _("Quantity In"), _("Quantity Out"), _("Quantity On Hand"));
79
80 table_header($th);
81
82 $before_qty = get_stock_movements_before($_POST['stock_id'], $_POST['StockLocation'], $_POST['AfterDate']);
83         
84 $after_qty = $before_qty;
85
86 /*
87 if (!isset($before_qty_row[0]))
88 {
89         $after_qty = $before_qty = 0;
90 }
91 */
92 start_row("class='inquirybg'");
93 label_cell("<b>"._("Quantity on hand before") . " " . $_POST['AfterDate']."</b>", "align=center colspan=5");
94 label_cell("&nbsp;", "colspan=2");
95 $dec = get_qty_dec($_POST['stock_id']);
96 qty_cell($before_qty, false, $dec);
97 end_row();
98
99 $j = 1;
100 $k = 0; //row colour counter
101
102 $total_in = 0;
103 $total_out = 0;
104
105 while ($myrow = db_fetch($result))
106 {
107
108         alt_table_row_color($k);
109
110         $trandate = sql2date($myrow["tran_date"]);
111
112         $type_name = $systypes_array[$myrow["type"]];
113
114         if ($myrow["qty"] > 0)
115         {
116                 $quantity_formatted = number_format2($myrow["qty"], $dec);
117                 $total_in += $myrow["qty"];
118         }
119         else
120         {
121                 $quantity_formatted = number_format2(-$myrow["qty"], $dec);
122                 $total_out += -$myrow["qty"];
123         }
124         $after_qty += $myrow["qty"];
125
126         label_cell($type_name);
127
128         label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]));
129
130         label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"], $myrow["reference"]));
131         label_cell($trandate);
132
133         $person = $myrow["person_id"];
134         $gl_posting = "";
135
136         if (($myrow["type"] == ST_CUSTDELIVERY) || ($myrow["type"] == ST_CUSTCREDIT))
137         {
138                 $cust_row = get_customer_details_from_trans($myrow["type"], $myrow["trans_no"]);
139
140                 if (strlen($cust_row['name']) > 0)
141                         $person = $cust_row['name'] . " (" . $cust_row['br_name'] . ")";
142
143         }
144         elseif ($myrow["type"] == ST_SUPPRECEIVE || $myrow['type'] == ST_SUPPCREDIT)
145         {
146                 // get the supplier name
147                 $supp_name = get_supplier_name($myrow["person_id"]);
148
149                 if (strlen($supp_name) > 0)
150                         $person = $supp_name;
151         }
152         elseif ($myrow["type"] == ST_LOCTRANSFER || $myrow["type"] == ST_INVADJUST)
153         {
154                 // get the adjustment type
155                 $movement_type = get_movement_type($myrow["person_id"]);
156                 $person = $movement_type["name"];
157         }
158         elseif ($myrow["type"]==ST_WORKORDER || $myrow["type"] == ST_MANUISSUE  ||
159                 $myrow["type"] == ST_MANURECEIVE)
160         {
161                 $person = "";
162         }
163
164         label_cell($person);
165
166         label_cell((($myrow["qty"] >= 0) ? $quantity_formatted : ""), "nowrap align=right");
167         label_cell((($myrow["qty"] < 0) ? $quantity_formatted : ""), "nowrap align=right");
168         qty_cell($after_qty, false, $dec);
169         end_row();
170         $j++;
171         If ($j == 12)
172         {
173                 $j = 1;
174                 table_header($th);
175         }
176 //end of page full new headings if
177 }
178 //end of while loop
179
180 start_row("class='inquirybg'");
181 label_cell("<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']."</b>", "align=center colspan=5");
182 qty_cell($total_in, false, $dec);
183 qty_cell($total_out, false, $dec);
184 qty_cell($after_qty, false, $dec);
185 end_row();
186
187 end_table(1);
188 div_end();
189 end_page();
190
191 ?>