Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c465b69603 | |||
| a003c62fd3 |
@@ -37,6 +37,11 @@ class PengajuanAbsenController extends Controller
|
||||
|
||||
private array $notifikasiTertunda = [];
|
||||
|
||||
// Pengajuan batch (banyak tanggal) memakai satu file & satu notifikasi WhatsApp ke atasan.
|
||||
private ?string $uniqBatch = null;
|
||||
|
||||
private bool $waAtasanTerkirim = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// $this->p = Periode::where('status', true)->first()->id_periode;
|
||||
@@ -149,6 +154,8 @@ class PengajuanAbsenController extends Controller
|
||||
$hasil = null;
|
||||
$this->fileTersimpan = [];
|
||||
$this->notifikasiTertunda = [];
|
||||
$this->uniqBatch = $batch ? uniqid() : null;
|
||||
$this->waAtasanTerkirim = false;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
@@ -468,7 +475,7 @@ class PengajuanAbsenController extends Controller
|
||||
$absen['periode'] = $periode;
|
||||
$absen['tanggal_mulai'] = $absen['tanggal'];
|
||||
$absen['status'] = 'Diajukan';
|
||||
$namaFile = uniqid().'-'.$pegawai->nip.'.pdf';
|
||||
$namaFile = ($this->uniqBatch ?? uniqid()).'-'.$pegawai->nip.'.pdf';
|
||||
$absen['file'] = $namaFile;
|
||||
|
||||
// Simpan file ke storage/app/public/absen/presensi/{periode}
|
||||
@@ -489,7 +496,7 @@ class PengajuanAbsenController extends Controller
|
||||
}
|
||||
|
||||
if ($request->kategori == 2 && $request->hasFile('file_lampiran')) {
|
||||
$namaFileLampiran = uniqid().'-'.$pegawai->nip.'-lampiran.pdf';
|
||||
$namaFileLampiran = ($this->uniqBatch ?? uniqid()).'-'.$pegawai->nip.'-lampiran.pdf';
|
||||
$filePathLampiran = $request->file('file_lampiran')->storeAs("absen/presensi/$periode", $namaFileLampiran, 'public');
|
||||
if ($filePathLampiran) {
|
||||
$this->fileTersimpan[] = $filePathLampiran;
|
||||
@@ -521,7 +528,10 @@ class PengajuanAbsenController extends Controller
|
||||
return $gagal;
|
||||
}
|
||||
} else {
|
||||
$this->notifikasiTertunda[] = fn () => $this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
||||
if (! $this->waAtasanTerkirim) {
|
||||
$this->waAtasanTerkirim = true;
|
||||
$this->notifikasiTertunda[] = fn () => $this->notifikasiAtasanWhatsApp($pengajuan, $pegawai, $dawaiService);
|
||||
}
|
||||
$this->notifikasiTertunda[] = fn () => (new VerifikatorWebhookService)->kirimIzin($pengajuan, VerifikatorWebhookService::STATUS_PENDING);
|
||||
}
|
||||
|
||||
@@ -895,17 +905,25 @@ class PengajuanAbsenController extends Controller
|
||||
|
||||
$link = (new VerifikasiAbsenLinkService())->generate($pengajuan->id, $atasan['nip']);
|
||||
|
||||
$tanggalMulai = Carbon::parse($pengajuan->tanggal_mulai);
|
||||
$tanggalSelesai = Carbon::parse($pengajuan->tanggal_selesai ?? $pengajuan->tanggal_mulai);
|
||||
// Pengajuan batch berbagi file yang sama; satu notifikasi mencakup semua tanggalnya.
|
||||
$daftarTanggal = PengajuanPresensi::where('nip', $pengajuan->nip)
|
||||
->where('tipe', 'absen')
|
||||
->where('kategori', $pengajuan->getRawOriginal('kategori'))
|
||||
->where('file', $pengajuan->getRawOriginal('file'))
|
||||
->orderBy('tanggal_mulai')
|
||||
->pluck('tanggal_mulai')
|
||||
->map(fn ($tanggal) => Carbon::parse($tanggal)->format('d-m-Y'))
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
(new WhatsAppService())->sendPengajuanAbsenNotification(
|
||||
$nomorTujuan,
|
||||
$atasan['nama_lengkap'] ?? $atasan['nama'],
|
||||
$pegawai->nama,
|
||||
$pengajuan->nip,
|
||||
max($tanggalMulai->diffInDays($tanggalSelesai), 1),
|
||||
$tanggalMulai->format('d-m-Y'),
|
||||
$tanggalSelesai->format('d-m-Y'),
|
||||
max(count($daftarTanggal), 1),
|
||||
$daftarTanggal,
|
||||
$pengajuan->keterangan ?: '-',
|
||||
$link['button_param']
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@ use App\Services\VerifikatorWebhookService;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -47,11 +48,13 @@ class VerifikasiAbsenController extends Controller
|
||||
return $this->responseTidakBerwenang($otorisasi['reason']);
|
||||
}
|
||||
|
||||
$grup = $this->grupPengajuan($pengajuan);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'state' => $this->resolveStateGrup($grup),
|
||||
'sisa_detik' => $this->linkService->sisaSesiDetik($pengajuan->id, $request->input('token')),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan, $grup),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -108,8 +111,11 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
$nipAtasan = $otorisasi;
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
$grup = $this->grupPengajuan($pengajuan);
|
||||
$menunggu = $this->yangBisaDiproses($grup);
|
||||
|
||||
if ($menunggu->isEmpty()) {
|
||||
return $this->cekBisaDiproses($pengajuan) ?? $this->responseSudahDiproses($pengajuan, $grup);
|
||||
}
|
||||
|
||||
// File lokal dibaca langsung dari disk (bukan lewat URL /storage) supaya tidak bergantung pada symlink & HTTP ke diri sendiri.
|
||||
@@ -145,26 +151,40 @@ class VerifikasiAbsenController extends Controller
|
||||
Log::error("Gagal mengunggah dokumen tertandatangani ke Google Drive untuk pengajuan #$id");
|
||||
}
|
||||
|
||||
if (! $this->proses(
|
||||
$pengajuan,
|
||||
'Diterima',
|
||||
null,
|
||||
$nipAtasan,
|
||||
(string) $request->input('token'),
|
||||
$linkDrive ?: null,
|
||||
fn () => $this->kirimKeDawai($pengajuan, 'Diterima', null, $nipAtasan, $linkDrive ?: null)
|
||||
)) {
|
||||
$gagal = 0;
|
||||
|
||||
foreach ($menunggu as $item) {
|
||||
if (! $this->proses(
|
||||
$item,
|
||||
'Diterima',
|
||||
null,
|
||||
$nipAtasan,
|
||||
(string) $request->input('token'),
|
||||
$linkDrive ?: null,
|
||||
fn () => $this->kirimKeDawai($item, 'Diterima', null, $nipAtasan, $linkDrive ?: null)
|
||||
)) {
|
||||
$gagal++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($gagal > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menyetujui pengajuan absen. Silakan coba lagi.',
|
||||
'message' => $gagal === $menunggu->count()
|
||||
? 'Gagal menyetujui pengajuan absen. Silakan coba lagi.'
|
||||
: "$gagal dari {$menunggu->count()} pengajuan gagal disetujui. Muat ulang halaman lalu coba lagi.",
|
||||
], 500);
|
||||
}
|
||||
|
||||
$grup = $this->grupPengajuan($pengajuan);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil disetujui.',
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
'message' => $menunggu->count() > 1
|
||||
? "{$menunggu->count()} pengajuan absen berhasil disetujui."
|
||||
: 'Pengajuan absen berhasil disetujui.',
|
||||
'state' => $this->resolveStateGrup($grup),
|
||||
'data' => $this->formatPengajuan($pengajuan, $grup),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -188,30 +208,47 @@ class VerifikasiAbsenController extends Controller
|
||||
|
||||
$nipAtasan = $otorisasi;
|
||||
|
||||
if ($gagal = $this->cekBisaDiproses($pengajuan)) {
|
||||
return $gagal;
|
||||
$grup = $this->grupPengajuan($pengajuan);
|
||||
$menunggu = $this->yangBisaDiproses($grup);
|
||||
|
||||
if ($menunggu->isEmpty()) {
|
||||
return $this->cekBisaDiproses($pengajuan) ?? $this->responseSudahDiproses($pengajuan, $grup);
|
||||
}
|
||||
|
||||
if (! $this->proses(
|
||||
$pengajuan,
|
||||
'Ditolak',
|
||||
$request->catatan,
|
||||
$nipAtasan,
|
||||
(string) $request->input('token'),
|
||||
null,
|
||||
fn () => $this->kirimKeDawai($pengajuan, 'Ditolak', $request->catatan, $nipAtasan)
|
||||
)) {
|
||||
$gagal = 0;
|
||||
|
||||
foreach ($menunggu as $item) {
|
||||
if (! $this->proses(
|
||||
$item,
|
||||
'Ditolak',
|
||||
$request->catatan,
|
||||
$nipAtasan,
|
||||
(string) $request->input('token'),
|
||||
null,
|
||||
fn () => $this->kirimKeDawai($item, 'Ditolak', $request->catatan, $nipAtasan)
|
||||
)) {
|
||||
$gagal++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($gagal > 0) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Gagal menolak pengajuan absen. Silakan coba lagi.',
|
||||
'message' => $gagal === $menunggu->count()
|
||||
? 'Gagal menolak pengajuan absen. Silakan coba lagi.'
|
||||
: "$gagal dari {$menunggu->count()} pengajuan gagal ditolak. Muat ulang halaman lalu coba lagi.",
|
||||
], 500);
|
||||
}
|
||||
|
||||
$grup = $this->grupPengajuan($pengajuan);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Pengajuan absen berhasil ditolak.',
|
||||
'state' => $this->resolveState($pengajuan),
|
||||
'data' => $this->formatPengajuan($pengajuan),
|
||||
'message' => $menunggu->count() > 1
|
||||
? "{$menunggu->count()} pengajuan absen berhasil ditolak."
|
||||
: 'Pengajuan absen berhasil ditolak.',
|
||||
'state' => $this->resolveStateGrup($grup),
|
||||
'data' => $this->formatPengajuan($pengajuan, $grup),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -251,13 +288,64 @@ class VerifikasiAbsenController extends Controller
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
private function formatPengajuan(PengajuanPresensi $pengajuan): array
|
||||
/**
|
||||
* Pengajuan batch (banyak tanggal dalam satu request) berbagi nip, kategori, dan file yang sama,
|
||||
* sehingga diverifikasi sekaligus lewat satu tautan. Pengajuan tunggal menghasilkan grup berisi dirinya sendiri.
|
||||
*/
|
||||
private function grupPengajuan(PengajuanPresensi $pengajuan): Collection
|
||||
{
|
||||
return PengajuanPresensi::with(['pegawai', 'notes'])
|
||||
->where('nip', $pengajuan->nip)
|
||||
->where('tipe', $pengajuan->tipe)
|
||||
->where('kategori', $pengajuan->getRawOriginal('kategori'))
|
||||
->where('file', $pengajuan->getRawOriginal('file'))
|
||||
->orderBy('tanggal_mulai')
|
||||
->get();
|
||||
}
|
||||
|
||||
private function yangBisaDiproses(Collection $grup): Collection
|
||||
{
|
||||
return $grup->filter(fn (PengajuanPresensi $item) => $item->status === 'Diajukan' && ! $this->isExpired($item))->values();
|
||||
}
|
||||
|
||||
private function resolveStateGrup(Collection $grup): string
|
||||
{
|
||||
if ($this->yangBisaDiproses($grup)->isNotEmpty()) {
|
||||
return 'pending';
|
||||
}
|
||||
|
||||
if ($grup->contains(fn (PengajuanPresensi $item) => $item->status === 'Diajukan')) {
|
||||
return 'expired';
|
||||
}
|
||||
|
||||
return 'already_processed';
|
||||
}
|
||||
|
||||
private function responseSudahDiproses(PengajuanPresensi $pengajuan, Collection $grup): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Pengajuan ini sudah diproses sebelumnya.',
|
||||
'state' => 'already_processed',
|
||||
'data' => $this->formatPengajuan($pengajuan, $grup),
|
||||
], 422);
|
||||
}
|
||||
|
||||
private function formatPengajuan(PengajuanPresensi $pengajuan, ?Collection $grup = null): array
|
||||
{
|
||||
$grup ??= collect([$pengajuan]);
|
||||
$items = $grup->map(fn (PengajuanPresensi $item) => [
|
||||
'id' => $item->id,
|
||||
'tanggal' => $item->tanggal_mulai,
|
||||
'status' => $item->status,
|
||||
])->values();
|
||||
|
||||
return [
|
||||
'id' => $pengajuan->id,
|
||||
'nip' => $pengajuan->nip,
|
||||
'nama' => $pengajuan->pegawai?->nama,
|
||||
'tanggal' => $pengajuan->tanggal_mulai,
|
||||
'items' => $items,
|
||||
'kategori' => $pengajuan->kategori,
|
||||
'keterangan' => $pengajuan->keterangan,
|
||||
'file' => $pengajuan->file,
|
||||
|
||||
@@ -12,14 +12,28 @@ class WhatsAppService
|
||||
|
||||
private string $token = 'apicoid_live_7J0vmW5Sbk2dBBAEIEDtdc4tG4fOswy3Seblz_nKZqk';
|
||||
|
||||
/**
|
||||
* ["19-02-2026"] => "19-02-2026"; 2 tanggal => "a dan b"; 3+ => "a, b, dan c".
|
||||
*/
|
||||
private function formatDaftarTanggal(array $daftarTanggal): string
|
||||
{
|
||||
$daftarTanggal = array_values($daftarTanggal);
|
||||
$terakhir = array_pop($daftarTanggal);
|
||||
|
||||
if ($daftarTanggal === []) {
|
||||
return (string) $terakhir;
|
||||
}
|
||||
|
||||
return implode(', ', $daftarTanggal).(count($daftarTanggal) > 1 ? ',' : '')." dan $terakhir";
|
||||
}
|
||||
|
||||
public function sendPengajuanAbsenNotification(
|
||||
string $nomorTujuan,
|
||||
string $namaAtasan,
|
||||
string $namaPemohon,
|
||||
string $nipPemohon,
|
||||
int $jumlahHari,
|
||||
string $tanggalMulai,
|
||||
string $tanggalSelesai,
|
||||
array $daftarTanggal,
|
||||
string $keterangan,
|
||||
string $link
|
||||
): bool {
|
||||
@@ -40,7 +54,7 @@ class WhatsAppService
|
||||
['type' => 'text', 'text' => $namaPemohon],
|
||||
['type' => 'text', 'text' => $nipPemohon],
|
||||
['type' => 'text', 'text' => (string) $jumlahHari],
|
||||
['type' => 'text', 'text' => $tanggalMulai === $tanggalSelesai ? $tanggalMulai : "$tanggalMulai dan $tanggalSelesai"],
|
||||
['type' => 'text', 'text' => $this->formatDaftarTanggal($daftarTanggal)],
|
||||
['type' => 'text', 'text' => $keterangan],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -298,7 +298,12 @@
|
||||
|
||||
$('#dataNama').text(data.nama || '-');
|
||||
$('#dataNip').text(data.nip || '-');
|
||||
$('#dataTanggal').text(data.tanggal || '-');
|
||||
// Pengajuan banyak tanggal diverifikasi sekaligus: tampilkan semua tanggalnya.
|
||||
$('#dataTanggal').text(
|
||||
Array.isArray(data.items) && data.items.length > 1
|
||||
? data.items.map(i => i.tanggal).join(', ')
|
||||
: (data.tanggal || '-')
|
||||
);
|
||||
$('#dataKategori').text(data.kategori || '-');
|
||||
// File bukti dibuka lewat halaman ini sendiri (?token=...&img=nama-file) supaya tidak bergantung pada /storage.
|
||||
const linkFile = data.file_nama
|
||||
|
||||
Reference in New Issue
Block a user