@ossy/consultancy 3.25.0 → 3.26.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 (53) hide show
  1. package/README.md +7 -7
  2. package/package.json +7 -5
  3. package/src/ConsultancyNav.jsx +6 -6
  4. package/src/CreateConsultancyButton.jsx +21 -7
  5. package/src/Forecast.jsx +38 -37
  6. package/src/RequestMatches.jsx +29 -19
  7. package/src/RequestStatsPanel.jsx +1 -1
  8. package/src/ResumeMatches.jsx +51 -0
  9. package/src/calendar-quarter-months.js +36 -0
  10. package/src/calendar-quarter-months.spec.js +22 -0
  11. package/src/create-company.flow.js +9 -9
  12. package/src/current-month.component.jsx +14 -25
  13. package/src/delete-company.flow.js +5 -5
  14. package/src/en.translations.json +17 -32
  15. package/src/extract-request.task.js +20 -13
  16. package/src/extract-request.task.spec.js +7 -3
  17. package/src/file-inbound-request.task.js +93 -0
  18. package/src/file-inbound-request.task.spec.js +118 -0
  19. package/src/forecast-figures.jsx +42 -0
  20. package/src/forecast-panels.jsx +29 -42
  21. package/src/index.js +0 -1
  22. package/src/intake-categories.js +6 -22
  23. package/src/kpi-trend.component.jsx +1 -1
  24. package/src/match-reasons.js +85 -0
  25. package/src/match-reasons.spec.js +73 -0
  26. package/src/match-resumes.js +12 -7
  27. package/src/match-resumes.spec.js +13 -8
  28. package/src/match-resumes.task.js +1 -22
  29. package/src/match-resumes.task.spec.js +19 -14
  30. package/src/{consultancy.page.jsx → overview.page.jsx} +7 -7
  31. package/src/refresh-matches.js +38 -0
  32. package/src/refresh-matches.spec.js +31 -1
  33. package/src/refresh-matches.task.js +322 -72
  34. package/src/refresh-matches.task.spec.js +229 -27
  35. package/src/request.schema.js +0 -1
  36. package/src/{resume-inbound-screening.task.js → resume-inbound-requests.task.js} +12 -14
  37. package/src/{resume-inbound-screening.task.spec.js → resume-inbound-requests.task.spec.js} +32 -18
  38. package/src/resumes.page.jsx +43 -12
  39. package/src/schema-ids.js +0 -1
  40. package/src/spend-for-month.js +67 -0
  41. package/src/spend-for-month.spec.js +41 -0
  42. package/src/spend-year.jsx +91 -0
  43. package/src/{org.page.jsx → spend.page.jsx} +14 -13
  44. package/src/sv.translations.json +17 -32
  45. package/src/use-chart-months.js +5 -2
  46. package/src/use-spend-by-month.js +52 -0
  47. package/src/utilization.component.jsx +1 -1
  48. package/src/view-forecasts.flow.js +3 -3
  49. package/src/year-totals.component.jsx +1 -1
  50. package/src/Overview.jsx +0 -91
  51. package/src/company-basic-info.schema.js +0 -25
  52. package/src/screen-inbound.task.js +0 -133
  53. package/src/screen-inbound.task.spec.js +0 -154
