@getsoren/shared-module 2.68.0 → 2.69.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +15 -0
  2. package/dist/documentImport.js +202 -0
  3. package/dist/events.js +1 -1
  4. package/dist/hourSheets.js +58 -0
  5. package/dist/main.d.ts +6 -6
  6. package/dist/main.js +512 -548
  7. package/dist/{context → modules/chat/context}/ChatProvider.d.ts +1 -1
  8. package/dist/{hooks → modules/chat/hooks}/useChat.d.ts +1 -1
  9. package/dist/modules/documentImport/index.d.ts +9 -0
  10. package/dist/modules/documentImport/types.d.ts +127 -0
  11. package/dist/modules/documentImport/utils/matching/matching.d.ts +144 -0
  12. package/dist/modules/documentImport/utils/proposals/proposals.d.ts +10 -0
  13. package/dist/modules/documentImport/utils/reading/reading.d.ts +26 -0
  14. package/dist/modules/events/utils/payload/payload.test.d.ts +1 -0
  15. package/dist/modules/events/utils/readEvent/readEvent.test.d.ts +1 -0
  16. package/dist/modules/events/utils/steps/steps.test.d.ts +1 -0
  17. package/dist/modules/hourSheets/constants.d.ts +33 -0
  18. package/dist/modules/hourSheets/index.d.ts +13 -0
  19. package/dist/modules/hourSheets/types.d.ts +143 -0
  20. package/dist/modules/hourSheets/utils/billingReferences/billingReferences.d.ts +35 -0
  21. package/dist/modules/hourSheets/utils/billingReferences/billingReferences.test.d.ts +1 -0
  22. package/dist/modules/hourSheets/utils/imputation/imputation.d.ts +44 -0
  23. package/dist/modules/hourSheets/utils/imputation/imputation.test.d.ts +1 -0
  24. package/dist/modules/hourSheets/utils/readCostCentres/readCostCentres.d.ts +42 -0
  25. package/dist/modules/hourSheets/utils/readCostCentres/readCostCentres.test.d.ts +1 -0
  26. package/dist/modules/hourSheets/utils/sheetBlocker/sheetBlocker.d.ts +53 -0
  27. package/dist/modules/hourSheets/utils/sheetBlocker/sheetBlocker.test.d.ts +1 -0
  28. package/dist/modules/hourSheets/utils/sheetDays/sheetDays.d.ts +68 -0
  29. package/dist/modules/hourSheets/utils/sheetDays/sheetDays.test.d.ts +1 -0
  30. package/dist/modules/hourSheets/utils/sheetLines/sheetLines.d.ts +103 -0
  31. package/dist/modules/hourSheets/utils/sheetLines/sheetLines.test.d.ts +1 -0
  32. package/dist/operator-Cj1X_Zg5.js +41 -0
  33. package/dist/orval.js +1 -1
  34. package/dist/sheetLines-DECsEz55.js +123 -0
  35. package/package.json +17 -2
  36. /package/dist/{chat → modules/chat}/ChatClient.d.ts +0 -0
  37. /package/dist/{chat → modules/chat}/tests/ChatClient.test.d.ts +0 -0
  38. /package/dist/{chat → modules/chat}/types.d.ts +0 -0
  39. /package/dist/{events/hooks/useEventDeclaration/useEventDeclaration.test.d.ts → modules/documentImport/utils/matching/matching.test.d.ts} +0 -0
  40. /package/dist/{events/tenants/tenants.test.d.ts → modules/documentImport/utils/proposals/proposals.test.d.ts} +0 -0
  41. /package/dist/{events/utils/amounts/amounts.test.d.ts → modules/documentImport/utils/reading/reading.test.d.ts} +0 -0
  42. /package/dist/{events → modules/events}/catalog/clientEvents.d.ts +0 -0
  43. /package/dist/{events → modules/events}/catalog/supplierEvents.d.ts +0 -0
  44. /package/dist/{events → modules/events}/constants.d.ts +0 -0
  45. /package/dist/{events → modules/events}/hooks/useEventDeclaration/useEventDeclaration.d.ts +0 -0
  46. /package/dist/{events/utils/credits/credits.test.d.ts → modules/events/hooks/useEventDeclaration/useEventDeclaration.test.d.ts} +0 -0
  47. /package/dist/{events → modules/events}/index.d.ts +0 -0
  48. /package/dist/{events → modules/events}/locales/ar.d.ts +0 -0
  49. /package/dist/{events → modules/events}/locales/de.d.ts +0 -0
  50. /package/dist/{events → modules/events}/locales/en.d.ts +0 -0
  51. /package/dist/{events → modules/events}/locales/es.d.ts +0 -0
  52. /package/dist/{events → modules/events}/locales/fr.d.ts +0 -0
  53. /package/dist/{events → modules/events}/locales/it.d.ts +0 -0
  54. /package/dist/{events → modules/events}/locales/locales.d.ts +0 -0
  55. /package/dist/{events → modules/events}/locales/pt.d.ts +0 -0
  56. /package/dist/{events → modules/events}/tenants/bouygues/bouygues.d.ts +0 -0
  57. /package/dist/{events → modules/events}/tenants/index.d.ts +0 -0
  58. /package/dist/{events/utils/lineFunnel/lineFunnel.test.d.ts → modules/events/tenants/tenants.test.d.ts} +0 -0
  59. /package/dist/{events → modules/events}/types.d.ts +0 -0
  60. /package/dist/{events → modules/events}/utils/amounts/amounts.d.ts +0 -0
  61. /package/dist/{events/utils/payload/payload.test.d.ts → modules/events/utils/amounts/amounts.test.d.ts} +0 -0
  62. /package/dist/{events → modules/events}/utils/credits/credits.d.ts +0 -0
  63. /package/dist/{events/utils/readEvent/readEvent.test.d.ts → modules/events/utils/credits/credits.test.d.ts} +0 -0
  64. /package/dist/{events → modules/events}/utils/lineFunnel/lineFunnel.d.ts +0 -0
  65. /package/dist/{events/utils/steps/steps.test.d.ts → modules/events/utils/lineFunnel/lineFunnel.test.d.ts} +0 -0
  66. /package/dist/{events → modules/events}/utils/payload/payload.d.ts +0 -0
  67. /package/dist/{events → modules/events}/utils/readEvent/readEvent.d.ts +0 -0
  68. /package/dist/{events → modules/events}/utils/steps/steps.d.ts +0 -0
  69. /package/dist/{orval-Bf_zcxLE.js → orval-BSFwOlVR.js} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { PropsWithChildren } from 'react';
2
- import { ServerEvent } from '../chat/types';
2
+ import { ServerEvent } from '../types';
3
3
  type EventListener = (event: ServerEvent) => void;
4
4
  type ChatContext = "client" | "supplier";
5
5
  export interface ChatProviderProps {
@@ -1,5 +1,5 @@
1
- import { UseChatParams } from '../chat/types';
2
1
  import { ChatContextValue } from '../context/ChatProvider';
2
+ import { UseChatParams } from '../types';
3
3
  type UseChatReturn = Omit<ChatContextValue, "subscribe" | "setEnabled">;
4
4
  /**
5
5
  * Hook to access the shared WebSocket chat connection.
@@ -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,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,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,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';
@@ -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,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,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;