-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhome.php
More file actions
165 lines (157 loc) · 5.23 KB
/
home.php
File metadata and controls
165 lines (157 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
$page_title = 'Home Page';
require_once('includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(3);
?>
<?php
// Get all stock quantity
$c_stock = count_by_id('products');
// Get all categories
$c_category = count_by_id('categories');
// Get all user except Admin
$c_user = count_by_id('users');
// Get all sales
$c_sale = count_by_id('sales');
// Get all products
$products_sold = find_higest_saleing_product('10');
// Get all sales
$recent_sales = find_recent_sale_added('5');
// Store the filter value in session to persist it
if(isset($_POST['filter_quantity'])) {
$_SESSION['low_stock_filter'] = (int)$_POST['filter_quantity'];
}
// Use the session value or default to 10
$filter_quantity = isset($_SESSION['low_stock_filter']) ? $_SESSION['low_stock_filter'] : 10;
// Get low stock products using the filter value
$low_stock_products = find_products_below_quantity($filter_quantity);
?>
<?php include_once('layouts/header.php'); ?>
<div class="row">
<div class="col-md-12">
<?php echo display_msg($msg); ?>
</div>
<div class="col-md-12">
<div class="panel">
<div class="jumbotron text-center">
<h1>Welcome User <hr> Inventory Management System</h1>
<p>Browes around to find out the pages that you can access!</p>
</div>
</div>
</div>
</div>
<?php
// Count warehouses - Fix the function call to use only one parameter
$c_warehouse = count_by_id('warehouses');
// Get warehouse statistics
$warehouse_stats = array();
$warehouses = find_all_warehouses_by_user($_SESSION['user_id']);
foreach($warehouses as $warehouse) {
$products = find_products_by_warehouse($warehouse['id']);
$total_items = count($products);
$total_value = 0;
foreach($products as $product) {
$total_value += $product['buy_price'] * $product['quantity'];
}
$warehouse_stats[] = array(
'id' => $warehouse['id'],
'name' => $warehouse['name'],
'total_items' => $total_items,
'total_value' => $total_value
);
}
?>
<!-- Add warehouse statistics to dashboard -->
<div class="row">
<div class="col-md-4">
<div class="panel panel-box clearfix">
<div class="panel-icon pull-left bg-green">
<i class="glyphicon glyphicon-home"></i>
</div>
<div class="panel-value pull-right">
<h2 class="margin-top"><?php echo $c_warehouse['total']; ?></h2>
<p class="text-muted">Warehouses</p>
</div>
</div>
</div>
</div>
<!-- Add warehouse breakdown section -->
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>Warehouse Overview</span>
</strong>
</div>
<div class="panel-body">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Warehouse</th>
<th class="text-center">Total Items</th>
<th class="text-center">Total Value</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($warehouse_stats as $stat): ?>
<tr>
<td><?php echo remove_junk($stat['name']); ?></td>
<td class="text-center"><?php echo $stat['total_items']; ?></td>
<td class="text-center"><?php echo number_format($stat['total_value'], 2); ?></td>
<td class="text-center">
<a href="view_warehouse.php?id=<?php echo (int)$stat['id']; ?>" class="btn btn-primary btn-xs">View Details</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- In the low stock section, update the form to show the current filter value -->
<div class="panel panel-default">
<div class="panel-heading">
<strong>
<span class="glyphicon glyphicon-th"></span>
<span>LOW STOCK PRODUCTS</span>
</strong>
</div>
<div class="panel-body">
<form method="post" action="">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-filter"></i>
</span>
<input type="number" class="form-control" name="filter_quantity" placeholder="Filter by quantity" value="<?php echo $filter_quantity; ?>">
<span class="input-group-btn">
<button class="btn btn-primary" type="submit">Filter</button>
</span>
</div>
</div>
</form>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Alert Level</th>
</tr>
</thead>
<tbody>
<?php foreach ($low_stock_products as $low_stock): ?>
<tr>
<td><?php echo remove_junk($low_stock['name']); ?></td>
<td><?php echo remove_junk($low_stock['quantity']); ?></td>
<td><?php echo remove_junk($filter_quantity); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php include_once('layouts/footer.php'); ?>