@ossy/consultancy 3.21.0 → 3.23.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.
Files changed (43) hide show
  1. package/package.json +4 -2
  2. package/src/AssignmentMarginCalculator.jsx +7 -32
  3. package/src/ConsultancyNav.jsx +17 -9
  4. package/src/Forecast.jsx +33 -384
  5. package/src/MonthDayGrid.jsx +68 -0
  6. package/src/Overview.jsx +10 -31
  7. package/src/RequestStatsPanel.jsx +66 -0
  8. package/src/consultancy.page.jsx +3 -40
  9. package/src/current-month.component.jsx +47 -25
  10. package/src/en.translations.json +52 -2
  11. package/src/extract-request.action.js +5 -0
  12. package/src/extract-request.task.js +117 -0
  13. package/src/extract-request.task.spec.js +131 -0
  14. package/src/forecast-panels.jsx +125 -0
  15. package/src/forecast-widget-menu.jsx +89 -0
  16. package/src/get-request-stats.action.js +6 -0
  17. package/src/get-request-stats.task.js +26 -0
  18. package/src/index.js +1 -0
  19. package/src/intake-categories.js +39 -0
  20. package/src/kpi-trend.component.jsx +17 -0
  21. package/src/margin-panels.jsx +7 -32
  22. package/src/org.page.jsx +1 -2
  23. package/src/reports.page.jsx +103 -0
  24. package/src/request-buckets.js +76 -0
  25. package/src/request-buckets.spec.js +33 -0
  26. package/src/request-stats.aggregate.js +52 -0
  27. package/src/request-stats.aggregate.spec.js +34 -0
  28. package/src/request-stats.component.jsx +16 -0
  29. package/src/request.schema.js +29 -0
  30. package/src/requests.page.jsx +26 -0
  31. package/src/resume-inbound-screening.task.js +77 -0
  32. package/src/resume-inbound-screening.task.spec.js +68 -0
  33. package/src/schema-ids.js +1 -0
  34. package/src/screen-inbound.task.js +133 -0
  35. package/src/screen-inbound.task.spec.js +154 -0
  36. package/src/sv.translations.json +52 -2
  37. package/src/use-chart-months.js +27 -0
  38. package/src/utilization-hours.js +21 -3
  39. package/src/utilization-hours.spec.js +23 -0
  40. package/src/utilization.component.jsx +17 -0
  41. package/src/year-totals.component.jsx +17 -0
  42. package/src/forecast-kpi-chart.js +0 -184
  43. package/src/forecast-kpi-chart.spec.js +0 -159
