Files
alrahma_sunday_school_api/app/Services/Administrator/AdministratorEnrollmentEventService.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

83 lines
2.7 KiB
PHP

<?php
namespace App\Services\Administrator;
use App\Models\Invoice;
use App\Services\ApplicationUrlService;
use Illuminate\Support\Facades\Event;
class AdministratorEnrollmentEventService
{
private ApplicationUrlService $urls;
public function __construct(?ApplicationUrlService $urls = null)
{
$this->urls = $urls ?? app(ApplicationUrlService::class);
}
public function dispatchGroupedEvents(
array $groupsByParentStatus,
array $parentInfo,
array $refundAmountByParent,
string $schoolYear
): void {
$eventMap = [
'admission under review' => 'admissionUnderReview',
'payment pending' => 'paymentPending',
'enrolled' => 'studentEnrolled',
'withdraw under review' => 'withdrawUnderReview',
'refund pending' => 'refundPending',
'withdrawn' => 'withdrawn',
'denied' => 'denied',
'waitlist' => 'waitlist',
];
foreach ($groupsByParentStatus as $pid => $byStatus) {
$p = $parentInfo[$pid] ?? [
'user_id' => $pid,
'email' => null,
'firstname' => '',
'lastname' => '',
];
$invoice = Invoice::query()
->where('parent_id', $pid)
->where('school_year', $schoolYear)
->latest('created_at')
->first();
foreach ($byStatus as $status => $studentsArr) {
if (! isset($eventMap[$status])) {
continue;
}
$studentData = array_map(
fn ($s) => [
'name' => $s['student_name'],
'student_id' => $s['student_id'],
],
$studentsArr
);
$parentData = [
'user_id' => $p['user_id'],
'email' => $p['email'],
'firstname' => $p['firstname'],
'lastname' => $p['lastname'],
'school_year' => $schoolYear,
'portalLink' => $this->urls->webLoginUrl(),
];
if ($status === 'payment pending' && $invoice) {
$parentData['amount'] = (float) ($invoice->balance ?? $invoice->amount_due ?? $invoice->total_amount ?? 0);
$parentData['due_date'] = $invoice->due_date ?? null;
} elseif ($status === 'refund pending') {
$parentData['amount'] = $refundAmountByParent[$pid] ?? null;
}
Event::dispatch($eventMap[$status], [$parentData, $studentData]);
}
}
}
}