accounting

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceTypeYearEndCarryForward         = "YEAR_END_CARRY_FORWARD"
	SourceTypeYearEndCarryForwardReversal = "YEAR_END_CARRY_FORWARD_REVERSAL"
)
View Source
const (
	// SourceTypeJournalTemplate marks journal entries generated from reusable templates.
	SourceTypeJournalTemplate = "JOURNAL_TEMPLATE"
)

Variables

View Source
var (
	ErrTemplateEvidenceAutoPost = errors.New("cannot auto-post a template entry that requires evidence")
	ErrSystemAccountImmutable   = errors.New("system accounts cannot be modified")
)

Functions

func IsFiscalYearEndPeriod

func IsFiscalYearEndPeriod(rawPeriodEndDate string, fiscalYearStartMonth int) (bool, error)

IsFiscalYearEndPeriod reports whether a period end date matches the tenant fiscal year end.

func YearEndCarryForwardSourceID

func YearEndCarryForwardSourceID(tenantID string, fiscalYearEndDate time.Time) string

YearEndCarryForwardSourceID returns the deterministic source UUID used for a fiscal year.

func YearEndCloseEvidenceEntityID

func YearEndCloseEvidenceEntityID(tenantID, rawPeriodEndDate string) (string, error)

YearEndCloseEvidenceEntityID returns the deterministic document entity UUID used for close-pack evidence.

Types

type Account

type Account struct {
	ID          string      `json:"id"`
	TenantID    string      `json:"tenant_id"`
	Code        string      `json:"code"`
	Name        string      `json:"name"`
	AccountType AccountType `json:"account_type"`
	ParentID    *string     `json:"parent_id,omitempty"`
	IsActive    bool        `json:"is_active"`
	IsSystem    bool        `json:"is_system"`
	Description string      `json:"description,omitempty"`
	CreatedAt   time.Time   `json:"created_at"`
}

Account represents a GL account in the chart of accounts

type AccountBalance

type AccountBalance struct {
	AccountID     string          `json:"account_id"`
	AccountCode   string          `json:"account_code"`
	AccountName   string          `json:"account_name"`
	AccountType   AccountType     `json:"account_type"`
	DebitBalance  decimal.Decimal `json:"debit_balance"`
	CreditBalance decimal.Decimal `json:"credit_balance"`
	NetBalance    decimal.Decimal `json:"net_balance"`
}

AccountBalance represents an account's balance at a point in time

type AccountGroup

type AccountGroup struct {
	Code     string           `json:"code"`
	Name     string           `json:"name"`
	Balance  decimal.Decimal  `json:"balance"`
	Children []AccountBalance `json:"children,omitempty"`
}

AccountGroup represents a group of accounts in a financial report

type AccountHierarchyRow

type AccountHierarchyRow struct {
	Account
	ParentCode  string `json:"parent_code,omitempty"`
	ParentName  string `json:"parent_name,omitempty"`
	Depth       int    `json:"depth"`
	Path        string `json:"path"`
	HasChildren bool   `json:"has_children"`
}

AccountHierarchyRow is a flattened chart-of-accounts hierarchy row.

func BuildAccountHierarchy

func BuildAccountHierarchy(accounts []Account) []AccountHierarchyRow

BuildAccountHierarchy flattens accounts into deterministic parent-child order.

type AccountSummary

type AccountSummary struct {
	ID   string `json:"id"`
	Code string `json:"code"`
	Name string `json:"name"`
}

AccountSummary is a lightweight account reference for workflow responses.

type AccountType

type AccountType string

AccountType represents the type of account in the chart of accounts

const (
	AccountTypeAsset     AccountType = "ASSET"
	AccountTypeLiability AccountType = "LIABILITY"
	AccountTypeEquity    AccountType = "EQUITY"
	AccountTypeRevenue   AccountType = "REVENUE"
	AccountTypeExpense   AccountType = "EXPENSE"
)

func (AccountType) IsDebitNormal

func (t AccountType) IsDebitNormal() bool

IsDebitNormal returns true if account type normally has debit balance

type ApplyJournalEntryTemplateRequest

type ApplyJournalEntryTemplateRequest struct {
	EntryDate   time.Time `json:"entry_date"`
	Description string    `json:"description,omitempty"`
	Reference   string    `json:"reference,omitempty"`
	Post        bool      `json:"post,omitempty"`
	UserID      string    `json:"-"`
}

ApplyJournalEntryTemplateRequest creates a journal entry from a template.

type BalanceSheet

type BalanceSheet struct {
	TenantID         string           `json:"tenant_id"`
	AsOfDate         time.Time        `json:"as_of_date"`
	GeneratedAt      time.Time        `json:"generated_at"`
	Assets           []AccountBalance `json:"assets"`
	Liabilities      []AccountBalance `json:"liabilities"`
	Equity           []AccountBalance `json:"equity"`
	TotalAssets      decimal.Decimal  `json:"total_assets"`
	TotalLiabilities decimal.Decimal  `json:"total_liabilities"`
	TotalEquity      decimal.Decimal  `json:"total_equity"`
	RetainedEarnings decimal.Decimal  `json:"retained_earnings"`
	IsBalanced       bool             `json:"is_balanced"`
}

BalanceSheet represents a balance sheet report as of a specific date

type BudgetPeriod

type BudgetPeriod string

BudgetPeriod represents the budget period for a cost center

const (
	BudgetPeriodMonthly   BudgetPeriod = "MONTHLY"
	BudgetPeriodQuarterly BudgetPeriod = "QUARTERLY"
	BudgetPeriodAnnual    BudgetPeriod = "ANNUAL"
)

type CostAllocation

type CostAllocation struct {
	ID                   string           `json:"id"`
	TenantID             string           `json:"tenant_id"`
	CostCenterID         string           `json:"cost_center_id"`
	JournalEntryLineID   string           `json:"journal_entry_line_id"`
	Amount               decimal.Decimal  `json:"amount"`
	AllocationPercentage *decimal.Decimal `json:"allocation_percentage,omitempty"`
	AllocationDate       time.Time        `json:"allocation_date"`
	Notes                string           `json:"notes,omitempty"`
	CreatedAt            time.Time        `json:"created_at"`
	// Joined fields
	CostCenterCode string `json:"cost_center_code,omitempty"`
	CostCenterName string `json:"cost_center_name,omitempty"`
}

CostAllocation tracks expense allocations to cost centers

type CostAllocationFilters

type CostAllocationFilters struct {
	CostCenterID       string
	JournalEntryLineID string
	StartDate          *time.Time
	EndDate            *time.Time
}

CostAllocationFilters filters cost allocations for review and reporting.

type CostCenter

type CostCenter struct {
	ID           string           `json:"id"`
	TenantID     string           `json:"tenant_id"`
	Code         string           `json:"code"`
	Name         string           `json:"name"`
	Description  string           `json:"description,omitempty"`
	ParentID     *string          `json:"parent_id,omitempty"`
	IsActive     bool             `json:"is_active"`
	BudgetAmount *decimal.Decimal `json:"budget_amount,omitempty"`
	BudgetPeriod BudgetPeriod     `json:"budget_period"`
	CreatedAt    time.Time        `json:"created_at"`
	UpdatedAt    time.Time        `json:"updated_at"`
	// Computed fields for reports
	Children   []CostCenter     `json:"children,omitempty"`
	TotalSpent *decimal.Decimal `json:"total_spent,omitempty"`
	BudgetUsed *decimal.Decimal `json:"budget_used_percentage,omitempty"`
}