@@ -0,0 +1,34 @@
1
+ import { RequestStatsProjection } from './request-stats.aggregate.js'
2
+ import { ConsultancySchema } from './schema-ids.js'
3
+
4
+ describe('RequestStatsProjection', () => {
5
+ it('counts a request in the email month and week, not the import week', () => {
6
+ const state = RequestStatsProjection.Apply({
7
+ type: ConsultancySchema.request,
8
+ event: 'Created',
9
+ created: Date.parse('2026-10-17T08:00:00.000Z'),
10
+ payload: {
11
+ belongsTo: 'ws-1',
12
+ content: { receivedAt: '2023-04-15T10:00:00.000Z' },
13
+ },
14
+ }, RequestStatsProjection.initialState('ws-1'))
15
+
16
+ expect(state.byMonth).toEqual({ '2023-04': 1 })
17
+ expect(state.byWeek).toEqual({ '2023-W15': 1 })
18
+ })
19
+
20
+ it('adds a second email in the same month', () => {
21
+ const first = RequestStatsProjection.Apply({
22
+ created: 1,
23
+ payload: { belongsTo: 'ws-1', content: { receivedAt: '2023-04-02T00:00:00.000Z' } },
24
+ }, RequestStatsProjection.initialState('ws-1'))
25
+ const second = RequestStatsProjection.Apply({
26
+ created: 2,
27
+ payload: { belongsTo: 'ws-1', content: { receivedAt: '2023-04-20T00:00:00.000Z' } },
28
+ }, first)
29
+
30
+ expect(second.byMonth['2023-04']).toBe(2)
31
+ expect(second.byWeek['2023-W13']).toBe(1)
32
+ expect(second.byWeek['2023-W16']).toBe(1)
33
+ })
34
+ })
@@ -0,0 +1,16 @@
1
+ import React from 'react'
2
+ import { RequestStatsPanel } from './RequestStatsPanel.jsx'
3
+
4
+ export const metadata = {
5
+ id: '@ossy/consultancy/view/request-stats',
6
+ widget: {
7
+ title: 'consultancy.widgets.requestStats.title',
8
+ description: 'consultancy.widgets.requestStats.description',
9
+ span: 8,
10
+ ownsHeader: true,
11
+ },
12
+ }
13
+
14
+ export default function RequestStatsWidget (props) {
15
+ return <RequestStatsPanel {...props} />
16
+ }
@@ -0,0 +1,29 @@
1
+ import { ConsultancySchema } from './schema-ids.js'
2
+
3
+ /**
4
+ * A consultancy request is the assignment described in an inbound email
5
+ * (role, duration, where, who wrote). It is not an Opportunity.
6
+ * Opportunity is the sales pipeline after someone qualifies the request
7
+ * (status, fit, next action, linked proposal).
8
+ */
9
+ export default {
10
+ name: 'Request',
11
+ id: ConsultancySchema.request,
12
+ categoryName: 'Consultancy',
13
+ icon: 'mail',
14
+ fields: [
15
+ { name: 'title', type: 'text', required: true, description: 'Assignment title' },
16
+ { name: 'summary', type: 'textarea', description: 'What the client is asking for' },
17
+ { name: 'role', type: 'text', description: 'Profile they are looking for' },
18
+ { name: 'skills', type: 'textarea', description: 'Skills or technologies named in the request' },
19
+ { name: 'location', type: 'text', description: 'Where the work happens' },
20
+ { name: 'duration', type: 'text', description: 'How long the assignment lasts, in the message\'s own words' },
21
+ { name: 'start', type: 'text', description: 'When the assignment starts, in the message\'s own words' },
22
+ { name: 'rate', type: 'number', description: 'Numeric amount only, without a currency symbol. Omit when the message states no rate.' },
23
+ { name: 'currency', type: 'select', options: ['SEK', 'EUR', 'USD', 'NOK', 'DKK'], description: 'Currency of the rate. Omit when the message states no rate.' },
24
+ { name: 'contactName', type: 'text', description: 'Person who sent the request' },
25
+ { name: 'contactEmail', type: 'email', description: 'Email address of that person. Omit when the message has none.' },
26
+ { name: 'messageId', type: 'text', description: 'Message-ID of the inbound email' },
27
+ { name: 'receivedAt', type: 'text', description: 'ISO-8601 arrival time from the email Date header. Omit; the pipeline copies it.' },
28
+ ],
29
+ }
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import { ConsultancyRecordPage } from './ConsultancyRecordList.jsx'
3
+ import { ConsultancySchema } from './schema-ids.js'
4
+ import requestSchema from './request.schema.js'
5
+
6
+ export const metadata = {
7
+ id: 'consultancy/requests',
8
+ path: {
9
+ sv: '/konsultverksamhet/forfragningar',
10
+ en: '/consultancy/requests',
11
+ },
12
+ }
13
+
14
+ export const RequestsPage = () => (
15
+ <ConsultancyRecordPage
16
+ active="consultancy/requests"
17
+ title="consultancy.requests.title"
18
+ description="consultancy.requests.description"
19
+ schemaId={ConsultancySchema.request}
20
+ icon={requestSchema.icon}
21
+ listHeader="consultancy.nav.requests"
22
+ emptyText="consultancy.requests.empty"
23
+ />
24
+ )
25
+
26
+ export default RequestsPage
@@ -0,0 +1,77 @@
1
+ import { run as screenInbound } from './screen-inbound.task.js'
2
+ import { acceptsRequestCategory } from './intake-categories.js'
3
+
4
+ const ListResources = { id: '@ossy/resources/actions/list' }
5
+ const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
6
+ const INBOUND_LOCATION = '/@ossy/email/inbound/'
7
+ const MAX_AGE_MS = 14 * 24 * 60 * 60 * 1000
8
+ const MAX_PER_PASS = 20
9
+
10
+ export const metadata = {
11
+ id: '@ossy/consultancy/tasks/resume-inbound-screening',
12
+ schedule: '*/5 * * * *',
13
+ }
14
+
15
+ function asResourceList (result) {
16
+ if (Array.isArray(result)) return result
17
+ if (Array.isArray(result?.items)) return result.items
18
+ return []
19
+ }
20
+
21
+ /**
22
+ * A message still needs screening when it has no request and no finished
23
+ * intake label. A confident request label with no request means extraction
24
+ * died and should be run again.
25
+ *
26
+ * @param {object | null | undefined} resource
27
+ * @param {number} [now]
28
+ */
29
+ export function needsInboundScreening (resource, now = Date.now()) {
30
+ if (resource?.type !== INBOUND_MESSAGE) return false
31
+ const content = resource.content && typeof resource.content === 'object' ? resource.content : {}
32
+ if (content.requestId) return false
33
+ const received = Date.parse(content.receivedAt || '')
34
+ if (!Number.isNaN(received) && now - received > MAX_AGE_MS) return false
35
+ if (!Object.hasOwn(content, 'intakeCategory')) return true
36
+ return acceptsRequestCategory({
37
+ category: content.intakeCategory,
38
+ confidence: content.intakeConfidence,
39
+ })
40
+ }
41
+
42
+ /**
43
+ * Finish inbound mail whose screening was interrupted. One pass per workspace.
44
+ */
45
+ export async function run ({ payload, req, sdk, log }) {
46
+ if (!sdk?.invoke) throw Object.assign(new Error('sdk is required'), { status: 500 })
47
+
48
+ const workspaceId = payload?.workspaceId || req?.workspaceId
49
+ if (!workspaceId) throw Object.assign(new Error('workspaceId is required'), { status: 400 })
50
+
51
+ const listed = await sdk.invoke(ListResources, {
52
+ location: INBOUND_LOCATION,
53
+ workspaceId,
54
+ })
55
+ const pending = asResourceList(listed)
56
+ .filter((resource) => needsInboundScreening(resource))
57
+ .slice(0, MAX_PER_PASS)
58
+
59
+ let screened = 0
60
+ let failed = 0
61
+ for (const message of pending) {
62
+ try {
63
+ await screenInbound({
64
+ event: { resourceId: message.id, payload: { belongsTo: workspaceId } },
65
+ payload: { resourceId: message.id, workspaceId },
66
+ req,
67
+ sdk,
68
+ })
69
+ screened += 1
70
+ } catch (error) {
71
+ failed += 1
72
+ log?.error('[consultancy/tasks/resume-inbound-screening] message failed', { resourceId: message.id }, error)
73
+ }
74
+ }
75
+
76
+ return { screened, failed }
77
+ }
@@ -0,0 +1,68 @@
1
+ import { metadata, needsInboundScreening, run } from './resume-inbound-screening.task.js'
2
+ import { REQUEST_CATEGORY } from './intake-categories.js'
3
+
4
+ const message = {
5
+ id: 'msg-1',
6
+ type: '@ossy/email/schema/inbound-message',
7
+ content: {
8
+ from: 'client@studio.se',
9
+ subject: 'SDK',
10
+ text: 'Vi behöver en specialist.',
11
+ receivedAt: '2026-10-17T17:56:46.000Z',
12
+ },
13
+ }
14
+
15
+ describe('resume-inbound-screening', () => {
16
+ it('runs every five minutes', () => {
17
+ expect(metadata.schedule).toBe('*/5 * * * *')
18
+ })
19
+
20
+ it('selects mail that never finished screening', () => {
21
+ const now = Date.parse('2026-10-17T19:00:00.000Z')
22
+ expect(needsInboundScreening(message, now)).toBe(true)
23
+ expect(needsInboundScreening({
24
+ ...message,
25
+ content: { ...message.content, intakeCategory: 'contact', intakeConfidence: 0.9 },
26
+ }, now)).toBe(false)
27
+ expect(needsInboundScreening({
28
+ ...message,
29
+ content: { ...message.content, intakeCategory: REQUEST_CATEGORY, intakeConfidence: 1 },
30
+ }, now)).toBe(true)
31
+ expect(needsInboundScreening({
32
+ ...message,
33
+ content: { ...message.content, requestId: 'request-1' },
34
+ }, now)).toBe(false)
35
+ expect(needsInboundScreening({
36
+ ...message,
37
+ content: { ...message.content, receivedAt: '2026-01-01T00:00:00.000Z' },
38
+ }, now)).toBe(false)
39
+ })
40
+
41
+ it('screens only the unfinished message', async () => {
42
+ const calls = []
43
+ const settled = {
44
+ ...message,
45
+ id: 'msg-settled',
46
+ content: { ...message.content, intakeCategory: 'contact', intakeConfidence: 1 },
47
+ }
48
+ const sdk = {
49
+ async invoke (action, payload) {
50
+ calls.push({ id: action.id, payload })
51
+ if (action.id === '@ossy/resources/actions/list') return [settled, message]
52
+ if (action.id === '@ossy/resources/actions/get') return message
53
+ if (action.id === '@ossy/media-tasks/actions/categorize') return { category: 'contact', confidence: 0.95 }
54
+ if (action.id === '@ossy/resources/actions/update-content') return { ...message, content: payload.content }
55
+ throw new Error(`unexpected ${action.id}`)
56
+ },
57
+ }
58
+
59
+ const result = await run({
60
+ payload: { workspaceId: 'ws-1' },
61
+ sdk,
62
+ })
63
+
64
+ expect(result).toEqual({ screened: 1, failed: 0 })
65
+ const gets = calls.filter((call) => call.id === '@ossy/resources/actions/get')
66
+ expect(gets.map((call) => call.payload.resourceId)).toEqual(['msg-1'])
67
+ })
68
+ })
package/src/schema-ids.js CHANGED
@@ -5,5 +5,6 @@ export const ConsultancySchema = Object.freeze({
5
5
  employee: '@ossy/consultancy/schema/employee',
6
6
  vacation: '@ossy/consultancy/schema/vacation',
7
7
  opportunity: '@ossy/consultancy/schema/opportunity',
8
+ request: '@ossy/consultancy/schema/request',
8
9
  proposal: '@ossy/consultancy/schema/proposal',
9
10
  })
