@feedmepos/mf-inventory-portal 1.5.8 → 1.5.9-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/{App-CkuUHPEo.js → App-B7rirksC.js} +4 -4
  2. package/dist/{ApprovalView-DubepVw0.js → ApprovalView-BomKMill.js} +7 -7
  3. package/dist/{BindingsDialog-B4WNBwyC.js → BindingsDialog-CI8qKlCl.js} +13 -13
  4. package/dist/{BindingsPicker-BRrLqG1M.js → BindingsPicker-BhED4TMH.js} +2 -2
  5. package/dist/{BindingsTable-CsL2_ZUy.js → BindingsTable-CgD27m69.js} +3 -3
  6. package/dist/ClosingDraftView-BKjxsKag.js +3342 -0
  7. package/dist/{ClosingHistoryView-C9Hidhix.js → ClosingHistoryView-C8xdmA9v.js} +469 -459
  8. package/dist/{ClosingTemplateView-gzJmYQLL.js → ClosingTemplateView-C3IMkNtu.js} +14 -14
  9. package/dist/{DefaultView-Wd26nwBn.js → DefaultView-M1s5DkYs.js} +2 -2
  10. package/dist/{DeliveryOrderPrintPreview-5Jm6QgAP.js → DeliveryOrderPrintPreview-DNvsv0bs.js} +2 -2
  11. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Bye4GWOd.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DPiYsxMt.js} +2 -2
  12. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-D0u8X0Bk.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-W4K3RNpN.js} +2 -2
  13. package/dist/{FmMultiselectDialog-BuXhazyF.js → FmMultiselectDialog-D5vlbq9s.js} +1 -1
  14. package/dist/{FmMultiselectDialog-CrbCQvck.js → FmMultiselectDialog-DpiLiqOe.js} +2 -2
  15. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-U0Io6FhR.js → FmUnitInput.vue_vue_type_script_setup_true_lang-tiIC1uvr.js} +111 -110
  16. package/dist/{ImportView-PBP1w1_z.js → ImportView-uPX4OhrY.js} +6 -6
  17. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-BvlBuk3S.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-iTmbGMAv.js} +1 -1
  18. package/dist/{IngredientGroupView-ZavZf2r_.js → IngredientGroupView-Dhhm6SwF.js} +5 -5
  19. package/dist/{IngredientsView-DXKIqdoR.js → IngredientsView-BeuJFNel.js} +17 -17
  20. package/dist/{IntegrationExplorerView-D-7q6p_s.js → IntegrationExplorerView-DvIVyrTk.js} +352 -352
  21. package/dist/{IntegrationView-ByvhMaCO.js → IntegrationView-BlCqI1aF.js} +13 -13
  22. package/dist/{InventoryBindingForm-DAAeny2A.js → InventoryBindingForm-BbaQJX-2.js} +1 -1
  23. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-DpR5ySFv.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-8kDSVOQT.js} +5 -5
  24. package/dist/{InventoryBindingSummary-CZBnbomV.js → InventoryBindingSummary-ISEBBsyC.js} +1 -1
  25. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BJ6gswNM.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-C2XS7S9B.js} +1 -1
  26. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-mlVRfnxo.js → PremiumBadge.vue_vue_type_script_setup_true_lang-DMQCjdfY.js} +1 -1
  27. package/dist/{PublishView-CsMKko5l.js → PublishView-B7ngdwbS.js} +3 -3
  28. package/dist/{PurchaseOrderPrintPreview-B-jchSYL.js → PurchaseOrderPrintPreview-CdKQ2vC9.js} +2 -2
  29. package/dist/{ReceiveRequestView-DfOcn_OW.js → ReceiveRequestView-i7V6aTo7.js} +25 -25
  30. package/dist/{RecipeView-C-1PuiaO.js → RecipeView-DQeKXITE.js} +19 -19
  31. package/dist/{SettingsView-C3vB5Vjb.js → SettingsView-5jm5pZxN.js} +4 -4
  32. package/dist/{StockView-BAXULvMh.js → StockView-BeNHn4jp.js} +775 -765
  33. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-BI_hHa88.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CKfaF6XM.js} +1 -1
  34. package/dist/{SupplierView-B9y9d6C0.js → SupplierView-DzX3leQE.js} +12 -12
  35. package/dist/{SurchargeView-D3lq3G0g.js → SurchargeView-q8Rl6XQg.js} +6 -6
  36. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-D54FjCtg.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-CfYRww5Y.js} +2 -2
  37. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Bi-9US2G.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Bywpva5c.js} +1 -1
  38. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-BkmO63qQ.js → TransferDetails.vue_vue_type_script_setup_true_lang-Ceg3e163.js} +20 -20
  39. package/dist/{TransferTemplateView-B7hDis-b.js → TransferTemplateView-ClEeuE0A.js} +18 -18
  40. package/dist/{UnitCostHistoryView-DR-RJ6lO.js → UnitCostHistoryView-CkvS4aGj.js} +4 -4
  41. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-WSYbNJL_.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-C7VKd1XK.js} +4 -4
  42. package/dist/{UnitView-Dx3NUFp2.js → UnitView-COKzqhf7.js} +9 -9
  43. package/dist/{WarehouseView-CSmq2xhS.js → WarehouseView-CWsl1Awb.js} +5 -5
  44. package/dist/{WastageTemplateView-Bya8Ptja.js → WastageTemplateView-BAEbIzfQ.js} +14 -14
  45. package/dist/api/error.d.ts +6 -3
  46. package/dist/{app-BtIUZZer.js → app-DTz4LGCJ.js} +10353 -10377
  47. package/dist/app.d.ts +8 -0
  48. package/dist/app.js +4 -4
  49. package/dist/{closing-template-CY4I4oi6.js → closing-template-DmMvmiD8.js} +1 -1
  50. package/dist/{date2-BXHREmqe.js → date2-BJJQIIV9.js} +1 -1
  51. package/dist/{dayjs.min-B15_mmz6.js → dayjs.min-YbnVt6Kp.js} +1 -1
  52. package/dist/{decimal-CfCuBc7o.js → decimal-DstnZVub.js} +2 -2
  53. package/dist/{defineDeepModel-CeW3ETAv.js → defineDeepModel-CxxsD8UG.js} +1 -1
  54. package/dist/{duplicate-template-CTHciPHW.js → duplicate-template-DFAfrk_o.js} +1 -1
  55. package/dist/{export-CCbJ-2Gk.js → export-C0aosI78.js} +2 -2
  56. package/dist/{feature-RoG35971.js → feature-dHHbIKf7.js} +86 -86
  57. package/dist/{format-time-from-id-q1T46zz9.js → format-time-from-id-BtGI10RN.js} +1 -1
  58. package/dist/{format-unit-display-DUaKGmsk.js → format-unit-display-C4V_dB6d.js} +11 -11
  59. package/dist/helper/uom-rules.d.ts +12 -0
  60. package/dist/{import-export.helper-B2ZzXsyT.js → import-export.helper-BblDa7MU.js} +6 -6
  61. package/dist/{index-CF466Sy_.js → index-B8bFII4h.js} +3 -3
  62. package/dist/{index-BC06YbP9.js → index-Y7yMwT_5.js} +1 -1
  63. package/dist/{index-CKErlM6H.js → index-j4PQ4n55.js} +1 -1
  64. package/dist/{inventory-core-dart.default-BEB7pV9M.js → inventory-core-dart.default-JrRChx_V.js} +1319 -1264
  65. package/dist/{lz-string-D3Jm7T7Q.js → lz-string-C856gsAG.js} +1 -1
  66. package/dist/{menu-usage-module-BiCPifRX.js → menu-usage-module-D7cxkbEk.js} +11 -12
  67. package/dist/netsuite-B6QeJ2cS.js +9381 -0
  68. package/dist/{number-C6mI12qg.js → number-CKzPOWR2.js} +3 -3
  69. package/dist/{predefined-templates-DfpzUsNl.js → predefined-templates-bmWnR8Cx.js} +1 -1
  70. package/dist/{purchase-order-template-Dq3N4vgB.js → purchase-order-template-DQwbAN8F.js} +1 -1
  71. package/dist/{recalculationUtils-D0A7mbSs.js → recalculationUtils-CTLTLQ9V.js} +1 -1
  72. package/dist/{rules-Dajxj04v.js → rules-EEgDDXMF.js} +2 -2
  73. package/dist/{stock-D6d8tS4B.js → stock-GVmcy_Vk.js} +1 -1
  74. package/dist/{supplier-CkfePT6a.js → supplier-D2tc_iCh.js} +2 -2
  75. package/dist/{surcharge-C3uSQoRw.js → surcharge-xQ1WGUtz.js} +1 -1
  76. package/dist/tsconfig.app.tsbuildinfo +1 -1
  77. package/dist/uom-rules-BOqMU5Ob.js +21 -0
  78. package/dist/{use-ingredient-select-dialog-C3zCgi5E.js → use-ingredient-select-dialog-BQmyEVZx.js} +2 -2
  79. package/dist/{use-inventory-binding-dialog-CsDrU6sx.js → use-inventory-binding-dialog-BzFcGuKM.js} +2 -2
  80. package/dist/{use-template-enabled-locations-DpZY_R7j.js → use-template-enabled-locations-CkW-7UVo.js} +2 -2
  81. package/dist/{use-transfer-locations-DlHF5kG-.js → use-transfer-locations-CjrxfaGK.js} +2 -2
  82. package/dist/{useHrmPermission-C1G3BVpn.js → useHrmPermission-DcAcggus.js} +1 -1
  83. package/dist/{useNavigationMenu-tNJYWFkU.js → useNavigationMenu-D2tNJzZl.js} +2 -2
  84. package/dist/{useSseClient-4qu-xO3k.js → useSseClient-D9Xmiz-D.js} +3 -3
  85. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +11 -2
  86. package/dist/{vue-i18n-eqPSat_0.js → vue-i18n-BQm9JO9o.js} +358 -358
  87. package/dist/{xlsx-DB2JHegF.js → xlsx-DZYL-v8V.js} +1 -1
  88. package/dist/{xlsx.util-TwDCO4ay.js → xlsx.util-FEXJ9YRM.js} +3 -3
  89. package/package.json +3 -3
  90. package/dist/ClosingDraftView-Psl49bhd.js +0 -3202
  91. package/dist/lodash-D9rnJgGZ.js +0 -3678
  92. package/dist/netsuite-CuPJ_UTs.js +0 -5708
