@feedmepos/mf-inventory-portal 1.0.36 → 1.0.37-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/{App-BM-ivBnF.js → App-_SMozUEj.js} +1 -1
  2. package/dist/{ApprovalView-C4hE43Zp.js → ApprovalView-D55iBGg5.js} +19 -19
  3. package/dist/{BindingsDialog-BqjiXxGY.js → BindingsDialog-Di_xTPkA.js} +4 -4
  4. package/dist/{BindingsPicker-DqCR7P5k.js → BindingsPicker-BwIKt9Il.js} +1 -1
  5. package/dist/{BindingsTable-DD_mVBtS.js → BindingsTable-CMFvNSAH.js} +4 -4
  6. package/dist/{ClosingDraftView-CL09Xu9q.js → ClosingDraftView-DXoi5cw9.js} +26 -26
  7. package/dist/ClosingTemplateView-DaPOj50P.js +1849 -0
  8. package/dist/{DeliveryOrderPrintPreview-CNPUHnpX.js → DeliveryOrderPrintPreview-CkIPZo14.js} +4 -4
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DB6m8oSF.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BSzt53-l.js} +11 -11
  10. package/dist/{FmMultiselectDialog-DJ5cyN7G.js → FmMultiselectDialog-EpV0X6CI.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-CPAnSCWa.js → FmUnitInput.vue_vue_type_script_setup_true_lang-Cn3qOqJr.js} +21 -21
  12. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-CauBVtK9.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-BUQQL5kL.js} +1 -1
  13. package/dist/{IngredientGroupView-D0U1ivRz.js → IngredientGroupView-DvxOGAuo.js} +2 -2
  14. package/dist/IngredientsView-BhFDYfnd.js +1851 -0
  15. package/dist/{IntegrationView-hERgFYsT.js → IntegrationView-B_EmS2-x.js} +69 -69
  16. package/dist/{InventoryBindingForm-vO00BnZP.js → InventoryBindingForm-B79lRAe6.js} +1 -1
  17. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-Bku7tdc-.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DBsD7abQ.js} +24 -24
  18. package/dist/{InventoryBindingSummary-DWOniuG6.js → InventoryBindingSummary-CmnSXYAW.js} +1 -1
  19. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-C4_atZsW.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CDRN_Nrk.js} +1 -1
  20. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-DUdI1WOL.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BknocD4_.js} +10 -10
  21. package/dist/{PublishView-enVS6QHQ.js → PublishView-DNkUYpMh.js} +17 -17
  22. package/dist/{PurchaseOrderPrintPreview-Z769Yvkh.js → PurchaseOrderPrintPreview-D0UhIY8z.js} +12 -12
  23. package/dist/{ReceiveRequestView-BYYWrgNX.js → ReceiveRequestView-DsBpjA9P.js} +797 -782
  24. package/dist/{RecipeView-CU9pkFiv.js → RecipeView-lpMLqWM8.js} +3 -3
  25. package/dist/{StockView-iqR-h1Mg.js → StockView-CIgg_FTJ.js} +6 -6
  26. package/dist/{SupplierView-DFzgQ53O.js → SupplierView-fwzviqqM.js} +3 -3
  27. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-BEVlutvf.js → TransferDetails.vue_vue_type_script_setup_true_lang-TYNgMCEs.js} +604 -602
  28. package/dist/{TransferTemplateView-EZ_z14kY.js → TransferTemplateView-CSy8pydr.js} +83 -83
  29. package/dist/{UnitView-gYD75UdW.js → UnitView-CMOz7RLY.js} +3 -3
  30. package/dist/{WarehouseView-COLgYw-j.js → WarehouseView-B-1c6rRg.js} +1 -1
  31. package/dist/api/duplicate-template.d.ts +5 -0
  32. package/dist/api/inventory.d.ts +4 -0
  33. package/dist/api/netsuite.d.ts +7 -0
  34. package/dist/{app-DMbkakEB.js → app-CFm28RQ_.js} +53154 -52645
  35. package/dist/app.d.ts +9 -0
  36. package/dist/app.js +1 -1
  37. package/dist/components/inventory-binding/InventoryBinding.vue.d.ts +1 -0
  38. package/dist/components/row-action.enum.d.ts +2 -1
  39. package/dist/components/shell/inventory/binding-ui.vue.d.ts +1 -0
  40. package/dist/{decimal-BLjZMddB.js → decimal-UyI93Y1E.js} +1 -1
  41. package/dist/format-unit-display-CNki_g8Q.js +1275 -0
  42. package/dist/{index-C5rv3Yu2.js → index-BWYshfa3.js} +1 -1
  43. package/dist/{index-Bj0hlHvy.js → index-DliBh-3z.js} +1 -1
  44. package/dist/{stock-DjOpPBxG.js → stock-A60nU_aj.js} +1 -1
  45. package/dist/stores/integration/netsuite.d.ts +7 -1
  46. package/dist/stores/inventory.d.ts +9 -0
  47. package/dist/{supplier-BRKfl2V3.js → supplier-lcKFLaW5.js} +1 -1
  48. package/dist/tsconfig.app.tsbuildinfo +1 -1
  49. package/dist/{use-ingredient-select-dialog-DRIWNN3P.js → use-ingredient-select-dialog-B17VDJ0o.js} +1 -1
  50. package/dist/{use-inventory-binding-dialog-DLnKkFpe.js → use-inventory-binding-dialog-sj5lERBj.js} +1 -1
  51. package/dist/views/adjustment-template/wastage-template/actions.d.ts +4 -1
  52. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +8 -0
  53. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +24 -0
  54. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +1 -0
  55. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +16 -1
  56. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +12 -0
  57. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +2 -0
  58. package/dist/views/ingredients/composables/use-ingredient-table.d.ts +1 -0
  59. package/dist/views/integration/components/netsuite/InventoryTransferIngredientTable.vue.d.ts +2 -0
  60. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +4 -0
  61. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +17 -0
  62. package/dist/views/receive-request/components/transfer-form/components/ForecastStock.vue.d.ts +2 -0
  63. package/dist/views/receive-request/components/transfer-form/components/TransferItemTable.vue.d.ts +4 -0
  64. package/dist/views/receive-request/components/transfer-form/composables/use-transfer-items.d.ts +1 -0
  65. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +4 -0
  66. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +24 -0
  67. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +24 -0
  68. package/dist/views/stock/components/dialog/AdjustedItemForm.vue.d.ts +2 -0
  69. package/dist/views/transfer-template/components/transfer-template-dialog/TransferTemplateDialog.vue.d.ts +2 -0
  70. package/dist/views/transfer-template/components/transfer-template-form/components/NetSuiteCustomCodeSelection.vue.d.ts +2 -0
  71. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateItemTable.vue.d.ts +2 -0
  72. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.d.ts +1 -0
  73. package/dist/views/transfer-template/composables/use-netsuite-custom-field.d.ts +3 -0
  74. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +16 -1
  75. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +12 -0
  76. package/dist/{vue-i18n-x8-PdKzv.js → vue-i18n-CZSieSF0.js} +487 -487
  77. package/package.json +4 -4
  78. package/dist/ClosingTemplateView-CDWMdZOk.js +0 -1804
  79. package/dist/IngredientsView-pgJWthql.js +0 -1838
  80. package/dist/format-unit-display-BkXJg2Ux.js +0 -1230
@@ -0,0 +1,1851 @@
1
+ import { ref as L, h as X, defineComponent as le, computed as S, resolveComponent as w, openBlock as _, createBlock as A, withCtx as V, createVNode as v, unref as u, createElementBlock as D, Fragment as ee, createElementVNode as c, createCommentVNode as O, renderSlot as ve, createTextVNode as Ee, toDisplayString as T, normalizeClass as Q, onMounted as dt, watch as Je, renderList as ye, isRef as Ne, createSlots as Ze, normalizeStyle as ut, Teleport as ze, normalizeProps as mt, guardReactiveProps as ct } from "vue";
2
+ import { a as te, e as H, f as Qe, S as pt, h as vt, D as Le, i as _e, A as ke, b as Ue, j as Xe, k as Ve, t as et, l as ge, m as we, U as ft, n as yt, M as gt, o as Oe, p as He, c as tt, q as je, r as nt, s as bt, v as ot, w as ht, x as _t, I as xt, y as kt, z as Vt, N as St, H as Ct, u as wt, B as Ft, _ as Mt, C as It, E as $t, G as Ye, J as Et } from "./app-CFm28RQ_.js";
3
+ import { useDialog as lt, useSnackbar as Se, components as qe, useProxiedModel as Ge, useDialogChild as Ut, useBreakpoints as Rt } from "@feedmepos/ui-library";
4
+ import { i as At, _ as Tt } from "./is-linked-ingredient-error-fJ2TJb3z.js";
5
+ import { useI18n as ae, useCoreStore as be } from "@feedmepos/mf-common";
6
+ import { defineStore as Dt, storeToRefs as Bt } from "pinia";
7
+ import { g as Pt, _ as Fe, S as Me } from "./StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js";
8
+ import { _ as Nt } from "./InventoryBindingForm.vue_vue_type_script_setup_true_lang-DBsD7abQ.js";
9
+ import { _ as Ie } from "./IngredientBindedItem.vue_vue_type_script_setup_true_lang-BUQQL5kL.js";
10
+ import { _ as xe } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-CRZiQHjx.js";
11
+ import { _ as zt } from "./FmCustomAttribute.vue_vue_type_script_setup_true_lang-D-IWRjRD.js";
12
+ import { r as Lt } from "./random-CSbEbElR.js";
13
+ import "./array-Ca8T3f_G.js";
14
+ import { u as Ot } from "./FmMultiselectDialog-EpV0X6CI.js";
15
+ const $e = Dt("ingredientForm", function() {
16
+ const o = lt(), y = Se(), l = te(), n = L(!1), { t: a } = ae(), s = L();
17
+ function m() {
18
+ const b = {
19
+ unit: {},
20
+ mode: H.CREATE,
21
+ show: !0,
22
+ "onUpdate:show"(r) {
23
+ s.value.show = r;
24
+ }
25
+ };
26
+ s.value = b;
27
+ }
28
+ async function p(b) {
29
+ const r = {
30
+ unit: Qe(b),
31
+ mode: H.UPDATE,
32
+ show: !0,
33
+ "onUpdate:show"(x) {
34
+ s.value.show = x;
35
+ }
36
+ };
37
+ s.value = r;
38
+ }
39
+ async function g(b) {
40
+ n.value = !0;
41
+ try {
42
+ await l.deleteSku(b), y.open({
43
+ title: "Success",
44
+ message: `Deleted ${b.name}`,
45
+ type: "success"
46
+ });
47
+ } catch (r) {
48
+ r instanceof pt && At(r) ? o.open({
49
+ title: "Cannot delete ingredient",
50
+ contentComponent: Tt,
51
+ contentComponentProps: {
52
+ subject: (b == null ? void 0 : b.name) ?? "",
53
+ items: r.errorResponse.message
54
+ },
55
+ secondaryActions: {
56
+ text: "Close",
57
+ close: !0
58
+ }
59
+ }) : console.log("unable to delete ingredient", r), y.open({
60
+ title: `Cannot delete ${b.name}`,
61
+ message: "Please try again.",
62
+ type: "error"
63
+ }), console.error("failed to delete ingredient", r);
64
+ } finally {
65
+ n.value = !1;
66
+ }
67
+ }
68
+ function i(b) {
69
+ o.open({
70
+ title: a("inventory.ingredient.delete.title", [(b == null ? void 0 : b.name) ?? ""]),
71
+ closeButton: !1,
72
+ message: a("inventory.ingredient.delete.message"),
73
+ primaryActions: {
74
+ text: a("common.delete"),
75
+ close: !0,
76
+ variant: "destructive"
77
+ },
78
+ secondaryActions: {
79
+ text: a("common.cancel"),
80
+ close: !0
81
+ }
82
+ }).onPrimary(() => g(b));
83
+ }
84
+ return {
85
+ createIngredient: m,
86
+ updateIngredient: p,
87
+ deleteIngredient: i,
88
+ ingredientDialogProps: s,
89
+ ingredientViewLoading: n
90
+ };
91
+ });
92
+ function Ht() {
93
+ const { updateIngredient: d, deleteIngredient: o } = $e(), y = te(), { t: l } = ae();
94
+ async function n(s, m) {
95
+ const p = Qe(m);
96
+ if (s === _e.Edit) {
97
+ await d(p);
98
+ return;
99
+ }
100
+ if (s === _e.Delete) {
101
+ await o(p);
102
+ return;
103
+ }
104
+ }
105
+ return { columnDefs: [
106
+ {
107
+ accessorKey: "code",
108
+ header: () => l("inventory.ingredient.code"),
109
+ enableSorting: !0,
110
+ size: 300
111
+ },
112
+ {
113
+ accessorKey: "name",
114
+ header: () => l("inventory.ingredient.name"),
115
+ enableSorting: !0,
116
+ size: 300,
117
+ cell(s) {
118
+ const m = s.row.original, p = y.skuBindingFlattenCache[m._id], g = p == null ? void 0 : p.inventoryBindings.some(
119
+ (i) => "error" in i && i.reason === "circularDependency"
120
+ );
121
+ return X("div", { class: "flex items-center w-full gap-4" }, [
122
+ g ? X(
123
+ qe.FmTooltip,
124
+ {},
125
+ {
126
+ default() {
127
+ return X(qe.FmIcon, {
128
+ name: "info",
129
+ color: "system-error-300",
130
+ size: "sm"
131
+ });
132
+ },
133
+ content() {
134
+ return l("inventory.inventoryBindings.circularError");
135
+ }
136
+ }
137
+ ) : null,
138
+ m.name
139
+ ]);
140
+ }
141
+ },
142
+ {
143
+ id: "unit",
144
+ header: () => l("inventory.ingredient.unit"),
145
+ cell(s) {
146
+ var p;
147
+ const m = s.row.original;
148
+ if (m.trackingMeasurement) {
149
+ const g = (p = m.unit.measurements) == null ? void 0 : p.find(
150
+ (i) => i.id === m.trackingMeasurement
151
+ );
152
+ if (g)
153
+ return `${g.name} (${g.abbrev})`;
154
+ }
155
+ return `${m.unit.name} (${m.unit.abbrev})`;
156
+ },
157
+ enableSorting: !1,
158
+ size: "auto"
159
+ },
160
+ {
161
+ accessorKey: "isInactive",
162
+ header: () => l("inventory.ingredient.isInactive.title"),
163
+ cell(s) {
164
+ const m = s.row.original.isInactive;
165
+ return X(
166
+ "span",
167
+ {
168
+ class: [
169
+ "inline-block px-3 py-1 rounded-full text-xs font-semibold",
170
+ m ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"
171
+ ].join(" ")
172
+ },
173
+ l(m ? "inventory.ingredient.isInactive.yes" : "inventory.ingredient.isInactive.no")
174
+ );
175
+ },
176
+ enableSorting: !0,
177
+ size: 300
178
+ },
179
+ {
180
+ id: "action",
181
+ header: "",
182
+ cell(s) {
183
+ return vt(
184
+ [Le[_e.Edit], Le[_e.Delete]],
185
+ (m) => {
186
+ n(m, s.row.original);
187
+ }
188
+ );
189
+ },
190
+ enableSorting: !1,
191
+ size: 40,
192
+ meta: {
193
+ cellClass: "",
194
+ headerClass: ""
195
+ }
196
+ }
197
+ ] };
198
+ }
199
+ const jt = /* @__PURE__ */ le({
200
+ __name: "ConvertForm",
201
+ props: {
202
+ modelValue: {},
203
+ rootValue: {},
204
+ disabled: { type: Boolean },
205
+ readonly: { type: Boolean }
206
+ },
207
+ emits: ["update:modelValue"],
208
+ setup(d, { emit: o }) {
209
+ const y = d, l = S(() => {
210
+ var r;
211
+ return (r = y.rootValue) == null ? void 0 : r.unit;
212
+ }), n = S(() => {
213
+ var r;
214
+ return (r = y.rootValue) == null ? void 0 : r._id;
215
+ }), a = o, { t: s } = ae(), m = S({
216
+ get() {
217
+ return !!y.modelValue;
218
+ },
219
+ set(r) {
220
+ r ? a("update:modelValue", {
221
+ measurement: null,
222
+ inventoryBindings: []
223
+ }) : a("update:modelValue", null);
224
+ }
225
+ }), p = S(() => Pt(l.value));
226
+ function g(r) {
227
+ const x = y.modelValue ?? {};
228
+ x.measurement = r ? `${r}` : null, a("update:modelValue", x);
229
+ }
230
+ function i(r) {
231
+ const x = y.modelValue ?? {};
232
+ x.inventoryBindings = r, a("update:modelValue", x);
233
+ }
234
+ const b = S(() => {
235
+ if (!y.modelValue) return null;
236
+ const r = y.modelValue;
237
+ return r.measurement ? p.value.find((x) => x.value === r.measurement) ?? null : p.value.find((x) => x.value === null) ?? null;
238
+ });
239
+ return (r, x) => {
240
+ const P = w("FmSwitch"), E = w("FmSelect"), N = w("FmCard");
241
+ return _(), A(N, {
242
+ variant: "outlined",
243
+ class: "p-16 flex flex-col gap-16"
244
+ }, {
245
+ default: V(() => {
246
+ var k, I;
247
+ return [
248
+ v(P, {
249
+ value: "",
250
+ "model-value": m.value,
251
+ "onUpdate:modelValue": x[0] || (x[0] = (M) => m.value = M),
252
+ label: u(s)("inventory.ingredient.convertible.title"),
253
+ sublabel: u(s)("inventory.ingredient.convertible.subtitle"),
254
+ labelPlacement: "right",
255
+ disabled: r.readonly
256
+ }, null, 8, ["model-value", "label", "sublabel", "disabled"]),
257
+ m.value ? (_(), D(ee, { key: 0 }, [
258
+ c("div", null, [
259
+ v(E, {
260
+ label: u(s)("inventory.ingredient.convertible.convertTo"),
261
+ modelValue: (k = b.value) == null ? void 0 : k.value,
262
+ "onUpdate:modelValue": g,
263
+ items: p.value,
264
+ disabled: r.readonly
265
+ }, null, 8, ["label", "modelValue", "items", "disabled"])
266
+ ]),
267
+ v(Nt, {
268
+ id: n.value,
269
+ "model-value": ((I = r.modelValue) == null ? void 0 : I.inventoryBindings) ?? [],
270
+ "onUpdate:modelValue": i,
271
+ "exclude-binding-id": n.value,
272
+ rules: [u(ke)(1)],
273
+ readonly: r.readonly
274
+ }, null, 8, ["id", "model-value", "exclude-binding-id", "rules", "readonly"])
275
+ ], 64)) : O("", !0)
276
+ ];
277
+ }),
278
+ _: 1
279
+ });
280
+ };
281
+ }
282
+ });
283
+ function ie() {
284
+ return {
285
+ low: 6,
286
+ mid: 14
287
+ };
288
+ }
289
+ const Yt = {
290
+ key: 0,
291
+ class: "flex flex-col gap-4"
292
+ }, fe = /* @__PURE__ */ le({
293
+ __name: "FmLockableField",
294
+ props: {
295
+ locked: { type: Boolean },
296
+ disabled: { type: Boolean },
297
+ label: {},
298
+ helperText: {},
299
+ modelValue: {},
300
+ tooltipMessage: {},
301
+ tooltipPlacement: {},
302
+ tooltipZIndex: {}
303
+ },
304
+ setup(d) {
305
+ return (o, y) => {
306
+ const l = w("FmLabel"), n = w("FmIcon"), a = w("FmTooltip"), s = w("FmField");
307
+ return o.locked ? (_(), D("div", Yt, [
308
+ ve(o.$slots, "label", {}, () => [
309
+ v(l, {
310
+ label: o.label,
311
+ disabled: o.disabled
312
+ }, null, 8, ["label", "disabled"])
313
+ ]),
314
+ ve(o.$slots, "field", {}, () => [
315
+ v(s, { disabled: o.disabled }, {
316
+ prepend: V(() => [
317
+ o.tooltipMessage ? (_(), A(a, {
318
+ key: 0,
319
+ placement: o.tooltipPlacement,
320
+ "z-index": o.tooltipZIndex
321
+ }, {
322
+ content: V(() => [
323
+ Ee(T(o.tooltipMessage), 1)
324
+ ]),
325
+ default: V(() => [
326
+ v(n, {
327
+ name: "lock",
328
+ color: "neutral-gray-400"
329
+ })
330
+ ]),
331
+ _: 1
332
+ }, 8, ["placement", "z-index"])) : (_(), A(n, {
333
+ key: 1,
334
+ name: "lock",
335
+ color: "neutral-gray-400"
336
+ }))
337
+ ]),
338
+ default: V(() => [
339
+ ve(o.$slots, "modelValue", {}, () => [
340
+ c("div", {
341
+ class: Q([
342
+ o.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-primary",
343
+ "line-clamp-1 text-ellipsis break-all"
344
+ ])
345
+ }, T(o.modelValue), 3)
346
+ ])
347
+ ]),
348
+ _: 3
349
+ }, 8, ["disabled"])
350
+ ]),
351
+ ve(o.$slots, "helper-text", {}, () => [
352
+ c("div", {
353
+ class: Q([
354
+ "fm-typo-en-body-sm-400 line-clamp-1",
355
+ o.disabled ? "text-fm-color-typo-disabled" : "text-fm-color-typo-secondary"
356
+ ])
357
+ }, T(o.helperText), 3)
358
+ ])
359
+ ])) : ve(o.$slots, "default", { key: 1 });
360
+ };
361
+ }
362
+ }), qt = { class: "flex gap-8" }, Gt = { class: "flex-1" }, Wt = { class: "flex-1" }, Kt = { class: "text-fm-color-typo-secondary" }, Jt = { class: "text-fm-color-typo-secondary whitespace-nowrap" }, Zt = {
363
+ key: 3,
364
+ class: "border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16"
365
+ }, Qt = { class: "flex flex-col" }, Xt = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, en = {
366
+ key: 4,
367
+ class: "border-1 border-fm-color-neutral-gray-200 fm-corner-radius-lg flex flex-col p-16 gap-16"
368
+ }, tn = { class: "flex flex-col gap-12" }, nn = { class: "flex flex-col gap-4" }, on = { class: "fm-typo-en-title-sm-600" }, ln = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, an = { class: "flex flex-col gap-4" }, rn = { class: "flex fm-corner-radius-md border-1 border-fm-color-neutral-gray-200" }, sn = { class: "flex-1 p-12 flex flex-col gap-8" }, dn = { class: "mx-auto" }, un = { class: "flex flex-col" }, mn = { class: "fm-typo-en-body-sm-600 translate-y-4" }, cn = { class: "flex-1 p-12 flex flex-col gap-8" }, pn = { class: "mx-auto" }, vn = { class: "flex flex-col" }, fn = { class: "fm-typo-en-body-sm-600 translate-y-4" }, yn = { class: "flex-1 p-12 flex flex-col gap-8" }, gn = { class: "mx-auto" }, bn = { class: "flex flex-col" }, hn = { class: "fm-typo-en-body-sm-600 translate-y-4" }, _n = /* @__PURE__ */ le({
369
+ __name: "IngredientForm",
370
+ props: {
371
+ mode: {},
372
+ modelValue: {},
373
+ disabled: { type: Boolean }
374
+ },
375
+ emits: ["update:modelValue", "click:submit"],
376
+ setup(d, { expose: o, emit: y }) {
377
+ var B;
378
+ const { t: l } = ae(), n = d, a = y, s = te(), m = be(), p = tt(), g = Ue(), i = S(() => g.isEnabled);
379
+ function b(t) {
380
+ if (t.length === 0) return;
381
+ const e = t[0], f = n.modelValue ?? {
382
+ unit: s.units.find((h) => h)
383
+ };
384
+ f.unit || (f.unit = e, a("update:modelValue", f));
385
+ }
386
+ dt(() => {
387
+ b(s.units);
388
+ }), Je([() => s.units], ([t]) => {
389
+ b(t);
390
+ });
391
+ function r() {
392
+ a("click:submit");
393
+ }
394
+ const x = S({
395
+ get() {
396
+ var t;
397
+ return ((t = n.modelValue) == null ? void 0 : t.code) ?? "";
398
+ },
399
+ set(t) {
400
+ const e = n.modelValue ? {
401
+ ...n.modelValue
402
+ } : {};
403
+ e.code = t, a("update:modelValue", e);
404
+ }
405
+ }), P = S({
406
+ get() {
407
+ var t;
408
+ return ((t = n.modelValue) == null ? void 0 : t.isInactive) ?? !1;
409
+ },
410
+ set(t) {
411
+ const e = n.modelValue ? {
412
+ ...n.modelValue
413
+ } : {};
414
+ e.isInactive = t, a("update:modelValue", e);
415
+ }
416
+ }), E = S({
417
+ get() {
418
+ var t;
419
+ return ((t = n.modelValue) == null ? void 0 : t.name) ?? "";
420
+ },
421
+ set(t) {
422
+ const e = n.modelValue ? {
423
+ ...n.modelValue
424
+ } : {};
425
+ e.name = t, a("update:modelValue", e);
426
+ }
427
+ }), N = S({
428
+ get() {
429
+ var e, f;
430
+ const t = (f = (e = n.modelValue) == null ? void 0 : e.defaultCost) == null ? void 0 : f.costPerUnit;
431
+ return t ? +Xe(t) : 0;
432
+ },
433
+ set(t) {
434
+ var f, h, R, $;
435
+ const e = n.modelValue ? {
436
+ ...n.modelValue
437
+ } : {};
438
+ e.defaultCost ?? (e.defaultCost = {
439
+ costPerUnit: {
440
+ amount: 0,
441
+ precision: 2,
442
+ currency: ((f = Ve(m.currentCountry.value)) == null ? void 0 : f.currency) ?? "MYR"
443
+ },
444
+ measurement: ($ = (R = (h = n.modelValue) == null ? void 0 : h.unit) == null ? void 0 : R.measurements) == null ? void 0 : $.find(
445
+ (j) => {
446
+ var Y;
447
+ return j.id === ((Y = n.modelValue) == null ? void 0 : Y.trackingMeasurement);
448
+ }
449
+ )
450
+ }), e.defaultCost.costPerUnit = {
451
+ ...e.defaultCost.costPerUnit,
452
+ ...et(+t, 4)
453
+ }, a("update:modelValue", e);
454
+ }
455
+ }), k = S(() => {
456
+ var e, f, h;
457
+ const t = ((e = n.modelValue) == null ? void 0 : e.unit) ?? s.units.find((R) => R);
458
+ return t ? {
459
+ _id: t._id,
460
+ measurement: (f = n.modelValue) == null ? void 0 : f.trackingMeasurement,
461
+ name: ((h = t.measurements.find((R) => {
462
+ var $;
463
+ return R.id === (($ = n.modelValue) == null ? void 0 : $.trackingMeasurement);
464
+ })) == null ? void 0 : h.name) ?? t.name
465
+ } : null;
466
+ }), I = S(
467
+ () => s.units.flatMap(({ name: t, _id: e, abbrev: f, measurements: h }) => [
468
+ {
469
+ label: `${t}`,
470
+ value: null,
471
+ displayAsSection: !0
472
+ },
473
+ {
474
+ label: `${t} (${f})`,
475
+ value: { _id: e },
476
+ displayAsSection: !1
477
+ },
478
+ ...h.map(({ id: R, name: $, abbrev: j }) => ({
479
+ label: `${$} (${j})`,
480
+ value: { _id: e, measurement: R },
481
+ displayAsSection: !1
482
+ }))
483
+ ])
484
+ );
485
+ function M(t) {
486
+ var e, f, h, R, $;
487
+ return ((f = (e = n.modelValue) == null ? void 0 : e.unit) == null ? void 0 : f._id) === ((h = t.value) == null ? void 0 : h._id) && ((R = n.modelValue) == null ? void 0 : R.trackingMeasurement) === (($ = t.value) == null ? void 0 : $.measurement);
488
+ }
489
+ function ne(t) {
490
+ var j, Y;
491
+ if (!t) return;
492
+ const { _id: e, measurement: f } = t, h = f || void 0, R = s.units.find((G) => G._id === e);
493
+ if (!R)
494
+ return;
495
+ const $ = n.modelValue ?? {};
496
+ $.unit = R, $.trackingMeasurement = h, $.convert && ($.convert.measurement = h || null), p.enableTotalCost && ($.defaultCost = {
497
+ measurement: R.measurements.find((G) => G.id === h),
498
+ costPerUnit: {
499
+ ...((j = $.defaultCost) == null ? void 0 : j.costPerUnit) ?? {
500
+ amount: 0,
501
+ precision: 2,
502
+ currency: ((Y = Ve(m.currentCountry.value)) == null ? void 0 : Y.currency) ?? "MYR"
503
+ }
504
+ }
505
+ }), a("update:modelValue", $);
506
+ }
507
+ const W = S({
508
+ get() {
509
+ var t;
510
+ return ((t = n.modelValue) == null ? void 0 : t.convert) ?? null;
511
+ },
512
+ set(t) {
513
+ const e = n.modelValue ? {
514
+ ...n.modelValue
515
+ } : {};
516
+ t ? e.convert = t : e.convert = null, a("update:modelValue", e);
517
+ }
518
+ }), K = S(() => ge.options.filter(
519
+ (t) => t === ge.enum.FIFO || t === ge.enum.WAVG
520
+ ).map((t) => ({
521
+ label: l(`inventory.ingredient.valuationMethod.${t}`),
522
+ value: t
523
+ }))), de = S({
524
+ get() {
525
+ var t;
526
+ return ((t = n.modelValue) == null ? void 0 : t.valuation) ?? "WAVG";
527
+ },
528
+ set(t) {
529
+ const e = n.modelValue ? {
530
+ ...n.modelValue
531
+ } : {};
532
+ e.valuation = t, a("update:modelValue", e);
533
+ }
534
+ }), re = S({
535
+ get() {
536
+ var t;
537
+ return ((t = n.modelValue) == null ? void 0 : t.customAttributes) ?? {};
538
+ },
539
+ set(t) {
540
+ const e = n.modelValue ? {
541
+ ...n.modelValue
542
+ } : {};
543
+ e.customAttributes = t, a("update:modelValue", e);
544
+ }
545
+ }), se = L();
546
+ o({
547
+ validateInputs: () => {
548
+ var t, e;
549
+ (e = (t = se.value) == null ? void 0 : t.validateInputs) == null || e.call(t);
550
+ },
551
+ resetInputsValidation: () => {
552
+ var t, e;
553
+ (e = (t = se.value) == null ? void 0 : t.resetInputsValidation) == null || e.call(t);
554
+ },
555
+ resetInputs: () => {
556
+ var t, e;
557
+ (e = (t = se.value) == null ? void 0 : t.resetInputs) == null || e.call(t);
558
+ }
559
+ });
560
+ const oe = L(!1), he = S(
561
+ () => {
562
+ var t, e, f;
563
+ return (t = n.modelValue) != null && t._id ? ((f = s.menu.bindedBySkuId[(e = n.modelValue) == null ? void 0 : e._id]) == null ? void 0 : f.filter(
564
+ (h) => h.from === "INGREDIENT"
565
+ )) ?? [] : [];
566
+ }
567
+ ), ue = S(
568
+ () => {
569
+ var t, e, f;
570
+ return (t = n.modelValue) != null && t._id ? ((f = s.menu.bindedBySkuId[(e = n.modelValue) == null ? void 0 : e._id]) == null ? void 0 : f.filter(
571
+ (h) => h.from === "RECIPE"
572
+ )) ?? [] : [];
573
+ }
574
+ ), me = S(
575
+ () => {
576
+ var t, e, f;
577
+ return (t = n.modelValue) != null && t._id ? ((f = s.menu.bindedBySkuId[(e = n.modelValue) == null ? void 0 : e._id]) == null ? void 0 : f.filter((h) => h.from === "MENU")) ?? [] : [];
578
+ }
579
+ ), Ce = S(
580
+ () => s.skus.map((t) => ({ label: t.name, value: t.code }))
581
+ ), U = L((B = n.modelValue) == null ? void 0 : B.code);
582
+ function C(t) {
583
+ var f;
584
+ const e = t.el;
585
+ e && ((f = e.querySelector("[x-should-scroll-into=true]")) == null || f.scrollIntoView());
586
+ }
587
+ const ce = S(
588
+ () => {
589
+ var t, e, f, h, R, $;
590
+ return ((h = (f = (e = (t = n.modelValue) == null ? void 0 : t.unit) == null ? void 0 : e.measurements) == null ? void 0 : f.find(
591
+ (j) => {
592
+ var Y;
593
+ return j.id === ((Y = n.modelValue) == null ? void 0 : Y.trackingMeasurement);
594
+ }
595
+ )) == null ? void 0 : h.abbrev) ?? (($ = (R = n.modelValue) == null ? void 0 : R.unit) == null ? void 0 : $.abbrev);
596
+ }
597
+ ), J = S({
598
+ get() {
599
+ var t, e;
600
+ return ((e = (t = n.modelValue) == null ? void 0 : t.thresholds) == null ? void 0 : e.low) ?? ie().low;
601
+ },
602
+ set(t) {
603
+ var h;
604
+ const e = ((h = n.modelValue) == null ? void 0 : h.thresholds) ?? ie();
605
+ e.low = t;
606
+ const f = n.modelValue ? {
607
+ ...n.modelValue
608
+ } : {};
609
+ f.thresholds = e, a("update:modelValue", f);
610
+ }
611
+ }), Z = S({
612
+ get() {
613
+ var t, e;
614
+ return ((e = (t = n.modelValue) == null ? void 0 : t.thresholds) == null ? void 0 : e.mid) ?? ie().mid;
615
+ },
616
+ set(t) {
617
+ var h;
618
+ const e = ((h = n.modelValue) == null ? void 0 : h.thresholds) ?? ie();
619
+ e.mid = t;
620
+ const f = n.modelValue ? {
621
+ ...n.modelValue
622
+ } : {};
623
+ f.thresholds = e, a("update:modelValue", f);
624
+ }
625
+ });
626
+ function z() {
627
+ return function(e) {
628
+ return typeof (e == null ? void 0 : e.low) != "number" || typeof (e == null ? void 0 : e.mid) != "number" ? "Required" : e.low >= e.mid ? "Days for red indicator should be less than yellow indicator." : !0;
629
+ };
630
+ }
631
+ return (t, e) => {
632
+ const f = w("FmTextField"), h = w("FmLabel"), R = w("FmField"), $ = w("FmMenuHeader"), j = w("FmMenuDivider"), Y = w("FmMenuItem"), G = w("FmMenu"), pe = w("FmFormGroup"), st = w("FmSelect"), Re = w("FmSwitch"), Ae = w("FmStepperField"), it = w("FmForm");
633
+ return _(), A(it, {
634
+ disabled: t.disabled,
635
+ ref_key: "formRef",
636
+ ref: se,
637
+ class: "flex flex-col gap-32",
638
+ onValidationSuccess: r
639
+ }, {
640
+ default: V(() => {
641
+ var Te, De, Be, Pe;
642
+ return [
643
+ c("div", qt, [
644
+ c("div", Gt, [
645
+ v(fe, {
646
+ "tooltip-message": "This field is managed by NetSuite",
647
+ "tooltip-z-index": 50,
648
+ label: u(l)("inventory.ingredient.code"),
649
+ "model-value": x.value,
650
+ "onUpdate:modelValue": e[1] || (e[1] = (F) => x.value = F),
651
+ locked: i.value,
652
+ disabled: t.disabled
653
+ }, {
654
+ default: V(() => [
655
+ v(f, {
656
+ label: u(l)("inventory.ingredient.code"),
657
+ "model-value": x.value,
658
+ "onUpdate:modelValue": e[0] || (e[0] = (F) => x.value = F),
659
+ rules: [u(we)(), u(ft)(Ce.value, U.value)],
660
+ "label-mark": "required"
661
+ }, null, 8, ["label", "model-value", "rules"])
662
+ ]),
663
+ _: 1
664
+ }, 8, ["label", "model-value", "locked", "disabled"])
665
+ ]),
666
+ c("div", Wt, [
667
+ v(fe, {
668
+ "tooltip-message": "This field is managed by NetSuite",
669
+ "tooltip-z-index": 50,
670
+ label: u(l)("inventory.ingredient.name"),
671
+ "model-value": E.value,
672
+ "onUpdate:modelValue": e[3] || (e[3] = (F) => E.value = F),
673
+ locked: i.value,
674
+ disabled: t.disabled
675
+ }, {
676
+ default: V(() => [
677
+ v(f, {
678
+ label: u(l)("inventory.ingredient.name"),
679
+ "model-value": E.value,
680
+ "onUpdate:modelValue": e[2] || (e[2] = (F) => E.value = F),
681
+ rules: [u(we)()],
682
+ "label-mark": "required"
683
+ }, null, 8, ["label", "model-value", "rules"])
684
+ ]),
685
+ _: 1
686
+ }, 8, ["label", "model-value", "locked", "disabled"])
687
+ ])
688
+ ]),
689
+ v(fe, {
690
+ "tooltip-message": "This field is managed by NetSuite",
691
+ "tooltip-z-index": 50,
692
+ label: u(l)("inventory.ingredient.unit"),
693
+ "helper-text": (Te = t.modelValue) != null && Te.trackingMeasurement ? `Base unit: ${(Be = (De = t.modelValue) == null ? void 0 : De.unit) == null ? void 0 : Be.name}` : void 0,
694
+ "model-value": (Pe = k.value) == null ? void 0 : Pe.name,
695
+ locked: i.value,
696
+ disabled: t.disabled
697
+ }, {
698
+ default: V(() => [
699
+ v(pe, {
700
+ "model-value": k.value,
701
+ rules: [u(we)()],
702
+ "label-mark": "required"
703
+ }, {
704
+ label: V(() => [
705
+ v(h, {
706
+ label: u(l)("inventory.ingredient.unit")
707
+ }, null, 8, ["label"])
708
+ ]),
709
+ default: V(({ invalid: F }) => [
710
+ v(G, null, {
711
+ "menu-button": V(() => [
712
+ v(R, {
713
+ class: Q([
714
+ "fm-typo-en-body-lg-400",
715
+ {
716
+ "text-fm-color-typo-primary": !t.disabled,
717
+ "text-fm-color-typo-disabled": t.disabled
718
+ }
719
+ ]),
720
+ invalid: F,
721
+ "append-icon": "expand_more"
722
+ }, {
723
+ default: V(() => {
724
+ var q;
725
+ return [
726
+ Ee(T((q = k.value) == null ? void 0 : q.name), 1)
727
+ ];
728
+ }),
729
+ _: 2
730
+ }, 1032, ["class", "invalid"])
731
+ ]),
732
+ default: V(() => [
733
+ c("div", {
734
+ class: "overflow-x-hidden overflow-y-auto max-h-[300px]",
735
+ onVnodeMounted: C
736
+ }, [
737
+ (_(!0), D(ee, null, ye(I.value, (q) => (_(), D(ee, {
738
+ key: q.label
739
+ }, [
740
+ q.displayAsSection ? (_(), D(ee, { key: 0 }, [
741
+ v($, {
742
+ label: q.label
743
+ }, null, 8, ["label"]),
744
+ v(j)
745
+ ], 64)) : (_(), A(Y, {
746
+ key: 1,
747
+ label: q.label,
748
+ "model-value": M(q),
749
+ onClick: (Jn) => ne(q.value),
750
+ "x-should-scroll-into": `${M(q)}`
751
+ }, null, 8, ["label", "model-value", "onClick", "x-should-scroll-into"]))
752
+ ], 64))), 128))
753
+ ], 512)
754
+ ]),
755
+ _: 2
756
+ }, 1024)
757
+ ]),
758
+ _: 1
759
+ }, 8, ["model-value", "rules"])
760
+ ]),
761
+ _: 1
762
+ }, 8, ["label", "helper-text", "model-value", "locked", "disabled"]),
763
+ u(p).enableTotalCost ? (_(), A(fe, {
764
+ key: 0,
765
+ "tooltip-message": "This field is managed by NetSuite",
766
+ "tooltip-z-index": 50,
767
+ label: u(l)("inventory.ingredient.valuationMethod.title"),
768
+ "model-value": u(l)("inventory.ingredient.valuationMethod." + de.value),
769
+ locked: i.value,
770
+ disabled: t.disabled
771
+ }, {
772
+ label: V(() => [
773
+ v(xe, { "z-index": 50 }, {
774
+ default: V(() => [
775
+ v(h, {
776
+ label: u(l)("inventory.ingredient.valuationMethod.title")
777
+ }, null, 8, ["label"])
778
+ ]),
779
+ _: 1
780
+ })
781
+ ]),
782
+ default: V(() => [
783
+ v(st, {
784
+ class: "col-span-2",
785
+ label: u(l)("inventory.ingredient.valuationMethod.title"),
786
+ "model-value": de.value,
787
+ "onUpdate:modelValue": e[4] || (e[4] = (F) => de.value = F),
788
+ items: K.value
789
+ }, null, 8, ["label", "model-value", "items"])
790
+ ]),
791
+ _: 1
792
+ }, 8, ["label", "model-value", "locked", "disabled"])) : O("", !0),
793
+ u(p).enableTotalCost ? (_(), A(fe, {
794
+ key: 1,
795
+ "tooltip-message": "This field is managed by NetSuite",
796
+ "tooltip-z-index": 50,
797
+ "model-value": `${u(yt)()} ${N.value}`,
798
+ locked: i.value,
799
+ disabled: t.disabled
800
+ }, {
801
+ label: V(() => [
802
+ v(xe, { "z-index": 50 }, {
803
+ default: V(() => [
804
+ v(h, {
805
+ label: u(l)("inventory.ingredient.pricePerUnit")
806
+ }, null, 8, ["label"])
807
+ ]),
808
+ _: 1
809
+ })
810
+ ]),
811
+ default: V(() => [
812
+ v(f, {
813
+ "model-value": N.value,
814
+ "onUpdate:modelValue": e[5] || (e[5] = (F) => N.value = F),
815
+ rules: [u(ke)(0), u(gt)(4)]
816
+ }, {
817
+ label: V(() => [
818
+ v(xe, { "z-index": 50 }, {
819
+ default: V(() => [
820
+ v(h, {
821
+ label: u(l)("inventory.ingredient.pricePerUnit")
822
+ }, null, 8, ["label"])
823
+ ]),
824
+ _: 1
825
+ })
826
+ ]),
827
+ prepend: V(() => {
828
+ var F, q;
829
+ return [
830
+ c("div", Kt, T(u(Oe)(((F = u(m).currentCountry) == null ? void 0 : F.value) ?? u(He)) === "MYR" ? "RM" : u(Oe)(((q = u(m).currentCountry) == null ? void 0 : q.value) ?? u(He))), 1)
831
+ ];
832
+ }),
833
+ append: V(() => [
834
+ c("div", Jt, " / " + T(ce.value), 1)
835
+ ]),
836
+ _: 1
837
+ }, 8, ["model-value", "rules"])
838
+ ]),
839
+ _: 1
840
+ }, 8, ["model-value", "locked", "disabled"])) : O("", !0),
841
+ !i.value || W.value ? (_(), A(jt, {
842
+ key: 2,
843
+ "model-value": W.value,
844
+ "onUpdate:modelValue": e[6] || (e[6] = (F) => W.value = F),
845
+ "root-value": t.modelValue,
846
+ readonly: i.value
847
+ }, null, 8, ["model-value", "root-value", "readonly"])) : O("", !0),
848
+ t.mode !== u(H).CREATE ? (_(), D("div", Zt, [
849
+ v(Re, {
850
+ label: u(l)("inventory.ingredient.isInactive.title"),
851
+ "model-value": P.value,
852
+ "onUpdate:modelValue": e[7] || (e[7] = (F) => P.value = F),
853
+ "label-placement": "right",
854
+ disabled: i.value
855
+ }, null, 8, ["label", "model-value", "disabled"]),
856
+ c("div", Qt, [
857
+ c("div", Xt, T(u(l)("inventory.ingredient.isInactive.preventFromOrder")), 1)
858
+ ])
859
+ ])) : O("", !0),
860
+ t.mode !== u(H).CREATE ? (_(), D("div", en, [
861
+ c("div", null, [
862
+ v(Re, {
863
+ label: u(l)("inventory.ingredient.bindedItems.title"),
864
+ modelValue: oe.value,
865
+ "onUpdate:modelValue": e[8] || (e[8] = (F) => oe.value = F),
866
+ "label-placement": "right"
867
+ }, null, 8, ["label", "modelValue"])
868
+ ]),
869
+ oe.value && he.value.length ? (_(), A(Ie, {
870
+ key: 0,
871
+ name: u(l)("inventory.ingredient.bindedItems.ingredient"),
872
+ bindings: he.value
873
+ }, null, 8, ["name", "bindings"])) : O("", !0),
874
+ oe.value && ue.value.length ? (_(), A(Ie, {
875
+ key: 1,
876
+ name: u(l)("inventory.ingredient.bindedItems.recipe"),
877
+ bindings: ue.value
878
+ }, null, 8, ["name", "bindings"])) : O("", !0),
879
+ oe.value && me.value.length ? (_(), A(Ie, {
880
+ key: 2,
881
+ name: u(l)("inventory.ingredient.bindedItems.menu"),
882
+ bindings: me.value
883
+ }, null, 8, ["name", "bindings"])) : O("", !0)
884
+ ])) : O("", !0),
885
+ c("div", tn, [
886
+ c("div", nn, [
887
+ v(xe, null, {
888
+ default: V(() => [
889
+ c("div", on, T(u(l)("inventory.ingredient.threshold.title")), 1)
890
+ ]),
891
+ _: 1
892
+ }),
893
+ c("div", ln, T(u(l)("inventory.ingredient.threshold.subtitle")), 1)
894
+ ]),
895
+ c("div", an, [
896
+ v(pe, {
897
+ "model-value": { low: J.value, mid: Z.value },
898
+ rules: [z()]
899
+ }, null, 8, ["model-value", "rules"]),
900
+ c("div", rn, [
901
+ c("div", sn, [
902
+ c("div", dn, [
903
+ v(Fe, {
904
+ days: J.value,
905
+ level: u(Me).low
906
+ }, null, 8, ["days", "level"])
907
+ ]),
908
+ c("div", un, [
909
+ c("div", mn, T(u(l)("inventory.ingredient.threshold.whenRemaining")), 1),
910
+ v(Ae, {
911
+ modelValue: J.value,
912
+ "onUpdate:modelValue": e[9] || (e[9] = (F) => J.value = F),
913
+ rules: [u(ke)(0)]
914
+ }, {
915
+ append: V(() => e[12] || (e[12] = [
916
+ c("div", {
917
+ class: "text-fm-color-typo-secondary",
918
+ style: { "padding-right": "32px" }
919
+ }, "days", -1)
920
+ ])),
921
+ _: 1
922
+ }, 8, ["modelValue", "rules"])
923
+ ])
924
+ ]),
925
+ e[14] || (e[14] = c("div", {
926
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
927
+ style: { width: "1px" }
928
+ }, [
929
+ c("div", {
930
+ class: "absolute bg-white",
931
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "24px" }
932
+ }, " < ")
933
+ ], -1)),
934
+ c("div", cn, [
935
+ c("div", pn, [
936
+ v(Fe, {
937
+ days: Z.value,
938
+ level: u(Me).mid
939
+ }, null, 8, ["days", "level"])
940
+ ]),
941
+ c("div", vn, [
942
+ c("div", fn, T(u(l)("inventory.ingredient.threshold.whenRemaining")), 1),
943
+ v(Ae, {
944
+ modelValue: Z.value,
945
+ "onUpdate:modelValue": e[10] || (e[10] = (F) => Z.value = F),
946
+ rules: [u(ke)(0)]
947
+ }, {
948
+ append: V(() => e[13] || (e[13] = [
949
+ c("div", {
950
+ class: "text-fm-color-typo-secondary",
951
+ style: { "padding-right": "32px" }
952
+ }, "days", -1)
953
+ ])),
954
+ _: 1
955
+ }, 8, ["modelValue", "rules"])
956
+ ])
957
+ ]),
958
+ e[15] || (e[15] = c("div", {
959
+ class: "h-full bg-fm-color-neutral-gray-200 relative",
960
+ style: { width: "1px" }
961
+ }, [
962
+ c("div", {
963
+ class: "absolute bg-white",
964
+ style: { transform: "translate(-50%, -50%)", left: "50%", top: "24px" }
965
+ }, " < ")
966
+ ], -1)),
967
+ c("div", yn, [
968
+ c("div", gn, [
969
+ v(Fe, {
970
+ days: Z.value + 1,
971
+ level: u(Me).high
972
+ }, null, 8, ["days", "level"])
973
+ ]),
974
+ c("div", bn, [
975
+ c("div", hn, T(u(l)("inventory.ingredient.threshold.stockIsStaple")), 1)
976
+ ])
977
+ ])
978
+ ])
979
+ ])
980
+ ]),
981
+ c("div", null, [
982
+ v(zt, {
983
+ entity: "inventorySku",
984
+ modelValue: re.value,
985
+ "onUpdate:modelValue": e[11] || (e[11] = (F) => re.value = F)
986
+ }, null, 8, ["modelValue"])
987
+ ])
988
+ ];
989
+ }),
990
+ _: 1
991
+ }, 8, ["disabled"]);
992
+ };
993
+ }
994
+ }), xn = { class: "flex flex-col gap-32" }, kn = { class: "flex gap-4" }, Vn = /* @__PURE__ */ le({
995
+ __name: "IngredientDialog",
996
+ props: {
997
+ show: { type: Boolean },
998
+ unit: {},
999
+ mode: { default: H.READ }
1000
+ },
1001
+ emits: ["update:show"],
1002
+ setup(d) {
1003
+ const o = d, y = te(), l = Ue(), n = Se(), { t: a } = ae(), s = Ge(o, "show"), m = Ge(o, "unit"), p = S(
1004
+ () => {
1005
+ var k;
1006
+ return l.isEnabled && l.netSuiteItemBySkuId.has((k = o.unit) == null ? void 0 : k._id);
1007
+ }
1008
+ ), g = S(() => {
1009
+ switch (o.mode) {
1010
+ case H.READ:
1011
+ return "";
1012
+ case H.UPDATE:
1013
+ return a("inventory.ingredient.update.title");
1014
+ case H.CREATE:
1015
+ return a("inventory.ingredient.create.title");
1016
+ }
1017
+ return "";
1018
+ }), i = S(() => {
1019
+ switch (o.mode) {
1020
+ case H.READ:
1021
+ return "";
1022
+ case H.UPDATE:
1023
+ return a("common.save");
1024
+ case H.CREATE:
1025
+ return a("common.add");
1026
+ }
1027
+ return "";
1028
+ }), b = L(), r = L(!1);
1029
+ async function x() {
1030
+ r.value = !0;
1031
+ try {
1032
+ await y.createSku(m.value), s.value = !1, n.open({
1033
+ title: a("inventory.common.success"),
1034
+ message: a("inventory.ingredient.create.success", { name: m.value.name }),
1035
+ type: "success"
1036
+ });
1037
+ } catch (k) {
1038
+ k instanceof je || n.open({
1039
+ title: a("inventory.ingredient.create.error.title"),
1040
+ message: a("inventory.ingredient.create.error.message"),
1041
+ type: "error"
1042
+ });
1043
+ } finally {
1044
+ r.value = !1;
1045
+ }
1046
+ }
1047
+ async function P() {
1048
+ r.value = !0;
1049
+ try {
1050
+ await y.updateSku(m.value), r.value = !1, s.value = !1, n.open({
1051
+ title: a("inventory.common.success"),
1052
+ message: a("inventory.ingredient.update.success", { name: m.value.name }),
1053
+ type: "success"
1054
+ });
1055
+ } catch (k) {
1056
+ k instanceof je || n.open({
1057
+ title: a("inventory.ingredient.update.error.title"),
1058
+ message: a("inventory.ingredient.update.error.message"),
1059
+ type: "error"
1060
+ });
1061
+ } finally {
1062
+ r.value = !1;
1063
+ }
1064
+ }
1065
+ function E() {
1066
+ var k, I;
1067
+ (I = (k = b.value) == null ? void 0 : k.validateInputs) == null || I.call(k);
1068
+ }
1069
+ function N() {
1070
+ switch (o.mode) {
1071
+ case H.READ:
1072
+ return;
1073
+ case H.UPDATE:
1074
+ return P();
1075
+ case H.CREATE:
1076
+ return x();
1077
+ }
1078
+ }
1079
+ return (k, I) => {
1080
+ const M = w("FmChip"), ne = w("FmButton"), W = w("FmSideSheet");
1081
+ return _(), A(W, {
1082
+ "model-value": u(s),
1083
+ "onUpdate:modelValue": I[3] || (I[3] = (K) => Ne(s) ? s.value = K : null),
1084
+ header: g.value,
1085
+ "close-button": "",
1086
+ "dismiss-away": "",
1087
+ "max-width": 500
1088
+ }, {
1089
+ "side-sheet-footer": V(() => [
1090
+ c("div", kn, [
1091
+ v(ne, {
1092
+ loading: r.value,
1093
+ label: i.value,
1094
+ onClick: E
1095
+ }, null, 8, ["loading", "label"]),
1096
+ v(ne, {
1097
+ disabled: r.value,
1098
+ label: u(a)("common.close"),
1099
+ variant: "tertiary",
1100
+ onClick: I[2] || (I[2] = (K) => s.value = !1)
1101
+ }, null, 8, ["disabled", "label"])
1102
+ ])
1103
+ ]),
1104
+ default: V(() => [
1105
+ c("div", xn, [
1106
+ c("div", null, [
1107
+ p.value ? (_(), A(M, {
1108
+ key: 0,
1109
+ label: "Managed by Netsuite",
1110
+ compact: ""
1111
+ })) : O("", !0)
1112
+ ]),
1113
+ v(_n, {
1114
+ class: "w-full",
1115
+ ref_key: "hasValidationExpose",
1116
+ ref: b,
1117
+ modelValue: u(m),
1118
+ "onUpdate:modelValue": I[0] || (I[0] = (K) => Ne(m) ? m.value = K : null),
1119
+ mode: k.mode,
1120
+ disabled: r.value,
1121
+ "onClick:submit": I[1] || (I[1] = (K) => N())
1122
+ }, null, 8, ["modelValue", "mode", "disabled"])
1123
+ ])
1124
+ ]),
1125
+ _: 1
1126
+ }, 8, ["model-value", "header"]);
1127
+ };
1128
+ }
1129
+ });
1130
+ function Sn() {
1131
+ return `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Lt()}`;
1132
+ }
1133
+ const Cn = {
1134
+ _id: "",
1135
+ name: "",
1136
+ abbrev: "",
1137
+ precision: 0,
1138
+ measurements: []
1139
+ };
1140
+ function wn(d) {
1141
+ return !d || Object.keys(d).length === 0 ? "" : Object.entries(d).map(([o, y]) => `${o}: ${y}`).join(", ");
1142
+ }
1143
+ function at(d) {
1144
+ if (!d || d.trim() === "")
1145
+ return;
1146
+ const o = {}, y = d.split(",").map((l) => l.trim());
1147
+ for (const l of y) {
1148
+ const n = l.indexOf(":");
1149
+ if (n > 0) {
1150
+ const a = l.substring(0, n).trim(), s = l.substring(n + 1).trim();
1151
+ a && s && (o[a] = s);
1152
+ }
1153
+ }
1154
+ return Object.keys(o).length > 0 ? o : void 0;
1155
+ }
1156
+ function Fn(d) {
1157
+ var y, l, n, a, s;
1158
+ return {
1159
+ code: d.code,
1160
+ name: d.name,
1161
+ unit: ((y = d.unit.measurements.find((m) => m.id === d.trackingMeasurement)) == null ? void 0 : y.abbrev) ?? d.unit.abbrev,
1162
+ baseUnit: d.unit.abbrev,
1163
+ valuationMethod: d.valuation ?? "WAVG",
1164
+ pricePerUnit: (l = d.defaultCost) != null && l.costPerUnit ? +Xe((n = d.defaultCost) == null ? void 0 : n.costPerUnit) : 0,
1165
+ thresholdLow: ((a = d.thresholds) == null ? void 0 : a.low) ?? ie().low,
1166
+ thresholdMid: ((s = d.thresholds) == null ? void 0 : s.mid) ?? ie().mid,
1167
+ customAttributes: wn(d.customAttributes)
1168
+ };
1169
+ }
1170
+ function rt() {
1171
+ var n;
1172
+ const d = [
1173
+ {
1174
+ id: "code",
1175
+ name: "Code"
1176
+ },
1177
+ {
1178
+ id: "name",
1179
+ name: "Name"
1180
+ },
1181
+ {
1182
+ id: "unit",
1183
+ name: "Unit"
1184
+ },
1185
+ {
1186
+ id: "baseUnit",
1187
+ name: "Base unit"
1188
+ }
1189
+ ], o = tt(), y = be(), l = Ve(y.currentCountry.value);
1190
+ return o.enableTotalCost && d.push(
1191
+ {
1192
+ id: "valuationMethod",
1193
+ name: "Valuation method"
1194
+ },
1195
+ {
1196
+ id: "pricePerUnit",
1197
+ name: `Price per unit (${l == null ? void 0 : l.currency})`
1198
+ }
1199
+ ), ((n = y.currentBusiness.value) == null ? void 0 : n.menuVersion) === "v4" && d.push(
1200
+ {
1201
+ id: "thresholdLow",
1202
+ name: "Show RED when remaining"
1203
+ },
1204
+ {
1205
+ id: "thresholdMid",
1206
+ name: "Show YELLOW when remaining"
1207
+ }
1208
+ ), d.push({
1209
+ id: "customAttributes",
1210
+ name: "Custom Attributes"
1211
+ }), d;
1212
+ }
1213
+ function Mn() {
1214
+ const o = te().skus.map(Fn), l = be().currentBusiness.value, n = rt(), a = [
1215
+ ["Business name:", l == null ? void 0 : l.name],
1216
+ ["Business ID:", l == null ? void 0 : l._id],
1217
+ ["Menu version", l == null ? void 0 : l.menuVersion],
1218
+ [],
1219
+ n.map((g) => g.name),
1220
+ ...o.map((g) => n.map((i) => g[i.id]))
1221
+ ], s = n.map((g) => `system:${g.id}`), m = nt(a, s), p = `${l == null ? void 0 : l.name} ingredients (${bt(/* @__PURE__ */ new Date())}).xlsx`;
1222
+ return ot(m, p), p;
1223
+ }
1224
+ function In() {
1225
+ const o = be().currentBusiness.value, y = rt(), l = [
1226
+ ["Business name:", o == null ? void 0 : o.name],
1227
+ ["Business ID:", o == null ? void 0 : o._id],
1228
+ ["Menu version", o == null ? void 0 : o.menuVersion],
1229
+ [],
1230
+ y.map((m) => m.name)
1231
+ ], n = y.map((m) => `system:${m.id}`), a = nt(l, n), s = "FeedMe ingredients template.xlsx";
1232
+ return ot(a, s), s;
1233
+ }
1234
+ function $n(d) {
1235
+ const [
1236
+ o,
1237
+ y,
1238
+ l,
1239
+ n,
1240
+ a,
1241
+ s,
1242
+ ...m
1243
+ ] = _t(d);
1244
+ if (!o || !o.length || o.some((r) => r.length && !r.startsWith("system:")))
1245
+ throw new Error("Missing meta header. Excel file does not come from the template.");
1246
+ const p = o.map((r) => r.split(":")[1]), i = ["code", "name", "unit", "baseUnit"].filter((r) => !p.includes(r));
1247
+ if (i.length)
1248
+ throw new Error(
1249
+ `Missing meta headers (${i.join()}). Excel file does not come from the template.`
1250
+ );
1251
+ return m.map((r, x) => {
1252
+ const P = {};
1253
+ for (const E in p) {
1254
+ const N = p[E];
1255
+ Object.assign(P, { [N]: r[E] });
1256
+ }
1257
+ return {
1258
+ index: x,
1259
+ data: P
1260
+ };
1261
+ });
1262
+ }
1263
+ function We(d, o, y) {
1264
+ var I;
1265
+ const n = te().units, a = new Array(), s = y.filter((M) => M.data.code === d.code);
1266
+ s.length > 1 && a.push(
1267
+ `Code ${d.code} is already used in row ${s.map((M) => M.index + 6).join()}.`
1268
+ );
1269
+ const m = n.find((M) => M.abbrev === d.baseUnit), p = m == null ? void 0 : m.measurements.find((M) => M.abbrev === d.unit);
1270
+ if (!m)
1271
+ a.push(`Cannot find base unit of symbol ${d.baseUnit}.`);
1272
+ else if (d.baseUnit !== d.unit && !p) {
1273
+ const M = `Cannot find unit conversion for ${d.baseUnit} with symbol ${d.unit || "[empty]"}.`;
1274
+ a.push(M);
1275
+ }
1276
+ const g = ge.options.find(
1277
+ (M) => M === d.valuationMethod
1278
+ );
1279
+ d.valuationMethod && !g && a.push(
1280
+ `Expected valuation method to be one of ${ge.options.join()} but got ${d.valuationMethod} instead.`
1281
+ );
1282
+ const b = be().currentCountry.value, r = (M) => `${M}`.length && xt()(M) === !0, x = r(`${d.pricePerUnit}`) === !0 ? {
1283
+ costPerUnit: {
1284
+ ...et(Number(d.pricePerUnit) || 0),
1285
+ currency: ((I = Ve(b)) == null ? void 0 : I.currency) ?? "MYR"
1286
+ },
1287
+ measurement: p
1288
+ } : void 0, P = r(`${d.thresholdLow}`) && r(`${d.thresholdMid}`) ? {
1289
+ low: Number(d.thresholdLow) || 0,
1290
+ mid: Number(d.thresholdMid) || 0
1291
+ } : void 0, E = "customAttributes" in d ? at(d.customAttributes) : null;
1292
+ return {
1293
+ type: "create",
1294
+ sku: {
1295
+ _id: Sn(),
1296
+ code: d.code,
1297
+ name: d.name,
1298
+ unit: m ?? n.find((M) => M) ?? Cn,
1299
+ trackingMeasurement: p == null ? void 0 : p.id,
1300
+ valuation: g,
1301
+ defaultCost: x,
1302
+ thresholds: P,
1303
+ ...E !== null && { customAttributes: E }
1304
+ },
1305
+ errors: a,
1306
+ excelRowNumber: o + 6
1307
+ };
1308
+ }
1309
+ function En(d) {
1310
+ try {
1311
+ const o = $n(d).filter((g) => g.data.code), l = te().skus, n = ht(l, "code"), a = o.filter((g) => !n[g.data.code]), s = o.filter((g) => n[g.data.code]), m = a.map(
1312
+ (g) => We(g.data, g.index, o)
1313
+ ), p = s.map((g) => {
1314
+ const i = We(g.data, g.index, o), b = n[g.data.code];
1315
+ let r = b.customAttributes;
1316
+ return "customAttributes" in g.data && (r = at(g.data.customAttributes)), {
1317
+ ...i,
1318
+ type: "update",
1319
+ original: b,
1320
+ sku: {
1321
+ // to maintain original props not in the import excel, e.g. inventory binding, etc...
1322
+ ...b,
1323
+ code: i.sku.code || b.code,
1324
+ name: i.sku.name || b.name,
1325
+ unit: i.sku.unit || b.unit,
1326
+ trackingMeasurement: i.sku.trackingMeasurement || b.trackingMeasurement,
1327
+ valuation: i.sku.valuation || b.valuation,
1328
+ defaultCost: i.sku.defaultCost || b.defaultCost,
1329
+ thresholds: i.sku.thresholds || b.thresholds,
1330
+ customAttributes: r
1331
+ }
1332
+ };
1333
+ });
1334
+ return {
1335
+ invalidExcel: !1,
1336
+ importCreateResult: m,
1337
+ importUpdateResult: p
1338
+ };
1339
+ } catch (o) {
1340
+ return {
1341
+ invalidExcel: !0,
1342
+ invalidExcelMessage: (o == null ? void 0 : o.message) ?? "Invalid excel",
1343
+ importCreateResult: [],
1344
+ importUpdateResult: []
1345
+ };
1346
+ }
1347
+ }
1348
+ const Un = { class: "flex items-center gap-12 pl-8" }, Rn = { class: "flex flex-col" }, An = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, Tn = {
1349
+ key: 0,
1350
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
1351
+ }, Dn = { key: 0 }, Ke = /* @__PURE__ */ le({
1352
+ __name: "ImportIngredientItem",
1353
+ props: {
1354
+ type: {},
1355
+ code: {},
1356
+ name: {},
1357
+ errors: {}
1358
+ },
1359
+ setup(d) {
1360
+ return (o, y) => {
1361
+ const l = w("FmIcon"), n = w("FmTooltip");
1362
+ return _(), D("div", Un, [
1363
+ y[0] || (y[0] = c("div", null, "•", -1)),
1364
+ c("div", Rn, [
1365
+ c("div", An, [
1366
+ c("div", {
1367
+ class: Q({
1368
+ "text-fm-color-system-error-300": o.errors.length
1369
+ })
1370
+ }, [
1371
+ Ee(T(o.name) + " ", 1),
1372
+ o.type === "create" ? (_(), D("span", Tn, "(new)")) : O("", !0)
1373
+ ], 2),
1374
+ o.errors.length ? (_(), D("div", Dn, [
1375
+ v(n, { "z-index": 50 }, {
1376
+ content: V(() => [
1377
+ c("ol", null, [
1378
+ (_(!0), D(ee, null, ye(o.errors, (a, s) => (_(), D("li", { key: s }, T(a), 1))), 128))
1379
+ ])
1380
+ ]),
1381
+ default: V(() => [
1382
+ v(l, {
1383
+ name: "error",
1384
+ size: "sm",
1385
+ color: "system-error-300"
1386
+ })
1387
+ ]),
1388
+ _: 1
1389
+ })
1390
+ ])) : O("", !0)
1391
+ ]),
1392
+ c("div", {
1393
+ class: Q([
1394
+ "fm-typo-en-body-sm-400",
1395
+ {
1396
+ "text-fm-color-system-error-200": o.errors.length,
1397
+ "text-fm-color-typo-secondary": !o.errors.length
1398
+ }
1399
+ ])
1400
+ }, T(o.code), 3)
1401
+ ])
1402
+ ]);
1403
+ };
1404
+ }
1405
+ }), Bn = { class: "flex flex-col gap-24" }, Pn = { class: "fm-typo-en-body-md-400" }, Nn = { class: "flex flex-col gap-8" }, zn = { class: "line-clamp-2 text-ellipsis break-all" }, Ln = {
1406
+ key: 2,
1407
+ class: "shrink-0"
1408
+ }, On = {
1409
+ key: 0,
1410
+ class: "flex flex-col"
1411
+ }, Hn = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, jn = {
1412
+ key: 0,
1413
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
1414
+ }, Yn = { class: "fm-typo-en-body-lg-600" }, qn = /* @__PURE__ */ le({
1415
+ __name: "ImportIngredients",
1416
+ setup(d) {
1417
+ const o = L(null), y = Ut(), l = Se(), n = L(!1), a = L(new Array()), s = L([]), m = L([]), p = S(
1418
+ () => !!a.value.length || s.value.some((r) => r.errors.length) || m.value.some((r) => r.errors.length)
1419
+ ), g = S(
1420
+ () => !!s.value.length || !!m.value.length
1421
+ ), { t: i } = ae();
1422
+ async function b(r) {
1423
+ a.value = [], s.value = [], m.value = [];
1424
+ try {
1425
+ n.value = !0;
1426
+ const [x] = await Promise.all([
1427
+ Vt(r),
1428
+ // fake buffer
1429
+ new Promise((N) => setTimeout(N, 1e3))
1430
+ ]), P = x.SheetNames.find((N) => N);
1431
+ if (!P) {
1432
+ a.value.push(i("inventory.ingredient.import.fileError.noSheet"));
1433
+ return;
1434
+ }
1435
+ const E = En(x.Sheets[P]);
1436
+ if (E.invalidExcel) {
1437
+ a.value.push(E.invalidExcelMessage ?? i("inventory.ingredient.import.fileError.invalidExcel"));
1438
+ return;
1439
+ }
1440
+ if (s.value = E.importCreateResult, m.value = E.importUpdateResult, !s.value.length && !m.value.length) {
1441
+ a.value.push(i("inventory.ingredient.import.fileError.noData"));
1442
+ return;
1443
+ }
1444
+ y.emitData(E);
1445
+ } catch (x) {
1446
+ l.open({
1447
+ title: i("inventory.ingredient.import.fileError.unableToRead"),
1448
+ message: x == null ? void 0 : x.message,
1449
+ type: "error"
1450
+ }), console.error("Error in reading file", x);
1451
+ } finally {
1452
+ a.value.length && l.open({
1453
+ title: i("inventory.ingredient.import.fileError.invalidExcel"),
1454
+ type: "error"
1455
+ }), n.value = !1;
1456
+ }
1457
+ }
1458
+ return Je(o, (r) => {
1459
+ r && b(r);
1460
+ }), (r, x) => {
1461
+ const P = w("FmCircularProgress"), E = w("FmIcon"), N = w("FmButton");
1462
+ return _(), D("div", Bn, [
1463
+ c("div", Pn, T(u(i)("inventory.ingredient.import.uploadDescription")), 1),
1464
+ v(kt, {
1465
+ class: Q({
1466
+ "w-full": !0,
1467
+ "h-[200px]": !o.value
1468
+ }),
1469
+ accept: ".xlsx",
1470
+ onFileUpload: x[0] || (x[0] = (k) => o.value = k),
1471
+ label: u(i)("inventory.ingredient.import.uploadTemplate"),
1472
+ "button-label": u(i)("inventory.ingredient.import.selectFile")
1473
+ }, Ze({ _: 2 }, [
1474
+ o.value ? {
1475
+ name: "default",
1476
+ fn: V(({ openFileDialog: k }) => [
1477
+ c("div", Nn, [
1478
+ c("div", {
1479
+ class: Q([
1480
+ "fm-corner-radius-md p-16 flex items-center gap-16",
1481
+ {
1482
+ "border border-fm-color-neutral-gray-100": n.value,
1483
+ "border border-fm-color-neutral-gray-200": !n.value && !p.value,
1484
+ "border border-fm-color-system-error-200": p.value
1485
+ }
1486
+ ])
1487
+ }, [
1488
+ n.value ? (_(), A(P, {
1489
+ key: 0,
1490
+ size: "md",
1491
+ color: "neutral-gray-200"
1492
+ })) : (_(), A(E, {
1493
+ key: 1,
1494
+ name: p.value ? "error" : "attach_file",
1495
+ outline: "",
1496
+ color: p.value ? "system-error-300" : void 0
1497
+ }, null, 8, ["name", "color"])),
1498
+ c("div", {
1499
+ class: Q([
1500
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
1501
+ {
1502
+ "text-fm-color-typo-disabled": n.value,
1503
+ "text-fm-color-typo-primary": !n.value
1504
+ }
1505
+ ])
1506
+ }, [
1507
+ c("div", zn, T(o.value.name), 1)
1508
+ ], 2),
1509
+ n.value ? O("", !0) : (_(), D("div", Ln, [
1510
+ v(N, {
1511
+ label: u(i)("inventory.ingredient.import.replaceFile"),
1512
+ variant: p.value ? "destructive" : "secondary",
1513
+ "prepend-icon": p.value ? void 0 : "autorenew",
1514
+ onClick: k
1515
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
1516
+ ]))
1517
+ ], 2),
1518
+ a.value.length ? (_(), D("div", On, [
1519
+ (_(!0), D(ee, null, ye(a.value, (I, M) => (_(), D("div", {
1520
+ key: M,
1521
+ class: "flex gap-8 items-center"
1522
+ }, [
1523
+ v(E, {
1524
+ name: "error",
1525
+ size: "sm",
1526
+ color: "system-error-300"
1527
+ }),
1528
+ c("div", Hn, T(I), 1)
1529
+ ]))), 128))
1530
+ ])) : O("", !0)
1531
+ ])
1532
+ ]),
1533
+ key: "0"
1534
+ } : void 0
1535
+ ]), 1032, ["class", "label", "button-label"]),
1536
+ g.value ? (_(), D("div", jn, [
1537
+ c("div", Yn, T(u(i)("inventory.ingredient.import.summary")), 1),
1538
+ (_(!0), D(ee, null, ye(s.value, (k) => (_(), A(Ke, {
1539
+ key: k.sku._id,
1540
+ code: k.sku.code,
1541
+ name: k.sku.name,
1542
+ errors: k.errors,
1543
+ type: "create"
1544
+ }, null, 8, ["code", "name", "errors"]))), 128)),
1545
+ (_(!0), D(ee, null, ye(m.value, (k) => (_(), A(Ke, {
1546
+ key: k.sku._id,
1547
+ code: k.sku.code,
1548
+ name: k.sku.name,
1549
+ errors: k.errors,
1550
+ type: "update"
1551
+ }, null, 8, ["code", "name", "errors"]))), 128))
1552
+ ])) : O("", !0)
1553
+ ]);
1554
+ };
1555
+ }
1556
+ }), Gn = { class: "flex flex-col py-8" }, Wn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Kn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, co = /* @__PURE__ */ le({
1557
+ __name: "IngredientsView",
1558
+ setup(d) {
1559
+ const o = te(), y = S(() => [
1560
+ {
1561
+ type: "string",
1562
+ key: "skuCode",
1563
+ entity: "sku",
1564
+ values: o.skus.map((C) => C.code)
1565
+ },
1566
+ {
1567
+ type: "string",
1568
+ key: "skuUnitAbbrev",
1569
+ entity: "sku",
1570
+ values: o.units.map((C) => C.abbrev)
1571
+ }
1572
+ ]), l = L(null), n = S(() => {
1573
+ if (!l.value)
1574
+ return o.skus;
1575
+ const U = St.build(l.value);
1576
+ return o.skus.filter((C) => Ct(
1577
+ {
1578
+ skuCode: C.code,
1579
+ skuUnitAbbrev: C.unit.abbrev
1580
+ },
1581
+ U
1582
+ ));
1583
+ }), a = wt(), s = lt(), m = Ot(), p = Se(), g = Ue(), { t: i } = ae(), { createIngredient: b, updateIngredient: r } = $e(), { ingredientDialogProps: x, ingredientViewLoading: P } = Bt($e()), { columnDefs: E } = Ht();
1584
+ function N(U) {
1585
+ switch (U) {
1586
+ case "add":
1587
+ return g.isEnabled ? void 0 : b();
1588
+ case "import":
1589
+ return me();
1590
+ case "export":
1591
+ return ue();
1592
+ }
1593
+ }
1594
+ const k = L(""), I = L(!1), M = S(() => I.value || P.value), { breakpoints: ne } = Rt(), W = S(() => ne.value.xs || ne.value.sm), K = S(() => W.value ? 10 : 20), de = Ft(), re = L(!1), se = [
1595
+ {
1596
+ value: "import",
1597
+ label: i("common.import")
1598
+ },
1599
+ {
1600
+ value: "export",
1601
+ label: i("common.export")
1602
+ }
1603
+ ];
1604
+ function oe(U) {
1605
+ switch (re.value = !1, U) {
1606
+ case "import":
1607
+ return me();
1608
+ case "export":
1609
+ return ue();
1610
+ }
1611
+ }
1612
+ const he = S(() => [
1613
+ ...g.isEnabled ? [] : [
1614
+ {
1615
+ label: i("inventory.ingredient.create.title"),
1616
+ value: "add",
1617
+ isPrimary: !0,
1618
+ prependIcon: "add"
1619
+ }
1620
+ ],
1621
+ { label: i("common.import"), value: "import" },
1622
+ { label: i("common.export"), value: "export" }
1623
+ ]);
1624
+ function ue() {
1625
+ const U = Mn();
1626
+ p.open({
1627
+ title: i("inventory.ingredient.export.success"),
1628
+ message: i("inventory.ingredient.export.filename", [U]),
1629
+ type: "success"
1630
+ });
1631
+ }
1632
+ function me() {
1633
+ s.open({
1634
+ title: i("inventory.ingredient.import.title"),
1635
+ contentComponent: qn,
1636
+ overlay: !0,
1637
+ closeButton: !0,
1638
+ primaryActions: {
1639
+ text: i("common.import"),
1640
+ close: !1
1641
+ },
1642
+ secondaryActions: {
1643
+ text: i("common.close"),
1644
+ close: !0
1645
+ },
1646
+ tertiaryActions: {
1647
+ text: i("inventory.ingredient.import.actions.downloadTemplate"),
1648
+ close: !1,
1649
+ variant: "plain"
1650
+ }
1651
+ }).onPrimary((U) => {
1652
+ if (!U) {
1653
+ p.open({
1654
+ title: i("inventory.ingredient.import.error.noData"),
1655
+ type: "error"
1656
+ });
1657
+ return;
1658
+ }
1659
+ if (!U.importCreateResult.length && !U.importUpdateResult.length) {
1660
+ p.open({
1661
+ title: i("inventory.ingredient.import.error.invalidContent"),
1662
+ message: i("inventory.ingredient.import.error.noImportData"),
1663
+ type: "error"
1664
+ });
1665
+ return;
1666
+ }
1667
+ if (U.importCreateResult.some((C) => C.errors.length) || U.importUpdateResult.some((C) => C.errors.length)) {
1668
+ p.open({
1669
+ title: i("inventory.ingredient.import.error.invalidContent"),
1670
+ message: i("inventory.ingredient.import.error.hasErrors"),
1671
+ type: "error"
1672
+ });
1673
+ return;
1674
+ }
1675
+ s.close(), Ce(U);
1676
+ }).onTertiary(In);
1677
+ }
1678
+ async function Ce(U) {
1679
+ I.value = !0;
1680
+ try {
1681
+ const C = [
1682
+ ...U.importCreateResult.map(({ sku: B }) => ({ type: "create", sku: B })),
1683
+ ...U.importUpdateResult.map(({ sku: B }) => ({ type: "update", sku: B }))
1684
+ ], ce = 100;
1685
+ let J = 0;
1686
+ const Z = () => {
1687
+ J += ce, p.open({
1688
+ title: i("inventory.ingredient.import.progress", [
1689
+ Math.min(J, C.length),
1690
+ C.length
1691
+ ])
1692
+ });
1693
+ }, z = new Array();
1694
+ for (const B of C.chunk(100)) {
1695
+ Z();
1696
+ try {
1697
+ const t = await o.importSkus({
1698
+ create: B.filter((e) => e.type === "create").map((e) => e.sku),
1699
+ update: B.filter((e) => e.type === "update").map((e) => e.sku)
1700
+ });
1701
+ z.push(...t.errors);
1702
+ } catch (t) {
1703
+ z.push(
1704
+ ...B.map((e) => {
1705
+ const f = {
1706
+ module: Et.enum.sku,
1707
+ _id: e.sku._id,
1708
+ name: e.sku.name,
1709
+ message: (t == null ? void 0 : t.stack) ?? t
1710
+ };
1711
+ return {
1712
+ data: e.sku,
1713
+ error: [f]
1714
+ };
1715
+ })
1716
+ );
1717
+ }
1718
+ }
1719
+ p.open({
1720
+ title: i("inventory.ingredient.import.success"),
1721
+ type: "success"
1722
+ }), z.length && m.alert(
1723
+ "Some operation failed",
1724
+ X(
1725
+ "div",
1726
+ { class: "flex flex-col gap-8" },
1727
+ z.map(
1728
+ (B) => X("div", { class: "flex flex-col" }, [
1729
+ X("div", { class: "fm-typo-en-body-lg-600" }, `(${B.data.code}) ${B.data.name}`),
1730
+ X(
1731
+ "div",
1732
+ { class: "fm-typo-en-body-lg-400" },
1733
+ `${B.error.map((t) => (t == null ? void 0 : t.message) ?? "Unknown error").join(", ")}`
1734
+ )
1735
+ ])
1736
+ )
1737
+ )
1738
+ );
1739
+ } catch (C) {
1740
+ p.open({
1741
+ title: i("inventory.ingredient.import.error.failed"),
1742
+ message: i("inventory.ingredient.import.error.systemMessage", [C == null ? void 0 : C.message]),
1743
+ type: "error"
1744
+ }), console.error("Error in importing skus", U, C);
1745
+ } finally {
1746
+ I.value = !1;
1747
+ }
1748
+ }
1749
+ return (U, C) => {
1750
+ const ce = w("FmTable"), J = w("FmCollapsibleTabs"), Z = w("FmBottomSheet");
1751
+ return _(), A(Mt, {
1752
+ title: u(i)("inventory.ingredient.title"),
1753
+ actions: he.value,
1754
+ "onClick:action": N
1755
+ }, {
1756
+ default: V(() => [
1757
+ c("div", {
1758
+ class: Q([
1759
+ "flex flex-col gap-8 max-h-full",
1760
+ {
1761
+ "p-0": W.value,
1762
+ "px-24 ": !W.value
1763
+ }
1764
+ ])
1765
+ }, [
1766
+ v(It, {
1767
+ searchable: "",
1768
+ search: k.value,
1769
+ "onUpdate:search": C[0] || (C[0] = (z) => k.value = z),
1770
+ filterable: "",
1771
+ "filter-attributes": y.value,
1772
+ filter: l.value,
1773
+ "onUpdate:filter": C[1] || (C[1] = (z) => l.value = z)
1774
+ }, null, 8, ["search", "filter-attributes", "filter"]),
1775
+ (_(), A(ce, {
1776
+ key: JSON.stringify(l.value),
1777
+ style: ut(u(de).tableHeight),
1778
+ "column-defs": u(E),
1779
+ "row-data": n.value,
1780
+ "search-value": k.value,
1781
+ loading: !u(a)._currentLocation || M.value,
1782
+ "loading-text": "Loading",
1783
+ onRowClick: C[2] || (C[2] = (z) => u(r)(z.original)),
1784
+ "page-size": K.value
1785
+ }, {
1786
+ "list-row": V((z) => [
1787
+ v($t, {
1788
+ row: z,
1789
+ onRowClick: u(r)
1790
+ }, Ze({
1791
+ default: V((B) => {
1792
+ var t, e, f, h, R, $, j, Y, G, pe;
1793
+ return [
1794
+ c("div", Gn, [
1795
+ c("div", Wn, [
1796
+ v(u(Ye), {
1797
+ render: (f = (e = (t = B.code) == null ? void 0 : t.column) == null ? void 0 : e.columnDef) == null ? void 0 : f.cell,
1798
+ props: (R = (h = B.code) == null ? void 0 : h.getContext) == null ? void 0 : R.call(h)
1799
+ }, null, 8, ["render", "props"])
1800
+ ]),
1801
+ c("div", Kn, [
1802
+ v(u(Ye), {
1803
+ render: (Y = (j = ($ = B.name) == null ? void 0 : $.column) == null ? void 0 : j.columnDef) == null ? void 0 : Y.cell,
1804
+ props: (pe = (G = B.name) == null ? void 0 : G.getContext) == null ? void 0 : pe.call(G)
1805
+ }, null, 8, ["render", "props"])
1806
+ ])
1807
+ ])
1808
+ ];
1809
+ }),
1810
+ _: 2
1811
+ }, [
1812
+ I.value ? {
1813
+ name: "loading-text",
1814
+ fn: V(() => [
1815
+ c("div", null, T(u(i)("inventory.ingredient.table.importing")), 1)
1816
+ ]),
1817
+ key: "0"
1818
+ } : void 0
1819
+ ]), 1032, ["row", "onRowClick"])
1820
+ ]),
1821
+ _: 1
1822
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
1823
+ ], 2),
1824
+ (_(), A(ze, { to: "body" }, [
1825
+ v(Vn, mt(ct(u(x))), null, 16)
1826
+ ])),
1827
+ (_(), A(ze, { to: "body" }, [
1828
+ v(Z, {
1829
+ "dismiss-away": "",
1830
+ modelValue: re.value,
1831
+ "onUpdate:modelValue": C[4] || (C[4] = (z) => re.value = z)
1832
+ }, {
1833
+ default: V(() => [
1834
+ v(J, {
1835
+ class: "pb-8",
1836
+ items: se,
1837
+ "onUpdate:modelValue": C[3] || (C[3] = (z) => oe(z))
1838
+ })
1839
+ ]),
1840
+ _: 1
1841
+ }, 8, ["modelValue"])
1842
+ ]))
1843
+ ]),
1844
+ _: 1
1845
+ }, 8, ["title", "actions"]);
1846
+ };
1847
+ }
1848
+ });
1849
+ export {
1850
+ co as default
1851
+ };