@feedmepos/mf-inventory-portal 1.2.46-dev.3 → 1.2.46-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 (71) hide show
  1. package/dist/{App-ySxcDomm.js → App-DsW9zwH-.js} +3 -3
  2. package/dist/{ApprovalView-_EJKApES.js → ApprovalView-Dvyp3wel.js} +5 -5
  3. package/dist/{BindingsDialog-9GOaeI8n.js → BindingsDialog-YBp__WSV.js} +2 -2
  4. package/dist/{BindingsPicker-BeGibuLu.js → BindingsPicker-DlBjt-Ba.js} +2 -2
  5. package/dist/{BindingsTable-BRIxUXYh.js → BindingsTable-CTRzUUB-.js} +3 -3
  6. package/dist/ClosingDraftView-6c7X_KiP.js +2410 -0
  7. package/dist/{ClosingHistoryView-Dn4Cjswm.js → ClosingHistoryView-bOwlkF4Q.js} +3 -3
  8. package/dist/{ClosingTemplateView-Co_DSUTb.js → ClosingTemplateView-CA-f8FAh.js} +14 -14
  9. package/dist/{DeliveryOrderPrintPreview-DkJwksMs.js → DeliveryOrderPrintPreview-DmjK4cj3.js} +1 -1
  10. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DyWHsoW6.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-B813CRxg.js} +4 -4
  11. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-No_HFW6L.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-lgr6bbOW.js} +2 -2
  12. package/dist/{FmMultiselectDialog-BQgNlFR9.js → FmMultiselectDialog-26pdE-k-.js} +1 -1
  13. package/dist/{FmMultiselectDialog-Cf8uKaTm.js → FmMultiselectDialog-72g5JwZ9.js} +2 -2
  14. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-CNLY-Hzz.js → FmUnitInput.vue_vue_type_script_setup_true_lang-CQAnQxH8.js} +3 -3
  15. package/dist/{ImportView-D1v8E1VD.js → ImportView-4mjAMfeB.js} +6 -6
  16. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-CQzXwQYK.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CDodN-Rh.js} +1 -1
  17. package/dist/{IngredientGroupView-BrZ_OwZv.js → IngredientGroupView-DmcHEj63.js} +5 -5
  18. package/dist/{IngredientsView-C6RNpxxb.js → IngredientsView-BDPANb85.js} +14 -14
  19. package/dist/{IntegrationView-Ca7ejuaF.js → IntegrationView-pyqYL2jb.js} +12 -12
  20. package/dist/{InventoryBindingForm-D0pD3HsN.js → InventoryBindingForm-DSbRfb3F.js} +1 -1
  21. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-CTdLmzkv.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-KfPb4N5d.js} +4 -4
  22. package/dist/{InventoryBindingSummary-DeaupJPl.js → InventoryBindingSummary-BcGBSNvn.js} +1 -1
  23. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Dyeizcb9.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Dgauy-iB.js} +1 -1
  24. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-SpBOB8Jf.js → PremiumBadge.vue_vue_type_script_setup_true_lang-B53Hy6EY.js} +2 -2
  25. package/dist/{PublishView-C6mc-X3S.js → PublishView-CJBqs89f.js} +3 -3
  26. package/dist/{PurchaseOrderPrintPreview-D2iF1QHy.js → PurchaseOrderPrintPreview-BKvf3c7F.js} +1 -1
  27. package/dist/{ReceiveRequestView-CdtV-Shg.js → ReceiveRequestView-DwclAVDm.js} +18 -18
  28. package/dist/{RecipeView-DWZfk8K4.js → RecipeView-CYIOyih-.js} +8 -8
  29. package/dist/{StockView-8wAAtKfj.js → StockView-loAHU_aR.js} +15 -15
  30. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-DVpjp5eW.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CNIpGt9s.js} +1 -1
  31. package/dist/{SupplierView-CH_KBKSr.js → SupplierView-D0h-AaRw.js} +11 -11
  32. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-Ddn8qCWG.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-D1UE7aKR.js} +2 -2
  33. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CjaWOrc7.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-DhqGYaf-.js} +1 -1
  34. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-B1SE0VPO.js → TransferDetails.vue_vue_type_script_setup_true_lang-D-g6cXC3.js} +14 -14
  35. package/dist/{TransferTemplateView-CJ74oEFd.js → TransferTemplateView-dvekbFPc.js} +412 -412
  36. package/dist/{UnitView-CHZpS66w.js → UnitView-BJPDHJ1t.js} +6 -6
  37. package/dist/{WarehouseView-BdlEzxyN.js → WarehouseView-DfBC9bn5.js} +5 -5
  38. package/dist/{WastageTemplateView-DPYFFFPg.js → WastageTemplateView-D7txOfrr.js} +14 -14
  39. package/dist/{app-L6j_SX6Z.js → app-DZ9CIN-l.js} +22 -22
  40. package/dist/app.js +1 -1
  41. package/dist/{closing-template-DL2xo4-p.js → closing-template-Bhuuo6RL.js} +1 -1
  42. package/dist/{date2-C60QiPZL.js → date2-D0I4_co0.js} +1 -1
  43. package/dist/{dayjs.min-1i9VF7ko.js → dayjs.min-DyYDX3Ns.js} +1 -1
  44. package/dist/{decimal-DfXZArxr.js → decimal-CpLUQcWa.js} +2 -2
  45. package/dist/{defineDeepModel-DYMBS2Up.js → defineDeepModel-CBc_F4eu.js} +1 -1
  46. package/dist/{duplicate-template-DbCPaO6i.js → duplicate-template-BIMQgrkD.js} +1 -1
  47. package/dist/{feature-BrCYCAw3.js → feature-CjK6Ds77.js} +2 -2
  48. package/dist/{format-time-from-id-Cr_k7Wi5.js → format-time-from-id-9kP1kaTe.js} +1 -1
  49. package/dist/{format-unit-display-DSOafWus.js → format-unit-display-De_mv7m7.js} +10 -10
  50. package/dist/{import-export.helper-BLHYLWps.js → import-export.helper-BcEjyb3B.js} +5 -5
  51. package/dist/{index-D-ZXljMu.js → index-B1bw59a2.js} +1 -1
  52. package/dist/{index-CL_V6m9F.js → index-BcRb-JAY.js} +3 -3
  53. package/dist/{index-DGIytAs7.js → index-CJRR1JAe.js} +1 -1
  54. package/dist/{lodash-iJopJ73U.js → lodash-AfG_nKQX.js} +1 -1
  55. package/dist/{netsuite-C7gUg5Ne.js → netsuite-d7P730Bm.js} +3 -3
  56. package/dist/{purchase-order-template-Qy0dXMvI.js → purchase-order-template-J9nWMrS2.js} +1 -1
  57. package/dist/{rules-DNwy6oOH.js → rules-9v8VtDWl.js} +3 -3
  58. package/dist/{stock-DQX_I8wd.js → stock-C2_qYIxU.js} +1 -1
  59. package/dist/{stock-DTK8SpFp.js → stock-Cjj5e8_a.js} +3 -3
  60. package/dist/{supplier-Dl0JI_BN.js → supplier-Ds2vZ4qg.js} +2 -2
  61. package/dist/tsconfig.app.tsbuildinfo +1 -1
  62. package/dist/{use-ingredient-select-dialog-B6akNhzG.js → use-ingredient-select-dialog-CAKpgkQ9.js} +2 -2
  63. package/dist/{use-inventory-binding-dialog-C72_9SY7.js → use-inventory-binding-dialog-D98L2Cuv.js} +2 -2
  64. package/dist/{use-template-enabled-locations-2-Ba-OnSOi.js → use-template-enabled-locations-2-DrUrir8n.js} +2 -2
  65. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftApprovalDialog.vue.d.ts +2 -10
  66. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +3 -3
  67. package/dist/{vue-i18n-Drpwc5_v.js → vue-i18n-CNwuZJlQ.js} +242 -242
  68. package/dist/{xlsx-DLXI5MPN.js → xlsx-BfWdatQl.js} +1 -1
  69. package/dist/{xlsx.util-Coy8SybJ.js → xlsx.util-sMO_ulne.js} +1 -1
  70. package/package.json +3 -3
  71. package/dist/ClosingDraftView-BatMvmqU.js +0 -2362
