@feedmepos/mf-inventory-portal 1.3.12-dev.2 → 1.3.13

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