CostCenter represents a cost center for expense tracking

type CostCenterGORMRepository

type CostCenterGORMRepository struct {
	// contains filtered or unexported fields
}

CostCenterGORMRepository implements CostCenterRepository with the shared ORM layer.

func NewCostCenterGORMRepository

func NewCostCenterGORMRepository(db *gorm.DB) *CostCenterGORMRepository

func NewCostCenterRepository

func NewCostCenterRepository(db *pgxpool.Pool) *CostCenterGORMRepository

NewCostCenterRepository creates a new ORM-backed cost center repository.

func (*CostCenterGORMRepository) Create

func (r *CostCenterGORMRepository) Create(ctx context.Context, schemaName string, cc *CostCenter) error

Create creates a new cost center

func (*CostCenterGORMRepository) CreateAllocation

func (r *CostCenterGORMRepository) CreateAllocation(ctx context.Context, schemaName string, allocation *CostAllocation) error

CreateAllocation creates a cost allocation row.

func (*CostCenterGORMRepository) Delete

func (r *CostCenterGORMRepository) Delete(ctx context.Context, schemaName, tenantID, costCenterID string) error

Delete deletes a cost center

func (*CostCenterGORMRepository) GetByID

func (r *CostCenterGORMRepository) GetByID(ctx context.Context, schemaName, tenantID, costCenterID string) (*CostCenter, error)

GetByID retrieves a cost center by ID

func (*CostCenterGORMRepository) GetExpensesByPeriod

func (r *CostCenterGORMRepository) GetExpensesByPeriod(ctx context.Context, schemaName, tenantID, costCenterID string, start, end time.Time) (decimal.Decimal, error)

GetExpensesByPeriod gets total expenses for a cost center in a period

func (*CostCenterGORMRepository) List

func (r *CostCenterGORMRepository) List(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]CostCenter, error)

List retrieves all cost centers for a tenant

func (*CostCenterGORMRepository) ListAllocations

func (r *CostCenterGORMRepository) ListAllocations(ctx context.Context, schemaName, tenantID string, filters CostAllocationFilters) ([]CostAllocation, error)

ListAllocations lists cost allocations with optional cost center and date filters.

func (*CostCenterGORMRepository) Update

func (r *CostCenterGORMRepository) Update(ctx context.Context, schemaName string, cc *CostCenter) error

Update updates an existing cost center

type CostCenterReport

type CostCenterReport struct {
	TenantID      string              `json:"tenant_id"`
	PeriodStart   time.Time           `json:"period_start"`
	PeriodEnd     time.Time           `json:"period_end"`
	GeneratedAt   time.Time           `json:"generated_at"`
	CostCenters   []CostCenterSummary `json:"cost_centers"`
	TotalExpenses decimal.Decimal     `json:"total_expenses"`
	TotalBudget   decimal.Decimal     `json:"total_budget"`
}

CostCenterReport is a full report across all cost centers

type CostCenterRepository

type CostCenterRepository interface {
	GetByID(ctx context.Context, schemaName, tenantID, costCenterID string) (*CostCenter, error)
	List(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]CostCenter, error)
	Create(ctx context.Context, schemaName string, cc *CostCenter) error
	Update(ctx context.Context, schemaName string, cc *CostCenter) error
	Delete(ctx context.Context, schemaName, tenantID, costCenterID string) error
	GetExpensesByPeriod(ctx context.Context, schemaName, tenantID, costCenterID string, start, end time.Time) (decimal.Decimal, error)
	CreateAllocation(ctx context.Context, schemaName string, allocation *CostAllocation) error
	ListAllocations(ctx context.Context, schemaName, tenantID string, filters CostAllocationFilters) ([]CostAllocation, error)
}

CostCenterRepository defines the interface for cost center data access

type CostCenterService

type CostCenterService struct {
	// contains filtered or unexported fields
}

CostCenterService provides business logic for cost centers

func NewCostCenterService

func NewCostCenterService(db *pgxpool.Pool) *CostCenterService

NewCostCenterService creates a new cost center service with an ORM-backed repository.

func NewCostCenterServiceWithRepository

func NewCostCenterServiceWithRepository(repo CostCenterRepository) *CostCenterService

NewCostCenterServiceWithRepository creates a new cost center service with a custom repository.

func (*CostCenterService) CreateCostAllocation

func (s *CostCenterService) CreateCostAllocation(ctx context.Context, schemaName, tenantID string, req *CreateCostAllocationRequest) (*CostAllocation, error)

CreateCostAllocation assigns a journal entry line amount to a cost center.

func (*CostCenterService) CreateCostCenter

func (s *CostCenterService) CreateCostCenter(ctx context.Context, schemaName, tenantID string, req *CreateCostCenterRequest) (*CostCenter, error)

CreateCostCenter creates a new cost center

func (*CostCenterService) DeleteCostCenter

func (s *CostCenterService) DeleteCostCenter(ctx context.Context, schemaName, tenantID, costCenterID string) error

DeleteCostCenter deletes a cost center

func (*CostCenterService) GetCostCenter

func (s *CostCenterService) GetCostCenter(ctx context.Context, schemaName, tenantID, costCenterID string) (*CostCenter, error)

GetCostCenter retrieves a cost center by ID

func (*CostCenterService) GetCostCenterReport

func (s *CostCenterService) GetCostCenterReport(ctx context.Context, schemaName, tenantID string, start, end time.Time) (*CostCenterReport, error)

GetCostCenterReport generates a report for all cost centers

func (*CostCenterService) ImportCostAllocationsCSV

func (s *CostCenterService) ImportCostAllocationsCSV(ctx context.Context, schemaName, tenantID string, req *ImportCostAllocationsRequest) (*ImportCostAllocationsResult, error)

ImportCostAllocationsCSV imports historical cost allocation rows from CSV content.

func (*CostCenterService) ImportCostCentersCSV

func (s *CostCenterService) ImportCostCentersCSV(ctx context.Context, schemaName, tenantID string, req *ImportCostCentersRequest) (*ImportCostCentersResult, error)

ImportCostCentersCSV imports cost center master data from CSV content.

func (*CostCenterService) ListCostAllocations

func (s *CostCenterService) ListCostAllocations(ctx context.Context, schemaName, tenantID string, filters CostAllocationFilters) ([]CostAllocation, error)

ListCostAllocations returns cost-center allocations for review and automation.

func (*CostCenterService) ListCostCenters

func (s *CostCenterService) ListCostCenters(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]CostCenter, error)

ListCostCenters retrieves all cost centers for a tenant

func (*CostCenterService) UpdateCostCenter

func (s *CostCenterService) UpdateCostCenter(ctx context.Context, schemaName, tenantID, costCenterID string, req *UpdateCostCenterRequest) (*CostCenter, error)

