@feedmepos/mf-inventory-portal 1.5.7 → 1.5.9-dev.1

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