A 30-foot boat rings up $845 for haul-out, prep, and four months of storage. Apply the $200 deposit and the balance is $645. The marina later changes all three rates. Open the approved revision again and the same $645 is still due.

Price the work order at approval

Length overall (LOA) is the billable length for the haul-out in this example. The fixture takes whole billable feet and whole storage months as inputs. If a marina bills fractional lengths, establish the billable quantity under its pricing terms before approval.

Work-order line Calculation Amount
Haul-out 30 ft × $4 per foot $120
Prep One flat charge $125
Seasonal storage 4 months × $150 per month $600
Approved total $845
Applied deposit Receipt DEP-200 −$200
Balance $645

Use bigint cents for rates, charges, and deposits. At approval, copy the live rates and freeze the copied rates, calculated charges, and revision record. Those nested freezes matter because Object.freeze operates on one object at a time. Editing the live card to $5 per foot, $150 for prep, and $170 per month produces a $980 second approval and leaves revision 1 at $845.

Replay the applied deposits

The example ledger contains one row per applied receipt for the work order. Each row carries its receipt ID, work-order ID, and amount applied. Before subtracting the credits, reject duplicate receipt IDs, receipts attached to another order, and totals above the approved price. Replaying the same deposit entries against the saved approval reproduces the balance without reading the live rate card.

Run the benchmark

Save the block as boathaul-benchmark.ts and run node --experimental-strip-types boathaul-benchmark.ts with Node.js 24. The script needs no packages. Node.js TypeScript documentation

import assert from "node:assert/strict"; type RateCard = { haulPerFootCents: bigint; prepCents: bigint; storagePerMonthCents: bigint; }; type WorkOrderRevision = { workOrderId: string; revision: number; loaFeet: bigint; storageMonths: bigint; }; type DepositApplication = { receiptId: string; workOrderId: string; appliedCents: bigint; }; function approve(draft: WorkOrderRevision, rateCard: RateCard) { const { workOrderId, revision, loaFeet, storageMonths } = draft; assert(workOrderId.trim(), "Work order ID is required"); assert(Number.isSafeInteger(revision) && revision > 0, "Invalid revision"); assert(loaFeet > 0n && storageMonths >= 0n, "Invalid LOA or storage term"); const rates = Object.freeze({ ...rateCard }); assert(rates.haulPerFootCents >= 0n && rates.prepCents >= 0n && rates.storagePerMonthCents >= 0n, "Rates must be nonnegative"); const haulCents = loaFeet * rates.haulPerFootCents; const storageCents = storageMonths * rates.storagePerMonthCents; const charges = Object.freeze({ haulCents, prepCents: rates.prepCents, storageCents, totalCents: haulCents + rates.prepCents + storageCents, }); return Object.freeze({ workOrderId, revision, loaFeet, storageMonths, rates, charges }); } function reconcileDeposit( approval: ReturnType<typeof approve>, applications: readonly DepositApplication[], ) { const usedReceipts = new Set<string>(); let appliedCents = 0n; for (const entry of applications) { const receiptId = entry.receiptId.trim(); assert(receiptId, "Deposit receipt ID is required"); assert.equal(entry.workOrderId, approval.workOrderId, "Deposit belongs to another work order"); assert(!usedReceipts.has(receiptId), `Duplicate deposit receipt: ${receiptId}`); assert(entry.appliedCents > 0n, "Applied deposit must be positive"); usedReceipts.add(receiptId); appliedCents += entry.appliedCents; } const { totalCents } = approval.charges; assert(appliedCents <= totalCents, "Applied deposits exceed approved total"); return { appliedCents, balanceCents: totalCents - appliedCents }; } const draft = { workOrderId: "WO-030", revision: 1, loaFeet: 30n, storageMonths: 4n }; const rateCard = { haulPerFootCents: 400n, prepCents: 12_500n, storagePerMonthCents: 15_000n }; const deposit = { receiptId: "DEP-200", workOrderId: draft.workOrderId, appliedCents: 20_000n }; const approved = approve(draft, rateCard); const expectedR1 = { ...draft, rates: { ...rateCard }, charges: { haulCents: 12_000n, prepCents: 12_500n, storageCents: 60_000n, totalCents: 84_500n }, }; assert.deepEqual(approved, expectedR1); assert.equal(Reflect.set(approved, "revision", 2), false); assert.equal(Reflect.set(approved.rates, "haulPerFootCents", 999n), false); assert.equal(Reflect.set(approved.charges, "totalCents", 0n), false); const originalBalance = reconcileDeposit(approved, [deposit]); assert.deepEqual(originalBalance, { appliedCents: 20_000n, balanceCents: 64_500n }); rateCard.haulPerFootCents = 500n; rateCard.prepCents = 15_000n; rateCard.storagePerMonthCents = 17_000n; const revisedApproval = approve({ ...draft, revision: 2 }, rateCard); const reopened = reconcileDeposit(approved, [deposit]); assert.deepEqual(approved, expectedR1); assert.deepEqual(reopened, originalBalance); assert.equal(revisedApproval.charges.totalCents, 98_000n); assert.throws(() => reconcileDeposit(approved, [deposit, { ...deposit, receiptId: " DEP-200 " }]), /Duplicate deposit receipt/); assert.throws(() => reconcileDeposit(approved, [{ ...deposit, workOrderId: "WO-031" }]), /another work order/); assert.throws(() => reconcileDeposit(approved, [{ ...deposit, appliedCents: 84_501n }]), /exceed approved total/); const { workOrderId, revision, charges } = approved; console.log(`${workOrderId} r${revision} haul + prep + storage (cents): ${charges.haulCents} + ${charges.prepCents} + ${charges.storageCents} = ${charges.totalCents}`); console.log(`Applied deposit / balance (cents): ${originalBalance.appliedCents} / ${originalBalance.balanceCents}`); console.log(`After rate-card edit, r${revision} total / balance (cents): ${charges.totalCents} / ${reopened.balanceCents}`); console.log(`New approval r${revisedApproval.revision} total (cents): ${revisedApproval.charges.totalCents}`); 

Verified Node output

WO-030 r1 haul + prep + storage (cents): 12000 + 12500 + 60000 = 84500 Applied deposit / balance (cents): 20000 / 64500 After rate-card edit, r1 total / balance (cents): 84500 / 64500 New approval r2 total (cents): 98000 

Persist approved snapshots under the work-order ID and revision number. Keep applied receipts with the work order so a marina can trace both the original price and the credits behind a balance.

BoatHaul marina work orders · B2B Ops and FinOps Benchmarks