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

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 (53) hide show
  1. package/dist/{App-DAWBJNxz.js → App-D5hXQpVn.js} +1 -1
  2. package/dist/{ApprovalView-B2WUwSN4.js → ApprovalView-B__WDklZ.js} +2 -2
  3. package/dist/{BindingsDialog-C3OOcB8g.js → BindingsDialog-DXdwRSnn.js} +2 -2
  4. package/dist/{BindingsPicker-R3Zz0fWB.js → BindingsPicker-CqAD3aHc.js} +1 -1
  5. package/dist/{BindingsTable-B46C8p7M.js → BindingsTable-DVNjpusl.js} +1 -1
  6. package/dist/{ClosingDraftView-a_QhmaM4.js → ClosingDraftView-DL678GBB.js} +2 -2
  7. package/dist/{ClosingTemplateView-CEVmIsVw.js → ClosingTemplateView-DThiXLtp.js} +3 -3
  8. package/dist/{DeliveryOrderPrintPreview-BeQFF6sn.js → DeliveryOrderPrintPreview-B2MB9S6a.js} +1 -1
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DIG9NwPj.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BNxs6Bcr.js} +3 -3
  10. package/dist/{FmMultiselectDialog-BunyF2O-.js → FmMultiselectDialog-B45ZLjVp.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-Bx0dzfHO.js → FmUnitInput.vue_vue_type_script_setup_true_lang-D8ks6AEM.js} +1 -1
  12. package/dist/ImportView-EXm_g_jD.js +1303 -0
  13. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-CfwprwJN.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-C5zIvG2h.js} +1 -1
  14. package/dist/{IngredientGroupView-CIPTj0hf.js → IngredientGroupView-D95dFXIZ.js} +2 -2
  15. package/dist/{IngredientsView-BwBaeLtw.js → IngredientsView-MF1USuZI.js} +8 -8
  16. package/dist/{IntegrationView-CvRD-5O6.js → IntegrationView-9m3N_9lW.js} +3 -3
  17. package/dist/{InventoryBindingForm-DLQTH1di.js → InventoryBindingForm-kLoQskao.js} +1 -1
  18. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-XvIklIYw.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-BytErBcK.js} +3 -3
  19. package/dist/{InventoryBindingSummary-BGFSPQIw.js → InventoryBindingSummary-Dg0FH7ad.js} +1 -1
  20. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B3J0i5IU.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BKrUNLuG.js} +1 -1
  21. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-CyMRTB5L.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BL1f817e.js} +1 -1
  22. package/dist/{PublishView-7g0bx6KO.js → PublishView-BcOHSAj3.js} +1 -1
  23. package/dist/{PurchaseOrderPrintPreview-LEfLcjkd.js → PurchaseOrderPrintPreview-UfF8RVkv.js} +1 -1
  24. package/dist/{ReceiveRequestView-DUNfHRGf.js → ReceiveRequestView-D_y_xNUb.js} +8 -8
  25. package/dist/{RecipeView-XzqGQg_a.js → RecipeView-DOaU9GIF.js} +3 -3
  26. package/dist/{StockView-vZr9etBj.js → StockView-ciU6aAV7.js} +7 -7
  27. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-3_csD6uU.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-XwDTGpR-.js} +1 -1
  28. package/dist/{SupplierView-CUORFWJW.js → SupplierView-DFwtALPg.js} +4 -4
  29. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CdA5_lEz.js +3221 -0
  30. package/dist/{TransferTemplateView-DeliKkYY.js → TransferTemplateView-BXr_GqTi.js} +7 -7
  31. package/dist/{UnitView-B4NCl6jJ.js → UnitView-CAXHvh3n.js} +3 -3
  32. package/dist/{WarehouseView-jLGGlnwV.js → WarehouseView-BYd0bPhi.js} +1 -1
  33. package/dist/api/purchase-order.d.ts +1 -0
  34. package/dist/{app-DJcCTZjT.js → app-Bb0-8bRg.js} +7962 -7669
  35. package/dist/app.d.ts +252 -0
  36. package/dist/app.js +1 -1
  37. package/dist/{closing-template-hM43IpP-.js → closing-template-DPVNEyI7.js} +1 -1
  38. package/dist/{decimal-BVu2HlCS.js → decimal-BdBZYISm.js} +1 -1
  39. package/dist/{format-unit-display-C-M_AirC.js → format-unit-display-DlmCwWo_.js} +3 -3
  40. package/dist/{import-export.helper-C05Vl6i-.js → import-export.helper-B04wszRI.js} +1 -1
  41. package/dist/{index-v6hU4gAy.js → index-CKFmV1Pk.js} +1 -1
  42. package/dist/{index-CNQtmSfJ.js → index-CqBKFj1B.js} +1 -1
  43. package/dist/{purchase-order-template-BBCEFnbo.js → purchase-order-template-CLtEYr5E.js} +1 -1
  44. package/dist/{stock-CK3LBQmj.js → stock-nHQhfe2W.js} +1 -1
  45. package/dist/stores/feature.d.ts +2 -0
  46. package/dist/{supplier-CoCAyG12.js → supplier-DuOjLpOa.js} +1 -1
  47. package/dist/tsconfig.app.tsbuildinfo +1 -1
  48. package/dist/{use-ingredient-select-dialog-DYfpyC4u.js → use-ingredient-select-dialog-B-11Eqlm.js} +1 -1
  49. package/dist/{use-inventory-binding-dialog-CDwm6TPx.js → use-inventory-binding-dialog-DhLSdRtp.js} +1 -1
  50. package/dist/views/receive-request/components/delivery-order-form/SystemTrailDialog.vue.d.ts +17 -0
  51. package/package.json +3 -3
  52. package/dist/ImportView-CwBeBbXz.js +0 -1220
  53. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-DhXoNkss.js +0 -3057
@@ -0,0 +1,1303 @@
1
+ import { defineComponent as Ae, ref as D, computed as X, watch as ze, resolveComponent as ee, openBlock as N, createElementBlock as P, createVNode as B, normalizeClass as ve, unref as i, createSlots as Ke, withCtx as Z, createElementVNode as n, createBlock as ae, toDisplayString as a, createCommentVNode as te, Fragment as Be, renderList as Pe, shallowRef as $e, h as we, createTextVNode as E } from "vue";
2
+ import { a as le, aq as je, b5 as Me, ao as Ve, V as We, an as Se, l as Le, z as Je, B as qe, C as Xe, E as Ee, c as Qe } from "./app-Bb0-8bRg.js";
3
+ import { useCoreStore as ke, useI18n as Oe } from "@feedmepos/mf-common";
4
+ import { useDialogChild as Ye, useSnackbar as He, useDialog as Ze, useBreakpoints as et } from "@feedmepos/ui-library";
5
+ import { s as tt, g as nt, b as ot, d as Fe } from "./import-export.helper-B04wszRI.js";
6
+ import { r as Re } from "./random-CSbEbElR.js";
7
+ function rt() {
8
+ return `unit_${(/* @__PURE__ */ new Date()).toISOString()}_${Re()}`;
9
+ }
10
+ function De() {
11
+ return `measurement_${(/* @__PURE__ */ new Date()).toISOString()}_${Re()}`;
12
+ }
13
+ function st(R) {
14
+ const [
15
+ e,
16
+ S,
17
+ h,
18
+ x,
19
+ w,
20
+ _,
21
+ ...o
22
+ ] = je(R);
23
+ if (!e || !e.length || e.some((d) => d.length && !d.startsWith("system:")))
24
+ throw new Error("Missing meta header. Excel file does not come from the template.");
25
+ const l = e.map((d) => d.split(":")[1]), y = ["name", "symbol", "precision"].filter((d) => !l.includes(d));
26
+ if (y.length)
27
+ throw new Error(
28
+ `Missing meta headers (${y.join()}). Excel file does not come from the template.`
29
+ );
30
+ return o.map((d, f) => {
31
+ const g = {};
32
+ for (const p in l) {
33
+ const u = l[p];
34
+ Object.assign(g, { [u]: d[p] });
35
+ }
36
+ return {
37
+ index: f,
38
+ data: g
39
+ };
40
+ });
41
+ }
42
+ function it(R) {
43
+ try {
44
+ const e = st(R).filter((o) => {
45
+ const { name: l, symbol: s, precision: y, measurement_name: c, measurement_symbol: d, measurement_conversion: f } = o.data;
46
+ return l || s || y || c || d || f;
47
+ }), h = le().units, x = [], w = [];
48
+ let _ = {};
49
+ for (const o of e)
50
+ if (o.data.name && o.data.symbol)
51
+ _[o.data.name] = {
52
+ unit: {
53
+ _id: rt(),
54
+ name: o.data.name,
55
+ abbrev: o.data.symbol,
56
+ precision: Math.max(0, Math.min(10, Math.floor(o.data.precision || 2))),
57
+ measurements: []
58
+ },
59
+ rowNumber: o.index
60
+ }, o.data.measurement_name && o.data.measurement_symbol && o.data.measurement_conversion && _[o.data.name].unit.measurements.push({
61
+ id: De(),
62
+ name: o.data.measurement_name,
63
+ abbrev: o.data.measurement_symbol,
64
+ conversion: {
65
+ amount: Math.round(o.data.measurement_conversion * Math.pow(10, _[o.data.name].unit.precision)),
66
+ precision: _[o.data.name].unit.precision
67
+ }
68
+ });
69
+ else {
70
+ const l = Object.keys(_)[Object.keys(_).length - 1];
71
+ l && _[l] && o.data.measurement_name && o.data.measurement_symbol && o.data.measurement_conversion && _[l].unit.measurements.push({
72
+ id: De(),
73
+ name: o.data.measurement_name,
74
+ abbrev: o.data.measurement_symbol,
75
+ conversion: {
76
+ amount: Math.round(o.data.measurement_conversion * Math.pow(10, _[l].unit.precision)),
77
+ precision: _[l].unit.precision
78
+ }
79
+ });
80
+ }
81
+ for (const [o, { unit: l, rowNumber: s }] of Object.entries(_)) {
82
+ const y = h.find((c) => {
83
+ var d, f;
84
+ return c.abbrev === l.abbrev && ((d = c.name) == null ? void 0 : d.trim()) === ((f = l.name) == null ? void 0 : f.trim());
85
+ });
86
+ y ? w.push({
87
+ type: "update",
88
+ original: y,
89
+ unit: {
90
+ ...y,
91
+ name: l.name || y.name,
92
+ abbrev: l.abbrev || y.abbrev,
93
+ precision: l.precision !== void 0 ? l.precision : y.precision,
94
+ measurements: l.measurements.map((c) => {
95
+ const d = y.measurements.find((f) => f.name === c.name && f.abbrev === c.abbrev);
96
+ return d ? { ...d, ...c, id: d.id } : c;
97
+ })
98
+ },
99
+ errors: [],
100
+ excelRowNumber: s
101
+ }) : x.push({
102
+ type: "create",
103
+ unit: l,
104
+ errors: [],
105
+ excelRowNumber: s
106
+ });
107
+ }
108
+ return {
109
+ invalidExcel: !1,
110
+ importCreateResult: x,
111
+ importUpdateResult: w
112
+ };
113
+ } catch (e) {
114
+ return {
115
+ invalidExcel: !0,
116
+ invalidExcelMessage: (e == null ? void 0 : e.message) ?? "Invalid excel",
117
+ importCreateResult: [],
118
+ importUpdateResult: []
119
+ };
120
+ }
121
+ }
122
+ function at() {
123
+ return `recipe_${(/* @__PURE__ */ new Date()).toISOString()}_${Re()}`;
124
+ }
125
+ function lt(R, { ignoreErrors: e = !1 } = {}) {
126
+ var S, h, x;
127
+ try {
128
+ const w = le(), _ = w.skuByCode, o = w.recipeByName, l = w.skuGroupById, s = w.skuGroups, y = w.units, c = [];
129
+ let d = {};
130
+ for (const r of R) {
131
+ const b = [];
132
+ let C = "";
133
+ if (r.data.type === "INGREDIENT") {
134
+ const U = _[r.data.code];
135
+ U ? C = U._id : b.push(`Ingredient with code '${r.data.code}' not found`);
136
+ } else if (r.data.type === "RECIPE") {
137
+ const U = o[r.data.name];
138
+ U ? C = U._id : b.push(`Recipe with name '${r.data.name}' not found`);
139
+ } else if (r.data.type === "SKU_GROUP") {
140
+ const U = s.find((T) => T.ref === r.data.code || T.name === r.data.name);
141
+ U ? C = U._id : b.push(`SKU Group with ref '${r.data.code}' or name '${r.data.name}' not found`);
142
+ } else
143
+ b.push(`Invalid type '${r.data.type}'. Must be 'INGREDIENT', 'RECIPE', or 'SKU_GROUP'`);
144
+ (!r.data.amount || isNaN(parseFloat(r.data.amount))) && b.push(`Invalid amount '${r.data.amount}'. Must be a valid number`);
145
+ let A;
146
+ if ((r.data.unit || r.data.baseUnit) && r.data.type !== "RECIPE" && r.data.type !== "SKU_GROUP" && (A = y.find((U) => {
147
+ var T, re;
148
+ return U.abbrev === r.data.baseUnit && ((T = U.name) == null ? void 0 : T.trim()) === ((re = r.data.unit) == null ? void 0 : re.trim());
149
+ }), A || (r.data.baseUnit && r.data.unit ? b.push(`Cannot find unit with symbol '${r.data.baseUnit}' and name '${r.data.unit}'`) : r.data.baseUnit ? b.push(`Cannot find unit with symbol '${r.data.baseUnit}'`) : r.data.unit && b.push(`Cannot find unit with name '${r.data.unit}'`))), b.length > 0 && c.push(`Row ${r.index + 6}: ${b.join(", ")}`), e || b.length === 0) {
150
+ let U;
151
+ if (r.data.type === "RECIPE" || r.data.type === "SKU_GROUP" ? U = void 0 : U = (S = A == null ? void 0 : A.measurements) == null ? void 0 : S.find((T) => T.abbrev === r.data.measurementName), r.data.recipeName)
152
+ d[r.data.recipeName] = {
153
+ _id: at(),
154
+ name: r.data.recipeName,
155
+ customAttributes: r.data.customAttributes ? tt(r.data.customAttributes) : {},
156
+ contains: [{
157
+ type: r.data.type === "INGREDIENT" ? "SKU" : r.data.type,
158
+ id: C,
159
+ amount: {
160
+ amount: parseFloat(r.data.amount) || 0,
161
+ precision: Me(r.data.amount) === !0 && ((h = r.data.amount.split(".")[1]) == null ? void 0 : h.length) || 0
162
+ },
163
+ measurement: U || void 0
164
+ }]
165
+ }, c[r.data.recipeName] = b.length > 0 ? `Row ${r.index + 6}: ${b.join(", ")}` : [];
166
+ else {
167
+ const T = Object.keys(d)[Object.keys(d).length - 1];
168
+ T && d[T] && (d[T] = {
169
+ ...d[T],
170
+ contains: [
171
+ ...d[T].contains,
172
+ {
173
+ type: r.data.type === "INGREDIENT" ? "SKU" : r.data.type,
174
+ id: C,
175
+ amount: {
176
+ amount: parseFloat(r.data.amount) || 0,
177
+ precision: Me(r.data.amount) === !0 && ((x = r.data.amount.split(".")[1]) == null ? void 0 : x.length) || 0
178
+ },
179
+ measurement: U || void 0
180
+ }
181
+ ]
182
+ }, c[T] = b.length > 0 ? c[T] ? `${c[T]}, Row ${r.index + 6}: ${b.join(", ")}` : `Row ${r.index + 6}: ${b.join(", ")}` : []);
183
+ }
184
+ }
185
+ }
186
+ const f = Object.values(d), g = f.filter((r) => !o[r.name]), p = f.filter((r) => o[r.name]), u = g.map((r, b) => ({
187
+ type: "create",
188
+ recipe: r,
189
+ errors: c[r.name],
190
+ excelRowNumber: b + 6
191
+ // Assuming header rows
192
+ })), G = p.map((r, b) => {
193
+ const C = o[r.name];
194
+ return {
195
+ type: "update",
196
+ original: C,
197
+ recipe: {
198
+ ...C,
199
+ name: r.name || C.name,
200
+ contains: r.contains.length > 0 ? r.contains : C.contains,
201
+ customAttributes: r.customAttributes || C.customAttributes
202
+ },
203
+ errors: c[r.name],
204
+ excelRowNumber: b + 6
205
+ };
206
+ });
207
+ return {
208
+ invalidExcel: c.length > 0,
209
+ invalidExcelMessage: c.length > 0 ? `Import completed with ${c.length} error(s): ${c.join("; ")}` : void 0,
210
+ importCreateResult: u,
211
+ importUpdateResult: G
212
+ };
213
+ } catch (w) {
214
+ return {
215
+ invalidExcel: !0,
216
+ invalidExcelMessage: w instanceof Error ? w.message : "Unknown error occurred",
217
+ importCreateResult: [],
218
+ importUpdateResult: []
219
+ };
220
+ }
221
+ }
222
+ function mt(R) {
223
+ const [
224
+ e,
225
+ S,
226
+ h,
227
+ x,
228
+ w,
229
+ _,
230
+ ...o
231
+ ] = je(R);
232
+ if (!e || !e.length || e.some((d) => d.length && !d.startsWith("system:")))
233
+ throw new Error("Missing meta header. Excel file does not come from the template.");
234
+ const l = e.map((d) => d.split(":")[1]), y = ["code", "recipeName", "unit", "baseUnit", "type", "amount"].filter((d) => !l.includes(d));
235
+ if (y.length)
236
+ throw new Error(
237
+ `Missing meta headers (${y.join()}). Excel file does not come from the template.`
238
+ );
239
+ return o.map((d, f) => {
240
+ const g = {};
241
+ for (const p in l) {
242
+ const u = l[p];
243
+ Object.assign(g, { [u]: d[p] });
244
+ }
245
+ return {
246
+ index: f,
247
+ data: g
248
+ };
249
+ }).filter((d) => {
250
+ const { recipeName: f, type: g, code: p, name: u, amount: G, unit: r, baseUnit: b, measurementName: C, customAttributes: A } = d.data;
251
+ return f || g || p || u || G || r || b || C || A;
252
+ });
253
+ }
254
+ function ut() {
255
+ const e = ke().currentBusiness.value, S = le(), h = [
256
+ { id: "name", name: "Unit Name" },
257
+ { id: "symbol", name: "Symbol" },
258
+ { id: "precision", name: "Precision" },
259
+ { id: "measurement_name", name: "Measurement Name" },
260
+ { id: "measurement_symbol", name: "Measurement Symbol" },
261
+ { id: "measurement_conversion", name: "Measurement Conversion" }
262
+ ];
263
+ let x = [];
264
+ S.units.length > 0 ? S.units.forEach((o) => {
265
+ if (o.measurements.length === 0)
266
+ x.push([
267
+ o.name,
268
+ o.abbrev,
269
+ o.precision,
270
+ "",
271
+ "",
272
+ ""
273
+ ]);
274
+ else {
275
+ x.push([
276
+ o.name,
277
+ o.abbrev,
278
+ o.precision,
279
+ o.measurements[0].name,
280
+ o.measurements[0].abbrev,
281
+ o.measurements[0].conversion.amount
282
+ ]);
283
+ for (let l = 1; l < o.measurements.length; l++)
284
+ x.push([
285
+ "",
286
+ "",
287
+ "",
288
+ o.measurements[l].name,
289
+ o.measurements[l].abbrev,
290
+ o.measurements[l].conversion.amount
291
+ ]);
292
+ }
293
+ }) : x = [
294
+ ["Length", "m", 2, "Meter", "m", 1],
295
+ ["", "", "", "Centimeter", "cm", 0.01],
296
+ ["", "", "", "Millimeter", "mm", 1e-3],
297
+ ["Weight", "kg", 3, "Kilogram", "kg", 1],
298
+ ["", "", "", "Gram", "g", 1e-3],
299
+ ["", "", "", "Pound", "lb", 0.453592]
300
+ ];
301
+ const w = [
302
+ ["Business name:", e == null ? void 0 : e.name],
303
+ ["Business ID:", e == null ? void 0 : e._id],
304
+ ["Menu version", e == null ? void 0 : e.menuVersion],
305
+ [],
306
+ h.map((o) => o.name),
307
+ ...x
308
+ ], _ = h.map((o) => `system:${o.id}`);
309
+ return Se(w, _);
310
+ }
311
+ function dt() {
312
+ const e = ke().currentBusiness.value, S = le(), h = ot();
313
+ let x = [];
314
+ S.skus.length > 0 ? x = S.skus.map((o) => {
315
+ var l, s, y, c, d, f, g, p;
316
+ return [
317
+ o.code,
318
+ o.name,
319
+ ((l = o.unit) == null ? void 0 : l.name) || "",
320
+ ((s = o.unit) == null ? void 0 : s.abbrev) || "",
321
+ ((c = (y = o.unit) == null ? void 0 : y.measurements.find((u) => u.id === o.trackingMeasurement)) == null ? void 0 : c.abbrev) ?? o.unit.abbrev,
322
+ o.valuation || "WAVG",
323
+ (d = o.defaultCost) != null && d.costPerUnit ? +Le((f = o.defaultCost) == null ? void 0 : f.costPerUnit) : 0,
324
+ ((g = o.thresholds) == null ? void 0 : g.low) ?? Fe().low,
325
+ ((p = o.thresholds) == null ? void 0 : p.mid) ?? Fe().mid,
326
+ o.customAttributes ? Object.entries(o.customAttributes).map(([u, G]) => `${u}:${G}`).join("|") : ""
327
+ ];
328
+ }) : x = [
329
+ ["EXAMPLE_CODE", "Example Ingredient", "kg", "kg", "Unit Name", "WAVG", 10.5, 5, 10, ""]
330
+ ];
331
+ const w = [
332
+ ["Business name:", e == null ? void 0 : e.name],
333
+ ["Business ID:", e == null ? void 0 : e._id],
334
+ ["Menu version", e == null ? void 0 : e.menuVersion],
335
+ [],
336
+ h.map((o) => o.name),
337
+ ...x
338
+ ], _ = h.map((o) => `system:${o.id}`);
339
+ return Se(w, _);
340
+ }
341
+ function ct() {
342
+ const e = ke().currentBusiness.value, S = le(), h = [
343
+ { id: "recipeName", name: "Recipe Name" },
344
+ { id: "type", name: "Type" },
345
+ { id: "code", name: "Code" },
346
+ { id: "name", name: "Item Name" },
347
+ { id: "amount", name: "Amount" },
348
+ { id: "unit", name: "Unit" },
349
+ { id: "baseUnit", name: "Base Unit" },
350
+ { id: "measurementName", name: "Measurement Name" },
351
+ { id: "customAttributes", name: "Custom Attributes" }
352
+ ];
353
+ let x = [];
354
+ if (S.recipes.length > 0) {
355
+ const o = S.recipeById, l = S.skuById, s = S.skuGroupById;
356
+ x = S.recipes.flatMap((y) => {
357
+ var d;
358
+ const c = y.customAttributes ? Object.entries(y.customAttributes).map(([f, g]) => `${f}:${g}`).join("|") : "";
359
+ if ((d = y.contains) != null && d.length) {
360
+ const f = y.contains.filter((u) => u.type === "RECIPE"), g = y.contains.filter((u) => u.type === "SKU"), p = y.contains.filter((u) => u.type === "SKU_GROUP");
361
+ return [
362
+ ...f.map((u, G) => {
363
+ var r;
364
+ return [
365
+ G === 0 ? y.name : "",
366
+ "RECIPE",
367
+ "",
368
+ ((r = o[u.id]) == null ? void 0 : r.name) || "",
369
+ u.amount.amount,
370
+ "",
371
+ "unit",
372
+ "Unit",
373
+ G === 0 ? c : ""
374
+ ];
375
+ }),
376
+ ...g.map((u, G) => {
377
+ var r, b, C, A, U, T, re, ye, ge, me, fe, ue, be, he, xe, _e;
378
+ return [
379
+ !f.length && G === 0 ? y.name : "",
380
+ "INGREDIENT",
381
+ ((r = l[u.id]) == null ? void 0 : r.code) || "",
382
+ ((b = l[u.id]) == null ? void 0 : b.name) || "",
383
+ u.amount.amount,
384
+ u.measurement ? ((A = (C = l[u.id]) == null ? void 0 : C.unit) == null ? void 0 : A.name) || "" : ((T = (U = l[u.id]) == null ? void 0 : U.unit) == null ? void 0 : T.name) || "",
385
+ u.measurement ? ((ye = (re = l[u.id]) == null ? void 0 : re.unit) == null ? void 0 : ye.abbrev) || "" : ((me = (ge = l[u.id]) == null ? void 0 : ge.unit) == null ? void 0 : me.abbrev) || "",
386
+ u.measurement ? u.measurement.abbrev : ((he = (be = (ue = (fe = l[u.id]) == null ? void 0 : fe.unit) == null ? void 0 : ue.measurements) == null ? void 0 : be.find((Ie) => {
387
+ var m;
388
+ return Ie.id === ((m = l[u.id]) == null ? void 0 : m.trackingMeasurement);
389
+ })) == null ? void 0 : he.abbrev) || ((_e = (xe = l[u.id]) == null ? void 0 : xe.unit) == null ? void 0 : _e.abbrev) || "",
390
+ !f.length && G === 0 ? c : ""
391
+ ];
392
+ }),
393
+ ...p.map((u, G) => {
394
+ var r, b;
395
+ return [
396
+ f.length === 0 && g.length === 0 && G === 0 ? y.name : "",
397
+ "SKU_GROUP",
398
+ ((r = s[u.id]) == null ? void 0 : r.ref) || "",
399
+ ((b = s[u.id]) == null ? void 0 : b.name) || "",
400
+ u.amount.amount,
401
+ "",
402
+ "unit",
403
+ "Unit",
404
+ f.length === 0 && g.length === 0 && G === 0 ? c : ""
405
+ ];
406
+ })
407
+ ];
408
+ }
409
+ return [];
410
+ });
411
+ } else
412
+ x = [
413
+ ["Pizza Dough", "INGREDIENT", "FLOUR001", "Flour", "500", "Weight", "g", "Gram", "difficulty:easy, category:italian"],
414
+ ["", "INGREDIENT", "WATER001", "Water", "300", "Volume", "ml", "Milliliter", ""],
415
+ ["", "INGREDIENT", "SALT001", "Salt", "10", "Weight", "g", "Gram", ""]
416
+ ];
417
+ const w = [
418
+ ["Business name:", e == null ? void 0 : e.name],
419
+ ["Business ID:", e == null ? void 0 : e._id],
420
+ ["Menu version", e == null ? void 0 : e.menuVersion],
421
+ [],
422
+ h.map((o) => o.name),
423
+ ...x
424
+ ], _ = h.map((o) => `system:${o.id}`);
425
+ return Se(w, _);
426
+ }
427
+ function pt() {
428
+ const R = Ve({
429
+ unit: ut(),
430
+ ingredient: dt(),
431
+ recipe: ct()
432
+ }), e = "FeedMe comprehensive template.xlsx";
433
+ return We(R, e), e;
434
+ }
435
+ async function vt(R) {
436
+ if (!R) return null;
437
+ try {
438
+ return it(R);
439
+ } catch (e) {
440
+ throw console.error("Error in processUnitsSheet:", e), e;
441
+ }
442
+ }
443
+ async function yt(R) {
444
+ if (!R) return null;
445
+ try {
446
+ return nt(R);
447
+ } catch (e) {
448
+ throw console.error("Error in processIngredientsSheet:", e), e;
449
+ }
450
+ }
451
+ async function gt(R) {
452
+ if (!R) return null;
453
+ try {
454
+ const e = mt(R);
455
+ return lt(e, { ignoreErrors: !0 });
456
+ } catch (e) {
457
+ throw console.error("Error in processRecipesSheet:", e), e;
458
+ }
459
+ }
460
+ const ft = { class: "flex flex-col gap-24" }, bt = { class: "flex flex-col gap-8" }, ht = { class: "flex flex-col flex-1 gap-4" }, xt = { class: "fm-typo-en-body-md-600" }, _t = {
461
+ key: 2,
462
+ class: "shrink-0"
463
+ }, wt = {
464
+ key: 0,
465
+ class: "flex flex-col"
466
+ }, It = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, Et = {
467
+ key: 0,
468
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
469
+ }, St = { class: "fm-typo-en-body-lg-600" }, kt = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Rt = /* @__PURE__ */ Ae({
470
+ __name: "ImportDialog",
471
+ setup(R) {
472
+ const e = D(null), S = Ye();
473
+ He();
474
+ const h = D(!1), x = D(new Array()), w = D(null), _ = D([]), o = D([]), l = X(() => !!x.value.length), s = X(() => !!w.value && _.value.length > 0), { t: y } = Oe();
475
+ async function c(g) {
476
+ x.value = [], w.value = null, _.value = [], o.value = [];
477
+ try {
478
+ h.value = !0;
479
+ const [p] = await Promise.all([
480
+ qe(g),
481
+ // fake buffer for UX
482
+ new Promise((u) => setTimeout(u, 1e3))
483
+ ]);
484
+ w.value = p, d();
485
+ } catch (p) {
486
+ console.error("Error parsing Excel file:", p), x.value.push((p == null ? void 0 : p.message) || "Unknown error occurred");
487
+ } finally {
488
+ h.value = !1;
489
+ }
490
+ }
491
+ function d() {
492
+ if (x.value = [], !w.value) return;
493
+ const p = ["unit", "ingredient", "recipe"].filter((u) => w.value.Sheets[u]);
494
+ if (p.length === 0) {
495
+ x.value.push("No valid sheets found. Expected sheets: unit, ingredient, or recipe");
496
+ return;
497
+ }
498
+ _.value = p, S.emitData({ availableSheets: p, workbook: w.value });
499
+ }
500
+ ze(e, (g) => {
501
+ g && c(g);
502
+ });
503
+ function f() {
504
+ if (!w.value || _.value.length === 0) return "";
505
+ const g = [];
506
+ return _.value.forEach((p) => {
507
+ switch (p) {
508
+ case "unit":
509
+ g.push("Units sheet found");
510
+ break;
511
+ case "ingredient":
512
+ g.push("Ingredients sheet found");
513
+ break;
514
+ case "recipe":
515
+ g.push("Recipes sheet found");
516
+ break;
517
+ }
518
+ }), g.length > 0 ? `Ready to process: ${g.join(", ")}. Processing will follow dependency order.` : "No valid sheets found";
519
+ }
520
+ return (g, p) => {
521
+ const u = ee("FmCircularProgress"), G = ee("FmIcon"), r = ee("FmButton");
522
+ return N(), P("div", ft, [
523
+ B(Je, {
524
+ class: ve({
525
+ "w-full": !0,
526
+ "h-[200px]": !e.value
527
+ }),
528
+ accept: ".xlsx,.xls",
529
+ onFileUpload: p[0] || (p[0] = (b) => e.value = b),
530
+ label: i(y)("inventory.ingredient.import.uploadTemplate"),
531
+ "button-label": i(y)("inventory.ingredient.import.selectFile")
532
+ }, Ke({ _: 2 }, [
533
+ e.value ? {
534
+ name: "default",
535
+ fn: Z(({ openFileDialog: b }) => [
536
+ n("div", bt, [
537
+ n("div", {
538
+ class: ve([
539
+ "fm-corner-radius-md p-16 flex items-center gap-16",
540
+ {
541
+ "border border-fm-color-neutral-gray-100": h.value,
542
+ "border border-fm-color-neutral-gray-200": !h.value && !l.value,
543
+ "border border-fm-color-system-error-200": l.value
544
+ }
545
+ ])
546
+ }, [
547
+ h.value ? (N(), ae(u, {
548
+ key: 0,
549
+ size: "md",
550
+ color: "neutral-gray-200"
551
+ })) : (N(), ae(G, {
552
+ key: 1,
553
+ name: l.value ? "error" : "check_circle",
554
+ color: l.value ? "system-error-300" : "system-success-400",
555
+ size: "lg"
556
+ }, null, 8, ["name", "color"])),
557
+ n("div", ht, [
558
+ n("div", xt, a(e.value.name), 1),
559
+ n("div", {
560
+ class: ve([
561
+ "fm-typo-en-body-sm-400",
562
+ {
563
+ "text-fm-color-system-error-300": l.value,
564
+ "text-fm-color-typo-secondary": !l.value
565
+ }
566
+ ])
567
+ }, a(l.value ? i(y)("inventory.ingredient.import.error.invalidContent") : "File valid"), 3)
568
+ ]),
569
+ h.value ? te("", !0) : (N(), P("div", _t, [
570
+ B(r, {
571
+ label: i(y)("inventory.ingredient.import.replaceFile"),
572
+ variant: l.value ? "destructive" : "secondary",
573
+ "prepend-icon": l.value ? void 0 : "autorenew",
574
+ onClick: b
575
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
576
+ ]))
577
+ ], 2),
578
+ x.value.length ? (N(), P("div", wt, [
579
+ (N(!0), P(Be, null, Pe(x.value, (C, A) => (N(), P("div", {
580
+ key: A,
581
+ class: "flex gap-8 items-center"
582
+ }, [
583
+ B(G, {
584
+ name: "error",
585
+ size: "sm",
586
+ color: "system-error-300"
587
+ }),
588
+ n("div", It, a(C), 1)
589
+ ]))), 128))
590
+ ])) : te("", !0)
591
+ ])
592
+ ]),
593
+ key: "0"
594
+ } : void 0
595
+ ]), 1032, ["class", "label", "button-label"]),
596
+ s.value ? (N(), P("div", Et, [
597
+ n("div", St, a(i(y)("inventory.ingredient.import.summary")), 1),
598
+ n("div", kt, a(f()), 1)
599
+ ])) : te("", !0)
600
+ ]);
601
+ };
602
+ }
603
+ }), Ct = {
604
+ key: 0,
605
+ class: "bg-blue-50 border border-blue-200 rounded-lg p-16"
606
+ }, Ut = { class: "flex items-start gap-12" }, Nt = { class: "flex flex-col gap-8" }, Gt = { class: "fm-typo-en-body-md-400 text-blue-800" }, Tt = { class: "fm-typo-en-body-sm-400 text-blue-700" }, $t = { class: "mb-8" }, Mt = ["innerHTML"], Ft = ["innerHTML"], Dt = { class: "mb-8" }, At = { class: "mb-12" }, Bt = { class: "mb-12" }, Pt = { class: "mb-8" }, jt = { class: "text-orange-600" }, Ot = {
607
+ key: 1,
608
+ class: "bg-white rounded-lg shadow"
609
+ }, Ht = { class: "flex items-center justify-between p-16 border-b" }, zt = { class: "fm-typo-en-title-md-600" }, Kt = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, Vt = {
610
+ key: 0,
611
+ class: "text-red-600"
612
+ }, Wt = {
613
+ key: 1,
614
+ class: "text-orange-600"
615
+ }, Lt = {
616
+ key: 2,
617
+ class: "text-green-600"
618
+ }, Jt = { class: "flex gap-8" }, qt = { class: "p-16" }, Xt = {
619
+ key: 2,
620
+ class: "bg-white rounded-lg shadow"
621
+ }, Qt = { class: "flex items-center justify-between p-16 border-b" }, Yt = { class: "fm-typo-en-title-md-600 text-red-800" }, Zt = { class: "fm-typo-en-body-sm-400 text-gray-600 mt-4" }, en = { class: "flex gap-8" }, tn = { class: "p-16" }, nn = {
622
+ key: 0,
623
+ class: "flex flex-col gap-16 p-16"
624
+ }, on = { class: "fm-typo-en-title-sm-600 mb-12" }, rn = { class: "grid grid-cols-2 gap-12" }, sn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, an = { class: "fm-typo-en-body-md-600" }, ln = { key: 0 }, mn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, un = { class: "fm-typo-en-body-md-600" }, dn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, cn = { class: "fm-typo-en-body-md-600" }, pn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, vn = { class: "fm-typo-en-body-md-600" }, yn = { class: "fm-typo-en-body-sm-400 text-gray-600" }, gn = { class: "fm-typo-en-title-sm-600 mb-12 text-red-800" }, fn = { class: "space-y-8" }, bn = { class: "fm-typo-en-body-md-400 text-red-800" }, hn = { class: "fm-typo-en-title-sm-600 mb-12" }, xn = { class: "bg-gray-50 p-12 rounded border overflow-auto" }, _n = { class: "text-sm" }, wn = { class: "flex gap-8" }, In = { class: "flex flex-col items-center justify-center h-64 gap-16" }, En = { class: "text-center" }, Sn = { class: "fm-typo-en-title-md-600 text-gray-600 mb-8" }, kn = { class: "flex flex-col items-center justify-center h-64 gap-16" }, Rn = { class: "text-center" }, Cn = { class: "fm-typo-en-title-md-600 text-gray-600 mb-8" }, Un = { class: "fm-typo-en-body-md-400 text-gray-500" }, Dn = /* @__PURE__ */ Ae({
625
+ __name: "ImportView",
626
+ setup(R) {
627
+ const { t: e } = Oe(), S = Ze(), h = He();
628
+ Xe();
629
+ const x = Qe(), { breakpoints: w } = et(), _ = le(), o = D("");
630
+ D(!1);
631
+ const l = D(!1), s = D(null), y = D(!1), c = D(null), d = D(!1), f = D([]), g = D(null), p = D([]), u = D(!1), G = X(() => w.value.xs || w.value.sm), r = X(() => G.value ? 10 : 20), b = X(() => {
632
+ const m = s.value;
633
+ if (!m) return [];
634
+ const t = [], { units: k, skus: j, recipes: J, _invalidExcel: V, _invalidExcelMessage: Q } = m, Y = (M) => {
635
+ var H;
636
+ return ((H = M.errors) == null ? void 0 : H.length) > 0 ? Array.isArray(M.errors) ? M.errors.join(", ") : M.errors || e("inventory.common.validationFailed") : V ? Q || e("inventory.common.invalidExcelFormat") : e("inventory.common.readyToImport");
637
+ }, K = (M, z) => {
638
+ if (M)
639
+ for (const H of ["create", "update"]) {
640
+ const W = M[H];
641
+ if (W)
642
+ for (const O of W)
643
+ t.push({
644
+ name: O.name || O.abbrev || O.code || e("inventory.common.unknown"),
645
+ type: z,
646
+ operation: e(H === "create" ? "inventory.common.create" : "inventory.common.update"),
647
+ status: Y(O),
648
+ errors: O.errors || [],
649
+ details: O
650
+ });
651
+ }
652
+ };
653
+ return K(k, e("inventory.common.unit")), K(j, e("inventory.common.ingredient")), K(J, e("inventory.common.recipe")), t;
654
+ }), C = X(() => b.value.some(
655
+ (m) => m.errors && m.errors.length > 0
656
+ )), A = X(() => b.value.some(
657
+ (m) => m.status && m.status.includes("Invalid Excel")
658
+ )), U = X(() => {
659
+ const m = b.value.find(
660
+ (t) => t.status && t.status.includes("Invalid Excel")
661
+ );
662
+ return (m == null ? void 0 : m.status) || e("inventory.common.invalidExcelFormatDetected");
663
+ }), T = X(() => !p.value || p.value.length === 0 ? [] : p.value.map((m, t) => {
664
+ var k, j;
665
+ return {
666
+ id: t + 1,
667
+ name: ((k = m.error.data) == null ? void 0 : k.name) || e("inventory.common.unknown"),
668
+ type: m.type || e("inventory.common.general"),
669
+ message: ((j = m.error) == null ? void 0 : j.message) || JSON.stringify(m.error)
670
+ };
671
+ }));
672
+ function re(m) {
673
+ switch (m) {
674
+ case "import":
675
+ return ye();
676
+ }
677
+ }
678
+ function ye() {
679
+ S.open({
680
+ title: e("inventory.common.import"),
681
+ contentComponent: Rt,
682
+ overlay: !0,
683
+ closeButton: !0,
684
+ primaryActions: {
685
+ text: e("inventory.common.next"),
686
+ close: !1
687
+ },
688
+ secondaryActions: {
689
+ text: e("inventory.common.close"),
690
+ close: !0
691
+ },
692
+ tertiaryActions: {
693
+ text: e("inventory.ingredient.import.actions.downloadTemplate"),
694
+ close: !1,
695
+ variant: "plain"
696
+ }
697
+ }).onPrimary(async (m) => {
698
+ m && m.workbook && m.availableSheets && (await ge(m), S.close()), f.value.length === 0 && S.close();
699
+ }).onTertiary(() => {
700
+ try {
701
+ const m = pt();
702
+ h.open({
703
+ title: e("inventory.common.export") + " " + e("inventory.ingredient.import.actions.downloadTemplate"),
704
+ message: e("inventory.common.templateDownloaded", [m]),
705
+ type: "success"
706
+ });
707
+ } catch (m) {
708
+ h.open({
709
+ title: e("inventory.common.downloadFailed"),
710
+ message: e("inventory.common.failedDownloadTemplate"),
711
+ type: "error"
712
+ }), console.error("Error downloading template:", m);
713
+ }
714
+ });
715
+ }
716
+ async function ge(m) {
717
+ g.value = m.workbook, f.value = [...m.availableSheets], s.value = {}, await me();
718
+ }
719
+ async function me() {
720
+ var t, k, j, J, V, Q, Y, K, M, z, H, W, O, de, ce;
721
+ if (!g.value || f.value.length === 0) {
722
+ y.value = !0;
723
+ return;
724
+ }
725
+ const m = f.value[0];
726
+ try {
727
+ switch (m) {
728
+ case "unit": {
729
+ const q = g.value.Sheets.unit, I = await vt(q);
730
+ I && (s.value = {
731
+ ...s.value,
732
+ _invalidExcel: I.invalidExcel || ((t = s.value) == null ? void 0 : t._invalidExcel),
733
+ _invalidExcelMessage: I.invalidExcelMessage || ((k = s.value) == null ? void 0 : k._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Units sheet",
734
+ units: I.importCreateResult || I.importUpdateResult ? {
735
+ create: ((j = I.importCreateResult) == null ? void 0 : j.map((F) => ({
736
+ ...F.unit,
737
+ errors: F.errors
738
+ }))) || [],
739
+ update: ((J = I.importUpdateResult) == null ? void 0 : J.map((F) => ({
740
+ ...F.unit,
741
+ errors: F.errors
742
+ }))) || []
743
+ } : (V = s.value) == null ? void 0 : V.units
744
+ });
745
+ break;
746
+ }
747
+ case "ingredient": {
748
+ const q = g.value.Sheets.ingredient, I = await yt(q);
749
+ I && (s.value = {
750
+ ...s.value,
751
+ _invalidExcel: I.invalidExcel || ((Q = s.value) == null ? void 0 : Q._invalidExcel),
752
+ _invalidExcelMessage: I.invalidExcelMessage || ((Y = s.value) == null ? void 0 : Y._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Ingredients sheet",
753
+ skus: I.importCreateResult || I.importUpdateResult ? {
754
+ create: ((K = I.importCreateResult) == null ? void 0 : K.map((F) => ({
755
+ ...F.sku,
756
+ errors: F.errors
757
+ }))) || [],
758
+ update: ((M = I.importUpdateResult) == null ? void 0 : M.map((F) => ({
759
+ ...F.sku,
760
+ errors: F.errors
761
+ }))) || []
762
+ } : (z = s.value) == null ? void 0 : z.skus
763
+ });
764
+ break;
765
+ }
766
+ case "recipe": {
767
+ const q = g.value.Sheets.recipe, I = await gt(q);
768
+ I && (s.value = {
769
+ ...s.value,
770
+ _invalidExcel: I.invalidExcel || ((H = s.value) == null ? void 0 : H._invalidExcel),
771
+ _invalidExcelMessage: I.invalidExcelMessage || ((W = s.value) == null ? void 0 : W._invalidExcelMessage) || e("inventory.common.invalidExcelFormat") + " for Recipes sheet",
772
+ recipes: I.importCreateResult || I.importUpdateResult ? {
773
+ create: ((O = I.importCreateResult) == null ? void 0 : O.map((F) => ({
774
+ ...F.recipe,
775
+ errors: F.errors
776
+ }))) || [],
777
+ update: ((de = I.importUpdateResult) == null ? void 0 : de.map((F) => ({
778
+ ...F.recipe,
779
+ errors: F.errors
780
+ }))) || []
781
+ } : (ce = s.value) == null ? void 0 : ce.recipes
782
+ });
783
+ break;
784
+ }
785
+ }
786
+ f.value.shift(), y.value = !0;
787
+ } catch (q) {
788
+ console.error(`Error processing ${m} sheet:`, q), h.open({
789
+ title: e("inventory.common.processingError"),
790
+ message: e("inventory.common.failedToProcessSheet", [m]),
791
+ type: "error"
792
+ });
793
+ }
794
+ }
795
+ async function fe() {
796
+ var m, t, k, j, J, V, Q, Y, K, M, z, H, W, O, de, ce, q, I, F, Ce, Ue, Ne, Ge, Te;
797
+ if (s.value) {
798
+ if (A.value) {
799
+ h.open({
800
+ title: e("inventory.common.invalidExcelFormatTitle"),
801
+ message: U.value,
802
+ type: "error"
803
+ });
804
+ return;
805
+ }
806
+ if (C.value) {
807
+ h.open({
808
+ title: e("inventory.ingredient.import.error.invalidContent"),
809
+ message: e("inventory.ingredient.import.error.hasErrors"),
810
+ type: "error"
811
+ });
812
+ return;
813
+ }
814
+ l.value = !0;
815
+ try {
816
+ let L = 0, se = "";
817
+ if (s.value.units && ((m = s.value.units.create) != null && m.length || (t = s.value.units.update) != null && t.length)) {
818
+ const $ = {
819
+ create: ((k = s.value.units.create) == null ? void 0 : k.filter((v) => !v.errors || v.errors.length === 0)) || [],
820
+ update: ((j = s.value.units.update) == null ? void 0 : j.filter((v) => !v.errors || v.errors.length === 0)) || []
821
+ };
822
+ if ($.create.length || $.update.length) {
823
+ const v = await _.importUnits($);
824
+ ((J = v == null ? void 0 : v.errors) == null ? void 0 : J.length) > 0 && p.value.push(...v.errors.map((ie) => ({
825
+ type: "units",
826
+ error: ie
827
+ })));
828
+ const ne = $.create.length + $.update.length, oe = ((V = v == null ? void 0 : v.errors) == null ? void 0 : V.length) || 0;
829
+ L = ne - oe, se = "units", s.value = {
830
+ ...s.value,
831
+ units: null
832
+ };
833
+ }
834
+ } else if (s.value.skus && ((Q = s.value.skus.create) != null && Q.length || (Y = s.value.skus.update) != null && Y.length)) {
835
+ const $ = {
836
+ create: ((K = s.value.skus.create) == null ? void 0 : K.filter((v) => !v.errors || v.errors.length === 0)) || [],
837
+ update: ((M = s.value.skus.update) == null ? void 0 : M.filter((v) => !v.errors || v.errors.length === 0)) || []
838
+ };
839
+ if ($.create.length || $.update.length) {
840
+ const v = await _.importSkus($);
841
+ ((z = v == null ? void 0 : v.errors) == null ? void 0 : z.length) > 0 && p.value.push(...v.errors.map((ie) => ({
842
+ type: "ingredients",
843
+ error: ie
844
+ })));
845
+ const ne = $.create.length + $.update.length, oe = ((H = v == null ? void 0 : v.errors) == null ? void 0 : H.length) || 0;
846
+ L = ne - oe, se = "ingredients", s.value = {
847
+ ...s.value,
848
+ skus: null
849
+ };
850
+ }
851
+ } else if (s.value.recipes && ((W = s.value.recipes.create) != null && W.length || (O = s.value.recipes.update) != null && O.length)) {
852
+ const $ = {
853
+ create: ((de = s.value.recipes.create) == null ? void 0 : de.filter((v) => !v.errors || v.errors.length === 0)) || [],
854
+ update: ((ce = s.value.recipes.update) == null ? void 0 : ce.filter((v) => !v.errors || v.errors.length === 0)) || []
855
+ };
856
+ if ($.create.length || $.update.length) {
857
+ const v = await _.importRecipes($);
858
+ ((q = v == null ? void 0 : v.errors) == null ? void 0 : q.length) > 0 && p.value.push(...v.errors.map((ie) => ({
859
+ type: "recipes",
860
+ error: ie
861
+ })));
862
+ const ne = $.create.length + $.update.length, oe = ((I = v == null ? void 0 : v.errors) == null ? void 0 : I.length) || 0;
863
+ L = ne - oe, se = "recipes", s.value = {
864
+ ...s.value,
865
+ recipes: null
866
+ };
867
+ }
868
+ }
869
+ if (L > 0) {
870
+ const $ = p.value.filter((v) => v.type === se);
871
+ $.length > 0 ? h.open({
872
+ title: e("inventory.common.importCompletedWithIssues"),
873
+ message: e("inventory.common.successfullyImported", [L, se, $.length, se]),
874
+ type: "warning"
875
+ }) : h.open({
876
+ title: e("inventory.ingredient.import.success"),
877
+ message: e("inventory.common.successfullyImported", [L, se, "0", ""]),
878
+ type: "success"
879
+ });
880
+ }
881
+ if (f.value.length > 0)
882
+ await me();
883
+ else if (!(s.value.units && (((F = s.value.units.create) == null ? void 0 : F.length) || ((Ce = s.value.units.update) == null ? void 0 : Ce.length)) || s.value.skus && (((Ue = s.value.skus.create) == null ? void 0 : Ue.length) || ((Ne = s.value.skus.update) == null ? void 0 : Ne.length)) || s.value.recipes && (((Ge = s.value.recipes.create) == null ? void 0 : Ge.length) || ((Te = s.value.recipes.update) == null ? void 0 : Te.length))))
884
+ if (ue(), p.value.length > 0) {
885
+ const v = p.value.filter((pe) => pe.type === "units").length, ne = p.value.filter((pe) => pe.type === "ingredients").length, oe = p.value.filter((pe) => pe.type === "recipes").length, ie = v + ne + oe;
886
+ u.value = !0, h.open({
887
+ title: e("inventory.common.importCompletedWithIssues"),
888
+ message: e("inventory.common.importFinishedWithFailedItems", [ie, v, ne, oe]),
889
+ type: "warning"
890
+ }), console.error("Import errors:", p.value);
891
+ } else
892
+ h.open({
893
+ title: e("inventory.common.importComplete"),
894
+ message: e("inventory.common.allDataSuccessfullyImported"),
895
+ type: "success"
896
+ });
897
+ } catch (L) {
898
+ h.open({
899
+ title: e("inventory.ingredient.import.error.failed"),
900
+ message: (L == null ? void 0 : L.message) || e("inventory.common.unknownErrorOccurred"),
901
+ type: "error"
902
+ }), console.error("Error during import:", L);
903
+ } finally {
904
+ l.value = !1;
905
+ }
906
+ }
907
+ }
908
+ function ue() {
909
+ y.value = !1, u.value = !1, s.value = null, f.value = [], g.value = null;
910
+ }
911
+ function be() {
912
+ u.value = !1, p.value = [];
913
+ }
914
+ function he() {
915
+ d.value = !1, c.value = null;
916
+ }
917
+ const xe = X(() => [
918
+ {
919
+ label: e("inventory.common.import"),
920
+ value: "import",
921
+ isPrimary: !1,
922
+ prependIcon: "upload"
923
+ }
924
+ ]), _e = $e([
925
+ {
926
+ id: "name",
927
+ accessorKey: "name",
928
+ header: () => e("inventory.common.name"),
929
+ size: 200
930
+ },
931
+ {
932
+ id: "type",
933
+ accessorKey: "type",
934
+ header: () => e("inventory.common.type"),
935
+ size: 120
936
+ },
937
+ {
938
+ id: "operation",
939
+ accessorKey: "operation",
940
+ header: () => e("inventory.common.operation"),
941
+ size: 100
942
+ },
943
+ {
944
+ id: "status",
945
+ accessorKey: "status",
946
+ header: () => e("inventory.common.status"),
947
+ size: 120,
948
+ cell: (m) => {
949
+ const t = m.row.original.status;
950
+ let k = "px-8 py-4 rounded";
951
+ return t === e("inventory.common.readyToImport") ? k += " bg-blue-100 text-blue-800 border border-blue-200" : t === "Imported" || t === "Successfully Imported" ? k += " bg-green-100 text-green-800 border border-green-200" : t === "Failed" ? k += " bg-red-100 text-red-800 border border-red-200" : t === e("inventory.common.validationFailed") ? k += " bg-orange-100 text-orange-800 border border-orange-200" : (t.includes("Invalid Excel"), k += " bg-red-100 text-red-800 border border-red-200"), we("div", { class: k, title: t }, t);
952
+ }
953
+ }
954
+ ]), Ie = $e([
955
+ {
956
+ id: "name",
957
+ accessorKey: "name",
958
+ header: () => e("inventory.common.name"),
959
+ cell: (m) => we("div", { class: "text-gray-800 text-sm py-2" }, m.row.original.name || e("inventory.common.unknown"))
960
+ },
961
+ {
962
+ id: "type",
963
+ accessorKey: "type",
964
+ header: () => e("inventory.common.errorType"),
965
+ cell: (m) => {
966
+ const t = m.row.original.type, k = e(t === "units" ? "inventory.common.unit" : t === "ingredients" ? "inventory.common.ingredient" : t === "recipes" ? "inventory.common.recipe" : "inventory.common.unknown");
967
+ return we("div", { class: "text-gray-800 text-sm py-2" }, k);
968
+ }
969
+ },
970
+ {
971
+ id: "message",
972
+ accessorKey: "message",
973
+ header: () => e("inventory.common.errorMessage"),
974
+ cell: (m) => we(
975
+ "div",
976
+ { class: "text-red-800 text-sm py-2", title: m.row.original.message },
977
+ m.row.original.message
978
+ )
979
+ }
980
+ ]);
981
+ return (m, t) => {
982
+ const k = ee("FmIcon"), j = ee("FmButton"), J = ee("FmTable"), V = ee("FmCard"), Q = ee("FmSideSheet"), Y = ee("FmSpinner");
983
+ return i(x).isLoaded && i(x).enableBulkImport ? (N(), ae(Ee, {
984
+ key: 0,
985
+ title: i(e)("inventory.common.import"),
986
+ actions: xe.value,
987
+ "onClick:action": re
988
+ }, {
989
+ default: Z(() => {
990
+ var K;
991
+ return [
992
+ n("div", {
993
+ class: ve([
994
+ "flex flex-col gap-8 max-h-full",
995
+ {
996
+ "p-0": G.value,
997
+ "px-24": !G.value
998
+ }
999
+ ])
1000
+ }, [
1001
+ y.value ? te("", !0) : (N(), P("div", Ct, [
1002
+ n("div", Ut, [
1003
+ B(k, {
1004
+ name: "info",
1005
+ class: "text-blue-600 mt-2"
1006
+ }),
1007
+ n("div", Nt, [
1008
+ n("div", Gt, a(i(e)("inventory.ingredient.import.multiUploadTemplateInstruction")), 1),
1009
+ n("div", Tt, [
1010
+ n("div", $t, [
1011
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.title")), 1)
1012
+ ]),
1013
+ t[39] || (t[39] = E(" 1. ")),
1014
+ n("span", {
1015
+ innerHTML: i(e)("inventory.ingredient.import.importInstructions.step1")
1016
+ }, null, 8, Mt),
1017
+ t[40] || (t[40] = n("br", null, null, -1)),
1018
+ t[41] || (t[41] = E(" 2. ")),
1019
+ n("span", {
1020
+ innerHTML: i(e)("inventory.ingredient.import.importInstructions.step2")
1021
+ }, null, 8, Ft),
1022
+ t[42] || (t[42] = n("br", null, null, -1)),
1023
+ E(" 3. " + a(i(e)("inventory.ingredient.import.importInstructions.step3")), 1),
1024
+ t[43] || (t[43] = n("br", null, null, -1)),
1025
+ E(" 4. " + a(i(e)("inventory.ingredient.import.importInstructions.step4")), 1),
1026
+ t[44] || (t[44] = n("br", null, null, -1)),
1027
+ t[45] || (t[45] = n("br", null, null, -1)),
1028
+ n("div", Dt, [
1029
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.title")), 1)
1030
+ ]),
1031
+ n("div", At, [
1032
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.title")), 1),
1033
+ E(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.description")), 1),
1034
+ t[1] || (t[1] = n("br", null, null, -1)),
1035
+ t[2] || (t[2] = E(" • ")),
1036
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col1")), 1),
1037
+ t[3] || (t[3] = n("br", null, null, -1)),
1038
+ t[4] || (t[4] = E(" • ")),
1039
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col2")), 1),
1040
+ t[5] || (t[5] = n("br", null, null, -1)),
1041
+ t[6] || (t[6] = E(" • ")),
1042
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col3")), 1),
1043
+ t[7] || (t[7] = n("br", null, null, -1)),
1044
+ t[8] || (t[8] = E(" • ")),
1045
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col4")), 1),
1046
+ t[9] || (t[9] = n("br", null, null, -1)),
1047
+ t[10] || (t[10] = E(" • ")),
1048
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col5")), 1),
1049
+ t[11] || (t[11] = n("br", null, null, -1)),
1050
+ t[12] || (t[12] = E(" • ")),
1051
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.unitsSheet.col6")), 1)
1052
+ ]),
1053
+ n("div", Bt, [
1054
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.title")), 1),
1055
+ E(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.description")), 1),
1056
+ t[13] || (t[13] = n("br", null, null, -1)),
1057
+ t[14] || (t[14] = E(" • ")),
1058
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col1")), 1),
1059
+ t[15] || (t[15] = n("br", null, null, -1)),
1060
+ t[16] || (t[16] = E(" • ")),
1061
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col2")), 1),
1062
+ t[17] || (t[17] = n("br", null, null, -1)),
1063
+ t[18] || (t[18] = E(" • ")),
1064
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col3")), 1),
1065
+ t[19] || (t[19] = n("br", null, null, -1)),
1066
+ t[20] || (t[20] = E(" • ")),
1067
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col4")), 1),
1068
+ t[21] || (t[21] = n("br", null, null, -1)),
1069
+ t[22] || (t[22] = E(" • ")),
1070
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.ingredientsSheet.col5")), 1)
1071
+ ]),
1072
+ n("div", Pt, [
1073
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.title")), 1),
1074
+ E(" " + a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.description")), 1),
1075
+ t[23] || (t[23] = n("br", null, null, -1)),
1076
+ t[24] || (t[24] = E(" • ")),
1077
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col1")), 1),
1078
+ t[25] || (t[25] = n("br", null, null, -1)),
1079
+ t[26] || (t[26] = E(" • ")),
1080
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col2")), 1),
1081
+ t[27] || (t[27] = n("br", null, null, -1)),
1082
+ t[28] || (t[28] = E(" • ")),
1083
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col3")), 1),
1084
+ t[29] || (t[29] = n("br", null, null, -1)),
1085
+ t[30] || (t[30] = E(" • ")),
1086
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col4")), 1),
1087
+ t[31] || (t[31] = n("br", null, null, -1)),
1088
+ t[32] || (t[32] = E(" • ")),
1089
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col5")), 1),
1090
+ t[33] || (t[33] = n("br", null, null, -1)),
1091
+ t[34] || (t[34] = E(" • ")),
1092
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col6")), 1),
1093
+ t[35] || (t[35] = n("br", null, null, -1)),
1094
+ t[36] || (t[36] = E(" • ")),
1095
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col7")), 1),
1096
+ t[37] || (t[37] = n("br", null, null, -1)),
1097
+ t[38] || (t[38] = E(" • ")),
1098
+ n("em", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.recipesSheet.col8")), 1)
1099
+ ]),
1100
+ n("div", jt, [
1101
+ n("strong", null, a(i(e)("inventory.ingredient.import.importInstructions.detailedGuide.warning")), 1)
1102
+ ])
1103
+ ])
1104
+ ])
1105
+ ])
1106
+ ])),
1107
+ y.value ? (N(), P("div", Ot, [
1108
+ n("div", Ht, [
1109
+ n("div", null, [
1110
+ n("div", zt, a(i(e)("inventory.common.importPreview")), 1),
1111
+ n("div", Kt, [
1112
+ A.value ? (N(), P("span", Vt, a(i(e)("inventory.common.errorExist")) + ": " + a(U.value), 1)) : C.value ? (N(), P("span", Wt, a(i(e)("inventory.common.someItemsValidationErrors")), 1)) : (N(), P("span", Lt, a(i(e)("inventory.common.allItemsValidReadyImport")), 1))
1113
+ ])
1114
+ ]),
1115
+ n("div", Jt, [
1116
+ B(j, {
1117
+ variant: "secondary",
1118
+ onClick: ue,
1119
+ label: i(e)("inventory.common.cancel")
1120
+ }, null, 8, ["label"]),
1121
+ B(j, {
1122
+ variant: "primary",
1123
+ onClick: fe,
1124
+ loading: l.value,
1125
+ disabled: l.value || C.value || A.value,
1126
+ label: i(e)("inventory.common.import")
1127
+ }, null, 8, ["loading", "disabled", "label"])
1128
+ ])
1129
+ ]),
1130
+ n("div", qt, [
1131
+ B(J, {
1132
+ "column-defs": _e.value,
1133
+ "row-data": b.value,
1134
+ "page-size": r.value,
1135
+ "search-value": o.value,
1136
+ loading: !1,
1137
+ "row-hover": ""
1138
+ }, null, 8, ["column-defs", "row-data", "page-size", "search-value"])
1139
+ ])
1140
+ ])) : te("", !0),
1141
+ u.value && p.value.length > 0 ? (N(), P("div", Xt, [
1142
+ n("div", Qt, [
1143
+ n("div", null, [
1144
+ n("div", Yt, a(i(e)("inventory.common.importErrors")), 1),
1145
+ n("div", Zt, a(p.value.length) + " " + a(i(e)("inventory.common.itemsFailedImport")), 1)
1146
+ ]),
1147
+ n("div", en, [
1148
+ B(j, {
1149
+ variant: "secondary",
1150
+ onClick: be,
1151
+ label: i(e)("inventory.common.close")
1152
+ }, null, 8, ["label"])
1153
+ ])
1154
+ ]),
1155
+ n("div", tn, [
1156
+ B(J, {
1157
+ "column-defs": Ie.value,
1158
+ "row-data": T.value,
1159
+ "page-size": r.value,
1160
+ "search-value": o.value,
1161
+ loading: !1,
1162
+ "row-hover": ""
1163
+ }, null, 8, ["column-defs", "row-data", "page-size", "search-value"])
1164
+ ])
1165
+ ])) : te("", !0)
1166
+ ], 2),
1167
+ B(Q, {
1168
+ "model-value": d.value,
1169
+ "onUpdate:modelValue": t[0] || (t[0] = (M) => d.value = M),
1170
+ header: `${(K = c.value) == null ? void 0 : K.type} Details`,
1171
+ "max-width": 600,
1172
+ "dismiss-away": ""
1173
+ }, {
1174
+ "side-sheet-footer": Z(() => [
1175
+ n("div", wn, [
1176
+ B(j, {
1177
+ label: i(e)("inventory.common.close"),
1178
+ variant: "tertiary",
1179
+ onClick: he
1180
+ }, null, 8, ["label"])
1181
+ ])
1182
+ ]),
1183
+ default: Z(() => [
1184
+ c.value != null ? (N(), P("div", nn, [
1185
+ B(V, {
1186
+ variant: "outlined",
1187
+ class: "p-16"
1188
+ }, {
1189
+ default: Z(() => {
1190
+ var M, z, H, W, O;
1191
+ return [
1192
+ n("div", on, a(i(e)("inventory.common.basicInformation")), 1),
1193
+ n("div", rn, [
1194
+ n("div", null, [
1195
+ n("div", sn, a(i(e)("inventory.common.name")), 1),
1196
+ n("div", an, a(((z = (M = c.value) == null ? void 0 : M.details) == null ? void 0 : z.name) || ((H = c.value) == null ? void 0 : H.name)), 1)
1197
+ ]),
1198
+ (O = (W = c.value) == null ? void 0 : W.details) != null && O.code ? (N(), P("div", ln, [
1199
+ n("div", mn, a(i(e)("inventory.common.code")), 1),
1200
+ n("div", un, a(c.value.details.code), 1)
1201
+ ])) : te("", !0),
1202
+ n("div", null, [
1203
+ n("div", dn, a(i(e)("inventory.common.type")), 1),
1204
+ n("div", cn, a(c.value.type), 1)
1205
+ ]),
1206
+ n("div", null, [
1207
+ n("div", pn, a(i(e)("inventory.common.operation")), 1),
1208
+ n("div", vn, a(c.value.operation), 1)
1209
+ ]),
1210
+ n("div", null, [
1211
+ n("div", yn, a(i(e)("inventory.common.status")), 1),
1212
+ n("div", {
1213
+ class: ve([
1214
+ "inline-block px-8 py-4 rounded text-sm",
1215
+ c.value.status !== i(e)("inventory.common.readyToImport") ? "bg-red-100 text-red-800 border border-red-200" : "bg-green-100 text-green-800 border border-green-200"
1216
+ ])
1217
+ }, a(c.value.status), 3)
1218
+ ])
1219
+ ])
1220
+ ];
1221
+ }),
1222
+ _: 1
1223
+ }),
1224
+ c.value.errors && c.value.errors.length > 0 ? (N(), ae(V, {
1225
+ key: 0,
1226
+ variant: "outlined",
1227
+ class: "p-16"
1228
+ }, {
1229
+ default: Z(() => [
1230
+ n("div", gn, a(i(e)("inventory.common.validationErrors")), 1),
1231
+ n("div", fn, [
1232
+ (N(!0), P(Be, null, Pe(c.value.errors, (M, z) => (N(), P("div", {
1233
+ key: z,
1234
+ class: "flex items-start gap-8 p-12 bg-red-50 border border-red-200 rounded"
1235
+ }, [
1236
+ B(k, {
1237
+ name: "error",
1238
+ class: "text-red-600 mt-2",
1239
+ size: "sm"
1240
+ }),
1241
+ n("div", bn, a(M), 1)
1242
+ ]))), 128))
1243
+ ])
1244
+ ]),
1245
+ _: 1
1246
+ })) : te("", !0),
1247
+ B(V, {
1248
+ variant: "outlined",
1249
+ class: "p-16"
1250
+ }, {
1251
+ default: Z(() => [
1252
+ n("div", hn, a(i(e)("inventory.common.rawData")), 1),
1253
+ n("div", xn, [
1254
+ n("pre", _n, a(JSON.stringify(c.value.details, null, 2)), 1)
1255
+ ])
1256
+ ]),
1257
+ _: 1
1258
+ })
1259
+ ])) : te("", !0)
1260
+ ]),
1261
+ _: 1
1262
+ }, 8, ["model-value", "header"])
1263
+ ];
1264
+ }),
1265
+ _: 1
1266
+ }, 8, ["title", "actions"])) : i(x).isLoaded ? (N(), ae(Ee, {
1267
+ key: 2,
1268
+ title: i(e)("inventory.common.import")
1269
+ }, {
1270
+ default: Z(() => [
1271
+ n("div", kn, [
1272
+ B(k, {
1273
+ name: "block",
1274
+ class: "text-gray-400",
1275
+ size: "xl"
1276
+ }),
1277
+ n("div", Rn, [
1278
+ n("div", Cn, a(i(e)("inventory.common.featureNotAvailable")), 1),
1279
+ n("div", Un, a(i(e)("inventory.common.bulkImportNotEnabled")), 1)
1280
+ ])
1281
+ ])
1282
+ ]),
1283
+ _: 1
1284
+ }, 8, ["title"])) : (N(), ae(Ee, {
1285
+ key: 1,
1286
+ title: i(e)("inventory.common.import")
1287
+ }, {
1288
+ default: Z(() => [
1289
+ n("div", In, [
1290
+ B(Y, { size: "lg" }),
1291
+ n("div", En, [
1292
+ n("div", Sn, a(i(e)("inventory.common.loading")), 1)
1293
+ ])
1294
+ ])
1295
+ ]),
1296
+ _: 1
1297
+ }, 8, ["title"]));
1298
+ };
1299
+ }
1300
+ });
1301
+ export {
1302
+ Dn as default
1303
+ };