@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
package/README.md
CHANGED
|
@@ -210,6 +210,21 @@ input: "./openapi.json"
|
|
|
210
210
|
| getOrvalConfig | Build the orval config (input resolution included) |
|
|
211
211
|
| resolveOrvalInput | Standalone schema target resolution (local file → local → upstream) |
|
|
212
212
|
|
|
213
|
+
## Hour sheets and document import
|
|
214
|
+
|
|
215
|
+
Two entry points hold the rules the back office and the mobile app share, as pure functions with their tests; each app
|
|
216
|
+
keeps only its screens. They need `@getsoren/react-utils` and `dayjs`.
|
|
217
|
+
|
|
218
|
+
| Entry point | Holds |
|
|
219
|
+
|------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
|
|
220
|
+
| `@getsoren/shared-module/hourSheets` | A driver's hour sheet: its days and overtime, the document lines they state, their imputation, what blocks a save |
|
|
221
|
+
| `@getsoren/shared-module/documentImport` | What the assistant read on a document (facts, an hour sheet's days) and the order the document is matched to |
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { extendedRentalOf, sheetLinesOf } from "@getsoren/shared-module/hourSheets";
|
|
225
|
+
import { candidateOf, factsOfAnalysis, matchesOf } from "@getsoren/shared-module/documentImport";
|
|
226
|
+
```
|
|
227
|
+
|
|
213
228
|
## Utils function
|
|
214
229
|
| Module | Description |
|
|
215
230
|
|---------------------|----------------------------------------------------------------------------------------|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point `@getsoren/shared-module/documentImport`: what the assistant's reading of a document says (its facts, an
|
|
3
|
+
* hour sheet's days) and the order the document goes on, matched on what was read. Pure data and logic shared by the
|
|
4
|
+
* back office and the mobile app, which each render their own review.
|
|
5
|
+
*/
|
|
6
|
+
export type * from './types';
|
|
7
|
+
export * from './utils/matching/matching';
|
|
8
|
+
export * from './utils/proposals/proposals';
|
|
9
|
+
export * from './utils/reading/reading';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the assistant read in a file, as the API answers it: its header's fields, and its tables' rows.
|
|
3
|
+
*/
|
|
4
|
+
export interface DocumentAnalysis {
|
|
5
|
+
fields?: Record<string, string>;
|
|
6
|
+
tables?: Record<string, Record<string, string>[]>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A worked day read on an hour sheet.
|
|
10
|
+
*/
|
|
11
|
+
export interface ReadDay {
|
|
12
|
+
/**
|
|
13
|
+
* YYYY-MM-DD
|
|
14
|
+
*/
|
|
15
|
+
date: string;
|
|
16
|
+
hours: number;
|
|
17
|
+
/**
|
|
18
|
+
* The cost centre the sheet writes for these hours, as written: a day split between two holds a line for each.
|
|
19
|
+
*/
|
|
20
|
+
costCentre?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Hours a sheet writes without the day they were worked: a subtotal by week, machine or imputation.
|
|
24
|
+
*/
|
|
25
|
+
export interface UndatedHours {
|
|
26
|
+
hours: number;
|
|
27
|
+
/**
|
|
28
|
+
* YYYY-MM-DD, first and last day: a week runs Monday to Sunday.
|
|
29
|
+
*/
|
|
30
|
+
period?: {
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
};
|
|
34
|
+
equipment?: string;
|
|
35
|
+
costCentre?: string;
|
|
36
|
+
taskCode?: string;
|
|
37
|
+
orderNumber?: string;
|
|
38
|
+
place?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The machine's delivery or pick-up, by its article type.
|
|
42
|
+
*/
|
|
43
|
+
export type TransportType = "machine_delivery" | "machine_retrieval";
|
|
44
|
+
/**
|
|
45
|
+
* Values read on a document.
|
|
46
|
+
*/
|
|
47
|
+
export interface ReadFacts {
|
|
48
|
+
supplierName?: string;
|
|
49
|
+
worksiteName?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The client the document is addressed to, as written on it.
|
|
52
|
+
*/
|
|
53
|
+
clientName?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The machine the document is about: the first it names.
|
|
56
|
+
*/
|
|
57
|
+
machine?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The other machines the document names, after the first: each a line of its own.
|
|
60
|
+
*/
|
|
61
|
+
otherLines?: {
|
|
62
|
+
id: string;
|
|
63
|
+
machine: string;
|
|
64
|
+
}[];
|
|
65
|
+
/**
|
|
66
|
+
* The machine's transports the document names.
|
|
67
|
+
*/
|
|
68
|
+
transports?: TransportType[];
|
|
69
|
+
operatorName?: string;
|
|
70
|
+
/**
|
|
71
|
+
* YYYY-MM-DD
|
|
72
|
+
*/
|
|
73
|
+
from?: string;
|
|
74
|
+
/**
|
|
75
|
+
* YYYY-MM-DD
|
|
76
|
+
*/
|
|
77
|
+
to?: string;
|
|
78
|
+
hours?: number;
|
|
79
|
+
/**
|
|
80
|
+
* The total an hour sheet writes, when it writes one: compared with what its days add up to.
|
|
81
|
+
*/
|
|
82
|
+
writtenHours?: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* What a document is matched to an order on: what was read on it, the supplier picked for it correcting the one read.
|
|
86
|
+
*/
|
|
87
|
+
export interface MatchFacts extends Pick<ReadFacts, "clientName" | "from" | "machine" | "supplierName" | "to" | "worksiteName"> {
|
|
88
|
+
/**
|
|
89
|
+
* The supplier the user picked for the document's order, whatever the issuer read on it.
|
|
90
|
+
*/
|
|
91
|
+
orderSupplier?: {
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* An order as the order list answers it: what a document is matched on.
|
|
97
|
+
*/
|
|
98
|
+
export interface ListedOrder {
|
|
99
|
+
id: string;
|
|
100
|
+
fromDate?: string | null;
|
|
101
|
+
toDate?: string | null;
|
|
102
|
+
worksite?: {
|
|
103
|
+
name?: string;
|
|
104
|
+
} | null;
|
|
105
|
+
items: {
|
|
106
|
+
articleName?: string;
|
|
107
|
+
image?: string | null;
|
|
108
|
+
fromDate?: string | null;
|
|
109
|
+
toDate?: string | null;
|
|
110
|
+
supplier?: {
|
|
111
|
+
name?: string;
|
|
112
|
+
logo?: string | null;
|
|
113
|
+
} | null;
|
|
114
|
+
}[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* An order as the order search answers it, without its supplier nor its worksite.
|
|
118
|
+
*/
|
|
119
|
+
export interface SearchedOrder {
|
|
120
|
+
id: string;
|
|
121
|
+
fromDate?: string | null;
|
|
122
|
+
toDate?: string | null;
|
|
123
|
+
items: {
|
|
124
|
+
image?: string | null;
|
|
125
|
+
name?: string | null;
|
|
126
|
+
}[];
|
|
127
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ListedOrder, MatchFacts, SearchedOrder } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* An order a document may go on, from the order list or the order search.
|
|
4
|
+
*/
|
|
5
|
+
export interface OrderCandidate {
|
|
6
|
+
id: string;
|
|
7
|
+
supplierName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Shown over the machine's picture, as elsewhere in the app.
|
|
10
|
+
*/
|
|
11
|
+
supplierLogo?: string | null;
|
|
12
|
+
articleName?: string;
|
|
13
|
+
articleImage?: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* YYYY-MM-DD
|
|
16
|
+
*/
|
|
17
|
+
fromDate?: string;
|
|
18
|
+
/**
|
|
19
|
+
* YYYY-MM-DD
|
|
20
|
+
*/
|
|
21
|
+
toDate?: string;
|
|
22
|
+
worksiteName?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Created from the document under review: it stays the document's order, never detached, so that it is never created
|
|
25
|
+
* twice.
|
|
26
|
+
*/
|
|
27
|
+
isCreatedFromDocument?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface OrderMatch {
|
|
30
|
+
candidate: OrderCandidate;
|
|
31
|
+
score: number;
|
|
32
|
+
/**
|
|
33
|
+
* How close the order's article is to the machine as written, from 0 to 1: the first to break score ties, since two
|
|
34
|
+
* machines of a family score alike.
|
|
35
|
+
*/
|
|
36
|
+
machineLikeness: number;
|
|
37
|
+
/**
|
|
38
|
+
* Days between the document's and the order's periods; breaks the ties left.
|
|
39
|
+
*/
|
|
40
|
+
distanceDays: number;
|
|
41
|
+
}
|
|
42
|
+
interface MatchOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Worksite the candidates were listed for, when it is the document's (read on it or picked by the user): the app's
|
|
45
|
+
* selected worksite says nothing of the document, its orders' worksites are then compared with the one written.
|
|
46
|
+
*/
|
|
47
|
+
worksiteId?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reached by supplier and machine alone, or by three criteria including the dates.
|
|
51
|
+
*/
|
|
52
|
+
export declare const MIN_MATCH_SCORE = 6;
|
|
53
|
+
/**
|
|
54
|
+
* Candidate from the order list, read from its first non-transport line.
|
|
55
|
+
*/
|
|
56
|
+
export declare const candidateOf: (booking: ListedOrder) => OrderCandidate;
|
|
57
|
+
/**
|
|
58
|
+
* Candidate from the order search, which returns no supplier or worksite.
|
|
59
|
+
*/
|
|
60
|
+
export declare const candidateOfSearch: ({ fromDate, id, items, toDate }: SearchedOrder) => OrderCandidate;
|
|
61
|
+
/**
|
|
62
|
+
* A supplier's name without the agency after a dash: "Loxam - Agence de Gennevilliers" → "Loxam".
|
|
63
|
+
*/
|
|
64
|
+
export declare const companyNameOf: (supplierName: string) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Supplier brand: a known brand, else the first word, ignoring an agency after a dash.
|
|
67
|
+
*/
|
|
68
|
+
export declare const brandOf: (name?: string | null) => string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* What a worksite written on a document is searched by: its whole name, then its name without what follows a dash,
|
|
71
|
+
* often a street or a lot ("Plozévet - Rue du Stade" is filed as "Plozévet").
|
|
72
|
+
*/
|
|
73
|
+
export declare const worksiteSearchesOf: (name: string) => string[];
|
|
74
|
+
/**
|
|
75
|
+
* The worksite a document writes, among those its searches answered: the one of that name, with or without what
|
|
76
|
+
* follows a dash, else the only one found. None between several: the user chooses.
|
|
77
|
+
*/
|
|
78
|
+
export declare const worksiteOfName: <T extends {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
}>(name: string, found: T[]) => T | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The words of a supplier's own name: without its agency after a dash nor its legal form. "S.a.r.l. Butemps" and "SARL
|
|
84
|
+
* BUTEMPS" both read "butemps".
|
|
85
|
+
*/
|
|
86
|
+
export declare const supplierWordsOf: (name?: string | null) => string[];
|
|
87
|
+
/**
|
|
88
|
+
* The word a supplier is searched by in the catalogue: the longest of its own name that names it, which a register's
|
|
89
|
+
* spelling keeps whatever it adds around it ("Lefevre TP" is filed as "Soc à responsabilité limitée Lefevre").
|
|
90
|
+
*/
|
|
91
|
+
export declare const supplierSearchOf: (name: string) => string;
|
|
92
|
+
/**
|
|
93
|
+
* Two names of the same rental company: the same known brand whatever the agency, else the words of one all found in
|
|
94
|
+
* the other's, one at least naming the company ("Transports Fieloux" in "Transports Christophe Fieloux", never
|
|
95
|
+
* "Transports" alone). Unknown without a name on either side.
|
|
96
|
+
*/
|
|
97
|
+
export declare const isSameSupplier: (name?: string | null, other?: string | null) => boolean | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Weight class in tonnes: 2.5 for "Pelle 2,5 tonnes".
|
|
100
|
+
*/
|
|
101
|
+
export declare const tonnageOf: (text?: string) => number | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Whether a document is addressed to someone else than the user's company: the client it writes shares no word with
|
|
104
|
+
* any of the company's names. A document that writes no client, or a company without a known name, tells nothing.
|
|
105
|
+
*/
|
|
106
|
+
export declare const isAddressedElsewhere: (clientName: string | undefined, ownNames: (string | null | undefined)[]) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Two documents are about the same rental: the same rental company and the same machine, for the same client when both
|
|
109
|
+
* write theirs. Only then does one follow the other onto its order: documents imported together are not all one order's.
|
|
110
|
+
*/
|
|
111
|
+
export declare const isSameRental: (facts: MatchFacts, other: MatchFacts) => boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Scores an order against a document's worksite, supplier brand, machine and dates.
|
|
114
|
+
*/
|
|
115
|
+
export declare const scoreOf: (facts: MatchFacts, candidate: OrderCandidate, { worksiteId }: MatchOptions) => OrderMatch;
|
|
116
|
+
/**
|
|
117
|
+
* Orders scoring at least `MIN_MATCH_SCORE`, best first; ties go to the order whose article is named most like the
|
|
118
|
+
* machine written, then to the nearest in time, then to the most recent.
|
|
119
|
+
*/
|
|
120
|
+
export declare const matchesOf: (facts: MatchFacts, candidates: OrderCandidate[], options: MatchOptions) => OrderMatch[];
|
|
121
|
+
/**
|
|
122
|
+
* The matches nothing tells from `match`: the same score, as alike a machine, as near in time. Between them, only the
|
|
123
|
+
* user knows which order the document is about.
|
|
124
|
+
*/
|
|
125
|
+
export declare const rivalsOf: (matches: OrderMatch[], match?: Pick<OrderMatch, "candidate">) => OrderMatch[];
|
|
126
|
+
/**
|
|
127
|
+
* Best order scoring at least `MIN_MATCH_SCORE` (see `matchesOf`).
|
|
128
|
+
*/
|
|
129
|
+
export declare const bestMatchOf: (facts: MatchFacts, candidates: OrderCandidate[], options: MatchOptions) => OrderMatch;
|
|
130
|
+
/**
|
|
131
|
+
* Catalog search text for a machine: its words without the weight class.
|
|
132
|
+
*/
|
|
133
|
+
export declare const machineSearchOf: (machine: string) => string;
|
|
134
|
+
/**
|
|
135
|
+
* Best catalog article for a machine: with operator as asked first, then of the same weight class, then the one whose
|
|
136
|
+
* name is closest to the machine as written. Without the last, the first search result stood for any machine of the
|
|
137
|
+
* family: a 9-10 t for a 12-13 t.
|
|
138
|
+
*/
|
|
139
|
+
export declare const rentalArticleFor: <T extends {
|
|
140
|
+
name: string;
|
|
141
|
+
type?: string | null;
|
|
142
|
+
withOperator?: boolean | null;
|
|
143
|
+
}>(machine: string, withOperator: boolean, articles: T[]) => T;
|
|
144
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OrderCandidate, OrderMatch } from '../matching/matching';
|
|
2
|
+
/**
|
|
3
|
+
* An order proposed for a document.
|
|
4
|
+
*/
|
|
5
|
+
export type Proposal = Pick<OrderMatch, "candidate">;
|
|
6
|
+
/**
|
|
7
|
+
* The orders proposed for a document, best first: its matches, then the order a sibling went on when it matches none,
|
|
8
|
+
* since documents imported together usually share one.
|
|
9
|
+
*/
|
|
10
|
+
export declare const proposalsOf: (matches: OrderMatch[], siblingOrder?: OrderCandidate) => Proposal[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DocumentAnalysis, ReadDay, ReadFacts, TransportType, UndatedHours } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* The machine's transports, in their order on screen: its delivery, then its pick-up.
|
|
4
|
+
*/
|
|
5
|
+
export declare const TRANSPORT_TYPES: TransportType[];
|
|
6
|
+
/**
|
|
7
|
+
* An hour sheet's days with their hours, sorted. Lines in days or over a full day are dropped; lines of the same day
|
|
8
|
+
* charged alike (morning and afternoon) are summed. A day the sheet charges to several cost centres keeps a line for
|
|
9
|
+
* each, with the cost centre as written.
|
|
10
|
+
*/
|
|
11
|
+
export declare const daysOfAnalysis: (analysis: DocumentAnalysis) => ReadDay[];
|
|
12
|
+
/**
|
|
13
|
+
* The hours a sheet writes without their day (a week's, a machine's or an imputation's subtotal), in its order. A line
|
|
14
|
+
* whose day is misread rather than missing is dropped, as in `daysOfAnalysis`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const undatedHoursOfAnalysis: (analysis: DocumentAnalysis) => UndatedHours[];
|
|
17
|
+
/**
|
|
18
|
+
* The machine's transports an article name stands for, by their type: none for a machine. "Transport A/R" or "Amenée
|
|
19
|
+
* et repli" stand for both.
|
|
20
|
+
*/
|
|
21
|
+
export declare const transportTypesOf: (name: string) => TransportType[];
|
|
22
|
+
/**
|
|
23
|
+
* Facts read on a document; its period spans its lines' days and periods, else the period its header writes, else its
|
|
24
|
+
* issue date.
|
|
25
|
+
*/
|
|
26
|
+
export declare const factsOfAnalysis: (analysis: DocumentAnalysis) => ReadFacts;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { s as e } from "./operator-Cj1X_Zg5.js";
|
|
2
|
+
import { s as t } from "./sheetLines-DzQEyJOO.js";
|
|
3
|
+
import { normalizeSearch as n, roundToHundredths as r, toNumberOrNull as i } from "@getsoren/react-utils";
|
|
4
|
+
import a from "dayjs";
|
|
5
|
+
//#region src/documentImport/utils/matching/matching.ts
|
|
6
|
+
var o = {
|
|
7
|
+
dateMet: 2,
|
|
8
|
+
machineFamily: 1,
|
|
9
|
+
machineMet: 3,
|
|
10
|
+
machineMismatch: -3,
|
|
11
|
+
periodMismatch: -3,
|
|
12
|
+
supplierMet: 3,
|
|
13
|
+
supplierMismatch: -4,
|
|
14
|
+
worksiteMet: 2,
|
|
15
|
+
worksiteMismatch: -3
|
|
16
|
+
}, s = 6, ee = /^(livraison|reprise|transport|enlevement)\b/, c = [
|
|
17
|
+
"acces industrie",
|
|
18
|
+
"boels",
|
|
19
|
+
"hertz",
|
|
20
|
+
"kiloutou",
|
|
21
|
+
"loxam",
|
|
22
|
+
"mediaco",
|
|
23
|
+
"ramirent",
|
|
24
|
+
"salti"
|
|
25
|
+
], l = [
|
|
26
|
+
["miniExcavator", /\b(mini ?pelles?|minipelles?)\b/],
|
|
27
|
+
["backhoeLoader", /\btractopelles?\b/],
|
|
28
|
+
["excavator", /\bpelles?\b/],
|
|
29
|
+
["aerialPlatform", /\bnacelles?\b/],
|
|
30
|
+
["forklift", /\b(chariots?|telescopiques?|manitou)\b/],
|
|
31
|
+
["compactor", /\b(compacteurs?|cylindres?|plaques? vibrantes?)\b/],
|
|
32
|
+
["loader", /\bchargeuses?\b/],
|
|
33
|
+
["dumper", /\b(dumpers?|tombereaux?)\b/],
|
|
34
|
+
["crane", /\bgrues?\b/],
|
|
35
|
+
["truck", /\b(camions?|porteurs?)\b/],
|
|
36
|
+
["generator", /\bgroupes? electrogenes?\b/]
|
|
37
|
+
], u = (e) => n(e ?? "").replace(/[^a-z0-9]+/g, " ").trim(), d = (e) => e?.slice(0, 10) || void 0, f = (e) => {
|
|
38
|
+
let t = e.items.find(({ articleName: e }) => !ee.test(u(e))) ?? e.items[0];
|
|
39
|
+
return {
|
|
40
|
+
articleImage: t?.image,
|
|
41
|
+
articleName: t?.articleName,
|
|
42
|
+
fromDate: d(e.fromDate ?? t?.fromDate),
|
|
43
|
+
id: e.id,
|
|
44
|
+
supplierLogo: t?.supplier?.logo,
|
|
45
|
+
supplierName: t?.supplier?.name,
|
|
46
|
+
toDate: d(e.toDate ?? t?.toDate),
|
|
47
|
+
worksiteName: e.worksite?.name
|
|
48
|
+
};
|
|
49
|
+
}, te = ({ fromDate: e, id: t, items: n, toDate: r }) => ({
|
|
50
|
+
articleImage: n[0]?.image,
|
|
51
|
+
articleName: n[0]?.name ?? void 0,
|
|
52
|
+
fromDate: d(e),
|
|
53
|
+
id: t,
|
|
54
|
+
toDate: d(r)
|
|
55
|
+
}), p = (e) => e.split(/\s[-–]\s/)[0], m = (e) => {
|
|
56
|
+
let t = u(p(e ?? ""));
|
|
57
|
+
if (t) return c.find((e) => t === e || t.startsWith(`${e} `)) ?? t.split(" ")[0];
|
|
58
|
+
}, h = (e) => [...new Set([e.trim(), e.split(/\s[-–]\s/)[0].trim()])].filter(Boolean), g = (e, t) => {
|
|
59
|
+
let n = t.filter((e, n) => t.findIndex(({ id: t }) => t === e.id) === n);
|
|
60
|
+
return h(e).flatMap((e) => n.filter((t) => u(t.name) === u(e)))[0] ?? (n.length === 1 ? n[0] : void 0);
|
|
61
|
+
}, _ = /\b(s a r l|sarl|s a s u|sasu|s a s|sas|e u r l|eurl|s c i|sci|s n c|snc|soc(?:iete)?(?: a responsabilite limitee| anonyme| par actions simplifiee)?|ste|ets|etablissements?)\b/g, v = [
|
|
62
|
+
"btp",
|
|
63
|
+
"groupe",
|
|
64
|
+
"loc",
|
|
65
|
+
"location",
|
|
66
|
+
"locations",
|
|
67
|
+
"publics",
|
|
68
|
+
"services",
|
|
69
|
+
"tp",
|
|
70
|
+
"transport",
|
|
71
|
+
"transports",
|
|
72
|
+
"travaux"
|
|
73
|
+
], y = (e) => u(p(e ?? "")).replace(_, " ").split(" ").filter(Boolean), ne = (e) => [...y(e)].filter((e) => !v.includes(e)).sort((e, t) => t.length - e.length)[0] ?? e.trim(), b = (e, t) => {
|
|
74
|
+
let n = y(e), r = y(t);
|
|
75
|
+
if (n.length === 0 || r.length === 0) return;
|
|
76
|
+
let i = [n, r].map((e) => c.find((t) => e.join(" ").startsWith(t)));
|
|
77
|
+
if (i[0] || i[1]) return i[0] === i[1];
|
|
78
|
+
let [a, o] = n.length <= r.length ? [n, r] : [r, n];
|
|
79
|
+
return a.every((e) => o.includes(e)) && a.some((e) => !v.includes(e));
|
|
80
|
+
}, x = (e) => l.find(([, t]) => t.test(u(e)))?.[0], S = (e) => i((e ?? "").toLowerCase().replace(/(\d),(\d)/g, "$1.$2").match(/(\d+(?:\.\d+)?)\s*(?:t|tonnes?)\b/)?.[1]) ?? void 0, C = (e, t) => {
|
|
81
|
+
let n = x(e), r = x(t);
|
|
82
|
+
if (!(n && r)) return "unknown";
|
|
83
|
+
if (n !== r) return "different";
|
|
84
|
+
let i = S(e), a = S(t);
|
|
85
|
+
return i !== void 0 && a !== void 0 && Math.abs(i - a) > 1 ? "family" : "same";
|
|
86
|
+
}, w = (e, t) => {
|
|
87
|
+
let n = u(e).split(" ").filter(Boolean), r = t.flatMap((e) => u(e).split(" ")).filter((e) => e.length > 2);
|
|
88
|
+
return n.length > 0 && r.length > 0 && !n.some((e) => r.includes(e));
|
|
89
|
+
}, T = (e, t) => {
|
|
90
|
+
let n = C(e, t);
|
|
91
|
+
return n === "same" || n === "unknown" && !!u(e) && u(e) === u(t);
|
|
92
|
+
}, E = (e, t) => {
|
|
93
|
+
let n = u(e.clientName), r = u(t.clientName);
|
|
94
|
+
return b(O(e), O(t)) === !0 && T(e.machine, t.machine) && !(n && r && n !== r);
|
|
95
|
+
}, D = (e, t) => {
|
|
96
|
+
let n = new Set(u(e).split(" ").filter(Boolean)), r = new Set(u(t).split(" ").filter(Boolean));
|
|
97
|
+
return [...n].filter((e) => r.has(e)).length / Math.max(1, new Set([...n, ...r]).size);
|
|
98
|
+
}, re = ({ from: e, to: t }, n) => {
|
|
99
|
+
if (!(e && t && n.fromDate)) return;
|
|
100
|
+
let r = n.toDate ?? n.fromDate;
|
|
101
|
+
return t < n.fromDate ? a(n.fromDate).diff(t, "day") : e > r ? a(e).diff(r, "day") : 0;
|
|
102
|
+
}, ie = {
|
|
103
|
+
different: o.machineMismatch,
|
|
104
|
+
family: o.machineFamily,
|
|
105
|
+
same: o.machineMet,
|
|
106
|
+
unknown: 0
|
|
107
|
+
}, ae = ({ worksiteName: e }, t, n) => {
|
|
108
|
+
let r = u(e), i = u(t.worksiteName);
|
|
109
|
+
return n || r && r === i ? o.worksiteMet : r && i ? o.worksiteMismatch : 0;
|
|
110
|
+
}, O = ({ supplierName: e, orderSupplier: t }) => t?.name || e?.trim(), oe = (e, t) => {
|
|
111
|
+
let n = b(O(e), t.supplierName);
|
|
112
|
+
return n === void 0 ? 0 : n ? o.supplierMet : o.supplierMismatch;
|
|
113
|
+
}, k = 7, A = (e) => e === 0 ? o.dateMet : e === void 0 || e <= k ? 0 : o.periodMismatch, j = (e, t, { worksiteId: n }) => {
|
|
114
|
+
let r = re(e, t);
|
|
115
|
+
return {
|
|
116
|
+
candidate: t,
|
|
117
|
+
distanceDays: r ?? Infinity,
|
|
118
|
+
machineLikeness: e.machine && t.articleName ? D(e.machine, t.articleName) : 0,
|
|
119
|
+
score: ae(e, t, n) + oe(e, t) + ie[C(e.machine, t.articleName)] + A(r)
|
|
120
|
+
};
|
|
121
|
+
}, M = (e, t, n) => t.map((t) => j(e, t, n)).filter(({ score: e }) => e >= 6).sort((e, t) => t.score - e.score || t.machineLikeness - e.machineLikeness || e.distanceDays - t.distanceDays || (t.candidate.fromDate ?? "").localeCompare(e.candidate.fromDate ?? "")), N = (e, t) => {
|
|
122
|
+
let n = e.find(({ candidate: e }) => e.id === t?.candidate.id);
|
|
123
|
+
return n ? e.filter((e) => e.candidate.id !== n.candidate.id && e.score === n.score && e.machineLikeness === n.machineLikeness && e.distanceDays === n.distanceDays) : [];
|
|
124
|
+
}, P = (e, t, n) => M(e, t, n)[0], F = (e) => u(e).replace(/\b\d+(?:[ .]\d+)?\s*(?:t|tonnes?)\b/g, "").replace(/\s+/g, " ").trim(), I = (t, n, r) => {
|
|
125
|
+
let i = S(t), a = (r) => {
|
|
126
|
+
let a = e(r), o = i !== void 0 && S(r.name) === i;
|
|
127
|
+
return (a === n ? 4 : 0) + (o ? 2 : 0) + D(t, r.name);
|
|
128
|
+
};
|
|
129
|
+
return [...r].sort((e, t) => a(t) - a(e))[0];
|
|
130
|
+
}, L = (e, t) => t && !e.some(({ candidate: e }) => e.id === t.id) ? [...e, { candidate: t }] : e, R = "YYYY-MM-DD", z = /^\d{4}-\d{2}-\d{2}$/, B = (e) => typeof e == "string" && z.test(e) && a(e).format(R) === e, V = ["machine_delivery", "machine_retrieval"], H = "lines", U = (e) => e?.trim() || void 0, W = (e) => i(/^(\d+(?:\.\d+)?) hour$/.exec(e?.trim() ?? "")?.[1]) ?? void 0, G = (e) => {
|
|
131
|
+
let t = e?.trim();
|
|
132
|
+
return B(t) ? t : void 0;
|
|
133
|
+
}, K = (e) => {
|
|
134
|
+
let [t, n, ...r] = e?.split("/").map((e) => G(e)) ?? [];
|
|
135
|
+
return t && n && r.length === 0 && t <= n ? {
|
|
136
|
+
from: t,
|
|
137
|
+
to: n
|
|
138
|
+
} : void 0;
|
|
139
|
+
}, q = ({ tables: e }) => e?.[H] ?? [], J = (e) => {
|
|
140
|
+
let n = q(e).flatMap((e) => {
|
|
141
|
+
let t = G(e.date), n = W(e.quantity);
|
|
142
|
+
return t && n !== void 0 && n <= 24 ? [{
|
|
143
|
+
costCentre: U(e.cost_centre),
|
|
144
|
+
date: t,
|
|
145
|
+
hours: n
|
|
146
|
+
}] : [];
|
|
147
|
+
}), i = (e, t) => e.date === t.date && e.costCentre === t.costCentre;
|
|
148
|
+
return n.filter((e, t) => n.findIndex((t) => i(t, e)) === t).map((e) => ({
|
|
149
|
+
...e,
|
|
150
|
+
hours: r(t(n.filter((t) => i(t, e))))
|
|
151
|
+
})).sort((e, t) => e.date.localeCompare(t.date));
|
|
152
|
+
}, Y = (e) => q(e).flatMap((e) => {
|
|
153
|
+
let t = W(e.quantity);
|
|
154
|
+
return U(e.date) || t === void 0 ? [] : [{
|
|
155
|
+
costCentre: U(e.cost_centre),
|
|
156
|
+
equipment: U(e.equipment),
|
|
157
|
+
hours: t,
|
|
158
|
+
orderNumber: U(e.order_number),
|
|
159
|
+
period: K(e.period),
|
|
160
|
+
place: U(e.place),
|
|
161
|
+
taskCode: U(e.task_code)
|
|
162
|
+
}];
|
|
163
|
+
}), se = (e) => {
|
|
164
|
+
let n = W(e.fields?.written_total), r = [...J(e), ...Y(e)];
|
|
165
|
+
return n === void 0 ? r.length > 0 ? t(r) : void 0 : n;
|
|
166
|
+
}, X = (e) => e.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().replace(/[^a-z0-9]+/g, " ").trim(), Z = (e, t) => {
|
|
167
|
+
let n = X(e), r = X(t);
|
|
168
|
+
return n.includes(r) || r.includes(n);
|
|
169
|
+
}, ce = /\b(livraison|amenee|aller|acheminement|delivery)\b/, le = /\b(reprise|repli|retour|enlevement|pickup|pick up|collection)\b/, ue = /\b(transport|transports|transfert)\b/, Q = (e) => {
|
|
170
|
+
let t = X(e), n = ce.test(t), r = le.test(t), i = !(n || r) && ue.test(t);
|
|
171
|
+
return V.filter((e) => e === "machine_delivery" ? n || i : r || i);
|
|
172
|
+
}, $ = (e) => [e.fields?.equipment, ...q(e).map((e) => e.equipment)].flatMap((e) => U(e) ?? []), de = (e) => {
|
|
173
|
+
let t = $(e).filter((e) => Q(e).length === 0), n = t.filter((e, n) => t.findIndex((t) => Z(t, e)) === n), r = U([e.fields?.machine_brand, e.fields?.model].filter(Boolean).join(" "));
|
|
174
|
+
return n.length > 0 ? n : r ? [r] : [];
|
|
175
|
+
}, fe = (e) => {
|
|
176
|
+
let t = e.fields ?? {}, n = q(e).flatMap((e) => {
|
|
177
|
+
let t = K(e.period);
|
|
178
|
+
return [
|
|
179
|
+
G(e.date),
|
|
180
|
+
t?.from,
|
|
181
|
+
t?.to
|
|
182
|
+
].flatMap((e) => e ?? []);
|
|
183
|
+
}).sort(), r = K(t.period), i = G(t.issue_date), [a, ...o] = de(e), s = V.filter((t) => $(e).some((e) => Q(e).includes(t)));
|
|
184
|
+
return {
|
|
185
|
+
clientName: U(t.client),
|
|
186
|
+
from: n[0] ?? r?.from ?? i,
|
|
187
|
+
hours: se(e),
|
|
188
|
+
machine: a,
|
|
189
|
+
operatorName: U(t.driver),
|
|
190
|
+
otherLines: o.length > 0 ? o.map((e, t) => ({
|
|
191
|
+
id: `read-${t + 1}`,
|
|
192
|
+
machine: e
|
|
193
|
+
})) : void 0,
|
|
194
|
+
supplierName: U(t.supplier),
|
|
195
|
+
to: n.at(-1) ?? r?.to ?? i,
|
|
196
|
+
transports: s.length > 0 ? s : void 0,
|
|
197
|
+
worksiteName: U(t.worksite),
|
|
198
|
+
writtenHours: W(t.written_total)
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
//#endregion
|
|
202
|
+
export { s as MIN_MATCH_SCORE, V as TRANSPORT_TYPES, P as bestMatchOf, m as brandOf, f as candidateOf, te as candidateOfSearch, p as companyNameOf, J as daysOfAnalysis, fe as factsOfAnalysis, w as isAddressedElsewhere, E as isSameRental, b as isSameSupplier, F as machineSearchOf, M as matchesOf, L as proposalsOf, I as rentalArticleFor, N as rivalsOf, j as scoreOf, ne as supplierSearchOf, y as supplierWordsOf, S as tonnageOf, Q as transportTypesOf, Y as undatedHoursOfAnalysis, g as worksiteOfName, h as worksiteSearchesOf };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type of an hour sheet among an order's documents.
|
|
3
|
+
*/
|
|
4
|
+
export declare const HOUR_SHEET_DOCUMENT_TYPE = "HOUR_SHEET";
|
|
5
|
+
/**
|
|
6
|
+
* Imputation key of the sheet's chart of accounts: one per sheet, repeated on each of its lines.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CHART_OF_ACCOUNTS_FIELD = "plan_de_compte";
|
|
9
|
+
/**
|
|
10
|
+
* Imputation key of a day's cost centre: an entity of the chart of accounts.
|
|
11
|
+
*/
|
|
12
|
+
export declare const COST_CENTRE_FIELD = "centre_de_cout";
|
|
13
|
+
/**
|
|
14
|
+
* Imputation key of a line's OM: a billing reference of its cost centre, to name when the cost centre has several.
|
|
15
|
+
*/
|
|
16
|
+
export declare const BILLING_REFERENCE_FIELD = "billing_reference";
|
|
17
|
+
/**
|
|
18
|
+
* The order form's fields a day can be charged to, besides the chart of accounts: the keys the API bills on.
|
|
19
|
+
*/
|
|
20
|
+
export declare const IMPUTATION_FIELDS: readonly ["centre_de_cout", "code_tache", "sous_livre", "divers"];
|
|
21
|
+
/**
|
|
22
|
+
* Label of an overtime line: extra hours the sheet prices apart from the day's, imputed on their own.
|
|
23
|
+
*/
|
|
24
|
+
export declare const OVERTIME_LABEL = "overtime";
|
|
25
|
+
/**
|
|
26
|
+
* A day holds no more hours than it has: the API refuses a longer one.
|
|
27
|
+
*/
|
|
28
|
+
export declare const MAX_HOURS_PER_DAY = 24;
|
|
29
|
+
/**
|
|
30
|
+
* Days a sheet extends its order by at most, before or after its dates: further, a day misread or mistyped would bill
|
|
31
|
+
* weeks. The API refuses more.
|
|
32
|
+
*/
|
|
33
|
+
export declare const MAX_RENTAL_EXTENSION_DAYS = 31;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point `@getsoren/shared-module/hourSheets`: the rules of a driver's hour sheets. Its days and its overtime, the
|
|
3
|
+
* document lines they state, what they are charged to, and what keeps a sheet from being saved. Pure data and logic
|
|
4
|
+
* shared by the back office and the mobile app, which each render their own review.
|
|
5
|
+
*/
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export type * from './types';
|
|
8
|
+
export * from './utils/billingReferences/billingReferences';
|
|
9
|
+
export * from './utils/imputation/imputation';
|
|
10
|
+
export * from './utils/readCostCentres/readCostCentres';
|
|
11
|
+
export * from './utils/sheetBlocker/sheetBlocker';
|
|
12
|
+
export * from './utils/sheetDays/sheetDays';
|
|
13
|
+
export * from './utils/sheetLines/sheetLines';
|