fix school year for all tables
Tests / PHPUnit (push) Failing after 1m20s

This commit is contained in:
root
2026-07-18 14:45:38 -04:00
parent 4db8334a3c
commit 716cc8b8d3
125 changed files with 2315 additions and 81 deletions
+27 -3
View File
@@ -74,9 +74,15 @@ class InvoiceLedgerService
$paidCents = $this->toCents($paidTotal);
$refundPaidCents = $this->toCents($refundPaidTotal);
$discountBaseCents = max(0, $tuitionCents + $additionalCents);
$discountCents = min($discountRawCents, $discountBaseCents);
$totalAmountCents = $tuitionCents + $eventCents + $additionalCents;
if ($this->isCarryForwardInvoice($invoice)) {
$totalAmountCents = $this->toCents((float) ($invoice['total_amount'] ?? 0));
$discountCents = 0;
} else {
$discountBaseCents = max(0, $tuitionCents + $additionalCents);
$discountCents = min($discountRawCents, $discountBaseCents);
$totalAmountCents = $tuitionCents + $eventCents + $additionalCents;
}
$balanceCents = max(0, $totalAmountCents - $discountCents - $paidCents - $refundPaidCents);
if ($balanceCents === 0) {
@@ -129,6 +135,24 @@ class InvoiceLedgerService
return $this->invoiceModel->find($invoiceId);
}
protected function isCarryForwardInvoice(array $invoice): bool
{
$invoiceNumber = (string) ($invoice['invoice_number'] ?? '');
if (str_starts_with($invoiceNumber, 'CF-')) {
return true;
}
if (strcasecmp((string) ($invoice['semester'] ?? ''), 'Opening Balance') === 0) {
return true;
}
$description = strtolower((string) ($invoice['description'] ?? ''));
return str_contains($description, 'carried over')
|| str_contains($description, 'carry-forward')
|| str_contains($description, 'previous school year');
}
protected function calculateTuitionTotal(array $invoice): float
{
$parentId = (int) ($invoice['parent_id'] ?? 0);