@feedmepos/mf-inventory-portal 1.7.0 → 1.7.1

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