Files
alrahma_sunday_school_api/app/Services/Events/EventStudentChargeService.php
T
root e0dfc3ec82
API CI/CD / Validate (composer + pint) (push) Successful in 3m15s
API CI/CD / Test (PHPUnit) (push) Failing after 5m4s
API CI/CD / Build frontend assets (push) Successful in 1m3s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
Fixed many feature failures around preferences, route coverage, administrator enrollment, assignment section names, attendance tracking controller access, finance PDF generation, and finance notification logging.
2026-07-07 21:26:47 -04:00

42 lines
1.2 KiB
PHP

<?php
namespace App\Services\Events;
use App\Models\EventCharges;
use App\Models\Student;
use Illuminate\Support\Facades\DB;
class EventStudentChargeService
{
public function listStudentsWithCharges(int $parentId, string $schoolYear, string $semester): array
{
$students = DB::table((new Student)->getTable())
->where('parent_id', $parentId)
->get()
->map(fn ($row) => (array) $row)
->all();
$chargedIds = DB::table((new EventCharges)->getTable())
->where('parent_id', $parentId)
->where('school_year', $schoolYear)
->where('semester', $semester)
->distinct()
->pluck('student_id')
->map(fn ($id) => (int) $id)
->all();
$chargedMap = array_flip($chargedIds);
$data = [];
foreach ($students as $student) {
$data[] = [
'id' => (int) ($student['id'] ?? 0),
'name' => trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? '')),
'charged' => isset($chargedMap[(int) ($student['id'] ?? 0)]),
];
}
return $data;
}
}