fix(billing): address code review issues - ALTER TABLE syntax, null period handling, type detection

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/e8da2cb7-dbf1-4296-b25d-766f8e099581

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-02 12:23:23 +00:00 committed by GitHub
parent 4a1b5bc725
commit 3066d9c75c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 20 deletions

View file

@ -171,7 +171,16 @@ class BillingService
// If current expiry is in the future, extend from it; otherwise reset from period_end
$currentExpiry = $home['billing_expires_at'] ?? null;
if ($currentExpiry && strtotime($currentExpiry) > time()) {
$currentPeriodSecs = strtotime($invoiceRow['period_end'] ?? $now) - strtotime($invoiceRow['period_start'] ?? $now);
// Calculate the period length from the invoice; fall back to rate_type if dates are missing
$periodStart = $invoiceRow['period_start'] ?? null;
$periodEndVal = $invoiceRow['period_end'] ?? null;
if ($periodStart && $periodEndVal) {
$currentPeriodSecs = strtotime($periodEndVal) - strtotime($periodStart);
} else {
$rateType2 = $invoiceRow['rate_type'] ?? 'monthly';
$periodSecMap = ['daily' => 86400, 'monthly' => 31 * 86400, 'yearly' => 365 * 86400];
$currentPeriodSecs = $periodSecMap[$rateType2] ?? (31 * 86400);
}
$newExpiry = date('Y-m-d H:i:s', strtotime($currentExpiry) + max(86400, $currentPeriodSecs));
} else {
$newExpiry = $periodEnd;