« Back to History
punch.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php // /erp/attendance/punch.php require_once __DIR__ . '/../erp/partials/header.php'; require_once __DIR__ . '/../core/db.php'; require_once __DIR__ . '/../modules/auth/auth.php'; // $company_id and $current_user should be provided by auth include // If you want to let admin punch for others, provide employee list; otherwise current user punches self. $db = getDB(); // Fetch employees if current user is admin (so admin can choose employee). Otherwise show current user only. $employees = []; $can_choose_employee = in_array($current_user['role'] ?? 'staff', ['owner','admin','hr']); if ($can_choose_employee) { $stmt = $db->prepare("SELECT id, employee_code, name FROM employee_master WHERE company_id = :cid ORDER BY name"); $stmt->execute([':cid'=>$company_id]); $employees = $stmt->fetchAll(PDO::FETCH_ASSOC); } $logged_employee_id = $current_user['employee_id'] ?? ($current_user['id'] ?? 0); ?> <div class="container fc-punch-page"> <div class="card"> <div class="card-header"> <h3 class="card-title">Attendance Punch</h3> </div> <div class="card-body"> <form id="fc-punch-form" class="form-grid" onsubmit="return false;"> <?php if ($can_choose_employee): ?> <div class="form-row"> <label class="label">Employee</label> <select id="employee_id" class="input"> <option value="">-- Select employee --</option> <?php foreach ($employees as $e): ?> <option value="<?= htmlspecialchars($e['id']) ?>"><?= htmlspecialchars($e['name'] . ' [' . ($e['employee_code'] ?: $e['id']) . ']') ?></option> <?php endforeach; ?> </select> </div> <?php else: ?> <input type="hidden" id="employee_id" value="<?= htmlspecialchars($logged_employee_id) ?>"> <div class="form-row"> <label class="label">Employee</label> <div class="readonly"><?= htmlspecialchars($current_user['name'] ?? 'You') ?></div> </div> <?php endif; ?> <div class="form-row"> <label class="label">Method</label> <select id="method" class="input"> <option value="face">Face (camera)</option> <option value="manual">Manual (no photo)</option> <option value="web">Web</option> </select> </div> <div class="form-row"> <label class="label">Direction</label> <select id="direction" class="input"> <option value="in">IN</option> <option value="out">OUT</option> </select> </div> <div class="form-row" id="fc-camera-row"> <label class="label">Camera</label> <div class="fc-video-wrap"> <video id="fc-video" autoplay playsinline></video> </div> <div class="fc-camera-actions"> <button id="fc-capture-btn" class="btn" type="button">Capture & Punch</button> <button id="fc-stop-btn" class="btn" type="button">Stop Camera</button> </div> </div> <div class="form-row" id="fc-manual-row" style="display:none;"> <label class="label">Manual note</label> <input id="manual_note" class="input" placeholder="Optional note/reason"> <button id="fc-manual-punch-btn" class="btn" type="button">Submit Manual Punch</button> </div> <div class="form-row"> <div id="fc-punch-result" class="notice"></div> </div> </form> </div> </div> </div> <script src="/erp/assets/js/attendance-punch.js"></script> <?php require_once __DIR__ . '/../erp/partials/footer.php'; ?>