Deterministic multi-source business ledger reconciliation and exception attribution.
moon check
moon test
moon run cmd/mainlet policy = @ledgerweave.default_policy()
let input : @ledgerweave.LedgerInput = {
orders: [{ id: "ORD-1", account_id: "team", currency: "CNY", amount_minor: 1000, created_day: 1, status: Paid }],
payments: [{ id: "PAY-1", order_id: "ORD-1", currency: "CNY", amount_minor: 1000, received_day: 1, status: Captured }],
refunds: [],
adjustments: [],
}
let result = @ledgerweave.reconcile(input, policy, 1)
assert_true(result.valid)moon fmt
moon check
moon test
moon build --target native
moon publish --dry-runmoon 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 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 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 PaymentRecord {
id : String
order_id : String
currency : String
amount_minor : Int
received_day : Int
status : PaymentStatus
} derive(Eq, Debug)fn make_finding(code : FindingCode, severity : Severity, record_kind : RecordKind, record_id : String, order_id : String, message : String) -> Findingfn parse_day(text : String) -> Intfn parse_ledger_csv(orders : String, payments : String, refunds : String, adjustments : String) -> LedgerInputInstall
Download zipDeterministic multi-source business ledger reconciliation and exception attribution.