Deterministic multi-source business ledger reconciliation and exception attribution.
Dependencies
moon update
moon check --target native
moon test --target native
moon build --target nativemoon run --target native cmd/main -- \
examples/csv/orders.csv examples/csv/payments.csv \
examples/csv/refunds.csv examples/csv/adjustments.csv 40pub(all) struct AdjustmentRecord {
id : String
order_id : String
currency : String
amount_minor : Int
day : Int
direction : AdjustmentDirection
reason : String
} derive(Eq, Debug)pub(all) struct AllocationPlan {
allocations : Array[PaymentAllocation]
unallocated_minor : Int
allocated_minor : Int
ignored_minor : Int
valid : Bool
} derive(Eq, Debug)pub(all) struct Finding {
code : FindingCode
severity : Severity
record_kind : RecordKind
record_id : String
order_id : String
message : String
} derive(Eq, Debug)pub(all) enum FindingCode {
DuplicateOrderId
DuplicatePaymentId
DuplicateRefundId
DuplicateAdjustmentId
InvalidAmount
InvalidCurrency
UnknownOrder
CurrencyMismatch
PaymentAfterDeadline
PaymentForCancelledOrder
RefundExceedsPayment
Overpaid
Underpaid
OpenPastDue
PaymentVoided
MissingReference
} derive(Eq, Debug)pub(all) struct FindingQuery {
minimum_severity : Severity
code : FindingCode?
order_id : String?
record_kind : RecordKind?
} derive(Eq, Debug)pub(all) struct InputQualityReport {
orders : SourceProfile
payments : SourceProfile
refunds : SourceProfile
adjustments : SourceProfile
issues : Array[QualityIssue]
ready : Bool
} derive(Eq, Debug)pub(all) struct LedgerInput {
orders : Array[OrderRecord]
payments : Array[PaymentRecord]
refunds : Array[RefundRecord]
adjustments : Array[AdjustmentRecord]
} derive(Eq, Debug)pub(all) struct OrderBalance {
order_id : String
expected_minor : Int
captured_minor : Int
refunded_minor : Int
adjustments_minor : Int
outstanding_minor : Int
resolution : Resolution
} derive(Eq, Debug)pub(all) struct OrderRecord {
id : String
account_id : String
currency : String
amount_minor : Int
created_day : Int
status : OrderStatus
} derive(Eq, Debug)pub(all) struct PaymentAllocation {
payment_id : String
order_id : String
currency : String
allocated_minor : Int
state : AllocationState
note : String
} derive(Eq, Debug)pub(all) struct PaymentRecord {
id : String
order_id : String
currency : String
amount_minor : Int
received_day : Int
status : PaymentStatus
} derive(Eq, Debug)pub(all) struct QualityIssue {
source : SourceKind
row_number : Int
record_id : String
order_id : String
code : QualityIssueCode
severity : Severity
message : String
} derive(Eq, Debug)pub(all) struct ResultMetrics {
finding_metrics : FindingMetrics
settled_orders : Int
awaiting_payment_orders : Int
over_collected_orders : Int
refund_risk_orders : Int
review_orders : Int
expected_minor : Int
captured_minor : Int
refunded_minor : Int
outstanding_minor : Int
} derive(Eq, Debug)pub(all) struct ReviewCase {
case_id : String
finding : Finding
priority : Int
state : ReviewState
owner : String
opened_day : Int
updated_day : Int
decision : ReviewDecision
resolution_note : String
} derive(Eq, Debug)pub(all) struct SourceProfile {
source : SourceKind
record_count : Int
blank_identifier_count : Int
duplicate_identifier_count : Int
invalid_amount_count : Int
blank_reference_count : Int
orphan_reference_count : Int
invalid_currency_count : Int
future_day_count : Int
} derive(Eq, Debug)fn allocations_for_order(allocations : Array[PaymentAllocation], order_id : String) -> Array[PaymentAllocation]fn allocations_for_payment(allocations : Array[PaymentAllocation], payment_id : String) -> Array[PaymentAllocation]fn assign_case(queue : ReviewQueue, wanted : String, owner : String, updated_day : Int) -> ReviewQueuefn auto_assign(queue : ReviewQueue, rules : Array[AssignmentRule], updated_day : Int) -> ReviewQueuefn balances_above_outstanding(balances : Array[OrderBalance], threshold_minor : Int) -> Array[OrderBalance]fn balances_below_outstanding(balances : Array[OrderBalance], threshold_minor : Int) -> Array[OrderBalance]fn decide_case(queue : ReviewQueue, wanted : String, decision : ReviewDecision, note : String, updated_day : Int) -> ReviewQueuefn enqueue_findings(queue : ReviewQueue, findings : Array[Finding], opened_day : Int) -> ReviewQueuefn inspect_input_quality(input : LedgerInput, policy : Policy, current_day : Int) -> InputQualityReportfn make_finding(code : FindingCode, severity : Severity, record_kind : RecordKind, record_id : String, order_id : String, message : String) -> Findingfn outstanding_by_age(input : LedgerInput, result : ReconciliationResult, current_day : Int) -> Array[AgeBucket]fn overdue_cases(cases : Array[ReviewCase], current_day : Int, max_age_days : Int) -> Array[ReviewCase]fn parse_day(text : String) -> Intfn parse_ledger_csv(orders : String, payments : String, refunds : String, adjustments : String) -> LedgerInputfn quality_issue(source : SourceKind, row_number : Int, record_id : String, order_id : String, code : QualityIssueCode, message : String) -> QualityIssuefn quality_issues_for_code(report : InputQualityReport, code : QualityIssueCode) -> Array[QualityIssue]fn quality_issues_for_source(report : InputQualityReport, source : SourceKind) -> Array[QualityIssue]fn render_audit_bundle(input : LedgerInput, result : ReconciliationResult, current_day : Int) -> Stringfn set_case_priority(queue : ReviewQueue, wanted : String, priority : Int, updated_day : Int) -> ReviewQueuefn transition_case(queue : ReviewQueue, wanted : String, target : ReviewState, updated_day : Int) -> ReviewQueueInstall
Download zipDeterministic multi-source business ledger reconciliation and exception attribution.
Dependencies