@feedmepos/mf-inventory-portal 1.2.30 → 1.2.31-dev.2

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 (78) hide show
  1. package/dist/{App-CZJre5y8.js → App-BMf3N76A.js} +19 -19
  2. package/dist/{ApprovalView-CnxHxojY.js → ApprovalView-ue3fJ7v_.js} +6 -6
  3. package/dist/{BindingsDialog-C6lCOPNs.js → BindingsDialog-ByMj3RjY.js} +8 -8
  4. package/dist/{BindingsPicker-DZtFKLQ5.js → BindingsPicker-DgSjaVrq.js} +2 -2
  5. package/dist/{BindingsTable-BmQGLuJ4.js → BindingsTable-BUu0r9Zo.js} +3 -3
  6. package/dist/{ClosingDraftView-KLtlh31f.js → ClosingDraftView-R2NPPsXD.js} +61 -62
  7. package/dist/{ClosingHistoryView-Rf1yMhMj.js → ClosingHistoryView-1W_y3JEM.js} +4 -4
  8. package/dist/ClosingTemplateView-BC9w8vZ0.js +2059 -0
  9. package/dist/{DeliveryOrderPrintPreview-UF7V005U.js → DeliveryOrderPrintPreview-zJhQH8By.js} +1 -1
  10. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BcMvEdc0.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CJ_bPMX_.js} +5 -5
  11. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CqAeF0wL.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-Cphr1J6U.js} +3 -3
  12. package/dist/{FmMultiselectDialog-BasrjBFA.js → FmMultiselectDialog-DEt2I4_c.js} +2 -2
  13. package/dist/{FmMultiselectDialog-B0aKuf2o.js → FmMultiselectDialog-DSGQitHT.js} +1 -1
  14. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-CaYJJkXz.js → FmUnitInput.vue_vue_type_script_setup_true_lang-spkm7SZK.js} +3 -3
  15. package/dist/{ImportView-DRSoz0uM.js → ImportView-ank5c4AV.js} +7 -7
  16. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-DA8SlWPy.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-DhE2M3CD.js} +1 -1
  17. package/dist/{IngredientGroupView-D5Laak2-.js → IngredientGroupView-DVT0Yyae.js} +6 -6
  18. package/dist/{IngredientsView-TG3fPQhR.js → IngredientsView-BcmPBoOb.js} +15 -15
  19. package/dist/{IntegrationView-CElpjyo7.js → IntegrationView-0JY21Fjn.js} +1607 -1592
  20. package/dist/{InventoryBindingForm-CBgxRYBd.js → InventoryBindingForm-FhDgibuy.js} +1 -1
  21. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-Ys5GBHoQ.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DL2pd-U1.js} +4 -4
  22. package/dist/{InventoryBindingSummary-OK3vNWhi.js → InventoryBindingSummary-Rj4rLIp-.js} +1 -1
  23. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-9QRntUlk.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CtqVtwbE.js} +1 -1
  24. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-Bc01NoOn.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BJZmEJ_9.js} +2 -2
  25. package/dist/{PublishView-CLMfiLjP.js → PublishView-NyqU4ogZ.js} +4 -4
  26. package/dist/{PurchaseOrderPrintPreview-Dy77yWDC.js → PurchaseOrderPrintPreview-Cua1-cfS.js} +1 -1
  27. package/dist/{ReceiveRequestView-BhD-NaHE.js → ReceiveRequestView-BQtpsAOR.js} +304 -304
  28. package/dist/{RecipeView-RWaO94w_.js → RecipeView-Dcv3Pnvu.js} +9 -9
  29. package/dist/{SingleColumnLayout.vue_vue_type_script_setup_true_lang-DY7TaxPK.js → SingleColumnLayout.vue_vue_type_script_setup_true_lang-CWZkVCAj.js} +99 -99
  30. package/dist/{StockView-D5t8OxaG.js → StockView-D2jlQ_IE.js} +16 -16
  31. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-3Asf1TGd.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang--F8e7pUI.js} +1 -1
  32. package/dist/{SupplierView-DiospFKq.js → SupplierView-CGAtUowc.js} +12 -12
  33. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-DfCHteOF.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-Cd9R8l0c.js} +3 -3
  34. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CNtvx-LA.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Dy5JfpNp.js} +1 -1
  35. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-p959Op4k.js → TransferDetails.vue_vue_type_script_setup_true_lang-BqxG1uZu.js} +15 -15
  36. package/dist/{TransferTemplateView-ePZFdZ0p.js → TransferTemplateView-DMuw4LtY.js} +16 -16
  37. package/dist/{UnitView-Banlxw7y.js → UnitView-CwlT0HpP.js} +7 -7
  38. package/dist/{WarehouseView-BL-p5hbi.js → WarehouseView-mT3A-9uq.js} +6 -6
  39. package/dist/{WastageTemplateView-B1pmSuW0.js → WastageTemplateView-C3_KtgFQ.js} +15 -15
  40. package/dist/api/netsuite.d.ts +9 -3
  41. package/dist/{app-EpEEb8EO.js → app-C2nudFnk.js} +1272 -1191
  42. package/dist/app.d.ts +21 -0
  43. package/dist/app.js +5 -5
  44. package/dist/{closing-template-zIjwO1_E.js → closing-template-fRmBNy4y.js} +1 -1
  45. package/dist/{date2-Dnc8Y81g.js → date2-ngfXp6E2.js} +1 -1
  46. package/dist/{dayjs.min-TdUgzmww.js → dayjs.min-BvcCfiWk.js} +1 -1
  47. package/dist/{decimal-C6s3GvGb.js → decimal-h7clfS02.js} +2 -2
  48. package/dist/{defineDeepModel-BSaaXVBF.js → defineDeepModel-C_n3Ytw6.js} +1 -1
  49. package/dist/{duplicate-template-Bw0H416G.js → duplicate-template-CHiQ3uHE.js} +1 -1
  50. package/dist/{feature-C95Hao53.js → feature-CrcV14lV.js} +2 -2
  51. package/dist/{format-time-from-id-DlbHo6kY.js → format-time-from-id-ljQJ36VV.js} +1 -1
  52. package/dist/{format-unit-display-QBS54q0R.js → format-unit-display-r1oynPKD.js} +10 -10
  53. package/dist/{import-export.helper-CUKCKtP7.js → import-export.helper-C5TdWJLB.js} +5 -5
  54. package/dist/{index-goD-WGVb.js → index-C0Q6KaoS.js} +3 -3
  55. package/dist/{index-CFn_9RMm.js → index-DluVXb7-.js} +1 -1
  56. package/dist/{index-S9Ak__QC.js → index-gutj1NVB.js} +1 -1
  57. package/dist/{lodash-gq8IrP4j.js → lodash-CJ0fXmvq.js} +1 -1
  58. package/dist/netsuite-Dp3KQlN9.js +4979 -0
  59. package/dist/{purchase-order-template-CBIpWdEW.js → purchase-order-template-CTICqz-0.js} +1 -1
  60. package/dist/{rules-DKklsaS1.js → rules-CWhZXxdv.js} +3 -3
  61. package/dist/{stock-BW8fen3H.js → stock-BpY8FTMC.js} +3 -3
  62. package/dist/{stock-3K93Mif9.js → stock-DHpvp37w.js} +1 -1
  63. package/dist/stores/integration/netsuite.d.ts +5 -1
  64. package/dist/{supplier-CObCSfot.js → supplier-CfiMZbRg.js} +2 -2
  65. package/dist/tsconfig.app.tsbuildinfo +1 -1
  66. package/dist/{use-ingredient-select-dialog-DwvQiaVW.js → use-ingredient-select-dialog-DrYxhoTU.js} +2 -2
  67. package/dist/{use-inventory-binding-dialog-CuLEHLDM.js → use-inventory-binding-dialog-BAYX4xEg.js} +2 -2
  68. package/dist/{use-template-enabled-locations-2-DkUJeppb.js → use-template-enabled-locations-2-DbNAe5rC.js} +2 -2
  69. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +1 -0
  70. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +12 -0
  71. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +12 -0
  72. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +6 -2
  73. package/dist/{vue-i18n-CUznvVzc.js → vue-i18n-BNE50uOV.js} +424 -424
  74. package/dist/{xlsx-bT1p3YVR.js → xlsx-BSJt4rqr.js} +398 -398
  75. package/dist/{xlsx.util-Cr9DpDFb.js → xlsx.util-DEF923iN.js} +1 -1
  76. package/package.json +4 -4
  77. package/dist/ClosingTemplateView-C_IiKnGx.js +0 -2019
  78. package/dist/netsuite-CnhAKyAO.js +0 -4316
