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