@feedmepos/mf-inventory-portal 1.2.22-dev.2 → 1.2.22-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/{App-DtwLZ9Ng.js → App-aHs88TEq.js} +1 -1
  2. package/dist/{ApprovalView-DTiPzA1y.js → ApprovalView-DBZQsKg9.js} +2 -2
  3. package/dist/{BindingsDialog--1wB_TX2.js → BindingsDialog-arTYvJn2.js} +2 -2
  4. package/dist/{BindingsPicker-JjZfjlvz.js → BindingsPicker-Bm0s6sKE.js} +1 -1
  5. package/dist/{BindingsTable-M2CGWdTD.js → BindingsTable-DXlM-qDU.js} +1 -1
  6. package/dist/ClosingDraftView-DVB02I09.js +1888 -0
  7. package/dist/{ClosingTemplateView-B1TVIzzy.js → ClosingTemplateView-k8EkjlIJ.js} +2 -2
  8. package/dist/{DeliveryOrderPrintPreview-CUXfCixj.js → DeliveryOrderPrintPreview-CSv5FOby.js} +1 -1
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Bdw3Q4Dz.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-D0BKSSSp.js} +3 -3
  10. package/dist/{FmMultiselectDialog-CyYcvvyg.js → FmMultiselectDialog-DOf8rbVD.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-D-FDSjxY.js → FmUnitInput.vue_vue_type_script_setup_true_lang-BZX05ToS.js} +1 -1
  12. package/dist/{ImportView-BR7JpsG8.js → ImportView-6ckPf1Ll.js} +2 -2
  13. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-Bae5DUA9.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-QK12Klz5.js} +1 -1
  14. package/dist/{IngredientGroupView-c6XH5Fzg.js → IngredientGroupView-D2RuwnJ3.js} +2 -2
  15. package/dist/{IngredientsView-D4JiQ6Bp.js → IngredientsView-CZIyrGJ0.js} +7 -7
  16. package/dist/{IntegrationView-BdOTe6FG.js → IntegrationView-D9JrR8Hb.js} +3 -3
  17. package/dist/{InventoryBindingForm-kqrZutMr.js → InventoryBindingForm-6QGOGZlB.js} +1 -1
  18. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-DZ-Mr8-U.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DG_WKGVU.js} +3 -3
  19. package/dist/{InventoryBindingSummary-D4p9cOiy.js → InventoryBindingSummary-CoeODKLp.js} +1 -1
  20. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Bj_2aQiY.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Ovi_bWlF.js} +1 -1
  21. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-CX9H2gLU.js → PremiumBadge.vue_vue_type_script_setup_true_lang-CaKjg0eV.js} +1 -1
  22. package/dist/{PublishView-DcQQtuF8.js → PublishView-BLtshSks.js} +1 -1
  23. package/dist/{PurchaseOrderPrintPreview-Ueo4Yftu.js → PurchaseOrderPrintPreview-DCLjVNlh.js} +1 -1
  24. package/dist/{ReceiveRequestView-Cikz66hY.js → ReceiveRequestView-DdJ3_qMY.js} +8 -8
  25. package/dist/{RecipeView-DL1kKy2w.js → RecipeView-DYFDguU9.js} +3 -3
  26. package/dist/{StockView-DzaCcxc5.js → StockView-DyUrO7Y0.js} +7 -7
  27. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-DP5AFZM2.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Bj05qEWl.js} +1 -1
  28. package/dist/{SupplierView-CJuI_jPc.js → SupplierView-BYDbDGfd.js} +4 -4
  29. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-BoZEbHkN.js → TransferDetails.vue_vue_type_script_setup_true_lang-DuaHM-Wk.js} +5 -5
  30. package/dist/{TransferTemplateView-DiGdnr0-.js → TransferTemplateView-db5L1CIZ.js} +7 -7
  31. package/dist/{UnitView-CA2isH5r.js → UnitView-4ygzmFTY.js} +3 -3
  32. package/dist/{WarehouseView-BMUJN1D1.js → WarehouseView-D-b-t21n.js} +1 -1
  33. package/dist/{app-DdrL4md8.js → app-BDiHcGqi.js} +28748 -28983
  34. package/dist/app.js +1 -1
  35. package/dist/{decimal-DJjE7Vf3.js → decimal-C-phHxE7.js} +1 -1
  36. package/dist/{format-unit-display-CK-PNM0G.js → format-unit-display-MVZRrkkD.js} +3 -3
  37. package/dist/{import-export.helper-CJeCekEB.js → import-export.helper-C3camZX5.js} +1 -1
  38. package/dist/{index-Crgf6sCC.js → index-B60G756h.js} +1 -1
  39. package/dist/{index-D4F6boO1.js → index-B6zknB--.js} +1 -1
  40. package/dist/{purchase-order-template-BOLP3UzN.js → purchase-order-template-Bkz_Xjv5.js} +1 -1
  41. package/dist/{stock-DqL6z9wL.js → stock-DnawcaKQ.js} +1 -1
  42. package/dist/{supplier-CW3GGX9U.js → supplier-Bq0fMcn0.js} +1 -1
  43. package/dist/tsconfig.app.tsbuildinfo +1 -1
  44. package/dist/{use-ingredient-select-dialog-CrCo-DHA.js → use-ingredient-select-dialog-BH2O0eEN.js} +1 -1
  45. package/dist/{use-inventory-binding-dialog-RdX9Q4q9.js → use-inventory-binding-dialog-CI_pMWSk.js} +1 -1
  46. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +56 -0
  47. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +468 -0
  48. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +8 -1
  49. package/package.json +4 -4
  50. package/dist/ClosingDraftView-B800NjEZ.js +0 -1739
