add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
@@ -8,6 +8,7 @@ use App\Models\ParentAccount;
use App\Models\ParentBalanceTransfer;
use App\Models\SchoolYear;
use App\Services\Promotions\LevelProgressionService;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Validation\ValidationException;
@@ -18,7 +19,8 @@ class SchoolYearClosureService
public function __construct(
private SchoolYearResolver $resolver,
private LevelProgressionService $progression
) {}
) {
}
public function list(): array
{
@@ -233,7 +235,7 @@ class SchoolYearClosureService
{
$year = $this->findOrFail($id);
$validation = $this->validateClose($id, $payload);
if (! $validation['can_close']) {
if (!$validation['can_close']) {
throw ValidationException::withMessages(['school_year' => $validation['errors']]);
}
@@ -247,7 +249,7 @@ class SchoolYearClosureService
$newYearPayload = $payload['new_school_year'];
$promotionPreview = $this->buildPromotionPreview($year->name, $newYearPayload['name']);
$balances = ! empty($payload['transfer_unpaid_balances'])
$balances = !empty($payload['transfer_unpaid_balances'])
? $this->buildParentBalanceRows($year->name, $newYearPayload['name'])
: ['rows' => [], 'summary' => ['net_balance_to_transfer' => 0]];
@@ -289,7 +291,7 @@ class SchoolYearClosureService
Configuration::setConfigValueByKey('school_year', $newYear->name);
$promotionCounts = $this->applyPromotions($promotionPreview['rows'], $newYear->name, $newYear->start_date, $actorId);
$balanceCounts = ! empty($payload['transfer_unpaid_balances'])
$balanceCounts = !empty($payload['transfer_unpaid_balances'])
? $this->applyBalanceTransfers($balances['rows'], $year->name, $newYear->name, $actorId)
: [
'transferred_parents' => 0,
@@ -394,9 +396,8 @@ class SchoolYearClosureService
$errors[] = 'New school year name is required.';
}
if (! $startDate || ! $endDate) {
if (!$startDate || !$endDate) {
$errors[] = 'New school year start_date and end_date are required.';
return $errors;
}
@@ -456,7 +457,7 @@ class SchoolYearClosureService
];
foreach ($tables as $mapping) {
if (! Schema::hasTable($mapping['table'])) {
if (!Schema::hasTable($mapping['table'])) {
continue;
}
if (DB::table($mapping['table'])->where($mapping['column'], $schoolYear)->exists()) {
@@ -489,7 +490,7 @@ class SchoolYearClosureService
$assignmentByStudent = [];
foreach ($assignments as $assignment) {
$studentId = (int) $assignment->student_id;
if (! isset($assignmentByStudent[$studentId])) {
if (!isset($assignmentByStudent[$studentId])) {
$assignmentByStudent[$studentId] = $assignment;
}
}
@@ -505,7 +506,7 @@ class SchoolYearClosureService
$enrollmentByStudent = [];
foreach ($enrollments as $enrollment) {
$studentId = (int) $enrollment->student_id;
if (! isset($enrollmentByStudent[$studentId])) {
if (!isset($enrollmentByStudent[$studentId])) {
$enrollmentByStudent[$studentId] = $enrollment;
}
}
@@ -520,7 +521,7 @@ class SchoolYearClosureService
$decisionByStudent = [];
foreach ($decisions as $decision) {
$studentId = (int) $decision->student_id;
if (! isset($decisionByStudent[$studentId])) {
if (!isset($decisionByStudent[$studentId])) {
$decisionByStudent[$studentId] = $decision;
}
}
@@ -538,7 +539,7 @@ class SchoolYearClosureService
foreach ($studentIds as $studentId) {
$student = $students->get($studentId);
if (! $student) {
if (!$student) {
continue;
}
@@ -598,7 +599,7 @@ class SchoolYearClosureService
$row = [
'student_id' => $studentId,
'student_name' => trim((string) ($student->firstname ?? '').' '.(string) ($student->lastname ?? '')),
'student_name' => trim((string) ($student->firstname ?? '') . ' ' . (string) ($student->lastname ?? '')),
'parent_id' => (int) ($student->parent_id ?? 0) ?: null,
'current_grade' => $progression['current_level_name'] ?? ($currentClass->class_name ?? null),
'current_class' => $section->class_section_name ?? null,
@@ -644,7 +645,7 @@ class SchoolYearClosureService
? (float) $invoice->balance
: (float) ($invoice->total_amount ?? 0) - (float) ($invoice->paid_amount ?? 0);
if (! isset($byParent[$parentId])) {
if (!isset($byParent[$parentId])) {
$existing = ParentBalanceTransfer::query()
->where('parent_id', $parentId)
->where('from_school_year', $fromSchoolYear)
@@ -736,7 +737,7 @@ class SchoolYearClosureService
->orderBy('class_section_id')
->first();
if (! $section) {
if (!$section) {
return [null, null];
}
@@ -756,13 +757,13 @@ class SchoolYearClosureService
foreach ($rows as $row) {
$action = $row['promotion_action'];
if (! isset($counts[$action])) {
if (!isset($counts[$action])) {
continue;
}
$counts[$action]++;
if (! in_array($action, ['promote', 'repeat'], true)) {
if (!in_array($action, ['promote', 'repeat'], true)) {
$this->logAudit(
$actorId,
'school_year_promotion_decision_applied',
@@ -772,7 +773,6 @@ class SchoolYearClosureService
null,
['action' => $action, 'new_school_year' => $newSchoolYear]
);
continue;
}
@@ -781,7 +781,7 @@ class SchoolYearClosureService
->where('school_year', $newSchoolYear)
->first();
if (! $existingEnrollment) {
if (!$existingEnrollment) {
DB::table('enrollments')->insert([
'student_id' => $row['student_id'],
'class_section_id' => $row['target_class_section_id'],
@@ -805,7 +805,7 @@ class SchoolYearClosureService
->where('class_section_id', $row['target_class_section_id'])
->exists();
if (! $existingAssignment) {
if (!$existingAssignment) {
DB::table('student_class')->insert([
'student_id' => $row['student_id'],
'class_section_id' => $row['target_class_section_id'],
@@ -950,7 +950,7 @@ class SchoolYearClosureService
private function countPendingPayments(string $schoolYear): int
{
if (! Schema::hasTable('payments')) {
if (!Schema::hasTable('payments')) {
return 0;
}
@@ -978,7 +978,7 @@ class SchoolYearClosureService
private function countDuplicateParentAccounts(): int
{
if (! Schema::hasTable('parent_accounts')) {
if (!Schema::hasTable('parent_accounts')) {
return 0;
}
@@ -992,11 +992,11 @@ class SchoolYearClosureService
private function resolveParentName(int $parentId): ?string
{
$row = DB::table('users')->where('id', $parentId)->first();
if (! $row) {
if (!$row) {
return null;
}
return trim((string) ($row->firstname ?? '').' '.(string) ($row->lastname ?? ''));
return trim((string) ($row->firstname ?? '') . ' ' . (string) ($row->lastname ?? ''));
}
private function resolveStudentNames(int $parentId, string $schoolYear): array
@@ -1015,7 +1015,7 @@ class SchoolYearClosureService
return DB::table('students')
->whereIn('id', $studentIds)
->get()
->map(fn ($student) => trim((string) ($student->firstname ?? '').' '.(string) ($student->lastname ?? '')))
->map(fn ($student) => trim((string) ($student->firstname ?? '') . ' ' . (string) ($student->lastname ?? '')))
->filter()
->values()
->all();
@@ -1023,7 +1023,7 @@ class SchoolYearClosureService
private function presentSchoolYear(?SchoolYear $year): ?array
{
if (! $year) {
if (!$year) {
return null;
}
@@ -1048,7 +1048,7 @@ class SchoolYearClosureService
?array $newValue,
?array $metadata = null
): void {
if (! Schema::hasTable('audit_logs')) {
if (!Schema::hasTable('audit_logs')) {
return;
}