Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fc2f51108 | |||
| 797c9371ce | |||
| 8e5432c983 | |||
| 3dc0f870c9 |
@@ -6,9 +6,11 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Http\Requests\Api\AbsenRequest;
|
use App\Http\Requests\Api\AbsenRequest;
|
||||||
use App\Http\Resources\Presensi\AbsenCollection;
|
use App\Http\Resources\Presensi\AbsenCollection;
|
||||||
use App\Http\Resources\Presensi\AbsenResource;
|
use App\Http\Resources\Presensi\AbsenResource;
|
||||||
|
use App\Models\Verifikator\Dosen;
|
||||||
use App\Models\Verifikator\Honorer;
|
use App\Models\Verifikator\Honorer;
|
||||||
use App\Models\Verifikator\PengajuanPresensi;
|
use App\Models\Verifikator\PengajuanPresensi;
|
||||||
use App\Models\Verifikator\Tendik;
|
use App\Models\Verifikator\Tendik;
|
||||||
|
use App\Models\Verifikator\View\Pegawai;
|
||||||
use App\Services\DawaiService;
|
use App\Services\DawaiService;
|
||||||
use App\Services\VerifikasiAbsenLinkService;
|
use App\Services\VerifikasiAbsenLinkService;
|
||||||
use App\Services\WhatsAppService;
|
use App\Services\WhatsAppService;
|
||||||
@@ -352,6 +354,8 @@ class PengajuanAbsenController extends Controller
|
|||||||
|
|
||||||
$pengajuan = PengajuanPresensi::create($absen);
|
$pengajuan = PengajuanPresensi::create($absen);
|
||||||
|
|
||||||
|
$this->catatLog($pengajuan, 'Pengajuan Presensi diajukan', $pegawai->nip, 'Pemohon', 'POST', $pegawai->nama);
|
||||||
|
|
||||||
$this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
$this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
||||||
|
|
||||||
// Ambil nama kategori dari Dawai Service
|
// Ambil nama kategori dari Dawai Service
|
||||||
@@ -380,7 +384,7 @@ class PengajuanAbsenController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function batalkan(string $id)
|
public function batalkan(Request $request, string $id)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$pengajuan = PengajuanPresensi::where('tipe', 'absen')
|
$pengajuan = PengajuanPresensi::where('tipe', 'absen')
|
||||||
@@ -405,6 +409,14 @@ class PengajuanAbsenController extends Controller
|
|||||||
$pengajuan->status = 'Diajukan';
|
$pengajuan->status = 'Diajukan';
|
||||||
$pengajuan->save();
|
$pengajuan->save();
|
||||||
|
|
||||||
|
$this->catatLog(
|
||||||
|
$pengajuan,
|
||||||
|
"Pengajuan Presensi dibatalkan ke status Diajukan (sebelumnya: $statusLama)",
|
||||||
|
$request->input('nip'),
|
||||||
|
$this->rolePelaku($request->input('nip'), $pengajuan),
|
||||||
|
'PATCH'
|
||||||
|
);
|
||||||
|
|
||||||
Log::info("Batalkan Pengajuan Presensi: ID $id - NIP $pengajuan->nip - Status lama: $statusLama");
|
Log::info("Batalkan Pengajuan Presensi: ID $id - NIP $pengajuan->nip - Status lama: $statusLama");
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -415,7 +427,7 @@ class PengajuanAbsenController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(string $id)
|
public function destroy(Request $request, string $id)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$pengajuan = PengajuanPresensi::withTrashed()
|
$pengajuan = PengajuanPresensi::withTrashed()
|
||||||
@@ -447,6 +459,14 @@ class PengajuanAbsenController extends Controller
|
|||||||
|
|
||||||
$pengajuan->delete();
|
$pengajuan->delete();
|
||||||
|
|
||||||
|
$this->catatLog(
|
||||||
|
$pengajuan,
|
||||||
|
'Pengajuan Presensi dihapus',
|
||||||
|
$request->input('nip'),
|
||||||
|
$this->rolePelaku($request->input('nip'), $pengajuan),
|
||||||
|
'DELETE'
|
||||||
|
);
|
||||||
|
|
||||||
Log::info("Hapus Pengajuan Presensi: ID $id - NIP $pengajuan->nip");
|
Log::info("Hapus Pengajuan Presensi: ID $id - NIP $pengajuan->nip");
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -600,6 +620,59 @@ class PengajuanAbsenController extends Controller
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function rolePelaku(?string $nipPelaku, PengajuanPresensi $pengajuan): string
|
||||||
|
{
|
||||||
|
if (! $nipPelaku) {
|
||||||
|
return 'Tidak diketahui';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nipPelaku === $pengajuan->nip ? 'Pemohon' : 'Atasan';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catat riwayat pengajuan (siapa & NIP-nya). Gagal mencatat tidak menggagalkan proses utama.
|
||||||
|
*/
|
||||||
|
private function catatLog(PengajuanPresensi $pengajuan, string $pesan, ?string $nipPelaku, string $role, string $method, ?string $namaPelaku = null): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$namaPelaku ??= $nipPelaku
|
||||||
|
? Pegawai::withoutGlobalScopes()->where('nip', $nipPelaku)->value('nama')
|
||||||
|
: null;
|
||||||
|
|
||||||
|
$pengajuan->logs()->create([
|
||||||
|
'user_id' => null,
|
||||||
|
'method' => $method,
|
||||||
|
'employee_id' => $nipPelaku,
|
||||||
|
'employee_name' => $namaPelaku,
|
||||||
|
'employee_role' => $role,
|
||||||
|
'message' => $pesan,
|
||||||
|
]);
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error("Catat log pengajuan #$pengajuan->id gagal: ".$th->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nomor HP pimpinan (diisi oleh command pegawai:update-no-hp-pimpinan) dalam format 62xxxxxxxxxx.
|
||||||
|
*/
|
||||||
|
private function nomorWhatsAppPimpinan(string $nip): ?string
|
||||||
|
{
|
||||||
|
$noHp = Dosen::where('nip', $nip)->value('no_hp') ?: Tendik::where('nip', $nip)->value('no_hp');
|
||||||
|
|
||||||
|
$digit = preg_replace('/\D+/', '', (string) $noHp);
|
||||||
|
|
||||||
|
if ($digit === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match (true) {
|
||||||
|
str_starts_with($digit, '62') => $digit,
|
||||||
|
str_starts_with($digit, '0') => '62'.substr($digit, 1),
|
||||||
|
str_starts_with($digit, '8') => '62'.$digit,
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kirim notifikasi WhatsApp ke atasan berisi link verifikasi (terima/tolak) pengajuan absen.
|
* Kirim notifikasi WhatsApp ke atasan berisi link verifikasi (terima/tolak) pengajuan absen.
|
||||||
* Kegagalan di sini tidak menggagalkan pengajuan (dicatat ke log saja).
|
* Kegagalan di sini tidak menggagalkan pengajuan (dicatat ke log saja).
|
||||||
@@ -615,14 +688,19 @@ class PengajuanAbsenController extends Controller
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$nomorTujuan = $this->nomorWhatsAppPimpinan($atasan['nip']);
|
||||||
|
|
||||||
|
if (! $nomorTujuan) {
|
||||||
|
Log::error("Notifikasi WhatsApp Pengajuan Absen: nomor HP atasan (NIP {$atasan['nip']}) belum tersedia untuk pengajuan #$pengajuan->id");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$link = (new VerifikasiAbsenLinkService())->generate($pengajuan->id, $atasan['nip']);
|
$link = (new VerifikasiAbsenLinkService())->generate($pengajuan->id, $atasan['nip']);
|
||||||
|
|
||||||
$tanggalMulai = Carbon::parse($pengajuan->tanggal_mulai);
|
$tanggalMulai = Carbon::parse($pengajuan->tanggal_mulai);
|
||||||
$tanggalSelesai = Carbon::parse($pengajuan->tanggal_selesai ?? $pengajuan->tanggal_mulai);
|
$tanggalSelesai = Carbon::parse($pengajuan->tanggal_selesai ?? $pengajuan->tanggal_mulai);
|
||||||
|
|
||||||
// TODO: nomor WA atasan masih manual/sementara, belum ada sumber data resminya.
|
|
||||||
$nomorTujuan = '6289698424476';
|
|
||||||
|
|
||||||
(new WhatsAppService())->sendPengajuanAbsenNotification(
|
(new WhatsAppService())->sendPengajuanAbsenNotification(
|
||||||
$nomorTujuan,
|
$nomorTujuan,
|
||||||
$atasan['nama_lengkap'] ?? $atasan['nama'],
|
$atasan['nama_lengkap'] ?? $atasan['nama'],
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class VerifikasiAbsenController extends Controller
|
class VerifikasiAbsenController extends Controller
|
||||||
@@ -32,7 +33,11 @@ class VerifikasiAbsenController extends Controller
|
|||||||
|
|
||||||
public function show(Request $request, int $id): JsonResponse
|
public function show(Request $request, int $id): JsonResponse
|
||||||
{
|
{
|
||||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->find($id);
|
||||||
|
|
||||||
|
if (! $pengajuan) {
|
||||||
|
return $this->responsePengajuanTidakDitemukan();
|
||||||
|
}
|
||||||
|
|
||||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
@@ -54,7 +59,11 @@ class VerifikasiAbsenController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function perbaruiSesi(Request $request, int $id): JsonResponse
|
public function perbaruiSesi(Request $request, int $id): JsonResponse
|
||||||
{
|
{
|
||||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
$pengajuan = PengajuanPresensi::find($id);
|
||||||
|
|
||||||
|
if (! $pengajuan) {
|
||||||
|
return $this->responsePengajuanTidakDitemukan();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->isExpired($pengajuan)) {
|
if ($this->isExpired($pengajuan)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -87,7 +96,11 @@ class VerifikasiAbsenController extends Controller
|
|||||||
'passphrase' => 'required|string',
|
'passphrase' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->find($id);
|
||||||
|
|
||||||
|
if (! $pengajuan) {
|
||||||
|
return $this->responsePengajuanTidakDitemukan();
|
||||||
|
}
|
||||||
|
|
||||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
@@ -101,14 +114,21 @@ class VerifikasiAbsenController extends Controller
|
|||||||
return $gagal;
|
return $gagal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// File lokal dibaca langsung dari disk (bukan lewat URL /storage) supaya tidak bergantung pada symlink & HTTP ke diri sendiri.
|
||||||
|
$sumberFile = $pengajuan->bdr_id === null
|
||||||
|
? Storage::disk('public')->path("{$pengajuan->tipe}/presensi/{$pengajuan->periode}/{$pengajuan->getRawOriginal('file')}")
|
||||||
|
: $pengajuan->file;
|
||||||
|
|
||||||
$dokumenTertandatangani = $this->tteService->signDokumenUser(
|
$dokumenTertandatangani = $this->tteService->signDokumenUser(
|
||||||
$request->nik,
|
$request->nik,
|
||||||
$request->passphrase,
|
$request->passphrase,
|
||||||
$pengajuan->file,
|
$sumberFile,
|
||||||
$this->linkService->url($pengajuan->id)
|
$this->linkService->url($pengajuan->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($dokumenTertandatangani === false) {
|
if ($dokumenTertandatangani === false) {
|
||||||
|
$this->catatLogGagalTtd($pengajuan, $nipAtasan);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
'message' => 'Gagal menandatangani dokumen. Periksa kembali NIK dan Passphrase Anda.',
|
'message' => 'Gagal menandatangani dokumen. Periksa kembali NIK dan Passphrase Anda.',
|
||||||
@@ -146,7 +166,11 @@ class VerifikasiAbsenController extends Controller
|
|||||||
'catatan' => 'required|string|max:500',
|
'catatan' => 'required|string|max:500',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->find($id);
|
||||||
|
|
||||||
|
if (! $pengajuan) {
|
||||||
|
return $this->responsePengajuanTidakDitemukan();
|
||||||
|
}
|
||||||
|
|
||||||
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
$otorisasi = $this->otorisasiAtasan($request, $pengajuan);
|
||||||
|
|
||||||
@@ -254,6 +278,36 @@ class VerifikasiAbsenController extends Controller
|
|||||||
return $hasil['nip'];
|
return $hasil['nip'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Catat percobaan tanda tangan yang gagal (NIK/passphrase salah). NIK dan passphrase sengaja tidak disimpan.
|
||||||
|
*/
|
||||||
|
private function catatLogGagalTtd(PengajuanPresensi $pengajuan, string $nipAtasan): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$atasan = Pegawai::withoutGlobalScopes()->where('nip', $nipAtasan)->first();
|
||||||
|
|
||||||
|
$pengajuan->logs()->create([
|
||||||
|
'user_id' => null,
|
||||||
|
'method' => 'POST',
|
||||||
|
'employee_id' => $nipAtasan,
|
||||||
|
'employee_name' => $atasan?->nama,
|
||||||
|
'employee_role' => 'Atasan (via WhatsApp)',
|
||||||
|
'message' => 'Gagal menandatangani dokumen saat menyetujui via WhatsApp (NIK atau passphrase tidak sesuai)',
|
||||||
|
]);
|
||||||
|
} catch (Throwable $th) {
|
||||||
|
Log::error("Catat log gagal TTD pengajuan #$pengajuan->id: ".$th->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function responsePengajuanTidakDitemukan(): JsonResponse
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'state' => 'not_found',
|
||||||
|
'message' => 'Pengajuan ini sudah dihapus oleh pemohon atau tidak ditemukan lagi, sehingga tidak dapat diverifikasi.',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
private function responseTidakBerwenang(string $reason): JsonResponse
|
private function responseTidakBerwenang(string $reason): JsonResponse
|
||||||
{
|
{
|
||||||
return match ($reason) {
|
return match ($reason) {
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ class VerifikasiAbsenHalamanController extends Controller
|
|||||||
|
|
||||||
abort_unless($hasil['ok'], 403, 'Tautan tidak valid atau sesi sudah berakhir.');
|
abort_unless($hasil['ok'], 403, 'Tautan tidak valid atau sesi sudah berakhir.');
|
||||||
|
|
||||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
$pengajuan = PengajuanPresensi::find($id);
|
||||||
|
|
||||||
|
abort_unless($pengajuan, 404, 'Pengajuan tidak ditemukan.');
|
||||||
|
|
||||||
$namaFile = basename($img);
|
$namaFile = basename($img);
|
||||||
$fileSah = array_filter([
|
$fileSah = array_filter([
|
||||||
@@ -46,7 +48,7 @@ class VerifikasiAbsenHalamanController extends Controller
|
|||||||
|
|
||||||
abort_unless(Storage::disk('public')->exists($path), 404, 'File tidak ditemukan.');
|
abort_unless(Storage::disk('public')->exists($path), 404, 'File tidak ditemukan.');
|
||||||
|
|
||||||
return Storage::disk('public')->response($path, $namaFile, [
|
return response()->file(Storage::disk('public')->path($path), [
|
||||||
'Content-Disposition' => 'inline; filename="'.$namaFile.'"',
|
'Content-Disposition' => 'inline; filename="'.$namaFile.'"',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,10 +154,6 @@
|
|||||||
<dt>Kategori</dt>
|
<dt>Kategori</dt>
|
||||||
<dd id="dataKategori">-</dd>
|
<dd id="dataKategori">-</dd>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
|
||||||
<dt>Keterangan</dt>
|
|
||||||
<dd id="dataKeterangan">-</dd>
|
|
||||||
</div>
|
|
||||||
<div class="col-12" id="dataAlasanWrap" style="display:none">
|
<div class="col-12" id="dataAlasanWrap" style="display:none">
|
||||||
<dt>Catatan</dt>
|
<dt>Catatan</dt>
|
||||||
<dd id="dataAlasan">-</dd>
|
<dd id="dataAlasan">-</dd>
|
||||||
@@ -263,7 +259,6 @@
|
|||||||
$('#dataNip').text(data.nip || '-');
|
$('#dataNip').text(data.nip || '-');
|
||||||
$('#dataTanggal').text(data.tanggal || '-');
|
$('#dataTanggal').text(data.tanggal || '-');
|
||||||
$('#dataKategori').text(data.kategori || '-');
|
$('#dataKategori').text(data.kategori || '-');
|
||||||
$('#dataKeterangan').text(data.keterangan || '-');
|
|
||||||
// File bukti dibuka lewat halaman ini sendiri (?token=...&img=nama-file) supaya tidak bergantung pada /storage.
|
// File bukti dibuka lewat halaman ini sendiri (?token=...&img=nama-file) supaya tidak bergantung pada /storage.
|
||||||
const linkFile = data.file_nama
|
const linkFile = data.file_nama
|
||||||
? `${window.location.pathname}?token=${encodeURIComponent(token)}&img=${encodeURIComponent(data.file_nama)}`
|
? `${window.location.pathname}?token=${encodeURIComponent(token)}&img=${encodeURIComponent(data.file_nama)}`
|
||||||
@@ -282,6 +277,7 @@
|
|||||||
$('#aksiButtons').removeClass('d-none');
|
$('#aksiButtons').removeClass('d-none');
|
||||||
} else {
|
} else {
|
||||||
$('#aksiButtons').addClass('d-none');
|
$('#aksiButtons').addClass('d-none');
|
||||||
|
$('.aksi-form').hide().find('input, textarea').val('');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === 'pending' && typeof sisaDetik === 'number') {
|
if (state === 'pending' && typeof sisaDetik === 'number') {
|
||||||
|
|||||||
Reference in New Issue
Block a user