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

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