@@ -0,0 +1,3342 @@
1
+ import { defineComponent as je, ref as W, computed as M, onMounted as kt, resolveComponent as Z, openBlock as h, createElementBlock as T, 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 K, h as k, watch as ze, renderList as he, onUnmounted as kn, reactive as Ot, isRef as _t, normalizeClass as Se, normalizeStyle as Kt, createSlots as _n, Teleport as wn, mergeProps as xn } from "vue";
2
+ import { u as Dn, _ as An } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DGlWE5I8.js";
3
+ import { useCoreStore as Wt, useI18n as Ye } from "@feedmepos/mf-common";
4
+ import { useSnackbar as Ke, useDialog as Cn, components as pe, useProxiedModel as qt, useBreakpoints as Sn } from "@feedmepos/ui-library";
5
+ import { m as $n, u as We, L as oe, w as te, q as Gt, s as Be, M as _e, B as Te, c as Fn, a as wt, j as In } from "./app-DTz4LGCJ.js";
6
+ import { defineStore as Qt, storeToRefs as Bn } from "pinia";
7
+ import { b as rt, e as Zt, f as Tn, a as Ce } from "./date2-BJJQIIV9.js";
8
+ import { R as jn } from "./rules-EEgDDXMF.js";
9
+ import { e as lt, a as ht, t as Jt, c as He, l as Xt, m as en, j as tn, k as nn, o as ne } from "./number-CKzPOWR2.js";
10
+ import { b as Mn, d as Un } from "./xlsx.util-FEXJ9YRM.js";
11
+ import { i as an, u as on } from "./uom-rules-BOqMU5Ob.js";
12
+ import { u as Rn, a as Pn } from "./useSseClient-D9Xmiz-D.js";
13
+ import { u as ct } from "./stock-GVmcy_Vk.js";
14
+ import { D as Ht, R as Ne } from "./row-action.enum-DQ9bJ_uv.js";
15
+ import { c as Vn } from "./component-kqxARxvM.js";
16
+ import { f as Nn } from "./format-time-from-id-BtGI10RN.js";
17
+ import { f as zn } from "./recalculationUtils-CTLTLQ9V.js";
18
+ import { _ as En } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-W4K3RNpN.js";
19
+ import { _ as Ln } from "./empty-placeholder-B0QU467o.js";
20
+ import { F as gt } from "./FmAdminBadge-DjnBAgyv.js";
21
+ import { u as On } from "./vue-i18n-BQm9JO9o.js";
22
+ import { F as Hn } from "./decimal-DstnZVub.js";
23
+ import { r as Yn, u as ot, w as Kn } from "./xlsx-DZYL-v8V.js";
24
+ import { d as Wn } from "./dayjs.min-YbnVt6Kp.js";
25
+ import { F as qn } from "./FmDroppableField-J0xUsOTV.js";
26
+ import { _ as Gn } from "./FmConfirmationButton.vue_vue_type_script_setup_true_lang-DLrMEGFR.js";
27
+ import { _ as Qn, F as at } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
28
+ const qe = $n((n, l) => {
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 l.get(i);
37
+ },
38
+ async readDrafts() {
39
+ const o = t(), g = `${n.inventoryBackendUrl}/${o}/closing-draft`;
40
+ return l.get(g);
41
+ },
42
+ async runOperation(o) {
43
+ const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/run-operation`;
44
+ return l.post(i, o);
45
+ },
46
+ async runOperationV1(o) {
47
+ const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/v1/run-operation`;
48
+ return l.post(i, o);
49
+ },
50
+ async sync(o) {
51
+ const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/sync`;
52
+ return l.post(i, o);
53
+ },
54
+ async cloneDraft(o) {
55
+ const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/${o}/clone`;
56
+ return l.post(i, {});
57
+ },
58
+ async createQuickModeDraftWithItems(o) {
59
+ const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/quick-mode/new-with-items`;
60
+ return l.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 l.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 l.get(s);
69
+ }
70
+ };
71
+ }), Zn = { class: "fm-typo-en-body-lg-400" }, Jn = { class: "fm-typo-en-body-lg-600" }, Xn = {
72
+ key: 0,
73
+ class: "flex flex-col"
74
+ }, ea = {
75
+ key: 0,
76
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
77
+ }, ta = { 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 l = n, t = W(), o = qe(), g = Ke(), i = W(!1), s = W(null), c = W(!1), x = M(() => {
87
+ switch (l.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: ${l.action}`);
96
+ }), A = M(() => {
97
+ switch (l.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: ${l.action}`);
106
+ });
107
+ kt(() => {
108
+ if (l.draft.effectiveAt)
109
+ s.value = new Date(l.draft.effectiveAt);
110
+ else {
111
+ const I = new Date(l.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 ? "" : rt(s.value);
119
+ },
120
+ set(I) {
121
+ if (I) {
122
+ const _ = /* @__PURE__ */ new Date(`${I} ${B.value}`);
123
+ _.setSeconds(59, 999), s.value = _;
124
+ } else
125
+ s.value = null;
126
+ }
127
+ }), B = M({
128
+ get() {
129
+ return s.value === null ? "" : Zt(s.value);
130
+ },
131
+ set(I) {
132
+ if (I) {
133
+ const _ = /* @__PURE__ */ new Date(`${f.value} ${I}`);
134
+ _.setSeconds(59, 999), s.value = _;
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: l.draft._id,
144
+ _rev: l.draft._rev ?? "",
145
+ action: l.action,
146
+ data: {
147
+ effectiveAt: s.value ? s.value.toISOString() : null,
148
+ remark: t.value
149
+ }
150
+ }).delayed(500) : await o.runOperation({
151
+ _id: l.draft._id,
152
+ _rev: l.draft._rev ?? "",
153
+ action: l.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
+ }), l.onFinished();
163
+ } catch (_) {
164
+ g.open({
165
+ title: "Something went wrong",
166
+ message: (_ == null ? void 0 : _.message) ?? "Unable to submit action. Please try again",
167
+ type: "error"
168
+ }), console.error("error on submit closing draft action", _);
169
+ } finally {
170
+ i.value = !1;
171
+ }
172
+ }
173
+ return (I, _) => {
174
+ const R = Z("FmLabel"), p = Z("FmDatePicker"), v = Z("FmTimePicker"), m = Z("FmTextField"), b = Z("FmButton"), y = Z("FmForm");
175
+ return c.value ? (h(), 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", Zn, [
183
+ _[4] || (_[4] = de(" You are about to ")),
184
+ a("span", Jn, H(x.value), 1),
185
+ _[5] || (_[5] = de(" this draft. Please provide a remark to justify this action. "))
186
+ ]),
187
+ I.action === u(oe).enum.approveDraft ? (h(), T("div", Xn, [
188
+ $(R, { class: "fm-typo-en-body-lg-600" }, {
189
+ default: ee(() => _[6] || (_[6] = [
190
+ de("Closing Date")
191
+ ])),
192
+ _: 1
193
+ }),
194
+ $(p, {
195
+ modelValue: f.value,
196
+ "onUpdate:modelValue": _[0] || (_[0] = (w) => f.value = w),
197
+ max: u(rt)(/* @__PURE__ */ new Date())
198
+ }, null, 8, ["modelValue", "max"]),
199
+ $(R, { class: "fm-typo-en-body-lg-600" }, {
200
+ default: ee(() => _[7] || (_[7] = [
201
+ de("Closing Time")
202
+ ])),
203
+ _: 1
204
+ }),
205
+ $(v, {
206
+ modelValue: B.value,
207
+ "onUpdate:modelValue": _[1] || (_[1] = (w) => B.value = w)
208
+ }, null, 8, ["modelValue"]),
209
+ N.value ? (h(), T("div", ea, " Cannot select future date ")) : K("", !0)
210
+ ])) : K("", !0),
211
+ $(m, {
212
+ modelValue: t.value,
213
+ "onUpdate:modelValue": _[2] || (_[2] = (w) => t.value = w),
214
+ label: "Remark",
215
+ "label-mark": "required",
216
+ rules: [u(jn)()]
217
+ }, null, 8, ["modelValue", "rules"]),
218
+ a("div", ta, [
219
+ $(b, {
220
+ label: "Cancel",
221
+ variant: "tertiary",
222
+ onClick: _[3] || (_[3] = (w) => 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"])) : (h(), T(ce, { key: 0 }, [
234
+ de("Loading")
235
+ ], 64));
236
+ };
237
+ }
238
+ }), na = He(0);
239
+ function sn(n) {
240
+ const l = n.measurementsAmounts.groupBy((o) => o.measurement.id), t = n.sku.unit.measurements.reduce((o, g) => {
241
+ var c, x;
242
+ const i = ((x = (c = l.get(g.id)) == null ? void 0 : c[0]) == null ? void 0 : x.amount) ?? na, s = lt(g.conversion, i);
243
+ return o + +ht(s);
244
+ }, +ht(n.baseAmount));
245
+ return Jt(t, n.baseAmount.precision);
246
+ }
247
+ const aa = He(0), oa = He(100);
248
+ function sa(n, l, t, o, g, i, s, c) {
249
+ var z, le, P, S, ie;
250
+ const x = sn(n), A = o ?? x, f = Xt(A, l), B = l.amount === 0 ? null : en(f, {
251
+ ...l,
252
+ amount: Math.abs(l.amount)
253
+ }), N = B ? lt(B, oa) : null, E = ((z = n.sku.defaultCost) == null ? void 0 : z.costPerUnit) ?? { amount: 0, precision: 0 }, I = Number(te.toFormatString({ value: E })), _ = ((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: _ })
258
+ ), p = g ? Number(te.toFormatString({ value: g })) : 0, v = Number(te.toFormatString({ value: l })), m = Number(te.toFormatString({ value: A })), b = m - v, y = b * I / R, w = m * I / R, Y = v * I / R, q = {};
259
+ return s && i && s.forEach((L) => {
260
+ const F = { amount: 0, precision: 0 }, Q = i[L];
261
+ if (Q) {
262
+ const se = tn(F, Q);
263
+ q[`adjustment_${L}`] = ht(se);
264
+ } else
265
+ q[`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: nn(N, 2)
285
+ })
286
+ ) : null,
287
+ costPerUnit: I,
288
+ opening: p,
289
+ ...q,
290
+ varianceQty: b,
291
+ varianceInCost: y,
292
+ stockTakeValue: w,
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 ra(n) {
306
+ let l = 0;
307
+ for (const t of n.values())
308
+ t.length > l && (l = t.length);
309
+ return l;
310
+ }
311
+ function la(n, l) {
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: an(c, l),
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 ia(n, l = [], t = []) {
343
+ const o = Gt(), 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
+ ...l.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 ca(n, l, t, o = [], g) {
424
+ var re, z, le, P, S, ie, L;
425
+ const i = l.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 = Wt().currentBusiness.value, p = la(I, g), v = I.map((F) => {
444
+ var De, $e;
445
+ const Q = ((De = i.get(F.sku._id)) == null ? void 0 : De[0]) ?? aa, se = p.get(F.sku._id) ?? [], we = c.get(F.sku._id), xe = A.get(F.sku._id);
446
+ return sa(
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 = ra(p), b = ia(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
+ ], w = b.map((F) => `system:${F.id}`), Y = Mn(y, w), q = `[${R == null ? void 0 : R.name}] closing draft (${Tn(new Date(n.updatedAt))}).xlsx`;
481
+ return Un(Y, q), q;
482
+ }
483
+ const ua = { class: "flex flex-col" }, da = {
484
+ key: 0,
485
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
486
+ }, ma = { class: "flex gap-12 py-8 justify-end w-full" }, fa = /* @__PURE__ */ je({
487
+ __name: "RefreshBalanceAction",
488
+ props: {
489
+ draft: {},
490
+ onCancel: { type: Function },
491
+ onFinished: { type: Function }
492
+ },
493
+ setup(n) {
494
+ const l = n;
495
+ ct();
496
+ const t = W(!1), o = W(null), g = W(!1);
497
+ kt(() => {
498
+ if (l.draft.effectiveAt)
499
+ o.value = new Date(l.draft.effectiveAt);
500
+ else {
501
+ const A = new Date(l.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 ? "" : rt(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 ? "" : Zt(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, l.onFinished(o.value.toISOString());
531
+ }
532
+ return (A, f) => {
533
+ const B = Z("FmLabel"), N = Z("FmDatePicker"), E = Z("FmTimePicker"), I = Z("FmButton"), _ = Z("FmForm");
534
+ return g.value ? (h(), ae(_, {
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", ua, [
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(rt)(/* @__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 ? (h(), T("div", da, " Cannot select future date ")) : K("", !0)
576
+ ]),
577
+ a("div", ma, [
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"])) : (h(), T(ce, { key: 0 }, [
594
+ de("Loading")
595
+ ], 64));
596
+ };
597
+ }
598
+ }), it = Qt(
599
+ "closingDraftActions",
600
+ function() {
601
+ const l = Cn(), t = Ke(), o = ct(), g = qe(), i = Rn(), s = on(), c = W(!1), x = W();
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 w;
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 q = await o.readAdjustmentById(Y);
621
+ return ((q == null ? void 0 : q.skus) ?? []).map((z) => ({
622
+ id: z.sku._id,
623
+ balance: z.fromBalance,
624
+ costs: z.fromCostBalances
625
+ }));
626
+ } else
627
+ return await i.readStockBalance(), ((w = i.stockBalance) == null ? void 0 : w.skus) ?? [];
628
+ }
629
+ async function B(b, y, w, Y) {
630
+ y || (t.open({
631
+ title: "Exporting",
632
+ message: "Fetching data..."
633
+ }), y = await f(b)), ca(
634
+ b,
635
+ y,
636
+ w ?? [],
637
+ Y ?? [],
638
+ s.value
639
+ );
640
+ }
641
+ function N(b, y, w) {
642
+ l.open({
643
+ title: "Approve draft",
644
+ contentComponent: bt,
645
+ contentComponentProps: {
646
+ draft: b,
647
+ action: oe.enum.approveDraft,
648
+ onFinished: () => {
649
+ l.close(), y == null || y();
650
+ },
651
+ onCancel: () => {
652
+ l.close();
653
+ }
654
+ }
655
+ }).onClose(() => {
656
+ w == null || w();
657
+ });
658
+ }
659
+ function E(b, y) {
660
+ l.open({
661
+ title: "Reject draft",
662
+ contentComponent: bt,
663
+ contentComponentProps: {
664
+ draft: b,
665
+ action: oe.enum.rejectDraft,
666
+ onFinished: () => {
667
+ l.close(), y == null || y();
668
+ },
669
+ onCancel: () => l.close()
670
+ }
671
+ });
672
+ }
673
+ function I(b, y) {
674
+ l.open({
675
+ title: "Mark draft as failed",
676
+ contentComponent: bt,
677
+ contentComponentProps: {
678
+ draft: b,
679
+ action: oe.enum.markAsFailed,
680
+ onFinished: () => {
681
+ l.close(), y == null || y();
682
+ },
683
+ onCancel: () => l.close()
684
+ }
685
+ });
686
+ }
687
+ async function _(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, w) {
705
+ await l.open({
706
+ title: "Refresh balance",
707
+ contentComponent: fa,
708
+ contentComponentProps: {
709
+ draft: b,
710
+ onFinished: (Y) => {
711
+ l.close(), w == null || w(Y);
712
+ },
713
+ onCancel: async () => {
714
+ l.close(), y == null || y();
715
+ }
716
+ }
717
+ });
718
+ }
719
+ async function v(b) {
720
+ await l.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 (w) {
744
+ t.open({
745
+ title: "Error",
746
+ message: (w == null ? void 0 : w.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: _,
758
+ exportDraft: B,
759
+ refreshBalance: p,
760
+ cloneDraft: m,
761
+ viewClosingDraftShow: c,
762
+ viewClosingDraftProps: x,
763
+ invalidateDraftCache: v
764
+ };
765
+ }
766
+ );
767
+ function st(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 rn = Qt(
780
+ "closingDraftTable",
781
+ function() {
782
+ const { t: l } = Ye(), t = Wt(), o = it(), g = W(new Array()), i = W(0), s = W(!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 = zn(
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((w) => w.rejectRemark)) ?? p.remark ?? "";
831
+ return { count: v, remark: m };
832
+ }
833
+ function I() {
834
+ o.closeDraftDialog(), A();
835
+ }
836
+ function _(p, v) {
837
+ switch (v = Fn(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: () => l("inventory.closing.table.createdAt"),
858
+ cell(p) {
859
+ return Nn(`${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: () => l("inventory.closing.draft.table.id"),
869
+ cell(p) {
870
+ return p.getValue();
871
+ },
872
+ enableSorting: !0
873
+ },
874
+ {
875
+ accessorKey: "effectiveAt",
876
+ header: () => l("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: () => l("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, w) => k("div", { class: "flex gap-4" }, [
896
+ k(
897
+ "span",
898
+ { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" },
899
+ `${y}:`
900
+ ),
901
+ k(
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
+ `${w}`
908
+ )
909
+ ]);
910
+ return k("div", { class: "flex flex-col gap-2", style: "width: 300px;" }, [
911
+ b(l("inventory.closing.draft.table.items"), v),
912
+ m ? b(l("inventory.closing.draft.table.remark"), m) : null
913
+ ]);
914
+ }
915
+ },
916
+ {
917
+ id: "status",
918
+ accessorFn: (p) => p.status,
919
+ header: () => l("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((q) => q.rejectedAt), w = y ? new Date(y) : null;
924
+ return m === "DRAFT" && w ? w.getTime() > b.getTime() ? k(
925
+ "div",
926
+ {
927
+ class: "flex"
928
+ },
929
+ k(
930
+ "div",
931
+ {
932
+ class: ["fm-status-badge", st("FAILED")]
933
+ },
934
+ "Rejected"
935
+ )
936
+ ) : k(
937
+ "div",
938
+ {
939
+ class: "flex"
940
+ },
941
+ k(
942
+ "div",
943
+ {
944
+ class: ["fm-status-badge", st("PROCESSING")]
945
+ },
946
+ "Updated"
947
+ )
948
+ ) : k(
949
+ "div",
950
+ {
951
+ class: "flex"
952
+ },
953
+ k(
954
+ "div",
955
+ {
956
+ class: ["fm-status-badge", st(m)]
957
+ },
958
+ Be(m)
959
+ )
960
+ );
961
+ }
962
+ },
963
+ {
964
+ id: "updatedAt",
965
+ accessorFn: (p) => p.updatedAt,
966
+ header: () => l("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 k("div", { class: "flex flex-col" }, [
973
+ k(
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
+ k(
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
+ Ht[Ne.Details],
992
+ Ht[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
+ ], w = 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 Vn(
1017
+ [
1018
+ ...b,
1019
+ ...v.status === _e.enum.DRAFT ? y : []
1020
+ ],
1021
+ (q) => _(q, v),
1022
+ w
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
+ ), pa = { class: "fm-typo-en-heading-lg-600" }, va = { class: "py-4" }, ya = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, ga = { key: 0 }, ba = { class: "mt-4 flex gap-4" }, ha = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, ka = { key: 0 }, _a = {
1042
+ key: 0,
1043
+ class: "mb-4"
1044
+ }, wa = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full" }, xa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Da = {
1045
+ key: 0,
1046
+ class: "text-fm-color-system-success-300 mr-1"
1047
+ }, Aa = {
1048
+ key: 1,
1049
+ class: "text-fm-color-system-error-300 mr-1"
1050
+ }, Ca = { class: "fm-typo-en-body-md-400" }, Sa = { class: "mt-4 flex gap-4" }, $a = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Fa = {
1051
+ key: 0,
1052
+ class: "flex gap-4"
1053
+ }, Ia = /* @__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: l }) {
1063
+ const { FmStepper: t, FmStep: o, FmDialog: g, FmButton: i } = pe, { t: s } = On(), c = wt(), x = n, A = l, 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
+ }), _ = W(1), R = () => _.value > 1, p = () => _.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 w(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 && (_.value = Y());
1123
+ }
1124
+ ), ze(
1125
+ () => f.value,
1126
+ (P) => {
1127
+ P && _.value === 1 && (_.value = y(1));
1128
+ }
1129
+ ), ze(
1130
+ () => E.value.length,
1131
+ (P) => {
1132
+ P === 0 && _.value === 2 && (_.value = y(2));
1133
+ }
1134
+ );
1135
+ function q() {
1136
+ A("refresh");
1137
+ }
1138
+ function re() {
1139
+ _.value < 3 && (_.value = y(_.value));
1140
+ }
1141
+ function z() {
1142
+ _.value > 1 && (_.value = w(_.value));
1143
+ }
1144
+ function le() {
1145
+ A("approve");
1146
+ }
1147
+ return (P, S) => {
1148
+ const ie = Z("FmIcon");
1149
+ return h(), 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", pa, H(u(s)("inventory.closing.approval.title")), 1)
1156
+ ]),
1157
+ default: ee(() => [
1158
+ a("div", va, [
1159
+ $(u(t), {
1160
+ modelValue: _.value,
1161
+ "onUpdate:modelValue": S[0] || (S[0] = (L) => _.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", ya, H(u(s)("inventory.closing.approval.step.generateReport.description")), 1),
1172
+ _.value === 1 ? (h(), T("div", ga, [
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: q
1180
+ }, null, 8, ["label", "loading", "disabled"]),
1181
+ a("div", ba, [
1182
+ $(u(i), {
1183
+ label: u(s)("inventory.common.continue"),
1184
+ disabled: !f.value,
1185
+ onClick: re
1186
+ }, null, 8, ["label", "disabled"])
1187
+ ])
1188
+ ])) : K("", !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", ha, 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
+ _.value === 2 ? (h(), T("div", ka, [
1201
+ N.value.length > 0 ? (h(), T("div", _a, [
1202
+ S[2] || (S[2] = a("div", { class: "fm-typo-en-body-md-600 mb-2" }, null, -1)),
1203
+ a("div", wa, [
1204
+ (h(!0), T(ce, null, he(N.value, (L) => (h(), T("div", {
1205
+ key: L.id,
1206
+ class: "flex gap-8"
1207
+ }, [
1208
+ a("div", xa, [
1209
+ B.value[L.id] ? (h(), T("span", Da, [
1210
+ $(ie, {
1211
+ name: "check_circle",
1212
+ size: "sm"
1213
+ })
1214
+ ])) : (h(), T("span", Aa, [
1215
+ $(ie, {
1216
+ name: "error",
1217
+ size: "sm"
1218
+ })
1219
+ ])),
1220
+ de(" " + H(L.code), 1)
1221
+ ]),
1222
+ a("div", Ca, H(L.name), 1)
1223
+ ]))), 128))
1224
+ ])
1225
+ ])) : K("", !0),
1226
+ a("div", Sa, [
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
+ ])) : K("", !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", $a, H(u(s)("inventory.closing.approval.step.approval.warning")), 1),
1250
+ _.value === 3 ? (h(), T("div", Fa, [
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
+ ])) : K("", !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 Ba(n) {
1278
+ const l = qe(), t = Pn(), o = Ke(), { t: g } = Ye(), i = W(!1), s = W(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: l.getDbName(),
1291
+ closingDraftRevision: b
1292
+ }
1293
+ }, { unsubscribe: w, initialState: Y } = t.subscribe(y, E);
1294
+ x = w, Y.then((q) => {
1295
+ q != null && q.initialState && E(q.initialState);
1296
+ }).catch((q) => {
1297
+ console.error("Failed to fetch initial state", q);
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 l.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 _(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 l.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, w]) => {
1382
+ f && (m === y && b === w || B());
1383
+ }
1384
+ ), kn(() => {
1385
+ v();
1386
+ }), {
1387
+ refreshing: i,
1388
+ refreshStatus: s,
1389
+ startListening: N,
1390
+ startRefresh: _,
1391
+ cleanup: v
1392
+ };
1393
+ }
1394
+ const Ta = { class: "w-full flex flex-col gap-32" }, ja = { class: "flex flex-col gap-4" }, Ma = { class: "flex justify-between" }, Ua = { class: "flex" }, Ra = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, Pa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Va = { class: "flex gap-1" }, Na = {
1395
+ class: "fm-typo-en-body-lg-600",
1396
+ style: { "white-space": "pre-wrap", "word-break": "break-word" }
1397
+ }, za = {
1398
+ key: 0,
1399
+ class: "flex items-start gap-8 p-12 fm-corner-radius-md border-1 border-yellow-500 bg-yellow-50 text-yellow-700"
1400
+ }, Ea = { class: "flex flex-col gap-2" }, La = { class: "fm-typo-en-body-sm-400 list-disc pl-16" }, Oa = { key: 0 }, Ha = { key: 1 }, Ya = { class: "flex flex-col gap-16" }, Ka = { class: "flex items-center" }, Wa = {
1401
+ key: 0,
1402
+ class: "flex gap-8"
1403
+ }, qa = {
1404
+ key: 0,
1405
+ class: "w-full flex flex-col items-center"
1406
+ }, Ga = { class: "flex items-center gap-8" }, Qa = { class: "flex flex-col gap-8" }, Za = { class: "flex gap-8" }, Ja = {
1407
+ key: 0,
1408
+ class: "flex gap-8"
1409
+ }, Xa = {
1410
+ key: 1,
1411
+ class: "flex gap-8 flex-wrap"
1412
+ }, eo = { class: "overflow-x-auto" }, to = {
1413
+ key: 1,
1414
+ class: "flex-1 xs:w-screen xs:max-w-full"
1415
+ }, no = {
1416
+ key: 0,
1417
+ class: "flex flex-col items-center gap-8 h-full"
1418
+ }, ao = ["src"], oo = {
1419
+ key: 1,
1420
+ class: "px-4 flex flex-col"
1421
+ }, so = { class: "flex gap-12 content-stretch" }, ro = {
1422
+ class: "flex flex-col w-24",
1423
+ name: "circles"
1424
+ }, lo = { class: "flex-1 flex flex-col items-center" }, io = { class: "flex-1 flex flex-col items-center" }, co = {
1425
+ class: "py-12 flex flex-col gap-4",
1426
+ name: "received-at header"
1427
+ }, uo = { class: "fm-typo-en-body-lg-400" }, mo = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, fo = { class: "flex gap-12 content-stretch" }, po = {
1428
+ class: "flex flex-col w-24",
1429
+ name: "circles"
1430
+ }, vo = { class: "flex-1 flex flex-col items-center" }, yo = {
1431
+ class: "py-12 flex flex-col gap-4 flex-1",
1432
+ name: "delivery details"
1433
+ }, go = { class: "flex flex-col gap-8" }, bo = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, ho = { class: "flex flex-col gap-4" }, ko = { class: "flex items-center justify-between gap-8 w-full" }, _o = { class: "flex items-center gap-8" }, wo = { class: "flex flex-col items-end" }, xo = { class: "text-2xl font-semibold" }, Yt = "N/A", Do = /* @__PURE__ */ je({
1434
+ __name: "ClosingDraftDialog",
1435
+ props: {
1436
+ show: { type: Boolean },
1437
+ draft: {}
1438
+ },
1439
+ emits: ["submitted", "refresh"],
1440
+ setup(n, { emit: l }) {
1441
+ const t = n, o = M(() => {
1442
+ const r = Gt();
1443
+ return r === "MYR" ? "RM" : r;
1444
+ }), g = rn(), i = M(() => {
1445
+ var r, e;
1446
+ return (r = t.draft) != null && r.closingId ? ((e = g.drafts.find((d) => d._id === t.draft._id)) == null ? void 0 : e.closingIdDisplay) ?? null : null;
1447
+ }), s = it(), c = qt(t, "show"), x = W(!1), A = W(!1), f = W(new Array()), B = W(new Array()), N = W([]), E = ct(), I = Ke(), _ = wt(), R = We(), p = Ot({}), v = M(() => new Set(
1448
+ _.skus.filter((r) => {
1449
+ var e;
1450
+ return p[(e = r.customAttributes) == null ? void 0 : e.tag];
1451
+ }).map((r) => r._id)
1452
+ )), m = l, b = M(() => {
1453
+ var r;
1454
+ return (r = t.draft) == null ? void 0 : r._id;
1455
+ }), y = M(() => {
1456
+ var r;
1457
+ return (r = t.draft) == null ? void 0 : r._rev;
1458
+ }), {
1459
+ refreshing: w,
1460
+ startListening: Y,
1461
+ startRefresh: q,
1462
+ cleanup: re
1463
+ } = Ba({
1464
+ closingDraftId: b,
1465
+ currentRev: y,
1466
+ onCompleted: (r) => {
1467
+ m("refresh", r), f.value = r.stockSnapshot ?? [], c.value = !1;
1468
+ }
1469
+ }), z = W({
1470
+ templateItem: !0,
1471
+ nonTemplateItem: !0
1472
+ }), le = W(null);
1473
+ function P(r, e) {
1474
+ le.value = e ? r : le.value === r ? null : le.value;
1475
+ }
1476
+ const S = (r) => ne(r, { minPrecision: 0, maxPrecision: 3 });
1477
+ function ie(r, e) {
1478
+ return e ? "text-fm-color-system-error-300" : r ? "text-purple-500" : "";
1479
+ }
1480
+ function L(r, e) {
1481
+ return e ? k(pe.FmIcon, { name: "warning", size: "sm", color: "system-error-300" }) : r ? k(pe.FmIcon, { name: "rule", size: "sm" }) : null;
1482
+ }
1483
+ function F(r) {
1484
+ return k(
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
+ k("div", { class: "fm-typo-en-body-sm-600 text-fm-color-typo-secondary mb-4" }, "Breakdown"),
1491
+ ...r.breakdown.map(
1492
+ (e) => k("div", { class: "flex justify-between gap-12" }, [
1493
+ k(
1494
+ "div",
1495
+ { class: ["flex items-center gap-4", ie(e.inactive, e.orphan)] },
1496
+ [L(e.inactive, e.orphan), k("span", e.label)]
1497
+ ),
1498
+ k(
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)} ${r.baseUnit}` : `${S(e.subtotal)} ${r.baseUnit} (ignored)`
1502
+ )
1503
+ ])
1504
+ ),
1505
+ k("hr", { class: "border-fm-color-typo-secondary my-4" }),
1506
+ k("div", { class: "flex justify-between fm-typo-en-body-lg-600" }, [
1507
+ k("span", "Total"),
1508
+ k("span", `${S(r.physicalBalance)} ${r.baseUnit}`)
1509
+ ])
1510
+ ]
1511
+ );
1512
+ }
1513
+ const Q = M(() => {
1514
+ var e, d;
1515
+ const r = [...((e = t.draft) == null ? void 0 : e.items) ?? [], ...((d = t.draft) == null ? void 0 : d.negativeStockItems) ?? []];
1516
+ return v.value.size ? r.filter((j) => v.value.has(j.sku._id)) : r;
1517
+ }), se = M(() => {
1518
+ const r = Q.value.map((e) => e.sku);
1519
+ return r.sort((e, d) => e.code.localeCompare(d.code)), r;
1520
+ }), we = on();
1521
+ kt(Ee), ze(
1522
+ () => t.show,
1523
+ async (r) => {
1524
+ if (!r) {
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(() => Qe.value.reduce((r, e) => r + Number(e.stockTakeValue), 0)), De = He(0), $e = He(100);
1536
+ async function Ee() {
1537
+ var e, d, j, D;
1538
+ if (!R._currentLocation) return;
1539
+ x.value = !0;
1540
+ const r = ((e = t.draft) == null ? void 0 : e.status) === _e.enum.COMPLETED;
1541
+ B.value = [];
1542
+ try {
1543
+ if (await _.init(), r) {
1544
+ const G = t.draft.closingAdjustmentId;
1545
+ if (!G) {
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(G), 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 = ((j = t.draft) == null ? void 0 : j.stockSnapshot) ?? [];
1570
+ const V = /* @__PURE__ */ new Set();
1571
+ if ((D = t.draft) != null && D.adjustmentSnapshot)
1572
+ for (const G of t.draft.adjustmentSnapshot)
1573
+ G.adjustmentsByType && Object.keys(G.adjustmentsByType).forEach((me) => {
1574
+ V.add(me);
1575
+ });
1576
+ const C = ["receive", "sales", "wastage"], J = [];
1577
+ C.forEach((G) => {
1578
+ V.has(G) && (J.push(G), V.delete(G));
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 (w.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 (j) => {
1609
+ await q(j);
1610
+ }
1611
+ );
1612
+ }
1613
+ async function Me() {
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
+ (r) => r.id,
1628
+ (r) => r.balance
1629
+ )
1630
+ ), ut = M(() => Q.value.groupBy((r) => r.sku._id)), ln = M(() => {
1631
+ var r;
1632
+ return (r = t.draft) != null && r.adjustmentSnapshot ? new Map(t.draft.adjustmentSnapshot.map((e) => [e.skuId, e.adjustmentsByType])) : /* @__PURE__ */ new Map();
1633
+ }), cn = M(() => {
1634
+ var r;
1635
+ return (r = t.draft) != null && r.opening ? new Map(t.draft.opening.map((e) => [e.skuId, e.balance])) : /* @__PURE__ */ new Map();
1636
+ });
1637
+ function ye(r, e) {
1638
+ return k(
1639
+ pe.FmTooltip,
1640
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
1641
+ {
1642
+ default() {
1643
+ return r;
1644
+ },
1645
+ content() {
1646
+ return e || r;
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, j = d.adjustedDiffPercentage, D = typeof j == "number" && Math.abs(j) > 10, V = k("div", { class: "flex flex-col gap-4" }, [
1659
+ k(
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
+ k(
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 k(
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 k("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
+ ...Ct.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 j = d.row.original.customAttributeValues[e];
1707
+ return j == null ? "N/A" : typeof j == "number" ? k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(j)) : k("div", { class: "text-right fm-typo-en-body-lg-400" }, String(j));
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 k("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, j = d.costUnit, D = d.baseUnit, V = j ?? D;
1734
+ if (j && j !== D) {
1735
+ const J = se.value.find((G) => G._id === d.id), O = (C = J == null ? void 0 : J.defaultCost) == null ? void 0 : C.measurement;
1736
+ if (O) {
1737
+ const G = O.conversion.amount / Math.pow(10, O.conversion.precision);
1738
+ return k("div", { class: "flex flex-col" }, [
1739
+ k(
1740
+ "span",
1741
+ { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1742
+ V
1743
+ ),
1744
+ k("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, [
1745
+ "1 ",
1746
+ k("span", { class: "fm-typo-en-body-sm-600" }, j),
1747
+ ` = ${G} `,
1748
+ k("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 k("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 j = d.row.original.adjustmentAmounts[e] ?? { amount: 0, precision: 0 };
1778
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(j));
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 k("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 j;
1802
+ const d = (j = B.value.find((D) => D.id === e.id)) == null ? void 0 : j.balance;
1803
+ return d ? Hn.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, j = te.fromNumber(d.physicalBalance);
1809
+ let D = !0;
1810
+ const V = (O = B.value.find((G) => G.id === d.id)) == null ? void 0 : O.balance;
1811
+ let C;
1812
+ V && !te.equals({ a: j, b: V }) ? (D = !1, C = ne(V)) : C = ne(d.physicalBalance);
1813
+ const J = k("div", { class: "flex flex-col items-end" }, [
1814
+ k(
1815
+ "span",
1816
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1817
+ C
1818
+ ),
1819
+ D ? null : k(
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 ? k(
1826
+ pe.FmPopover,
1827
+ {
1828
+ showPopover: le.value === d.id,
1829
+ placement: "bottom-end",
1830
+ zIndex: 9999,
1831
+ "onPopover-changed": (G) => P(d.id, G)
1832
+ },
1833
+ {
1834
+ "popover-button": () => k(
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
+ k(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 k("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 k("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 k(
1892
+ "div",
1893
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" },
1894
+ Yt
1895
+ );
1896
+ const j = ne(d);
1897
+ if (d === 0)
1898
+ return k("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 k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
1903
+ k(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
+ j
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, j = d.stockTakeValue, D = se.value.find((G) => G._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 G = te.toFormatString({ value: V.conversion }), me = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${d.baseUnit} ÷ ${G} × ${J} ${o.value}`;
1925
+ return k(
1926
+ pe.FmTooltip,
1927
+ { zIndex: 51 },
1928
+ {
1929
+ content() {
1930
+ return me;
1931
+ },
1932
+ default() {
1933
+ return k(
1934
+ "div",
1935
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
1936
+ ne(j)
1937
+ );
1938
+ }
1939
+ }
1940
+ );
1941
+ } else {
1942
+ const G = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${d.baseUnit} × ${J} ${o.value}`;
1943
+ return k(
1944
+ pe.FmTooltip,
1945
+ { zIndex: 51 },
1946
+ {
1947
+ content() {
1948
+ return G;
1949
+ },
1950
+ default() {
1951
+ return k(
1952
+ "div",
1953
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
1954
+ ne(j)
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, j = d.systemValue, D = se.value.find((G) => G._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 G = te.toFormatString({ value: V.conversion }), me = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${d.baseUnit} ÷ ${G} × ${J} ${o.value}`;
1975
+ return k(
1976
+ pe.FmTooltip,
1977
+ { zIndex: 51 },
1978
+ {
1979
+ content() {
1980
+ return me;
1981
+ },
1982
+ default() {
1983
+ return k(
1984
+ "div",
1985
+ { class: "text-right fm-typo-en-body-lg-400" },
1986
+ ne(j)
1987
+ );
1988
+ }
1989
+ }
1990
+ );
1991
+ } else {
1992
+ const G = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${d.baseUnit} × ${J} ${o.value}`;
1993
+ return k(
1994
+ pe.FmTooltip,
1995
+ { zIndex: 51 },
1996
+ {
1997
+ content() {
1998
+ return G;
1999
+ },
2000
+ default() {
2001
+ return k(
2002
+ "div",
2003
+ { class: "text-right fm-typo-en-body-lg-400" },
2004
+ ne(j)
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, j = (C, J, O = "normal") => k(
2021
+ pe.FmTooltip,
2022
+ { zIndex: 50 },
2023
+ {
2024
+ default() {
2025
+ return k(
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
+ k("span", { class: "text-fm-color-typo-primary" }, `${C} `),
2035
+ k(
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) => j(C.amount, C.abbrev, C.variant)), V = d.baseUnitAmount || !D.length ? [j(d.baseUnitAmount, d.baseUnit), ...D] : D;
2051
+ return k(
2052
+ "div",
2053
+ {
2054
+ class: "flex gap-8 flex-nowrap",
2055
+ style: { minWidth: `${120 * V.length}px` }
2056
+ },
2057
+ V
2058
+ );
2059
+ }
2060
+ }
2061
+ ]), un = M(() => xt.value.map((r) => r.size ?? 0).reduce((r, e) => r + e)), dt = W(""), Qe = M(() => {
2062
+ var d, j;
2063
+ const r = ((j = (d = t.draft) == null ? void 0 : d.negativeStockItems) == null ? void 0 : j.reduce(
2064
+ (D, V) => (D[V.sku._id] = V, D),
2065
+ {}
2066
+ )) ?? {};
2067
+ return se.value.map((D) => {
2068
+ var Bt, Tt, jt, Mt, Ut, Rt, Pt, Vt, Nt, zt, Et;
2069
+ const V = (Bt = ut.value.get(D._id)) == null ? void 0 : Bt[0], C = ((Tt = Ge.value.get(D._id)) == null ? void 0 : Tt[0]) ?? De, J = ((jt = D.defaultCost) == null ? void 0 : jt.costPerUnit) ?? De, O = Number(te.toFormatString({ value: J })), G = ((Ut = (Mt = D.defaultCost) == null ? void 0 : Mt.measurement) == null ? void 0 : Ut.conversion) ?? {
2070
+ amount: 1,
2071
+ precision: 0
2072
+ }, me = Number(
2073
+ te.toFormatString({ value: G })
2074
+ ), Ae = cn.value.get(D._id), ge = Ae ? Number(te.toFormatString({ value: Ae })) : 0, Fe = ln.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] = tn(be, Ie));
2078
+ }), !V) {
2079
+ const X = Number(te.toFormatString({ value: C })), be = 0 - X, Ie = be * O / me, nt = 0, Pe = X * O / me;
2080
+ return {
2081
+ id: D._id,
2082
+ code: D.code,
2083
+ name: D.name,
2084
+ costUnit: ((Pt = (Rt = D.defaultCost) == null ? void 0 : Rt.measurement) == null ? void 0 : Pt.abbrev) ?? null,
2085
+ baseUnit: D.unit.abbrev,
2086
+ baseUnitAmount: 0,
2087
+ systemBalance: X,
2088
+ physicalBalance: 0,
2089
+ adjustedAmount: -X,
2090
+ adjustedDiffPercentage: -100,
2091
+ isTemplateItem: !r[D._id],
2092
+ costPerUnit: O,
2093
+ opening: ge,
2094
+ varianceQty: be,
2095
+ varianceInCost: Ie,
2096
+ stockTakeValue: nt,
2097
+ systemValue: Pe,
2098
+ adjustmentAmounts: U,
2099
+ customAttributeValues: D.customAttributes ?? {},
2100
+ measurements: [],
2101
+ breakdown: []
2102
+ };
2103
+ }
2104
+ const ue = sn(V), fe = (Nt = (Vt = B.value) == null ? void 0 : Vt.find(
2105
+ (X) => X.id === D._id
2106
+ )) == null ? void 0 : Nt.balance, ke = Xt(
2107
+ fe ?? ue,
2108
+ C
2109
+ ), Re = C.amount === 0 ? null : en(ke, {
2110
+ ...C,
2111
+ amount: Math.abs(C.amount)
2112
+ }), et = Re ? lt(Re, $e) : null, pt = Number(te.toFormatString({ value: C })), vt = Number(te.toFormatString({ value: ue })), $t = vt - pt, pn = $t * O / me, vn = vt * O / me, yn = pt * O / me, tt = Number(te.toFormatString({ value: V.baseAmount })), Ft = [], yt = [];
2113
+ tt && yt.push({
2114
+ label: "Base",
2115
+ amount: tt,
2116
+ abbrev: D.unit.abbrev,
2117
+ subtotal: tt,
2118
+ inactive: !1,
2119
+ orphan: !1,
2120
+ counted: !0
2121
+ });
2122
+ const gn = new Map(
2123
+ V.measurementsAmounts.map((X) => [X.measurement.id, X.amount])
2124
+ ), bn = new Set(D.unit.measurements.map((X) => X.id)), It = (X, be, Ie, nt, Pe) => {
2125
+ const Ve = Number(te.toFormatString({ value: Ie })), Lt = te.toFormatString({ value: be });
2126
+ if (Ft.push({
2127
+ abbrev: `(${X}) × ${Lt}`,
2128
+ amount: Ve,
2129
+ variant: Pe ? "orphan" : nt ? "inactive" : "normal"
2130
+ }), !Ve) return;
2131
+ const hn = Number(
2132
+ te.toFormatString({ value: lt(Ie, be) })
2133
+ );
2134
+ yt.push({
2135
+ label: Pe ? `${Ve} ${X}` : `${Ve} ${X} × ${Lt} ${D.unit.abbrev}`,
2136
+ amount: Ve,
2137
+ abbrev: X,
2138
+ subtotal: hn,
2139
+ inactive: nt,
2140
+ orphan: Pe,
2141
+ counted: !Pe
2142
+ });
2143
+ };
2144
+ for (const X of D.unit.measurements) {
2145
+ const be = gn.get(X.id);
2146
+ be && It(X.abbrev, X.conversion, be, an(X, we.value), !1);
2147
+ }
2148
+ for (const X of V.measurementsAmounts)
2149
+ bn.has(X.measurement.id) || It(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: ((Et = (zt = D.defaultCost) == null ? void 0 : zt.measurement) == null ? void 0 : Et.abbrev) ?? null,
2155
+ baseUnit: D.unit.abbrev,
2156
+ baseUnitAmount: tt,
2157
+ measurements: Ft,
2158
+ breakdown: yt,
2159
+ systemBalance: pt,
2160
+ physicalBalance: vt,
2161
+ adjustedAmount: Number(te.toFormatString({ value: ke })),
2162
+ adjustedDiffPercentage: et ? Number(
2163
+ te.toFormatString({
2164
+ value: nn(et, 2)
2165
+ })
2166
+ ) : null,
2167
+ isTemplateItem: !r[D._id],
2168
+ costPerUnit: O,
2169
+ opening: ge,
2170
+ varianceQty: $t,
2171
+ varianceInCost: pn,
2172
+ stockTakeValue: vn,
2173
+ systemValue: yn,
2174
+ adjustmentAmounts: U,
2175
+ customAttributeValues: D.customAttributes ?? {}
2176
+ };
2177
+ }).filter((D) => !!(D.isTemplateItem && z.value.templateItem || !D.isTemplateItem && z.value.nonTemplateItem));
2178
+ }), Dt = M(
2179
+ () => Qe.value.some((r) => r.measurements.some((e) => e.variant === "inactive"))
2180
+ ), At = M(
2181
+ () => Qe.value.some((r) => r.measurements.some((e) => e.variant === "orphan"))
2182
+ ), dn = M(
2183
+ () => Dt.value || At.value
2184
+ ), mt = M(() => {
2185
+ const r = /* @__PURE__ */ new Set();
2186
+ for (const e of se.value)
2187
+ if (e.customAttributes)
2188
+ for (const d of Object.keys(e.customAttributes))
2189
+ d !== "tag" && r.add(d);
2190
+ return Array.from(r).sort();
2191
+ }), Ze = Ot({}), Ct = M(
2192
+ () => mt.value.filter((r) => Ze[r])
2193
+ ), mn = M(() => {
2194
+ var e, d, j, D, V;
2195
+ if (!t.draft) return [];
2196
+ const r = t.draft.approvedAt ? {
2197
+ action: `Approve at ${Ce(t.draft.approvedAt)}`,
2198
+ // actionAt: props.draft.approvedAt,
2199
+ actionBy: t.draft.approvedBy,
2200
+ remark: t.draft.approveRemark
2201
+ } : (e = t.draft.rejectionHistory) == null ? void 0 : e.computeFirst((C) => ({
2202
+ action: `Reject at ${Ce(C.rejectedAt)}`,
2203
+ // actionAt: e.rejectedAt,
2204
+ actionBy: C.rejectedBy,
2205
+ remark: C.rejectRemark
2206
+ }));
2207
+ return [
2208
+ i.value ? {
2209
+ label: "ID",
2210
+ value: i.value
2211
+ } : null,
2212
+ {
2213
+ label: "Location",
2214
+ value: ((d = R._currentLocation) == null ? void 0 : d.name) ?? Yt
2215
+ },
2216
+ {
2217
+ label: "Created at",
2218
+ value: Ce(t.draft.createdAt)
2219
+ },
2220
+ {
2221
+ label: "Created by",
2222
+ value: t.draft.createdBy.name
2223
+ },
2224
+ {
2225
+ label: "Updated at",
2226
+ value: Ce(t.draft.updatedAt)
2227
+ },
2228
+ {
2229
+ label: "Updated by",
2230
+ value: t.draft.updatedBy.name
2231
+ },
2232
+ {
2233
+ label: "Effective at",
2234
+ value: Ce(t.draft.effectiveAt ?? Te((j = t.draft) == null ? void 0 : j._id))
2235
+ },
2236
+ {
2237
+ label: "Using template",
2238
+ value: ((D = t.draft.usingTemplates.find((C) => C)) == null ? void 0 : D.name) ?? "None"
2239
+ },
2240
+ t.draft.remark ? {
2241
+ label: "Remark",
2242
+ value: t.draft.remark
2243
+ } : null,
2244
+ r ? {
2245
+ label: "Last action",
2246
+ value: r.action
2247
+ } : null,
2248
+ r && r.actionBy ? {
2249
+ label: "Last action by",
2250
+ value: (V = r.actionBy) == null ? void 0 : V.name
2251
+ } : null,
2252
+ r && r.remark ? {
2253
+ label: "Action remark",
2254
+ value: r.remark
2255
+ } : null
2256
+ ].filter((C) => C).map((C) => C);
2257
+ }), ft = [
2258
+ {
2259
+ label: "Overview",
2260
+ value: "overview"
2261
+ },
2262
+ {
2263
+ label: "Action history",
2264
+ value: "history"
2265
+ }
2266
+ ], Oe = W(ft[0]), Ue = M(() => {
2267
+ var j, D, V;
2268
+ const r = ((j = t.draft) == null ? void 0 : j.activityLogs) ?? [], e = ((D = t.draft) == null ? void 0 : D.rejectionHistory) ?? [];
2269
+ for (const C of e)
2270
+ r.find(
2271
+ (O) => `${O.action}_${O.performedAt}` == `${oe.enum.rejectDraft}_${C.rejectedAt}`
2272
+ ) || r.push({
2273
+ action: oe.enum.rejectDraft,
2274
+ performedAt: C.rejectedAt,
2275
+ performedBy: C.rejectedBy,
2276
+ remark: C.rejectRemark
2277
+ });
2278
+ return (V = t.draft) != null && V.approvedAt && (r.find(
2279
+ (J) => {
2280
+ var O;
2281
+ return `${J.action}_${J.performedAt}` == `${oe.enum.approveDraft}_${(O = t.draft) == null ? void 0 : O.approvedAt}`;
2282
+ }
2283
+ ) || r.push({
2284
+ action: oe.enum.approveDraft,
2285
+ performedAt: t.draft.approvedAt,
2286
+ performedBy: t.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
2287
+ remark: t.draft.approveRemark
2288
+ })), r.sort((C, J) => new Date(J.performedAt).getTime() - new Date(C.performedAt).getTime()).map(
2289
+ (C) => ({
2290
+ header: Be(C.action),
2291
+ date: Ce(C.performedAt),
2292
+ info: [
2293
+ {
2294
+ label: "Performed by",
2295
+ values: [C.performedBy.name]
2296
+ },
2297
+ {
2298
+ label: "Remark",
2299
+ values: [C.remark ?? ""]
2300
+ }
2301
+ ]
2302
+ })
2303
+ );
2304
+ }), Je = W(!1), Xe = W(!1), St = M(() => {
2305
+ var r;
2306
+ return ((r = t.draft) == null ? void 0 : r.status) !== _e.enum.DRAFT ? "Status is not draft." : null;
2307
+ });
2308
+ function fn() {
2309
+ t.draft && (Xe.value = !0, s.approveDraft(
2310
+ t.draft,
2311
+ () => {
2312
+ Xe.value = !1, Je.value = !1, m("submitted");
2313
+ },
2314
+ () => {
2315
+ Xe.value = !1;
2316
+ }
2317
+ ));
2318
+ }
2319
+ return (r, e) => {
2320
+ const d = Z("FmButtonGroup"), j = Z("FmMenuDivider"), D = Z("FmCard"), V = Z("FmIcon"), C = Z("FmButton"), J = Z("FmCircularProgress"), O = Z("FmChip"), G = Z("FmTextField"), me = Z("FmTable"), Ae = Z("FmSpacer"), ge = Z("FmTooltip"), Fe = Z("FmSideSheet");
2321
+ return h(), T(ce, null, [
2322
+ $(Fe, {
2323
+ "dismiss-away": "",
2324
+ "max-width": 9999,
2325
+ "model-value": u(c),
2326
+ "onUpdate:modelValue": e[9] || (e[9] = (U) => _t(c) ? c.value = U : null),
2327
+ header: "Closing details"
2328
+ }, {
2329
+ "side-sheet-footer": ee(() => {
2330
+ var U, ue, fe, ke;
2331
+ return [
2332
+ a("div", ko, [
2333
+ a("div", _o, [
2334
+ ((U = t.draft) == null ? void 0 : U.status) === u(_e).enum.DRAFT ? (h(), T(ce, { key: 0 }, [
2335
+ St.value ? (h(), ae(ge, {
2336
+ key: 0,
2337
+ "z-index": 51,
2338
+ placement: "right"
2339
+ }, {
2340
+ content: ee(() => [
2341
+ de(H(St.value), 1)
2342
+ ]),
2343
+ default: ee(() => [
2344
+ $(C, {
2345
+ disabled: "",
2346
+ key: "approve key",
2347
+ label: "Approve"
2348
+ })
2349
+ ]),
2350
+ _: 1
2351
+ })) : (h(), ae(C, {
2352
+ key: "approve key",
2353
+ label: "Approve",
2354
+ onClick: e[5] || (e[5] = (Re) => Je.value = !0)
2355
+ }))
2356
+ ], 64)) : K("", !0),
2357
+ ((ue = t.draft) == null ? void 0 : ue.status) === u(_e).enum.DRAFT ? (h(), ae(C, {
2358
+ key: 1,
2359
+ label: "Reject",
2360
+ variant: "destructive",
2361
+ onClick: e[6] || (e[6] = () => t.draft && u(s).rejectDraft(t.draft, () => m("submitted")))
2362
+ })) : K("", !0),
2363
+ $(C, {
2364
+ label: "Close",
2365
+ variant: "tertiary",
2366
+ onClick: e[7] || (e[7] = (Re) => c.value = !1)
2367
+ }),
2368
+ (fe = t.draft) != null && fe.approvedAt && ((ke = t.draft) == null ? void 0 : ke.status) !== u(_e).enum.COMPLETED ? (h(), ae(gt, { key: 2 }, {
2369
+ default: ee(() => [
2370
+ $(C, {
2371
+ label: "Sync",
2372
+ loading: A.value,
2373
+ onClick: e[8] || (e[8] = () => {
2374
+ t.draft && (A.value = !0, u(s).syncDraft(t.draft, () => {
2375
+ A.value = !1, m("submitted");
2376
+ }));
2377
+ })
2378
+ }, null, 8, ["loading"])
2379
+ ]),
2380
+ _: 1
2381
+ })) : K("", !0)
2382
+ ]),
2383
+ a("div", wo, [
2384
+ e[23] || (e[23] = a("div", { class: "text-xs text-gray-500 uppercase tracking-wide" }, "Total stock take value", -1)),
2385
+ a("div", xo, H(o.value) + " " + H(xe.value.toFixed(2)), 1)
2386
+ ])
2387
+ ])
2388
+ ];
2389
+ }),
2390
+ default: ee(() => [
2391
+ a("div", Ta, [
2392
+ a("div", null, [
2393
+ $(d, {
2394
+ items: ft,
2395
+ modelValue: Oe.value,
2396
+ "onUpdate:modelValue": e[0] || (e[0] = (U) => Oe.value = U)
2397
+ }, null, 8, ["modelValue"])
2398
+ ]),
2399
+ Oe.value.value === "overview" ? (h(), T(ce, { key: 0 }, [
2400
+ $(gt, { selectable: "" }, {
2401
+ default: ee(() => {
2402
+ var U;
2403
+ return [
2404
+ a("div", ja, [
2405
+ e[11] || (e[11] = a("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, [
2406
+ a("div", { class: "flex gap-1" }, "Draft ID")
2407
+ ], -1)),
2408
+ de(" " + H((U = r.draft) == null ? void 0 : U._id), 1)
2409
+ ])
2410
+ ];
2411
+ }),
2412
+ _: 1
2413
+ }),
2414
+ $(D, {
2415
+ variant: "outlined",
2416
+ class: "flex flex-col gap-8 px-12 py-16"
2417
+ }, {
2418
+ default: ee(() => {
2419
+ var U, ue;
2420
+ return [
2421
+ a("div", Ma, [
2422
+ e[12] || (e[12] = a("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
2423
+ a("div", Ua, [
2424
+ a("div", {
2425
+ class: Se(["fm-status-badge", u(st)(((U = r.draft) == null ? void 0 : U.status) ?? "DRAFT")])
2426
+ }, H(u(Be)(((ue = r.draft) == null ? void 0 : ue.status) ?? "")), 3)
2427
+ ])
2428
+ ]),
2429
+ $(j),
2430
+ a("div", Ra, [
2431
+ (h(!0), T(ce, null, he(mn.value, (fe, ke) => (h(), T("div", {
2432
+ class: "flex flex-col gap-4",
2433
+ key: ke
2434
+ }, [
2435
+ a("div", Pa, [
2436
+ a("div", Va, H(fe.label), 1)
2437
+ ]),
2438
+ a("div", Na, H(fe.value), 1)
2439
+ ]))), 128))
2440
+ ])
2441
+ ];
2442
+ }),
2443
+ _: 1
2444
+ }),
2445
+ dn.value ? (h(), T("div", za, [
2446
+ $(V, {
2447
+ name: "rule",
2448
+ size: "sm"
2449
+ }),
2450
+ a("div", Ea, [
2451
+ e[14] || (e[14] = a("div", { class: "fm-typo-en-body-md-600" }, "UOM notes", -1)),
2452
+ a("ul", La, [
2453
+ Dt.value ? (h(), T("li", Oa, e[13] || (e[13] = [
2454
+ de(" Measurements highlighted in "),
2455
+ a("span", { class: "font-bold" }, "purple", -1),
2456
+ de(" are NetSuite-inactive UOMs (surfaced for audit; their amounts are part of the base total). ")
2457
+ ]))) : K("", !0),
2458
+ At.value ? (h(), T("li", Ha, " Red highlights are UOMs not on the SKU (ignored). ")) : K("", !0)
2459
+ ])
2460
+ ])
2461
+ ])) : K("", !0),
2462
+ a("div", Ya, [
2463
+ a("div", Ka, [
2464
+ e[15] || (e[15] = a("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
2465
+ x.value ? K("", !0) : (h(), T("div", Wa, [
2466
+ r.draft && r.draft.status !== u(_e).enum.COMPLETED ? (h(), ae(C, {
2467
+ key: 0,
2468
+ label: "Refresh balance",
2469
+ "prepend-icon": "refresh",
2470
+ variant: "secondary",
2471
+ "text-color": "primary",
2472
+ "bg-color": "transparent",
2473
+ "border-color": "primary",
2474
+ loading: u(w),
2475
+ disabled: u(w),
2476
+ onClick: Le
2477
+ }, null, 8, ["loading", "disabled"])) : K("", !0),
2478
+ $(gt, null, {
2479
+ default: ee(() => [
2480
+ $(C, {
2481
+ label: "Invalidate Draft Cache",
2482
+ "prepend-icon": "refresh",
2483
+ variant: "secondary",
2484
+ "text-color": "primary",
2485
+ "bg-color": "transparent",
2486
+ "border-color": "primary",
2487
+ loading: u(w),
2488
+ onClick: Me
2489
+ }, null, 8, ["loading"])
2490
+ ]),
2491
+ _: 1
2492
+ }),
2493
+ $(C, {
2494
+ label: "Export data",
2495
+ "prepend-icon": "download",
2496
+ variant: "secondary",
2497
+ "text-color": "primary",
2498
+ "bg-color": "transparent",
2499
+ "border-color": "primary",
2500
+ onClick: e[1] || (e[1] = (U) => r.draft ? u(s).exportDraft(
2501
+ r.draft,
2502
+ f.value,
2503
+ B.value,
2504
+ Ct.value
2505
+ ) : null)
2506
+ })
2507
+ ]))
2508
+ ]),
2509
+ x.value ? (h(), T("div", qa, [
2510
+ e[17] || (e[17] = a("div", { class: "h-80" }, null, -1)),
2511
+ a("div", Ga, [
2512
+ a("div", null, [
2513
+ $(J, { size: "md" })
2514
+ ]),
2515
+ e[16] || (e[16] = a("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
2516
+ ]),
2517
+ e[18] || (e[18] = a("div", { class: "h-80" }, null, -1))
2518
+ ])) : (h(), T(ce, { key: 1 }, [
2519
+ a("div", Qa, [
2520
+ a("div", Za, [
2521
+ $(O, {
2522
+ label: "Template Item(s)",
2523
+ selected: z.value.templateItem,
2524
+ onClick: e[2] || (e[2] = (U) => z.value.templateItem = !z.value.templateItem)
2525
+ }, null, 8, ["selected"]),
2526
+ $(O, {
2527
+ label: "Non-template Item(s)",
2528
+ selected: z.value.nonTemplateItem,
2529
+ onClick: e[3] || (e[3] = (U) => z.value.nonTemplateItem = !z.value.nonTemplateItem)
2530
+ }, null, 8, ["selected"])
2531
+ ]),
2532
+ $(G, {
2533
+ modelValue: dt.value,
2534
+ "onUpdate:modelValue": e[4] || (e[4] = (U) => dt.value = U),
2535
+ placeholder: "Filter items"
2536
+ }, null, 8, ["modelValue"])
2537
+ ]),
2538
+ u(_).skuTags.size ? (h(), T("div", Ja, [
2539
+ (h(!0), T(ce, null, he(u(_).skuTags.keys(), (U) => (h(), ae(O, {
2540
+ key: `${U}`,
2541
+ label: `${U}`,
2542
+ selectable: "",
2543
+ selected: p[`${U}`],
2544
+ onClick: (ue) => p[`${U}`] = !p[`${U}`]
2545
+ }, {
2546
+ default: ee(() => [
2547
+ p[`${U}`] ? (h(), ae(V, {
2548
+ key: 0,
2549
+ name: "check",
2550
+ class: "text-white",
2551
+ size: "sm"
2552
+ })) : K("", !0),
2553
+ a("span", {
2554
+ class: Se([
2555
+ "",
2556
+ {
2557
+ "text-white fm-typo-en-body-md-600": p[`${U}`],
2558
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !p[`${U}`]
2559
+ }
2560
+ ])
2561
+ }, H(U), 3)
2562
+ ]),
2563
+ _: 2
2564
+ }, 1032, ["label", "selected", "onClick"]))), 128))
2565
+ ])) : K("", !0),
2566
+ mt.value.length ? (h(), T("div", Xa, [
2567
+ e[19] || (e[19] = a("span", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary self-center" }, "Extra columns:", -1)),
2568
+ (h(!0), T(ce, null, he(mt.value, (U) => (h(), ae(O, {
2569
+ key: U,
2570
+ label: U,
2571
+ selectable: "",
2572
+ selected: Ze[U],
2573
+ onClick: (ue) => Ze[U] = !Ze[U]
2574
+ }, null, 8, ["label", "selected", "onClick"]))), 128))
2575
+ ])) : K("", !0),
2576
+ a("div", eo, [
2577
+ a("div", {
2578
+ style: Kt({ height: "600px", minWidth: `${un.value}px` })
2579
+ }, [
2580
+ $(me, {
2581
+ "column-defs": xt.value,
2582
+ "row-data": Qe.value,
2583
+ "search-value": dt.value
2584
+ }, null, 8, ["column-defs", "row-data", "search-value"])
2585
+ ], 4)
2586
+ ])
2587
+ ], 64))
2588
+ ])
2589
+ ], 64)) : K("", !0),
2590
+ Oe.value.value === "history" ? (h(), T("div", to, [
2591
+ Ue.value.length ? (h(), T("div", oo, [
2592
+ (h(!0), T(ce, null, he(Ue.value, (U, ue) => (h(), T(ce, { key: ue }, [
2593
+ a("div", so, [
2594
+ a("div", ro, [
2595
+ a("div", lo, [
2596
+ a("div", {
2597
+ class: Se([
2598
+ {
2599
+ "bg-fm-color-primary": ue !== 0,
2600
+ "bg-white": ue === 0
2601
+ },
2602
+ "w-[2px] h-full"
2603
+ ])
2604
+ }, null, 2)
2605
+ ]),
2606
+ e[22] || (e[22] = a("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
2607
+ a("div", io, [
2608
+ a("div", {
2609
+ class: Se([
2610
+ {
2611
+ "bg-fm-color-primary": ue < Ue.value.length - 1,
2612
+ "bg-white": ue >= Ue.value.length - 1
2613
+ },
2614
+ "w-[2px] h-full"
2615
+ ])
2616
+ }, null, 2)
2617
+ ])
2618
+ ]),
2619
+ a("div", co, [
2620
+ a("div", uo, H(U.header), 1),
2621
+ a("div", mo, H(U.date), 1)
2622
+ ])
2623
+ ]),
2624
+ a("div", fo, [
2625
+ a("div", po, [
2626
+ a("div", vo, [
2627
+ a("div", {
2628
+ class: Se([
2629
+ {
2630
+ "bg-fm-color-primary": ue < Ue.value.length - 1,
2631
+ "bg-white": ue >= Ue.value.length - 1
2632
+ },
2633
+ "w-[2px] h-full"
2634
+ ])
2635
+ }, null, 2)
2636
+ ])
2637
+ ]),
2638
+ a("div", yo, [
2639
+ $(D, {
2640
+ variant: "outlined",
2641
+ class: "py-12 px-16"
2642
+ }, {
2643
+ default: ee(() => [
2644
+ a("div", go, [
2645
+ (h(!0), T(ce, null, he(U.info, (fe, ke) => (h(), T("div", {
2646
+ key: ke,
2647
+ class: "flex flex-col gap-4"
2648
+ }, [
2649
+ a("div", bo, H(fe == null ? void 0 : fe.label), 1),
2650
+ a("div", ho, [
2651
+ (h(!0), T(ce, null, he(fe == null ? void 0 : fe.values, (Re, et) => (h(), T("div", {
2652
+ key: et,
2653
+ class: "fm-typo-en-body-lg-600"
2654
+ }, H(Re), 1))), 128))
2655
+ ])
2656
+ ]))), 128))
2657
+ ])
2658
+ ]),
2659
+ _: 2
2660
+ }, 1024)
2661
+ ])
2662
+ ])
2663
+ ], 64))), 128))
2664
+ ])) : (h(), T("div", no, [
2665
+ $(Ae),
2666
+ a("div", null, [
2667
+ a("img", {
2668
+ src: u(Ln),
2669
+ alt: "List is empty"
2670
+ }, null, 8, ao)
2671
+ ]),
2672
+ e[20] || (e[20] = a("div", { class: "fm-typo-en-body-lg-600" }, H("No records found"), -1)),
2673
+ e[21] || (e[21] = 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)),
2674
+ $(Ae),
2675
+ $(Ae)
2676
+ ]))
2677
+ ])) : K("", !0)
2678
+ ])
2679
+ ]),
2680
+ _: 1
2681
+ }, 8, ["model-value"]),
2682
+ u(c) && t.draft ? (h(), ae(Ia, {
2683
+ key: 0,
2684
+ show: Je.value,
2685
+ "onUpdate:show": e[10] || (e[10] = (U) => Je.value = U),
2686
+ refreshing: u(w),
2687
+ approving: Xe.value,
2688
+ draft: t.draft,
2689
+ onRefresh: Le,
2690
+ onApprove: fn
2691
+ }, null, 8, ["show", "refreshing", "approving", "draft"])) : K("", !0)
2692
+ ], 64);
2693
+ };
2694
+ }
2695
+ });
2696
+ var ve = /* @__PURE__ */ ((n) => (n.ready = "ready", n.negative = "negative", n.systemNegative = "systemNegative", n))(ve || {});
2697
+ async function Ao(n) {
2698
+ return new Promise((l, t) => {
2699
+ const o = new FileReader();
2700
+ o.onload = (g) => {
2701
+ var i;
2702
+ try {
2703
+ const s = (i = g.target) == null ? void 0 : i.result, c = Yn(s, { type: "array" }), x = c.SheetNames[0], A = c.Sheets[x], f = ot.sheet_to_json(A, {
2704
+ header: 1,
2705
+ defval: ""
2706
+ }), B = (v) => String(v).trim().toLowerCase().replace(/^\uFEFF/, ""), N = f.findIndex(
2707
+ (v) => v.some((m) => B(m) === "code")
2708
+ );
2709
+ if (N === -1) {
2710
+ l([]);
2711
+ return;
2712
+ }
2713
+ const E = f[N], I = E.findIndex((v) => B(v) === "code"), _ = E.findIndex((v) => B(v) === "balance");
2714
+ if (I === -1 || _ === -1) {
2715
+ t(
2716
+ new Error(
2717
+ `Missing required columns: ${I === -1 ? '"Code" ' : ""}${_ === -1 ? '"Balance"' : ""}.`.trim()
2718
+ )
2719
+ );
2720
+ return;
2721
+ }
2722
+ const p = f.slice(N + 1).filter((v) => String(v[I]).trim()).map((v) => ({
2723
+ itemCode: String(v[I]).trim(),
2724
+ quantity: Number(v[_]) || 0
2725
+ }));
2726
+ l(p);
2727
+ } catch (s) {
2728
+ t(s);
2729
+ }
2730
+ }, o.onerror = t, o.readAsArrayBuffer(n);
2731
+ });
2732
+ }
2733
+ function Co(n) {
2734
+ const l = /* @__PURE__ */ new Map();
2735
+ return n.forEach((t) => {
2736
+ const o = l.get(t.itemCode) || 0;
2737
+ l.set(t.itemCode, o + t.quantity);
2738
+ }), l;
2739
+ }
2740
+ function So(n, l) {
2741
+ const t = [], o = [];
2742
+ for (const [g, i] of l.entries()) {
2743
+ const s = n[g];
2744
+ if (!s) {
2745
+ o.push(g);
2746
+ continue;
2747
+ }
2748
+ const c = i < 0 ? "negative" : "ready";
2749
+ t.push({
2750
+ sku: s,
2751
+ physicalCount: i,
2752
+ // Note: filled by composable after readStockBalance()
2753
+ systemBalance: { amount: 0, precision: 0 },
2754
+ variance: i - 0,
2755
+ status: c
2756
+ });
2757
+ }
2758
+ return { mergedItems: t, unrecognisedItemCodes: o };
2759
+ }
2760
+ function $o(n, l) {
2761
+ const t = n.filter((x) => !x.isInactive), o = Wn().format("YYYY-MM-DD"), g = `${l} - ${o}.csv`, i = [
2762
+ ["Code", "Name", "Balance"],
2763
+ ...t.map((x) => [x.code, x.name, ""])
2764
+ ], s = ot.aoa_to_sheet(i), c = ot.book_new();
2765
+ ot.book_append_sheet(c, s, "Template"), Kn(c, g, { bookType: "csv" });
2766
+ }
2767
+ function Fo() {
2768
+ const n = W([]), l = W([]), t = W(!1), o = wt(), g = We(), i = ct(), s = M(
2769
+ () => n.value.some((f) => f.status === ve.negative)
2770
+ );
2771
+ async function c(f) {
2772
+ n.value = [], l.value = [], t.value = !0;
2773
+ try {
2774
+ const B = await Ao(f), N = Co(B), E = o.skuByCode, { mergedItems: I, unrecognisedItemCodes: _ } = So(
2775
+ E,
2776
+ N
2777
+ ), R = await i.readStockBalance(), p = R.skus ?? [];
2778
+ p.length === 0 && console.warn(
2779
+ "No SKU balances found when importing closing draft. All system balances will be set to 0.",
2780
+ {
2781
+ stockBalance: R
2782
+ }
2783
+ );
2784
+ const v = new Map(
2785
+ p.map((b) => [b.id, b.balance])
2786
+ ), m = new Set(I.map((b) => b.sku._id));
2787
+ n.value = I.map((b) => {
2788
+ const y = v.get(b.sku._id) ?? { amount: 0, precision: 0 }, w = y.amount / Math.pow(10, y.precision);
2789
+ return { ...b, systemBalance: y, variance: b.physicalCount - w };
2790
+ });
2791
+ for (const b of Object.values(o.skuByCode)) {
2792
+ if (m.has(b._id)) continue;
2793
+ const y = v.get(b._id);
2794
+ if (!y) continue;
2795
+ const w = y.amount / Math.pow(10, y.precision);
2796
+ w >= 0 || n.value.push({
2797
+ sku: b,
2798
+ physicalCount: 0,
2799
+ systemBalance: y,
2800
+ variance: 0 - w,
2801
+ status: ve.systemNegative
2802
+ });
2803
+ }
2804
+ l.value = _;
2805
+ } catch (B) {
2806
+ n.value = [], l.value = [], console.error("Error processing uploaded file", { error: B });
2807
+ } finally {
2808
+ t.value = !1;
2809
+ }
2810
+ }
2811
+ async function x() {
2812
+ const f = qe(), B = n.value.filter((p) => p.status === ve.ready), N = n.value.filter(
2813
+ (p) => p.status === ve.systemNegative
2814
+ ), E = (p) => ({
2815
+ sku: {
2816
+ _id: p.sku._id,
2817
+ code: p.sku.code,
2818
+ name: p.sku.name,
2819
+ unit: p.sku.unit
2820
+ },
2821
+ baseAmount: Jt(p.physicalCount, p.sku.unit.precision),
2822
+ measurementsAmounts: []
2823
+ }), I = B.map(E), _ = N.map(E), R = {
2824
+ effectiveAt: (/* @__PURE__ */ new Date()).toISOString(),
2825
+ items: I,
2826
+ negativeStockItems: _
2827
+ };
2828
+ return await f.createQuickModeDraftWithItems(R);
2829
+ }
2830
+ function A() {
2831
+ var B;
2832
+ const f = ((B = g.currentLocation) == null ? void 0 : B.name) ?? "template";
2833
+ $o(o.skus, f);
2834
+ }
2835
+ return { mergedItems: n, unrecognisedItemCodes: l, hasBlockingErrors: s, isLoading: t, onFileUpload: c, submit: x, downloadTemplate: A };
2836
+ }
2837
+ const Io = { class: "flex flex-col gap-16" }, Bo = {
2838
+ key: 0,
2839
+ class: "px-16 py-12 rounded-8 bg-fm-color-danger-weak text-fm-color-danger-default"
2840
+ }, To = { key: 1 }, jo = { class: "fm-typo-en-label-md-400 cursor-pointer" }, Mo = { class: "mt-8 flex flex-col gap-4" }, Uo = { key: 2 }, Ro = { class: "fm-typo-en-label-md-400 cursor-pointer" }, Po = { class: "mt-8 flex flex-col gap-4" }, Vo = /* @__PURE__ */ je({
2841
+ __name: "ClosingDraftCreatePreviewTable",
2842
+ props: {
2843
+ items: {},
2844
+ unrecognisedItemCodes: {}
2845
+ },
2846
+ setup(n) {
2847
+ const l = n, { t } = Ye(), o = M(
2848
+ () => l.items.filter((c) => c.status === ve.negative)
2849
+ ), g = M(
2850
+ () => l.items.filter((c) => c.status === ve.systemNegative)
2851
+ ), i = M(() => ({
2852
+ [ve.negative]: {
2853
+ bgColor: "bg-fm-color-danger-weak",
2854
+ textColor: "text-fm-color-danger-default",
2855
+ icon: "🚫",
2856
+ label: t("inventory.closing.draft.createDraft.previewTable.status.negative")
2857
+ },
2858
+ [ve.systemNegative]: {
2859
+ bgColor: "bg-fm-color-warning-weak",
2860
+ textColor: "text-fm-color-warning-default",
2861
+ icon: "⚠️",
2862
+ label: t("inventory.closing.draft.createDraft.previewTable.status.systemNegative")
2863
+ }
2864
+ })), s = [
2865
+ {
2866
+ id: "name",
2867
+ header: () => t("inventory.ingredient.name"),
2868
+ cell: (c) => c.row.original.sku.name
2869
+ },
2870
+ {
2871
+ id: "uom",
2872
+ header: () => t("inventory.closing.draft.createDraft.previewTable.uom"),
2873
+ size: 80,
2874
+ cell: (c) => c.row.original.sku.unit.abbrev
2875
+ },
2876
+ {
2877
+ id: "systemBalance",
2878
+ header: () => t("inventory.closing.draft.createDraft.previewTable.systemBalance"),
2879
+ size: 180,
2880
+ cell: (c) => {
2881
+ const x = c.row.original;
2882
+ return k("div", ne(x.systemBalance));
2883
+ }
2884
+ },
2885
+ {
2886
+ id: "physicalCount",
2887
+ header: () => t("inventory.closing.draft.createDraft.previewTable.stockTakeBalance"),
2888
+ cell: (c) => {
2889
+ const x = c.row.original;
2890
+ return k("div", ne(x.physicalCount));
2891
+ }
2892
+ },
2893
+ {
2894
+ id: "variance",
2895
+ header: () => t("inventory.closing.draft.createDraft.previewTable.variance"),
2896
+ cell: (c) => {
2897
+ const A = c.row.original.variance, f = A < 0 ? "text-fm-color-danger-default" : A > 0 ? "text-fm-color-success-default" : "";
2898
+ return k("span", { class: f }, ne(A));
2899
+ }
2900
+ },
2901
+ {
2902
+ id: "variancePercentage",
2903
+ header: () => t("inventory.closing.draft.createDraft.previewTable.variancePercentage"),
2904
+ size: 130,
2905
+ cell: (c) => {
2906
+ const x = c.row.original, A = x.systemBalance.amount / Math.pow(10, x.systemBalance.precision), f = A === 0 ? null : Math.max(
2907
+ -100,
2908
+ Math.min(100, Math.round(x.variance / Math.abs(A) * 1e4) / 100)
2909
+ );
2910
+ if (f === null)
2911
+ return k(
2912
+ "div",
2913
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
2914
+ t("inventory.closing.draft.createDraft.previewTable.notApplicable")
2915
+ );
2916
+ const B = `${ne(f)}`;
2917
+ if (f === 0)
2918
+ return k(
2919
+ "div",
2920
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
2921
+ B
2922
+ );
2923
+ const N = f > 0;
2924
+ return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" }, [
2925
+ k(pe.FmIcon, {
2926
+ name: N ? "arrow_drop_up" : "arrow_drop_down",
2927
+ color: N ? "system-success-300" : "system-error-300",
2928
+ size: "md"
2929
+ }),
2930
+ B
2931
+ ]);
2932
+ }
2933
+ },
2934
+ {
2935
+ id: "status",
2936
+ header: () => t("inventory.common.status"),
2937
+ cell: (c) => {
2938
+ const x = c.row.original.status, A = i.value[x];
2939
+ return A ? k(
2940
+ "span",
2941
+ {
2942
+ class: `px-8 py-2 rounded-4 ${A.bgColor} ${A.textColor} fm-typo-en-label-sm-400`
2943
+ },
2944
+ `${A.icon} ${A.label}`
2945
+ ) : null;
2946
+ }
2947
+ }
2948
+ ];
2949
+ return (c, x) => {
2950
+ const A = Z("FmTable");
2951
+ return h(), T("div", Io, [
2952
+ o.value.length > 0 ? (h(), T("div", Bo, [
2953
+ de(H(u(t)("inventory.closing.draft.createDraft.previewTable.cannotSubmitNegative")) + " ", 1),
2954
+ a("strong", null, H(o.value.map((f) => f.sku.code).join(", ")), 1)
2955
+ ])) : K("", !0),
2956
+ g.value.length > 0 ? (h(), T("details", To, [
2957
+ a("summary", jo, H(u(t)("inventory.closing.draft.createDraft.previewTable.systemNegativeNote", [g.value.length])), 1),
2958
+ a("ul", Mo, [
2959
+ (h(!0), T(ce, null, he(g.value, (f) => (h(), T("li", {
2960
+ key: f.sku._id,
2961
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
2962
+ }, H(f.sku.code), 1))), 128))
2963
+ ])
2964
+ ])) : K("", !0),
2965
+ c.unrecognisedItemCodes.length > 0 ? (h(), T("details", Uo, [
2966
+ a("summary", Ro, H(u(t)("inventory.closing.draft.createDraft.previewTable.unrecognisedNote", [c.unrecognisedItemCodes.length])), 1),
2967
+ a("ul", Po, [
2968
+ (h(!0), T(ce, null, he(c.unrecognisedItemCodes, (f) => (h(), T("li", {
2969
+ key: f,
2970
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
2971
+ }, H(f), 1))), 128))
2972
+ ])
2973
+ ])) : K("", !0),
2974
+ $(A, {
2975
+ "row-data": l.items,
2976
+ "column-defs": s,
2977
+ pagination: { pageSize: 20 }
2978
+ }, null, 8, ["row-data"])
2979
+ ]);
2980
+ };
2981
+ }
2982
+ }), No = { class: "flex flex-col gap-16" }, zo = { class: "flex flex-col gap-8" }, Eo = { class: "fm-typo-en-body-lg-600" }, Lo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Oo = { class: "fm-corner-radius-md p-16 flex items-center gap-16 border border-fm-color-border-default" }, Ho = { class: "flex flex-col flex-1 gap-4" }, Yo = { class: "fm-typo-en-body-md-600" }, Ko = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Wo = {
2983
+ key: 0,
2984
+ class: "flex flex-col gap-8"
2985
+ }, qo = { class: "fm-typo-en-body-lg-600" }, Go = {
2986
+ key: 0,
2987
+ class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 flex items-center gap-8"
2988
+ }, Qo = { class: "grid grid-cols-[repeat(3,1fr)] gap-12" }, Zo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary flex items-center gap-4" }, Jo = { class: "flex items-center gap-8 w-full" }, Xo = /* @__PURE__ */ je({
2989
+ __name: "ClosingDraftCreateSideSheet",
2990
+ props: {
2991
+ show: { type: Boolean }
2992
+ },
2993
+ emits: ["update:show", "submitted"],
2994
+ setup(n, { emit: l }) {
2995
+ const t = n, o = l, g = qt(t, "show"), { t: i } = Ye(), s = Ke(), c = W("upload"), x = W(null), A = W(!1), { mergedItems: f, unrecognisedItemCodes: B, hasBlockingErrors: N, isLoading: E, onFileUpload: I, submit: _, downloadTemplate: R } = Fo(), p = M(
2996
+ () => x.value && !E.value && f.value.length > 0
2997
+ ), v = M(() => {
2998
+ const w = f.value.filter(
2999
+ (z) => z.status === ve.ready
3000
+ ).length, Y = f.value.filter(
3001
+ (z) => z.status === ve.negative
3002
+ ).length, q = f.value.filter(
3003
+ (z) => z.status === ve.systemNegative
3004
+ ).length, re = f.value.filter((z) => z.variance !== 0).length;
3005
+ return [
3006
+ { label: i("inventory.closing.draft.createDraft.summary.totalItems"), value: f.value.length },
3007
+ { label: i("inventory.closing.draft.createDraft.summary.itemsWithCount"), value: w },
3008
+ {
3009
+ label: i("inventory.closing.draft.createDraft.summary.unrecognisedItems"),
3010
+ value: B.value.length,
3011
+ isWarning: B.value.length > 0
3012
+ },
3013
+ { label: i("inventory.closing.draft.createDraft.summary.itemsWithVariance"), value: re },
3014
+ { label: i("inventory.closing.draft.createDraft.summary.negativeCounts"), value: Y, isError: Y > 0 },
3015
+ {
3016
+ label: i("inventory.closing.draft.createDraft.summary.systemNegative"),
3017
+ value: q,
3018
+ isWarning: q > 0
3019
+ }
3020
+ ];
3021
+ });
3022
+ async function m(w) {
3023
+ x.value = w, await I(w);
3024
+ }
3025
+ async function b() {
3026
+ A.value = !0;
3027
+ try {
3028
+ await _(), y(), o("submitted"), s.open({
3029
+ title: "Success",
3030
+ message: "Closing draft created successfully",
3031
+ type: "success"
3032
+ });
3033
+ } catch (w) {
3034
+ console.error("Failed to create closing draft", { error: w }), s.open({
3035
+ title: "Something went wrong",
3036
+ message: "Failed to create closing draft. Please try again",
3037
+ type: "error"
3038
+ });
3039
+ } finally {
3040
+ A.value = !1;
3041
+ }
3042
+ }
3043
+ ze(g, (w) => {
3044
+ w || (c.value = "upload", x.value = null);
3045
+ });
3046
+ function y() {
3047
+ g.value = !1;
3048
+ }
3049
+ return (w, Y) => {
3050
+ const q = Z("FmCircularProgress"), re = Z("FmIcon"), z = Z("FmButton"), le = Z("FmCard"), P = Z("FmSideSheet");
3051
+ return h(), ae(P, {
3052
+ "dismiss-away": "",
3053
+ "max-width": 9999,
3054
+ "model-value": u(g),
3055
+ "onUpdate:modelValue": Y[2] || (Y[2] = (S) => _t(g) ? g.value = S : null),
3056
+ header: u(i)("inventory.closing.draft.createDraft.title")
3057
+ }, {
3058
+ default: ee(() => [
3059
+ a("div", No, [
3060
+ c.value === "upload" ? (h(), T(ce, { key: 0 }, [
3061
+ a("div", zo, [
3062
+ a("div", Eo, H(u(i)("inventory.closing.draft.createDraft.importCsv")), 1),
3063
+ a("div", Lo, H(u(i)("inventory.closing.draft.createDraft.uploadDescription")), 1),
3064
+ $(qn, {
3065
+ class: Se({ "h-[200px]": !x.value }),
3066
+ accept: ".csv",
3067
+ disabled: u(E),
3068
+ onFileUpload: m
3069
+ }, _n({ _: 2 }, [
3070
+ x.value ? {
3071
+ name: "default",
3072
+ fn: ee(({ openFileDialog: S }) => [
3073
+ a("div", Oo, [
3074
+ u(E) ? (h(), ae(q, {
3075
+ key: 0,
3076
+ size: "md",
3077
+ color: "neutral-gray-200"
3078
+ })) : (h(), ae(re, {
3079
+ key: 1,
3080
+ name: "check_circle",
3081
+ color: "system-success-400",
3082
+ size: "lg"
3083
+ })),
3084
+ a("div", Ho, [
3085
+ a("div", Yo, H(x.value.name), 1),
3086
+ a("div", Ko, H(u(E) ? u(i)("inventory.closing.draft.createDraft.processing") : u(i)("inventory.closing.draft.createDraft.itemsLoaded", [u(f).length])), 1)
3087
+ ]),
3088
+ u(E) ? K("", !0) : (h(), ae(z, {
3089
+ key: 2,
3090
+ label: u(i)("inventory.closing.draft.createDraft.replaceFile"),
3091
+ variant: "secondary",
3092
+ "prepend-icon": "autorenew",
3093
+ onClick: S
3094
+ }, null, 8, ["label", "onClick"]))
3095
+ ])
3096
+ ]),
3097
+ key: "0"
3098
+ } : void 0
3099
+ ]), 1032, ["class", "disabled"])
3100
+ ]),
3101
+ p.value ? (h(), T("div", Wo, [
3102
+ a("div", qo, H(u(i)("inventory.closing.draft.createDraft.importSummary")), 1),
3103
+ u(N) ? (h(), T("div", Go, [
3104
+ $(re, {
3105
+ name: "error",
3106
+ size: "sm",
3107
+ color: "system-error-300"
3108
+ }),
3109
+ a("span", null, H(u(i)("inventory.closing.draft.createDraft.reviewIssues")), 1)
3110
+ ])) : K("", !0),
3111
+ $(le, {
3112
+ variant: "outlined",
3113
+ class: "flex flex-col gap-12 px-16 py-12"
3114
+ }, {
3115
+ default: ee(() => [
3116
+ a("div", Qo, [
3117
+ (h(!0), T(ce, null, he(v.value, (S) => (h(), T("div", {
3118
+ key: S.label,
3119
+ class: "flex flex-col gap-4"
3120
+ }, [
3121
+ a("div", Zo, [
3122
+ S.isError ? (h(), ae(re, {
3123
+ key: 0,
3124
+ name: "error",
3125
+ size: "sm",
3126
+ color: "system-error-300"
3127
+ })) : K("", !0),
3128
+ S.isWarning && !S.isError ? (h(), ae(re, {
3129
+ key: 1,
3130
+ name: "warning",
3131
+ size: "sm",
3132
+ color: "system-warning-300"
3133
+ })) : K("", !0),
3134
+ a("span", null, H(S.label), 1)
3135
+ ]),
3136
+ a("div", {
3137
+ class: Se([
3138
+ "fm-typo-en-body-lg-600",
3139
+ {
3140
+ "text-fm-color-system-error-300": S.isError,
3141
+ "text-fm-color-system-warning-300": S.isWarning && !S.isError
3142
+ }
3143
+ ])
3144
+ }, H(S.value), 3)
3145
+ ]))), 128))
3146
+ ])
3147
+ ]),
3148
+ _: 1
3149
+ })
3150
+ ])) : K("", !0)
3151
+ ], 64)) : K("", !0),
3152
+ c.value === "preview" ? (h(), ae(Vo, {
3153
+ key: 1,
3154
+ items: u(f),
3155
+ "unrecognised-item-codes": u(B)
3156
+ }, null, 8, ["items", "unrecognised-item-codes"])) : K("", !0)
3157
+ ])
3158
+ ]),
3159
+ "side-sheet-footer": ee(() => [
3160
+ a("div", Jo, [
3161
+ c.value === "preview" ? (h(), ae(z, {
3162
+ key: 0,
3163
+ variant: "secondary",
3164
+ label: u(i)("inventory.common.back"),
3165
+ "prepend-icon": "arrow_back",
3166
+ onClick: Y[0] || (Y[0] = (S) => c.value = "upload")
3167
+ }, null, 8, ["label"])) : K("", !0),
3168
+ c.value === "upload" ? (h(), ae(z, {
3169
+ key: 1,
3170
+ variant: "primary",
3171
+ label: u(i)("inventory.common.next"),
3172
+ disabled: !x.value || u(E),
3173
+ onClick: Y[1] || (Y[1] = (S) => c.value = "preview")
3174
+ }, null, 8, ["label", "disabled"])) : K("", !0),
3175
+ c.value === "preview" ? (h(), ae(Gn, {
3176
+ key: 2,
3177
+ label: u(i)("inventory.closing.draft.createDraft.submit"),
3178
+ disabled: u(N) || u(f).length === 0 || A.value,
3179
+ loading: A.value,
3180
+ "confirm-title": u(i)("inventory.closing.draft.createDraft.confirmTitle"),
3181
+ "confirm-message": u(i)("inventory.closing.draft.createDraft.confirmMessage"),
3182
+ onConfirm: b
3183
+ }, null, 8, ["label", "disabled", "loading", "confirm-title", "confirm-message"])) : K("", !0),
3184
+ $(z, {
3185
+ variant: "tertiary",
3186
+ label: u(i)("inventory.common.close"),
3187
+ onClick: y
3188
+ }, null, 8, ["label"]),
3189
+ c.value === "upload" ? (h(), ae(z, {
3190
+ key: 3,
3191
+ class: "ml-auto",
3192
+ variant: "secondary",
3193
+ label: u(i)("inventory.closing.draft.createDraft.downloadTemplate"),
3194
+ "prepend-icon": "download",
3195
+ onClick: u(R)
3196
+ }, null, 8, ["label", "onClick"])) : K("", !0)
3197
+ ])
3198
+ ]),
3199
+ _: 1
3200
+ }, 8, ["model-value", "header"]);
3201
+ };
3202
+ }
3203
+ }), es = { class: "flex-1 flex flex-col gap-8" }, ts = { class: "flex flex-col" }, ns = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, as = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, os = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, ss = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Ms = /* @__PURE__ */ je({
3204
+ __name: "ClosingDraftView",
3205
+ setup(n) {
3206
+ const { t: l } = Ye(), { viewDraft: t } = it(), { viewClosingDraftProps: o, viewClosingDraftShow: g } = Bn(it()), i = We(), s = rn(), c = Dn(), { breakpoints: x } = Sn();
3207
+ i.watchLocation(s.fetchDrafts);
3208
+ const A = M(() => s.loading), f = W(""), B = W(!1), N = M(() => x.value.xs || x.value.sm), E = M(() => N.value ? 10 : 20), I = M(
3209
+ () => {
3210
+ var v;
3211
+ return ((v = i.currentLocation) == null ? void 0 : v.type) === In.enum.warehouse;
3212
+ }
3213
+ );
3214
+ function _(v) {
3215
+ switch (v) {
3216
+ case "add":
3217
+ return B.value = !0;
3218
+ case "refresh":
3219
+ return s.fetchDrafts();
3220
+ }
3221
+ }
3222
+ function R(v) {
3223
+ return v;
3224
+ }
3225
+ const p = M(() => {
3226
+ const v = {
3227
+ label: l("inventory.closing.draft.createDraft.title"),
3228
+ value: "add",
3229
+ isPrimary: !0,
3230
+ prependIcon: "add"
3231
+ }, m = {
3232
+ label: l("inventory.common.refresh"),
3233
+ value: "refresh",
3234
+ isPrimary: !1
3235
+ };
3236
+ return [...I.value ? [v] : [], m];
3237
+ });
3238
+ return (v, m) => {
3239
+ const b = Z("FmTable");
3240
+ return h(), T(ce, null, [
3241
+ $(An, {
3242
+ title: u(l)("inventory.closing.draft.title"),
3243
+ actions: p.value,
3244
+ "onClick:action": _
3245
+ }, {
3246
+ default: ee(() => [
3247
+ a("div", {
3248
+ class: Se([
3249
+ "flex flex-col gap-8 max-h-full",
3250
+ {
3251
+ "p-0": N.value,
3252
+ "px-24 ": !N.value
3253
+ }
3254
+ ])
3255
+ }, [
3256
+ $(En, {
3257
+ "change-location": "",
3258
+ searchable: "",
3259
+ search: f.value,
3260
+ "onUpdate:search": m[0] || (m[0] = (y) => f.value = y)
3261
+ }, null, 8, ["search"]),
3262
+ (h(), ae(b, {
3263
+ key: u(s).tableKey,
3264
+ style: Kt(u(c).tableHeight),
3265
+ "column-defs": u(s).columnDefs,
3266
+ "row-data": u(s).drafts,
3267
+ "search-value": f.value,
3268
+ loading: A.value,
3269
+ onRowClick: m[1] || (m[1] = (y) => u(t)(y.original)),
3270
+ "page-size": E.value
3271
+ }, {
3272
+ "list-row": ee((y) => [
3273
+ $(Qn, {
3274
+ row: y,
3275
+ onRowClick: (w) => u(t)(w)
3276
+ }, {
3277
+ default: ee((w) => {
3278
+ var Y, q, re, z, le, P, S, ie, L, F, Q, se, we, xe, De, $e, Ee, Le, Me, Ge;
3279
+ return [
3280
+ a("div", es, [
3281
+ a("div", ts, [
3282
+ a("div", ns, [
3283
+ $(u(at), {
3284
+ render: (re = (q = (Y = w._id) == null ? void 0 : Y.column) == null ? void 0 : q.columnDef) == null ? void 0 : re.cell,
3285
+ props: (le = (z = w._id) == null ? void 0 : z.getContext) == null ? void 0 : le.call(z)
3286
+ }, null, 8, ["render", "props"])
3287
+ ]),
3288
+ a("div", as, [
3289
+ $(u(at), {
3290
+ render: (ie = (S = (P = w.name) == null ? void 0 : P.column) == null ? void 0 : S.columnDef) == null ? void 0 : ie.cell,
3291
+ props: (F = (L = w.name) == null ? void 0 : L.getContext) == null ? void 0 : F.call(L)
3292
+ }, null, 8, ["render", "props"])
3293
+ ]),
3294
+ a("div", os, H([
3295
+ ...y.original.items.slice(0, 3).map((ut) => ut.sku.name),
3296
+ ...y.original.items.length >= 3 ? [`and ${y.original.items.length - 3} more items`] : []
3297
+ ].join(", ")), 1),
3298
+ a("div", ss, [
3299
+ $(u(at), {
3300
+ render: (we = (se = (Q = w.ref) == null ? void 0 : Q.column) == null ? void 0 : se.columnDef) == null ? void 0 : we.cell,
3301
+ props: (De = (xe = w.ref) == null ? void 0 : xe.getContext) == null ? void 0 : De.call(xe)
3302
+ }, null, 8, ["render", "props"])
3303
+ ])
3304
+ ]),
3305
+ a("div", null, [
3306
+ $(u(at), {
3307
+ render: (Le = (Ee = ($e = w.status) == null ? void 0 : $e.column) == null ? void 0 : Ee.columnDef) == null ? void 0 : Le.cell,
3308
+ props: (Ge = (Me = w.status) == null ? void 0 : Me.getContext) == null ? void 0 : Ge.call(Me)
3309
+ }, null, 8, ["render", "props"])
3310
+ ])
3311
+ ])
3312
+ ];
3313
+ }),
3314
+ _: 2
3315
+ }, 1032, ["row", "onRowClick"])
3316
+ ]),
3317
+ _: 1
3318
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
3319
+ ], 2)
3320
+ ]),
3321
+ _: 1
3322
+ }, 8, ["title", "actions"]),
3323
+ $(Xo, {
3324
+ show: B.value,
3325
+ "onUpdate:show": m[2] || (m[2] = (y) => B.value = y),
3326
+ onSubmitted: u(s).fetchDrafts
3327
+ }, null, 8, ["show", "onSubmitted"]),
3328
+ (h(), ae(wn, { to: "body" }, [
3329
+ $(Do, xn(u(o), {
3330
+ show: u(g),
3331
+ "onUpdate:show": m[3] || (m[3] = (y) => _t(g) ? g.value = y : null),
3332
+ onSubmitted: m[4] || (m[4] = () => (g.value = !1, u(s).fetchDrafts())),
3333
+ onRefresh: m[5] || (m[5] = (y) => u(s).updateDraftRef(y))
3334
+ }), null, 16, ["show"])
3335
+ ]))
3336
+ ], 64);
3337
+ };
3338
+ }
3339
+ });
3340
+ export {
3341
+ Ms as default
3342
+ };