@ossy/consultancy 3.20.0 → 3.21.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/consultancy",
3
3
  "description": "Consultancy feature package — schemas, forecasts UI, and assignment margins",
4
- "version": "3.20.0",
4
+ "version": "3.21.0",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
7
7
  "module": "./src/index.js",
@@ -25,12 +25,13 @@
25
25
  "README.md"
26
26
  ],
27
27
  "dependencies": {
28
- "@ossy/schema": "^3.20.0"
28
+ "@ossy/schema": "^3.20.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@ossy/calendar": "*",
32
32
  "@ossy/dashboard": "*",
33
33
  "@ossy/design-system": "*",
34
+ "@ossy/resources": "*",
34
35
  "@ossy/router-react": "*",
35
36
  "@ossy/sdk-react": "*",
36
37
  "react": "*"
@@ -38,5 +39,5 @@
38
39
  "devDependencies": {
39
40
  "jest": "^30.2.0"
40
41
  },
41
- "gitHead": "edab6a966f41c07a68bdd86f3864cc2ad02e3406"
42
+ "gitHead": "f3eeb810cfdd6eb8be7951eb767669fa29a1b3d8"
42
43
  }
@@ -2,12 +2,32 @@ import React from 'react'
2
2
  import { Tabs } from '@ossy/design-system'
3
3
  import { useRouter } from '@ossy/router-react'
4
4
 
