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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/143-the-book-line-on-the-clock-adds-commissi → main 1 commit fork

  • Merged. mason/143-the-book-line-on-the-clock-adds-commissi was merged into main as f7b0b29.

Review

Sign in to review this change.
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
173173 terminal open the deal and press A; over MCP, the `update_address` tool.
174174 **Price and earnest money.** A deal may carry a sale price and an earnest
175175 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.
177177 The deal's page and the client timeline show them as `$425,000`, a deal
178178 with none shows nothing, and the earnest money reminder says the amount
179179 ("Your $12,750 earnest money deposit is due Nov 7"). The sample deals carry
contract/openapi.json +14 −2
@@ -579,11 +579,11 @@
579579 },
580580 "/api/book": {
581581 "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.",
583583 "operationId": "getApiBook",
584584 "responses": {
585585 "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.",
587587 "content": {
588588 "application/json": {
589589 "schema": {
@@ -612,6 +612,18 @@
612612 "without_price": {
613613 "type": "integer",
614614 "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."
615627 }
616628 }
617629 }
src/book.closed.test.ts +2 −1
@@ -56,7 +56,8 @@ test("the terminal's clock view opens with the same book line", () => {
5656 const t = terminal(openDb(dir), alice, { title: "deal-clock", where: "test", agent: { name: "Dana", brokerage: "HP", phone: "555", email: "[email protected]" } });
5757 const screen = t.screen().map((l) => l.replace(/\x1b\[[0-9;]*m/g, ""));
5858 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)");
6061 const guest = terminal(openDb(dir), { role: "anon" }, { title: "deal-clock", where: "test", agent: { name: "Dana", brokerage: "HP", phone: "555", email: "[email protected]" } });
6162 expect(guest.screen().map((l) => l.replace(/\x1b\[[0-9;]*m/g, "")).some((l) => l.includes("under contract"))).toBe(false);
6263 });
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
2525 const b = (await res.json()) as Record<string, number>;
2626 expect(b["under_contract"]).toBeGreaterThan(0);
2727 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");
2834 expect((await get("/api/book", {})).status).not.toBe(200);
2935 expect(JSON.stringify(await (await get("/openapi.json")).json())).toContain("/api/book");
3036 });
src/book.test.ts +29 −2
@@ -1,7 +1,8 @@
11 import { expect, test } from "bun:test";
22 import { bookLine, tally } from "./book.ts";
33
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,
56 closing,
67 sale_price,
78 closed: o.closed ?? false,
@@ -11,7 +12,7 @@ const ON = "2026-11-08";
1112
1213 test("an empty book is zeros", () => {
1314 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 });
1516 expect(bookLine(b, ON)).toBe("0 open · $0 under contract · 0 close in November · 0 closed this year, $0");
1617 });
1718
@@ -35,3 +36,29 @@ test("a deal that closed last year is not closed this year", () => {
3536 test("closings in other months are not this month's", () => {
3637 expect(tally([deal("2026-10-31", 1), deal("2026-11-01", 1), deal("2027-11-05", 1)], ON).closingThisMonth).toBe(1);
3738 });
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 @@
11 /**
22 * 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
45 * deal that fell through counts in none of it; a deal counts as closed on its
56 * closing date. Deals with no price count as deals and add no dollars.
67 */
78
8 import { dollars } from "./money.ts";
9 import { commission, dollars } from "./money.ts";
910
1011 export type Book = {
1112 /** Deals neither closed nor fallen through. */
@@ -20,22 +21,35 @@ export type Book = {
2021 closedVolume: number;
2122 /** Counted deals (open, or closed this year) that have no price. */
2223 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;
2332 };
2433
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 };
2635
2736 /** Totals over `deals`, as of `on` (YYYY-MM-DD). */
2837 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 };
3039 for (const deal of deals) {
3140 if (deal.fell_through) continue;
3241 const counted = deal.closed ? deal.closing.slice(0, 4) === on.slice(0, 4) : true;
3342 if (!counted) continue;
3443 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;
3547 if (deal.closed) {
48 totals.commissionEarned += pays;
3649 totals.closedThisYear++;
3750 totals.closedVolume += deal.sale_price ?? 0;
3851 } else {
52 totals.commissionPending += pays;
3953 totals.open++;
4054 totals.underContract += deal.sale_price ?? 0;
4155 if (deal.closing.slice(0, 7) === on.slice(0, 7)) totals.closingThisMonth++;
@@ -55,5 +69,6 @@ export function bookLine(b: Book, on: string): string {
5569 `${b.closingThisMonth} ${b.closingThisMonth === 1 ? "closes" : "close"} in ${month}`,
5670 `${b.closedThisYear} closed this year, ${dollars(b.closedVolume)}`,
5771 ];
72 if (b.withRate > 0) parts.push(`${dollars(b.commissionPending)} commission pending · ${dollars(b.commissionEarned)} earned this year`);
5873 return parts.join(" · ") + (b.withoutPrice > 0 ? ` (${b.withoutPrice} without a price)` : "");
5974 }
src/routes.ts +5 −2
@@ -197,6 +197,9 @@ const BOOK: Schema = {
197197 closed_this_year: { type: "integer", description: "Closed deals whose closing date is in the current year." },
198198 closed_volume: { type: "integer", description: "Their prices added." },
199199 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." },
200203 },
201204 };
202205 export const PERSON: Schema = {
@@ -1394,11 +1397,11 @@ export const routes: readonly Route[] = [
13941397 const b = tally(deals.value, today());
13951398 return answer({
13961399 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 },
13981401 });
13991402 },
14001403 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.",
14021405 answer: BOOK,
14031406 cell: { resource: "deal", verb: "list" },
14041407 },

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs