Right align numbers in inquiries and lists.
[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 ($SysPrefs->use_popup_windows)
23         $js .= get_js_open_window(800, 500);
24 if (user_use_date_picker())
25         $js .= get_js_date_picker();
26
27 if (isset($_GET['FixedAsset'])) {
28         $page_security = 'SA_ASSETSTRANSVIEW';
29         $_POST['fixed_asset'] = 1;
30         $_SESSION['page_title'] = _($help_context = "Fixed Assets Movement");
31 } else {
32         $_SESSION['page_title'] = _($help_context = "Inventory Item Movement");
33 }
34
35 page($_SESSION['page_title'], isset($_GET['stock_id']), false, "", $js);
36 //------------------------------------------------------------------------------------------------
37
38 if (get_post('fixed_asset') == 1)
39         check_db_has_fixed_assets(_("There are no fixed asset defined in the system."));
40 else
41         check_db_has_stock_items(_("There are no items defined in the system."));
42
43 if(get_post('ShowMoves'))
44 {
45         $Ajax->activate('doc_tbl');
46 }
47
48 if (isset($_GET['stock_id']))
49 {
50         $_POST['stock_id'] = $_GET['stock_id'];
51 }
52
53 start_form();
54
55 hidden('fixed_asset');
56
57 if (!isset($_POST['stock_id']))
58         $_POST['stock_id'] = get_global_stock_item();
59
60 start_table(TABLESTYLE_NOBORDER);
61 start_row();
62 if (!$page_nested)
63 {
64         if (get_post('fixed_asset') == 1) {
65                 stock_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id'],
66                         false, false, check_value('show_inactive'), false, array('fixed_asset' => true));
67                 check_cells(_("Show inactive:"), 'show_inactive', null, true);
68
69                 if (get_post('_show_inactive_update')) {
70                         $Ajax->activate('stock_id');
71                         set_focus('stock_id');
72                 }
73         } else
74                 stock_costable_items_list_cells(_("Item:"), 'stock_id', $_POST['stock_id']);
75 }
76
77 end_row();
78 end_table();
79
80 start_table(TABLESTYLE_NOBORDER);
81 start_row();
82
83 locations_list_cells(_("From Location:"), 'StockLocation', null, true, false, (get_post('fixed_asset') == 1));
84
85 date_cells(_("From:"), 'AfterDate', '', null, -user_transaction_days());
86 date_cells(_("To:"), 'BeforeDate');
87
88 submit_cells('ShowMoves',_("Show Movements"),'',_('Refresh Inquiry'), 'default');
89 end_row();
90 end_table();
91 end_form();
92
93 set_global_stock_item($_POST['stock_id']);
94
95 $before_date = date2sql($_POST['BeforeDate']);
96 $after_date = date2sql($_POST['AfterDate']);
97 $display_location = !$_POST['StockLocation'];
98
99 $result = get_stock_movements($_POST['stock_id'], $_POST['StockLocation'],
100         $_POST['BeforeDate'], $_POST['AfterDate']);
101
102 div_start('doc_tbl');
103 start_table(TABLESTYLE);
104 $th = array(_("Type"), _("#"), _("Reference"));
105
106 if ($display_location)
107         array_push($th, _("Location"));
108
109 array_push($th, _("Date"), _("Detail"), _("Quantity In"), _("Quantity Out"), _("Quantity On Hand"));
110
111 table_header($th);
112
113 $before_qty = get_qoh_on_date($_POST['stock_id'], $_POST['StockLocation'], add_days($_POST['AfterDate'], -1));
114
115 $after_qty = $before_qty;
116
117 start_row("class='inquirybg'");
118 $header_span = $display_location ? 6 : 5;
119 label_cell("<b>"._("Quantity on hand before") . " " . $_POST['AfterDate']."</b>", "align=center colspan=$header_span");
120 label_cell("&nbsp;", "colspan=2");
121 $dec = get_qty_dec($_POST['stock_id']);
122 qty_cell($before_qty, false, $dec);
123 end_row();
124
125 $j = 1;
126 $k = 0; //row colour counter
127
128 $total_in = 0;
129 $total_out = 0;
130
131 while ($myrow = db_fetch($result))
132 {
133
134         alt_table_row_color($k);
135
136         $trandate = sql2date($myrow["tran_date"]);
137
138         if (get_post('fixed_asset') == 1 && isset($fa_systypes_array[$myrow["type"]]))
139                 $type_name = $fa_systypes_array[$myrow["type"]];
140         else
141                 $type_name = $systypes_array[$myrow["type"]];
142
143         if ($myrow["qty"] > 0)
144         {
145                 $quantity_formatted = number_format2($myrow["qty"], $dec);
146                 $total_in += $myrow["qty"];
147         }
148         else
149         {
150                 $quantity_formatted = number_format2(-$myrow["qty"], $dec);
151                 $total_out += -$myrow["qty"];
152         }
153         $after_qty += $myrow["qty"];
154
155         label_cell($type_name);
156
157         label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"]), "nowrap align='right'");
158
159         label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"], $myrow["reference"]));
160
161         if($display_location) {
162                 label_cell($myrow['loc_code']);
163         }
164         label_cell($trandate);
165
166         $gl_posting = "";
167
168         label_cell($myrow['name']);
169
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);
173         end_row();
174
175         $j++;
176         if ($j == 12)
177         {
178                 $j = 1;
179                 table_header($th);
180         }
181 }
182
183 start_row("class='inquirybg'");
184 label_cell("<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']."</b>", "align=center colspan=$header_span");
185 qty_cell($total_in, false, $dec);
186 qty_cell($total_out, false, $dec);
187 qty_cell($after_qty, false, $dec);
188 end_row();
189
190 end_table(1);
191 div_end();
192 end_page();
193