@@ -0,0 +1,67 @@
1
+ /**
2
+ * `year-monthNumber` key shared by forecast months and spend stats.
3
+ *
4
+ * @param {{ year?: number|string, monthNumber?: number|string } | null | undefined} month
5
+ * @returns {string | null}
6
+ */
7
+ export function monthSpendKey (month) {
8
+ if (month?.year == null || month.monthNumber == null || month.monthNumber === '') return null
9
+ const monthNumber = String(month.monthNumber).padStart(2, '0')
10
+ return `${month.year}-${monthNumber}`
11
+ }
12
+
13
+ /**
14
+ * @param {Map<string, number> | null | undefined} spendByMonth
15
+ * @param {{ year?: number|string, monthNumber?: number|string } | null | undefined} month
16
+ */
17
+ export function spendForMonth (spendByMonth, month) {
18
+ const key = monthSpendKey(month)
19
+ if (!key || !spendByMonth) return 0
20
+ const value = Number(spendByMonth.get(key))
21
+ return Number.isFinite(value) ? value : 0
22
+ }
23
+
24
+ /** Salary plus invoice spend: what left the month. */
25
+ export function moneyOutOf (salary, spend) {
26
+ return (Number(salary) || 0) + (Number(spend) || 0)
27
+ }
28
+
29
+ /**
30
+ * SEK purchases that make up one month's spend, largest first.
31
+ *
32
+ * @param {Map<string, Array<{ id?: string, supplier?: string, total?: number }>> | null | undefined} purchasesByMonth
33
+ * @param {{ year?: number|string, monthNumber?: number|string } | null | undefined} month
34
+ */
35
+ export function purchasesForMonth (purchasesByMonth, month) {
36
+ const key = monthSpendKey(month)
37
+ if (!key || !purchasesByMonth) return []
38
+ return purchasesByMonth.get(key) || []
39
+ }
40
+
41
+ /** Every SEK purchase counted in the open fiscal year. */
42
+ export function purchasesInYear (purchasesByMonth) {
43
+ if (!purchasesByMonth) return []
44
+ return [...purchasesByMonth.values()].flat()
45
+ }
46
+
47
+ /** Income minus salary minus invoice spend. */
48
+ export function monthResult ({ income = 0, salary = 0, spend = 0 } = {}) {
49
+ return (Number(income) || 0) - (Number(salary) || 0) - (Number(spend) || 0)
50
+ }
51
+
52
+ /**
53
+ * Copy forecast months and set `spend` from fiscal-month totals.
54
+ *
55
+ * @param {Array<object>} months
56
+ * @param {Map<string, number>} spendByMonth
57
+ */
58
+ export function attachSpend (months, spendByMonth) {
59
+ return (Array.isArray(months) ? months : []).map((month) => {
60
+ const spend = spendForMonth(spendByMonth, month)
61
+ return {
62
+ ...month,
63
+ spend,
64
+ moneyOut: moneyOutOf(month.monthlyCostOfEmployees, spend),
65
+ }
66
+ })
67
+ }
@@ -0,0 +1,41 @@
1
+ import { describe, expect, it } from '@jest/globals'
2
+ import { attachSpend, moneyOutOf, monthResult, monthSpendKey, spendForMonth } from './spend-for-month.js'
3
+
4
+ describe('spend for a forecast month', () => {
5
+ const spendByMonth = new Map([
6
+ ['2026-01', 1490],
7
+ ['2026-10', 3150],
8
+ ])
9
+
10
+ it('pads a numeric month onto the spend key', () => {
11
+ expect(monthSpendKey({ year: 2026, monthNumber: 1 })).toBe('2026-01')
12
+ expect(monthSpendKey({ year: 2026, monthNumber: '10' })).toBe('2026-10')
13
+ expect(monthSpendKey({ year: 2026 })).toBeNull()
14
+ })
15
+
16
+ it('reads the month total and leaves other months at zero', () => {
17
+ expect(spendForMonth(spendByMonth, { year: 2026, monthNumber: '01' })).toBe(1490)
18
+ expect(spendForMonth(spendByMonth, { year: 2026, monthNumber: '02' })).toBe(0)
19
+ expect(spendForMonth(null, { year: 2026, monthNumber: '01' })).toBe(0)
20
+ })
21
+
22
+ it('attaches spend without dropping the forecast fields', () => {
23
+ const [january] = attachSpend(
24
+ [{ year: 2026, monthNumber: '01', projectedIncome: 10 }],
25
+ spendByMonth,
26
+ )
27
+ expect(january).toEqual({
28
+ year: 2026,
29
+ monthNumber: '01',
30
+ projectedIncome: 10,
31
+ spend: 1490,
32
+ moneyOut: 1490,
33
+ })
34
+ })
35
+
36
+ it('subtracts salary and invoices from income', () => {
37
+ expect(monthResult({ income: 10000, salary: 4000, spend: 1500 })).toBe(4500)
38
+ expect(monthResult({ income: 0, salary: 0, spend: 3150 })).toBe(-3150)
39
+ expect(moneyOutOf(4000, 1500)).toBe(5500)
40
+ })
41
+ })
@@ -0,0 +1,91 @@
1
+ import React, { useMemo } from 'react'
2
+ import { Button, LineChart, Panel, Text, View, useLocale } from '@ossy/design-system'
3
+ import { useForecast } from '@ossy/calendar'
4
+ import { useRouter } from '@ossy/router-react'
5
+ import { attachSpend, purchasesForMonth } from './spend-for-month.js'
6
+ import { useSpendByMonth } from './use-spend-by-month.js'
7
+
8
+ const SPEND_SERIES = [
9
+ {
10
+ key: 'spend',
11
+ label: 'spend.overview.chartSeries',
12
+ color: 'var(--surface-danger, hsl(0, 89%, 43%))',
13
+ },
14
+ ]
15
+
16
+ function resourceHref (router, resourceId) {
17
+ if (!resourceId) return null
18
+ // Page ids that already start with @ need a second @. getHref strips one.
19
+ return router.getHref({ id: '@@resource', params: { resourceId } })
20
+ }
21
+
22
+ /**
23
+ * Fiscal-year SEK invoices and receipts, month by month.
24
+ * Each supplier opens the purchase.
25
+ */
26
+ export function SpendYear () {
27
+ const forecastMonths = useForecast()
28
+ const { totals, purchasesByMonth } = useSpendByMonth()
29
+ const { language } = useLocale()
30
+ const router = useRouter()
31
+ const months = useMemo(
32
+ () => attachSpend(Array.isArray(forecastMonths) ? forecastMonths : [], totals),
33
+ [forecastMonths, totals],
34
+ )
35
+ const money = (value) => {
36
+ const amount = Number(value)
37
+ return new Intl.NumberFormat(language === 'sv' ? 'sv-SE' : 'en-SE', {
38
+ style: 'currency',
39
+ currency: 'SEK',
40
+ }).format(Number.isFinite(amount) ? amount : 0)
41
+ }
42
+ const yearSpend = months.reduce((sum, month) => sum + (Number(month.spend) || 0), 0)
43
+ const withPurchases = months.filter((month) => purchasesForMonth(purchasesByMonth, month).length > 0)
44
+
45
+ return (
46
+ <View gap="m">
47
+ <Panel title="spend.overview.chartTitle" data-spend-year>
48
+ <View gap="s" inset="m">
49
+ <View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
50
+ <Text variant="m" style={{ marginBottom: 0 }} text="spend.overview.yearTotal" />
51
+ <Text variant="m" style={{ marginBottom: 0 }}>{money(yearSpend)}</Text>
52
+ </View>
53
+ <LineChart
54
+ months={months}
55
+ series={SPEND_SERIES}
56
+ unit="spend.overview.unitMoney"
57
+ empty="spend.overview.chartEmpty"
58
+ />
59
+ </View>
60
+ </Panel>
61
+ {withPurchases.map((month) => {
62
+ const purchases = purchasesForMonth(purchasesByMonth, month)
63
+ return (
64
+ <Panel
65
+ key={`${month.year}-${month.monthNumber}`}
66
+ title={(
67
+ <Text variant="small" as="h2" weight="bold">
68
+ {month.year} {month.month}
69
+ </Text>
70
+ )}
71
+ data-spend-month={month.monthNumber}
72
+ >
73
+ <View gap="s" inset="m">
74
+ {purchases.map((purchase) => {
75
+ const href = resourceHref(router, purchase.id)
76
+ return (
77
+ <View key={purchase.id || purchase.supplier} layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
78
+ {href
79
+ ? <Button variant="link" href={href}>{purchase.supplier}</Button>
80
+ : <Text variant="m" style={{ marginBottom: 0 }}>{purchase.supplier}</Text>}
81
+ <Text variant="m" style={{ marginBottom: 0 }}>{money(purchase.total)}</Text>
82
+ </View>
83
+ )
84
+ })}
85
+ </View>
86
+ </Panel>
87
+ )
88
+ })}
89
+ </View>
90
+ )
91
+ }
@@ -1,37 +1,38 @@
1
1
  import React from 'react'
