Files
root 02ba2fe6b6
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix parent pages and teachers and admin
2026-07-09 13:56:22 -04:00

99 lines
3.1 KiB
PHP

<?php
namespace Tests\Unit\Services\Invoices;
use App\Services\Invoices\InvoiceConfigService;
use App\Services\Invoices\InvoicePaymentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
class InvoicePaymentServiceTest extends TestCase
{
use RefreshDatabase;
public function test_parent_invoice_summary_includes_refunds_and_last_payment(): void
{
DB::table('invoices')->insert([
[
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-001',
'total_amount' => 100,
'balance' => 40,
'paid_amount' => 60,
'has_discount' => 0,
'issue_date' => '2025-01-10',
'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-15',
'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,
]);
$service = new InvoicePaymentService(new InvoiceConfigService);
$data = $service->getParentInvoiceSummary(10, '2025-2026');
$this->assertSame('2025-2026', $data['selectedYear']);
$this->assertSame(5.0, $data['invoices'][0]['refund_amount']);
$this->assertSame(60.0, $data['invoices'][0]['last_paid_amount']);
}
public function test_parent_invoice_summary_applies_full_discount_to_balance(): void
{
DB::table('invoices')->insert([
[
'id' => 1,
'parent_id' => 10,
'invoice_number' => 'INV-DISCOUNT',
'total_amount' => 370,
'balance' => 370,
'paid_amount' => 0,
'has_discount' => 1,
'issue_date' => '2025-01-10',
'status' => 'Paid',
'school_year' => '2025-2026',
],
]);
DB::table('discount_usages')->insert([
'id' => 1,
'voucher_id' => 1,
'parent_id' => 10,
'invoice_id' => 1,
'discount_amount' => 370,
'description' => 'Full scholarship',
'school_year' => '2025-2026',
]);
$service = new InvoicePaymentService(new InvoiceConfigService);
$data = $service->getParentInvoiceSummary(10, '2025-2026');
$this->assertSame(370.0, $data['invoices'][0]['discount']);
$this->assertSame(0.0, $data['invoices'][0]['balance']);
$this->assertSame('Paid', $data['invoices'][0]['status']);
}
}