JezK
Edit File: index.php
<?php session_start(); require_once 'config/database.php'; require_once 'includes/functions.php'; // Check if user is logged in if (!isset($_SESSION['user_id'])) { header('Location: login.php'); exit(); } // Get dashboard statistics $stats = getDashboardStats($conn); $employeeStats = getEmployeeDashboardStats($conn); $recentTransactions = getRecentTransactions($conn, 10); $upcomingReminders = getUpcomingReminders($conn, 5); $monthlyRevenue = getMonthlyRevenue($conn); $sellerPerformance = getSellerPerformance($conn); // Get expense summary for dashboard (admin only) $expense_dashboard_summary = null; if (isAdmin()) { $expense_dashboard_summary = getExpenseSummary($conn); } // Get current month attendance and salary data $current_month = date('Y-m'); $month_start = $current_month . '-01'; $month_end = date('Y-m-t', strtotime($month_start)); $total_days = date('t', strtotime($month_start)); // Get all active employees $employees_sql = "SELECT id, employee_id, full_name, basic_salary FROM employees WHERE status = 'active' ORDER BY full_name"; $employees_result = $conn->query($employees_sql); $employees = $employees_result->fetch_all(MYSQLI_ASSOC); // Get salary settings $settings = getSalarySettings($conn); // Get attendance records for all employees $attendance_records = array(); foreach ($employees as $employee) { // Get attendance records $attendance = getEmployeeAttendance($conn, $employee['id'], $current_month); // Calculate attendance summary (only present/absent) $present_days = 0; $absent_days = 0; foreach ($attendance as $date => $status) { if ($status === 'present') { $present_days++; } else { $absent_days++; } } $summary = array( 'present_days' => $present_days, 'absent_days' => $absent_days ); // Calculate salary $salary = calculateSalaryFromAttendance($employee['basic_salary'], $summary, $settings); // Store complete record $attendance_records[] = array_merge( $employee, array('attendance' => $attendance), array('summary' => $summary), array('salary' => $salary) ); } ?> <!DOCTYPE html> <html lang="en"> <head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PAYMIND - Payment Management System</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet"> <link href="assets/css/style.css" rel="stylesheet"> <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> </head> <body> <!-- Navigation --> <nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <div class="container-fluid"> <a class="navbar-brand" href="index.php"> <i class="fas fa-credit-card me-2"></i>PAYMIND </a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav me-auto"> <li class="nav-item"> <a class="nav-link active" href="index.php"> <i class="fas fa-tachometer-alt me-1"></i>Dashboard </a> </li> <li class="nav-item"> <a class="nav-link" href="transactions.php"> <i class="fas fa-list me-1"></i>Transactions </a> </li> <li class="nav-item"> <a class="nav-link" href="add_transaction.php"> <i class="fas fa-plus me-1"></i>Add Transaction </a> </li> <li class="nav-item"> <a class="nav-link" href="sellers.php"> <i class="fas fa-users me-1"></i>Sellers </a> </li> <li class="nav-item"> <a class="nav-link" href="employees.php"> <i class="fas fa-user-tie me-1"></i>Employees </a> </li> <li class="nav-item"> <a class="nav-link" href="attendance.php"> <i class="fas fa-calendar-check me-1"></i>Attendance & Salary </a> </li> <li class="nav-item"> <a class="nav-link" href="expense_tracker.php"> <i class="fas fa-receipt me-1"></i>Expense Tracker </a> </li> <li class="nav-item"> <a class="nav-link" href="reports.php"> <i class="fas fa-chart-bar me-1"></i>Reports </a> </li> <li class="nav-item"> <a class="nav-link" href="reminders.php"> <i class="fas fa-bell me-1"></i>Reminders </a> </li> <li class="nav-item"> <a class="nav-link" href="settings.php"> <i class="fas fa-cog me-1"></i>Settings </a> </li> </ul> <ul class="navbar-nav"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown"> <i class="fas fa-user me-1"></i><?php echo isset($_SESSION['username']) ? $_SESSION['username'] : 'User'; ?> </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="profile.php">Profile</a></li> <li><a class="dropdown-item" href="settings.php">Settings</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="logout.php">Logout</a></li> </ul> </li> </ul> </div> </div> </nav> <div class="container-fluid mt-4"> <!-- Dashboard Header --> <div class="row mb-4"> <div class="col-12"> <h1 class="h3 mb-0 text-gray-800">Dashboard</h1> <p class="text-muted">Welcome back, <?php echo isset($_SESSION['username']) ? $_SESSION['username'] : 'User'; ?>!</p> </div> </div> <!-- Statistics Cards --> <div class="row mb-4"> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-primary shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-primary text-uppercase mb-1"> Total Revenue </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> ₹<?php echo number_format($stats['total_revenue']); ?> </div> </div> <div class="col-auto"> <i class="fas fa-calendar fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-success shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-success text-uppercase mb-1"> Amount Received </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> ₹<?php echo number_format($stats['amount_received']); ?> </div> </div> <div class="col-auto"> <i class="fas fa-dollar-sign fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-warning shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-warning text-uppercase mb-1"> Pending Amount </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> ₹<?php echo number_format($stats['pending_amount']); ?> </div> </div> <div class="col-auto"> <i class="fas fa-clock fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-info shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-info text-uppercase mb-1"> Total Transactions </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> <?php echo $stats['total_transactions']; ?> </div> </div> <div class="col-auto"> <i class="fas fa-clipboard-list fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> </div> <!-- Employee Statistics Row --> <div class="row mb-4"> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-success shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-success text-uppercase mb-1"> Total Employees </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> <?php echo $employeeStats['total_employees']; ?> </div> </div> <div class="col-auto"> <i class="fas fa-user-tie fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-warning shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-warning text-uppercase mb-1"> Total Salary Paid </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> ₹<?php echo number_format($employeeStats['total_salary_paid']); ?> </div> </div> <div class="col-auto"> <i class="fas fa-money-bill-wave fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-primary shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-primary text-uppercase mb-1"> Avg Attendance % </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> <?php echo $employeeStats['avg_attendance']; ?>% </div> </div> <div class="col-auto"> <i class="fas fa-calendar-check fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> <div class="col-xl-3 col-md-6 mb-4"> <div class="card border-left-danger shadow h-100 py-2"> <div class="card-body"> <div class="row no-gutters align-items-center"> <div class="col mr-2"> <div class="text-xs font-weight-bold text-danger text-uppercase mb-1"> Pending Salaries </div> <div class="h5 mb-0 font-weight-bold text-gray-800"> ₹<?php echo number_format($employeeStats['pending_salaries']); ?> </div> </div> <div class="col-auto"> <i class="fas fa-clock fa-2x text-gray-300"></i> </div> </div> </div> </div> </div> </div> <!-- Expense Summary Row (Admin Only) --> <?php if (isAdmin() && $expense_dashboard_summary): ?> <div class="row mb-4"> <div class="col-12"> <div class="card shadow"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Expense Overview</h6> <a href="expense_tracker.php" class="btn btn-sm btn-primary"> <i class="fas fa-receipt me-1"></i>View All Expenses </a> </div> <div class="card-body"> <div class="row"> <div class="col-md-2"> <div class="text-center"> <h4 class="text-primary"><?php echo $expense_dashboard_summary['total_expenses']; ?></h4> <p class="text-muted mb-0">Total Expenses</p> </div> </div> <div class="col-md-2"> <div class="text-center"> <h4 class="text-danger">₹<?php echo number_format($expense_dashboard_summary['total_amount'] ?: 0, 2); ?></h4> <p class="text-muted mb-0">Total Amount</p> </div> </div> <div class="col-md-2"> <div class="text-center"> <h4 class="text-info">₹<?php echo number_format($expense_dashboard_summary['average_amount'] ?: 0, 2); ?></h4> <p class="text-muted mb-0">Average per Expense</p> </div> </div> <div class="col-md-2"> <div class="text-center"> <h4 class="text-warning">₹<?php echo number_format($expense_dashboard_summary['max_amount'] ?: 0, 2); ?></h4> <p class="text-muted mb-0">Highest Expense</p> </div> </div> <div class="col-md-2"> <div class="text-center"> <h4 class="text-success">₹<?php echo number_format($expense_dashboard_summary['min_amount'] ?: 0, 2); ?></h4> <p class="text-muted mb-0">Lowest Expense</p> </div> </div> <div class="col-md-2"> <div class="text-center"> <h4 class="text-secondary">₹<?php $current_month = date('Y-m'); $month_sql = "SELECT SUM(amount) as month_total FROM expenses WHERE DATE_FORMAT(expense_date, '%Y-%m') = ?"; $month_stmt = $conn->prepare($month_sql); $month_stmt->bind_param("s", $current_month); $month_stmt->execute(); $month_result = $month_stmt->get_result(); $month_data = $month_result->fetch_assoc(); echo number_format($month_data['month_total'] ?: 0, 2); ?></h4> <p class="text-muted mb-0">This Month</p> </div> </div> </div> </div> </div> </div> </div> <?php endif; ?> <!-- Charts Row --> <div class="row mb-4"> <div class="col-xl-8 col-lg-7"> <div class="card shadow mb-4"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Monthly Revenue Overview</h6> </div> <div class="card-body"> <div class="chart-container"> <canvas id="revenueChart"></canvas> </div> </div> </div> </div> <div class="col-xl-4 col-lg-5"> <div class="card shadow mb-4"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Top Destination Cities</h6> </div> <div class="card-body"> <div class="chart-container"> <canvas id="sellerChart"></canvas> </div> </div> </div> </div> </div> <!-- Employee Attendance Cards --> <div class="row mb-4"> <div class="col-12"> <div class="card shadow"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Employee Attendance & Salary Overview</h6> <div> <a href="attendance.php" class="btn btn-sm btn-info me-2"> <i class="fas fa-calendar-check me-1"></i>Attendance </a> <a href="attendance.php" class="btn btn-sm btn-success"> <i class="fas fa-money-bill-wave me-1"></i>Salary </a> </div> </div> <div class="card-body"> <div class="row"> <?php foreach ($attendance_records as $record): ?> <div class="col-md-6 col-lg-4 mb-4"> <div class="card shadow-sm h-100"> <div class="card-header bg-primary text-white py-2"> <div class="d-flex justify-content-between align-items-center"> <h6 class="mb-0"><?php echo htmlspecialchars($record['employee_id']); ?></h6> <small><?php echo date('F Y'); ?></small> </div> <small><?php echo htmlspecialchars($record['full_name']); ?></small> </div> <div class="card-body p-3"> <!-- Attendance Summary --> <div class="row text-center mb-3"> <div class="col-6"> <div class="badge bg-success d-block p-2 mb-1"> <?php echo $record['summary']['present_days']; ?> </div> <small class="text-muted">Present</small> </div> <div class="col-6"> <div class="badge bg-danger d-block p-2 mb-1"> <?php echo $record['summary']['absent_days']; ?> </div> <small class="text-muted">Absent</small> </div> </div> <!-- Salary Information --> <div class="border-top pt-3"> <div class="row"> <div class="col-6"> <small class="text-muted">Basic Salary:</small> <div class="fw-bold">₹<?php echo number_format($record['basic_salary'], 2); ?></div> </div> <div class="col-6"> <small class="text-muted">Deductions:</small> <div class="fw-bold text-danger">₹<?php echo number_format($record['salary']['total_deduction'], 2); ?></div> </div> </div> <div class="text-center mt-2"> <small class="text-muted">Net Salary:</small> <div class="h5 mb-0 text-success">₹<?php echo number_format($record['salary']['net_salary'], 2); ?></div> </div> </div> </div> </div> </div> <?php endforeach; ?> </div> </div> </div> </div> </div> <!-- Content Row --> <div class="row"> <!-- Recent Transactions --> <div class="col-lg-8 mb-4"> <div class="card shadow mb-4"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Recent Transactions</h6> <a href="transactions.php" class="btn btn-sm btn-primary">View All</a> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered" width="100%" cellspacing="0"> <thead> <tr> <th>Invoice No.</th> <th>Barcode No.</th> <th>Receiver</th> <th>Sender</th> <th>COD Value</th> <th>Type</th> <th>Date</th> </tr> </thead> <tbody> <?php foreach ($recentTransactions as $transaction): ?> <tr> <td><span class="badge bg-primary"><?php echo htmlspecialchars($transaction['invoice_number'] ?? 'N/A'); ?></span></td> <td><?php echo htmlspecialchars($transaction['barcode_no']); ?></td> <td><?php echo htmlspecialchars($transaction['receiver_name']); ?></td> <td><?php echo htmlspecialchars($transaction['sender_name']); ?></td> <td>₹<?php echo number_format($transaction['total_amount']); ?></td> <td> <span class="badge bg-info"> <?php echo ucfirst($transaction['transaction_type'] ?? 'COD'); ?> </span> </td> <td><?php echo date('d M Y', strtotime($transaction['order_date'])); ?></td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> <!-- Upcoming Reminders --> <div class="col-lg-4 mb-4"> <div class="card shadow mb-4"> <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between"> <h6 class="m-0 font-weight-bold text-primary">Upcoming Reminders</h6> <a href="reminders.php" class="btn btn-sm btn-primary">View All</a> </div> <div class="card-body"> <?php if (empty($upcomingReminders)): ?> <p class="text-muted">No upcoming reminders</p> <?php else: ?> <?php foreach ($upcomingReminders as $reminder): ?> <div class="reminder-item mb-3 p-3 border rounded"> <div class="d-flex justify-content-between align-items-start"> <div> <h6 class="mb-1"><?php echo htmlspecialchars($reminder['client_name']); ?></h6> <p class="mb-1 text-muted"> <span class="badge bg-<?php echo $reminder['reminder_type'] == 'payment' ? 'warning' : ($reminder['reminder_type'] == 'delivery' ? 'info' : 'secondary'); ?> me-2"> <?php echo ucfirst($reminder['reminder_type']); ?> </span> ₹<?php echo number_format($reminder['amount_pending']); ?> pending </p> <small class="text-danger"> <i class="fas fa-calendar me-1"></i> Due: <?php echo date('d M Y', strtotime($reminder['reminder_date'])); ?> </small> <?php if ($reminder['status'] == 'overdue'): ?> <br><small class="text-danger"><i class="fas fa-exclamation-triangle me-1"></i>Overdue</small> <?php endif; ?> </div> <div> <span class="badge bg-<?php echo $reminder['status'] == 'pending' ? 'warning' : 'danger'; ?>"> <?php echo ucfirst($reminder['status']); ?> </span> </div> </div> </div> <?php endforeach; ?> <?php endif; ?> </div> </div> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="assets/js/dashboard.js"></script> <script> // Pass PHP data to JavaScript const monthlyRevenueData = <?php echo json_encode($monthlyRevenue); ?>; const sellerPerformanceData = <?php echo json_encode($sellerPerformance); ?>; </script> </body> </html>