Added Wizard for Month/Year End Close
This commit is contained in:
@@ -7,7 +7,13 @@ const { all, audit, now, one, run } = require('../db');
|
||||
const TYPES = ['asset', 'contra_asset', 'liability', 'equity', 'revenue', 'expense'];
|
||||
const BALANCES = ['debit', 'credit'];
|
||||
// Used as a last-resort fallback if a company somehow has no defaults row (seed normally creates one).
|
||||
const FALLBACK_DEFAULTS = { asset_account: '1500', accumulated_account: '1590', expense_account: '6400', pm_expense_account: '6450', pm_clearing_account: '2000' };
|
||||
const FALLBACK_DEFAULTS = {
|
||||
asset_account: '1500', accumulated_account: '1590', expense_account: '6400',
|
||||
pm_expense_account: '6450', pm_clearing_account: '2000',
|
||||
cwip_account: '1800', gain_account: '7200', loss_account: '7300',
|
||||
proceeds_account: '1010', retained_earnings_account: '3900'
|
||||
};
|
||||
const DEFAULT_KEYS = Object.keys(FALLBACK_DEFAULTS);
|
||||
|
||||
function fromRow(row) {
|
||||
if (!row) return null;
|
||||
@@ -85,17 +91,22 @@ function getDefaults(companyId) {
|
||||
|
||||
function saveDefaults(body, userId, companyId) {
|
||||
const before = getDefaults(companyId);
|
||||
const keys = ['asset_account', 'accumulated_account', 'expense_account', 'pm_expense_account', 'pm_clearing_account'];
|
||||
const next = {};
|
||||
for (const key of keys) next[key] = body[key] !== undefined ? (String(body[key] || '').trim() || null) : (before[key] || null);
|
||||
for (const key of DEFAULT_KEYS) next[key] = body[key] !== undefined ? (String(body[key] || '').trim() || null) : (before[key] || null);
|
||||
run(
|
||||
`INSERT INTO gl_account_defaults (entity_id, asset_account, accumulated_account, expense_account, pm_expense_account, pm_clearing_account, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`INSERT INTO gl_account_defaults
|
||||
(entity_id, asset_account, accumulated_account, expense_account, pm_expense_account, pm_clearing_account,
|
||||
cwip_account, gain_account, loss_account, proceeds_account, retained_earnings_account, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(entity_id) DO UPDATE SET
|
||||
asset_account = excluded.asset_account, accumulated_account = excluded.accumulated_account,
|
||||
expense_account = excluded.expense_account, pm_expense_account = excluded.pm_expense_account,
|
||||
pm_clearing_account = excluded.pm_clearing_account, updated_at = excluded.updated_at`,
|
||||
[companyId, next.asset_account, next.accumulated_account, next.expense_account, next.pm_expense_account, next.pm_clearing_account, now()]
|
||||
pm_clearing_account = excluded.pm_clearing_account, cwip_account = excluded.cwip_account,
|
||||
gain_account = excluded.gain_account, loss_account = excluded.loss_account,
|
||||
proceeds_account = excluded.proceeds_account, retained_earnings_account = excluded.retained_earnings_account,
|
||||
updated_at = excluded.updated_at`,
|
||||
[companyId, next.asset_account, next.accumulated_account, next.expense_account, next.pm_expense_account, next.pm_clearing_account,
|
||||
next.cwip_account, next.gain_account, next.loss_account, next.proceeds_account, next.retained_earnings_account, now()]
|
||||
);
|
||||
const after = getDefaults(companyId);
|
||||
audit(userId, 'update', 'gl_account_defaults', companyId, before, after);
|
||||
|
||||
Reference in New Issue
Block a user