Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e5432c983 | |||
| 3dc0f870c9 | |||
| eaeb276774 | |||
| 77ae40b53f |
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\AbsenRequest;
|
||||
use App\Http\Resources\Presensi\AbsenCollection;
|
||||
use App\Http\Resources\Presensi\AbsenResource;
|
||||
use App\Models\Verifikator\Dosen;
|
||||
use App\Models\Verifikator\Honorer;
|
||||
use App\Models\Verifikator\PengajuanPresensi;
|
||||
use App\Models\Verifikator\Tendik;
|
||||
@@ -600,6 +601,27 @@ class PengajuanAbsenController extends Controller
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Kegagalan di sini tidak menggagalkan pengajuan (dicatat ke log saja).
|
||||
@@ -615,14 +637,19 @@ class PengajuanAbsenController extends Controller
|
||||
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']);
|
||||
|
||||
$tanggalMulai = Carbon::parse($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(
|
||||
$nomorTujuan,
|
||||
$atasan['nama_lengkap'] ?? $atasan['nama'],
|
||||
|
||||
@@ -32,7 +32,11 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
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);
|
||||
|
||||
@@ -54,7 +58,11 @@ class VerifikasiAbsenController extends Controller
|
||||
*/
|
||||
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)) {
|
||||
return response()->json([
|
||||
@@ -87,7 +95,11 @@ class VerifikasiAbsenController extends Controller
|
||||
'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);
|
||||
|
||||
@@ -146,7 +158,11 @@ class VerifikasiAbsenController extends Controller
|
||||
'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);
|
||||
|
||||
@@ -221,6 +237,7 @@ class VerifikasiAbsenController extends Controller
|
||||
'kategori' => $pengajuan->kategori,
|
||||
'keterangan' => $pengajuan->keterangan,
|
||||
'file' => $pengajuan->file,
|
||||
'file_nama' => $pengajuan->bdr_id === null ? $pengajuan->getRawOriginal('file') : null,
|
||||
'status' => $pengajuan->status,
|
||||
'alasan' => $pengajuan->notes?->last()?->message,
|
||||
'created_at' => $pengajuan->created_at,
|
||||
@@ -253,6 +270,15 @@ class VerifikasiAbsenController extends Controller
|
||||
return $hasil['nip'];
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return match ($reason) {
|
||||
|
||||
@@ -2,10 +2,54 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Verifikator\PengajuanPresensi;
|
||||
use App\Services\VerifikasiAbsenLinkService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class VerifikasiAbsenHalamanController extends Controller
|
||||
{
|
||||
public function show(int $id)
|
||||
public function __construct(
|
||||
protected VerifikasiAbsenLinkService $linkService,
|
||||
) {}
|
||||
|
||||
public function show(Request $request, int $id)
|
||||
{
|
||||
if ($request->filled('img')) {
|
||||
return $this->tampilkanFile($request, $id, (string) $request->query('img'));
|
||||
}
|
||||
|
||||
return view('verifikasi-absen.halaman', ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tampilkan file bukti pengajuan lewat ?token=...&img=<nama file>.
|
||||
* Hanya file milik pengajuan ini yang bisa dibuka, dan token harus masih dalam sesi yang valid.
|
||||
*/
|
||||
private function tampilkanFile(Request $request, int $id, string $img)
|
||||
{
|
||||
$hasil = $this->linkService->verify($id, $request->query('token'));
|
||||
|
||||
abort_unless($hasil['ok'], 403, 'Tautan tidak valid atau sesi sudah berakhir.');
|
||||
|
||||
$pengajuan = PengajuanPresensi::find($id);
|
||||
|
||||
abort_unless($pengajuan, 404, 'Pengajuan tidak ditemukan.');
|
||||
|
||||
$namaFile = basename($img);
|
||||
$fileSah = array_filter([
|
||||
$pengajuan->getRawOriginal('file'),
|
||||
$pengajuan->getRawOriginal('file_lampiran'),
|
||||
]);
|
||||
|
||||
abort_unless($pengajuan->bdr_id === null && in_array($namaFile, $fileSah, true), 404);
|
||||
|
||||
$path = "{$pengajuan->tipe}/presensi/{$pengajuan->periode}/{$namaFile}";
|
||||
|
||||
abort_unless(Storage::disk('public')->exists($path), 404, 'File tidak ditemukan.');
|
||||
|
||||
return response()->file(Storage::disk('public')->path($path), [
|
||||
'Content-Disposition' => 'inline; filename="'.$namaFile.'"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,10 +154,6 @@
|
||||
<dt>Kategori</dt>
|
||||
<dd id="dataKategori">-</dd>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<dt>Keterangan</dt>
|
||||
<dd id="dataKeterangan">-</dd>
|
||||
</div>
|
||||
<div class="col-12" id="dataAlasanWrap" style="display:none">
|
||||
<dt>Catatan</dt>
|
||||
<dd id="dataAlasan">-</dd>
|
||||
@@ -263,8 +259,11 @@
|
||||
$('#dataNip').text(data.nip || '-');
|
||||
$('#dataTanggal').text(data.tanggal || '-');
|
||||
$('#dataKategori').text(data.kategori || '-');
|
||||
$('#dataKeterangan').text(data.keterangan || '-');
|
||||
$('#dataFile').attr('href', data.file || '#');
|
||||
// File bukti dibuka lewat halaman ini sendiri (?token=...&img=nama-file) supaya tidak bergantung pada /storage.
|
||||
const linkFile = data.file_nama
|
||||
? `${window.location.pathname}?token=${encodeURIComponent(token)}&img=${encodeURIComponent(data.file_nama)}`
|
||||
: (data.file || '#');
|
||||
$('#dataFile').attr('href', linkFile);
|
||||
|
||||
const badge = statusBadgeMap[data.status] || ['bg-secondary', data.status];
|
||||
$('#statusBadge').attr('class', `badge status-badge ${badge[0]}`).text(badge[1]);
|
||||
|
||||
Reference in New Issue
Block a user