Updated GL system allows changing account defaults and add/updating journal entries
This commit is contained in:
@@ -4,12 +4,7 @@ const { ruleSetForBook } = require('./ruleSets');
|
||||
const { computeYear } = require('./reportEngine');
|
||||
const { assetFromRow } = require('./assets');
|
||||
const { pmBookLedger } = require('./pm');
|
||||
|
||||
const DEFAULT_ACCOUNTS = {
|
||||
asset: '1500',
|
||||
accumulated: '1590',
|
||||
expense: '6400'
|
||||
};
|
||||
const { getDefaults } = require('./glAccounts');
|
||||
|
||||
function bookFromRow(row) {
|
||||
return {
|
||||
@@ -20,6 +15,9 @@ function bookFromRow(row) {
|
||||
}
|
||||
|
||||
function listBooks(companyId) {
|
||||
// book.code is unique only per company, and asset_books link by code string — so the asset_count
|
||||
// subquery joins through to the asset and matches a.entity_id = b.entity_id to count only this
|
||||
// company's assets on this company's book.
|
||||
const books = all(
|
||||
`SELECT b.*, t.name AS tax_rule_set_name, t.version AS tax_rule_set_version,
|
||||
(SELECT COUNT(*) FROM asset_books ab JOIN assets a ON a.id = ab.asset_id
|
||||
@@ -115,6 +113,7 @@ function bookLedger(code, year, companyId) {
|
||||
return { ...pmBookLedger(year, companyId), book };
|
||||
}
|
||||
const rules = ruleSetForBook(code);
|
||||
const defaults = getDefaults(companyId); // per-company fallback accounts (admin-configurable)
|
||||
const rows = all(
|
||||
`SELECT a.*, b.cost AS book_cost, b.depreciation_method, b.convention,
|
||||
b.useful_life_months AS book_life, b.section_179_amount, b.bonus_percent,
|
||||
@@ -152,9 +151,9 @@ function bookLedger(code, year, companyId) {
|
||||
manual_depreciation: row.manual_depreciation
|
||||
};
|
||||
const c = computeYear(asset, bk, rules, year);
|
||||
const assetAccount = asset.gl_asset_account || DEFAULT_ACCOUNTS.asset;
|
||||
const accumAccount = asset.gl_accumulated_account || DEFAULT_ACCOUNTS.accumulated;
|
||||
const expenseAccount = asset.gl_expense_account || DEFAULT_ACCOUNTS.expense;
|
||||
const assetAccount = asset.gl_asset_account || defaults.asset_account;
|
||||
const accumAccount = asset.gl_accumulated_account || defaults.accumulated_account;
|
||||
const expenseAccount = asset.gl_expense_account || defaults.expense_account;
|
||||
|
||||
addLine(assetAccount, 'Asset cost', c.cost, 0);
|
||||
addLine(accumAccount, 'Accumulated depreciation', 0, c.accumulated_end);
|
||||
|
||||
Reference in New Issue
Block a user