5
- /** Overview (home) first, Margins middle, Org Details last. */
5
+ /** Overview first, record lists, then Margins and Org Details. */
6
6
  const TABS = [
7
7
  {
8
8
  id: 'consultancy/home',
9
9
  label: 'consultancy.nav.overview',
10
10
  },
11
+ {
12
+ id: 'consultancy/employees',
13
+ label: 'consultancy.nav.employees',
14
+ },
15
+ {
16
+ id: 'consultancy/vacations',
17
+ label: 'consultancy.nav.vacations',
18
+ },
19
+ {
20
+ id: 'consultancy/contracts',
21
+ label: 'consultancy.nav.contracts',
22
+ },
23
+ {
24
+ id: 'consultancy/opportunities',
25
+ label: 'consultancy.nav.opportunities',
26
+ },
27
+ {
28
+ id: 'consultancy/proposals',
29
+ label: 'consultancy.nav.proposals',
30
+ },
11
31
  {
12
32
  id: 'consultancy/margins',
13
33
  label: 'consultancy.nav.margins',
@@ -34,6 +54,7 @@ export function ConsultancyNav ({ active }) {
34
54
  activeTabId={active}
35
55
  onTabClick={() => {}}
36
56
  data-consultancy-nav
57
+ style={{ height: 'auto', flexShrink: 0 }}
37
58
  />
38
59
  )
39
60
  }
@@ -0,0 +1,172 @@
1
+ import React, { useMemo } from 'react'
2
+ import { Icon, List, Page, Tags, Text, View, useLocale } from '@ossy/design-system'
3
+ import { AsyncStatus, useSdk } from '@ossy/sdk-react'
4
+ import { resourceIdOf } from '@ossy/calendar/holiday-locale'
5
+ import {
6
+ ListResources,
7
+ ListPanelLayout,
8
+ ResourcePanel,
9
+ listPanelPageProps,
10
+ useSelectedResourceId,
11
+ } from '@ossy/resources'
12
+ import { ConsultancyNav } from './ConsultancyNav.jsx'
13
+ import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
14
+ import { Definition } from './Definition.js'
15
+ import { location } from './locations.js'
16
+ import { ConsultancySchema } from './schema-ids.js'
17
+
18
+ function contentOf (resource) {
19
+ return resource?.content && typeof resource.content === 'object' ? resource.content : {}
20
+ }
21
+
22
+ function parseDay (value) {
23
+ if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
24
+ const [year, month, day] = value.slice(0, 10).split('-').map(Number)
25
+ if (year && month && day) return new Date(year, month - 1, day)
26
+ }
27
+ const date = new Date(value)
28
+ return Number.isNaN(date.getTime()) ? null : date
29
+ }
30
+
31
+ function formatDay (value, language) {
32
+ const date = parseDay(value)
33
+ if (!date) return ''
34
+ const locale = language === 'sv' ? 'sv-SE' : 'en'
35
+ return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date)
36
+ }
37
+
38
+ function vacationRange (resource, language) {
39
+ const content = contentOf(resource)
40
+ const start = formatDay(content.start, language)
41
+ const end = formatDay(content.end, language)
42
+ if (start && end && start !== end) return `${start} – ${end}`
43
+ return start || end || ''
44
+ }
45
+
46
+ function recordLabel (resource, language) {
47
+ if (resource?.type === ConsultancySchema.vacation) {
48
+ const range = vacationRange(resource, language)
49
+ if (range) return range
50
+ }
51
+ const content = contentOf(resource)
52
+ const name = resource?.name || content.name || content.title || content.clientName
53
+ if (typeof name === 'string' && name.trim()) return name.trim()
54
+ return resource?.id || ''
55
+ }
56
+
57
+ function recordMeta (resource, byId, language) {
58
+ const content = contentOf(resource)
59
+ if (resource?.type === ConsultancySchema.vacation) {
60
+ const employeeId = resourceIdOf(content.employeeId)
61
+ const employee = employeeId ? byId.get(employeeId) : null
62
+ return employee ? recordLabel(employee, language) : ''
63
+ }
64
+ const value = content.email || content.clientName || content.status
65
+ return typeof value === 'string' && value.trim() ? value.trim() : ''
66
+ }
67
+
68
+ /**
69
+ * Storage-style list of one consultancy schema, with the resource panel beside it.
70
+ */
71
+ export function ConsultancyRecordList ({ schemaId, icon, listHeader, emptyText }) {
72
+ const sdk = useSdk()
73
+ const { language } = useLocale()
74
+ const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
75
+ const { data: resources = [], status } = sdk.read(ListResources, { location })
76
+
77
+ const byId = useMemo(() => {
78
+ const list = Array.isArray(resources) ? resources : []
79
+ const map = new Map()
80
+ for (const resource of list) {
81
+ if (resource?.id) map.set(resource.id, resource)
82
+ const contentId = contentOf(resource).id
83
+ if (typeof contentId === 'string' && contentId.trim()) map.set(contentId.trim(), resource)
84
+ }
85
+ return map
86
+ }, [resources])
87
+
88
+ const rows = useMemo(() => {
89
+ const list = Array.isArray(resources) ? resources : []
90
+ return list
91
+ .filter((resource) => resource.type === schemaId)
92
+ .sort((a, b) => recordLabel(a, language).localeCompare(recordLabel(b, language)))
93
+ }, [resources, schemaId, language])
94
+
95
+ const loading = status === AsyncStatus.Loading || status === AsyncStatus.NotInitialized
96
+
97
+ return (
98
+ <ListPanelLayout
99
+ data-consultancy-records={schemaId}
100
+ listHeader={listHeader}
101
+ style={{ flex: '1 1 auto', minHeight: 0 }}
102
+ list={loading ? (
103
+ <View inset="m">
104
+ <Text color="secondary" text="consultancy.records.loading" />
105
+ </View>
106
+ ) : rows.length === 0 ? (
107
+ <View inset="m">
108
+ <Text color="secondary" text={emptyText} />
109
+ </View>
110
+ ) : (
111
+ <List>
112
+ {rows.map((resource) => {
113
+ const label = recordLabel(resource, language)
114
+ const meta = recordMeta(resource, byId, language)
115
+ return (
116
+ <List.Item
117
+ key={resource.id}
118
+ selectable
119
+ selected={resource.id === selectedResourceId}
120
+ onClick={() => setSelectedResourceId(resource.id)}
121
+ data-resource-name={label || undefined}
122
+ leading={(
123
+ <Icon size="s" name={icon || 'file'} style={{ fill: 'hsl(0, 0%, 80%)' }} />
124
+ )}
125
+ meta={meta ? <Text variant="small">{meta}</Text> : null}
126
+ >
127
+ {label}
128
+ </List.Item>
129
+ )
130
+ })}
131
+ </List>
132
+ )}
133
+ panel={selectedResourceId
134
+ ? <ResourcePanel width="100%" resourceId={selectedResourceId} onClose={clearSelectedResourceId} />
135
+ : null}
136
+ />
137
+ )
138
+ }
139
+
140
+ export function ConsultancyRecordPage ({
141
+ active,
142
+ title,
143
+ description,
144
+ schemaId,
145
+ icon,
146
+ listHeader,
147
+ emptyText,
148
+ }) {
149
+ const statusTags = (Definition.status ?? [])
150
+ .map((status) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[status]))
151
+ .filter(Boolean)
152
+
153
+ return (
154
+ <Page
155
+ {...listPanelPageProps}
156
+ title={title}
157
+ near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
158
+ description={description}
159
+ far={<CreateConsultancyButton />}
160
+ >
161
+ <View gap="m" style={{ flex: '1 1 auto', height: '100%', minHeight: 0, display: 'flex', flexDirection: 'column' }}>
162
+ <ConsultancyNav active={active} />
163
+ <ConsultancyRecordList
164
+ schemaId={schemaId}
165
+ icon={icon}
166
+ listHeader={listHeader}
167
+ emptyText={emptyText}
168
+ />
169
+ </View>
170
+ </Page>
171
+ )
172
+ }
@@ -1,7 +1,22 @@
1
1
  import React from 'react'