@@ -0,0 +1,2410 @@
1
+ import { defineComponent as Te, ref as q, computed as P, onMounted as Xe, resolveComponent as K, openBlock as x, createElementBlock as V, Fragment as ie, createTextVNode as ce, createBlock as de, withCtx as Y, createElementVNode as n, toDisplayString as X, unref as v, createVNode as k, createCommentVNode as ne, h as F, watch as Ne, renderList as Ce, reactive as Pt, isRef as yt, normalizeClass as $e, normalizeStyle as bt, Teleport as Mt, mergeProps as Lt } from "vue";
2
+ import { F as Ze, u as Nt, _ as Et } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-CWZkVCAj.js";
3
+ import { useCoreStore as ht, useI18n as kt } from "@feedmepos/mf-common";
4
+ import { useSnackbar as et, useDialog as zt, components as be, useProxiedModel as Ht, useBreakpoints as Ot } from "@feedmepos/ui-library";
5
+ import { o as Kt, u as Ye, I as W, s as H, J as _t, K as De, A as Ee, v as ze, c as Yt, a as xt } from "./app-DZ9CIN-l.js";
6
+ import { defineStore as Dt, storeToRefs as Qt } from "pinia";
7
+ import { d as Oe, e as At, f as qt, a as xe } from "./date2-D0I4_co0.js";
8
+ import { R as Gt, f as tt, a as Je, t as Wt, d as Be, o as wt, p as St, m as Ft, l as Zt } from "./rules-9v8VtDWl.js";
9
+ import { b as Jt, d as Xt } from "./xlsx.util-sMO_ulne.js";
10
+ import { u as Ct } from "./stock-Cjj5e8_a.js";
11
+ import { u as at } from "./stock-C2_qYIxU.js";
12
+ import { D as gt, R as Fe } from "./row-action.enum-BcW_L_nE.js";
13
+ import { c as ea, _ as ta, F as Le } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-cfFHDIwQ.js";
14
+ import { f as aa } from "./format-time-from-id-9kP1kaTe.js";
15
+ import { _ as na } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-lgr6bbOW.js";
16
+ import { E as oa } from "./empty-placeholder-wf6-BWE8.js";
17
+ import { u as sa } from "./vue-i18n-CNwuZJlQ.js";
18
+ const Qe = Kt((c, o) => {
19
+ function e() {
20
+ return Ye().currentLocation.dbName;
21
+ }
22
+ return {
23
+ async getDraft(d) {
24
+ const h = e(), y = `${c.inventoryBackendUrl}/${h}/closing-draft/${d}`;
25
+ return o.get(y);
26
+ },
27
+ async readDrafts() {
28
+ const d = e(), h = `${c.inventoryBackendUrl}/${d}/closing-draft`;
29
+ return o.get(h);
30
+ },
31
+ async runOperation(d) {
32
+ const h = e(), y = `${c.inventoryBackendUrl}/${h}/closing-draft/run-operation`;
33
+ return o.post(y, d);
34
+ },
35
+ async runOperationV1(d) {
36
+ const h = e(), y = `${c.inventoryBackendUrl}/${h}/closing-draft/v1/run-operation`;
37
+ return o.post(y, d);
38
+ },
39
+ async sync(d) {
40
+ const h = e(), y = `${c.inventoryBackendUrl}/${h}/closing-draft/sync`;
41
+ return o.post(y, d);
42
+ },
43
+ async cloneDraft(d) {
44
+ const h = e(), y = `${c.inventoryBackendUrl}/${h}/closing-draft/${d}/clone`;
45
+ return o.post(y, {});
46
+ }
47
+ };
48
+ }), ra = { class: "fm-typo-en-body-lg-400" }, la = { class: "fm-typo-en-body-lg-600" }, ia = {
49
+ key: 0,
50
+ class: "flex flex-col"
51
+ }, ca = {
52
+ key: 0,
53
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
54
+ }, ua = { class: "flex gap-12 py-8 justify-end w-full" }, We = /* @__PURE__ */ Te({
55
+ __name: "ClosingDraftAction",
56
+ props: {
57
+ draft: {},
58
+ action: {},
59
+ onCancel: { type: Function },
60
+ onFinished: { type: Function }
61
+ },
62
+ setup(c) {
63
+ const o = c, e = q(), d = Qe(), h = et(), y = q(!1), m = q(null), M = q(!1), U = P(() => {
64
+ switch (o.action) {
65
+ case W.enum.approveDraft:
66
+ return "Approve";
67
+ case W.enum.rejectDraft:
68
+ return "Reject";
69
+ case W.enum.markAsFailed:
70
+ return "Mark as Failed";
71
+ }
72
+ throw new Error(`Unknown action: ${o.action}`);
73
+ }), R = P(() => {
74
+ switch (o.action) {
75
+ case W.enum.approveDraft:
76
+ return "primary";
77
+ case W.enum.rejectDraft:
78
+ return "destructive";
79
+ case W.enum.markAsFailed:
80
+ return "destructive";
81
+ }
82
+ throw new Error(`Unknown action: ${o.action}`);
83
+ });
84
+ Xe(() => {
85
+ if (o.draft.effectiveAt)
86
+ m.value = new Date(o.draft.effectiveAt);
87
+ else {
88
+ const s = new Date(o.draft.createdAt);
89
+ s.setHours(23, 59, 59, 999), m.value = s;
90
+ }
91
+ M.value = !0;
92
+ });
93
+ const _ = P({
94
+ get() {
95
+ return m.value === null ? "" : Oe(m.value);
96
+ },
97
+ set(s) {
98
+ if (s) {
99
+ const t = /* @__PURE__ */ new Date(`${s} ${E.value}`);
100
+ t.setSeconds(59, 999), m.value = t;
101
+ } else
102
+ m.value = null;
103
+ }
104
+ }), E = P({
105
+ get() {
106
+ return m.value === null ? "" : At(m.value);
107
+ },
108
+ set(s) {
109
+ if (s) {
110
+ const t = /* @__PURE__ */ new Date(`${_.value} ${s}`);
111
+ t.setSeconds(59, 999), m.value = t;
112
+ } else
113
+ m.value = null;
114
+ }
115
+ }), j = P(() => m.value ? m.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
116
+ async function G(s) {
117
+ y.value = !0;
118
+ try {
119
+ s ? await d.runOperationV1({
120
+ _id: o.draft._id,
121
+ _rev: o.draft._rev ?? "",
122
+ action: o.action,
123
+ data: {
124
+ effectiveAt: m.value ? m.value.toISOString() : null,
125
+ remark: e.value
126
+ }
127
+ }).delayed(500) : await d.runOperation({
128
+ _id: o.draft._id,
129
+ _rev: o.draft._rev ?? "",
130
+ action: o.action,
131
+ data: {
132
+ effectiveAt: m.value ? m.value.toISOString() : null,
133
+ remark: e.value
134
+ }
135
+ }).delayed(500), h.open({
136
+ title: "Success",
137
+ message: "Action submitted",
138
+ type: "success"
139
+ }), o.onFinished();
140
+ } catch (t) {
141
+ h.open({
142
+ title: "Something went wrong",
143
+ message: (t == null ? void 0 : t.message) ?? "Unable to submit action. Please try again",
144
+ type: "error"
145
+ }), console.error("error on submit closing draft action", t);
146
+ } finally {
147
+ y.value = !1;
148
+ }
149
+ }
150
+ return (s, t) => {
151
+ const C = K("FmLabel"), I = K("FmDatePicker"), Z = K("FmTimePicker"), g = K("FmTextField"), l = K("FmButton"), $ = K("FmForm");
152
+ return M.value ? (x(), de($, {
153
+ key: 1,
154
+ onValidationSuccess: G,
155
+ class: "flex flex-col gap-32",
156
+ disabled: y.value
157
+ }, {
158
+ default: Y(() => [
159
+ n("div", ra, [
160
+ t[5] || (t[5] = ce(" You are about to ")),
161
+ n("span", la, X(U.value), 1),
162
+ t[6] || (t[6] = ce(" this draft. Please provide a remark to justify this action. "))
163
+ ]),
164
+ s.action === v(W).enum.approveDraft ? (x(), V("div", ia, [
165
+ k(C, { class: "fm-typo-en-body-lg-600" }, {
166
+ default: Y(() => t[7] || (t[7] = [
167
+ ce("Closing Date")
168
+ ])),
169
+ _: 1
170
+ }),
171
+ k(I, {
172
+ modelValue: _.value,
173
+ "onUpdate:modelValue": t[0] || (t[0] = (z) => _.value = z),
174
+ max: v(Oe)(/* @__PURE__ */ new Date())
175
+ }, null, 8, ["modelValue", "max"]),
176
+ k(C, { class: "fm-typo-en-body-lg-600" }, {
177
+ default: Y(() => t[8] || (t[8] = [
178
+ ce("Closing Time")
179
+ ])),
180
+ _: 1
181
+ }),
182
+ k(Z, {
183
+ modelValue: E.value,
184
+ "onUpdate:modelValue": t[1] || (t[1] = (z) => E.value = z)
185
+ }, null, 8, ["modelValue"]),
186
+ j.value ? (x(), V("div", ca, " Cannot select future date ")) : ne("", !0)
187
+ ])) : ne("", !0),
188
+ k(g, {
189
+ modelValue: e.value,
190
+ "onUpdate:modelValue": t[2] || (t[2] = (z) => e.value = z),
191
+ label: "Remark",
192
+ "label-mark": "required",
193
+ rules: [v(Gt)()]
194
+ }, null, 8, ["modelValue", "rules"]),
195
+ n("div", ua, [
196
+ k(l, {
197
+ label: "Cancel",
198
+ variant: "tertiary",
199
+ onClick: t[3] || (t[3] = (z) => s.onCancel())
200
+ }),
201
+ s.action === v(W).enum.approveDraft ? (x(), de(Ze, { key: 0 }, {
202
+ default: Y(() => [
203
+ k(l, {
204
+ label: "Approve (Legacy)",
205
+ type: "button",
206
+ onClick: t[4] || (t[4] = (z) => G(!0)),
207
+ variant: R.value,
208
+ loading: y.value,
209
+ disabled: j.value
210
+ }, null, 8, ["variant", "loading", "disabled"])
211
+ ]),
212
+ _: 1
213
+ })) : ne("", !0),
214
+ k(l, {
215
+ label: U.value,
216
+ type: "submit",
217
+ variant: R.value,
218
+ loading: y.value
219
+ }, null, 8, ["label", "variant", "loading"])
220
+ ])
221
+ ]),
222
+ _: 1
223
+ }, 8, ["disabled"])) : (x(), V(ie, { key: 0 }, [
224
+ ce("Loading")
225
+ ], 64));
226
+ };
227
+ }
228
+ }), da = Be(0);
229
+ function $t(c) {
230
+ const o = c.measurementsAmounts.groupBy((d) => d.measurement.id), e = c.sku.unit.measurements.reduce((d, h) => {
231
+ var M, U;
232
+ const y = ((U = (M = o.get(h.id)) == null ? void 0 : M[0]) == null ? void 0 : U.amount) ?? da, m = tt(h.conversion, y);
233
+ return d + +Je(m);
234
+ }, +Je(c.baseAmount));
235
+ return Wt(e, c.baseAmount.precision);
236
+ }
237
+ const ma = Be(0), fa = Be(100), Bt = "N/A";
238
+ function pa(c, o, e, d, h, y) {
239
+ var te, oe, w, ee, me;
240
+ const m = $t(c), M = d ?? m, U = wt(M, o), R = o.amount === 0 ? null : St(U, {
241
+ ...o,
242
+ amount: Math.abs(o.amount)
243
+ }), _ = R ? tt(R, fa) : null, E = ((te = c.sku.defaultCost) == null ? void 0 : te.costPerUnit) ?? { amount: 0, precision: 0 }, j = Number(H.toFormatString({ value: E })), G = ((w = (oe = c.sku.defaultCost) == null ? void 0 : oe.measurement) == null ? void 0 : w.conversion) ?? {
244
+ amount: 1,
245
+ precision: 0
246
+ }, s = Number(
247
+ H.toFormatString({ value: G })
248
+ ), t = h ? Number(H.toFormatString({ value: h })) : 0, C = Number(H.toFormatString({ value: o })), I = Number(H.toFormatString({ value: M })), Z = C - I, g = Z * j / s, l = I * j / s, $ = C * j / s;
249
+ return {
250
+ code: c.sku.code,
251
+ name: c.sku.name,
252
+ baseUnit: c.sku.unit.abbrev,
253
+ costUnit: ((me = (ee = c.sku.defaultCost) == null ? void 0 : ee.measurement) == null ? void 0 : me.abbrev) ?? null,
254
+ baseUnitAmount: Number(H.toFormatString({ value: c.baseAmount })),
255
+ ...c.measurementsAmounts.filter(
256
+ (A) => va(A.measurement) && e.includes(A.measurement.id)
257
+ ).reduce(
258
+ (A, D, J) => (A[`measurementAbbrev${J}`] = `(${D.measurement.abbrev}) × ${H.toFormatString({ value: D.measurement.conversion })}`, A[`measurementAmount${J}`] = Number(H.toFormatString({ value: D.amount })), A),
259
+ {}
260
+ ),
261
+ systemBalance: C,
262
+ physicalBalance: I,
263
+ adjustedAmount: Number(H.toFormatString({ value: U })),
264
+ adjustedDiffPercentage: _ ? Number(
265
+ H.toFormatString({
266
+ value: Ft(_, 2)
267
+ })
268
+ ) : null,
269
+ costPerUnit: j,
270
+ opening: t,
271
+ adjustmentTypes: y ?? Bt,
272
+ varianceQty: Z,
273
+ varianceInCost: g,
274
+ stockTakeValue: l,
275
+ systemValue: $
276
+ };
277
+ }
278
+ function va(c) {
279
+ return !c.abbrev.toLocaleLowerCase().includes("inactive");
280
+ }
281
+ function ga(c) {
282
+ const o = Tt(c);
283
+ return c.reduce(
284
+ (e, d) => {
285
+ var h;
286
+ return Math.max(e, ((h = o == null ? void 0 : o.get(d.sku._id)) == null ? void 0 : h[0].length) ?? 0);
287
+ },
288
+ 0
289
+ );
290
+ }
291
+ function Tt(c) {
292
+ return c.groupBy(
293
+ (o) => o.sku._id,
294
+ (o) => o.measurementsAmounts.filter((e) => !e.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((e) => e.measurement.id)
295
+ );
296
+ }
297
+ function ya(c) {
298
+ const o = _t(), e = o === "MYR" ? "RM" : o;
299
+ return [
300
+ {
301
+ id: "code",
302
+ name: "Code"
303
+ },
304
+ {
305
+ id: "name",
306
+ name: "Name"
307
+ },
308
+ {
309
+ id: "baseUnit",
310
+ name: "Base unit"
311
+ },
312
+ {
313
+ id: "costPerUnit",
314
+ name: "Cost per unit"
315
+ },
316
+ {
317
+ id: "costUnit",
318
+ name: "UOM"
319
+ },
320
+ {
321
+ id: "opening",
322
+ name: "Opening (B/F)"
323
+ },
324
+ {
325
+ id: "adjustmentTypes",
326
+ name: "Type"
327
+ },
328
+ {
329
+ id: "varianceQty",
330
+ name: "Variance (Qty)"
331
+ },
332
+ {
333
+ id: "varianceInCost",
334
+ name: `Variance (${e})`
335
+ },
336
+ {
337
+ id: "physicalBalance",
338
+ name: "Stock take (Qty)"
339
+ },
340
+ {
341
+ id: "systemBalance",
342
+ name: "System balance (Qty)"
343
+ },
344
+ {
345
+ id: "stockTakeValue",
346
+ name: `Stock take value (${e})`
347
+ },
348
+ {
349
+ id: "systemValue",
350
+ name: `System value (${e})`
351
+ },
352
+ {
353
+ id: "adjustedAmount",
354
+ name: "Adjusted balance"
355
+ },
356
+ {
357
+ id: "adjustedDiffPercentage",
358
+ name: "Diff (%)"
359
+ },
360
+ {
361
+ id: "baseUnitAmount",
362
+ name: "Base unit amount"
363
+ },
364
+ ...Array.from({ length: c }).flatMap((h, y) => [
365
+ {
366
+ id: `measurementAmount${y}`,
367
+ name: `UOM amount ${y + 1}`
368
+ },
369
+ {
370
+ id: `measurementAbbrev${y}`,
371
+ name: `UOM ${y + 1}`
372
+ }
373
+ ])
374
+ ];
375
+ }
376
+ function ba(c, o, e) {
377
+ var Z, g, l, $, z, te, oe;
378
+ const d = o.groupBy(
379
+ (w) => w.id,
380
+ (w) => w.balance
381
+ ), h = e.groupBy(
382
+ (w) => w.id,
383
+ (w) => w.balance
384
+ ), y = /* @__PURE__ */ new Map();
385
+ if (c.opening)
386
+ for (const w of c.opening)
387
+ y.set(w.skuId, w.balance);
388
+ const m = /* @__PURE__ */ new Map();
389
+ if (c.adjustmentSnapshot)
390
+ for (const w of c.adjustmentSnapshot) {
391
+ const ee = Object.keys(w.adjustmentsByType).join(", ");
392
+ m.set(w.skuId, ee || Bt);
393
+ }
394
+ const M = [...c.items, ...c.negativeStockItems ?? []], U = Tt(M), R = M.map((w) => {
395
+ var J, O, re;
396
+ const ee = ((J = d.get(w.sku._id)) == null ? void 0 : J[0]) ?? ma, me = ((O = U == null ? void 0 : U.get(w.sku._id)) == null ? void 0 : O[0]) ?? [], A = y.get(w.sku._id), D = m.get(w.sku._id);
397
+ return pa(
398
+ w,
399
+ ee,
400
+ me,
401
+ (re = h.get(w.sku._id)) == null ? void 0 : re[0],
402
+ A,
403
+ D
404
+ );
405
+ }), _ = ga(M), j = ht().currentBusiness.value, G = ya(_), s = [
406
+ ["Business name:", j == null ? void 0 : j.name],
407
+ ["Business ID:", j == null ? void 0 : j._id],
408
+ ["Menu version", j == null ? void 0 : j.menuVersion],
409
+ ["Created at", new Date(c.createdAt)],
410
+ ["Created by", (Z = c.createdBy) == null ? void 0 : Z.name],
411
+ ["Updated at", new Date(c.updatedAt)],
412
+ ["Updated by", (g = c.updatedBy) == null ? void 0 : g.name],
413
+ ["Recent action", c.approvedAt ? "Approve" : c.rejectionHistory ? "Reject" : ""],
414
+ [
415
+ "Action by",
416
+ c.approvedAt ? (l = c.approvedBy) == null ? void 0 : l.name : c.rejectionHistory ? (z = ($ = c.rejectionHistory[0]) == null ? void 0 : $.rejectedBy) == null ? void 0 : z.name : ""
417
+ ],
418
+ [
419
+ "Action at",
420
+ c.approvedAt ? new Date(c.approvedAt) : c.rejectionHistory ? new Date((te = c.rejectionHistory[0]) == null ? void 0 : te.rejectedAt) : ""
421
+ ],
422
+ [
423
+ "Action remark",
424
+ c.approvedAt ? c.approveRemark : c.rejectionHistory ? new Date((oe = c.rejectionHistory[0]) == null ? void 0 : oe.rejectRemark) : ""
425
+ ],
426
+ [],
427
+ G.map((w) => w.name),
428
+ ...R.map((w) => G.map((ee) => w[ee.id]))
429
+ ], t = G.map((w) => `system:${w.id}`), C = Jt(s, t), I = `[${j == null ? void 0 : j.name}] closing draft (${qt(new Date(c.updatedAt))}).xlsx`;
430
+ return Xt(C, I), I;
431
+ }
432
+ const ha = { class: "flex flex-col" }, ka = {
433
+ key: 0,
434
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
435
+ }, _a = { class: "flex gap-12 py-8 justify-end w-full" }, xa = /* @__PURE__ */ Te({
436
+ __name: "RefreshBalanceAction",
437
+ props: {
438
+ draft: {},
439
+ onCancel: { type: Function },
440
+ onFinished: { type: Function }
441
+ },
442
+ setup(c) {
443
+ const o = c;
444
+ at();
445
+ const e = q(!1), d = q(null), h = q(!1);
446
+ Xe(() => {
447
+ if (o.draft.effectiveAt)
448
+ d.value = new Date(o.draft.effectiveAt);
449
+ else {
450
+ const R = new Date(o.draft.createdAt);
451
+ R.setHours(23, 59, 59, 999), d.value = R;
452
+ }
453
+ h.value = !0;
454
+ });
455
+ const y = P({
456
+ get() {
457
+ return d.value === null ? "" : Oe(d.value);
458
+ },
459
+ set(R) {
460
+ if (R) {
461
+ const _ = /* @__PURE__ */ new Date(`${R} ${m.value}`);
462
+ _.setSeconds(59, 999), d.value = _;
463
+ } else
464
+ d.value = null;
465
+ }
466
+ }), m = P({
467
+ get() {
468
+ return d.value === null ? "" : At(d.value);
469
+ },
470
+ set(R) {
471
+ if (R) {
472
+ const _ = /* @__PURE__ */ new Date(`${y.value} ${R}`);
473
+ _.setSeconds(59, 999), d.value = _;
474
+ } else
475
+ d.value = null;
476
+ }
477
+ }), M = P(() => d.value ? d.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
478
+ async function U() {
479
+ e.value = !0, o.onFinished(d.value.toISOString());
480
+ }
481
+ return (R, _) => {
482
+ const E = K("FmLabel"), j = K("FmDatePicker"), G = K("FmTimePicker"), s = K("FmButton"), t = K("FmForm");
483
+ return h.value ? (x(), de(t, {
484
+ key: 1,
485
+ onValidationSuccess: U,
486
+ class: "flex flex-col gap-32",
487
+ disabled: e.value
488
+ }, {
489
+ default: Y(() => [
490
+ _[5] || (_[5] = n("div", { class: "fm-typo-en-body-lg-400" }, [
491
+ n("p", null, [
492
+ ce(" Performing "),
493
+ n("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
494
+ ce(" until closing effective date and time. ")
495
+ ]),
496
+ n("p", { class: "mt-2" }, [
497
+ ce(" Please note that this action will "),
498
+ n("b", null, "update"),
499
+ ce(" the effective date and time. ")
500
+ ])
501
+ ], -1)),
502
+ n("div", ha, [
503
+ k(E, { class: "fm-typo-en-body-lg-600" }, {
504
+ default: Y(() => _[3] || (_[3] = [
505
+ ce("Closing Date")
506
+ ])),
507
+ _: 1
508
+ }),
509
+ k(j, {
510
+ modelValue: y.value,
511
+ "onUpdate:modelValue": _[0] || (_[0] = (C) => y.value = C),
512
+ max: v(Oe)(/* @__PURE__ */ new Date())
513
+ }, null, 8, ["modelValue", "max"]),
514
+ k(E, { class: "fm-typo-en-body-lg-600" }, {
515
+ default: Y(() => _[4] || (_[4] = [
516
+ ce("Closing Time")
517
+ ])),
518
+ _: 1
519
+ }),
520
+ k(G, {
521
+ modelValue: m.value,
522
+ "onUpdate:modelValue": _[1] || (_[1] = (C) => m.value = C)
523
+ }, null, 8, ["modelValue"]),
524
+ M.value ? (x(), V("div", ka, " Cannot select future date ")) : ne("", !0)
525
+ ]),
526
+ n("div", _a, [
527
+ k(s, {
528
+ label: "Cancel",
529
+ variant: "tertiary",
530
+ onClick: _[2] || (_[2] = (C) => R.onCancel())
531
+ }),
532
+ k(s, {
533
+ label: "Refresh balance",
534
+ type: "submit",
535
+ variant: "primary",
536
+ loading: e.value,
537
+ disabled: M.value
538
+ }, null, 8, ["loading", "disabled"])
539
+ ])
540
+ ]),
541
+ _: 1
542
+ }, 8, ["disabled"])) : (x(), V(ie, { key: 0 }, [
543
+ ce("Loading")
544
+ ], 64));
545
+ };
546
+ }
547
+ }), Ke = Dt(
548
+ "closingDraftActions",
549
+ function() {
550
+ const o = zt(), e = et(), d = at(), h = Qe(), y = Ct(), m = q(!1), M = q();
551
+ function U(g) {
552
+ const l = {
553
+ draft: g
554
+ };
555
+ M.value = l, m.value = !0;
556
+ }
557
+ async function R(g) {
558
+ var $;
559
+ if (g.status === De.enum.COMPLETED) {
560
+ const z = g.closingAdjustmentId;
561
+ if (!z)
562
+ return e.open({
563
+ title: "Something went wrong",
564
+ message: "Closing draft is completed but closing document cannot be found.",
565
+ type: "error"
566
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
567
+ draftId: g._id
568
+ }), [];
569
+ const te = await d.readAdjustmentById(z);
570
+ return ((te == null ? void 0 : te.skus) ?? []).map((w) => ({
571
+ id: w.sku._id,
572
+ balance: w.fromBalance,
573
+ costs: w.fromCostBalances
574
+ }));
575
+ } else
576
+ return await y.readStockBalance(), (($ = y.stockBalance) == null ? void 0 : $.skus) ?? [];
577
+ }
578
+ async function _(g, l, $) {
579
+ l || (e.open({
580
+ title: "Exporting",
581
+ message: "Fetching data..."
582
+ }), l = await R(g)), ba(g, l, $ ?? []);
583
+ }
584
+ function E(g, l, $) {
585
+ o.open({
586
+ title: "Approve draft",
587
+ contentComponent: We,
588
+ contentComponentProps: {
589
+ draft: g,
590
+ action: W.enum.approveDraft,
591
+ onFinished: () => {
592
+ o.close(), l == null || l();
593
+ },
594
+ onCancel: () => {
595
+ o.close();
596
+ }
597
+ }
598
+ }).onClose(() => {
599
+ $ == null || $();
600
+ });
601
+ }
602
+ function j(g, l) {
603
+ o.open({
604
+ title: "Reject draft",
605
+ contentComponent: We,
606
+ contentComponentProps: {
607
+ draft: g,
608
+ action: W.enum.rejectDraft,
609
+ onFinished: () => {
610
+ o.close(), l == null || l();
611
+ },
612
+ onCancel: () => o.close()
613
+ }
614
+ });
615
+ }
616
+ function G(g, l) {
617
+ o.open({
618
+ title: "Mark draft as failed",
619
+ contentComponent: We,
620
+ contentComponentProps: {
621
+ draft: g,
622
+ action: W.enum.markAsFailed,
623
+ onFinished: () => {
624
+ o.close(), l == null || l();
625
+ },
626
+ onCancel: () => o.close()
627
+ }
628
+ });
629
+ }
630
+ async function s(g, l) {
631
+ await h.sync({
632
+ _id: g._id,
633
+ _rev: g._rev ?? "",
634
+ action: W.enum.approveDraft,
635
+ data: {
636
+ remark: g.remark ?? ""
637
+ }
638
+ }).delayed(500), e.open({
639
+ title: "Success",
640
+ message: "Sync requested",
641
+ type: "success"
642
+ }), l == null || l();
643
+ }
644
+ function t() {
645
+ m.value = !1;
646
+ }
647
+ async function C(g, l, $) {
648
+ await o.open({
649
+ title: "Refresh balance",
650
+ contentComponent: xa,
651
+ contentComponentProps: {
652
+ draft: g,
653
+ onFinished: (z) => {
654
+ o.close(), $ == null || $(z);
655
+ },
656
+ onCancel: async () => {
657
+ o.close(), l == null || l();
658
+ }
659
+ }
660
+ });
661
+ }
662
+ async function I(g) {
663
+ await o.open({
664
+ title: "Invalidate closing draft cache",
665
+ message: "It will invalidate opening and stock movement cache for this draft.",
666
+ primaryActions: { text: "Proceed", close: !0 },
667
+ secondaryActions: { text: "Cancel", close: !0 }
668
+ }).onPrimary(async () => {
669
+ await d.recalculation.scheduleInvalidateClosingDraftCache([g._id]), e.open({
670
+ title: "Success",
671
+ message: "Invalidate cache requested",
672
+ type: "success"
673
+ });
674
+ });
675
+ }
676
+ async function Z(g, l) {
677
+ try {
678
+ e.open({
679
+ title: "Cloning",
680
+ message: "Creating a copy of the draft..."
681
+ }), await h.cloneDraft(g._id), e.open({
682
+ title: "Success",
683
+ message: "Draft cloned successfully",
684
+ type: "success"
685
+ }), l == null || l();
686
+ } catch ($) {
687
+ e.open({
688
+ title: "Error",
689
+ message: ($ == null ? void 0 : $.message) || "Failed to clone draft",
690
+ type: "error"
691
+ });
692
+ }
693
+ }
694
+ return {
695
+ viewDraft: U,
696
+ closeDraftDialog: t,
697
+ approveDraft: E,
698
+ rejectDraft: j,
699
+ markAsFailed: G,
700
+ syncDraft: s,
701
+ exportDraft: _,
702
+ refreshBalance: C,
703
+ cloneDraft: Z,
704
+ viewClosingDraftShow: m,
705
+ viewClosingDraftProps: M,
706
+ invalidateDraftCache: I
707
+ };
708
+ }
709
+ );
710
+ function He(c) {
711
+ switch (c) {
712
+ case "DRAFT":
713
+ return "fm-status-badge-draft";
714
+ case "PROCESSING":
715
+ return "fm-status-badge-processing";
716
+ case "FAILED":
717
+ return "fm-status-badge-cancel";
718
+ case "COMPLETED":
719
+ return "fm-status-badge-complete";
720
+ }
721
+ }
722
+ const Da = Dt(
723
+ "closingDraftTable",
724
+ function() {
725
+ const { t: o } = kt(), e = ht(), d = Ke(), h = q(new Array()), y = q(!1), m = Ye(), M = Qe();
726
+ async function U() {
727
+ if (h.value = [], !!m._currentLocation) {
728
+ y.value = !0;
729
+ try {
730
+ const [s] = await Promise.all([M.readDrafts()]).delayed(1e3);
731
+ h.value = s.reverse();
732
+ } catch (s) {
733
+ console.log("Something went wrong when fetching drafts:", s);
734
+ } finally {
735
+ y.value = !1;
736
+ }
737
+ }
738
+ }
739
+ async function R(s) {
740
+ if (!h.value.find((t) => t._id) && m._currentLocation) {
741
+ y.value = !0;
742
+ try {
743
+ const [t] = await Promise.all([
744
+ M.getDraft(s),
745
+ new Promise((C) => setTimeout(C, 1e3))
746
+ ]);
747
+ h.value = [t];
748
+ } catch (t) {
749
+ console.log("Something went wrong when fetching drafts:", t);
750
+ } finally {
751
+ y.value = !1;
752
+ }
753
+ }
754
+ }
755
+ function _(s) {
756
+ h.value = h.value.map((t) => t._id === s._id ? {
757
+ ...s,
758
+ _rev: t._rev
759
+ } : t);
760
+ }
761
+ function E() {
762
+ d.closeDraftDialog(), U();
763
+ }
764
+ function j(s, t) {
765
+ switch (t = Yt(t), s) {
766
+ case Fe.Details:
767
+ return d.viewDraft(t);
768
+ case Fe.Export:
769
+ return d.exportDraft(t);
770
+ case W.enum.approveDraft:
771
+ return d.approveDraft(t, E);
772
+ case W.enum.rejectDraft:
773
+ return d.rejectDraft(t, E);
774
+ case W.enum.markAsFailed:
775
+ return d.markAsFailed(t, E);
776
+ case Fe.Duplicate:
777
+ return d.cloneDraft(t, E);
778
+ }
779
+ }
780
+ return {
781
+ columnDefs: [
782
+ {
783
+ id: "_id",
784
+ accessorKey: "_id",
785
+ header: () => o("inventory.closing.table.createdAt"),
786
+ cell(s) {
787
+ return aa(`${s.getValue()}`);
788
+ },
789
+ enableSorting: !0
790
+ },
791
+ {
792
+ accessorKey: "effectiveAt",
793
+ header: () => "Effective at",
794
+ cell(s) {
795
+ const t = s.row.original;
796
+ let C = s.getValue();
797
+ return C || (C = Ee(t._id)), xe(C);
798
+ },
799
+ enableSorting: !0,
800
+ size: 200
801
+ },
802
+ {
803
+ id: "updatedAt",
804
+ accessorFn: (s) => xe(s.updatedAt),
805
+ header: () => "Updated at",
806
+ enableSorting: !0,
807
+ size: 200
808
+ },
809
+ {
810
+ id: "updatedBy",
811
+ accessorKey: "updatedBy.name",
812
+ header: () => "Last update by",
813
+ enableSorting: !0,
814
+ size: 200
815
+ },
816
+ {
817
+ id: "noOfItems",
818
+ accessorFn: (s) => {
819
+ var t;
820
+ return s.items.length + (((t = s.negativeStockItems) == null ? void 0 : t.length) ?? 0);
821
+ },
822
+ header: () => o("inventory.closing.table.noOfItems"),
823
+ enableSorting: !1,
824
+ meta: {
825
+ width: "10rem",
826
+ textAlign: "right"
827
+ }
828
+ },
829
+ {
830
+ id: "recentRemark",
831
+ accessorFn: (s) => {
832
+ var t;
833
+ return (s == null ? void 0 : s.approveRemark) ?? ((t = s == null ? void 0 : s.rejectionHistory) == null ? void 0 : t.computeFirst((C) => C.rejectRemark)) ?? s.remark;
834
+ },
835
+ header: () => "Recent remark"
836
+ },
837
+ {
838
+ id: "status",
839
+ accessorFn: (s) => s.status,
840
+ header: () => o("inventory.closing.table.status"),
841
+ enableSorting: !1,
842
+ cell(s) {
843
+ var l;
844
+ const t = s.row.original, C = t.status, I = new Date(t.updatedAt), Z = (l = t == null ? void 0 : t.rejectionHistory) == null ? void 0 : l.computeFirst(($) => $.rejectedAt), g = Z ? new Date(Z) : null;
845
+ return C === "DRAFT" && g ? g.getTime() > I.getTime() ? F(
846
+ "div",
847
+ {
848
+ class: "flex"
849
+ },
850
+ F(
851
+ "div",
852
+ {
853
+ class: ["fm-status-badge", He("FAILED")]
854
+ },
855
+ "Rejected"
856
+ )
857
+ ) : F(
858
+ "div",
859
+ {
860
+ class: "flex"
861
+ },
862
+ F(
863
+ "div",
864
+ {
865
+ class: ["fm-status-badge", He("PROCESSING")]
866
+ },
867
+ "Updated"
868
+ )
869
+ ) : F(
870
+ "div",
871
+ {
872
+ class: "flex"
873
+ },
874
+ F(
875
+ "div",
876
+ {
877
+ class: ["fm-status-badge", He(C)]
878
+ },
879
+ ze(C)
880
+ )
881
+ );
882
+ }
883
+ },
884
+ {
885
+ id: "action",
886
+ cell(s) {
887
+ var l;
888
+ const t = s.row.original, C = ((l = e.sessionUser.value) == null ? void 0 : l.role.isAdmin) ?? !1, I = [
889
+ gt[Fe.Details],
890
+ gt[Fe.Export]
891
+ ], Z = [
892
+ {
893
+ translationKey: "inventory.closing.draft.approveDraft",
894
+ color: "text-fm-color-typo-primary",
895
+ value: W.enum.approveDraft
896
+ },
897
+ {
898
+ translationKey: "inventory.closing.draft.rejectDraft",
899
+ color: "text-fm-color-typo-error",
900
+ value: W.enum.rejectDraft
901
+ },
902
+ {
903
+ translationKey: "inventory.closing.draft.markAsFailed",
904
+ color: "text-fm-color-typo-error",
905
+ value: W.enum.markAsFailed
906
+ }
907
+ ], g = C && t.status !== De.enum.DRAFT ? [
908
+ {
909
+ translationKey: "inventory.closing.draft.cloneDraft",
910
+ color: "text-fm-color-typo-primary",
911
+ value: Fe.Duplicate
912
+ }
913
+ ] : [];
914
+ return ea(
915
+ [
916
+ ...I,
917
+ ...t.status === De.enum.DRAFT ? Z : []
918
+ ],
919
+ ($) => j($, t),
920
+ g
921
+ );
922
+ },
923
+ enableSorting: !1,
924
+ size: 40,
925
+ meta: {
926
+ cellClass: "",
927
+ headerClass: ""
928
+ }
929
+ }
930
+ ],
931
+ drafts: h,
932
+ loading: y,
933
+ fetchDrafts: U,
934
+ loadDraft: R,
935
+ updateDraftRef: _
936
+ };
937
+ }
938
+ ), Aa = { class: "fm-typo-en-heading-lg-600" }, wa = { class: "py-4" }, Sa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Fa = { key: 0 }, Ca = { class: "mt-4 flex gap-4" }, $a = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Ba = { key: 0 }, Ta = {
939
+ key: 0,
940
+ class: "mb-4"
941
+ }, ja = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full" }, Ia = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ua = {
942
+ key: 0,
943
+ class: "text-fm-color-system-success-300 mr-1"
944
+ }, Ra = {
945
+ key: 1,
946
+ class: "text-fm-color-system-error-300 mr-1"
947
+ }, Va = { class: "fm-typo-en-body-md-400" }, Pa = { class: "mt-4 flex gap-4" }, Ma = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, La = {
948
+ key: 0,
949
+ class: "flex gap-4"
950
+ }, Na = /* @__PURE__ */ Te({
951
+ __name: "ClosingDraftApprovalDialog",
952
+ props: {
953
+ show: { type: Boolean },
954
+ refreshing: { type: Boolean },
955
+ approving: { type: Boolean },
956
+ draft: {}
957
+ },
958
+ emits: ["update:show", "refresh", "approve"],
959
+ setup(c, { emit: o }) {
960
+ const { FmStepper: e, FmStep: d, FmDialog: h, FmButton: y } = be, { t: m } = sa(), M = xt(), U = c, R = o, _ = P(
961
+ () => {
962
+ var A, D;
963
+ return ((A = U.draft) == null ? void 0 : A.stockSnapshot) && ((D = U.draft) == null ? void 0 : D.stockSnapshot) !== void 0;
964
+ }
965
+ ), E = P(() => {
966
+ var J, O, re;
967
+ const A = ((J = U.draft) == null ? void 0 : J.items.map((Q) => ({
968
+ id: Q.sku._id,
969
+ code: Q.sku.code,
970
+ name: Q.sku.name
971
+ }))) ?? [], D = ((re = (O = U.draft) == null ? void 0 : O.negativeStockItems) == null ? void 0 : re.map((Q) => ({
972
+ id: Q.sku._id,
973
+ code: Q.sku.code,
974
+ name: Q.sku.name
975
+ }))) ?? [];
976
+ return [...A, ...D].reduce(
977
+ (Q, ve) => (Q[ve.id] = ve, Q),
978
+ {}
979
+ );
980
+ }), j = P(
981
+ () => {
982
+ var A, D, J;
983
+ return (((J = (D = (A = U.draft) == null ? void 0 : A.stockSnapshot) == null ? void 0 : D.filter((O) => O.balance.amount < 0)) == null ? void 0 : J.map((O) => {
984
+ const re = M.skuById[O.id];
985
+ return re ? {
986
+ id: re._id,
987
+ code: re.code,
988
+ name: re.name
989
+ } : null;
990
+ })) ?? []).filter((O) => O !== null);
991
+ }
992
+ ), G = P(() => {
993
+ var A;
994
+ return _.value ? ((A = j.value) == null ? void 0 : A.filter((D) => !E.value[D.id]).map((D) => D.id)) ?? [] : [];
995
+ }), s = P({
996
+ get: () => U.show,
997
+ set: (A) => R("update:show", A)
998
+ }), t = q(1), C = () => t.value > 1, I = () => t.value > 2, Z = () => !1;
999
+ function g(A) {
1000
+ return A === 1 ? _.value : A === 2 ? G.value.length == 0 : !1;
1001
+ }
1002
+ const l = P(() => !_.value || G.value.length > 0);
1003
+ function $(A) {
1004
+ let D = A + 1;
1005
+ for (; D <= 3 && g(D); ) D++;
1006
+ return D > 3 ? 3 : D;
1007
+ }
1008
+ function z(A) {
1009
+ let D = A - 1;
1010
+ for (; D >= 1 && g(D); ) D--;
1011
+ return D < 1 ? 1 : D;
1012
+ }
1013
+ function te() {
1014
+ return _.value ? l.value ? 3 : 2 : 1;
1015
+ }
1016
+ Ne(
1017
+ () => U.show,
1018
+ (A) => {
1019
+ A && (t.value = te());
1020
+ }
1021
+ ), Ne(
1022
+ () => _.value,
1023
+ (A) => {
1024
+ A && t.value === 1 && (t.value = $(1));
1025
+ }
1026
+ ), Ne(
1027
+ () => G.value.length,
1028
+ (A) => {
1029
+ A === 0 && t.value === 2 && (t.value = $(2));
1030
+ }
1031
+ );
1032
+ function oe() {
1033
+ R("refresh");
1034
+ }
1035
+ function w() {
1036
+ t.value < 3 && (t.value = $(t.value));
1037
+ }
1038
+ function ee() {
1039
+ t.value > 1 && (t.value = z(t.value));
1040
+ }
1041
+ function me() {
1042
+ R("approve");
1043
+ }
1044
+ return (A, D) => {
1045
+ const J = K("FmIcon");
1046
+ return x(), de(v(h), {
1047
+ modelValue: s.value,
1048
+ "onUpdate:modelValue": D[1] || (D[1] = (O) => s.value = O),
1049
+ "max-width": 600
1050
+ }, {
1051
+ "dialog-header": Y(() => [
1052
+ n("div", Aa, X(v(m)("inventory.closing.approval.title")), 1)
1053
+ ]),
1054
+ default: Y(() => [
1055
+ n("div", wa, [
1056
+ k(v(e), {
1057
+ modelValue: t.value,
1058
+ "onUpdate:modelValue": D[0] || (D[0] = (O) => t.value = O),
1059
+ orientation: "vertical"
1060
+ }, {
1061
+ default: Y(() => [
1062
+ k(v(d), {
1063
+ value: 1,
1064
+ title: v(m)("inventory.closing.approval.step.generateReport.title"),
1065
+ complete: C
1066
+ }, {
1067
+ default: Y(() => [
1068
+ n("div", Sa, X(v(m)("inventory.closing.approval.step.generateReport.description")), 1),
1069
+ t.value === 1 ? (x(), V("div", Fa, [
1070
+ k(v(y), {
1071
+ label: v(m)("inventory.stock.stock_balance.refreshBalance"),
1072
+ "prepend-icon": "refresh",
1073
+ variant: "secondary",
1074
+ loading: A.refreshing,
1075
+ onClick: oe
1076
+ }, null, 8, ["label", "loading"]),
1077
+ n("div", Ca, [
1078
+ k(v(y), {
1079
+ label: v(m)("inventory.common.continue"),
1080
+ disabled: !_.value,
1081
+ onClick: w
1082
+ }, null, 8, ["label", "disabled"])
1083
+ ])
1084
+ ])) : ne("", !0)
1085
+ ]),
1086
+ _: 1
1087
+ }, 8, ["title"]),
1088
+ k(v(d), {
1089
+ value: 2,
1090
+ title: v(m)("inventory.closing.approval.step.negativeItems.title"),
1091
+ disabled: () => !_.value,
1092
+ complete: I
1093
+ }, {
1094
+ default: Y(() => [
1095
+ n("div", $a, X(j.value.length > 0 ? `${v(m)("inventory.closing.approval.step.negativeItems.resolveMessage")} [${v(m)("inventory.closing.approval.step.negativeItems.itemsHeader")} (${G.value.length})]` : v(m)("inventory.closing.approval.step.negativeItems.noItemsMessage")), 1),
1096
+ t.value === 2 ? (x(), V("div", Ba, [
1097
+ j.value.length > 0 ? (x(), V("div", Ta, [
1098
+ D[2] || (D[2] = n("div", { class: "fm-typo-en-body-md-600 mb-2" }, null, -1)),
1099
+ n("div", ja, [
1100
+ (x(!0), V(ie, null, Ce(j.value, (O) => (x(), V("div", {
1101
+ key: O.id,
1102
+ class: "flex gap-8"
1103
+ }, [
1104
+ n("div", Ia, [
1105
+ E.value[O.id] ? (x(), V("span", Ua, [
1106
+ k(J, {
1107
+ name: "check_circle",
1108
+ size: "sm"
1109
+ })
1110
+ ])) : (x(), V("span", Ra, [
1111
+ k(J, {
1112
+ name: "error",
1113
+ size: "sm"
1114
+ })
1115
+ ])),
1116
+ ce(" " + X(O.code), 1)
1117
+ ]),
1118
+ n("div", Va, X(O.name), 1)
1119
+ ]))), 128))
1120
+ ])
1121
+ ])) : ne("", !0),
1122
+ n("div", Pa, [
1123
+ k(v(y), {
1124
+ label: v(m)("inventory.common.back"),
1125
+ variant: "secondary",
1126
+ onClick: ee
1127
+ }, null, 8, ["label"]),
1128
+ k(v(y), {
1129
+ label: v(m)("inventory.common.continue"),
1130
+ disabled: l.value,
1131
+ onClick: w
1132
+ }, null, 8, ["label", "disabled"])
1133
+ ])
1134
+ ])) : ne("", !0)
1135
+ ]),
1136
+ _: 1
1137
+ }, 8, ["title", "disabled"]),
1138
+ k(v(d), {
1139
+ value: 3,
1140
+ title: v(m)("inventory.closing.approval.step.approval.title"),
1141
+ disabled: () => l.value,
1142
+ complete: Z
1143
+ }, {
1144
+ default: Y(() => [
1145
+ n("div", Ma, X(v(m)("inventory.closing.approval.step.approval.warning")), 1),
1146
+ t.value === 3 ? (x(), V("div", La, [
1147
+ k(v(y), {
1148
+ label: v(m)("inventory.common.back"),
1149
+ variant: "secondary",
1150
+ onClick: ee
1151
+ }, null, 8, ["label"]),
1152
+ k(v(y), {
1153
+ label: v(m)("inventory.common.approve"),
1154
+ variant: "destructive",
1155
+ disabled: l.value,
1156
+ loading: A.approving,
1157
+ onClick: me
1158
+ }, null, 8, ["label", "disabled", "loading"])
1159
+ ])) : ne("", !0)
1160
+ ]),
1161
+ _: 1
1162
+ }, 8, ["title", "disabled"])
1163
+ ]),
1164
+ _: 1
1165
+ }, 8, ["modelValue"])
1166
+ ])
1167
+ ]),
1168
+ _: 1
1169
+ }, 8, ["modelValue"]);
1170
+ };
1171
+ }
1172
+ }), Ea = { class: "w-full flex flex-col gap-32" }, za = { class: "flex justify-between" }, Ha = { class: "flex" }, Oa = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, Ka = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ya = { class: "flex gap-1" }, Qa = { class: "fm-typo-en-body-lg-600" }, qa = { class: "flex flex-col gap-16" }, Ga = { class: "flex items-center" }, Wa = {
1173
+ key: 0,
1174
+ class: "flex gap-8"
1175
+ }, Za = {
1176
+ key: 0,
1177
+ class: "w-full flex flex-col items-center"
1178
+ }, Ja = { class: "flex items-center gap-8" }, Xa = { class: "flex flex-col gap-8" }, en = { class: "flex gap-8" }, tn = {
1179
+ key: 0,
1180
+ class: "flex gap-8"
1181
+ }, an = { class: "overflow-x-auto" }, nn = {
1182
+ key: 1,
1183
+ class: "flex-1 xs:w-screen xs:max-w-full"
1184
+ }, on = {
1185
+ key: 0,
1186
+ class: "flex flex-col items-center gap-8 h-full"
1187
+ }, sn = ["src"], rn = {
1188
+ key: 1,
1189
+ class: "px-4 flex flex-col"
1190
+ }, ln = { class: "flex gap-12 content-stretch" }, cn = {
1191
+ class: "flex flex-col w-24",
1192
+ name: "circles"
1193
+ }, un = { class: "flex-1 flex flex-col items-center" }, dn = { class: "flex-1 flex flex-col items-center" }, mn = {
1194
+ class: "py-12 flex flex-col gap-4",
1195
+ name: "received-at header"
1196
+ }, fn = { class: "fm-typo-en-body-lg-400" }, pn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, vn = { class: "flex gap-12 content-stretch" }, gn = {
1197
+ class: "flex flex-col w-24",
1198
+ name: "circles"
1199
+ }, yn = { class: "flex-1 flex flex-col items-center" }, bn = {
1200
+ class: "py-12 flex flex-col gap-4 flex-1",
1201
+ name: "delivery details"
1202
+ }, hn = { class: "flex flex-col gap-8" }, kn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, _n = { class: "flex flex-col gap-4" }, xn = { class: "flex gap-8" }, Dn = "N/A", An = /* @__PURE__ */ Te({
1203
+ __name: "ClosingDraftDialog",
1204
+ props: {
1205
+ show: { type: Boolean },
1206
+ draft: {}
1207
+ },
1208
+ emits: ["submitted", "refresh"],
1209
+ setup(c, { emit: o }) {
1210
+ const e = c, d = P(() => {
1211
+ const u = _t();
1212
+ return u === "MYR" ? "RM" : u;
1213
+ });
1214
+ Ct();
1215
+ const h = Ke(), y = Ht(e, "show"), m = q(!1), M = q(!1), U = q(!1), R = q(new Array()), _ = q(new Array()), E = q([]), j = at(), G = Qe(), s = et(), t = xt(), C = Ye(), I = Pt({}), Z = P(() => new Set(
1216
+ t.skus.filter((u) => {
1217
+ var a;
1218
+ return I[(a = u.customAttributes) == null ? void 0 : a.tag];
1219
+ }).map((u) => u._id)
1220
+ )), g = o, l = q({
1221
+ templateItem: !0,
1222
+ nonTemplateItem: !0
1223
+ }), $ = P(() => {
1224
+ var a, p;
1225
+ const u = [...((a = e.draft) == null ? void 0 : a.items) ?? [], ...((p = e.draft) == null ? void 0 : p.negativeStockItems) ?? []];
1226
+ return Z.value.size ? u.filter((r) => Z.value.has(r.sku._id)) : u;
1227
+ }), z = P(() => {
1228
+ const u = $.value.map((a) => a.sku);
1229
+ return u.sort((a, p) => a.code.localeCompare(p.code)), u;
1230
+ }), te = P(() => $.value.groupBy(
1231
+ (a) => a.sku._id,
1232
+ (a) => a.measurementsAmounts.filter((p) => !p.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((p) => p.measurement.id)
1233
+ ));
1234
+ Xe(ee), Ne(
1235
+ () => e.show,
1236
+ (u) => {
1237
+ u && (ke.value = he[0], ee(), l.value = {
1238
+ templateItem: !0,
1239
+ nonTemplateItem: !0
1240
+ });
1241
+ }
1242
+ );
1243
+ const oe = Be(0), w = Be(100);
1244
+ async function ee() {
1245
+ var a, p, r, i;
1246
+ if (!C._currentLocation) return;
1247
+ m.value = !0;
1248
+ const u = ((a = e.draft) == null ? void 0 : a.status) === De.enum.COMPLETED;
1249
+ _.value = [];
1250
+ try {
1251
+ if (await t.init(), u) {
1252
+ const L = e.draft.closingAdjustmentId;
1253
+ if (!L) {
1254
+ s.open({
1255
+ title: "Something went wrong",
1256
+ message: "Closing draft is completed but closing document cannot be found.",
1257
+ type: "error"
1258
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
1259
+ draftId: (p = e.draft) == null ? void 0 : p._id
1260
+ });
1261
+ return;
1262
+ }
1263
+ const N = await j.readAdjustmentById(L), ue = (N == null ? void 0 : N.skus) ?? [];
1264
+ for (const fe of ue) {
1265
+ const Ae = {
1266
+ id: fe.sku._id,
1267
+ balance: fe.fromBalance,
1268
+ costs: fe.fromCostBalances
1269
+ }, T = {
1270
+ id: fe.sku._id,
1271
+ balance: fe.toBalance,
1272
+ costs: fe.toCostBalances
1273
+ };
1274
+ R.value.push(Ae), _.value.push(T);
1275
+ }
1276
+ } else
1277
+ R.value = ((r = e.draft) == null ? void 0 : r.stockSnapshot) ?? [];
1278
+ const f = /* @__PURE__ */ new Set();
1279
+ if ((i = e.draft) != null && i.adjustmentSnapshot)
1280
+ for (const L of e.draft.adjustmentSnapshot)
1281
+ L.adjustmentsByType && Object.keys(L.adjustmentsByType).forEach((N) => f.add(N));
1282
+ const b = ["receive", "sales", "wastage"], B = [];
1283
+ b.forEach((L) => {
1284
+ f.has(L) && (B.push(L), f.delete(L));
1285
+ });
1286
+ const S = Array.from(f).sort();
1287
+ E.value = [...B, ...S];
1288
+ } catch (f) {
1289
+ s.open({
1290
+ title: "Something went wrong",
1291
+ message: "Something went wrong when fetching info. Please try again.",
1292
+ type: "error"
1293
+ }), console.error("error on fetch stock balances", f);
1294
+ } finally {
1295
+ m.value = !1;
1296
+ }
1297
+ }
1298
+ async function me() {
1299
+ var a, p;
1300
+ if (!(((a = e.draft) == null ? void 0 : a.effectiveAt) ?? (e.draft ? Ee((p = e.draft) == null ? void 0 : p._id) : null))) {
1301
+ s.open({
1302
+ title: "Cannot refresh",
1303
+ message: "Effective date is not available for this draft.",
1304
+ type: "error"
1305
+ });
1306
+ return;
1307
+ }
1308
+ await h.refreshBalance(
1309
+ e.draft,
1310
+ () => {
1311
+ },
1312
+ async (r) => {
1313
+ var B;
1314
+ M.value = !0;
1315
+ const i = (B = e.draft) == null ? void 0 : B._rev, f = 30, b = 2e3;
1316
+ try {
1317
+ await j.recalculation.scheduleCalculateStockSnapshotAtDate(r, e.draft._id);
1318
+ let S = null;
1319
+ for (let L = 0; L < f && (S = await G.getDraft(e.draft._id).delayed(b), S._rev === i); L++)
1320
+ ;
1321
+ if (!S || S._rev === i) {
1322
+ s.open({
1323
+ title: "Refresh failed",
1324
+ message: "Failed to refresh stock balance. Please try again.",
1325
+ type: "error"
1326
+ }), console.error("error refreshing stock balances: there is no change in _rev");
1327
+ return;
1328
+ }
1329
+ g("refresh", S), R.value = S.stockSnapshot ?? [], s.open({
1330
+ title: "Balance refreshed",
1331
+ message: "Stock balance has been recalculated.",
1332
+ type: "success"
1333
+ }), y.value = !1;
1334
+ } catch (S) {
1335
+ s.open({
1336
+ title: "Refresh failed",
1337
+ message: "Failed to refresh stock balance. Please try again.",
1338
+ type: "error"
1339
+ }), console.error("error refreshing stock balances", S);
1340
+ } finally {
1341
+ M.value = !1;
1342
+ }
1343
+ }
1344
+ );
1345
+ }
1346
+ async function A() {
1347
+ var a, p;
1348
+ if (!(((a = e.draft) == null ? void 0 : a.effectiveAt) ?? (e.draft ? Ee((p = e.draft) == null ? void 0 : p._id) : null))) {
1349
+ s.open({
1350
+ title: "Cannot refresh",
1351
+ message: "Effective date is not available for this draft.",
1352
+ type: "error"
1353
+ });
1354
+ return;
1355
+ }
1356
+ await h.invalidateDraftCache(e.draft);
1357
+ }
1358
+ const D = P(
1359
+ () => R.value.groupBy(
1360
+ (u) => u.id,
1361
+ (u) => u.balance
1362
+ )
1363
+ ), J = P(() => $.value.groupBy((u) => u.sku._id)), O = P(() => {
1364
+ var u;
1365
+ return (u = e.draft) != null && u.adjustmentSnapshot ? new Map(e.draft.adjustmentSnapshot.map((a) => [a.skuId, a.adjustmentsByType])) : /* @__PURE__ */ new Map();
1366
+ }), re = P(() => {
1367
+ var u;
1368
+ return (u = e.draft) != null && u.opening ? new Map(e.draft.opening.map((a) => [a.skuId, a.balance])) : /* @__PURE__ */ new Map();
1369
+ });
1370
+ function Q(u, a) {
1371
+ return F(
1372
+ be.FmTooltip,
1373
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
1374
+ {
1375
+ default() {
1376
+ return u;
1377
+ },
1378
+ content() {
1379
+ return a || u;
1380
+ }
1381
+ }
1382
+ );
1383
+ }
1384
+ const ve = P(() => {
1385
+ const u = z.value.reduce((p, r) => {
1386
+ var i, f;
1387
+ return Math.max(p, ((f = (i = te.value) == null ? void 0 : i.get(r._id)) == null ? void 0 : f[0].length) ?? 0);
1388
+ }, 0);
1389
+ return [
1390
+ {
1391
+ id: "sku",
1392
+ accessorFn: (p) => `${p.code} ${p.name}`,
1393
+ header: () => "Name",
1394
+ size: 350,
1395
+ cell(p) {
1396
+ const r = p.row.original, i = r.adjustedDiffPercentage, f = typeof i == "number" && Math.abs(i) > 10, b = F("div", { class: "flex flex-col gap-4" }, [
1397
+ F(
1398
+ "div",
1399
+ {
1400
+ class: [
1401
+ "line-clamp-1 fm-typo-en-body-lg-400",
1402
+ f ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
1403
+ ]
1404
+ },
1405
+ r.name
1406
+ ),
1407
+ F(
1408
+ "div",
1409
+ {
1410
+ class: [
1411
+ "line-clamp-1 fm-typo-en-body-md-400",
1412
+ f ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
1413
+ ]
1414
+ },
1415
+ r.code
1416
+ )
1417
+ ]);
1418
+ return F(
1419
+ be.FmTooltip,
1420
+ {
1421
+ zIndex: 51
1422
+ },
1423
+ {
1424
+ content() {
1425
+ return f ? "Adjustment difference is more than 10%." : `${r.code} - ${r.name}`;
1426
+ },
1427
+ default() {
1428
+ return F("div", { class: "flex items-center gap-4 justify-start w-full" }, [
1429
+ b
1430
+ ]);
1431
+ }
1432
+ }
1433
+ );
1434
+ }
1435
+ },
1436
+ {
1437
+ id: "costPerUnit",
1438
+ accessorKey: "costPerUnit",
1439
+ header: () => Q("Cost per unit"),
1440
+ size: 160,
1441
+ cell(p) {
1442
+ const r = p.row.original.costPerUnit;
1443
+ return F("div", { class: "text-right" }, r.toFixed(2));
1444
+ },
1445
+ meta: {
1446
+ textAlign: "right"
1447
+ }
1448
+ },
1449
+ {
1450
+ id: "costUnit",
1451
+ header: () => "UOM",
1452
+ size: 120,
1453
+ cell(p) {
1454
+ var B;
1455
+ const r = p.row.original, i = r.costUnit, f = r.baseUnit, b = i ?? f;
1456
+ if (i && i !== f) {
1457
+ const S = z.value.find((N) => N._id === r.id), L = (B = S == null ? void 0 : S.defaultCost) == null ? void 0 : B.measurement;
1458
+ if (L) {
1459
+ const N = L.conversion.amount / Math.pow(10, L.conversion.precision);
1460
+ return F("div", { class: "flex flex-col" }, [
1461
+ F(
1462
+ "span",
1463
+ { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1464
+ b
1465
+ ),
1466
+ F("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, [
1467
+ "1 ",
1468
+ F("span", { class: "fm-typo-en-body-sm-600" }, i),
1469
+ ` = ${N} `,
1470
+ F("span", { class: "fm-typo-en-body-sm-600" }, f)
1471
+ ])
1472
+ ]);
1473
+ }
1474
+ }
1475
+ return b;
1476
+ }
1477
+ },
1478
+ {
1479
+ id: "opening",
1480
+ accessorKey: "opening",
1481
+ header: () => Q("Opening (B/F)", "The opening balance brought forward from previous period."),
1482
+ size: 150,
1483
+ cell(p) {
1484
+ const r = p.row.original.opening;
1485
+ return F("div", { class: "text-right" }, r.toFixed(2));
1486
+ },
1487
+ meta: {
1488
+ textAlign: "right"
1489
+ }
1490
+ },
1491
+ // Dynamic adjustment type columns
1492
+ ...E.value.map(
1493
+ (p) => ({
1494
+ id: `adjustment_${p}`,
1495
+ accessorFn: (r) => r.adjustmentAmounts[p] ?? { amount: 0, precision: 0 },
1496
+ header: () => Q(ze(p)),
1497
+ size: 150,
1498
+ cell(r) {
1499
+ const i = r.row.original.adjustmentAmounts[p] ?? { amount: 0, precision: 0 };
1500
+ return F("div", { class: "text-right" }, Je(i));
1501
+ },
1502
+ meta: {
1503
+ textAlign: "right"
1504
+ }
1505
+ })
1506
+ ),
1507
+ {
1508
+ id: "systemBalance",
1509
+ accessorKey: "systemBalance",
1510
+ header: () => Q("System Balance", "The system calculated balance before stock take."),
1511
+ size: 200,
1512
+ meta: {
1513
+ textAlign: "right"
1514
+ }
1515
+ },
1516
+ {
1517
+ id: "physicalBalance",
1518
+ accessorFn: (p) => {
1519
+ var i;
1520
+ const r = (i = _.value.find((f) => f.id === p.id)) == null ? void 0 : i.balance;
1521
+ return r ? H.toFormatString({ value: r }) : p.physicalBalance;
1522
+ },
1523
+ header: () => Q("Stock Take balance", "The physical balance recorded during stock take."),
1524
+ cell(p) {
1525
+ var S;
1526
+ const r = p.row.original, i = H.fromNumber(r.physicalBalance);
1527
+ let f = !0, b = r.physicalBalance;
1528
+ const B = (S = _.value.find((L) => L.id === r.id)) == null ? void 0 : S.balance;
1529
+ return B && (H.equals({
1530
+ a: i,
1531
+ b: B
1532
+ }) || (f = !1, b = Number(H.toFormatString({ value: B })))), F("div", { class: "flex flex-col" }, [
1533
+ F(
1534
+ "span",
1535
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1536
+ b
1537
+ ),
1538
+ f ? null : F(
1539
+ "span",
1540
+ { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
1541
+ `Draft: ${r.physicalBalance.toString()}`
1542
+ )
1543
+ ]);
1544
+ },
1545
+ size: 200,
1546
+ meta: {
1547
+ textAlign: "right"
1548
+ }
1549
+ },
1550
+ {
1551
+ id: "adjustedAmount",
1552
+ accessorKey: "adjustedAmount",
1553
+ header: () => Q("Variance", "The difference between Stock Take balance and System Balance."),
1554
+ size: 200,
1555
+ meta: {
1556
+ textAlign: "right"
1557
+ }
1558
+ },
1559
+ {
1560
+ id: "varianceInCost",
1561
+ accessorKey: "varianceInCost",
1562
+ header: () => Q(`Variance (${d.value})`),
1563
+ size: 150,
1564
+ cell(p) {
1565
+ const r = p.row.original.varianceInCost;
1566
+ return F(
1567
+ "div",
1568
+ { class: "text-right" },
1569
+ r.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 4 })
1570
+ );
1571
+ },
1572
+ meta: {
1573
+ textAlign: "right"
1574
+ }
1575
+ },
1576
+ {
1577
+ id: "adjustedDiffPercentage",
1578
+ accessorKey: "adjustedDiffPercentage",
1579
+ header: () => Q(
1580
+ "Variance (%)",
1581
+ "Difference between Stock Take balance and System Balance in percentage."
1582
+ ),
1583
+ size: 200,
1584
+ cell(p) {
1585
+ const r = p.row.original.adjustedDiffPercentage;
1586
+ if (!r) return Dn;
1587
+ const i = r.toFixed(2);
1588
+ if (i === "0.00")
1589
+ return F("div", { class: "flex items-center gap-4 justify-end" }, ["0.00"]);
1590
+ const f = r > 0;
1591
+ return F("div", { class: "flex items-center gap-4 justify-end" }, [
1592
+ F(be.FmIcon, {
1593
+ name: f ? "arrow_drop_up" : "arrow_drop_down",
1594
+ color: f ? "system-success-300" : "system-error-300",
1595
+ size: "md"
1596
+ }),
1597
+ i
1598
+ ]);
1599
+ },
1600
+ meta: {
1601
+ textAlign: "right"
1602
+ }
1603
+ },
1604
+ {
1605
+ id: "stockTakeValue",
1606
+ accessorKey: "stockTakeValue",
1607
+ header: () => Q(`Stock take value (${d.value})`),
1608
+ size: 180,
1609
+ cell(p) {
1610
+ var L;
1611
+ const r = p.row.original, i = r.stockTakeValue, f = z.value.find((N) => N._id === r.id), b = (L = f == null ? void 0 : f.defaultCost) == null ? void 0 : L.measurement, B = r.physicalBalance, S = r.costPerUnit;
1612
+ if (b) {
1613
+ const N = H.toFormatString({ value: b.conversion }), ue = `${B.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${r.baseUnit} ÷ ${N} × ${S} ${d.value}`;
1614
+ return F(
1615
+ be.FmTooltip,
1616
+ { zIndex: 51 },
1617
+ {
1618
+ content() {
1619
+ return ue;
1620
+ },
1621
+ default() {
1622
+ return F(
1623
+ "div",
1624
+ { class: "text-right" },
1625
+ i.toLocaleString("en-US", {
1626
+ minimumFractionDigits: 2,
1627
+ maximumFractionDigits: 4
1628
+ })
1629
+ );
1630
+ }
1631
+ }
1632
+ );
1633
+ } else {
1634
+ const N = `${B.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${r.baseUnit} × ${S} ${d.value}`;
1635
+ return F(
1636
+ be.FmTooltip,
1637
+ { zIndex: 51 },
1638
+ {
1639
+ content() {
1640
+ return N;
1641
+ },
1642
+ default() {
1643
+ return F(
1644
+ "div",
1645
+ { class: "text-right" },
1646
+ i.toLocaleString("en-US", {
1647
+ minimumFractionDigits: 2,
1648
+ maximumFractionDigits: 4
1649
+ })
1650
+ );
1651
+ }
1652
+ }
1653
+ );
1654
+ }
1655
+ },
1656
+ meta: {
1657
+ textAlign: "right"
1658
+ }
1659
+ },
1660
+ {
1661
+ id: "systemValue",
1662
+ accessorKey: "systemValue",
1663
+ header: () => Q(`System value (${d.value})`),
1664
+ size: 180,
1665
+ cell(p) {
1666
+ var L;
1667
+ const r = p.row.original, i = r.systemValue, f = z.value.find((N) => N._id === r.id), b = (L = f == null ? void 0 : f.defaultCost) == null ? void 0 : L.measurement, B = r.systemBalance, S = r.costPerUnit;
1668
+ if (b) {
1669
+ const N = H.toFormatString({ value: b.conversion }), ue = `${B.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 4 })} ${r.baseUnit} ÷ ${N} × ${S} ${d.value}`;
1670
+ return F(
1671
+ be.FmTooltip,
1672
+ { zIndex: 51 },
1673
+ {
1674
+ content() {
1675
+ return ue;
1676
+ },
1677
+ default() {
1678
+ return F(
1679
+ "div",
1680
+ { class: "text-right" },
1681
+ i.toLocaleString("en-US", {
1682
+ minimumFractionDigits: 2,
1683
+ maximumFractionDigits: 4
1684
+ })
1685
+ );
1686
+ }
1687
+ }
1688
+ );
1689
+ } else {
1690
+ const N = `${B.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 4 })} ${r.baseUnit} × ${S} ${d.value}`;
1691
+ return F(
1692
+ be.FmTooltip,
1693
+ { zIndex: 51 },
1694
+ {
1695
+ content() {
1696
+ return N;
1697
+ },
1698
+ default() {
1699
+ return F(
1700
+ "div",
1701
+ { class: "text-right" },
1702
+ i.toLocaleString("en-US", {
1703
+ minimumFractionDigits: 2,
1704
+ maximumFractionDigits: 4
1705
+ })
1706
+ );
1707
+ }
1708
+ }
1709
+ );
1710
+ }
1711
+ },
1712
+ meta: {
1713
+ textAlign: "right"
1714
+ }
1715
+ },
1716
+ {
1717
+ id: "physicalBalances",
1718
+ header: () => "Amounts",
1719
+ enableSorting: !1,
1720
+ cell(p) {
1721
+ const r = p.row.original, i = (b, B) => F(
1722
+ be.FmTooltip,
1723
+ { zIndex: 50 },
1724
+ {
1725
+ default() {
1726
+ return F(
1727
+ "div",
1728
+ {
1729
+ 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"
1730
+ },
1731
+ [
1732
+ F("span", { class: "text-fm-color-typo-primary" }, `${b} `),
1733
+ F(
1734
+ "span",
1735
+ {
1736
+ class: "text-fm-color-typo-secondary",
1737
+ style: { maxWidth: "80px" }
1738
+ },
1739
+ B
1740
+ )
1741
+ ]
1742
+ );
1743
+ },
1744
+ content() {
1745
+ return `${b} ${B}`;
1746
+ }
1747
+ }
1748
+ );
1749
+ let f = Array.from({ length: u }).map((b, B) => {
1750
+ if (!r[`measurementAmount${B}`])
1751
+ return null;
1752
+ const S = r[`measurementAmount${B}`], L = r[`measurementAbbrev${B}`];
1753
+ return i(S, L);
1754
+ }).filter((b) => b);
1755
+ return (r.baseUnitAmount || !f.length) && (f = [i(r.baseUnitAmount, r.baseUnit), ...f]), F(
1756
+ "div",
1757
+ {
1758
+ class: "flex gap-8 flex-nowrap",
1759
+ style: {
1760
+ minWidth: `${120 * f.length}px`
1761
+ }
1762
+ },
1763
+ f
1764
+ );
1765
+ }
1766
+ }
1767
+ ];
1768
+ }), je = P(() => ve.value.map((u) => u.size ?? 0).reduce((u, a) => u + a)), we = q(""), Ie = P(() => {
1769
+ var p, r;
1770
+ const u = ((r = (p = e.draft) == null ? void 0 : p.negativeStockItems) == null ? void 0 : r.reduce(
1771
+ (i, f) => (i[f.sku._id] = f, i),
1772
+ {}
1773
+ )) ?? {};
1774
+ return z.value.map((i) => {
1775
+ var st, rt, lt, it, ct, ut, dt, mt, ft, pt, vt;
1776
+ const f = (st = J.value.get(i._id)) == null ? void 0 : st[0], b = ((rt = D.value.get(i._id)) == null ? void 0 : rt[0]) ?? oe, B = ((lt = i.defaultCost) == null ? void 0 : lt.costPerUnit) ?? oe, S = Number(H.toFormatString({ value: B })), L = ((ct = (it = i.defaultCost) == null ? void 0 : it.measurement) == null ? void 0 : ct.conversion) ?? {
1777
+ amount: 1,
1778
+ precision: 0
1779
+ }, N = Number(
1780
+ H.toFormatString({ value: L })
1781
+ ), ue = re.value.get(i._id), fe = ue ? Number(H.toFormatString({ value: ue })) : 0, Ae = O.value.get(i._id), T = {};
1782
+ if (E.value.forEach((se) => {
1783
+ const pe = T[se] ?? { amount: 0, precision: 0 }, ge = Ae == null ? void 0 : Ae[se];
1784
+ ge && (T[se] = Zt(pe, ge));
1785
+ }), !f) {
1786
+ const se = Number(H.toFormatString({ value: b })), pe = se - 0, ge = pe * S / N, Me = 0, Vt = se * S / N;
1787
+ return {
1788
+ id: i._id,
1789
+ code: i.code,
1790
+ name: i.name,
1791
+ costUnit: ((dt = (ut = i.defaultCost) == null ? void 0 : ut.measurement) == null ? void 0 : dt.abbrev) ?? null,
1792
+ baseUnit: i.unit.abbrev,
1793
+ baseUnitAmount: 0,
1794
+ systemBalance: se,
1795
+ physicalBalance: 0,
1796
+ adjustedAmount: -se,
1797
+ adjustedDiffPercentage: -100,
1798
+ isTemplateItem: !u[i._id],
1799
+ costPerUnit: S,
1800
+ opening: fe,
1801
+ varianceQty: pe,
1802
+ varianceInCost: ge,
1803
+ stockTakeValue: Me,
1804
+ systemValue: Vt,
1805
+ adjustmentAmounts: T
1806
+ };
1807
+ }
1808
+ const ae = $t(f), le = (ft = (mt = _.value) == null ? void 0 : mt.find(
1809
+ (se) => se.id === i._id
1810
+ )) == null ? void 0 : ft.balance, ye = wt(
1811
+ le ?? ae,
1812
+ b
1813
+ ), Se = b.amount === 0 ? null : St(ye, {
1814
+ ...b,
1815
+ amount: Math.abs(b.amount)
1816
+ }), Pe = Se ? tt(Se, w) : null, qe = Number(H.toFormatString({ value: b })), Ge = Number(H.toFormatString({ value: ae })), ot = qe - Ge, It = ot * S / N, Ut = Ge * S / N, Rt = qe * S / N;
1817
+ return {
1818
+ id: i._id,
1819
+ code: i.code,
1820
+ name: i.name,
1821
+ costUnit: ((vt = (pt = i.defaultCost) == null ? void 0 : pt.measurement) == null ? void 0 : vt.abbrev) ?? null,
1822
+ baseUnit: i.unit.abbrev,
1823
+ baseUnitAmount: Number(H.toFormatString({ value: f.baseAmount })),
1824
+ ...f.measurementsAmounts.filter((se) => {
1825
+ var pe, ge, Me;
1826
+ return (Me = (ge = (pe = te.value) == null ? void 0 : pe.get(i._id)) == null ? void 0 : ge[0]) == null ? void 0 : Me.includes(se.measurement.id);
1827
+ }).reduce((se, pe, ge) => (se[`measurementAbbrev${ge}`] = `(${pe.measurement.abbrev}) × ${H.toFormatString({ value: pe.measurement.conversion })}`, se[`measurementAmount${ge}`] = Number(H.toFormatString({ value: pe.amount })), se), {}),
1828
+ systemBalance: qe,
1829
+ physicalBalance: Ge,
1830
+ adjustedAmount: Number(H.toFormatString({ value: ye })),
1831
+ adjustedDiffPercentage: Pe ? Number(
1832
+ H.toFormatString({
1833
+ value: Ft(Pe, 2)
1834
+ })
1835
+ ) : null,
1836
+ isTemplateItem: !u[i._id],
1837
+ costPerUnit: S,
1838
+ opening: fe,
1839
+ varianceQty: ot,
1840
+ varianceInCost: It,
1841
+ stockTakeValue: Ut,
1842
+ systemValue: Rt,
1843
+ adjustmentAmounts: T
1844
+ };
1845
+ }).filter((i) => !!(i.isTemplateItem && l.value.templateItem || !i.isTemplateItem && l.value.nonTemplateItem));
1846
+ }), Ue = P(() => {
1847
+ var a, p, r, i, f;
1848
+ if (!e.draft) return [];
1849
+ const u = e.draft.approvedAt ? {
1850
+ action: `Approve at ${xe(e.draft.approvedAt)}`,
1851
+ // actionAt: props.draft.approvedAt,
1852
+ actionBy: e.draft.approvedBy,
1853
+ remark: e.draft.approveRemark
1854
+ } : (a = e.draft.rejectionHistory) == null ? void 0 : a.computeFirst((b) => ({
1855
+ action: `Reject at ${xe(b.rejectedAt)}`,
1856
+ // actionAt: e.rejectedAt,
1857
+ actionBy: b.rejectedBy,
1858
+ remark: b.rejectRemark
1859
+ }));
1860
+ return [
1861
+ {
1862
+ label: "Location",
1863
+ value: ((p = C._currentLocation) == null ? void 0 : p.name) ?? "N/A"
1864
+ },
1865
+ {
1866
+ label: "Created at",
1867
+ value: xe(e.draft.createdAt)
1868
+ },
1869
+ {
1870
+ label: "Created by",
1871
+ value: e.draft.createdBy.name
1872
+ },
1873
+ {
1874
+ label: "Updated at",
1875
+ value: xe(e.draft.updatedAt)
1876
+ },
1877
+ {
1878
+ label: "Updated by",
1879
+ value: e.draft.updatedBy.name
1880
+ },
1881
+ {
1882
+ label: "Effective at",
1883
+ value: xe(e.draft.effectiveAt ?? Ee((r = e.draft) == null ? void 0 : r._id))
1884
+ },
1885
+ {
1886
+ label: "Using template",
1887
+ value: ((i = e.draft.usingTemplates.find((b) => b)) == null ? void 0 : i.name) ?? "None"
1888
+ },
1889
+ e.draft.remark ? {
1890
+ label: "Remark",
1891
+ value: e.draft.remark
1892
+ } : null,
1893
+ u ? {
1894
+ label: "Last action",
1895
+ value: u.action
1896
+ } : null,
1897
+ u && u.actionBy ? {
1898
+ label: "Last action by",
1899
+ value: (f = u.actionBy) == null ? void 0 : f.name
1900
+ } : null,
1901
+ u && u.remark ? {
1902
+ label: "Action remark",
1903
+ value: u.remark
1904
+ } : null
1905
+ ].filter((b) => b).map((b) => b);
1906
+ }), he = [
1907
+ {
1908
+ label: "Overview",
1909
+ value: "overview"
1910
+ },
1911
+ {
1912
+ label: "Action history",
1913
+ value: "history"
1914
+ }
1915
+ ], ke = q(he[0]), _e = P(() => {
1916
+ var r, i, f;
1917
+ const u = ((r = e.draft) == null ? void 0 : r.activityLogs) ?? [], a = ((i = e.draft) == null ? void 0 : i.rejectionHistory) ?? [];
1918
+ for (const b of a)
1919
+ u.find(
1920
+ (S) => `${S.action}_${S.performedAt}` == `${W.enum.rejectDraft}_${b.rejectedAt}`
1921
+ ) || u.push({
1922
+ action: W.enum.rejectDraft,
1923
+ performedAt: b.rejectedAt,
1924
+ performedBy: b.rejectedBy,
1925
+ remark: b.rejectRemark
1926
+ });
1927
+ return (f = e.draft) != null && f.approvedAt && (u.find(
1928
+ (B) => {
1929
+ var S;
1930
+ return `${B.action}_${B.performedAt}` == `${W.enum.approveDraft}_${(S = e.draft) == null ? void 0 : S.approvedAt}`;
1931
+ }
1932
+ ) || u.push({
1933
+ action: W.enum.approveDraft,
1934
+ performedAt: e.draft.approvedAt,
1935
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
1936
+ remark: e.draft.approveRemark
1937
+ })), u.sort((b, B) => new Date(B.performedAt).getTime() - new Date(b.performedAt).getTime()).map(
1938
+ (b) => ({
1939
+ header: ze(b.action),
1940
+ date: xe(b.performedAt),
1941
+ info: [
1942
+ {
1943
+ label: "Performed by",
1944
+ values: [b.performedBy.name]
1945
+ },
1946
+ {
1947
+ label: "Remark",
1948
+ values: [b.remark ?? ""]
1949
+ }
1950
+ ]
1951
+ })
1952
+ );
1953
+ }), Re = q(!1), Ve = q(!1), nt = P(() => {
1954
+ var u;
1955
+ return ((u = e.draft) == null ? void 0 : u.status) !== De.enum.DRAFT ? "Status is not draft." : null;
1956
+ });
1957
+ function jt() {
1958
+ e.draft && (Ve.value = !0, h.approveDraft(
1959
+ e.draft,
1960
+ () => {
1961
+ Ve.value = !1, Re.value = !1, g("submitted");
1962
+ },
1963
+ () => {
1964
+ Ve.value = !1;
1965
+ }
1966
+ ));
1967
+ }
1968
+ return (u, a) => {
1969
+ const p = K("FmButtonGroup"), r = K("FmMenuDivider"), i = K("FmCard"), f = K("FmButton"), b = K("FmCircularProgress"), B = K("FmChip"), S = K("FmTextField"), L = K("FmIcon"), N = K("FmTable"), ue = K("FmSpacer"), fe = K("FmTooltip"), Ae = K("FmSideSheet");
1970
+ return x(), V(ie, null, [
1971
+ k(Ae, {
1972
+ "dismiss-away": "",
1973
+ "max-width": 9999,
1974
+ "model-value": v(y),
1975
+ "onUpdate:modelValue": a[9] || (a[9] = (T) => yt(y) ? y.value = T : null),
1976
+ header: "Closing details"
1977
+ }, {
1978
+ "side-sheet-footer": Y(() => {
1979
+ var T, ae, le, ye;
1980
+ return [
1981
+ n("div", xn, [
1982
+ ((T = e.draft) == null ? void 0 : T.status) === v(De).enum.DRAFT ? (x(), V(ie, { key: 0 }, [
1983
+ nt.value ? (x(), de(fe, {
1984
+ key: 0,
1985
+ "z-index": 51,
1986
+ placement: "right"
1987
+ }, {
1988
+ content: Y(() => [
1989
+ ce(X(nt.value), 1)
1990
+ ]),
1991
+ default: Y(() => [
1992
+ k(f, {
1993
+ disabled: "",
1994
+ key: "approve key",
1995
+ label: "Approve"
1996
+ })
1997
+ ]),
1998
+ _: 1
1999
+ })) : (x(), de(f, {
2000
+ key: "approve key",
2001
+ label: "Approve",
2002
+ onClick: a[5] || (a[5] = (Se) => Re.value = !0)
2003
+ }))
2004
+ ], 64)) : ne("", !0),
2005
+ ((ae = e.draft) == null ? void 0 : ae.status) === v(De).enum.DRAFT ? (x(), de(f, {
2006
+ key: 1,
2007
+ label: "Reject",
2008
+ variant: "destructive",
2009
+ onClick: a[6] || (a[6] = () => e.draft && v(h).rejectDraft(e.draft, () => g("submitted")))
2010
+ })) : ne("", !0),
2011
+ (le = e.draft) != null && le.approvedAt && ((ye = e.draft) == null ? void 0 : ye.status) !== v(De).enum.COMPLETED ? (x(), de(Ze, { key: 2 }, {
2012
+ default: Y(() => [
2013
+ k(f, {
2014
+ label: "Sync",
2015
+ loading: U.value,
2016
+ onClick: a[7] || (a[7] = () => {
2017
+ e.draft && (U.value = !0, v(h).syncDraft(e.draft, () => {
2018
+ U.value = !1, g("submitted");
2019
+ }));
2020
+ })
2021
+ }, null, 8, ["loading"])
2022
+ ]),
2023
+ _: 1
2024
+ })) : ne("", !0),
2025
+ k(f, {
2026
+ label: "Close",
2027
+ variant: "tertiary",
2028
+ onClick: a[8] || (a[8] = (Se) => y.value = !1)
2029
+ })
2030
+ ])
2031
+ ];
2032
+ }),
2033
+ default: Y(() => [
2034
+ n("div", Ea, [
2035
+ n("div", null, [
2036
+ k(p, {
2037
+ items: he,
2038
+ modelValue: ke.value,
2039
+ "onUpdate:modelValue": a[0] || (a[0] = (T) => ke.value = T)
2040
+ }, null, 8, ["modelValue"])
2041
+ ]),
2042
+ ke.value.value === "overview" ? (x(), V(ie, { key: 0 }, [
2043
+ k(i, {
2044
+ variant: "outlined",
2045
+ class: "flex flex-col gap-8 px-12 py-16"
2046
+ }, {
2047
+ default: Y(() => {
2048
+ var T, ae;
2049
+ return [
2050
+ n("div", za, [
2051
+ a[11] || (a[11] = n("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
2052
+ n("div", Ha, [
2053
+ n("div", {
2054
+ class: $e(["fm-status-badge", v(He)(((T = u.draft) == null ? void 0 : T.status) ?? "DRAFT")])
2055
+ }, X(v(ze)(((ae = u.draft) == null ? void 0 : ae.status) ?? "")), 3)
2056
+ ])
2057
+ ]),
2058
+ k(r),
2059
+ n("div", Oa, [
2060
+ (x(!0), V(ie, null, Ce(Ue.value, (le, ye) => (x(), V("div", {
2061
+ class: "flex flex-col gap-4",
2062
+ key: ye
2063
+ }, [
2064
+ n("div", Ka, [
2065
+ n("div", Ya, X(le.label), 1)
2066
+ ]),
2067
+ n("div", Qa, X(le.value), 1)
2068
+ ]))), 128))
2069
+ ])
2070
+ ];
2071
+ }),
2072
+ _: 1
2073
+ }),
2074
+ n("div", qa, [
2075
+ n("div", Ga, [
2076
+ a[12] || (a[12] = n("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
2077
+ m.value ? ne("", !0) : (x(), V("div", Wa, [
2078
+ k(Ze, null, {
2079
+ default: Y(() => [
2080
+ k(f, {
2081
+ label: "Invalidate Draft Cache",
2082
+ "prepend-icon": "refresh",
2083
+ variant: "secondary",
2084
+ "text-color": "primary",
2085
+ "bg-color": "transparent",
2086
+ "border-color": "primary",
2087
+ loading: M.value,
2088
+ onClick: A
2089
+ }, null, 8, ["loading"])
2090
+ ]),
2091
+ _: 1
2092
+ }),
2093
+ k(f, {
2094
+ label: "Export data",
2095
+ "prepend-icon": "download",
2096
+ variant: "secondary",
2097
+ "text-color": "primary",
2098
+ "bg-color": "transparent",
2099
+ "border-color": "primary",
2100
+ onClick: a[1] || (a[1] = (T) => u.draft ? v(h).exportDraft(
2101
+ u.draft,
2102
+ R.value,
2103
+ _.value
2104
+ ) : null)
2105
+ })
2106
+ ]))
2107
+ ]),
2108
+ m.value ? (x(), V("div", Za, [
2109
+ a[14] || (a[14] = n("div", { class: "h-80" }, null, -1)),
2110
+ n("div", Ja, [
2111
+ n("div", null, [
2112
+ k(b, { size: "md" })
2113
+ ]),
2114
+ a[13] || (a[13] = n("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
2115
+ ]),
2116
+ a[15] || (a[15] = n("div", { class: "h-80" }, null, -1))
2117
+ ])) : (x(), V(ie, { key: 1 }, [
2118
+ n("div", Xa, [
2119
+ n("div", en, [
2120
+ k(B, {
2121
+ label: "Template Item(s)",
2122
+ selected: l.value.templateItem,
2123
+ onClick: a[2] || (a[2] = (T) => l.value.templateItem = !l.value.templateItem)
2124
+ }, null, 8, ["selected"]),
2125
+ k(B, {
2126
+ label: "Non-template Item(s)",
2127
+ selected: l.value.nonTemplateItem,
2128
+ onClick: a[3] || (a[3] = (T) => l.value.nonTemplateItem = !l.value.nonTemplateItem)
2129
+ }, null, 8, ["selected"])
2130
+ ]),
2131
+ k(S, {
2132
+ modelValue: we.value,
2133
+ "onUpdate:modelValue": a[4] || (a[4] = (T) => we.value = T),
2134
+ placeholder: "Filter items"
2135
+ }, null, 8, ["modelValue"])
2136
+ ]),
2137
+ v(t).skuTags.size ? (x(), V("div", tn, [
2138
+ (x(!0), V(ie, null, Ce(v(t).skuTags.keys(), (T) => (x(), de(B, {
2139
+ key: `${T}`,
2140
+ label: `${T}`,
2141
+ selectable: "",
2142
+ selected: I[`${T}`],
2143
+ onClick: (ae) => I[`${T}`] = !I[`${T}`]
2144
+ }, {
2145
+ default: Y(() => [
2146
+ I[`${T}`] ? (x(), de(L, {
2147
+ key: 0,
2148
+ name: "check",
2149
+ class: "text-white",
2150
+ size: "sm"
2151
+ })) : ne("", !0),
2152
+ n("span", {
2153
+ class: $e([
2154
+ "",
2155
+ {
2156
+ "text-white fm-typo-en-body-md-600": I[`${T}`],
2157
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !I[`${T}`]
2158
+ }
2159
+ ])
2160
+ }, X(T), 3)
2161
+ ]),
2162
+ _: 2
2163
+ }, 1032, ["label", "selected", "onClick"]))), 128))
2164
+ ])) : ne("", !0),
2165
+ n("div", an, [
2166
+ n("div", {
2167
+ style: bt({ height: "600px", minWidth: `${je.value}px` })
2168
+ }, [
2169
+ k(N, {
2170
+ "column-defs": ve.value,
2171
+ "row-data": Ie.value,
2172
+ "search-value": we.value
2173
+ }, null, 8, ["column-defs", "row-data", "search-value"])
2174
+ ], 4)
2175
+ ])
2176
+ ], 64))
2177
+ ])
2178
+ ], 64)) : ne("", !0),
2179
+ ke.value.value === "history" ? (x(), V("div", nn, [
2180
+ _e.value.length ? (x(), V("div", rn, [
2181
+ (x(!0), V(ie, null, Ce(_e.value, (T, ae) => (x(), V(ie, { key: ae }, [
2182
+ n("div", ln, [
2183
+ n("div", cn, [
2184
+ n("div", un, [
2185
+ n("div", {
2186
+ class: $e([
2187
+ {
2188
+ "bg-fm-color-primary": ae !== 0,
2189
+ "bg-white": ae === 0
2190
+ },
2191
+ "w-[2px] h-full"
2192
+ ])
2193
+ }, null, 2)
2194
+ ]),
2195
+ a[18] || (a[18] = n("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
2196
+ n("div", dn, [
2197
+ n("div", {
2198
+ class: $e([
2199
+ {
2200
+ "bg-fm-color-primary": ae < _e.value.length - 1,
2201
+ "bg-white": ae >= _e.value.length - 1
2202
+ },
2203
+ "w-[2px] h-full"
2204
+ ])
2205
+ }, null, 2)
2206
+ ])
2207
+ ]),
2208
+ n("div", mn, [
2209
+ n("div", fn, X(T.header), 1),
2210
+ n("div", pn, X(T.date), 1)
2211
+ ])
2212
+ ]),
2213
+ n("div", vn, [
2214
+ n("div", gn, [
2215
+ n("div", yn, [
2216
+ n("div", {
2217
+ class: $e([
2218
+ {
2219
+ "bg-fm-color-primary": ae < _e.value.length - 1,
2220
+ "bg-white": ae >= _e.value.length - 1
2221
+ },
2222
+ "w-[2px] h-full"
2223
+ ])
2224
+ }, null, 2)
2225
+ ])
2226
+ ]),
2227
+ n("div", bn, [
2228
+ k(i, {
2229
+ variant: "outlined",
2230
+ class: "py-12 px-16"
2231
+ }, {
2232
+ default: Y(() => [
2233
+ n("div", hn, [
2234
+ (x(!0), V(ie, null, Ce(T.info, (le, ye) => (x(), V("div", {
2235
+ key: ye,
2236
+ class: "flex flex-col gap-4"
2237
+ }, [
2238
+ n("div", kn, X(le == null ? void 0 : le.label), 1),
2239
+ n("div", _n, [
2240
+ (x(!0), V(ie, null, Ce(le == null ? void 0 : le.values, (Se, Pe) => (x(), V("div", {
2241
+ key: Pe,
2242
+ class: "fm-typo-en-body-lg-600"
2243
+ }, X(Se), 1))), 128))
2244
+ ])
2245
+ ]))), 128))
2246
+ ])
2247
+ ]),
2248
+ _: 2
2249
+ }, 1024)
2250
+ ])
2251
+ ])
2252
+ ], 64))), 128))
2253
+ ])) : (x(), V("div", on, [
2254
+ k(ue),
2255
+ n("div", null, [
2256
+ n("img", {
2257
+ src: v(oa),
2258
+ alt: "List is empty"
2259
+ }, null, 8, sn)
2260
+ ]),
2261
+ a[16] || (a[16] = n("div", { class: "fm-typo-en-body-lg-600" }, X("No records found"), -1)),
2262
+ a[17] || (a[17] = n("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, X("You can track approval and rejection history here"), -1)),
2263
+ k(ue),
2264
+ k(ue)
2265
+ ]))
2266
+ ])) : ne("", !0)
2267
+ ])
2268
+ ]),
2269
+ _: 1
2270
+ }, 8, ["model-value"]),
2271
+ v(y) && e.draft ? (x(), de(Na, {
2272
+ key: 0,
2273
+ show: Re.value,
2274
+ "onUpdate:show": a[10] || (a[10] = (T) => Re.value = T),
2275
+ refreshing: M.value,
2276
+ approving: Ve.value,
2277
+ draft: e.draft,
2278
+ onRefresh: me,
2279
+ onApprove: jt
2280
+ }, null, 8, ["show", "refreshing", "approving", "draft"])) : ne("", !0)
2281
+ ], 64);
2282
+ };
2283
+ }
2284
+ }), wn = { class: "flex-1 flex flex-col gap-8" }, Sn = { class: "flex flex-col" }, Fn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Cn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, $n = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Bn = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Wn = /* @__PURE__ */ Te({
2285
+ __name: "ClosingDraftView",
2286
+ setup(c) {
2287
+ const { t: o } = kt(), { viewDraft: e } = Ke(), { viewClosingDraftProps: d, viewClosingDraftShow: h } = Qt(Ke()), y = Ye(), m = Da(), M = Nt(), { breakpoints: U } = Ot();
2288
+ y.watchLocation(m.fetchDrafts);
2289
+ const R = P(() => m.loading), _ = q(""), E = P(() => U.value.xs || U.value.sm), j = P(() => E.value ? 10 : 20);
2290
+ function G(C) {
2291
+ switch (C) {
2292
+ case "refresh":
2293
+ return m.fetchDrafts();
2294
+ }
2295
+ }
2296
+ function s(C) {
2297
+ return C;
2298
+ }
2299
+ const t = P(() => E.value ? [
2300
+ {
2301
+ label: o("inventory.common.refresh"),
2302
+ value: "refresh",
2303
+ isPrimary: !1
2304
+ }
2305
+ ] : [
2306
+ {
2307
+ label: o("inventory.common.refresh"),
2308
+ value: "refresh",
2309
+ isPrimary: !1
2310
+ }
2311
+ ]);
2312
+ return (C, I) => {
2313
+ const Z = K("FmTable");
2314
+ return x(), V(ie, null, [
2315
+ k(Et, {
2316
+ title: v(o)("inventory.closing.draft.title"),
2317
+ actions: t.value,
2318
+ "onClick:action": G
2319
+ }, {
2320
+ default: Y(() => [
2321
+ n("div", {
2322
+ class: $e([
2323
+ "flex flex-col gap-8 max-h-full",
2324
+ {
2325
+ "p-0": E.value,
2326
+ "px-24 ": !E.value
2327
+ }
2328
+ ])
2329
+ }, [
2330
+ k(na, {
2331
+ "change-location": "",
2332
+ searchable: "",
2333
+ search: _.value,
2334
+ "onUpdate:search": I[0] || (I[0] = (g) => _.value = g)
2335
+ }, null, 8, ["search"]),
2336
+ k(Z, {
2337
+ style: bt(v(M).tableHeight),
2338
+ "column-defs": v(m).columnDefs,
2339
+ "row-data": v(m).drafts,
2340
+ "search-value": _.value,
2341
+ loading: R.value,
2342
+ onRowClick: I[1] || (I[1] = (g) => v(e)(g.original)),
2343
+ "page-size": j.value
2344
+ }, {
2345
+ "list-row": Y((g) => [
2346
+ k(ta, {
2347
+ row: g,
2348
+ onRowClick: (l) => v(e)(l)
2349
+ }, {
2350
+ default: Y((l) => {
2351
+ var $, z, te, oe, w, ee, me, A, D, J, O, re, Q, ve, je, we, Ie, Ue, he, ke;
2352
+ return [
2353
+ n("div", wn, [
2354
+ n("div", Sn, [
2355
+ n("div", Fn, [
2356
+ k(v(Le), {
2357
+ render: (te = (z = ($ = l._id) == null ? void 0 : $.column) == null ? void 0 : z.columnDef) == null ? void 0 : te.cell,
2358
+ props: (w = (oe = l._id) == null ? void 0 : oe.getContext) == null ? void 0 : w.call(oe)
2359
+ }, null, 8, ["render", "props"])
2360
+ ]),
2361
+ n("div", Cn, [
2362
+ k(v(Le), {
2363
+ render: (A = (me = (ee = l.name) == null ? void 0 : ee.column) == null ? void 0 : me.columnDef) == null ? void 0 : A.cell,
2364
+ props: (J = (D = l.name) == null ? void 0 : D.getContext) == null ? void 0 : J.call(D)
2365
+ }, null, 8, ["render", "props"])
2366
+ ]),
2367
+ n("div", $n, X([
2368
+ ...g.original.items.slice(0, 3).map((_e) => _e.sku.name),
2369
+ ...g.original.items.length >= 3 ? [`and ${g.original.items.length - 3} more items`] : []
2370
+ ].join(", ")), 1),
2371
+ n("div", Bn, [
2372
+ k(v(Le), {
2373
+ render: (Q = (re = (O = l.ref) == null ? void 0 : O.column) == null ? void 0 : re.columnDef) == null ? void 0 : Q.cell,
2374
+ props: (je = (ve = l.ref) == null ? void 0 : ve.getContext) == null ? void 0 : je.call(ve)
2375
+ }, null, 8, ["render", "props"])
2376
+ ])
2377
+ ]),
2378
+ n("div", null, [
2379
+ k(v(Le), {
2380
+ render: (Ue = (Ie = (we = l.status) == null ? void 0 : we.column) == null ? void 0 : Ie.columnDef) == null ? void 0 : Ue.cell,
2381
+ props: (ke = (he = l.status) == null ? void 0 : he.getContext) == null ? void 0 : ke.call(he)
2382
+ }, null, 8, ["render", "props"])
2383
+ ])
2384
+ ])
2385
+ ];
2386
+ }),
2387
+ _: 2
2388
+ }, 1032, ["row", "onRowClick"])
2389
+ ]),
2390
+ _: 1
2391
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
2392
+ ], 2)
2393
+ ]),
2394
+ _: 1
2395
+ }, 8, ["title", "actions"]),
2396
+ (x(), de(Mt, { to: "body" }, [
2397
+ k(An, Lt(v(d), {
2398
+ show: v(h),
2399
+ "onUpdate:show": I[2] || (I[2] = (g) => yt(h) ? h.value = g : null),
2400
+ onSubmitted: I[3] || (I[3] = () => (h.value = !1, v(m).fetchDrafts())),
2401
+ onRefresh: I[4] || (I[4] = (g) => v(m).updateDraftRef(g))
2402
+ }), null, 16, ["show"])
2403
+ ]))
2404
+ ], 64);
2405
+ };
2406
+ }
2407
+ });
2408
+ export {
2409
+ Wn as default
2410
+ };