diff --git a/assets/views/__init__.py b/assets/views/__init__.py index dea89e3..8655360 100644 --- a/assets/views/__init__.py +++ b/assets/views/__init__.py @@ -66,6 +66,8 @@ from .ci_views import ( ci_remove, ci_replace, ci_report_damage, + ci_export_excel, + ci_export_pdf, ) # Consumable Item (Barang Habis Pakai) @@ -159,6 +161,8 @@ __all__ = [ 'ci_remove', 'ci_replace', 'ci_report_damage', + 'ci_export_excel', + 'ci_export_pdf', # Consumable Items 'consumable_list', 'consumable_detail', diff --git a/assets/views/ci_views.py b/assets/views/ci_views.py index 4185805..bd57097 100644 --- a/assets/views/ci_views.py +++ b/assets/views/ci_views.py @@ -3,7 +3,7 @@ from datetime import datetime from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth.decorators import login_required from django.contrib import messages -from django.http import JsonResponse +from django.http import HttpResponse, JsonResponse from django.db import transaction from django.db.models import Count, Q from django.core.paginator import Paginator @@ -496,3 +496,258 @@ def ci_report_damage(request, ci_id): messages.success(request, f'Komponen {ci.ci_code} selesai diperbaiki dan siap digunakan.') return redirect(request.META.get('HTTP_REFERER', 'ci_list')) + + +@login_required +def ci_export_excel(request): + """Menghasilkan laporan Excel profesional untuk katalog Configuration Item.""" + from openpyxl import Workbook + from openpyxl.styles import Font, Alignment, PatternFill, Border, Side + + search_query = request.GET.get('q', '').strip() + status_filter = request.GET.get('status', '').strip() + category_filter = request.GET.get('category', '').strip() + condition_filter = request.GET.get('condition', '').strip() + + ci_qs = ConfigurationItem.objects.select_related( + 'installed_on', 'installed_on__asset', 'installed_on__assigned_to', 'assigned_to' + ).order_by('category', 'ci_code') + + if status_filter: + if status_filter == 'repair': + ci_qs = ci_qs.filter(status__in=['under_inspection', 'under_repair']) + else: + ci_qs = ci_qs.filter(status=status_filter) + + if category_filter: + ci_qs = ci_qs.filter(category=category_filter) + + if condition_filter: + ci_qs = ci_qs.filter(condition=condition_filter) + + if search_query: + ci_qs = ci_qs.filter( + Q(ci_code__icontains=search_query) | + Q(name__icontains=search_query) | + Q(brand__icontains=search_query) | + Q(model_series__icontains=search_query) | + Q(serial_number__icontains=search_query) | + Q(specifications__icontains=search_query) | + Q(installed_on__unit_code__icontains=search_query) | + Q(assigned_to__name__icontains=search_query) + ) + + wb = Workbook() + ws = wb.active + ws.title = "Katalog CI" + + title_font = Font(size=14, bold=True, color="002060") + subtitle_font = Font(size=10, italic=True, color="555555") + header_font = Font(bold=True, color="FFFFFF") + header_fill = PatternFill(start_color="002060", end_color="002060", fill_type="solid") + center_align = Alignment(horizontal="center", vertical="center") + left_align = Alignment(horizontal="left", vertical="center") + thin_border = Border( + left=Side(style='thin', color='CCCCCC'), + right=Side(style='thin', color='CCCCCC'), + top=Side(style='thin', color='CCCCCC'), + bottom=Side(style='thin', color='CCCCCC') + ) + + ws.merge_cells('A1:J1') + ws['A1'] = "LAPORAN CONFIGURATION ITEM (CI) - PT. KERINCI HYDROPOWER" + ws['A1'].font = title_font + ws['A1'].alignment = left_align + + ws.merge_cells('A2:J2') + ws['A2'] = f"Tanggal Ekspor: {datetime.now().strftime('%d %B %Y %H:%M')} WIB | Dicetak oleh: {request.user.get_full_name() or request.user.username}" + ws['A2'].font = subtitle_font + ws['A2'].alignment = left_align + + headers = [ + "No", "Kode CI", "Nama Komponen", "Kategori", "Merek & Model", + "Nomor Seri (S/N)", "Status", "Kondisi", "Perangkat Terpasang", "PIC / Pengguna" + ] + ws.append([]) + ws.append(headers) + + for col_idx in range(1, len(headers) + 1): + cell = ws.cell(row=4, column=col_idx) + cell.font = header_font + cell.fill = header_fill + cell.alignment = center_align + + for idx, ci in enumerate(ci_qs, 1): + installed = f"{ci.installed_on.unit_code} ({ci.installed_on.asset.name})" if ci.installed_on else "-" + pic = ci.assigned_to.name if ci.assigned_to else (ci.installed_on.assigned_to.name if ci.installed_on and ci.installed_on.assigned_to else "-") + row = [ + idx, + ci.ci_code, + ci.name, + ci.get_category_display(), + f"{ci.brand or ''} {ci.model_series or ''}".strip() or "-", + ci.serial_number or "-", + ci.get_status_display(), + ci.get_condition_display(), + installed, + pic + ] + ws.append(row) + curr_row = ws.max_row + for col_idx in range(1, len(headers) + 1): + c = ws.cell(row=curr_row, column=col_idx) + c.border = thin_border + if col_idx in [1, 2, 7, 8]: + c.alignment = center_align + else: + c.alignment = left_align + + col_widths = {'A': 6, 'B': 18, 'C': 26, 'D': 16, 'E': 20, 'F': 20, 'G': 16, 'H': 14, 'I': 24, 'J': 22} + for col, width in col_widths.items(): + ws.column_dimensions[col].width = width + + response = HttpResponse(content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') + filename = f"laporan_configuration_item_{datetime.now().strftime('%Y%m%d_%H%M%S')}.xlsx" + response['Content-Disposition'] = f'attachment; filename="{filename}"' + wb.save(response) + return response + + +@login_required +def ci_export_pdf(request): + """Menghasilkan laporan PDF ringkasan status Configuration Item.""" + from reportlab.lib.pagesizes import A4, landscape + from reportlab.lib.units import mm + from reportlab.lib.colors import HexColor, white + from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer + from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle + from reportlab.lib.enums import TA_CENTER, TA_LEFT + from io import BytesIO + + search_query = request.GET.get('q', '').strip() + status_filter = request.GET.get('status', '').strip() + category_filter = request.GET.get('category', '').strip() + condition_filter = request.GET.get('condition', '').strip() + + ci_qs = ConfigurationItem.objects.select_related( + 'installed_on', 'installed_on__asset', 'installed_on__assigned_to', 'assigned_to' + ).order_by('category', 'ci_code') + + if status_filter: + if status_filter == 'repair': + ci_qs = ci_qs.filter(status__in=['under_inspection', 'under_repair']) + else: + ci_qs = ci_qs.filter(status=status_filter) + + if category_filter: + ci_qs = ci_qs.filter(category=category_filter) + + if condition_filter: + ci_qs = ci_qs.filter(condition=condition_filter) + + if search_query: + ci_qs = ci_qs.filter( + Q(ci_code__icontains=search_query) | + Q(name__icontains=search_query) | + Q(brand__icontains=search_query) | + Q(model_series__icontains=search_query) | + Q(serial_number__icontains=search_query) | + Q(specifications__icontains=search_query) | + Q(installed_on__unit_code__icontains=search_query) | + Q(assigned_to__name__icontains=search_query) + ) + + buffer = BytesIO() + doc = SimpleDocTemplate( + buffer, + pagesize=landscape(A4), + leftMargin=10 * mm, + rightMargin=10 * mm, + topMargin=10 * mm, + bottomMargin=10 * mm + ) + + styles = getSampleStyleSheet() + title_style = ParagraphStyle( + 'CITitle', + parent=styles['Normal'], + fontName='Helvetica-Bold', + fontSize=14, + leading=16, + textColor=HexColor('#002060'), + alignment=TA_LEFT + ) + meta_style = ParagraphStyle( + 'CIMeta', + parent=styles['Normal'], + fontName='Helvetica-Oblique', + fontSize=8, + leading=10, + textColor=HexColor('#555555'), + alignment=TA_LEFT + ) + cell_style = ParagraphStyle( + 'CICell', + parent=styles['Normal'], + fontName='Helvetica', + fontSize=7.5, + leading=9, + alignment=TA_LEFT + ) + cell_center = ParagraphStyle( + 'CICellCenter', + parent=cell_style, + alignment=TA_CENTER + ) + + elements = [ + Paragraph("LAPORAN CONFIGURATION ITEM (CI) - PT. KERINCI HYDROPOWER", title_style), + Spacer(1, 2 * mm), + Paragraph(f"Dicetak pada: {datetime.now().strftime('%d %B %Y %H:%M')} WIB | Oleh: {request.user.get_full_name() or request.user.username} | Total: {ci_qs.count()} item", meta_style), + Spacer(1, 4 * mm) + ] + + table_data = [ + ["No", "Kode CI", "Nama Komponen", "Kategori", "Merek/Model", "S/N", "Status", "Kondisi", "Terpasang", "PIC"] + ] + + for idx, ci in enumerate(ci_qs, 1): + installed = ci.installed_on.unit_code if ci.installed_on else "-" + pic = ci.assigned_to.name if ci.assigned_to else (ci.installed_on.assigned_to.name if ci.installed_on and ci.installed_on.assigned_to else "-") + table_data.append([ + str(idx), + Paragraph(ci.ci_code, cell_center), + Paragraph(ci.name, cell_style), + Paragraph(ci.get_category_display(), cell_style), + Paragraph(f"{ci.brand or ''} {ci.model_series or ''}".strip() or "-", cell_style), + Paragraph(ci.serial_number or "-", cell_style), + Paragraph(ci.get_status_display(), cell_center), + Paragraph(ci.get_condition_display(), cell_center), + Paragraph(installed, cell_style), + Paragraph(pic, cell_style), + ]) + + col_widths = [10*mm, 28*mm, 45*mm, 26*mm, 35*mm, 30*mm, 25*mm, 23*mm, 28*mm, 27*mm] + t = Table(table_data, colWidths=col_widths, repeatRows=1) + t.setStyle(TableStyle([ + ('BACKGROUND', (0, 0), (-1, 0), HexColor('#002060')), + ('TEXTCOLOR', (0, 0), (-1, 0), white), + ('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'), + ('FONTSIZE', (0, 0), (-1, 0), 8), + ('ALIGN', (0, 0), (-1, -1), 'LEFT'), + ('ALIGN', (0, 0), (0, -1), 'CENTER'), + ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'), + ('TOPPADDING', (0, 0), (-1, -1), 3), + ('BOTTOMPADDING', (0, 0), (-1, -1), 3), + ('GRID', (0, 0), (-1, -1), 0.5, HexColor('#DDDDDD')), + ('ROWBACKGROUNDS', (0, 1), (-1, -1), [white, HexColor('#F9FAFB')]), + ])) + + elements.append(t) + doc.build(elements) + + buffer.seek(0) + response = HttpResponse(buffer.getvalue(), content_type='application/pdf') + filename = f"laporan_configuration_item_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf" + response['Content-Disposition'] = f'inline; filename="{filename}"' + return response diff --git a/itam_core/urls.py b/itam_core/urls.py index 681e335..e6cf8ed 100644 --- a/itam_core/urls.py +++ b/itam_core/urls.py @@ -11,6 +11,7 @@ from assets.views import ( employee_list, employee_export_pdf, employee_detail, employee_detail_export_pdf, employee_create, employee_edit, employee_delete, employee_activate, ci_list, ci_detail, ci_create, ci_edit, ci_assign, ci_remove, ci_replace, ci_report_damage, + ci_export_excel, ci_export_pdf, asset_export_pdf, asset_export_excel, backup_database_view, asset_units_export_excel, unit_history_export_excel, status_aset_export_excel, distribusi_export_excel, employee_export_excel, employee_detail_export_excel, @@ -72,6 +73,8 @@ urlpatterns = [ path('karyawan//activate/', employee_activate, name='employee_activate'), # Configuration Items (CI / CMDB) path('ci/', ci_list, name='ci_list'), + path('ci/export/', ci_export_pdf, name='ci_export_pdf'), + path('ci/export-excel/', ci_export_excel, name='ci_export_excel'), path('ci/create/', ci_create, name='ci_create'), path('ci//', ci_detail, name='ci_detail'), path('ci//edit/', ci_edit, name='ci_edit'), diff --git a/templates/ci_list.html b/templates/ci_list.html index 39ff7c8..a11cbc0 100644 --- a/templates/ci_list.html +++ b/templates/ci_list.html @@ -1,204 +1,183 @@ {% extends 'base.html' %} -{% block page_title %}Configuration Item (CI / CMDB){% endblock %} +{% block page_title %}Configuration Item{% endblock %} + +{% block page_title_guide %}Panduan Configuration Item (CMDB){% endblock %} +{% block page_guide_content %} +
+

