[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / inventory / reorder_level.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_REORDER';
13
14 if (@$_GET['page_level'] == 1)
15         $path_to_root = "../..";
16 else    
17         $path_to_root = "..";
18
19 include_once($path_to_root . "/includes/session.inc");
20 include_once($path_to_root . "/includes/date_functions.inc");
21 include_once($path_to_root . "/includes/ui.inc");
22 include_once($path_to_root . "/includes/data_checks.inc");
23 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
24
25 $js = "";
26 if ($SysPrefs->use_popup_windows && $SysPrefs->use_popup_search)
27         $js .= get_js_open_window(900, 500);
28 page(_($help_context = "Reorder Levels"), false, false, "", $js);
29
30 check_db_has_costable_items(_("There are no inventory items defined in the system (Purchased or manufactured items)."));
31
32 //------------------------------------------------------------------------------------
33
34 if (isset($_GET['stock_id']))
35         $_POST['stock_id'] = $_GET['stock_id'];
36
37 if (list_updated('stock_id')) 
38 {
39         $Ajax->activate('show_heading');
40         $Ajax->activate('reorders');
41 }
42 //------------------------------------------------------------------------------------
43
44 $action = $_SERVER['PHP_SELF'];
45 if ($page_nested)
46         $action .= "?stock_id=".get_post('stock_id');
47 start_form(false, false, $action);
48
49 if (!isset($_POST['stock_id']))
50         $_POST['stock_id'] = get_global_stock_item();
51
52 if (!$page_nested)
53 {
54         echo "<center>" . _("Item:"). "&nbsp;";
55         echo stock_costable_items_list('stock_id', $_POST['stock_id'], false, true);
56
57         echo "<hr></center>";
58 }
59 else
60         br(2);
61 div_start('show_heading');
62 stock_item_heading($_POST['stock_id']);
63 br();
64 div_end();
65
66 set_global_stock_item($_POST['stock_id']);
67
68 div_start('reorders');
69 start_table(TABLESTYLE, "width='30%'");
70
71 $th = array(_("Location"), _("Quantity On Hand"), _("Re-Order Level"));
72 table_header($th);
73
74 $j = 1;
75 $k=0; //row colour counter
76
77 $result = get_loc_details($_POST['stock_id']);
78
79 while ($myrow = db_fetch($result))
80 {
81
82         alt_table_row_color($k);
83
84         if (isset($_POST['UpdateData']) && check_num($myrow["loc_code"]))
85         {
86
87                 $myrow["reorder_level"] = input_num($myrow["loc_code"]);
88                 set_reorder_level($_POST['stock_id'], $myrow["loc_code"], input_num($myrow["loc_code"]));
89                 display_notification(_("Reorder levels has been updated."));
90         }
91
92         $qoh = get_qoh_on_date($_POST['stock_id'], $myrow["loc_code"]);
93
94         label_cell($myrow["location_name"]);
95
96         $_POST[$myrow["loc_code"]] = qty_format($myrow["reorder_level"], $_POST['stock_id'], $dec);
97
98         qty_cell($qoh, false, $dec);
99         qty_cells(null, $myrow["loc_code"], null, null, null, $dec);
100         end_row();
101         $j++;
102         If ($j == 12)
103         {
104                 $j = 1;
105                 table_header($th);
106         }
107 }
108
109 end_table(1);
110 div_end();
111 submit_center('UpdateData', _("Update"), true, false, 'default');
112
113 end_form();
114 end_page();