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