@@ -0,0 +1,133 @@
1
+ import { forwardedOriginalFromMessage } from '@ossy/email/forwarded-original'
2
+ import { location } from './locations.js'
3
+ import { ConsultancySchema } from './schema-ids.js'
4
+ import { requestSourceText } from './extract-request.task.js'
5
+ import {
6
+ INTAKE_CATEGORIES,
7
+ acceptsRequestCategory,
8
+ } from './intake-categories.js'
9
+
10
+ const GetResource = { id: '@ossy/resources/actions/get' }
11
+ const UpdateContent = { id: '@ossy/resources/actions/update-content' }
12
+ const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
13
+ const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
14
+ const INBOUND_MESSAGE = '@ossy/email/schema/inbound-message'
15
+
16
+ export const metadata = {
17
+ id: '@ossy/consultancy/tasks/screen-inbound',
18
+ triggers: [
19
+ {
20
+ type: INBOUND_MESSAGE,
21
+ event: 'Created',
22
+ },
23
+ ],
24
+ outputs: [
25
+ {
26
+ name: 'request',
27
+ kind: 'location',
28
+ schemaId: ConsultancySchema.request,
29
+ prefix: location,
30
+ },
31
+ ],
32
+ }
33
+
34
+ function fail (message, status) {
35
+ throw Object.assign(new Error(message), { status })
36
+ }
37
+
38
+ function workspaceIdFrom ({ event, payload, req }) {
39
+ return event?.payload?.belongsTo
40
+ ?? event?.belongsTo
41
+ ?? payload?.workspaceId
42
+ ?? req?.workspaceId
43
+ ?? null
44
+ }
45
+
46
+ async function saveContent (sdk, resource, workspaceId, patch) {
47
+ const content = { ...resource.content, ...patch }
48
+ const updated = await sdk.invoke(UpdateContent, {
49
+ resourceId: resource.id,
50
+ workspaceId,
51
+ content,
52
+ })
53
+ return updated?.content ? updated : { ...resource, content }
54
+ }
55
+
56
+ /**
57
+ * A forward stores the person who clicked forward as From. Replace that with
58
+ * the sender inside the forwarded block, and remember who forwarded it.
59
+ */
60
+ async function withOriginalSender (sdk, resource, workspaceId) {
61
+ const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
62
+ if (content.forwardedBy) return resource
63
+ const forward = forwardedOriginalFromMessage(content)
64
+ if (!forward?.from) return resource
65
+ return saveContent(sdk, resource, workspaceId, {
66
+ from: forward.from,
67
+ forwardedBy: content.from || '',
68
+ ...(forward.subject ? { subject: forward.subject } : {}),
69
+ ...(forward.receivedAt ? { receivedAt: forward.receivedAt } : {}),
70
+ })
71
+ }
72
+
73
+ /**
74
+ * New inbound mail is categorized first. A consultancy request is extracted.
75
+ * The outcome is stored on the message so a later pass can finish a run that
76
+ * died before the request was saved. Anything else stays in the inbox.
77
+ */
78
+ export async function run ({ event, payload, req, sdk }) {
79
+ if (!sdk?.invoke) fail('sdk is required', 500)
80
+
81
+ const resourceId = event?.resourceId || payload?.resourceId
82
+ if (!resourceId) fail('resourceId is required', 400)
83
+
84
+ const workspaceId = workspaceIdFrom({ event, payload, req })
85
+ if (!workspaceId) fail('workspaceId is required', 400)
86
+
87
+ let resource = await sdk.invoke(GetResource, { resourceId })
88
+ if (resource?.type !== INBOUND_MESSAGE) fail('inbound message is required', 400)
89
+ if (resource.content?.requestId) {
90
+ return { skipped: false, requestId: resource.content.requestId, category: resource.content.intakeCategory ?? null }
91
+ }
92
+
93
+ resource = await withOriginalSender(sdk, resource, workspaceId)
94
+
95
+ const alreadyScreened = Object.hasOwn(resource.content ?? {}, 'intakeCategory')
96
+ let category = typeof resource.content?.intakeCategory === 'string' ? resource.content.intakeCategory : null
97
+ let confidence = typeof resource.content?.intakeConfidence === 'number' ? resource.content.intakeConfidence : null
98
+
99
+ if (!alreadyScreened) {
100
+ const text = requestSourceText(resource)
101
+ if (!text) {
102
+ return { skipped: true, reason: 'empty', category: null, confidence: null }
103
+ }
104
+
105
+ const categorized = await sdk.invoke(Categorize, {
106
+ workspaceId,
107
+ text,
108
+ categories: INTAKE_CATEGORIES,
109
+ })
110
+ category = typeof categorized?.category === 'string' ? categorized.category : null
111
+ confidence = typeof categorized?.confidence === 'number' ? categorized.confidence : null
112
+ resource = await saveContent(sdk, resource, workspaceId, {
113
+ intakeCategory: category,
114
+ intakeConfidence: confidence,
115
+ })
116
+ }
117
+
118
+ if (!acceptsRequestCategory({ category, confidence })) {
119
+ return { skipped: true, reason: 'category', category, confidence }
120
+ }
121
+
122
+ const request = await sdk.invoke(ExtractRequest, { resourceId, workspaceId })
123
+ const requestId = request?.id ?? null
124
+ if (requestId) {
125
+ await saveContent(sdk, resource, workspaceId, { requestId })
126
+ }
127
+ return {
128
+ skipped: false,
129
+ category,
130
+ confidence,
131
+ requestId,
132
+ }
133
+ }
@@ -0,0 +1,154 @@
1
+ import { metadata, run } from './screen-inbound.task.js'
2
+ import { INTAKE_CATEGORIES, REQUEST_CATEGORY } from './intake-categories.js'
3
+ import { requestSourceText } from './extract-request.task.js'
4
+
5
+ const GetResource = { id: '@ossy/resources/actions/get' }
6
+ const UpdateContent = { id: '@ossy/resources/actions/update-content' }
7
+ const Categorize = { id: '@ossy/media-tasks/actions/categorize' }
8
+ const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
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
+ subject: 'Senior React, 6 manader',
16
+ text: 'Vi soker en senior React-utvecklare i Stockholm.',
17
+ messageId: 'assignment-1@client.se',
18
+ },
19
+ }
20
+
21
+ function sdkFor (categorized, source = inbound) {
22
+ let current = { ...source, content: { ...source.content } }
23
+ const calls = []
24
+ const sdk = {
25
+ async invoke (action, payload) {
26
+ calls.push({ id: action.id, payload })
27
+ if (action.id === GetResource.id) return current
28
+ if (action.id === UpdateContent.id) {
29
+ current = { ...current, content: payload.content }
30
+ return current
31
+ }
32
+ if (action.id === Categorize.id) return categorized
33
+ if (action.id === ExtractRequest.id) return { id: 'request-1' }
34
+ throw new Error(`unexpected ${action.id}`)
35
+ },
36
+ }
37
+ return { calls, sdk }
38
+ }
39
+
40
+ describe('screen-inbound task', () => {
41
+ it('listens for a new inbound message', () => {
42
+ expect(metadata.triggers).toEqual([
43
+ { type: '@ossy/email/schema/inbound-message', event: 'Created' },
44
+ ])
45
+ })
46
+
47
+ it('extracts a request when the category is a confident consultancy request', async () => {
48
+ const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 1 })
49
+ const result = await run({
50
+ event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
51
+ sdk,
52
+ })
53
+
54
+ const categorize = calls.find((call) => call.id === Categorize.id)
55
+ expect(categorize.payload).toMatchObject({
56
+ workspaceId: 'ws-1',
57
+ text: requestSourceText(inbound),
58
+ categories: INTAKE_CATEGORIES,
59
+ })
60
+ expect(calls.map((call) => call.id)).toEqual([
61
+ GetResource.id,
62
+ Categorize.id,
63
+ UpdateContent.id,
64
+ ExtractRequest.id,
65
+ UpdateContent.id,
66
+ ])
67
+ expect(calls.find((call) => call.id === ExtractRequest.id).payload).toEqual({
68
+ resourceId: inbound.id,
69
+ workspaceId: 'ws-1',
70
+ })
71
+ expect(calls.filter((call) => call.id === UpdateContent.id).at(-1).payload.content.requestId).toBe('request-1')
72
+ expect(result).toEqual({
73
+ skipped: false,
74
+ category: REQUEST_CATEGORY,
75
+ confidence: 1,
76
+ requestId: 'request-1',
77
+ })
78
+ })
79
+
80
+ it('leaves a contact message in the inbox', async () => {
81
+ const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 })
82
+ const result = await run({
83
+ event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
84
+ sdk,
85
+ })
86
+
87
+ expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
88
+ expect(calls.find((call) => call.id === UpdateContent.id).payload.content.intakeCategory).toBe('contact')
89
+ expect(result).toEqual({
90
+ skipped: true,
91
+ reason: 'category',
92
+ category: 'contact',
93
+ confidence: 0.99,
94
+ })
95
+ })
96
+
97
+ it('leaves a low-confidence consultancy request in the inbox', async () => {
98
+ const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 0.4 })
99
+ const result = await run({
100
+ event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
101
+ sdk,
102
+ })
103
+
104
+ expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
105
+ expect(result).toMatchObject({ skipped: true, reason: 'category', confidence: 0.4 })
106
+ })
107
+
108
+ it('extracts again when a confident label was saved and the request was not', async () => {
109
+ const { calls, sdk } = sdkFor(null, {
110
+ ...inbound,
111
+ content: {
112
+ ...inbound.content,
113
+ intakeCategory: REQUEST_CATEGORY,
114
+ intakeConfidence: 1,
115
+ },
116
+ })
117
+ const result = await run({
118
+ event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
119
+ sdk,
120
+ })
121
+
122
+ expect(calls.map((call) => call.id)).not.toContain(Categorize.id)
123
+ expect(calls.map((call) => call.id)).toContain(ExtractRequest.id)
124
+ expect(result.requestId).toBe('request-1')
125
+ })
126
+
127
+ it('stores the original sender before screening a forward', async () => {
128
+ const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 }, {
129
+ ...inbound,
130
+ content: {
131
+ ...inbound.content,
132
+ from: 'oskars.sylwan@ossy.se',
133
+ subject: 'Fwd: Senior React',
134
+ text: [
135
+ '---------- Forwarded message ---------',
136
+ 'From: Recruiter <recruiter@client.se>',
137
+ 'Subject: Senior React',
138
+ '',
139
+ 'Vi soker en senior React-utvecklare i Stockholm.',
140
+ ].join('\n'),
141
+ },
142
+ })
143
+
144
+ await run({
145
+ event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
146
+ sdk,
147
+ })
148
+
149
+ const firstSave = calls.find((call) => call.id === UpdateContent.id)
150
+ expect(firstSave.payload.content.from).toBe('recruiter@client.se')
151
+ expect(firstSave.payload.content.forwardedBy).toBe('oskars.sylwan@ossy.se')
152
+ expect(firstSave.payload.content.subject).toBe('Senior React')
153
+ })
154
+ })
@@ -6,6 +6,8 @@
6
6
  "consultancy/vacations.documentTitle": "Semester",
