525 lines
33 KiB
HTML
525 lines
33 KiB
HTML
{% extends 'base.html' %}
|
|||
|
|
{% block page_title %}Data Karyawan{% endblock %}
|
||
|
|
|
||
|
|
{% block content %}
|
||
|
|
<div class="mb-6 flex flex-col sm:flex-row sm:justify-between sm:items-end space-y-4 sm:space-y-0">
|
||
|
|
<div>
|
||
|
|
<p class="text-xs font-bold text-kerinci uppercase tracking-widest mb-1">Manajemen Aset</p>
|
||
|
|
<div class="flex items-center space-x-3">
|
||
|
|
<h2 class="text-3xl font-extrabold text-gray-900">Data Karyawan</h2>
|
||
|
|
<button onclick="openGuideModal()" class="w-5 h-5 rounded-full bg-gray-200 text-gray-600 hover:bg-kerinci hover:text-white flex items-center justify-center text-xs font-extrabold transition-colors shadow-sm shrink-0" title="Panduan Halaman">!</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="flex items-center space-x-3 w-full sm:w-auto">
|
||
|
|
<div class="relative inline-block w-full sm:w-auto flex-1 sm:flex-none">
|
||
|
|
<button onclick="var d = document.getElementById('exportMenuEmployee'); d.style.display = d.style.display === 'block' ? 'none' : 'block'; event.stopPropagation();" class="w-full border border-kerinci text-kerinci rounded-xl px-4 py-2 text-sm font-bold hover:bg-kerinci/10 transition-colors flex items-center space-x-2 justify-center">
|
||
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
|
||
|
|
<span>Ekspor Karyawan</span>
|
||
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
|
||
|
|
</button>
|
||
|
|
<div id="exportMenuEmployee" style="display: none;" class="absolute right-0 mt-2 w-48 bg-white rounded-xl shadow-[0_8px_30px_rgb(0,0,0,0.12)] border border-gray-100 z-50">
|
||
|
|
<a href="{% url 'employee_export_pdf' %}{% if search_query %}?q={{ search_query }}{% endif %}" target="_blank" class="flex items-center px-4 py-3 text-sm text-gray-700 hover:bg-gray-50 hover:text-kerinci rounded-t-xl font-bold transition-colors">
|
||
|
|
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path></svg>
|
||
|
|
Format PDF
|
||
|
|
</a>
|
||
|
|
<div class="h-px bg-gray-100 mx-2"></div>
|
||
|
|
<a href="{% url 'employee_export_excel' %}{% if search_query %}?q={{ search_query }}{% endif %}" class="flex items-center px-4 py-3 text-sm text-green-600 hover:bg-green-50 rounded-b-xl font-bold transition-colors">
|
||
|
|
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
|
||
|
|
Format Excel (.xlsx)
|
||
|
|
</a>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
{% if not is_read_only %}
|
||
|
|
<button onclick="openAddEmployeeModal()" class="bg-kerinci text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors flex items-center space-x-2 justify-center w-full sm:w-auto flex-1 sm:flex-none">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
|
||
|
|
<span>Tambah Karyawan</span>
|
||
|
|
</button>
|
||
|
|
{% endif %}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Status Tabs -->
|
||
|
|
<div class="flex space-x-2 mb-6 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
|
||
|
|
<a href="?status=aktif{% if search_query %}&q={{ search_query }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'aktif' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
|
||
|
|
Karyawan Aktif
|
||
|
|
<span class="ml-2 {% if status_filter == 'aktif' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ count_active|default:"0" }}</span>
|
||
|
|
</a>
|
||
|
|
<a href="?status=nonaktif{% if search_query %}&q={{ search_query }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'nonaktif' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
|
||
|
|
Karyawan Non-Aktif
|
||
|
|
<span class="ml-2 {% if status_filter == 'nonaktif' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ count_inactive|default:"0" }}</span>
|
||
|
|
</a>
|
||
|
|
<a href="?status=semua{% if search_query %}&q={{ search_query }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'semua' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
|
||
|
|
Semua Karyawan
|
||
|
|
<span class="ml-2 {% if status_filter == 'semua' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ count_all|default:"0" }}</span>
|
||
|
|
</a>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Search Bar -->
|
||
|
|
<div class="mb-4">
|
||
|
|
<form id="searchForm" method="GET" class="relative w-full sm:w-96">
|
||
|
|
<input type="hidden" name="status" value="{{ status_filter }}">
|
||
|
|
<input type="text" id="searchInput" name="q" value="{{ search_query }}" placeholder="Cari NIK atau nama karyawan..." class="w-full pl-10 pr-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white shadow-sm placeholder-gray-400">
|
||
|
|
<svg class="w-5 h-5 text-gray-400 absolute left-3 top-2.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path></svg>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="bg-white rounded-none sm:rounded-2xl shadow-sm border border-gray-100 overflow-hidden w-full" id="tableContainer">
|
||
|
|
<div class="overflow-x-auto">
|
||
|
|
<table class="w-full text-left border-collapse">
|
||
|
|
<thead>
|
||
|
|
<tr class="bg-[#002060] text-white text-[11px] uppercase tracking-widest">
|
||
|
|
<th class="p-4 font-bold text-center w-16">No</th>
|
||
|
|
<th class="p-4 font-bold">Nomor Induk (NIK)</th>
|
||
|
|
<th class="p-4 font-bold min-w-[200px]">Nama Lengkap</th>
|
||
|
|
<th class="p-4 font-bold min-w-[150px]">Jabatan</th>
|
||
|
|
<th class="p-4 font-bold text-center">Status</th>
|
||
|
|
<th class="p-4 font-bold text-center">Aset Yang Digunakan</th>
|
||
|
|
<th class="p-4 font-bold text-center">Aksi</th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody class="text-sm divide-y divide-gray-50">
|
||
|
|
{% for emp in employees %}
|
||
|
|
<tr class="hover:bg-gray-50/50 transition-colors {% if not emp.is_active %}bg-gray-50/60 opacity-75{% endif %}">
|
||
|
|
<td class="p-4 text-gray-500 font-medium text-center">{{ forloop.counter }}</td>
|
||
|
|
<td class="p-4">
|
||
|
|
<a href="{% url 'employee_detail' emp.id %}" class="block group">
|
||
|
|
<span class="font-bold text-gray-900 group-hover:text-kerinci transition-colors">{{ emp.nik }}</span>
|
||
|
|
</a>
|
||
|
|
</td>
|
||
|
|
<td class="p-4">
|
||
|
|
<a href="{% url 'employee_detail' emp.id %}" class="block group">
|
||
|
|
<span class="font-bold text-gray-800 group-hover:text-kerinci transition-colors">{{ emp.name }}</span>
|
||
|
|
</a>
|
||
|
|
</td>
|
||
|
|
<td class="p-4">
|
||
|
|
<span class="text-gray-600 font-medium">{{ emp.position|default:"-" }}</span>
|
||
|
|
</td>
|
||
|
|
<td class="p-4 text-center">
|
||
|
|
{% if emp.is_active %}
|
||
|
|
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-emerald-50 text-emerald-600 border border-emerald-100">
|
||
|
|
Aktif
|
||
|
|
</span>
|
||
|
|
{% else %}
|
||
|
|
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-gray-100 text-gray-500 border border-gray-200">
|
||
|
|
Non-Aktif
|
||
|
|
</span>
|
||
|
|
{% endif %}
|
||
|
|
</td>
|
||
|
|
<td class="p-4 text-center">
|
||
|
|
{% if emp.active_assets > 0 %}
|
||
|
|
<a href="{% url 'employee_detail' emp.id %}" class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-emerald-50 text-emerald-600 hover:bg-emerald-100 transition-colors border border-emerald-100">
|
||
|
|
{{ emp.active_assets }} Perangkat
|
||
|
|
<svg class="w-3 h-3 ml-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path></svg>
|
||
|
|
</a>
|
||
|
|
{% else %}
|
||
|
|
<span class="text-gray-400 italic text-xs">Tidak ada pinjaman</span>
|
||
|
|
{% endif %}
|
||
|
|
</td>
|
||
|
|
<td class="p-4 text-center">
|
||
|
|
<div class="flex items-center justify-center space-x-2">
|
||
|
|
{% if emp.is_active %}
|
||
|
|
<button onclick="openEditEmployeeModal('{{ emp.id }}', '{{ emp.nik|escapejs }}', '{{ emp.name|escapejs }}', '{{ emp.position|default:""|escapejs }}')" class="p-1.5 text-amber-500 hover:bg-amber-50 rounded-lg transition-colors" title="Edit Karyawan">
|
||
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>
|
||
|
|
</button>
|
||
|
|
<button onclick="openDeleteEmployeeModal('{{ emp.id }}', '{{ emp.name|escapejs }}', {{ emp.active_assets }})" class="p-1.5 {% if emp.active_assets > 0 %}text-gray-300 cursor-not-allowed{% else %}text-red-500 hover:bg-red-50{% endif %} rounded-lg transition-colors" {% if emp.active_assets > 0 %}title="Tidak bisa dinonaktifkan karena masih memegang aset"{% else %}title="Nonaktifkan Karyawan"{% endif %} {% if emp.active_assets > 0 %}disabled{% endif %}>
|
||
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"></path></svg>
|
||
|
|
</button>
|
||
|
|
{% else %}
|
||
|
|
<form action="{% url 'employee_activate' emp.id %}" method="POST" class="inline" onsubmit="return confirm('Aktifkan kembali karyawan {{ emp.name|escapejs }}?');">
|
||
|
|
{% csrf_token %}
|
||
|
|
<button type="submit" class="p-1.5 text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors" title="Aktifkan Kembali">
|
||
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg>
|
||
|
|
</button>
|
||
|
|
</form>
|
||
|
|
{% endif %}
|
||
|
|
</div>
|
||
|
|
</td>
|
||
|
|
</tr>
|
||
|
|
{% empty %}
|
||
|
|
<tr>
|
||
|
|
<td colspan="7" class="p-8 text-center text-gray-400 text-sm">
|
||
|
|
<div class="flex flex-col items-center justify-center space-y-3">
|
||
|
|
<svg class="w-12 h-12 text-gray-200" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
|
||
|
|
<p>Belum ada data karyawan.</p>
|
||
|
|
</div>
|
||
|
|
</td>
|
||
|
|
</tr>
|
||
|
|
{% endfor %}
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
{% include 'components/pagination.html' %}
|
||
|
|
</div>
|
||
|
|
|
||
|
|
|
||
|
|
<div id="addEmployeeModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
|
||
|
|
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity opacity-0" id="empOverlay" onclick="closeAddEmployeeModal()"></div>
|
||
|
|
|
||
|
|
<div class="bg-white rounded-2xl shadow-2xl w-[90%] mx-auto max-h-[90vh] overflow-y-auto max-w-lg relative z-10 p-6 transform transition-all scale-95 opacity-0" id="empCard">
|
||
|
|
<div class="flex justify-between items-center mb-6">
|
||
|
|
<h3 class="text-xl font-extrabold text-gray-900">Tambah Data Karyawan</h3>
|
||
|
|
<button onclick="closeAddEmployeeModal()" class="text-gray-400 hover:text-gray-600 transition-colors p-2 rounded-full hover:bg-gray-100">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<form action="{% url 'employee_create' %}" method="POST" class="space-y-4" onsubmit="submitAddEmployee(event)">
|
||
|
|
{% csrf_token %}
|
||
|
|
<div>
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Nomor Induk Karyawan (NIK) <span class="text-red-500">*</span></label>
|
||
|
|
<input type="text" id="add_emp_nik" name="nik" required class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white" placeholder="Contoh: 0001">
|
||
|
|
<p id="add_emp_error" class="text-red-500 text-xs mt-1 hidden font-bold"></p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Nama Lengkap <span class="text-red-500">*</span></label>
|
||
|
|
<input type="text" id="add_emp_name" name="name" required class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white" placeholder="Contoh: Ahmad Budi">
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mt-4">
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Jabatan</label>
|
||
|
|
<input type="text" id="add_emp_position" name="position" class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white" placeholder="Contoh: Staff IT">
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
|
||
|
|
<button type="button" onclick="closeAddEmployeeModal()" class="px-5 py-2 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50 transition-colors">Batal</button>
|
||
|
|
<button type="submit" class="px-5 py-2 bg-kerinci text-white font-bold rounded-xl text-sm shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors">Simpan Data</button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Modal Edit Karyawan -->
|
||
|
|
<div id="editEmployeeModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
|
||
|
|
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity opacity-0" id="editEmpOverlay" onclick="closeEditEmployeeModal()"></div>
|
||
|
|
|
||
|
|
<div class="bg-white rounded-2xl shadow-2xl w-[90%] mx-auto max-h-[90vh] overflow-y-auto max-w-lg relative z-10 p-6 transform transition-all scale-95 opacity-0" id="editEmpCard">
|
||
|
|
<div class="flex justify-between items-center mb-6">
|
||
|
|
<h3 class="text-xl font-extrabold text-gray-900">Edit Data Karyawan</h3>
|
||
|
|
<button onclick="closeEditEmployeeModal()" class="text-gray-400 hover:text-gray-600 transition-colors p-2 rounded-full hover:bg-gray-100">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<form id="editEmployeeForm" method="POST" class="space-y-4" onsubmit="submitEditEmployee(event)">
|
||
|
|
{% csrf_token %}
|
||
|
|
<div>
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Nomor Induk Karyawan (NIK) <span class="text-red-500">*</span></label>
|
||
|
|
<input type="text" id="edit_emp_nik" name="nik" required class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white">
|
||
|
|
<p id="edit_emp_error" class="text-red-500 text-xs mt-1 hidden font-bold"></p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div>
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Nama Lengkap <span class="text-red-500">*</span></label>
|
||
|
|
<input type="text" id="edit_emp_name" name="name" required class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white">
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mt-4">
|
||
|
|
<label class="block text-sm font-bold text-gray-700 mb-1.5">Jabatan</label>
|
||
|
|
<input type="text" id="edit_emp_position" name="position" class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white">
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
|
||
|
|
<button type="button" onclick="closeEditEmployeeModal()" class="px-5 py-2 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50 transition-colors">Batal</button>
|
||
|
|
<button type="submit" class="px-5 py-2 bg-amber-500 text-white font-bold rounded-xl text-sm shadow-sm hover:bg-amber-600 transition-colors">Simpan Perubahan</button>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Modal Hapus Karyawan -->
|
||
|
|
<div id="deleteEmployeeModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
|
||
|
|
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity opacity-0" id="delEmpOverlay" onclick="closeDeleteEmployeeModal()"></div>
|
||
|
|
|
||
|
|
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-md relative mx-auto z-10 p-8 transform transition-all scale-95 opacity-0 text-center" id="delEmpCard">
|
||
|
|
<div class="w-20 h-20 bg-red-50 border-[6px] border-red-100 text-red-500 rounded-full flex items-center justify-center mx-auto mb-6">
|
||
|
|
<svg class="w-10 h-10" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<h3 class="text-2xl font-extrabold text-gray-900 mb-2">Nonaktifkan Karyawan?</h3>
|
||
|
|
<p class="text-gray-500 mb-8 max-w-sm mx-auto">Apakah Anda yakin ingin menonaktifkan karyawan <strong id="del_emp_name"></strong>? Karyawan yang dinonaktifkan tidak akan dapat menerima penugasan aset baru. Seluruh data historis pemakaian aset tetap aman dipertahankan dan dapat diaktifkan kembali nanti.</p>
|
||
|
|
|
||
|
|
<form id="deleteEmployeeForm" method="POST" class="flex justify-center space-x-4">
|
||
|
|
{% csrf_token %}
|
||
|
|
<button type="button" onclick="closeDeleteEmployeeModal()" class="px-6 py-3 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50 transition-colors">Batal</button>
|
||
|
|
<button type="submit" class="px-6 py-3 bg-red-500 text-white font-bold rounded-xl text-sm shadow-sm hover:bg-red-600 transition-colors">Ya, Nonaktifkan</button>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
function openAddEmployeeModal() {
|
||
|
|
const modal = document.getElementById('addEmployeeModal');
|
||
|
|
const overlay = document.getElementById('empOverlay');
|
||
|
|
const card = document.getElementById('empCard');
|
||
|
|
|
||
|
|
modal.classList.remove('hidden');
|
||
|
|
setTimeout(() => {
|
||
|
|
overlay.classList.remove('opacity-0');
|
||
|
|
overlay.classList.add('opacity-100');
|
||
|
|
card.classList.remove('scale-95', 'opacity-0');
|
||
|
|
card.classList.add('scale-100', 'opacity-100');
|
||
|
|
|
||
|
|
document.getElementById('add_emp_nik').focus();
|
||
|
|
}, 10);
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeAddEmployeeModal() {
|
||
|
|
const modal = document.getElementById('addEmployeeModal');
|
||
|
|
const overlay = document.getElementById('empOverlay');
|
||
|
|
const card = document.getElementById('empCard');
|
||
|
|
|
||
|
|
overlay.classList.remove('opacity-100');
|
||
|
|
overlay.classList.add('opacity-0');
|
||
|
|
card.classList.remove('scale-100', 'opacity-100');
|
||
|
|
card.classList.add('scale-95', 'opacity-0');
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
modal.classList.add('hidden');
|
||
|
|
}, 300);
|
||
|
|
}
|
||
|
|
|
||
|
|
function openEditEmployeeModal(id, nik, name, position) {
|
||
|
|
document.getElementById('editEmployeeForm').action = '/karyawan/' + id + '/edit/';
|
||
|
|
document.getElementById('edit_emp_nik').value = nik;
|
||
|
|
document.getElementById('edit_emp_name').value = name;
|
||
|
|
document.getElementById('edit_emp_position').value = position;
|
||
|
|
document.getElementById('edit_emp_error').classList.add('hidden');
|
||
|
|
|
||
|
|
const modal = document.getElementById('editEmployeeModal');
|
||
|
|
const overlay = document.getElementById('editEmpOverlay');
|
||
|
|
const card = document.getElementById('editEmpCard');
|
||
|
|
|
||
|
|
modal.classList.remove('hidden');
|
||
|
|
setTimeout(() => {
|
||
|
|
overlay.classList.remove('opacity-0');
|
||
|
|
overlay.classList.add('opacity-100');
|
||
|
|
card.classList.remove('scale-95', 'opacity-0');
|
||
|
|
card.classList.add('scale-100', 'opacity-100');
|
||
|
|
|
||
|
|
document.getElementById('edit_emp_nik').focus();
|
||
|
|
}, 10);
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeEditEmployeeModal() {
|
||
|
|
const modal = document.getElementById('editEmployeeModal');
|
||
|
|
const overlay = document.getElementById('editEmpOverlay');
|
||
|
|
const card = document.getElementById('editEmpCard');
|
||
|
|
|
||
|
|
overlay.classList.remove('opacity-100');
|
||
|
|
overlay.classList.add('opacity-0');
|
||
|
|
card.classList.remove('scale-100', 'opacity-100');
|
||
|
|
card.classList.add('scale-95', 'opacity-0');
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
modal.classList.add('hidden');
|
||
|
|
}, 300);
|
||
|
|
}
|
||
|
|
|
||
|
|
function openDeleteEmployeeModal(id, name, active_assets) {
|
||
|
|
if (active_assets > 0) return;
|
||
|
|
document.getElementById('deleteEmployeeForm').action = '/karyawan/' + id + '/delete/';
|
||
|
|
document.getElementById('del_emp_name').innerText = name;
|
||
|
|
|
||
|
|
const modal = document.getElementById('deleteEmployeeModal');
|
||
|
|
const overlay = document.getElementById('delEmpOverlay');
|
||
|
|
const card = document.getElementById('delEmpCard');
|
||
|
|
|
||
|
|
modal.classList.remove('hidden');
|
||
|
|
setTimeout(() => {
|
||
|
|
overlay.classList.remove('opacity-0');
|
||
|
|
overlay.classList.add('opacity-100');
|
||
|
|
card.classList.remove('scale-95', 'opacity-0');
|
||
|
|
card.classList.add('scale-100', 'opacity-100');
|
||
|
|
}, 10);
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeDeleteEmployeeModal() {
|
||
|
|
const modal = document.getElementById('deleteEmployeeModal');
|
||
|
|
const overlay = document.getElementById('delEmpOverlay');
|
||
|
|
const card = document.getElementById('delEmpCard');
|
||
|
|
|
||
|
|
overlay.classList.remove('opacity-100');
|
||
|
|
overlay.classList.add('opacity-0');
|
||
|
|
card.classList.remove('scale-100', 'opacity-100');
|
||
|
|
card.classList.add('scale-95', 'opacity-0');
|
||
|
|
|
||
|
|
setTimeout(() => {
|
||
|
|
modal.classList.add('hidden');
|
||
|
|
}, 300);
|
||
|
|
}
|
||
|
|
|
||
|
|
// AJAX Search
|
||
|
|
let searchTimeout;
|
||
|
|
const searchInput = document.getElementById('searchInput');
|
||
|
|
if (searchInput) {
|
||
|
|
const val = searchInput.value;
|
||
|
|
if (val) {
|
||
|
|
searchInput.focus();
|
||
|
|
searchInput.value = '';
|
||
|
|
searchInput.value = val;
|
||
|
|
}
|
||
|
|
|
||
|
|
searchInput.addEventListener('input', function() {
|
||
|
|
clearTimeout(searchTimeout);
|
||
|
|
searchTimeout = setTimeout(() => {
|
||
|
|
const url = new URL(window.location.href);
|
||
|
|
url.searchParams.set('q', searchInput.value);
|
||
|
|
|
||
|
|
// Update Export PDF Button URL
|
||
|
|
const exportBtn = document.getElementById('exportPdfBtn');
|
||
|
|
if (exportBtn) {
|
||
|
|
const exportUrl = new URL(exportBtn.href);
|
||
|
|
if (searchInput.value) {
|
||
|
|
exportUrl.searchParams.set('q', searchInput.value);
|
||
|
|
} else {
|
||
|
|
exportUrl.searchParams.delete('q');
|
||
|
|
}
|
||
|
|
exportBtn.href = exportUrl.toString();
|
||
|
|
}
|
||
|
|
|
||
|
|
const tableContainer = document.getElementById('tableContainer');
|
||
|
|
tableContainer.style.opacity = '0.5';
|
||
|
|
tableContainer.style.transition = 'opacity 0.2s';
|
||
|
|
|
||
|
|
fetch(url)
|
||
|
|
.then(response => response.text())
|
||
|
|
.then(html => {
|
||
|
|
const parser = new DOMParser();
|
||
|
|
const doc = parser.parseFromString(html, 'text/html');
|
||
|
|
const newTableContainer = doc.getElementById('tableContainer');
|
||
|
|
|
||
|
|
if (newTableContainer) {
|
||
|
|
tableContainer.innerHTML = newTableContainer.innerHTML;
|
||
|
|
}
|
||
|
|
|
||
|
|
tableContainer.style.opacity = '1';
|
||
|
|
window.history.pushState({}, '', url);
|
||
|
|
})
|
||
|
|
.catch(error => {
|
||
|
|
console.error('Error fetching search results:', error);
|
||
|
|
tableContainer.style.opacity = '1';
|
||
|
|
});
|
||
|
|
}, 300);
|
||
|
|
});
|
||
|
|
|
||
|
|
document.getElementById('searchForm').addEventListener('submit', function(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
async function submitAddEmployee(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
const form = e.target;
|
||
|
|
const btn = form.querySelector('button[type="submit"]');
|
||
|
|
const errorText = document.getElementById('add_emp_error');
|
||
|
|
|
||
|
|
btn.disabled = true;
|
||
|
|
errorText.classList.add('hidden');
|
||
|
|
errorText.innerText = '';
|
||
|
|
|
||
|
|
try {
|
||
|
|
const formData = new FormData(form);
|
||
|
|
const response = await fetch(form.action, {
|
||
|
|
method: 'POST',
|
||
|
|
body: formData,
|
||
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
||
|
|
});
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
window.location.reload();
|
||
|
|
} else {
|
||
|
|
const data = await response.json();
|
||
|
|
errorText.innerText = data.message || 'Terjadi kesalahan sistem.';
|
||
|
|
errorText.classList.remove('hidden');
|
||
|
|
btn.disabled = false;
|
||
|
|
}
|
||
|
|
} catch (err) {
|
||
|
|
errorText.innerText = 'Koneksi terputus. Coba lagi.';
|
||
|
|
errorText.classList.remove('hidden');
|
||
|
|
btn.disabled = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
async function submitEditEmployee(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
const form = e.target;
|
||
|
|
const btn = form.querySelector('button[type="submit"]');
|
||
|
|
const errorText = document.getElementById('edit_emp_error');
|
||
|
|
|
||
|
|
btn.disabled = true;
|
||
|
|
errorText.classList.add('hidden');
|
||
|
|
errorText.innerText = '';
|
||
|
|
|
||
|
|
try {
|
||
|
|
const formData = new FormData(form);
|
||
|
|
const response = await fetch(form.action, {
|
||
|
|
method: 'POST',
|
||
|
|
body: formData,
|
||
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
||
|
|
});
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
window.location.reload();
|
||
|
|
} else {
|
||
|
|
const data = await response.json();
|
||
|
|
errorText.innerText = data.message || 'Terjadi kesalahan sistem.';
|
||
|
|
errorText.classList.remove('hidden');
|
||
|
|
btn.disabled = false;
|
||
|
|
}
|
||
|
|
} catch (err) {
|
||
|
|
errorText.innerText = 'Koneksi terputus. Coba lagi.';
|
||
|
|
errorText.classList.remove('hidden');
|
||
|
|
btn.disabled = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
</script>
|
||
|
|
{% endblock %}
|
||
|
|
|
||
|
|
{% block page_title_guide %}Manajemen Data Karyawan{% endblock %}
|
||
|
|
|
||
|
|
{% block page_guide_content %}
|
||
|
|
<div class="space-y-4">
|
||
|
|
<p>Halaman <strong>Data Karyawan</strong> adalah daftar staf/karyawan yang terdaftar untuk dapat menerima atau memegang perangkat inventaris perusahaan. Di halaman ini Anda dapat:</p>
|
||
|
|
|
||
|
|
<div class="space-y-3">
|
||
|
|
<div class="flex items-start space-x-3 bg-gray-50 p-4 rounded-xl border border-gray-100">
|
||
|
|
<div class="mt-0.5 text-kerinci bg-kerinci-light rounded p-1 shrink-0">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
|
||
|
|
</div>
|
||
|
|
<div>
|
||
|
|
<h4 class="font-bold text-gray-900 mb-1">Menambah & Mengedit Karyawan</h4>
|
||
|
|
<p>Klik tombol <strong>"Tambah Karyawan"</strong> untuk mendaftarkan NIK dan nama baru. Anda juga bisa mengedit profil mereka dengan mengklik ikon pensil (warna kuning) di kolom aksi.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="flex items-start space-x-3 bg-gray-50 p-4 rounded-xl border border-gray-100">
|
||
|
|
<div class="mt-0.5 text-blue-500 bg-blue-50 rounded p-1 shrink-0">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path></svg>
|
||
|
|
</div>
|
||
|
|
<div>
|
||
|
|
<h4 class="font-bold text-gray-900 mb-1">Melihat Detail Pinjaman (Aset Ditahan)</h4>
|
||
|
|
<p>Kolom "Aset Yang Dipegang" menunjukkan jumlah unit yang sedang dipinjam karyawan. Klik tombol tersebut (atau klik nama karyawan) untuk masuk ke halaman detail dan melihat <strong>apa saja spesifik perangkat yang sedang mereka pegang</strong> saat ini.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<div class="flex items-start space-x-3 bg-gray-50 p-4 rounded-xl border border-gray-100">
|
||
|
|
<div class="mt-0.5 text-red-500 bg-red-50 rounded p-1 shrink-0">
|
||
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path></svg>
|
||
|
|
</div>
|
||
|
|
<div>
|
||
|
|
<h4 class="font-bold text-gray-900 mb-1">Aturan Hapus Data (Penting)</h4>
|
||
|
|
<p>Data karyawan <strong>tidak dapat dihapus</strong> (tombol hapus terkunci/abu-abu) apabila karyawan tersebut masih memegang atau meminjam aset. Pastikan semua barang sudah dikembalikan (Return) sebelum menghapus data karyawan dari sistem.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
{% endblock %}
|
||
|
|
|
||
|
|
<script>
|
||
|
|
document.addEventListener('click', function() {
|
||
|
|
var menu = document.getElementById('exportMenuEmployee');
|
||
|
|
if (menu) menu.style.display = 'none';
|
||
|
|
});
|
||
|
|
</script>
|