client = new Client([ 'base_uri' => $default, 'timeout' => 0, ]); } public function getJabatan(string $nip, int $periode): array|bool { try { $response = $this->client->get("api/v1/jabatan/$nip/$periode"); } catch (Throwable $th) { try { Log::error('DAWAI : '.$th->getMessage()); Log::error("DAWAI : $nip ($periode)"); } catch (Throwable) { // Log failure should not crash the process } return false; } $data = json_decode($response->getBody()->getContents(), true); return $data; } public function getListBawahan(string $nip): array|bool { try { $response = $this->client->get("api/v1/listBawahanAtasanv2/$nip"); } catch (Throwable $th) { Log::error('DAWAI Bawahan: '.$th->getMessage()); Log::error("DAWAI Bawahan: $nip"); return []; } $data = json_decode($response->getBody()->getContents(), true); return $data; } public function isVerifikatorTriDharma(string $nip) { try { if (count($this->getListBawahan($nip)['data']['bawahan']) === 0) { return false; } return true; } catch (Throwable $th) { return false; } } public function isVerifikatorTendik(string $nip): bool { try { $bawahan = $this->getListBawahan($nip)['data']['bawahan']; foreach ($bawahan as $bawah) { if ($bawah['jenis_pegawai'] === 'tendik') { return true; } } return false; } catch (Throwable $th) { return false; } } public function listPegawai(string $nip = '', string $jenisPegawai = '', string $email = ''): array { try { $response = $this->client->get("api/v1/pegawai?jenis_pegawai=$jenisPegawai&nip=$nip&email=$email&asn=true&pensiun=0&wafat=0&mutkel=0&nonaktif=0"); $data = json_decode($response->getBody()->getContents(), true); return $data; } catch (Throwable $th) { Log::error('SIDIA: '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function updateBawahan(string $atasan, array $bawahan): array { $listBawahan = []; foreach ($bawahan as $nip) { $listBawahan[] = [ 'name' => 'site_nip_bawahan[]', 'contents' => $nip, ]; } try { Log::info('Update Bawahan Request', [ 'atasan' => $atasan, 'jumlah_bawahan' => count($bawahan), 'bawahan' => $bawahan, ]); $response = $this->client->post('api/v1/updateBawahan', [ 'multipart' => [ [ 'name' => 'site_nip_atasan', 'contents' => $atasan, ], ...$listBawahan, ], ]); $data = json_decode($response->getBody()->getContents(), true); Log::info('Update Bawahan Response', ['response' => $data]); if ($data['status']) { return ['success' => true, 'message' => $data['message'] ?? 'Berhasil mengubah daftar bawahan']; } return ['success' => false, 'message' => $data['message'] ?? 'Gagal mengubah daftar bawahan']; } catch (Throwable $th) { Log::error('Update Bawahan Error: '.$th->getMessage()); return ['success' => false, 'message' => $th->getMessage()]; } } public function verifikasiUsulanPresensi(string $nip, array $tanggals, ?bool $status, null|string|int $kategori, ?string $username = null, ?string $name = null): bool { $tanggal = []; try { foreach ($tanggals as $t) { $tanggal[] = [ 'name' => 'tanggal[]', 'contents' => $t, ]; } $options = [ 'multipart' => [ [ 'name' => 'nip', 'contents' => $nip, ], ...$tanggal, [ 'name' => 'status_usulan', 'contents' => $status, ], [ 'name' => 'kategori', 'contents' => $kategori, ], [ 'name' => 'username', 'contents' => Auth::user()?->username ?? $username, ], [ 'name' => 'name', 'contents' => Auth::user()?->name ?? $name, ], ], ]; $response = $this->client->post('api/v1/verifikasiUsulanPresensi', $options); $data = json_decode($response->getBody()->getContents(), true); if ($data['status']) { return true; } throw new Error($data['message']); } catch (Throwable $th) { Log::error('Presensi DAWAI : '.$th->getMessage()); return false; } return false; } public function listJabatanFungsional(?int $id) { try { $response = $this->client->get("api/v1/list-jafung?id=$id"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function listJabatanTambahan(?int $id) { try { $response = $this->client->get("api/v1/list-dtt?id=$id"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function listStatusPresensi(?string $kategori = null) { try { $response = $this->client->get("api/v1/listStatusPresensi?kategori=$kategori"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDetailPresensi(string $nip, int $tahun, int $bulan, ?int $tanggal) { try { $response = $this->client->get("api/v1/getDetailPresensi/$tahun/$bulan/$nip?hari=$tanggal"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function cutiExists(string $nip, string $tanggal): bool { try { $response = $this->client->post('api/v1/cekPengajuanCuti', [ 'form_params' => [ 'nip' => $nip, 'tanggal' => $tanggal, ], ]); $data = json_decode($response->getBody()->getContents(), true); return $data['status']; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); return true; } } public function listRekening() { try { $response = $this->client->get('api/v1/rekening'); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getRekapP1(int $tahun, int $bulan, int $unit): array { try { $response = $this->client->get("api/v1/psatu/$tahun/$bulan/?id_unit=$unit"); return json_decode($response->getBody()->getContents(), true) ?? []; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDataP1(?string $jenisPegawai, int $tahun, int $bulan, ?int $unit) { try { $response = $this->client->get("api/v1/psatu/$tahun/$bulan/?id_unit=$unit&jenis_pegawai=$jenisPegawai"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDataP1Selisih(?string $jenisPegawai, int $tahun, int $bulan, ?int $unit) { try { $response = $this->client->get("api/v1/psatu/$tahun/$bulan/?id_unit=$unit&jenis_pegawai=$jenisPegawai&selisih=true"); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getRekapThr(int $tahun, int $unit): array { try { $response = $this->client->get("api/v1/thrApi/$tahun/?id_unit=$unit"); return json_decode($response->getBody()->getContents(), true) ?? []; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDataThr(?string $jenisPegawai, int $tahun, ?int $unit, bool $selisih = false) { try { $url = "api/v1/thrApi/$tahun/?id_unit=$unit&jenis_pegawai=$jenisPegawai"; if ($selisih) { $url .= '&selisih=true'; } $response = $this->client->get($url); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getRekapR13(int $tahun, int $unit): array { try { $response = $this->client->get("api/v1/r13Api/$tahun/6?id_unit=$unit"); return json_decode($response->getBody()->getContents(), true) ?? []; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } public function getDataR13(?string $jenisPegawai, int $tahun, ?int $unit, bool $selisih = false) { try { $url = "api/v1/r13Api/$tahun/6?id_unit=$unit&jenis_pegawai=$jenisPegawai"; if ($selisih) { $url .= '&selisih=true'; } $response = $this->client->get($url); $data = json_decode($response->getBody()->getContents(), true)['data']; return $data; } catch (Throwable $th) { Log::error('DAWAI : '.$th->getMessage()); throw new Error($th->getMessage(), 500); } } }