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