@feedmepos/mf-inventory-portal 1.6.0-dev.3 → 1.6.0-dev.5

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