@feedmepos/mf-inventory-portal 1.2.12-dev.3 → 1.2.13

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 (74) hide show
  1. package/dist/{App-D5hXQpVn.js → App-ZoXow3DD.js} +40 -44
  2. package/dist/{ApprovalView-B__WDklZ.js → ApprovalView-BWX6xBQs.js} +30 -30
  3. package/dist/{BindingsDialog-DXdwRSnn.js → BindingsDialog-CuwkcDKX.js} +2 -2
  4. package/dist/{BindingsPicker-CqAD3aHc.js → BindingsPicker-BibFsY0g.js} +1 -1
  5. package/dist/{BindingsTable-DVNjpusl.js → BindingsTable-AdjKwSPH.js} +1 -1
  6. package/dist/{ClosingDraftView-DL678GBB.js → ClosingDraftView-DWFHP9nE.js} +129 -129
  7. package/dist/{ClosingTemplateView-DThiXLtp.js → ClosingTemplateView-DOCF5f_u.js} +28 -28
  8. package/dist/{DeliveryOrderPrintPreview-B2MB9S6a.js → DeliveryOrderPrintPreview-DNDtL_Vo.js} +1 -1
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BNxs6Bcr.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BWhINOE8.js} +3 -3
  10. package/dist/{FmMultiselectDialog-B45ZLjVp.js → FmMultiselectDialog-Dfo04ak5.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-D8ks6AEM.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DGVs4zLl.js} +45 -45
  12. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-C5zIvG2h.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-BESx2u4Y.js} +1 -1
  13. package/dist/{IngredientGroupView-D95dFXIZ.js → IngredientGroupView-M9sXlnE0.js} +32 -31
  14. package/dist/IngredientsView-DUwhH3j1.js +2475 -0
  15. package/dist/{IntegrationView-9m3N_9lW.js → IntegrationView-BlUNz1yc.js} +57 -57
  16. package/dist/{InventoryBindingForm-kLoQskao.js → InventoryBindingForm-CvQ5zh6v.js} +1 -1
  17. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-BytErBcK.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-BEAEmPsU.js} +31 -31
  18. package/dist/{InventoryBindingSummary-Dg0FH7ad.js → InventoryBindingSummary-CsJ-6G2P.js} +1 -1
  19. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BKrUNLuG.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DjN_ktl1.js} +1 -1
  20. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-BL1f817e.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BN_e7k7U.js} +1 -1
  21. package/dist/{PublishView-BcOHSAj3.js → PublishView-DZgCyLK2.js} +15 -15
  22. package/dist/{PurchaseOrderPrintPreview-UfF8RVkv.js → PurchaseOrderPrintPreview-CB2xvQ33.js} +1 -1
  23. package/dist/{ReceiveRequestView-D_y_xNUb.js → ReceiveRequestView-DgDHOS-Y.js} +63 -62
  24. package/dist/RecipeView-DQDfwCJd.js +621 -0
  25. package/dist/{StockView-ciU6aAV7.js → StockView-eJOngk08.js} +166 -165
  26. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-XwDTGpR-.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-BMFfegsk.js} +1 -1
  27. package/dist/{SupplierView-DFwtALPg.js → SupplierView-BS8rBAKC.js} +492 -490
  28. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-w98ibfql.js +3060 -0
  29. package/dist/{TransferTemplateView-BXr_GqTi.js → TransferTemplateView-By5Ci4Yg.js} +48 -48
  30. package/dist/UnitView-DmuWMFlA.js +667 -0
  31. package/dist/{WarehouseView-BYd0bPhi.js → WarehouseView-4ZLSJXYc.js} +32 -32
  32. package/dist/api/inventory.d.ts +0 -306
  33. package/dist/api/purchase-order.d.ts +0 -1
  34. package/dist/{app-Bb0-8bRg.js → app-D2lun71R.js} +11108 -11723
  35. package/dist/app.d.ts +0 -421
  36. package/dist/app.js +1 -1
  37. package/dist/array-Ca8T3f_G.js +44 -0
  38. package/dist/{closing-template-DPVNEyI7.js → closing-template-Cm1TtVzm.js} +1 -1
  39. package/dist/{decimal-BdBZYISm.js → decimal-eeicE4jp.js} +1 -1
  40. package/dist/{format-unit-display-DlmCwWo_.js → format-unit-display-vHKazw0l.js} +25 -25
  41. package/dist/helper/number.d.ts +0 -1
  42. package/dist/{index-CqBKFj1B.js → index-C5s-1g7c.js} +1 -1
  43. package/dist/{index-CKFmV1Pk.js → index-DvX9cMJV.js} +1 -1
  44. package/dist/{purchase-order-template-CLtEYr5E.js → purchase-order-template-uTs7bR89.js} +1 -1
  45. package/dist/router/name.d.ts +0 -1
  46. package/dist/{stock-nHQhfe2W.js → stock-CL2LNdXp.js} +1 -1
  47. package/dist/stores/feature.d.ts +0 -2
  48. package/dist/stores/inventory.d.ts +199 -26
  49. package/dist/{supplier-DuOjLpOa.js → supplier-CuzoW2k4.js} +1 -1
  50. package/dist/tsconfig.app.tsbuildinfo +1 -1
  51. package/dist/{use-ingredient-select-dialog-B-11Eqlm.js → use-ingredient-select-dialog-Cpg4lHHC.js} +1 -1
  52. package/dist/{use-inventory-binding-dialog-DhLSdRtp.js → use-inventory-binding-dialog-h4M4ICQK.js} +1 -1
  53. package/dist/views/ingredients/helper/import-export.helper.d.ts +1 -3
  54. package/dist/views/recipe/RecipeView.vue.d.ts +0 -1
  55. package/dist/views/unit/UnitView.vue.d.ts +0 -1
  56. package/package.json +2 -2
  57. package/dist/ImportView-EXm_g_jD.js +0 -1303
  58. package/dist/IngredientsView-MF1USuZI.js +0 -2240
  59. package/dist/RecipeView-DOaU9GIF.js +0 -636
  60. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CdA5_lEz.js +0 -3221
  61. package/dist/UnitView-CAXHvh3n.js +0 -674
  62. package/dist/import-export.helper-B04wszRI.js +0 -243
  63. package/dist/views/import/ImportView.vue.d.ts +0 -3
  64. package/dist/views/import/components/ImportDialog.vue.d.ts +0 -2
  65. package/dist/views/import/helper/import-export.helper.d.ts +0 -4
  66. package/dist/views/receive-request/components/delivery-order-form/SystemTrailDialog.vue.d.ts +0 -17
  67. package/dist/views/recipe/components/import-recipes/ImportRecipeItem.vue.d.ts +0 -16
  68. package/dist/views/recipe/components/import-recipes/ImportRecipes.vue.d.ts +0 -2
  69. package/dist/views/recipe/helper/import-recipe.d.ts +0 -48
  70. package/dist/views/unit/components/import-units/ImportUnitItem.vue.d.ts +0 -12
  71. package/dist/views/unit/components/import-units/ImportUnitItemProps.d.ts +0 -6
  72. package/dist/views/unit/components/import-units/ImportUnits.vue.d.ts +0 -9
  73. package/dist/views/unit/components/import-units/ImportUnitsProps.d.ts +0 -5
  74. package/dist/views/unit/helper/import-export.helper.d.ts +0 -40