@@ -0,0 +1,1888 @@
1
+ import { defineComponent as He, ref as H, computed as V, onMounted as Ye, resolveComponent as U, openBlock as C, createElementBlock as L, Fragment as ee, createTextVNode as X, createBlock as se, withCtx as G, createElementVNode as s, toDisplayString as J, unref as F, createVNode as x, createCommentVNode as de, h as T, reactive as kt, watch as ht, isRef as at, normalizeClass as De, renderList as Ce, normalizeStyle as nt, Teleport as At, mergeProps as xt } from "vue";
2
+ import { aa as _t, u as ze, ax as z, am as ot, ay as st, r as Dt, Z as Qe, n as N, t as wt, a0 as Be, W as St, Y as jt, X as Ct, az as rt, aA as lt, ah as ct, aB as pe, an as Bt, ac as Ke, ab as ve, a6 as Ue, D as tt, j as Re, i as Ft, f as Tt, a as $t, $ as Ie, a9 as Mt, G as Rt, I as It, J as Pt, K as Vt, L as Pe } from "./app-BDiHcGqi.js";
3
+ import { useCoreStore as Ut, useI18n as it } from "@feedmepos/mf-common";
4
+ import { useSnackbar as Ge, useDialog as Lt, useProxiedModel as Et, components as Ve, useBreakpoints as Ht } from "@feedmepos/ui-library";
5
+ import { defineStore as ut, storeToRefs as zt } from "pinia";
6
+ import { a as We, u as dt } from "./stock-DnawcaKQ.js";
7
+ import { E as Nt } from "./empty-placeholder-wf6-BWE8.js";
8
+ const Ne = _t((n, r) => {
9
+ function e() {
10
+ return ze().currentLocation.dbName;
11
+ }
12
+ return {
13
+ async getDraft(m) {
14
+ const p = e(), w = `${n.inventoryBackendUrl}/${p}/closing-draft/${m}`;
15
+ return r.get(w);
16
+ },
17
+ async readDrafts() {
18
+ const m = e(), p = `${n.inventoryBackendUrl}/${m}/closing-draft`;
19
+ return r.get(p);
20
+ },
21
+ async runOperation(m) {
22
+ const p = e(), w = `${n.inventoryBackendUrl}/${p}/closing-draft/run-operation`;
23
+ return r.post(w, m);
24
+ },
25
+ async sync(m) {
26
+ const p = e(), w = `${n.inventoryBackendUrl}/${p}/closing-draft/sync`;
27
+ return r.post(w, m);
28
+ }
29
+ };
30
+ }), Ot = { class: "fm-typo-en-body-lg-400" }, Kt = { class: "fm-typo-en-body-lg-600" }, Yt = {
31
+ key: 0,
32
+ class: "flex flex-col"
33
+ }, Qt = { class: "flex gap-12 py-8 justify-end w-full" }, Oe = /* @__PURE__ */ He({
34
+ __name: "ClosingDraftAction",
35
+ props: {
36
+ draft: {},
37
+ action: {},
38
+ onCancel: { type: Function },
39
+ onFinished: { type: Function }
40
+ },
41
+ setup(n) {
42
+ const r = n, e = H(), m = Ne(), p = Ge(), w = H(!1), v = H(null), R = H(!1), S = V(() => {
43
+ switch (r.action) {
44
+ case z.enum.approveDraft:
45
+ return "Approve";
46
+ case z.enum.rejectDraft:
47
+ return "Reject";
48
+ case z.enum.markAsFailed:
49
+ return "Mark as Failed";
50
+ }
51
+ throw new Error(`Unknown action: ${r.action}`);
52
+ }), k = V(() => {
53
+ switch (r.action) {
54
+ case z.enum.approveDraft:
55
+ return "primary";
56
+ case z.enum.rejectDraft:
57
+ return "destructive";
58
+ case z.enum.markAsFailed:
59
+ return "destructive";
60
+ }
61
+ throw new Error(`Unknown action: ${r.action}`);
62
+ });
63
+ Ye(() => {
64
+ if (r.draft.effectiveAt)
65
+ v.value = new Date(r.draft.effectiveAt);
66
+ else {
67
+ const o = new Date(r.draft.createdAt);
68
+ o.setHours(23, 59, 59, 999), v.value = o;
69
+ }
70
+ R.value = !0;
71
+ });
72
+ const $ = V({
73
+ get() {
74
+ return v.value === null ? "" : ot(v.value);
75
+ },
76
+ set(o) {
77
+ if (o) {
78
+ const a = /* @__PURE__ */ new Date(`${o} ${P.value}`);
79
+ a.setSeconds(59, 999), v.value = a;
80
+ } else
81
+ v.value = null;
82
+ }
83
+ }), P = V({
84
+ get() {
85
+ return v.value === null ? "" : st(v.value);
86
+ },
87
+ set(o) {
88
+ if (o) {
89
+ const a = /* @__PURE__ */ new Date(`${$.value} ${o}`);
90
+ a.setSeconds(59, 999), v.value = a;
91
+ } else
92
+ v.value = null;
93
+ }
94
+ });
95
+ async function I() {
96
+ w.value = !0;
97
+ try {
98
+ await m.runOperation({
99
+ _id: r.draft._id,
100
+ _rev: r.draft._rev ?? "",
101
+ action: r.action,
102
+ data: {
103
+ effectiveAt: v.value ? v.value.toISOString() : null,
104
+ remark: e.value
105
+ }
106
+ }).delayed(500), p.open({
107
+ title: "Success",
108
+ message: "Action submitted",
109
+ type: "success"
110
+ }), r.onFinished();
111
+ } catch (o) {
112
+ p.open({
113
+ title: "Something went wrong",
114
+ message: "Unable to submit action. Please try again",
115
+ type: "error"
116
+ }), console.error("error on submit closing draft action", o);
117
+ } finally {
118
+ w.value = !1;
119
+ }
120
+ }
121
+ return (o, a) => {
122
+ const _ = U("FmLabel"), O = U("FmDatePicker"), f = U("FmTimePicker"), y = U("FmTextField"), h = U("FmButton"), D = U("FmForm");
123
+ return R.value ? (C(), se(D, {
124
+ key: 1,
125
+ onValidationSuccess: I,
126
+ class: "flex flex-col gap-32",
127
+ disabled: w.value
128
+ }, {
129
+ default: G(() => [
130
+ s("div", Ot, [
131
+ a[4] || (a[4] = X(" You are about to ")),
132
+ s("span", Kt, J(S.value), 1),
133
+ a[5] || (a[5] = X(" this draft. Please provide a remark to justify this action. "))
134
+ ]),
135
+ o.action === F(z).enum.approveDraft ? (C(), L("div", Yt, [
136
+ x(_, { class: "fm-typo-en-body-lg-600" }, {
137
+ default: G(() => a[6] || (a[6] = [
138
+ X("Closing Date")
139
+ ])),
140
+ _: 1
141
+ }),
142
+ x(O, {
143
+ modelValue: $.value,
144
+ "onUpdate:modelValue": a[0] || (a[0] = (M) => $.value = M)
145
+ }, null, 8, ["modelValue"]),
146
+ x(_, { class: "fm-typo-en-body-lg-600" }, {
147
+ default: G(() => a[7] || (a[7] = [
148
+ X("Closing Time")
149
+ ])),
150
+ _: 1
151
+ }),
152
+ x(f, {
153
+ modelValue: P.value,
154
+ "onUpdate:modelValue": a[1] || (a[1] = (M) => P.value = M)
155
+ }, null, 8, ["modelValue"])
156
+ ])) : de("", !0),
157
+ x(y, {
158
+ modelValue: e.value,
159
+ "onUpdate:modelValue": a[2] || (a[2] = (M) => e.value = M),
160
+ label: "Remark",
161
+ "label-mark": "required",
162
+ rules: [F(Dt)()]
163
+ }, null, 8, ["modelValue", "rules"]),
164
+ s("div", Qt, [
165
+ x(h, {
166
+ label: "Cancel",
167
+ variant: "tertiary",
168
+ onClick: a[3] || (a[3] = (M) => o.onCancel())
169
+ }),
170
+ x(h, {
171
+ label: S.value,
172
+ type: "submit",
173
+ variant: k.value,
174
+ loading: w.value
175
+ }, null, 8, ["label", "variant", "loading"])
176
+ ])
177
+ ]),
178
+ _: 1
179
+ }, 8, ["disabled"])) : (C(), L(ee, { key: 0 }, [
180
+ X("Loading")
181
+ ], 64));
182
+ };
183
+ }
184
+ }), Gt = Be(0);
185
+ function mt(n) {
186
+ const r = n.measurementsAmounts.groupBy((m) => m.measurement.id), e = n.sku.unit.measurements.reduce((m, p) => {
187
+ var R, S;
188
+ const w = ((S = (R = r.get(p.id)) == null ? void 0 : R[0]) == null ? void 0 : S.amount) ?? Gt, v = Qe(p.conversion, w);
189
+ return m + +N(v);
190
+ }, +N(n.baseAmount));
191
+ return wt(e, n.baseAmount.precision);
192
+ }
193
+ const Wt = Be(0), qt = Be(100), ft = "N/A";
194
+ function Zt(n, r, e, m, p, w) {
195
+ var D;
196
+ const v = mt(n), R = m ?? v, S = rt(R, r), k = r.amount === 0 ? null : lt(S, {
197
+ ...r,
198
+ amount: Math.abs(r.amount)
199
+ }), $ = k ? Qe(k, qt) : null, P = (D = n.sku.defaultCost) != null && D.costPerUnit ? n.sku.defaultCost.costPerUnit.amount / Math.pow(10, n.sku.defaultCost.costPerUnit.precision) : 0, I = p ? +N(p) : 0, o = +N(r), a = +N(R), _ = o - a, O = _ * P, f = a * P, y = o * P;
200
+ return {
201
+ code: n.sku.code,
202
+ name: n.sku.name,
203
+ baseUnit: n.sku.unit.abbrev,
204
+ baseUnitAmount: +N(n.baseAmount),
205
+ ...n.measurementsAmounts.filter(
206
+ (M) => Jt(M.measurement) && e.includes(M.measurement.id)
207
+ ).reduce(
208
+ (M, Z, W) => (M[`measurementAbbrev${W}`] = `(${Z.measurement.abbrev}) × ${N(Z.measurement.conversion)}`, M[`measurementAmount${W}`] = +N(Z.amount), M),
209
+ {}
210
+ ),
211
+ systemBalance: o,
212
+ physicalBalance: a,
213
+ adjustedAmount: +N(S),
214
+ adjustedDiffPercentage: $ ? +N(ct($, 2)) : null,
215
+ costPerUnit: P,
216
+ opening: I,
217
+ adjustmentTypes: w ?? ft,
218
+ varianceQty: _,
219
+ varianceRM: O,
220
+ stockTakeValue: f,
221
+ systemValue: y
222
+ };
223
+ }
224
+ function Jt(n) {
225
+ return !n.abbrev.toLocaleLowerCase().includes("inactive");
226
+ }
227
+ function Xt(n) {
228
+ const r = pt(n);
229
+ return n.reduce(
230
+ (e, m) => {
231
+ var p;
232
+ return Math.max(e, ((p = r == null ? void 0 : r.get(m.sku._id)) == null ? void 0 : p[0].length) ?? 0);
233
+ },
234
+ 0
235
+ );
236
+ }
237
+ function pt(n) {
238
+ return n.groupBy(
239
+ (r) => r.sku._id,
240
+ (r) => r.measurementsAmounts.filter((e) => !e.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((e) => e.measurement.id)
241
+ );
242
+ }
243
+ function ea(n) {
244
+ return [
245
+ {
246
+ id: "code",
247
+ name: "Code"
248
+ },
249
+ {
250
+ id: "name",
251
+ name: "Name"
252
+ },
253
+ {
254
+ id: "baseUnit",
255
+ name: "Base unit"
256
+ },
257
+ {
258
+ id: "costPerUnit",
259
+ name: "Cost per unit"
260
+ },
261
+ {
262
+ id: "opening",
263
+ name: "Opening (B/F)"
264
+ },
265
+ {
266
+ id: "adjustmentTypes",
267
+ name: "Type"
268
+ },
269
+ {
270
+ id: "varianceQty",
271
+ name: "Variance (Qty)"
272
+ },
273
+ {
274
+ id: "varianceRM",
275
+ name: "Variance (RM)"
276
+ },
277
+ {
278
+ id: "physicalBalance",
279
+ name: "Stock take (Qty)"
280
+ },
281
+ {
282
+ id: "systemBalance",
283
+ name: "System balance (Qty)"
284
+ },
285
+ {
286
+ id: "stockTakeValue",
287
+ name: "Stock take value (RM)"
288
+ },
289
+ {
290
+ id: "systemValue",
291
+ name: "System value (RM)"
292
+ },
293
+ {
294
+ id: "adjustedAmount",
295
+ name: "Adjusted balance"
296
+ },
297
+ {
298
+ id: "adjustedDiffPercentage",
299
+ name: "Diff (%)"
300
+ },
301
+ {
302
+ id: "baseUnitAmount",
303
+ name: "Base unit amount"
304
+ },
305
+ ...Array.from({ length: n }).flatMap((e, m) => [
306
+ {
307
+ id: `measurementAmount${m}`,
308
+ name: `UOM amount ${m + 1}`
309
+ },
310
+ {
311
+ id: `measurementAbbrev${m}`,
312
+ name: `UOM ${m + 1}`
313
+ }
314
+ ])
315
+ ];
316
+ }
317
+ function ta(n, r, e) {
318
+ var y, h, D, M, Z, W, re;
319
+ const m = r.groupBy(
320
+ (B) => B.id,
321
+ (B) => B.balance
322
+ ), p = e.groupBy(
323
+ (B) => B.id,
324
+ (B) => B.balance
325
+ ), w = /* @__PURE__ */ new Map();
326
+ if (n.opening)
327
+ for (const B of n.opening)
328
+ w.set(B.skuId, B.balance);
329
+ const v = /* @__PURE__ */ new Map();
330
+ if (n.adjustmentSnapshot)
331
+ for (const B of n.adjustmentSnapshot) {
332
+ const te = Object.keys(B.adjustmentsByType).join(", ");
333
+ v.set(B.skuId, te || ft);
334
+ }
335
+ const R = [...n.items, ...n.negativeStockItems ?? []], S = pt(R), k = R.map((B) => {
336
+ var ye, ge, Y;
337
+ const te = ((ye = m.get(B.sku._id)) == null ? void 0 : ye[0]) ?? Wt, be = ((ge = S == null ? void 0 : S.get(B.sku._id)) == null ? void 0 : ge[0]) ?? [], ke = w.get(B.sku._id), fe = v.get(B.sku._id);
338
+ return Zt(
339
+ B,
340
+ te,
341
+ be,
342
+ (Y = p.get(B.sku._id)) == null ? void 0 : Y[0],
343
+ ke,
344
+ fe
345
+ );
346
+ }), $ = Xt(R), I = Ut().currentBusiness.value, o = ea($), a = [
347
+ ["Business name:", I == null ? void 0 : I.name],
348
+ ["Business ID:", I == null ? void 0 : I._id],
349
+ ["Menu version", I == null ? void 0 : I.menuVersion],
350
+ ["Created at", new Date(n.createdAt)],
351
+ ["Created by", (y = n.createdBy) == null ? void 0 : y.name],
352
+ ["Updated at", new Date(n.updatedAt)],
353
+ ["Updated by", (h = n.updatedBy) == null ? void 0 : h.name],
354
+ ["Recent action", n.approvedAt ? "Approve" : n.rejectionHistory ? "Reject" : ""],
355
+ [
356
+ "Action by",
357
+ n.approvedAt ? (D = n.approvedBy) == null ? void 0 : D.name : n.rejectionHistory ? (Z = (M = n.rejectionHistory[0]) == null ? void 0 : M.rejectedBy) == null ? void 0 : Z.name : ""
358
+ ],
359
+ [
360
+ "Action at",
361
+ n.approvedAt ? new Date(n.approvedAt) : n.rejectionHistory ? new Date((W = n.rejectionHistory[0]) == null ? void 0 : W.rejectedAt) : ""
362
+ ],
363
+ [
364
+ "Action remark",
365
+ n.approvedAt ? n.approveRemark : n.rejectionHistory ? new Date((re = n.rejectionHistory[0]) == null ? void 0 : re.rejectRemark) : ""
366
+ ],
367
+ [],
368
+ o.map((B) => B.name),
369
+ ...k.map((B) => o.map((te) => B[te.id]))
370
+ ], _ = o.map((B) => `system:${B.id}`), O = St(a, _), f = `[${I == null ? void 0 : I.name}] closing draft (${jt(new Date(n.updatedAt))}).xlsx`;
371
+ return Ct(O, f), f;
372
+ }
373
+ const aa = { class: "flex flex-col" }, na = { class: "flex gap-12 py-8 justify-end w-full" }, oa = /* @__PURE__ */ He({
374
+ __name: "RefreshBalanceAction",
375
+ props: {
376
+ draft: {},
377
+ onCancel: { type: Function },
378
+ onFinished: { type: Function }
379
+ },
380
+ setup(n) {
381
+ const r = n;
382
+ We();
383
+ const e = H(!1), m = H(null), p = H(!1);
384
+ Ye(() => {
385
+ if (r.draft.effectiveAt)
386
+ m.value = new Date(r.draft.effectiveAt);
387
+ else {
388
+ const S = new Date(r.draft.createdAt);
389
+ S.setHours(23, 59, 59, 999), m.value = S;
390
+ }
391
+ p.value = !0;
392
+ });
393
+ const w = V({
394
+ get() {
395
+ return m.value === null ? "" : ot(m.value);
396
+ },
397
+ set(S) {
398
+ if (S) {
399
+ const k = /* @__PURE__ */ new Date(`${S} ${v.value}`);
400
+ k.setSeconds(59, 999), m.value = k;
401
+ } else
402
+ m.value = null;
403
+ }
404
+ }), v = V({
405
+ get() {
406
+ return m.value === null ? "" : st(m.value);
407
+ },
408
+ set(S) {
409
+ if (S) {
410
+ const k = /* @__PURE__ */ new Date(`${w.value} ${S}`);
411
+ k.setSeconds(59, 999), m.value = k;
412
+ } else
413
+ m.value = null;
414
+ }
415
+ });
416
+ async function R() {
417
+ e.value = !0, r.onFinished(m.value.toISOString());
418
+ }
419
+ return (S, k) => {
420
+ const $ = U("FmLabel"), P = U("FmDatePicker"), I = U("FmTimePicker"), o = U("FmButton"), a = U("FmForm");
421
+ return p.value ? (C(), se(a, {
422
+ key: 1,
423
+ onValidationSuccess: R,
424
+ class: "flex flex-col gap-32",
425
+ disabled: e.value
426
+ }, {
427
+ default: G(() => [
428
+ k[5] || (k[5] = s("div", { class: "fm-typo-en-body-lg-400" }, [
429
+ s("p", null, [
430
+ X(" Performing "),
431
+ s("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
432
+ X(" until closing effective date and time. ")
433
+ ]),
434
+ s("p", { class: "mt-2" }, [
435
+ X(" Please note that this action will "),
436
+ s("b", null, "update"),
437
+ X(" the effective date and time. ")
438
+ ])
439
+ ], -1)),
440
+ s("div", aa, [
441
+ x($, { class: "fm-typo-en-body-lg-600" }, {
442
+ default: G(() => k[3] || (k[3] = [
443
+ X("Closing Date")
444
+ ])),
445
+ _: 1
446
+ }),
447
+ x(P, {
448
+ modelValue: w.value,
449
+ "onUpdate:modelValue": k[0] || (k[0] = (_) => w.value = _)
450
+ }, null, 8, ["modelValue"]),
451
+ x($, { class: "fm-typo-en-body-lg-600" }, {
452
+ default: G(() => k[4] || (k[4] = [
453
+ X("Closing Time")
454
+ ])),
455
+ _: 1
456
+ }),
457
+ x(I, {
458
+ modelValue: v.value,
459
+ "onUpdate:modelValue": k[1] || (k[1] = (_) => v.value = _)
460
+ }, null, 8, ["modelValue"])
461
+ ]),
462
+ s("div", na, [
463
+ x(o, {
464
+ label: "Cancel",
465
+ variant: "tertiary",
466
+ onClick: k[2] || (k[2] = (_) => S.onCancel())
467
+ }),
468
+ x(o, {
469
+ label: "Refresh balance",
470
+ type: "submit",
471
+ variant: "primary",
472
+ loading: e.value
473
+ }, null, 8, ["loading"])
474
+ ])
475
+ ]),
476
+ _: 1
477
+ }, 8, ["disabled"])) : (C(), L(ee, { key: 0 }, [
478
+ X("Loading")
479
+ ], 64));
480
+ };
481
+ }
482
+ }), Ee = ut(
483
+ "closingDraftActions",
484
+ function() {
485
+ const r = Lt(), e = Ge(), m = We(), p = Ne(), w = dt(), v = H(!1), R = H();
486
+ function S(f) {
487
+ const y = {
488
+ draft: f
489
+ };
490
+ R.value = y, v.value = !0;
491
+ }
492
+ async function k(f) {
493
+ var h;
494
+ if (f.status === pe.enum.COMPLETED) {
495
+ const D = f.closingAdjustmentId;
496
+ if (!D)
497
+ return e.open({
498
+ title: "Something went wrong",
499
+ message: "Closing draft is completed but closing document cannot be found.",
500
+ type: "error"
501
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
502
+ draftId: f._id
503
+ }), [];
504
+ const M = await m.readAdjustmentById(D);
505
+ return ((M == null ? void 0 : M.skus) ?? []).map((W) => ({
506
+ id: W.sku._id,
507
+ balance: W.fromBalance,
508
+ costs: W.fromCostBalances
509
+ }));
510
+ } else
511
+ return await w.readStockBalance(), ((h = w.stockBalance) == null ? void 0 : h.skus) ?? [];
512
+ }
513
+ async function $(f, y, h) {
514
+ y || (e.open({
515
+ title: "Exporting",
516
+ message: "Fetching data..."
517
+ }), y = await k(f)), ta(f, y, h ?? []);
518
+ }
519
+ function P(f, y) {
520
+ r.open({
521
+ title: "Approve draft",
522
+ contentComponent: Oe,
523
+ contentComponentProps: {
524
+ draft: f,
525
+ action: z.enum.approveDraft,
526
+ onFinished: () => {
527
+ r.close(), y == null || y();
528
+ },
529
+ onCancel: () => r.close()
530
+ }
531
+ });
532
+ }
533
+ function I(f, y) {
534
+ r.open({
535
+ title: "Reject draft",
536
+ contentComponent: Oe,
537
+ contentComponentProps: {
538
+ draft: f,
539
+ action: z.enum.rejectDraft,
540
+ onFinished: () => {
541
+ r.close(), y == null || y();
542
+ },
543
+ onCancel: () => r.close()
544
+ }
545
+ });
546
+ }
547
+ function o(f, y) {
548
+ r.open({
549
+ title: "Mark draft as failed",
550
+ contentComponent: Oe,
551
+ contentComponentProps: {
552
+ draft: f,
553
+ action: z.enum.markAsFailed,
554
+ onFinished: () => {
555
+ r.close(), y == null || y();
556
+ },
557
+ onCancel: () => r.close()
558
+ }
559
+ });
560
+ }
561
+ async function a(f, y) {
562
+ await p.sync({
563
+ _id: f._id,
564
+ _rev: f._rev ?? "",
565
+ action: z.enum.approveDraft,
566
+ data: {
567
+ remark: f.remark ?? ""
568
+ }
569
+ }).delayed(500), e.open({
570
+ title: "Success",
571
+ message: "Sync requested",
572
+ type: "success"
573
+ }), y == null || y();
574
+ }
575
+ function _() {
576
+ v.value = !1;
577
+ }
578
+ async function O(f, y, h) {
579
+ await r.open({
580
+ title: "Refresh balance",
581
+ contentComponent: oa,
582
+ contentComponentProps: {
583
+ draft: f,
584
+ onFinished: (D) => {
585
+ r.close(), h == null || h(D);
586
+ },
587
+ onCancel: async () => {
588
+ r.close(), y == null || y();
589
+ }
590
+ }
591
+ });
592
+ }
593
+ return {
594
+ viewDraft: S,
595
+ closeDraftDialog: _,
596
+ approveDraft: P,
597
+ rejectDraft: I,
598
+ markAsFailed: o,
599
+ syncDraft: a,
600
+ exportDraft: $,
601
+ refreshBalance: O,
602
+ viewClosingDraftShow: v,
603
+ viewClosingDraftProps: R
604
+ };
605
+ }
606
+ );
607
+ function Le(n) {
608
+ switch (n) {
609
+ case "DRAFT":
610
+ return "fm-status-badge-draft";
611
+ case "PROCESSING":
612
+ return "fm-status-badge-processing";
613
+ case "FAILED":
614
+ return "fm-status-badge-cancel";
615
+ case "COMPLETED":
616
+ return "fm-status-badge-complete";
617
+ }
618
+ }
619
+ const sa = ut(
620
+ "closingDraftTable",
621
+ function() {
622
+ const { t: r } = it(), e = Ee(), m = H(new Array()), p = H(!1), w = ze(), v = Ne();
623
+ async function R() {
624
+ if (m.value = [], !!w._currentLocation) {
625
+ p.value = !0;
626
+ try {
627
+ const [o] = await Promise.all([v.readDrafts()]).delayed(1e3);
628
+ m.value = o.reverse();
629
+ } catch (o) {
630
+ console.log("Something went wrong when fetching drafts:", o);
631
+ } finally {
632
+ p.value = !1;
633
+ }
634
+ }
635
+ }
636
+ async function S(o) {
637
+ if (!m.value.find((a) => a._id) && w._currentLocation) {
638
+ p.value = !0;
639
+ try {
640
+ const [a] = await Promise.all([
641
+ v.getDraft(o),
642
+ new Promise((_) => setTimeout(_, 1e3))
643
+ ]);
644
+ m.value = [a];
645
+ } catch (a) {
646
+ console.log("Something went wrong when fetching drafts:", a);
647
+ } finally {
648
+ p.value = !1;
649
+ }
650
+ }
651
+ }
652
+ function k(o) {
653
+ m.value = m.value.map((a) => a._id === o._id ? {
654
+ ...o,
655
+ _rev: a._rev
656
+ } : a);
657
+ }
658
+ function $() {
659
+ e.closeDraftDialog(), R();
660
+ }
661
+ function P(o, a) {
662
+ switch (a = Tt(a), o) {
663
+ case Re.Details:
664
+ return e.viewDraft(a);
665
+ case Re.Export:
666
+ return e.exportDraft(a);
667
+ case z.enum.approveDraft:
668
+ return e.approveDraft(a, $);
669
+ case z.enum.rejectDraft:
670
+ return e.rejectDraft(a, $);
671
+ case z.enum.markAsFailed:
672
+ return e.markAsFailed(a, $);
673
+ }
674
+ }
675
+ return {
676
+ columnDefs: [
677
+ {
678
+ id: "_id",
679
+ accessorKey: "_id",
680
+ header: () => r("inventory.closing.table.createdAt"),
681
+ cell(o) {
682
+ return Bt(`${o.getValue()}`);
683
+ },
684
+ enableSorting: !0
685
+ },
686
+ {
687
+ accessorKey: "effectiveAt",
688
+ header: () => "Effective at",
689
+ cell(o) {
690
+ const a = o.row.original;
691
+ let _ = o.getValue();
692
+ return _ || (_ = Ke(a._id)), ve(_);
693
+ },
694
+ enableSorting: !0,
695
+ size: 200
696
+ },
697
+ {
698
+ id: "updatedAt",
699
+ accessorFn: (o) => ve(o.updatedAt),
700
+ header: () => "Updated at",
701
+ enableSorting: !0,
702
+ size: 200
703
+ },
704
+ {
705
+ id: "updatedBy",
706
+ accessorKey: "updatedBy.name",
707
+ header: () => "Last update by",
708
+ enableSorting: !0,
709
+ size: 200
710
+ },
711
+ {
712
+ id: "noOfItems",
713
+ accessorFn: (o) => {
714
+ var a;
715
+ return o.items.length + (((a = o.negativeStockItems) == null ? void 0 : a.length) ?? 0);
716
+ },
717
+ header: () => r("inventory.closing.table.noOfItems"),
718
+ enableSorting: !1,
719
+ meta: {
720
+ width: "10rem",
721
+ textAlign: "right"
722
+ }
723
+ },
724
+ {
725
+ id: "recentRemark",
726
+ accessorFn: (o) => {
727
+ var a;
728
+ return (o == null ? void 0 : o.approveRemark) ?? ((a = o == null ? void 0 : o.rejectionHistory) == null ? void 0 : a.computeFirst((_) => _.rejectRemark)) ?? o.remark;
729
+ },
730
+ header: () => "Recent remark"
731
+ },
732
+ {
733
+ id: "status",
734
+ accessorFn: (o) => o.status,
735
+ header: () => r("inventory.closing.table.status"),
736
+ enableSorting: !1,
737
+ cell(o) {
738
+ var h;
739
+ const a = o.row.original, _ = a.status, O = new Date(a.updatedAt), f = (h = a == null ? void 0 : a.rejectionHistory) == null ? void 0 : h.computeFirst((D) => D.rejectedAt), y = f ? new Date(f) : null;
740
+ return _ === "DRAFT" && y ? y.getTime() > O.getTime() ? T(
741
+ "div",
742
+ {
743
+ class: "flex"
744
+ },
745
+ T(
746
+ "div",
747
+ {
748
+ class: ["fm-status-badge", Le("FAILED")]
749
+ },
750
+ "Rejected"
751
+ )
752
+ ) : T(
753
+ "div",
754
+ {
755
+ class: "flex"
756
+ },
757
+ T(
758
+ "div",
759
+ {
760
+ class: ["fm-status-badge", Le("PROCESSING")]
761
+ },
762
+ "Updated"
763
+ )
764
+ ) : T(
765
+ "div",
766
+ {
767
+ class: "flex"
768
+ },
769
+ T(
770
+ "div",
771
+ {
772
+ class: ["fm-status-badge", Le(_)]
773
+ },
774
+ Ue(_)
775
+ )
776
+ );
777
+ }
778
+ },
779
+ {
780
+ id: "action",
781
+ cell(o) {
782
+ const a = o.row.original, _ = [
783
+ tt[Re.Details],
784
+ tt[Re.Export]
785
+ ], O = [
786
+ {
787
+ translationKey: "inventory.closing.draft.approveDraft",
788
+ color: "text-fm-color-typo-primary",
789
+ value: z.enum.approveDraft
790
+ },
791
+ {
792
+ translationKey: "inventory.closing.draft.rejectDraft",
793
+ color: "text-fm-color-typo-error",
794
+ value: z.enum.rejectDraft
795
+ },
796
+ {
797
+ translationKey: "inventory.closing.draft.markAsFailed",
798
+ color: "text-fm-color-typo-error",
799
+ value: z.enum.markAsFailed
800
+ }
801
+ ];
802
+ return Ft(
803
+ [
804
+ ..._,
805
+ ...a.status === pe.enum.DRAFT ? O : []
806
+ ],
807
+ (f) => P(f, a)
808
+ );
809
+ },
810
+ enableSorting: !1,
811
+ size: 40,
812
+ meta: {
813
+ cellClass: "",
814
+ headerClass: ""
815
+ }
816
+ }
817
+ ],
818
+ drafts: m,
819
+ loading: p,
820
+ fetchDrafts: R,
821
+ loadDraft: S,
822
+ updateDraftRef: k
823
+ };
824
+ }
825
+ ), ra = { class: "w-full flex flex-col gap-32" }, la = { class: "flex justify-between" }, ca = { class: "flex" }, ia = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, ua = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, da = { class: "flex gap-1" }, ma = { class: "fm-typo-en-body-lg-600" }, fa = { class: "flex flex-col gap-16" }, pa = { class: "flex items-center" }, va = {
826
+ key: 0,
827
+ class: "flex gap-8"
828
+ }, ya = {
829
+ key: 0,
830
+ class: "w-full flex flex-col items-center"
831
+ }, ga = { class: "flex items-center gap-8" }, ba = { class: "flex flex-col gap-8" }, ka = { class: "flex gap-8" }, ha = {
832
+ key: 0,
833
+ class: "flex gap-8"
834
+ }, Aa = { class: "overflow-x-auto" }, xa = {
835
+ key: 1,
836
+ class: "flex-1 xs:w-screen xs:max-w-full"
837
+ }, _a = {
838
+ key: 0,
839
+ class: "flex flex-col items-center gap-8 h-full"
840
+ }, Da = ["src"], wa = {
841
+ key: 1,
842
+ class: "px-4 flex flex-col"
843
+ }, Sa = { class: "flex gap-12 content-stretch" }, ja = {
844
+ class: "flex flex-col w-24",
845
+ name: "circles"
846
+ }, Ca = { class: "flex-1 flex flex-col items-center" }, Ba = { class: "flex-1 flex flex-col items-center" }, Fa = {
847
+ class: "py-12 flex flex-col gap-4",
848
+ name: "received-at header"
849
+ }, Ta = { class: "fm-typo-en-body-lg-400" }, $a = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Ma = { class: "flex gap-12 content-stretch" }, Ra = {
850
+ class: "flex flex-col w-24",
851
+ name: "circles"
852
+ }, Ia = { class: "flex-1 flex flex-col items-center" }, Pa = {
853
+ class: "py-12 flex flex-col gap-4 flex-1",
854
+ name: "delivery details"
855
+ }, Va = { class: "flex flex-col gap-8" }, Ua = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, La = { class: "flex flex-col gap-4" }, Ea = { class: "flex gap-8" }, Ha = "N/A", za = /* @__PURE__ */ He({
856
+ __name: "ClosingDraftDialog",
857
+ props: {
858
+ show: { type: Boolean },
859
+ draft: {}
860
+ },
861
+ emits: ["submitted", "refresh"],
862
+ setup(n, { emit: r }) {
863
+ const e = n, m = dt(), p = Ee(), w = Et(e, "show"), v = H(!1), R = H(!1), S = H(!1), k = H(new Array()), $ = H(new Array()), P = H([]), I = We(), o = Ne(), a = Ge(), _ = $t(), O = ze(), f = kt({}), y = V(() => new Set(
864
+ _.skus.filter((l) => {
865
+ var t;
866
+ return f[(t = l.customAttributes) == null ? void 0 : t.tag];
867
+ }).map((l) => l._id)
868
+ )), h = r, D = H({
869
+ templateItem: !0,
870
+ nonTemplateItem: !0
871
+ }), M = V(() => {
872
+ var t, d;
873
+ const l = [...((t = e.draft) == null ? void 0 : t.items) ?? [], ...((d = e.draft) == null ? void 0 : d.negativeStockItems) ?? []];
874
+ return y.value.size ? l.filter((u) => y.value.has(u.sku._id)) : l;
875
+ }), Z = V(() => {
876
+ const l = M.value.map((t) => t.sku);
877
+ return l.sort((t, d) => t.code.localeCompare(d.code)), l;
878
+ }), W = V(() => M.value.groupBy(
879
+ (t) => t.sku._id,
880
+ (t) => t.measurementsAmounts.filter((d) => !d.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((d) => d.measurement.id)
881
+ ));
882
+ Ye(te), ht(
883
+ () => e.show,
884
+ (l) => {
885
+ l && (le.value = xe[0], te(), D.value = {
886
+ templateItem: !0,
887
+ nonTemplateItem: !0
888
+ });
889
+ }
890
+ );
891
+ const re = Be(0), B = Be(100);
892
+ async function te() {
893
+ var t, d, u, c;
894
+ if (!O._currentLocation) return;
895
+ v.value = !0;
896
+ const l = ((t = e.draft) == null ? void 0 : t.status) === pe.enum.COMPLETED;
897
+ $.value = [];
898
+ try {
899
+ if (await _.init(), l) {
900
+ const E = e.draft.closingAdjustmentId;
901
+ if (!E) {
902
+ a.open({
903
+ title: "Something went wrong",
904
+ message: "Closing draft is completed but closing document cannot be found.",
905
+ type: "error"
906
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
907
+ draftId: (d = e.draft) == null ? void 0 : d._id
908
+ });
909
+ return;
910
+ }
911
+ const ae = await I.readAdjustmentById(E), ce = (ae == null ? void 0 : ae.skus) ?? [];
912
+ for (const ne of ce) {
913
+ const je = {
914
+ id: ne.sku._id,
915
+ balance: ne.fromBalance,
916
+ costs: ne.fromCostBalances
917
+ }, j = {
918
+ id: ne.sku._id,
919
+ balance: ne.toBalance,
920
+ costs: ne.toCostBalances
921
+ };
922
+ k.value.push(je), $.value.push(j);
923
+ }
924
+ } else
925
+ k.value = ((u = e.draft) == null ? void 0 : u.stockSnapshot) ?? [];
926
+ const i = /* @__PURE__ */ new Set();
927
+ if ((c = e.draft) != null && c.adjustmentSnapshot)
928
+ for (const E of e.draft.adjustmentSnapshot)
929
+ E.adjustmentsByType && Object.keys(E.adjustmentsByType).forEach((ae) => i.add(ae));
930
+ const g = ["receive", "sales", "wastage"], A = [];
931
+ g.forEach((E) => {
932
+ i.has(E) && (A.push(E), i.delete(E));
933
+ });
934
+ const b = Array.from(i).sort();
935
+ P.value = [...A, ...b];
936
+ } catch (i) {
937
+ a.open({
938
+ title: "Something went wrong",
939
+ message: "Something went wrong when fetching info. Please try again.",
940
+ type: "error"
941
+ }), console.error("error on fetch stock balances", i);
942
+ } finally {
943
+ v.value = !1;
944
+ }
945
+ }
946
+ async function be() {
947
+ var t, d;
948
+ if (!(((t = e.draft) == null ? void 0 : t.effectiveAt) ?? (e.draft ? Ke((d = e.draft) == null ? void 0 : d._id) : null))) {
949
+ a.open({
950
+ title: "Cannot refresh",
951
+ message: "Effective date is not available for this draft.",
952
+ type: "error"
953
+ });
954
+ return;
955
+ }
956
+ await p.refreshBalance(
957
+ e.draft,
958
+ () => {
959
+ },
960
+ async (u) => {
961
+ var A;
962
+ R.value = !0;
963
+ const c = (A = e.draft) == null ? void 0 : A._rev, i = 30, g = 2e3;
964
+ try {
965
+ await I.recalculation.scheduleCalculateStockSnapshotAtDate(u, e.draft._id);
966
+ let b = null;
967
+ for (let E = 0; E < i && (b = await o.getDraft(e.draft._id).delayed(g), b._rev === c); E++)
968
+ ;
969
+ if (!b || b._rev === c) {
970
+ a.open({
971
+ title: "Refresh failed",
972
+ message: "Failed to refresh stock balance. Please try again.",
973
+ type: "error"
974
+ }), console.error("error refreshing stock balances: there is no change in _rev");
975
+ return;
976
+ }
977
+ h("refresh", b), k.value = b.stockSnapshot ?? [], a.open({
978
+ title: "Balance refreshed",
979
+ message: "Stock balance has been recalculated.",
980
+ type: "success"
981
+ });
982
+ } catch (b) {
983
+ a.open({
984
+ title: "Refresh failed",
985
+ message: "Failed to refresh stock balance. Please try again.",
986
+ type: "error"
987
+ }), console.error("error refreshing stock balances", b);
988
+ } finally {
989
+ R.value = !1;
990
+ }
991
+ }
992
+ );
993
+ }
994
+ const ke = V(
995
+ () => k.value.groupBy(
996
+ (l) => l.id,
997
+ (l) => l.balance
998
+ )
999
+ ), fe = V(() => M.value.groupBy((l) => l.sku._id)), ye = V(() => {
1000
+ var l;
1001
+ return (l = e.draft) != null && l.adjustmentSnapshot ? new Map(e.draft.adjustmentSnapshot.map((t) => [t.skuId, t.adjustmentsByType])) : /* @__PURE__ */ new Map();
1002
+ }), ge = V(() => {
1003
+ var l;
1004
+ return (l = e.draft) != null && l.opening ? new Map(e.draft.opening.map((t) => [t.skuId, t.balance])) : /* @__PURE__ */ new Map();
1005
+ });
1006
+ function Y(l, t) {
1007
+ return T(
1008
+ Ve.FmTooltip,
1009
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
1010
+ {
1011
+ default() {
1012
+ return l;
1013
+ },
1014
+ content() {
1015
+ return t || l;
1016
+ }
1017
+ }
1018
+ );
1019
+ }
1020
+ const we = V(() => {
1021
+ const l = Z.value.reduce((d, u) => {
1022
+ var c, i;
1023
+ return Math.max(d, ((i = (c = W.value) == null ? void 0 : c.get(u._id)) == null ? void 0 : i[0].length) ?? 0);
1024
+ }, 0);
1025
+ return [
1026
+ {
1027
+ id: "sku",
1028
+ accessorFn: (d) => `${d.code} ${d.name}`,
1029
+ header: () => "Name",
1030
+ size: 350,
1031
+ cell(d) {
1032
+ const u = d.row.original, c = u.adjustedDiffPercentage, i = typeof c == "number" && Math.abs(c) > 10, g = T("div", { class: "flex flex-col gap-4" }, [
1033
+ T(
1034
+ "div",
1035
+ {
1036
+ class: [
1037
+ "line-clamp-1 fm-typo-en-body-lg-400",
1038
+ i ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
1039
+ ]
1040
+ },
1041
+ u.name
1042
+ ),
1043
+ T(
1044
+ "div",
1045
+ {
1046
+ class: [
1047
+ "line-clamp-1 fm-typo-en-body-md-400",
1048
+ i ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
1049
+ ]
1050
+ },
1051
+ u.code
1052
+ )
1053
+ ]);
1054
+ return T(
1055
+ Ve.FmTooltip,
1056
+ {
1057
+ zIndex: 51
1058
+ },
1059
+ {
1060
+ content() {
1061
+ return i ? "Adjustment difference is more than 10%." : `${u.code} - ${u.name}`;
1062
+ },
1063
+ default() {
1064
+ return T("div", { class: "flex items-center gap-4 justify-start w-full" }, [
1065
+ g
1066
+ ]);
1067
+ }
1068
+ }
1069
+ );
1070
+ }
1071
+ },
1072
+ {
1073
+ id: "costPerUnit",
1074
+ accessorKey: "costPerUnit",
1075
+ header: () => Y("Cost per unit"),
1076
+ size: 160,
1077
+ cell(d) {
1078
+ const u = d.row.original.costPerUnit;
1079
+ return T("div", { class: "text-right" }, u.toFixed(2));
1080
+ },
1081
+ meta: {
1082
+ textAlign: "right"
1083
+ }
1084
+ },
1085
+ {
1086
+ id: "baseUnit",
1087
+ header: () => "UOM",
1088
+ size: 80,
1089
+ accessorKey: "baseUnit"
1090
+ },
1091
+ {
1092
+ id: "opening",
1093
+ accessorKey: "opening",
1094
+ header: () => Y("Opening (B/F)", "The opening balance brought forward from previous period."),
1095
+ size: 150,
1096
+ cell(d) {
1097
+ const u = d.row.original.opening;
1098
+ return T("div", { class: "text-right" }, u.toFixed(2));
1099
+ },
1100
+ meta: {
1101
+ textAlign: "right"
1102
+ }
1103
+ },
1104
+ // Dynamic adjustment type columns
1105
+ ...P.value.map((d) => ({
1106
+ id: `adjustment_${d}`,
1107
+ accessorFn: (u) => u.adjustmentAmounts[d] ?? { amount: 0, precision: 0 },
1108
+ header: () => Y(Ue(d)),
1109
+ size: 150,
1110
+ cell(u) {
1111
+ const c = u.row.original.adjustmentAmounts[d] ?? { amount: 0, precision: 0 };
1112
+ return T("div", { class: "text-right" }, N(c));
1113
+ },
1114
+ meta: {
1115
+ textAlign: "right"
1116
+ }
1117
+ })),
1118
+ {
1119
+ id: "systemBalance",
1120
+ accessorKey: "systemBalance",
1121
+ header: () => Y("System Balance", "The system calculated balance before stock take."),
1122
+ size: 200,
1123
+ meta: {
1124
+ textAlign: "right"
1125
+ }
1126
+ },
1127
+ {
1128
+ id: "physicalBalance",
1129
+ accessorFn: (d) => {
1130
+ var c;
1131
+ const u = (c = $.value.find((i) => i.id === d.id)) == null ? void 0 : c.balance;
1132
+ return u ? Ie.toFormatString({ value: u }) : d.physicalBalance;
1133
+ },
1134
+ header: () => Y("Stock Take balance", "The physical balance recorded during stock take."),
1135
+ cell(d) {
1136
+ var b;
1137
+ const u = d.row.original, c = Ie.fromNumber(u.physicalBalance);
1138
+ let i = !0, g = u.physicalBalance;
1139
+ const A = (b = $.value.find((E) => E.id === u.id)) == null ? void 0 : b.balance;
1140
+ return A && (Ie.equals({
1141
+ a: c,
1142
+ b: A
1143
+ }) || (i = !1, g = Number(Ie.toFormatString({ value: A })))), T("div", { class: "flex flex-col" }, [
1144
+ T(
1145
+ "span",
1146
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1147
+ g
1148
+ ),
1149
+ i ? null : T(
1150
+ "span",
1151
+ { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
1152
+ `Draft: ${u.physicalBalance.toString()}`
1153
+ )
1154
+ ]);
1155
+ },
1156
+ size: 200,
1157
+ meta: {
1158
+ textAlign: "right"
1159
+ }
1160
+ },
1161
+ {
1162
+ id: "adjustedAmount",
1163
+ accessorKey: "adjustedAmount",
1164
+ header: () => Y("Variance", "The difference between Stock Take balance and System Balance."),
1165
+ size: 200,
1166
+ meta: {
1167
+ textAlign: "right"
1168
+ }
1169
+ },
1170
+ {
1171
+ id: "varianceRM",
1172
+ accessorKey: "varianceRM",
1173
+ header: () => Y("Variance (RM)"),
1174
+ size: 150,
1175
+ cell(d) {
1176
+ const u = d.row.original.varianceRM;
1177
+ return T("div", { class: "text-right" }, u.toFixed(2));
1178
+ },
1179
+ meta: {
1180
+ textAlign: "right"
1181
+ }
1182
+ },
1183
+ {
1184
+ id: "adjustedDiffPercentage",
1185
+ accessorKey: "adjustedDiffPercentage",
1186
+ header: () => Y("Variance (%)", "Difference between Stock Take balance and System Balance in percentage."),
1187
+ size: 200,
1188
+ cell(d) {
1189
+ const u = d.row.original.adjustedDiffPercentage;
1190
+ if (!u) return Ha;
1191
+ const c = u.toFixed(2);
1192
+ if (c === "0.00")
1193
+ return T("div", { class: "flex items-center gap-4 justify-end" }, ["0.00"]);
1194
+ const i = u > 0;
1195
+ return T("div", { class: "flex items-center gap-4 justify-end" }, [
1196
+ T(Ve.FmIcon, {
1197
+ name: i ? "arrow_drop_up" : "arrow_drop_down",
1198
+ color: i ? "system-success-300" : "system-error-300",
1199
+ size: "md"
1200
+ }),
1201
+ c
1202
+ ]);
1203
+ },
1204
+ meta: {
1205
+ textAlign: "right"
1206
+ }
1207
+ },
1208
+ {
1209
+ id: "stockTakeValue",
1210
+ accessorKey: "stockTakeValue",
1211
+ header: () => Y("Stock take value (RM)"),
1212
+ size: 180,
1213
+ cell(d) {
1214
+ const u = d.row.original.stockTakeValue;
1215
+ return T("div", { class: "text-right" }, u.toFixed(2));
1216
+ },
1217
+ meta: {
1218
+ textAlign: "right"
1219
+ }
1220
+ },
1221
+ {
1222
+ id: "systemValue",
1223
+ accessorKey: "systemValue",
1224
+ header: () => Y("System value (RM)"),
1225
+ size: 180,
1226
+ cell(d) {
1227
+ const u = d.row.original.systemValue;
1228
+ return T("div", { class: "text-right" }, u.toFixed(2));
1229
+ },
1230
+ meta: {
1231
+ textAlign: "right"
1232
+ }
1233
+ },
1234
+ {
1235
+ id: "physicalBalances",
1236
+ header: () => "Amounts",
1237
+ enableSorting: !1,
1238
+ cell(d) {
1239
+ const u = d.row.original, c = (g, A) => T(
1240
+ Ve.FmTooltip,
1241
+ { zIndex: 50 },
1242
+ {
1243
+ default() {
1244
+ return T(
1245
+ "div",
1246
+ {
1247
+ class: "fm-typo-en-body-md-400 py-4 px-8 border-1 border-fm-color-typo-secondary fm-corner-radius-md line-clamp-1"
1248
+ },
1249
+ [
1250
+ T("span", { class: "text-fm-color-typo-primary" }, `${g} `),
1251
+ T(
1252
+ "span",
1253
+ {
1254
+ class: "text-fm-color-typo-secondary",
1255
+ style: { maxWidth: "80px" }
1256
+ },
1257
+ A
1258
+ )
1259
+ ]
1260
+ );
1261
+ },
1262
+ content() {
1263
+ return `${g} ${A}`;
1264
+ }
1265
+ }
1266
+ );
1267
+ let i = Array.from({ length: l }).map((g, A) => {
1268
+ if (!u[`measurementAmount${A}`])
1269
+ return null;
1270
+ const b = u[`measurementAmount${A}`], E = u[`measurementAbbrev${A}`];
1271
+ return c(b, E);
1272
+ }).filter((g) => g);
1273
+ return (u.baseUnitAmount || !i.length) && (i = [c(u.baseUnitAmount, u.baseUnit), ...i]), T(
1274
+ "div",
1275
+ {
1276
+ class: "flex gap-8 flex-nowrap",
1277
+ style: {
1278
+ minWidth: `${120 * i.length}px`
1279
+ }
1280
+ },
1281
+ i
1282
+ );
1283
+ }
1284
+ }
1285
+ ];
1286
+ }), he = V(() => we.value.map((l) => l.size ?? 0).reduce((l, t) => l + t)), Ae = H(""), Se = V(() => {
1287
+ var d, u;
1288
+ const l = ((u = (d = e.draft) == null ? void 0 : d.negativeStockItems) == null ? void 0 : u.reduce(
1289
+ (c, i) => (c[i.sku._id] = i, c),
1290
+ {}
1291
+ )) ?? {};
1292
+ return Z.value.map((c) => {
1293
+ var qe, Ze, Je, Xe, et;
1294
+ const i = (qe = fe.value.get(c._id)) == null ? void 0 : qe[0], g = ((Ze = ke.value.get(c._id)) == null ? void 0 : Ze[0]) ?? re, A = (Je = c.defaultCost) != null && Je.costPerUnit ? c.defaultCost.costPerUnit.amount / Math.pow(10, c.defaultCost.costPerUnit.precision) : 0, b = ge.value.get(c._id), E = b ? +N(b) : 0, ae = ye.value.get(c._id), ce = {};
1295
+ if (P.value.forEach((Q) => {
1296
+ const oe = ce[Q] ?? { amount: 0, precision: 0 }, ue = ae == null ? void 0 : ae[Q];
1297
+ ue && (ce[Q] = Mt(oe, ue));
1298
+ }), !i) {
1299
+ const Q = +N(g), oe = Q - 0, ue = oe * A, Me = 0, bt = Q * A;
1300
+ return {
1301
+ id: c._id,
1302
+ code: c.code,
1303
+ name: c.name,
1304
+ baseUnit: c.unit.abbrev,
1305
+ baseUnitAmount: 0,
1306
+ systemBalance: Q,
1307
+ physicalBalance: 0,
1308
+ adjustedAmount: -Q,
1309
+ adjustedDiffPercentage: -100,
1310
+ isTemplateItem: !l[c._id],
1311
+ costPerUnit: A,
1312
+ opening: E,
1313
+ varianceQty: oe,
1314
+ varianceRM: ue,
1315
+ stockTakeValue: Me,
1316
+ systemValue: bt,
1317
+ adjustmentAmounts: ce
1318
+ };
1319
+ }
1320
+ const ne = mt(i), je = (et = (Xe = $.value) == null ? void 0 : Xe.find(
1321
+ (Q) => Q.id === c._id
1322
+ )) == null ? void 0 : et.balance, j = rt(
1323
+ je ?? ne,
1324
+ g
1325
+ ), K = g.amount === 0 ? null : lt(j, {
1326
+ ...g,
1327
+ amount: Math.abs(g.amount)
1328
+ }), q = K ? Qe(K, B) : null, ie = +N(g), _e = +N(ne), $e = ie - _e, vt = $e * A, yt = _e * A, gt = ie * A;
1329
+ return {
1330
+ id: c._id,
1331
+ code: c.code,
1332
+ name: c.name,
1333
+ baseUnit: c.unit.abbrev,
1334
+ baseUnitAmount: +N(i.baseAmount),
1335
+ ...i.measurementsAmounts.filter((Q) => {
1336
+ var oe, ue, Me;
1337
+ return (Me = (ue = (oe = W.value) == null ? void 0 : oe.get(c._id)) == null ? void 0 : ue[0]) == null ? void 0 : Me.includes(Q.measurement.id);
1338
+ }).reduce((Q, oe, ue) => (Q[`measurementAbbrev${ue}`] = `(${oe.measurement.abbrev}) × ${N(oe.measurement.conversion)}`, Q[`measurementAmount${ue}`] = +N(oe.amount), Q), {}),
1339
+ systemBalance: ie,
1340
+ physicalBalance: _e,
1341
+ adjustedAmount: +N(j),
1342
+ adjustedDiffPercentage: q ? +N(ct(q, 2)) : null,
1343
+ isTemplateItem: !l[c._id],
1344
+ costPerUnit: A,
1345
+ opening: E,
1346
+ varianceQty: $e,
1347
+ varianceRM: vt,
1348
+ stockTakeValue: yt,
1349
+ systemValue: gt,
1350
+ adjustmentAmounts: ce
1351
+ };
1352
+ }).filter((c) => !!(c.isTemplateItem && D.value.templateItem || !c.isTemplateItem && D.value.nonTemplateItem));
1353
+ }), Fe = V(() => {
1354
+ var t, d, u, c;
1355
+ if (!e.draft) return [];
1356
+ const l = e.draft.approvedAt ? {
1357
+ action: `Approve at ${ve(e.draft.approvedAt)}`,
1358
+ // actionAt: props.draft.approvedAt,
1359
+ actionBy: e.draft.approvedBy,
1360
+ remark: e.draft.approveRemark
1361
+ } : (t = e.draft.rejectionHistory) == null ? void 0 : t.computeFirst((i) => ({
1362
+ action: `Reject at ${ve(i.rejectedAt)}`,
1363
+ // actionAt: e.rejectedAt,
1364
+ actionBy: i.rejectedBy,
1365
+ remark: i.rejectRemark
1366
+ }));
1367
+ return [
1368
+ {
1369
+ label: "Created at",
1370
+ value: ve(e.draft.createdAt)
1371
+ },
1372
+ {
1373
+ label: "Created by",
1374
+ value: e.draft.createdBy.name
1375
+ },
1376
+ {
1377
+ label: "Updated at",
1378
+ value: ve(e.draft.updatedAt)
1379
+ },
1380
+ {
1381
+ label: "Updated by",
1382
+ value: e.draft.updatedBy.name
1383
+ },
1384
+ {
1385
+ label: "Effective at",
1386
+ value: ve(e.draft.effectiveAt ?? Ke((d = e.draft) == null ? void 0 : d._id))
1387
+ },
1388
+ {
1389
+ label: "Using template",
1390
+ value: ((u = e.draft.usingTemplates.find((i) => i)) == null ? void 0 : u.name) ?? "None"
1391
+ },
1392
+ e.draft.remark ? {
1393
+ label: "Remark",
1394
+ value: e.draft.remark
1395
+ } : null,
1396
+ l ? {
1397
+ label: "Last action",
1398
+ value: l.action
1399
+ } : null,
1400
+ l && l.actionBy ? {
1401
+ label: "Last action by",
1402
+ value: (c = l.actionBy) == null ? void 0 : c.name
1403
+ } : null,
1404
+ l && l.remark ? {
1405
+ label: "Action remark",
1406
+ value: l.remark
1407
+ } : null
1408
+ ].filter((i) => i).map((i) => i);
1409
+ }), xe = [
1410
+ {
1411
+ label: "Overview",
1412
+ value: "overview"
1413
+ },
1414
+ {
1415
+ label: "Action history",
1416
+ value: "history"
1417
+ }
1418
+ ], le = H(xe[0]), me = V(() => {
1419
+ var u, c, i;
1420
+ const l = ((u = e.draft) == null ? void 0 : u.activityLogs) ?? [], t = ((c = e.draft) == null ? void 0 : c.rejectionHistory) ?? [];
1421
+ for (const g of t)
1422
+ l.find(
1423
+ (b) => `${b.action}_${b.performedAt}` == `${z.enum.rejectDraft}_${g.rejectedAt}`
1424
+ ) || l.push({
1425
+ action: z.enum.rejectDraft,
1426
+ performedAt: g.rejectedAt,
1427
+ performedBy: g.rejectedBy,
1428
+ remark: g.rejectRemark
1429
+ });
1430
+ return (i = e.draft) != null && i.approvedAt && (l.find(
1431
+ (A) => {
1432
+ var b;
1433
+ return `${A.action}_${A.performedAt}` == `${z.enum.approveDraft}_${(b = e.draft) == null ? void 0 : b.approvedAt}`;
1434
+ }
1435
+ ) || l.push({
1436
+ action: z.enum.approveDraft,
1437
+ performedAt: e.draft.approvedAt,
1438
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
1439
+ remark: e.draft.approveRemark
1440
+ })), l.sort((g, A) => new Date(A.performedAt).getTime() - new Date(g.performedAt).getTime()).map(
1441
+ (g) => ({
1442
+ header: Ue(g.action),
1443
+ date: ve(g.performedAt),
1444
+ info: [
1445
+ {
1446
+ label: "Performed by",
1447
+ values: [g.performedBy.name]
1448
+ },
1449
+ {
1450
+ label: "Remark",
1451
+ values: [g.remark ?? ""]
1452
+ }
1453
+ ]
1454
+ })
1455
+ );
1456
+ }), Te = V(() => {
1457
+ var c, i, g, A;
1458
+ if ((c = e == null ? void 0 : e.draft) != null && c.approvedAt) return "Draft is already approved.";
1459
+ if (((i = e.draft) == null ? void 0 : i.status) !== pe.enum.DRAFT) return "Status is not draft.";
1460
+ const l = Se.value.some((b) => b.physicalBalance < 0), t = ((A = (g = m.stockBalance.skus) == null ? void 0 : g.filter((b) => b.balance.amount < 0)) == null ? void 0 : A.map((b) => b.id)) ?? [], d = new Set(Z.value.map((b) => b._id)), u = t.filter((b) => !d.has(b)).length;
1461
+ return [
1462
+ l ? "Negative total exist." : null,
1463
+ u ? "Negative stock is not included in this draft. Reopen draft in POS and apply changes." : null
1464
+ ].filter((b) => b).join(" ");
1465
+ });
1466
+ return (l, t) => {
1467
+ const d = U("FmButtonGroup"), u = U("FmMenuDivider"), c = U("FmCard"), i = U("FmButton"), g = U("FmCircularProgress"), A = U("FmChip"), b = U("FmTextField"), E = U("FmIcon"), ae = U("FmTable"), ce = U("FmSpacer"), ne = U("FmTooltip"), je = U("FmSideSheet");
1468
+ return C(), se(je, {
1469
+ "dismiss-away": "",
1470
+ "max-width": 9999,
1471
+ "model-value": F(w),
1472
+ "onUpdate:modelValue": t[10] || (t[10] = (j) => at(w) ? w.value = j : null),
1473
+ header: "Closing details"
1474
+ }, {
1475
+ "side-sheet-footer": G(() => {
1476
+ var j, K, q, ie;
1477
+ return [
1478
+ s("div", Ea, [
1479
+ ((j = e.draft) == null ? void 0 : j.status) === F(pe).enum.DRAFT ? (C(), L(ee, { key: 0 }, [
1480
+ Te.value ? (C(), se(ne, {
1481
+ key: 0,
1482
+ "z-index": 51
1483
+ }, {
1484
+ content: G(() => [
1485
+ X(J(Te.value), 1)
1486
+ ]),
1487
+ default: G(() => [
1488
+ x(i, {
1489
+ disabled: "",
1490
+ key: "approve key",
1491
+ label: "Approve",
1492
+ onClick: t[5] || (t[5] = () => e.draft && F(p).approveDraft(e.draft, () => h("submitted")))
1493
+ })
1494
+ ]),
1495
+ _: 1
1496
+ })) : (C(), se(i, {
1497
+ key: "approve key",
1498
+ label: "Approve",
1499
+ onClick: t[6] || (t[6] = () => e.draft && F(p).approveDraft(e.draft, () => h("submitted")))
1500
+ }))
1501
+ ], 64)) : de("", !0),
1502
+ ((K = e.draft) == null ? void 0 : K.status) === F(pe).enum.DRAFT ? (C(), se(i, {
1503
+ key: 1,
1504
+ label: "Reject",
1505
+ variant: "destructive",
1506
+ onClick: t[7] || (t[7] = () => e.draft && F(p).rejectDraft(e.draft, () => h("submitted")))
1507
+ })) : de("", !0),
1508
+ (q = e.draft) != null && q.approvedAt && ((ie = e.draft) == null ? void 0 : ie.status) !== F(pe).enum.COMPLETED ? (C(), se(i, {
1509
+ key: 2,
1510
+ label: "Sync",
1511
+ loading: S.value,
1512
+ onClick: t[8] || (t[8] = () => {
1513
+ e.draft && (S.value = !0, F(p).syncDraft(e.draft, () => {
1514
+ S.value = !1, h("submitted");
1515
+ }));
1516
+ })
1517
+ }, null, 8, ["loading"])) : de("", !0),
1518
+ x(i, {
1519
+ label: "Close",
1520
+ variant: "tertiary",
1521
+ onClick: t[9] || (t[9] = (_e) => w.value = !1)
1522
+ })
1523
+ ])
1524
+ ];
1525
+ }),
1526
+ default: G(() => [
1527
+ s("div", ra, [
1528
+ s("div", null, [
1529
+ x(d, {
1530
+ items: xe,
1531
+ modelValue: le.value,
1532
+ "onUpdate:modelValue": t[0] || (t[0] = (j) => le.value = j)
1533
+ }, null, 8, ["modelValue"])
1534
+ ]),
1535
+ le.value.value === "overview" ? (C(), L(ee, { key: 0 }, [
1536
+ x(c, {
1537
+ variant: "outlined",
1538
+ class: "flex flex-col gap-8 px-12 py-16"
1539
+ }, {
1540
+ default: G(() => {
1541
+ var j, K;
1542
+ return [
1543
+ s("div", la, [
1544
+ t[11] || (t[11] = s("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
1545
+ s("div", ca, [
1546
+ s("div", {
1547
+ class: De(["fm-status-badge", F(Le)(((j = l.draft) == null ? void 0 : j.status) ?? "DRAFT")])
1548
+ }, J(F(Ue)(((K = l.draft) == null ? void 0 : K.status) ?? "")), 3)
1549
+ ])
1550
+ ]),
1551
+ x(u),
1552
+ s("div", ia, [
1553
+ (C(!0), L(ee, null, Ce(Fe.value, (q, ie) => (C(), L("div", {
1554
+ class: "flex flex-col gap-4",
1555
+ key: ie
1556
+ }, [
1557
+ s("div", ua, [
1558
+ s("div", da, J(q.label), 1)
1559
+ ]),
1560
+ s("div", ma, J(q.value), 1)
1561
+ ]))), 128))
1562
+ ])
1563
+ ];
1564
+ }),
1565
+ _: 1
1566
+ }),
1567
+ s("div", fa, [
1568
+ s("div", pa, [
1569
+ t[12] || (t[12] = s("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
1570
+ v.value ? de("", !0) : (C(), L("div", va, [
1571
+ l.draft && l.draft.status !== F(pe).enum.COMPLETED ? (C(), se(i, {
1572
+ key: 0,
1573
+ label: "Refresh balance",
1574
+ "prepend-icon": "refresh",
1575
+ variant: "secondary",
1576
+ "text-color": "primary",
1577
+ "bg-color": "transparent",
1578
+ "border-color": "primary",
1579
+ loading: R.value,
1580
+ onClick: be
1581
+ }, null, 8, ["loading"])) : de("", !0),
1582
+ x(i, {
1583
+ label: "Export data",
1584
+ "prepend-icon": "download",
1585
+ variant: "secondary",
1586
+ "text-color": "primary",
1587
+ "bg-color": "transparent",
1588
+ "border-color": "primary",
1589
+ onClick: t[1] || (t[1] = (j) => l.draft ? F(p).exportDraft(
1590
+ l.draft,
1591
+ k.value,
1592
+ $.value
1593
+ ) : null)
1594
+ })
1595
+ ]))
1596
+ ]),
1597
+ v.value ? (C(), L("div", ya, [
1598
+ t[14] || (t[14] = s("div", { class: "h-80" }, null, -1)),
1599
+ s("div", ga, [
1600
+ s("div", null, [
1601
+ x(g, { size: "md" })
1602
+ ]),
1603
+ t[13] || (t[13] = s("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
1604
+ ]),
1605
+ t[15] || (t[15] = s("div", { class: "h-80" }, null, -1))
1606
+ ])) : (C(), L(ee, { key: 1 }, [
1607
+ s("div", ba, [
1608
+ s("div", ka, [
1609
+ x(A, {
1610
+ label: "Template Item(s)",
1611
+ selected: D.value.templateItem,
1612
+ onClick: t[2] || (t[2] = (j) => D.value.templateItem = !D.value.templateItem)
1613
+ }, null, 8, ["selected"]),
1614
+ x(A, {
1615
+ label: "Non-template Item(s)",
1616
+ selected: D.value.nonTemplateItem,
1617
+ onClick: t[3] || (t[3] = (j) => D.value.nonTemplateItem = !D.value.nonTemplateItem)
1618
+ }, null, 8, ["selected"])
1619
+ ]),
1620
+ x(b, {
1621
+ modelValue: Ae.value,
1622
+ "onUpdate:modelValue": t[4] || (t[4] = (j) => Ae.value = j),
1623
+ placeholder: "Filter items"
1624
+ }, null, 8, ["modelValue"])
1625
+ ]),
1626
+ F(_).skuTags.size ? (C(), L("div", ha, [
1627
+ (C(!0), L(ee, null, Ce(F(_).skuTags.keys(), (j) => (C(), se(A, {
1628
+ key: `${j}`,
1629
+ label: `${j}`,
1630
+ selectable: "",
1631
+ selected: f[`${j}`],
1632
+ onClick: (K) => f[`${j}`] = !f[`${j}`]
1633
+ }, {
1634
+ default: G(() => [
1635
+ f[`${j}`] ? (C(), se(E, {
1636
+ key: 0,
1637
+ name: "check",
1638
+ class: "text-white",
1639
+ size: "sm"
1640
+ })) : de("", !0),
1641
+ s("span", {
1642
+ class: De([
1643
+ "",
1644
+ {
1645
+ "text-white fm-typo-en-body-md-600": f[`${j}`],
1646
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !f[`${j}`]
1647
+ }
1648
+ ])
1649
+ }, J(j), 3)
1650
+ ]),
1651
+ _: 2
1652
+ }, 1032, ["label", "selected", "onClick"]))), 128))
1653
+ ])) : de("", !0),
1654
+ s("div", Aa, [
1655
+ s("div", {
1656
+ style: nt({ minWidth: `${he.value}px` })
1657
+ }, [
1658
+ x(ae, {
1659
+ "column-defs": we.value,
1660
+ "row-data": Se.value,
1661
+ "search-value": Ae.value
1662
+ }, null, 8, ["column-defs", "row-data", "search-value"])
1663
+ ], 4)
1664
+ ])
1665
+ ], 64))
1666
+ ])
1667
+ ], 64)) : de("", !0),
1668
+ le.value.value === "history" ? (C(), L("div", xa, [
1669
+ me.value.length ? (C(), L("div", wa, [
1670
+ (C(!0), L(ee, null, Ce(me.value, (j, K) => (C(), L(ee, { key: K }, [
1671
+ s("div", Sa, [
1672
+ s("div", ja, [
1673
+ s("div", Ca, [
1674
+ s("div", {
1675
+ class: De([
1676
+ {
1677
+ "bg-fm-color-primary": K !== 0,
1678
+ "bg-white": K === 0
1679
+ },
1680
+ "w-[2px] h-full"
1681
+ ])
1682
+ }, null, 2)
1683
+ ]),
1684
+ t[18] || (t[18] = s("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
1685
+ s("div", Ba, [
1686
+ s("div", {
1687
+ class: De([
1688
+ {
1689
+ "bg-fm-color-primary": K < me.value.length - 1,
1690
+ "bg-white": K >= me.value.length - 1
1691
+ },
1692
+ "w-[2px] h-full"
1693
+ ])
1694
+ }, null, 2)
1695
+ ])
1696
+ ]),
1697
+ s("div", Fa, [
1698
+ s("div", Ta, J(j.header), 1),
1699
+ s("div", $a, J(j.date), 1)
1700
+ ])
1701
+ ]),
1702
+ s("div", Ma, [
1703
+ s("div", Ra, [
1704
+ s("div", Ia, [
1705
+ s("div", {
1706
+ class: De([
1707
+ {
1708
+ "bg-fm-color-primary": K < me.value.length - 1,
1709
+ "bg-white": K >= me.value.length - 1
1710
+ },
1711
+ "w-[2px] h-full"
1712
+ ])
1713
+ }, null, 2)
1714
+ ])
1715
+ ]),
1716
+ s("div", Pa, [
1717
+ x(c, {
1718
+ variant: "outlined",
1719
+ class: "py-12 px-16"
1720
+ }, {
1721
+ default: G(() => [
1722
+ s("div", Va, [
1723
+ (C(!0), L(ee, null, Ce(j.info, (q, ie) => (C(), L("div", {
1724
+ key: ie,
1725
+ class: "flex flex-col gap-4"
1726
+ }, [
1727
+ s("div", Ua, J(q == null ? void 0 : q.label), 1),
1728
+ s("div", La, [
1729
+ (C(!0), L(ee, null, Ce(q == null ? void 0 : q.values, (_e, $e) => (C(), L("div", {
1730
+ key: $e,
1731
+ class: "fm-typo-en-body-lg-600"
1732
+ }, J(_e), 1))), 128))
1733
+ ])
1734
+ ]))), 128))
1735
+ ])
1736
+ ]),
1737
+ _: 2
1738
+ }, 1024)
1739
+ ])
1740
+ ])
1741
+ ], 64))), 128))
1742
+ ])) : (C(), L("div", _a, [
1743
+ x(ce),
1744
+ s("div", null, [
1745
+ s("img", {
1746
+ src: F(Nt),
1747
+ alt: "List is empty"
1748
+ }, null, 8, Da)
1749
+ ]),
1750
+ t[16] || (t[16] = s("div", { class: "fm-typo-en-body-lg-600" }, J("No records found"), -1)),
1751
+ t[17] || (t[17] = s("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, J("You can track approval and rejection history here"), -1)),
1752
+ x(ce),
1753
+ x(ce)
1754
+ ]))
1755
+ ])) : de("", !0)
1756
+ ])
1757
+ ]),
1758
+ _: 1
1759
+ }, 8, ["model-value"]);
1760
+ };
1761
+ }
1762
+ }), Na = { class: "flex-1 flex flex-col gap-8" }, Oa = { class: "flex flex-col" }, Ka = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ya = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Qa = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Ga = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, on = /* @__PURE__ */ He({
1763
+ __name: "ClosingDraftView",
1764
+ setup(n) {
1765
+ const { t: r } = it(), { viewDraft: e } = Ee(), { viewClosingDraftProps: m, viewClosingDraftShow: p } = zt(Ee()), w = ze(), v = sa(), R = Rt(), { breakpoints: S } = Ht();
1766
+ w.watchLocation(v.fetchDrafts);
1767
+ const k = V(() => v.loading), $ = H(""), P = V(() => S.value.xs || S.value.sm), I = V(() => P.value ? 10 : 20);
1768
+ function o(O) {
1769
+ switch (O) {
1770
+ case "refresh":
1771
+ return v.fetchDrafts();
1772
+ }
1773
+ }
1774
+ function a(O) {
1775
+ return O;
1776
+ }
1777
+ const _ = V(() => P.value ? [
1778
+ {
1779
+ label: r("inventory.common.refresh"),
1780
+ value: "refresh",
1781
+ isPrimary: !1
1782
+ }
1783
+ ] : [
1784
+ {
1785
+ label: r("inventory.common.refresh"),
1786
+ value: "refresh",
1787
+ isPrimary: !1
1788
+ }
1789
+ ]);
1790
+ return (O, f) => {
1791
+ const y = U("FmTable");
1792
+ return C(), L(ee, null, [
1793
+ x(It, {
1794
+ title: F(r)("inventory.closing.draft.title"),
1795
+ actions: _.value,
1796
+ "onClick:action": o
1797
+ }, {
1798
+ default: G(() => [
1799
+ s("div", {
1800
+ class: De([
1801
+ "flex flex-col gap-8 max-h-full",
1802
+ {
1803
+ "p-0": P.value,
1804
+ "px-24 ": !P.value
1805
+ }
1806
+ ])
1807
+ }, [
1808
+ x(Pt, {
1809
+ "change-location": "",
1810
+ searchable: "",
1811
+ search: $.value,
1812
+ "onUpdate:search": f[0] || (f[0] = (h) => $.value = h)
1813
+ }, null, 8, ["search"]),
1814
+ x(y, {
1815
+ style: nt(F(R).tableHeight),
1816
+ "column-defs": F(v).columnDefs,
1817
+ "row-data": F(v).drafts,
1818
+ "search-value": $.value,
1819
+ loading: k.value,
1820
+ onRowClick: f[1] || (f[1] = (h) => F(e)(h.original)),
1821
+ "page-size": I.value
1822
+ }, {
1823
+ "list-row": G((h) => [
1824
+ x(Vt, {
1825
+ row: h,
1826
+ onRowClick: (D) => F(e)(D)
1827
+ }, {
1828
+ default: G((D) => {
1829
+ var M, Z, W, re, B, te, be, ke, fe, ye, ge, Y, we, he, Ae, Se, Fe, xe, le, me;
1830
+ return [
1831
+ s("div", Na, [
1832
+ s("div", Oa, [
1833
+ s("div", Ka, [
1834
+ x(F(Pe), {
1835
+ render: (W = (Z = (M = D._id) == null ? void 0 : M.column) == null ? void 0 : Z.columnDef) == null ? void 0 : W.cell,
1836
+ props: (B = (re = D._id) == null ? void 0 : re.getContext) == null ? void 0 : B.call(re)
1837
+ }, null, 8, ["render", "props"])
1838
+ ]),
1839
+ s("div", Ya, [
1840
+ x(F(Pe), {
1841
+ render: (ke = (be = (te = D.name) == null ? void 0 : te.column) == null ? void 0 : be.columnDef) == null ? void 0 : ke.cell,
1842
+ props: (ye = (fe = D.name) == null ? void 0 : fe.getContext) == null ? void 0 : ye.call(fe)
1843
+ }, null, 8, ["render", "props"])
1844
+ ]),
1845
+ s("div", Qa, J([
1846
+ ...h.original.items.slice(0, 3).map((Te) => Te.sku.name),
1847
+ ...h.original.items.length >= 3 ? [`and ${h.original.items.length - 3} more items`] : []
1848
+ ].join(", ")), 1),
1849
+ s("div", Ga, [
1850
+ x(F(Pe), {
1851
+ render: (we = (Y = (ge = D.ref) == null ? void 0 : ge.column) == null ? void 0 : Y.columnDef) == null ? void 0 : we.cell,
1852
+ props: (Ae = (he = D.ref) == null ? void 0 : he.getContext) == null ? void 0 : Ae.call(he)
1853
+ }, null, 8, ["render", "props"])
1854
+ ])
1855
+ ]),
1856
+ s("div", null, [
1857
+ x(F(Pe), {
1858
+ render: (xe = (Fe = (Se = D.status) == null ? void 0 : Se.column) == null ? void 0 : Fe.columnDef) == null ? void 0 : xe.cell,
1859
+ props: (me = (le = D.status) == null ? void 0 : le.getContext) == null ? void 0 : me.call(le)
1860
+ }, null, 8, ["render", "props"])
1861
+ ])
1862
+ ])
1863
+ ];
1864
+ }),
1865
+ _: 2
1866
+ }, 1032, ["row", "onRowClick"])
1867
+ ]),
1868
+ _: 1
1869
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
1870
+ ], 2)
1871
+ ]),
1872
+ _: 1
1873
+ }, 8, ["title", "actions"]),
1874
+ (C(), se(At, { to: "body" }, [
1875
+ x(za, xt(F(m), {
1876
+ show: F(p),
1877
+ "onUpdate:show": f[2] || (f[2] = (h) => at(p) ? p.value = h : null),
1878
+ onSubmitted: f[3] || (f[3] = () => (p.value = !1, F(v).fetchDrafts())),
1879
+ onRefresh: f[4] || (f[4] = (h) => F(v).updateDraftRef(h))
1880
+ }), null, 16, ["show"])
1881
+ ]))
1882
+ ], 64);
1883
+ };
1884
+ }
1885
+ });
1886
+ export {
1887
+ on as default
1888
+ };