Initial commit - expense
Deploy to VPS (PAT over HTTPS) / deploy (push) Has been cancelled

This commit is contained in:
root
2026-06-01 15:01:03 +07:00
parent 9e9fab4a3f
commit 1c1418f3e0
123 changed files with 18622 additions and 10376 deletions
@@ -1,11 +1,12 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<section class="content-header">
<div class="container-fluid">
@@ -16,7 +17,6 @@
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
</li>
</ol>
</div>
</div>
@@ -45,7 +45,7 @@
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.entertainment.store') }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.entertainment.store') }}" enctype="multipart/form-data">
@csrf
@include('backend.layouts.partials.messages')
<div class="row">
@@ -57,7 +57,7 @@
<div class="mb-3">
<label class="form-label">Jenis <span class="font-italic font-weight-normal">(required)</span></label>
<select class="form-control form-control-md" name="jenis" required >
<option value="">Pilih Jenis</option>
<option value="" disabled {{ old('jenis') == '' ? 'selected' : '' }}>Pilih Jenis</option>
<option value="entertainment" {{ old('jenis') == 'entertainment' ? 'selected' : '' }} >Entertainment</option>
<option value="presentation" {{ old('jenis') == 'presentation' ? 'selected' : '' }}>Presentation</option>
<option value="sponsorship" {{ old('jenis') == 'sponsorship' ? 'selected' : '' }}>Sponsorship</option>
@@ -78,9 +78,25 @@
<label class="form-label">Alamat <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" class="form-control" name="alamat" id="alamat" required value="{{ old('alamat') }}">
</div>
<div class="mb-3">
<div class="row">
<div class="col-md-4">
<label>Nama Perusahaan <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="nama_perusahaan" class="form-control" placeholder="Contoh: PT. Maju Jaya" required value="{{ old('nama_perusahaan') }}">
</div>
<div class="col-md-4">
<label>Jabatan <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="jabatan" class="form-control" placeholder="Contoh: Manager Operasional" required value="{{ old('jabatan') }}">
</div>
<div class="col-md-4">
<label>Jenis Usaha <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="jenis_usaha" class="form-control" placeholder="Contoh: Farmasi / Manufaktur" required value="{{ old('jenis_usaha') }}">
</div>
</div>
<div class="mb-3 mt-3">
<label class="form-label">Total <span class="font-italic font-weight-normal">(required)</span></label>
<input type="string" class="form-control" name="total" id="total" required value="{{ old('total') }}">
<input type="text" class="form-control" name="total" id="total" required value="{{ old('total') }}">
</div>
<div class="mb-3">
<label class="form-label">Keterangan <span class="font-italic font-weight-normal">(required)</span></label>
@@ -122,13 +138,13 @@
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</form>
<div id="loading-spinner-overlay" class="d-none">
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<p>Submitting, please wait...</p>
<p class="mt-2">Submitting, please wait...</p>
</div>
</div>
</div>
@@ -137,21 +153,50 @@
</section>
<script>
new AutoNumeric('#total', {
digitGroupSeparator: '.', // Pemisah ribuan
decimalCharacter: ',', // Karakter desimal (tidak digunakan karena tanpa desimal)
currencySymbol: 'Rp.', // Simbol mata uang
decimalPlaces: 0, // Tidak ada angka desimal
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
});
$(document).ready(function () {
// 1. Inisialisasi AutoNumeric
const totalInput = new AutoNumeric('#total', {
digitGroupSeparator: '.', // Pemisah ribuan
decimalCharacter: ',', // Karakter desimal
currencySymbol: 'Rp. ', // Simbol mata uang
decimalPlaces: 0, // Tidak ada angka desimal
minimumValue: '0', // Cegah minus
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
});
document.getElementById('expense-form').addEventListener('submit', function (e) {
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
spinnerOverlay.classList.remove('d-none'); // Show overlay
spinnerOverlay.classList.add('d-flex'); // Use flexbox for centering
// 2. Mencegah Scroll Mouse Wheel pada Input Nominal
$('#total').on('wheel font-wheel', function(e) {
e.preventDefault();
$(this).blur();
});
// 3. Interseptor Form Submit untuk Validasi Maksimal Rp 1 Juta
$('#expense-form').on('submit', function (e) {
e.preventDefault(); // Tahan pengiriman sementara
const form = this;
const spinnerOverlay = $('#loading-spinner-overlay');
// Ambil nilai nominal mentah dari AutoNumeric
const totalExpense = totalInput.getNumber() || 0;
// Cek Aturan Bisnis: Tidak Boleh Lebih dari Rp 1.000.000
if (totalExpense > 1000000) {
Swal.fire({
title: 'Nominal Melebihi Batas!',
text: `Pengajuan Anda sebesar Rp ${new Intl.NumberFormat('id-ID').format(totalExpense)} melebihi batas maksimal yang diizinkan yaitu Rp 1.000.000. Mohon sesuaikan nominal Anda.`,
icon: 'error',
confirmButtonColor: '#d33',
confirmButtonText: 'Revisi Angka'
});
} else {
// Lolos Validasi -> Tampilkan Spinner & Eksekusi Submit
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
});
</script>
@include('backend.pages.forms.entertainment.partials.attachment-modal')
@include('backend.pages.forms.entertainment.partials.attachment-scripts')
@endsection
@endsection
@@ -1,11 +1,12 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<section class="content-header">
<div class="container-fluid">
@@ -16,12 +17,12 @@
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
</li>
</ol>
</div>
</div>
</div>
</section>
<style>
#loading-spinner-overlay {
position: fixed;
@@ -29,23 +30,20 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
z-index: 9999; /* High z-index to cover everything */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
}
.spinner-wrapper {
text-align: center;
color: white;
}
.spinner-wrapper { text-align: center; color: white; }
</style>
<section class="content">
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.entertainment.update', $form->id) }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.entertainment.update', $form->id) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('backend.layouts.partials.messages')
@@ -53,14 +51,15 @@
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
<input type="date" class="form-control" name="tanggal" required value="{{ $form->tanggal }}">
{{-- Diubah menjadi input date murni --}}
<input type="date" class="form-control" name="tanggal" required value="{{ \Carbon\Carbon::parse($form->tanggal)->format('Y-m-d') }}">
</div>
<div class="mb-3">
<label class="form-label">Jenis <span class="font-italic font-weight-normal">(required)</span></label>
<select class="form-control form-control-md" name="jenis" required>
<option value="">Pilih Jenis</option>
<option value="entertainment" {{ $form->jenis == 'entertainment' ? 'selected' : '' }}>Entertainment</option>
<option value="presentation" {{ $form->jenis == 'presentation' ? 'selected' : '' }}>Presentation</option>
<option value="presentation" {{ $form->jenis == 'presentation' ? 'selected' : '' }}>Presentation</option>
<option value="sponsorship" {{ $form->jenis == 'sponsorship' ? 'selected' : '' }}>Sponsorship</option>
</select>
</div>
@@ -79,9 +78,25 @@
<label class="form-label">Alamat <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" class="form-control" name="alamat" id="alamat" required value="{{ $form->alamat }}">
</div>
<div class="mb-3">
<div class="row">
<div class="col-md-4">
<label>Nama Perusahaan <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="nama_perusahaan" class="form-control" required value="{{ old('nama_perusahaan', $form->nama_perusahaan) }}">
</div>
<div class="col-md-4">
<label>Jabatan <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="jabatan" class="form-control" required value="{{ old('jabatan', $form->jabatan) }}">
</div>
<div class="col-md-4">
<label>Jenis Usaha <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" name="jenis_usaha" class="form-control" required value="{{ old('jenis_usaha', $form->jenis_usaha) }}">
</div>
</div>
<div class="mb-3 mt-3">
<label class="form-label">Total <span class="font-italic font-weight-normal">(required)</span></label>
<input type="string" class="form-control" name="total" id="total" required value="{{ $form->total }}">
<input type="text" class="form-control" name="total" id="total" required value="{{ $form->total }}">
</div>
<div class="mb-3">
<label class="form-label">Keterangan <span class="font-italic font-weight-normal">(required)</span></label>
@@ -89,6 +104,7 @@
</div>
</div>
{{-- Lampiran Existing --}}
<div class="col-12">
<hr class="my-4">
<h5 class="mb-3">Lampiran Saat Ini</h5>
@@ -100,55 +116,41 @@
<th>Nama File</th>
<th style="width: 120px;" class="text-center">Preview</th>
<th style="width: 120px;" class="text-center">Download</th>
<th style="width: 100px;" class="text-center">Delete</th>
<th style="width: 100px;" class="text-center">Aksi</th>
</tr>
</thead>
<tbody>
@forelse ($attachments as $attachment)
<tr class="entertainment-attachment-row">
<td>{{ $attachment['category_label'] ?? '-' }}</td>
<td>{{ ucwords(str_replace('_', ' ', $attachment['file_category'])) }}</td>
<td>{{ $attachment['filename'] }}</td>
<td class="text-center">
<button type="button"
class="btn btn-sm btn-outline-secondary entertainment-preview-trigger"
data-preview-type="{{ $attachment['preview_type'] }}"
data-preview-source="{{ $attachment['preview_url'] ?? '' }}"
data-download-url="{{ $attachment['download_url'] ?? '' }}"
data-filename="{{ $attachment['filename'] }}">
Preview
<button type="button" class="btn btn-sm btn-outline-secondary entertainment-preview-trigger"
data-preview-type="{{ $attachment['preview_type'] }}"
data-preview-source="{{ $attachment['preview_url'] }}"
data-download-url="{{ $attachment['download_url'] }}"
data-filename="{{ $attachment['filename'] }}">Preview</button>
</td>
<td class="text-center">
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank">Download</a>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger entertainment-delete-existing-attachment"
data-delete-url="{{ route('forms.entertainment.attachments.destroy', [$form->id, $attachment['id']]) }}">
<i class="fas fa-trash"></i>
</button>
</td>
<td class="text-center">
@if (!empty($attachment['download_url']))
<a href="{{ $attachment['download_url'] }}" class="btn btn-sm btn-outline-success" target="_blank" rel="noopener">Download</a>
@else
<span class="text-muted">Tidak tersedia</span>
@endif
</td>
<td class="text-center">
@if (!empty($attachment['can_delete']))
<button type="button"
class="btn btn-sm btn-outline-danger entertainment-delete-existing-attachment"
data-delete-url="{{ route('forms.entertainment.attachments.destroy', [$form->id, $attachment['id']]) }}">
<i class="fas fa-trash"></i>
</button>
@else
<span class="text-muted">Tidak tersedia</span>
@endif
</td>
</tr>
@empty
<tr class="entertainment-empty-row">
<td colspan="5" class="text-center text-muted">Belum ada attachment.</td>
</tr>
<tr class="text-center text-muted"><td colspan="5">Belum ada lampiran tersimpan.</td></tr>
@endforelse
</tbody>
</table>
</div>
</div>
<div class="col-12">
<hr class="my-4">
{{-- Lampiran Baru --}}
<div class="col-12 mt-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<h5 class="mb-0">Tambah Lampiran Baru</h5>
<button type="button" class="btn btn-sm btn-primary" id="entertainment-add-attachment-row">
@@ -156,7 +158,7 @@
</button>
</div>
<div class="table-responsive">
<table class="table table-bordered table-striped mb-0" id="entertainment-new-attachments-table" data-next-index="0">
<table class="table table-bordered align-middle" id="entertainment-new-attachments-table">
<thead class="bg-light">
<tr>
<th style="width: 30%;">Kategori</th>
@@ -166,27 +168,21 @@
</tr>
</thead>
<tbody>
<tr class="entertainment-empty-row">
<td colspan="4" class="text-center text-muted">Belum ada attachment.</td>
</tr>
<tr class="entertainment-empty-row"><td colspan="4" class="text-center text-muted">Belum ada lampiran baru.</td></tr>
</tbody>
</table>
</div>
<small class="text-muted d-block mt-2">
Maksimum 10 MB per file. Tidak diperbolehkan: {{ implode(', ', $entertainmentBlockedExtensions ?? []) }}.
</small>
</div>
<div class="col-12 text-right mt-4">
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</form>
</form>
<div id="loading-spinner-overlay" class="d-none">
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<div class="spinner-border text-primary" role="status"></div>
<p>Submitting, please wait...</p>
</div>
</div>
@@ -196,21 +192,37 @@
</section>
<script>
new AutoNumeric('#total', {
digitGroupSeparator: '.', // Pemisah ribuan
decimalCharacter: ',', // Karakter desimal (tidak digunakan karena tanpa desimal)
currencySymbol: 'Rp.', // Simbol mata uang
decimalPlaces: 0, // Tidak ada angka desimal
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
});
$(document).ready(function() {
// 1. Inisialisasi AutoNumeric Aman
const totalInput = new AutoNumeric('#total', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp. ',
decimalPlaces: 0,
minimumValue: '0',
unformatOnSubmit: true
});
document.getElementById('expense-form').addEventListener('submit', function (e) {
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
spinnerOverlay.classList.remove('d-none'); // Show overlay
spinnerOverlay.classList.add('d-flex'); // Use flexbox for centering
// 2. Cegah Scroll Wheel pada Input
$('#total').on('wheel', function(e) { e.preventDefault(); $(this).blur(); });
// 3. Interseptor Form Submit dengan Validasi 1 Juta
$('#expense-form').on('submit', function (e) {
const totalExpense = totalInput.getNumber() || 0;
if (totalExpense > 1000000) {
e.preventDefault();
Swal.fire({
title: 'Nominal Melebihi Batas!',
text: 'Total pengajuan melebihi batas Rp 1.000.000. Mohon revisi nominal Anda.',
icon: 'error'
});
} else {
$('#loading-spinner-overlay').removeClass('d-none').addClass('d-flex');
}
});
});
</script>
@include('backend.pages.forms.entertainment.partials.attachment-modal')
@include('backend.pages.forms.entertainment.partials.attachment-scripts')
@endsection
@endsection
File diff suppressed because it is too large Load Diff
@@ -26,11 +26,11 @@
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<div>
<div>
@include('backend.layouts.partials.messages')
<div class="row">
<div class="col-lg-6">
<div class="mb-3">
<div class="mb-3">
<label class="form-label">No Expense</label>
<input type="text" class="form-control" name="expense_number" value="{{ $form->expense_number }}" readonly>
</div>
@@ -55,6 +55,10 @@
<label class="form-label">NPWP / NIK</label>
<input type="text" class="form-control" name="nik_or_npwp" id="nik_or_npwp" readonly value="{{ $form->nik_or_npwp }}">
</div>
<div class="mb-3">
<label class="form-label">Nama Perusahaan</label>
<input type="text" class="form-control" name="nama_perusahaan" id="nama_perusahaan" readonly value="{{ $form->nama_perusahaan }}">
</div>
</div>
<div class="col-lg-6">
@@ -62,6 +66,14 @@
<label class="form-label">Alamat</label>
<input type="text" class="form-control" name="alamat" id="alamat" readonly value="{{ $form->alamat }}">
</div>
<div class="mb-3">
<label class="form-label">Jabatan</label>
<input type="text" class="form-control" name="jabatan" id="jabatan" readonly value="{{ $form->jabatan }}">
</div>
<div class="mb-3">
<label class="form-label">Jenis Usaha</label>
<input type="text" class="form-control" name="jenis_usaha" id="jenis_usaha" readonly value="{{ $form->jenis_usaha }}">
</div>
<div class="mb-3">
<label class="form-label">Total</label>
<input type="string" class="form-control" name="total" id="total" readonly value="{{ $form->total }}">
@@ -118,7 +130,7 @@
</div>
</div>
<div class="col-lg-12">
<div class="col-lg-12">
<div class="mb-3">
<label class="form-label">Status</label>
<input type="text" class="form-control" name="status" value="{{ $form->status }}" readonly>
@@ -130,196 +142,210 @@
@if (auth()->user()->can('approval.approve') && $form->status == 'On Progress')
<button type="button" class="btn btn-success final-approve-modal" data-id="{{ route('forms.entertainment.approve', $form->id) }}">Approve 1</button>
<button type="button"
class="btn btn-danger open-reject-modal"
data-action="{{ route('forms.entertainment.reject', $form->id) }}">
Reject
</button>
<button type="button"
class="btn btn-danger open-reject-modal"
data-action="{{ route('forms.entertainment.reject', $form->id) }}">
Reject
</button>
@elseif(auth()->user()->can('approval2.approve') && $form->status == 'Approved 1')
<button type="button" class="btn btn-success open-approve-modal" data-id="{{ route('forms.entertainment.approve2', $form->id) }}">Approve 2</button>
<button type="button"
class="btn btn-danger open-reject-modal"
data-action="{{ route('forms.entertainment.reject', $form->id) }}">
Reject
</button>
<button type="button"
class="btn btn-danger open-reject-modal"
data-action="{{ route('forms.entertainment.reject', $form->id) }}">
Reject
</button>
@elseif(auth()->user()->can('final_approval.approve') && $form->status == 'Approved 2')
<button type="button" class="btn btn-primary open-approve-modal" data-id="{{ route('forms.entertainment.final-approve', $form->id) }}">Final Approve</button>
@endif
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="approveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="approveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Loading spinner -->
<div id="loadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="modal fade" id="approveModal" tabindex="-1" role="dialog" aria-labelledby="approveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="approveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="approveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div id="loadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- Modal content (hidden initially) -->
<div id="modalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="user"></span>
</li>
<li class="list-group-item">
<strong>NIK/NPWP Penerima:</strong> <span id="nik_or_npwp"></span>
</li>
<li class="list-group-item">
<strong>Tanggal:</strong> <span id="tanggal"></span>
</li>
<li class="list-group-item">
<strong>Nama Penerima:</strong> <span id="name"></span>
</li>
<li class="list-group-item">
<strong>Jenis:</strong> <span id="jenis"></span>
</li>
<li class="list-group-item">
<strong>Keterangan:</strong> <span id="keterangan"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total:</strong> <span id="bukti_total"></span>
</li>
<li class="list-group-item">
<strong>Nominal Total:</strong> <span id="total_value"></span>
</li>
</ul>
</div>
</div>
<div id="modalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="modal_expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="modal_user"></span>
</li>
<li class="list-group-item">
<strong>NIK/NPWP Penerima:</strong> <span id="modal_nik_or_npwp"></span>
</li>
<li class="list-group-item">
<strong>Nama Perusahaan:</strong> <span id="modal_nama_perusahaan"></span>
</li>
<li class="list-group-item">
<strong>Jabatan:</strong> <span id="modal_jabatan"></span>
</li>
<li class="list-group-item">
<strong>Jenis Usaha:</strong> <span id="modal_jenis_usaha"></span>
</li>
<li class="list-group-item">
<strong>Tanggal:</strong> <span id="modal_tanggal"></span>
</li>
<li class="list-group-item">
<strong>Nama Penerima:</strong> <span id="modal_name"></span>
</li>
<li class="list-group-item">
<strong>Jenis:</strong> <span id="modal_jenis"></span>
</li>
<li class="list-group-item">
<strong>Keterangan:</strong> <span id="modal_keterangan"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total:</strong> <span id="modal_bukti_total"></span>
</li>
<li class="list-group-item">
<strong>Nominal Total:</strong> <span id="total_value"></span>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="finalApproveModal" tabindex="-1" role="dialog" aria-labelledby="finalApproveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="finalApproveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="approveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Loading spinner -->
<div id="finalLoadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="finalApproveModal" tabindex="-1" role="dialog" aria-labelledby="finalApproveModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form id="finalApproveForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="finalApproveModalLabel">Approve Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div id="finalLoadingSpinner" class="d-flex justify-content-center align-items-center" style="height: 200px;">
<div class="spinner-border text-primary" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<!-- Modal content (hidden initially) -->
<div id="finalModalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="final_expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="final_user"></span>
</li>
<li class="list-group-item">
<strong>NIK/NPWP Penerima:</strong> <span id="final_nik_or_npwp"></span>
</li>
<li class="list-group-item">
<strong>Tanggal:</strong> <span id="final_tanggal"></span>
</li>
<li class="list-group-item">
<strong>Nama Penerima:</strong> <span id="final_name"></span>
</li>
<li class="list-group-item">
<strong>Jenis:</strong> <span id="final_jenis"></span>
</li>
<li class="list-group-item">
<strong>Keterangan:</strong> <span id="final_keterangan"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total:</strong> <span id="final_bukti_total"></span>
</li>
</ul>
<p class="mt-2">Please select the items you want to approve:</p>
<ul class="list-group list-unstyled">
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="final_total" name="total" required>
<label class="custom-control-label" for="final_total">Total (<span id="final_total_value"></span>)</label>
</div>
</div>
</li>
</ul>
</div>
</div>
<div id="finalModalContent" class="d-none">
<p>Please review the details below:</p>
<ul class="list-group">
<li class="list-group-item">
<strong>Expense Number:</strong> <span id="final_expense_number"></span>
</li>
<li class="list-group-item">
<strong>User:</strong> <span id="final_user"></span>
</li>
<li class="list-group-item">
<strong>NIK/NPWP Penerima:</strong> <span id="final_nik_or_npwp"></span>
</li>
<li class="list-group-item">
<strong>Nama Perusahaan:</strong> <span id="final_nama_perusahaan"></span>
</li>
<li class="list-group-item">
<strong>Jabatan:</strong> <span id="final_jabatan"></span>
</li>
<li class="list-group-item">
<strong>Jenis Usaha:</strong> <span id="final_jenis_usaha"></span>
</li>
<li class="list-group-item">
<strong>Tanggal:</strong> <span id="final_tanggal"></span>
</li>
<li class="list-group-item">
<strong>Nama Penerima:</strong> <span id="final_name"></span>
</li>
<li class="list-group-item">
<strong>Jenis:</strong> <span id="final_jenis"></span>
</li>
<li class="list-group-item">
<strong>Keterangan:</strong> <span id="final_keterangan"></span>
</li>
<li class="list-group-item">
<strong>Bukti Total:</strong> <span id="final_bukti_total"></span>
</li>
</ul>
<p class="mt-2">Please select the items you want to approve:</p>
<ul class="list-group list-unstyled">
<li>
<div class="form-group">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="final_total" name="total" required>
<label class="custom-control-label" for="final_total">Total (<span id="final_total_value"></span>)</label>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="rejectModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="rejectForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="rejectModalLabel">Reject Expense</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="rejectRemarks">Remarks <span class="text-danger">*</span></label>
<textarea class="form-control" name="remarks" id="rejectRemarks" rows="3" required></textarea>
</div>
<p class="mb-0 text-muted small">Pengajuan akan ditolak setelah Anda mengirimkan catatan ini.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Reject</button>
</div>
</form>
</div>
</div>
</div>
</section>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Approve</button>
</div>
</form>
</div>
</div>
</div>
</section>
<section>
<div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="rejectModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="rejectForm" method="POST" action="">
@csrf
@method('PUT')
<div class="modal-header">
<h5 class="modal-title" id="rejectModalLabel">Reject Expense</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="rejectRemarks">Remarks <span class="text-danger">*</span></label>
<textarea class="form-control" name="remarks" id="rejectRemarks" rows="3" required></textarea>
</div>
<p class="mb-0 text-muted small">Pengajuan akan ditolak setelah Anda mengirimkan catatan ini.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Reject</button>
</div>
</form>
</div>
</div>
</div>
</section>
@endsection
@section('scripts')
@@ -329,7 +355,7 @@
decimalCharacter: ',', // Karakter desimal (tidak digunakan karena tanpa desimal)
currencySymbol: 'Rp.', // Simbol mata uang
decimalPlaces: 0, // Tidak ada angka desimal
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
unformatOnSubmit: true // Nilai asli tanpa format saat dikirimkan
});
</script>
@@ -351,131 +377,141 @@
});
$(document).on('click', '.open-approve-modal', function() {
const approveUrl = $(this).data('id');
const approveUrl = $(this).data('id');
// Show spinner and hide content initially
$('#loadingSpinner').show();
$('#modalContent').addClass('d-none');
// Show spinner and hide content initially
$('#loadingSpinner').show();
$('#modalContent').addClass('d-none');
$('#approveForm').attr('action', approveUrl); // Set the form action
$('#loadingSpinner').addClass('d-flex');
$('#approveModal').modal('show'); // Show the modal
$('#approveForm').attr('action', approveUrl); // Set the form action
$('#loadingSpinner').addClass('d-flex');
$('#approveModal').modal('show'); // Show the modal
// Get detail from /forms/entertainment/detail/{id}
$.get(approveUrl.replace(/approve2|final-approve/g, 'detail'), function (data) {
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
// Get detail from /forms/entertainment/detail/{id}
$.get(approveUrl.replace(/approve2|final-approve/g, 'detail'), function (data) {
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
$('#total_value').text(formatter.format(data.total));
$('#total_value').text(formatter.format(data.total));
// Detail data
$('#user').text(data.user.name);
$('#expense_number').text(data.expense_number);
$('#tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
// Detail data
$('#modal_user').text(data.user.name);
$('#modal_expense_number').text(data.expense_number);
$('#modal_tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
$('#nik_or_npwp').text(data.nik_or_npwp);
$('#name').text(data.name);
$('#jenis').text(data.jenis);
$('#keterangan').text(data.keterangan);
$('#modal_nik_or_npwp').text(data.nik_or_npwp);
// Tambahan Mapping Data Perusahaan
$('#modal_nama_perusahaan').text(data.nama_perusahaan || '-');
$('#modal_jabatan').text(data.jabatan || '-');
$('#modal_jenis_usaha').text(data.jenis_usaha || '-');
$('#modal_name').text(data.name);
$('#modal_jenis').text(data.jenis);
$('#modal_keterangan').text(data.keterangan);
$('#bukti_total').html(data.total ? '<a href="' + data.total + '" target="_blank">Download</a>' : '-');
$('#modal_bukti_total').html(data.total ? '<a href="' + data.total + '" target="_blank">Download</a>' : '-');
// Hide spinner and show content
$('#loadingSpinner').hide();
$('#loadingSpinner').removeClass('d-flex');
$('#loadingSpinner').addClass('d-none');
$('#modalContent').removeClass('d-none');
// Hide spinner and show content
$('#loadingSpinner').hide();
$('#loadingSpinner').removeClass('d-flex');
$('#loadingSpinner').addClass('d-none');
$('#modalContent').removeClass('d-none');
// Reset the total to zero
$('#total').val(0);
});
});
// Reset the total to zero
$('#total').val(0);
});
});
// Handle Approve Button Click
$(document).on('click', '.final-approve-modal', function() {
const approveUrl = $(this).data('id');
// Handle Approve Button Click
$(document).on('click', '.final-approve-modal', function() {
const approveUrl = $(this).data('id');
// Show spinner and hide content initially
$('#finalLoadingSpinner').show();
$('#finalModalContent').addClass('d-none');
// Show spinner and hide content initially
$('#finalLoadingSpinner').show();
$('#finalModalContent').addClass('d-none');
$('#finalApproveForm').attr('action', approveUrl); // Set the form action
$('#finalLoadingSpinner').addClass('d-flex');
$('#finalApproveModal').modal('show'); // Show the modal
$('#finalApproveForm').attr('action', approveUrl); // Set the form action
$('#finalLoadingSpinner').addClass('d-flex');
$('#finalApproveModal').modal('show'); // Show the modal
// Get detail from /forms/entertainment/detail/{id}
$.get(approveUrl.replace('approve', 'detail'), function (data) {
console.log(data);
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
// Get detail from /forms/entertainment/detail/{id}
$.get(approveUrl.replace('approve', 'detail'), function (data) {
console.log(data);
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0
});
$('#final_total_value').text(formatter.format(data.total));
$('#final_total_value').text(formatter.format(data.total));
// Assign data values to checkboxes
$('#final_total').data('value', data.total);
// Assign data values to checkboxes
$('#final_total').data('value', data.total);
// Detail data
$('#final_user').text(data.user.name);
$('#final_expense_number').text(data.expense_number);
$('#final_tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
// Detail data
$('#final_user').text(data.user.name);
$('#final_expense_number').text(data.expense_number);
$('#final_tanggal').text(new Date(data.created_at).toLocaleDateString('id-ID', {
year: 'numeric',
month: 'long',
day: 'numeric'
}));
$('#final_nik_or_npwp').text(data.nik_or_npwp);
$('#final_name').text(data.name);
$('#final_jenis').text(data.jenis);
$('#final_keterangan').text(data.keterangan);
$('#final_nik_or_npwp').text(data.nik_or_npwp);
// Tambahan Mapping Data Perusahaan
$('#final_nama_perusahaan').text(data.nama_perusahaan || '-');
$('#final_jabatan').text(data.jabatan || '-');
$('#final_jenis_usaha').text(data.jenis_usaha || '-');
$('#final_name').text(data.name);
$('#final_jenis').text(data.jenis);
$('#final_keterangan').text(data.keterangan);
$('#final_bukti_total').html(data.bukti_total ? '<a href="' + data.bukti_total + '" target="_blank">Download</a>' : '-');
$('#final_bukti_total').html(data.bukti_total ? '<a href="' + data.bukti_total + '" target="_blank">Download</a>' : '-');
// Hide spinner and show content
$('#finalLoadingSpinner').hide();
$('#finalLoadingSpinner').removeClass('d-flex');
$('#finalLoadingSpinner').addClass('d-none');
$('#finalModalContent').removeClass('d-none');
// Hide spinner and show content
$('#finalLoadingSpinner').hide();
$('#finalLoadingSpinner').removeClass('d-flex');
$('#finalLoadingSpinner').addClass('d-none');
$('#finalModalContent').removeClass('d-none');
// Reset the total to zero
$('#total').val(0);
});
});
// Reset the total to zero
$('#total').val(0);
});
});
// Update total dynamically
$('.custom-control-input').on('change', function () {
let total = 0;
$('.custom-control-input:checked').each(function () {
total += parseFloat($(this).data('value') || 0);
});
// Update total dynamically
$('.custom-control-input').on('change', function () {
let total = 0;
$('.custom-control-input:checked').each(function () {
total += parseFloat($(this).data('value') || 0);
});
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0,
});
const formatter = new Intl.NumberFormat('id-ID', {
style: 'currency',
currency: 'IDR',
minimumFractionDigits: 0,
});
$('#total').val(formatter.format(total));
});
$('#total').val(formatter.format(total));
});
// Uncheck all checkboxes when the modal is closed
$('#finalApproveModal').on('hidden.bs.modal', function () {
$('.custom-control-input').prop('checked', false); // Uncheck all checkboxes
$('#total').val('0'); // Reset total to 0
});
// Uncheck all checkboxes when the modal is closed
$('#finalApproveModal').on('hidden.bs.modal', function () {
$('.custom-control-input').prop('checked', false); // Uncheck all checkboxes
$('#total').val('0'); // Reset total to 0
});
</script>
@include('backend.pages.forms.entertainment.partials.attachment-modal')
@include('backend.pages.forms.entertainment.partials.attachment-scripts')
@endsection
@endsection
File diff suppressed because it is too large Load Diff
@@ -1,11 +1,12 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<section class="content-header">
<div class="container-fluid">
@@ -45,7 +46,7 @@
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.other.store') }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.other.store') }}" enctype="multipart/form-data">
@csrf
@include('backend.layouts.partials.messages')
<div class="row">
@@ -82,7 +83,7 @@
<div class="mb-3">
<div class="d-flex align-items-center justify-content-between">
<label class="form-label mb-0">Lampiran</label>
<button type="button" class="btn btn-outline-primary btn-sm" id="other-add-attachment-row">
<button type="button" class="btn btn-slate-custom btn-outline-primary btn-sm" id="other-add-attachment-row">
<i class="fas fa-plus mr-1"></i> Tambah Lampiran
</button>
</div>
@@ -113,7 +114,7 @@
<button type="submit" class="btn btn-primary ml-2">Submit</button>
</div>
</div>
</form>
</form>
@include('backend.components.attachment-preview-modal', [
'modalId' => 'otherAttachmentPreviewModal',
@@ -133,19 +134,44 @@
</section>
<script>
new AutoNumeric('#total', {
// 1. Inisialisasi AutoNumeric dengan batasan angka minimum nol
const totalAutoNumeric = new AutoNumeric('#total', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
minimumValue: '0',
unformatOnSubmit: true
});
// 2. Mematikan sliding wheel mouse (scrolling) pada kolom input nominal angka
document.getElementById('total').addEventListener('wheel', function (e) {
e.preventDefault();
this.blur();
});
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
document.getElementById('expense-form').addEventListener('submit', function () {
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
// 3. Interseptor Validasi Submit Form dengan Batasan Nilai Rp 1.000.000 bersih
document.getElementById('expense-form').addEventListener('submit', function (e) {
// Mengambil angka murni tanpa format simbol dari instance AutoNumeric
const rawTotalValue = totalAutoNumeric.getNumber() || 0;
if (rawTotalValue > 1000000) {
e.preventDefault(); // Batalkan pengiriman form ke route backend
Swal.fire({
title: 'Batas Angka Terlampaui!',
text: 'Pengajuan nominal Expense Other tidak diperbolehkan melebihi batas Rp 1.000.000. Mohon periksa kembali input Anda.',
icon: 'error',
confirmButtonColor: '#d33',
confirmButtonText: 'Revisi Data'
});
} else {
// Lolos validasi, aktifkan spinner overlay UI
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
}
});
const attachmentCategories = @json($attachmentCategories ?? ($otherAttachmentCategories ?? []));
@@ -394,4 +420,4 @@
addOtherAttachmentRow();
});
</script>
@endsection
@endsection
@@ -1,7 +1,7 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
@@ -45,7 +45,7 @@
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.other.update', $form->id) }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.other.update', $form->id) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('backend.layouts.partials.messages')
@@ -169,7 +169,7 @@
<button type="submit" class="btn btn-primary ml-2">Update</button>
</div>
</div>
</form>
</form>
@include('backend.components.attachment-preview-modal', [
'modalId' => 'otherExistingAttachmentPreviewModal',
@@ -195,18 +195,44 @@
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
new AutoNumeric('#total', {
// 1. Inisialisasi AutoNumeric dengan batasan angka minimum nol
const totalAutoNumeric = new AutoNumeric('#total', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
minimumValue: '0',
unformatOnSubmit: true
});
// 2. Mematikan sliding wheel mouse (scrolling) pada kolom input nominal angka
document.getElementById('total').addEventListener('wheel', function (e) {
e.preventDefault();
this.blur();
});
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
document.getElementById('expense-form').addEventListener('submit', function () {
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
// 3. Interseptor Validasi Submit Form dengan Batasan Nilai Rp 1.000.000 bersih
document.getElementById('expense-form').addEventListener('submit', function (e) {
// Mengambil angka murni tanpa format simbol dari instance AutoNumeric
const rawTotalValue = totalAutoNumeric.getNumber() || 0;
if (rawTotalValue > 1000000) {
e.preventDefault(); // Batalkan pengiriman form ke route backend
Swal.fire({
title: 'Batas Angka Terlampaui!',
text: 'Pengajuan nominal Expense Other tidak diperbolehkan melebihi batas Rp 1.000.000. Mohon periksa kembali input Anda.',
icon: 'error',
confirmButtonColor: '#d33',
confirmButtonText: 'Revisi Data'
});
} else {
// Lolos validasi, aktifkan spinner overlay UI
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
}
});
const attachmentCategories = @json($attachmentCategories ?? ($otherAttachmentCategories ?? []));
@@ -543,4 +569,4 @@
addOtherNewAttachmentRow();
});
</script>
@endsection
@endsection
File diff suppressed because it is too large Load Diff
@@ -1,11 +1,13 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
@@ -15,12 +17,12 @@
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
</li>
</ol>
</div>
</div>
</div>
</section>
<style>
#loading-spinner-overlay {
position: fixed;
@@ -28,8 +30,8 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
z-index: 9999; /* High z-index to cover everything */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
@@ -40,15 +42,17 @@
color: white;
}
</style>
@php
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
@endphp
<section class="content">
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.up-country.store') }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.up-country.store') }}" enctype="multipart/form-data">
@csrf
@include('backend.layouts.partials.messages')
<div class="row">
@@ -78,22 +82,22 @@
</div>
<div class="mb-3">
<label class="form-label">Allowance <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="allowance" id="allowance" value="{{ old('allowance') }}">
<input type="text" class="form-control autonumeric-input" name="allowance" id="allowance" value="{{ old('allowance') }}">
</div>
</div>
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label">Transport Dalam Kota <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="transport_dalkot" id="transport_dalkot" value="{{ old('transport_dalkot') }}">
<input type="text" class="form-control autonumeric-input" name="transport_dalkot" id="transport_dalkot" value="{{ old('transport_dalkot') }}">
</div>
<div class="mb-3">
<label class="form-label">Transport Antar Kota <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="transport_ankot" id="transport_ankot" value="{{ old('transport_ankot') }}">
<input type="text" class="form-control autonumeric-input" name="transport_ankot" id="transport_ankot" value="{{ old('transport_ankot') }}">
</div>
<div class="mb-3">
<label class="form-label">Hotel <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="hotel" id="hotel" value="{{ old('hotel') }}">
<input type="text" class="form-control autonumeric-input" name="hotel" id="hotel" value="{{ old('hotel') }}">
</div>
</div>
@@ -137,7 +141,7 @@
<button type="submit" class="btn btn-primary ml-2">Submit</button>
</div>
</form>
</form>
@include('backend.components.attachment-preview-modal', [
'modalId' => 'newAttachmentPreviewModal',
@@ -146,256 +150,284 @@
<div id="loading-spinner-overlay" class="d-none">
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<p>Sedang mengirim, mohon tunggu...</p>
<div class="spinner-border text-primary" role="status"></div>
<p class="mt-2">Sedang mengirim, mohon tunggu...</p>
</div>
</div>
</div>
</div>
</div>
</section>
@endsection
@section('scripts')
<script>
new AutoNumeric('#allowance', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#transport_dalkot', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#transport_ankot', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#hotel', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
const fileAccept = '.jpg,.jpeg,.png,.pdf';
let attachmentIndex = 0;
function categoryToLabel(value) {
if (!value) {
return 'Pilih Kategori';
}
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
return attachmentCategoryLabels[value];
}
return value
.replace(/_/g, ' ')
.replace(/\b\w/g, (char) => char.toUpperCase());
}
function buildCategoryOptions() {
return attachmentCategories
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
.join('');
}
function resetInlinePreview($row) {
$row
.find('.attachment-inline-preview')
.removeClass('bg-light')
.html('<i class="fas fa-file-upload text-muted"></i>');
}
function clearRowData($row) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl');
$row.removeData('previewType');
$row.removeData('previewSource');
resetInlinePreview($row);
$row.find('.preview-new-attachment').addClass('d-none');
$row.find('.preview-filename').text('');
}
function addAttachmentRow() {
const attachmentTableBody = $('#attachments-table tbody');
const emptyRowMarkup = `<tr class="attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran ditambahkan.</td></tr>`;
if (attachmentTableBody.find('.attachments-empty').length) {
attachmentTableBody.empty();
}
const index = attachmentIndex++;
const row = $(`
<tr class="attachment-row" data-index="${index}">
<td>
<select class="form-control attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${categoryToLabel('')}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center gap-2">
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}">
</div>
<div class="small text-muted mt-1 preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
Pratinjau
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`);
attachmentTableBody.append(row);
}
function removeAttachmentRow(button) {
const $row = $(button).closest('tr');
const attachmentTableBody = $('#attachments-table tbody');
const emptyRowMarkup = `<tr class="attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran ditambahkan.</td></tr>`;
clearRowData($row);
$row.remove();
if (!attachmentTableBody.find('.attachment-row').length) {
attachmentTableBody.append(emptyRowMarkup);
}
}
function setInlinePreview($row, type, source) {
const previewBox = $row.find('.attachment-inline-preview');
if (type === 'image' && source) {
previewBox
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">`)
.addClass('bg-light');
} else if (type === 'pdf') {
previewBox
.html('<i class="fas fa-file-pdf text-danger fa-lg"></i>')
.addClass('bg-light');
} else {
resetInlinePreview($row);
}
}
function openAttachmentModal(modalSelector, title, type, source) {
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none');
if (type === 'image' && source) {
$image.attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (type === 'pdf' && source) {
$object.attr('data', source).attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
$modal.modal('show');
}
}
function previewFile(input) {
const $input = $(input);
const $row = $input.closest('tr');
const previewButton = $row.find('.preview-new-attachment');
const filenameHolder = $row.find('.preview-filename');
clearRowData($row);
const file = input.files && input.files[0];
if (!file) {
return;
}
filenameHolder.text(file.name);
const extension = file.name.split('.').pop().toLowerCase();
if (['jpg', 'jpeg', 'png'].includes(extension)) {
const reader = new FileReader();
reader.onload = function (event) {
const source = event.target.result;
$row.data('previewType', 'image');
$row.data('previewSource', source);
setInlinePreview($row, 'image', source);
previewButton.removeClass('d-none');
// Gunakan DOMContentLoaded agar script terisolasi dan langsung jalan sebelum jQuery external selesai
document.addEventListener('DOMContentLoaded', function() {
try {
// ==========================================
// 1. INISIALISASI AUTONUMERIC ASLI & AMAN
// ==========================================
const autoNumericConfig = {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp. ',
decimalPlaces: 0,
unformatOnSubmit: true // Mengirim nilai integer murni ke backend
};
reader.readAsDataURL(file);
} else {
const objectUrl = URL.createObjectURL(file);
$row.data('previewType', 'pdf');
$row.data('previewSource', objectUrl);
$row.data('objectUrl', objectUrl);
setInlinePreview($row, 'pdf');
previewButton.removeClass('d-none');
const allowanceInput = new AutoNumeric('#allowance', autoNumericConfig);
const dalkotInput = new AutoNumeric('#transport_dalkot', autoNumericConfig);
const ankotInput = new AutoNumeric('#transport_ankot', autoNumericConfig);
const hotelInput = new AutoNumeric('#hotel', autoNumericConfig);
// ==========================================
// 2. BLOKIR SCROLL WHEEL DENGAN EVENT BROWSER NATIVE
// ==========================================
// Mencegah input berubah tanpa memicu error library
const inputIds = ['allowance', 'transport_dalkot', 'transport_ankot', 'hotel'];
inputIds.forEach(function(id) {
const el = document.getElementById(id);
if (el) {
el.addEventListener('wheel', function(e) {
e.preventDefault(); // Menghentikan angka bergulir
this.blur(); // Melepas fokus kursor
}, { passive: false });
}
});
// ==========================================
// 3. LOGIKA MULTI UPLOAD ATTACHMENT
// ==========================================
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
const fileAccept = '.jpg,.jpeg,.png,.pdf';
let attachmentIndex = 0;
function categoryToLabel(value) {
if (!value) return 'Pilih Kategori';
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
return attachmentCategoryLabels[value];
}
return value.replace(/_/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase());
}
function buildCategoryOptions() {
return attachmentCategories
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
.join('');
}
function resetInlinePreview($row) {
$row.find('.attachment-inline-preview')
.removeClass('bg-light')
.html('<i class="fas fa-file-upload text-muted"></i>');
}
function clearRowData($row) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl');
$row.removeData('previewType');
$row.removeData('previewSource');
resetInlinePreview($row);
$row.find('.preview-new-attachment').addClass('d-none');
$row.find('.preview-filename').text('');
}
function addAttachmentRow() {
const attachmentTableBody = $('#attachments-table tbody');
if (attachmentTableBody.find('.attachments-empty').length) {
attachmentTableBody.empty();
}
const index = attachmentIndex++;
const row = $(`
<tr class="attachment-row" data-index="${index}">
<td>
<select class="form-control attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${categoryToLabel('')}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center gap-2">
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}" required>
</div>
<div class="small text-muted mt-1 preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
Pratinjau
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`);
attachmentTableBody.append(row);
}
function removeAttachmentRow(button) {
const $row = $(button).closest('tr');
const attachmentTableBody = $('#attachments-table tbody');
const emptyRowMarkup = `<tr class="attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran ditambahkan.</td></tr>`;
clearRowData($row);
$row.remove();
if (!attachmentTableBody.find('.attachment-row').length) {
attachmentTableBody.append(emptyRowMarkup);
}
}
function setInlinePreview($row, type, source) {
const previewBox = $row.find('.attachment-inline-preview');
if (type === 'image' && source) {
previewBox
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau">`)
.addClass('bg-light');
} else if (type === 'pdf') {
previewBox
.html('<i class="fas fa-file-pdf text-danger fa-lg"></i>')
.addClass('bg-light');
} else {
resetInlinePreview($row);
}
}
function openAttachmentModal(modalSelector, title, type, source) {
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none');
if (type === 'image' && source) {
$image.attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (type === 'pdf' && source) {
$object.attr('data', source).attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
$modal.modal('show');
}
}
function previewFile(input) {
const $input = $(input);
const $row = $input.closest('tr');
const previewButton = $row.find('.preview-new-attachment');
const filenameHolder = $row.find('.preview-filename');
clearRowData($row);
const file = input.files && input.files[0];
if (!file) return;
filenameHolder.text(file.name);
const extension = file.name.split('.').pop().toLowerCase();
if (['jpg', 'jpeg', 'png'].includes(extension)) {
const reader = new FileReader();
reader.onload = function (event) {
const source = event.target.result;
$row.data('previewType', 'image');
$row.data('previewSource', source);
setInlinePreview($row, 'image', source);
previewButton.removeClass('d-none');
};
reader.readAsDataURL(file);
} else {
const objectUrl = URL.createObjectURL(file);
$row.data('previewType', 'pdf');
$row.data('previewSource', objectUrl);
$row.data('objectUrl', objectUrl);
setInlinePreview($row, 'pdf');
previewButton.removeClass('d-none');
}
}
// ==========================================
// 4. INTERCEPTOR FORM SUBMISSION DENGAN SWEETALERT (> 1 JUTA)
// ==========================================
$('#expense-form').on('submit', function (e) {
e.preventDefault();
const form = this;
// Mengambil nilai desimal asli dari object AutoNumeric
const allowance = allowanceInput.getNumber() || 0;
const transportDalkot = dalkotInput.getNumber() || 0;
const transportAnkot = ankotInput.getNumber() || 0;
const hotel = hotelInput.getNumber() || 0;
const totalExpense = allowance + transportDalkot + transportAnkot + hotel;
if (totalExpense > 1000000) {
Swal.fire({
title: 'Nominal Melebihi Batas Expense!',
text: `Total pengajuan Anda adalah Rp ${new Intl.NumberFormat('id-ID').format(totalExpense)}. Jumlah ini melebihi batas standar Rp 1.000.000. Apakah yakin tetap ajukan?`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Tetap Ajukan!',
cancelButtonText: 'No, Batalkan'
}).then((result) => {
if (result.isConfirmed) {
$('#loading-spinner-overlay').removeClass('d-none').addClass('d-flex');
form.submit();
}
});
} else {
$('#loading-spinner-overlay').removeClass('d-none').addClass('d-flex');
form.submit();
}
});
// ==========================================
// 5. EVENT BINDINGS
// ==========================================
$('#add-attachment-row').on('click', function (e) {
e.preventDefault();
addAttachmentRow();
});
$(document).on('click', '.remove-attachment-row', function () { removeAttachmentRow(this); });
$(document).on('change', '.attachment-file', function () { previewFile(this); });
$(document).on('click', '.preview-new-attachment', function () {
const $row = $(this).closest('tr');
const previewType = $row.data('previewType');
const previewSource = $row.data('previewSource');
const category = categoryToLabel($row.find('.attachment-category').val());
const modalSelector = $(this).data('modal') || '#newAttachmentPreviewModal';
openAttachmentModal(modalSelector, category, previewType, previewSource);
});
} catch (err) {
console.error("Local Script Error:", err);
}
}
$(function () {
const spinnerOverlay = $('#loading-spinner-overlay');
$('#expense-form').on('submit', function () {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
});
$('#add-attachment-row').on('click', function () {
addAttachmentRow();
});
$(document).on('click', '.remove-attachment-row', function () {
removeAttachmentRow(this);
});
$(document).on('change', '.attachment-file', function () {
previewFile(this);
});
$(document).on('click', '.preview-new-attachment', function () {
const $row = $(this).closest('tr');
const previewType = $row.data('previewType');
const previewSource = $row.data('previewSource');
const category = categoryToLabel($row.find('.attachment-category').val());
const modalSelector = $(this).data('modal') || '#newAttachmentPreviewModal';
openAttachmentModal(modalSelector, category, previewType, previewSource);
});
});
</script>
@endsection
@endsection
@@ -1,12 +1,13 @@
@extends('layouts.app')
@section('title')
Dashboard
Dashboard
@endsection
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
@@ -16,12 +17,12 @@
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="{{ route('dashboard.index') }}">Dashboard</a></li>
</li>
</ol>
</div>
</div>
</div>
</section>
<style>
#loading-spinner-overlay {
position: fixed;
@@ -29,8 +30,8 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
z-index: 9999; /* High z-index to cover everything */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
@@ -41,15 +42,17 @@
color: white;
}
</style>
@php
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []);
$attachmentCategories = $attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
@endphp
<section class="content">
<div class="container-fluid">
<div class="card card-primary card-outline">
<div class="card-body">
<form id="expense-form" method="POST" action="{{ route('forms.up-country.update', $form->id) }}" enctype="multipart/form-data">
<form id="expense-form" method="POST" action="{{ route('forms.up-country.update', $form->id) }}" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('backend.layouts.partials.messages')
@@ -68,7 +71,8 @@
</div>
<div class="mb-3">
<label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
<input type="date" class="form-control" name="tanggal" required value="{{ $form->tanggal }}">
<input type="date" class="form-control" name="tanggal" required
value="{{ old('tanggal', !empty($form->tanggal) ? date('Y-m-d', strtotime($form->tanggal)) : '') }}">
</div>
<div class="mb-3">
<label class="form-label">Tujuan <span class="font-italic font-weight-normal">(required)</span></label>
@@ -80,22 +84,22 @@
</div>
<div class="mb-3">
<label class="form-label">Allowance <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="allowance" id="allowance" value="{{ $form->allowance }}">
<input type="text" class="form-control" name="allowance" id="allowance" value="{{ $form->allowance }}">
</div>
</div>
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label">Transport Dalam Kota <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="transport_dalkot" id="transport_dalkot" value="{{ $form->transport_dalkot }}">
<input type="text" class="form-control" name="transport_dalkot" id="transport_dalkot" value="{{ $form->transport_dalkot }}">
</div>
<div class="mb-3">
<label class="form-label">Transport Antar Kota <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="transport_ankot" id="transport_ankot" value="{{ $form->transport_ankot }}">
<input type="text" class="form-control" name="transport_ankot" id="transport_ankot" value="{{ $form->transport_ankot }}">
</div>
<div class="mb-3">
<label class="form-label">Hotel <span class="font-italic font-weight-normal">(optional)</span></label>
<input type="string" class="form-control" name="hotel" id="hotel" value="{{ $form->hotel }}">
<input type="text" class="form-control" name="hotel" id="hotel" value="{{ $form->hotel }}">
</div>
</div>
@@ -201,7 +205,7 @@
<button type="submit" class="btn btn-primary ml-2">Save</button>
</div>
</form>
</form>
@include('backend.components.attachment-preview-modal', [
'modalId' => 'existingAttachmentPreviewModal',
@@ -217,7 +221,7 @@
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<p>Sedang mengirim, mohon tunggu...</p>
<p class="mt-2">Sedang mengirim, mohon tunggu...</p>
</div>
</div>
</div>
@@ -226,317 +230,333 @@
</section>
<script>
new AutoNumeric('#allowance', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#transport_dalkot', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#transport_ankot', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
new AutoNumeric('#hotel', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
const fileAccept = '.jpg,.jpeg,.png,.pdf';
let attachmentIndex = 0;
let newAttachmentsTableBody;
let existingAttachmentsTableBody;
let emptyNewRowMarkup = '';
let emptyExistingRowMarkup = '';
function categoryToLabel(value) {
if (!value) {
return 'Pilih Kategori';
}
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
return attachmentCategoryLabels[value];
}
return value
.replace(/_/g, ' ')
.replace(/\b\w/g, (char) => char.toUpperCase());
}
function buildCategoryOptions() {
return attachmentCategories
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
.join('');
}
function resetInlinePreview($row) {
$row
.find('.attachment-inline-preview')
.removeClass('bg-light')
.html('<i class="fas fa-file-upload text-muted"></i>');
}
function clearRowData($row) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl');
$row.removeData('previewType');
$row.removeData('previewSource');
resetInlinePreview($row);
$row.find('.preview-new-attachment').addClass('d-none');
$row.find('.preview-filename').text('');
}
function addAttachmentRow() {
if (!newAttachmentsTableBody) {
return;
}
if (newAttachmentsTableBody.find('.new-attachments-empty').length) {
newAttachmentsTableBody.empty();
}
const index = attachmentIndex++;
const row = $(`
<tr class="attachment-row" data-index="${index}">
<td>
<select class="form-control attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${categoryToLabel('')}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center gap-2">
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}">
</div>
<div class="small text-muted mt-1 preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none">
Pratinjau
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`);
newAttachmentsTableBody.append(row);
}
function removeAttachmentRow(button) {
if (!newAttachmentsTableBody) {
return;
}
const $row = $(button).closest('tr');
clearRowData($row);
$row.remove();
if (!newAttachmentsTableBody.find('.attachment-row').length) {
newAttachmentsTableBody.html(emptyNewRowMarkup);
}
}
function setInlinePreview($row, type, source) {
const previewBox = $row.find('.attachment-inline-preview');
if (type === 'image' && source) {
previewBox
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">`)
.addClass('bg-light');
} else if (type === 'pdf') {
previewBox
.html('<i class="fas fa-file-pdf text-danger fa-lg"></i>')
.addClass('bg-light');
} else {
resetInlinePreview($row);
}
}
function openAttachmentModal(modalSelector, title, type, source) {
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none');
if (type === 'image' && source) {
$image.attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (type === 'pdf' && source) {
$object.attr('data', source).attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
$modal.modal('show');
}
}
function previewFile(input) {
const $input = $(input);
const $row = $input.closest('tr');
const previewButton = $row.find('.preview-new-attachment');
const filenameHolder = $row.find('.preview-filename');
clearRowData($row);
const file = input.files && input.files[0];
if (!file) {
return;
}
filenameHolder.text(file.name);
const extension = file.name.split('.').pop().toLowerCase();
if (['jpg', 'jpeg', 'png'].includes(extension)) {
const reader = new FileReader();
reader.onload = function (event) {
const source = event.target.result;
$row.data('previewType', 'image');
$row.data('previewSource', source);
setInlinePreview($row, 'image', source);
previewButton.removeClass('d-none');
$(document).ready(function() {
try {
// ==========================================
// 1. INISIALISASI AUTONUMERIC ASLI (KEMBALI NORMAL & ANTI MINUS)
// ==========================================
const autoNumericConfig = {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp. ',
decimalPlaces: 0,
minimumValue: '0', // Mencegah nilai minus
unformatOnSubmit: true // Mengirimkan angka bersih ke backend
};
reader.readAsDataURL(file);
} else {
const objectUrl = URL.createObjectURL(file);
$row.data('previewType', 'pdf');
$row.data('previewSource', objectUrl);
$row.data('objectUrl', objectUrl);
setInlinePreview($row, 'pdf');
previewButton.removeClass('d-none');
}
}
$(function () {
const spinnerOverlay = $('#loading-spinner-overlay');
const allowanceInput = new AutoNumeric('#allowance', autoNumericConfig);
const dalkotInput = new AutoNumeric('#transport_dalkot', autoNumericConfig);
const ankotInput = new AutoNumeric('#transport_ankot', autoNumericConfig);
const hotelInput = new AutoNumeric('#hotel', autoNumericConfig);
$('#expense-form').on('submit', function () {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
});
newAttachmentsTableBody = $('#new-attachments-table tbody');
existingAttachmentsTableBody = $('#existing-attachments-table tbody');
emptyNewRowMarkup = `<tr class="new-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran baru.</td></tr>`;
emptyExistingRowMarkup = `<tr class="existing-attachments-empty text-center text-muted"><td colspan="5">Belum ada lampiran tersimpan.</td></tr>`;
const csrfToken = $('meta[name="csrf-token"]').attr('content');
if (csrfToken) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': csrfToken
}
// ==========================================
// 2. SOLUSI FIX SCROLLING: Blokir Paksa Menggunakan jQuery Native
// ==========================================
$('#allowance, #transport_dalkot, #transport_ankot, #hotel').on('wheel font-wheel', function(e) {
e.preventDefault();
$(this).blur(); // Melepas fokus kursor saat roda scroll digerakkan
});
}
$('#add-new-attachment-row').on('click', function () {
addAttachmentRow();
});
$(document).on('click', '.remove-attachment-row', function () {
removeAttachmentRow(this);
});
// ==========================================
// 3. LOGIKA MULTI UPLOAD ATTACHMENT
// ==========================================
const attachmentCategories = @json($attachmentCategories ?? ($upCountryAttachmentCategoryKeys ?? []));
const attachmentCategoryLabels = @json($attachmentCategoryLabels ?? ($upCountryAttachmentCategories ?? []));
const fileAccept = '.jpg,.jpeg,.png,.pdf';
let attachmentIndex = 0;
let newAttachmentsTableBody = $('#new-attachments-table tbody');
let existingAttachmentsTableBody = $('#existing-attachments-table tbody');
let emptyNewRowMarkup = `<tr class="new-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran baru.</td></tr>`;
let emptyExistingRowMarkup = `<tr class="existing-attachments-empty text-center text-muted"><td colspan="5">Belum ada lampiran tersimpan.</td></tr>`;
$(document).on('change', '.attachment-file', function () {
previewFile(this);
});
$(document).on('click', '.preview-new-attachment', function () {
const $row = $(this).closest('tr');
const previewType = $row.data('previewType');
const previewSource = $row.data('previewSource');
const category = categoryToLabel($row.find('.attachment-category').val());
openAttachmentModal('#newAttachmentPreviewModal', category, previewType, previewSource);
});
$(document).on('click', '.preview-existing-attachment', function () {
const button = $(this);
const previewType = button.data('preview-type');
const previewUrl = button.data('preview-url');
const downloadUrl = button.data('download-url');
const category = button.data('category') || 'Lampiran';
if (!previewUrl) {
if (downloadUrl) {
window.open(downloadUrl, '_blank');
}
return;
const csrfToken = $('meta[name="csrf-token"]').attr('content');
if (csrfToken) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': csrfToken
}
});
}
openAttachmentModal('#existingAttachmentPreviewModal', category, previewType, previewUrl);
});
function categoryToLabel(value) {
if (!value) return 'Pilih Kategori';
if (attachmentCategoryLabels && attachmentCategoryLabels[value]) {
return attachmentCategoryLabels[value];
}
return value.replace(/_/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase());
}
$(document).on('click', '.delete-attachment', function () {
const button = $(this);
const deleteUrl = button.data('delete-url');
const $row = button.closest('tr');
function buildCategoryOptions() {
return attachmentCategories
.map((category) => `<option value="${category}">${categoryToLabel(category)}</option>`)
.join('');
}
Swal.fire({
title: 'Hapus lampiran?',
text: 'Lampiran yang dihapus tidak dapat dikembalikan.',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Batal'
}).then((result) => {
if (!result.isConfirmed) {
function resetInlinePreview($row) {
$row.find('.attachment-inline-preview')
.removeClass('bg-light')
.html('<i class="fas fa-file-upload text-muted"></i>');
}
function clearRowData($row) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl');
$row.removeData('previewType');
$row.removeData('previewSource');
resetInlinePreview($row);
$row.find('.preview-new-attachment').addClass('d-none');
$row.find('.preview-filename').text('');
}
window.addAttachmentRow = function() {
if (!newAttachmentsTableBody) return;
if (newAttachmentsTableBody.find('.new-attachments-empty').length) {
newAttachmentsTableBody.empty();
}
const index = attachmentIndex++;
const row = $(`
<tr class="attachment-row" data-index="${index}">
<td>
<select class="form-control attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${categoryToLabel('')}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center gap-2">
<div class="attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white" style="width: 56px; height: 56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control attachment-file" name="attachments[${index}][file_path]" accept="${fileAccept}" required>
</div>
<div class="small text-muted mt-1 preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary preview-new-attachment d-none" data-modal="#newAttachmentPreviewModal">
Pratinjau
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger remove-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`);
newAttachmentsTableBody.append(row);
}
function removeAttachmentRow(button) {
if (!newAttachmentsTableBody) return;
const $row = $(button).closest('tr');
clearRowData($row);
$row.remove();
if (!newAttachmentsTableBody.find('.attachment-row').length) {
newAttachmentsTableBody.html(emptyNewRowMarkup);
}
}
function setInlinePreview($row, type, source) {
const previewBox = $row.find('.attachment-inline-preview');
if (type === 'image' && source) {
previewBox
.html(`<img src="${source}" class="img-thumbnail" style="width: 100%; height: 100%; object-fit: cover;" alt="Pratinjau lampiran">`)
.addClass('bg-light');
} else if (type === 'pdf') {
previewBox
.html('<i class="fas fa-file-pdf text-danger fa-lg"></i>')
.addClass('bg-light');
} else {
resetInlinePreview($row);
}
}
function openAttachmentModal(modalSelector, title, type, source) {
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none');
if (type === 'image' && source) {
$image.attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (type === 'pdf' && source) {
$object.attr('data', source).attr('src', source).removeClass('d-none');
$placeholder.addClass('d-none');
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
$modal.modal('show');
}
}
function previewFile(input) {
const $input = $(input);
const $row = $input.closest('tr');
const previewButton = $row.find('.preview-new-attachment');
const filenameHolder = $row.find('.preview-filename');
clearRowData($row);
const file = input.files && input.files[0];
if (!file) {
return;
}
$.ajax({
url: deleteUrl,
type: 'DELETE',
success: function (response) {
$row.remove();
if (!existingAttachmentsTableBody.find('tr').not('.existing-attachments-empty').length) {
existingAttachmentsTableBody.html(emptyExistingRowMarkup);
}
filenameHolder.text(file.name);
const extension = file.name.split('.').pop().toLowerCase();
Swal.fire('Berhasil', response?.message || 'Lampiran berhasil dihapus.', 'success');
},
error: function (xhr) {
const message = xhr?.responseJSON?.message || 'Gagal menghapus lampiran.';
Swal.fire('Error', message, 'error');
if (['jpg', 'jpeg', 'png'].includes(extension)) {
const reader = new FileReader();
reader.onload = function (event) {
const source = event.target.result;
$row.data('previewType', 'image');
$row.data('previewSource', source);
setInlinePreview($row, 'image', source);
previewButton.removeClass('d-none');
};
reader.readAsDataURL(file);
} else {
const objectUrl = URL.createObjectURL(file);
$row.data('previewType', 'pdf');
$row.data('previewSource', objectUrl);
$row.data('objectUrl', objectUrl);
setInlinePreview($row, 'pdf');
previewButton.removeClass('d-none');
}
}
// ==========================================
// 4. INTERCEPTOR FORM SUBMIT & SWEETALERT (> 1 JUTA)
// ==========================================
const spinnerOverlay = $('#loading-spinner-overlay');
$('#expense-form').on('submit', function (e) {
e.preventDefault();
const form = this;
const allowance = allowanceInput.getNumber() || 0;
const transportDalkot = dalkotInput.getNumber() || 0;
const transportAnkot = ankotInput.getNumber() || 0;
const hotel = hotelInput.getNumber() || 0;
const totalExpense = allowance + transportDalkot + transportAnkot + hotel;
if (totalExpense > 1000000) {
Swal.fire({
title: 'Nominal Melebihi Batas Expense!',
text: `Total pengajuan Anda adalah Rp ${new Intl.NumberFormat('id-ID').format(totalExpense)}. Jumlah ini melebihi batas standar Rp 1.000.000. Apakah yakin tetap ajukan?`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Tetap Ajukan!',
cancelButtonText: 'No, Batalkan'
}).then((result) => {
if (result.isConfirmed) {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
} else {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
// Event Listeners DOM
$('#add-new-attachment-row').on('click', function (e) {
e.preventDefault();
addAttachmentRow();
});
$(document).on('click', '.remove-attachment-row', function () {
removeAttachmentRow(this);
});
$(document).on('change', '.attachment-file', function () {
previewFile(this);
});
$(document).on('click', '.preview-new-attachment', function () {
const $row = $(this).closest('tr');
const previewType = $row.data('previewType');
const previewSource = $row.data('previewSource');
const category = categoryToLabel($row.find('.attachment-category').val());
openAttachmentModal('#newAttachmentPreviewModal', category, previewType, previewSource);
});
$(document).on('click', '.preview-existing-attachment', function () {
const button = $(this);
const previewType = button.data('preview-type');
const previewUrl = button.data('preview-url');
const downloadUrl = button.data('download-url');
const category = button.data('category') || 'Lampiran';
if (!previewUrl) {
if (downloadUrl) {
window.open(downloadUrl, '_blank');
}
return;
}
openAttachmentModal('#existingAttachmentPreviewModal', category, previewType, previewUrl);
});
$(document).on('click', '.delete-attachment', function () {
const button = $(this);
const deleteUrl = button.data('delete-url');
const $row = button.closest('tr');
Swal.fire({
title: 'Hapus lampiran?',
text: 'Lampiran yang dihapus tidak dapat dikembalikan.',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Batal'
}).then((result) => {
if (!result.isConfirmed) return;
$.ajax({
url: deleteUrl,
type: 'DELETE',
success: function (response) {
$row.remove();
if (!existingAttachmentsTableBody.find('tr').not('.existing-attachments-empty').length) {
existingAttachmentsTableBody.html(emptyExistingRowMarkup);
}
Swal.fire('Berhasil', response?.message || 'Lampiran berhasil dihapus.', 'success');
},
error: function (xhr) {
const message = xhr?.responseJSON?.message || 'Gagal menghapus lampiran.';
Swal.fire('Error', message, 'error');
}
});
});
});
});
} catch (err) {
console.error("Local Script Error:", err);
}
});
</script>
@endsection
@endsection
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -6,6 +6,7 @@
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<section class="content-header">
<div class="container-fluid">
@@ -28,8 +29,8 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
z-index: 9999; /* High z-index to cover everything */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
@@ -51,7 +52,8 @@
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
<input type="datetime-local" class="form-control" name="tanggal" required value="{{ old('tanggal') }}">
{{-- Mengubah datetime-local menjadi date --}}
<input type="date" class="form-control" name="tanggal" required value="{{ old('tanggal') }}">
</div>
<div class="mb-3">
<label class="form-label">Tipe Pengeluaran <span class="font-italic font-weight-normal">(required)</span></label>
@@ -63,11 +65,11 @@
<div class="mb-3 gasoline-fields">
<label class="form-label">Liter Bensin <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" class="form-control" name="liter" value="{{ old('liter') }}">
<input type="number" step="0.01" class="form-control" name="liter" id="liter" value="{{ old('liter') }}">
</div>
<div class="mb-3">
<label class="form-label">Total Harga <span class="font-italic font-weight-normal">(required)</span></label>
<input type="string" class="form-control" name="total" id="total" required value="{{ old('total') }}">
<input type="text" class="form-control" name="total" id="total" required value="{{ old('total') }}">
</div>
</div>
@@ -78,7 +80,8 @@
</div>
<div class="mb-3 gasoline-fields">
<label class="form-label">Tipe Bensin <span class="font-italic font-weight-normal">(required)</span></label>
<select class="form-control" name="tipe_bensin" id="tipe_bensin" value="{{ old('tipe_bensin') }}">
<select class="form-control" name="tipe_bensin" id="tipe_bensin">
<option value="" disabled selected>Pilih Tipe</option>
<option value="pertamax" {{ old('tipe_bensin') == 'pertamax' ? 'selected' : '' }}>Pertamax</option>
<option value="pertalite" {{ old('tipe_bensin') == 'pertalite' ? 'selected' : '' }}>Pertalite</option>
</select>
@@ -135,9 +138,8 @@
<div id="loading-spinner-overlay" class="d-none">
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<p>Submitting, please wait...</p>
<div class="spinner-border text-primary" role="status"></div>
<p class="mt-2">Submitting, please wait...</p>
</div>
</div>
</div>
@@ -146,226 +148,211 @@
</section>
<script>
new AutoNumeric('#total', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
$(document).ready(function() {
// 1. Inisialisasi Aman AutoNumeric (Sesuai Standar Up Country)
const autoNumericConfig = {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp. ',
decimalPlaces: 0,
minimumValue: '0', // Mencegah nilai minus
unformatOnSubmit: true
};
const totalInput = new AutoNumeric('#total', autoNumericConfig);
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
document.getElementById('expense-form').addEventListener('submit', function () {
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
});
// Toggle gasoline specific fields
const expenseTypeSelect = document.getElementById('expense_type');
const gasolineFields = document.querySelectorAll('.gasoline-fields');
const literInput = document.querySelector('input[name="liter"]');
const jarakInput = document.querySelector('input[name="jarak"]');
const tipeBensinSelect = document.getElementById('tipe_bensin');
const nopolInput = document.getElementById('nopol');
function toggleGasolineFields() {
if (expenseTypeSelect.value === 'gasoline') {
gasolineFields.forEach(field => field.style.display = 'block');
literInput.setAttribute('required', 'required');
jarakInput.setAttribute('required', 'required');
tipeBensinSelect.setAttribute('required', 'required');
nopolInput.setAttribute('required', 'required');
} else {
gasolineFields.forEach(field => field.style.display = 'none');
literInput.value = '';
jarakInput.value = '';
tipeBensinSelect.value = '';
nopolInput.value = '';
literInput.removeAttribute('required');
jarakInput.removeAttribute('required');
tipeBensinSelect.removeAttribute('required');
nopolInput.removeAttribute('required');
}
}
toggleGasolineFields();
expenseTypeSelect.addEventListener('change', toggleGasolineFields);
const attachmentCategories = @json($attachmentCategories ?? ($vehicleAttachmentCategories ?? []));
const blockedExtensions = ['exe', 'bat', 'sh', 'cmd', 'dll', 'msi'];
const maxFileSizeBytes = 10 * 1024 * 1024;
const vehicleAttachmentEmptyRow = '<tr class="vehicle-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran.</td></tr>';
let vehicleAttachmentIndex = 0;
function escapeHtml(value) {
return String(value || '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function categoryToLabel(value) {
if (!value) {
return 'Pilih Kategori';
}
return value.replace(/_/g, ' ').replace(/\b\w/g, function (char) {
return char.toUpperCase();
// 2. Cegah Scroll Wheel agar angka tidak berubah tanpa sengaja
$('#total, #liter, #jarak').on('wheel font-wheel', function(e) {
e.preventDefault();
$(this).blur();
});
}
function detectPreviewType(extension) {
const images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
if (images.indexOf(extension) !== -1) {
return 'image';
}
if (extension === 'pdf') {
return 'pdf';
}
return 'other';
}
// 3. Toggle Logika Field Bensin
const expenseTypeSelect = document.getElementById('expense_type');
const gasolineFields = document.querySelectorAll('.gasoline-fields');
const literInput = document.getElementById('liter');
const jarakInput = document.getElementById('jarak');
const tipeBensinSelect = document.getElementById('tipe_bensin');
const nopolInput = document.getElementById('nopol');
function buildCategoryOptions() {
return attachmentCategories.map(function (category) {
return '<option value="' + category + '">' + escapeHtml(categoryToLabel(category)) + '</option>';
}).join('');
}
function setInlinePreview($row, type, source) {
const $box = $row.find('.vehicle-attachment-inline-preview');
$box.removeClass('bg-light').html('<i class="fas fa-file-upload text-muted"></i>');
if (type === 'image' && source) {
$box.addClass('bg-light').html(
'<img src="' + source + '" class="img-thumbnail" style="width:100%;height:100%;object-fit:cover;" alt="Preview">'
);
} else if (type === 'pdf') {
$box.addClass('bg-light').html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
} else if (type === 'other') {
$box.addClass('bg-light').html('<i class="fas fa-file-alt text-secondary fa-lg"></i>');
}
}
function resetAttachmentRowData($row, clearInput = true) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl')
.removeData('previewType')
.removeData('previewSource')
.removeData('previewFileName')
.removeData('downloadUrl');
setInlinePreview($row, null, null);
$row.find('.vehicle-preview-new-attachment').addClass('d-none');
$row.find('.vehicle-preview-filename').text('');
if (clearInput) {
$row.find('.vehicle-attachment-file').val('');
}
}
function openAttachmentModal(modalSelector, options) {
const settings = Object.assign({
title: 'Lampiran',
type: 'other',
source: null,
downloadUrl: null,
fileName: 'Lampiran'
}, options || {});
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(settings.title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none').html('Tidak ada file untuk ditampilkan.');
if (settings.type === 'image' && settings.source) {
$image.attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (settings.type === 'pdf' && settings.source) {
$object.attr('data', settings.source).attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else {
const safeName = escapeHtml(settings.fileName || 'Lampiran');
let message = '<p class="mb-2">' + safeName + '</p><p class="text-muted mb-0">Preview tidak tersedia. Silakan unduh file untuk melihat konten.</p>';
if (settings.downloadUrl) {
message += '<div class="mt-3"><a href="' + settings.downloadUrl + '" target="_blank" class="btn btn-sm btn-outline-primary">Download</a></div>';
function toggleGasolineFields() {
if (expenseTypeSelect.value === 'gasoline') {
gasolineFields.forEach(field => field.style.display = 'block');
literInput.setAttribute('required', 'required');
jarakInput.setAttribute('required', 'required');
tipeBensinSelect.setAttribute('required', 'required');
nopolInput.setAttribute('required', 'required');
} else {
gasolineFields.forEach(field => field.style.display = 'none');
literInput.value = '';
jarakInput.value = '';
tipeBensinSelect.value = '';
nopolInput.value = '';
literInput.removeAttribute('required');
jarakInput.removeAttribute('required');
tipeBensinSelect.removeAttribute('required');
nopolInput.removeAttribute('required');
}
$placeholder.html(message);
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
toggleGasolineFields();
expenseTypeSelect.addEventListener('change', toggleGasolineFields);
// 4. Integrasi Interseptor Form Submit & SweetAlert
const spinnerOverlay = $('#loading-spinner-overlay');
$('#expense-form').on('submit', function (e) {
e.preventDefault();
const form = this;
const totalExpense = totalInput.getNumber() || 0;
if (totalExpense > 1000000) {
Swal.fire({
title: 'Nominal Melebihi Batas Expense!',
text: `Total pengajuan Anda adalah Rp ${new Intl.NumberFormat('id-ID').format(totalExpense)}. Jumlah ini melebihi batas standar Rp 1.000.000. Apakah yakin tetap ajukan?`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Tetap Ajukan!',
cancelButtonText: 'No, Batalkan'
}).then((result) => {
if (result.isConfirmed) {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
} else {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
// 5. Lampiran Engine (Tetap Utuh)
const attachmentCategories = @json($attachmentCategories ?? ($vehicleAttachmentCategories ?? []));
const blockedExtensions = ['exe', 'bat', 'sh', 'cmd', 'dll', 'msi'];
const maxFileSizeBytes = 10 * 1024 * 1024;
const vehicleAttachmentEmptyRow = '<tr class="vehicle-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran.</td></tr>';
let vehicleAttachmentIndex = 0;
function escapeHtml(value) {
return String(value || '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function categoryToLabel(value) {
if (!value) return 'Pilih Kategori';
return value.replace(/_/g, ' ').replace(/\b\w/g, function (char) { return char.toUpperCase(); });
}
function detectPreviewType(extension) {
const images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
if (images.indexOf(extension) !== -1) return 'image';
if (extension === 'pdf') return 'pdf';
return 'other';
}
function buildCategoryOptions() {
return attachmentCategories.map(function (category) {
return '<option value="' + category + '">' + escapeHtml(categoryToLabel(category)) + '</option>';
}).join('');
}
function setInlinePreview($row, type, source) {
const $box = $row.find('.vehicle-attachment-inline-preview');
$box.removeClass('bg-light').html('<i class="fas fa-file-upload text-muted"></i>');
if (type === 'image' && source) {
$box.addClass('bg-light').html('<img src="' + source + '" class="img-thumbnail" style="width:100%;height:100%;object-fit:cover;" alt="Preview">');
} else if (type === 'pdf') {
$box.addClass('bg-light').html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
} else if (type === 'other') {
$box.addClass('bg-light').html('<i class="fas fa-file-alt text-secondary fa-lg"></i>');
}
}
function resetAttachmentRowData($row, clearInput = true) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) URL.revokeObjectURL(existingUrl);
$row.removeData('objectUrl').removeData('previewType').removeData('previewSource').removeData('previewFileName').removeData('downloadUrl');
setInlinePreview($row, null, null);
$row.find('.vehicle-preview-new-attachment').addClass('d-none');
$row.find('.vehicle-preview-filename').text('');
if (clearInput) $row.find('.vehicle-attachment-file').val('');
}
function openAttachmentModal(modalSelector, options) {
const settings = Object.assign({ title: 'Lampiran', type: 'other', source: null, downloadUrl: null, fileName: 'Lampiran' }, options || {});
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(settings.title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none').html('Tidak ada file untuk ditampilkan.');
if (settings.type === 'image' && settings.source) {
$image.attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (settings.type === 'pdf' && settings.source) {
$object.attr('data', settings.source).attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else {
const safeName = escapeHtml(settings.fileName || 'Lampiran');
let message = '<p class="mb-2">' + safeName + '</p><p class="text-muted mb-0">Preview tidak tersedia. Silakan unduh file untuk melihat konten.</p>';
if (settings.downloadUrl) message += '<div class="mt-3"><a href="' + settings.downloadUrl + '" target="_blank" class="btn btn-sm btn-outline-primary">Download</a></div>';
$placeholder.html(message);
}
$modal.modal('show');
}
}
function addVehicleAttachmentRow() {
const $tbody = $('#vehicle-attachments-table tbody');
function addVehicleAttachmentRow() {
const $tbody = $('#vehicle-attachments-table tbody');
if ($tbody.find('.vehicle-attachments-empty').length) $tbody.empty();
if ($tbody.find('.vehicle-attachments-empty').length) {
$tbody.empty();
const index = vehicleAttachmentIndex++;
const rowHtml = `
<tr class="vehicle-attachment-row" data-index="${index}">
<td>
<select class="form-control vehicle-attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${escapeHtml(categoryToLabel(''))}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center">
<div class="vehicle-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white mr-2" style="width:56px;height:56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control vehicle-attachment-file" name="attachments[${index}][file_path]" required>
</div>
<div class="small text-muted mt-1 vehicle-preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary vehicle-preview-new-attachment d-none">Preview</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger vehicle-remove-attachment-row"><i class="fas fa-trash"></i></button>
</td>
</tr>
`;
$tbody.append(rowHtml);
}
const index = vehicleAttachmentIndex++;
const rowHtml = `
<tr class="vehicle-attachment-row" data-index="${index}">
<td>
<select class="form-control vehicle-attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${escapeHtml(categoryToLabel(''))}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center">
<div class="vehicle-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white mr-2" style="width:56px;height:56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control vehicle-attachment-file" name="attachments[${index}][file_path]">
</div>
<div class="small text-muted mt-1 vehicle-preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary vehicle-preview-new-attachment d-none">
Preview
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger vehicle-remove-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`;
$tbody.append(rowHtml);
}
$(function () {
$('#vehicle-add-attachment-row').on('click', function () {
addVehicleAttachmentRow();
});
$('#vehicle-add-attachment-row').on('click', function () { addVehicleAttachmentRow(); });
$(document).on('click', '.vehicle-remove-attachment-row', function () {
const $row = $(this).closest('tr');
const $tbody = $('#vehicle-attachments-table tbody');
resetAttachmentRowData($row, true);
$row.remove();
if (!$tbody.find('.vehicle-attachment-row').length) {
$tbody.html(vehicleAttachmentEmptyRow);
}
if (!$tbody.find('.vehicle-attachment-row').length) $tbody.html(vehicleAttachmentEmptyRow);
});
$(document).on('change', '.vehicle-attachment-file', function () {
@@ -378,9 +365,7 @@
filenameHolder.text('');
const file = this.files && this.files[0];
if (!file) {
return;
}
if (!file) return;
if (file.size > maxFileSizeBytes) {
alert('Ukuran file melebihi 10 MB.');
@@ -419,7 +404,6 @@
$row.data('previewSource', null);
setInlinePreview($row, 'other', null);
}
previewButton.removeClass('d-none');
});
@@ -438,8 +422,8 @@
});
});
// Add initial attachment row for user convenience
// Berikan 1 baris input file kosong sebagai default awal
addVehicleAttachmentRow();
});
</script>
@endsection
@endsection
@@ -6,6 +6,8 @@
@section('admin-content')
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.6.0/dist/autoNumeric.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
@@ -27,8 +29,8 @@
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black background */
z-index: 9999; /* High z-index to cover everything */
background-color: rgba(0, 0, 0, 0.5);
z-index: 9999;
display: flex;
justify-content: center;
align-items: center;
@@ -39,6 +41,12 @@
color: white;
}
</style>
@php
$attachmentCategoryLabels = $attachmentCategoryLabels ?? ($vehicleAttachmentCategories ?? []);
$attachmentCategories = $attachmentCategories ?? ($vehicleAttachmentCategoryKeys ?? array_keys($attachmentCategoryLabels));
@endphp
<section class="content">
<div class="container-fluid">
<div class="card card-primary card-outline">
@@ -51,9 +59,10 @@
<div class="col-lg-6">
<div class="mb-3">
<label class="form-label">Tanggal <span class="font-italic font-weight-normal">(required)</span></label>
<input type="datetime-local" class="form-control" name="tanggal" required value="{{ old('tanggal', $form->tanggal ? \Carbon\Carbon::parse($form->tanggal)->format('Y-m-d\TH:i') : '') }}">
{{-- Konversi Cerdas Format Input Tipe 'date' --}}
<input type="date" class="form-control" name="tanggal" required
value="{{ old('tanggal', $form->tanggal ? \Carbon\Carbon::parse($form->tanggal)->format('Y-m-d') : '') }}">
</div>
{{-- Updated: Expense Type dropdown with name="type" and $form->type for selection --}}
<div class="mb-3">
<label class="form-label">Tipe Pengeluaran <span class="font-italic font-weight-normal">(required)</span></label>
<select class="form-control" name="type" id="expense_type" required>
@@ -62,19 +71,17 @@
</select>
</div>
{{-- Wrap gasoline-specific fields with .gasoline-fields --}}
<div class="mb-3 gasoline-fields">
<label class="form-label">Liter Bensin <span class="font-italic font-weight-normal">(required)</span></label>
<input type="text" class="form-control" name="liter" value="{{ old('liter', $form->liter) }}">
<input type="number" step="0.01" class="form-control" name="liter" id="liter" value="{{ old('liter', $form->liter) }}">
</div>
<div class="mb-3">
<label class="form-label">Total Harga <span class="font-italic font-weight-normal">(required)</span></label>
<input type="string" class="form-control" name="total" id="total" required value="{{ old('total', $form->total) }}">
<input type="text" class="form-control" name="total" id="total" required value="{{ old('total', $form->total) }}">
</div>
</div>
<div class="col-lg-6">
{{-- Wrap gasoline-specific fields with .gasoline-fields --}}
<div class="mb-3 gasoline-fields">
<label class="form-label">Km (Odometer) <span class="font-italic font-weight-normal">(required)</span></label>
<input type="number" class="form-control" name="jarak" id="jarak" value="{{ old('jarak', $form->jarak) }}">
@@ -82,6 +89,7 @@
<div class="mb-3 gasoline-fields">
<label class="form-label">Tipe Bensin <span class="font-italic font-weight-normal">(required)</span></label>
<select class="form-control" name="tipe_bensin" id="tipe_bensin">
<option value="" disabled selected>Pilih Tipe</option>
<option value="pertamax" {{ old('tipe_bensin', $form->tipe_bensin) == 'pertamax' ? 'selected' : '' }}>Pertamax</option>
<option value="pertalite" {{ old('tipe_bensin', $form->tipe_bensin) == 'pertalite' ? 'selected' : '' }}>Pertalite</option>
</select>
@@ -96,53 +104,61 @@
</div>
</div>
<div class="col-12">
{{-- BAGIAN LAMPIRAN TERSIMPAN DATABASE --}}
<div class="col-lg-12">
<div class="mb-4">
<label class="form-label mb-0">Lampiran Saat Ini</label>
<p class="text-muted small mt-1 mb-2">Gunakan tombol preview untuk melihat lampiran.</p>
<label class="form-label mb-0">Lampiran Tersimpan</label>
<p class="text-muted small mt-1 mb-2">Pratinjau, unduh, atau hapus lampiran yang telah diunggah sebelumnya.</p>
<div class="table-responsive">
<table class="table table-bordered align-middle" id="vehicle-existing-attachments-table">
<table class="table table-bordered align-middle" id="existing-attachments-table">
<thead class="table-light">
<tr>
<th style="width: 30%">Kategori</th>
<th style="width: 35%">Nama File</th>
<th style="width: 15%" class="text-center">Preview</th>
<th style="width: 20%" class="text-center">Aksi</th>
<th style="width: 30%">Kategori Lampiran</th>
<th style="width: 30%">Nama File</th>
<th style="width: 15%" class="text-center">Pratinjau</th>
<th style="width: 15%" class="text-center">Unduh</th>
<th style="width: 10%" class="text-center">Aksi</th>
</tr>
</thead>
<tbody>
@forelse ($attachments as $attachment)
<tr class="vehicle-existing-attachment-row" data-attachment-id="{{ $attachment['id'] }}">
<td>{{ $attachment['file_category'] ? ucwords(str_replace('_', ' ', $attachment['file_category'])) : '-' }}</td>
@php
$categoryValue = $attachment['file_category'] ?? null;
$categoryLabel = $categoryValue
? ($attachmentCategoryLabels[$categoryValue] ?? ucwords(str_replace('_', ' ', $categoryValue)))
: '-';
@endphp
<tr data-attachment-id="{{ $attachment['id'] }}">
<td>{{ $categoryLabel }}</td>
<td>{{ $attachment['filename'] ?? basename($attachment['file_path']) }}</td>
<td class="text-center">
<button type="button"
class="btn btn-sm btn-outline-secondary vehicle-preview-existing-attachment"
data-preview-url="{{ $attachment['preview_url'] }}"
data-download-url="{{ $attachment['download_url'] }}"
data-preview-type="{{ $attachment['preview_type'] }}"
data-file-name="{{ $attachment['filename'] ?? basename($attachment['file_path']) }}">
Preview
class="btn btn-sm btn-outline-secondary preview-existing-attachment"
data-preview-url="{{ $attachment['preview_url'] }}"
data-download-url="{{ $attachment['download_url'] }}"
data-preview-type="{{ $attachment['preview_type'] }}"
data-category="{{ $categoryLabel }}">
Pratinjau
</button>
</td>
<td class="text-center">
<a href="{{ $attachment['download_url'] }}"
target="_blank"
class="btn btn-sm btn-outline-primary mr-1">
Download
class="btn btn-sm btn-outline-primary">
Unduh
</a>
@if($attachment['can_delete'])
<button type="button"
class="btn btn-sm btn-outline-danger vehicle-delete-attachment"
data-delete-url="{{ route('forms.vehicle.attachments.destroy', [$form->id, $attachment['id']]) }}">
<i class="fas fa-trash"></i>
</button>
@endif
</td>
<td class="text-center">
<button type="button"
class="btn btn-sm btn-outline-danger delete-attachment"
data-delete-url="{{ route('forms.vehicle.attachments.destroy', [$form->id, $attachment['id']]) }}">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
@empty
<tr class="vehicle-existing-attachments-empty text-center text-muted">
<td colspan="4">Belum ada lampiran.</td>
<tr class="existing-attachments-empty text-center text-muted">
<td colspan="5">Belum ada lampiran tersimpan.</td>
</tr>
@endforelse
</tbody>
@@ -155,15 +171,15 @@
<div class="mb-3">
<div class="d-flex align-items-center justify-content-between">
<label class="form-label mb-0">Tambah Lampiran Baru</label>
<button type="button" class="btn btn-outline-primary btn-sm" id="vehicle-add-new-attachment-row">
<i class="fas fa-plus mr-1"></i> Tambah Lampiran
<button type="button" class="btn btn-outline-primary btn-sm" id="vehicle-add-attachment-row">
<i class="fas fa-plus mr-1"></i> Add attachment
</button>
</div>
<p class="text-muted small mt-1 mb-2">
Maksimal 10 MB per file. Semua tipe file diperbolehkan kecuali <code>.exe</code>, <code>.bat</code>, <code>.sh</code>, <code>.cmd</code>, <code>.dll</code>, dan <code>.msi</code>.
</p>
<div class="table-responsive">
<table class="table table-bordered align-middle" id="vehicle-new-attachments-table">
<table class="table table-bordered align-middle" id="vehicle-attachments-table">
<thead class="table-light">
<tr>
<th style="width: 30%">Kategori</th>
@@ -173,8 +189,8 @@
</tr>
</thead>
<tbody>
<tr class="vehicle-new-attachments-empty text-center text-muted">
<td colspan="4">Belum ada lampiran baru.</td>
<tr class="vehicle-attachments-empty text-center text-muted">
<td colspan="4">Belum ada lampiran.</td>
</tr>
</tbody>
</table>
@@ -182,13 +198,13 @@
</div>
</div>
<button type="submit" class="btn btn-primary ml-2">Save</button>
<button type="submit" class="btn btn-primary ml-2">Simpan Perubahan</button>
</div>
</form>
@include('backend.components.attachment-preview-modal', [
'modalId' => 'vehicleExistingAttachmentPreviewModal',
'title' => 'Preview Lampiran',
'modalId' => 'existingAttachmentPreviewModal',
'title' => 'Pratinjau Lampiran',
])
@include('backend.components.attachment-preview-modal', [
@@ -198,9 +214,8 @@
<div id="loading-spinner-overlay" class="d-none">
<div class="spinner-wrapper">
<div class="spinner-border text-primary" role="status">
</div>
<p>Submitting, please wait...</p>
<div class="spinner-border text-primary" role="status"></div>
<p class="mt-2">Submitting, please wait...</p>
</div>
</div>
</div>
@@ -208,255 +223,280 @@
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
new AutoNumeric('#total', {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp.',
decimalPlaces: 0,
unformatOnSubmit: true
});
const spinnerOverlay = document.getElementById('loading-spinner-overlay');
document.getElementById('expense-form').addEventListener('submit', function () {
spinnerOverlay.classList.remove('d-none');
spinnerOverlay.classList.add('d-flex');
});
// Toggle gasoline specific fields
const expenseTypeSelect = document.getElementById('expense_type');
const gasolineFields = document.querySelectorAll('.gasoline-fields');
const literInput = document.querySelector('input[name="liter"]');
const jarakInput = document.querySelector('input[name="jarak"]');
const tipeBensinSelect = document.getElementById('tipe_bensin');
const nopolInput = document.getElementById('nopol');
function toggleGasolineFields() {
if (expenseTypeSelect.value === 'gasoline') {
gasolineFields.forEach(field => field.style.display = 'block');
literInput.setAttribute('required', 'required');
jarakInput.setAttribute('required', 'required');
tipeBensinSelect.setAttribute('required', 'required');
nopolInput.setAttribute('required', 'required');
} else {
gasolineFields.forEach(field => field.style.display = 'none');
literInput.value = '';
jarakInput.value = '';
tipeBensinSelect.value = '';
nopolInput.value = '';
literInput.removeAttribute('required');
jarakInput.removeAttribute('required');
tipeBensinSelect.removeAttribute('required');
nopolInput.removeAttribute('required');
$(document).ready(function() {
// Setup Global Token CSRF Khusus untuk Delete File via AJAX
const csrfToken = $('meta[name="csrf-token"]').attr('content');
if (csrfToken) {
$.ajaxSetup({
headers: { 'X-CSRF-TOKEN': csrfToken }
});
}
}
toggleGasolineFields();
expenseTypeSelect.addEventListener('change', toggleGasolineFields);
// 1. Inisialisasi Aman AutoNumeric (Sesuai Standar Up Country)
const autoNumericConfig = {
digitGroupSeparator: '.',
decimalCharacter: ',',
currencySymbol: 'Rp. ',
decimalPlaces: 0,
minimumValue: '0',
unformatOnSubmit: true
};
const totalInput = new AutoNumeric('#total', autoNumericConfig);
const attachmentCategories = @json($attachmentCategories ?? ($vehicleAttachmentCategories ?? []));
const blockedExtensions = ['exe', 'bat', 'sh', 'cmd', 'dll', 'msi'];
const maxFileSizeBytes = 10 * 1024 * 1024;
const existingEmptyRow = '<tr class="vehicle-existing-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran.</td></tr>';
const newEmptyRow = '<tr class="vehicle-new-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran baru.</td></tr>';
let vehicleNewAttachmentIndex = 0;
function escapeHtml(value) {
return String(value || '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function categoryToLabel(value) {
if (!value) {
return 'Pilih Kategori';
}
return value.replace(/_/g, ' ').replace(/\b\w/g, function (char) {
return char.toUpperCase();
// 2. Cegah Scroll Wheel
$('#total, #liter, #jarak').on('wheel font-wheel', function(e) {
e.preventDefault();
$(this).blur();
});
}
function detectPreviewType(extension) {
const images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
if (images.indexOf(extension) !== -1) {
return 'image';
}
if (extension === 'pdf') {
return 'pdf';
}
return 'other';
}
// 3. Toggle Logika Field Bensin
const expenseTypeSelect = document.getElementById('expense_type');
const gasolineFields = document.querySelectorAll('.gasoline-fields');
const literInput = document.getElementById('liter');
const jarakInput = document.getElementById('jarak');
const tipeBensinSelect = document.getElementById('tipe_bensin');
const nopolInput = document.getElementById('nopol');
function buildCategoryOptions() {
return attachmentCategories.map(function (category) {
return '<option value="' + category + '">' + escapeHtml(categoryToLabel(category)) + '</option>';
}).join('');
}
function setInlinePreview($row, type, source) {
const $box = $row.find('.vehicle-new-attachment-inline-preview');
$box.removeClass('bg-light').html('<i class="fas fa-file-upload text-muted"></i>');
if (type === 'image' && source) {
$box.addClass('bg-light').html(
'<img src="' + source + '" class="img-thumbnail" style="width:100%;height:100%;object-fit:cover;" alt="Preview">'
);
} else if (type === 'pdf') {
$box.addClass('bg-light').html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
} else if (type === 'other') {
$box.addClass('bg-light').html('<i class="fas fa-file-alt text-secondary fa-lg"></i>');
}
}
function resetNewAttachmentRowData($row, clearInput = true) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) {
URL.revokeObjectURL(existingUrl);
}
$row.removeData('objectUrl')
.removeData('previewType')
.removeData('previewSource')
.removeData('previewFileName')
.removeData('downloadUrl');
setInlinePreview($row, null, null);
$row.find('.vehicle-preview-new-attachment').addClass('d-none');
$row.find('.vehicle-new-preview-filename').text('');
if (clearInput) {
$row.find('.vehicle-new-attachment-file').val('');
}
}
function openAttachmentModal(modalSelector, options) {
const settings = Object.assign({
title: 'Lampiran',
type: 'other',
source: null,
downloadUrl: null,
fileName: 'Lampiran'
}, options || {});
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(settings.title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none').html('Tidak ada file untuk ditampilkan.');
if (settings.type === 'image' && settings.source) {
$image.attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (settings.type === 'pdf' && settings.source) {
$object.attr('data', settings.source).attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else {
const safeName = escapeHtml(settings.fileName || 'Lampiran');
let message = '<p class="mb-2">' + safeName + '</p><p class="text-muted mb-0">Preview tidak tersedia. Silakan unduh file untuk melihat konten.</p>';
if (settings.downloadUrl) {
message += '<div class="mt-3"><a href="' + settings.downloadUrl + '" target="_blank" class="btn btn-sm btn-outline-primary">Download</a></div>';
function toggleGasolineFields() {
if (expenseTypeSelect.value === 'gasoline') {
gasolineFields.forEach(field => field.style.display = 'block');
literInput.setAttribute('required', 'required');
jarakInput.setAttribute('required', 'required');
tipeBensinSelect.setAttribute('required', 'required');
nopolInput.setAttribute('required', 'required');
} else {
gasolineFields.forEach(field => field.style.display = 'none');
literInput.value = '';
jarakInput.value = '';
tipeBensinSelect.value = '';
nopolInput.value = '';
literInput.removeAttribute('required');
jarakInput.removeAttribute('required');
tipeBensinSelect.removeAttribute('required');
nopolInput.removeAttribute('required');
}
$placeholder.html(message);
}
if (window.bootstrap && bootstrap.Modal && typeof bootstrap.Modal.getOrCreateInstance === 'function') {
bootstrap.Modal.getOrCreateInstance($modal[0]).show();
} else {
toggleGasolineFields();
expenseTypeSelect.addEventListener('change', toggleGasolineFields);
// 4. Integrasi Interseptor Form Submit & SweetAlert
const spinnerOverlay = $('#loading-spinner-overlay');
$('#expense-form').on('submit', function (e) {
e.preventDefault();
const form = this;
const totalExpense = totalInput.getNumber() || 0;
if (totalExpense > 1000000) {
Swal.fire({
title: 'Nominal Melebihi Batas Expense!',
text: `Total pengajuan Anda adalah Rp ${new Intl.NumberFormat('id-ID').format(totalExpense)}. Jumlah ini melebihi batas standar Rp 1.000.000. Apakah yakin tetap ajukan?`,
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, Tetap Simpan!',
cancelButtonText: 'No, Batalkan'
}).then((result) => {
if (result.isConfirmed) {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
} else {
spinnerOverlay.removeClass('d-none').addClass('d-flex');
form.submit();
}
});
// 5. Lampiran Engine AJAX (Existing Table Delete)
$(document).on('click', '.delete-attachment', function () {
const button = $(this);
const deleteUrl = button.data('delete-url');
const $row = button.closest('tr');
const existingAttachmentsTableBody = $('#existing-attachments-table tbody');
const emptyExistingRowMarkup = '<tr class="existing-attachments-empty text-center text-muted"><td colspan="5">Belum ada lampiran tersimpan.</td></tr>';
Swal.fire({
title: 'Hapus lampiran?',
text: 'Lampiran yang dihapus tidak dapat dikembalikan.',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Batal'
}).then((result) => {
if (!result.isConfirmed) return;
$.ajax({
url: deleteUrl,
type: 'DELETE',
success: function (response) {
$row.remove();
if (!existingAttachmentsTableBody.find('tr').not('.existing-attachments-empty').length) {
existingAttachmentsTableBody.html(emptyExistingRowMarkup);
}
Swal.fire('Berhasil', response?.message || 'Lampiran berhasil dihapus.', 'success');
},
error: function (xhr) {
const message = xhr?.responseJSON?.message || 'Gagal menghapus lampiran.';
Swal.fire('Error', message, 'error');
}
});
});
});
$(document).on('click', '.preview-existing-attachment', function () {
const button = $(this);
const previewType = button.data('preview-type');
const previewUrl = button.data('preview-url');
const downloadUrl = button.data('download-url');
const category = button.data('category') || 'Lampiran';
if (!previewUrl) {
if (downloadUrl) window.open(downloadUrl, '_blank');
return;
}
openAttachmentModal('#existingAttachmentPreviewModal', {
title: category, type: previewType, source: previewUrl
});
});
// 6. Lampiran Engine Tambahan Baru
const attachmentCategories = @json($attachmentCategories ?? ($vehicleAttachmentCategories ?? []));
const blockedExtensions = ['exe', 'bat', 'sh', 'cmd', 'dll', 'msi'];
const maxFileSizeBytes = 10 * 1024 * 1024;
const vehicleAttachmentEmptyRow = '<tr class="vehicle-attachments-empty text-center text-muted"><td colspan="4">Belum ada lampiran.</td></tr>';
let vehicleAttachmentIndex = 0;
function escapeHtml(value) {
return String(value || '')
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
}
function categoryToLabel(value) {
if (!value) return 'Pilih Kategori';
return value.replace(/_/g, ' ').replace(/\b\w/g, function (char) { return char.toUpperCase(); });
}
function detectPreviewType(extension) {
const images = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'];
if (images.indexOf(extension) !== -1) return 'image';
if (extension === 'pdf') return 'pdf';
return 'other';
}
function buildCategoryOptions() {
return attachmentCategories.map(function (category) {
return '<option value="' + category + '">' + escapeHtml(categoryToLabel(category)) + '</option>';
}).join('');
}
function setInlinePreview($row, type, source) {
const $box = $row.find('.vehicle-attachment-inline-preview');
$box.removeClass('bg-light').html('<i class="fas fa-file-upload text-muted"></i>');
if (type === 'image' && source) {
$box.addClass('bg-light').html('<img src="' + source + '" class="img-thumbnail" style="width:100%;height:100%;object-fit:cover;" alt="Preview">');
} else if (type === 'pdf') {
$box.addClass('bg-light').html('<i class="fas fa-file-pdf text-danger fa-lg"></i>');
} else if (type === 'other') {
$box.addClass('bg-light').html('<i class="fas fa-file-alt text-secondary fa-lg"></i>');
}
}
function resetAttachmentRowData($row, clearInput = true) {
const existingUrl = $row.data('objectUrl');
if (existingUrl) URL.revokeObjectURL(existingUrl);
$row.removeData('objectUrl').removeData('previewType').removeData('previewSource').removeData('previewFileName').removeData('downloadUrl');
setInlinePreview($row, null, null);
$row.find('.vehicle-preview-new-attachment').addClass('d-none');
$row.find('.vehicle-preview-filename').text('');
if (clearInput) $row.find('.vehicle-attachment-file').val('');
}
function openAttachmentModal(modalSelector, options) {
const settings = Object.assign({ title: 'Lampiran', type: 'other', source: null, downloadUrl: null, fileName: 'Lampiran' }, options || {});
const $modal = $(modalSelector);
const $image = $modal.find('.attachment-preview-image');
const $object = $modal.find('.attachment-preview-object');
const $placeholder = $modal.find('.attachment-preview-placeholder');
$modal.find('.attachment-preview-modal-title').text(settings.title || 'Lampiran');
$image.addClass('d-none').attr('src', '');
$object.addClass('d-none').attr('data', '').attr('src', '');
$placeholder.removeClass('d-none').html('Tidak ada file untuk ditampilkan.');
if (settings.type === 'image' && settings.source) {
$image.attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else if (settings.type === 'pdf' && settings.source) {
$object.attr('data', settings.source).attr('src', settings.source).removeClass('d-none');
$placeholder.addClass('d-none');
} else {
const safeName = escapeHtml(settings.fileName || 'Lampiran');
let message = '<p class="mb-2">' + safeName + '</p><p class="text-muted mb-0">Preview tidak tersedia. Silakan unduh file untuk melihat konten.</p>';
if (settings.downloadUrl) message += '<div class="mt-3"><a href="' + settings.downloadUrl + '" target="_blank" class="btn btn-sm btn-outline-primary">Download</a></div>';
$placeholder.html(message);
}
$modal.modal('show');
}
}
function refreshExistingEmptyState() {
const $tbody = $('#vehicle-existing-attachments-table tbody');
if (!$tbody.find('.vehicle-existing-attachment-row').length) {
$tbody.html(existingEmptyRow);
}
}
function addVehicleAttachmentRow() {
const $tbody = $('#vehicle-attachments-table tbody');
if ($tbody.find('.vehicle-attachments-empty').length) $tbody.empty();
function refreshNewEmptyState() {
const $tbody = $('#vehicle-new-attachments-table tbody');
if (!$tbody.find('.vehicle-new-attachment-row').length) {
$tbody.html(newEmptyRow);
}
}
function addVehicleNewAttachmentRow() {
const $tbody = $('#vehicle-new-attachments-table tbody');
if ($tbody.find('.vehicle-new-attachments-empty').length) {
$tbody.empty();
}
const index = vehicleNewAttachmentIndex++;
const rowHtml = `
<tr class="vehicle-new-attachment-row" data-index="${index}">
<td>
<select class="form-control vehicle-new-attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${escapeHtml(categoryToLabel(''))}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center">
<div class="vehicle-new-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white mr-2" style="width:56px;height:56px;">
<i class="fas fa-file-upload text-muted"></i>
const index = vehicleAttachmentIndex++;
const rowHtml = `
<tr class="vehicle-attachment-row" data-index="${index}">
<td>
<select class="form-control vehicle-attachment-category" name="attachments[${index}][file_category]" required>
<option value="">${escapeHtml(categoryToLabel(''))}</option>
${buildCategoryOptions()}
</select>
</td>
<td>
<div class="d-flex align-items-center">
<div class="vehicle-attachment-inline-preview border rounded d-flex align-items-center justify-content-center bg-white mr-2" style="width:56px;height:56px;">
<i class="fas fa-file-upload text-muted"></i>
</div>
<input type="file" class="form-control vehicle-attachment-file" name="attachments[${index}][file_path]" required>
</div>
<input type="file" class="form-control vehicle-new-attachment-file" name="attachments[${index}][file_path]">
</div>
<div class="small text-muted mt-1 vehicle-new-preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary vehicle-preview-new-attachment d-none">
Preview
</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger vehicle-remove-new-attachment-row">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
`;
<div class="small text-muted mt-1 vehicle-preview-filename"></div>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-secondary vehicle-preview-new-attachment d-none">Preview</button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-danger vehicle-remove-attachment-row"><i class="fas fa-trash"></i></button>
</td>
</tr>
`;
$tbody.append(rowHtml);
}
$tbody.append(rowHtml);
}
$('#vehicle-add-attachment-row').on('click', function () { addVehicleAttachmentRow(); });
$(function () {
$('#vehicle-add-new-attachment-row').on('click', function () {
addVehicleNewAttachmentRow();
});
$(document).on('click', '.vehicle-remove-new-attachment-row', function () {
$(document).on('click', '.vehicle-remove-attachment-row', function () {
const $row = $(this).closest('tr');
const $tbody = $('#vehicle-new-attachments-table tbody');
resetNewAttachmentRowData($row, true);
const $tbody = $('#vehicle-attachments-table tbody');
resetAttachmentRowData($row, true);
$row.remove();
refreshNewEmptyState();
if (!$tbody.find('.vehicle-attachment-row').length) $tbody.html(vehicleAttachmentEmptyRow);
});
$(document).on('change', '.vehicle-new-attachment-file', function () {
$(document).on('change', '.vehicle-attachment-file', function () {
const $input = $(this);
const $row = $input.closest('tr');
const previewButton = $row.find('.vehicle-preview-new-attachment');
const filenameHolder = $row.find('.vehicle-new-preview-filename');
const filenameHolder = $row.find('.vehicle-preview-filename');
resetNewAttachmentRowData($row, false);
resetAttachmentRowData($row, false);
filenameHolder.text('');
const file = this.files && this.files[0];
if (!file) {
return;
}
if (!file) return;
if (file.size > maxFileSizeBytes) {
alert('Ukuran file melebihi 10 MB.');
@@ -495,7 +535,6 @@
$row.data('previewSource', null);
setInlinePreview($row, 'other', null);
}
previewButton.removeClass('d-none');
});
@@ -513,73 +552,6 @@
fileName: fileName
});
});
$(document).on('click', '.vehicle-preview-existing-attachment', function () {
const $button = $(this);
const previewType = $button.data('preview-type') || 'other';
const previewUrl = $button.data('preview-url') || null;
const downloadUrl = $button.data('download-url') || null;
const fileName = $button.data('file-name') || 'Lampiran';
let type = previewType;
let source = previewUrl;
if (!previewUrl || (previewType !== 'image' && previewType !== 'pdf')) {
type = 'other';
source = null;
}
openAttachmentModal('#vehicleExistingAttachmentPreviewModal', {
title: fileName,
type: type,
source: source,
downloadUrl: downloadUrl,
fileName: fileName
});
});
$(document).on('click', '.vehicle-delete-attachment', function () {
const $button = $(this);
const deleteUrl = $button.data('delete-url');
const $row = $button.closest('tr');
if (!deleteUrl) {
return;
}
Swal.fire({
title: 'Hapus lampiran?',
text: 'Lampiran yang dihapus tidak dapat dikembalikan.',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Ya, hapus',
cancelButtonText: 'Batal'
}).then((result) => {
if (!result.isConfirmed) {
return;
}
$.ajax({
url: deleteUrl,
type: 'DELETE',
success: function (response) {
$row.remove();
refreshExistingEmptyState();
Swal.fire('Berhasil', response?.message || 'Lampiran berhasil dihapus.', 'success');
},
error: function (xhr) {
const message = xhr?.responseJSON?.message || 'Gagal menghapus lampiran.';
Swal.fire('Error', message, 'error');
}
});
});
});
refreshExistingEmptyState();
refreshNewEmptyState();
// Provide an initial row for new attachments
addVehicleNewAttachmentRow();
});
</script>
@endsection
@endsection
File diff suppressed because it is too large Load Diff