fix: resolve issues in laporan gadaian ujrah

This commit is contained in:
nurafrinaalimi16
2026-09-06 15:55:50 +08:00
committed by ISMAIL MASSERAN
parent 834556b65d
commit b6e4cf79ef
2 changed files with 139 additions and 62 deletions
+11 -2
View File
@@ -4012,12 +4012,21 @@ class KhazanahController extends Controller
$hingga_date = $split_date[2] . '-' . $split_date[1] . '-' . $split_date[0]; $hingga_date = $split_date[2] . '-' . $split_date[1] . '-' . $split_date[0];
} }
$reportGadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url'). '/api/gadailaporanRangeDate/'. $auth_user['cawangan'] ,['mula' => $mula_date,'akhir' => $hingga_date])->json();
$gadai = $reportGadai['gadai'];
$statistik =$reportGadai['statistik'];
$reportPembiayaan= $statistik['reportPembiayaan'];
$reportLoanAmount=$statistik['reportLoanAmount'];
$reportMarhunValue=$statistik['reportMarhunValue'];
$reportMarhunMargin=$statistik['reportMarhunMargin'];
$reportCustomerJob=$statistik['reportCustomerJob'];
$reportCustomerRace=$statistik['reportCustomerRace'];
// dd($reportCustomerRace);
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url'). '/api/gadailaporanRangeDate/'. $auth_user['cawangan'] ,['mula' => $mula_date,'akhir' => $hingga_date])->json();
$cawangan=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/cawangan/detail/'.$auth_user['cawangan'])->json(); $cawangan=Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url').'/api/cawangan/detail/'.$auth_user['cawangan'])->json();
$cawangan_detail=$cawangan[0]; $cawangan_detail=$cawangan[0];
return view('print.laporan_gadaian_ujrah', compact('gadai','cawangan_detail','tarikh_cetak','mula_date','api_url','hingga_date')); return view('print.laporan_gadaian_ujrah', compact('gadai','cawangan_detail','tarikh_cetak','mula_date','api_url','hingga_date','statistik','reportPembiayaan','reportLoanAmount','reportMarhunValue','reportMarhunMargin','reportCustomerJob','reportCustomerRace','reportCustomerRace'));
} }
@@ -22,7 +22,7 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-"> <div class="col-md-12">
<form action="{{ route('gadaianujrah.laporancetak') }}" target="_blank" method="post"> <form action="{{ route('gadaianujrah.laporancetak') }}" target="_blank" method="post">
@csrf @csrf
<div class="input-group mb-3"> <div class="input-group mb-3">
@@ -86,6 +86,7 @@
var tablegadai = $('#myTable').DataTable({ var tablegadai = $('#myTable').DataTable({
"ordering": false "ordering": false
}); });
$(document).ready(function () { $(document).ready(function () {
$('#datemula').datepicker({ $('#datemula').datepicker({
format: 'dd-mm-yyyy' format: 'dd-mm-yyyy'
@@ -108,14 +109,42 @@
mula:today_date, mula:today_date,
akhir:today_date, akhir:today_date,
}, },
success: function(gadai){ success: function(response){
console.log('=== RESPONSE PENUH ===');
console.log('Type:', typeof response);
console.log('Is Array:', Array.isArray(response));
console.log('Response:', response);
// Check jika response adalah array terus
var gadai;
if (Array.isArray(response)) {
gadai = response;
} else if (response.gadai && Array.isArray(response.gadai)) {
gadai = response.gadai;
} else {
gadai = [];
}
console.log('=== DATA GADAI ===');
console.log('Jumlah rekod:', gadai.length);
console.log('Data gadai:', gadai);
if(gadai.length > 0) {
console.log('Contoh rekod pertama:', gadai[0]);
console.log('Field yang ada:', Object.keys(gadai[0]));
}
gadaitable(gadai); gadaitable(gadai);
},
error: function(xhr, status, error) {
console.error('Error AJAX:', error);
console.error('Status:', status);
console.error('Response:', xhr.responseText);
} }
}); });
}); });
$('#datemula').change(function(){ $('#datemula').change(function(){
//mula //mula
var input_date = this.value; var input_date = this.value;
var split_date = input_date.split('-'); var split_date = input_date.split('-');
@@ -151,7 +180,18 @@
mula:mula, mula:mula,
akhir:akhir, akhir:akhir,
}, },
success: function(gadai){ success: function(response){
console.log('Response datemula:', response);
var gadai;
if (Array.isArray(response)) {
gadai = response;
} else if (response.gadai && Array.isArray(response.gadai)) {
gadai = response.gadai;
} else {
gadai = [];
}
gadaitable(gadai); gadaitable(gadai);
} }
}); });
@@ -189,7 +229,18 @@
mula:mula, mula:mula,
akhir:akhir, akhir:akhir,
}, },
success: function(gadai){ success: function(response){
console.log('Response datehingga:', response);
var gadai;
if (Array.isArray(response)) {
gadai = response;
} else if (response.gadai && Array.isArray(response.gadai)) {
gadai = response.gadai;
} else {
gadai = [];
}
gadaitable(gadai); gadaitable(gadai);
} }
}); });
@@ -208,55 +259,72 @@
var total_onepercent = 0; var total_onepercent = 0;
var total_ujrah = 0; var total_ujrah = 0;
tablegadai.clear().draw(); tablegadai.clear().draw();
$.each(data,function(index,gadai){
total_pinjaman += Number(gadai['pinjaman']);
total_nm += Number(gadai['nilaimarhun']);
total_berat += Number(gadai['berat']);
total_onepercent += Number(gadai['onepercent']*12);
total_ujrah += Number(gadai['ujrah']*12);
if (gadai['tagbaru'] == 0) {
var upah12 = gadai['upah12'];
} else {
var upah12 = gadai['ujrah']*12 + gadai['onepercent']*12;
// Semak jika data kosong
if(!data || data.length === 0) {
console.log('Tiada data untuk dipaparkan');
return;
} }
total_upah12 += Number(upah12) ; // TAMBAH INI: Log structure data pertama
console.log('=== STRUKTUR DATA ===');
console.log('Data pertama:', data[0]);
console.log('Keys yang ada:', Object.keys(data[0]));
$.each(data,function(index,gadai){
// Log setiap item untuk debug
console.log('Item ' + index + ':', gadai);
// Validasi data sebelum gunakan
var pinjaman = gadai['pinjaman'] ? Number(gadai['pinjaman']) : 0;
var nilaimarhun = gadai['nilaimarhun'] ? Number(gadai['nilaimarhun']) : 0;
var berat = gadai['berat'] ? Number(gadai['berat']) : 0;
var onepercent = gadai['onepercent'] ? Number(gadai['onepercent']) : 0;
var ujrah = gadai['ujrah'] ? Number(gadai['ujrah']) : 0;
console.log('Nilai processed:', {pinjaman, nilaimarhun, berat, onepercent, ujrah});
total_pinjaman += pinjaman;
total_nm += nilaimarhun;
total_berat += berat;
total_onepercent += (onepercent * 12);
total_ujrah += (ujrah * 12);
var upah12 = 0;
if (gadai['tagbaru'] == 0) {
upah12 = gadai['upah12'] ? Number(gadai['upah12']) : 0;
} else {
upah12 = (ujrah * 12) + (onepercent * 12);
}
total_upah12 += upah12;
// Pastikan semua nilai ada sebelum add row
tablegadai.row.add([ tablegadai.row.add([
counter, counter,
gadai['nama'], gadai['nama'] || '-',
gadai['nokp'], gadai['nokp'] || '-',
gadai['t_gadai'], gadai['t_gadai'] || '-',
gadai['norujukan'], gadai['norujukan'] || '-',
formatter.format(gadai['pinjaman']), formatter.format(pinjaman),
formatter.format(gadai['ujrah']*12), formatter.format(ujrah * 12),
formatter.format(gadai['onepercent']*12), formatter.format(onepercent * 12),
formatter.format(upah12), formatter.format(upah12),
formatter.format(gadai['nilaimarhun']), formatter.format(nilaimarhun),
formatter.format(gadai['berat']) formatter.format(berat)
]).draw(); ]).draw(false);
counter++;
});
// Update total selepas loop selesai
$('#pinjamantotal').text(formatter.format(total_pinjaman.toFixed(2))); $('#pinjamantotal').text(formatter.format(total_pinjaman.toFixed(2)));
$('#upah12total').text(formatter.format(total_upah12.toFixed(2))); $('#upah12total').text(formatter.format(total_upah12.toFixed(2)));
$('#nmtotal').text(formatter.format(total_nm.toFixed(2))); $('#nmtotal').text(formatter.format(total_nm.toFixed(2)));
$('#berattotal').text(formatter.format(total_berat.toFixed(2))); $('#berattotal').text(formatter.format(total_berat.toFixed(2)));
$('#berattotal').text(formatter.format(total_berat.toFixed(2)));
$('#onepercenttotal').text(formatter.format(total_onepercent.toFixed(2))); $('#onepercenttotal').text(formatter.format(total_onepercent.toFixed(2)));
$('#ujrahtotal').text(formatter.format(total_ujrah.toFixed(2))); $('#ujrahtotal').text(formatter.format(total_ujrah.toFixed(2)));
counter = counter + 1;
});
} }
</script> </script>
@endsection @endsection