add controllers, servoices

This commit is contained in:
root
2026-03-09 02:52:13 -04:00
parent c8de5f7edc
commit d76c871cb7
501 changed files with 34439 additions and 21843 deletions
@@ -0,0 +1,38 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoiceConfigServiceTest extends TestCase
{
use RefreshDatabase;
public function test_config_service_reads_values(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
['config_key' => 'due_date', 'config_value' => '2025-09-01'],
['config_key' => 'grade_fee', 'config_value' => '9'],
['config_key' => 'first_student_fee', 'config_value' => '350'],
['config_key' => 'second_student_fee', 'config_value' => '200'],
['config_key' => 'youth_fee', 'config_value' => '180'],
['config_key' => 'refund_deadline', 'config_value' => '2025-10-01'],
]);
$service = new InvoiceConfigService();
$this->assertSame('2025-2026', $service->getSchoolYear());
$this->assertSame('Fall', $service->getSemester());
$this->assertSame('2025-09-01', $service->getDueDate());
$this->assertSame(9, $service->getGradeFee());
$this->assertSame(350.0, $service->getFirstStudentFee());
$this->assertSame(200.0, $service->getSecondStudentFee());
$this->assertSame(180.0, $service->getYouthFee());
$this->assertSame('2025-10-01', $service->getRefundDeadline());
}
}
@@ -0,0 +1,92 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoiceGenerationService;
use App\Services\Invoices\InvoiceGradeService;
use App\Services\Invoices\InvoiceTuitionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoiceGenerationServiceTest extends TestCase
{
use RefreshDatabase;
public function test_generate_invoice_creates_new_invoice(): void
{
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
'id' => 100,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'is_active' => 1,
]);
DB::table('classSection')->insert([
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
DB::table('enrollments')->insert([
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_status' => 'enrolled',
'school_year' => '2025-2026',
]);
$config = new InvoiceConfigService();
$grades = new InvoiceGradeService($config->getGradeFee());
$tuition = new InvoiceTuitionService(
$grades,
$config->getGradeFee(),
$config->getFirstStudentFee(),
$config->getSecondStudentFee(),
$config->getYouthFee(),
$config->getTimezone()
);
$service = new InvoiceGenerationService($config, $tuition);
$result = $service->generateInvoice(10, '2025-2026');
$this->assertTrue($result['ok']);
$this->assertNotNull($result['insert_id']);
$this->assertDatabaseHas('invoices', [
'id' => $result['insert_id'],
'parent_id' => 10,
'school_year' => '2025-2026',
]);
}
}
@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceGradeService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class InvoiceGradeServiceTest extends TestCase
{
use RefreshDatabase;
public function test_grade_parsing_handles_common_cases(): void
{
$service = new InvoiceGradeService(9);
$this->assertTrue($service->isKindergarten('KG'));
$this->assertSame(1, $service->gradeLevelInt('K'));
$this->assertSame(-1, $service->gradeLevelInt('PK'));
$this->assertSame(10, $service->gradeLevelInt('Youth'));
$this->assertSame(5, $service->gradeLevelInt('Grade 5'));
$info = $service->getGradeLevel('5A');
$this->assertSame(5, $info['level']);
$this->assertSame('A', $info['suffix']);
}
public function test_compare_grades_orders_numeric_then_suffix(): void
{
$service = new InvoiceGradeService(9);
$this->assertSame(-1, $service->compareGrades('1', '2'));
$this->assertSame(1, $service->compareGrades('2', '1'));
$this->assertSame(-1, $service->compareGrades('2A', '2B'));
$this->assertSame(0, $service->compareGrades('K', 'K'));
}
}
@@ -0,0 +1,107 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoiceManagementService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoiceManagementServiceTest extends TestCase
{
use RefreshDatabase;
public function test_management_data_returns_parent_invoice_summary(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('user_roles')->insert([
'user_id' => 10,
'role_id' => 1,
]);
DB::table('students')->insert([
'id' => 100,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'is_active' => 1,
]);
DB::table('classSection')->insert([
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
DB::table('enrollments')->insert([
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_status' => 'enrolled',
'school_year' => '2025-2026',
]);
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 100,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-10',
'status' => 'unpaid',
'school_year' => '2025-2026',
]);
DB::table('refunds')->insert([
'id' => 1,
'parent_id' => 10,
'school_year' => '2025-2026',
'invoice_id' => 1,
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
]);
$service = new InvoiceManagementService(new InvoiceConfigService());
$data = $service->getManagementData('2025-2026');
$this->assertSame('2025-2026', $data['schoolYear']);
$this->assertCount(1, $data['invoices']);
$this->assertSame(5.0, $data['invoices'][0]['refund_amount']);
}
}
@@ -0,0 +1,63 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoicePaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoicePaymentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_parent_invoice_summary_includes_refunds_and_last_payment(): void
{
DB::table('invoices')->insert([
[
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 40,
'paid_amount' => 60,
'has_discount' => 0,
'issue_date' => '2025-01-10',
'status' => 'unpaid',
'school_year' => '2025-2026',
],
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 60,
'balance' => 40,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-01-15',
'school_year' => '2025-2026',
'status' => 'Paid',
]);
DB::table('refunds')->insert([
'id' => 1,
'parent_id' => 10,
'school_year' => '2025-2026',
'invoice_id' => 1,
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
]);
$service = new InvoicePaymentService(new InvoiceConfigService());
$data = $service->getParentInvoiceSummary(10, '2025-2026');
$this->assertSame('2025-2026', $data['selectedYear']);
$this->assertSame(5.0, $data['invoices'][0]['refund_amount']);
$this->assertSame(60.0, $data['invoices'][0]['last_paid_amount']);
}
}
@@ -0,0 +1,91 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoiceGradeService;
use App\Services\Invoices\InvoicePdfService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoicePdfServiceTest extends TestCase
{
use RefreshDatabase;
public function test_build_pdf_returns_bytes(): void
{
DB::table('users')->insert([
'id' => 10,
'school_id' => 1,
'firstname' => 'Parent',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'parent@example.com',
'address_street' => '123 Main',
'city' => 'City',
'state' => 'ST',
'zip' => '12345',
'accept_school_policy' => 1,
'is_verified' => 1,
'status' => 'Active',
'is_suspended' => 0,
'failed_attempts' => 0,
'password' => bcrypt('secret'),
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
DB::table('students')->insert([
'id' => 100,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'is_active' => 1,
]);
DB::table('classSection')->insert([
'class_section_id' => 1,
'class_section_name' => '1A',
'class_id' => 1,
]);
DB::table('student_class')->insert([
'student_id' => 100,
'class_section_id' => 1,
'school_year' => '2025-2026',
'is_event_only' => 0,
]);
DB::table('enrollments')->insert([
'student_id' => 100,
'parent_id' => 10,
'class_section_id' => 1,
'enrollment_status' => 'enrolled',
'school_year' => '2025-2026',
]);
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 100,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-10',
'status' => 'unpaid',
'school_year' => '2025-2026',
]);
$config = new InvoiceConfigService();
$grades = new InvoiceGradeService($config->getGradeFee());
$service = new InvoicePdfService($config, $grades);
$pdf = $service->buildPdf(1);
$this->assertIsString($pdf);
$this->assertNotSame('', $pdf);
}
}
@@ -0,0 +1,60 @@
<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceGradeService;
use App\Services\Invoices\InvoiceTuitionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoiceTuitionServiceTest extends TestCase
{
use RefreshDatabase;
public function test_calculate_tuition_fee_counts_regular_and_youth(): void
{
DB::table('classSection')->insert([
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2],
['class_section_id' => 3, 'class_section_name' => '10', 'class_id' => 10],
]);
$grades = new InvoiceGradeService(9);
$service = new InvoiceTuitionService($grades, 9, 350.0, 200.0, 180.0, 'UTC');
$registeredKids = [
['class_section_id' => 1],
['class_section_id' => 2],
['class_section_id' => 3],
];
$total = $service->calculateTuitionFee($registeredKids, [], date('Y-m-d', strtotime('+10 days')));
$this->assertSame(730.0, $total);
}
public function test_refund_deadline_includes_withdrawn_when_passed(): void
{
DB::table('classSection')->insert([
['class_section_id' => 1, 'class_section_name' => '1', 'class_id' => 1],
['class_section_id' => 2, 'class_section_name' => '2', 'class_id' => 2],
]);
$grades = new InvoiceGradeService(9);
$service = new InvoiceTuitionService($grades, 9, 350.0, 200.0, 180.0, 'UTC');
$registeredKids = [
['class_section_id' => 1],
];
$withdrawnKids = [
['class_section_id' => 2],
];
$totalAllowed = $service->calculateTuitionFee($registeredKids, $withdrawnKids, date('Y-m-d', strtotime('+10 days')));
$totalBlocked = $service->calculateTuitionFee($registeredKids, $withdrawnKids, date('Y-m-d', strtotime('-10 days')));
$this->assertSame(350.0, $totalAllowed);
$this->assertSame(550.0, $totalBlocked);
}
}