fix tests
This commit is contained in:
@@ -20,8 +20,7 @@ class AccountEventService
|
||||
public function __construct(
|
||||
private EmailService $emailService,
|
||||
private UserNotificationDispatchService $notifier
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function newAccountAdded(array $userData): array
|
||||
{
|
||||
@@ -29,7 +28,7 @@ class AccountEventService
|
||||
$message = $this->renderEmail('emails/welcome_user', ['user' => $userData], $subject);
|
||||
|
||||
$sent = false;
|
||||
if (!empty($userData['email'])) {
|
||||
if (! empty($userData['email'])) {
|
||||
$sent = $this->emailService->send(
|
||||
(string) $userData['email'],
|
||||
$subject,
|
||||
@@ -41,7 +40,7 @@ class AccountEventService
|
||||
$supportMessage = $this->renderEmail('emails/support_new_account', ['user' => $userData], $subject);
|
||||
$this->emailService->send(
|
||||
'support@alrahmaisgl.org',
|
||||
'New Account Created: ' . trim((string) ($userData['firstname'] ?? '') . ' ' . (string) ($userData['lastname'] ?? '')),
|
||||
'New Account Created: '.trim((string) ($userData['firstname'] ?? '').' '.(string) ($userData['lastname'] ?? '')),
|
||||
$supportMessage,
|
||||
'notifications'
|
||||
);
|
||||
@@ -53,13 +52,14 @@ class AccountEventService
|
||||
|
||||
public function studentRegistered(array $data): array
|
||||
{
|
||||
if (empty($data['parents']) || !is_array($data['parents'])) {
|
||||
if (empty($data['parents']) || ! is_array($data['parents'])) {
|
||||
Log::warning('StudentRegistered: missing parent data');
|
||||
|
||||
return ['ok' => false, 'message' => 'Missing parent data.'];
|
||||
}
|
||||
|
||||
$studentFullName = trim((string) ($data['firstname'] ?? '') . ' ' . (string) ($data['lastname'] ?? ''));
|
||||
if (!empty($data['parents']['user_id'])) {
|
||||
$studentFullName = trim((string) ($data['firstname'] ?? '').' '.(string) ($data['lastname'] ?? ''));
|
||||
if (! empty($data['parents']['user_id'])) {
|
||||
$title = 'Your child has been registered';
|
||||
$msg = "{$studentFullName} has been successfully registered to Al Rahma Sunday School.";
|
||||
$this->notifier->notifyUser((int) $data['parents']['user_id'], $title, $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
@@ -100,18 +100,21 @@ class AccountEventService
|
||||
public function userRegistered(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Welcome!', 'Thanks for registering with our school system.', ['in_app', 'email'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function userProfileUpdated(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Profile Updated', 'Your profile information was successfully updated.', ['in_app'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function userDeactivated(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Account Deactivated', 'Your account has been deactivated by the administrator.', ['in_app', 'email'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -120,6 +123,7 @@ class AccountEventService
|
||||
foreach ((array) ($data['students'] ?? []) as $student) {
|
||||
$this->notifier->notifyUser((int) ($student['id'] ?? 0), 'New Score Available', 'A new score has been posted.', ['in_app', 'email'], 'registration', 'student');
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -136,21 +140,24 @@ class AccountEventService
|
||||
|
||||
public function studentMarkedAbsent(array $record): array
|
||||
{
|
||||
$msg = (string) ($record['student_name'] ?? 'Student') . ' was absent on ' . (string) ($record['date'] ?? '');
|
||||
$msg = (string) ($record['student_name'] ?? 'Student').' was absent on '.(string) ($record['date'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($record['parent_id'] ?? 0), 'Absence Notification', $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function studentMarkedLate(array $record): array
|
||||
{
|
||||
$msg = (string) ($record['student_name'] ?? 'Student') . ' was late on ' . (string) ($record['date'] ?? '');
|
||||
$msg = (string) ($record['student_name'] ?? 'Student').' was late on '.(string) ($record['date'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($record['parent_id'] ?? 0), 'Late Notification', $msg, ['in_app', 'email'], 'registration', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function paymentMissed(array $user): array
|
||||
{
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), 'Payment Missed', 'You have missed a scheduled payment. Please settle your balance.', ['in_app', 'email'], 'payment', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -159,13 +166,15 @@ class AccountEventService
|
||||
foreach ((array) ($data['students'] ?? []) as $student) {
|
||||
$this->notifier->notifyUser((int) ($student['id'] ?? 0), 'Schedule Update', 'Your class schedule has been updated.', ['in_app'], 'notifications', 'student');
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
public function newMessageReceived(array $data): array
|
||||
{
|
||||
$msg = 'You have a new message from ' . (string) ($data['sender_name'] ?? '');
|
||||
$msg = 'You have a new message from '.(string) ($data['sender_name'] ?? '');
|
||||
$this->notifier->notifyUser((int) ($data['recipient_id'] ?? 0), 'New Message Received', $msg, ['in_app'], 'notifications', 'parent');
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -180,6 +189,7 @@ class AccountEventService
|
||||
foreach ($users as $user) {
|
||||
$this->notifier->notifyUser((int) ($user['id'] ?? 0), (string) ($data['title'] ?? ''), (string) ($data['message'] ?? ''), ['in_app'], 'notifications', $targetGroup);
|
||||
}
|
||||
|
||||
return ['ok' => true];
|
||||
}
|
||||
|
||||
@@ -205,10 +215,10 @@ class AccountEventService
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($userData, $userId): void {
|
||||
$familyCode = 'FAM-' . $userId;
|
||||
$familyCode = 'FAM-'.$userId;
|
||||
$family = Family::query()->where('family_code', $familyCode)->first();
|
||||
if (!$family) {
|
||||
$householdName = trim('Family of ' . ((string) ($userData['firstname'] ?? '') . ' ' . (string) ($userData['lastname'] ?? '')));
|
||||
if (! $family) {
|
||||
$householdName = trim('Family of '.((string) ($userData['firstname'] ?? '').' '.(string) ($userData['lastname'] ?? '')));
|
||||
$family = Family::query()->create([
|
||||
'family_code' => $familyCode,
|
||||
'household_name' => $householdName,
|
||||
@@ -252,12 +262,12 @@ class AccountEventService
|
||||
{
|
||||
try {
|
||||
$currentYear = (string) Configuration::getConfigValueByKey('school_year');
|
||||
if (!preg_match('/^(\d{4})-(\d{4})$/', $currentYear, $m)) {
|
||||
if (! preg_match('/^(\d{4})-(\d{4})$/', $currentYear, $m)) {
|
||||
return;
|
||||
}
|
||||
$y1 = (int) $m[1];
|
||||
$y2 = (int) $m[2];
|
||||
$nextYear = ($y1 + 1) . '-' . ($y2 + 1);
|
||||
$nextYear = ($y1 + 1).'-'.($y2 + 1);
|
||||
|
||||
$rows = DB::table('students as s')
|
||||
->select('s.id as student_id', 'sc.class_section_id', 'fall.semester_score as fall_score', 'spring.semester_score as spring_score')
|
||||
@@ -309,7 +319,7 @@ class AccountEventService
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Promotion queue build failed: ' . $e->getMessage());
|
||||
Log::error('Promotion queue build failed: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,6 +327,6 @@ class AccountEventService
|
||||
{
|
||||
Log::debug('Skipping Blade email template', ['view' => $viewName]);
|
||||
|
||||
return '<p>' . e($fallbackTitle) . '</p>';
|
||||
return '<p>'.e($fallbackTitle).'</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ class EnrollmentEventService
|
||||
private EmailService $emailService,
|
||||
private UserNotificationDispatchService $notifier,
|
||||
private ApplicationUrlService $urls,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function admissionUnderReview(array $parentData, array $students): array
|
||||
{
|
||||
@@ -179,7 +178,7 @@ class EnrollmentEventService
|
||||
'parentName' => $parentName,
|
||||
'studentName' => $studentName,
|
||||
'withdrawalDate' => $parentData['withdrawal_date'] ?? ($parentData['date'] ?? ''),
|
||||
'withdrawals' => !empty($withdrawals) ? $withdrawals : null,
|
||||
'withdrawals' => ! empty($withdrawals) ? $withdrawals : null,
|
||||
'portalLink' => $parentData['portalLink'] ?? $this->urls->webLoginUrl(),
|
||||
'title' => 'Withdrawal Confirmed',
|
||||
];
|
||||
@@ -278,16 +277,16 @@ class EnrollmentEventService
|
||||
|
||||
private function parentName(array $parentData): string
|
||||
{
|
||||
return trim((string) ($parentData['firstname'] ?? '') . ' ' . (string) ($parentData['lastname'] ?? ''));
|
||||
return trim((string) ($parentData['firstname'] ?? '').' '.(string) ($parentData['lastname'] ?? ''));
|
||||
}
|
||||
|
||||
private function studentNameData(array $studentdata, array $parentData)
|
||||
{
|
||||
$names = [];
|
||||
foreach ($studentdata as $s) {
|
||||
$nm = !empty($s['name'])
|
||||
$nm = ! empty($s['name'])
|
||||
? trim((string) $s['name'])
|
||||
: trim((string) ($s['firstname'] ?? '') . ' ' . (string) ($s['lastname'] ?? ''));
|
||||
: trim((string) ($s['firstname'] ?? '').' '.(string) ($s['lastname'] ?? ''));
|
||||
if ($nm !== '') {
|
||||
$names[] = $nm;
|
||||
}
|
||||
@@ -299,6 +298,7 @@ class EnrollmentEventService
|
||||
if (count($names) === 1) {
|
||||
return $names[0];
|
||||
}
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
@@ -306,9 +306,9 @@ class EnrollmentEventService
|
||||
{
|
||||
$names = [];
|
||||
foreach ($studentdata as $s) {
|
||||
$nm = !empty($s['name'])
|
||||
$nm = ! empty($s['name'])
|
||||
? trim((string) $s['name'])
|
||||
: trim((string) ($s['firstname'] ?? '') . ' ' . (string) ($s['lastname'] ?? ''));
|
||||
: trim((string) ($s['firstname'] ?? '').' '.(string) ($s['lastname'] ?? ''));
|
||||
if ($nm !== '') {
|
||||
$names[] = $nm;
|
||||
}
|
||||
@@ -321,19 +321,20 @@ class EnrollmentEventService
|
||||
return $names[0];
|
||||
}
|
||||
if (count($names) === 2) {
|
||||
return $names[0] . ' and ' . $names[1];
|
||||
return $names[0].' and '.$names[1];
|
||||
}
|
||||
$last = array_pop($names);
|
||||
return implode(', ', $names) . ', and ' . $last;
|
||||
|
||||
return implode(', ', $names).', and '.$last;
|
||||
}
|
||||
|
||||
private function studentDetails(array $studentdata): array
|
||||
{
|
||||
$details = [];
|
||||
foreach ($studentdata as $s) {
|
||||
$nm = !empty($s['name'])
|
||||
$nm = ! empty($s['name'])
|
||||
? trim((string) $s['name'])
|
||||
: trim((string) ($s['firstname'] ?? '') . ' ' . (string) ($s['lastname'] ?? ''));
|
||||
: trim((string) ($s['firstname'] ?? '').' '.(string) ($s['lastname'] ?? ''));
|
||||
if ($nm === '') {
|
||||
continue;
|
||||
}
|
||||
@@ -345,6 +346,7 @@ class EnrollmentEventService
|
||||
'startDate' => $s['start_date'] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
@@ -352,9 +354,9 @@ class EnrollmentEventService
|
||||
{
|
||||
$withdrawals = [];
|
||||
foreach ($studentdata as $s) {
|
||||
$nm = !empty($s['name'])
|
||||
$nm = ! empty($s['name'])
|
||||
? trim((string) $s['name'])
|
||||
: trim((string) ($s['firstname'] ?? '') . ' ' . (string) ($s['lastname'] ?? ''));
|
||||
: trim((string) ($s['firstname'] ?? '').' '.(string) ($s['lastname'] ?? ''));
|
||||
if ($nm === '') {
|
||||
continue;
|
||||
}
|
||||
@@ -366,6 +368,7 @@ class EnrollmentEventService
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $withdrawals;
|
||||
}
|
||||
|
||||
@@ -373,9 +376,9 @@ class EnrollmentEventService
|
||||
{
|
||||
$rows = [];
|
||||
foreach ($studentdata as $s) {
|
||||
$nm = !empty($s['name'])
|
||||
$nm = ! empty($s['name'])
|
||||
? trim((string) $s['name'])
|
||||
: trim((string) ($s['firstname'] ?? '') . ' ' . (string) ($s['lastname'] ?? ''));
|
||||
: trim((string) ($s['firstname'] ?? '').' '.(string) ($s['lastname'] ?? ''));
|
||||
if ($nm === '') {
|
||||
continue;
|
||||
}
|
||||
@@ -384,6 +387,7 @@ class EnrollmentEventService
|
||||
'reason' => $s['reason'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
@@ -399,13 +403,15 @@ class EnrollmentEventService
|
||||
{
|
||||
if ($to === '') {
|
||||
Log::warning('Enrollment event: missing recipient email', ['subject' => $subject]);
|
||||
|
||||
return ['ok' => false, 'message' => 'Missing recipient email.'];
|
||||
}
|
||||
|
||||
$ok = $this->emailService->send($to, $subject, $html, $fromKey);
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
Log::error('Enrollment event email failed', ['to' => $to, 'subject' => $subject]);
|
||||
}
|
||||
|
||||
return ['ok' => $ok];
|
||||
}
|
||||
|
||||
@@ -413,6 +419,6 @@ class EnrollmentEventService
|
||||
{
|
||||
Log::debug('Skipping Blade email template', ['view' => $viewName]);
|
||||
|
||||
return '<p>' . e($fallbackTitle) . '</p>';
|
||||
return '<p>'.e($fallbackTitle).'</p>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,21 @@ class PaymentEventService
|
||||
private EmailService $emailService,
|
||||
private UserNotificationDispatchService $notifier,
|
||||
private ApplicationUrlService $urls,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
public function paymentReceived(array $data, array $studentdata = []): array
|
||||
{
|
||||
$parentName = trim((string) ($data['firstname'] ?? '') . ' ' . (string) ($data['lastname'] ?? ''));
|
||||
$parentName = trim((string) ($data['firstname'] ?? '').' '.(string) ($data['lastname'] ?? ''));
|
||||
|
||||
$fmtMoney = static fn ($v) => '$' . number_format((float) $v, 2);
|
||||
$fmtMoney = static fn ($v) => '$'.number_format((float) $v, 2);
|
||||
$fmtDateTz = static function (?string $s): string {
|
||||
if (!$s) {
|
||||
if (! $s) {
|
||||
return '';
|
||||
}
|
||||
$dt = new \DateTime($s, new \DateTimeZone('UTC'));
|
||||
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
|
||||
$dt->setTimezone(new \DateTimeZone($tzName ?: 'UTC'));
|
||||
|
||||
return $dt->format('m-d-Y h:i A');
|
||||
};
|
||||
|
||||
@@ -94,30 +94,33 @@ class PaymentEventService
|
||||
|
||||
public function extraCharge(array $data, array $studentdata = []): array
|
||||
{
|
||||
$fmtMoney = static fn ($v) => '$' . number_format((float) $v, 2);
|
||||
$fmtMoney = static fn ($v) => '$'.number_format((float) $v, 2);
|
||||
$fmtFromUtc = static function (?string $s, string $fmt = 'm-d-Y h:i A'): string {
|
||||
if (!$s) {
|
||||
if (! $s) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
$dt = new \DateTime($s, new \DateTimeZone('UTC'));
|
||||
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
|
||||
$dt->setTimezone(new \DateTimeZone($tzName ?: 'UTC'));
|
||||
|
||||
return $dt->format($fmt);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('extraCharge date error: ' . $e->getMessage());
|
||||
Log::error('extraCharge date error: '.$e->getMessage());
|
||||
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
$fmtDueLocal = static function (?string $s): string {
|
||||
if (!$s) {
|
||||
if (! $s) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
if (strlen($s) <= 10) {
|
||||
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
|
||||
$dt = \DateTime::createFromFormat('Y-m-d', $s, new \DateTimeZone($tzName ?: 'UTC'));
|
||||
|
||||
return $dt ? $dt->format('m-d-Y') : '';
|
||||
}
|
||||
|
||||
@@ -125,19 +128,22 @@ class PaymentEventService
|
||||
$dt = new \DateTime($s);
|
||||
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
|
||||
$dt->setTimezone(new \DateTimeZone($tzName ?: 'UTC'));
|
||||
|
||||
return $dt->format('m-d-Y h:i A');
|
||||
}
|
||||
|
||||
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
|
||||
$dt = new \DateTime($s, new \DateTimeZone($tzName ?: 'UTC'));
|
||||
|
||||
return $dt->format('m-d-Y h:i A');
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('extraCharge due date error: ' . $e->getMessage());
|
||||
Log::error('extraCharge due date error: '.$e->getMessage());
|
||||
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
$parentName = trim((string) ($data['firstname'] ?? '') . ' ' . (string) ($data['lastname'] ?? ''));
|
||||
$parentName = trim((string) ($data['firstname'] ?? '').' '.(string) ($data['lastname'] ?? ''));
|
||||
|
||||
$amountSigned = (float) ($data['amount_signed'] ?? 0);
|
||||
$amountAbs = (float) ($data['amount_abs'] ?? abs($amountSigned));
|
||||
@@ -189,6 +195,7 @@ class PaymentEventService
|
||||
);
|
||||
|
||||
$body = $this->renderEmail('emails/extra_charge_notice', $emailData, 'Account Charge Update');
|
||||
|
||||
return $this->sendEmail((string) ($data['email'] ?? ''), $subject, $body, 'billing');
|
||||
}
|
||||
|
||||
@@ -204,13 +211,15 @@ class PaymentEventService
|
||||
{
|
||||
if ($to === '') {
|
||||
Log::warning('Payment event missing recipient email', ['subject' => $subject]);
|
||||
|
||||
return ['ok' => false, 'message' => 'Missing recipient email.'];
|
||||
}
|
||||
|
||||
$ok = $this->emailService->send($to, $subject, $html, $fromKey);
|
||||
if (!$ok) {
|
||||
if (! $ok) {
|
||||
Log::error('Payment event email failed', ['to' => $to, 'subject' => $subject]);
|
||||
}
|
||||
|
||||
return ['ok' => $ok];
|
||||
}
|
||||
|
||||
@@ -218,6 +227,6 @@ class PaymentEventService
|
||||
{
|
||||
Log::debug('Skipping Blade email template', ['view' => $viewName]);
|
||||
|
||||
return '<p>' . e($fallbackTitle) . '</p>';
|
||||
return '<p>'.e($fallbackTitle).'</p>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user