@autologix-engineering/shared 1.2.263 → 1.2.265

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 (39) hide show
  1. package/package.json +1 -1
  2. package/src/lib/commands/src/generate.summary.vendor.knock.off.pdf.handler.d.ts +1 -0
  3. package/src/lib/commands/src/generate.summary.vendor.knock.off.pdf.handler.js.map +1 -1
  4. package/src/lib/data-transfer-objects/src/command/create.statement.dto.d.ts +11 -0
  5. package/src/lib/data-transfer-objects/src/command/create.statement.dto.js +51 -1
  6. package/src/lib/data-transfer-objects/src/command/create.statement.dto.js.map +1 -1
  7. package/src/lib/data-transfer-objects/src/command/generate.summary.knock.off.dto.d.ts +19 -0
  8. package/src/lib/data-transfer-objects/src/command/generate.summary.knock.off.dto.js +47 -0
  9. package/src/lib/data-transfer-objects/src/command/generate.summary.knock.off.dto.js.map +1 -1
  10. package/src/lib/enums/src/alert.command.types.d.ts +2 -0
  11. package/src/lib/enums/src/alert.command.types.js +26 -0
  12. package/src/lib/enums/src/alert.command.types.js.map +1 -0
  13. package/src/lib/enums/src/command.type.enum.d.ts +1 -0
  14. package/src/lib/enums/src/command.type.enum.js +1 -0
  15. package/src/lib/enums/src/command.type.enum.js.map +1 -1
  16. package/src/lib/enums/src/index.d.ts +1 -0
  17. package/src/lib/enums/src/index.js +1 -0
  18. package/src/lib/enums/src/index.js.map +1 -1
  19. package/src/lib/routes/src/command.registry.routes.d.ts +1 -0
  20. package/src/lib/routes/src/command.registry.routes.js +1 -0
  21. package/src/lib/routes/src/command.registry.routes.js.map +1 -1
  22. package/src/lib/utilities/src/calculate.deducted.sharing.amount.d.ts +48 -0
  23. package/src/lib/utilities/src/calculate.deducted.sharing.amount.js +293 -0
  24. package/src/lib/utilities/src/calculate.deducted.sharing.amount.js.map +1 -0
  25. package/src/lib/utilities/src/find.ba.contract.for.booking.d.ts +25 -0
  26. package/src/lib/utilities/src/find.ba.contract.for.booking.js +66 -0
  27. package/src/lib/utilities/src/find.ba.contract.for.booking.js.map +1 -0
  28. package/src/lib/utilities/src/index.d.ts +4 -0
  29. package/src/lib/utilities/src/index.js +4 -0
  30. package/src/lib/utilities/src/index.js.map +1 -1
  31. package/src/lib/utilities/src/ist.d.ts +6 -0
  32. package/src/lib/utilities/src/ist.js +15 -0
  33. package/src/lib/utilities/src/ist.js.map +1 -1
  34. package/src/lib/utilities/src/pick.incentive.amount.d.ts +20 -0
  35. package/src/lib/utilities/src/pick.incentive.amount.js +30 -0
  36. package/src/lib/utilities/src/pick.incentive.amount.js.map +1 -0
  37. package/src/lib/utilities/src/pick.numbered.invoice.for.booking.d.ts +37 -0
  38. package/src/lib/utilities/src/pick.numbered.invoice.for.booking.js +96 -0
  39. package/src/lib/utilities/src/pick.numbered.invoice.for.booking.js.map +1 -0