@@ -0,0 +1,4979 @@
1
+ import { m as e, U as jt, V as Vt, W as Bt, X as qt, Y as je, Z as Ht, _ as Be, L as qe, $ as bt, a0 as St, a1 as R, a2 as O, s as C, e as ve, a3 as Oe, Q as ee, z as ie, a4 as Kt, J as j, a5 as vt, a6 as V, a7 as Yt, a8 as Gt, a9 as Jt, aa as Qe, ab as zt, o as Qt, j as Wt, t as dt, a as Zt, u as Ce } from "./app-C2nudFnk.js";
2
+ import { useCoreStore as Me } from "@feedmepos/mf-common";
3
+ import { useSnackbar as Xt } from "@feedmepos/ui-library";
4
+ import { _ as L } from "./lodash-CJ0fXmvq.js";
5
+ import { defineComponent as en, ref as He, computed as le, resolveComponent as we, openBlock as z, createBlock as tn, withCtx as re, createVNode as oe, createElementVNode as M, createElementBlock as ae, Fragment as Re, createCommentVNode as Ae, createTextVNode as Q, toDisplayString as x, renderList as nn, unref as ct, h as sn } from "vue";
6
+ import { u as rn } from "./feature-CrcV14lV.js";
7
+ var on = Object.defineProperty, g = (s, a) => on(s, "name", { value: a, configurable: !0 }), he = "MYR";
8
+ e.enum([
9
+ "custbody_fm_do_id",
10
+ "custbody_fm_po_request_id",
11
+ "custbody_fm_po_id",
12
+ "custbody_fm_po_num",
13
+ "custbody_fm_created_by_id",
14
+ "custbody_fm_created_by_name",
15
+ "custbody_fm_adjustment_id"
16
+ ]);
17
+ e.enum([
18
+ /// purchase order item id
19
+ /// delivery fulfillment item id
20
+ /// delivery order item id
21
+ "custcol_fm_line_id"
22
+ ]);
23
+ var Ke;
24
+ (function(s) {
25
+ s[s.Create = 0] = "Create", s[s.Set = 1] = "Set", s[s.Unset = 2] = "Unset", s[s.Change = 3] = "Change";
26
+ })(Ke || (Ke = {}));
27
+ e.nativeEnum(Ke);
28
+ e.enum([
29
+ "TrnfrOrd",
30
+ "PurchOrd"
31
+ ]);
32
+ var We = e.object({
33
+ hascostline: e.string(),
34
+ itemid: e.string(),
35
+ transactionline: e.string(),
36
+ amount: e.string().nullish(),
37
+ debit: e.string().nullish(),
38
+ credit: e.string().nullish(),
39
+ memo: e.string().nullish(),
40
+ rate: e.string().nullish(),
41
+ // custcol_fm_line_id: z.string().nullish(),
42
+ isocurrency: e.string().nullish()
43
+ });
44
+ e.object({
45
+ lineid: e.string(),
46
+ item: e.string().optional(),
47
+ // item fulfillment and item receipt refering to this as `orderLine`
48
+ // it can be refer back to `id` in purchase/transfer order line id
49
+ transferorderitemlineid: e.string().optional(),
50
+ /// In order to find the related gl impact for [inventory transfer]
51
+ /// First find the lineid that with `mainLine` = 'T',
52
+ /// then +1 to get the next line which should have the cost
53
+ mainline: e.string().optional()
54
+ });
55
+ e.object({
56
+ datetime: e.string(),
57
+ field: e.string(),
58
+ status: e.string(),
59
+ recordid: e.string()
60
+ });
61
+ e.object({
62
+ lineid: e.string().nullish(),
63
+ _contextname: e.string(),
64
+ _dateiso8601: e.string(),
65
+ _employeeid: e.string().nullish(),
66
+ _employeename: e.string().nullish(),
67
+ _fieldname: e.string().nullish(),
68
+ field: e.string().nullish(),
69
+ _recordtype: e.string().nullish(),
70
+ _rolename: e.string().nullish(),
71
+ type: e.string(),
72
+ oldvalue: e.string().nullish(),
73
+ newvalue: e.string().nullish(),
74
+ recordid: e.string()
75
+ });
76
+ var an = e.object({
77
+ custcol_fm_line_id: e.string().nullish(),
78
+ item: e.object({
79
+ id: e.string(),
80
+ refName: e.string()
81
+ }),
82
+ line: e.number(),
83
+ orderLine: e.number(),
84
+ quantity: e.number(),
85
+ units: e.string(),
86
+ /// Zus
87
+ custcol_pkt_code: e.string().nullish(),
88
+ custcol_pkt_name: e.string().nullish()
89
+ }), un = e.object({
90
+ createdDate: e.string(),
91
+ orderType: e.string(),
92
+ orderId: e.number(),
93
+ id: e.string(),
94
+ item: e.object({
95
+ items: e.array(an),
96
+ totalResults: e.number()
97
+ }),
98
+ tranDate: e.string(),
99
+ tranId: e.string(),
100
+ lastModifiedDate: e.string(),
101
+ memo: e.string().nullish(),
102
+ subsidiary: e.object({
103
+ id: e.string(),
104
+ refName: e.string()
105
+ })
106
+ });
107
+ un.extend({
108
+ glImpacts: e.array(We).nullish()
109
+ });
110
+ e.object({
111
+ item: e.object({
112
+ items: e.array(e.object({
113
+ item: e.object({
114
+ id: e.string()
115
+ }),
116
+ itemReceive: e.boolean(),
117
+ orderLine: e.number(),
118
+ quantity: e.number().positive().nullish()
119
+ }))
120
+ })
121
+ });
122
+ var dn = e.object({
123
+ custcol_fm_line_id: e.string().nullish(),
124
+ custcol_pkt_code: e.string().nullish(),
125
+ custcol_pkt_name: e.string().nullish(),
126
+ item: e.object({
127
+ id: e.string(),
128
+ refName: e.string()
129
+ }),
130
+ line: e.number(),
131
+ orderLine: e.number(),
132
+ quantity: e.number(),
133
+ units: e.string()
134
+ }), cn = e.object({
135
+ custbody_fm_do_id: e.string().nullish(),
136
+ createdDate: e.string(),
137
+ id: e.string(),
138
+ currency: e.object({
139
+ id: e.string(),
140
+ refName: e.string()
141
+ }),
142
+ item: e.object({
143
+ items: e.array(dn),
144
+ totalResults: e.number()
145
+ }),
146
+ itemFulfillment: e.object({
147
+ id: e.string(),
148
+ refName: e.string()
149
+ }).nullish(),
150
+ lastModifiedDate: e.string(),
151
+ orderId: e.number(),
152
+ orderType: e.string(),
153
+ tranDate: e.string(),
154
+ tranId: e.string(),
155
+ custbody_fm_created_by_id: e.string().nullish(),
156
+ custbody_fm_created_by_name: e.string().nullish()
157
+ });
158
+ cn.extend({
159
+ glImpacts: e.array(We).nullish()
160
+ });
161
+ e.object({
162
+ trandate: e.string(),
163
+ purchaseOrderId: e.string(),
164
+ items: e.array(e.object({
165
+ itemId: e.string(),
166
+ quantity: e.number().positive()
167
+ })),
168
+ fields: e.object({
169
+ custbody_fm_do_id: e.string(),
170
+ custbody_fm_created_by_id: e.string(),
171
+ custbody_fm_created_by_name: e.string()
172
+ })
173
+ });
174
+ e.object({
175
+ trandate: e.string(),
176
+ transferOrderId: e.string(),
177
+ itemFulfillmentId: e.string(),
178
+ items: e.array(e.object({
179
+ orderLine: e.string().optional(),
180
+ itemId: e.string(),
181
+ quantity: e.number().positive()
182
+ })),
183
+ fields: e.object({
184
+ custbody_fm_do_id: e.string(),
185
+ custbody_fm_created_by_id: e.string(),
186
+ custbody_fm_created_by_name: e.string()
187
+ })
188
+ });
189
+ e.object({
190
+ trandate: e.string(),
191
+ items: e.array(e.object({
192
+ /// As we stored `orderLine` as `externalId` in delivery orders,
193
+ /// we need to fetch item receipt from netsuite,
194
+ /// then we can get the `line` mapping with `externalId`
195
+ /// because netsuite item receipt not able to update based on `orderLine`
196
+ line: e.number(),
197
+ itemId: e.string(),
198
+ quantity: e.number().positive(),
199
+ custcol_fm_line_id: e.string()
200
+ })).nullish(),
201
+ custbody_fm_do_id: e.string(),
202
+ custbody_fm_created_by_id: e.string(),
203
+ custbody_fm_created_by_name: e.string()
204
+ });
205
+ var ln = e.object({
206
+ amount: e.number(),
207
+ custcol_pkt_code: e.string(),
208
+ custcol_pkt_name: e.string(),
209
+ item: e.object({
210
+ id: e.string(),
211
+ refName: e.string()
212
+ }),
213
+ itemType: e.object({
214
+ id: e.string(),
215
+ refName: e.string()
216
+ }),
217
+ isClosed: e.boolean().nullish(),
218
+ line: e.number(),
219
+ quantity: e.number(),
220
+ rate: e.number(),
221
+ units: e.string(),
222
+ expectedReceiptDate: e.string().nullish()
223
+ });
224
+ e.object({
225
+ custbody_fm_po_id: e.string().nullable(),
226
+ custbody_fm_po_num: e.number().nullable(),
227
+ currency: e.object({
228
+ id: e.string(),
229
+ refName: e.string()
230
+ }),
231
+ approvalStatus: e.object({
232
+ id: e.string(),
233
+ refName: e.string()
234
+ }),
235
+ createdDate: e.string(),
236
+ externalId: e.string().nullish(),
237
+ id: e.string(),
238
+ item: e.object({
239
+ items: e.array(ln),
240
+ totalResults: e.number()
241
+ }),
242
+ lastModifiedDate: e.string(),
243
+ location: e.object({
244
+ id: e.string(),
245
+ refName: e.string()
246
+ }),
247
+ memo: e.string().nullish(),
248
+ orderStatus: e.object({
249
+ id: e.string(),
250
+ refName: e.string()
251
+ }),
252
+ status: e.object({
253
+ id: e.string(),
254
+ refName: e.string()
255
+ }),
256
+ subsidiary: e.object({
257
+ id: e.string(),
258
+ refName: e.string()
259
+ }),
260
+ subtotal: e.number(),
261
+ total: e.number(),
262
+ tranDate: e.string(),
263
+ tranId: e.string(),
264
+ entity: e.object({
265
+ id: e.string(),
266
+ refName: e.string()
267
+ })
268
+ });
269
+ var mn = e.object({
270
+ line: e.number().optional(),
271
+ item: e.object({
272
+ id: e.string()
273
+ }),
274
+ quantity: e.number().positive(),
275
+ location: e.object({
276
+ id: e.string()
277
+ }),
278
+ units: e.string(),
279
+ amount: e.number().positive().nullish(),
280
+ rate: e.number().positive().nullish(),
281
+ custcol_pkt_code: e.string().nullish(),
282
+ custcol_pkt_name: e.string().nullish(),
283
+ externalId: e.string().nullish()
284
+ });
285
+ e.object({
286
+ entity: e.object({
287
+ id: e.string()
288
+ }),
289
+ location: e.object({
290
+ id: e.string()
291
+ }),
292
+ subsidiary: e.object({
293
+ id: e.string()
294
+ }),
295
+ item: e.object({
296
+ items: e.array(mn)
297
+ }),
298
+ orderStatus: e.object({
299
+ id: e.string()
300
+ }).optional(),
301
+ custbody_fm_po_id: e.string(),
302
+ custbody_fm_po_num: e.number(),
303
+ memo: e.string().nullish(),
304
+ approvalStatus: e.object({
305
+ id: e.string(),
306
+ refName: e.string()
307
+ }).optional()
308
+ });
309
+ var fn = e.object({
310
+ location: e.object({
311
+ id: e.string()
312
+ }),
313
+ item: e.object({
314
+ id: e.string()
315
+ }),
316
+ line: e.number().optional(),
317
+ quantity: e.number().positive(),
318
+ unit: e.object({
319
+ id: e.string()
320
+ }),
321
+ custcol_pkt_code: e.string().nullish(),
322
+ custcol_pkt_name: e.string().nullish(),
323
+ externalId: e.string().nullish()
324
+ });
325
+ e.object({
326
+ trandate: e.string().nullish(),
327
+ item: e.object({
328
+ items: e.array(fn)
329
+ }).optional(),
330
+ custbody_fm_po_id: e.string(),
331
+ custbody_fm_po_num: e.number()
332
+ });
333
+ var De;
334
+ (function(s) {
335
+ s.A = "Pending Supervisor Approval", s.B = "Approved by Supervisor/Pending Receipt", s.C = "Rejected", s.D = "Partially Received", s.E = "Pending Billing/Partially Received", s.F = "Approved by Supervisor/Pending Bill", s.G = "Fully Billed", s.H = "Closed";
336
+ })(De || (De = {}));
337
+ var X = e.nativeEnum(De), In = e.object({
338
+ amount: e.number().nullish(),
339
+ custcol_fm_line_id: e.string().nullish(),
340
+ item: e.object({
341
+ id: e.string(),
342
+ refName: e.string()
343
+ }),
344
+ isClosed: e.boolean().nullish(),
345
+ line: e.number(),
346
+ quantity: e.number().positive(),
347
+ units: e.string(),
348
+ quantityFulfilled: e.number().positive().nullish(),
349
+ /// ZUS Project
350
+ custcol_item_external_id: e.string().nullish(),
351
+ custcol_pkt_code: e.string().nullish(),
352
+ custcol_pkt_name: e.string().nullish()
353
+ });
354
+ e.object({
355
+ custbody_fm_po_num: e.string().optional(),
356
+ custbody_fm_po_request_id: e.string().optional(),
357
+ createdDate: e.string(),
358
+ currency: e.object({
359
+ id: e.string(),
360
+ refName: e.string()
361
+ }),
362
+ id: e.string(),
363
+ item: e.object({
364
+ items: e.array(In)
365
+ }),
366
+ lastModifiedDate: e.string(),
367
+ location: e.object({
368
+ id: e.string(),
369
+ refName: e.string()
370
+ }),
371
+ memo: e.string().nullish(),
372
+ orderStatus: e.object({
373
+ id: e.string(),
374
+ refName: e.string()
375
+ }),
376
+ status: e.object({
377
+ id: e.string(),
378
+ refName: e.string()
379
+ }),
380
+ subsidiary: e.object({
381
+ id: e.string(),
382
+ refName: e.string()
383
+ }),
384
+ tranDate: e.string(),
385
+ tranId: e.string(),
386
+ transferLocation: e.object({
387
+ id: e.string(),
388
+ refName: e.string()
389
+ }),
390
+ shipDate: e.string().nullish()
391
+ });
392
+ var pn = e.object({
393
+ amount: e.number().nullish(),
394
+ rate: e.number().nullish(),
395
+ item: e.object({
396
+ id: e.string()
397
+ }),
398
+ line: e.number().optional(),
399
+ quantity: e.number().positive(),
400
+ units: e.string(),
401
+ custcol_pkt_code: e.string().nullish(),
402
+ custcol_pkt_name: e.string().nullish(),
403
+ externalId: e.string().nullish()
404
+ }), gn = e.object({
405
+ item: e.object({
406
+ id: e.string()
407
+ }),
408
+ line: e.number().optional(),
409
+ quantity: e.number().positive(),
410
+ unit: e.object({
411
+ id: e.string()
412
+ }),
413
+ isClosed: e.boolean().nullish(),
414
+ custcol_pkt_code: e.string().nullish(),
415
+ custcol_pkt_name: e.string().nullish(),
416
+ externalId: e.string().nullish()
417
+ });
418
+ e.object({
419
+ location: e.object({
420
+ // from location
421
+ id: e.string()
422
+ }),
423
+ transferLocation: e.object({
424
+ // to location
425
+ id: e.string()
426
+ }),
427
+ subsidiary: e.object({
428
+ id: e.string()
429
+ }),
430
+ item: e.object({
431
+ items: e.array(pn)
432
+ }),
433
+ orderStatus: e.object({
434
+ id: e.string()
435
+ }).optional(),
436
+ approvalStatus: e.object({
437
+ id: e.string(),
438
+ refName: e.string()
439
+ }).optional(),
440
+ memo: e.string().nullish(),
441
+ custbody_fm_po_num: e.number(),
442
+ custbody_fm_po_request_id: e.string()
443
+ });
444
+ e.object({
445
+ orderStatus: e.object({
446
+ id: e.string()
447
+ }).optional(),
448
+ trandate: e.string().nullish(),
449
+ item: e.object({
450
+ items: e.array(gn)
451
+ }).optional(),
452
+ custbody_fm_po_request_id: e.string(),
453
+ custbody_fm_po_num: e.number()
454
+ });
455
+ var w;
456
+ (function(s) {
457
+ s.A = "Pending Approval", s.B = "Pending Fulfillment", s.C = "Rejected", s.D = "Partially Fulfilled", s.E = "Pending Receipt/Partially Fulfilled", s.F = "Pending Receipt", s.G = "Received", s.H = "Closed";
458
+ })(w || (w = {}));
459
+ var ue = e.nativeEnum(w), En = e.object({
460
+ abbreviation: e.string(),
461
+ baseUnit: e.boolean(),
462
+ conversionRate: e.number(),
463
+ internalId: e.number(),
464
+ inUse: e.boolean(),
465
+ pluralAbbreviation: e.string(),
466
+ pluralName: e.string(),
467
+ unitName: e.string()
468
+ });
469
+ e.object({
470
+ id: e.string(),
471
+ isInactive: e.boolean(),
472
+ lastModifiedDate: e.string(),
473
+ name: e.string(),
474
+ uom: e.object({
475
+ items: e.array(En),
476
+ totalResults: e.number()
477
+ })
478
+ });
479
+ var Tt = jt.extend({
480
+ nsConfig: Vt
481
+ }), ht = Bt.omit({
482
+ measurements: !0
483
+ }).extend({
484
+ nsConfig: qt,
485
+ measurements: e.array(Tt)
486
+ }), yn = e.object({
487
+ itemVendorPrice: e.object({
488
+ itemvendorpricelines: e.object({
489
+ items: e.array(e.object({
490
+ id: e.number(),
491
+ vendorcurrency: e.object({
492
+ id: e.string(),
493
+ refName: e.string()
494
+ }),
495
+ vendorprice: e.number()
496
+ })),
497
+ totalResults: e.number()
498
+ })
499
+ }).nullish(),
500
+ preferredVendor: e.boolean(),
501
+ purchasePrice: e.number().nullish(),
502
+ subsidiary: e.object({
503
+ id: e.string(),
504
+ refName: e.string()
505
+ }),
506
+ vendor: e.object({
507
+ id: e.string(),
508
+ refName: e.string()
509
+ }),
510
+ vendorCode: e.string().nullish(),
511
+ vendorCurrencyId: e.object({
512
+ id: e.string(),
513
+ refName: e.string()
514
+ }).nullish(),
515
+ vendorCurrencyName: e.string().nullish()
516
+ });
517
+ e.object({
518
+ averageCost: e.number().nullish(),
519
+ baseUnit: e.string(),
520
+ purchaseUnit: e.string(),
521
+ stockUnit: e.string(),
522
+ parent: e.object({
523
+ id: e.string(),
524
+ refName: e.string()
525
+ }).nullish(),
526
+ cogsAccount: e.object({
527
+ id: e.string(),
528
+ refName: e.string()
529
+ }).nullish(),
530
+ cost: e.number(),
531
+ costingMethod: e.object({
532
+ id: e.string(),
533
+ refName: e.string()
534
+ }),
535
+ createdDate: e.string(),
536
+ currency: e.object({
537
+ id: e.string(),
538
+ refName: e.string()
539
+ }),
540
+ displayName: e.string().nullish(),
541
+ id: e.string(),
542
+ includeChildren: e.boolean(),
543
+ internalId: e.number(),
544
+ isInactive: e.boolean(),
545
+ itemId: e.string(),
546
+ itemType: e.object({
547
+ id: e.string(),
548
+ refName: e.string()
549
+ }),
550
+ itemVendor: e.object({
551
+ items: e.array(yn),
552
+ totalResults: e.number()
553
+ }),
554
+ lastModifiedDate: e.string(),
555
+ subsidiary: e.object({
556
+ items: e.array(e.object({
557
+ id: e.string(),
558
+ refName: e.string()
559
+ })),
560
+ totalResults: e.number()
561
+ }),
562
+ unitsType: e.object({
563
+ // Cannot be changed once item created
564
+ id: e.string(),
565
+ refName: e.string()
566
+ }).nullish(),
567
+ /// Zus
568
+ externalId: e.string(),
569
+ custitem_item_externalid: e.string().nullish(),
570
+ custitem_item_externalid_current: e.string().nullish(),
571
+ custitem_pkt_code: e.string().nullish(),
572
+ custitem_pkt_name: e.string().nullish()
573
+ });
574
+ je.omit({
575
+ unit: !0
576
+ }).extend({
577
+ unit: ht,
578
+ nsConfig: Ht
579
+ });
580
+ e.enum([
581
+ "AVG",
582
+ "FIFO",
583
+ "LIFO"
584
+ ]);
585
+ var _n = e.object({
586
+ addressBookAddress: e.object({
587
+ attention: e.string().nullish(),
588
+ addressee: e.string(),
589
+ addr1: e.string().nullish(),
590
+ addr2: e.string().nullish(),
591
+ city: e.string().nullish(),
592
+ country: e.object({
593
+ id: e.string(),
594
+ refName: e.string()
595
+ }),
596
+ state: e.string().nullish(),
597
+ zip: e.string().nullish()
598
+ }),
599
+ defaultBilling: e.boolean(),
600
+ defaultShipping: e.boolean()
601
+ });
602
+ e.object({
603
+ id: e.string(),
604
+ companyName: e.string(),
605
+ dateCreated: e.string(),
606
+ addressBook: e.object({
607
+ items: e.array(_n),
608
+ totalResults: e.number()
609
+ }),
610
+ email: e.string().nullish(),
611
+ phone: e.string().nullish(),
612
+ lastModifiedDate: e.string(),
613
+ subsidiary: e.object({
614
+ id: e.string(),
615
+ refName: e.string()
616
+ })
617
+ });
618
+ e.enum([
619
+ "unitstype",
620
+ "transferorder",
621
+ "purchaseorder",
622
+ "inventoryitem",
623
+ "itemfulfillment",
624
+ "itemreceipt",
625
+ "inventorytransfer"
626
+ ]);
627
+ e.object({
628
+ event: e.string(),
629
+ recordId: e.string(),
630
+ recordType: e.string(),
631
+ accountId: e.string(),
632
+ source: e.string().nullish()
633
+ });
634
+ var bn = e.object({
635
+ adjustQtyBy: e.number().positive(),
636
+ item: e.object({
637
+ id: e.string(),
638
+ refName: e.string()
639
+ }),
640
+ line: e.number().positive(),
641
+ units: e.string()
642
+ }), Sn = e.object({
643
+ createdDate: e.string(),
644
+ id: e.string(),
645
+ inventory: e.object({
646
+ items: e.array(bn),
647
+ totalResults: e.number().positive()
648
+ }),
649
+ lastModifiedDate: e.string(),
650
+ location: e.object({
651
+ id: e.string(),
652
+ refName: e.string()
653
+ }),
654
+ subsidiary: e.object({
655
+ id: e.string(),
656
+ refName: e.string()
657
+ }),
658
+ tranDate: e.string(),
659
+ tranId: e.string(),
660
+ transferLocation: e.object({
661
+ id: e.string(),
662
+ refName: e.string()
663
+ }),
664
+ custbody_fm_po_num: e.number().nullish(),
665
+ custbody_fm_po_request_id: e.string().nullish(),
666
+ custbody_fm_adjustment_id: e.string().nullish()
667
+ }), vn = e.object({
668
+ item: e.object({
669
+ id: e.string()
670
+ }),
671
+ adjustQtyBy: e.number().positive(),
672
+ units: e.string()
673
+ });
674
+ e.object({
675
+ tranDate: e.string(),
676
+ location: e.object({
677
+ // from location
678
+ id: e.string()
679
+ }),
680
+ transferLocation: e.object({
681
+ // to location
682
+ id: e.string()
683
+ }),
684
+ subsidiary: e.object({
685
+ id: e.string()
686
+ }),
687
+ inventory: e.object({
688
+ items: e.array(vn)
689
+ }),
690
+ custbody_fm_adjustment_id: e.string()
691
+ });
692
+ e.object({
693
+ custbody_fm_po_id: e.string(),
694
+ custbody_fm_po_num: e.number(),
695
+ custbody_fm_po_request_id: e.string().nullish()
696
+ });
697
+ Sn.extend({
698
+ glImpacts: e.array(We).nullish()
699
+ });
700
+ e.object({
701
+ externalId: e.string(),
702
+ id: e.string(),
703
+ isInactive: e.boolean().nullish(),
704
+ lastModifiedDate: e.string(),
705
+ mainAddress: e.object({
706
+ addr1: e.string().nullish(),
707
+ addr2: e.string().nullish(),
708
+ addressee: e.string().nullish(),
709
+ addrText: e.string().nullish(),
710
+ attention: e.string().nullish(),
711
+ city: e.string().nullish(),
712
+ country: e.object({
713
+ id: e.string(),
714
+ refName: e.string()
715
+ }).nullish(),
716
+ state: e.string().nullish(),
717
+ zip: e.string().nullish()
718
+ }),
719
+ name: e.string(),
720
+ returnAddress: e.object({
721
+ addrText: e.string().nullish(),
722
+ country: e.object({
723
+ id: e.string(),
724
+ refName: e.string()
725
+ })
726
+ }).nullish(),
727
+ subsidiary: e.object({
728
+ items: e.array(e.object({
729
+ id: e.string(),
730
+ refName: e.string()
731
+ })),
732
+ totalResults: e.number()
733
+ }),
734
+ timeZone: e.object({
735
+ id: e.string(),
736
+ refName: e.string()
737
+ })
738
+ });
739
+ e.object({
740
+ netsuiteId: e.string(),
741
+ name: e.string(),
742
+ subsidiaryName: e.string(),
743
+ subsidiaryId: e.string()
744
+ });
745
+ e.object({
746
+ id: e.string(),
747
+ name: e.string(),
748
+ parent: e.object({
749
+ id: e.string(),
750
+ refName: e.string()
751
+ }).nullish(),
752
+ country: e.object({
753
+ id: e.string(),
754
+ refName: e.string()
755
+ }),
756
+ currency: e.object({
757
+ id: e.string(),
758
+ refName: e.string()
759
+ })
760
+ });
761
+ e.object({
762
+ id: e.string(),
763
+ createdAt: e.string(),
764
+ effectiveAt: e.string(),
765
+ recordType: Be,
766
+ status: e.string().optional(),
767
+ fulfillments: e.array(e.string()).optional(),
768
+ receipts: e.array(e.string()).optional()
769
+ });
770
+ e.object({
771
+ type: e.enum([
772
+ "transferIn",
773
+ "transferOut"
774
+ ]),
775
+ adjustmentId: e.string().nullish(),
776
+ netsuiteId: e.string().nullish(),
777
+ netsuiteTranId: e.string().nullish(),
778
+ netsuiteTranDate: e.string().nullish(),
779
+ sourceLocation: e.object({
780
+ netSuiteId: e.string().nullish(),
781
+ netSuiteName: e.string().nullish()
782
+ }),
783
+ destinationLocation: e.object({
784
+ netSuiteId: e.string().nullish(),
785
+ netSuiteName: e.string().nullish()
786
+ }),
787
+ items: e.array(e.object({
788
+ itemId: e.string().nullish(),
789
+ itemName: e.string().nullish(),
790
+ quantity: e.number().min(0).optional(),
791
+ uomId: e.string().nullish(),
792
+ uomName: e.string().nullish()
793
+ })).optional()
794
+ });
795
+ e.object({
796
+ parent: e.object({
797
+ id: e.string(),
798
+ refName: e.string()
799
+ }).nullish(),
800
+ averageCost: e.number(),
801
+ baseUnit: e.string(),
802
+ cogsAccount: e.object({
803
+ id: e.string(),
804
+ refName: e.string()
805
+ }).nullish(),
806
+ consumptionUnit: e.string(),
807
+ cost: e.number().nullish(),
808
+ costingMethod: e.object({
809
+ id: e.string(),
810
+ refName: e.string()
811
+ }),
812
+ createdDate: e.string(),
813
+ currency: e.object({
814
+ id: e.string(),
815
+ refName: e.string()
816
+ }),
817
+ id: e.string(),
818
+ includeChildren: e.boolean(),
819
+ internalId: e.number(),
820
+ isGCoCompliant: e.boolean(),
821
+ isInactive: e.boolean(),
822
+ isLotItem: e.boolean(),
823
+ isOnline: e.boolean(),
824
+ isPhantom: e.boolean(),
825
+ isSerialItem: e.boolean(),
826
+ isSpecialWorkOrderItem: e.boolean(),
827
+ itemId: e.string(),
828
+ itemOptions: e.object({
829
+ count: e.number(),
830
+ hasMore: e.boolean(),
831
+ items: e.array(e.unknown()),
832
+ offset: e.number(),
833
+ totalResults: e.number()
834
+ }),
835
+ itemType: e.object({
836
+ id: e.string(),
837
+ refName: e.string()
838
+ }),
839
+ itemVendor: e.object({
840
+ items: e.array(e.unknown()),
841
+ totalResults: e.number()
842
+ }),
843
+ lastModifiedDate: e.string(),
844
+ lastPurchasePrice: e.number().nullish(),
845
+ purchaseUnit: e.string(),
846
+ saleUnit: e.string(),
847
+ stockUnit: e.string(),
848
+ subsidiary: e.object({
849
+ count: e.number(),
850
+ hasMore: e.boolean(),
851
+ items: e.array(e.object({
852
+ id: e.string(),
853
+ refName: e.string()
854
+ })),
855
+ offset: e.number(),
856
+ totalResults: e.number()
857
+ }),
858
+ unitsType: e.object({
859
+ id: e.string(),
860
+ refName: e.string()
861
+ }),
862
+ /// custom fields
863
+ externalId: e.string().nullish()
864
+ });
865
+ function Ze(s) {
866
+ return Oe.FCurrency.safeParse(s.trim().toUpperCase()).success;
867
+ }
868
+ g(Ze, "isCurrencySupported");
869
+ var lt;
870
+ (function(s) {
871
+ (function(a) {
872
+ function u(r, t) {
873
+ var v, N;
874
+ const { nsAssemblyItem: n, fmUnit: i, nsUnitTypeConfig: o } = r;
875
+ if (!n.unitsType)
876
+ throw new Error(`Missing unit type in NetSuite assembly item ${n.id}`);
877
+ if (o.netSuiteId !== n.unitsType.id)
878
+ throw new Error(`Unit type mismatch for NetSuite assembly item ${n.id}: expected unit type ID ${n.unitsType.id}, got ${o.netSuiteId}`);
879
+ const m = n.subsidiary.items.map((D) => D.id), l = R({
880
+ prefix: O.Enum.sku
881
+ }), f = (v = t == null ? void 0 : t.netsuiteCustomAttributes) == null ? void 0 : v.reduce((D, b) => {
882
+ const A = b.compute(r);
883
+ return {
884
+ ...D,
885
+ [b.fieldId]: A
886
+ };
887
+ }, {}), d = n.purchaseUnit === n.baseUnit;
888
+ let I = null;
889
+ if (!d) {
890
+ const D = o.measurements.find((b) => b.netSuiteId === n.purchaseUnit);
891
+ if (!D)
892
+ throw new Error(`Measurement with NetSuite ID ${n.purchaseUnit} not found in unit ${i._id} (NetSuite unit type ${n.unitsType.id}). Please sync unit types before syncing assembly items.`);
893
+ I = D.id;
894
+ }
895
+ const p = (N = t == null ? void 0 : t.overrideAttributes) == null ? void 0 : N.reduce((D, b) => {
896
+ const A = b.compute(r);
897
+ return {
898
+ ...D,
899
+ [b.fieldId]: A
900
+ };
901
+ }, {}), E = n.currency.refName.trim().toUpperCase(), y = n.cost ?? n.lastPurchasePrice, _ = {
902
+ _id: l,
903
+ name: n.itemId,
904
+ code: n.id,
905
+ unit: i,
906
+ trackingMeasurement: I,
907
+ convert: null,
908
+ valuation: Dt(n),
909
+ isInactive: n.isInactive,
910
+ defaultCost: y ? {
911
+ costPerUnit: {
912
+ currency: Ze(E) ? E : he,
913
+ ...C.fromNumber(y)
914
+ }
915
+ } : null,
916
+ ...p
917
+ };
918
+ return {
919
+ businessId: "",
920
+ itemType: n.itemType.refName,
921
+ skuCache: _,
922
+ name: n.itemId,
923
+ netSuiteId: String(n.internalId),
924
+ unitTypeId: n.unitsType.id,
925
+ unitOfMeasureId: n.purchaseUnit,
926
+ cogsAccount: n.cogsAccount ? {
927
+ id: n.cogsAccount.id,
928
+ refName: n.cogsAccount.refName
929
+ } : null,
930
+ subsidiaryIds: m,
931
+ includeChildren: n.includeChildren,
932
+ externalId: n.externalId,
933
+ customFields: {
934
+ ...f
935
+ }
936
+ };
937
+ }
938
+ g(u, "transformAsParent"), a.transformAsParent = u;
939
+ function c(r, t) {
940
+ var f;
941
+ const { nsAssemblyItem: n, nsUnitTypeConfig: i } = r;
942
+ if (!n.unitsType)
943
+ throw new Error(`Missing unit type in NetSuite assembly child item ${n.id}`);
944
+ if (i.netSuiteId !== n.unitsType.id)
945
+ throw new Error(`Unit type mismatch for NetSuite assembly child item ${n.id}: expected unit type ID ${n.unitsType.id}, got ${i.netSuiteId}`);
946
+ const o = n.subsidiary.items.map((d) => d.id), m = (f = t == null ? void 0 : t.netsuiteCustomAttributes) == null ? void 0 : f.reduce((d, I) => {
947
+ const p = I.compute(r);
948
+ return {
949
+ ...d,
950
+ [I.fieldId]: p
951
+ };
952
+ }, {});
953
+ return {
954
+ businessId: "",
955
+ parentNetSuiteId: n.parent.id,
956
+ itemType: n.itemType.refName,
957
+ name: n.itemId,
958
+ netSuiteId: String(n.internalId),
959
+ unitTypeId: n.unitsType.id,
960
+ unitOfMeasureId: n.purchaseUnit,
961
+ cogsAccount: n.cogsAccount ? {
962
+ id: n.cogsAccount.id,
963
+ refName: n.cogsAccount.refName
964
+ } : null,
965
+ subsidiaryIds: o,
966
+ includeChildren: n.includeChildren,
967
+ externalId: n.externalId,
968
+ customFields: {
969
+ ...m
970
+ }
971
+ };
972
+ }
973
+ g(c, "transformAsChild"), a.transformAsChild = c;
974
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
975
+ })(lt || (lt = {}));
976
+ function Dt(s) {
977
+ switch (s.costingMethod.id) {
978
+ case "FIFO":
979
+ return ve.Enum.FIFO;
980
+ case "LIFO":
981
+ return ve.Enum.LIFO;
982
+ default:
983
+ return ve.Enum.WAVG;
984
+ }
985
+ }
986
+ g(Dt, "_getValuation");
987
+ var mt;
988
+ (function(s) {
989
+ (function(a) {
990
+ function u(r, t) {
991
+ var v, N;
992
+ const { nsInventoryItem: n, fmUnit: i, nsUnitTypeConfig: o } = r;
993
+ if (!n.unitsType)
994
+ throw new Error(`Missing unit type in NetSuite inventory item ${n.id}`);
995
+ if (o.netSuiteId !== n.unitsType.id)
996
+ throw new Error(`Unit type mismatch for NetSuite inventory item ${n.id}: expected unit type ID ${n.unitsType.id}, got ${o.netSuiteId}`);
997
+ const m = n.subsidiary.items.map((D) => D.id), l = R({
998
+ prefix: O.Enum.sku
999
+ }), f = (v = t == null ? void 0 : t.netsuiteCustomAttributes) == null ? void 0 : v.reduce((D, b) => {
1000
+ const A = b.compute(r);
1001
+ return {
1002
+ ...D,
1003
+ [b.fieldId]: A
1004
+ };
1005
+ }, {}), d = n.purchaseUnit === n.baseUnit;
1006
+ let I = null;
1007
+ if (!d) {
1008
+ const D = o.measurements.find((b) => b.netSuiteId === n.purchaseUnit);
1009
+ if (!D)
1010
+ throw new Error(`Measurement with NetSuite ID ${n.purchaseUnit} not found in unit ${i._id} (NetSuite unit type ${n.unitsType.id}). Please sync unit types before syncing inventory items.`);
1011
+ I = D.id;
1012
+ }
1013
+ const p = (N = t == null ? void 0 : t.overrideAttributes) == null ? void 0 : N.reduce((D, b) => {
1014
+ const A = b.compute(r);
1015
+ return {
1016
+ ...D,
1017
+ [b.fieldId]: A
1018
+ };
1019
+ }, {}), E = n.currency.refName.trim().toUpperCase(), y = n.cost, _ = {
1020
+ _id: l,
1021
+ name: n.itemId,
1022
+ code: n.id,
1023
+ unit: i,
1024
+ trackingMeasurement: I,
1025
+ convert: null,
1026
+ valuation: Nt(n),
1027
+ isInactive: n.isInactive,
1028
+ defaultCost: y ? {
1029
+ costPerUnit: {
1030
+ currency: Ze(E) ? E : he,
1031
+ ...C.fromNumber(y)
1032
+ }
1033
+ } : null,
1034
+ ...p
1035
+ };
1036
+ return {
1037
+ businessId: "",
1038
+ itemType: n.itemType.refName,
1039
+ skuCache: _,
1040
+ name: n.itemId,
1041
+ netSuiteId: String(n.internalId),
1042
+ unitTypeId: n.unitsType.id,
1043
+ unitOfMeasureId: n.purchaseUnit,
1044
+ cogsAccount: n.cogsAccount ? {
1045
+ id: n.cogsAccount.id,
1046
+ refName: n.cogsAccount.refName
1047
+ } : null,
1048
+ subsidiaryIds: m,
1049
+ includeChildren: n.includeChildren,
1050
+ externalId: n.externalId,
1051
+ customFields: {
1052
+ ...f
1053
+ }
1054
+ };
1055
+ }
1056
+ g(u, "transformAsParent"), a.transformAsParent = u;
1057
+ function c(r, t) {
1058
+ var f;
1059
+ const { nsInventoryItem: n, nsUnitTypeConfig: i } = r;
1060
+ if (!n.unitsType)
1061
+ throw new Error(`Missing unit type in NetSuite inventory child item ${n.id}`);
1062
+ if (i.netSuiteId !== n.unitsType.id)
1063
+ throw new Error(`Unit type mismatch for NetSuite inventory child item ${n.id}: expected unit type ID ${n.unitsType.id}, got ${i.netSuiteId}`);
1064
+ const o = n.subsidiary.items.map((d) => d.id), m = (f = t == null ? void 0 : t.netsuiteCustomAttributes) == null ? void 0 : f.reduce((d, I) => {
1065
+ const p = I.compute(r);
1066
+ return {
1067
+ ...d,
1068
+ [I.fieldId]: p
1069
+ };
1070
+ }, {});
1071
+ return {
1072
+ businessId: "",
1073
+ parentNetSuiteId: n.parent.id,
1074
+ itemType: n.itemType.refName,
1075
+ name: n.itemId,
1076
+ netSuiteId: String(n.internalId),
1077
+ unitTypeId: n.unitsType.id,
1078
+ unitOfMeasureId: n.purchaseUnit,
1079
+ cogsAccount: n.cogsAccount ? {
1080
+ id: n.cogsAccount.id,
1081
+ refName: n.cogsAccount.refName
1082
+ } : null,
1083
+ subsidiaryIds: o,
1084
+ includeChildren: n.includeChildren,
1085
+ externalId: n.externalId,
1086
+ customFields: {
1087
+ ...m
1088
+ }
1089
+ };
1090
+ }
1091
+ g(c, "transformAsChild"), a.transformAsChild = c;
1092
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
1093
+ })(mt || (mt = {}));
1094
+ function Nt(s) {
1095
+ switch (s.costingMethod.id) {
1096
+ case "FIFO":
1097
+ return ve.Enum.FIFO;
1098
+ case "LIFO":
1099
+ return ve.Enum.LIFO;
1100
+ default:
1101
+ return ve.Enum.WAVG;
1102
+ }
1103
+ }
1104
+ g(Nt, "_getValuation");
1105
+ function Xe(s, a, u) {
1106
+ let c = 0, r = he;
1107
+ const t = s == null ? void 0 : s.find((n) => n.itemid === u && n.hascostline === "T" && n.transactionline === a);
1108
+ if (t) {
1109
+ const n = s == null ? void 0 : s.find((i) => i.itemid === u && Number(i.amount) > 0 && i.transactionline === String(Number(t.transactionline) + 1));
1110
+ n && (c = Number(n.amount), n.isocurrency && (r = n.isocurrency));
1111
+ } else {
1112
+ const n = s == null ? void 0 : s.find((i) => i.itemid === u);
1113
+ n && (c = Number(n.amount), n.isocurrency && (r = n.isocurrency));
1114
+ }
1115
+ return {
1116
+ cost: c,
1117
+ currency: r
1118
+ };
1119
+ }
1120
+ g(Xe, "getGLImpactCostMapping");
1121
+ var te;
1122
+ (function(s) {
1123
+ (function(a) {
1124
+ function u(t) {
1125
+ var p;
1126
+ const { poItem: n, nsItemSetting: i, nsUnitTypes: o, overrideCost: m = !0, customAttributes: l } = t;
1127
+ let f;
1128
+ if (m && n.totalCost) {
1129
+ const E = C.divide([
1130
+ n.totalCost,
1131
+ n.quantity
1132
+ ]);
1133
+ f = {
1134
+ amount: Number(C.toFormatString({
1135
+ value: n.totalCost
1136
+ })),
1137
+ rate: Number(C.toFormatString({
1138
+ value: E
1139
+ }))
1140
+ };
1141
+ }
1142
+ let d;
1143
+ if (n.measurement) {
1144
+ const E = n.measurement.id;
1145
+ for (const y of o)
1146
+ for (const _ of (y == null ? void 0 : y.measurements) || [])
1147
+ if (_.id === E) {
1148
+ d = _.netSuiteId;
1149
+ break;
1150
+ }
1151
+ } else
1152
+ d = (p = o.find((E) => E.id == n.sku.unit._id)) == null ? void 0 : p.baseUnitUnitOfMeasureId;
1153
+ const I = l == null ? void 0 : l.reduce((E, y) => {
1154
+ const _ = y.compute(t, y.extraParams);
1155
+ return {
1156
+ ...E,
1157
+ [y.fieldId]: _
1158
+ };
1159
+ }, {});
1160
+ return {
1161
+ ...f || {},
1162
+ item: {
1163
+ id: i.netSuiteId
1164
+ },
1165
+ line: n.externalId ? Number(n.externalId) : void 0,
1166
+ units: d,
1167
+ quantity: Number(C.toFormatString({
1168
+ value: n.quantity
1169
+ })),
1170
+ ...I
1171
+ };
1172
+ }
1173
+ g(u, "toCreateDto"), a.toCreateDto = u;
1174
+ function c(t) {
1175
+ var d;
1176
+ const {
1177
+ poItem: n,
1178
+ nsItemSetting: i,
1179
+ nsUnitTypes: o,
1180
+ // overrideCost = true,
1181
+ customAttributes: m
1182
+ } = t;
1183
+ let l;
1184
+ if (n.measurement) {
1185
+ const I = n.measurement.id;
1186
+ for (const p of o)
1187
+ for (const E of (p == null ? void 0 : p.measurements) || [])
1188
+ if (E.id === I) {
1189
+ l = E.netSuiteId;
1190
+ break;
1191
+ }
1192
+ } else
1193
+ l = (d = o.find((I) => I.id == n.sku.unit._id)) == null ? void 0 : d.baseUnitUnitOfMeasureId;
1194
+ const f = m == null ? void 0 : m.reduce((I, p) => {
1195
+ const E = p.compute(t, p.extraParams);
1196
+ return {
1197
+ ...I,
1198
+ [p.fieldId]: E
1199
+ };
1200
+ }, {});
1201
+ return {
1202
+ line: Number(n.externalId) || void 0,
1203
+ item: {
1204
+ id: i.netSuiteId
1205
+ },
1206
+ unit: {
1207
+ id: l
1208
+ },
1209
+ quantity: Number(C.toFormatString({
1210
+ value: n.quantity
1211
+ })),
1212
+ ...f
1213
+ };
1214
+ }
1215
+ g(c, "toTransferOrderItemUpdateDto"), a.toTransferOrderItemUpdateDto = c;
1216
+ function r(t) {
1217
+ const {
1218
+ poItem: n,
1219
+ nsItemSetting: i,
1220
+ nsUnitTypes: o,
1221
+ // overrideCost = true,
1222
+ customAttributes: m,
1223
+ nsLocationId: l
1224
+ } = t;
1225
+ return {
1226
+ ...s.ToNetSuite.toTransferOrderItemUpdateDto({
1227
+ poItem: n,
1228
+ nsItemSetting: i,
1229
+ nsUnitTypes: o,
1230
+ // overrideCost,
1231
+ customAttributes: m
1232
+ }),
1233
+ location: {
1234
+ id: l
1235
+ }
1236
+ };
1237
+ }
1238
+ g(r, "toPurchaseOrderItemUpdateDto"), a.toPurchaseOrderItemUpdateDto = r;
1239
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
1240
+ function u(r) {
1241
+ var E, y, _;
1242
+ const { nsOrderItem: t, sku: n, measurement: i, context: o, currency: m } = r, l = (_ = (y = (E = o == null ? void 0 : o.options) == null ? void 0 : E.purchaseOrderItem) == null ? void 0 : y.customAttributes) == null ? void 0 : _.reduce((S, v) => {
1243
+ const N = v.compute(r, v.extraParams);
1244
+ return {
1245
+ ...S,
1246
+ [v.fieldId]: N
1247
+ };
1248
+ }, {}), f = C.fromNumber(t.quantity), d = t.amount ? C.fromNumber(t.amount) : C.fromNumber(0), I = Oe.FCurrency.safeParse(m), p = I.success ? I.data : he;
1249
+ return {
1250
+ id: "",
1251
+ externalId: String(t.line),
1252
+ sku: n,
1253
+ code: n.code,
1254
+ name: n.name,
1255
+ quantity: {
1256
+ amount: f.amount,
1257
+ precision: f.precision
1258
+ },
1259
+ totalCost: {
1260
+ amount: d.amount,
1261
+ precision: d.precision,
1262
+ currency: p
1263
+ },
1264
+ measurement: i ?? null,
1265
+ ...l
1266
+ };
1267
+ }
1268
+ g(u, "toPurchaseOrderItem"), a.toPurchaseOrderItem = u;
1269
+ function c(r) {
1270
+ var _, S, v;
1271
+ const { nsOrderItem: t, sku: n, measurement: i, context: o, glImpactCost: m } = r, { cost: l, currency: f } = Xe(m, String(t.line), t.item.id), d = (v = (S = (_ = o == null ? void 0 : o.options) == null ? void 0 : _.purchaseOrderReceived) == null ? void 0 : S.customAttributes) == null ? void 0 : v.reduce((N, D) => {
1272
+ const b = D.compute(r);
1273
+ return {
1274
+ ...N,
1275
+ [D.fieldId]: b
1276
+ };
1277
+ }, {}), I = C.fromNumber(t.quantity), p = C.fromNumber(l), E = Oe.FCurrency.safeParse(f), y = E.success ? E.data : he;
1278
+ return {
1279
+ id: "",
1280
+ externalId: String(t.orderLine),
1281
+ sku: n,
1282
+ amount: {
1283
+ amount: I.amount,
1284
+ precision: I.precision
1285
+ },
1286
+ cost: {
1287
+ amount: p.amount,
1288
+ precision: p.precision,
1289
+ currency: y
1290
+ },
1291
+ measurement: i ?? null,
1292
+ ...d
1293
+ };
1294
+ }
1295
+ g(c, "toPurchaseOrderReceived"), a.toPurchaseOrderReceived = c;
1296
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
1297
+ })(te || (te = {}));
1298
+ var ft;
1299
+ (function(s) {
1300
+ (function(a) {
1301
+ function u(c) {
1302
+ var t;
1303
+ return {
1304
+ id: c.id,
1305
+ name: c.name,
1306
+ parentId: (t = c.parent) == null ? void 0 : t.id,
1307
+ country: c.country.refName,
1308
+ currency: c.currency.refName
1309
+ };
1310
+ }
1311
+ g(u, "transform"), a.transform = u;
1312
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
1313
+ })(ft || (ft = {}));
1314
+ var Ye;
1315
+ (function(s) {
1316
+ (function(a) {
1317
+ function u(c, r, t, n) {
1318
+ if (!t.every((m) => m.externalId))
1319
+ throw new Error("All purchase order items must have externalId");
1320
+ if (c !== ee.Enum[1] && !n.items.every((m) => m.id))
1321
+ throw new Error("All delivery fulfillment items must have id, if not v1");
1322
+ const i = n.items.reduce((m, l) => (c === ee.Enum[1] ? m[l.sku._id] = l : m[l.id] = l, m), {}), o = [];
1323
+ for (const m of t) {
1324
+ const l = Number(m.externalId), f = r.find((I) => I.line === l);
1325
+ if (!f)
1326
+ throw new Error(`Invalid line id ${m.externalId}`);
1327
+ let d;
1328
+ c === ee.Enum[1] ? d = i[m.sku._id] : d = i[m.id], d ? o.push({
1329
+ item: {
1330
+ id: f.item.id
1331
+ },
1332
+ itemReceive: !0,
1333
+ quantity: Number(C.toFormatString({
1334
+ value: d.amount
1335
+ })),
1336
+ orderLine: l + 1
1337
+ }) : o.push({
1338
+ item: {
1339
+ id: f.item.id
1340
+ },
1341
+ itemReceive: !1,
1342
+ orderLine: l + 1
1343
+ });
1344
+ }
1345
+ return {
1346
+ item: {
1347
+ items: o
1348
+ }
1349
+ };
1350
+ }
1351
+ g(u, "transformFromTransferOrder"), a.transformFromTransferOrder = u;
1352
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
1353
+ function u(c, r, t) {
1354
+ const n = t.item.items.map((o) => {
1355
+ const m = r[o.line].sku, l = r[o.line].measurement;
1356
+ return te.FromNetSuite.toPurchaseOrderReceived({
1357
+ context: c,
1358
+ glImpactCost: t.glImpacts ?? [],
1359
+ nsOrderItem: o,
1360
+ sku: m,
1361
+ measurement: l
1362
+ });
1363
+ });
1364
+ return {
1365
+ id: "",
1366
+ createdAt: new Date(t.createdDate).toISOString(),
1367
+ remark: t.memo,
1368
+ items: n,
1369
+ netSuite: {
1370
+ id: String(t.id),
1371
+ refNo: t.tranId
1372
+ }
1373
+ };
1374
+ }
1375
+ g(u, "transform"), a.transform = u;
1376
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
1377
+ })(Ye || (Ye = {}));
1378
+ function Le(s) {
1379
+ const a = s.getFullYear(), u = String(s.getMonth() + 1).padStart(2, "0"), c = String(s.getDate()).padStart(2, "0");
1380
+ return `${a}-${u}-${c}`;
1381
+ }
1382
+ g(Le, "formatDateYYYYMMDD");
1383
+ function J(s, a) {
1384
+ return s.getDate() === a.getDate() && s.getMonth() === a.getMonth() && s.getFullYear() === a.getFullYear();
1385
+ }
1386
+ g(J, "isSameDay");
1387
+ var Pe;
1388
+ (function(s) {
1389
+ (function(a) {
1390
+ function u(c, r, t, n, i) {
1391
+ const o = Le(new Date(n.effectiveAt ?? n.createdAt)), m = c.reduce((f, d) => (d.id && (f[d.id] = d), f), {}), l = n.received.map((f) => {
1392
+ var I;
1393
+ let d = f.id ? (I = m[f.id]) == null ? void 0 : I.externalId : void 0;
1394
+ if (d) {
1395
+ const p = Number(d);
1396
+ if (!!isNaN(p))
1397
+ throw new Error(`Invalid order line number: ${d} for item ID: ${f.id}`);
1398
+ d = (p + 2).toString();
1399
+ }
1400
+ return {
1401
+ orderLine: d,
1402
+ itemId: i[f.sku._id],
1403
+ quantity: Number(C.toFormatString({
1404
+ value: f.amount
1405
+ }))
1406
+ };
1407
+ });
1408
+ return {
1409
+ trandate: o,
1410
+ transferOrderId: r,
1411
+ itemFulfillmentId: t,
1412
+ items: l,
1413
+ fields: {
1414
+ custbody_fm_do_id: n.id || "",
1415
+ custbody_fm_created_by_id: n.createdBy.id,
1416
+ custbody_fm_created_by_name: n.createdBy.name
1417
+ }
1418
+ };
1419
+ }
1420
+ g(u, "toCreateDto"), a.toCreateDto = u;
1421
+ })(s.ToNetSuiteTransferOrder || (s.ToNetSuiteTransferOrder = {})), function(a) {
1422
+ function u(c, r, t, n) {
1423
+ const i = Le(new Date(t.effectiveAt ?? t.createdAt)), o = c.reduce((l, f) => (f.id && (l[f.id] = f), l), {}), m = t.received.map((l) => {
1424
+ var d;
1425
+ let f = l.id ? (d = o[l.id]) == null ? void 0 : d.externalId : void 0;
1426
+ if (f) {
1427
+ const I = Number(f);
1428
+ if (!!isNaN(I))
1429
+ throw new Error(`Invalid order line number: ${f} for item ID: ${l.id}`);
1430
+ f = I.toString();
1431
+ }
1432
+ return {
1433
+ orderLine: f,
1434
+ itemId: n[l.sku._id],
1435
+ quantity: Number(C.toFormatString({
1436
+ value: l.amount
1437
+ }))
1438
+ };
1439
+ });
1440
+ return {
1441
+ trandate: i,
1442
+ purchaseOrderId: r,
1443
+ items: m,
1444
+ fields: {
1445
+ custbody_fm_do_id: t.id || "",
1446
+ custbody_fm_created_by_id: t.createdBy.id,
1447
+ custbody_fm_created_by_name: t.createdBy.name
1448
+ }
1449
+ };
1450
+ }
1451
+ g(u, "toCreateDto"), a.toCreateDto = u;
1452
+ }(s.ToNetSuitePurchaseOrder || (s.ToNetSuitePurchaseOrder = {})), function(a) {
1453
+ function u(c, r, t) {
1454
+ var o;
1455
+ const n = t.item.items.map((m) => {
1456
+ const l = r[m.line].sku, f = r[m.line].measurement;
1457
+ return te.FromNetSuite.toPurchaseOrderReceived({
1458
+ context: c,
1459
+ glImpactCost: t.glImpacts ?? [],
1460
+ nsOrderItem: m,
1461
+ sku: l,
1462
+ measurement: f
1463
+ });
1464
+ }), i = new Date(t.tranDate);
1465
+ return {
1466
+ id: t.custbody_fm_do_id || "",
1467
+ createdAt: t.createdDate,
1468
+ effectiveAt: i.toISOString(),
1469
+ createdBy: {
1470
+ id: t.custbody_fm_created_by_id ?? "",
1471
+ name: t.custbody_fm_created_by_name ?? ""
1472
+ },
1473
+ deliveryOrderNumber: "",
1474
+ received: n,
1475
+ netSuite: {
1476
+ id: String(t.id),
1477
+ refNo: t.tranId
1478
+ },
1479
+ fullfillmentId: (o = t.itemFulfillment) == null ? void 0 : o.id
1480
+ };
1481
+ }
1482
+ g(u, "transform"), a.transform = u;
1483
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
1484
+ })(Pe || (Pe = {}));
1485
+ function Ct(s) {
1486
+ switch (w[s.id]) {
1487
+ case ue.enum.A:
1488
+ return j.Enum.REQUESTING;
1489
+ case ue.enum.B:
1490
+ case ue.enum.D:
1491
+ return j.Enum.PROCESSING;
1492
+ case ue.enum.C:
1493
+ return j.Enum.REJECT;
1494
+ case ue.enum.E:
1495
+ case ue.enum.F:
1496
+ return j.Enum.RECEIVING;
1497
+ case ue.enum.G:
1498
+ return j.Enum.COMPLETE;
1499
+ case ue.enum.H:
1500
+ return j.Enum.CLOSE;
1501
+ }
1502
+ throw new Error(`Invalid NetSuite Transfer Order status with ${s.id}`);
1503
+ }
1504
+ g(Ct, "validateTransferOrderStatusByKey");
1505
+ function At(s) {
1506
+ switch (De[s.id]) {
1507
+ case X.enum.A:
1508
+ return j.Enum.PROCESSING;
1509
+ case X.enum.C:
1510
+ return j.Enum.REJECT;
1511
+ case X.enum.B:
1512
+ case X.enum.D:
1513
+ case X.enum.E:
1514
+ return j.Enum.RECEIVING;
1515
+ case X.enum.F:
1516
+ case X.enum.G:
1517
+ return j.Enum.COMPLETE;
1518
+ case X.enum.H:
1519
+ return j.Enum.CLOSE;
1520
+ }
1521
+ throw new Error(`Invalid NetSuite Purchase Order status with ${s.id}`);
1522
+ }
1523
+ g(At, "validatePurchaseOrderStatusByKey");
1524
+ function xe(s) {
1525
+ const a = Object.keys(w).find((u) => w[u] === s);
1526
+ if (!a)
1527
+ throw new Error(`Invalid transfer order status value: ${s}`);
1528
+ return a;
1529
+ }
1530
+ g(xe, "getTransferOrderStatusEnumKeyByValue");
1531
+ function Ge(s) {
1532
+ const a = Object.keys(De).find((u) => De[u] === s);
1533
+ if (!a)
1534
+ throw new Error(`Invalid purchase order status value: ${s}`);
1535
+ return a;
1536
+ }
1537
+ g(Ge, "getPurchaseOrderStatusEnumKeyByValue");
1538
+ function Mt(s, a, u) {
1539
+ const c = u.filter((d) => d.field === "TRANDOC.KSTATUS"), r = [
1540
+ w.B,
1541
+ w.D,
1542
+ w.E,
1543
+ w.F,
1544
+ w.G
1545
+ ], t = [
1546
+ w.C
1547
+ ], n = Object.keys(w).filter((d) => r.includes(w[d])), i = Object.keys(w).filter((d) => t.includes(w[d])), o = c.find((d) => d.status === "Rejected"), m = c.find((d) => d.status === "Pending Fulfillment");
1548
+ let l = null, f = null;
1549
+ if (m ? l = new Date(m.datetime) : n.includes(a) && (l = new Date(s)), o ? f = new Date(o.datetime) : i.includes(a) && (f = new Date(s)), l && f)
1550
+ throw new Error("Both processedAt and rejectedAt are set.");
1551
+ return {
1552
+ processedAt: l ? l.toISOString() : null,
1553
+ rejectedAt: f ? f.toISOString() : null
1554
+ };
1555
+ }
1556
+ g(Mt, "getPurchaseOrderRequestStatusTimestamp");
1557
+ function Ut(s) {
1558
+ const a = s.shipDate;
1559
+ if (!a)
1560
+ return null;
1561
+ const u = /* @__PURE__ */ new Date();
1562
+ return {
1563
+ type: vt.Enum.PREPARING,
1564
+ description: "Expected Delivery Date (Synced from NetSuite)",
1565
+ createdAt: u.toISOString(),
1566
+ estimatedTime: new Date(a).toISOString()
1567
+ };
1568
+ }
1569
+ g(Ut, "transformTransferOrderPreparingShipmentMilestoneFromNetSuite");
1570
+ var It;
1571
+ (function(s) {
1572
+ (function(a) {
1573
+ function u({ setting: t, purchaseOrderRequest: n, status: i = ue.enum.A, overrideItemCost: o = !0, customItemAttributes: m, customFields: l }) {
1574
+ const { purchaseOrder: f } = n;
1575
+ if (!f)
1576
+ throw new Error("Purchase order request does not have a purchase order");
1577
+ if (n.netSuite.subsidiary === void 0)
1578
+ throw new Error("Purchase order request does not have a NetSuite subsidiary");
1579
+ const d = f.items.map((E) => {
1580
+ const y = t.items.find((_) => _.id === E.sku._id);
1581
+ return te.ToNetSuite.toCreateDto({
1582
+ poItem: E,
1583
+ nsUnitTypes: t.units,
1584
+ nsItemSetting: y,
1585
+ overrideCost: o,
1586
+ customAttributes: m
1587
+ });
1588
+ }), { netSuiteFromId: I, netSuiteToId: p } = Ft(t.locations, n);
1589
+ return {
1590
+ // spread user-supplied custom fields (typed as CF)
1591
+ ...l,
1592
+ location: {
1593
+ // from location
1594
+ id: I
1595
+ },
1596
+ transferLocation: {
1597
+ // to location
1598
+ id: p
1599
+ },
1600
+ subsidiary: {
1601
+ id: n.netSuite.subsidiary.id
1602
+ },
1603
+ item: {
1604
+ items: d
1605
+ },
1606
+ orderStatus: {
1607
+ id: xe(i)
1608
+ },
1609
+ custbody_fm_po_num: f.seqNumber,
1610
+ custbody_fm_po_request_id: n._id
1611
+ };
1612
+ }
1613
+ g(u, "toCreateDto"), a.toCreateDto = u;
1614
+ function c({ setting: t, purchaseOrder: n, overrideItemCost: i, customItemAttributes: o, includeItems: m = !1, orderStatus: l, customFields: f }) {
1615
+ const d = n.items.map((I) => {
1616
+ const p = t.items.find((E) => E.id === I.sku._id);
1617
+ return te.ToNetSuite.toTransferOrderItemUpdateDto({
1618
+ poItem: I,
1619
+ nsUnitTypes: t.units,
1620
+ nsItemSetting: p,
1621
+ overrideCost: i,
1622
+ customAttributes: o
1623
+ });
1624
+ });
1625
+ return {
1626
+ // spread user-supplied custom fields (typed as CF)
1627
+ ...f,
1628
+ orderStatus: l,
1629
+ item: m ? {
1630
+ items: d
1631
+ } : void 0,
1632
+ // trandate: formatDateYYYYMMDD(new Date(effectiveAt)),
1633
+ custbody_fm_po_num: n.seqNumber,
1634
+ custbody_fm_po_request_id: n.request.id
1635
+ };
1636
+ }
1637
+ g(c, "toUpdateDto"), a.toUpdateDto = c;
1638
+ function r(t) {
1639
+ return {
1640
+ item: {
1641
+ items: t.item.items.map((n) => ({
1642
+ line: n.line,
1643
+ isClosed: !0
1644
+ }))
1645
+ }
1646
+ };
1647
+ }
1648
+ g(r, "toCloseDto"), a.toCloseDto = r;
1649
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
1650
+ function u(r) {
1651
+ var $, be, ke, it, st, rt, ot, at, ut;
1652
+ const { fromLocation: t, toLocation: n, nsTransferOrder: i, orderItemMapping: o, nsItemFulfillments: m, orderItemMappingByFulfillment: l, nsItemReceipts: f, orderItemMappingByReceipt: d, context: I, nsSystemNotes: p } = r, E = {
1653
+ _id: t.doc._id,
1654
+ internal: t.type,
1655
+ contactName: t.doc.profile.name,
1656
+ name: t.doc.profile.name ?? "",
1657
+ email: t.doc.profile.email,
1658
+ phoneNumber: t.doc.profile.phoneNo,
1659
+ registrationNumber: t.doc.profile.regNo,
1660
+ address: {
1661
+ line1: (($ = t.doc.profile.address) == null ? void 0 : $.line1) || "",
1662
+ line2: (be = t.doc.profile.address) == null ? void 0 : be.line2,
1663
+ state: ((ke = t.doc.profile.address) == null ? void 0 : ke.state) || "",
1664
+ city: ((it = t.doc.profile.address) == null ? void 0 : it.city) || "",
1665
+ country: ((st = t.doc.profile.address) == null ? void 0 : st.country) || "",
1666
+ postcode: ((rt = t.doc.profile.address) == null ? void 0 : rt.postcode) || ""
1667
+ }
1668
+ }, y = (ut = (at = (ot = I.options) == null ? void 0 : ot.netSuite) == null ? void 0 : at.additionalInfo) == null ? void 0 : ut.reduce((P, Y) => {
1669
+ const fe = Y.compute(r, Y.extraParams);
1670
+ return {
1671
+ ...P,
1672
+ [Y.fieldId]: fe
1673
+ };
1674
+ }, {}), _ = {
1675
+ id: i.id,
1676
+ refNo: i.tranId,
1677
+ subsidiary: {
1678
+ id: i.subsidiary.id,
1679
+ name: i.subsidiary.refName
1680
+ },
1681
+ additionalInfo: {
1682
+ ...y
1683
+ }
1684
+ }, S = m.map((P) => {
1685
+ const Y = l[P.id];
1686
+ return Ye.FromNetSuite.transform(I, Y, P);
1687
+ }), v = f.map((P) => {
1688
+ const Y = d[P.id];
1689
+ return Pe.FromNetSuite.transform(I, Y, P);
1690
+ }), N = i.item.items.map((P) => {
1691
+ const Y = o[P.line].sku, fe = o[P.line].measurement;
1692
+ return te.FromNetSuite.toPurchaseOrderItem({
1693
+ currency: i.currency.refName,
1694
+ nsOrderItem: P,
1695
+ sku: Y,
1696
+ glImpactCost: [],
1697
+ measurement: fe,
1698
+ context: I
1699
+ });
1700
+ }), D = new Date(i.createdDate), [b, A, F] = i.tranDate.split("-"), k = new Date(Number(b), Number(A) - 1, Number(F)), U = Ut(i), B = {
1701
+ _id: R({
1702
+ prefix: O.Enum.purchaseOrder,
1703
+ dateTime: D.toISOString()
1704
+ }),
1705
+ version: "2",
1706
+ status: Ct(i.orderStatus),
1707
+ supplier: E,
1708
+ seqNumber: parseInt(i.custbody_fm_po_num ?? "0"),
1709
+ items: N,
1710
+ effectiveAt: k.toISOString(),
1711
+ deliveryFullfillment: S,
1712
+ deliveryOrder: v,
1713
+ // NetSuite
1714
+ netSuite: _,
1715
+ request: i.custbody_fm_po_request_id ? {
1716
+ id: i.custbody_fm_po_request_id,
1717
+ adjustmentIds: []
1718
+ } : void 0
1719
+ }, { processedAt: Ue, rejectedAt: Fe } = Mt(i.createdDate, i.orderStatus.id, p ?? []), _e = S.reduce((P, Y) => {
1720
+ const fe = new Date(Y.createdAt);
1721
+ return P ? fe.getTime() < P.getTime() ? fe : P : fe;
1722
+ }, null);
1723
+ return {
1724
+ purchaseOrderRequest: {
1725
+ _id: i.custbody_fm_po_request_id || "",
1726
+ from: {
1727
+ dbName: `${t.type}_${t.dbName}`,
1728
+ name: t.name
1729
+ },
1730
+ to: {
1731
+ dbName: `${n.type}_${n.dbName}`,
1732
+ name: n.name
1733
+ },
1734
+ purchaseOrderId: B._id,
1735
+ processedAt: Ue || (_e == null ? void 0 : _e.toISOString()) || null,
1736
+ rejectedAt: Fe,
1737
+ adjustmentIds: [],
1738
+ purchaseOrder: B,
1739
+ // NetSuite
1740
+ netSuite: _
1741
+ },
1742
+ purchaseOrder: B,
1743
+ deliveryMilestone: U
1744
+ };
1745
+ }
1746
+ g(u, "transform"), a.transform = u;
1747
+ function c() {
1748
+ }
1749
+ g(c, "convertToV1"), a.convertToV1 = c;
1750
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
1751
+ })(It || (It = {}));
1752
+ function Ft(s, a) {
1753
+ var r, t;
1754
+ const u = (r = s.find((n) => {
1755
+ const [i, o] = a.from.dbName.split("_");
1756
+ return n.id === o && n.type === i;
1757
+ })) == null ? void 0 : r.netSuiteId, c = (t = s.find((n) => {
1758
+ const [i, o] = a.to.dbName.split("_");
1759
+ return n.id === o && n.type === i;
1760
+ })) == null ? void 0 : t.netSuiteId;
1761
+ if (!u || !c || u === c)
1762
+ throw new Error("Invalid location");
1763
+ return {
1764
+ netSuiteFromId: u,
1765
+ netSuiteToId: c
1766
+ };
1767
+ }
1768
+ g(Ft, "locationMapper");
1769
+ function kt(s) {
1770
+ let a = null, u = !1, c = !1;
1771
+ for (const n of s.item.items) {
1772
+ const i = n.expectedReceiptDate;
1773
+ if (!i) {
1774
+ u = !0;
1775
+ continue;
1776
+ }
1777
+ if (c = !0, a === null) {
1778
+ a = i;
1779
+ continue;
1780
+ }
1781
+ if (i !== a)
1782
+ throw new Error("Inconsistent expected delivery dates found in purchase order items.");
1783
+ }
1784
+ if (u && c)
1785
+ throw new Error("Inconsistent expected delivery dates found in purchase order items.");
1786
+ if (!a)
1787
+ return null;
1788
+ const r = /* @__PURE__ */ new Date();
1789
+ return {
1790
+ type: vt.Enum.PREPARING,
1791
+ description: "Expected Delivery Date (Synced from NetSuite)",
1792
+ createdAt: r.toISOString(),
1793
+ estimatedTime: new Date(a).toISOString()
1794
+ };
1795
+ }
1796
+ g(kt, "transformPreparingShipmentMilestoneFromNetSuite");
1797
+ var pt;
1798
+ (function(s) {
1799
+ (function(a) {
1800
+ function u({ locationDb: t, setting: n, purchaseOrder: i, status: o = X.enum.A, overrideItemCost: m = !0, customItemAttributes: l, customFields: f }) {
1801
+ const { netSuiteFromId: d, netSuiteToId: I } = Je(n.locations, n.vendors, t, i.supplier._id), p = i.items.map((E) => {
1802
+ const y = n.items.find((_) => _.id === E.sku._id);
1803
+ return te.ToNetSuite.toCreateDto({
1804
+ poItem: E,
1805
+ nsUnitTypes: n.units,
1806
+ nsItemSetting: y,
1807
+ overrideCost: m,
1808
+ customAttributes: [
1809
+ {
1810
+ fieldId: "location",
1811
+ extraParams: I,
1812
+ compute: /* @__PURE__ */ g((_, S) => ({
1813
+ id: S
1814
+ }), "compute")
1815
+ },
1816
+ ...l || []
1817
+ ]
1818
+ });
1819
+ });
1820
+ return {
1821
+ // spread user-supplied custom fields (typed as CF)
1822
+ ...f,
1823
+ entity: {
1824
+ // from location
1825
+ id: d
1826
+ },
1827
+ location: {
1828
+ // to location
1829
+ id: I
1830
+ },
1831
+ subsidiary: {
1832
+ id: i.netSuite.subsidiary.id
1833
+ },
1834
+ item: {
1835
+ items: p
1836
+ },
1837
+ orderStatus: {
1838
+ id: Ge(o)
1839
+ },
1840
+ custbody_fm_po_num: i.seqNumber,
1841
+ custbody_fm_po_id: i._id
1842
+ };
1843
+ }
1844
+ g(u, "toCreateDto"), a.toCreateDto = u;
1845
+ function c({ locationDb: t, setting: n, purchaseOrder: i, overrideItemCost: o, customItemAttributes: m, includeItems: l = !1, customFields: f }) {
1846
+ const { netSuiteToId: d } = Je(n.locations, n.vendors, t, i.supplier._id);
1847
+ i != null && i.effectiveAt || ie(i._id);
1848
+ const I = i.items.map((p) => {
1849
+ const E = n.items.find((y) => y.id === p.sku._id);
1850
+ return te.ToNetSuite.toPurchaseOrderItemUpdateDto({
1851
+ nsLocationId: d,
1852
+ poItem: p,
1853
+ nsUnitTypes: n.units,
1854
+ nsItemSetting: E,
1855
+ overrideCost: o,
1856
+ customAttributes: m
1857
+ });
1858
+ });
1859
+ return {
1860
+ ...f,
1861
+ item: l ? {
1862
+ items: I
1863
+ } : void 0,
1864
+ // trandate: formatDateYYYYMMDD(new Date(effectiveAt)),
1865
+ custbody_fm_po_num: i.seqNumber,
1866
+ custbody_fm_po_id: i._id
1867
+ };
1868
+ }
1869
+ g(c, "toUpdateDto"), a.toUpdateDto = c;
1870
+ function r() {
1871
+ return {
1872
+ orderStatus: {
1873
+ id: Ge(X.enum.H)
1874
+ }
1875
+ };
1876
+ }
1877
+ g(r, "toCloseDto"), a.toCloseDto = r;
1878
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
1879
+ function u(c) {
1880
+ var b, A, F, k, U, B, Ue, Fe, _e;
1881
+ const { vendor: r, nsPurchaseOrder: t, orderItemMapping: n, nsItemReceipts: i, orderItemMappingByReceipt: o, context: m } = c, l = {
1882
+ _id: r._id,
1883
+ contactName: r.contactName,
1884
+ name: r.name ?? "",
1885
+ email: r.email,
1886
+ phoneNumber: r.phoneNumber,
1887
+ registrationNumber: r.registrationNumber,
1888
+ address: {
1889
+ line1: ((b = r.address) == null ? void 0 : b.line1) || "",
1890
+ line2: (A = r.address) == null ? void 0 : A.line2,
1891
+ state: ((F = r.address) == null ? void 0 : F.state) || "",
1892
+ city: ((k = r.address) == null ? void 0 : k.city) || "",
1893
+ country: ((U = r.address) == null ? void 0 : U.country) || "",
1894
+ postcode: ((B = r.address) == null ? void 0 : B.postcode) || ""
1895
+ }
1896
+ }, f = (_e = (Fe = (Ue = m.options) == null ? void 0 : Ue.netSuite) == null ? void 0 : Fe.additionalInfo) == null ? void 0 : _e.reduce((se, $) => {
1897
+ const be = $.compute(c, $.extraParams);
1898
+ return {
1899
+ ...se,
1900
+ [$.fieldId]: be
1901
+ };
1902
+ }, {}), d = {
1903
+ id: t.id,
1904
+ refNo: t.tranId,
1905
+ subsidiary: {
1906
+ id: t.subsidiary.id,
1907
+ name: t.subsidiary.refName
1908
+ },
1909
+ additionalInfo: {
1910
+ ...f
1911
+ }
1912
+ }, I = i.map((se) => {
1913
+ const $ = o[se.id];
1914
+ return Pe.FromNetSuite.transform(m, $, se);
1915
+ }), p = t.item.items.reduce((se, $) => {
1916
+ if ($.itemType.id === "Service")
1917
+ return console.log(`Skipping service type item with line ${$.line} in purchase order ${t.tranId}`), se;
1918
+ const be = n[$.line].sku, ke = n[$.line].measurement;
1919
+ return se.push(te.FromNetSuite.toPurchaseOrderItem({
1920
+ currency: t.currency.refName,
1921
+ nsOrderItem: $,
1922
+ sku: be,
1923
+ glImpactCost: [],
1924
+ measurement: ke,
1925
+ context: m
1926
+ })), se;
1927
+ }, []), E = new Date(t.createdDate), [y, _, S] = t.tranDate.split("-"), v = new Date(Number(y), Number(_) - 1, Number(S)), N = kt(t);
1928
+ return {
1929
+ purchaseOrder: {
1930
+ _id: R({
1931
+ prefix: O.Enum.purchaseOrder,
1932
+ dateTime: E.toISOString()
1933
+ }),
1934
+ version: "2",
1935
+ status: At(t.orderStatus),
1936
+ supplier: l,
1937
+ seqNumber: parseInt(`${t.custbody_fm_po_num ?? "0"}`),
1938
+ items: p,
1939
+ effectiveAt: v.toISOString(),
1940
+ deliveryOrder: I,
1941
+ // NetSuite
1942
+ netSuite: d
1943
+ },
1944
+ deliveryMilestone: N
1945
+ };
1946
+ }
1947
+ g(u, "transform"), a.transform = u;
1948
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
1949
+ })(pt || (pt = {}));
1950
+ function Je(s, a, u, c) {
1951
+ var n, i;
1952
+ const r = (n = a.find((o) => o.id === c)) == null ? void 0 : n.netSuiteId, t = (i = s.find((o) => {
1953
+ const [m, l] = u.split("_");
1954
+ return o.id === l && o.type === m;
1955
+ })) == null ? void 0 : i.netSuiteId;
1956
+ if (!r || !t || r === t)
1957
+ throw new Error("Invalid location");
1958
+ return {
1959
+ netSuiteFromId: r,
1960
+ netSuiteToId: t
1961
+ };
1962
+ }
1963
+ g(Je, "locationMapper");
1964
+ var ze;
1965
+ (function(s) {
1966
+ (function(a) {
1967
+ function u(c) {
1968
+ const t = {
1969
+ id: R({
1970
+ prefix: O.Enum.measurement
1971
+ }),
1972
+ name: c.unitName,
1973
+ abbrev: c.abbreviation,
1974
+ conversion: {
1975
+ amount: c.conversionRate,
1976
+ precision: 0
1977
+ }
1978
+ };
1979
+ return {
1980
+ ...t,
1981
+ nsConfig: {
1982
+ id: t.id,
1983
+ netSuiteId: String(c.internalId)
1984
+ }
1985
+ };
1986
+ }
1987
+ g(u, "transform"), a.transform = u;
1988
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
1989
+ })(ze || (ze = {}));
1990
+ var gt;
1991
+ (function(s) {
1992
+ (function(a) {
1993
+ function u(c, r) {
1994
+ let t = c.uom.items, n = R({
1995
+ prefix: O.Enum.unit
1996
+ });
1997
+ const i = {
1998
+ _id: n,
1999
+ name: c.name,
2000
+ abbrev: c.name,
2001
+ precision: (r == null ? void 0 : r.precision) ?? 0,
2002
+ measurements: []
2003
+ };
2004
+ let o;
2005
+ const m = [], l = [];
2006
+ for (const d of t) {
2007
+ if (d.baseUnit == !0) {
2008
+ i.name = `${c.name} (${d.unitName})`, i.abbrev = d.abbreviation, o = String(d.internalId);
2009
+ continue;
2010
+ }
2011
+ const I = ze.FromNetsuite.transform(d);
2012
+ l.push(I), m.push(I.nsConfig);
2013
+ }
2014
+ if (i.measurements = l, o === void 0)
2015
+ throw new Error("Base unit not found");
2016
+ const f = {
2017
+ id: n,
2018
+ netSuiteId: String(c.id),
2019
+ baseUnitUnitOfMeasureId: o,
2020
+ measurements: m
2021
+ };
2022
+ return {
2023
+ ...i,
2024
+ nsConfig: f,
2025
+ measurements: l
2026
+ };
2027
+ }
2028
+ g(u, "transform"), a.transform = u;
2029
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
2030
+ })(gt || (gt = {}));
2031
+ function Tn(s, a) {
2032
+ let u;
2033
+ const c = [];
2034
+ for (const r of a.measurements) {
2035
+ const t = s.measurements.find((n) => n.id === r.id);
2036
+ t && c.push({
2037
+ ...r,
2038
+ nsConfig: t
2039
+ });
2040
+ }
2041
+ return u = {
2042
+ ...a,
2043
+ nsConfig: s,
2044
+ measurements: c
2045
+ }, u;
2046
+ }
2047
+ g(Tn, "convertToUnitWithNsConfig");
2048
+ var Et;
2049
+ (function(s) {
2050
+ (function(a) {
2051
+ function u(c) {
2052
+ const r = c.addressBook.items.find((o) => o.defaultBilling), t = R({
2053
+ prefix: O.Enum.supplier
2054
+ }), n = {
2055
+ _id: t,
2056
+ name: c.companyName,
2057
+ email: c.email,
2058
+ contactName: (r == null ? void 0 : r.addressBookAddress.attention) || (r == null ? void 0 : r.addressBookAddress.addressee),
2059
+ phoneNumber: c.phone,
2060
+ registrationNumber: "",
2061
+ address: wt(r)
2062
+ }, i = {
2063
+ id: t,
2064
+ netSuiteId: c.id,
2065
+ name: c.companyName,
2066
+ subsidiaryId: c.subsidiary.id
2067
+ };
2068
+ return {
2069
+ ...n,
2070
+ nsConfig: i
2071
+ };
2072
+ }
2073
+ g(u, "transform"), a.transform = u;
2074
+ })(s.FromNetsuite || (s.FromNetsuite = {}));
2075
+ })(Et || (Et = {}));
2076
+ function wt(s) {
2077
+ let a = {
2078
+ line1: "",
2079
+ state: "",
2080
+ city: "",
2081
+ postcode: "",
2082
+ country: ""
2083
+ };
2084
+ return s && (a = {
2085
+ ...a,
2086
+ line1: s.addressBookAddress.addr1 ?? "",
2087
+ line2: s.addressBookAddress.addr2,
2088
+ state: s.addressBookAddress.state ?? "",
2089
+ city: s.addressBookAddress.city ?? "",
2090
+ postcode: s.addressBookAddress.zip ?? "",
2091
+ country: s.addressBookAddress.country.refName
2092
+ }), a;
2093
+ }
2094
+ g(wt, "_transfromToSupplierAddress");
2095
+ function et(s, a) {
2096
+ const u = {}, c = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
2097
+ for (const n of a) {
2098
+ let { externalId: i, id: o } = n;
2099
+ if (i) {
2100
+ if (c.has(i))
2101
+ throw new Error(`Duplicate externalId found in poItems: ${i}`);
2102
+ if (c.add(i), !o || r.has(o)) {
2103
+ if (o || console.warn(`Missing id found in poItems for externalId: ${i}, generating a new id.`), o && r.has(o)) {
2104
+ let m;
2105
+ Object.entries(u).forEach(([l, f]) => {
2106
+ f === o && (m = l);
2107
+ }), console.warn(`Duplicate id for both externalIds: ${i} and ${m}, generating a new id.`);
2108
+ }
2109
+ o = crypto.randomUUID();
2110
+ }
2111
+ r.add(o), u[i] = o;
2112
+ }
2113
+ }
2114
+ const t = {};
2115
+ for (const n of s) {
2116
+ const i = n.transferorderitemlineid || n.lineid, o = u[i];
2117
+ o && (t[n.lineid] = o);
2118
+ }
2119
+ return t;
2120
+ }
2121
+ g(et, "mapOrderLineId");
2122
+ function hn(s, a, u, c, r) {
2123
+ var l, f;
2124
+ const t = u.some((d) => d.id), n = et(a, u), i = [], o = c, m = [
2125
+ ...r || []
2126
+ ];
2127
+ for (const d of u) {
2128
+ const I = t && d.externalId ? n[d.externalId] : "";
2129
+ i.push({
2130
+ ...d,
2131
+ id: I
2132
+ });
2133
+ }
2134
+ for (let d = 0; d < o.length; d++) {
2135
+ const I = o[d], p = [];
2136
+ for (const E of I.received) {
2137
+ const y = E.externalId;
2138
+ if (!y) {
2139
+ p.push(E);
2140
+ continue;
2141
+ }
2142
+ const _ = (l = a.find((N) => N.lineid === y)) == null ? void 0 : l.transferorderitemlineid, S = t && _ ? n[_] : void 0, v = {
2143
+ ...E,
2144
+ id: S
2145
+ };
2146
+ if (s === ee.Enum[2] && (!S || S === ""))
2147
+ throw new Error(`Cannot find mapped item ID for external line id ${y} in delivery order`);
2148
+ p.push(v);
2149
+ }
2150
+ o[d] = {
2151
+ ...I,
2152
+ received: p
2153
+ };
2154
+ }
2155
+ if (m)
2156
+ for (let d = 0; d < m.length; d++) {
2157
+ const I = m[d], p = [];
2158
+ for (const E of I.items) {
2159
+ const y = E.externalId;
2160
+ if (!y) {
2161
+ p.push(E);
2162
+ continue;
2163
+ }
2164
+ const _ = (f = a.find((N) => N.lineid === y)) == null ? void 0 : f.transferorderitemlineid, S = t && _ ? n[_] : E.id, v = {
2165
+ ...E,
2166
+ id: S
2167
+ };
2168
+ if (s === ee.Enum[2] && (!S || S === ""))
2169
+ throw new Error(`Cannot find mapped item ID for order external id ${y} in delivery fulfillment`);
2170
+ p.push(v);
2171
+ }
2172
+ m[d] = {
2173
+ ...I,
2174
+ items: p
2175
+ };
2176
+ }
2177
+ return {
2178
+ alignedPOItems: i,
2179
+ alignedDeliveryOrders: o,
2180
+ alignedDeliveryFulfillments: m
2181
+ };
2182
+ }
2183
+ g(hn, "alignItemLineIdsAcrossDocuments");
2184
+ function Dn(s, a, u) {
2185
+ const c = a.some((i) => i.id), r = et(s, a), t = [], n = u;
2186
+ for (const i of a) {
2187
+ const o = c && i.externalId ? r[i.externalId] : "";
2188
+ t.push({
2189
+ ...i,
2190
+ id: o
2191
+ });
2192
+ }
2193
+ for (let i = 0; i < n.length; i++) {
2194
+ const o = n[i], m = [];
2195
+ for (const l of o.received) {
2196
+ const f = l.externalId, d = a.find((I) => I.externalId === f).id;
2197
+ m.push({
2198
+ ...l,
2199
+ id: d
2200
+ });
2201
+ }
2202
+ n[i] = {
2203
+ ...o,
2204
+ received: m
2205
+ };
2206
+ }
2207
+ return {
2208
+ alignedPOItems: t,
2209
+ alignedDeliveryOrders: n
2210
+ };
2211
+ }
2212
+ g(Dn, "alignInventoryTransferItemLineIds");
2213
+ var Ie;
2214
+ (function(s) {
2215
+ (function(a) {
2216
+ function u(c) {
2217
+ const { orderItem: r, nsUnitTypes: t, nsItemSetting: n } = c;
2218
+ let i;
2219
+ if (r.measurement) {
2220
+ const o = r.measurement.id;
2221
+ for (const m of t)
2222
+ for (const l of (m == null ? void 0 : m.measurements) || [])
2223
+ if (l.id === o) {
2224
+ i = l.netSuiteId;
2225
+ break;
2226
+ }
2227
+ } else
2228
+ i = t.find((o) => o.id == r.sku.unit._id).baseUnitUnitOfMeasureId;
2229
+ return {
2230
+ item: {
2231
+ id: n.netSuiteId
2232
+ },
2233
+ adjustQtyBy: Number(C.toFormatString({
2234
+ value: r.quantity
2235
+ })),
2236
+ units: i
2237
+ };
2238
+ }
2239
+ g(u, "toCreateDto"), a.toCreateDto = u;
2240
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
2241
+ function u(r, t, n, i) {
2242
+ const { cost: o, currency: m } = Xe(t, String(r.line), r.item.id), l = C.fromNumber(r.adjustQtyBy), f = C.fromNumber(o), d = Oe.FCurrency.safeParse(m), I = d.success ? d.data : he;
2243
+ return {
2244
+ id: "",
2245
+ externalId: String(r.line),
2246
+ sku: n,
2247
+ amount: {
2248
+ amount: l.amount,
2249
+ precision: l.precision
2250
+ },
2251
+ cost: {
2252
+ amount: f.amount,
2253
+ precision: f.precision,
2254
+ currency: I
2255
+ },
2256
+ measurement: i ?? null
2257
+ };
2258
+ }
2259
+ g(u, "toPurchaseOrderReceived"), a.toPurchaseOrderReceived = u;
2260
+ function c(r, t, n) {
2261
+ const i = C.fromNumber(r.adjustQtyBy), o = C.fromNumber(0);
2262
+ return {
2263
+ id: "",
2264
+ externalId: String(r.line),
2265
+ sku: t,
2266
+ code: t.code,
2267
+ name: t.name,
2268
+ quantity: {
2269
+ amount: i.amount,
2270
+ precision: i.precision
2271
+ },
2272
+ totalCost: {
2273
+ amount: o.amount,
2274
+ precision: o.precision,
2275
+ currency: "MYR"
2276
+ },
2277
+ measurement: n ?? null
2278
+ };
2279
+ }
2280
+ g(c, "toPurchaseOrderItem"), a.toPurchaseOrderItem = c;
2281
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
2282
+ })(Ie || (Ie = {}));
2283
+ var yt;
2284
+ (function(s) {
2285
+ (function(a) {
2286
+ function u(r) {
2287
+ const { setting: t, sourceLocationId: n, destinationLocationId: i, subsidiaryId: o, effectiveAt: m, orderItems: l, newAdjustmentId: f } = r, d = l.map((I) => {
2288
+ const p = t.items.find((E) => E.id === I.sku._id);
2289
+ return Ie.ToNetSuite.toCreateDto({
2290
+ orderItem: I,
2291
+ nsUnitTypes: t.units,
2292
+ nsItemSetting: p
2293
+ });
2294
+ });
2295
+ return {
2296
+ location: {
2297
+ id: n
2298
+ },
2299
+ transferLocation: {
2300
+ id: i
2301
+ },
2302
+ subsidiary: {
2303
+ id: o
2304
+ },
2305
+ inventory: {
2306
+ items: d
2307
+ },
2308
+ tranDate: Le(new Date(m)),
2309
+ custbody_fm_adjustment_id: f
2310
+ };
2311
+ }
2312
+ g(u, "toCreateDto"), a.toCreateDto = u;
2313
+ function c(r, t) {
2314
+ return {
2315
+ custbody_fm_po_id: r._id,
2316
+ custbody_fm_po_num: r.seqNumber,
2317
+ custbody_fm_po_request_id: t == null ? void 0 : t._id
2318
+ };
2319
+ }
2320
+ g(c, "toUpdateDto"), a.toUpdateDto = c;
2321
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
2322
+ function u(r) {
2323
+ const { nsInventoryTransfer: t, transferItemMapping: n } = r, i = new Date(t.createdDate), [o, m, l] = t.tranDate.split("-"), f = new Date(Number(o), Number(m) - 1, Number(l)), d = {
2324
+ _id: "",
2325
+ name: t.location.refName,
2326
+ internal: Kt.Enum.restaurant,
2327
+ address: {
2328
+ line1: "",
2329
+ state: "",
2330
+ city: "",
2331
+ country: "",
2332
+ postcode: ""
2333
+ }
2334
+ }, I = {
2335
+ id: t.id,
2336
+ refNo: t.tranId,
2337
+ recordType: Be.Enum.inventoryTransfer
2338
+ }, E = {
2339
+ received: t.inventory.items.map((S) => {
2340
+ const v = n[S.line].sku, N = n[S.line].measurement;
2341
+ return Ie.FromNetSuite.toPurchaseOrderReceived(S, t.glImpacts ?? [], v, N);
2342
+ }),
2343
+ createdBy: {
2344
+ name: "",
2345
+ id: ""
2346
+ },
2347
+ createdAt: i.toISOString(),
2348
+ deliveryOrderNumber: "",
2349
+ netSuite: I,
2350
+ effectiveAt: f.toISOString()
2351
+ }, y = t.inventory.items.map((S) => {
2352
+ const v = n[S.line].sku, N = n[S.line].measurement;
2353
+ return Ie.FromNetSuite.toPurchaseOrderItem(S, v, N);
2354
+ });
2355
+ return {
2356
+ _id: R({
2357
+ prefix: O.Enum.purchaseOrder,
2358
+ dateTime: i.toISOString()
2359
+ }),
2360
+ version: "2",
2361
+ effectiveAt: f.toISOString(),
2362
+ status: j.Enum.COMPLETE,
2363
+ supplier: d,
2364
+ seqNumber: t.custbody_fm_po_num ?? 0,
2365
+ items: y,
2366
+ deliveryOrder: [
2367
+ E
2368
+ ],
2369
+ request: t.custbody_fm_po_request_id ? {
2370
+ id: t.custbody_fm_po_request_id,
2371
+ adjustmentIds: []
2372
+ } : void 0,
2373
+ netSuite: I
2374
+ };
2375
+ }
2376
+ g(u, "transformTransferIn"), a.transformTransferIn = u;
2377
+ function c(r) {
2378
+ var v, N, D, b, A, F;
2379
+ const { sourceLocation: t, nsInventoryTransfer: n, transferItemMapping: i } = r, o = new Date(n.createdDate), [m, l, f] = n.tranDate.split("-"), d = new Date(Number(m), Number(l) - 1, Number(f)), I = {
2380
+ _id: t.doc._id,
2381
+ internal: t.type,
2382
+ contactName: t.doc.profile.name,
2383
+ name: t.doc.profile.name ?? "",
2384
+ email: t.doc.profile.email,
2385
+ phoneNumber: t.doc.profile.phoneNo,
2386
+ registrationNumber: t.doc.profile.regNo,
2387
+ address: {
2388
+ line1: ((v = t.doc.profile.address) == null ? void 0 : v.line1) || "",
2389
+ line2: (N = t.doc.profile.address) == null ? void 0 : N.line2,
2390
+ state: ((D = t.doc.profile.address) == null ? void 0 : D.state) || "",
2391
+ city: ((b = t.doc.profile.address) == null ? void 0 : b.city) || "",
2392
+ country: ((A = t.doc.profile.address) == null ? void 0 : A.country) || "",
2393
+ postcode: ((F = t.doc.profile.address) == null ? void 0 : F.postcode) || ""
2394
+ }
2395
+ }, p = {
2396
+ id: n.id,
2397
+ refNo: n.tranId,
2398
+ recordType: Be.Enum.inventoryTransfer,
2399
+ subsidiary: {
2400
+ id: n.subsidiary.id,
2401
+ name: n.subsidiary.refName
2402
+ }
2403
+ }, y = {
2404
+ received: n.inventory.items.map((k) => {
2405
+ const U = i[k.line].sku, B = i[k.line].measurement;
2406
+ return Ie.FromNetSuite.toPurchaseOrderReceived(k, n.glImpacts ?? [], U, B);
2407
+ }),
2408
+ createdBy: {
2409
+ name: "",
2410
+ id: ""
2411
+ },
2412
+ createdAt: o.toISOString(),
2413
+ deliveryOrderNumber: "",
2414
+ netSuite: p,
2415
+ effectiveAt: d.toISOString()
2416
+ }, _ = n.inventory.items.map((k) => {
2417
+ const U = i[k.line].sku, B = i[k.line].measurement;
2418
+ return Ie.FromNetSuite.toPurchaseOrderItem(k, U, B);
2419
+ });
2420
+ return {
2421
+ _id: R({
2422
+ prefix: O.Enum.purchaseOrder,
2423
+ dateTime: o.toISOString()
2424
+ }),
2425
+ version: "2",
2426
+ effectiveAt: d.toISOString(),
2427
+ status: j.Enum.COMPLETE,
2428
+ supplier: I,
2429
+ seqNumber: n.custbody_fm_po_num ?? 0,
2430
+ items: _,
2431
+ deliveryOrder: [
2432
+ y
2433
+ ],
2434
+ request: n.custbody_fm_po_request_id ? {
2435
+ id: n.custbody_fm_po_request_id,
2436
+ adjustmentIds: []
2437
+ } : void 0,
2438
+ netSuite: p
2439
+ };
2440
+ }
2441
+ g(c, "transformTransferOut"), a.transformTransferOut = c;
2442
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
2443
+ })(yt || (yt = {}));
2444
+ function pe(s, a, u, c) {
2445
+ const r = {};
2446
+ return c.forEach((t) => {
2447
+ "itemType" in t && t.itemType.id === "Service" || (r[t.line] = Rt(s, a, u, t.item.id, t.units));
2448
+ }), r;
2449
+ }
2450
+ g(pe, "validateOrderItems");
2451
+ function Rt(s, a, u, c, r) {
2452
+ const t = u.items.find((f) => f.netSuiteId === c);
2453
+ if (!t)
2454
+ throw new Error(`SKU with ID ${c} not found in settings`);
2455
+ const n = s.find((f) => f._id === t.id);
2456
+ if (!n)
2457
+ throw new Error(`SKU with ID ${t.id} not matched`);
2458
+ const i = u.units.find((f) => f.netSuiteId === t.unitTypeId);
2459
+ if (!i)
2460
+ throw new Error(`Unit with ID ${t.unitTypeId} not found in settings`);
2461
+ const o = r == (i == null ? void 0 : i.baseUnitUnitOfMeasureId), m = a.find((f) => f._id === i.id);
2462
+ if (!m)
2463
+ throw new Error(`Unit with ID ${t.unitTypeId} not matched`);
2464
+ let l;
2465
+ if (!o) {
2466
+ const f = i.measurements.find((d) => d.netSuiteId === r);
2467
+ if (!f)
2468
+ throw new Error(`Measurement with ID ${r} not found in unit "${i == null ? void 0 : i.id}"`);
2469
+ if (l = m.measurements.find((d) => d.id === f.id), !l)
2470
+ throw new Error(`Measurement with ID ${f.id} not found in SKU ${n._id}`);
2471
+ }
2472
+ return {
2473
+ sku: n,
2474
+ measurement: l
2475
+ };
2476
+ }
2477
+ g(Rt, "validateNetSuiteOrderItem");
2478
+ function Nn(s, a) {
2479
+ const u = s.items.reduce((c, r) => {
2480
+ const { id: t, quantity: n } = r;
2481
+ return c[t] || (c[t] = C.fromNumber(0)), c[t] = C.add([
2482
+ c[t],
2483
+ n
2484
+ ]), c;
2485
+ }, {});
2486
+ for (const c of a) {
2487
+ const r = c.received;
2488
+ for (const t of r)
2489
+ u[t.id] = C.subtract([
2490
+ u[t.id],
2491
+ t.amount
2492
+ ]);
2493
+ }
2494
+ return Object.entries(u).reduce((c, [r, t]) => (C.smallerThan({
2495
+ a: t,
2496
+ b: C.fromNumber(0)
2497
+ }) && (c[r] = t), c), {});
2498
+ }
2499
+ g(Nn, "validatePurchaseOrderOverReceive");
2500
+ function Cn(s, a) {
2501
+ const u = s.items.reduce((c, r) => {
2502
+ const { id: t, amount: n } = r;
2503
+ return c[t] || (c[t] = C.fromNumber(0)), c[t] = C.add([
2504
+ c[t],
2505
+ n
2506
+ ]), c;
2507
+ }, {});
2508
+ for (const c of a) {
2509
+ const r = c.received;
2510
+ for (const t of r)
2511
+ u[t.id] = C.subtract([
2512
+ u[t.id],
2513
+ t.amount
2514
+ ]);
2515
+ }
2516
+ return Object.entries(u).reduce((c, [r, t]) => (C.smallerThan({
2517
+ a: t,
2518
+ b: C.fromNumber(0)
2519
+ }) && (c[r] = t), c), {});
2520
+ }
2521
+ g(Cn, "validateItemFulfillmentOverReceive");
2522
+ var _t;
2523
+ (function(s) {
2524
+ (function(a) {
2525
+ function u(r, t) {
2526
+ var n, i;
2527
+ if (t)
2528
+ throw new Error("NetSuite Transfer Order already exists");
2529
+ if ((i = (n = r.netSuite) == null ? void 0 : n.subsidiary) != null && i.id)
2530
+ throw new Error("NetSuite subsidiary ID is required");
2531
+ }
2532
+ g(u, "validateCreate"), a.validateCreate = u;
2533
+ function c(r) {
2534
+ const { orderStatus: t, processedAt: n, rejectedAt: i } = r;
2535
+ if (!t || !t.id)
2536
+ throw new Error("Missing transfer order status");
2537
+ if (n && i)
2538
+ throw new Error("Transfer Order cannot be both approved and rejected at the same time");
2539
+ const o = xe(w.A);
2540
+ return t.id === o && n ? {
2541
+ id: xe(w.B)
2542
+ } : t;
2543
+ }
2544
+ g(c, "validateApprovalStatus"), a.validateApprovalStatus = c;
2545
+ })(s.ToNetSuite || (s.ToNetSuite = {})), function(a) {
2546
+ function u(c, r, t, n) {
2547
+ const i = c.every((l) => l.isClosed);
2548
+ let o = {
2549
+ ...r
2550
+ };
2551
+ const m = {};
2552
+ if (i) {
2553
+ m[t] = [];
2554
+ for (const l of o.deliveryFullfillment ?? [])
2555
+ l.adjustment && m[t].push(l.adjustment);
2556
+ m[n] = [];
2557
+ for (const l of o.deliveryOrder)
2558
+ l.adjustment && m[n].push(l.adjustment);
2559
+ o = {
2560
+ ...o,
2561
+ deliveryFullfillment: [],
2562
+ deliveryOrder: []
2563
+ };
2564
+ }
2565
+ return {
2566
+ isOrderVoided: i,
2567
+ purchaseOrder: o,
2568
+ adjustmentGoingToDeleteMap: m
2569
+ };
2570
+ }
2571
+ g(u, "isVoided"), a.isVoided = u;
2572
+ }(s.FromNetSuite || (s.FromNetSuite = {}));
2573
+ })(_t || (_t = {}));
2574
+ function An(s, a) {
2575
+ const u = s.reduce((r, t) => (r[t.line] = (r[t.line] || 0) + t.quantity, r), {}), c = [];
2576
+ for (const r of a) {
2577
+ const t = r.line, n = u[t] ?? 0;
2578
+ if (r.quantity !== n) {
2579
+ if (n > r.quantity) {
2580
+ console.warn(`Quantity fulfilled (${n}) is greater than order item (${r.quantity}) for line ${t}`);
2581
+ continue;
2582
+ }
2583
+ c.push(r);
2584
+ }
2585
+ }
2586
+ return c;
2587
+ }
2588
+ g(An, "getAvailableItemToBeFulfilled");
2589
+ function Mn(s) {
2590
+ var l, f;
2591
+ const { inventorySkus: a, legacyParentItemConfigs: u, parentReplicas: c } = s, r = u.reduce((d, I) => (d[I.id] = I, d), {}), t = c.reduce((d, I) => (d[I.netSuiteId] = I, d), {}), n = /* @__PURE__ */ new Set(), i = [];
2592
+ for (const d of a) {
2593
+ let I = d;
2594
+ try {
2595
+ const p = r[d._id];
2596
+ if (!p)
2597
+ throw new Error(`Missing NetSuite assembly item config for SKU with ID ${d._id}`);
2598
+ const E = t[p.netSuiteId];
2599
+ if (!E)
2600
+ throw new Error(`Missing replica for NetSuite ID ${p.netSuiteId} for SKU with ID ${d._id}`);
2601
+ if (!E.skuCache)
2602
+ throw new Error(`Replica for NetSuite ID ${p.netSuiteId} is missing skuCache. Expected parent item replica.`);
2603
+ if (E.itemType !== V.Enum.Assembly)
2604
+ throw new Error(`Replica for NetSuite ID ${p.netSuiteId} has itemType '${E.itemType}'. Expected 'Assembly'.`);
2605
+ if (E.skuCache._id !== d._id)
2606
+ throw new Error(`SKU ID mismatch: expected replica skuCache._id to be '${d._id}', but got '${E.skuCache._id}'`);
2607
+ I = {
2608
+ ...E.skuCache,
2609
+ customAttributes: d.customAttributes
2610
+ };
2611
+ } catch (p) {
2612
+ console.log("Error merging SKU:", p);
2613
+ }
2614
+ i.push(I), n.add(I._id);
2615
+ }
2616
+ for (const d of c)
2617
+ !d.skuCache || n.has(d.skuCache._id) || (i.push({
2618
+ ...d.skuCache
2619
+ }), n.add(d.skuCache._id));
2620
+ const o = [], m = /* @__PURE__ */ new Set();
2621
+ for (const d of c)
2622
+ d.skuCache && (m.add(d.skuCache._id), o.push({
2623
+ id: d.skuCache._id,
2624
+ name: d.name,
2625
+ netSuiteId: d.netSuiteId,
2626
+ unitTypeId: d.unitTypeId,
2627
+ unitOfMeasureId: d.unitOfMeasureId,
2628
+ subsidiaryIds: d.subsidiaryIds,
2629
+ includeChildren: d.includeChildren,
2630
+ cogsAccount: d.cogsAccount,
2631
+ itemType: d.itemType,
2632
+ externalId: d.externalId,
2633
+ pktCode: (l = d.customFields) == null ? void 0 : l.pktCode,
2634
+ pktName: (f = d.customFields) == null ? void 0 : f.pktName
2635
+ }));
2636
+ for (const d of u)
2637
+ d.itemType !== V.Enum.Assembly && !m.has(d.id) && o.push(d);
2638
+ return {
2639
+ updatedInventorySkus: i,
2640
+ updatedParentItemConfigs: o
2641
+ };
2642
+ }
2643
+ g(Mn, "syncAssemblyParentItemsWithLegacyConfig");
2644
+ function Un(s) {
2645
+ var t, n;
2646
+ const { legacyChildItemConfigs: a, childReplicas: u } = s, c = [], r = /* @__PURE__ */ new Set();
2647
+ for (const i of u)
2648
+ r.add(i.netSuiteId), c.push({
2649
+ name: i.name,
2650
+ netSuiteId: i.netSuiteId,
2651
+ parentNetSuiteId: i.parentNetSuiteId,
2652
+ unitTypeId: i.unitTypeId,
2653
+ unitOfMeasureId: i.unitOfMeasureId,
2654
+ subsidiaryIds: i.subsidiaryIds,
2655
+ includeChildren: i.includeChildren,
2656
+ cogsAccount: i.cogsAccount,
2657
+ itemType: i.itemType,
2658
+ externalId: i.externalId,
2659
+ pktCode: (t = i.customFields) == null ? void 0 : t.pktCode,
2660
+ pktName: (n = i.customFields) == null ? void 0 : n.pktName
2661
+ });
2662
+ for (const i of a)
2663
+ i.itemType !== V.Enum.Assembly && !r.has(i.netSuiteId) && c.push(i);
2664
+ return c;
2665
+ }
2666
+ g(Un, "syncAssemblyChildItemsWithLegacyConfig");
2667
+ function Fn(s) {
2668
+ var l, f;
2669
+ const { inventorySkus: a, legacyParentItemConfigs: u, parentReplicas: c } = s, r = u.reduce((d, I) => (d[I.id] = I, d), {}), t = c.reduce((d, I) => (d[I.netSuiteId] = I, d), {}), n = /* @__PURE__ */ new Set(), i = [];
2670
+ for (const d of a) {
2671
+ let I = d;
2672
+ try {
2673
+ const p = r[d._id];
2674
+ if (!p)
2675
+ throw new Error(`Missing NetSuite inventory item config for SKU with ID ${d._id}`);
2676
+ const E = t[p.netSuiteId];
2677
+ if (!E)
2678
+ throw new Error(`Missing replica for NetSuite ID ${p.netSuiteId} for SKU with ID ${d._id}`);
2679
+ if (!E.skuCache)
2680
+ throw new Error(`Replica for NetSuite ID ${p.netSuiteId} is missing skuCache. Expected parent item replica.`);
2681
+ if (E.itemType !== V.Enum.InvtPart)
2682
+ throw new Error(`Replica for NetSuite ID ${p.netSuiteId} has itemType '${E.itemType}'. Expected 'InvtPart'.`);
2683
+ if (E.skuCache._id !== d._id)
2684
+ throw new Error(`SKU ID mismatch: expected replica skuCache._id to be '${d._id}', but got '${E.skuCache._id}'`);
2685
+ I = {
2686
+ ...E.skuCache,
2687
+ customAttributes: d.customAttributes
2688
+ };
2689
+ } catch (p) {
2690
+ console.log("Error merging SKU:", p);
2691
+ }
2692
+ i.push(I), n.add(I._id);
2693
+ }
2694
+ for (const d of c)
2695
+ !d.skuCache || n.has(d.skuCache._id) || (i.push({
2696
+ ...d.skuCache
2697
+ }), n.add(d.skuCache._id));
2698
+ const o = [], m = /* @__PURE__ */ new Set();
2699
+ for (const d of c)
2700
+ d.skuCache && (m.add(d.skuCache._id), o.push({
2701
+ id: d.skuCache._id,
2702
+ name: d.name,
2703
+ netSuiteId: d.netSuiteId,
2704
+ unitTypeId: d.unitTypeId,
2705
+ unitOfMeasureId: d.unitOfMeasureId,
2706
+ subsidiaryIds: d.subsidiaryIds,
2707
+ includeChildren: d.includeChildren,
2708
+ cogsAccount: d.cogsAccount,
2709
+ itemType: d.itemType,
2710
+ externalId: d.externalId,
2711
+ pktCode: (l = d.customFields) == null ? void 0 : l.pktCode,
2712
+ pktName: (f = d.customFields) == null ? void 0 : f.pktName
2713
+ }));
2714
+ for (const d of u)
2715
+ d.itemType !== V.Enum.InvtPart && !m.has(d.id) && o.push(d);
2716
+ return {
2717
+ updatedInventorySkus: i,
2718
+ updatedParentItemConfigs: o
2719
+ };
2720
+ }
2721
+ g(Fn, "syncInventoryParentItemsWithLegacyConfig");
2722
+ function kn(s) {
2723
+ var t, n;
2724
+ const { legacyChildItemConfigs: a, childReplicas: u } = s, c = [], r = /* @__PURE__ */ new Set();
2725
+ for (const i of u)
2726
+ r.add(i.netSuiteId), c.push({
2727
+ name: i.name,
2728
+ netSuiteId: i.netSuiteId,
2729
+ parentNetSuiteId: i.parentNetSuiteId,
2730
+ unitTypeId: i.unitTypeId,
2731
+ unitOfMeasureId: i.unitOfMeasureId,
2732
+ subsidiaryIds: i.subsidiaryIds,
2733
+ includeChildren: i.includeChildren,
2734
+ cogsAccount: i.cogsAccount,
2735
+ itemType: i.itemType,
2736
+ externalId: i.externalId,
2737
+ pktCode: (t = i.customFields) == null ? void 0 : t.pktCode,
2738
+ pktName: (n = i.customFields) == null ? void 0 : n.pktName
2739
+ });
2740
+ for (const i of a)
2741
+ i.itemType !== V.Enum.InvtPart && !r.has(i.netSuiteId) && c.push(i);
2742
+ return c;
2743
+ }
2744
+ g(kn, "syncInventoryChildItemsWithLegacyConfig");
2745
+ var h;
2746
+ (function(s) {
2747
+ s.ITEM_CREATED = "ITEM_CREATED", s.ITEM_UPDATED = "ITEM_UPDATED", s.ITEM_DELETED = "ITEM_DELETED", s.ITEM_DUPLICATE = "ITEM_DUPLICATE", s.ITEM_RECEIPT_ITEM_CREATED = "ITEM_RECEIPT_ITEM_CREATED", s.ITEM_RECEIPT_ITEM_UPDATED = "ITEM_RECEIPT_ITEM_UPDATED", s.ITEM_RECEIPT_ITEM_DELETED = "ITEM_RECEIPT_ITEM_DELETED", s.ITEM_FULFILLMENT_ITEM_CREATED = "ITEM_FULFILLMENT_ITEM_CREATED", s.ITEM_FULFILLMENT_ITEM_UPDATED = "ITEM_FULFILLMENT_ITEM_UPDATED", s.ITEM_FULFILLMENT_ITEM_DELETED = "ITEM_FULFILLMENT_ITEM_DELETED";
2748
+ })(h || (h = {}));
2749
+ function ne(s, a) {
2750
+ return a.reduce((u, c) => u.replace("$", c), s);
2751
+ }
2752
+ g(ne, "replacePlaceholders");
2753
+ var Te = 'Record [$] item on line [$], field "$" changed from "$" to "$"';
2754
+ function ye(s, a, u, c, r = !1) {
2755
+ const t = [];
2756
+ if ((c === ee.Enum[2] || r) && a.length != 0 && a.every((n) => !n.externalId))
2757
+ for (let n = 0; n < a.length; n++) {
2758
+ const i = s[n];
2759
+ if (!i)
2760
+ throw new Error("Incoming item is undefined");
2761
+ t.push({
2762
+ type: h.ITEM_UPDATED,
2763
+ message: ne(Te, [
2764
+ "Order Item",
2765
+ `${i.externalId}`,
2766
+ "externalId",
2767
+ `${a[n].externalId}`,
2768
+ `${i.externalId}`
2769
+ ]),
2770
+ data: {
2771
+ recordId: u,
2772
+ recordType: "purchaseOrder",
2773
+ field: "externalId",
2774
+ externalId: i.externalId,
2775
+ incomingValue: i.externalId,
2776
+ existingValue: a[n].externalId
2777
+ }
2778
+ }), a[n].externalId = i.externalId;
2779
+ }
2780
+ for (const n of a)
2781
+ s.find((o) => c == "2" ? o.externalId === n.externalId : o.sku._id === n.sku._id) || t.push({
2782
+ type: h.ITEM_DELETED,
2783
+ message: `Order Item ${u} does not match sku ${n.sku._id} with existing line [${n.externalId}]`,
2784
+ data: {
2785
+ existinglineItem: n,
2786
+ recordId: u
2787
+ }
2788
+ });
2789
+ for (const n of s) {
2790
+ const i = a.find((o) => c == "2" ? o.externalId === n.externalId : o.sku._id === n.sku._id);
2791
+ if (!i)
2792
+ t.push({
2793
+ type: h.ITEM_CREATED,
2794
+ message: `Order Item from ${u} does not have sku ${n.sku._id} with line [${n.externalId}]`,
2795
+ data: {
2796
+ lineItem: n,
2797
+ recordId: u
2798
+ }
2799
+ });
2800
+ else {
2801
+ const o = Object.keys(qe.shape);
2802
+ for (const m of o) {
2803
+ if (m === "id" || m === "code" || m === "name" || m === "externalId" && c === ee.Enum[1])
2804
+ continue;
2805
+ if (m === "sku") {
2806
+ n[m]._id !== i[m]._id && t.push({
2807
+ type: h.ITEM_UPDATED,
2808
+ message: ne(Te, [
2809
+ "Order Item",
2810
+ `${n.externalId}`,
2811
+ m,
2812
+ `${i[m]._id}`,
2813
+ `${n[m]._id}`
2814
+ ]),
2815
+ data: {
2816
+ recordId: u,
2817
+ recordType: "purchaseOrder",
2818
+ field: m,
2819
+ externalId: n.externalId,
2820
+ sku: i.sku,
2821
+ incomingValue: n[m],
2822
+ existingValue: i[m]
2823
+ }
2824
+ });
2825
+ continue;
2826
+ }
2827
+ const l = n[m] ?? null, f = i[m] ?? null;
2828
+ if (!(m === "quantity" && l && f && C.equals({
2829
+ a: l,
2830
+ b: f
2831
+ })) && !L.isEqual(n[m], i[m])) {
2832
+ let d = f, I = l;
2833
+ typeof n[m] == "object" && (d = JSON.stringify(f), I = JSON.stringify(l)), t.push({
2834
+ type: h.ITEM_UPDATED,
2835
+ message: ne(Te, [
2836
+ "Purchase Order Item",
2837
+ `${n.externalId}`,
2838
+ m,
2839
+ `${d}`,
2840
+ `${I}`
2841
+ ]),
2842
+ data: {
2843
+ recordId: u,
2844
+ externalId: n.externalId,
2845
+ sku: i.sku,
2846
+ field: m,
2847
+ incomingValue: n[m],
2848
+ existingValue: i[m]
2849
+ }
2850
+ });
2851
+ }
2852
+ }
2853
+ }
2854
+ }
2855
+ return t;
2856
+ }
2857
+ g(ye, "detectPurchaseOrderItemConflicts");
2858
+ function tt(s, a, u, c, r) {
2859
+ const t = [], n = {};
2860
+ if (r === ee.Enum[2] && c.length != 0 && c.every((i) => !i.externalId))
2861
+ for (let i = 0; i < c.length; i++) {
2862
+ const o = u[i];
2863
+ if (!o)
2864
+ throw new Error("Incoming item is undefined");
2865
+ t.push({
2866
+ type: a === "deliveryFulfillment" ? h.ITEM_FULFILLMENT_ITEM_UPDATED : h.ITEM_RECEIPT_ITEM_UPDATED,
2867
+ message: ne(Te, [
2868
+ `${a}`,
2869
+ `${o.externalId}`,
2870
+ "externalId",
2871
+ `${c[i].externalId}`,
2872
+ `${o.externalId}`
2873
+ ]),
2874
+ data: {
2875
+ recordId: s,
2876
+ field: "externalId",
2877
+ externalId: o.externalId,
2878
+ incomingValue: o.externalId,
2879
+ existingValue: c[i].externalId
2880
+ }
2881
+ }), c[i].externalId = o.externalId;
2882
+ }
2883
+ for (const i of c) {
2884
+ const o = u.find((m) => r == "2" ? m.externalId === i.externalId : m.sku._id === i.sku._id);
2885
+ o || t.push({
2886
+ type: a === "deliveryFulfillment" ? h.ITEM_FULFILLMENT_ITEM_DELETED : h.ITEM_RECEIPT_ITEM_DELETED,
2887
+ message: `${a} ${s} does match sku ${i.sku._id} with existing line [${i.externalId}]`,
2888
+ data: {
2889
+ lineItem: o,
2890
+ existinglineItem: i,
2891
+ recordId: s
2892
+ }
2893
+ });
2894
+ }
2895
+ for (const i of u) {
2896
+ const o = c.find((m) => r == "2" ? m.externalId === i.externalId : m.sku._id === i.sku._id);
2897
+ if (!o)
2898
+ t.push({
2899
+ type: a === "deliveryFulfillment" ? h.ITEM_FULFILLMENT_ITEM_CREATED : h.ITEM_RECEIPT_ITEM_CREATED,
2900
+ message: `${a} ${s} does not have sku ${i.sku._id} with line [${i.externalId}]`,
2901
+ data: {
2902
+ lineItem: i,
2903
+ recordId: s
2904
+ }
2905
+ });
2906
+ else {
2907
+ i.id && i.externalId && (n[i.id] = i.externalId);
2908
+ const m = Object.keys(Yt.shape);
2909
+ for (const l of m) {
2910
+ if (l === "id" || l === "externalId" && r === ee.Enum[1])
2911
+ continue;
2912
+ if (l === "sku") {
2913
+ i[l]._id !== o[l]._id && t.push({
2914
+ type: a === "deliveryFulfillment" ? h.ITEM_FULFILLMENT_ITEM_UPDATED : h.ITEM_RECEIPT_ITEM_UPDATED,
2915
+ message: ne(Te, [
2916
+ `${a}`,
2917
+ `${i.externalId}`,
2918
+ l,
2919
+ `${o[l]._id}`,
2920
+ `${i[l]._id}`
2921
+ ]),
2922
+ data: {
2923
+ recordId: s,
2924
+ recordType: a,
2925
+ sku: o.sku,
2926
+ externalId: i.externalId,
2927
+ field: l,
2928
+ incomingValue: i[l],
2929
+ existingValue: o[l]
2930
+ }
2931
+ });
2932
+ continue;
2933
+ }
2934
+ const f = i[l] ?? null, d = o[l] ?? null;
2935
+ if (!(l === "amount" && f && d && C.equals({
2936
+ a: f,
2937
+ b: d
2938
+ })) && !L.isEqual(i[l], o[l])) {
2939
+ let I = d, p = f;
2940
+ typeof i[l] == "object" && (I = JSON.stringify(d), p = JSON.stringify(f)), t.push({
2941
+ type: a === "deliveryFulfillment" ? h.ITEM_FULFILLMENT_ITEM_UPDATED : h.ITEM_RECEIPT_ITEM_UPDATED,
2942
+ message: ne(Te, [
2943
+ `${a}`,
2944
+ `${i.externalId}`,
2945
+ l,
2946
+ `${I}`,
2947
+ `${p}`
2948
+ ]),
2949
+ data: {
2950
+ recordId: s,
2951
+ recordType: a,
2952
+ sku: o.sku,
2953
+ externalId: i.externalId,
2954
+ field: l,
2955
+ incomingValue: i[l],
2956
+ existingValue: o[l]
2957
+ }
2958
+ });
2959
+ }
2960
+ }
2961
+ }
2962
+ }
2963
+ return t;
2964
+ }
2965
+ g(tt, "detectPurchaseOrderReceivedConflicts");
2966
+ function Ve(s, a, u = "1") {
2967
+ if (a.length === 0)
2968
+ return s;
2969
+ const c = [
2970
+ ...s
2971
+ ];
2972
+ for (const r of a) {
2973
+ if (r.type === h.ITEM_CREATED && c.push({
2974
+ ...r.data.lineItem,
2975
+ id: r.data.lineItem.id || crypto.randomUUID()
2976
+ }), r.type === h.ITEM_UPDATED) {
2977
+ let t = -1;
2978
+ u == "2" ? t = c.findIndex((n) => n.externalId === r.data.externalId) : r.data.sku && (t = c.findIndex((n) => n.sku._id === r.data.sku._id)), t !== -1 && (c[t][r.data.field] = r.data.incomingValue);
2979
+ }
2980
+ if (r.type === h.ITEM_DELETED) {
2981
+ const t = c.findIndex((n) => n.externalId === r.data.existinglineItem.externalId);
2982
+ t !== -1 && c.splice(t, 1);
2983
+ }
2984
+ }
2985
+ return c.map((r) => ({
2986
+ ...r,
2987
+ id: r.id || crypto.randomUUID()
2988
+ }));
2989
+ }
2990
+ g(Ve, "resolvePurchaseOrderItemConflicts");
2991
+ function nt(s, a, u = "1") {
2992
+ if (a.length === 0)
2993
+ return s;
2994
+ const c = [
2995
+ ...s
2996
+ ];
2997
+ for (const r of a) {
2998
+ if ((r.type === h.ITEM_CREATED || r.type === h.ITEM_RECEIPT_ITEM_CREATED || r.type === h.ITEM_FULFILLMENT_ITEM_CREATED) && c.push({
2999
+ ...r.data.lineItem,
3000
+ id: r.data.lineItem.id || crypto.randomUUID()
3001
+ }), r.type === h.ITEM_UPDATED || r.type === h.ITEM_RECEIPT_ITEM_UPDATED || r.type === h.ITEM_FULFILLMENT_ITEM_UPDATED) {
3002
+ let t = -1;
3003
+ u == "2" ? t = c.findIndex((n) => n.externalId === r.data.externalId) : r.data.sku && (t = c.findIndex((n) => n.sku._id === r.data.sku._id)), t !== -1 && (c[t][r.data.field] = r.data.incomingValue);
3004
+ }
3005
+ if (r.type === h.ITEM_DELETED || r.type === h.ITEM_RECEIPT_ITEM_DELETED || r.type === h.ITEM_FULFILLMENT_ITEM_DELETED) {
3006
+ const t = c.findIndex((n) => n.externalId === r.data.existinglineItem.externalId);
3007
+ t !== -1 && c.splice(t, 1);
3008
+ }
3009
+ }
3010
+ return c;
3011
+ }
3012
+ g(nt, "resolvePurchaseOrderReceivedConflicts");
3013
+ var de;
3014
+ (function(s) {
3015
+ s.ITEM_FULFILLMENT_CREATED = "ITEM_FULFILLMENT_CREATED", s.ITEM_FULFILLMENT_UPDATED = "ITEM_FULFILLMENT_UPDATED", s.ITEM_FULFILLMENT_DELETED = "ITEM_FULFILLMENT_DELETED";
3016
+ })(de || (de = {}));
3017
+ var wn = 'Record [$] item on line [$], field "$" changed from "$" to "$"';
3018
+ function Rn(s, a, u) {
3019
+ var t, n, i;
3020
+ const c = Object.keys(Gt.shape), r = [];
3021
+ for (const o of a) {
3022
+ const m = s.find((l) => {
3023
+ var f;
3024
+ return ((f = l.netSuite) == null ? void 0 : f.id) === o.netSuite.id;
3025
+ });
3026
+ if (!m)
3027
+ r.push({
3028
+ type: de.ITEM_FULFILLMENT_CREATED,
3029
+ message: `New Item Fulfillment ${(t = o.netSuite) == null ? void 0 : t.id} created`,
3030
+ data: o
3031
+ });
3032
+ else
3033
+ for (const l of c) {
3034
+ if (l === "adjustment" || l === "id")
3035
+ continue;
3036
+ if (l === "items") {
3037
+ r.push(...tt(m.id, "deliveryFulfillment", o.items, m.items, u));
3038
+ continue;
3039
+ }
3040
+ const f = o[l] ?? null, d = m[l] ?? null;
3041
+ if (!L.isEqual(f, d)) {
3042
+ let I = d, p = f;
3043
+ typeof o[l] == "object" && (I = JSON.stringify(d), p = JSON.stringify(f)), l === "createdAt" && (I = new Date(o[l]).toISOString(), p = new Date(m[l]).toISOString()), r.push({
3044
+ type: de.ITEM_FULFILLMENT_UPDATED,
3045
+ message: ne(wn, [
3046
+ "Item Fulfillment Field",
3047
+ `${(n = o.netSuite) == null ? void 0 : n.id}`,
3048
+ l,
3049
+ `${I}`,
3050
+ `${p}`
3051
+ ]),
3052
+ data: {
3053
+ recordId: `${(i = o.netSuite) == null ? void 0 : i.id}`,
3054
+ field: l,
3055
+ incomingValue: f,
3056
+ existingValue: d
3057
+ }
3058
+ });
3059
+ }
3060
+ }
3061
+ }
3062
+ return r;
3063
+ }
3064
+ g(Rn, "detectItemFulfillmentConflicts");
3065
+ function On(s, a) {
3066
+ const u = a.filter((t) => t.type === de.ITEM_FULFILLMENT_CREATED || t.type === de.ITEM_FULFILLMENT_UPDATED || t.type === de.ITEM_FULFILLMENT_DELETED || t.type === h.ITEM_FULFILLMENT_ITEM_CREATED || t.type === h.ITEM_FULFILLMENT_ITEM_UPDATED || t.type === h.ITEM_FULFILLMENT_ITEM_DELETED), c = [];
3067
+ if (u.length === 0)
3068
+ return s;
3069
+ for (const t of s) {
3070
+ const n = u.filter((l) => l.data.recordId != "" && l.data.recordId === t.id), i = n.filter((l) => (l.type === h.ITEM_FULFILLMENT_ITEM_CREATED || l.type === h.ITEM_FULFILLMENT_ITEM_UPDATED || l.type === h.ITEM_FULFILLMENT_ITEM_DELETED) && l.data.recordId === t.id), o = nt(t.items || [], i);
3071
+ let m = {
3072
+ ...t,
3073
+ items: o
3074
+ };
3075
+ for (const l of n)
3076
+ if (l.type === de.ITEM_FULFILLMENT_UPDATED) {
3077
+ const f = l.data.field, d = l.data.incomingValue, I = t[f];
3078
+ d !== I && (m = {
3079
+ ...t,
3080
+ [f]: d
3081
+ });
3082
+ }
3083
+ c.push(m);
3084
+ }
3085
+ for (const t of u)
3086
+ t.type === de.ITEM_FULFILLMENT_CREATED && c.push({
3087
+ ...t.data,
3088
+ id: t.data.id || R({
3089
+ prefix: O.Enum.deliveryFulfillment
3090
+ })
3091
+ });
3092
+ const r = [];
3093
+ for (const t of c)
3094
+ t.id ? r.push(t) : (console.warn("Missing delivery fulfillment id, generating new id"), r.push({
3095
+ ...t,
3096
+ id: R({
3097
+ prefix: O.Enum.deliveryFulfillment
3098
+ })
3099
+ }));
3100
+ return r;
3101
+ }
3102
+ g(On, "resolveDeliveryFulfillmentConflicts");
3103
+ var ce;
3104
+ (function(s) {
3105
+ s.ITEM_RECEIPT_CREATED = "ITEM_RECEIPT_CREATED", s.ITEM_RECEIPT_UPDATED = "ITEM_RECEIPT_UPDATED", s.ITEM_RECEIPT_DELETED = "ITEM_RECEIPT_DELETED";
3106
+ })(ce || (ce = {}));
3107
+ var W = /* @__PURE__ */ g((s) => s === "" ? null : s, "normalizeNullOrEmpty"), Ln = 'Record [$] item on line [$], field "$" changed from "$" to "$"';
3108
+ function Ot(s, a, u) {
3109
+ var i, o, m, l, f, d, I;
3110
+ const c = Object.keys(Jt.shape), r = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set();
3111
+ for (const p of s) {
3112
+ const E = W((i = p.netSuite) == null ? void 0 : i.id), y = W(p.id);
3113
+ if (E) {
3114
+ if (r.has(E))
3115
+ throw new Error(`Duplicate NetSuite ID found: ${E}`);
3116
+ r.add(E);
3117
+ }
3118
+ if (y) {
3119
+ if (t.has(y))
3120
+ throw new Error(`Duplicate delivery order ID found: ${y}`);
3121
+ t.add(y);
3122
+ }
3123
+ }
3124
+ const n = [];
3125
+ for (const p of a) {
3126
+ const E = W(p.id), y = W((o = p.netSuite) == null ? void 0 : o.id);
3127
+ if (!y)
3128
+ continue;
3129
+ const _ = s.find((S) => {
3130
+ var A;
3131
+ const v = W(S.id), N = W((A = S.netSuite) == null ? void 0 : A.id);
3132
+ return N && y && N === y || v && v === E;
3133
+ });
3134
+ if (!_)
3135
+ n.push({
3136
+ type: ce.ITEM_RECEIPT_CREATED,
3137
+ message: `New Item Receipt ${(m = p.netSuite) == null ? void 0 : m.id} created`,
3138
+ data: p
3139
+ });
3140
+ else {
3141
+ const S = W(_.id), v = W((l = _.netSuite) == null ? void 0 : l.id);
3142
+ if (v && y && v !== y || E && S && S !== E)
3143
+ throw new Error(`Inconsistent data for Item Receipt ${(f = p.netSuite) == null ? void 0 : f.id} (or ${p.id})`);
3144
+ for (const b of c) {
3145
+ if (b === "adjustment" || b === "id")
3146
+ continue;
3147
+ if (b === "received") {
3148
+ n.push(...tt(_.id, "deliveryOrder", p.received, _.received, u));
3149
+ continue;
3150
+ }
3151
+ const A = W(p[b] ?? null), F = W(_[b] ?? null);
3152
+ if (!L.isEqual(A, F)) {
3153
+ if ((b === "createdAt" || b === "createdBy" || b === "remark" || b === "effectiveAt") && F)
3154
+ continue;
3155
+ let k = F, U = A;
3156
+ typeof p[b] == "object" && (k = JSON.stringify(F), U = JSON.stringify(A)), b === "createdAt" && (k = new Date(p[b]).toISOString(), U = new Date(_[b]).toISOString()), n.push({
3157
+ type: ce.ITEM_RECEIPT_UPDATED,
3158
+ message: ne(Ln, [
3159
+ "Item Receipt Field",
3160
+ `${(d = p.netSuite) == null ? void 0 : d.id}`,
3161
+ b,
3162
+ `${k}`,
3163
+ `${U}`
3164
+ ]),
3165
+ data: {
3166
+ recordId: `${(I = p.netSuite) == null ? void 0 : I.id}`,
3167
+ field: b,
3168
+ incomingValue: A,
3169
+ existingValue: F
3170
+ }
3171
+ });
3172
+ }
3173
+ }
3174
+ }
3175
+ }
3176
+ return n;
3177
+ }
3178
+ g(Ot, "detectItemReceiptConflicts");
3179
+ function Lt(s, a) {
3180
+ const u = a.filter((t) => t.type === ce.ITEM_RECEIPT_CREATED || t.type === ce.ITEM_RECEIPT_UPDATED || t.type === ce.ITEM_RECEIPT_DELETED || t.type === h.ITEM_RECEIPT_ITEM_CREATED || t.type === h.ITEM_RECEIPT_ITEM_UPDATED || t.type === h.ITEM_RECEIPT_ITEM_DELETED), c = [];
3181
+ if (u.length === 0)
3182
+ return s;
3183
+ for (const t of s) {
3184
+ const n = u.filter((l) => {
3185
+ const f = l.data;
3186
+ return f.recordId != "" && f.recordId === t.id;
3187
+ }), i = n.filter((l) => l.type === h.ITEM_RECEIPT_ITEM_CREATED || l.type === h.ITEM_RECEIPT_ITEM_UPDATED || l.type === h.ITEM_RECEIPT_ITEM_DELETED), o = nt(t.received || [], i);
3188
+ let m = {
3189
+ ...t,
3190
+ received: o
3191
+ };
3192
+ for (const l of n)
3193
+ if (l.type === ce.ITEM_RECEIPT_UPDATED) {
3194
+ const f = l.data.field, d = l.data.incomingValue, I = t[f];
3195
+ d !== I && (m = {
3196
+ ...t,
3197
+ [f]: d
3198
+ });
3199
+ }
3200
+ c.push(m);
3201
+ }
3202
+ for (const t of u)
3203
+ if (t.type === ce.ITEM_RECEIPT_CREATED) {
3204
+ const n = new Date(t.data.createdAt), i = new Date(t.data.effectiveAt);
3205
+ c.push({
3206
+ ...t.data,
3207
+ id: t.data.id || R({
3208
+ prefix: O.Enum.deliveryOrder
3209
+ }),
3210
+ effectiveAt: J(n, i) ? void 0 : i.toISOString()
3211
+ });
3212
+ }
3213
+ const r = [];
3214
+ for (const t of c)
3215
+ t.id ? r.push(t) : (console.warn("Missing delivery order id, generating new id"), r.push({
3216
+ ...t,
3217
+ id: R({
3218
+ prefix: O.Enum.deliveryOrder
3219
+ })
3220
+ }));
3221
+ return r;
3222
+ }
3223
+ g(Lt, "resolveDeliveryOrdersConflicts");
3224
+ function Pn(s, a, u, c) {
3225
+ var n, i;
3226
+ const r = Lt(a, c), t = [];
3227
+ for (const o of r) {
3228
+ const m = {
3229
+ ...o
3230
+ };
3231
+ if ((n = o.netSuite) != null && n.id && !((i = o.fullfillmentId) != null && i.startsWith("delivery_fulfillment"))) {
3232
+ const l = s.find((f) => {
3233
+ var d;
3234
+ return ((d = f.netSuite) == null ? void 0 : d.id) === o.fullfillmentId;
3235
+ });
3236
+ l && (m.fullfillmentId = l.id);
3237
+ }
3238
+ t.push(m);
3239
+ }
3240
+ return t;
3241
+ }
3242
+ g(Pn, "resolveAndMergeDeliveryOrders");
3243
+ var G;
3244
+ (function(s) {
3245
+ s.PURCHASE_ORDER_CREATED = "PURCHASE_ORDER_CREATED", s.PURCHASE_ORDER_UPDATED = "PURCHASE_ORDER_UPDATED", s.PURCHASE_ORDER_REQUEST_CREATED = "PURCHASE_ORDER_REQUEST_CREATED", s.PURCHASE_ORDER_REQUEST_UPDATED = "PURCHASE_ORDER_REQUEST_UPDATED", s.ITEM_FULFILLMENT_CREATED = "ITEM_FULFILLMENT_CREATED", s.ITEM_FULFILLMENT_UPDATED = "ITEM_FULFILLMENT_UPDATED", s.ITEM_FULFILLMENT_DELETED = "ITEM_FULFILLMENT_DELETED", s.ITEM_FULFILLMENT_ITEM_CREATED = "ITEM_FULFILLMENT_ITEM_CREATED", s.ITEM_FULFILLMENT_ITEM_UPDATED = "ITEM_FULFILLMENT_ITEM_UPDATED", s.ITEM_FULFILLMENT_ITEM_DELETED = "ITEM_FULFILLMENT_ITEM_DELETED";
3246
+ })(G || (G = {}));
3247
+ function K(s, a, u, c, r) {
3248
+ let t = c, n = r;
3249
+ return typeof c == "object" && (t = JSON.stringify(c), n = JSON.stringify(r)), `${s} ${a} field ${u} changed from "${t}" to "${n}"`;
3250
+ }
3251
+ g(K, "generateLogMessage");
3252
+ function xn(s, a, u, c = !1) {
3253
+ var t, n;
3254
+ const r = [];
3255
+ if (a || r.push({
3256
+ type: G.PURCHASE_ORDER_CREATED,
3257
+ message: "Purchase order not found",
3258
+ data: s.purchaseOrder
3259
+ }), u || r.push({
3260
+ type: G.PURCHASE_ORDER_REQUEST_CREATED,
3261
+ message: "Purchase order request not found",
3262
+ data: s.purchaseOrderRequest
3263
+ }), !a && !u)
3264
+ return r.push(...ye(s.purchaseOrder.items, [], "", "2")), r;
3265
+ if (a) {
3266
+ const i = Object.keys(Qe.shape);
3267
+ for (const o of i) {
3268
+ if (![
3269
+ "status",
3270
+ "ref",
3271
+ "items",
3272
+ "effectiveAt",
3273
+ "netSuite"
3274
+ ].includes(o))
3275
+ continue;
3276
+ if (o === "items") {
3277
+ r.push(...ye(s.purchaseOrder.items, a.items, a._id, a.version || "1", c));
3278
+ continue;
3279
+ }
3280
+ let l = s.purchaseOrder[o] ?? null;
3281
+ const f = a[o] ?? null;
3282
+ if (o === "request") {
3283
+ const d = l, I = f;
3284
+ if (!(d != null && d.id) && (I != null && I.id))
3285
+ continue;
3286
+ }
3287
+ if (o === "effectiveAt" && l && typeof l == "string") {
3288
+ const d = new Date(ie(a._id));
3289
+ J(d, new Date(l)) && (l = null);
3290
+ }
3291
+ if (!L.isEqual(l, f)) {
3292
+ let d = f, I = l;
3293
+ if (l && f && typeof l == "object" && typeof f == "object" && (d = f ? JSON.stringify(f) : null, I = l ? JSON.stringify(l) : null), o === "effectiveAt") {
3294
+ if (!f) {
3295
+ const p = new Date(ie(a._id));
3296
+ if (typeof l == "string" && new Date(l).toDateString() === new Date(p).toDateString())
3297
+ continue;
3298
+ }
3299
+ d = f && typeof f == "string" ? new Date(f).toISOString() : null, I = l && typeof l == "string" ? new Date(l).toISOString() : null;
3300
+ }
3301
+ r.push({
3302
+ type: G.PURCHASE_ORDER_UPDATED,
3303
+ message: K("Transfer Order", (t = s.purchaseOrder.netSuite) == null ? void 0 : t.id, o, d, I),
3304
+ data: {
3305
+ field: o,
3306
+ incomingValue: l,
3307
+ existingValue: f
3308
+ }
3309
+ });
3310
+ }
3311
+ }
3312
+ }
3313
+ if (u) {
3314
+ const i = Object.keys(zt.shape);
3315
+ for (const o of i) {
3316
+ if (o === "_id")
3317
+ continue;
3318
+ const m = s.purchaseOrderRequest[o] ?? null, l = u[o] ?? null;
3319
+ if ((o === "processedAt" || o === "rejectedAt") && m !== l) {
3320
+ const f = !!u.processedAt, d = !!u.rejectedAt;
3321
+ if (s.purchaseOrder.status === j.Enum.REQUESTING && (f || d))
3322
+ continue;
3323
+ const p = s.purchaseOrderRequest[o] ? new Date(s.purchaseOrderRequest[o]).toISOString() : null, E = u[o] ? new Date(u[o]).toISOString() : null;
3324
+ r.push({
3325
+ type: G.PURCHASE_ORDER_REQUEST_UPDATED,
3326
+ message: K("Transfer Order", (n = s.purchaseOrder.netSuite) == null ? void 0 : n.id, o, E, p),
3327
+ data: {
3328
+ field: o,
3329
+ incomingValue: s.purchaseOrderRequest[o],
3330
+ existingValue: u[o]
3331
+ }
3332
+ });
3333
+ }
3334
+ }
3335
+ }
3336
+ return r;
3337
+ }
3338
+ g(xn, "detectTransferOrderConflicts");
3339
+ function $n(s, a, u, c, r) {
3340
+ if (s.length === 0)
3341
+ throw new Error("No order lines found");
3342
+ let t = c || (r == null ? void 0 : r.purchaseOrder), n = r;
3343
+ const i = Ve((t == null ? void 0 : t.items) || [], a);
3344
+ if (a.length === 0)
3345
+ return {
3346
+ purchaseOrder: c,
3347
+ purchaseOrderRequest: r
3348
+ };
3349
+ if (t) {
3350
+ for (const o of a)
3351
+ if (o.type === G.PURCHASE_ORDER_UPDATED) {
3352
+ const m = o.data.field, l = o.data.incomingValue;
3353
+ t = {
3354
+ ...t,
3355
+ [m]: l
3356
+ };
3357
+ }
3358
+ t = {
3359
+ ...t,
3360
+ items: i
3361
+ };
3362
+ }
3363
+ for (const o of a)
3364
+ switch (o.type) {
3365
+ case G.PURCHASE_ORDER_CREATED:
3366
+ const m = new Date(ie(u.purchaseOrder._id)), l = new Date(u.purchaseOrder.effectiveAt);
3367
+ t = {
3368
+ ...u.purchaseOrder,
3369
+ _id: (r == null ? void 0 : r.purchaseOrderId) || u.purchaseOrder._id || R({
3370
+ prefix: O.Enum.purchaseOrder
3371
+ }),
3372
+ effectiveAt: J(m, l) ? void 0 : l.toISOString(),
3373
+ items: i
3374
+ };
3375
+ break;
3376
+ case G.PURCHASE_ORDER_REQUEST_CREATED:
3377
+ n = {
3378
+ ...u.purchaseOrderRequest,
3379
+ purchaseOrder: {
3380
+ ...u.purchaseOrder,
3381
+ items: i
3382
+ }
3383
+ };
3384
+ break;
3385
+ case G.PURCHASE_ORDER_UPDATED:
3386
+ if (t) {
3387
+ const f = o.data.field, d = o.data.incomingValue, I = t[f];
3388
+ if (f === "version" && d !== I)
3389
+ continue;
3390
+ t = {
3391
+ ...t,
3392
+ [f]: d
3393
+ };
3394
+ }
3395
+ break;
3396
+ case G.PURCHASE_ORDER_REQUEST_UPDATED:
3397
+ if (n) {
3398
+ const f = o.data.field, d = o.data.incomingValue, I = n[f];
3399
+ d !== I && (n = {
3400
+ ...n,
3401
+ [f]: d
3402
+ });
3403
+ }
3404
+ break;
3405
+ }
3406
+ return t = {
3407
+ ...t,
3408
+ status: u.purchaseOrder.status,
3409
+ netSuite: u.purchaseOrder.deliveryFullfillment.length > 0 ? u.purchaseOrder.netSuite : t == null ? void 0 : t.netSuite
3410
+ }, n = {
3411
+ ...n,
3412
+ purchaseOrder: t,
3413
+ purchaseOrderId: t._id,
3414
+ _id: n._id
3415
+ }, {
3416
+ purchaseOrder: t,
3417
+ purchaseOrderRequest: n
3418
+ };
3419
+ }
3420
+ g($n, "resolveTransferOrderConflicts");
3421
+ e.object({
3422
+ lineItem: qe.nullish(),
3423
+ existinglineItem: qe.nullish(),
3424
+ recordId: e.string()
3425
+ });
3426
+ e.object({
3427
+ recordId: e.string(),
3428
+ recordType: e.string(),
3429
+ externalId: e.string(),
3430
+ sku: je.optional(),
3431
+ field: e.string(),
3432
+ incomingValue: e.any(),
3433
+ existingValue: e.any()
3434
+ });
3435
+ var ge;
3436
+ (function(s) {
3437
+ s.PURCHASE_ORDER_CREATED = "PURCHASE_ORDER_CREATED", s.PURCHASE_ORDER_UPDATED = "PURCHASE_ORDER_UPDATED", s.ITEM_RECEIPT_CREATED = "ITEM_RECEIPT_CREATED", s.ITEM_RECEIPT_UPDATED = "ITEM_RECEIPT_UPDATED", s.ITEM_RECEIPT_DELETED = "ITEM_RECEIPT_DELETED", s.ITEM_RECEIPT_ITEM_CREATED = "ITEM_RECEIPT_ITEM_CREATED", s.ITEM_RECEIPT_ITEM_UPDATED = "ITEM_RECEIPT_ITEM_UPDATED", s.ITEM_RECEIPT_ITEM_DELETED = "ITEM_RECEIPT_ITEM_DELETED";
3438
+ })(ge || (ge = {}));
3439
+ function jn(s, a) {
3440
+ var r;
3441
+ const u = [];
3442
+ if (!a)
3443
+ return u.push({
3444
+ type: ge.PURCHASE_ORDER_CREATED,
3445
+ message: "Purchase order not found",
3446
+ data: s
3447
+ }), u.push(...ye(s.items, [], "", "2")), u;
3448
+ const c = Object.keys(Qe.shape);
3449
+ for (const t of c) {
3450
+ if (![
3451
+ "status",
3452
+ "ref",
3453
+ "items",
3454
+ "effectiveAt",
3455
+ "netSuite"
3456
+ ].includes(t))
3457
+ continue;
3458
+ if (t === "items") {
3459
+ u.push(...ye(s.items, a.items, a._id, a.version || "1"));
3460
+ continue;
3461
+ }
3462
+ const i = s[t] ?? null, o = a[t] ?? null;
3463
+ if (t === "effectiveAt" && i && typeof i == "string") {
3464
+ const m = new Date(ie(a._id));
3465
+ if (J(m, new Date(i)))
3466
+ continue;
3467
+ }
3468
+ if (t === "effectiveAt" && i !== o) {
3469
+ if (i && o && typeof i == "string" && typeof o == "string" && new Date(i).toDateString() === new Date(o).toDateString())
3470
+ continue;
3471
+ const m = i && typeof i == "string" ? new Date(i).toISOString() : null, l = o && typeof o == "string" ? new Date(o).toISOString() : null;
3472
+ u.push({
3473
+ type: ge.PURCHASE_ORDER_UPDATED,
3474
+ message: K("Purchase Order", (r = s.netSuite) == null ? void 0 : r.id, t, l, m),
3475
+ data: {
3476
+ field: t,
3477
+ incomingValue: i,
3478
+ existingValue: o
3479
+ }
3480
+ });
3481
+ }
3482
+ }
3483
+ return u.push(...Ot((a == null ? void 0 : a.deliveryOrder) ?? [], s.deliveryOrder ?? [], a ? (a == null ? void 0 : a.version) || "1" : s.version)), u;
3484
+ }
3485
+ g(jn, "detectPurchaseOrderConflicts");
3486
+ function Vn(s, a, u, c) {
3487
+ let r = c ? L.cloneDeep(c) : null;
3488
+ const t = Ve((r == null ? void 0 : r.items) || [], a);
3489
+ if (s.length === 0)
3490
+ throw new Error("No order lines found");
3491
+ if (r) {
3492
+ for (const n of a)
3493
+ if (n.type === ge.PURCHASE_ORDER_UPDATED) {
3494
+ const i = n.data.field, o = n.data.incomingValue, m = r[i];
3495
+ o !== m && (r = {
3496
+ ...r,
3497
+ [i]: o
3498
+ });
3499
+ }
3500
+ if (a.length === 0)
3501
+ return {
3502
+ ...u,
3503
+ _id: (c == null ? void 0 : c._id) ?? u._id,
3504
+ items: t
3505
+ };
3506
+ r = {
3507
+ ...r,
3508
+ items: t
3509
+ };
3510
+ }
3511
+ for (const n of a)
3512
+ switch (n.type) {
3513
+ case ge.PURCHASE_ORDER_CREATED:
3514
+ const i = new Date(ie(u._id)), o = new Date(u.effectiveAt);
3515
+ r = {
3516
+ ...u,
3517
+ _id: u._id || R({
3518
+ prefix: O.Enum.purchaseOrder
3519
+ }),
3520
+ effectiveAt: J(i, o) ? void 0 : o.toISOString(),
3521
+ items: t
3522
+ };
3523
+ break;
3524
+ case ge.PURCHASE_ORDER_UPDATED:
3525
+ if (r) {
3526
+ const m = n.data.field, l = n.data.incomingValue;
3527
+ r[m], r = {
3528
+ ...r,
3529
+ [m]: l,
3530
+ items: t
3531
+ };
3532
+ }
3533
+ }
3534
+ return r = {
3535
+ ...r,
3536
+ status: u.status,
3537
+ netSuite: u.netSuite
3538
+ }, r;
3539
+ }
3540
+ g(Vn, "resolvePurchaseOrderConflicts");
3541
+ var Ne;
3542
+ (function(s) {
3543
+ s.UNIT_CREATED = "UNIT_CREATED", s.UNIT_UPDATED = "UNIT_UPDATED", s.UNIT_DELETED = "UNIT_DELETED";
3544
+ })(Ne || (Ne = {}));
3545
+ var me;
3546
+ (function(s) {
3547
+ s.UNIT_OF_MEASUREMENT_CREATED = "UNIT_OF_MEASUREMENT_CREATED", s.UNIT_OF_MEASUREMENT_UPDATED = "UNIT_OF_MEASUREMENT_UPDATED", s.UNIT_OF_MEASUREMENT_DELETED = "UNIT_OF_MEASUREMENT_DELETED", s.UNIT_OF_MEASUREMENT_DUPLICATE = "UNIT_OF_MEASUREMENT_DUPLICATE";
3548
+ })(me || (me = {}));
3549
+ var Bn = 'Record [$] unif of measure on line [$], field "$" changed from "$" to "$"';
3550
+ function Pt(s, a) {
3551
+ const u = Object.keys(Tt.shape), c = [];
3552
+ for (const r of a) {
3553
+ const t = s.measurements.find((n) => n.nsConfig.netSuiteId === r.nsConfig.netSuiteId);
3554
+ if (!t)
3555
+ c.push({
3556
+ type: me.UNIT_OF_MEASUREMENT_CREATED,
3557
+ message: `NetSuite Measurement ${r.nsConfig.netSuiteId} does not exist in existing unit ${s.name} ${s.nsConfig.netSuiteId})`,
3558
+ data: r
3559
+ });
3560
+ else
3561
+ for (const n of u) {
3562
+ if (n === "nsConfig" || n === "id")
3563
+ continue;
3564
+ const i = r[n] ?? null, o = t[n] ?? null;
3565
+ if (!L.isEqual(i, o)) {
3566
+ let m = o, l = i;
3567
+ typeof i == "object" && (m = JSON.stringify(o), l = JSON.stringify(i)), c.push({
3568
+ type: me.UNIT_OF_MEASUREMENT_UPDATED,
3569
+ message: ne(Bn, [
3570
+ "Unit Of Measure",
3571
+ `${r.nsConfig.netSuiteId}`,
3572
+ n,
3573
+ `${m}`,
3574
+ `${l}`
3575
+ ]),
3576
+ data: {
3577
+ config: t.nsConfig,
3578
+ field: n,
3579
+ incomingValue: r[n],
3580
+ existingValue: t[n]
3581
+ }
3582
+ });
3583
+ }
3584
+ }
3585
+ }
3586
+ for (const r of s.measurements)
3587
+ a.find((n) => n.nsConfig.netSuiteId === r.nsConfig.netSuiteId) || c.push({
3588
+ type: me.UNIT_OF_MEASUREMENT_DELETED,
3589
+ message: `Unit Of Measure [${r.nsConfig.netSuiteId}] doesn't exist in incoming units`,
3590
+ data: r
3591
+ });
3592
+ return c;
3593
+ }
3594
+ g(Pt, "detectUnitOfMeasureConflicts");
3595
+ function qn(s, a) {
3596
+ const u = [];
3597
+ if (!a)
3598
+ u.push({
3599
+ type: Ne.UNIT_CREATED,
3600
+ message: `Unit type [${s.nsConfig.netSuiteId}] config doesn't exist`,
3601
+ data: s
3602
+ });
3603
+ else {
3604
+ const c = Object.keys(ht.shape);
3605
+ for (const r of c) {
3606
+ if (r === "nsConfig" || r === "_id")
3607
+ continue;
3608
+ if (r === "measurements") {
3609
+ u.push(...Pt(a, s.measurements));
3610
+ continue;
3611
+ }
3612
+ const t = s[r] ?? null, n = a[r] ?? null;
3613
+ if (!L.isEqual(t, n)) {
3614
+ let i = n, o = t;
3615
+ u.push({
3616
+ type: Ne.UNIT_UPDATED,
3617
+ message: K("Unit Type", s.nsConfig.netSuiteId, r, i, o),
3618
+ data: {
3619
+ field: r,
3620
+ incomingValue: t,
3621
+ existingValue: n
3622
+ }
3623
+ });
3624
+ }
3625
+ }
3626
+ }
3627
+ return u;
3628
+ }
3629
+ g(qn, "detectUnitTypeConflicts");
3630
+ function xt(s, a) {
3631
+ if (a.length === 0)
3632
+ return s;
3633
+ const u = [
3634
+ ...s
3635
+ ];
3636
+ for (const c of a) {
3637
+ if (c.type === me.UNIT_OF_MEASUREMENT_CREATED && u.push(c.data), c.type === me.UNIT_OF_MEASUREMENT_UPDATED) {
3638
+ const r = u.findIndex((t) => t.nsConfig.netSuiteId === c.data.config.netSuiteId);
3639
+ r !== -1 && (u[r][c.data.field] = c.data.incomingValue);
3640
+ }
3641
+ if (c.type === me.UNIT_OF_MEASUREMENT_DELETED) {
3642
+ const r = u.findIndex((t) => t.nsConfig.netSuiteId === c.data.nsConfig.netSuiteId);
3643
+ r !== -1 && u.splice(r, 1);
3644
+ }
3645
+ }
3646
+ return u;
3647
+ }
3648
+ g(xt, "resolveUnitOfMeasurementConflicts");
3649
+ function Hn(s, a, u) {
3650
+ let c = u;
3651
+ const r = xt((u == null ? void 0 : u.measurements) || a.measurements, s);
3652
+ for (const t of s)
3653
+ switch (t.type) {
3654
+ case Ne.UNIT_CREATED:
3655
+ c = a;
3656
+ break;
3657
+ case Ne.UNIT_UPDATED:
3658
+ const n = t.data.field, i = t.data.incomingValue;
3659
+ c = {
3660
+ ...c,
3661
+ [n]: i,
3662
+ measurements: r
3663
+ };
3664
+ break;
3665
+ default:
3666
+ c && (c = {
3667
+ ...c,
3668
+ measurements: r
3669
+ });
3670
+ break;
3671
+ }
3672
+ return c || {
3673
+ ...a,
3674
+ measurements: r
3675
+ };
3676
+ }
3677
+ g(Hn, "resolveUnitTypeConflicts");
3678
+ var Ee;
3679
+ (function(s) {
3680
+ s.PURCHASE_ORDER_CREATED = "PURCHASE_ORDER_CREATED", s.PURCHASE_ORDER_UPDATED = "PURCHASE_ORDER_UPDATED";
3681
+ })(Ee || (Ee = {}));
3682
+ function Kn(s, a) {
3683
+ var c;
3684
+ const u = [];
3685
+ if (a || u.push({
3686
+ type: Ee.PURCHASE_ORDER_CREATED,
3687
+ message: "Purchase order not found",
3688
+ data: s
3689
+ }), !a)
3690
+ return u.push(...ye(s.items, [], "", "2")), u;
3691
+ if (a) {
3692
+ const r = Object.keys(Qe.shape);
3693
+ for (const t of r) {
3694
+ if (t === "_id" || t === "_rev" || t === "templateDoc" || t === "template" || t === "deliveryFullfillment" || t === "deliveryOrder" || t === "supplier" || t === "seqNumber" || t === "version")
3695
+ continue;
3696
+ if (t === "items") {
3697
+ u.push(...ye(s.items, a.items, a._id, a.version || "2"));
3698
+ continue;
3699
+ }
3700
+ let n = s[t] ?? null;
3701
+ const i = a[t] ?? null;
3702
+ if (t === "request") {
3703
+ const o = n, m = i;
3704
+ if (!(o != null && o.id) && (m != null && m.id))
3705
+ continue;
3706
+ }
3707
+ if (t === "effectiveAt" && n && typeof n == "string") {
3708
+ const o = new Date(ie(a._id));
3709
+ J(o, new Date(n)) && (n = null);
3710
+ }
3711
+ if (!L.isEqual(n, i)) {
3712
+ let o = i, m = n;
3713
+ if (n && i && typeof n == "object" && typeof i == "object") {
3714
+ if (t === "netSuite") {
3715
+ const l = n, f = i;
3716
+ if (l.id === f.id)
3717
+ continue;
3718
+ }
3719
+ o = i ? JSON.stringify(i) : null, m = n ? JSON.stringify(n) : null;
3720
+ }
3721
+ if (t === "effectiveAt") {
3722
+ if (!i) {
3723
+ const l = new Date(ie(a._id));
3724
+ if (typeof n == "string" && new Date(n).toDateString() === new Date(l).toDateString())
3725
+ continue;
3726
+ }
3727
+ o = i && typeof i == "string" ? new Date(i).toISOString() : null, m = n && typeof n == "string" ? new Date(n).toISOString() : null;
3728
+ }
3729
+ u.push({
3730
+ type: Ee.PURCHASE_ORDER_UPDATED,
3731
+ message: K("Inventory Transfer", (c = s.netSuite) == null ? void 0 : c.id, t, o, m),
3732
+ data: {
3733
+ field: t,
3734
+ incomingValue: n,
3735
+ existingValue: i
3736
+ }
3737
+ });
3738
+ }
3739
+ }
3740
+ }
3741
+ return u;
3742
+ }
3743
+ g(Kn, "detectInventoryTransferConflicts");
3744
+ function Yn(s, a, u, c) {
3745
+ if (s.length === 0)
3746
+ throw new Error("No order lines found");
3747
+ let r = c;
3748
+ const t = Ve((r == null ? void 0 : r.items) || [], a);
3749
+ if (a.length === 0)
3750
+ return c;
3751
+ if (r) {
3752
+ for (const n of a)
3753
+ if (n.type === Ee.PURCHASE_ORDER_UPDATED) {
3754
+ const i = n.data.field, o = n.data.incomingValue;
3755
+ r = {
3756
+ ...r,
3757
+ [i]: o
3758
+ };
3759
+ }
3760
+ r = {
3761
+ ...r,
3762
+ items: t
3763
+ };
3764
+ }
3765
+ for (const n of a)
3766
+ switch (n.type) {
3767
+ case Ee.PURCHASE_ORDER_CREATED:
3768
+ const i = new Date(ie(u._id)), o = new Date(u.effectiveAt);
3769
+ r = {
3770
+ ...u,
3771
+ _id: u._id || R({
3772
+ prefix: O.Enum.purchaseOrder
3773
+ }),
3774
+ effectiveAt: J(i, o) ? void 0 : o.toISOString(),
3775
+ items: t
3776
+ };
3777
+ break;
3778
+ case Ee.PURCHASE_ORDER_UPDATED:
3779
+ if (r) {
3780
+ const m = n.data.field, l = n.data.incomingValue, f = r[m];
3781
+ if (m === "version" && l !== f)
3782
+ continue;
3783
+ r = {
3784
+ ...r,
3785
+ [m]: l
3786
+ };
3787
+ }
3788
+ }
3789
+ return r = {
3790
+ ...r,
3791
+ status: u.status,
3792
+ netSuite: u.netSuite
3793
+ }, r;
3794
+ }
3795
+ g(Yn, "resolveInventoryTransferConflicts");
3796
+ var q;
3797
+ (function(s) {
3798
+ s.INVENTORY_ITEM_CREATED = "INVENTORY_ITEM_CREATED", s.INVENTORY_ITEM_UPDATED = "INVENTORY_ITEM_UPDATED", s.INVENTORY_ITEM_DELETED = "INVENTORY_ITEM_DELETED", s.INVENTORY_ITEM_SKU_UPDATED = "INVENTORY_ITEM_SKU_UPDATED";
3799
+ })(q || (q = {}));
3800
+ var Gn = je.pick({
3801
+ code: !0,
3802
+ name: !0,
3803
+ defaultCost: !0,
3804
+ isInactive: !0,
3805
+ trackingMeasurement: !0,
3806
+ unit: !0,
3807
+ valuation: !0
3808
+ }), Jn = bt.omit({
3809
+ netSuiteId: !0,
3810
+ businessId: !0,
3811
+ skuCache: !0,
3812
+ deletedAt: !0
3813
+ }), zn = St.omit({
3814
+ netSuiteId: !0,
3815
+ businessId: !0,
3816
+ deletedAt: !0
3817
+ });
3818
+ function Qn(s) {
3819
+ const a = [], { incoming: u, current: c } = s;
3820
+ if (u.itemType !== V.Enum.InvtPart)
3821
+ throw new Error("[detectInventoryChildItemConflicts] only supports InvtPart child items");
3822
+ if (!c)
3823
+ return a.push({
3824
+ type: q.INVENTORY_ITEM_CREATED,
3825
+ message: `InvtPart Child Item [${u.netSuiteId}] config doesn't exist`,
3826
+ data: u
3827
+ }), a;
3828
+ const r = Object.keys(zn.shape);
3829
+ for (const t of r) {
3830
+ const n = u[t] ?? null, i = c[t] ?? null;
3831
+ L.isEqual(n, i) || a.push({
3832
+ type: q.INVENTORY_ITEM_UPDATED,
3833
+ message: K("InvtPart Child Item", u.netSuiteId, t, i, n),
3834
+ data: {
3835
+ field: t,
3836
+ incomingValue: n,
3837
+ existingValue: i
3838
+ }
3839
+ });
3840
+ }
3841
+ return a;
3842
+ }
3843
+ g(Qn, "detectInventoryChildItemConflicts");
3844
+ function Wn(s) {
3845
+ const a = [], { incoming: u, current: c } = s;
3846
+ if (u.itemType !== V.Enum.InvtPart)
3847
+ throw new Error("[detectInventoryParentItemConflicts] only supports InvtPart parent items");
3848
+ if (!c)
3849
+ return a.push({
3850
+ type: q.INVENTORY_ITEM_CREATED,
3851
+ message: `Inventory Parent Item [${u.netSuiteId}] config doesn't exist`,
3852
+ data: u
3853
+ }), a;
3854
+ const r = Object.keys(Jn.shape);
3855
+ for (const n of r) {
3856
+ const i = u[n] ?? null, o = c[n] ?? null;
3857
+ L.isEqual(i, o) || a.push({
3858
+ type: q.INVENTORY_ITEM_UPDATED,
3859
+ message: K("Inventory Parent Item", u.netSuiteId, n, o, i),
3860
+ data: {
3861
+ field: n,
3862
+ incomingValue: i,
3863
+ existingValue: o
3864
+ }
3865
+ });
3866
+ }
3867
+ const t = Object.keys(Gn.shape);
3868
+ for (const n of t) {
3869
+ const i = u.skuCache[n] ?? null, o = c.skuCache[n] ?? null;
3870
+ L.isEqual(i, o) || a.push({
3871
+ type: q.INVENTORY_ITEM_SKU_UPDATED,
3872
+ message: K("Inventory Parent Item", u.netSuiteId, n, o, i),
3873
+ data: {
3874
+ field: n,
3875
+ incomingValue: i,
3876
+ existingValue: o
3877
+ }
3878
+ });
3879
+ }
3880
+ return a;
3881
+ }
3882
+ g(Wn, "detectInventoryParentItemConflicts");
3883
+ function Zn(s, a, u) {
3884
+ if (a.itemType !== V.Enum.InvtPart)
3885
+ throw new Error("[resolveInventoryParentItemConflicts] only supports InvtPart parent items");
3886
+ if (s.some((t) => t.type === q.INVENTORY_ITEM_CREATED))
3887
+ return a;
3888
+ let r = u;
3889
+ for (const t of s)
3890
+ if (t.type === q.INVENTORY_ITEM_UPDATED) {
3891
+ const n = t.data.field;
3892
+ r = {
3893
+ ...r,
3894
+ [n]: t.data.incomingValue
3895
+ };
3896
+ } else if (t.type === q.INVENTORY_ITEM_SKU_UPDATED) {
3897
+ const n = t.data.field;
3898
+ r = {
3899
+ ...r,
3900
+ skuCache: {
3901
+ ...r.skuCache,
3902
+ [n]: t.data.incomingValue
3903
+ }
3904
+ };
3905
+ }
3906
+ return r;
3907
+ }
3908
+ g(Zn, "resolveInventoryParentItemConflicts");
3909
+ function Xn(s, a, u) {
3910
+ if (a.itemType !== V.Enum.InvtPart)
3911
+ throw new Error("[resolveInventoryChildItemConflicts] only supports InvtPart child items");
3912
+ if (s.some((t) => t.type === q.INVENTORY_ITEM_CREATED))
3913
+ return a;
3914
+ let r = u;
3915
+ for (const t of s)
3916
+ if (t.type === q.INVENTORY_ITEM_UPDATED) {
3917
+ const n = t.data.field;
3918
+ r = {
3919
+ ...r,
3920
+ [n]: t.data.incomingValue
3921
+ };
3922
+ }
3923
+ return r;
3924
+ }
3925
+ g(Xn, "resolveInventoryChildItemConflicts");
3926
+ var H;
3927
+ (function(s) {
3928
+ s.ASSEMBLY_ITEM_CREATED = "ASSEMBLY_ITEM_CREATED", s.ASSEMBLY_ITEM_UPDATED = "ASSEMBLY_ITEM_UPDATED", s.ASSEMBLY_ITEM_DELETED = "ASSEMBLY_ITEM_DELETED", s.ASSEMBLY_ITEM_SKU_UPDATED = "ASSEMBLY_ITEM_SKU_UPDATED";
3929
+ })(H || (H = {}));
3930
+ var ei = je.pick({
3931
+ code: !0,
3932
+ name: !0,
3933
+ defaultCost: !0,
3934
+ isInactive: !0,
3935
+ trackingMeasurement: !0,
3936
+ unit: !0,
3937
+ valuation: !0
3938
+ }), ti = bt.omit({
3939
+ netSuiteId: !0,
3940
+ businessId: !0,
3941
+ skuCache: !0,
3942
+ deletedAt: !0
3943
+ }), ni = St.omit({
3944
+ netSuiteId: !0,
3945
+ businessId: !0,
3946
+ deletedAt: !0
3947
+ });
3948
+ function ii(s) {
3949
+ const a = [], { incoming: u, current: c } = s;
3950
+ if (u.itemType !== V.Enum.Assembly)
3951
+ throw new Error("[detectAssemblyChildItemConflicts] only supports Assembly child items");
3952
+ if (!c)
3953
+ return a.push({
3954
+ type: H.ASSEMBLY_ITEM_CREATED,
3955
+ message: `Assembly Child Item [${u.netSuiteId}] config doesn't exist`,
3956
+ data: u
3957
+ }), a;
3958
+ const r = Object.keys(ni.shape);
3959
+ for (const t of r) {
3960
+ const n = u[t] ?? null, i = c[t] ?? null;
3961
+ L.isEqual(n, i) || a.push({
3962
+ type: H.ASSEMBLY_ITEM_UPDATED,
3963
+ message: K("Assembly Child Item", u.netSuiteId, t, i, n),
3964
+ data: {
3965
+ field: t,
3966
+ incomingValue: n,
3967
+ existingValue: i
3968
+ }
3969
+ });
3970
+ }
3971
+ return a;
3972
+ }
3973
+ g(ii, "detectAssemblyChildItemConflicts");
3974
+ function si(s) {
3975
+ const a = [], { incoming: u, current: c } = s;
3976
+ if (u.itemType !== V.Enum.Assembly)
3977
+ throw new Error("[detectAssemblyParentItemConflicts] only supports Assembly parent items");
3978
+ if (!c)
3979
+ return a.push({
3980
+ type: H.ASSEMBLY_ITEM_CREATED,
3981
+ message: `Assembly Parent Item [${u.netSuiteId}] config doesn't exist`,
3982
+ data: u
3983
+ }), a;
3984
+ const r = Object.keys(ti.shape);
3985
+ for (const n of r) {
3986
+ const i = u[n] ?? null, o = c[n] ?? null;
3987
+ L.isEqual(i, o) || a.push({
3988
+ type: H.ASSEMBLY_ITEM_UPDATED,
3989
+ message: K("Assembly Parent Item", u.netSuiteId, n, o, i),
3990
+ data: {
3991
+ field: n,
3992
+ incomingValue: i,
3993
+ existingValue: o
3994
+ }
3995
+ });
3996
+ }
3997
+ const t = Object.keys(ei.shape);
3998
+ for (const n of t) {
3999
+ const i = u.skuCache[n] ?? null, o = c.skuCache[n] ?? null;
4000
+ L.isEqual(i, o) || a.push({
4001
+ type: H.ASSEMBLY_ITEM_SKU_UPDATED,
4002
+ message: K("Assembly Parent Item", u.netSuiteId, n, o, i),
4003
+ data: {
4004
+ field: n,
4005
+ incomingValue: i,
4006
+ existingValue: o
4007
+ }
4008
+ });
4009
+ }
4010
+ return a;
4011
+ }
4012
+ g(si, "detectAssemblyParentItemConflicts");
4013
+ function ri(s, a, u) {
4014
+ if (a.itemType !== V.Enum.Assembly)
4015
+ throw new Error("[resolveAssemblyParentItemConflicts] only supports Assembly parent items");
4016
+ if (s.some((t) => t.type === H.ASSEMBLY_ITEM_CREATED))
4017
+ return a;
4018
+ let r = u;
4019
+ for (const t of s)
4020
+ if (t.type === H.ASSEMBLY_ITEM_UPDATED) {
4021
+ const n = t.data.field;
4022
+ r = {
4023
+ ...r,
4024
+ [n]: t.data.incomingValue
4025
+ };
4026
+ } else if (t.type === H.ASSEMBLY_ITEM_SKU_UPDATED) {
4027
+ const n = t.data.field;
4028
+ r = {
4029
+ ...r,
4030
+ skuCache: {
4031
+ ...r.skuCache,
4032
+ [n]: t.data.incomingValue
4033
+ }
4034
+ };
4035
+ }
4036
+ return r;
4037
+ }
4038
+ g(ri, "resolveAssemblyParentItemConflicts");
4039
+ function oi(s, a, u) {
4040
+ if (a.itemType !== V.Enum.Assembly)
4041
+ throw new Error("[resolveAssemblyChildItemConflicts] only supports Assembly child items");
4042
+ if (s.some((t) => t.type === H.ASSEMBLY_ITEM_CREATED))
4043
+ return a;
4044
+ let r = u;
4045
+ for (const t of s)
4046
+ if (t.type === H.ASSEMBLY_ITEM_UPDATED) {
4047
+ const n = t.data.field;
4048
+ r = {
4049
+ ...r,
4050
+ [n]: t.data.incomingValue
4051
+ };
4052
+ }
4053
+ return r;
4054
+ }
4055
+ g(oi, "resolveAssemblyChildItemConflicts");
4056
+ function ai(s, a, u, c, r) {
4057
+ const t = {}, n = {};
4058
+ for (const o of a) {
4059
+ const m = pe(r.sku ?? [], r.unit ?? [], c, o.item.items);
4060
+ t[o.id] = m;
4061
+ }
4062
+ for (const o of u) {
4063
+ const m = pe(r.sku ?? [], r.unit ?? [], c, o.item.items);
4064
+ n[o.id] = m;
4065
+ }
4066
+ return {
4067
+ orderItemMapping: pe(r.sku ?? [], r.unit ?? [], c, s.item.items),
4068
+ orderItemMappingByFulfillment: t,
4069
+ orderItemMappingByReceipt: n
4070
+ };
4071
+ }
4072
+ g(ai, "prepareTransferOrderTransformContext");
4073
+ function ui(s, a, u, c) {
4074
+ const r = {};
4075
+ for (const n of a) {
4076
+ const i = pe(c.sku ?? [], c.unit ?? [], u, n.item.items);
4077
+ r[n.id] = i;
4078
+ }
4079
+ return {
4080
+ orderItemMapping: pe(c.sku ?? [], c.unit ?? [], u, s.item.items),
4081
+ orderItemMappingByReceipt: r
4082
+ };
4083
+ }
4084
+ g(ui, "preparePurchaseOrderTransformContext");
4085
+ function di(s, a, u) {
4086
+ return {
4087
+ orderItemMapping: pe(u.sku ?? [], u.unit ?? [], a, s.inventory.items)
4088
+ };
4089
+ }
4090
+ g(di, "prepareInventoryTransferTransformContext");
4091
+ function ci(s, a) {
4092
+ const u = s;
4093
+ u.version = ee.Enum[1];
4094
+ const c = /* @__PURE__ */ new Set(), r = [], t = [];
4095
+ for (const n of u.items) {
4096
+ c.has(n.sku._id) && t.push(n.sku._id), c.add(n.sku._id);
4097
+ const i = {
4098
+ ...n
4099
+ };
4100
+ delete i.id, r.push(i);
4101
+ }
4102
+ if (t.length > 0)
4103
+ throw new Error(`Duplicate SKU found: ${t.join(", ")}`);
4104
+ return u.items = r, u.deliveryOrder = u.deliveryOrder.map((n) => {
4105
+ const i = {
4106
+ ...n
4107
+ };
4108
+ return i.received = i.received.map((o) => {
4109
+ const m = {
4110
+ ...o
4111
+ };
4112
+ return delete m.id, m;
4113
+ }), i;
4114
+ }), u.deliveryFullfillment && (u.deliveryFullfillment = u.deliveryFullfillment.map((n) => {
4115
+ const i = {
4116
+ ...n
4117
+ };
4118
+ return i.items = i.items.map((o) => {
4119
+ const m = {
4120
+ ...o
4121
+ };
4122
+ return delete m.id, m;
4123
+ }), i;
4124
+ })), {
4125
+ purchaseOrder: u,
4126
+ purchaseOrderRequest: a ? {
4127
+ ...a,
4128
+ purchaseOrder: u
4129
+ } : void 0
4130
+ };
4131
+ }
4132
+ g(ci, "transformPurchaseOrderToV1");
4133
+ function li(s, a) {
4134
+ const u = new Date(ie(s._id));
4135
+ if (J(u, a)) return !0;
4136
+ const c = s.deliveryFullfillment || [], r = s.deliveryOrder || [];
4137
+ for (const t of c) {
4138
+ const n = new Date(t.createdAt);
4139
+ if (J(n, a)) return !0;
4140
+ }
4141
+ for (const t of r) {
4142
+ const n = new Date(t.createdAt);
4143
+ if (J(n, a)) return !0;
4144
+ }
4145
+ return !1;
4146
+ }
4147
+ g(li, "shouldSyncOrderByTimestamp");
4148
+ function mi(s) {
4149
+ var a, u;
4150
+ return {
4151
+ name: s.name,
4152
+ netSuiteId: s.netSuiteId,
4153
+ itemType: s.itemType,
4154
+ unitTypeId: s.unitTypeId,
4155
+ unitOfMeasureId: s.unitOfMeasureId,
4156
+ subsidiaryIds: s.subsidiaryIds,
4157
+ includeChildren: s.includeChildren,
4158
+ externalId: s.externalId,
4159
+ pktCode: ((a = s.customFields) == null ? void 0 : a.pktCode) || null,
4160
+ pktName: ((u = s.customFields) == null ? void 0 : u.pktName) || null,
4161
+ parentNetSuiteId: null,
4162
+ cogsAccount: s.cogsAccount
4163
+ };
4164
+ }
4165
+ g(mi, "transformParentToFdoNetSuiteItem");
4166
+ function fi(s) {
4167
+ var a, u;
4168
+ return {
4169
+ name: s.name,
4170
+ netSuiteId: s.netSuiteId,
4171
+ itemType: s.itemType,
4172
+ unitTypeId: s.unitTypeId,
4173
+ unitOfMeasureId: s.unitOfMeasureId,
4174
+ subsidiaryIds: s.subsidiaryIds,
4175
+ includeChildren: s.includeChildren,
4176
+ externalId: s.externalId,
4177
+ pktCode: ((a = s.customFields) == null ? void 0 : a.pktCode) || null,
4178
+ pktName: ((u = s.customFields) == null ? void 0 : u.pktName) || null,
4179
+ parentNetSuiteId: s.parentNetSuiteId,
4180
+ cogsAccount: s.cogsAccount
4181
+ };
4182
+ }
4183
+ g(fi, "transformChildToFdoNetSuiteItem");
4184
+ const Se = Qt((s, a) => {
4185
+ const u = Me(), c = Xt();
4186
+ return a.onError(async (r) => {
4187
+ if (r instanceof Wt)
4188
+ throw c == null || c.open({
4189
+ title: r.title,
4190
+ message: r.message,
4191
+ type: "error"
4192
+ }), r;
4193
+ }), {
4194
+ async readSetting() {
4195
+ var n;
4196
+ const r = ((n = u.currentBusiness.value) == null ? void 0 : n._id) ?? "", t = `${s.netSuiteBackendUrl}/${r}/v2/settings`;
4197
+ return await a.get(t);
4198
+ },
4199
+ async updateLocationConfigs(r) {
4200
+ var i;
4201
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/settings/update-locations`;
4202
+ return await a.post(n, r);
4203
+ },
4204
+ async getNetSuiteLocationOptions() {
4205
+ var n;
4206
+ const r = ((n = u.currentBusiness.value) == null ? void 0 : n._id) ?? "", t = `${s.netSuiteBackendUrl}/${r}/v2/location/options`;
4207
+ return await a.get(t);
4208
+ },
4209
+ async getNetSuiteLocation() {
4210
+ var n;
4211
+ const r = ((n = u.currentBusiness.value) == null ? void 0 : n._id) ?? "", t = `${s.netSuiteBackendUrl}/${r}/location/browse`;
4212
+ return await a.get(t);
4213
+ },
4214
+ async manualSyncInventoryTransfer(r) {
4215
+ var i;
4216
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/api/${t}/${r}/inventory-transfer-sync`;
4217
+ return await a.post(n);
4218
+ },
4219
+ async syncPurchaseOrder(r, t) {
4220
+ const n = `${s.netSuiteBackendUrl}/api/${r}/po-sync`;
4221
+ return await a.post(n, {
4222
+ purchaseOrderId: t
4223
+ });
4224
+ },
4225
+ async getItemAverageCosts(r) {
4226
+ var i;
4227
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/inventory-item/${r}/average-cost`;
4228
+ return await a.post(n);
4229
+ },
4230
+ async createInventoryTransfer(r, t) {
4231
+ var o;
4232
+ const n = ((o = u.currentBusiness.value) == null ? void 0 : o._id) ?? "", i = `${s.netSuiteBackendUrl}/${n}/v2/inventory-transfer/${r}/create`;
4233
+ return await a.post(i, t);
4234
+ },
4235
+ async getInventoryTransferHistory(r, t, n) {
4236
+ var m;
4237
+ const i = ((m = u.currentBusiness.value) == null ? void 0 : m._id) ?? "", o = `${s.netSuiteBackendUrl}/${i}/v2/inventory-transfer/${r}/transfer-out-history`;
4238
+ return await a.post(o, {
4239
+ startDate: t == null ? void 0 : t.toISOString(),
4240
+ endDate: n == null ? void 0 : n.toISOString()
4241
+ });
4242
+ },
4243
+ async getSyncLogs(r) {
4244
+ const t = `${s.inventoryBackendUrl}/log/query?query=${encodeURIComponent(r)}`;
4245
+ return await a.get(t);
4246
+ },
4247
+ async getMoreInfo(r, t) {
4248
+ var o;
4249
+ const n = ((o = u.currentBusiness.value) == null ? void 0 : o._id) ?? "", i = `${s.netSuiteBackendUrl}/api/${n}/${r}/more-info`;
4250
+ return await a.post(i, {
4251
+ purchaseOrderId: t
4252
+ });
4253
+ },
4254
+ async getChangeLogs(r) {
4255
+ var i;
4256
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/system-note/${r}`;
4257
+ return await a.post(n, {}, AbortSignal.timeout(6e4));
4258
+ },
4259
+ async getUnSyncTransferInOrders(r) {
4260
+ var i;
4261
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/transfer-order-cron/unlink-transfer-in/${r}`;
4262
+ return await a.post(n);
4263
+ },
4264
+ async manualSyncMultipleTransferInOrders(r) {
4265
+ var i;
4266
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/transfer-order/sync-multiple`;
4267
+ return await a.post(n, {
4268
+ netsuiteIds: r
4269
+ });
4270
+ },
4271
+ async getUnSyncPurchaseOrders(r) {
4272
+ var i;
4273
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/purchase-order-cron/unlink-purchase-order/${r}`;
4274
+ return await a.post(n);
4275
+ },
4276
+ async manualSyncMultiplePurchaseOrders(r) {
4277
+ var i;
4278
+ const t = ((i = u.currentBusiness.value) == null ? void 0 : i._id) ?? "", n = `${s.netSuiteBackendUrl}/${t}/v2/purchase-order/sync-multiple`;
4279
+ return await a.post(n, {
4280
+ netsuiteIds: r
4281
+ });
4282
+ },
4283
+ urls: s
4284
+ };
4285
+ }), Ii = { class: "flex flex-col" }, pi = { class: "text-sm" }, gi = { class: "text-sm" }, Ei = { class: "text-sm" }, yi = { class: "flex flex-col gap-2 mt-2" }, _i = { class: "text-xs" }, bi = { class: "text-xs" }, Si = { class: "text-xs" }, vi = { class: "text-xs" }, Ti = {
4286
+ key: 0,
4287
+ class: "text-xs"
4288
+ }, hi = {
4289
+ key: 0,
4290
+ class: "text-sm text-gray-400"
4291
+ }, Di = {
4292
+ key: 0,
4293
+ class: "mt-2 flex flex-col"
4294
+ }, Ni = { class: "text-xs text-gray-400" }, Ci = { class: "text-xs text-gray-400" }, Ai = { class: "text-xs text-gray-400" }, Mi = { class: "text-xs text-gray-400" }, Ui = {
4295
+ key: 0,
4296
+ class: "text-xs text-gray-400"
4297
+ }, Fi = {
4298
+ class: "flex flex-col w-full gap-2",
4299
+ style: { "margin-left": "15px" }
4300
+ }, ki = { class: "flex flex-col gap-3" }, wi = /* @__PURE__ */ en({
4301
+ __name: "NetSuiteCustomCodeSelection",
4302
+ props: {
4303
+ readonly: { type: Boolean },
4304
+ sku: {},
4305
+ settingOptions: {}
4306
+ },
4307
+ emits: ["update:modelValue"],
4308
+ setup(s, { emit: a }) {
4309
+ const u = s, c = a, r = He(!1), t = le(() => u.sku._id ? i.customFieldOptions[u.sku._id] ?? [] : []), n = He({
4310
+ code: "",
4311
+ name: "",
4312
+ childName: ""
4313
+ }), i = Oi(), o = Me(), m = le(() => {
4314
+ var d;
4315
+ const f = `business_${((d = o.currentBusiness.value) == null ? void 0 : d._id) ?? ""}`;
4316
+ return $e[f].code;
4317
+ });
4318
+ function l(f) {
4319
+ return `Overwrite with "${f ?? "N/A"}"`;
4320
+ }
4321
+ return (f, d) => {
4322
+ const I = we("FmButton"), p = we("FmLabel"), E = we("FmSelect"), y = we("FmDialog");
4323
+ return z(), tn(y, {
4324
+ modelValue: r.value,
4325
+ "onUpdate:modelValue": d[4] || (d[4] = (_) => r.value = _),
4326
+ overlay: !0,
4327
+ dismissAway: !0
4328
+ }, {
4329
+ "dialog-button": re(() => [
4330
+ oe(I, {
4331
+ class: "delete-button",
4332
+ label: "NetSuite",
4333
+ type: "button",
4334
+ icon: "extension",
4335
+ variant: "secondary",
4336
+ size: "md",
4337
+ onClick: d[0] || (d[0] = () => {
4338
+ r.value = !0;
4339
+ })
4340
+ })
4341
+ ]),
4342
+ "dialog-header": re(() => d[5] || (d[5] = [
4343
+ M("div", null, "NetSuite Custom Info", -1)
4344
+ ])),
4345
+ "dialog-footer": re(() => [
4346
+ M("div", Fi, [
4347
+ f.readonly ? Ae("", !0) : (z(), ae(Re, { key: 0 }, [
4348
+ d[17] || (d[17] = M("span", { class: "text-sm mb-2 font-bold" }, " This will overwrite the code and uom only.", -1)),
4349
+ M("div", ki, [
4350
+ oe(I, {
4351
+ class: "sm:w-full xs:w-full",
4352
+ label: l(n.value.code),
4353
+ size: "md",
4354
+ variant: "destructive",
4355
+ onClick: d[2] || (d[2] = () => {
4356
+ r.value = !1;
4357
+ const _ = u.sku.unit.measurements.find(
4358
+ (S) => S.id === n.value.fmMeasurementId
4359
+ );
4360
+ c("update:modelValue", u.sku, n.value.code, _);
4361
+ })
4362
+ }, null, 8, ["label"])
4363
+ ])
4364
+ ], 64)),
4365
+ oe(I, {
4366
+ class: "ml-auto sm:w-full xs:w-full",
4367
+ label: "Close",
4368
+ size: "md",
4369
+ variant: "primary",
4370
+ onClick: d[3] || (d[3] = (_) => r.value = !1)
4371
+ })
4372
+ ])
4373
+ ]),
4374
+ default: re(() => [
4375
+ M("div", null, [
4376
+ M("div", Ii, [
4377
+ oe(p, null, {
4378
+ default: re(() => d[6] || (d[6] = [
4379
+ Q("Code")
4380
+ ])),
4381
+ _: 1
4382
+ }),
4383
+ M("span", pi, x(f.sku.code), 1),
4384
+ oe(p, null, {
4385
+ default: re(() => d[7] || (d[7] = [
4386
+ Q("Name")
4387
+ ])),
4388
+ _: 1
4389
+ }),
4390
+ M("span", gi, x(f.sku.name), 1),
4391
+ oe(p, null, {
4392
+ default: re(() => d[8] || (d[8] = [
4393
+ Q("Unit")
4394
+ ])),
4395
+ _: 1
4396
+ }),
4397
+ M("span", Ei, x(f.sku.unit.name), 1)
4398
+ ]),
4399
+ f.readonly ? (z(), ae(Re, { key: 0 }, [
4400
+ d[14] || (d[14] = M("hr", { class: "my-2" }, null, -1)),
4401
+ oe(p, null, {
4402
+ default: re(() => d[9] || (d[9] = [
4403
+ Q("Custom Codes")
4404
+ ])),
4405
+ _: 1
4406
+ }),
4407
+ M("div", yi, [
4408
+ (z(!0), ae(Re, null, nn(t.value, (_, S) => (z(), ae("div", {
4409
+ key: S,
4410
+ class: "rounded border-1 flex flex-col p-2"
4411
+ }, [
4412
+ M("span", _i, [
4413
+ d[10] || (d[10] = M("b", null, "Child Name:", -1)),
4414
+ Q(" " + x(_.value.childName), 1)
4415
+ ]),
4416
+ M("span", bi, [
4417
+ M("b", null, "Custom code (" + x(m.value ? ct(dt)(m.value) : "N/A") + "):", 1),
4418
+ Q(" " + x(_.value.code), 1)
4419
+ ]),
4420
+ M("span", Si, [
4421
+ d[11] || (d[11] = M("b", null, "Custom name:", -1)),
4422
+ Q(" " + x(_.value.name), 1)
4423
+ ]),
4424
+ M("span", vi, [
4425
+ d[12] || (d[12] = M("b", null, "UOM:", -1)),
4426
+ Q(" " + x(_.value.fmMeasurementAbbrev ?? u.sku.unit.abbrev), 1)
4427
+ ]),
4428
+ _.value.remark ? (z(), ae("span", Ti, [
4429
+ d[13] || (d[13] = M("b", null, "Remark:", -1)),
4430
+ Q(" " + x(_.value.remark), 1)
4431
+ ])) : Ae("", !0)
4432
+ ]))), 128)),
4433
+ t.value.length === 0 ? (z(), ae("span", hi, "No custom code found.")) : Ae("", !0)
4434
+ ])
4435
+ ], 64)) : (z(), ae(Re, { key: 1 }, [
4436
+ d[16] || (d[16] = M("hr", { class: "my-2" }, null, -1)),
4437
+ oe(p, null, {
4438
+ default: re(() => d[15] || (d[15] = [
4439
+ Q("Custom Code")
4440
+ ])),
4441
+ _: 1
4442
+ }),
4443
+ oe(E, {
4444
+ modelValue: n.value,
4445
+ "onUpdate:modelValue": d[1] || (d[1] = (_) => n.value = _),
4446
+ items: t.value,
4447
+ placeholder: "Select NetSuite Custom Code",
4448
+ class: "w-full mt-2"
4449
+ }, null, 8, ["modelValue", "items"]),
4450
+ n.value ? (z(), ae("div", Di, [
4451
+ M("span", Ni, "Child Name: " + x(n.value.childName), 1),
4452
+ M("span", Ci, "Custom code (" + x(m.value ? ct(dt)(m.value) : "N/A") + "): " + x(n.value.code), 1),
4453
+ M("span", Ai, "Custom name: " + x(n.value.name), 1),
4454
+ M("span", Mi, "UOM: " + x(n.value.fmMeasurementAbbrev ?? u.sku.unit.abbrev), 1),
4455
+ n.value.remark ? (z(), ae("span", Ui, "Remark: " + x(n.value.remark), 1)) : Ae("", !0)
4456
+ ])) : Ae("", !0)
4457
+ ], 64))
4458
+ ])
4459
+ ]),
4460
+ _: 1
4461
+ }, 8, ["modelValue"]);
4462
+ };
4463
+ }
4464
+ }), $e = {
4465
+ /// TH - Zus (Dev)
4466
+ business_67e6a27d0d160c001c0fb938: {
4467
+ code: "pktCode",
4468
+ name: "pktName"
4469
+ },
4470
+ /// TH - Zus (Prod)
4471
+ business_685cf259edad89001c7c44b0: {
4472
+ code: "pktCode",
4473
+ name: "pktName"
4474
+ },
4475
+ /// MY - Zus (Dev)
4476
+ business_671005de24a7f4001c87e25e: {
4477
+ code: "externalId",
4478
+ name: "name"
4479
+ },
4480
+ /// MY - Zus (Prod)
4481
+ business_6776a1fe205a52001c516efa: {
4482
+ code: "externalId",
4483
+ name: "name"
4484
+ }
4485
+ };
4486
+ function Ri() {
4487
+ return {
4488
+ setting: {
4489
+ _id: "",
4490
+ items: [],
4491
+ childItems: [],
4492
+ units: [],
4493
+ locations: [],
4494
+ subsidiaries: [],
4495
+ vendors: [],
4496
+ enable: !1,
4497
+ syncedAt: null
4498
+ },
4499
+ vendorSubsidiary: {},
4500
+ skuSubsidiaries: {},
4501
+ isReady: !1,
4502
+ skuOptions: {},
4503
+ businessSubsidiaryName: ""
4504
+ };
4505
+ }
4506
+ const T = He(Ri());
4507
+ function Oi() {
4508
+ const s = Zt(), a = le(() => T.value.setting.items.groupBy("netSuiteId", (i) => i.id)), u = le(() => T.value.setting.units.flatMap((i) => i.measurements).groupBy("netSuiteId", (i) => i.id)), c = le(() => T.value.setting.items.groupBy((i) => i.id)), r = le(
4509
+ () => T.value.setting.units.groupBy(
4510
+ (i) => i.netSuiteId,
4511
+ (i) => s.unitById[i.id]
4512
+ )
4513
+ ), t = le(
4514
+ () => Li({
4515
+ units: s.unitById,
4516
+ skus: s.skus,
4517
+ settingOptions: T.value.skuOptions,
4518
+ customFields: Pi
4519
+ })
4520
+ ), n = le(
4521
+ () => T.value.setting.units.flatMap(
4522
+ (i) => i.measurements.map((o) => {
4523
+ var m;
4524
+ return {
4525
+ unit: (m = r.value.get(i.netSuiteId)) == null ? void 0 : m[0],
4526
+ measurement: o
4527
+ };
4528
+ })
4529
+ ).groupBy(
4530
+ (i) => i.measurement.netSuiteId,
4531
+ (i) => {
4532
+ var o;
4533
+ return (o = i.unit) == null ? void 0 : o.measurements.find((m) => m.id === i.measurement.id);
4534
+ }
4535
+ )
4536
+ );
4537
+ return {
4538
+ get customFieldOptions() {
4539
+ return t.value;
4540
+ },
4541
+ async checkCustomFieldCodes(i) {
4542
+ i.beforeStart && await i.beforeStart();
4543
+ const o = {};
4544
+ for (let m = 0; m < i.templateItems.length; m++) {
4545
+ const l = i.templateItems[m], f = s.skuById[l.sku._id];
4546
+ if (!f) {
4547
+ o[m] = "Invalid record. Please remove this row.";
4548
+ continue;
4549
+ }
4550
+ if (!L.isEqual(f, l.sku)) {
4551
+ o[m] = "Record is outdated. Please re-apply the item.";
4552
+ continue;
4553
+ }
4554
+ const d = t.value[f._id];
4555
+ if (!d)
4556
+ continue;
4557
+ const I = l.measurement, p = l.code;
4558
+ if (!d.find(
4559
+ (y) => y.value.code === p && y.value.fmMeasurementId === (I == null ? void 0 : I.id)
4560
+ )) {
4561
+ if (!I) {
4562
+ o[m] = `Invalid custom code "${p}" for base unit "${f.unit.abbrev}".`;
4563
+ continue;
4564
+ }
4565
+ o[m] = `Invalid custom code "${p}" for measurement "${I == null ? void 0 : I.abbrev}".`;
4566
+ continue;
4567
+ }
4568
+ }
4569
+ return o;
4570
+ },
4571
+ transferTemplateColumnDefs(i) {
4572
+ return this.isEnabled ? {
4573
+ 0: {
4574
+ id: "netsuite-verify",
4575
+ cell: (o) => {
4576
+ const m = s.skuById[o.row.original.sku._id];
4577
+ return sn(wi, {
4578
+ sku: m,
4579
+ settingOptions: T.value.skuOptions,
4580
+ "onUpdate:modelValue": (l, f, d) => {
4581
+ i.onUpdate(o.row.index, l, f, d);
4582
+ }
4583
+ });
4584
+ }
4585
+ }
4586
+ } : {};
4587
+ },
4588
+ get skuSettingOptions() {
4589
+ return T.value.skuOptions;
4590
+ },
4591
+ // state
4592
+ get inventoryTransferOutEnabled() {
4593
+ return rn().isNetSuiteInventoryTransferOutEnabled;
4594
+ },
4595
+ get isReady() {
4596
+ return T.value.isReady;
4597
+ },
4598
+ get isEnabled() {
4599
+ return T.value.setting.enable;
4600
+ },
4601
+ get isBusinessLocation() {
4602
+ return Ce().businessLevel;
4603
+ },
4604
+ get businessSubsidiaryId() {
4605
+ return T.value.setting.subsidiaryId;
4606
+ },
4607
+ get businessSubsidiaryName() {
4608
+ return T.value.businessSubsidiaryName;
4609
+ },
4610
+ get state() {
4611
+ return T.value;
4612
+ },
4613
+ get netSuiteItemIdToSkuId() {
4614
+ return a.value;
4615
+ },
4616
+ get netSuiteMeasurementIdToMeasurementId() {
4617
+ return u.value;
4618
+ },
4619
+ get netSuiteItemBySkuId() {
4620
+ return c.value;
4621
+ },
4622
+ get unitByNetsuiteId() {
4623
+ return r.value;
4624
+ },
4625
+ get measurementByNetsuiteId() {
4626
+ return n.value;
4627
+ },
4628
+ get configuredLocations() {
4629
+ return T.value.setting.locations;
4630
+ },
4631
+ get currentLocationSetting() {
4632
+ const o = Ce().currentLocationDBName;
4633
+ return this.getNetSuiteLocation(o);
4634
+ },
4635
+ get isCurrentLocationBindedToNetSuite() {
4636
+ return this.currentLocationSetting !== void 0;
4637
+ },
4638
+ getNetSuiteVendor(i) {
4639
+ return T.value.setting.vendors.find((o) => o.id === i);
4640
+ },
4641
+ getNetSuiteLocation(i) {
4642
+ const [o, m] = i.split("_");
4643
+ return T.value.setting.locations.find((f) => f.id == m && f.type == o);
4644
+ },
4645
+ getSubsidiaryFullName(i) {
4646
+ if (!i)
4647
+ return {
4648
+ id: void 0,
4649
+ name: "",
4650
+ fullName: ""
4651
+ };
4652
+ const { flat: o } = Z(T.value.setting.subsidiaries), m = o.find((l) => l.id === i);
4653
+ return {
4654
+ id: m == null ? void 0 : m.id,
4655
+ name: (m == null ? void 0 : m.name) || "",
4656
+ fullName: `${(m == null ? void 0 : m.fullName) ?? ""}`
4657
+ };
4658
+ },
4659
+ getLocationSubsidiary(i) {
4660
+ var f;
4661
+ if (!i)
4662
+ return {
4663
+ id: void 0,
4664
+ name: "",
4665
+ fullName: ""
4666
+ };
4667
+ const o = ((f = T.value.setting.locations.find((d) => d.netSuiteId === i)) == null ? void 0 : f.subsidiaryId) ?? null, { flat: m } = Z(T.value.setting.subsidiaries), l = m.find((d) => d.id === o);
4668
+ return {
4669
+ id: l == null ? void 0 : l.id,
4670
+ name: (l == null ? void 0 : l.name) || "",
4671
+ fullName: `${(l == null ? void 0 : l.fullName) ?? ""}`
4672
+ };
4673
+ },
4674
+ currentLocationSubsidiary() {
4675
+ var I;
4676
+ const i = Ce(), o = i.currentLocation.doc._id, m = i.currentLocation.type, l = ((I = T.value.setting.locations.find(
4677
+ (p) => p.id === o && p.type == m
4678
+ )) == null ? void 0 : I.subsidiaryId) ?? null, { flat: f } = Z(T.value.setting.subsidiaries), d = f.find((p) => p.id === l);
4679
+ return {
4680
+ id: d == null ? void 0 : d.id,
4681
+ name: (d == null ? void 0 : d.name) || "",
4682
+ fullName: `${(d == null ? void 0 : d.fullName) ?? ""}`
4683
+ };
4684
+ },
4685
+ currentVendorSubsidiary(i) {
4686
+ var f;
4687
+ const o = ((f = T.value.setting.vendors.find((d) => d.id === i)) == null ? void 0 : f.subsidiaryId) ?? null, { flat: m } = Z(T.value.setting.subsidiaries), l = m.find((d) => d.id === o);
4688
+ return {
4689
+ id: l == null ? void 0 : l.id,
4690
+ name: (l == null ? void 0 : l.name) || "",
4691
+ fullName: `${(l == null ? void 0 : l.fullName) ?? ""}`
4692
+ };
4693
+ },
4694
+ get subsidiaryOptions() {
4695
+ const { flat: i } = Z(T.value.setting.subsidiaries);
4696
+ return i.map((o) => ({
4697
+ label: `${"   ".repeat(o.depth)}${o.name}`,
4698
+ value: {
4699
+ id: o.id,
4700
+ name: o.name
4701
+ }
4702
+ }));
4703
+ },
4704
+ getBusinessSubsidiaryTree() {
4705
+ const { tree: i } = Z(
4706
+ T.value.setting.subsidiaries,
4707
+ T.value.setting.subsidiaryId
4708
+ );
4709
+ return i;
4710
+ },
4711
+ getBusinessSubsidiaryPath() {
4712
+ if (!T.value.setting.subsidiaryId)
4713
+ return [];
4714
+ const { flat: i } = Z(T.value.setting.subsidiaries), o = [];
4715
+ let m = T.value.setting.subsidiaryId;
4716
+ for (; m; ) {
4717
+ o.unshift(m);
4718
+ const l = i.find((f) => f.id === m);
4719
+ m = l == null ? void 0 : l.parentId;
4720
+ }
4721
+ return o;
4722
+ },
4723
+ getAvailableItems(i) {
4724
+ const { available: o, flatMapping: m } = Z(
4725
+ T.value.setting.subsidiaries,
4726
+ i
4727
+ );
4728
+ return T.value.setting.items.filter(
4729
+ (l) => l.subsidiaryIds.some((f) => l.includeChildren && m[f] && m[f].some((d) => o.includes(d)) || o.includes(f))
4730
+ ).map((l) => l.id);
4731
+ },
4732
+ getAvailableMeasurements(i, o) {
4733
+ const m = T.value.setting.items.find((d) => d.id === i);
4734
+ if (!m)
4735
+ return [];
4736
+ const { available: l, flatMapping: f } = Z(
4737
+ T.value.setting.subsidiaries,
4738
+ o
4739
+ );
4740
+ if (m.includeChildren) {
4741
+ const I = T.value.setting.childItems.filter((p) => {
4742
+ let E = p.subsidiaryIds;
4743
+ if (p.includeChildren == !0)
4744
+ for (const y of p.subsidiaryIds)
4745
+ E = E.concat(f[y]);
4746
+ return E = [...new Set(E)], p.parentNetSuiteId === m.netSuiteId && console.log(p), p.parentNetSuiteId === m.netSuiteId && E.some((y) => l.includes(y));
4747
+ }).flatMap((p) => p.unitTypeId);
4748
+ return T.value.setting.units.filter((p) => I.includes(p.netSuiteId)).flatMap((p) => p.measurements).map((p) => p.id);
4749
+ }
4750
+ return T.value.setting.units.filter((d) => d.netSuiteId === m.unitTypeId).flatMap((d) => d.measurements).map((d) => d.id);
4751
+ },
4752
+ async readSetting() {
4753
+ var m;
4754
+ const o = await Se().readSetting();
4755
+ if (o) {
4756
+ if (this.state.setting = o, (m = T.value.setting.subsidiaries) != null && m.length) {
4757
+ const { flat: f, tree: d } = Z(T.value.setting.subsidiaries);
4758
+ for (const p of o.vendors) {
4759
+ const E = f.find((y) => y.id === p.subsidiaryId);
4760
+ this.state.vendorSubsidiary[p.id] = (E == null ? void 0 : E.fullName) || "";
4761
+ }
4762
+ for (const p of o.items) {
4763
+ const E = [];
4764
+ for (const _ of p.subsidiaryIds) {
4765
+ const S = f.find((v) => v.id === _);
4766
+ S && E.push(S.fullName || "");
4767
+ }
4768
+ const y = $t(
4769
+ d,
4770
+ p.subsidiaryIds,
4771
+ p.includeChildren
4772
+ );
4773
+ this.state.skuSubsidiaries[p.id] = {
4774
+ includeChildren: p.includeChildren,
4775
+ flattenedSubsidiaryNames: E,
4776
+ subsidiaryTree: y
4777
+ };
4778
+ }
4779
+ const I = f.find((p) => p.id === T.value.setting.subsidiaryId);
4780
+ this.state.businessSubsidiaryName = (I == null ? void 0 : I.fullName) || "";
4781
+ }
4782
+ const l = T.value.setting.units.reduce(
4783
+ (f, d) => (f[d.netSuiteId] = d, f),
4784
+ {}
4785
+ );
4786
+ this.state.skuOptions = T.value.setting.items.reduce(
4787
+ (f, d) => (f[d.id] = {
4788
+ item: d,
4789
+ childItems: T.value.setting.childItems.filter(
4790
+ (I) => I.parentNetSuiteId === d.netSuiteId
4791
+ ),
4792
+ unit: l[d.unitTypeId] || {
4793
+ id: "ERROR",
4794
+ measurements: [
4795
+ {
4796
+ id: "ERROR",
4797
+ netSuiteId: "ERROR"
4798
+ }
4799
+ ],
4800
+ netSuiteId: "ERROR",
4801
+ baseUnitUnitOfMeasureId: "ERROR"
4802
+ },
4803
+ units: l
4804
+ }, f),
4805
+ {}
4806
+ );
4807
+ }
4808
+ this.state.isReady = !0;
4809
+ },
4810
+ async updateLocationConfigs(i) {
4811
+ const m = await Se().updateLocationConfigs(i);
4812
+ m && (this.state.setting = m);
4813
+ },
4814
+ async getNetSuiteLocations() {
4815
+ const o = await Se().getNetSuiteLocation();
4816
+ return console.log(o), o;
4817
+ },
4818
+ getVendorSubsidiaryName(i) {
4819
+ return this.state.vendorSubsidiary[i] || "";
4820
+ },
4821
+ getSkuSubsidiaries(i) {
4822
+ return this.state.skuSubsidiaries[i] || {
4823
+ includeChildren: !1,
4824
+ flattenedSubsidiaryNames: [],
4825
+ subsidiaryTree: []
4826
+ };
4827
+ },
4828
+ async syncPurchaseOrder(i, o) {
4829
+ const m = Se();
4830
+ let l = o;
4831
+ if (!l) {
4832
+ const f = Ce(), d = f.currentLocation.doc._id;
4833
+ l = `${f.currentLocation.type}_${d}`;
4834
+ }
4835
+ await m.syncPurchaseOrder(l, i);
4836
+ },
4837
+ getItemCustomCode(i, o) {
4838
+ var p;
4839
+ const l = `business_${((p = Me().currentBusiness.value) == null ? void 0 : p._id) ?? ""}`, f = $e[l].code, d = c.value.get(i._id);
4840
+ let I = null;
4841
+ if (d && d.length > 0) {
4842
+ const E = d[0];
4843
+ E[f] && (I = E[f]);
4844
+ const y = T.value.setting.units.find((S) => {
4845
+ var v;
4846
+ return S.id === ((v = i.unit) == null ? void 0 : v._id);
4847
+ }), _ = E.netSuiteId;
4848
+ if (o) {
4849
+ const S = y == null ? void 0 : y.measurements.find((v) => v.id === o);
4850
+ if (S) {
4851
+ const v = ["ZPH"], D = T.value.setting.childItems.filter(
4852
+ (b) => b.parentNetSuiteId === _ && b.unitTypeId === (y == null ? void 0 : y.netSuiteId) && b.unitOfMeasureId === S.netSuiteId && b.externalId && !v.some((A) => {
4853
+ var F;
4854
+ return (F = b.externalId) == null ? void 0 : F.startsWith(A);
4855
+ })
4856
+ )[0];
4857
+ D && D[f] && (I = D[f]);
4858
+ }
4859
+ }
4860
+ }
4861
+ return I;
4862
+ },
4863
+ async getNetSuiteLocationOptions() {
4864
+ return await Se().getNetSuiteLocationOptions();
4865
+ },
4866
+ async getItemAverageCosts() {
4867
+ const i = Se(), m = Ce().currentLocation.doc._id;
4868
+ return await i.getItemAverageCosts(m);
4869
+ }
4870
+ };
4871
+ }
4872
+ function $t(s, a, u) {
4873
+ return s.map((c) => {
4874
+ const r = a.includes(c.id), t = $t(c.children, a);
4875
+ return { ...c, children: t, isAssigned: r };
4876
+ }).filter(Boolean);
4877
+ }
4878
+ function Z(s, a) {
4879
+ const u = [], c = [];
4880
+ function r(o, m, l = !1) {
4881
+ return s.filter((d) => d.parentId === m).map((d) => ((l || d.id === a || !a) && u.push(d.id), {
4882
+ id: d.id,
4883
+ name: d.name,
4884
+ country: d.country,
4885
+ currency: d.currency,
4886
+ parentId: d.parentId,
4887
+ depth: o,
4888
+ children: r(o + 1, d.id, l || d.id === a)
4889
+ }));
4890
+ }
4891
+ const t = r(0, null), n = {};
4892
+ function i(o, m = "") {
4893
+ const l = o.fullName || o.name, f = m ? `${m} : ${l}` : l;
4894
+ c.push({ ...o, fullName: f }), n[o.id] = [o.id];
4895
+ for (const d of o.children)
4896
+ i(d, f), n[o.id].push(...n[d.id]);
4897
+ }
4898
+ return t.forEach((o) => i(o)), {
4899
+ tree: t,
4900
+ available: u,
4901
+ flat: c,
4902
+ flatMapping: n
4903
+ };
4904
+ }
4905
+ function Li(s) {
4906
+ function a(i, o, m) {
4907
+ const l = u[i];
4908
+ return l(o, m);
4909
+ }
4910
+ const { customFields: u, skus: c, settingOptions: r, units: t } = s, n = {};
4911
+ for (const i of c) {
4912
+ const o = r[i._id], m = a("name", o.item), l = a("code", o.item), f = {
4913
+ label: `${i.name} (${l})`,
4914
+ value: {
4915
+ code: l,
4916
+ name: m,
4917
+ childName: "-",
4918
+ externalId: o.item.externalId || ""
4919
+ }
4920
+ }, d = o.childItems.reduce(
4921
+ (I, p) => {
4922
+ const E = a("code", void 0, p), y = a("name", void 0, p), _ = o.unit.measurements.find(
4923
+ (b) => b.netSuiteId === p.unitOfMeasureId
4924
+ );
4925
+ let S = i.unit.measurements.find((b) => b.id === (_ == null ? void 0 : _.id)), v, N = S == null ? void 0 : S.abbrev;
4926
+ if (!_) {
4927
+ const b = o.units[p.unitTypeId];
4928
+ if (b) {
4929
+ const A = t[b.id], F = b == null ? void 0 : b.measurements.find(
4930
+ (U) => U.netSuiteId === p.unitOfMeasureId
4931
+ ), k = A == null ? void 0 : A.measurements.find(
4932
+ (U) => U.id === (F == null ? void 0 : F.id)
4933
+ );
4934
+ if (k) {
4935
+ const U = i.unit.measurements.find(
4936
+ (B) => B.name === k.name
4937
+ );
4938
+ U ? (N = `${U == null ? void 0 : U.abbrev} ⚠️`, S = U) : N = `Fallback to "${i.unit.abbrev}" (⚠️ Not match with any measurement name)`, v = `UOM "${k.abbrev}" is from "${A.name}"`;
4939
+ }
4940
+ }
4941
+ }
4942
+ const D = p.name || "N/A (childName not found)";
4943
+ return I.push({
4944
+ label: `${D} (${E})`,
4945
+ value: {
4946
+ code: E,
4947
+ name: y,
4948
+ childName: D,
4949
+ externalId: p.externalId || "N/A (externalId not found)",
4950
+ fmMeasurementId: S == null ? void 0 : S.id,
4951
+ fmMeasurementAbbrev: N,
4952
+ remark: v
4953
+ }
4954
+ }), I;
4955
+ },
4956
+ [f]
4957
+ );
4958
+ n[i._id] = d;
4959
+ }
4960
+ return n;
4961
+ }
4962
+ const Pi = {
4963
+ code: (s, a) => {
4964
+ var t;
4965
+ const c = `business_${((t = Me().currentBusiness.value) == null ? void 0 : t._id) ?? ""}`, r = $e[c].code;
4966
+ return s && s[r] ? s[r] : a && a[r] ? a[r] : "N/A";
4967
+ },
4968
+ name: (s, a) => {
4969
+ var t;
4970
+ const c = `business_${((t = Me().currentBusiness.value) == null ? void 0 : t._id) ?? ""}`, r = $e[c].name;
4971
+ return s && s[r] ? s[r] : a && a[r] ? a[r] : "N/A";
4972
+ }
4973
+ };
4974
+ export {
4975
+ Ke as S,
4976
+ wi as _,
4977
+ Se as a,
4978
+ Oi as u
4979
+ };