fix: BOC ledger-integration — fixa robust_client för riktig DB-schema

- Uppdatera GetBalanceSheet att använda entry_date istället för period
- Uppdatera GetIncomeStatement att använda entry_date istället för period
- Uppdatera GetMomsReport att använda entry_date och ta bort status
- Lägg till integrationstester som verifierar mot riktig DB
- Alla tester passerar: GetAccounts, GetBalanceSheet, GetIncomeStatement, GetMomsReport
This commit is contained in:
Bernt
2026-07-29 19:24:03 +00:00
parent e5623d2f84
commit f367eaadb8
3 changed files with 76 additions and 6 deletions
+6 -6
View File
@@ -92,10 +92,10 @@ func (c *RobustClient) GetBalanceSheet(ctx context.Context, period string) (*Bal
SUM(CASE WHEN jl.credit IS NOT NULL THEN jl.credit ELSE 0 END), 0) as balance
FROM accounts a
LEFT JOIN journal_lines jl ON a.id = jl.account_id
LEFT JOIN journal_entries je ON jl.journal_entry_id = je.id AND je.period = $1 AND je.status = 'posted'
LEFT JOIN journal_entries je ON jl.journal_entry_id = je.id AND je.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
GROUP BY a.id, a.code, a.name, a.account_type
ORDER BY a.code
`, period)
`, period+"-01")
if err != nil {
return nil, fmt.Errorf("query balance sheet: %w", err)
}
@@ -146,11 +146,11 @@ func (c *RobustClient) GetIncomeStatement(ctx context.Context, period string) (*
SUM(CASE WHEN jl.credit IS NOT NULL THEN jl.credit ELSE 0 END), 0) as balance
FROM accounts a
LEFT JOIN journal_lines jl ON a.id = jl.account_id
LEFT JOIN journal_entries je ON jl.journal_entry_id = je.id AND je.period = $1 AND je.status = 'posted'
LEFT JOIN journal_entries je ON jl.journal_entry_id = je.id AND je.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
WHERE a.account_type IN ('Revenue', 'Expense')
GROUP BY a.id, a.code, a.name, a.account_type
ORDER BY a.code
`, period)
`, period+"-01")
if err != nil {
return nil, fmt.Errorf("query income statement: %w", err)
}
@@ -200,9 +200,9 @@ func (c *RobustClient) GetMomsReport(ctx context.Context, period string) (*MomsR
FROM journal_lines jl
JOIN journal_entries je ON jl.journal_entry_id = je.id
JOIN accounts a ON jl.account_id = a.id
WHERE je.period = $1 AND je.status = 'posted'
WHERE je.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
AND a.code LIKE '26%'
`, period).Scan(&report.MomsUt)
`, period+"-01").Scan(&report.MomsUt)
if err != nil {
return nil, fmt.Errorf("query moms ut: %w", err)
}