@feedmepos/mf-inventory-portal 1.9.1 → 1.9.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 (98) hide show
  1. package/dist/{App-ChwM2mdj.js → App-Bip0baby.js} +10 -10
  2. package/dist/{ApprovalView-6nGsV69S.js → ApprovalView-CE85REo2.js} +9 -9
  3. package/dist/{BindingsDialog-OGTf0sNI.js → BindingsDialog-Ds7Vk2VQ.js} +2 -2
  4. package/dist/{BindingsPicker-BQsDrDd0.js → BindingsPicker-B28BAkR5.js} +2 -2
  5. package/dist/{BindingsTable-C03Zlp_f.js → BindingsTable-D8L_-zso.js} +4 -4
  6. package/dist/{BulkReceiveRequestPage-Bo4JDMkv.js → BulkReceiveRequestPage-Bf5zsedj.js} +19 -19
  7. package/dist/{ChangeLocationComponent.vue_vue_type_script_setup_true_lang-DZvWlqzW.js → ChangeLocationComponent.vue_vue_type_script_setup_true_lang-DIe4QGW4.js} +1 -1
  8. package/dist/{ClosingDraftView-CCU_VR6a.js → ClosingDraftView-br23XIYx.js} +19 -19
  9. package/dist/{ClosingHistoryView-IeBJW27N.js → ClosingHistoryView-R6667fAp.js} +7 -7
  10. package/dist/ClosingTemplateView-CVVev-wi.js +2409 -0
  11. package/dist/{CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-Cv18okDy.js → CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-CnC05TWX.js} +1 -1
  12. package/dist/{DefaultView-BFnkhq_H.js → DefaultView-CnC2ffJG.js} +2 -2
  13. package/dist/{DeliveryOrderPrintPreview-DXgt1t1x.js → DeliveryOrderPrintPreview-MahhQkSO.js} +2 -2
  14. package/dist/{EmailDialog.vue_vue_type_script_setup_true_lang-DGbAG3eM.js → EmailDialog.vue_vue_type_script_setup_true_lang-D2N_1VWH.js} +23 -23
  15. package/dist/{FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-CVQNcS4i.js → FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-AnSwoMnm.js} +1 -1
  16. package/dist/{FeatureCapabilityGate-Ddg6XQEe.js → FeatureCapabilityGate-CdB-dKPj.js} +2 -2
  17. package/dist/{FeaturePageGate.vue_vue_type_script_setup_true_lang-AyCP8jjY.js → FeaturePageGate.vue_vue_type_script_setup_true_lang-Dc_Lj6N5.js} +1 -1
  18. package/dist/{FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-3BBkd3fK.js → FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-CpB6jfVR.js} +1 -1
  19. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DxiyDPE4.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-_RqcUvn1.js} +2 -2
  20. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-NbqdrNZC.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BewIoyJq.js} +2 -2
  21. package/dist/{FmMultiselectDialog-C6v0K8O_.js → FmMultiselectDialog-CYCVAv1G.js} +2 -2
  22. package/dist/{FmMultiselectDialog-CbjJjImr.js → FmMultiselectDialog-DT7uPM66.js} +2 -2
  23. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-WmoFkpEY.js → FmUnitInput.vue_vue_type_script_setup_true_lang-2eASRTS_.js} +5 -5
  24. package/dist/{ImportView-CWp4v9Fw.js → ImportView-WW2X66rs.js} +7 -7
  25. package/dist/{IngredientsView-CA1_zt7Z.js → IngredientsView-B3wYe9Sb.js} +15 -15
  26. package/dist/{IntegrationExplorerView-De9Kzwnn.js → IntegrationExplorerView-BSYTMmyx.js} +6 -6
  27. package/dist/{IntegrationPlatformView-B50Phqtk.js → IntegrationPlatformView-DLsgFSW3.js} +2 -2
  28. package/dist/{IntegrationView-B6uYjzkw.js → IntegrationView-f-6i3IW-.js} +15 -15
  29. package/dist/{InventoryBindingForm-DJ30AwVX.js → InventoryBindingForm-Dn1gDSYA.js} +1 -1
  30. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-Bz-ZlZr0.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-D14GHsTr.js} +4 -4
  31. package/dist/{InventoryBindingSummary-DeBaiXQl.js → InventoryBindingSummary-CPjxxMgY.js} +1 -1
  32. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DWr79uhC.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Nhnc5fm7.js} +2 -2
  33. package/dist/{ProductionRunDetailPage-C1bTPmbW.js → ProductionRunDetailPage-BmH4UM7y.js} +4 -4
  34. package/dist/{ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-DBIoS4Lh.js → ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-CAT6wWf0.js} +8 -8
  35. package/dist/{ProductionRunPage-BjvU_1VH.js → ProductionRunPage-BF7rqTn7.js} +4 -4
  36. package/dist/{PublishView-hNen_JwE.js → PublishView-CHHUYo4m.js} +5 -5
  37. package/dist/{PurchaseOrderPrintPreview-CsUbnmIe.js → PurchaseOrderPrintPreview-5a4qj3eY.js} +2 -2
  38. package/dist/{ReceiveRequestView-0InxDJ3M.js → ReceiveRequestView--oyp49iL.js} +14 -14
  39. package/dist/{RecipeView-bCcgkdE6.js → RecipeView-lfkqibuU.js} +16 -16
  40. package/dist/{SettingsView-C4pni2wW.js → SettingsView-B7t1rWaE.js} +7 -7
  41. package/dist/{StockView-C0XG_9B6.js → StockView-CNqMpHio.js} +21 -21
  42. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CA8HcdSr.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Cw4q-B5E.js} +1 -1
  43. package/dist/{SupplierView-_PvNpWiU.js → SupplierView-BpwkcdGC.js} +13 -13
  44. package/dist/{SurchargeView-3rxIcCh2.js → SurchargeView-DcN1DxcO.js} +7 -7
  45. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-BziSnRwh.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-Dx7OJu5i.js} +2 -2
  46. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CapbC0-B.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Db-0enSJ.js} +1 -1
  47. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-u_wcCBvQ.js → TransferDetails.vue_vue_type_script_setup_true_lang-r1X46S49.js} +21 -21
  48. package/dist/{TransferTemplateView-D0LPeds-.js → TransferTemplateView-BpkNNXQO.js} +19 -19
  49. package/dist/{UnitCostHistoryView-CT9_LcqD.js → UnitCostHistoryView-B1Cb28gJ.js} +4 -4
  50. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-DjUxPx5x.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-Dw4vYOJB.js} +4 -4
  51. package/dist/{UnitView-B0b_LWAr.js → UnitView-BpG95geA.js} +7 -7
  52. package/dist/{WarehouseView-WwtqpXFc.js → WarehouseView-CD03O20D.js} +8 -8
  53. package/dist/{WastageTemplateView-BrJb7i3s.js → WastageTemplateView-B5zb2M1G.js} +15 -15
  54. package/dist/{app-DMR8lGeI.js → app-EBU-NyD3.js} +14 -14
  55. package/dist/app.js +1 -1
  56. package/dist/{bulk-edit-simulation.helper-BodN3Ovb.js → bulk-edit-simulation.helper-iXqP-Afi.js} +2 -2
  57. package/dist/{closing-template-D8-w7dJR.js → closing-template-BExcgt_y.js} +1 -1
  58. package/dist/{date2-gSK_CaAD.js → date2-BrsjI6gr.js} +1 -1
  59. package/dist/{dayjs.min-DYqzr2b4.js → dayjs.min-DhHR1Atx.js} +1 -1
  60. package/dist/{decimal-CV2CbIP_.js → decimal-CIjtFLFM.js} +2 -2
  61. package/dist/{defineDeepModel-Cgts0baA.js → defineDeepModel-D8_jChhs.js} +1 -1
  62. package/dist/{duplicate-template-_QC3-Dg0.js → duplicate-template-Drpx3l8P.js} +1 -1
  63. package/dist/{feature-Bzo4okfR.js → feature-CrqPX2nV.js} +2 -2
  64. package/dist/{format-time-from-id-D_mE0jBr.js → format-time-from-id-BRm36x25.js} +1 -1
  65. package/dist/{format-unit-display-Dd20Rit0.js → format-unit-display-CmuPkS0X.js} +12 -12
  66. package/dist/{id-to-date-BuMcKhAt.js → id-to-date-B8bZXCrJ.js} +1 -1
  67. package/dist/{import-export.helper-rzwKzV8j.js → import-export.helper-XRtJRsBy.js} +5 -5
  68. package/dist/{index-D2cksjKT.js → index-BQjvQ4jA.js} +1 -1
  69. package/dist/{index-B9qwc0uO.js → index-COCHojZC.js} +3 -3
  70. package/dist/{index-4hXkHXmU.js → index-VYeDb0tU.js} +1 -1
  71. package/dist/{lz-string-COQMQMdP.js → lz-string-Cysh8zS1.js} +1 -1
  72. package/dist/{netsuite-DpV5ZMba.js → netsuite-DH_dLLGS.js} +2 -2
  73. package/dist/{netsuite-explorer-CIr8qGIj.js → netsuite-explorer-B7PSwbUs.js} +1 -1
  74. package/dist/{predefined-templates-BtUdyeYn.js → predefined-templates-DFbOloni.js} +1 -1
  75. package/dist/{publish-versions-BqVzJN6P.js → publish-versions-CkkPlQvJ.js} +1 -1
  76. package/dist/{purchase-order-template-DxLHYHnX.js → purchase-order-template-ZW2RQLI0.js} +1 -1
  77. package/dist/{recalculationUtils-Bo2_wEwi.js → recalculationUtils-Dvp3I_bZ.js} +1 -1
  78. package/dist/{row-action.enum-CHpsNnrw.js → row-action.enum-CpWt9pKv.js} +1 -1
  79. package/dist/{rules-xgpOOQLG.js → rules-tQ6dVbmR.js} +3 -3
  80. package/dist/{stock-DrM-LYXO.js → stock-Ca1gJEgm.js} +2 -2
  81. package/dist/{stock-DBLaI4RH.js → stock-DgZrIUgV.js} +1 -1
  82. package/dist/{supplier-C476fF0r.js → supplier-DXmkyzoG.js} +2 -2
  83. package/dist/{surcharge-Nr5deDxT.js → surcharge-zNev4QX6.js} +1 -1
  84. package/dist/tsconfig.app.tsbuildinfo +1 -1
  85. package/dist/{uom-rules-BfpbgbnI.js → uom-rules-CYMN0gFj.js} +1 -1
  86. package/dist/use-ingredient-select-dialog-CtXkM-zf.js +56 -0
  87. package/dist/{use-inventory-binding-dialog-C2QWjvLV.js → use-inventory-binding-dialog-C3Y8dQeX.js} +2 -2
  88. package/dist/{use-template-enabled-locations-DdOyqrZw.js → use-template-enabled-locations-CsqFfXDC.js} +2 -2
  89. package/dist/{use-transfer-locations-C96gYh0y.js → use-transfer-locations-B18yKDME.js} +2 -2
  90. package/dist/{useHrmPermission-D35mRgdj.js → useHrmPermission-Dg8Vmlv1.js} +1 -1
  91. package/dist/{useNavigationMenu-9aQZjIuP.js → useNavigationMenu--7ucF68d.js} +5 -5
  92. package/dist/{useSseClient-CrK7D2Lk.js → useSseClient-DsXyp1gS.js} +1 -1
  93. package/dist/{vue-ueg1t-sr.js → vue-Dw4OoOfe.js} +2 -2
  94. package/dist/{vue-i18n-C9MdGWJ_.js → vue-i18n-gs-FmaMq.js} +127 -127
  95. package/dist/{xlsx.util-kkTKpxAB.js → xlsx.util-D_AjvL9p.js} +2 -2
  96. package/package.json +6 -6
  97. package/dist/ClosingTemplateView-Dc2EI6Ir.js +0 -2392
  98. package/dist/use-ingredient-select-dialog-IuYDEpDR.js +0 -52
