@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
|
@@ -0,0 +1,97 @@
|
|
|
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 Categorize = { id: '@ossy/media-tasks/actions/categorize' }
|
|
7
|
+
const ExtractRequest = { id: '@ossy/consultancy/actions/extract-request' }
|
|
8
|
+
|
|
9
|
+
const inbound = {
|
|
10
|
+
id: 'msg-1',
|
|
11
|
+
type: '@ossy/email/schema/inbound-message',
|
|
12
|
+
content: {
|
|
13
|
+
from: 'Anna Berg <anna@client.se>',
|
|
14
|
+
subject: 'Senior React, 6 manader',
|
|
15
|
+
text: 'Vi soker en senior React-utvecklare i Stockholm.',
|
|
16
|
+
messageId: 'assignment-1@client.se',
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function sdkFor (categorized) {
|
|
21
|
+
const calls = []
|
|
22
|
+
const sdk = {
|
|
23
|
+
async invoke (action, payload) {
|
|
24
|
+
calls.push({ id: action.id, payload })
|
|
25
|
+
if (action.id === GetResource.id) return inbound
|
|
26
|
+
if (action.id === Categorize.id) return categorized
|
|
27
|
+
if (action.id === ExtractRequest.id) return { id: 'request-1' }
|
|
28
|
+
throw new Error(`unexpected ${action.id}`)
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
return { calls, sdk }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('screen-inbound task', () => {
|
|
35
|
+
it('listens for a new inbound message', () => {
|
|
36
|
+
expect(metadata.triggers).toEqual([
|
|
37
|
+
{ type: '@ossy/email/schema/inbound-message', event: 'Created' },
|
|
38
|
+
])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('extracts a request when the category is a confident consultancy request', async () => {
|
|
42
|
+
const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 1 })
|
|
43
|
+
const result = await run({
|
|
44
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
45
|
+
sdk,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const categorize = calls.find((call) => call.id === Categorize.id)
|
|
49
|
+
expect(categorize.payload).toMatchObject({
|
|
50
|
+
workspaceId: 'ws-1',
|
|
51
|
+
text: requestSourceText(inbound),
|
|
52
|
+
categories: INTAKE_CATEGORIES,
|
|
53
|
+
})
|
|
54
|
+
expect(calls.map((call) => call.id)).toEqual([
|
|
55
|
+
GetResource.id,
|
|
56
|
+
Categorize.id,
|
|
57
|
+
ExtractRequest.id,
|
|
58
|
+
])
|
|
59
|
+
expect(calls.find((call) => call.id === ExtractRequest.id).payload).toEqual({
|
|
60
|
+
resourceId: inbound.id,
|
|
61
|
+
workspaceId: 'ws-1',
|
|
62
|
+
})
|
|
63
|
+
expect(result).toEqual({
|
|
64
|
+
skipped: false,
|
|
65
|
+
category: REQUEST_CATEGORY,
|
|
66
|
+
confidence: 1,
|
|
67
|
+
requestId: 'request-1',
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('leaves a contact message in the inbox', async () => {
|
|
72
|
+
const { calls, sdk } = sdkFor({ category: 'contact', confidence: 0.99 })
|
|
73
|
+
const result = await run({
|
|
74
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
75
|
+
sdk,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
|
|
79
|
+
expect(result).toEqual({
|
|
80
|
+
skipped: true,
|
|
81
|
+
reason: 'category',
|
|
82
|
+
category: 'contact',
|
|
83
|
+
confidence: 0.99,
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('leaves a low-confidence consultancy request in the inbox', async () => {
|
|
88
|
+
const { calls, sdk } = sdkFor({ category: REQUEST_CATEGORY, confidence: 0.4 })
|
|
89
|
+
const result = await run({
|
|
90
|
+
event: { resourceId: inbound.id, payload: { belongsTo: 'ws-1' } },
|
|
91
|
+
sdk,
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
expect(calls.map((call) => call.id)).not.toContain(ExtractRequest.id)
|
|
95
|
+
expect(result).toMatchObject({ skipped: true, reason: 'category', confidence: 0.4 })
|
|
96
|
+
})
|
|
97
|
+
})
|
package/src/sv.translations.json
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
"consultancy/home.documentTitle": "Översikt",
|
|
3
3
|
"consultancy/org.documentTitle": "Orgdetaljer",
|
|
4
4
|
"consultancy/margins.documentTitle": "Marginaler",
|
|
5
|
+
"consultancy/employees.documentTitle": "Anställda",
|
|
6
|
+
"consultancy/vacations.documentTitle": "Semester",
|
|
7
|
+
"consultancy/contracts.documentTitle": "Avtal",
|
|
8
|
+
"consultancy/opportunities.documentTitle": "Möjligheter",
|
|
9
|
+
"consultancy/requests.documentTitle": "Förfrågningar",
|
|
10
|
+
"consultancy/reports.documentTitle": "Rapporter",
|
|
11
|
+
"consultancy/proposals.documentTitle": "Offerter",
|
|
5
12
|
"consultancy.home.title": "Översikt",
|
|
6
13
|
"consultancy.home.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
|
|
7
14
|
"consultancy.org.title": "Orgdetaljer",
|
|
@@ -9,13 +16,29 @@
|
|
|
9
16
|
"consultancy.nav.title": "Konsultverksamhet",
|
|
10
17
|
"consultancy.nav.overview": "Översikt",
|
|
11
18
|
"consultancy.nav.forecasts": "Prognoser",
|
|
19
|
+
"consultancy.nav.employees": "Anställda",
|
|
20
|
+
"consultancy.nav.vacations": "Semester",
|
|
21
|
+
"consultancy.nav.contracts": "Avtal",
|
|
22
|
+
"consultancy.nav.requests": "Förfrågningar",
|
|
23
|
+
"consultancy.nav.opportunities": "Möjligheter",
|
|
24
|
+
"consultancy.nav.proposals": "Offerter",
|
|
25
|
+
"consultancy.nav.reports": "Rapporter",
|
|
12
26
|
"consultancy.nav.margins": "Marginaler",
|
|
13
27
|
"consultancy.forecasts.title": "Översikt",
|
|
14
28
|
"consultancy.forecasts.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
|
|
15
29
|
"consultancy.forecasts.income": "Intäkt",
|
|
30
|
+
"consultancy.forecasts.forecastIncome": "Prognostiserad intäkt",
|
|
31
|
+
"consultancy.forecasts.actualIncome": "Faktisk intäkt",
|
|
32
|
+
"consultancy.forecasts.forecastRevenue": "Prognostiserat resultat",
|
|
33
|
+
"consultancy.forecasts.actualRevenue": "Faktiskt resultat",
|
|
16
34
|
"consultancy.forecasts.salaryCost": "Lönekostnad",
|
|
17
35
|
"consultancy.forecasts.revenue": "Resultat",
|
|
18
36
|
"consultancy.forecasts.hoursWorked": "Arbetade timmar",
|
|
37
|
+
"consultancy.forecasts.utilization": "Beläggning",
|
|
38
|
+
"consultancy.forecasts.forecastHours": "Prognostiserade timmar",
|
|
39
|
+
"consultancy.forecasts.actualHours": "Faktiska timmar",
|
|
40
|
+
"consultancy.forecasts.unitMoney": "kr",
|
|
41
|
+
"consultancy.forecasts.unitHours": "tim",
|
|
19
42
|
"consultancy.margins.title": "Marginaler",
|
|
20
43
|
"consultancy.margins.description": "Se uppdragets marginal och adminläckage innan du fakturerar",
|
|
21
44
|
"consultancy.margins.notes.purpose": "Byggt för nordiska IT-konsultbolag som vuxit ur timer + kalkylark men inte behöver ett tungt PSA.",
|
|
@@ -40,6 +63,38 @@
|
|
|
40
63
|
"consultancy.overview.fiscalYears": "Räkenskapsår",
|
|
41
64
|
"consultancy.overview.company": "Företag",
|
|
42
65
|
"consultancy.overview.noFiscalYears": "Inga räkenskapsår ännu.",
|
|
66
|
+
"consultancy.employees.title": "Anställda",
|
|
67
|
+
"consultancy.employees.description": "Personer i konsultverksamheten",
|
|
68
|
+
"consultancy.employees.empty": "Inga anställda ännu.",
|
|
69
|
+
"consultancy.vacations.title": "Semester",
|
|
70
|
+
"consultancy.vacations.description": "Ledighet som inte faktureras",
|
|
71
|
+
"consultancy.vacations.empty": "Ingen semester ännu.",
|
|
72
|
+
"consultancy.contracts.title": "Avtal",
|
|
73
|
+
"consultancy.contracts.description": "Kunduppdrag och timpriser",
|
|
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.",
|
|
85
|
+
"consultancy.opportunities.title": "Möjligheter",
|
|
86
|
+
"consultancy.opportunities.description": "Pipeline med möjliga uppdrag",
|
|
87
|
+
"consultancy.opportunities.empty": "Inga möjligheter ännu.",
|
|
88
|
+
"consultancy.proposals.title": "Offerter",
|
|
89
|
+
"consultancy.proposals.description": "Offerter skickade för möjligheter",
|
|
90
|
+
"consultancy.proposals.empty": "Inga offerter ännu.",
|
|
91
|
+
"consultancy.records.loading": "Laddar…",
|
|
92
|
+
"consultancy.add.company": "Företag",
|
|
93
|
+
"consultancy.add.employee": "Anställd",
|
|
94
|
+
"consultancy.add.contract": "Avtal",
|
|
95
|
+
"consultancy.add.opportunity": "Möjlighet",
|
|
96
|
+
"consultancy.add.proposal": "Offert",
|
|
97
|
+
"consultancy.add.vacation": "Semester",
|
|
43
98
|
"consultancy.empty.title": "Här är tomt",
|
|
44
99
|
"consultancy.empty.text": "Lägg till företagsinfo, anställda, avtal och semester för att komma igång.",
|
|
45
100
|
"@ossy/consultancy/form/calculator.label": "Uppdragsmarginalkalkylator",
|
|
@@ -146,7 +201,8 @@
|
|
|
146
201
|
"@ossy/consultancy/schema/proposal.body.description": "Hela anbudstexten.",
|
|
147
202
|
"consultancy.nav.orgDetails": "Orgdetaljer",
|
|
148
203
|
"consultancy.forecasts.yearChart": "KPI-trend",
|
|
149
|
-
"consultancy.forecasts.
|
|
204
|
+
"consultancy.forecasts.monthForecast": "{month} prognos",
|
|
205
|
+
"consultancy.forecasts.yearSummary": "Räkenskapsåret prognos",
|
|
150
206
|
"consultancy.forecasts.yearChartEmpty": "Inga prognosmånader att visa ännu.",
|
|
151
207
|
"consultancy.margins.pin.done": "Nålad på instrumentpanel",
|
|
152
208
|
"consultancy.margins.pin.error": "Nålning misslyckades — försök igen",
|
|
@@ -161,5 +217,14 @@
|
|
|
161
217
|
"consultancy.widgets.adminLeakage.title": "Adminläckage",
|
|
162
218
|
"consultancy.widgets.adminLeakage.description": "Årliga timmar och intäkter som går förlorade på återkommande admin.",
|
|
163
219
|
"consultancy.widgets.forecastCurrentMonth.title": "Prognos denna månad",
|
|
164
|
-
"consultancy.widgets.forecastCurrentMonth.description": "Prognostiserad intäkt, lönekostnad, omsättning och timmar för innevarande månad."
|
|
220
|
+
"consultancy.widgets.forecastCurrentMonth.description": "Prognostiserad intäkt, lönekostnad, omsättning och timmar för innevarande månad.",
|
|
221
|
+
"consultancy.widgets.kpiTrend.title": "KPI-trend",
|
|
222
|
+
"consultancy.widgets.kpiTrend.description": "Prognos och utfall för intäkt, lönekostnad och omsättning under räkenskapsåret.",
|
|
223
|
+
"consultancy.widgets.yearTotals.title": "Räkenskapsåret prognos",
|
|
224
|
+
"consultancy.widgets.yearTotals.description": "Intäkt, lönekostnad, omsättning och timmar för räkenskapsåret.",
|
|
225
|
+
"consultancy.widgets.utilization.title": "Beläggning",
|
|
226
|
+
"consultancy.widgets.utilization.description": "Prognostiserade och faktiska timmar under räkenskapsåret.",
|
|
227
|
+
"consultancy.widgets.requestStats.title": "Inkommande förfrågningar",
|
|
228
|
+
"consultancy.widgets.requestStats.description": "Förfrågningar per månad, daterade efter e-postens egen ankomsttid.",
|
|
229
|
+
"consultancy.widgets.menu": "Mer"
|
|
165
230
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { isDayInInclusiveRange, localDayKey, resourceIdOf, utcDayKey } from '@ossy/calendar/holiday-locale'
|
|
2
|
+
|
|
3
|
+
/** Timesheet documents used for beläggning actuals. */
|
|
4
|
+
export const TIMESHEET_LOCATION = '/@ossy/timesheets/sheets/'
|
|
5
|
+
export const TIMESHEET_TYPE = '@ossy/timesheets/schema/timesheet'
|
|
6
|
+
|
|
7
|
+
function contentOf (resource) {
|
|
8
|
+
if (resource?.content && typeof resource.content === 'object') {
|
|
9
|
+
return { ...resource.content, id: resource.id ?? resource.content.id }
|
|
10
|
+
}
|
|
11
|
+
return resource ?? {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function padMonth (monthNumber) {
|
|
15
|
+
return String(monthNumber).padStart(2, '0')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Local calendar month of a timesheet line date.
|
|
20
|
+
* Timesheet rows are stored as local-midnight timestamps.
|
|
21
|
+
*
|
|
22
|
+
* @param {unknown} value
|
|
23
|
+
* @returns {{ year: string, monthNumber: string } | null}
|
|
24
|
+
*/
|
|
25
|
+
export function localMonthOf (value) {
|
|
26
|
+
if (value == null || value === '') return null
|
|
27
|
+
const date = value instanceof Date ? value : new Date(value)
|
|
28
|
+
if (Number.isNaN(date.getTime())) return null
|
|
29
|
+
return {
|
|
30
|
+
year: String(date.getFullYear()),
|
|
31
|
+
monthNumber: padMonth(date.getMonth() + 1),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function dayKeysForLine (employeeId, lineDate) {
|
|
36
|
+
if (!employeeId) return []
|
|
37
|
+
const keys = []
|
|
38
|
+
const utc = utcDayKey(lineDate)
|
|
39
|
+
if (utc) keys.push(`${employeeId}:${utc}`)
|
|
40
|
+
const date = lineDate instanceof Date ? lineDate : new Date(lineDate)
|
|
41
|
+
if (!Number.isNaN(date.getTime())) keys.push(`${employeeId}:${localDayKey(date)}`)
|
|
42
|
+
return keys
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function contractRecord (contract) {
|
|
46
|
+
if (contract?.content && typeof contract.content === 'object') {
|
|
47
|
+
return { ...contract.content, id: contract.id ?? contract.content.id }
|
|
48
|
+
}
|
|
49
|
+
return contract ?? {}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Hourly rate for a timesheet. Prefer its contract, then the employee's contract.
|
|
54
|
+
*
|
|
55
|
+
* @param {object} content
|
|
56
|
+
* @param {Array<object>} contracts
|
|
57
|
+
* @returns {number}
|
|
58
|
+
*/
|
|
59
|
+
function hourlyRateForSheet (content, contracts) {
|
|
60
|
+
const list = Array.isArray(contracts) ? contracts.map(contractRecord) : []
|
|
61
|
+
const contractId = resourceIdOf(content.contractId)
|
|
62
|
+
const employeeId = resourceIdOf(content.employeeId)
|
|
63
|
+
const contract = (contractId && list.find((entry) => entry.id === contractId))
|
|
64
|
+
|| (employeeId && list.find((entry) => resourceIdOf(entry.employeeId) === employeeId))
|
|
65
|
+
|| null
|
|
66
|
+
const rate = Number(contract?.hourlyCompensation)
|
|
67
|
+
return Number.isFinite(rate) ? rate : 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function lineInMonth (lineDate, month) {
|
|
71
|
+
const local = localMonthOf(lineDate)
|
|
72
|
+
if (!local) return false
|
|
73
|
+
return local.year === String(month.year) && local.monthNumber === padMonth(month.monthNumber)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Actual hours for one fiscal month.
|
|
78
|
+
*
|
|
79
|
+
* Timesheet line hours in the month are the reported actuals. Vacation is
|
|
80
|
+
* included by adding the employee's work hours for each vacation workday that
|
|
81
|
+
* has no timesheet line yet, so an unlogged vacation still counts.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} options
|
|
84
|
+
* @param {{ year?: number|string, monthNumber?: number|string, days?: Array<{ date: string, isWorkday?: boolean }> }} options.month
|
|
85
|
+
* @param {Array<object>} [options.timesheets]
|
|
86
|
+
* @param {Array<object>} [options.vacations]
|
|
87
|
+
* @param {Array<object>} [options.employees]
|
|
88
|
+
* @returns {number}
|
|
89
|
+
*/
|
|
90
|
+
export function actualHoursForMonth ({
|
|
91
|
+
month,
|
|
92
|
+
timesheets = [],
|
|
93
|
+
vacations = [],
|
|
94
|
+
employees = [],
|
|
95
|
+
}) {
|
|
96
|
+
if (!month) return 0
|
|
97
|
+
|
|
98
|
+
let hours = 0
|
|
99
|
+
/** @type {Set<string>} */
|
|
100
|
+
const covered = new Set()
|
|
101
|
+
|
|
102
|
+
for (const sheet of timesheets) {
|
|
103
|
+
const content = contentOf(sheet)
|
|
104
|
+
const employeeId = resourceIdOf(content.employeeId) || ''
|
|
105
|
+
for (const line of content.lines || []) {
|
|
106
|
+
if (!lineInMonth(line?.date, month)) continue
|
|
107
|
+
hours += Number(line.hours) || 0
|
|
108
|
+
for (const key of dayKeysForLine(employeeId, line?.date)) covered.add(key)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const employeesById = new Map(employees.map((employee) => {
|
|
113
|
+
const content = contentOf(employee)
|
|
114
|
+
return [content.id, content]
|
|
115
|
+
}))
|
|
116
|
+
|
|
117
|
+
for (const vacation of vacations) {
|
|
118
|
+
const content = contentOf(vacation)
|
|
119
|
+
const employeeId = resourceIdOf(content.employeeId)
|
|
120
|
+
const perDay = Number(employeesById.get(employeeId)?.workHoursPerDay) || 0
|
|
121
|
+
if (!employeeId || !perDay) continue
|
|
122
|
+
|
|
123
|
+
for (const day of month.days || []) {
|
|
124
|
+
if (!day?.isWorkday || !day.date) continue
|
|
125
|
+
if (!isDayInInclusiveRange(day.date, content.start, content.end)) continue
|
|
126
|
+
const key = `${employeeId}:${day.date}`
|
|
127
|
+
if (covered.has(key)) continue
|
|
128
|
+
hours += perDay
|
|
129
|
+
covered.add(key)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return hours
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Billable income from timesheet lines in the month, at each sheet's contract rate.
|
|
138
|
+
* Vacation days are not billed unless they are logged on a timesheet.
|
|
139
|
+
*
|
|
140
|
+
* @param {object} options
|
|
141
|
+
* @param {object} options.month
|
|
142
|
+
* @param {Array<object>} [options.timesheets]
|
|
143
|
+
* @param {Array<object>} [options.contracts]
|
|
144
|
+
* @returns {number}
|
|
145
|
+
*/
|
|
146
|
+
export function actualIncomeForMonth ({
|
|
147
|
+
month,
|
|
148
|
+
timesheets = [],
|
|
149
|
+
contracts = [],
|
|
150
|
+
}) {
|
|
151
|
+
if (!month) return 0
|
|
152
|
+
|
|
153
|
+
let income = 0
|
|
154
|
+
for (const sheet of timesheets) {
|
|
155
|
+
const content = contentOf(sheet)
|
|
156
|
+
const rate = hourlyRateForSheet(content, contracts)
|
|
157
|
+
if (!rate) continue
|
|
158
|
+
for (const line of content.lines || []) {
|
|
159
|
+
if (!lineInMonth(line?.date, month)) continue
|
|
160
|
+
income += (Number(line.hours) || 0) * rate
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return income
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Attach forecast and actual hour series to fiscal-year months.
|
|
168
|
+
* Forecast hours are the contract projection (`hoursWorked`), which already
|
|
169
|
+
* drops vacation days, weekends, and days outside the contract.
|
|
170
|
+
*
|
|
171
|
+
* @param {object} options
|
|
172
|
+
* @param {Array<object>} options.months
|
|
173
|
+
* @param {Array<object>} [options.timesheets]
|
|
174
|
+
* @param {Array<object>} [options.vacations]
|
|
175
|
+
* @param {Array<object>} [options.employees]
|
|
176
|
+
* @param {Array<object>} [options.contracts]
|
|
177
|
+
*/
|
|
178
|
+
export function withUtilizationHours ({
|
|
179
|
+
months = [],
|
|
180
|
+
timesheets = [],
|
|
181
|
+
vacations = [],
|
|
182
|
+
employees = [],
|
|
183
|
+
contracts = [],
|
|
184
|
+
} = {}) {
|
|
185
|
+
return months.map((month) => {
|
|
186
|
+
const actualIncome = actualIncomeForMonth({ month, timesheets, contracts })
|
|
187
|
+
const salary = Number(month.monthlyCostOfEmployees) || 0
|
|
188
|
+
return {
|
|
189
|
+
...month,
|
|
190
|
+
forecastHours: Number(month.hoursWorked) || 0,
|
|
191
|
+
actualHours: actualHoursForMonth({ month, timesheets, vacations, employees }),
|
|
192
|
+
actualIncome,
|
|
193
|
+
actualRevenue: actualIncome - salary,
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { actualHoursForMonth, actualIncomeForMonth, withUtilizationHours } from './utilization-hours.js'
|
|
2
|
+
|
|
3
|
+
const january = {
|
|
4
|
+
year: 2026,
|
|
5
|
+
monthNumber: '01',
|
|
6
|
+
hoursWorked: 120,
|
|
7
|
+
days: [
|
|
8
|
+
{ date: '2026-01-05', isWorkday: true },
|
|
9
|
+
{ date: '2026-01-06', isWorkday: true },
|
|
10
|
+
{ date: '2026-01-10', isWorkday: false },
|
|
11
|
+
],
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('actualHoursForMonth', () => {
|
|
15
|
+
it('sums timesheet hours that fall in the month', () => {
|
|
16
|
+
const hours = actualHoursForMonth({
|
|
17
|
+
month: january,
|
|
18
|
+
timesheets: [{
|
|
19
|
+
content: {
|
|
20
|
+
employeeId: 'emp-1',
|
|
21
|
+
lines: [
|
|
22
|
+
{ date: new Date(2026, 0, 5).getTime(), hours: 6 },
|
|
23
|
+
{ date: new Date(2026, 1, 2).getTime(), hours: 8 },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
}],
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
expect(hours).toBe(6)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('counts a vacation workday when that day has no timesheet line', () => {
|
|
33
|
+
const hours = actualHoursForMonth({
|
|
34
|
+
month: january,
|
|
35
|
+
employees: [{ id: 'emp-1', workHoursPerDay: 8 }],
|
|
36
|
+
vacations: [{ employeeId: 'emp-1', start: '2026-01-05', end: '2026-01-06' }],
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
expect(hours).toBe(16)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
it('does not add vacation hours on top of a timesheet line for the same day', () => {
|
|
43
|
+
const hours = actualHoursForMonth({
|
|
44
|
+
month: january,
|
|
45
|
+
employees: [{ id: 'emp-1', workHoursPerDay: 8 }],
|
|
46
|
+
vacations: [{ employeeId: 'emp-1', start: '2026-01-05', end: '2026-01-05' }],
|
|
47
|
+
timesheets: [{
|
|
48
|
+
content: {
|
|
49
|
+
employeeId: 'emp-1',
|
|
50
|
+
lines: [{ date: new Date(2026, 0, 5).getTime(), hours: 4 }],
|
|
51
|
+
},
|
|
52
|
+
}],
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
expect(hours).toBe(4)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('ignores vacation days that are not workdays', () => {
|
|
59
|
+
const hours = actualHoursForMonth({
|
|
60
|
+
month: january,
|
|
61
|
+
employees: [{ id: 'emp-1', workHoursPerDay: 8 }],
|
|
62
|
+
vacations: [{ employeeId: 'emp-1', start: '2026-01-10', end: '2026-01-10' }],
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
expect(hours).toBe(0)
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('actualIncomeForMonth', () => {
|
|
70
|
+
it('bills timesheet hours at the linked contract rate', () => {
|
|
71
|
+
const income = actualIncomeForMonth({
|
|
72
|
+
month: january,
|
|
73
|
+
contracts: [{ id: 'con-1', hourlyCompensation: 1000, employeeId: 'emp-1' }],
|
|
74
|
+
timesheets: [{
|
|
75
|
+
content: {
|
|
76
|
+
contractId: 'con-1',
|
|
77
|
+
lines: [
|
|
78
|
+
{ date: new Date(2026, 0, 5).getTime(), hours: 6 },
|
|
79
|
+
{ date: new Date(2026, 1, 2).getTime(), hours: 8 },
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
}],
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
expect(income).toBe(6000)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('falls back to the employee contract when the sheet has no contract', () => {
|
|
89
|
+
const income = actualIncomeForMonth({
|
|
90
|
+
month: january,
|
|
91
|
+
contracts: [{ id: 'con-1', hourlyCompensation: 500, employeeId: { resourceId: 'emp-1' } }],
|
|
92
|
+
timesheets: [{
|
|
93
|
+
content: {
|
|
94
|
+
employeeId: 'emp-1',
|
|
95
|
+
lines: [{ date: new Date(2026, 0, 5).getTime(), hours: 4 }],
|
|
96
|
+
},
|
|
97
|
+
}],
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
expect(income).toBe(2000)
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
describe('withUtilizationHours', () => {
|
|
105
|
+
it('uses contract hours as the forecast series', () => {
|
|
106
|
+
const [month] = withUtilizationHours({
|
|
107
|
+
months: [january],
|
|
108
|
+
timesheets: [{
|
|
109
|
+
content: {
|
|
110
|
+
lines: [{ date: new Date(2026, 0, 6).getTime(), hours: 7 }],
|
|
111
|
+
},
|
|
112
|
+
}],
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
expect(month.forecastHours).toBe(120)
|
|
116
|
+
expect(month.actualHours).toBe(7)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('sets actual result from timesheet income minus salary cost', () => {
|
|
120
|
+
const [month] = withUtilizationHours({
|
|
121
|
+
months: [{ ...january, monthlyCostOfEmployees: 4000 }],
|
|
122
|
+
contracts: [{ id: 'con-1', hourlyCompensation: 1000 }],
|
|
123
|
+
timesheets: [{
|
|
124
|
+
content: {
|
|
125
|
+
contractId: { resourceId: 'con-1' },
|
|
126
|
+
lines: [{ date: new Date(2026, 0, 5).getTime(), hours: 6 }],
|
|
127
|
+
},
|
|
128
|
+
}],
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
expect(month.actualIncome).toBe(6000)
|
|
132
|
+
expect(month.actualRevenue).toBe(2000)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { DataLoader } from '@ossy/calendar'
|
|
3
|
+
import { UtilizationPanel } from './forecast-panels.jsx'
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
id: '@ossy/consultancy/view/utilization',
|
|
7
|
+
widget: {
|
|
8
|
+
title: 'consultancy.widgets.utilization.title',
|
|
9
|
+
description: 'consultancy.widgets.utilization.description',
|
|
10
|
+
ownsHeader: true,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Slot widget — fiscal-year utilization for dashboards. */
|
|
15
|
+
export default function UtilizationWidget (props) {
|
|
16
|
+
return <DataLoader content={<UtilizationPanel {...props} />} />
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { ConsultancyRecordPage } from './ConsultancyRecordList.jsx'
|
|
3
|
+
import { ConsultancySchema } from './schema-ids.js'
|
|
4
|
+
import vacationSchema from './vacation.schema.js'
|
|
5
|
+
|
|
6
|
+
export const metadata = {
|
|
7
|
+
id: 'consultancy/vacations',
|
|
8
|
+
path: {
|
|
9
|
+
sv: '/konsultverksamhet/semester',
|
|
10
|
+
en: '/consultancy/vacations',
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const VacationsPage = () => (
|
|
15
|
+
<ConsultancyRecordPage
|
|
16
|
+
active="consultancy/vacations"
|
|
17
|
+
title="consultancy.vacations.title"
|
|
18
|
+
description="consultancy.vacations.description"
|
|
19
|
+
schemaId={ConsultancySchema.vacation}
|
|
20
|
+
icon={vacationSchema.icon}
|
|
21
|
+
listHeader="consultancy.nav.vacations"
|
|
22
|
+
emptyText="consultancy.vacations.empty"
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export default VacationsPage
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { DataLoader } from '@ossy/calendar'
|
|
3
|
+
import { YearTotalsPanel } from './forecast-panels.jsx'
|
|
4
|
+
|
|
5
|
+
export const metadata = {
|
|
6
|
+
id: '@ossy/consultancy/view/year-totals',
|
|
7
|
+
widget: {
|
|
8
|
+
title: 'consultancy.widgets.yearTotals.title',
|
|
9
|
+
description: 'consultancy.widgets.yearTotals.description',
|
|
10
|
+
ownsHeader: true,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Slot widget — fiscal-year totals for dashboards. */
|
|
15
|
+
export default function YearTotalsWidget (props) {
|
|
16
|
+
return <DataLoader content={<YearTotalsPanel {...props} />} />
|
|
17
|
+
}
|