@@ -0,0 +1,293 @@
1
+ import { BenchmarkRateField, BusinessContextOwnerField, ClientPersonaField, InstantInvoiceBodyField, NumberedInvoiceField, NumberedInvoiceLineItemField, OrganizationField, RequestField, RuleCategoryField, TaxInvoiceField, VendorDeductionRuleField, VendorGlobalRulesField, } from '../../models/src/index';
2
+ import { BillingType, BillTo, InvoiceType, RequestType, TripBillingDistanceNewEnum, } from '../../enums/src/index';
3
+ /**
4
+ * Group a flat rules array by `BillingType` so the helper can do a single
5
+ * Map lookup per booking instead of filtering the whole array each time.
6
+ * Idempotent: rules with no BillingType land in their own (undefined-keyed)
7
+ * bucket which the helper's lookup never asks for, so they're skipped.
8
+ */
9
+ export function groupDeductionRulesByBillingType(rules) {
10
+ const map = new Map();
11
+ for (const rule of rules) {
12
+ const key = rule?.[VendorDeductionRuleField.BillingType];
13
+ if (key == null)
14
+ continue;
15
+ const bucket = map.get(key);
16
+ if (bucket)
17
+ bucket.push(rule);
18
+ else
19
+ map.set(key, [rule]);
20
+ }
21
+ return map;
22
+ }
23
+ /**
24
+ * Compute the BA payout sharing amount for one booking, applying:
25
+ * 1. Benchmark-based deduction (percentage band, looked up from
26
+ * `percentageRulesMap` by booking's BillingType).
27
+ * 2. Vendor global-rule deductions (per-component flat + percentage).
28
+ * 3. Client / garage / signup-city exemptions.
29
+ *
30
+ * Sign-aware for credit notes: when the source amount is negative,
31
+ * benchmark deduction magnitude uses `Math.abs` and is applied with the
32
+ * matching sign so an original-vs-CN pair nets symmetrically. Final
33
+ * clamp at 0 applies only to positive originals (CN rows stay signed).
34
+ *
35
+ * Side effect: appends to `book.Deductions[]` so the caller can render the
36
+ * per-line deduction breakdown. The function does NOT assign to
37
+ * `book.SharingAmount` — callers do that after the call if they want it.
38
+ *
39
+ * Lifted verbatim from the duplicated private methods on
40
+ * CalculateBusinessAssociatePayoutRowsController and
41
+ * ExportBAPayoutReportController. Two pre-existing cosmetic differences
42
+ * harmonised here:
43
+ * - Fallback `invoice.SharingAmount` only triggers when all three of
44
+ * BaseCost/ExtraKmCost/ExtraHrCost are null (the calculate path's
45
+ * stricter `== null` check, not export's `!x` which also matched 0).
46
+ * - Rules parameter is a Map keyed by BillingType (the export path's
47
+ * pre-grouped shape). Use `groupDeductionRulesByBillingType` to convert.
48
+ */
49
+ export function calculateDeductedSharingAmount(book, options) {
50
+ const { defaultDeduction, benchmarkMap, percentageRulesMap, exemptedClients, exemptedGarages, globalRules, exemptedSignupCityIds, debug, } = options;
51
+ // Reset Deductions unconditionally so the function is idempotent across
52
+ // retries and pre-populated bookings. Callers used to do this manually
53
+ // (or not at all, depending on which controller). The helper owns the
54
+ // invariant now.
55
+ book[RequestField.Deductions] = [];
56
+ // Get cost components: prefer invoice fields when an invoice is present,
57
+ // fall back to booking fields for non-invoiced bookings
58
+ const invoice = book?.[RequestField.Invoices]?.[0];
59
+ let baseCost;
60
+ let extraKmCost;
61
+ let extraHrCost;
62
+ if (invoice && !invoice?.[TaxInvoiceField.Consolidated]) {
63
+ baseCost = Number(invoice?.[TaxInvoiceField.BaseCost] ?? 0);
64
+ extraKmCost = Number(invoice?.[TaxInvoiceField.ExtraKmCost] ?? 0);
65
+ extraHrCost = Number(invoice?.[TaxInvoiceField.ExtraHrCost] ?? 0);
66
+ // Fallback: if invoice components not stored, use invoice SharingAmount
67
+ if (invoice?.[TaxInvoiceField.BaseCost] == null &&
68
+ invoice?.[TaxInvoiceField.ExtraKmCost] == null &&
69
+ invoice?.[TaxInvoiceField.ExtraHrCost] == null) {
70
+ baseCost = invoice?.[TaxInvoiceField.SharingAmount] || 0;
71
+ }
72
+ }
73
+ else {
74
+ baseCost = Number(book?.[RequestField.BaseCost] ?? 0);
75
+ extraKmCost = Number(book?.[RequestField.ExtraKmCost] ?? 0);
76
+ extraHrCost = Number(book?.[RequestField.ExtraHrCost] ?? 0);
77
+ // Fallback: if booking components not stored, use booking SharingAmount
78
+ if (book?.[RequestField.BaseCost] == null &&
79
+ book?.[RequestField.ExtraKmCost] == null &&
80
+ book?.[RequestField.ExtraHrCost] == null) {
81
+ baseCost = book?.[RequestField.SharingAmount] || 0;
82
+ }
83
+ if (!invoice) {
84
+ // Skip deductions for non-invoiced bookings
85
+ return Number((baseCost + extraKmCost + extraHrCost).toFixed(2));
86
+ }
87
+ }
88
+ // Consolidated CN/DN: cost components above came from `book.*` fields
89
+ // (positive originals), so flip at entry to express the cancellation.
90
+ // Covers both full-cancel and partial CN/DN — for partial the magnitude
91
+ // is over-stated (full original instead of partial reversal), but the
92
+ // sign is correct, which matches BA-report behaviour. Non-consolidated
93
+ // CN/DN already carry signed BaseCost/ExtraKmCost/ExtraHrCost on the
94
+ // TI itself; the invoice branch above picks up the negative directly,
95
+ // no flip needed for that path. Sign carries through deductions, global
96
+ // rules, and the final return.
97
+ const isCNOrDN = invoice?.[TaxInvoiceField.InvoiceType] === InvoiceType.CreditNote ||
98
+ invoice?.[TaxInvoiceField.InvoiceType] === InvoiceType.DebitNote;
99
+ const isConsolidatedCNDN = !!invoice && !!invoice?.[TaxInvoiceField.Consolidated] && isCNOrDN;
100
+ if (isConsolidatedCNDN) {
101
+ baseCost = -baseCost;
102
+ extraKmCost = -extraKmCost;
103
+ extraHrCost = -extraHrCost;
104
+ }
105
+ // Keep original amounts; compute each deduction separately, then subtract all at end
106
+ const originalBaseCost = baseCost;
107
+ const originalExtraKmCost = extraKmCost;
108
+ const originalExtraHrCost = extraHrCost;
109
+ const baseCostForDeduction = originalBaseCost + originalExtraKmCost + originalExtraHrCost;
110
+ let totalBaseDeduction = 0;
111
+ let totalExtraKmDeduction = 0;
112
+ let totalExtraHrDeduction = 0;
113
+ // Benchmark-based deduction: applies to baseCost only (from original)
114
+ let deductionPercent = defaultDeduction;
115
+ let bookingBillType;
116
+ if (invoice && !invoice?.[TaxInvoiceField.Consolidated]) {
117
+ bookingBillType =
118
+ invoice?.[TaxInvoiceField.ClientPersona]?.[ClientPersonaField.BillingMethods]?.[ClientPersonaField.DefaultBillingType];
119
+ }
120
+ else {
121
+ bookingBillType =
122
+ book?.[RequestField.NumberedInvoices]?.[0]?.[NumberedInvoiceField.InstantInvoiceBody]?.[InstantInvoiceBodyField.DistanceType];
123
+ }
124
+ debug?.(`[deduction] invoice NIs present: ${!!invoice?.[TaxInvoiceField.NumberedInvoices]?.length}`);
125
+ if (invoice &&
126
+ invoice?.[TaxInvoiceField.Consolidated] &&
127
+ invoice?.[TaxInvoiceField.NumberedInvoices]?.length > 0) {
128
+ bookingBillType = invoice?.[TaxInvoiceField.NumberedInvoices]?.find((e) => e?.[NumberedInvoiceField.InstantInvoiceBody]?.[InstantInvoiceBodyField.RequestNumber] === book?.[RequestField.RequestNumber])?.[NumberedInvoiceField.InstantInvoiceBody]?.[InstantInvoiceBodyField.DistanceType];
129
+ }
130
+ debug?.(`[deduction] bookingBillType: ${bookingBillType}`);
131
+ if (bookingBillType == null)
132
+ bookingBillType = TripBillingDistanceNewEnum.AutomatedGtoG;
133
+ const billingTypeForLookup = bookingBillType === TripBillingDistanceNewEnum.AutomatedGtoG
134
+ ? BillingType.GtoG
135
+ : BillingType.PtoP;
136
+ const benchMark = benchmarkMap?.get(`${billingTypeForLookup}-${book?.[RequestField.MasterCityId]}-${book?.[RequestField.VehicleGroupId]}-${book?.[RequestField.RequestType]}`);
137
+ const targetBenchmarkRate = benchMark?.[BenchmarkRateField.BenchMarkRate];
138
+ debug?.(`[deduction] targetBenchmarkRate: ${targetBenchmarkRate}`);
139
+ // Retrieve pre-filtered rules for this billing type (no per-booking filter needed)
140
+ const percentageRules = percentageRulesMap.get(billingTypeForLookup) ?? [];
141
+ let clientSignedAmount = book?.[RequestField.BenchmarkRate];
142
+ if (book?.[RequestField.RequestType] === RequestType.AirportTransfer) {
143
+ if (invoice && !invoice?.[TaxInvoiceField.Consolidated]) {
144
+ debug?.(`[deduction] airport invoice lineItems count: ${invoice?.[TaxInvoiceField.LineItems]?.length ?? 0}`);
145
+ clientSignedAmount = invoice?.[TaxInvoiceField.LineItems]?.find((e) => e?.[NumberedInvoiceLineItemField.Description]
146
+ ?.toLowerCase()
147
+ ?.includes('base cost'))?.[NumberedInvoiceLineItemField.TotalBeforeTax];
148
+ }
149
+ else {
150
+ clientSignedAmount = book?.[RequestField.NumberedInvoices]?.[0]?.[NumberedInvoiceField.LineItems]?.find((e) => e?.[NumberedInvoiceLineItemField.Description]
151
+ ?.toLowerCase()
152
+ ?.includes('base cost'))?.[NumberedInvoiceLineItemField.TotalBeforeTax];
153
+ }
154
+ debug?.(`[deduction] clientSignedAmount: ${clientSignedAmount}`);
155
+ if (invoice &&
156
+ invoice?.[TaxInvoiceField.Consolidated] &&
157
+ invoice?.[TaxInvoiceField.NumberedInvoices]?.length > 0) {
158
+ clientSignedAmount = invoice?.[TaxInvoiceField.NumberedInvoices]
159
+ ?.find((e) => e?.[NumberedInvoiceField.InstantInvoiceBody]?.[InstantInvoiceBodyField.RequestNumber] === book?.[RequestField.RequestNumber])?.[NumberedInvoiceField.LineItems]
160
+ ?.find((e) => e?.[NumberedInvoiceLineItemField.Description]
161
+ ?.toLowerCase()
162
+ ?.includes('base cost'))?.[NumberedInvoiceLineItemField.TotalBeforeTax];
163
+ }
164
+ }
165
+ if (clientSignedAmount &&
166
+ targetBenchmarkRate &&
167
+ percentageRules?.length > 0) {
168
+ const percentIncrease = clientSignedAmount === 0
169
+ ? null
170
+ : ((clientSignedAmount - targetBenchmarkRate) /
171
+ clientSignedAmount) *
172
+ 100;
173
+ if (percentIncrease != null && percentIncrease > 0) {
174
+ const sortedRules = [...percentageRules].sort((a, b) => a?.[VendorDeductionRuleField.RangeStart] -
175
+ b?.[VendorDeductionRuleField.RangeStart]);
176
+ const deduction = sortedRules.find((e) => e?.[VendorDeductionRuleField.RangeStart] <=
177
+ percentIncrease &&
178
+ percentIncrease <
179
+ e?.[VendorDeductionRuleField.RangeEnd]);
180
+ if (deduction) {
181
+ deductionPercent =
182
+ deduction?.[VendorDeductionRuleField.DeductionPercentage];
183
+ }
184
+ }
185
+ else {
186
+ deductionPercent = 0;
187
+ }
188
+ }
189
+ if (exemptedClients.includes(book?.[RequestField.ClientPersonaId]) ||
190
+ exemptedGarages.includes(book?.[RequestField.GarageId])) {
191
+ deductionPercent = 0;
192
+ }
193
+ // For credit notes, baseCost is negative; use abs only when calculating
194
+ // benchmarkDeductionAmount for correct magnitude
195
+ if (deductionPercent > 0 && baseCostForDeduction !== 0) {
196
+ const benchmarkDeductionAmount = Number(((Math.abs(baseCostForDeduction) * deductionPercent) /
197
+ 100).toFixed(2));
198
+ const signedDeduction = baseCostForDeduction >= 0
199
+ ? benchmarkDeductionAmount
200
+ : -benchmarkDeductionAmount;
201
+ totalBaseDeduction += signedDeduction;
202
+ book[RequestField.Deductions].push({
203
+ deductionName: 'Benchmark Deduction',
204
+ deductionAmount: signedDeduction,
205
+ });
206
+ }
207
+ // Apply vendor global rules deductions per component (each from original amounts)
208
+ const signupCityId = book?.[RequestField.ClientPersona]?.[ClientPersonaField.SignupCityId];
209
+ const hasExemption = !!signupCityId && exemptedSignupCityIds.has(signupCityId);
210
+ const paymentMode = book?.[RequestField.ModeOfPayment];
211
+ const orgType = book?.[RequestField.ClientPersona]?.[ClientPersonaField.PersonaOf]?.[BusinessContextOwnerField.Organization]?.[OrganizationField.ClientType];
212
+ const requestType = book?.[RequestField.RequestType];
213
+ const applicableGlobalRules = hasExemption
214
+ ? []
215
+ : globalRules.filter((rule) => (rule[VendorGlobalRulesField.AllCities] ||
216
+ rule[VendorGlobalRulesField.CityId] ===
217
+ book?.[RequestField.MasterCityId]) &&
218
+ (rule[VendorGlobalRulesField.AllClients] ||
219
+ rule[VendorGlobalRulesField.ClientId] ===
220
+ book?.[RequestField.ClientPersonaId]) &&
221
+ (rule[VendorGlobalRulesField.AllVehicleGroups] ||
222
+ rule[VendorGlobalRulesField.VehicleGroupId] ===
223
+ book?.[RequestField.VehicleGroupId]) &&
224
+ (rule[VendorGlobalRulesField.AllGarages] ||
225
+ rule[VendorGlobalRulesField.GarageId] ===
226
+ book?.[RequestField.GarageId]) &&
227
+ (rule[VendorGlobalRulesField.RuleCategory]?.[RuleCategoryField.PaymentMode] === paymentMode ||
228
+ rule[VendorGlobalRulesField.RuleCategory]?.[RuleCategoryField.PaymentMode] === BillTo.Both) &&
229
+ rule[VendorGlobalRulesField.RuleCategory]?.[RuleCategoryField.ClientType]?.includes(orgType) &&
230
+ rule[VendorGlobalRulesField.RequestType]?.includes(requestType));
231
+ for (const rule of applicableGlobalRules) {
232
+ let ruleDeductionAmount = 0;
233
+ // Deduction can stay negative for credit notes; only
234
+ // benchmarkDeductionAmount uses abs
235
+ if (rule[VendorGlobalRulesField.BaseCost]) {
236
+ const d = rule[VendorGlobalRulesField.BaseCost];
237
+ totalBaseDeduction += d;
238
+ ruleDeductionAmount += d;
239
+ }
240
+ if (rule[VendorGlobalRulesField.BaseCostPercentage]) {
241
+ const d = Number(((originalBaseCost *
242
+ rule[VendorGlobalRulesField.BaseCostPercentage]) /
243
+ 100).toFixed(2));
244
+ totalBaseDeduction += d;
245
+ ruleDeductionAmount += d;
246
+ }
247
+ if (rule[VendorGlobalRulesField.ExtraKm]) {
248
+ const d = rule[VendorGlobalRulesField.ExtraKm];
249
+ totalExtraKmDeduction += d;
250
+ ruleDeductionAmount += d;
251
+ }
252
+ if (rule[VendorGlobalRulesField.ExtraKmPercentage]) {
253
+ const d = Number(((originalExtraKmCost *
254
+ rule[VendorGlobalRulesField.ExtraKmPercentage]) /
255
+ 100).toFixed(2));
256
+ totalExtraKmDeduction += d;
257
+ ruleDeductionAmount += d;
258
+ }
259
+ if (rule[VendorGlobalRulesField.ExtraHr]) {
260
+ const d = rule[VendorGlobalRulesField.ExtraHr];
261
+ totalExtraHrDeduction += d;
262
+ ruleDeductionAmount += d;
263
+ }
264
+ if (rule[VendorGlobalRulesField.ExtraHrPercentage]) {
265
+ const d = Number(((originalExtraHrCost *
266
+ rule[VendorGlobalRulesField.ExtraHrPercentage]) /
267
+ 100).toFixed(2));
268
+ totalExtraHrDeduction += d;
269
+ ruleDeductionAmount += d;
270
+ }
271
+ book[RequestField.Deductions].push({
272
+ deductionName: rule[VendorGlobalRulesField.RuleCategory]?.[RuleCategoryField.CategoryName],
273
+ deductionAmount: Number(ruleDeductionAmount.toFixed(2)),
274
+ });
275
+ }
276
+ // Subtract all deductions at the end (credit notes can be negative;
277
+ // do not clamp to 0)
278
+ const rawBaseCost = Number((originalBaseCost - totalBaseDeduction).toFixed(2));
279
+ const rawExtraKmCost = Number((originalExtraKmCost - totalExtraKmDeduction).toFixed(2));
280
+ const rawExtraHrCost = Number((originalExtraHrCost - totalExtraHrDeduction).toFixed(2));
281
+ baseCost =
282
+ originalBaseCost >= 0 ? Math.max(0, rawBaseCost) : rawBaseCost;
283
+ extraKmCost =
284
+ originalExtraKmCost >= 0
285
+ ? Math.max(0, rawExtraKmCost)
286
+ : rawExtraKmCost;
287
+ extraHrCost =
288
+ originalExtraHrCost >= 0
289
+ ? Math.max(0, rawExtraHrCost)
290
+ : rawExtraHrCost;
291
+ return Number((baseCost + extraKmCost + extraHrCost).toFixed(2));
292
+ }
293
+ //# sourceMappingURL=calculate.deducted.sharing.amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculate.deducted.sharing.amount.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/calculate.deducted.sharing.amount.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAElB,uBAAuB,EAIvB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,sBAAsB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,WAAW,EACX,MAAM,EACN,WAAW,EACX,WAAW,EACX,0BAA0B,GAC1B,MAAM,uBAAuB,CAAC;AAe/B;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,KAA6B;IAE7B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAuC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,IAAI,EAAE,CAAC,wBAAwB,CAAC,WAAW,CAAgB,CAAC;QACxE,IAAI,GAAG,IAAI,IAAI;YAAE,SAAS;QAC1B,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM;YAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;YACzB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,8BAA8B,CAC7C,IAAc,EACd,OAA8C;IAE9C,MAAM,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,KAAK,GACL,GAAG,OAAO,CAAC;IAEZ,wEAAwE;IACxE,uEAAuE;IACvE,sEAAsE;IACtE,iBAAiB;IACjB,IAAI,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AAC,EAAE,cAAc,CAAC;YAC7B,CAAC,CAAC,cAAc,CAAC;IAEnB,OAAO,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { IBAContract, IRequest } from '../../models/src/index';
2
+ /**
3
+ * Resolve the BA contract that owns a booking.
4
+ *
5
+ * Picks the contract whose active window contains the booking's pickup time.
6
+ * Returns `null` if no contract matches.
7
+ *
8
+ * Differences from the inline duplicates this replaces:
9
+ * - Pickup time, not invoice-cut date. A booking on Apr 8 invoiced Apr 30 must
10
+ * be attributed to the contract active on Apr 8, not the one active on
11
+ * Apr 30. Fixes pre-contract and post-surrender bookings appearing under
12
+ * the wrong contract row.
13
+ * - Effective end = earlier of `ContractEndDate` and `SurrenderEffectiveDate`
14
+ * (AND, not OR). The previous `||` accepted a contract whose original end
15
+ * date was still in the future even after early surrender, so post-surrender
16
+ * bookings stuck to the surrendered contract. This is also a behaviour
17
+ * change for the export-report path, which previously used OR.
18
+ * - Cancelled contracts are skipped. A `Cancelled` row with a future end date
19
+ * used to match.
20
+ * - Surrendered contracts without a populated `SurrenderEffectiveDate` are
21
+ * skipped — without an effective date the surrender guard cannot be
22
+ * enforced and the contract would silently fall back to matching on
23
+ * `ContractEndDate` alone (the exact mis-attribution this helper fixes).
24
+ */
25
+ export declare function findBAContractForBooking(booking: IRequest, contracts: IBAContract[] | undefined): IBAContract | null;
@@ -0,0 +1,66 @@
1
+ import { BAContractField, RequestField, TripField, } from '../../models/src/index';
2
+ import { BAContractStatus } from '../../enums/src/index';
3
+ /**
4
+ * Resolve the BA contract that owns a booking.
5
+ *
6
+ * Picks the contract whose active window contains the booking's pickup time.
7
+ * Returns `null` if no contract matches.
8
+ *
9
+ * Differences from the inline duplicates this replaces:
10
+ * - Pickup time, not invoice-cut date. A booking on Apr 8 invoiced Apr 30 must
11
+ * be attributed to the contract active on Apr 8, not the one active on
12
+ * Apr 30. Fixes pre-contract and post-surrender bookings appearing under
13
+ * the wrong contract row.
14
+ * - Effective end = earlier of `ContractEndDate` and `SurrenderEffectiveDate`
15
+ * (AND, not OR). The previous `||` accepted a contract whose original end
16
+ * date was still in the future even after early surrender, so post-surrender
17
+ * bookings stuck to the surrendered contract. This is also a behaviour
18
+ * change for the export-report path, which previously used OR.
19
+ * - Cancelled contracts are skipped. A `Cancelled` row with a future end date
20
+ * used to match.
21
+ * - Surrendered contracts without a populated `SurrenderEffectiveDate` are
22
+ * skipped — without an effective date the surrender guard cannot be
23
+ * enforced and the contract would silently fall back to matching on
24
+ * `ContractEndDate` alone (the exact mis-attribution this helper fixes).
25
+ */
26
+ export function findBAContractForBooking(booking, contracts) {
27
+ if (!contracts?.length)
28
+ return null;
29
+ const trip = booking?.[RequestField.Trip];
30
+ const bookingDateRaw = trip?.[TripField.StartGarageDate] ??
31
+ booking?.[RequestField.PickupTime] ??
32
+ booking?.[RequestField.InvoiceDate];
33
+ if (!bookingDateRaw)
34
+ return null;
35
+ const bookingDate = new Date(bookingDateRaw);
36
+ return (contracts.find((c) => {
37
+ const status = c?.[BAContractField.Status];
38
+ if (status === BAContractStatus.Cancelled)
39
+ return false;
40
+ if (status === BAContractStatus.Surrendered &&
41
+ !c?.[BAContractField.SurrenderEffectiveDate]) {
42
+ return false;
43
+ }
44
+ const start = c?.[BAContractField.ContractStartDate]
45
+ ? new Date(c[BAContractField.ContractStartDate])
46
+ : null;
47
+ if (!start || start > bookingDate)
48
+ return false;
49
+ const endDate = c?.[BAContractField.ContractEndDate]
50
+ ? new Date(c[BAContractField.ContractEndDate])
51
+ : null;
52
+ const surrenderDate = c?.[BAContractField.SurrenderEffectiveDate]
53
+ ? new Date(c[BAContractField.SurrenderEffectiveDate])
54
+ : null;
55
+ // Contract must have some end boundary, and the booking must fall on
56
+ // or before the earlier of (ContractEndDate, SurrenderEffectiveDate).
57
+ if (!endDate && !surrenderDate)
58
+ return false;
59
+ if (endDate && endDate < bookingDate)
60
+ return false;
61
+ if (surrenderDate && surrenderDate < bookingDate)
62
+ return false;
63
+ return true;
64
+ }) ?? null);
65
+ }
66
+ //# sourceMappingURL=find.ba.contract.for.booking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.ba.contract.for.booking.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/find.ba.contract.for.booking.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EAGf,YAAY,EACZ,SAAS,GACT,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,wBAAwB,CACvC,OAAiB,EACjB,SAAoC;IAEpC,IAAI,CAAC,SAAS,EAAE,MAAM;QAAE,OAAO,IAAI,CAAC;IAEpC,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,cAAc,GACnB,IAAI,EAAE,CAAC,SAAS,CAAC,eAAe,CAAC;QACjC,OAAO,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;QAClC,OAAO,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACrC,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IACjC,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC;IAE7C,OAAO,CACN,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QACpB,MAAM,MAAM,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,MAAM,KAAK,gBAAgB,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;QACxD,IACC,MAAM,KAAK,gBAAgB,CAAC,WAAW;YACvC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAC3C,CAAC;YACF,OAAO,KAAK,CAAC;QACd,CAAC;QAED,MAAM,KAAK,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,iBAAiB,CAAC;YACnD,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;YAChD,CAAC,CAAC,IAAI,CAAC;QACR,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,WAAW;YAAE,OAAO,KAAK,CAAC;QAEhD,MAAM,OAAO,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,eAAe,CAAC;YACnD,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;YAC9C,CAAC,CAAC,IAAI,CAAC;QACR,MAAM,aAAa,GAAG,CAAC,EAAE,CAAC,eAAe,CAAC,sBAAsB,CAAC;YAChE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,sBAAsB,CAAC,CAAC;YACrD,CAAC,CAAC,IAAI,CAAC;QAER,qEAAqE;QACrE,sEAAsE;QACtE,IAAI,CAAC,OAAO,IAAI,CAAC,aAAa;YAAE,OAAO,KAAK,CAAC;QAC7C,IAAI,OAAO,IAAI,OAAO,GAAG,WAAW;YAAE,OAAO,KAAK,CAAC;QACnD,IAAI,aAAa,IAAI,aAAa,GAAG,WAAW;YAAE,OAAO,KAAK,CAAC;QAE/D,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,IAAI,IAAI,CACV,CAAC;AACH,CAAC"}
@@ -22,3 +22,7 @@ export * from './build.cleartax.pay.dtls';
22
22
  export * from './resolve.cleartax.driver.sac.hsn';