7
7
  "consultancy/contracts.documentTitle": "Avtal",
8
8
  "consultancy/opportunities.documentTitle": "Möjligheter",
9
+ "consultancy/requests.documentTitle": "Förfrågningar",
10
+ "consultancy/reports.documentTitle": "Rapporter",
9
11
  "consultancy/proposals.documentTitle": "Offerter",
10
12
  "consultancy.home.title": "Översikt",
11
13
  "consultancy.home.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
@@ -17,8 +19,10 @@
17
19
  "consultancy.nav.employees": "Anställda",
18
20
  "consultancy.nav.vacations": "Semester",
19
21
  "consultancy.nav.contracts": "Avtal",
22
+ "consultancy.nav.requests": "Förfrågningar",
20
23
  "consultancy.nav.opportunities": "Möjligheter",
21
24
  "consultancy.nav.proposals": "Offerter",
25
+ "consultancy.nav.reports": "Rapporter",
22
26
  "consultancy.nav.margins": "Marginaler",
23
27
  "consultancy.forecasts.title": "Översikt",
24
28
  "consultancy.forecasts.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
@@ -68,6 +72,16 @@
68
72
  "consultancy.contracts.title": "Avtal",
69
73
  "consultancy.contracts.description": "Kunduppdrag och timpriser",
