@getsoren/shared-module 2.62.0 → 2.63.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.
@@ -5,11 +5,11 @@ import { EventFunnel } from '../types';
5
5
  */
6
6
  export declare const CLIENT_EVENTS: {
7
7
  breakage: {
8
- amountGate: "known";
9
8
  dates: "single";
10
9
  dayHint: "breakage";
11
10
  defaultsToToday: true;
12
11
  hasIntervention: true;
12
+ hasOptionalAmount: true;
13
13
  id: string;
14
14
  price: "amount";
15
15
  questions: {
@@ -31,9 +31,9 @@ export declare const CLIENT_EVENTS: {
31
31
  reason: string;
32
32
  };
33
33
  delivery_problem: {
34
- amountGate: "known";
35
34
  dates: "single";
36
35
  dayHint: "deliveryProblem";
36
+ hasOptionalAmount: true;
37
37
  id: string;
38
38
  price: "amount";
39
39
  questions: {
@@ -72,6 +72,7 @@ export declare const CLIENT_EVENTS: {
72
72
  id: string;
73
73
  price: "credit";
74
74
  reason: string;
75
+ suggestsDailyShare: true;
75
76
  };
76
77
  inventory: {
77
78
  closesOnSubmit: true;
@@ -102,9 +103,9 @@ export declare const CLIENT_EVENTS: {
102
103
  reason: string;
103
104
  };
104
105
  material_usage: {
105
- amountGate: "known";
106
106
  dates: "single";
107
107
  dayHint: "problem";
108
+ hasOptionalAmount: true;
108
109
  id: string;
109
110
  price: "amount";
110
111
  questions: {
@@ -160,17 +161,17 @@ export declare const CLIENT_EVENTS: {
160
161
  reason: string;
161
162
  };
162
163
  other: {
163
- amountGate: "known";
164
164
  dates: "single";
165
165
  dayHint: "event";
166
+ hasOptionalAmount: true;
166
167
  hasTitle: true;
167
168
  id: string;
168
169
  price: "amount";
169
170
  };
170
171
  other_material: {
171
- amountGate: "known";
172
172
  dates: "single";
173
173
  dayHint: "problem";
174
+ hasOptionalAmount: true;
174
175
  hasTitle: true;
175
176
  id: string;
176
177
  price: "amount";
@@ -186,9 +187,9 @@ export declare const CLIENT_EVENTS: {
186
187
  price: "amount";
187
188
  };
188
189
  robbery: {
189
- amountGate: "known";
190
190
  dates: "single";
191
191
  dayHint: "robbery";
192
+ hasOptionalAmount: true;
192
193
  id: string;
193
194
  price: "amount";
194
195
  questions: {
@@ -206,6 +207,7 @@ export declare const CLIENT_EVENTS: {
206
207
  dates: "weatherDays";
207
208
  };
208
209
  reason: string;
210
+ suggestsDailyShare: true;
209
211
  };
210
212
  };
211
213
  export type ClientEventId = keyof typeof CLIENT_EVENTS;
@@ -14,9 +14,13 @@ export interface UseEventDeclarationParams {
14
14
  * Today (YYYY-MM-DD) when the order's calendar offers it: an event declared the day it happens starts on it.
15
15
  */
16
16
  today?: string;
17
+ /**
18
+ * The one day (YYYY-MM-DD) of an order of one day: its events happen that day, their dates step is not asked.
19
+ */
20
+ onlyDay?: string;
17
21
  }
18
22
  /** The declaration of an event, step by step, whatever renders it. */
19
- declare const useEventDeclaration: ({ funnel, countBillableDays, dailyPrice, lastReBillRatio, isEditing, today, }: UseEventDeclarationParams) => {
23
+ declare const useEventDeclaration: ({ funnel, countBillableDays, dailyPrice, lastReBillRatio, isEditing, today, onlyDay, }: UseEventDeclarationParams) => {
20
24
  amounts: import('../../utils/amounts/amounts').EventAmounts;
21
25
  answers: EventAnswers;
22
26
  asksAmount: boolean;
@@ -53,6 +53,11 @@ export interface EventDefinition {
53
53
  amountGate?: EventAmountGate;
54
54
  /** The amount asked can be left empty: the event is then declared without one. */
55
55
  hasOptionalAmount?: boolean;
56
+ /**
57
+ * A credit a supplier settles as a share of the daily price over the days hit (half of it for these two days), the
58
+ * shares of `DAILY_PRICE_SHARES` offered before an amount per day.
59
+ */
60
+ suggestsDailyShare?: boolean;
56
61
  /**
57
62
  * The sum is billed or taken off the invoice, the user saying which (`answers.isCreditNote`): a credit note is
58
63
  * declared like an extra.
@@ -19,6 +19,18 @@ export declare const getUnitPrice: (event: EventDefinition, answers: Pick<EventA
19
19
  * A period of one day counts one whatever the calendar, as the backend bills it, and so does an event without a period.
20
20
  */
21
21
  export declare const getEventAmounts: (event: EventDefinition | undefined, answers: EventAnswers, billableDays: number) => EventAmounts;
22
+ /**
23
+ * The shares of the daily price a supplier usually deducts, in percent, the whole of it first.
24
+ */
25
+ export declare const DAILY_PRICE_SHARES: number[];
26
+ /**
27
+ * A share of the daily price, to the cent: 75 % of 36,50 € is 27,38 €.
28
+ */
29
+ export declare const getShareAmount: (dailyPrice: number, percent: number) => number;
30
+ /**
31
+ * The share an amount matches, if any: another amount is no share.
32
+ */
33
+ export declare const findShare: (dailyPrice: number, amount: number | null) => number | undefined;
22
34
  /**
23
35
  * Whether an event still waits for its amount: it has a price and none goes with it, though its days are billed and
24
36
  * nobody answered that there was nothing to bill. `isSent` is false for a user who sees no price, whose amount on
@@ -7,8 +7,11 @@ export interface FunnelGroup extends Omit<EventGroup, "events"> {
7
7
  export declare const getFunnelGroups: ({ groups, events }: EventFunnel) => FunnelGroup[];
8
8
  /** The one date of an end of rental, which depends on the end picked. */
9
9
  export declare const getEndDate: (event: EventDefinition, reason: string) => import('../../types').EventEndDate | undefined;
10
- /** `asksAmount` is false for a user who sees no price, or a credit that falls on no billed day. */
11
- export declare const getSteps: (group: FunnelGroup | undefined, event: EventDefinition | undefined, answers: EventAnswers, asksAmount: boolean) => EventStep[];
10
+ /**
11
+ * `asksAmount` is false for a user who sees no price, or a credit that falls on no billed day. `hasOnlyDay` is true on
12
+ * an order of one day, whose events happen that day: their dates are not asked (an end of rental still asks its own).
13
+ */
14
+ export declare const getSteps: (group: FunnelGroup | undefined, event: EventDefinition | undefined, answers: EventAnswers, asksAmount: boolean, hasOnlyDay?: boolean) => EventStep[];
12
15
  /** First question after the family and the event, skipping a reason already given unless asked again. */
13
16
  export declare const getFirstQuestion: (steps: EventStep[], answers: EventAnswers, asksAgain?: boolean) => EventStep;
14
17
  export declare const isStepAnswered: (step: EventStep, event: EventDefinition, answers: EventAnswers) => boolean;
package/dist/events.js CHANGED
@@ -10,11 +10,11 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
10
10
  unitPrice: "unitPrice"
11
11
  }, o = "inventory", s = {
12
12
  breakage: {
13
- amountGate: "known",
14
13
  dates: "single",
15
14
  dayHint: "breakage",
16
15
  defaultsToToday: !0,
17
16
  hasIntervention: !0,
17
+ hasOptionalAmount: !0,
18
18
  id: "breakage",
19
19
  price: "amount",
20
20
  questions: { reason: "breakageKind" },
@@ -34,9 +34,9 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
34
34
  reason: "breakdown"
35
35
  },
36
36
  delivery_problem: {
37
- amountGate: "known",
38
37
  dates: "single",
39
38
  dayHint: "deliveryProblem",
39
+ hasOptionalAmount: !0,
40
40
  id: "delivery_problem",
41
41
  price: "amount",
42
42
  questions: { reason: "deliveryProblemKind" },
@@ -74,7 +74,8 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
74
74
  hasOptionalAmount: !0,
75
75
  id: "immobilisation",
76
76
  price: "credit",
77
- reason: "immobilisation"
77
+ reason: "immobilisation",
78
+ suggestsDailyShare: !0
78
79
  },
79
80
  [o]: {
80
81
  closesOnSubmit: !0,
@@ -111,9 +112,9 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
111
112
  reason: "Affectation machine"
112
113
  },
113
114
  material_usage: {
114
- amountGate: "known",
115
115
  dates: "single",
116
116
  dayHint: "problem",
117
+ hasOptionalAmount: !0,
117
118
  id: "material_usage",
118
119
  price: "amount",
119
120
  questions: { reason: "materialUsageKind" },
@@ -188,17 +189,17 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
188
189
  reason: "operator_change"
189
190
  },
190
191
  other: {
191
- amountGate: "known",
192
192
  dates: "single",
193
193
  dayHint: "event",
194
+ hasOptionalAmount: !0,
194
195
  hasTitle: !0,
195
196
  id: "other",
196
197
  price: "amount"
197
198
  },
198
199
  other_material: {
199
- amountGate: "known",
200
200
  dates: "single",
201
201
  dayHint: "problem",
202
+ hasOptionalAmount: !0,
202
203
  hasTitle: !0,
203
204
  id: "other_material",
204
205
  price: "amount"
@@ -214,9 +215,9 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
214
215
  price: "amount"
215
216
  },
216
217
  robbery: {
217
- amountGate: "known",
218
218
  dates: "single",
219
219
  dayHint: "robbery",
220
+ hasOptionalAmount: !0,
220
221
  id: "robbery",
221
222
  price: "amount",
222
223
  questions: {
@@ -231,7 +232,8 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
231
232
  id: "weather",
232
233
  price: "credit",
233
234
  questions: { dates: "weatherDays" },
234
- reason: "weather"
235
+ reason: "weather",
236
+ suggestsDailyShare: !0
235
237
  }
236
238
  }, c = {
237
239
  admin_request: {
@@ -445,36 +447,41 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
445
447
  total: a === null ? null : a * o,
446
448
  unitPrice: a
447
449
  };
448
- }, h = (e, { hasNothingToBill: t, unitPrice: n }, r = !0) => !!e.price && !(r && n !== null) && !t && e.amountGate !== "billed", g = ({ groups: e, events: t }) => e.flatMap((e) => {
450
+ }, h = [
451
+ 100,
452
+ 75,
453
+ 50,
454
+ 25
455
+ ], g = (e, t) => Math.round(e * t) / 100, _ = (e, t) => h.find((n) => t === g(e, n)), v = (e, { hasNothingToBill: t, unitPrice: n }, r = !0) => !!e.price && !(r && n !== null) && !t && e.amountGate !== "billed", y = ({ groups: e, events: t }) => e.flatMap((e) => {
449
456
  let n = t.filter(({ id: t }) => e.events.includes(t));
450
457
  return n.length ? [{
451
458
  ...e,
452
459
  events: n
453
460
  }] : [];
454
- }), _ = (e, t) => e.endDates?.[t], v = (e, t, n, r) => [
461
+ }), b = (e, t) => e.endDates?.[t], x = (e, t, n, r, i = !1) => [
455
462
  "kind",
456
463
  ...(e?.events.length ?? 0) > 1 ? ["event"] : [],
457
464
  ...t?.reasons?.length ? ["reason"] : [],
458
- ...t?.dates || t && _(t, n.reason) ? ["dates"] : [],
465
+ ...t?.dates && !i || t && b(t, n.reason) ? ["dates"] : [],
459
466
  ...t?.checks?.length ? ["checks"] : [],
460
467
  ...t?.hasTitle || t?.fields?.length ? ["fields"] : [],
461
468
  ...r && t?.price && t.amountGate ? ["amountGate"] : [],
462
469
  ...r && t?.price && (!t.amountGate || n.amountGate) ? ["amount"] : [],
463
470
  ...t ? ["details"] : []
464
- ], y = (e, t, n = !1) => e.find((e) => e !== "kind" && e !== "event" && (n || e !== "reason" || !t.reason)) ?? "details", b = ({ name: e, required: t, type: n }, { fields: r }) => {
471
+ ], S = (e, t, n = !1) => e.find((e) => e !== "kind" && e !== "event" && (n || e !== "reason" || !t.reason)) ?? "details", C = ({ name: e, required: t, type: n }, { fields: r }) => {
465
472
  let i = r[e]?.trim() ?? "";
466
473
  return i ? n !== "number" || f(i) !== null : !t;
467
- }, x = (e, t, n) => {
474
+ }, w = (e, t, n) => {
468
475
  switch (e) {
469
476
  case "reason": return !!n.reason;
470
477
  case "dates": return !!(n.dates.fromDate && n.dates.toDate);
471
- case "fields": return (!t.hasTitle || !!n.title.trim()) && (t.fields ?? []).every((e) => b(e, n));
478
+ case "fields": return (!t.hasTitle || !!n.title.trim()) && (t.fields ?? []).every((e) => C(e, n));
472
479
  case "amountGate": return n.amountGate !== void 0;
473
480
  case "amount": return !!t.hasOptionalAmount && !n.isCreditNote || p(t, n) !== null;
474
481
  default: return !0;
475
482
  }
476
- }, S = (e, t) => e.hasTitle ? t.title.trim() : e.reasonDetail ? e.reason ?? "" : t.reason || (e.reason ?? ""), C = (e, t, n) => {
477
- let r = S(e, t);
483
+ }, T = (e, t) => e.hasTitle ? t.title.trim() : e.reasonDetail ? e.reason ?? "" : t.reason || (e.reason ?? ""), E = (e, t, n) => {
484
+ let r = T(e, t);
478
485
  if (e.hasTitle) return {
479
486
  label: n("values.title"),
480
487
  name: a.reason,
@@ -493,8 +500,8 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
493
500
  value: r
494
501
  }
495
502
  };
496
- }, w = (e, { dates: { fromDate: t, toDate: n }, reason: r }, i) => {
497
- let o = _(e, r);
503
+ }, D = (e, { dates: { fromDate: t, toDate: n }, reason: r }, i) => {
504
+ let o = b(e, r);
498
505
  return t && n ? o ? [{
499
506
  label: i(`values.${o.name}`),
500
507
  name: o.name,
@@ -511,18 +518,18 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
511
518
  type: "date",
512
519
  value: t
513
520
  }] : [] : [];
514
- }, T = (e, t) => {
521
+ }, O = (e, t) => {
515
522
  let n = e === "number" ? f(t) : null;
516
523
  return n === null ? t.trim() : String(n);
517
- }, E = "dedicated", D = (e, t) => ({
524
+ }, k = "dedicated", A = (e, t) => ({
518
525
  eventId: t,
519
- funnel: E,
526
+ funnel: k,
520
527
  side: e,
521
528
  source: r,
522
529
  version: 2
523
- }), O = (e) => typeof e == "object" && !!e && "source" in e && e.source === "soren-event" && "eventId" in e && typeof e.eventId == "string", k = ({ funnel: e, event: t, answers: n, translate: i, bookingItemId: o, withPrice: s, billableDays: c, withReBillRatio: l = e.pricing.asksReBillRatio }) => {
530
+ }), j = (e) => typeof e == "object" && !!e && "source" in e && e.source === "soren-event" && "eventId" in e && typeof e.eventId == "string", M = ({ funnel: e, event: t, answers: n, translate: i, bookingItemId: o, withPrice: s, billableDays: c, withReBillRatio: l = e.pricing.asksReBillRatio }) => {
524
531
  let { fromDate: u, toDate: d } = n.dates, m = !!(t.dates && u && d) && c !== 0, h = s ? p(t, n) : null, g = f(n.reBillRatio), _ = n.description.trim(), v = t.billingType === "DELTA", y = f(n.fields.quantity ?? ""), b = [
525
- C(t, n, i),
532
+ E(t, n, i),
526
533
  ...t.reasonDetail && n.reason ? [{
527
534
  label: i(`values.${t.reasonDetail}`),
528
535
  name: t.reasonDetail,
@@ -532,7 +539,7 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
532
539
  value: n.reason
533
540
  }
534
541
  }] : [],
535
- ...w(t, n, i),
542
+ ...D(t, n, i),
536
543
  ..._ ? [{
537
544
  label: i("values.description"),
538
545
  name: a.description,
@@ -550,7 +557,7 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
550
557
  label: i(`fields.${e}`),
551
558
  name: e,
552
559
  type: t,
553
- value: T(t, n.fields[e])
560
+ value: O(t, n.fields[e])
554
561
  })),
555
562
  ...t.hasIntervention ? [{
556
563
  label: i("values.intervention"),
@@ -590,7 +597,7 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
590
597
  quantity: y
591
598
  }
592
599
  };
593
- }, A = {
600
+ }, N = {
594
601
  amount: "",
595
602
  checks: {},
596
603
  dates: {
@@ -603,99 +610,103 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
603
610
  reason: "",
604
611
  reBillRatio: "",
605
612
  title: ""
606
- }, j = ({ funnel: n, countBillableDays: r, dailyPrice: i, lastReBillRatio: a = "", isEditing: o = !1, today: s }) => {
607
- let [c, l] = t(), [u, d] = t(), [f, p] = t("kind"), [h, _] = t(A), [b, S] = t(!1), C = e(() => g(n), [n]), w = C.find(({ id: e }) => e === c), T = w?.events.find(({ id: e }) => e === u), { showsPrice: E, asksReBillRatio: D } = n.pricing, O = m(T, h, T?.dates === "range" ? r(h.dates) : 1), j = E && !!T?.price, M = j && !O.hasNothingToBill, N = v(w, T, h, M), P = N[N.indexOf(f) - 1], F = (e) => _((t) => ({
613
+ }, P = ({ funnel: n, countBillableDays: r, dailyPrice: i, lastReBillRatio: a = "", isEditing: o = !1, today: s, onlyDay: c }) => {
614
+ let [l, u] = t(), [d, f] = t(), [p, h] = t("kind"), [g, _] = t(N), [v, b] = t(!1), C = e(() => y(n), [n]), T = C.find(({ id: e }) => e === l), E = T?.events.find(({ id: e }) => e === d), { showsPrice: D, asksReBillRatio: O } = n.pricing, k = m(E, g, E?.dates === "range" ? r(g.dates) : 1), A = D && !!E?.price, j = A && !k.hasNothingToBill, P = x(T, E, g, j, !!c), F = P[P.indexOf(p) - 1], I = (e) => _((t) => ({
608
615
  ...t,
609
616
  ...e
610
- })), I = (e) => e.price === "credit" && i ? String(Math.abs(i)) : "", L = (e, t) => {
611
- let n = v(w, T, t, M);
617
+ })), L = (e) => c && e.dates ? {
618
+ fromDate: c,
619
+ toDate: c
620
+ } : e.defaultsToToday && s ? {
621
+ fromDate: s,
622
+ toDate: s
623
+ } : N.dates, R = (e) => e.price === "credit" && i ? String(Math.abs(i)) : "", z = (e, t) => {
624
+ let n = x(T, E, t, j, !!c);
612
625
  return n[n.indexOf(e) + 1] ?? "details";
613
- }, R = () => {
614
- l(void 0), d(void 0), p("kind"), _(A), S(!1);
615
- }, z = (e, t, n = {}) => {
616
- let r = {
617
- ...A,
618
- amount: I(t),
619
- dates: t.defaultsToToday && s ? {
620
- fromDate: s,
621
- toDate: s
622
- } : A.dates,
626
+ }, B = () => {
627
+ u(void 0), f(void 0), h("kind"), _(N), b(!1);
628
+ }, V = (e, t, n = {}) => {
629
+ let r = L(t), i = {
630
+ ...N,
631
+ amount: R(t),
632
+ dates: r,
623
633
  reason: t.reasons?.length ? "" : t.reason ?? "",
624
- reBillRatio: D ? a : "",
625
- ...n
634
+ reBillRatio: O ? a : "",
635
+ ...n,
636
+ ...c && !n.dates?.fromDate && { dates: r }
626
637
  };
627
- l(e.id), d(t.id), _(r), p(y(v(e, t, r, E && !!t.price), r, o));
628
- }, B = ({ eventId: e, answers: t }) => {
638
+ u(e.id), f(t.id), _(i), h(S(x(e, t, i, D && !!t.price, !!c), i, o));
639
+ }, H = ({ eventId: e, answers: t }) => {
629
640
  let n = C.find(({ events: t }) => t.some(({ id: t }) => t === e)), r = n?.events.find(({ id: t }) => t === e);
630
- return n && r ? (z(n, r, t), S(!0), !0) : !1;
631
- }, V = (e, t) => {
641
+ return n && r ? (V(n, r, t), b(!0), !0) : !1;
642
+ }, U = (e, t) => {
632
643
  if (e.events.length === 1) {
633
- z(e, e.events[0], t);
644
+ V(e, e.events[0], t);
634
645
  return;
635
646
  }
636
- l(e.id), d(void 0), p("event");
637
- }, H = (e) => {
638
- w && z(w, e);
639
- }, U = () => p(L(f, h)), W = (e) => {
640
- let t = T?.endDates && e !== h.reason ? {
641
- dates: A.dates,
647
+ u(e.id), f(void 0), h("event");
648
+ }, W = (e) => {
649
+ T && V(T, e);
650
+ }, G = () => h(z(p, g)), K = (e) => {
651
+ let t = E?.endDates && e !== g.reason ? {
652
+ dates: N.dates,
642
653
  reason: e
643
654
  } : { reason: e }, n = {
644
- ...h,
655
+ ...g,
645
656
  ...t
646
657
  };
647
- F(t), p(L("reason", n));
648
- }, G = (e) => {
658
+ I(t), h(z("reason", n));
659
+ }, q = (e) => {
649
660
  let t = {
650
- amount: e && T ? h.amount || I(T) : "",
661
+ amount: e && E ? g.amount || R(E) : "",
651
662
  amountGate: e
652
663
  };
653
- F(t), p(L("amountGate", {
654
- ...h,
664
+ I(t), h(z("amountGate", {
665
+ ...g,
655
666
  ...t
656
667
  }));
657
- }, K = () => {
658
- if (!P || P === "kind") {
659
- R();
668
+ }, J = () => {
669
+ if (!F || F === "kind") {
670
+ B();
660
671
  return;
661
672
  }
662
- p(P);
663
- }, q = !!T && N.every((e) => x(e, T, h)), J = o && !E && !O.hasNothingToBill;
673
+ h(F);
674
+ }, Y = !!E && P.every((e) => w(e, E, g)), X = o && !D && !k.hasNothingToBill;
664
675
  return {
665
- amounts: O,
666
- answers: h,
667
- asksAmount: M,
668
- buildPayload: (e, t) => T && q ? k({
669
- answers: h,
670
- billableDays: O.billableDays,
676
+ amounts: k,
677
+ answers: g,
678
+ asksAmount: j,
679
+ buildPayload: (e, t) => E && Y ? M({
680
+ answers: g,
681
+ billableDays: k.billableDays,
671
682
  bookingItemId: t,
672
- event: T,
683
+ event: E,
673
684
  funnel: n,
674
685
  translate: e,
675
- withPrice: M || J,
676
- withReBillRatio: D || o
686
+ withPrice: j || X,
687
+ withReBillRatio: O || o
677
688
  }) : void 0,
678
- canGoBack: f !== "kind" && !(b && (P === "kind" || P === "event")),
679
- canGoNext: !!T && x(f, T, h),
680
- event: T,
681
- goBack: K,
682
- goNext: U,
683
- group: w,
689
+ canGoBack: p !== "kind" && !(v && (F === "kind" || F === "event")),
690
+ canGoNext: !!E && w(p, E, g),
691
+ event: E,
692
+ goBack: J,
693
+ goNext: G,
694
+ group: T,
684
695
  groups: C,
685
- isComplete: q,
686
- isPriced: j,
687
- reset: R,
688
- selectAmountGate: G,
689
- selectEvent: H,
690
- selectGroup: V,
691
- selectReason: W,
692
- setAnswers: F,
693
- showsReBillRatio: D && j,
694
- startPrefill: B,
695
- step: f,
696
- steps: N
696
+ isComplete: Y,
697
+ isPriced: A,
698
+ reset: B,
699
+ selectAmountGate: q,
700
+ selectEvent: W,
701
+ selectGroup: U,
702
+ selectReason: K,
703
+ setAnswers: I,
704
+ showsReBillRatio: O && A,
705
+ startPrefill: H,
706
+ step: p,
707
+ steps: P
697
708
  };
698
- }, M = {
709
+ }, F = {
699
710
  ar: {
700
711
  checks: {
701
712
  ce_conformity: "تم التحقق من شهادة أو إقرار CE",
@@ -1823,7 +1834,7 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
1823
1834
  title: "Título do evento"
1824
1835
  }
1825
1836
  }
1826
- }, N = ["companion", "operative"], P = {
1837
+ }, I = ["companion", "operative"], L = {
1827
1838
  ...s,
1828
1839
  breakage: {
1829
1840
  ...s.breakage,
@@ -1861,7 +1872,7 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
1861
1872
  ...s.robbery,
1862
1873
  reasons: ["robbery_machine", "robbery_option"]
1863
1874
  }
1864
- }, F = [
1875
+ }, R = [
1865
1876
  "n1_control",
1866
1877
  "other_request",
1867
1878
  "breakdown",
@@ -1879,13 +1890,13 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
1879
1890
  "hours_record",
1880
1891
  "robbery",
1881
1892
  "other"
1882
- ], I = [
1893
+ ], z = [
1883
1894
  "n1_control",
1884
1895
  "n3_control",
1885
1896
  "machine_assignment",
1886
1897
  "operator_change",
1887
1898
  "hours_record"
1888
- ], L = [
1899
+ ], B = [
1889
1900
  c.controls,
1890
1901
  c.admin_request,
1891
1902
  c.machine_problem,
@@ -1894,88 +1905,88 @@ var n = "eventDeclaration", r = "soren-event", i = 2, a = {
1894
1905
  c.delivery,
1895
1906
  c.documents,
1896
1907
  c.other
1897
- ], R = {
1898
- events: F.map((e) => P[e]),
1899
- groups: L,
1908
+ ], V = {
1909
+ events: R.map((e) => L[e]),
1910
+ groups: B,
1900
1911
  id: "bouygues",
1901
1912
  pricing: {
1902
1913
  asksReBillRatio: !0,
1903
1914
  showsPrice: !0
1904
1915
  },
1905
1916
  side: "client"
1906
- }, z = {
1907
- events: F.filter((e) => !I.includes(e)).map((e) => P[e]),
1908
- groups: L,
1917
+ }, H = {
1918
+ events: R.filter((e) => !z.includes(e)).map((e) => L[e]),
1919
+ groups: B,
1909
1920
  id: "bouyguesField",
1910
1921
  pricing: {
1911
1922
  asksReBillRatio: !1,
1912
1923
  showsPrice: !1
1913
1924
  },
1914
1925
  side: "client"
1915
- }, B = [{
1916
- funnels: [R, z],
1917
- getFunnel: (e) => N.includes(e ?? "") ? z : R,
1926
+ }, U = [{
1927
+ funnels: [V, H],
1928
+ getFunnel: (e) => I.includes(e ?? "") ? H : V,
1918
1929
  tenants: ["bouygues"]
1919
- }], V = [
1930
+ }], W = [
1920
1931
  l,
1921
1932
  u,
1922
- ...B.flatMap(({ funnels: e }) => e)
1923
- ], H = ({ side: e, tenantName: t, roleName: n }) => e === "supplier" ? u : B.find(({ tenants: e }) => e.includes(t ?? ""))?.getFunnel(n) ?? l, U = (e) => V.find((t) => t.id === e), W = 10, G = (e) => e.slice(0, W), K = (e) => e.lineType === "booking_events", q = ({ workflowValues: e }, t) => Array.isArray(e) ? e.find((e) => typeof e == "object" && !!e && e.name === t) : void 0, J = (e) => {
1924
- let t = q(e, a.unitPrice)?.value;
1933
+ ...U.flatMap(({ funnels: e }) => e)
1934
+ ], G = ({ side: e, tenantName: t, roleName: n }) => e === "supplier" ? u : U.find(({ tenants: e }) => e.includes(t ?? ""))?.getFunnel(n) ?? l, K = (e) => W.find((t) => t.id === e), q = 10, J = (e) => e.slice(0, q), Y = (e) => e.lineType === "booking_events", X = ({ workflowValues: e }, t) => Array.isArray(e) ? e.find((e) => typeof e == "object" && !!e && e.name === t) : void 0, ee = (e) => {
1935
+ let t = X(e, a.unitPrice)?.value;
1925
1936
  return typeof t == "string" || typeof t == "number" ? f(String(t)) : null;
1926
- }, ee = (e) => {
1927
- let t = J(e);
1928
- return t !== null && t < 0 && !!q(e, a.dates);
1929
- }, te = (e = [], t) => e.filter(K).flatMap((e) => {
1937
+ }, te = (e) => {
1938
+ let t = ee(e);
1939
+ return t !== null && t < 0 && !!X(e, a.dates);
1940
+ }, ne = (e = [], t) => e.filter(Y).flatMap((e) => {
1930
1941
  let [n, r] = e.dates ?? [];
1931
- return e.id !== t && n && r && ee(e) ? [{
1932
- fromDate: G(n),
1942
+ return e.id !== t && n && r && te(e) ? [{
1943
+ fromDate: J(n),
1933
1944
  line: e,
1934
- toDate: G(r)
1945
+ toDate: J(r)
1935
1946
  }] : [];
1936
- }), ne = (e, t) => t.find(({ fromDate: t, toDate: n }) => G(t) <= G(e) && G(e) <= G(n)), re = ({ fromDate: e, toDate: t }, n) => e && t ? n.find((n) => G(e) <= G(n.toDate) && G(n.fromDate) <= G(t)) : void 0, Y = (e, t) => e.billingType !== "DELTA" || t?.qtyUnit === "HOURS", ie = (e, t) => ({
1947
+ }), re = (e, t) => t.find(({ fromDate: t, toDate: n }) => J(t) <= J(e) && J(e) <= J(n)), ie = ({ fromDate: e, toDate: t }, n) => e && t ? n.find((n) => J(e) <= J(n.toDate) && J(n.fromDate) <= J(t)) : void 0, Z = (e, t) => e.billingType !== "DELTA" || t?.qtyUnit === "HOURS", ae = (e, t) => ({
1937
1948
  ...e,
1938
- events: e.events.filter((e) => Y(e, t))
1939
- }), X = 10, Z = (e) => typeof e == "object" && e && "value" in e ? Z(e.value) : typeof e == "string" || typeof e == "number" ? String(e) : "", Q = (e) => e === !0 || e === "true", $ = (e) => {
1949
+ events: e.events.filter((e) => Z(e, t))
1950
+ }), Q = 10, $ = (e) => typeof e == "object" && e && "value" in e ? $(e.value) : typeof e == "string" || typeof e == "number" ? String(e) : "", oe = (e) => e === !0 || e === "true", se = (e) => {
1940
1951
  let t = f(e);
1941
1952
  return t === null ? e : String(t);
1942
- }, ae = (e, t) => {
1943
- let n = (e) => t.find((t) => t.name === e)?.value, r = Z(t.find(({ tag: e }) => e === "reason")?.value), i = t.find(({ tag: e }) => e === "description")?.value ?? n(a.description), o = e.hasTitle ? "" : Z(e.reasonDetail ? n(e.reasonDetail) : r), s = n(a.dates), [c = "", l = ""] = Array.isArray(s) ? s.map(Z) : [], u = Z(n(_(e, o)?.name ?? a.date)), d = Number(Z(n(a.unitPrice)) || NaN), f = Number.isFinite(d);
1953
+ }, ce = (e, t) => {
1954
+ let n = (e) => t.find((t) => t.name === e)?.value, r = $(t.find(({ tag: e }) => e === "reason")?.value), i = t.find(({ tag: e }) => e === "description")?.value ?? n(a.description), o = e.hasTitle ? "" : $(e.reasonDetail ? n(e.reasonDetail) : r), s = n(a.dates), [c = "", l = ""] = Array.isArray(s) ? s.map($) : [], u = $(n(b(e, o)?.name ?? a.date)), d = Number($(n(a.unitPrice)) || NaN), f = Number.isFinite(d);
1944
1955
  return {
1945
1956
  amount: f ? String(e.price === "credit" || e.hasCreditNoteChoice ? Math.abs(d) : d) : "",
1946
1957
  ...e.amountGate && { amountGate: f },
1947
1958
  ...e.hasCreditNoteChoice && f && { isCreditNote: d < 0 },
1948
- checks: Object.fromEntries((e.checks ?? []).map((e) => [e, Q(n(e))])),
1959
+ checks: Object.fromEntries((e.checks ?? []).map((e) => [e, oe(n(e))])),
1949
1960
  dates: {
1950
- fromDate: (c || u).slice(0, X),
1951
- toDate: (l || u).slice(0, X)
1961
+ fromDate: (c || u).slice(0, Q),
1962
+ toDate: (l || u).slice(0, Q)
1952
1963
  },
1953
- description: Z(i),
1954
- fields: Object.fromEntries((e.fields ?? []).map(({ name: e, type: t }) => [e, t === "number" ? $(Z(n(e))) : Z(n(e))])),
1955
- intervention: Q(n(a.intervention)),
1964
+ description: $(i),
1965
+ fields: Object.fromEntries((e.fields ?? []).map(({ name: e, type: t }) => [e, t === "number" ? se($(n(e))) : $(n(e))])),
1966
+ intervention: oe(n(a.intervention)),
1956
1967
  reason: o,
1957
- reBillRatio: $(Z(n(a.reBillRatio))),
1968
+ reBillRatio: se($(n(a.reBillRatio))),
1958
1969
  title: e.hasTitle ? r : ""
1959
1970
  };
1960
- }, oe = (e, t, { reason: n }) => e.reasonDetail === t.reasonDetail && !!e.hasTitle == !!t.hasTitle && (!!e.hasTitle || !!e.reasonDetail || (e.reasons?.includes(n) ?? n === e.reason)), se = (e, t) => e === "client" && t === "supplier", ce = ({ workflow: e, workflowValues: t }, n) => {
1961
- if (!O(e)) return;
1962
- let r = U(e.funnel), i = n.side === e.side ? n.events.find(({ id: t }) => t === e.eventId) : void 0, a = r?.events.find(({ id: t }) => t === e.eventId) ?? i;
1971
+ }, le = (e, t, { reason: n }) => e.reasonDetail === t.reasonDetail && !!e.hasTitle == !!t.hasTitle && (!!e.hasTitle || !!e.reasonDetail || (e.reasons?.includes(n) ?? n === e.reason)), ue = (e, t) => e === "client" && t === "supplier", de = ({ workflow: e, workflowValues: t }, n) => {
1972
+ if (!j(e)) return;
1973
+ let r = K(e.funnel), i = n.side === e.side ? n.events.find(({ id: t }) => t === e.eventId) : void 0, a = r?.events.find(({ id: t }) => t === e.eventId) ?? i;
1963
1974
  if (!a) return;
1964
- let o = ae(a, t ?? []);
1965
- return i && oe(i, a, o) ? {
1975
+ let o = ce(a, t ?? []);
1976
+ return i && le(i, a, o) ? {
1966
1977
  answers: o,
1967
1978
  editFunnel: n,
1968
1979
  event: i,
1969
1980
  side: e.side
1970
1981
  } : {
1971
1982
  answers: o,
1972
- editFunnel: r && !a.isProof && se(n.side, e.side) ? {
1983
+ editFunnel: r && !a.isProof && ue(n.side, e.side) ? {
1973
1984
  ...r,
1974
1985
  pricing: n.pricing
1975
1986
  } : void 0,
1976
1987
  event: a,
1977
1988
  side: e.side
1978
1989
  };
1979
- }, le = ({ answers: e, event: t }) => !!t.hasTitle && !!e.title || !t.reasons?.length;
1990
+ }, fe = ({ answers: e, event: t }) => !!t.hasTitle && !!e.title || !t.reasons?.length;
1980
1991
  //#endregion
1981
- export { s as CLIENT_EVENTS, c as CLIENT_GROUPS, E as DEDICATED_FUNNEL, l as DEFAULT_CLIENT_FUNNEL, M as EVENT_LOCALES, n as EVENT_NAMESPACE, o as INVENTORY_ID, r as NATIVE_EVENT_SOURCE, i as NATIVE_EVENT_VERSION, u as SUPPLIER_FUNNEL, a as VALUE_NAMES, Y as billsOnLine, k as buildEventPayload, ne as findCreditOfDay, re as findCreditOverlap, U as findEventFunnel, te as getCreditedPeriods, D as getDedicatedEventWorkflow, _ as getEndDate, m as getEventAmounts, H as getEventFunnel, y as getFirstQuestion, g as getFunnelGroups, ie as getLineFunnel, S as getReason, v as getSteps, p as getUnitPrice, h as isAmountToComplete, le as isNamedByDeclaration, O as isNativeEventWorkflow, x as isStepAnswered, ce as readEvent, f as toDecimal, j as useEventDeclaration };
1992
+ export { s as CLIENT_EVENTS, c as CLIENT_GROUPS, h as DAILY_PRICE_SHARES, k as DEDICATED_FUNNEL, l as DEFAULT_CLIENT_FUNNEL, F as EVENT_LOCALES, n as EVENT_NAMESPACE, o as INVENTORY_ID, r as NATIVE_EVENT_SOURCE, i as NATIVE_EVENT_VERSION, u as SUPPLIER_FUNNEL, a as VALUE_NAMES, Z as billsOnLine, M as buildEventPayload, re as findCreditOfDay, ie as findCreditOverlap, K as findEventFunnel, _ as findShare, ne as getCreditedPeriods, A as getDedicatedEventWorkflow, b as getEndDate, m as getEventAmounts, G as getEventFunnel, S as getFirstQuestion, y as getFunnelGroups, ae as getLineFunnel, T as getReason, g as getShareAmount, x as getSteps, p as getUnitPrice, v as isAmountToComplete, fe as isNamedByDeclaration, j as isNativeEventWorkflow, w as isStepAnswered, de as readEvent, f as toDecimal, P as useEventDeclaration };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getsoren/shared-module",
3
- "version": "2.62.0",
3
+ "version": "2.63.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "types": "./dist/main.d.ts",