UpdateCostCenter updates an existing cost center

type CostCenterSummary

type CostCenterSummary struct {
	CostCenter    CostCenter      `json:"cost_center"`
	TotalExpenses decimal.Decimal `json:"total_expenses"`
	BudgetAmount  decimal.Decimal `json:"budget_amount"`
	BudgetUsed    decimal.Decimal `json:"budget_used_percentage"`
	IsOverBudget  bool            `json:"is_over_budget"`
	PeriodStart   time.Time       `json:"period_start"`
	PeriodEnd     time.Time       `json:"period_end"`
}

CostCenterSummary provides expense summary for a cost center

type CreateAccountRequest

type CreateAccountRequest struct {
	ID          string      `json:"id,omitempty"`
	Code        string      `json:"code"`
	Name        string      `json:"name"`
	AccountType AccountType `json:"account_type"`
	ParentID    *string     `json:"parent_id,omitempty"`
	Description string      `json:"description,omitempty"`
}

CreateAccountRequest is the request to create an account

type CreateCostAllocationRequest

type CreateCostAllocationRequest struct {
	CostCenterID         string           `json:"cost_center_id"`
	JournalEntryLineID   string           `json:"journal_entry_line_id"`
	Amount               decimal.Decimal  `json:"amount"`
	AllocationPercentage *decimal.Decimal `json:"allocation_percentage,omitempty"`
	AllocationDate       time.Time        `json:"allocation_date"`
	Notes                string           `json:"notes,omitempty"`
}

CreateCostAllocationRequest assigns a journal entry line amount to a cost center.

type CreateCostCenterRequest

type CreateCostCenterRequest struct {
	Code         string           `json:"code"`
	Name         string           `json:"name"`
	Description  string           `json:"description,omitempty"`
	ParentID     *string          `json:"parent_id,omitempty"`
	IsActive     bool             `json:"is_active"`
	BudgetAmount *decimal.Decimal `json:"budget_amount,omitempty"`
	BudgetPeriod BudgetPeriod     `json:"budget_period,omitempty"`
}

CreateCostCenterRequest is the request to create a cost center

type CreateJournalEntryLineReq

type CreateJournalEntryLineReq struct {
	AccountID      string          `json:"account_id"`
	LineID         string          `json:"line_id,omitempty"`
	Description    string          `json:"description,omitempty"`
	DebitAmount    decimal.Decimal `json:"debit_amount"`
	CreditAmount   decimal.Decimal `json:"credit_amount"`
	Currency       string          `json:"currency,omitempty"`
	ExchangeRate   decimal.Decimal `json:"exchange_rate,omitempty"`
	VATRate        decimal.Decimal `json:"vat_rate,omitempty"`
	IsVATInclusive bool            `json:"is_vat_inclusive,omitempty"`
}

CreateJournalEntryLineReq is a line in the create request

type CreateJournalEntryRequest

type CreateJournalEntryRequest struct {
	EntryDate        time.Time                   `json:"entry_date"`
	Description      string                      `json:"description"`
	Reference        string                      `json:"reference,omitempty"`
	SourceType       string                      `json:"source_type,omitempty"`
	SourceID         *string                     `json:"source_id,omitempty"`
	RequiresEvidence bool                        `json:"requires_evidence,omitempty"`
	Lines            []CreateJournalEntryLineReq `json:"lines"`
	UserID           string                      `json:"-"`
}

CreateJournalEntryRequest is the request to create a new journal entry

type CreateJournalEntryTemplateRequest

type CreateJournalEntryTemplateRequest struct {
	Name               string                        `json:"name"`
	Description        string                        `json:"description"`
	Reference          string                        `json:"reference,omitempty"`
	RequiresEvidence   bool                          `json:"requires_evidence,omitempty"`
	Frequency          JournalEntryTemplateFrequency `json:"frequency,omitempty"`
	StartDate          *time.Time                    `json:"start_date,omitempty"`
	EndDate            *time.Time                    `json:"end_date,omitempty"`
	NextGenerationDate *time.Time                    `json:"next_generation_date,omitempty"`
	Lines              []CreateJournalEntryLineReq   `json:"lines"`
	UserID             string                        `json:"-"`
}

CreateJournalEntryTemplateRequest is the request to create a journal entry template.

type CreateYearEndCarryForwardRequest

type CreateYearEndCarryForwardRequest struct {
	PeriodEndDate            string `json:"period_end_date"`
	InventoryValuationMethod string `json:"inventory_valuation_method,omitempty"`
	UserID                   string `json:"-"`
}

CreateYearEndCarryForwardRequest requests a year-end carry-forward journal.

type GORMRepository

type GORMRepository struct {
	// contains filtered or unexported fields
}

GORMRepository implements RepositoryInterface using GORM

func NewGORMRepository

func NewGORMRepository(db *gorm.DB) *GORMRepository

NewGORMRepository creates a new GORM accounting repository

func NewRepository

func NewRepository(db *pgxpool.Pool) *GORMRepository

NewRepository creates an ORM-backed accounting repository.

func (*GORMRepository) CreateAccount

func (r *GORMRepository) CreateAccount(ctx context.Context, schemaName string, a *Account) error

CreateAccount creates a new account

func (*GORMRepository) CreateJournalEntry

func (r *GORMRepository) CreateJournalEntry(ctx context.Context, schemaName string, je *JournalEntry) error

CreateJournalEntry creates a new journal entry with lines

func (*GORMRepository) CreateJournalEntryTemplate

func (r *GORMRepository) CreateJournalEntryTemplate(ctx context.Context, schemaName string, template *JournalEntryTemplate) error

CreateJournalEntryTemplate creates a reusable balanced journal entry template.

func (*GORMRepository) GetAccountBalance

func (r *GORMRepository) GetAccountBalance(ctx context.Context, schemaName, tenantID, accountID string, asOfDate time.Time) (decimal.Decimal, error)

GetAccountBalance retrieves the balance of an account as of a date

func (*GORMRepository) GetAccountByID

func (r *GORMRepository) GetAccountByID(ctx context.Context, schemaName, tenantID, accountID string) (*Account, error)

GetAccountByID retrieves an account by ID

func (*GORMRepository) GetDueJournalEntryTemplateIDs

func (r *GORMRepository) GetDueJournalEntryTemplateIDs(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) ([]string, error)

GetDueJournalEntryTemplateIDs returns active recurring templates due by a date.

func (*GORMRepository) GetJournalEntryByID

func (r *GORMRepository) GetJournalEntryByID(ctx context.Context, schemaName, tenantID, entryID string) (*JournalEntry, error)

GetJournalEntryByID retrieves a journal entry with its lines

func (*GORMRepository) GetJournalEntryBySource

func (r *GORMRepository) GetJournalEntryBySource(ctx context.Context, schemaName, tenantID, sourceType, sourceID string) (*JournalEntry, error)

GetJournalEntryBySource retrieves the most recent non-voided journal entry for a source pair.

func (*GORMRepository) GetJournalEntryTemplateByID

func (r *GORMRepository) GetJournalEntryTemplateByID(ctx context.Context, schemaName, tenantID, templateID string) (*JournalEntryTemplate, error)

