Service Layer medium complexity mobile
1
Dependencies
2
Dependents
1
Entities
0
Integrations

Description

Maps each expense type to its reimbursement formula and computes the expected payout for a given selection. Handles per-km rate lookup for mileage, flat-amount logic for tolls and parking receipts, and zone-based public transit amounts. Produces a structured result for display and for downstream accounting export.

Feature: Expense Type Selection with Mutual Exclusion

expense-calculation-service

Summaries

The Expense Calculation Service is the financial computation core of the reimbursement feature, translating an employee's expense selection into an accurate, policy-compliant payout figure before submission. By computing reimbursements in real time on the device, employees see exactly what they will receive before submitting, reducing disputes and resubmissions. Accurate pre-submission totals also streamline finance team approval workflows, as submissions arrive pre-validated with correct amounts. This directly lowers processing cost per claim and reduces time-to-reimbursement, improving employee satisfaction and retention — a measurable competitive advantage in expense management tooling.

Medium complexity component with a single dependency on expense-type-config, which must be delivered first. The primary scheduling risk is formula definition: per-km rates, transit zone amounts, and receipt thresholds must be confirmed with finance stakeholders before development begins — any late changes to rates require code or config updates. Plan a stakeholder sign-off milestone for formula parameters. Testing should cover all four expense types independently and in valid combined selections, including boundary values for km counts and zone thresholds.

The structured ExpenseCalculationResult output must be reviewed with the accounting export team early to prevent interface mismatches that could delay downstream integration.

This pure Dart service depends on expense-type-config for formula parameters and rate constants. The core interface, calculate(Set, ExpenseInputParams) → ExpenseCalculationResult, dispatches per type: mileage applies a per-km rate multiply, tolls and parking apply flat receipt amounts, and public transit applies a zone-based lookup. ExpenseCalculationResult should carry a List plus a total, enabling itemised display. getFormulaDescription and getRequiredInputs support dynamic UI rendering — the picker widget calls getRequiredInputs to know which input fields to show for each active type.

Keep formula logic pure and side-effect-free to simplify testing. Rate parameters must be sourced exclusively from expense-type-config, never hardcoded inline.

Responsibilities

  • Apply per-km rate formula for mileage expense type
  • Apply flat receipt logic for toll and parking types
  • Apply transit amount formula for public transit type
  • Produce structured ExpenseCalculationResult with line items and total

Interfaces

calculate(Set<ExpenseType> selectedTypes, ExpenseInputParams params) → ExpenseCalculationResult
getFormulaDescription(ExpenseType type) → String
getRequiredInputs(ExpenseType type) → List<ExpenseInputField>

Relationships

Dependencies (1)

Components this component depends on

Dependents (2)

Components that depend on this component

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/expense-calculations 6 endpoints
GET /api/v1/expense-calculations List historical expense calculations
GET /api/v1/expense-calculations/:id Get a specific calculation result
POST /api/v1/expense-calculations Calculate reimbursement for selected expense types and input params
PUT /api/v1/expense-calculations/:id Recalculate with updated input parameters
DELETE /api/v1/expense-calculations/:id Delete a calculation record
GET /api/v1/expense-calculations/required-inputs/:expense_type Get required input fields for a specific expense type