70
74
  "consultancy.contracts.empty": "Inga avtal ännu.",
75
+ "consultancy.requests.title": "Förfrågningar",
76
+ "consultancy.requests.description": "Uppdrag tolkade från inkommande e-post",
77
+ "consultancy.requests.empty": "Inga förfrågningar ännu.",
78
+ "consultancy.requests.statsTitle": "Inkommande förfrågningar",
79
+ "consultancy.requests.statsSeries": "Förfrågningar",
80
+ "consultancy.requests.statsUnit": "förfrågningar",
81
+ "consultancy.requests.statsEmpty": "Inga daterade förfrågningar ännu.",
82
+ "consultancy.reports.title": "Rapporter",
83
+ "consultancy.reports.description": "Diagram över inkommande arbete",
84
+ "consultancy.reports.empty": "Inga rapporter ännu.",
71
85
  "consultancy.opportunities.title": "Möjligheter",
72
86
  "consultancy.opportunities.description": "Pipeline med möjliga uppdrag",
73
87
  "consultancy.opportunities.empty": "Inga möjligheter ännu.",
@@ -151,6 +165,32 @@
151
165
  "@ossy/consultancy/schema/vacation.start.description": "Första semesterdagen (inklusive). De här dagarna faktureras inte.",
152
166
  "@ossy/consultancy/schema/vacation.end.label": "Sista lediga dagen",
