@baack-software/baack-ts-crm 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +74 -2
  3. package/dist/account.d.ts +36 -0
  4. package/dist/account.d.ts.map +1 -0
  5. package/dist/account.js +48 -0
  6. package/dist/account.js.map +1 -0
  7. package/dist/backend.d.ts +76 -0
  8. package/dist/backend.d.ts.map +1 -0
  9. package/dist/backend.js +233 -0
  10. package/dist/backend.js.map +1 -0
  11. package/dist/crm-client.d.ts +122 -0
  12. package/dist/crm-client.d.ts.map +1 -0
  13. package/dist/crm-client.js +168 -0
  14. package/dist/crm-client.js.map +1 -0
  15. package/dist/errors.d.ts +21 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +33 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/index.d.ts +13 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +13 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/invoices.d.ts +46 -0
  24. package/dist/invoices.d.ts.map +1 -0
  25. package/dist/invoices.js +137 -0
  26. package/dist/invoices.js.map +1 -0
  27. package/dist/leads.d.ts +29 -0
  28. package/dist/leads.d.ts.map +1 -0
  29. package/dist/leads.js +56 -0
  30. package/dist/leads.js.map +1 -0
  31. package/dist/mock/index.d.ts +43 -0
  32. package/dist/mock/index.d.ts.map +1 -0
  33. package/dist/mock/index.js +303 -0
  34. package/dist/mock/index.js.map +1 -0
  35. package/dist/money.d.ts +29 -0
  36. package/dist/money.d.ts.map +1 -0
  37. package/dist/money.js +82 -0
  38. package/dist/money.js.map +1 -0
  39. package/dist/period.d.ts +17 -0
  40. package/dist/period.d.ts.map +1 -0
  41. package/dist/period.js +23 -0
  42. package/dist/period.js.map +1 -0
  43. package/dist/pipeline.d.ts +30 -0
  44. package/dist/pipeline.d.ts.map +1 -0
  45. package/dist/pipeline.js +40 -0
  46. package/dist/pipeline.js.map +1 -0
  47. package/dist/react/Charts.d.ts +19 -0
  48. package/dist/react/Charts.d.ts.map +1 -0
  49. package/dist/react/Charts.js +38 -0
  50. package/dist/react/Charts.js.map +1 -0
  51. package/dist/react/CompanyAccountView.d.ts +21 -0
  52. package/dist/react/CompanyAccountView.d.ts.map +1 -0
  53. package/dist/react/CompanyAccountView.js +27 -0
  54. package/dist/react/CompanyAccountView.js.map +1 -0
  55. package/dist/react/DashboardCards.d.ts +32 -0
  56. package/dist/react/DashboardCards.d.ts.map +1 -0
  57. package/dist/react/DashboardCards.js +38 -0
  58. package/dist/react/DashboardCards.js.map +1 -0
  59. package/dist/react/DealsBoard.d.ts +30 -0
  60. package/dist/react/DealsBoard.d.ts.map +1 -0
  61. package/dist/react/DealsBoard.js +33 -0
  62. package/dist/react/DealsBoard.js.map +1 -0
  63. package/dist/react/Details.d.ts +52 -0
  64. package/dist/react/Details.d.ts.map +1 -0
  65. package/dist/react/Details.js +111 -0
  66. package/dist/react/Details.js.map +1 -0
  67. package/dist/react/Forms.d.ts +59 -0
  68. package/dist/react/Forms.d.ts.map +1 -0
  69. package/dist/react/Forms.js +204 -0
  70. package/dist/react/Forms.js.map +1 -0
  71. package/dist/react/LeadsTable.d.ts +22 -0
  72. package/dist/react/LeadsTable.d.ts.map +1 -0
  73. package/dist/react/LeadsTable.js +79 -0
  74. package/dist/react/LeadsTable.js.map +1 -0
  75. package/dist/react/Sales.d.ts +49 -0
  76. package/dist/react/Sales.d.ts.map +1 -0
  77. package/dist/react/Sales.js +186 -0
  78. package/dist/react/Sales.js.map +1 -0
  79. package/dist/react/SidePanel.d.ts +21 -0
  80. package/dist/react/SidePanel.d.ts.map +1 -0
  81. package/dist/react/SidePanel.js +37 -0
  82. package/dist/react/SidePanel.js.map +1 -0
  83. package/dist/react/format.d.ts +28 -0
  84. package/dist/react/format.d.ts.map +1 -0
  85. package/dist/react/format.js +30 -0
  86. package/dist/react/format.js.map +1 -0
  87. package/dist/react/index.d.ts +14 -0
  88. package/dist/react/index.d.ts.map +1 -0
  89. package/dist/react/index.js +14 -0
  90. package/dist/react/index.js.map +1 -0
  91. package/dist/react/parts.d.ts +45 -0
  92. package/dist/react/parts.d.ts.map +1 -0
  93. package/dist/react/parts.js +59 -0
  94. package/dist/react/parts.js.map +1 -0
  95. package/dist/react/text.d.ts +145 -0
  96. package/dist/react/text.d.ts.map +1 -0
  97. package/dist/react/text.js +142 -0
  98. package/dist/react/text.js.map +1 -0
  99. package/dist/react/ui/alert.d.ts +11 -0
  100. package/dist/react/ui/alert.d.ts.map +1 -0
  101. package/dist/react/ui/alert.js +29 -0
  102. package/dist/react/ui/alert.js.map +1 -0
  103. package/dist/react/ui/badge.d.ts +10 -0
  104. package/dist/react/ui/badge.d.ts.map +1 -0
  105. package/dist/react/ui/badge.js +26 -0
  106. package/dist/react/ui/badge.js.map +1 -0
  107. package/dist/react/ui/button.d.ts +11 -0
  108. package/dist/react/ui/button.d.ts.map +1 -0
  109. package/dist/react/ui/button.js +37 -0
  110. package/dist/react/ui/button.js.map +1 -0
  111. package/dist/react/ui/card.d.ts +12 -0
  112. package/dist/react/ui/card.d.ts.map +1 -0
  113. package/dist/react/ui/card.js +26 -0
  114. package/dist/react/ui/card.js.map +1 -0
  115. package/dist/react/ui/chart.d.ts +45 -0
  116. package/dist/react/ui/chart.d.ts.map +1 -0
  117. package/dist/react/ui/chart.js +116 -0
  118. package/dist/react/ui/chart.js.map +1 -0
  119. package/dist/react/ui/input.d.ts +4 -0
  120. package/dist/react/ui/input.d.ts.map +1 -0
  121. package/dist/react/ui/input.js +8 -0
  122. package/dist/react/ui/input.js.map +1 -0
  123. package/dist/react/ui/label.d.ts +5 -0
  124. package/dist/react/ui/label.d.ts.map +1 -0
  125. package/dist/react/ui/label.js +10 -0
  126. package/dist/react/ui/label.js.map +1 -0
  127. package/dist/react/ui/progress.d.ts +5 -0
  128. package/dist/react/ui/progress.d.ts.map +1 -0
  129. package/dist/react/ui/progress.js +10 -0
  130. package/dist/react/ui/progress.js.map +1 -0
  131. package/dist/react/ui/select.d.ts +16 -0
  132. package/dist/react/ui/select.d.ts.map +1 -0
  133. package/dist/react/ui/select.js +37 -0
  134. package/dist/react/ui/select.js.map +1 -0
  135. package/dist/react/ui/separator.d.ts +5 -0
  136. package/dist/react/ui/separator.d.ts.map +1 -0
  137. package/dist/react/ui/separator.js +10 -0
  138. package/dist/react/ui/separator.js.map +1 -0
  139. package/dist/react/ui/sheet.d.ts +15 -0
  140. package/dist/react/ui/sheet.d.ts.map +1 -0
  141. package/dist/react/ui/sheet.js +38 -0
  142. package/dist/react/ui/sheet.js.map +1 -0
  143. package/dist/react/ui/skeleton.d.ts +3 -0
  144. package/dist/react/ui/skeleton.d.ts.map +1 -0
  145. package/dist/react/ui/skeleton.js +7 -0
  146. package/dist/react/ui/skeleton.js.map +1 -0
  147. package/dist/react/ui/table.d.ts +11 -0
  148. package/dist/react/ui/table.d.ts.map +1 -0
  149. package/dist/react/ui/table.js +29 -0
  150. package/dist/react/ui/table.js.map +1 -0
  151. package/dist/react/ui/tabs.d.ts +12 -0
  152. package/dist/react/ui/tabs.d.ts.map +1 -0
  153. package/dist/react/ui/tabs.js +31 -0
  154. package/dist/react/ui/tabs.js.map +1 -0
  155. package/dist/react/views.d.ts +60 -0
  156. package/dist/react/views.d.ts.map +1 -0
  157. package/dist/react/views.js +172 -0
  158. package/dist/react/views.js.map +1 -0
  159. package/dist/sales.d.ts +57 -0
  160. package/dist/sales.d.ts.map +1 -0
  161. package/dist/sales.js +64 -0
  162. package/dist/sales.js.map +1 -0
  163. package/dist/store.d.ts +140 -0
  164. package/dist/store.d.ts.map +1 -0
  165. package/dist/store.js +244 -0
  166. package/dist/store.js.map +1 -0
  167. package/dist/target.d.ts +21 -0
  168. package/dist/target.d.ts.map +1 -0
  169. package/dist/target.js +36 -0
  170. package/dist/target.js.map +1 -0
  171. package/dist/types.d.ts +180 -0
  172. package/dist/types.d.ts.map +1 -0
  173. package/dist/types.js +2 -0
  174. package/dist/types.js.map +1 -0
  175. package/package.json +100 -4
  176. package/src/account.ts +79 -0
  177. package/src/backend.ts +371 -0
  178. package/src/crm-client.ts +250 -0
  179. package/src/errors.ts +34 -0
  180. package/src/index.ts +12 -0
  181. package/src/invoices.ts +157 -0
  182. package/src/leads.ts +78 -0
  183. package/src/mock/index.ts +398 -0
  184. package/src/money.ts +104 -0
  185. package/src/period.ts +32 -0
  186. package/src/pipeline.ts +61 -0
  187. package/src/react/Charts.tsx +143 -0
  188. package/src/react/CompanyAccountView.tsx +198 -0
  189. package/src/react/DashboardCards.tsx +171 -0
  190. package/src/react/DealsBoard.tsx +177 -0
  191. package/src/react/Details.tsx +293 -0
  192. package/src/react/Forms.tsx +619 -0
  193. package/src/react/LeadsTable.tsx +234 -0
  194. package/src/react/Sales.tsx +539 -0
  195. package/src/react/SidePanel.tsx +95 -0
  196. package/src/react/format.ts +53 -0
  197. package/src/react/index.ts +13 -0
  198. package/src/react/parts.tsx +131 -0
  199. package/src/react/text.ts +144 -0
  200. package/src/react/ui/README.md +6 -0
  201. package/src/react/ui/alert.tsx +75 -0
  202. package/src/react/ui/badge.tsx +48 -0
  203. package/src/react/ui/button.tsx +66 -0
  204. package/src/react/ui/card.tsx +102 -0
  205. package/src/react/ui/chart.tsx +304 -0
  206. package/src/react/ui/input.tsx +18 -0
  207. package/src/react/ui/label.tsx +23 -0
  208. package/src/react/ui/progress.tsx +30 -0
  209. package/src/react/ui/select.tsx +189 -0
  210. package/src/react/ui/separator.tsx +27 -0
  211. package/src/react/ui/sheet.tsx +145 -0
  212. package/src/react/ui/skeleton.tsx +13 -0
  213. package/src/react/ui/table.tsx +113 -0
  214. package/src/react/ui/tabs.tsx +89 -0
  215. package/src/react/views.tsx +443 -0
  216. package/src/sales.ts +120 -0
  217. package/src/store.ts +419 -0
  218. package/src/target.ts +51 -0
  219. package/src/types.ts +202 -0
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from "./types.js";
2
+ export * from "./money.js";
3
+ export * from "./period.js";
4
+ export * from "./leads.js";
5
+ export * from "./pipeline.js";
6
+ export * from "./target.js";
7
+ export * from "./invoices.js";
8
+ export * from "./account.js";
9
+ export * from "./sales.js";
10
+ export * from "./errors.js";
11
+ export * from "./backend.js";
12
+ export * from "./crm-client.js";
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type MoneyTotals } from './money.ts';
2
+ import { type DateRange } from './period.ts';
3
+ import type { Invoice, InvoiceStatus, Money, Remittance } from './types.ts';
4
+ /** Statuses of an invoice that has been sent and is waiting to be paid. */
5
+ export declare const AWAITING_PAYMENT: readonly InvoiceStatus[];
6
+ export declare const INVOICE_STATUS_LABELS: Readonly<Record<InvoiceStatus, string>>;
7
+ /** What's still to pay on an invoice awaiting payment: its total less what's been paid. Undefined otherwise. */
8
+ export declare function outstanding(invoice: Invoice): Money | undefined;
9
+ /** Whether an invoice is past its due date with something still to pay. */
10
+ export declare function isOverdueInvoice(invoice: Invoice, now?: Date): boolean;
11
+ /** What's still to pay across invoices, per currency. */
12
+ export declare function outstandingTotals(invoices: readonly Invoice[]): MoneyTotals;
13
+ /** What's overdue across invoices, per currency. */
14
+ export declare function overdueTotals(invoices: readonly Invoice[], now?: Date): MoneyTotals;
15
+ export type AgeBucket = 'CURRENT' | 'DAYS_1_30' | 'DAYS_31_60' | 'DAYS_61_90' | 'DAYS_OVER_90';
16
+ export declare const AGE_BUCKETS: readonly AgeBucket[];
17
+ export declare const AGE_BUCKET_LABELS: Readonly<Record<AgeBucket, string>>;
18
+ /** How long an invoice has been overdue, as a bucket for an aged debt view. */
19
+ export declare function ageBucket(invoice: Invoice, now?: Date): AgeBucket;
20
+ /** What's still to pay, per age bucket and currency, every bucket in order. */
21
+ export declare function outstandingByAge(invoices: readonly Invoice[], now?: Date): {
22
+ bucket: AgeBucket;
23
+ totals: MoneyTotals;
24
+ }[];
25
+ /** Money received less refunds paid, per currency, optionally only within a date range. */
26
+ export declare function paymentsReceived(remittances: readonly Remittance[], range?: DateRange): MoneyTotals;
27
+ /** Payments received per UTC day in a range, every day included, for a chart. */
28
+ export declare function paymentsByDay(remittances: readonly Remittance[], range: DateRange): {
29
+ day: string;
30
+ totals: MoneyTotals;
31
+ }[];
32
+ /** An invoice's payment fields as they follow from its remittances. */
33
+ export interface InvoicePayments {
34
+ paid: Money;
35
+ refunded: Money;
36
+ status: InvoiceStatus;
37
+ fullyPaidTimestamp: string | null;
38
+ }
39
+ /**
40
+ * An invoice's `paid`, `refunded`, `status` and `fullyPaidTimestamp` worked out from its remittances, which the API
41
+ * lists on the invoice but doesn't total. An invoice's own amounts (`total`, `tax`) are as it was given: the API
42
+ * doesn't add them up from its lines, so an invoice can total something other than its lines' sum. Only received remittances count. An invoice is paid once payments reach its total (fully paid when the
43
+ * payment that got there arrived), and refunded once refunds match the payments; otherwise its status is kept.
44
+ */
45
+ export declare function invoiceFromRemittances(invoice: Invoice, remittances: readonly Remittance[]): InvoicePayments;
46
+ //# sourceMappingURL=invoices.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoices.d.ts","sourceRoot":"","sources":["../src/invoices.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,aAAa,CAA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,UAAU,EAAE,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,WAAW,CAOnG;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAC3B,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,KAAK,EAAE,SAAS,GACf;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,EAAE,CAWxC;AAED,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,KAAK,CAAC;IACZ,QAAQ,EAAE,KAAK,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,eAAe,CAyB5G"}
@@ -0,0 +1,137 @@
1
+ import { parseTimestamp, toTimestamp } from '@baack-software/baack-ts-tasks';
2
+ import { addMoney, fromMinor, minorOf } from "./money.js";
3
+ import { inRange } from "./period.js";
4
+ /** Statuses of an invoice that has been sent and is waiting to be paid. */
5
+ export const AWAITING_PAYMENT = ['AUTHORISED', 'PENDING'];
6
+ export const INVOICE_STATUS_LABELS = {
7
+ DRAFT: 'Draft',
8
+ IN_REVIEW: 'In review',
9
+ AUTHORISED: 'Awaiting payment',
10
+ PENDING: 'Awaiting payment',
11
+ VOIDED: 'Void',
12
+ PAID: 'Paid',
13
+ REFUNDED: 'Refunded',
14
+ };
15
+ /** What's still to pay on an invoice awaiting payment: its total less what's been paid. Undefined otherwise. */
16
+ export function outstanding(invoice) {
17
+ if (!AWAITING_PAYMENT.includes(invoice.status))
18
+ return undefined;
19
+ const { currencyCode } = invoice;
20
+ const due = minorOf(invoice.total) - minorOf(invoice.paid);
21
+ return due > 0 ? fromMinor(due, currencyCode) : undefined;
22
+ }
23
+ /** Whether an invoice is past its due date with something still to pay. */
24
+ export function isOverdueInvoice(invoice, now = new Date()) {
25
+ const due = parseTimestamp(invoice.dueTimestamp);
26
+ return due !== undefined && due < now && outstanding(invoice) !== undefined;
27
+ }
28
+ /** What's still to pay across invoices, per currency. */
29
+ export function outstandingTotals(invoices) {
30
+ return invoices.reduce((totals, invoice) => addMoney(totals, outstanding(invoice)), {});
31
+ }
32
+ /** What's overdue across invoices, per currency. */
33
+ export function overdueTotals(invoices, now = new Date()) {
34
+ return invoices
35
+ .filter((invoice) => isOverdueInvoice(invoice, now))
36
+ .reduce((totals, invoice) => addMoney(totals, outstanding(invoice)), {});
37
+ }
38
+ export const AGE_BUCKETS = ['CURRENT', 'DAYS_1_30', 'DAYS_31_60', 'DAYS_61_90', 'DAYS_OVER_90'];
39
+ export const AGE_BUCKET_LABELS = {
40
+ CURRENT: 'Not yet due',
41
+ DAYS_1_30: '1 to 30 days overdue',
42
+ DAYS_31_60: '31 to 60 days overdue',
43
+ DAYS_61_90: '61 to 90 days overdue',
44
+ DAYS_OVER_90: 'Over 90 days overdue',
45
+ };
46
+ /** How long an invoice has been overdue, as a bucket for an aged debt view. */
47
+ export function ageBucket(invoice, now = new Date()) {
48
+ const due = parseTimestamp(invoice.dueTimestamp);
49
+ const days = due ? Math.floor((now.getTime() - due.getTime()) / 86_400_000) : 0;
50
+ if (days <= 0)
51
+ return 'CURRENT';
52
+ if (days <= 30)
53
+ return 'DAYS_1_30';
54
+ if (days <= 60)
55
+ return 'DAYS_31_60';
56
+ if (days <= 90)
57
+ return 'DAYS_61_90';
58
+ return 'DAYS_OVER_90';
59
+ }
60
+ /** What's still to pay, per age bucket and currency, every bucket in order. */
61
+ export function outstandingByAge(invoices, now = new Date()) {
62
+ const byBucket = new Map();
63
+ for (const invoice of invoices) {
64
+ const due = outstanding(invoice);
65
+ if (!due)
66
+ continue;
67
+ const bucket = ageBucket(invoice, now);
68
+ byBucket.set(bucket, addMoney(byBucket.get(bucket) ?? {}, due));
69
+ }
70
+ return AGE_BUCKETS.map((bucket) => ({ bucket, totals: byBucket.get(bucket) ?? {} }));
71
+ }
72
+ const counts = (remittance) => remittance.remittanceStatus === 'RECEIVED';
73
+ /** Money received less refunds paid, per currency, optionally only within a date range. */
74
+ export function paymentsReceived(remittances, range) {
75
+ let totals = {};
76
+ for (const remittance of remittances) {
77
+ if (!counts(remittance) || (range && !inRange(remittance.receivedTimestamp, range)))
78
+ continue;
79
+ totals = addMoney(totals, remittance.value, remittance.remittanceDirection === 'REFUND' ? -1 : 1);
80
+ }
81
+ return totals;
82
+ }
83
+ /** Payments received per UTC day in a range, every day included, for a chart. */
84
+ export function paymentsByDay(remittances, range) {
85
+ const days = [];
86
+ const start = new Date(Date.UTC(range.start.getUTCFullYear(), range.start.getUTCMonth(), range.start.getUTCDate()));
87
+ for (let day = start; day < range.end; day = new Date(day.getTime() + 86_400_000)) {
88
+ const next = new Date(day.getTime() + 86_400_000);
89
+ days.push({
90
+ day: day.toISOString().slice(0, 10),
91
+ totals: paymentsReceived(remittances, { start: day, end: next }),
92
+ });
93
+ }
94
+ return days;
95
+ }
96
+ /**
97
+ * An invoice's `paid`, `refunded`, `status` and `fullyPaidTimestamp` worked out from its remittances, which the API
98
+ * lists on the invoice but doesn't total. An invoice's own amounts (`total`, `tax`) are as it was given: the API
99
+ * doesn't add them up from its lines, so an invoice can total something other than its lines' sum. Only received remittances count. An invoice is paid once payments reach its total (fully paid when the
100
+ * payment that got there arrived), and refunded once refunds match the payments; otherwise its status is kept.
101
+ */
102
+ export function invoiceFromRemittances(invoice, remittances) {
103
+ const total = minorOf(invoice.total);
104
+ const mine = remittances
105
+ .filter((remittance) => remittance.paymentInvoice.urn === invoice.urn && counts(remittance))
106
+ .toSorted((a, b) => a.receivedTimestamp.localeCompare(b.receivedTimestamp));
107
+ let paid = 0;
108
+ let refunded = 0;
109
+ let fullyPaid = null;
110
+ for (const remittance of mine) {
111
+ const minor = remittance.value.unitValue;
112
+ if (remittance.remittanceDirection === 'REFUND')
113
+ refunded += minor;
114
+ else {
115
+ paid += minor;
116
+ if (fullyPaid === null && paid >= total)
117
+ fullyPaid = normalise(remittance.receivedTimestamp);
118
+ }
119
+ }
120
+ let status = invoice.status;
121
+ if (paid > 0 && refunded >= paid)
122
+ status = 'REFUNDED';
123
+ else if (fullyPaid)
124
+ status = 'PAID';
125
+ return {
126
+ paid: fromMinor(paid, invoice.currencyCode),
127
+ refunded: fromMinor(refunded, invoice.currencyCode),
128
+ status,
129
+ fullyPaidTimestamp: fullyPaid,
130
+ };
131
+ }
132
+ /** A Baack timestamp written the one way, with milliseconds. */
133
+ function normalise(timestamp) {
134
+ const date = parseTimestamp(timestamp);
135
+ return date ? toTimestamp(date) : timestamp;
136
+ }
137
+ //# sourceMappingURL=invoices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoices.js","sourceRoot":"","sources":["../src/invoices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAoB,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAkB,MAAM,aAAa,CAAC;AAGtD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,gBAAgB,GAA6B,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;AAEpF,MAAM,CAAC,MAAM,qBAAqB,GAA4C;IAC5E,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,kBAAkB;IAC9B,OAAO,EAAE,kBAAkB;IAC3B,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;CACrB,CAAC;AAEF,gHAAgH;AAChH,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IACjE,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM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K;gBAAE,SAAS,GAAG,SAAS,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;IACD,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC5B,IAAI,IAAI,GAAG,CAAC,IAAI,QAAQ,IAAI,IAAI;QAAE,MAAM,GAAG,UAAU,CAAC;SACjD,IAAI,SAAS;QAAE,MAAM,GAAG,MAAM,CAAC;IACpC,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC;QAC3C,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC;QACnD,MAAM;QACN,kBAAkB,EAAE,SAAS;KAC9B,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,SAAS,SAAS,CAAC,SAAiB;IAClC,MAAM,IAAI,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Lead, LeadOutcome, LeadSource, LeadStatus } from './types.ts';
2
+ export declare const LEAD_SOURCES: readonly LeadSource[];
3
+ export declare const SOURCE_LABELS: Readonly<Record<LeadSource, string>>;
4
+ /** Lead statuses in the order a lead moves through them. */
5
+ export declare const LEAD_STATUSES: readonly LeadStatus[];
6
+ export declare const LEAD_STATUS_LABELS: Readonly<Record<LeadStatus, string>>;
7
+ export declare const LEAD_OUTCOME_LABELS: Readonly<Record<LeadOutcome, string>>;
8
+ /** How a lead ended: its own outcome, in progress when it has none. */
9
+ export declare const leadOutcome: (lead: Lead) => LeadOutcome;
10
+ /** Whether a lead still needs work: not yet converted into a deal or closed as unqualified. */
11
+ export declare const isOpenLead: (lead: Lead) => boolean;
12
+ /** Where a lead stands, in one word for tables and filters: its outcome once closed, otherwise its status. */
13
+ export type LeadState = LeadStatus | Exclude<LeadOutcome, 'IN_PROGRESS'>;
14
+ export declare const LEAD_STATES: readonly LeadState[];
15
+ export declare const LEAD_STATE_LABELS: Readonly<Record<LeadState, string>>;
16
+ export declare function leadState(lead: Lead): LeadState;
17
+ /** The deal a lead was converted into: the deal whose `leadSource` is the lead. */
18
+ export declare const dealFromLead: <D extends {
19
+ leadSource?: {
20
+ urn: string;
21
+ } | null;
22
+ }>(lead: Pick<Lead, "urn">, deals: readonly D[]) => D | undefined;
23
+ export interface SourceCount {
24
+ source: LeadSource;
25
+ count: number;
26
+ }
27
+ /** How many leads came from each source, every source in order, including those with none. */
28
+ export declare function leadsBySource(leads: readonly Lead[]): SourceCount[];
29
+ //# sourceMappingURL=leads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leads.d.ts","sourceRoot":"","sources":["../src/leads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE5E,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAS7C,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAS9D,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,aAAa,EAAE,SAAS,UAAU,EAAsC,CAAC;AAEtF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAInE,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAIrE,CAAC;AAEF,uEAAuE;AACvE,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,WAA4C,CAAC;AAEtF,+FAA+F;AAC/F,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,OAA8C,CAAC;AAEvF,8GAA8G;AAC9G,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAEzE,eAAO,MAAM,WAAW,EAAE,SAAS,SAAS,EAA8C,CAAC;AAE3F,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAIjE,CAAC;AAEF,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAG/C;AAED,mFAAmF;AACnF,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS;IAAE,UAAU,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;CAAE,EAC5E,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,EACvB,OAAO,SAAS,CAAC,EAAE,KAClB,CAAC,GAAG,SAAoE,CAAC;AAE5E,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,8FAA8F;AAC9F,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,WAAW,EAAE,CAInE"}
package/dist/leads.js ADDED
@@ -0,0 +1,56 @@
1
+ export const LEAD_SOURCES = [
2
+ 'WEBSITE',
3
+ 'REFERRAL',
4
+ 'SOCIAL',
5
+ 'EMAIL',
6
+ 'CALL',
7
+ 'ADS',
8
+ 'EVENT',
9
+ 'UNKNOWN',
10
+ ];
11
+ export const SOURCE_LABELS = {
12
+ WEBSITE: 'Website',
13
+ REFERRAL: 'Referral',
14
+ SOCIAL: 'Social',
15
+ EMAIL: 'Email',
16
+ CALL: 'Call',
17
+ ADS: 'Ads',
18
+ EVENT: 'Event',
19
+ UNKNOWN: 'Other',
20
+ };
21
+ /** Lead statuses in the order a lead moves through them. */
22
+ export const LEAD_STATUSES = ['NEW', 'CONTACTED', 'QUALIFIED'];
23
+ export const LEAD_STATUS_LABELS = {
24
+ NEW: 'New',
25
+ CONTACTED: 'Contacted',
26
+ QUALIFIED: 'Qualified',
27
+ };
28
+ export const LEAD_OUTCOME_LABELS = {
29
+ IN_PROGRESS: 'In progress',
30
+ CONVERTED: 'Converted',
31
+ CLOSED: 'Closed',
32
+ };
33
+ /** How a lead ended: its own outcome, in progress when it has none. */
34
+ export const leadOutcome = (lead) => lead.outcome ?? 'IN_PROGRESS';
35
+ /** Whether a lead still needs work: not yet converted into a deal or closed as unqualified. */
36
+ export const isOpenLead = (lead) => leadOutcome(lead) === 'IN_PROGRESS';
37
+ export const LEAD_STATES = [...LEAD_STATUSES, 'CONVERTED', 'CLOSED'];
38
+ export const LEAD_STATE_LABELS = {
39
+ ...LEAD_STATUS_LABELS,
40
+ CONVERTED: LEAD_OUTCOME_LABELS.CONVERTED,
41
+ CLOSED: LEAD_OUTCOME_LABELS.CLOSED,
42
+ };
43
+ export function leadState(lead) {
44
+ const outcome = leadOutcome(lead);
45
+ return outcome === 'IN_PROGRESS' ? lead.status : outcome;
46
+ }
47
+ /** The deal a lead was converted into: the deal whose `leadSource` is the lead. */
48
+ export const dealFromLead = (lead, deals) => deals.find((deal) => deal.leadSource?.urn === lead.urn);
49
+ /** How many leads came from each source, every source in order, including those with none. */
50
+ export function leadsBySource(leads) {
51
+ const counts = new Map();
52
+ for (const lead of leads)
53
+ counts.set(lead.source, (counts.get(lead.source) ?? 0) + 1);
54
+ return LEAD_SOURCES.map((source) => ({ source, count: counts.get(source) ?? 0 }));
55
+ }
56
+ //# sourceMappingURL=leads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leads.js","sourceRoot":"","sources":["../src/leads.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAA0B;IACjD,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,MAAM;IACN,KAAK;IACL,OAAO;IACP,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAyC;IACjE,OAAO,EAAE,SAAS;IAClB,QAAQ,EA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MAAM,YAAY,GAAG,CAC1B,IAAuB,EACvB,KAAmB,EACJ,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC;AAO5E,8FAA8F;AAC9F,MAAM,UAAU,aAAa,CAAC,KAAsB;IAClD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7C,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACtF,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACpF,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { type RefLike } from '@baack-software/baack-ts-tasks';
2
+ import type { CrmData } from '../backend.ts';
3
+ /** A company the sample can attach records to, with its name for display. */
4
+ export interface SampleCompany {
5
+ urn: string;
6
+ name: string;
7
+ }
8
+ /** A person the sample can use as a contact, with the company they belong to. */
9
+ export interface SamplePerson {
10
+ urn: string;
11
+ company?: string | null;
12
+ }
13
+ export interface SampleOptions {
14
+ /** The company whose CRM this is. */
15
+ owner: RefLike;
16
+ /**
17
+ * Real customer companies to attach the sample's deals, leads and invoices to, in turn. Without them the sample uses
18
+ * its own companies (`SAMPLE_COMPANIES`), which aren't in Baack.
19
+ */
20
+ companies?: readonly SampleCompany[];
21
+ /** Real people to use as contacts: each company's first person. */
22
+ people?: readonly SamplePerson[];
23
+ /** Team members to assign leads and deals to, in turn. */
24
+ team?: readonly RefLike[];
25
+ now?: Date;
26
+ currencyCode?: string;
27
+ }
28
+ export interface SampleCrm extends CrmData {
29
+ /** The companies the records point at, with names. */
30
+ companies: SampleCompany[];
31
+ }
32
+ /** A fixed URN for sample record `n` of a kind, recognisable by its `5a3e` start. */
33
+ export declare function sampleUrn(kind: number, n: number): string;
34
+ /** Whether a URN belongs to sample data. */
35
+ export declare const isSampleUrn: (urn: string) => boolean;
36
+ /** The sample's own customer companies, used when no real ones are given. */
37
+ export declare const SAMPLE_COMPANIES: readonly SampleCompany[];
38
+ /**
39
+ * A sample CRM for `owner`: a pipeline, leads, deals, invoices and payments. Pass real `companies`, `people` and
40
+ * `team` to attach the records to them, so a console page can mix real people and tasks with sample deals.
41
+ */
42
+ export declare function sampleCrm(options: SampleOptions): SampleCrm;
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,KAAK,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAGjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAoB7C,6EAA6E;AAC7E,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,KAAK,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACrC,mEAAmE;IACnE,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IACjC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC1B,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,YAAY,CAAC,EAAE,MAA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