GetJournalEntryTemplateByID retrieves a reusable journal entry template with lines.

func (*GORMRepository) GetPeriodBalances

func (r *GORMRepository) GetPeriodBalances(ctx context.Context, schemaName, tenantID string, startDate, endDate time.Time) ([]AccountBalance, error)

GetPeriodBalances retrieves account activity for a specific period (not cumulative)

func (*GORMRepository) GetTrialBalance

func (r *GORMRepository) GetTrialBalance(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) ([]AccountBalance, error)

GetTrialBalance retrieves all account balances as of a date

func (*GORMRepository) ListAccounts

func (r *GORMRepository) ListAccounts(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]Account, error)

ListAccounts retrieves all accounts for a tenant

func (*GORMRepository) ListJournalEntries

func (r *GORMRepository) ListJournalEntries(ctx context.Context, schemaName, tenantID string, limit int) ([]JournalEntry, error)

ListJournalEntries retrieves the most recent journal entries with their lines.

func (*GORMRepository) ListJournalEntryTemplates

func (r *GORMRepository) ListJournalEntryTemplates(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]JournalEntryTemplate, error)

ListJournalEntryTemplates lists reusable journal entry templates for a tenant.

func (*GORMRepository) UpdateAccount

func (r *GORMRepository) UpdateAccount(ctx context.Context, schemaName string, a *Account) error

UpdateAccount updates an existing tenant account.

func (*GORMRepository) UpdateJournalEntryStatus

func (r *GORMRepository) UpdateJournalEntryStatus(ctx context.Context, schemaName, tenantID, entryID string, status JournalEntryStatus, userID string, reason ...string) error

UpdateJournalEntryStatus updates the status of a journal entry

func (*GORMRepository) UpdateJournalEntryTemplateAfterGeneration

func (r *GORMRepository) UpdateJournalEntryTemplateAfterGeneration(ctx context.Context, schemaName, tenantID, templateID string, nextDate time.Time, generatedAt time.Time) error

UpdateJournalEntryTemplateAfterGeneration advances recurring template schedule metadata.

func (*GORMRepository) VoidJournalEntry

func (r *GORMRepository) VoidJournalEntry(ctx context.Context, schemaName, tenantID, entryID, userID, reason string, reversal *JournalEntry) error

VoidJournalEntry voids a journal entry and creates a reversal entry within a transaction

type GenerateDueJournalEntryTemplatesRequest

type GenerateDueJournalEntryTemplatesRequest struct {
	AsOfDate       *time.Time `json:"as_of_date,omitempty"`
	Post           bool       `json:"post,omitempty"`
	UserID         string     `json:"-"`
	PeriodLockDate *time.Time `json:"-"`
}

GenerateDueJournalEntryTemplatesRequest generates all recurring templates due by a date.

type GenerateJournalEntryTemplateRequest

type GenerateJournalEntryTemplateRequest struct {
	EntryDate      *time.Time `json:"entry_date,omitempty"`
	Post           bool       `json:"post,omitempty"`
	UserID         string     `json:"-"`
	PeriodLockDate *time.Time `json:"-"`
}

GenerateJournalEntryTemplateRequest generates and advances a recurring journal template.

type ImportAccountsRequest

type ImportAccountsRequest struct {
	CSVContent string `json:"csv_content"`
	FileName   string `json:"file_name,omitempty"`
}

ImportAccountsRequest contains CSV payload for bulk account import.

type ImportAccountsResult

type ImportAccountsResult struct {
	FileName        string                   `json:"file_name,omitempty"`
	RowsProcessed   int                      `json:"rows_processed"`
	AccountsCreated int                      `json:"accounts_created"`
	RowsSkipped     int                      `json:"rows_skipped"`
	Errors          []ImportAccountsRowError `json:"errors,omitempty"`
}

ImportAccountsResult summarizes a bulk account import.

type ImportAccountsRowError

type ImportAccountsRowError struct {
	Row     int    `json:"row"`
	Code    string `json:"code,omitempty"`
	Name    string `json:"name,omitempty"`
	Message string `json:"message"`
}

ImportAccountsRowError describes a row-level import failure.

type ImportCostAllocationsRequest

type ImportCostAllocationsRequest struct {
	CSVContent string `json:"csv_content"`
	FileName   string `json:"file_name,omitempty"`
}

ImportCostAllocationsRequest contains CSV payload for cost allocation migration.

type ImportCostAllocationsResult

type ImportCostAllocationsResult struct {
	FileName            string                          `json:"file_name,omitempty"`
	RowsProcessed       int                             `json:"rows_processed"`
	AllocationsImported int                             `json:"allocations_imported"`
	RowsSkipped         int                             `json:"rows_skipped"`
	Errors              []ImportCostAllocationsRowError `json:"errors,omitempty"`
}

ImportCostAllocationsResult summarizes a cost allocation CSV import.

type ImportCostAllocationsRowError

type ImportCostAllocationsRowError struct {
	Row                int    `json:"row"`
	CostCenterID       string `json:"cost_center_id,omitempty"`
	CostCenterCode     string `json:"cost_center_code,omitempty"`
	JournalEntryLineID string `json:"journal_entry_line_id,omitempty"`
	Message            string `json:"message"`
}

ImportCostAllocationsRowError describes a row-level cost allocation import failure.

type ImportCostCentersRequest

type ImportCostCentersRequest struct {
	CSVContent string `json:"csv_content"`
	FileName   string `json:"file_name,omitempty"`
}

ImportCostCentersRequest contains CSV payload for cost center migration.

type ImportCostCentersResult

type ImportCostCentersResult struct {
	FileName           string                      `json:"file_name,omitempty"`
	RowsProcessed      int                         `json:"rows_processed"`
	CostCentersCreated int                         `json:"cost_centers_created"`
	RowsSkipped        int                         `json:"rows_skipped"`
	Errors             []ImportCostCentersRowError `json:"errors,omitempty"`
}

ImportCostCentersResult summarizes a cost center CSV import.

type ImportCostCentersRowError

type ImportCostCentersRowError struct {
	Row     int    `json:"row"`
	Code    string `json:"code,omitempty"`
	Name    string `json:"name,omitempty"`
	Message string `json:"message"`
}

ImportCostCentersRowError describes a row-level cost center import failure.

type ImportJournalEntriesRequest

type ImportJournalEntriesRequest struct {
	CSVContent     string     `json:"csv_content"`
	FileName       string     `json:"file_name,omitempty"`
	SourceType     string     `json:"source_type,omitempty"`
	PostEntries    bool       `json:"post_entries,omitempty"`
	UserID         string     `json:"-"`
	PeriodLockDate *time.Time `json:"-"`
}

ImportJournalEntriesRequest contains CSV payload for historical journal import.

type ImportJournalEntriesResult

