Penambahan fitur verifikasi pengajuan penghapusan tugas dinas
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Verifikator\PengajuanPresensi;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Throwable;
|
||||
|
||||
class SenjaService
|
||||
@@ -16,6 +20,21 @@ class SenjaService
|
||||
|
||||
public const JAM_PULANG_DEFAULT = '16:30';
|
||||
|
||||
public function kosongkanTugasDinas(PengajuanPresensi $pengajuan): void
|
||||
{
|
||||
$response = Http::timeout(20)
|
||||
->post(self::URL.'/api/tugas-dinas/kosongkan-presensi', [
|
||||
'pengajuan_id' => $pengajuan->id,
|
||||
'nip' => $pengajuan->nip,
|
||||
'tanggal_mulai' => $pengajuan->tanggal_mulai,
|
||||
'tanggal_selesai' => $pengajuan->tanggal_selesai ?: $pengajuan->tanggal_mulai,
|
||||
]);
|
||||
|
||||
if (! $response->successful() || $response->json('status') !== 'success') {
|
||||
throw ValidationException::withMessages(['absensi' => 'Gagal mengosongkan presensi di absensi_v2. Pengajuan belum selesai; periksa integrasi absensi.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function simpanIndex(string $nip, string $tanggalMulai, string $tanggalSelesai, string $jenisAbsen, string $jam, ?string $keterangan = null): bool
|
||||
{
|
||||
try {
|
||||
@@ -52,4 +71,71 @@ class SenjaService
|
||||
|
||||
return $masuk && $pulang;
|
||||
}
|
||||
|
||||
public function ajukanPenghapusanTugasDinas(PengajuanPresensi $pengajuan, ?string $pemohon): PengajuanPresensi
|
||||
{
|
||||
return DB::transaction(function () use ($pengajuan, $pemohon) {
|
||||
$row = PengajuanPresensi::whereKey($pengajuan->id)->lockForUpdate()->firstOrFail();
|
||||
if ((int) $row->getRawOriginal('kategori') !== 2) {
|
||||
throw ValidationException::withMessages(['pengajuan' => 'Pengajuan bukan Tugas / Dinas.']);
|
||||
}
|
||||
if (! in_array($row->status, ['Diajukan', 'Diterima'], true)) {
|
||||
throw ValidationException::withMessages(['pengajuan' => 'Status pengajuan tidak dapat dimintakan penghapusan.']);
|
||||
}
|
||||
if ($row->penghapusan_status !== 'Diajukan') {
|
||||
$row->forceFill([
|
||||
'penghapusan_status' => 'Diajukan', 'penghapusan_pemohon' => $pemohon,
|
||||
'penghapusan_diajukan_at' => now(), 'penghapusan_verifikator' => null,
|
||||
'penghapusan_diverifikasi_at' => null, 'penghapusan_catatan' => null,
|
||||
])->save();
|
||||
}
|
||||
|
||||
return $row;
|
||||
});
|
||||
}
|
||||
|
||||
public function verifikasiPenghapusanTugasDinas(PengajuanPresensi $pengajuan, string $status, string $verifikator, ?string $catatan): void
|
||||
{
|
||||
$deleted = DB::transaction(function () use ($pengajuan, $status, $verifikator, $catatan) {
|
||||
$row = PengajuanPresensi::whereKey($pengajuan->id)->lockForUpdate()->firstOrFail();
|
||||
if ((int) $row->getRawOriginal('kategori') !== 2 || $row->penghapusan_status !== 'Diajukan') {
|
||||
throw ValidationException::withMessages(['pengajuan' => 'Tidak ada permintaan penghapusan yang menunggu verifikasi.']);
|
||||
}
|
||||
if (! in_array($status, ['Diterima', 'Ditolak'], true)) {
|
||||
throw ValidationException::withMessages(['status' => 'Status verifikasi tidak valid.']);
|
||||
}
|
||||
if ($status === 'Ditolak' && ! trim((string) $catatan)) {
|
||||
throw ValidationException::withMessages(['catatan' => 'Alasan penolakan wajib diisi.']);
|
||||
}
|
||||
if ($status === 'Diterima' && $row->dawai_id) {
|
||||
$result = app(DawaiService::class)->deletePengajuanCutiDinas($row->dawai_id);
|
||||
if (! $result['berhasil']) {
|
||||
throw ValidationException::withMessages(['dawai' => 'Gagal menghapus di DAWAI: '.$result['message']]);
|
||||
}
|
||||
} elseif ($status === 'Diterima' && $row->status === 'Diterima') {
|
||||
throw ValidationException::withMessages(['dawai_id' => 'ID DAWAI belum tersedia. Lengkapi ID sebelum menyetujui penghapusan.']);
|
||||
}
|
||||
$row->forceFill([
|
||||
'penghapusan_status' => $status, 'penghapusan_verifikator' => $verifikator,
|
||||
'penghapusan_diverifikasi_at' => now(), 'penghapusan_catatan' => $catatan,
|
||||
])->save();
|
||||
Log::info('Verifikasi penghapusan Tugas / Dinas', ['id' => $row->id, 'status' => $status, 'verifikator' => $verifikator]);
|
||||
if ($status === 'Diterima') {
|
||||
$row->delete();
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
if ($deleted) {
|
||||
$mulai = Carbon::parse($deleted->tanggal_mulai)->toDateString();
|
||||
$selesai = Carbon::parse($deleted->tanggal_selesai ?: $mulai)->toDateString();
|
||||
if (! $this->resetJamKerja($deleted->nip, $mulai, $selesai, 'Batal Pengajuan Tugas / Dinas')) {
|
||||
Log::warning('Reset SENJA setelah hapus Tugas / Dinas gagal', ['id' => $deleted->id]);
|
||||
}
|
||||
(new VerifikatorWebhookService)->kirimIzin($deleted, VerifikatorWebhookService::STATUS_DELETED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user