// ========== INCLUDE SECURITY & DATABASE ==========
include('security.php'); // this should start session and check login
include('dbcon.php');
$user_type = '';
$location = '';
$header1 = '';
$header2 = '';
$not1 = '';
$usermail = '';
date_default_timezone_set("Asia/Calcutta");
$date = date('m/d/Y h:i:s a', time());
$startTime = date("Y-m-d H:i:s");
$cenvertedTime = date('Y-m-d H:i:s', strtotime('+0 hour +0 minutes', strtotime($startTime)));
$new_time = date("Y-m-d H:i:s", strtotime('+5:30 hours'));
$new_date = date("Y-m-d", strtotime('+5:30 hours'));
if (mysqli_connect_error()) {
die("There was an error connecting to database");
} else {
$username = $_SESSION['username'];
$result = mysqli_query($link, "SELECT * from tbluser WHERE email = '$username'");
while ($row = mysqli_fetch_array($result)) {
$user_type = $row['user_type'];
$location = $row['location'];
$header1 = $row['header1'];
$header2 = $row['header2'];
$not1 = $row['not1'];
}
}
// ==============================================
// DYNAMIC DATA FROM tblvehicle TABLE
// ==============================================
// Get date range from request or use default (last 24 hours)
$from_date = isset($_GET['from_date']) && !empty($_GET['from_date']) ? $_GET['from_date'] : date('Y-m-d H:i:s', strtotime('-24 hours'));
$to_date = isset($_GET['to_date']) && !empty($_GET['to_date']) ? $_GET['to_date'] : date('Y-m-d H:i:s');
// Build location filter
$location_filter = "";
if (!empty($location) && $user_type != 'Super') {
$location_filter = "AND location = '" . mysqli_real_escape_string($link, $location) . "'";
}
// 1. ENTERED VEHICLES
$query_entered = "SELECT COUNT(*) as total,
SUM(CASE WHEN type = 'Pass' OR type = 'pass' THEN 1 ELSE 0 END) as pass_count,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN 1 ELSE 0 END) as ticket_count,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN 1 ELSE 0 END) as fasttag_count,
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN 1 ELSE 0 END) as anpr_count
FROM tblvehicle
WHERE indatetime BETWEEN '$from_date' AND '$to_date' $location_filter";
$result_entered = mysqli_query($link, $query_entered);
if (!$result_entered) {
die("Query Error: " . mysqli_error($link));
}
$entered_data = mysqli_fetch_assoc($result_entered);
$entered_total = $entered_data['total'] ?? 0;
$entered_pass = $entered_data['pass_count'] ?? 0;
$entered_ticket = $entered_data['ticket_count'] ?? 0;
$entered_fasttag = $entered_data['fasttag_count'] ?? 0;
$entered_anpr = $entered_data['anpr_count'] ?? 0;
$entered_pass_pct = $entered_total > 0 ? round(($entered_pass / $entered_total) * 100, 2) : 0;
$entered_ticket_pct = $entered_total > 0 ? round(($entered_ticket / $entered_total) * 100, 2) : 0;
$entered_fasttag_pct = $entered_total > 0 ? round(($entered_fasttag / $entered_total) * 100, 2) : 0;
$entered_anpr_pct = $entered_total > 0 ? round(($entered_anpr / $entered_total) * 100, 2) : 0;
// 2. EXIT VEHICLES
$query_exit = "SELECT COUNT(*) as total,
SUM(CASE WHEN type = 'Pass' OR type = 'pass' THEN 1 ELSE 0 END) as pass_count,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN 1 ELSE 0 END) as ticket_count,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN 1 ELSE 0 END) as fasttag_count,
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN 1 ELSE 0 END) as anpr_count
FROM tblvehicle
WHERE outdatetime BETWEEN '$from_date' AND '$to_date'
AND departure = 'Departed' $location_filter";
$result_exit = mysqli_query($link, $query_exit);
$exit_data = mysqli_fetch_assoc($result_exit);
$exit_total = $exit_data['total'] ?? 0;
$exit_pass = $exit_data['pass_count'] ?? 0;
$exit_ticket = $exit_data['ticket_count'] ?? 0;
$exit_fasttag = $exit_data['fasttag_count'] ?? 0;
$exit_anpr = $exit_data['anpr_count'] ?? 0;
$exit_pass_pct = $exit_total > 0 ? round(($exit_pass / $exit_total) * 100, 2) : 0;
$exit_ticket_pct = $exit_total > 0 ? round(($exit_ticket / $exit_total) * 100, 2) : 0;
$exit_fasttag_pct = $exit_total > 0 ? round(($exit_fasttag / $exit_total) * 100, 2) : 0;
$exit_anpr_pct = $exit_total > 0 ? round(($exit_anpr / $exit_total) * 100, 2) : 0;
// 3. PENDING VEHICLES
$query_pending = "SELECT COUNT(*) as total,
SUM(CASE WHEN type = 'Pass' OR type = 'pass' THEN 1 ELSE 0 END) as pass_count,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN 1 ELSE 0 END) as ticket_count,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN 1 ELSE 0 END) as fasttag_count,
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN 1 ELSE 0 END) as anpr_count
FROM tblvehicle
WHERE indatetime BETWEEN '$from_date' AND '$to_date'
AND (departure = 'Parked' OR departure IS NULL OR departure = '') $location_filter";
$result_pending = mysqli_query($link, $query_pending);
$pending_data = mysqli_fetch_assoc($result_pending);
$pending_total = $pending_data['total'] ?? 0;
$pending_pass = $pending_data['pass_count'] ?? 0;
$pending_ticket = $pending_data['ticket_count'] ?? 0;
$pending_fasttag = $pending_data['fasttag_count'] ?? 0;
$pending_anpr = $pending_data['anpr_count'] ?? 0;
$pending_pass_pct = $pending_total > 0 ? round(($pending_pass / $pending_total) * 100, 2) : 0;
$pending_ticket_pct = $pending_total > 0 ? round(($pending_ticket / $pending_total) * 100, 2) : 0;
$pending_fasttag_pct = $pending_total > 0 ? round(($pending_fasttag / $pending_total) * 100, 2) : 0;
$pending_anpr_pct = $pending_total > 0 ? round(($pending_anpr / $pending_total) * 100, 2) : 0;
// 4. AMOUNT DATA
$query_amount = "SELECT
SUM(CASE WHEN type = 'Pass' OR type = 'pass' THEN charge ELSE 0 END) as pass_amount,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN charge ELSE 0 END) as ticket_amount,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN charge ELSE 0 END) as fasttag_amount,
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN charge ELSE 0 END) as anpr_amount,
SUM(CASE WHEN pcode = 'Foc' OR pcode = 'foc' OR pcode = 'FOC' THEN charge ELSE 0 END) as foc_amount,
SUM(CASE WHEN pcode = 'Online' OR pcode = 'online' THEN charge ELSE 0 END) as online_amount,
SUM(CASE WHEN pcode = 'Cash' OR pcode = 'cash' THEN charge ELSE 0 END) as cash_amount,
SUM(charge) as total_amount
FROM tblvehicle
WHERE outdatetime BETWEEN '$from_date' AND '$to_date'
AND departure = 'Departed' $location_filter";
$result_amount = mysqli_query($link, $query_amount);
$amount_data = mysqli_fetch_assoc($result_amount);
$total_amount = $amount_data['total_amount'] ?? 0;
$pass_amount = $amount_data['pass_amount'] ?? 0;
$ticket_amount = $amount_data['ticket_amount'] ?? 0;
$fasttag_amount = $amount_data['fasttag_amount'] ?? 0;
$anpr_amount = $amount_data['anpr_amount'] ?? 0;
$foc_amount = $amount_data['foc_amount'] ?? 0;
$online_amount = $amount_data['online_amount'] ?? 0;
$cash_amount = $amount_data['cash_amount'] ?? 0;
$pass_amount_pct = $total_amount > 0 ? round(($pass_amount / $total_amount) * 100, 2) : 0;
$ticket_amount_pct = $total_amount > 0 ? round(($ticket_amount / $total_amount) * 100, 2) : 0;
$fasttag_amount_pct = $total_amount > 0 ? round(($fasttag_amount / $total_amount) * 100, 2) : 0;
$anpr_amount_pct = $total_amount > 0 ? round(($anpr_amount / $total_amount) * 100, 2) : 0;
$foc_amount_pct = $total_amount > 0 ? round(($foc_amount / $total_amount) * 100, 2) : 0;
$online_amount_pct = $total_amount > 0 ? round(($online_amount / $total_amount) * 100, 2) : 0;
$cash_amount_pct = $total_amount > 0 ? round(($cash_amount / $total_amount) * 100, 2) : 0;
// 5. WEEKLY DATA FOR CHART (last 7 days)
$weekly_labels = [];
$weekly_anpr = [];
$weekly_fasttag = [];
$weekly_ticket = [];
for ($i = 6; $i >= 0; $i--) {
$day = date('D', strtotime("-$i days"));
$day_start = date('Y-m-d 00:00:00', strtotime("-$i days"));
$day_end = date('Y-m-d 23:59:59', strtotime("-$i days"));
$weekly_labels[] = $day;
$query_day = "SELECT
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN 1 ELSE 0 END) as anpr_count,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN 1 ELSE 0 END) as fasttag_count,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN 1 ELSE 0 END) as ticket_count
FROM tblvehicle
WHERE indatetime BETWEEN '$day_start' AND '$day_end' $location_filter";
$result_day = mysqli_query($link, $query_day);
$day_data = mysqli_fetch_assoc($result_day);
$weekly_anpr[] = $day_data['anpr_count'] ?? 0;
$weekly_fasttag[] = $day_data['fasttag_count'] ?? 0;
$weekly_ticket[] = $day_data['ticket_count'] ?? 0;
}
// 6. TRANSACTION PERCENTAGES FOR PIE CHART
$query_transaction_pct = "SELECT
SUM(CASE WHEN type = 'ANPR' OR type = 'anpr' THEN 1 ELSE 0 END) as anpr_total,
SUM(CASE WHEN type = 'FastTag' OR type = 'fasttag' OR type = 'Fastag' THEN 1 ELSE 0 END) as fasttag_total,
SUM(CASE WHEN type = 'Ticket' OR type = 'ticket' THEN 1 ELSE 0 END) as ticket_total,
COUNT(*) as grand_total
FROM tblvehicle
WHERE indatetime BETWEEN '$from_date' AND '$to_date' $location_filter";
$result_transaction = mysqli_query($link, $query_transaction_pct);
$transaction_data = mysqli_fetch_assoc($result_transaction);
$grand_total = $transaction_data['grand_total'] ?? 1;
$anpr_pct = $grand_total > 0 ? round(($transaction_data['anpr_total'] / $grand_total) * 100, 1) : 0;
$fasttag_pct = $grand_total > 0 ? round(($transaction_data['fasttag_total'] / $grand_total) * 100, 1) : 0;
$ticket_pct = $grand_total > 0 ? round(($transaction_data['ticket_total'] / $grand_total) * 100, 1) : 0;
?>
AccessPark - Dashboard
Dashboard
Live parking operations data from tblvehicle
| Pass (%) | 0 |
| Ticket (%) | 0 |
| FastTag (%) | 0 |
| ANPR (%) | 0 |
| Pass (%) | 0 |
| Ticket (%) | 0 |
| FastTag (%) | 0 |
| ANPR (%) | 0 |
| Pass (%) | 0 |
| Ticket (%) | 0 |
| FastTag (%) | 0 |
| ANPR (%) | 0 |
| Pass (%) | ₹0 |
| Ticket (%) | ₹0 |
| FastTag (%) | ₹0 |
| ANPR (%) | ₹0 |
| Foc (%) | ₹0 |
| Online (%) | ₹0 |
| Cash (%) | ₹0 |
| Total Amount | ₹0 |
ANPR (%)
FastTag (%)
Ticket (%)