153
167
  "@ossy/consultancy/schema/vacation.end.description": "Sista semesterdagen (inklusive).",
168
+ "@ossy/consultancy/schema/request.title.label": "Titel",
169
+ "@ossy/consultancy/schema/request.title.description": "Uppdragets titel.",
170
+ "@ossy/consultancy/schema/request.summary.label": "Sammanfattning",
171
+ "@ossy/consultancy/schema/request.summary.description": "Vad kunden frågar efter.",
172
+ "@ossy/consultancy/schema/request.role.label": "Roll",
173
+ "@ossy/consultancy/schema/request.role.description": "Profilen de söker.",
174
+ "@ossy/consultancy/schema/request.skills.label": "Kompetenser",
175
+ "@ossy/consultancy/schema/request.skills.description": "Kompetenser eller tekniker som nämns.",
176
+ "@ossy/consultancy/schema/request.location.label": "Plats",
177
+ "@ossy/consultancy/schema/request.location.description": "Var arbetet sker.",
178
+ "@ossy/consultancy/schema/request.duration.label": "Längd",
179
+ "@ossy/consultancy/schema/request.duration.description": "Hur länge uppdraget pågår.",
180
+ "@ossy/consultancy/schema/request.start.label": "Start",
181
+ "@ossy/consultancy/schema/request.start.description": "När uppdraget startar.",
182
+ "@ossy/consultancy/schema/request.rate.label": "Arvode",
183
+ "@ossy/consultancy/schema/request.rate.description": "Belopp utan valutasymbol.",
184
+ "@ossy/consultancy/schema/request.currency.label": "Valuta",
185
+ "@ossy/consultancy/schema/request.currency.description": "Valuta för arvodet.",
186
+ "@ossy/consultancy/schema/request.contactName.label": "Kontaktperson",
187
+ "@ossy/consultancy/schema/request.contactName.description": "Personen som skickade förfrågan.",
188
+ "@ossy/consultancy/schema/request.contactEmail.label": "Kontaktens e-post",
189
+ "@ossy/consultancy/schema/request.contactEmail.description": "Personens e-postadress.",
190
+ "@ossy/consultancy/schema/request.messageId.label": "Meddelande-id",
191
+ "@ossy/consultancy/schema/request.messageId.description": "Id på det inkommande mejlet.",
192
+ "@ossy/consultancy/schema/request.receivedAt.label": "Mottaget",
193
+ "@ossy/consultancy/schema/request.receivedAt.description": "När mejlet skickades.",
154
194
  "@ossy/consultancy/schema/opportunity.title.label": "Titel",