type ImportJournalEntriesResult struct {
	FileName       string                         `json:"file_name,omitempty"`
	RowsProcessed  int                            `json:"rows_processed"`
	EntriesCreated int                            `json:"entries_created"`
	LinesImported  int                            `json:"lines_imported"`
	RowsSkipped    int                            `json:"rows_skipped"`
	TotalDebit     decimal.Decimal                `json:"total_debit"`
	TotalCredit    decimal.Decimal                `json:"total_credit"`
	JournalEntries []JournalEntry                 `json:"journal_entries,omitempty"`
	Errors         []ImportJournalEntriesRowError `json:"errors,omitempty"`
}

ImportJournalEntriesResult summarizes a historical journal CSV import.

type ImportJournalEntriesRowError

type ImportJournalEntriesRowError struct {
	Row            int    `json:"row"`
	EntryReference string `json:"entry_reference,omitempty"`
	Message        string `json:"message"`
}

ImportJournalEntriesRowError describes a journal import group or row failure.

type ImportOpeningBalancesRequest

type ImportOpeningBalancesRequest struct {
	EntryDate   string `json:"entry_date"`
	CSVContent  string `json:"csv_content"`
	FileName    string `json:"file_name,omitempty"`
	Description string `json:"description,omitempty"`
	Reference   string `json:"reference,omitempty"`
	UserID      string `json:"-"`
}

ImportOpeningBalancesRequest contains CSV payload for opening-balance import.

type ImportOpeningBalancesResult

type ImportOpeningBalancesResult struct {
	FileName      string          `json:"file_name,omitempty"`
	RowsProcessed int             `json:"rows_processed"`
	LinesImported int             `json:"lines_imported"`
	TotalDebit    decimal.Decimal `json:"total_debit"`
	TotalCredit   decimal.Decimal `json:"total_credit"`
	JournalEntry  *JournalEntry   `json:"journal_entry"`
}

ImportOpeningBalancesResult summarizes a successful opening-balance import.

type IncomeStatement

type IncomeStatement struct {
	TenantID      string           `json:"tenant_id"`
	StartDate     time.Time        `json:"start_date"`
	EndDate       time.Time        `json:"end_date"`
	GeneratedAt   time.Time        `json:"generated_at"`
	Revenue       []AccountBalance `json:"revenue"`
	Expenses      []AccountBalance `json:"expenses"`
	TotalRevenue  decimal.Decimal  `json:"total_revenue"`
	TotalExpenses decimal.Decimal  `json:"total_expenses"`
	NetIncome     decimal.Decimal  `json:"net_income"`
}

IncomeStatement represents an income statement (P&L) for a period

type JournalEntry

type JournalEntry struct {
	ID               string             `json:"id"`
	TenantID         string             `json:"tenant_id"`
	EntryNumber      string             `json:"entry_number"`
	EntryDate        time.Time          `json:"entry_date"`
	Description      string             `json:"description"`
	Reference        string             `json:"reference,omitempty"`
	SourceType       string             `json:"source_type,omitempty"`
	SourceID         *string            `json:"source_id,omitempty"`
	RequiresEvidence bool               `json:"requires_evidence"`
	Status           JournalEntryStatus `json:"status"`
	Lines            []JournalEntryLine `json:"lines"`
	PostedAt         *time.Time         `json:"posted_at,omitempty"`
	PostedBy         *string            `json:"posted_by,omitempty"`
	PostReason       string             `json:"post_reason,omitempty"`
	VoidedAt         *time.Time         `json:"voided_at,omitempty"`
	VoidedBy         *string            `json:"voided_by,omitempty"`
	VoidReason       string             `json:"void_reason,omitempty"`
	CreatedAt        time.Time          `json:"created_at"`
	CreatedBy        string             `json:"created_by"`
}

JournalEntry represents an immutable accounting transaction

func (*JournalEntry) IsBalanced

func (je *JournalEntry) IsBalanced() bool

IsBalanced returns true if debits equal credits

func (*JournalEntry) TotalCredits

func (je *JournalEntry) TotalCredits() decimal.Decimal

TotalCredits returns the sum of all credit amounts

func (*JournalEntry) TotalDebits

func (je *JournalEntry) TotalDebits() decimal.Decimal

TotalDebits returns the sum of all debit amounts

func (*JournalEntry) Validate

func (je *JournalEntry) Validate() error

Validate ensures the journal entry is balanced and valid

type JournalEntryLine

type JournalEntryLine struct {
	ID             string          `json:"id"`
	TenantID       string          `json:"tenant_id"`
	JournalEntryID string          `json:"journal_entry_id"`
	AccountID      string          `json:"account_id"`
	Account        *Account        `json:"account,omitempty"`
	Description    string          `json:"description,omitempty"`
	DebitAmount    decimal.Decimal `json:"debit_amount"`
	CreditAmount   decimal.Decimal `json:"credit_amount"`
	Currency       string          `json:"currency"`
	ExchangeRate   decimal.Decimal `json:"exchange_rate"`
	BaseDebit      decimal.Decimal `json:"base_debit"`
	BaseCredit     decimal.Decimal `json:"base_credit"`
	VATRate        decimal.Decimal `json:"vat_rate"`
	IsVATInclusive bool            `json:"is_vat_inclusive"`
}

JournalEntryLine represents a single debit or credit in a journal entry

type JournalEntryStatus

type JournalEntryStatus string

JournalEntryStatus represents the lifecycle status of a journal entry

const (
	StatusDraft  JournalEntryStatus = "DRAFT"
	StatusPosted JournalEntryStatus = "POSTED"
	StatusVoided JournalEntryStatus = "VOIDED"
)

type JournalEntrySummary

type JournalEntrySummary struct {
	ID          string             `json:"id"`
	EntryNumber string             `json:"entry_number"`
	EntryDate   string             `json:"entry_date"`
	Description string             `json:"description"`
	Reference   string             `json:"reference,omitempty"`
	Status      JournalEntryStatus `json:"status"`
}

JournalEntrySummary is a lightweight journal-entry reference for workflow responses.

type JournalEntryTemplate

type JournalEntryTemplate struct {
	ID                 string                        `json:"id"`
	TenantID           string                        `json:"tenant_id"`
	Name               string                        `json:"name"`
	Description        string                        `json:"description"`
	Reference          string                        `json:"reference,omitempty"`
	RequiresEvidence   bool                          `json:"requires_evidence"`
	IsActive           bool                          `json:"is_active"`
	Frequency          JournalEntryTemplateFrequency `json:"frequency,omitempty"`
	StartDate          *time.Time                    `json:"start_date,omitempty"`
	EndDate            *time.Time                    `json:"end_date,omitempty"`
	NextGenerationDate *time.Time                    `json:"next_generation_date,omitempty"`
	LastGeneratedAt    *time.Time                    `json:"last_generated_at,omitempty"`
	GeneratedCount     int                           `json:"generated_count"`
	LineCount          int                           `json:"line_count"`
	Lines              []JournalEntryTemplateLine    `json:"lines,omitempty"`
	CreatedAt          time.Time                     `json:"created_at"`
	CreatedBy          string                        `json:"created_by"`
	UpdatedAt          time.Time                     `json:"updated_at"`
}

JournalEntryTemplate represents a reusable balanced journal entry pattern.

func (*JournalEntryTemplate) CalculateNextDate

func (t *JournalEntryTemplate) CalculateNextDate(from time.Time) time.Time

