147 lines
5.0 KiB
PHP
147 lines
5.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/includes/layout.php';
|
|
|
|
$pdo = db();
|
|
$departments = $pdo->query("SELECT id, name FROM departments ORDER BY name ASC")->fetchAll();
|
|
$positions = $pdo->query("SELECT id, name FROM positions ORDER BY name ASC")->fetchAll();
|
|
|
|
$q = trim($_GET['q'] ?? '');
|
|
$deptId = $_GET['dept_id'] ?? '';
|
|
$posId = $_GET['position_id'] ?? '';
|
|
$status = $_GET['status'] ?? '';
|
|
|
|
$where = [];
|
|
$params = [];
|
|
if ($q !== '') {
|
|
$where[] = "(e.full_name LIKE :q OR e.employee_code LIKE :q OR e.email LIKE :q)";
|
|
$params[':q'] = '%' . $q . '%';
|
|
}
|
|
if ($deptId !== '') {
|
|
$where[] = "e.dept_id = :dept_id";
|
|
$params[':dept_id'] = $deptId;
|
|
}
|
|
if ($posId !== '') {
|
|
$where[] = "e.position_id = :position_id";
|
|
$params[':position_id'] = $posId;
|
|
}
|
|
if ($status !== '') {
|
|
$where[] = "e.status = :status";
|
|
$params[':status'] = $status;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT e.*, d.name AS dept_name, p.name AS position_name
|
|
FROM employees e
|
|
LEFT JOIN departments d ON d.id = e.dept_id
|
|
LEFT JOIN positions p ON p.id = e.position_id
|
|
";
|
|
if ($where) {
|
|
$sql .= " WHERE " . implode(' AND ', $where);
|
|
}
|
|
$sql .= " ORDER BY e.full_name ASC";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$employees = $stmt->fetchAll();
|
|
|
|
render_header('Data Pegawai', 'employees');
|
|
?>
|
|
|
|
<div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-4">
|
|
<div>
|
|
<h1 class="h3 fw-semibold mb-1">Data Pegawai</h1>
|
|
<p class="small-muted mb-0">Kelola profil, status kerja, dan penempatan pegawai.</p>
|
|
</div>
|
|
<a href="employee_new.php" class="btn btn-primary">Tambah Pegawai</a>
|
|
</div>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-body">
|
|
<form class="row g-2 align-items-end" method="get">
|
|
<div class="col-md-4">
|
|
<label class="form-label small-muted">Cari</label>
|
|
<input type="text" class="form-control" name="q" value="<?= e($q) ?>" placeholder="Nama, kode, atau email">
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small-muted">Departemen</label>
|
|
<select class="form-select" name="dept_id">
|
|
<option value="">Semua</option>
|
|
<?php foreach ($departments as $dept): ?>
|
|
<option value="<?= e((string)$dept['id']) ?>" <?= $deptId == $dept['id'] ? 'selected' : '' ?>><?= e($dept['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<label class="form-label small-muted">Jabatan</label>
|
|
<select class="form-select" name="position_id">
|
|
<option value="">Semua</option>
|
|
<?php foreach ($positions as $pos): ?>
|
|
<option value="<?= e((string)$pos['id']) ?>" <?= $posId == $pos['id'] ? 'selected' : '' ?>><?= e($pos['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-2">
|
|
<label class="form-label small-muted">Status</label>
|
|
<select class="form-select" name="status">
|
|
<option value="">Semua</option>
|
|
<?php foreach (['Aktif', 'Probation', 'Nonaktif'] as $st): ?>
|
|
<option value="<?= e($st) ?>" <?= $status === $st ? 'selected' : '' ?>><?= e($st) ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-12 d-flex gap-2">
|
|
<button class="btn btn-outline-primary" type="submit">Terapkan Filter</button>
|
|
<a class="btn btn-light border" href="employees.php">Reset</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex align-items-center justify-content-between">
|
|
<span class="section-title">Daftar Pegawai</span>
|
|
<span class="small-muted"><?= count($employees) ?> hasil</span>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (count($employees) === 0): ?>
|
|
<div class="empty-state">Belum ada pegawai yang cocok dengan filter ini.</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Nama</th>
|
|
<th>Kode</th>
|
|
<th>Departemen</th>
|
|
<th>Jabatan</th>
|
|
<th>Status</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($employees as $emp): ?>
|
|
<tr>
|
|
<td>
|
|
<div class="fw-semibold"><?= e($emp['full_name']) ?></div>
|
|
<div class="small text-muted"><?= e($emp['email'] ?? '-') ?></div>
|
|
</td>
|
|
<td><?= e($emp['employee_code']) ?></td>
|
|
<td><?= e($emp['dept_name'] ?? '—') ?></td>
|
|
<td><?= e($emp['position_name'] ?? '—') ?></td>
|
|
<td><span class="badge bg-light text-dark border"><?= e($emp['status']) ?></span></td>
|
|
<td class="text-end">
|
|
<a class="btn btn-sm btn-outline-primary" href="employee_view.php?id=<?= e((string)$emp['id']) ?>">Detail</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php render_footer(); ?>
|