Aturan Perhitungan Baru

This commit is contained in:
Ariyutta
2026-10-08 19:01:21 +07:00
parent 4f74b6a0fc
commit 899e29e275
9 changed files with 970 additions and 23 deletions
+90
View File
@@ -694,4 +694,94 @@ class ImamAVService
];
}
}
public function attendanceSimulasi2026(string $nip, array $params = []): array
{
try {
$token = $this->getBearerToken();
if (! $token) {
Log::error('Failed to get bearer token for attendance simulasi 2026');
return [
'success' => false,
'error' => 'Failed to authenticate with API',
'data' => [],
];
}
$query = array_merge(['nip' => $nip], $params);
$response = $this->client->get('attendance-simulasi-2026', [
'headers' => [
'Authorization' => 'Bearer '.$token,
],
'query' => $query,
'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('attendance-simulasi-2026', [
'headers' => [
'Authorization' => 'Bearer '.$newToken,
],
'query' => $query,
'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 attendance simulasi 2026. Status: '.$statusCode);
Log::error('Response: '.$responseBody);
return [
'success' => false,
'error' => 'Failed to fetch attendance simulasi 2026 from API',
'data' => [],
];
} catch (Throwable $th) {
Log::error('ImamAV Attendance Simulasi 2026 API Error: '.$th->getMessage());
Log::error('Stack trace: '.$th->getTraceAsString());
return [
'success' => false,
'error' => $th->getMessage(),
'data' => [],
];
}
}
}