CalculateNextDate returns the next scheduled generation date.

func (*JournalEntryTemplate) IsRecurring

func (t *JournalEntryTemplate) IsRecurring() bool

IsRecurring returns true when the template has a recurrence schedule.

type JournalEntryTemplateFrequency

type JournalEntryTemplateFrequency string

JournalEntryTemplateFrequency represents how often a recurring journal template is generated.

const (
	JournalEntryTemplateFrequencyWeekly    JournalEntryTemplateFrequency = "WEEKLY"
	JournalEntryTemplateFrequencyBiweekly  JournalEntryTemplateFrequency = "BIWEEKLY"
	JournalEntryTemplateFrequencyMonthly   JournalEntryTemplateFrequency = "MONTHLY"
	JournalEntryTemplateFrequencyQuarterly JournalEntryTemplateFrequency = "QUARTERLY"
	JournalEntryTemplateFrequencyYearly    JournalEntryTemplateFrequency = "YEARLY"
)

type JournalEntryTemplateGenerationResult

type JournalEntryTemplateGenerationResult struct {
	TemplateID           string     `json:"template_id"`
	TemplateName         string     `json:"template_name,omitempty"`
	GeneratedEntryID     string     `json:"generated_entry_id,omitempty"`
	GeneratedEntryNumber string     `json:"generated_entry_number,omitempty"`
	EntryDate            *time.Time `json:"entry_date,omitempty"`
	NextGenerationDate   *time.Time `json:"next_generation_date,omitempty"`
	Status               string     `json:"status"`
	Error                string     `json:"error,omitempty"`
}

JournalEntryTemplateGenerationResult describes one recurring template generation attempt.

type JournalEntryTemplateLine

type JournalEntryTemplateLine struct {
	ID           string          `json:"id"`
	TemplateID   string          `json:"template_id"`
	LineNumber   int             `json:"line_number"`
	AccountID    string          `json:"account_id"`
	Description  string          `json:"description,omitempty"`
	DebitAmount  decimal.Decimal `json:"debit_amount"`
	CreditAmount decimal.Decimal `json:"credit_amount"`
	Currency     string          `json:"currency"`
	ExchangeRate decimal.Decimal `json:"exchange_rate"`
}

JournalEntryTemplateLine is one line in a reusable journal entry template.

type JournalEntryTemplateRepository

type JournalEntryTemplateRepository interface {
	CreateJournalEntryTemplate(ctx context.Context, schemaName string, template *JournalEntryTemplate) error
	ListJournalEntryTemplates(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]JournalEntryTemplate, error)
	GetJournalEntryTemplateByID(ctx context.Context, schemaName, tenantID, templateID string) (*JournalEntryTemplate, error)
	GetDueJournalEntryTemplateIDs(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) ([]string, error)
	UpdateJournalEntryTemplateAfterGeneration(ctx context.Context, schemaName, tenantID, templateID string, nextDate time.Time, generatedAt time.Time) error
}

JournalEntryTemplateRepository is the optional repository surface for reusable entry templates.

type MockCostCenterRepository

type MockCostCenterRepository struct {
	CostCenters map[string]*CostCenter
	Allocations map[string][]CostAllocation
}

MockCostCenterRepository is a mock implementation for testing

func NewMockCostCenterRepository

func NewMockCostCenterRepository() *MockCostCenterRepository

NewMockCostCenterRepository creates a new mock repository

func (*MockCostCenterRepository) Create

Create mock implementation

func (*MockCostCenterRepository) CreateAllocation

func (m *MockCostCenterRepository) CreateAllocation(_ context.Context, _ string, allocation *CostAllocation) error

CreateAllocation mock implementation

func (*MockCostCenterRepository) Delete

func (m *MockCostCenterRepository) Delete(_ context.Context, _, tenantID, costCenterID string) error

Delete mock implementation

func (*MockCostCenterRepository) GetByID

func (m *MockCostCenterRepository) GetByID(_ context.Context, _, tenantID, costCenterID string) (*CostCenter, error)

GetByID mock implementation

func (*MockCostCenterRepository) GetExpensesByPeriod

func (m *MockCostCenterRepository) GetExpensesByPeriod(_ context.Context, _, tenantID, costCenterID string, start, end time.Time) (decimal.Decimal, error)

GetExpensesByPeriod mock implementation

func (*MockCostCenterRepository) List

func (m *MockCostCenterRepository) List(_ context.Context, _, tenantID string, activeOnly bool) ([]CostCenter, error)

List mock implementation

func (*MockCostCenterRepository) ListAllocations

func (m *MockCostCenterRepository) ListAllocations(_ context.Context, _, tenantID string, filters CostAllocationFilters) ([]CostAllocation, error)

ListAllocations mock implementation

func (*MockCostCenterRepository) Update

Update mock implementation

type PostJournalEntryRequest

type PostJournalEntryRequest struct {
	Reason string `json:"reason"`
}

PostJournalEntryRequest records why a draft journal entry is being finalized.

type RepositoryInterface

type RepositoryInterface interface {
	GetAccountByID(ctx context.Context, schemaName, tenantID, accountID string) (*Account, error)
	ListAccounts(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]Account, error)
	CreateAccount(ctx context.Context, schemaName string, a *Account) error
	UpdateAccount(ctx context.Context, schemaName string, a *Account) error
	ListJournalEntries(ctx context.Context, schemaName, tenantID string, limit int) ([]JournalEntry, error)
	GetJournalEntryByID(ctx context.Context, schemaName, tenantID, entryID string) (*JournalEntry, error)
	GetJournalEntryBySource(ctx context.Context, schemaName, tenantID, sourceType, sourceID string) (*JournalEntry, error)
	CreateJournalEntry(ctx context.Context, schemaName string, je *JournalEntry) error
	UpdateJournalEntryStatus(ctx context.Context, schemaName, tenantID, entryID string, status JournalEntryStatus, userID string, reason ...string) error
	GetAccountBalance(ctx context.Context, schemaName, tenantID, accountID string, asOfDate time.Time) (decimal.Decimal, error)
	GetTrialBalance(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) ([]AccountBalance, error)
	GetPeriodBalances(ctx context.Context, schemaName, tenantID string, startDate, endDate time.Time) ([]AccountBalance, error)
	VoidJournalEntry(ctx context.Context, schemaName, tenantID, entryID, userID, reason string, reversal *JournalEntry) error
}

RepositoryInterface defines the contract for accounting data access

type ReverseYearEndCarryForwardRequest

type ReverseYearEndCarryForwardRequest struct {
	PeriodEndDate string `json:"period_end_date"`
	Reason        string `json:"reason"`
	UserID        string `json:"-"`
}

ReverseYearEndCarryForwardRequest requests reversal of an existing carry-forward journal.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides accounting operations

func NewService

func NewService(db *pgxpool.Pool) *Service

NewService creates a new accounting service

func NewServiceWithRepository

func NewServiceWithRepository(repo RepositoryInterface) *Service

NewServiceWithRepository creates a new accounting service with a custom repository.

func (*Service) ApplyJournalEntryTemplate

