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:
Bernt
2026-07-29 19:53:39 +00:00
parent f367eaadb8
commit bd28b60338
14 changed files with 671 additions and 488 deletions
+89
View File
@@ -0,0 +1,89 @@
package handlers
import (
"encoding/json"
"net/http"
"boc/ledger"
)
var ledgerDBURL = getEnv("LEDGER_DB_URL", "postgres://wavult_admin:efG15aKjqgu7uotZoAiLTRBtBDMoXITxIe9Hi6EB@platform-identity-core.cvi0qcksmsfj.eu-north-1.rds.amazonaws.com:5432/amos?sslmode=disable")
// LedgerV2Handler uses direct DB connection for reliable data
type LedgerV2Handler struct {
client *ledger.RobustClient
}
// NewLedgerV2Handler creates a handler with DB connection
func NewLedgerV2Handler() (*LedgerV2Handler, error) {
client, err := ledger.NewRobustClient(ledgerDBURL)
if err != nil {
return nil, err
}
return &LedgerV2Handler{client: client}, nil
}
// GetAccounts returns all BAS accounts
func (h *LedgerV2Handler) GetAccounts(w http.ResponseWriter, r *http.Request) {
accounts, err := h.client.GetAccounts(r.Context())
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"accounts": accounts,
})
}
// GetBalanceSheet returns balance sheet for a period
func (h *LedgerV2Handler) GetBalanceSheet(w http.ResponseWriter, r *http.Request) {
period := r.URL.Query().Get("period")
if period == "" {
period = "2026-01"
}
bs, err := h.client.GetBalanceSheet(r.Context(), period)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(bs)
}
// GetIncomeStatement returns P&L for a period
func (h *LedgerV2Handler) GetIncomeStatement(w http.ResponseWriter, r *http.Request) {
period := r.URL.Query().Get("period")
if period == "" {
period = "2026-01"
}
is, err := h.client.GetIncomeStatement(r.Context(), period)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(is)
}
// GetMomsReport returns VAT report for a period
func (h *LedgerV2Handler) GetMomsReport(w http.ResponseWriter, r *http.Request) {
period := r.URL.Query().Get("period")
if period == "" {
period = "2026-01"
}
report, err := h.client.GetMomsReport(r.Context(), period)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(report)
}