@feedmepos/mf-inventory-portal 1.2.45 → 1.2.46-dev.2

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