Update Pengajuan Presensi WhatsApp
This commit is contained in:
@@ -312,6 +312,25 @@ class PengajuanAbsenController extends Controller
|
||||
], 500);
|
||||
}
|
||||
|
||||
if ($request->hasFile('file_lampiran')) {
|
||||
$namaFileLampiran = uniqid().'-'.$pegawai->nip.'-lampiran.pdf';
|
||||
$filePathLampiran = $request->file('file_lampiran')->storeAs("absen/presensi/$periode", $namaFileLampiran, 'public');
|
||||
|
||||
if (! $filePathLampiran) {
|
||||
Log::error("Gagal menyimpan file lampiran: $namaFileLampiran");
|
||||
|
||||
return response()->json([
|
||||
'code' => 500,
|
||||
'status' => 'failed',
|
||||
'message' => 'Gagal menyimpan file lampiran',
|
||||
], 500);
|
||||
}
|
||||
|
||||
$absen['file_lampiran'] = $namaFileLampiran;
|
||||
} else {
|
||||
unset($absen['file_lampiran']);
|
||||
}
|
||||
|
||||
$pengajuan = PengajuanPresensi::create($absen);
|
||||
|
||||
$this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\VerifikasiAbsen;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\PengajuanPresensi;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\DawaiService;
|
||||
use App\Services\GoogleDriveService;
|
||||
use App\Services\TteService;
|
||||
use App\Services\VerifikasiAbsenLinkService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class VerifikasiAbsenController extends Controller
|
||||
{
|
||||
const BATAS_HARI_VERIFIKASI = 5;
|
||||
|
||||
private DawaiService $dawaiService;
|
||||
|
||||
public function __construct(
|
||||
protected TteService $tteService,
|
||||
protected GoogleDriveService $googleDriveService,
|
||||
protected VerifikasiAbsenLinkService $linkService,
|
||||
) {
|
||||
$this->dawaiService = new DawaiService('http://172.16.40.128/');
|
||||
}
|
||||
|
||||
public function show(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'state' => 'unauthorized',
|
||||
'message' => 'Tautan ini tidak valid, sudah kedaluwarsa, atau Anda bukan atasan dari pegawai pemohon.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
]);
|
||||
}
|
||||
|
||||
public function setujui(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'nik' => 'required|string',
|
||||
'passphrase' => 'required|string',
|
||||
]);
|
||||
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
}
|
||||
|
||||
$dokumenTertandatangani = $this->tteService->signDokumenUser(
|
||||
$request->nik,
|
||||
$request->passphrase,
|
||||
$pengajuan->file,
|
||||
$this->linkService->url($pengajuan->id)
|
||||
);
|
||||
|
||||
if ($dokumenTertandatangani === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menandatangani dokumen. Periksa kembali NIK dan Passphrase Anda.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (! $this->googleDriveService->uploadPdf(
|
||||
$dokumenTertandatangani,
|
||||
$pengajuan->nip,
|
||||
$pengajuan->pegawai?->nama ?? $pengajuan->nip,
|
||||
$pengajuan->tanggal_mulai,
|
||||
$pengajuan->kategori
|
||||
)) {
|
||||
Log::error("Gagal mengunggah dokumen tertandatangani ke Google Drive untuk pengajuan #$id");
|
||||
}
|
||||
|
||||
if (! $this->proses($pengajuan, 'Diterima', null, $nipAtasan)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menyetujui pengajuan absen. Silakan coba lagi.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil disetujui.',
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
]);
|
||||
}
|
||||
|
||||
public function tolak(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'catatan' => 'required|string|max:500',
|
||||
]);
|
||||
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
}
|
||||
|
||||
if (! $this->proses($pengajuan, 'Ditolak', $request->catatan, $nipAtasan)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil ditolak.',
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
]);
|
||||
}
|
||||
|
||||
private function cekBisaDiproses(PengajuanPresensi $pengajuan): ?JsonResponse
|
||||
{
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
||||
'state' => 'already_processed',
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
], 422);
|
||||
}
|
||||
|
||||
if ($this->isExpired($pengajuan)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah kadaluarsa dan tidak dapat diverifikasi lagi.',
|
||||
'state' => 'expired',
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
], 422);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveState(PengajuanPresensi $pengajuan): string
|
||||
{
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return 'already_processed';
|
||||
}
|
||||
|
||||
if ($this->isExpired($pengajuan)) {
|
||||
return 'expired';
|
||||
}
|
||||
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
private function formatPengajuan(PengajuanPresensi $pengajuan): array
|
||||
{
|
||||
return [
|
||||
'id' => $pengajuan->id,
|
||||
'nip' => $pengajuan->nip,
|
||||
'nama' => $pengajuan->pegawai?->nama,
|
||||
'tanggal' => $pengajuan->tanggal_mulai,
|
||||
'kategori' => $pengajuan->kategori,
|
||||
'keterangan' => $pengajuan->keterangan,
|
||||
'file' => $pengajuan->file,
|
||||
'status' => $pengajuan->status,
|
||||
'alasan' => $pengajuan->notes?->last()?->message,
|
||||
'created_at' => $pengajuan->created_at,
|
||||
'batas_hari_verifikasi' => self::BATAS_HARI_VERIFIKASI,
|
||||
];
|
||||
}
|
||||
|
||||
private function isExpired(PengajuanPresensi $pengajuan): bool
|
||||
{
|
||||
return $pengajuan->created_at?->copy()->addDays(self::BATAS_HARI_VERIFIKASI)->isPast() ?? false;
|
||||
}
|
||||
|
||||
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|false
|
||||
{
|
||||
$nip = $request->input('nip');
|
||||
$expires = $request->input('expires');
|
||||
$signature = $request->input('signature');
|
||||
|
||||
if (! $this->linkService->verify($pengajuan->id, $nip, $expires, $signature)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->dawaiService->isAtasanDari($nip, $pengajuan->nip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $nip;
|
||||
}
|
||||
|
||||
private function proses(PengajuanPresensi $pengajuan, string $status, ?string $catatan, string $nipAtasan): bool
|
||||
{
|
||||
$atasan = Pegawai::withoutGlobalScopes()->where('nip', $nipAtasan)->first();
|
||||
$verifikatorRole = 'Atasan (via WhatsApp)';
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$pengajuan->update(['status' => $status]);
|
||||
|
||||
$pengajuan->logs()->create([
|
||||
'user_id' => null,
|
||||
'method' => 'POST',
|
||||
'employee_id' => $nipAtasan,
|
||||
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||
'employee_role' => $verifikatorRole,
|
||||
'message' => 'Pengajuan Presensi Berhasil '.strtolower($status).' via WhatsApp',
|
||||
]);
|
||||
|
||||
if ($status === 'Ditolak') {
|
||||
$pengajuan->notes()->create([
|
||||
'type' => 'Catatan',
|
||||
'user_id' => null,
|
||||
'employee_id' => $nipAtasan,
|
||||
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||
'employee_role' => $verifikatorRole,
|
||||
'message' => $catatan,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
$pengajuan->refresh()->load('notes');
|
||||
|
||||
try {
|
||||
$webhookResponse = Http::timeout(5)
|
||||
->withHeaders(['X-API-Key' => config('services.verifikator_webhook.key')])
|
||||
->post(config('services.verifikator_webhook.url'), [
|
||||
'jenis' => 'izin',
|
||||
'nip' => $pengajuan->nip,
|
||||
'tanggal' => $pengajuan->tanggal_mulai,
|
||||
'kategori' => $this->mapKategoriSlug($pengajuan->getRawOriginal('kategori')),
|
||||
'status' => $status === 'Diterima' ? 'approved' : 'rejected',
|
||||
'alasan' => $catatan ?? '',
|
||||
]);
|
||||
|
||||
if ($webhookResponse->successful()) {
|
||||
Log::info("Webhook Verifikator via WhatsApp berhasil: {$pengajuan->nip} ($status)");
|
||||
} else {
|
||||
Log::warning("Webhook Verifikator via WhatsApp gagal: {$pengajuan->nip} ($status) - HTTP {$webhookResponse->status()}");
|
||||
}
|
||||
} catch (Throwable $webhookException) {
|
||||
Log::error("Webhook Verifikator via WhatsApp error: {$pengajuan->nip} ($status) - ".$webhookException->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
Log::error("Verifikasi Absen via WhatsApp ($status): ".$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function mapKategoriSlug(mixed $kategoriId): ?string
|
||||
{
|
||||
return match ((int) $kategoriId) {
|
||||
2 => 'dinas',
|
||||
3 => 'terlambat',
|
||||
20 => 'lupa_absen',
|
||||
21 => 'cepat_pulang',
|
||||
24 => 'lupa_absen_masuk',
|
||||
25 => 'lupa_absen_pulang',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Lainnya\VerifikasiAbsen;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Verifikator\PengajuanPresensi;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use App\Services\DawaiService;
|
||||
use App\Services\GoogleDriveService;
|
||||
use App\Services\TteService;
|
||||
use App\Services\VerifikasiAbsenLinkService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
use Throwable;
|
||||
|
||||
class VerifikasiAbsenController extends Controller
|
||||
{
|
||||
const BATAS_HARI_VERIFIKASI = 5;
|
||||
|
||||
private DawaiService $dawaiService;
|
||||
|
||||
public function __construct(
|
||||
protected TteService $tteService,
|
||||
protected GoogleDriveService $googleDriveService,
|
||||
protected VerifikasiAbsenLinkService $linkService,
|
||||
) {
|
||||
$this->dawaiService = new DawaiService('http://172.16.40.128/');
|
||||
}
|
||||
|
||||
public function show(Request $request, int $id): View|RedirectResponse|Response
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return $this->tidakBerwenang();
|
||||
}
|
||||
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
||||
}
|
||||
|
||||
if ($this->isExpired($pengajuan)) {
|
||||
return redirect()->route('verifikasi-absen.kadaluarsa', $id);
|
||||
}
|
||||
|
||||
$title = 'Verifikasi Pengajuan Absen';
|
||||
$nip = $nipAtasan;
|
||||
$expires = $request->input('expires');
|
||||
$signature = $request->input('signature');
|
||||
|
||||
return view('lainnya.verifikasi-absen.show', compact('title', 'pengajuan', 'nip', 'expires', 'signature'));
|
||||
}
|
||||
|
||||
public function setujui(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'nik' => 'required|string',
|
||||
'passphrase' => 'required|string',
|
||||
]);
|
||||
|
||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if ($this->isExpired($pengajuan)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah kadaluarsa dan tidak dapat diverifikasi lagi.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$dokumenTertandatangani = $this->tteService->signDokumenUser(
|
||||
$request->nik,
|
||||
$request->passphrase,
|
||||
$pengajuan->file,
|
||||
route('verifikasi-absen.show', $id)
|
||||
);
|
||||
|
||||
if ($dokumenTertandatangani === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menandatangani dokumen. Periksa kembali NIK dan Passphrase Anda.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$fileName = "pengajuan-presensi-{$pengajuan->nip}-{$pengajuan->id}.pdf";
|
||||
|
||||
if (! $this->googleDriveService->uploadPdf($dokumenTertandatangani, $fileName)) {
|
||||
Log::error("Gagal mengunggah dokumen tertandatangani ke Google Drive untuk pengajuan #$id");
|
||||
}
|
||||
|
||||
$success = $this->proses([$id], 'Diterima', null, $nipAtasan);
|
||||
|
||||
if ($success) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil disetujui.',
|
||||
'redirect' => route('verifikasi-absen.berhasil-disetujui', $id),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menyetujui pengajuan absen. Silakan coba lagi.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
public function berhasilDisetujui(int $id): View|RedirectResponse
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
||||
|
||||
if ($pengajuan->status === 'Diajukan') {
|
||||
return redirect()->route('verifikasi-absen.show', $id);
|
||||
}
|
||||
|
||||
if ($pengajuan->status !== 'Diterima') {
|
||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
||||
}
|
||||
|
||||
$title = 'Berhasil Menyetujui Pengajuan Absen';
|
||||
|
||||
return view('lainnya.verifikasi-absen.berhasil-disetujui', compact('title', 'pengajuan'));
|
||||
}
|
||||
|
||||
public function tolak(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'catatan' => 'required|string|max:500',
|
||||
]);
|
||||
|
||||
$pengajuan = PengajuanPresensi::findOrFail($id);
|
||||
|
||||
$nipAtasan = $this->otorisasiAtasan($request, $pengajuan);
|
||||
|
||||
if ($nipAtasan === false) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Anda tidak berwenang memverifikasi pengajuan ini.',
|
||||
], 403);
|
||||
}
|
||||
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if ($this->isExpired($pengajuan)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah kadaluarsa dan tidak dapat diverifikasi lagi.',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$success = $this->proses([$id], 'Ditolak', $request->catatan, $nipAtasan);
|
||||
|
||||
if ($success) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil ditolak.',
|
||||
'redirect' => route('verifikasi-absen.berhasil-ditolak', $id),
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
||||
], 500);
|
||||
}
|
||||
|
||||
public function berhasilDitolak(int $id): View|RedirectResponse
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with(['pegawai', 'notes'])->findOrFail($id);
|
||||
|
||||
if ($pengajuan->status === 'Diajukan') {
|
||||
return redirect()->route('verifikasi-absen.show', $id);
|
||||
}
|
||||
|
||||
if ($pengajuan->status !== 'Ditolak') {
|
||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
||||
}
|
||||
|
||||
$title = 'Berhasil Menolak Pengajuan Absen';
|
||||
|
||||
return view('lainnya.verifikasi-absen.berhasil-ditolak', compact('title', 'pengajuan'));
|
||||
}
|
||||
|
||||
public function sudahDiproses(int $id): View|RedirectResponse
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
||||
|
||||
if ($pengajuan->status === 'Diajukan') {
|
||||
return redirect()->route(
|
||||
$this->isExpired($pengajuan) ? 'verifikasi-absen.kadaluarsa' : 'verifikasi-absen.show',
|
||||
$id
|
||||
);
|
||||
}
|
||||
|
||||
$title = 'Pengajuan Sudah Diproses';
|
||||
|
||||
return view('lainnya.verifikasi-absen.sudah-diproses', compact('title', 'pengajuan'));
|
||||
}
|
||||
|
||||
public function kadaluarsa(int $id): View|RedirectResponse
|
||||
{
|
||||
$pengajuan = PengajuanPresensi::with('pegawai')->findOrFail($id);
|
||||
|
||||
if ($pengajuan->status !== 'Diajukan') {
|
||||
return redirect()->route('verifikasi-absen.sudah-diproses', $id);
|
||||
}
|
||||
|
||||
if (! $this->isExpired($pengajuan)) {
|
||||
return redirect()->route('verifikasi-absen.show', $id);
|
||||
}
|
||||
|
||||
$title = 'Pengajuan Kadaluarsa';
|
||||
|
||||
return view('lainnya.verifikasi-absen.kadaluarsa', compact('title', 'pengajuan'));
|
||||
}
|
||||
|
||||
private function isExpired(PengajuanPresensi $pengajuan): bool
|
||||
{
|
||||
return $pengajuan->created_at?->copy()->addDays(self::BATAS_HARI_VERIFIKASI)->isPast() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validasi bahwa request membawa nip+expires+signature yang valid (dari tautan WhatsApp)
|
||||
* DAN nip tersebut benar-benar atasan dari pegawai pemilik pengajuan.
|
||||
* Return NIP atasan yang tervalidasi, atau false kalau tidak berwenang.
|
||||
*/
|
||||
private function otorisasiAtasan(Request $request, PengajuanPresensi $pengajuan): string|false
|
||||
{
|
||||
$nip = $request->input('nip');
|
||||
$expires = $request->input('expires');
|
||||
$signature = $request->input('signature');
|
||||
|
||||
if (! $this->linkService->verify($pengajuan->id, $nip, $expires, $signature)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->dawaiService->isAtasanDari($nip, $pengajuan->nip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $nip;
|
||||
}
|
||||
|
||||
private function tidakBerwenang(): Response
|
||||
{
|
||||
$title = 'Tidak Berwenang';
|
||||
|
||||
return response()->view('lainnya.verifikasi-absen.tidak-berwenang', compact('title'), 403);
|
||||
}
|
||||
|
||||
private function proses(array $ids, string $status, ?string $catatan, ?string $nipAtasan = null): bool
|
||||
{
|
||||
// Diproses tanpa sesi login (diakses langsung dari tautan WhatsApp),
|
||||
// sehingga identitas verifikator diambil dari NIP atasan yang tervalidasi (bukan Auth::user()).
|
||||
$atasan = $nipAtasan ? Pegawai::withoutGlobalScopes()->where('nip', $nipAtasan)->first() : null;
|
||||
$verifikatorRole = 'Atasan (via WhatsApp)';
|
||||
|
||||
try {
|
||||
$pengajuans = PengajuanPresensi::whereIn('id', $ids)->get();
|
||||
|
||||
foreach ($pengajuans as $pengajuan) {
|
||||
DB::beginTransaction();
|
||||
|
||||
$pengajuan->update(['status' => $status]);
|
||||
|
||||
$pengajuan->logs()->create([
|
||||
'user_id' => null,
|
||||
'method' => 'POST',
|
||||
'employee_id' => $nipAtasan ?? $pengajuan->nip,
|
||||
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||
'employee_role' => $verifikatorRole,
|
||||
'message' => 'Pengajuan Presensi Berhasil ' . strtolower($status) . ' via WhatsApp',
|
||||
]);
|
||||
|
||||
if ($status === 'Ditolak') {
|
||||
$pengajuan->notes()->create([
|
||||
'type' => 'Catatan',
|
||||
'user_id' => null,
|
||||
'employee_id' => $nipAtasan ?? $pengajuan->nip,
|
||||
'employee_name' => $atasan?->nama ?? $pengajuan->pegawai?->nama,
|
||||
'employee_role' => $verifikatorRole,
|
||||
'message' => $catatan,
|
||||
]);
|
||||
}
|
||||
|
||||
// $dawai = $this->dawaiService->verifikasiUsulanPresensi(
|
||||
// $pengajuan->nip,
|
||||
// [$pengajuan->tanggal_mulai],
|
||||
// $this->mapStatus($status),
|
||||
// $pengajuan->getRawOriginal('kategori'),
|
||||
// 'whatsapp',
|
||||
// $verifikatorRole
|
||||
// );
|
||||
|
||||
// if (! $dawai) {
|
||||
// Log::error("Presensi DAWAI via WhatsApp: $pengajuan->nip ($status)");
|
||||
// throw new Exception('Presensi: DAWAI ERROR');
|
||||
// }
|
||||
|
||||
DB::commit();
|
||||
|
||||
// try {
|
||||
// Http::timeout(5)->asMultipart()->post('http://172.16.50.94:8084/webhook/presensi', [
|
||||
// ['name' => 'jenis', 'contents' => 'izin],
|
||||
// ['name' => 'nip', 'contents' => $pengajuan->nip],
|
||||
// ['name' => 'tanggal[]', 'contents' => $pengajuan->tanggal_mulai],
|
||||
// ['name' => 'kategori', 'contents' => (string) $pengajuan->getRawOriginal('kategori')],
|
||||
// ['name' => 'username', 'contents' => 'whatsapp'],
|
||||
// ['name' => 'name', 'contents' => $verifikatorRole],
|
||||
// ]);
|
||||
// } catch (Throwable $webhookException) {
|
||||
// Log::error("Webhook Presensi via WhatsApp error: {$pengajuan->nip} ($status) - " . $webhookException->getMessage());
|
||||
// }
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
Log::error("Verifikasi Absen via WhatsApp ($status): " . $th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function mapStatus(string $status): ?bool
|
||||
{
|
||||
return match ($status) {
|
||||
'Diterima' => true,
|
||||
'Ditolak' => false,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user