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,31 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialChartService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class FinancialChartServiceTest extends TestCase
{
use RefreshDatabase;
public function test_generate_charts_returns_null_in_tests(): void
{
$service = new FinancialChartService();
$summary = [
'totalCharges' => 100,
'amountCollected' => 80,
'totalUnpaid' => 20,
'totalDiscounts' => 5,
'totalRefunds' => 2,
'totalExpenses' => 10,
'totalReimbursements' => 4,
'netAmount' => 93,
];
$this->assertNull($service->generateBarChart($summary));
$this->assertNull($service->generatePieChart($summary));
}
}
@@ -0,0 +1,94 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialPaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FinancialPaymentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_payment_aggregates_exclude_void_statuses(): void
{
DB::table('payments')->insert([
[
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 30,
'balance' => 70,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-01-05',
'school_year' => '2025-2026',
'status' => 'Paid',
],
[
'id' => 2,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 20,
'balance' => 50,
'number_of_installments' => 1,
'payment_method' => 'Credit Card',
'payment_date' => '2025-01-06',
'school_year' => '2025-2026',
'status' => 'Paid',
],
[
'id' => 3,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 50,
'balance' => 0,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-01-07',
'school_year' => '2025-2026',
'status' => 'void',
],
[
'id' => 4,
'parent_id' => 11,
'invoice_id' => 2,
'total_amount' => 40,
'paid_amount' => 10,
'balance' => 30,
'number_of_installments' => 1,
'payment_method' => 'Check',
'payment_date' => '2025-01-08',
'school_year' => '2025-2026',
'status' => 'Paid',
],
]);
$service = new FinancialPaymentService();
$payments = $service->paymentsByInvoice('2025-2026', '2025-01-01', '2025-01-31');
$breakdown = $service->paymentBreakdown('2025-2026', '2025-01-01', '2025-01-31');
$totals = $service->paymentTotals('2025-2026', '2025-01-01', '2025-01-31');
$map = [];
foreach ($payments as $row) {
$map[(int) $row['invoice_id']] = (float) $row['paid_amount'];
}
$this->assertSame(50.0, $map[1]);
$this->assertSame(10.0, $map[2]);
$this->assertSame(30.0, (float) ($breakdown[1]['cash'] ?? 0));
$this->assertSame(20.0, (float) ($breakdown[1]['credit'] ?? 0));
$this->assertSame(10.0, (float) ($breakdown[2]['check'] ?? 0));
$this->assertSame(60.0, $totals['total_all']);
$this->assertSame(30.0, $totals['total_cash']);
$this->assertSame(20.0, $totals['total_credit']);
$this->assertSame(10.0, $totals['total_check']);
}
}
@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialChartService;
use App\Services\Finance\FinancialPdfReportService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class FinancialPdfReportServiceTest extends TestCase
{
use RefreshDatabase;
public function test_build_pdf_returns_bytes(): void
{
$service = new FinancialPdfReportService(new FinancialChartService());
$summary = [
'schoolYear' => '2025-2026',
'totalCharges' => 100,
'totalExtraCharges' => 20,
'totalDiscounts' => 10,
'totalRefunds' => 5,
'totalExpenses' => 15,
'totalReimbursements' => 8,
'donationToSchool' => 3,
'netAmount' => 85,
'amountCollected' => 60,
'totalUnpaid' => 40,
];
$pdf = $service->buildPdf($summary);
$this->assertIsString($pdf);
$this->assertNotSame('', $pdf);
}
}
@@ -0,0 +1,126 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialPaymentService;
use App\Services\Finance\FinancialReportService;
use App\Services\Finance\FinancialSchoolYearService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FinancialReportServiceTest extends TestCase
{
use RefreshDatabase;
public function test_report_returns_grouped_data(): void
{
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('invoices')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 40,
'paid_amount' => 60,
'has_discount' => 1,
'issue_date' => '2025-01-01',
'due_date' => '2025-02-01',
'status' => 'unpaid',
'school_year' => '2025-2026',
]);
DB::table('payments')->insert([
'id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'total_amount' => 100,
'paid_amount' => 60,
'balance' => 40,
'number_of_installments' => 1,
'payment_method' => 'Cash',
'payment_date' => '2025-01-02',
'school_year' => '2025-2026',
'status' => 'Paid',
]);
DB::table('refunds')->insert([
'id' => 1,
'parent_id' => 10,
'school_year' => '2025-2026',
'invoice_id' => 1,
'refund_amount' => 5,
'status' => 'Paid',
'refund_paid_amount' => 5,
]);
DB::table('discount_usages')->insert([
'id' => 1,
'voucher_id' => 1,
'invoice_id' => 1,
'parent_id' => 10,
'discount_amount' => 10,
'school_year' => '2025-2026',
]);
DB::table('expenses')->insert([
'id' => 1,
'category' => 'Expense',
'amount' => 20,
'date_of_purchase' => '2025-01-05',
'purchased_by' => 10,
'added_by' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
]);
DB::table('reimbursements')->insert([
'id' => 1,
'expense_id' => 1,
'amount' => 15,
'reimbursed_to' => 10,
'added_by' => 1,
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
]);
$service = new FinancialReportService(
new FinancialPaymentService(),
new FinancialSchoolYearService()
);
$report = $service->getReport('2025-01-01', '2025-12-31', '2025-2026');
$this->assertSame('2025-2026', $report['selectedYear']);
$this->assertSame(['2025-2026'], $report['schoolYears']);
$this->assertCount(1, $report['invoices']);
$this->assertCount(1, $report['payments']);
$this->assertCount(1, $report['refunds']);
$this->assertCount(1, $report['discounts']);
$this->assertCount(1, $report['expenses']);
$this->assertCount(1, $report['reimbursements']);
$this->assertSame(60.0, $report['paymentTotals']['total_all']);
}
}
@@ -0,0 +1,50 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialSchoolYearService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FinancialSchoolYearServiceTest extends TestCase
{
use RefreshDatabase;
public function test_list_years_returns_distinct_sorted_years(): void
{
DB::table('invoices')->insert([
[
'id' => 1,
'parent_id' => 1,
'invoice_number' => 'INV-100',
'total_amount' => 10,
'balance' => 10,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2024-01-01',
'due_date' => '2024-02-01',
'status' => 'unpaid',
'school_year' => '2024-2025',
],
[
'id' => 2,
'parent_id' => 1,
'invoice_number' => 'INV-101',
'total_amount' => 10,
'balance' => 10,
'paid_amount' => 0,
'has_discount' => 0,
'issue_date' => '2025-01-01',
'due_date' => '2025-02-01',
'status' => 'unpaid',
'school_year' => '2025-2026',
],
]);
$service = new FinancialSchoolYearService();
$years = $service->listYears();
$this->assertSame(['2025-2026', '2024-2025'], $years);
}
}
@@ -0,0 +1,165 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialDonationRecipientService;
use App\Services\Finance\FinancialSummaryService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FinancialSummaryServiceTest extends TestCase
{
use RefreshDatabase;
public function test_summary_calculates_totals(): 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',
]);
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('additional_charges')->insert([
[
'id' => 1,
'parent_id' => 2,
'amount' => 20,
'school_year' => '2025-2026',
'status' => 'pending',
],
[
'id' => 2,
'parent_id' => 2,
'amount' => 30,
'invoice_id' => 1,
'school_year' => '2025-2026',
'status' => 'applied',
],
]);
DB::table('expenses')->insert([
[
'id' => 1,
'category' => 'Donation',
'amount' => 12,
'date_of_purchase' => '2025-01-05',
'purchased_by' => 2,
'added_by' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
],
[
'id' => 2,
'category' => 'Expense',
'amount' => 8,
'date_of_purchase' => '2025-01-06',
'purchased_by' => 2,
'added_by' => 1,
'school_year' => '2025-2026',
'semester' => 'Fall',
'status' => 'approved',
],
]);
DB::table('reimbursements')->insert([
[
'id' => 1,
'expense_id' => 2,
'amount' => 15,
'reimbursed_to' => 2,
'added_by' => 1,
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
],
[
'id' => 2,
'expense_id' => 1,
'amount' => 7,
'reimbursed_to' => 990002,
'added_by' => 1,
'status' => 'Paid',
'school_year' => '2025-2026',
'semester' => 'Fall',
],
]);
$service = new FinancialSummaryService(new FinancialDonationRecipientService());
$summary = $service->getSummary('2025-01-01', '2025-12-31', '2025-2026');
$this->assertSame(120.0, $summary['totalCharges']);
$this->assertSame(50.0, $summary['totalExtraCharges']);
$this->assertSame(10.0, $summary['totalDiscounts']);
$this->assertSame(5.0, $summary['totalRefunds']);
$this->assertSame(20.0, $summary['totalExpenses']);
$this->assertSame(15.0, $summary['totalReimbursements']);
$this->assertSame(19.0, $summary['donationToSchool']);
$this->assertSame(60.0, $summary['totalPaid']);
$this->assertSame(45.0, $summary['totalUnpaid']);
$this->assertSame(105.0, $summary['netAmount']);
}
}
@@ -0,0 +1,110 @@
<?php
namespace Tests\Unit\Services\Finance;
use App\Services\Finance\FinancialSchoolYearService;
use App\Services\Finance\FinancialUnpaidParentsService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class FinancialUnpaidParentsServiceTest extends TestCase
{
use RefreshDatabase;
public function test_unpaid_parents_returns_installment_data(): void
{
DB::table('configuration')->insert([
['id' => 1, 'config_key' => 'installment_date', 'config_value' => date('Y-m-t')],
]);
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',
],
]);
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('additional_charges')->insert([
'id' => 1,
'parent_id' => 2,
'amount' => 20,
'school_year' => '2025-2026',
'status' => 'pending',
]);
$service = new FinancialUnpaidParentsService(new FinancialSchoolYearService());
$result = $service->getUnpaidParents('2025-2026');
$this->assertSame('2025-2026', $result['schoolYear']);
$this->assertCount(1, $result['results']);
$row = $result['results'][0];
$this->assertSame(45.0, $row['total_balance']);
$this->assertSame('installment', $row['type']);
$this->assertSame(1, $row['has_installment']);
}
}