38471-vm/db/migrations/20260503_seed_chart_of_accounts.php
2026-05-03 02:57:40 +00:00

23 lines
740 B
PHP

<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/config.php';
require_once dirname(__DIR__, 2) . '/includes/accounting_helper.php';
if (function_exists('ensureAccountingSchema')) {
ensureAccountingSchema();
}
$added = function_exists('seedDefaultAccountingAccounts') ? seedDefaultAccountingAccounts() : 0;
$total = 0;
try {
$total = (int) db()->query('SELECT COUNT(*) FROM acc_accounts')->fetchColumn();
} catch (Throwable $e) {
error_log('Chart of accounts count failed: ' . $e->getMessage());
}
echo $added > 0
? sprintf('Chart of accounts seeded successfully. Added %d account(s); total is now %d.', $added, $total)
: sprintf('Chart of accounts already up to date. Total accounts: %d.', $total);