@feedmepos/mf-inventory-portal 1.4.2 → 1.4.4-dev.1

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 (96) hide show
  1. package/dist/App-_rrlFpzI.js +309 -0
  2. package/dist/{ApprovalView-B6WmrP3R.js → ApprovalView-BA13wbQ-.js} +7 -7
  3. package/dist/{BindingsDialog-DAG2toHR.js → BindingsDialog-DMzMv881.js} +2 -2
  4. package/dist/{BindingsPicker-CPbNuwFq.js → BindingsPicker-BGxYZDn_.js} +2 -2
  5. package/dist/{BindingsTable-Hkkel0vq.js → BindingsTable-D7I6KyIQ.js} +3 -3
  6. package/dist/ClosingDraftView-osqh-QJ1.js +3649 -0
  7. package/dist/{ClosingHistoryView-D7GacAqj.js → ClosingHistoryView-DQoNfb5z.js} +5 -5
  8. package/dist/{ClosingTemplateView-DqpbjHK2.js → ClosingTemplateView-Ckq2Veyq.js} +14 -14
  9. package/dist/{DefaultView-BSm6fE5w.js → DefaultView-BYIk34PR.js} +2 -2
  10. package/dist/{DeliveryOrderPrintPreview-DFj56iJk.js → DeliveryOrderPrintPreview-BgHL-gvt.js} +2 -2
  11. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CaVUl6v3.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-yqA2fgtH.js} +2 -2
  12. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-FunJ5ZX5.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-Bvma2A4K.js} +2 -2
  13. package/dist/{FmMultiselectDialog-DpekFj8a.js → FmMultiselectDialog-BmTCvmlw.js} +2 -2
  14. package/dist/{FmMultiselectDialog-BE2Tqm4H.js → FmMultiselectDialog-VPcV-FQV.js} +1 -1
  15. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-Bt_kCIFn.js → FmUnitInput.vue_vue_type_script_setup_true_lang-7dkCTYcT.js} +4 -4
  16. package/dist/{ImportView-CAcUO9Pv.js → ImportView-gzF9CWtM.js} +6 -6
  17. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-0Abq7FDN.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-BJKxFdjv.js} +1 -1
  18. package/dist/{IngredientGroupView-CeUfykez.js → IngredientGroupView-DkoVLdIi.js} +5 -5
  19. package/dist/{IngredientsView-Cdhgw3Tw.js → IngredientsView-NBpaVLDo.js} +15 -15
  20. package/dist/{IntegrationExplorerView-BioiObpU.js → IntegrationExplorerView-D4P5Sxcm.js} +5 -5
  21. package/dist/{IntegrationView-BHjOvMpX.js → IntegrationView-B5YN8TEE.js} +13 -13
  22. package/dist/{InventoryBindingForm-D892WEqV.js → InventoryBindingForm-B7VMypYy.js} +1 -1
  23. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-BMfmKcz8.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DziCetjY.js} +5 -5
  24. package/dist/{InventoryBindingSummary-DOGWF0fo.js → InventoryBindingSummary-B9Vy49tr.js} +1 -1
  25. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B-dhMJ0F.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DXbiPSqB.js} +1 -1
  26. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-CKuIWTXZ.js → PremiumBadge.vue_vue_type_script_setup_true_lang-7ikbnzXX.js} +1 -1
  27. package/dist/{PublishView-Dh6OiaG1.js → PublishView-BwmWveBB.js} +3 -3
  28. package/dist/{PurchaseOrderPrintPreview-Cpme08gm.js → PurchaseOrderPrintPreview-kajF_P0m.js} +2 -2
  29. package/dist/{ReceiveRequestView-Dldwu3-H.js → ReceiveRequestView-DHYEENEf.js} +10550 -10507
  30. package/dist/{RecipeView-gkZuFdCP.js → RecipeView-BHwVXfLJ.js} +17 -17
  31. package/dist/{SettingsView-wOy_OATI.js → SettingsView-AdpIDPVs.js} +4 -4
  32. package/dist/{StockView-DeLcyQrC.js → StockView-C5AtoijI.js} +19 -19
  33. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-C2Jax3tb.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-B3az_NVO.js} +1 -1
  34. package/dist/{SupplierView-Bf2AW8JH.js → SupplierView-D7Nr2RxT.js} +12 -12
  35. package/dist/{SurchargeView-CJtg87ol.js → SurchargeView-vJimp1Cv.js} +6 -6
  36. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-Bfzqxalj.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-CinFL3QM.js} +2 -2
  37. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CEz3Yc2Z.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-D2SvRBN6.js} +1 -1
  38. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-DlEjTd8E.js +4353 -0
  39. package/dist/{TransferTemplateView-DpWFExzQ.js → TransferTemplateView-C6RmjS-v.js} +18 -18
  40. package/dist/{UnitCostHistoryView-PEexDaAO.js → UnitCostHistoryView-aC4aPr3L.js} +4 -4
  41. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-i8HZEphD.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-CuP7FMd1.js} +4 -4
  42. package/dist/{UnitView-BPyyMHKE.js → UnitView-BCGMlHCV.js} +7 -7
  43. package/dist/{WarehouseView-BmCech19.js → WarehouseView-O3gc_PiU.js} +5 -5
  44. package/dist/{WastageTemplateView-DJOBAWKd.js → WastageTemplateView-H9PA6ryl.js} +14 -14
  45. package/dist/api/purchase-order.d.ts +1 -0
  46. package/dist/api/sse.d.ts +3 -15
  47. package/dist/{app-D4P-koOR.js → app-CItiJtFw.js} +13 -11
  48. package/dist/app.js +1 -1
  49. package/dist/{closing-template-CCvXzoLm.js → closing-template-Cwj3O7Lm.js} +1 -1
  50. package/dist/composable/useSseClient.d.ts +5 -4
  51. package/dist/{date2-XHYHbI0K.js → date2-D00juOhc.js} +1 -1
  52. package/dist/{dayjs.min-pkE_kmHZ.js → dayjs.min-DmEufB_X.js} +1 -1
  53. package/dist/{decimal-CQ7SlCe0.js → decimal-Cfx4iNIN.js} +2 -2
  54. package/dist/{defineDeepModel-CZDkmNol.js → defineDeepModel-Dn4pcA76.js} +1 -1
  55. package/dist/{duplicate-template-BQ0bF_MO.js → duplicate-template-3GCMrDdJ.js} +1 -1
  56. package/dist/{export-CDIp6ydU.js → export-Taxbki8U.js} +2 -2
  57. package/dist/{feature-C4zPjstX.js → feature-CWFT4m6D.js} +426 -400
  58. package/dist/{format-time-from-id-D_USijTz.js → format-time-from-id-DBU5YJL6.js} +1 -1
  59. package/dist/{format-unit-display-CF6-yU7v.js → format-unit-display-Bcg7Sa60.js} +11 -11
  60. package/dist/{import-export.helper-iVXMr9yw.js → import-export.helper-DDM-pvFO.js} +6 -6
  61. package/dist/{index-BIG8c4oA.js → index-BMhosF1x.js} +3 -3
  62. package/dist/{index-EoaZ_eFV.js → index-DHnHIq4-.js} +1 -1
  63. package/dist/{index-CTNLpvtM.js → index-DK0BNrfa.js} +1 -1
  64. package/dist/{inventory-core-dart.default-D6cCA8tk.js → inventory-core-dart.default-B8aW6vKZ.js} +1 -1
  65. package/dist/{lodash-DR7t9CsC.js → lodash-raCw-gUe.js} +1 -1
  66. package/dist/{lz-string-DgqLqrsO.js → lz-string-eBAqN_g9.js} +1 -1
  67. package/dist/{netsuite-ByBZj6uf.js → netsuite-uRj2P-EH.js} +5 -6
  68. package/dist/{number-f4J4YlZT.js → number-C9o5tPfP.js} +3 -3
  69. package/dist/{predefined-templates-BlmLhRsh.js → predefined-templates-YPJMW8GJ.js} +1 -1
  70. package/dist/{purchase-order-template-BS94QDpg.js → purchase-order-template-B6aV2vdS.js} +1 -1
  71. package/dist/{recalculationUtils-D0wl-tgM.js → recalculationUtils-BiZ-pU6y.js} +1 -1
  72. package/dist/{rules-Cpi5Vduo.js → rules-01UCJome.js} +2 -2
  73. package/dist/{stock-BynB5KIH.js → stock-DTp9AhdZ.js} +1 -1
  74. package/dist/{stock-GYUDrBUF.js → stock-SuApOj2U.js} +3 -3
  75. package/dist/stores/feature.d.ts +15 -0
  76. package/dist/{supplier-BDpzWHvm.js → supplier-D60bDAuZ.js} +2 -2
  77. package/dist/{surcharge-ztZ3mUE2.js → surcharge-BWwSWZ1U.js} +1 -1
  78. package/dist/tsconfig.app.tsbuildinfo +1 -1
  79. package/dist/{use-ingredient-select-dialog-xx_W7OyU.js → use-ingredient-select-dialog-B4zci6JI.js} +2 -2
  80. package/dist/{use-inventory-binding-dialog-B_OV8CCL.js → use-inventory-binding-dialog-CgSz72ZS.js} +2 -2
  81. package/dist/{use-template-enabled-locations-ByOi4t2R.js → use-template-enabled-locations-DVLHfYM9.js} +2 -2
  82. package/dist/{use-transfer-locations-BOR-wq8s.js → use-transfer-locations-POSn3UDi.js} +2 -2
  83. package/dist/{useHrmPermission-BtXw89bp.js → useHrmPermission-B9ffPr7i.js} +1 -1
  84. package/dist/{useNavigationMenu-Ds6IBfYX.js → useNavigationMenu-dJYOEiud.js} +2 -2
  85. package/dist/views/receive-request/components/delivery-order-form/CreateFormProps.d.ts +2 -0
  86. package/dist/views/receive-request/components/delivery-order-form/EditFormProps.d.ts +1 -0
  87. package/dist/views/receive-request/helper/extra-items.d.ts +10 -0
  88. package/dist/views/receive-request/helper/extra-items.spec.d.ts +1 -0
  89. package/dist/{vue-i18n-C35dl24s.js → vue-i18n-CqFS0F9S.js} +477 -477
  90. package/dist/{xlsx-CzLrFB_A.js → xlsx-BY0_-lpm.js} +1 -1
  91. package/dist/{xlsx.util-osyDkxYO.js → xlsx.util-DR3_mTtm.js} +3 -3
  92. package/package.json +4 -4
  93. package/dist/App-D8p5pMar.js +0 -310
  94. package/dist/ClosingDraftView-JCtS2MZa.js +0 -3183
  95. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CcpH12aM.js +0 -3874
  96. package/dist/useSseClient-q5d7Qjrq.js +0 -502
