add refund and event logic
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Billing;
|
||||
|
||||
use App\Services\Billing\BillingTotalsService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BillingTotalsServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_event_and_additional_subtotals(): void
|
||||
{
|
||||
DB::table('events')->insert([
|
||||
'id' => 1,
|
||||
'event_name' => 'Field Trip',
|
||||
'amount' => 25.00,
|
||||
]);
|
||||
|
||||
DB::table('event_charges')->insert([
|
||||
'id' => 1,
|
||||
'event_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'charged' => 25.00,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('additional_charges')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'invoice_id' => 99,
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'charge_type' => 'add',
|
||||
'amount' => 15.00,
|
||||
'status' => 'applied',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'invoice_id' => 99,
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'charge_type' => 'deduct',
|
||||
'amount' => 5.00,
|
||||
'status' => 'applied',
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new BillingTotalsService();
|
||||
|
||||
$eventSubtotal = $service->eventSubtotal(10, '2025-2026');
|
||||
$additionalSubtotal = $service->additionalSubtotal(99, '2025-2026');
|
||||
|
||||
$this->assertSame(25.0, $eventSubtotal);
|
||||
$this->assertSame(10.0, $additionalSubtotal);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Services\Events\EventCategoryService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventCategoryServiceTest extends TestCase
|
||||
{
|
||||
public function test_categories_returns_list(): void
|
||||
{
|
||||
$categories = EventCategoryService::categories();
|
||||
|
||||
$this->assertContains('workshops', $categories);
|
||||
$this->assertContains('field trips', $categories);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Services\Events\EventChargeQueryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventChargeQueryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_returns_paginated_charges(): void
|
||||
{
|
||||
DB::table('event_charges')->insert([
|
||||
'id' => 1,
|
||||
'event_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'student_id' => 1,
|
||||
'participation' => 'yes',
|
||||
'charged' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$service = new EventChargeQueryService();
|
||||
$result = $service->list(['per_page' => 10, 'page' => 1]);
|
||||
|
||||
$this->assertSame(1, $result['pagination']['total']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Services\Events\EventChargeService;
|
||||
use App\Services\Invoices\InvoiceGenerationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventChargeServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_seed_charges_creates_event_charges(): void
|
||||
{
|
||||
DB::table('events')->insert([
|
||||
'id' => 1,
|
||||
'event_name' => 'Trip',
|
||||
'event_category' => 'field trips',
|
||||
'amount' => 25,
|
||||
'expiration_date' => '2025-02-01',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'One',
|
||||
]);
|
||||
|
||||
DB::table('enrollments')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'enrolled',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$invoiceService = Mockery::mock(InvoiceGenerationService::class);
|
||||
$invoiceService->shouldReceive('generateInvoice')->andReturn(['ok' => true]);
|
||||
|
||||
$service = new EventChargeService($invoiceService);
|
||||
$event = Event::query()->findOrFail(1);
|
||||
$service->seedChargesForEvent($event, '2025-2026', 'Fall', 25, 1);
|
||||
|
||||
$this->assertDatabaseHas('event_charges', [
|
||||
'event_id' => 1,
|
||||
'student_id' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Services\Events\EventListService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventListServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_filters_active_events(): void
|
||||
{
|
||||
DB::table('events')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'event_name' => 'Active',
|
||||
'event_category' => 'workshops',
|
||||
'amount' => 10,
|
||||
'expiration_date' => now()->addDays(2)->toDateString(),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'event_name' => 'Expired',
|
||||
'event_category' => 'workshops',
|
||||
'amount' => 10,
|
||||
'expiration_date' => now()->subDays(2)->toDateString(),
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new EventListService();
|
||||
$result = $service->list(['active' => true, 'per_page' => 10]);
|
||||
|
||||
$this->assertSame(1, $result['pagination']['total']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Services\Events\EventChargeService;
|
||||
use App\Services\Events\EventManagementService;
|
||||
use App\Services\Invoices\InvoiceGenerationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventManagementServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_update_returns_not_found(): void
|
||||
{
|
||||
$chargeService = Mockery::mock(EventChargeService::class);
|
||||
$invoiceService = Mockery::mock(InvoiceGenerationService::class);
|
||||
|
||||
$service = new EventManagementService($chargeService, $invoiceService);
|
||||
$result = $service->update(999, ['event_name' => 'Missing'], null);
|
||||
|
||||
$this->assertFalse($result['ok']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Events;
|
||||
|
||||
use App\Services\Events\EventStudentChargeService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EventStudentChargeServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_students_with_charges(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'One',
|
||||
]);
|
||||
|
||||
DB::table('event_charges')->insert([
|
||||
'id' => 1,
|
||||
'event_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'student_id' => 1,
|
||||
'participation' => 'yes',
|
||||
'charged' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
$service = new EventStudentChargeService();
|
||||
$rows = $service->listStudentsWithCharges(10, '2025-2026', 'Fall');
|
||||
|
||||
$this->assertTrue($rows[0]['charged']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services;
|
||||
|
||||
use App\Services\FeeCalculationService;
|
||||
use App\Services\Fees\FeeRefundCalculatorService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeeCalculationServiceTest extends TestCase
|
||||
{
|
||||
public function test_calculate_refund_returns_calculator_amount(): void
|
||||
{
|
||||
$calculator = Mockery::mock(FeeRefundCalculatorService::class);
|
||||
$calculator->shouldReceive('calculateRefund')
|
||||
->once()
|
||||
->with([], 10)
|
||||
->andReturn(['refund_amount' => 123.45]);
|
||||
|
||||
$service = new FeeCalculationService($calculator);
|
||||
|
||||
$this->assertSame(123.45, $service->calculateRefund([], 10));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Fees;
|
||||
|
||||
use App\Services\Fees\FeeRefundDetailService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeeRefundDetailServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_calculate_refund_details_returns_amount(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-02-01'],
|
||||
['config_key' => 'book_price', 'config_value' => '20'],
|
||||
['config_key' => 'first_student_fee', 'config_value' => '350'],
|
||||
['config_key' => 'second_student_fee', 'config_value' => '200'],
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Sam',
|
||||
'lastname' => 'Parent',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 350.00,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => 100.00,
|
||||
'status' => 'Paid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 100.00,
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new FeeRefundDetailService();
|
||||
$result = $service->calculateRefundDetails([
|
||||
[
|
||||
'student_id' => 1,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
],
|
||||
], 10);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertSame(80.0, $result['refund_amount']);
|
||||
$this->assertTrue($result['eligible']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Fees;
|
||||
|
||||
use App\Services\Fees\FeeConfigService;
|
||||
use App\Services\Fees\FeeGradeService;
|
||||
use App\Services\Fees\FeeStudentFeeService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeeStudentFeeServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
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'],
|
||||
]);
|
||||
|
||||
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());
|
||||
|
||||
$total = $service->totalTuitionFee([
|
||||
['class_section_id' => 101],
|
||||
['class_section_id' => 102],
|
||||
]);
|
||||
|
||||
$this->assertSame(530.0, $total);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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\InvoiceManagementService;
|
||||
use App\Services\Invoices\InvoiceService;
|
||||
use App\Services\Invoices\InvoiceTuitionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvoiceServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_has_class_assignment_returns_true(): void
|
||||
{
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'One',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('student_class')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
$service = new InvoiceService(
|
||||
Mockery::mock(InvoiceConfigService::class),
|
||||
Mockery::mock(InvoiceManagementService::class),
|
||||
Mockery::mock(InvoiceGenerationService::class),
|
||||
Mockery::mock(InvoiceTuitionService::class),
|
||||
Mockery::mock(InvoiceGradeService::class)
|
||||
);
|
||||
|
||||
$this->assertTrue($service->hasClassAssignment('2025-2026', 10));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundDecisionService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundDecisionServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_approve_updates_refund_status(): void
|
||||
{
|
||||
DB::table('refunds')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'refund_amount' => 50,
|
||||
'refund_paid_amount' => 0,
|
||||
'status' => 'Pending',
|
||||
'request' => 'overpayment',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$service = new RefundDecisionService();
|
||||
$result = $service->approve(1, 2);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('refunds', [
|
||||
'id' => 1,
|
||||
'status' => 'Approved',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Services\Discounts\DiscountInvoiceService;
|
||||
use App\Services\Refunds\RefundInvoiceAdjustmentService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundInvoiceAdjustmentServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_apply_book_charge_inserts_additional_charge(): void
|
||||
{
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 100.00,
|
||||
'paid_amount' => 0.00,
|
||||
'status' => 'Unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
$invoice = Invoice::query()->findOrFail(1);
|
||||
|
||||
$invoiceService = Mockery::mock(DiscountInvoiceService::class);
|
||||
$invoiceService->shouldReceive('recalculateInvoice')->once()->with(1, '2025-2026');
|
||||
|
||||
$service = new RefundInvoiceAdjustmentService($invoiceService);
|
||||
|
||||
$result = $service->applyBookChargeAndUpdateInvoice($invoice, 10, [
|
||||
'eligible' => true,
|
||||
'book_price' => 15.00,
|
||||
], 'Fall', 1);
|
||||
|
||||
$this->assertSame('inserted', $result['book_charge_action']);
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'invoice_id' => 1,
|
||||
'title' => 'Book Fee (Non-Refundable)',
|
||||
'amount' => 15.00,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundNotificationService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundNotificationServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_notify_pending_logs_event(): void
|
||||
{
|
||||
Log::spy();
|
||||
|
||||
$service = new RefundNotificationService();
|
||||
$service->notifyPending(10, 50.25, 'https://example.test/login');
|
||||
|
||||
Log::shouldHaveReceived('info')->once();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundNotificationService;
|
||||
use App\Services\Refunds\RefundOverpaymentService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundOverpaymentServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_recalculate_creates_overpayment_refund(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => 100.00,
|
||||
'status' => 'Paid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 150.00,
|
||||
'total_amount' => 150.00,
|
||||
'balance' => 0.00,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new RefundOverpaymentService(new RefundNotificationService());
|
||||
$result = $service->recalculate(false, null, 1);
|
||||
|
||||
$this->assertNotEmpty($result['created_ids']);
|
||||
$this->assertDatabaseHas('refunds', [
|
||||
'parent_id' => 10,
|
||||
'request' => 'overpayment',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundPayoutService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundPayoutServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_record_payment_marks_partial(): void
|
||||
{
|
||||
DB::table('refunds')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'refund_amount' => 100,
|
||||
'refund_paid_amount' => 0,
|
||||
'status' => 'Approved',
|
||||
'request' => 'overpayment',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$service = new RefundPayoutService();
|
||||
$result = $service->recordPayment(1, [
|
||||
'paid_amount' => 40,
|
||||
'payment_method' => 'Cash',
|
||||
], 2);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('refunds', [
|
||||
'id' => 1,
|
||||
'status' => 'Partial',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundInvoiceAdjustmentService;
|
||||
use App\Services\Refunds\RefundPolicyService;
|
||||
use App\Services\Fees\FeeRefundDetailService;
|
||||
use App\Services\Discounts\DiscountInvoiceService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundPolicyServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_process_withdrawal_refund_creates_refund(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
['config_key' => 'refund_deadline', 'config_value' => '2025-02-01'],
|
||||
['config_key' => 'book_price', 'config_value' => '10'],
|
||||
['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'],
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
'id' => 1,
|
||||
'class_id' => 1,
|
||||
'class_section_id' => 101,
|
||||
'class_section_name' => '3',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('students')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'firstname' => 'Kid',
|
||||
'lastname' => 'One',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
DB::table('enrollments')->insert([
|
||||
'id' => 1,
|
||||
'student_id' => 1,
|
||||
'parent_id' => 10,
|
||||
'class_section_id' => 101,
|
||||
'enrollment_status' => 'withdrawn',
|
||||
'withdrawal_date' => '2025-01-15',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'admission_status' => 'accepted',
|
||||
'is_withdrawn' => 1,
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 350.00,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => 100.00,
|
||||
'status' => 'Paid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 100.00,
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new RefundPolicyService(
|
||||
new FeeRefundDetailService(),
|
||||
new RefundInvoiceAdjustmentService(new DiscountInvoiceService())
|
||||
);
|
||||
|
||||
$result = $service->processWithdrawalRefund(10, 1, '2025-2026', 'Fall', 1);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('refunds', [
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'request' => 'tuition',
|
||||
]);
|
||||
$this->assertDatabaseHas('additional_charges', [
|
||||
'invoice_id' => 1,
|
||||
'title' => 'Book Fee (Non-Refundable)',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundQueryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundQueryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_list_filters_by_status(): void
|
||||
{
|
||||
DB::table('refunds')->insert([
|
||||
[
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'refund_amount' => 10,
|
||||
'refund_paid_amount' => 0,
|
||||
'status' => 'Pending',
|
||||
'request' => 'overpayment',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'parent_id' => 11,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'refund_amount' => 20,
|
||||
'refund_paid_amount' => 0,
|
||||
'status' => 'Approved',
|
||||
'request' => 'overpayment',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
],
|
||||
]);
|
||||
|
||||
$service = new RefundQueryService();
|
||||
$result = $service->list(['status' => 'Approved', 'per_page' => 10, 'page' => 1]);
|
||||
|
||||
$this->assertSame(1, $result['pagination']['total']);
|
||||
$this->assertSame('Approved', $result['refunds']->items()[0]->status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Fees\FeeRefundDetailService;
|
||||
use App\Services\Refunds\RefundInvoiceAdjustmentService;
|
||||
use App\Services\Refunds\RefundNotificationService;
|
||||
use App\Services\Refunds\RefundPolicyService;
|
||||
use App\Services\Refunds\RefundRequestService;
|
||||
use App\Services\Refunds\RefundSummaryService;
|
||||
use App\Services\Discounts\DiscountInvoiceService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundRequestServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_request_overpayment_creates_refund(): void
|
||||
{
|
||||
DB::table('configuration')->insert([
|
||||
['config_key' => 'school_year', 'config_value' => '2025-2026'],
|
||||
['config_key' => 'semester', 'config_value' => 'Fall'],
|
||||
]);
|
||||
|
||||
DB::table('users')->insert([
|
||||
'id' => 10,
|
||||
'firstname' => 'Parent',
|
||||
'lastname' => 'User',
|
||||
'email' => 'parent@example.com',
|
||||
'status' => 'Active',
|
||||
]);
|
||||
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 100.00,
|
||||
'paid_amount' => 0.00,
|
||||
'status' => 'Unpaid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 150.00,
|
||||
'total_amount' => 150.00,
|
||||
'balance' => 0.00,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
$service = new RefundRequestService(
|
||||
new RefundPolicyService(
|
||||
new FeeRefundDetailService(),
|
||||
new RefundInvoiceAdjustmentService(new DiscountInvoiceService())
|
||||
),
|
||||
new RefundSummaryService(),
|
||||
new RefundNotificationService()
|
||||
);
|
||||
|
||||
$result = $service->requestRefund([
|
||||
'parent_id' => 10,
|
||||
'request_type' => 'overpayment',
|
||||
'amount' => 25,
|
||||
], 1);
|
||||
|
||||
$this->assertTrue($result['ok']);
|
||||
$this->assertDatabaseHas('refunds', [
|
||||
'parent_id' => 10,
|
||||
'request' => 'overpayment',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services\Refunds;
|
||||
|
||||
use App\Services\Refunds\RefundSummaryService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RefundSummaryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_summary_calculates_unapplied_balance(): void
|
||||
{
|
||||
DB::table('invoices')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_number' => 'INV-1',
|
||||
'total_amount' => 100.00,
|
||||
'balance' => 0.00,
|
||||
'paid_amount' => 100.00,
|
||||
'status' => 'Paid',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'issue_date' => '2025-01-05',
|
||||
]);
|
||||
|
||||
DB::table('payments')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'paid_amount' => 150.00,
|
||||
'total_amount' => 150.00,
|
||||
'balance' => 0.00,
|
||||
'payment_date' => '2025-01-10',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'status' => 'Paid',
|
||||
]);
|
||||
|
||||
DB::table('refunds')->insert([
|
||||
'id' => 1,
|
||||
'parent_id' => 10,
|
||||
'invoice_id' => 1,
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
'refund_amount' => 20,
|
||||
'refund_paid_amount' => 20,
|
||||
'status' => 'Paid',
|
||||
'request' => 'overpayment',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$service = new RefundSummaryService();
|
||||
$summary = $service->getParentFinancialSummary(10, '2025-2026', 'Fall');
|
||||
|
||||
$this->assertSame(100.0, $summary['total_invoiced']);
|
||||
$this->assertSame(150.0, $summary['total_paid_in']);
|
||||
$this->assertSame(20.0, $summary['total_refunded']);
|
||||
$this->assertSame(30.0, $summary['unapplied_balance']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user