Public: anyone can read this; the crew can change it.
The book line on the clock adds commission pending on open deals and commission earned this year, so the agent sees their year in one look #150
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/143-the-book-line-on-the-clock-adds-commissi → main 1 commit fork
7 files
changed +76
−12
README.md +1 −1
| @@ -173,7 +173,7 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 173 | 173 | terminal open the deal and press A; over MCP, the `update_address` tool. |
| 174 | 174 | **Price and earnest money.** A deal may carry a sale price and an earnest |
| 175 | 175 | money amount, in whole dollars (digits only, up to 100,000,000): set them |
| 176 | when you open the deal, or tap Edit price and earnest money on its page. Under the clock's heading one line adds up your book ("6 open · $2,410,000 under contract · 2 close in November · 3 closed this year, $1,180,000"; deals without a price add no dollars and are noted, deals that fell through count in none), and each Closed line shows its price. | |
| 176 | when you open the deal, or tap Edit price and earnest money on its page. Under the clock's heading one line adds up your book ("6 open · $2,410,000 under contract · 2 close in November · 3 closed this year, $1,180,000"; once any deal has a commission rate it ends "· $31,000 commission pending · $9,000 earned this year" (open deals with a price and a rate; deals closed this year; the sample deals show it; the figure is on this line only, never on This week or the printed sheet); deals without a price add no dollars and are noted, deals that fell through count in none), and each Closed line shows its price. | |
| 177 | 177 | The deal's page and the client timeline show them as `$425,000`, a deal |
| 178 | 178 | with none shows nothing, and the earnest money reminder says the amount |
| 179 | 179 | ("Your $12,750 earnest money deposit is due Nov 7"). The sample deals carry |
contract/openapi.json +14 −2
| @@ -579,11 +579,11 @@ | ||
| 579 | 579 | }, |
| 580 | 580 | "/api/book": { |
| 581 | 581 | "get": { |
| 582 | "summary": "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, and how many counted deals have no price. Deals that fell through count in none.", | |
| 582 | "summary": "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, how many counted deals have no price, the commission pending on open deals and earned this year, and how many priced deals have no rate. Deals that fell through count in none.", | |
| 583 | 583 | "operationId": "getApiBook", |
| 584 | 584 | "responses": { |
| 585 | 585 | "200": { |
| 586 | "description": "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, and how many counted deals have no price. Deals that fell through count in none.", | |
| 586 | "description": "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, how many counted deals have no price, the commission pending on open deals and earned this year, and how many priced deals have no rate. Deals that fell through count in none.", | |
| 587 | 587 | "content": { |
| 588 | 588 | "application/json": { |
| 589 | 589 | "schema": { |
| @@ -612,6 +612,18 @@ | ||
| 612 | 612 | "without_price": { |
| 613 | 613 | "type": "integer", |
| 614 | 614 | "description": "Counted deals with no price." |
| 615 | }, | |
| 616 | "commission_pending": { | |
| 617 | "type": "integer", | |
| 618 | "description": "Commissions of the open deals that have a price and a rate, in whole dollars." | |
| 619 | }, | |
| 620 | "commission_earned": { | |
| 621 | "type": "integer", | |
| 622 | "description": "Commissions of the deals closed this year that have a price and a rate, in whole dollars." | |
| 623 | }, | |
| 624 | "without_rate": { | |
| 625 | "type": "integer", | |
| 626 | "description": "Counted deals that have a price but no commission rate." | |
| 615 | 627 | } |
| 616 | 628 | } |
| 617 | 629 | } |
src/book.closed.test.ts +2 −1
| @@ -56,7 +56,8 @@ test("the terminal's clock view opens with the same book line", () => { | ||
| 56 | 56 | const t = terminal(openDb(dir), alice, { title: "deal-clock", where: "test", agent: { name: "Dana", brokerage: "HP", phone: "555", email: "[email protected]" } }); |
| 57 | 57 | const screen = t.screen().map((l) => l.replace(/\x1b\[[0-9;]*m/g, "")); |
| 58 | 58 | expect(screen).toContain(want); |
| 59 | expect(want).toContain("2 closed this year, $612,000 ("); | |
| 59 | expect(want).toContain("2 closed this year, $612,000 · "); | |
| 60 | expect(want).toContain("(1 without a price)"); | |
| 60 | 61 | const guest = terminal(openDb(dir), { role: "anon" }, { title: "deal-clock", where: "test", agent: { name: "Dana", brokerage: "HP", phone: "555", email: "[email protected]" } }); |
| 61 | 62 | expect(guest.screen().map((l) => l.replace(/\x1b\[[0-9;]*m/g, "")).some((l) => l.includes("under contract"))).toBe(false); |
| 62 | 63 | }); |
src/book.page.test.ts +6
| @@ -25,6 +25,12 @@ test("the clock opens with the book in one line, and GET /api/book says the same | ||
| 25 | 25 | const b = (await res.json()) as Record<string, number>; |
| 26 | 26 | expect(b["under_contract"]).toBeGreaterThan(0); |
| 27 | 27 | expect(line.startsWith(`${b["open"]} open · $${b["under_contract"]!.toLocaleString("en-US")} under contract`)).toBe(true); |
| 28 | expect(b["commission_pending"]).toBeGreaterThan(0); | |
| 29 | expect(b["commission_earned"]).toBeGreaterThanOrEqual(0); | |
| 30 | expect(b["without_rate"]).toBe(0); | |
| 31 | expect(line).toContain(`$${b["commission_pending"]!.toLocaleString("en-US")} commission pending · $${b["commission_earned"]!.toLocaleString("en-US")} earned this year`); | |
| 32 | // The figure stays on the book line: never This week. | |
| 33 | expect(await (await get("/week")).text()).not.toContain("commission pending"); | |
| 28 | 34 | expect((await get("/api/book", {})).status).not.toBe(200); |
| 29 | 35 | expect(JSON.stringify(await (await get("/openapi.json")).json())).toContain("/api/book"); |
| 30 | 36 | }); |
src/book.test.ts +29 −2
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | 2 | import { bookLine, tally } from "./book.ts"; |
| 3 | 3 | |
| 4 | const deal = (closing: string, sale_price: number | null, o: { closed?: boolean; fell_through?: boolean } = {}) => ({ | |
| 4 | const deal = (closing: string, sale_price: number | null, o: { closed?: boolean; fell_through?: boolean; rate?: number | null } = {}) => ({ | |
| 5 | commission_rate: o.rate ?? null, | |
| 5 | 6 | closing, |
| 6 | 7 | sale_price, |
| 7 | 8 | closed: o.closed ?? false, |
| @@ -11,7 +12,7 @@ const ON = "2026-11-08"; | ||
| 11 | 12 | |
| 12 | 13 | test("an empty book is zeros", () => { |
| 13 | 14 | const b = tally([], ON); |
| 14 | expect(b).toEqual({ open: 0, underContract: 0, closingThisMonth: 0, closedThisYear: 0, closedVolume: 0, withoutPrice: 0 }); | |
| 15 | expect(b).toEqual({ open: 0, underContract: 0, closingThisMonth: 0, closedThisYear: 0, closedVolume: 0, withoutPrice: 0, commissionPending: 0, commissionEarned: 0, withRate: 0, withoutRate: 0 }); | |
| 15 | 16 | expect(bookLine(b, ON)).toBe("0 open · $0 under contract · 0 close in November · 0 closed this year, $0"); |
| 16 | 17 | }); |
| 17 | 18 | |
| @@ -35,3 +36,29 @@ test("a deal that closed last year is not closed this year", () => { | ||
| 35 | 36 | test("closings in other months are not this month's", () => { |
| 36 | 37 | expect(tally([deal("2026-10-31", 1), deal("2026-11-01", 1), deal("2027-11-05", 1)], ON).closingThisMonth).toBe(1); |
| 37 | 38 | }); |
| 39 | ||
| 40 | test("commission: open pending, closed this year earned, last year and fell through in neither", () => { | |
| 41 | const b = tally( | |
| 42 | [ | |
| 43 | deal("2026-11-20", 400_000, { rate: 250 }), | |
| 44 | deal("2026-03-01", 300_000, { closed: true, rate: 300 }), | |
| 45 | deal("2025-12-30", 500_000, { closed: true, rate: 300 }), | |
| 46 | deal("2026-12-01", 600_000, { fell_through: true, rate: 300 }), | |
| 47 | ], | |
| 48 | ON, | |
| 49 | ); | |
| 50 | expect(b).toMatchObject({ commissionPending: 10_000, commissionEarned: 9_000, withoutRate: 0 }); | |
| 51 | expect(bookLine(b, ON)).toContain(" · $10,000 commission pending · $9,000 earned this year"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("a deal with a price and no rate is counted without_rate and adds nothing; no rates, no commission words", () => { | |
| 55 | const b = tally([deal("2026-11-20", 400_000), deal("2026-12-02", null)], ON); | |
| 56 | expect(b).toMatchObject({ commissionPending: 0, commissionEarned: 0, withoutRate: 1 }); | |
| 57 | expect(bookLine(b, ON)).not.toContain("commission"); | |
| 58 | }); | |
| 59 | ||
| 60 | test("a rate with no price pays nothing but still shows the commission figures", () => { | |
| 61 | const b = tally([deal("2026-11-20", null, { rate: 250 })], ON); | |
| 62 | expect(b).toMatchObject({ commissionPending: 0, withoutRate: 0 }); | |
| 63 | expect(bookLine(b, ON)).toContain("$0 commission pending · $0 earned this year"); | |
| 64 | }); |
src/book.ts +19 −4
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The agent's book in one line: open deals, dollars under contract, closings |
| 3 | * this month, and what closed this year. Plain deals in, plain totals out. A | |
| 3 | * this month, and what closed this year; when deals carry a commission rate, what | |
| 4 | * the open ones will pay and what this year's closed ones paid. Plain deals in, plain totals out. A | |
| 4 | 5 | * deal that fell through counts in none of it; a deal counts as closed on its |
| 5 | 6 | * closing date. Deals with no price count as deals and add no dollars. |
| 6 | 7 | */ |
| 7 | 8 | |
| 8 | import { dollars } from "./money.ts"; | |
| 9 | import { commission, dollars } from "./money.ts"; | |
| 9 | 10 | |
| 10 | 11 | export type Book = { |
| 11 | 12 | /** Deals neither closed nor fallen through. */ |
| @@ -20,22 +21,35 @@ export type Book = { | ||
| 20 | 21 | closedVolume: number; |
| 21 | 22 | /** Counted deals (open, or closed this year) that have no price. */ |
| 22 | 23 | withoutPrice: number; |
| 24 | /** Open deals with a price and a rate: what their commissions pay at closing, in whole dollars. */ | |
| 25 | commissionPending: number; | |
| 26 | /** Deals closed this year with a price and a rate: what their commissions paid, in whole dollars. */ | |
| 27 | commissionEarned: number; | |
| 28 | /** Counted deals that have a rate. */ | |
| 29 | withRate: number; | |
| 30 | /** Counted deals that have a price but no rate. */ | |
| 31 | withoutRate: number; | |
| 23 | 32 | }; |
| 24 | 33 | |
| 25 | type Counted = { closing: string; closed: boolean; fell_through: boolean; sale_price: number | null }; | |
| 34 | type Counted = { closing: string; closed: boolean; fell_through: boolean; sale_price: number | null; commission_rate: number | null }; | |
| 26 | 35 | |
| 27 | 36 | /** Totals over `deals`, as of `on` (YYYY-MM-DD). */ |
| 28 | 37 | export function tally(deals: readonly Counted[], on: string): Book { |
| 29 | const totals: Book = { open: 0, underContract: 0, closingThisMonth: 0, closedThisYear: 0, closedVolume: 0, withoutPrice: 0 }; | |
| 38 | const totals: Book = { open: 0, underContract: 0, closingThisMonth: 0, closedThisYear: 0, closedVolume: 0, withoutPrice: 0, commissionPending: 0, commissionEarned: 0, withRate: 0, withoutRate: 0 }; | |
| 30 | 39 | for (const deal of deals) { |
| 31 | 40 | if (deal.fell_through) continue; |
| 32 | 41 | const counted = deal.closed ? deal.closing.slice(0, 4) === on.slice(0, 4) : true; |
| 33 | 42 | if (!counted) continue; |
| 34 | 43 | if (deal.sale_price === null) totals.withoutPrice++; |
| 44 | if (deal.commission_rate !== null) totals.withRate++; | |
| 45 | else if (deal.sale_price !== null) totals.withoutRate++; | |
| 46 | const pays = deal.sale_price !== null && deal.commission_rate !== null ? commission(deal.sale_price, deal.commission_rate) : 0; | |
| 35 | 47 | if (deal.closed) { |
| 48 | totals.commissionEarned += pays; | |
| 36 | 49 | totals.closedThisYear++; |
| 37 | 50 | totals.closedVolume += deal.sale_price ?? 0; |
| 38 | 51 | } else { |
| 52 | totals.commissionPending += pays; | |
| 39 | 53 | totals.open++; |
| 40 | 54 | totals.underContract += deal.sale_price ?? 0; |
| 41 | 55 | if (deal.closing.slice(0, 7) === on.slice(0, 7)) totals.closingThisMonth++; |
| @@ -55,5 +69,6 @@ export function bookLine(b: Book, on: string): string { | ||
| 55 | 69 | `${b.closingThisMonth} ${b.closingThisMonth === 1 ? "closes" : "close"} in ${month}`, |
| 56 | 70 | `${b.closedThisYear} closed this year, ${dollars(b.closedVolume)}`, |
| 57 | 71 | ]; |
| 72 | if (b.withRate > 0) parts.push(`${dollars(b.commissionPending)} commission pending · ${dollars(b.commissionEarned)} earned this year`); | |
| 58 | 73 | return parts.join(" · ") + (b.withoutPrice > 0 ? ` (${b.withoutPrice} without a price)` : ""); |
| 59 | 74 | } |
src/routes.ts +5 −2
| @@ -197,6 +197,9 @@ const BOOK: Schema = { | ||
| 197 | 197 | closed_this_year: { type: "integer", description: "Closed deals whose closing date is in the current year." }, |
| 198 | 198 | closed_volume: { type: "integer", description: "Their prices added." }, |
| 199 | 199 | without_price: { type: "integer", description: "Counted deals with no price." }, |
| 200 | commission_pending: { type: "integer", description: "Commissions of the open deals that have a price and a rate, in whole dollars." }, | |
| 201 | commission_earned: { type: "integer", description: "Commissions of the deals closed this year that have a price and a rate, in whole dollars." }, | |
| 202 | without_rate: { type: "integer", description: "Counted deals that have a price but no commission rate." }, | |
| 200 | 203 | }, |
| 201 | 204 | }; |
| 202 | 205 | export const PERSON: Schema = { |
| @@ -1394,11 +1397,11 @@ export const routes: readonly Route[] = [ | ||
| 1394 | 1397 | const b = tally(deals.value, today()); |
| 1395 | 1398 | return answer({ |
| 1396 | 1399 | ok: true, |
| 1397 | value: { open: b.open, under_contract: b.underContract, closing_this_month: b.closingThisMonth, closed_this_year: b.closedThisYear, closed_volume: b.closedVolume, without_price: b.withoutPrice }, | |
| 1400 | value: { open: b.open, under_contract: b.underContract, closing_this_month: b.closingThisMonth, closed_this_year: b.closedThisYear, closed_volume: b.closedVolume, without_price: b.withoutPrice, commission_pending: b.commissionPending, commission_earned: b.commissionEarned, without_rate: b.withoutRate }, | |
| 1398 | 1401 | }); |
| 1399 | 1402 | }, |
| 1400 | 1403 | api: { |
| 1401 | summary: "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, and how many counted deals have no price. Deals that fell through count in none.", | |
| 1404 | summary: "The agent's book as numbers: open deals, dollars under contract, open deals closing this month, deals closed this year with their sales volume, how many counted deals have no price, the commission pending on open deals and earned this year, and how many priced deals have no rate. Deals that fell through count in none.", | |
| 1402 | 1405 | answer: BOOK, |
| 1403 | 1406 | cell: { resource: "deal", verb: "list" }, |
| 1404 | 1407 | }, |
new above
offline