484 lines
21 KiB
PHP
484 lines
21 KiB
PHP
@extends('layouts.main')
|
|
|
|
@section('css')
|
|
<style>
|
|
#paguTable thead th {
|
|
background: #2563eb !important; background-color: #2563eb !important;
|
|
color: #fff !important;
|
|
border-color: #2563eb !important;
|
|
}
|
|
|
|
#paguTable tbody tr:hover > * {
|
|
background-color: rgba(13, 110, 253, 0.08) !important;
|
|
box-shadow: none;
|
|
}
|
|
</style>
|
|
@endsection
|
|
|
|
@section('breadcrumb')
|
|
<ol class="breadcrumb m-0">
|
|
<li class="breadcrumb-item"><a href="javascript:void(0);">Perhitungan</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page">{{ $title }}</li>
|
|
</ol>
|
|
@endsection
|
|
|
|
@section('content')
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card border">
|
|
<div class="card-body">
|
|
@include('components.datatable-header', [
|
|
'title' => 'Daftar Pagu',
|
|
'description' => 'Berikut adalah daftar pagu anggaran untuk setiap Unit Kerja',
|
|
'actionButton' => ($canTambah ? '
|
|
<button type="button" class="btn btn-primary me-2" data-bs-toggle="modal" data-bs-target="#paguModal" onclick="resetForm()">
|
|
<i class="uil-plus"></i> Tambah Pagu
|
|
</button>' : '') .
|
|
(!$showQuestionMark ? '
|
|
<button type="button" class="btn btn-success" id="exportExcelBtn">
|
|
<i class="uil-file-download-alt me-1"></i> Export Excel
|
|
</button>' : '')
|
|
])
|
|
|
|
@if($hasBacaPagu)
|
|
<!-- Summary Cards -->
|
|
<div class="row mb-4" id="summaryCards">
|
|
@if(!$hideJumlahCards)
|
|
<div class="col-md-4">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div class="flex-grow-1">
|
|
<p class="text-muted mb-1">Jumlah Pagu</p>
|
|
<h4 class="mb-0" id="totalPagu">{{ $showQuestionMark ? '?' : 'Rp 0' }}</h4>
|
|
</div>
|
|
<div class="flex-shrink-0">
|
|
<div class="avatar-sm">
|
|
<span class="avatar-title bg-primary-subtle text-primary rounded-circle fs-3">
|
|
<i class="uil-moneybag"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div class="flex-grow-1">
|
|
<p class="text-muted mb-1">Jumlah Terpakai</p>
|
|
<h4 class="mb-0" id="totalTerpakai">{{ $showQuestionMark ? '?' : 'Rp 0' }}</h4>
|
|
</div>
|
|
<div class="flex-shrink-0">
|
|
<div class="avatar-sm">
|
|
<span class="avatar-title bg-warning-subtle text-warning rounded-circle fs-3">
|
|
<i class="uil-shopping-cart"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
<div class="col-md-{{ $hideJumlahCards ? '12' : '4' }}">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<div class="d-flex align-items-center">
|
|
<div class="flex-grow-1">
|
|
<p class="text-muted mb-1">Sisa Pagu</p>
|
|
<h4 class="mb-0" id="sisaPagu">Rp 0</h4>
|
|
</div>
|
|
<div class="flex-shrink-0">
|
|
<div class="avatar-sm">
|
|
<span class="avatar-title bg-success-subtle text-success rounded-circle fs-3">
|
|
<i class="uil-wallet"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
|
|
<!-- Form Filter -->
|
|
<div class="mb-4">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<label for="periode" class="form-label">Periode (Tahun)</label>
|
|
<select name="periode" id="periode" class="form-select select2"
|
|
data-placeholder="Pilih Periode">
|
|
<option value="">Semua Periode</option>
|
|
@foreach ($periodes as $periode)
|
|
<option value="{{ $periode }}" {{ $periode == date('Y') ? 'selected' : '' }}>
|
|
{{ $periode }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Tabel Data Pagu -->
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered w-100" id="paguTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Unit Kerja</th>
|
|
<th>Tahun</th>
|
|
@if(!$hideJumlahCards)
|
|
<th>Pagu</th>
|
|
<th>Jumlah Terpakai</th>
|
|
@endif
|
|
<th>Sisa Pagu</th>
|
|
@if($canUbah || $canHapus)
|
|
<th>Aksi</th>
|
|
@endif
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
@if($canTambah || $canUbah)
|
|
<!-- Modal Form Pagu -->
|
|
<div class="modal fade" id="paguModal" tabindex="-1" role="dialog" aria-labelledby="paguModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<form id="paguForm">
|
|
@csrf
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="paguModalLabel">Tambah Pagu</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="hidden" id="pagu_id" name="pagu_id">
|
|
|
|
<div class="form-group mb-3">
|
|
<label for="unit_pembayaran_id" class="form-label">Unit Kerja <span class="text-danger">*</span></label>
|
|
<select class="form-select select2" id="unit_pembayaran_id" name="unit_pembayaran_id"
|
|
data-placeholder="Pilih Unit Kerja" data-dropdown-parent="#paguModal">
|
|
<option value=""></option>
|
|
@foreach($unitKerjas as $unit)
|
|
<option value="{{ $unit->id }}">{{ $unit->nama }}</option>
|
|
@endforeach
|
|
</select>
|
|
<div class="invalid-feedback"></div>
|
|
</div>
|
|
|
|
<div class="form-group mb-3">
|
|
<label for="tahun" class="form-label">Tahun <span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" id="tahun" name="tahun"
|
|
placeholder="Contoh: {{ date('Y') }}" min="2000" max="2099">
|
|
<div class="invalid-feedback"></div>
|
|
</div>
|
|
|
|
<div class="form-group mb-3">
|
|
<label for="pagu" class="form-label">Pagu <span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" id="pagu" name="pagu"
|
|
placeholder="Masukkan jumlah pagu" min="0" step="any">
|
|
<div class="invalid-feedback"></div>
|
|
</div>
|
|
|
|
<div class="form-group mb-3">
|
|
<label for="pagu_smt1" class="form-label">Pagu Semester 1 <span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" id="pagu_smt1" name="pagu_smt1"
|
|
placeholder="Masukkan pagu semester 1" min="0" step="any">
|
|
<div class="invalid-feedback"></div>
|
|
</div>
|
|
|
|
<div class="form-group mb-3">
|
|
<label for="pagu_smt2" class="form-label">Pagu Semester 2 <span class="text-danger">*</span></label>
|
|
<input type="number" class="form-control" id="pagu_smt2" name="pagu_smt2"
|
|
placeholder="Masukkan pagu semester 2" min="0" step="any">
|
|
<div class="invalid-feedback"></div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
|
<button type="submit" class="btn btn-primary" id="submitBtn">Simpan</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
@endsection
|
|
|
|
@section('js')
|
|
<script>
|
|
let table;
|
|
let isEdit = false;
|
|
const hasBacaPagu = {{ $hasBacaPagu ? 'true' : 'false' }};
|
|
const canTambah = {{ $canTambah ? 'true' : 'false' }};
|
|
const canUbah = {{ $canUbah ? 'true' : 'false' }};
|
|
const canHapus = {{ $canHapus ? 'true' : 'false' }};
|
|
const showAksi = canUbah || canHapus;
|
|
const showQuestionMark = {{ $showQuestionMark ? 'true' : 'false' }};
|
|
const hideJumlahCards = {{ $hideJumlahCards ? 'true' : 'false' }};
|
|
const currentYear = '{{ date("Y") }}';
|
|
|
|
$(document).ready(function() {
|
|
// Initialize Select2 for filter periode, default to current year
|
|
$('#periode').select2({
|
|
allowClear: true,
|
|
placeholder: 'Pilih Periode',
|
|
width: '100%'
|
|
}).val(currentYear).trigger('change');
|
|
|
|
if (canTambah || canUbah) {
|
|
initModalSelect2();
|
|
|
|
$('#paguModal').on('shown.bs.modal', function() {
|
|
initModalSelect2();
|
|
});
|
|
|
|
// Handle form submission
|
|
$('#paguForm').on('submit', function(e) {
|
|
e.preventDefault();
|
|
submitForm();
|
|
});
|
|
|
|
// Handle edit button
|
|
if (canUbah) {
|
|
$(document).on('click', '.edit-btn', function() {
|
|
let id = $(this).data('id');
|
|
isEdit = true;
|
|
|
|
$.ajax({
|
|
url: "{{ route('pagu.show', ':id') }}".replace(':id', id),
|
|
type: 'GET',
|
|
success: function(data) {
|
|
$('#pagu_id').val(data.id);
|
|
$('#tahun').val(data.tahun);
|
|
$('#pagu').val(data.pagu);
|
|
$('#pagu_smt1').val(data.pagu_smt1);
|
|
$('#pagu_smt2').val(data.pagu_smt2);
|
|
$('#paguModalLabel').text('Edit Pagu');
|
|
|
|
let modal = new bootstrap.Modal(document.getElementById('paguModal'));
|
|
modal.show();
|
|
|
|
setTimeout(function() {
|
|
$('#unit_pembayaran_id').val(data.unit_pembayaran_id).trigger('change');
|
|
}, 300);
|
|
},
|
|
error: function() {
|
|
showAlert('error', 'Gagal memuat data pagu.');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
// Handle delete button
|
|
if (canHapus) {
|
|
$(document).on('click', '.delete-btn', function() {
|
|
let id = $(this).data('id');
|
|
|
|
if (confirm('Apakah Anda yakin ingin menghapus data pagu ini?')) {
|
|
$.ajax({
|
|
url: "{{ route('pagu.destroy', ':id') }}".replace(':id', id),
|
|
type: 'DELETE',
|
|
data: {
|
|
_token: '{{ csrf_token() }}'
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
table.ajax.reload();
|
|
loadSummary();
|
|
showAlert('success', response.message);
|
|
}
|
|
},
|
|
error: function() {
|
|
showAlert('error', 'Terjadi kesalahan saat menghapus data.');
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
// Define columns
|
|
var columns = [
|
|
{ data: 'unit_kerja_nama', name: 'unit_kerja_nama' },
|
|
{ data: 'tahun', name: 'tahun', className: 'text-center' }
|
|
];
|
|
|
|
if (!hideJumlahCards) {
|
|
columns.push({ data: 'pagu', name: 'pagu', className: 'text-center' });
|
|
columns.push({
|
|
data: 'jumlah_terpakai',
|
|
name: 'jumlah_terpakai',
|
|
orderable: false,
|
|
searchable: false,
|
|
className: 'text-center'
|
|
});
|
|
}
|
|
|
|
columns.push({
|
|
data: 'jumlah_sisa_pagu',
|
|
name: 'jumlah_sisa_pagu',
|
|
orderable: false,
|
|
searchable: false,
|
|
className: 'text-center'
|
|
});
|
|
|
|
if (showAksi) {
|
|
columns.push({
|
|
data: 'action',
|
|
name: 'action',
|
|
orderable: false,
|
|
searchable: false,
|
|
className: 'text-center',
|
|
width: '8%'
|
|
});
|
|
}
|
|
|
|
// Initialize DataTable with current year as default filter
|
|
table = $('#paguTable').DataTable({
|
|
processing: true,
|
|
serverSide: true,
|
|
ajax: {
|
|
url: "{{ route('pagu.data') }}",
|
|
data: function(d) {
|
|
d.periode = $('#periode').val();
|
|
}
|
|
},
|
|
columns: columns,
|
|
language: {
|
|
processing: "<div class='spinner'></div> Sedang Memuat...",
|
|
},
|
|
ordering: false
|
|
});
|
|
|
|
loadSummary();
|
|
|
|
$('#periode').on('change', function() {
|
|
table.ajax.reload();
|
|
loadSummary();
|
|
});
|
|
|
|
$('#exportExcelBtn').on('click', function() {
|
|
var periode = $('#periode').val();
|
|
var url = "{{ route('pagu.export') }}" + "?periode=" + periode;
|
|
window.location.href = url;
|
|
});
|
|
});
|
|
|
|
function loadSummary() {
|
|
if (!hasBacaPagu) {
|
|
return;
|
|
}
|
|
|
|
$.ajax({
|
|
url: "{{ route('pagu.summary') }}",
|
|
data: { periode: $('#periode').val() },
|
|
success: function(response) {
|
|
if (hideJumlahCards) {
|
|
$('#sisaPagu').text('Rp ' + response.sisa_pagu.toLocaleString('id-ID'));
|
|
} else {
|
|
$('#totalPagu').text('Rp ' + response.total_pagu.toLocaleString('id-ID'));
|
|
$('#totalTerpakai').text('Rp ' + response.total_terpakai.toLocaleString('id-ID'));
|
|
$('#sisaPagu').text('Rp ' + response.sisa_pagu.toLocaleString('id-ID'));
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function initModalSelect2() {
|
|
$('#unit_pembayaran_id').select2({
|
|
allowClear: true,
|
|
placeholder: 'Pilih Unit Kerja',
|
|
width: '100%',
|
|
dropdownParent: $('#paguModal')
|
|
});
|
|
}
|
|
|
|
function submitForm() {
|
|
let id = $('#pagu_id').val();
|
|
let url = isEdit
|
|
? "{{ route('pagu.update', ':id') }}".replace(':id', id)
|
|
: "{{ route('pagu.store') }}";
|
|
|
|
let formData = {
|
|
_token: '{{ csrf_token() }}',
|
|
unit_pembayaran_id: $('#unit_pembayaran_id').val(),
|
|
tahun: $('#tahun').val(),
|
|
pagu: $('#pagu').val(),
|
|
pagu_smt1: $('#pagu_smt1').val(),
|
|
pagu_smt2: $('#pagu_smt2').val(),
|
|
};
|
|
|
|
if (isEdit) {
|
|
formData._method = 'PUT';
|
|
}
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: 'POST',
|
|
data: formData,
|
|
beforeSend: function() {
|
|
$('#submitBtn').prop('disabled', true).text('Menyimpan...');
|
|
$('.is-invalid').removeClass('is-invalid');
|
|
$('.invalid-feedback').text('');
|
|
},
|
|
success: function(response) {
|
|
if (response.success) {
|
|
bootstrap.Modal.getInstance(document.getElementById('paguModal')).hide();
|
|
table.ajax.reload();
|
|
loadSummary();
|
|
showAlert('success', response.message);
|
|
}
|
|
},
|
|
error: function(xhr) {
|
|
if (xhr.status === 422) {
|
|
let errors = xhr.responseJSON.errors;
|
|
$.each(errors, function(key, value) {
|
|
let field = $('#' + key);
|
|
field.addClass('is-invalid');
|
|
field.siblings('.invalid-feedback').text(value[0]);
|
|
// Handle select2
|
|
field.parent().find('.invalid-feedback').text(value[0]);
|
|
});
|
|
} else {
|
|
let msg = (xhr.responseJSON && xhr.responseJSON.message)
|
|
? xhr.responseJSON.message
|
|
: 'Terjadi kesalahan saat menyimpan data.';
|
|
showAlert('error', msg);
|
|
}
|
|
},
|
|
complete: function() {
|
|
$('#submitBtn').prop('disabled', false).text('Simpan');
|
|
}
|
|
});
|
|
}
|
|
|
|
function resetForm() {
|
|
isEdit = false;
|
|
$('#paguForm')[0].reset();
|
|
$('#pagu_id').val('');
|
|
$('#unit_pembayaran_id').val(null).trigger('change');
|
|
$('#paguModalLabel').text('Tambah Pagu');
|
|
$('.is-invalid').removeClass('is-invalid');
|
|
$('.invalid-feedback').text('');
|
|
}
|
|
|
|
function showAlert(type, message) {
|
|
if (type === 'success') {
|
|
showSuccess('Berhasil', message);
|
|
} else if (type === 'error') {
|
|
showError('Error', message);
|
|
} else {
|
|
showInfo('Informasi', message);
|
|
}
|
|
}
|
|
</script>
|
|
@endsection
|