@@ -0,0 +1,2409 @@
1
+ import { defineComponent as ee, resolveComponent as G, createElementBlock as T, openBlock as h, createElementVNode as i, createCommentVNode as O, normalizeClass as Z, createTextVNode as W, toDisplayString as S, unref as f, createVNode as A, withCtx as Y, Fragment as K, renderList as X, ref as z, computed as L, watch as De, createSlots as Ze, createBlock as H, h as Pe, createStaticVNode as et, normalizeStyle as Me, withDirectives as tt, isRef as Oe, vModelText as ot, withModifiers as we, Teleport as nt, normalizeProps as st, guardReactiveProps as at, mergeProps as lt } from "vue";
2
+ import { u as rt, _ as it } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DpwneGOV.js";
3
+ import { useCoreStore as Ee, useI18n as oe } from "@feedmepos/mf-common";
4
+ import { useDialogChild as ct, useSnackbar as me, useDialog as Ae, FmButtonVariant as $e, components as ut, useProxiedModel as dt, useBreakpoints as mt } from "@feedmepos/ui-library";
5
+ import { defineStore as He, storeToRefs as je } from "pinia";
6
+ import { F as te } from "./form-mode.enum-BKiNVH6A.js";
7
+ import { a as pe } from "./closing-template-BExcgt_y.js";
8
+ import { a as fe, m as pt, u as Ne, c as Ye, S as ze } from "./app-EBU-NyD3.js";
9
+ import { t as Fe, a as Be, d as Le, s as Ke, r as ft } from "./xlsx.util-D_AjvL9p.js";
10
+ import { F as yt } from "./FmDroppableField-J0tG_U3w.js";
11
+ import { f as We, b as Ie } from "./date2-BrsjI6gr.js";
12
+ import { u as vt } from "./netsuite-DH_dLLGS.js";
13
+ import { D as Ce, R as q } from "./row-action.enum-CpWt9pKv.js";
14
+ import { c as gt } from "./component-BmLAdDiY.js";
15
+ import { f as bt } from "./format-time-from-id-BRm36x25.js";
16
+ import { _ as ht } from "./TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Db-0enSJ.js";
17
+ import { u as _t } from "./duplicate-template-Drpx3l8P.js";
18
+ import { _ as xt } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BewIoyJq.js";
19
+ import { _ as kt } from "./CursorPaginatedTable.vue_vue_type_script_setup_true_lang-BCUhtL_B.js";
20
+ import { R as wt, A as $t } from "./rules-tQ6dVbmR.js";
21
+ import { u as Qe } from "./use-ingredient-select-dialog-CtXkM-zf.js";
22
+ import { d as Ct } from "./defineDeepModel-D8_jChhs.js";
23
+ import { _ as Tt } from "./FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-AnSwoMnm.js";
24
+ import { u as It } from "./use-template-enabled-locations-CsqFfXDC.js";
25
+ import { _ as Ft } from "./SystemTrailDialog.vue_vue_type_script_setup_true_lang-Dx7OJu5i.js";
26
+ import { _ as St } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-gJQQKKAC.js";
27
+ import { F as Te } from "./index-eGvSlWMU.js";
28
+ import { _ as Dt } from "./_plugin-vue_export-helper-CHgC5LLL.js";
29
+ var Ue = /* @__PURE__ */ ((r) => (r.Ingredients = "Ingredients", r))(Ue || {});
30
+ function qe(r) {
31
+ const t = r.sku, e = new Set(r.disabledMeasurements);
32
+ return [
33
+ {
34
+ code: t.code,
35
+ name: t.name,
36
+ unit: t.unit.abbrev,
37
+ enabled: !e.has(t.unit._id)
38
+ },
39
+ ...t.unit.measurements.map((y) => ({
40
+ unit: y.abbrev,
41
+ enabled: !e.has(y.id)
42
+ }))
43
+ ];
44
+ }
45
+ function Je() {
46
+ return [
47
+ {
48
+ id: "code",
49
+ name: "Code"
50
+ },
51
+ {
52
+ id: "name",
53
+ name: "Name"
54
+ },
55
+ {
56
+ id: "unit",
57
+ name: "Unit"
58
+ },
59
+ {
60
+ id: "enabled",
61
+ name: "Enabled"
62
+ }
63
+ ];
64
+ }
65
+ function At(r) {
66
+ var C;
67
+ const e = Ee().currentBusiness.value, m = (C = r.map((u) => {
68
+ var x;
69
+ const a = u.items.flatMap(qe), b = Je(), l = [
70
+ ["Template ID", u._id],
71
+ ["Template name", u.name],
72
+ ["Business name", e == null ? void 0 : e.name],
73
+ ["Business ID", e == null ? void 0 : e._id],
74
+ ["Menu version", e == null ? void 0 : e.menuVersion],
75
+ [
76
+ "Locations",
77
+ ...(x = u.locations) != null && x.length ? u.locations.map((c) => `${c.name} (${c.dbName})`) : ["All"]
78
+ ],
79
+ ["Reference", u.ref ?? ""],
80
+ [],
81
+ b.map((c) => c.name),
82
+ ...a.map((c) => b.map((s) => c[s.id]))
83
+ ], D = b.map((c) => `system:${c.id}`), w = Fe(l, D);
84
+ return { name: u.name, sheet: w };
85
+ }).reduce(
86
+ (u, a) => {
87
+ var l;
88
+ const b = a.name.slice(0, 12);
89
+ return (l = u.sheetOccurence)[b] ?? (l[b] = 0), u.sheetOccurence[b] += 1, u.sheets[`${b} (${u.sheetOccurence[b]})`] = a.sheet, u;
90
+ },
91
+ {
92
+ sheets: {},
93
+ sheetOccurence: {}
94
+ }
95
+ )) == null ? void 0 : C.sheets, y = `${e == null ? void 0 : e.name} closing templates (${We(/* @__PURE__ */ new Date())}).xlsx`, v = Be(m);
96
+ return Le(v, y), y;
97
+ }
98
+ function Rt(r) {
99
+ Ee().currentBusiness.value;
100
+ const e = 3, _ = (l) => {
101
+ const D = [], w = l.sku, x = new Set(l.disabledMeasurements || []);
102
+ x.has(w.unit._id) || D.push(w.unit.abbrev);
103
+ for (const c of w.unit.measurements) {
104
+ if (D.length >= e) break;
105
+ x.has(c.id) || D.push(c.abbrev);
106
+ }
107
+ return D;
108
+ }, m = ["#", "Code", "Name", "UOM"], y = [
109
+ ["Template:", r.name],
110
+ ["Reference:", r.ref ?? ""],
111
+ [],
112
+ m,
113
+ ...r.items.map((l, D) => {
114
+ const w = _(l);
115
+ return [
116
+ D + 1,
117
+ // Index starting from 1
118
+ l.sku.code,
119
+ l.sku.name,
120
+ // Add UOM columns (up to MAX_UOM_COLUMNS)
121
+ ...Array(e).fill("").map(
122
+ (x, c) => w[c] ? `_____ ${w[c]}` : ""
123
+ )
124
+ ];
125
+ })
126
+ ], v = Fe(y, m);
127
+ if (v["!ref"]) {
128
+ const l = {
129
+ top: { style: "thin", color: { rgb: "000000" } },
130
+ bottom: { style: "thin", color: { rgb: "000000" } },
131
+ left: { style: "thin", color: { rgb: "000000" } },
132
+ right: { style: "thin", color: { rgb: "000000" } }
133
+ }, D = 4, w = D + r.items.length, x = m.map((c, s) => String.fromCharCode(65 + s));
134
+ for (let c = D; c <= w; c++)
135
+ x.forEach((s) => {
136
+ const $ = `${s}${c}`;
137
+ v[$] || (v[$] = { t: "s", v: "" }), v[$].s = {
138
+ border: l
139
+ };
140
+ });
141
+ }
142
+ v["!cols"] = [
143
+ { wch: 5 },
144
+ // Index column - narrow
145
+ { wch: 15 },
146
+ // Code column
147
+ { wch: 30 },
148
+ // Name column - adjusted for more columns
149
+ ...Array.from({ length: e }, () => ({ wch: 15 }))
150
+ // UOM columns
151
+ ], v["!margins"] = {
152
+ left: 0.7,
153
+ right: 0.7,
154
+ top: 0.75,
155
+ bottom: 0.75,
156
+ header: 0.3,
157
+ footer: 0.3
158
+ };
159
+ const u = r.name.slice(0, 31), a = Be({ [u]: v }), b = `${r.name} - Closing Template (${We(/* @__PURE__ */ new Date())}).xlsx`;
160
+ return Le(a, b), b;
161
+ }
162
+ function Pt() {
163
+ const r = Ee(), t = fe(), e = vt(), _ = qe({
164
+ sku: {
165
+ unit: {
166
+ _id: "",
167
+ name: "Unit",
168
+ abbrev: "Unit",
169
+ precision: 0,
170
+ measurements: []
171
+ },
172
+ code: "ING001",
173
+ _id: "",
174
+ name: "Sugar"
175
+ }
176
+ })[0], m = r.currentBusiness.value, y = Je(), v = [
177
+ ["Template ID (leave empty to create new)", ""],
178
+ ["Template Name", "New template"],
179
+ ["Business name", m == null ? void 0 : m.name],
180
+ ["Business ID", m == null ? void 0 : m._id],
181
+ ["Menu version", m == null ? void 0 : m.menuVersion],
182
+ [
183
+ "Location codes (leave empty to enable all)",
184
+ "Example outlet (restaurant_xxx)",
185
+ "Example outlet 2 (restaurant_xxx)"
186
+ ],
187
+ ["Reference:"],
188
+ [],
189
+ y.map((x) => x.name),
190
+ y.map((x) => _[x.id])
191
+ ], C = y.map((x) => `system:${x.id}`), u = Fe(v, C), a = e.isEnabled ? e.state.setting.childItems ?? [] : [], b = a.reduce(
192
+ (x, c) => {
193
+ var F, P;
194
+ const s = (F = e.netSuiteItemIdToSkuId.get(c.parentNetSuiteId)) == null ? void 0 : F[0], $ = (P = e.netSuiteMeasurementIdToMeasurementId.get(
195
+ c.unitOfMeasureId
196
+ )) == null ? void 0 : P[0];
197
+ if (!c.externalId)
198
+ return x;
199
+ if (!s)
200
+ return console.error(`Item ${c.externalId} cannot be mapped to parent FdoInventorySku.`, c), x;
201
+ const o = t.skuById[s], k = o.unit.measurements.find((n) => n.id === $);
202
+ return k ? (x[c.externalId] = {
203
+ sku: o,
204
+ measurement: k
205
+ }, x) : (console.error(
206
+ `Item ${c.externalId} found parent FdoInventorySku of ${o.code} ${o.name} but the measurement of netsuite id ${c.unitOfMeasureId} cannot be found.`,
207
+ c
208
+ ), x);
209
+ },
210
+ {}
211
+ ), l = Fe(
212
+ [
213
+ ...t.skus.flatMap((x) => [
214
+ [x.code, x.name, x.unit.abbrev, !0],
215
+ ...x.unit.measurements.map((s) => [
216
+ "",
217
+ "",
218
+ s.abbrev,
219
+ !s.abbrev.toLocaleLowerCase("en-us").includes("inactive")
220
+ ])
221
+ ]),
222
+ ...Object.entries(b).map(([x, { sku: c, measurement: s }]) => [
223
+ c.code,
224
+ c.name,
225
+ s.abbrev,
226
+ !s.abbrev.toLocaleLowerCase("en-us").includes("inactive"),
227
+ x
228
+ ])
229
+ ],
230
+ [
231
+ "Code",
232
+ "Name",
233
+ "Units",
234
+ "Enabled (true/false)",
235
+ ...a.length ? ["Netsuite Parent"] : []
236
+ ]
237
+ ), D = Be({
238
+ Template: u,
239
+ Ingredients: l
240
+ }), w = `${m == null ? void 0 : m.name} transfer templates import.xlsx`;
241
+ return Le(D, w), w;
242
+ }
243
+ function Mt(r) {
244
+ if (!r.length || `${r[0]}`.toLocaleLowerCase() === "all")
245
+ return [];
246
+ const t = /(.*) \(((warehouse_|restaurant_).{24,})\)/, _ = Ne().locationByDbName;
247
+ return r.map((m) => {
248
+ const y = new Array(), v = m.trim(), C = t.exec(v);
249
+ if (!C)
250
+ return y.push(`Enabled location value of ${v} cannot be read.`), {
251
+ errors: y
252
+ };
253
+ const u = C[1], a = C[2], b = _[a];
254
+ return b ? (u !== b.name && y.push(
255
+ `Location id ${a} has non-matching name. Found ${u} but expected ${b.name}`
256
+ ), {
257
+ errors: y,
258
+ location: b
259
+ }) : (y.push(`Location (${u}) of id ${a} is not found.`), {
260
+ errors: y
261
+ });
262
+ });
263
+ }
264
+ function Et(r) {
265
+ const [
266
+ t,
267
+ e,
268
+ _,
269
+ m,
270
+ y,
271
+ v,
272
+ C,
273
+ u
274
+ ] = Ke(r);
275
+ return {
276
+ id: `${e[1] ?? ""}`.trim(),
277
+ name: `${_[1] ?? ""}`.trim(),
278
+ locations: C.slice(1).map((a) => `${a}`.trim()).filter((a) => a),
279
+ reference: `${u[1] ?? ""}`.trim()
280
+ };
281
+ }
282
+ function Nt(r) {
283
+ const [
284
+ t,
285
+ e,
286
+ _,
287
+ m,
288
+ y,
289
+ v,
290
+ C,
291
+ u,
292
+ a,
293
+ b,
294
+ ...l
295
+ ] = Ke(r);
296
+ if (!t || !t.length || t.some((s) => s.length && !s.startsWith("system:")))
297
+ throw new Error("Missing meta header. Excel file does not come from the template.");
298
+ const D = t.map((s) => s.split(":")[1]), x = ["code", "name", "unit", "enabled"].filter((s) => !D.includes(s));
299
+ if (x.length)
300
+ throw new Error(
301
+ `Missing meta headers (${x.join()}). Excel file does not come from the template.`
302
+ );
303
+ return l.map((s, $) => {
304
+ const o = {};
305
+ for (const k in D) {
306
+ const F = D[k];
307
+ Object.assign(o, { [F]: s[k] });
308
+ }
309
+ return {
310
+ index: $,
311
+ data: o
312
+ };
313
+ });
314
+ }
315
+ function Bt(r) {
316
+ return r.reduce(
317
+ (t, e) => {
318
+ var y;
319
+ const _ = e.data, m = e.index;
320
+ return _.unit && (_.code ? t.result.push({ parent: e, children: [] }) : t.result.length ? (y = t.result.at(-1)) == null || y.children.push(e) : t.errors.push(`Cannot find parent for row ${m + 9}`)), t;
321
+ },
322
+ { result: new Array(), errors: new Array() }
323
+ );
324
+ }
325
+ function Lt(r) {
326
+ const t = r.parent.data, e = new Array(), m = fe().skuByCode[t.code ?? ""];
327
+ if (!m)
328
+ return e.push(`Cannot find ingredient of code ${t.code} ${t.name}`), { errors: e };
329
+ const y = {
330
+ sku: m
331
+ }, v = /* @__PURE__ */ new Set([m.unit._id, ...m.unit.measurements.map((u) => u.id)]), C = m.unit.measurements.find((u) => u.abbrev === t.unit);
332
+ t.unit !== m.unit.abbrev && !C ? e.push(
333
+ `Cannot find measurement unit of ${t.unit} for (${t.code}) ${t.name}.`
334
+ ) : (t.enabled === !0 || `${t.enabled}`.toLocaleLowerCase() === "true") && v.delete(m.unit._id);
335
+ for (const u of r.children) {
336
+ const a = u.data, b = a.unit === m.unit.abbrev ? m.unit : void 0, l = m.unit.measurements.find((D) => D.abbrev === a.unit);
337
+ if (!l && !b) {
338
+ e.push(
339
+ `Cannot find measurement unit of ${a.unit} for (${t.code}) ${t.name}.`
340
+ );
341
+ continue;
342
+ }
343
+ (a.enabled === !0 || `${a.enabled}`.toLocaleLowerCase() === "true") && v.delete((l == null ? void 0 : l.id) ?? (b == null ? void 0 : b._id) ?? "");
344
+ }
345
+ return v.has(m.unit._id) && y.sku.unit.measurements.every((u) => v.has(u.id)) && e.push(`Ingredient ${m.code} - ${m.name} must have at least one unit enabled.`), y.disabledMeasurements = [...v], { errors: e, templateItem: y };
346
+ }
347
+ async function Ut(r) {
348
+ const t = r.SheetNames.filter(
349
+ (y) => !Object.values(Ue).map(String).includes(y)
350
+ ), _ = await pe().readTemplates(), m = pt(_, "_id");
351
+ try {
352
+ return t.reduce(
353
+ (y, v) => {
354
+ const C = new Array(), u = r.Sheets[v], a = Et(u), b = Mt(a.locations), l = b.filter((o) => o.location).map((o) => o.location);
355
+ C.push(...b.flatMap((o) => o.errors));
356
+ const D = Nt(u).filter(
357
+ (o) => o.data.code || o.data.unit
358
+ ), w = Bt(D);
359
+ C.push(...w.errors);
360
+ const x = w.result.map(
361
+ (o) => Lt(o)
362
+ );
363
+ C.push(...x.flatMap((o) => o.errors));
364
+ const c = x.filter((o) => o.templateItem).map((o) => o.templateItem);
365
+ if (a.id) {
366
+ const o = m[a.id];
367
+ if (!o) {
368
+ const F = {
369
+ _id: a.id,
370
+ _rev: "",
371
+ name: a.name || `(unnamed from sheet ${v || "<unnamed sheet>"})`,
372
+ items: []
373
+ };
374
+ return C.push(`Template ID ${a.id} is not found.`), y.importUpdateResult.push({
375
+ type: "update",
376
+ original: F,
377
+ template: F,
378
+ excelSheetName: v,
379
+ errors: C
380
+ }), y;
381
+ }
382
+ const k = {
383
+ type: "update",
384
+ original: o,
385
+ template: {
386
+ ...o,
387
+ name: a.name,
388
+ locations: l.length ? l : null,
389
+ ref: a.reference,
390
+ items: c
391
+ },
392
+ excelSheetName: v,
393
+ errors: C
394
+ };
395
+ return y.importUpdateResult.push(k), y;
396
+ }
397
+ const $ = {
398
+ type: "create",
399
+ template: {
400
+ name: a.name,
401
+ locations: l.length ? l : null,
402
+ ref: a.reference,
403
+ items: c
404
+ },
405
+ excelSheetName: v,
406
+ errors: C
407
+ };
408
+ return y.importCreateResult.push($), y;
409
+ },
410
+ {
411
+ invalidExcel: !1,
412
+ importCreateResult: new Array(),
413
+ importUpdateResult: new Array()
414
+ }
415
+ );
416
+ } catch (y) {
417
+ return {
418
+ invalidExcel: !0,
419
+ invalidExcelMessage: (y == null ? void 0 : y.message) ?? "Invalid excel",
420
+ importCreateResult: [],
421
+ importUpdateResult: []
422
+ };
423
+ }
424
+ }
425
+ const Vt = { class: "flex items-center gap-12 pl-8" }, zt = { class: "flex flex-col" }, Gt = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary flex items-center gap-4" }, Ot = {
426
+ key: 0,
427
+ class: "text-fm-color-typo-secondary fm-typo-en-body-sm-400"
428
+ }, Ht = { key: 0 }, Ge = /* @__PURE__ */ ee({
429
+ __name: "ClosingTemplateImportItem",
430
+ props: {
431
+ type: {},
432
+ name: {},
433
+ locations: {},
434
+ items: {},
435
+ errors: {}
436
+ },
437
+ setup(r) {
438
+ const { t } = oe();
439
+ return (e, _) => {
440
+ var v, C, u;
441
+ const m = G("FmIcon"), y = G("FmTooltip");
442
+ return h(), T("div", Vt, [
443
+ _[0] || (_[0] = i("div", null, "•", -1)),
444
+ i("div", zt, [
445
+ i("div", Gt, [
446
+ i("div", {
447
+ class: Z({
448
+ "text-fm-color-system-error-300": e.errors.length
449
+ })
450
+ }, [
451
+ W(S(e.name) + " ", 1),
452
+ e.type === "create" ? (h(), T("span", Ot, "(" + S(f(t)("inventory.closing.template.import.new")) + ")", 1)) : O("", !0)
453
+ ], 2),
454
+ e.errors.length ? (h(), T("div", Ht, [
455
+ A(y, { "z-index": 50 }, {
456
+ content: Y(() => [
457
+ i("ol", null, [
458
+ (h(!0), T(K, null, X(e.errors, (a, b) => (h(), T("li", { key: b }, S(a), 1))), 128))
459
+ ])
460
+ ]),
461
+ default: Y(() => [
462
+ A(m, {
463
+ name: "error",
464
+ size: "sm",
465
+ color: "system-error-300"
466
+ })
467
+ ]),
468
+ _: 1
469
+ })
470
+ ])) : O("", !0)
471
+ ]),
472
+ i("div", {
473
+ class: Z([
474
+ "fm-typo-en-body-sm-400",
475
+ {
476
+ "text-fm-color-system-error-200": e.errors.length,
477
+ "text-fm-color-typo-secondary": !e.errors.length
478
+ }
479
+ ])
480
+ }, S((v = e.locations) != null && v.length ? f(t)("inventory.closing.template.import.nLocations", { count: (C = e.locations) == null ? void 0 : C.length }) : f(t)("inventory.closing.template.import.allLocations")) + ", " + S(f(t)("inventory.closing.template.import.nItems", { count: (u = e.items) == null ? void 0 : u.length })), 3)
481
+ ])
482
+ ]);
483
+ };
484
+ }
485
+ }), jt = { class: "flex flex-col gap-24" }, Yt = { class: "fm-typo-en-body-md-400" }, Kt = {
486
+ key: 0,
487
+ class: "flex items-center gap-8"
488
+ }, Wt = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Qt = { class: "flex flex-col gap-8" }, qt = { class: "line-clamp-2 text-ellipsis break-all" }, Jt = {
489
+ key: 2,
490
+ class: "shrink-0"
491
+ }, Xt = {
492
+ key: 0,
493
+ class: "flex flex-col"
494
+ }, Zt = { class: "text-fm-color-system-error-300 fm-typo-en-body-sm-400" }, eo = {
495
+ key: 0,
496
+ class: "max-h-[200px] overflow-y-auto flex flex-col gap-8"
497
+ }, to = { class: "fm-typo-en-body-lg-600" }, oo = /* @__PURE__ */ ee({
498
+ __name: "ClosingTemplateImport",
499
+ setup(r) {
500
+ const t = z(null), e = ct(), _ = me(), m = z(!1), y = z(!1), v = z(new Array()), C = z([]), u = z([]), a = L(
501
+ () => !!v.value.length || C.value.some((w) => w.errors.length) || u.value.some((w) => w.errors.length)
502
+ ), b = L(
503
+ () => !!C.value.length || !!u.value.length
504
+ ), { t: l } = oe();
505
+ async function D(w) {
506
+ v.value = [], C.value = [], u.value = [];
507
+ try {
508
+ m.value = !0;
509
+ const [x] = await Promise.all([
510
+ ft(w),
511
+ // fake buffer
512
+ new Promise((o) => setTimeout(o, 1e3))
513
+ ]);
514
+ if (!x.SheetNames.filter(
515
+ (o) => !Object.values(Ue).map(String).includes(o)
516
+ ).find((o) => o)) {
517
+ v.value.push(l("inventory.ingredient.import.fileError.noSheet"));
518
+ return;
519
+ }
520
+ const $ = await Ut(x);
521
+ if ($.invalidExcel) {
522
+ v.value.push(
523
+ $.invalidExcelMessage ?? l("inventory.ingredient.import.fileError.invalidExcel")
524
+ );
525
+ return;
526
+ }
527
+ if (C.value = $.importCreateResult, u.value = $.importUpdateResult, !C.value.length && !u.value.length) {
528
+ v.value.push(l("inventory.ingredient.import.fileError.noData"));
529
+ return;
530
+ }
531
+ e.emitData($);
532
+ } catch (x) {
533
+ _.open({
534
+ title: l("inventory.ingredient.import.fileError.unableToRead"),
535
+ message: x == null ? void 0 : x.message,
536
+ type: "error"
537
+ }), console.error("Error in reading file", x);
538
+ } finally {
539
+ v.value.length && _.open({
540
+ title: l("inventory.ingredient.import.fileError.invalidExcel"),
541
+ type: "error"
542
+ }), m.value = !1;
543
+ }
544
+ }
545
+ return De(t, (w) => {
546
+ w && D(w);
547
+ }), (w, x) => {
548
+ const c = G("FmCircularProgress"), s = G("FmIcon"), $ = G("FmButton");
549
+ return h(), T("div", jt, [
550
+ i("div", Yt, S(f(l)("inventory.closing.template.import.message")), 1),
551
+ y.value ? (h(), T("div", Kt, [
552
+ i("div", null, [
553
+ A(c, {
554
+ size: "md",
555
+ color: "neutral-gray-200"
556
+ })
557
+ ]),
558
+ i("div", Wt, S(f(l)("inventory.formField.loading")), 1)
559
+ ])) : (h(), T(K, { key: 1 }, [
560
+ A(yt, {
561
+ class: Z({
562
+ "w-full": !0,
563
+ "h-[200px]": !t.value
564
+ }),
565
+ accept: ".xlsx",
566
+ onFileUpload: x[0] || (x[0] = (o) => t.value = o),
567
+ label: f(l)("inventory.ingredient.import.uploadTemplate"),
568
+ "button-label": f(l)("inventory.ingredient.import.selectFile")
569
+ }, Ze({ _: 2 }, [
570
+ t.value ? {
571
+ name: "default",
572
+ fn: Y(({ openFileDialog: o }) => [
573
+ i("div", Qt, [
574
+ i("div", {
575
+ class: Z([
576
+ "fm-corner-radius-md p-16 flex items-center gap-16",
577
+ {
578
+ "border border-fm-color-neutral-gray-100": m.value,
579
+ "border border-fm-color-neutral-gray-200": !m.value && !a.value,
580
+ "border border-fm-color-system-error-200": a.value
581
+ }
582
+ ])
583
+ }, [
584
+ m.value ? (h(), H(c, {
585
+ key: 0,
586
+ size: "md",
587
+ color: "neutral-gray-200"
588
+ })) : (h(), H(s, {
589
+ key: 1,
590
+ name: a.value ? "error" : "attach_file",
591
+ outline: "",
592
+ color: a.value ? "system-error-300" : void 0
593
+ }, null, 8, ["name", "color"])),
594
+ i("div", {
595
+ class: Z([
596
+ "fm-typo-en-body-md-400 flex-1 h-[36px] flex items-center",
597
+ {
598
+ "text-fm-color-typo-disabled": m.value,
599
+ "text-fm-color-typo-primary": !m.value
600
+ }
601
+ ])
602
+ }, [
603
+ i("div", qt, S(t.value.name), 1)
604
+ ], 2),
605
+ m.value ? O("", !0) : (h(), T("div", Jt, [
606
+ A($, {
607
+ label: f(l)("inventory.ingredient.import.replaceFile"),
608
+ variant: a.value ? "destructive" : "secondary",
609
+ "prepend-icon": a.value ? void 0 : "autorenew",
610
+ onClick: o
611
+ }, null, 8, ["label", "variant", "prepend-icon", "onClick"])
612
+ ]))
613
+ ], 2),
614
+ v.value.length ? (h(), T("div", Xt, [
615
+ (h(!0), T(K, null, X(v.value, (k, F) => (h(), T("div", {
616
+ key: F,
617
+ class: "flex gap-8 items-center"
618
+ }, [
619
+ A(s, {
620
+ name: "error",
621
+ size: "sm",
622
+ color: "system-error-300"
623
+ }),
624
+ i("div", Zt, S(k), 1)
625
+ ]))), 128))
626
+ ])) : O("", !0)
627
+ ])
628
+ ]),
629
+ key: "0"
630
+ } : void 0
631
+ ]), 1032, ["class", "label", "button-label"]),
632
+ b.value ? (h(), T("div", eo, [
633
+ i("div", to, S(f(l)("inventory.ingredient.import.summary")), 1),
634
+ (h(!0), T(K, null, X(C.value, (o, k) => (h(), H(Ge, {
635
+ key: k,
636
+ name: o.template.name,
637
+ locations: o.template.locations,
638
+ items: o.template.items,
639
+ errors: o.errors,
640
+ type: "create"
641
+ }, null, 8, ["name", "locations", "items", "errors"]))), 128)),
642
+ (h(!0), T(K, null, X(u.value, (o) => (h(), H(Ge, {
643
+ key: o.template._id,
644
+ name: o.template.name,
645
+ locations: o.template.locations,
646
+ items: o.template.items,
647
+ errors: o.errors,
648
+ type: "update"
649
+ }, null, 8, ["name", "locations", "items", "errors"]))), 128))
650
+ ])) : O("", !0)
651
+ ], 64))
652
+ ]);
653
+ };
654
+ }
655
+ }), Ve = He(
656
+ "closingTemplateTable",
657
+ function() {
658
+ var P;
659
+ const { t } = oe(), e = Ae(), _ = me();
660
+ function m(n) {
661
+ console.error("Row action failed:", n), _.open({
662
+ title: t("inventory.common.somethingWentWrong"),
663
+ message: (n == null ? void 0 : n.message) || t("inventory.common.tryAgain"),
664
+ type: "error"
665
+ });
666
+ }
667
+ const y = z({}), v = Se(), C = z({}), u = z(new Array()), a = z(!1), b = Ne(), l = pe();
668
+ function D(n) {
669
+ const d = {
670
+ title: n.name,
671
+ doc: n,
672
+ controller: {
673
+ publishAll: async (E) => {
674
+ const R = E || n.locations, N = await l.publishSingleDoc(
675
+ n._id,
676
+ R == null ? void 0 : R.map((U) => U.dbName)
677
+ );
678
+ return y.value = N.publishedRevByLocation || {}, y.value;
679
+ },
680
+ publishAtLocation: async (E) => {
681
+ const R = await l.publishSingleDoc(n._id, [E.dbName]);
682
+ return y.value = R.publishedRevByLocation || {}, y.value;
683
+ },
684
+ unpublishAll: async (E) => {
685
+ const R = E || n.locations, N = await l.unpublishSingleDoc(
686
+ n._id,
687
+ R == null ? void 0 : R.map((U) => U.dbName)
688
+ );
689
+ return y.value = N.publishedRevByLocation || {}, y.value;
690
+ },
691
+ unpublishAtLocation: async (E) => {
692
+ const R = await l.unpublishSingleDoc(n._id, [
693
+ E.dbName
694
+ ]);
695
+ return y.value = R.publishedRevByLocation || {}, y.value;
696
+ }
697
+ },
698
+ initialPublishedRev: y.value,
699
+ locations: b.locations,
700
+ enabledLocations: n.locations
701
+ };
702
+ e.open({
703
+ title: "Publish template",
704
+ contentComponent: ht,
705
+ contentComponentProps: d,
706
+ closeButton: !0,
707
+ minWidth: 700,
708
+ maxHeight: "80vh",
709
+ contentScrollable: !1,
710
+ primaryActions: {
711
+ text: t("common.close"),
712
+ close: !0,
713
+ variant: "tertiary"
714
+ }
715
+ });
716
+ }
717
+ const w = z(0);
718
+ let x = (P = b._currentLocation) == null ? void 0 : P.dbName;
719
+ async function c(n) {
720
+ if (!b._currentLocation) return { docs: [], nextStartkey: null, hasMore: !1 };
721
+ if (x = b._currentLocation.dbName, n.startkey) return l.listTemplatesPage(n);
722
+ const [d, E, R] = await Promise.all([
723
+ l.listTemplatesPage(n),
724
+ l.getRecentPublishingJob(),
725
+ l.getRecentPublishInfo()
726
+ ]);
727
+ return C.value = E, y.value = R.publishedRevByLocation || {}, d;
728
+ }
729
+ function s() {
730
+ u.value = [], w.value++;
731
+ }
732
+ async function $() {
733
+ var d;
734
+ ((d = b._currentLocation) == null ? void 0 : d.dbName) !== x && s();
735
+ }
736
+ async function o(n) {
737
+ if (!u.value.find((d) => d._id) && b._currentLocation) {
738
+ a.value = !0;
739
+ try {
740
+ const [d] = await Promise.all([
741
+ l.getTemplate(n),
742
+ new Promise((R) => setTimeout(R, 1e3))
743
+ ]), { toClosingTemplateListItem: E } = await import("./index-VYeDb0tU.js");
744
+ u.value = [
745
+ E(d)
746
+ ];
747
+ } catch (d) {
748
+ console.log("Something went wrong when fetching templates:", d);
749
+ } finally {
750
+ a.value = !1;
751
+ }
752
+ }
753
+ }
754
+ function k(n, d) {
755
+ switch (d = Ye(d), n) {
756
+ case q.Details:
757
+ return v.viewTemplate(d._id).catch(m);
758
+ case q.Edit:
759
+ return v.updateTemplate(d._id).catch(m);
760
+ case q.Delete:
761
+ return v.deleteTemplate(d, a, s);
762
+ case q.Publish:
763
+ return D(d);
764
+ case q.Duplicate:
765
+ return v.duplicateTemplate(d, a, s);
766
+ }
767
+ }
768
+ return {
769
+ columnDefs: [
770
+ {
771
+ id: "_id",
772
+ accessorKey: "_id",
773
+ header: () => t("inventory.closing.table.createdAt"),
774
+ cell(n) {
775
+ return bt(`${n.getValue()}`);
776
+ },
777
+ enableSorting: !0
778
+ },
779
+ {
780
+ id: "name",
781
+ accessorKey: "name",
782
+ header: () => t("inventory.closing.table.name"),
783
+ enableSorting: !0,
784
+ size: 200
785
+ },
786
+ {
787
+ id: "noOfItems",
788
+ accessorKey: "itemCount",
789
+ header: () => t("inventory.closing.table.noOfItems"),
790
+ enableSorting: !1,
791
+ meta: {
792
+ width: "10rem",
793
+ textAlign: "right"
794
+ }
795
+ },
796
+ {
797
+ id: "enabledLocations",
798
+ accessorKey: "locations.length",
799
+ header: () => t("inventory.closing.table.enabledOutlets"),
800
+ cell(n) {
801
+ var E;
802
+ const d = (E = n.row.original.locations) == null ? void 0 : E.length;
803
+ return d ? `${d}` : "All";
804
+ },
805
+ enableSorting: !1,
806
+ meta: {
807
+ width: "10rem",
808
+ textAlign: "right"
809
+ }
810
+ },
811
+ {
812
+ id: "ref",
813
+ accessorKey: "ref",
814
+ header: () => t("inventory.closing.table.reference"),
815
+ enableSorting: !1,
816
+ size: "auto"
817
+ },
818
+ {
819
+ id: "status",
820
+ header: () => t("inventory.adjustment.template.table.status"),
821
+ enableSorting: !1,
822
+ cell(n) {
823
+ const d = n.row.original, R = (n.row.original.locations || b.locations).filter((j) => !!b.locationByDbName[j.dbName]), N = R.filter((j) => !!(y.value[j.dbName] || []).find(
824
+ (Q) => Q._id === d._id && (Q.updatedAt ? Q.updatedAt === d.updatedAt : Q._rev === d._rev)
825
+ )).length, U = R.length > 0 && N === R.length;
826
+ return Pe(
827
+ "div",
828
+ {
829
+ class: "flex items-center gap-8"
830
+ },
831
+ Pe(
832
+ "div",
833
+ {
834
+ class: [
835
+ "fm-status-badge",
836
+ U ? "fm-status-badge-success-secondary" : "fm-status-badge-info-secondary"
837
+ ]
838
+ },
839
+ U ? "Published" : "Unpublished"
840
+ )
841
+ );
842
+ }
843
+ },
844
+ {
845
+ id: "action",
846
+ cell(n) {
847
+ const d = n.row.original, E = [
848
+ Ce[q.Edit],
849
+ Ce[q.Duplicate],
850
+ Ce[q.Delete],
851
+ Ce[q.Publish]
852
+ ];
853
+ return gt(E, (R) => k(R, d));
854
+ },
855
+ enableSorting: !1,
856
+ size: 40,
857
+ meta: {
858
+ cellClass: "",
859
+ headerClass: ""
860
+ }
861
+ }
862
+ ],
863
+ recentPublish: C,
864
+ templates: u,
865
+ loading: a,
866
+ tableKey: w,
867
+ fetchTemplatesPage: c,
868
+ refresh: s,
869
+ onLocationChanged: $,
870
+ loadTemplate: o
871
+ };
872
+ }
873
+ ), Se = He("closingTemplateActions", () => {
874
+ const { t: r } = oe(), t = Ae(), e = me(), _ = pe(), m = _t(), y = Ve(), { loading: v } = je(y), C = z({});
875
+ function u() {
876
+ C.value = {
877
+ mode: te.CREATE,
878
+ show: !0,
879
+ "onUpdate:show"(o) {
880
+ C.value.show = o;
881
+ }
882
+ };
883
+ }
884
+ async function a(o, k) {
885
+ const F = typeof o == "string" ? await _.getTemplate(o, k) : o;
886
+ return C.value = {
887
+ mode: te.UPDATE,
888
+ modelValue: F,
889
+ show: !0,
890
+ "onUpdate:show"(P) {
891
+ C.value.show = P;
892
+ }
893
+ }, F;
894
+ }
895
+ function b(o, k, F) {
896
+ t.open({
897
+ title: `Confirm deleting template ${o.name}?`,
898
+ message: "Deleted template can no longer be retrieved",
899
+ primaryActions: {
900
+ text: "Delete",
901
+ variant: $e.Destructive,
902
+ close: !0
903
+ },
904
+ secondaryActions: {
905
+ text: "Cancel",
906
+ variant: $e.Plain,
907
+ close: !0
908
+ }
909
+ }).onPrimary(async () => {
910
+ e.open({
911
+ title: `Deleting ${o.name}`,
912
+ type: "info"
913
+ });
914
+ try {
915
+ k.value = !0;
916
+ const [P] = await Promise.allSettled([
917
+ _.deleteTemplate(o),
918
+ new Promise((n) => setTimeout(n, 1e3))
919
+ ]);
920
+ if (P.status === "rejected") throw P.reason;
921
+ e.open({
922
+ title: `Deleted "${o.name}"`,
923
+ type: "success"
924
+ });
925
+ } catch (P) {
926
+ e.open({
927
+ title: `Unable to delete "${o.name}"`,
928
+ message: P.message,
929
+ type: "error"
930
+ });
931
+ } finally {
932
+ k.value = !1, F();
933
+ }
934
+ });
935
+ }
936
+ function l(o, k, F) {
937
+ let P;
938
+ t.open({
939
+ title: `Confirm duplicating template "${o.name}"?`,
940
+ message: "Duplicated template can be edited after creation",
941
+ primaryActions: {
942
+ text: "Duplicate",
943
+ variant: $e.Destructive,
944
+ close: !0
945
+ },
946
+ secondaryActions: {
947
+ text: "Cancel",
948
+ variant: $e.Plain,
949
+ close: !0
950
+ },
951
+ contentComponent: ee({
952
+ props: ["modelValue"],
953
+ emits: ["update:modelValue"],
954
+ setup(n) {
955
+ return () => Pe(ut.FmTextField, {
956
+ modelValue: n.modelValue,
957
+ "onUpdate:modelValue": (d) => P = d,
958
+ label: "New Template Name",
959
+ size: "md",
960
+ variant: "primary"
961
+ });
962
+ }
963
+ })
964
+ }).onPrimary(async () => {
965
+ e.open({
966
+ title: `Duplicating "${o.name}"`,
967
+ type: "info"
968
+ });
969
+ try {
970
+ k.value = !0;
971
+ const [n] = await Promise.allSettled([
972
+ m.duplicateClosingTemplate(o._id, P),
973
+ new Promise((d) => setTimeout(d, 1e3))
974
+ ]);
975
+ if (n.status === "rejected") throw n.reason;
976
+ e.open({
977
+ title: `Duplicated "${o.name}"`,
978
+ type: "success"
979
+ });
980
+ } catch (n) {
981
+ e.open({
982
+ title: `Unable to duplicate "${o.name}"`,
983
+ message: `See error from server: ${n}`,
984
+ type: "error"
985
+ }), console.error("error on duplicating closing template", n);
986
+ } finally {
987
+ k.value = !1, F();
988
+ }
989
+ });
990
+ }
991
+ const D = z({});
992
+ async function w(o) {
993
+ const k = await _.getTemplate(o);
994
+ D.value = {
995
+ template: k,
996
+ show: !0,
997
+ "onUpdate:show"(F) {
998
+ D.value.show = F;
999
+ },
1000
+ "onAction:edit"() {
1001
+ D.value.show = !1, a(Ye(k));
1002
+ }
1003
+ };
1004
+ }
1005
+ async function x() {
1006
+ const o = await _.readTemplates();
1007
+ if (!o.length) {
1008
+ e.open({
1009
+ title: "No data to export",
1010
+ type: "error"
1011
+ });
1012
+ return;
1013
+ }
1014
+ const k = At(o);
1015
+ e.open({
1016
+ title: r("inventory.ingredient.export.success"),
1017
+ message: r("inventory.ingredient.export.filename", [k]),
1018
+ type: "success"
1019
+ });
1020
+ }
1021
+ function c(o) {
1022
+ if (!o.items.length) {
1023
+ e.open({
1024
+ title: "No items in template to export",
1025
+ type: "error"
1026
+ });
1027
+ return;
1028
+ }
1029
+ const k = Rt(o);
1030
+ e.open({
1031
+ title: r("inventory.ingredient.export.success"),
1032
+ message: r("inventory.ingredient.export.filename", [k]),
1033
+ type: "success"
1034
+ });
1035
+ }
1036
+ function s() {
1037
+ y.loading || t.open({
1038
+ title: r("inventory.ingredient.import.title"),
1039
+ contentComponent: oo,
1040
+ overlay: !0,
1041
+ closeButton: !0,
1042
+ primaryActions: {
1043
+ text: r("common.import"),
1044
+ close: !1
1045
+ },
1046
+ secondaryActions: {
1047
+ text: r("common.close"),
1048
+ close: !0
1049
+ },
1050
+ tertiaryActions: {
1051
+ text: r("inventory.ingredient.import.actions.downloadTemplate"),
1052
+ close: !1,
1053
+ variant: "plain"
1054
+ }
1055
+ }).onPrimary((o) => {
1056
+ if (!o) {
1057
+ e.open({
1058
+ title: r("inventory.ingredient.import.error.noData"),
1059
+ type: "error"
1060
+ });
1061
+ return;
1062
+ }
1063
+ if (!o.importCreateResult.length && !o.importUpdateResult.length) {
1064
+ e.open({
1065
+ title: r("inventory.ingredient.import.error.invalidContent"),
1066
+ message: r("inventory.ingredient.import.error.noImportData"),
1067
+ type: "error"
1068
+ });
1069
+ return;
1070
+ }
1071
+ if (o.importCreateResult.some((k) => k.errors.length) || o.importUpdateResult.some((k) => k.errors.length)) {
1072
+ e.open({
1073
+ title: r("inventory.ingredient.import.error.invalidContent"),
1074
+ message: r("inventory.ingredient.import.error.hasErrors"),
1075
+ type: "error"
1076
+ });
1077
+ return;
1078
+ }
1079
+ t.close(), $(o);
1080
+ }).onTertiary(Pt);
1081
+ }
1082
+ async function $(o) {
1083
+ v.value = !0;
1084
+ try {
1085
+ const k = [
1086
+ ...o.importCreateResult.map(
1087
+ (d) => d.template
1088
+ ),
1089
+ ...o.importUpdateResult.map(
1090
+ (d) => d.template
1091
+ )
1092
+ ], F = 100;
1093
+ let P = 0;
1094
+ const n = () => {
1095
+ P += F, e.open({
1096
+ title: r("inventory.ingredient.import.progress", [
1097
+ Math.min(P, k.length),
1098
+ k.length
1099
+ ])
1100
+ });
1101
+ };
1102
+ for (const d of k.chunk(100))
1103
+ n(), await _.importTemplates(d);
1104
+ e.open({
1105
+ title: r("inventory.ingredient.import.success"),
1106
+ type: "success"
1107
+ });
1108
+ } catch (k) {
1109
+ e.open({
1110
+ title: r("inventory.ingredient.import.error.failed"),
1111
+ message: r("inventory.ingredient.import.error.systemMessage", [k == null ? void 0 : k.message]),
1112
+ type: "error"
1113
+ }), console.error("Error in importing skus", o, k);
1114
+ } finally {
1115
+ v.value = !1, y.refresh();
1116
+ }
1117
+ }
1118
+ return {
1119
+ createTemplate: u,
1120
+ viewTemplate: w,
1121
+ updateTemplate: a,
1122
+ deleteTemplate: b,
1123
+ duplicateTemplate: l,
1124
+ exportTemplates: x,
1125
+ exportSingleTemplate: c,
1126
+ importTemplates: s,
1127
+ templateDialogProps: C,
1128
+ templateDetailsProps: D
1129
+ };
1130
+ });
1131
+ function no(r) {
1132
+ return r ? Number(r.amount) / Math.pow(10, Number(r.precision) || 0) : 0;
1133
+ }
1134
+ function Re(r) {
1135
+ const t = new Set(r.disabledMeasurements ?? []), e = [
1136
+ {
1137
+ id: r.sku.unit._id,
1138
+ label: r.sku.unit.abbrev,
1139
+ isBase: !0,
1140
+ factor: 0,
1141
+ enabled: !t.has(r.sku.unit._id)
1142
+ }
1143
+ ];
1144
+ for (const _ of r.sku.unit.measurements)
1145
+ e.push({
1146
+ id: _.id,
1147
+ label: _.abbrev,
1148
+ isBase: !1,
1149
+ factor: no(_.conversion),
1150
+ enabled: !t.has(_.id)
1151
+ });
1152
+ return e;
1153
+ }
1154
+ function so(r) {
1155
+ return Re(r).filter((t) => t.enabled).length;
1156
+ }
1157
+ function ao(r) {
1158
+ return Re(r).filter((t) => t.enabled).map((t) => !t.isBase && t.factor ? `${t.label} ×${t.factor}` : t.label);
1159
+ }
1160
+ function lo(r, t) {
1161
+ const e = new Set(r.disabledMeasurements ?? []);
1162
+ if (t.enabled) {
1163
+ if (so(r) <= 1) return null;
1164
+ e.add(t.id);
1165
+ } else
1166
+ e.delete(t.id);
1167
+ return { ...r, disabledMeasurements: [...e] };
1168
+ }
1169
+ function ro(r, t, e) {
1170
+ const _ = new Set(r.disabledMeasurements ?? []);
1171
+ for (const m of t)
1172
+ e ? _.delete(m) : _.add(m);
1173
+ return Re(r).every((m) => _.has(m.id)) && _.delete(r.sku.unit._id), { ...r, disabledMeasurements: [..._] };
1174
+ }
1175
+ const io = { class: "flex items-center gap-12 py-12" }, co = {
1176
+ class: "flex items-center justify-center shrink-0 rounded-md border border-fm-color-neutral-gray-300 fm-typo-en-body-sm-600 text-fm-color-typo-secondary",
1177
+ style: { width: "28px", height: "28px" }
1178
+ }, uo = {
1179
+ class: "flex flex-col gap-2 shrink-0",
1180
+ style: { width: "280px" }
1181
+ }, mo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 border border-fm-color-neutral-gray-200 rounded px-8 py-1 self-start" }, po = {
1182
+ class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary",
1183
+ style: { "word-break": "break-word", "line-height": "1.2" }
1184
+ }, fo = {
1185
+ class: "flex-1 flex flex-wrap items-center",
1186
+ style: { gap: "6px" }
1187
+ }, yo = {
1188
+ key: 0,
1189
+ class: "fm-typo-en-body-sm-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-200 rounded",
1190
+ style: { padding: "0 6px" }
1191
+ }, vo = {
1192
+ key: 1,
1193
+ class: "fm-typo-en-body-sm-400 text-fm-color-primary",
1194
+ style: { opacity: "0.7" }
1195
+ }, go = {
1196
+ class: "shrink-0 flex items-center justify-end gap-4",
1197
+ style: { width: "200px" }
1198
+ }, bo = { class: "sticky top-0 py-8 bg-white" }, ho = /* @__PURE__ */ ee({
1199
+ __name: "ClosingTemplateItem",
1200
+ props: {
1201
+ item: {},
1202
+ index: {},
1203
+ disabled: { type: Boolean }
1204
+ },
1205
+ emits: ["update", "delete"],
1206
+ setup(r, { emit: t }) {
1207
+ const e = r, _ = t, m = fe(), y = L(
1208
+ () => (m.skuById[e.item.sku._id] ?? e.item.sku).isInactive === !0
1209
+ ), v = L(() => Re(e.item)), C = L(() => v.value.filter((c) => c.enabled)), u = L(() => C.value.length), a = z(""), b = L(() => {
1210
+ const c = a.value.trim().toLowerCase();
1211
+ return c ? v.value.filter((s) => s.label.toLowerCase().includes(c)) : v.value;
1212
+ }), l = L(() => b.value.every((c) => c.enabled));
1213
+ function D() {
1214
+ if (e.disabled) return;
1215
+ const c = b.value.map((s) => s.id);
1216
+ _("update", ro(e.item, c, !l.value));
1217
+ }
1218
+ function w(c) {
1219
+ if (e.disabled) return;
1220
+ const s = lo(e.item, c);
1221
+ s && _("update", s);
1222
+ }
1223
+ function x(c) {
1224
+ return c.isBase ? "Base unit" : c.factor ? `1 ${c.label} = ${c.factor} ${e.item.sku.unit.abbrev}` : "";
1225
+ }
1226
+ return (c, s) => {
1227
+ const $ = G("FmChip"), o = G("FmButton"), k = G("FmSearch"), F = G("FmMenuItem"), P = G("FmMenu");
1228
+ return h(), T("div", io, [
1229
+ i("span", co, S(c.index + 1), 1),
1230
+ i("div", uo, [
1231
+ i("span", mo, S(c.item.sku.code), 1),
1232
+ i("div", po, S(c.item.sku.name), 1),
1233
+ y.value ? (h(), H($, {
1234
+ key: 0,
1235
+ label: "Inactive",
1236
+ compact: "",
1237
+ class: "self-start"
1238
+ })) : O("", !0)
1239
+ ]),
1240
+ i("div", fo, [
1241
+ (h(!0), T(K, null, X(C.value, (n) => (h(), T("span", {
1242
+ key: n.id,
1243
+ class: Z([
1244
+ "flex items-center rounded-full border",
1245
+ n.isBase ? "border-fm-color-neutral-gray-300 bg-fm-color-neutral-gray-100" : "border-fm-color-primary bg-fm-color-system-warning-100"
1246
+ ]),
1247
+ style: { gap: "6px", padding: "4px 12px" }
1248
+ }, [
1249
+ i("span", {
1250
+ class: Z(["fm-typo-en-body-sm-600 whitespace-nowrap", n.isBase ? "text-fm-color-typo-primary" : "text-fm-color-primary"])
1251
+ }, S(n.label), 3),
1252
+ n.isBase ? (h(), T("span", yo, " BASE ")) : n.factor ? (h(), T("span", vo, " ×" + S(n.factor), 1)) : O("", !0)
1253
+ ], 2))), 128))
1254
+ ]),
1255
+ i("div", go, [
1256
+ A(P, { "close-on-click": !1 }, {
1257
+ "menu-button": Y(() => [
1258
+ A(o, {
1259
+ variant: "secondary",
1260
+ "prepend-icon": "tune",
1261
+ size: "md",
1262
+ disabled: c.disabled,
1263
+ label: `Units ${u.value}/${v.value.length}`
1264
+ }, null, 8, ["disabled", "label"])
1265
+ ]),
1266
+ default: Y(() => [
1267
+ i("div", bo, [
1268
+ A(k, {
1269
+ "model-value": a.value,
1270
+ "onUpdate:modelValue": s[0] || (s[0] = (n) => a.value = n),
1271
+ placeholder: "Search units"
1272
+ }, null, 8, ["model-value"])
1273
+ ]),
1274
+ b.value.length ? (h(), H(F, {
1275
+ key: 0,
1276
+ "model-value": l.value,
1277
+ "has-checkbox": "",
1278
+ label: l.value ? "Deselect all" : "Select all",
1279
+ disabled: c.disabled,
1280
+ onClick: D
1281
+ }, null, 8, ["model-value", "label", "disabled"])) : O("", !0),
1282
+ (h(!0), T(K, null, X(b.value, (n) => (h(), H(F, {
1283
+ key: n.id,
1284
+ "model-value": n.enabled,
1285
+ "has-checkbox": "",
1286
+ label: n.label,
1287
+ sublabel: x(n),
1288
+ disabled: c.disabled || n.enabled && u.value === 1,
1289
+ onClick: (d) => w(n)
1290
+ }, null, 8, ["model-value", "label", "sublabel", "disabled", "onClick"]))), 128)),
1291
+ b.value.length ? O("", !0) : (h(), H(F, {
1292
+ key: 1,
1293
+ disabled: "",
1294
+ label: "No units match"
1295
+ }))
1296
+ ]),
1297
+ _: 1
1298
+ }),
1299
+ A(o, {
1300
+ disabled: c.disabled,
1301
+ icon: "delete",
1302
+ variant: "tertiary",
1303
+ size: "md",
1304
+ onClick: s[1] || (s[1] = (n) => _("delete"))
1305
+ }, null, 8, ["disabled"])
1306
+ ])
1307
+ ]);
1308
+ };
1309
+ }
1310
+ });
1311
+ function _o(r) {
1312
+ const t = z("");
1313
+ De(r, () => {
1314
+ t.value = "";
1315
+ });
1316
+ const e = L(() => t.value.trim().length > 0);
1317
+ function _(m) {
1318
+ const y = t.value.trim().toLowerCase();
1319
+ return y ? m.filter(
1320
+ (v) => v.sku.name.toLowerCase().includes(y) || v.sku.code.toLowerCase().includes(y)
1321
+ ) : m;
1322
+ }
1323
+ return { searchQuery: t, hasQuery: e, filterItems: _ };
1324
+ }
1325
+ const xo = { class: "flex flex-col gap-12" }, ko = { class: "flex items-start justify-between gap-8" }, wo = { class: "flex flex-col" }, $o = { class: "flex items-center gap-8" }, Co = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, To = { class: "flex gap-8 shrink-0" }, Io = { class: "flex flex-wrap items-center gap-8" }, Fo = ["onClick"], So = { class: "fm-typo-en-body-md-600 whitespace-nowrap" }, Do = ["disabled"], Ao = { class: "rounded-lg border border-fm-color-neutral-gray-200 overflow-hidden" }, Ro = { class: "flex items-center gap-12 px-16 py-12 border-b border-fm-color-neutral-gray-200 bg-fm-color-neutral-gray-50" }, Po = {
1326
+ key: 0,
1327
+ class: "flex-1 flex items-baseline gap-8 min-w-0"
1328
+ }, Mo = {
1329
+ key: 1,
1330
+ class: "flex-1 min-w-0"
1331
+ }, Eo = {
1332
+ class: "fm-typo-en-body-sm-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 rounded-full shrink-0",
1333
+ style: { padding: "4px 10px" }
1334
+ }, No = {
1335
+ key: 0,
1336
+ class: "flex items-center gap-8 px-16 py-8 border-b border-fm-color-neutral-gray-200 bg-white"
1337
+ }, Bo = {
1338
+ key: 1,
1339
+ class: "flex items-center gap-4 px-16 py-8 border-b border-fm-color-neutral-gray-200 bg-fm-color-neutral-gray-50 fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
1340
+ }, Lo = {
1341
+ key: 2,
1342
+ class: "flex flex-col"
1343
+ }, Uo = ["draggable", "onDragstart", "onDrop"], Vo = {
1344
+ key: 0,
1345
+ class: "m-16 rounded-lg border border-dashed border-fm-color-neutral-gray-300 text-center fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
1346
+ style: { padding: "24px" }
1347
+ }, zo = { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" }, Go = {
1348
+ key: 1,
1349
+ class: "m-16 rounded-lg border border-dashed border-fm-color-neutral-gray-300 text-center fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
1350
+ style: { padding: "24px" }
1351
+ }, Oo = {
1352
+ key: 3,
1353
+ class: "flex flex-col"
1354
+ }, Ho = {
1355
+ key: 0,
1356
+ class: "m-16 rounded-lg border border-dashed border-fm-color-neutral-gray-300 text-center fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
1357
+ style: { padding: "24px" }
1358
+ }, jo = { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" }, Yo = {
1359
+ key: 1,
1360
+ class: "m-16 rounded-lg border border-dashed border-fm-color-neutral-gray-300 text-center fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
1361
+ style: { padding: "24px" }
1362
+ }, Ko = ["draggable", "onDragstart", "onDrop"], Wo = {
1363
+ class: "flex items-center justify-center shrink-0 rounded-md border border-fm-color-neutral-gray-300 fm-typo-en-body-sm-600 text-fm-color-typo-secondary",
1364
+ style: { width: "28px", height: "28px" }
1365
+ }, Qo = { class: "flex-1 min-w-0" }, qo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Jo = {
1366
+ class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary",
1367
+ style: { "line-height": "1.2" }
1368
+ }, Xo = {
1369
+ class: "flex flex-wrap gap-4 justify-end",
1370
+ style: { "max-width": "320px" }
1371
+ }, Zo = /* @__PURE__ */ ee({
1372
+ __name: "ClosingTemplateGroupsEditor",
1373
+ props: {
1374
+ items: {},
1375
+ groups: {},
1376
+ updateItem: { type: Function },
1377
+ deleteItem: { type: Function },
1378
+ updateGroups: { type: Function },
1379
+ disabled: { type: Boolean }
1380
+ },
1381
+ emits: ["reorderDefault", "addItems"],
1382
+ setup(r, { emit: t }) {
1383
+ const { promptSelectIngredients: e } = Qe(), _ = Ae(), m = fe();
1384
+ function y(p) {
1385
+ return (m.skuById[p.sku._id] ?? p.sku).isInactive === !0;
1386
+ }
1387
+ const v = r, C = t, u = ["#EAB308", "#22C55E", "#3B82F6", "#A855F7", "#F97316", "#EC4899", "#14B8A6"], a = z("default"), { searchQuery: b, hasQuery: l, filterItems: D } = _o(a), w = L(() => v.groups ?? []);
1388
+ function x(p) {
1389
+ v.updateGroups(p);
1390
+ }
1391
+ function c() {
1392
+ return `tmplGroup_${Date.now()}_${Math.floor(Math.random() * 1e4)}`;
1393
+ }
1394
+ const s = z(null), $ = z(null);
1395
+ function o(p, g, I) {
1396
+ var M;
1397
+ $.value = p, s.value = g, (M = I.dataTransfer) == null || M.setData("text/plain", String(g)), I.dataTransfer && (I.dataTransfer.effectAllowed = "move");
1398
+ }
1399
+ function k(p, g, I) {
1400
+ const M = [...p], [B] = M.splice(g, 1);
1401
+ return M.splice(I, 0, B), M;
1402
+ }
1403
+ function F(p, g) {
1404
+ const I = s.value, M = $.value;
1405
+ if (s.value = null, $.value = null, !(I === null || M !== p || I === g))
1406
+ if (p === "default")
1407
+ C(
1408
+ "reorderDefault",
1409
+ k(
1410
+ v.items.map((B) => B.sku._id),
1411
+ I,
1412
+ g
1413
+ )
1414
+ );
1415
+ else {
1416
+ const B = Q(p);
1417
+ B && ie(
1418
+ p,
1419
+ k(
1420
+ B.items.map((se) => se.skuId),
1421
+ I,
1422
+ g
1423
+ )
1424
+ );
1425
+ }
1426
+ }
1427
+ const P = L(
1428
+ () => Object.fromEntries(v.items.map((p) => [p.sku._id, p]))
1429
+ );
1430
+ De(
1431
+ () => v.items.map((p) => p.sku._id),
1432
+ (p) => {
1433
+ const g = new Set(p);
1434
+ let I = !1;
1435
+ const M = w.value.map((B) => {
1436
+ const se = B.items.filter((V) => g.has(V.skuId));
1437
+ return se.length !== B.items.length ? (I = !0, { ...B, items: se }) : B;
1438
+ });
1439
+ I && x(M);
1440
+ }
1441
+ );
1442
+ const n = L(() => {
1443
+ const p = /* @__PURE__ */ new Map();
1444
+ for (const I of w.value)
1445
+ for (const M of I.items) p.set(M.skuId, (p.get(M.skuId) ?? 0) + 1);
1446
+ let g = 0;
1447
+ return p.forEach((I) => {
1448
+ I > 1 && g++;
1449
+ }), g;
1450
+ }), d = L(() => {
1451
+ const p = w.value.length;
1452
+ return `${v.items.length} items in Default · ${n.value} shared across named groups · ${p + 1} total groups (${p} named + Default)`;
1453
+ }), E = L(() => [
1454
+ { id: "default", isDefault: !0, name: "Default", color: null, itemCount: v.items.length },
1455
+ ...w.value.map((p, g) => ({
1456
+ id: p.id,
1457
+ isDefault: !1,
1458
+ name: p.name,
1459
+ color: u[g % u.length],
1460
+ itemCount: p.items.length
1461
+ }))
1462
+ ]), R = L(
1463
+ () => E.value.find((p) => p.id === a.value) ?? E.value[0]
1464
+ ), N = L(() => R.value.isDefault), U = L(
1465
+ () => N.value ? [] : he(a.value)
1466
+ );
1467
+ function j(p) {
1468
+ return a.value === p;
1469
+ }
1470
+ function le() {
1471
+ const p = c();
1472
+ x([...w.value, { id: p, name: `Group ${w.value.length + 1}`, items: [] }]), a.value = p;
1473
+ }
1474
+ function Q(p) {
1475
+ return w.value.find((g) => g.id === p) ?? null;
1476
+ }
1477
+ function re(p) {
1478
+ x(w.value.filter((g) => g.id !== p)), a.value === p && (a.value = "default");
1479
+ }
1480
+ function ye(p, g) {
1481
+ _.open({
1482
+ title: `Delete group "${g || "Untitled"}"?`,
1483
+ closeButton: !1,
1484
+ message: "This removes the group and its item selection. The items stay in Default and other groups.",
1485
+ primaryActions: { text: "Delete", close: !0, variant: "destructive" },
1486
+ secondaryActions: { text: "Cancel", close: !0 }
1487
+ }).onPrimary(() => re(p));
1488
+ }
1489
+ function ve(p, g) {
1490
+ x(w.value.map((I) => I.id === p ? { ...I, name: g } : I));
1491
+ }
1492
+ function ie(p, g) {
1493
+ x(
1494
+ w.value.map(
1495
+ (I) => I.id === p ? { ...I, items: g.map((M, B) => ({ skuId: M, position: B })) } : I
1496
+ )
1497
+ );
1498
+ }
1499
+ async function ge(p) {
1500
+ if (v.disabled) return;
1501
+ const g = Q(p);
1502
+ if (!g) return;
1503
+ const I = await e(
1504
+ g.items.map((M) => M.skuId),
1505
+ (M) => M,
1506
+ v.items.map((M) => M.sku)
1507
+ );
1508
+ I && ie(p, I);
1509
+ }
1510
+ function ce() {
1511
+ N.value ? C("addItems") : ge(a.value);
1512
+ }
1513
+ function be(p, g) {
1514
+ const I = Q(p);
1515
+ if (!I) return;
1516
+ const M = I.items.some((B) => B.skuId === g) ? I.items.filter((B) => B.skuId !== g).map((B) => B.skuId) : [...I.items.map((B) => B.skuId), g];
1517
+ ie(p, M);
1518
+ }
1519
+ function he(p) {
1520
+ const g = Q(p);
1521
+ return g ? g.items.map((I) => P.value[I.skuId]).filter(Boolean) : [];
1522
+ }
1523
+ const ue = L(() => D(v.items)), de = L(
1524
+ () => D(U.value)
1525
+ ), _e = L(
1526
+ () => l.value ? N.value ? ue.value.length : de.value.length : R.value.itemCount
1527
+ );
1528
+ function xe(p) {
1529
+ const g = j(p.id);
1530
+ if (p.isDefault)
1531
+ return g ? { background: "#1F2937", color: "#FFFFFF", border: "1px solid #1F2937" } : { background: "#FFFFFF", color: "#374151", border: "1px solid #E5E7EB" };
1532
+ const I = p.color || "#999999";
1533
+ return g ? { background: I, color: ne(I), border: `1px solid ${I}` } : { background: `${I}1A`, color: "#374151", border: `1px solid ${I}` };
1534
+ }
1535
+ function ne(p) {
1536
+ const g = p.replace("#", ""), I = parseInt(g.slice(0, 2), 16), M = parseInt(g.slice(2, 4), 16), B = parseInt(g.slice(4, 6), 16);
1537
+ return (0.299 * I + 0.587 * M + 0.114 * B) / 255 > 0.6 ? "#1F2937" : "#FFFFFF";
1538
+ }
1539
+ function ke(p) {
1540
+ return j(p.id) ? (p.isDefault ? "#FFFFFF" : ne(p.color || "#999999")) === "#FFFFFF" ? { background: "rgba(255,255,255,0.25)", color: "#FFFFFF" } : { background: "rgba(0,0,0,0.12)", color: "#1F2937" } : { background: "rgba(0,0,0,0.06)", color: "inherit" };
1541
+ }
1542
+ return (p, g) => {
1543
+ const I = G("FmButton"), M = G("FmIcon"), B = G("FmTextField"), se = G("FmChip");
1544
+ return h(), T("div", xo, [
1545
+ i("div", ko, [
1546
+ i("div", wo, [
1547
+ i("div", $o, [
1548
+ g[6] || (g[6] = i("div", { class: "fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, "Groups & items", -1)),
1549
+ A(Tt, {
1550
+ tier: "standard",
1551
+ category: "beta"
1552
+ })
1553
+ ]),
1554
+ i("div", Co, S(d.value), 1)
1555
+ ]),
1556
+ i("div", To, [
1557
+ A(I, {
1558
+ disabled: p.disabled,
1559
+ label: "New Group",
1560
+ "prepend-icon": "add",
1561
+ variant: "primary",
1562
+ size: "md",
1563
+ class: "rounded-lg",
1564
+ onClick: le
1565
+ }, null, 8, ["disabled"])
1566
+ ])
1567
+ ]),
1568
+ g[15] || (g[15] = et('<div class="flex items-start gap-8 p-12 fm-corner-radius-md border-1 border-yellow-500 bg-yellow-50 text-yellow-700"><div class="flex flex-col gap-2"><div class="fm-typo-en-body-md-600 text-fm-color-typo-primary">📦 Closing Groups</div><div class="fm-typo-en-body-sm-400"> Split a closing template into named groups (e.g. by section, fridge, or station) so several staff can stock take in parallel and you manage them in one place. Group stock take is currently only available in the Inventory mobile app — it&#39;s not yet available in POS. You can keep using the <span class="fm-typo-en-body-sm-600 text-fm-color-typo-primary">Default (master list)</span> group as usual. </div></div></div>', 1)),
1569
+ i("div", Io, [
1570
+ (h(!0), T(K, null, X(E.value, (V) => (h(), T("button", {
1571
+ key: V.id,
1572
+ type: "button",
1573
+ class: "flex items-center rounded-full",
1574
+ style: Me([{ gap: "8px", padding: "6px 14px" }, xe(V)]),
1575
+ onClick: (ae) => a.value = V.id
1576
+ }, [
1577
+ i("span", So, S(V.name), 1),
1578
+ i("span", {
1579
+ class: "fm-typo-en-body-sm-600 rounded-full",
1580
+ style: Me([{ padding: "0 8px" }, ke(V)])
1581
+ }, S(V.itemCount), 5)
1582
+ ], 12, Fo))), 128)),
1583
+ i("button", {
1584
+ type: "button",
1585
+ disabled: p.disabled,
1586
+ class: "flex items-center rounded-full border border-dashed border-fm-color-neutral-gray-400 text-fm-color-typo-secondary",
1587
+ style: { gap: "6px", padding: "6px 14px" },
1588
+ onClick: le
1589
+ }, [
1590
+ A(M, {
1591
+ name: "add",
1592
+ size: "sm"
1593
+ }),
1594
+ g[7] || (g[7] = i("span", { class: "fm-typo-en-body-md-400 whitespace-nowrap" }, "New group", -1))
1595
+ ], 8, Do)
1596
+ ]),
1597
+ i("div", Ao, [
1598
+ i("div", Ro, [
1599
+ N.value ? (h(), T("div", Po, g[8] || (g[8] = [
1600
+ i("span", { class: "fm-typo-en-body-lg-600 italic text-fm-color-typo-primary" }, "Default", -1),
1601
+ i("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary truncate" }, " master list · sets the item pool & units ", -1)
1602
+ ]))) : (h(), T("div", Mo, [
1603
+ A(B, {
1604
+ "model-value": R.value.name,
1605
+ disabled: p.disabled,
1606
+ placeholder: "Group name",
1607
+ "onUpdate:modelValue": g[0] || (g[0] = (V) => ve(a.value, V))
1608
+ }, null, 8, ["model-value", "disabled"])
1609
+ ])),
1610
+ i("span", Eo, [
1611
+ f(l) ? (h(), T(K, { key: 0 }, [
1612
+ W(S(_e.value) + " of " + S(R.value.itemCount), 1)
1613
+ ], 64)) : (h(), T(K, { key: 1 }, [
1614
+ W(S(R.value.itemCount), 1)
1615
+ ], 64)),
1616
+ g[9] || (g[9] = W(" items "))
1617
+ ]),
1618
+ N.value ? O("", !0) : (h(), H(I, {
1619
+ key: 2,
1620
+ disabled: p.disabled,
1621
+ label: "Delete group",
1622
+ "prepend-icon": "delete",
1623
+ variant: "secondary",
1624
+ size: "md",
1625
+ class: "rounded-lg shrink-0",
1626
+ onClick: g[1] || (g[1] = (V) => ye(a.value, R.value.name))
1627
+ }, null, 8, ["disabled"])),
1628
+ A(I, {
1629
+ disabled: p.disabled,
1630
+ label: "Add items",
1631
+ "prepend-icon": "add",
1632
+ variant: "primary",
1633
+ size: "md",
1634
+ class: "rounded-lg shrink-0",
1635
+ onClick: ce
1636
+ }, null, 8, ["disabled"])
1637
+ ]),
1638
+ R.value.itemCount > 0 || f(l) ? (h(), T("div", No, [
1639
+ A(M, {
1640
+ name: "search",
1641
+ size: "sm",
1642
+ color: "neutral-gray-400",
1643
+ class: "shrink-0"
1644
+ }),
1645
+ tt(i("input", {
1646
+ "onUpdate:modelValue": g[2] || (g[2] = (V) => Oe(b) ? b.value = V : null),
1647
+ type: "search",
1648
+ "aria-label": "Search items by name or code",
1649
+ placeholder: "Search items by name or code...",
1650
+ class: "flex-1 bg-transparent outline-none fm-typo-en-body-md-400 text-fm-color-typo-primary placeholder:text-fm-color-typo-disabled"
1651
+ }, null, 512), [
1652
+ [ot, f(b)]
1653
+ ]),
1654
+ f(l) ? (h(), T("button", {
1655
+ key: 0,
1656
+ type: "button",
1657
+ "aria-label": "Clear search",
1658
+ title: "Clear search",
1659
+ class: "flex items-center text-fm-color-typo-secondary hover:text-fm-color-typo-primary",
1660
+ onClick: g[3] || (g[3] = (V) => b.value = "")
1661
+ }, [
1662
+ A(M, {
1663
+ name: "close",
1664
+ size: "sm"
1665
+ })
1666
+ ])) : O("", !0)
1667
+ ])) : O("", !0),
1668
+ !f(l) && R.value.itemCount > 1 ? (h(), T("div", Bo, [
1669
+ A(M, {
1670
+ name: "drag_indicator",
1671
+ size: "sm",
1672
+ color: "neutral-gray-400",
1673
+ class: "shrink-0"
1674
+ }),
1675
+ g[10] || (g[10] = W(" Drag a row to reorder items. "))
1676
+ ])) : O("", !0),
1677
+ N.value ? (h(), T("div", Lo, [
1678
+ (h(!0), T(K, null, X(ue.value, (V, ae) => (h(), T("div", {
1679
+ key: V.sku._id,
1680
+ draggable: !f(l),
1681
+ onDragstart: (J) => !f(l) && o("default", ae, J),
1682
+ onDragover: g[4] || (g[4] = we(() => {
1683
+ }, ["prevent"])),
1684
+ onDrop: we((J) => !f(l) && F("default", ae), ["prevent"]),
1685
+ class: Z(["flex items-center gap-4 px-16 border-b border-fm-color-neutral-gray-200 hover:bg-fm-color-neutral-gray-100", f(l) ? "cursor-default" : "cursor-grab"])
1686
+ }, [
1687
+ f(l) ? O("", !0) : (h(), H(M, {
1688
+ key: 0,
1689
+ name: "drag_indicator",
1690
+ size: "sm",
1691
+ color: "neutral-gray-400",
1692
+ class: "shrink-0"
1693
+ })),
1694
+ A(ho, {
1695
+ class: "flex-1 min-w-0",
1696
+ item: V,
1697
+ index: ae,
1698
+ disabled: p.disabled,
1699
+ onUpdate: p.updateItem,
1700
+ onDelete: (J) => p.deleteItem(V)
1701
+ }, null, 8, ["item", "index", "disabled", "onUpdate", "onDelete"])
1702
+ ], 42, Uo))), 128)),
1703
+ f(l) && p.items.length > 0 && !ue.value.length ? (h(), T("div", Vo, [
1704
+ g[11] || (g[11] = W(" No items match ")),
1705
+ i("span", zo, S(f(b)), 1)
1706
+ ])) : p.items.length ? O("", !0) : (h(), T("div", Go, g[12] || (g[12] = [
1707
+ W(" No items yet — click "),
1708
+ i("span", { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" }, "+ Add items", -1),
1709
+ W(" to add from your catalog. ")
1710
+ ])))
1711
+ ])) : (h(), T("div", Oo, [
1712
+ f(l) && U.value.length > 0 && !de.value.length ? (h(), T("div", Ho, [
1713
+ g[13] || (g[13] = W(" No items match ")),
1714
+ i("span", jo, S(f(b)), 1)
1715
+ ])) : U.value.length ? O("", !0) : (h(), T("div", Yo, g[14] || (g[14] = [
1716
+ W(" No items yet — click "),
1717
+ i("span", { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" }, "+ Add items", -1),
1718
+ W(" on this group to assign items. ")
1719
+ ]))),
1720
+ (h(!0), T(K, null, X(de.value, (V, ae) => (h(), T("div", {
1721
+ key: V.sku._id,
1722
+ draggable: !f(l),
1723
+ onDragstart: (J) => !f(l) && o(a.value, ae, J),
1724
+ onDragover: g[5] || (g[5] = we(() => {
1725
+ }, ["prevent"])),
1726
+ onDrop: we((J) => !f(l) && F(a.value, ae), ["prevent"]),
1727
+ class: Z(["flex items-center gap-12 px-16 py-12 border-b border-fm-color-neutral-gray-200 hover:bg-fm-color-neutral-gray-100", f(l) ? "cursor-default" : "cursor-grab"])
1728
+ }, [
1729
+ f(l) ? O("", !0) : (h(), H(M, {
1730
+ key: 0,
1731
+ name: "drag_indicator",
1732
+ size: "sm",
1733
+ color: "neutral-gray-400",
1734
+ class: "shrink-0"
1735
+ })),
1736
+ i("span", Wo, S(U.value.findIndex((J) => J.sku._id === V.sku._id) + 1), 1),
1737
+ i("div", Qo, [
1738
+ i("div", qo, S(V.sku.code), 1),
1739
+ i("div", Jo, S(V.sku.name), 1),
1740
+ y(V) ? (h(), H(se, {
1741
+ key: 0,
1742
+ label: "Inactive",
1743
+ compact: ""
1744
+ })) : O("", !0)
1745
+ ]),
1746
+ i("div", Xo, [
1747
+ (h(!0), T(K, null, X(f(ao)(V), (J, Xe) => (h(), T("span", {
1748
+ key: Xe,
1749
+ class: "px-8 py-2 rounded-full border border-fm-color-neutral-gray-200 fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
1750
+ }, S(J), 1))), 128))
1751
+ ]),
1752
+ A(I, {
1753
+ disabled: p.disabled,
1754
+ icon: "delete",
1755
+ variant: "tertiary",
1756
+ size: "md",
1757
+ onClick: (J) => be(a.value, V.sku._id)
1758
+ }, null, 8, ["disabled", "onClick"])
1759
+ ], 42, Ko))), 128))
1760
+ ]))
1761
+ ])
1762
+ ]);
1763
+ };
1764
+ }
1765
+ }), en = { class: "flex flex-col gap-16" }, tn = { class: "flex flex-col gap-24" }, on = { class: "flex flex-col gap-16" }, nn = { class: "flex items-center" }, sn = { class: "flex-1 fm-typo-en-title-sm-600" }, an = { class: "flex flex-col gap-16" }, ln = { class: "flex items-center" }, rn = { class: "flex-1 gap-8 fm-typo-en-title-sm-600" }, cn = /* @__PURE__ */ ee({
1766
+ __name: "ClosingTemplateForm",
1767
+ props: {
1768
+ modelValue: {},
1769
+ disabled: { type: Boolean }
1770
+ },
1771
+ setup(r, { expose: t }) {
1772
+ const e = Ct(), { t: _ } = oe(), m = fe(), {
1773
+ promptSelectLocations: y,
1774
+ columnDefs: v,
1775
+ rowData: C
1776
+ } = It({
1777
+ getLocations() {
1778
+ return e.locations;
1779
+ },
1780
+ setLocations(s) {
1781
+ e.locations = s;
1782
+ }
1783
+ }), u = z(), a = L(() => e.items.map((s, $) => ({ item: s, originalIndex: $ })).sort((s, $) => {
1784
+ const o = s.item.position ?? s.originalIndex, k = $.item.position ?? $.originalIndex;
1785
+ return o - k;
1786
+ }).map(({ item: s }) => s));
1787
+ function b(s) {
1788
+ const $ = new Map(e.items.map((k) => [k.sku._id, k])), o = [];
1789
+ s.forEach((k, F) => {
1790
+ const P = $.get(k);
1791
+ P && o.push({ ...P, position: F });
1792
+ }), e.items = o;
1793
+ }
1794
+ t({
1795
+ validateInputs: () => {
1796
+ var s, $;
1797
+ ($ = (s = u.value) == null ? void 0 : s.validateInputs) == null || $.call(s);
1798
+ },
1799
+ resetInputsValidation: () => {
1800
+ var s, $;
1801
+ ($ = (s = u.value) == null ? void 0 : s.resetInputsValidation) == null || $.call(s);
1802
+ },
1803
+ resetInputs: () => {
1804
+ var s, $;
1805
+ ($ = (s = u.value) == null ? void 0 : s.resetInputs) == null || $.call(s);
1806
+ }
1807
+ });
1808
+ function l(s) {
1809
+ e.items = e.items.map(($) => $.sku._id === s.sku._id ? s : $);
1810
+ }
1811
+ function D(s) {
1812
+ e.items = e.items.filter(($) => $.sku._id !== s.sku._id);
1813
+ }
1814
+ function w(s) {
1815
+ e.groups = s;
1816
+ }
1817
+ const { promptSelectIngredients: x } = Qe();
1818
+ async function c() {
1819
+ const $ = m.skus.map((F) => ({
1820
+ label: F.name,
1821
+ sublabel: F.code,
1822
+ value: F
1823
+ })).filter((F) => {
1824
+ var P;
1825
+ return (P = e.items) == null ? void 0 : P.find((n) => n.sku._id === F.value._id);
1826
+ }).map((F) => F.value), o = e.items ?? [], k = await x(
1827
+ $.map((F) => F._id),
1828
+ (F) => {
1829
+ const P = m.skuById[F], n = o.find((E) => E.sku._id === P._id);
1830
+ return n || {
1831
+ sku: P
1832
+ };
1833
+ }
1834
+ );
1835
+ k && (k.sort((F, P) => F.sku.code.localeCompare(P.sku.code)), e.items = k);
1836
+ }
1837
+ return (s, $) => {
1838
+ const o = G("FmTextField"), k = G("FmButton"), F = G("FmTable"), P = G("FmFormGroup"), n = G("FmForm");
1839
+ return h(), H(n, {
1840
+ ref_key: "formRef",
1841
+ ref: u,
1842
+ class: "flex flex-col gap-32",
1843
+ disabled: s.disabled
1844
+ }, {
1845
+ default: Y(() => [
1846
+ i("div", en, [
1847
+ i("div", tn, [
1848
+ A(o, {
1849
+ label: f(_)("inventory.closing.form.name"),
1850
+ "label-mark": "required",
1851
+ modelValue: f(e).name,
1852
+ "onUpdate:modelValue": $[0] || ($[0] = (d) => f(e).name = d),
1853
+ rules: [f(wt)()]
1854
+ }, null, 8, ["label", "modelValue", "rules"]),
1855
+ A(o, {
1856
+ label: f(_)("inventory.closing.form.reference"),
1857
+ "label-mark": "optional",
1858
+ modelValue: f(e).ref,
1859
+ "onUpdate:modelValue": $[1] || ($[1] = (d) => f(e).ref = d)
1860
+ }, null, 8, ["label", "modelValue"])
1861
+ ])
1862
+ ]),
1863
+ i("div", on, [
1864
+ i("div", nn, [
1865
+ i("div", sn, S(f(_)("inventory.closing.form.locations")), 1),
1866
+ A(k, {
1867
+ disabled: s.disabled,
1868
+ label: f(_)("inventory.closing.form.selectLocation"),
1869
+ "prepend-icon": "add",
1870
+ variant: "plain",
1871
+ class: "border-2 rounded-lg border-fm-color-primary",
1872
+ onClick: f(y)
1873
+ }, null, 8, ["disabled", "label", "onClick"])
1874
+ ]),
1875
+ A(F, {
1876
+ "column-defs": f(v),
1877
+ "row-data": f(C),
1878
+ "shrink-at": 9999,
1879
+ onRowClick: f(y),
1880
+ "hide-footer": ""
1881
+ }, null, 8, ["column-defs", "row-data", "onRowClick"])
1882
+ ]),
1883
+ i("div", an, [
1884
+ i("div", ln, [
1885
+ i("div", rn, S(f(_)("inventory.closing.form.items.title")), 1)
1886
+ ]),
1887
+ A(Zo, {
1888
+ items: a.value,
1889
+ groups: f(e).groups,
1890
+ "update-item": l,
1891
+ "delete-item": D,
1892
+ "update-groups": w,
1893
+ disabled: s.disabled,
1894
+ onReorderDefault: b,
1895
+ onAddItems: c
1896
+ }, null, 8, ["items", "groups", "disabled"]),
1897
+ A(P, {
1898
+ "model-value": f(e).items.length,
1899
+ rules: [f($t)(1)]
1900
+ }, null, 8, ["model-value", "rules"])
1901
+ ])
1902
+ ]),
1903
+ _: 1
1904
+ }, 8, ["disabled"]);
1905
+ };
1906
+ }
1907
+ }), un = { class: "flex items-center" }, dn = { class: "fm-typo-en-title-md-600" }, mn = { class: "flex justify-between" }, pn = { class: "fm-typo-en-body-lg-600" }, fn = { class: "flex flex-col gap-8" }, yn = { class: "flex flex-col gap-4" }, vn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, gn = { class: "flex items-center gap-8" }, bn = { class: "fm-typo-en-body-lg-600" }, hn = { class: "flex gap-4" }, _n = /* @__PURE__ */ ee({
1908
+ __name: "ClosingTemplateDialog",
1909
+ props: {
1910
+ mode: {},
1911
+ modelValue: {},
1912
+ show: { type: Boolean }
1913
+ },
1914
+ emits: ["update:show", "submitted"],
1915
+ setup(r, { expose: t, emit: e }) {
1916
+ var P;
1917
+ const _ = r, m = e, y = pe(), v = Se(), C = me(), { t: u } = oe(), a = dt(_, "show");
1918
+ function b() {
1919
+ return {
1920
+ _id: "",
1921
+ name: "",
1922
+ items: []
1923
+ };
1924
+ }
1925
+ const l = z(_.modelValue ?? b()), D = z(((P = _.modelValue) == null ? void 0 : P._id) ?? `${Math.random()}`);
1926
+ De(
1927
+ () => _.show,
1928
+ (n) => {
1929
+ var d;
1930
+ n && (l.value = _.modelValue ?? b(), D.value = ((d = _.modelValue) == null ? void 0 : d._id) ?? `${Math.random()}`);
1931
+ }
1932
+ );
1933
+ const w = z(!1), x = L(() => {
1934
+ switch (_.mode) {
1935
+ case te.READ:
1936
+ return "";
1937
+ case te.CREATE:
1938
+ return u("inventory.closing.template.create.title");
1939
+ case te.UPDATE:
1940
+ return u("inventory.closing.template.update.title");
1941
+ }
1942
+ return "";
1943
+ }), c = z();
1944
+ t({
1945
+ validateInputs: () => {
1946
+ var n, d;
1947
+ (d = (n = c.value) == null ? void 0 : n.validateInputs) == null || d.call(n);
1948
+ },
1949
+ resetInputsValidation: () => {
1950
+ var n, d;
1951
+ (d = (n = c.value) == null ? void 0 : n.resetInputsValidation) == null || d.call(n);
1952
+ },
1953
+ resetInputs: () => {
1954
+ var n, d;
1955
+ (d = (n = c.value) == null ? void 0 : n.resetInputs) == null || d.call(n);
1956
+ }
1957
+ });
1958
+ async function s() {
1959
+ const n = l.value;
1960
+ if (n) {
1961
+ w.value = !0;
1962
+ try {
1963
+ await y.createTemplate(n), await new Promise((d) => setTimeout(d, 1e3)), C.open({
1964
+ title: u("inventory.closing.template.create.success"),
1965
+ message: u("inventory.closing.template.create.successMessage"),
1966
+ type: "success"
1967
+ }), m("update:show", !1), m("submitted");
1968
+ } catch (d) {
1969
+ C.open({
1970
+ title: u("inventory.closing.template.create.error"),
1971
+ message: d instanceof ze ? d.message : u("inventory.closing.template.create.errorMessage"),
1972
+ type: "error"
1973
+ }), console.error("Error in creating closing template", d);
1974
+ } finally {
1975
+ w.value = !1;
1976
+ }
1977
+ }
1978
+ }
1979
+ async function $() {
1980
+ const n = l.value;
1981
+ if (n) {
1982
+ w.value = !0, delete n.updatedAt;
1983
+ try {
1984
+ await y.updateTemplate({
1985
+ ...n,
1986
+ _rev: n._rev ?? ""
1987
+ }), await new Promise((d) => setTimeout(d, 1e3)), C.open({
1988
+ title: u("inventory.closing.template.update.success"),
1989
+ message: u("inventory.closing.template.update.successMessage"),
1990
+ type: "success"
1991
+ }), m("update:show", !1), m("submitted");
1992
+ } catch (d) {
1993
+ C.open({
1994
+ title: u("inventory.closing.template.update.error"),
1995
+ message: d instanceof ze ? d.message : u("inventory.closing.template.update.errorMessage"),
1996
+ type: "error"
1997
+ }), console.error("Error in updating closing template", d);
1998
+ } finally {
1999
+ w.value = !1;
2000
+ }
2001
+ }
2002
+ }
2003
+ function o() {
2004
+ switch (_.mode) {
2005
+ case te.CREATE:
2006
+ return s();
2007
+ case te.UPDATE:
2008
+ return $();
2009
+ }
2010
+ }
2011
+ function k() {
2012
+ var n, d;
2013
+ (d = (n = c.value) == null ? void 0 : n.validateInputs) == null || d.call(n);
2014
+ }
2015
+ function F() {
2016
+ l.value && v.exportSingleTemplate(l.value);
2017
+ }
2018
+ return (n, d) => {
2019
+ const E = G("FmMenuDivider"), R = G("FmCard"), N = G("FmButton"), U = G("FmSideSheet");
2020
+ return h(), H(U, {
2021
+ modelValue: f(a),
2022
+ "onUpdate:modelValue": d[2] || (d[2] = (j) => Oe(a) ? a.value = j : null),
2023
+ "dismiss-away": "",
2024
+ "close-button": "",
2025
+ "max-width": 9999
2026
+ }, {
2027
+ "side-sheet-header": Y(() => [
2028
+ i("div", un, [
2029
+ i("div", dn, S(x.value), 1)
2030
+ ])
2031
+ ]),
2032
+ default: Y(() => [
2033
+ l.value.updatedAt ? (h(), H(R, {
2034
+ key: 0,
2035
+ variant: "outlined",
2036
+ class: "flex flex-col gap-8 px-12 py-16 mb-16"
2037
+ }, {
2038
+ default: Y(() => {
2039
+ var j;
2040
+ return [
2041
+ i("div", mn, [
2042
+ i("div", pn, S(f(u)("inventory.transfer.template.details.templateSummary")), 1)
2043
+ ]),
2044
+ A(E),
2045
+ i("div", fn, [
2046
+ i("div", yn, [
2047
+ i("div", vn, S(f(u)("inventory.transfer.receiveRequest.details.updatedAt")), 1),
2048
+ i("div", gn, [
2049
+ i("div", bn, [
2050
+ W(S(f(Ie)(l.value.updatedAt)) + " ", 1),
2051
+ (j = l.value.updatedBy) != null && j.name ? (h(), T(K, { key: 0 }, [
2052
+ W(" (" + S(l.value.updatedBy.name) + ") ", 1)
2053
+ ], 64)) : O("", !0)
2054
+ ]),
2055
+ A(Ft, {
2056
+ "closing-id": l.value._id
2057
+ }, null, 8, ["closing-id"])
2058
+ ])
2059
+ ])
2060
+ ])
2061
+ ];
2062
+ }),
2063
+ _: 1
2064
+ })) : O("", !0),
2065
+ (h(), H(cn, {
2066
+ class: "w-full",
2067
+ ref_key: "formRef",
2068
+ ref: c,
2069
+ onValidationSuccess: o,
2070
+ "model-value": l.value,
2071
+ "onUpdate:modelValue": d[0] || (d[0] = (j) => l.value = j),
2072
+ disabled: w.value,
2073
+ key: D.value
2074
+ }, null, 8, ["model-value", "disabled"]))
2075
+ ]),
2076
+ "side-sheet-footer": Y(() => [
2077
+ i("div", hn, [
2078
+ A(N, {
2079
+ loading: w.value,
2080
+ label: f(u)("common.save"),
2081
+ onClick: k
2082
+ }, null, 8, ["loading", "label"]),
2083
+ n.mode === f(te).UPDATE ? (h(), H(N, {
2084
+ key: 0,
2085
+ disabled: w.value,
2086
+ variant: "secondary",
2087
+ label: f(u)("inventory.common.export"),
2088
+ "prepend-icon": "download",
2089
+ onClick: F
2090
+ }, null, 8, ["disabled", "label"])) : O("", !0),
2091
+ A(N, {
2092
+ disabled: w.value,
2093
+ variant: "tertiary",
2094
+ label: f(u)("common.close"),
2095
+ onClick: d[1] || (d[1] = (j) => m("update:show", !1))
2096
+ }, null, 8, ["disabled", "label"])
2097
+ ])
2098
+ ]),
2099
+ _: 1
2100
+ }, 8, ["modelValue"]);
2101
+ };
2102
+ }
2103
+ }), xn = {};
2104
+ function kn(r, t) {
2105
+ return h(), T("div");
2106
+ }
2107
+ const wn = /* @__PURE__ */ Dt(xn, [["render", kn]]), $n = { class: "flex flex-col gap-40" }, Cn = { key: 0 }, Tn = {
2108
+ key: 1,
2109
+ class: "flex gap-8 items-center"
2110
+ }, In = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" }, Fn = {
2111
+ key: 2,
2112
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary"
2113
+ }, Sn = {
2114
+ key: 3,
2115
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary flex flex-col gap-12"
2116
+ }, Dn = { class: "fm-typo-en-body-md-600" }, An = { class: "fm-typo-en-body-md-600" }, Rn = { key: 4 }, Pn = { class: "fm-typo-en-body-md-600" }, Mn = { class: "fm-typo-en-body-md-600" }, En = { class: "flex sm:flex-col xs:flex-col justify-end gap-8 w-full mb-16" }, Nn = /* @__PURE__ */ ee({
2117
+ __name: "ClosingTemplatePublish",
2118
+ emits: ["close"],
2119
+ setup(r, { emit: t }) {
2120
+ const e = z(!1), _ = me(), m = pe(), y = Ve(), { t: v } = oe(), C = t;
2121
+ async function u() {
2122
+ e.value = !0;
2123
+ try {
2124
+ await m.startNewPublish().delayed(1e3), _.open({
2125
+ title: "Success",
2126
+ message: "You may refresh after a while to review publish status",
2127
+ type: "success"
2128
+ }), l();
2129
+ } catch (D) {
2130
+ _.open({
2131
+ title: "Something went wrong",
2132
+ message: "Please try again",
2133
+ type: "error"
2134
+ }), console.error("error on creating publish task", D);
2135
+ } finally {
2136
+ e.value = !1;
2137
+ }
2138
+ }
2139
+ const a = L(() => y.recentPublish.recentJob), b = L(
2140
+ () => y.templates.length && (!a.value || a.value.outlets.length === a.value.completed.length)
2141
+ );
2142
+ function l() {
2143
+ C("close");
2144
+ }
2145
+ return (D, w) => {
2146
+ const x = G("FmCircularProgress"), c = G("i18n-t"), s = G("FmButton");
2147
+ return h(), T("div", $n, [
2148
+ f(y).templates.length ? e.value ? (h(), T("div", Tn, [
2149
+ i("div", null, [
2150
+ A(x, {
2151
+ size: "md",
2152
+ color: "neutral-gray-300"
2153
+ })
2154
+ ]),
2155
+ i("div", In, [
2156
+ i("span", null, S(f(v)("inventory.closing.template.publish.publishing")), 1)
2157
+ ])
2158
+ ])) : a.value ? a.value.outlets.length === a.value.completed.length ? (h(), T("div", Sn, [
2159
+ A(c, {
2160
+ keypath: "inventory.closing.template.publish.recentlyPublishedAt",
2161
+ tag: "p"
2162
+ }, {
2163
+ started: Y(() => [
2164
+ i("span", Dn, S(f(Ie)(new Date(a.value.createdAt))), 1)
2165
+ ]),
2166
+ finished: Y(() => [
2167
+ i("span", An, S(f(Ie)(new Date(a.value.updatedAt))), 1)
2168
+ ]),
2169
+ _: 1
2170
+ }),
2171
+ i("p", null, S(f(v)("inventory.closing.template.publish.message")), 1)
2172
+ ])) : (h(), T("div", Rn, [
2173
+ A(c, {
2174
+ keypath: "inventory.closing.template.publish.stillPublishing",
2175
+ tag: "p"
2176
+ }, {
2177
+ started: Y(() => [
2178
+ i("span", Pn, S(f(Ie)(new Date(a.value.createdAt))), 1)
2179
+ ]),
2180
+ progress: Y(() => [
2181
+ i("span", Mn, " (" + S(a.value.completed.length) + "/" + S(a.value.outlets.length) + " completed) ", 1)
2182
+ ]),
2183
+ _: 1
2184
+ }),
2185
+ W(" Your recent publishing task is still pending (" + S(a.value.completed.length) + " / " + S(a.value.outlets.length) + "). Please wait until all publishing task has completed. ", 1)
2186
+ ])) : (h(), T("div", Fn, [
2187
+ i("p", null, S(f(v)("inventory.closing.template.publish.noRecentActivity")), 1),
2188
+ i("p", null, S(f(v)("inventory.closing.template.publish.message")), 1)
2189
+ ])) : (h(), T("div", Cn, [
2190
+ i("p", null, S(f(v)("inventory.closing.template.publish.nothingToPublish")), 1)
2191
+ ])),
2192
+ i("div", En, [
2193
+ A(s, {
2194
+ disabled: !b.value,
2195
+ loading: e.value,
2196
+ label: "Publish to all outlets",
2197
+ onClick: u
2198
+ }, null, 8, ["disabled", "loading"]),
2199
+ A(s, {
2200
+ variant: "tertiary",
2201
+ label: "Close",
2202
+ onClick: l
2203
+ })
2204
+ ])
2205
+ ]);
2206
+ };
2207
+ }
2208
+ }), Bn = { class: "flex-1 flex flex-col gap-8" }, Ln = { class: "flex flex-col" }, Un = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Vn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, zn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Gn = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, gs = /* @__PURE__ */ ee({
2209
+ __name: "ClosingTemplateView",
2210
+ setup(r) {
2211
+ const { t } = oe(), { createTemplate: e, updateTemplate: _, exportTemplates: m, importTemplates: y } = Se(), { templateDialogProps: v, templateDetailsProps: C } = je(Se()), u = Ne(), a = Ae(), b = Ve(), l = rt(), { breakpoints: D } = mt();
2212
+ u.watchLocation(b.onLocationChanged);
2213
+ const w = L(() => b.loading), x = z(""), c = z();
2214
+ function s(E) {
2215
+ var R;
2216
+ (R = c.value) == null || R.openRowDetail(E);
2217
+ }
2218
+ async function $(E) {
2219
+ const { toClosingTemplateListItem: R } = await import("./index-VYeDb0tU.js");
2220
+ return { ...R(E), _rev: E._rev };
2221
+ }
2222
+ const o = L(() => D.value.xs || D.value.sm), k = L(() => o.value ? 10 : 20);
2223
+ function F(E) {
2224
+ switch (E) {
2225
+ case q.Add:
2226
+ return e();
2227
+ case "publish":
2228
+ return P();
2229
+ case "import":
2230
+ return y();
2231
+ case "export":
2232
+ return m();
2233
+ case "refresh":
2234
+ return b.refresh();
2235
+ }
2236
+ }
2237
+ function P() {
2238
+ a.open({
2239
+ title: "Publish closing templates",
2240
+ contentComponent: Nn,
2241
+ contentComponentProps: {
2242
+ onClose() {
2243
+ a.close();
2244
+ }
2245
+ }
2246
+ });
2247
+ }
2248
+ function n(E) {
2249
+ return E;
2250
+ }
2251
+ const d = L(() => o.value ? [
2252
+ {
2253
+ label: t("inventory.closing.template.create.title"),
2254
+ value: q.Add,
2255
+ isPrimary: !0,
2256
+ prependIcon: "add"
2257
+ },
2258
+ {
2259
+ label: t("inventory.common.refresh"),
2260
+ value: "refresh",
2261
+ isPrimary: !1
2262
+ },
2263
+ {
2264
+ label: t("inventory.common.publish"),
2265
+ value: "publish",
2266
+ isPrimary: !1
2267
+ },
2268
+ {
2269
+ label: t("inventory.common.import"),
2270
+ value: "import",
2271
+ isPrimary: !1
2272
+ },
2273
+ {
2274
+ label: t("inventory.common.export"),
2275
+ value: "export",
2276
+ isPrimary: !1
2277
+ }
2278
+ ] : [
2279
+ {
2280
+ label: t("inventory.closing.template.create.title"),
2281
+ value: q.Add,
2282
+ isPrimary: !0,
2283
+ prependIcon: "add"
2284
+ },
2285
+ {
2286
+ label: t("inventory.common.publish"),
2287
+ value: "publish",
2288
+ isPrimary: !1
2289
+ },
2290
+ {
2291
+ label: t("inventory.common.import"),
2292
+ value: "import",
2293
+ isPrimary: !1
2294
+ },
2295
+ {
2296
+ label: t("inventory.common.refresh"),
2297
+ value: "refresh",
2298
+ isPrimary: !1
2299
+ },
2300
+ {
2301
+ label: t("inventory.common.export"),
2302
+ value: "export",
2303
+ isPrimary: !1
2304
+ }
2305
+ ]);
2306
+ return (E, R) => (h(), T(K, null, [
2307
+ A(it, {
2308
+ title: f(t)("inventory.closing.template.title"),
2309
+ actions: d.value,
2310
+ "onClick:action": F
2311
+ }, {
2312
+ default: Y(() => [
2313
+ i("div", {
2314
+ class: Z([
2315
+ "flex flex-col gap-8 max-h-full",
2316
+ {
2317
+ "p-0": o.value,
2318
+ "px-24 ": !o.value
2319
+ }
2320
+ ])
2321
+ }, [
2322
+ A(xt, {
2323
+ searchable: "",
2324
+ search: x.value,
2325
+ "onUpdate:search": R[0] || (R[0] = (N) => x.value = N)
2326
+ }, null, 8, ["search"]),
2327
+ A(kt, {
2328
+ style: Me(f(l).tableHeight),
2329
+ "column-defs": f(b).columnDefs,
2330
+ rows: f(b).templates,
2331
+ "onUpdate:rows": R[1] || (R[1] = (N) => f(b).templates = N),
2332
+ "fetch-page": f(b).fetchTemplatesPage,
2333
+ "refresh-key": f(b).tableKey,
2334
+ ref_key: "tableRef",
2335
+ ref: c,
2336
+ "search-value": x.value,
2337
+ loading: w.value,
2338
+ "fetch-detail": (N, U) => f(_)(N._id, U),
2339
+ "detail-to-row": $,
2340
+ "page-size": k.value
2341
+ }, {
2342
+ "list-row": Y((N) => [
2343
+ A(St, {
2344
+ row: N,
2345
+ onRowClick: (U) => s(U)
2346
+ }, {
2347
+ default: Y((U) => {
2348
+ var j, le, Q, re, ye, ve, ie, ge, ce, be, he, ue, de, _e, xe, ne, ke, p, g, I, M, B;
2349
+ return [
2350
+ i("div", Bn, [
2351
+ i("div", Ln, [
2352
+ i("div", Un, [
2353
+ A(f(Te), {
2354
+ render: (Q = (le = (j = U._id) == null ? void 0 : j.column) == null ? void 0 : le.columnDef) == null ? void 0 : Q.cell,
2355
+ props: (ye = (re = U._id) == null ? void 0 : re.getContext) == null ? void 0 : ye.call(re)
2356
+ }, null, 8, ["render", "props"])
2357
+ ]),
2358
+ i("div", Vn, [
2359
+ A(f(Te), {
2360
+ render: (ge = (ie = (ve = U.name) == null ? void 0 : ve.column) == null ? void 0 : ie.columnDef) == null ? void 0 : ge.cell,
2361
+ props: (be = (ce = U.name) == null ? void 0 : ce.getContext) == null ? void 0 : be.call(ce)
2362
+ }, null, 8, ["render", "props"])
2363
+ ]),
2364
+ i("div", null, S((he = N.original.locations) != null && he.length ? f(t)("inventory.closing.table.enabledForN", {
2365
+ count: ((ue = N.original.locations) == null ? void 0 : ue.length) ?? 0
2366
+ }) : f(t)("inventory.closing.table.enabledForAll")), 1),
2367
+ i("div", zn, S([
2368
+ ...N.original.previewItemNames,
2369
+ ...N.original.itemCount - N.original.previewItemNames.length > 0 ? [
2370
+ `and ${N.original.itemCount - N.original.previewItemNames.length} more items`
2371
+ ] : []
2372
+ ].join(", ")), 1),
2373
+ i("div", Gn, [
2374
+ A(f(Te), {
2375
+ render: (xe = (_e = (de = U.ref) == null ? void 0 : de.column) == null ? void 0 : _e.columnDef) == null ? void 0 : xe.cell,
2376
+ props: (ke = (ne = U.ref) == null ? void 0 : ne.getContext) == null ? void 0 : ke.call(ne)
2377
+ }, null, 8, ["render", "props"])
2378
+ ])
2379
+ ]),
2380
+ i("div", null, [
2381
+ A(f(Te), {
2382
+ render: (I = (g = (p = U.status) == null ? void 0 : p.column) == null ? void 0 : g.columnDef) == null ? void 0 : I.cell,
2383
+ props: (B = (M = U.status) == null ? void 0 : M.getContext) == null ? void 0 : B.call(M)
2384
+ }, null, 8, ["render", "props"])
2385
+ ])
2386
+ ])
2387
+ ];
2388
+ }),
2389
+ _: 2
2390
+ }, 1032, ["row", "onRowClick"])
2391
+ ]),
2392
+ _: 1
2393
+ }, 8, ["style", "column-defs", "rows", "fetch-page", "refresh-key", "search-value", "loading", "fetch-detail", "page-size"])
2394
+ ], 2)
2395
+ ]),
2396
+ _: 1
2397
+ }, 8, ["title", "actions"]),
2398
+ (h(), H(nt, { to: "body" }, [
2399
+ A(wn, st(at(f(C))), null, 16),
2400
+ A(_n, lt(f(v), {
2401
+ onSubmitted: R[2] || (R[2] = (N) => f(b).refresh())
2402
+ }), null, 16)
2403
+ ]))
2404
+ ], 64));
2405
+ }
2406
+ });
2407
+ export {
2408
+ gs as default
2409
+ };