fix invoice and enrollment fees
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 48s
Tests / PHPUnit (push) Failing after 1m19s

This commit is contained in:
root
2026-08-27 18:34:36 -04:00
parent 0ae9993d82
commit 38644b32ae
29 changed files with 1836 additions and 1555 deletions
+1 -27
View File
@@ -2,25 +2,22 @@
namespace App\Libraries;
use App\Models\InvoiceLineModel;
use App\Models\InvoiceModel;
class InvoiceIssuanceService
{
private \CodeIgniter\Database\BaseConnection $db;
private InvoiceModel $invoiceModel;
private InvoiceLineModel $invoiceLineModel;
private InvoiceLedgerService $invoiceLedgerService;
public function __construct(
?\CodeIgniter\Database\BaseConnection $db = null,
?InvoiceModel $invoiceModel = null,
?InvoiceLineModel $invoiceLineModel = null,
$invoiceLineModel = null,
?InvoiceLedgerService $invoiceLedgerService = null
) {
$this->db = $db ?? db_connect();
$this->invoiceModel = $invoiceModel ?? new InvoiceModel();
$this->invoiceLineModel = $invoiceLineModel ?? new InvoiceLineModel();
$this->invoiceLedgerService = $invoiceLedgerService ?? new InvoiceLedgerService();
}
@@ -45,29 +42,6 @@ class InvoiceIssuanceService
$this->db->query('SELECT id FROM invoices WHERE id = ? FOR UPDATE', [(int)$invoiceId]);
$inserted = $this->invoiceLedgerService->issueInitialInvoiceLines(
(int)$invoiceId,
$command->tuitionAmount,
$command->eventAmount,
$command->metadata
);
if ($inserted <= 0) {
throw new FinancialPersistenceException('INVOICE_ISSUE_NO_LINES');
}
$lineTotals = $this->db->table('invoice_lines')
->select('COUNT(*) AS line_count, COALESCE(SUM(line_amount_cents),0) AS total_cents')
->where('invoice_id', (int)$invoiceId)
->where('voided_at IS NULL', null, false)
->get()
->getRowArray();
if ((int)($lineTotals['line_count'] ?? 0) !== $inserted) {
throw new FinancialPersistenceException('INVOICE_ISSUE_LINE_COUNT_MISMATCH');
}
if ((int)($lineTotals['total_cents'] ?? 0) === 0) {
throw new FinancialPersistenceException('INVOICE_ISSUE_ZERO_LINE_TOTAL');
}
$this->requireWrite($this->invoiceModel->update((int)$invoiceId, [
'status' => FinancialStatus::INVOICE_ISSUED,
'updated_at' => utc_now(),