« Back to History
advance_report.php
|
20261119_140743.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================ File: /erp/advance_report.php Purpose: Employee Advance Report (From Date onwards) with Row Print Option ============================================================================ */ header('X-Frame-Options: SAMEORIGIN'); error_reporting(E_ALL); ini_set('display_errors', '1'); /* ================= AUTH & CONTEXT ================= */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('attendance_dashboard'); $pdo = $ctx['pdo']; $COMPANY_ID = (int)$ctx['company_id']; $u = $ctx['user'] ?? null; function j($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function money0($n){ return number_format((float)$n, 2, '.', ''); } /* ================= FILTER ================= */ $from_date = $_GET['from_date'] ?? date('Y-m-01'); $where = ["ea.company_id = :cid"]; $params = [':cid' => $COMPANY_ID]; if (!empty($from_date)) { $where[] = "ea.date >= :from"; $params[':from'] = $from_date; } $sql = " SELECT ea.*, cem.name AS employee_name FROM employee_advance ea LEFT JOIN company_employee_master cem ON cem.id = ea.employee_id WHERE " . implode(' AND ', $where) . " ORDER BY ea.id DESC "; $stmt = $pdo->prepare($sql); $stmt->execute($params); $ROWS = $stmt->fetchAll(PDO::FETCH_ASSOC); /* ================= TOTAL SUM ================= */ $total_amount = 0; foreach ($ROWS as $r) { $total_amount += (float)$r['amount']; } /* ================= HEADER ================= */ require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-4"> <div class="card mb-4 shadow-sm"> <div class="card-body"> <form method="get" class="row g-3 align-items-end"> <div class="col-md-4"> <label class="form-label fw-bold">Start Date</label> <input type="date" name="from_date" value="<?= j($from_date) ?>" class="form-control"> </div> <div class="col-md-2"> <button class="btn btn-primary w-100">Generate</button> </div> </form> </div> </div> <div class="card shadow-sm"> <div class="card-header bg-dark text-white d-flex justify-content-between align-items-center"> <h5 class="mb-0">Advance Report (From <?= j(date('d-M-Y', strtotime($from_date))) ?>)</h5> <span class="badge bg-light text-dark fs-6"> Total: ₹<?= money0($total_amount) ?> </span> </div> <div class="table-responsive"> <table class="table table-bordered table-hover mb-0"> <thead class="table-light"> <tr> <th>ID</th> <th>Date</th> <th>Employee</th> <th class="text-end">Amount</th> <th>Remark</th> <th>Status</th> <th class="text-center">Action</th> </tr> </thead> <tbody> <?php if (!$ROWS): ?> <tr> <td colspan="7" class="text-center py-4 text-muted fw-bold"> No advance records found for this period. </td> </tr> <?php else: ?> <?php foreach ($ROWS as $r): ?> <tr> <td><?= (int)$r['id'] ?></td> <td><?= j(date('d-M-Y', strtotime($r['date']))) ?></td> <td><?= j($r['employee_name'] ?? 'Unknown Employee') ?></td> <td class="text-end fw-bold text-danger">₹<?= money0($r['amount']) ?></td> <td><?= j($r['remark']) ?></td> <td> <span class="badge bg-<?= ($r['status'] === 'Approved' || $r['status'] === 'Paid') ? 'success' : 'secondary' ?>"> <?= j($r['status']) ?> </span> </td> <td class="text-center"> <a href="print_advance_slip.php?id=<?= (int)$r['id'] ?>" target="_blank" class="btn btn-sm btn-outline-secondary"> <i class="bi bi-printer"></i> Print </a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> <div class="card-footer text-end fw-bold bg-light fs-5"> Grand Total: <span class="text-danger">₹<?= money0($total_amount) ?></span> </div> </div> </div> <?php /* ================= FOOTER ================= */ require_once __DIR__ . '/partials/footer.php'; ?>