@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.
- package/LICENSE +201 -0
- package/README.md +74 -2
- package/dist/account.d.ts +36 -0
- package/dist/account.d.ts.map +1 -0
- package/dist/account.js +48 -0
- package/dist/account.js.map +1 -0
- package/dist/backend.d.ts +76 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +233 -0
- package/dist/backend.js.map +1 -0
- package/dist/crm-client.d.ts +122 -0
- package/dist/crm-client.d.ts.map +1 -0
- package/dist/crm-client.js +168 -0
- package/dist/crm-client.js.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +46 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +137 -0
- package/dist/invoices.js.map +1 -0
- package/dist/leads.d.ts +29 -0
- package/dist/leads.d.ts.map +1 -0
- package/dist/leads.js +56 -0
- package/dist/leads.js.map +1 -0
- package/dist/mock/index.d.ts +43 -0
- package/dist/mock/index.d.ts.map +1 -0
- package/dist/mock/index.js +303 -0
- package/dist/mock/index.js.map +1 -0
- package/dist/money.d.ts +29 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +82 -0
- package/dist/money.js.map +1 -0
- package/dist/period.d.ts +17 -0
- package/dist/period.d.ts.map +1 -0
- package/dist/period.js +23 -0
- package/dist/period.js.map +1 -0
- package/dist/pipeline.d.ts +30 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +40 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/react/Charts.d.ts +19 -0
- package/dist/react/Charts.d.ts.map +1 -0
- package/dist/react/Charts.js +38 -0
- package/dist/react/Charts.js.map +1 -0
- package/dist/react/CompanyAccountView.d.ts +21 -0
- package/dist/react/CompanyAccountView.d.ts.map +1 -0
- package/dist/react/CompanyAccountView.js +27 -0
- package/dist/react/CompanyAccountView.js.map +1 -0
- package/dist/react/DashboardCards.d.ts +32 -0
- package/dist/react/DashboardCards.d.ts.map +1 -0
- package/dist/react/DashboardCards.js +38 -0
- package/dist/react/DashboardCards.js.map +1 -0
- package/dist/react/DealsBoard.d.ts +30 -0
- package/dist/react/DealsBoard.d.ts.map +1 -0
- package/dist/react/DealsBoard.js +33 -0
- package/dist/react/DealsBoard.js.map +1 -0
- package/dist/react/Details.d.ts +52 -0
- package/dist/react/Details.d.ts.map +1 -0
- package/dist/react/Details.js +111 -0
- package/dist/react/Details.js.map +1 -0
- package/dist/react/Forms.d.ts +59 -0
- package/dist/react/Forms.d.ts.map +1 -0
- package/dist/react/Forms.js +204 -0
- package/dist/react/Forms.js.map +1 -0
- package/dist/react/LeadsTable.d.ts +22 -0
- package/dist/react/LeadsTable.d.ts.map +1 -0
- package/dist/react/LeadsTable.js +79 -0
- package/dist/react/LeadsTable.js.map +1 -0
- package/dist/react/Sales.d.ts +49 -0
- package/dist/react/Sales.d.ts.map +1 -0
- package/dist/react/Sales.js +186 -0
- package/dist/react/Sales.js.map +1 -0
- package/dist/react/SidePanel.d.ts +21 -0
- package/dist/react/SidePanel.d.ts.map +1 -0
- package/dist/react/SidePanel.js +37 -0
- package/dist/react/SidePanel.js.map +1 -0
- package/dist/react/format.d.ts +28 -0
- package/dist/react/format.d.ts.map +1 -0
- package/dist/react/format.js +30 -0
- package/dist/react/format.js.map +1 -0
- package/dist/react/index.d.ts +14 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/parts.d.ts +45 -0
- package/dist/react/parts.d.ts.map +1 -0
- package/dist/react/parts.js +59 -0
- package/dist/react/parts.js.map +1 -0
- package/dist/react/text.d.ts +145 -0
- package/dist/react/text.d.ts.map +1 -0
- package/dist/react/text.js +142 -0
- package/dist/react/text.js.map +1 -0
- package/dist/react/ui/alert.d.ts +11 -0
- package/dist/react/ui/alert.d.ts.map +1 -0
- package/dist/react/ui/alert.js +29 -0
- package/dist/react/ui/alert.js.map +1 -0
- package/dist/react/ui/badge.d.ts +10 -0
- package/dist/react/ui/badge.d.ts.map +1 -0
- package/dist/react/ui/badge.js +26 -0
- package/dist/react/ui/badge.js.map +1 -0
- package/dist/react/ui/button.d.ts +11 -0
- package/dist/react/ui/button.d.ts.map +1 -0
- package/dist/react/ui/button.js +37 -0
- package/dist/react/ui/button.js.map +1 -0
- package/dist/react/ui/card.d.ts +12 -0
- package/dist/react/ui/card.d.ts.map +1 -0
- package/dist/react/ui/card.js +26 -0
- package/dist/react/ui/card.js.map +1 -0
- package/dist/react/ui/chart.d.ts +45 -0
- package/dist/react/ui/chart.d.ts.map +1 -0
- package/dist/react/ui/chart.js +116 -0
- package/dist/react/ui/chart.js.map +1 -0
- package/dist/react/ui/input.d.ts +4 -0
- package/dist/react/ui/input.d.ts.map +1 -0
- package/dist/react/ui/input.js +8 -0
- package/dist/react/ui/input.js.map +1 -0
- package/dist/react/ui/label.d.ts +5 -0
- package/dist/react/ui/label.d.ts.map +1 -0
- package/dist/react/ui/label.js +10 -0
- package/dist/react/ui/label.js.map +1 -0
- package/dist/react/ui/progress.d.ts +5 -0
- package/dist/react/ui/progress.d.ts.map +1 -0
- package/dist/react/ui/progress.js +10 -0
- package/dist/react/ui/progress.js.map +1 -0
- package/dist/react/ui/select.d.ts +16 -0
- package/dist/react/ui/select.d.ts.map +1 -0
- package/dist/react/ui/select.js +37 -0
- package/dist/react/ui/select.js.map +1 -0
- package/dist/react/ui/separator.d.ts +5 -0
- package/dist/react/ui/separator.d.ts.map +1 -0
- package/dist/react/ui/separator.js +10 -0
- package/dist/react/ui/separator.js.map +1 -0
- package/dist/react/ui/sheet.d.ts +15 -0
- package/dist/react/ui/sheet.d.ts.map +1 -0
- package/dist/react/ui/sheet.js +38 -0
- package/dist/react/ui/sheet.js.map +1 -0
- package/dist/react/ui/skeleton.d.ts +3 -0
- package/dist/react/ui/skeleton.d.ts.map +1 -0
- package/dist/react/ui/skeleton.js +7 -0
- package/dist/react/ui/skeleton.js.map +1 -0
- package/dist/react/ui/table.d.ts +11 -0
- package/dist/react/ui/table.d.ts.map +1 -0
- package/dist/react/ui/table.js +29 -0
- package/dist/react/ui/table.js.map +1 -0
- package/dist/react/ui/tabs.d.ts +12 -0
- package/dist/react/ui/tabs.d.ts.map +1 -0
- package/dist/react/ui/tabs.js +31 -0
- package/dist/react/ui/tabs.js.map +1 -0
- package/dist/react/views.d.ts +60 -0
- package/dist/react/views.d.ts.map +1 -0
- package/dist/react/views.js +172 -0
- package/dist/react/views.js.map +1 -0
- package/dist/sales.d.ts +57 -0
- package/dist/sales.d.ts.map +1 -0
- package/dist/sales.js +64 -0
- package/dist/sales.js.map +1 -0
- package/dist/store.d.ts +140 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +244 -0
- package/dist/store.js.map +1 -0
- package/dist/target.d.ts +21 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +36 -0
- package/dist/target.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +100 -4
- package/src/account.ts +79 -0
- package/src/backend.ts +371 -0
- package/src/crm-client.ts +250 -0
- package/src/errors.ts +34 -0
- package/src/index.ts +12 -0
- package/src/invoices.ts +157 -0
- package/src/leads.ts +78 -0
- package/src/mock/index.ts +398 -0
- package/src/money.ts +104 -0
- package/src/period.ts +32 -0
- package/src/pipeline.ts +61 -0
- package/src/react/Charts.tsx +143 -0
- package/src/react/CompanyAccountView.tsx +198 -0
- package/src/react/DashboardCards.tsx +171 -0
- package/src/react/DealsBoard.tsx +177 -0
- package/src/react/Details.tsx +293 -0
- package/src/react/Forms.tsx +619 -0
- package/src/react/LeadsTable.tsx +234 -0
- package/src/react/Sales.tsx +539 -0
- package/src/react/SidePanel.tsx +95 -0
- package/src/react/format.ts +53 -0
- package/src/react/index.ts +13 -0
- package/src/react/parts.tsx +131 -0
- package/src/react/text.ts +144 -0
- package/src/react/ui/README.md +6 -0
- package/src/react/ui/alert.tsx +75 -0
- package/src/react/ui/badge.tsx +48 -0
- package/src/react/ui/button.tsx +66 -0
- package/src/react/ui/card.tsx +102 -0
- package/src/react/ui/chart.tsx +304 -0
- package/src/react/ui/input.tsx +18 -0
- package/src/react/ui/label.tsx +23 -0
- package/src/react/ui/progress.tsx +30 -0
- package/src/react/ui/select.tsx +189 -0
- package/src/react/ui/separator.tsx +27 -0
- package/src/react/ui/sheet.tsx +145 -0
- package/src/react/ui/skeleton.tsx +13 -0
- package/src/react/ui/table.tsx +113 -0
- package/src/react/ui/tabs.tsx +89 -0
- package/src/react/views.tsx +443 -0
- package/src/sales.ts +120 -0
- package/src/store.ts +419 -0
- package/src/target.ts +51 -0
- package/src/types.ts +202 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { ref, toTimestamp, urnOf } from '@baack-software/baack-ts-tasks';
|
|
2
|
+
import { fractionDigits } from "../money.js";
|
|
3
|
+
/** A fixed URN for sample record `n` of a kind, recognisable by its `5a3e` start. */
|
|
4
|
+
export function sampleUrn(kind, n) {
|
|
5
|
+
return `5a3e0000-0000-4000-8000-${kind}${String(n).padStart(11, '0')}`;
|
|
6
|
+
}
|
|
7
|
+
/** Whether a URN belongs to sample data. */
|
|
8
|
+
export const isSampleUrn = (urn) => urn.startsWith('5a3e0000-');
|
|
9
|
+
/** The sample's own customer companies, used when no real ones are given. */
|
|
10
|
+
export const SAMPLE_COMPANIES = [
|
|
11
|
+
'Porthmeor Surf Co',
|
|
12
|
+
'Gyllyngvase Swim Club',
|
|
13
|
+
'Harbour View Hotel',
|
|
14
|
+
'Atlantic Outfitters',
|
|
15
|
+
'Penwith Wild Swimmers',
|
|
16
|
+
'Bretagne Nautique',
|
|
17
|
+
].map((name, n) => ({ urn: sampleUrn(6, n + 1), name }));
|
|
18
|
+
const PIPELINE_URN = sampleUrn(3, 0);
|
|
19
|
+
// A plain workflow: its stages are only progress. Whether a deal is won or lost, and how likely, is on the deal.
|
|
20
|
+
const STAGES = ['Lead', 'Qualified', 'Proposal', 'Negotiation', 'Closed'].map((name, order) => ({
|
|
21
|
+
urn: sampleUrn(3, order + 1),
|
|
22
|
+
name,
|
|
23
|
+
order,
|
|
24
|
+
}));
|
|
25
|
+
/** The sample pipeline's stage by name. */
|
|
26
|
+
const stage = (name) => STAGES.find((candidate) => candidate.name === name);
|
|
27
|
+
/** Where the sample's deals sit: the stage, how each stands, and the chance it's won while open. */
|
|
28
|
+
const PLACES = {
|
|
29
|
+
Lead: { stage: 'Lead', outcome: 'OPEN', probability: 10 },
|
|
30
|
+
Qualified: { stage: 'Qualified', outcome: 'OPEN', probability: 25 },
|
|
31
|
+
Proposal: { stage: 'Proposal', outcome: 'OPEN', probability: 50 },
|
|
32
|
+
Negotiation: { stage: 'Negotiation', outcome: 'OPEN', probability: 75 },
|
|
33
|
+
'Closed won': { stage: 'Closed', outcome: 'WON', probability: null },
|
|
34
|
+
'Closed lost': { stage: 'Closed', outcome: 'LOST', probability: null },
|
|
35
|
+
};
|
|
36
|
+
// Company is an index into the companies, or the name of a prospect's company: a sample company, made for the lead.
|
|
37
|
+
const LEADS = [
|
|
38
|
+
['Robes for the spring club season', 1, 'REFERRAL', 'CONVERTED', 2400, 40],
|
|
39
|
+
['Hotel spa robes and towels', 2, 'WEBSITE', 'CONVERTED', 5200, 35],
|
|
40
|
+
['Changing ponchos for summer stock', 0, 'EVENT', 'CONVERTED', 3800, 60],
|
|
41
|
+
['Club swim caps with logo', 4, 'SOCIAL', 'QUALIFIED', 900, 9],
|
|
42
|
+
['Wholesale account for a new shop', 'Sennen Cove Supplies', 'EMAIL', 'NEW', 1500, 2],
|
|
43
|
+
['Event kit for a charity swim', 'Swim the Fal', 'SOCIAL', 'CONTACTED', 1200, 6],
|
|
44
|
+
['Rental fleet of changing robes', 'Kynance Kayaks', 'CALL', 'CONTACTED', 2700, 12],
|
|
45
|
+
['Staff uniforms for a beach cafe', 'Little Shore Cafe', 'WEBSITE', 'NEW', 650, 1],
|
|
46
|
+
['French stockist for the winter range', 5, 'ADS', 'CONVERTED', 6400, 50],
|
|
47
|
+
['Gift shop range for a museum', 'Maritime Museum Shop', 'REFERRAL', 'CLOSED', 800, 25],
|
|
48
|
+
['Swim school starter packs', 'Tidal Pool Swim School', 'ADS', 'NEW', 1100, 3],
|
|
49
|
+
['Corporate gifts for a retreat', 'Saltings Retreats', 'EMAIL', 'CONTACTED', 1900, 15],
|
|
50
|
+
['Repeat order of winter beanies', 3, 'UNKNOWN', 'CONVERTED', 1300, 70],
|
|
51
|
+
];
|
|
52
|
+
const DEALS = [
|
|
53
|
+
['Spring club robes', 1, 'Proposal', 2600, 30, 14, 0],
|
|
54
|
+
['Spa robes and towels', 2, 'Negotiation', 5200, 28, 7, 1],
|
|
55
|
+
['Summer ponchos', 0, 'Closed won', 3650, 55, -20, 2],
|
|
56
|
+
['Winter range stockist', 5, 'Qualified', 6400, 45, 30, 8],
|
|
57
|
+
['Winter beanies repeat', 3, 'Closed won', 1300, 65, -40, 12],
|
|
58
|
+
['Autumn hoodies', 0, 'Closed lost', 2100, 80, -45, undefined, 'Went with a cheaper supplier'],
|
|
59
|
+
['Club towels', 4, 'Lead', 750, 4, 45],
|
|
60
|
+
['Branded tote bags', 3, 'Proposal', 980, 18, 21],
|
|
61
|
+
['Shop fit-out display stock', 0, 'Closed won', 4200, 90, -60],
|
|
62
|
+
['Lifeguard jackets', 2, 'Negotiation', 3100, 20, 10],
|
|
63
|
+
];
|
|
64
|
+
const INVOICES = [
|
|
65
|
+
[2, 'PAID', 18, 12, 1],
|
|
66
|
+
[4, 'PAID', 38, -8, 1],
|
|
67
|
+
[8, 'AUTHORISED', 50, -20, 0.5],
|
|
68
|
+
[8, 'AUTHORISED', 20, 10, 0],
|
|
69
|
+
[2, 'AUTHORISED', 45, -15, 0],
|
|
70
|
+
[1, 'DRAFT', 0, 30, 0],
|
|
71
|
+
[4, 'REFUNDED', 60, -30, 1],
|
|
72
|
+
];
|
|
73
|
+
// Smaller orders between deals: what each customer buys again, when it was issued, and how many days later it was paid.
|
|
74
|
+
const REPEAT_ORDERS = [
|
|
75
|
+
['Restock: changing robes', 0, 640, 54, 6],
|
|
76
|
+
['Restock: swim caps', 1, 180, 49, 3],
|
|
77
|
+
['Restock: beanies', 3, 420, 45, 9],
|
|
78
|
+
['Spa towels top-up', 2, 760, 41, 12],
|
|
79
|
+
['Restock: changing robes', 0, 880, 36, 5],
|
|
80
|
+
['Club hoodies', 4, 540, 33, 4],
|
|
81
|
+
['Restock: dry bags', 3, 310, 28, 7],
|
|
82
|
+
['Restock: swim caps', 1, 220, 24, 2],
|
|
83
|
+
['Winter range samples', 5, 950, 20, 10],
|
|
84
|
+
['Restock: changing robes', 0, 720, 16, 4],
|
|
85
|
+
['Spa towels top-up', 2, 690, 12, 6],
|
|
86
|
+
['Restock: beanies', 3, 460, 9, 3],
|
|
87
|
+
['Club hoodies', 4, 610, 6, 2],
|
|
88
|
+
['Restock: dry bags', 3, 290, 4],
|
|
89
|
+
['Restock: swim caps', 1, 240, 2],
|
|
90
|
+
];
|
|
91
|
+
const METHODS = ['BANK_TRANSFER', 'CARD_PAYMENT', 'DIRECT_DEBIT', 'BANK_TRANSFER', 'E_WALLET'];
|
|
92
|
+
/**
|
|
93
|
+
* A sample CRM for `owner`: a pipeline, leads, deals, invoices and payments. Pass real `companies`, `people` and
|
|
94
|
+
* `team` to attach the records to them, so a console page can mix real people and tasks with sample deals.
|
|
95
|
+
*/
|
|
96
|
+
export function sampleCrm(options) {
|
|
97
|
+
const { now = new Date(), currencyCode = 'GBP' } = options;
|
|
98
|
+
const owner = ref(options.owner);
|
|
99
|
+
const companies = options.companies?.length ? [...options.companies] : [...SAMPLE_COMPANIES];
|
|
100
|
+
const team = (options.team ?? []).map(urnOf);
|
|
101
|
+
const ago = (days) => toTimestamp(new Date(now.getTime() - days * 86_400_000));
|
|
102
|
+
// The tables below are in major units (pounds); records hold minor units, as the API does.
|
|
103
|
+
const scale = 10 ** fractionDigits(currencyCode);
|
|
104
|
+
const u = (amount) => Math.round(amount * scale);
|
|
105
|
+
const money = (amount) => ({ unitValue: u(amount), currencyCode });
|
|
106
|
+
const companyAt = (index) => companies[index % companies.length];
|
|
107
|
+
const contactAt = (company) => options.people?.find((person) => person.company === company);
|
|
108
|
+
const assignee = (n) => (team.length ? { urn: team[n % team.length] } : null);
|
|
109
|
+
const pipeline = {
|
|
110
|
+
urn: PIPELINE_URN,
|
|
111
|
+
url: `/n/v1/workflow/${PIPELINE_URN}`,
|
|
112
|
+
name: 'Sales pipeline',
|
|
113
|
+
owner: owner,
|
|
114
|
+
stages: STAGES,
|
|
115
|
+
};
|
|
116
|
+
const deals = DEALS.map(([title, company, stageName, value, age, closeIn, lead, lostReason], n) => {
|
|
117
|
+
const urn = sampleUrn(2, n + 1);
|
|
118
|
+
const at = companyAt(company);
|
|
119
|
+
const contact = contactAt(at.urn);
|
|
120
|
+
const place = PLACES[stageName];
|
|
121
|
+
const closed = place.outcome !== 'OPEN';
|
|
122
|
+
return {
|
|
123
|
+
urn,
|
|
124
|
+
url: `/n/v1/deal/${urn}`,
|
|
125
|
+
owner,
|
|
126
|
+
title,
|
|
127
|
+
contactCompanies: [{ urn: at.urn }],
|
|
128
|
+
contactIdentities: contact ? [{ urn: contact.urn }] : [],
|
|
129
|
+
workflowStage: { urn: stage(place.stage).urn },
|
|
130
|
+
outcome: place.outcome,
|
|
131
|
+
probability: place.probability,
|
|
132
|
+
targetValue: money(value),
|
|
133
|
+
targetCloseTimestamp: ago(-closeIn),
|
|
134
|
+
closeTimestamp: closed ? ago(-closeIn) : null,
|
|
135
|
+
lostReason: lostReason ?? null,
|
|
136
|
+
assignee: assignee(n),
|
|
137
|
+
leadSource: lead === undefined ? null : { urn: sampleUrn(1, lead + 1) },
|
|
138
|
+
invoices: [],
|
|
139
|
+
createdTimestamp: ago(age),
|
|
140
|
+
updatedTimestamp: ago(Math.max(0, Math.min(age, closed ? -closeIn : 1))),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
// Prospects' companies, made for the leads naming them: in the sample's companies, so their names show.
|
|
144
|
+
const prospects = [];
|
|
145
|
+
const leads = LEADS.map(([title, company, source, state, value, age], n) => {
|
|
146
|
+
const urn = sampleUrn(1, n + 1);
|
|
147
|
+
let at = typeof company === 'number' ? companyAt(company) : undefined;
|
|
148
|
+
if (typeof company === 'string') {
|
|
149
|
+
at = { urn: sampleUrn(8, prospects.length + 1), name: company };
|
|
150
|
+
prospects.push(at);
|
|
151
|
+
}
|
|
152
|
+
const contact = at ? contactAt(at.urn) : undefined;
|
|
153
|
+
return {
|
|
154
|
+
urn,
|
|
155
|
+
url: `/n/v1/lead/${urn}`,
|
|
156
|
+
owner,
|
|
157
|
+
title,
|
|
158
|
+
contactIdentity: contact ? { urn: contact.urn } : null,
|
|
159
|
+
contactCompany: at ? { urn: at.urn } : null,
|
|
160
|
+
source,
|
|
161
|
+
status: state === 'CONVERTED' ? 'QUALIFIED' : state === 'CLOSED' ? 'CONTACTED' : state,
|
|
162
|
+
outcome: state === 'CONVERTED' || state === 'CLOSED' ? state : 'IN_PROGRESS',
|
|
163
|
+
closedReason: state === 'CLOSED' ? 'Wants own-brand stock we do not make' : null,
|
|
164
|
+
targetValue: money(value),
|
|
165
|
+
assignee: assignee(n + 1),
|
|
166
|
+
createdTimestamp: ago(age),
|
|
167
|
+
updatedTimestamp: ago(Math.max(0, age - 2)),
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
const invoices = [];
|
|
171
|
+
const remittances = [];
|
|
172
|
+
INVOICES.forEach(([dealIndex, status, issuedAgo, dueIn, paidShare], n) => {
|
|
173
|
+
const deal = deals[dealIndex];
|
|
174
|
+
const urn = sampleUrn(4, n + 1);
|
|
175
|
+
const total = (deal.targetValue.unitValue / scale) * (n === 2 || n === 3 ? 0.5 : 1);
|
|
176
|
+
const subTotal = total / 1.2;
|
|
177
|
+
const paid = total * paidShare;
|
|
178
|
+
const party = { company: deal.contactCompanies[0] ?? null, identity: deal.contactIdentities[0] ?? null };
|
|
179
|
+
deal.invoices.push({ urn });
|
|
180
|
+
invoices.push({
|
|
181
|
+
urn,
|
|
182
|
+
url: `/n/v1/paymentinvoice/${urn}`,
|
|
183
|
+
owner,
|
|
184
|
+
recipient: party,
|
|
185
|
+
remitter: party,
|
|
186
|
+
status,
|
|
187
|
+
currencyCode,
|
|
188
|
+
subTotal: money(subTotal),
|
|
189
|
+
tax: money(total - subTotal),
|
|
190
|
+
total: money(total),
|
|
191
|
+
paid: money(paid),
|
|
192
|
+
refunded: money(status === 'REFUNDED' ? paid : 0),
|
|
193
|
+
issuedTimestamp: status === 'DRAFT' ? null : ago(issuedAgo),
|
|
194
|
+
dueTimestamp: ago(-dueIn),
|
|
195
|
+
fullyPaidTimestamp: paidShare === 1 ? ago(Math.max(0, issuedAgo - 10)) : null,
|
|
196
|
+
lines: [
|
|
197
|
+
{
|
|
198
|
+
urn: sampleUrn(7, n + 1),
|
|
199
|
+
lineNumber: 1,
|
|
200
|
+
description: deal.title,
|
|
201
|
+
quantity: 1,
|
|
202
|
+
unitPrice: Number(subTotal.toFixed(2)),
|
|
203
|
+
price: money(subTotal),
|
|
204
|
+
tax: money(total - subTotal),
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
updatedTimestamp: ago(Math.max(0, issuedAgo - 10)),
|
|
208
|
+
});
|
|
209
|
+
if (paid > 0) {
|
|
210
|
+
remittances.push({
|
|
211
|
+
urn: sampleUrn(5, remittances.length + 1),
|
|
212
|
+
paymentInvoice: { urn },
|
|
213
|
+
remittanceDirection: 'PAYMENT',
|
|
214
|
+
remittanceStatus: 'RECEIVED',
|
|
215
|
+
value: money(paid),
|
|
216
|
+
remittanceMethod: METHODS[n % METHODS.length],
|
|
217
|
+
reference: `TW-${1040 + n}`,
|
|
218
|
+
remittingCompany: party.company,
|
|
219
|
+
remittingIdentity: party.identity,
|
|
220
|
+
receivedTimestamp: ago(Math.max(0, issuedAgo - 10)),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (status === 'REFUNDED') {
|
|
224
|
+
remittances.push({
|
|
225
|
+
urn: sampleUrn(5, remittances.length + 1),
|
|
226
|
+
paymentInvoice: { urn },
|
|
227
|
+
remittanceDirection: 'REFUND',
|
|
228
|
+
remittanceStatus: 'RECEIVED',
|
|
229
|
+
value: money(paid),
|
|
230
|
+
remittanceMethod: 'BANK_TRANSFER',
|
|
231
|
+
reference: `TW-R${1040 + n}`,
|
|
232
|
+
remittingCompany: party.company,
|
|
233
|
+
remittingIdentity: party.identity,
|
|
234
|
+
receivedTimestamp: ago(Math.max(0, issuedAgo - 20)),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
// Repeat orders from customers, paid soon after they're issued, so payments run through the last eight weeks.
|
|
239
|
+
REPEAT_ORDERS.forEach(([description, company, amount, issuedAgo, paidAfter], n) => {
|
|
240
|
+
const urn = sampleUrn(4, INVOICES.length + n + 1);
|
|
241
|
+
const at = companyAt(company);
|
|
242
|
+
const contact = contactAt(at.urn);
|
|
243
|
+
const party = { company: { urn: at.urn }, identity: contact ? { urn: contact.urn } : null };
|
|
244
|
+
const paid = paidAfter !== undefined && issuedAgo - paidAfter >= 0;
|
|
245
|
+
const subTotal = amount / 1.2;
|
|
246
|
+
invoices.push({
|
|
247
|
+
urn,
|
|
248
|
+
url: `/n/v1/paymentinvoice/${urn}`,
|
|
249
|
+
owner,
|
|
250
|
+
recipient: party,
|
|
251
|
+
remitter: party,
|
|
252
|
+
status: paid ? 'PAID' : 'AUTHORISED',
|
|
253
|
+
currencyCode,
|
|
254
|
+
subTotal: money(subTotal),
|
|
255
|
+
tax: money(amount - subTotal),
|
|
256
|
+
total: money(amount),
|
|
257
|
+
paid: money(paid ? amount : 0),
|
|
258
|
+
refunded: money(0),
|
|
259
|
+
issuedTimestamp: ago(issuedAgo),
|
|
260
|
+
dueTimestamp: ago(issuedAgo - 30),
|
|
261
|
+
fullyPaidTimestamp: paid ? ago(issuedAgo - paidAfter) : null,
|
|
262
|
+
lines: [
|
|
263
|
+
{
|
|
264
|
+
urn: sampleUrn(7, INVOICES.length + n + 1),
|
|
265
|
+
lineNumber: 1,
|
|
266
|
+
description,
|
|
267
|
+
quantity: 1,
|
|
268
|
+
price: money(subTotal),
|
|
269
|
+
},
|
|
270
|
+
],
|
|
271
|
+
updatedTimestamp: ago(paid ? issuedAgo - paidAfter : issuedAgo),
|
|
272
|
+
});
|
|
273
|
+
if (paid) {
|
|
274
|
+
remittances.push({
|
|
275
|
+
urn: sampleUrn(5, remittances.length + 1),
|
|
276
|
+
paymentInvoice: { urn },
|
|
277
|
+
remittanceDirection: 'PAYMENT',
|
|
278
|
+
remittanceStatus: 'RECEIVED',
|
|
279
|
+
value: money(amount),
|
|
280
|
+
remittanceMethod: METHODS[(n + 1) % METHODS.length],
|
|
281
|
+
reference: `TW-${1100 + n}`,
|
|
282
|
+
remittingCompany: party.company,
|
|
283
|
+
remittingIdentity: party.identity,
|
|
284
|
+
receivedTimestamp: ago(issuedAgo - paidAfter),
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
// A card payment that failed, against the invoice still awaiting payment.
|
|
289
|
+
remittances.push({
|
|
290
|
+
urn: sampleUrn(5, remittances.length + 1),
|
|
291
|
+
paymentInvoice: { urn: invoices[4].urn },
|
|
292
|
+
remittanceDirection: 'PAYMENT',
|
|
293
|
+
remittanceStatus: 'FAILED',
|
|
294
|
+
value: invoices[4].total,
|
|
295
|
+
remittanceMethod: 'CARD_PAYMENT',
|
|
296
|
+
reference: 'TW-1044-DECLINED',
|
|
297
|
+
remittingCompany: invoices[4].remitter?.company ?? null,
|
|
298
|
+
remittingIdentity: invoices[4].remitter?.identity ?? null,
|
|
299
|
+
receivedTimestamp: ago(5),
|
|
300
|
+
});
|
|
301
|
+
return { companies: [...companies, ...prospects], pipelines: [pipeline], leads, deals, invoices, remittances };
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mock/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAA0B,MAAM,gCAAgC,CAAC;AAEjG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAsD7C,qFAAqF;AACrF,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,CAAS;IAC/C,OAAO,2BAA2B,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;AACzE,CAAC;AAED,4CAA4C;AAC5C,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAEjF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,gBAAgB,GAA6B;IACxD,mBAAmB;IACnB,uBAAuB;IACvB,oBAAoB;IACpB,qBAAqB;IACrB,uBAAuB;IACvB,mBAAmB;CACpB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEzD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAErC,iHAAiH;AACjH,MAAM,MAAM,GAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,IAA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,EAAE,kBAAkB;QAC7B,gBAAgB,EAAE,QAAQ,CAAC,CAAC,CAAE,CAAC,QAAQ,EAAE,OAAO,IAAI,IAAI;QACxD,iBAAiB,EAAE,QAAQ,CAAC,CAAC,CAAE,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI;QAC1D,iBAAiB,EAAE,GAAG,CAAC,CAAC,CAAC;KAC1B,CAAC,CAAC;IAEH,OAAO,EAAE,SAAS,EAAE,CAAC,GAAG,SAAS,EAAE,GAAG,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACjH,CAAC"}
|
package/dist/money.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Money } from './types.ts';
|
|
2
|
+
/** Totals per currency, in minor units: `{ GBP: 125000 }` is 1,250.00 GBP. */
|
|
3
|
+
export type MoneyTotals = Readonly<Record<string, number>>;
|
|
4
|
+
/** How many decimal places a currency uses: 2 for GBP, 0 for JPY, 3 for KWD. */
|
|
5
|
+
export declare function fractionDigits(currencyCode: string): number;
|
|
6
|
+
/**
|
|
7
|
+
* Decimal text, such as a person types it, in minor units, rounding half away from zero past the currency's decimal places. Throws on a value
|
|
8
|
+
* that isn't a plain decimal, such as `"1,250"` or `"abc"`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toMinor(amount: string, currencyCode: string): number;
|
|
11
|
+
/** Minor units as decimal text with the currency's decimal places: `toDecimal(125000, 'GBP')` is `"1250.00"`. */
|
|
12
|
+
export declare function toDecimal(minor: number, currencyCode: string): string;
|
|
13
|
+
/** Minor units as Money, rounded to a whole unit. */
|
|
14
|
+
export declare const fromMinor: (minor: number, currencyCode: string) => Money;
|
|
15
|
+
/** An amount's minor units, 0 when there's none: for the API's optional money fields (`paid`, `refunded`). */
|
|
16
|
+
export declare const minorOf: (money: Pick<Money, "unitValue"> | null | undefined) => number;
|
|
17
|
+
/** Totals with `money` added (`times` scales it, such as -1 for a refund). Absent money adds nothing. */
|
|
18
|
+
export declare function addMoney(totals: MoneyTotals, money: Pick<Money, 'unitValue' | 'currencyCode'> | null | undefined, times?: number): MoneyTotals;
|
|
19
|
+
/** The totals of a list of amounts, per currency. */
|
|
20
|
+
export declare function sumMoney(values: Iterable<Money | null | undefined>): MoneyTotals;
|
|
21
|
+
/** Two sets of totals added together. */
|
|
22
|
+
export declare function addTotals(a: MoneyTotals, b: MoneyTotals): MoneyTotals;
|
|
23
|
+
/** Totals as Money, largest first, leaving out currencies that total zero. */
|
|
24
|
+
export declare function totalsToMoney(totals: MoneyTotals): Money[];
|
|
25
|
+
/** The total in one currency, in minor units (0 when there's none). */
|
|
26
|
+
export declare const totalIn: (totals: MoneyTotals, currencyCode: string) => number;
|
|
27
|
+
/** Money for people to read, such as "GBP 1,250.00" written with its symbol. */
|
|
28
|
+
export declare function formatMoney(money: Money, locale?: string, options?: Intl.NumberFormatOptions): string;
|
|
29
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../src/money.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAQxC,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAI3D,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAa3D;AAID;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAQpE;AAED,iHAAiH;AACjH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAKrE;AAED,qDAAqD;AACrD,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,cAAc,MAAM,KAAG,KAG9D,CAAC;AAEH,8GAA8G;AAC9G,eAAO,MAAM,OAAO,GAAI,OAAO,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,KAAG,MAA+B,CAAC;AAE7G,yGAAyG;AACzG,wBAAgB,QAAQ,CACtB,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,EACnE,KAAK,SAAI,GACR,WAAW,CAGb;AAED,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,WAAW,CAIhF;AAED,yCAAyC;AACzC,wBAAgB,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,WAAW,CAIrE;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,CAK1D;AAED,uEAAuE;AACvE,eAAO,MAAM,OAAO,GAAI,QAAQ,WAAW,EAAE,cAAc,MAAM,KAAG,MAAmC,CAAC;AAExG,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,SAAU,EAAE,OAAO,GAAE,IAAI,CAAC,mBAAwB,GAAG,MAAM,CAK1G"}
|
package/dist/money.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const digitsCache = new Map();
|
|
2
|
+
/** How many decimal places a currency uses: 2 for GBP, 0 for JPY, 3 for KWD. */
|
|
3
|
+
export function fractionDigits(currencyCode) {
|
|
4
|
+
let digits = digitsCache.get(currencyCode);
|
|
5
|
+
if (digits === undefined) {
|
|
6
|
+
try {
|
|
7
|
+
digits =
|
|
8
|
+
new Intl.NumberFormat('en', { style: 'currency', currency: currencyCode }).resolvedOptions()
|
|
9
|
+
.maximumFractionDigits ?? 2;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
digits = 2;
|
|
13
|
+
}
|
|
14
|
+
digitsCache.set(currencyCode, digits);
|
|
15
|
+
}
|
|
16
|
+
return digits;
|
|
17
|
+
}
|
|
18
|
+
const DECIMAL = /^\s*([+-]?)(\d*)(?:\.(\d*))?\s*$/;
|
|
19
|
+
/**
|
|
20
|
+
* Decimal text, such as a person types it, in minor units, rounding half away from zero past the currency's decimal places. Throws on a value
|
|
21
|
+
* that isn't a plain decimal, such as `"1,250"` or `"abc"`.
|
|
22
|
+
*/
|
|
23
|
+
export function toMinor(amount, currencyCode) {
|
|
24
|
+
const match = DECIMAL.exec(amount);
|
|
25
|
+
if (!match || (match[2] === '' && !match[3]))
|
|
26
|
+
throw new RangeError(`Not a decimal amount: "${amount}"`);
|
|
27
|
+
const [, sign, whole = '', fraction = ''] = match;
|
|
28
|
+
const digits = fractionDigits(currencyCode);
|
|
29
|
+
let minor = Number(whole || '0') * 10 ** digits + Number(fraction.slice(0, digits).padEnd(digits, '0') || '0');
|
|
30
|
+
if (Number(fraction[digits] ?? '0') >= 5)
|
|
31
|
+
minor += 1;
|
|
32
|
+
return sign === '-' ? -minor : minor;
|
|
33
|
+
}
|
|
34
|
+
/** Minor units as decimal text with the currency's decimal places: `toDecimal(125000, 'GBP')` is `"1250.00"`. */
|
|
35
|
+
export function toDecimal(minor, currencyCode) {
|
|
36
|
+
const digits = fractionDigits(currencyCode);
|
|
37
|
+
const sign = minor < 0 ? '-' : '';
|
|
38
|
+
const units = String(Math.abs(Math.round(minor))).padStart(digits + 1, '0');
|
|
39
|
+
return sign + (digits === 0 ? units : `${units.slice(0, -digits)}.${units.slice(-digits)}`);
|
|
40
|
+
}
|
|
41
|
+
/** Minor units as Money, rounded to a whole unit. */
|
|
42
|
+
export const fromMinor = (minor, currencyCode) => ({
|
|
43
|
+
unitValue: Math.round(minor),
|
|
44
|
+
currencyCode,
|
|
45
|
+
});
|
|
46
|
+
/** An amount's minor units, 0 when there's none: for the API's optional money fields (`paid`, `refunded`). */
|
|
47
|
+
export const minorOf = (money) => money?.unitValue ?? 0;
|
|
48
|
+
/** Totals with `money` added (`times` scales it, such as -1 for a refund). Absent money adds nothing. */
|
|
49
|
+
export function addMoney(totals, money, times = 1) {
|
|
50
|
+
if (!money)
|
|
51
|
+
return totals;
|
|
52
|
+
return { ...totals, [money.currencyCode]: (totals[money.currencyCode] ?? 0) + money.unitValue * times };
|
|
53
|
+
}
|
|
54
|
+
/** The totals of a list of amounts, per currency. */
|
|
55
|
+
export function sumMoney(values) {
|
|
56
|
+
let totals = {};
|
|
57
|
+
for (const value of values)
|
|
58
|
+
totals = addMoney(totals, value);
|
|
59
|
+
return totals;
|
|
60
|
+
}
|
|
61
|
+
/** Two sets of totals added together. */
|
|
62
|
+
export function addTotals(a, b) {
|
|
63
|
+
const totals = { ...a };
|
|
64
|
+
for (const [currency, minor] of Object.entries(b))
|
|
65
|
+
totals[currency] = (totals[currency] ?? 0) + minor;
|
|
66
|
+
return totals;
|
|
67
|
+
}
|
|
68
|
+
/** Totals as Money, largest first, leaving out currencies that total zero. */
|
|
69
|
+
export function totalsToMoney(totals) {
|
|
70
|
+
return Object.entries(totals)
|
|
71
|
+
.filter(([, minor]) => minor !== 0)
|
|
72
|
+
.sort(([, a], [, b]) => b - a)
|
|
73
|
+
.map(([currency, minor]) => fromMinor(minor, currency));
|
|
74
|
+
}
|
|
75
|
+
/** The total in one currency, in minor units (0 when there's none). */
|
|
76
|
+
export const totalIn = (totals, currencyCode) => totals[currencyCode] ?? 0;
|
|
77
|
+
/** Money for people to read, such as "GBP 1,250.00" written with its symbol. */
|
|
78
|
+
export function formatMoney(money, locale = 'en-GB', options = {}) {
|
|
79
|
+
const digits = fractionDigits(money.currencyCode);
|
|
80
|
+
return new Intl.NumberFormat(locale, { style: 'currency', currency: money.currencyCode, ...options }).format(money.unitValue / 10 ** digits);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingUR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AE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;SAC7B,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAE,YAAoB,EAAU,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AAExG,gFAAgF;AAChF,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,MAAM,GAAG,OAAO,EAAE,UAAoC,EAAE;IAChG,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,YAAY,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,MAAM,CAC1G,KAAK,CAAC,SAAS,GAAG,EAAE,IAAI,MAAM,CAC/B,CAAC;AACJ,CAAC"}
|
package/dist/period.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** A span of time: from `start` (included) to `end` (excluded). */
|
|
2
|
+
export interface DateRange {
|
|
3
|
+
start: Date;
|
|
4
|
+
end: Date;
|
|
5
|
+
}
|
|
6
|
+
/** The `days` up to `now`, for "last 28 days" views. */
|
|
7
|
+
export declare function lastDays(days: number, now?: Date): DateRange;
|
|
8
|
+
/** The same length of time just before `range`, for "vs previous period". */
|
|
9
|
+
export declare function previousRange(range: DateRange): DateRange;
|
|
10
|
+
/** Whether a Baack timestamp falls in a range. Empty or invalid timestamps don't. */
|
|
11
|
+
export declare function inRange(timestamp: string | null | undefined, range: DateRange): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The change from `previous` to `current` as a fraction (0.1 is a 10% rise), or undefined when there was nothing
|
|
14
|
+
* before to compare with.
|
|
15
|
+
*/
|
|
16
|
+
export declare function periodChange(current: number, previous: number): number | undefined;
|
|
17
|
+
//# sourceMappingURL=period.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.d.ts","sourceRoot":"","sources":["../src/period.ts"],"names":[],"mappings":"AAEA,mEAAmE;AACnE,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,wDAAwD;AACxD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAa,GAAG,SAAS,CAElE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAGzD;AAED,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,OAAO,CAGvF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAElF"}
|
package/dist/period.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { parseTimestamp } from '@baack-software/baack-ts-tasks';
|
|
2
|
+
/** The `days` up to `now`, for "last 28 days" views. */
|
|
3
|
+
export function lastDays(days, now = new Date()) {
|
|
4
|
+
return { start: new Date(now.getTime() - days * 86_400_000), end: now };
|
|
5
|
+
}
|
|
6
|
+
/** The same length of time just before `range`, for "vs previous period". */
|
|
7
|
+
export function previousRange(range) {
|
|
8
|
+
const length = range.end.getTime() - range.start.getTime();
|
|
9
|
+
return { start: new Date(range.start.getTime() - length), end: range.start };
|
|
10
|
+
}
|
|
11
|
+
/** Whether a Baack timestamp falls in a range. Empty or invalid timestamps don't. */
|
|
12
|
+
export function inRange(timestamp, range) {
|
|
13
|
+
const date = parseTimestamp(timestamp);
|
|
14
|
+
return date !== undefined && date >= range.start && date < range.end;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The change from `previous` to `current` as a fraction (0.1 is a 10% rise), or undefined when there was nothing
|
|
18
|
+
* before to compare with.
|
|
19
|
+
*/
|
|
20
|
+
export function periodChange(current, previous) {
|
|
21
|
+
return previous === 0 ? undefined : (current - previous) / previous;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=period.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.js","sourceRoot":"","sources":["../src/period.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAQhE,wDAAwD;AACxD,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,GAAG,GAAG,IAAI,IAAI,EAAE;IACrD,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,GAAG,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC1E,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,KAAgB;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC3D,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;AAC/E,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,OAAO,CAAC,SAAoC,EAAE,KAAgB;IAC5E,MAAM,IAAI,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;IACvC,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC;AACvE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,QAAgB;IAC5D,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type MoneyTotals } from './money.ts';
|
|
2
|
+
import type { Deal, DealOutcome, Pipeline, PipelineStage } from './types.ts';
|
|
3
|
+
/** A pipeline's stages in order. */
|
|
4
|
+
export declare const orderedStages: (pipeline: Pipeline) => PipelineStage[];
|
|
5
|
+
/** The stage a deal is at, when it's in this pipeline. */
|
|
6
|
+
export declare const stageOf: (deal: Deal, pipeline: Pipeline) => PipelineStage | undefined;
|
|
7
|
+
/** The pipeline a deal is in, among several. */
|
|
8
|
+
export declare const pipelineOf: (deal: Deal, pipelines: readonly Pipeline[]) => Pipeline | undefined;
|
|
9
|
+
/** How a deal stands: its own outcome, open when it has none. */
|
|
10
|
+
export declare const dealOutcome: (deal: Deal) => DealOutcome;
|
|
11
|
+
export declare const isOpenDeal: (deal: Deal) => boolean;
|
|
12
|
+
/** A deal's customer company: its first contact company, when it has one. */
|
|
13
|
+
export declare const dealCompany: (deal: Pick<Deal, "contactCompanies">) => import("@baack-software/baack-ts-tasks").Ref | undefined;
|
|
14
|
+
/** Whether a deal is with a company: among its contact companies. */
|
|
15
|
+
export declare const isDealWith: (deal: Pick<Deal, "contactCompanies">, company: string) => boolean;
|
|
16
|
+
/** The chance a deal is won, 0 to 100: won is 100 and lost 0, otherwise the deal's own probability. */
|
|
17
|
+
export declare function dealProbability(deal: Deal): number | undefined;
|
|
18
|
+
export interface StageSummary {
|
|
19
|
+
stage: PipelineStage;
|
|
20
|
+
deals: Deal[];
|
|
21
|
+
/** The deals' target values per currency. */
|
|
22
|
+
value: MoneyTotals;
|
|
23
|
+
/** The values weighted by each deal's probability; deals without one aren't counted. */
|
|
24
|
+
weighted: MoneyTotals;
|
|
25
|
+
/** This stage's share of the pipeline's deals, 0 to 1. */
|
|
26
|
+
share: number;
|
|
27
|
+
}
|
|
28
|
+
/** One row per stage, in order, for the pipeline card: its deals, their value, weighted value and share. */
|
|
29
|
+
export declare function pipelineByStage(deals: readonly Deal[], pipeline: Pipeline): StageSummary[];
|
|
30
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE7E,oCAAoC;AACpC,eAAO,MAAM,aAAa,GAAI,UAAU,QAAQ,KAAG,aAAa,EACT,CAAC;AAExD,0DAA0D;AAC1D,eAAO,MAAM,OAAO,GAAI,MAAM,IAAI,EAAE,UAAU,QAAQ,KAAG,aAAa,GAAG,SACD,CAAC;AAEzE,gDAAgD;AAChD,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,EAAE,WAAW,SAAS,QAAQ,EAAE,KAAG,QAAQ,GAAG,SAC5B,CAAC;AAExD,iEAAiE;AACjE,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,WAAqC,CAAC;AAE/E,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,OAAuC,CAAC;AAEhF,6EAA6E;AAC7E,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,6DAA+B,CAAC;AAEhG,qEAAqE;AACrE,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE,SAAS,MAAM,KAAG,OACb,CAAC;AAEvE,uGAAuG;AACvG,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAK9D;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,aAAa,CAAC;IACrB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,6CAA6C;IAC7C,KAAK,EAAE,WAAW,CAAC;IACnB,wFAAwF;IACxF,QAAQ,EAAE,WAAW,CAAC;IACtB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;CACf;AAED,4GAA4G;AAC5G,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,YAAY,EAAE,CAa1F"}
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { addMoney } from "./money.js";
|
|
2
|
+
/** A pipeline's stages in order. */
|
|
3
|
+
export const orderedStages = (pipeline) => pipeline.stages.toSorted((a, b) => a.order - b.order);
|
|
4
|
+
/** The stage a deal is at, when it's in this pipeline. */
|
|
5
|
+
export const stageOf = (deal, pipeline) => pipeline.stages.find((stage) => stage.urn === deal.workflowStage?.urn);
|
|
6
|
+
/** The pipeline a deal is in, among several. */
|
|
7
|
+
export const pipelineOf = (deal, pipelines) => pipelines.find((pipeline) => stageOf(deal, pipeline));
|
|
8
|
+
/** How a deal stands: its own outcome, open when it has none. */
|
|
9
|
+
export const dealOutcome = (deal) => deal.outcome ?? 'OPEN';
|
|
10
|
+
export const isOpenDeal = (deal) => dealOutcome(deal) === 'OPEN';
|
|
11
|
+
/** A deal's customer company: its first contact company, when it has one. */
|
|
12
|
+
export const dealCompany = (deal) => deal.contactCompanies?.[0];
|
|
13
|
+
/** Whether a deal is with a company: among its contact companies. */
|
|
14
|
+
export const isDealWith = (deal, company) => (deal.contactCompanies ?? []).some((other) => other.urn === company);
|
|
15
|
+
/** The chance a deal is won, 0 to 100: won is 100 and lost 0, otherwise the deal's own probability. */
|
|
16
|
+
export function dealProbability(deal) {
|
|
17
|
+
const outcome = dealOutcome(deal);
|
|
18
|
+
if (outcome === 'WON')
|
|
19
|
+
return 100;
|
|
20
|
+
if (outcome === 'LOST')
|
|
21
|
+
return 0;
|
|
22
|
+
return deal.probability ?? undefined;
|
|
23
|
+
}
|
|
24
|
+
/** One row per stage, in order, for the pipeline card: its deals, their value, weighted value and share. */
|
|
25
|
+
export function pipelineByStage(deals, pipeline) {
|
|
26
|
+
const inPipeline = deals.filter((deal) => stageOf(deal, pipeline));
|
|
27
|
+
return orderedStages(pipeline).map((stage) => {
|
|
28
|
+
const here = inPipeline.filter((deal) => deal.workflowStage?.urn === stage.urn);
|
|
29
|
+
let value = {};
|
|
30
|
+
let weighted = {};
|
|
31
|
+
for (const deal of here) {
|
|
32
|
+
value = addMoney(value, deal.targetValue);
|
|
33
|
+
const probability = dealProbability(deal);
|
|
34
|
+
if (probability !== undefined)
|
|
35
|
+
weighted = addMoney(weighted, deal.targetValue, probability / 100);
|
|
36
|
+
}
|
|
37
|
+
return { stage, deals: here, value, weighted, share: inPipeline.length ? here.length / inPipeline.length : 0 };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAGxD,oCAAoC;AACpC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAkB,EAAmB,EAAE,CACnE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAExD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAU,EAAE,QAAkB,EAA6B,EAAE,CACnF,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE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GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACnE,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC;QAChF,IAAI,KAAK,GAAgB,EAAE,CAAC;QAC5B,IAAI,QAAQ,GAAgB,EAAE,CAAC;QAC/B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YAC1C,MAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,WAAW,KAAK,SAAS;gBAAE,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,GAAG,CAAC,CAAC;QACpG,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACjH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type SourceCount } from '../leads.ts';
|
|
2
|
+
import { type MoneyTotals } from '../money.ts';
|
|
3
|
+
import { type CrmText } from './text.ts';
|
|
4
|
+
/** Payments received each day, as an area like the console's usage chart. */
|
|
5
|
+
export declare function RevenueChart({ days, currencyCode, text, }: {
|
|
6
|
+
days: {
|
|
7
|
+
day: string;
|
|
8
|
+
totals: MoneyTotals;
|
|
9
|
+
}[];
|
|
10
|
+
/** The currency charted; others aren't added in. */
|
|
11
|
+
currencyCode: string | undefined;
|
|
12
|
+
text?: Partial<CrmText> | undefined;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
/** How many leads came from each source, as a shadcn bar chart. */
|
|
15
|
+
export declare function LeadsBySourceCard({ counts, text }: {
|
|
16
|
+
counts: SourceCount[];
|
|
17
|
+
text?: Partial<CrmText> | undefined;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=Charts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Charts.d.ts","sourceRoot":"","sources":["../../src/react/Charts.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAA0C,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAEvF,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAWnD,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,YAAY,EACZ,IAAI,GACL,EAAE;IACD,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,EAAE,CAAC;IAC7C,oDAAoD;IACpD,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CACrC,+BA0EA;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;IAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;CAAE,+BAuCjH"}
|