2
- import { Button, useLocale } from '@ossy/design-system'
2
+ import { Button, ContextMenu, Dropdown, View, useLocale } from '@ossy/design-system'
3
3
  import { useRouter } from '@ossy/router-react'
4
4
  import { location } from './locations.js'
5
+ import companyBasicInfoSchema from './company-basic-info.schema.js'
6
+ import employeeSchema from './employee.schema.js'
7
+ import contractSchema from './contract.schema.js'
8
+ import vacationSchema from './vacation.schema.js'
9
+ import opportunitySchema from './opportunity.schema.js'
10
+ import proposalSchema from './proposal.schema.js'
11
+
12
+ const ADD_TYPES = [
13
+ { schema: companyBasicInfoSchema, label: 'consultancy.add.company' },
14
+ { schema: employeeSchema, label: 'consultancy.add.employee' },
15
+ { schema: contractSchema, label: 'consultancy.add.contract' },
16
+ { schema: opportunitySchema, label: 'consultancy.add.opportunity' },
17
+ { schema: proposalSchema, label: 'consultancy.add.proposal' },
18
+ { schema: vacationSchema, label: 'consultancy.add.vacation' },
19
+ ]
5
20
 
6
21
  function currentReturnTo (href) {
7
22
  const raw = typeof href === 'string' && href
@@ -21,26 +36,59 @@ function currentReturnTo (href) {
21
36
  }
22
37
  }
23
38
 
39
+ function createHref (router, schemaId) {
40
+ const params = new URLSearchParams({ location, category: 'Consultancy' })
41
+ if (schemaId) params.set('schemaId', schemaId)
42
+ const returnTo = currentReturnTo(router.href)
43
+ if (returnTo) params.set('returnTo', returnTo)
44
+ return router.getHref(`@create-document?${params.toString()}`)
45
+ }
46
+
24
47
  /**
25
- * Add CTA that opens the generic create-document form for consultancy schemas.
48
+ * Add CTA for consultancy schemas.
49
+ * Without `schemaId`, opens a dropdown of document types instead of the type-picker page.
50
+ * With `schemaId`, links straight to that type's create form.
26
51
  * @param {{ schemaId?: string }} [props]
27
52
  */