Modul Configuration Item (CI) digunakan untuk melacak dan mengelola komponen hardware modular, peripheral, dan modul pendukung perangkat IT (misalnya: RAM, SSD/HDD, kartu grafis, adaptor, monitor eksternal, mouse, keyboard).

+
+

Hubungan Perangkat & Karyawan

+

Setiap CI dapat berdiri sendiri di gudang (Tersedia), terpasang pada Unit Aset induk (misal: SSD di dalam laptop ACR-GEN11-001), atau dipegang langsung oleh PIC Karyawan.

+
+
    +
  • Tersedia: Komponen berada di gudang/workshop IT dan siap dialokasikan.
  • +
  • Digunakan: Terpasang pada unit perangkat aktif atau dipegang karyawan.
  • +
  • Maintenance: Sedang dalam proses pengecekan atau servis teknis.
  • +
  • Pensiun / Bricked: Komponen telah rusak total atau tidak dapat digunakan kembali.
  • +
+
+{% endblock %} {% block content %} -
+
-

Manajemen Aset • CMDB

+

Manajemen Aset

-

Configuration Item (CI)

- - CMDB & Komponen - +

Configuration Item

+
-

Pelacakan komponen internal, peripheral, dan modul pendukung perangkat IT.

+
+ + +
{% if not is_read_only %} - {% endif %}
- -
-
-
-

