256 lines
8.0 KiB
PHP
256 lines
8.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Models\AcademicYear;
|
|
use App\Models\Assessment;
|
|
use App\Models\AssessmentLearningObjective;
|
|
use App\Models\ClassRoom;
|
|
use App\Models\ClassSubject;
|
|
use App\Models\CompetencyAchievement;
|
|
use App\Models\ExtracurricularAssessment;
|
|
use App\Models\HomeRoomTeacher;
|
|
use App\Models\Student;
|
|
use App\Models\SchoolInformation;
|
|
use App\Models\Subject;
|
|
use App\Models\TeacherSubject;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
use function PHPUnit\Framework\isEmpty;
|
|
use function Symfony\Component\String\s;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
|
|
Carbon::setLocale('id');
|
|
|
|
class ReportPreview extends Page
|
|
{
|
|
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
|
|
|
protected static string $view = 'filament.pages.report-preview';
|
|
|
|
public $student;
|
|
public $class;
|
|
public $class_name;
|
|
public $academic_year;
|
|
public $semester;
|
|
|
|
public $school_information;
|
|
|
|
public $table = [];
|
|
|
|
public $sakit = 0;
|
|
public $izin = 0;
|
|
public $tanpa_keterangan = 0;
|
|
|
|
public $home_room_teacher;
|
|
|
|
public function mount()
|
|
{
|
|
$this->loadData();
|
|
}
|
|
|
|
public function saveAttendance()
|
|
{
|
|
$this->validate([
|
|
'sakit' => 'required|integer|min:0',
|
|
'izin' => 'required|integer|min:0',
|
|
'tanpa_keterangan' => 'required|integer|min:0',
|
|
]);
|
|
|
|
Notification::make()
|
|
->title('Data Kehadiran Disimpan')
|
|
->success()
|
|
->send();
|
|
}
|
|
|
|
protected function loadData() : void
|
|
{
|
|
$this->student = Student::find(request()->query('studentId')) ?? 1;
|
|
|
|
$this->class = ClassRoom::find(request()->query('classId')) ?? 1;
|
|
$this->academic_year = AcademicYear::find(request()->query('yearId')) ?? 1;
|
|
$this->semester = request()->query('semester') ?? "first";
|
|
$this->school_information = SchoolInformation::first();
|
|
|
|
$this->class_name = $this->toRoman($this->class->class_level) . ' ' . $this->extractClassLetter($this->class->class_name);
|
|
|
|
$this->loadAssessment();
|
|
}
|
|
|
|
protected function loadAssessment(): void
|
|
{
|
|
$requiredParams = ['studentId', 'classId', 'semester', 'yearId'];
|
|
|
|
foreach ($requiredParams as $param) {
|
|
if (blank(request()->query($param))) {
|
|
Notification::make()
|
|
->title('Missing Data')
|
|
->body("The parameter '{$param}' is required.")
|
|
->danger()
|
|
->send();
|
|
}
|
|
}
|
|
|
|
$student_id = request()->query('studentId');
|
|
$class_id = request()->query('classId');
|
|
$semester = request()->query('semester');
|
|
$year_id = request()->query('yearId');
|
|
|
|
// Assessment Mapping
|
|
$assessments = Assessment::where('semester', $this->semester)
|
|
->whereHas('teacherSubject', function($query) use ($class_id, $year_id) {
|
|
$query->where('academic_year_id', $year_id)
|
|
->where('class_id', $class_id);
|
|
})
|
|
->where('student_id', $this->student->id)
|
|
->with('teacherSubject.subject', 'student')
|
|
->get()
|
|
->map(function ($as) use ($class_id) {
|
|
$subject = $as->teacherSubject->subject ?? null;
|
|
|
|
if (!$subject) {
|
|
return null;
|
|
}
|
|
|
|
$assesmentLearningObjectivesLower = AssessmentLearningObjective::with('learningObjective')
|
|
->where('teacher_subject_id', $as->teacherSubject->id)
|
|
->where('student_id', $this->student->id)
|
|
->where('type', 'lower')
|
|
->get()
|
|
->pluck('learningObjective.description')
|
|
->toArray();
|
|
|
|
$joinedStringLower = $as->student->full_name . ' perlu peningkatan dalam ' . implode(', ', $assesmentLearningObjectivesLower);
|
|
|
|
$assesmentLearningObjectivesHighest = AssessmentLearningObjective::with('learningObjective')
|
|
->where('teacher_subject_id', $as->teacherSubject->id)
|
|
->where('student_id', $this->student->id)
|
|
->where('type', 'highest')
|
|
->get()
|
|
->pluck('learningObjective.description')
|
|
->toArray();
|
|
|
|
$joinedStringHighest = $as->student->full_name . ' menunjukan pemahaman dalam ' . implode(', ', $assesmentLearningObjectivesHighest);
|
|
|
|
return [
|
|
"score" => $as->score,
|
|
"subject" => $subject->name,
|
|
"category" => $subject->category,
|
|
"lower" => $assesmentLearningObjectivesLower ? $joinedStringLower : null,
|
|
"highest" => $assesmentLearningObjectivesHighest ? $joinedStringHighest : null,
|
|
];
|
|
})
|
|
->filter() // Hapus null jika ada
|
|
->sortByDesc('subject')
|
|
->sortBy(function ($item) {
|
|
return $item['category'] === 'umum' ? 0 : 1;
|
|
})
|
|
->values()
|
|
->toArray();
|
|
|
|
$this->table["assessments"]['umum'] = array_filter($assessments, function ($item) {
|
|
return $item["category"] === "umum";
|
|
});
|
|
|
|
$this->table["assessments"]['muatan lokal'] = array_filter($assessments, function ($item) {
|
|
return $item["category"] === "muatan lokal";
|
|
});
|
|
|
|
$this->table["assessments"]['seni'] = array_filter($assessments, function ($item) {
|
|
return $item["category"] === "seni";
|
|
});
|
|
|
|
$extracurricular = ExtracurricularAssessment::with('classStudent','extracurricular')
|
|
->where('semester', $this->semester)
|
|
->whereHas('classStudent', function($query) use ($class_id, $year_id) {
|
|
$query->where('academic_year_id', $year_id)
|
|
->where('class_room_id', $class_id)
|
|
->where('student_id', $this->student->id);
|
|
})
|
|
->get()
|
|
->map(function ($as) {
|
|
return [
|
|
"name" => $as->extracurricular->name,
|
|
"predicate" => $as->predicate,
|
|
"description" => $as->description,
|
|
];
|
|
})
|
|
->toArray();
|
|
$this->table["extracurricular"] = $extracurricular;
|
|
|
|
$homeRoom = HomeRoomTeacher::with(['teacher'])
|
|
->where('class_room_id', $this->class->id)
|
|
->where('academic_year_id', $this->academic_year->id)
|
|
->first();
|
|
|
|
if ($homeRoom) {
|
|
$this->home_room_teacher = $homeRoom ?? [];
|
|
}
|
|
}
|
|
|
|
public function extractClassLetter($className)
|
|
{
|
|
preg_match('/[A-Z]+$/i', trim($className), $matches);
|
|
return $matches[0] ?? '';
|
|
}
|
|
|
|
public function toRoman($number)
|
|
{
|
|
$map = [
|
|
'M' => 1000,
|
|
'CM' => 900,
|
|
'D' => 500,
|
|
'CD' => 400,
|
|
'C' => 100,
|
|
'XC' => 90,
|
|
'L' => 50,
|
|
'XL' => 40,
|
|
'X' => 10,
|
|
'IX' => 9,
|
|
'V' => 5,
|
|
'IV' => 4,
|
|
'I' => 1,
|
|
];
|
|
|
|
$returnValue = '';
|
|
while ($number > 0) {
|
|
foreach ($map as $roman => $int) {
|
|
if ($number >= $int) {
|
|
$number -= $int;
|
|
$returnValue .= $roman;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $returnValue;
|
|
}
|
|
|
|
public static function shouldRegisterNavigation(): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function getTitle(): string | Htmlable
|
|
{
|
|
return 'Pratinjau Rapor Siswa'; // Contoh jika nama laporan dinamis
|
|
}
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return 'Pratinjau Rapor Siswa';
|
|
}
|
|
|
|
public static function getBreadcrumb(): string
|
|
{
|
|
return 'Pratinjau Rapor Siswa';
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return 'Pratinjau Rapor Siswa';
|
|
}
|
|
}
|