feat: add option to exclude year-end closing entries in SIE export and related reports (#567)
This commit is contained in:
@@ -16,7 +16,13 @@ export async function generateIncomeStatement(
|
||||
companyId: string,
|
||||
fiscalPeriodId: string
|
||||
): Promise<IncomeStatementReport> {
|
||||
const { rows } = await generateTrialBalance(supabase, companyId, fiscalPeriodId)
|
||||
// Exclude year-end closing entries: after closing, P&L accounts (3-8) are
|
||||
// zeroed by the closing verifikat (8999 → 2099). Including them collapses
|
||||
// the resultaträkning to zero. The income statement must reflect the
|
||||
// pre-closing activity for the year.
|
||||
const { rows } = await generateTrialBalance(supabase, companyId, fiscalPeriodId, {
|
||||
excludeYearEndClosing: true,
|
||||
})
|
||||
|
||||
// Filter to income/expense accounts (class 3-8)
|
||||
const incomeExpenseRows = rows.filter(
|
||||
|
||||
@@ -57,7 +57,7 @@ export async function generateSIEExport(
|
||||
)
|
||||
|
||||
// Fetch all posted journal entries with lines
|
||||
const { data: entries } = await supabase
|
||||
let entriesQuery = supabase
|
||||
.from('journal_entries')
|
||||
.select('*, lines:journal_entry_lines(*)')
|
||||
.eq('company_id', companyId)
|
||||
@@ -65,6 +65,12 @@ export async function generateSIEExport(
|
||||
.in('status', ['posted', 'reversed'])
|
||||
.order('voucher_number')
|
||||
|
||||
if (options.exclude_year_end_closing) {
|
||||
entriesQuery = entriesQuery.neq('source_type', 'year_end')
|
||||
}
|
||||
|
||||
const { data: entries } = await entriesQuery
|
||||
|
||||
// Fetch cost centers and projects for dimension records
|
||||
const { data: costCenters } = await supabase
|
||||
.from('cost_centers')
|
||||
|
||||
@@ -16,7 +16,8 @@ import type { TrialBalanceRow } from '@/types'
|
||||
export async function generateTrialBalance(
|
||||
supabase: SupabaseClient,
|
||||
companyId: string,
|
||||
fiscalPeriodId: string
|
||||
fiscalPeriodId: string,
|
||||
options?: { excludeYearEndClosing?: boolean }
|
||||
): Promise<{
|
||||
rows: TrialBalanceRow[]
|
||||
totalDebit: number
|
||||
@@ -51,7 +52,7 @@ export async function generateTrialBalance(
|
||||
}>(({ from, to }) => {
|
||||
let query = supabase
|
||||
.from('journal_entry_lines')
|
||||
.select('account_number, debit_amount, credit_amount, journal_entries!inner(company_id, fiscal_period_id, status)')
|
||||
.select('account_number, debit_amount, credit_amount, journal_entries!inner(company_id, fiscal_period_id, status, source_type)')
|
||||
.eq('journal_entries.company_id', companyId)
|
||||
.eq('journal_entries.fiscal_period_id', fiscalPeriodId)
|
||||
.in('journal_entries.status', ['posted', 'reversed'])
|
||||
@@ -60,6 +61,10 @@ export async function generateTrialBalance(
|
||||
query = query.neq('journal_entry_id', obEntryId)
|
||||
}
|
||||
|
||||
if (options?.excludeYearEndClosing) {
|
||||
query = query.neq('journal_entries.source_type', 'year_end')
|
||||
}
|
||||
|
||||
return query.range(from, to)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user