Total Komponen

-

{{ counts.total }}

-

Terdaftar di CMDB

-
-
- -
-
-
-
-

Sedang Digunakan

-

{{ counts.in_use }}

-

Terpasang / Dipegang

-
-
- -
-
-
-
-

Tersedia (Gudang)

-

{{ counts.available }}

-

Siap dialokasikan

-
-
- -
-
-
-
-

Dalam Perbaikan

-

{{ counts.under_repair }}

-

Inspeksi / Maintenance

-
-
- -
-
-
- - -
- + + -
-
+
+ -
- - -
+ {% if category_filter %}{% endif %} + {% if condition_filter %}{% endif %} + + + - + {% for cat_val, cat_label in categories %} - + {% endfor %} - + {% for cond_val, cond_label in condition_choices %} - + {% endfor %} {% if search_query or category_filter or condition_filter or status_filter %} - + Reset {% endif %} - +
-
+
- - + + - + - + - + {% for item in items %} - - - + + - - {% empty %} - {% endfor %} @@ -257,7 +233,6 @@ {% include 'components/pagination.html' %} -
    -
  • Barang Masuk: Mencatat penambahan stok dari pengadaan/pembelian, transfer, atau retur sisa teknisi.
  • -
  • Barang Keluar: Mencatat konsumsi material oleh teknisi dengan keterkaitan ke tiket support, work order, atau unit aset terkait.
  • +
  • Barang Masuk: Penambahan stok dari pengadaan/pembelian, transfer, atau retur sisa teknisi.
  • +
  • Barang Keluar: Konsumsi material oleh teknisi dengan keterkaitan ke tiket support, work order, atau unit aset.
  • Stock Opname: Penyesuaian fisik berkala dengan alasan audit yang wajib diisi.
{% endblock %} {% block content %} - -
+
-

