feat(noc): implementasi logika conditional checkbox status pembayaran

- Menambahkan fungsi `updateCheckboxStatus()` untuk evaluasi kondisi real-time.
- Checkbox otomatis disabled jika total_harus_bayar = nominal_bayar = total_pembukuan.
- Checkbox **status_kurang_bayar** aktif jika nominal/pembukuan < total_harus_bayar.
- Checkbox **status_lebih_bayar** aktif jika nominal/pembukuan > total_harus_bayar.
- Menambahkan event listeners pada field nominal_bayar dan total_pembukuan.
- Memastikan initial state dicek saat halaman dimuat.
- Menambahkan logging untuk debugging dan monitoring.
- Meningkatkan UX dengan mencegah input data tidak logis.
This commit is contained in:
Daeng Deni Mardaeni
2025-09-12 08:55:44 +07:00
parent eb784a982f
commit ba29f5ee8e
4 changed files with 277 additions and 183 deletions

View File

@@ -394,6 +394,79 @@
const nominalLebihBayarSection = document.getElementById('nominal_lebih_bayar_section');
const buktiPengembalianSection = document.getElementById('bukti_pengembalian_section');
// Field untuk perbandingan nilai
const totalHarusBayar = document.getElementById('total_harus_bayar');
const nominalBayar = document.getElementById('nominal_bayar');
const totalPembukuan = document.getElementById('total_pembukuan');
/**
* Fungsi untuk mengatur enable/disable status checkbox berdasarkan perbandingan nilai
* Logika:
* - Jika semua nilai sama: kedua checkbox disabled
* - Jika nominal_bayar/total_pembukuan < total_harus_bayar: hanya status_kurang_bayar enabled
* - Jika nominal_bayar/total_pembukuan > total_harus_bayar: hanya status_lebih_bayar enabled
*/
function updateCheckboxStatus() {
const totalHarus = parseFloat(totalHarusBayar.value) || 0;
const nominal = parseFloat(nominalBayar.value) || 0;
const pembukuan = parseFloat(totalPembukuan.value) || 0;
console.log('Updating checkbox status:', {
totalHarus,
nominal,
pembukuan
});
// Reset checkbox states
statusKurangBayar.disabled = false;
statusLebihBayar.disabled = false;
// Jika semua nilai sama, disable kedua checkbox
if (totalHarus === nominal && nominal === pembukuan && totalHarus > 0) {
statusKurangBayar.disabled = true;
statusLebihBayar.disabled = true;
statusKurangBayar.checked = false;
statusLebihBayar.checked = false;
nominalKurangBayarSection.style.display = 'none';
nominalLebihBayarSection.style.display = 'none';
buktiPengembalianSection.style.display = 'none';
console.log('Semua nilai sama, kedua checkbox disabled');
}
// Jika nominal/pembukuan kurang dari total harus bayar
else if ((nominal > 0 && nominal < totalHarus) || (pembukuan > 0 && pembukuan < totalHarus)) {
statusLebihBayar.disabled = true;
statusLebihBayar.checked = false;
statusKurangBayar.checked = true;
nominalKurangBayarSection.style.display = '';
nominalLebihBayarSection.style.display = 'none';
buktiPengembalianSection.style.display = 'none';
console.log('Kurang bayar, hanya status_kurang_bayar enabled');
}
// Jika nominal/pembukuan lebih dari total harus bayar
else if ((nominal > 0 && nominal > totalHarus) || (pembukuan > 0 && pembukuan > totalHarus)) {
statusKurangBayar.disabled = true;
statusKurangBayar.checked = false;
statusLebihBayar.checked = true;
nominalLebihBayarSection.style.display = '';
nominalKurangBayarSection.style.display = 'none';
console.log('Lebih bayar, hanya status_lebih_bayar enabled');
}
}
// Event listeners untuk update otomatis saat nilai berubah
if (nominalBayar) {
nominalBayar.addEventListener('input', updateCheckboxStatus);
nominalBayar.addEventListener('change', updateCheckboxStatus);
}
if (totalPembukuan) {
totalPembukuan.addEventListener('input', updateCheckboxStatus);
totalPembukuan.addEventListener('change', updateCheckboxStatus);
}
// Initial check saat halaman dimuat
updateCheckboxStatus();
/**
* Fungsi untuk reset field dan section visibility
* @param {string} type - 'kurang' atau 'lebih'
@@ -426,6 +499,12 @@
}
statusKurangBayar.addEventListener('change', function() {
// Cek apakah checkbox tidak disabled sebelum memproses
if (this.disabled) {
this.checked = false;
return;
}
if (this.checked) {
nominalKurangBayarSection.style.display = 'flex';
resetFields('kurang');
@@ -451,6 +530,12 @@
}
statusLebihBayar.addEventListener('change', function() {
// Cek apakah checkbox tidak disabled sebelum memproses
if (this.disabled) {
this.checked = false;
return;
}
if (this.checked) {
nominalLebihBayarSection.style.display = 'flex';
buktiPengembalianSection.style.display = 'flex';

View File

@@ -5,9 +5,10 @@
@endsection
@section('content')
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
<div class="card border border-agi-100 card-grid min-w-full" data-datatable="false" data-datatable-page-size="10" data-datatable-state-save="false" id="noc-table" data-api-url="{{ route('noc.datatables') }}">
<div class="card-header bg-agi-50 py-5 flex-wrap">
<div class="grid gap-5 mx-auto w-full lg:gap-7.5">
<div class="min-w-full border card border-agi-100 card-grid" data-datatable="false" data-datatable-page-size="10"
data-datatable-state-save="false" id="noc-table" data-api-url="{{ route('noc.datatables') }}">
<div class="flex-wrap py-5 card-header bg-agi-50">
<h3 class="card-title">
Daftar NOC
</h3>
@@ -27,77 +28,78 @@
<div class="card-body">
<div class="scrollable-x-auto">
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
data-datatable-table="true">
<thead>
<tr>
<th class="w-14">
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox"/>
</th>
<th class="min-w-[150px]" data-datatable-column="nomor_registrasi">
<span class="sort"> <span class="sort-label"> Nomor Registrasi </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nama_debitur">
<span class="sort"> <span class="sort-label"> Nama Debitur </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="cabang">
<span class="sort"> <span class="sort-label"> Cabang </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_setor">
<span class="sort"> <span class="sort-label"> Tanggal KSL </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_bayar">
<span class="sort"> <span class="sort-label"> Nominal bayar </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_bayar">
<span class="sort"> <span class="sort-label"> Bukti Bayar </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_diterima">
<span class="sort"> <span class="sort-label"> Nominal Diterima </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_ksl">
<span class="sort"> <span class="sort-label"> Bukti KSL </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_pembayaran">
<span class="sort"> <span class="sort-label"> Tanggal Pembayaran </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="memo_penyelesaian">
<span class="sort"> <span class="sort-label"> Memo Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_penyelesaian">
<span class="sort"> <span class="sort-label"> Bukti Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_penyelesaian">
<span class="sort"> <span class="sort-label"> Nominal Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_penyelesaian">
<span class="sort"> <span class="sort-label"> Tanggal Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
</tr>
<tr>
<th class="w-14">
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox" />
</th>
<th class="min-w-[150px]" data-datatable-column="nomor_registrasi">
<span class="sort"> <span class="sort-label"> Nomor Registrasi </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nama_debitur">
<span class="sort"> <span class="sort-label"> Nama Debitur </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="cabang">
<span class="sort"> <span class="sort-label"> Cabang </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_setor">
<span class="sort"> <span class="sort-label"> Tanggal KSL </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_bayar">
<span class="sort"> <span class="sort-label"> Nominal bayar </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_bayar">
<span class="sort"> <span class="sort-label"> Bukti Bayar </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_diterima">
<span class="sort"> <span class="sort-label"> Nominal Diterima </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_ksl">
<span class="sort"> <span class="sort-label"> Bukti KSL </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_pembayaran">
<span class="sort"> <span class="sort-label"> Tanggal Pembayaran </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="memo_penyelesaian">
<span class="sort"> <span class="sort-label"> Memo Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="bukti_penyelesaian">
<span class="sort"> <span class="sort-label"> Bukti Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="nominal_penyelesaian">
<span class="sort"> <span class="sort-label"> Nominal Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[150px]" data-datatable-column="tanggal_penyelesaian">
<span class="sort"> <span class="sort-label"> Tanggal Penyelesaian </span>
<span class="sort-icon"> </span> </span>
</th>
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
</tr>
</thead>
</table>
</div>
<div
class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
<div class="flex items-center gap-2">
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
<div class="flex gap-2 items-center">
Show
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
page
</div>
<div class="flex items-center gap-4">
<div class="flex gap-4 items-center">
<span data-datatable-info="true"> </span>
<div class="pagination" data-datatable-pagination="true">
</div>
@@ -105,140 +107,143 @@
</div>
</div>
</div>
@endsection
@endsection
@push('scripts')
<script type="text/javascript">
function prosesData(data) {
Swal.fire({
title: 'NOC',
text: "Apakah Anda yakin ingin menyetujui pembayaran ini?",
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya',
cancelButtonText: 'Tidak'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = `noc/${data}/edit`;
@push('scripts')
<script type="text/javascript">
function prosesData(data) {
Swal.fire({
title: 'NOC',
text: "Apakah Anda yakin ingin menyetujui pembayaran ini?",
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya',
cancelButtonText: 'Tidak'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = `noc/${data}/edit`;
}
})
}
</script>
<script type="module">
const element = document.querySelector('#noc-table');
const searchInput = document.getElementById('search');
const apiUrl = element.getAttribute('data-api-url');
const dataTableOptions = {
apiEndpoint: apiUrl,
pageSize: 5,
columns: {
select: {
render: (item, data, context) => {
const checkbox = document.createElement('input');
checkbox.className = 'checkbox checkbox-sm';
checkbox.type = 'checkbox';
checkbox.value = data.id.toString();
checkbox.setAttribute('data-datatable-row-check', 'true');
return checkbox.outerHTML.trim();
},
},
nomor_registrasi: {
title: 'Nomor Registrasi'
},
nama_debitur: {
title: 'Nama Debitur',
},
cabang: {
title: 'Cabang',
return: (item, data) => {
return data.cabang.code + ' - ' + data.cabang.nama;
}
})
}
</script>
<script type="module">
const element = document.querySelector('#noc-table');
const searchInput = document.getElementById('search');
const apiUrl = element.getAttribute('data-api-url');
const dataTableOptions = {
apiEndpoint: apiUrl,
pageSize: 5,
columns: {
select: {
render: (item, data, context) => {
const checkbox = document.createElement('input');
checkbox.className = 'checkbox checkbox-sm';
checkbox.type = 'checkbox';
checkbox.value = data.id.toString();
checkbox.setAttribute('data-datatable-row-check', 'true');
return checkbox.outerHTML.trim();
},
},
nomor_registrasi: {
title: 'Nomor Registrasi'
},
nama_debitur: {
title: 'Nama Debitur',
},
cabang: {
title: 'Cabang',
},
tanggal_setor: {
title: 'Tanggal Setor',
},
nominal_bayar: {
title: 'Nominal Bayar',
},
bukti_bayar: {
title: 'Bukti KSL',
render: (item, data) => {
if (data.bukti_bayar) {
return `<a href="storage/${data.bukti_bayar}" download="storage/${data.bukti_bayar}" target="_blank" class="badge badge-sm badge-outline">
},
tanggal_setor: {
title: 'Tanggal Setor',
},
nominal_bayar: {
title: 'Nominal Bayar',
},
bukti_bayar: {
title: 'Bukti KSL',
render: (item, data) => {
if (data.bukti_bayar) {
return `<a href="storage/${data.bukti_bayar}" download="storage/${data.bukti_bayar}" target="_blank" class="badge badge-sm badge-outline">
Download <i class="ki-filled ki-cloud-download"></i>
</a>`;
} else {
return '-';
}
},
} else {
return '-';
}
},
nominal_diterima: {
title: 'Nominal Diterima',
},
bukti_ksl: {
title: 'Bukti KSL',
render: (item, data) => {
if (data.bukti_ksl) {
return `<a href="storage/${data.bukti_ksl}" download="storage/${data.bukti_ksl}" target="_blank" class="badge badge-sm badge-outline">
},
nominal_diterima: {
title: 'Nominal Diterima',
},
bukti_ksl: {
title: 'Bukti KSL',
render: (item, data) => {
if (data.bukti_ksl) {
return `<a href="storage/${data.bukti_ksl}" download="storage/${data.bukti_ksl}" target="_blank" class="badge badge-sm badge-outline">
Download <i class="ki-filled ki-cloud-download"></i>
</a>`;
} else {
return '-';
}
},
} else {
return '-';
}
},
tanggal_pembayaran: {
title: 'Tanggal Pembayaran',
},
memo_penyelesaian: {
title: 'Memo Penyelesaian',
render: (item, data) => {
if (data.memo_penyelesaian) {
return `<a href="storage/${data.memo_penyelesaian}" download="storage/${data.memo_penyelesaian}" target="_blank" class="badge badge-sm badge-outline">
},
tanggal_pembayaran: {
title: 'Tanggal Pembayaran',
},
memo_penyelesaian: {
title: 'Memo Penyelesaian',
render: (item, data) => {
if (data.memo_penyelesaian) {
return `<a href="storage/${data.memo_penyelesaian}" download="storage/${data.memo_penyelesaian}" target="_blank" class="badge badge-sm badge-outline">
Download <i class="ki-filled ki-cloud-download"></i>
</a>`;
} else {
return '-';
}
},
} else {
return '-';
}
},
bukti_penyelesaian: {
title: 'Bukti Penyelesaian',
render: (item, data) => {
if (data.bukti_penyelesaian) {
return `<a href="storage/${data.bukti_penyelesaian}" download="storage/${data.bukti_penyelesaian}" target="_blank" class="badge badge-sm badge-outline">
},
bukti_penyelesaian: {
title: 'Bukti Penyelesaian',
render: (item, data) => {
if (data.bukti_penyelesaian) {
return `<a href="storage/${data.bukti_penyelesaian}" download="storage/${data.bukti_penyelesaian}" target="_blank" class="badge badge-sm badge-outline">
Download <i class="ki-filled ki-cloud-download"></i>
</a>`;
} else {
return '-';
}
},
} else {
return '-';
}
},
nominal_penyelesaian: {
title: 'Nominal Penyelesaian',
},
tanggal_penyelesaian: {
title: 'Tanggal Penyelesaian',
},
actions: {
title: 'Action',
render: (item, data) => {
return `<div class="flex flex-nowrap justify-center">
},
nominal_penyelesaian: {
title: 'Nominal Penyelesaian',
},
tanggal_penyelesaian: {
title: 'Tanggal Penyelesaian',
},
actions: {
title: 'Action',
render: (item, data) => {
return `<div class="flex flex-nowrap justify-center">
<a class="btn btn-sm btn-outline btn-info" onclick="prosesData(${data.id})">
<i class="ki-filled ki-double-check"></i>
</a>
</div>`;
},
}
},
};
},
}
},
};
let dataTable = new KTDataTable(element, dataTableOptions);
// Custom search functionality
searchInput.addEventListener('input', function () {
const searchValue = this.value.trim();
dataTable.search(searchValue, true);
});
</script>
let dataTable = new KTDataTable(element, dataTableOptions);
// Custom search functionality
searchInput.addEventListener('input', function() {
const searchValue = this.value.trim();
dataTable.search(searchValue, true);
});
</script>
@endpush

View File

@@ -140,6 +140,9 @@
},
cabang: {
title: 'Cabang',
render: (item, data) => {
return data.kode_cabang + ' - ' + data.cabang;
}
},
tanggal_setor: {
title: 'Tanggal KSL',