@feedmepos/mf-inventory-portal 1.2.30 → 1.2.31-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 (78) hide show
  1. package/dist/{App-CZJre5y8.js → App-BMf3N76A.js} +19 -19
  2. package/dist/{ApprovalView-CnxHxojY.js → ApprovalView-ue3fJ7v_.js} +6 -6
  3. package/dist/{BindingsDialog-C6lCOPNs.js → BindingsDialog-ByMj3RjY.js} +8 -8
  4. package/dist/{BindingsPicker-DZtFKLQ5.js → BindingsPicker-DgSjaVrq.js} +2 -2
  5. package/dist/{BindingsTable-BmQGLuJ4.js → BindingsTable-BUu0r9Zo.js} +3 -3
  6. package/dist/{ClosingDraftView-KLtlh31f.js → ClosingDraftView-R2NPPsXD.js} +61 -62
  7. package/dist/{ClosingHistoryView-Rf1yMhMj.js → ClosingHistoryView-1W_y3JEM.js} +4 -4
  8. package/dist/ClosingTemplateView-BC9w8vZ0.js +2059 -0
  9. package/dist/{DeliveryOrderPrintPreview-UF7V005U.js → DeliveryOrderPrintPreview-zJhQH8By.js} +1 -1
  10. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BcMvEdc0.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CJ_bPMX_.js} +5 -5
  11. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CqAeF0wL.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-Cphr1J6U.js} +3 -3
  12. package/dist/{FmMultiselectDialog-BasrjBFA.js → FmMultiselectDialog-DEt2I4_c.js} +2 -2
  13. package/dist/{FmMultiselectDialog-B0aKuf2o.js → FmMultiselectDialog-DSGQitHT.js} +1 -1
  14. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-CaYJJkXz.js → FmUnitInput.vue_vue_type_script_setup_true_lang-spkm7SZK.js} +3 -3
  15. package/dist/{ImportView-DRSoz0uM.js → ImportView-ank5c4AV.js} +7 -7
  16. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-DA8SlWPy.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-DhE2M3CD.js} +1 -1
  17. package/dist/{IngredientGroupView-D5Laak2-.js → IngredientGroupView-DVT0Yyae.js} +6 -6
  18. package/dist/{IngredientsView-TG3fPQhR.js → IngredientsView-BcmPBoOb.js} +15 -15
  19. package/dist/{IntegrationView-CElpjyo7.js → IntegrationView-0JY21Fjn.js} +1607 -1592
  20. package/dist/{InventoryBindingForm-CBgxRYBd.js → InventoryBindingForm-FhDgibuy.js} +1 -1
  21. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-Ys5GBHoQ.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DL2pd-U1.js} +4 -4
  22. package/dist/{InventoryBindingSummary-OK3vNWhi.js → InventoryBindingSummary-Rj4rLIp-.js} +1 -1
  23. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-9QRntUlk.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CtqVtwbE.js} +1 -1
  24. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-Bc01NoOn.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BJZmEJ_9.js} +2 -2
  25. package/dist/{PublishView-CLMfiLjP.js → PublishView-NyqU4ogZ.js} +4 -4
  26. package/dist/{PurchaseOrderPrintPreview-Dy77yWDC.js → PurchaseOrderPrintPreview-Cua1-cfS.js} +1 -1
  27. package/dist/{ReceiveRequestView-BhD-NaHE.js → ReceiveRequestView-BQtpsAOR.js} +304 -304
  28. package/dist/{RecipeView-RWaO94w_.js → RecipeView-Dcv3Pnvu.js} +9 -9
  29. package/dist/{SingleColumnLayout.vue_vue_type_script_setup_true_lang-DY7TaxPK.js → SingleColumnLayout.vue_vue_type_script_setup_true_lang-CWZkVCAj.js} +99 -99
  30. package/dist/{StockView-D5t8OxaG.js → StockView-D2jlQ_IE.js} +16 -16
  31. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-3Asf1TGd.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang--F8e7pUI.js} +1 -1
  32. package/dist/{SupplierView-DiospFKq.js → SupplierView-CGAtUowc.js} +12 -12
  33. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-DfCHteOF.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-Cd9R8l0c.js} +3 -3
  34. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CNtvx-LA.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Dy5JfpNp.js} +1 -1
  35. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-p959Op4k.js → TransferDetails.vue_vue_type_script_setup_true_lang-BqxG1uZu.js} +15 -15
  36. package/dist/{TransferTemplateView-ePZFdZ0p.js → TransferTemplateView-DMuw4LtY.js} +16 -16
  37. package/dist/{UnitView-Banlxw7y.js → UnitView-CwlT0HpP.js} +7 -7
  38. package/dist/{WarehouseView-BL-p5hbi.js → WarehouseView-mT3A-9uq.js} +6 -6
  39. package/dist/{WastageTemplateView-B1pmSuW0.js → WastageTemplateView-C3_KtgFQ.js} +15 -15
  40. package/dist/api/netsuite.d.ts +9 -3
  41. package/dist/{app-EpEEb8EO.js → app-C2nudFnk.js} +1272 -1191
  42. package/dist/app.d.ts +21 -0
  43. package/dist/app.js +5 -5
  44. package/dist/{closing-template-zIjwO1_E.js → closing-template-fRmBNy4y.js} +1 -1
  45. package/dist/{date2-Dnc8Y81g.js → date2-ngfXp6E2.js} +1 -1
  46. package/dist/{dayjs.min-TdUgzmww.js → dayjs.min-BvcCfiWk.js} +1 -1
  47. package/dist/{decimal-C6s3GvGb.js → decimal-h7clfS02.js} +2 -2
  48. package/dist/{defineDeepModel-BSaaXVBF.js → defineDeepModel-C_n3Ytw6.js} +1 -1
  49. package/dist/{duplicate-template-Bw0H416G.js → duplicate-template-CHiQ3uHE.js} +1 -1
  50. package/dist/{feature-C95Hao53.js → feature-CrcV14lV.js} +2 -2
  51. package/dist/{format-time-from-id-DlbHo6kY.js → format-time-from-id-ljQJ36VV.js} +1 -1
  52. package/dist/{format-unit-display-QBS54q0R.js → format-unit-display-r1oynPKD.js} +10 -10
  53. package/dist/{import-export.helper-CUKCKtP7.js → import-export.helper-C5TdWJLB.js} +5 -5
  54. package/dist/{index-goD-WGVb.js → index-C0Q6KaoS.js} +3 -3
  55. package/dist/{index-CFn_9RMm.js → index-DluVXb7-.js} +1 -1
  56. package/dist/{index-S9Ak__QC.js → index-gutj1NVB.js} +1 -1
  57. package/dist/{lodash-gq8IrP4j.js → lodash-CJ0fXmvq.js} +1 -1
  58. package/dist/netsuite-Dp3KQlN9.js +4979 -0
  59. package/dist/{purchase-order-template-CBIpWdEW.js → purchase-order-template-CTICqz-0.js} +1 -1
  60. package/dist/{rules-DKklsaS1.js → rules-CWhZXxdv.js} +3 -3
  61. package/dist/{stock-BW8fen3H.js → stock-BpY8FTMC.js} +3 -3
  62. package/dist/{stock-3K93Mif9.js → stock-DHpvp37w.js} +1 -1
  63. package/dist/stores/integration/netsuite.d.ts +5 -1
  64. package/dist/{supplier-CObCSfot.js → supplier-CfiMZbRg.js} +2 -2
  65. package/dist/tsconfig.app.tsbuildinfo +1 -1
  66. package/dist/{use-ingredient-select-dialog-DwvQiaVW.js → use-ingredient-select-dialog-DrYxhoTU.js} +2 -2
  67. package/dist/{use-inventory-binding-dialog-CuLEHLDM.js → use-inventory-binding-dialog-BAYX4xEg.js} +2 -2
  68. package/dist/{use-template-enabled-locations-2-DkUJeppb.js → use-template-enabled-locations-2-DbNAe5rC.js} +2 -2
  69. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +1 -0
  70. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +12 -0
  71. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +12 -0
  72. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +6 -2
  73. package/dist/{vue-i18n-CUznvVzc.js → vue-i18n-BNE50uOV.js} +424 -424
  74. package/dist/{xlsx-bT1p3YVR.js → xlsx-BSJt4rqr.js} +398 -398
  75. package/dist/{xlsx.util-Cr9DpDFb.js → xlsx.util-DEF923iN.js} +1 -1
  76. package/package.json +4 -4
  77. package/dist/ClosingTemplateView-C_IiKnGx.js +0 -2019
  78. package/dist/netsuite-CnhAKyAO.js +0 -4316