28
53
  export function CreateConsultancyButton ({ schemaId, ...props }) {
29
54
  const { t } = useLocale()
30
55
  const router = useRouter()
31
- const params = new URLSearchParams({ location, category: 'Consultancy' })
32
- if (schemaId) params.set('schemaId', schemaId)
33
- const returnTo = currentReturnTo(router.href)
34
- if (returnTo) params.set('returnTo', returnTo)
56
+
57
+ if (schemaId) {
58
+ return (
59
+ <Button
60
+ variant="cta"
61
+ prefix="add"
62
+ href={createHref(router, schemaId)}
63
+ {...props}
64
+ >
65
+ {t('design-system.add')}
66
+ </Button>
67
+ )
68
+ }
35
69
 
36
70
  return (
37
- <Button
38
- variant="cta"
39
- prefix="add"
40
- href={router.getHref(`@create-document?${params.toString()}`)}
41
- {...props}
71
+ <Dropdown
72
+ trigger={(
73
+ <Button variant="cta" prefix="add" {...props}>
74
+ {t('design-system.add')}
75
+ </Button>
76
+ )}
42
77
  >
43
- {t('design-system.add')}
44
- </Button>
78
+ <View inset="xs" surface="primary" roundness="s">
79
+ <ContextMenu roundness="s" surface="primary">
80
+ {ADD_TYPES.map(({ schema, label }) => (
81
+ <ContextMenu.Item
82
+ key={schema.id}
83
+ prefix={schema.icon || 'add'}
84
+ href={createHref(router, schema.id)}
85
+ data-schema-id={schema.id}
86
+ >
87
+ {t(label)}
88
+ </ContextMenu.Item>
89
+ ))}
90
+ </ContextMenu>
91
+ </View>
92
+ </Dropdown>
45
93
  )
46
94
  }
package/src/Forecast.jsx CHANGED
@@ -1,7 +1,10 @@
1
1
  import React, { useMemo } from 'react'
2
2
  import { View, Text, Separator, useLocale } from '@ossy/design-system'
3
- import { CalendarDaySurfaceStyles, sumFiscalYearTotals, useForecast } from '@ossy/calendar'
3
+ import { CalendarDaySurfaceStyles, sumFiscalYearTotals, useContracts, useEmployees, useForecast, useVacations } from '@ossy/calendar'
4
+ import { ListResources } from '@ossy/resources'
5
+ import { useSdk } from '@ossy/sdk-react'
4
6
  import { buildKpiChartLayout } from './forecast-kpi-chart.js'
7
+ import { TIMESHEET_LOCATION, TIMESHEET_TYPE, withUtilizationHours } from './utilization-hours.js'
5
8
 
