Merge pull request 'Pembaruan P1' (#85) from development into main
Reviewed-on: #85
This commit was merged in pull request #85.
This commit is contained in:
@@ -60,41 +60,7 @@ class P1Controller extends Controller
|
||||
$cacheKey = "p1_rekap_compare_v2_{$jenisPegawai}_{$tahun}_{$bulan}_{$unit}";
|
||||
|
||||
$data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $bulan, $unit) {
|
||||
$apiData = collect((new DawaiService)->getDataP1($jenisPegawai, $tahun, $bulan, $unit))
|
||||
->keyBy(fn ($item) => preg_replace("/['\.\-]/", '', $item['nip'] ?? ''));
|
||||
|
||||
return P1::query()
|
||||
->where('tahun', $tahun)
|
||||
->where('bulan', $bulan)
|
||||
->when($unit !== null && $unit !== '', function ($query) use ($unit) {
|
||||
$idUnitPembayaran = (int) $unit === 0 ? 99 : (int) $unit;
|
||||
$query->where('id_unit_pembayaran', $idUnitPembayaran);
|
||||
})
|
||||
->when($jenisPegawai !== '', function ($query) use ($jenisPegawai) {
|
||||
$query->whereRaw('LOWER(jenis_pegawai) = ?', [strtolower($jenisPegawai)]);
|
||||
})
|
||||
->get()
|
||||
->map(function (P1 $pegawai) use ($apiData) {
|
||||
$apiPegawai = $apiData->get(preg_replace("/['\.\-]/", '', $pegawai->nip));
|
||||
$differs = fn ($dbValue, $apiValue) => $apiPegawai !== null
|
||||
&& abs((float) $dbValue - (float) $apiValue) >= 0.01;
|
||||
|
||||
return [
|
||||
'nama_lengkap' => $pegawai->nama,
|
||||
'nip' => $pegawai->nip,
|
||||
'jenis_pegawai' => strtolower($pegawai->jenis_pegawai ?? ''),
|
||||
'nama_unit' => $pegawai->nama_unit_kerja,
|
||||
'nama_jafung' => $pegawai->nama_jabatan_fungsional,
|
||||
'nama_jtt' => $pegawai->nama_jabatan_tugas_tambahan,
|
||||
'harga_p1' => $pegawai->gaji_yang_dibayarkan,
|
||||
'pajak_p1' => $pegawai->pph21,
|
||||
'harga_p1_setelah_pajak' => $pegawai->gaji_bersih,
|
||||
'harga_p1_diff' => $differs($pegawai->gaji_yang_dibayarkan, $apiPegawai['harga_p1'] ?? 0),
|
||||
'pajak_p1_diff' => $differs($pegawai->pph21, $apiPegawai['pajak_p1'] ?? 0),
|
||||
'harga_p1_setelah_pajak_diff' => $differs($pegawai->gaji_bersih, $apiPegawai['harga_p1_setelah_pajak'] ?? 0),
|
||||
];
|
||||
})
|
||||
->all();
|
||||
return $this->fetchCompareData($jenisPegawai, $tahun, $bulan, $unit);
|
||||
});
|
||||
|
||||
$includePppk2025 = $request->boolean('include_pppk_2025');
|
||||
@@ -152,9 +118,7 @@ class P1Controller extends Controller
|
||||
$cacheKey = "p1_selisih_data_{$jenisPegawai}_{$tahun}_{$bulan}_{$unit}";
|
||||
|
||||
$data = Cache::remember($cacheKey, now()->addDay(), function () use ($jenisPegawai, $tahun, $bulan, $unit) {
|
||||
$dawaiService = new DawaiService;
|
||||
|
||||
return $dawaiService->getDataP1Selisih($jenisPegawai, $tahun, $bulan, $unit);
|
||||
return $this->fetchSelisihData($jenisPegawai, $tahun, $bulan, $unit);
|
||||
});
|
||||
|
||||
$filteredData = collect($data)->filter(function ($item) use ($jenisSelisih, $includePppk2025) {
|
||||
@@ -595,4 +559,101 @@ class P1Controller extends Controller
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => 'Log berhasil disimpan']);
|
||||
}
|
||||
|
||||
public function refresh(Request $request): JsonResponse
|
||||
{
|
||||
$datenow = Carbon::now();
|
||||
$bulanNow = $datenow->format('m');
|
||||
$tahunNow = $datenow->format('Y');
|
||||
$team = Team::find(session('team_id'));
|
||||
|
||||
if (! $team) {
|
||||
return response()->json(['success' => false, 'message' => 'Team tidak ditemukan'], 403);
|
||||
}
|
||||
|
||||
if (! isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0) {
|
||||
$unit = $request->unit;
|
||||
} else {
|
||||
$unit = $team->unit_kerja_id;
|
||||
}
|
||||
|
||||
$tahun = (int) ($request->tahun ?? $tahunNow);
|
||||
$bulan = (int) ($request->bulan ?? $bulanNow);
|
||||
|
||||
try {
|
||||
// Bersihkan semua variasi cache terkait untuk tahun dan bulan terpilih
|
||||
$jenisList = ['', 'dosen', 'jtt-univ', 'jtt', 'tendik'];
|
||||
$unitList = array_unique([$unit, '', null, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
|
||||
foreach ($unitList as $u) {
|
||||
foreach ($jenisList as $j) {
|
||||
Cache::forget("p1_rekap_compare_v2_{$j}_{$tahun}_{$bulan}_{$u}");
|
||||
Cache::forget("p1_rekap_compare_{$j}_{$tahun}_{$bulan}_{$u}");
|
||||
Cache::forget("p1_selisih_data_{$j}_{$tahun}_{$bulan}_{$u}");
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Cache data P1 berhasil dibersihkan.',
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
Log::error('P1 Refresh Error: '.$th->getMessage(), [
|
||||
'exception' => $th,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal memperbarui data cache: '.$th->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function fetchCompareData(string $jenisPegawai, int|string $tahun, int|string $bulan, mixed $unit): array
|
||||
{
|
||||
$dawaiUnit = ($unit !== null && $unit !== '') ? (int) $unit : null;
|
||||
$apiData = collect((new DawaiService)->getDataP1($jenisPegawai, (int) $tahun, (int) $bulan, $dawaiUnit))
|
||||
->keyBy(fn ($item) => preg_replace("/['\.\-]/", '', $item['nip'] ?? ''));
|
||||
|
||||
return P1::query()
|
||||
->where('tahun', $tahun)
|
||||
->where('bulan', $bulan)
|
||||
->when($unit !== null && $unit !== '', function ($query) use ($unit) {
|
||||
$idUnitPembayaran = (int) $unit === 0 ? 99 : (int) $unit;
|
||||
$query->where('id_unit_pembayaran', $idUnitPembayaran);
|
||||
})
|
||||
->when($jenisPegawai !== '', function ($query) use ($jenisPegawai) {
|
||||
$query->whereRaw('LOWER(jenis_pegawai) = ?', [strtolower($jenisPegawai)]);
|
||||
})
|
||||
->get()
|
||||
->map(function (P1 $pegawai) use ($apiData) {
|
||||
$apiPegawai = $apiData->get(preg_replace("/['\.\-]/", '', $pegawai->nip));
|
||||
$differs = fn ($dbValue, $apiValue) => $apiPegawai !== null
|
||||
&& abs((float) $dbValue - (float) $apiValue) >= 0.01;
|
||||
|
||||
return [
|
||||
'nama_lengkap' => $pegawai->nama,
|
||||
'nip' => $pegawai->nip,
|
||||
'jenis_pegawai' => strtolower($pegawai->jenis_pegawai ?? ''),
|
||||
'nama_unit' => $pegawai->nama_unit_kerja,
|
||||
'nama_jafung' => $pegawai->nama_jabatan_fungsional,
|
||||
'nama_jtt' => $pegawai->nama_jabatan_tugas_tambahan,
|
||||
'harga_p1' => $pegawai->gaji_yang_dibayarkan,
|
||||
'pajak_p1' => $pegawai->pph21,
|
||||
'harga_p1_setelah_pajak' => $pegawai->gaji_bersih,
|
||||
'harga_p1_diff' => $differs($pegawai->gaji_yang_dibayarkan, $apiPegawai['harga_p1'] ?? 0),
|
||||
'pajak_p1_diff' => $differs($pegawai->pph21, $apiPegawai['pajak_p1'] ?? 0),
|
||||
'harga_p1_setelah_pajak_diff' => $differs($pegawai->gaji_bersih, $apiPegawai['harga_p1_setelah_pajak'] ?? 0),
|
||||
];
|
||||
})
|
||||
->all();
|
||||
}
|
||||
|
||||
private function fetchSelisihData(string $jenisPegawai, int|string $tahun, int|string $bulan, mixed $unit): array
|
||||
{
|
||||
$dawaiUnit = ($unit !== null && $unit !== '') ? (int) $unit : null;
|
||||
$dawaiService = new DawaiService;
|
||||
|
||||
return $dawaiService->getDataP1Selisih($jenisPegawai, (int) $tahun, (int) $bulan, $dawaiUnit) ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,9 @@
|
||||
'title' => 'Daftar P1',
|
||||
'description' => 'Berikut adalah daftar perhitungan P1 untuk setiap pegawai',
|
||||
'actionButton' => '
|
||||
<button type="button" class="btn btn-sm btn-outline-primary me-2" id="btnPerbaruiData">
|
||||
<i class="mdi mdi-database-refresh-outline"></i> Perbarui Data
|
||||
</button>
|
||||
<a href="#" class="btn btn-sm btn-outline-success export"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-success export-selisih"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||
<a href="#" class="btn btn-sm btn-outline-success export-perbandingan"><i class="uil-file-download-alt"></i> Export Excel</a>
|
||||
@@ -419,6 +422,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="warmCacheModal" tabindex="-1" aria-hidden="true" data-bs-backdrop="static"
|
||||
data-bs-keyboard="false">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body text-center p-4">
|
||||
<h6 class="mb-1">Memperbarui Data P1</h6>
|
||||
<p class="text-muted small mb-3">Membersihkan cache & memuat data terbaru…</p>
|
||||
<div class="progress" style="height: 14px;">
|
||||
<div id="warm-cache-bar"
|
||||
class="progress-bar progress-bar-striped progress-bar-animated bg-primary" role="progressbar"
|
||||
style="width: 0%"></div>
|
||||
</div>
|
||||
<div id="warm-cache-pct" class="fw-semibold mt-2">0%</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('js')
|
||||
@@ -573,6 +593,65 @@
|
||||
tablePerbandingan.ajax.reload();
|
||||
});
|
||||
|
||||
$('#btnPerbaruiData').on('click', function() {
|
||||
var $btn = $(this);
|
||||
var modalEl = document.getElementById('warmCacheModal');
|
||||
var modal = bootstrap.Modal.getOrCreateInstance(modalEl);
|
||||
var $bar = $('#warm-cache-bar');
|
||||
var $pct = $('#warm-cache-pct');
|
||||
var pct = 0;
|
||||
|
||||
function setPct(v) {
|
||||
pct = v;
|
||||
$bar.css('width', v + '%');
|
||||
$pct.text(v + '%');
|
||||
}
|
||||
setPct(0);
|
||||
$btn.prop('disabled', true);
|
||||
modal.show();
|
||||
|
||||
// Progres merangkak sampai ~90% selama menunggu server.
|
||||
var timer = setInterval(function() {
|
||||
if (pct < 90) {
|
||||
setPct(Math.min(90, pct + Math.max(1, Math.round((90 - pct) / 12))));
|
||||
}
|
||||
}, 350);
|
||||
|
||||
var postData = {
|
||||
tahun: $('select#tahun').val(),
|
||||
bulan: $('select#bulan').val(),
|
||||
jenis_pegawai: $('select#jenis_pegawai').val()
|
||||
};
|
||||
|
||||
@if (!$team || !isset($team->unit_kerja_id) || $team->unit_kerja_id === null || $team->unit_kerja_id === 0)
|
||||
postData.unit = $('select#unit_kerja').val();
|
||||
@endif
|
||||
|
||||
$.ajax({
|
||||
url: "{{ route('remunerasi.p1.refresh') }}",
|
||||
method: 'POST',
|
||||
data: postData
|
||||
}).done(function(res) {
|
||||
clearInterval(timer);
|
||||
setPct(100);
|
||||
setTimeout(function() {
|
||||
modal.hide();
|
||||
showSuccess('Berhasil!', res.message || 'Data cache P1 berhasil diperbarui.');
|
||||
if (table) { table.ajax.reload(null, false); }
|
||||
if (tableSelisih) { tableSelisih.ajax.reload(null, false); }
|
||||
if (tablePerbandingan) { tablePerbandingan.ajax.reload(null, false); }
|
||||
}, 450);
|
||||
}).fail(function(xhr) {
|
||||
clearInterval(timer);
|
||||
modal.hide();
|
||||
var errorMsg = (xhr.responseJSON && xhr.responseJSON.message) ?
|
||||
xhr.responseJSON.message : 'Terjadi kesalahan saat memperbarui data.';
|
||||
showError('Gagal', errorMsg);
|
||||
}).always(function() {
|
||||
$btn.prop('disabled', false);
|
||||
});
|
||||
});
|
||||
|
||||
$('a.export').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var button = $(this);
|
||||
|
||||
@@ -21,6 +21,7 @@ Route::middleware('permission:Baca Pembayaran')->prefix('/remunerasi')->name('re
|
||||
Route::get('/export-selisih', [P1Controller::class, 'exportSelisih'])->name('export-selisih');
|
||||
Route::get('/export-perbandingan', [P1Controller::class, 'exportPerbandingan'])->name('export-perbandingan');
|
||||
Route::post('/logs', [P1Controller::class, 'logs'])->name('logs');
|
||||
Route::post('/refresh', [P1Controller::class, 'refresh'])->name('refresh');
|
||||
});
|
||||
|
||||
Route::prefix('/p2')->name('p2.')->group(function () {
|
||||
|
||||
Reference in New Issue
Block a user