update api and add more features
This commit is contained in:
@@ -16,54 +16,12 @@ class FeeRefundCalculatorServiceTest extends TestCase
|
||||
|
||||
public function test_calculate_refund_caps_at_total_paid(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-02-01'],
|
||||
['config_key' => 'weeks_study', 'config_value' => '8'],
|
||||
['config_key' => 'last_school_day', 'config_value' => '2025-06-01'],
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(101, '3');
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '3',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
$this->seedInvoiceAndPayment(99, 100.00);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 99,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => 100.00,
|
||||
'issue_date' => '2025-01-01',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 99,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 100.00,
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'number_of_installments' => 1,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new FeeRefundCalculatorService(
|
||||
new FeeConfigService(),
|
||||
new FeeStudentFeeService(new FeeGradeService(), new FeeConfigService())
|
||||
);
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
@@ -76,5 +34,249 @@ class FeeRefundCalculatorServiceTest extends TestCase
|
||||
], 99);
|
||||
|
||||
$this->assertSame(100.0, $result['refund_amount']);
|
||||
$this->assertSame(1, $result['withdrawn_students']);
|
||||
$this->assertCount(1, $result['students']);
|
||||
$this->assertTrue($result['students'][0]['eligible']);
|
||||
$this->assertSame(350.0, $result['students'][0]['tuition_fee']);
|
||||
}
|
||||
|
||||
public function test_returns_zero_when_parent_has_no_payments(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(101, '3');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
], 12345);
|
||||
|
||||
$this->assertSame(0.0, $result['refund_amount']);
|
||||
$this->assertSame(0, $result['withdrawn_students']);
|
||||
$this->assertSame([], $result['students']);
|
||||
}
|
||||
|
||||
public function test_returns_zero_when_no_withdrawn_students(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(101, '3');
|
||||
$this->seedInvoiceAndPayment(50, 500.00);
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
], 50);
|
||||
|
||||
$this->assertSame(0.0, $result['refund_amount']);
|
||||
$this->assertSame(0, $result['withdrawn_students']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plan section 8 regression: each withdrawn student must carry the
|
||||
* tuition fee that was assigned during fee calculation, otherwise the
|
||||
* refund loop silently produces $0 for any student whose id does not
|
||||
* round-trip through the lookup map.
|
||||
*/
|
||||
public function test_withdrawn_student_breakdown_carries_assigned_tuition_fee(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(201, '4');
|
||||
$this->seedClassSection(202, '5');
|
||||
$this->seedInvoiceAndPayment(77, 1000.00);
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 10,
|
||||
'class_section_id' => 201,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 11,
|
||||
'class_section_id' => 202,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
], 77);
|
||||
|
||||
$this->assertCount(1, $result['students']);
|
||||
$withdrawn = $result['students'][0];
|
||||
$this->assertSame(11, $withdrawn['student_id']);
|
||||
// First regular = $350 (grade 4), additional = $200 (grade 5) -> the
|
||||
// withdrawn 5th-grader is the additional regular student and must
|
||||
// refund using $200, not $0 or a stale lookup value.
|
||||
$this->assertSame(200.0, $withdrawn['tuition_fee']);
|
||||
$this->assertSame('additional_regular', $withdrawn['fee_category']);
|
||||
$this->assertGreaterThan(0, $withdrawn['refund_amount']);
|
||||
$this->assertTrue($withdrawn['eligible']);
|
||||
}
|
||||
|
||||
public function test_multi_student_family_only_refunds_withdrawn_students(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(301, '2');
|
||||
$this->seedClassSection(302, '6');
|
||||
$this->seedClassSection(303, '10');
|
||||
$this->seedInvoiceAndPayment(88, 1000.00);
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 21,
|
||||
'class_section_id' => 301,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 22,
|
||||
'class_section_id' => 302,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
[
|
||||
'student_id' => 23,
|
||||
'class_section_id' => 303,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
], 88);
|
||||
|
||||
$this->assertCount(2, $result['students']);
|
||||
$this->assertSame(2, $result['withdrawn_students']);
|
||||
|
||||
$byStudent = [];
|
||||
foreach ($result['students'] as $row) {
|
||||
$byStudent[$row['student_id']] = $row;
|
||||
}
|
||||
|
||||
$this->assertSame('additional_regular', $byStudent[22]['fee_category']);
|
||||
$this->assertSame(200.0, $byStudent[22]['tuition_fee']);
|
||||
|
||||
$this->assertSame('youth', $byStudent[23]['fee_category']);
|
||||
$this->assertSame(180.0, $byStudent[23]['tuition_fee']);
|
||||
|
||||
$sumPerStudent = round(array_sum(array_column($result['students'], 'refund_amount')), 2);
|
||||
$this->assertSame($result['refund_amount'], $sumPerStudent);
|
||||
}
|
||||
|
||||
public function test_withdrawal_after_deadline_is_not_eligible(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(401, '3');
|
||||
$this->seedInvoiceAndPayment(33, 500.00);
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 401,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
'withdrawal_date' => '2025-03-01',
|
||||
],
|
||||
], 33);
|
||||
|
||||
$this->assertSame(0.0, $result['refund_amount']);
|
||||
$this->assertCount(1, $result['students']);
|
||||
$this->assertFalse($result['students'][0]['eligible']);
|
||||
$this->assertSame('after_refund_deadline', $result['students'][0]['reason']);
|
||||
}
|
||||
|
||||
public function test_missing_withdrawal_date_is_skipped_with_reason(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(501, '3');
|
||||
$this->seedInvoiceAndPayment(44, 500.00);
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculateRefund([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 501,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
], 44);
|
||||
|
||||
$this->assertSame(0.0, $result['refund_amount']);
|
||||
$this->assertSame('missing_withdrawal_date', $result['students'][0]['reason']);
|
||||
}
|
||||
|
||||
private function makeService(): FeeRefundCalculatorService
|
||||
{
|
||||
return new FeeRefundCalculatorService(
|
||||
new FeeConfigService(),
|
||||
new FeeStudentFeeService(new FeeGradeService(), new FeeConfigService())
|
||||
);
|
||||
}
|
||||
|
||||
private function seedFeeConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-02-01'],
|
||||
['config_key' => 'weeks_study', 'config_value' => '8'],
|
||||
['config_key' => 'last_school_day', 'config_value' => '2025-06-01'],
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedClassSection(int $sectionId, string $gradeName): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => $sectionId,
|
||||
'class_section_id' => $sectionId,
|
||||
'class_section_name' => $gradeName,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedInvoiceAndPayment(int $parentId, float $amount): void
|
||||
{
|
||||
$invoiceId = DB::table('invoices')->insertGetId([
|
||||
'parent_id' => $parentId,
|
||||
'invoice_number' => 'INV-' . $parentId,
|
||||
'total_amount' => $amount,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => $amount,
|
||||
'issue_date' => '2025-01-01',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'parent_id' => $parentId,
|
||||
'invoice_id' => $invoiceId,
|
||||
'paid_amount' => $amount,
|
||||
'total_amount' => $amount,
|
||||
'balance' => 0.00,
|
||||
'number_of_installments' => 1,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,32 +15,11 @@ class FeeStudentFeeServiceTest extends TestCase
|
||||
|
||||
public function test_total_tuition_fee_applies_tiers_and_youth_fee(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(101, '3');
|
||||
$this->seedClassSection(102, '10');
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '3',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'class_id' => 2,
|
||||
'class_section_id' => 102,
|
||||
'class_section_name' => '10',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new FeeStudentFeeService(new FeeGradeService(), new FeeConfigService());
|
||||
$service = $this->makeService();
|
||||
|
||||
$total = $service->totalTuitionFee([
|
||||
['class_section_id' => 101],
|
||||
@@ -49,4 +28,136 @@ class FeeStudentFeeServiceTest extends TestCase
|
||||
|
||||
$this->assertSame(530.0, $total);
|
||||
}
|
||||
|
||||
public function test_assign_fees_stores_tuition_fee_and_fee_category_on_each_student(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(101, '2');
|
||||
$this->seedClassSection(102, '5');
|
||||
$this->seedClassSection(103, '10');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$assigned = $service->assignFees([
|
||||
['student_id' => 1, 'class_section_id' => 101],
|
||||
['student_id' => 2, 'class_section_id' => 102],
|
||||
['student_id' => 3, 'class_section_id' => 103],
|
||||
]);
|
||||
|
||||
$byId = [];
|
||||
foreach ($assigned as $row) {
|
||||
$byId[$row['student_id']] = $row;
|
||||
}
|
||||
|
||||
$this->assertSame(350.0, $byId[1]['tuition_fee']);
|
||||
$this->assertSame('first_regular', $byId[1]['fee_category']);
|
||||
|
||||
$this->assertSame(200.0, $byId[2]['tuition_fee']);
|
||||
$this->assertSame('additional_regular', $byId[2]['fee_category']);
|
||||
|
||||
$this->assertSame(180.0, $byId[3]['tuition_fee']);
|
||||
$this->assertSame('youth', $byId[3]['fee_category']);
|
||||
}
|
||||
|
||||
public function test_calculate_breakdown_includes_billable_and_non_billable_students(): void
|
||||
{
|
||||
$this->seedFeeConfig();
|
||||
$this->seedClassSection(201, '3');
|
||||
$this->seedClassSection(202, '4');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$breakdown = $service->calculateBreakdown([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'firstname' => 'Ada',
|
||||
'lastname' => 'L',
|
||||
'class_section_id' => 201,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'firstname' => 'Bo',
|
||||
'lastname' => 'L',
|
||||
'class_section_id' => 202,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 3,
|
||||
'firstname' => 'Cy',
|
||||
'lastname' => 'L',
|
||||
'class_section_id' => 201,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'pending',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(350.0, $breakdown['family_total']);
|
||||
$this->assertSame(1, $breakdown['billable_count']);
|
||||
$this->assertSame(2, $breakdown['non_billable_count']);
|
||||
$this->assertCount(3, $breakdown['students']);
|
||||
|
||||
$byId = [];
|
||||
foreach ($breakdown['students'] as $row) {
|
||||
$byId[$row['student_id']] = $row;
|
||||
}
|
||||
|
||||
$this->assertSame('first_regular', $byId[1]['fee_category']);
|
||||
$this->assertSame(350.0, $byId[1]['tuition_fee']);
|
||||
|
||||
$this->assertSame('not_billable', $byId[2]['fee_category']);
|
||||
$this->assertSame(0.0, $byId[2]['tuition_fee']);
|
||||
|
||||
$this->assertSame('not_billable', $byId[3]['fee_category']);
|
||||
}
|
||||
|
||||
public function test_is_billable_and_is_withdrawn_classifiers(): void
|
||||
{
|
||||
$service = $this->makeService();
|
||||
|
||||
$this->assertTrue($service->isBillable([
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
]));
|
||||
$this->assertTrue($service->isBillable([
|
||||
'enrollment_status' => 'payment pending',
|
||||
'admission_status' => 'accepted',
|
||||
]));
|
||||
$this->assertFalse($service->isBillable([
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'pending',
|
||||
]));
|
||||
|
||||
$this->assertTrue($service->isWithdrawn(['enrollment_status' => 'withdrawn']));
|
||||
$this->assertTrue($service->isWithdrawn(['enrollment_status' => 'refund pending']));
|
||||
$this->assertTrue($service->isWithdrawn(['enrollment_status' => 'withdraw under review']));
|
||||
$this->assertFalse($service->isWithdrawn(['enrollment_status' => 'enrolled']));
|
||||
}
|
||||
|
||||
private function makeService(): FeeStudentFeeService
|
||||
{
|
||||
return new FeeStudentFeeService(new FeeGradeService(), new FeeConfigService());
|
||||
}
|
||||
|
||||
private function seedFeeConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedClassSection(int $sectionId, string $gradeName): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => $sectionId,
|
||||
'class_section_id' => $sectionId,
|
||||
'class_section_name' => $gradeName,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Fees;
|
||||
|
||||
use App\Services\Fees\FeeConfigService;
|
||||
use App\Services\Fees\FeeGradeService;
|
||||
use App\Services\Fees\FeeStudentFeeService;
|
||||
use App\Services\Fees\TuitionCalculationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TuitionCalculationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_calculate_returns_family_total_and_per_student_breakdown(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$this->seedClassSection(101, '2');
|
||||
$this->seedClassSection(102, '5');
|
||||
$this->seedClassSection(103, '11');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculate([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'firstname' => 'Anna',
|
||||
'lastname' => 'Doe',
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 2,
|
||||
'firstname' => 'Ben',
|
||||
'lastname' => 'Doe',
|
||||
'class_section_id' => 102,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 3,
|
||||
'firstname' => 'Cara',
|
||||
'lastname' => 'Doe',
|
||||
'class_section_id' => 103,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame('2025-2026', $result['school_year']);
|
||||
$this->assertSame(3, $result['billable_count']);
|
||||
$this->assertSame(0, $result['non_billable_count']);
|
||||
$this->assertSame(730.0, $result['family_total']);
|
||||
|
||||
$byStudent = [];
|
||||
foreach ($result['students'] as $row) {
|
||||
$byStudent[$row['student_id']] = $row;
|
||||
}
|
||||
|
||||
$this->assertSame('first_regular', $byStudent[1]['fee_category']);
|
||||
$this->assertSame(350.0, $byStudent[1]['tuition_fee']);
|
||||
$this->assertSame('Anna Doe', $byStudent[1]['student_name']);
|
||||
|
||||
$this->assertSame('additional_regular', $byStudent[2]['fee_category']);
|
||||
$this->assertSame(200.0, $byStudent[2]['tuition_fee']);
|
||||
|
||||
$this->assertSame('youth', $byStudent[3]['fee_category']);
|
||||
$this->assertSame(180.0, $byStudent[3]['tuition_fee']);
|
||||
}
|
||||
|
||||
public function test_calculate_excludes_non_billable_students_from_family_total(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$this->seedClassSection(201, '3');
|
||||
$this->seedClassSection(202, '4');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculate([
|
||||
[
|
||||
'student_id' => 10,
|
||||
'class_section_id' => 201,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
[
|
||||
'student_id' => 11,
|
||||
'class_section_id' => 202,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(1, $result['billable_count']);
|
||||
$this->assertSame(1, $result['non_billable_count']);
|
||||
$this->assertSame(350.0, $result['family_total']);
|
||||
|
||||
$byStudent = [];
|
||||
foreach ($result['students'] as $row) {
|
||||
$byStudent[$row['student_id']] = $row;
|
||||
}
|
||||
|
||||
$this->assertSame('not_billable', $byStudent[11]['fee_category']);
|
||||
$this->assertSame(0.0, $byStudent[11]['tuition_fee']);
|
||||
}
|
||||
|
||||
public function test_calculate_applies_per_student_discount(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$this->seedClassSection(301, '2');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$result = $service->calculate([
|
||||
[
|
||||
'student_id' => 99,
|
||||
'class_section_id' => 301,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
'discount_amount' => 100.0,
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(250.0, $result['family_total']);
|
||||
$this->assertSame(100.0, $result['students'][0]['discount_amount']);
|
||||
$this->assertSame(250.0, $result['students'][0]['final_tuition_amount']);
|
||||
}
|
||||
|
||||
public function test_family_total_helper(): void
|
||||
{
|
||||
$this->seedConfig();
|
||||
$this->seedClassSection(401, '3');
|
||||
|
||||
$service = $this->makeService();
|
||||
|
||||
$this->assertSame(350.0, $service->familyTotal([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 401,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'admission_status' => 'accepted',
|
||||
],
|
||||
]));
|
||||
}
|
||||
|
||||
private function makeService(): TuitionCalculationService
|
||||
{
|
||||
$config = new FeeConfigService();
|
||||
return new TuitionCalculationService(
|
||||
$config,
|
||||
new FeeStudentFeeService(new FeeGradeService(), $config)
|
||||
);
|
||||
}
|
||||
|
||||
private function seedConfig(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
['config_key' => 'youth_fee', 'config_value' => '180'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedClassSection(int $sectionId, string $gradeName): void
|
||||
{
|
||||
DB::table('classSection')->insert([
|
||||
'class_id' => $sectionId,
|
||||
'class_section_id' => $sectionId,
|
||||
'class_section_name' => $gradeName,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user