Commit cfd003e1 authored by Syaifur Rohman's avatar Syaifur Rohman

add table and chart absensi

parent a57f7baa
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Akademik\AbsensiModel;
class ChartDashboardController extends Controller
{
public function __construct()
{
$this->mAkAbsensi = new AbsensiModel();
}
public function getStatistikAbsensi()
{
// Fetch all attendance records for the current school and active period
$absensi = $this->mAkAbsensi
->where('idPSekolah', session()->get('idPSekolah'))
->where('idPPeriode', session()->get('idPPeriode'))
->get();
// Initialize a status count array with descriptive keys
$statusCount = [
'belum_ada_absensi' => 0,
'hadir' => 0,
'tidak_hadir' => 0,
'terlambat' => 0,
'ijin' => 0,
'sakit' => 0,
];
// Count each status across all students
foreach ($absensi as $record) {
switch ($record->idStatus) {
case 0:
$statusCount['belum_ada_absensi']++;
break;
case 1:
$statusCount['hadir']++;
break;
case 2:
$statusCount['tidak_hadir']++;
break;
case 3:
$statusCount['terlambat']++;
break;
case 4:
$statusCount['ijin']++;
break;
case 5:
$statusCount['sakit']++;
break;
}
}
// Return the status count as JSON
return response()->json($statusCount);
}
}
\ No newline at end of file
...@@ -120,6 +120,8 @@ Route::middleware(['login:1'])->group(function () { ...@@ -120,6 +120,8 @@ Route::middleware(['login:1'])->group(function () {
Route::middleware(['login:2'])->group(function () { Route::middleware(['login:2'])->group(function () {
@include_once('web_sekolah.php'); @include_once('web_sekolah.php');
// Chart Dashboard
Route::get('chart/dashboard/get-statistik-absensi', 'Api\ChartDashboardController@getStatistikAbsensi');
}); });
Route::middleware(['login:3'])->group(function () { Route::middleware(['login:3'])->group(function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment