[0004904] Customer Credit Note: fixed invalid inventory GL postings for service items.
[fa-stable.git] / inventory / inquiry / stock_status.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_ITEMSSTATVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 $js = "";
17 if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
18         $js .= get_js_open_window(900, 500);
19
20 if (isset($_GET['stock_id']))
21         $_POST['stock_id'] = $_GET['stock_id'];
22
23 page(_($help_context = "Inventory Item Status"), isset($_GET['stock_id']), false, "", $js);
24
25 include_once($path_to_root . "/includes/date_functions.inc");
26 include_once($path_to_root . "/includes/ui.inc");
27 include_once($path_to_root . "/includes/data_checks.inc");
28
29 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
30 include_once($path_to_root . "/includes/db/manufacturing_db.inc");
31
32 if (list_updated('stock_id')) 
33         $Ajax->activate('status_tbl');
34 //----------------------------------------------------------------------------------------------------
35
36 check_db_has_stock_items(_("There are no items defined in the system."));
37
38 start_form();
39
40 if (!isset($_POST['stock_id']))
41         $_POST['stock_id'] = get_global_stock_item();
42
43 if (!$page_nested)
44 {
45         echo "<center> " . _("Item:"). " ";
46         echo stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
47 }
48 echo "<br>";
49
50 echo "<hr></center>";
51
52 set_global_stock_item($_POST['stock_id']);
53
54 $mb_flag = get_mb_flag($_POST['stock_id']);
55 $kitset_or_service = false;
56
57 div_start('status_tbl');
58 if (is_service($mb_flag))
59 {
60         display_note(_("This is a service and cannot have a stock holding, only the total quantity on outstanding sales orders is shown."), 0, 1);
61         $kitset_or_service = true;
62 }
63
64 $loc_details = get_loc_details($_POST['stock_id']);
65
66 start_table(TABLESTYLE);
67
68 if ($kitset_or_service == true)
69 {
70         $th = array(_("Location"), _("Demand"));
71 }
72 else
73 {
74         $th = array(_("Location"), _("Quantity On Hand"), _("Re-Order Level"),
75                 _("Demand"), _("Available"), _("On Order"));
76 }
77 table_header($th);
78 $dec = get_qty_dec($_POST['stock_id']);
79 $j = 1;
80 $k = 0; //row colour counter
81
82 while ($myrow = db_fetch($loc_details))
83 {
84
85         alt_table_row_color($k);
86
87         $demand_qty = get_demand_qty($_POST['stock_id'], $myrow["loc_code"]);
88         $demand_qty += get_demand_asm_qty($_POST['stock_id'], $myrow["loc_code"]);
89
90         $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
91
92         if ($kitset_or_service == false)
93         {
94                 $qoo = get_on_porder_qty($_POST['stock_id'], $myrow["loc_code"]);
95                 $qoo += get_on_worder_qty($_POST['stock_id'], $myrow["loc_code"]);
96                 label_cell($myrow["location_name"]);
97                 qty_cell($qoh, false, $dec);
98         qty_cell($myrow["reorder_level"], false, $dec);
99         qty_cell($demand_qty, false, $dec);
100         qty_cell($qoh - $demand_qty, false, $dec);
101         qty_cell($qoo, false, $dec);
102         end_row();
103
104         }
105         else
106         {
107         /* It must be a service or kitset part */
108                 label_cell($myrow["location_name"]);
109                 qty_cell($demand_qty, false, $dec);
110                 end_row();
111
112         }
113         $j++;
114         If ($j == 12)
115         {
116                 $j = 1;
117                 table_header($th);
118         }
119 }
120
121 end_table();
122 div_end();
123 end_form();
124 end_page();
125