@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
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure layout helpers for the consultancy fiscal-year KPI line chart.
|
|
3
|
-
* Money series share one Y-scale; hours use a secondary scale so shapes stay distinct.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export const MONEY_KEYS = ['projectedIncome', 'monthlyCostOfEmployees', 'revenue']
|
|
7
|
-
export const HOURS_KEY = 'hoursWorked'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 3-letter month label for chart axis (locale-aware short month, truncated).
|
|
11
|
-
*
|
|
12
|
-
* @param {{ year?: number|string, monthNumber?: number|string, month?: string }} month
|
|
13
|
-
* @param {string} [language='en']
|
|
14
|
-
* @returns {string}
|
|
15
|
-
*/
|
|
16
|
-
export function shortMonthLabel (month, language = 'en') {
|
|
17
|
-
const year = Number(month?.year)
|
|
18
|
-
const monthNumber = Number(month?.monthNumber)
|
|
19
|
-
if (Number.isFinite(year) && Number.isFinite(monthNumber) && monthNumber >= 1 && monthNumber <= 12) {
|
|
20
|
-
const locale = language === 'sv' ? 'sv-SE' : 'en'
|
|
21
|
-
const date = new Date(Date.UTC(year, monthNumber - 1, 1))
|
|
22
|
-
const short = new Intl.DateTimeFormat(locale, { month: 'short' }).format(date)
|
|
23
|
-
const letters = short.replace(/\./g, '').trim()
|
|
24
|
-
if (letters.length >= 3) {
|
|
25
|
-
return letters.slice(0, 3).replace(/^./, (c) => c.toUpperCase())
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const fallback = String(month?.month || '').replace(/\./g, '').trim()
|
|
29
|
-
return fallback.slice(0, 3).replace(/^./, (c) => c.toUpperCase())
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {Array<Record<string, unknown>>} months
|
|
34
|
-
* @param {string[]} keys
|
|
35
|
-
* @returns {{ min: number, max: number } | null}
|
|
36
|
-
*/
|
|
37
|
-
export function extentForKeys (months, keys) {
|
|
38
|
-
if (!months?.length || !keys?.length) return null
|
|
39
|
-
let min = Infinity
|
|
40
|
-
let max = -Infinity
|
|
41
|
-
for (const month of months) {
|
|
42
|
-
for (const key of keys) {
|
|
43
|
-
const value = Number(month[key]) || 0
|
|
44
|
-
if (value < min) min = value
|
|
45
|
-
if (value > max) max = value
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!Number.isFinite(min) || !Number.isFinite(max)) return null
|
|
49
|
-
if (min === max) {
|
|
50
|
-
min -= 1
|
|
51
|
-
max += 1
|
|
52
|
-
}
|
|
53
|
-
return { min, max }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {number} value
|
|
58
|
-
* @param {{ min: number, max: number }} extent
|
|
59
|
-
* @param {number} padY
|
|
60
|
-
* @param {number} innerH
|
|
61
|
-
*/
|
|
62
|
-
export function valueToY (value, extent, padY, innerH) {
|
|
63
|
-
const span = extent.max - extent.min
|
|
64
|
-
return padY + innerH - ((value - extent.min) / span) * innerH
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Build SVG path strings for KPI series plus all-month X labels.
|
|
69
|
-
*
|
|
70
|
-
* ViewBox defaults use a wide aspect ratio (~3.5:1) so `preserveAspectRatio="meet"`
|
|
71
|
-
* can scale uniformly without squishing axis labels (see #1001).
|
|
72
|
-
*
|
|
73
|
-
* @param {object} options
|
|
74
|
-
* @param {Array<Record<string, unknown>>} options.months
|
|
75
|
-
* @param {Array<{ key: string, label: string, color: string, dashed?: boolean }>} options.series
|
|
76
|
-
* @param {string} [options.language='en']
|
|
77
|
-
* @param {number} [options.viewWidth=560]
|
|
78
|
-
* @param {number} [options.plotHeight=140]
|
|
79
|
-
* @param {number} [options.padX=16]
|
|
80
|
-
* @param {number} [options.padTop=12]
|
|
81
|
-
* @param {number} [options.padBottom=28]
|
|
82
|
-
* @returns {{ viewWidth: number, viewHeight: number, seriesPaths: Array<object>, monthLabels: Array<object> } | null}
|
|
83
|
-
*/
|
|
84
|
-
export function buildKpiChartLayout ({
|
|
85
|
-
months,
|
|
86
|
-
series,
|
|
87
|
-
language = 'en',
|
|
88
|
-
viewWidth = 560,
|
|
89
|
-
plotHeight = 140,
|
|
90
|
-
padX = 16,
|
|
91
|
-
padTop = 12,
|
|
92
|
-
padBottom = 28,
|
|
93
|
-
}) {
|
|
94
|
-
if (!months?.length || !series?.length) return null
|
|
95
|
-
|
|
96
|
-
const viewHeight = padTop + plotHeight + padBottom
|
|
97
|
-
const innerW = viewWidth - padX * 2
|
|
98
|
-
const innerH = plotHeight
|
|
99
|
-
const step = months.length === 1 ? 0 : innerW / (months.length - 1)
|
|
100
|
-
|
|
101
|
-
const moneyExtent = extentForKeys(months, MONEY_KEYS)
|
|
102
|
-
const hoursExtent = extentForKeys(months, [HOURS_KEY])
|
|
103
|
-
|
|
104
|
-
const seriesPaths = series.map((entry) => {
|
|
105
|
-
const extent = entry.key === HOURS_KEY ? hoursExtent : moneyExtent
|
|
106
|
-
if (!extent) return { ...entry, path: null }
|
|
107
|
-
|
|
108
|
-
const points = months.map((month, index) => {
|
|
109
|
-
const value = Number(month[entry.key]) || 0
|
|
110
|
-
const x = padX + index * step
|
|
111
|
-
const y = valueToY(value, extent, padTop, innerH)
|
|
112
|
-
return `${x},${y}`
|
|
113
|
-
})
|
|
114
|
-
return { ...entry, path: `M ${points.join(' L ')}` }
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const monthLabels = months.map((month, index) => ({
|
|
118
|
-
index,
|
|
119
|
-
label: shortMonthLabel(month, language),
|
|
120
|
-
x: padX + index * step,
|
|
121
|
-
y: viewHeight - 6,
|
|
122
|
-
}))
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
viewWidth,
|
|
126
|
-
viewHeight,
|
|
127
|
-
seriesPaths,
|
|
128
|
-
monthLabels,
|
|
129
|
-
step,
|
|
130
|
-
padX,
|
|
131
|
-
padTop,
|
|
132
|
-
padBottom,
|
|
133
|
-
plotHeight,
|
|
134
|
-
innerW,
|
|
135
|
-
innerH,
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MONEY_KEYS,
|
|
3
|
-
HOURS_KEY,
|
|
4
|
-
extentForKeys,
|
|
5
|
-
valueToY,
|
|
6
|
-
buildKpiChartLayout,
|
|
7
|
-
shortMonthLabel,
|
|
8
|
-
} from './forecast-kpi-chart.js'
|
|
9
|
-
|
|
10
|
-
const sampleMonths = [
|
|
11
|
-
{ year: 2026, monthNumber: '01', month: 'January', projectedIncome: 100, monthlyCostOfEmployees: 50, revenue: 50, hoursWorked: 10 },
|
|
12
|
-
{ year: 2026, monthNumber: '02', month: 'February', projectedIncome: 200, monthlyCostOfEmployees: 50, revenue: 150, hoursWorked: 20 },
|
|
13
|
-
{ year: 2026, monthNumber: '03', month: 'March', projectedIncome: 150, monthlyCostOfEmployees: 50, revenue: 100, hoursWorked: 15 },
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
const series = [
|
|
17
|
-
{ key: 'projectedIncome', label: 'income', color: 'blue' },
|
|
18
|
-
{ key: 'monthlyCostOfEmployees', label: 'salary', color: 'orange' },
|
|
19
|
-
{ key: 'revenue', label: 'revenue', color: 'green' },
|
|
20
|
-
{ key: 'hoursWorked', label: 'hours', color: 'gray', dashed: true },
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
describe('shortMonthLabel', () => {
|
|
24
|
-
it('formats English months as three letters', () => {
|
|
25
|
-
expect(shortMonthLabel({ year: 2026, monthNumber: '01' }, 'en')).toBe('Jan')
|
|
26
|
-
expect(shortMonthLabel({ year: 2026, monthNumber: '09' }, 'en')).toBe('Sep')
|
|
27
|
-
expect(shortMonthLabel({ year: 2026, monthNumber: 12 }, 'en')).toBe('Dec')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('formats Swedish months as three letters without trailing punctuation', () => {
|
|
31
|
-
expect(shortMonthLabel({ year: 2026, monthNumber: '01' }, 'sv')).toBe('Jan')
|
|
32
|
-
expect(shortMonthLabel({ year: 2026, monthNumber: '02' }, 'sv')).toBe('Feb')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('falls back to the long month name when numbers are missing', () => {
|
|
36
|
-
expect(shortMonthLabel({ month: 'January' }, 'en')).toBe('Jan')
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
describe('extentForKeys', () => {
|
|
41
|
-
it('returns shared min/max across money keys', () => {
|
|
42
|
-
const extent = extentForKeys(sampleMonths, MONEY_KEYS)
|
|
43
|
-
expect(extent).toEqual({ min: 50, max: 200 })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('expands a constant series so a flat line stays mid-range', () => {
|
|
47
|
-
const flat = [
|
|
48
|
-
{ monthlyCostOfEmployees: 50 },
|
|
49
|
-
{ monthlyCostOfEmployees: 50 },
|
|
50
|
-
]
|
|
51
|
-
const extent = extentForKeys(flat, ['monthlyCostOfEmployees'])
|
|
52
|
-
expect(extent.min).toBe(49)
|
|
53
|
-
expect(extent.max).toBe(51)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe('buildKpiChartLayout', () => {
|
|
58
|
-
it('spans the full viewBox width for N months', () => {
|
|
59
|
-
const layout = buildKpiChartLayout({ months: sampleMonths, series, viewWidth: 100 })
|
|
60
|
-
expect(layout).not.toBeNull()
|
|
61
|
-
expect(layout.padX + (sampleMonths.length - 1) * layout.step).toBeCloseTo(100 - layout.padX)
|
|
62
|
-
expect(layout.viewWidth).toBe(100)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('keeps salary flat and distinct from income under a shared money scale', () => {
|
|
66
|
-
const layout = buildKpiChartLayout({ months: sampleMonths, series })
|
|
67
|
-
const income = layout.seriesPaths.find((s) => s.key === 'projectedIncome')
|
|
68
|
-
const salary = layout.seriesPaths.find((s) => s.key === 'monthlyCostOfEmployees')
|
|
69
|
-
const revenue = layout.seriesPaths.find((s) => s.key === 'revenue')
|
|
70
|
-
const hours = layout.seriesPaths.find((s) => s.key === HOURS_KEY)
|
|
71
|
-
|
|
72
|
-
expect(income.path).not.toBe(salary.path)
|
|
73
|
-
expect(income.path).not.toBe(revenue.path)
|
|
74
|
-
expect(salary.path).not.toBe(revenue.path)
|
|
75
|
-
|
|
76
|
-
// Constant salary → identical Y across months
|
|
77
|
-
const salaryYs = salary.path.match(/[\d.]+,([\d.]+)/g).map((p) => p.split(',')[1])
|
|
78
|
-
expect(new Set(salaryYs).size).toBe(1)
|
|
79
|
-
|
|
80
|
-
// Hours secondary scale is not forced onto the money path
|
|
81
|
-
expect(hours.path).not.toBe(income.path)
|
|
82
|
-
expect(hours.dashed).toBe(true)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('maps shared money extent extremes to plot top/bottom', () => {
|
|
86
|
-
const extent = extentForKeys(sampleMonths, MONEY_KEYS)
|
|
87
|
-
const padTop = 10
|
|
88
|
-
const plotHeight = 100
|
|
89
|
-
expect(valueToY(extent.max, extent, padTop, plotHeight)).toBeCloseTo(padTop)
|
|
90
|
-
expect(valueToY(extent.min, extent, padTop, plotHeight)).toBeCloseTo(padTop + plotHeight)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('labels every month with a 3-letter abbreviation', () => {
|
|
94
|
-
const fiscalYear = Array.from({ length: 12 }, (_, i) => ({
|
|
95
|
-
year: 2026,
|
|
96
|
-
monthNumber: String(i + 1).padStart(2, '0'),
|
|
97
|
-
month: 'placeholder',
|
|
98
|
-
projectedIncome: 100 + i,
|
|
99
|
-
monthlyCostOfEmployees: 50,
|
|
100
|
-
revenue: 50 + i,
|
|
101
|
-
hoursWorked: 10,
|
|
102
|
-
}))
|
|
103
|
-
const layout = buildKpiChartLayout({ months: fiscalYear, series, language: 'en' })
|
|
104
|
-
expect(layout.monthLabels).toHaveLength(12)
|
|
105
|
-
expect(layout.monthLabels.map((entry) => entry.label)).toEqual([
|
|
106
|
-
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
107
|
-
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
|
|
108
|
-
])
|
|
109
|
-
expect(layout.monthLabels[0].x).toBe(layout.padX)
|
|
110
|
-
expect(layout.monthLabels[11].x).toBeCloseTo(layout.padX + 11 * layout.step)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('defaults to a wide viewBox so meet-scaling keeps labels readable', () => {
|
|
114
|
-
const layout = buildKpiChartLayout({ months: sampleMonths, series })
|
|
115
|
-
expect(layout.viewWidth).toBe(560)
|
|
116
|
-
expect(layout.viewHeight / layout.viewWidth).toBeLessThan(0.5)
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
it('returns null for empty months', () => {
|
|
120
|
-
expect(buildKpiChartLayout({ months: [], series })).toBeNull()
|
|
121
|
-
})
|
|
122
|
-
})
|