feat: BOC ledger-integration frontend + backend fixes
- Uppdatera robust_client.go med rätt tabellnamn (boc_chart_of_accounts, boc_journal_lines, boc_journal_entries) - Uppdatera kolumnnamn (entry_id istället för journal_entry_id, account_code istället för code) - Hantera både stora och små bokstäver för account_type - Lägg till ledgerApi i frontend med BalanceSheet, IncomeStatement, MomsReport - Uppdatera DashboardPage med Ledger KPI-kort - Lägg till LEDGER_DB_URL i docker-compose.yml - Uppdatera Dockerfile till golang:1.25-alpine
This commit is contained in:
@@ -44,13 +44,13 @@ type LedgerAccount struct {
|
||||
// GetAccounts returns all BAS accounts with balances
|
||||
func (c *RobustClient) GetAccounts(ctx context.Context) ([]LedgerAccount, error) {
|
||||
rows, err := c.db.QueryContext(ctx, `
|
||||
SELECT a.code, a.name, a.account_type,
|
||||
SELECT a.account_code, a.name, a.account_type,
|
||||
COALESCE(SUM(CASE WHEN jl.debit IS NOT NULL THEN jl.debit ELSE 0 END) -
|
||||
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
|
||||
GROUP BY a.id, a.code, a.name, a.account_type
|
||||
ORDER BY a.code
|
||||
FROM boc_chart_of_accounts a
|
||||
LEFT JOIN boc_journal_lines jl ON a.id = jl.account_id
|
||||
GROUP BY a.id, a.account_code, a.name, a.account_type
|
||||
ORDER BY a.account_code
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query accounts: %w", err)
|
||||
@@ -87,14 +87,14 @@ func (c *RobustClient) GetBalanceSheet(ctx context.Context, period string) (*Bal
|
||||
}
|
||||
|
||||
rows, err := c.db.QueryContext(ctx, `
|
||||
SELECT a.code, a.name, a.account_type,
|
||||
SELECT a.account_code, a.name, a.account_type,
|
||||
COALESCE(SUM(CASE WHEN jl.debit IS NOT NULL THEN jl.debit ELSE 0 END) -
|
||||
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.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
|
||||
FROM boc_chart_of_accounts a
|
||||
LEFT JOIN boc_journal_lines jl ON a.id = jl.account_id
|
||||
LEFT JOIN boc_journal_entries je ON jl.entry_id = je.id AND je.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
|
||||
GROUP BY a.id, a.account_code, a.name, a.account_type
|
||||
ORDER BY a.account_code
|
||||
`, period+"-01")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query balance sheet: %w", err)
|
||||
@@ -109,13 +109,13 @@ func (c *RobustClient) GetBalanceSheet(ctx context.Context, period string) (*Bal
|
||||
}
|
||||
|
||||
switch a.AccountType {
|
||||
case "Asset":
|
||||
case "Asset", "asset":
|
||||
bs.Assets = append(bs.Assets, a)
|
||||
bs.TotalAssets += a.Balance
|
||||
case "Liability":
|
||||
case "Liability", "liability":
|
||||
bs.Liabilities = append(bs.Liabilities, a)
|
||||
bs.TotalLiabilities += a.Balance
|
||||
case "Equity":
|
||||
case "Equity", "equity":
|
||||
bs.Equity = append(bs.Equity, a)
|
||||
bs.TotalEquity += a.Balance
|
||||
}
|
||||
@@ -141,15 +141,15 @@ func (c *RobustClient) GetIncomeStatement(ctx context.Context, period string) (*
|
||||
}
|
||||
|
||||
rows, err := c.db.QueryContext(ctx, `
|
||||
SELECT a.code, a.name, a.account_type,
|
||||
SELECT a.account_code, a.name, a.account_type,
|
||||
COALESCE(SUM(CASE WHEN jl.debit IS NOT NULL THEN jl.debit ELSE 0 END) -
|
||||
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.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
|
||||
FROM boc_chart_of_accounts a
|
||||
LEFT JOIN boc_journal_lines jl ON a.id = jl.account_id
|
||||
LEFT JOIN boc_journal_entries je ON jl.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
|
||||
GROUP BY a.id, a.account_code, a.name, a.account_type
|
||||
ORDER BY a.account_code
|
||||
`, period+"-01")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query income statement: %w", err)
|
||||
@@ -164,10 +164,10 @@ func (c *RobustClient) GetIncomeStatement(ctx context.Context, period string) (*
|
||||
}
|
||||
|
||||
switch a.AccountType {
|
||||
case "Revenue":
|
||||
case "Revenue", "revenue":
|
||||
is.Revenues = append(is.Revenues, a)
|
||||
is.TotalRevenue += a.Balance
|
||||
case "Expense":
|
||||
case "Expense", "expense":
|
||||
is.Expenses = append(is.Expenses, a)
|
||||
is.TotalExpense += a.Balance
|
||||
}
|
||||
@@ -197,11 +197,11 @@ func (c *RobustClient) GetMomsReport(ctx context.Context, period string) (*MomsR
|
||||
// Moms in (utgående moms från försäljning)
|
||||
err := c.db.QueryRowContext(ctx, `
|
||||
SELECT COALESCE(SUM(jl.credit), 0)
|
||||
FROM journal_lines jl
|
||||
JOIN journal_entries je ON jl.journal_entry_id = je.id
|
||||
JOIN accounts a ON jl.account_id = a.id
|
||||
FROM boc_journal_lines jl
|
||||
JOIN boc_journal_entries je ON jl.entry_id = je.id
|
||||
JOIN boc_chart_of_accounts a ON jl.account_id = a.id
|
||||
WHERE je.entry_date >= $1::date AND je.entry_date < ($1::date + INTERVAL '1 month')
|
||||
AND a.code LIKE '26%'
|
||||
AND a.account_code LIKE '26%'
|
||||
`, period+"-01").Scan(&report.MomsUt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query moms ut: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user