feat: implement consumable inventory module, network LAN access, and CI/CD enhancements

- Modul Consumable Item: model master, buku besar transaksi (stock ledger), purchase unit conversion, stock opname, dan transaction reversal
- Integrasi ke Employee Management, Asset Unit, dan tiket/work order
- Konfigurasi akses jaringan lokal (LAN) via 0.0.0.0:8000, ALLOWED_HOSTS, dan CSRF_TRUSTED_ORIGINS otomatis
- Script pembuka firewall Windows (buka_firewall_lan.bat) dan menu interaktif run.bat
- Skema migrasi 0019_consumableitem_consumabletransaction
- Seeder 11 item consumable riil (seed_consumables.py)
- Test suite komprehensif (41 automated tests, 100% lulus)
- Pipeline CI/CD GitHub Actions (.github/workflows/ci.yml)
This commit is contained in:
nuexn0x-9
2026-10-27 09:42:15 +07:00
commit f28983011c
110 changed files with 20296 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Halaman Tidak Ditemukan - IT All Role Kerinci Hydropower</title>
<link rel="stylesheet" href="{% static 'dist/style.css' %}?v=2.1">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
</style>
</head>
<body class="bg-gray-50 text-gray-800 font-sans antialiased h-screen flex flex-col justify-center items-center p-4">
<div class="text-center max-w-lg">
<!-- Icon / Illustration -->
<div class="mb-8 flex justify-center">
<div class="w-32 h-32 bg-kerinci-light rounded-full flex items-center justify-center relative">
<svg class="w-16 h-16 text-kerinci" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<!-- Floating elements -->
<div class="absolute -top-2 -right-2 w-8 h-8 bg-white rounded-full shadow-sm flex items-center justify-center animate-bounce" style="animation-delay: 0.1s;">
<span class="text-red-500 font-bold text-xs">4</span>
</div>
<div class="absolute top-10 -left-4 w-10 h-10 bg-white rounded-full shadow-sm flex items-center justify-center animate-bounce" style="animation-delay: 0.5s;">
<span class="text-amber-500 font-bold text-sm">0</span>
</div>
<div class="absolute bottom-2 -right-4 w-9 h-9 bg-white rounded-full shadow-sm flex items-center justify-center animate-bounce" style="animation-delay: 0.3s;">
<span class="text-kerinci font-bold text-sm">4</span>
</div>
</div>
</div>
<h1 class="text-4xl font-extrabold text-gray-900 mb-3">Waduh! Tersesat?</h1>
<p class="text-gray-500 mb-8 leading-relaxed">
Halaman atau rute yang Anda tuju sepertinya tidak ada di dalam sistem. <br class="hidden sm:block">
Mungkin halamannya sudah dihapus, atau Anda salah mengetik URL.
</p>
<a href="{% url 'dashboard' %}" class="inline-flex items-center justify-center px-6 py-3.5 bg-kerinci text-white font-bold rounded-xl text-sm shadow-sm shadow-kerinci/30 hover:bg-kerinci-dark hover:shadow-md transition-all space-x-2 group">
<svg class="w-4 h-4 transform group-hover:-translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
<span>Kembali ke Dashboard</span>
</a>
</div>
<!-- Footer Logo -->
<div class="absolute bottom-8 text-center w-full">
<img src="{% static 'img/main_logo.png' %}" alt="IT All Role" class="h-6 mx-auto opacity-50 grayscale">
</div>
</body>
</html>
+686
View File
@@ -0,0 +1,686 @@
{% extends 'base.html' %}
{% block page_title %}Daftar Aset
{% endblock %}
{% block content %}
<div class="mb-8 flex flex-col sm:flex-row sm:justify-between sm:items-center 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">Daftar Aset</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('exportMenuAsset'); 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 Aset</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="exportMenuAsset" 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 'asset_export_pdf' %}?tab={{ active_tab }}" 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 'asset_export_excel' %}?tab={{ active_tab }}" 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="openAddAssetModal()" class="bg-kerinci text-white border border-kerinci rounded-xl shadow-sm px-4 py-2 text-sm font-bold 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-4 h-4" 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 Aset</span>
</button>
{% endif %}
</div>
</div>
<!-- Category Tabs -->
<div class="flex space-x-2 mb-6 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
<a href="?tab=karyawan" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if active_tab == 'karyawan' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Aset Karyawan
<span class="ml-2 {% if active_tab == 'karyawan' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.karyawan|default:"0" }}</span>
</a>
<a href="?tab=network" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if active_tab == 'network' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Aset Network & Infrastruktur
<span class="ml-2 {% if active_tab == 'network' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.network|default:"0" }}</span>
</a>
</div>
<div class="mb-4">
<form id="searchForm" method="GET" class="relative w-full sm:w-96">
<input type="hidden" name="tab" value="{{ active_tab }}">
<input type="text" id="searchInput" name="q" value="{{ search_query }}" placeholder="Cari kode, nama aset, atau merek..." 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" 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 w-32">Kode Aset</th>
<th class="p-4 font-bold min-w-[250px]">Nama Aset</th>
<th class="p-4 font-bold">Merek</th>
<th class="p-4 font-bold text-center">Jumlah (Qty)</th>
{% if active_tab == 'karyawan' %}
<th class="p-4 font-bold text-center">Ketersediaan</th>
{% endif %}
<th class="p-4 font-bold text-center w-24">Aksi</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-200">
{% for asset in assets %}
<tr class="hover:bg-gray-50 transition-colors cursor-pointer group" onclick="openAssetModal(this)"
data-id="{{ asset.id }}"
data-code="{{ asset.asset_code }}"
data-name="{{ asset.name }}"
data-brand="{{ asset.brand|default:'' }}"
data-cat="{{ asset.category.name }}"
data-cat-id="{{ asset.category.id }}"
data-qty="{{ asset.qty }}"
data-uom="{{ asset.uom }}"
data-price="{{ asset.price }}"
data-total="{{ asset.total_price }}"
data-tersedia="{{ asset.unit_tersedia }}"
data-digunakan="{{ asset.unit_digunakan }}">
<td class="p-4 text-center text-gray-500">{{ forloop.counter }}</td>
<td class="p-4 font-bold text-gray-600">{{ asset.asset_code }}</td>
<td class="p-4">
<p class="font-bold text-gray-800">{{ asset.name }}</p>
</td>
<td class="p-4 text-gray-600 font-medium">{{ asset.brand|default:"-" }}</td>
<td class="p-4 text-center">
<a href="/aset/{{ asset.id }}/units/" onclick="event.stopPropagation();" class="inline-flex items-center justify-center space-x-1 px-4 py-1.5 bg-emerald-50 text-emerald-600 font-bold rounded-full text-sm border border-emerald-100 hover:bg-emerald-100 transition-colors">
<span>{{ asset.qty }} {{ asset.uom|default:"Unit" }}</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="M9 5l7 7-7 7"></path></svg>
</a>
</td>
{% if active_tab == 'karyawan' %}
<td class="p-4 text-center">
<span class="font-extrabold text-emerald-600">{{ asset.unit_tersedia }}</span>
<span class="text-gray-300 mx-1">/</span>
<span class="font-bold text-blue-600">{{ asset.unit_digunakan }}</span>
</td>
{% endif %}
<td class="p-4 text-center">
<button onclick="editAssetDirectly(event, this.closest('tr'))" class="p-2 bg-amber-50 text-amber-600 hover:bg-amber-100 rounded-lg transition-colors border border-amber-100" title="Edit Aset">
<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>
</td>
</tr>
{% empty %}
<tr>
<td colspan="8" class="p-8 text-center text-gray-400 text-sm">
Belum ada data aset untuk kategori ini.
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include 'components/pagination.html' %}
</div>
<!-- Modal Detail Aset -->
<div id="assetModal" 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="modalOverlay" onclick="closeModal()"></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="modalCard">
<!-- Header -->
<div class="flex justify-between items-start mb-5">
<div>
<p class="text-[10px] font-extrabold text-kerinci uppercase tracking-widest mb-1" id="m-cat"></p>
<h3 class="text-2xl font-extrabold text-gray-900 leading-tight" id="m-name"></h3>
<p class="text-sm font-medium text-gray-500 mt-1">Kode Induk: <span id="m-code" class="text-gray-900 font-bold"></span></p>
<p class="text-sm font-medium text-gray-500">Merek: <span id="m-brand" class="text-gray-900 font-bold"></span></p>
</div>
<button onclick="closeModal()" class="text-gray-400 hover:bg-gray-100 p-2 rounded-lg transition-colors">
<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>
<!-- Body -->
<div class="space-y-4">
<div class="grid grid-cols-2 gap-4 bg-gray-50 p-4 rounded-xl border border-gray-100">
{% if active_tab == 'karyawan' %}
<div class="col-span-2">
<p class="text-xs text-gray-500 uppercase tracking-wider font-bold mb-1">Ketersediaan Unit</p>
<div class="flex items-center space-x-1 mt-1 text-sm">
<span class="text-emerald-600 font-extrabold" id="m-tersedia"></span>
<span class="text-gray-400 text-xs mr-2">tersedia</span>
<span class="text-gray-300">|</span>
<span class="text-blue-600 font-extrabold ml-2" id="m-digunakan"></span>
<span class="text-gray-400 text-xs">digunakan</span>
</div>
</div>
{% endif %}
<div>
<p class="text-xs text-gray-500 uppercase tracking-wider font-bold mb-1">Total Kuantitas</p>
<p class="font-medium text-sm text-gray-900"><span id="m-qty"></span> <span id="m-uom"></span></p>
</div>
</div>
<a href="#" id="m-btn-units" class="w-full flex items-center justify-center space-x-2 bg-indigo-50 text-indigo-600 font-bold py-3 rounded-xl hover:bg-indigo-100 transition-colors">
<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 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
<span>Lihat Unit Aset</span>
</a>
</div>
<!-- Footer Actions -->
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button id="m-btn-edit" onclick="openEditModalFromCurrent()" class="px-5 py-2.5 bg-amber-50 text-amber-600 font-bold rounded-xl text-sm hover:bg-amber-100 transition-colors flex items-center space-x-2">
<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>
<span>Edit Data</span>
</button>
<button id="m-btn-delete" class="hidden px-5 py-2.5 bg-red-50 text-red-600 font-bold rounded-xl text-sm hover:bg-red-100 transition-colors flex items-center space-x-2">
<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 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>
<span>Hapus</span>
</button>
</div>
</div>
</div>
<!-- Modal Konfirmasi Hapus -->
<div id="deleteConfirmModal" 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="deleteOverlay" onclick="closeDeleteModal()"></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-8 transform transition-all scale-95 opacity-0 text-center" id="deleteCard">
<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">Hapus "<span id="d-code"></span>"?</h3>
<p class="text-gray-500 mb-8 max-w-md mx-auto">Apakah Anda yakin ingin menghapus aset <strong id="d-name"></strong> secara permanen? Aksi ini tidak dapat dibatalkan dan semua data historis terkait aset ini akan ikut terpengaruh.</p>
<form id="deleteForm" method="POST" class="flex justify-center space-x-4">
{% csrf_token %}
<button type="button" onclick="closeDeleteModal()" class="px-8 py-3.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50 transition-colors">Batal, Kembali</button>
<button type="submit" class="px-8 py-3.5 bg-red-500 text-white font-bold rounded-xl text-sm shadow-sm shadow-red-500/30 hover:bg-red-600 transition-colors">Ya, Hapus Permanen</button>
</form>
</div>
</div>
<script>
function editAssetDirectly(event, row) {
event.stopPropagation(); // Mencegah modal detail terbuka
window.currentAssetData = {
id: row.getAttribute('data-id'),
code: row.getAttribute('data-code'),
name: row.getAttribute('data-name'),
brand: row.getAttribute('data-brand'),
cat_id: row.getAttribute('data-cat-id'),
uom: row.getAttribute('data-uom')
};
openEditModalFromCurrent();
}
function openAssetModal(row) {
// Set Data
document.getElementById('m-cat').innerText = row.getAttribute('data-cat');
document.getElementById('m-name').innerText = row.getAttribute('data-name');
document.getElementById('m-code').innerText = row.getAttribute('data-code');
document.getElementById('m-brand').innerText = row.getAttribute('data-brand') || '-';
document.getElementById('m-qty').innerText = row.getAttribute('data-qty');
document.getElementById('m-uom').innerText = row.getAttribute('data-uom');
const elTersedia = document.getElementById('m-tersedia');
if (elTersedia) {
elTersedia.innerText = row.getAttribute('data-tersedia');
document.getElementById('m-digunakan').innerText = row.getAttribute('data-digunakan');
}
// Set Links
const id = row.getAttribute('data-id');
window.currentAssetData = {
id: id,
code: row.getAttribute('data-code'),
name: row.getAttribute('data-name'),
brand: row.getAttribute('data-brand'),
cat_id: row.getAttribute('data-cat-id'),
uom: row.getAttribute('data-uom')
};
// document.getElementById('m-btn-edit').href is no longer needed since it's a button calling openEditModalFromCurrent()
document.getElementById('m-btn-units').href = '/aset/' + id + '/units/';
// Hook up delete button to open second modal or block if has units
const btnDelete = document.getElementById('m-btn-delete');
const qty = parseInt(row.getAttribute('data-qty') || '0');
if (qty > 0) {
btnDelete.className = 'hidden px-5 py-2.5 bg-gray-100 text-gray-400 font-bold rounded-xl text-sm cursor-not-allowed flex items-center space-x-2';
btnDelete.title = 'Aset tidak dapat dihapus karena masih memiliki ' + qty + ' unit fisik terdaftar.';
btnDelete.onclick = function(e) {
e.preventDefault();
alert('Peringatan: Aset tidak dapat dihapus karena masih memiliki ' + qty + ' unit fisik di dalamnya.\n\nSilakan hapus semua unit fisik aset ini terlebih dahulu dari menu "Lihat Unit Aset".');
};
} else {
btnDelete.className = 'hidden px-5 py-2.5 bg-red-50 text-red-600 font-bold rounded-xl text-sm hover:bg-red-100 transition-colors flex items-center space-x-2';
btnDelete.title = '';
btnDelete.onclick = function(e) {
e.preventDefault();
openDeleteModal(id, row.getAttribute('data-code'), row.getAttribute('data-name'));
};
}
// Show Modal
const modal = document.getElementById('assetModal');
const overlay = document.getElementById('modalOverlay');
const card = document.getElementById('modalCard');
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 closeModal() {
const modal = document.getElementById('assetModal');
const overlay = document.getElementById('modalOverlay');
const card = document.getElementById('modalCard');
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 openDeleteModal(id, code, name) {
closeModal(); // Hide the first modal
document.getElementById('d-code').innerText = code;
document.getElementById('d-name').innerText = name;
document.getElementById('deleteForm').action = '/aset/' + id + '/delete/';
const modal = document.getElementById('deleteConfirmModal');
const overlay = document.getElementById('deleteOverlay');
const card = document.getElementById('deleteCard');
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); // Start animation slightly after rendering
}
function closeDeleteModal() {
const modal = document.getElementById('deleteConfirmModal');
const overlay = document.getElementById('deleteOverlay');
const card = document.getElementById('deleteCard');
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);
}
// Auto-search menggunakan AJAX agar halaman tidak ter-reload penuh
let searchTimeout = null;
const searchInput = document.getElementById('searchInput');
if (searchInput) {
// Memindahkan cursor ke akhir teks jika ada value awal
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);
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 newContainer = doc.getElementById('tableContainer');
if (newContainer) {
tableContainer.innerHTML = newContainer.innerHTML;
}
tableContainer.style.opacity = '1';
// Update URL tanpa reload
window.history.pushState({}, '', url);
})
.catch(error => {
console.error('Error during search fetch:', error);
tableContainer.style.opacity = '1';
});
}, 300); // 300ms delay lebih responsif untuk AJAX
});
}
</script>
<!-- Modal Tambah Aset -->
<div id="addAssetModal" class="fixed inset-0 z-[60] hidden flex items-center justify-center overflow-y-auto">
<div class="fixed inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeAddAssetModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-2xl relative mx-auto z-10 my-8">
<div class="p-6 border-b border-gray-100 flex justify-between items-center">
<h3 class="text-xl font-bold text-gray-900">Tambah Aset Baru</h3>
<button onclick="closeAddAssetModal()" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="w-6 h-6" 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="addAssetForm" action="{% url 'asset_add' %}" method="POST" class="p-6 space-y-6" onsubmit="submitAddAsset(event)">
{% csrf_token %}
<div id="addAssetError" class="hidden bg-red-50 border border-red-200 text-red-600 px-4 py-3 rounded-xl text-sm font-bold flex items-center space-x-2">
<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 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>
<span id="addAssetErrorText"></span>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Kategori Aset <span class="text-red-500">*</span></label>
<select name="category" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
<option value="">-- Pilih Kategori --</option>
{% for cat in categories %}
<option value="{{ cat.id }}">{{ cat.name }}</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Kode Aset <span class="text-red-500">*</span></label>
<input type="text" id="addAssetCode" name="asset_code" required placeholder="Misal: DLL, LNV" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm text-gray-900 focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-white uppercase">
<p class="text-xs text-gray-500 mt-1">* Kode aset tidak boleh sama dengan kode aset yang lain.</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Nama Aset <span class="text-red-500">*</span></label>
<input type="text" name="name" placeholder="Misal: Laptop Lenovo ThinkPad" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Merek (Brand) <span class="text-red-500">*</span></label>
<input type="text" name="brand" required placeholder="Misal: Lenovo, Dell" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Satuan (UoM) <span class="text-red-500">*</span></label>
<input type="text" name="uom" required placeholder="Unit, Pcs, Roll..." class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
</div>
<div class="pt-4 border-t border-gray-100 flex justify-end space-x-3">
<button type="button" onclick="closeAddAssetModal()" 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-kerinci text-white font-bold rounded-xl text-sm shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors flex items-center justify-center">
<span>Simpan Aset Baru</span>
</button>
</div>
</form>
</div>
</div>
<script>
function openAddAssetModal() {
document.getElementById('addAssetModal').classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeAddAssetModal() {
document.getElementById('addAssetModal').classList.add('hidden');
document.body.style.overflow = '';
document.getElementById('addAssetForm').reset();
document.getElementById('addAssetError').classList.add('hidden');
document.getElementById('addAssetCode').classList.remove('border-red-300', 'ring-1', 'ring-red-300');
}
async function submitAddAsset(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const submitBtn = form.querySelector('button[type="submit"]');
submitBtn.disabled = true;
const originalText = submitBtn.innerHTML;
submitBtn.innerHTML = '<svg class="animate-spin h-5 w-5 mr-3 text-white" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> Menyimpan...';
try {
const response = await fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
});
const data = await response.json();
if (data.success) {
window.location.reload();
} else {
const errorDiv = document.getElementById('addAssetError');
const errorText = document.getElementById('addAssetErrorText');
const inputField = document.getElementById('addAssetCode');
errorText.textContent = data.error;
errorDiv.classList.remove('hidden');
inputField.classList.add('border-red-300', 'ring-1', 'ring-red-300');
submitBtn.disabled = false;
submitBtn.innerHTML = originalText;
}
} catch (error) {
console.error('Error:', error);
submitBtn.disabled = false;
submitBtn.innerHTML = originalText;
}
}
</script>
<!-- Modal Edit Aset -->
<div id="editAssetModal" class="fixed inset-0 z-[60] hidden flex items-center justify-center overflow-y-auto">
<div class="fixed inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeEditAssetModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-2xl relative mx-auto z-10 my-8">
<div class="p-6 border-b border-gray-100 flex justify-between items-center">
<h3 class="text-xl font-bold text-gray-900">Edit Aset: <span id="editAssetTitle" class="text-kerinci"></span></h3>
<button onclick="closeEditAssetModal()" class="text-gray-400 hover:text-gray-600 transition-colors">
<svg class="w-6 h-6" 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="editAssetForm" method="POST" class="p-6 space-y-6" onsubmit="submitEditAsset(event)">
{% csrf_token %}
<div id="editAssetError" class="hidden bg-red-50 border border-red-200 text-red-600 px-4 py-3 rounded-xl text-sm font-bold flex items-center space-x-2">
<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 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>
<span id="editAssetErrorText"></span>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Kategori Aset <span class="text-red-500">*</span></label>
<select id="editAssetCat" name="category" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
<option value="">-- Pilih Kategori --</option>
{% for cat in categories %}
<option value="{{ cat.id }}">{{ cat.name }}</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Kode Aset <span class="text-red-500">*</span></label>
<input type="text" id="editAssetCode" name="asset_code" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm text-gray-900 focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-white uppercase">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Nama Aset <span class="text-red-500">*</span></label>
<input type="text" id="editAssetName" name="name" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Merek (Brand) <span class="text-red-500">*</span></label>
<input type="text" id="editAssetBrand" name="brand" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Satuan (UoM) <span class="text-red-500">*</span></label>
<input type="text" id="editAssetUom" name="uom" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50">
</div>
</div>
<div class="pt-4 border-t border-gray-100 flex justify-end space-x-3">
<button type="button" onclick="closeEditAssetModal()" 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-amber-500 text-white font-bold rounded-xl text-sm shadow-sm shadow-amber-500/30 hover:bg-amber-600 transition-colors flex items-center justify-center">
<span>Simpan Perubahan</span>
</button>
</div>
</form>
</div>
</div>
<script>
function openEditModalFromCurrent() {
closeModal(); // close the info modal first
if(!window.currentAssetData) return;
const data = window.currentAssetData;
document.getElementById('editAssetTitle').innerText = data.code;
document.getElementById('editAssetCat').value = data.cat_id;
document.getElementById('editAssetCode').value = data.code;
document.getElementById('editAssetName').value = data.name;
document.getElementById('editAssetBrand').value = data.brand;
document.getElementById('editAssetUom').value = data.uom;
document.getElementById('editAssetForm').action = '/aset/' + data.id + '/edit/';
document.getElementById('editAssetModal').classList.remove('hidden');
document.body.style.overflow = 'hidden';
}
function closeEditAssetModal() {
document.getElementById('editAssetModal').classList.add('hidden');
document.body.style.overflow = '';
document.getElementById('editAssetError').classList.add('hidden');
document.getElementById('editAssetCode').classList.remove('border-red-300', 'ring-1', 'ring-red-300');
}
async function submitEditAsset(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const submitBtn = form.querySelector('button[type="submit"]');
submitBtn.disabled = true;
const originalText = submitBtn.innerHTML;
submitBtn.innerHTML = '<svg class="animate-spin h-5 w-5 mr-3 text-white" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" fill="none"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg> Menyimpan...';
try {
const response = await fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
});
const data = await response.json();
if (data.success) {
window.location.reload();
} else {
const errorDiv = document.getElementById('editAssetError');
const errorText = document.getElementById('editAssetErrorText');
const inputField = document.getElementById('editAssetCode');
errorText.textContent = data.error;
errorDiv.classList.remove('hidden');
inputField.classList.add('border-red-300', 'ring-1', 'ring-red-300');
submitBtn.disabled = false;
submitBtn.innerHTML = originalText;
}
} catch (error) {
console.error('Error:', error);
submitBtn.disabled = false;
submitBtn.innerHTML = originalText;
}
}
</script>
{% endblock %}
{% block page_title_guide %}Manajemen Daftar Aset{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman <strong>Daftar Aset</strong> digunakan untuk mendata seluruh inventaris induk perangkat IT. 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 dan Mengedit Aset</h4>
<p>Gunakan tombol "Tambah Aset" untuk memasukkan tipe perangkat baru. Anda juga dapat mengedit informasi aset dengan mengklik tombol pensil (edit) di kolom Aksi pada masing-masing baris.</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="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Melihat Detail Unit (Jumlah)</h4>
<p>Klik tombol berwarna hijau berbentuk kapsul (contoh: "5 Unit >") pada kolom Jumlah untuk masuk ke halaman detail unit. Di sana Anda dapat mendaftarkan nomor seri, mencetak QR code, dan melihat status masing-masing fisik barang.</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-indigo-500 bg-indigo-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="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Kategori & Ekspor Data</h4>
<p>Terdapat tab untuk memfilter kategori (Aset Karyawan vs Network). Anda juga bisa langsung mengekspor daftar yang sedang tampil ke bentuk laporan PDF.</p>
</div>
</div>
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuAsset');
if (menu) menu.style.display = 'none';
});
</script>
+522
View File
@@ -0,0 +1,522 @@
{% extends 'base.html' %}
{% block page_title %}Unit Aset{% endblock %}
{% block content %}
<div class="mb-6 flex flex-col sm:flex-row sm:justify-between sm:items-center items-start space-y-4 sm:space-y-0">
<div>
<p class="text-xs font-bold text-kerinci uppercase tracking-widest mb-1">{{ asset.category.name }}</p>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-extrabold text-gray-900">{{ asset.name }}</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>
<p class="text-sm text-gray-500 mt-1">Kode: <strong>{{ asset.asset_code }}</strong> &middot; Total: <strong>{{ asset.qty }} {{ asset.uom }}</strong></p>
</div>
<div class="flex flex-wrap sm:flex-nowrap items-center gap-3 w-full sm:w-auto">
<a href="{% url 'asset_list' %}" class="order-1 sm:order-1 bg-white border border-gray-200 rounded-xl shadow-sm px-4 py-2.5 text-sm font-bold text-gray-700 hover:bg-gray-50 transition-colors flex-1 sm:flex-none text-center">
Kembali
</a>
<div class="relative inline-block w-full sm:w-auto flex-1 sm:flex-none">
<button onclick="var d = document.getElementById('exportMenuUnits'); 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 Data</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="exportMenuUnits" 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 'asset_units_export_pdf' asset.id %}" 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 'asset_units_export_excel' asset.id %}" 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>
<button onclick="openAddUnitModal()" class="order-2 sm:order-3 bg-kerinci text-white border border-kerinci rounded-xl shadow-sm px-4 py-2.5 text-sm font-bold hover:bg-kerinci/90 transition-colors flex items-center justify-center space-x-2 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 Unit</span>
</button>
</div>
</div>
<!-- Stats Row -->
<div class="grid grid-cols-3 gap-3 sm:gap-6 mb-6">
<div class="flex flex-col items-center">
<div class="bg-emerald-50 rounded-2xl w-full aspect-[4/3] sm:aspect-auto sm:h-24 flex items-center justify-center mb-3 shadow-sm border border-emerald-100">
<p class="text-3xl sm:text-4xl font-extrabold text-emerald-600">{{ tersedia }}</p>
</div>
<p class="text-[10px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center">Tersedia</p>
</div>
<div class="flex flex-col items-center">
<div class="bg-blue-50 rounded-2xl w-full aspect-[4/3] sm:aspect-auto sm:h-24 flex items-center justify-center mb-3 shadow-sm border border-blue-100">
<p class="text-3xl sm:text-4xl font-extrabold text-blue-600">{{ digunakan }}</p>
</div>
<p class="text-[10px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center">Digunakan</p>
</div>
<div class="flex flex-col items-center">
<div class="bg-gray-50 rounded-2xl w-full aspect-[4/3] sm:aspect-auto sm:h-24 flex items-center justify-center mb-3 shadow-sm border border-gray-200">
<p class="text-3xl sm:text-4xl font-extrabold text-gray-700">{{ units|length }}</p>
</div>
<p class="text-[10px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center">Total Unit</p>
</div>
</div>
<!-- Table -->
<div class="bg-white rounded-none sm:rounded-2xl shadow-sm border border-gray-100 overflow-hidden w-full">
<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-3 font-bold text-center w-16">No</th>
<th class="p-3 font-bold">Kode Unit</th>
<th class="p-3 font-bold text-center">Status</th>
<th class="p-3 font-bold">{% if "Network" in asset.category.name %}Lokasi{% else %}Dipegang Oleh{% endif %}</th>
<th class="p-3 font-bold text-center w-24">QR Code</th>
<th class="p-3 font-bold text-center w-32">Riwayat Unit</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-200">
{% for unit in units %}
<tr class="hover:bg-gray-50 transition-colors">
<td class="p-3 text-center text-gray-500">{{ forloop.counter }}</td>
<td class="p-3">
<a href="{% url 'unit_history' unit.id %}" class="font-bold text-gray-900 hover:text-kerinci transition-colors inline-block w-max">{{ unit.unit_code }}</a>
</td>
<td class="p-3 text-center">
{% if unit.status == 'tersedia' %}
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" title="Klik untuk ubah status" style="display:inline-flex;align-items:center;gap:4px;" class="bg-emerald-50 border border-emerald-200 text-emerald-700 hover:bg-emerald-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider focus:outline-none focus:ring-2 focus:ring-emerald-400 focus:ring-offset-1 cursor-pointer">
Tersedia
<svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</button>
{% elif unit.status == 'digunakan' %}
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" title="Klik untuk ubah status" style="display:inline-flex;align-items:center;gap:4px;" class="bg-blue-50 border border-blue-200 text-blue-700 hover:bg-blue-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider focus:outline-none focus:ring-2 focus:ring-blue-400 focus:ring-offset-1 cursor-pointer">
Digunakan
<svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</button>
{% elif unit.status == 'rusak' %}
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" title="Klik untuk ubah status" style="display:inline-flex;align-items:center;gap:4px;" class="bg-red-50 border border-red-200 text-red-700 hover:bg-red-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider focus:outline-none focus:ring-2 focus:ring-red-400 focus:ring-offset-1 cursor-pointer">
Maintenance
<svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</button>
{% else %}
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" title="Klik untuk ubah status" style="display:inline-flex;align-items:center;gap:4px;" class="bg-gray-50 border border-gray-200 text-gray-600 hover:bg-gray-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider focus:outline-none focus:ring-2 focus:ring-gray-400 focus:ring-offset-1 cursor-pointer">
{{ unit.get_status_display }}
<svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</button>
{% endif %}
</td>
<td class="p-3">
{% if unit.assigned_to %}
<a href="{% url 'employee_detail' unit.assigned_to.id %}" class="flex flex-col group w-max">
<p class="font-bold text-gray-800 text-xs transition-colors group-hover:text-kerinci">{{ unit.assigned_to.name }}</p>
<p class="text-[10px] text-gray-400 transition-colors group-hover:text-kerinci/70">NIK: {{ unit.assigned_to.nik }}</p>
</a>
{% elif unit.area %}
<div class="flex flex-col">
<p class="font-bold text-kerinci text-xs">{{ unit.area }}</p>
<p class="text-[10px] text-gray-500 max-w-[150px] truncate" title="{{ unit.location }}">{{ unit.location }}</p>
</div>
{% else %}
<span class="text-gray-300 text-xs italic">-</span>
{% endif %}
</td>
<td class="p-3 text-center">
<button type="button" onclick="openQrModal('{% url 'unit_qr_code' unit.id_uuid %}', '{{ unit.unit_code }}')" class="inline-flex items-center justify-center p-2 text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded-xl transition-colors focus:outline-none focus:ring-2 focus:ring-kerinci focus:ring-offset-1" title="Lihat/Download QR">
<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 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm14 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"></path></svg>
</button>
</td>
<td class="p-3 text-center">
<div class="flex justify-center items-center space-x-1">
<a href="{% url 'unit_history' unit.id %}" class="inline-flex items-center justify-center p-1.5 text-blue-500 hover:bg-blue-50 rounded-lg transition-colors" title="Riwayat Unit">
<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 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</a>
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="p-8 text-center text-gray-400 text-sm">
Belum ada unit untuk jenis aset ini.
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- Modal Tambah Unit -->
<div id="addUnitModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeAddUnitModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-md relative mx-auto z-10 p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Tambah Unit Baru</h3>
<form id="addUnitForm" action="{% url 'unit_add' asset.id %}" method="POST" class="space-y-4" onsubmit="submitAddUnit(event)">
{% csrf_token %}
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Aset Induk</label>
<input type="text" value="{{ asset.asset_code }} - {{ asset.name }}" disabled class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm bg-gray-100 text-gray-500 cursor-not-allowed">
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Kode Unit <span class="text-red-500">*</label>
<div class="flex">
<span class="inline-flex items-center px-3 rounded-l-lg border border-r-0 border-gray-200 bg-gray-100 text-gray-500 text-sm font-bold">
{{ asset.asset_code }}-
</span>
<input type="text" id="add_unit_code_suffix" name="unit_code_suffix" required pattern="\d+" oninput="this.value = this.value.replace(/[^0-9]/g, '')" class="flex-1 min-w-0 block w-full px-4 py-2 rounded-none rounded-r-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white" placeholder="Contoh: 001">
</div>
<p id="add_error" class="text-red-500 text-xs mt-1 hidden font-bold"></p>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeAddUnitModal()" class="px-4 py-2 border border-gray-300 text-gray-700 font-bold rounded-lg text-sm hover:bg-gray-50 transition-colors">Batal</button>
<button type="submit" class="px-4 py-2 bg-kerinci text-white font-bold rounded-lg text-sm shadow-sm hover:bg-kerinci/90 transition-colors flex items-center justify-center">
<span id="add_spinner" class="hidden mr-2">...</span>
Simpan Unit
</button>
</div>
</form>
</div>
</div>
<!-- Modal Update Status Unit -->
<div id="statusUnitModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeStatusUnitModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-md relative mx-auto z-10 p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Update Status Unit</h3>
<p class="text-sm text-gray-500 mb-1">Kode Unit: <strong id="su_code" class="text-gray-900"></strong></p>
<p id="su_assigned_info" class="text-sm text-gray-500 mb-4 hidden">Dipegang Oleh: <strong id="su_assigned_name" class="text-gray-900"></strong></p>
<form id="statusUnitForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Status Baru</label>
<select id="su_status" name="status" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="tersedia" id="opt_su_tersedia">Tersedia</option>
<option value="digunakan" id="opt_su_digunakan" class="hidden" disabled>Digunakan</option>
<option value="rusak">Diperbaiki (Rusak / Maintenance)</option>
</select>
<p id="su_bast_warning" class="text-xs text-amber-600 mt-1 hidden font-bold">* Aset sedang digunakan. Pengembalian atau Mutasi harus melalui menu Distribusi Aset.</p>
</div>
<div id="su_notes_container" class="hidden">
<label class="block text-sm font-bold text-gray-700 mb-1">Catatan Kejadian <span class="text-red-500">*</span></label>
<textarea id="su_notes" name="notes" rows="2" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Jelaskan alasan perbaikan / keluhan kerusakan..."></textarea>
</div>
<div id="su_network_fields" class="hidden space-y-4 pt-4 border-t border-gray-100 mt-4">
<p class="text-xs font-bold text-gray-500 uppercase">Detail Lokasi Pemasangan</p>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Area <span class="text-red-500">*</span></label>
<select id="su_area" name="area" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="">-- Pilih Area --</option>
<option value="Regulating Weir (RW)">Regulating Weir (RW)</option>
<option value="Jakon">Jakon</option>
<option value="Beringin Tunggal (BT)">Beringin Tunggal (BT)</option>
<option value="DAM">DAM</option>
<option value="Adit 1">Adit 1</option>
<option value="Adit 2">Adit 2</option>
<option value="Adit 3">Adit 3</option>
<option value="Gudang Induk (GI)">Gudang Induk (GI)</option>
<option value="Vertical Shaft (VS)">Vertical Shaft (VS)</option>
<option value="Power House (PH)">Power House (PH)</option>
<option value="Lain-lainnya">Lain-lainnya</option>
</select>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Lokasi Spesifik <span class="text-red-500">*</span></label>
<input type="text" id="su_location" name="location" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Misal: Dinding server room barat...">
</div>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeStatusUnitModal()" class="px-4 py-2 border border-gray-300 text-gray-700 font-bold rounded-lg text-sm hover:bg-gray-50 transition-colors">Batal</button>
<button type="submit" class="px-4 py-2 bg-kerinci text-white font-bold rounded-lg text-sm shadow-sm hover:bg-kerinci/90 transition-colors">
Simpan Status
</button>
</div>
</form>
</div>
</div>
<!-- QR Code Modal -->
<div id="qrModal" class="fixed inset-0 z-50 hidden" aria-labelledby="modal-title" role="dialog" aria-modal="true">
<div class="fixed inset-0 bg-gray-900/50 backdrop-blur-sm transition-opacity opacity-0" id="qrModalBackdrop" onclick="closeQrModal()"></div>
<div class="fixed inset-0 z-10 overflow-y-auto">
<div class="flex min-h-full items-center justify-center p-4 text-center sm:p-0">
<div class="relative transform overflow-hidden rounded-2xl bg-white text-left shadow-2xl transition-all sm:my-8 sm:w-full sm:max-w-sm opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" id="qrModalPanel">
<div class="bg-white px-4 pb-4 pt-5 sm:p-6 sm:pb-4 text-center">
<div class="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-kerinci/10 mb-4">
<svg class="h-6 w-6 text-kerinci" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 013.75 9.375v-4.5zM3.75 14.625c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5a1.125 1.125 0 01-1.125-1.125v-4.5zM13.5 4.875c0-.621.504-1.125 1.125-1.125h4.5c.621 0 1.125.504 1.125 1.125v4.5c0 .621-.504 1.125-1.125 1.125h-4.5A1.125 1.125 0 0113.5 9.375v-4.5z" />
<path stroke-linecap="round" stroke-linejoin="round" d="M6.75 6.75h.75v.75h-.75v-.75zM6.75 16.5h.75v.75h-.75v-.75zM16.5 6.75h.75v.75h-.75v-.75zM13.5 13.5h.75v.75h-.75v-.75zM13.5 19.5h.75v.75h-.75v-.75zM19.5 13.5h.75v.75h-.75v-.75zM19.5 19.5h.75v.75h-.75v-.75zM16.5 16.5h.75v.75h-.75v-.75z" />
</svg>
</div>
<p class="text-sm text-gray-500 mb-6">Scan QR ini untuk melihat detail lengkap dan riwayat unit.</p>
<!-- QR Image Container -->
<div class="bg-gray-50 rounded-xl p-4 flex justify-center items-center border border-gray-100 mb-6 min-h-[200px]">
<img id="qrModalImage" src="" alt="QR Code" class="w-full h-auto max-w-[280px] object-contain mx-auto">
</div>
</div>
<div class="bg-gray-50 px-4 py-4 sm:flex sm:flex-row-reverse sm:px-6">
<a id="qrDownloadBtn" href="" download="QRCode.png" class="inline-flex w-full justify-center rounded-xl bg-kerinci px-4 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-kerinci-dark sm:ml-3 sm:w-auto 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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
Download QR
</a>
<button type="button" onclick="closeQrModal()" class="mt-3 inline-flex w-full justify-center rounded-xl bg-white px-4 py-2.5 text-sm font-bold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto transition-colors">
Tutup
</button>
</div>
</div>
</div>
</div>
</div>
<script>
async function submitAddUnit(e) {
e.preventDefault();
const form = e.target;
const btn = form.querySelector('button[type="submit"]');
const spinner = document.getElementById('add_spinner');
const errorText = document.getElementById('add_error');
spinner.classList.remove('hidden');
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');
spinner.classList.add('hidden');
btn.disabled = false;
}
} catch (err) {
errorText.innerText = 'Koneksi terputus. Coba lagi.';
errorText.classList.remove('hidden');
spinner.classList.add('hidden');
btn.disabled = false;
}
}
function openAddUnitModal() {
document.getElementById('add_error').classList.add('hidden');
document.getElementById('addUnitModal').classList.remove('hidden');
setTimeout(() => {
document.getElementById('add_unit_code_suffix').focus();
}, 50);
}
function closeAddUnitModal() {
document.getElementById('addUnitModal').classList.add('hidden');
}
function openStatusModal(id, fullCode, status, assignedTo, categoryName, area, location) {
document.getElementById('statusUnitForm').action = '/unit/' + id + '/status/';
document.getElementById('su_code').innerText = fullCode;
const assignedInfo = document.getElementById('su_assigned_info');
const assignedName = document.getElementById('su_assigned_name');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '' && assignedTo !== 'true') {
assignedName.innerText = assignedTo;
assignedInfo.classList.remove('hidden');
} else {
assignedInfo.classList.add('hidden');
}
const statSelect = document.getElementById('su_status');
const optTersedia = document.getElementById('opt_su_tersedia');
const optDigunakan = document.getElementById('opt_su_digunakan');
const warnText = document.getElementById('su_bast_warning');
const netFields = document.getElementById('su_network_fields');
const areaInput = document.getElementById('su_area');
const locInput = document.getElementById('su_location');
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
areaInput.value = area && area !== 'None' ? area : '';
locInput.value = location && location !== 'None' ? location : '';
const isNetwork = categoryName && categoryName.includes('Network');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '') {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = true;
optTersedia.classList.add('hidden');
warnText.classList.remove('hidden');
let empName = assignedTo === 'true' ? 'karyawan' : assignedTo;
warnText.innerHTML = '* Aset sedang digunakan oleh <strong class="font-extrabold underline">' + empName + '</strong>. Pengembalian harus melalui menu Distribusi Aset.';
} else if (isNetwork) {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
} else {
optDigunakan.disabled = true;
optDigunakan.classList.add('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
}
statSelect.value = status;
statSelect.onchange = function() {
const notesContainer = document.getElementById('su_notes_container');
const notesInput = document.getElementById('su_notes');
if (this.value === 'rusak') {
notesContainer.classList.remove('hidden');
notesInput.required = true;
} else {
notesContainer.classList.add('hidden');
notesInput.required = false;
}
if ((this.value === 'digunakan' || this.value === 'rusak') && isNetwork) {
netFields.classList.remove('hidden');
areaInput.required = true;
locInput.required = true;
} else {
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
}
};
statSelect.onchange();
document.getElementById('statusUnitModal').classList.remove('hidden');
}
function closeStatusUnitModal() {
document.getElementById('statusUnitModal').classList.add('hidden');
}
function openQrModal(qrUrl, unitCode) {
const modal = document.getElementById('qrModal');
const backdrop = document.getElementById('qrModalBackdrop');
const panel = document.getElementById('qrModalPanel');
document.getElementById('qrModalImage').src = qrUrl;
const downloadBtn = document.getElementById('qrDownloadBtn');
downloadBtn.href = qrUrl;
downloadBtn.download = 'QR_' + unitCode + '.png';
modal.classList.remove('hidden');
// Trigger reflow
void modal.offsetWidth;
backdrop.classList.remove('opacity-0');
backdrop.classList.add('opacity-100');
panel.classList.remove('opacity-0', 'translate-y-4', 'sm:translate-y-0', 'sm:scale-95');
panel.classList.add('opacity-100', 'translate-y-0', 'sm:scale-100');
}
function closeQrModal() {
const modal = document.getElementById('qrModal');
const backdrop = document.getElementById('qrModalBackdrop');
const panel = document.getElementById('qrModalPanel');
backdrop.classList.remove('opacity-100');
backdrop.classList.add('opacity-0');
panel.classList.remove('opacity-100', 'translate-y-0', 'sm:scale-100');
panel.classList.add('opacity-0', 'translate-y-4', 'sm:translate-y-0', 'sm:scale-95');
setTimeout(() => {
modal.classList.add('hidden');
document.getElementById('qrModalImage').src = ''; // Clear image
}, 300);
}
</script>
{% endblock %}
{% block page_title_guide %}Manajemen Detail Unit{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman <strong>Unit Aset</strong> menjabarkan fisik peranti/barang (kuantitas aktual) dari satu jenis inventaris (misal: Laptop Lenovo). 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">Mendaftarkan Unit Baru (S/N)</h4>
<p>Klik tombol <strong>"Tambah Unit"</strong> untuk mendaftarkan barang baru yang masuk (misal ada pembelian laptop baru dari tipe ini). Anda wajib memasukkan <strong>Nomor Seri (S/N)</strong> yang ada pada fisik barang.</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="M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm14 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Cetak & Unduh Label QR Code</h4>
<p>Setiap unit secara otomatis digenerasikan <strong>QR Code unik</strong>. Klik ikon kotak di kolom QR Code untuk melihat/mengunduh gambarnya. Stiker QR ini nantinya bisa ditempelkan di fisik barang untuk keperluan *scanning*.</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="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Ubah Status Kondisi Cepat</h4>
<p>Layaknya pada halaman Status Aset, Anda bisa langsung mengklik label/badge status (cth: "Tersedia" hijau) di tabel ini untuk melaporkan jika unit tersebut masuk fase <em>Maintenance</em> (rusak) tanpa perlu berpindah menu.</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-indigo-500 bg-indigo-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="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Riwayat Spesifik Barang</h4>
<p>Klik ikon jam di kolom paling kanan untuk menelusuri ke mana saja spesifik unit ini pernah dipinjamkan dari sejak awal ia diregistrasi.</p>
</div>
</div>
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuUnits');
if (menu) menu.style.display = 'none';
});
</script>
+57
View File
@@ -0,0 +1,57 @@
{% extends 'base.html' %}
{% block page_title %}Backup Data{% endblock %}
{% block content %}
<div class="mb-8">
<h2 class="text-3xl font-extrabold text-gray-900 mb-2">Backup Database</h2>
<p class="text-sm text-gray-500">Cadangkan seluruh data sistem untuk mencegah kehilangan data jika terjadi masalah pada server.</p>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-8">
<div class="mb-6">
<h3 class="text-xl font-bold text-gray-900">Ekspor Data Sistem</h3>
<p class="text-sm text-gray-500">Mencakup aset, riwayat, dan karyawan.</p>
</div>
<p class="text-gray-600 text-sm mb-8 leading-relaxed">
Sistem akan menyusun seluruh struktur dan data yang Anda miliki saat ini menjadi sebuah file `.json`. File ini sangat penting dan bisa digunakan untuk memulihkan (restore) server kapan pun diperlukan.
</p>
<form method="POST">
{% csrf_token %}
<div class="mb-6">
<label for="format" class="block text-sm font-semibold text-gray-700 mb-2">Format File Backup</label>
<select name="format" id="format" class="w-full rounded-xl border-gray-200 shadow-sm focus:border-kerinci focus:ring focus:ring-kerinci focus:ring-opacity-50 text-sm py-2.5 px-3">
<option value="json">Format JSON (Standar Django - loaddata)</option>
<option value="sql">Format SQL (Database MySQL Mentah)</option>
</select>
<p class="text-xs text-gray-500 mt-2">*Pilih SQL jika Anda ingin melakukan import langsung via phpMyAdmin/MySQL.</p>
</div>
<button type="submit" class="w-full bg-kerinci hover:bg-kerinci-dark text-white font-bold py-3.5 px-6 rounded-xl transition-colors shadow-sm shadow-kerinci/30 flex items-center justify-center space-x-2 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-kerinci">
<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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
<span>Unduh File Backup</span>
</button>
</form>
</div>
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-8">
<h3 class="text-lg font-bold text-gray-900 mb-4">Informasi Penting</h3>
<ul class="space-y-4">
<li class="flex items-start">
<svg class="w-5 h-5 text-kerinci mt-0.5 mr-3 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<p class="text-sm text-gray-600">Simpan file backup ini di tempat yang sangat aman (seperti Google Drive atau Flashdisk eksternal) dan hindari membagikannya ke pihak luar.</p>
</li>
<li class="flex items-start">
<svg class="w-5 h-5 text-kerinci mt-0.5 mr-3 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<p class="text-sm text-gray-600">Lakukan backup secara rutin (minimal seminggu sekali) terutama jika Anda sering menambahkan unit atau karyawan baru ke dalam sistem.</p>
</li>
<li class="flex items-start">
<svg class="w-5 h-5 text-kerinci mt-0.5 mr-3 flex-shrink-0" 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>
<p class="text-sm text-gray-600">Untuk melakukan <em>restore</em>, berikan file ini kepada Teknisi IT yang memelihara sistem untuk dimuat ulang menggunakan perintah <code>loaddata</code>.</p>
</li>
</ul>
</div>
</div>
{% endblock %}
+344
View File
@@ -0,0 +1,344 @@
{% load static %}
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manajemen Aset IT - Kerinci Hydropower</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static 'dist/style.css' %}?v=2.1">
<style>
body { background-color: #F8F9FA; }
/* Hide scrollbar for Chrome, Safari and Opera */
.scrollbar-hide::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.scrollbar-hide {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
[x-cloak] { display: none !important; }
</style>
</head>
<body class="bg-[#F8F9FA] font-sans antialiased text-gray-900 h-screen flex overflow-hidden">
<!-- Mobile Sidebar Backdrop -->
<div id="sidebarBackdrop" onclick="toggleSidebar()" class="fixed inset-0 bg-gray-900/50 z-40 hidden lg:hidden backdrop-blur-sm transition-opacity opacity-0"></div>
<!-- Sidebar -->
<aside id="sidebar" class="w-64 bg-white border-r border-gray-200 h-full flex flex-col fixed lg:static z-50 transform -translate-x-full lg:translate-x-0 transition-transform duration-300">
<div class="h-20 ml-6 flex items-center justify-start border-b border-gray-200">
<!-- Logo -->
<img src="{% static 'img/main_logo.png' %}?v=6" alt="IT All Role Kerinci Hydropower" class="h-9 w-auto object-contain">
</div>
<nav class="flex-1 p-4 space-y-2 overflow-y-auto">
<a href="{% url 'dashboard' %}" class="flex items-center space-x-3 px-4 py-3 rounded-xl transition-colors {% if request.path == '/' %}bg-kerinci text-white shadow-sm shadow-kerinci/30{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm10 0a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zm10 0a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"></path></svg>
<span class="font-semibold text-sm">Dashboard</span>
</a>
<p class="text-xs font-bold text-gray-400 mt-6 mb-2 px-4">MANAJEMEN ASET</p>
<a href="{% url 'asset_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/aset/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="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>
<span class="font-semibold text-sm">Daftar Aset</span>
</a>
<a href="{% url 'distribusi_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/distribusi/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"></path></svg>
<span class="font-semibold text-sm">Distribusi Aset</span>
</a>
<a href="{% url 'status_aset_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/status-aset/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<span class="font-semibold text-sm">Status Aset</span>
</a>
<a href="{% url 'ci_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/ci/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"></path></svg>
<span class="font-semibold text-sm">Configuration Item</span>
</a>
<a href="{% url 'consumable_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/consumable/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
<span class="font-semibold text-sm">Consumable Item</span>
</a>
<a href="{% url 'employee_list' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/karyawan/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path></svg>
<span class="font-semibold text-sm">Data Karyawan</span>
</a>
<p class="px-4 text-xs font-bold text-gray-400 uppercase tracking-widest mb-2 mt-10">Pengaturan</p>
{% if is_admin %}
<a href="{% url 'backup_database' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/backup/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"></path></svg>
<span class="font-semibold text-sm">Backup Data</span>
</a>
{% endif %}
<a href="{% url 'profile' %}" class="flex items-center space-x-3 px-4 py-2.5 rounded-lg transition-colors {% if '/profil/' in request.path %}bg-kerinci-light text-kerinci font-semibold{% else %}text-gray-500 hover:text-kerinci hover:bg-kerinci-light{% endif %}">
<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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
<span class="font-semibold text-sm">Profil Saya</span>
</a>
</nav>
<div class="p-4 border-t border-gray-100">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-2">
<div class="w-8 h-8 bg-kerinci text-white rounded-full flex items-center justify-center font-bold text-xs">A</div>
<div>
<p class="text-xs font-bold text-gray-800 truncate">{% if request.user.is_authenticated %}{{ request.user.get_full_name|default:request.user.username }}{% else %}Administrator{% endif %}</p>
</div>
</div>
<form action="{% url 'logout' %}" method="POST" class="inline">
{% csrf_token %}
<button type="submit" class="text-gray-400 hover:text-red-500 transition-colors" title="Keluar">
<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="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"></path></svg>
</button>
</form>
</div>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 flex flex-col h-full relative min-w-0">
<!-- Topbar -->
<header class="h-16 bg-white border-b border-gray-200 flex items-center px-4 lg:px-8 justify-between z-10">
<div class="flex items-center space-x-3 w-full sm:w-auto">
<button onclick="toggleSidebar()" class="lg:hidden p-1.5 rounded-lg text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-kerinci transition-colors">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg>
</button>
<div class="flex items-center">
<h2 class="font-bold text-gray-800 text-lg truncate max-w-[150px] sm:max-w-none">{% block page_title %}Dashboard{% endblock %}</h2>
</div>
</div>
<div class="flex items-center space-x-4">
<div class="relative" id="profileDropdownContainer">
<button type="button" onclick="toggleProfileDropdown()" class="flex items-center space-x-3 text-left focus:outline-none p-1.5 rounded-xl hover:bg-gray-50 transition-colors">
<div class="w-10 h-10 bg-kerinci text-white rounded-full flex items-center justify-center font-bold shadow-sm shadow-kerinci/30 shrink-0">
{% if request.user.is_authenticated %}{{ request.user.first_name|default:request.user.username|first|upper }}{% else %}A{% endif %}
</div>
<div class="hidden sm:block">
<p class="text-sm font-bold text-gray-800">{% if request.user.is_authenticated %}{{ request.user.get_full_name|default:request.user.username }}{% else %}Pengguna{% endif %}</p>
<p class="text-[10px] text-gray-500 uppercase tracking-wider font-bold">
{% if is_admin %}Administrator{% elif is_operator %}Teknisi IT{% elif is_read_only %}Auditor / Viewer{% else %}{{ user_role|title }}{% endif %}
</p>
</div>
<svg class="w-4 h-4 text-gray-400 hidden sm:block" 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>
<!-- Dropdown Menu -->
<div id="profileDropdown" class="hidden absolute right-0 mt-2 w-48 bg-white rounded-2xl shadow-[0_8px_30px_rgb(0,0,0,0.12)] border border-gray-100 py-2 z-50 transform opacity-0 scale-95 transition-all origin-top-right">
<a href="{% url 'profile' %}" class="flex items-center space-x-3 px-4 py-2.5 text-sm font-bold text-gray-700 hover:bg-gray-50 hover:text-kerinci transition-colors">
<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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
<span>Profil Saya</span>
</a>
<div class="h-px bg-gray-100 my-1"></div>
<form action="{% url 'logout' %}" method="POST" class="w-full">
{% csrf_token %}
<button type="submit" class="flex items-center space-x-3 px-4 py-2.5 text-sm font-bold text-red-600 hover:bg-red-50 transition-colors w-full text-left">
<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="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"></path></svg>
<span>Keluar Sistem</span>
</button>
</form>
</div>
</div>
</div>
</header>
<!-- Scrollable Content Area -->
<div class="flex-1 overflow-y-auto" id="main-content">
<div class="p-4 md:p-8 max-w-[1400px] mx-auto w-full min-w-0">
{% block content %}{% endblock %}
</div>
</div>
</main>
<!-- Global Toasts -->
{% if messages %}
<div id="toast-container" class="fixed bottom-5 right-5 z-50 flex flex-col gap-3">
{% for message in messages %}
<div class="toast-item relative overflow-hidden bg-white border border-gray-100 shadow-[0_8px_30px_rgb(0,0,0,0.12)] rounded-xl p-4 flex items-start gap-3 w-[350px] transform translate-y-10 opacity-0 transition-all duration-300">
<!-- Icon -->
<div class="flex-shrink-0 mt-0.5">
{% if message.tags == 'success' %}
<svg class="w-5 h-5 text-emerald-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% elif message.tags == 'error' %}
<svg class="w-5 h-5 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% else %}
<svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% endif %}
</div>
<!-- Message -->
<div class="flex-1">
<p class="text-sm font-bold text-gray-900">{{ message }}</p>
</div>
<!-- Close Btn -->
<button onclick="this.closest('.toast-item').remove()" class="text-gray-400 hover:text-gray-600 transition-colors focus:outline-none">
<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="M6 18L18 6M6 6l12 12"></path></svg>
</button>
<!-- Progress bar -->
<div class="absolute bottom-0 right-0 h-1 bg-emerald-500 toast-progress" style="width: 100%;"></div>
</div>
{% endfor %}
</div>
<style>
@keyframes toastProgress {
from { width: 100%; }
to { width: 0%; }
}
.toast-progress {
animation: toastProgress 4s linear forwards;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const toasts = document.querySelectorAll('.toast-item');
toasts.forEach((toast, index) => {
setTimeout(() => {
toast.classList.remove('translate-y-10', 'opacity-0');
toast.classList.add('translate-y-0', 'opacity-100');
}, index * 150);
const svg = toast.querySelector('svg');
const progress = toast.querySelector('.toast-progress');
if (svg.classList.contains('text-red-500')) {
progress.classList.remove('bg-emerald-500');
progress.classList.add('bg-red-500');
} else if (svg.classList.contains('text-blue-500')) {
progress.classList.remove('bg-emerald-500');
progress.classList.add('bg-blue-500');
}
setTimeout(() => {
toast.classList.remove('translate-y-0', 'opacity-100');
toast.classList.add('translate-y-5', 'opacity-0');
setTimeout(() => toast.remove(), 300);
}, 4000);
});
});
</script>
{% endif %}
<script>
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
const backdrop = document.getElementById('sidebarBackdrop');
if (sidebar.classList.contains('-translate-x-full')) {
sidebar.classList.remove('-translate-x-full');
backdrop.classList.remove('hidden');
setTimeout(() => backdrop.classList.remove('opacity-0'), 10);
} else {
sidebar.classList.add('-translate-x-full');
backdrop.classList.add('opacity-0');
setTimeout(() => backdrop.classList.add('hidden'), 300);
}
}
</script>
<script>
function toggleProfileDropdown() {
const dropdown = document.getElementById('profileDropdown');
if (dropdown.classList.contains('hidden')) {
dropdown.classList.remove('hidden');
setTimeout(() => {
dropdown.classList.remove('opacity-0', 'scale-95');
dropdown.classList.add('opacity-100', 'scale-100');
}, 10);
} else {
dropdown.classList.remove('opacity-100', 'scale-100');
dropdown.classList.add('opacity-0', 'scale-95');
setTimeout(() => {
dropdown.classList.add('hidden');
}, 150);
}
}
document.addEventListener('click', function(event) {
const container = document.getElementById('profileDropdownContainer');
const dropdown = document.getElementById('profileDropdown');
if (container && !container.contains(event.target)) {
if (!dropdown.classList.contains('hidden')) {
dropdown.classList.remove('opacity-100', 'scale-100');
dropdown.classList.add('opacity-0', 'scale-95');
setTimeout(() => {
dropdown.classList.add('hidden');
}, 150);
}
}
});
function openGuideModal() {
const modal = document.getElementById('guideModal');
const overlay = document.getElementById('guideOverlay');
const card = document.getElementById('guideCard');
modal.classList.remove('hidden');
setTimeout(() => {
overlay.classList.remove('opacity-0');
overlay.classList.add('opacity-100');
card.classList.remove('scale-95', 'opacity-0', 'translate-y-4');
card.classList.add('scale-100', 'opacity-100', 'translate-y-0');
}, 10);
}
function closeGuideModal() {
const modal = document.getElementById('guideModal');
const overlay = document.getElementById('guideOverlay');
const card = document.getElementById('guideCard');
overlay.classList.remove('opacity-100');
overlay.classList.add('opacity-0');
card.classList.remove('scale-100', 'opacity-100', 'translate-y-0');
card.classList.add('scale-95', 'opacity-0', 'translate-y-4');
setTimeout(() => {
modal.classList.add('hidden');
}, 300);
}
</script>
<!-- Modal Panduan (Global) -->
<div id="guideModal" class="fixed inset-0 hidden flex items-center justify-center p-4 sm:p-0" style="z-index: 9999;">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm transition-opacity opacity-0" id="guideOverlay" onclick="closeGuideModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-full max-w-2xl relative z-10 transform transition-all duration-300 scale-95 opacity-0 translate-y-4 max-h-[90vh] flex flex-col overflow-hidden" id="guideCard">
<!-- Header Modal -->
<div class="flex justify-between items-center shrink-0 border-b border-gray-100 p-4 sm:p-6 bg-white">
<div class="flex items-center space-x-3">
<div class="w-10 h-10 bg-indigo-50 rounded-full flex items-center justify-center text-indigo-500 shrink-0">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h3 class="text-xl font-extrabold text-gray-900 leading-tight">Panduan Halaman</h3>
<p class="text-sm text-gray-500 font-medium">{% block page_title_guide %}{% endblock %}</p>
</div>
</div>
<button onclick="closeGuideModal()" class="text-gray-400 hover:bg-gray-100 hover:text-gray-600 p-2 rounded-xl transition-colors 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="M6 18L18 6M6 6l12 12"></path></svg>
</button>
</div>
<!-- Isi Modal -->
<div class="overflow-y-auto flex-1 min-h-0 p-6 sm:p-8 space-y-6 text-sm text-gray-600 leading-relaxed scrollbar-hide bg-white">
{% block page_guide_content %}
<div class="text-center py-8">
<svg class="w-12 h-12 text-gray-300 mx-auto mb-3" 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 class="text-gray-500 font-medium">Belum ada panduan khusus untuk halaman ini.</p>
</div>
{% endblock %}
</div>
<!-- Footer Modal -->
<div class="p-4 sm:p-6 border-t border-gray-100 flex justify-end shrink-0 bg-gray-50/50">
<button onclick="closeGuideModal()" class="px-6 py-2.5 bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold rounded-xl text-sm transition-colors">Saya Mengerti</button>
</div>
</div>
</div>
</body>
</html>
+271
View File
@@ -0,0 +1,271 @@
{% extends 'base.html' %}
{% block page_title %}{{ ci.ci_code }} &bull; {{ ci.name }}{% endblock %}
{% block content %}
<!-- Breadcrumb & Header -->
<div class="mb-6 flex flex-col sm:flex-row sm:justify-between sm:items-start space-y-4 sm:space-y-0">
<div>
<div class="flex items-center space-x-2 text-xs font-bold text-gray-400 uppercase tracking-widest mb-1">
<a href="{% url 'ci_list' %}" class="hover:text-kerinci transition-colors">Configuration Item</a>
<span>&bull;</span>
<span class="text-kerinci">Detail Komponen</span>
</div>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-black text-gray-900 font-mono">{{ ci.ci_code }}</h2>
{% if ci.status == 'available' %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">Tersedia</span>
{% elif ci.status == 'in_use' %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-blue-50 text-blue-700 border border-blue-200">Digunakan</span>
{% elif ci.status == 'under_repair' or ci.status == 'under_inspection' %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-amber-50 text-amber-700 border border-amber-200">Perbaikan</span>
{% else %}
<span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-bold bg-gray-100 text-gray-500 border border-gray-200">Bricked</span>
{% endif %}
</div>
<p class="text-base font-bold text-gray-700 mt-1">{{ ci.name }}</p>
</div>
<!-- Header Actions -->
<div class="flex items-center space-x-2">
<a href="{% url 'ci_list' %}" class="px-4 py-2 border border-gray-200 rounded-xl text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
&larr; Kembali
</a>
{% if not is_read_only %}
<button onclick="openEditModal()" class="px-4 py-2 bg-amber-50 text-amber-700 hover:bg-amber-100 border border-amber-200 rounded-xl text-sm font-bold transition-colors flex items-center space-x-1.5">
<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>
<span>Edit Data</span>
</button>
{% endif %}
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
<!-- Kolom Kiri: Relasi Aktif & Spesifikasi Komponen -->
<div class="lg:col-span-1 space-y-6">
<!-- Status Relasi Aktif -->
<div class="bg-white rounded-2xl p-6 border border-gray-100 shadow-sm">
<h3 class="text-xs font-extrabold text-gray-400 uppercase tracking-widest mb-4">Relasi & Penempatan Aktif</h3>
{% if ci.installed_on %}
<div class="bg-blue-50/60 p-4 rounded-xl border border-blue-100">
<div class="flex items-center space-x-2 text-blue-700 font-extrabold text-sm mb-1">
<svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path></svg>
<span>Terpasang Pada Perangkat</span>
</div>
<p class="text-lg font-black text-gray-900 mt-2 font-mono">{{ ci.installed_on.unit_code }}</p>
<p class="text-xs text-gray-600 font-semibold">{{ ci.installed_on.asset.name }}</p>
<div class="mt-3 pt-3 border-t border-blue-100/70 text-xs text-gray-600 space-y-1">
<p><span class="font-bold text-gray-500">Pengguna (PIC):</span> <strong class="text-gray-900">{{ ci.installed_on.assigned_to.name|default:"Tidak terikat karyawan" }}</strong></p>
{% if ci.installed_on.area %}
<p><span class="font-bold text-gray-500">Area:</span> {{ ci.installed_on.area }}</p>
{% endif %}
</div>
</div>
{% elif ci.assigned_to %}
<div class="bg-purple-50/60 p-4 rounded-xl border border-purple-100">
<div class="flex items-center space-x-2 text-purple-700 font-extrabold text-sm mb-1">
<svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
<span>Dialokasikan ke Karyawan</span>
</div>
<p class="text-lg font-black text-gray-900 mt-2">{{ ci.assigned_to.name }}</p>
<p class="text-xs text-gray-500">NIK: {{ ci.assigned_to.nik }} &bull; {{ ci.assigned_to.position|default:"Staff" }}</p>
</div>
{% elif ci.status == 'available' %}
<div class="bg-emerald-50/60 p-4 rounded-xl border border-emerald-100">
<div class="flex items-center space-x-2 text-emerald-700 font-extrabold text-sm mb-1">
<svg class="w-5 h-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
<span>Tersedia di Gudang IT</span>
</div>
<p class="text-sm font-bold text-gray-900 mt-2">Lokasi: {{ ci.location|default:"Gudang Induk (GI)" }}</p>
<p class="text-xs text-gray-500 mt-1">Komponen siap dipasang ke perangkat atau dialokasikan.</p>
</div>
{% else %}
<div class="bg-gray-50 p-4 rounded-xl border border-gray-100">
<p class="text-sm font-bold text-gray-700">Status: {{ ci.get_status_display }}</p>
<p class="text-xs text-gray-500 mt-1">Lokasi saat ini: {{ ci.location|default:"-" }}</p>
</div>
{% endif %}
</div>
<!-- Spesifikasi & Identitas Teknis -->
<div class="bg-white rounded-2xl p-6 border border-gray-100 shadow-sm">
<h3 class="text-xs font-extrabold text-gray-400 uppercase tracking-widest mb-4">Informasi Spesifikasi</h3>
<dl class="space-y-3 text-sm">
<div>
<dt class="text-xs font-bold text-gray-400">Kategori</dt>
<dd class="text-gray-900 font-semibold">{{ ci.get_category_display }}</dd>
</div>
<div>
<dt class="text-xs font-bold text-gray-400">Merek & Model</dt>
<dd class="text-gray-900 font-semibold">{{ ci.brand|default:"-" }} {{ ci.model_series|default:"" }}</dd>
</div>
<div>
<dt class="text-xs font-bold text-gray-400">Nomor Seri (S/N)</dt>
<dd class="text-gray-900 font-mono text-xs font-bold">{{ ci.serial_number|default:"-" }}</dd>
</div>
<div>
<dt class="text-xs font-bold text-gray-400">Kondisi Fisik</dt>
<dd class="text-gray-900 font-semibold">{{ ci.get_condition_display }}</dd>
</div>
{% if ci.specifications %}
<div>
<dt class="text-xs font-bold text-gray-400">Spesifikasi Detail</dt>
<dd class="text-gray-700 text-xs bg-gray-50 p-3 rounded-xl mt-1 font-mono whitespace-pre-wrap">{{ ci.specifications }}</dd>
</div>
{% endif %}
{% if ci.warranty_expiry %}
<div>
<dt class="text-xs font-bold text-gray-400">Garansi Berlaku Hingga</dt>
<dd class="text-gray-900 font-semibold">{{ ci.warranty_expiry|date:"d M Y" }}</dd>
</div>
{% endif %}
{% if ci.notes %}
<div>
<dt class="text-xs font-bold text-gray-400">Catatan Internal</dt>
<dd class="text-gray-600 text-xs mt-0.5">{{ ci.notes }}</dd>
</div>
{% endif %}
</dl>
</div>
</div>
<!-- Kolom Kanan: Timeline Riwayat Siklus Hidup (Audit Trail) -->
<div class="lg:col-span-2">
<div class="bg-white rounded-2xl p-6 sm:p-8 border border-gray-100 shadow-sm">
<div class="flex items-center justify-between mb-6 pb-4 border-b border-gray-100">
<div>
<h3 class="text-lg font-black text-gray-900">Timeline Riwayat Perjalanan Komponen</h3>
<p class="text-xs text-gray-500 mt-0.5">Audit log kronologis pemasangan, mutasi, pelepasan, dan perbaikan komponen.</p>
</div>
<span class="text-xs font-bold bg-gray-100 text-gray-600 px-3 py-1 rounded-full">
{{ history_logs|length }} Catatan
</span>
</div>
<!-- Timeline List -->
<div class="relative pl-6 space-y-6 before:absolute before:left-2.5 before:top-3 before:bottom-3 before:w-0.5 before:bg-gray-100">
{% for log in history_logs %}
<div class="relative group">
<!-- Bullet Icon -->
<div class="absolute -left-6 top-1 w-5 h-5 rounded-full border-2 border-white
{% if log.action == 'installed' %}bg-blue-600 shadow-sm shadow-blue-500/30
{% elif log.action == 'removed' %}bg-amber-500 shadow-sm shadow-amber-500/30
{% elif log.action == 'replaced' %}bg-purple-600 shadow-sm shadow-purple-500/30
{% elif log.action == 'repair_in' %}bg-red-500 shadow-sm shadow-red-500/30
{% elif log.action == 'repair_out' %}bg-emerald-500 shadow-sm shadow-emerald-500/30
{% else %}bg-gray-400{% endif %}">
</div>
<div class="bg-gray-50/70 hover:bg-gray-50 p-4 rounded-xl border border-gray-100 transition-colors">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-1 mb-1.5">
<span class="text-xs font-extrabold uppercase tracking-wider
{% if log.action == 'installed' %}text-blue-700
{% elif log.action == 'removed' %}text-amber-700
{% elif log.action == 'replaced' %}text-purple-700
{% elif log.action == 'repair_in' %}text-red-700
{% elif log.action == 'repair_out' %}text-emerald-700
{% else %}text-gray-700{% endif %}">
{{ log.get_action_display }}
</span>
<span class="text-[11px] text-gray-400 font-medium">
{{ log.timestamp|date:"d M Y, H:i" }}
</span>
</div>
<p class="text-xs text-gray-800 leading-relaxed font-medium">{{ log.notes|default:"-" }}</p>
<div class="mt-2 pt-2 border-t border-gray-100 flex items-center justify-between text-[11px] text-gray-400">
{% if log.related_unit %}
<span>Perangkat: <strong class="text-gray-700">{{ log.related_unit.unit_code }}</strong></span>
{% elif log.related_employee %}
<span>Karyawan: <strong class="text-gray-700">{{ log.related_employee.name }}</strong></span>
{% else %}
<span></span>
{% endif %}
<span>Oleh: <strong class="text-gray-700">{{ log.performed_by.username|default:"Sistem" }}</strong></span>
</div>
</div>
</div>
{% empty %}
<div class="text-center py-8 text-gray-400 text-xs">
Belum ada riwayat tercatat untuk komponen ini.
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<!-- Modal Edit Data CI -->
<div id="editCIModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeEditModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-xl max-h-[90vh] overflow-y-auto relative z-10 p-6 sm:p-8">
<div class="flex justify-between items-center mb-6 pb-3 border-b border-gray-100">
<h3 class="text-xl font-extrabold text-gray-900">Edit Data {{ ci.ci_code }}</h3>
<button onclick="closeEditModal()" class="text-gray-400 hover:text-gray-600 p-2 rounded-lg">
<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 'ci_edit' ci.id %}" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Nama Item</label>
<input type="text" name="name" value="{{ ci.name }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Merek</label>
<input type="text" name="brand" value="{{ ci.brand|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Model / Seri</label>
<input type="text" name="model_series" value="{{ ci.model_series|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Nomor Seri (S/N)</label>
<input type="text" name="serial_number" value="{{ ci.serial_number|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white font-mono">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Kondisi Fisik</label>
<select name="condition" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="new" {% if ci.condition == 'new' %}selected{% endif %}>Baru (New)</option>
<option value="good" {% if ci.condition == 'good' %}selected{% endif %}>Bagus / Normal (Good)</option>
<option value="fair" {% if ci.condition == 'fair' %}selected{% endif %}>Cukup / Bekas (Fair)</option>
<option value="damaged" {% if ci.condition == 'damaged' %}selected{% endif %}>Rusak (Damaged)</option>
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Lokasi Penyimpanan</label>
<input type="text" name="location" value="{{ ci.location|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Spesifikasi Teknis</label>
<textarea name="specifications" rows="2" class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white font-mono">{{ ci.specifications|default:'' }}</textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeEditModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-amber-500 text-white font-bold rounded-xl text-sm hover:bg-amber-600">Simpan Perubahan</button>
</div>
</form>
</div>
</div>
<script>
function openEditModal() {
document.getElementById('editCIModal').classList.remove('hidden');
}
function closeEditModal() {
document.getElementById('editCIModal').classList.add('hidden');
}
</script>
{% endblock %}
+604
View File
@@ -0,0 +1,604 @@
{% extends 'base.html' %}
{% block page_title %}Configuration Item (CI / CMDB){% 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 &bull; CMDB</p>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-extrabold text-gray-900">Configuration Item (CI)</h2>
<span class="px-2.5 py-0.5 rounded-full text-xs font-extrabold bg-blue-50 text-blue-700 border border-blue-200">
CMDB & Komponen
</span>
</div>
<p class="text-xs text-gray-500 mt-1">Pelacakan komponen internal, peripheral, dan modul pendukung perangkat IT.</p>
</div>
<div class="flex items-center space-x-3 w-full sm:w-auto">
{% if not is_read_only %}
<button onclick="openCreateCIModal()" 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">
<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 CI Baru</span>
</button>
{% endif %}
</div>
</div>
<!-- KPI Summary Cards -->
<div class="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-bold text-gray-400 uppercase tracking-wider mb-1">Total Komponen</p>
<h3 class="text-2xl font-black text-gray-900">{{ counts.total }}</h3>
<p class="text-[11px] text-gray-400 mt-1">Terdaftar di CMDB</p>
</div>
<div class="w-12 h-12 bg-blue-50 text-kerinci rounded-xl flex items-center justify-center font-bold">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"></path></svg>
</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-bold text-blue-600 uppercase tracking-wider mb-1">Sedang Digunakan</p>
<h3 class="text-2xl font-black text-blue-900">{{ counts.in_use }}</h3>
<p class="text-[11px] text-blue-500 mt-1">Terpasang / Dipegang</p>
</div>
<div class="w-12 h-12 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center font-bold">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-bold text-emerald-600 uppercase tracking-wider mb-1">Tersedia (Gudang)</p>
<h3 class="text-2xl font-black text-emerald-900">{{ counts.available }}</h3>
<p class="text-[11px] text-emerald-500 mt-1">Siap dialokasikan</p>
</div>
<div class="w-12 h-12 bg-emerald-50 text-emerald-600 rounded-xl flex items-center justify-center font-bold">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
</div>
</div>
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-xs font-bold text-amber-600 uppercase tracking-wider mb-1">Dalam Perbaikan</p>
<h3 class="text-2xl font-black text-amber-900">{{ counts.under_repair }}</h3>
<p class="text-[11px] text-amber-500 mt-1">Inspeksi / Maintenance</p>
</div>
<div class="w-12 h-12 bg-amber-50 text-amber-600 rounded-xl flex items-center justify-center font-bold">
<svg class="w-6 h-6" 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>
</div>
</div>
</div>
<!-- Status Tabs -->
<div class="flex space-x-2 mb-4 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
<a href="?status={% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if not status_filter %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Semua Komponen
<span class="ml-2 {% if not status_filter %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.total }}</span>
</a>
<a href="?status=available{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'available' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Tersedia (Gudang)
<span class="ml-2 {% if status_filter == 'available' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.available }}</span>
</a>
<a href="?status=in_use{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'in_use' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Sedang Digunakan
<span class="ml-2 {% if status_filter == 'in_use' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.in_use }}</span>
</a>
<a href="?status=repair{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'repair' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Perbaikan / Rusak
<span class="ml-2 {% if status_filter == 'repair' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.under_repair }}</span>
</a>
<a href="?status=retired{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'retired' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Bricked
<span class="ml-2 {% if status_filter == 'retired' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.retired }}</span>
</a>
</div>
<!-- Filters & Search -->
<div class="mb-4 flex flex-col md:flex-row md:items-center justify-between gap-3">
<form id="searchForm" method="GET" class="flex flex-wrap items-center gap-2 w-full">
<input type="hidden" name="status" value="{{ status_filter }}">
<div class="relative flex-1 min-w-[240px]">
<input type="text" id="searchInput" name="q" value="{{ search_query }}" placeholder="Cari Kode Item, nama, S/N, perangkat, atau PIC..." 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>
</div>
<select name="category" onchange="this.form.submit()" class="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 text-gray-700 shadow-sm">
<option value="">Semua Kategori</option>
{% for cat_val, cat_label in categories %}
<option value="{{ cat_val }}" {% if category_filter == cat_val %}selected{% endif %}>{{ cat_label }}</option>
{% endfor %}
</select>
<select name="condition" onchange="this.form.submit()" class="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 text-gray-700 shadow-sm">
<option value="">Semua Kondisi</option>
{% for cond_val, cond_label in condition_choices %}
<option value="{{ cond_val }}" {% if condition_filter == cond_val %}selected{% endif %}>{{ cond_label }}</option>
{% endfor %}
</select>
{% if search_query or category_filter or condition_filter or status_filter %}
<a href="{% url 'ci_list' %}" class="px-3.5 py-2.5 text-xs font-bold text-gray-500 hover:text-red-500 border border-gray-200 hover:border-red-200 rounded-xl bg-white transition-colors" title="Reset Filter">
Reset
</a>
{% endif %}
</form>
</div>
<!-- Main Data Table -->
<div class="bg-white rounded-none sm:rounded-2xl shadow-sm border border-gray-100 overflow-hidden w-full">
<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-12">No</th>
<th class="p-4 font-bold min-w-[130px]">Kode Item</th>
<th class="p-4 font-bold min-w-[220px]">Nama & Komponen</th>
<th class="p-4 font-bold">Kategori</th>
<th class="p-4 font-bold min-w-[140px]">Nomor Seri (S/N)</th>
<th class="p-4 font-bold min-w-[200px]">Perangkat / Pengguna</th>
<th class="p-4 font-bold text-center">Kondisi</th>
<th class="p-4 font-bold text-center">Status</th>
<th class="p-4 font-bold text-center min-w-[140px]">Aksi</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-50">
{% for item in items %}
<tr class="hover:bg-gray-50/50 transition-colors">
<td class="p-4 text-gray-400 font-medium text-center text-xs">{{ forloop.counter }}</td>
<td class="p-4">
<a href="{% url 'ci_detail' item.id %}" class="block group">
<span class="font-extrabold text-gray-900 group-hover:text-kerinci transition-colors font-mono text-xs">{{ item.ci_code }}</span>
</a>
</td>
<td class="p-4">
<a href="{% url 'ci_detail' item.id %}" class="block group">
<span class="font-bold text-gray-900 group-hover:text-kerinci transition-colors">{{ item.name }}</span>
</a>
<p class="text-xs text-gray-500 mt-0.5">{{ item.brand|default:"-" }}{% if item.model_series %} &bull; {{ item.model_series }}{% endif %}</p>
</td>
<td class="p-4">
<span class="text-xs font-semibold text-gray-700 bg-gray-100 px-2 py-1 rounded-md">
{{ item.get_category_display }}
</span>
</td>
<td class="p-4">
<span class="font-mono text-xs text-gray-700">{{ item.serial_number|default:"-" }}</span>
</td>
<td class="p-4">
{% if item.installed_on %}
<div class="flex items-center space-x-1.5">
<span class="w-2 h-2 rounded-full bg-blue-500"></span>
<div>
<span class="font-bold text-xs text-blue-700">Terpasang: {{ item.installed_on.unit_code }}</span>
{% if item.installed_on.assigned_to %}
<p class="text-[11px] text-gray-500">PIC: {{ item.installed_on.assigned_to.name }}</p>
{% endif %}
</div>
</div>
{% elif item.assigned_to %}
<div class="flex items-center space-x-1.5">
<span class="w-2 h-2 rounded-full bg-purple-500"></span>
<div>
<span class="font-bold text-xs text-purple-700">Dipegang: {{ item.assigned_to.name }}</span>
<p class="text-[11px] text-gray-400">NIK: {{ item.assigned_to.nik }}</p>
</div>
</div>
{% elif item.status == 'available' %}
<span class="text-xs text-emerald-700 font-medium bg-emerald-50 px-2 py-0.5 rounded border border-emerald-100">
{{ item.location|default:"Gudang IT" }}
</span>
{% else %}
<span class="text-xs text-gray-400 italic">-</span>
{% endif %}
</td>
<td class="p-4 text-center">
{% if item.condition == 'new' %}
<span class="px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-blue-50 text-blue-700 border border-blue-200">Baru</span>
{% elif item.condition == 'good' %}
<span class="px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">Bagus</span>
{% elif item.condition == 'fair' %}
<span class="px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-amber-50 text-amber-700 border border-amber-200">Bekas</span>
{% else %}
<span class="px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-red-50 text-red-700 border border-red-200">Rusak</span>
{% endif %}
</td>
<td class="p-4 text-center">
{% if item.status == 'available' %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-emerald-50 text-emerald-700 border border-emerald-200">Tersedia</span>
{% elif item.status == 'in_use' %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-blue-50 text-blue-700 border border-blue-200">Digunakan</span>
{% elif item.status == 'under_repair' or item.status == 'under_inspection' %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-amber-50 text-amber-700 border border-amber-200">Perbaikan</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">Pensiun</span>
{% endif %}
</td>
<td class="p-4 text-center">
<div class="flex items-center justify-center space-x-1.5">
<a href="{% url 'ci_detail' item.id %}" class="p-1.5 text-gray-500 hover:text-kerinci hover:bg-gray-100 rounded-lg transition-colors" title="Lihat Detail & Riwayat">
<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="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>
</a>
{% if not is_read_only %}
{% if item.status == 'available' %}
<button onclick="openAssignModal('{{ item.id }}', '{{ item.ci_code }}', '{{ item.name|escapejs }}')" class="p-1.5 text-emerald-600 hover:bg-emerald-50 rounded-lg transition-colors" title="Gunakan Untuk (Pasang/Alokasi)">
<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 4v16m8-8H4"></path></svg>
</button>
{% elif item.status == 'in_use' %}
{% if item.installed_on %}
<button onclick="openReplaceModal('{{ item.id }}', '{{ item.ci_code }}', '{{ item.name|escapejs }}', '{{ item.installed_on.unit_code }}')" class="p-1.5 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors" title="Ganti / Upgrade Komponen">
<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>
{% endif %}
<button onclick="openRemoveModal('{{ item.id }}', '{{ item.ci_code }}', '{{ item.name|escapejs }}')" class="p-1.5 text-amber-600 hover:bg-amber-50 rounded-lg transition-colors" title="Lepas dari Perangkat/Pengguna">
<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="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"></path></svg>
</button>
{% endif %}
<button onclick="openDamageModal('{{ item.id }}', '{{ item.ci_code }}', '{{ item.name|escapejs }}')" class="p-1.5 text-red-500 hover:bg-red-50 rounded-lg transition-colors" title="Laporkan Kerusakan / Perbaikan">
<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 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>
</button>
{% endif %}
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="9" class="p-12 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-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"></path></svg>
<p class="font-medium text-gray-500">Belum ada Configuration Item yang cocok dengan kriteria pencarian.</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include 'components/pagination.html' %}
</div>
<!-- ============================================================== -->
<!-- MODAL: Tambah Configuration Item Baru -->
<!-- ============================================================== -->
<div id="createCIModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeCreateCIModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-2xl max-h-[90vh] overflow-y-auto relative z-10 p-6 sm:p-8">
<div class="flex justify-between items-center mb-6 pb-4 border-b border-gray-100">
<div>
<h3 class="text-xl font-extrabold text-gray-900">Tambah Configuration Item (CI)</h3>
<p class="text-xs text-gray-500 mt-0.5">Daftarkan komponen atau peripheral baru ke dalam CMDB.</p>
</div>
<button onclick="closeCreateCIModal()" class="text-gray-400 hover:text-gray-600 p-2 rounded-lg 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 'ci_create' %}" method="POST" class="space-y-4">
{% csrf_token %}
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Kode Item (Opsional)</label>
<input type="text" name="ci_code" placeholder="Auto-generate jika dikosongkan" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Kategori Komponen <span class="text-red-500">*</span></label>
<select name="category" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
{% for cat_val, cat_label in categories %}
<option value="{{ cat_val }}">{{ cat_label }}</option>
{% endfor %}
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Nama Item / Komponen <span class="text-red-500">*</span></label>
<input type="text" name="name" required placeholder="Contoh: SSD Samsung 980 NVMe 1TB / Logitech B100 Mouse" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Merek</label>
<input type="text" name="brand" placeholder="Samsung / Kingston / dll" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Model / Seri</label>
<input type="text" name="model_series" placeholder="980 Pro / DDR4 3200MHz" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Nomor Seri (S/N)</label>
<input type="text" name="serial_number" placeholder="S/N fisik item" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono bg-white">
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Kondisi Fisik Awal</label>
<select name="condition" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
{% for cond_val, cond_label in condition_choices %}
<option value="{{ cond_val }}">{{ cond_label }}</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Lokasi Penyimpanan</label>
<input type="text" name="location" value="Gudang IT" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Spesifikasi Teknis</label>
<textarea name="specifications" rows="2" placeholder="Detail kapasitas, interface, form factor, speed, dsb..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white"></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeCreateCIModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-kerinci text-white font-bold rounded-xl text-sm hover:bg-kerinci/90 shadow-sm shadow-kerinci/30">Simpan Komponen</button>
</div>
</form>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: Gunakan Untuk (Assignment) -->
<!-- ============================================================== -->
<div id="assignModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeAssignModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-lg relative z-10 p-6 sm:p-8">
<h3 class="text-xl font-extrabold text-gray-900 mb-1">Gunakan / Alokasikan Komponen</h3>
<p class="text-xs text-gray-500 mb-4">Pilih apakah komponen akan dipasang ke unit perangkat atau dialokasikan langsung ke karyawan.</p>
<div class="bg-gray-50 p-3 rounded-xl border border-gray-100 mb-4 text-xs">
<span class="text-gray-400 font-bold">Item:</span> <strong id="assign_ci_text" class="text-gray-800"></strong>
</div>
<form id="assignForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Tujuan Penggunaan</label>
<div class="grid grid-cols-2 gap-3">
<label class="flex items-center p-3 border rounded-xl cursor-pointer hover:bg-blue-50/50 has-[:checked]:border-kerinci has-[:checked]:bg-blue-50/30">
<input type="radio" name="usage_type" value="asset" checked onchange="toggleUsageType('asset')" class="text-kerinci focus:ring-kerinci">
<span class="ml-2 text-xs font-bold text-gray-800">Pasang ke Perangkat</span>
</label>
<label class="flex items-center p-3 border rounded-xl cursor-pointer hover:bg-blue-50/50 has-[:checked]:border-kerinci has-[:checked]:bg-blue-50/30">
<input type="radio" name="usage_type" value="employee" onchange="toggleUsageType('employee')" class="text-kerinci focus:ring-kerinci">
<span class="ml-2 text-xs font-bold text-gray-800">Alokasikan ke Karyawan</span>
</label>
</div>
</div>
<!-- Target: Perangkat (AssetUnit) -->
<div id="target_asset_container">
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Pilih Perangkat Tujuan <span class="text-red-500">*</span></label>
<select id="target_unit_select" name="target_id" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="">-- Pilih Unit Perangkat --</option>
{% for u in available_units %}
<option value="{{ u.id }}">{{ u.unit_code }} &bull; {{ u.asset.name }}{% if u.assigned_to %} (PIC: {{ u.assigned_to.name }}){% endif %}</option>
{% endfor %}
</select>
</div>
<!-- Target: Karyawan (Employee) -->
<div id="target_employee_container" class="hidden">
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Pilih Karyawan Penerima <span class="text-red-500">*</span></label>
<select id="target_employee_select" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="">-- Pilih Karyawan Aktif --</option>
{% for emp in available_employees %}
<option value="{{ emp.id }}">{{ emp.nik }} &bull; {{ emp.name }} ({{ emp.position|default:"Staff" }})</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Catatan Pemasangan / Work Order</label>
<textarea name="notes" rows="2" placeholder="No tiket, teknisi pelaksana, atau alasan pemasangan..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white"></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeAssignModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-emerald-600 text-white font-bold rounded-xl text-sm hover:bg-emerald-700 shadow-sm shadow-emerald-600/30">Proses Pemasangan</button>
</div>
</form>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: Ganti / Upgrade Komponen (Replacement) -->
<!-- ============================================================== -->
<div id="replaceModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeReplaceModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-lg relative z-10 p-6 sm:p-8">
<h3 class="text-xl font-extrabold text-gray-900 mb-1">Ganti / Upgrade Komponen</h3>
<p class="text-xs text-gray-500 mb-4">Gantikan komponen yang sedang terpasang dengan komponen baru/cadangan dari gudang.</p>
<div class="bg-amber-50 p-3 rounded-xl border border-amber-200 mb-4 text-xs">
<p><span class="text-amber-800 font-bold">Komponen Lama:</span> <strong id="rep_old_ci_text"></strong></p>
<p class="mt-1"><span class="text-amber-800 font-bold">Perangkat Induk:</span> <strong id="rep_unit_text"></strong></p>
</div>
<form id="replaceForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Komponen Pengganti (Dari Gudang) <span class="text-red-500">*</span></label>
<select name="replacement_ci_id" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="">-- Pilih Komponen Tersedia --</option>
{% for sp in spare_cis %}
<option value="{{ sp.id }}">{{ sp.ci_code }} &bull; {{ sp.name }} ({{ sp.get_category_display }})</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Alasan Penggantian</label>
<select name="reason" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="Replacement Kerusakan">Replacement (Komponen Lama Rusak)</option>
<option value="Peningkatan Kapasitas / Performa">Upgrade (Peningkatan Kapasitas / Performa)</option>
<option value="Preventive Maintenance">Preventive Maintenance Berkala</option>
<option value="Standardisasi Perangkat">Standardisasi Perangkat IT</option>
</select>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Status Komponen Lama</label>
<select name="old_ci_status" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="under_repair">Masuk Perbaikan</option>
<option value="available">Tersedia (Masih Bagus)</option>
<option value="retired">Bricked</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Kondisi Komponen Lama</label>
<select name="old_ci_condition" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="damaged">Rusak (Damaged)</option>
<option value="good">Bagus / Normal</option>
<option value="fair">Cukup / Bekas</option>
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Catatan Penggantian</label>
<textarea name="notes" rows="2" placeholder="Catatan hasil pengujian komponen baru, nomor tiket, teknisi..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white"></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeReplaceModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-blue-600 text-white font-bold rounded-xl text-sm hover:bg-blue-700 shadow-sm shadow-blue-600/30">Lakukan Penggantian</button>
</div>
</form>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: Lepas dari Perangkat (Remove) -->
<!-- ============================================================== -->
<div id="removeModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeRemoveModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-md relative z-10 p-6 sm:p-8">
<h3 class="text-xl font-extrabold text-gray-900 mb-1">Lepas Komponen</h3>
<p class="text-xs text-gray-500 mb-4">Putuskan relasi komponen dari perangkat/pengguna dan simpan kembali ke inventaris.</p>
<form id="removeForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Status Komponen Setelah Dilepas</label>
<select name="new_status" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="available">Tersedia di Gudang (Bagus)</option>
<option value="under_inspection">Masuk Pemeriksaan</option>
<option value="under_repair">Masuk Perbaikan (Rusak)</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Lokasi Penyimpanan</label>
<input type="text" name="location" value="Gudang IT" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Alasan Pelepasan</label>
<textarea name="notes" rows="2" placeholder="Alasan pelepasan..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white"></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeRemoveModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-amber-500 text-white font-bold rounded-xl text-sm hover:bg-amber-600 shadow-sm shadow-amber-500/30">Ya, Lepas Komponen</button>
</div>
</form>
</div>
</div>
<!-- ============================================================== -->
<!-- MODAL: Laporkan Kerusakan / Perbaikan -->
<!-- ============================================================== -->
<div id="damageModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeDamageModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] max-w-md relative z-10 p-6 sm:p-8">
<h3 class="text-xl font-extrabold text-gray-900 mb-1">Lapor Status Perbaikan</h3>
<p class="text-xs text-gray-500 mb-4">Update status pemeliharaan atau laporkan keluhan kerusakan teknis.</p>
<form id="damageForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Tindakan Maintenance</label>
<select name="action_type" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<option value="repair_in">Masuk Perbaikan (Unit Mengalami Gangguan)</option>
<option value="repair_out">Selesai Perbaikan (Unit Sudah Normal)</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase mb-1">Keterangan Kerusakan / Solusi</label>
<textarea name="notes" rows="3" required placeholder="Jelaskan detail kerusakan, error, atau tindakan perbaikan yang dilakukan..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white"></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeDamageModal()" class="px-5 py-2.5 border border-gray-300 text-gray-700 font-bold rounded-xl text-sm hover:bg-gray-50">Batal</button>
<button type="submit" class="px-6 py-2.5 bg-red-600 text-white font-bold rounded-xl text-sm hover:bg-red-700 shadow-sm shadow-red-600/30">Simpan Laporan</button>
</div>
</form>
</div>
</div>
<script>
function openCreateCIModal() {
document.getElementById('createCIModal').classList.remove('hidden');
}
function closeCreateCIModal() {
document.getElementById('createCIModal').classList.add('hidden');
}
function openAssignModal(id, code, name) {
document.getElementById('assign_ci_text').innerText = code + ' - ' + name;
document.getElementById('assignForm').action = '/ci/' + id + '/assign/';
document.getElementById('assignModal').classList.remove('hidden');
}
function closeAssignModal() {
document.getElementById('assignModal').classList.add('hidden');
}
function toggleUsageType(type) {
const assetCont = document.getElementById('target_asset_container');
const empCont = document.getElementById('target_employee_container');
const unitSelect = document.getElementById('target_unit_select');
const empSelect = document.getElementById('target_employee_select');
if (type === 'asset') {
assetCont.classList.remove('hidden');
empCont.classList.add('hidden');
unitSelect.name = 'target_id';
empSelect.name = '';
} else {
assetCont.classList.add('hidden');
empCont.classList.remove('hidden');
unitSelect.name = '';
empSelect.name = 'target_id';
}
}
function openReplaceModal(id, code, name, unitCode) {
document.getElementById('rep_old_ci_text').innerText = code + ' (' + name + ')';
document.getElementById('rep_unit_text').innerText = unitCode;
document.getElementById('replaceForm').action = '/ci/' + id + '/replace/';
document.getElementById('replaceModal').classList.remove('hidden');
}
function closeReplaceModal() {
document.getElementById('replaceModal').classList.add('hidden');
}
function openRemoveModal(id, code, name) {
document.getElementById('removeForm').action = '/ci/' + id + '/remove/';
document.getElementById('removeModal').classList.remove('hidden');
}
function closeRemoveModal() {
document.getElementById('removeModal').classList.add('hidden');
}
function openDamageModal(id, code, name) {
document.getElementById('damageForm').action = '/ci/' + id + '/report-damage/';
document.getElementById('damageModal').classList.remove('hidden');
}
function closeDamageModal() {
document.getElementById('damageModal').classList.add('hidden');
}
</script>
{% endblock %}
+50
View File
@@ -0,0 +1,50 @@
{% if page_obj.has_other_pages %}
<div class="px-6 py-4 bg-gray-50/50 border-t border-gray-100 flex flex-col sm:flex-row items-center justify-between gap-4">
<div class="text-sm text-gray-500">
Menampilkan <span class="font-bold text-gray-900">{{ page_obj.start_index }}</span> - <span class="font-bold text-gray-900">{{ page_obj.end_index }}</span> dari <span class="font-bold text-gray-900">{{ page_obj.paginator.count }}</span> data
</div>
<div class="flex items-center space-x-1">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" class="px-3 py-1.5 rounded-lg border border-gray-200 text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors">
&laquo; Prev
</a>
{% else %}
<span class="px-3 py-1.5 rounded-lg border border-gray-100 text-sm font-semibold text-gray-300 cursor-not-allowed">
&laquo; Prev
</span>
{% endif %}
{% for p in page_obj.paginator.page_range %}
{% if p == page_obj.number %}
<span class="px-3.5 py-1.5 rounded-lg bg-kerinci text-white text-sm font-bold shadow-sm">
{{ p }}
</span>
{% elif p >= page_obj.number|add:"-2" and p <= page_obj.number|add:"2" %}
<a href="?page={{ p }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" class="px-3.5 py-1.5 rounded-lg border border-gray-200 text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors">
{{ p }}
</a>
{% elif p == 1 or p == page_obj.paginator.num_pages %}
<a href="?page={{ p }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" class="px-3.5 py-1.5 rounded-lg border border-gray-200 text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors">
{{ p }}
</a>
{% elif p == page_obj.number|add:"-3" or p == page_obj.number|add:"3" %}
<span class="px-2 py-1.5 text-sm text-gray-400">...</span>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}" class="px-3 py-1.5 rounded-lg border border-gray-200 text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors">
Next &raquo;
</a>
{% else %}
<span class="px-3 py-1.5 rounded-lg border border-gray-100 text-sm font-semibold text-gray-300 cursor-not-allowed">
Next &raquo;
</span>
{% endif %}
</div>
</div>
{% else %}
<div class="px-6 py-4 bg-gray-50/50 border-t border-gray-100 flex items-center justify-between text-sm text-gray-500">
<p>Menampilkan <span class="font-bold text-gray-900">{{ page_obj.paginator.count|default:page_obj|length }}</span> data</p>
</div>
{% endif %}
+658
View File
@@ -0,0 +1,658 @@
{% extends 'base.html' %}
{% block page_title %}{{ item.item_code }} - {{ item.name }}{% endblock %}
{% block page_title_guide %}Buku Besar & Riwayat Stok Consumable{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman ini menyajikan <b>Buku Besar Persediaan (Stock Ledger)</b> untuk item <b>{{ item.name }}</b>. Seluruh mutasi kuantitas dicatat secara permanen dan berurutan untuk keperluan audit.</p>
<div class="p-3 bg-blue-50 border border-blue-200 rounded-xl">
<h4 class="font-bold text-blue-800 text-xs uppercase tracking-wider mb-1">Mekanisme Reversal (Pembalik Transaksi)</h4>
<p class="text-xs text-blue-700">Jika terjadi kesalahan input transaksi yang telah diposting, sistem menyediakan tombol <b>Reversal</b>. Transaksi asal tidak akan dihapus melainkan ditandai dan dibuatkan entri transaksi pembalik secara atomik untuk menjaga keutuhan audit trail.</p>
</div>
</div>
{% endblock %}
{% block content %}
<!-- Header Navigation & Actions -->
<div class="mb-6 flex flex-col sm:flex-row sm:justify-between sm:items-end space-y-4 sm:space-y-0">
<div>
<div class="flex items-center space-x-2 text-xs font-bold text-gray-400 mb-1">
<a href="{% url 'consumable_list' %}" class="hover:text-kerinci transition-colors">Consumable Item</a>
<span>&bull;</span>
<span class="text-kerinci font-mono">{{ item.item_code }}</span>
</div>
<div class="flex flex-wrap items-center gap-3">
<h2 class="text-2xl sm:text-3xl font-extrabold text-gray-900">{{ item.name }}</h2>
<!-- Status Badge -->
{% if item.stock_status == 'out_of_stock' %}
<span class="px-3 py-1 rounded-full text-xs font-bold bg-red-100 text-red-700 border border-red-200 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-red-500"></span>
Stok Habis
</span>
{% elif item.stock_status == 'low_stock' %}
<span class="px-3 py-1 rounded-full text-xs font-bold bg-amber-100 text-amber-800 border border-amber-200 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-amber-500"></span>
Stok Menipis
</span>
{% else %}
<span class="px-3 py-1 rounded-full text-xs font-bold bg-emerald-100 text-emerald-800 border border-emerald-200 flex items-center gap-1.5">
<span class="w-2 h-2 rounded-full bg-emerald-500"></span>
Stok Tersedia
</span>
{% endif %}
<span class="px-2.5 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700">
{{ item.get_category_display }}
</span>
</div>
<p class="text-xs text-gray-500 mt-1">{{ item.brand|default:"Tanpa Merek" }} &bull; {{ item.specification|default:"Tidak ada spesifikasi khusus" }}</p>
</div>
<!-- Action Buttons -->
<div class="flex flex-wrap items-center gap-2 w-full sm:w-auto">
<a href="{% url 'consumable_list' %}" class="px-3.5 py-2 rounded-xl border border-gray-200 text-xs font-bold text-gray-600 hover:bg-gray-50 transition-colors flex items-center space-x-1.5 bg-white shadow-sm">
<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="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg>
<span>Katalog</span>
</a>
{% if not is_read_only %}
<button onclick="openModalBarangMasuk()" class="bg-blue-600 text-white px-3.5 py-2 rounded-xl text-xs font-bold shadow-sm shadow-blue-500/20 hover:bg-blue-700 transition-colors flex items-center space-x-1.5">
<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 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg>
<span>+ Barang Masuk</span>
</button>
<button onclick="openModalBarangKeluar()" class="bg-amber-600 text-white px-3.5 py-2 rounded-xl text-xs font-bold shadow-sm shadow-amber-500/20 hover:bg-amber-700 transition-colors flex items-center space-x-1.5">
<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 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
<span>- Barang Keluar</span>
</button>
<button onclick="openModalEditItem()" class="px-3.5 py-2 rounded-xl border border-gray-200 text-xs font-bold text-gray-700 hover:bg-gray-50 transition-colors flex items-center space-x-1.5 bg-white shadow-sm">
<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>
<span>Edit Master</span>
</button>
{% endif %}
</div>
</div>
<!-- Specs & Stat Cards -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
<!-- Card 1: Stok Saat Ini -->
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm">
<p class="text-[11px] font-bold text-gray-400 uppercase tracking-wider mb-1">Stok Tersedia</p>
<h3 class="text-3xl font-black {% if item.stock_status == 'out_of_stock' %}text-red-600{% elif item.stock_status == 'low_stock' %}text-amber-600{% else %}text-emerald-700{% endif %}">
{{ item.formatted_stock }}
</h3>
<p class="text-xs text-gray-500 mt-1">Batas Minimum: <b>{{ item.formatted_minimum_stock }}</b></p>
</div>
<!-- Card 2: Satuan & Rasio Konversi -->
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm">
<p class="text-[11px] font-bold text-gray-400 uppercase tracking-wider mb-1">Satuan & Konversi</p>
<h4 class="text-lg font-extrabold text-gray-800">UoM: {{ item.base_unit }}</h4>
{% if item.purchase_unit %}
<p class="text-xs text-gray-600 mt-1">
Beli: <b>{{ item.purchase_unit }}</b> (1 {{ item.purchase_unit }} = {{ item.conversion_rate|floatformat:0 }} {{ item.base_unit }})
</p>
{% else %}
<p class="text-xs text-gray-400 mt-1">Hanya menggunakan satuan dasar.</p>
{% endif %}
</div>
<!-- Card 3: Lokasi & Gudang -->
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm">
<p class="text-[11px] font-bold text-gray-400 uppercase tracking-wider mb-1">Lokasi Penyimpanan</p>
<h4 class="text-lg font-extrabold text-gray-800 truncate" title="{{ item.location }}">{{ item.location }}</h4>
<p class="text-xs text-gray-500 mt-1">
Harga Beli: {% if item.last_purchase_price > 0 %}Rp {{ item.last_purchase_price|floatformat:0 }}{% else %}Tidak diset{% endif %}
</p>
</div>
<!-- Card 4: Akumulasi Perputaran Material -->
<div class="bg-white p-5 rounded-2xl border border-gray-100 shadow-sm">
<p class="text-[11px] font-bold text-gray-400 uppercase tracking-wider mb-1">Perputaran Material</p>
<div class="flex items-center justify-between text-xs mt-1">
<span class="text-gray-500">Total Masuk:</span>
<span class="font-bold text-blue-700">+{{ total_in|floatformat:1 }} {{ item.base_unit }}</span>
</div>
<div class="flex items-center justify-between text-xs mt-1">
<span class="text-gray-500">Total Keluar:</span>
<span class="font-bold text-amber-700">-{{ total_out|floatformat:1 }} {{ item.base_unit }}</span>
</div>
</div>
</div>
<!-- Stock Ledger Table (Buku Besar Mutasi) -->
<div class="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden mb-6">
<div class="p-4 border-b border-gray-100 flex items-center justify-between bg-gray-50/50">
<div class="flex items-center space-x-2">
<svg class="w-5 h-5 text-kerinci" 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>
<h3 class="font-extrabold text-gray-900 text-sm">Buku Besar Persediaan (Stock Ledger)</h3>
</div>
<span class="text-xs text-gray-500 font-medium">Audit Trail Mutasi Stok</span>
</div>
<div class="overflow-x-auto">
<table class="w-full text-left border-collapse min-w-[1000px]">
<thead>
<tr class="bg-gray-50/75 border-b border-gray-200 text-[11px] font-bold text-gray-500 uppercase tracking-wider">
<th class="py-3 px-4">Tanggal & Ref</th>
<th class="py-3 px-4 text-center">Tipe Transaksi</th>
<th class="py-3 px-4 text-right">Kuantitas Transaksi</th>
<th class="py-3 px-4 text-right">Efektif Dasar</th>
<th class="py-3 px-4 text-right">Saldo Sebelum</th>
<th class="py-3 px-4 text-right">Saldo Sesudah</th>
<th class="py-3 px-4">Penerima / Sumber / Area</th>
<th class="py-3 px-4">Ref Tiket / Unit</th>
<th class="py-3 px-4">Petugas</th>
<th class="py-3 px-4 text-center">Aksi</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100 text-xs">
{% for trx in page_obj %}
<tr class="hover:bg-gray-50/80 transition-colors {% if trx.is_reversed %}opacity-60 bg-gray-50/50 line-through{% endif %}">
<!-- Tanggal & Kode Transaksi -->
<td class="py-3 px-4 whitespace-nowrap">
<div class="font-bold text-gray-900">{{ trx.transaction_date|date:"d M Y" }}</div>
<div class="font-mono text-[10px] text-gray-400">{{ trx.transaction_code }}</div>
</td>
<!-- Tipe Transaksi Badge -->
<td class="py-3 px-4 text-center whitespace-nowrap">
{% if trx.transaction_type == 'in' %}
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-blue-100 text-blue-700">
Masuk
</span>
{% elif trx.transaction_type == 'out' %}
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-amber-100 text-amber-800">
Keluar
</span>
{% elif trx.transaction_type == 'adjustment' %}
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-purple-100 text-purple-700">
Opname
</span>
{% elif trx.transaction_type == 'reversal' %}
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-gray-200 text-gray-800">
Reversal
</span>
{% endif %}
{% if trx.is_reversed %}
<span class="block text-[9px] text-red-600 font-bold mt-0.5 no-underline">DIBALIK</span>
{% endif %}
</td>
<!-- Kuantitas Transaksi -->
<td class="py-3 px-4 text-right whitespace-nowrap font-mono">
{% if trx.transaction_type == 'in' %}
<span class="font-bold text-blue-600">+{{ trx.quantity }} {{ trx.unit }}</span>
{% elif trx.transaction_type == 'out' %}
<span class="font-bold text-amber-600">-{{ trx.quantity }} {{ trx.unit }}</span>
{% elif trx.transaction_type == 'reversal' %}
<span class="font-bold text-gray-600">{{ trx.quantity }} {{ trx.unit }}</span>
{% else %}
<span class="font-bold text-purple-600">{{ trx.quantity }} {{ trx.unit }}</span>
{% endif %}
</td>
<!-- Kuantitas Satuan Dasar -->
<td class="py-3 px-4 text-right whitespace-nowrap font-mono font-bold text-gray-800">
{{ trx.quantity_base }} {{ item.base_unit }}
</td>
<!-- Saldo Sebelum -->
<td class="py-3 px-4 text-right whitespace-nowrap font-mono text-gray-500">
{{ trx.stock_before }}
</td>
<!-- Saldo Sesudah -->
<td class="py-3 px-4 text-right whitespace-nowrap font-mono font-black text-gray-900">
{{ trx.stock_after }}
</td>
<!-- Penerima / Sumber / Area -->
<td class="py-3 px-4 max-w-[200px]">
{% if trx.recipient_employee %}
<div class="font-semibold text-gray-800">{{ trx.recipient_employee.name }}</div>
{% endif %}
<div class="text-[11px] text-gray-500 truncate" title="{{ trx.source_destination }}">
{{ trx.source_destination|default:"-" }}
</div>
{% if trx.supplier %}
<div class="text-[10px] text-gray-400">Supplier: {{ trx.supplier }}</div>
{% endif %}
</td>
<!-- Ref Tiket / Unit -->
<td class="py-3 px-4 whitespace-nowrap">
{% if trx.ticket_number %}
<span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-mono bg-blue-50 text-blue-700 font-semibold mb-0.5">
{{ trx.ticket_number }}
</span>
{% endif %}
{% if trx.related_unit %}
<div class="text-[11px] text-gray-600 font-medium">Unit: {{ trx.related_unit.unit_code }}</div>
{% endif %}
{% if trx.reference_no %}
<div class="text-[10px] text-gray-400">Ref: {{ trx.reference_no }}</div>
{% endif %}
</td>
<!-- Petugas Pelaksana -->
<td class="py-3 px-4 whitespace-nowrap text-gray-600">
{{ trx.performed_by.username|default:"Sistem" }}
{% if trx.notes %}
<div class="text-[10px] text-gray-400 italic max-w-[150px] truncate" title="{{ trx.notes }}">
"{{ trx.notes }}"
</div>
{% endif %}
</td>
<!-- Aksi Reversal -->
<td class="py-3 px-4 text-center whitespace-nowrap">
{% if not is_read_only and not trx.is_reversed and trx.transaction_type != 'reversal' %}
<button onclick="openModalReversal('{{ trx.id }}', '{{ trx.transaction_code }}')" class="px-2 py-1 text-[10px] font-bold text-red-600 hover:text-white hover:bg-red-600 border border-red-200 rounded-lg transition-colors" title="Balik Transaksi (Reversal)">
Reversal
</button>
{% else %}
<span class="text-gray-300">-</span>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="10" class="py-10 text-center text-gray-400">
Belum ada mutasi transaksi untuk item ini.
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Paginasi -->
{% include 'components/pagination.html' %}
</div>
<!-- ========================================================================= -->
<!-- MODAL: Edit Master Consumable Item -->
<!-- ========================================================================= -->
<div id="modalEditItem" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-gray-50/50">
<div class="flex items-center space-x-2.5">
<div class="w-8 h-8 rounded-lg bg-gray-100 text-gray-700 flex items-center justify-center">
<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="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>
</div>
<div>
<h3 class="font-extrabold text-gray-900 text-base">Edit Data Master: {{ item.item_code }}</h3>
<p class="text-xs text-gray-500">Perbarui informasi metadata, spesifikasi, dan batas stok minimum.</p>
</div>
</div>
<button onclick="closeModalEditItem()" class="text-gray-400 hover:text-gray-600 p-1.5 rounded-lg transition-colors">
<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 'consumable_edit' item.id %}" method="POST" class="flex-1 overflow-y-auto p-6 space-y-4">
{% csrf_token %}
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Nama Barang <span class="text-red-500">*</span>
</label>
<input type="text" name="name" value="{{ item.name }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Kategori <span class="text-red-500">*</span>
</label>
<select name="category" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
{% for cat_val, cat_label in categories %}
<option value="{{ cat_val }}" {% if item.category == cat_val %}selected{% endif %}>{{ cat_label }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Merek / Brand
</label>
<input type="text" name="brand" value="{{ item.brand|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Lokasi Penyimpanan
</label>
<select name="location" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
{% for loc in locations %}
<option value="{{ loc }}" {% if item.location == loc %}selected{% endif %}>{{ loc }}</option>
{% endfor %}
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Spesifikasi Teknis
</label>
<input type="text" name="specification" value="{{ item.specification|default:'' }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci">
</div>
<div class="p-3.5 bg-gray-50/80 rounded-xl border border-gray-200 space-y-3">
<p class="text-xs font-bold text-gray-700 uppercase tracking-wider">Satuan Kuantitas & Konversi</p>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Satuan Dasar (UoM) <span class="text-red-500">*</span>
</label>
<input type="text" name="base_unit" value="{{ item.base_unit }}" required class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Satuan Pembelian
</label>
<input type="text" name="purchase_unit" value="{{ item.purchase_unit|default:'' }}" class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
</div>
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Faktor Konversi
</label>
<input type="number" step="0.01" min="0.01" name="conversion_rate" value="{{ item.conversion_rate }}" class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white font-mono">
</div>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Batas Stok Minimum
</label>
<input type="number" step="0.01" min="0" name="minimum_stock" value="{{ item.minimum_stock }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Harga Beli Terakhir (Rp)
</label>
<input type="number" step="100" min="0" name="last_purchase_price" value="{{ item.last_purchase_price }}" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono">
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan
</label>
<textarea name="notes" rows="2" class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci">{{ item.notes|default:'' }}</textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalEditItem()" class="px-5 py-2.5 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
Batal
</button>
<button type="submit" class="px-6 py-2.5 rounded-xl bg-kerinci text-white text-sm font-bold shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors">
Simpan Perubahan
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: Barang Masuk (Item Ini) -->
<!-- ========================================================================= -->
<div id="modalBarangMasuk" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-lg w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-blue-50/50">
<h3 class="font-extrabold text-gray-900 text-base">Barang Masuk: {{ item.name }}</h3>
<button onclick="closeModalBarangMasuk()" class="text-gray-400 hover:text-gray-600 p-1 rounded-lg">
<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 'consumable_in' %}" method="POST" class="p-6 space-y-4">
{% csrf_token %}
<input type="hidden" name="item_id" value="{{ item.id }}">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Jumlah Masuk <span class="text-red-500">*</span>
</label>
<input type="number" step="0.01" min="0.01" name="quantity" required placeholder="0.00" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 font-mono font-bold">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Satuan
</label>
<select name="unit_type" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
<option value="base">Satuan Dasar ({{ item.base_unit }})</option>
{% if item.purchase_unit %}
<option value="purchase">Satuan Beli ({{ item.purchase_unit }} = {{ item.conversion_rate|floatformat:0 }} {{ item.base_unit }})</option>
{% endif %}
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Sumber
</label>
<select name="source_destination" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
<option value="Pembelian / Restock">Pembelian / Restock</option>
<option value="Pengembalian Sisa Teknisi">Pengembalian Sisa Teknisi</option>
<option value="Transfer Antar Gudang">Transfer Antar Gudang</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Penerimaan <span class="text-red-500">*</span>
</label>
<input type="date" name="transaction_date" value="{{ today_date }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Supplier / Vendor
</label>
<input type="text" name="supplier" placeholder="Nama toko / vendor" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
No. PO / BAST
</label>
<input type="text" name="reference_no" placeholder="PO-2026-..." class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600">
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan
</label>
<textarea name="notes" rows="2" class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalBarangMasuk()" class="px-5 py-2 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50">
Batal
</button>
<button type="submit" class="px-6 py-2 rounded-xl bg-blue-600 text-white text-sm font-bold shadow-sm hover:bg-blue-700">
Posting Masuk
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: Barang Keluar (Item Ini) -->
<!-- ========================================================================= -->
<div id="modalBarangKeluar" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-lg w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-amber-50/50">
<h3 class="font-extrabold text-gray-900 text-base">Barang Keluar: {{ item.name }}</h3>
<button onclick="closeModalBarangKeluar()" class="text-gray-400 hover:text-gray-600 p-1 rounded-lg">
<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 'consumable_out' %}" method="POST" class="p-6 space-y-4">
{% csrf_token %}
<input type="hidden" name="item_id" value="{{ item.id }}">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Jumlah Keluar <span class="text-red-500">*</span>
</label>
<input type="number" step="0.01" min="0.01" max="{{ item.stock_available }}" name="quantity" required placeholder="0.00" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 font-mono font-bold">
<span class="text-[10px] text-gray-400">Tersedia: {{ item.formatted_stock }}</span>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Satuan
</label>
<select name="unit_type" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="base">Satuan Dasar ({{ item.base_unit }})</option>
{% if item.purchase_unit %}
<option value="purchase">Satuan Beli ({{ item.purchase_unit }})</option>
{% endif %}
</select>
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Teknisi Penerima <span class="text-red-500">*</span>
</label>
<select name="recipient_employee" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="">-- Pilih Karyawan --</option>
{% for emp in employees %}
<option value="{{ emp.id }}">{{ emp.nik }} - {{ emp.name }}</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Pemakaian <span class="text-red-500">*</span>
</label>
<input type="date" name="transaction_date" value="{{ today_date }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
No. Tiket / Work Order
</label>
<input type="text" name="ticket_number" placeholder="WO-2026-..." class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Unit Aset Terkait
</label>
<select name="related_unit" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="">-- Opsional --</option>
{% for unt in units %}
<option value="{{ unt.id }}">{{ unt.unit_code }} - {{ unt.asset.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tujuan / Area Penggunaan <span class="text-red-500">*</span>
</label>
<input type="text" name="source_destination" required placeholder="Contoh: Maintenance Switch Ruang Kontrol" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan
</label>
<textarea name="notes" rows="2" class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalBarangKeluar()" class="px-5 py-2 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50">
Batal
</button>
<button type="submit" class="px-6 py-2 rounded-xl bg-amber-600 text-white text-sm font-bold shadow-sm hover:bg-amber-700">
Posting Keluar
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL: Reversal Transaksi -->
<!-- ========================================================================= -->
<div id="modalReversal" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-md w-full overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-red-50/50">
<h3 class="font-extrabold text-red-900 text-base">Reversal Transaksi</h3>
<button onclick="closeModalReversal()" class="text-gray-400 hover:text-gray-600 p-1 rounded-lg">
<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="reversalForm" method="POST" action="" class="p-6 space-y-4">
{% csrf_token %}
<p class="text-xs text-gray-600">
Anda akan membalik transaksi <b id="reversal_trx_code" class="font-mono text-gray-900"></b>. Saldo stok item akan disesuaikan kembali secara otomatis.
</p>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Alasan Pembatalan / Reversal <span class="text-red-500">*</span>
</label>
<textarea name="reversal_reason" rows="3" required placeholder="Jelaskan alasan pembalikan transaksi ini (misal: salah input kuantitas, duplikasi entri)..." class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-red-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalReversal()" class="px-5 py-2 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50">
Batal
</button>
<button type="submit" class="px-6 py-2 rounded-xl bg-red-600 text-white text-sm font-bold shadow-sm hover:bg-red-700">
Eksekusi Reversal
</button>
</div>
</form>
</div>
</div>
<script>
function openModalEditItem() {
document.getElementById('modalEditItem').classList.remove('hidden');
}
function closeModalEditItem() {
document.getElementById('modalEditItem').classList.add('hidden');
}
function openModalBarangMasuk() {
document.getElementById('modalBarangMasuk').classList.remove('hidden');
}
function closeModalBarangMasuk() {
document.getElementById('modalBarangMasuk').classList.add('hidden');
}
function openModalBarangKeluar() {
document.getElementById('modalBarangKeluar').classList.remove('hidden');
}
function closeModalBarangKeluar() {
document.getElementById('modalBarangKeluar').classList.add('hidden');
}
function openModalReversal(trxId, trxCode) {
document.getElementById('reversal_trx_code').textContent = trxCode;
document.getElementById('reversalForm').action = "/consumable/transaction/" + trxId + "/reverse/";
document.getElementById('modalReversal').classList.remove('hidden');
}
function closeModalReversal() {
document.getElementById('modalReversal').classList.add('hidden');
}
</script>
{% endblock %}
+905
View File
@@ -0,0 +1,905 @@
{% extends 'base.html' %}
{% block page_title %}Consumable Item & Persediaan IT{% endblock %}
{% block page_title_guide %}Panduan Modul Consumable Item{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Modul <b>Consumable Item</b> dirancang khusus untuk mengelola logistik barang habis pakai yang digunakan oleh tim IT Network & Security serta Technical Support PT. Kerinci Hydropower.</p>
<div class="p-3 bg-emerald-50 border border-emerald-200 rounded-xl">
<h4 class="font-bold text-emerald-800 text-xs uppercase tracking-wider mb-1">Prinsip Audit & Integritas Stok</h4>
<p class="text-xs text-emerald-700">Saldo stok tidak dapat diedit sembarangan. Setiap perubahan stok dicatat secara mutlak melalui transaksi atomik: <b>Barang Masuk</b>, <b>Barang Keluar</b>, atau <b>Stock Opname</b> pada buku besar transaksi (stock ledger).</p>
</div>
<ul class="list-disc pl-5 space-y-1 text-xs text-gray-600">
<li><b>Barang Masuk:</b> Mencatat penambahan stok dari pengadaan/pembelian, transfer, atau retur sisa teknisi.</li>
<li><b>Barang Keluar:</b> Mencatat konsumsi material oleh teknisi dengan keterkaitan ke tiket support, work order, atau unit aset terkait.</li>
<li><b>Stock Opname:</b> Penyesuaian fisik berkala dengan alasan audit yang wajib diisi.</li>
</ul>
</div>
{% endblock %}
{% block content %}
<!-- Top Header & Action Buttons -->
<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 &bull; Logistik Habis Pakai</p>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-extrabold text-gray-900">Consumable Item</h2>
<span class="px-2.5 py-0.5 rounded-full text-xs font-extrabold bg-emerald-50 text-emerald-700 border border-emerald-200">
Network & Support
</span>
<button onclick="openGuideModal()" class="text-gray-400 hover:text-kerinci p-1 rounded-lg hover:bg-gray-100 transition-colors" title="Buka Panduan Modul">
<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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</button>
</div>
<p class="text-xs text-gray-500 mt-1">Pengelolaan persediaan kabel, konektor RJ45, thermal paste, cable ties, fastener, dan perlengkapan teknisi IT.</p>
</div>
<!-- Quick Action Buttons -->
<div class="flex flex-wrap items-center gap-2 w-full sm:w-auto">
{% if not is_read_only %}
<button onclick="openModalBarangMasuk()" class="bg-blue-600 text-white px-3.5 py-2.5 rounded-xl text-xs font-bold shadow-sm shadow-blue-500/20 hover:bg-blue-700 transition-colors flex items-center space-x-1.5">
<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 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg>
<span>Barang Masuk</span>
</button>
<button onclick="openModalBarangKeluar()" class="bg-amber-600 text-white px-3.5 py-2.5 rounded-xl text-xs font-bold shadow-sm shadow-amber-500/20 hover:bg-amber-700 transition-colors flex items-center space-x-1.5">
<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 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
<span>Barang Keluar</span>
</button>
<button onclick="openModalOpname()" class="bg-purple-600 text-white px-3.5 py-2.5 rounded-xl text-xs font-bold shadow-sm shadow-purple-500/20 hover:bg-purple-700 transition-colors flex items-center space-x-1.5">
<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="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path></svg>
<span>Stock Opname</span>
</button>
<button onclick="openCreateItemModal()" class="bg-kerinci text-white px-4 py-2.5 rounded-xl text-xs font-bold shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors flex items-center space-x-1.5">
<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 4v16m8-8H4"></path></svg>
<span>+ Tambah Item</span>
</button>
{% endif %}
<!-- Export Dropdown / Buttons -->
<div class="flex items-center space-x-1 pl-1">
<a href="{% url 'consumable_export_excel' %}?q={{ search_query }}&category={{ category_filter }}&status={{ status_filter }}" class="p-2.5 rounded-xl border border-gray-200 bg-white hover:bg-gray-50 text-emerald-700 transition-colors shadow-sm" title="Ekspor Excel">
<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>
</a>
<a href="{% url 'consumable_export_pdf' %}?q={{ search_query }}&category={{ category_filter }}&status={{ status_filter }}" target="_blank" class="p-2.5 rounded-xl border border-gray-200 bg-white hover:bg-gray-50 text-red-600 transition-colors shadow-sm" title="Ekspor PDF">
<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="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>
</a>
</div>
</div>
</div>
<!-- KPI Summary Cards -->
<div class="grid grid-cols-2 lg:grid-cols-5 gap-3.5 mb-6">
<!-- Total Jenis Item -->
<div class="bg-white p-4 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-[11px] font-bold text-gray-400 uppercase tracking-wider mb-0.5">Total Jenis</p>
<h3 class="text-2xl font-black text-gray-900">{{ counts.total }}</h3>
<p class="text-[10px] text-gray-400">Item Terdaftar</p>
</div>
<div class="w-10 h-10 bg-emerald-50 text-kerinci rounded-xl flex items-center justify-center font-bold">
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
</div>
</div>
<!-- Akumulasi Stok Fisik -->
<div class="bg-white p-4 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-[11px] font-bold text-blue-600 uppercase tracking-wider mb-0.5" title="Jumlah agregat kuantitas seluruh item">Akumulasi Stok</p>
<h3 class="text-2xl font-black text-blue-900">{{ counts.total_qty|floatformat:0 }}</h3>
<p class="text-[10px] text-blue-500" title="Agregat lintas satuan (pcs, meter, roll, dsb)">*Agregat kuantitas</p>
</div>
<div class="w-10 h-10 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center font-bold">
<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="M7 12l3-3 3 3 4-4M8 21l4-4 4 4M3 4h18M4 4h16v12a1 1 0 01-1 1H5a1 1 0 01-1-1V4z"></path></svg>
</div>
</div>
<!-- Stok Tersedia Aman -->
<div class="bg-white p-4 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-[11px] font-bold text-emerald-600 uppercase tracking-wider mb-0.5">Stok Normal</p>
<h3 class="text-2xl font-black text-emerald-900">{{ counts.available }}</h3>
<p class="text-[10px] text-emerald-500">Di atas batas min</p>
</div>
<div class="w-10 h-10 bg-emerald-50 text-emerald-600 rounded-xl flex items-center justify-center font-bold">
<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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
</div>
<!-- Stok Menipis -->
<div class="bg-white p-4 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between">
<div>
<p class="text-[11px] font-bold text-amber-600 uppercase tracking-wider mb-0.5">Stok Menipis</p>
<h3 class="text-2xl font-black text-amber-900">{{ counts.low_stock }}</h3>
<p class="text-[10px] text-amber-500">Perlu reorder</p>
</div>
<div class="w-10 h-10 bg-amber-50 text-amber-600 rounded-xl flex items-center justify-center font-bold">
<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 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>
</div>
<!-- Stok Habis -->
<div class="bg-white p-4 rounded-2xl border border-gray-100 shadow-sm flex items-center justify-between col-span-2 lg:col-span-1">
<div>
<p class="text-[11px] font-bold text-red-600 uppercase tracking-wider mb-0.5">Stok Habis</p>
<h3 class="text-2xl font-black text-red-900">{{ counts.out_of_stock }}</h3>
<p class="text-[10px] text-red-500">Saldo 0</p>
</div>
<div class="w-10 h-10 bg-red-50 text-red-600 rounded-xl flex items-center justify-center font-bold">
<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="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>
</div>
</div>
</div>
<!-- Status Tabs -->
<div class="flex space-x-2 mb-4 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
<a href="?status={% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}{% if location_filter %}&location={{ location_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if not status_filter %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Semua Item
<span class="ml-2 {% if not status_filter %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.total }}</span>
</a>
<a href="?status=available{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}{% if location_filter %}&location={{ location_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'available' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Stok Aman
<span class="ml-2 {% if status_filter == 'available' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.available }}</span>
</a>
<a href="?status=low_stock{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}{% if location_filter %}&location={{ location_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'low_stock' %}border-amber-600 text-amber-600{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Stok Menipis
<span class="ml-2 {% if status_filter == 'low_stock' %}bg-amber-100 text-amber-700{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.low_stock }}</span>
</a>
<a href="?status=out_of_stock{% if search_query %}&q={{ search_query }}{% endif %}{% if category_filter %}&category={{ category_filter }}{% endif %}{% if location_filter %}&location={{ location_filter }}{% endif %}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if status_filter == 'out_of_stock' %}border-red-600 text-red-600{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Stok Habis
<span class="ml-2 {% if status_filter == 'out_of_stock' %}bg-red-100 text-red-700{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.out_of_stock }}</span>
</a>
</div>
<!-- Filters & Search Bar -->
<div class="mb-5 flex flex-col md:flex-row md:items-center justify-between gap-3">
<form id="filterForm" method="GET" class="flex flex-wrap items-center gap-2 w-full">
<input type="hidden" name="status" value="{{ status_filter }}">
<div class="relative flex-1 min-w-[240px]">
<input type="text" name="q" value="{{ search_query }}" placeholder="Cari kode barang, nama, merek, spesifikasi, lokasi..." 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>
</div>
<select name="category" onchange="this.form.submit()" class="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 text-gray-700 shadow-sm">
<option value="">Semua Kategori</option>
{% for cat_val, cat_label in categories %}
<option value="{{ cat_val }}" {% if category_filter == cat_val %}selected{% endif %}>{{ cat_label }}</option>
{% endfor %}
</select>
<select name="location" onchange="this.form.submit()" class="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 text-gray-700 shadow-sm">
<option value="">Semua Lokasi</option>
{% for loc in locations %}
<option value="{{ loc }}" {% if location_filter == loc %}selected{% endif %}>{{ loc }}</option>
{% endfor %}
</select>
{% if search_query or category_filter or location_filter or status_filter %}
<a href="{% url 'consumable_list' %}" class="px-3.5 py-2.5 text-xs font-bold text-gray-500 hover:text-red-500 border border-gray-200 hover:border-red-200 rounded-xl bg-white transition-colors" title="Reset Semua Filter">
Reset
</a>
{% endif %}
</form>
</div>
<!-- Consumable Item Table Card -->
<div class="bg-white rounded-2xl shadow-sm border border-gray-200 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-left border-collapse min-w-[900px]">
<thead>
<tr class="bg-gray-50/75 border-b border-gray-200 text-[11px] font-bold text-gray-500 uppercase tracking-wider">
<th class="py-3.5 px-4">Kode Item</th>
<th class="py-3.5 px-4">Nama Barang & Merek</th>
<th class="py-3.5 px-4">Kategori</th>
<th class="py-3.5 px-4">Spesifikasi</th>
<th class="py-3.5 px-4 text-center">Satuan</th>
<th class="py-3.5 px-4 text-right">Stok Tersedia</th>
<th class="py-3.5 px-4 text-right">Stok Min</th>
<th class="py-3.5 px-4">Lokasi</th>
<th class="py-3.5 px-4 text-center">Status</th>
<th class="py-3.5 px-4 text-center">Aksi</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100 text-sm">
{% for item in page_obj %}
<tr class="hover:bg-gray-50/80 transition-colors">
<!-- Kode Item -->
<td class="py-3.5 px-4 whitespace-nowrap">
<a href="{% url 'consumable_detail' item.id %}" class="font-mono text-xs font-bold text-kerinci hover:underline">
{{ item.item_code }}
</a>
</td>
<!-- Nama Barang & Merek -->
<td class="py-3.5 px-4">
<div class="font-bold text-gray-900 leading-snug">
<a href="{% url 'consumable_detail' item.id %}" class="hover:text-kerinci">
{{ item.name }}
</a>
</div>
{% if item.brand %}
<div class="text-[11px] text-gray-400 font-medium">Merek: {{ item.brand }}</div>
{% endif %}
</td>
<!-- Kategori -->
<td class="py-3.5 px-4 whitespace-nowrap">
<span class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-medium bg-gray-100 text-gray-700">
{{ item.get_category_display|truncatewords:2 }}
</span>
</td>
<!-- Spesifikasi -->
<td class="py-3.5 px-4 text-xs text-gray-600 max-w-[220px]">
<span class="line-clamp-2" title="{{ item.specification }}">{{ item.specification|default:"-" }}</span>
</td>
<!-- Satuan & Konversi -->
<td class="py-3.5 px-4 text-center whitespace-nowrap">
<span class="font-semibold text-gray-700 text-xs">{{ item.base_unit }}</span>
{% if item.purchase_unit %}
<div class="text-[10px] text-gray-400" title="1 {{ item.purchase_unit }} = {{ item.conversion_rate }} {{ item.base_unit }}">
1 {{ item.purchase_unit }} = {{ item.conversion_rate|floatformat:0 }} {{ item.base_unit }}
</div>
{% endif %}
</td>
<!-- Stok Tersedia -->
<td class="py-3.5 px-4 text-right whitespace-nowrap">
<span class="text-base font-extrabold {% if item.stock_status == 'out_of_stock' %}text-red-600{% elif item.stock_status == 'low_stock' %}text-amber-600{% else %}text-emerald-700{% endif %}">
{{ item.formatted_stock }}
</span>
</td>
<!-- Stok Minimum -->
<td class="py-3.5 px-4 text-right whitespace-nowrap text-xs text-gray-500 font-medium">
{{ item.formatted_minimum_stock }}
</td>
<!-- Lokasi -->
<td class="py-3.5 px-4 whitespace-nowrap text-xs text-gray-600">
<span class="inline-flex items-center gap-1">
<svg class="w-3.5 h-3.5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path></svg>
{{ item.location }}
</span>
</td>
<!-- Status Stok Badge -->
<td class="py-3.5 px-4 text-center whitespace-nowrap">
{% if item.stock_status == 'out_of_stock' %}
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-red-100 text-red-700 border border-red-200">
<span class="w-1.5 h-1.5 rounded-full bg-red-500 mr-1.5"></span>
Habis
</span>
{% elif item.stock_status == 'low_stock' %}
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-amber-100 text-amber-800 border border-amber-200">
<span class="w-1.5 h-1.5 rounded-full bg-amber-500 mr-1.5"></span>
Menipis
</span>
{% else %}
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-emerald-100 text-emerald-800 border border-emerald-200">
<span class="w-1.5 h-1.5 rounded-full bg-emerald-500 mr-1.5"></span>
Tersedia
</span>
{% endif %}
</td>
<!-- Aksi -->
<td class="py-3.5 px-4 text-center whitespace-nowrap">
<div class="flex items-center justify-center space-x-1.5">
<a href="{% url 'consumable_detail' item.id %}" class="p-1.5 text-gray-500 hover:text-kerinci hover:bg-gray-100 rounded-lg transition-colors" title="Buku Besar & Riwayat Lengkap">
<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="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>
</a>
{% if not is_read_only %}
<button onclick="openModalBarangMasukItem('{{ item.id }}', '{{ item.name|escapejs }}', '{{ item.base_unit }}', '{{ item.purchase_unit|default:'' }}')" class="p-1.5 text-blue-600 hover:text-blue-800 hover:bg-blue-50 rounded-lg transition-colors" title="Tambah Stok (Barang Masuk)">
<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 4v16m8-8H4"></path></svg>
</button>
<button onclick="openModalBarangKeluarItem('{{ item.id }}', '{{ item.name|escapejs }}', '{{ item.base_unit }}', '{{ item.stock_available }}')" class="p-1.5 text-amber-600 hover:text-amber-800 hover:bg-amber-50 rounded-lg transition-colors" title="Gunakan / Keluarkan Barang">
<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="M20 12H4"></path></svg>
</button>
{% endif %}
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="10" class="py-12 text-center text-gray-500">
<div class="flex flex-col items-center justify-center">
<div class="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center text-gray-400 mb-3">
<svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
</div>
<h4 class="text-base font-bold text-gray-800">Tidak ada consumable item ditemukan</h4>
<p class="text-xs text-gray-400 mt-1 max-w-sm">
{% if search_query or category_filter or location_filter or status_filter %}
Tidak ada data yang cocok dengan kriteria pencarian atau filter yang diterapkan.
{% else %}
Belum ada data barang habis pakai. Klik tombol "+ Tambah Item" di atas untuk mendaftarkan barang baru.
{% endif %}
</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Paginasi -->
{% include 'components/pagination.html' %}
</div>
<!-- ========================================================================= -->
<!-- MODAL 1: Tambah Consumable Item Baru -->
<!-- ========================================================================= -->
<div id="modalCreateItem" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-2xl w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-gray-50/50">
<div class="flex items-center space-x-2.5">
<div class="w-8 h-8 rounded-lg bg-emerald-50 text-kerinci flex items-center justify-center">
<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>
<h3 class="font-extrabold text-gray-900 text-base">Tambah Consumable Item Baru</h3>
<p class="text-xs text-gray-500">Daftarkan jenis barang habis pakai ke katalog master persediaan.</p>
</div>
</div>
<button onclick="closeCreateItemModal()" class="text-gray-400 hover:text-gray-600 p-1.5 rounded-lg transition-colors">
<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 'consumable_create' %}" method="POST" class="flex-1 overflow-y-auto p-6 space-y-4">
{% csrf_token %}
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<!-- Kode Barang -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Kode Barang <span class="text-gray-400 font-normal text-[10px]">(Opsional - auto-generated)</span>
</label>
<input type="text" name="item_code" placeholder="Misal: CNS-CAB-001" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci uppercase font-mono">
</div>
<!-- Kategori -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Kategori <span class="text-red-500">*</span>
</label>
<select name="category" required class="w-full px-3.5 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">
{% for cat_val, cat_label in categories %}
<option value="{{ cat_val }}">{{ cat_label }}</option>
{% endfor %}
</select>
</div>
</div>
<!-- Nama Barang & Merek -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Nama Barang <span class="text-red-500">*</span>
</label>
<input type="text" name="name" required placeholder="Contoh: Kabel UTP Cat6, Konektor RJ45" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Merek / Brand
</label>
<input type="text" name="brand" placeholder="Contoh: Belden, CommScope, Arctic, 3M" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci">
</div>
</div>
<!-- Spesifikasi Teknis -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Spesifikasi Teknis
</label>
<input type="text" name="specification" placeholder="Contoh: UTP Cat6 24AWG Solid Copper, Thermal Paste 5g 8.5W/mK" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci">
</div>
<!-- Satuan & Konversi -->
<div class="p-3.5 bg-gray-50/80 rounded-xl border border-gray-200 space-y-3">
<p class="text-xs font-bold text-gray-700 uppercase tracking-wider">Satuan Kuantitas & Konversi</p>
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Satuan Dasar (UoM) <span class="text-red-500">*</span>
</label>
<input type="text" name="base_unit" required placeholder="pcs, meter, tube, roll" class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<span class="text-[10px] text-gray-400">Satuan terkecil pemakaian</span>
</div>
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Satuan Pembelian
</label>
<input type="text" name="purchase_unit" placeholder="roll, box, pack, tube" class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
<span class="text-[10px] text-gray-400">Satuan saat order/beli</span>
</div>
<div>
<label class="block text-[11px] font-semibold text-gray-600 mb-1">
Faktor Konversi
</label>
<input type="number" step="0.01" min="0.01" name="conversion_rate" value="1.00" class="w-full px-3 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white font-mono">
<span class="text-[10px] text-gray-400">1 Beli = X Satuan Dasar</span>
</div>
</div>
</div>
<!-- Stok & Lokasi -->
<div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Stok Awal Fisik
</label>
<input type="number" step="0.01" min="0" name="initial_stock" value="0" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono">
<span class="text-[10px] text-gray-400">Dicatat terotorisasi ke buku besar</span>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Batas Stok Minimum
</label>
<input type="number" step="0.01" min="0" name="minimum_stock" value="10" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono">
<span class="text-[10px] text-gray-400">Ambang batas peringatan</span>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Lokasi Penyimpanan
</label>
<select name="location" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci bg-white">
{% for loc in locations %}
<option value="{{ loc }}" {% if loc == 'Gudang Induk (GI)' %}selected{% endif %}>{{ loc }}</option>
{% endfor %}
</select>
</div>
</div>
<!-- Estimasi Harga Beli & Catatan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Estimasi Harga Beli Satuan (Rp)
</label>
<input type="number" step="100" min="0" name="last_purchase_price" value="0" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci font-mono">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan Tambahan
</label>
<input type="text" name="notes" placeholder="Keterangan peruntukan, rak, vendor langganan" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci">
</div>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeCreateItemModal()" class="px-5 py-2.5 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
Batal
</button>
<button type="submit" class="px-6 py-2.5 rounded-xl bg-kerinci text-white text-sm font-bold shadow-sm shadow-kerinci/30 hover:bg-kerinci/90 transition-colors">
Simpan Master Item
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL 2: Transaksi Barang Masuk -->
<!-- ========================================================================= -->
<div id="modalBarangMasuk" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-xl w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-blue-50/50">
<div class="flex items-center space-x-2.5">
<div class="w-8 h-8 rounded-lg bg-blue-100 text-blue-700 flex items-center justify-center">
<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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg>
</div>
<div>
<h3 class="font-extrabold text-gray-900 text-base">Penerimaan Barang Masuk</h3>
<p class="text-xs text-gray-500">Mencatat penambahan stok dari pengadaan, restock, atau retur.</p>
</div>
</div>
<button onclick="closeModalBarangMasuk()" class="text-gray-400 hover:text-gray-600 p-1.5 rounded-lg transition-colors">
<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 'consumable_in' %}" method="POST" class="flex-1 overflow-y-auto p-6 space-y-4">
{% csrf_token %}
<!-- Pilih Item -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Pilih Item Consumable <span class="text-red-500">*</span>
</label>
<select id="in_item_select" name="item_id" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
<option value="">-- Pilih Barang --</option>
{% for itm in selectable_items %}
<option value="{{ itm.id }}" data-base="{{ itm.base_unit }}" data-purchase="{{ itm.purchase_unit|default:'' }}" data-conv="{{ itm.conversion_rate }}">
{{ itm.item_code }} - {{ itm.name }} (Stok saat ini: {{ itm.formatted_stock }})
</option>
{% endfor %}
</select>
</div>
<!-- Jumlah & Pilihan Satuan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Jumlah Masuk <span class="text-red-500">*</span>
</label>
<input type="number" step="0.01" min="0.01" name="quantity" required placeholder="0.00" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 font-mono font-bold">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Satuan Transaksi
</label>
<select id="in_unit_type" name="unit_type" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
<option value="base">Satuan Dasar</option>
<option value="purchase">Satuan Pembelian (Jika ada)</option>
</select>
</div>
</div>
<!-- Sumber & Tanggal -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Sumber Barang
</label>
<select name="source_destination" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
<option value="Pembelian / Pengadaan Baru">Pembelian / Pengadaan Baru</option>
<option value="Pengembalian Sisa Proyek">Pengembalian Sisa Proyek / Teknisi</option>
<option value="Transfer Antar Gudang">Transfer Antar Gudang</option>
<option value="Hibah / Suplai Kantor Pusat">Hibah / Suplai Kantor Pusat</option>
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Penerimaan <span class="text-red-500">*</span>
</label>
<input type="date" name="transaction_date" value="{{ today_date }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
</div>
</div>
<!-- Supplier & Referensi -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Vendor / Supplier
</label>
<input type="text" name="supplier" placeholder="Nama toko / distributor" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
No. Referensi / PO / Faktur
</label>
<input type="text" name="reference_no" placeholder="PO-2026-..., BAST-..." class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600">
</div>
</div>
<!-- Batch / Lot & Expiry Date -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Nomor Batch / Lot
</label>
<input type="text" name="batch_lot" placeholder="Opsional" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Kedaluwarsa
</label>
<input type="date" name="expiry_date" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600 bg-white">
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan
</label>
<textarea name="notes" rows="2" placeholder="Keterangan tambahan barang masuk..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-blue-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalBarangMasuk()" class="px-5 py-2.5 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
Batal
</button>
<button type="submit" class="px-6 py-2.5 rounded-xl bg-blue-600 text-white text-sm font-bold shadow-sm shadow-blue-500/20 hover:bg-blue-700 transition-colors">
Posting Barang Masuk
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL 3: Transaksi Barang Keluar (Pemakaian Teknisi) -->
<!-- ========================================================================= -->
<div id="modalBarangKeluar" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-xl w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-amber-50/50">
<div class="flex items-center space-x-2.5">
<div class="w-8 h-8 rounded-lg bg-amber-100 text-amber-700 flex items-center justify-center">
<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="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
</div>
<div>
<h3 class="font-extrabold text-gray-900 text-base">Pengeluaran Barang (Pemakaian)</h3>
<p class="text-xs text-gray-500">Mencatat konsumsi material untuk pekerjaan teknis IT.</p>
</div>
</div>
<button onclick="closeModalBarangKeluar()" class="text-gray-400 hover:text-gray-600 p-1.5 rounded-lg transition-colors">
<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 'consumable_out' %}" method="POST" class="flex-1 overflow-y-auto p-6 space-y-4">
{% csrf_token %}
<!-- Pilih Item -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Pilih Item Consumable <span class="text-red-500">*</span>
</label>
<select id="out_item_select" name="item_id" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="">-- Pilih Barang --</option>
{% for itm in selectable_items %}
<option value="{{ itm.id }}" data-stock="{{ itm.stock_available }}" data-base="{{ itm.base_unit }}">
{{ itm.item_code }} - {{ itm.name }} (Stok: {{ itm.formatted_stock }})
</option>
{% endfor %}
</select>
</div>
<!-- Jumlah & Satuan -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Jumlah Dikeluarkan <span class="text-red-500">*</span>
</label>
<input type="number" step="0.01" min="0.01" name="quantity" required placeholder="0.00" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 font-mono font-bold">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Satuan Pemakaian
</label>
<select name="unit_type" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="base">Satuan Dasar</option>
<option value="purchase">Satuan Pembelian</option>
</select>
</div>
</div>
<!-- Teknisi Penerima & Tanggal -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Teknisi / Karyawan Penerima <span class="text-red-500">*</span>
</label>
<select name="recipient_employee" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="">-- Pilih Teknisi --</option>
{% for emp in employees %}
<option value="{{ emp.id }}">{{ emp.nik }} - {{ emp.name }} ({{ emp.position|default:"Staff" }})</option>
{% endfor %}
</select>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Pemakaian <span class="text-red-500">*</span>
</label>
<input type="date" name="transaction_date" value="{{ today_date }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
</div>
</div>
<!-- Tiket & Unit Aset Terkait -->
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
No. Tiket Support / Work Order
</label>
<input type="text" name="ticket_number" placeholder="WO-2026-..., TIKET-IT-..." class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Unit Aset Terkait <span class="text-gray-400 font-normal text-[10px]">(Jika maintenance aset)</span>
</label>
<select name="related_unit" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600 bg-white">
<option value="">-- Tidak Terikat Unit Tertentu --</option>
{% for unt in units %}
<option value="{{ unt.id }}">{{ unt.unit_code }} - {{ unt.asset.name }}</option>
{% endfor %}
</select>
</div>
</div>
<!-- Peruntukan / Area Pekerjaan -->
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tujuan / Area Penggunaan <span class="text-red-500">*</span>
</label>
<input type="text" name="source_destination" required placeholder="Contoh: Instalasi Titik LAN Adit 1, Repasting Server DB, Terminasi Patch Cord" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Catatan
</label>
<textarea name="notes" rows="2" placeholder="Keterangan tambahan penggunaan..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalBarangKeluar()" class="px-5 py-2.5 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
Batal
</button>
<button type="submit" class="px-6 py-2.5 rounded-xl bg-amber-600 text-white text-sm font-bold shadow-sm shadow-amber-500/20 hover:bg-amber-700 transition-colors">
Posting Barang Keluar
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- MODAL 4: Stock Opname / Penyesuaian Fisik -->
<!-- ========================================================================= -->
<div id="modalOpname" class="fixed inset-0 z-50 hidden overflow-y-auto bg-gray-900/50 backdrop-blur-sm flex items-center justify-center p-4">
<div class="bg-white rounded-2xl shadow-xl max-w-lg w-full max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
<div class="px-6 py-4 border-b border-gray-100 flex items-center justify-between bg-purple-50/50">
<div class="flex items-center space-x-2.5">
<div class="w-8 h-8 rounded-lg bg-purple-100 text-purple-700 flex items-center justify-center">
<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="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path></svg>
</div>
<div>
<h3 class="font-extrabold text-gray-900 text-base">Stock Opname & Penyesuaian</h3>
<p class="text-xs text-gray-500">Sesuaikan saldo sistem dengan perhitungan fisik aktual di gudang.</p>
</div>
</div>
<button onclick="closeModalOpname()" class="text-gray-400 hover:text-gray-600 p-1.5 rounded-lg transition-colors">
<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 'consumable_adjust' %}" method="POST" class="flex-1 overflow-y-auto p-6 space-y-4">
{% csrf_token %}
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Pilih Item Consumable <span class="text-red-500">*</span>
</label>
<select id="opname_item_select" name="item_id" required onchange="updateOpnameSystemStock(this)" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-purple-600 bg-white">
<option value="">-- Pilih Barang --</option>
{% for itm in selectable_items %}
<option value="{{ itm.id }}" data-stock="{{ itm.stock_available }}" data-base="{{ itm.base_unit }}">
{{ itm.item_code }} - {{ itm.name }} (Stok Sistem: {{ itm.formatted_stock }})
</option>
{% endfor %}
</select>
</div>
<!-- Panel Selisih Real-time -->
<div class="grid grid-cols-2 gap-3 p-3 bg-gray-50 rounded-xl border border-gray-200">
<div>
<p class="text-[10px] font-bold text-gray-400 uppercase">Stok Sistem Saat Ini</p>
<p id="opname_sys_stock" class="text-lg font-black text-gray-800">0</p>
</div>
<div>
<p class="text-[10px] font-bold text-gray-400 uppercase">Selisih (+/-)</p>
<p id="opname_diff_display" class="text-lg font-black text-gray-500">0</p>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Stok Fisik Aktual <span class="text-red-500">*</span>
</label>
<input type="number" id="opname_actual_input" step="0.01" min="0" name="actual_stock" required oninput="calculateOpnameDiff()" placeholder="0.00" class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-purple-600 font-mono font-bold">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Tanggal Opname <span class="text-red-500">*</span>
</label>
<input type="date" name="transaction_date" value="{{ today_date }}" required class="w-full px-3.5 py-2.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-purple-600 bg-white">
</div>
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-1">
Alasan Penyesuaian <span class="text-red-500">*</span>
</label>
<textarea name="reason" rows="3" required placeholder="Contoh: Hasil audit opname fisik akhir bulan; 2 pcs konektor rusak pecah dipisahkan..." class="w-full px-3.5 py-2 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-purple-600"></textarea>
</div>
<div class="pt-4 border-t border-gray-100 flex items-center justify-end space-x-3">
<button type="button" onclick="closeModalOpname()" class="px-5 py-2.5 rounded-xl border border-gray-200 text-sm font-bold text-gray-600 hover:bg-gray-50 transition-colors">
Batal
</button>
<button type="submit" class="px-6 py-2.5 rounded-xl bg-purple-600 text-white text-sm font-bold shadow-sm shadow-purple-500/20 hover:bg-purple-700 transition-colors">
Posting Penyesuaian
</button>
</div>
</form>
</div>
</div>
<!-- ========================================================================= -->
<!-- JAVASCRIPT MODAL HANDLERS -->
<!-- ========================================================================= -->
<script>
// Create Modal
function openCreateItemModal() {
document.getElementById('modalCreateItem').classList.remove('hidden');
}
function closeCreateItemModal() {
document.getElementById('modalCreateItem').classList.add('hidden');
}
// In Modal
function openModalBarangMasuk() {
document.getElementById('modalBarangMasuk').classList.remove('hidden');
}
function closeModalBarangMasuk() {
document.getElementById('modalBarangMasuk').classList.add('hidden');
}
function openModalBarangMasukItem(id, name, base, purchase) {
openModalBarangMasuk();
const select = document.getElementById('in_item_select');
select.value = id;
}
// Out Modal
function openModalBarangKeluar() {
document.getElementById('modalBarangKeluar').classList.remove('hidden');
}
function closeModalBarangKeluar() {
document.getElementById('modalBarangKeluar').classList.add('hidden');
}
function openModalBarangKeluarItem(id, name, base, stock) {
openModalBarangKeluar();
const select = document.getElementById('out_item_select');
select.value = id;
}
// Opname Modal
function openModalOpname() {
document.getElementById('modalOpname').classList.remove('hidden');
}
function closeModalOpname() {
document.getElementById('modalOpname').classList.add('hidden');
}
let currentOpnameStock = 0;
function updateOpnameSystemStock(select) {
const option = select.options[select.selectedIndex];
if (option && option.dataset.stock) {
currentOpnameStock = parseFloat(option.dataset.stock) || 0;
const baseUnit = option.dataset.base || '';
document.getElementById('opname_sys_stock').textContent = currentOpnameStock + ' ' + baseUnit;
calculateOpnameDiff();
} else {
currentOpnameStock = 0;
document.getElementById('opname_sys_stock').textContent = '0';
document.getElementById('opname_diff_display').textContent = '0';
}
}
function calculateOpnameDiff() {
const actualInput = document.getElementById('opname_actual_input');
const diffDisplay = document.getElementById('opname_diff_display');
const actual = parseFloat(actualInput.value);
if (!isNaN(actual)) {
const diff = actual - currentOpnameStock;
if (diff > 0) {
diffDisplay.textContent = '+' + diff;
diffDisplay.className = 'text-lg font-black text-emerald-600';
} else if (diff < 0) {
diffDisplay.textContent = diff;
diffDisplay.className = 'text-lg font-black text-red-600';
} else {
diffDisplay.textContent = '0';
diffDisplay.className = 'text-lg font-black text-gray-500';
}
} else {
diffDisplay.textContent = '0';
diffDisplay.className = 'text-lg font-black text-gray-500';
}
}
</script>
{% endblock %}
+191
View File
@@ -0,0 +1,191 @@
{% extends 'base.html' %}
{% block page_title %}Dashboard{% endblock %}
{% block content %}
<div class="mb-6">
<p class="text-xs font-bold text-kerinci uppercase tracking-widest mb-1">Sistem Administrator</p>
<div class="flex items-center space-x-3 mb-2">
<h2 class="text-3xl font-extrabold text-gray-900">Selamat datang, {% if request.user.is_authenticated %}{{ request.user.get_full_name|default:request.user.username }}{% else %}Administrator{% endif %}</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>
<p class="text-sm text-gray-500">Berikut ringkasan operasional sistem manajemen aset IT secara keseluruhan.</p>
</div>
<!-- 5 Cards Statistik -->
<div class="flex flex-wrap lg:flex-nowrap gap-4 mb-10">
<!-- Aset Karyawan -->
<a href="{% url 'asset_list' %}?tab=karyawan" class="w-[calc(50%-0.5rem)] lg:flex-1 flex flex-col items-center group">
<div class="bg-[#e9f2eb] rounded-2xl w-full h-20 sm:h-24 flex items-center justify-center mb-3 sm:mb-4 shadow-sm border border-[#d3e5d7] group-hover:bg-[#d3e5d7] transition-all group-hover:shadow-md">
<p class="text-4xl sm:text-5xl font-extrabold text-[#1f5c35]">{{ count_karyawan }}</p>
</div>
<p class="text-[10px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center group-hover:text-[#1f5c35] transition-colors">Aset Karyawan</p>
</a>
<!-- Aset Network -->
<a href="{% url 'asset_list' %}?tab=network" class="w-[calc(50%-0.5rem)] lg:flex-1 flex flex-col items-center group">
<div class="bg-blue-50 rounded-2xl w-full h-20 sm:h-24 flex items-center justify-center mb-3 sm:mb-4 shadow-sm border border-blue-100 group-hover:bg-blue-100 transition-all group-hover:shadow-md">
<p class="text-4xl sm:text-5xl font-extrabold text-blue-600">{{ count_network }}</p>
</div>
<p class="text-[10px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center group-hover:text-blue-600 transition-colors">Aset Network</p>
</a>
<!-- Aset Tersedia -->
<a href="{% url 'status_aset_list' %}?tab=tersedia" class="w-[calc(33.333%-0.67rem)] lg:flex-1 flex flex-col items-center group mt-2 lg:mt-0">
<div class="bg-emerald-50 rounded-2xl w-full h-16 sm:h-24 flex items-center justify-center mb-2 sm:mb-4 shadow-sm border border-emerald-100 group-hover:bg-emerald-100 transition-all group-hover:shadow-md">
<p class="text-3xl sm:text-5xl font-extrabold text-emerald-600">{{ count_tersedia }}</p>
</div>
<p class="text-[9px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center group-hover:text-emerald-600 transition-colors leading-tight">Aset Tersedia</p>
</a>
<!-- Aset Digunakan -->
<a href="{% url 'status_aset_list' %}?tab=digunakan" class="w-[calc(33.333%-0.67rem)] lg:flex-1 flex flex-col items-center group mt-2 lg:mt-0">
<div class="bg-blue-50 rounded-2xl w-full h-16 sm:h-24 flex items-center justify-center mb-2 sm:mb-4 shadow-sm border border-blue-100 group-hover:bg-blue-100 transition-all group-hover:shadow-md">
<p class="text-3xl sm:text-5xl font-extrabold text-blue-600">{{ count_digunakan }}</p>
</div>
<p class="text-[9px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center group-hover:text-blue-600 transition-colors leading-tight">Aset Digunakan</p>
</a>
<!-- Aset Maintenance -->
<a href="{% url 'status_aset_list' %}?tab=rusak" class="w-[calc(33.333%-0.67rem)] lg:flex-1 flex flex-col items-center group mt-2 lg:mt-0">
<div class="bg-amber-50 rounded-2xl w-full h-16 sm:h-24 flex items-center justify-center mb-2 sm:mb-4 shadow-sm border border-amber-100 group-hover:bg-amber-100 transition-all group-hover:shadow-md">
<p class="text-3xl sm:text-5xl font-extrabold text-amber-500">{{ count_maintenance }}</p>
</div>
<p class="text-[9px] sm:text-xs font-bold text-gray-500 uppercase tracking-wider text-center group-hover:text-amber-500 transition-colors leading-tight">Aset Maintenance</p>
</a>
</div>
<!-- 3 Lists Bawah: Log Distribusi -->
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
<!-- Kiri: Log Serah Terima -->
<div class="lg:col-span-7 bg-white rounded-2xl shadow-sm border border-gray-100 p-5 flex flex-col h-[400px] lg:h-[640px]">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-gray-800">Log Serah Terima</h3>
<a href="/distribusi/?tab=handover" class="text-xs font-bold text-kerinci hover:text-kerinci-dark transition-colors">Lihat Semua</a>
</div>
<div class="flex-1 overflow-y-auto scrollbar-hide space-y-4 pr-2">
{% for log in recent_handovers %}
<a href="{% url 'unit_history' log.unit.id %}" class="block group">
<div class="flex items-start space-x-3 p-3 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-100 transition-all">
<div class="w-8 h-8 rounded-full bg-kerinci-light text-kerinci flex items-center justify-center font-bold text-xs shrink-0 group-hover:bg-kerinci group-hover:text-white transition-colors">
{% if log.employee %}{{ log.employee.name|make_list|first|upper }}{% else %}?{% endif %}
</div>
<div>
<p class="text-sm font-bold text-gray-800 group-hover:text-kerinci transition-colors line-clamp-1">{{ log.unit.unit_code }} <span class="text-gray-400 font-normal ml-1">ke</span> {% if log.employee %}{{ log.employee.name }}{% else %}-{% endif %}</p>
<p class="text-xs text-gray-500 mt-1 line-clamp-1">{{ log.unit.asset.name }}</p>
<p class="text-[10px] text-gray-400 mt-1">{{ log.assigned_date|date:"d M Y" }}</p>
</div>
</div>
</a>
{% empty %}
<div class="flex flex-col items-center justify-center h-full text-center">
<p class="text-gray-400 text-sm">Belum ada data serah terima.</p>
</div>
{% endfor %}
</div>
</div>
<!-- Kanan: Log Mutasi & Pengembalian -->
<div class="lg:col-span-5 flex flex-col gap-6 lg:h-[640px]">
<!-- Log Mutasi -->
<div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-5 flex flex-col flex-1 min-h-[300px] lg:min-h-0">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-gray-800">Log Mutasi</h3>
<a href="/distribusi/?tab=mutation" class="text-xs font-bold text-kerinci hover:text-kerinci-dark transition-colors">Lihat Semua</a>
</div>
<div class="flex-1 overflow-y-auto scrollbar-hide space-y-4 pr-2">
{% for log in recent_mutations %}
<a href="{% url 'unit_history' log.unit.id %}" class="block group">
<div class="flex items-start space-x-3 p-3 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-100 transition-all">
<div class="w-8 h-8 rounded-full bg-blue-50 text-blue-500 flex items-center justify-center font-bold text-xs shrink-0 group-hover:bg-blue-500 group-hover:text-white transition-colors">
<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="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"></path></svg>
</div>
<div>
<p class="text-sm font-bold text-gray-800 group-hover:text-blue-600 transition-colors line-clamp-1">{{ log.unit.unit_code }} <span class="text-gray-400 font-normal mx-1">➜</span> {% if log.employee %}{{ log.employee.name }}{% else %}-{% endif %}</p>
<p class="text-xs text-gray-500 mt-1 line-clamp-1">{{ log.unit.asset.name }}</p>
<p class="text-[10px] text-gray-400 mt-1">Dari: {% if log.from_employee %}{{ log.from_employee.name }}{% else %}-{% endif %} • {{ log.assigned_date|date:"d M Y" }}</p>
</div>
</div>
</a>
{% empty %}
<div class="flex flex-col items-center justify-center h-full text-center">
<p class="text-gray-400 text-sm">Belum ada data mutasi.</p>
</div>
{% endfor %}
</div>
</div>
<!-- Log Pengembalian -->
<div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-5 flex flex-col flex-1 min-h-[300px] lg:min-h-0">
<div class="flex justify-between items-center mb-4">
<h3 class="font-bold text-gray-800">Log Pengembalian</h3>
<a href="/distribusi/?tab=return" class="text-xs font-bold text-kerinci hover:text-kerinci-dark transition-colors">Lihat Semua</a>
</div>
<div class="flex-1 overflow-y-auto scrollbar-hide space-y-4 pr-2">
{% for log in recent_returns %}
<a href="{% url 'unit_history' log.unit.id %}" class="block group">
<div class="flex items-start space-x-3 p-3 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-100 transition-all">
<div class="w-8 h-8 rounded-full bg-amber-50 text-amber-500 flex items-center justify-center font-bold text-xs shrink-0 group-hover:bg-amber-500 group-hover:text-white transition-colors">
<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="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"></path></svg>
</div>
<div>
<p class="text-sm font-bold text-gray-800 group-hover:text-amber-500 transition-colors line-clamp-1">{{ log.unit.unit_code }} <span class="text-gray-400 font-normal ml-1">dari</span> {% if log.employee %}{{ log.employee.name }}{% else %}-{% endif %}</p>
<p class="text-xs text-gray-500 mt-1 line-clamp-1">{{ log.unit.asset.name }}</p>
<p class="text-[10px] text-gray-400 mt-1">{{ log.assigned_date|date:"d M Y" }}</p>
</div>
</div>
</a>
{% empty %}
<div class="flex flex-col items-center justify-center h-full text-center">
<p class="text-gray-400 text-sm">Belum ada data pengembalian.</p>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block page_title_guide %}Dashboard Operasional{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Selamat datang di <strong>Dashboard</strong>! Halaman ini adalah pusat ringkasan untuk memantau aktivitas dan status aset IT secara cepat. 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="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Memantau Ringkasan Angka Aset</h4>
<p>Lihat total aset yang tersedia, sedang digunakan, atau dalam masa perbaikan (maintenance) melalui deretan kartu metrik di bagian atas.</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="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>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Melihat Log Distribusi Terbaru</h4>
<p>Bagian bawah halaman menampilkan aktivitas terbaru terkait Serah Terima, Mutasi, dan Pengembalian aset untuk melacak pergerakan aset terkini.</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-amber-500 bg-amber-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">Akses Cepat (Shortcut)</h4>
<p>Klik pada <strong>kartu metrik angka aset</strong> di bagian atas, atau pada tulisan <strong>"Lihat Semua"</strong> pada log untuk melompat langsung ke halaman detail terkait.</p>
</div>
</div>
</div>
</div>
{% endblock %}
+553
View File
@@ -0,0 +1,553 @@
{% extends 'base.html' %}
{% block page_title %}Distribusi Aset{% 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">Distribusi Aset</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('exportMenuDistribusi'); 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 Riwayat</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="exportMenuDistribusi" 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 'distribusi_export_pdf' %}?tab={{ tab }}{% if search_query %}&q={{ search_query }}{% endif %}&sort={{ request.GET.sort|default:'desc' }}" 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 'distribusi_export_excel' %}?tab={{ tab }}{% if search_query %}&q={{ search_query }}{% endif %}&sort={{ request.GET.sort|default:'desc' }}" 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="openCreateModal()" class="bg-kerinci text-white px-5 py-2 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>Buat Baru</span>
</button>
{% endif %}
</div>
</div>
<!-- Tabs -->
<div class="flex space-x-2 mb-6 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
<a href="?tab=handover" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'handover' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Serah Terima
{% if counts.handover > 0 %}<span class="ml-2 {% if tab == 'handover' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.handover }}</span>{% endif %}
</a>
<a href="?tab=mutation" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'mutation' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Mutasi
{% if counts.mutation > 0 %}<span class="ml-2 {% if tab == 'mutation' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.mutation }}</span>{% endif %}
</a>
<a href="?tab=return" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'return' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Pengembalian
{% if counts.return > 0 %}<span class="ml-2 {% if tab == 'return' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.return }}</span>{% endif %}
</a>
</div>
<!-- Search Bar -->
<div class="mb-4">
<form id="searchForm" method="GET" class="relative w-full sm:w-96">
<input type="hidden" name="tab" value="{{ tab }}">
<input type="hidden" name="sort" value="{{ request.GET.sort|default:'desc' }}">
<input type="text" id="searchInput" name="q" value="{{ search_query }}" placeholder="Cari NIK, nama, atau tanggal (cth: 07 Oct 2026)..." 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>
<!-- Table -->
<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 border-b border-[#002060]">
<th class="p-4 font-bold w-12 text-center">No</th>
<th class="p-4 font-bold">
{% if request.GET.sort == 'asc' %}
<a href="?tab={{ tab }}&q={{ search_query }}&sort=desc" class="flex items-center space-x-2 hover:text-gray-300 transition-colors" title="Urutkan Terbaru (Descending)">
<span>Tanggal</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="M5 15l7-7 7 7"></path></svg>
</a>
{% else %}
<a href="?tab={{ tab }}&q={{ search_query }}&sort=asc" class="flex items-center space-x-2 hover:text-gray-300 transition-colors" title="Urutkan Terlama (Ascending)">
<span>Tanggal</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>
</a>
{% endif %}
</th>
<th class="p-4 font-bold min-w-[250px]">Unit Aset</th>
{% if tab == 'handover' %}
<th class="p-4 font-bold">Diserahkan Kepada</th>
{% elif tab == 'mutation' %}
<th class="p-4 font-bold">Dari</th>
<th class="p-4 font-bold">Ke</th>
{% elif tab == 'return' %}
<th class="p-4 font-bold">Dikembalikan Oleh</th>
{% endif %}
<th class="p-4 font-bold text-center">Dokumen</th>
<th class="p-4 font-bold">Catatan</th>
<th class="p-4 font-bold text-center w-32">Riwayat Unit</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-50">
{% for log in assignments %}
<tr class="hover:bg-gray-50/50 transition-colors">
<td class="p-4 text-gray-500 font-medium text-center">{{ forloop.counter }}</td>
<td class="p-4 font-medium text-gray-900">
<p>{{ log.assigned_date|date:"d M Y" }}</p>
{% if log.created_at %}
<p class="text-xs text-gray-400 mt-0.5 font-normal">{{ log.created_at|date:"H:i" }} WIB</p>
{% endif %}
</td>
<td class="p-4">
<a href="{% url 'asset_units' log.unit.asset.id %}" class="block group">
<p class="font-medium text-gray-800 group-hover:text-kerinci transition-colors">{{ log.unit.asset.name }}</p>
<p class="text-xs text-kerinci mt-0.5 font-bold group-hover:underline">{{ log.unit.unit_code }}</p>
</a>
</td>
{% if tab == 'handover' %}
<td class="p-4">
<a href="{% url 'employee_detail' log.employee.id %}" class="block group">
<p class="font-bold text-gray-800 group-hover:text-kerinci transition-colors">{{ log.employee.name }}</p>
<p class="text-xs text-gray-400 group-hover:underline">NIK: {{ log.employee.nik }}</p>
</a>
</td>
{% elif tab == 'mutation' %}
<td class="p-4">
{% if log.from_employee %}
<a href="{% url 'employee_detail' log.from_employee.id %}" class="block group">
<p class="font-bold text-gray-800 group-hover:text-kerinci transition-colors">{{ log.from_employee.name }}</p>
<p class="text-xs text-gray-400 group-hover:underline">NIK: {{ log.from_employee.nik }}</p>
</a>
{% else %}
<span class="text-gray-300 italic text-xs">-</span>
{% endif %}
</td>
<td class="p-4">
<a href="{% url 'employee_detail' log.employee.id %}" class="block group">
<p class="font-bold text-gray-800 group-hover:text-kerinci transition-colors">{{ log.employee.name }}</p>
<p class="text-xs text-gray-400 group-hover:underline">NIK: {{ log.employee.nik }}</p>
</a>
</td>
{% elif tab == 'return' %}
<td class="p-4">
{% if log.from_employee %}
<a href="{% url 'employee_detail' log.from_employee.id %}" class="block group">
<p class="font-bold text-gray-800 group-hover:text-kerinci transition-colors">{{ log.from_employee.name }}</p>
<p class="text-xs text-gray-400 group-hover:underline">NIK: {{ log.from_employee.nik }}</p>
</a>
{% else %}
<p class="font-bold text-gray-800">{{ log.employee.name }}</p>
<p class="text-xs text-gray-400">NIK: {{ log.employee.nik }}</p>
{% endif %}
</td>
{% endif %}
<td class="p-4 text-center">
{% if log.document %}
<div class="inline-flex items-center justify-center space-x-1">
<a href="{{ log.document.url }}" target="_blank" class="inline-flex items-center space-x-1 text-kerinci hover:underline font-bold text-xs bg-kerinci-light px-3 py-1.5 rounded-lg" title="Lihat Dokumen Fisik">
<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>File</span>
</a>
<form action="{% url 'distribusi_upload_doc' log.id %}" method="POST" enctype="multipart/form-data" class="inline-block relative">
{% csrf_token %}
<label class="cursor-pointer inline-flex items-center justify-center p-1.5 text-gray-400 hover:text-kerinci hover:bg-kerinci/10 rounded-lg transition-colors" title="Perbarui / Ganti Dokumen">
<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="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
<input type="file" name="document" class="hidden" accept=".pdf,.jpg,.jpeg,.png" onchange="this.form.submit()">
</label>
</form>
</div>
{% else %}
<form action="{% url 'distribusi_upload_doc' log.id %}" method="POST" enctype="multipart/form-data" class="inline-block relative">
{% csrf_token %}
<label class="cursor-pointer inline-flex items-center justify-center p-1.5 text-gray-400 hover:text-kerinci hover:bg-kerinci/10 rounded-lg transition-colors border border-dashed border-gray-300 hover:border-kerinci" title="Upload Dokumen">
<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 4v16m8-8H4"></path></svg>
<input type="file" name="document" class="hidden" accept=".pdf,.jpg,.jpeg,.png" onchange="this.form.submit()">
</label>
</form>
{% endif %}
</td>
<td class="p-4 text-gray-500 text-xs max-w-xs truncate">{{ log.notes|default:"-" }}</td>
<td class="p-4 text-center">
<a href="{% url 'unit_history' log.unit.id %}" class="inline-flex items-center justify-center p-2 text-kerinci hover:bg-kerinci-light rounded-xl transition-colors" title="Riwayat Unit">
<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 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="10" 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
{% if tab == 'handover' %}serah terima{% elif tab == 'mutation' %}mutasi{% else %}pengembalian{% endif %}
aset.</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include 'components/pagination.html' %}
</div>
<!-- Modal Buat Baru -->
<div id="createModal" 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="createOverlay" onclick="closeCreateModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-[90%] mx-auto max-h-[90vh] overflow-y-auto scrollbar-hide max-w-lg relative z-10 p-6 transform transition-all scale-95 opacity-0" id="createCard">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-extrabold text-gray-900" id="modalTitle">Serah Terima Aset</h3>
<button onclick="closeCreateModal()" 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="createForm" method="POST" enctype="multipart/form-data" class="space-y-4">
{% csrf_token %}
<!-- Tipe Distribusi -->
<div>
<label class="block text-sm font-bold text-gray-700 mb-1.5">Tipe Distribusi <span class="text-red-500">*</span></label>
<select id="dist_type" onchange="onTypeChange()" 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 font-bold">
<option value="handover" {% if tab == 'handover' %}selected{% endif %}>Serah Terima (Gudang → Karyawan)</option>
<option value="mutation" {% if tab == 'mutation' %}selected{% endif %}>Mutasi (Karyawan → Karyawan Lain)</option>
<option value="return" {% if tab == 'return' %}selected{% endif %}>Pengembalian (Karyawan → Gudang)</option>
</select>
</div>
<!-- Unit - Handover (Tersedia) -->
<div id="unitHandoverGroup">
<label class="block text-sm font-bold text-gray-700 mb-1.5">Pilih Unit Aset <span class="text-red-500">*</span></label>
<select id="unit_handover" name="unit" 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">
<option value="">-- Pilih unit yang tersedia --</option>
{% regroup available_units by asset as asset_groups %}
{% for group in asset_groups %}
<optgroup label="{{ group.grouper.name }}">
{% for unit in group.list %}
<option value="{{ unit.id }}">{{ unit.unit_code }}</option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
<p class="text-xs text-gray-400 mt-1">Hanya unit berstatus "Tersedia"</p>
</div>
<!-- Unit - Mutation/Return (Digunakan) -->
<div id="unitUsedGroup" class="hidden">
<label class="block text-sm font-bold text-gray-700 mb-1.5">Pilih Unit Aset <span class="text-red-500">*</span></label>
<select id="unit_used" name="unit_used" onchange="onUsedUnitChange()" 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">
<option value="">-- Pilih unit yang sedang digunakan --</option>
{% for unit in used_units %}
<option value="{{ unit.id }}" data-holder-id="{{ unit.assigned_to.id }}" data-holder="{{ unit.assigned_to.name }}" data-holder-nik="{{ unit.assigned_to.nik }}">{{ unit.unit_code }} — {{ unit.asset.name }} ({{ unit.assigned_to.name }})</option>
{% endfor %}
</select>
<p class="text-xs text-gray-400 mt-1">Hanya unit berstatus "Digunakan"</p>
</div>
<!-- Pemegang Saat Ini -->
<div id="currentHolderGroup" class="hidden">
<label class="block text-sm font-bold text-gray-700 mb-1.5">Pemegang Saat Ini</label>
<input type="text" id="currentHolderDisplay" disabled class="w-full px-4 py-2.5 rounded-xl border border-gray-200 text-sm bg-gray-100 text-gray-500 cursor-not-allowed font-bold">
</div>
<!-- Karyawan Penerima (Handover & Mutation) -->
<div id="employeeGroup">
<label class="block text-sm font-bold text-gray-700 mb-1.5" id="employeeLabel">Diserahkan Kepada <span class="text-red-500">*</span></label>
<select id="dist_employee" name="employee" 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">
<option value="">-- Pilih karyawan --</option>
{% for emp in employees %}
<option value="{{ emp.id }}">{{ emp.nik }} - {{ emp.name }}</option>
{% endfor %}
</select>
</div>
<!-- Tanggal -->
<div>
<label class="block text-sm font-bold text-gray-700 mb-1.5">Tanggal <span class="text-red-500">*</span></label>
<input type="date" name="assigned_date" id="dist_date" 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>
<!-- Upload File -->
<div>
<label class="block text-sm font-bold text-gray-700 mb-1.5">Dokumen Bukti <span class="text-xs text-gray-400 font-normal">(Opsional)</span></label>
<input type="file" name="document" accept=".pdf,.jpg,.jpeg,.png" class="w-full px-2 py-1.5 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-white file:mr-4 file:py-2 file:px-4 file:rounded-full file:border-0 file:text-xs file:font-bold file:bg-kerinci/10 file:text-kerinci hover:file:bg-kerinci/20 cursor-pointer">
</div>
<!-- Catatan -->
<div>
<label class="block text-sm font-bold text-gray-700 mb-1.5">Catatan <span class="text-xs text-gray-400 font-normal">(Opsional)</span></label>
<textarea name="notes" rows="2" 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="Catatan tambahan..."></textarea>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeCreateModal()" 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" id="submitBtn">Simpan</button>
</div>
</form>
</div>
</div>
<script>
// Set default date
document.getElementById('dist_date').value = new Date().toISOString().split('T')[0];
// Set initial type based on current tab
const currentTab = '{{ tab }}';
if (currentTab) {
document.getElementById('dist_type').value = currentTab;
}
function onTypeChange() {
const type = document.getElementById('dist_type').value;
const unitHandover = document.getElementById('unitHandoverGroup');
const unitUsed = document.getElementById('unitUsedGroup');
const currentHolder = document.getElementById('currentHolderGroup');
const employeeGroup = document.getElementById('employeeGroup');
const employeeLabel = document.getElementById('employeeLabel');
const modalTitle = document.getElementById('modalTitle');
const form = document.getElementById('createForm');
// Reset name attributes and required
document.getElementById('unit_handover').name = '';
document.getElementById('unit_handover').required = false;
document.getElementById('unit_used').name = '';
document.getElementById('unit_used').required = false;
document.getElementById('dist_employee').required = false;
if (type === 'handover') {
modalTitle.textContent = 'Serah Terima Aset';
unitHandover.classList.remove('hidden');
unitUsed.classList.add('hidden');
currentHolder.classList.add('hidden');
employeeGroup.classList.remove('hidden');
employeeLabel.innerHTML = 'Diserahkan Kepada <span class="text-red-500">*</span>';
document.getElementById('unit_handover').name = 'unit';
document.getElementById('unit_handover').required = true;
document.getElementById('dist_employee').required = true;
form.action = '{% url "distribusi_handover" %}';
} else if (type === 'mutation') {
modalTitle.textContent = 'Mutasi Aset';
unitHandover.classList.add('hidden');
unitUsed.classList.remove('hidden');
currentHolder.classList.remove('hidden');
employeeGroup.classList.remove('hidden');
employeeLabel.innerHTML = 'Karyawan Penerima Baru <span class="text-red-500">*</span>';
document.getElementById('unit_used').name = 'unit';
document.getElementById('unit_used').required = true;
document.getElementById('dist_employee').required = true;
form.action = '{% url "distribusi_mutation" %}';
} else if (type === 'return') {
modalTitle.textContent = 'Pengembalian Aset';
unitHandover.classList.add('hidden');
unitUsed.classList.remove('hidden');
currentHolder.classList.remove('hidden');
employeeGroup.classList.add('hidden');
document.getElementById('unit_used').name = 'unit';
document.getElementById('unit_used').required = true;
document.getElementById('dist_employee').required = false;
form.action = '{% url "distribusi_return" %}';
}
if (type === 'mutation' || type === 'return') {
onUsedUnitChange();
} else {
// Tampilkan kembali semua karyawan untuk serah terima
const empSelect = document.getElementById('dist_employee');
if (empSelect) {
for (let i = 0; i < empSelect.options.length; i++) {
empSelect.options[i].style.display = '';
}
}
}
}
function onUsedUnitChange() {
const sel = document.getElementById('unit_used');
const opt = sel.options[sel.selectedIndex];
const holder = opt.getAttribute('data-holder') || '';
const nik = opt.getAttribute('data-holder-nik') || '';
const holderId = opt.getAttribute('data-holder-id') || '';
document.getElementById('currentHolderDisplay').value = holder ? holder + ' (NIK: ' + nik + ')' : '';
// Sembunyikan pemegang saat ini dari daftar penerima baru
const empSelect = document.getElementById('dist_employee');
if (empSelect) {
for (let i = 0; i < empSelect.options.length; i++) {
const empOpt = empSelect.options[i];
if (empOpt.value !== "") {
if (empOpt.value === holderId) {
empOpt.style.display = 'none';
} else {
empOpt.style.display = '';
}
}
}
// Reset pilihan jika employee yang terpilih sekarang disembunyikan
if (empSelect.value === holderId) {
empSelect.value = "";
}
}
}
function openCreateModal() {
onTypeChange(); // Initialize form based on type
const modal = document.getElementById('createModal');
const overlay = document.getElementById('createOverlay');
const card = document.getElementById('createCard');
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 closeCreateModal() {
const modal = document.getElementById('createModal');
const overlay = document.getElementById('createOverlay');
const card = document.getElementById('createCard');
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();
});
}
</script>
{% endblock %}
{% block page_title_guide %}Manajemen Distribusi Aset{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman <strong>Distribusi Aset</strong> mencatat riwayat pergerakan dan perpindahan tangan seluruh unit aset IT. 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">Pencatatan Distribusi Baru</h4>
<p>Klik tombol <strong>"Tambah Baru"</strong> di sudut kanan atas (berikon +) untuk mencatat aktivitas <strong>Serah Terima</strong>, <strong>Mutasi</strong>, atau <strong>Pengembalian</strong> unit dari/ke karyawan.</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="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>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Manajemen Dokumen Fisik (BAST)</h4>
<p>Pada kolom <strong>"Dokumen"</strong>, Anda dapat mengunggah file hasil scan (PDF/Foto) Berita Acara Serah Terima yang telah ditandatangani sebagai bukti fisik yang sah untuk setiap aktivitas.</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-indigo-500 bg-indigo-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="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Melihat Riwayat Spesifik (Jejak Unit)</h4>
<p>Klik ikon <strong>Jam / Waktu</strong> pada kolom aksi di baris manapun untuk melihat jejak perjalanan sejarah lengkap dari unit tersebut (dari awal dibeli hingga status terakhirnya).</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-amber-500 bg-amber-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="M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Filter, Urutkan & Ekspor</h4>
<p>Gunakan tab untuk memfilter jenis aktivitas (Serah Terima/Mutasi/Return). Klik judul kolom <strong>"Tanggal"</strong> untuk mengurutkan (terbaru/terlama), dan klik <strong>Ekspor PDF</strong> untuk mencetak rekap data yang sedang tampil.</p>
</div>
</div>
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuDistribusi');
if (menu) menu.style.display = 'none';
});
</script>
+295
View File
@@ -0,0 +1,295 @@
{% extends 'base.html' %}
{% block page_title %}Detail Karyawan{% endblock %}
{% block content %}
<div class="mb-6 flex flex-col sm:flex-row sm:justify-between sm:items-center items-start space-y-4 sm:space-y-0">
<div>
<p class="text-xs font-bold text-kerinci uppercase tracking-widest mb-1">Detail Karyawan</p>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-extrabold text-gray-900">{{ employee.name }}</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>
<p class="text-gray-500 mt-1 font-medium">NIK: {{ employee.nik }} <span class="mx-2">&bull;</span> Jabatan: {{ employee.position|default:"-" }}</p>
</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('exportMenuEmployeeDetail'); 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 Data</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="exportMenuEmployeeDetail" 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_detail_export_pdf' employee.id %}" 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_detail_export_excel' employee.id %}" 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>
<a href="{% url 'employee_list' %}" class="bg-white border border-gray-200 rounded-xl shadow-sm px-4 py-2 text-sm font-bold text-gray-700 hover:bg-gray-50 transition-colors flex items-center space-x-2 justify-center text-center w-full sm:w-auto flex-1 sm:flex-none">
<span>Kembali</span>
</a>
</div>
</div>
<div class="bg-white rounded-none sm:rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
<div class="p-5 border-b border-gray-100 bg-gray-50/50 flex justify-between items-center">
<h3 class="font-bold text-gray-800">Aset Yang Digunakan Saat Ini</h3>
<span class="bg-kerinci text-white px-3 py-1 rounded-full text-xs font-bold shadow-sm">{{ units|length }} Aset</span>
</div>
<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 border-b border-[#002060]">
<th class="p-4 font-bold text-center w-16">No</th>
<th class="p-4 font-bold w-40">Kode Unit</th>
<th class="p-4 font-bold">Nama Aset</th>
<th class="p-4 font-bold text-center w-32">Status</th>
<th class="p-4 font-bold text-center w-40">Riwayat Unit</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-50">
{% for unit in units %}
<tr class="hover:bg-gray-50/50 transition-colors">
<td class="p-4 text-center text-gray-500">{{ forloop.counter }}</td>
<td class="p-4">
<a href="{% url 'unit_history' unit.id %}" class="font-bold text-gray-900 hover:text-kerinci transition-colors inline-block w-max">{{ unit.unit_code }}</a>
</td>
<td class="p-4">
<a href="{% url 'asset_units' unit.asset.id %}" class="block group w-max">
<p class="font-bold text-gray-800 transition-colors group-hover:text-kerinci">{{ unit.asset.name }}</p>
</a>
</td>
<td class="p-4 text-center">
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" class="hover:opacity-80 transition-opacity focus:outline-none focus:ring-2 focus:ring-kerinci focus:ring-offset-1 rounded-md" title="Klik untuk ubah status">
{% if unit.status == 'tersedia' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-emerald-50 border border-emerald-200 text-emerald-700 hover:bg-emerald-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Tersedia <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% elif unit.status == 'digunakan' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-blue-50 border border-blue-200 text-blue-700 hover:bg-blue-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Digunakan <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% elif unit.status == 'rusak' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-red-50 border border-red-200 text-red-700 hover:bg-red-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Maintenance <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% else %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-gray-50 border border-gray-200 text-gray-600 hover:bg-gray-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">{{ unit.get_status_display }} <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% endif %}
</button>
</td>
<td class="p-4 text-center">
<a href="{% url 'unit_history' unit.id %}" class="inline-flex items-center justify-center p-2 text-kerinci hover:bg-kerinci-light rounded-xl transition-colors" title="Riwayat Unit">
<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 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="5" class="p-12 text-center text-gray-400">
<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="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"></path></svg>
<p class="text-sm font-medium">Karyawan ini tidak memegang aset apapun saat ini.</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div id="statusUnitModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeStatusUnitModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-md relative mx-auto z-10 p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Update Status Unit</h3>
<p class="text-sm text-gray-500 mb-1">Kode Unit: <strong id="su_code" class="text-gray-900"></strong></p>
<p id="su_assigned_info" class="text-sm text-gray-500 mb-4 hidden">Dipegang Oleh: <strong id="su_assigned_name" class="text-gray-900"></strong></p>
<form id="statusUnitForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Status Baru</label>
<select id="su_status" name="status" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="tersedia" id="opt_su_tersedia">Tersedia</option>
<option value="digunakan" id="opt_su_digunakan" class="hidden" disabled>Digunakan</option>
<option value="rusak">Diperbaiki (Rusak / Maintenance)</option>
</select>
<p id="su_bast_warning" class="text-xs text-amber-600 mt-1 hidden font-bold">* Aset sedang digunakan. Pengembalian atau Mutasi harus melalui menu Distribusi Aset.</p>
</div>
<div id="su_notes_container" class="hidden">
<label class="block text-sm font-bold text-gray-700 mb-1">Catatan Kejadian <span class="text-red-500">*</span></label>
<textarea id="su_notes" name="notes" rows="2" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Jelaskan alasan perbaikan / keluhan kerusakan..."></textarea>
</div>
<div id="su_network_fields" class="hidden space-y-4 pt-4 border-t border-gray-100 mt-4">
<p class="text-xs font-bold text-gray-500 uppercase">Detail Lokasi Pemasangan</p>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Area <span class="text-red-500">*</span></label>
<select id="su_area" name="area" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="">-- Pilih Area --</option>
<option value="Regulating Weir (RW)">Regulating Weir (RW)</option>
<option value="Jakon">Jakon</option>
<option value="Beringin Tunggal (BT)">Beringin Tunggal (BT)</option>
<option value="DAM">DAM</option>
<option value="Adit 1">Adit 1</option>
<option value="Adit 2">Adit 2</option>
<option value="Adit 3">Adit 3</option>
<option value="Gudang Induk (GI)">Gudang Induk (GI)</option>
<option value="Vertical Shaft (VS)">Vertical Shaft (VS)</option>
<option value="Power House (PH)">Power House (PH)</option>
<option value="Lain-lainnya">Lain-lainnya</option>
</select>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Lokasi Spesifik <span class="text-red-500">*</span></label>
<input type="text" id="su_location" name="location" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Misal: Dinding server room barat...">
</div>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeStatusUnitModal()" class="px-4 py-2 border border-gray-300 text-gray-700 font-bold rounded-lg text-sm hover:bg-gray-50 transition-colors">Batal</button>
<button type="submit" class="px-4 py-2 bg-kerinci text-white font-bold rounded-lg text-sm shadow-sm hover:bg-kerinci/90 transition-colors">
Simpan Status
</button>
</div>
</form>
</div>
</div>
<script>
function openStatusModal(id, fullCode, status, assignedTo, categoryName, area, location) {
document.getElementById('statusUnitForm').action = '/unit/' + id + '/status/';
document.getElementById('su_code').innerText = fullCode;
const assignedInfo = document.getElementById('su_assigned_info');
const assignedName = document.getElementById('su_assigned_name');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '' && assignedTo !== 'true') {
assignedName.innerText = assignedTo;
assignedInfo.classList.remove('hidden');
} else {
assignedInfo.classList.add('hidden');
}
const statSelect = document.getElementById('su_status');
const optTersedia = document.getElementById('opt_su_tersedia');
const optDigunakan = document.getElementById('opt_su_digunakan');
const warnText = document.getElementById('su_bast_warning');
const netFields = document.getElementById('su_network_fields');
const areaInput = document.getElementById('su_area');
const locInput = document.getElementById('su_location');
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
areaInput.value = area && area !== 'None' ? area : '';
locInput.value = location && location !== 'None' ? location : '';
const isNetwork = categoryName && categoryName.includes('Network');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '') {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = true;
optTersedia.classList.add('hidden');
warnText.classList.remove('hidden');
let empName = assignedTo === 'true' ? 'karyawan' : assignedTo;
warnText.innerHTML = '* Aset sedang digunakan oleh <strong class="font-extrabold underline">' + empName + '</strong>. Pengembalian harus melalui menu Distribusi Aset.';
} else if (isNetwork) {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
} else {
optDigunakan.disabled = true;
optDigunakan.classList.add('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
}
statSelect.value = status;
statSelect.onchange = function() {
const notesContainer = document.getElementById('su_notes_container');
const notesInput = document.getElementById('su_notes');
if (this.value === 'rusak') {
notesContainer.classList.remove('hidden');
notesInput.required = true;
} else {
notesContainer.classList.add('hidden');
notesInput.required = false;
}
if ((this.value === 'digunakan' || this.value === 'rusak') && isNetwork) {
netFields.classList.remove('hidden');
areaInput.required = true;
locInput.required = true;
} else {
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
}
};
statSelect.onchange();
document.getElementById('statusUnitModal').classList.remove('hidden');
}
function closeStatusUnitModal() {
document.getElementById('statusUnitModal').classList.add('hidden');
}
</script>
{% endblock %}
{% block page_title_guide %}Profil & Aset Karyawan{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman <strong>Detail Karyawan</strong> adalah profil personal tiap karyawan yang merangkum segala perangkat IT yang saat ini sedang menjadi tanggung jawab mereka. 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="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Mengecek Aset yang Ditahan</h4>
<p>Tabel menampilkan secara spesifik unit aset apa saja (beserta kodenya) yang statusnya sedang <strong>Digunakan</strong> oleh karyawan bersangkutan 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-amber-500 bg-amber-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="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Informasi Penarikan / Pengembalian</h4>
<p>Apabila Anda ingin menarik perangkat dari karyawan ini (misal karena mereka resign atau ganti perangkat), Anda harus melakukannya melalui menu <strong>Distribusi Aset &gt; Tambah Baru &gt; Pilih Pengembalian</strong>. Anda tidak dapat langsung menghapusnya dari sini demi menjaga integritas rekaman jejak (log).</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="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>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Ekspor Laporan Peminjaman</h4>
<p>Klik tombol <strong>Ekspor PDF</strong> di bagian atas untuk mencetak dokumen daftar inventaris resmi atas nama karyawan bersangkutan.</p>
</div>
</div>
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuEmployeeDetail');
if (menu) menu.style.display = 'none';
});
</script>
+525
View File
@@ -0,0 +1,525 @@
{% 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>
+123
View File
@@ -0,0 +1,123 @@
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login - IT All Role Kerinci Hydropower</title>
<link rel="stylesheet" href="{% static 'dist/style.css' %}?v=2.1">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<style>
body { font-family: 'Inter', sans-serif; }
</style>
</head>
<body class="bg-gray-50 text-gray-800 font-sans antialiased h-screen flex flex-col justify-center items-center p-4">
<!-- Toast Notification Container -->
{% if messages %}
<div id="toast-container" class="fixed top-5 right-5 z-50 flex flex-col gap-3">
{% for message in messages %}
<div class="toast-item relative overflow-hidden bg-white border border-gray-100 shadow-[0_8px_30px_rgb(0,0,0,0.12)] rounded-xl p-4 flex items-start gap-3 w-[350px] transform translate-y-[-20px] opacity-0 transition-all duration-300">
<!-- Icon -->
<div class="flex-shrink-0 mt-0.5">
{% if message.tags == 'error' %}
<svg class="w-5 h-5 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% else %}
<svg class="w-5 h-5 text-blue-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% endif %}
</div>
<!-- Message Content -->
<div class="flex-1">
<p class="text-sm font-bold text-gray-800">{% if message.tags == 'error' %}Akses Ditolak{% else %}Pemberitahuan{% endif %}</p>
<p class="text-xs text-gray-500 mt-0.5 leading-relaxed">{{ message }}</p>
</div>
<!-- Close Button -->
<button onclick="this.closest('.toast-item').remove()" class="text-gray-400 hover:text-gray-600 transition-colors focus:outline-none">
<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="M6 18L18 6M6 6l12 12"></path></svg>
</button>
<!-- Progress bar -->
<div class="absolute bottom-0 right-0 h-1 {% if message.tags == 'error' %}bg-red-500{% else %}bg-blue-500{% endif %} toast-progress" style="width: 100%;"></div>
</div>
{% endfor %}
</div>
<style>
@keyframes toastProgress {
from { width: 100%; }
to { width: 0%; }
}
.toast-progress {
animation: toastProgress 4s linear forwards;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const toasts = document.querySelectorAll('.toast-item');
toasts.forEach((toast, index) => {
setTimeout(() => {
toast.classList.remove('translate-y-[-20px]', 'opacity-0');
toast.classList.add('translate-y-0', 'opacity-100');
}, index * 150);
setTimeout(() => {
toast.classList.remove('translate-y-0', 'opacity-100');
toast.classList.add('translate-y-[-10px]', 'opacity-0');
setTimeout(() => toast.remove(), 300);
}, 4000);
});
});
</script>
{% endif %}
<div class="w-full max-w-md">
<!-- Card -->
<div class="bg-white rounded-3xl shadow-[0_8px_30px_rgb(0,0,0,0.08)] border border-gray-100 overflow-hidden">
<!-- Header Logo -->
<div class="bg-gray-50/50 border-b border-gray-100 p-8 flex justify-center">
<img src="{% static 'img/main_logo.png' %}" alt="IT All Role Kerinci Hydropower" class="h-12 w-auto object-contain">
</div>
<!-- Form Body -->
<div class="p-8">
<div class="text-center mb-8">
<h1 class="text-2xl font-extrabold text-gray-900">Masuk ke Sistem</h1>
<p class="text-sm text-gray-500 mt-1">Sistem Manajemen Aset IT - PT. KMH</p>
</div>
<form action="{% url 'login' %}{% if request.GET.next %}?next={{ request.GET.next }}{% endif %}" method="POST" class="space-y-5">
{% csrf_token %}
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Username atau Email</label>
<div class="relative">
<input type="text" name="username" required class="w-full pl-11 pr-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50 transition-all" placeholder="Masukkan username atau email">
<svg class="w-5 h-5 text-gray-400 absolute left-4 top-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
</div>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-2">Password</label>
<div class="relative">
<input type="password" name="password" required class="w-full pl-11 pr-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light bg-gray-50 transition-all" placeholder="Masukkan password">
<svg class="w-5 h-5 text-gray-400 absolute left-4 top-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
</div>
</div>
<button type="submit" class="w-full py-3.5 mt-2 bg-kerinci text-white font-bold rounded-xl text-sm shadow-sm shadow-kerinci/30 hover:bg-kerinci-dark hover:shadow-md transition-all flex items-center justify-center space-x-2">
<span>Masuk</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="M14 5l7 7m0 0l-7 7m7-7H3"></path></svg>
</button>
</form>
</div>
<!-- Footer -->
<div class="bg-gray-50/50 py-4 text-center border-t border-gray-100">
<p class="text-[10px] font-bold text-gray-400 uppercase tracking-widest">&copy; {% now "Y" %} IT ALL ROLE</p>
</div>
</div>
</div>
</body>
</html>
+124
View File
@@ -0,0 +1,124 @@
{% extends 'base.html' %}
{% block page_title %}Profil Saya{% endblock %}
{% block content %}
<div class="mb-8">
<h2 class="text-3xl font-extrabold text-gray-900 mb-2">Pengaturan Profil</h2>
<p class="text-sm text-gray-500">Kelola informasi pribadi dan pengaturan keamanan akun Anda.</p>
</div>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Kolom Kiri: Info Umum -->
<div class="lg:col-span-1">
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-8 flex flex-col items-center text-center">
<div class="w-32 h-32 bg-kerinci-light text-kerinci rounded-full flex items-center justify-center font-extrabold text-5xl mb-6 shadow-sm border-4 border-white ring-1 ring-gray-100">
{{ request.user.first_name|default:request.user.username|first|upper }}
</div>
<h3 class="text-xl font-extrabold text-gray-900">{{ request.user.get_full_name|default:request.user.username }}</h3>
<p class="text-sm font-bold text-gray-400 uppercase tracking-wider mt-1">Administrator Sistem</p>
<div class="w-full h-px bg-gray-100 my-6"></div>
<div class="w-full flex justify-between items-center text-sm">
<span class="text-gray-500">Status Akun</span>
<span class="px-3 py-1 bg-emerald-50 text-emerald-600 rounded-full font-bold text-xs">Aktif</span>
</div>
<div class="w-full flex justify-between items-center text-sm mt-3">
<span class="text-gray-500">Terdaftar pada</span>
<span class="font-bold text-gray-700">{{ request.user.date_joined|date:"d M Y" }}</span>
</div>
</div>
</div>
<!-- Kolom Kanan: Form Edit -->
<div class="lg:col-span-2 space-y-8">
<!-- Form Informasi Pribadi -->
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-8">
<div class="flex items-center space-x-3 mb-6">
<div class="w-10 h-10 rounded-full bg-blue-50 text-blue-500 flex items-center justify-center">
<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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
</div>
<h3 class="text-lg font-extrabold text-gray-900">Informasi Pribadi</h3>
</div>
<form action="{% url 'profile' %}" method="POST">
{% csrf_token %}
<input type="hidden" name="action" value="update_info">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6 mb-6">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Nama Depan (Atau Peran)</label>
<input type="text" name="first_name" value="{{ request.user.first_name }}" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light transition-all bg-gray-50" placeholder="Contoh: Admin IT">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Nama Belakang (Atau Divisi)</label>
<input type="text" name="last_name" value="{{ request.user.last_name }}" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light transition-all bg-gray-50" placeholder="Contoh: PT. KMH">
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6 mb-8">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Username (Login)</label>
<input type="text" name="username" value="{{ request.user.username }}" required class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light transition-all bg-gray-50 font-mono">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Email</label>
<input type="email" name="email" value="{{ request.user.email }}" class="w-full px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-2 focus:ring-kerinci-light transition-all bg-gray-50" placeholder="[email protected]">
</div>
</div>
<div class="flex justify-end">
<button type="submit" class="px-6 py-3 bg-kerinci text-white font-bold rounded-xl text-sm shadow-sm shadow-kerinci/30 hover:bg-kerinci-dark hover:shadow-md transition-all flex items-center space-x-2">
<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="M5 13l4 4L19 7"></path></svg>
<span>Simpan Perubahan</span>
</button>
</div>
</form>
</div>
<!-- Form Keamanan Akun -->
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-8">
<div class="flex items-center space-x-3 mb-6">
<div class="w-10 h-10 rounded-full bg-amber-50 text-amber-500 flex items-center justify-center">
<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 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
</div>
<h3 class="text-lg font-extrabold text-gray-900">Keamanan & Password</h3>
</div>
<form action="{% url 'profile' %}" method="POST">
{% csrf_token %}
<input type="hidden" name="action" value="update_password">
<div class="space-y-6 mb-8">
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Password Saat Ini</label>
<input type="password" name="old_password" required class="w-full max-w-md px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-500 focus:ring-2 focus:ring-amber-100 transition-all bg-gray-50" placeholder="••••••••">
</div>
<div class="h-px w-full max-w-md bg-gray-100"></div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Password Baru</label>
<input type="password" name="new_password" required minlength="6" class="w-full max-w-md px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-500 focus:ring-2 focus:ring-amber-100 transition-all bg-gray-50" placeholder="Minimal 6 karakter">
</div>
<div>
<label class="block text-xs font-bold text-gray-700 uppercase tracking-wider mb-2">Konfirmasi Password Baru</label>
<input type="password" name="confirm_password" required minlength="6" class="w-full max-w-md px-4 py-3 rounded-xl border border-gray-200 text-sm focus:outline-none focus:border-amber-500 focus:ring-2 focus:ring-amber-100 transition-all bg-gray-50" placeholder="Ketik ulang password baru">
</div>
</div>
<div class="flex justify-start">
<button type="submit" class="px-6 py-3 bg-amber-500 text-white font-bold rounded-xl text-sm shadow-sm shadow-amber-500/30 hover:bg-amber-600 hover:shadow-md transition-all flex items-center space-x-2">
<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="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"></path></svg>
<span>Perbarui Password</span>
</button>
</div>
</form>
</div>
</div>
</div>
{% endblock %}
+400
View File
@@ -0,0 +1,400 @@
{% extends 'base.html' %}
{% block page_title %}Status Aset{% endblock %}
{% block content %}
<div class="mb-8 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 tracking-wider text-kerinci uppercase mb-1">Manajemen Aset</p>
<div class="flex items-center space-x-3">
<h2 class="text-3xl font-extrabold text-gray-900">Status Aset</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('exportMenuStatus'); 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 Data</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="exportMenuStatus" 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 'status_aset_export_pdf' %}?tab={{ tab }}&cat={{ cat_filter }}{% 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 'status_aset_export_excel' %}?tab={{ tab }}&cat={{ cat_filter }}{% 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>
</div>
</div>
<!-- Tabs -->
<div class="flex space-x-2 mb-6 border-b border-gray-200 overflow-x-auto whitespace-nowrap scrollbar-hide">
<a href="?tab=tersedia&cat={{ cat_filter }}&q={{ search_query }}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'tersedia' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Tersedia
<span class="ml-2 {% if tab == 'tersedia' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.tersedia }}</span>
</a>
<a href="?tab=digunakan&cat={{ cat_filter }}&q={{ search_query }}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'digunakan' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Digunakan
<span class="ml-2 {% if tab == 'digunakan' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.digunakan }}</span>
</a>
<a href="?tab=rusak&cat={{ cat_filter }}&q={{ search_query }}" class="px-5 py-3 text-sm font-bold border-b-2 transition-colors flex items-center {% if tab == 'rusak' %}border-kerinci text-kerinci{% else %}border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300{% endif %}">
Maintenance
<span class="ml-2 {% if tab == 'rusak' %}bg-kerinci/10 text-kerinci{% else %}bg-gray-100 text-gray-500{% endif %} text-[10px] px-2 py-0.5 rounded-full font-extrabold">{{ counts.rusak }}</span>
</a>
</div>
<!-- Search and Filters -->
<div class="mb-4 flex flex-col sm:flex-row sm:items-center sm:justify-between space-y-3 sm:space-y-0">
<form id="searchForm" method="GET" class="relative w-full sm:w-96">
<input type="hidden" name="tab" value="{{ tab }}">
<input type="hidden" name="cat" value="{{ cat_filter }}">
<input type="text" id="searchInput" name="q" value="{{ search_query }}" placeholder="Cari NIK, nama, area, lokasi, kode unit, atau aset..." 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 class="flex space-x-1 bg-gray-100 p-1 rounded-xl w-full sm:w-auto">
<a href="?tab={{ tab }}&cat=karyawan&q={{ search_query }}" class="flex-1 sm:flex-none text-center px-4 py-2 rounded-lg text-sm font-bold transition-colors {% if cat_filter == 'karyawan' %}bg-kerinci text-white shadow-sm{% else %}text-gray-500 hover:text-gray-900 hover:bg-gray-200{% endif %}">Aset Karyawan</a>
<a href="?tab={{ tab }}&cat=network&q={{ search_query }}" class="flex-1 sm:flex-none text-center px-4 py-2 rounded-lg text-sm font-bold transition-colors {% if cat_filter == 'network' %}bg-kerinci text-white shadow-sm{% else %}text-gray-500 hover:text-gray-900 hover:bg-gray-200{% endif %}">Aset Network</a>
</div>
</div>
<!-- Table -->
<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">Kode Unit</th>
<th class="p-4 font-bold min-w-[250px]">Nama Aset</th>
<th class="p-4 font-bold text-center">Status</th>
{% if tab != 'tersedia' %}
<th class="p-4 font-bold">{% if cat_filter == "network" %}Lokasi{% else %}Dipegang Oleh{% endif %}</th>
{% endif %}
<th class="p-4 font-bold text-center">Riwayat Unit</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-gray-50">
{% for unit in units %}
<tr class="hover:bg-gray-50/50 transition-colors">
<td class="p-4 text-gray-500 font-medium text-center">{{ forloop.counter }}</td>
<td class="p-4">
<a href="{% url 'unit_history' unit.id %}" class="font-bold text-gray-900 hover:text-kerinci transition-colors inline-block w-max">{{ unit.unit_code }}</a>
</td>
<td class="p-4">
<a href="{% url 'asset_units' unit.asset.id %}" class="block group">
<p class="font-medium text-gray-800 group-hover:text-kerinci transition-colors">{{ unit.asset.name }}</p>
<p class="text-[10px] text-gray-400 mt-0.5">{{ unit.asset.category.name }}</p>
</a>
</td>
<td class="p-4 text-center">
<button onclick="openStatusModal('{{ unit.id }}', '{{ unit.unit_code }}', '{{ unit.status }}', '{% if unit.assigned_to %}{{ unit.assigned_to.name|escapejs }}{% endif %}', '{{ unit.asset.category.name|escapejs }}', '{{ unit.area|default_if_none:""|escapejs }}', '{{ unit.location|default_if_none:""|escapejs }}')" class="hover:opacity-80 transition-opacity focus:outline-none focus:ring-2 focus:ring-kerinci focus:ring-offset-1 rounded-md" title="Klik untuk ubah status">
{% if unit.status == 'tersedia' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-emerald-50 border border-emerald-200 text-emerald-700 hover:bg-emerald-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Tersedia <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% elif unit.status == 'digunakan' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-blue-50 border border-blue-200 text-blue-700 hover:bg-blue-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Digunakan <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% elif unit.status == 'rusak' %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-red-50 border border-red-200 text-red-700 hover:bg-red-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">Maintenance <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% else %}
<span style="display:inline-flex;align-items:center;gap:4px;" class="bg-gray-50 border border-gray-200 text-gray-600 hover:bg-gray-100 transition-colors px-2.5 py-1 rounded-md text-[10px] font-extrabold uppercase tracking-wider">{{ unit.get_status_display }} <svg width="10" height="10" fill="none" stroke="currentColor" viewBox="0 0 24 24" style="opacity:0.7;flex-shrink:0;"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg></span>
{% endif %}
</button>
</td>
{% if tab != 'tersedia' %}
<td class="p-4">
{% if unit.assigned_to %}
<a href="{% url 'employee_detail' unit.assigned_to.id %}" class="flex flex-col group w-max">
<p class="font-bold text-gray-800 transition-colors group-hover:text-kerinci">{{ unit.assigned_to.name }}</p>
<p class="text-xs text-gray-400 transition-colors group-hover:text-kerinci/70">NIK: {{ unit.assigned_to.nik }}</p>
</a>
{% elif unit.area %}
<div class="flex flex-col">
<p class="font-bold text-kerinci">{{ unit.area }}</p>
<p class="text-xs text-gray-500 max-w-[200px] truncate" title="{{ unit.location }}">{{ unit.location }}</p>
</div>
{% else %}
<span class="text-gray-300 text-xs italic">-</span>
{% endif %}
</td>
{% endif %}
<td class="p-4 text-center">
<a href="{% url 'unit_history' unit.id %}" class="inline-flex items-center justify-center p-2 text-kerinci hover:bg-kerinci-light rounded-xl transition-colors" title="Riwayat Unit">
<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 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="{% if tab == 'tersedia' %}5{% else %}6{% endif %}" 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 unit {% if tab == 'rusak' %}maintenance{% else %}{{ tab }}{% endif %} saat ini.</p>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% include 'components/pagination.html' %}
</div>
<div id="statusUnitModal" class="fixed inset-0 z-50 hidden flex items-center justify-center">
<div class="absolute inset-0 bg-gray-900/40 backdrop-blur-sm" onclick="closeStatusUnitModal()"></div>
<div class="bg-white rounded-2xl shadow-2xl w-11/12 max-w-md relative mx-auto z-10 p-6">
<h3 class="text-xl font-bold text-gray-900 mb-4">Update Status Unit</h3>
<p class="text-sm text-gray-500 mb-1">Kode Unit: <strong id="su_code" class="text-gray-900"></strong></p>
<p id="su_assigned_info" class="text-sm text-gray-500 mb-4 hidden">Dipegang Oleh: <strong id="su_assigned_name" class="text-gray-900"></strong></p>
<form id="statusUnitForm" method="POST" class="space-y-4">
{% csrf_token %}
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Status Baru</label>
<select id="su_status" name="status" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="tersedia" id="opt_su_tersedia">Tersedia</option>
<option value="digunakan" id="opt_su_digunakan" class="hidden" disabled>Digunakan</option>
<option value="rusak">Diperbaiki (Rusak / Maintenance)</option>
</select>
<p id="su_bast_warning" class="text-xs text-amber-600 mt-1 hidden font-bold">* Aset sedang digunakan. Pengembalian atau Mutasi harus melalui menu Distribusi Aset.</p>
</div>
<div id="su_notes_container" class="hidden">
<label class="block text-sm font-bold text-gray-700 mb-1">Catatan Kejadian <span class="text-red-500">*</span></label>
<textarea id="su_notes" name="notes" rows="2" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Jelaskan alasan perbaikan / keluhan kerusakan..."></textarea>
</div>
<div id="su_network_fields" class="hidden space-y-4 pt-4 border-t border-gray-100 mt-4">
<p class="text-xs font-bold text-gray-500 uppercase">Detail Lokasi Pemasangan</p>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Area <span class="text-red-500">*</span></label>
<select id="su_area" name="area" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50">
<option value="">-- Pilih Area --</option>
<option value="Regulating Weir (RW)">Regulating Weir (RW)</option>
<option value="Jakon">Jakon</option>
<option value="Beringin Tunggal (BT)">Beringin Tunggal (BT)</option>
<option value="DAM">DAM</option>
<option value="Adit 1">Adit 1</option>
<option value="Adit 2">Adit 2</option>
<option value="Adit 3">Adit 3</option>
<option value="Gudang Induk (GI)">Gudang Induk (GI)</option>
<option value="Vertical Shaft (VS)">Vertical Shaft (VS)</option>
<option value="Power House (PH)">Power House (PH)</option>
<option value="Lain-lainnya">Lain-lainnya</option>
</select>
</div>
<div>
<label class="block text-sm font-bold text-gray-700 mb-1">Lokasi Spesifik <span class="text-red-500">*</span></label>
<input type="text" id="su_location" name="location" class="w-full px-4 py-2 rounded-lg border border-gray-200 text-sm focus:outline-none focus:border-kerinci focus:ring-1 focus:ring-kerinci bg-gray-50" placeholder="Misal: Dinding server room barat...">
</div>
</div>
<div class="mt-6 flex justify-end space-x-3 pt-4 border-t border-gray-100">
<button type="button" onclick="closeStatusUnitModal()" class="px-4 py-2 border border-gray-300 text-gray-700 font-bold rounded-lg text-sm hover:bg-gray-50 transition-colors">Batal</button>
<button type="submit" class="px-4 py-2 bg-kerinci text-white font-bold rounded-lg text-sm shadow-sm hover:bg-kerinci/90 transition-colors">
Simpan Status
</button>
</div>
</form>
</div>
</div>
<script>
// JS for status modal
function openStatusModal(id, fullCode, status, assignedTo, categoryName, area, location) {
document.getElementById('statusUnitForm').action = '/unit/' + id + '/status/';
document.getElementById('su_code').innerText = fullCode;
const assignedInfo = document.getElementById('su_assigned_info');
const assignedName = document.getElementById('su_assigned_name');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '' && assignedTo !== 'true') {
assignedName.innerText = assignedTo;
assignedInfo.classList.remove('hidden');
} else {
assignedInfo.classList.add('hidden');
}
const statSelect = document.getElementById('su_status');
const optTersedia = document.getElementById('opt_su_tersedia');
const optDigunakan = document.getElementById('opt_su_digunakan');
const warnText = document.getElementById('su_bast_warning');
const netFields = document.getElementById('su_network_fields');
const areaInput = document.getElementById('su_area');
const locInput = document.getElementById('su_location');
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
areaInput.value = area && area !== 'None' ? area : '';
locInput.value = location && location !== 'None' ? location : '';
const isNetwork = categoryName && categoryName.includes('Network');
if (assignedTo && assignedTo !== 'None' && assignedTo !== '') {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = true;
optTersedia.classList.add('hidden');
warnText.classList.remove('hidden');
let empName = assignedTo === 'true' ? 'karyawan' : assignedTo;
warnText.innerHTML = '* Aset sedang digunakan oleh <strong class="font-extrabold underline">' + empName + '</strong>. Pengembalian harus melalui menu Distribusi Aset.';
} else if (isNetwork) {
optDigunakan.disabled = false;
optDigunakan.classList.remove('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
} else {
optDigunakan.disabled = true;
optDigunakan.classList.add('hidden');
optTersedia.disabled = false;
optTersedia.classList.remove('hidden');
warnText.classList.add('hidden');
}
statSelect.value = status;
statSelect.onchange = function() {
const notesContainer = document.getElementById('su_notes_container');
const notesInput = document.getElementById('su_notes');
if (this.value === 'rusak') {
notesContainer.classList.remove('hidden');
notesInput.required = true;
} else {
notesContainer.classList.add('hidden');
notesInput.required = false;
}
if ((this.value === 'digunakan' || this.value === 'rusak') && isNetwork) {
netFields.classList.remove('hidden');
areaInput.required = true;
locInput.required = true;
} else {
netFields.classList.add('hidden');
areaInput.required = false;
locInput.required = false;
}
};
statSelect.onchange();
document.getElementById('statusUnitModal').classList.remove('hidden');
}
function closeStatusUnitModal() {
document.getElementById('statusUnitModal').classList.add('hidden');
}
// 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();
});
}
</script>
{% endblock %}
{% block page_title_guide %}Manajemen Status Aset{% endblock %}
{% block page_guide_content %}
<div class="space-y-4">
<p>Halaman <strong>Status Aset</strong> memungkinkan Anda untuk memantau kondisi fisik secara *real-time* dari setiap unit individu. 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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Filter Kategori & Kondisi</h4>
<p>Gunakan tab untuk melihat barang yang <strong>Tersedia</strong> (gudang), <strong>Digunakan</strong> (dipegang karyawan/dipasang), atau dalam masa <strong>Maintenance</strong> (rusak). Anda juga bisa memisahkan khusus Aset Karyawan dan Network.</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.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Mengubah Status secara Manual (Penting)</h4>
<p>Klik langsung pada <strong>Label/Badge Status</strong> (contoh: label "Tersedia" warna hijau) di dalam tabel untuk membuka pop-up. Dari sana Anda bisa mengubah status barang tersebut secara manual menjadi *Maintenance* atau lainnya jika ada kerusakan fisik.</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-indigo-500 bg-indigo-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="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</div>
<div>
<h4 class="font-bold text-gray-900 mb-1">Riwayat Unit & Ekspor</h4>
<p>Sama seperti halaman lain, klik ikon <strong>Jam / Waktu</strong> untuk melacak rekam jejak historis unit tersebut, serta gunakan tombol <strong>Ekspor PDF</strong> untuk mencetak daftar aset berdasarkan filter status yang sedang Anda lihat.</p>
</div>
</div>
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuStatus');
if (menu) menu.style.display = 'none';
});
</script>
+164
View File
@@ -0,0 +1,164 @@
{% extends 'base.html' %}
{% block page_title %}Riwayat Unit{% endblock %}
{% block content %}
<div class="mb-8 flex flex-col sm:flex-row sm:justify-between items-start space-y-4 sm:space-y-0">
<div>
<p class="text-xs font-bold text-kerinci uppercase tracking-widest mb-1">Riwayat Unit</p>
<h2 class="text-3xl font-extrabold text-gray-900">{{ unit.unit_code }}</h2>
<p class="text-sm text-gray-500 mt-2">
Dari Aset: <a href="{% url 'asset_units' unit.asset.id %}" class="font-bold text-blue-600 hover:underline">{{ unit.asset.name }}</a>
</p>
</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('exportMenuHistory'); 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 Riwayat</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="exportMenuHistory" 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 'unit_history_export_pdf' unit.id %}" 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 'unit_history_export_excel' unit.id %}" 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>
<a href="{% url 'asset_units' unit.asset.id %}" class="bg-white border border-gray-200 rounded-xl shadow-sm px-4 py-2 text-sm font-bold text-gray-700 hover:bg-gray-50 transition-colors flex items-center space-x-2 justify-center text-center w-full sm:w-auto flex-1 sm:flex-none">
<span>Kembali</span>
</a>
</div>
</div>
<!-- Komponen Terpasang (Configuration Items) -->
<div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6 w-full mb-6">
<div class="flex items-center justify-between mb-4 pb-3 border-b border-gray-100">
<div>
<h3 class="text-base font-extrabold text-gray-900 flex items-center space-x-2">
<svg class="w-5 h-5 text-kerinci" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"></path></svg>
<span>Komponen Terpasang (Configuration Items)</span>
</h3>
<p class="text-xs text-gray-500 mt-0.5">Daftar komponen hardware, peripheral, dan modul yang aktif terpasang pada perangkat ini.</p>
</div>
<span class="text-xs font-bold bg-blue-50 text-blue-700 px-3 py-1 rounded-full border border-blue-200">
{{ unit.components.count }} Komponen
</span>
</div>
{% if unit.components.all %}
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
{% for comp in unit.components.all %}
<div class="bg-gray-50/70 hover:bg-gray-50 p-4 rounded-xl border border-gray-200/70 transition-colors flex flex-col justify-between">
<div>
<div class="flex items-center justify-between gap-1 mb-1">
<span class="font-mono text-xs font-black text-gray-800">{{ comp.ci_code }}</span>
<span class="text-[10px] font-bold px-2 py-0.5 rounded bg-white text-gray-600 border border-gray-200">
{{ comp.get_category_display }}
</span>
</div>
<h4 class="font-bold text-sm text-gray-900 leading-snug">{{ comp.name }}</h4>
<p class="text-xs text-gray-500 mt-0.5">{{ comp.brand|default:"-" }}{% if comp.model_series %} &bull; {{ comp.model_series }}{% endif %}</p>
{% if comp.serial_number %}
<p class="text-[11px] text-gray-400 font-mono mt-1">S/N: {{ comp.serial_number }}</p>
{% endif %}
</div>
<div class="mt-3 pt-2.5 border-t border-gray-200/50 flex items-center justify-between text-xs">
<span class="font-bold text-emerald-700 text-[11px]">{{ comp.get_condition_display }}</span>
<a href="{% url 'ci_detail' comp.id %}" class="text-kerinci font-bold hover:underline inline-flex items-center space-x-1">
<span>Lihat CI</span>
<svg class="w-3 h-3" 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>
</div>
</div>
{% endfor %}
</div>
{% else %}
<div class="p-6 text-center text-gray-400 text-xs italic bg-gray-50/50 rounded-xl border border-dashed border-gray-200">
Belum ada komponen Configuration Item yang tercatat terpasang pada perangkat ini.
</div>
{% endif %}
</div>
<div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-8 w-full">
<h3 class="text-lg font-bold text-gray-900 mb-8 border-b border-gray-100 pb-4">Timeline Kejadian</h3>
<div class="relative border-l border-gray-200 ml-3 md:ml-4 space-y-8">
{% for log in logs %}
<div class="relative pl-8 md:pl-10">
<!-- Timeline Node (Icon) -->
<div class="absolute -left-4 top-1 w-8 h-8 rounded-full border-4 border-white flex items-center justify-center
{% if log.action == 'created' %}bg-gray-200 text-gray-600
{% elif log.action == 'assigned' %}bg-blue-100 text-blue-600
{% elif log.action == 'returned' %}bg-emerald-100 text-emerald-600
{% elif log.action == 'maintenance_in' %}bg-red-100 text-red-600
{% elif log.action == 'maintenance_out' %}bg-emerald-100 text-emerald-600
{% elif log.action == 'mutation' %}bg-purple-100 text-purple-600
{% elif log.action == 'retired' %}bg-gray-800 text-white
{% else %}bg-gray-200 text-gray-600{% endif %}">
{% if log.action == 'created' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M12 4v16m8-8H4"></path></svg>
{% elif log.action == 'assigned' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M14 5l7 7m0 0l-7 7m7-7H3"></path></svg>
{% elif log.action == 'returned' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"></path></svg>
{% elif log.action == 'maintenance_out' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M5 13l4 4L19 7"></path></svg>
{% elif log.action == 'maintenance_in' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M11.42 15.17L17.25 21A2.652 2.652 0 0021 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 11-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 004.486-6.336l-3.276 3.277a3.004 3.004 0 01-2.25-2.25l3.276-3.276a4.5 4.5 0 00-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437l1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008z"></path></svg>
{% elif log.action == 'mutation' %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"></path></svg>
{% else %}
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
{% endif %}
</div>
<!-- Content -->
<div class="pt-1.5 pb-2">
<div class="flex flex-col md:flex-row md:items-center justify-between mb-2">
<h4 class="font-bold text-gray-900 text-base flex items-center space-x-2">
<span>{{ log.get_action_display }}</span>
</h4>
<span class="text-xs font-bold text-gray-400 mt-1 md:mt-0">{{ log.timestamp|date:"d M Y, H:i" }}</span>
</div>
{% if log.employee %}
<a href="{% url 'employee_detail' log.employee.id %}" class="flex items-center space-x-2 mb-2 group w-max">
<div class="w-6 h-6 rounded-full bg-kerinci-light text-kerinci flex items-center justify-center font-bold text-[9px] uppercase transition-colors group-hover:bg-kerinci group-hover:text-white">{{ log.employee.name|make_list|first }}</div>
<div>
<p class="font-bold text-gray-700 text-xs transition-colors group-hover:text-kerinci">{{ log.employee.name }}</p>
</div>
</a>
{% elif log.deleted_employee_name %}
<div class="flex items-center space-x-2 mb-2 w-max opacity-60">
<div class="w-6 h-6 rounded-full bg-gray-200 text-gray-500 flex items-center justify-center font-bold text-[9px] uppercase">{{ log.deleted_employee_name|make_list|first }}</div>
<div>
<p class="font-bold text-gray-500 text-xs">{{ log.deleted_employee_name }} <span class="text-[10px] font-normal italic">(Dihapus)</span></p>
</div>
</div>
{% endif %}
{% if log.notes %}
<p class="text-sm text-gray-600 mt-1.5 leading-relaxed">{{ log.notes }}</p>
{% endif %}
</div>
</div>
{% empty %}
<div class="pl-8 text-gray-400 text-sm italic">Belum ada riwayat tercatat untuk unit ini.</div>
{% endfor %}
</div>
</div>
{% endblock %}
<script>
document.addEventListener('click', function() {
var menu = document.getElementById('exportMenuHistory');
if (menu) menu.style.display = 'none';
});
</script>
+101
View File
@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Detail Unit - {{ unit.unit_code }}</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
kerinci: '#215c45',
}
}
}
}
</script>
<style>
body { font-family: 'Nunito', sans-serif; }
</style>
</head>
<body class="bg-gray-50 min-h-screen p-4 sm:p-8 text-gray-800">
<div class="max-w-2xl mx-auto">
<!-- Logo Header -->
<div class="flex items-center justify-center mb-8">
<h1 class="text-3xl font-black tracking-tighter text-[#002060]">IT <span class="text-green-800 text-xl tracking-wide font-extrabold ml-1">ALL ROLE</span></h1>
</div>
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 overflow-hidden mb-6">
<div class="bg-[#002060] p-6 text-white text-center">
<p class="text-green-400 text-xs font-bold uppercase tracking-widest mb-1">{{ unit.asset.category.name }}</p>
<h2 class="text-2xl font-extrabold">{{ unit.asset.name }}</h2>
<p class="text-blue-200 mt-1">Kode Unit: <span class="font-bold text-white">{{ unit.unit_code }}</span></p>
</div>
<div class="p-6 sm:p-8 space-y-6">
<!-- Status Badge -->
<div class="flex flex-col items-center justify-center border-b border-gray-100 pb-6">
<p class="text-sm font-bold text-gray-500 mb-2 uppercase">Status Saat Ini</p>
{% if unit.status == 'tersedia' %}
<span class="bg-green-100 text-green-700 px-6 py-2 rounded-xl text-sm font-black uppercase tracking-wider">Tersedia</span>
{% elif unit.status == 'digunakan' %}
<span class="bg-blue-100 text-blue-700 px-6 py-2 rounded-xl text-sm font-black uppercase tracking-wider">Digunakan</span>
{% else %}
<span class="bg-red-100 text-red-700 px-6 py-2 rounded-xl text-sm font-black uppercase tracking-wider">Maintenance</span>
{% endif %}
</div>
<!-- Assignment / Location Details -->
<div class="bg-gray-50 rounded-2xl p-6">
{% if unit.assigned_to %}
<p class="text-xs font-bold text-gray-500 uppercase mb-1">Dipegang Oleh</p>
<p class="text-lg font-bold text-gray-900">{{ unit.assigned_to.name }}</p>
<p class="text-sm text-gray-500">NIK: {{ unit.assigned_to.nik }}</p>
{% elif unit.area %}
<p class="text-xs font-bold text-gray-500 uppercase mb-1">Lokasi Pemasangan</p>
<p class="text-lg font-bold text-green-700">{{ unit.area }}</p>
<p class="text-sm text-gray-600 mt-1">{{ unit.location }}</p>
{% else %}
<p class="text-sm font-bold text-gray-400 text-center italic py-2">Unit ini sedang tidak digunakan (disimpan di IT).</p>
{% endif %}
</div>
</div>
</div>
<!-- History -->
<div class="bg-white rounded-3xl shadow-sm border border-gray-100 p-6 sm:p-8">
<h3 class="text-lg font-bold text-gray-900 mb-6 border-b border-gray-100 pb-4">Riwayat Aset</h3>
<div class="relative border-l-2 border-gray-100 ml-3 space-y-8">
{% for log in logs %}
<div class="relative pl-6">
<!-- Dot -->
<div class="absolute -left-[9px] top-1 w-4 h-4 rounded-full border-4 border-white {% if forloop.first %}bg-kerinci{% else %}bg-gray-300{% endif %}"></div>
<p class="text-xs font-bold text-gray-400 mb-1">{{ log.timestamp|date:"d M Y, H:i" }}</p>
<p class="text-sm font-bold text-gray-800">{{ log.get_action_display }}</p>
{% if log.notes %}
<p class="text-sm text-gray-600 mt-1">{{ log.notes }}</p>
{% endif %}
{% if log.employee %}
<p class="text-xs font-bold text-gray-500 mt-2 flex items-center">
<svg class="w-3 h-3 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
{{ log.employee.name }}
</p>
{% endif %}
</div>
{% empty %}
<p class="text-sm text-gray-500 italic pl-6">Belum ada riwayat tercatat.</p>
{% endfor %}
</div>
</div>
<div class="text-center mt-8 text-xs text-gray-400 font-bold">
<p>&copy; 2026 IT Management - Kerinci Hydropower</p>
</div>
</div>
</body>
</html>