Manajemen Aset • Logistik Habis Pakai

+

Manajemen Aset

Consumable Item

- - Network & Support - - +
-

Pengelolaan persediaan kabel, konektor RJ45, thermal paste, cable ties, fastener, dan perlengkapan teknisi IT.

- -
+ +
+ +
+ + +
+ {% if not is_read_only %} - - - - + +
+ + + {% endif %} - - -
- -
- -
-
-

Total Jenis

-

{{ counts.total }}

-

Item Terdaftar

-
-
- -
-
- - -
-
-

Akumulasi Stok

-

{{ counts.total_qty|floatformat:0 }}

-

*Agregat kuantitas

-
-
- -
-
- - -
-
-

Stok Normal

-

{{ counts.available }}

-

Di atas batas min

-
-
- -
-
- - -
-
-

Stok Menipis

-

{{ counts.low_stock }}

-

Perlu reorder

-
-
- -
-
- - -
-
-

Stok Habis

-

{{ counts.out_of_stock }}

-

Saldo 0

-
-
- -
-
-
- - -
+ + - -
-
+ +
+ -
- - -
+ {% if category_filter %}{% endif %} + {% if location_filter %}{% endif %} + + + - + {% for cat_val, cat_label in categories %} - + {% endfor %} - + {% for loc in locations %} - + {% endfor %} {% if search_query or category_filter or location_filter or status_filter %} - + Reset {% endif %} - +
- -
+ +
-
NoKode ItemNoKode Item Nama & Komponen KategoriNomor Seri (S/N)Nomor Seri (S/N) Perangkat / Pengguna Kondisi StatusAksiAksi
{{ forloop.counter }} - - {{ item.ci_code }} +
{{ forloop.counter }} + + {{ item.ci_code }} - - {{ item.name }} + + {{ item.name }} -