func (s *Service) ApplyJournalEntryTemplate(ctx context.Context, schemaName, tenantID, templateID string, req *ApplyJournalEntryTemplateRequest) (*JournalEntry, error)

ApplyJournalEntryTemplate creates a journal entry from a reusable template.

func (*Service) CreateAccount

func (s *Service) CreateAccount(ctx context.Context, schemaName, tenantID string, req *CreateAccountRequest) (*Account, error)

CreateAccount creates a new account

func (*Service) CreateJournalEntry

func (s *Service) CreateJournalEntry(ctx context.Context, schemaName, tenantID string, req *CreateJournalEntryRequest) (*JournalEntry, error)

CreateJournalEntry creates a new journal entry

func (*Service) CreateJournalEntryTemplate

func (s *Service) CreateJournalEntryTemplate(ctx context.Context, schemaName, tenantID string, req *CreateJournalEntryTemplateRequest) (*JournalEntryTemplate, error)

CreateJournalEntryTemplate stores a balanced reusable journal entry template.

func (*Service) CreateYearEndCarryForward

func (s *Service) CreateYearEndCarryForward(ctx context.Context, schemaName, tenantID string, fiscalYearStartMonth int, lockedThroughDate *string, req *CreateYearEndCarryForwardRequest) (*YearEndCarryForwardResult, error)

CreateYearEndCarryForward creates and posts a year-end carry-forward journal entry.

func (*Service) DeactivateAccount

func (s *Service) DeactivateAccount(ctx context.Context, schemaName, tenantID, accountID string) (*Account, error)

DeactivateAccount soft-deletes a chart-of-accounts row while preserving accounting history.

func (*Service) GenerateDueJournalEntryTemplates

func (s *Service) GenerateDueJournalEntryTemplates(ctx context.Context, schemaName, tenantID string, req *GenerateDueJournalEntryTemplatesRequest) ([]JournalEntryTemplateGenerationResult, error)

GenerateDueJournalEntryTemplates generates all recurring journal templates due by a date.

func (*Service) GenerateJournalEntryTemplate

func (s *Service) GenerateJournalEntryTemplate(ctx context.Context, schemaName, tenantID, templateID string, req *GenerateJournalEntryTemplateRequest) (*JournalEntryTemplateGenerationResult, error)

GenerateJournalEntryTemplate generates one due recurring journal template and advances its schedule.

func (*Service) GetAccount

func (s *Service) GetAccount(ctx context.Context, schemaName, tenantID, accountID string) (*Account, error)

GetAccount retrieves an account by ID

func (*Service) GetAccountBalance

func (s *Service) GetAccountBalance(ctx context.Context, schemaName, tenantID, accountID string, asOfDate time.Time) (decimal.Decimal, error)

GetAccountBalance retrieves the balance of an account as of a date

func (*Service) GetAccountHierarchy

func (s *Service) GetAccountHierarchy(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]AccountHierarchyRow, error)

GetAccountHierarchy returns accounts in parent-child chart order.

func (*Service) GetBalanceSheet

func (s *Service) GetBalanceSheet(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) (*BalanceSheet, error)

GetBalanceSheet generates a balance sheet as of a specific date

func (*Service) GetIncomeStatement

func (s *Service) GetIncomeStatement(ctx context.Context, schemaName, tenantID string, startDate, endDate time.Time) (*IncomeStatement, error)

GetIncomeStatement generates an income statement for a period

func (*Service) GetJournalEntry

func (s *Service) GetJournalEntry(ctx context.Context, schemaName, tenantID, entryID string) (*JournalEntry, error)

GetJournalEntry retrieves a journal entry by ID

func (*Service) GetJournalEntryTemplate

func (s *Service) GetJournalEntryTemplate(ctx context.Context, schemaName, tenantID, templateID string) (*JournalEntryTemplate, error)

GetJournalEntryTemplate retrieves a reusable journal entry template.

func (*Service) GetTrialBalance

func (s *Service) GetTrialBalance(ctx context.Context, schemaName, tenantID string, asOfDate time.Time) (*TrialBalance, error)

GetTrialBalance retrieves all account balances as of a date

func (*Service) GetYearEndClosePack

func (s *Service) GetYearEndClosePack(ctx context.Context, schemaName, tenantID string, fiscalYearStartMonth int, rawPeriodEndDate string, lockedThroughDate *string) (*YearEndClosePack, error)

GetYearEndClosePack returns readiness plus core fiscal year-end reports.

func (*Service) GetYearEndCloseStatus

func (s *Service) GetYearEndCloseStatus(ctx context.Context, schemaName, tenantID string, fiscalYearStartMonth int, rawPeriodEndDate string, lockedThroughDate *string) (*YearEndCloseStatus, error)

GetYearEndCloseStatus returns the carry-forward readiness state for a fiscal year.

func (*Service) ImportAccountsCSV

func (s *Service) ImportAccountsCSV(ctx context.Context, schemaName, tenantID string, req *ImportAccountsRequest) (*ImportAccountsResult, error)

ImportAccountsCSV imports chart-of-account rows from CSV content.

func (*Service) ImportJournalEntriesCSV

func (s *Service) ImportJournalEntriesCSV(ctx context.Context, schemaName, tenantID string, req *ImportJournalEntriesRequest) (*ImportJournalEntriesResult, error)

ImportJournalEntriesCSV imports historical double-entry journals from grouped CSV rows.

func (*Service) ImportOpeningBalancesCSV

func (s *Service) ImportOpeningBalancesCSV(ctx context.Context, schemaName, tenantID string, req *ImportOpeningBalancesRequest) (*ImportOpeningBalancesResult, error)

ImportOpeningBalancesCSV imports opening balances from CSV and posts them as a journal entry.

func (*Service) ListAccounts

func (s *Service) ListAccounts(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]Account, error)

ListAccounts retrieves all accounts for a tenant

func (*Service) ListJournalEntries

func (s *Service) ListJournalEntries(ctx context.Context, schemaName, tenantID string, limit int) ([]JournalEntry, error)

ListJournalEntries retrieves recent journal entries for a tenant.

func (*Service) ListJournalEntryTemplates

func (s *Service) ListJournalEntryTemplates(ctx context.Context, schemaName, tenantID string, activeOnly bool) ([]JournalEntryTemplate, error)

ListJournalEntryTemplates retrieves reusable journal entry templates.

func (*Service) PostJournalEntry

func (s *Service) PostJournalEntry(ctx context.Context, schemaName, tenantID, entryID, userID, reason string) error

PostJournalEntry posts a draft journal entry

func (*Service) ReverseYearEndCarryForward

func (s *Service) ReverseYearEndCarryForward(ctx context.Context, schemaName, tenantID string, fiscalYearStartMonth int, lockedThroughDate *string, req *ReverseYearEndCarryForwardRequest) (*YearEndCarryForwardReversalResult, error)

ReverseYearEndCarryForward voids an existing year-end carry-forward journal entry.

func (*Service) UpdateAccount

func (s *Service) UpdateAccount(ctx context.Context, schemaName, tenantID, accountID string, req *UpdateAccountRequest) (*Account, error)

UpdateAccount updates an editable chart-of-accounts row.

