@feedmepos/mf-inventory-portal 1.2.10-dev.3 → 1.2.10-dev.4

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