update api and add more features

This commit is contained in:
root
2026-06-04 02:24:41 -04:00
parent fa6c9519a0
commit 4e33882ac7
131 changed files with 34596 additions and 340 deletions
@@ -74,9 +74,188 @@ class FeeCalculationControllerTest extends TestCase
'school_end_date',
'weeks_of_study',
'withdrawn_students',
'students' => [
'*' => [
'student_id',
'grade',
'grade_level',
'fee_category',
'tuition_fee',
'withdrawal_date',
'weeks_remaining',
'refund_amount',
'eligible',
'reason',
],
],
],
]);
$this->assertGreaterThan(0, (float) $response->json('refund.refund_amount'));
$this->assertGreaterThan(0, count($response->json('refund.students') ?? []));
}
public function test_tuition_breakdown_endpoint_returns_per_student_detail(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$this->seedConfig();
$this->seedClassSection();
$response = $this->postJson('/api/v1/finance/fees/tuition-breakdown', [
'students' => [
[
'student_id' => 1,
'firstname' => 'Alpha',
'lastname' => 'Last',
'class_section_id' => 101,
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
],
[
'student_id' => 2,
'firstname' => 'Beta',
'lastname' => 'Last',
'class_section_id' => 101,
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
],
],
]);
$response->assertOk();
$response->assertJsonPath('ok', true);
$response->assertJsonStructure([
'ok',
'tuition' => [
'school_year',
'family_total',
'billable_count',
'non_billable_count',
'fees' => ['first_student_fee', 'second_student_fee', 'youth_fee'],
'students' => [
'*' => [
'student_id',
'student_name',
'grade',
'grade_level',
'enrollment_status',
'admission_status',
'fee_category',
'tuition_fee',
'discount_amount',
'final_tuition_amount',
],
],
],
]);
$this->assertSame(550.0, (float) $response->json('tuition.family_total'));
$this->assertSame(2, (int) $response->json('tuition.billable_count'));
}
public function test_tuition_breakdown_endpoint_requires_authentication(): void
{
$response = $this->postJson('/api/v1/finance/fees/tuition-breakdown', [
'students' => [
['class_section_id' => 101],
],
]);
$response->assertStatus(401);
}
public function test_tuition_breakdown_endpoint_validates_payload(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/finance/fees/tuition-breakdown', [
'students' => [],
]);
$response->assertStatus(422);
$response->assertJsonStructure(['message', 'errors']);
}
public function test_family_balance_endpoint_returns_account_summary(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
$this->seedConfig();
$this->seedClassSection();
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-1',
'total_amount' => 500.00,
'balance' => 0.00,
'paid_amount' => 200.00,
'has_discount' => 0,
'issue_date' => '2025-01-05',
'status' => 'paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'paid_amount' => 200.00,
'total_amount' => 200.00,
'balance' => 0.00,
'number_of_installments' => 1,
'payment_date' => '2025-01-10',
'payment_method' => 'manual',
'school_year' => '2025-2026',
'status' => 'Paid',
]);
$response = $this->postJson('/api/v1/finance/fees/family-balance', [
'parent_id' => 10,
'students' => [
[
'student_id' => 1,
'class_section_id' => 101,
'enrollment_status' => 'enrolled',
'admission_status' => 'accepted',
],
],
]);
$response->assertOk();
$response->assertJsonPath('ok', true);
$response->assertJsonStructure([
'ok',
'account' => [
'parent_id',
'school_year',
'charges' => ['tuition', 'extra_charges', 'event_charges', 'late_fees', 'total'],
'credits' => ['discounts', 'total'],
'payments',
'refunds_applied',
'remaining_balance',
'account_credit',
'students',
],
]);
$this->assertSame(350.0, (float) $response->json('account.charges.tuition'));
$this->assertSame(150.0, (float) $response->json('account.remaining_balance'));
}
public function test_family_balance_endpoint_requires_authentication(): void
{
$response = $this->postJson('/api/v1/finance/fees/family-balance', [
'parent_id' => 10,
'students' => [
['class_section_id' => 101],
],
]);
$response->assertStatus(401);
}
public function test_tuition_total_endpoint_returns_total(): void