@ossy/consultancy 3.20.1 → 3.22.0
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/package.json +4 -2
- package/src/AssignmentMarginCalculator.jsx +7 -32
- package/src/ConsultancyNav.jsx +30 -1
- package/src/ConsultancyRecordList.jsx +172 -0
- package/src/CreateConsultancyButton.jsx +61 -13
- package/src/Forecast.jsx +42 -220
- package/src/Overview.jsx +10 -31
- package/src/RequestStatsPanel.jsx +66 -0
- package/src/consultancy.page.jsx +3 -40
- package/src/contracts.page.jsx +26 -0
- package/src/current-month.component.jsx +43 -25
- package/src/employees.page.jsx +26 -0
- package/src/en.translations.json +67 -2
- package/src/extract-request.action.js +5 -0
- package/src/extract-request.task.js +100 -0
- package/src/extract-request.task.spec.js +89 -0
- package/src/forecast-panels.jsx +125 -0
- package/src/forecast-widget-menu.jsx +89 -0
- package/src/get-request-stats.action.js +6 -0
- package/src/get-request-stats.task.js +26 -0
- package/src/index.js +1 -0
- package/src/intake-categories.js +39 -0
- package/src/kpi-trend.component.jsx +17 -0
- package/src/margin-panels.jsx +7 -32
- package/src/opportunities.page.jsx +26 -0
- package/src/opportunity.schema.js +1 -1
- package/src/org.page.jsx +1 -2
- package/src/proposals.page.jsx +26 -0
- package/src/reports.page.jsx +103 -0
- package/src/request-buckets.js +76 -0
- package/src/request-buckets.spec.js +33 -0
- package/src/request-stats.aggregate.js +52 -0
- package/src/request-stats.aggregate.spec.js +34 -0
- package/src/request-stats.component.jsx +16 -0
- package/src/request.schema.js +29 -0
- package/src/requests.page.jsx +26 -0
- package/src/schema-ids.js +1 -0
- package/src/screen-inbound.task.js +84 -0
- package/src/screen-inbound.task.spec.js +97 -0
- package/src/sv.translations.json +67 -2
- package/src/use-chart-months.js +27 -0
- package/src/utilization-hours.js +196 -0
- package/src/utilization-hours.spec.js +134 -0
- package/src/utilization.component.jsx +17 -0
- package/src/vacations.page.jsx +26 -0
- package/src/year-totals.component.jsx +17 -0
- package/src/forecast-kpi-chart.js +0 -137
- package/src/forecast-kpi-chart.spec.js +0 -122
package/src/en.translations.json
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
"consultancy/home.documentTitle": "Overview",
|
|
3
3
|
"consultancy/org.documentTitle": "Org Details",
|
|
4
4
|
"consultancy/margins.documentTitle": "Margins",
|
|
5
|
+
"consultancy/employees.documentTitle": "Employees",
|
|
6
|
+
"consultancy/vacations.documentTitle": "Vacations",
|
|
7
|
+
"consultancy/contracts.documentTitle": "Contracts",
|
|
8
|
+
"consultancy/opportunities.documentTitle": "Opportunities",
|
|
9
|
+
"consultancy/requests.documentTitle": "Requests",
|
|
10
|
+
"consultancy/proposals.documentTitle": "Proposals",
|
|
11
|
+
"consultancy/reports.documentTitle": "Reports",
|
|
5
12
|
"consultancy.home.title": "Overview",
|
|
6
13
|
"consultancy.home.description": "Fiscal-year KPIs, year totals, and monthly capacity from contracts, employees, and vacations",
|
|
7
14
|
"consultancy.org.title": "Org Details",
|
|
@@ -9,13 +16,29 @@
|
|
|
9
16
|
"consultancy.nav.title": "Consultancy",
|
|
10
17
|
"consultancy.nav.overview": "Overview",
|
|
11
18
|
"consultancy.nav.forecasts": "Forecasts",
|
|
19
|
+
"consultancy.nav.employees": "Employees",
|
|
20
|
+
"consultancy.nav.vacations": "Vacations",
|
|
21
|
+
"consultancy.nav.contracts": "Contracts",
|
|
22
|
+
"consultancy.nav.requests": "Requests",
|
|
23
|
+
"consultancy.nav.opportunities": "Opportunities",
|
|
24
|
+
"consultancy.nav.proposals": "Proposals",
|
|
25
|
+
"consultancy.nav.reports": "Reports",
|
|
12
26
|
"consultancy.nav.margins": "Margins",
|
|
13
27
|
"consultancy.forecasts.title": "Overview",
|
|
14
28
|
"consultancy.forecasts.description": "Fiscal-year KPIs, year totals, and monthly capacity from contracts, employees, and vacations",
|
|
15
29
|
"consultancy.forecasts.income": "Income",
|
|
30
|
+
"consultancy.forecasts.forecastIncome": "Forecast income",
|
|
31
|
+
"consultancy.forecasts.actualIncome": "Actual income",
|
|
32
|
+
"consultancy.forecasts.forecastRevenue": "Forecast result",
|
|
33
|
+
"consultancy.forecasts.actualRevenue": "Actual result",
|
|
16
34
|
"consultancy.forecasts.salaryCost": "Salary cost",
|
|
17
35
|
"consultancy.forecasts.revenue": "Revenue",
|
|
18
36
|
"consultancy.forecasts.hoursWorked": "Hours worked",
|
|
37
|
+
"consultancy.forecasts.utilization": "Utilization",
|
|
38
|
+
"consultancy.forecasts.forecastHours": "Forecast hours",
|
|
39
|
+
"consultancy.forecasts.actualHours": "Actual hours",
|
|
40
|
+
"consultancy.forecasts.unitMoney": "SEK",
|
|
41
|
+
"consultancy.forecasts.unitHours": "h",
|
|
19
42
|
"consultancy.margins.title": "Margins",
|
|
20
43
|
"consultancy.margins.description": "See assignment margin and admin leakage before you invoice",
|
|
21
44
|
"consultancy.margins.notes.purpose": "Built for Nordic IT consultancies that outgrew timers + spreadsheets but do not need an enterprise PSA.",
|
|
@@ -40,6 +63,38 @@
|
|
|
40
63
|
"consultancy.overview.fiscalYears": "Fiscal years",
|
|
41
64
|
"consultancy.overview.company": "Company",
|
|
42
65
|
"consultancy.overview.noFiscalYears": "No fiscal years yet.",
|
|
66
|
+
"consultancy.employees.title": "Employees",
|
|
67
|
+
"consultancy.employees.description": "People on the consultancy",
|
|
68
|
+
"consultancy.employees.empty": "No employees yet.",
|
|
69
|
+
"consultancy.vacations.title": "Vacations",
|
|
70
|
+
"consultancy.vacations.description": "Time off that is not billed",
|
|
71
|
+
"consultancy.vacations.empty": "No vacations yet.",
|
|
72
|
+
"consultancy.contracts.title": "Contracts",
|
|
73
|
+
"consultancy.contracts.description": "Client assignments and rates",
|
|
74
|
+
"consultancy.contracts.empty": "No contracts yet.",
|
|
75
|
+
"consultancy.requests.title": "Requests",
|
|
76
|
+
"consultancy.requests.description": "Assignments parsed from inbound email",
|
|
77
|
+
"consultancy.requests.empty": "No requests yet.",
|
|
78
|
+
"consultancy.requests.statsTitle": "Incoming requests",
|
|
79
|
+
"consultancy.requests.statsSeries": "Requests",
|
|
80
|
+
"consultancy.requests.statsUnit": "requests",
|
|
81
|
+
"consultancy.requests.statsEmpty": "No requests dated yet.",
|
|
82
|
+
"consultancy.reports.title": "Reports",
|
|
83
|
+
"consultancy.reports.description": "Charts of incoming work",
|
|
84
|
+
"consultancy.reports.empty": "No reports yet.",
|
|
85
|
+
"consultancy.opportunities.title": "Opportunities",
|
|
86
|
+
"consultancy.opportunities.description": "Pipeline of possible assignments",
|
|
87
|
+
"consultancy.opportunities.empty": "No opportunities yet.",
|
|
88
|
+
"consultancy.proposals.title": "Proposals",
|
|
89
|
+
"consultancy.proposals.description": "Offers sent for opportunities",
|
|
90
|
+
"consultancy.proposals.empty": "No proposals yet.",
|
|
91
|
+
"consultancy.records.loading": "Loading…",
|
|
92
|
+
"consultancy.add.company": "Company",
|
|
93
|
+
"consultancy.add.employee": "Employee",
|
|
94
|
+
"consultancy.add.contract": "Contract",
|
|
95
|
+
"consultancy.add.opportunity": "Opportunity",
|
|
96
|
+
"consultancy.add.proposal": "Proposal",
|
|
97
|
+
"consultancy.add.vacation": "Vacation",
|
|
43
98
|
"consultancy.empty.title": "Looks empty",
|
|
44
99
|
"consultancy.empty.text": "Add company info, employees, contracts, and vacations to get started.",
|
|
45
100
|
"@ossy/consultancy/form/calculator.label": "Assignment margin calculator",
|
|
@@ -146,7 +201,8 @@
|
|
|
146
201
|
"@ossy/consultancy/schema/proposal.body.description": "Full proposal text.",
|
|
147
202
|
"consultancy.nav.orgDetails": "Org Details",
|
|
148
203
|
"consultancy.forecasts.yearChart": "KPI trend",
|
|
149
|
-
"consultancy.forecasts.
|
|
204
|
+
"consultancy.forecasts.monthForecast": "{month} forecast",
|
|
205
|
+
"consultancy.forecasts.yearSummary": "Fiscal year forecast",
|
|
150
206
|
"consultancy.forecasts.yearChartEmpty": "No forecast months to chart yet.",
|
|
151
207
|
"consultancy.margins.pin.done": "Pinned to dashboard",
|
|
152
208
|
"consultancy.margins.pin.error": "Pin failed — try again",
|
|
@@ -161,5 +217,14 @@
|
|
|
161
217
|
"consultancy.widgets.adminLeakage.title": "Admin leakage",
|
|
162
218
|
"consultancy.widgets.adminLeakage.description": "Annual hours and revenue lost to recurring admin work.",
|
|
163
219
|
"consultancy.widgets.forecastCurrentMonth.title": "This month forecast",
|
|
164
|
-
"consultancy.widgets.forecastCurrentMonth.description": "Projected income, salary cost, revenue, and hours for the current month."
|
|
220
|
+
"consultancy.widgets.forecastCurrentMonth.description": "Projected income, salary cost, revenue, and hours for the current month.",
|
|
221
|
+
"consultancy.widgets.kpiTrend.title": "KPI trend",
|
|
222
|
+
"consultancy.widgets.kpiTrend.description": "Forecast and actual income, salary cost, and revenue for the fiscal year.",
|
|
223
|
+
"consultancy.widgets.yearTotals.title": "Fiscal year forecast",
|
|
224
|
+
"consultancy.widgets.yearTotals.description": "Income, salary cost, revenue, and hours for the fiscal year.",
|
|
225
|
+
"consultancy.widgets.utilization.title": "Utilization",
|
|
226
|
+
"consultancy.widgets.utilization.description": "Forecast and actual hours across the fiscal year.",
|
|
227
|
+
"consultancy.widgets.requestStats.title": "Incoming requests",
|
|
228
|
+
"consultancy.widgets.requestStats.description": "Requests per month, dated by the email's own arrival time.",
|
|
229
|
+
"consultancy.widgets.menu": "More"
|
|
165
230
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
2
|
+
import { location } from './locations.js'
|
|
3
|
+
|
|
4
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
5
|
+
const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
6
|
+
const ExtractStructuredData = { id: '@ossy/media-tasks/actions/extract-structured-data' }
|
|
7
|
+
const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
|
|
8
|
+
|
|
9
|
+
export const metadata = {
|
|
10
|
+
id: '@ossy/consultancy/tasks/extract-request',
|
|
11
|
+
triggers: [
|
|
12
|
+
{
|
|
13
|
+
kind: 'on_action',
|
|
14
|
+
action: '@ossy/consultancy/actions/extract-request',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
outputs: [
|
|
18
|
+
{
|
|
19
|
+
name: 'request',
|
|
20
|
+
kind: 'location',
|
|
21
|
+
schemaId: ConsultancySchema.request,
|
|
22
|
+
prefix: location,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function fail (message, status) {
|
|
28
|
+
throw Object.assign(new Error(message), { status })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function workspaceIdFrom ({ event, payload, req }) {
|
|
32
|
+
return event?.payload?.belongsTo
|
|
33
|
+
?? event?.belongsTo
|
|
34
|
+
?? payload?.workspaceId
|
|
35
|
+
?? req?.workspaceId
|
|
36
|
+
?? null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Text the extractor should read. The subject often is the assignment title.
|
|
41
|
+
*
|
|
42
|
+
* @param {object | null | undefined} resource
|
|
43
|
+
*/
|
|
44
|
+
export function requestSourceText (resource) {
|
|
45
|
+
const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
|
|
46
|
+
const lines = []
|
|
47
|
+
if (content.subject) lines.push(`Subject: ${content.subject}`)
|
|
48
|
+
if (content.from) lines.push(`From: ${content.from}`)
|
|
49
|
+
const body = typeof content.text === 'string' ? content.text.trim() : ''
|
|
50
|
+
if (body) lines.push('', body)
|
|
51
|
+
return lines.join('\n').trim()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Inbound assignment → extract-structured-data → a consultancy request resource.
|
|
56
|
+
* Screening decides whether this runs. It does not listen to every inbound message.
|
|
57
|
+
*/
|
|
58
|
+
export async function run ({ event, payload, req, sdk }) {
|
|
59
|
+
if (!sdk?.invoke) fail('sdk is required', 500)
|
|
60
|
+
|
|
61
|
+
const resourceId = event?.resourceId || payload?.resourceId
|
|
62
|
+
if (!resourceId) fail('resourceId is required', 400)
|
|
63
|
+
|
|
64
|
+
const workspaceId = workspaceIdFrom({ event, payload, req })
|
|
65
|
+
if (!workspaceId) fail('workspaceId is required', 400)
|
|
66
|
+
|
|
67
|
+
const resource = await sdk.invoke(GetResource, { resourceId })
|
|
68
|
+
if (resource?.type !== INBOUND_MESSAGE) fail('inbound message is required', 400)
|
|
69
|
+
|
|
70
|
+
const text = requestSourceText(resource)
|
|
71
|
+
if (!text) fail('text is required', 400)
|
|
72
|
+
|
|
73
|
+
const extracted = await sdk.invoke(ExtractStructuredData, {
|
|
74
|
+
schemaId: ConsultancySchema.request,
|
|
75
|
+
text,
|
|
76
|
+
workspaceId,
|
|
77
|
+
})
|
|
78
|
+
const data = extracted?.data
|
|
79
|
+
if (!data || typeof data !== 'object') fail('extraction is required', 422)
|
|
80
|
+
|
|
81
|
+
const messageId = typeof resource.content?.messageId === 'string' ? resource.content.messageId : ''
|
|
82
|
+
const receivedAt = typeof resource.content?.receivedAt === 'string' ? resource.content.receivedAt.trim() : ''
|
|
83
|
+
const content = {
|
|
84
|
+
...data,
|
|
85
|
+
...(messageId ? { messageId } : {}),
|
|
86
|
+
...(receivedAt ? { receivedAt } : {}),
|
|
87
|
+
}
|
|
88
|
+
const title = typeof content.title === 'string' ? content.title.trim() : ''
|
|
89
|
+
if (!title) fail('title is required', 422)
|
|
90
|
+
|
|
91
|
+
const created = await sdk.invoke(CreateResource, {
|
|
92
|
+
workspaceId,
|
|
93
|
+
type: ConsultancySchema.request,
|
|
94
|
+
location,
|
|
95
|
+
name: title,
|
|
96
|
+
content,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
return { id: created?.id ?? null, workspaceId, content }
|
|
100
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Schema, validateContent } from '@ossy/schema'
|
|
2
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
3
|
+
import requestSchema from './request.schema.js'
|
|
4
|
+
import { metadata, requestSourceText, run } from './extract-request.task.js'
|
|
5
|
+
|
|
6
|
+
const GetResource = { id: '@ossy/resources/actions/get' }
|
|
7
|
+
const CreateResource = { id: '@ossy/resources/actions/create' }
|
|
8
|
+
const ExtractStructuredData = { id: '@ossy/media-tasks/actions/extract-structured-data' }
|
|
9
|
+
|
|
10
|
+
const inbound = {
|
|
11
|
+
id: 'msg-1',
|
|
12
|
+
type: '@ossy/email/schema/inbound-message',
|
|
13
|
+
content: {
|
|
14
|
+
from: 'Anna Berg <anna@client.se>',
|
|
15
|
+
to: 'requests+ws-1@inbound.ossy.se',
|
|
16
|
+
subject: 'Senior React, 6 manader',
|
|
17
|
+
text: 'Vi soker en senior React-utvecklare i Stockholm. Uppdraget ar 6 manader med start i januari. Anna Berg, anna@client.se.',
|
|
18
|
+
messageId: 'assignment-1@client.se',
|
|
19
|
+
receivedAt: '2023-04-15T10:00:00.000Z',
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const extracted = {
|
|
24
|
+
title: 'Senior React, 6 manader',
|
|
25
|
+
summary: 'Senior React developer in Stockholm for 6 months, starting in January.',
|
|
26
|
+
role: 'Senior React developer',
|
|
27
|
+
skills: 'React',
|
|
28
|
+
location: 'Stockholm',
|
|
29
|
+
duration: '6 months',
|
|
30
|
+
start: 'January',
|
|
31
|
+
contactName: 'Anna Berg',
|
|
32
|
+
contactEmail: 'anna@client.se',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('extract-request task', () => {
|
|
36
|
+
it('runs only when the extract-request action is invoked', () => {
|
|
37
|
+
expect(metadata.triggers).toEqual([
|
|
38
|
+
{
|
|
39
|
+
kind: 'on_action',
|
|
40
|
+
action: '@ossy/consultancy/actions/extract-request',
|
|
41
|
+
},
|
|
42
|
+
])
|
|
43
|
+
expect(metadata.outputs[0].schemaId).toBe(ConsultancySchema.request)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('turns a forwarded assignment email into a request record', async () => {
|
|
47
|
+
const calls = []
|
|
48
|
+
const sdk = {
|
|
49
|
+
async invoke (action, payload) {
|
|
50
|
+
calls.push({ id: action.id, payload })
|
|
51
|
+
if (action.id === GetResource.id) return inbound
|
|
52
|
+
if (action.id === ExtractStructuredData.id) return { data: extracted }
|
|
53
|
+
if (action.id === CreateResource.id) return { id: 'request-1' }
|
|
54
|
+
throw new Error(`unexpected ${action.id}`)
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const result = await run({
|
|
59
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
60
|
+
sdk,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const extractCall = calls.find((call) => call.id === ExtractStructuredData.id)
|
|
64
|
+
expect(extractCall.payload.schemaId).toBe(ConsultancySchema.request)
|
|
65
|
+
expect(extractCall.payload.text).toBe(requestSourceText(inbound))
|
|
66
|
+
expect(extractCall.payload.text).toContain('Senior React, 6 manader')
|
|
67
|
+
expect(extractCall.payload.text).toContain('Stockholm')
|
|
68
|
+
|
|
69
|
+
const created = calls.find((call) => call.id === CreateResource.id).payload
|
|
70
|
+
expect(created).toMatchObject({
|
|
71
|
+
workspaceId: 'ws-1',
|
|
72
|
+
type: ConsultancySchema.request,
|
|
73
|
+
name: 'Senior React, 6 manader',
|
|
74
|
+
})
|
|
75
|
+
expect(created.content).toMatchObject({
|
|
76
|
+
...extracted,
|
|
77
|
+
messageId: 'assignment-1@client.se',
|
|
78
|
+
receivedAt: '2023-04-15T10:00:00.000Z',
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const engine = Schema.of({ schemas: [requestSchema] })
|
|
82
|
+
expect(validateContent(engine, requestSchema, created.content).ok).toBe(true)
|
|
83
|
+
expect(result).toEqual({
|
|
84
|
+
id: 'request-1',
|
|
85
|
+
workspaceId: 'ws-1',
|
|
86
|
+
content: created.content,
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
|
+
import { LineChart, Panel, Text, View, useLocale } from '@ossy/design-system'
|
|
3
|
+
import { sumFiscalYearTotals } from '@ossy/calendar'
|
|
4
|
+
import { ForecastWidgetMenu } from './forecast-widget-menu.jsx'
|
|
5
|
+
import { useChartMonths } from './use-chart-months.js'
|
|
6
|
+
|
|
7
|
+
export const KPI_TREND_WIDGET_ID = '@ossy/consultancy/view/kpi-trend'
|
|
8
|
+
export const YEAR_TOTALS_WIDGET_ID = '@ossy/consultancy/view/year-totals'
|
|
9
|
+
export const UTILIZATION_WIDGET_ID = '@ossy/consultancy/view/utilization'
|
|
10
|
+
|
|
11
|
+
const KPI_SERIES = [
|
|
12
|
+
{ key: 'projectedIncome', label: 'consultancy.forecasts.forecastIncome', color: 'var(--color-info, hsl(199, 89%, 43%))', dashed: true },
|
|
13
|
+
{ key: 'actualIncome', label: 'consultancy.forecasts.actualIncome', color: 'var(--color-info, hsl(199, 89%, 43%))' },
|
|
14
|
+
{ key: 'monthlyCostOfEmployees', label: 'consultancy.forecasts.salaryCost', color: 'var(--color-warning, hsl(38, 92%, 50%))', dashed: true },
|
|
15
|
+
{ key: 'revenue', label: 'consultancy.forecasts.forecastRevenue', color: 'var(--color-accent, hsl(167, 89%, 43%))', dashed: true },
|
|
16
|
+
{ key: 'actualRevenue', label: 'consultancy.forecasts.actualRevenue', color: 'var(--color-accent, hsl(167, 89%, 43%))' },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const UTILIZATION_SERIES = [
|
|
20
|
+
{ key: 'forecastHours', label: 'consultancy.forecasts.forecastHours', color: 'var(--color-info, hsl(199, 89%, 43%))', scale: 'hours', dashed: true },
|
|
21
|
+
{ key: 'actualHours', label: 'consultancy.forecasts.actualHours', color: 'var(--color-accent, hsl(167, 89%, 43%))', scale: 'hours' },
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
const panelStyle = { height: '100%', flex: '1 1 auto', minWidth: 0 }
|
|
25
|
+
|
|
26
|
+
function useMoneyAndHours () {
|
|
27
|
+
const { language } = useLocale()
|
|
28
|
+
const money = (value) => new Intl.NumberFormat(language === 'sv' ? 'sv-SE' : 'en-SE', {
|
|
29
|
+
style: 'currency',
|
|
30
|
+
currency: 'SEK',
|
|
31
|
+
}).format(value)
|
|
32
|
+
const hours = (value) => new Intl.NumberFormat(language === 'sv' ? 'sv-SE' : 'en-GB', {
|
|
33
|
+
style: 'unit',
|
|
34
|
+
unit: 'hour',
|
|
35
|
+
}).format(value)
|
|
36
|
+
return { money, hours }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function KpiTrendPanel ({ dashboardId, pinnedWidgetId }) {
|
|
40
|
+
const months = useChartMonths()
|
|
41
|
+
return (
|
|
42
|
+
<Panel
|
|
43
|
+
title="consultancy.forecasts.yearChart"
|
|
44
|
+
style={panelStyle}
|
|
45
|
+
actions={(
|
|
46
|
+
<ForecastWidgetMenu
|
|
47
|
+
componentId={KPI_TREND_WIDGET_ID}
|
|
48
|
+
dashboardId={dashboardId}
|
|
49
|
+
pinnedWidgetId={pinnedWidgetId}
|
|
50
|
+
/>
|
|
51
|
+
)}
|
|
52
|
+
>
|
|
53
|
+
<LineChart
|
|
54
|
+
months={months}
|
|
55
|
+
series={KPI_SERIES}
|
|
56
|
+
unit="consultancy.forecasts.unitMoney"
|
|
57
|
+
empty="consultancy.forecasts.yearChartEmpty"
|
|
58
|
+
/>
|
|
59
|
+
</Panel>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function YearTotalsPanel ({ dashboardId, pinnedWidgetId }) {
|
|
64
|
+
const months = useChartMonths()
|
|
65
|
+
const { money, hours } = useMoneyAndHours()
|
|
66
|
+
const totals = useMemo(() => sumFiscalYearTotals(months), [months])
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Panel
|
|
70
|
+
title="consultancy.forecasts.yearSummary"
|
|
71
|
+
style={panelStyle}
|
|
72
|
+
data-consultancy-year-summary
|
|
73
|
+
actions={(
|
|
74
|
+
<ForecastWidgetMenu
|
|
75
|
+
componentId={YEAR_TOTALS_WIDGET_ID}
|
|
76
|
+
dashboardId={dashboardId}
|
|
77
|
+
pinnedWidgetId={pinnedWidgetId}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<View gap="s" inset="m">
|
|
82
|
+
<View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
|
|
83
|
+
<Text variant="m" style={{ marginBottom: 0 }} text="consultancy.forecasts.income" />
|
|
84
|
+
<Text variant="m" style={{ marginBottom: 0 }}>{money(totals.projectedIncome)}</Text>
|
|
85
|
+
</View>
|
|
86
|
+
<View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
|
|
87
|
+
<Text variant="m" style={{ marginBottom: 0 }} text="consultancy.forecasts.salaryCost" />
|
|
88
|
+
<Text variant="m" style={{ marginBottom: 0 }}>{money(totals.monthlyCostOfEmployees)}</Text>
|
|
89
|
+
</View>
|
|
90
|
+
<View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
|
|
91
|
+
<Text variant="m" style={{ marginBottom: 0 }} text="consultancy.forecasts.revenue" />
|
|
92
|
+
<Text variant="m" style={{ marginBottom: 0 }}>{money(totals.revenue)}</Text>
|
|
93
|
+
</View>
|
|
94
|
+
<View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
|
|
95
|
+
<Text variant="m" style={{ marginBottom: 0 }} text="consultancy.forecasts.hoursWorked" />
|
|
96
|
+
<Text variant="m" style={{ marginBottom: 0 }}>{hours(totals.hoursWorked)}</Text>
|
|
97
|
+
</View>
|
|
98
|
+
</View>
|
|
99
|
+
</Panel>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function UtilizationPanel ({ dashboardId, pinnedWidgetId }) {
|
|
104
|
+
const months = useChartMonths()
|
|
105
|
+
return (
|
|
106
|
+
<Panel
|
|
107
|
+
title="consultancy.forecasts.utilization"
|
|
108
|
+
style={panelStyle}
|
|
109
|
+
actions={(
|
|
110
|
+
<ForecastWidgetMenu
|
|
111
|
+
componentId={UTILIZATION_WIDGET_ID}
|
|
112
|
+
dashboardId={dashboardId}
|
|
113
|
+
pinnedWidgetId={pinnedWidgetId}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
>
|
|
117
|
+
<LineChart
|
|
118
|
+
months={months}
|
|
119
|
+
series={UTILIZATION_SERIES}
|
|
120
|
+
unit="consultancy.forecasts.unitHours"
|
|
121
|
+
empty="consultancy.forecasts.yearChartEmpty"
|
|
122
|
+
/>
|
|
123
|
+
</Panel>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
import { Button, ContextMenu, Dropdown, useLocale } from '@ossy/design-system'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
4
|
+
import { ListDashboards, PinWidget, UpdateDashboard } from '@ossy/dashboard'
|
|
5
|
+
|
|
6
|
+
function findPlacement (boards, componentId) {
|
|
7
|
+
for (const board of boards) {
|
|
8
|
+
const match = (board.widgets ?? []).find((widget) => widget.componentId === componentId)
|
|
9
|
+
if (match) return { dashboardId: board.id, widgetId: match.id }
|
|
10
|
+
}
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* More menu on a forecast panel. Pins the widget onto the default dashboard,
|
|
16
|
+
* or unpins the instance already on a dashboard.
|
|
17
|
+
*
|
|
18
|
+
* When the panel is rendered inside a dashboard, pass that board and widget id
|
|
19
|
+
* so unpin targets the instance on screen.
|
|
20
|
+
*/
|
|
21
|
+
export function ForecastWidgetMenu ({ componentId, dashboardId, pinnedWidgetId }) {
|
|
22
|
+
const sdk = useSdk()
|
|
23
|
+
const { t } = useLocale()
|
|
24
|
+
const [boards, setBoards] = useState(null)
|
|
25
|
+
const [busy, setBusy] = useState(false)
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
let cancelled = false
|
|
29
|
+
sdk.invoke(ListDashboards, { ensureDefault: false })
|
|
30
|
+
.then((data) => {
|
|
31
|
+
if (!cancelled) setBoards(Array.isArray(data?.items) ? data.items : [])
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
if (!cancelled) setBoards([])
|
|
35
|
+
})
|
|
36
|
+
return () => { cancelled = true }
|
|
37
|
+
}, [sdk])
|
|
38
|
+
|
|
39
|
+
const placement = (dashboardId && pinnedWidgetId)
|
|
40
|
+
? { dashboardId, widgetId: pinnedWidgetId }
|
|
41
|
+
: findPlacement(boards ?? [], componentId)
|
|
42
|
+
const pinned = Boolean(placement)
|
|
43
|
+
|
|
44
|
+
const toggle = async () => {
|
|
45
|
+
if (busy || boards == null) return
|
|
46
|
+
const board = (boards ?? []).find((item) => item.id === placement?.dashboardId)
|
|
47
|
+
if (pinned && !board) return
|
|
48
|
+
setBusy(true)
|
|
49
|
+
try {
|
|
50
|
+
if (pinned) {
|
|
51
|
+
const widgets = (board.widgets ?? []).filter((widget) => widget.id !== placement.widgetId)
|
|
52
|
+
await sdk.invoke(UpdateDashboard, { dashboardId: placement.dashboardId, widgets })
|
|
53
|
+
} else {
|
|
54
|
+
await sdk.invoke(PinWidget, { componentId })
|
|
55
|
+
}
|
|
56
|
+
const data = await sdk.invoke(ListDashboards, { ensureDefault: false })
|
|
57
|
+
setBoards(Array.isArray(data?.items) ? data.items : [])
|
|
58
|
+
} catch {
|
|
59
|
+
// Leave the menu on the previous pin state so the user can retry.
|
|
60
|
+
} finally {
|
|
61
|
+
setBusy(false)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<Dropdown
|
|
67
|
+
trigger={(
|
|
68
|
+
<Button
|
|
69
|
+
variant="command"
|
|
70
|
+
prefix="more-vertical-alt"
|
|
71
|
+
aria-label={t('consultancy.widgets.menu')}
|
|
72
|
+
title={t('consultancy.widgets.menu')}
|
|
73
|
+
data-forecast-widget-menu={componentId}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
>
|
|
77
|
+
<ContextMenu>
|
|
78
|
+
<ContextMenu.Item
|
|
79
|
+
prefix={pinned ? 'close' : 'pin'}
|
|
80
|
+
disabled={busy || boards == null || (pinned && !(boards ?? []).some((item) => item.id === placement.dashboardId))}
|
|
81
|
+
onClick={toggle}
|
|
82
|
+
data-forecast-widget-pin={pinned ? 'unpin' : 'pin'}
|
|
83
|
+
>
|
|
84
|
+
{pinned ? t('dashboard.unpin') : t('dashboard.actions.pinWidget')}
|
|
85
|
+
</ContextMenu.Item>
|
|
86
|
+
</ContextMenu>
|
|
87
|
+
</Dropdown>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getProjection } from '@ossy/event-store'
|
|
2
|
+
import { monthPoints } from './request-buckets.js'
|
|
3
|
+
import { RequestStatsProjection } from './request-stats.aggregate.js'
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
id: '@ossy/consultancy/tasks/get-request-stats',
|
|
7
|
+
audit: false,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function run ({ payload, req }) {
|
|
11
|
+
const workspaceId = payload?.workspaceId ?? req?.workspaceId
|
|
12
|
+
if (!workspaceId) {
|
|
13
|
+
throw Object.assign(new Error('workspaceId required'), { status: 400 })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const state = await getProjection(workspaceId, RequestStatsProjection.ProjectionId)
|
|
17
|
+
const byMonth = state?.byMonth ?? {}
|
|
18
|
+
const byWeek = state?.byWeek ?? {}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
workspaceId,
|
|
22
|
+
byMonth,
|
|
23
|
+
byWeek,
|
|
24
|
+
months: monthPoints(byMonth),
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { default as contractSchema } from './contract.schema.js'
|
|
|
5
5
|
export { default as companyBasicInfoSchema } from './company-basic-info.schema.js'
|
|
6
6
|
export { default as vacationSchema } from './vacation.schema.js'
|
|
7
7
|
export { default as opportunitySchema } from './opportunity.schema.js'
|
|
8
|
+
export { default as requestSchema } from './request.schema.js'
|
|
8
9
|
export { default as proposalSchema } from './proposal.schema.js'
|
|
9
10
|
export { Definition } from './Definition.js'
|
|
10
11
|
export { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Category the intake pipeline files as a consultancy request. */
|
|
2
|
+
export const REQUEST_CATEGORY = 'consultancy-request'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Below this, a consultancy-request label stays in the inbox.
|
|
6
|
+
* Jev's confidence is how concentrated the choice is.
|
|
7
|
+
*/
|
|
8
|
+
export const MIN_REQUEST_CONFIDENCE = 0.8
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Contrasting options so a contact, invoice, or receipt is not forced
|
|
12
|
+
* into a consultancy request. The chosen category is the only route.
|
|
13
|
+
*/
|
|
14
|
+
export const INTAKE_CATEGORIES = Object.freeze([
|
|
15
|
+
{
|
|
16
|
+
name: REQUEST_CATEGORY,
|
|
17
|
+
description: 'Someone is offering or asking for a consulting assignment, role, or engagement.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'invoice',
|
|
21
|
+
description: 'A bill asking to be paid, with an amount due.',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'receipt',
|
|
25
|
+
description: 'Proof that a payment was already made.',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'contact',
|
|
29
|
+
description: 'A general message, question, or introduction that is none of the above.',
|
|
30
|
+
},
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {{ category?: string | null, confidence?: number | null } | null | undefined} result
|
|
35
|
+
*/
|
|
36
|
+
export function acceptsRequestCategory (result) {
|
|
37
|
+
if (result?.category !== REQUEST_CATEGORY) return false
|
|
38
|
+
return typeof result.confidence === 'number' && result.confidence >= MIN_REQUEST_CONFIDENCE
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { DataLoader } from '@ossy/calendar'
|
|
3
|
+
import { KpiTrendPanel } from './forecast-panels.jsx'
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
id: '@ossy/consultancy/view/kpi-trend',
|
|
7
|
+
widget: {
|
|
8
|
+
title: 'consultancy.widgets.kpiTrend.title',
|
|
9
|
+
description: 'consultancy.widgets.kpiTrend.description',
|
|
10
|
+
ownsHeader: true,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Slot widget — fiscal-year KPI trend for dashboards. */
|
|
15
|
+
export default function KpiTrendWidget (props) {
|
|
16
|
+
return <DataLoader content={<KpiTrendPanel {...props} />} />
|
|
17
|
+
}
|