BOC v1.0: RS256 auth, Ledger integration, Prometheus metrics, CI/CD, backup
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MockLedgerHandler provides mock data when real ledger is unavailable
|
||||
type MockLedgerHandler struct{}
|
||||
|
||||
func NewMockLedgerHandler() *MockLedgerHandler {
|
||||
return &MockLedgerHandler{}
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetBalanceSheet(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"assets": []map[string]interface{}{
|
||||
{"account": "1930 - Checkkonto", "amount": 245000},
|
||||
{"account": "1940 - Sparkonto", "amount": 500000},
|
||||
{"account": "1510 - Kundfordringar", "amount": 125000},
|
||||
},
|
||||
"liabilities": []map[string]interface{}{
|
||||
{"account": "2440 - Leverantörsskulder", "amount": 85000},
|
||||
{"account": "2013 - Aktiekapital", "amount": 100000},
|
||||
},
|
||||
"equity": []map[string]interface{}{
|
||||
{"account": "2091 - Balanserad vinst", "amount": 485000},
|
||||
},
|
||||
"total_assets": 870000,
|
||||
"total_liabilities": 185000,
|
||||
"total_equity": 685000,
|
||||
"period": time.Now().Format("2006-01"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetIncomeStatement(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"revenue": []map[string]interface{}{
|
||||
{"account": "3001 - Försäljning tjänster", "amount": 450000},
|
||||
{"account": "3002 - Försäljning produkter", "amount": 125000},
|
||||
},
|
||||
"expenses": []map[string]interface{}{
|
||||
{"account": "6100 - Löner", "amount": 180000},
|
||||
{"account": "6200 - Hyra", "amount": 45000},
|
||||
{"account": "6300 - Marknadsföring", "amount": 35000},
|
||||
{"account": "6400 - IT-kostnader", "amount": 25000},
|
||||
},
|
||||
"total_revenue": 575000,
|
||||
"total_expenses": 285000,
|
||||
"net_income": 290000,
|
||||
"period": time.Now().Format("2006-01"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetMomsReport(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"moms_in": 143750,
|
||||
"moms_ut": 71250,
|
||||
"moms_att_betala": 72500,
|
||||
"period": time.Now().Format("2006-01"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetAccounts(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"accounts": []map[string]interface{}{
|
||||
{"id": "1930", "name": "Checkkonto", "type": "asset", "balance": 245000},
|
||||
{"id": "1940", "name": "Sparkonto", "type": "asset", "balance": 500000},
|
||||
{"id": "1510", "name": "Kundfordringar", "type": "asset", "balance": 125000},
|
||||
{"id": "2440", "name": "Leverantörsskulder", "type": "liability", "balance": 85000},
|
||||
{"id": "2013", "name": "Aktiekapital", "type": "equity", "balance": 100000},
|
||||
{"id": "2091", "name": "Balanserad vinst", "type": "equity", "balance": 485000},
|
||||
{"id": "3001", "name": "Försäljning tjänster", "type": "revenue", "balance": 450000},
|
||||
{"id": "6100", "name": "Löner", "type": "expense", "balance": 180000},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetInvoices(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"invoices": []map[string]interface{}{
|
||||
{"id": "INV-001", "customer": "Test AB", "amount": 25000, "status": "paid", "due_date": "2026-07-30"},
|
||||
{"id": "INV-002", "customer": "Acme Corp", "amount": 45000, "status": "pending", "due_date": "2026-08-15"},
|
||||
{"id": "INV-003", "customer": "Stark Industries", "amount": 125000, "status": "overdue", "due_date": "2026-06-30"},
|
||||
},
|
||||
"total": 3,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetCashflow(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"inflow": 320000,
|
||||
"outflow": 180000,
|
||||
"net": 140000,
|
||||
"period": time.Now().Format("2006-01"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) GetBudget(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"budget": 500000,
|
||||
"actual": 245000,
|
||||
"remaining": 255000,
|
||||
"period": time.Now().Format("2006-01"),
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) CreateExpense(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"id": "EXP-001",
|
||||
"status": "created",
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MockLedgerHandler) ListExpenses(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"expenses": []map[string]interface{}{
|
||||
{"id": "EXP-001", "category": "Boende", "amount": 8500, "date": "2026-07-01"},
|
||||
{"id": "EXP-002", "category": "Mat", "amount": 3200, "date": "2026-07-05"},
|
||||
{"id": "EXP-003", "category": "Resa", "amount": 4500, "date": "2026-07-10"},
|
||||
},
|
||||
"total": 3,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user