155
195
  "@ossy/consultancy/schema/opportunity.title.description": "Kort namn på leadet eller möjligheten.",
156
196
  "@ossy/consultancy/schema/opportunity.source.label": "Källa",
@@ -187,7 +227,8 @@
187
227
  "@ossy/consultancy/schema/proposal.body.description": "Hela anbudstexten.",
188
228
  "consultancy.nav.orgDetails": "Orgdetaljer",
189
229
  "consultancy.forecasts.yearChart": "KPI-trend",
190
- "consultancy.forecasts.yearSummary": "Totalsummor för räkenskapsåret",
230
+ "consultancy.forecasts.monthForecast": "{month} prognos",
231
+ "consultancy.forecasts.yearSummary": "Räkenskapsåret prognos",
191
232
  "consultancy.forecasts.yearChartEmpty": "Inga prognosmånader att visa ännu.",
192
233
  "consultancy.margins.pin.done": "Nålad på instrumentpanel",
193
234
  "consultancy.margins.pin.error": "Nålning misslyckades — försök igen",
@@ -202,5 +243,14 @@
202
243
  "consultancy.widgets.adminLeakage.title": "Adminläckage",
203
244
  "consultancy.widgets.adminLeakage.description": "Årliga timmar och intäkter som går förlorade på återkommande admin.",
