first commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class AktivitasService
|
||||
{
|
||||
private $client;
|
||||
|
||||
public function __construct(string $default = 'http://172.16.40.177:8023/')
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => $default,
|
||||
'timeout' => 30,
|
||||
'connect_timeout' => 10,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPengajuanSk()
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get('api/pengajuan-sk');
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Aktivitas Pelayanan Service : '.$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function verifikasiPengajuan($id, $status, $catatan = null)
|
||||
{
|
||||
try {
|
||||
// Jika status dibatalkan dari frontend, kirim sebagai diajukan ke API
|
||||
$apiStatus = $status === 'dibatalkan' ? 'diajukan' : $status;
|
||||
|
||||
$payload = [
|
||||
'status' => $apiStatus,
|
||||
];
|
||||
|
||||
if ($catatan) {
|
||||
$payload['keterangan'] = $catatan;
|
||||
}
|
||||
|
||||
$response = $this->client->post("api/pengajuan-sk/{$id}/verifikasi", [
|
||||
'json' => $payload,
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$body = $response->getBody()->getContents();
|
||||
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Aktivitas Pelayanan Service Verifikasi : '.$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode($body, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
Log::error('JSON decode error: '.json_last_error_msg());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Error;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class DawaiService
|
||||
{
|
||||
private $client;
|
||||
|
||||
public function __construct($default = 'http://172.16.40.128/')
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Error;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class DokSiremunService
|
||||
{
|
||||
private $client;
|
||||
|
||||
protected $urlDevelopment = 'http://172.16.50.23';
|
||||
|
||||
protected $urlProduction = 'https://dokumen.siremun.untan.ac.id/';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (env('APP_ENV') === 'DEVELOPMENT') {
|
||||
$default = $this->urlDevelopment;
|
||||
} else {
|
||||
$default = $this->urlProduction;
|
||||
}
|
||||
|
||||
$this->client = new Client([
|
||||
'base_uri' => $default,
|
||||
'timeout' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
public function verifikasiSk(int|string $id_sk): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/verifikasisk', [
|
||||
'form_params' => [
|
||||
'id_sk' => $id_sk,
|
||||
'nip' => Auth::user()?->nip ?? 'Otomatis data semester lalu',
|
||||
'name' => Auth::user()?->name ?? 'Otomatis data semester lalu',
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen ($id_sk): ".$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function hapusSk(int $id_sk): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/hapussk', [
|
||||
'form_params' => [
|
||||
'id_sk' => $id_sk,
|
||||
'nip' => Auth::user()?->nip ?? 'Otomatis hapus sementara data semester lalu',
|
||||
'name' => Auth::user()?->name ?? 'Otomatis hapus sementara data semester lalu',
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen ($id_sk): ".$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function hapusAnggotaSk(int $id_sk, int $id_anggota_sk): bool|int|null
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/hapusanggotask', [
|
||||
'form_params' => [
|
||||
'id_sk' => $id_sk,
|
||||
'id_anggota_sk' => $id_anggota_sk,
|
||||
'nip' => Auth::user()->nip,
|
||||
'name' => Auth::user()->name,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen ($id_sk, $id_anggota_sk): ".$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPoin(int $rubrik_id, float $satuan = 0, float $jangka_waktu = 0)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/syarat/hitung-rubrik', [
|
||||
'form_params' => [
|
||||
'id_rubrik' => $rubrik_id,
|
||||
'jumlah_satuan' => $satuan,
|
||||
'jangka_waktu_per_semester' => $jangka_waktu,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data;
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Dokumen: '.$th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function triggerPresensi(string $nip)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/triggerpresensi', [
|
||||
'form_params' => [
|
||||
'employee_id' => $nip,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['status'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Dokumen: '.$th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function jumlahKelasMengajar($periode = 386)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('GET', 'api/v1/verifikator/jumlahkelasmengajar/'.$periode);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Dokumen: '.$th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function jumlahKelasMengajarMbkm($periode = 386)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('GET', 'api/v1/verifikator/jumlahkelasmengajarmbkm/'.$periode);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Dokumen: '.$th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifikasiSkSemesterLalu(int|string $id_sk): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/verifikasisksemesterlalu', [
|
||||
'form_params' => [
|
||||
'id_sk' => $id_sk,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data['data'];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen Verifikasi SK Semester Lalu ($id_sk): ".$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function syncMengajar(string $nip, int $idPeriode): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('GET', "api/v1/siremuntendiks/pendidikan/mengajar/nip/{$nip}/periode/{$idPeriode}", [
|
||||
'query' => ['sync' => 'true'],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return $data ?? [];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen Sync Mengajar ($nip, $idPeriode): ".$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePresensiMengajar(string $nip, int $id_kelas, int $jumlah_kehadiran, int $total_kehadiran, string $pengubah, int $jumlah_mahasiswa)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->request('POST', 'api/v1/verifikator/updatePresensiMengajar', [
|
||||
'form_params' => [
|
||||
'nip' => $nip,
|
||||
'id_kelas' => $id_kelas,
|
||||
'jumlah_kehadiran' => (int) $jumlah_kehadiran,
|
||||
'total_kehadiran' => (int) $total_kehadiran,
|
||||
'pengubah' => $pengubah,
|
||||
'jumlah_mahasiswa' => (int) $jumlah_mahasiswa,
|
||||
],
|
||||
]);
|
||||
// dd($response);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return [
|
||||
'status' => $data['status'],
|
||||
'message' => $data['message'],
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error("Dokumen Update Presensi Mengajar ($id_kelas, $nip): ".$th->getMessage());
|
||||
|
||||
return [
|
||||
'status' => false,
|
||||
'message' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class ImamAVService
|
||||
{
|
||||
private Client $client;
|
||||
|
||||
private string $baseUrl = 'http://172.16.40.201:8080';
|
||||
|
||||
private array $credentials = ['username' => 'arbi', 'password' => 'UntanMulia-2020'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => $this->baseUrl,
|
||||
'timeout' => 30,
|
||||
]);
|
||||
}
|
||||
|
||||
private function login(): ?string
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post($this->baseUrl.'/login', [
|
||||
'json' => $this->credentials,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
Log::error('ImamAV login failed. Status: '.$response->getStatusCode());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$token = $data['access_token'] ?? null;
|
||||
$expiredAt = $data['expired_at'] ?? null;
|
||||
|
||||
if (! $token) {
|
||||
Log::error('ImamAV login: access_token not found in response');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$ttl = $expiredAt
|
||||
? now()->diffInSeconds(Carbon::parse($expiredAt)) - 60
|
||||
: 3300;
|
||||
|
||||
Cache::put('imamav_token', $token, max($ttl, 60));
|
||||
|
||||
return $token;
|
||||
} catch (Throwable $th) {
|
||||
Log::error('ImamAV login error: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function getBearerToken(): ?string
|
||||
{
|
||||
return Cache::get('imamav_token') ?? $this->login();
|
||||
}
|
||||
|
||||
public function generateIdKelas(): string
|
||||
{
|
||||
$year = now()->year;
|
||||
$prefix = "KLS-{$year}-";
|
||||
|
||||
$result = $this->getListMataKuliah();
|
||||
|
||||
$lastNumber = collect($result['data'])
|
||||
->pluck('ID Kelas')
|
||||
->filter(fn ($id) => str_starts_with((string) $id, $prefix))
|
||||
->map(fn ($id) => (int) substr($id, strlen($prefix)))
|
||||
->max() ?? 0;
|
||||
|
||||
return $prefix.str_pad($lastNumber + 1, 3, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function getListMataKuliah(): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
return ['success' => false, 'error' => 'Failed to authenticate with API', 'data' => []];
|
||||
}
|
||||
|
||||
$response = $this->client->get('mata-kuliah-manual', [
|
||||
'headers' => ['Authorization' => 'Bearer '.$token],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$responseData = json_decode($response->getBody()->getContents(), true);
|
||||
$mataKuliah = $responseData['data'] ?? $responseData['results'] ?? $responseData;
|
||||
|
||||
return ['success' => true, 'data' => is_array($mataKuliah) ? $mataKuliah : []];
|
||||
}
|
||||
|
||||
Log::error('Failed to fetch mata kuliah list. Status: '.$response->getStatusCode());
|
||||
|
||||
return ['success' => false, 'error' => 'Failed to fetch data from API', 'data' => []];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima API Error: '.$th->getMessage());
|
||||
|
||||
return ['success' => false, 'error' => $th->getMessage(), 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
public function createMataKuliah(array $data): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
Log::error('Failed to get bearer token for create mata kuliah');
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Failed to authenticate with API',
|
||||
];
|
||||
}
|
||||
|
||||
Log::info('Creating mata kuliah with token: '.substr($token, 0, 20).'...');
|
||||
Log::info('Request data: '.json_encode($data));
|
||||
|
||||
// Use JSON format as API expects dictionary/object
|
||||
$response = $this->client->post('tambah-makul', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'json' => $data,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if ($statusCode === 200 || $statusCode === 201) {
|
||||
$responseData = json_decode($responseBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Mata kuliah berhasil ditambahkan',
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
// If unauthorized, clear cache and retry once
|
||||
if ($statusCode === 401) {
|
||||
Log::warning('Token expired or invalid, retrying with new token...');
|
||||
Cache::forget('imamav_token');
|
||||
|
||||
$newToken = $this->login();
|
||||
|
||||
if ($newToken) {
|
||||
Log::info('Retrying with new token: '.substr($newToken, 0, 20).'...');
|
||||
|
||||
$retryResponse = $this->client->post('tambah-makul', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$newToken,
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'json' => $data,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$retryStatusCode = $retryResponse->getStatusCode();
|
||||
$retryBody = $retryResponse->getBody()->getContents();
|
||||
|
||||
if ($retryStatusCode === 200 || $retryStatusCode === 201) {
|
||||
$responseData = json_decode($retryBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Mata kuliah berhasil ditambahkan',
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
Log::error('Retry failed. Status: '.$retryStatusCode);
|
||||
Log::error('Retry Response: '.$retryBody);
|
||||
|
||||
$errorBody = json_decode($retryBody, true);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $errorBody['detail'] ?? $errorBody['message'] ?? 'Failed to create mata kuliah after retry',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('Failed to create mata kuliah. Status: '.$statusCode);
|
||||
Log::error('Response: '.$responseBody);
|
||||
|
||||
$errorBody = json_decode($responseBody, true);
|
||||
$errorMsg = $errorBody['error'] ?? $errorBody['detail'] ?? $errorBody['message'] ?? 'Failed to create mata kuliah';
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $errorMsg,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima Create Error: '.$th->getMessage());
|
||||
Log::error('Stack trace: '.$th->getTraceAsString());
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function updateMataKuliah(array $data): array
|
||||
{
|
||||
try {
|
||||
$idKelas = $data['id_kelas'];
|
||||
$nip = $data['nip'];
|
||||
|
||||
// API tidak memiliki endpoint update — hapus lalu buat ulang dengan id_kelas yang sama
|
||||
$deleteResult = $this->deleteMataKuliah($idKelas, $nip);
|
||||
|
||||
if (! $deleteResult['success']) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Gagal menghapus data lama: '.$deleteResult['message'],
|
||||
];
|
||||
}
|
||||
|
||||
$createData = $data;
|
||||
$createData['id_kelas'] = $idKelas;
|
||||
|
||||
$createResult = $this->createMataKuliah($createData);
|
||||
|
||||
if (! $createResult['success']) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Data lama sudah dihapus, tetapi gagal membuat data baru: '.$createResult['message'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Mata kuliah berhasil diperbarui',
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima Update Error: '.$th->getMessage());
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteMataKuliah(string $idKelas, string $nip): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
Log::error('Failed to get bearer token for delete mata kuliah');
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Failed to authenticate with API',
|
||||
];
|
||||
}
|
||||
|
||||
Log::info('Deleting mata kuliah with ID Kelas: '.$idKelas.' and NIP: '.$nip);
|
||||
|
||||
$response = $this->client->delete("hapus-makul/{$idKelas}/{$nip}", [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
Log::info('Delete Response Status: '.$statusCode);
|
||||
Log::info('Delete Response Body: '.$responseBody);
|
||||
|
||||
if ($statusCode === 200 || $statusCode === 204) {
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Mata kuliah berhasil dihapus',
|
||||
];
|
||||
}
|
||||
|
||||
// If unauthorized, clear cache and retry once
|
||||
if ($statusCode === 401) {
|
||||
Log::warning('Token expired or invalid, retrying with new token...');
|
||||
Cache::forget('imamav_token');
|
||||
|
||||
$newToken = $this->login();
|
||||
|
||||
if ($newToken) {
|
||||
Log::info('Retrying delete with new token');
|
||||
|
||||
$retryResponse = $this->client->delete("hapus-makul/{$idKelas}/{$nip}", [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$newToken,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$retryStatusCode = $retryResponse->getStatusCode();
|
||||
$retryBody = $retryResponse->getBody()->getContents();
|
||||
|
||||
if ($retryStatusCode === 200 || $retryStatusCode === 204) {
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => 'Mata kuliah berhasil dihapus',
|
||||
];
|
||||
}
|
||||
|
||||
Log::error('Retry delete failed. Status: '.$retryStatusCode);
|
||||
Log::error('Retry Response: '.$retryBody);
|
||||
|
||||
$errorBody = json_decode($retryBody, true);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $errorBody['detail'] ?? $errorBody['message'] ?? 'Failed to delete mata kuliah after retry',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('Failed to delete mata kuliah. Status: '.$statusCode);
|
||||
Log::error('Response: '.$responseBody);
|
||||
|
||||
$errorBody = json_decode($responseBody, true);
|
||||
$errorMsg = $errorBody['error'] ?? $errorBody['detail'] ?? $errorBody['message'] ?? 'Failed to delete mata kuliah';
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $errorMsg,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima Delete Error: '.$th->getMessage());
|
||||
Log::error('Stack trace: '.$th->getTraceAsString());
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function testToken(): array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post($this->baseUrl.'/login', [
|
||||
'json' => $this->credentials,
|
||||
]);
|
||||
|
||||
return [
|
||||
'status' => $response->getStatusCode(),
|
||||
'body' => json_decode($response->getBody()->getContents(), true),
|
||||
'server_ip' => gethostbyname(gethostname()),
|
||||
'request_url' => $this->baseUrl.'/login',
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
return [
|
||||
'error' => $th->getMessage(),
|
||||
'trace' => $th->getTraceAsString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreateRequest(array $data): array
|
||||
{
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
return [
|
||||
'error' => 'Failed to get token',
|
||||
];
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
// Test 1: Direct data
|
||||
try {
|
||||
$response1 = $this->client->post('tambah-makul', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => $data,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$results['test_1_direct'] = [
|
||||
'status' => $response1->getStatusCode(),
|
||||
'body' => json_decode($response1->getBody()->getContents(), true),
|
||||
'request' => $data,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
$results['test_1_direct'] = [
|
||||
'error' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
// Test 2: Wrapped in request_body
|
||||
try {
|
||||
$response2 = $this->client->post('tambah-makul', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => [
|
||||
'request_body' => $data,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$results['test_2_wrapped'] = [
|
||||
'status' => $response2->getStatusCode(),
|
||||
'body' => json_decode($response2->getBody()->getContents(), true),
|
||||
'request' => ['request_body' => $data],
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
$results['test_2_wrapped'] = [
|
||||
'error' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
// Test 3: Form params instead of JSON
|
||||
try {
|
||||
$response3 = $this->client->post('tambah-makul', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
'form_params' => $data,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$results['test_3_form_params'] = [
|
||||
'status' => $response3->getStatusCode(),
|
||||
'body' => json_decode($response3->getBody()->getContents(), true),
|
||||
'request' => $data,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
$results['test_3_form_params'] = [
|
||||
'error' => $th->getMessage(),
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getSkp(): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
Log::error('Failed to get bearer token for SKP');
|
||||
|
||||
return ['success' => false, 'error' => 'Failed to authenticate with API', 'data' => []];
|
||||
}
|
||||
|
||||
$response = $this->client->get('skp/all', [
|
||||
'headers' => ['Authorization' => 'Bearer '.$token],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if ($statusCode === 200) {
|
||||
$data = json_decode($responseBody, true);
|
||||
|
||||
return ['success' => true, 'data' => is_array($data) ? $data : []];
|
||||
}
|
||||
|
||||
if ($statusCode === 401) {
|
||||
Cache::forget('imamav_token');
|
||||
$newToken = $this->login();
|
||||
|
||||
if ($newToken) {
|
||||
$retryResponse = $this->client->get('skp/all', [
|
||||
'headers' => ['Authorization' => 'Bearer '.$newToken],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
if ($retryResponse->getStatusCode() === 200) {
|
||||
$data = json_decode($retryResponse->getBody()->getContents(), true);
|
||||
|
||||
return ['success' => true, 'data' => is_array($data) ? $data : []];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('Failed to fetch SKP. Status: '.$statusCode.' Response: '.$responseBody);
|
||||
|
||||
return ['success' => false, 'error' => 'Failed to fetch SKP from API', 'data' => []];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('ImamAV SKP API Error: '.$th->getMessage());
|
||||
|
||||
return ['success' => false, 'error' => $th->getMessage(), 'data' => []];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSummary(): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
Log::error('Failed to get bearer token for summary');
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => 'Failed to authenticate with API',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$response = $this->client->get('summary', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if ($statusCode === 200) {
|
||||
$responseData = json_decode($responseBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
// If unauthorized, clear cache and retry once
|
||||
if ($statusCode === 401) {
|
||||
Log::warning('Token expired or invalid, retrying with new token...');
|
||||
Cache::forget('imamav_token');
|
||||
|
||||
$newToken = $this->login();
|
||||
|
||||
if ($newToken) {
|
||||
$retryResponse = $this->client->get('summary', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$newToken,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$retryStatusCode = $retryResponse->getStatusCode();
|
||||
$retryBody = $retryResponse->getBody()->getContents();
|
||||
|
||||
if ($retryStatusCode === 200) {
|
||||
$responseData = json_decode($retryBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
Log::error('Retry failed. Status: '.$retryStatusCode);
|
||||
Log::error('Retry Response: '.$retryBody);
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('Failed to fetch summary. Status: '.$statusCode);
|
||||
Log::error('Response: '.$responseBody);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => 'Failed to fetch summary from API',
|
||||
'data' => [],
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima Summary API Error: '.$th->getMessage());
|
||||
Log::error('Stack trace: '.$th->getTraceAsString());
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $th->getMessage(),
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function getUktSummary(int $idfakultasunit, int $period): array
|
||||
{
|
||||
try {
|
||||
$token = $this->getBearerToken();
|
||||
|
||||
if (! $token) {
|
||||
Log::error('Failed to get bearer token for UKT summary');
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => 'Failed to authenticate with API',
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$response = $this->client->get('ukt-summary', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$token,
|
||||
],
|
||||
'query' => [
|
||||
'idfakultasunit' => $idfakultasunit,
|
||||
'period' => $period,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$statusCode = $response->getStatusCode();
|
||||
$responseBody = $response->getBody()->getContents();
|
||||
|
||||
if ($statusCode === 200) {
|
||||
$responseData = json_decode($responseBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
// If unauthorized, clear cache and retry once
|
||||
if ($statusCode === 401) {
|
||||
Log::warning('Token expired or invalid, retrying with new token...');
|
||||
Cache::forget('imamav_token');
|
||||
|
||||
$newToken = $this->login();
|
||||
|
||||
if ($newToken) {
|
||||
$retryResponse = $this->client->get('ukt-summary', [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$newToken,
|
||||
],
|
||||
'query' => [
|
||||
'idfakultasunit' => $idfakultasunit,
|
||||
'period' => $period,
|
||||
],
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
$retryStatusCode = $retryResponse->getStatusCode();
|
||||
$retryBody = $retryResponse->getBody()->getContents();
|
||||
|
||||
if ($retryStatusCode === 200) {
|
||||
$responseData = json_decode($retryBody, true);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
Log::error('Retry failed. Status: '.$retryStatusCode);
|
||||
Log::error('Retry Response: '.$retryBody);
|
||||
}
|
||||
}
|
||||
|
||||
Log::error('Failed to fetch UKT summary. Status: '.$statusCode);
|
||||
Log::error('Response: '.$responseBody);
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => 'Failed to fetch UKT summary from API',
|
||||
'data' => [],
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('Sevima UKT Summary API Error: '.$th->getMessage());
|
||||
Log::error('Stack trace: '.$th->getTraceAsString());
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'error' => $th->getMessage(),
|
||||
'data' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Verifikator\Periode;
|
||||
use Error;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class InsentifService
|
||||
{
|
||||
private $client;
|
||||
|
||||
protected $urlDevelopment = 'http://172.16.40.47:9000/';
|
||||
|
||||
protected $urlProduction = 'https://insentif.jurnal.untan.ac.id/';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (env('APP_ENV') === 'DEVELOPMENT') {
|
||||
$default = $this->urlDevelopment;
|
||||
} else {
|
||||
$default = $this->urlProduction;
|
||||
}
|
||||
|
||||
$this->client = new Client([
|
||||
'base_uri' => $default,
|
||||
'connect_timeout' => 5,
|
||||
'timeout' => 15,
|
||||
]);
|
||||
}
|
||||
|
||||
public function bukuAjar(string $nip, int $periode, ?int $limit = 1, ?string $status = 'Diterima')
|
||||
{
|
||||
try {
|
||||
$url = "api/v1/buku/pengajuan/$nip?kategori=Buku Ajar&periode=$periode";
|
||||
if ($status !== null) {
|
||||
$url .= "&status=$status";
|
||||
}
|
||||
$response = $this->client->get($url);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$data = collect($data['data'])->sortByDesc('poin');
|
||||
if ($limit) {
|
||||
$data = $data->take($limit);
|
||||
}
|
||||
|
||||
return $data;
|
||||
} catch (Throwable $th) {
|
||||
Log::info("Insentif ($nip): ".$th->getMessage());
|
||||
throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function modulAjar(string $nip, int $periode, ?int $limit = 2, ?string $status = 'Diterima')
|
||||
{
|
||||
// API Insentif modul ajar sudah tidak terpakai lagi, return empty collection (poin 0)
|
||||
return collect([]);
|
||||
}
|
||||
|
||||
public function publikasi(string $type, string $nip, int $periode = 386)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/$type/$nip/$periode");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return collect($data['data']);
|
||||
} catch (Throwable $th) {
|
||||
Log::info("Insentif ($nip): ".$th->getMessage());
|
||||
throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function cekData(string $nip)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/v1/perhitungan/$nip");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return collect($data);
|
||||
} catch (Throwable $th) {
|
||||
Log::info("Insentif ($nip): ".$th->getMessage());
|
||||
throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifikasiBukuAjar(string $unique, string $action, string $nip, ?string $note = null): array
|
||||
{
|
||||
try {
|
||||
$url = "api/v1/buku/verifikasi/$unique/$action";
|
||||
$body = [
|
||||
'kategori' => 'buku-ajar',
|
||||
'nip' => $nip,
|
||||
'apps' => 'Verifikator',
|
||||
];
|
||||
if ($note !== null) {
|
||||
$body['note'] = $note;
|
||||
}
|
||||
$response = $this->client->put($url, [
|
||||
'json' => $body,
|
||||
'http_errors' => false,
|
||||
]);
|
||||
|
||||
return [
|
||||
'_http_status' => $response->getStatusCode(),
|
||||
'data' => json_decode($response->getBody()->getContents(), true) ?? [],
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::info("Insentif verifikasi buku ajar ($unique/$action): ".$th->getMessage());
|
||||
throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function jurnal(string $nip, ?int $periode = null)
|
||||
{
|
||||
try {
|
||||
if ($periode === null) {
|
||||
$periode = Periode::where('status', true)->first()->id_periode;
|
||||
}
|
||||
$response = $this->client->get("api/v1/jurnal/pengajuan/$nip?periode=$periode");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
|
||||
return collect($data['data']);
|
||||
} catch (Throwable $th) {
|
||||
Log::info("Insentif ($nip): ".$th->getMessage());
|
||||
throw new Error('Server Insentif Jurnal Sedang Bermasalah', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\DokSiremun\Kegiatan;
|
||||
use App\Models\DokSiremun\Syarat;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use Error;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class KegiatanService
|
||||
{
|
||||
protected $dokumenService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dokumenService = new DokSiremunService;
|
||||
}
|
||||
|
||||
public function getKegiatan(int|string $id, $exclude = [1, 2, 3, 5, 6])
|
||||
{
|
||||
$kegiatan = Kegiatan::with([
|
||||
'syarats' => function ($query) use ($exclude) {
|
||||
return $query->select('id', 'id_kegiatan', 'id_kategori', 'id_rubrik', 'id_pelaksana', 'nama_pelaksana', 'uraian_kegiatan', 'posisi', 'poin_total', 'status_verifikasi_id', 'jumlah_satuan', 'satuan', 'jangka_waktu_per_semester', 'rasio', 'updated_at')
|
||||
->whereNotIn('id_kategori', $exclude);
|
||||
},
|
||||
])->find($id);
|
||||
|
||||
if (! $kegiatan) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$syarats = $kegiatan->syarats ?? collect();
|
||||
$kategoris = $syarats->whereNotNull('id_kategori')->unique('id_kategori')->pluck('id_kategori');
|
||||
|
||||
if ($kategoris->count() === 1 && $kategoris->first() === null) {
|
||||
return [
|
||||
[
|
||||
'nama' => $syarats->first()?->uraian_kegiatan ?? 'Tidak ada uraian',
|
||||
'anggota' => $syarats,
|
||||
'kategori' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$kegiatans = [];
|
||||
|
||||
foreach ($kategoris ?? [] as $kategori) {
|
||||
$anggota = $syarats->where('id_kategori', $kategori)->values();
|
||||
|
||||
$anggota->load([
|
||||
'dokumens:id,id_syarat,nama_file,kategori_dokumen',
|
||||
'pegawai:nip,nama,jenis_pegawai,unit_kerja_id',
|
||||
'pegawai.unit:id,nama',
|
||||
'pegawai.jabatan' => function ($query) {
|
||||
$query->select('id', 'nip', 'periode', 'active');
|
||||
},
|
||||
'pegawai.jabatan.detail' => function ($query) {
|
||||
$query->select('id', 'jabatan_pegawai_id', 'unit_pembayaran_id')
|
||||
->without('fungsional')
|
||||
->with('tambahan:id,nama');
|
||||
},
|
||||
'rubrik:id,uraian,kategori_rubrik_id',
|
||||
'rubrik.syarats:id,nama',
|
||||
'statusVerifikasi:id,name',
|
||||
]);
|
||||
|
||||
$firstAnggota = $anggota->first();
|
||||
$nama = $firstAnggota?->rubrik?->uraian ?? $firstAnggota?->uraian_kegiatan ?? 'Uraian tidak tersedia';
|
||||
|
||||
$kegiatans[] = [
|
||||
'nama' => $nama,
|
||||
'anggota' => $anggota,
|
||||
'kategori' => [],
|
||||
'biaya' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return $kegiatans ?? [];
|
||||
}
|
||||
|
||||
public function verifikasi(int|string $syaratId, int $statusVerifikasi, string $message, ?string $catatan = null)
|
||||
{
|
||||
$syarat = Syarat::find($syaratId);
|
||||
|
||||
if ($syarat->rubrik && $syarat->rubrik->syarats && $syarat->rubrik->syarats->where('nama', 'laporan kegiatan')->count() > 0) {
|
||||
$anggotas = Syarat::where('id_kegiatan', $syarat->id_kegiatan)->where('id_kategori', $syarat->id_kategori)->get();
|
||||
} else {
|
||||
$anggotas = collect([$syarat]);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
foreach ($anggotas as $anggota) {
|
||||
$original = collect($anggota->getOriginal());
|
||||
$anggota->update([
|
||||
'status_verifikasi_id' => $statusVerifikasi,
|
||||
]);
|
||||
|
||||
$anggota->logs()->create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => $message,
|
||||
'before' => json_encode($original->only(array_keys($anggota->getChanges()))),
|
||||
'after' => json_encode($anggota->getChanges()),
|
||||
]);
|
||||
|
||||
if ($catatan !== null) {
|
||||
$anggota->notes()->create([
|
||||
'type' => 'Catatan',
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => $catatan,
|
||||
]);
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
Log::info("Syarat: $syaratId");
|
||||
Log::error($th->getMessage());
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public function changeDuration(Syarat $syarat, float $jangka_waktu, ?string $alasan = '')
|
||||
{
|
||||
try {
|
||||
$jangka_waktu_per_semester = $jangka_waktu / 6;
|
||||
DB::beginTransaction();
|
||||
$poin = $this->dokumenService->getPoin($syarat->id_rubrik, $syarat->jumlah_satuan, $jangka_waktu_per_semester)['data'];
|
||||
$prevJangkaWaktu = $syarat->jangka_waktu_per_semester;
|
||||
$original = collect($syarat->getOriginal());
|
||||
$syarat->update([
|
||||
'poin_total' => $poin,
|
||||
'jangka_waktu_per_semester' => $jangka_waktu_per_semester,
|
||||
]);
|
||||
|
||||
$syarat->logs()->create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => "Jangka waktu diubah dari $prevJangkaWaktu menjadi $jangka_waktu_per_semester".($alasan ? " dengan alasan $alasan" : ''),
|
||||
'before' => json_encode($original->only(array_keys($syarat->getChanges()))),
|
||||
'after' => json_encode($syarat->getChanges()),
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
// HitungRemunerasi::dispatch($syarat->id_kegiatan, $syarat->rasio * 100, Auth::user(), false);
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
return false;
|
||||
DB::rollBack();
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeUnit(Syarat $syarat, float $jumlah)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$poin = $this->dokumenService->getPoin($syarat->id_rubrik, $jumlah, $syarat->jangka_waktu_per_semester)['data'];
|
||||
$prevJumlah = $syarat->jumlah_satuan;
|
||||
$original = collect($syarat->getOriginal());
|
||||
$syarat->update([
|
||||
'poin_total' => $poin,
|
||||
'jumlah_satuan' => $jumlah,
|
||||
]);
|
||||
|
||||
$syarat->logs()->create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => "Jumlah unit diubah dari $prevJumlah menjadi $jumlah",
|
||||
'before' => json_encode($original->only(array_keys($syarat->getChanges()))),
|
||||
'after' => json_encode($syarat->getChanges()),
|
||||
]);
|
||||
DB::commit();
|
||||
// HitungRemunerasi::dispatch($syarat->id_kegiatan, $syarat->rasio * 100, Auth::user(), false);
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
Log::info($th->getMessage());
|
||||
throw new Error($th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function changeRatio($id, float $ratio, ?int $id_anggota = null)
|
||||
{
|
||||
$kegiatan = Kegiatan::when($id_anggota, function ($query) use ($id_anggota) {
|
||||
$query->with([
|
||||
'syarats' => function ($subquery) use ($id_anggota) {
|
||||
$subquery->where('id', $id_anggota);
|
||||
},
|
||||
]);
|
||||
})
|
||||
->whereNotIn('uploader', ['Api Praktisi', 'Api Spada', 'API LMS', 'API Permatasari'])
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
if (! $kegiatan) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rasioDesimal = $ratio / 100;
|
||||
Syarat::where('id_kegiatan', $id)
|
||||
->update(['rasio' => $rasioDesimal]);
|
||||
|
||||
// Hitung Terakhir
|
||||
// $kegiatan->update(['status_processing' => 'WAITING']);
|
||||
// HitungRemunerasi::dispatch($id, $ratio, Auth::user(), $id_anggota ? $kegiatan->syarats->first()->id_kategori : null, false);
|
||||
$kegiatan->update(['status_processing' => 'SUCCESS']);
|
||||
}
|
||||
|
||||
public function pengajuan(int|string $syaratId, string $method = 'POST')
|
||||
{
|
||||
$syarat = Syarat::findOrFail($syaratId);
|
||||
$user = Pegawai::select('id')->where('nip', $syarat->id_pelaksana)->firstOrFail();
|
||||
if ($syarat->status_verifikasi_id > 2) {
|
||||
Log::info('Pengajuan: '.$syaratId);
|
||||
Log::info('Kegiatan sudah diajukan');
|
||||
throw new Error('Kegiatan sudah diajukan', 400);
|
||||
}
|
||||
|
||||
if ($syarat->rubrik->syarats->where('nama', 'laporan kegiatan')->count() > 0 && ! in_array($syarat->rubrik->kategori_rubrik_id, [1, 2, 3, 5, 6])) {
|
||||
$anggotas = Syarat::where('id_kegiatan', $syarat->id_kegiatan)->where('id_kategori', $syarat->id_kategori)->get();
|
||||
} else {
|
||||
$anggotas = collect([$syarat]);
|
||||
}
|
||||
|
||||
if ($syarat->id_kegiatan === 10022781) {
|
||||
$anggotas = Syarat::where('id_kegiatan', $syarat->id_kegiatan)->get();
|
||||
}
|
||||
|
||||
if ($syarat->id_rubrik === 657) {
|
||||
$anggotas = Syarat::where('id_kegiatan', $syarat->id_kegiatan)->get();
|
||||
}
|
||||
|
||||
if ($anggotas->where('status', 'INCOMPLETE')->count() > 0) {
|
||||
Log::info('Pengajuan: '.$syaratId);
|
||||
Log::info('Belum lengkap');
|
||||
throw new Error('Tidak dapat mengajukan kegiatan karena terdapat dokumen yang belum lengkap', 500);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
foreach ($anggotas as $anggota) {
|
||||
if ($syarat->id_kegiatan === 10022781) {
|
||||
$anggota->logs()->create([
|
||||
'user_id' => $user->id,
|
||||
'method' => $method,
|
||||
'employee_id' => $syarat->id_pelaksana,
|
||||
'employee_name' => $syarat->nama_pelaksana,
|
||||
'employee_role' => $syarat->keterangan,
|
||||
'message' => 'Pengajuan di bypass atas permintaan atasan',
|
||||
]);
|
||||
} else {
|
||||
$anggota->logs()->create([
|
||||
'user_id' => $user->id,
|
||||
'method' => $method,
|
||||
'employee_id' => $syarat->id_pelaksana,
|
||||
'employee_name' => $syarat->nama_pelaksana,
|
||||
'employee_role' => $syarat->keterangan,
|
||||
'message' => $anggota->status_verifikasi_id === 1 ? 'Pengajuan baru berhasil ditambahkan' : 'Pengajuan berhasil diperbaiki',
|
||||
]);
|
||||
}
|
||||
|
||||
if ($anggota->status_verifikasi_id === 1) {
|
||||
$anggota->update([
|
||||
'status_verifikasi_id' => 3,
|
||||
'tanggal_pengajuan' => date('Y-m-d'),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($anggota->status_verifikasi_id === 2) {
|
||||
$anggota->update([
|
||||
'status_verifikasi_id' => 4,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
if ($th instanceof ModelNotFoundException) {
|
||||
throw new ModelNotFoundException('Kegiatan tidak ditemukan');
|
||||
}
|
||||
Log::info('Pengajuan: '.$syaratId);
|
||||
Log::info($th->getMessage());
|
||||
throw new Error('Server Error', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Verifikator\JabatanPegawai;
|
||||
use App\Models\Verifikator\JabatanFungsionalRiwayat;
|
||||
use App\Models\Verifikator\JabatanTugasTambahanRiwayat;
|
||||
|
||||
class P1PegawaiService
|
||||
{
|
||||
/**
|
||||
* Update P1 untuk pegawai berdasarkan NIP, periode, dan bulan
|
||||
*/
|
||||
public function updateP1(string $nip, int $periode, int $bulan): array
|
||||
{
|
||||
$p1 = $tax = 0;
|
||||
|
||||
$jabatans = JabatanPegawai::with('detail')
|
||||
->where('nip', $nip)
|
||||
->where('periode', $periode)
|
||||
->get();
|
||||
|
||||
foreach ($jabatans as $jabatan) {
|
||||
$p1 = $tax = 0;
|
||||
|
||||
foreach ($jabatan?->detail ?? [] as $detail) {
|
||||
$fungsional = $detail->p1_jf ? $detail->jabatan_fungsional_id : null;
|
||||
$tambahan = $detail->p1_jtt ? $detail->jabatan_tambahan_id : null;
|
||||
|
||||
$p1 = $this->p1($fungsional, $tambahan, $detail->status_pns);
|
||||
$tax = $this->tax($p1, $detail->golongan);
|
||||
|
||||
$detail->update([
|
||||
'p1' => $p1,
|
||||
'p1_tax' => $tax,
|
||||
'p1_netto' => $p1 - $tax,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'p1' => $p1,
|
||||
'tax' => $tax,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung P1 berdasarkan jabatan fungsional dan tambahan
|
||||
*/
|
||||
public function p1(?int $jabatanFungsionalId, ?int $jabatanTambahanId, ?string $status = null): float
|
||||
{
|
||||
$hargaFungsional = JabatanFungsionalRiwayat::where('jabatan_fungsional_id', $jabatanFungsionalId)
|
||||
->where('periode', 377)
|
||||
->first()
|
||||
->harga ?? 0;
|
||||
|
||||
$hargaTambahan = JabatanTugasTambahanRiwayat::where('jtt_id', $jabatanTambahanId)
|
||||
->where('periode', 377)
|
||||
->first()
|
||||
->harga ?? 0;
|
||||
|
||||
$pengali = strtolower($status) === 'cpns' ? 0.8 : 1;
|
||||
$hargaJabatan = max($hargaFungsional, $hargaTambahan);
|
||||
|
||||
return 2 * $hargaJabatan * $pengali;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hitung pajak berdasarkan P1 dan golongan
|
||||
*/
|
||||
public function tax(float $p1, string $golongan): float
|
||||
{
|
||||
if (str_contains($golongan, 'III') || in_array($golongan, ['IX', 'X', 'XI'])) {
|
||||
$pengali = 5;
|
||||
} elseif (str_contains($golongan, 'IV')) {
|
||||
$pengali = 15;
|
||||
} else {
|
||||
$pengali = 0;
|
||||
}
|
||||
|
||||
return $p1 * ($pengali / 100);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Verifikator\JabatanPegawaiDetail;
|
||||
use Error;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class PerhitunganP2Service
|
||||
{
|
||||
public function dosen(JabatanPegawaiDetail $jabatan, float $poinKegiatan, float $poinSkp, float $poinGrade_14_17, float $rasio, ?int $pembagi = 6, float $adhocPoinKegiatan = 0.0)
|
||||
{
|
||||
try {
|
||||
$p2 = [];
|
||||
$total = $ratio = $tax = $netto = 0;
|
||||
$fmt = fn ($v) => number_format($v, 2, ',', '.');
|
||||
|
||||
$poin = $poinKegiatan + $poinSkp + $poinGrade_14_17;
|
||||
$rasio = $rasio === null ? $jabatan->unit->rasio->rasio : $rasio;
|
||||
$p2Fungsional = $p2Tambahan = 0;
|
||||
|
||||
// Narasi "Pemotongan Poin" sengaja ditampilkan berbasis Total Poin PENUH (termasuk Adhoc)
|
||||
// supaya sederhana & tidak menjelaskan pengurangan Adhoc di sini. $poin (dipakai untuk
|
||||
// JTT/Fungsional & P2 Bruto) tetap dihitung dari $poinKegiatan yang SUDAH dikeluarkan
|
||||
// poin Adhoc-nya — kedua angka boleh berbeda karena basisnya memang berbeda.
|
||||
$poinKegiatanPenuh = $poinKegiatan + $adhocPoinKegiatan;
|
||||
$poinDisplay = $poinKegiatanPenuh + $poinSkp + $poinGrade_14_17;
|
||||
|
||||
$p2['poin']['steps'][] = 'Total Poin + Poin SKP + Poin Grade 14 s.d. 17';
|
||||
$p2['poin']['steps'][] = $fmt($poinKegiatanPenuh).' + '.$fmt($poinSkp).' + '.$fmt($poinGrade_14_17);
|
||||
$p2['poin']['steps'][] = $fmt($poinDisplay);
|
||||
$p2['poin']['steps'][] = $fmt($poinDisplay).' > 68 ? 68 : '.$fmt($poinDisplay);
|
||||
$poinDisplay = $poinDisplay > 68 ? 68 : $poinDisplay;
|
||||
$p2['poin']['steps'][] = $fmt($poinDisplay).' - Poin P1';
|
||||
$p2['poin']['steps'][] = $fmt($poinDisplay).' - 12';
|
||||
$poinDisplay -= 12;
|
||||
$poinDisplay = round($poinDisplay, 2);
|
||||
$poinDisplay = $poinDisplay < 0 ? 0 : $poinDisplay;
|
||||
$p2['poin']['steps'][] = $fmt($poinDisplay);
|
||||
|
||||
$poin = $poin > 68 ? 68 : $poin;
|
||||
$poin -= 12;
|
||||
$poin = round($poin, 2);
|
||||
$poin = $poin < 0 ? 0 : $poin;
|
||||
$p2['poin']['total'] = round($poin, 2);
|
||||
|
||||
if ($jabatan->jabatan_tambahan_id && $jabatan->p2_jtt == 1) {
|
||||
$p2['tambahan']['jabatan'] = $jabatan?->tambahan?->nama ?? null;
|
||||
$p2['tambahan']['grade'] = $jabatan?->tambahan?->detail?->grade ?? null;
|
||||
$p2['tambahan']['harga'] = $jabatan?->tambahan?->detail?->harga ?? null;
|
||||
if ($poin >= 28) {
|
||||
$p2['tambahan']['steps'][] = 'Poin SKP + Poin Tri Dharma';
|
||||
$p2['tambahan']['steps'][] = $fmt($poinSkp).' + '.$fmt(28 - $poinSkp);
|
||||
$p2['tambahan']['steps'][] = $fmt($poinSkp + (28 - $poinSkp));
|
||||
$p2['tambahan']['poin'] = 28;
|
||||
$p2['tambahan']['poin_skp'] = $poinSkp;
|
||||
$p2['tambahan']['poin_tridharma'] = 28 - $poinSkp;
|
||||
} else {
|
||||
$p2['tambahan']['steps'][] = $fmt($poin);
|
||||
$p2['tambahan']['poin'] = $poin;
|
||||
}
|
||||
|
||||
$pengaliTambahan = $jabatan?->tambahan?->detail?->harga >= $jabatan?->fungsional?->detail?->harga ? $jabatan?->tambahan : $jabatan?->fungsional;
|
||||
$p2['tambahan']['steps'][] = '(Jumlah Bulan Menjabat / Total Bulan Menjabat) x Poin Jabatan Tugas Tambahan x '.$pengaliTambahan?->nama;
|
||||
$p2['tambahan']['steps'][] = "1/$pembagi x ".$fmt($poin > 28 ? 28 : $poin).' x '.$pengaliTambahan?->detail?->harga;
|
||||
$p2Tambahan = ($poin > 28 ? 28 : $poin) * $pengaliTambahan?->detail?->harga / $pembagi;
|
||||
$p2['tambahan']['steps'][] = 'Rp. '.number_format($p2Tambahan, 2, ',', '.');
|
||||
$p2['tambahan']['total'] = $p2Tambahan;
|
||||
$poin -= 28;
|
||||
}
|
||||
|
||||
$poin = $poin < 0 ? 0 : $poin;
|
||||
|
||||
$p2['fungsional']['jabatan'] = $jabatan?->fungsional?->nama;
|
||||
$p2['fungsional']['grade'] = $jabatan?->fungsional?->detail?->grade;
|
||||
$p2['fungsional']['harga'] = $jabatan?->fungsional?->detail?->harga;
|
||||
if ($jabatan->jabatan_tambahan_id && $jabatan->p2_jtt == 1) {
|
||||
if ($adhocPoinKegiatan > 0.001) {
|
||||
$p2['fungsional']['steps'][] = 'Total Poin P2 - Poin Kegiatan Adhoc';
|
||||
$p2['fungsional']['steps'][] = $fmt($p2['poin']['total'] + $adhocPoinKegiatan).' - '.$fmt($adhocPoinKegiatan);
|
||||
$p2['fungsional']['steps'][] = $fmt($p2['poin']['total']);
|
||||
$p2['fungsional']['steps'][] = 'Poin P2 - Poin Jabatan Tugas Tambahan';
|
||||
} else {
|
||||
$p2['fungsional']['steps'][] = 'Total Poin P2 - Poin Jabatan Tugas Tambahan';
|
||||
}
|
||||
$p2['fungsional']['steps'][] = $fmt($p2['poin']['total']).' - '.$fmt($p2['tambahan']['poin']);
|
||||
$p2['fungsional']['steps'][] = $fmt($p2['poin']['total'] - $p2['tambahan']['poin']);
|
||||
$p2['fungsional']['poin'] = $p2['poin']['total'] - $p2['tambahan']['poin'];
|
||||
} else {
|
||||
if ($adhocPoinKegiatan > 0.001) {
|
||||
$p2['fungsional']['steps'][] = 'Total Poin P2 - Poin Kegiatan Adhoc';
|
||||
$p2['fungsional']['steps'][] = $fmt($poin + $adhocPoinKegiatan).' - '.$fmt($adhocPoinKegiatan);
|
||||
$p2['fungsional']['steps'][] = $fmt($poin);
|
||||
$p2['fungsional']['steps'][] = 'Poin P2 - Poin P1';
|
||||
} else {
|
||||
$p2['fungsional']['steps'][] = 'Total Poin - Poin P1';
|
||||
}
|
||||
$p2['fungsional']['steps'][] = $fmt($poin + 12).' - 12';
|
||||
$p2['fungsional']['steps'][] = $fmt($poin);
|
||||
$p2['fungsional']['poin'] = $poin;
|
||||
}
|
||||
$p2['fungsional']['steps'][] = '(Jumlah Bulan Menjabat / Total Bulan Menjabat) x Poin Jabatan Fungsional x '.$jabatan?->fungsional?->nama;
|
||||
$p2['fungsional']['steps'][] = "(1 / $pembagi) x ".$fmt($p2['fungsional']['poin']).' x '.$jabatan?->fungsional?->detail?->harga;
|
||||
$p2Fungsional = 1 / $pembagi * $p2['fungsional']['poin'] * $jabatan?->fungsional?->detail?->harga;
|
||||
$p2['fungsional']['steps'][] = 'Rp. '.number_format($p2Fungsional, 2, ',', '.');
|
||||
$p2['fungsional']['total'] = $p2Fungsional;
|
||||
|
||||
$pengaliPns = $this->getPengaliPns($jabatan->status_pns);
|
||||
$pajak = 0;
|
||||
if (str_contains($jabatan->golongan, 'III') || in_array($jabatan->golongan, ['IX', 'X', 'XI'])) {
|
||||
$pajak = 5;
|
||||
} elseif (str_contains($jabatan->golongan, 'IV')) {
|
||||
$pajak = 15;
|
||||
} else {
|
||||
$pajak = 0;
|
||||
}
|
||||
|
||||
// Start Bruto Income
|
||||
$p2['bruto']['steps'][] = '(P2 Jabatan Fungsional + P2 Jabatan Tugas Tambahan) x Pengali '.strtoupper($jabatan?->status_pns ?? 'pns');
|
||||
$p2['bruto']['steps'][] = '(Rp. '.$fmt($p2Fungsional).' + Rp. '.$fmt($p2Tambahan).") x $pengaliPns";
|
||||
$p2['bruto']['steps'][] = 'Rp. '.number_format(($p2Fungsional + $p2Tambahan) * $pengaliPns, 2, ',', '.');
|
||||
$p2['bruto']['total'] = ($p2Fungsional + $p2Tambahan) * $pengaliPns;
|
||||
// End Bruto Income
|
||||
|
||||
// Start Bruto Income
|
||||
$p2['ratio']['steps'][] = 'P2 (Bruto) * Rasio';
|
||||
$p2['ratio']['steps'][] = 'Rp. '.number_format(($p2Fungsional + $p2Tambahan) * $pengaliPns, 2, ',', '.').' * '.(($rasio ?? 1) * 100).'%';
|
||||
$p2['ratio']['total'] = $p2['bruto']['total'] * ($rasio ?? 1);
|
||||
$p2['ratio']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.');
|
||||
// End Bruto Income
|
||||
|
||||
// Start Tax
|
||||
$p2['tax']['steps'][] = "Jumlah P2 (Bruto) * Pajak Golongan {$jabatan->golongan}";
|
||||
$p2['tax']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.')." * $pajak%";
|
||||
$p2['tax']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'] * $pajak / 100, 2, ',', '.');
|
||||
$p2['tax']['total'] = $p2['ratio']['total'] * $pajak / 100;
|
||||
// End Tax
|
||||
|
||||
// Start Net Income
|
||||
$p2['net']['steps'][] = "Jumlah P2 (Bruto) - Pajak Golongan {$jabatan->golongan}";
|
||||
$p2['net']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.').' - Rp. '.number_format($p2['tax']['total'], 2, ',', '.');
|
||||
$p2['net']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'] - $p2['tax']['total'], 2, ',', '.');
|
||||
$p2['net']['total'] = $p2['ratio']['total'] - $p2['tax']['total'];
|
||||
// End Net Income
|
||||
|
||||
$total += $p2['bruto']['total'];
|
||||
$ratio += $p2['ratio']['total'];
|
||||
$tax += $p2['tax']['total'];
|
||||
$netto += $p2['net']['total'];
|
||||
|
||||
return [
|
||||
'total' => [
|
||||
'bruto' => $total,
|
||||
'ratio' => $ratio,
|
||||
'tax' => $tax,
|
||||
'netto' => $netto,
|
||||
],
|
||||
'p2' => $p2,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
throw new Error('Terjadi kesalahan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function tendik(JabatanPegawaiDetail $jabatan, float $poinKegiatan, float $poinSkp, float $poinPresensi, float $rasio)
|
||||
{
|
||||
try {
|
||||
$total = $ratio = $tax = $netto = 0;
|
||||
$p2 = [];
|
||||
$fmt = fn ($v) => number_format($v, 2, ',', '.');
|
||||
|
||||
$pembagi = 6;
|
||||
|
||||
$poin = $poinKegiatan > 14 ? 14 : $poinKegiatan;
|
||||
$poin += $poinPresensi;
|
||||
$poin += $poinSkp ?? 0;
|
||||
$poin = round($poin, 2);
|
||||
|
||||
$p2['poin']['steps'][] = 'Total Poin > 54 ? 54 : Total Poin';
|
||||
$p2['poin']['steps'][] = $fmt($poin).' > 54 ? 54 : '.$fmt($poin);
|
||||
$poin = $poin > 54 ? 54 : $poin;
|
||||
|
||||
$p2['poin']['steps'][] = 'Total Poin - Poin P1';
|
||||
$p2['poin']['steps'][] = $fmt($poin).' - 12';
|
||||
$poin -= 12;
|
||||
$poin = $poin < 0 ? 0 : $poin;
|
||||
$p2['poin']['steps'][] = $fmt($poin);
|
||||
|
||||
$p2['poin']['total'] = $poin;
|
||||
|
||||
if ($jabatan->p2_jtt == 1) {
|
||||
$pengali = $jabatan?->tambahan?->detail?->harga >= $jabatan?->fungsional?->detail?->harga ? $jabatan?->tambahan : $jabatan?->fungsional;
|
||||
} else {
|
||||
$pengali = $jabatan?->fungsional;
|
||||
}
|
||||
$pajak = 0;
|
||||
if (str_contains($jabatan->golongan, 'III') || in_array($jabatan->golongan, ['IX', 'X', 'XI'])) {
|
||||
$pajak = 5;
|
||||
} elseif (str_contains($jabatan->golongan, 'IV')) {
|
||||
$pajak = 15;
|
||||
} else {
|
||||
$pajak = 0;
|
||||
}
|
||||
|
||||
$p2['jabatan'] = $pengali?->nama ?? null;
|
||||
$p2['grade'] = $pengali?->detail?->grade;
|
||||
$p2['harga'] = $pengali?->detail?->harga;
|
||||
|
||||
// Start Bruto Income
|
||||
$pengaliPns = $this->getPengaliPns($jabatan?->status_pns);
|
||||
$p2['bruto']['steps'][] = 'Jumlah bulan Menjabat / Total Bulan Menjabat x Total Poin x '.$p2['jabatan'].' x '.strtoupper($jabatan?->status_pns ?? 'pns');
|
||||
$p2['bruto']['steps'][] = "1 / $pembagi x ".$fmt($poin).' x '.$pengali?->detail?->harga.' x '.$pengaliPns;
|
||||
$p2['bruto']['total'] = $poin * $pengali?->detail?->harga / $pembagi * $pengaliPns;
|
||||
$p2['bruto']['steps'][] = 'Rp. '.number_format($p2['bruto']['total'], 2, ',', '.');
|
||||
// End Bruto Income
|
||||
|
||||
// Start Ratio Income
|
||||
$p2['ratio']['steps'][] = 'P2 Bruto * Rasio';
|
||||
$p2['ratio']['steps'][] = 'Rp. '.number_format($p2['bruto']['total'], 2, ',', '.').' * '.($rasio * 100).'%';
|
||||
$p2['ratio']['total'] = $p2['bruto']['total'] * $rasio;
|
||||
$p2['ratio']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.');
|
||||
// End Ratio Income
|
||||
|
||||
// Start Tax
|
||||
$p2['tax']['steps'][] = "Jumlah P2 (Bruto) * Pajak Golongan {$jabatan->golongan}";
|
||||
$p2['tax']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.')." * $pajak%";
|
||||
$p2['tax']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'] * $pajak / 100, 2, ',', '.');
|
||||
$p2['tax']['total'] = $p2['ratio']['total'] * $pajak / 100;
|
||||
// End Tax
|
||||
|
||||
// Start Net Income
|
||||
$p2['net']['steps'][] = "Jumlah P2 (Rasio) - Pajak Golongan {$jabatan->golongan}";
|
||||
$p2['net']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'], 2, ',', '.').' - Rp. '.number_format($p2['tax']['total'], 2, ',', '.');
|
||||
$p2['net']['steps'][] = 'Rp. '.number_format($p2['ratio']['total'] - $p2['tax']['total'], 2, ',', '.');
|
||||
$p2['net']['total'] = $p2['ratio']['total'] - $p2['tax']['total'];
|
||||
// End Net Income
|
||||
|
||||
$total += $p2['bruto']['total'];
|
||||
$ratio += $p2['ratio']['total'];
|
||||
$tax += $p2['tax']['total'];
|
||||
$netto += $p2['net']['total'];
|
||||
|
||||
return [
|
||||
'total' => [
|
||||
'bruto' => $total,
|
||||
'ratio' => $ratio,
|
||||
'tax' => $tax,
|
||||
'netto' => $netto,
|
||||
],
|
||||
'p2' => $p2,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
Log::error($th->getMessage());
|
||||
throw new Error('Terjadi kesalahan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function getPengaliPns(?string $statusPns): float
|
||||
{
|
||||
return match (strtoupper($statusPns ?? 'PNS')) {
|
||||
'CPNS' => 0.8,
|
||||
'PPPK', 'P3K' => 0.7,
|
||||
default => 1.0,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,527 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Http\Resources\Poin\DosenResource;
|
||||
use App\Http\Resources\Poin\PoinKalkulatorTendikResource;
|
||||
use App\Http\Resources\Poin\PoinTendikResource;
|
||||
use App\Http\Resources\Poin\TendikResource;
|
||||
use App\Models\DokSiremun\Membimbing;
|
||||
use App\Models\DokSiremun\Menguji;
|
||||
use App\Models\DokSiremun\Skp;
|
||||
use App\Models\DokSiremun\Syarat;
|
||||
use App\Models\Verifikator\KategoriRubrik;
|
||||
use App\Models\Verifikator\LimitMengajar;
|
||||
use App\Models\Verifikator\LimitPenunjang;
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\Tendik;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
|
||||
class PoinService
|
||||
{
|
||||
protected $insentifService;
|
||||
|
||||
protected $triDharmaService;
|
||||
|
||||
protected $periode;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->insentifService = new InsentifService;
|
||||
$this->triDharmaService = new TriDharmaService;
|
||||
$this->periode = Periode::where('status', true)->first()->id_periode;
|
||||
}
|
||||
|
||||
public function totalPoin(string $nip, $periode = null)
|
||||
{
|
||||
$jenisPegawai = Pegawai::select('jenis_pegawai')->where('nip', $nip)->first()->jenis_pegawai;
|
||||
if ($periode) {
|
||||
$this->periode = $periode;
|
||||
}
|
||||
if ($jenisPegawai === 'dosen') {
|
||||
return $this->dosen($nip);
|
||||
}
|
||||
|
||||
return $this->tendik($nip);
|
||||
}
|
||||
|
||||
public function mengajar(string $nip)
|
||||
{
|
||||
return [
|
||||
'antara' => $this->mengajarSiakad($nip, 'Antara'),
|
||||
's1' => $this->mengajarSiakad($nip, 'S1'),
|
||||
's2' => $this->mengajarSiakad($nip, 'S2'),
|
||||
's3' => $this->mengajarSiakad($nip, 'S3'),
|
||||
'mkwu' => $this->mengajarSiakad($nip, 'MKWU'),
|
||||
];
|
||||
}
|
||||
|
||||
public function mengajarSiakad(string $nip, string $nama, ?int $periode = null)
|
||||
{
|
||||
if (! $periode) {
|
||||
$periode = $this->periode;
|
||||
}
|
||||
|
||||
$pegawai = Pegawai::select('jenis_pegawai', 'prodi_id', 'unit_kerja_id')->where('nip', $nip)->first();
|
||||
if ($pegawai->jenis_pegawai === 'dosen') {
|
||||
$prodi = Pegawai::select('prodi_id')->where('nip', $nip)->first()->prodi_id;
|
||||
} else {
|
||||
$prodi = $pegawai->unit_kerja_id;
|
||||
}
|
||||
$limit = LimitMengajar::where('prodi_id', $prodi)
|
||||
->where('periode', $periode)
|
||||
->where('name', "Mengajar $nama")
|
||||
->first();
|
||||
$jenjang = $limit?->jenjangs->pluck('jenjang');
|
||||
$tipeMk = $limit?->tipeMks->pluck('tipe_mk');
|
||||
|
||||
$periode = $nama === 'Antara' ? $periode - 2 : $periode;
|
||||
|
||||
$column = ['id', 'id_pelaksana', 'sks', 'beban_mengajar', 'poin_total', 'kode_mk'];
|
||||
|
||||
if ($jenjang) {
|
||||
$jenjang = $jenjang->toArray();
|
||||
} elseif (in_array($nama, ['S2', 'S3'])) {
|
||||
$jenjang = [$nama];
|
||||
} elseif ($nama === 'S1') {
|
||||
$jenjang = ['D3', 'PROFESI', 'S1'];
|
||||
}
|
||||
|
||||
if ($tipeMk) {
|
||||
$tipeMk = $tipeMk->toArray();
|
||||
} elseif ($nama === 'MKWU') {
|
||||
$tipeMk = ['mkwu'];
|
||||
} elseif ($nama === 'Antara') {
|
||||
$tipeMk = ['biasa', 'pkl', 'mkwu', 'skripsi'];
|
||||
} else {
|
||||
$tipeMk = ['biasa', 'pkl', 'skripsi'];
|
||||
}
|
||||
|
||||
if ($periode === 383) {
|
||||
$rawQuery = '(poin_total / sks) as poin_per_sks';
|
||||
} else {
|
||||
$rawQuery = '(poin_total / beban_mengajar) as poin_per_sks';
|
||||
}
|
||||
$mengajars = $this->triDharmaService->mengajarSiakad($nip, $periode, 6, 8, $column, $rawQuery, $jenjang, $tipeMk)->sortByDesc('poin_per_sks');
|
||||
|
||||
$limit_type = 0;
|
||||
$poin = 0;
|
||||
|
||||
if ($limit) {
|
||||
if ($limit->limit_type === 'poin_total') {
|
||||
$poin = $mengajars->sum('poin_total');
|
||||
$poin = $poin > $limit->limit ? $limit->limit : $poin;
|
||||
} else {
|
||||
foreach ($mengajars as $mengajar) {
|
||||
if ($limit_type + $mengajar->{$limit->limit_type} <= $limit->limit) {
|
||||
$poin += $mengajar->poin_total;
|
||||
$limit_type += $mengajar->{$limit->limit_type};
|
||||
} else {
|
||||
$poin += ($limit->limit - $limit_type) * $mengajar->poin_per_sks;
|
||||
$limit_type += $limit->limit - $limit_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$poin = $mengajars->sum('poin_total');
|
||||
}
|
||||
|
||||
return round($poin, 2);
|
||||
}
|
||||
|
||||
public function membimbing(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$membimbing = Membimbing::where('id_pelaksana', $nip)->where('id_periode', $periode)->where('status_verifikasi_id', 7)->sum('poin_total');
|
||||
|
||||
return [
|
||||
'membimbing' => round($membimbing, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function mbkm(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$mbkm = Syarat::where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query->where('feeder', null)->where('id_periode', $periode);
|
||||
})
|
||||
->whereIn('id_rubrik', [625])
|
||||
->sum('poin_total');
|
||||
|
||||
$dpl = Syarat::where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query->where('feeder', null)->where('id_periode', $periode);
|
||||
})
|
||||
->whereIn('id_rubrik', [660])
|
||||
->get()
|
||||
->sortByDesc('poin_total')
|
||||
->take(5)
|
||||
->sum('poin_total');
|
||||
|
||||
$praktisi = Syarat::where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query->where('feeder', null)->where('id_periode', $periode);
|
||||
})
|
||||
->whereIn('id_rubrik', [999])
|
||||
->sum('poin_total');
|
||||
|
||||
return [
|
||||
'mbkm' => round($mbkm, 2),
|
||||
'dpl' => round($dpl, 2),
|
||||
'praktisi' => round($praktisi, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function pendidikanLainnya(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$lainnya = Syarat::where('id_pelaksana', $nip)
|
||||
->whereNotIn('id_rubrik', [645, 657, 658, 660, 999, 625])
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereIn('id_kategori', [1, 5, 6])
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query
|
||||
->where('feeder', null)
|
||||
->whereNotIn('uploader', ['Api Spada', 'API LMS', 'Api Praktisi', 'API Permatasari'])
|
||||
->where('id_periode', $periode);
|
||||
})
|
||||
->sum('poin_total');
|
||||
|
||||
$ppl = Syarat::where('id_pelaksana', $nip)
|
||||
->whereIn('id_rubrik', [645])
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query
|
||||
->where('feeder', null)
|
||||
->whereNotIn('uploader', ['Api Spada', 'API LMS', 'Api Praktisi', 'API Permatasari'])
|
||||
->where('id_periode', $periode);
|
||||
})
|
||||
->get()
|
||||
->sum('poin_total');
|
||||
|
||||
return [
|
||||
'pendidikan_lainnya' => round($lainnya + $ppl, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function lms(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$lms = Syarat::where('id_pelaksana', $nip)
|
||||
->whereNotIn('id_rubrik', [657, 658, 660, 999, 625])
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query
|
||||
->where('feeder', null)
|
||||
->whereIn('uploader', ['API LMS'])
|
||||
->where('id_periode', $periode)
|
||||
->where(function ($subquery) {
|
||||
$subquery
|
||||
->where('kategori_kegiatan', 'ILIKE', '%'.'Mengajar'.'%')
|
||||
->orWhere('kategori_kegiatan', 'ILIKE', '%'.'Membimbing'.'%')
|
||||
->orWhere('kategori_kegiatan', 'ILIKE', '%'.'Menguji'.'%');
|
||||
});
|
||||
})
|
||||
->sum('poin_total');
|
||||
|
||||
$spada = Syarat::where('id_pelaksana', $nip)
|
||||
->whereNotIn('id_rubrik', [657, 658, 660, 999, 625])
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query
|
||||
->where('feeder', null)
|
||||
->whereIn('uploader', ['Api Spada'])
|
||||
->where('id_periode', $periode)
|
||||
->where(function ($subquery) {
|
||||
$subquery
|
||||
->where('kategori_kegiatan', 'ILIKE', '%'.'Mengajar'.'%')
|
||||
->orWhere('kategori_kegiatan', 'ILIKE', '%'.'Membimbing'.'%')
|
||||
->orWhere('kategori_kegiatan', 'ILIKE', '%'.'Menguji'.'%');
|
||||
});
|
||||
})
|
||||
->sum('poin_total');
|
||||
|
||||
return [
|
||||
'lms' => round($lms, 2),
|
||||
'spada' => round($spada, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function menguji(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$menguji = $menguji = Menguji::where('id_pelaksana', $nip)->where('id_periode', $periode)->where('status_verifikasi_id', 7)->sum('poin_total');
|
||||
|
||||
return [
|
||||
'menguji' => round($menguji, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function publikasi(string $nip)
|
||||
{
|
||||
return round($this->insentifService->cekData($nip)['total_nilai'], 2);
|
||||
}
|
||||
|
||||
public function mpd(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$mpd = Syarat::where('id_pelaksana', $nip)
|
||||
->where('id_rubrik', 657)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query->where('id_periode', $periode);
|
||||
})
|
||||
->where('status_verifikasi_id', 7)
|
||||
->orderBy('poin_total', 'DESC')
|
||||
->get()
|
||||
->take(2)
|
||||
->sum('poin_total');
|
||||
|
||||
return [
|
||||
'mpd' => round($mpd, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function bukuAjar(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$bukuAjars = $this->insentifService->bukuAjar($nip, $periode);
|
||||
|
||||
return round($bukuAjars->sum('nilai'), 2);
|
||||
}
|
||||
|
||||
public function penunjang(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$kategoriPenunjangs = KategoriRubrik::with([
|
||||
'rubriks' => function ($query) {
|
||||
// return $query->where('periode_id', $periode);
|
||||
},
|
||||
])
|
||||
->where('nama', 'ILIKE', 'Kegiatan Penunjang%')
|
||||
->get();
|
||||
$penunjangs = [];
|
||||
foreach ($kategoriPenunjangs as $kategori) {
|
||||
$limit = LimitPenunjang::where('kategori_rubrik_id', $kategori->id)->first();
|
||||
$poin = Syarat::where('id_pelaksana', $nip)
|
||||
->whereIn('id_rubrik', $kategori->rubriks->pluck('id')->toArray())
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) use ($periode) {
|
||||
$query
|
||||
->where('id_periode', $periode)
|
||||
->whereNotIn('uploader', ['Api Praktisi', 'Api Spada', 'API LMS', 'API Permatasari'])
|
||||
->whereNull('feeder');
|
||||
})
|
||||
->orderBy('poin_total', 'DESC')
|
||||
->when($limit, function ($query) use ($limit) {
|
||||
return $query->limit($limit->limit)->get();
|
||||
})
|
||||
->sum('poin_total');
|
||||
$penunjangs[$kategori->nama] = round($poin, 2);
|
||||
}
|
||||
|
||||
return $penunjangs;
|
||||
}
|
||||
|
||||
public function penelitian(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$poin = 0;
|
||||
$penelitians = Syarat::where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) {
|
||||
$query->where('kategori_kegiatan', 'penelitian')->where('uploader', '!=', 'Api Siska')->whereNull('feeder');
|
||||
})
|
||||
->get()
|
||||
->groupBy('id_rubrik');
|
||||
|
||||
foreach ($penelitians as $penelitian) {
|
||||
$lastPeriode = $penelitian->where('kegiatan.id_periode', $periode - 3)->count() > 0;
|
||||
if ($lastPeriode) {
|
||||
continue;
|
||||
}
|
||||
$poin += $penelitian->sortByDesc('poin_total')->first()->poin_total;
|
||||
}
|
||||
|
||||
return [
|
||||
'penelitian' => round($poin, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function pengabdian(string $nip)
|
||||
{
|
||||
$periode = $this->periode;
|
||||
$poin = 0;
|
||||
$pengabdians = Syarat::with('kegiatan')
|
||||
->where('id_pelaksana', $nip)
|
||||
->where('status_verifikasi_id', 7)
|
||||
->whereHas('kegiatan', function ($query) {
|
||||
$query->where('kategori_kegiatan', 'pengabdian')->where('uploader', '!=', 'Api Siska')->whereNull('feeder');
|
||||
})
|
||||
->get()
|
||||
->groupBy('id_rubrik');
|
||||
foreach ($pengabdians as $pengabdian) {
|
||||
$lastPeriode = $pengabdian->where('kegiatan.id_periode', $periode - 3)->count() > 0;
|
||||
if ($lastPeriode) {
|
||||
continue;
|
||||
}
|
||||
$poin += $pengabdian->sortByDesc('poin_total')->first()->poin_total;
|
||||
}
|
||||
|
||||
return [
|
||||
'pengabdian' => round($poin, 2),
|
||||
];
|
||||
}
|
||||
|
||||
public function realNip(string $nip)
|
||||
{
|
||||
$pegawai = Pegawai::where('nip', $nip)->orWhere('nip_siakad', $nip)->first();
|
||||
|
||||
return $pegawai?->nip ?? $nip;
|
||||
}
|
||||
|
||||
public function dosen($nip)
|
||||
{
|
||||
$nip = $this->realNip($nip);
|
||||
|
||||
$mengajar = $this->mengajar($nip);
|
||||
$membimbing = $this->membimbing($nip);
|
||||
$menguji = $this->menguji($nip);
|
||||
$mpd = $this->mpd($nip);
|
||||
$bukuAjar = $this->bukuAjar($nip);
|
||||
$mbkm = $this->mbkm($nip);
|
||||
$lms = $this->lms($nip);
|
||||
$pendidikanLainnya = $this->pendidikanLainnya($nip);
|
||||
|
||||
$pendidikan = collect([...$mengajar, ...$membimbing, ...$menguji, 'modul' => $mpd['mpd'], 'lainnya' => $pendidikanLainnya['pendidikan_lainnya'], ...$mbkm, 'buku_ajar' => $bukuAjar, ...$lms]);
|
||||
|
||||
$penelitian = $this->penelitian($nip);
|
||||
$pengabdian = $this->pengabdian($nip);
|
||||
$penunjangs = $this->penunjang($nip);
|
||||
$publikasi = $this->publikasi($nip);
|
||||
|
||||
$poin = [
|
||||
'pendidikan' => $pendidikan,
|
||||
'penelitian' => $penelitian['penelitian'],
|
||||
'pengabdian' => $pengabdian['pengabdian'],
|
||||
'penunjang' => $penunjangs,
|
||||
'publikasi' => (float) $publikasi,
|
||||
];
|
||||
|
||||
return new DosenResource($poin);
|
||||
}
|
||||
|
||||
public function tendik($nip)
|
||||
{
|
||||
$nip = $this->realNip($nip);
|
||||
$tendik = Tendik::with('presensi')->select('id', 'nip')->where('nip', $nip)->orWhere('nip_siakad', $nip)->first();
|
||||
$mengajar = $this->mengajar($nip);
|
||||
$membimbing = $this->membimbing($nip);
|
||||
$menguji = $this->menguji($nip);
|
||||
$mpd = $this->mpd($nip);
|
||||
$bukuAjar = $this->bukuAjar($nip);
|
||||
$mbkm = $this->mbkm($nip);
|
||||
$lms = $this->lms($nip);
|
||||
$pendidikanLainnya = $this->pendidikanLainnya($nip);
|
||||
|
||||
$pendidikan = collect([...$mengajar, ...$membimbing, ...$menguji, 'modul' => $mpd['mpd'], 'lainnya' => $pendidikanLainnya['pendidikan_lainnya'], ...$mbkm, 'buku_ajar' => $bukuAjar, ...$lms]);
|
||||
|
||||
$penelitian = $this->penelitian($nip);
|
||||
$pengabdian = $this->pengabdian($nip);
|
||||
$penunjangs = $this->penunjang($nip);
|
||||
$penunjangs['Pendidikan'] = $pendidikan;
|
||||
$penunjangs['Pengabdian'] = $pengabdian['pengabdian'];
|
||||
$penunjangs['Penelitian'] = $penelitian['penelitian'];
|
||||
$publikasi = $this->publikasi($nip);
|
||||
$presensi = $tendik?->presensi?->poin_total ?? 0;
|
||||
$skp = Skp::where('id_pelaksana', $nip)->where('id_periode', $this->periode)->where('status_verifikasi_id', 7)->first();
|
||||
$poin = [
|
||||
'penunjang' => $penunjangs,
|
||||
'publikasi' => (float) $publikasi,
|
||||
'presensi' => round($presensi, 2),
|
||||
'skp' => [
|
||||
'nilai' => $skp?->nilai ?? 0,
|
||||
'poin' => $skp?->poin_total ?? 0,
|
||||
],
|
||||
];
|
||||
|
||||
return new TendikResource($poin);
|
||||
}
|
||||
|
||||
public function poinTendik($nip)
|
||||
{
|
||||
$nip = $this->realNip($nip);
|
||||
$tendik = Tendik::with('presensi')->select('id', 'nip')->where('nip', $nip)->orWhere('nip_siakad', $nip)->first();
|
||||
$mengajar = $this->mengajar($nip);
|
||||
$membimbing = $this->membimbing($nip);
|
||||
$menguji = $this->menguji($nip);
|
||||
$mpd = $this->mpd($nip);
|
||||
$bukuAjar = $this->bukuAjar($nip);
|
||||
$mbkm = $this->mbkm($nip);
|
||||
$lms = $this->lms($nip);
|
||||
$pendidikanLainnya = $this->pendidikanLainnya($nip);
|
||||
|
||||
$pendidikan = collect([...$mengajar, ...$membimbing, ...$menguji, 'modul' => $mpd['mpd'], 'lainnya' => $pendidikanLainnya['pendidikan_lainnya'], ...$mbkm, 'buku_ajar' => $bukuAjar, ...$lms]);
|
||||
|
||||
$penelitian = $this->penelitian($nip);
|
||||
$pengabdian = $this->pengabdian($nip);
|
||||
$penunjangs = $this->penunjang($nip);
|
||||
$penunjangs['Pendidikan'] = $pendidikan;
|
||||
$penunjangs['Pengabdian'] = $pengabdian['pengabdian'];
|
||||
$penunjangs['Penelitian'] = $penelitian['penelitian'];
|
||||
$publikasi = $this->publikasi($nip);
|
||||
$presensi = $tendik?->presensi?->poin_total ?? 0;
|
||||
$skp = Skp::where('id_pelaksana', $nip)->where('id_periode', $this->periode)->where('status_verifikasi_id', 7)->first();
|
||||
$poin = [
|
||||
'penunjang' => $penunjangs,
|
||||
'publikasi' => (float) $publikasi,
|
||||
'presensi' => round($presensi, 2),
|
||||
'skp' => [
|
||||
'nilai' => $skp?->nilai ?? 0,
|
||||
'poin' => $skp?->poin_total ?? 0,
|
||||
],
|
||||
];
|
||||
|
||||
return new PoinTendikResource($poin);
|
||||
}
|
||||
|
||||
public function poinKalkulatorTendik($nip)
|
||||
{
|
||||
$nip = $this->realNip($nip);
|
||||
$tendik = Tendik::with('presensi')->select('id', 'nip')->where('nip', $nip)->orWhere('nip_siakad', $nip)->first();
|
||||
$mengajar = $this->mengajar($nip);
|
||||
$membimbing = $this->membimbing($nip);
|
||||
$menguji = $this->menguji($nip);
|
||||
$mpd = $this->mpd($nip);
|
||||
$bukuAjar = $this->bukuAjar($nip);
|
||||
$mbkm = $this->mbkm($nip);
|
||||
$lms = $this->lms($nip);
|
||||
$pendidikanLainnya = $this->pendidikanLainnya($nip);
|
||||
|
||||
$pendidikan = collect([...$mengajar, ...$membimbing, ...$menguji, 'modul' => $mpd['mpd'], 'lainnya' => $pendidikanLainnya['pendidikan_lainnya'], ...$mbkm, 'buku_ajar' => $bukuAjar, ...$lms]);
|
||||
|
||||
$penelitian = $this->penelitian($nip);
|
||||
$pengabdian = $this->pengabdian($nip);
|
||||
$penunjangs = $this->penunjang($nip);
|
||||
$penunjangs['Pendidikan'] = $pendidikan;
|
||||
$penunjangs['Pengabdian'] = $pengabdian['pengabdian'];
|
||||
$penunjangs['Penelitian'] = $penelitian['penelitian'];
|
||||
$publikasi = $this->publikasi($nip);
|
||||
$presensi = $tendik?->presensi?->poin_total ?? 0;
|
||||
$skp = Skp::where('id_pelaksana', $nip)->where('id_periode', $this->periode)->where('status_verifikasi_id', 7)->first();
|
||||
$poin = [
|
||||
'penunjang' => $penunjangs,
|
||||
'publikasi' => (float) $publikasi,
|
||||
'presensi' => round($presensi, 2),
|
||||
'skp' => [
|
||||
'nilai' => $skp?->nilai ?? 0,
|
||||
'poin' => $skp?->poin_total ?? 0,
|
||||
],
|
||||
];
|
||||
|
||||
return new PoinKalkulatorTendikResource($poin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Verifikator\Periode;
|
||||
use App\Models\Verifikator\View\Pegawai;
|
||||
use Error;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Throwable;
|
||||
|
||||
class RemunerasiService
|
||||
{
|
||||
public function p2Sk(string $nip, $totalPoin, float $rasio = 100, $id_rubrik = null)
|
||||
{
|
||||
try {
|
||||
$periode = Periode::where('status', true)->first()->id_periode;
|
||||
$pegawai = Pegawai::with([
|
||||
'jabatan' => function ($query) use ($periode) {
|
||||
$query->where('periode', $periode)->where('active', true)->with('detail', function ($subquery) {
|
||||
$subquery->where('p2_jf', true)->where('p2_jtt', true);
|
||||
});
|
||||
},
|
||||
])
|
||||
->where('nip', $nip)
|
||||
->first();
|
||||
|
||||
$total = 0;
|
||||
$p2 = [];
|
||||
|
||||
if ($pegawai?->jabatan?->detail?->count() === 0) {
|
||||
return [
|
||||
'total' => $total,
|
||||
'p2' => $p2,
|
||||
];
|
||||
}
|
||||
|
||||
$pembagi = 6;
|
||||
|
||||
foreach ($pegawai?->jabatan?->detail ?? [] as $detail) {
|
||||
$month = $detail->bulan;
|
||||
$poin = $totalPoin;
|
||||
$poin = round($poin, 2);
|
||||
|
||||
$p2[$month]['poin']['steps'][] = 'Total Poin';
|
||||
$p2[$month]['poin']['steps'][] = $poin;
|
||||
$p2[$month]['poin']['total'] = $poin;
|
||||
|
||||
$poin = $poin < 0 ? 0 : $poin;
|
||||
|
||||
$pengalis = $detail?->tambahan?->detail?->harga >= $detail?->fungsional?->detail?->harga ? $detail?->tambahan : $detail?->fungsional;
|
||||
|
||||
// Pengali untuk Rubrik Tim Adhoc dan Kepanitiaan Adhoc
|
||||
if ($detail->jenis_pegawai === 'tendik') {
|
||||
$pengali = $pengalis?->detail?->harga;
|
||||
$hargaJabatan = $pengalis?->nama ?? null;
|
||||
} elseif ($detail->jenis_pegawai === 'dosen') {
|
||||
if (in_array($id_rubrik, [684, 685, 686, 687, 695, 696, 697])) {
|
||||
$pengali = 660000;
|
||||
$hargaJabatan = 'Rp.660.000';
|
||||
} else {
|
||||
$pengali = $pengalis?->detail?->harga;
|
||||
$hargaJabatan = $pengalis?->nama ?? null;
|
||||
}
|
||||
} else {
|
||||
$pengali = 1;
|
||||
$hargaJabatan = 'Tidak Ada';
|
||||
}
|
||||
|
||||
// Poin Pengali untuk PNS
|
||||
$poinPengaliPegawai = 0;
|
||||
|
||||
if (strtoupper($detail->status_pns) === 'PNS') {
|
||||
$poinPengaliPegawai = 1;
|
||||
} elseif (strtoupper($detail->status_pns) === 'CPNS') {
|
||||
$poinPengaliPegawai = 0.8;
|
||||
} elseif (strtoupper($detail->status_pns) === 'PPPK') {
|
||||
$poinPengaliPegawai = 0.7;
|
||||
}
|
||||
|
||||
$p2[$month]['jabatan'] = $pengalis?->nama ?? null;
|
||||
$p2[$month]['grade'] = $pengalis?->detail?->grade;
|
||||
$p2[$month]['harga'] = $pengalis?->detail?->harga;
|
||||
|
||||
$p2[$month]['jumlah']['steps'][] = 'Jumlah bulan Menjabat / Total Bulan Menjabat x Total Poin x '.$hargaJabatan.' x '.strtoupper($detail->status_pns).' x Rasio';
|
||||
$p2[$month]['jumlah']['steps'][] = "1 / $pembagi x $poin x ".$pengali.' x '.$poinPengaliPegawai." x $rasio%";
|
||||
$p2[$month]['total'] = ((($poin * $pengali) / $pembagi) * $poinPengaliPegawai * $rasio) / 100;
|
||||
$p2[$month]['jumlah']['steps'][] = 'Rp. '.number_format($p2[$month]['total'], 2, ',', '.');
|
||||
$total += $p2[$month]['total'];
|
||||
}
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'p2' => $p2,
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
if ($th instanceof ModelNotFoundException) {
|
||||
throw new Error('Pegawai Tidak Ditemukan', 404);
|
||||
}
|
||||
throw new Error('Terjadi kesalahan : '.$th->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function biaya(float $poin, $jabatans, $initialPointRatio, $jenisPegawai, $id_rubrik = null)
|
||||
{
|
||||
$result = [];
|
||||
$pembagi = strtolower($jenisPegawai) === 'dosen' ? count($jabatans) : 6;
|
||||
|
||||
foreach ($jabatans as $jabatan) {
|
||||
$pointRasio = $initialPointRatio;
|
||||
$pengali = $jabatan?->tambahan?->detail?->harga >= $jabatan?->fungsional?->detail?->harga ? $jabatan?->tambahan : $jabatan?->fungsional;
|
||||
|
||||
// Pengali untuk Rubrik Tim Adhoc dan Kepanitiaan Adhoc
|
||||
if ($jenisPegawai === 'tendik') {
|
||||
$pengali = $pengali?->detail?->harga;
|
||||
} elseif ($jenisPegawai === 'dosen') {
|
||||
if (in_array($id_rubrik, [684, 685, 686, 687, 695, 696, 697])) {
|
||||
$pengali = 660000;
|
||||
} else {
|
||||
$pengali = $pengali?->detail?->harga;
|
||||
}
|
||||
}
|
||||
|
||||
// Poin Pengali untuk PNS
|
||||
$poinPengaliPegawai = 0;
|
||||
if (strtoupper($jabatan->status_pns) === 'PNS') {
|
||||
$poinPengaliPegawai = 1;
|
||||
} elseif (strtoupper($jabatan->status_pns) === 'CPNS') {
|
||||
$poinPengaliPegawai = 0.8;
|
||||
} elseif (strtoupper($jabatan->status_pns) === 'PPPK') {
|
||||
$poinPengaliPegawai = 0.7;
|
||||
}
|
||||
|
||||
$result[$jabatan->id]['poin'] = $poin * $pointRasio;
|
||||
$result[$jabatan->id]['bruto'] = (($poin * $pointRasio * $pengali) / $pembagi) * $poinPengaliPegawai;
|
||||
$result[$jabatan->id]['ratio'] = $result[$jabatan->id]['bruto'];
|
||||
|
||||
$pajak = 0;
|
||||
if (str_contains($jabatan->golongan, 'III') || in_array($jabatan?->golongan, ['IX', 'X'])) {
|
||||
$pajak = 5;
|
||||
} elseif (str_contains($jabatan->golongan, 'IV') || in_array($jabatan?->golongan, ['XI'])) {
|
||||
$pajak = 15;
|
||||
}
|
||||
|
||||
$result[$jabatan->id]['tax'] = ($result[$jabatan->id]['ratio'] * $pajak) / 100;
|
||||
$result[$jabatan->id]['netto'] = $result[$jabatan->id]['ratio'] - $result[$jabatan->id]['tax'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,728 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Error;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
|
||||
class SiskaService
|
||||
{
|
||||
private $client;
|
||||
|
||||
protected $urlIp = 'http://172.16.50.16:8123/';
|
||||
|
||||
protected $urlDomain = 'https://siska.untan.ac.id/';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$baseUrl = $this->urlDomain;
|
||||
|
||||
if (env('APP_ENV') === 'DEVELOPMENT') {
|
||||
$baseUrl = $this->urlIp;
|
||||
} else {
|
||||
$baseUrl = $this->urlDomain;
|
||||
}
|
||||
|
||||
$this->client = new Client([
|
||||
'base_uri' => $baseUrl,
|
||||
'timeout' => 30,
|
||||
]);
|
||||
}
|
||||
|
||||
public function daftarSks(int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/sk?page=$page&per_page=$per_page");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function daftarUnits(): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get('api/daftar-fakultas');
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (! isset($data['meta']['code']) || $data['meta']['code'] !== 200) {
|
||||
}
|
||||
$units = $data['data'];
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
public function skPerUnit(int $id_unit, string $status, int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
$result = $this->status($status);
|
||||
$status_verifikator = $result['status_verifikator'];
|
||||
$finalisasi = $result['finalisasi'];
|
||||
$must_fix = $result['must_fix'];
|
||||
try {
|
||||
$response = $this->client->get("api/sk-per-unit/$id_unit?page=$page&per_page=$per_page&status_verifikator=$status_verifikator&finalisasi=$finalisasi&must_fix=$must_fix");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function detailSk(int|string $id_sk): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/detail-sk/$id_sk");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$sk = $data['data'];
|
||||
|
||||
return $sk;
|
||||
}
|
||||
|
||||
public function verif(int|string $id_sk): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/verif-verifikator/$id_sk");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function tolak(int|string $id_sk, string $catatan): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/tolak-verifikator/$id_sk", [
|
||||
'form_params' => [
|
||||
'catatan' => $catatan,
|
||||
],
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function perbaikan(int|string $id_sk, ?string $catatan = null): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/tolak-verifikator-dengan-perbaikan/$id_sk", [
|
||||
'form_params' => [
|
||||
'catatan' => $catatan,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function pilihRubrik(int $id_anggota, int $kategori_id, ?int $rubrik_id): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/pilih-rubrik/$id_anggota", [
|
||||
'form_params' => [
|
||||
'kategori_id' => $kategori_id,
|
||||
'rubrik_id' => $rubrik_id,
|
||||
],
|
||||
]);
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function SkBelumFinalisasi(int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/sk-belum-finalisasi?page=$page&per_page=$per_page");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = $data['data'];
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function skBelumFinalisasiPerUnit(int $id_unit, int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/sk-belum-finalisasi-per-unit/$id_unit?page=$page&per_page=$per_page");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function finalisasi(int|string $id_sk): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/finalisasi/$id_sk");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPosisi(): array
|
||||
{
|
||||
return Cache::remember('siska_posisi', 3600, function () {
|
||||
try {
|
||||
$response = Http::get('http://172.16.40.201:9098/api/v1/siska3/');
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
||||
} catch (Throwable $th) {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getKategoriByPosisi(string $posisi, array $exclude = []): ?array
|
||||
{
|
||||
$isPembimbingPenguji = str_contains(strtolower($posisi), 'pembimbing') || str_contains(strtolower($posisi), 'penguji');
|
||||
$cacheKey = $isPembimbingPenguji ? 'siska_kategori_sks' : 'siska_kategori_'.md5(strtolower($posisi));
|
||||
|
||||
$rawData = Cache::remember($cacheKey, 3600, function () use ($posisi, $isPembimbingPenguji) {
|
||||
try {
|
||||
$uri = $isPembimbingPenguji
|
||||
? 'http://172.16.40.201:9098/api/v1/sks'
|
||||
: "http://172.16.40.201:9098/api/v1/siska1/$posisi";
|
||||
|
||||
$response = Http::get($uri);
|
||||
|
||||
return json_decode($response->getBody()->getContents(), true) ?? [];
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
$kategoris = collect($rawData)
|
||||
->filter(function ($kategori) use ($posisi, $exclude) {
|
||||
if (! is_array($kategori)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strtolower($kategori['posisi']) !== strtolower($posisi)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ! in_array($kategori['rubrik_id'], $exclude);
|
||||
})
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
if (strtolower($posisi) === 'tidak ada dalam rubrik') {
|
||||
$kategoris[] = [
|
||||
'kategori_id' => 1000,
|
||||
'uraian' => 'Tidak Ada dalam Rubrik',
|
||||
'posisi' => $posisi,
|
||||
'nama_kegiatan' => 'Tidak Ada dalam Rubrik',
|
||||
'rubrik_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return $kategoris;
|
||||
}
|
||||
|
||||
public function getRubriksByKategoriId(int $kategori_id): ?array
|
||||
{
|
||||
try {
|
||||
$uri = "http://172.16.40.201:9098/api/v1/siska2/$kategori_id";
|
||||
|
||||
$response = Http::get($uri);
|
||||
$rubriks = json_decode($response->getBody()->getContents(), true);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $rubriks;
|
||||
}
|
||||
|
||||
public function searchSks(string $keyword, string $status = 'belum-verif', int $page = 1, int $per_page = 10, ?int $id_unit = null): ?array
|
||||
{
|
||||
$filter = $this->status($status);
|
||||
$status_verifikator = $filter['status_verifikator'];
|
||||
$finalisasi = $filter['finalisasi'];
|
||||
$must_fix = $filter['must_fix'];
|
||||
try {
|
||||
if ($id_unit) {
|
||||
$response = $this->client->get("api/cari?tentang=$keyword&id_unit=$id_unit&page=$page&per_page=$per_page&status_verifikator=$status_verifikator&finalisasi=$finalisasi&must_fix=$must_fix");
|
||||
} else {
|
||||
$response = $this->client->get("api/cari?tentang=$keyword&page=$page&per_page=$per_page&status_verifikator=$status_verifikator&finalisasi=$finalisasi&must_fix=$must_fix");
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = $data['data'];
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function searchSkPerUnit(int $unit, string $status, string $keyword, int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
$filter = $this->status($status);
|
||||
$status_verifikator = $filter['status_verifikator'];
|
||||
$finalisasi = $filter['finalisasi'];
|
||||
$must_fix = $filter['must_fix'];
|
||||
try {
|
||||
$response = $this->client->get("api/cari-per-unit/$unit/$keyword?page=$page&per_page=$per_page&status_verifikator=$status_verifikator&finalisasi=$finalisasi&must_fix=$must_fix");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = $data['data'];
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function searchByNoSk(string $no_sk, string $status = 'belum-verif', int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/cari-by-nosk?no_sk=$no_sk&status=$status&page=$page&per_page=$per_page");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function deleteMember(int $id_anggota, string $catatan): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/hapus-anggota/$id_anggota", [
|
||||
'form_params' => [
|
||||
'catatan' => $catatan,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function changeDuration(int $id_anggota, int $duration): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/tetapkan-jangka-waktu/$id_anggota", [
|
||||
'form_params' => [
|
||||
'jangka_waktu' => $duration,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
if ($th instanceof ClientException) {
|
||||
throw new NotFoundHttpException('SISKA : SK tidak ditemukan');
|
||||
}
|
||||
|
||||
if ($th instanceof ServerException) {
|
||||
throw new Error('SISKA : Server sedang mengalami gangguan', 500);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function statusPerbaikan($unit_id, string $status = 'Belum Diperbaiki', int $page = 1, int $per_page = 10, ?string $tentang = null)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/status-perbaikan?status=$status&tentang=$tentang&page=$page&per_page=$per_page&unit_id=$unit_id");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
if ($totalPage > 1 && count($data['data']) < $per_page) {
|
||||
$totalPage = 1;
|
||||
}
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function searchStatusPerbaikanByNomorSk($unit_id, string $no_sk, string $status = 'Belum Diperbaiki', int $page = 1, int $per_page = 10)
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/cari-status-perbaikan-by-nomor?no_sk=$no_sk&status=$status&page=$page&per_page=$per_page&unit_id=$unit_id");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = array_values($data['data']);
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function gantiPosisi(int $id_anggota, string $posisi): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/ganti-posisi/$id_anggota", [
|
||||
'form_params' => [
|
||||
'posisi' => $posisi,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200) {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error("$id_anggota menjadi $posisi");
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function tambahAnggota(int $id_sk, string $nama, string $nip, ?string $gol, string $keterangan, string $posisi, ?int $kategori_id = null, ?int $rubrik_id = null): int
|
||||
{
|
||||
try {
|
||||
$response = $this->client->post("api/tambah-anggota/$id_sk", [
|
||||
'form_params' => [
|
||||
'id_sk' => $id_sk,
|
||||
'nama' => $nama,
|
||||
'nip' => $nip,
|
||||
'gol' => $gol,
|
||||
'keterangan' => $keterangan,
|
||||
'posisi' => $posisi,
|
||||
'kategori_id' => $kategori_id,
|
||||
'rubrik_id' => $rubrik_id,
|
||||
],
|
||||
]);
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
if (isset($data['meta']['code']) && $data['meta']['code'] === 200 && $data['meta']['message'] !== 'gagal') {
|
||||
return $data['data']['id'];
|
||||
}
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function cariSkByNip(string $nip, int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/cari-sk-by-nip/$nip?page=$page&per_page=$per_page");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = $data['data'];
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function penandatangan()
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get('api/penandatangan');
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$penandatangans = $data['data'];
|
||||
|
||||
return $penandatangans;
|
||||
}
|
||||
|
||||
public function cariSkByPenandatangan(int $idPenandatangan, int $page = 1, int $per_page = 10): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/cari-sk-by-penandatangan/$idPenandatangan?page=$page&per_page=$per_page");
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$totalPage = count($response->getHeader('X-Total-Pages')) > 0 ? (int) $response->getHeader('X-Total-Pages')[0] : 0;
|
||||
$sks['data'] = $data['data']['sk'];
|
||||
$sks['total_pages'] = $totalPage;
|
||||
$sks['recordsFiltered'] = $totalPage * $per_page;
|
||||
$sks['recordsTotal'] = $totalPage * $per_page;
|
||||
$sks['belum_verif'] = $data['data']['jumlah belum verif'];
|
||||
$sks['belum_finalisasi'] = $data['data']['jumlah belum finalisasi'];
|
||||
$sks['sudah_finalisasi'] = $data['data']['jumlah sudah finalisasi'];
|
||||
$sks['tolak'] = $data['data']['jumlah tolak'];
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function statistikSk()
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get('api/statistik-sk');
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA : '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
$statistik = $data['data'];
|
||||
|
||||
return $statistik;
|
||||
}
|
||||
|
||||
public function skReclaim(int $page = 1): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/reclaim?page=$page&per_page=10000");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$sks['data'] = $data['data'] ?? [];
|
||||
$sks['meta'] = $data['meta'] ?? [];
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function skReclaimPerUnit(int $id_unit, int $page = 1): ?array
|
||||
{
|
||||
try {
|
||||
$response = $this->client->get("api/reclaim-per-unit/$id_unit?page=$page");
|
||||
} catch (Throwable $th) {
|
||||
Log::error('SISKA: '.$th->getMessage());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = json_decode($response->getBody()->getContents(), true);
|
||||
$sks['data'] = $data['data'] ?? [];
|
||||
$sks['meta'] = $data['meta'] ?? [];
|
||||
|
||||
return $sks;
|
||||
}
|
||||
|
||||
public function status(string $status)
|
||||
{
|
||||
$result = [
|
||||
'status_verifikator' => 'null',
|
||||
'finalisasi' => 'null',
|
||||
'must_fix' => 'null',
|
||||
];
|
||||
switch ($status) {
|
||||
case 'belum-verif':
|
||||
$result = [
|
||||
'status_verifikator' => 'null',
|
||||
'finalisasi' => 0,
|
||||
'must_fix' => 'null',
|
||||
];
|
||||
break;
|
||||
case 'belum-finalisasi':
|
||||
$result = [
|
||||
'status_verifikator' => 1,
|
||||
'finalisasi' => 0,
|
||||
'must_fix' => 'null',
|
||||
];
|
||||
break;
|
||||
case 'diterima':
|
||||
$result = [
|
||||
'status_verifikator' => 1,
|
||||
'finalisasi' => 1,
|
||||
'must_fix' => 'null',
|
||||
];
|
||||
break;
|
||||
case 'ditolak':
|
||||
$result = [
|
||||
'status_verifikator' => 0,
|
||||
'finalisasi' => 0,
|
||||
'must_fix' => 'null',
|
||||
];
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\DokSiremun\Membimbing;
|
||||
use App\Models\DokSiremun\Mengajar;
|
||||
use App\Models\DokSiremun\Menguji;
|
||||
use App\Models\DokSiremun\Syarat;
|
||||
use App\Traits\TriDharma\AsesorTrait;
|
||||
use App\Traits\TriDharma\MembimbingTrait;
|
||||
use App\Traits\TriDharma\MengajarTrait;
|
||||
use App\Traits\TriDharma\MengujiTrait;
|
||||
use App\Traits\TriDharma\ModulPembelajaranTrait;
|
||||
use App\Traits\TriDharma\PenelitianTrait;
|
||||
use App\Traits\TriDharma\PengabdianTrait;
|
||||
use App\Traits\TriDharma\ReviewerTrait;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class TriDharmaService
|
||||
{
|
||||
use AsesorTrait, MembimbingTrait, MengajarTrait, MengujiTrait, ModulPembelajaranTrait, PenelitianTrait, PengabdianTrait, ReviewerTrait;
|
||||
|
||||
public function getPengajuan(string $type, int $id)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'MengajarSiakad':
|
||||
$pengajuan = Mengajar::find($id);
|
||||
break;
|
||||
case 'MembimbingSiakad':
|
||||
case 'MembimbingAkademik':
|
||||
$pengajuan = Membimbing::find($id);
|
||||
break;
|
||||
case 'MengujiSiakad':
|
||||
$pengajuan = Menguji::find($id);
|
||||
break;
|
||||
case 'MengajarNonSiakad':
|
||||
case 'MembimbingNonSiakad':
|
||||
case 'MengujiNonSiakad':
|
||||
case 'Penelitian':
|
||||
case 'Pengabdian':
|
||||
case 'ModulPembelajaran':
|
||||
case 'Asesor':
|
||||
case 'Reviewer':
|
||||
$pengajuan = Syarat::find($id);
|
||||
break;
|
||||
default:
|
||||
Log::info("$type: $id");
|
||||
break;
|
||||
}
|
||||
|
||||
return $pengajuan;
|
||||
}
|
||||
|
||||
public function verifikasi(Mengajar|Membimbing|Menguji|Syarat $pengajuan, int $status_verifikasi_id, string $method, ?string $catatan = null)
|
||||
{
|
||||
switch ($status_verifikasi_id) {
|
||||
case 1:
|
||||
$message = 'Verifikasi dibatalkan atas permintaan ybs.';
|
||||
break;
|
||||
case 2:
|
||||
$message = 'Pengajuan ditolak oleh verifikator';
|
||||
break;
|
||||
case 3:
|
||||
$message = 'Verifikasi dibatalkan oleh verifikator';
|
||||
break;
|
||||
case 6:
|
||||
if ($pengajuan->status_verifikasi_id < 6) {
|
||||
$message = 'Pengajuan diterima oleh verifikator';
|
||||
} else {
|
||||
$message = 'Pleno dibatalkan oleh dekan';
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
$message = 'Pleno diterima oleh dekan';
|
||||
break;
|
||||
case 8:
|
||||
$message = 'Pleno ditolak oleh dekan';
|
||||
break;
|
||||
default:
|
||||
$message = null;
|
||||
}
|
||||
|
||||
if ($pengajuan->id_rubrik === 652) {
|
||||
return $this->verifikasiBimbinganAkademik($pengajuan->id_pelaksana, $pengajuan->id_periode, $status_verifikasi_id, $method, $message, $catatan);
|
||||
}
|
||||
|
||||
if ($pengajuan->id_rubrik === 657) {
|
||||
return $this->verifikasiModulPembelajaran($pengajuan->id_kegiatan, $status_verifikasi_id, $method, $message, $catatan);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$action = 'verifikasi';
|
||||
if ($status_verifikasi_id > 6) {
|
||||
$action = 'pleno';
|
||||
}
|
||||
|
||||
$pengajuan->update([
|
||||
'status_verifikasi_id' => $status_verifikasi_id,
|
||||
]);
|
||||
|
||||
$pengajuan->logs()->create([
|
||||
'user_id' => Auth::user()->id,
|
||||
'method' => $method,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => 'Verifikator',
|
||||
'message' => $message,
|
||||
]);
|
||||
|
||||
if (in_array($status_verifikasi_id, [2, 5, 8])) {
|
||||
$pengajuan->notes()->create([
|
||||
'type' => 'catatan',
|
||||
'user_id' => Auth::user()->id,
|
||||
'employee_id' => Auth::user()->nip,
|
||||
'employee_name' => Auth::user()->name,
|
||||
'employee_role' => Auth::user()->role,
|
||||
'message' => $catatan,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return [
|
||||
'code' => 200,
|
||||
'status' => 'success',
|
||||
'message' => "Berhasil melakukan $action pengajuan",
|
||||
];
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
Log::info(get_class($pengajuan));
|
||||
Log::info($pengajuan->id);
|
||||
Log::error($th->getMessage());
|
||||
|
||||
return [
|
||||
'code' => 500,
|
||||
'status' => 'error',
|
||||
'message' => "Gagal melakukan $action pengajuan",
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user