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