2
2
  import { View, Page, Tags } from '@ossy/design-system'
3
- import { Overview } from './Overview.jsx'
4
3
  import { DataLoader } from '@ossy/calendar'
5
- import { Definition } from './Definition.js'
6
- import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
7
4
  import { ConsultancyNav } from './ConsultancyNav.jsx'
5
+ import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
6
+ import { Definition } from './Definition.js'
7
+ import { SpendYear } from './spend-year.jsx'
8
8
 
9
9
  export const metadata = {
10
- id: 'consultancy/org',
10
+ id: 'consultancy/spend',
11
11
  path: {
12
- sv: '/konsultverksamhet/orgdetaljer',
13
- en: '/consultancy/org',
12
+ sv: '/konsultverksamhet/utgifter',
13
+ en: '/consultancy/spend',
14
14
  },
15
15
  }
16
16
 
17
- export const OrgPage = () => {
17
+ export const SpendPage = () => {
18
18
  const statusTags = (Definition.status ?? [])
19
- .map((s) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[s]))
19
+ .map((status) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[status]))
20
20
  .filter(Boolean)
21
21
 
22
22
  return (
23
23
  <Page
24
- title="consultancy.org.title"
24
+ scroll
25
+ title="consultancy.spend.title"
25
26
  near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
26
- description="consultancy.org.description"
27
+ description="consultancy.spend.description"
27
28
  far={<CreateConsultancyButton />}
28
29
  >
29
30
  <View gap="m">
30
- <ConsultancyNav active="consultancy/org" />
31
- <DataLoader content={<Overview />} />
31
+ <ConsultancyNav active="consultancy/spend" />
32
+ <DataLoader content={<SpendYear />} />
32
33
  </View>
33
34
  </Page>
34
35
  )
