@getsoren/shared-module 2.68.0 → 2.69.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/README.md +15 -0
- package/dist/documentImport/index.d.ts +9 -0
- package/dist/documentImport/types.d.ts +127 -0
- package/dist/documentImport/utils/matching/matching.d.ts +144 -0
- package/dist/documentImport/utils/matching/matching.test.d.ts +1 -0
- package/dist/documentImport/utils/proposals/proposals.d.ts +10 -0
- package/dist/documentImport/utils/proposals/proposals.test.d.ts +1 -0
- package/dist/documentImport/utils/reading/reading.d.ts +26 -0
- package/dist/documentImport/utils/reading/reading.test.d.ts +1 -0
- package/dist/documentImport.js +202 -0
- package/dist/hourSheets/constants.d.ts +33 -0
- package/dist/hourSheets/index.d.ts +13 -0
- package/dist/hourSheets/types.d.ts +143 -0
- package/dist/hourSheets/utils/billingReferences/billingReferences.d.ts +35 -0
- package/dist/hourSheets/utils/billingReferences/billingReferences.test.d.ts +1 -0
- package/dist/hourSheets/utils/imputation/imputation.d.ts +44 -0
- package/dist/hourSheets/utils/imputation/imputation.test.d.ts +1 -0
- package/dist/hourSheets/utils/readCostCentres/readCostCentres.d.ts +42 -0
- package/dist/hourSheets/utils/readCostCentres/readCostCentres.test.d.ts +1 -0
- package/dist/hourSheets/utils/sheetBlocker/sheetBlocker.d.ts +53 -0
- package/dist/hourSheets/utils/sheetBlocker/sheetBlocker.test.d.ts +1 -0
- package/dist/hourSheets/utils/sheetDays/sheetDays.d.ts +68 -0
- package/dist/hourSheets/utils/sheetDays/sheetDays.test.d.ts +1 -0
- package/dist/hourSheets/utils/sheetLines/sheetLines.d.ts +103 -0
- package/dist/hourSheets/utils/sheetLines/sheetLines.test.d.ts +1 -0
- package/dist/hourSheets.js +58 -0
- package/dist/main.js +339 -375
- package/dist/operator-Cj1X_Zg5.js +41 -0
- package/dist/orval.js +1 -1
- package/dist/sheetLines-DzQEyJOO.js +123 -0
- package/package.json +16 -1
- /package/dist/{orval-Bf_zcxLE.js → orval-BSFwOlVR.js} +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value an imputation field takes: what accounting reads, and the label shown for it.
|
|
3
|
+
*/
|
|
4
|
+
export interface ImputationValue {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Where a line of a document comes from: read on it, or typed by the user.
|
|
10
|
+
*/
|
|
11
|
+
export type DocumentLineSource = "read" | "typed";
|
|
12
|
+
/**
|
|
13
|
+
* A day's imputation values, by field (cost centre, task code…).
|
|
14
|
+
*/
|
|
15
|
+
export type DayImputation = Record<string, ImputationValue>;
|
|
16
|
+
/**
|
|
17
|
+
* Hours of a worked day charged to one imputation: a line of the day. A day whose hours are split between several
|
|
18
|
+
* imputations holds one line for each, kept together in the sheet's days.
|
|
19
|
+
*/
|
|
20
|
+
export interface SheetDay {
|
|
21
|
+
/**
|
|
22
|
+
* Its line's id, or a generated one until it is saved: a day can hold several lines.
|
|
23
|
+
*/
|
|
24
|
+
id: string;
|
|
25
|
+
/**
|
|
26
|
+
* YYYY-MM-DD
|
|
27
|
+
*/
|
|
28
|
+
date: string;
|
|
29
|
+
hours: number;
|
|
30
|
+
/**
|
|
31
|
+
* What these hours are charged to apart from their order: a field left out is charged as the order is.
|
|
32
|
+
*/
|
|
33
|
+
imputation: DayImputation;
|
|
34
|
+
/**
|
|
35
|
+
* The cost centre the sheet writes for the day when none of the client's is told from it: the day is then charged to
|
|
36
|
+
* no cost centre, not the order's, until the user picks one.
|
|
37
|
+
*/
|
|
38
|
+
unreadCostCentre?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Read on the sheet, or typed by the user.
|
|
41
|
+
*/
|
|
42
|
+
source: DocumentLineSource;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Overtime on a sheet: hours of one day at their own hourly rate, with their own imputation.
|
|
46
|
+
*/
|
|
47
|
+
export interface SheetOvertime {
|
|
48
|
+
/**
|
|
49
|
+
* Its line's id, or a generated one until it is saved: a day can hold several overtime entries.
|
|
50
|
+
*/
|
|
51
|
+
id: string;
|
|
52
|
+
/**
|
|
53
|
+
* YYYY-MM-DD
|
|
54
|
+
*/
|
|
55
|
+
date: string;
|
|
56
|
+
/**
|
|
57
|
+
* Hours worked beyond the day's own; null until typed.
|
|
58
|
+
*/
|
|
59
|
+
hours: number | null;
|
|
60
|
+
/**
|
|
61
|
+
* Hourly rate, in euros excluding tax; null until typed.
|
|
62
|
+
*/
|
|
63
|
+
rate: number | null;
|
|
64
|
+
/**
|
|
65
|
+
* What the overtime is charged to apart from its order, as a day's.
|
|
66
|
+
*/
|
|
67
|
+
imputation: DayImputation;
|
|
68
|
+
source: DocumentLineSource;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* An hour sheet as its lines say it: the chart of accounts it is imputed on, its days and its overtime. What it leaves
|
|
72
|
+
* out is charged as its order is, the API's own rule: the sheet follows the order it goes on, whichever that is.
|
|
73
|
+
*/
|
|
74
|
+
export interface HourSheet {
|
|
75
|
+
/**
|
|
76
|
+
* The chart of accounts the sheet is imputed on when another than its order's; none keeps the order's.
|
|
77
|
+
*/
|
|
78
|
+
chart: ImputationValue | null;
|
|
79
|
+
/**
|
|
80
|
+
* The lines of its worked days, in date order: the lines of a day follow each other.
|
|
81
|
+
*/
|
|
82
|
+
days: SheetDay[];
|
|
83
|
+
overtimes: SheetOvertime[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* First and last day (YYYY-MM-DD) something falls within: a rental, a period awaiting its sheet.
|
|
87
|
+
*/
|
|
88
|
+
export interface DayRange {
|
|
89
|
+
from?: string;
|
|
90
|
+
to?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A line of an hour sheet as it is sent to the API: a worked day's hours, or an overtime with its label.
|
|
94
|
+
*/
|
|
95
|
+
export interface SheetLineInput {
|
|
96
|
+
/**
|
|
97
|
+
* Order line the line applies to: the driver's.
|
|
98
|
+
*/
|
|
99
|
+
bookingItemId: string | null;
|
|
100
|
+
/**
|
|
101
|
+
* YYYY-MM-DD
|
|
102
|
+
*/
|
|
103
|
+
date: string;
|
|
104
|
+
/**
|
|
105
|
+
* The stored line this line is; none for a new line.
|
|
106
|
+
*/
|
|
107
|
+
id?: string;
|
|
108
|
+
imputation: DayImputation;
|
|
109
|
+
/**
|
|
110
|
+
* What the line is when not a day's hours: an overtime.
|
|
111
|
+
*/
|
|
112
|
+
label?: string;
|
|
113
|
+
qtyUnit: "HOURS";
|
|
114
|
+
quantity: number | null;
|
|
115
|
+
unitPrice?: number | null;
|
|
116
|
+
amount?: number | null;
|
|
117
|
+
source: DocumentLineSource;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A line of a stored document as the API answers it, quantities and amounts written as decimal strings.
|
|
121
|
+
*/
|
|
122
|
+
export interface StoredSheetLine {
|
|
123
|
+
id: string;
|
|
124
|
+
/**
|
|
125
|
+
* 0-based position on the document.
|
|
126
|
+
*/
|
|
127
|
+
position?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Day of the line; none for hours written without their day.
|
|
130
|
+
*/
|
|
131
|
+
date?: string | null;
|
|
132
|
+
/**
|
|
133
|
+
* First and last day, `YYYY-MM-DD/YYYY-MM-DD`, for a line without `date`.
|
|
134
|
+
*/
|
|
135
|
+
period?: string | null;
|
|
136
|
+
label?: string | null;
|
|
137
|
+
qtyUnit?: string | null;
|
|
138
|
+
quantity?: number | string | null;
|
|
139
|
+
unitPrice?: number | string | null;
|
|
140
|
+
amount?: number | string | null;
|
|
141
|
+
imputation: DayImputation;
|
|
142
|
+
source: DocumentLineSource;
|
|
143
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DayImputation, HourSheet, ImputationValue } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* A billing reference of a cost centre, as the API lists them.
|
|
4
|
+
*/
|
|
5
|
+
export interface BillingReference {
|
|
6
|
+
id: string;
|
|
7
|
+
reference: string;
|
|
8
|
+
/**
|
|
9
|
+
* `active`, or `archived` once it can no longer be named.
|
|
10
|
+
*/
|
|
11
|
+
status: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The OMs a line can name on a cost centre: its billing references that are not archived, as imputation values.
|
|
15
|
+
*/
|
|
16
|
+
export declare const activeBillingReferencesOf: (references: readonly BillingReference[]) => ImputationValue[];
|
|
17
|
+
/**
|
|
18
|
+
* Whether a line must name its OM: a cost centre with a single one needs none, the API picks it.
|
|
19
|
+
*/
|
|
20
|
+
export declare const isBillingReferenceChoice: (options: readonly ImputationValue[]) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a line still has its OM to choose: its cost centre has several active ones and the line names none of them,
|
|
23
|
+
* none at all or one archived since. The API refuses such a line.
|
|
24
|
+
*/
|
|
25
|
+
export declare const isBillingReferenceMissing: (options: readonly ImputationValue[], picked?: ImputationValue) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether a line the sheet states still has its OM to choose: a day with hours or an overtime, charged as the order is
|
|
28
|
+
* where it says nothing. `optionsOf` gives the active OMs of a cost centre, none while they are not loaded.
|
|
29
|
+
*/
|
|
30
|
+
export declare const hasMissingBillingReference: ({ days, overtimes }: Pick<HourSheet, "days" | "overtimes">, orderImputation: DayImputation, optionsOf: (costCentreId: string) => readonly ImputationValue[]) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether a line of the sheet has its OM to choose, named or not: its cost centre has several active ones. The sheet
|
|
33
|
+
* then shows the OM in a column of its own.
|
|
34
|
+
*/
|
|
35
|
+
export declare const hasBillingReferenceChoice: ({ days, overtimes }: Pick<HourSheet, "days" | "overtimes">, orderImputation: DayImputation, optionsOf: (costCentreId: string) => readonly ImputationValue[]) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BILLING_REFERENCE_FIELD } from '../../constants';
|
|
2
|
+
import { DayImputation, ImputationValue, SheetDay } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* The order's own imputation on the given fields. The order form stores each value (an entity id, a lookup code) under
|
|
5
|
+
* its field, and the label shown for it under `<field>_display`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const orderImputationOf: (meta: Record<string, unknown> | null | undefined, fields: readonly string[]) => DayImputation;
|
|
8
|
+
/**
|
|
9
|
+
* The values an imputation charges to, by field: what accounting reads and an order form stores on an order, whatever
|
|
10
|
+
* the labels shown, which the API writes itself.
|
|
11
|
+
*/
|
|
12
|
+
export declare const imputationValuesOf: (imputation: DayImputation) => Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether two imputations charge to the same values, a field left empty counting as absent.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isSameImputation: (imputation: DayImputation, other: DayImputation) => boolean;
|
|
17
|
+
interface DayImputationChange {
|
|
18
|
+
/**
|
|
19
|
+
* Position of the changed line among the sheet's days.
|
|
20
|
+
*/
|
|
21
|
+
index: number;
|
|
22
|
+
field: string;
|
|
23
|
+
value: ImputationValue;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What a day or an overtime is charged to: what it says, the order's imputation for what it leaves out.
|
|
27
|
+
*/
|
|
28
|
+
export declare const imputationOn: (imputation: DayImputation, orderImputation: DayImputation) => DayImputation;
|
|
29
|
+
/**
|
|
30
|
+
* What a line of the sheet is charged to, as `imputationOn`, but a day whose written cost centre is not told among the
|
|
31
|
+
* client's: it is charged to none until one is picked, rather than to the order's, which the sheet does not say.
|
|
32
|
+
*/
|
|
33
|
+
export declare const lineImputationOn: ({ imputation, unreadCostCentre }: Pick<SheetDay, "imputation" | "unreadCostCentre">, orderImputation: DayImputation) => DayImputation;
|
|
34
|
+
/**
|
|
35
|
+
* An imputation without its OM, which belongs to its cost centre.
|
|
36
|
+
*/
|
|
37
|
+
export declare const withoutBillingReference: ({ [BILLING_REFERENCE_FIELD]: _reference, ...imputation }: DayImputation) => DayImputation;
|
|
38
|
+
/**
|
|
39
|
+
* Applies a field change to one line of a day. The value also fills that field on the lines that show none, neither
|
|
40
|
+
* their own nor their order's, since a sheet is usually imputed once; a line that shows a value keeps it. A cost centre
|
|
41
|
+
* set on a line drops its OM, which belongs to the previous one; an OM only fills the lines of the same cost centre.
|
|
42
|
+
*/
|
|
43
|
+
export declare const withDayImputation: (days: SheetDay[], { index, field, value }: DayImputationChange, orderImputation?: DayImputation) => SheetDay[];
|
|
44
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ImputationValue } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* A cost centre as a sheet writes it, searched in a chart of accounts.
|
|
4
|
+
*/
|
|
5
|
+
export interface CostCentreSearch {
|
|
6
|
+
/**
|
|
7
|
+
* The cost centre as written on the sheet.
|
|
8
|
+
*/
|
|
9
|
+
text: string;
|
|
10
|
+
chart: ImputationValue;
|
|
11
|
+
/**
|
|
12
|
+
* The chart's cost centres the search answered.
|
|
13
|
+
*/
|
|
14
|
+
found: ImputationValue[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What a sheet's written cost centres stand for among the client's: the chart of accounts they are in, each one's cost
|
|
18
|
+
* centre there, and those no chart names.
|
|
19
|
+
*/
|
|
20
|
+
export interface ReadCostCentres {
|
|
21
|
+
chart: ImputationValue | null;
|
|
22
|
+
costCentres: Record<string, ImputationValue>;
|
|
23
|
+
unrecognized: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The cost centres a sheet's days write, each once, in their order on the sheet.
|
|
27
|
+
*/
|
|
28
|
+
export declare const writtenCostCentresOf: (days: {
|
|
29
|
+
costCentre?: string;
|
|
30
|
+
}[]) => string[];
|
|
31
|
+
/**
|
|
32
|
+
* What a written cost centre is searched by: its number when it has one ("OM 17156601 AQTA" reads 17156601), which the
|
|
33
|
+
* client's cost centres carry in their name, else its words without their accents, as a hand writes "Coëx" where the
|
|
34
|
+
* client's list says "Coex".
|
|
35
|
+
*/
|
|
36
|
+
export declare const costCentreSearchOf: (text: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* The written cost centres told among the client's. A sheet is imputed on one chart of accounts: the preferred one (its
|
|
39
|
+
* order's) when it names any of them, else the one that names most. A cost centre is taken only where the search
|
|
40
|
+
* answers a single one: between two, nothing says which the sheet means.
|
|
41
|
+
*/
|
|
42
|
+
export declare const readCostCentresOf: (texts: string[], searches: CostCentreSearch[], preferredChartId?: string) => ReadCostCentres;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why an hour sheet cannot be saved, in the order a user settles them: its order first, then its lines.
|
|
3
|
+
*/
|
|
4
|
+
export type SheetBlocker = "rateMissing" | "dateRefused" | "extensionTooLong" | "takenDaysChecking" | "takenDaysError" | "dayTaken" | "billingReferenceMissing" | "costCentreMissing" | "overtimeIncomplete" | "incomplete";
|
|
5
|
+
interface SheetState {
|
|
6
|
+
/**
|
|
7
|
+
* The driver's line, ordered by the hour, has no hourly rate yet.
|
|
8
|
+
*/
|
|
9
|
+
isRateMissing: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* A billed day falls outside the rental, or is still to come.
|
|
12
|
+
*/
|
|
13
|
+
hasRefusedDate: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* The sheet would extend the order by more than the days a sheet extends one by: a date was likely misread.
|
|
16
|
+
*/
|
|
17
|
+
isExtensionTooLong?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The order's other sheets still load: the days they hold are not known yet.
|
|
20
|
+
*/
|
|
21
|
+
isCheckingTakenDays: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The order's other sheets could not be loaded: the days they hold are unknown.
|
|
24
|
+
*/
|
|
25
|
+
isTakenDaysError: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* A worked day is already on another sheet of the order: saved again, it would be billed twice.
|
|
28
|
+
*/
|
|
29
|
+
hasTakenDay: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* A line still has its OM to choose.
|
|
32
|
+
*/
|
|
33
|
+
isBillingReferenceMissing: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* A line still has its cost centre to choose, which the procurement platform asks of each.
|
|
36
|
+
*/
|
|
37
|
+
isCostCentreMissing?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* An overtime still has its hours or its rate to type.
|
|
40
|
+
*/
|
|
41
|
+
hasIncompleteOvertime?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The form takes the sheet: a worked day at least, no day longer than a day, no overtime left half typed.
|
|
44
|
+
*/
|
|
45
|
+
isValid: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* What keeps an hour sheet from being saved, the first to settle; none once it can be: what the API refuses, a day it
|
|
49
|
+
* would bill twice, or what is not known yet (the order's other sheets). Said over the button it greys, so that a greyed
|
|
50
|
+
* button always tells why.
|
|
51
|
+
*/
|
|
52
|
+
export declare const sheetBlockerOf: ({ isRateMissing, hasRefusedDate, isExtensionTooLong, isCheckingTakenDays, isTakenDaysError, hasTakenDay, isBillingReferenceMissing, isCostCentreMissing, hasIncompleteOvertime, isValid, }: SheetState) => SheetBlocker | undefined;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DayRange, HourSheet, SheetDay } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a day (YYYY-MM-DD) falls within the range, an open end taking any day.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isWithin: (date: string, { from, to }: DayRange) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Whether every day the sheet bills falls within the range: its days with hours, and its overtime. The API refuses a
|
|
8
|
+
* sheet stating hours on a day outside the rental on a line by the hour and checks nothing on a line by the day, where the
|
|
9
|
+
* day would be kept on a rental that does not cover it: a reading that took a date for another gives one. A day without
|
|
10
|
+
* hours states no line and is not checked.
|
|
11
|
+
*/
|
|
12
|
+
export declare const areBilledDaysWithin: ({ days, overtimes }: Pick<HourSheet, "days" | "overtimes">, range: DayRange) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The rental stretched over the days the sheet bills outside it, before as after, which saving the sheet extends the
|
|
15
|
+
* order to; none while every day falls within it. A day still to come is refused before: the sheet is not saved.
|
|
16
|
+
*/
|
|
17
|
+
export declare const extendedRentalOf: ({ days, overtimes }: Pick<HourSheet, "days" | "overtimes">, rental: DayRange) => DayRange | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Whether extending the rental to `extended` moves either of its ends by more than the days a sheet extends one by.
|
|
20
|
+
*/
|
|
21
|
+
export declare const isExtensionTooLong: (rental: DayRange, extended?: DayRange) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The days a sheet can hold, which its calendar proposes and its save checks: the rental's, none still to come.
|
|
24
|
+
*/
|
|
25
|
+
export declare const sheetDayRangeOf: (rental: DayRange, today: string) => DayRange;
|
|
26
|
+
/**
|
|
27
|
+
* The day proposed when adding one to a sheet: the first day of its week (Monday to Sunday) it does not hold yet, kept
|
|
28
|
+
* within the given dates; once the week holds every day it can, the day after its last, wherever it falls (a day of
|
|
29
|
+
* the sheet already would add nothing). An empty sheet takes the week of `anchor`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const nextFreeDayOf: (dates: string[], anchor: string, within?: DayRange) => string;
|
|
32
|
+
/**
|
|
33
|
+
* The sheet's days with one more, kept in date order; a day the sheet already holds is left as it is.
|
|
34
|
+
*/
|
|
35
|
+
export declare const withDay: (days: SheetDay[], day: SheetDay) => SheetDay[];
|
|
36
|
+
/**
|
|
37
|
+
* The sheet's days with one more line on a day it holds, after that day's last: hours of the same day charged to
|
|
38
|
+
* something else. The line starts without hours, on the imputation of the line before it, where only what differs is
|
|
39
|
+
* left to change. A day the sheet does not hold gets none.
|
|
40
|
+
*/
|
|
41
|
+
export declare const withDayLine: (days: SheetDay[], date: string, id: string) => SheetDay[];
|
|
42
|
+
/**
|
|
43
|
+
* Where a line stands among the lines of its day, which the sheet shows together.
|
|
44
|
+
*/
|
|
45
|
+
export interface DayLinePlace {
|
|
46
|
+
/**
|
|
47
|
+
* Hours of the line's whole day, across its lines.
|
|
48
|
+
*/
|
|
49
|
+
dayHours: number;
|
|
50
|
+
/**
|
|
51
|
+
* Another line of the same day comes right after it.
|
|
52
|
+
*/
|
|
53
|
+
isFollowed: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Its place among the lines of its day, from 0: the first one names the day.
|
|
56
|
+
*/
|
|
57
|
+
rank: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The place of each of the sheet's lines among the lines of its day, the lines of a day following each other.
|
|
61
|
+
*/
|
|
62
|
+
export declare const dayLinePlacesOf: (days: Pick<SheetDay, "date" | "hours">[]) => DayLinePlace[];
|
|
63
|
+
/**
|
|
64
|
+
* The sheet's days with one of them moved to another date, as when the reading took a date for another: its lines keep
|
|
65
|
+
* their hours and their imputation, and the days stay in date order. Moved onto a day the sheet already holds, nothing
|
|
66
|
+
* changes.
|
|
67
|
+
*/
|
|
68
|
+
export declare const withDayMoved: (days: SheetDay[], from: string, to: string) => SheetDay[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { DayImputation, HourSheet, SheetDay, SheetLineInput, SheetOvertime, StoredSheetLine } from '../../types';
|
|
2
|
+
import { ReadCostCentres } from '../readCostCentres/readCostCentres';
|
|
3
|
+
/**
|
|
4
|
+
* A sheet's total hours, rounded to the hundredth.
|
|
5
|
+
*/
|
|
6
|
+
export declare const sheetHoursOf: (days: Pick<SheetDay, "hours">[]) => number;
|
|
7
|
+
/**
|
|
8
|
+
* The hours a sheet's overtime adds, those typed: an overtime still without its hours adds none.
|
|
9
|
+
*/
|
|
10
|
+
export declare const overtimeHoursOf: (overtimes: Pick<SheetOvertime, "hours">[]) => number;
|
|
11
|
+
/**
|
|
12
|
+
* What an overtime added on a day is charged to: what the day's first line says, as the overtime is worked on that day;
|
|
13
|
+
* nothing for a day the sheet does not hold, or one charged as the order is.
|
|
14
|
+
*/
|
|
15
|
+
export declare const overtimeImputationOf: (days: Pick<SheetDay, "date" | "imputation">[], date: string) => DayImputation;
|
|
16
|
+
/**
|
|
17
|
+
* An overtime with its hours and its rate: the one the sheet states.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isOvertimePriced: ({ hours, rate }: Pick<SheetOvertime, "hours" | "rate">) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* An overtime the sheet states: with its hours and its rate where the driver's line bills it (by the hour), with its
|
|
22
|
+
* hours alone where it does not (by the day): no rate is asked that nothing bills.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isOvertimeStated: (overtime: Pick<SheetOvertime, "hours" | "rate">, isBilled?: boolean) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* An overtime not stated yet (see `isOvertimeStated`): added to the sheet, it is completed or taken out, never left empty.
|
|
27
|
+
*/
|
|
28
|
+
export declare const isOvertimeIncomplete: (overtime: Pick<SheetOvertime, "hours" | "rate">, isBilled?: boolean) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* What an overtime comes to, excluding tax: its hours at its rate, to the cent; none until it has both.
|
|
31
|
+
*/
|
|
32
|
+
export declare const overtimeAmountOf: (overtime: Pick<SheetOvertime, "hours" | "rate">) => number | null;
|
|
33
|
+
interface SheetLinesContext {
|
|
34
|
+
/**
|
|
35
|
+
* Order line the sheet's hours apply to: the driver's.
|
|
36
|
+
*/
|
|
37
|
+
bookingItemId: string | null;
|
|
38
|
+
/**
|
|
39
|
+
* The order's own imputation, its chart of accounts included: what a day leaves out is charged to.
|
|
40
|
+
*/
|
|
41
|
+
orderImputation: DayImputation;
|
|
42
|
+
/**
|
|
43
|
+
* Ids of the lines the sheet's file already holds; none for a sheet whose lines are all new.
|
|
44
|
+
*/
|
|
45
|
+
storedLineIds?: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* The driver's line bills the sheet's overtime (by the hour): its lines say their rate and amount. Off (by the day),
|
|
48
|
+
* they say their hours alone.
|
|
49
|
+
*/
|
|
50
|
+
isOvertimeBilled?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A sheet's document lines: one per line of a worked day, in hours, then one per overtime stated, with its hours, and
|
|
54
|
+
* where the driver's line bills it (by the hour) its rate and the amount they come to, which is what the API bills. A
|
|
55
|
+
* day's line without hours states nothing: it is left out, as an overtime not stated yet is.
|
|
56
|
+
*
|
|
57
|
+
* A line charged as the order is states no imputation: the API then bills it on the order's own, where stating the same
|
|
58
|
+
* values would bill it as a line charged elsewhere. Any other line states its whole imputation: what it says, the
|
|
59
|
+
* order's for what it leaves out, and the sheet's chart of accounts.
|
|
60
|
+
*
|
|
61
|
+
* A line the sheet's file already holds says its id: the API then keeps it the same line wherever it now stands, so
|
|
62
|
+
* that a line added or removed before it does not pass for a change of it. A new line has none.
|
|
63
|
+
*/
|
|
64
|
+
export declare const sheetLinesOf: ({ chart, days, overtimes }: HourSheet, { bookingItemId, orderImputation, storedLineIds, isOvertimeBilled }: SheetLinesContext) => SheetLineInput[];
|
|
65
|
+
/**
|
|
66
|
+
* A day's line or an overtime: what it is charged to.
|
|
67
|
+
*/
|
|
68
|
+
interface ImputedLine {
|
|
69
|
+
imputation: DayImputation;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Lines once the sheet goes on another order: an OM stated on a line charged to the previous order's cost centre is
|
|
73
|
+
* dropped, since it belongs to that cost centre. A line stating its own cost centre keeps its OM.
|
|
74
|
+
*/
|
|
75
|
+
export declare const withoutOrderBillingReferences: <T extends ImputedLine>(lines: T[]) => T[];
|
|
76
|
+
/**
|
|
77
|
+
* Lines once the sheet's chart of accounts changes: their cost centres, entities of the previous chart, are dropped with
|
|
78
|
+
* their OMs.
|
|
79
|
+
*/
|
|
80
|
+
export declare const withoutCostCentres: <T extends ImputedLine>(lines: T[]) => T[];
|
|
81
|
+
/**
|
|
82
|
+
* A worked day as read on a sheet, with the cost centre the sheet writes for it.
|
|
83
|
+
*/
|
|
84
|
+
interface ReadSheetDay extends Pick<SheetDay, "date" | "hours"> {
|
|
85
|
+
costCentre?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The sheet a review starts from when its days were only read: each worked day on a line named after its place among
|
|
89
|
+
* them, the same from one reading of the sheet to the next. A day is charged as its order is, unless the sheet writes a
|
|
90
|
+
* cost centre for it: one of the client's is then stated, and the sheet the chart of accounts it is in; one told among
|
|
91
|
+
* none is kept as written, the day charged to no cost centre until the user picks one.
|
|
92
|
+
* A day read without hours is not a worked day.
|
|
93
|
+
*/
|
|
94
|
+
export declare const sheetOfReadDays: (days: ReadSheetDay[], { chart, costCentres }?: Pick<ReadCostCentres, "chart" | "costCentres">) => HourSheet;
|
|
95
|
+
/**
|
|
96
|
+
* Reads a sheet back from its lines: its days, its overtime, and its chart of accounts. A line states what it is charged
|
|
97
|
+
* to, or nothing when charged as its order is. The API writes quantities and amounts as decimal strings. A line that is
|
|
98
|
+
* neither a dated day in hours nor a dated overtime is not part of the sheet. The lines of a day are read together,
|
|
99
|
+
* in date order, wherever they stand on the document. An overtime saved as an amount alone, before it had hours, shows
|
|
100
|
+
* that amount as its rate: its hours are still to type.
|
|
101
|
+
*/
|
|
102
|
+
export declare const sheetOfLines: (lines: StoredSheetLine[]) => HourSheet;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { C as e, D as t, E as n, S as r, T as i, _ as a, a as o, b as s, c, d as l, f as u, g as d, h as f, i as p, l as m, m as h, n as g, o as _, p as v, r as y, s as b, t as x, u as S, v as C, w, x as T, y as E } from "./sheetLines-DzQEyJOO.js";
|
|
2
|
+
import D from "dayjs";
|
|
3
|
+
//#region src/hourSheets/utils/billingReferences/billingReferences.ts
|
|
4
|
+
var O = "active", k = (e) => e.filter(({ status: e }) => e === O).map(({ id: e, reference: t }) => ({
|
|
5
|
+
label: t,
|
|
6
|
+
value: e
|
|
7
|
+
})), A = (e) => e.length > 1, j = (e, t) => A(e) && !e.some(({ value: e }) => e === t?.value), M = ({ days: e, overtimes: t }, n, i) => [...e.filter(({ hours: e }) => e > 0), ...t].some((e) => {
|
|
8
|
+
let { [s]: t, [r]: a } = v(e.imputation, n);
|
|
9
|
+
return !!a?.value && j(i(a.value), t);
|
|
10
|
+
}), N = ({ days: e, overtimes: t }, n, i) => [...e, ...t].some((e) => {
|
|
11
|
+
let t = v(e.imputation, n)[r]?.value;
|
|
12
|
+
return !!t && A(i(t));
|
|
13
|
+
}), P = (e) => [...new Set(e.flatMap(({ costCentre: e }) => e ?? []))], F = (e) => e.match(/\d{5,}/)?.[0] ?? e.normalize("NFD").replace(/\p{Diacritic}/gu, "").trim(), I = (e, t, n) => {
|
|
14
|
+
let r = t.filter(({ found: e }) => e.length === 1), i = r.map(({ chart: e }) => e).filter((e, t, n) => n.findIndex(({ value: t }) => t === e.value) === t), a = (e) => r.filter(({ chart: t }) => t.value === e).length, o = i.find(({ value: e }) => e === n) ?? [...i].sort((e, t) => a(t.value) - a(e.value))[0] ?? null, s = Object.fromEntries(r.filter((e) => e.chart.value === o?.value).map(({ text: e, found: t }) => [e, t[0]]));
|
|
15
|
+
return {
|
|
16
|
+
chart: o,
|
|
17
|
+
costCentres: s,
|
|
18
|
+
unrecognized: e.filter((e) => !s[e])
|
|
19
|
+
};
|
|
20
|
+
}, L = ({ isRateMissing: e, hasRefusedDate: t, isExtensionTooLong: n = !1, isCheckingTakenDays: r, isTakenDaysError: i, hasTakenDay: a, isBillingReferenceMissing: o, isCostCentreMissing: s = !1, hasIncompleteOvertime: c = !1, isValid: l }) => e ? "rateMissing" : t ? "dateRefused" : n ? "extensionTooLong" : r ? "takenDaysChecking" : i ? "takenDaysError" : a ? "dayTaken" : s ? "costCentreMissing" : o ? "billingReferenceMissing" : c ? "overtimeIncomplete" : l ? void 0 : "incomplete", R = "YYYY-MM-DD", z = (e) => D(e).subtract((D(e).day() + 6) % 7, "day"), B = (e, { from: t, to: n }) => (!t || e >= t) && (!n || e <= n), V = ({ days: e, overtimes: t }, n) => [...e.filter(({ hours: e }) => e > 0), ...t].every(({ date: e }) => B(e, n)), H = ({ days: e, overtimes: t }, n) => {
|
|
21
|
+
let r = [...e.filter(({ hours: e }) => e > 0), ...t].map(({ date: e }) => e).sort(), i = r[0], a = r.at(-1);
|
|
22
|
+
if (!(!(i && a) || r.every((e) => B(e, n)))) return {
|
|
23
|
+
from: n.from && n.from < i ? n.from : i,
|
|
24
|
+
to: n.to && n.to > a ? n.to : a
|
|
25
|
+
};
|
|
26
|
+
}, U = (e, t) => {
|
|
27
|
+
let n = (e, t) => e && t ? D(t).diff(D(e), "day") : 0;
|
|
28
|
+
return !!t && (n(t.from, e.from) > 31 || n(e.to, t.to) > 31);
|
|
29
|
+
}, W = (e, t) => ({
|
|
30
|
+
from: e.from,
|
|
31
|
+
to: e.to && e.to < t ? e.to : t
|
|
32
|
+
}), G = (e, t, n = {}) => {
|
|
33
|
+
let r = [...e].sort(), i = z(r[0] ?? t), a = Array.from({ length: 7 }, (e, t) => i.add(t, "day").format(R)).find((t) => B(t, n) && !e.includes(t)), o = r.at(-1);
|
|
34
|
+
return a ?? (o ? D(o).add(1, "day").format(R) : t);
|
|
35
|
+
}, K = (e, t) => e.some(({ date: e }) => e === t.date) ? e : [...e, t].sort((e, t) => e.date.localeCompare(t.date)), q = (e, t, n) => {
|
|
36
|
+
let r = e.findLastIndex((e) => e.date === t);
|
|
37
|
+
return r < 0 ? e : [
|
|
38
|
+
...e.slice(0, r + 1),
|
|
39
|
+
{
|
|
40
|
+
date: t,
|
|
41
|
+
hours: 0,
|
|
42
|
+
id: n,
|
|
43
|
+
imputation: e[r].imputation,
|
|
44
|
+
source: "typed"
|
|
45
|
+
},
|
|
46
|
+
...e.slice(r + 1)
|
|
47
|
+
];
|
|
48
|
+
}, J = (e) => e.map(({ date: t }, n) => ({
|
|
49
|
+
dayHours: b(e.filter((e) => e.date === t)),
|
|
50
|
+
isFollowed: e[n + 1]?.date === t,
|
|
51
|
+
rank: e.slice(0, n).filter((e) => e.date === t).length
|
|
52
|
+
})), Y = (e, t, n) => e.some(({ date: e }) => e === n) ? e : e.map((e) => e.date === t ? {
|
|
53
|
+
...e,
|
|
54
|
+
date: n,
|
|
55
|
+
source: "typed"
|
|
56
|
+
} : e).sort((e, t) => e.date.localeCompare(t.date));
|
|
57
|
+
//#endregion
|
|
58
|
+
export { s as BILLING_REFERENCE_FIELD, T as CHART_OF_ACCOUNTS_FIELD, r as COST_CENTRE_FIELD, e as HOUR_SHEET_DOCUMENT_TYPE, w as IMPUTATION_FIELDS, i as MAX_HOURS_PER_DAY, n as MAX_RENTAL_EXTENSION_DAYS, t as OVERTIME_LABEL, k as activeBillingReferencesOf, V as areBilledDaysWithin, F as costCentreSearchOf, J as dayLinePlacesOf, H as extendedRentalOf, N as hasBillingReferenceChoice, M as hasMissingBillingReference, v as imputationOn, h as imputationValuesOf, A as isBillingReferenceChoice, j as isBillingReferenceMissing, U as isExtensionTooLong, x as isOvertimeIncomplete, g as isOvertimePriced, y as isOvertimeStated, f as isSameImputation, B as isWithin, d as lineImputationOn, G as nextFreeDayOf, a as orderImputationOf, p as overtimeAmountOf, o as overtimeHoursOf, _ as overtimeImputationOf, I as readCostCentresOf, L as sheetBlockerOf, W as sheetDayRangeOf, b as sheetHoursOf, c as sheetLinesOf, m as sheetOfLines, S as sheetOfReadDays, K as withDay, C as withDayImputation, q as withDayLine, Y as withDayMoved, E as withoutBillingReference, l as withoutCostCentres, u as withoutOrderBillingReferences, P as writtenCostCentresOf };
|