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