-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
450 lines (404 loc) · 18.5 KB
/
index.php
File metadata and controls
450 lines (404 loc) · 18.5 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?php
session_start();
include 'connection.php';
if (!isset($_SESSION['id']) || !isset($_SESSION['role']) || !isset($_SESSION['status'])) {
header('Location: login.php');
exit;
}
include_once('includes/header.php');
// Fetch the number of staff members
$sqlExpense = "SELECT SUM(amount) as totalExpense FROM expense";
$resultExpense = mysqli_query($conn, $sqlExpense);
$rowExpense = mysqli_fetch_assoc($resultExpense);
$totalExpense = $rowExpense['totalExpense'];
// Fetch the total transactions from the transaction table
$sqlBooking = "SELECT COUNT(*) as numBooking FROM booking";
$resultBooking = mysqli_query($conn, $sqlBooking);
$rowBooking = mysqli_fetch_assoc($resultBooking);
$numBooking = $rowBooking['numBooking'];
// Fetch the total transactions from the transaction table
$sqlTransactions = "SELECT SUM(total) as totalTransactions, SUM(due) as total_due, SUM(advance) as advance, SUM(cash) as cash FROM transaction";
$resultTransactions = mysqli_query($conn, $sqlTransactions);
$rowTransactions = mysqli_fetch_assoc($resultTransactions);
$totalTransactions = $rowTransactions['totalTransactions'];
$total_due = $rowTransactions['total_due'];
$advance = $rowTransactions['advance'];
$cash = $rowTransactions['cash'];
$totalProfit = $totalTransactions - $totalExpense;
// Include necessary files
include_once('includes/header.php');
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header text-center">Dashboard</h1>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-warning">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-shopping-cart fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge"><?php echo $numBooking; ?></div>
<div>Total Bookings</div>
</div>
</div>
</div>
<a href="bookingManagement.php">
<div class="panel-footer">
<span class="pull-left">Book Now</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-success">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-money fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $totalTransactions; ?></div>
<div>Total Income</div>
</div>
</div>
</div>
<a href="transaction.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-tasks fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $totalExpense; ?></div>
<div>Total Expenses</div>
</div>
</div>
</div>
<a href="allExpense.php">
<div class="panel-footer">
<span class="pull-left">All Expenses</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-money fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $totalProfit ?></div>
<div>Total Profit</div>
</div>
</div>
</div>
<a href="report.php">
<div class="panel-footer">
<span class="pull-left">View Report</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-red">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-money fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $total_due; ?></div>
<div>Total Due</div>
</div>
</div>
</div>
<a href="transaction.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-info">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-money fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $advance; ?></div>
<div>Total Advanced</div>
</div>
</div>
</div>
<a href="transaction.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-yellow">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-money fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">৳ <?php echo $cash; ?></div>
<div>Total Income</div>
</div>
</div>
</div>
<a href="transaction.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-bar-chart fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class="huge">All Reports</div>
<div>Report</div>
</div>
</div>
</div>
<a href="report.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
</div>
<div class="row">
<style>
#transactionChart,
#customerChart {
background-color: #e1f7d5;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
.filter-container {
background-color: #e1f7d5;
margin-bottom: 20px;
padding: 15px;
border-radius: 8px;
}
.filter-container label {
margin-right: 10px;
font-weight: bold;
color: #007bff;
}
.filter-container select {
padding: 8px;
border-radius: 4px;
border: 1px solid #ced4da;
outline: none;
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
</style>
<div class="row">
<div class=" mt-4">
<!-- Filter Select Box -->
<div class="filter-container">
<label for="interval">Select Interval:</label>
<select id="interval" name="filter" class="form-select">
<option value="last-7-days" <?php echo (!isset($_POST['filter']) || $_POST['filter'] == 'last-7-days') ? 'selected' : ''; ?>>Last 7 Days</option>
<option value="last-30-days" <?php echo (isset($_POST['filter']) && $_POST['filter'] == 'last-30-days') ? 'selected' : ''; ?>>Last 30 Days</option>
<option value="monthly" <?php echo (isset($_POST['filter']) && $_POST['filter'] == 'monthly') ? 'selected' : ''; ?>>Monthly</option>
<option value="yearly" <?php echo (isset($_POST['filter']) && $_POST['filter'] == 'yearly') ? 'selected' : ''; ?>>Yearly</option>
<!-- <option value="all-time" <?php echo (isset($_POST['filter']) && $_POST['filter'] == 'all-time') ? 'selected' : ''; ?>>All Time</option> -->
</select>
</div>
<!-- Stylish Canvas for Chart.js -->
<div class="card">
<div class="card-body">
<canvas id="myChart" width="400" height="150"></canvas>
</div>
</div>
<?php
function fetchDataForChart($interval, $format, $conn)
{
$sql = "SELECT DATE(b.date) AS booking_date, SUM(t.total) AS total_income
FROM booking b
LEFT JOIN transaction t ON b.transaction_id = t.id";
switch ($interval) {
case 'last-7-days':
$sql .= " WHERE b.date >= CURDATE() - INTERVAL 6 DAY AND b.date <= NOW()";
break;
case 'last-30-days':
$sql .= " WHERE b.date >= CURDATE() - INTERVAL 29 DAY AND b.date <= NOW()";
break;
case 'monthly':
$sql .= " WHERE b.date >= DATE_SUB(NOW(), INTERVAL 1 MONTH) AND b.date <= NOW()";
break;
case 'yearly':
$sql .= " WHERE b.date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) AND b.date <= NOW()";
break;
// Add more cases for other intervals if needed
}
$sql .= " GROUP BY booking_date";
$result = mysqli_query($conn, $sql);
// Check for errors
if (!$result) {
die("Error in SQL: " . mysqli_error($conn));
}
$data = array();
// Fetch data and group by the specified interval from the booking table
while ($row = mysqli_fetch_assoc($result)) {
// Use the booking date for grouping
$date = date_create($row['booking_date']);
$groupKey = date_format($date, $format);
if (!isset($data[$groupKey])) {
$data[$groupKey] = 0;
}
// Sum up the total amount for each interval
$data[$groupKey] += $row['total_income'];
}
return array('totalIncome' => $data);
}
// Display data by default (last 30 days)
$data = fetchDataForChart('last-7-days', 'Y-m-d', $conn);
?>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
var myChart; // Variable to hold the Chart.js instance
// Function to create a stylish Chart.js bar chart
function createChart(data) {
var ctx = document.getElementById('myChart').getContext('2d');
// Check if a chart instance exists, destroy it before creating a new one
if (window.myChart) {
window.myChart.destroy();
}
var labels = [];
var values = [];
// Extract keys (labels) and values from the data.totalIncome array
for (var key in data.totalIncome) {
labels.push(key);
values.push(data.totalIncome[key]);
}
// Define vibrant and deeper colors for the bars
var barColors = [
'rgba(75, 192, 192, 0.8)',
'rgba(255, 99, 132, 0.8)',
'rgba(54, 162, 235, 0.8)',
'rgba(255, 206, 86, 0.8)',
'rgba(153, 102, 255, 0.8)',
'rgba(255, 159, 64, 0.8)',
];
window.myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Total Amount',
data: values,
backgroundColor: barColors,
borderColor: barColors.map(color => color.replace('0.8', '1')),
borderWidth: 2
}]
},
options: {
scales: {
y: {
beginAtZero: true,
grid: {
color: 'rgba(0, 0, 0, 0.1)',
}
},
x: {
grid: {
color: 'rgba(0, 0, 0, 0)',
}
}
},
plugins: {
legend: {
display: true,
position: 'top',
}
}
}
});
}
// Function to update the chart
function updateChart() {
// Fetch data using jQuery AJAX
var selectedFilter = $('#interval').val();
$.ajax({
method: 'POST',
url: 'update_chart_data.php',
data: {
filter: selectedFilter
},
dataType: 'json',
cache: false, // Add this line to prevent caching
success: function(response) {
if (response.error) {
console.error('Error:', response.error);
} else {
// Call the function to update the chart
createChart(response.data);
}
},
error: function(xhr, status, error) {
console.error('AJAX Error:', error);
}
});
}
// Bind the updateChart function to the change event of the select box
$('#interval').change(updateChart);
// Initial chart creation
createChart(<?php echo json_encode($data); ?>);
</script>
</div>
</div>
</div>
</div>
<?php include_once('includes/footer.php'); ?>