@@ -0,0 +1,2059 @@
1
+ import { ref as R, h as P, defineComponent as K, resolveComponent as E, openBlock as $, createElementBlock as D, createElementVNode as _, normalizeClass as q, createTextVNode as ae, toDisplayString as I, unref as u, createCommentVNode as O, createVNode as C, withCtx as V, Fragment as j, renderList as Z, computed as L, watch as Pe, createSlots as Ee, createBlock as N, isRef as Ye, normalizeStyle as Ge, Teleport as Ke, normalizeProps as We, guardReactiveProps as qe, mergeProps as Je } from "vue";
2
+ import { u as Xe, _ as Qe } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-CWZkVCAj.js";
3
+ import { useI18n as W, useCoreStore as de } from "@feedmepos/mf-common";
4
+ import { useDialog as pe, useDialogChild as Ze, useSnackbar as ce, FmButtonVariant as oe, components as Y, FmAdvancedSort as et, useProxiedModel as tt, useBreakpoints as nt } from "@feedmepos/ui-library";
5
+ import { defineStore as Ve, storeToRefs as Ue } from "pinia";
6
+ import { F as G } from "./form-mode.enum-BKiNVH6A.js";
7
+ import { a as me } from "./closing-template-fRmBNy4y.js";
8
+ import { u as fe, c as Ne, a as ve, n as ot } from "./app-C2nudFnk.js";
9
+ import { t as re, a as ge, d as ye, s as Le, r as st } from "./xlsx.util-DEF923iN.js";
10
+ import { F as lt } from "./FmDroppableField-J0xUsOTV.js";
11
+ import { f as Be, a as le } from "./date2-ngfXp6E2.js";
12
+ import { D as se, R as z } from "./row-action.enum-BcW_L_nE.js";
13
+ import { c as at, F as X, _ as ze } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js";
14
+ import { f as rt } from "./format-time-from-id-ljQJ36VV.js";
15
+ import { _ as it } from "./TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Dy5JfpNp.js";
16
+ import { u as ct } from "./netsuite-Dp3KQlN9.js";
17
+ import { u as mt } from "./duplicate-template-CHiQ3uHE.js";
18
+ import { _ as ut } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-Cphr1J6U.js";
19
+ import { R as dt, A as pt } from "./rules-CWhZXxdv.js";
20
+ import { u as ft } from "./use-ingredient-select-dialog-DrYxhoTU.js";
21
+ import { d as vt } from "./defineDeepModel-C_n3Ytw6.js";
22
+ import { u as gt } from "./use-template-enabled-locations-2-DbNAe5rC.js";
23
+ import { _ as yt } from "./SystemTrailDialog.vue_vue_type_script_setup_true_lang-Cd9R8l0c.js";
24
+ import { _ as ht } from "./_plugin-vue_export-helper-CHgC5LLL.js";
25
+ const ue = Ve(
26
+ "closingTemplateTable",
27
+ function() {
28
+ const { t: r } = W(), l = pe(), d = R({}), t = ie(), n = R({}), f = R(new Array()), b = R(!1), c = fe(), a = me();
29
+ function g(s) {
30
+ const v = {
31
+ title: s.name,
32
+ doc: s,
33
+ controller: {
34
+ publishAll: async () => {
35
+ var e;
36
+ const T = await a.publishSingleDoc(
37
+ s._id,
38
+ (e = s.locations) == null ? void 0 : e.map((k) => k.dbName)
39
+ );
40
+ return d.value = T.publishedRevByLocation || {}, d.value;
41
+ },
42
+ publishAtLocation: async (T) => {
43
+ const e = await a.publishSingleDoc(s._id, [T.dbName]);
44
+ return d.value = e.publishedRevByLocation || {}, d.value;
45
+ }
46
+ },
47
+ initialPublishedRev: d.value,
48
+ locations: c.locations,
49
+ enabledLocations: s.locations
50
+ };
51
+ l.open({
52
+ title: "Publish template",
53
+ contentComponent: it,
54
+ contentComponentProps: v,
55
+ closeButton: !0,
56
+ primaryActions: {
57
+ text: r("common.close"),
58
+ close: !0,
59
+ variant: "tertiary"
60
+ }
61
+ });
62
+ }
63
+ async function i() {
64
+ if (f.value = [], !!c._currentLocation) {
65
+ b.value = !0;
66
+ try {
67
+ const [s, v, T] = await Promise.all([
68
+ a.readTemplates(),
69
+ a.getRecentPublishingJob(),
70
+ a.getRecentPublishInfo()
71
+ ]).delayed(1e3);
72
+ f.value = s, n.value = v, d.value = T.publishedRevByLocation || {};
73
+ } catch (s) {
74
+ console.log("Something went wrong when fetching templates:", s);
75
+ } finally {
76
+ b.value = !1;
77
+ }
78
+ }
79
+ }
80
+ async function h(s) {
81
+ if (!f.value.find((v) => v._id) && c._currentLocation) {
82
+ b.value = !0;
83
+ try {
84
+ const [v] = await Promise.all([
85
+ a.getTemplate(s),
86
+ new Promise((T) => setTimeout(T, 1e3))
87
+ ]);
88
+ f.value = [v];
89
+ } catch (v) {
90
+ console.log("Something went wrong when fetching templates:", v);
91
+ } finally {
92
+ b.value = !1;
93
+ }
94
+ }
95
+ }
96
+ function w(s, v) {
97
+ switch (v = Ne(v), s) {
98
+ case z.Details:
99
+ return t.viewTemplate(v);
100
+ case z.Edit:
101
+ return t.updateTemplate(v);
102
+ case z.Delete:
103
+ return t.deleteTemplate(v, b, i);
104
+ case z.Publish:
105
+ return g(v);
106
+ case z.Duplicate:
107
+ return t.duplicateTemplate(v, b, i);
108
+ }
109
+ }
110
+ return {
111
+ columnDefs: [
112
+ {
113
+ id: "_id",
114
+ accessorKey: "_id",
115
+ header: () => r("inventory.closing.table.createdAt"),
116
+ cell(s) {
117
+ return rt(`${s.getValue()}`);
118
+ },
119
+ enableSorting: !0
120
+ },
121
+ {
122
+ id: "name",
123
+ accessorKey: "name",
124
+ header: () => r("inventory.closing.table.name"),
125
+ enableSorting: !0,
126
+ size: 200
127
+ },
128
+ {
129
+ id: "noOfItems",
130
+ accessorKey: "items.length",
131
+ header: () => r("inventory.closing.table.noOfItems"),
132
+ enableSorting: !1,
133
+ meta: {
134
+ width: "10rem",
135
+ textAlign: "right"
136
+ }
137
+ },
138
+ {
139
+ id: "enabledLocations",
140
+ accessorKey: "locations.length",
141
+ header: () => r("inventory.closing.table.enabledOutlets"),
142
+ cell(s) {
143
+ var T;
144
+ const v = (T = s.row.original.locations) == null ? void 0 : T.length;
145
+ return v ? `${v}` : "All";
146
+ },
147
+ enableSorting: !1,
148
+ meta: {
149
+ width: "10rem",
150
+ textAlign: "right"
151
+ }
152
+ },
153
+ {
154
+ id: "ref",
155
+ accessorKey: "ref",
156
+ header: () => r("inventory.closing.table.reference"),
157
+ enableSorting: !1,
158
+ size: "auto"
159
+ },
160
+ {
161
+ id: "status",
162
+ header: () => r("inventory.adjustment.template.table.status"),
163
+ enableSorting: !1,
164
+ cell(s) {
165
+ const v = s.row.original, T = v._rev, e = s.row.original.locations || c.locations, F = e.filter((p) => !!(d.value[p.dbName] || []).find((x) => x._id === v._id && x._rev === T)).length === e.length;
166
+ return P(
167
+ "div",
168
+ {
169
+ class: "flex items-center gap-8"
170
+ },
171
+ P(
172
+ "div",
173
+ {
174
+ class: [
175
+ "fm-status-badge",
176
+ F ? "fm-status-badge-success-secondary" : "fm-status-badge-info-secondary"
177
+ ]
178
+ },
179
+ F ? "Published" : "Unpublished"
180
+ )
181
+ );
182
+ }
183
+ },
184
+ {
185
+ id: "action",
186
+ cell(s) {
187
+ const v = s.row.original, T = [
188
+ se[z.Edit],
189
+ se[z.Duplicate],
190
+ se[z.Delete],
191
+ se[z.Publish]
192
+ ];
193
+ return at(T, (e) => w(e, v));
194
+ },
195
+ enableSorting: !1,
196
+ size: 40,
197
+ meta: {
198
+ cellClass: "",
199
+ headerClass: ""
200
+ }
201
+ }
202
+ ],
203
+ recentPublish: n,
204
+ templates: f,
205
+ loading: b,
206
+ fetchTemplates: i,
207
+ loadTemplate: h
208
+ };
209
+ }
210
+ );
211
+ var he = /* @__PURE__ */ ((m) => (m.Ingredients = "Ingredients", m))(he || {});
212
+ function He(m) {
213
+ const r = m.sku, l = new Set(m.disabledMeasurements);
214
+ return [
215
+ {
216
+ code: r.code,
217
+ name: r.name,
218
+ unit: r.unit.abbrev,
219
+ enabled: !l.has(r.unit._id)
220
+ },
221
+ ...r.unit.measurements.map((n) => ({
222
+ unit: n.abbrev,
223
+ enabled: !l.has(n.id)
224
+ }))
225
+ ];
226
+ }
227
+ function Oe() {
228
+ return [
229
+ {
230
+ id: "code",
231
+ name: "Code"
232
+ },
233
+ {
234
+ id: "name",
235
+ name: "Name"
236
+ },
237
+ {
238
+ id: "unit",
239
+ name: "Unit"
240
+ },
241
+ {
242
+ id: "enabled",
243
+ name: "Enabled"
244
+ }
245
+ ];
246
+ }
247
+ function bt(m) {
248
+ var b;
249
+ const l = de().currentBusiness.value, t = (b = m.map((c) => {
250
+ var y;
251
+ const a = c.items.flatMap(He), g = Oe(), i = [
252
+ ["Template ID", c._id],
253
+ ["Template name", c.name],
254
+ ["Business name", l == null ? void 0 : l.name],
255
+ ["Business ID", l == null ? void 0 : l._id],
256
+ ["Menu version", l == null ? void 0 : l.menuVersion],
257
+ [
258
+ "Locations",
259
+ ...(y = c.locations) != null && y.length ? c.locations.map((s) => `${s.name} (${s.dbName})`) : ["All"]
260
+ ],
261
+ ["Reference", c.ref ?? ""],
262
+ [],
263
+ g.map((s) => s.name),
264
+ ...a.map((s) => g.map((v) => s[v.id]))
265
+ ], h = g.map((s) => `system:${s.id}`), w = re(i, h);
266
+ return { name: c.name, sheet: w };
267
+ }).reduce(
268
+ (c, a) => {
269
+ var i;
270
+ const g = a.name.slice(0, 12);
271
+ return (i = c.sheetOccurence)[g] ?? (i[g] = 0), c.sheetOccurence[g] += 1, c.sheets[`${g} (${c.sheetOccurence[g]})`] = a.sheet, c;
272
+ },
273
+ {
274
+ sheets: {},
275
+ sheetOccurence: {}
276
+ }
277
+ )) == null ? void 0 : b.sheets, n = `${l == null ? void 0 : l.name} closing templates (${Be(/* @__PURE__ */ new Date())}).xlsx`, f = ge(t);
278
+ return ye(f, n), n;
279
+ }
280
+ function _t(m) {
281
+ de().currentBusiness.value;
282
+ const l = 3, d = (i) => {
283
+ const h = [], w = i.sku, y = new Set(i.disabledMeasurements || []);
284
+ y.has(w.unit._id) || h.push(w.unit.abbrev);
285
+ for (const s of w.unit.measurements) {
286
+ if (h.length >= l) break;
287
+ y.has(s.id) || h.push(s.abbrev);
288
+ }
289
+ return h;
290
+ }, t = ["#", "Code", "Name", "UOM"], n = [
291
+ ["Template:", m.name],
292
+ ["Reference:", m.ref ?? ""],
293
+ [],
294
+ t,
295
+ ...m.items.map((i, h) => {
296
+ const w = d(i);
297
+ return [
298
+ h + 1,
299
+ // Index starting from 1
300
+ i.sku.code,
301
+ i.sku.name,
302
+ // Add UOM columns (up to MAX_UOM_COLUMNS)
303
+ ...Array(l).fill("").map(
304
+ (y, s) => w[s] ? `_____ ${w[s]}` : ""
305
+ )
306
+ ];
307
+ })
308
+ ], f = re(n, t);
309
+ if (f["!ref"]) {
310
+ const i = {
311
+ top: { style: "thin", color: { rgb: "000000" } },
312
+ bottom: { style: "thin", color: { rgb: "000000" } },
313
+ left: { style: "thin", color: { rgb: "000000" } },
314
+ right: { style: "thin", color: { rgb: "000000" } }
315
+ }, h = 4, w = h + m.items.length, y = t.map((s, v) => String.fromCharCode(65 + v));
316
+ for (let s = h; s <= w; s++)
317
+ y.forEach((v) => {
318
+ const T = `${v}${s}`;
319
+ f[T] || (f[T] = { t: "s", v: "" }), f[T].s = {
320
+ border: i
321
+ };
322
+ });
323
+ }
324
+ f["!cols"] = [
325
+ { wch: 5 },
326
+ // Index column - narrow
327
+ { wch: 15 },
328
+ // Code column
329
+ { wch: 30 },
330
+ // Name column - adjusted for more columns
331
+ ...Array.from({ length: l }, () => ({ wch: 15 }))
332
+ // UOM columns
333
+ ], f["!margins"] = {
334
+ left: 0.7,
335
+ right: 0.7,
336
+ top: 0.75,
337
+ bottom: 0.75,
338
+ header: 0.3,
339
+ footer: 0.3
340
+ };
341
+ const c = m.name.slice(0, 31), a = ge({ [c]: f }), g = `${m.name} - Closing Template (${Be(/* @__PURE__ */ new Date())}).xlsx`;
342
+ return ye(a, g), g;
343
+ }
344
+ function xt() {
345
+ const m = de(), r = ve(), l = ct(), d = He({
346
+ sku: {
347
+ unit: {
348
+ _id: "",
349
+ name: "Unit",
350
+ abbrev: "Unit",
351
+ precision: 0,
352
+ measurements: []
353
+ },
354
+ code: "ING001",
355
+ _id: "",
356
+ name: "Sugar"
357
+ }
358
+ })[0], t = m.currentBusiness.value, n = Oe(), f = [
359
+ ["Template ID (leave empty to create new)", ""],
360
+ ["Template Name", "New template"],
361
+ ["Business name", t == null ? void 0 : t.name],
362
+ ["Business ID", t == null ? void 0 : t._id],
363
+ ["Menu version", t == null ? void 0 : t.menuVersion],
364
+ [
365
+ "Location codes (leave empty to enable all)",
366
+ "Example outlet (restaurant_xxx)",
367
+ "Example outlet 2 (restaurant_xxx)"
368
+ ],
369
+ ["Reference:"],
370
+ [],
371
+ n.map((y) => y.name),
372
+ n.map((y) => d[y.id])
373
+ ], b = n.map((y) => `system:${y.id}`), c = re(f, b), a = l.isEnabled ? l.state.setting.childItems ?? [] : [], g = a.reduce(
374
+ (y, s) => {
375
+ var F, p;
376
+ const v = (F = l.netSuiteItemIdToSkuId.get(s.parentNetSuiteId)) == null ? void 0 : F[0], T = (p = l.netSuiteMeasurementIdToMeasurementId.get(
377
+ s.unitOfMeasureId
378
+ )) == null ? void 0 : p[0];
379
+ if (!s.externalId)
380
+ return y;
381
+ if (!v)
382
+ return console.error(`Item ${s.externalId} cannot be mapped to parent FdoInventorySku.`, s), y;
383
+ const e = r.skuById[v], k = e.unit.measurements.find((o) => o.id === T);
384
+ return k ? (y[s.externalId] = {
385
+ sku: e,
386
+ measurement: k
387
+ }, y) : (console.error(
388
+ `Item ${s.externalId} found parent FdoInventorySku of ${e.code} ${e.name} but the measurement of netsuite id ${s.unitOfMeasureId} cannot be found.`,
389
+ s
390
+ ), y);
391
+ },
392
+ {}
393
+ ), i = re(
394
+ [
395
+ ...r.skus.flatMap((y) => [
396
+ [y.code, y.name, y.unit.abbrev, !0],
397
+ ...y.unit.measurements.map((v) => [
398
+ "",
399
+ "",
400
+ v.abbrev,
401
+ !v.abbrev.toLocaleLowerCase("en-us").includes("inactive")
402
+ ])
403
+ ]),
404
+ ...Object.entries(g).map(([y, { sku: s, measurement: v }]) => [
405
+ s.code,
406
+ s.name,
407
+ v.abbrev,
408
+ !v.abbrev.toLocaleLowerCase("en-us").includes("inactive"),
409
+ y
410
+ ])
411
+ ],
412
+ [
413
+ "Code",
414
+ "Name",
415
+ "Units",
416
+ "Enabled (true/false)",
417
+ ...a.length ? ["Netsuite Parent"] : []
418
+ ]
419
+ ), h = ge({
420
+ Template: c,
421
+ Ingredients: i
422
+ }), w = `${t == null ? void 0 : t.name} transfer templates import.xlsx`;
423
+ return ye(h, w), w;
424
+ }
425
+ function wt(m) {
426
+ if (!m.length || `${m[0]}`.toLocaleLowerCase() === "all")
427
+ return [];
428
+ const r = /(.*) \(((warehouse_|restaurant_).{24,})\)/, d = fe().locationByDbName;
429
+ return m.map((t) => {
430
+ const n = new Array(), f = t.trim(), b = r.exec(f);
431
+ if (!b)
432
+ return n.push(`Enabled location value of ${f} cannot be read.`), {
433
+ errors: n
434
+ };
435
+ const c = b[1], a = b[2], g = d[a];
436
+ return g ? (c !== g.name && n.push(
437
+ `Location id ${a} has non-matching name. Found ${c} but expected ${g.name}`
438
+ ), {
439
+ errors: n,
440
+ location: g
441
+ }) : (n.push(`Location (${c}) of id ${a} is not found.`), {
442
+ errors: n
443
+ });
444
+ });
445
+ }
446
+ function kt(m) {
447
+ const [
448
+ r,
449
+ l,
450
+ d,
451
+ t,
452
+ n,
453
+ f,
454
+ b,
455
+ c
456
+ ] = Le(m);
457
+ return {
458
+ id: `${l[1] ?? ""}`.trim(),
459
+ name: `${d[1] ?? ""}`.trim(),
460
+ locations: b.slice(1).map((a) => `${a}`.trim()).filter((a) => a),
461
+ reference: `${c[1] ?? ""}`.trim()
462
+ };
463
+ }
464
+ function Tt(m) {
465
+ const [
466
+ r,
467
+ l,
468
+ d,
469
+ t,
470
+ n,
471
+ f,
472
+ b,
473
+ c,
474
+ a,
475
+ g,
476
+ ...i
477
+ ] = Le(m);
478
+ if (!r || !r.length || r.some((v) => v.length && !v.startsWith("system:")))
479
+ throw new Error("Missing meta header. Excel file does not come from the template.");
480
+ const h = r.map((v) => v.split(":")[1]), y = ["code", "name", "unit", "enabled"].filter((v) => !h.includes(v));
481
+ if (y.length)
482
+ throw new Error(
483
+ `Missing meta headers (${y.join()}). Excel file does not come from the template.`
484
+ );
485
+ return i.map((v, T) => {
486
+ const e = {};
487
+ for (const k in h) {
488
+ const F = h[k];
489
+ Object.assign(e, { [F]: v[k] });
490
+ }
491
+ return {
492
+ index: T,
493
+ data: e
494
+ };
495
+ });
496
+ }
497
+ function $t(m) {
498
+ return m.reduce(
499
+ (r, l) => {
500
+ var n;
501
+ const d = l.data, t = l.index;
502
+ return d.unit && (d.code ? r.result.push({ parent: l, children: [] }) : r.result.length ? (n = r.result.at(-1)) == null || n.children.push(l) : r.errors.push(`Cannot find parent for row ${t + 9}`)), r;
503
+ },
504
+ { result: new Array(), errors: new Array() }
505
+ );
506
+ }
507
+ function Ct(m) {
508
+ const r = m.parent.data, l = new Array(), t = ve().skuByCode[r.code ?? ""];
509
+ if (!t)
510
+ return l.push(`Cannot find ingredient of code ${r.code} ${r.name}`), { errors: l };
511
+ const n = {
512
+ sku: t
513
+ }, f = /* @__PURE__ */ new Set([t.unit._id, ...t.unit.measurements.map((c) => c.id)]), b = t.unit.measurements.find((c) => c.abbrev === r.unit);
514
+ r.unit !== t.unit.abbrev && !b ? l.push(
515
+ `Cannot find measurement unit of ${r.unit} for (${r.code}) ${r.name}.`
516
+ ) : (r.enabled === !0 || `${r.enabled}`.toLocaleLowerCase() === "true") && f.delete(t.unit._id);
517
+ for (const c of m.children) {
518
+ const a = c.data, g = a.unit === t.unit.abbrev ? t.unit : void 0, i = t.unit.measurements.find((h) => h.abbrev === a.unit);
519
+ if (!i && !g) {
520
+ l.push(
521
+ `Cannot find measurement unit of ${a.unit} for (${r.code}) ${r.name}.`
522
+ );
523
+ continue;
524
+ }
525
+ (a.enabled === !0 || `${a.enabled}`.toLocaleLowerCase() === "true") && f.delete((i == null ? void 0 : i.id) ?? (g == null ? void 0 : g._id) ?? "");
526
+ }
527
+ return f.has(t.unit._id) && n.sku.unit.measurements.every((c) => f.has(c.id)) && l.push(`Ingredient ${t.code} - ${t.name} must have at least one unit enabled.`), n.disabledMeasurements = [...f], { errors: l, templateItem: n };
528
+ }
529
+ function It(m) {
530
+ const r = m.SheetNames.filter(
531
+ (n) => !Object.values(he).map(String).includes(n)
532
+ ), d = ue().templates, t = ot(d, "_id");
533
+ try {
534
+ return r.reduce(
535
+ (n, f) => {
536
+ const b = new Array(), c = m.Sheets[f], a = kt(c), g = wt(a.locations), i = g.filter((e) => e.location).map((e) => e.location);
537
+ b.push(...g.flatMap((e) => e.errors));
538
+ const h = Tt(c).filter(
539
+ (e) => e.data.code || e.data.unit
540
+ ), w = $t(h);
541
+ b.push(...w.errors);
542
+ const y = w.result.map(
543
+ (e) => Ct(e)
544
+ );
545
+ b.push(...y.flatMap((e) => e.errors));
546
+ const s = y.filter((e) => e.templateItem).map((e) => e.templateItem);
547
+ if (a.id) {
548
+ const e = t[a.id];
549
+ if (!e) {
550
+ const F = {
551
+ _id: a.id,
552
+ _rev: "",
553
+ name: a.name || `(unnamed from sheet ${f || "<unnamed sheet>"})`,
554
+ items: []
555
+ };
556
+ return b.push(`Template ID ${a.id} is not found.`), n.importUpdateResult.push({
557
+ type: "update",
558
+ original: F,
559
+ template: F,
560
+ excelSheetName: f,
561
+ errors: b
562
+ }), n;
563
+ }
564
+ const k = {
565
+ type: "update",
566
+ original: e,
567
+ template: {
568
+ ...e,
569
+ name: a.name,
570
+ locations: i.length ? i : null,
571
+ ref: a.reference,
572
+ items: s
573
+ },
574
+ excelSheetName: f,
575
+ errors: b
576
+ };
577
+ return n.importUpdateResult.push(k), n;
578
+ }
579
+ const T = {
580
+ type: "create",
581
+ template: {
582
+ name: a.name,
583
+ locations: i.length ? i : null,
584
+ ref: a.reference,
585
+ items: s
586
+ },
587
+ excelSheetName: f,
588
+ errors: b
589
+ };
590
+ return n.importCreateResult.push(T), n;
591
+ },
592
+ {
593
+ invalidExcel: !1,
594
+ importCreateResult: new Array(),
595
+ importUpdateResult: new Array()
596
+ }
597
+ );
598
+ } catch (n) {
599
+ return {
600
+ invalidExcel: !0,
601
+ invalidExcelMessage: (n == null ? void 0 : n.message) ?? "Invalid excel",
602
+ importCreateResult: [],
603
+ importUpdateResult: []
604
+ };
605
+ }
606
+ }
607
+ const St = { class: "flex items-center gap-12 pl-8" }, Dt = { class: "flex flex-col" }, Mt = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, Ft = {
608
+ key: 0,
609
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
610
+ }, Rt = { key: 0 }, Ae = /* @__PURE__ */ K({
611
+ __name: "ClosingTemplateImportItem",
612
+ props: {
613
+ type: {},
614
+ name: {},
615
+ locations: {},
616
+ items: {},
617
+ errors: {}
618
+ },
619
+ setup(m) {
620
+ const { t: r } = W();
621
+ return (l, d) => {
622
+ var f, b, c;
623
+ const t = E("FmIcon"), n = E("FmTooltip");
624
+ return $(), D("div", St, [
625
+ d[0] || (d[0] = _("div", null, "•", -1)),
626
+ _("div", Dt, [
627
+ _("div", Mt, [
628
+ _("div", {
629
+ class: q({
630
+ "text-fm-color-system-error-300": l.errors.length
631
+ })
632
+ }, [
633
+ ae(I(l.name) + " ", 1),
634
+ l.type === "create" ? ($(), D("span", Ft, "(" + I(u(r)("inventory.closing.template.import.new")) + ")", 1)) : O("", !0)
635
+ ], 2),
636
+ l.errors.length ? ($(), D("div", Rt, [
637
+ C(n, { "z-index": 50 }, {
638
+ content: V(() => [
639
+ _("ol", null, [
640
+ ($(!0), D(j, null, Z(l.errors, (a, g) => ($(), D("li", { key: g }, I(a), 1))), 128))
641
+ ])
642
+ ]),
643
+ default: V(() => [
644
+ C(t, {
645
+ name: "error",
646
+ size: "sm",
647
+ color: "system-error-300"
648
+ })
649
+ ]),
650
+ _: 1
651
+ })
652
+ ])) : O("", !0)
653
+ ]),
654
+ _("div", {
655
+ class: q([
656
+ "fm-typo-en-body-sm-400",
657
+ {
658
+ "text-fm-color-system-error-200": l.errors.length,
659
+ "text-fm-color-typo-secondary": !l.errors.length
660
+ }
661
+ ])
662
+ }, I((f = l.locations) != null && f.length ? u(r)("inventory.closing.template.import.nLocations", { count: (b = l.locations) == null ? void 0 : b.length }) : u(r)("inventory.closing.template.import.allLocations")) + ", " + I(u(r)("inventory.closing.template.import.nItems", { count: (c = l.items) == null ? void 0 : c.length })), 3)
663
+ ])
664
+ ]);
665
+ };
666
+ }
667
+ }), At = { class: "flex flex-col gap-24" }, Pt = { class: "fm-typo-en-body-md-400" }, Et = {
668
+ key: 0,
669
+ class: "flex items-center gap-8"
670
+ }, Vt = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ut = { class: "flex flex-col gap-8" }, Nt = { class: "line-clamp-2 text-ellipsis break-all" }, Lt = {
671
+ key: 2,
672
+ class: "shrink-0"
673
+ }, Bt = {
674
+ key: 0,
675
+ class: "flex flex-col"
676
+ }, zt = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, Ht = {
677
+ key: 0,
678
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
679
+ }, Ot = { class: "fm-typo-en-body-lg-600" }, jt = /* @__PURE__ */ K({
680
+ __name: "ClosingTemplateImport",
681
+ setup(m) {
682
+ const r = R(null), l = Ze(), d = ce(), t = R(!1), n = R(!1), f = R(new Array()), b = R([]), c = R([]), a = L(
683
+ () => !!f.value.length || b.value.some((w) => w.errors.length) || c.value.some((w) => w.errors.length)
684
+ ), g = L(
685
+ () => !!b.value.length || !!c.value.length
686
+ ), { t: i } = W();
687
+ async function h(w) {
688
+ f.value = [], b.value = [], c.value = [];
689
+ try {
690
+ t.value = !0;
691
+ const [y] = await Promise.all([
692
+ st(w),
693
+ // fake buffer
694
+ new Promise((e) => setTimeout(e, 1e3))
695
+ ]);
696
+ if (!y.SheetNames.filter(
697
+ (e) => !Object.values(he).map(String).includes(e)
698
+ ).find((e) => e)) {
699
+ f.value.push(i("inventory.ingredient.import.fileError.noSheet"));
700
+ return;
701
+ }
702
+ const T = It(y);
703
+ if (T.invalidExcel) {
704
+ f.value.push(
705
+ T.invalidExcelMessage ?? i("inventory.ingredient.import.fileError.invalidExcel")
706
+ );
707
+ return;
708
+ }
709
+ if (b.value = T.importCreateResult, c.value = T.importUpdateResult, !b.value.length && !c.value.length) {
710
+ f.value.push(i("inventory.ingredient.import.fileError.noData"));
711
+ return;
712
+ }
713
+ l.emitData(T);
714
+ } catch (y) {
715
+ d.open({
716
+ title: i("inventory.ingredient.import.fileError.unableToRead"),
717
+ message: y == null ? void 0 : y.message,
718
+ type: "error"
719
+ }), console.error("Error in reading file", y);
720
+ } finally {
721
+ f.value.length && d.open({
722
+ title: i("inventory.ingredient.import.fileError.invalidExcel"),
723
+ type: "error"
724
+ }), t.value = !1;
725
+ }
726
+ }
727
+ return Pe(r, (w) => {
728
+ w && h(w);
729
+ }), (w, y) => {
730
+ const s = E("FmCircularProgress"), v = E("FmIcon"), T = E("FmButton");
731
+ return $(), D("div", At, [
732
+ _("div", Pt, I(u(i)("inventory.closing.template.import.message")), 1),
733
+ n.value ? ($(), D("div", Et, [
734
+ _("div", null, [
735
+ C(s, {
736
+ size: "md",
737
+ color: "neutral-gray-200"
738
+ })
739
+ ]),
740
+ _("div", Vt, I(u(i)("inventory.formField.loading")), 1)
741
+ ])) : ($(), D(j, { key: 1 }, [
742
+ C(lt, {
743
+ class: q({
744
+ "w-full": !0,
745
+ "h-[200px]": !r.value
746
+ }),
747
+ accept: ".xlsx",
748
+ onFileUpload: y[0] || (y[0] = (e) => r.value = e),
749
+ label: u(i)("inventory.ingredient.import.uploadTemplate"),
750
+ "button-label": u(i)("inventory.ingredient.import.selectFile")
751
+ }, Ee({ _: 2 }, [
752
+ r.value ? {
753
+ name: "default",
754
+ fn: V(({ openFileDialog: e }) => [
755
+ _("div", Ut, [
756
+ _("div", {
757
+ class: q([
758
+ "fm-corner-radius-md p-16 flex items-center gap-16",
759
+ {
760
+ "border border-fm-color-neutral-gray-100": t.value,
761
+ "border border-fm-color-neutral-gray-200": !t.value && !a.value,
762
+ "border border-fm-color-system-error-200": a.value
763
+ }
764
+ ])
765
+ }, [
766
+ t.value ? ($(), N(s, {
767
+ key: 0,
768
+ size: "md",
769
+ color: "neutral-gray-200"
770
+ })) : ($(), N(v, {
771
+ key: 1,
772
+ name: a.value ? "error" : "attach_file",
773
+ outline: "",
774
+ color: a.value ? "system-error-300" : void 0
775
+ }, null, 8, ["name", "color"])),
776
+ _("div", {
777
+ class: q([
778
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
779
+ {
780
+ "text-fm-color-typo-disabled": t.value,
781
+ "text-fm-color-typo-primary": !t.value
782
+ }
783
+ ])
784
+ }, [
785
+ _("div", Nt, I(r.value.name), 1)
786
+ ], 2),
787
+ t.value ? O("", !0) : ($(), D("div", Lt, [
788
+ C(T, {
789
+ label: u(i)("inventory.ingredient.import.replaceFile"),
790
+ variant: a.value ? "destructive" : "secondary",
791
+ "prepend-icon": a.value ? void 0 : "autorenew",
792
+ onClick: e
793
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
794
+ ]))
795
+ ], 2),
796
+ f.value.length ? ($(), D("div", Bt, [
797
+ ($(!0), D(j, null, Z(f.value, (k, F) => ($(), D("div", {
798
+ key: F,
799
+ class: "flex gap-8 items-center"
800
+ }, [
801
+ C(v, {
802
+ name: "error",
803
+ size: "sm",
804
+ color: "system-error-300"
805
+ }),
806
+ _("div", zt, I(k), 1)
807
+ ]))), 128))
808
+ ])) : O("", !0)
809
+ ])
810
+ ]),
811
+ key: "0"
812
+ } : void 0
813
+ ]), 1032, ["class", "label", "button-label"]),
814
+ g.value ? ($(), D("div", Ht, [
815
+ _("div", Ot, I(u(i)("inventory.ingredient.import.summary")), 1),
816
+ ($(!0), D(j, null, Z(b.value, (e, k) => ($(), N(Ae, {
817
+ key: k,
818
+ name: e.template.name,
819
+ locations: e.template.locations,
820
+ items: e.template.items,
821
+ errors: e.errors,
822
+ type: "create"
823
+ }, null, 8, ["name", "locations", "items", "errors"]))), 128)),
824
+ ($(!0), D(j, null, Z(c.value, (e) => ($(), N(Ae, {
825
+ key: e.template._id,
826
+ name: e.template.name,
827
+ locations: e.template.locations,
828
+ items: e.template.items,
829
+ errors: e.errors,
830
+ type: "update"
831
+ }, null, 8, ["name", "locations", "items", "errors"]))), 128))
832
+ ])) : O("", !0)
833
+ ], 64))
834
+ ]);
835
+ };
836
+ }
837
+ }), ie = Ve("closingTemplateActions", () => {
838
+ const { t: m } = W(), r = pe(), l = ce(), d = me(), t = mt(), n = ue(), { loading: f } = Ue(n), b = R({});
839
+ function c() {
840
+ b.value = {
841
+ mode: G.CREATE,
842
+ show: !0,
843
+ "onUpdate:show"(e) {
844
+ b.value.show = e;
845
+ }
846
+ };
847
+ }
848
+ function a(e) {
849
+ b.value = {
850
+ mode: G.UPDATE,
851
+ modelValue: e,
852
+ show: !0,
853
+ "onUpdate:show"(k) {
854
+ b.value.show = k;
855
+ }
856
+ };
857
+ }
858
+ function g(e, k, F) {
859
+ r.open({
860
+ title: `Confirm deleting template ${e.name}?`,
861
+ message: "Deleted template can no longer be retrieved",
862
+ primaryActions: {
863
+ text: "Delete",
864
+ variant: oe.Destructive,
865
+ close: !0
866
+ },
867
+ secondaryActions: {
868
+ text: "Cancel",
869
+ variant: oe.Plain,
870
+ close: !0
871
+ }
872
+ }).onPrimary(async () => {
873
+ l.open({
874
+ title: `Deleting ${e.name}`,
875
+ type: "info"
876
+ });
877
+ try {
878
+ k.value = !0;
879
+ const [p] = await Promise.allSettled([
880
+ d.deleteTemplate(e),
881
+ new Promise((o) => setTimeout(o, 1e3))
882
+ ]);
883
+ if (p.status === "rejected") throw p.reason;
884
+ l.open({
885
+ title: `Deleted ${e.name}`,
886
+ type: "success"
887
+ });
888
+ } catch (p) {
889
+ l.open({
890
+ title: `Unable to delete ${e.name}`,
891
+ message: `See error from server: ${p}`,
892
+ type: "error"
893
+ }), console.error("error on deleting closing template", p);
894
+ } finally {
895
+ k.value = !1, F();
896
+ }
897
+ });
898
+ }
899
+ function i(e, k, F) {
900
+ let p;
901
+ r.open({
902
+ title: `Confirm duplicating template "${e.name}"?`,
903
+ message: "Duplicated template can be edited after creation",
904
+ primaryActions: {
905
+ text: "Duplicate",
906
+ variant: oe.Destructive,
907
+ close: !0
908
+ },
909
+ secondaryActions: {
910
+ text: "Cancel",
911
+ variant: oe.Plain,
912
+ close: !0
913
+ },
914
+ contentComponent: K({
915
+ props: ["modelValue"],
916
+ emits: ["update:modelValue"],
917
+ setup(o) {
918
+ return () => P(Y.FmTextField, {
919
+ modelValue: o.modelValue,
920
+ "onUpdate:modelValue": (x) => p = x,
921
+ label: "New Template Name",
922
+ size: "md",
923
+ variant: "primary"
924
+ });
925
+ }
926
+ })
927
+ }).onPrimary(async () => {
928
+ l.open({
929
+ title: `Duplicating "${e.name}"`,
930
+ type: "info"
931
+ });
932
+ try {
933
+ k.value = !0;
934
+ const [o] = await Promise.allSettled([
935
+ t.duplicateClosingTemplate(e._id, p),
936
+ new Promise((x) => setTimeout(x, 1e3))
937
+ ]);
938
+ if (o.status === "rejected") throw o.reason;
939
+ l.open({
940
+ title: `Duplicated "${e.name}"`,
941
+ type: "success"
942
+ });
943
+ } catch (o) {
944
+ l.open({
945
+ title: `Unable to duplicate "${e.name}"`,
946
+ message: `See error from server: ${o}`,
947
+ type: "error"
948
+ }), console.error("error on duplicating closing template", o);
949
+ } finally {
950
+ k.value = !1, F();
951
+ }
952
+ });
953
+ }
954
+ const h = R({});
955
+ function w(e) {
956
+ h.value = {
957
+ template: e,
958
+ show: !0,
959
+ "onUpdate:show"(k) {
960
+ h.value.show = k;
961
+ },
962
+ "onAction:edit"() {
963
+ h.value.show = !1, a(Ne(e));
964
+ }
965
+ };
966
+ }
967
+ function y() {
968
+ if (!n.templates.length) {
969
+ l.open({
970
+ title: "No data to export",
971
+ type: "error"
972
+ });
973
+ return;
974
+ }
975
+ const e = bt(n.templates);
976
+ l.open({
977
+ title: m("inventory.ingredient.export.success"),
978
+ message: m("inventory.ingredient.export.filename", [e]),
979
+ type: "success"
980
+ });
981
+ }
982
+ function s(e) {
983
+ if (!e.items.length) {
984
+ l.open({
985
+ title: "No items in template to export",
986
+ type: "error"
987
+ });
988
+ return;
989
+ }
990
+ const k = _t(e);
991
+ l.open({
992
+ title: m("inventory.ingredient.export.success"),
993
+ message: m("inventory.ingredient.export.filename", [k]),
994
+ type: "success"
995
+ });
996
+ }
997
+ function v() {
998
+ n.loading || r.open({
999
+ title: m("inventory.ingredient.import.title"),
1000
+ contentComponent: jt,
1001
+ overlay: !0,
1002
+ closeButton: !0,
1003
+ primaryActions: {
1004
+ text: m("common.import"),
1005
+ close: !1
1006
+ },
1007
+ secondaryActions: {
1008
+ text: m("common.close"),
1009
+ close: !0
1010
+ },
1011
+ tertiaryActions: {
1012
+ text: m("inventory.ingredient.import.actions.downloadTemplate"),
1013
+ close: !1,
1014
+ variant: "plain"
1015
+ }
1016
+ }).onPrimary((e) => {
1017
+ if (!e) {
1018
+ l.open({
1019
+ title: m("inventory.ingredient.import.error.noData"),
1020
+ type: "error"
1021
+ });
1022
+ return;
1023
+ }
1024
+ if (!e.importCreateResult.length && !e.importUpdateResult.length) {
1025
+ l.open({
1026
+ title: m("inventory.ingredient.import.error.invalidContent"),
1027
+ message: m("inventory.ingredient.import.error.noImportData"),
1028
+ type: "error"
1029
+ });
1030
+ return;
1031
+ }
1032
+ if (e.importCreateResult.some((k) => k.errors.length) || e.importUpdateResult.some((k) => k.errors.length)) {
1033
+ l.open({
1034
+ title: m("inventory.ingredient.import.error.invalidContent"),
1035
+ message: m("inventory.ingredient.import.error.hasErrors"),
1036
+ type: "error"
1037
+ });
1038
+ return;
1039
+ }
1040
+ r.close(), T(e);
1041
+ }).onTertiary(xt);
1042
+ }
1043
+ async function T(e) {
1044
+ f.value = !0;
1045
+ try {
1046
+ const k = [
1047
+ ...e.importCreateResult.map(
1048
+ (x) => x.template
1049
+ ),
1050
+ ...e.importUpdateResult.map(
1051
+ (x) => x.template
1052
+ )
1053
+ ], F = 100;
1054
+ let p = 0;
1055
+ const o = () => {
1056
+ p += F, l.open({
1057
+ title: m("inventory.ingredient.import.progress", [
1058
+ Math.min(p, k.length),
1059
+ k.length
1060
+ ])
1061
+ });
1062
+ };
1063
+ for (const x of k.chunk(100))
1064
+ o(), await d.importTemplates(x);
1065
+ l.open({
1066
+ title: m("inventory.ingredient.import.success"),
1067
+ type: "success"
1068
+ });
1069
+ } catch (k) {
1070
+ l.open({
1071
+ title: m("inventory.ingredient.import.error.failed"),
1072
+ message: m("inventory.ingredient.import.error.systemMessage", [k == null ? void 0 : k.message]),
1073
+ type: "error"
1074
+ }), console.error("Error in importing skus", e, k);
1075
+ } finally {
1076
+ f.value = !1, n.fetchTemplates();
1077
+ }
1078
+ }
1079
+ return {
1080
+ createTemplate: c,
1081
+ viewTemplate: w,
1082
+ updateTemplate: a,
1083
+ deleteTemplate: g,
1084
+ duplicateTemplate: i,
1085
+ exportTemplates: y,
1086
+ exportSingleTemplate: s,
1087
+ importTemplates: v,
1088
+ templateDialogProps: b,
1089
+ templateDetailsProps: h
1090
+ };
1091
+ });
1092
+ var Q = /* @__PURE__ */ ((m) => (m.Name = "Name", m.Unit = "Unit", m.Delete = "Delete", m))(Q || {});
1093
+ function Yt(m) {
1094
+ return {
1095
+ columnDefs: L(() => {
1096
+ const l = m.items.map((t) => t.sku.unit.measurements.length).reduce((t, n) => Math.max(t, n), 0);
1097
+ return [
1098
+ {
1099
+ id: "Name",
1100
+ header: () => "Name",
1101
+ enableSorting: !1,
1102
+ size: 400,
1103
+ minSize: 400,
1104
+ accessorFn: (t) => `${t.sku.name} ${t.sku.code}`,
1105
+ cell(t) {
1106
+ const n = t.row.original;
1107
+ return P(
1108
+ "div",
1109
+ {
1110
+ class: "flex flex-col",
1111
+ style: { minWidth: "400px" }
1112
+ },
1113
+ [
1114
+ P(
1115
+ "span",
1116
+ { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary line-clamp-1" },
1117
+ n.sku.name
1118
+ ),
1119
+ P(
1120
+ "span",
1121
+ { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary line-clamp-1" },
1122
+ n.sku.code
1123
+ )
1124
+ ]
1125
+ );
1126
+ }
1127
+ },
1128
+ {
1129
+ id: "Unit",
1130
+ header: () => "Enable unit",
1131
+ enableSorting: !1,
1132
+ minSize: 200,
1133
+ maxSize: 400,
1134
+ cell(t) {
1135
+ var f, b, c;
1136
+ const n = t.row.original;
1137
+ return P("div", { class: "flex items-center gap-32" }, [
1138
+ P(
1139
+ Y.FmFormGroup,
1140
+ {
1141
+ value: n.sku.unit._id,
1142
+ modelValue: !((f = n.disabledMeasurements) != null && f.includes(n.sku.unit._id))
1143
+ },
1144
+ P(
1145
+ "div",
1146
+ {
1147
+ class: "flex items-center gap-4",
1148
+ style: { width: "120px" }
1149
+ },
1150
+ [
1151
+ P(Y.FmCheckbox, {
1152
+ value: n.sku.unit._id,
1153
+ modelValue: !((b = n.disabledMeasurements) != null && b.includes(n.sku.unit._id)),
1154
+ disabled: m.disabled || !((c = n.disabledMeasurements) != null && c.includes(n.sku.unit._id)) && n.sku.unit.measurements.every(
1155
+ (a) => {
1156
+ var g;
1157
+ return (g = n.disabledMeasurements) == null ? void 0 : g.includes(a.id);
1158
+ }
1159
+ ),
1160
+ "onUpdate:modelValue"(a) {
1161
+ var g;
1162
+ if (a)
1163
+ m.updateItem({
1164
+ ...n,
1165
+ disabledMeasurements: (g = n.disabledMeasurements) == null ? void 0 : g.filter(
1166
+ (i) => i !== n.sku.unit._id
1167
+ )
1168
+ });
1169
+ else {
1170
+ const i = n.disabledMeasurements ?? [];
1171
+ m.updateItem({
1172
+ ...n,
1173
+ disabledMeasurements: [...i, n.sku.unit._id]
1174
+ });
1175
+ }
1176
+ }
1177
+ }),
1178
+ P(
1179
+ Y.FmTooltip,
1180
+ { zIndex: 51 },
1181
+ {
1182
+ content() {
1183
+ return n.sku.unit.abbrev;
1184
+ },
1185
+ default() {
1186
+ return P(
1187
+ "div",
1188
+ { class: "line-clamp-2 fm-typo-en-body-lg-400" },
1189
+ n.sku.unit.abbrev
1190
+ );
1191
+ }
1192
+ }
1193
+ )
1194
+ ]
1195
+ )
1196
+ ),
1197
+ ...Array.from({ length: Math.max(l, 0) }).map((a, g) => {
1198
+ var w, y, s, v;
1199
+ const i = t.row.original, h = i.sku.unit.measurements[g];
1200
+ return h ? P(
1201
+ Y.FmFormGroup,
1202
+ {
1203
+ modelValue: !((w = i.disabledMeasurements) != null && w.includes(h.id)),
1204
+ value: h.id
1205
+ },
1206
+ P(
1207
+ "div",
1208
+ {
1209
+ class: "flex items-center gap-4",
1210
+ style: { width: "120px" }
1211
+ },
1212
+ [
1213
+ P(Y.FmCheckbox, {
1214
+ value: h.id,
1215
+ modelValue: !((y = i.disabledMeasurements) != null && y.includes(h.id)),
1216
+ disabled: m.disabled || !((s = i.disabledMeasurements) != null && s.includes(h.id)) && ((v = i.disabledMeasurements) == null ? void 0 : v.includes(i.sku.unit._id)) && i.sku.unit.measurements.filter((T) => T.id != h.id).every((T) => {
1217
+ var e;
1218
+ return (e = i.disabledMeasurements) == null ? void 0 : e.includes(T.id);
1219
+ }),
1220
+ "onUpdate:modelValue"(T) {
1221
+ var e;
1222
+ if (T)
1223
+ m.updateItem({
1224
+ ...i,
1225
+ disabledMeasurements: (e = i.disabledMeasurements) == null ? void 0 : e.filter(
1226
+ (k) => k !== h.id
1227
+ )
1228
+ });
1229
+ else {
1230
+ const k = i.disabledMeasurements ?? [];
1231
+ m.updateItem({
1232
+ ...i,
1233
+ disabledMeasurements: [...k, h.id]
1234
+ });
1235
+ }
1236
+ }
1237
+ }),
1238
+ P(
1239
+ Y.FmTooltip,
1240
+ { zIndex: 51 },
1241
+ {
1242
+ content() {
1243
+ return h.abbrev;
1244
+ },
1245
+ default() {
1246
+ return P(
1247
+ "div",
1248
+ { class: "line-clamp-2 fm-typo-en-body-lg-400" },
1249
+ h.abbrev
1250
+ );
1251
+ }
1252
+ }
1253
+ )
1254
+ ]
1255
+ )
1256
+ ) : null;
1257
+ })
1258
+ ]);
1259
+ }
1260
+ },
1261
+ {
1262
+ id: "Delete",
1263
+ header: "",
1264
+ cell(t) {
1265
+ const n = t.row.original;
1266
+ return P(
1267
+ "div",
1268
+ { class: "w-full flex justify-end" },
1269
+ P(Y.FmButton, {
1270
+ class: "delete-button",
1271
+ key: n.sku._id,
1272
+ type: "button",
1273
+ icon: "delete",
1274
+ variant: "tertiary",
1275
+ size: "md",
1276
+ disabled: m.disabled,
1277
+ onClick: () => {
1278
+ m.deleteItem(n);
1279
+ }
1280
+ })
1281
+ );
1282
+ },
1283
+ enableSorting: !1,
1284
+ size: 40,
1285
+ meta: {
1286
+ cellClass: "",
1287
+ headerClass: ""
1288
+ }
1289
+ }
1290
+ ];
1291
+ })
1292
+ };
1293
+ }
1294
+ const Gt = { class: "flex flex-col gap-16 py-12" }, Kt = { class: "flex" }, Wt = { class: "flex-1 flex flex-col" }, qt = { class: "fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, Jt = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Xt = { class: "flex flex-col gap-4" }, Qt = /* @__PURE__ */ K({
1295
+ __name: "ClosingTemplateItem",
1296
+ props: {
1297
+ cellByColId: {},
1298
+ row: {}
1299
+ },
1300
+ setup(m) {
1301
+ const r = m, l = L(() => r.row), d = L(
1302
+ () => l.value.getVisibleCells().filter((t) => t.column.id !== Q.Name && t.column.id !== Q.Delete)
1303
+ );
1304
+ return (t, n) => {
1305
+ var f, b, c, a, g;
1306
+ return $(), D("div", Gt, [
1307
+ _("div", Kt, [
1308
+ _("div", Wt, [
1309
+ _("div", qt, I(l.value.original.sku.name), 1),
1310
+ _("div", Jt, I(l.value.original.sku.code), 1)
1311
+ ]),
1312
+ _("div", null, [
1313
+ C(u(X), {
1314
+ render: (c = (b = (f = t.cellByColId[u(Q).Delete]) == null ? void 0 : f.column) == null ? void 0 : b.columnDef) == null ? void 0 : c.cell,
1315
+ props: (g = (a = t.cellByColId[u(Q).Delete]) == null ? void 0 : a.getContext) == null ? void 0 : g.call(a)
1316
+ }, null, 8, ["render", "props"])
1317
+ ])
1318
+ ]),
1319
+ _("div", Xt, [
1320
+ n[0] || (n[0] = _("div", { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, null, -1)),
1321
+ ($(!0), D(j, null, Z(d.value, (i) => {
1322
+ var h, w, y;
1323
+ return $(), D("div", {
1324
+ key: i.id
1325
+ }, [
1326
+ C(u(X), {
1327
+ render: (w = (h = i.column) == null ? void 0 : h.columnDef) == null ? void 0 : w.cell,
1328
+ props: (y = i.getContext) == null ? void 0 : y.call(i)
1329
+ }, null, 8, ["render", "props"])
1330
+ ]);
1331
+ }), 128))
1332
+ ])
1333
+ ]);
1334
+ };
1335
+ }
1336
+ }), Zt = { class: "flex flex-col gap-16" }, en = { class: "flex flex-col gap-24" }, tn = { class: "flex flex-col gap-16" }, nn = { class: "flex items-center" }, on = { class: "flex-1 fm-typo-en-title-sm-600" }, sn = { class: "flex flex-col gap-16" }, ln = { class: "flex items-center" }, an = { class: "flex-1 gap-8 fm-typo-en-title-sm-600" }, rn = { class: "flex gap-8" }, cn = { key: 0 }, mn = /* @__PURE__ */ K({
1337
+ __name: "ClosingTemplateForm",
1338
+ props: {
1339
+ modelValue: {},
1340
+ disabled: { type: Boolean }
1341
+ },
1342
+ setup(m, { expose: r }) {
1343
+ const l = m, d = vt(), { t } = W(), n = ve(), {
1344
+ promptSelectLocations: f,
1345
+ columnDefs: b,
1346
+ rowData: c
1347
+ } = gt({
1348
+ getLocations() {
1349
+ return d.locations;
1350
+ },
1351
+ setLocations(p) {
1352
+ d.locations = p;
1353
+ }
1354
+ }), a = R(), g = R(""), i = R(null), h = R(!1), w = [
1355
+ {
1356
+ key: "name",
1357
+ label: "Name",
1358
+ getter: (p) => {
1359
+ var o;
1360
+ return (o = p.sku) == null ? void 0 : o.name;
1361
+ }
1362
+ },
1363
+ {
1364
+ key: "code",
1365
+ label: "Code",
1366
+ getter: (p) => {
1367
+ var o;
1368
+ return (o = p.sku) == null ? void 0 : o.code;
1369
+ }
1370
+ }
1371
+ ], y = R([]), s = L(() => d.items.map((p, o) => ({ item: p, originalIndex: o })).sort((p, o) => {
1372
+ const x = p.item.position ?? p.originalIndex, M = o.item.position ?? o.originalIndex;
1373
+ return x - M;
1374
+ }).map(({ item: p }) => p));
1375
+ function v() {
1376
+ h.value ? d.items = y.value.map(({ id: p, label: o, ...x }, M) => ({
1377
+ ...x,
1378
+ position: M
1379
+ })) : y.value = s.value.map((p) => ({
1380
+ ...p,
1381
+ id: p.sku._id,
1382
+ label: `${p.sku.code} ${p.sku.name}`
1383
+ })), h.value = !h.value;
1384
+ }
1385
+ r({
1386
+ validateInputs: () => {
1387
+ var p, o;
1388
+ (o = (p = a.value) == null ? void 0 : p.validateInputs) == null || o.call(p);
1389
+ },
1390
+ resetInputsValidation: () => {
1391
+ var p, o;
1392
+ (o = (p = a.value) == null ? void 0 : p.resetInputsValidation) == null || o.call(p);
1393
+ },
1394
+ resetInputs: () => {
1395
+ var p, o;
1396
+ (o = (p = a.value) == null ? void 0 : p.resetInputs) == null || o.call(p);
1397
+ }
1398
+ });
1399
+ const T = Yt({
1400
+ updateItem: (p) => {
1401
+ d.items = d.items.map((o) => o.sku._id !== p.sku._id ? o : p);
1402
+ },
1403
+ deleteItem: (p) => {
1404
+ d.items = d.items.filter((o) => o.sku._id !== p.sku._id);
1405
+ },
1406
+ get items() {
1407
+ return s.value;
1408
+ },
1409
+ get disabled() {
1410
+ return l.disabled;
1411
+ }
1412
+ }), e = L(() => T.columnDefs.value), { promptSelectIngredients: k } = ft();
1413
+ async function F() {
1414
+ const o = n.skus.map((S) => ({
1415
+ label: S.name,
1416
+ sublabel: S.code,
1417
+ value: S
1418
+ })).filter((S) => {
1419
+ var U;
1420
+ return (U = d.items) == null ? void 0 : U.find((H) => H.sku._id === S.value._id);
1421
+ }).map((S) => S.value), x = d.items ?? [], M = await k(
1422
+ o.map((S) => S._id),
1423
+ (S) => {
1424
+ const U = n.skuById[S], H = x.find((A) => A.sku._id === U._id);
1425
+ return H || {
1426
+ sku: U
1427
+ };
1428
+ }
1429
+ );
1430
+ M && (M.sort((S, U) => S.sku.code.localeCompare(U.sku.code)), d.items = M);
1431
+ }
1432
+ return (p, o) => {
1433
+ const x = E("FmTextField"), M = E("FmButton"), S = E("FmTable"), U = E("FmIcon"), H = E("FmFormGroup"), B = E("FmForm");
1434
+ return $(), N(B, {
1435
+ ref_key: "formRef",
1436
+ ref: a,
1437
+ class: "flex flex-col gap-32",
1438
+ disabled: p.disabled
1439
+ }, {
1440
+ default: V(() => [
1441
+ _("div", Zt, [
1442
+ _("div", en, [
1443
+ C(x, {
1444
+ label: u(t)("inventory.closing.form.name"),
1445
+ "label-mark": "required",
1446
+ modelValue: u(d).name,
1447
+ "onUpdate:modelValue": o[0] || (o[0] = (A) => u(d).name = A),
1448
+ rules: [u(dt)()]
1449
+ }, null, 8, ["label", "modelValue", "rules"]),
1450
+ C(x, {
1451
+ label: u(t)("inventory.closing.form.reference"),
1452
+ "label-mark": "optional",
1453
+ modelValue: u(d).ref,
1454
+ "onUpdate:modelValue": o[1] || (o[1] = (A) => u(d).ref = A)
1455
+ }, null, 8, ["label", "modelValue"])
1456
+ ])
1457
+ ]),
1458
+ _("div", tn, [
1459
+ _("div", nn, [
1460
+ _("div", on, I(u(t)("inventory.closing.form.locations")), 1),
1461
+ C(M, {
1462
+ disabled: p.disabled,
1463
+ label: u(t)("inventory.closing.form.selectLocation"),
1464
+ "prepend-icon": "add",
1465
+ variant: "plain",
1466
+ class: "border-2 rounded-lg border-fm-color-primary",
1467
+ onClick: u(f)
1468
+ }, null, 8, ["disabled", "label", "onClick"])
1469
+ ]),
1470
+ C(S, {
1471
+ "column-defs": u(b),
1472
+ "row-data": u(c),
1473
+ "shrink-at": 9999,
1474
+ onRowClick: u(f),
1475
+ "hide-footer": ""
1476
+ }, null, 8, ["column-defs", "row-data", "onRowClick"])
1477
+ ]),
1478
+ _("div", sn, [
1479
+ _("div", ln, [
1480
+ _("div", an, I(u(t)("inventory.closing.form.items.title")), 1),
1481
+ _("div", rn, [
1482
+ u(d).items.length > 0 ? ($(), N(M, {
1483
+ key: 0,
1484
+ disabled: p.disabled,
1485
+ label: h.value ? u(t)("inventory.common.done") : u(t)("inventory.common.rearrange"),
1486
+ "prepend-icon": h.value ? "check" : "swap_vert",
1487
+ variant: h.value ? "primary" : "secondary",
1488
+ class: q(["border-2 rounded-lg", h.value ? "" : "border-fm-color-secondary"]),
1489
+ onClick: v,
1490
+ size: "md"
1491
+ }, null, 8, ["disabled", "label", "prepend-icon", "variant", "class"])) : O("", !0),
1492
+ h.value ? O("", !0) : ($(), N(M, {
1493
+ key: 1,
1494
+ disabled: p.disabled,
1495
+ label: u(t)("inventory.closing.form.items.addItem"),
1496
+ "prepend-icon": "add",
1497
+ variant: "plain",
1498
+ class: "border-2 rounded-lg border-fm-color-primary",
1499
+ onClick: o[2] || (o[2] = (A) => F()),
1500
+ size: "md"
1501
+ }, null, 8, ["disabled", "label"]))
1502
+ ])
1503
+ ]),
1504
+ h.value ? ($(), D("div", cn, [
1505
+ C(u(et), {
1506
+ modelValue: y.value,
1507
+ "onUpdate:modelValue": o[3] || (o[3] = (A) => y.value = A),
1508
+ "sort-fields": w,
1509
+ "left-column-label": u(t)("inventory.closing.form.items.availableItems"),
1510
+ "right-column-label": u(t)("inventory.closing.form.items.organizedGroups"),
1511
+ height: "600px"
1512
+ }, null, 8, ["modelValue", "left-column-label", "right-column-label"])
1513
+ ])) : ($(), D(j, { key: 1 }, [
1514
+ C(x, {
1515
+ placeholder: u(t)("inventory.formField.filterItems"),
1516
+ modelValue: g.value,
1517
+ "onUpdate:modelValue": o[5] || (o[5] = (A) => g.value = A)
1518
+ }, Ee({ _: 2 }, [
1519
+ g.value ? {
1520
+ name: "append",
1521
+ fn: V(() => [
1522
+ C(U, {
1523
+ name: "close",
1524
+ onClick: o[4] || (o[4] = (A) => g.value = ""),
1525
+ class: "cursor-pointer"
1526
+ })
1527
+ ]),
1528
+ key: "0"
1529
+ } : void 0
1530
+ ]), 1032, ["placeholder", "modelValue"]),
1531
+ _("div", {
1532
+ ref_key: "itemsTableRef",
1533
+ ref: i
1534
+ }, [
1535
+ ($(), N(S, {
1536
+ "search-value": g.value,
1537
+ "column-defs": e.value,
1538
+ "row-data": s.value,
1539
+ key: s.value.map((A) => A.sku._id).join("."),
1540
+ "hide-footer": s.value.length <= 10,
1541
+ "page-size": Math.min(10, s.value.length)
1542
+ }, {
1543
+ "list-row": V((A) => [
1544
+ ($(), N(ze, {
1545
+ row: A,
1546
+ key: s.value.map((J) => J.sku._id).join(".")
1547
+ }, {
1548
+ default: V((J) => [
1549
+ C(Qt, {
1550
+ row: A,
1551
+ "cell-by-col-id": J
1552
+ }, null, 8, ["row", "cell-by-col-id"])
1553
+ ]),
1554
+ _: 2
1555
+ }, 1032, ["row"]))
1556
+ ]),
1557
+ _: 1
1558
+ }, 8, ["search-value", "column-defs", "row-data", "hide-footer", "page-size"]))
1559
+ ], 512)
1560
+ ], 64)),
1561
+ C(H, {
1562
+ "model-value": u(d).items.length,
1563
+ rules: [u(pt)(1)]
1564
+ }, null, 8, ["model-value", "rules"])
1565
+ ])
1566
+ ]),
1567
+ _: 1
1568
+ }, 8, ["disabled"]);
1569
+ };
1570
+ }
1571
+ }), un = { class: "flex items-center" }, dn = { class: "fm-typo-en-title-md-600" }, pn = { class: "flex justify-between" }, fn = { class: "fm-typo-en-body-lg-600" }, vn = { class: "flex flex-col gap-8" }, gn = { class: "flex flex-col gap-4" }, yn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, hn = { class: "flex items-center gap-8" }, bn = { class: "fm-typo-en-body-lg-600" }, _n = { class: "flex gap-4" }, xn = /* @__PURE__ */ K({
1572
+ __name: "ClosingTemplateDialog",
1573
+ props: {
1574
+ mode: {},
1575
+ modelValue: {},
1576
+ show: { type: Boolean }
1577
+ },
1578
+ emits: ["update:show", "submitted"],
1579
+ setup(m, { expose: r, emit: l }) {
1580
+ var p;
1581
+ const d = m, t = l, n = me(), f = ie(), b = ce(), { t: c } = W(), a = tt(d, "show");
1582
+ function g() {
1583
+ return {
1584
+ _id: "",
1585
+ name: "",
1586
+ items: []
1587
+ };
1588
+ }
1589
+ const i = R(d.modelValue ?? g()), h = R(((p = d.modelValue) == null ? void 0 : p._id) ?? `${Math.random()}`);
1590
+ Pe(
1591
+ () => d.show,
1592
+ (o) => {
1593
+ var x;
1594
+ o && (i.value = d.modelValue ?? g(), h.value = ((x = d.modelValue) == null ? void 0 : x._id) ?? `${Math.random()}`);
1595
+ }
1596
+ );
1597
+ const w = R(!1), y = L(() => {
1598
+ switch (d.mode) {
1599
+ case G.READ:
1600
+ return "";
1601
+ case G.CREATE:
1602
+ return c("inventory.closing.template.create.title");
1603
+ case G.UPDATE:
1604
+ return c("inventory.closing.template.update.title");
1605
+ }
1606
+ return "";
1607
+ }), s = R();
1608
+ r({
1609
+ validateInputs: () => {
1610
+ var o, x;
1611
+ (x = (o = s.value) == null ? void 0 : o.validateInputs) == null || x.call(o);
1612
+ },
1613
+ resetInputsValidation: () => {
1614
+ var o, x;
1615
+ (x = (o = s.value) == null ? void 0 : o.resetInputsValidation) == null || x.call(o);
1616
+ },
1617
+ resetInputs: () => {
1618
+ var o, x;
1619
+ (x = (o = s.value) == null ? void 0 : o.resetInputs) == null || x.call(o);
1620
+ }
1621
+ });
1622
+ async function v() {
1623
+ const o = i.value;
1624
+ if (o) {
1625
+ w.value = !0;
1626
+ try {
1627
+ await n.createTemplate(o), await new Promise((x) => setTimeout(x, 1e3)), b.open({
1628
+ title: c("inventory.closing.template.create.success"),
1629
+ message: c("inventory.closing.template.create.successMessage"),
1630
+ type: "success"
1631
+ }), t("update:show", !1), t("submitted");
1632
+ } catch (x) {
1633
+ b.open({
1634
+ title: c("inventory.closing.template.create.error"),
1635
+ message: c("inventory.closing.template.create.errorMessage"),
1636
+ type: "error"
1637
+ }), console.error("Error in creating closing template", x);
1638
+ } finally {
1639
+ w.value = !1;
1640
+ }
1641
+ }
1642
+ }
1643
+ async function T() {
1644
+ const o = i.value;
1645
+ if (o) {
1646
+ w.value = !0, delete o.updatedAt;
1647
+ try {
1648
+ await n.updateTemplate({
1649
+ ...o,
1650
+ _rev: o._rev ?? ""
1651
+ }), await new Promise((x) => setTimeout(x, 1e3)), b.open({
1652
+ title: c("inventory.closing.template.update.success"),
1653
+ message: c("inventory.closing.template.update.successMessage"),
1654
+ type: "success"
1655
+ }), t("update:show", !1), t("submitted");
1656
+ } catch (x) {
1657
+ b.open({
1658
+ title: c("inventory.closing.template.update.error"),
1659
+ message: c("inventory.closing.template.update.errorMessage"),
1660
+ type: "error"
1661
+ }), console.error("Error in updating closing template", x);
1662
+ } finally {
1663
+ w.value = !1;
1664
+ }
1665
+ }
1666
+ }
1667
+ function e() {
1668
+ switch (d.mode) {
1669
+ case G.CREATE:
1670
+ return v();
1671
+ case G.UPDATE:
1672
+ return T();
1673
+ }
1674
+ }
1675
+ function k() {
1676
+ var o, x;
1677
+ (x = (o = s.value) == null ? void 0 : o.validateInputs) == null || x.call(o);
1678
+ }
1679
+ function F() {
1680
+ i.value && f.exportSingleTemplate(i.value);
1681
+ }
1682
+ return (o, x) => {
1683
+ const M = E("FmMenuDivider"), S = E("FmCard"), U = E("FmButton"), H = E("FmSideSheet");
1684
+ return $(), N(H, {
1685
+ modelValue: u(a),
1686
+ "onUpdate:modelValue": x[2] || (x[2] = (B) => Ye(a) ? a.value = B : null),
1687
+ "dismiss-away": "",
1688
+ "close-button": "",
1689
+ "max-width": 9999
1690
+ }, {
1691
+ "side-sheet-header": V(() => [
1692
+ _("div", un, [
1693
+ _("div", dn, I(y.value), 1)
1694
+ ])
1695
+ ]),
1696
+ default: V(() => [
1697
+ i.value.updatedAt ? ($(), N(S, {
1698
+ key: 0,
1699
+ variant: "outlined",
1700
+ class: "flex flex-col gap-8 px-12 py-16 mb-16"
1701
+ }, {
1702
+ default: V(() => {
1703
+ var B;
1704
+ return [
1705
+ _("div", pn, [
1706
+ _("div", fn, I(u(c)("inventory.transfer.template.details.templateSummary")), 1)
1707
+ ]),
1708
+ C(M),
1709
+ _("div", vn, [
1710
+ _("div", gn, [
1711
+ _("div", yn, I(u(c)("inventory.transfer.receiveRequest.details.updatedAt")), 1),
1712
+ _("div", hn, [
1713
+ _("div", bn, [
1714
+ ae(I(u(le)(i.value.updatedAt)) + " ", 1),
1715
+ (B = i.value.updatedBy) != null && B.name ? ($(), D(j, { key: 0 }, [
1716
+ ae(" (" + I(i.value.updatedBy.name) + ") ", 1)
1717
+ ], 64)) : O("", !0)
1718
+ ]),
1719
+ C(yt, {
1720
+ "closing-id": i.value._id
1721
+ }, null, 8, ["closing-id"])
1722
+ ])
1723
+ ])
1724
+ ])
1725
+ ];
1726
+ }),
1727
+ _: 1
1728
+ })) : O("", !0),
1729
+ ($(), N(mn, {
1730
+ class: "w-full",
1731
+ ref_key: "formRef",
1732
+ ref: s,
1733
+ onValidationSuccess: e,
1734
+ "model-value": i.value,
1735
+ "onUpdate:modelValue": x[0] || (x[0] = (B) => i.value = B),
1736
+ disabled: w.value,
1737
+ key: h.value
1738
+ }, null, 8, ["model-value", "disabled"]))
1739
+ ]),
1740
+ "side-sheet-footer": V(() => [
1741
+ _("div", _n, [
1742
+ C(U, {
1743
+ loading: w.value,
1744
+ label: u(c)("common.save"),
1745
+ onClick: k
1746
+ }, null, 8, ["loading", "label"]),
1747
+ o.mode === u(G).UPDATE ? ($(), N(U, {
1748
+ key: 0,
1749
+ disabled: w.value,
1750
+ variant: "secondary",
1751
+ label: u(c)("inventory.common.export"),
1752
+ "prepend-icon": "download",
1753
+ onClick: F
1754
+ }, null, 8, ["disabled", "label"])) : O("", !0),
1755
+ C(U, {
1756
+ disabled: w.value,
1757
+ variant: "tertiary",
1758
+ label: u(c)("common.close"),
1759
+ onClick: x[1] || (x[1] = (B) => t("update:show", !1))
1760
+ }, null, 8, ["disabled", "label"])
1761
+ ])
1762
+ ]),
1763
+ _: 1
1764
+ }, 8, ["modelValue"]);
1765
+ };
1766
+ }
1767
+ }), wn = {};
1768
+ function kn(m, r) {
1769
+ return $(), D("div");
1770
+ }
1771
+ const Tn = /* @__PURE__ */ ht(wn, [["render", kn]]), $n = { class: "flex flex-col gap-40" }, Cn = { key: 0 }, In = {
1772
+ key: 1,
1773
+ class: "flex gap-8 items-center"
1774
+ }, Sn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" }, Dn = {
1775
+ key: 2,
1776
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary"
1777
+ }, Mn = {
1778
+ key: 3,
1779
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary flex flex-col gap-12"
1780
+ }, Fn = { class: "fm-typo-en-body-md-600" }, Rn = { class: "fm-typo-en-body-md-600" }, An = { key: 4 }, Pn = { class: "fm-typo-en-body-md-600" }, En = { class: "fm-typo-en-body-md-600" }, Vn = { class: "flex sm:flex-col xs:flex-col justify-end gap-8 w-full mb-16" }, Un = /* @__PURE__ */ K({
1781
+ __name: "ClosingTemplatePublish",
1782
+ emits: ["close"],
1783
+ setup(m, { emit: r }) {
1784
+ const l = R(!1), d = ce(), t = me(), n = ue(), { t: f } = W(), b = r;
1785
+ async function c() {
1786
+ l.value = !0;
1787
+ try {
1788
+ await t.startNewPublish().delayed(1e3), d.open({
1789
+ title: "Success",
1790
+ message: "You may refresh after a while to review publish status",
1791
+ type: "success"
1792
+ }), i();
1793
+ } catch (h) {
1794
+ d.open({
1795
+ title: "Something went wrong",
1796
+ message: "Please try again",
1797
+ type: "error"
1798
+ }), console.error("error on creating publish task", h);
1799
+ } finally {
1800
+ l.value = !1;
1801
+ }
1802
+ }
1803
+ const a = L(() => n.recentPublish.recentJob), g = L(
1804
+ () => n.templates.length && (!a.value || a.value.outlets.length === a.value.completed.length)
1805
+ );
1806
+ function i() {
1807
+ b("close");
1808
+ }
1809
+ return (h, w) => {
1810
+ const y = E("FmCircularProgress"), s = E("i18n-t"), v = E("FmButton");
1811
+ return $(), D("div", $n, [
1812
+ u(n).templates.length ? l.value ? ($(), D("div", In, [
1813
+ _("div", null, [
1814
+ C(y, {
1815
+ size: "md",
1816
+ color: "neutral-gray-300"
1817
+ })
1818
+ ]),
1819
+ _("div", Sn, [
1820
+ _("span", null, I(u(f)("inventory.closing.template.publish.publishing")), 1)
1821
+ ])
1822
+ ])) : a.value ? a.value.outlets.length === a.value.completed.length ? ($(), D("div", Mn, [
1823
+ C(s, {
1824
+ keypath: "inventory.closing.template.publish.recentlyPublishedAt",
1825
+ tag: "p"
1826
+ }, {
1827
+ started: V(() => [
1828
+ _("span", Fn, I(u(le)(new Date(a.value.createdAt))), 1)
1829
+ ]),
1830
+ finished: V(() => [
1831
+ _("span", Rn, I(u(le)(new Date(a.value.updatedAt))), 1)
1832
+ ]),
1833
+ _: 1
1834
+ }),
1835
+ _("p", null, I(u(f)("inventory.closing.template.publish.message")), 1)
1836
+ ])) : ($(), D("div", An, [
1837
+ C(s, {
1838
+ keypath: "inventory.closing.template.publish.stillPublishing",
1839
+ tag: "p"
1840
+ }, {
1841
+ started: V(() => [
1842
+ _("span", Pn, I(u(le)(new Date(a.value.createdAt))), 1)
1843
+ ]),
1844
+ progress: V(() => [
1845
+ _("span", En, " (" + I(a.value.completed.length) + "/" + I(a.value.outlets.length) + " completed) ", 1)
1846
+ ]),
1847
+ _: 1
1848
+ }),
1849
+ ae(" Your recent publishing task is still pending (" + I(a.value.completed.length) + " / " + I(a.value.outlets.length) + "). Please wait until all publishing task has completed. ", 1)
1850
+ ])) : ($(), D("div", Dn, [
1851
+ _("p", null, I(u(f)("inventory.closing.template.publish.noRecentActivity")), 1),
1852
+ _("p", null, I(u(f)("inventory.closing.template.publish.message")), 1)
1853
+ ])) : ($(), D("div", Cn, [
1854
+ _("p", null, I(u(f)("inventory.closing.template.publish.nothingToPublish")), 1)
1855
+ ])),
1856
+ _("div", Vn, [
1857
+ C(v, {
1858
+ disabled: !g.value,
1859
+ loading: l.value,
1860
+ label: "Publish to all outlets",
1861
+ onClick: c
1862
+ }, null, 8, ["disabled", "loading"]),
1863
+ C(v, {
1864
+ variant: "tertiary",
1865
+ label: "Close",
1866
+ onClick: i
1867
+ })
1868
+ ])
1869
+ ]);
1870
+ };
1871
+ }
1872
+ }), Nn = { class: "flex-1 flex flex-col gap-8" }, Ln = { class: "flex flex-col" }, Bn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, zn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Hn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, On = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, vo = /* @__PURE__ */ K({
1873
+ __name: "ClosingTemplateView",
1874
+ setup(m) {
1875
+ const { t: r } = W(), { createTemplate: l, updateTemplate: d, exportTemplates: t, importTemplates: n } = ie(), { templateDialogProps: f, templateDetailsProps: b } = Ue(ie()), c = fe(), a = pe(), g = ue(), i = Xe(), { breakpoints: h } = nt();
1876
+ c.watchLocation(g.fetchTemplates);
1877
+ const w = L(() => g.loading), y = R(""), s = L(() => h.value.xs || h.value.sm), v = L(() => s.value ? 10 : 20);
1878
+ function T(p) {
1879
+ switch (p) {
1880
+ case z.Add:
1881
+ return l();
1882
+ case "publish":
1883
+ return e();
1884
+ case "import":
1885
+ return n();
1886
+ case "export":
1887
+ return t();
1888
+ case "refresh":
1889
+ return g.fetchTemplates();
1890
+ }
1891
+ }
1892
+ function e() {
1893
+ a.open({
1894
+ title: "Publish closing templates",
1895
+ contentComponent: Un,
1896
+ contentComponentProps: {
1897
+ onClose() {
1898
+ a.close();
1899
+ }
1900
+ }
1901
+ });
1902
+ }
1903
+ function k(p) {
1904
+ return p;
1905
+ }
1906
+ const F = L(() => s.value ? [
1907
+ {
1908
+ label: r("inventory.closing.template.create.title"),
1909
+ value: z.Add,
1910
+ isPrimary: !0,
1911
+ prependIcon: "add"
1912
+ },
1913
+ {
1914
+ label: r("inventory.common.refresh"),
1915
+ value: "refresh",
1916
+ isPrimary: !1
1917
+ },
1918
+ {
1919
+ label: r("inventory.common.publish"),
1920
+ value: "publish",
1921
+ isPrimary: !1
1922
+ },
1923
+ {
1924
+ label: r("inventory.common.import"),
1925
+ value: "import",
1926
+ isPrimary: !1
1927
+ },
1928
+ {
1929
+ label: r("inventory.common.export"),
1930
+ value: "export",
1931
+ isPrimary: !1
1932
+ }
1933
+ ] : [
1934
+ {
1935
+ label: r("inventory.closing.template.create.title"),
1936
+ value: z.Add,
1937
+ isPrimary: !0,
1938
+ prependIcon: "add"
1939
+ },
1940
+ {
1941
+ label: r("inventory.common.publish"),
1942
+ value: "publish",
1943
+ isPrimary: !1
1944
+ },
1945
+ {
1946
+ label: r("inventory.common.import"),
1947
+ value: "import",
1948
+ isPrimary: !1
1949
+ },
1950
+ {
1951
+ label: r("inventory.common.refresh"),
1952
+ value: "refresh",
1953
+ isPrimary: !1
1954
+ },
1955
+ {
1956
+ label: r("inventory.common.export"),
1957
+ value: "export",
1958
+ isPrimary: !1
1959
+ }
1960
+ ]);
1961
+ return (p, o) => {
1962
+ const x = E("FmTable");
1963
+ return $(), D(j, null, [
1964
+ C(Qe, {
1965
+ title: u(r)("inventory.closing.template.title"),
1966
+ actions: F.value,
1967
+ "onClick:action": T
1968
+ }, {
1969
+ default: V(() => [
1970
+ _("div", {
1971
+ class: q([
1972
+ "flex flex-col gap-8 max-h-full",
1973
+ {
1974
+ "p-0": s.value,
1975
+ "px-24 ": !s.value
1976
+ }
1977
+ ])
1978
+ }, [
1979
+ C(ut, {
1980
+ searchable: "",
1981
+ search: y.value,
1982
+ "onUpdate:search": o[0] || (o[0] = (M) => y.value = M)
1983
+ }, null, 8, ["search"]),
1984
+ C(x, {
1985
+ style: Ge(u(i).tableHeight),
1986
+ "column-defs": u(g).columnDefs,
1987
+ "row-data": u(g).templates,
1988
+ "search-value": y.value,
1989
+ loading: w.value,
1990
+ onRowClick: o[1] || (o[1] = (M) => u(d)(M.original)),
1991
+ "page-size": v.value
1992
+ }, {
1993
+ "list-row": V((M) => [
1994
+ C(ze, {
1995
+ row: M,
1996
+ onRowClick: (S) => u(d)(S)
1997
+ }, {
1998
+ default: V((S) => {
1999
+ var U, H, B, A, J, be, _e, xe, ee, we, ke, Te, $e, Ce, Ie, te, Se, De, Me, Fe, ne, Re;
2000
+ return [
2001
+ _("div", Nn, [
2002
+ _("div", Ln, [
2003
+ _("div", Bn, [
2004
+ C(u(X), {
2005
+ render: (B = (H = (U = S._id) == null ? void 0 : U.column) == null ? void 0 : H.columnDef) == null ? void 0 : B.cell,
2006
+ props: (J = (A = S._id) == null ? void 0 : A.getContext) == null ? void 0 : J.call(A)
2007
+ }, null, 8, ["render", "props"])
2008
+ ]),
2009
+ _("div", zn, [
2010
+ C(u(X), {
2011
+ render: (xe = (_e = (be = S.name) == null ? void 0 : be.column) == null ? void 0 : _e.columnDef) == null ? void 0 : xe.cell,
2012
+ props: (we = (ee = S.name) == null ? void 0 : ee.getContext) == null ? void 0 : we.call(ee)
2013
+ }, null, 8, ["render", "props"])
2014
+ ]),
2015
+ _("div", null, I((ke = M.original.locations) != null && ke.length ? u(r)("inventory.closing.table.enabledForN", {
2016
+ count: ((Te = M.original.locations) == null ? void 0 : Te.length) ?? 0
2017
+ }) : u(r)("inventory.closing.table.enabledForAll")), 1),
2018
+ _("div", Hn, I([
2019
+ ...M.original.items.slice(0, 3).map((je) => je.sku.name),
2020
+ ...M.original.items.length >= 3 ? [`and ${M.original.items.length - 3} more items`] : []
2021
+ ].join(", ")), 1),
2022
+ _("div", On, [
2023
+ C(u(X), {
2024
+ render: (Ie = (Ce = ($e = S.ref) == null ? void 0 : $e.column) == null ? void 0 : Ce.columnDef) == null ? void 0 : Ie.cell,
2025
+ props: (Se = (te = S.ref) == null ? void 0 : te.getContext) == null ? void 0 : Se.call(te)
2026
+ }, null, 8, ["render", "props"])
2027
+ ])
2028
+ ]),
2029
+ _("div", null, [
2030
+ C(u(X), {
2031
+ render: (Fe = (Me = (De = S.status) == null ? void 0 : De.column) == null ? void 0 : Me.columnDef) == null ? void 0 : Fe.cell,
2032
+ props: (Re = (ne = S.status) == null ? void 0 : ne.getContext) == null ? void 0 : Re.call(ne)
2033
+ }, null, 8, ["render", "props"])
2034
+ ])
2035
+ ])
2036
+ ];
2037
+ }),
2038
+ _: 2
2039
+ }, 1032, ["row", "onRowClick"])
2040
+ ]),
2041
+ _: 1
2042
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
2043
+ ], 2)
2044
+ ]),
2045
+ _: 1
2046
+ }, 8, ["title", "actions"]),
2047
+ ($(), N(Ke, { to: "body" }, [
2048
+ C(Tn, We(qe(u(b))), null, 16),
2049
+ C(xn, Je(u(f), {
2050
+ onSubmitted: o[2] || (o[2] = (M) => u(g).fetchTemplates())
2051
+ }), null, 16)
2052
+ ]))
2053
+ ], 64);
2054
+ };
2055
+ }
2056
+ });
2057
+ export {
2058
+ vo as default
2059
+ };