A booth item sells for $100.01 under a 60/40 agreement. The consignor receives $60.01 and the shop keeps $40.00. After payout, the customer returns $25.01 of the sale. The next statement posts a $15.01 debit against the consignor's $12.00 in new earnings. That run pays $0 and carries a $3.01 debit forward.
Reverse the original split in integer cents
Use the original sale line as the settlement record. The POS adapter supplies the amount eligible for splitting after it applies the agreement's rules for tax, fees, and discounts. This example rounds the consignor's share half up and gives the shop the residual cent. The two shares always add to the eligible amount.
A return inherits the original sale's allocations. Compute the consignor's cumulative reversal from the original allocation and the cumulative refunded cents. Subtract the already reversed amount to get the new debit, then assign the remainder of this refund to the shop. For a three-cent sale that paid two cents to the consignor, three successive one-cent refunds reverse one cent, zero cents, and one cent. The final return closes both shares exactly.
Carry the debit on the next open statement
Freeze settled statements and emit a new row keyed by return ID. The sample policy offsets the debit against the same consignor's future earnings. It pays out positive balances and carries a negative balance into the next period. The refund to the customer is separate from the settlement entries shown here.
Save the block as settlement.mts and run node settlement.mts with Node.js 24. The output shows the original payout, the first open run after the return, and the run that clears the debit. Node.js TypeScript documentation
import assert from "node:assert/strict"; type Entry = { id: string; saleId: string; consignor: string; consignorCents: bigint; shopCents: bigint }; type PostedSale = Entry & { grossCents: bigint }; type PosReturn = { id: string; saleId: string; eligibleCents: bigint }; function halfUp(numerator: bigint, denominator: bigint): bigint { return (numerator + denominator / 2n) / denominator; } function postSale(saleId: string, consignor: string, grossCents: bigint, shareBps: bigint): PostedSale { assert(grossCents > 0n && shareBps >= 0n && shareBps <= 10_000n, "Invalid sale or split"); const consignorCents = halfUp(grossCents * shareBps, 10_000n); return { id: `sale:${saleId}`, saleId, consignor, grossCents, consignorCents, shopCents: grossCents - consignorCents }; } function postReturn(sale: PostedSale, previouslyRefunded: bigint, refund: PosReturn): Entry { const cumulativeRefund = previouslyRefunded + refund.eligibleCents; assert(refund.saleId === sale.saleId && previouslyRefunded >= 0n && refund.eligibleCents > 0n && cumulativeRefund <= sale.grossCents, "Invalid refund"); const priorReversal = halfUp(sale.consignorCents * previouslyRefunded, sale.grossCents); const cumulativeReversal = halfUp(sale.consignorCents * cumulativeRefund, sale.grossCents); const consignorDebit = cumulativeReversal - priorReversal; return { id: `return:${refund.id}`, saleId: sale.saleId, consignor: sale.consignor, consignorCents: -consignorDebit, shopCents: -(refund.eligibleCents - consignorDebit), }; } function settle(consignor: string, openingCarry: bigint, entries: Entry[]) { assert(openingCarry <= 0n && entries.every((entry) => entry.consignor === consignor), "Invalid settlement scope"); assert.equal(new Set(entries.map((entry) => entry.id)).size, entries.length, "Duplicate entry"); const net = entries.reduce((balance, entry) => balance + entry.consignorCents, openingCarry); return { payout: net > 0n ? net : 0n, closingCarry: net < 0n ? net : 0n }; } const consignor = "BOOTH-17"; const original = postSale("S-101", consignor, 10_001n, 6_000n); assert.deepEqual([original.consignorCents, original.shopCents], [6_001n, 4_000n]); const paid = settle(consignor, 0n, [original]); assert.deepEqual(paid, { payout: 6_001n, closingCarry: 0n }); const refund = postReturn(original, 0n, { id: "R-01", saleId: "S-101", eligibleCents: 2_501n }); assert.deepEqual([refund.consignorCents, refund.shopCents], [-1_501n, -1_000n]); const next = settle(consignor, paid.closingCarry, [postSale("S-102", consignor, 2_000n, 6_000n), refund]); assert.deepEqual(next, { payout: 0n, closingCarry: -301n }); const later = settle(consignor, next.closingCarry, [postSale("S-103", consignor, 5_000n, 6_000n)]); assert.deepEqual(later, { payout: 2_699n, closingCarry: 0n }); const remainder = postReturn(original, 2_501n, { id: "R-02", saleId: "S-101", eligibleCents: 7_500n }); assert.equal(original.consignorCents + refund.consignorCents + remainder.consignorCents, 0n); assert.equal(original.shopCents + refund.shopCents + remainder.shopCents, 0n); assert.throws(() => settle(consignor, 0n, [refund, refund]), /Duplicate entry/); assert.throws(() => postReturn(original, 2_501n, { id: "R-03", saleId: "S-101", eligibleCents: 7_501n }), /Invalid refund/); const tinySale = postSale("S-104", consignor, 3n, 5_000n); assert.deepEqual([0n, 1n, 2n].map((prior, index) => postReturn(tinySale, prior, { id: `R-tiny-${index}`, saleId: tinySale.saleId, eligibleCents: 1n, }).consignorCents), [-1n, 0n, -1n]); console.table({ paid, next, later }); In a database-backed POS, make return IDs unique per source and store the return entry and cumulative refunded amount in the same transaction. Assign each ledger entry to one completed settlement so a retried export reads the same statement. The per-consignor PDF and XLSX should show the opening carry, itemized activity, payout, and closing carry from that settlement. ConsignPack

