« Back to History
fani_entry.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================ File: fani_entry.php Purpose: Separate Fani Entry Shows ONLY Pasaria Employees Inserts ONLY into pasaria_entry_new ============================================================ */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('fani_entry'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ================= MASTER DATA ================= */ /* Machines */ $st = $pdo->prepare(" SELECT id, code FROM machines WHERE company_id = ? AND is_active = 1 ORDER BY code "); $st->execute([$company_id]); $machines = $st->fetchAll(PDO::FETCH_ASSOC); /* ONLY Pasaria Employees (same as old pasaria page) */ $st = $pdo->prepare(" SELECT id, name FROM company_employee_master WHERE company_id = ? AND is_active = 1 AND designation_name = 'Pasaria' ORDER BY name "); $st->execute([$company_id]); $employees = $st->fetchAll(PDO::FETCH_ASSOC); /* Types */ $st = $pdo->prepare(" SELECT pasaria_type FROM pasaria_rates WHERE company_id = ? ORDER BY pasaria_type "); $st->execute([$company_id]); $types = $st->fetchAll(PDO::FETCH_ASSOC); $msg = $err = ''; /* ================= SUBMIT ================= */ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $machine_id = (int)($_POST['machine_id'] ?? 0); $employee_id = (int)($_POST['employee_id'] ?? 0); $type = trim($_POST['type'] ?? ''); $entry_date = $_POST['entry_date'] ?? date('Y-m-d'); if (!$machine_id || !$employee_id || $type === '') { $err = 'All fields are required.'; } else { try { $st = $pdo->prepare(" SELECT code FROM machines WHERE id = ? AND company_id = ? "); $st->execute([$machine_id, $company_id]); $code = (string)$st->fetchColumn(); if (!$code) { throw new Exception('Invalid machine selected.'); } if (!preg_match('/(\d+)$/', $code, $m)) { throw new Exception('Machine code format invalid.'); } $machine_no = ltrim($m[1], '0'); if ($machine_no === '') $machine_no = '0'; /* Insert ONLY into pasaria_entry_new */ $st = $pdo->prepare(" INSERT INTO pasaria_entry_new (company_id, pasaria_date, employee_id, pasaria_type, machine_no, created_at) VALUES (?,?,?,?,?,NOW()) "); $st->execute([ $company_id, $entry_date, $employee_id, $type, $machine_no ]); $msg = 'Fani entry saved successfully.'; } catch (Exception $e) { $err = $e->getMessage(); } } } require_once __DIR__ . '/partials/header.php'; ?> <div class="container py-4"> <div class="card shadow-sm"> <div class="card-header bg-primary text-white"> <h5 class="mb-0">Fani Entry</h5> </div> <div class="card-body"> <?php if ($msg): ?> <div class="alert alert-success"><?=h($msg)?></div> <?php endif; ?> <?php if ($err): ?> <div class="alert alert-danger"><?=h($err)?></div> <?php endif; ?> <form method="post"> <div class="row g-3"> <div class="col-md-3"> <label class="form-label">Machine</label> <select name="machine_id" class="form-select" required> <option value="">Select</option> <?php foreach ($machines as $m): ?> <option value="<?=$m['id']?>"><?=h($m['code'])?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label">Pasaria Employee</label> <select name="employee_id" class="form-select" required> <option value="">Select</option> <?php foreach ($employees as $e): ?> <option value="<?=$e['id']?>"><?=h($e['name'])?></option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label">Type</label> <select name="type" class="form-select" required> <option value="">Select</option> <?php foreach ($types as $t): ?> <option value="<?=h($t['pasaria_type'])?>"> <?=h($t['pasaria_type'])?> </option> <?php endforeach; ?> </select> </div> <div class="col-md-3"> <label class="form-label">Date</label> <input type="date" name="entry_date" class="form-control" value="<?=date('Y-m-d')?>"> </div> <div class="col-12 text-end"> <button type="submit" class="btn btn-success"> Save Entry </button> </div> </div> </form> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>