@feedmepos/mf-inventory-portal 1.2.1 → 1.2.2-5.dev-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/App-DMkUg806.js +297 -0
  2. package/dist/{ApprovalView-DwRrbVDo.js → ApprovalView-DWJh2K6W.js} +65 -64
  3. package/dist/{BindingsDialog-DUVKv10-.js → BindingsDialog-EmHCvqJI.js} +2 -2
  4. package/dist/{BindingsPicker-Daib_iq4.js → BindingsPicker-h_9jm1s0.js} +3 -3
  5. package/dist/{BindingsTable-Bv9UmcJP.js → BindingsTable-BAVWGUoa.js} +1 -1
  6. package/dist/ClosingDraftView-Du4kOwIg.js +1899 -0
  7. package/dist/ClosingHistoryView-DuW2Vtrs.js +355 -0
  8. package/dist/ClosingTemplateView-CfPY8R5M.js +2001 -0
  9. package/dist/{DeliveryOrderPrintPreview-DZPcRAja.js → DeliveryOrderPrintPreview-C6Cj8mOp.js} +9 -9
  10. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-WWIrybw_.js +230 -0
  11. package/dist/{FmMultiselectDialog-CZmwOkrb.js → FmMultiselectDialog-BzWrQOS4.js} +1 -1
  12. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-C-2V2bGc.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DwqVRUFz.js} +36 -36
  13. package/dist/ImportView-lKlYeLay.js +1291 -0
  14. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-BGnoF1Zz.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-_2WZMZU2.js} +5 -5
  15. package/dist/{IngredientGroupView-CAVYpEj3.js → IngredientGroupView-CrmwR2Xt.js} +34 -35
  16. package/dist/IngredientsView-1bAsyz-b.js +2254 -0
  17. package/dist/{IntegrationView-DdLFyZ4H.js → IntegrationView-D16qeEc_.js} +1773 -1635
  18. package/dist/{InventoryBindingForm-C7BdEDtM.js → InventoryBindingForm-BRwOXV_P.js} +1 -1
  19. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-B7DND2dQ.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-NDbtbtqK.js} +28 -28
  20. package/dist/{InventoryBindingSummary-IZ7F-Lti.js → InventoryBindingSummary-DKM2gX8_.js} +1 -1
  21. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-sgqVSlUB.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CdaiYTdf.js} +4 -4
  22. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-DeF32bHu.js → PremiumBadge.vue_vue_type_script_setup_true_lang-B0OKeK5O.js} +7 -7
  23. package/dist/{PublishView-DkgfYneI.js → PublishView-D0NnU22l.js} +73 -63
  24. package/dist/{PurchaseOrderPrintPreview-CltLC4o4.js → PurchaseOrderPrintPreview-BmuwNbeL.js} +4 -4
  25. package/dist/{ReceiveRequestView-Dj7ji0DY.js → ReceiveRequestView-j79m7TKk.js} +343 -333
  26. package/dist/RecipeView-D_fNQQ-C.js +636 -0
  27. package/dist/StockView-DX_xeFBT.js +2385 -0
  28. package/dist/SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Bg49isUy.js +172 -0
  29. package/dist/{SupplierView-DE_M_9kd.js → SupplierView-DuFTqbOg.js} +1193 -1073
  30. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-c428GXwc.js +3233 -0
  31. package/dist/{TransferTemplateView-gWGBCF3u.js → TransferTemplateView-Ccsfcetz.js} +104 -103
  32. package/dist/UnitView-BklpNsFN.js +674 -0
  33. package/dist/WarehouseView-BrURbU67.js +1066 -0
  34. package/dist/api/adjustment-template.d.ts +1 -0
  35. package/dist/api/bill.d.ts +140 -2
  36. package/dist/api/closing-template.d.ts +1 -0
  37. package/dist/api/closing.d.ts +1 -0
  38. package/dist/api/inventory.d.ts +405 -0
  39. package/dist/api/netsuite.d.ts +5 -1
  40. package/dist/api/purchase-order-template.d.ts +1 -0
  41. package/dist/api/purchase-order.d.ts +3 -0
  42. package/dist/api/shipment.d.ts +11 -0
  43. package/dist/api/stock.d.ts +2 -44
  44. package/dist/api/warehouse.d.ts +3 -1
  45. package/dist/{app-CruHLH1e.js → app-a9r50k3U.js} +68551 -67573
  46. package/dist/app.d.ts +643 -15
  47. package/dist/app.js +6 -6
  48. package/dist/components/FmAdminBadge.vue.d.ts +1 -4
  49. package/dist/components/FmEnhancedSelect.vue.d.ts +30 -0
  50. package/dist/components/FmInventoryTableToolbar.vue.d.ts +16 -2
  51. package/dist/components/FmLockableField.vue.d.ts +3 -0
  52. package/dist/components/netsuite/ItemSubsidiaryTreeDialog.vue.d.ts +16 -0
  53. package/dist/components/netsuite/SubsidiaryTreeDialog.vue.d.ts +2 -0
  54. package/dist/composable/defineApi.d.ts +1 -1
  55. package/dist/composable/useIframe.d.ts +2 -2
  56. package/dist/{decimal-izbvCC1j.js → decimal-AusUnA1W.js} +1 -1
  57. package/dist/{format-unit-display-4SAdfyZB.js → format-unit-display-BqkHL-ph.js} +397 -429
  58. package/dist/helper/array.d.ts +1 -0
  59. package/dist/helper/core/country/utils.d.ts +3 -4
  60. package/dist/helper/country.d.ts +6 -255
  61. package/dist/helper/number.d.ts +1 -0
  62. package/dist/import-export.helper-PIyNeHfa.js +238 -0
  63. package/dist/{index-B6GGthLw.js → index-CjxirPvn.js} +283 -268
  64. package/dist/{index-CnQloOEo.js → index-Dj9-pdT9.js} +1 -1
  65. package/dist/layout/SingleColumnLayout.vue.d.ts +6 -3
  66. package/dist/purchase-order-template-CQikvY1p.js +41 -0
  67. package/dist/router/name.d.ts +2 -0
  68. package/dist/stock-CDZ2uWSF.js +83 -0
  69. package/dist/stock-Dw908dIC.js +74 -0
  70. package/dist/stores/feature.d.ts +12 -0
  71. package/dist/stores/integration/netsuite.d.ts +42 -0
  72. package/dist/stores/inventory.d.ts +28 -199
  73. package/dist/stores/location.d.ts +331 -1
  74. package/dist/stores/supplier.d.ts +96 -0
  75. package/dist/stores/warehouse.d.ts +4 -0
  76. package/dist/style.css +1 -1
  77. package/dist/{supplier-CTVE1lHO.js → supplier-BPPBUudN.js} +1 -1
  78. package/dist/tsconfig.app.tsbuildinfo +1 -1
  79. package/dist/{use-ingredient-select-dialog-CM80TfX0.js → use-ingredient-select-dialog-C_fSKN3_.js} +5 -5
  80. package/dist/{use-inventory-binding-dialog-D_omdhgn.js → use-inventory-binding-dialog-ClAkJ864.js} +8 -8
  81. package/dist/views/adjustment-template/wastage-template/actions.d.ts +60 -0
  82. package/dist/views/adjustment-template/wastage-template/table.d.ts +60 -0
  83. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +56 -0
  84. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +3 -3
  85. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +468 -0
  86. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +9 -2
  87. package/dist/views/closing-history/ClosingHistoryView.vue.d.ts +2 -0
  88. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +4 -1
  89. package/dist/views/closing-template/helpers/import-export.helper.d.ts +5 -0
  90. package/dist/views/import/ImportView.vue.d.ts +3 -0
  91. package/dist/views/import/components/ImportDialog.vue.d.ts +2 -0
  92. package/dist/views/import/helper/import-export.helper.d.ts +4 -0
  93. package/dist/views/ingredients/components/ingredient-dialog/IngredientDialogProps.d.ts +1 -1
  94. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +181 -12
  95. package/dist/views/ingredients/components/ingredient-form/IngredientFormProps.d.ts +6 -0
  96. package/dist/views/ingredients/helper/import-export.helper.d.ts +4 -1
  97. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +2 -0
  98. package/dist/views/receive-request/components/delivery-order-form/CreateForm.vue.d.ts +16 -0
  99. package/dist/views/receive-request/components/delivery-order-form/CreateFormProps.d.ts +4 -0
  100. package/dist/views/receive-request/components/delivery-order-form/EditForm.vue.d.ts +16 -0
  101. package/dist/views/receive-request/components/delivery-order-form/EditFormProps.d.ts +4 -0
  102. package/dist/views/receive-request/components/delivery-order-form/SystemTrailDialog.vue.d.ts +21 -0
  103. package/dist/views/receive-request/components/netsuite/NetSuiteTransactionChangeLog.vue.d.ts +15 -0
  104. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +1 -0
  105. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +420 -2
  106. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +99 -0
  107. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +644 -13
  108. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +711 -14
  109. package/dist/views/recipe/RecipeView.vue.d.ts +1 -0
  110. package/dist/views/recipe/components/import-recipes/ImportRecipeItem.vue.d.ts +16 -0
  111. package/dist/views/recipe/components/import-recipes/ImportRecipes.vue.d.ts +2 -0
  112. package/dist/views/recipe/helper/import-recipe.d.ts +48 -0
  113. package/dist/views/stock/components/StockRecordCard.vue.d.ts +70 -1
  114. package/dist/views/stock/components/dialog/RecalculationDialog.vue.d.ts +11 -0
  115. package/dist/views/stock/components/dialog/RecalculationDialogProps.d.ts +3 -0
  116. package/dist/views/stock/components/dialog/StockAdjustmentSideSheet.vue.d.ts +20 -0
  117. package/dist/views/supplier/components/SupplierForm.vue.d.ts +8 -0
  118. package/dist/views/supplier/components/SupplierSupplyItemField.vue.d.ts +3 -0
  119. package/dist/views/supplier/composables/use-supplier-table.d.ts +4 -0
  120. package/dist/views/transfer-template/components/transfer-template-dialog/TransferTemplateDialog.vue.d.ts +8 -0
  121. package/dist/views/transfer-template/components/transfer-template-form/components/NetSuiteCustomCodeSelection.vue.d.ts +2 -0
  122. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-locations.d.ts +16 -0
  123. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +48 -0
  124. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +48 -0
  125. package/dist/views/unit/UnitView.vue.d.ts +1 -0
  126. package/dist/views/unit/components/import-units/ImportUnitItem.vue.d.ts +12 -0
  127. package/dist/views/unit/components/import-units/ImportUnitItemProps.d.ts +6 -0
  128. package/dist/views/unit/components/import-units/ImportUnits.vue.d.ts +9 -0
  129. package/dist/views/unit/components/import-units/ImportUnitsProps.d.ts +5 -0
  130. package/dist/views/unit/helper/import-export.helper.d.ts +40 -0
  131. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +8 -0
  132. package/package.json +3 -3
  133. package/dist/App-BqaRC0Sb.js +0 -276
  134. package/dist/ClosingDraftView-sJ_zRPeo.js +0 -1687
  135. package/dist/ClosingTemplateView-cNgXHq1r.js +0 -1908
  136. package/dist/FmAdminBadge-oCnz8SW6.js +0 -34
  137. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BKR8C4p_.js +0 -224
  138. package/dist/IngredientsView-CHHeAJH_.js +0 -1858
  139. package/dist/RecipeView-BukmKdVG.js +0 -621
  140. package/dist/StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js +0 -59
  141. package/dist/StockView-wxRCw_w-.js +0 -2087
  142. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-eqUOnJoM.js +0 -2336
  143. package/dist/UnitView-BgwDmGZo.js +0 -667
  144. package/dist/WarehouseView-BdccenhO.js +0 -1034
  145. package/dist/array-Ca8T3f_G.js +0 -44
  146. package/dist/helper/core/country/codes.d.ts +0 -255
  147. package/dist/stock-BJP5BB5b.js +0 -146
