got a exporter for forecasting

This commit is contained in:
samantha42
2026-03-21 18:42:54 +01:00
parent 6c5b4bae67
commit 8a8a64c8af
6 changed files with 259 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
package model
import "time"
import (
"fmt"
"time"
)
type GLAccountType string
@@ -361,3 +364,77 @@ type PnLRequest struct {
DeptCodes []string
Version BudgetVersion
}
// ForecastIngestRequest is the payload an external model POSTs back
// after consuming the export endpoint.
type ForecastIngestRequest struct {
Department string `json:"department"`
FiscalYear int `json:"fiscal_year"`
Version BudgetVersion `json:"version"`
CreatedBy string `json:"created_by"`
Lines []ForecastLine `json:"lines"`
}
type ForecastLine struct {
FiscalPeriod int `json:"period"`
GLCode string `json:"gl_code"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
}
func (f *ForecastIngestRequest) Valid() []string {
var errs []string
if f.Department == "" {
errs = append(errs, "department is required")
}
if f.FiscalYear < 1 || f.FiscalYear > 2200 {
errs = append(errs, "fiscal_year must be between 1 and 2200")
}
if f.Version == "" {
errs = append(errs, "version is required")
}
if f.Version == VersionOriginal {
errs = append(errs, "version cannot be original — forecasts must use forecast_1, forecast_2, or forecast_3")
}
if f.CreatedBy == "" {
errs = append(errs, "created_by is required")
}
if len(f.Lines) == 0 {
errs = append(errs, "lines must contain at least one record")
}
for i, line := range f.Lines {
if line.FiscalPeriod < 1 || line.FiscalPeriod > 12 {
errs = append(errs, fmt.Sprintf("lines[%d]: period must be between 1 and 12", i))
}
if line.GLCode == "" {
errs = append(errs, fmt.Sprintf("lines[%d]: gl_code is required", i))
}
if line.Amount <= 0 {
errs = append(errs, fmt.Sprintf("lines[%d]: amount must be greater than 0", i))
}
if line.Currency == "" {
errs = append(errs, fmt.Sprintf("lines[%d]: currency is required", i))
}
}
return errs
}
type ForecastPeriodRow struct {
FiscalPeriod int `json:"period"`
GLCode string `json:"gl_code"`
GLType GLAccountType `json:"gl_type,omitempty"`
Amount float64 `json:"amount"`
Currency string `json:"currency,omitempty"`
}
type ForecastExport struct {
Department string `json:"department"`
FiscalYear int `json:"fiscal_year"`
Version BudgetVersion `json:"version"`
PeriodsActual []ForecastPeriodRow `json:"periods_actual"`
PeriodsBudget []ForecastPeriodRow `json:"periods_budget"`
RemainingPeriods []int `json:"remaining_periods"`
}