func (*Service) VoidJournalEntry

func (s *Service) VoidJournalEntry(ctx context.Context, schemaName, tenantID, entryID, userID, reason string) (*JournalEntry, error)

VoidJournalEntry voids a posted journal entry by creating a reversing entry

type TrialBalance

type TrialBalance struct {
	TenantID     string           `json:"tenant_id"`
	AsOfDate     time.Time        `json:"as_of_date"`
	GeneratedAt  time.Time        `json:"generated_at"`
	Accounts     []AccountBalance `json:"accounts"`
	TotalDebits  decimal.Decimal  `json:"total_debits"`
	TotalCredits decimal.Decimal  `json:"total_credits"`
	IsBalanced   bool             `json:"is_balanced"`
}

TrialBalance represents a trial balance report

type UpdateAccountRequest

type UpdateAccountRequest struct {
	Code        string      `json:"code"`
	Name        string      `json:"name"`
	AccountType AccountType `json:"account_type"`
	ParentID    *string     `json:"parent_id,omitempty"`
	Description string      `json:"description,omitempty"`
}

UpdateAccountRequest is the request to update an editable account.

type UpdateCostCenterRequest

type UpdateCostCenterRequest struct {
	Code         string           `json:"code"`
	Name         string           `json:"name"`
	Description  string           `json:"description,omitempty"`
	ParentID     *string          `json:"parent_id,omitempty"`
	IsActive     bool             `json:"is_active"`
	BudgetAmount *decimal.Decimal `json:"budget_amount,omitempty"`
	BudgetPeriod BudgetPeriod     `json:"budget_period,omitempty"`
}

UpdateCostCenterRequest is the request to update a cost center

type YearEndCarryForwardResult

type YearEndCarryForwardResult struct {
	JournalEntry *JournalEntry       `json:"journal_entry"`
	Status       *YearEndCloseStatus `json:"status"`
}

YearEndCarryForwardResult contains the created journal entry and refreshed status.

type YearEndCarryForwardReversalResult

type YearEndCarryForwardReversalResult struct {
	ReversalJournalEntry *JournalEntry       `json:"reversal_journal_entry"`
	Status               *YearEndCloseStatus `json:"status"`
}

YearEndCarryForwardReversalResult contains the reversal journal and refreshed status.

type YearEndCloseAuditEvidence

type YearEndCloseAuditEvidence struct {
	Pack           *YearEndClosePack               `json:"pack"`
	EvidencePolicy *documents.EvidencePolicyResult `json:"evidence_policy,omitempty"`
	Documents      []documents.Document            `json:"documents"`
	GeneratedAt    time.Time                       `json:"generated_at"`
}

YearEndCloseAuditEvidence bundles the close pack with reviewer evidence metadata.

type YearEndClosePack

type YearEndClosePack struct {
	Status          *YearEndCloseStatus `json:"status"`
	TrialBalance    *TrialBalance       `json:"trial_balance"`
	BalanceSheet    *BalanceSheet       `json:"balance_sheet"`
	IncomeStatement *IncomeStatement    `json:"income_statement"`
	GeneratedAt     time.Time           `json:"generated_at"`
}

YearEndClosePack bundles close readiness with core year-end financial reports.

type YearEndCloseRemediationAction

type YearEndCloseRemediationAction struct {
	Code           string `json:"code"`
	Severity       string `json:"severity"`
	Scope          string `json:"scope"`
	OwnerRole      string `json:"owner_role"`
	WorkspaceQueue string `json:"workspace_queue,omitempty"`
	AssignmentKey  string `json:"assignment_key,omitempty"`
	Priority       string `json:"priority,omitempty"`
	DueInDays      int    `json:"due_in_days,omitempty"`
	Message        string `json:"message"`
	Action         string `json:"action"`
	EntityType     string `json:"entity_type,omitempty"`
	EntityID       string `json:"entity_id,omitempty"`
	UIPath         string `json:"ui_path,omitempty"`
	CLICommand     string `json:"cli_command,omitempty"`
}

YearEndCloseRemediationAction describes one operator action needed to complete or correct year-end close.

func BuildYearEndCloseRemediationActions

func BuildYearEndCloseRemediationActions(status *YearEndCloseStatus) []YearEndCloseRemediationAction

BuildYearEndCloseRemediationActions turns close readiness blockers into concrete operator actions.

type YearEndCloseStatus

type YearEndCloseStatus struct {
	PeriodEndDate              string                          `json:"period_end_date"`
	FiscalYearLabel            string                          `json:"fiscal_year_label"`
	FiscalYearStartDate        string                          `json:"fiscal_year_start_date"`
	FiscalYearEndDate          string                          `json:"fiscal_year_end_date"`
	CarryForwardDate           string                          `json:"carry_forward_date"`
	LockedThroughDate          *string                         `json:"locked_through_date,omitempty"`
	IsFiscalYearEnd            bool                            `json:"is_fiscal_year_end"`
	PeriodClosed               bool                            `json:"period_closed"`
	HasProfitAndLossActivity   bool                            `json:"has_profit_and_loss_activity"`
	CarryForwardNeeded         bool                            `json:"carry_forward_needed"`
	CarryForwardReady          bool                            `json:"carry_forward_ready"`
	HasRetainedEarningsAccount bool                            `json:"has_retained_earnings_account"`
	RetainedEarningsAccount    *AccountSummary                 `json:"retained_earnings_account,omitempty"`
	NetIncome                  decimal.Decimal                 `json:"net_income"`
	ExistingCarryForward       *JournalEntrySummary            `json:"existing_carry_forward,omitempty"`
	ClosePackEvidenceEntityID  string                          `json:"close_pack_evidence_entity_id,omitempty"`
	ClosePackEvidence          *documents.EvidencePolicyResult `json:"close_pack_evidence,omitempty"`
	InventoryCostingReview     *YearEndInventoryCostingReview  `json:"inventory_costing_review,omitempty"`
	RemediationActions         []YearEndCloseRemediationAction `json:"remediation_actions,omitempty"`
}

YearEndCloseStatus summarizes readiness for fiscal-year carry-forward.

type YearEndInventoryCostingReview

type YearEndInventoryCostingReview struct {
	ValuationMethod            string          `json:"valuation_method"`
	LineCount                  int             `json:"line_count"`
	TotalQuantity              decimal.Decimal `json:"total_quantity"`
	TotalReserved              decimal.Decimal `json:"total_reserved"`
	TotalAvailable             decimal.Decimal `json:"total_available"`
	TotalValue                 decimal.Decimal `json:"total_value"`
	NegativeQuantityLineCount  int             `json:"negative_quantity_line_count"`
	NegativeAvailableLineCount int             `json:"negative_available_line_count"`
	NegativeValueLineCount     int             `json:"negative_value_line_count"`
	MissingCostLineCount       int             `json:"missing_cost_line_count"`
	BlockingExceptionLineCount int             `json:"blocking_exception_line_count"`
	Ready                      bool            `json:"ready"`
	GeneratedAt                time.Time       `json:"generated_at"`
}

YearEndInventoryCostingReview summarizes inventory valuation checks for close readiness.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL