@feedmepos/mf-inventory-portal 1.2.7 → 1.2.8

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 (86) hide show
  1. package/dist/{App-BtLCesbn.js → App-D1IJlQS8.js} +1 -1
  2. package/dist/{ApprovalView-Ba4XBhGf.js → ApprovalView-GnDYWZHY.js} +69 -68
  3. package/dist/{BindingsDialog-BbBUniCu.js → BindingsDialog-Bs00N9mp.js} +2 -2
  4. package/dist/{BindingsPicker-C3q3ROku.js → BindingsPicker-LO15pMdZ.js} +1 -1
  5. package/dist/{BindingsTable-BTxWMif_.js → BindingsTable-g27KG9q4.js} +1 -1
  6. package/dist/{ClosingDraftView-DGITBnaY.js → ClosingDraftView-Ddsgcrmg.js} +203 -203
  7. package/dist/ClosingTemplateView-G8Ya81UZ.js +1862 -0
  8. package/dist/{DeliveryOrderPrintPreview-CUaHpblV.js → DeliveryOrderPrintPreview-qq1rhFKV.js} +8 -8
  9. package/dist/{FmAdminBadge-BdwGZY-f.js → FmAdminBadge-B2NpMmJi.js} +6 -6
  10. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-C1i9CHE1.js +230 -0
  11. package/dist/{FmMultiselectDialog-BETfHs3j.js → FmMultiselectDialog-u2dbuZUp.js} +1 -1
  12. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-BNdbeRQp.js → FmUnitInput.vue_vue_type_script_setup_true_lang-vpiiv6C1.js} +23 -23
  13. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-VYMMcwLl.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-3T-d1pIb.js} +1 -1
  14. package/dist/{IngredientGroupView-C4d9b3Td.js → IngredientGroupView-CqB73-e4.js} +12 -12
  15. package/dist/IngredientsView-Cq42ytcN.js +2291 -0
  16. package/dist/{IntegrationView-CWFzRDWO.js → IntegrationView-OHnUGZst.js} +4 -4
  17. package/dist/{InventoryBindingForm-Cx0Prlq8.js → InventoryBindingForm-DorgxR-Y.js} +1 -1
  18. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-cpR3Sf2Y.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-CZy77tY7.js} +41 -41
  19. package/dist/{InventoryBindingSummary-l8XvpxVU.js → InventoryBindingSummary-B_YavyPb.js} +1 -1
  20. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BjRvIX-v.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-XuEDo134.js} +1 -1
  21. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-gjuZveKy.js → PremiumBadge.vue_vue_type_script_setup_true_lang-Blq1oE5l.js} +11 -11
  22. package/dist/{PublishView-D2iUnDan.js → PublishView-Ds_ztGcV.js} +14 -14
  23. package/dist/{PurchaseOrderPrintPreview-DdLvM-wt.js → PurchaseOrderPrintPreview-DnyqN_xE.js} +11 -11
  24. package/dist/{ReceiveRequestView-DpF5ZzvH.js → ReceiveRequestView-ChpKsDaF.js} +148 -145
  25. package/dist/{RecipeView-Dvtm8o1Y.js → RecipeView-Dyp9Xcme.js} +49 -49
  26. package/dist/StockView-D-iP52Zw.js +2089 -0
  27. package/dist/{SupplierView-7GtIJ3Fz.js → SupplierView-BaEK3C8q.js} +1133 -1015
  28. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-B_ravTwn.js +3058 -0
  29. package/dist/{TransferTemplateView-Cmvg-yvW.js → TransferTemplateView-3zS7hNZz.js} +131 -130
  30. package/dist/{UnitView-DjVm1iVX.js → UnitView-BP5eztAG.js} +59 -59
  31. package/dist/WarehouseView-DMY7Lgwq.js +1066 -0
  32. package/dist/api/inventory.d.ts +8 -0
  33. package/dist/api/netsuite.d.ts +3 -0
  34. package/dist/api/purchase-order-template.d.ts +1 -0
  35. package/dist/api/purchase-order.d.ts +2 -0
  36. package/dist/api/shipment.d.ts +11 -0
  37. package/dist/api/warehouse.d.ts +3 -1
  38. package/dist/{app-Z-ylwRmy.js → app-P6XaUzjP.js} +17877 -17113
  39. package/dist/app.d.ts +96 -9
  40. package/dist/app.js +3 -3
  41. package/dist/closing-template-BGYZPBty.js +53 -0
  42. package/dist/components/FmInventoryTableToolbar.vue.d.ts +9 -2
  43. package/dist/components/netsuite/SubsidiaryTreeDialog.vue.d.ts +2 -0
  44. package/dist/{decimal-D1pJ2776.js → decimal-wz5HXhQ8.js} +1 -1
  45. package/dist/{format-unit-display-9BMm-8A4.js → format-unit-display-DOOJqLop.js} +372 -404
  46. package/dist/{index-BOl10vcm.js → index-CHTB43Wl.js} +1 -1
  47. package/dist/{index-rEIM0AVC.js → index-oR0svfBM.js} +1 -1
  48. package/dist/purchase-order-template-BGunGekw.js +41 -0
  49. package/dist/{stock-B8ewk80v.js → stock-TJayQnag.js} +1 -1
  50. package/dist/stores/feature.d.ts +10 -0
  51. package/dist/stores/integration/netsuite.d.ts +19 -0
  52. package/dist/stores/inventory.d.ts +1 -0
  53. package/dist/stores/location.d.ts +57 -1
  54. package/dist/stores/supplier.d.ts +96 -0
  55. package/dist/stores/warehouse.d.ts +4 -0
  56. package/dist/{supplier-DLSXYY1o.js → supplier-C_vqpE92.js} +1 -1
  57. package/dist/tsconfig.app.tsbuildinfo +1 -1
  58. package/dist/{use-ingredient-select-dialog-CTjwdY3T.js → use-ingredient-select-dialog-CIahwuTX.js} +5 -5
  59. package/dist/{use-inventory-binding-dialog-zXJB7MQY.js → use-inventory-binding-dialog-BiKRXVhY.js} +8 -8
  60. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +24 -0
  61. package/dist/views/ingredients/components/ingredient-form/IngredientFormProps.d.ts +6 -0
  62. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +2 -0
  63. package/dist/views/receive-request/components/delivery-order-form/CreateForm.vue.d.ts +16 -0
  64. package/dist/views/receive-request/components/delivery-order-form/CreateFormProps.d.ts +4 -0
  65. package/dist/views/receive-request/components/delivery-order-form/EditForm.vue.d.ts +16 -0
  66. package/dist/views/receive-request/components/delivery-order-form/EditFormProps.d.ts +4 -0
  67. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +1 -0
  68. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +60 -0
  69. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +10 -0
  70. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +94 -0
  71. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +72 -1
  72. package/dist/views/supplier/components/SupplierForm.vue.d.ts +8 -0
  73. package/dist/views/supplier/components/SupplierSupplyItemField.vue.d.ts +3 -0
  74. package/dist/views/supplier/composables/use-supplier-table.d.ts +4 -0
  75. package/dist/views/transfer-template/components/transfer-template-dialog/TransferTemplateDialog.vue.d.ts +8 -0
  76. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-locations.d.ts +16 -0
  77. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +48 -0
  78. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +48 -0
  79. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +8 -0
  80. package/package.json +3 -3
  81. package/dist/ClosingTemplateView-eRvwxXBq.js +0 -1908
  82. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-lDkElrkF.js +0 -227
  83. package/dist/IngredientsView-BvqWuIVT.js +0 -1876
  84. package/dist/StockView-CRDu_GQ_.js +0 -2086
  85. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-DbmLtbZt.js +0 -2494
  86. package/dist/WarehouseView-CBso3SXT.js +0 -1034
@@ -0,0 +1,2291 @@
1
+ import { ref as B, h as J, defineComponent as ye, computed as k, resolveComponent as S, openBlock as f, createBlock as D, withCtx as w, createVNode as p, unref as a, createElementBlock as E, Fragment as X, createElementVNode as d, createCommentVNode as H, renderSlot as Ve, createTextVNode as qe, toDisplayString as $, normalizeClass as ae, mergeModels as dt, onMounted as jt, watch as wt, useModel as Ht, renderList as ue, isRef as ct, createSlots as Tt, normalizeStyle as Wt, Teleport as mt, normalizeProps as Yt, guardReactiveProps as qt } from "vue";
2
+ import { a as de, e as W, f as Vt, S as Gt, b as Be, h as Kt, D as pt, i as $e, A as Pe, j as It, k as Ct, l as Oe, t as St, m as Jt, n as Ce, o as ze, U as Qt, p as Zt, M as Xt, q as vt, r as ft, c as Ge, s as Le, v as yt, w as en, x as gt, y as Ft, z as tn, B as Mt, C as nn, E as on, I as ln, G as an, H as sn, N as rn, J as un, u as dn, K as cn, _ as mn, L as pn, O as vn, P as bt, Q as fn } from "./app-P6XaUzjP.js";
3
+ import { useDialog as Ke, useSnackbar as Se, components as Re, useProxiedModel as ht, useDialogChild as yn, useBreakpoints as gn } from "@feedmepos/ui-library";
4
+ import { i as bn, _ as hn } from "./is-linked-ingredient-error-fJ2TJb3z.js";
5
+ import { useI18n as ge, useCoreStore as Fe } from "@feedmepos/mf-common";
6
+ import { defineStore as _n, storeToRefs as xn } from "pinia";
7
+ import { g as kn, _ as je, S as He } from "./StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js";
8
+ import { _ as wn } from "./InventoryBindingForm.vue_vue_type_script_setup_true_lang-CZy77tY7.js";
9
+ import { _ as We } from "./IngredientBindedItem.vue_vue_type_script_setup_true_lang-3T-d1pIb.js";
10
+ import { _ as fe } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-CRZiQHjx.js";
11
+ import { _ as Tn } from "./FmCustomAttribute.vue_vue_type_script_setup_true_lang-D-IWRjRD.js";
12
+ import { u as Et } from "./purchase-order-template-BGunGekw.js";
13
+ import { u as At } from "./closing-template-BGYZPBty.js";
14
+ import { r as Vn } from "./random-CSbEbElR.js";
15
+ import "./array-Ca8T3f_G.js";
16
+ import { u as In } from "./FmMultiselectDialog-u2dbuZUp.js";
17
+ const Ye = _n("ingredientForm", function() {
18
+ const o = Ke(), v = Se(), l = de(), c = B(!1), { t: g } = ge(), h = B();
19
+ function y() {
20
+ const i = {
21
+ unit: {},
22
+ mode: W.CREATE,
23
+ show: !0,
24
+ "onUpdate:show"(r) {
25
+ h.value.show = r;
26
+ }
27
+ };
28
+ h.value = i;
29
+ }
30
+ async function n(i) {
31
+ const r = {
32
+ unit: Vt(i),
33
+ mode: W.UPDATE,
34
+ show: !0,
35
+ "onUpdate:show"(T) {
36
+ h.value.show = T;
37
+ }
38
+ };
39
+ h.value = r;
40
+ }
41
+ async function s(i) {
42
+ c.value = !0;
43
+ try {
44
+ await l.deleteSku(i), v.open({
45
+ title: "Success",
46
+ message: `Deleted ${i.name}`,
47
+ type: "success"
48
+ });
49
+ } catch (r) {
50
+ r instanceof Gt && bn(r) ? o.open({
51
+ title: "Cannot delete ingredient",
52
+ contentComponent: hn,
53
+ contentComponentProps: {
54
+ subject: (i == null ? void 0 : i.name) ?? "",
55
+ items: r.errorResponse.message
56
+ },
57
+ secondaryActions: {
58
+ text: "Close",
59
+ close: !0
60
+ }
61
+ }) : console.log("unable to delete ingredient", r), v.open({
62
+ title: `Cannot delete ${i.name}`,
63
+ message: "Please try again.",
64
+ type: "error"
65
+ }), console.error("failed to delete ingredient", r);
66
+ } finally {
67
+ c.value = !1;
68
+ }
69
+ }
70
+ function m(i) {
71
+ o.open({
72
+ title: g("inventory.ingredient.delete.title", [(i == null ? void 0 : i.name) ?? ""]),
73
+ closeButton: !1,
74
+ message: g("inventory.ingredient.delete.message"),
75
+ primaryActions: {
76
+ text: g("common.delete"),
77
+ close: !0,
78
+ variant: "destructive"
79
+ },
80
+ secondaryActions: {
81
+ text: g("common.cancel"),
82
+ close: !0
83
+ }
84
+ }).onPrimary(() => s(i));
85
+ }
86
+ return {
87
+ createIngredient: y,
88
+ updateIngredient: n,
89
+ deleteIngredient: m,
90
+ ingredientDialogProps: h,
91
+ ingredientViewLoading: c
92
+ };
93
+ });
94
+ function Cn() {
95
+ const { updateIngredient: u, deleteIngredient: o } = Ye(), v = de(), l = Be(), { t: c } = ge();
96
+ async function g(y, n) {
97
+ const s = Vt(n);
98
+ if (y === $e.Edit) {
99
+ await u(s);
100
+ return;
101
+ }
102
+ if (y === $e.Delete) {
103
+ await o(s);
104
+ return;
105
+ }
106
+ }
107
+ return { columnDefs: [
108
+ {
109
+ accessorKey: "code",
110
+ header: () => c("inventory.ingredient.code"),
111
+ enableSorting: !0,
112
+ size: 300
113
+ },
114
+ {
115
+ accessorKey: "name",
116
+ header: () => c("inventory.ingredient.name"),
117
+ enableSorting: !0,
118
+ size: 300,
119
+ cell(y) {
120
+ const n = y.row.original, s = v.skuBindingFlattenCache[n._id], m = s == null ? void 0 : s.inventoryBindings.some(
121
+ (i) => "error" in i && i.reason === "circularDependency"
122
+ );
123
+ return J("div", { class: "flex items-center w-full gap-4" }, [
124
+ m ? J(
125
+ Re.FmTooltip,
126
+ { class: "text-left" },
127
+ {
128
+ default() {
129
+ return J(Re.FmIcon, {
130
+ name: "info",
131
+ color: "system-error-300",
132
+ size: "sm"
133
+ });
134
+ },
135
+ content() {
136
+ return c("inventory.inventoryBindings.circularError");
137
+ }
138
+ }
139
+ ) : null,
140
+ n.name
141
+ ]);
142
+ }
143
+ },
144
+ {
145
+ id: "unit",
146
+ header: () => c("inventory.ingredient.unit"),
147
+ accessorFn: (y) => _t(y),
148
+ cell(y) {
149
+ const n = y.row.original, s = _t(n);
150
+ return J(
151
+ Re.FmTooltip,
152
+ { zIndex: 51, content: s },
153
+ J(
154
+ "span",
155
+ {
156
+ class: "flex-auto line-clamp-2 text-ellipsis break-all"
157
+ },
158
+ s
159
+ )
160
+ );
161
+ },
162
+ enableSorting: !1,
163
+ size: "auto"
164
+ },
165
+ {
166
+ accessorKey: "isInactive",
167
+ header: () => c("inventory.ingredient.status.title"),
168
+ cell(y) {
169
+ const n = y.row.original.isInactive;
170
+ return J(
171
+ "span",
172
+ {
173
+ class: [
174
+ "inline-block px-3 py-1 rounded-full text-xs font-semibold",
175
+ n ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"
176
+ ].join(" ")
177
+ },
178
+ c(n ? "inventory.ingredient.status.inactive" : "inventory.ingredient.status.active")
179
+ );
180
+ },
181
+ enableSorting: !0
182
+ },
183
+ {
184
+ accessorKey: "netsuiteSubsidiary",
185
+ header: () => "NetSuite Subsidiary",
186
+ cell(y) {
187
+ const n = y.row.original, { includeChildren: s, subsidiaryNames: m } = l.getSkuSubsidiaries(n._id);
188
+ return J(
189
+ Re.FmTooltip,
190
+ { zIndex: 51, variant: "rich" },
191
+ {
192
+ default: () => J(
193
+ "span",
194
+ {
195
+ class: "flex-auto line-clamp-2 text-ellipsis break-all whitespace-pre-wrap"
196
+ },
197
+ m.join(", ")
198
+ ),
199
+ content: () => J("div", { class: "flex flex-col" }, [
200
+ J("div", { class: "font-semibold" }, [
201
+ s ? J("span", { class: "text-green-500" }, "Include ") : J("span", { class: "text-red-500" }, "Not Include "),
202
+ "Children Subsidiaries"
203
+ ]),
204
+ J(
205
+ "ul",
206
+ { class: "text-left pb-2" },
207
+ m.map(
208
+ (i) => J(
209
+ "li",
210
+ {
211
+ class: "my-1 p-1 rounded bg-fm-color-system-info-100 text-fm-color-neutral-black"
212
+ },
213
+ i
214
+ )
215
+ )
216
+ )
217
+ ])
218
+ }
219
+ );
220
+ },
221
+ enableSorting: !1,
222
+ size: "auto"
223
+ },
224
+ {
225
+ id: "action",
226
+ header: "",
227
+ cell(y) {
228
+ return Kt(
229
+ [pt[$e.Edit], pt[$e.Delete]],
230
+ (n) => {
231
+ g(n, y.row.original);
232
+ }
233
+ );
234
+ },
235
+ enableSorting: !1,
236
+ size: 40,
237
+ meta: {
238
+ cellClass: "",
239
+ headerClass: ""
240
+ }
241
+ }
242
+ ] };
243
+ }
244
+ function _t(u) {
245
+ var o;
246
+ if (u.trackingMeasurement) {
247
+ const v = (o = u.unit.measurements) == null ? void 0 : o.find((l) => l.id === u.trackingMeasurement);
248
+ if (v)
249
+ return `${v.name} (${v.abbrev})`;
250
+ }
251
+ return `${u.unit.name} (${u.unit.abbrev})`;
252
+ }
253
+ const Sn = /* @__PURE__ */ ye({
254
+ __name: "ConvertForm",
255
+ props: {
256
+ modelValue: {},
257
+ rootValue: {},
258
+ disabled: { type: Boolean },
259
+ readonly: { type: Boolean }
260
+ },
261
+ emits: ["update:modelValue"],
262
+ setup(u, { emit: o }) {
263
+ const v = u, l = k(() => {
264
+ var r;
265
+ return (r = v.rootValue) == null ? void 0 : r.unit;
266
+ }), c = k(() => {
267
+ var r;
268
+ return (r = v.rootValue) == null ? void 0 : r._id;
269
+ }), g = o, { t: h } = ge(), y = k({
270
+ get() {
271
+ return !!v.modelValue;
272
+ },
273
+ set(r) {
274
+ r ? g("update:modelValue", {
275
+ measurement: null,
276
+ inventoryBindings: []
277
+ }) : g("update:modelValue", null);
278
+ }
279
+ }), n = k(() => kn(l.value));
280
+ function s(r) {
281
+ const T = v.modelValue ?? {};
282
+ T.measurement = r ? `${r}` : null, g("update:modelValue", T);
283
+ }
284
+ function m(r) {
285
+ const T = v.modelValue ?? {};
286
+ T.inventoryBindings = r, g("update:modelValue", T);
287
+ }
288
+ const i = k(() => {
289
+ if (!v.modelValue) return null;
290
+ const r = v.modelValue;
291
+ return r.measurement ? n.value.find((T) => T.value === r.measurement) ?? null : n.value.find((T) => T.value === null) ?? null;
292
+ });
293
+ return (r, T) => {
294
+ const A = S("FmSwitch"), R = S("FmSelect"), G = S("FmCard");
295
+ return f(), D(G, {
296
+ variant: "outlined",
297
+ class: "p-16 flex flex-col gap-16"
298
+ }, {
299
+ default: w(() => {
300
+ var U, j;
301
+ return [
302
+ p(A, {
303
+ value: "",
304
+ "model-value": y.value,
305
+ "onUpdate:modelValue": T[0] || (T[0] = (V) => y.value = V),
306
+ label: a(h)("inventory.ingredient.convertible.title"),
307
+ sublabel: a(h)("inventory.ingredient.convertible.subtitle"),
308
+ labelPlacement: "right",
309
+ disabled: r.readonly
310
+ }, null, 8, ["model-value", "label", "sublabel", "disabled"]),
311
+ y.value ? (f(), E(X, { key: 0 }, [
312
+ d("div", null, [
313
+ p(R, {
314
+ label: a(h)("inventory.ingredient.convertible.convertTo"),
315
+ modelValue: (U = i.value) == null ? void 0 : U.value,
316
+ "onUpdate:modelValue": s,
317
+ items: n.value,
318
+ disabled: r.readonly
319
+ }, null, 8, ["label", "modelValue", "items", "disabled"])
320
+ ]),
321
+ p(wn, {
322
+ id: c.value,
323
+ "model-value": ((j = r.modelValue) == null ? void 0 : j.inventoryBindings) ?? [],
324
+ "onUpdate:modelValue": m,
325
+ "exclude-binding-id": c.value,
326
+ rules: [a(Pe)(1)],
327
+ readonly: r.readonly
328
+ }, null, 8, ["id", "model-value", "exclude-binding-id", "rules", "readonly"])
329
+ ], 64)) : H("", !0)
330
+ ];
331
+ }),
332
+ _: 1
333
+ });
334
+ };
335
+ }
336
+ });
337
+ function _e() {
338
+ return {
339
+ low: 6,
340
+ mid: 14
341
+ };
342
+ }
343
+ const Fn = {
344
+ key: 0,
345
+ class: "flex flex-col gap-4"
346
+ }, Ie = /* @__PURE__ */ ye({
347
+ __name: "FmLockableField",
348
+ props: {
349
+ locked: { type: Boolean },
350
+ disabled: { type: Boolean },
351
+ label: {},
352
+ helperText: {},
353
+ modelValue: {},
354
+ tooltipMessage: {},
355
+ tooltipPlacement: {},
356
+ tooltipZIndex: {}
357
+ },
358
+ setup(u) {
359
+ return (o, v) => {
360
+ const l = S("FmLabel"), c = S("FmIcon"), g = S("FmTooltip"), h = S("FmField");
361
+ return o.locked ? (f(), E("div", Fn, [
362
+ Ve(o.$slots, "label", {}, () => [
363
+ p(l, {
364
+ label: o.label,
365
+ disabled: o.disabled
366
+ }, null, 8, ["label", "disabled"])
367
+ ]),
368
+ Ve(o.$slots, "field", {}, () => [
369
+ p(h, { disabled: o.disabled }, {
370
+ prepend: w(() => [
371
+ o.tooltipMessage ? (f(), D(g, {
372
+ key: 0,
373
+ placement: o.tooltipPlacement,
374
+ "z-index": o.tooltipZIndex
375
+ }, {
376
+ content: w(() => [
377
+ qe($(o.tooltipMessage), 1)
378
+ ]),
379
+ default: w(() => [
380
+ p(c, {
381
+ name: "lock",
382
+ color: "neutral-gray-400"
383
+ })
384
+ ]),
385
+ _: 1
386
+ }, 8, ["placement", "z-index"])) : (f(), D(c, {
387
+ key: 1,
388
+ name: "lock",
389
+ color: "neutral-gray-400"
390
+ }))
391
+ ]),
392
+ default: w(() => [
393
+ Ve(o.$slots, "modelValue", {}, () => [
394
+ d("div", {
395
+ class: ae([
396
+ o.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-primary",
397
+ "line-clamp-1 text-ellipsis break-all"
398
+ ])
399
+ }, $(o.modelValue), 3)
400
+ ])
401
+ ]),
402
+ _: 3
403
+ }, 8, ["disabled"])
404
+ ]),
405
+ Ve(o.$slots, "helper-text", {}, () => [
406
+ d("div", {
407
+ class: ae([
408
+ "fm-typo-en-body-sm-400 line-clamp-1",
409
+ o.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-secondary"
410
+ ])
411
+ }, $(o.helperText), 3)
412
+ ])
413
+ ])) : Ve(o.$slots, "default", { key: 1 });
414
+ };
415
+ }
416
+ }), Mn = { class: "flex gap-8" }, En = { class: "flex-1" }, An = { class: "flex-1" }, Un = { class: "flex flex-col gap-5" }, $n = { class: "text-fm-color-typo-secondary" }, Rn = { class: "text-fm-color-typo-secondary whitespace-nowrap" }, Pn = {
417
+ key: 3,
418
+ class: "border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16"
419
+ }, On = { class: "flex flex-col" }, Bn = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Dn = {
420
+ key: 4,
421
+ class: "border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16"
422
+ }, Nn = { class: "flex flex-col gap-12" }, zn = { class: "flex flex-col gap-4" }, Ln = { class: "fm-typo-en-title-sm-600" }, jn = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Hn = { class: "flex flex-col gap-4" }, Wn = { class: "flex fm-corner-radius-md border-1 border-fm-color-neutral-gray-200" }, Yn = { class: "flex-1 p-12 flex flex-col gap-8" }, qn = { class: "mx-auto" }, Gn = { class: "flex flex-col" }, Kn = { class: "fm-typo-en-body-sm-600 translate-y-4" }, Jn = { class: "flex-1 p-12 flex flex-col gap-8" }, Qn = { class: "mx-auto" }, Zn = { class: "flex flex-col" }, Xn = { class: "fm-typo-en-body-sm-600 translate-y-4" }, eo = { class: "flex-1 p-12 flex flex-col gap-8" }, to = { class: "mx-auto" }, no = { class: "flex flex-col" }, oo = { class: "fm-typo-en-body-sm-600 translate-y-4" }, lo = {
423
+ key: 5,
424
+ class: "flex flex-col gap-12"
425
+ }, ao = { class: "flex flex-col" }, so = { class: "flex items-center justify-between" }, ro = { class: "fm-typo-en-title-sm-600" }, io = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, uo = {
426
+ key: 0,
427
+ class: "flex flex-col gap-8"
428
+ }, co = { class: "flex flex-wrap gap-8" }, mo = {
429
+ key: 6,
430
+ class: "flex flex-col gap-12"
431
+ }, po = { class: "flex flex-col" }, vo = { class: "flex items-center justify-between" }, fo = { class: "fm-typo-en-title-sm-600" }, yo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, go = {
432
+ key: 0,
433
+ class: "flex flex-col gap-8"
434
+ }, bo = { class: "flex flex-wrap gap-8" }, ho = {
435
+ key: 7,
436
+ class: "flex flex-col gap-12"
437
+ }, _o = { class: "flex flex-col" }, xo = { class: "flex items-center justify-between" }, ko = { class: "fm-typo-en-title-sm-600" }, wo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, To = {
438
+ key: 0,
439
+ class: "flex flex-col gap-8"
440
+ }, Vo = { class: "flex flex-wrap gap-8" }, Io = /* @__PURE__ */ ye({
441
+ __name: "IngredientForm",
442
+ props: /* @__PURE__ */ dt({
443
+ mode: {},
444
+ modelValue: {},
445
+ disabled: { type: Boolean },
446
+ purchaseOrderTemplateIds: {},
447
+ wastageTemplateIds: {},
448
+ closingTemplateIds: {}
449
+ }, {
450
+ search: {},
451
+ searchModifiers: {}
452
+ }),
453
+ emits: /* @__PURE__ */ dt(["update:modelValue", "click:submit", "update:purchaseOrderTemplateIds", "update:wastageTemplateIds", "update:closingTemplateIds"], ["update:search"]),
454
+ setup(u, { expose: o, emit: v }) {
455
+ var nt;
456
+ const { t: l } = ge(), c = Ke();
457
+ Se();
458
+ const g = Et(), h = It(), y = At(), n = u, s = v, m = de(), i = Fe(), r = Ge(), T = Be(), A = k(() => T.isEnabled);
459
+ B(void 0);
460
+ const R = B([]), G = B([]), U = B([]), j = B(!1);
461
+ function V(e) {
462
+ if (e.length === 0) return;
463
+ const t = e[0], x = n.modelValue ?? {
464
+ unit: m.units.find((C) => C)
465
+ };
466
+ x.unit || (x.unit = t, s("update:modelValue", x));
467
+ }
468
+ jt(() => {
469
+ V(m.units), n.mode === W.CREATE && (r.mustUsePoTemplate && ke(), r.enableWastageTemplate && be(), r.enableClosingTemplate && ce());
470
+ }), wt([() => m.units], ([e]) => {
471
+ V(e);
472
+ });
473
+ function xe() {
474
+ s("click:submit");
475
+ }
476
+ async function ke() {
477
+ R.value = [], j.value = !0;
478
+ try {
479
+ const [e] = await Promise.all([g.readTemplates()]).delayed(
480
+ 1e3
481
+ );
482
+ R.value = e;
483
+ } catch (e) {
484
+ console.log("Something went wrong when fetching templates:", e);
485
+ } finally {
486
+ j.value = !1;
487
+ }
488
+ }
489
+ async function be() {
490
+ G.value = [], j.value = !0;
491
+ try {
492
+ const [e] = await Promise.all([h.readTemplates()]).delayed(
493
+ 1e3
494
+ );
495
+ G.value = e;
496
+ } catch (e) {
497
+ console.log("Something went wrong when fetching wastage templates:", e);
498
+ } finally {
499
+ j.value = !1;
500
+ }
501
+ }
502
+ async function ce() {
503
+ U.value = [], j.value = !0;
504
+ try {
505
+ const [e] = await Promise.all([y.readTemplates()]).delayed(
506
+ 1e3
507
+ );
508
+ U.value = e;
509
+ } catch (e) {
510
+ console.log("Something went wrong when fetching closing templates:", e);
511
+ } finally {
512
+ j.value = !1;
513
+ }
514
+ }
515
+ const se = k({
516
+ get() {
517
+ var e;
518
+ return ((e = n.modelValue) == null ? void 0 : e.code) ?? "";
519
+ },
520
+ set(e) {
521
+ const t = n.modelValue ? {
522
+ ...n.modelValue
523
+ } : {};
524
+ t.code = e, s("update:modelValue", t);
525
+ }
526
+ }), he = k({
527
+ get() {
528
+ var e;
529
+ return ((e = n.modelValue) == null ? void 0 : e.isInactive) ?? !1;
530
+ },
531
+ set(e) {
532
+ const t = n.modelValue ? {
533
+ ...n.modelValue
534
+ } : {};
535
+ t.isInactive = e, s("update:modelValue", t);
536
+ }
537
+ }), ee = k({
538
+ get() {
539
+ var e;
540
+ return ((e = n.modelValue) == null ? void 0 : e.name) ?? "";
541
+ },
542
+ set(e) {
543
+ const t = n.modelValue ? {
544
+ ...n.modelValue
545
+ } : {};
546
+ t.name = e, s("update:modelValue", t);
547
+ }
548
+ }), me = k({
549
+ get() {
550
+ var t, x;
551
+ const e = (x = (t = n.modelValue) == null ? void 0 : t.defaultCost) == null ? void 0 : x.costPerUnit;
552
+ return e ? +Ct(e) : 0;
553
+ },
554
+ set(e) {
555
+ var x, C, q, z;
556
+ const t = n.modelValue ? {
557
+ ...n.modelValue
558
+ } : {};
559
+ t.defaultCost ?? (t.defaultCost = {
560
+ costPerUnit: {
561
+ amount: 0,
562
+ precision: 2,
563
+ currency: ((x = Oe(i.currentCountry.value)) == null ? void 0 : x.currency) ?? "MYR"
564
+ },
565
+ measurement: (z = (q = (C = n.modelValue) == null ? void 0 : C.unit) == null ? void 0 : q.measurements) == null ? void 0 : z.find(
566
+ (te) => {
567
+ var ne;
568
+ return te.id === ((ne = n.modelValue) == null ? void 0 : ne.trackingMeasurement);
569
+ }
570
+ )
571
+ }), t.defaultCost.costPerUnit = {
572
+ ...t.defaultCost.costPerUnit,
573
+ ...St(+e, 4)
574
+ }, s("update:modelValue", t);
575
+ }
576
+ }), pe = k(() => {
577
+ var t, x, C;
578
+ const e = ((t = n.modelValue) == null ? void 0 : t.unit) ?? m.units.find((q) => q);
579
+ return e ? {
580
+ _id: e._id,
581
+ measurement: (x = n.modelValue) == null ? void 0 : x.trackingMeasurement,
582
+ name: ((C = e.measurements.find((q) => {
583
+ var z;
584
+ return q.id === ((z = n.modelValue) == null ? void 0 : z.trackingMeasurement);
585
+ })) == null ? void 0 : C.name) ?? e.name
586
+ } : null;
587
+ }), we = k(
588
+ () => m.units.flatMap(({ name: e, _id: t, abbrev: x, measurements: C }) => [
589
+ {
590
+ label: `${e}`,
591
+ value: null,
592
+ displayAsSection: !0
593
+ },
594
+ {
595
+ label: `${e} (${x})`,
596
+ value: { _id: t },
597
+ displayAsSection: !1
598
+ },
599
+ ...C.map(({ id: q, name: z, abbrev: te }) => ({
600
+ label: `${z} (${te})`,
601
+ value: { _id: t, measurement: q },
602
+ displayAsSection: !1
603
+ }))
604
+ ])
605
+ ), _ = Ht(u, "search"), M = k(
606
+ () => new Jt(we.value, ["label", "value"], {
607
+ caseSensitive: !1,
608
+ sort: !0
609
+ })
610
+ ), K = k(() => M.value.search(_.value));
611
+ function F(e) {
612
+ var t, x, C, q, z;
613
+ return ((x = (t = n.modelValue) == null ? void 0 : t.unit) == null ? void 0 : x._id) === ((C = e.value) == null ? void 0 : C._id) && ((q = n.modelValue) == null ? void 0 : q.trackingMeasurement) === ((z = e.value) == null ? void 0 : z.measurement);
614
+ }
615
+ function b(e) {
616
+ var te, ne;
617
+ if (!e) return;
618
+ const { _id: t, measurement: x } = e, C = x || void 0, q = m.units.find((Te) => Te._id === t);
619
+ if (!q)
620
+ return;
621
+ const z = n.modelValue ?? {};
622
+ z.unit = q, z.trackingMeasurement = C, z.convert && (z.convert.measurement = C || null), r.enableTotalCost && (z.defaultCost = {
623
+ measurement: q.measurements.find((Te) => Te.id === C),
624
+ costPerUnit: {
625
+ ...((te = z.defaultCost) == null ? void 0 : te.costPerUnit) ?? {
626
+ amount: 0,
627
+ precision: 2,
628
+ currency: ((ne = Oe(i.currentCountry.value)) == null ? void 0 : ne.currency) ?? "MYR"
629
+ }
630
+ }
631
+ }), s("update:modelValue", z);
632
+ }
633
+ const L = k({
634
+ get() {
635
+ var e;
636
+ return ((e = n.modelValue) == null ? void 0 : e.convert) ?? null;
637
+ },
638
+ set(e) {
639
+ const t = n.modelValue ? {
640
+ ...n.modelValue
641
+ } : {};
642
+ e ? t.convert = e : t.convert = null, s("update:modelValue", t);
643
+ }
644
+ }), Q = k(() => Ce.options.filter(
645
+ (e) => e === Ce.enum.FIFO || e === Ce.enum.WAVG
646
+ ).map((e) => ({
647
+ label: l(`inventory.ingredient.valuationMethod.${e}`),
648
+ value: e
649
+ }))), re = k({
650
+ get() {
651
+ var e;
652
+ return ((e = n.modelValue) == null ? void 0 : e.valuation) ?? "WAVG";
653
+ },
654
+ set(e) {
655
+ const t = n.modelValue ? {
656
+ ...n.modelValue
657
+ } : {};
658
+ t.valuation = e, s("update:modelValue", t);
659
+ }
660
+ }), P = k({
661
+ get() {
662
+ var e;
663
+ return ((e = n.modelValue) == null ? void 0 : e.customAttributes) ?? {};
664
+ },
665
+ set(e) {
666
+ const t = n.modelValue ? {
667
+ ...n.modelValue
668
+ } : {};
669
+ t.customAttributes = e, s("update:modelValue", t);
670
+ }
671
+ }), N = B();
672
+ o({
673
+ validateInputs: () => {
674
+ var e, t;
675
+ (t = (e = N.value) == null ? void 0 : e.validateInputs) == null || t.call(e);
676
+ },
677
+ resetInputsValidation: () => {
678
+ var e, t;
679
+ (t = (e = N.value) == null ? void 0 : e.resetInputsValidation) == null || t.call(e);
680
+ },
681
+ resetInputs: () => {
682
+ var e, t;
683
+ (t = (e = N.value) == null ? void 0 : e.resetInputs) == null || t.call(e);
684
+ }
685
+ });
686
+ const O = B(!1), Y = k(
687
+ () => {
688
+ var e, t, x;
689
+ return (e = n.modelValue) != null && e._id ? ((x = m.menu.bindedBySkuId[(t = n.modelValue) == null ? void 0 : t._id]) == null ? void 0 : x.filter(
690
+ (C) => C.from === "INGREDIENT"
691
+ )) ?? [] : [];
692
+ }
693
+ ), oe = k(
694
+ () => {
695
+ var e, t, x;
696
+ return (e = n.modelValue) != null && e._id ? ((x = m.menu.bindedBySkuId[(t = n.modelValue) == null ? void 0 : t._id]) == null ? void 0 : x.filter(
697
+ (C) => C.from === "RECIPE"
698
+ )) ?? [] : [];
699
+ }
700
+ ), ve = k(
701
+ () => {
702
+ var e, t, x;
703
+ return (e = n.modelValue) != null && e._id ? ((x = m.menu.bindedBySkuId[(t = n.modelValue) == null ? void 0 : t._id]) == null ? void 0 : x.filter((C) => C.from === "MENU")) ?? [] : [];
704
+ }
705
+ ), Me = k(
706
+ () => m.skus.map((e) => ({ label: e.name, value: e.code }))
707
+ ), Ee = B((nt = n.modelValue) == null ? void 0 : nt.code);
708
+ function Ae(e) {
709
+ var x;
710
+ const t = e.el;
711
+ t && ((x = t.querySelector("[x-should-scroll-into=true]")) == null || x.scrollIntoView());
712
+ }
713
+ const Ue = k(
714
+ () => {
715
+ var e, t, x, C, q, z;
716
+ return ((C = (x = (t = (e = n.modelValue) == null ? void 0 : e.unit) == null ? void 0 : t.measurements) == null ? void 0 : x.find(
717
+ (te) => {
718
+ var ne;
719
+ return te.id === ((ne = n.modelValue) == null ? void 0 : ne.trackingMeasurement);
720
+ }
721
+ )) == null ? void 0 : C.abbrev) ?? ((z = (q = n.modelValue) == null ? void 0 : q.unit) == null ? void 0 : z.abbrev);
722
+ }
723
+ ), le = k({
724
+ get() {
725
+ var e, t;
726
+ return ((t = (e = n.modelValue) == null ? void 0 : e.thresholds) == null ? void 0 : t.low) ?? _e().low;
727
+ },
728
+ set(e) {
729
+ var C;
730
+ const t = ((C = n.modelValue) == null ? void 0 : C.thresholds) ?? _e();
731
+ t.low = e;
732
+ const x = n.modelValue ? {
733
+ ...n.modelValue
734
+ } : {};
735
+ x.thresholds = t, s("update:modelValue", x);
736
+ }
737
+ }), ie = k({
738
+ get() {
739
+ var e, t;
740
+ return ((t = (e = n.modelValue) == null ? void 0 : e.thresholds) == null ? void 0 : t.mid) ?? _e().mid;
741
+ },
742
+ set(e) {
743
+ var C;
744
+ const t = ((C = n.modelValue) == null ? void 0 : C.thresholds) ?? _e();
745
+ t.mid = e;
746
+ const x = n.modelValue ? {
747
+ ...n.modelValue
748
+ } : {};
749
+ x.thresholds = t, s("update:modelValue", x);
750
+ }
751
+ }), Je = k(() => r.mustUsePoTemplate && n.mode === W.CREATE && R.value.length > 0 ? R.value.map((e) => ({
752
+ label: e.name || "Template",
753
+ value: e._id || "template_" + e.name
754
+ })) : []), Qe = k(() => Je.value.filter(
755
+ (e) => (n.purchaseOrderTemplateIds ?? []).includes(e.value)
756
+ )), Ze = k(() => r.enableWastageTemplate && n.mode === W.CREATE && G.value.length > 0 ? G.value.map((e) => ({
757
+ label: e.name || "Template",
758
+ value: e._id || "template_" + e.name
759
+ })) : []), Xe = k(() => Ze.value.filter(
760
+ (e) => (n.wastageTemplateIds ?? []).includes(e.value)
761
+ )), et = k(() => r.enableClosingTemplate && n.mode === W.CREATE && U.value.length > 0 ? U.value.map((e) => ({
762
+ label: e.name || "Template",
763
+ value: e._id || "template_" + e.name
764
+ })) : []), tt = k(() => et.value.filter(
765
+ (e) => (n.closingTemplateIds ?? []).includes(e.value)
766
+ ));
767
+ function Rt() {
768
+ c.open({
769
+ title: l("inventory.ingredient.purchaseOrderTemplates.selectTitle"),
770
+ closeButton: !0,
771
+ contentComponent: Le,
772
+ contentComponentProps: {
773
+ modelValue: n.purchaseOrderTemplateIds ?? [],
774
+ items: Je.value
775
+ },
776
+ primaryActions: {
777
+ text: l("common.confirm"),
778
+ close: !0
779
+ },
780
+ secondaryActions: {
781
+ text: l("common.cancel"),
782
+ close: !0,
783
+ variant: "tertiary"
784
+ }
785
+ }).onPrimary((e) => {
786
+ s("update:purchaseOrderTemplateIds", e);
787
+ });
788
+ }
789
+ function Pt() {
790
+ c.open({
791
+ title: l("inventory.ingredient.wastageTemplates.selectTitle"),
792
+ closeButton: !0,
793
+ contentComponent: Le,
794
+ contentComponentProps: {
795
+ modelValue: n.wastageTemplateIds ?? [],
796
+ items: Ze.value
797
+ },
798
+ primaryActions: {
799
+ text: l("common.confirm"),
800
+ close: !0
801
+ },
802
+ secondaryActions: {
803
+ text: l("common.cancel"),
804
+ close: !0,
805
+ variant: "tertiary"
806
+ }
807
+ }).onPrimary((e) => {
808
+ s("update:wastageTemplateIds", e);
809
+ });
810
+ }
811
+ function Ot() {
812
+ c.open({
813
+ title: l("inventory.ingredient.closingTemplates.selectTitle"),
814
+ closeButton: !0,
815
+ contentComponent: Le,
816
+ contentComponentProps: {
817
+ modelValue: n.closingTemplateIds ?? [],
818
+ items: et.value
819
+ },
820
+ primaryActions: {
821
+ text: l("common.confirm"),
822
+ close: !0
823
+ },
824
+ secondaryActions: {
825
+ text: l("common.cancel"),
826
+ close: !0,
827
+ variant: "tertiary"
828
+ }
829
+ }).onPrimary((e) => {
830
+ s("update:closingTemplateIds", e);
831
+ });
832
+ }
833
+ function Bt() {
834
+ return function(t) {
835
+ return typeof (t == null ? void 0 : t.low) != "number" || typeof (t == null ? void 0 : t.mid) != "number" ? "Required" : t.low >= t.mid ? "Days for red indicator should be less than yellow indicator." : !0;
836
+ };
837
+ }
838
+ return (e, t) => {
839
+ const x = S("FmTextField"), C = S("FmLabel"), q = S("FmField"), z = S("FmIcon"), te = S("FmMenuHeader"), ne = S("FmMenuDivider"), Te = S("FmMenuItem"), Dt = S("FmMenu"), ot = S("FmFormGroup"), Nt = S("FmSelect"), lt = S("FmSwitch"), at = S("FmStepperField"), De = S("FmButton"), Ne = S("FmChip"), zt = S("FmForm");
840
+ return f(), D(zt, {
841
+ disabled: e.disabled,
842
+ ref_key: "formRef",
843
+ ref: N,
844
+ class: "flex flex-col gap-32",
845
+ onValidationSuccess: xe
846
+ }, {
847
+ default: w(() => {
848
+ var st, rt, it, ut;
849
+ return [
850
+ d("div", Mn, [
851
+ d("div", En, [
852
+ p(Ie, {
853
+ "tooltip-message": "This field is managed by NetSuite",
854
+ "tooltip-z-index": 50,
855
+ label: a(l)("inventory.ingredient.code"),
856
+ "model-value": se.value,
857
+ "onUpdate:modelValue": t[1] || (t[1] = (I) => se.value = I),
858
+ locked: A.value,
859
+ disabled: e.disabled
860
+ }, {
861
+ default: w(() => [
862
+ p(x, {
863
+ label: a(l)("inventory.ingredient.code"),
864
+ "model-value": se.value,
865
+ "onUpdate:modelValue": t[0] || (t[0] = (I) => se.value = I),
866
+ rules: [a(ze)(), a(Qt)(Me.value, Ee.value)],
867
+ "label-mark": "required"
868
+ }, null, 8, ["label", "model-value", "rules"])
869
+ ]),
870
+ _: 1
871
+ }, 8, ["label", "model-value", "locked", "disabled"])
872
+ ]),
873
+ d("div", An, [
874
+ p(Ie, {
875
+ "tooltip-message": "This field is managed by NetSuite",
876
+ "tooltip-z-index": 50,
877
+ label: a(l)("inventory.ingredient.name"),
878
+ "model-value": ee.value,
879
+ "onUpdate:modelValue": t[3] || (t[3] = (I) => ee.value = I),
880
+ locked: A.value,
881
+ disabled: e.disabled
882
+ }, {
883
+ default: w(() => [
884
+ p(x, {
885
+ label: a(l)("inventory.ingredient.name"),
886
+ "model-value": ee.value,
887
+ "onUpdate:modelValue": t[2] || (t[2] = (I) => ee.value = I),
888
+ rules: [a(ze)()],
889
+ "label-mark": "required"
890
+ }, null, 8, ["label", "model-value", "rules"])
891
+ ]),
892
+ _: 1
893
+ }, 8, ["label", "model-value", "locked", "disabled"])
894
+ ])
895
+ ]),
896
+ p(Ie, {
897
+ "tooltip-message": "This field is managed by NetSuite",
898
+ "tooltip-z-index": 50,
899
+ label: a(l)("inventory.ingredient.unit"),
900
+ "helper-text": (st = e.modelValue) != null && st.trackingMeasurement ? `Base unit: ${(it = (rt = e.modelValue) == null ? void 0 : rt.unit) == null ? void 0 : it.name}` : void 0,
901
+ "model-value": (ut = pe.value) == null ? void 0 : ut.name,
902
+ locked: A.value,
903
+ disabled: e.disabled
904
+ }, {
905
+ default: w(() => [
906
+ p(ot, {
907
+ "model-value": pe.value,
908
+ rules: [a(ze)()],
909
+ "label-mark": "required"
910
+ }, {
911
+ label: w(() => [
912
+ p(C, {
913
+ label: a(l)("inventory.ingredient.unit")
914
+ }, null, 8, ["label"])
915
+ ]),
916
+ default: w(({ invalid: I }) => [
917
+ p(Dt, null, {
918
+ "menu-button": w(() => [
919
+ p(q, {
920
+ class: ae([
921
+ "fm-typo-en-body-lg-400",
922
+ {
923
+ "text-fm-color-typo-primary": !e.disabled,
924
+ "text-fm-color-typo-disabled": e.disabled
925
+ }
926
+ ]),
927
+ invalid: I,
928
+ "append-icon": "expand_more"
929
+ }, {
930
+ default: w(() => {
931
+ var Z;
932
+ return [
933
+ qe($((Z = pe.value) == null ? void 0 : Z.name), 1)
934
+ ];
935
+ }),
936
+ _: 2
937
+ }, 1032, ["class", "invalid"])
938
+ ]),
939
+ default: w(() => [
940
+ d("div", Un, [
941
+ p(x, {
942
+ modelValue: _.value,
943
+ "onUpdate:modelValue": t[4] || (t[4] = (Z) => _.value = Z),
944
+ placeholder: "Filter options"
945
+ }, {
946
+ prepend: w(() => [
947
+ p(z, { name: "search" })
948
+ ]),
949
+ _: 1
950
+ }, 8, ["modelValue"]),
951
+ d("div", {
952
+ class: "overflow-x-hidden overflow-y-auto max-h-[300px]",
953
+ onVnodeMounted: Ae
954
+ }, [
955
+ (f(!0), E(X, null, ue(K.value, (Z, Lt) => (f(), E(X, { key: Lt }, [
956
+ Z.displayAsSection ? (f(), E(X, { key: 0 }, [
957
+ p(te, {
958
+ label: Z.label
959
+ }, null, 8, ["label"]),
960
+ p(ne)
961
+ ], 64)) : (f(), D(Te, {
962
+ key: 1,
963
+ label: Z.label,
964
+ "model-value": F(Z),
965
+ onClick: (nl) => b(Z.value),
966
+ "x-should-scroll-into": `${F(Z)}`
967
+ }, null, 8, ["label", "model-value", "onClick", "x-should-scroll-into"]))
968
+ ], 64))), 128))
969
+ ], 512)
970
+ ])
971
+ ]),
972
+ _: 2
973
+ }, 1024)
974
+ ]),
975
+ _: 1
976
+ }, 8, ["model-value", "rules"])
977
+ ]),
978
+ _: 1
979
+ }, 8, ["label", "helper-text", "model-value", "locked", "disabled"]),
980
+ a(r).enableTotalCost ? (f(), D(Ie, {
981
+ key: 0,
982
+ "tooltip-message": "This field is managed by NetSuite",
983
+ "tooltip-z-index": 50,
984
+ label: a(l)("inventory.ingredient.valuationMethod.title"),
985
+ "model-value": a(l)("inventory.ingredient.valuationMethod." + re.value),
986
+ locked: A.value,
987
+ disabled: e.disabled
988
+ }, {
989
+ label: w(() => [
990
+ p(fe, { "z-index": 50 }, {
991
+ default: w(() => [
992
+ p(C, {
993
+ label: a(l)("inventory.ingredient.valuationMethod.title")
994
+ }, null, 8, ["label"])
995
+ ]),
996
+ _: 1
997
+ })
998
+ ]),
999
+ default: w(() => [
1000
+ p(Nt, {
1001
+ class: "col-span-2",
1002
+ label: a(l)("inventory.ingredient.valuationMethod.title"),
1003
+ "model-value": re.value,
1004
+ "onUpdate:modelValue": t[5] || (t[5] = (I) => re.value = I),
1005
+ items: Q.value
1006
+ }, null, 8, ["label", "model-value", "items"])
1007
+ ]),
1008
+ _: 1
1009
+ }, 8, ["label", "model-value", "locked", "disabled"])) : H("", !0),
1010
+ a(r).enableTotalCost ? (f(), D(Ie, {
1011
+ key: 1,
1012
+ "tooltip-message": "This field is managed by NetSuite",
1013
+ "tooltip-z-index": 50,
1014
+ "model-value": `${a(Zt)()} ${me.value}`,
1015
+ locked: A.value,
1016
+ disabled: e.disabled
1017
+ }, {
1018
+ label: w(() => [
1019
+ p(fe, { "z-index": 50 }, {
1020
+ default: w(() => [
1021
+ p(C, {
1022
+ label: a(l)("inventory.ingredient.pricePerUnit")
1023
+ }, null, 8, ["label"])
1024
+ ]),
1025
+ _: 1
1026
+ })
1027
+ ]),
1028
+ default: w(() => [
1029
+ p(x, {
1030
+ "model-value": me.value,
1031
+ "onUpdate:modelValue": t[6] || (t[6] = (I) => me.value = I),
1032
+ rules: [a(Pe)(0), a(Xt)(4)]
1033
+ }, {
1034
+ label: w(() => [
1035
+ p(fe, { "z-index": 50 }, {
1036
+ default: w(() => [
1037
+ p(C, {
1038
+ label: a(l)("inventory.ingredient.pricePerUnit")
1039
+ }, null, 8, ["label"])
1040
+ ]),
1041
+ _: 1
1042
+ })
1043
+ ]),
1044
+ prepend: w(() => {
1045
+ var I, Z;
1046
+ return [
1047
+ d("div", $n, $(a(vt)(((I = a(i).currentCountry) == null ? void 0 : I.value) ?? a(ft)) === "MYR" ? "RM" : a(vt)(((Z = a(i).currentCountry) == null ? void 0 : Z.value) ?? a(ft))), 1)
1048
+ ];
1049
+ }),
1050
+ append: w(() => [
1051
+ d("div", Rn, " / " + $(Ue.value), 1)
1052
+ ]),
1053
+ _: 1
1054
+ }, 8, ["model-value", "rules"])
1055
+ ]),
1056
+ _: 1
1057
+ }, 8, ["model-value", "locked", "disabled"])) : H("", !0),
1058
+ !A.value || L.value ? (f(), D(Sn, {
1059
+ key: 2,
1060
+ "model-value": L.value,
1061
+ "onUpdate:modelValue": t[7] || (t[7] = (I) => L.value = I),
1062
+ "root-value": e.modelValue,
1063
+ readonly: A.value
1064
+ }, null, 8, ["model-value", "root-value", "readonly"])) : H("", !0),
1065
+ e.mode !== a(W).CREATE ? (f(), E("div", Pn, [
1066
+ p(lt, {
1067
+ label: a(l)("inventory.ingredient.status.inactive"),
1068
+ "model-value": he.value,
1069
+ "onUpdate:modelValue": t[8] || (t[8] = (I) => he.value = I),
1070
+ "label-placement": "right",
1071
+ disabled: A.value
1072
+ }, null, 8, ["label", "model-value", "disabled"]),
1073
+ d("div", On, [
1074
+ d("div", Bn, $(a(l)("inventory.ingredient.status.preventFromOrder")), 1)
1075
+ ])
1076
+ ])) : H("", !0),
1077
+ e.mode !== a(W).CREATE ? (f(), E("div", Dn, [
1078
+ d("div", null, [
1079
+ p(lt, {
1080
+ label: a(l)("inventory.ingredient.bindedItems.title"),
1081
+ modelValue: O.value,
1082
+ "onUpdate:modelValue": t[9] || (t[9] = (I) => O.value = I),
1083
+ "label-placement": "right"
1084
+ }, null, 8, ["label", "modelValue"])
1085
+ ]),
1086
+ O.value && Y.value.length ? (f(), D(We, {
1087
+ key: 0,
1088
+ name: a(l)("inventory.ingredient.bindedItems.ingredient"),
1089
+ bindings: Y.value
1090
+ }, null, 8, ["name", "bindings"])) : H("", !0),
1091
+ O.value && oe.value.length ? (f(), D(We, {
1092
+ key: 1,
1093
+ name: a(l)("inventory.ingredient.bindedItems.recipe"),
1094
+ bindings: oe.value
1095
+ }, null, 8, ["name", "bindings"])) : H("", !0),
1096
+ O.value && ve.value.length ? (f(), D(We, {
1097
+ key: 2,
1098
+ name: a(l)("inventory.ingredient.bindedItems.menu"),
1099
+ bindings: ve.value
1100
+ }, null, 8, ["name", "bindings"])) : H("", !0)
1101
+ ])) : H("", !0),
1102
+ d("div", Nn, [
1103
+ d("div", zn, [
1104
+ p(fe, null, {
1105
+ default: w(() => [
1106
+ d("div", Ln, $(a(l)("inventory.ingredient.threshold.title")), 1)
1107
+ ]),
1108
+ _: 1
1109
+ }),
1110
+ d("div", jn, $(a(l)("inventory.ingredient.threshold.subtitle")), 1)
1111
+ ]),
1112
+ d("div", Hn, [
1113
+ p(ot, {
1114
+ "model-value": { low: le.value, mid: ie.value },
1115
+ rules: [Bt()]
1116
+ }, null, 8, ["model-value", "rules"]),
1117
+ d("div", Wn, [
1118
+ d("div", Yn, [
1119
+ d("div", qn, [
1120
+ p(je, {
1121
+ days: le.value,
1122
+ level: a(He).low
1123
+ }, null, 8, ["days", "level"])
1124
+ ]),
1125
+ d("div", Gn, [
1126
+ d("div", Kn, $(a(l)("inventory.ingredient.threshold.whenRemaining")), 1),
1127
+ p(at, {
1128
+ modelValue: le.value,
1129
+ "onUpdate:modelValue": t[10] || (t[10] = (I) => le.value = I),
1130
+ rules: [a(Pe)(0)]
1131
+ }, {
1132
+ append: w(() => t[13] || (t[13] = [
1133
+ d("div", {
1134
+ class: "text-fm-color-typo-secondary",
1135
+ style: { "padding-right": "32px" }
1136
+ }, "days", -1)
1137
+ ])),
1138
+ _: 1
1139
+ }, 8, ["modelValue", "rules"])
1140
+ ])
1141
+ ]),
1142
+ t[15] || (t[15] = d("div", {
1143
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
1144
+ style: { width: "1px" }
1145
+ }, [
1146
+ d("div", {
1147
+ class: "absolute bg-white",
1148
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "24px" }
1149
+ }, " < ")
1150
+ ], -1)),
1151
+ d("div", Jn, [
1152
+ d("div", Qn, [
1153
+ p(je, {
1154
+ days: ie.value,
1155
+ level: a(He).mid
1156
+ }, null, 8, ["days", "level"])
1157
+ ]),
1158
+ d("div", Zn, [
1159
+ d("div", Xn, $(a(l)("inventory.ingredient.threshold.whenRemaining")), 1),
1160
+ p(at, {
1161
+ modelValue: ie.value,
1162
+ "onUpdate:modelValue": t[11] || (t[11] = (I) => ie.value = I),
1163
+ rules: [a(Pe)(0)]
1164
+ }, {
1165
+ append: w(() => t[14] || (t[14] = [
1166
+ d("div", {
1167
+ class: "text-fm-color-typo-secondary",
1168
+ style: { "padding-right": "32px" }
1169
+ }, "days", -1)
1170
+ ])),
1171
+ _: 1
1172
+ }, 8, ["modelValue", "rules"])
1173
+ ])
1174
+ ]),
1175
+ t[16] || (t[16] = d("div", {
1176
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
1177
+ style: { width: "1px" }
1178
+ }, [
1179
+ d("div", {
1180
+ class: "absolute bg-white",
1181
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "24px" }
1182
+ }, " < ")
1183
+ ], -1)),
1184
+ d("div", eo, [
1185
+ d("div", to, [
1186
+ p(je, {
1187
+ days: ie.value + 1,
1188
+ level: a(He).high
1189
+ }, null, 8, ["days", "level"])
1190
+ ]),
1191
+ d("div", no, [
1192
+ d("div", oo, $(a(l)("inventory.ingredient.threshold.stockIsStaple")), 1)
1193
+ ])
1194
+ ])
1195
+ ])
1196
+ ])
1197
+ ]),
1198
+ a(r).mustUsePoTemplate && e.mode === a(W).CREATE ? (f(), E("div", lo, [
1199
+ d("div", ao, [
1200
+ d("div", so, [
1201
+ p(fe, null, {
1202
+ default: w(() => [
1203
+ d("div", ro, $(a(l)("inventory.ingredient.purchaseOrderTemplates.title")), 1)
1204
+ ]),
1205
+ _: 1
1206
+ }),
1207
+ p(De, {
1208
+ variant: "secondary",
1209
+ "text-color": "primary",
1210
+ "border-color": "primary",
1211
+ "prepend-icon": "add",
1212
+ onClick: Rt
1213
+ })
1214
+ ]),
1215
+ d("div", io, $(a(l)("inventory.ingredient.purchaseOrderTemplates.description")), 1)
1216
+ ]),
1217
+ Qe.value.length > 0 ? (f(), E("div", uo, [
1218
+ d("div", co, [
1219
+ (f(!0), E(X, null, ue(Qe.value, (I) => (f(), D(Ne, {
1220
+ key: I.value,
1221
+ label: I.label,
1222
+ variant: "info",
1223
+ compact: ""
1224
+ }, null, 8, ["label"]))), 128))
1225
+ ])
1226
+ ])) : H("", !0)
1227
+ ])) : H("", !0),
1228
+ a(r).enableWastageTemplate && e.mode === a(W).CREATE ? (f(), E("div", mo, [
1229
+ d("div", po, [
1230
+ d("div", vo, [
1231
+ p(fe, null, {
1232
+ default: w(() => [
1233
+ d("div", fo, $(a(l)("inventory.ingredient.wastageTemplates.title")), 1)
1234
+ ]),
1235
+ _: 1
1236
+ }),
1237
+ p(De, {
1238
+ variant: "secondary",
1239
+ "text-color": "primary",
1240
+ "border-color": "primary",
1241
+ "prepend-icon": "add",
1242
+ onClick: Pt
1243
+ })
1244
+ ]),
1245
+ d("div", yo, $(a(l)("inventory.ingredient.wastageTemplates.description")), 1)
1246
+ ]),
1247
+ Xe.value.length > 0 ? (f(), E("div", go, [
1248
+ d("div", bo, [
1249
+ (f(!0), E(X, null, ue(Xe.value, (I) => (f(), D(Ne, {
1250
+ key: I.value,
1251
+ label: I.label,
1252
+ variant: "info",
1253
+ compact: ""
1254
+ }, null, 8, ["label"]))), 128))
1255
+ ])
1256
+ ])) : H("", !0)
1257
+ ])) : H("", !0),
1258
+ a(r).enableClosingTemplate && e.mode === a(W).CREATE ? (f(), E("div", ho, [
1259
+ d("div", _o, [
1260
+ d("div", xo, [
1261
+ p(fe, null, {
1262
+ default: w(() => [
1263
+ d("div", ko, $(a(l)("inventory.ingredient.closingTemplates.title")), 1)
1264
+ ]),
1265
+ _: 1
1266
+ }),
1267
+ p(De, {
1268
+ variant: "secondary",
1269
+ "text-color": "primary",
1270
+ "border-color": "primary",
1271
+ "prepend-icon": "add",
1272
+ onClick: Ot
1273
+ })
1274
+ ]),
1275
+ d("div", wo, $(a(l)("inventory.ingredient.closingTemplates.description")), 1)
1276
+ ]),
1277
+ tt.value.length > 0 ? (f(), E("div", To, [
1278
+ d("div", Vo, [
1279
+ (f(!0), E(X, null, ue(tt.value, (I) => (f(), D(Ne, {
1280
+ key: I.value,
1281
+ label: I.label,
1282
+ variant: "info",
1283
+ compact: ""
1284
+ }, null, 8, ["label"]))), 128))
1285
+ ])
1286
+ ])) : H("", !0)
1287
+ ])) : H("", !0),
1288
+ d("div", null, [
1289
+ p(Tn, {
1290
+ entity: "inventorySku",
1291
+ modelValue: P.value,
1292
+ "onUpdate:modelValue": t[12] || (t[12] = (I) => P.value = I)
1293
+ }, null, 8, ["modelValue"])
1294
+ ])
1295
+ ];
1296
+ }),
1297
+ _: 1
1298
+ }, 8, ["disabled"]);
1299
+ };
1300
+ }
1301
+ }), Co = { class: "flex flex-col gap-32" }, So = { class: "flex gap-4" }, Fo = /* @__PURE__ */ ye({
1302
+ __name: "IngredientDialog",
1303
+ props: {
1304
+ show: { type: Boolean },
1305
+ unit: {},
1306
+ mode: { default: W.READ }
1307
+ },
1308
+ emits: ["update:show"],
1309
+ setup(u) {
1310
+ const o = u, v = de(), l = Ge(), c = Be(), g = Et(), h = It(), y = At(), n = Se(), { t: s } = ge(), m = ht(o, "show"), i = ht(o, "unit"), r = B([]), T = B([]), A = B([]), R = k(
1311
+ () => {
1312
+ var _;
1313
+ return c.isEnabled && c.netSuiteItemBySkuId.has((_ = o.unit) == null ? void 0 : _._id);
1314
+ }
1315
+ ), G = k(() => {
1316
+ switch (o.mode) {
1317
+ case W.READ:
1318
+ return "";
1319
+ case W.UPDATE:
1320
+ return s("inventory.ingredient.update.title");
1321
+ case W.CREATE:
1322
+ return s("inventory.ingredient.create.title");
1323
+ }
1324
+ return "";
1325
+ }), U = k(() => {
1326
+ switch (o.mode) {
1327
+ case W.READ:
1328
+ return "";
1329
+ case W.UPDATE:
1330
+ return s("common.save");
1331
+ case W.CREATE:
1332
+ return s("common.add");
1333
+ }
1334
+ return "";
1335
+ }), j = B(), V = B(!1);
1336
+ async function xe() {
1337
+ V.value = !0;
1338
+ try {
1339
+ await v.createSku(i.value);
1340
+ const _ = v.skuByCode[i.value.code];
1341
+ l.enablePoTemplate && r.value.length > 0 && await be(_), l.enableWastageTemplate && T.value.length > 0 && await ce(_), l.enableClosingTemplate && A.value.length > 0 && await se(_), m.value = !1, n.open({
1342
+ title: s("inventory.common.success"),
1343
+ message: s("inventory.ingredient.create.success", { name: i.value.name }),
1344
+ type: "success"
1345
+ });
1346
+ } catch (_) {
1347
+ _ instanceof yt || n.open({
1348
+ title: s("inventory.ingredient.create.error.title"),
1349
+ message: s("inventory.ingredient.create.error.message"),
1350
+ type: "error"
1351
+ });
1352
+ } finally {
1353
+ V.value = !1;
1354
+ }
1355
+ }
1356
+ async function ke() {
1357
+ V.value = !0;
1358
+ try {
1359
+ await v.updateSku(i.value), V.value = !1, m.value = !1, n.open({
1360
+ title: s("inventory.common.success"),
1361
+ message: s("inventory.ingredient.update.success", { name: i.value.name }),
1362
+ type: "success"
1363
+ });
1364
+ } catch (_) {
1365
+ _ instanceof yt || n.open({
1366
+ title: s("inventory.ingredient.update.error.title"),
1367
+ message: s("inventory.ingredient.update.error.message"),
1368
+ type: "error"
1369
+ });
1370
+ } finally {
1371
+ V.value = !1;
1372
+ }
1373
+ }
1374
+ async function be(_) {
1375
+ var M, K, F, b;
1376
+ try {
1377
+ for (const L of r.value) {
1378
+ const Q = await g.getTemplate(L);
1379
+ if (!Q) {
1380
+ console.warn(`Template with ID ${L} not found`);
1381
+ continue;
1382
+ }
1383
+ if (!Q.purchaseOrder.items.find((P) => P.sku._id === _._id)) {
1384
+ const P = { amount: 1, precision: en(_.unit) }, N = {
1385
+ sku: _,
1386
+ name: _.name,
1387
+ code: _.code,
1388
+ quantity: P,
1389
+ minimumQuantity: P,
1390
+ quantityStep: P,
1391
+ measurement: ((K = (M = _.unit) == null ? void 0 : M.measurements) == null ? void 0 : K[0]) || null
1392
+ }, O = {
1393
+ ...Q,
1394
+ purchaseOrder: {
1395
+ ...Q.purchaseOrder,
1396
+ items: [...Q.purchaseOrder.items, N]
1397
+ }
1398
+ };
1399
+ (((F = O.purchaseOrder.supplier) == null ? void 0 : F.internal) === gt.enum.warehouse || ((b = O.purchaseOrder.supplier) == null ? void 0 : b.internal) === gt.enum.restaurant) && (O.purchaseOrder.items = O.purchaseOrder.items.map(
1400
+ ({ totalCost: Y, ...oe }) => oe
1401
+ )), await g.updateTemplate(O), await new Promise((Y) => setTimeout(Y, 1e3));
1402
+ }
1403
+ }
1404
+ } catch (L) {
1405
+ n.open({
1406
+ title: s("inventory.transfer.template.update.error"),
1407
+ message: s("inventory.transfer.template.update.errorMessage"),
1408
+ type: "error"
1409
+ }), console.error("Error in updating transfer template", L);
1410
+ }
1411
+ }
1412
+ async function ce(_) {
1413
+ try {
1414
+ for (const M of T.value) {
1415
+ const K = await h.getTemplate(M);
1416
+ if (!K) {
1417
+ console.warn(`Wastage Template with ID ${M} not found`);
1418
+ continue;
1419
+ }
1420
+ if (!K.items.find((b) => b.id === _._id)) {
1421
+ const b = {
1422
+ id: _._id,
1423
+ name: _.name,
1424
+ code: _.code,
1425
+ type: "sku",
1426
+ disabledMeasurements: []
1427
+ }, L = {
1428
+ ...K,
1429
+ items: [...K.items, b]
1430
+ };
1431
+ await h.updateTemplate(L), await new Promise((Q) => setTimeout(Q, 1e3));
1432
+ }
1433
+ }
1434
+ } catch (M) {
1435
+ n.open({
1436
+ title: s("inventory.wastage.template.update.error"),
1437
+ message: s("inventory.wastage.template.update.errorMessage"),
1438
+ type: "error"
1439
+ }), console.error("Error in updating wastage template", M);
1440
+ }
1441
+ }
1442
+ async function se(_) {
1443
+ try {
1444
+ for (const M of A.value) {
1445
+ const K = await y.getTemplate(M);
1446
+ if (!K) {
1447
+ console.warn(`Closing Template with ID ${M} not found`);
1448
+ continue;
1449
+ }
1450
+ if (!K.items.find((b) => b.sku._id === _._id)) {
1451
+ const b = {
1452
+ sku: _
1453
+ }, L = {
1454
+ ...K,
1455
+ items: [...K.items, b]
1456
+ };
1457
+ await y.updateTemplate(L), await new Promise((Q) => setTimeout(Q, 1e3));
1458
+ }
1459
+ }
1460
+ } catch (M) {
1461
+ n.open({
1462
+ title: s("inventory.closing.template.update.error"),
1463
+ message: s("inventory.closing.template.update.errorMessage"),
1464
+ type: "error"
1465
+ }), console.error("Error in updating closing template", M);
1466
+ }
1467
+ }
1468
+ function he() {
1469
+ var _, M;
1470
+ (M = (_ = j.value) == null ? void 0 : _.validateInputs) == null || M.call(_);
1471
+ }
1472
+ function ee() {
1473
+ switch (o.mode) {
1474
+ case W.READ:
1475
+ return;
1476
+ case W.UPDATE:
1477
+ return ke();
1478
+ case W.CREATE:
1479
+ return xe();
1480
+ }
1481
+ }
1482
+ function me(_) {
1483
+ r.value = _;
1484
+ }
1485
+ function pe(_) {
1486
+ T.value = _;
1487
+ }
1488
+ function we(_) {
1489
+ A.value = _;
1490
+ }
1491
+ return (_, M) => {
1492
+ const K = S("FmChip"), F = S("FmButton"), b = S("FmSideSheet");
1493
+ return f(), D(b, {
1494
+ "model-value": a(m),
1495
+ "onUpdate:modelValue": M[3] || (M[3] = (L) => ct(m) ? m.value = L : null),
1496
+ header: G.value,
1497
+ "close-button": "",
1498
+ "dismiss-away": "",
1499
+ "max-width": 500
1500
+ }, {
1501
+ "side-sheet-footer": w(() => [
1502
+ d("div", So, [
1503
+ p(F, {
1504
+ loading: V.value,
1505
+ label: U.value,
1506
+ onClick: he
1507
+ }, null, 8, ["loading", "label"]),
1508
+ p(F, {
1509
+ disabled: V.value,
1510
+ label: a(s)("common.close"),
1511
+ variant: "tertiary",
1512
+ onClick: M[2] || (M[2] = (L) => m.value = !1)
1513
+ }, null, 8, ["disabled", "label"])
1514
+ ])
1515
+ ]),
1516
+ default: w(() => [
1517
+ d("div", Co, [
1518
+ d("div", null, [
1519
+ R.value ? (f(), D(K, {
1520
+ key: 0,
1521
+ label: "Managed by Netsuite",
1522
+ compact: ""
1523
+ })) : H("", !0)
1524
+ ]),
1525
+ p(Io, {
1526
+ class: "w-full",
1527
+ ref_key: "hasValidationExpose",
1528
+ ref: j,
1529
+ modelValue: a(i),
1530
+ "onUpdate:modelValue": M[0] || (M[0] = (L) => ct(i) ? i.value = L : null),
1531
+ mode: _.mode,
1532
+ disabled: V.value,
1533
+ purchaseOrderTemplateIds: r.value,
1534
+ wastageTemplateIds: T.value,
1535
+ closingTemplateIds: A.value,
1536
+ "onClick:submit": M[1] || (M[1] = (L) => ee()),
1537
+ "onUpdate:purchaseOrderTemplateIds": me,
1538
+ "onUpdate:wastageTemplateIds": pe,
1539
+ "onUpdate:closingTemplateIds": we
1540
+ }, null, 8, ["modelValue", "mode", "disabled", "purchaseOrderTemplateIds", "wastageTemplateIds", "closingTemplateIds"])
1541
+ ])
1542
+ ]),
1543
+ _: 1
1544
+ }, 8, ["model-value", "header"]);
1545
+ };
1546
+ }
1547
+ });
1548
+ function Mo() {
1549
+ return `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Vn()}`;
1550
+ }
1551
+ const Eo = {
1552
+ _id: "",
1553
+ name: "",
1554
+ abbrev: "",
1555
+ precision: 0,
1556
+ measurements: []
1557
+ };
1558
+ function Ao(u) {
1559
+ return !u || Object.keys(u).length === 0 ? "" : Object.entries(u).map(([o, v]) => `${o}: ${v}`).join(", ");
1560
+ }
1561
+ function Ut(u) {
1562
+ if (!u || u.trim() === "")
1563
+ return;
1564
+ const o = {}, v = u.split(",").map((l) => l.trim());
1565
+ for (const l of v) {
1566
+ const c = l.indexOf(":");
1567
+ if (c > 0) {
1568
+ const g = l.substring(0, c).trim(), h = l.substring(c + 1).trim();
1569
+ g && h && (o[g] = h);
1570
+ }
1571
+ }
1572
+ return Object.keys(o).length > 0 ? o : void 0;
1573
+ }
1574
+ function Uo(u) {
1575
+ var v, l, c, g, h;
1576
+ return {
1577
+ code: u.code,
1578
+ name: u.name,
1579
+ unit: ((v = u.unit.measurements.find((y) => y.id === u.trackingMeasurement)) == null ? void 0 : v.abbrev) ?? u.unit.abbrev,
1580
+ baseUnit: u.unit.abbrev,
1581
+ valuationMethod: u.valuation ?? "WAVG",
1582
+ pricePerUnit: (l = u.defaultCost) != null && l.costPerUnit ? +Ct((c = u.defaultCost) == null ? void 0 : c.costPerUnit) : 0,
1583
+ thresholdLow: ((g = u.thresholds) == null ? void 0 : g.low) ?? _e().low,
1584
+ thresholdMid: ((h = u.thresholds) == null ? void 0 : h.mid) ?? _e().mid,
1585
+ customAttributes: Ao(u.customAttributes)
1586
+ };
1587
+ }
1588
+ function $t() {
1589
+ var c;
1590
+ const u = [
1591
+ {
1592
+ id: "code",
1593
+ name: "Code"
1594
+ },
1595
+ {
1596
+ id: "name",
1597
+ name: "Name"
1598
+ },
1599
+ {
1600
+ id: "unit",
1601
+ name: "Unit"
1602
+ },
1603
+ {
1604
+ id: "baseUnit",
1605
+ name: "Base unit"
1606
+ }
1607
+ ], o = Ge(), v = Fe(), l = Oe(v.currentCountry.value);
1608
+ return o.enableTotalCost && u.push(
1609
+ {
1610
+ id: "valuationMethod",
1611
+ name: "Valuation method"
1612
+ },
1613
+ {
1614
+ id: "pricePerUnit",
1615
+ name: `Price per unit (${l == null ? void 0 : l.currency})`
1616
+ }
1617
+ ), ((c = v.currentBusiness.value) == null ? void 0 : c.menuVersion) === "v4" && u.push(
1618
+ {
1619
+ id: "thresholdLow",
1620
+ name: "Show RED when remaining"
1621
+ },
1622
+ {
1623
+ id: "thresholdMid",
1624
+ name: "Show YELLOW when remaining"
1625
+ }
1626
+ ), u.push({
1627
+ id: "customAttributes",
1628
+ name: "Custom Attributes"
1629
+ }), u;
1630
+ }
1631
+ function $o() {
1632
+ const o = de().skus.map(Uo), l = Fe().currentBusiness.value, c = $t(), g = [
1633
+ ["Business name:", l == null ? void 0 : l.name],
1634
+ ["Business ID:", l == null ? void 0 : l._id],
1635
+ ["Menu version", l == null ? void 0 : l.menuVersion],
1636
+ [],
1637
+ c.map((s) => s.name),
1638
+ ...o.map((s) => c.map((m) => s[m.id]))
1639
+ ], h = c.map((s) => `system:${s.id}`), y = Ft(g, h), n = `${l == null ? void 0 : l.name} ingredients (${tn(/* @__PURE__ */ new Date())}).xlsx`;
1640
+ return Mt(y, n), n;
1641
+ }
1642
+ function Ro() {
1643
+ const o = Fe().currentBusiness.value, v = $t(), l = [
1644
+ ["Business name:", o == null ? void 0 : o.name],
1645
+ ["Business ID:", o == null ? void 0 : o._id],
1646
+ ["Menu version", o == null ? void 0 : o.menuVersion],
1647
+ [],
1648
+ v.map((y) => y.name)
1649
+ ], c = v.map((y) => `system:${y.id}`), g = Ft(l, c), h = "FeedMe ingredients template.xlsx";
1650
+ return Mt(g, h), h;
1651
+ }
1652
+ function Po(u) {
1653
+ const [
1654
+ o,
1655
+ v,
1656
+ l,
1657
+ c,
1658
+ g,
1659
+ h,
1660
+ ...y
1661
+ ] = on(u);
1662
+ if (!o || !o.length || o.some((r) => r.length && !r.startsWith("system:")))
1663
+ throw new Error("Missing meta header. Excel file does not come from the template.");
1664
+ const n = o.map((r) => r.split(":")[1]), m = ["code", "name", "unit", "baseUnit"].filter((r) => !n.includes(r));
1665
+ if (m.length)
1666
+ throw new Error(
1667
+ `Missing meta headers (${m.join()}). Excel file does not come from the template.`
1668
+ );
1669
+ return y.map((r, T) => {
1670
+ const A = {};
1671
+ for (const R in n) {
1672
+ const G = n[R];
1673
+ Object.assign(A, { [G]: r[R] });
1674
+ }
1675
+ return {
1676
+ index: T,
1677
+ data: A
1678
+ };
1679
+ });
1680
+ }
1681
+ function xt(u, o, v) {
1682
+ var j;
1683
+ const c = de().units, g = new Array(), h = v.filter((V) => V.data.code === u.code);
1684
+ h.length > 1 && g.push(
1685
+ `Code ${u.code} is already used in row ${h.map((V) => V.index + 6).join()}.`
1686
+ );
1687
+ const y = c.find((V) => V.abbrev === u.baseUnit), n = y == null ? void 0 : y.measurements.find((V) => V.abbrev === u.unit);
1688
+ if (!y)
1689
+ g.push(`Cannot find base unit of symbol ${u.baseUnit}.`);
1690
+ else if (u.baseUnit !== u.unit && !n) {
1691
+ const V = `Cannot find unit conversion for ${u.baseUnit} with symbol ${u.unit || "[empty]"}.`;
1692
+ g.push(V);
1693
+ }
1694
+ const s = Ce.options.find(
1695
+ (V) => V === u.valuationMethod
1696
+ );
1697
+ u.valuationMethod && !s && g.push(
1698
+ `Expected valuation method to be one of ${Ce.options.join()} but got ${u.valuationMethod} instead.`
1699
+ );
1700
+ const i = Fe().currentCountry.value, r = (V) => `${V}`.length && ln()(V) === !0, T = r(`${u.pricePerUnit}`) === !0 ? {
1701
+ costPerUnit: {
1702
+ ...St(Number(u.pricePerUnit) || 0),
1703
+ currency: ((j = Oe(i)) == null ? void 0 : j.currency) ?? "MYR"
1704
+ },
1705
+ measurement: n
1706
+ } : void 0, A = r(`${u.thresholdLow}`) && r(`${u.thresholdMid}`) ? {
1707
+ low: Number(u.thresholdLow) || 0,
1708
+ mid: Number(u.thresholdMid) || 0
1709
+ } : void 0, R = "customAttributes" in u ? Ut(u.customAttributes) : null;
1710
+ return {
1711
+ type: "create",
1712
+ sku: {
1713
+ _id: Mo(),
1714
+ code: u.code,
1715
+ name: u.name,
1716
+ unit: y ?? c.find((V) => V) ?? Eo,
1717
+ trackingMeasurement: n == null ? void 0 : n.id,
1718
+ valuation: s,
1719
+ defaultCost: T,
1720
+ thresholds: A,
1721
+ ...R !== null && { customAttributes: R }
1722
+ },
1723
+ errors: g,
1724
+ excelRowNumber: o + 6
1725
+ };
1726
+ }
1727
+ function Oo(u) {
1728
+ try {
1729
+ const o = Po(u).filter((s) => s.data.code), l = de().skus, c = nn(l, "code"), g = o.filter((s) => !c[s.data.code]), h = o.filter((s) => c[s.data.code]), y = g.map(
1730
+ (s) => xt(s.data, s.index, o)
1731
+ ), n = h.map((s) => {
1732
+ const m = xt(s.data, s.index, o), i = c[s.data.code];
1733
+ let r = i.customAttributes;
1734
+ return "customAttributes" in s.data && (r = Ut(s.data.customAttributes)), {
1735
+ ...m,
1736
+ type: "update",
1737
+ original: i,
1738
+ sku: {
1739
+ // to maintain original props not in the import excel, e.g. inventory binding, etc...
1740
+ ...i,
1741
+ code: m.sku.code || i.code,
1742
+ name: m.sku.name || i.name,
1743
+ unit: m.sku.unit || i.unit,
1744
+ trackingMeasurement: m.sku.trackingMeasurement || i.trackingMeasurement,
1745
+ valuation: m.sku.valuation || i.valuation,
1746
+ defaultCost: m.sku.defaultCost || i.defaultCost,
1747
+ thresholds: m.sku.thresholds || i.thresholds,
1748
+ customAttributes: r
1749
+ }
1750
+ };
1751
+ });
1752
+ return {
1753
+ invalidExcel: !1,
1754
+ importCreateResult: y,
1755
+ importUpdateResult: n
1756
+ };
1757
+ } catch (o) {
1758
+ return {
1759
+ invalidExcel: !0,
1760
+ invalidExcelMessage: (o == null ? void 0 : o.message) ?? "Invalid excel",
1761
+ importCreateResult: [],
1762
+ importUpdateResult: []
1763
+ };
1764
+ }
1765
+ }
1766
+ const Bo = { class: "flex items-center gap-12 pl-8" }, Do = { class: "flex flex-col" }, No = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, zo = {
1767
+ key: 0,
1768
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
1769
+ }, Lo = { key: 0 }, kt = /* @__PURE__ */ ye({
1770
+ __name: "ImportIngredientItem",
1771
+ props: {
1772
+ type: {},
1773
+ code: {},
1774
+ name: {},
1775
+ errors: {}
1776
+ },
1777
+ setup(u) {
1778
+ return (o, v) => {
1779
+ const l = S("FmIcon"), c = S("FmTooltip");
1780
+ return f(), E("div", Bo, [
1781
+ v[0] || (v[0] = d("div", null, "•", -1)),
1782
+ d("div", Do, [
1783
+ d("div", No, [
1784
+ d("div", {
1785
+ class: ae({
1786
+ "text-fm-color-system-error-300": o.errors.length
1787
+ })
1788
+ }, [
1789
+ qe($(o.name) + " ", 1),
1790
+ o.type === "create" ? (f(), E("span", zo, "(new)")) : H("", !0)
1791
+ ], 2),
1792
+ o.errors.length ? (f(), E("div", Lo, [
1793
+ p(c, { "z-index": 50 }, {
1794
+ content: w(() => [
1795
+ d("ol", null, [
1796
+ (f(!0), E(X, null, ue(o.errors, (g, h) => (f(), E("li", { key: h }, $(g), 1))), 128))
1797
+ ])
1798
+ ]),
1799
+ default: w(() => [
1800
+ p(l, {
1801
+ name: "error",
1802
+ size: "sm",
1803
+ color: "system-error-300"
1804
+ })
1805
+ ]),
1806
+ _: 1
1807
+ })
1808
+ ])) : H("", !0)
1809
+ ]),
1810
+ d("div", {
1811
+ class: ae([
1812
+ "fm-typo-en-body-sm-400",
1813
+ {
1814
+ "text-fm-color-system-error-200": o.errors.length,
1815
+ "text-fm-color-typo-secondary": !o.errors.length
1816
+ }
1817
+ ])
1818
+ }, $(o.code), 3)
1819
+ ])
1820
+ ]);
1821
+ };
1822
+ }
1823
+ }), jo = { class: "flex flex-col gap-24" }, Ho = { class: "fm-typo-en-body-md-400" }, Wo = { class: "flex flex-col gap-8" }, Yo = { class: "line-clamp-2 text-ellipsis break-all" }, qo = {
1824
+ key: 2,
1825
+ class: "shrink-0"
1826
+ }, Go = {
1827
+ key: 0,
1828
+ class: "flex flex-col"
1829
+ }, Ko = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, Jo = {
1830
+ key: 0,
1831
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
1832
+ }, Qo = { class: "fm-typo-en-body-lg-600" }, Zo = /* @__PURE__ */ ye({
1833
+ __name: "ImportIngredients",
1834
+ setup(u) {
1835
+ const o = B(null), v = yn(), l = Se(), c = B(!1), g = B(new Array()), h = B([]), y = B([]), n = k(
1836
+ () => !!g.value.length || h.value.some((r) => r.errors.length) || y.value.some((r) => r.errors.length)
1837
+ ), s = k(
1838
+ () => !!h.value.length || !!y.value.length
1839
+ ), { t: m } = ge();
1840
+ async function i(r) {
1841
+ g.value = [], h.value = [], y.value = [];
1842
+ try {
1843
+ c.value = !0;
1844
+ const [T] = await Promise.all([
1845
+ sn(r),
1846
+ // fake buffer
1847
+ new Promise((G) => setTimeout(G, 1e3))
1848
+ ]), A = T.SheetNames.find((G) => G);
1849
+ if (!A) {
1850
+ g.value.push(m("inventory.ingredient.import.fileError.noSheet"));
1851
+ return;
1852
+ }
1853
+ const R = Oo(T.Sheets[A]);
1854
+ if (R.invalidExcel) {
1855
+ g.value.push(R.invalidExcelMessage ?? m("inventory.ingredient.import.fileError.invalidExcel"));
1856
+ return;
1857
+ }
1858
+ if (h.value = R.importCreateResult, y.value = R.importUpdateResult, !h.value.length && !y.value.length) {
1859
+ g.value.push(m("inventory.ingredient.import.fileError.noData"));
1860
+ return;
1861
+ }
1862
+ v.emitData(R);
1863
+ } catch (T) {
1864
+ l.open({
1865
+ title: m("inventory.ingredient.import.fileError.unableToRead"),
1866
+ message: T == null ? void 0 : T.message,
1867
+ type: "error"
1868
+ }), console.error("Error in reading file", T);
1869
+ } finally {
1870
+ g.value.length && l.open({
1871
+ title: m("inventory.ingredient.import.fileError.invalidExcel"),
1872
+ type: "error"
1873
+ }), c.value = !1;
1874
+ }
1875
+ }
1876
+ return wt(o, (r) => {
1877
+ r && i(r);
1878
+ }), (r, T) => {
1879
+ const A = S("FmCircularProgress"), R = S("FmIcon"), G = S("FmButton");
1880
+ return f(), E("div", jo, [
1881
+ d("div", Ho, $(a(m)("inventory.ingredient.import.uploadDescription")), 1),
1882
+ p(an, {
1883
+ class: ae({
1884
+ "w-full": !0,
1885
+ "h-[200px]": !o.value
1886
+ }),
1887
+ accept: ".xlsx",
1888
+ onFileUpload: T[0] || (T[0] = (U) => o.value = U),
1889
+ label: a(m)("inventory.ingredient.import.uploadTemplate"),
1890
+ "button-label": a(m)("inventory.ingredient.import.selectFile")
1891
+ }, Tt({ _: 2 }, [
1892
+ o.value ? {
1893
+ name: "default",
1894
+ fn: w(({ openFileDialog: U }) => [
1895
+ d("div", Wo, [
1896
+ d("div", {
1897
+ class: ae([
1898
+ "fm-corner-radius-md p-16 flex items-center gap-16",
1899
+ {
1900
+ "border border-fm-color-neutral-gray-100": c.value,
1901
+ "border border-fm-color-neutral-gray-200": !c.value && !n.value,
1902
+ "border border-fm-color-system-error-200": n.value
1903
+ }
1904
+ ])
1905
+ }, [
1906
+ c.value ? (f(), D(A, {
1907
+ key: 0,
1908
+ size: "md",
1909
+ color: "neutral-gray-200"
1910
+ })) : (f(), D(R, {
1911
+ key: 1,
1912
+ name: n.value ? "error" : "attach_file",
1913
+ outline: "",
1914
+ color: n.value ? "system-error-300" : void 0
1915
+ }, null, 8, ["name", "color"])),
1916
+ d("div", {
1917
+ class: ae([
1918
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
1919
+ {
1920
+ "text-fm-color-typo-disabled": c.value,
1921
+ "text-fm-color-typo-primary": !c.value
1922
+ }
1923
+ ])
1924
+ }, [
1925
+ d("div", Yo, $(o.value.name), 1)
1926
+ ], 2),
1927
+ c.value ? H("", !0) : (f(), E("div", qo, [
1928
+ p(G, {
1929
+ label: a(m)("inventory.ingredient.import.replaceFile"),
1930
+ variant: n.value ? "destructive" : "secondary",
1931
+ "prepend-icon": n.value ? void 0 : "autorenew",
1932
+ onClick: U
1933
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
1934
+ ]))
1935
+ ], 2),
1936
+ g.value.length ? (f(), E("div", Go, [
1937
+ (f(!0), E(X, null, ue(g.value, (j, V) => (f(), E("div", {
1938
+ key: V,
1939
+ class: "flex gap-8 items-center"
1940
+ }, [
1941
+ p(R, {
1942
+ name: "error",
1943
+ size: "sm",
1944
+ color: "system-error-300"
1945
+ }),
1946
+ d("div", Ko, $(j), 1)
1947
+ ]))), 128))
1948
+ ])) : H("", !0)
1949
+ ])
1950
+ ]),
1951
+ key: "0"
1952
+ } : void 0
1953
+ ]), 1032, ["class", "label", "button-label"]),
1954
+ s.value ? (f(), E("div", Jo, [
1955
+ d("div", Qo, $(a(m)("inventory.ingredient.import.summary")), 1),
1956
+ (f(!0), E(X, null, ue(h.value, (U) => (f(), D(kt, {
1957
+ key: U.sku._id,
1958
+ code: U.sku.code,
1959
+ name: U.sku.name,
1960
+ errors: U.errors,
1961
+ type: "create"
1962
+ }, null, 8, ["code", "name", "errors"]))), 128)),
1963
+ (f(!0), E(X, null, ue(y.value, (U) => (f(), D(kt, {
1964
+ key: U.sku._id,
1965
+ code: U.sku.code,
1966
+ name: U.sku.name,
1967
+ errors: U.errors,
1968
+ type: "update"
1969
+ }, null, 8, ["code", "name", "errors"]))), 128))
1970
+ ])) : H("", !0)
1971
+ ]);
1972
+ };
1973
+ }
1974
+ }), Xo = { class: "flex flex-col py-8" }, el = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, tl = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, hl = /* @__PURE__ */ ye({
1975
+ __name: "IngredientsView",
1976
+ setup(u) {
1977
+ const o = de(), v = Be(), l = k(() => [
1978
+ {
1979
+ type: "string",
1980
+ key: "skuCode",
1981
+ entity: "sku",
1982
+ values: o.skus.map((b) => b.code)
1983
+ },
1984
+ {
1985
+ type: "string",
1986
+ key: "skuUnitAbbrev",
1987
+ entity: "sku",
1988
+ values: o.units.map((b) => b.abbrev)
1989
+ },
1990
+ {
1991
+ type: "string",
1992
+ key: "status",
1993
+ entity: "sku",
1994
+ values: ["Inactive", "Active"]
1995
+ }
1996
+ ]), c = B({
1997
+ logic: "AND",
1998
+ rules: [
1999
+ {
2000
+ property: "status",
2001
+ operator: "$in",
2002
+ value: ["Active"],
2003
+ type: "string"
2004
+ }
2005
+ ]
2006
+ }), g = k(
2007
+ () => new Set(v.getAvailableItems(v.businessSubsidiaryId))
2008
+ ), h = k(() => {
2009
+ if (!c.value)
2010
+ return o.skus;
2011
+ const F = rn.build(c.value);
2012
+ return o.skus.filter((b) => v.isEnabled && ke.value && g.value && !g.value.has(b._id) ? !1 : un(
2013
+ {
2014
+ skuCode: b.code,
2015
+ skuUnitAbbrev: b.unit.abbrev,
2016
+ status: b.isInactive ? "Inactive" : "Active"
2017
+ },
2018
+ F
2019
+ ));
2020
+ }), y = dn(), n = Ke(), s = In(), m = Se(), { t: i } = ge(), { createIngredient: r, updateIngredient: T } = Ye(), { ingredientDialogProps: A, ingredientViewLoading: R } = xn(Ye()), { columnDefs: G } = Cn();
2021
+ function U(F) {
2022
+ switch (F) {
2023
+ case "add":
2024
+ return v.isEnabled ? void 0 : r();
2025
+ case "import":
2026
+ return M();
2027
+ case "export":
2028
+ return _();
2029
+ }
2030
+ }
2031
+ const j = B(""), V = B(!1), xe = k(() => V.value || R.value), ke = B(!1), { breakpoints: be } = gn(), ce = k(() => be.value.xs || be.value.sm), se = k(() => ce.value ? 10 : 20), he = cn(), ee = B(!1), me = [
2032
+ {
2033
+ value: "import",
2034
+ label: i("common.import")
2035
+ },
2036
+ {
2037
+ value: "export",
2038
+ label: i("common.export")
2039
+ }
2040
+ ];
2041
+ function pe(F) {
2042
+ switch (ee.value = !1, F) {
2043
+ case "import":
2044
+ return M();
2045
+ case "export":
2046
+ return _();
2047
+ }
2048
+ }
2049
+ const we = k(() => [
2050
+ ...v.isEnabled ? [] : [
2051
+ {
2052
+ label: i("inventory.ingredient.create.title"),
2053
+ value: "add",
2054
+ isPrimary: !0,
2055
+ prependIcon: "add"
2056
+ }
2057
+ ],
2058
+ { label: i("common.import"), value: "import" },
2059
+ { label: i("common.export"), value: "export" }
2060
+ ]);
2061
+ function _() {
2062
+ const F = $o();
2063
+ m.open({
2064
+ title: i("inventory.ingredient.export.success"),
2065
+ message: i("inventory.ingredient.export.filename", [F]),
2066
+ type: "success"
2067
+ });
2068
+ }
2069
+ function M() {
2070
+ n.open({
2071
+ title: i("inventory.ingredient.import.title"),
2072
+ contentComponent: Zo,
2073
+ overlay: !0,
2074
+ closeButton: !0,
2075
+ primaryActions: {
2076
+ text: i("common.import"),
2077
+ close: !1
2078
+ },
2079
+ secondaryActions: {
2080
+ text: i("common.close"),
2081
+ close: !0
2082
+ },
2083
+ tertiaryActions: {
2084
+ text: i("inventory.ingredient.import.actions.downloadTemplate"),
2085
+ close: !1,
2086
+ variant: "plain"
2087
+ }
2088
+ }).onPrimary((F) => {
2089
+ if (!F) {
2090
+ m.open({
2091
+ title: i("inventory.ingredient.import.error.noData"),
2092
+ type: "error"
2093
+ });
2094
+ return;
2095
+ }
2096
+ if (!F.importCreateResult.length && !F.importUpdateResult.length) {
2097
+ m.open({
2098
+ title: i("inventory.ingredient.import.error.invalidContent"),
2099
+ message: i("inventory.ingredient.import.error.noImportData"),
2100
+ type: "error"
2101
+ });
2102
+ return;
2103
+ }
2104
+ if (F.importCreateResult.some((b) => b.errors.length) || F.importUpdateResult.some((b) => b.errors.length)) {
2105
+ m.open({
2106
+ title: i("inventory.ingredient.import.error.invalidContent"),
2107
+ message: i("inventory.ingredient.import.error.hasErrors"),
2108
+ type: "error"
2109
+ });
2110
+ return;
2111
+ }
2112
+ n.close(), K(F);
2113
+ }).onTertiary(Ro);
2114
+ }
2115
+ async function K(F) {
2116
+ V.value = !0;
2117
+ try {
2118
+ const b = [
2119
+ ...F.importCreateResult.map(({ sku: N }) => ({ type: "create", sku: N })),
2120
+ ...F.importUpdateResult.map(({ sku: N }) => ({ type: "update", sku: N }))
2121
+ ], L = 100;
2122
+ let Q = 0;
2123
+ const re = () => {
2124
+ Q += L, m.open({
2125
+ title: i("inventory.ingredient.import.progress", [
2126
+ Math.min(Q, b.length),
2127
+ b.length
2128
+ ])
2129
+ });
2130
+ }, P = new Array();
2131
+ for (const N of b.chunk(100)) {
2132
+ re();
2133
+ try {
2134
+ const O = await o.importSkus({
2135
+ create: N.filter((Y) => Y.type === "create").map((Y) => Y.sku),
2136
+ update: N.filter((Y) => Y.type === "update").map((Y) => Y.sku)
2137
+ });
2138
+ P.push(...O.errors);
2139
+ } catch (O) {
2140
+ P.push(
2141
+ ...N.map((Y) => {
2142
+ const oe = {
2143
+ module: fn.enum.sku,
2144
+ _id: Y.sku._id,
2145
+ name: Y.sku.name,
2146
+ message: (O == null ? void 0 : O.stack) ?? O
2147
+ };
2148
+ return {
2149
+ data: Y.sku,
2150
+ error: [oe]
2151
+ };
2152
+ })
2153
+ );
2154
+ }
2155
+ }
2156
+ m.open({
2157
+ title: i("inventory.ingredient.import.success"),
2158
+ type: "success"
2159
+ }), P.length && s.alert(
2160
+ "Some operation failed",
2161
+ J(
2162
+ "div",
2163
+ { class: "flex flex-col gap-8" },
2164
+ P.map(
2165
+ (N) => J("div", { class: "flex flex-col" }, [
2166
+ J("div", { class: "fm-typo-en-body-lg-600" }, `(${N.data.code}) ${N.data.name}`),
2167
+ J(
2168
+ "div",
2169
+ { class: "fm-typo-en-body-lg-400" },
2170
+ `${N.error.map((O) => (O == null ? void 0 : O.message) ?? "Unknown error").join(", ")}`
2171
+ )
2172
+ ])
2173
+ )
2174
+ )
2175
+ );
2176
+ } catch (b) {
2177
+ m.open({
2178
+ title: i("inventory.ingredient.import.error.failed"),
2179
+ message: i("inventory.ingredient.import.error.systemMessage", [b == null ? void 0 : b.message]),
2180
+ type: "error"
2181
+ }), console.error("Error in importing skus", F, b);
2182
+ } finally {
2183
+ V.value = !1;
2184
+ }
2185
+ }
2186
+ return (F, b) => {
2187
+ const L = S("FmTable"), Q = S("FmCollapsibleTabs"), re = S("FmBottomSheet");
2188
+ return f(), D(mn, {
2189
+ title: a(i)("inventory.ingredient.title"),
2190
+ actions: we.value,
2191
+ "onClick:action": U
2192
+ }, {
2193
+ default: w(() => [
2194
+ d("div", {
2195
+ class: ae([
2196
+ "flex flex-col gap-8 max-h-full",
2197
+ {
2198
+ "p-0": ce.value,
2199
+ "px-24 ": !ce.value
2200
+ }
2201
+ ])
2202
+ }, [
2203
+ p(pn, {
2204
+ searchable: "",
2205
+ search: j.value,
2206
+ "onUpdate:search": b[0] || (b[0] = (P) => j.value = P),
2207
+ filterable: "",
2208
+ "filter-attributes": l.value,
2209
+ filter: c.value,
2210
+ "onUpdate:filter": b[1] || (b[1] = (P) => c.value = P)
2211
+ }, null, 8, ["search", "filter-attributes", "filter"]),
2212
+ (f(), D(L, {
2213
+ key: JSON.stringify(c.value),
2214
+ style: Wt(a(he).tableHeight),
2215
+ "column-defs": a(G),
2216
+ "row-data": h.value,
2217
+ "search-value": j.value,
2218
+ columnVisibility: {
2219
+ netsuiteSubsidiary: a(v).isEnabled
2220
+ },
2221
+ loading: (!a(y)._currentLocation || xe.value) && a(v).isReady,
2222
+ "loading-text": "Loading",
2223
+ onRowClick: b[2] || (b[2] = (P) => a(T)(P.original)),
2224
+ "page-size": se.value
2225
+ }, {
2226
+ "list-row": w((P) => [
2227
+ p(vn, {
2228
+ row: P,
2229
+ onRowClick: a(T)
2230
+ }, Tt({
2231
+ default: w((N) => {
2232
+ var O, Y, oe, ve, Me, Ee, Ae, Ue, le, ie;
2233
+ return [
2234
+ d("div", Xo, [
2235
+ d("div", el, [
2236
+ p(a(bt), {
2237
+ render: (oe = (Y = (O = N.code) == null ? void 0 : O.column) == null ? void 0 : Y.columnDef) == null ? void 0 : oe.cell,
2238
+ props: (Me = (ve = N.code) == null ? void 0 : ve.getContext) == null ? void 0 : Me.call(ve)
2239
+ }, null, 8, ["render", "props"])
2240
+ ]),
2241
+ d("div", tl, [
2242
+ p(a(bt), {
2243
+ render: (Ue = (Ae = (Ee = N.name) == null ? void 0 : Ee.column) == null ? void 0 : Ae.columnDef) == null ? void 0 : Ue.cell,
2244
+ props: (ie = (le = N.name) == null ? void 0 : le.getContext) == null ? void 0 : ie.call(le)
2245
+ }, null, 8, ["render", "props"])
2246
+ ])
2247
+ ])
2248
+ ];
2249
+ }),
2250
+ _: 2
2251
+ }, [
2252
+ V.value ? {
2253
+ name: "loading-text",
2254
+ fn: w(() => [
2255
+ d("div", null, $(a(i)("inventory.ingredient.table.importing")), 1)
2256
+ ]),
2257
+ key: "0"
2258
+ } : void 0
2259
+ ]), 1032, ["row", "onRowClick"])
2260
+ ]),
2261
+ _: 1
2262
+ }, 8, ["style", "column-defs", "row-data", "search-value", "columnVisibility", "loading", "page-size"]))
2263
+ ], 2),
2264
+ (f(), D(mt, { to: "body" }, [
2265
+ p(Fo, Yt(qt(a(A))), null, 16)
2266
+ ])),
2267
+ (f(), D(mt, { to: "body" }, [
2268
+ p(re, {
2269
+ "dismiss-away": "",
2270
+ modelValue: ee.value,
2271
+ "onUpdate:modelValue": b[4] || (b[4] = (P) => ee.value = P)
2272
+ }, {
2273
+ default: w(() => [
2274
+ p(Q, {
2275
+ class: "pb-8",
2276
+ items: me,
2277
+ "onUpdate:modelValue": b[3] || (b[3] = (P) => pe(P))
2278
+ })
2279
+ ]),
2280
+ _: 1
2281
+ }, 8, ["modelValue"])
2282
+ ]))
2283
+ ]),
2284
+ _: 1
2285
+ }, 8, ["title", "actions"]);
2286
+ };
2287
+ }
2288
+ });
2289
+ export {
2290
+ hl as default
2291
+ };