204
245
  "consultancy.widgets.forecastCurrentMonth.title": "Prognos denna månad",
205
- "consultancy.widgets.forecastCurrentMonth.description": "Prognostiserad intäkt, lönekostnad, omsättning och timmar för innevarande månad."
246
+ "consultancy.widgets.forecastCurrentMonth.description": "Prognostiserad intäkt, lönekostnad, omsättning och timmar för innevarande månad.",
247
+ "consultancy.widgets.kpiTrend.title": "KPI-trend",
248
+ "consultancy.widgets.kpiTrend.description": "Prognos och utfall för intäkt, lönekostnad och omsättning under räkenskapsåret.",
249
+ "consultancy.widgets.yearTotals.title": "Räkenskapsåret prognos",
250
+ "consultancy.widgets.yearTotals.description": "Intäkt, lönekostnad, omsättning och timmar för räkenskapsåret.",
251
+ "consultancy.widgets.utilization.title": "Beläggning",
252
+ "consultancy.widgets.utilization.description": "Prognostiserade och faktiska timmar under räkenskapsåret.",
253
+ "consultancy.widgets.requestStats.title": "Inkommande förfrågningar",
254
+ "consultancy.widgets.requestStats.description": "Förfrågningar per månad, daterade efter e-postens egen ankomsttid.",
255
+ "consultancy.widgets.menu": "Mer"
206
256
  }
@@ -0,0 +1,27 @@
1
+ import { useMemo } from 'react'
2
+ import { useContracts, useEmployees, useForecast, useVacations } from '@ossy/calendar'
3
+ import { ListResources } from '@ossy/resources'
4
+ import { useSdk } from '@ossy/sdk-react'
5
+ import { TIMESHEET_LOCATION, TIMESHEET_TYPE, withUtilizationHours } from './utilization-hours.js'
6
+
7
+ /**
8
+ * Fiscal-year months with timesheet actuals merged in.
9
+ * Shared by the overview and the pinnable forecast widgets.
10
+ */
11
+ export function useChartMonths () {
12
+ const months = useForecast()
13
+ const contracts = useContracts()
14
+ const employees = useEmployees()
15
+ const vacations = useVacations()
16
+ const sdk = useSdk()
17
+ const { data: timesheetResources = [] } = sdk.read(ListResources, { location: TIMESHEET_LOCATION })
18
+
19
+ return useMemo(() => withUtilizationHours({
20
+ months,
21
+ timesheets: (Array.isArray(timesheetResources) ? timesheetResources : [])
22
+ .filter((resource) => resource.type === TIMESHEET_TYPE),
23
+ vacations,
24
+ employees,
25
+ contracts,
26
+ }), [months, timesheetResources, vacations, employees, contracts])
27
+ }