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,83 @@
<?php
namespace Tests\Unit\Services\Reimbursements;
use App\Services\Reimbursements\ReimbursementBatchAssignmentService;
use App\Services\Reimbursements\ReimbursementLookupService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ReimbursementBatchAssignmentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_assign_and_unassign_batch_item(): void
{
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('reimbursement_batches')->insert([
'id' => 10,
'title' => 'Batch 10',
'status' => 'open',
'school_year' => '2025-2026',
'semester' => 'Fall',
'opened_at' => now(),
]);
DB::table('expenses')->insert([
'id' => 100,
'category' => 'Expense',
'amount' => 25.00,
'date_of_purchase' => '2025-01-01',
'added_by' => 1,
'purchased_by' => 1,
'status' => 'approved',
]);
$service = new ReimbursementBatchAssignmentService(new ReimbursementLookupService());
$result = $service->updateAssignment(100, 10, 1, null, '2025-2026', 'Fall');
$this->assertSame(10, $result['batch_id']);
$this->assertDatabaseHas('reimbursement_batch_items', [
'batch_id' => 10,
'expense_id' => 100,
'admin_id' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service->updateAssignment(100, 0, null, null, '2025-2026', 'Fall');
$this->assertDatabaseHas('reimbursement_batch_items', [
'batch_id' => 10,
'expense_id' => 100,
]);
$this->assertDatabaseMissing('reimbursement_batch_items', [
'batch_id' => 10,
'expense_id' => 100,
'unassigned_at' => null,
]);
}
}
@@ -0,0 +1,30 @@
<?php
namespace Tests\Unit\Services\Reimbursements;
use App\Services\Reimbursements\ReimbursementBatchService;
use App\Services\Reimbursements\ReimbursementLookupService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ReimbursementBatchServiceTest extends TestCase
{
use RefreshDatabase;
public function test_create_batch_assigns_sequence_and_title(): void
{
$service = new ReimbursementBatchService(new ReimbursementLookupService());
$batch = $service->createBatch(null, 1, '2025-2026', 'Fall');
$this->assertSame(1, $batch['sequence']);
$this->assertStringContainsString('Batch', $batch['label']);
$this->assertDatabaseHas('reimbursement_batches', [
'id' => $batch['batch_id'],
'status' => 'open',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
}
}
@@ -0,0 +1,77 @@
<?php
namespace Tests\Unit\Services\Reimbursements;
use App\Services\Reimbursements\ReimbursementDonationService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ReimbursementDonationServiceTest extends TestCase
{
use RefreshDatabase;
public function test_mark_donation_updates_expense_and_unassigns(): void
{
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('expenses')->insert([
'id' => 200,
'category' => 'Expense',
'amount' => 40.00,
'date_of_purchase' => '2025-02-01',
'added_by' => 1,
'purchased_by' => 1,
'status' => 'approved',
]);
DB::table('reimbursement_batches')->insert([
'id' => 5,
'title' => 'Batch 5',
'status' => 'open',
'school_year' => '2025-2026',
'semester' => 'Fall',
'opened_at' => now(),
]);
DB::table('reimbursement_batch_items')->insert([
'batch_id' => 5,
'expense_id' => 200,
'assigned_at' => now(),
]);
$service = new ReimbursementDonationService();
$service->markDonation(200, 1);
$this->assertDatabaseHas('expenses', [
'id' => 200,
'category' => 'Donation',
'status' => 'approved',
]);
$this->assertDatabaseMissing('reimbursement_batch_items', [
'batch_id' => 5,
'expense_id' => 200,
'unassigned_at' => null,
]);
}
}
@@ -0,0 +1,79 @@
<?php
namespace Tests\Unit\Services\Reimbursements;
use App\Services\Reimbursements\ReimbursementRecipientService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class ReimbursementRecipientServiceTest extends TestCase
{
use RefreshDatabase;
public function test_recipient_options_include_staff_and_specials(): void
{
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',
],
[
'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('roles')->insert([
['id' => 1, 'name' => 'admin'],
['id' => 2, 'name' => 'parent'],
]);
DB::table('user_roles')->insert([
['user_id' => 1, 'role_id' => 1],
['user_id' => 2, 'role_id' => 2],
]);
$service = new ReimbursementRecipientService();
$recipients = $service->recipientOptions();
$ids = array_map(static fn ($row) => (int) ($row['id'] ?? 0), $recipients);
$this->assertContains(1, $ids);
$this->assertNotContains(2, $ids);
$this->assertContains(990001, $ids);
$this->assertContains(990002, $ids);
}
}