6
9
  const grid = {
7
10
  width: '100%',
@@ -35,13 +38,42 @@ const calendarDayLayout = {
35
38
  }
36
39
 
37
40
  const KPI_SERIES = [
38
- // --color-primary is paper white in Cloud themes; income must stay visible on surface-primary.
39
- { key: 'projectedIncome', label: 'consultancy.forecasts.income', color: 'var(--color-info, hsl(199, 89%, 43%))' },
40
- { key: 'monthlyCostOfEmployees', label: 'consultancy.forecasts.salaryCost', color: 'var(--color-warning, hsl(38, 92%, 50%))' },
41
- { key: 'revenue', label: 'consultancy.forecasts.revenue', color: 'var(--color-accent, hsl(167, 89%, 43%))' },
42
- { key: 'hoursWorked', label: 'consultancy.forecasts.hoursWorked', color: 'var(--fg-secondary, hsl(220, 10%, 45%))', dashed: true },
41
+ // Contract forecast is dashed. Timesheet actuals are solid. Same color pairs the two.
42
+ { key: 'projectedIncome', label: 'consultancy.forecasts.forecastIncome', color: 'var(--color-info, hsl(199, 89%, 43%))', dashed: true },
43
+ { key: 'actualIncome', label: 'consultancy.forecasts.actualIncome', color: 'var(--color-info, hsl(199, 89%, 43%))' },
44
+ { key: 'monthlyCostOfEmployees', label: 'consultancy.forecasts.salaryCost', color: 'var(--color-warning, hsl(38, 92%, 50%))', dashed: true },
45
+ { key: 'revenue', label: 'consultancy.forecasts.forecastRevenue', color: 'var(--color-accent, hsl(167, 89%, 43%))', dashed: true },
46
+ { key: 'actualRevenue', label: 'consultancy.forecasts.actualRevenue', color: 'var(--color-accent, hsl(167, 89%, 43%))' },
43
47
  ]
44
48
 
49
+ const UTILIZATION_SERIES = [
50
+ { key: 'forecastHours', label: 'consultancy.forecasts.forecastHours', color: 'var(--color-info, hsl(199, 89%, 43%))', scale: 'hours', dashed: true },
51
+ { key: 'actualHours', label: 'consultancy.forecasts.actualHours', color: 'var(--color-accent, hsl(167, 89%, 43%))', scale: 'hours' },
52
+ ]
53
+
54
+ function ChartAxisLabel ({ x, y, viewWidth, viewHeight, children }) {
55
+ return (
56
+ <Text
57
+ as="span"
58
+ variant="small"
59
+ data-chart-axis-label=""
60
+ style={{
61
+ position: 'absolute',
62
+ left: `${(x / viewWidth) * 100}%`,
63
+ top: `${(y / viewHeight) * 100}%`,
64
+ transform: 'translate(-50%, -100%)',
65
+ margin: 0,
66
+ opacity: 0.75,
67
+ lineHeight: 1,
68
+ whiteSpace: 'nowrap',
69
+ pointerEvents: 'none',
70
+ }}
71
+ >
72
+ {children}
73
+ </Text>
74
+ )
75
+ }
76
+
45
77
  function SectionPanel ({ title, children }) {
46
78
  return (
47
79
  <View surface="primary" roundness="xs" style={{ minWidth: 0, overflow: 'hidden', height: '100%' }}>
@@ -69,15 +101,14 @@ function SectionPanel ({ title, children }) {
69
101
  }
70
102
 
71
103
  /**
72
- * Hand-rolled multi-series line chart for fiscal-year KPIs.
104
+ * Hand-rolled multi-series line chart.
73
105
  * Matches the no-dependency SVG approach from analytics DailyBarChart (#917).
74
- * Money KPIs share one Y-scale; hours use a secondary scale (dashed stroke).
75
106
  */
76
- function ForecastKpiChart ({ months }) {
77
- const { language } = useLocale()
107
+ function ForecastKpiChart ({ months, series, unit }) {
108
+ const { language, t } = useLocale()
78
109
  const chart = useMemo(
79
- () => buildKpiChartLayout({ months, series: KPI_SERIES, language }),
80
- [months, language],
110
+ () => buildKpiChartLayout({ months, series, language }),
111
+ [months, series, language],
81
112
  )
82
113
 
83
114
  if (!chart) {
@@ -90,40 +121,114 @@ function ForecastKpiChart ({ months }) {
90
121
 
91
122
  return (
92
123
  <View gap="s" inset="m" style={{ width: '100%' }}>
124
+ <View layout="row-wrap" gap="m" style={{ alignItems: 'center', justifyContent: 'space-between' }}>
93
125
  <View layout="row-wrap" gap="m" style={{ alignItems: 'center' }}>
94
- {KPI_SERIES.map((series) => (
95
- <View key={series.key} layout="row" gap="s" style={{ alignItems: 'center' }}>
126
+ {series.map((entry) => (
127
+ <View key={entry.key} layout="row" gap="s" style={{ alignItems: 'center' }}>
96
128
  <span
97
129
  aria-hidden
98
130
  style={{
99
131
  width: 10,
100
132
  height: 10,
101
133
  borderRadius: 2,
102
- background: series.color,
134
+ background: entry.color,
103
135
  display: 'inline-block',
104
136
  flexShrink: 0,
105
- ...(series.dashed
137
+ ...(entry.dashed
106
138
  ? {
107
139
  background: 'transparent',
108
- borderTop: `2px dashed ${series.color}`,
140
+ borderTop: `2px dashed ${entry.color}`,
109
141
  height: 0,
110
142
  borderRadius: 0,
111
143
  }
112
144
  : null),
113
145
  }}
114
146
  />
115
- <Text variant="small" style={{ marginBottom: 0 }} text={series.label} />
147
+ <Text variant="small" style={{ marginBottom: 0 }} text={entry.label} />
116
148
  </View>
117
149
  ))}
118
150
  </View>
151
+ {unit ? (
152
+ <Text
153
+ as="span"
154
+ variant="small"
155
+ data-consultancy-chart-unit=""
156
+ text={unit}
157
+ style={{ marginBottom: 0 }}
158
+ />
159
+ ) : null}
160
+ </View>
161
+ <div style={{ display: 'flex', alignItems: 'stretch', width: '100%', gap: 4 }}>
162
+ {chart.yTicks.length > 0 ? (
163
+ <div style={{ position: 'relative', flex: '0 0 auto' }}>
164
+ <div aria-hidden style={{ display: 'grid' }}>
165
+ {chart.yTicks.map((tick) => (
166
+ <Text
167
+ key={`tick-size-${tick.value}`}
168
+ as="span"
169
+ variant="small"
170
+ style={{
171
+ gridArea: '1 / 1',
172
+ visibility: 'hidden',
173
+ margin: 0,
174
+ lineHeight: 1,
175
+ whiteSpace: 'nowrap',
176
+ }}
177
+ >
178
+ {tick.label}
179
+ </Text>
180
+ ))}
181
+ </div>
182
+ {chart.yTicks.map((tick) => (
183
+ <Text
184
+ key={`tick-label-${tick.value}`}
185
+ as="span"
186
+ variant="small"
187
+ data-consultancy-chart-tick={tick.label}
188
+ style={{
189
+ position: 'absolute',
190
+ right: 0,
191
+ top: `${(tick.y / chart.viewHeight) * 100}%`,
192
+ transform: 'translateY(-50%)',
193
+ margin: 0,
194
+ opacity: 0.75,
195
+ lineHeight: 1,
196
+ whiteSpace: 'nowrap',
197
+ pointerEvents: 'none',
198
+ }}
199
+ >
200
+ {tick.label}
201
+ </Text>
202
+ ))}
203
+ </div>
204
+ ) : null}
205
+ <div style={{ position: 'relative', flex: '1 1 auto', minWidth: 0 }}>
119
206
  <svg
120
207
  data-consultancy-kpi-chart
121
208
  viewBox={`0 0 ${chart.viewWidth} ${chart.viewHeight}`}
122
209
  width="100%"
123
- height={chart.viewHeight}
124
- style={{ display: 'block', width: '100%' }}
125
- preserveAspectRatio="none"
210
+ role="img"
211
+ aria-label={unit ? t(unit) : undefined}
212
+ style={{
213
+ display: 'block',
214
+ width: '100%',
215
+ height: 'auto',
216
+ aspectRatio: `${chart.viewWidth} / ${chart.viewHeight}`,
217
+ }}
218
+ preserveAspectRatio="xMidYMid meet"
126
219
  >
220
+ {chart.yTicks.map((tick) => (
221
+ <line
222
+ key={`tick-${tick.value}`}
223
+ x1={tick.x1}
224
+ x2={tick.x2}
225
+ y1={tick.y}
226
+ y2={tick.y}
227
+ stroke="currentColor"
228
+ strokeOpacity="0.15"
229
+ vectorEffect="non-scaling-stroke"
230
+ />
231
+ ))}
127
232
  {chart.seriesPaths.map((series) => (
128
233
  series.path ? (
129
234
  <path
@@ -134,30 +239,39 @@ function ForecastKpiChart ({ months }) {
134
239
  strokeWidth={2}
135
240
  strokeLinejoin="round"
136
241
  strokeLinecap="round"
137
- strokeDasharray={series.dashed ? '4 3' : undefined}
242
+ strokeDasharray={series.dashed ? '6 4' : undefined}
138
243
  vectorEffect="non-scaling-stroke"
139
244
  />
140
245
  ) : null
141
246
  ))}
142
- {chart.monthLabels.map((label) => (
143
- <text
144
- key={`month-${label.index}`}
145
- data-consultancy-kpi-month={label.label}
146
- x={label.x}
147
- y={label.y}
148
- textAnchor="middle"
149
- fill="var(--fg-secondary, currentColor)"
150
- fontSize={7}
151
- style={{ opacity: 0.75 }}
152
- >
153
- {label.label}
154
- </text>
155
- ))}
156
247
  </svg>
248
+ {chart.monthLabels.map((label) => (
249
+ <ChartAxisLabel
250
+ key={`month-${label.index}`}
251
+ x={label.x}
252
+ y={label.y}
253
+ viewWidth={chart.viewWidth}
254
+ viewHeight={chart.viewHeight}
255
+ >
256
+ <span data-consultancy-kpi-month={label.label}>{label.label}</span>
257
+ </ChartAxisLabel>
258
+ ))}
259
+ </div>
260
+ </div>
157
261
  </View>
158
262
  )
159
263
  }
160
264
 
265
+ function UtilizationPanel ({ months }) {
266
+ const { t } = useLocale()
267
+
268
+ return (
269
+ <SectionPanel title={t('consultancy.forecasts.utilization')}>
270
+ <ForecastKpiChart months={months} series={UTILIZATION_SERIES} unit="consultancy.forecasts.unitHours" />
271
+ </SectionPanel>
272
+ )
273
+ }
274
+
161
275
  function YearSummary ({ months, money, hours }) {
162
276
  const { t } = useLocale()
163
277
  const totals = useMemo(() => sumFiscalYearTotals(months), [months])
@@ -171,7 +285,7 @@ function YearSummary ({ months, money, hours }) {
171
285
  >
172
286
  <View style={{ flex: '2 1 320px', minWidth: 0 }}>
173
287
  <SectionPanel title={t('consultancy.forecasts.yearChart')}>
174
- <ForecastKpiChart months={months} />
288
+ <ForecastKpiChart months={months} series={KPI_SERIES} unit="consultancy.forecasts.unitMoney" />
175
289
  </SectionPanel>
176
290
  </View>
177
291
  <View style={{ flex: '1 1 240px', minWidth: 0 }}>
@@ -202,6 +316,19 @@ function YearSummary ({ months, money, hours }) {
202
316
 
203
317
  export const Forecast = () => {
204
318
  const months = useForecast()
319
+ const contracts = useContracts()
320
+ const employees = useEmployees()
321
+ const vacations = useVacations()
322
+ const sdk = useSdk()
323
+ const { data: timesheetResources = [] } = sdk.read(ListResources, { location: TIMESHEET_LOCATION })
324
+ const chartMonths = useMemo(() => withUtilizationHours({
325
+ months,
326
+ timesheets: (Array.isArray(timesheetResources) ? timesheetResources : [])
327
+ .filter((resource) => resource.type === TIMESHEET_TYPE),
328
+ vacations,
329
+ employees,
330
+ contracts,
331
+ }), [months, timesheetResources, vacations, employees, contracts])
205
332
  const { language } = useLocale()
206
333
  const money = (value) => new Intl.NumberFormat(language === 'sv' ? 'sv-SE' : 'en-SE', { style: "currency", currency: "SEK" }).format(value)
207
334
  const hours = (value) => new Intl.NumberFormat(language === 'sv' ? 'sv-SE' : 'en-GB', { style: "unit", unit: "hour" }).format(value)
@@ -217,7 +344,8 @@ export const Forecast = () => {
217
344
  `}
218
345
  </style>
219
346
  <View gap="m" style={{ width: '100%' }}>
220
- <YearSummary months={months} money={money} hours={hours} />
347
+ <YearSummary months={chartMonths} money={money} hours={hours} />
348
+ <UtilizationPanel months={chartMonths} />
221
349
  <div style={grid}>
222
350
 
223
351
  {months.map(month => {
@@ -0,0 +1,26 @@
1
+ import React from 'react'
2
+ import { ConsultancyRecordPage } from './ConsultancyRecordList.jsx'
3
+ import { ConsultancySchema } from './schema-ids.js'
4
+ import contractSchema from './contract.schema.js'
5
+
6
+ export const metadata = {
7
+ id: 'consultancy/contracts',
8
+ path: {
9
+ sv: '/konsultverksamhet/avtal',
10
+ en: '/consultancy/contracts',
11
+ },
12
+ }
13
+
14
+ export const ContractsPage = () => (
15
+ <ConsultancyRecordPage
16
+ active="consultancy/contracts"
17
+ title="consultancy.contracts.title"
18
+ description="consultancy.contracts.description"
19
+ schemaId={ConsultancySchema.contract}
20
+ icon={contractSchema.icon}
21
+ listHeader="consultancy.nav.contracts"
22
+ emptyText="consultancy.contracts.empty"
23
+ />
24
+ )
25
+
26
+ export default ContractsPage