@@ -0,0 +1,3649 @@
1
+ import { defineComponent as Le, ref as Y, computed as V, onMounted as Lt, resolveComponent as G, openBlock as x, createElementBlock as M, Fragment as ue, createTextVNode as pe, createBlock as ne, withCtx as Z, createElementVNode as m, toDisplayString as W, unref as p, createVNode as B, createCommentVNode as q, h as T, watch as Qe, renderList as Se, onUnmounted as Un, reactive as cn, isRef as Ot, normalizeClass as Be, normalizeStyle as gn, createSlots as Pn, Teleport as Vn, mergeProps as Ln } from "vue";
2
+ import { u as On, _ as zn } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
3
+ import { useCoreStore as zt, useI18n as xt } from "@feedmepos/mf-common";
4
+ import { useSnackbar as rt, useDialog as Wn, components as Ce, useProxiedModel as hn, useBreakpoints as Hn } from "@feedmepos/ui-library";
5
+ import { m as bn, u as lt, L as le, w as te, q as _n, s as Pe, M as Te, B as Ve, c as Yn, a as Wt, j as Kn } from "./app-CItiJtFw.js";
6
+ import { defineStore as wn, storeToRefs as qn } from "pinia";
7
+ import { b as _t, e as kn, f as Gn, a as Fe } from "./date2-D00juOhc.js";
8
+ import { R as Qn } from "./rules-01UCJome.js";
9
+ import { e as Ht, a as Bt, t as xn, c as st, l as Dn, m as Cn, j as Sn, k as An, o as ae } from "./number-C9o5tPfP.js";
10
+ import { b as Zn, d as Jn } from "./xlsx.util-DR3_mTtm.js";
11
+ import { u as Xn } from "./stock-SuApOj2U.js";
12
+ import { u as Dt } from "./stock-DTp9AhdZ.js";
13
+ import { D as un, R as He } from "./row-action.enum-DQ9bJ_uv.js";
14
+ import { c as ea } from "./component-kqxARxvM.js";
15
+ import { f as ta } from "./format-time-from-id-DBU5YJL6.js";
16
+ import { f as na } from "./recalculationUtils-BiZ-pU6y.js";
17
+ import { _ as aa } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-Bvma2A4K.js";
18
+ import { _ as oa } from "./empty-placeholder-B0QU467o.js";
19
+ import { F as It } from "./FmAdminBadge-DjnBAgyv.js";
20
+ import { u as sa } from "./vue-i18n-CqFS0F9S.js";
21
+ import { F as ra } from "./decimal-Cfx4iNIN.js";
22
+ import { r as la, u as gt, w as ia } from "./xlsx-BY0_-lpm.js";
23
+ import { d as ca } from "./dayjs.min-DmEufB_X.js";
24
+ import { F as ua } from "./FmDroppableField-J0xUsOTV.js";
25
+ import { _ as da } from "./FmConfirmationButton.vue_vue_type_script_setup_true_lang-DLrMEGFR.js";
26
+ import { _ as ma, F as yt } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
27
+ const it = bn((t, n) => {
28
+ function e() {
29
+ return lt().currentLocation.dbName;
30
+ }
31
+ return {
32
+ getDbName: e,
33
+ async getDraft(a) {
34
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/${a}`;
35
+ return n.get(s);
36
+ },
37
+ async readDrafts() {
38
+ const a = e(), l = `${t.inventoryBackendUrl}/${a}/closing-draft`;
39
+ return n.get(l);
40
+ },
41
+ async runOperation(a) {
42
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/run-operation`;
43
+ return n.post(s, a);
44
+ },
45
+ async runOperationV1(a) {
46
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/v1/run-operation`;
47
+ return n.post(s, a);
48
+ },
49
+ async sync(a) {
50
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/sync`;
51
+ return n.post(s, a);
52
+ },
53
+ async cloneDraft(a) {
54
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/${a}/clone`;
55
+ return n.post(s, {});
56
+ },
57
+ async createQuickModeDraftWithItems(a) {
58
+ const l = e(), s = `${t.inventoryBackendUrl}/${l}/closing-draft/quick-mode/new-with-items`;
59
+ return n.post(s, a);
60
+ },
61
+ initializeStockSnapshot(a, l) {
62
+ const s = e(), o = `${t.inventoryBackendUrl}/${s}/closing-draft/${encodeURIComponent(a)}/initialize-stock-snapshot`;
63
+ return n.post(o, { effectiveAt: l });
64
+ },
65
+ async getRefreshBalanceStatus(a, l) {
66
+ const s = e(), o = `${t.inventoryBackendUrl}/${s}/closing-draft/${a}/refresh-balance/status?closingDraftRevision=${encodeURIComponent(l)}`;
67
+ return n.get(o);
68
+ }
69
+ };
70
+ }), fa = { class: "fm-typo-en-body-lg-400" }, pa = { class: "fm-typo-en-body-lg-600" }, va = {
71
+ key: 0,
72
+ class: "flex flex-col"
73
+ }, ya = {
74
+ key: 0,
75
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
76
+ }, ga = { class: "flex gap-12 py-8 justify-end w-full" }, Tt = /* @__PURE__ */ Le({
77
+ __name: "ClosingDraftAction",
78
+ props: {
79
+ draft: {},
80
+ action: {},
81
+ onCancel: { type: Function },
82
+ onFinished: { type: Function }
83
+ },
84
+ setup(t) {
85
+ const n = t, e = Y(), a = it(), l = rt(), s = Y(!1), o = Y(null), d = Y(!1), g = V(() => {
86
+ switch (n.action) {
87
+ case le.enum.approveDraft:
88
+ return "Approve";
89
+ case le.enum.rejectDraft:
90
+ return "Reject";
91
+ case le.enum.markAsFailed:
92
+ return "Mark as Failed";
93
+ }
94
+ throw new Error(`Unknown action: ${n.action}`);
95
+ }), _ = V(() => {
96
+ switch (n.action) {
97
+ case le.enum.approveDraft:
98
+ return "primary";
99
+ case le.enum.rejectDraft:
100
+ return "destructive";
101
+ case le.enum.markAsFailed:
102
+ return "destructive";
103
+ }
104
+ throw new Error(`Unknown action: ${n.action}`);
105
+ });
106
+ Lt(() => {
107
+ if (n.draft.effectiveAt)
108
+ o.value = new Date(n.draft.effectiveAt);
109
+ else {
110
+ const S = new Date(n.draft.createdAt);
111
+ S.setHours(23, 59, 59, 999), o.value = S;
112
+ }
113
+ d.value = !0;
114
+ });
115
+ const f = V({
116
+ get() {
117
+ return o.value === null ? "" : _t(o.value);
118
+ },
119
+ set(S) {
120
+ if (S) {
121
+ const u = /* @__PURE__ */ new Date(`${S} ${I.value}`);
122
+ u.setSeconds(59, 999), o.value = u;
123
+ } else
124
+ o.value = null;
125
+ }
126
+ }), I = V({
127
+ get() {
128
+ return o.value === null ? "" : kn(o.value);
129
+ },
130
+ set(S) {
131
+ if (S) {
132
+ const u = /* @__PURE__ */ new Date(`${f.value} ${S}`);
133
+ u.setSeconds(59, 999), o.value = u;
134
+ } else
135
+ o.value = null;
136
+ }
137
+ }), R = V(() => o.value ? o.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
138
+ async function U(S) {
139
+ s.value = !0;
140
+ try {
141
+ S ? await a.runOperationV1({
142
+ _id: n.draft._id,
143
+ _rev: n.draft._rev ?? "",
144
+ action: n.action,
145
+ data: {
146
+ effectiveAt: o.value ? o.value.toISOString() : null,
147
+ remark: e.value
148
+ }
149
+ }).delayed(500) : await a.runOperation({
150
+ _id: n.draft._id,
151
+ _rev: n.draft._rev ?? "",
152
+ action: n.action,
153
+ data: {
154
+ effectiveAt: o.value ? o.value.toISOString() : null,
155
+ remark: e.value
156
+ }
157
+ }).delayed(500), l.open({
158
+ title: "Success",
159
+ message: "Action submitted",
160
+ type: "success"
161
+ }), n.onFinished();
162
+ } catch (u) {
163
+ l.open({
164
+ title: "Something went wrong",
165
+ message: (u == null ? void 0 : u.message) ?? "Unable to submit action. Please try again",
166
+ type: "error"
167
+ }), console.error("error on submit closing draft action", u);
168
+ } finally {
169
+ s.value = !1;
170
+ }
171
+ }
172
+ return (S, u) => {
173
+ const F = G("FmLabel"), c = G("FmDatePicker"), r = G("FmTimePicker"), i = G("FmTextField"), b = G("FmButton"), C = G("FmForm");
174
+ return d.value ? (x(), ne(C, {
175
+ key: 1,
176
+ onValidationSuccess: U,
177
+ class: "flex flex-col gap-32",
178
+ disabled: s.value
179
+ }, {
180
+ default: Z(() => [
181
+ m("div", fa, [
182
+ u[4] || (u[4] = pe(" You are about to ")),
183
+ m("span", pa, W(g.value), 1),
184
+ u[5] || (u[5] = pe(" this draft. Please provide a remark to justify this action. "))
185
+ ]),
186
+ S.action === p(le).enum.approveDraft ? (x(), M("div", va, [
187
+ B(F, { class: "fm-typo-en-body-lg-600" }, {
188
+ default: Z(() => u[6] || (u[6] = [
189
+ pe("Closing Date")
190
+ ])),
191
+ _: 1
192
+ }),
193
+ B(c, {
194
+ modelValue: f.value,
195
+ "onUpdate:modelValue": u[0] || (u[0] = (A) => f.value = A),
196
+ max: p(_t)(/* @__PURE__ */ new Date())
197
+ }, null, 8, ["modelValue", "max"]),
198
+ B(F, { class: "fm-typo-en-body-lg-600" }, {
199
+ default: Z(() => u[7] || (u[7] = [
200
+ pe("Closing Time")
201
+ ])),
202
+ _: 1
203
+ }),
204
+ B(r, {
205
+ modelValue: I.value,
206
+ "onUpdate:modelValue": u[1] || (u[1] = (A) => I.value = A)
207
+ }, null, 8, ["modelValue"]),
208
+ R.value ? (x(), M("div", ya, " Cannot select future date ")) : q("", !0)
209
+ ])) : q("", !0),
210
+ B(i, {
211
+ modelValue: e.value,
212
+ "onUpdate:modelValue": u[2] || (u[2] = (A) => e.value = A),
213
+ label: "Remark",
214
+ "label-mark": "required",
215
+ rules: [p(Qn)()]
216
+ }, null, 8, ["modelValue", "rules"]),
217
+ m("div", ga, [
218
+ B(b, {
219
+ label: "Cancel",
220
+ variant: "tertiary",
221
+ onClick: u[3] || (u[3] = (A) => S.onCancel())
222
+ }),
223
+ B(b, {
224
+ label: g.value,
225
+ type: "submit",
226
+ variant: _.value,
227
+ loading: s.value
228
+ }, null, 8, ["label", "variant", "loading"])
229
+ ])
230
+ ]),
231
+ _: 1
232
+ }, 8, ["disabled"])) : (x(), M(ue, { key: 0 }, [
233
+ pe("Loading")
234
+ ], 64));
235
+ };
236
+ }
237
+ }), ha = st(0);
238
+ function $n(t) {
239
+ const n = t.measurementsAmounts.groupBy((a) => a.measurement.id), e = t.sku.unit.measurements.reduce((a, l) => {
240
+ var d, g;
241
+ const s = ((g = (d = n.get(l.id)) == null ? void 0 : d[0]) == null ? void 0 : g.amount) ?? ha, o = Ht(l.conversion, s);
242
+ return a + +Bt(o);
243
+ }, +Bt(t.baseAmount));
244
+ return xn(e, t.baseAmount.precision);
245
+ }
246
+ const ba = st(0), _a = st(100);
247
+ function wa(t, n, e, a, l, s, o, d) {
248
+ var O, me, N, E, ie;
249
+ const g = $n(t), _ = a ?? g, f = Dn(_, n), I = n.amount === 0 ? null : Cn(f, {
250
+ ...n,
251
+ amount: Math.abs(n.amount)
252
+ }), R = I ? Ht(I, _a) : null, U = ((O = t.sku.defaultCost) == null ? void 0 : O.costPerUnit) ?? { amount: 0, precision: 0 }, S = Number(te.toFormatString({ value: U })), u = ((N = (me = t.sku.defaultCost) == null ? void 0 : me.measurement) == null ? void 0 : N.conversion) ?? {
253
+ amount: 1,
254
+ precision: 0
255
+ }, F = Number(
256
+ te.toFormatString({ value: u })
257
+ ), c = l ? Number(te.toFormatString({ value: l })) : 0, r = Number(te.toFormatString({ value: n })), i = Number(te.toFormatString({ value: _ })), b = i - r, C = b * S / F, A = i * S / F, L = r * S / F, se = {};
258
+ return o && s && o.forEach((D) => {
259
+ const X = { amount: 0, precision: 0 }, J = s[D];
260
+ if (J) {
261
+ const ve = Sn(X, J);
262
+ se[`adjustment_${D}`] = Bt(ve);
263
+ } else
264
+ se[`adjustment_${D}`] = "0";
265
+ }), {
266
+ code: t.sku.code,
267
+ name: t.sku.name,
268
+ baseUnit: t.sku.unit.abbrev,
269
+ costUnit: ((ie = (E = t.sku.defaultCost) == null ? void 0 : E.measurement) == null ? void 0 : ie.abbrev) ?? null,
270
+ baseUnitAmount: Number(te.toFormatString({ value: t.baseAmount })),
271
+ ...t.measurementsAmounts.filter(
272
+ (D) => ka(D.measurement) && e.includes(D.measurement.id)
273
+ ).reduce(
274
+ (D, X, J) => (D[`measurementAbbrev${J}`] = `(${X.measurement.abbrev}) × ${te.toFormatString({ value: X.measurement.conversion })}`, D[`measurementAmount${J}`] = Number(te.toFormatString({ value: X.amount })), D),
275
+ {}
276
+ ),
277
+ systemBalance: r,
278
+ physicalBalance: i,
279
+ adjustedAmount: Number(te.toFormatString({ value: f })),
280
+ adjustedDiffPercentage: R ? Number(
281
+ te.toFormatString({
282
+ value: An(R, 2)
283
+ })
284
+ ) : null,
285
+ costPerUnit: S,
286
+ opening: c,
287
+ ...se,
288
+ varianceQty: b,
289
+ varianceInCost: C,
290
+ stockTakeValue: A,
291
+ systemValue: L,
292
+ // Include custom attribute values
293
+ ...(d ?? []).reduce(
294
+ (D, X) => {
295
+ var ve;
296
+ const J = (ve = t.sku.customAttributes) == null ? void 0 : ve[X];
297
+ return D[`customAttr_${X}`] = J != null ? String(J) : null, D;
298
+ },
299
+ {}
300
+ )
301
+ };
302
+ }
303
+ function ka(t) {
304
+ return !t.abbrev.toLocaleLowerCase().includes("inactive");
305
+ }
306
+ function xa(t) {
307
+ const n = In(t);
308
+ return t.reduce(
309
+ (e, a) => {
310
+ var l;
311
+ return Math.max(e, ((l = n == null ? void 0 : n.get(a.sku._id)) == null ? void 0 : l[0].length) ?? 0);
312
+ },
313
+ 0
314
+ );
315
+ }
316
+ function In(t) {
317
+ return t.groupBy(
318
+ (n) => n.sku._id,
319
+ (n) => n.measurementsAmounts.filter((e) => !e.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((e) => e.measurement.id)
320
+ );
321
+ }
322
+ function Da(t, n = [], e = []) {
323
+ const a = _n(), l = a === "MYR" ? "RM" : a;
324
+ return [
325
+ {
326
+ id: "code",
327
+ name: "Code"
328
+ },
329
+ {
330
+ id: "name",
331
+ name: "Name"
332
+ },
333
+ {
334
+ id: "baseUnit",
335
+ name: "Base unit"
336
+ },
337
+ {
338
+ id: "costPerUnit",
339
+ name: "Cost per unit"
340
+ },
341
+ {
342
+ id: "costUnit",
343
+ name: "UOM"
344
+ },
345
+ {
346
+ id: "opening",
347
+ name: "Opening (B/F)"
348
+ },
349
+ // Dynamic adjustment type columns
350
+ ...n.map((o) => ({
351
+ id: `adjustment_${o}`,
352
+ name: Pe(o)
353
+ })),
354
+ {
355
+ id: "systemBalance",
356
+ name: "System balance (Qty)"
357
+ },
358
+ {
359
+ id: "physicalBalance",
360
+ name: "Stock take (Qty)"
361
+ },
362
+ {
363
+ id: "adjustedAmount",
364
+ name: "Variance"
365
+ },
366
+ {
367
+ id: "varianceInCost",
368
+ name: `Variance (${l})`
369
+ },
370
+ {
371
+ id: "adjustedDiffPercentage",
372
+ name: "Variance (%)"
373
+ },
374
+ {
375
+ id: "stockTakeValue",
376
+ name: `Stock take value (${l})`
377
+ },
378
+ {
379
+ id: "systemValue",
380
+ name: `System value (${l})`
381
+ },
382
+ {
383
+ id: "baseUnitAmount",
384
+ name: "Base unit amount"
385
+ },
386
+ ...Array.from({ length: t }).flatMap((o, d) => [
387
+ {
388
+ id: `measurementAmount${d}`,
389
+ name: `UOM amount ${d + 1}`
390
+ },
391
+ {
392
+ id: `measurementAbbrev${d}`,
393
+ name: `UOM ${d + 1}`
394
+ }
395
+ ]),
396
+ // Dynamic custom attribute columns
397
+ ...e.map((o) => ({
398
+ id: `customAttr_${o}`,
399
+ name: Pe(o)
400
+ }))
401
+ ];
402
+ }
403
+ function Ca(t, n, e, a = []) {
404
+ var se, re, O, me, N, E, ie;
405
+ const l = n.groupBy(
406
+ (D) => D.id,
407
+ (D) => D.balance
408
+ ), s = e.groupBy(
409
+ (D) => D.id,
410
+ (D) => D.balance
411
+ ), o = /* @__PURE__ */ new Map();
412
+ if (t.opening)
413
+ for (const D of t.opening)
414
+ o.set(D.skuId, D.balance);
415
+ const d = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map();
416
+ if (t.adjustmentSnapshot)
417
+ for (const D of t.adjustmentSnapshot)
418
+ D.adjustmentsByType && (Object.keys(D.adjustmentsByType).forEach((X) => d.add(X)), g.set(D.skuId, D.adjustmentsByType));
419
+ const _ = ["receive", "sales", "wastage"], f = [];
420
+ _.forEach((D) => {
421
+ d.has(D) && (f.push(D), d.delete(D));
422
+ });
423
+ const I = Array.from(d).sort(), R = [...f, ...I], U = [...t.items, ...t.negativeStockItems ?? []], S = In(U), u = U.map((D) => {
424
+ var Ae, je, Re;
425
+ const X = ((Ae = l.get(D.sku._id)) == null ? void 0 : Ae[0]) ?? ba, J = ((je = S == null ? void 0 : S.get(D.sku._id)) == null ? void 0 : je[0]) ?? [], ve = o.get(D.sku._id), Oe = g.get(D.sku._id);
426
+ return wa(
427
+ D,
428
+ X,
429
+ J,
430
+ (Re = s.get(D.sku._id)) == null ? void 0 : Re[0],
431
+ ve,
432
+ Oe,
433
+ R,
434
+ a
435
+ );
436
+ }), F = xa(U), r = zt().currentBusiness.value, i = Da(F, R, a), b = [
437
+ ["Business name:", r == null ? void 0 : r.name],
438
+ ["Business ID:", r == null ? void 0 : r._id],
439
+ ["Menu version", r == null ? void 0 : r.menuVersion],
440
+ ["Created at", new Date(t.createdAt)],
441
+ ["Created by", (se = t.createdBy) == null ? void 0 : se.name],
442
+ ["Updated at", new Date(t.updatedAt)],
443
+ ["Updated by", (re = t.updatedBy) == null ? void 0 : re.name],
444
+ ["Recent action", t.approvedAt ? "Approve" : t.rejectionHistory ? "Reject" : ""],
445
+ [
446
+ "Action by",
447
+ t.approvedAt ? (O = t.approvedBy) == null ? void 0 : O.name : t.rejectionHistory ? (N = (me = t.rejectionHistory[0]) == null ? void 0 : me.rejectedBy) == null ? void 0 : N.name : ""
448
+ ],
449
+ [
450
+ "Action at",
451
+ t.approvedAt ? new Date(t.approvedAt) : t.rejectionHistory ? new Date((E = t.rejectionHistory[0]) == null ? void 0 : E.rejectedAt) : ""
452
+ ],
453
+ [
454
+ "Action remark",
455
+ t.approvedAt ? t.approveRemark : t.rejectionHistory ? new Date((ie = t.rejectionHistory[0]) == null ? void 0 : ie.rejectRemark) : ""
456
+ ],
457
+ [],
458
+ i.map((D) => D.name),
459
+ ...u.map((D) => i.map((X) => D[X.id]))
460
+ ], C = i.map((D) => `system:${D.id}`), A = Zn(b, C), L = `[${r == null ? void 0 : r.name}] closing draft (${Gn(new Date(t.updatedAt))}).xlsx`;
461
+ return Jn(A, L), L;
462
+ }
463
+ const Sa = { class: "flex flex-col" }, Aa = {
464
+ key: 0,
465
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
466
+ }, $a = { class: "flex gap-12 py-8 justify-end w-full" }, Ia = /* @__PURE__ */ Le({
467
+ __name: "RefreshBalanceAction",
468
+ props: {
469
+ draft: {},
470
+ onCancel: { type: Function },
471
+ onFinished: { type: Function }
472
+ },
473
+ setup(t) {
474
+ const n = t;
475
+ Dt();
476
+ const e = Y(!1), a = Y(null), l = Y(!1);
477
+ Lt(() => {
478
+ if (n.draft.effectiveAt)
479
+ a.value = new Date(n.draft.effectiveAt);
480
+ else {
481
+ const _ = new Date(n.draft.createdAt);
482
+ _.setHours(23, 59, 59, 999), a.value = _;
483
+ }
484
+ l.value = !0;
485
+ });
486
+ const s = V({
487
+ get() {
488
+ return a.value === null ? "" : _t(a.value);
489
+ },
490
+ set(_) {
491
+ if (_) {
492
+ const f = /* @__PURE__ */ new Date(`${_} ${o.value}`);
493
+ f.setSeconds(59, 999), a.value = f;
494
+ } else
495
+ a.value = null;
496
+ }
497
+ }), o = V({
498
+ get() {
499
+ return a.value === null ? "" : kn(a.value);
500
+ },
501
+ set(_) {
502
+ if (_) {
503
+ const f = /* @__PURE__ */ new Date(`${s.value} ${_}`);
504
+ f.setSeconds(59, 999), a.value = f;
505
+ } else
506
+ a.value = null;
507
+ }
508
+ }), d = V(() => a.value ? a.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
509
+ async function g() {
510
+ e.value = !0, n.onFinished(a.value.toISOString());
511
+ }
512
+ return (_, f) => {
513
+ const I = G("FmLabel"), R = G("FmDatePicker"), U = G("FmTimePicker"), S = G("FmButton"), u = G("FmForm");
514
+ return l.value ? (x(), ne(u, {
515
+ key: 1,
516
+ onValidationSuccess: g,
517
+ class: "flex flex-col gap-32",
518
+ disabled: e.value
519
+ }, {
520
+ default: Z(() => [
521
+ f[5] || (f[5] = m("div", { class: "fm-typo-en-body-lg-400" }, [
522
+ m("p", null, [
523
+ pe(" Performing "),
524
+ m("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
525
+ pe(" until closing effective date and time. ")
526
+ ]),
527
+ m("p", { class: "mt-2" }, [
528
+ pe(" Please note that this action will "),
529
+ m("b", null, "update"),
530
+ pe(" the effective date and time. ")
531
+ ])
532
+ ], -1)),
533
+ m("div", Sa, [
534
+ B(I, { class: "fm-typo-en-body-lg-600" }, {
535
+ default: Z(() => f[3] || (f[3] = [
536
+ pe("Closing Date")
537
+ ])),
538
+ _: 1
539
+ }),
540
+ B(R, {
541
+ modelValue: s.value,
542
+ "onUpdate:modelValue": f[0] || (f[0] = (F) => s.value = F),
543
+ max: p(_t)(/* @__PURE__ */ new Date())
544
+ }, null, 8, ["modelValue", "max"]),
545
+ B(I, { class: "fm-typo-en-body-lg-600" }, {
546
+ default: Z(() => f[4] || (f[4] = [
547
+ pe("Closing Time")
548
+ ])),
549
+ _: 1
550
+ }),
551
+ B(U, {
552
+ modelValue: o.value,
553
+ "onUpdate:modelValue": f[1] || (f[1] = (F) => o.value = F)
554
+ }, null, 8, ["modelValue"]),
555
+ d.value ? (x(), M("div", Aa, " Cannot select future date ")) : q("", !0)
556
+ ]),
557
+ m("div", $a, [
558
+ B(S, {
559
+ label: "Cancel",
560
+ variant: "tertiary",
561
+ onClick: f[2] || (f[2] = (F) => _.onCancel())
562
+ }),
563
+ B(S, {
564
+ label: "Refresh balance",
565
+ type: "submit",
566
+ variant: "primary",
567
+ loading: e.value,
568
+ disabled: d.value
569
+ }, null, 8, ["loading", "disabled"])
570
+ ])
571
+ ]),
572
+ _: 1
573
+ }, 8, ["disabled"])) : (x(), M(ue, { key: 0 }, [
574
+ pe("Loading")
575
+ ], 64));
576
+ };
577
+ }
578
+ }), wt = wn(
579
+ "closingDraftActions",
580
+ function() {
581
+ const n = Wn(), e = rt(), a = Dt(), l = it(), s = Xn(), o = Y(!1), d = Y();
582
+ function g(i) {
583
+ const b = {
584
+ draft: i
585
+ };
586
+ d.value = b, o.value = !0;
587
+ }
588
+ async function _(i) {
589
+ var C;
590
+ if (i.status === Te.enum.COMPLETED) {
591
+ const A = i.closingAdjustmentId;
592
+ if (!A)
593
+ return e.open({
594
+ title: "Something went wrong",
595
+ message: "Closing draft is completed but closing document cannot be found.",
596
+ type: "error"
597
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
598
+ draftId: i._id
599
+ }), [];
600
+ const L = await a.readAdjustmentById(A);
601
+ return ((L == null ? void 0 : L.skus) ?? []).map((re) => ({
602
+ id: re.sku._id,
603
+ balance: re.fromBalance,
604
+ costs: re.fromCostBalances
605
+ }));
606
+ } else
607
+ return await s.readStockBalance(), ((C = s.stockBalance) == null ? void 0 : C.skus) ?? [];
608
+ }
609
+ async function f(i, b, C, A) {
610
+ b || (e.open({
611
+ title: "Exporting",
612
+ message: "Fetching data..."
613
+ }), b = await _(i)), Ca(i, b, C ?? [], A ?? []);
614
+ }
615
+ function I(i, b, C) {
616
+ n.open({
617
+ title: "Approve draft",
618
+ contentComponent: Tt,
619
+ contentComponentProps: {
620
+ draft: i,
621
+ action: le.enum.approveDraft,
622
+ onFinished: () => {
623
+ n.close(), b == null || b();
624
+ },
625
+ onCancel: () => {
626
+ n.close();
627
+ }
628
+ }
629
+ }).onClose(() => {
630
+ C == null || C();
631
+ });
632
+ }
633
+ function R(i, b) {
634
+ n.open({
635
+ title: "Reject draft",
636
+ contentComponent: Tt,
637
+ contentComponentProps: {
638
+ draft: i,
639
+ action: le.enum.rejectDraft,
640
+ onFinished: () => {
641
+ n.close(), b == null || b();
642
+ },
643
+ onCancel: () => n.close()
644
+ }
645
+ });
646
+ }
647
+ function U(i, b) {
648
+ n.open({
649
+ title: "Mark draft as failed",
650
+ contentComponent: Tt,
651
+ contentComponentProps: {
652
+ draft: i,
653
+ action: le.enum.markAsFailed,
654
+ onFinished: () => {
655
+ n.close(), b == null || b();
656
+ },
657
+ onCancel: () => n.close()
658
+ }
659
+ });
660
+ }
661
+ async function S(i, b) {
662
+ await l.sync({
663
+ _id: i._id,
664
+ _rev: i._rev ?? "",
665
+ action: le.enum.approveDraft,
666
+ data: {
667
+ remark: i.remark ?? ""
668
+ }
669
+ }).delayed(500), e.open({
670
+ title: "Success",
671
+ message: "Sync requested",
672
+ type: "success"
673
+ }), b == null || b();
674
+ }
675
+ function u() {
676
+ o.value = !1;
677
+ }
678
+ async function F(i, b, C) {
679
+ await n.open({
680
+ title: "Refresh balance",
681
+ contentComponent: Ia,
682
+ contentComponentProps: {
683
+ draft: i,
684
+ onFinished: (A) => {
685
+ n.close(), C == null || C(A);
686
+ },
687
+ onCancel: async () => {
688
+ n.close(), b == null || b();
689
+ }
690
+ }
691
+ });
692
+ }
693
+ async function c(i) {
694
+ await n.open({
695
+ title: "Invalidate closing draft cache",
696
+ message: "It will invalidate opening and stock movement cache for this draft.",
697
+ primaryActions: { text: "Proceed", close: !0 },
698
+ secondaryActions: { text: "Cancel", close: !0 }
699
+ }).onPrimary(async () => {
700
+ await a.recalculation.scheduleInvalidateClosingDraftCache([i._id]), e.open({
701
+ title: "Success",
702
+ message: "Invalidate cache requested",
703
+ type: "success"
704
+ });
705
+ });
706
+ }
707
+ async function r(i, b) {
708
+ try {
709
+ e.open({
710
+ title: "Cloning",
711
+ message: "Creating a copy of the draft..."
712
+ }), await l.cloneDraft(i._id), e.open({
713
+ title: "Success",
714
+ message: "Draft cloned successfully",
715
+ type: "success"
716
+ }), b == null || b();
717
+ } catch (C) {
718
+ e.open({
719
+ title: "Error",
720
+ message: (C == null ? void 0 : C.message) || "Failed to clone draft",
721
+ type: "error"
722
+ });
723
+ }
724
+ }
725
+ return {
726
+ viewDraft: g,
727
+ closeDraftDialog: u,
728
+ approveDraft: I,
729
+ rejectDraft: R,
730
+ markAsFailed: U,
731
+ syncDraft: S,
732
+ exportDraft: f,
733
+ refreshBalance: F,
734
+ cloneDraft: r,
735
+ viewClosingDraftShow: o,
736
+ viewClosingDraftProps: d,
737
+ invalidateDraftCache: c
738
+ };
739
+ }
740
+ );
741
+ function ht(t) {
742
+ switch (t) {
743
+ case "DRAFT":
744
+ return "fm-status-badge-draft";
745
+ case "PROCESSING":
746
+ return "fm-status-badge-processing";
747
+ case "FAILED":
748
+ return "fm-status-badge-cancel";
749
+ case "COMPLETED":
750
+ return "fm-status-badge-complete";
751
+ }
752
+ }
753
+ const Tn = wn(
754
+ "closingDraftTable",
755
+ function() {
756
+ const { t: n } = xt(), e = zt(), a = wt(), l = Y(new Array()), s = Y(0), o = Y(!1), d = lt(), g = it();
757
+ async function _() {
758
+ if (l.value = [], !!d._currentLocation) {
759
+ o.value = !0;
760
+ try {
761
+ const [c] = await Promise.all([g.readDrafts()]).delayed(1e3);
762
+ l.value = I(c.reverse());
763
+ } catch (c) {
764
+ console.log("Something went wrong when fetching drafts:", c);
765
+ } finally {
766
+ o.value = !1;
767
+ }
768
+ }
769
+ }
770
+ async function f(c) {
771
+ if (!l.value.find((r) => r._id) && d._currentLocation) {
772
+ o.value = !0;
773
+ try {
774
+ const [r] = await Promise.all([
775
+ g.getDraft(c),
776
+ new Promise((i) => setTimeout(i, 1e3))
777
+ ]);
778
+ l.value = I([r]);
779
+ } catch (r) {
780
+ console.log("Something went wrong when fetching drafts:", r);
781
+ } finally {
782
+ o.value = !1;
783
+ }
784
+ }
785
+ }
786
+ function I(c) {
787
+ const r = na(
788
+ c.filter((i) => !!i.closingId).map((i) => ({ closingId: i.closingId, draftCreatedAt: new Date(Ve(i._id)) }))
789
+ );
790
+ return c.map((i) => ({
791
+ ...i,
792
+ closingIdDisplay: i.closingId ? r.get(i.closingId) ?? null : null
793
+ }));
794
+ }
795
+ function R(c) {
796
+ l.value = l.value.map((r) => r._id === c._id ? {
797
+ ...c,
798
+ _rev: c._rev,
799
+ closingIdDisplay: r.closingIdDisplay
800
+ } : r), s.value++;
801
+ }
802
+ function U(c) {
803
+ var b, C;
804
+ const r = c.items.length + (((b = c.negativeStockItems) == null ? void 0 : b.length) ?? 0), i = (c == null ? void 0 : c.approveRemark) ?? ((C = c == null ? void 0 : c.rejectionHistory) == null ? void 0 : C.computeFirst((A) => A.rejectRemark)) ?? c.remark ?? "";
805
+ return { count: r, remark: i };
806
+ }
807
+ function S() {
808
+ a.closeDraftDialog(), _();
809
+ }
810
+ function u(c, r) {
811
+ switch (r = Yn(r), c) {
812
+ case He.Details:
813
+ return a.viewDraft(r);
814
+ case He.Export:
815
+ return a.exportDraft(r);
816
+ case le.enum.approveDraft:
817
+ return a.approveDraft(r, S);
818
+ case le.enum.rejectDraft:
819
+ return a.rejectDraft(r, S);
820
+ case le.enum.markAsFailed:
821
+ return a.markAsFailed(r, S);
822
+ case He.Duplicate:
823
+ return a.cloneDraft(r, S);
824
+ }
825
+ }
826
+ return {
827
+ columnDefs: [
828
+ {
829
+ id: "_id",
830
+ accessorKey: "_id",
831
+ header: () => n("inventory.closing.table.createdAt"),
832
+ cell(c) {
833
+ return ta(`${c.getValue()}`);
834
+ },
835
+ sortingFn: (c, r) => new Date(Ve(c.original._id)).getTime() - new Date(Ve(r.original._id)).getTime(),
836
+ enableSorting: !0
837
+ },
838
+ {
839
+ id: "closingId",
840
+ accessorFn: (c) => c.closingIdDisplay,
841
+ size: 160,
842
+ header: () => n("inventory.closing.draft.table.id"),
843
+ cell(c) {
844
+ return c.getValue();
845
+ },
846
+ enableSorting: !0
847
+ },
848
+ {
849
+ accessorKey: "effectiveAt",
850
+ header: () => n("inventory.closing.draft.table.effectiveAt"),
851
+ cell(c) {
852
+ const r = c.row.original;
853
+ let i = c.getValue();
854
+ return i || (i = Ve(r._id)), Fe(i);
855
+ },
856
+ enableSorting: !0,
857
+ size: 230
858
+ },
859
+ {
860
+ id: "description",
861
+ accessorFn: (c) => {
862
+ const { count: r, remark: i } = U(c);
863
+ return `${r} ${i}`;
864
+ },
865
+ header: () => n("inventory.closing.draft.table.description"),
866
+ enableSorting: !0,
867
+ size: 350,
868
+ cell(c) {
869
+ const { count: r, remark: i } = U(c.row.original), b = (C, A) => T("div", { class: "flex gap-4" }, [
870
+ T(
871
+ "span",
872
+ { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" },
873
+ `${C}:`
874
+ ),
875
+ T(
876
+ "span",
877
+ {
878
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
879
+ style: "white-space: pre-wrap; word-break: break-word;"
880
+ },
881
+ `${A}`
882
+ )
883
+ ]);
884
+ return T("div", { class: "flex flex-col gap-2", style: "width: 300px;" }, [
885
+ b(n("inventory.closing.draft.table.items"), r),
886
+ i ? b(n("inventory.closing.draft.table.remark"), i) : null
887
+ ]);
888
+ }
889
+ },
890
+ {
891
+ id: "status",
892
+ accessorFn: (c) => c.status,
893
+ header: () => n("inventory.closing.table.status"),
894
+ enableSorting: !1,
895
+ cell(c) {
896
+ var L;
897
+ const r = c.row.original, i = r.status, b = new Date(r.updatedAt), C = (L = r == null ? void 0 : r.rejectionHistory) == null ? void 0 : L.computeFirst((se) => se.rejectedAt), A = C ? new Date(C) : null;
898
+ return i === "DRAFT" && A ? A.getTime() > b.getTime() ? T(
899
+ "div",
900
+ {
901
+ class: "flex"
902
+ },
903
+ T(
904
+ "div",
905
+ {
906
+ class: ["fm-status-badge", ht("FAILED")]
907
+ },
908
+ "Rejected"
909
+ )
910
+ ) : T(
911
+ "div",
912
+ {
913
+ class: "flex"
914
+ },
915
+ T(
916
+ "div",
917
+ {
918
+ class: ["fm-status-badge", ht("PROCESSING")]
919
+ },
920
+ "Updated"
921
+ )
922
+ ) : T(
923
+ "div",
924
+ {
925
+ class: "flex"
926
+ },
927
+ T(
928
+ "div",
929
+ {
930
+ class: ["fm-status-badge", ht(i)]
931
+ },
932
+ Pe(i)
933
+ )
934
+ );
935
+ }
936
+ },
937
+ {
938
+ id: "updatedAt",
939
+ accessorFn: (c) => c.updatedAt,
940
+ header: () => n("inventory.closing.draft.table.lastUpdate"),
941
+ enableSorting: !0,
942
+ size: 200,
943
+ cell(c) {
944
+ var i;
945
+ const r = c.row.original;
946
+ return T("div", { class: "flex flex-col" }, [
947
+ T(
948
+ "div",
949
+ { class: "fm-typo-en-body-md-600 text-fm-color-typo-primary" },
950
+ ((i = r.updatedBy) == null ? void 0 : i.name) ?? ""
951
+ ),
952
+ T(
953
+ "div",
954
+ { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
955
+ Fe(r.updatedAt)
956
+ )
957
+ ]);
958
+ }
959
+ },
960
+ {
961
+ id: "action",
962
+ cell(c) {
963
+ var L;
964
+ const r = c.row.original, i = ((L = e.sessionUser.value) == null ? void 0 : L.role.isAdmin) ?? !1, b = [
965
+ un[He.Details],
966
+ un[He.Export]
967
+ ], C = [
968
+ {
969
+ translationKey: "inventory.closing.draft.approveDraft",
970
+ color: "text-fm-color-typo-primary",
971
+ value: le.enum.approveDraft
972
+ },
973
+ {
974
+ translationKey: "inventory.closing.draft.rejectDraft",
975
+ color: "text-fm-color-typo-error",
976
+ value: le.enum.rejectDraft
977
+ },
978
+ {
979
+ translationKey: "inventory.closing.draft.markAsFailed",
980
+ color: "text-fm-color-typo-error",
981
+ value: le.enum.markAsFailed
982
+ }
983
+ ], A = i && r.status !== Te.enum.DRAFT ? [
984
+ {
985
+ translationKey: "inventory.closing.draft.cloneDraft",
986
+ color: "text-fm-color-typo-primary",
987
+ value: He.Duplicate
988
+ }
989
+ ] : [];
990
+ return ea(
991
+ [
992
+ ...b,
993
+ ...r.status === Te.enum.DRAFT ? C : []
994
+ ],
995
+ (se) => u(se, r),
996
+ A
997
+ );
998
+ },
999
+ enableSorting: !1,
1000
+ size: 40,
1001
+ meta: {
1002
+ cellClass: "",
1003
+ headerClass: ""
1004
+ }
1005
+ }
1006
+ ],
1007
+ drafts: l,
1008
+ loading: o,
1009
+ tableKey: s,
1010
+ fetchDrafts: _,
1011
+ loadDraft: f,
1012
+ updateDraftRef: R
1013
+ };
1014
+ }
1015
+ ), Ta = { class: "fm-typo-en-heading-lg-600" }, Fa = { class: "py-4" }, Ba = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Ea = { key: 0 }, ja = { class: "mt-4 flex gap-4" }, Ra = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Ma = { key: 0 }, Na = {
1016
+ key: 0,
1017
+ class: "mb-4"
1018
+ }, Ua = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full" }, Pa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Va = {
1019
+ key: 0,
1020
+ class: "text-fm-color-system-success-300 mr-1"
1021
+ }, La = {
1022
+ key: 1,
1023
+ class: "text-fm-color-system-error-300 mr-1"
1024
+ }, Oa = { class: "fm-typo-en-body-md-400" }, za = { class: "mt-4 flex gap-4" }, Wa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Ha = {
1025
+ key: 0,
1026
+ class: "flex gap-4"
1027
+ }, Ya = /* @__PURE__ */ Le({
1028
+ __name: "ClosingDraftApprovalDialog",
1029
+ props: {
1030
+ show: { type: Boolean },
1031
+ refreshing: { type: Boolean },
1032
+ approving: { type: Boolean },
1033
+ draft: {}
1034
+ },
1035
+ emits: ["update:show", "refresh", "approve"],
1036
+ setup(t, { emit: n }) {
1037
+ const { FmStepper: e, FmStep: a, FmDialog: l, FmButton: s } = Ce, { t: o } = sa(), d = Wt(), g = t, _ = n, f = V(
1038
+ () => {
1039
+ var N, E;
1040
+ return ((N = g.draft) == null ? void 0 : N.stockSnapshot) && ((E = g.draft) == null ? void 0 : E.stockSnapshot) !== void 0;
1041
+ }
1042
+ ), I = V(() => {
1043
+ var ie, D, X;
1044
+ const N = ((ie = g.draft) == null ? void 0 : ie.items.map((J) => ({
1045
+ id: J.sku._id,
1046
+ code: J.sku.code,
1047
+ name: J.sku.name
1048
+ }))) ?? [], E = ((X = (D = g.draft) == null ? void 0 : D.negativeStockItems) == null ? void 0 : X.map((J) => ({
1049
+ id: J.sku._id,
1050
+ code: J.sku.code,
1051
+ name: J.sku.name
1052
+ }))) ?? [];
1053
+ return [...N, ...E].reduce(
1054
+ (J, ve) => (J[ve.id] = ve, J),
1055
+ {}
1056
+ );
1057
+ }), R = V(
1058
+ () => {
1059
+ var N, E, ie;
1060
+ return (((ie = (E = (N = g.draft) == null ? void 0 : N.stockSnapshot) == null ? void 0 : E.filter((D) => D.balance.amount < 0)) == null ? void 0 : ie.map((D) => {
1061
+ const X = d.skuById[D.id];
1062
+ return X ? {
1063
+ id: X._id,
1064
+ code: X.code,
1065
+ name: X.name
1066
+ } : null;
1067
+ })) ?? []).filter((D) => D !== null);
1068
+ }
1069
+ ), U = V(() => {
1070
+ var N;
1071
+ return f.value ? ((N = R.value) == null ? void 0 : N.filter((E) => !I.value[E.id]).map((E) => E.id)) ?? [] : [];
1072
+ }), S = V({
1073
+ get: () => g.show,
1074
+ set: (N) => _("update:show", N)
1075
+ }), u = Y(1), F = () => u.value > 1, c = () => u.value > 2, r = () => !1;
1076
+ function i(N) {
1077
+ return N === 1 ? f.value : N === 2 ? U.value.length == 0 : !1;
1078
+ }
1079
+ const b = V(() => !f.value || U.value.length > 0);
1080
+ function C(N) {
1081
+ let E = N + 1;
1082
+ for (; E <= 3 && i(E); ) E++;
1083
+ return E > 3 ? 3 : E;
1084
+ }
1085
+ function A(N) {
1086
+ let E = N - 1;
1087
+ for (; E >= 1 && i(E); ) E--;
1088
+ return E < 1 ? 1 : E;
1089
+ }
1090
+ function L() {
1091
+ return f.value ? b.value ? 3 : 2 : 1;
1092
+ }
1093
+ Qe(
1094
+ () => g.show,
1095
+ (N) => {
1096
+ N && (u.value = L());
1097
+ }
1098
+ ), Qe(
1099
+ () => f.value,
1100
+ (N) => {
1101
+ N && u.value === 1 && (u.value = C(1));
1102
+ }
1103
+ ), Qe(
1104
+ () => U.value.length,
1105
+ (N) => {
1106
+ N === 0 && u.value === 2 && (u.value = C(2));
1107
+ }
1108
+ );
1109
+ function se() {
1110
+ _("refresh");
1111
+ }
1112
+ function re() {
1113
+ u.value < 3 && (u.value = C(u.value));
1114
+ }
1115
+ function O() {
1116
+ u.value > 1 && (u.value = A(u.value));
1117
+ }
1118
+ function me() {
1119
+ _("approve");
1120
+ }
1121
+ return (N, E) => {
1122
+ const ie = G("FmIcon");
1123
+ return x(), ne(p(l), {
1124
+ modelValue: S.value,
1125
+ "onUpdate:modelValue": E[1] || (E[1] = (D) => S.value = D),
1126
+ "max-width": 600
1127
+ }, {
1128
+ "dialog-header": Z(() => [
1129
+ m("div", Ta, W(p(o)("inventory.closing.approval.title")), 1)
1130
+ ]),
1131
+ default: Z(() => [
1132
+ m("div", Fa, [
1133
+ B(p(e), {
1134
+ modelValue: u.value,
1135
+ "onUpdate:modelValue": E[0] || (E[0] = (D) => u.value = D),
1136
+ orientation: "vertical"
1137
+ }, {
1138
+ default: Z(() => [
1139
+ B(p(a), {
1140
+ value: 1,
1141
+ title: p(o)("inventory.closing.approval.step.generateReport.title"),
1142
+ complete: F
1143
+ }, {
1144
+ default: Z(() => [
1145
+ m("div", Ba, W(p(o)("inventory.closing.approval.step.generateReport.description")), 1),
1146
+ u.value === 1 ? (x(), M("div", Ea, [
1147
+ B(p(s), {
1148
+ label: p(o)("inventory.stock.stock_balance.refreshBalance"),
1149
+ "prepend-icon": "refresh",
1150
+ variant: "secondary",
1151
+ loading: N.refreshing,
1152
+ disabled: N.refreshing,
1153
+ onClick: se
1154
+ }, null, 8, ["label", "loading", "disabled"]),
1155
+ m("div", ja, [
1156
+ B(p(s), {
1157
+ label: p(o)("inventory.common.continue"),
1158
+ disabled: !f.value,
1159
+ onClick: re
1160
+ }, null, 8, ["label", "disabled"])
1161
+ ])
1162
+ ])) : q("", !0)
1163
+ ]),
1164
+ _: 1
1165
+ }, 8, ["title"]),
1166
+ B(p(a), {
1167
+ value: 2,
1168
+ title: p(o)("inventory.closing.approval.step.negativeItems.title"),
1169
+ disabled: () => !f.value,
1170
+ complete: c
1171
+ }, {
1172
+ default: Z(() => [
1173
+ m("div", Ra, W(R.value.length > 0 ? `${p(o)("inventory.closing.approval.step.negativeItems.resolveMessage")} [${p(o)("inventory.closing.approval.step.negativeItems.itemsHeader")} (${U.value.length})]` : p(o)("inventory.closing.approval.step.negativeItems.noItemsMessage")), 1),
1174
+ u.value === 2 ? (x(), M("div", Ma, [
1175
+ R.value.length > 0 ? (x(), M("div", Na, [
1176
+ E[2] || (E[2] = m("div", { class: "fm-typo-en-body-md-600 mb-2" }, null, -1)),
1177
+ m("div", Ua, [
1178
+ (x(!0), M(ue, null, Se(R.value, (D) => (x(), M("div", {
1179
+ key: D.id,
1180
+ class: "flex gap-8"
1181
+ }, [
1182
+ m("div", Pa, [
1183
+ I.value[D.id] ? (x(), M("span", Va, [
1184
+ B(ie, {
1185
+ name: "check_circle",
1186
+ size: "sm"
1187
+ })
1188
+ ])) : (x(), M("span", La, [
1189
+ B(ie, {
1190
+ name: "error",
1191
+ size: "sm"
1192
+ })
1193
+ ])),
1194
+ pe(" " + W(D.code), 1)
1195
+ ]),
1196
+ m("div", Oa, W(D.name), 1)
1197
+ ]))), 128))
1198
+ ])
1199
+ ])) : q("", !0),
1200
+ m("div", za, [
1201
+ B(p(s), {
1202
+ label: p(o)("inventory.common.back"),
1203
+ variant: "secondary",
1204
+ onClick: O
1205
+ }, null, 8, ["label"]),
1206
+ B(p(s), {
1207
+ label: p(o)("inventory.common.continue"),
1208
+ disabled: b.value,
1209
+ onClick: re
1210
+ }, null, 8, ["label", "disabled"])
1211
+ ])
1212
+ ])) : q("", !0)
1213
+ ]),
1214
+ _: 1
1215
+ }, 8, ["title", "disabled"]),
1216
+ B(p(a), {
1217
+ value: 3,
1218
+ title: p(o)("inventory.closing.approval.step.approval.title"),
1219
+ disabled: () => b.value,
1220
+ complete: r
1221
+ }, {
1222
+ default: Z(() => [
1223
+ m("div", Wa, W(p(o)("inventory.closing.approval.step.approval.warning")), 1),
1224
+ u.value === 3 ? (x(), M("div", Ha, [
1225
+ B(p(s), {
1226
+ label: p(o)("inventory.common.back"),
1227
+ variant: "secondary",
1228
+ onClick: O
1229
+ }, null, 8, ["label"]),
1230
+ B(p(s), {
1231
+ label: p(o)("inventory.common.approve"),
1232
+ variant: "destructive",
1233
+ disabled: b.value,
1234
+ loading: N.approving,
1235
+ onClick: me
1236
+ }, null, 8, ["label", "disabled", "loading"])
1237
+ ])) : q("", !0)
1238
+ ]),
1239
+ _: 1
1240
+ }, 8, ["title", "disabled"])
1241
+ ]),
1242
+ _: 1
1243
+ }, 8, ["modelValue"])
1244
+ ])
1245
+ ]),
1246
+ _: 1
1247
+ }, 8, ["modelValue"]);
1248
+ };
1249
+ }
1250
+ }), Ka = bn((t, n) => ({
1251
+ getSubscribeUrl(e, a, l) {
1252
+ const s = new URLSearchParams({ clientId: e, type: a, ...l });
1253
+ return `${t.inventoryBackendUrl}/sse/subscribe?${s.toString()}`;
1254
+ },
1255
+ async getStatus(e, a) {
1256
+ const l = new URLSearchParams({ type: e, ...a }), s = `${t.inventoryBackendUrl}/sse/status?${l.toString()}`;
1257
+ return n.get(s);
1258
+ }
1259
+ }));
1260
+ class dn extends Error {
1261
+ constructor(n, e) {
1262
+ super(n), this.name = "ParseError", this.type = e.type, this.field = e.field, this.value = e.value, this.line = e.line;
1263
+ }
1264
+ }
1265
+ function Ft(t) {
1266
+ }
1267
+ function qa(t) {
1268
+ if (typeof t == "function")
1269
+ throw new TypeError(
1270
+ "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
1271
+ );
1272
+ const { onEvent: n = Ft, onError: e = Ft, onRetry: a = Ft, onComment: l } = t;
1273
+ let s = "", o = !0, d, g = "", _ = "";
1274
+ function f(u) {
1275
+ const F = o ? u.replace(/^\xEF\xBB\xBF/, "") : u, [c, r] = Ga(`${s}${F}`);
1276
+ for (const i of c)
1277
+ I(i);
1278
+ s = r, o = !1;
1279
+ }
1280
+ function I(u) {
1281
+ if (u === "") {
1282
+ U();
1283
+ return;
1284
+ }
1285
+ if (u.startsWith(":")) {
1286
+ l && l(u.slice(u.startsWith(": ") ? 2 : 1));
1287
+ return;
1288
+ }
1289
+ const F = u.indexOf(":");
1290
+ if (F !== -1) {
1291
+ const c = u.slice(0, F), r = u[F + 1] === " " ? 2 : 1, i = u.slice(F + r);
1292
+ R(c, i, u);
1293
+ return;
1294
+ }
1295
+ R(u, "", u);
1296
+ }
1297
+ function R(u, F, c) {
1298
+ switch (u) {
1299
+ case "event":
1300
+ _ = F;
1301
+ break;
1302
+ case "data":
1303
+ g = `${g}${F}
1304
+ `;
1305
+ break;
1306
+ case "id":
1307
+ d = F.includes("\0") ? void 0 : F;
1308
+ break;
1309
+ case "retry":
1310
+ /^\d+$/.test(F) ? a(parseInt(F, 10)) : e(
1311
+ new dn(`Invalid \`retry\` value: "${F}"`, {
1312
+ type: "invalid-retry",
1313
+ value: F,
1314
+ line: c
1315
+ })
1316
+ );
1317
+ break;
1318
+ default:
1319
+ e(
1320
+ new dn(
1321
+ `Unknown field "${u.length > 20 ? `${u.slice(0, 20)}…` : u}"`,
1322
+ { type: "unknown-field", field: u, value: F, line: c }
1323
+ )
1324
+ );
1325
+ break;
1326
+ }
1327
+ }
1328
+ function U() {
1329
+ g.length > 0 && n({
1330
+ id: d,
1331
+ event: _ || void 0,
1332
+ // If the data buffer's last character is a U+000A LINE FEED (LF) character,
1333
+ // then remove the last character from the data buffer.
1334
+ data: g.endsWith(`
1335
+ `) ? g.slice(0, -1) : g
1336
+ }), d = void 0, g = "", _ = "";
1337
+ }
1338
+ function S(u = {}) {
1339
+ s && u.consume && I(s), o = !0, d = void 0, g = "", _ = "", s = "";
1340
+ }
1341
+ return { feed: f, reset: S };
1342
+ }
1343
+ function Ga(t) {
1344
+ const n = [];
1345
+ let e = "", a = 0;
1346
+ for (; a < t.length; ) {
1347
+ const l = t.indexOf("\r", a), s = t.indexOf(`
1348
+ `, a);
1349
+ let o = -1;
1350
+ if (l !== -1 && s !== -1 ? o = Math.min(l, s) : l !== -1 ? l === t.length - 1 ? o = -1 : o = l : s !== -1 && (o = s), o === -1) {
1351
+ e = t.slice(a);
1352
+ break;
1353
+ } else {
1354
+ const d = t.slice(a, o);
1355
+ n.push(d), a = o + 1, t[a - 1] === "\r" && t[a] === `
1356
+ ` && a++;
1357
+ }
1358
+ }
1359
+ return [n, e];
1360
+ }
1361
+ class mn extends Event {
1362
+ /**
1363
+ * Constructs a new `ErrorEvent` instance. This is typically not called directly,
1364
+ * but rather emitted by the `EventSource` object when an error occurs.
1365
+ *
1366
+ * @param type - The type of the event (should be "error")
1367
+ * @param errorEventInitDict - Optional properties to include in the error event
1368
+ */
1369
+ constructor(n, e) {
1370
+ var a, l;
1371
+ super(n), this.code = (a = e == null ? void 0 : e.code) != null ? a : void 0, this.message = (l = e == null ? void 0 : e.message) != null ? l : void 0;
1372
+ }
1373
+ /**
1374
+ * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
1375
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
1376
+ * we explicitly include the properties in the `inspect` method.
1377
+ *
1378
+ * This is automatically called by Node.js when you `console.log` an instance of this class.
1379
+ *
1380
+ * @param _depth - The current depth
1381
+ * @param options - The options passed to `util.inspect`
1382
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
1383
+ * @returns A string representation of the error
1384
+ */
1385
+ [Symbol.for("nodejs.util.inspect.custom")](n, e, a) {
1386
+ return a(fn(this), e);
1387
+ }
1388
+ /**
1389
+ * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
1390
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
1391
+ * we explicitly include the properties in the `inspect` method.
1392
+ *
1393
+ * This is automatically called by Deno when you `console.log` an instance of this class.
1394
+ *
1395
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
1396
+ * @param options - The options passed to `Deno.inspect`
1397
+ * @returns A string representation of the error
1398
+ */
1399
+ [Symbol.for("Deno.customInspect")](n, e) {
1400
+ return n(fn(this), e);
1401
+ }
1402
+ }
1403
+ function Qa(t) {
1404
+ const n = globalThis.DOMException;
1405
+ return typeof n == "function" ? new n(t, "SyntaxError") : new SyntaxError(t);
1406
+ }
1407
+ function Et(t) {
1408
+ return t instanceof Error ? "errors" in t && Array.isArray(t.errors) ? t.errors.map(Et).join(", ") : "cause" in t && t.cause instanceof Error ? `${t}: ${Et(t.cause)}` : t.message : `${t}`;
1409
+ }
1410
+ function fn(t) {
1411
+ return {
1412
+ type: t.type,
1413
+ message: t.message,
1414
+ code: t.code,
1415
+ defaultPrevented: t.defaultPrevented,
1416
+ cancelable: t.cancelable,
1417
+ timeStamp: t.timeStamp
1418
+ };
1419
+ }
1420
+ var Fn = (t) => {
1421
+ throw TypeError(t);
1422
+ }, Yt = (t, n, e) => n.has(t) || Fn("Cannot " + e), z = (t, n, e) => (Yt(t, n, "read from private field"), e ? e.call(t) : n.get(t)), ce = (t, n, e) => n.has(t) ? Fn("Cannot add the same private member more than once") : n instanceof WeakSet ? n.add(t) : n.set(t, e), oe = (t, n, e, a) => (Yt(t, n, "write to private field"), n.set(t, e), e), Ie = (t, n, e) => (Yt(t, n, "access private method"), e), he, Ue, Ye, bt, kt, nt, Ge, at, Ee, Ke, Ze, qe, et, xe, jt, Rt, Mt, pn, Nt, Ut, tt, Pt, Vt;
1423
+ class ot extends EventTarget {
1424
+ constructor(n, e) {
1425
+ var a, l;
1426
+ super(), ce(this, xe), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, ce(this, he), ce(this, Ue), ce(this, Ye), ce(this, bt), ce(this, kt), ce(this, nt), ce(this, Ge), ce(this, at, null), ce(this, Ee), ce(this, Ke), ce(this, Ze, null), ce(this, qe, null), ce(this, et, null), ce(this, Rt, async (s) => {
1427
+ var o;
1428
+ z(this, Ke).reset();
1429
+ const { body: d, redirected: g, status: _, headers: f } = s;
1430
+ if (_ === 204) {
1431
+ Ie(this, xe, tt).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
1432
+ return;
1433
+ }
1434
+ if (g ? oe(this, Ye, new URL(s.url)) : oe(this, Ye, void 0), _ !== 200) {
1435
+ Ie(this, xe, tt).call(this, `Non-200 status code (${_})`, _);
1436
+ return;
1437
+ }
1438
+ if (!(f.get("content-type") || "").startsWith("text/event-stream")) {
1439
+ Ie(this, xe, tt).call(this, 'Invalid content type, expected "text/event-stream"', _);
1440
+ return;
1441
+ }
1442
+ if (z(this, he) === this.CLOSED)
1443
+ return;
1444
+ oe(this, he, this.OPEN);
1445
+ const I = new Event("open");
1446
+ if ((o = z(this, et)) == null || o.call(this, I), this.dispatchEvent(I), typeof d != "object" || !d || !("getReader" in d)) {
1447
+ Ie(this, xe, tt).call(this, "Invalid response body, expected a web ReadableStream", _), this.close();
1448
+ return;
1449
+ }
1450
+ const R = new TextDecoder(), U = d.getReader();
1451
+ let S = !0;
1452
+ do {
1453
+ const { done: u, value: F } = await U.read();
1454
+ F && z(this, Ke).feed(R.decode(F, { stream: !u })), u && (S = !1, z(this, Ke).reset(), Ie(this, xe, Pt).call(this));
1455
+ } while (S);
1456
+ }), ce(this, Mt, (s) => {
1457
+ oe(this, Ee, void 0), !(s.name === "AbortError" || s.type === "aborted") && Ie(this, xe, Pt).call(this, Et(s));
1458
+ }), ce(this, Nt, (s) => {
1459
+ typeof s.id == "string" && oe(this, at, s.id);
1460
+ const o = new MessageEvent(s.event || "message", {
1461
+ data: s.data,
1462
+ origin: z(this, Ye) ? z(this, Ye).origin : z(this, Ue).origin,
1463
+ lastEventId: s.id || ""
1464
+ });
1465
+ z(this, qe) && (!s.event || s.event === "message") && z(this, qe).call(this, o), this.dispatchEvent(o);
1466
+ }), ce(this, Ut, (s) => {
1467
+ oe(this, nt, s);
1468
+ }), ce(this, Vt, () => {
1469
+ oe(this, Ge, void 0), z(this, he) === this.CONNECTING && Ie(this, xe, jt).call(this);
1470
+ });
1471
+ try {
1472
+ if (n instanceof URL)
1473
+ oe(this, Ue, n);
1474
+ else if (typeof n == "string")
1475
+ oe(this, Ue, new URL(n, Za()));
1476
+ else
1477
+ throw new Error("Invalid URL");
1478
+ } catch {
1479
+ throw Qa("An invalid or illegal string was specified");
1480
+ }
1481
+ oe(this, Ke, qa({
1482
+ onEvent: z(this, Nt),
1483
+ onRetry: z(this, Ut)
1484
+ })), oe(this, he, this.CONNECTING), oe(this, nt, 3e3), oe(this, kt, (a = e == null ? void 0 : e.fetch) != null ? a : globalThis.fetch), oe(this, bt, (l = e == null ? void 0 : e.withCredentials) != null ? l : !1), Ie(this, xe, jt).call(this);
1485
+ }
1486
+ /**
1487
+ * Returns the state of this EventSource object's connection. It can have the values described below.
1488
+ *
1489
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
1490
+ *
1491
+ * Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
1492
+ * defined in the TypeScript `dom` library.
1493
+ *
1494
+ * @public
1495
+ */
1496
+ get readyState() {
1497
+ return z(this, he);
1498
+ }
1499
+ /**
1500
+ * Returns the URL providing the event stream.
1501
+ *
1502
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
1503
+ *
1504
+ * @public
1505
+ */
1506
+ get url() {
1507
+ return z(this, Ue).href;
1508
+ }
1509
+ /**
1510
+ * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
1511
+ *
1512
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
1513
+ */
1514
+ get withCredentials() {
1515
+ return z(this, bt);
1516
+ }
1517
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
1518
+ get onerror() {
1519
+ return z(this, Ze);
1520
+ }
1521
+ set onerror(n) {
1522
+ oe(this, Ze, n);
1523
+ }
1524
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
1525
+ get onmessage() {
1526
+ return z(this, qe);
1527
+ }
1528
+ set onmessage(n) {
1529
+ oe(this, qe, n);
1530
+ }
1531
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
1532
+ get onopen() {
1533
+ return z(this, et);
1534
+ }
1535
+ set onopen(n) {
1536
+ oe(this, et, n);
1537
+ }
1538
+ addEventListener(n, e, a) {
1539
+ const l = e;
1540
+ super.addEventListener(n, l, a);
1541
+ }
1542
+ removeEventListener(n, e, a) {
1543
+ const l = e;
1544
+ super.removeEventListener(n, l, a);
1545
+ }
1546
+ /**
1547
+ * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
1548
+ *
1549
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
1550
+ *
1551
+ * @public
1552
+ */
1553
+ close() {
1554
+ z(this, Ge) && clearTimeout(z(this, Ge)), z(this, he) !== this.CLOSED && (z(this, Ee) && z(this, Ee).abort(), oe(this, he, this.CLOSED), oe(this, Ee, void 0));
1555
+ }
1556
+ }
1557
+ he = /* @__PURE__ */ new WeakMap(), Ue = /* @__PURE__ */ new WeakMap(), Ye = /* @__PURE__ */ new WeakMap(), bt = /* @__PURE__ */ new WeakMap(), kt = /* @__PURE__ */ new WeakMap(), nt = /* @__PURE__ */ new WeakMap(), Ge = /* @__PURE__ */ new WeakMap(), at = /* @__PURE__ */ new WeakMap(), Ee = /* @__PURE__ */ new WeakMap(), Ke = /* @__PURE__ */ new WeakMap(), Ze = /* @__PURE__ */ new WeakMap(), qe = /* @__PURE__ */ new WeakMap(), et = /* @__PURE__ */ new WeakMap(), xe = /* @__PURE__ */ new WeakSet(), /**
1558
+ * Connect to the given URL and start receiving events
1559
+ *
1560
+ * @internal
1561
+ */
1562
+ jt = function() {
1563
+ oe(this, he, this.CONNECTING), oe(this, Ee, new AbortController()), z(this, kt)(z(this, Ue), Ie(this, xe, pn).call(this)).then(z(this, Rt)).catch(z(this, Mt));
1564
+ }, Rt = /* @__PURE__ */ new WeakMap(), Mt = /* @__PURE__ */ new WeakMap(), /**
1565
+ * Get request options for the `fetch()` request
1566
+ *
1567
+ * @returns The request options
1568
+ * @internal
1569
+ */
1570
+ pn = function() {
1571
+ var t;
1572
+ const n = {
1573
+ // [spec] Let `corsAttributeState` be `Anonymous`…
1574
+ // [spec] …will have their mode set to "cors"…
1575
+ mode: "cors",
1576
+ redirect: "follow",
1577
+ headers: { Accept: "text/event-stream", ...z(this, at) ? { "Last-Event-ID": z(this, at) } : void 0 },
1578
+ cache: "no-store",
1579
+ signal: (t = z(this, Ee)) == null ? void 0 : t.signal
1580
+ };
1581
+ return "window" in globalThis && (n.credentials = this.withCredentials ? "include" : "same-origin"), n;
1582
+ }, Nt = /* @__PURE__ */ new WeakMap(), Ut = /* @__PURE__ */ new WeakMap(), /**
1583
+ * Handles the process referred to in the EventSource specification as "failing a connection".
1584
+ *
1585
+ * @param error - The error causing the connection to fail
1586
+ * @param code - The HTTP status code, if available
1587
+ * @internal
1588
+ */
1589
+ tt = function(t, n) {
1590
+ var e;
1591
+ z(this, he) !== this.CLOSED && oe(this, he, this.CLOSED);
1592
+ const a = new mn("error", { code: n, message: t });
1593
+ (e = z(this, Ze)) == null || e.call(this, a), this.dispatchEvent(a);
1594
+ }, /**
1595
+ * Schedules a reconnection attempt against the EventSource endpoint.
1596
+ *
1597
+ * @param message - The error causing the connection to fail
1598
+ * @param code - The HTTP status code, if available
1599
+ * @internal
1600
+ */
1601
+ Pt = function(t, n) {
1602
+ var e;
1603
+ if (z(this, he) === this.CLOSED)
1604
+ return;
1605
+ oe(this, he, this.CONNECTING);
1606
+ const a = new mn("error", { code: n, message: t });
1607
+ (e = z(this, Ze)) == null || e.call(this, a), this.dispatchEvent(a), oe(this, Ge, setTimeout(z(this, Vt), z(this, nt)));
1608
+ }, Vt = /* @__PURE__ */ new WeakMap(), /**
1609
+ * ReadyState representing an EventSource currently trying to connect
1610
+ *
1611
+ * @public
1612
+ */
1613
+ ot.CONNECTING = 0, /**
1614
+ * ReadyState representing an EventSource connection that is open (eg connected)
1615
+ *
1616
+ * @public
1617
+ */
1618
+ ot.OPEN = 1, /**
1619
+ * ReadyState representing an EventSource connection that is closed (eg disconnected)
1620
+ *
1621
+ * @public
1622
+ */
1623
+ ot.CLOSED = 2;
1624
+ Object.defineProperty(ot, Symbol.for("eventsource.supports-fetch-override"), {
1625
+ value: !0,
1626
+ writable: !1,
1627
+ configurable: !1,
1628
+ enumerable: !1
1629
+ });
1630
+ function Za() {
1631
+ const t = "document" in globalThis ? globalThis.document : void 0;
1632
+ return t && typeof t == "object" && "baseURI" in t && typeof t.baseURI == "string" ? t.baseURI : void 0;
1633
+ }
1634
+ const Ja = 3e3, Xa = 6e4, eo = 15, vn = to();
1635
+ function to() {
1636
+ var n, e;
1637
+ const t = (e = (n = globalThis.crypto) == null ? void 0 : n.randomUUID) == null ? void 0 : e.call(n);
1638
+ return t || `sse-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
1639
+ }
1640
+ function no() {
1641
+ const t = Ka(), n = zt();
1642
+ function e(l) {
1643
+ return Math.min(Ja * 2 ** l, Xa);
1644
+ }
1645
+ function a(l, s) {
1646
+ let o = null, d = null, g = 0, _ = !1;
1647
+ function f() {
1648
+ var u;
1649
+ const R = ((u = n.sessionUser.value) == null ? void 0 : u.token) ?? "";
1650
+ if (_ || !R) return;
1651
+ d && (clearTimeout(d), d = null);
1652
+ const U = t.getSubscribeUrl(vn, l.type, l.params), S = new ot(U, {
1653
+ fetch: (F, c) => fetch(F, {
1654
+ ...c,
1655
+ headers: {
1656
+ ...(c == null ? void 0 : c.headers) ?? {},
1657
+ authorization: `Bearer ${R}`
1658
+ }
1659
+ })
1660
+ });
1661
+ o = S, S.onopen = () => {
1662
+ g = 0;
1663
+ }, S.onmessage = (F) => {
1664
+ try {
1665
+ if (!F.data) return;
1666
+ const c = JSON.parse(F.data), r = c.data ? typeof c.data == "string" ? JSON.parse(c.data) : c.data : c;
1667
+ Promise.resolve(s(r)).catch((i) => {
1668
+ console.error("Failed to handle SSE message", i);
1669
+ });
1670
+ } catch (c) {
1671
+ console.error("Failed to parse SSE message", c);
1672
+ }
1673
+ }, S.onerror = () => {
1674
+ if (o === S && (o = null), S.close(), !_) {
1675
+ if (g >= eo) {
1676
+ console.warn("SSE subscription reconnect retries exhausted", l.type);
1677
+ return;
1678
+ }
1679
+ const F = e(g);
1680
+ g += 1, d = setTimeout(() => f(), F);
1681
+ }
1682
+ };
1683
+ }
1684
+ f();
1685
+ const I = t.getStatus(l.type, l.params).catch((R) => (console.error("Failed to fetch initial state", R), null));
1686
+ return {
1687
+ unsubscribe: () => {
1688
+ _ = !0, d && (clearTimeout(d), d = null), o && (o.close(), o = null);
1689
+ },
1690
+ initialState: I
1691
+ };
1692
+ }
1693
+ return {
1694
+ clientId: vn,
1695
+ subscribe: a
1696
+ };
1697
+ }
1698
+ function ao(t) {
1699
+ const n = it(), e = no(), a = rt(), l = Y(!1), s = Y(null);
1700
+ let o = !1, d = null, g = !1, _ = !1;
1701
+ function f() {
1702
+ u();
1703
+ const r = t.closingDraftId.value, i = t.currentRev.value;
1704
+ if (!r || !i)
1705
+ return;
1706
+ o = !1;
1707
+ const b = {
1708
+ type: "closing-draft",
1709
+ params: {
1710
+ draftId: r,
1711
+ locationId: n.getDbName(),
1712
+ closingDraftRevision: i
1713
+ }
1714
+ }, { unsubscribe: C, initialState: A } = e.subscribe(b, R);
1715
+ d = C, A.then((L) => {
1716
+ L != null && L.initialState && R(L.initialState);
1717
+ }).catch((L) => {
1718
+ console.error("Failed to fetch initial state", L);
1719
+ });
1720
+ }
1721
+ function I() {
1722
+ _ = !0, f();
1723
+ }
1724
+ async function R(r) {
1725
+ var i;
1726
+ if (o || !r) {
1727
+ s.value = r, l.value = !1;
1728
+ return;
1729
+ }
1730
+ if (!(r.closingDraftId && r.closingDraftId !== t.closingDraftId.value)) {
1731
+ if (s.value = r, r.message === "processing" || !r.completedAt && !r.message) {
1732
+ g = !0, l.value = !0;
1733
+ return;
1734
+ }
1735
+ if (r.message === "completed" || r.completedAt) {
1736
+ if (!g) {
1737
+ l.value = !1;
1738
+ return;
1739
+ }
1740
+ g = !1, await U();
1741
+ return;
1742
+ }
1743
+ g = !1, l.value = !1, a.open({
1744
+ title: "Refresh failed",
1745
+ message: "Failed to refresh stock balance. Please try again.",
1746
+ type: "error"
1747
+ }), (i = t.onError) == null || i.call(t, r.message ?? "Unknown error");
1748
+ }
1749
+ }
1750
+ async function U() {
1751
+ const r = t.closingDraftId.value;
1752
+ if (!r) {
1753
+ l.value = !1;
1754
+ return;
1755
+ }
1756
+ try {
1757
+ const i = await n.getDraft(r);
1758
+ l.value = !1, t.onCompleted(i), a.open({
1759
+ title: "Balance refreshed",
1760
+ message: "Stock balance has been recalculated.",
1761
+ type: "success"
1762
+ });
1763
+ } catch {
1764
+ l.value = !1, a.open({
1765
+ title: "Refresh completed",
1766
+ message: "Balance was refreshed but failed to load updated data. Please reload.",
1767
+ type: "warning"
1768
+ });
1769
+ }
1770
+ }
1771
+ async function S(r) {
1772
+ if (!(!t.closingDraftId.value || l.value || g)) {
1773
+ l.value = !0, g = !0, s.value = {
1774
+ requestId: "",
1775
+ closingDraftId: t.closingDraftId.value,
1776
+ closingDraftRevision: t.currentRev.value ?? "",
1777
+ message: "processing",
1778
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
1779
+ };
1780
+ try {
1781
+ await n.initializeStockSnapshot(t.closingDraftId.value, r);
1782
+ } catch (i) {
1783
+ g = !1, l.value = !1, a.open({
1784
+ title: "Refresh failed",
1785
+ message: "Failed to refresh stock balance. Please try again.",
1786
+ type: "error"
1787
+ }), console.error("error starting refresh", i);
1788
+ }
1789
+ }
1790
+ }
1791
+ function u() {
1792
+ o = !1, d && (d(), d = null);
1793
+ }
1794
+ function F() {
1795
+ u(), o = !0, l.value = !1, g = !1, s.value = null;
1796
+ }
1797
+ function c() {
1798
+ _ = !1, F();
1799
+ }
1800
+ return Qe(
1801
+ [t.closingDraftId, t.currentRev],
1802
+ ([r, i], [b, C]) => {
1803
+ _ && (r === b && i === C || f());
1804
+ }
1805
+ ), Un(() => {
1806
+ c();
1807
+ }), {
1808
+ refreshing: l,
1809
+ refreshStatus: s,
1810
+ startListening: I,
1811
+ startRefresh: S,
1812
+ cleanup: c
1813
+ };
1814
+ }
1815
+ const oo = { class: "w-full flex flex-col gap-32" }, so = { class: "flex flex-col gap-4" }, ro = { class: "flex justify-between" }, lo = { class: "flex" }, io = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, co = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, uo = { class: "flex gap-1" }, mo = {
1816
+ class: "fm-typo-en-body-lg-600",
1817
+ style: { "white-space": "pre-wrap", "word-break": "break-word" }
1818
+ }, fo = { class: "flex flex-col gap-16" }, po = { class: "flex items-center" }, vo = {
1819
+ key: 0,
1820
+ class: "flex gap-8"
1821
+ }, yo = {
1822
+ key: 0,
1823
+ class: "w-full flex flex-col items-center"
1824
+ }, go = { class: "flex items-center gap-8" }, ho = { class: "flex flex-col gap-8" }, bo = { class: "flex gap-8" }, _o = {
1825
+ key: 0,
1826
+ class: "flex gap-8"
1827
+ }, wo = {
1828
+ key: 1,
1829
+ class: "flex gap-8 flex-wrap"
1830
+ }, ko = { class: "overflow-x-auto" }, xo = {
1831
+ key: 1,
1832
+ class: "flex-1 xs:w-screen xs:max-w-full"
1833
+ }, Do = {
1834
+ key: 0,
1835
+ class: "flex flex-col items-center gap-8 h-full"
1836
+ }, Co = ["src"], So = {
1837
+ key: 1,
1838
+ class: "px-4 flex flex-col"
1839
+ }, Ao = { class: "flex gap-12 content-stretch" }, $o = {
1840
+ class: "flex flex-col w-24",
1841
+ name: "circles"
1842
+ }, Io = { class: "flex-1 flex flex-col items-center" }, To = { class: "flex-1 flex flex-col items-center" }, Fo = {
1843
+ class: "py-12 flex flex-col gap-4",
1844
+ name: "received-at header"
1845
+ }, Bo = { class: "fm-typo-en-body-lg-400" }, Eo = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, jo = { class: "flex gap-12 content-stretch" }, Ro = {
1846
+ class: "flex flex-col w-24",
1847
+ name: "circles"
1848
+ }, Mo = { class: "flex-1 flex flex-col items-center" }, No = {
1849
+ class: "py-12 flex flex-col gap-4 flex-1",
1850
+ name: "delivery details"
1851
+ }, Uo = { class: "flex flex-col gap-8" }, Po = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Vo = { class: "flex flex-col gap-4" }, Lo = { class: "flex items-center justify-between gap-8 w-full" }, Oo = { class: "flex items-center gap-8" }, zo = { class: "flex flex-col items-end" }, Wo = { class: "text-2xl font-semibold" }, yn = "N/A", Ho = /* @__PURE__ */ Le({
1852
+ __name: "ClosingDraftDialog",
1853
+ props: {
1854
+ show: { type: Boolean },
1855
+ draft: {}
1856
+ },
1857
+ emits: ["submitted", "refresh"],
1858
+ setup(t, { emit: n }) {
1859
+ const e = t, a = V(() => {
1860
+ const y = _n();
1861
+ return y === "MYR" ? "RM" : y;
1862
+ }), l = Tn(), s = V(() => {
1863
+ var y, v;
1864
+ return (y = e.draft) != null && y.closingId ? ((v = l.drafts.find((k) => k._id === e.draft._id)) == null ? void 0 : v.closingIdDisplay) ?? null : null;
1865
+ }), o = wt(), d = hn(e, "show"), g = Y(!1), _ = Y(!1), f = Y(new Array()), I = Y(new Array()), R = Y([]), U = Dt(), S = rt(), u = Wt(), F = lt(), c = cn({}), r = V(() => new Set(
1866
+ u.skus.filter((y) => {
1867
+ var v;
1868
+ return c[(v = y.customAttributes) == null ? void 0 : v.tag];
1869
+ }).map((y) => y._id)
1870
+ )), i = n, b = V(() => {
1871
+ var y;
1872
+ return (y = e.draft) == null ? void 0 : y._id;
1873
+ }), C = V(() => {
1874
+ var y;
1875
+ return (y = e.draft) == null ? void 0 : y._rev;
1876
+ }), {
1877
+ refreshing: A,
1878
+ startListening: L,
1879
+ startRefresh: se,
1880
+ cleanup: re
1881
+ } = ao({
1882
+ closingDraftId: b,
1883
+ currentRev: C,
1884
+ onCompleted: (y) => {
1885
+ i("refresh", y), f.value = y.stockSnapshot ?? [], d.value = !1;
1886
+ }
1887
+ }), O = Y({
1888
+ templateItem: !0,
1889
+ nonTemplateItem: !0
1890
+ }), me = V(() => {
1891
+ var v, k;
1892
+ const y = [...((v = e.draft) == null ? void 0 : v.items) ?? [], ...((k = e.draft) == null ? void 0 : k.negativeStockItems) ?? []];
1893
+ return r.value.size ? y.filter((h) => r.value.has(h.sku._id)) : y;
1894
+ }), N = V(() => {
1895
+ const y = me.value.map((v) => v.sku);
1896
+ return y.sort((v, k) => v.code.localeCompare(k.code)), y;
1897
+ }), E = V(() => me.value.groupBy(
1898
+ (v) => v.sku._id,
1899
+ (v) => v.measurementsAmounts.filter((k) => !k.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((k) => k.measurement.id)
1900
+ ));
1901
+ Lt(J), Qe(
1902
+ () => e.show,
1903
+ async (y) => {
1904
+ if (!y) {
1905
+ re();
1906
+ return;
1907
+ }
1908
+ Xe.value = St[0], J(), O.value = {
1909
+ templateItem: !0,
1910
+ nonTemplateItem: !0
1911
+ }, L();
1912
+ },
1913
+ { immediate: !0 }
1914
+ );
1915
+ const ie = V(() => Kt.value.reduce((y, v) => y + Number(v.stockTakeValue), 0)), D = st(0), X = st(100);
1916
+ async function J() {
1917
+ var v, k, h, w;
1918
+ if (!F._currentLocation) return;
1919
+ g.value = !0;
1920
+ const y = ((v = e.draft) == null ? void 0 : v.status) === Te.enum.COMPLETED;
1921
+ I.value = [];
1922
+ try {
1923
+ if (await u.init(), y) {
1924
+ const ee = e.draft.closingAdjustmentId;
1925
+ if (!ee) {
1926
+ S.open({
1927
+ title: "Something went wrong",
1928
+ message: "Closing draft is completed but closing document cannot be found.",
1929
+ type: "error"
1930
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
1931
+ draftId: (k = e.draft) == null ? void 0 : k._id
1932
+ });
1933
+ return;
1934
+ }
1935
+ const Q = await U.readAdjustmentById(ee), be = (Q == null ? void 0 : Q.skus) ?? [];
1936
+ for (const we of be) {
1937
+ const Ne = {
1938
+ id: we.sku._id,
1939
+ balance: we.fromBalance,
1940
+ costs: we.fromCostBalances
1941
+ }, P = {
1942
+ id: we.sku._id,
1943
+ balance: we.toBalance,
1944
+ costs: we.toCostBalances
1945
+ };
1946
+ f.value.push(Ne), I.value.push(P);
1947
+ }
1948
+ } else
1949
+ f.value = ((h = e.draft) == null ? void 0 : h.stockSnapshot) ?? [];
1950
+ const $ = /* @__PURE__ */ new Set();
1951
+ if ((w = e.draft) != null && w.adjustmentSnapshot)
1952
+ for (const ee of e.draft.adjustmentSnapshot)
1953
+ ee.adjustmentsByType && Object.keys(ee.adjustmentsByType).forEach((Q) => {
1954
+ $.add(Q);
1955
+ });
1956
+ const j = ["receive", "sales", "wastage"], H = [];
1957
+ j.forEach((ee) => {
1958
+ $.has(ee) && (H.push(ee), $.delete(ee));
1959
+ });
1960
+ const K = Array.from($).sort();
1961
+ R.value = [...H, ...K];
1962
+ } catch ($) {
1963
+ S.open({
1964
+ title: "Something went wrong",
1965
+ message: "Something went wrong when fetching info. Please try again.",
1966
+ type: "error"
1967
+ }), console.error("error on fetch stock balances", $);
1968
+ } finally {
1969
+ g.value = !1;
1970
+ }
1971
+ }
1972
+ async function ve() {
1973
+ var v, k;
1974
+ if (A.value)
1975
+ return;
1976
+ if (!(((v = e.draft) == null ? void 0 : v.effectiveAt) ?? (e.draft ? Ve((k = e.draft) == null ? void 0 : k._id) : null))) {
1977
+ S.open({
1978
+ title: "Cannot refresh",
1979
+ message: "Effective date is not available for this draft.",
1980
+ type: "error"
1981
+ });
1982
+ return;
1983
+ }
1984
+ await o.refreshBalance(
1985
+ e.draft,
1986
+ () => {
1987
+ },
1988
+ async (h) => {
1989
+ await se(h);
1990
+ }
1991
+ );
1992
+ }
1993
+ async function Oe() {
1994
+ var v, k;
1995
+ if (!(((v = e.draft) == null ? void 0 : v.effectiveAt) ?? (e.draft ? Ve((k = e.draft) == null ? void 0 : k._id) : null))) {
1996
+ S.open({
1997
+ title: "Cannot refresh",
1998
+ message: "Effective date is not available for this draft.",
1999
+ type: "error"
2000
+ });
2001
+ return;
2002
+ }
2003
+ await o.invalidateDraftCache(e.draft);
2004
+ }
2005
+ const Ae = V(
2006
+ () => f.value.groupBy(
2007
+ (y) => y.id,
2008
+ (y) => y.balance
2009
+ )
2010
+ ), je = V(() => me.value.groupBy((y) => y.sku._id)), Re = V(() => {
2011
+ var y;
2012
+ return (y = e.draft) != null && y.adjustmentSnapshot ? new Map(e.draft.adjustmentSnapshot.map((v) => [v.skuId, v.adjustmentsByType])) : /* @__PURE__ */ new Map();
2013
+ }), ct = V(() => {
2014
+ var y;
2015
+ return (y = e.draft) != null && y.opening ? new Map(e.draft.opening.map((v) => [v.skuId, v.balance])) : /* @__PURE__ */ new Map();
2016
+ });
2017
+ function ye(y, v) {
2018
+ return T(
2019
+ Ce.FmTooltip,
2020
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
2021
+ {
2022
+ default() {
2023
+ return y;
2024
+ },
2025
+ content() {
2026
+ return v || y;
2027
+ }
2028
+ }
2029
+ );
2030
+ }
2031
+ const Me = V(() => {
2032
+ const y = N.value.reduce((k, h) => {
2033
+ var w, $;
2034
+ return Math.max(k, (($ = (w = E.value) == null ? void 0 : w.get(h._id)) == null ? void 0 : $[0].length) ?? 0);
2035
+ }, 0);
2036
+ return [
2037
+ {
2038
+ id: "sku",
2039
+ accessorFn: (k) => `${k.code} ${k.name}`,
2040
+ header: () => "Name",
2041
+ size: 350,
2042
+ cell(k) {
2043
+ const h = k.row.original, w = h.adjustedDiffPercentage, $ = typeof w == "number" && Math.abs(w) > 10, j = T("div", { class: "flex flex-col gap-4" }, [
2044
+ T(
2045
+ "div",
2046
+ {
2047
+ class: [
2048
+ "line-clamp-1 fm-typo-en-body-lg-400",
2049
+ $ ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
2050
+ ]
2051
+ },
2052
+ h.name
2053
+ ),
2054
+ T(
2055
+ "div",
2056
+ {
2057
+ class: [
2058
+ "line-clamp-1 fm-typo-en-body-md-400",
2059
+ $ ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
2060
+ ]
2061
+ },
2062
+ h.code
2063
+ )
2064
+ ]);
2065
+ return T(
2066
+ Ce.FmTooltip,
2067
+ {
2068
+ zIndex: 51
2069
+ },
2070
+ {
2071
+ content() {
2072
+ return $ ? "Adjustment difference is more than 10%." : `${h.code} - ${h.name}`;
2073
+ },
2074
+ default() {
2075
+ return T("div", { class: "flex items-center gap-4 justify-start w-full" }, [
2076
+ j
2077
+ ]);
2078
+ }
2079
+ }
2080
+ );
2081
+ }
2082
+ },
2083
+ // Dynamic custom attribute columns (toggled by user)
2084
+ ...qt.value.map(
2085
+ (k) => ({
2086
+ id: `customAttr_${k}`,
2087
+ accessorFn: (h) => h.customAttributeValues[k],
2088
+ header: () => ye(Pe(k)),
2089
+ size: 160,
2090
+ cell(h) {
2091
+ const w = h.row.original.customAttributeValues[k];
2092
+ return w == null ? "N/A" : typeof w == "number" ? T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(w)) : T("div", { class: "text-right fm-typo-en-body-lg-400" }, String(w));
2093
+ },
2094
+ meta: {
2095
+ textAlign: "right"
2096
+ }
2097
+ })
2098
+ ),
2099
+ {
2100
+ id: "costPerUnit",
2101
+ accessorKey: "costPerUnit",
2102
+ header: () => ye("Cost per unit"),
2103
+ size: 160,
2104
+ cell(k) {
2105
+ const h = k.row.original.costPerUnit;
2106
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(h));
2107
+ },
2108
+ meta: {
2109
+ textAlign: "right"
2110
+ }
2111
+ },
2112
+ {
2113
+ id: "costUnit",
2114
+ header: () => "UOM",
2115
+ size: 120,
2116
+ cell(k) {
2117
+ var H;
2118
+ const h = k.row.original, w = h.costUnit, $ = h.baseUnit, j = w ?? $;
2119
+ if (w && w !== $) {
2120
+ const K = N.value.find((Q) => Q._id === h.id), ee = (H = K == null ? void 0 : K.defaultCost) == null ? void 0 : H.measurement;
2121
+ if (ee) {
2122
+ const Q = ee.conversion.amount / Math.pow(10, ee.conversion.precision);
2123
+ return T("div", { class: "flex flex-col" }, [
2124
+ T(
2125
+ "span",
2126
+ { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
2127
+ j
2128
+ ),
2129
+ T("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, [
2130
+ "1 ",
2131
+ T("span", { class: "fm-typo-en-body-sm-600" }, w),
2132
+ ` = ${Q} `,
2133
+ T("span", { class: "fm-typo-en-body-sm-600" }, $)
2134
+ ])
2135
+ ]);
2136
+ }
2137
+ }
2138
+ return j;
2139
+ }
2140
+ },
2141
+ {
2142
+ id: "opening",
2143
+ accessorKey: "opening",
2144
+ header: () => ye("Opening (B/F)", "The opening balance brought forward from previous period."),
2145
+ size: 150,
2146
+ cell(k) {
2147
+ const h = k.row.original.opening;
2148
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(h));
2149
+ },
2150
+ meta: {
2151
+ textAlign: "right"
2152
+ }
2153
+ },
2154
+ // Dynamic adjustment type columns
2155
+ ...R.value.map(
2156
+ (k) => ({
2157
+ id: `adjustment_${k}`,
2158
+ accessorFn: (h) => h.adjustmentAmounts[k] ?? { amount: 0, precision: 0 },
2159
+ header: () => ye(Pe(k)),
2160
+ size: 150,
2161
+ cell(h) {
2162
+ const w = h.row.original.adjustmentAmounts[k] ?? { amount: 0, precision: 0 };
2163
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(w));
2164
+ },
2165
+ meta: {
2166
+ textAlign: "right"
2167
+ }
2168
+ })
2169
+ ),
2170
+ {
2171
+ id: "systemBalance",
2172
+ accessorKey: "systemBalance",
2173
+ header: () => ye("System Balance", "The system calculated balance before stock take."),
2174
+ size: 200,
2175
+ cell(k) {
2176
+ const h = k.row.original.systemBalance;
2177
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(h));
2178
+ },
2179
+ meta: {
2180
+ textAlign: "right"
2181
+ }
2182
+ },
2183
+ {
2184
+ id: "physicalBalance",
2185
+ accessorFn: (k) => {
2186
+ var w;
2187
+ const h = (w = I.value.find(($) => $.id === k.id)) == null ? void 0 : w.balance;
2188
+ return h ? ra.toDouble(h) : k.physicalBalance;
2189
+ },
2190
+ header: () => ye("Stock Take balance", "The physical balance recorded during stock take."),
2191
+ cell(k) {
2192
+ var K;
2193
+ const h = k.row.original, w = te.fromNumber(h.physicalBalance);
2194
+ let $ = !0;
2195
+ const j = (K = I.value.find((ee) => ee.id === h.id)) == null ? void 0 : K.balance;
2196
+ let H;
2197
+ return j && !te.equals({ a: w, b: j }) ? ($ = !1, H = ae(j)) : H = ae(h.physicalBalance), T("div", { class: "flex flex-col" }, [
2198
+ T(
2199
+ "span",
2200
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
2201
+ H
2202
+ ),
2203
+ $ ? null : T(
2204
+ "span",
2205
+ { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
2206
+ `Draft: ${ae(h.physicalBalance)}`
2207
+ )
2208
+ ]);
2209
+ },
2210
+ size: 200,
2211
+ meta: {
2212
+ textAlign: "right"
2213
+ }
2214
+ },
2215
+ {
2216
+ id: "adjustedAmount",
2217
+ accessorKey: "adjustedAmount",
2218
+ header: () => ye("Variance", "The difference between Stock Take balance and System Balance."),
2219
+ size: 200,
2220
+ cell(k) {
2221
+ const h = k.row.original.adjustedAmount;
2222
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(h));
2223
+ },
2224
+ meta: {
2225
+ textAlign: "right"
2226
+ }
2227
+ },
2228
+ {
2229
+ id: "varianceInCost",
2230
+ accessorKey: "varianceInCost",
2231
+ header: () => ye(`Variance (${a.value})`),
2232
+ size: 150,
2233
+ cell(k) {
2234
+ const h = k.row.original.varianceInCost;
2235
+ return T("div", { class: "text-right fm-typo-en-body-lg-400" }, ae(h));
2236
+ },
2237
+ meta: {
2238
+ textAlign: "right"
2239
+ }
2240
+ },
2241
+ {
2242
+ id: "adjustedDiffPercentage",
2243
+ accessorKey: "adjustedDiffPercentage",
2244
+ header: () => ye(
2245
+ "Variance (%)",
2246
+ "Difference between Stock Take balance and System Balance in percentage."
2247
+ ),
2248
+ size: 200,
2249
+ cell(k) {
2250
+ const h = k.row.original.adjustedDiffPercentage;
2251
+ if (h == null)
2252
+ return T(
2253
+ "div",
2254
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" },
2255
+ yn
2256
+ );
2257
+ const w = ae(h);
2258
+ if (h === 0)
2259
+ return T("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
2260
+ ae(0)
2261
+ ]);
2262
+ const $ = h > 0;
2263
+ return T("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
2264
+ T(Ce.FmIcon, {
2265
+ name: $ ? "arrow_drop_up" : "arrow_drop_down",
2266
+ color: $ ? "system-success-300" : "system-error-300",
2267
+ size: "md"
2268
+ }),
2269
+ w
2270
+ ]);
2271
+ },
2272
+ meta: {
2273
+ textAlign: "right"
2274
+ }
2275
+ },
2276
+ {
2277
+ id: "stockTakeValue",
2278
+ accessorKey: "stockTakeValue",
2279
+ header: () => ye(`Stock take value (${a.value})`),
2280
+ size: 180,
2281
+ cell(k) {
2282
+ var ee;
2283
+ const h = k.row.original, w = h.stockTakeValue, $ = N.value.find((Q) => Q._id === h.id), j = (ee = $ == null ? void 0 : $.defaultCost) == null ? void 0 : ee.measurement, H = h.physicalBalance, K = h.costPerUnit;
2284
+ if (j) {
2285
+ const Q = te.toFormatString({ value: j.conversion }), be = `${ae(H, { minPrecision: 2, maxPrecision: 4 })} ${h.baseUnit} ÷ ${Q} × ${K} ${a.value}`;
2286
+ return T(
2287
+ Ce.FmTooltip,
2288
+ { zIndex: 51 },
2289
+ {
2290
+ content() {
2291
+ return be;
2292
+ },
2293
+ default() {
2294
+ return T(
2295
+ "div",
2296
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
2297
+ ae(w)
2298
+ );
2299
+ }
2300
+ }
2301
+ );
2302
+ } else {
2303
+ const Q = `${ae(H, { minPrecision: 2, maxPrecision: 4 })} ${h.baseUnit} × ${K} ${a.value}`;
2304
+ return T(
2305
+ Ce.FmTooltip,
2306
+ { zIndex: 51 },
2307
+ {
2308
+ content() {
2309
+ return Q;
2310
+ },
2311
+ default() {
2312
+ return T(
2313
+ "div",
2314
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
2315
+ ae(w)
2316
+ );
2317
+ }
2318
+ }
2319
+ );
2320
+ }
2321
+ },
2322
+ meta: {
2323
+ textAlign: "right"
2324
+ }
2325
+ },
2326
+ {
2327
+ id: "systemValue",
2328
+ accessorKey: "systemValue",
2329
+ header: () => ye(`System value (${a.value})`),
2330
+ size: 180,
2331
+ cell(k) {
2332
+ var ee;
2333
+ const h = k.row.original, w = h.systemValue, $ = N.value.find((Q) => Q._id === h.id), j = (ee = $ == null ? void 0 : $.defaultCost) == null ? void 0 : ee.measurement, H = h.systemBalance, K = h.costPerUnit;
2334
+ if (j) {
2335
+ const Q = te.toFormatString({ value: j.conversion }), be = `${ae(H, { minPrecision: 2, maxPrecision: 4 })} ${h.baseUnit} ÷ ${Q} × ${K} ${a.value}`;
2336
+ return T(
2337
+ Ce.FmTooltip,
2338
+ { zIndex: 51 },
2339
+ {
2340
+ content() {
2341
+ return be;
2342
+ },
2343
+ default() {
2344
+ return T(
2345
+ "div",
2346
+ { class: "text-right fm-typo-en-body-lg-400" },
2347
+ ae(w)
2348
+ );
2349
+ }
2350
+ }
2351
+ );
2352
+ } else {
2353
+ const Q = `${ae(H, { minPrecision: 2, maxPrecision: 4 })} ${h.baseUnit} × ${K} ${a.value}`;
2354
+ return T(
2355
+ Ce.FmTooltip,
2356
+ { zIndex: 51 },
2357
+ {
2358
+ content() {
2359
+ return Q;
2360
+ },
2361
+ default() {
2362
+ return T(
2363
+ "div",
2364
+ { class: "text-right fm-typo-en-body-lg-400" },
2365
+ ae(w)
2366
+ );
2367
+ }
2368
+ }
2369
+ );
2370
+ }
2371
+ },
2372
+ meta: {
2373
+ textAlign: "right"
2374
+ }
2375
+ },
2376
+ {
2377
+ id: "physicalBalances",
2378
+ header: () => "Amounts",
2379
+ enableSorting: !1,
2380
+ cell(k) {
2381
+ const h = k.row.original, w = (j, H) => T(
2382
+ Ce.FmTooltip,
2383
+ { zIndex: 50 },
2384
+ {
2385
+ default() {
2386
+ return T(
2387
+ "div",
2388
+ {
2389
+ class: "fm-typo-en-body-lg-400 py-4 px-8 border-1 border-fm-color-typo-secondary fm-corner-radius-md line-clamp-1"
2390
+ },
2391
+ [
2392
+ T("span", { class: "text-fm-color-typo-primary" }, `${j} `),
2393
+ T(
2394
+ "span",
2395
+ {
2396
+ class: "text-fm-color-typo-secondary",
2397
+ style: { maxWidth: "80px" }
2398
+ },
2399
+ H
2400
+ )
2401
+ ]
2402
+ );
2403
+ },
2404
+ content() {
2405
+ return `${j} ${H}`;
2406
+ }
2407
+ }
2408
+ );
2409
+ let $ = Array.from({ length: y }).map((j, H) => {
2410
+ if (!h[`measurementAmount${H}`])
2411
+ return null;
2412
+ const K = h[`measurementAmount${H}`], ee = h[`measurementAbbrev${H}`];
2413
+ return w(K, ee);
2414
+ }).filter((j) => j);
2415
+ return (h.baseUnitAmount || !$.length) && ($ = [w(h.baseUnitAmount, h.baseUnit), ...$]), T(
2416
+ "div",
2417
+ {
2418
+ class: "flex gap-8 flex-nowrap",
2419
+ style: {
2420
+ minWidth: `${120 * $.length}px`
2421
+ }
2422
+ },
2423
+ $
2424
+ );
2425
+ }
2426
+ }
2427
+ ];
2428
+ }), ut = V(() => Me.value.map((y) => y.size ?? 0).reduce((y, v) => y + v)), Je = Y(""), Kt = V(() => {
2429
+ var k, h;
2430
+ const y = ((h = (k = e.draft) == null ? void 0 : k.negativeStockItems) == null ? void 0 : h.reduce(
2431
+ (w, $) => (w[$.sku._id] = $, w),
2432
+ {}
2433
+ )) ?? {};
2434
+ return N.value.map((w) => {
2435
+ var Zt, Jt, Xt, en, tn, nn, an, on, sn, rn, ln;
2436
+ const $ = (Zt = je.value.get(w._id)) == null ? void 0 : Zt[0], j = ((Jt = Ae.value.get(w._id)) == null ? void 0 : Jt[0]) ?? D, H = ((Xt = w.defaultCost) == null ? void 0 : Xt.costPerUnit) ?? D, K = Number(te.toFormatString({ value: H })), ee = ((tn = (en = w.defaultCost) == null ? void 0 : en.measurement) == null ? void 0 : tn.conversion) ?? {
2437
+ amount: 1,
2438
+ precision: 0
2439
+ }, Q = Number(
2440
+ te.toFormatString({ value: ee })
2441
+ ), be = ct.value.get(w._id), we = be ? Number(te.toFormatString({ value: be })) : 0, Ne = Re.value.get(w._id), P = {};
2442
+ if (R.value.forEach((fe) => {
2443
+ const ke = P[fe] ?? { amount: 0, precision: 0 }, De = Ne == null ? void 0 : Ne[fe];
2444
+ De && (P[fe] = Sn(ke, De));
2445
+ }), !$) {
2446
+ const fe = Number(te.toFormatString({ value: j })), ke = 0 - fe, De = ke * K / Q, vt = 0, Nn = fe * K / Q;
2447
+ return {
2448
+ id: w._id,
2449
+ code: w.code,
2450
+ name: w.name,
2451
+ costUnit: ((an = (nn = w.defaultCost) == null ? void 0 : nn.measurement) == null ? void 0 : an.abbrev) ?? null,
2452
+ baseUnit: w.unit.abbrev,
2453
+ baseUnitAmount: 0,
2454
+ systemBalance: fe,
2455
+ physicalBalance: 0,
2456
+ adjustedAmount: -fe,
2457
+ adjustedDiffPercentage: -100,
2458
+ isTemplateItem: !y[w._id],
2459
+ costPerUnit: K,
2460
+ opening: we,
2461
+ varianceQty: ke,
2462
+ varianceInCost: De,
2463
+ stockTakeValue: vt,
2464
+ systemValue: Nn,
2465
+ adjustmentAmounts: P,
2466
+ customAttributeValues: w.customAttributes ?? {}
2467
+ };
2468
+ }
2469
+ const de = $n($), ge = (sn = (on = I.value) == null ? void 0 : on.find(
2470
+ (fe) => fe.id === w._id
2471
+ )) == null ? void 0 : sn.balance, $e = Dn(
2472
+ ge ?? de,
2473
+ j
2474
+ ), We = j.amount === 0 ? null : Cn($e, {
2475
+ ...j,
2476
+ amount: Math.abs(j.amount)
2477
+ }), pt = We ? Ht(We, X) : null, At = Number(te.toFormatString({ value: j })), $t = Number(te.toFormatString({ value: de })), Qt = $t - At, jn = Qt * K / Q, Rn = $t * K / Q, Mn = At * K / Q;
2478
+ return {
2479
+ id: w._id,
2480
+ code: w.code,
2481
+ name: w.name,
2482
+ costUnit: ((ln = (rn = w.defaultCost) == null ? void 0 : rn.measurement) == null ? void 0 : ln.abbrev) ?? null,
2483
+ baseUnit: w.unit.abbrev,
2484
+ baseUnitAmount: Number(te.toFormatString({ value: $.baseAmount })),
2485
+ ...$.measurementsAmounts.filter((fe) => {
2486
+ var ke, De, vt;
2487
+ return (vt = (De = (ke = E.value) == null ? void 0 : ke.get(w._id)) == null ? void 0 : De[0]) == null ? void 0 : vt.includes(fe.measurement.id);
2488
+ }).reduce((fe, ke, De) => (fe[`measurementAbbrev${De}`] = `(${ke.measurement.abbrev}) × ${te.toFormatString({ value: ke.measurement.conversion })}`, fe[`measurementAmount${De}`] = Number(te.toFormatString({ value: ke.amount })), fe), {}),
2489
+ systemBalance: At,
2490
+ physicalBalance: $t,
2491
+ adjustedAmount: Number(te.toFormatString({ value: $e })),
2492
+ adjustedDiffPercentage: pt ? Number(
2493
+ te.toFormatString({
2494
+ value: An(pt, 2)
2495
+ })
2496
+ ) : null,
2497
+ isTemplateItem: !y[w._id],
2498
+ costPerUnit: K,
2499
+ opening: we,
2500
+ varianceQty: Qt,
2501
+ varianceInCost: jn,
2502
+ stockTakeValue: Rn,
2503
+ systemValue: Mn,
2504
+ adjustmentAmounts: P,
2505
+ customAttributeValues: w.customAttributes ?? {}
2506
+ };
2507
+ }).filter((w) => !!(w.isTemplateItem && O.value.templateItem || !w.isTemplateItem && O.value.nonTemplateItem));
2508
+ }), Ct = V(() => {
2509
+ const y = /* @__PURE__ */ new Set();
2510
+ for (const v of N.value)
2511
+ if (v.customAttributes)
2512
+ for (const k of Object.keys(v.customAttributes))
2513
+ k !== "tag" && y.add(k);
2514
+ return Array.from(y).sort();
2515
+ }), dt = cn({}), qt = V(
2516
+ () => Ct.value.filter((y) => dt[y])
2517
+ ), Bn = V(() => {
2518
+ var v, k, h, w, $;
2519
+ if (!e.draft) return [];
2520
+ const y = e.draft.approvedAt ? {
2521
+ action: `Approve at ${Fe(e.draft.approvedAt)}`,
2522
+ // actionAt: props.draft.approvedAt,
2523
+ actionBy: e.draft.approvedBy,
2524
+ remark: e.draft.approveRemark
2525
+ } : (v = e.draft.rejectionHistory) == null ? void 0 : v.computeFirst((j) => ({
2526
+ action: `Reject at ${Fe(j.rejectedAt)}`,
2527
+ // actionAt: e.rejectedAt,
2528
+ actionBy: j.rejectedBy,
2529
+ remark: j.rejectRemark
2530
+ }));
2531
+ return [
2532
+ s.value ? {
2533
+ label: "ID",
2534
+ value: s.value
2535
+ } : null,
2536
+ {
2537
+ label: "Location",
2538
+ value: ((k = F._currentLocation) == null ? void 0 : k.name) ?? yn
2539
+ },
2540
+ {
2541
+ label: "Created at",
2542
+ value: Fe(e.draft.createdAt)
2543
+ },
2544
+ {
2545
+ label: "Created by",
2546
+ value: e.draft.createdBy.name
2547
+ },
2548
+ {
2549
+ label: "Updated at",
2550
+ value: Fe(e.draft.updatedAt)
2551
+ },
2552
+ {
2553
+ label: "Updated by",
2554
+ value: e.draft.updatedBy.name
2555
+ },
2556
+ {
2557
+ label: "Effective at",
2558
+ value: Fe(e.draft.effectiveAt ?? Ve((h = e.draft) == null ? void 0 : h._id))
2559
+ },
2560
+ {
2561
+ label: "Using template",
2562
+ value: ((w = e.draft.usingTemplates.find((j) => j)) == null ? void 0 : w.name) ?? "None"
2563
+ },
2564
+ e.draft.remark ? {
2565
+ label: "Remark",
2566
+ value: e.draft.remark
2567
+ } : null,
2568
+ y ? {
2569
+ label: "Last action",
2570
+ value: y.action
2571
+ } : null,
2572
+ y && y.actionBy ? {
2573
+ label: "Last action by",
2574
+ value: ($ = y.actionBy) == null ? void 0 : $.name
2575
+ } : null,
2576
+ y && y.remark ? {
2577
+ label: "Action remark",
2578
+ value: y.remark
2579
+ } : null
2580
+ ].filter((j) => j).map((j) => j);
2581
+ }), St = [
2582
+ {
2583
+ label: "Overview",
2584
+ value: "overview"
2585
+ },
2586
+ {
2587
+ label: "Action history",
2588
+ value: "history"
2589
+ }
2590
+ ], Xe = Y(St[0]), ze = V(() => {
2591
+ var h, w, $;
2592
+ const y = ((h = e.draft) == null ? void 0 : h.activityLogs) ?? [], v = ((w = e.draft) == null ? void 0 : w.rejectionHistory) ?? [];
2593
+ for (const j of v)
2594
+ y.find(
2595
+ (K) => `${K.action}_${K.performedAt}` == `${le.enum.rejectDraft}_${j.rejectedAt}`
2596
+ ) || y.push({
2597
+ action: le.enum.rejectDraft,
2598
+ performedAt: j.rejectedAt,
2599
+ performedBy: j.rejectedBy,
2600
+ remark: j.rejectRemark
2601
+ });
2602
+ return ($ = e.draft) != null && $.approvedAt && (y.find(
2603
+ (H) => {
2604
+ var K;
2605
+ return `${H.action}_${H.performedAt}` == `${le.enum.approveDraft}_${(K = e.draft) == null ? void 0 : K.approvedAt}`;
2606
+ }
2607
+ ) || y.push({
2608
+ action: le.enum.approveDraft,
2609
+ performedAt: e.draft.approvedAt,
2610
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
2611
+ remark: e.draft.approveRemark
2612
+ })), y.sort((j, H) => new Date(H.performedAt).getTime() - new Date(j.performedAt).getTime()).map(
2613
+ (j) => ({
2614
+ header: Pe(j.action),
2615
+ date: Fe(j.performedAt),
2616
+ info: [
2617
+ {
2618
+ label: "Performed by",
2619
+ values: [j.performedBy.name]
2620
+ },
2621
+ {
2622
+ label: "Remark",
2623
+ values: [j.remark ?? ""]
2624
+ }
2625
+ ]
2626
+ })
2627
+ );
2628
+ }), mt = Y(!1), ft = Y(!1), Gt = V(() => {
2629
+ var y;
2630
+ return ((y = e.draft) == null ? void 0 : y.status) !== Te.enum.DRAFT ? "Status is not draft." : null;
2631
+ });
2632
+ function En() {
2633
+ e.draft && (ft.value = !0, o.approveDraft(
2634
+ e.draft,
2635
+ () => {
2636
+ ft.value = !1, mt.value = !1, i("submitted");
2637
+ },
2638
+ () => {
2639
+ ft.value = !1;
2640
+ }
2641
+ ));
2642
+ }
2643
+ return (y, v) => {
2644
+ const k = G("FmButtonGroup"), h = G("FmMenuDivider"), w = G("FmCard"), $ = G("FmButton"), j = G("FmCircularProgress"), H = G("FmChip"), K = G("FmTextField"), ee = G("FmIcon"), Q = G("FmTable"), be = G("FmSpacer"), we = G("FmTooltip"), Ne = G("FmSideSheet");
2645
+ return x(), M(ue, null, [
2646
+ B(Ne, {
2647
+ "dismiss-away": "",
2648
+ "max-width": 9999,
2649
+ "model-value": p(d),
2650
+ "onUpdate:modelValue": v[9] || (v[9] = (P) => Ot(d) ? d.value = P : null),
2651
+ header: "Closing details"
2652
+ }, {
2653
+ "side-sheet-footer": Z(() => {
2654
+ var P, de, ge, $e;
2655
+ return [
2656
+ m("div", Lo, [
2657
+ m("div", Oo, [
2658
+ ((P = e.draft) == null ? void 0 : P.status) === p(Te).enum.DRAFT ? (x(), M(ue, { key: 0 }, [
2659
+ Gt.value ? (x(), ne(we, {
2660
+ key: 0,
2661
+ "z-index": 51,
2662
+ placement: "right"
2663
+ }, {
2664
+ content: Z(() => [
2665
+ pe(W(Gt.value), 1)
2666
+ ]),
2667
+ default: Z(() => [
2668
+ B($, {
2669
+ disabled: "",
2670
+ key: "approve key",
2671
+ label: "Approve"
2672
+ })
2673
+ ]),
2674
+ _: 1
2675
+ })) : (x(), ne($, {
2676
+ key: "approve key",
2677
+ label: "Approve",
2678
+ onClick: v[5] || (v[5] = (We) => mt.value = !0)
2679
+ }))
2680
+ ], 64)) : q("", !0),
2681
+ ((de = e.draft) == null ? void 0 : de.status) === p(Te).enum.DRAFT ? (x(), ne($, {
2682
+ key: 1,
2683
+ label: "Reject",
2684
+ variant: "destructive",
2685
+ onClick: v[6] || (v[6] = () => e.draft && p(o).rejectDraft(e.draft, () => i("submitted")))
2686
+ })) : q("", !0),
2687
+ B($, {
2688
+ label: "Close",
2689
+ variant: "tertiary",
2690
+ onClick: v[7] || (v[7] = (We) => d.value = !1)
2691
+ }),
2692
+ (ge = e.draft) != null && ge.approvedAt && (($e = e.draft) == null ? void 0 : $e.status) !== p(Te).enum.COMPLETED ? (x(), ne(It, { key: 2 }, {
2693
+ default: Z(() => [
2694
+ B($, {
2695
+ label: "Sync",
2696
+ loading: _.value,
2697
+ onClick: v[8] || (v[8] = () => {
2698
+ e.draft && (_.value = !0, p(o).syncDraft(e.draft, () => {
2699
+ _.value = !1, i("submitted");
2700
+ }));
2701
+ })
2702
+ }, null, 8, ["loading"])
2703
+ ]),
2704
+ _: 1
2705
+ })) : q("", !0)
2706
+ ]),
2707
+ m("div", zo, [
2708
+ v[21] || (v[21] = m("div", { class: "text-xs text-gray-500 uppercase tracking-wide" }, "Total stock take value", -1)),
2709
+ m("div", Wo, W(a.value) + " " + W(ie.value.toFixed(2)), 1)
2710
+ ])
2711
+ ])
2712
+ ];
2713
+ }),
2714
+ default: Z(() => [
2715
+ m("div", oo, [
2716
+ m("div", null, [
2717
+ B(k, {
2718
+ items: St,
2719
+ modelValue: Xe.value,
2720
+ "onUpdate:modelValue": v[0] || (v[0] = (P) => Xe.value = P)
2721
+ }, null, 8, ["modelValue"])
2722
+ ]),
2723
+ Xe.value.value === "overview" ? (x(), M(ue, { key: 0 }, [
2724
+ B(It, { selectable: "" }, {
2725
+ default: Z(() => {
2726
+ var P;
2727
+ return [
2728
+ m("div", so, [
2729
+ v[11] || (v[11] = m("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, [
2730
+ m("div", { class: "flex gap-1" }, "Draft ID")
2731
+ ], -1)),
2732
+ pe(" " + W((P = y.draft) == null ? void 0 : P._id), 1)
2733
+ ])
2734
+ ];
2735
+ }),
2736
+ _: 1
2737
+ }),
2738
+ B(w, {
2739
+ variant: "outlined",
2740
+ class: "flex flex-col gap-8 px-12 py-16"
2741
+ }, {
2742
+ default: Z(() => {
2743
+ var P, de;
2744
+ return [
2745
+ m("div", ro, [
2746
+ v[12] || (v[12] = m("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
2747
+ m("div", lo, [
2748
+ m("div", {
2749
+ class: Be(["fm-status-badge", p(ht)(((P = y.draft) == null ? void 0 : P.status) ?? "DRAFT")])
2750
+ }, W(p(Pe)(((de = y.draft) == null ? void 0 : de.status) ?? "")), 3)
2751
+ ])
2752
+ ]),
2753
+ B(h),
2754
+ m("div", io, [
2755
+ (x(!0), M(ue, null, Se(Bn.value, (ge, $e) => (x(), M("div", {
2756
+ class: "flex flex-col gap-4",
2757
+ key: $e
2758
+ }, [
2759
+ m("div", co, [
2760
+ m("div", uo, W(ge.label), 1)
2761
+ ]),
2762
+ m("div", mo, W(ge.value), 1)
2763
+ ]))), 128))
2764
+ ])
2765
+ ];
2766
+ }),
2767
+ _: 1
2768
+ }),
2769
+ m("div", fo, [
2770
+ m("div", po, [
2771
+ v[13] || (v[13] = m("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
2772
+ g.value ? q("", !0) : (x(), M("div", vo, [
2773
+ y.draft && y.draft.status !== p(Te).enum.COMPLETED ? (x(), ne($, {
2774
+ key: 0,
2775
+ label: "Refresh balance",
2776
+ "prepend-icon": "refresh",
2777
+ variant: "secondary",
2778
+ "text-color": "primary",
2779
+ "bg-color": "transparent",
2780
+ "border-color": "primary",
2781
+ loading: p(A),
2782
+ disabled: p(A),
2783
+ onClick: ve
2784
+ }, null, 8, ["loading", "disabled"])) : q("", !0),
2785
+ B(It, null, {
2786
+ default: Z(() => [
2787
+ B($, {
2788
+ label: "Invalidate Draft Cache",
2789
+ "prepend-icon": "refresh",
2790
+ variant: "secondary",
2791
+ "text-color": "primary",
2792
+ "bg-color": "transparent",
2793
+ "border-color": "primary",
2794
+ loading: p(A),
2795
+ onClick: Oe
2796
+ }, null, 8, ["loading"])
2797
+ ]),
2798
+ _: 1
2799
+ }),
2800
+ B($, {
2801
+ label: "Export data",
2802
+ "prepend-icon": "download",
2803
+ variant: "secondary",
2804
+ "text-color": "primary",
2805
+ "bg-color": "transparent",
2806
+ "border-color": "primary",
2807
+ onClick: v[1] || (v[1] = (P) => y.draft ? p(o).exportDraft(
2808
+ y.draft,
2809
+ f.value,
2810
+ I.value,
2811
+ qt.value
2812
+ ) : null)
2813
+ })
2814
+ ]))
2815
+ ]),
2816
+ g.value ? (x(), M("div", yo, [
2817
+ v[15] || (v[15] = m("div", { class: "h-80" }, null, -1)),
2818
+ m("div", go, [
2819
+ m("div", null, [
2820
+ B(j, { size: "md" })
2821
+ ]),
2822
+ v[14] || (v[14] = m("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
2823
+ ]),
2824
+ v[16] || (v[16] = m("div", { class: "h-80" }, null, -1))
2825
+ ])) : (x(), M(ue, { key: 1 }, [
2826
+ m("div", ho, [
2827
+ m("div", bo, [
2828
+ B(H, {
2829
+ label: "Template Item(s)",
2830
+ selected: O.value.templateItem,
2831
+ onClick: v[2] || (v[2] = (P) => O.value.templateItem = !O.value.templateItem)
2832
+ }, null, 8, ["selected"]),
2833
+ B(H, {
2834
+ label: "Non-template Item(s)",
2835
+ selected: O.value.nonTemplateItem,
2836
+ onClick: v[3] || (v[3] = (P) => O.value.nonTemplateItem = !O.value.nonTemplateItem)
2837
+ }, null, 8, ["selected"])
2838
+ ]),
2839
+ B(K, {
2840
+ modelValue: Je.value,
2841
+ "onUpdate:modelValue": v[4] || (v[4] = (P) => Je.value = P),
2842
+ placeholder: "Filter items"
2843
+ }, null, 8, ["modelValue"])
2844
+ ]),
2845
+ p(u).skuTags.size ? (x(), M("div", _o, [
2846
+ (x(!0), M(ue, null, Se(p(u).skuTags.keys(), (P) => (x(), ne(H, {
2847
+ key: `${P}`,
2848
+ label: `${P}`,
2849
+ selectable: "",
2850
+ selected: c[`${P}`],
2851
+ onClick: (de) => c[`${P}`] = !c[`${P}`]
2852
+ }, {
2853
+ default: Z(() => [
2854
+ c[`${P}`] ? (x(), ne(ee, {
2855
+ key: 0,
2856
+ name: "check",
2857
+ class: "text-white",
2858
+ size: "sm"
2859
+ })) : q("", !0),
2860
+ m("span", {
2861
+ class: Be([
2862
+ "",
2863
+ {
2864
+ "text-white fm-typo-en-body-md-600": c[`${P}`],
2865
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !c[`${P}`]
2866
+ }
2867
+ ])
2868
+ }, W(P), 3)
2869
+ ]),
2870
+ _: 2
2871
+ }, 1032, ["label", "selected", "onClick"]))), 128))
2872
+ ])) : q("", !0),
2873
+ Ct.value.length ? (x(), M("div", wo, [
2874
+ v[17] || (v[17] = m("span", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary self-center" }, "Extra columns:", -1)),
2875
+ (x(!0), M(ue, null, Se(Ct.value, (P) => (x(), ne(H, {
2876
+ key: P,
2877
+ label: P,
2878
+ selectable: "",
2879
+ selected: dt[P],
2880
+ onClick: (de) => dt[P] = !dt[P]
2881
+ }, null, 8, ["label", "selected", "onClick"]))), 128))
2882
+ ])) : q("", !0),
2883
+ m("div", ko, [
2884
+ m("div", {
2885
+ style: gn({ height: "600px", minWidth: `${ut.value}px` })
2886
+ }, [
2887
+ B(Q, {
2888
+ "column-defs": Me.value,
2889
+ "row-data": Kt.value,
2890
+ "search-value": Je.value
2891
+ }, null, 8, ["column-defs", "row-data", "search-value"])
2892
+ ], 4)
2893
+ ])
2894
+ ], 64))
2895
+ ])
2896
+ ], 64)) : q("", !0),
2897
+ Xe.value.value === "history" ? (x(), M("div", xo, [
2898
+ ze.value.length ? (x(), M("div", So, [
2899
+ (x(!0), M(ue, null, Se(ze.value, (P, de) => (x(), M(ue, { key: de }, [
2900
+ m("div", Ao, [
2901
+ m("div", $o, [
2902
+ m("div", Io, [
2903
+ m("div", {
2904
+ class: Be([
2905
+ {
2906
+ "bg-fm-color-primary": de !== 0,
2907
+ "bg-white": de === 0
2908
+ },
2909
+ "w-[2px] h-full"
2910
+ ])
2911
+ }, null, 2)
2912
+ ]),
2913
+ v[20] || (v[20] = m("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
2914
+ m("div", To, [
2915
+ m("div", {
2916
+ class: Be([
2917
+ {
2918
+ "bg-fm-color-primary": de < ze.value.length - 1,
2919
+ "bg-white": de >= ze.value.length - 1
2920
+ },
2921
+ "w-[2px] h-full"
2922
+ ])
2923
+ }, null, 2)
2924
+ ])
2925
+ ]),
2926
+ m("div", Fo, [
2927
+ m("div", Bo, W(P.header), 1),
2928
+ m("div", Eo, W(P.date), 1)
2929
+ ])
2930
+ ]),
2931
+ m("div", jo, [
2932
+ m("div", Ro, [
2933
+ m("div", Mo, [
2934
+ m("div", {
2935
+ class: Be([
2936
+ {
2937
+ "bg-fm-color-primary": de < ze.value.length - 1,
2938
+ "bg-white": de >= ze.value.length - 1
2939
+ },
2940
+ "w-[2px] h-full"
2941
+ ])
2942
+ }, null, 2)
2943
+ ])
2944
+ ]),
2945
+ m("div", No, [
2946
+ B(w, {
2947
+ variant: "outlined",
2948
+ class: "py-12 px-16"
2949
+ }, {
2950
+ default: Z(() => [
2951
+ m("div", Uo, [
2952
+ (x(!0), M(ue, null, Se(P.info, (ge, $e) => (x(), M("div", {
2953
+ key: $e,
2954
+ class: "flex flex-col gap-4"
2955
+ }, [
2956
+ m("div", Po, W(ge == null ? void 0 : ge.label), 1),
2957
+ m("div", Vo, [
2958
+ (x(!0), M(ue, null, Se(ge == null ? void 0 : ge.values, (We, pt) => (x(), M("div", {
2959
+ key: pt,
2960
+ class: "fm-typo-en-body-lg-600"
2961
+ }, W(We), 1))), 128))
2962
+ ])
2963
+ ]))), 128))
2964
+ ])
2965
+ ]),
2966
+ _: 2
2967
+ }, 1024)
2968
+ ])
2969
+ ])
2970
+ ], 64))), 128))
2971
+ ])) : (x(), M("div", Do, [
2972
+ B(be),
2973
+ m("div", null, [
2974
+ m("img", {
2975
+ src: p(oa),
2976
+ alt: "List is empty"
2977
+ }, null, 8, Co)
2978
+ ]),
2979
+ v[18] || (v[18] = m("div", { class: "fm-typo-en-body-lg-600" }, W("No records found"), -1)),
2980
+ v[19] || (v[19] = m("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, W("You can track approval and rejection history here"), -1)),
2981
+ B(be),
2982
+ B(be)
2983
+ ]))
2984
+ ])) : q("", !0)
2985
+ ])
2986
+ ]),
2987
+ _: 1
2988
+ }, 8, ["model-value"]),
2989
+ p(d) && e.draft ? (x(), ne(Ya, {
2990
+ key: 0,
2991
+ show: mt.value,
2992
+ "onUpdate:show": v[10] || (v[10] = (P) => mt.value = P),
2993
+ refreshing: p(A),
2994
+ approving: ft.value,
2995
+ draft: e.draft,
2996
+ onRefresh: ve,
2997
+ onApprove: En
2998
+ }, null, 8, ["show", "refreshing", "approving", "draft"])) : q("", !0)
2999
+ ], 64);
3000
+ };
3001
+ }
3002
+ });
3003
+ var _e = /* @__PURE__ */ ((t) => (t.ready = "ready", t.negative = "negative", t.systemNegative = "systemNegative", t))(_e || {});
3004
+ async function Yo(t) {
3005
+ return new Promise((n, e) => {
3006
+ const a = new FileReader();
3007
+ a.onload = (l) => {
3008
+ var s;
3009
+ try {
3010
+ const o = (s = l.target) == null ? void 0 : s.result, d = la(o, { type: "array" }), g = d.SheetNames[0], _ = d.Sheets[g], f = gt.sheet_to_json(_, {
3011
+ header: 1,
3012
+ defval: ""
3013
+ }), I = (r) => String(r).trim().toLowerCase().replace(/^\uFEFF/, ""), R = f.findIndex(
3014
+ (r) => r.some((i) => I(i) === "code")
3015
+ );
3016
+ if (R === -1) {
3017
+ n([]);
3018
+ return;
3019
+ }
3020
+ const U = f[R], S = U.findIndex((r) => I(r) === "code"), u = U.findIndex((r) => I(r) === "balance");
3021
+ if (S === -1 || u === -1) {
3022
+ e(
3023
+ new Error(
3024
+ `Missing required columns: ${S === -1 ? '"Code" ' : ""}${u === -1 ? '"Balance"' : ""}.`.trim()
3025
+ )
3026
+ );
3027
+ return;
3028
+ }
3029
+ const c = f.slice(R + 1).filter((r) => String(r[S]).trim()).map((r) => ({
3030
+ itemCode: String(r[S]).trim(),
3031
+ quantity: Number(r[u]) || 0
3032
+ }));
3033
+ n(c);
3034
+ } catch (o) {
3035
+ e(o);
3036
+ }
3037
+ }, a.onerror = e, a.readAsArrayBuffer(t);
3038
+ });
3039
+ }
3040
+ function Ko(t) {
3041
+ const n = /* @__PURE__ */ new Map();
3042
+ return t.forEach((e) => {
3043
+ const a = n.get(e.itemCode) || 0;
3044
+ n.set(e.itemCode, a + e.quantity);
3045
+ }), n;
3046
+ }
3047
+ function qo(t, n) {
3048
+ const e = [], a = [];
3049
+ for (const [l, s] of n.entries()) {
3050
+ const o = t[l];
3051
+ if (!o) {
3052
+ a.push(l);
3053
+ continue;
3054
+ }
3055
+ const d = s < 0 ? "negative" : "ready";
3056
+ e.push({
3057
+ sku: o,
3058
+ physicalCount: s,
3059
+ // Note: filled by composable after readStockBalance()
3060
+ systemBalance: { amount: 0, precision: 0 },
3061
+ variance: s - 0,
3062
+ status: d
3063
+ });
3064
+ }
3065
+ return { mergedItems: e, unrecognisedItemCodes: a };
3066
+ }
3067
+ function Go(t, n) {
3068
+ const e = t.filter((g) => !g.isInactive), a = ca().format("YYYY-MM-DD"), l = `${n} - ${a}.csv`, s = [
3069
+ ["Code", "Name", "Balance"],
3070
+ ...e.map((g) => [g.code, g.name, ""])
3071
+ ], o = gt.aoa_to_sheet(s), d = gt.book_new();
3072
+ gt.book_append_sheet(d, o, "Template"), ia(d, l, { bookType: "csv" });
3073
+ }
3074
+ function Qo() {
3075
+ const t = Y([]), n = Y([]), e = Y(!1), a = Wt(), l = lt(), s = Dt(), o = V(
3076
+ () => t.value.some((f) => f.status === _e.negative)
3077
+ );
3078
+ async function d(f) {
3079
+ t.value = [], n.value = [], e.value = !0;
3080
+ try {
3081
+ const I = await Yo(f), R = Ko(I), U = a.skuByCode, { mergedItems: S, unrecognisedItemCodes: u } = qo(
3082
+ U,
3083
+ R
3084
+ ), F = await s.readStockBalance(), c = F.skus ?? [];
3085
+ c.length === 0 && console.warn(
3086
+ "No SKU balances found when importing closing draft. All system balances will be set to 0.",
3087
+ {
3088
+ stockBalance: F
3089
+ }
3090
+ );
3091
+ const r = new Map(
3092
+ c.map((b) => [b.id, b.balance])
3093
+ ), i = new Set(S.map((b) => b.sku._id));
3094
+ t.value = S.map((b) => {
3095
+ const C = r.get(b.sku._id) ?? { amount: 0, precision: 0 }, A = C.amount / Math.pow(10, C.precision);
3096
+ return { ...b, systemBalance: C, variance: b.physicalCount - A };
3097
+ });
3098
+ for (const b of Object.values(a.skuByCode)) {
3099
+ if (i.has(b._id)) continue;
3100
+ const C = r.get(b._id);
3101
+ if (!C) continue;
3102
+ const A = C.amount / Math.pow(10, C.precision);
3103
+ A >= 0 || t.value.push({
3104
+ sku: b,
3105
+ physicalCount: 0,
3106
+ systemBalance: C,
3107
+ variance: 0 - A,
3108
+ status: _e.systemNegative
3109
+ });
3110
+ }
3111
+ n.value = u;
3112
+ } catch (I) {
3113
+ t.value = [], n.value = [], console.error("Error processing uploaded file", { error: I });
3114
+ } finally {
3115
+ e.value = !1;
3116
+ }
3117
+ }
3118
+ async function g() {
3119
+ const f = it(), I = t.value.filter((c) => c.status === _e.ready), R = t.value.filter(
3120
+ (c) => c.status === _e.systemNegative
3121
+ ), U = (c) => ({
3122
+ sku: {
3123
+ _id: c.sku._id,
3124
+ code: c.sku.code,
3125
+ name: c.sku.name,
3126
+ unit: c.sku.unit
3127
+ },
3128
+ baseAmount: xn(c.physicalCount, c.sku.unit.precision),
3129
+ measurementsAmounts: []
3130
+ }), S = I.map(U), u = R.map(U), F = {
3131
+ effectiveAt: (/* @__PURE__ */ new Date()).toISOString(),
3132
+ items: S,
3133
+ negativeStockItems: u
3134
+ };
3135
+ return await f.createQuickModeDraftWithItems(F);
3136
+ }
3137
+ function _() {
3138
+ var I;
3139
+ const f = ((I = l.currentLocation) == null ? void 0 : I.name) ?? "template";
3140
+ Go(a.skus, f);
3141
+ }
3142
+ return { mergedItems: t, unrecognisedItemCodes: n, hasBlockingErrors: o, isLoading: e, onFileUpload: d, submit: g, downloadTemplate: _ };
3143
+ }
3144
+ const Zo = { class: "flex flex-col gap-16" }, Jo = {
3145
+ key: 0,
3146
+ class: "px-16 py-12 rounded-8 bg-fm-color-danger-weak text-fm-color-danger-default"
3147
+ }, Xo = { key: 1 }, es = { class: "fm-typo-en-label-md-400 cursor-pointer" }, ts = { class: "mt-8 flex flex-col gap-4" }, ns = { key: 2 }, as = { class: "fm-typo-en-label-md-400 cursor-pointer" }, os = { class: "mt-8 flex flex-col gap-4" }, ss = /* @__PURE__ */ Le({
3148
+ __name: "ClosingDraftCreatePreviewTable",
3149
+ props: {
3150
+ items: {},
3151
+ unrecognisedItemCodes: {}
3152
+ },
3153
+ setup(t) {
3154
+ const n = t, { t: e } = xt(), a = V(
3155
+ () => n.items.filter((d) => d.status === _e.negative)
3156
+ ), l = V(
3157
+ () => n.items.filter((d) => d.status === _e.systemNegative)
3158
+ ), s = V(() => ({
3159
+ [_e.negative]: {
3160
+ bgColor: "bg-fm-color-danger-weak",
3161
+ textColor: "text-fm-color-danger-default",
3162
+ icon: "🚫",
3163
+ label: e("inventory.closing.draft.createDraft.previewTable.status.negative")
3164
+ },
3165
+ [_e.systemNegative]: {
3166
+ bgColor: "bg-fm-color-warning-weak",
3167
+ textColor: "text-fm-color-warning-default",
3168
+ icon: "⚠️",
3169
+ label: e("inventory.closing.draft.createDraft.previewTable.status.systemNegative")
3170
+ }
3171
+ })), o = [
3172
+ {
3173
+ id: "name",
3174
+ header: () => e("inventory.ingredient.name"),
3175
+ cell: (d) => d.row.original.sku.name
3176
+ },
3177
+ {
3178
+ id: "uom",
3179
+ header: () => e("inventory.closing.draft.createDraft.previewTable.uom"),
3180
+ size: 80,
3181
+ cell: (d) => d.row.original.sku.unit.abbrev
3182
+ },
3183
+ {
3184
+ id: "systemBalance",
3185
+ header: () => e("inventory.closing.draft.createDraft.previewTable.systemBalance"),
3186
+ size: 180,
3187
+ cell: (d) => {
3188
+ const g = d.row.original;
3189
+ return T("div", ae(g.systemBalance));
3190
+ }
3191
+ },
3192
+ {
3193
+ id: "physicalCount",
3194
+ header: () => e("inventory.closing.draft.createDraft.previewTable.stockTakeBalance"),
3195
+ cell: (d) => {
3196
+ const g = d.row.original;
3197
+ return T("div", ae(g.physicalCount));
3198
+ }
3199
+ },
3200
+ {
3201
+ id: "variance",
3202
+ header: () => e("inventory.closing.draft.createDraft.previewTable.variance"),
3203
+ cell: (d) => {
3204
+ const _ = d.row.original.variance, f = _ < 0 ? "text-fm-color-danger-default" : _ > 0 ? "text-fm-color-success-default" : "";
3205
+ return T("span", { class: f }, ae(_));
3206
+ }
3207
+ },
3208
+ {
3209
+ id: "variancePercentage",
3210
+ header: () => e("inventory.closing.draft.createDraft.previewTable.variancePercentage"),
3211
+ size: 130,
3212
+ cell: (d) => {
3213
+ const g = d.row.original, _ = g.systemBalance.amount / Math.pow(10, g.systemBalance.precision), f = _ === 0 ? null : Math.max(
3214
+ -100,
3215
+ Math.min(100, Math.round(g.variance / Math.abs(_) * 1e4) / 100)
3216
+ );
3217
+ if (f === null)
3218
+ return T(
3219
+ "div",
3220
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
3221
+ e("inventory.closing.draft.createDraft.previewTable.notApplicable")
3222
+ );
3223
+ const I = `${ae(f)}`;
3224
+ if (f === 0)
3225
+ return T(
3226
+ "div",
3227
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
3228
+ I
3229
+ );
3230
+ const R = f > 0;
3231
+ return T("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" }, [
3232
+ T(Ce.FmIcon, {
3233
+ name: R ? "arrow_drop_up" : "arrow_drop_down",
3234
+ color: R ? "system-success-300" : "system-error-300",
3235
+ size: "md"
3236
+ }),
3237
+ I
3238
+ ]);
3239
+ }
3240
+ },
3241
+ {
3242
+ id: "status",
3243
+ header: () => e("inventory.common.status"),
3244
+ cell: (d) => {
3245
+ const g = d.row.original.status, _ = s.value[g];
3246
+ return _ ? T(
3247
+ "span",
3248
+ {
3249
+ class: `px-8 py-2 rounded-4 ${_.bgColor} ${_.textColor} fm-typo-en-label-sm-400`
3250
+ },
3251
+ `${_.icon} ${_.label}`
3252
+ ) : null;
3253
+ }
3254
+ }
3255
+ ];
3256
+ return (d, g) => {
3257
+ const _ = G("FmTable");
3258
+ return x(), M("div", Zo, [
3259
+ a.value.length > 0 ? (x(), M("div", Jo, [
3260
+ pe(W(p(e)("inventory.closing.draft.createDraft.previewTable.cannotSubmitNegative")) + " ", 1),
3261
+ m("strong", null, W(a.value.map((f) => f.sku.code).join(", ")), 1)
3262
+ ])) : q("", !0),
3263
+ l.value.length > 0 ? (x(), M("details", Xo, [
3264
+ m("summary", es, W(p(e)("inventory.closing.draft.createDraft.previewTable.systemNegativeNote", [l.value.length])), 1),
3265
+ m("ul", ts, [
3266
+ (x(!0), M(ue, null, Se(l.value, (f) => (x(), M("li", {
3267
+ key: f.sku._id,
3268
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
3269
+ }, W(f.sku.code), 1))), 128))
3270
+ ])
3271
+ ])) : q("", !0),
3272
+ d.unrecognisedItemCodes.length > 0 ? (x(), M("details", ns, [
3273
+ m("summary", as, W(p(e)("inventory.closing.draft.createDraft.previewTable.unrecognisedNote", [d.unrecognisedItemCodes.length])), 1),
3274
+ m("ul", os, [
3275
+ (x(!0), M(ue, null, Se(d.unrecognisedItemCodes, (f) => (x(), M("li", {
3276
+ key: f,
3277
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
3278
+ }, W(f), 1))), 128))
3279
+ ])
3280
+ ])) : q("", !0),
3281
+ B(_, {
3282
+ "row-data": n.items,
3283
+ "column-defs": o,
3284
+ pagination: { pageSize: 20 }
3285
+ }, null, 8, ["row-data"])
3286
+ ]);
3287
+ };
3288
+ }
3289
+ }), rs = { class: "flex flex-col gap-16" }, ls = { class: "flex flex-col gap-8" }, is = { class: "fm-typo-en-body-lg-600" }, cs = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, us = { class: "fm-corner-radius-md p-16 flex items-center gap-16 border border-fm-color-border-default" }, ds = { class: "flex flex-col flex-1 gap-4" }, ms = { class: "fm-typo-en-body-md-600" }, fs = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, ps = {
3290
+ key: 0,
3291
+ class: "flex flex-col gap-8"
3292
+ }, vs = { class: "fm-typo-en-body-lg-600" }, ys = {
3293
+ key: 0,
3294
+ class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 flex items-center gap-8"
3295
+ }, gs = { class: "grid grid-cols-[repeat(3,1fr)] gap-12" }, hs = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary flex items-center gap-4" }, bs = { class: "flex items-center gap-8 w-full" }, _s = /* @__PURE__ */ Le({
3296
+ __name: "ClosingDraftCreateSideSheet",
3297
+ props: {
3298
+ show: { type: Boolean }
3299
+ },
3300
+ emits: ["update:show", "submitted"],
3301
+ setup(t, { emit: n }) {
3302
+ const e = t, a = n, l = hn(e, "show"), { t: s } = xt(), o = rt(), d = Y("upload"), g = Y(null), _ = Y(!1), { mergedItems: f, unrecognisedItemCodes: I, hasBlockingErrors: R, isLoading: U, onFileUpload: S, submit: u, downloadTemplate: F } = Qo(), c = V(
3303
+ () => g.value && !U.value && f.value.length > 0
3304
+ ), r = V(() => {
3305
+ const A = f.value.filter(
3306
+ (O) => O.status === _e.ready
3307
+ ).length, L = f.value.filter(
3308
+ (O) => O.status === _e.negative
3309
+ ).length, se = f.value.filter(
3310
+ (O) => O.status === _e.systemNegative
3311
+ ).length, re = f.value.filter((O) => O.variance !== 0).length;
3312
+ return [
3313
+ { label: s("inventory.closing.draft.createDraft.summary.totalItems"), value: f.value.length },
3314
+ { label: s("inventory.closing.draft.createDraft.summary.itemsWithCount"), value: A },
3315
+ {
3316
+ label: s("inventory.closing.draft.createDraft.summary.unrecognisedItems"),
3317
+ value: I.value.length,
3318
+ isWarning: I.value.length > 0
3319
+ },
3320
+ { label: s("inventory.closing.draft.createDraft.summary.itemsWithVariance"), value: re },
3321
+ { label: s("inventory.closing.draft.createDraft.summary.negativeCounts"), value: L, isError: L > 0 },
3322
+ {
3323
+ label: s("inventory.closing.draft.createDraft.summary.systemNegative"),
3324
+ value: se,
3325
+ isWarning: se > 0
3326
+ }
3327
+ ];
3328
+ });
3329
+ async function i(A) {
3330
+ g.value = A, await S(A);
3331
+ }
3332
+ async function b() {
3333
+ _.value = !0;
3334
+ try {
3335
+ await u(), C(), a("submitted"), o.open({
3336
+ title: "Success",
3337
+ message: "Closing draft created successfully",
3338
+ type: "success"
3339
+ });
3340
+ } catch (A) {
3341
+ console.error("Failed to create closing draft", { error: A }), o.open({
3342
+ title: "Something went wrong",
3343
+ message: "Failed to create closing draft. Please try again",
3344
+ type: "error"
3345
+ });
3346
+ } finally {
3347
+ _.value = !1;
3348
+ }
3349
+ }
3350
+ Qe(l, (A) => {
3351
+ A || (d.value = "upload", g.value = null);
3352
+ });
3353
+ function C() {
3354
+ l.value = !1;
3355
+ }
3356
+ return (A, L) => {
3357
+ const se = G("FmCircularProgress"), re = G("FmIcon"), O = G("FmButton"), me = G("FmCard"), N = G("FmSideSheet");
3358
+ return x(), ne(N, {
3359
+ "dismiss-away": "",
3360
+ "max-width": 9999,
3361
+ "model-value": p(l),
3362
+ "onUpdate:modelValue": L[2] || (L[2] = (E) => Ot(l) ? l.value = E : null),
3363
+ header: p(s)("inventory.closing.draft.createDraft.title")
3364
+ }, {
3365
+ default: Z(() => [
3366
+ m("div", rs, [
3367
+ d.value === "upload" ? (x(), M(ue, { key: 0 }, [
3368
+ m("div", ls, [
3369
+ m("div", is, W(p(s)("inventory.closing.draft.createDraft.importCsv")), 1),
3370
+ m("div", cs, W(p(s)("inventory.closing.draft.createDraft.uploadDescription")), 1),
3371
+ B(ua, {
3372
+ class: Be({ "h-[200px]": !g.value }),
3373
+ accept: ".csv",
3374
+ disabled: p(U),
3375
+ onFileUpload: i
3376
+ }, Pn({ _: 2 }, [
3377
+ g.value ? {
3378
+ name: "default",
3379
+ fn: Z(({ openFileDialog: E }) => [
3380
+ m("div", us, [
3381
+ p(U) ? (x(), ne(se, {
3382
+ key: 0,
3383
+ size: "md",
3384
+ color: "neutral-gray-200"
3385
+ })) : (x(), ne(re, {
3386
+ key: 1,
3387
+ name: "check_circle",
3388
+ color: "system-success-400",
3389
+ size: "lg"
3390
+ })),
3391
+ m("div", ds, [
3392
+ m("div", ms, W(g.value.name), 1),
3393
+ m("div", fs, W(p(U) ? p(s)("inventory.closing.draft.createDraft.processing") : p(s)("inventory.closing.draft.createDraft.itemsLoaded", [p(f).length])), 1)
3394
+ ]),
3395
+ p(U) ? q("", !0) : (x(), ne(O, {
3396
+ key: 2,
3397
+ label: p(s)("inventory.closing.draft.createDraft.replaceFile"),
3398
+ variant: "secondary",
3399
+ "prepend-icon": "autorenew",
3400
+ onClick: E
3401
+ }, null, 8, ["label", "onClick"]))
3402
+ ])
3403
+ ]),
3404
+ key: "0"
3405
+ } : void 0
3406
+ ]), 1032, ["class", "disabled"])
3407
+ ]),
3408
+ c.value ? (x(), M("div", ps, [
3409
+ m("div", vs, W(p(s)("inventory.closing.draft.createDraft.importSummary")), 1),
3410
+ p(R) ? (x(), M("div", ys, [
3411
+ B(re, {
3412
+ name: "error",
3413
+ size: "sm",
3414
+ color: "system-error-300"
3415
+ }),
3416
+ m("span", null, W(p(s)("inventory.closing.draft.createDraft.reviewIssues")), 1)
3417
+ ])) : q("", !0),
3418
+ B(me, {
3419
+ variant: "outlined",
3420
+ class: "flex flex-col gap-12 px-16 py-12"
3421
+ }, {
3422
+ default: Z(() => [
3423
+ m("div", gs, [
3424
+ (x(!0), M(ue, null, Se(r.value, (E) => (x(), M("div", {
3425
+ key: E.label,
3426
+ class: "flex flex-col gap-4"
3427
+ }, [
3428
+ m("div", hs, [
3429
+ E.isError ? (x(), ne(re, {
3430
+ key: 0,
3431
+ name: "error",
3432
+ size: "sm",
3433
+ color: "system-error-300"
3434
+ })) : q("", !0),
3435
+ E.isWarning && !E.isError ? (x(), ne(re, {
3436
+ key: 1,
3437
+ name: "warning",
3438
+ size: "sm",
3439
+ color: "system-warning-300"
3440
+ })) : q("", !0),
3441
+ m("span", null, W(E.label), 1)
3442
+ ]),
3443
+ m("div", {
3444
+ class: Be([
3445
+ "fm-typo-en-body-lg-600",
3446
+ {
3447
+ "text-fm-color-system-error-300": E.isError,
3448
+ "text-fm-color-system-warning-300": E.isWarning && !E.isError
3449
+ }
3450
+ ])
3451
+ }, W(E.value), 3)
3452
+ ]))), 128))
3453
+ ])
3454
+ ]),
3455
+ _: 1
3456
+ })
3457
+ ])) : q("", !0)
3458
+ ], 64)) : q("", !0),
3459
+ d.value === "preview" ? (x(), ne(ss, {
3460
+ key: 1,
3461
+ items: p(f),
3462
+ "unrecognised-item-codes": p(I)
3463
+ }, null, 8, ["items", "unrecognised-item-codes"])) : q("", !0)
3464
+ ])
3465
+ ]),
3466
+ "side-sheet-footer": Z(() => [
3467
+ m("div", bs, [
3468
+ d.value === "preview" ? (x(), ne(O, {
3469
+ key: 0,
3470
+ variant: "secondary",
3471
+ label: p(s)("inventory.common.back"),
3472
+ "prepend-icon": "arrow_back",
3473
+ onClick: L[0] || (L[0] = (E) => d.value = "upload")
3474
+ }, null, 8, ["label"])) : q("", !0),
3475
+ d.value === "upload" ? (x(), ne(O, {
3476
+ key: 1,
3477
+ variant: "primary",
3478
+ label: p(s)("inventory.common.next"),
3479
+ disabled: !g.value || p(U),
3480
+ onClick: L[1] || (L[1] = (E) => d.value = "preview")
3481
+ }, null, 8, ["label", "disabled"])) : q("", !0),
3482
+ d.value === "preview" ? (x(), ne(da, {
3483
+ key: 2,
3484
+ label: p(s)("inventory.closing.draft.createDraft.submit"),
3485
+ disabled: p(R) || p(f).length === 0 || _.value,
3486
+ loading: _.value,
3487
+ "confirm-title": p(s)("inventory.closing.draft.createDraft.confirmTitle"),
3488
+ "confirm-message": p(s)("inventory.closing.draft.createDraft.confirmMessage"),
3489
+ onConfirm: b
3490
+ }, null, 8, ["label", "disabled", "loading", "confirm-title", "confirm-message"])) : q("", !0),
3491
+ B(O, {
3492
+ variant: "tertiary",
3493
+ label: p(s)("inventory.common.close"),
3494
+ onClick: C
3495
+ }, null, 8, ["label"]),
3496
+ d.value === "upload" ? (x(), ne(O, {
3497
+ key: 3,
3498
+ class: "ml-auto",
3499
+ variant: "secondary",
3500
+ label: p(s)("inventory.closing.draft.createDraft.downloadTemplate"),
3501
+ "prepend-icon": "download",
3502
+ onClick: p(F)
3503
+ }, null, 8, ["label", "onClick"])) : q("", !0)
3504
+ ])
3505
+ ]),
3506
+ _: 1
3507
+ }, 8, ["model-value", "header"]);
3508
+ };
3509
+ }
3510
+ }), ws = { class: "flex-1 flex flex-col gap-8" }, ks = { class: "flex flex-col" }, xs = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ds = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Cs = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Ss = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, tr = /* @__PURE__ */ Le({
3511
+ __name: "ClosingDraftView",
3512
+ setup(t) {
3513
+ const { t: n } = xt(), { viewDraft: e } = wt(), { viewClosingDraftProps: a, viewClosingDraftShow: l } = qn(wt()), s = lt(), o = Tn(), d = On(), { breakpoints: g } = Hn();
3514
+ s.watchLocation(o.fetchDrafts);
3515
+ const _ = V(() => o.loading), f = Y(""), I = Y(!1), R = V(() => g.value.xs || g.value.sm), U = V(() => R.value ? 10 : 20), S = V(
3516
+ () => {
3517
+ var r;
3518
+ return ((r = s.currentLocation) == null ? void 0 : r.type) === Kn.enum.warehouse;
3519
+ }
3520
+ );
3521
+ function u(r) {
3522
+ switch (r) {
3523
+ case "add":
3524
+ return I.value = !0;
3525
+ case "refresh":
3526
+ return o.fetchDrafts();
3527
+ }
3528
+ }
3529
+ function F(r) {
3530
+ return r;
3531
+ }
3532
+ const c = V(() => {
3533
+ const r = {
3534
+ label: n("inventory.closing.draft.createDraft.title"),
3535
+ value: "add",
3536
+ isPrimary: !0,
3537
+ prependIcon: "add"
3538
+ }, i = {
3539
+ label: n("inventory.common.refresh"),
3540
+ value: "refresh",
3541
+ isPrimary: !1
3542
+ };
3543
+ return [...S.value ? [r] : [], i];
3544
+ });
3545
+ return (r, i) => {
3546
+ const b = G("FmTable");
3547
+ return x(), M(ue, null, [
3548
+ B(zn, {
3549
+ title: p(n)("inventory.closing.draft.title"),
3550
+ actions: c.value,
3551
+ "onClick:action": u
3552
+ }, {
3553
+ default: Z(() => [
3554
+ m("div", {
3555
+ class: Be([
3556
+ "flex flex-col gap-8 max-h-full",
3557
+ {
3558
+ "p-0": R.value,
3559
+ "px-24 ": !R.value
3560
+ }
3561
+ ])
3562
+ }, [
3563
+ B(aa, {
3564
+ "change-location": "",
3565
+ searchable: "",
3566
+ search: f.value,
3567
+ "onUpdate:search": i[0] || (i[0] = (C) => f.value = C)
3568
+ }, null, 8, ["search"]),
3569
+ (x(), ne(b, {
3570
+ key: p(o).tableKey,
3571
+ style: gn(p(d).tableHeight),
3572
+ "column-defs": p(o).columnDefs,
3573
+ "row-data": p(o).drafts,
3574
+ "search-value": f.value,
3575
+ loading: _.value,
3576
+ onRowClick: i[1] || (i[1] = (C) => p(e)(C.original)),
3577
+ "page-size": U.value
3578
+ }, {
3579
+ "list-row": Z((C) => [
3580
+ B(ma, {
3581
+ row: C,
3582
+ onRowClick: (A) => p(e)(A)
3583
+ }, {
3584
+ default: Z((A) => {
3585
+ var L, se, re, O, me, N, E, ie, D, X, J, ve, Oe, Ae, je, Re, ct, ye, Me, ut;
3586
+ return [
3587
+ m("div", ws, [
3588
+ m("div", ks, [
3589
+ m("div", xs, [
3590
+ B(p(yt), {
3591
+ render: (re = (se = (L = A._id) == null ? void 0 : L.column) == null ? void 0 : se.columnDef) == null ? void 0 : re.cell,
3592
+ props: (me = (O = A._id) == null ? void 0 : O.getContext) == null ? void 0 : me.call(O)
3593
+ }, null, 8, ["render", "props"])
3594
+ ]),
3595
+ m("div", Ds, [
3596
+ B(p(yt), {
3597
+ render: (ie = (E = (N = A.name) == null ? void 0 : N.column) == null ? void 0 : E.columnDef) == null ? void 0 : ie.cell,
3598
+ props: (X = (D = A.name) == null ? void 0 : D.getContext) == null ? void 0 : X.call(D)
3599
+ }, null, 8, ["render", "props"])
3600
+ ]),
3601
+ m("div", Cs, W([
3602
+ ...C.original.items.slice(0, 3).map((Je) => Je.sku.name),
3603
+ ...C.original.items.length >= 3 ? [`and ${C.original.items.length - 3} more items`] : []
3604
+ ].join(", ")), 1),
3605
+ m("div", Ss, [
3606
+ B(p(yt), {
3607
+ render: (Oe = (ve = (J = A.ref) == null ? void 0 : J.column) == null ? void 0 : ve.columnDef) == null ? void 0 : Oe.cell,
3608
+ props: (je = (Ae = A.ref) == null ? void 0 : Ae.getContext) == null ? void 0 : je.call(Ae)
3609
+ }, null, 8, ["render", "props"])
3610
+ ])
3611
+ ]),
3612
+ m("div", null, [
3613
+ B(p(yt), {
3614
+ render: (ye = (ct = (Re = A.status) == null ? void 0 : Re.column) == null ? void 0 : ct.columnDef) == null ? void 0 : ye.cell,
3615
+ props: (ut = (Me = A.status) == null ? void 0 : Me.getContext) == null ? void 0 : ut.call(Me)
3616
+ }, null, 8, ["render", "props"])
3617
+ ])
3618
+ ])
3619
+ ];
3620
+ }),
3621
+ _: 2
3622
+ }, 1032, ["row", "onRowClick"])
3623
+ ]),
3624
+ _: 1
3625
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
3626
+ ], 2)
3627
+ ]),
3628
+ _: 1
3629
+ }, 8, ["title", "actions"]),
3630
+ B(_s, {
3631
+ show: I.value,
3632
+ "onUpdate:show": i[2] || (i[2] = (C) => I.value = C),
3633
+ onSubmitted: p(o).fetchDrafts
3634
+ }, null, 8, ["show", "onSubmitted"]),
3635
+ (x(), ne(Vn, { to: "body" }, [
3636
+ B(Ho, Ln(p(a), {
3637
+ show: p(l),
3638
+ "onUpdate:show": i[3] || (i[3] = (C) => Ot(l) ? l.value = C : null),
3639
+ onSubmitted: i[4] || (i[4] = () => (l.value = !1, p(o).fetchDrafts())),
3640
+ onRefresh: i[5] || (i[5] = (C) => p(o).updateDraftRef(C))
3641
+ }), null, 16, ["show"])
3642
+ ]))
3643
+ ], 64);
3644
+ };
3645
+ }
3646
+ });
3647
+ export {
3648
+ tr as default
3649
+ };