{{ item.brand|default:"-" }}{% if item.model_series %} • {{ item.model_series }}{% endif %}

+ {% if item.brand or item.model_series %} +

{{ item.brand|default:"" }} {{ item.model_series|default:"" }}

+ {% endif %}
- - {{ item.get_category_display }} - + + {{ item.get_category_display }} - {{ item.serial_number|default:"-" }} + + {{ item.serial_number|default:"-" }} {% if item.installed_on %} -
- -
- Terpasang: {{ item.installed_on.unit_code }} - {% if item.installed_on.assigned_to %} -

PIC: {{ item.installed_on.assigned_to.name }}

- {% endif %} -
+
+ {{ item.installed_on.unit_code }}
+

{{ item.installed_on.asset.name }}

+ {% if item.installed_on.assigned_to %} +

PIC: {{ item.installed_on.assigned_to.name }}

+ {% endif %} {% elif item.assigned_to %} -
- -
- Dipegang: {{ item.assigned_to.name }} -

NIK: {{ item.assigned_to.nik }}

-
-
- {% elif item.status == 'available' %} - - {{ item.location|default:"Gudang IT" }} - +

{{ item.assigned_to.name }}

+

Pegang Langsung

{% else %} - - + Gudang / Tidak terpasang {% endif %}
- {% if item.condition == 'new' %} - Baru - {% elif item.condition == 'good' %} - Bagus + {% if item.condition == 'new' or item.condition == 'good' %} + {{ item.get_condition_display }} {% elif item.condition == 'fair' %} - Bekas + {{ item.get_condition_display }} + {% elif item.condition == 'poor' %} + {{ item.get_condition_display }} {% else %} - Rusak + {{ item.get_condition_display }} {% endif %} @@ -207,34 +186,34 @@ {% elif item.status == 'in_use' %} Digunakan {% elif item.status == 'under_repair' or item.status == 'under_inspection' %} - Perbaikan + Maintenance {% else %} Pensiun {% endif %}
- + {% if not is_read_only %} {% if item.status == 'available' %} - {% elif item.status == 'in_use' %} {% if item.installed_on %} - {% endif %} - {% endif %} - {% endif %} @@ -243,11 +222,8 @@
-
- -

Belum ada Configuration Item yang cocok dengan kriteria pencarian.

-
+
+ Belum ada data Configuration Item untuk kategori ini.
+
- - - - - - - - - - - + + + + + + + + + + + - + {% for item in page_obj %} - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - {% empty %} - {% endfor %}
Kode ItemNama Barang & MerekKategoriSpesifikasiSatuanStok TersediaStok MinLokasiStatusAksi
NoKode ItemNama Barang & MerekKategoriSpesifikasiSatuanStokLokasiStatusAksi
- +
{{ forloop.counter }} + {{ item.item_code }} - + + + {{ item.name }} + {% if item.brand %} -
Merek: {{ item.brand }}
+

Merek: {{ item.brand }}

{% endif %}
- - {{ item.get_category_display|truncatewords:2 }} - + + {{ item.get_category_display }} + {{ item.specification|default:"-" }} - {{ item.base_unit }} - {% if item.purchase_unit %} -
- 1 {{ item.purchase_unit }} = {{ item.conversion_rate|floatformat:0 }} {{ item.base_unit }} -
- {% endif %} +
+ {{ item.base_unit }} - - {{ item.formatted_stock }} - + + {{ item.formatted_stock }} + / + {{ item.minimum_stock|floatformat:0 }} - {{ item.formatted_minimum_stock }} + + {{ item.location }} - - - {{ item.location }} - - + {% if item.stock_status == 'out_of_stock' %} - - - Habis - + Habis {% elif item.stock_status == 'low_stock' %} - - - Menipis - + Menipis {% else %} - - - Tersedia - + Aman {% endif %} +
- + {% if not is_read_only %} - - {% endif %}
@@ -303,32 +213,17 @@
-
-
- -
-

Tidak ada consumable item ditemukan

-

- {% 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 %} -

-
+
+ Belum ada data Consumable Item untuk kategori ini.
- - {% include 'components/pagination.html' %}
-