accounting

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package accounting implements double-entry bookkeeping for okpos. It is invoked by the background job queue after domain events are emitted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpeningBalanceInput added in v0.5.1

type OpeningBalanceInput struct {
	Cash    int64
	Bank    int64
	EWallet int64
}

OpeningBalanceInput is the starting figure for each of a branch's three cash-family accounts. Zero-valued fields are simply skipped when posting.

type Service

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

Service creates and persists double-entry journal entries from domain events.

func NewService

func NewService(
	repo data.AccountingRepoer, assets data.AssetRepoer, log *slog.Logger, clk clock.Clock,
) *Service

NewService returns an accounting Service backed by the given repos. assets is a deliberate, narrow exception to "accounting only depends on its own repo": a depreciation run has no way to compute anything without reading the asset's own cost/salvage/life/branch/status, and depending on a repo interface (not another service) keeps this consistent with how every other service in this codebase is composed.

func (*Service) AssetDepreciationSummary added in v0.5.1

func (s *Service) AssetDepreciationSummary(
	ctx context.Context,
	asset *model.FixedAsset,
) (postedPeriods int, accumulated int64, err error)

AssetDepreciationSummary returns how many periods have been posted for asset and the resulting accumulated depreciation, computed via the same straight-line formula PostAssetDepreciation uses — this is never read from a cache (none exists; see the "Corrected design" note in accounting-implementation-plan.md Phase 7a), so it's always exactly consistent with what's actually posted, including the final-period remainder once the asset is fully depreciated.

func (*Service) BalanceByAccount

func (s *Service) BalanceByAccount(
	ctx context.Context,
	companyID uuid.UUID,
) ([]model.AccountBalance, error)

BalanceByAccount returns running debit/credit totals per COA account for a company.

func (*Service) Handle

func (s *Service) Handle(ctx context.Context, eventName string, payload map[string]any) error

Handle maps a domain event to the appropriate journal entry and posts it. Unknown events are silently ignored (no error returned).

func (*Service) HasOpeningBalance added in v0.5.1

func (s *Service) HasOpeningBalance(
	ctx context.Context,
	companyID, branchID uuid.UUID,
) (bool, error)

HasOpeningBalance reports whether branchID already has an opening-balance entry, for the settings page to hide the form once one exists.

func (*Service) ListAccounts

func (s *Service) ListAccounts(ctx context.Context) ([]model.Account, error)

ListAccounts returns all chart-of-accounts entries ordered by code.

func (*Service) ListJournalEntries

func (s *Service) ListJournalEntries(
	ctx context.Context,
	companyID uuid.UUID,
	q data.SupportsPagination,
) (*dto.PaginationResults[model.JournalEntry], error)

ListJournalEntries returns a paginated list of journal entries for a company. Lines are not populated; use the repo directly if lines are needed.

func (*Service) ListJournalEntriesFiltered added in v0.5.1

func (s *Service) ListJournalEntriesFiltered(
	ctx context.Context,
	companyID uuid.UUID,
	filter data.JournalEntryFilter,
	q data.SupportsPagination,
) (*dto.PaginationResults[model.JournalEntry], error)

ListJournalEntriesFiltered is the filterable counterpart to ListJournalEntries, used by the ledger UI's journal-entries page.

func (*Service) Post

func (s *Service) Post(ctx context.Context, entry *model.JournalEntry) error

Post validates that the entry is balanced (∑debit = ∑credit) and persists it.

func (*Service) PostAssetDepreciation added in v0.5.1

func (s *Service) PostAssetDepreciation(
	ctx context.Context,
	companyID, branchID uuid.UUID,
	asOf time.Time,
) (int, error)

PostAssetDepreciation posts straight-line depreciation for every active fixed asset in branchID, catching up any periods missed since each asset's last posting through asOf's calendar month. Synchronous, not event/job-queue routed — same reasoning as PostOpeningBalance: no domain-event origin outside accounting. Returns the number of journal entries posted across all assets; a mid-loop failure simply stops and returns what was posted so far (each period's Post call is independently atomic, so nothing is lost — the next call's CountDepreciationPeriods correctly resumes).

func (*Service) PostOpeningBalance added in v0.5.1

func (s *Service) PostOpeningBalance(
	ctx context.Context,
	companyID, branchID uuid.UUID,
	asOf time.Time,
	balances OpeningBalanceInput,
) error

PostOpeningBalance posts a single balanced entry dated asOf: Dr each nonzero cash-family account / Cr 3900 Opening Balance Equity for the sum. Returns data.ErrOpeningBalanceAlreadySet if branchID already has one, and data.ErrNoOpeningBalanceAmount if every field of balances is zero.

Jump to

Keyboard shortcuts

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