@adminiumjs/manifest 0.3.79 → 0.3.80
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/dist/change-guards.d.ts +2 -0
- package/dist/change-guards.d.ts.map +1 -1
- package/dist/change-guards.js +7 -2
- package/dist/change-guards.js.map +1 -1
- package/dist/compose.d.ts.map +1 -1
- package/dist/compose.js +3 -0
- package/dist/compose.js.map +1 -1
- package/dist/expiry-notice.d.ts +68 -0
- package/dist/expiry-notice.d.ts.map +1 -0
- package/dist/expiry-notice.js +75 -0
- package/dist/expiry-notice.js.map +1 -0
- package/dist/from-template.d.ts +52 -0
- package/dist/from-template.d.ts.map +1 -0
- package/dist/from-template.js +89 -0
- package/dist/from-template.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/instance.d.ts +2 -1
- package/dist/instance.d.ts.map +1 -1
- package/dist/instance.js +1 -0
- package/dist/instance.js.map +1 -1
- package/dist/leave/away.d.ts +67 -0
- package/dist/leave/away.d.ts.map +1 -0
- package/dist/leave/away.js +74 -0
- package/dist/leave/away.js.map +1 -0
- package/dist/leave/civil.d.ts +35 -0
- package/dist/leave/civil.d.ts.map +1 -0
- package/dist/leave/civil.js +75 -0
- package/dist/leave/civil.js.map +1 -0
- package/dist/leave/close-line.d.ts +91 -0
- package/dist/leave/close-line.d.ts.map +1 -0
- package/dist/leave/close-line.js +90 -0
- package/dist/leave/close-line.js.map +1 -0
- package/dist/leave/count.d.ts +82 -0
- package/dist/leave/count.d.ts.map +1 -0
- package/dist/leave/count.js +129 -0
- package/dist/leave/count.js.map +1 -0
- package/dist/leave/deciders.d.ts +81 -0
- package/dist/leave/deciders.d.ts.map +1 -0
- package/dist/leave/deciders.js +158 -0
- package/dist/leave/deciders.js.map +1 -0
- package/dist/leave/entitlement.d.ts +104 -0
- package/dist/leave/entitlement.d.ts.map +1 -0
- package/dist/leave/entitlement.js +59 -0
- package/dist/leave/entitlement.js.map +1 -0
- package/dist/leave/floors.d.ts +27 -0
- package/dist/leave/floors.d.ts.map +1 -0
- package/dist/leave/floors.js +37 -0
- package/dist/leave/floors.js.map +1 -0
- package/dist/leave/index.d.ts +22 -0
- package/dist/leave/index.d.ts.map +1 -0
- package/dist/leave/index.js +23 -0
- package/dist/leave/index.js.map +1 -0
- package/dist/leave/notice-gate.d.ts +41 -0
- package/dist/leave/notice-gate.d.ts.map +1 -0
- package/dist/leave/notice-gate.js +27 -0
- package/dist/leave/notice-gate.js.map +1 -0
- package/dist/leave/preset-england-wales.d.ts +10 -0
- package/dist/leave/preset-england-wales.d.ts.map +1 -0
- package/dist/leave/preset-england-wales.js +67 -0
- package/dist/leave/preset-england-wales.js.map +1 -0
- package/dist/leave/preset-germany.d.ts +30 -0
- package/dist/leave/preset-germany.d.ts.map +1 -0
- package/dist/leave/preset-germany.js +92 -0
- package/dist/leave/preset-germany.js.map +1 -0
- package/dist/leave/preset-us.d.ts +8 -0
- package/dist/leave/preset-us.d.ts.map +1 -0
- package/dist/leave/preset-us.js +48 -0
- package/dist/leave/preset-us.js.map +1 -0
- package/dist/leave/replay.d.ts +126 -0
- package/dist/leave/replay.d.ts.map +1 -0
- package/dist/leave/replay.js +158 -0
- package/dist/leave/replay.js.map +1 -0
- package/dist/leave/state.d.ts +64 -0
- package/dist/leave/state.d.ts.map +1 -0
- package/dist/leave/state.js +74 -0
- package/dist/leave/state.js.map +1 -0
- package/dist/leave/told.d.ts +32 -0
- package/dist/leave/told.d.ts.map +1 -0
- package/dist/leave/told.js +32 -0
- package/dist/leave/told.js.map +1 -0
- package/dist/leave/units.d.ts +21 -0
- package/dist/leave/units.d.ts.map +1 -0
- package/dist/leave/units.js +21 -0
- package/dist/leave/units.js.map +1 -0
- package/dist/leave-shape.d.ts +324 -0
- package/dist/leave-shape.d.ts.map +1 -0
- package/dist/leave-shape.js +164 -0
- package/dist/leave-shape.js.map +1 -0
- package/dist/leave-word.d.ts +86 -0
- package/dist/leave-word.d.ts.map +1 -0
- package/dist/leave-word.js +235 -0
- package/dist/leave-word.js.map +1 -0
- package/dist/outbox.d.ts +2 -0
- package/dist/outbox.d.ts.map +1 -1
- package/dist/outbox.js +5 -0
- package/dist/outbox.js.map +1 -1
- package/dist/person-import.d.ts +98 -0
- package/dist/person-import.d.ts.map +1 -0
- package/dist/person-import.js +270 -0
- package/dist/person-import.js.map +1 -0
- package/dist/record-classes.d.ts +99 -0
- package/dist/record-classes.d.ts.map +1 -0
- package/dist/record-classes.js +123 -0
- package/dist/record-classes.js.map +1 -0
- package/dist/removal.d.ts +1 -0
- package/dist/removal.d.ts.map +1 -1
- package/dist/removal.js +2 -0
- package/dist/removal.js.map +1 -1
- package/dist/roles.d.ts +23 -1
- package/dist/roles.d.ts.map +1 -1
- package/dist/roles.js +34 -5
- package/dist/roles.js.map +1 -1
- package/dist/schema.d.ts +601 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +134 -14
- package/dist/schema.js.map +1 -1
- package/dist/staff-accounts.d.ts +102 -0
- package/dist/staff-accounts.d.ts.map +1 -0
- package/dist/staff-accounts.js +179 -0
- package/dist/staff-accounts.js.map +1 -0
- package/dist/words.d.ts +1 -1
- package/dist/words.d.ts.map +1 -1
- package/dist/words.js +80 -0
- package/dist/words.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE REPLAY: which lots each day charges, worked out whole from the lots and
|
|
3
|
+
* the days, so its answer depends on what is true and never on the order
|
|
4
|
+
* things were entered in.
|
|
5
|
+
*
|
|
6
|
+
* A row holds its slot while it is `live`. It charges a lot through its
|
|
7
|
+
* allocation, which is why a day a sick report displaced keeps charging until
|
|
8
|
+
* HR hands it back (`returnedAt`).
|
|
9
|
+
*
|
|
10
|
+
* Each day, in order, takes the earliest usable lot. A `held` lot keeps its
|
|
11
|
+
* old date, so it goes first, and stays spendable past it: those are the days
|
|
12
|
+
* the law says cannot lapse. A `sealed` lot still serves days up to its date.
|
|
13
|
+
*
|
|
14
|
+
* Two modes. `judge` refuses a person's own request when it is short. `absorb`
|
|
15
|
+
* never refuses, for what nobody may refuse (a past absence HR records, a
|
|
16
|
+
* calendar correction): the shortfall goes on an overdraft lot of that day's
|
|
17
|
+
* year, flagged for HR.
|
|
18
|
+
*
|
|
19
|
+
* The replay writes nothing. What it finds about a sealed lot it answers as
|
|
20
|
+
* posts, each with the key that makes it happen once: a late day takes back
|
|
21
|
+
* what lapsed, and days handed back after the date come back in a new lot.
|
|
22
|
+
*/
|
|
23
|
+
import { type CivilDay } from './civil.js';
|
|
24
|
+
import type { DayPart } from './count.js';
|
|
25
|
+
import { type EarnRule } from './entitlement.js';
|
|
26
|
+
export type LotState = 'open' | 'held' | 'sealed';
|
|
27
|
+
export interface ReplayLot {
|
|
28
|
+
id: string;
|
|
29
|
+
tier?: string | null | undefined;
|
|
30
|
+
from: CivilDay;
|
|
31
|
+
/** The policy's expiry; empty for a lot that never expires. */
|
|
32
|
+
date: CivilDay | null;
|
|
33
|
+
state: LotState;
|
|
34
|
+
amount: number;
|
|
35
|
+
/** Units moved out to a later lot by a close. */
|
|
36
|
+
carriedOut?: number | undefined;
|
|
37
|
+
/** Units already handed back in a restored lot. */
|
|
38
|
+
restored?: number | undefined;
|
|
39
|
+
/** Units posted as lapsed. */
|
|
40
|
+
lapsed?: number | undefined;
|
|
41
|
+
earn?: EarnRule | null | undefined;
|
|
42
|
+
/** The lot a year's shortfall sits on. Never spent by the ordinary pass. */
|
|
43
|
+
overdraft?: boolean | undefined;
|
|
44
|
+
/** The leave year an overdraft lot is for. */
|
|
45
|
+
year?: number | undefined;
|
|
46
|
+
/** How many restored lots and lapse corrections have been posted from this lot: the next key's number. */
|
|
47
|
+
restores?: number | undefined;
|
|
48
|
+
corrections?: number | undefined;
|
|
49
|
+
}
|
|
50
|
+
export interface ReplayDay {
|
|
51
|
+
id: string;
|
|
52
|
+
day: CivilDay;
|
|
53
|
+
part: DayPart;
|
|
54
|
+
units: number;
|
|
55
|
+
live: boolean;
|
|
56
|
+
state?: string | undefined;
|
|
57
|
+
returnedAt?: string | null | undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface Charge {
|
|
60
|
+
dayId: string;
|
|
61
|
+
lotId: string;
|
|
62
|
+
units: number;
|
|
63
|
+
}
|
|
64
|
+
export interface ReplayLotResult {
|
|
65
|
+
id: string;
|
|
66
|
+
used: number;
|
|
67
|
+
left: number;
|
|
68
|
+
}
|
|
69
|
+
export interface ReplayResult {
|
|
70
|
+
/** Whether every day found its units. */
|
|
71
|
+
ok: boolean;
|
|
72
|
+
/** How many units the days could not find. */
|
|
73
|
+
shortBy: number;
|
|
74
|
+
charges: Charge[];
|
|
75
|
+
lots: ReplayLotResult[];
|
|
76
|
+
/** The shortfall of each year, on its overdraft lot (a new one is named `overdraft:<year>`). HR sees these. */
|
|
77
|
+
overdraft: OverdraftUse[];
|
|
78
|
+
/** Lapses to take back, because a late day was charged to the lot. */
|
|
79
|
+
corrections: LotPost[];
|
|
80
|
+
/** Days handed back after the lot's date, to post as a new lot. */
|
|
81
|
+
restores: LotPost[];
|
|
82
|
+
}
|
|
83
|
+
export interface OverdraftUse {
|
|
84
|
+
year: number;
|
|
85
|
+
lotId: string;
|
|
86
|
+
units: number;
|
|
87
|
+
}
|
|
88
|
+
export interface LotPost {
|
|
89
|
+
lotId: string;
|
|
90
|
+
units: number;
|
|
91
|
+
postKey: string;
|
|
92
|
+
}
|
|
93
|
+
export type ReplayMode = 'judge' | 'absorb';
|
|
94
|
+
/** Whether a row charges a lot: it holds its slot, or a report displaced it and HR has not handed it back. */
|
|
95
|
+
export declare const isCharged: (day: Pick<ReplayDay, "live" | "state" | "returnedAt">) => boolean;
|
|
96
|
+
/** Keys compare as numbers when both are, so row 10 comes after row 9. */
|
|
97
|
+
export declare function compareIds(a: string, b: string): number;
|
|
98
|
+
/** The order lots are spent in: soonest date first (no date last), statutory before extra. */
|
|
99
|
+
export declare function compareLots(a: ReplayLot, b: ReplayLot): number;
|
|
100
|
+
export declare function compareDays(a: ReplayDay, b: ReplayDay): number;
|
|
101
|
+
export interface ReplayInput {
|
|
102
|
+
lots: readonly ReplayLot[];
|
|
103
|
+
days: readonly ReplayDay[];
|
|
104
|
+
/** `judge` when left out. */
|
|
105
|
+
mode?: ReplayMode | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* In `judge`, the days being asked for now. A shortfall that was already
|
|
108
|
+
* there (an absence HR recorded) is no reason to refuse them: only what they
|
|
109
|
+
* add to it is. Left out, every day is judged.
|
|
110
|
+
*/
|
|
111
|
+
fresh?: ReadonlySet<string> | undefined;
|
|
112
|
+
}
|
|
113
|
+
/** The replay. In `judge`, a refusal is `ok: false` with `shortBy`, and nothing it answers is to be written. */
|
|
114
|
+
export declare function replayLeave(input: ReplayInput): ReplayResult;
|
|
115
|
+
/** What must change in the stored charges for them to say what the replay said. */
|
|
116
|
+
export declare function diffCharges(stored: readonly (Charge & {
|
|
117
|
+
id: string;
|
|
118
|
+
})[], next: readonly Charge[]): {
|
|
119
|
+
add: Charge[];
|
|
120
|
+
change: {
|
|
121
|
+
id: string;
|
|
122
|
+
units: number;
|
|
123
|
+
}[];
|
|
124
|
+
remove: string[];
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/leave/replay.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE3D,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAElD,M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C7B,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CACzC;AA4BD,gHAAgH;AAChH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,CAgD5D;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG;IAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAc/K"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* THE REPLAY: which lots each day charges, worked out whole from the lots and
|
|
4
|
+
* the days, so its answer depends on what is true and never on the order
|
|
5
|
+
* things were entered in.
|
|
6
|
+
*
|
|
7
|
+
* A row holds its slot while it is `live`. It charges a lot through its
|
|
8
|
+
* allocation, which is why a day a sick report displaced keeps charging until
|
|
9
|
+
* HR hands it back (`returnedAt`).
|
|
10
|
+
*
|
|
11
|
+
* Each day, in order, takes the earliest usable lot. A `held` lot keeps its
|
|
12
|
+
* old date, so it goes first, and stays spendable past it: those are the days
|
|
13
|
+
* the law says cannot lapse. A `sealed` lot still serves days up to its date.
|
|
14
|
+
*
|
|
15
|
+
* Two modes. `judge` refuses a person's own request when it is short. `absorb`
|
|
16
|
+
* never refuses, for what nobody may refuse (a past absence HR records, a
|
|
17
|
+
* calendar correction): the shortfall goes on an overdraft lot of that day's
|
|
18
|
+
* year, flagged for HR.
|
|
19
|
+
*
|
|
20
|
+
* The replay writes nothing. What it finds about a sealed lot it answers as
|
|
21
|
+
* posts, each with the key that makes it happen once: a late day takes back
|
|
22
|
+
* what lapsed, and days handed back after the date come back in a new lot.
|
|
23
|
+
*/
|
|
24
|
+
import { yearOf } from './civil.js';
|
|
25
|
+
import { earnedBy } from './entitlement.js';
|
|
26
|
+
/** Whether a row charges a lot: it holds its slot, or a report displaced it and HR has not handed it back. */
|
|
27
|
+
export const isCharged = (day) => day.live || (day.state === 'displaced' && (day.returnedAt === null || day.returnedAt === undefined));
|
|
28
|
+
/** Keys compare as numbers when both are, so row 10 comes after row 9. */
|
|
29
|
+
export function compareIds(a, b) {
|
|
30
|
+
const [x, y] = [Number(a), Number(b)];
|
|
31
|
+
if (a !== '' && b !== '' && Number.isFinite(x) && Number.isFinite(y) && x !== y)
|
|
32
|
+
return x - y;
|
|
33
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
34
|
+
}
|
|
35
|
+
const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
36
|
+
const tierRank = (tier) => (tier === 'extra' ? 1 : 0);
|
|
37
|
+
/** The order lots are spent in: soonest date first (no date last), statutory before extra. */
|
|
38
|
+
export function compareLots(a, b) {
|
|
39
|
+
if (a.date !== b.date) {
|
|
40
|
+
if (a.date === null)
|
|
41
|
+
return 1;
|
|
42
|
+
if (b.date === null)
|
|
43
|
+
return -1;
|
|
44
|
+
return compareText(a.date, b.date);
|
|
45
|
+
}
|
|
46
|
+
return tierRank(a.tier) - tierRank(b.tier) || compareIds(a.id, b.id);
|
|
47
|
+
}
|
|
48
|
+
export function compareDays(a, b) {
|
|
49
|
+
return compareText(a.day, b.day) || compareText(a.part, b.part) || compareIds(a.id, b.id);
|
|
50
|
+
}
|
|
51
|
+
/** What a lot can still give, beside what this replay has allocated. A sealed lot's lapse can be taken back, so it does not count against it. */
|
|
52
|
+
function room(lot, allocated) {
|
|
53
|
+
const moved = (lot.carriedOut ?? 0) + (lot.restored ?? 0) + (lot.state === 'sealed' ? 0 : (lot.lapsed ?? 0));
|
|
54
|
+
return lot.amount - moved - allocated;
|
|
55
|
+
}
|
|
56
|
+
function usableOn(lot, day) {
|
|
57
|
+
if (day < lot.from)
|
|
58
|
+
return false;
|
|
59
|
+
return lot.date === null || day <= lot.date || lot.state === 'held';
|
|
60
|
+
}
|
|
61
|
+
/** How many units the days cannot find, with no overdraft. */
|
|
62
|
+
const shortfall = (lots, days) => walk(lots, days).short.reduce((sum, one) => sum + one.units, 0);
|
|
63
|
+
function walk(lots, days) {
|
|
64
|
+
const allocated = new Map(lots.map((lot) => [lot.id, 0]));
|
|
65
|
+
const charges = [];
|
|
66
|
+
const short = [];
|
|
67
|
+
for (const day of days.filter(isCharged).sort(compareDays)) {
|
|
68
|
+
let need = day.units;
|
|
69
|
+
for (const lot of lots) {
|
|
70
|
+
if (need <= 0)
|
|
71
|
+
break;
|
|
72
|
+
if (!usableOn(lot, day.day))
|
|
73
|
+
continue;
|
|
74
|
+
const taken = allocated.get(lot.id);
|
|
75
|
+
const earned = earnedBy(lot, day.day);
|
|
76
|
+
if (earned <= taken)
|
|
77
|
+
continue;
|
|
78
|
+
const take = Math.min(need, room(lot, taken), earned - taken);
|
|
79
|
+
if (take <= 0)
|
|
80
|
+
continue;
|
|
81
|
+
allocated.set(lot.id, taken + take);
|
|
82
|
+
charges.push({ dayId: day.id, lotId: lot.id, units: take });
|
|
83
|
+
need -= take;
|
|
84
|
+
}
|
|
85
|
+
if (need > 0)
|
|
86
|
+
short.push({ day, units: need });
|
|
87
|
+
}
|
|
88
|
+
return { allocated, charges, short };
|
|
89
|
+
}
|
|
90
|
+
/** The replay. In `judge`, a refusal is `ok: false` with `shortBy`, and nothing it answers is to be written. */
|
|
91
|
+
export function replayLeave(input) {
|
|
92
|
+
const mode = input.mode ?? 'judge';
|
|
93
|
+
const all = [...input.lots].sort(compareLots);
|
|
94
|
+
const lots = all.filter((lot) => lot.overdraft !== true);
|
|
95
|
+
const { allocated, charges, short } = walk(lots, input.days);
|
|
96
|
+
const total = short.reduce((sum, one) => sum + one.units, 0);
|
|
97
|
+
const fresh = input.fresh;
|
|
98
|
+
const already = mode === 'judge' && fresh !== undefined && total > 0 ? shortfall(lots, input.days.filter((day) => !fresh.has(day.id))) : 0;
|
|
99
|
+
const shortBy = mode === 'absorb' ? 0 : Math.max(0, total - already);
|
|
100
|
+
// What nobody may refuse sits on its year's overdraft lot.
|
|
101
|
+
const overdraft = new Map();
|
|
102
|
+
if (mode === 'absorb' || (fresh !== undefined && shortBy === 0)) {
|
|
103
|
+
for (const { day, units } of short) {
|
|
104
|
+
const year = yearOf(day.day);
|
|
105
|
+
const lotId = all.find((lot) => lot.overdraft === true && (lot.year ?? yearOf(lot.from)) === year)?.id ?? `overdraft:${String(year)}`;
|
|
106
|
+
const use = overdraft.get(year) ?? { year, lotId, units: 0 };
|
|
107
|
+
use.units += units;
|
|
108
|
+
overdraft.set(year, use);
|
|
109
|
+
charges.push({ dayId: day.id, lotId, units });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const corrections = [];
|
|
113
|
+
const restores = [];
|
|
114
|
+
const lapsedNow = new Map();
|
|
115
|
+
for (const lot of lots) {
|
|
116
|
+
if (lot.state !== 'sealed')
|
|
117
|
+
continue;
|
|
118
|
+
const held = lot.amount - (lot.carriedOut ?? 0) - (lot.restored ?? 0) - allocated.get(lot.id);
|
|
119
|
+
const lapsed = Math.min(lot.lapsed ?? 0, held);
|
|
120
|
+
lapsedNow.set(lot.id, lapsed);
|
|
121
|
+
if (lapsed < (lot.lapsed ?? 0))
|
|
122
|
+
corrections.push({ lotId: lot.id, units: (lot.lapsed ?? 0) - lapsed, postKey: `lapse-fix:${lot.id}:${String(lot.corrections ?? 0)}` });
|
|
123
|
+
if (held > lapsed)
|
|
124
|
+
restores.push({ lotId: lot.id, units: held - lapsed, postKey: `restore:${lot.id}:${String(lot.restores ?? 0)}` });
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
ok: shortBy === 0,
|
|
128
|
+
shortBy,
|
|
129
|
+
charges,
|
|
130
|
+
lots: lots.map((lot) => {
|
|
131
|
+
const used = allocated.get(lot.id);
|
|
132
|
+
const given = restores.find((post) => post.lotId === lot.id)?.units ?? 0;
|
|
133
|
+
return { id: lot.id, used, left: lot.amount - (lot.carriedOut ?? 0) - (lot.restored ?? 0) - (lapsedNow.get(lot.id) ?? lot.lapsed ?? 0) - used - given };
|
|
134
|
+
}),
|
|
135
|
+
overdraft: [...overdraft.values()].sort((a, b) => a.year - b.year),
|
|
136
|
+
corrections,
|
|
137
|
+
restores,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** What must change in the stored charges for them to say what the replay said. */
|
|
141
|
+
export function diffCharges(stored, next) {
|
|
142
|
+
const key = (one) => `${one.dayId}\u0000${one.lotId}`;
|
|
143
|
+
const held = new Map(stored.map((one) => [key(one), one]));
|
|
144
|
+
const add = [];
|
|
145
|
+
const change = [];
|
|
146
|
+
for (const one of next) {
|
|
147
|
+
const was = held.get(key(one));
|
|
148
|
+
if (was === undefined)
|
|
149
|
+
add.push(one);
|
|
150
|
+
else {
|
|
151
|
+
if (was.units !== one.units)
|
|
152
|
+
change.push({ id: was.id, units: one.units });
|
|
153
|
+
held.delete(key(one));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { add, change, remove: [...held.values()].map((one) => one.id) };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/leave/replay.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAiB,MAAM,kBAAkB,CAAC;AA+E3D,8GAA8G;AAC9G,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAqD,EAAW,EA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G,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,MAAM,GAAoC,EAAE,CAAC;IACnD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,IAAI,GAAG,KAAK,SAAS;YAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aAChC,CAAC;YACJ,IAAI,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK;gBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YAC3E,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `leaveState`: THE ONE READ of a person's balance. Home, "Why is my balance
|
|
3
|
+
* this?", the dry-run, the Overview and every preview call it. It writes
|
|
4
|
+
* nothing: a year nobody has opened is worked out as virtual lots, and only a
|
|
5
|
+
* save opens one. "Taken" is never stored; it is worked out here from the day.
|
|
6
|
+
*/
|
|
7
|
+
import { type CivilDay } from './civil.js';
|
|
8
|
+
import { type ReplayDay, type ReplayLot, type ReplayResult } from './replay.js';
|
|
9
|
+
export type LotKind = 'grant' | 'carry' | 'toil' | 'restore' | 'correction' | 'overdraft';
|
|
10
|
+
export interface StateLot extends ReplayLot {
|
|
11
|
+
kind: LotKind;
|
|
12
|
+
year: number;
|
|
13
|
+
/** Worked out for a year nobody has opened: never saved. */
|
|
14
|
+
virtual?: boolean | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** Days a person is asking for, not saved. */
|
|
17
|
+
export interface LeaveDraft {
|
|
18
|
+
days: readonly Pick<ReplayDay, 'day' | 'part' | 'units'>[];
|
|
19
|
+
/** The stored day rows these would replace (a change of dates). */
|
|
20
|
+
replaces?: readonly string[] | undefined;
|
|
21
|
+
}
|
|
22
|
+
export interface LeaveStateInput {
|
|
23
|
+
lots: readonly StateLot[];
|
|
24
|
+
days: readonly ReplayDay[];
|
|
25
|
+
/** Today in the person's location. */
|
|
26
|
+
today: CivilDay;
|
|
27
|
+
/** For a person who is a sample row: the day their figures are read as of, for ever. */
|
|
28
|
+
sampleAsOf?: CivilDay | null | undefined;
|
|
29
|
+
/** The lots a save would post for a year nobody has opened. */
|
|
30
|
+
openYear?: ((year: number) => readonly Omit<StateLot, 'virtual'>[]) | undefined;
|
|
31
|
+
draft?: LeaveDraft | undefined;
|
|
32
|
+
/** Years to answer for though no day falls in them yet: the balance a form shows before its days are added. */
|
|
33
|
+
alsoYears?: readonly number[] | undefined;
|
|
34
|
+
}
|
|
35
|
+
export interface YearFigures {
|
|
36
|
+
year: number;
|
|
37
|
+
/** Whether a save has posted this year's lots. */
|
|
38
|
+
opened: boolean;
|
|
39
|
+
granted: number;
|
|
40
|
+
carried: number;
|
|
41
|
+
restored: number;
|
|
42
|
+
taken: number;
|
|
43
|
+
booked: number;
|
|
44
|
+
pending: number;
|
|
45
|
+
lapsed: number;
|
|
46
|
+
overdraft: number;
|
|
47
|
+
left: number;
|
|
48
|
+
}
|
|
49
|
+
export interface LeaveStanding {
|
|
50
|
+
asOf: CivilDay;
|
|
51
|
+
lots: (StateLot & {
|
|
52
|
+
used: number;
|
|
53
|
+
left: number;
|
|
54
|
+
})[];
|
|
55
|
+
result: ReplayResult;
|
|
56
|
+
years: YearFigures[];
|
|
57
|
+
/** Whether the draft fits. Always true with no draft. */
|
|
58
|
+
fits: boolean;
|
|
59
|
+
shortBy: number;
|
|
60
|
+
}
|
|
61
|
+
/** Whether a day row is waiting, already taken, or still ahead. The morning of today has been taken; its afternoon is ahead. */
|
|
62
|
+
export declare function dayStanding(row: Pick<ReplayDay, 'day' | 'part' | 'state'>, asOf: CivilDay): 'pending' | 'taken' | 'booked';
|
|
63
|
+
export declare function leaveState(input: LeaveStateInput): LeaveStanding;
|
|
64
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/leave/state.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAe,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAE7F,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,WAAW,CAAC;AAE1F,MAAM,WAAW,QAAS,SAAQ,SAAS;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC/B;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC3D,mEAAmE;IACnE,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC1B,IAAI,EAAE,SAAS,SAAS,EAA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AE,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAG1H;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,aAAa,CAyDhE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* `leaveState`: THE ONE READ of a person's balance. Home, "Why is my balance
|
|
4
|
+
* this?", the dry-run, the Overview and every preview call it. It writes
|
|
5
|
+
* nothing: a year nobody has opened is worked out as virtual lots, and only a
|
|
6
|
+
* save opens one. "Taken" is never stored; it is worked out here from the day.
|
|
7
|
+
*/
|
|
8
|
+
import { yearOf } from './civil.js';
|
|
9
|
+
import { replayLeave } from './replay.js';
|
|
10
|
+
/** Whether a day row is waiting, already taken, or still ahead. The morning of today has been taken; its afternoon is ahead. */
|
|
11
|
+
export function dayStanding(row, asOf) {
|
|
12
|
+
if (row.state === 'pending')
|
|
13
|
+
return 'pending';
|
|
14
|
+
return row.day < asOf || (row.day === asOf && row.part === 'am') ? 'taken' : 'booked';
|
|
15
|
+
}
|
|
16
|
+
export function leaveState(input) {
|
|
17
|
+
const asOf = input.sampleAsOf ?? input.today;
|
|
18
|
+
const replaced = new Set(input.draft?.replaces ?? []);
|
|
19
|
+
const drafted = (input.draft?.days ?? []).map((day, index) => ({ ...day, id: `draft:${String(index)}`, live: true, state: 'pending' }));
|
|
20
|
+
const days = [...input.days.filter((day) => !replaced.has(day.id)), ...drafted];
|
|
21
|
+
// A year any day falls in, or today does, that nobody has opened.
|
|
22
|
+
const stored = new Set(input.lots.filter((lot) => lot.kind === 'grant').map((lot) => lot.year));
|
|
23
|
+
const wanted = [...new Set([yearOf(asOf), ...(input.alsoYears ?? []), ...days.map((day) => yearOf(day.day))])].filter((year) => !stored.has(year)).sort((a, b) => a - b);
|
|
24
|
+
const virtual = input.openYear === undefined ? [] : wanted.flatMap((year) => input.openYear(year).map((lot) => ({ ...lot, virtual: true })));
|
|
25
|
+
const lots = [...input.lots, ...virtual];
|
|
26
|
+
const result = replayLeave(input.draft === undefined ? { mode: 'absorb', lots, days } : { mode: 'judge', lots, days, fresh: new Set(drafted.map((day) => day.id)) });
|
|
27
|
+
const figures = new Map(result.lots.map((one) => [one.id, one]));
|
|
28
|
+
const shown = lots.filter((lot) => lot.overdraft !== true).map((lot) => ({ ...lot, used: figures.get(lot.id)?.used ?? 0, left: figures.get(lot.id)?.left ?? 0 }));
|
|
29
|
+
const rowOf = new Map(days.map((day) => [day.id, day]));
|
|
30
|
+
const yearOfLot = new Map(lots.map((lot) => [lot.id, lot.year]));
|
|
31
|
+
for (const use of result.overdraft)
|
|
32
|
+
yearOfLot.set(use.lotId, use.year);
|
|
33
|
+
const years = new Map();
|
|
34
|
+
const yearRow = (year) => {
|
|
35
|
+
let row = years.get(year);
|
|
36
|
+
if (row === undefined) {
|
|
37
|
+
row = { year, opened: stored.has(year), granted: 0, carried: 0, restored: 0, taken: 0, booked: 0, pending: 0, lapsed: 0, overdraft: 0, left: 0 };
|
|
38
|
+
years.set(year, row);
|
|
39
|
+
}
|
|
40
|
+
return row;
|
|
41
|
+
};
|
|
42
|
+
const taken = new Map(result.corrections.map((post) => [post.lotId, post.units]));
|
|
43
|
+
for (const lot of shown) {
|
|
44
|
+
const row = yearRow(lot.year);
|
|
45
|
+
if (lot.kind === 'carry')
|
|
46
|
+
row.carried += lot.amount;
|
|
47
|
+
else if (lot.kind === 'restore')
|
|
48
|
+
row.restored += lot.amount;
|
|
49
|
+
else
|
|
50
|
+
row.granted += lot.amount;
|
|
51
|
+
row.lapsed += (lot.lapsed ?? 0) - (taken.get(lot.id) ?? 0);
|
|
52
|
+
row.left += lot.left;
|
|
53
|
+
}
|
|
54
|
+
for (const charge of result.charges) {
|
|
55
|
+
const day = rowOf.get(charge.dayId);
|
|
56
|
+
const year = yearOfLot.get(charge.lotId);
|
|
57
|
+
if (day === undefined || year === undefined)
|
|
58
|
+
continue;
|
|
59
|
+
yearRow(year)[dayStanding(day, asOf)] += charge.units;
|
|
60
|
+
}
|
|
61
|
+
for (const use of result.overdraft) {
|
|
62
|
+
const row = yearRow(use.year);
|
|
63
|
+
row.overdraft += use.units;
|
|
64
|
+
row.left -= use.units;
|
|
65
|
+
}
|
|
66
|
+
// Days handed back after their date are the person's again today, in the lot the next save posts.
|
|
67
|
+
for (const post of result.restores) {
|
|
68
|
+
const row = yearRow(yearOf(asOf));
|
|
69
|
+
row.restored += post.units;
|
|
70
|
+
row.left += post.units;
|
|
71
|
+
}
|
|
72
|
+
return { asOf, lots: shown, result, years: [...years.values()].sort((a, b) => a.year - b.year), fits: result.ok, shortBy: result.shortBy };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/leave/state.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,WAAW,EAAqD,MAAM,aAAa,CAAC;AAyD7F,gIAAgI;AAChI,MAAM,UAAU,WAAW,CAAC,GAA8C,EAAE,IAAc;IACxF,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,KAAK,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;IACtD,MAAM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,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC;IACxB,CAAC;IACD,kGAAkG;IAClG,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnC,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,GAAG,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC;QAC3B,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC;IACzB,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AAC7I,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is told of a change to a request. Everyone told gets one kept notice,
|
|
3
|
+
* unique by a key built from what it is, and a notice never holds a leave type.
|
|
4
|
+
* A sick or parental matter never reaches a cover or a next person up, because
|
|
5
|
+
* `decidersOf` never names one for it.
|
|
6
|
+
*/
|
|
7
|
+
import { type DeciderFacts, type DeciderRequest } from './deciders.js';
|
|
8
|
+
export type LeaveNoticeKind = 'asked' | 'step' | 'change-asked' | 'decided' | 'cancelled' | 'withdrawn' | 'sick-reported' | 'sick-ended' | 'recorded' | 'returned' | 'adjusted' | LeaveDailyNoticeKind;
|
|
9
|
+
/**
|
|
10
|
+
* What the daily job tells, as time passes: a request has waited long enough
|
|
11
|
+
* for the next person up to decide it too (`waited`), a sick report's last day
|
|
12
|
+
* has gone by (`still-off`, to the person), a cover's days have begun
|
|
13
|
+
* (`covering`, to the cover), and a leaver's last day has come (`days-owed`).
|
|
14
|
+
*/
|
|
15
|
+
export type LeaveDailyNoticeKind = 'waited' | 'still-off' | 'covering' | 'days-owed';
|
|
16
|
+
/** Why this person is the one told. */
|
|
17
|
+
export type ToldReason = 'yours' | 'manager' | 'cover' | 'next-up' | 'hr';
|
|
18
|
+
export interface Told {
|
|
19
|
+
personId: string;
|
|
20
|
+
reason: ToldReason;
|
|
21
|
+
}
|
|
22
|
+
/** Who is told of this event on this request, each once. */
|
|
23
|
+
export declare function whoIsTold(kind: LeaveNoticeKind, request: DeciderRequest, facts: DeciderFacts): Told[];
|
|
24
|
+
/** One notice row per person told: `<kind>:<request or ->:<step or ->:<person>:<reason>`. */
|
|
25
|
+
export declare function noticePostKey(input: {
|
|
26
|
+
kind: string;
|
|
27
|
+
requestId?: string | number | null | undefined;
|
|
28
|
+
step?: number | null | undefined;
|
|
29
|
+
personId: string | number;
|
|
30
|
+
reason: string;
|
|
31
|
+
}): string;
|
|
32
|
+
//# sourceMappingURL=told.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"told.d.ts","sourceRoot":"","sources":["../../src/leave/told.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEnF,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,eAAe,GAAG,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAEvM;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAErF,uCAAuC;AACvC,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC;AAE1E,MAAM,WAAW,IAAI;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;CACpB;AAKD,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,EAAE,CAWrG;AAED,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAG1L"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* Who is told of a change to a request. Everyone told gets one kept notice,
|
|
4
|
+
* unique by a key built from what it is, and a notice never holds a leave type.
|
|
5
|
+
* A sick or parental matter never reaches a cover or a next person up, because
|
|
6
|
+
* `decidersOf` never names one for it.
|
|
7
|
+
*/
|
|
8
|
+
import { decidersOf } from './deciders.js';
|
|
9
|
+
/** The events the person themselves is told of; every other tells whoever decides it now. `adjusted` is HR's recount or change of terms moving their days. */
|
|
10
|
+
const TELLS_THE_PERSON = new Set(['decided', 'withdrawn', 'recorded', 'returned', 'adjusted', 'still-off', 'days-owed']);
|
|
11
|
+
/** Who is told of this event on this request, each once. */
|
|
12
|
+
export function whoIsTold(kind, request, facts) {
|
|
13
|
+
if (TELLS_THE_PERSON.has(kind))
|
|
14
|
+
return [{ personId: request.personId, reason: 'yours' }];
|
|
15
|
+
// A report's end is told as the report was: to the manager if they are here, otherwise HR.
|
|
16
|
+
const asked = kind === 'sick-reported' || kind === 'sick-ended' ? { ...request, status: 'reported' } : kind === 'cancelled' ? { ...request, status: 'pending' } : request;
|
|
17
|
+
const out = decidersOf(asked, facts);
|
|
18
|
+
const managerId = facts.people.get(request.personId)?.managerId ?? null;
|
|
19
|
+
return out.who.map((personId) => {
|
|
20
|
+
if (personId === managerId)
|
|
21
|
+
return { personId, reason: 'manager' };
|
|
22
|
+
if (out.why === 'cover')
|
|
23
|
+
return { personId, reason: 'cover' };
|
|
24
|
+
return { personId, reason: facts.people.get(personId)?.isHr === true ? 'hr' : 'next-up' };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** One notice row per person told: `<kind>:<request or ->:<step or ->:<person>:<reason>`. */
|
|
28
|
+
export function noticePostKey(input) {
|
|
29
|
+
const part = (value) => (value === null || value === undefined ? '-' : String(value));
|
|
30
|
+
return `${input.kind}:${part(input.requestId)}:${part(input.step)}:${String(input.personId)}:${input.reason}`;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=told.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"told.js","sourceRoot":"","sources":["../../src/leave/told.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAA0C,MAAM,eAAe,CAAC;AAoBnF,8JAA8J;AAC9J,MAAM,gBAAgB,GAAiC,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;AAEvJ,4DAA4D;AAC5D,MAAM,UAAU,SAAS,CAAC,IAAqB,EAAE,OAAuB,EAAE,KAAmB;IAC3F,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACzF,2FAA2F;IAC3F,MAAM,KAAK,GAAmB,IAAI,KAAK,eAAe,IAAI,IAAI,KAAK,YAAY,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,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;AAChH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A balance is whole thousandths of a day, or whole minutes on an hours
|
|
3
|
+
* policy, so a sum is exact on all three databases. Every division here says
|
|
4
|
+
* which way it rounds.
|
|
5
|
+
*/
|
|
6
|
+
/** One day, in thousandths. */
|
|
7
|
+
export declare const UNITS_PER_DAY = 1000;
|
|
8
|
+
/** Half a day, in thousandths. */
|
|
9
|
+
export declare const HALF_DAY = 500;
|
|
10
|
+
/** What a policy counts in. */
|
|
11
|
+
export type LeaveBasis = 'days' | 'minutes';
|
|
12
|
+
/** `a ÷ b`, rounded down. `b` is positive. */
|
|
13
|
+
export declare const floorDiv: (a: number, b: number) => number;
|
|
14
|
+
/** `a ÷ b`, rounded up. `b` is positive. */
|
|
15
|
+
export declare const ceilDiv: (a: number, b: number) => number;
|
|
16
|
+
/** A day split into its morning and afternoon: the two always add up to the day, and the morning takes an odd unit. */
|
|
17
|
+
export declare function halves(whole: number): {
|
|
18
|
+
am: number;
|
|
19
|
+
pm: number;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/leave/units.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,+BAA+B;AAC/B,eAAO,MAAM,aAAa,OAAO,CAAC;AAClC,kCAAkC;AAClC,eAAO,MAAM,QAAQ,MAAM,CAAC;AAE5B,+BAA+B;AAC/B,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AAI5C,8CAA8C;AAC9C,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAAmC,CAAC;AAEpF,4CAA4C;AAC5C,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAA0B,CAAC;AAE1E,uHAAuH;AACvH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAGhE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
/**
|
|
3
|
+
* A balance is whole thousandths of a day, or whole minutes on an hours
|
|
4
|
+
* policy, so a sum is exact on all three databases. Every division here says
|
|
5
|
+
* which way it rounds.
|
|
6
|
+
*/
|
|
7
|
+
/** One day, in thousandths. */
|
|
8
|
+
export const UNITS_PER_DAY = 1000;
|
|
9
|
+
/** Half a day, in thousandths. */
|
|
10
|
+
export const HALF_DAY = 500;
|
|
11
|
+
const remainder = (a, b) => ((a % b) + b) % b;
|
|
12
|
+
/** `a ÷ b`, rounded down. `b` is positive. */
|
|
13
|
+
export const floorDiv = (a, b) => (a - remainder(a, b)) / b;
|
|
14
|
+
/** `a ÷ b`, rounded up. `b` is positive. */
|
|
15
|
+
export const ceilDiv = (a, b) => -floorDiv(-a, b);
|
|
16
|
+
/** A day split into its morning and afternoon: the two always add up to the day, and the morning takes an odd unit. */
|
|
17
|
+
export function halves(whole) {
|
|
18
|
+
const am = ceilDiv(whole, 2);
|
|
19
|
+
return { am, pm: whole - am };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/leave/units.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;GAIG;AAEH,+BAA+B;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAClC,kCAAkC;AAClC,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,CAAC;AAK5B,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AAEtE,8CAA8C;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1E,uHAAuH;AACvH,MAAM,UAAU,MAAM,CAAC,KAAa;IAClC,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAC7B,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,GAAG,EAAE,EAAE,CAAC;AAChC,CAAC"}
|