@@ -0,0 +1,1899 @@
1
+ import { defineComponent as He, ref as H, computed as V, onMounted as Ye, resolveComponent as U, openBlock as j, createElementBlock as L, Fragment as ee, createTextVNode as X, createBlock as se, withCtx as G, createElementVNode as r, toDisplayString as J, unref as F, createVNode as x, createCommentVNode as de, h as T, reactive as _t, watch as Dt, isRef as rt, normalizeClass as De, renderList as je, normalizeStyle as lt, Teleport as wt, mergeProps as St } from "vue";
2
+ import { aa as Ct, u as ze, ax as z, am as ct, ay as it, r as jt, Z as Qe, n as N, t as Bt, a0 as Be, W as Ft, Y as Tt, X as $t, az as ut, aA as dt, ah as mt, aB as pe, an as Mt, ac as Ke, ab as ve, a6 as Ue, D as st, j as Re, i as Rt, f as It, a as Pt, $ as Ie, a9 as Vt, G as Ut, I as Lt, J as Et, K as Ht, L as Pe } from "./app-a9r50k3U.js";
3
+ import { useCoreStore as zt, useI18n as ft } from "@feedmepos/mf-common";
4
+ import { useSnackbar as Ge, useDialog as Nt, useProxiedModel as Ot, components as Ve, useBreakpoints as Kt } from "@feedmepos/ui-library";
5
+ import { defineStore as pt, storeToRefs as Yt } from "pinia";
6
+ import { u as vt } from "./stock-Dw908dIC.js";
7
+ import { u as We } from "./stock-CDZ2uWSF.js";
8
+ import { E as Qt } from "./empty-placeholder-wf6-BWE8.js";
9
+ const Ne = Ct((o, l) => {
10
+ function e() {
11
+ return ze().currentLocation.dbName;
12
+ }
13
+ return {
14
+ async getDraft(m) {
15
+ const p = e(), w = `${o.inventoryBackendUrl}/${p}/closing-draft/${m}`;
16
+ return l.get(w);
17
+ },
18
+ async readDrafts() {
19
+ const m = e(), p = `${o.inventoryBackendUrl}/${m}/closing-draft`;
20
+ return l.get(p);
21
+ },
22
+ async runOperation(m) {
23
+ const p = e(), w = `${o.inventoryBackendUrl}/${p}/closing-draft/run-operation`;
24
+ return l.post(w, m);
25
+ },
26
+ async sync(m) {
27
+ const p = e(), w = `${o.inventoryBackendUrl}/${p}/closing-draft/sync`;
28
+ return l.post(w, m);
29
+ }
30
+ };
31
+ }), Gt = { class: "fm-typo-en-body-lg-400" }, Wt = { class: "fm-typo-en-body-lg-600" }, qt = {
32
+ key: 0,
33
+ class: "flex flex-col"
34
+ }, Zt = { class: "flex gap-12 py-8 justify-end w-full" }, Oe = /* @__PURE__ */ He({
35
+ __name: "ClosingDraftAction",
36
+ props: {
37
+ draft: {},
38
+ action: {},
39
+ onCancel: { type: Function },
40
+ onFinished: { type: Function }
41
+ },
42
+ setup(o) {
43
+ const l = o, e = H(), m = Ne(), p = Ge(), w = H(!1), v = H(null), R = H(!1), S = V(() => {
44
+ switch (l.action) {
45
+ case z.enum.approveDraft:
46
+ return "Approve";
47
+ case z.enum.rejectDraft:
48
+ return "Reject";
49
+ case z.enum.markAsFailed:
50
+ return "Mark as Failed";
51
+ }
52
+ throw new Error(`Unknown action: ${l.action}`);
53
+ }), k = V(() => {
54
+ switch (l.action) {
55
+ case z.enum.approveDraft:
56
+ return "primary";
57
+ case z.enum.rejectDraft:
58
+ return "destructive";
59
+ case z.enum.markAsFailed:
60
+ return "destructive";
61
+ }
62
+ throw new Error(`Unknown action: ${l.action}`);
63
+ });
64
+ Ye(() => {
65
+ if (l.draft.effectiveAt)
66
+ v.value = new Date(l.draft.effectiveAt);
67
+ else {
68
+ const s = new Date(l.draft.createdAt);
69
+ s.setHours(23, 59, 59, 999), v.value = s;
70
+ }
71
+ R.value = !0;
72
+ });
73
+ const $ = V({
74
+ get() {
75
+ return v.value === null ? "" : ct(v.value);
76
+ },
77
+ set(s) {
78
+ if (s) {
79
+ const a = /* @__PURE__ */ new Date(`${s} ${P.value}`);
80
+ a.setSeconds(59, 999), v.value = a;
81
+ } else
82
+ v.value = null;
83
+ }
84
+ }), P = V({
85
+ get() {
86
+ return v.value === null ? "" : it(v.value);
87
+ },
88
+ set(s) {
89
+ if (s) {
90
+ const a = /* @__PURE__ */ new Date(`${$.value} ${s}`);
91
+ a.setSeconds(59, 999), v.value = a;
92
+ } else
93
+ v.value = null;
94
+ }
95
+ });
96
+ async function I() {
97
+ w.value = !0;
98
+ try {
99
+ await m.runOperation({
100
+ _id: l.draft._id,
101
+ _rev: l.draft._rev ?? "",
102
+ action: l.action,
103
+ data: {
104
+ effectiveAt: v.value ? v.value.toISOString() : null,
105
+ remark: e.value
106
+ }
107
+ }).delayed(500), p.open({
108
+ title: "Success",
109
+ message: "Action submitted",
110
+ type: "success"
111
+ }), l.onFinished();
112
+ } catch (s) {
113
+ p.open({
114
+ title: "Something went wrong",
115
+ message: "Unable to submit action. Please try again",
116
+ type: "error"
117
+ }), console.error("error on submit closing draft action", s);
118
+ } finally {
119
+ w.value = !1;
120
+ }
121
+ }
122
+ return (s, a) => {
123
+ const _ = U("FmLabel"), O = U("FmDatePicker"), f = U("FmTimePicker"), y = U("FmTextField"), h = U("FmButton"), D = U("FmForm");
124
+ return R.value ? (j(), se(D, {
125
+ key: 1,
126
+ onValidationSuccess: I,
127
+ class: "flex flex-col gap-32",
128
+ disabled: w.value
129
+ }, {
130
+ default: G(() => [
131
+ r("div", Gt, [
132
+ a[4] || (a[4] = X(" You are about to ")),
133
+ r("span", Wt, J(S.value), 1),
134
+ a[5] || (a[5] = X(" this draft. Please provide a remark to justify this action. "))
135
+ ]),
136
+ s.action === F(z).enum.approveDraft ? (j(), L("div", qt, [
137
+ x(_, { class: "fm-typo-en-body-lg-600" }, {
138
+ default: G(() => a[6] || (a[6] = [
139
+ X("Closing Date")
140
+ ])),
141
+ _: 1
142
+ }),
143
+ x(O, {
144
+ modelValue: $.value,
145
+ "onUpdate:modelValue": a[0] || (a[0] = (M) => $.value = M)
146
+ }, null, 8, ["modelValue"]),
147
+ x(_, { class: "fm-typo-en-body-lg-600" }, {
148
+ default: G(() => a[7] || (a[7] = [
149
+ X("Closing Time")
150
+ ])),
151
+ _: 1
152
+ }),
153
+ x(f, {
154
+ modelValue: P.value,
155
+ "onUpdate:modelValue": a[1] || (a[1] = (M) => P.value = M)
156
+ }, null, 8, ["modelValue"])
157
+ ])) : de("", !0),
158
+ x(y, {
159
+ modelValue: e.value,
160
+ "onUpdate:modelValue": a[2] || (a[2] = (M) => e.value = M),
161
+ label: "Remark",
162
+ "label-mark": "required",
163
+ rules: [F(jt)()]
164
+ }, null, 8, ["modelValue", "rules"]),
165
+ r("div", Zt, [
166
+ x(h, {
167
+ label: "Cancel",
168
+ variant: "tertiary",
169
+ onClick: a[3] || (a[3] = (M) => s.onCancel())
170
+ }),
171
+ x(h, {
172
+ label: S.value,
173
+ type: "submit",
174
+ variant: k.value,
175
+ loading: w.value
176
+ }, null, 8, ["label", "variant", "loading"])
177
+ ])
178
+ ]),
179
+ _: 1
180
+ }, 8, ["disabled"])) : (j(), L(ee, { key: 0 }, [
181
+ X("Loading")
182
+ ], 64));
183
+ };
184
+ }
185
+ }), Jt = Be(0);
186
+ function yt(o) {
187
+ const l = o.measurementsAmounts.groupBy((m) => m.measurement.id), e = o.sku.unit.measurements.reduce((m, p) => {
188
+ var R, S;
189
+ const w = ((S = (R = l.get(p.id)) == null ? void 0 : R[0]) == null ? void 0 : S.amount) ?? Jt, v = Qe(p.conversion, w);
190
+ return m + +N(v);
191
+ }, +N(o.baseAmount));
192
+ return Bt(e, o.baseAmount.precision);
193
+ }
194
+ const Xt = Be(0), ea = Be(100), gt = "N/A";
195
+ function ta(o, l, e, m, p, w) {
196
+ var D;
197
+ const v = yt(o), R = m ?? v, S = ut(R, l), k = l.amount === 0 ? null : dt(S, {
198
+ ...l,
199
+ amount: Math.abs(l.amount)
200
+ }), $ = k ? Qe(k, ea) : null, P = (D = o.sku.defaultCost) != null && D.costPerUnit ? o.sku.defaultCost.costPerUnit.amount / Math.pow(10, o.sku.defaultCost.costPerUnit.precision) : 0, I = p ? +N(p) : 0, s = +N(l), a = +N(R), _ = s - a, O = _ * P, f = a * P, y = s * P;
201
+ return {
202
+ code: o.sku.code,
203
+ name: o.sku.name,
204
+ baseUnit: o.sku.unit.abbrev,
205
+ baseUnitAmount: +N(o.baseAmount),
206
+ ...o.measurementsAmounts.filter(
207
+ (M) => aa(M.measurement) && e.includes(M.measurement.id)
208
+ ).reduce(
209
+ (M, Z, W) => (M[`measurementAbbrev${W}`] = `(${Z.measurement.abbrev}) × ${N(Z.measurement.conversion)}`, M[`measurementAmount${W}`] = +N(Z.amount), M),
210
+ {}
211
+ ),
212
+ systemBalance: s,
213
+ physicalBalance: a,
214
+ adjustedAmount: +N(S),
215
+ adjustedDiffPercentage: $ ? +N(mt($, 2)) : null,
216
+ costPerUnit: P,
217
+ opening: I,
218
+ adjustmentTypes: w ?? gt,
219
+ varianceQty: _,
220
+ varianceRM: O,
221
+ stockTakeValue: f,
222
+ systemValue: y
223
+ };
224
+ }
225
+ function aa(o) {
226
+ return !o.abbrev.toLocaleLowerCase().includes("inactive");
227
+ }
228
+ function na(o) {
229
+ const l = bt(o);
230
+ return o.reduce(
231
+ (e, m) => {
232
+ var p;
233
+ return Math.max(e, ((p = l == null ? void 0 : l.get(m.sku._id)) == null ? void 0 : p[0].length) ?? 0);
234
+ },
235
+ 0
236
+ );
237
+ }
238
+ function bt(o) {
239
+ return o.groupBy(
240
+ (l) => l.sku._id,
241
+ (l) => l.measurementsAmounts.filter((e) => !e.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((e) => e.measurement.id)
242
+ );
243
+ }
244
+ function oa(o) {
245
+ return [
246
+ {
247
+ id: "code",
248
+ name: "Code"
249
+ },
250
+ {
251
+ id: "name",
252
+ name: "Name"
253
+ },
254
+ {
255
+ id: "baseUnit",
256
+ name: "Base unit"
257
+ },
258
+ {
259
+ id: "costPerUnit",
260
+ name: "Cost per unit"
261
+ },
262
+ {
263
+ id: "opening",
264
+ name: "Opening (B/F)"
265
+ },
266
+ {
267
+ id: "adjustmentTypes",
268
+ name: "Type"
269
+ },
270
+ {
271
+ id: "varianceQty",
272
+ name: "Variance (Qty)"
273
+ },
274
+ {
275
+ id: "varianceRM",
276
+ name: "Variance (RM)"
277
+ },
278
+ {
279
+ id: "physicalBalance",
280
+ name: "Stock take (Qty)"
281
+ },
282
+ {
283
+ id: "systemBalance",
284
+ name: "System balance (Qty)"
285
+ },
286
+ {
287
+ id: "stockTakeValue",
288
+ name: "Stock take value (RM)"
289
+ },
290
+ {
291
+ id: "systemValue",
292
+ name: "System value (RM)"
293
+ },
294
+ {
295
+ id: "adjustedAmount",
296
+ name: "Adjusted balance"
297
+ },
298
+ {
299
+ id: "adjustedDiffPercentage",
300
+ name: "Diff (%)"
301
+ },
302
+ {
303
+ id: "baseUnitAmount",
304
+ name: "Base unit amount"
305
+ },
306
+ ...Array.from({ length: o }).flatMap((e, m) => [
307
+ {
308
+ id: `measurementAmount${m}`,
309
+ name: `UOM amount ${m + 1}`
310
+ },
311
+ {
312
+ id: `measurementAbbrev${m}`,
313
+ name: `UOM ${m + 1}`
314
+ }
315
+ ])
316
+ ];
317
+ }
318
+ function sa(o, l, e) {
319
+ var y, h, D, M, Z, W, re;
320
+ const m = l.groupBy(
321
+ (B) => B.id,
322
+ (B) => B.balance
323
+ ), p = e.groupBy(
324
+ (B) => B.id,
325
+ (B) => B.balance
326
+ ), w = /* @__PURE__ */ new Map();
327
+ if (o.opening)
328
+ for (const B of o.opening)
329
+ w.set(B.skuId, B.balance);
330
+ const v = /* @__PURE__ */ new Map();
331
+ if (o.adjustmentSnapshot)
332
+ for (const B of o.adjustmentSnapshot) {
333
+ const te = Object.keys(B.adjustmentsByType).join(", ");
334
+ v.set(B.skuId, te || gt);
335
+ }
336
+ const R = [...o.items, ...o.negativeStockItems ?? []], S = bt(R), k = R.map((B) => {
337
+ var ye, ge, Y;
338
+ const te = ((ye = m.get(B.sku._id)) == null ? void 0 : ye[0]) ?? Xt, be = ((ge = S == null ? void 0 : S.get(B.sku._id)) == null ? void 0 : ge[0]) ?? [], ke = w.get(B.sku._id), fe = v.get(B.sku._id);
339
+ return ta(
340
+ B,
341
+ te,
342
+ be,
343
+ (Y = p.get(B.sku._id)) == null ? void 0 : Y[0],
344
+ ke,
345
+ fe
346
+ );
347
+ }), $ = na(R), I = zt().currentBusiness.value, s = oa($), a = [
348
+ ["Business name:", I == null ? void 0 : I.name],
349
+ ["Business ID:", I == null ? void 0 : I._id],
350
+ ["Menu version", I == null ? void 0 : I.menuVersion],
351
+ ["Created at", new Date(o.createdAt)],
352
+ ["Created by", (y = o.createdBy) == null ? void 0 : y.name],
353
+ ["Updated at", new Date(o.updatedAt)],
354
+ ["Updated by", (h = o.updatedBy) == null ? void 0 : h.name],
355
+ ["Recent action", o.approvedAt ? "Approve" : o.rejectionHistory ? "Reject" : ""],
356
+ [
357
+ "Action by",
358
+ o.approvedAt ? (D = o.approvedBy) == null ? void 0 : D.name : o.rejectionHistory ? (Z = (M = o.rejectionHistory[0]) == null ? void 0 : M.rejectedBy) == null ? void 0 : Z.name : ""
359
+ ],
360
+ [
361
+ "Action at",
362
+ o.approvedAt ? new Date(o.approvedAt) : o.rejectionHistory ? new Date((W = o.rejectionHistory[0]) == null ? void 0 : W.rejectedAt) : ""
363
+ ],
364
+ [
365
+ "Action remark",
366
+ o.approvedAt ? o.approveRemark : o.rejectionHistory ? new Date((re = o.rejectionHistory[0]) == null ? void 0 : re.rejectRemark) : ""
367
+ ],
368
+ [],
369
+ s.map((B) => B.name),
370
+ ...k.map((B) => s.map((te) => B[te.id]))
371
+ ], _ = s.map((B) => `system:${B.id}`), O = Ft(a, _), f = `[${I == null ? void 0 : I.name}] closing draft (${Tt(new Date(o.updatedAt))}).xlsx`;
372
+ return $t(O, f), f;
373
+ }
374
+ const ra = { class: "flex flex-col" }, la = { class: "flex gap-12 py-8 justify-end w-full" }, ca = /* @__PURE__ */ He({
375
+ __name: "RefreshBalanceAction",
376
+ props: {
377
+ draft: {},
378
+ onCancel: { type: Function },
379
+ onFinished: { type: Function }
380
+ },
381
+ setup(o) {
382
+ const l = o;
383
+ We();
384
+ const e = H(!1), m = H(null), p = H(!1);
385
+ Ye(() => {
386
+ if (l.draft.effectiveAt)
387
+ m.value = new Date(l.draft.effectiveAt);
388
+ else {
389
+ const S = new Date(l.draft.createdAt);
390
+ S.setHours(23, 59, 59, 999), m.value = S;
391
+ }
392
+ p.value = !0;
393
+ });
394
+ const w = V({
395
+ get() {
396
+ return m.value === null ? "" : ct(m.value);
397
+ },
398
+ set(S) {
399
+ if (S) {
400
+ const k = /* @__PURE__ */ new Date(`${S} ${v.value}`);
401
+ k.setSeconds(59, 999), m.value = k;
402
+ } else
403
+ m.value = null;
404
+ }
405
+ }), v = V({
406
+ get() {
407
+ return m.value === null ? "" : it(m.value);
408
+ },
409
+ set(S) {
410
+ if (S) {
411
+ const k = /* @__PURE__ */ new Date(`${w.value} ${S}`);
412
+ k.setSeconds(59, 999), m.value = k;
413
+ } else
414
+ m.value = null;
415
+ }
416
+ });
417
+ async function R() {
418
+ e.value = !0, l.onFinished(m.value.toISOString());
419
+ }
420
+ return (S, k) => {
421
+ const $ = U("FmLabel"), P = U("FmDatePicker"), I = U("FmTimePicker"), s = U("FmButton"), a = U("FmForm");
422
+ return p.value ? (j(), se(a, {
423
+ key: 1,
424
+ onValidationSuccess: R,
425
+ class: "flex flex-col gap-32",
426
+ disabled: e.value
427
+ }, {
428
+ default: G(() => [
429
+ k[5] || (k[5] = r("div", { class: "fm-typo-en-body-lg-400" }, [
430
+ r("p", null, [
431
+ X(" Performing "),
432
+ r("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
433
+ X(" until closing effective date and time. ")
434
+ ]),
435
+ r("p", { class: "mt-2" }, [
436
+ X(" Please note that this action will "),
437
+ r("b", null, "update"),
438
+ X(" the effective date and time. ")
439
+ ])
440
+ ], -1)),
441
+ r("div", ra, [
442
+ x($, { class: "fm-typo-en-body-lg-600" }, {
443
+ default: G(() => k[3] || (k[3] = [
444
+ X("Closing Date")
445
+ ])),
446
+ _: 1
447
+ }),
448
+ x(P, {
449
+ modelValue: w.value,
450
+ "onUpdate:modelValue": k[0] || (k[0] = (_) => w.value = _)
451
+ }, null, 8, ["modelValue"]),
452
+ x($, { class: "fm-typo-en-body-lg-600" }, {
453
+ default: G(() => k[4] || (k[4] = [
454
+ X("Closing Time")
455
+ ])),
456
+ _: 1
457
+ }),
458
+ x(I, {
459
+ modelValue: v.value,
460
+ "onUpdate:modelValue": k[1] || (k[1] = (_) => v.value = _)
461
+ }, null, 8, ["modelValue"])
462
+ ]),
463
+ r("div", la, [
464
+ x(s, {
465
+ label: "Cancel",
466
+ variant: "tertiary",
467
+ onClick: k[2] || (k[2] = (_) => S.onCancel())
468
+ }),
469
+ x(s, {
470
+ label: "Refresh balance",
471
+ type: "submit",
472
+ variant: "primary",
473
+ loading: e.value
474
+ }, null, 8, ["loading"])
475
+ ])
476
+ ]),
477
+ _: 1
478
+ }, 8, ["disabled"])) : (j(), L(ee, { key: 0 }, [
479
+ X("Loading")
480
+ ], 64));
481
+ };
482
+ }
483
+ }), Ee = pt(
484
+ "closingDraftActions",
485
+ function() {
486
+ const l = Nt(), e = Ge(), m = We(), p = Ne(), w = vt(), v = H(!1), R = H();
487
+ function S(f) {
488
+ const y = {
489
+ draft: f
490
+ };
491
+ R.value = y, v.value = !0;
492
+ }
493
+ async function k(f) {
494
+ var h;
495
+ if (f.status === pe.enum.COMPLETED) {
496
+ const D = f.closingAdjustmentId;
497
+ if (!D)
498
+ return e.open({
499
+ title: "Something went wrong",
500
+ message: "Closing draft is completed but closing document cannot be found.",
501
+ type: "error"
502
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
503
+ draftId: f._id
504
+ }), [];
505
+ const M = await m.readAdjustmentById(D);
506
+ return ((M == null ? void 0 : M.skus) ?? []).map((W) => ({
507
+ id: W.sku._id,
508
+ balance: W.fromBalance,
509
+ costs: W.fromCostBalances
510
+ }));
511
+ } else
512
+ return await w.readStockBalance(), ((h = w.stockBalance) == null ? void 0 : h.skus) ?? [];
513
+ }
514
+ async function $(f, y, h) {
515
+ y || (e.open({
516
+ title: "Exporting",
517
+ message: "Fetching data..."
518
+ }), y = await k(f)), sa(f, y, h ?? []);
519
+ }
520
+ function P(f, y) {
521
+ l.open({
522
+ title: "Approve draft",
523
+ contentComponent: Oe,
524
+ contentComponentProps: {
525
+ draft: f,
526
+ action: z.enum.approveDraft,
527
+ onFinished: () => {
528
+ l.close(), y == null || y();
529
+ },
530
+ onCancel: () => l.close()
531
+ }
532
+ });
533
+ }
534
+ function I(f, y) {
535
+ l.open({
536
+ title: "Reject draft",
537
+ contentComponent: Oe,
538
+ contentComponentProps: {
539
+ draft: f,
540
+ action: z.enum.rejectDraft,
541
+ onFinished: () => {
542
+ l.close(), y == null || y();
543
+ },
544
+ onCancel: () => l.close()
545
+ }
546
+ });
547
+ }
548
+ function s(f, y) {
549
+ l.open({
550
+ title: "Mark draft as failed",
551
+ contentComponent: Oe,
552
+ contentComponentProps: {
553
+ draft: f,
554
+ action: z.enum.markAsFailed,
555
+ onFinished: () => {
556
+ l.close(), y == null || y();
557
+ },
558
+ onCancel: () => l.close()
559
+ }
560
+ });
561
+ }
562
+ async function a(f, y) {
563
+ await p.sync({
564
+ _id: f._id,
565
+ _rev: f._rev ?? "",
566
+ action: z.enum.approveDraft,
567
+ data: {
568
+ remark: f.remark ?? ""
569
+ }
570
+ }).delayed(500), e.open({
571
+ title: "Success",
572
+ message: "Sync requested",
573
+ type: "success"
574
+ }), y == null || y();
575
+ }
576
+ function _() {
577
+ v.value = !1;
578
+ }
579
+ async function O(f, y, h) {
580
+ await l.open({
581
+ title: "Refresh balance",
582
+ contentComponent: ca,
583
+ contentComponentProps: {
584
+ draft: f,
585
+ onFinished: (D) => {
586
+ l.close(), h == null || h(D);
587
+ },
588
+ onCancel: async () => {
589
+ l.close(), y == null || y();
590
+ }
591
+ }
592
+ });
593
+ }
594
+ return {
595
+ viewDraft: S,
596
+ closeDraftDialog: _,
597
+ approveDraft: P,
598
+ rejectDraft: I,
599
+ markAsFailed: s,
600
+ syncDraft: a,
601
+ exportDraft: $,
602
+ refreshBalance: O,
603
+ viewClosingDraftShow: v,
604
+ viewClosingDraftProps: R
605
+ };
606
+ }
607
+ );
608
+ function Le(o) {
609
+ switch (o) {
610
+ case "DRAFT":
611
+ return "fm-status-badge-draft";
612
+ case "PROCESSING":
613
+ return "fm-status-badge-processing";
614
+ case "FAILED":
615
+ return "fm-status-badge-cancel";
616
+ case "COMPLETED":
617
+ return "fm-status-badge-complete";
618
+ }
619
+ }
620
+ const ia = pt(
621
+ "closingDraftTable",
622
+ function() {
623
+ const { t: l } = ft(), e = Ee(), m = H(new Array()), p = H(!1), w = ze(), v = Ne();
624
+ async function R() {
625
+ if (m.value = [], !!w._currentLocation) {
626
+ p.value = !0;
627
+ try {
628
+ const [s] = await Promise.all([v.readDrafts()]).delayed(1e3);
629
+ m.value = s.reverse();
630
+ } catch (s) {
631
+ console.log("Something went wrong when fetching drafts:", s);
632
+ } finally {
633
+ p.value = !1;
634
+ }
635
+ }
636
+ }
637
+ async function S(s) {
638
+ if (!m.value.find((a) => a._id) && w._currentLocation) {
639
+ p.value = !0;
640
+ try {
641
+ const [a] = await Promise.all([
642
+ v.getDraft(s),
643
+ new Promise((_) => setTimeout(_, 1e3))
644
+ ]);
645
+ m.value = [a];
646
+ } catch (a) {
647
+ console.log("Something went wrong when fetching drafts:", a);
648
+ } finally {
649
+ p.value = !1;
650
+ }
651
+ }
652
+ }
653
+ function k(s) {
654
+ m.value = m.value.map((a) => a._id === s._id ? {
655
+ ...s,
656
+ _rev: a._rev
657
+ } : a);
658
+ }
659
+ function $() {
660
+ e.closeDraftDialog(), R();
661
+ }
662
+ function P(s, a) {
663
+ switch (a = It(a), s) {
664
+ case Re.Details:
665
+ return e.viewDraft(a);
666
+ case Re.Export:
667
+ return e.exportDraft(a);
668
+ case z.enum.approveDraft:
669
+ return e.approveDraft(a, $);
670
+ case z.enum.rejectDraft:
671
+ return e.rejectDraft(a, $);
672
+ case z.enum.markAsFailed:
673
+ return e.markAsFailed(a, $);
674
+ }
675
+ }
676
+ return {
677
+ columnDefs: [
678
+ {
679
+ id: "_id",
680
+ accessorKey: "_id",
681
+ header: () => l("inventory.closing.table.createdAt"),
682
+ cell(s) {
683
+ return Mt(`${s.getValue()}`);
684
+ },
685
+ enableSorting: !0
686
+ },
687
+ {
688
+ accessorKey: "effectiveAt",
689
+ header: () => "Effective at",
690
+ cell(s) {
691
+ const a = s.row.original;
692
+ let _ = s.getValue();
693
+ return _ || (_ = Ke(a._id)), ve(_);
694
+ },
695
+ enableSorting: !0,
696
+ size: 200
697
+ },
698
+ {
699
+ id: "updatedAt",
700
+ accessorFn: (s) => ve(s.updatedAt),
701
+ header: () => "Updated at",
702
+ enableSorting: !0,
703
+ size: 200
704
+ },
705
+ {
706
+ id: "updatedBy",
707
+ accessorKey: "updatedBy.name",
708
+ header: () => "Last update by",
709
+ enableSorting: !0,
710
+ size: 200
711
+ },
712
+ {
713
+ id: "noOfItems",
714
+ accessorFn: (s) => {
715
+ var a;
716
+ return s.items.length + (((a = s.negativeStockItems) == null ? void 0 : a.length) ?? 0);
717
+ },
718
+ header: () => l("inventory.closing.table.noOfItems"),
719
+ enableSorting: !1,
720
+ meta: {
721
+ width: "10rem",
722
+ textAlign: "right"
723
+ }
724
+ },
725
+ {
726
+ id: "recentRemark",
727
+ accessorFn: (s) => {
728
+ var a;
729
+ return (s == null ? void 0 : s.approveRemark) ?? ((a = s == null ? void 0 : s.rejectionHistory) == null ? void 0 : a.computeFirst((_) => _.rejectRemark)) ?? s.remark;
730
+ },
731
+ header: () => "Recent remark"
732
+ },
733
+ {
734
+ id: "status",
735
+ accessorFn: (s) => s.status,
736
+ header: () => l("inventory.closing.table.status"),
737
+ enableSorting: !1,
738
+ cell(s) {
739
+ var h;
740
+ const a = s.row.original, _ = a.status, O = new Date(a.updatedAt), f = (h = a == null ? void 0 : a.rejectionHistory) == null ? void 0 : h.computeFirst((D) => D.rejectedAt), y = f ? new Date(f) : null;
741
+ return _ === "DRAFT" && y ? y.getTime() > O.getTime() ? T(
742
+ "div",
743
+ {
744
+ class: "flex"
745
+ },
746
+ T(
747
+ "div",
748
+ {
749
+ class: ["fm-status-badge", Le("FAILED")]
750
+ },
751
+ "Rejected"
752
+ )
753
+ ) : T(
754
+ "div",
755
+ {
756
+ class: "flex"
757
+ },
758
+ T(
759
+ "div",
760
+ {
761
+ class: ["fm-status-badge", Le("PROCESSING")]
762
+ },
763
+ "Updated"
764
+ )
765
+ ) : T(
766
+ "div",
767
+ {
768
+ class: "flex"
769
+ },
770
+ T(
771
+ "div",
772
+ {
773
+ class: ["fm-status-badge", Le(_)]
774
+ },
775
+ Ue(_)
776
+ )
777
+ );
778
+ }
779
+ },
780
+ {
781
+ id: "action",
782
+ cell(s) {
783
+ const a = s.row.original, _ = [
784
+ st[Re.Details],
785
+ st[Re.Export]
786
+ ], O = [
787
+ {
788
+ translationKey: "inventory.closing.draft.approveDraft",
789
+ color: "text-fm-color-typo-primary",
790
+ value: z.enum.approveDraft
791
+ },
792
+ {
793
+ translationKey: "inventory.closing.draft.rejectDraft",
794
+ color: "text-fm-color-typo-error",
795
+ value: z.enum.rejectDraft
796
+ },
797
+ {
798
+ translationKey: "inventory.closing.draft.markAsFailed",
799
+ color: "text-fm-color-typo-error",
800
+ value: z.enum.markAsFailed
801
+ }
802
+ ];
803
+ return Rt(
804
+ [
805
+ ..._,
806
+ ...a.status === pe.enum.DRAFT ? O : []
807
+ ],
808
+ (f) => P(f, a)
809
+ );
810
+ },
811
+ enableSorting: !1,
812
+ size: 40,
813
+ meta: {
814
+ cellClass: "",
815
+ headerClass: ""
816
+ }
817
+ }
818
+ ],
819
+ drafts: m,
820
+ loading: p,
821
+ fetchDrafts: R,
822
+ loadDraft: S,
823
+ updateDraftRef: k
824
+ };
825
+ }
826
+ ), ua = { class: "w-full flex flex-col gap-32" }, da = { class: "flex justify-between" }, ma = { class: "flex" }, fa = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, pa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, va = { class: "flex gap-1" }, ya = { class: "fm-typo-en-body-lg-600" }, ga = { class: "flex flex-col gap-16" }, ba = { class: "flex items-center" }, ka = {
827
+ key: 0,
828
+ class: "flex gap-8"
829
+ }, ha = {
830
+ key: 0,
831
+ class: "w-full flex flex-col items-center"
832
+ }, Aa = { class: "flex items-center gap-8" }, xa = { class: "flex flex-col gap-8" }, _a = { class: "flex gap-8" }, Da = {
833
+ key: 0,
834
+ class: "flex gap-8"
835
+ }, wa = { class: "overflow-x-auto" }, Sa = {
836
+ key: 1,
837
+ class: "flex-1 xs:w-screen xs:max-w-full"
838
+ }, Ca = {
839
+ key: 0,
840
+ class: "flex flex-col items-center gap-8 h-full"
841
+ }, ja = ["src"], Ba = {
842
+ key: 1,
843
+ class: "px-4 flex flex-col"
844
+ }, Fa = { class: "flex gap-12 content-stretch" }, Ta = {
845
+ class: "flex flex-col w-24",
846
+ name: "circles"
847
+ }, $a = { class: "flex-1 flex flex-col items-center" }, Ma = { class: "flex-1 flex flex-col items-center" }, Ra = {
848
+ class: "py-12 flex flex-col gap-4",
849
+ name: "received-at header"
850
+ }, Ia = { class: "fm-typo-en-body-lg-400" }, Pa = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Va = { class: "flex gap-12 content-stretch" }, Ua = {
851
+ class: "flex flex-col w-24",
852
+ name: "circles"
853
+ }, La = { class: "flex-1 flex flex-col items-center" }, Ea = {
854
+ class: "py-12 flex flex-col gap-4 flex-1",
855
+ name: "delivery details"
856
+ }, Ha = { class: "flex flex-col gap-8" }, za = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Na = { class: "flex flex-col gap-4" }, Oa = { class: "flex gap-8" }, Ka = "N/A", Ya = /* @__PURE__ */ He({
857
+ __name: "ClosingDraftDialog",
858
+ props: {
859
+ show: { type: Boolean },
860
+ draft: {}
861
+ },
862
+ emits: ["submitted", "refresh"],
863
+ setup(o, { emit: l }) {
864
+ const e = o, m = vt(), p = Ee(), w = Ot(e, "show"), v = H(!1), R = H(!1), S = H(!1), k = H(new Array()), $ = H(new Array()), P = H([]), I = We(), s = Ne(), a = Ge(), _ = Pt(), O = ze(), f = _t({}), y = V(() => new Set(
865
+ _.skus.filter((c) => {
866
+ var t;
867
+ return f[(t = c.customAttributes) == null ? void 0 : t.tag];
868
+ }).map((c) => c._id)
869
+ )), h = l, D = H({
870
+ templateItem: !0,
871
+ nonTemplateItem: !0
872
+ }), M = V(() => {
873
+ var t, d;
874
+ const c = [...((t = e.draft) == null ? void 0 : t.items) ?? [], ...((d = e.draft) == null ? void 0 : d.negativeStockItems) ?? []];
875
+ return y.value.size ? c.filter((i) => y.value.has(i.sku._id)) : c;
876
+ }), Z = V(() => {
877
+ const c = M.value.map((t) => t.sku);
878
+ return c.sort((t, d) => t.code.localeCompare(d.code)), c;
879
+ }), W = V(() => M.value.groupBy(
880
+ (t) => t.sku._id,
881
+ (t) => t.measurementsAmounts.filter((d) => !d.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((d) => d.measurement.id)
882
+ ));
883
+ Ye(te), Dt(
884
+ () => e.show,
885
+ (c) => {
886
+ c && (le.value = xe[0], te(), D.value = {
887
+ templateItem: !0,
888
+ nonTemplateItem: !0
889
+ });
890
+ }
891
+ );
892
+ const re = Be(0), B = Be(100);
893
+ async function te() {
894
+ var t, d, i, n;
895
+ if (!O._currentLocation) return;
896
+ v.value = !0;
897
+ const c = ((t = e.draft) == null ? void 0 : t.status) === pe.enum.COMPLETED;
898
+ $.value = [];
899
+ try {
900
+ if (await _.init(), c) {
901
+ const E = e.draft.closingAdjustmentId;
902
+ if (!E) {
903
+ a.open({
904
+ title: "Something went wrong",
905
+ message: "Closing draft is completed but closing document cannot be found.",
906
+ type: "error"
907
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
908
+ draftId: (d = e.draft) == null ? void 0 : d._id
909
+ });
910
+ return;
911
+ }
912
+ const ae = await I.readAdjustmentById(E), ce = (ae == null ? void 0 : ae.skus) ?? [];
913
+ for (const ne of ce) {
914
+ const Ce = {
915
+ id: ne.sku._id,
916
+ balance: ne.fromBalance,
917
+ costs: ne.fromCostBalances
918
+ }, C = {
919
+ id: ne.sku._id,
920
+ balance: ne.toBalance,
921
+ costs: ne.toCostBalances
922
+ };
923
+ k.value.push(Ce), $.value.push(C);
924
+ }
925
+ } else
926
+ k.value = ((i = e.draft) == null ? void 0 : i.stockSnapshot) ?? [];
927
+ const u = /* @__PURE__ */ new Set();
928
+ if ((n = e.draft) != null && n.adjustmentSnapshot)
929
+ for (const E of e.draft.adjustmentSnapshot)
930
+ E.adjustmentsByType && Object.keys(E.adjustmentsByType).forEach((ae) => u.add(ae));
931
+ const g = ["receive", "sales", "wastage"], A = [];
932
+ g.forEach((E) => {
933
+ u.has(E) && (A.push(E), u.delete(E));
934
+ });
935
+ const b = Array.from(u).sort();
936
+ P.value = [...A, ...b];
937
+ } catch (u) {
938
+ a.open({
939
+ title: "Something went wrong",
940
+ message: "Something went wrong when fetching info. Please try again.",
941
+ type: "error"
942
+ }), console.error("error on fetch stock balances", u);
943
+ } finally {
944
+ v.value = !1;
945
+ }
946
+ }
947
+ async function be() {
948
+ var t, d;
949
+ if (!(((t = e.draft) == null ? void 0 : t.effectiveAt) ?? (e.draft ? Ke((d = e.draft) == null ? void 0 : d._id) : null))) {
950
+ a.open({
951
+ title: "Cannot refresh",
952
+ message: "Effective date is not available for this draft.",
953
+ type: "error"
954
+ });
955
+ return;
956
+ }
957
+ await p.refreshBalance(
958
+ e.draft,
959
+ () => {
960
+ },
961
+ async (i) => {
962
+ var A;
963
+ R.value = !0;
964
+ const n = (A = e.draft) == null ? void 0 : A._rev, u = 30, g = 2e3;
965
+ try {
966
+ await I.recalculation.scheduleCalculateStockSnapshotAtDate(i, e.draft._id);
967
+ let b = null;
968
+ for (let E = 0; E < u && (b = await s.getDraft(e.draft._id).delayed(g), b._rev === n); E++)
969
+ ;
970
+ if (!b || b._rev === n) {
971
+ a.open({
972
+ title: "Refresh failed",
973
+ message: "Failed to refresh stock balance. Please try again.",
974
+ type: "error"
975
+ }), console.error("error refreshing stock balances: there is no change in _rev");
976
+ return;
977
+ }
978
+ h("refresh", b), k.value = b.stockSnapshot ?? [], a.open({
979
+ title: "Balance refreshed",
980
+ message: "Stock balance has been recalculated.",
981
+ type: "success"
982
+ });
983
+ } catch (b) {
984
+ a.open({
985
+ title: "Refresh failed",
986
+ message: "Failed to refresh stock balance. Please try again.",
987
+ type: "error"
988
+ }), console.error("error refreshing stock balances", b);
989
+ } finally {
990
+ R.value = !1;
991
+ }
992
+ }
993
+ );
994
+ }
995
+ const ke = V(
996
+ () => k.value.groupBy(
997
+ (c) => c.id,
998
+ (c) => c.balance
999
+ )
1000
+ ), fe = V(() => M.value.groupBy((c) => c.sku._id)), ye = V(() => {
1001
+ var c;
1002
+ return (c = e.draft) != null && c.adjustmentSnapshot ? new Map(e.draft.adjustmentSnapshot.map((t) => [t.skuId, t.adjustmentsByType])) : /* @__PURE__ */ new Map();
1003
+ }), ge = V(() => {
1004
+ var c;
1005
+ return (c = e.draft) != null && c.opening ? new Map(e.draft.opening.map((t) => [t.skuId, t.balance])) : /* @__PURE__ */ new Map();
1006
+ });
1007
+ function Y(c, t) {
1008
+ return T(
1009
+ Ve.FmTooltip,
1010
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
1011
+ {
1012
+ default() {
1013
+ return c;
1014
+ },
1015
+ content() {
1016
+ return t || c;
1017
+ }
1018
+ }
1019
+ );
1020
+ }
1021
+ const we = V(() => {
1022
+ const c = Z.value.reduce((d, i) => {
1023
+ var n, u;
1024
+ return Math.max(d, ((u = (n = W.value) == null ? void 0 : n.get(i._id)) == null ? void 0 : u[0].length) ?? 0);
1025
+ }, 0);
1026
+ return [
1027
+ {
1028
+ id: "sku",
1029
+ accessorFn: (d) => `${d.code} ${d.name}`,
1030
+ header: () => "Name",
1031
+ size: 350,
1032
+ cell(d) {
1033
+ const i = d.row.original, n = i.adjustedDiffPercentage, u = typeof n == "number" && Math.abs(n) > 10, g = T("div", { class: "flex flex-col gap-4" }, [
1034
+ T(
1035
+ "div",
1036
+ {
1037
+ class: [
1038
+ "line-clamp-1 fm-typo-en-body-lg-400",
1039
+ u ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
1040
+ ]
1041
+ },
1042
+ i.name
1043
+ ),
1044
+ T(
1045
+ "div",
1046
+ {
1047
+ class: [
1048
+ "line-clamp-1 fm-typo-en-body-md-400",
1049
+ u ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
1050
+ ]
1051
+ },
1052
+ i.code
1053
+ )
1054
+ ]);
1055
+ return T(
1056
+ Ve.FmTooltip,
1057
+ {
1058
+ zIndex: 51
1059
+ },
1060
+ {
1061
+ content() {
1062
+ return u ? "Adjustment difference is more than 10%." : `${i.code} - ${i.name}`;
1063
+ },
1064
+ default() {
1065
+ return T("div", { class: "flex items-center gap-4 justify-start w-full" }, [
1066
+ g
1067
+ ]);
1068
+ }
1069
+ }
1070
+ );
1071
+ }
1072
+ },
1073
+ {
1074
+ id: "costPerUnit",
1075
+ accessorKey: "costPerUnit",
1076
+ header: () => Y("Cost per unit"),
1077
+ size: 160,
1078
+ cell(d) {
1079
+ const i = d.row.original.costPerUnit;
1080
+ return T("div", { class: "text-right" }, i.toFixed(2));
1081
+ },
1082
+ meta: {
1083
+ textAlign: "right"
1084
+ }
1085
+ },
1086
+ {
1087
+ id: "costUnit",
1088
+ header: () => "UOM",
1089
+ size: 80,
1090
+ cell(d) {
1091
+ const i = d.row.original.costUnit, n = d.row.original.baseUnit;
1092
+ return i ?? n;
1093
+ }
1094
+ },
1095
+ {
1096
+ id: "opening",
1097
+ accessorKey: "opening",
1098
+ header: () => Y("Opening (B/F)", "The opening balance brought forward from previous period."),
1099
+ size: 150,
1100
+ cell(d) {
1101
+ const i = d.row.original.opening;
1102
+ return T("div", { class: "text-right" }, i.toFixed(2));
1103
+ },
1104
+ meta: {
1105
+ textAlign: "right"
1106
+ }
1107
+ },
1108
+ // Dynamic adjustment type columns
1109
+ ...P.value.map(
1110
+ (d) => ({
1111
+ id: `adjustment_${d}`,
1112
+ accessorFn: (i) => i.adjustmentAmounts[d] ?? { amount: 0, precision: 0 },
1113
+ header: () => Y(Ue(d)),
1114
+ size: 150,
1115
+ cell(i) {
1116
+ const n = i.row.original.adjustmentAmounts[d] ?? { amount: 0, precision: 0 };
1117
+ return T("div", { class: "text-right" }, N(n));
1118
+ },
1119
+ meta: {
1120
+ textAlign: "right"
1121
+ }
1122
+ })
1123
+ ),
1124
+ {
1125
+ id: "systemBalance",
1126
+ accessorKey: "systemBalance",
1127
+ header: () => Y("System Balance", "The system calculated balance before stock take."),
1128
+ size: 200,
1129
+ meta: {
1130
+ textAlign: "right"
1131
+ }
1132
+ },
1133
+ {
1134
+ id: "physicalBalance",
1135
+ accessorFn: (d) => {
1136
+ var n;
1137
+ const i = (n = $.value.find((u) => u.id === d.id)) == null ? void 0 : n.balance;
1138
+ return i ? Ie.toFormatString({ value: i }) : d.physicalBalance;
1139
+ },
1140
+ header: () => Y("Stock Take balance", "The physical balance recorded during stock take."),
1141
+ cell(d) {
1142
+ var b;
1143
+ const i = d.row.original, n = Ie.fromNumber(i.physicalBalance);
1144
+ let u = !0, g = i.physicalBalance;
1145
+ const A = (b = $.value.find((E) => E.id === i.id)) == null ? void 0 : b.balance;
1146
+ return A && (Ie.equals({
1147
+ a: n,
1148
+ b: A
1149
+ }) || (u = !1, g = Number(Ie.toFormatString({ value: A })))), T("div", { class: "flex flex-col" }, [
1150
+ T(
1151
+ "span",
1152
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1153
+ g
1154
+ ),
1155
+ u ? null : T(
1156
+ "span",
1157
+ { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
1158
+ `Draft: ${i.physicalBalance.toString()}`
1159
+ )
1160
+ ]);
1161
+ },
1162
+ size: 200,
1163
+ meta: {
1164
+ textAlign: "right"
1165
+ }
1166
+ },
1167
+ {
1168
+ id: "adjustedAmount",
1169
+ accessorKey: "adjustedAmount",
1170
+ header: () => Y("Variance", "The difference between Stock Take balance and System Balance."),
1171
+ size: 200,
1172
+ meta: {
1173
+ textAlign: "right"
1174
+ }
1175
+ },
1176
+ {
1177
+ id: "varianceRM",
1178
+ accessorKey: "varianceRM",
1179
+ header: () => Y("Variance (RM)"),
1180
+ size: 150,
1181
+ cell(d) {
1182
+ const i = d.row.original.varianceRM;
1183
+ return T("div", { class: "text-right" }, i.toFixed(2));
1184
+ },
1185
+ meta: {
1186
+ textAlign: "right"
1187
+ }
1188
+ },
1189
+ {
1190
+ id: "adjustedDiffPercentage",
1191
+ accessorKey: "adjustedDiffPercentage",
1192
+ header: () => Y(
1193
+ "Variance (%)",
1194
+ "Difference between Stock Take balance and System Balance in percentage."
1195
+ ),
1196
+ size: 200,
1197
+ cell(d) {
1198
+ const i = d.row.original.adjustedDiffPercentage;
1199
+ if (!i) return Ka;
1200
+ const n = i.toFixed(2);
1201
+ if (n === "0.00")
1202
+ return T("div", { class: "flex items-center gap-4 justify-end" }, ["0.00"]);
1203
+ const u = i > 0;
1204
+ return T("div", { class: "flex items-center gap-4 justify-end" }, [
1205
+ T(Ve.FmIcon, {
1206
+ name: u ? "arrow_drop_up" : "arrow_drop_down",
1207
+ color: u ? "system-success-300" : "system-error-300",
1208
+ size: "md"
1209
+ }),
1210
+ n
1211
+ ]);
1212
+ },
1213
+ meta: {
1214
+ textAlign: "right"
1215
+ }
1216
+ },
1217
+ {
1218
+ id: "stockTakeValue",
1219
+ accessorKey: "stockTakeValue",
1220
+ header: () => Y("Stock take value (RM)"),
1221
+ size: 180,
1222
+ cell(d) {
1223
+ const i = d.row.original.stockTakeValue;
1224
+ return T("div", { class: "text-right" }, i.toFixed(2));
1225
+ },
1226
+ meta: {
1227
+ textAlign: "right"
1228
+ }
1229
+ },
1230
+ {
1231
+ id: "systemValue",
1232
+ accessorKey: "systemValue",
1233
+ header: () => Y("System value (RM)"),
1234
+ size: 180,
1235
+ cell(d) {
1236
+ const i = d.row.original.systemValue;
1237
+ return T("div", { class: "text-right" }, i.toFixed(2));
1238
+ },
1239
+ meta: {
1240
+ textAlign: "right"
1241
+ }
1242
+ },
1243
+ {
1244
+ id: "physicalBalances",
1245
+ header: () => "Amounts",
1246
+ enableSorting: !1,
1247
+ cell(d) {
1248
+ const i = d.row.original, n = (g, A) => T(
1249
+ Ve.FmTooltip,
1250
+ { zIndex: 50 },
1251
+ {
1252
+ default() {
1253
+ return T(
1254
+ "div",
1255
+ {
1256
+ class: "fm-typo-en-body-md-400 py-4 px-8 border-1 border-fm-color-typo-secondary fm-corner-radius-md line-clamp-1"
1257
+ },
1258
+ [
1259
+ T("span", { class: "text-fm-color-typo-primary" }, `${g} `),
1260
+ T(
1261
+ "span",
1262
+ {
1263
+ class: "text-fm-color-typo-secondary",
1264
+ style: { maxWidth: "80px" }
1265
+ },
1266
+ A
1267
+ )
1268
+ ]
1269
+ );
1270
+ },
1271
+ content() {
1272
+ return `${g} ${A}`;
1273
+ }
1274
+ }
1275
+ );
1276
+ let u = Array.from({ length: c }).map((g, A) => {
1277
+ if (!i[`measurementAmount${A}`])
1278
+ return null;
1279
+ const b = i[`measurementAmount${A}`], E = i[`measurementAbbrev${A}`];
1280
+ return n(b, E);
1281
+ }).filter((g) => g);
1282
+ return (i.baseUnitAmount || !u.length) && (u = [n(i.baseUnitAmount, i.baseUnit), ...u]), T(
1283
+ "div",
1284
+ {
1285
+ class: "flex gap-8 flex-nowrap",
1286
+ style: {
1287
+ minWidth: `${120 * u.length}px`
1288
+ }
1289
+ },
1290
+ u
1291
+ );
1292
+ }
1293
+ }
1294
+ ];
1295
+ }), he = V(() => we.value.map((c) => c.size ?? 0).reduce((c, t) => c + t)), Ae = H(""), Se = V(() => {
1296
+ var d, i;
1297
+ const c = ((i = (d = e.draft) == null ? void 0 : d.negativeStockItems) == null ? void 0 : i.reduce(
1298
+ (n, u) => (n[u.sku._id] = u, n),
1299
+ {}
1300
+ )) ?? {};
1301
+ return Z.value.map((n) => {
1302
+ var qe, Ze, Je, Xe, et, tt, at, nt, ot;
1303
+ const u = (qe = fe.value.get(n._id)) == null ? void 0 : qe[0], g = ((Ze = ke.value.get(n._id)) == null ? void 0 : Ze[0]) ?? re, A = (Je = n.defaultCost) != null && Je.costPerUnit ? n.defaultCost.costPerUnit.amount / Math.pow(10, n.defaultCost.costPerUnit.precision) : 0, b = ge.value.get(n._id), E = b ? +N(b) : 0, ae = ye.value.get(n._id), ce = {};
1304
+ if (P.value.forEach((Q) => {
1305
+ const oe = ce[Q] ?? { amount: 0, precision: 0 }, ue = ae == null ? void 0 : ae[Q];
1306
+ ue && (ce[Q] = Vt(oe, ue));
1307
+ }), !u) {
1308
+ const Q = +N(g), oe = Q - 0, ue = oe * A, Me = 0, xt = Q * A;
1309
+ return {
1310
+ id: n._id,
1311
+ code: n.code,
1312
+ name: n.name,
1313
+ costUnit: ((et = (Xe = n.defaultCost) == null ? void 0 : Xe.measurement) == null ? void 0 : et.abbrev) ?? null,
1314
+ baseUnit: n.unit.abbrev,
1315
+ baseUnitAmount: 0,
1316
+ systemBalance: Q,
1317
+ physicalBalance: 0,
1318
+ adjustedAmount: -Q,
1319
+ adjustedDiffPercentage: -100,
1320
+ isTemplateItem: !c[n._id],
1321
+ costPerUnit: A,
1322
+ opening: E,
1323
+ varianceQty: oe,
1324
+ varianceRM: ue,
1325
+ stockTakeValue: Me,
1326
+ systemValue: xt,
1327
+ adjustmentAmounts: ce
1328
+ };
1329
+ }
1330
+ const ne = yt(u), Ce = (at = (tt = $.value) == null ? void 0 : tt.find(
1331
+ (Q) => Q.id === n._id
1332
+ )) == null ? void 0 : at.balance, C = ut(
1333
+ Ce ?? ne,
1334
+ g
1335
+ ), K = g.amount === 0 ? null : dt(C, {
1336
+ ...g,
1337
+ amount: Math.abs(g.amount)
1338
+ }), q = K ? Qe(K, B) : null, ie = +N(g), _e = +N(ne), $e = ie - _e, kt = $e * A, ht = _e * A, At = ie * A;
1339
+ return {
1340
+ id: n._id,
1341
+ code: n.code,
1342
+ name: n.name,
1343
+ costUnit: ((ot = (nt = n.defaultCost) == null ? void 0 : nt.measurement) == null ? void 0 : ot.abbrev) ?? null,
1344
+ baseUnit: n.unit.abbrev,
1345
+ baseUnitAmount: +N(u.baseAmount),
1346
+ ...u.measurementsAmounts.filter((Q) => {
1347
+ var oe, ue, Me;
1348
+ return (Me = (ue = (oe = W.value) == null ? void 0 : oe.get(n._id)) == null ? void 0 : ue[0]) == null ? void 0 : Me.includes(Q.measurement.id);
1349
+ }).reduce((Q, oe, ue) => (Q[`measurementAbbrev${ue}`] = `(${oe.measurement.abbrev}) × ${N(oe.measurement.conversion)}`, Q[`measurementAmount${ue}`] = +N(oe.amount), Q), {}),
1350
+ systemBalance: ie,
1351
+ physicalBalance: _e,
1352
+ adjustedAmount: +N(C),
1353
+ adjustedDiffPercentage: q ? +N(mt(q, 2)) : null,
1354
+ isTemplateItem: !c[n._id],
1355
+ costPerUnit: A,
1356
+ opening: E,
1357
+ varianceQty: $e,
1358
+ varianceRM: kt,
1359
+ stockTakeValue: ht,
1360
+ systemValue: At,
1361
+ adjustmentAmounts: ce
1362
+ };
1363
+ }).filter((n) => !!(n.isTemplateItem && D.value.templateItem || !n.isTemplateItem && D.value.nonTemplateItem));
1364
+ }), Fe = V(() => {
1365
+ var t, d, i, n;
1366
+ if (!e.draft) return [];
1367
+ const c = e.draft.approvedAt ? {
1368
+ action: `Approve at ${ve(e.draft.approvedAt)}`,
1369
+ // actionAt: props.draft.approvedAt,
1370
+ actionBy: e.draft.approvedBy,
1371
+ remark: e.draft.approveRemark
1372
+ } : (t = e.draft.rejectionHistory) == null ? void 0 : t.computeFirst((u) => ({
1373
+ action: `Reject at ${ve(u.rejectedAt)}`,
1374
+ // actionAt: e.rejectedAt,
1375
+ actionBy: u.rejectedBy,
1376
+ remark: u.rejectRemark
1377
+ }));
1378
+ return [
1379
+ {
1380
+ label: "Created at",
1381
+ value: ve(e.draft.createdAt)
1382
+ },
1383
+ {
1384
+ label: "Created by",
1385
+ value: e.draft.createdBy.name
1386
+ },
1387
+ {
1388
+ label: "Updated at",
1389
+ value: ve(e.draft.updatedAt)
1390
+ },
1391
+ {
1392
+ label: "Updated by",
1393
+ value: e.draft.updatedBy.name
1394
+ },
1395
+ {
1396
+ label: "Effective at",
1397
+ value: ve(e.draft.effectiveAt ?? Ke((d = e.draft) == null ? void 0 : d._id))
1398
+ },
1399
+ {
1400
+ label: "Using template",
1401
+ value: ((i = e.draft.usingTemplates.find((u) => u)) == null ? void 0 : i.name) ?? "None"
1402
+ },
1403
+ e.draft.remark ? {
1404
+ label: "Remark",
1405
+ value: e.draft.remark
1406
+ } : null,
1407
+ c ? {
1408
+ label: "Last action",
1409
+ value: c.action
1410
+ } : null,
1411
+ c && c.actionBy ? {
1412
+ label: "Last action by",
1413
+ value: (n = c.actionBy) == null ? void 0 : n.name
1414
+ } : null,
1415
+ c && c.remark ? {
1416
+ label: "Action remark",
1417
+ value: c.remark
1418
+ } : null
1419
+ ].filter((u) => u).map((u) => u);
1420
+ }), xe = [
1421
+ {
1422
+ label: "Overview",
1423
+ value: "overview"
1424
+ },
1425
+ {
1426
+ label: "Action history",
1427
+ value: "history"
1428
+ }
1429
+ ], le = H(xe[0]), me = V(() => {
1430
+ var i, n, u;
1431
+ const c = ((i = e.draft) == null ? void 0 : i.activityLogs) ?? [], t = ((n = e.draft) == null ? void 0 : n.rejectionHistory) ?? [];
1432
+ for (const g of t)
1433
+ c.find(
1434
+ (b) => `${b.action}_${b.performedAt}` == `${z.enum.rejectDraft}_${g.rejectedAt}`
1435
+ ) || c.push({
1436
+ action: z.enum.rejectDraft,
1437
+ performedAt: g.rejectedAt,
1438
+ performedBy: g.rejectedBy,
1439
+ remark: g.rejectRemark
1440
+ });
1441
+ return (u = e.draft) != null && u.approvedAt && (c.find(
1442
+ (A) => {
1443
+ var b;
1444
+ return `${A.action}_${A.performedAt}` == `${z.enum.approveDraft}_${(b = e.draft) == null ? void 0 : b.approvedAt}`;
1445
+ }
1446
+ ) || c.push({
1447
+ action: z.enum.approveDraft,
1448
+ performedAt: e.draft.approvedAt,
1449
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
1450
+ remark: e.draft.approveRemark
1451
+ })), c.sort((g, A) => new Date(A.performedAt).getTime() - new Date(g.performedAt).getTime()).map(
1452
+ (g) => ({
1453
+ header: Ue(g.action),
1454
+ date: ve(g.performedAt),
1455
+ info: [
1456
+ {
1457
+ label: "Performed by",
1458
+ values: [g.performedBy.name]
1459
+ },
1460
+ {
1461
+ label: "Remark",
1462
+ values: [g.remark ?? ""]
1463
+ }
1464
+ ]
1465
+ })
1466
+ );
1467
+ }), Te = V(() => {
1468
+ var n, u, g, A;
1469
+ if ((n = e == null ? void 0 : e.draft) != null && n.approvedAt) return "Draft is already approved.";
1470
+ if (((u = e.draft) == null ? void 0 : u.status) !== pe.enum.DRAFT) return "Status is not draft.";
1471
+ const c = Se.value.some((b) => b.physicalBalance < 0), t = ((A = (g = m.stockBalance.skus) == null ? void 0 : g.filter((b) => b.balance.amount < 0)) == null ? void 0 : A.map((b) => b.id)) ?? [], d = new Set(Z.value.map((b) => b._id)), i = t.filter((b) => !d.has(b)).length;
1472
+ return [
1473
+ c ? "Negative total exist." : null,
1474
+ i ? "Negative stock is not included in this draft. Reopen draft in POS and apply changes." : null
1475
+ ].filter((b) => b).join(" ");
1476
+ });
1477
+ return (c, t) => {
1478
+ const d = U("FmButtonGroup"), i = U("FmMenuDivider"), n = U("FmCard"), u = U("FmButton"), g = U("FmCircularProgress"), A = U("FmChip"), b = U("FmTextField"), E = U("FmIcon"), ae = U("FmTable"), ce = U("FmSpacer"), ne = U("FmTooltip"), Ce = U("FmSideSheet");
1479
+ return j(), se(Ce, {
1480
+ "dismiss-away": "",
1481
+ "max-width": 9999,
1482
+ "model-value": F(w),
1483
+ "onUpdate:modelValue": t[10] || (t[10] = (C) => rt(w) ? w.value = C : null),
1484
+ header: "Closing details"
1485
+ }, {
1486
+ "side-sheet-footer": G(() => {
1487
+ var C, K, q, ie;
1488
+ return [
1489
+ r("div", Oa, [
1490
+ ((C = e.draft) == null ? void 0 : C.status) === F(pe).enum.DRAFT ? (j(), L(ee, { key: 0 }, [
1491
+ Te.value ? (j(), se(ne, {
1492
+ key: 0,
1493
+ "z-index": 51
1494
+ }, {
1495
+ content: G(() => [
1496
+ X(J(Te.value), 1)
1497
+ ]),
1498
+ default: G(() => [
1499
+ x(u, {
1500
+ disabled: "",
1501
+ key: "approve key",
1502
+ label: "Approve",
1503
+ onClick: t[5] || (t[5] = () => e.draft && F(p).approveDraft(e.draft, () => h("submitted")))
1504
+ })
1505
+ ]),
1506
+ _: 1
1507
+ })) : (j(), se(u, {
1508
+ key: "approve key",
1509
+ label: "Approve",
1510
+ onClick: t[6] || (t[6] = () => e.draft && F(p).approveDraft(e.draft, () => h("submitted")))
1511
+ }))
1512
+ ], 64)) : de("", !0),
1513
+ ((K = e.draft) == null ? void 0 : K.status) === F(pe).enum.DRAFT ? (j(), se(u, {
1514
+ key: 1,
1515
+ label: "Reject",
1516
+ variant: "destructive",
1517
+ onClick: t[7] || (t[7] = () => e.draft && F(p).rejectDraft(e.draft, () => h("submitted")))
1518
+ })) : de("", !0),
1519
+ (q = e.draft) != null && q.approvedAt && ((ie = e.draft) == null ? void 0 : ie.status) !== F(pe).enum.COMPLETED ? (j(), se(u, {
1520
+ key: 2,
1521
+ label: "Sync",
1522
+ loading: S.value,
1523
+ onClick: t[8] || (t[8] = () => {
1524
+ e.draft && (S.value = !0, F(p).syncDraft(e.draft, () => {
1525
+ S.value = !1, h("submitted");
1526
+ }));
1527
+ })
1528
+ }, null, 8, ["loading"])) : de("", !0),
1529
+ x(u, {
1530
+ label: "Close",
1531
+ variant: "tertiary",
1532
+ onClick: t[9] || (t[9] = (_e) => w.value = !1)
1533
+ })
1534
+ ])
1535
+ ];
1536
+ }),
1537
+ default: G(() => [
1538
+ r("div", ua, [
1539
+ r("div", null, [
1540
+ x(d, {
1541
+ items: xe,
1542
+ modelValue: le.value,
1543
+ "onUpdate:modelValue": t[0] || (t[0] = (C) => le.value = C)
1544
+ }, null, 8, ["modelValue"])
1545
+ ]),
1546
+ le.value.value === "overview" ? (j(), L(ee, { key: 0 }, [
1547
+ x(n, {
1548
+ variant: "outlined",
1549
+ class: "flex flex-col gap-8 px-12 py-16"
1550
+ }, {
1551
+ default: G(() => {
1552
+ var C, K;
1553
+ return [
1554
+ r("div", da, [
1555
+ t[11] || (t[11] = r("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
1556
+ r("div", ma, [
1557
+ r("div", {
1558
+ class: De(["fm-status-badge", F(Le)(((C = c.draft) == null ? void 0 : C.status) ?? "DRAFT")])
1559
+ }, J(F(Ue)(((K = c.draft) == null ? void 0 : K.status) ?? "")), 3)
1560
+ ])
1561
+ ]),
1562
+ x(i),
1563
+ r("div", fa, [
1564
+ (j(!0), L(ee, null, je(Fe.value, (q, ie) => (j(), L("div", {
1565
+ class: "flex flex-col gap-4",
1566
+ key: ie
1567
+ }, [
1568
+ r("div", pa, [
1569
+ r("div", va, J(q.label), 1)
1570
+ ]),
1571
+ r("div", ya, J(q.value), 1)
1572
+ ]))), 128))
1573
+ ])
1574
+ ];
1575
+ }),
1576
+ _: 1
1577
+ }),
1578
+ r("div", ga, [
1579
+ r("div", ba, [
1580
+ t[12] || (t[12] = r("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
1581
+ v.value ? de("", !0) : (j(), L("div", ka, [
1582
+ c.draft && c.draft.status !== F(pe).enum.COMPLETED ? (j(), se(u, {
1583
+ key: 0,
1584
+ label: "Refresh balance",
1585
+ "prepend-icon": "refresh",
1586
+ variant: "secondary",
1587
+ "text-color": "primary",
1588
+ "bg-color": "transparent",
1589
+ "border-color": "primary",
1590
+ loading: R.value,
1591
+ onClick: be
1592
+ }, null, 8, ["loading"])) : de("", !0),
1593
+ x(u, {
1594
+ label: "Export data",
1595
+ "prepend-icon": "download",
1596
+ variant: "secondary",
1597
+ "text-color": "primary",
1598
+ "bg-color": "transparent",
1599
+ "border-color": "primary",
1600
+ onClick: t[1] || (t[1] = (C) => c.draft ? F(p).exportDraft(
1601
+ c.draft,
1602
+ k.value,
1603
+ $.value
1604
+ ) : null)
1605
+ })
1606
+ ]))
1607
+ ]),
1608
+ v.value ? (j(), L("div", ha, [
1609
+ t[14] || (t[14] = r("div", { class: "h-80" }, null, -1)),
1610
+ r("div", Aa, [
1611
+ r("div", null, [
1612
+ x(g, { size: "md" })
1613
+ ]),
1614
+ t[13] || (t[13] = r("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
1615
+ ]),
1616
+ t[15] || (t[15] = r("div", { class: "h-80" }, null, -1))
1617
+ ])) : (j(), L(ee, { key: 1 }, [
1618
+ r("div", xa, [
1619
+ r("div", _a, [
1620
+ x(A, {
1621
+ label: "Template Item(s)",
1622
+ selected: D.value.templateItem,
1623
+ onClick: t[2] || (t[2] = (C) => D.value.templateItem = !D.value.templateItem)
1624
+ }, null, 8, ["selected"]),
1625
+ x(A, {
1626
+ label: "Non-template Item(s)",
1627
+ selected: D.value.nonTemplateItem,
1628
+ onClick: t[3] || (t[3] = (C) => D.value.nonTemplateItem = !D.value.nonTemplateItem)
1629
+ }, null, 8, ["selected"])
1630
+ ]),
1631
+ x(b, {
1632
+ modelValue: Ae.value,
1633
+ "onUpdate:modelValue": t[4] || (t[4] = (C) => Ae.value = C),
1634
+ placeholder: "Filter items"
1635
+ }, null, 8, ["modelValue"])
1636
+ ]),
1637
+ F(_).skuTags.size ? (j(), L("div", Da, [
1638
+ (j(!0), L(ee, null, je(F(_).skuTags.keys(), (C) => (j(), se(A, {
1639
+ key: `${C}`,
1640
+ label: `${C}`,
1641
+ selectable: "",
1642
+ selected: f[`${C}`],
1643
+ onClick: (K) => f[`${C}`] = !f[`${C}`]
1644
+ }, {
1645
+ default: G(() => [
1646
+ f[`${C}`] ? (j(), se(E, {
1647
+ key: 0,
1648
+ name: "check",
1649
+ class: "text-white",
1650
+ size: "sm"
1651
+ })) : de("", !0),
1652
+ r("span", {
1653
+ class: De([
1654
+ "",
1655
+ {
1656
+ "text-white fm-typo-en-body-md-600": f[`${C}`],
1657
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !f[`${C}`]
1658
+ }
1659
+ ])
1660
+ }, J(C), 3)
1661
+ ]),
1662
+ _: 2
1663
+ }, 1032, ["label", "selected", "onClick"]))), 128))
1664
+ ])) : de("", !0),
1665
+ r("div", wa, [
1666
+ r("div", {
1667
+ style: lt({ minWidth: `${he.value}px` })
1668
+ }, [
1669
+ x(ae, {
1670
+ "column-defs": we.value,
1671
+ "row-data": Se.value,
1672
+ "search-value": Ae.value
1673
+ }, null, 8, ["column-defs", "row-data", "search-value"])
1674
+ ], 4)
1675
+ ])
1676
+ ], 64))
1677
+ ])
1678
+ ], 64)) : de("", !0),
1679
+ le.value.value === "history" ? (j(), L("div", Sa, [
1680
+ me.value.length ? (j(), L("div", Ba, [
1681
+ (j(!0), L(ee, null, je(me.value, (C, K) => (j(), L(ee, { key: K }, [
1682
+ r("div", Fa, [
1683
+ r("div", Ta, [
1684
+ r("div", $a, [
1685
+ r("div", {
1686
+ class: De([
1687
+ {
1688
+ "bg-fm-color-primary": K !== 0,
1689
+ "bg-white": K === 0
1690
+ },
1691
+ "w-[2px] h-full"
1692
+ ])
1693
+ }, null, 2)
1694
+ ]),
1695
+ t[18] || (t[18] = r("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
1696
+ r("div", Ma, [
1697
+ r("div", {
1698
+ class: De([
1699
+ {
1700
+ "bg-fm-color-primary": K < me.value.length - 1,
1701
+ "bg-white": K >= me.value.length - 1
1702
+ },
1703
+ "w-[2px] h-full"
1704
+ ])
1705
+ }, null, 2)
1706
+ ])
1707
+ ]),
1708
+ r("div", Ra, [
1709
+ r("div", Ia, J(C.header), 1),
1710
+ r("div", Pa, J(C.date), 1)
1711
+ ])
1712
+ ]),
1713
+ r("div", Va, [
1714
+ r("div", Ua, [
1715
+ r("div", La, [
1716
+ r("div", {
1717
+ class: De([
1718
+ {
1719
+ "bg-fm-color-primary": K < me.value.length - 1,
1720
+ "bg-white": K >= me.value.length - 1
1721
+ },
1722
+ "w-[2px] h-full"
1723
+ ])
1724
+ }, null, 2)
1725
+ ])
1726
+ ]),
1727
+ r("div", Ea, [
1728
+ x(n, {
1729
+ variant: "outlined",
1730
+ class: "py-12 px-16"
1731
+ }, {
1732
+ default: G(() => [
1733
+ r("div", Ha, [
1734
+ (j(!0), L(ee, null, je(C.info, (q, ie) => (j(), L("div", {
1735
+ key: ie,
1736
+ class: "flex flex-col gap-4"
1737
+ }, [
1738
+ r("div", za, J(q == null ? void 0 : q.label), 1),
1739
+ r("div", Na, [
1740
+ (j(!0), L(ee, null, je(q == null ? void 0 : q.values, (_e, $e) => (j(), L("div", {
1741
+ key: $e,
1742
+ class: "fm-typo-en-body-lg-600"
1743
+ }, J(_e), 1))), 128))
1744
+ ])
1745
+ ]))), 128))
1746
+ ])
1747
+ ]),
1748
+ _: 2
1749
+ }, 1024)
1750
+ ])
1751
+ ])
1752
+ ], 64))), 128))
1753
+ ])) : (j(), L("div", Ca, [
1754
+ x(ce),
1755
+ r("div", null, [
1756
+ r("img", {
1757
+ src: F(Qt),
1758
+ alt: "List is empty"
1759
+ }, null, 8, ja)
1760
+ ]),
1761
+ t[16] || (t[16] = r("div", { class: "fm-typo-en-body-lg-600" }, J("No records found"), -1)),
1762
+ t[17] || (t[17] = r("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, J("You can track approval and rejection history here"), -1)),
1763
+ x(ce),
1764
+ x(ce)
1765
+ ]))
1766
+ ])) : de("", !0)
1767
+ ])
1768
+ ]),
1769
+ _: 1
1770
+ }, 8, ["model-value"]);
1771
+ };
1772
+ }
1773
+ }), Qa = { class: "flex-1 flex flex-col gap-8" }, Ga = { class: "flex flex-col" }, Wa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, qa = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Za = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Ja = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, un = /* @__PURE__ */ He({
1774
+ __name: "ClosingDraftView",
1775
+ setup(o) {
1776
+ const { t: l } = ft(), { viewDraft: e } = Ee(), { viewClosingDraftProps: m, viewClosingDraftShow: p } = Yt(Ee()), w = ze(), v = ia(), R = Ut(), { breakpoints: S } = Kt();
1777
+ w.watchLocation(v.fetchDrafts);
1778
+ const k = V(() => v.loading), $ = H(""), P = V(() => S.value.xs || S.value.sm), I = V(() => P.value ? 10 : 20);
1779
+ function s(O) {
1780
+ switch (O) {
1781
+ case "refresh":
1782
+ return v.fetchDrafts();
1783
+ }
1784
+ }
1785
+ function a(O) {
1786
+ return O;
1787
+ }
1788
+ const _ = V(() => P.value ? [
1789
+ {
1790
+ label: l("inventory.common.refresh"),
1791
+ value: "refresh",
1792
+ isPrimary: !1
1793
+ }
1794
+ ] : [
1795
+ {
1796
+ label: l("inventory.common.refresh"),
1797
+ value: "refresh",
1798
+ isPrimary: !1
1799
+ }
1800
+ ]);
1801
+ return (O, f) => {
1802
+ const y = U("FmTable");
1803
+ return j(), L(ee, null, [
1804
+ x(Lt, {
1805
+ title: F(l)("inventory.closing.draft.title"),
1806
+ actions: _.value,
1807
+ "onClick:action": s
1808
+ }, {
1809
+ default: G(() => [
1810
+ r("div", {
1811
+ class: De([
1812
+ "flex flex-col gap-8 max-h-full",
1813
+ {
1814
+ "p-0": P.value,
1815
+ "px-24 ": !P.value
1816
+ }
1817
+ ])
1818
+ }, [
1819
+ x(Et, {
1820
+ "change-location": "",
1821
+ searchable: "",
1822
+ search: $.value,
1823
+ "onUpdate:search": f[0] || (f[0] = (h) => $.value = h)
1824
+ }, null, 8, ["search"]),
1825
+ x(y, {
1826
+ style: lt(F(R).tableHeight),
1827
+ "column-defs": F(v).columnDefs,
1828
+ "row-data": F(v).drafts,
1829
+ "search-value": $.value,
1830
+ loading: k.value,
1831
+ onRowClick: f[1] || (f[1] = (h) => F(e)(h.original)),
1832
+ "page-size": I.value
1833
+ }, {
1834
+ "list-row": G((h) => [
1835
+ x(Ht, {
1836
+ row: h,
1837
+ onRowClick: (D) => F(e)(D)
1838
+ }, {
1839
+ default: G((D) => {
1840
+ var M, Z, W, re, B, te, be, ke, fe, ye, ge, Y, we, he, Ae, Se, Fe, xe, le, me;
1841
+ return [
1842
+ r("div", Qa, [
1843
+ r("div", Ga, [
1844
+ r("div", Wa, [
1845
+ x(F(Pe), {
1846
+ render: (W = (Z = (M = D._id) == null ? void 0 : M.column) == null ? void 0 : Z.columnDef) == null ? void 0 : W.cell,
1847
+ props: (B = (re = D._id) == null ? void 0 : re.getContext) == null ? void 0 : B.call(re)
1848
+ }, null, 8, ["render", "props"])
1849
+ ]),
1850
+ r("div", qa, [
1851
+ x(F(Pe), {
1852
+ render: (ke = (be = (te = D.name) == null ? void 0 : te.column) == null ? void 0 : be.columnDef) == null ? void 0 : ke.cell,
1853
+ props: (ye = (fe = D.name) == null ? void 0 : fe.getContext) == null ? void 0 : ye.call(fe)
1854
+ }, null, 8, ["render", "props"])
1855
+ ]),
1856
+ r("div", Za, J([
1857
+ ...h.original.items.slice(0, 3).map((Te) => Te.sku.name),
1858
+ ...h.original.items.length >= 3 ? [`and ${h.original.items.length - 3} more items`] : []
1859
+ ].join(", ")), 1),
1860
+ r("div", Ja, [
1861
+ x(F(Pe), {
1862
+ render: (we = (Y = (ge = D.ref) == null ? void 0 : ge.column) == null ? void 0 : Y.columnDef) == null ? void 0 : we.cell,
1863
+ props: (Ae = (he = D.ref) == null ? void 0 : he.getContext) == null ? void 0 : Ae.call(he)
1864
+ }, null, 8, ["render", "props"])
1865
+ ])
1866
+ ]),
1867
+ r("div", null, [
1868
+ x(F(Pe), {
1869
+ render: (xe = (Fe = (Se = D.status) == null ? void 0 : Se.column) == null ? void 0 : Fe.columnDef) == null ? void 0 : xe.cell,
1870
+ props: (me = (le = D.status) == null ? void 0 : le.getContext) == null ? void 0 : me.call(le)
1871
+ }, null, 8, ["render", "props"])
1872
+ ])
1873
+ ])
1874
+ ];
1875
+ }),
1876
+ _: 2
1877
+ }, 1032, ["row", "onRowClick"])
1878
+ ]),
1879
+ _: 1
1880
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
1881
+ ], 2)
1882
+ ]),
1883
+ _: 1
1884
+ }, 8, ["title", "actions"]),
1885
+ (j(), se(wt, { to: "body" }, [
1886
+ x(Ya, St(F(m), {
1887
+ show: F(p),
1888
+ "onUpdate:show": f[2] || (f[2] = (h) => rt(p) ? p.value = h : null),
1889
+ onSubmitted: f[3] || (f[3] = () => (p.value = !1, F(v).fetchDrafts())),
1890
+ onRefresh: f[4] || (f[4] = (h) => F(v).updateDraftRef(h))
1891
+ }), null, 16, ["show"])
1892
+ ]))
1893
+ ], 64);
1894
+ };
1895
+ }
1896
+ });
1897
+ export {
1898
+ un as default
1899
+ };