35
36
  }
36
37
 
37
- export default OrgPage
38
+ export default SpendPage
@@ -1,6 +1,5 @@
1
1
  {
2
- "consultancy/home.documentTitle": "Översikt",
3
- "consultancy/org.documentTitle": "Orgdetaljer",
2
+ "consultancy/overview.documentTitle": "Översikt",
4
3
  "consultancy/margins.documentTitle": "Marginaler",
5
4
  "consultancy/employees.documentTitle": "Anställda",
6
5
  "consultancy/vacations.documentTitle": "Semester",
@@ -9,13 +8,15 @@
9
8
  "consultancy/requests.documentTitle": "Förfrågningar",
10
9
  "consultancy/resumes.documentTitle": "CV",
11
10
  "consultancy/reports.documentTitle": "Rapporter",
11
+ "consultancy/spend.documentTitle": "Utgifter",
12
12
  "consultancy/proposals.documentTitle": "Offerter",
13
- "consultancy.home.title": "Översikt",
14
- "consultancy.home.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
15
- "consultancy.org.title": "Orgdetaljer",
16
- "consultancy.org.description": "Företags- och räkenskapsårsdetaljer",
13
+ "consultancy.overview.title": "Översikt",
14
+ "consultancy.overview.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
15
+ "consultancy.spend.title": "Utgifter",
16
+ "consultancy.spend.description": "Fakturor och kvitton för det här räkenskapsåret",
17
17
  "consultancy.nav.title": "Konsultverksamhet",
18
18
  "consultancy.nav.overview": "Översikt",
19
+ "consultancy.nav.spend": "Utgifter",
19
20
  "consultancy.nav.forecasts": "Prognoser",
20
21
  "consultancy.nav.employees": "Anställda",
21
22
  "consultancy.nav.vacations": "Semester",
@@ -29,6 +30,8 @@
29
30
  "consultancy.forecasts.title": "Översikt",
30
31
  "consultancy.forecasts.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
31
32
  "consultancy.forecasts.income": "Intäkt",
33
+ "consultancy.forecasts.forecast": "Prognos",
34
+ "consultancy.forecasts.actual": "Faktisk",
32
35
  "consultancy.forecasts.forecastIncome": "Prognostiserad intäkt",
33
36
  "consultancy.forecasts.actualIncome": "Faktisk intäkt",
34
37
  "consultancy.forecasts.forecastRevenue": "Prognostiserat resultat",
@@ -36,7 +39,10 @@
36
39
  "consultancy.forecasts.salaryCost": "Lönekostnad",
37
40
  "consultancy.forecasts.revenue": "Resultat",
38
41
  "consultancy.forecasts.hoursWorked": "Arbetade timmar",
42
+ "consultancy.forecasts.spend": "Utgifter",
43
+ "consultancy.forecasts.costs": "Kostnader",
39
44
  "consultancy.forecasts.utilization": "Beläggning",
45
+ "consultancy.forecasts.hours": "Timmar",
40
46
  "consultancy.forecasts.forecastHours": "Prognostiserade timmar",
41
47
  "consultancy.forecasts.actualHours": "Faktiska timmar",
42
48
  "consultancy.forecasts.unitMoney": "kr",
@@ -62,9 +68,6 @@
62
68
  "consultancy.margins.leakage.description": "Uppskatta årlig intäktsförlust när teamet lägger återkommande tid på icke-debiterbar admin.",
63
69
  "consultancy.margins.leakage.hours": "Läckta timmar / år",
64
70
  "consultancy.margins.leakage.revenue": "Läckt intäkt / år",
65
- "consultancy.overview.fiscalYears": "Räkenskapsår",
66
- "consultancy.overview.company": "Företag",
67
- "consultancy.overview.noFiscalYears": "Inga räkenskapsår ännu.",
68
71
  "consultancy.employees.title": "Anställda",
69
72
  "consultancy.employees.description": "Personer i konsultverksamheten",
70
73
  "consultancy.employees.empty": "Inga anställda ännu.",
@@ -79,10 +82,14 @@
79
82
  "consultancy.requests.empty": "Inga förfrågningar ännu.",
80
83
  "consultancy.matches.title": "Matchande CV",
81
84
  "consultancy.matches.loading": "Matchar CV…",
82
- "consultancy.matches.empty": "Inga CV att matcha.",
85
+ "consultancy.matches.empty": "Inga matchande CV ännu.",
83
86
  "consultancy.matches.error": "Kunde inte matcha CV.",
84
87
  "consultancy.matches.embeddingsUnavailable": "Visar överlappande taggar. Likhet är inte tillgänglig.",
85
88
  "consultancy.matches.pending": "Matchningar tas fram när en förfrågan eller ett CV ändras.",
89
+ "consultancy.matches.requestsTitle": "Matchande förfrågningar",
90
+ "consultancy.matches.requestsLoading": "Matchar förfrågningar…",
91
+ "consultancy.matches.requestsEmpty": "Inga matchande förfrågningar ännu.",
92
+ "consultancy.resumes.openEditor": "Öppna CV-redigeraren",
86
93
  "@ossy/consultancy/actions/refresh-matches.label": "Uppdatera matchningar",
87
94
  "@ossy/consultancy/actions/refresh-matches.description": "Bädda in ändrade förfrågningar och CV och spara deras matchningar",
88
95
  "@ossy/consultancy/actions/match-resumes.label": "Matcha CV",
@@ -119,27 +126,6 @@
119
126
  "@ossy/consultancy/schema/calculator.availableHours.label": "Tillgängliga timmar denna månad",
120
127
  "@ossy/consultancy/schema/calculator.teamSize.label": "Teamstorlek",
121
128
  "@ossy/consultancy/schema/calculator.adminHoursPerWeek.label": "Admintimmar per person / vecka",
122
- "@ossy/consultancy/schema/company-basic-info.name.label": "Företagsnamn",
123
- "@ossy/consultancy/schema/company-basic-info.name.description": "Bolagets registrerade namn.",
124
- "@ossy/consultancy/schema/company-basic-info.registrationDate.label": "Registreringsdatum",
125
- "@ossy/consultancy/schema/company-basic-info.registrationDate.description": "Datum då bolaget registrerades hos Bolagsverket. Används för att räkna ut räkenskapsår.",
126
- "@ossy/consultancy/schema/company-basic-info.vatNumber.label": "Momsregistreringsnummer",
127
- "@ossy/consultancy/schema/company-basic-info.vatNumber.description": "VAT-/momsnummer, t.ex. SE556123456701.",
128
- "@ossy/consultancy/schema/company-basic-info.vatRegistredFrom.label": "Momsregistrerad från",
129
- "@ossy/consultancy/schema/company-basic-info.vatRegistredFrom.description": "Datum då bolaget blev momsregistrerat.",
130
- "@ossy/consultancy/schema/company-basic-info.vatPaymentResponsibilityFrom.label": "Momsredovisningsskyldig från",
131
- "@ossy/consultancy/schema/company-basic-info.vatPaymentResponsibilityFrom.description": "Datum då skyldigheten att redovisa moms började.",
132
- "@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.label": "Momsredovisningsperiod",
133
- "@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.description": "Hur ofta momsdeklarationen lämnas in.",
134
- "@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.option.month": "Månad",
135
- "@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.option.quarter": "Kvartal",
136
- "@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.option.year": "År",
137
- "@ossy/consultancy/schema/company-basic-info.financialYearStart.label": "Räkenskapsårets startmånad",
138
- "@ossy/consultancy/schema/company-basic-info.financialYearStart.description": "Månad då räkenskapsåret börjar.",
139
- "@ossy/consultancy/schema/company-basic-info.financialYearEnd.label": "Räkenskapsårets slutmånad",
140
- "@ossy/consultancy/schema/company-basic-info.financialYearEnd.description": "Månad då räkenskapsåret slutar.",
141
- "@ossy/consultancy/schema/company-basic-info.holidayLocale.label": "Helgdagskalender",
142
- "@ossy/consultancy/schema/company-basic-info.holidayLocale.description": "Land som används för röda dagar och helgdagar i prognoser och tidrapporter.",
143
129
  "@ossy/consultancy/schema/employee.name.label": "Namn",
144
130
  "@ossy/consultancy/schema/employee.name.description": "Den anställdas fullständiga namn.",
145
131
  "@ossy/consultancy/schema/employee.email.label": "E-post",
@@ -240,7 +226,6 @@
240
226
  "@ossy/consultancy/schema/proposal.timeline.description": "När arbetet skulle starta och sluta.",
241
227
  "@ossy/consultancy/schema/proposal.body.label": "Brödtext",
242
228
  "@ossy/consultancy/schema/proposal.body.description": "Hela anbudstexten.",
243
- "consultancy.nav.orgDetails": "Orgdetaljer",
244
229
  "consultancy.forecasts.yearChart": "KPI-trend",
245
230
  "consultancy.forecasts.monthForecast": "{month} prognos",
246
231
  "consultancy.forecasts.yearSummary": "Räkenskapsåret prognos",
@@ -2,6 +2,8 @@ import { useMemo } from 'react'
2
2
  import { useContracts, useEmployees, useForecast, useVacations } from '@ossy/calendar'
3
3
  import { ListResources } from '@ossy/resources'
4
4
  import { useSdk } from '@ossy/sdk-react'
5
+ import { attachSpend } from './spend-for-month.js'
6
+ import { useSpendByMonth } from './use-spend-by-month.js'
5
7
  import { TIMESHEET_LOCATION, TIMESHEET_TYPE, withUtilizationHours } from './utilization-hours.js'
6
8
 
7
9
  /**
@@ -15,13 +17,14 @@ export function useChartMonths () {
15
17
  const vacations = useVacations()
16
18
  const sdk = useSdk()
17
19
  const { data: timesheetResources = [] } = sdk.read(ListResources, { location: TIMESHEET_LOCATION })
20
+ const { totals: spendByMonth } = useSpendByMonth()
18
21
 
19
- return useMemo(() => withUtilizationHours({
22
+ return useMemo(() => attachSpend(withUtilizationHours({
20
23
  months,
21
24
  timesheets: (Array.isArray(timesheetResources) ? timesheetResources : [])
22
25
  .filter((resource) => resource.type === TIMESHEET_TYPE),
23
26
  vacations,
24
27
  employees,
25
28
  contracts,
26
- }), [months, timesheetResources, vacations, employees, contracts])
29
+ }), spendByMonth), [months, timesheetResources, vacations, employees, contracts, spendByMonth])
27
30
  }
@@ -0,0 +1,52 @@
1
+ import { useMemo } from 'react'
2
+ import { useCompany } from '@ossy/calendar'
3
+ import { ListResources } from '@ossy/resources'
4
+ import { useSdk } from '@ossy/sdk-react'
5
+ import { buildSpendStats, calendarDayFromIssueDate, location, purchaseInFiscalSpan, SpendSchema } from '@ossy/spend'
6
+
7
+ const CHART_CURRENCY = 'SEK'
8
+
9
+ /**
10
+ * SEK purchases that count toward a fiscal month, plus the month totals.
11
+ * Totals are keyed `year-monthNumber`. Months outside the open year are absent.
12
+ */
13
+ export function useSpendByMonth () {
14
+ const company = useCompany()
15
+ const sdk = useSdk()
16
+ const { data: resources = [] } = sdk.read(ListResources, { location })
17
+ const fiscalYearStart = company?.currentFiscalYearStart ?? null
18
+ const fiscalYearEnd = company?.currentFiscalYearEnd ?? null
19
+
20
+ return useMemo(() => {
21
+ const purchases = (Array.isArray(resources) ? resources : [])
22
+ .filter((resource) => resource?.type === SpendSchema.purchase)
23
+ const stats = buildSpendStats(purchases, {
24
+ fiscalYearStart,
25
+ fiscalYearEnd,
26
+ currency: CHART_CURRENCY,
27
+ })
28
+ const totals = new Map(stats.months.map((month) => [`${month.year}-${month.monthNumber}`, month.spend || 0]))
29
+ const purchasesByMonth = new Map()
30
+ for (const resource of purchases) {
31
+ const content = resource?.content && typeof resource.content === 'object' ? resource.content : {}
32
+ if (fiscalYearStart && fiscalYearEnd && !purchaseInFiscalSpan(content, fiscalYearStart, fiscalYearEnd)) continue
33
+ const currency = typeof content.currency === 'string' ? content.currency.trim().toUpperCase() : ''
34
+ if (currency !== CHART_CURRENCY) continue
35
+ const day = calendarDayFromIssueDate(content.issueDate)
36
+ const key = day?.slice(0, 7)
37
+ if (!key || !totals.has(key)) continue
38
+ const list = purchasesByMonth.get(key) || []
39
+ const total = Number(content.total)
40
+ list.push({
41
+ id: resource.id,
42
+ supplier: typeof content.supplier === 'string' && content.supplier.trim() ? content.supplier.trim() : 'Unknown',
43
+ total: Number.isFinite(total) ? total : 0,
44
+ })
45
+ purchasesByMonth.set(key, list)
46
+ }
47
+ for (const list of purchasesByMonth.values()) {
48
+ list.sort((a, b) => b.total - a.total)
49
+ }
50
+ return { totals, purchasesByMonth }
51
+ }, [resources, fiscalYearStart, fiscalYearEnd])
52
+ }
@@ -13,5 +13,5 @@ export const metadata = {
13
13
 
14
14
  /** Slot widget — fiscal-year utilization for dashboards. */
15
15
  export default function UtilizationWidget (props) {
16
- return <DataLoader content={<UtilizationPanel {...props} />} />
16
+ return <DataLoader emptyGuide={false} content={<UtilizationPanel {...props} />} />
17
17
  }
@@ -8,16 +8,16 @@ export const metadata = {
8
8
  }
9
9
 
10
10
  /**
11
- * After enabling consultancy from the catalog, open the home overview and assert
11
+ * After enabling consultancy from the catalog, open the overview and assert
12
12
  * the workspace forecasts surface is mounted.
13
13
  */
14
14
  export default {
15
15
  title: 'View forecasts',
16
16
  description:
17
- 'Signed-in user enables consultancy and opens the consultancy home overview',
17
+ 'Signed-in user enables consultancy and opens the consultancy overview',
18
18
  steps: [
19
19
  ...enableConsultancyFlow.steps,
20
- { page: '@consultancy/home' },
20
+ { page: '@consultancy/overview' },
21
21
  { result: { selector: '[data-forecasts-status="on"]', timeout: 20000 } },
22
22
  { result: { selector: '[data-consultancy-nav]', timeout: 10000 } },
23
23
  ],
@@ -13,5 +13,5 @@ export const metadata = {
13
13
 
14
14
  /** Slot widget — fiscal-year totals for dashboards. */
15
15
  export default function YearTotalsWidget (props) {
16
- return <DataLoader content={<YearTotalsPanel {...props} />} />
16
+ return <DataLoader emptyGuide={false} content={<YearTotalsPanel {...props} />} />
17
17
  }
package/src/Overview.jsx DELETED
@@ -1,91 +0,0 @@
1
- import React from 'react'
2
- import { Panel, View, Text, useLocale } from '@ossy/design-system'
3
- import { useCompany } from '@ossy/calendar'
4
-
5
- function InfoRow ({ label, value }) {
6
- return (
7
- <View layout="row" justifyContent="space-between" gap="s">
8
- <Text variant="small">{label}</Text>
9
- <Text variant="small">{value ?? '—'}</Text>
10
- </View>
11
- )
12
- }
13
-
14
- function formatDate (value) {
15
- if (value == null || value === '') return '—'
16
- if (typeof value === 'number' || /^\d+$/.test(String(value))) {
17
- const ms = Number(value)
18
- if (!Number.isNaN(ms)) return new Date(ms).toISOString().slice(0, 10)
19
- }
20
- return String(value)
21
- }
22
-
23
- export const Overview = () => {
24
- const company = useCompany()
25
- const { t } = useLocale()
26
- const fiscalYears = company?.getFiscalYears?.() ?? []
27
- const vatPeriod = company?.vatPaymentPeriod
28
- const vatPeriodLabel = vatPeriod
29
- ? t(`@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.option.${vatPeriod}`)
30
- : '—'
31
-
32
- return (
33
- <View
34
- data-consultancy="overview"
35
- layout="row-wrap"
36
- gap="m"
37
- style={{ alignItems: 'stretch' }}
38
- >
39
- <View style={{ flex: '1 1 280px', minWidth: 0 }}>
40
- <Panel title="consultancy.overview.fiscalYears" style={{ height: '100%' }}>
41
- <View gap="s" inset="m">
42
- {fiscalYears.length === 0 ? (
43
- <Text variant="small" text="consultancy.overview.noFiscalYears" />
44
- ) : fiscalYears.map((fiscalYear) => (
45
- <View key={fiscalYear.fiscalYear} layout="row" justifyContent="space-between" gap="s">
46
- <Text variant="small">{fiscalYear.fiscalYear}</Text>
47
- <Text variant="small">{fiscalYear.start} – {fiscalYear.end}</Text>
48
- </View>
49
- ))}
50
- </View>
51
- </Panel>
52
- </View>
53
-
54
- <View style={{ flex: '1 1 280px', minWidth: 0 }}>
55
- <Panel
56
- style={{ height: '100%' }}
57
- title={company?.name
58
- ? <Text variant="small" as="h2" style={{ fontWeight: 'bold' }}>{company.name}</Text>
59
- : 'consultancy.overview.company'}
60
- >
61
- <View gap="s" inset="m">
62
- <InfoRow
63
- label={t('@ossy/consultancy/schema/company-basic-info.registrationDate.label')}
64
- value={formatDate(company?.registrationDate)}
65
- />
66
- <InfoRow
67
- label={t('@ossy/consultancy/schema/company-basic-info.financialYearStart.label')}
68
- value={`${company?.financialYearStart ?? '—'} – ${company?.financialYearEnd ?? '—'}`}
69
- />
70
- <InfoRow
71
- label={t('@ossy/consultancy/schema/company-basic-info.vatNumber.label')}
72
- value={company?.vatNumber}
73
- />
74
- <InfoRow
75
- label={t('@ossy/consultancy/schema/company-basic-info.vatRegistredFrom.label')}
76
- value={formatDate(company?.vatRegistredFrom)}
77
- />
78
- <InfoRow
79
- label={t('@ossy/consultancy/schema/company-basic-info.vatPaymentResponsibilityFrom.label')}
80
- value={formatDate(company?.vatPaymentResponsibilityFrom)}
81
- />
82
- <InfoRow
83
- label={t('@ossy/consultancy/schema/company-basic-info.vatPaymentPeriod.label')}
84
- value={vatPeriodLabel}
85
- />
86
- </View>
87
- </Panel>
88
- </View>
89
- </View>
90
- )
91
- }
@@ -1,25 +0,0 @@
1
- import { ConsultancySchema } from './schema-ids.js'
2
-
3
- export default {
4
- name: 'Company Basic Info',
5
- id: ConsultancySchema.companyBasicInfo,
6
- categoryName: 'Consultancy',
7
- icon: 'organisation',
8
- fields: [
9
- { name: 'name', type: 'text' },
10
- { name: 'registrationDate', type: 'date' },
11
- { name: 'vatNumber', type: 'text' },
12
- { name: 'vatRegistredFrom', type: 'text' },
13
- { name: 'vatPaymentResponsibilityFrom', type: 'text' },
14
- { name: 'vatPaymentPeriod', type: 'select', options: ['month', 'quarter', 'year'] },
15
- { name: 'financialYearStart', type: 'month' },
16
- { name: 'financialYearEnd', type: 'month' },
17
- {
18
- name: 'holidayLocale',
19
- type: 'select',
20
- options: [
21
- 'AT', 'BE', 'CH', 'DE', 'DK', 'ES', 'FI', 'FR', 'GB', 'IE', 'IT', 'NL', 'NO', 'PL', 'PT', 'SE', 'US',
22
- ],
23
- },
24
- ],
25
- }