23
23
  export * from './resolve.passenger.display.name';
24
24
  export * from './remove.null.filter';
25
+ export * from './calculate.deducted.sharing.amount';
26
+ export * from './find.ba.contract.for.booking';
27
+ export * from './pick.numbered.invoice.for.booking';
28
+ export * from './pick.incentive.amount';
@@ -22,4 +22,8 @@ export * from './build.cleartax.pay.dtls';
22
22
  export * from './resolve.cleartax.driver.sac.hsn';
23
23
  export * from './resolve.passenger.display.name';
24
24
  export * from './remove.null.filter';
25
+ export * from './calculate.deducted.sharing.amount';
26
+ export * from './find.ba.contract.for.booking';
27
+ export * from './pick.numbered.invoice.for.booking';
28
+ export * from './pick.incentive.amount';
25
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,OAAO,CAAC;AACtB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,cAAc,oCAAoC,CAAC;AACnD,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wCAAwC,CAAC;AACvD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,OAAO,CAAC;AACtB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sBAAsB,CAAC;AACrC,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,yBAAyB,CAAC"}
@@ -1,5 +1,11 @@
1
1
  export declare const IST_OFFSET_MS: number;
2
2
  export declare function addIstOffset(d: Date): Date;
3
+ /**
4
+ * Normalizes any date/string to IST start-of-day (00:00:00 IST = 18:30:00 UTC previous day).
5
+ * Returns null for missing/invalid input so callers can guard rather than writing bad data.
6
+ * Safe regardless of whether the input carries a UTC offset, IST offset, or none.
7
+ */
8
+ export declare function toISTStartOfDay(d: Date | string | null | undefined): Date | null;
3
9
  /**
4
10
  * Returns a UTC-midnight Date anchored to the IST calendar day, suitable
5
11
  * for ExcelJS (and downstream xlsx writers) that serialise Dates via UTC.
@@ -2,6 +2,21 @@ export const IST_OFFSET_MS = 5.5 * 60 * 60 * 1000;
2
2
  export function addIstOffset(d) {
3
3
  return new Date(d.getTime() + IST_OFFSET_MS);
4
4
  }
5
+ /**
6
+ * Normalizes any date/string to IST start-of-day (00:00:00 IST = 18:30:00 UTC previous day).
7
+ * Returns null for missing/invalid input so callers can guard rather than writing bad data.
8
+ * Safe regardless of whether the input carries a UTC offset, IST offset, or none.
9
+ */
10
+ export function toISTStartOfDay(d) {
11
+ if (d === null || d === undefined || d === '')
12
+ return null;
13
+ const parsed = new Date(d);
14
+ if (Number.isNaN(parsed.getTime()))
15
+ return null;
16
+ const istDate = new Date(parsed.getTime() + IST_OFFSET_MS);
17
+ return new Date(Date.UTC(istDate.getUTCFullYear(), istDate.getUTCMonth(), istDate.getUTCDate())
18
+ - IST_OFFSET_MS);
19
+ }
5
20
  /**
6
21
  * Returns a UTC-midnight Date anchored to the IST calendar day, suitable
7
22
  * for ExcelJS (and downstream xlsx writers) that serialise Dates via UTC.
@@ -1 +1 @@
1
- {"version":3,"file":"ist.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/ist.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAElD,MAAM,UAAU,YAAY,CAAC,CAAO;IACnC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAC7B,GAAqC;IAErC,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACjE,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACxB,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3C,MAAM,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,IAAI,IAAI,CACd,IAAI,CAAC,GAAG,CACP,OAAO,CAAC,cAAc,EAAE,EACxB,OAAO,CAAC,WAAW,EAAE,EACrB,OAAO,CAAC,UAAU,EAAE,CACpB,CACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAsC;IAC/D,IAAI,CAAC,IAAI;QAAE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M,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACvD,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACzD,OAAO,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;QACtB,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { BAIncentiveCriteriaType } from '../../enums/src/index';
2
+ export interface IIncentiveEligibleRule {
3
+ minBenchmarkRevenue: number;
4
+ attendance: number;
5
+ criteria: BAIncentiveCriteriaType;
6
+ incentive: number;
7
+ }
8
+ /**
9
+ * Resolve the highest incentive amount across the eligible rules.
10
+ * AND rule fires when revenue AND attendance both meet the rule's
11
+ * thresholds; OR rule fires when either meets. Result is the max
12
+ * incentive across all firing rules — zero when none fire.
13
+ *
14
+ * Shared between Orion (initial computation in
15
+ * CalculateBusinessAssociatePayoutRowsController) and Iris
16
+ * (reactive recompute when the user edits revenue inputs in
17
+ * preview.payout.component.tsx). Keep this function pure — no IO,
18
+ * no date math — so both runtimes get identical answers.
19
+ */
20
+ export declare function pickIncentiveAmount(eligibleRules: IIncentiveEligibleRule[], revenue: number, dayCount: number): number;
@@ -0,0 +1,30 @@
1
+ import { BAIncentiveCriteriaType } from '../../enums/src/index';
2
+ /**
3
+ * Resolve the highest incentive amount across the eligible rules.
4
+ * AND rule fires when revenue AND attendance both meet the rule's
5
+ * thresholds; OR rule fires when either meets. Result is the max
6
+ * incentive across all firing rules — zero when none fire.
7
+ *
8
+ * Shared between Orion (initial computation in
9
+ * CalculateBusinessAssociatePayoutRowsController) and Iris
10
+ * (reactive recompute when the user edits revenue inputs in
11
+ * preview.payout.component.tsx). Keep this function pure — no IO,
12
+ * no date math — so both runtimes get identical answers.
13
+ */
14
+ export function pickIncentiveAmount(eligibleRules, revenue, dayCount) {
15
+ let incentive = 0;
16
+ for (const rule of eligibleRules ?? []) {
17
+ const revenueMatch = revenue >= rule.minBenchmarkRevenue;
18
+ const dayMatch = dayCount >= rule.attendance;
19
+ const fires = rule.criteria === BAIncentiveCriteriaType.AND
20
+ ? revenueMatch && dayMatch
21
+ : rule.criteria === BAIncentiveCriteriaType.OR
22
+ ? revenueMatch || dayMatch
23
+ : false;
24
+ if (fires && rule.incentive > incentive) {
25
+ incentive = rule.incentive;
26
+ }
27
+ }
28
+ return incentive;
29
+ }
30
+ //# sourceMappingURL=pick.incentive.amount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pick.incentive.amount.js","sourceRoot":"","sources":["../../../../../../../libs/shared/src/lib/utilities/src/pick.incentive.amount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAShE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CAClC,aAAuC,EACvC,OAAe,EACf,QAAgB;IAEhB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,IAAI,IAAI,aAAa,IAAI,EAAE,EAAE,CAAC;QACxC,MAAM,YAAY,GAAG,OAAO,IAAI,IAAI,CAAC,mBAAmB,CAAC;QACzD,MAAM,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC;QAC7C,MAAM,KAAK,GACV,IAAI,CAAC,QAAQ,KAAK,uBAAuB,CAAC,GAAG;YAC5C,CAAC,CAAC,YAAY,IAAI,QAAQ;YAC1B,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,uBAAuB,CAAC,EAAE;gBAC7C,CAAC,CAAC,YAAY,IAAI,QAAQ;gBAC1B,CAAC,CAAC,KAAK,CAAC;QACX,IAAI,KAAK,IAAI,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,CAAC;YACzC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAC5B,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { INumberedInvoice, IRequest, ITaxInvoice } from '../../models/src/index';
2
+ export interface PickNumberedInvoiceResult {
3
+ ni: INumberedInvoice | undefined;
4
+ lineItems: any[] | undefined;
5
+ /**
6
+ * True when the caller should sign-flip downstream amounts:
7
+ * a full-cancel CN/DN against a consolidated parent was resolved
8
+ * by walking to the parent's per-booking NI, so the picked
9
+ * lineItems carry the original (positive) values. The caller
10
+ * negates to express the cancellation in the row.
11
+ */
12
+ negateForFullCancel: boolean;
13
+ }
14
+ /**
15
+ * Resolve the per-booking NumberedInvoice and the right line-item slice
16
+ * for a (request, taxInvoice) pair, with CN/DN, full-cancel, and
17
+ * consolidated cases handled.
18
+ *
19
+ * - CN/DN: source NI from `ti.ReferenceInvoice` (the parent TI), not
20
+ * the CN itself. CN entities don't carry their own NumberedInvoice
21
+ * for the original sale — only the reversal.
22
+ * - Consolidated source: walk `sourceTI.NumberedInvoices` and pick
23
+ * the one whose `instantInvBody.tripId` matches the request's
24
+ * `Trip.TripId`. Single-child fallback when no tripId match.
25
+ * - Non-consolidated source: use `sourceTI.NumberedInvoice` (direct
26
+ * ManyToOne FK on the TI entity).
27
+ * - Consolidated full-cancel CN/DN: returns the parent NI's
28
+ * lineItems (positive originals) and `negateForFullCancel=true`
29
+ * so the caller sign-flips. If per-booking NI can't be resolved,
30
+ * returns empty lineItems rather than surfacing the consolidated
31
+ * whole-invoice total once per booking.
32
+ *
33
+ * Mirrors `VendorKnockOffCalculationService.pickNumberedInvoiceAndLineItems`
34
+ * — kept in shared so BA-payout / booking-report / vendor-KO can all
35
+ * use one source of truth.
36
+ */
37
+ export declare function pickNumberedInvoiceForBooking(request: IRequest, taxInvoice?: ITaxInvoice, debug?: (msg: string) => void): PickNumberedInvoiceResult;