@feedmepos/mf-inventory-portal 1.2.42-dev.2 → 1.2.42

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