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,193 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class FinancialControllerTest extends TestCase
{
use RefreshDatabase;
public function test_report_returns_financial_report(): void
{
$this->seedFinancialData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/financial-report?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('report.invoices'));
}
public function test_summary_returns_totals(): void
{
$this->seedFinancialData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/financial-summary?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertGreaterThan(0, (float) $response->json('summary.totalCharges'));
}
public function test_unpaid_parents_lists_balances(): void
{
$this->seedFinancialData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/unpaid-parents?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('results'));
}
private function seedFinancialData(): void
{
DB::table('users')->insert([
[
'id' => 2,
'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('invoices')->insert([
[
'id' => 1,
'parent_id' => 2,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 40,
'paid_amount' => 60,
'has_discount' => 1,
'issue_date' => '2025-01-10',
'due_date' => '2025-02-10',
'status' => 'unpaid',
'school_year' => '2025-2026',
],
[
'id' => 2,
'parent_id' => 2,
'invoice_number' => 'INV-002',
'total_amount' => 50,
'balance' => 50,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-02-01',
'due_date' => '2025-03-01',
'status' => 'unpaid',
'school_year' => '2025-2026',
],
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 2,
'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('discount_usages')->insert([
'id' => 1,
'voucher_id' => 1,
'invoice_id' => 1,
'parent_id' => 2,
'discount_amount' => 10,
'school_year' => '2025-2026',
]);
DB::table('refunds')->insert([
'id' => 1,
'parent_id' => 2,
'school_year' => '2025-2026',
'invoice_id' => 1,
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
]);
DB::table('expenses')->insert([
'id' => 1,
'category' => 'Expense',
'amount' => 20,
'date_of_purchase' => '2025-01-05',
'purchased_by' => 2,
'added_by' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
]);
DB::table('reimbursements')->insert([
'id' => 1,
'expense_id' => 1,
'amount' => 15,
'reimbursed_to' => 2,
'added_by' => 1,
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
private function createUser(): User
{
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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',
]);
return User::query()->findOrFail(1);
}
}
@@ -0,0 +1,166 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class InvoiceControllerTest extends TestCase
{
use RefreshDatabase;
public function test_management_returns_parent_invoice_data(): void
{
$this->seedBaseData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/invoices/management?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('invoices'));
}
public function test_generate_creates_invoice(): void
{
$this->seedBaseData(false);
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->postJson('/api/v1/finance/invoices/generate', [
'parent_id' => 10,
'school_year' => '2025-2026',
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('invoices', [
'parent_id' => 10,
'school_year' => '2025-2026',
]);
}
public function test_by_parent_returns_invoices(): void
{
$this->seedBaseData();
$user = $this->createUser();
Sanctum::actingAs($user);
$response = $this->getJson('/api/v1/finance/invoices/parent/10?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('invoices'));
}
private function seedBaseData(bool $withInvoice = true): 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',
]);
if ($withInvoice) {
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',
]);
}
}
private function createUser(): User
{
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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',
]);
return User::query()->findOrFail(1);
}
}
@@ -0,0 +1,153 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaymentControllerTest extends TestCase
{
use RefreshDatabase;
public function test_store_creates_payment_plan(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->postJson('/api/v1/finance/payments', [
'parent_id' => 10,
'total_amount' => 250,
'number_of_installments' => 2,
'payment_date' => '2025-01-05',
'payment_method' => 'cash',
'semester' => 'Fall',
'school_year' => '2025-2026',
]);
$response->assertStatus(201);
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('payments', [
'parent_id' => 10,
'total_amount' => 250,
'number_of_installments' => 2,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
public function test_by_parent_returns_payments(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 25,
'balance' => 75,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Partially Paid',
]);
$response = $this->getJson('/api/v1/finance/payments/parent/10?school_year=2025-2026');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('payments'));
}
public function test_update_balance_updates_payment(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
$response = $this->postJson('/api/v1/finance/payments/1/balance', [
'paid_amount' => 25,
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('payments', [
'id' => 1,
'paid_amount' => 25,
'balance' => 75,
]);
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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('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' => 1, 'role_id' => 1],
['user_id' => 10, 'role_id' => 2],
]);
}
}
@@ -0,0 +1,108 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaymentEventChargesControllerTest extends TestCase
{
use RefreshDatabase;
public function test_store_creates_event_charges(): void
{
$this->seedUsers();
$this->seedStudents();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->postJson('/api/v1/finance/event-charges', [
'parent_id' => 10,
'event_name' => 'Field Trip',
'description' => 'Bus fee',
'amount' => 25,
'semester' => 'Fall',
'school_year' => '2025-2026',
'student_ids' => [100],
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('event_charges', [
'parent_id' => 10,
'student_id' => 100,
'event_name' => 'Field Trip',
'amount' => 25,
'school_year' => '2025-2026',
]);
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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('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' => 1, 'role_id' => 1],
['user_id' => 10, 'role_id' => 2],
]);
}
private function seedStudents(): void
{
DB::table('students')->insert([
'id' => 100,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'is_active' => 1,
]);
}
}
@@ -0,0 +1,132 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaymentManualControllerTest extends TestCase
{
use RefreshDatabase;
public function test_search_returns_parent_data(): void
{
$this->seedUsers();
$this->seedConfig();
$this->seedStudent();
$this->seedInvoice();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->getJson('/api/v1/finance/manual-pay/search?search_term=parent@example.com');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertSame(10, $response->json('parent.id'));
}
public function test_suggest_returns_items(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->getJson('/api/v1/finance/manual-pay/suggest?q=parent');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('items'));
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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('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' => 1, 'role_id' => 1],
['user_id' => 10, 'role_id' => 2],
]);
}
private function seedConfig(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
['config_key' => 'installment_date', 'config_value' => '2025-06-01'],
]);
}
private function seedStudent(): void
{
DB::table('students')->insert([
'id' => 100,
'parent_id' => 10,
'firstname' => 'Kid',
'lastname' => 'User',
'school_id' => 1,
'is_active' => 1,
]);
}
private function seedInvoice(): void
{
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 100,
'paid_amount' => 0,
'status' => 'unpaid',
'school_year' => '2025-2026',
'issue_date' => '2025-01-01',
]);
}
}
@@ -0,0 +1,141 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaymentNotificationControllerTest extends TestCase
{
use RefreshDatabase;
public function test_send_creates_log(): void
{
Mail::fake();
$this->seedUsers();
$this->seedConfig();
$this->seedInvoice();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->postJson('/api/v1/finance/payment-notifications/send', [
'parent_id' => 10,
'school_year' => '2025-2026',
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('payment_notification_logs', [
'parent_id' => 10,
'school_year' => '2025-2026',
]);
}
public function test_index_lists_logs(): void
{
$this->seedUsers();
DB::table('payment_notification_logs')->insert([
'parent_id' => 10,
'school_year' => '2025-2026',
'period_year' => 2025,
'period_month' => 1,
'type' => 'installment',
'to_email' => 'parent@example.com',
'status' => 'sent',
'balance_snapshot' => 100,
'sent_at' => '2025-01-01 10:00:00',
]);
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->getJson('/api/v1/finance/payment-notifications');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('logs'));
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
['id' => 2, 'name' => 'parent', 'slug' => 'parent', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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('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' => 1, 'role_id' => 1],
['user_id' => 10, 'role_id' => 2],
]);
}
private function seedConfig(): void
{
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
['config_key' => 'installment_date', 'config_value' => '2025-06-01'],
]);
}
private function seedInvoice(): void
{
DB::table('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 200,
'balance' => 200,
'paid_amount' => 0,
'status' => 'unpaid',
'school_year' => '2025-2026',
'issue_date' => '2025-01-01',
]);
}
}
@@ -0,0 +1,136 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaymentTransactionControllerTest extends TestCase
{
use RefreshDatabase;
public function test_store_creates_transaction(): void
{
$this->seedUsers();
$this->seedPayment();
Sanctum::actingAs(User::query()->findOrFail(1));
$response = $this->postJson('/api/v1/finance/payment-transactions', [
'transaction_id' => 'TXN-1001',
'payment_id' => 1,
'transaction_date' => '2025-01-10',
'amount' => 25,
'payment_method' => 'cash',
]);
$response->assertStatus(201);
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('payment_transactions', [
'transaction_id' => 'TXN-1001',
'payment_id' => 1,
'amount' => 25,
]);
}
public function test_by_payment_returns_transactions(): void
{
$this->seedUsers();
$this->seedPayment();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('payment_transactions')->insert([
'transaction_id' => 'TXN-1002',
'payment_id' => 1,
'transaction_date' => '2025-01-11',
'amount' => 40,
'payment_method' => 'cash',
'payment_status' => 'Pending',
]);
$response = $this->getJson('/api/v1/finance/payment-transactions/payment/1');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('transactions'));
}
public function test_update_status_updates_transaction(): void
{
$this->seedUsers();
$this->seedPayment();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('payment_transactions')->insert([
'transaction_id' => 'TXN-1003',
'payment_id' => 1,
'transaction_date' => '2025-01-11',
'amount' => 40,
'payment_method' => 'cash',
'payment_status' => 'Pending',
]);
$response = $this->postJson('/api/v1/finance/payment-transactions/TXN-1003/status', [
'status' => 'Completed',
]);
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertDatabaseHas('payment_transactions', [
'transaction_id' => 'TXN-1003',
'payment_status' => 'Completed',
]);
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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' => 1,
'role_id' => 1,
]);
}
private function seedPayment(): void
{
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 0,
'balance' => 100,
'number_of_installments' => 1,
'payment_method' => 'cash',
'payment_date' => '2025-01-01',
'school_year' => '2025-2026',
'status' => 'Pending',
]);
}
}
@@ -0,0 +1,98 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class PaypalTransactionsControllerTest extends TestCase
{
use RefreshDatabase;
public function test_index_returns_transactions(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('paypal_payments')->insert([
'id' => 1,
'transaction_id' => 'PP-1001',
'order_id' => 'ORDER-1',
'parent_school_id' => 10,
'payer_email' => 'payer@example.com',
'amount' => 50,
'net_amount' => 48,
'currency' => 'USD',
'status' => 'COMPLETED',
'event_type' => 'PAYMENT.SALE.COMPLETED',
'created_at' => '2025-01-01 10:00:00',
]);
$response = $this->getJson('/api/v1/finance/paypal-transactions');
$response->assertOk();
$response->assertJson(['ok' => true]);
$this->assertNotEmpty($response->json('transactions'));
}
public function test_csv_download(): void
{
$this->seedUsers();
Sanctum::actingAs(User::query()->findOrFail(1));
DB::table('paypal_payments')->insert([
'id' => 1,
'transaction_id' => 'PP-1002',
'order_id' => 'ORDER-2',
'parent_school_id' => 10,
'payer_email' => 'payer@example.com',
'amount' => 60,
'net_amount' => 58,
'currency' => 'USD',
'status' => 'COMPLETED',
'event_type' => 'PAYMENT.SALE.COMPLETED',
'created_at' => '2025-01-01 10:00:00',
]);
$response = $this->get('/api/v1/finance/paypal-transactions/csv');
$response->assertOk();
$response->assertHeader('Content-Type', 'text/csv');
}
private function seedUsers(): void
{
DB::table('roles')->insert([
['id' => 1, 'name' => 'admin', 'slug' => 'admin', 'is_active' => 1],
]);
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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' => 1,
'role_id' => 1,
]);
}
}
@@ -0,0 +1,185 @@
<?php
namespace Tests\Feature\Api\V1\Finance;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;
class ReimbursementControllerTest extends TestCase
{
use RefreshDatabase;
public function test_create_batch_creates_open_batch(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
DB::table('configuration')->insert([
['config_key' => 'school_year', 'config_value' => '2025-2026'],
['config_key' => 'semester', 'config_value' => 'Fall'],
]);
$response = $this->postJson('/api/v1/finance/reimbursements/batches', [
'title' => 'Test Batch',
]);
$response->assertCreated();
$response->assertJsonPath('ok', true);
$this->assertDatabaseHas('reimbursement_batches', [
'title' => 'Test Batch',
'status' => 'open',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
public function test_mark_donation_updates_expense(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
DB::table('expenses')->insert([
'id' => 1,
'category' => 'Expense',
'amount' => 12.00,
'date_of_purchase' => '2025-02-01',
'added_by' => $user->id,
'purchased_by' => $user->id,
'status' => 'approved',
]);
$response = $this->postJson('/api/v1/finance/reimbursements/mark-donation', [
'expense_id' => 1,
]);
$response->assertOk();
$response->assertJsonPath('ok', true);
$this->assertDatabaseHas('expenses', [
'id' => 1,
'category' => 'Donation',
'status' => 'approved',
]);
}
public function test_store_reimbursement_creates_record_and_updates_expense(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
DB::table('users')->insert([
'id' => 2,
'school_id' => 1,
'firstname' => 'Recipient',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'recipient@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('expenses')->insert([
'id' => 2,
'category' => 'Expense',
'amount' => 50.00,
'date_of_purchase' => '2025-02-05',
'added_by' => $user->id,
'purchased_by' => $user->id,
'status' => 'approved',
]);
$response = $this->postJson('/api/v1/finance/reimbursements', [
'expense_id' => 2,
'amount' => 50.00,
'reimbursed_to' => 2,
'reimbursement_method' => 'Cash',
'description' => 'Test reimbursement',
]);
$response->assertCreated();
$response->assertJsonPath('ok', true);
$this->assertDatabaseHas('reimbursements', [
'expense_id' => 2,
'amount' => 50.00,
'reimbursed_to' => 2,
'status' => 'Paid',
]);
$this->assertDatabaseMissing('expenses', [
'id' => 2,
'reimbursement_id' => null,
]);
}
public function test_update_reimbursement_updates_fields(): void
{
$user = $this->createUser();
Sanctum::actingAs($user);
DB::table('reimbursements')->insert([
'id' => 10,
'amount' => 25.00,
'reimbursed_to' => $user->id,
'added_by' => $user->id,
'status' => 'Paid',
'reimbursement_method' => 'Cash',
]);
$response = $this->putJson('/api/v1/finance/reimbursements/10', [
'amount' => 30.00,
'reimbursed_to' => $user->id,
'reimbursement_method' => 'Cash',
'description' => 'Updated',
]);
$response->assertOk();
$response->assertJsonPath('ok', true);
$this->assertDatabaseHas('reimbursements', [
'id' => 10,
'amount' => 30.00,
'description' => 'Updated',
]);
}
private function createUser(): User
{
DB::table('users')->insert([
'id' => 1,
'school_id' => 1,
'firstname' => 'Admin',
'lastname' => 'User',
'cellphone' => '5555555555',
'email' => 'admin@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',
]);
return User::query()->findOrFail(1);
}
}