fix payments

This commit is contained in:
root
2026-07-08 23:30:16 -04:00
parent 6e8da3cc2c
commit ed11cccecc
15 changed files with 959 additions and 132 deletions
@@ -9,7 +9,11 @@ class FinancialSystemLedgerCleanup extends Migration
public function up()
{
$this->addInstallmentSequenceColumn();
$this->backfillInstallmentSequence();
$this->ensurePaymentDateHasTime();
$this->ensureIndexes();
$this->repairPaymentInvoiceTerms();
$this->normalizePaymentStatuses();
$this->ensureConfigurationDefaults();
$this->archivePaypalTables();
$this->refreshFinancialNavItems();
@@ -24,6 +28,7 @@ class FinancialSystemLedgerCleanup extends Migration
}
$this->dropIndexIfExists('payments', 'idx_payments_invoice_id');
$this->dropIndexIfExists('payments', 'idx_payments_parent_year');
$this->dropIndexIfExists('payments', 'idx_payments_parent_year_semester');
$this->dropIndexIfExists('payments', 'uniq_payments_transaction_id');
$this->dropIndexIfExists('invoices', 'idx_invoices_parent_year_semester');
@@ -68,10 +73,33 @@ class FinancialSystemLedgerCleanup extends Migration
}
}
protected function backfillInstallmentSequence(): void
{
if (!$this->db->tableExists('payments') || !$this->db->fieldExists('installment_seq', 'payments')) {
return;
}
$this->db->query(
'UPDATE `payments`
SET `installment_seq` = `number_of_installments`
WHERE `installment_seq` IS NULL'
);
}
protected function ensurePaymentDateHasTime(): void
{
if (!$this->db->tableExists('payments') || !$this->db->fieldExists('payment_date', 'payments')) {
return;
}
$this->db->query('ALTER TABLE `payments` MODIFY `payment_date` DATETIME NOT NULL');
}
protected function ensureIndexes(): void
{
$this->addIndexIfMissing('payments', 'idx_payments_invoice_id', ['invoice_id']);
$this->addIndexIfMissing('payments', 'idx_payments_parent_year_semester', ['parent_id', 'school_year', 'semester']);
$this->dropIndexIfExists('payments', 'idx_payments_parent_year_semester');
$this->addIndexIfMissing('payments', 'idx_payments_parent_year', ['parent_id', 'school_year']);
$this->addIndexIfMissing('invoices', 'idx_invoices_parent_year_semester', ['parent_id', 'school_year', 'semester']);
$this->addIndexIfMissing('discount_usages', 'idx_discount_usages_invoice_id', ['invoice_id']);
$this->addIndexIfMissing('discount_usages', 'idx_discount_usages_parent_year_semester', ['parent_id', 'school_year', 'semester']);
@@ -86,6 +114,33 @@ class FinancialSystemLedgerCleanup extends Migration
}
}
protected function repairPaymentInvoiceTerms(): void
{
if (!$this->db->tableExists('payments') || !$this->db->tableExists('invoices')) {
return;
}
$this->db->query(
'UPDATE `payments` p
JOIN `invoices` i ON i.`id` = p.`invoice_id`
SET p.`school_year` = i.`school_year`
WHERE COALESCE(p.`school_year`, \'\') <> COALESCE(i.`school_year`, \'\')'
);
}
protected function normalizePaymentStatuses(): void
{
if (!$this->db->tableExists('payments') || !$this->db->fieldExists('status', 'payments')) {
return;
}
$this->db->query(
"UPDATE `payments`
SET `status` = 'recorded'
WHERE LOWER(TRIM(`status`)) IN ('paid', 'partially paid', 'payment recorded', 'full', 'completed')"
);
}
protected function ensureConfigurationDefaults(): void
{
if (!$this->db->tableExists('configuration')) {