code wiki / (root) / nx_billing.nx

nx_billing.nx source

↩ module page · 49 lines · 2522 B

1// nx_billing.nx -- Nishi Office TIME & BILLING CLI/MCP organ: self-verifying demo over 2// nx_billing_lib. Logs billable time on a matter, invoices it, applies earned fees FROM the 3// IOLTA trust (RPC 1.15), and proves the no-overdraw refusal. license_tier: ORIGINAL 4 5import "nx_billing_lib.nx" 6const K_MAGIC_200000: i64 = 200000 7const K_MAGIC_30000: i64 = 30000 8const K_MAGIC_105000: i64 = 105000 9const K_MAGIC_95000: i64 = 95000 10const K_MAGIC_1024: i64 = 1024 11 12func main() -> i64 { 13 let bp: *u8 = "/tmp/nx_billing_demo-" as *u8 14 let tp: *u8 = "/tmp/nx_billing_trust-" as *u8 15 // client retainer: $2000 into IOLTA trust 16 trust_put(tp, "acme" as *u8, 0, "M-001" as *u8, "deposit" as *u8, K_MAGIC_200000) 17 // billable time on M-001: 2.5h + 1.0h @ $300/hr = $1050 18 bl_time_put(bp, "M-001" as *u8, 0, 250, K_MAGIC_30000, "research" as *u8) 19 bl_time_put(bp, "M-001" as *u8, 1, 100, K_MAGIC_30000, "drafting" as *u8) 20 let inv: i64 = bl_matter_total(bp, "M-001" as *u8) 21 if inv != K_MAGIC_105000 { return __syscall(93, 61, 0, 0, 0, 0, 0) } 22 // invoice + apply earned fees from trust (RPC 1.15) 23 let applied: i64 = bl_bill_from_trust(bp, "acme" as *u8, "M-001" as *u8, tp, 1) 24 if applied != K_MAGIC_105000 { return __syscall(93, 62, 0, 0, 0, 0, 0) } 25 let remain: i64 = trust_balance(tp, "acme" as *u8) 26 if remain != K_MAGIC_95000 { return __syscall(93, 63, 0, 0, 0, 0, 0) } 27 // M-002: $3000 of time, but trust only has $950 left -> NO-OVERDRAW refusal 28 bl_time_put(bp, "M-002" as *u8, 0, 1000, K_MAGIC_30000, "trial" as *u8) 29 let m2: i64 = bl_bill_from_trust(bp, "acme" as *u8, "M-002" as *u8, tp, 2) 30 if m2 != 0 - 1 { return __syscall(93, 64, 0, 0, 0, 0, 0) } 31 if trust_balance(tp, "acme" as *u8) != K_MAGIC_95000 { return __syscall(93, 65, 0, 0, 0, 0, 0) } 32 let d: *u8 = sys_mmap(32) 33 let out: *u8 = sys_mmap(K_MAGIC_1024) 34 var o: i64 = 0 35 o = mt_catcopy(out, o, "NISHI-BILLING OK matter=M-001 time-entries=2 invoice=" as *u8) 36 tr_dollars(inv, d) 37 o = mt_catcopy(out, o, d) 38 o = mt_catcopy(out, o, " applied-from-trust(RPC1.15)=" as *u8) 39 tr_dollars(applied, d) 40 o = mt_catcopy(out, o, d) 41 o = mt_catcopy(out, o, " trust-remaining=" as *u8) 42 tr_dollars(remain, d) 43 o = mt_catcopy(out, o, d) 44 o = mt_catcopy(out, o, " | M-002 invoice=$3000.00 > trust=$950.00 -> OVERDRAW-REFUSED trust-untouched | integer-cents-exact" as *u8) 45 out[o] = 10 as u8 46 o = o + 1 47 sys_write(1, out, o) 48 return __syscall(93, 0, 0, 0, 0, 0, 0) 49}