@@ -0,0 +1,2475 @@
1
+ import { ref as N, defineComponent as ve, computed as w, resolveComponent as A, openBlock as v, createElementBlock as F, Fragment as ee, unref as a, createVNode as m, withModifiers as Ht, createCommentVNode as j, withCtx as T, createElementVNode as s, toDisplayString as U, normalizeClass as ne, renderList as ce, createBlock as z, h as X, 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 fe, 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, H as rn, I as dn, J as un, K as cn, N as mn, L as pn, u as vn, O as fn, P as yn, Q as gn, T as bn, V as ht, W as hn } from "./app-D2lun71R.js";
3
+ import { useDialog as De, useSnackbar as Me, components as He, useProxiedModel as _t, useDialogChild as _n, useBreakpoints as xn } from "@feedmepos/ui-library";
4
+ import { i as kn, _ as wn } from "./is-linked-ingredient-error-fJ2TJb3z.js";
5
+ import { useI18n as ye, useCoreStore as we } from "@feedmepos/mf-common";
6
+ import { defineStore as Tn, storeToRefs as Vn } from "pinia";
7
+ import { g as Sn, _ as We, S as Ye, a as In } from "./SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-BMFfegsk.js";
8
+ import { _ as Cn } from "./InventoryBindingForm.vue_vue_type_script_setup_true_lang-BEAEmPsU.js";
9
+ import { _ as qe } from "./IngredientBindedItem.vue_vue_type_script_setup_true_lang-BESx2u4Y.js";
10
+ import { _ as _e } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-CRZiQHjx.js";
11
+ import { _ as Fn } from "./FmCustomAttribute.vue_vue_type_script_setup_true_lang-D-IWRjRD.js";
12
+ import { u as Mt } from "./purchase-order-template-uTs7bR89.js";
13
+ import { u as At } from "./closing-template-Cm1TtVzm.js";
14
+ import { r as $n } from "./random-CSbEbElR.js";
15
+ import "./array-Ca8T3f_G.js";
16
+ import { u as En } from "./FmMultiselectDialog-Dfo04ak5.js";
17
+ const Ke = Tn("ingredientForm", function() {
18
+ const o = De(), b = Me(), l = fe(), c = N(!1), { t: h } = ye(), k = N();
19
+ function f() {
20
+ const u = {
21
+ sku: {},
22
+ mode: W.CREATE,
23
+ show: !0,
24
+ "onUpdate:show"(d) {
25
+ k.value.show = d;
26
+ }
27
+ };
28
+ k.value = u;
29
+ }
30
+ async function n(u) {
31
+ const d = {
32
+ sku: St(u),
33
+ mode: W.UPDATE,
34
+ show: !0,
35
+ "onUpdate:show"(p) {
36
+ k.value.show = p;
37
+ }
38
+ };
39
+ k.value = d;
40
+ }
41
+ async function r(u) {
42
+ c.value = !0;
43
+ try {
44
+ await l.deleteSku(u), b.open({
45
+ title: "Success",
46
+ message: `Deleted ${u.name}`,
47
+ type: "success"
48
+ });
49
+ } catch (d) {
50
+ d instanceof Jt && kn(d) ? o.open({
51
+ title: "Cannot delete ingredient",
52
+ contentComponent: wn,
53
+ contentComponentProps: {
54
+ subject: (u == null ? void 0 : u.name) ?? "",
55
+ items: d.errorResponse.message
56
+ },
57
+ secondaryActions: {
58
+ text: "Close",
59
+ close: !0
60
+ }
61
+ }) : console.log("unable to delete ingredient", d), b.open({
62
+ title: `Cannot delete ${u.name}`,
63
+ message: "Please try again.",
64
+ type: "error"
65
+ }), console.error("failed to delete ingredient", d);
66
+ } finally {
67
+ c.value = !1;
68
+ }
69
+ }
70
+ function y(u) {
71
+ o.open({
72
+ title: h("inventory.ingredient.delete.title", [(u == null ? void 0 : u.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(u));
85
+ }
86
+ return {
87
+ createIngredient: f,
88
+ updateIngredient: n,
89
+ deleteIngredient: y,
90
+ ingredientDialogProps: k,
91
+ ingredientViewLoading: c
92
+ };
93
+ }), Mn = {
94
+ key: 0,
95
+ class: "flex items-center gap-8"
96
+ }, An = { class: "flex flex-col gap-1" }, Un = { class: "fm-typo-en-heading-lg-600" }, Pn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Rn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Bn = {
97
+ key: 0,
98
+ class: "fm-typo-en-body-md-400 text-fm-color-system-warning-300"
99
+ }, On = {
100
+ key: 1,
101
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
102
+ }, Dn = { class: "flex flex-col gap-2 mt-4" }, Nn = { class: "flex items-center gap-2 fm-typo-en-body-md-400" }, zn = { class: "flex flex-wrap gap-2" }, Ln = { class: "flex flex-col" }, jn = { class: "flex flex-col bg-fm-color-bg-secondary font-mono p-4 rounded-md" }, Hn = { class: "text-fm-color-typo-tertiary flex-shrink-0 fm-typo-en-body-md-400 whitespace-pre flex items-center" }, Wn = { class: "px-2 py-1 rounded-md bg-blue-200 border-2 border-blue-400" }, Yn = { class: "fm-typo-en-body-md-600 text-fm-color-typo-primary" }, qn = /* @__PURE__ */ ve({
103
+ __name: "ItemSubsidiaryTreeDialog",
104
+ props: {
105
+ skuId: {},
106
+ itemName: {},
107
+ itemCode: {}
108
+ },
109
+ setup(i) {
110
+ const o = i, { t: b } = ye(), 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, le = [..._, C];
130
+ let Q = "";
131
+ for (let te = 0; te < _.length; te++)
132
+ Q += _[te] ? " " : "│ ";
133
+ Q += C ? "└── " : "├── ";
134
+ const me = n.value.has(g.id), oe = g.isAssigned === !0, se = I && !oe;
135
+ if ($.push({
136
+ id: g.id,
137
+ name: g.name,
138
+ prefix: _.length === 0 ? "" : Q,
139
+ isHighlighted: me,
140
+ isDirectlyBound: oe,
141
+ isParentIncludedChild: se,
142
+ isRoot: _.length === 0
143
+ }), g.children && g.children.length > 0) {
144
+ const te = I || oe && f.value.includeChildren;
145
+ $.push(...r(g.children, le, te));
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 u(p, _) {
158
+ return p.map((I) => _.has(I.id) || I.isAssigned === !0 ? {
159
+ ...I,
160
+ // Recursively filter children
161
+ children: I.children ? u(I.children, _) : []
162
+ } : null).filter(Boolean);
163
+ }
164
+ const d = w(() => {
165
+ let p = f.value.subsidiaryTree;
166
+ if ((!p || p.length === 0) && (p = c.getBusinessSubsidiaryTree()), !k.value) {
167
+ const _ = y(p);
168
+ p = u(p, _);
169
+ }
170
+ return r(p, []);
171
+ });
172
+ return (p, _) => {
173
+ const I = A("FmButton"), $ = A("FmDialog");
174
+ return v(), F(ee, null, [
175
+ a(c).isEnabled ? (v(), F("div", Mn, [
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", Un, U(a(b)("inventory.integration.netsuite.subsidiaryHierarchy.title")), 1),
191
+ s("p", Pn, " Name: " + U(o.itemName), 1),
192
+ s("p", Rn, " Code: " + U(o.itemCode), 1),
193
+ k.value ? (v(), F("p", Bn, " All subsidiaries are shown since you are an admin. ")) : (v(), F("p", On, " Only showing subsidiaries in your business path and bound subsidiaries. ")),
194
+ s("div", Dn, [
195
+ s("div", Nn, [
196
+ _[2] || (_[2] = s("span", { class: "font-semibold" }, "Include Children Subsidiaries:", -1)),
197
+ s("span", {
198
+ class: ne(
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", zn, [
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", Ln, [
223
+ s("div", jn, [
224
+ (v(!0), F(ee, null, ce(d.value, (g) => (v(), F("div", {
225
+ key: g.id,
226
+ class: "flex items-stretch"
227
+ }, [
228
+ s("span", Hn, U(g.prefix), 1),
229
+ g.isParentIncludedChild ? (v(), z(Ge, {
230
+ key: 0,
231
+ class: "flex-1"
232
+ }, {
233
+ default: T(() => [
234
+ s("div", Wn, [
235
+ s("span", Yn, U(g.name), 1)
236
+ ])
237
+ ]),
238
+ _: 2
239
+ }, 1024)) : (v(), F("div", {
240
+ key: 1,
241
+ class: ne([
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: ne([
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 Gn() {
263
+ const { updateIngredient: i, deleteIngredient: o } = Ke(), b = fe(), l = Ee();
264
+ De();
265
+ const { t: c } = ye();
266
+ async function h(f, n) {
267
+ const r = St(n);
268
+ if (f === Re.Edit) {
269
+ await i(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
+ (u) => "error" in u && u.reason === "circularDependency"
292
+ );
293
+ return X("div", { class: "flex items-center w-full gap-4" }, [
294
+ y ? X(
295
+ He.FmTooltip,
296
+ { class: "text-left" },
297
+ {
298
+ default() {
299
+ return X(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 X(
321
+ He.FmTooltip,
322
+ { zIndex: 51, content: r },
323
+ X(
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 X(
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 X("div", { class: "flex gap-2 items-start" }, [
360
+ X(
361
+ "span",
362
+ {
363
+ class: "flex-1 line-clamp-2 text-ellipsis break-all whitespace-pre-wrap"
364
+ },
365
+ r.join(", ")
366
+ ),
367
+ X(qn, { 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(i) {
394
+ var o;
395
+ if (i.trackingMeasurement) {
396
+ const b = (o = i.unit.measurements) == null ? void 0 : o.find((l) => l.id === i.trackingMeasurement);
397
+ if (b)
398
+ return `${b.name} (${b.abbrev})`;
399
+ }
400
+ return `${i.unit.name} (${i.unit.abbrev})`;
401
+ }
402
+ const Kn = /* @__PURE__ */ ve({
403
+ __name: "ConvertForm",
404
+ props: {
405
+ modelValue: {},
406
+ rootValue: {},
407
+ disabled: { type: Boolean },
408
+ readonly: { type: Boolean }
409
+ },
410
+ emits: ["update:modelValue"],
411
+ setup(i, { emit: o }) {
412
+ const b = i, l = w(() => {
413
+ var d;
414
+ return (d = b.rootValue) == null ? void 0 : d.unit;
415
+ }), c = w(() => {
416
+ var d;
417
+ return (d = b.rootValue) == null ? void 0 : d._id;
418
+ }), h = o, { t: k } = ye(), f = w({
419
+ get() {
420
+ return !!b.modelValue;
421
+ },
422
+ set(d) {
423
+ d ? h("update:modelValue", {
424
+ measurement: null,
425
+ inventoryBindings: []
426
+ }) : h("update:modelValue", null);
427
+ }
428
+ }), n = w(() => Sn(l.value));
429
+ function r(d) {
430
+ const p = b.modelValue ?? {};
431
+ p.measurement = d ? `${d}` : null, h("update:modelValue", p);
432
+ }
433
+ function y(d) {
434
+ const p = b.modelValue ?? {};
435
+ p.inventoryBindings = d, h("update:modelValue", p);
436
+ }
437
+ const u = w(() => {
438
+ if (!b.modelValue) return null;
439
+ const d = b.modelValue;
440
+ return d.measurement ? n.value.find((p) => p.value === d.measurement) ?? null : n.value.find((p) => p.value === null) ?? null;
441
+ });
442
+ return (d, p) => {
443
+ const _ = A("FmSwitch"), I = A("FmSelect"), $ = A("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: d.readonly
459
+ }, null, 8, ["model-value", "label", "sublabel", "disabled"]),
460
+ f.value ? (v(), F(ee, { key: 0 }, [
461
+ s("div", null, [
462
+ m(I, {
463
+ label: a(k)("inventory.ingredient.convertible.convertTo"),
464
+ modelValue: (g = u.value) == null ? void 0 : g.value,
465
+ "onUpdate:modelValue": r,
466
+ items: n.value,
467
+ disabled: d.readonly
468
+ }, null, 8, ["label", "modelValue", "items", "disabled"])
469
+ ]),
470
+ m(Cn, {
471
+ id: c.value,
472
+ "model-value": ((D = d.modelValue) == null ? void 0 : D.inventoryBindings) ?? [],
473
+ "onUpdate:modelValue": y,
474
+ "exclude-binding-id": c.value,
475
+ rules: [a(Be)(1)],
476
+ readonly: d.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 Jn = {
493
+ key: 0,
494
+ class: "flex flex-col gap-4"
495
+ }, Fe = /* @__PURE__ */ ve({
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(i) {
508
+ return (o, b) => {
509
+ const l = A("FmLabel"), c = A("FmIcon"), h = A("FmTooltip"), k = A("FmField");
510
+ return o.locked ? (v(), F("div", Jn, [
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: ne([
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: ne([
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
+ }), Qn = { class: "flex gap-8" }, Zn = { class: "flex-1" }, Xn = { class: "flex-1" }, eo = { class: "flex flex-col gap-5" }, to = { class: "text-fm-color-typo-secondary" }, no = { class: "text-fm-color-typo-secondary whitespace-nowrap" }, oo = {
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
+ }, lo = { class: "flex flex-col" }, so = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, ao = {
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
+ }, ro = { class: "flex flex-col gap-12" }, io = { class: "flex flex-col gap-4" }, uo = { class: "fm-typo-en-title-sm-600" }, co = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, mo = { class: "flex flex-col gap-4" }, po = { class: "flex fm-corner-radius-md border-1 border-fm-color-neutral-gray-200" }, vo = { class: "flex-1 p-12 flex flex-col gap-8" }, fo = { class: "mx-auto" }, yo = { class: "flex flex-col" }, go = { class: "fm-typo-en-body-sm-600 translate-y-4" }, bo = { class: "flex-1 p-12 flex flex-col gap-8" }, ho = { class: "mx-auto" }, _o = { class: "flex flex-col" }, xo = { class: "fm-typo-en-body-sm-600 translate-y-4" }, ko = { class: "flex-1 p-12 flex flex-col gap-8" }, wo = { class: "mx-auto" }, To = { class: "flex flex-col" }, Vo = { class: "fm-typo-en-body-sm-600 translate-y-4" }, So = {
572
+ key: 5,
573
+ class: "flex flex-col gap-12"
574
+ }, Io = { class: "flex flex-col" }, Co = { class: "flex items-center justify-between" }, Fo = { class: "fm-typo-en-title-sm-600" }, $o = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Eo = {
575
+ key: 0,
576
+ class: "flex flex-col gap-8"
577
+ }, Mo = { class: "flex flex-wrap gap-8" }, Ao = {
578
+ key: 6,
579
+ class: "flex flex-col gap-12"
580
+ }, Uo = { class: "flex flex-col" }, Po = { class: "flex items-center justify-between" }, Ro = { class: "fm-typo-en-title-sm-600" }, Bo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Oo = {
581
+ key: 0,
582
+ class: "flex flex-col gap-8"
583
+ }, Do = { class: "flex flex-wrap gap-8" }, No = {
584
+ key: 7,
585
+ class: "flex flex-col gap-12"
586
+ }, zo = { class: "flex flex-col" }, Lo = { class: "flex items-center justify-between" }, jo = { class: "fm-typo-en-title-sm-600" }, Ho = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Wo = {
587
+ key: 0,
588
+ class: "flex flex-col gap-8"
589
+ }, Yo = { class: "flex flex-wrap gap-8" }, qo = /* @__PURE__ */ ve({
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(i, { expose: o, emit: b }) {
604
+ var ot;
605
+ const { t: l } = ye(), c = De();
606
+ Me();
607
+ const h = Mt(), k = It(), f = At(), n = i, r = b, y = fe(), u = we(), d = 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((M) => M)
614
+ };
615
+ S.unit || (S.unit = t, r("update:modelValue", S));
616
+ }
617
+ Wt(() => {
618
+ C(y.units), n.mode === W.CREATE && (d.mustUsePoTemplate && Q(), d.enableWastageTemplate && me(), d.enableClosingTemplate && oe());
619
+ }), Tt([() => y.units], ([e]) => {
620
+ C(e);
621
+ });
622
+ function le() {
623
+ r("click:submit");
624
+ }
625
+ async function Q() {
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 me() {
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 se = 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
+ }), te = 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
+ }), ae = 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, M, 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(u.currentCountry.value)) == null ? void 0 : S.currency) ?? "MYR"
711
+ },
712
+ measurement: (L = (q = (M = n.modelValue) == null ? void 0 : M.unit) == null ? void 0 : q.measurements) == null ? void 0 : L.find(
713
+ (ie) => {
714
+ var de;
715
+ return ie.id === ((de = n.modelValue) == null ? void 0 : de.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, M;
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: ((M = e.measurements.find((q) => {
730
+ var L;
731
+ return q.id === ((L = n.modelValue) == null ? void 0 : L.trackingMeasurement);
732
+ })) == null ? void 0 : M.name) ?? e.name
733
+ } : null;
734
+ }), Te = w(
735
+ () => y.units.flatMap(({ name: e, _id: t, abbrev: S, measurements: M }) => [
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
+ ...M.map(({ id: q, name: L, abbrev: ie }) => ({
747
+ label: `${L} (${ie})`,
748
+ value: { _id: t, measurement: q },
749
+ displayAsSection: !1
750
+ }))
751
+ ])
752
+ ), V = Yt(i, "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, M, q, L;
760
+ return ((S = (t = n.modelValue) == null ? void 0 : t.unit) == null ? void 0 : S._id) === ((M = e.value) == null ? void 0 : M._id) && ((q = n.modelValue) == null ? void 0 : q.trackingMeasurement) === ((L = e.value) == null ? void 0 : L.measurement);
761
+ }
762
+ function x(e) {
763
+ var ie, de;
764
+ if (!e) return;
765
+ const { _id: t, measurement: S } = e, M = 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 = M, L.convert && (L.convert.measurement = M || null), d.enableTotalCost && (L.defaultCost = {
770
+ measurement: q.measurements.find((Ie) => Ie.id === M),
771
+ costPerUnit: {
772
+ ...((ie = L.defaultCost) == null ? void 0 : ie.costPerUnit) ?? {
773
+ amount: 0,
774
+ precision: 2,
775
+ currency: ((de = Oe(u.currentCountry.value)) == null ? void 0 : de.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
+ }))), pe = 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
+ (M) => M.from === "INGREDIENT"
838
+ )) ?? [] : [];
839
+ }
840
+ ), ue = 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
+ (M) => M.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((M) => M.from === "MENU")) ?? [] : [];
851
+ }
852
+ ), xe = w(
853
+ () => y.skus.map((e) => ({ label: e.name, value: e.code }))
854
+ ), Ae = 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, M, q, L;
863
+ return ((M = (S = (t = (e = n.modelValue) == null ? void 0 : e.unit) == null ? void 0 : t.measurements) == null ? void 0 : S.find(
864
+ (ie) => {
865
+ var de;
866
+ return ie.id === ((de = n.modelValue) == null ? void 0 : de.trackingMeasurement);
867
+ }
868
+ )) == null ? void 0 : M.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 M;
877
+ const t = ((M = n.modelValue) == null ? void 0 : M.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
+ }), re = 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 M;
891
+ const t = ((M = n.modelValue) == null ? void 0 : M.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(() => d.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(() => d.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(() => d.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 = A("FmTextField"), M = A("FmLabel"), q = A("FmField"), L = A("FmIcon"), ie = A("FmMenuHeader"), de = A("FmMenuDivider"), Ie = A("FmMenuItem"), Nt = A("FmMenu"), lt = A("FmFormGroup"), zt = A("FmSelect"), st = A("FmSwitch"), at = A("FmStepperField"), Ne = A("FmButton"), ze = A("FmChip"), Lt = A("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: le
993
+ }, {
994
+ default: T(() => {
995
+ var rt, it, dt, ut;
996
+ return [
997
+ s("div", Qn, [
998
+ s("div", Zn, [
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": se.value,
1004
+ "onUpdate:modelValue": t[1] || (t[1] = (E) => se.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": se.value,
1012
+ "onUpdate:modelValue": t[0] || (t[0] = (E) => se.value = E),
1013
+ rules: [a(Le)(), a(Xt)(xe.value, Ae.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", Xn, [
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": ae.value,
1026
+ "onUpdate:modelValue": t[3] || (t[3] = (E) => ae.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": ae.value,
1034
+ "onUpdate:modelValue": t[2] || (t[2] = (E) => ae.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(M, {
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: ne([
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 Z;
1079
+ return [
1080
+ Je(U((Z = be.value) == null ? void 0 : Z.name), 1)
1081
+ ];
1082
+ }),
1083
+ _: 2
1084
+ }, 1032, ["class", "invalid"])
1085
+ ]),
1086
+ default: T(() => [
1087
+ s("div", eo, [
1088
+ m(S, {
1089
+ modelValue: V.value,
1090
+ "onUpdate:modelValue": t[4] || (t[4] = (Z) => V.value = Z),
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(ee, null, ce(G.value, (Z, jt) => (v(), F(ee, { key: jt }, [
1103
+ Z.displayAsSection ? (v(), F(ee, { key: 0 }, [
1104
+ m(ie, {
1105
+ label: Z.label
1106
+ }, null, 8, ["label"]),
1107
+ m(de)
1108
+ ], 64)) : (v(), z(Ie, {
1109
+ key: 1,
1110
+ label: Z.label,
1111
+ "model-value": P(Z),
1112
+ onClick: (Sl) => x(Z.value),
1113
+ "x-should-scroll-into": `${P(Z)}`
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(d).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." + pe.value),
1133
+ locked: _.value,
1134
+ disabled: e.disabled
1135
+ }, {
1136
+ label: T(() => [
1137
+ m(_e, { "z-index": 50 }, {
1138
+ default: T(() => [
1139
+ m(M, {
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": pe.value,
1151
+ "onUpdate:modelValue": t[5] || (t[5] = (E) => pe.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(d).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(M, {
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(M, {
1185
+ label: a(l)("inventory.ingredient.pricePerUnit")
1186
+ }, null, 8, ["label"])
1187
+ ]),
1188
+ _: 1
1189
+ })
1190
+ ]),
1191
+ prepend: T(() => {
1192
+ var E, Z;
1193
+ return [
1194
+ s("div", to, U(a(ft)(((E = a(u).currentCountry) == null ? void 0 : E.value) ?? a(yt)) === "MYR" ? "RM" : a(ft)(((Z = a(u).currentCountry) == null ? void 0 : Z.value) ?? a(yt))), 1)
1195
+ ];
1196
+ }),
1197
+ append: T(() => [
1198
+ s("div", no, " / " + 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(Kn, {
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", oo, [
1213
+ m(st, {
1214
+ label: a(l)("inventory.ingredient.status.inactive"),
1215
+ "model-value": te.value,
1216
+ "onUpdate:modelValue": t[8] || (t[8] = (E) => te.value = E),
1217
+ "label-placement": "right",
1218
+ disabled: _.value
1219
+ }, null, 8, ["label", "model-value", "disabled"]),
1220
+ s("div", lo, [
1221
+ s("div", so, U(a(l)("inventory.ingredient.status.preventFromOrder")), 1)
1222
+ ])
1223
+ ])) : j("", !0),
1224
+ e.mode !== a(W).CREATE ? (v(), F("div", ao, [
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 && ue.value.length ? (v(), z(qe, {
1239
+ key: 1,
1240
+ name: a(l)("inventory.ingredient.bindedItems.recipe"),
1241
+ bindings: ue.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", ro, [
1250
+ s("div", io, [
1251
+ m(_e, null, {
1252
+ default: T(() => [
1253
+ s("div", uo, U(a(l)("inventory.ingredient.threshold.title")), 1)
1254
+ ]),
1255
+ _: 1
1256
+ }),
1257
+ s("div", co, U(a(l)("inventory.ingredient.threshold.subtitle")), 1)
1258
+ ]),
1259
+ s("div", mo, [
1260
+ m(lt, {
1261
+ "model-value": { low: he.value, mid: re.value },
1262
+ rules: [Dt()]
1263
+ }, null, 8, ["model-value", "rules"]),
1264
+ s("div", po, [
1265
+ s("div", vo, [
1266
+ s("div", fo, [
1267
+ m(We, {
1268
+ days: he.value,
1269
+ level: a(Ye).low
1270
+ }, null, 8, ["days", "level"])
1271
+ ]),
1272
+ s("div", yo, [
1273
+ s("div", go, 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", bo, [
1299
+ s("div", ho, [
1300
+ m(We, {
1301
+ days: re.value,
1302
+ level: a(Ye).mid
1303
+ }, null, 8, ["days", "level"])
1304
+ ]),
1305
+ s("div", _o, [
1306
+ s("div", xo, U(a(l)("inventory.ingredient.threshold.whenRemaining")), 1),
1307
+ m(at, {
1308
+ modelValue: re.value,
1309
+ "onUpdate:modelValue": t[11] || (t[11] = (E) => re.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", ko, [
1332
+ s("div", wo, [
1333
+ m(We, {
1334
+ days: re.value + 1,
1335
+ level: a(Ye).high
1336
+ }, null, 8, ["days", "level"])
1337
+ ]),
1338
+ s("div", To, [
1339
+ s("div", Vo, U(a(l)("inventory.ingredient.threshold.stockIsStaple")), 1)
1340
+ ])
1341
+ ])
1342
+ ])
1343
+ ])
1344
+ ]),
1345
+ a(d).mustUsePoTemplate && e.mode === a(W).CREATE ? (v(), F("div", So, [
1346
+ s("div", Io, [
1347
+ s("div", Co, [
1348
+ m(_e, null, {
1349
+ default: T(() => [
1350
+ s("div", Fo, 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", $o, U(a(l)("inventory.ingredient.purchaseOrderTemplates.description")), 1)
1363
+ ]),
1364
+ Ze.value.length > 0 ? (v(), F("div", Eo, [
1365
+ s("div", Mo, [
1366
+ (v(!0), F(ee, null, ce(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(d).enableWastageTemplate && e.mode === a(W).CREATE ? (v(), F("div", Ao, [
1376
+ s("div", Uo, [
1377
+ s("div", Po, [
1378
+ m(_e, null, {
1379
+ default: T(() => [
1380
+ s("div", Ro, 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", Bo, U(a(l)("inventory.ingredient.wastageTemplates.description")), 1)
1393
+ ]),
1394
+ et.value.length > 0 ? (v(), F("div", Oo, [
1395
+ s("div", Do, [
1396
+ (v(!0), F(ee, null, ce(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(d).enableClosingTemplate && e.mode === a(W).CREATE ? (v(), F("div", No, [
1406
+ s("div", zo, [
1407
+ s("div", Lo, [
1408
+ m(_e, null, {
1409
+ default: T(() => [
1410
+ s("div", jo, 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", Ho, U(a(l)("inventory.ingredient.closingTemplates.description")), 1)
1423
+ ]),
1424
+ nt.value.length > 0 ? (v(), F("div", Wo, [
1425
+ s("div", Yo, [
1426
+ (v(!0), F(ee, null, ce(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(Fn, {
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
+ }), Go = { class: "flex flex-col gap-32" }, Ko = {
1449
+ key: 0,
1450
+ class: "flex justify-between items-center"
1451
+ }, Jo = { class: "flex gap-4" }, Qo = /* @__PURE__ */ ve({
1452
+ __name: "IngredientDialog",
1453
+ props: {
1454
+ show: { type: Boolean },
1455
+ sku: {},
1456
+ mode: { default: W.READ }
1457
+ },
1458
+ emits: ["update:show"],
1459
+ setup(i) {
1460
+ const o = i, b = fe(), l = Qe(), c = Ee(), h = Mt(), k = It(), f = At(), n = Me(), { t: r } = ye(), y = _t(o, "show"), u = _t(o, "sku"), d = 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 le() {
1487
+ C.value = !0;
1488
+ try {
1489
+ await b.createSku(u.value);
1490
+ const V = b.skuByCode[u.value.code];
1491
+ l.enablePoTemplate && d.value.length > 0 && await me(V), l.enableWastageTemplate && p.value.length > 0 && await oe(V), l.enableClosingTemplate && _.value.length > 0 && await se(V), y.value = !1, n.open({
1492
+ title: r("inventory.common.success"),
1493
+ message: r("inventory.ingredient.create.success", { name: u.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 Q() {
1507
+ C.value = !0;
1508
+ try {
1509
+ await b.updateSku(u.value), C.value = !1, y.value = !1, n.open({
1510
+ title: r("inventory.common.success"),
1511
+ message: r("inventory.ingredient.update.success", { name: u.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 me(V) {
1525
+ var B, G, P, x;
1526
+ try {
1527
+ for (const H of d.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, ...ue }) => ue
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 se(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 te() {
1621
+ var V, B;
1622
+ (B = (V = D.value) == null ? void 0 : V.validateInputs) == null || B.call(V);
1623
+ }
1624
+ function ae() {
1625
+ switch (o.mode) {
1626
+ case W.READ:
1627
+ return;
1628
+ case W.UPDATE:
1629
+ return Q();
1630
+ case W.CREATE:
1631
+ return le();
1632
+ }
1633
+ }
1634
+ function ge(V) {
1635
+ d.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 = A("FmChip"), P = A("FmButton"), x = A("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", Jo, [
1655
+ m(P, {
1656
+ loading: C.value,
1657
+ label: g.value,
1658
+ onClick: te
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", Go, [
1670
+ I.value ? (v(), F("div", Ko, [
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(qo, {
1682
+ class: "w-full",
1683
+ ref_key: "hasValidationExpose",
1684
+ ref: D,
1685
+ modelValue: a(u),
1686
+ "onUpdate:modelValue": B[0] || (B[0] = (H) => mt(u) ? u.value = H : null),
1687
+ mode: V.mode,
1688
+ disabled: C.value,
1689
+ purchaseOrderTemplateIds: d.value,
1690
+ wastageTemplateIds: p.value,
1691
+ closingTemplateIds: _.value,
1692
+ "onClick:submit": B[1] || (B[1] = (H) => ae()),
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 Zo() {
1705
+ return `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${$n()}`;
1706
+ }
1707
+ const Xo = {
1708
+ _id: "",
1709
+ name: "",
1710
+ abbrev: "",
1711
+ precision: 0,
1712
+ measurements: []
1713
+ };
1714
+ function el(i) {
1715
+ return !i || Object.keys(i).length === 0 ? "" : Object.entries(i).map(([o, b]) => `${o}: ${b}`).join(", ");
1716
+ }
1717
+ function Ut(i) {
1718
+ if (!i || i.trim() === "")
1719
+ return;
1720
+ const o = {}, b = i.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 tl(i) {
1731
+ var b, l, c, h, k;
1732
+ return {
1733
+ code: i.code,
1734
+ name: i.name,
1735
+ unit: i.unit.name,
1736
+ baseUnit: i.unit.abbrev,
1737
+ measurementName: ((b = i.unit.measurements.find((f) => f.id === i.trackingMeasurement)) == null ? void 0 : b.abbrev) ?? i.unit.abbrev,
1738
+ valuationMethod: i.valuation ?? "WAVG",
1739
+ pricePerUnit: (l = i.defaultCost) != null && l.costPerUnit ? +Ct((c = i.defaultCost) == null ? void 0 : c.costPerUnit) : 0,
1740
+ thresholdLow: ((h = i.thresholds) == null ? void 0 : h.low) ?? ke().low,
1741
+ thresholdMid: ((k = i.thresholds) == null ? void 0 : k.mid) ?? ke().mid,
1742
+ customAttributes: el(i.customAttributes)
1743
+ };
1744
+ }
1745
+ function Pt() {
1746
+ var c;
1747
+ const i = [
1748
+ {
1749
+ id: "code",
1750
+ name: "Code"
1751
+ },
1752
+ {
1753
+ id: "name",
1754
+ name: "Name"
1755
+ },
1756
+ {
1757
+ id: "unit",
1758
+ name: "Unit"
1759
+ },
1760
+ {
1761
+ id: "baseUnit",
1762
+ name: "Base unit"
1763
+ },
1764
+ {
1765
+ id: "measurementName",
1766
+ name: "Measurement Name"
1767
+ }
1768
+ ], o = Qe(), b = we(), l = Oe(b.currentCountry.value);
1769
+ return o.enableTotalCost && i.push(
1770
+ {
1771
+ id: "valuationMethod",
1772
+ name: "Valuation method"
1773
+ },
1774
+ {
1775
+ id: "pricePerUnit",
1776
+ name: `Price per unit (${l == null ? void 0 : l.currency})`
1777
+ }
1778
+ ), ((c = b.currentBusiness.value) == null ? void 0 : c.menuVersion) === "v4" && i.push(
1779
+ {
1780
+ id: "thresholdLow",
1781
+ name: "Show RED when remaining"
1782
+ },
1783
+ {
1784
+ id: "thresholdMid",
1785
+ name: "Show YELLOW when remaining"
1786
+ }
1787
+ ), i.push({
1788
+ id: "customAttributes",
1789
+ name: "Custom Attributes"
1790
+ }), i;
1791
+ }
1792
+ function nl() {
1793
+ const o = fe().skus.map(tl), l = we().currentBusiness.value, c = Pt(), h = [
1794
+ ["Business name:", l == null ? void 0 : l.name],
1795
+ ["Business ID:", l == null ? void 0 : l._id],
1796
+ ["Menu version", l == null ? void 0 : l.menuVersion],
1797
+ [],
1798
+ c.map((r) => r.name),
1799
+ ...o.map((r) => c.map((y) => r[y.id]))
1800
+ ], k = c.map((r) => `system:${r.id}`), f = $t(h, k), n = `${l == null ? void 0 : l.name} ingredients (${ln(/* @__PURE__ */ new Date())}).xlsx`;
1801
+ return Et(f, n), n;
1802
+ }
1803
+ function ol() {
1804
+ const o = we().currentBusiness.value, b = Pt(), l = [
1805
+ ["Business name:", o == null ? void 0 : o.name],
1806
+ ["Business ID:", o == null ? void 0 : o._id],
1807
+ ["Menu version", o == null ? void 0 : o.menuVersion],
1808
+ [],
1809
+ b.map((f) => f.name)
1810
+ ], c = b.map((f) => `system:${f.id}`), h = $t(l, c), k = "FeedMe ingredients template.xlsx";
1811
+ return Et(h, k), k;
1812
+ }
1813
+ function ll(i) {
1814
+ const [
1815
+ o,
1816
+ b,
1817
+ l,
1818
+ c,
1819
+ h,
1820
+ k,
1821
+ ...f
1822
+ ] = an(i);
1823
+ if (!o || !o.length || o.some((d) => d.length && !d.startsWith("system:")))
1824
+ throw new Error("Missing meta header. Excel file does not come from the template.");
1825
+ const n = o.map((d) => d.split(":")[1]), y = ["code", "name", "unit", "baseUnit", "measurementName"].filter((d) => !n.includes(d));
1826
+ if (y.length)
1827
+ throw new Error(
1828
+ `Missing meta headers (${y.join()}). Excel file does not come from the template.`
1829
+ );
1830
+ return f.map((d, p) => {
1831
+ const _ = {};
1832
+ for (const I in n) {
1833
+ const $ = n[I];
1834
+ Object.assign(_, { [$]: d[I] });
1835
+ }
1836
+ return {
1837
+ index: p,
1838
+ data: _
1839
+ };
1840
+ });
1841
+ }
1842
+ function kt(i, o, b) {
1843
+ var D;
1844
+ const c = fe().units, h = new Array(), k = b.filter((C) => C.data.code === i.code);
1845
+ k.length > 1 && h.push(
1846
+ `Code ${i.code} is already used in row ${k.map((C) => C.index + 6).join()}.`
1847
+ );
1848
+ const f = c.find((C) => {
1849
+ var le, Q;
1850
+ return C.abbrev === i.baseUnit && ((le = C.name) == null ? void 0 : le.trim()) === ((Q = i.unit) == null ? void 0 : Q.trim());
1851
+ }), n = f == null ? void 0 : f.measurements.find((C) => C.abbrev === i.measurementName);
1852
+ if (!f)
1853
+ h.push(`Cannot find base unit of symbol ${i.baseUnit}.`);
1854
+ else if (i.baseUnit !== i.measurementName && !n) {
1855
+ const C = `Cannot find unit conversion for ${i.baseUnit} with symbol ${i.measurementName || "[empty]"}.`;
1856
+ h.push(C);
1857
+ }
1858
+ const r = $e.options.find(
1859
+ (C) => C === i.valuationMethod
1860
+ );
1861
+ i.valuationMethod && !r && h.push(
1862
+ `Expected valuation method to be one of ${$e.options.join()} but got ${i.valuationMethod} instead.`
1863
+ );
1864
+ const u = we().currentCountry.value, d = (C) => `${C}`.length && dn()(C) === !0, p = d(`${i.pricePerUnit}`) === !0 ? {
1865
+ costPerUnit: {
1866
+ ...Ft(Number(i.pricePerUnit) || 0, rn(Number(i.pricePerUnit) || 0)),
1867
+ currency: ((D = Oe(u)) == null ? void 0 : D.currency) ?? "MYR"
1868
+ },
1869
+ measurement: n
1870
+ } : void 0, _ = d(`${i.thresholdLow}`) && d(`${i.thresholdMid}`) ? {
1871
+ low: Number(i.thresholdLow) || 0,
1872
+ mid: Number(i.thresholdMid) || 0
1873
+ } : void 0, I = "customAttributes" in i ? Ut(i.customAttributes) : null;
1874
+ return {
1875
+ type: "create",
1876
+ sku: {
1877
+ _id: Zo(),
1878
+ code: i.code,
1879
+ name: i.name,
1880
+ unit: f ?? c.find((C) => C) ?? Xo,
1881
+ trackingMeasurement: n == null ? void 0 : n.id,
1882
+ valuation: r,
1883
+ defaultCost: p,
1884
+ thresholds: _,
1885
+ ...I !== null && { customAttributes: I }
1886
+ },
1887
+ errors: h,
1888
+ excelRowNumber: o + 6
1889
+ };
1890
+ }
1891
+ function sl(i) {
1892
+ try {
1893
+ const o = ll(i).filter((r) => r.data.code), l = fe().skus, c = sn(l, "code"), h = o.filter((r) => !c[r.data.code]), k = o.filter((r) => c[r.data.code]), f = h.map(
1894
+ (r) => kt(r.data, r.index, o)
1895
+ ), n = k.map((r) => {
1896
+ const y = kt(r.data, r.index, o), u = c[r.data.code];
1897
+ let d = u.customAttributes;
1898
+ return "customAttributes" in r.data && (d = Ut(r.data.customAttributes)), {
1899
+ ...y,
1900
+ type: "update",
1901
+ original: u,
1902
+ sku: {
1903
+ // to maintain original props not in the import excel, e.g. inventory binding, etc...
1904
+ ...u,
1905
+ code: y.sku.code || u.code,
1906
+ name: y.sku.name || u.name,
1907
+ unit: y.sku.unit || u.unit,
1908
+ trackingMeasurement: y.sku.trackingMeasurement || u.trackingMeasurement,
1909
+ valuation: y.sku.valuation || u.valuation,
1910
+ defaultCost: y.sku.defaultCost || u.defaultCost,
1911
+ thresholds: y.sku.thresholds || u.thresholds,
1912
+ customAttributes: d
1913
+ }
1914
+ };
1915
+ });
1916
+ return {
1917
+ invalidExcel: !1,
1918
+ importCreateResult: f,
1919
+ importUpdateResult: n
1920
+ };
1921
+ } catch (o) {
1922
+ return {
1923
+ invalidExcel: !0,
1924
+ invalidExcelMessage: (o == null ? void 0 : o.message) ?? "Invalid excel",
1925
+ importCreateResult: [],
1926
+ importUpdateResult: []
1927
+ };
1928
+ }
1929
+ }
1930
+ const al = { class: "flex items-center gap-12 pl-8" }, rl = { class: "flex flex-col" }, il = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, dl = {
1931
+ key: 0,
1932
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
1933
+ }, ul = { key: 0 }, wt = /* @__PURE__ */ ve({
1934
+ __name: "ImportIngredientItem",
1935
+ props: {
1936
+ type: {},
1937
+ code: {},
1938
+ name: {},
1939
+ errors: {}
1940
+ },
1941
+ setup(i) {
1942
+ return (o, b) => {
1943
+ const l = A("FmIcon"), c = A("FmTooltip");
1944
+ return v(), F("div", al, [
1945
+ b[0] || (b[0] = s("div", null, "•", -1)),
1946
+ s("div", rl, [
1947
+ s("div", il, [
1948
+ s("div", {
1949
+ class: ne({
1950
+ "text-fm-color-system-error-300": o.errors.length
1951
+ })
1952
+ }, [
1953
+ Je(U(o.name) + " ", 1),
1954
+ o.type === "create" ? (v(), F("span", dl, "(new)")) : j("", !0)
1955
+ ], 2),
1956
+ o.errors.length ? (v(), F("div", ul, [
1957
+ m(c, { "z-index": 50 }, {
1958
+ content: T(() => [
1959
+ s("ol", null, [
1960
+ (v(!0), F(ee, null, ce(o.errors, (h, k) => (v(), F("li", { key: k }, U(h), 1))), 128))
1961
+ ])
1962
+ ]),
1963
+ default: T(() => [
1964
+ m(l, {
1965
+ name: "error",
1966
+ size: "sm",
1967
+ color: "system-error-300"
1968
+ })
1969
+ ]),
1970
+ _: 1
1971
+ })
1972
+ ])) : j("", !0)
1973
+ ]),
1974
+ s("div", {
1975
+ class: ne([
1976
+ "fm-typo-en-body-sm-400",
1977
+ {
1978
+ "text-fm-color-system-error-200": o.errors.length,
1979
+ "text-fm-color-typo-secondary": !o.errors.length
1980
+ }
1981
+ ])
1982
+ }, U(o.code), 3)
1983
+ ])
1984
+ ]);
1985
+ };
1986
+ }
1987
+ }), cl = { class: "flex flex-col gap-24" }, ml = { class: "fm-typo-en-body-md-400" }, pl = { class: "flex flex-col gap-8" }, vl = { class: "line-clamp-2 text-ellipsis break-all" }, fl = {
1988
+ key: 2,
1989
+ class: "shrink-0"
1990
+ }, yl = {
1991
+ key: 0,
1992
+ class: "flex flex-col"
1993
+ }, gl = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, bl = {
1994
+ key: 0,
1995
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
1996
+ }, hl = { class: "fm-typo-en-body-lg-600" }, _l = /* @__PURE__ */ ve({
1997
+ __name: "ImportIngredients",
1998
+ setup(i) {
1999
+ const o = N(null), b = _n(), l = Me(), c = N(!1), h = N(new Array()), k = N([]), f = N([]), n = w(
2000
+ () => !!h.value.length || k.value.some((d) => d.errors.length) || f.value.some((d) => d.errors.length)
2001
+ ), r = w(
2002
+ () => !!k.value.length || !!f.value.length
2003
+ ), { t: y } = ye();
2004
+ async function u(d) {
2005
+ h.value = [], k.value = [], f.value = [];
2006
+ try {
2007
+ c.value = !0;
2008
+ const [p] = await Promise.all([
2009
+ cn(d),
2010
+ // fake buffer
2011
+ new Promise(($) => setTimeout($, 1e3))
2012
+ ]), _ = p.SheetNames.find(($) => $);
2013
+ if (!_) {
2014
+ h.value.push(y("inventory.ingredient.import.fileError.noSheet"));
2015
+ return;
2016
+ }
2017
+ const I = sl(p.Sheets[_]);
2018
+ if (I.invalidExcel) {
2019
+ h.value.push(I.invalidExcelMessage ?? y("inventory.ingredient.import.fileError.invalidExcel"));
2020
+ return;
2021
+ }
2022
+ if (k.value = I.importCreateResult, f.value = I.importUpdateResult, !k.value.length && !f.value.length) {
2023
+ h.value.push(y("inventory.ingredient.import.fileError.noData"));
2024
+ return;
2025
+ }
2026
+ b.emitData(I);
2027
+ } catch (p) {
2028
+ l.open({
2029
+ title: y("inventory.ingredient.import.fileError.unableToRead"),
2030
+ message: p == null ? void 0 : p.message,
2031
+ type: "error"
2032
+ }), console.error("Error in reading file", p);
2033
+ } finally {
2034
+ h.value.length && l.open({
2035
+ title: y("inventory.ingredient.import.fileError.invalidExcel"),
2036
+ type: "error"
2037
+ }), c.value = !1;
2038
+ }
2039
+ }
2040
+ return Tt(o, (d) => {
2041
+ d && u(d);
2042
+ }), (d, p) => {
2043
+ const _ = A("FmCircularProgress"), I = A("FmIcon"), $ = A("FmButton");
2044
+ return v(), F("div", cl, [
2045
+ s("div", ml, U(a(y)("inventory.ingredient.import.uploadDescription")), 1),
2046
+ m(un, {
2047
+ class: ne({
2048
+ "w-full": !0,
2049
+ "h-[200px]": !o.value
2050
+ }),
2051
+ accept: ".xlsx",
2052
+ onFileUpload: p[0] || (p[0] = (g) => o.value = g),
2053
+ label: a(y)("inventory.ingredient.import.uploadTemplate"),
2054
+ "button-label": a(y)("inventory.ingredient.import.selectFile")
2055
+ }, Vt({ _: 2 }, [
2056
+ o.value ? {
2057
+ name: "default",
2058
+ fn: T(({ openFileDialog: g }) => [
2059
+ s("div", pl, [
2060
+ s("div", {
2061
+ class: ne([
2062
+ "fm-corner-radius-md p-16 flex items-center gap-16",
2063
+ {
2064
+ "border border-fm-color-neutral-gray-100": c.value,
2065
+ "border border-fm-color-neutral-gray-200": !c.value && !n.value,
2066
+ "border border-fm-color-system-error-200": n.value
2067
+ }
2068
+ ])
2069
+ }, [
2070
+ c.value ? (v(), z(_, {
2071
+ key: 0,
2072
+ size: "md",
2073
+ color: "neutral-gray-200"
2074
+ })) : (v(), z(I, {
2075
+ key: 1,
2076
+ name: n.value ? "error" : "attach_file",
2077
+ outline: "",
2078
+ color: n.value ? "system-error-300" : void 0
2079
+ }, null, 8, ["name", "color"])),
2080
+ s("div", {
2081
+ class: ne([
2082
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
2083
+ {
2084
+ "text-fm-color-typo-disabled": c.value,
2085
+ "text-fm-color-typo-primary": !c.value
2086
+ }
2087
+ ])
2088
+ }, [
2089
+ s("div", vl, U(o.value.name), 1)
2090
+ ], 2),
2091
+ c.value ? j("", !0) : (v(), F("div", fl, [
2092
+ m($, {
2093
+ label: a(y)("inventory.ingredient.import.replaceFile"),
2094
+ variant: n.value ? "destructive" : "secondary",
2095
+ "prepend-icon": n.value ? void 0 : "autorenew",
2096
+ onClick: g
2097
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
2098
+ ]))
2099
+ ], 2),
2100
+ h.value.length ? (v(), F("div", yl, [
2101
+ (v(!0), F(ee, null, ce(h.value, (D, C) => (v(), F("div", {
2102
+ key: C,
2103
+ class: "flex gap-8 items-center"
2104
+ }, [
2105
+ m(I, {
2106
+ name: "error",
2107
+ size: "sm",
2108
+ color: "system-error-300"
2109
+ }),
2110
+ s("div", gl, U(D), 1)
2111
+ ]))), 128))
2112
+ ])) : j("", !0)
2113
+ ])
2114
+ ]),
2115
+ key: "0"
2116
+ } : void 0
2117
+ ]), 1032, ["class", "label", "button-label"]),
2118
+ r.value ? (v(), F("div", bl, [
2119
+ s("div", hl, U(a(y)("inventory.ingredient.import.summary")), 1),
2120
+ (v(!0), F(ee, null, ce(k.value, (g) => (v(), z(wt, {
2121
+ key: g.sku._id,
2122
+ code: g.sku.code,
2123
+ name: g.sku.name,
2124
+ errors: g.errors,
2125
+ type: "create"
2126
+ }, null, 8, ["code", "name", "errors"]))), 128)),
2127
+ (v(!0), F(ee, null, ce(f.value, (g) => (v(), z(wt, {
2128
+ key: g.sku._id,
2129
+ code: g.sku.code,
2130
+ name: g.sku.name,
2131
+ errors: g.errors,
2132
+ type: "update"
2133
+ }, null, 8, ["code", "name", "errors"]))), 128))
2134
+ ])) : j("", !0)
2135
+ ]);
2136
+ };
2137
+ }
2138
+ }), xl = {
2139
+ key: 0,
2140
+ class: "flex items-center gap-1"
2141
+ }, kl = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, wl = { class: "flex flex-col py-8" }, Tl = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Vl = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, jl = /* @__PURE__ */ ve({
2142
+ __name: "IngredientsView",
2143
+ setup(i) {
2144
+ const o = fe(), b = Ee(), l = w(() => [
2145
+ {
2146
+ type: "string",
2147
+ key: "skuCode",
2148
+ entity: "sku",
2149
+ values: o.skus.map((x) => x.code)
2150
+ },
2151
+ {
2152
+ type: "string",
2153
+ key: "skuUnitAbbrev",
2154
+ entity: "sku",
2155
+ values: o.units.map((x) => x.abbrev)
2156
+ },
2157
+ {
2158
+ type: "string",
2159
+ key: "status",
2160
+ entity: "sku",
2161
+ values: ["Active", "Inactive"]
2162
+ }
2163
+ ]), c = N({
2164
+ logic: "AND",
2165
+ rules: [
2166
+ {
2167
+ property: "status",
2168
+ operator: "$in",
2169
+ value: ["Active"],
2170
+ type: "string"
2171
+ }
2172
+ ]
2173
+ }), h = w(
2174
+ () => new Set(b.getAvailableItems(b.businessSubsidiaryId))
2175
+ ), k = w(() => {
2176
+ if (!c.value)
2177
+ return o.skus;
2178
+ const P = mn.build(c.value);
2179
+ return o.skus.filter((x) => b.isEnabled && Q.value && h.value && !h.value.has(x._id) ? !1 : pn(
2180
+ {
2181
+ skuCode: x.code,
2182
+ skuUnitAbbrev: x.unit.abbrev,
2183
+ status: x.isInactive ? "Inactive" : "Active"
2184
+ },
2185
+ P
2186
+ ));
2187
+ }), f = vn(), n = De(), r = En(), y = Me(), { t: u } = ye(), { createIngredient: d, updateIngredient: p } = Ke(), { ingredientDialogProps: _, ingredientViewLoading: I } = Vn(Ke()), { columnDefs: $ } = Gn();
2188
+ function g(P) {
2189
+ switch (P) {
2190
+ case "add":
2191
+ return b.isEnabled ? void 0 : d();
2192
+ case "import":
2193
+ return B();
2194
+ case "export":
2195
+ return V();
2196
+ }
2197
+ }
2198
+ const D = N(""), C = N(!1), le = w(() => C.value || I.value), Q = N(!0), { breakpoints: me } = xn(), oe = w(() => me.value.xs || me.value.sm), se = w(() => oe.value ? 10 : 20), te = fn(), ae = N(!1), ge = [
2199
+ {
2200
+ value: "import",
2201
+ label: u("common.import")
2202
+ },
2203
+ {
2204
+ value: "export",
2205
+ label: u("common.export")
2206
+ }
2207
+ ];
2208
+ function be(P) {
2209
+ switch (ae.value = !1, P) {
2210
+ case "import":
2211
+ return B();
2212
+ case "export":
2213
+ return V();
2214
+ }
2215
+ }
2216
+ const Te = w(() => [
2217
+ ...b.isEnabled ? [] : [
2218
+ {
2219
+ label: u("inventory.ingredient.create.title"),
2220
+ value: "add",
2221
+ isPrimary: !0,
2222
+ prependIcon: "add"
2223
+ }
2224
+ ],
2225
+ { label: u("common.import"), value: "import" },
2226
+ { label: u("common.export"), value: "export" }
2227
+ ]);
2228
+ function V() {
2229
+ const P = nl();
2230
+ y.open({
2231
+ title: u("inventory.ingredient.export.success"),
2232
+ message: u("inventory.ingredient.export.filename", [P]),
2233
+ type: "success"
2234
+ });
2235
+ }
2236
+ function B() {
2237
+ n.open({
2238
+ title: u("inventory.ingredient.import.title"),
2239
+ contentComponent: _l,
2240
+ overlay: !0,
2241
+ closeButton: !0,
2242
+ primaryActions: {
2243
+ text: u("common.import"),
2244
+ close: !1
2245
+ },
2246
+ secondaryActions: {
2247
+ text: u("common.close"),
2248
+ close: !0
2249
+ },
2250
+ tertiaryActions: {
2251
+ text: u("inventory.ingredient.import.actions.downloadTemplate"),
2252
+ close: !1,
2253
+ variant: "plain"
2254
+ }
2255
+ }).onPrimary((P) => {
2256
+ if (!P) {
2257
+ y.open({
2258
+ title: u("inventory.ingredient.import.error.noData"),
2259
+ type: "error"
2260
+ });
2261
+ return;
2262
+ }
2263
+ if (!P.importCreateResult.length && !P.importUpdateResult.length) {
2264
+ y.open({
2265
+ title: u("inventory.ingredient.import.error.invalidContent"),
2266
+ message: u("inventory.ingredient.import.error.noImportData"),
2267
+ type: "error"
2268
+ });
2269
+ return;
2270
+ }
2271
+ if (P.importCreateResult.some((x) => x.errors.length) || P.importUpdateResult.some((x) => x.errors.length)) {
2272
+ y.open({
2273
+ title: u("inventory.ingredient.import.error.invalidContent"),
2274
+ message: u("inventory.ingredient.import.error.hasErrors"),
2275
+ type: "error"
2276
+ });
2277
+ return;
2278
+ }
2279
+ n.close(), G(P);
2280
+ }).onTertiary(ol);
2281
+ }
2282
+ async function G(P) {
2283
+ C.value = !0;
2284
+ try {
2285
+ const x = [
2286
+ ...P.importCreateResult.map(({ sku: R }) => ({ type: "create", sku: R })),
2287
+ ...P.importUpdateResult.map(({ sku: R }) => ({ type: "update", sku: R }))
2288
+ ], H = 100;
2289
+ let K = 0;
2290
+ const pe = () => {
2291
+ K += H, y.open({
2292
+ title: u("inventory.ingredient.import.progress", [
2293
+ Math.min(K, x.length),
2294
+ x.length
2295
+ ])
2296
+ });
2297
+ }, J = new Array();
2298
+ for (const R of x.chunk(100)) {
2299
+ pe();
2300
+ try {
2301
+ const O = await o.importSkus({
2302
+ create: R.filter((Y) => Y.type === "create").map((Y) => Y.sku),
2303
+ update: R.filter((Y) => Y.type === "update").map((Y) => Y.sku)
2304
+ });
2305
+ J.push(...O.errors);
2306
+ } catch (O) {
2307
+ J.push(
2308
+ ...R.map((Y) => {
2309
+ const ue = {
2310
+ module: hn.enum.sku,
2311
+ _id: Y.sku._id,
2312
+ name: Y.sku.name,
2313
+ message: (O == null ? void 0 : O.stack) ?? O
2314
+ };
2315
+ return {
2316
+ data: Y.sku,
2317
+ error: [ue]
2318
+ };
2319
+ })
2320
+ );
2321
+ }
2322
+ }
2323
+ y.open({
2324
+ title: u("inventory.ingredient.import.success"),
2325
+ type: "success"
2326
+ }), J.length && r.alert(
2327
+ "Some operation failed",
2328
+ X(
2329
+ "div",
2330
+ { class: "flex flex-col gap-8" },
2331
+ J.map(
2332
+ (R) => X("div", { class: "flex flex-col" }, [
2333
+ X("div", { class: "fm-typo-en-body-lg-600" }, `(${R.data.code}) ${R.data.name}`),
2334
+ X(
2335
+ "div",
2336
+ { class: "fm-typo-en-body-lg-400" },
2337
+ `${R.error.map((O) => (O == null ? void 0 : O.message) ?? "Unknown error").join(", ")}`
2338
+ )
2339
+ ])
2340
+ )
2341
+ )
2342
+ );
2343
+ } catch (x) {
2344
+ y.open({
2345
+ title: u("inventory.ingredient.import.error.failed"),
2346
+ message: u("inventory.ingredient.import.error.systemMessage", [x == null ? void 0 : x.message]),
2347
+ type: "error"
2348
+ }), console.error("Error in importing skus", P, x);
2349
+ } finally {
2350
+ C.value = !1;
2351
+ }
2352
+ }
2353
+ return (P, x) => {
2354
+ const H = A("FmSwitch"), K = A("FmTable"), pe = A("FmCollapsibleTabs"), J = A("FmBottomSheet");
2355
+ return v(), z(yn, {
2356
+ title: a(u)("inventory.ingredient.title"),
2357
+ actions: Te.value,
2358
+ "onClick:action": g
2359
+ }, {
2360
+ default: T(() => [
2361
+ s("div", {
2362
+ class: ne([
2363
+ "flex flex-col gap-8 max-h-full",
2364
+ {
2365
+ "p-0": oe.value,
2366
+ "px-24 ": !oe.value
2367
+ }
2368
+ ])
2369
+ }, [
2370
+ m(gn, {
2371
+ searchable: "",
2372
+ search: D.value,
2373
+ "onUpdate:search": x[1] || (x[1] = (R) => D.value = R),
2374
+ filterable: "",
2375
+ "filter-attributes": l.value,
2376
+ filter: c.value,
2377
+ "onUpdate:filter": x[2] || (x[2] = (R) => c.value = R)
2378
+ }, {
2379
+ default: T(() => [
2380
+ a(b).isEnabled ? (v(), F("div", xl, [
2381
+ s("span", kl, U(a(u)("inventory.integration.netsuite.subsidiaryHierarchy.filtering")), 1),
2382
+ m(In),
2383
+ m(Ge, null, {
2384
+ default: T(() => [
2385
+ m(H, {
2386
+ modelValue: Q.value,
2387
+ "onUpdate:modelValue": x[0] || (x[0] = (R) => Q.value = R)
2388
+ }, null, 8, ["modelValue"])
2389
+ ]),
2390
+ _: 1
2391
+ })
2392
+ ])) : j("", !0)
2393
+ ]),
2394
+ _: 1
2395
+ }, 8, ["search", "filter-attributes", "filter"]),
2396
+ (v(), z(K, {
2397
+ key: JSON.stringify(c.value),
2398
+ style: qt(a(te).tableHeight),
2399
+ "column-defs": a($),
2400
+ "row-data": k.value,
2401
+ "search-value": D.value,
2402
+ columnVisibility: {
2403
+ netsuiteSubsidiary: a(b).isEnabled
2404
+ },
2405
+ loading: (!a(f)._currentLocation || le.value) && a(b).isReady,
2406
+ "loading-text": "Loading",
2407
+ onRowClick: x[3] || (x[3] = (R) => a(p)(R.original)),
2408
+ "page-size": se.value
2409
+ }, {
2410
+ "list-row": T((R) => [
2411
+ m(bn, {
2412
+ row: R,
2413
+ onRowClick: a(p)
2414
+ }, Vt({
2415
+ default: T((O) => {
2416
+ var Y, ue, Ve, xe, Ae, Ue, Pe, he, re, Se;
2417
+ return [
2418
+ s("div", wl, [
2419
+ s("div", Tl, [
2420
+ m(a(ht), {
2421
+ render: (Ve = (ue = (Y = O.code) == null ? void 0 : Y.column) == null ? void 0 : ue.columnDef) == null ? void 0 : Ve.cell,
2422
+ props: (Ae = (xe = O.code) == null ? void 0 : xe.getContext) == null ? void 0 : Ae.call(xe)
2423
+ }, null, 8, ["render", "props"])
2424
+ ]),
2425
+ s("div", Vl, [
2426
+ m(a(ht), {
2427
+ render: (he = (Pe = (Ue = O.name) == null ? void 0 : Ue.column) == null ? void 0 : Pe.columnDef) == null ? void 0 : he.cell,
2428
+ props: (Se = (re = O.name) == null ? void 0 : re.getContext) == null ? void 0 : Se.call(re)
2429
+ }, null, 8, ["render", "props"])
2430
+ ])
2431
+ ])
2432
+ ];
2433
+ }),
2434
+ _: 2
2435
+ }, [
2436
+ C.value ? {
2437
+ name: "loading-text",
2438
+ fn: T(() => [
2439
+ s("div", null, U(a(u)("inventory.ingredient.table.importing")), 1)
2440
+ ]),
2441
+ key: "0"
2442
+ } : void 0
2443
+ ]), 1032, ["row", "onRowClick"])
2444
+ ]),
2445
+ _: 1
2446
+ }, 8, ["style", "column-defs", "row-data", "search-value", "columnVisibility", "loading", "page-size"]))
2447
+ ], 2),
2448
+ (v(), z(pt, { to: "body" }, [
2449
+ m(Qo, Gt(Kt(a(_))), null, 16)
2450
+ ])),
2451
+ (v(), z(pt, { to: "body" }, [
2452
+ m(J, {
2453
+ "dismiss-away": "",
2454
+ modelValue: ae.value,
2455
+ "onUpdate:modelValue": x[5] || (x[5] = (R) => ae.value = R)
2456
+ }, {
2457
+ default: T(() => [
2458
+ m(pe, {
2459
+ class: "pb-8",
2460
+ items: ge,
2461
+ "onUpdate:modelValue": x[4] || (x[4] = (R) => be(R))
2462
+ })
2463
+ ]),
2464
+ _: 1
2465
+ }, 8, ["modelValue"])
2466
+ ]))
2467
+ ]),
2468
+ _: 1
2469
+ }, 8, ["title", "actions"]);
2470
+ };
2471
+ }
2472
+ });
2473
+ export {
2474
+ jl as default
2475
+ };