@feedmepos/mf-inventory-portal 1.2.30-dev.1 → 1.2.30

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