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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/{App-BP1j0Wfm.js → App-BhEtjLqO.js} +1 -1
  2. package/dist/ApprovalView-BHIVSsbz.js +213 -0
  3. package/dist/{BindingsDialog-DsJ4ULCX.js → BindingsDialog-CX3Hu_r6.js} +4 -4
  4. package/dist/{BindingsPicker-C8VsQIVc.js → BindingsPicker-BbinQ8Hl.js} +1 -1
  5. package/dist/{BindingsTable-Dv7ovYaR.js → BindingsTable-DxlSz6Ev.js} +4 -4
  6. package/dist/ClosingDraftView-B5gQ2k-T.js +1520 -0
  7. package/dist/{ClosingTemplateView-3RWSh9GP.js → ClosingTemplateView-CB9_JOl4.js} +2 -2
  8. package/dist/{DeliveryOrderPrintPreview-BH060kC1.js → DeliveryOrderPrintPreview-BlE3fIAT.js} +1 -1
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CdeaTsc8.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DxKFFyWs.js} +3 -3
  10. package/dist/{FmMultiselectDialog-C-9RO1fp.js → FmMultiselectDialog-DcviKwNR.js} +1 -1
  11. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-C57WQ2iL.js → FmUnitInput.vue_vue_type_script_setup_true_lang-CepHeClt.js} +1 -1
  12. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-CpWvuh5U.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-Dg8VdQzg.js} +1 -1
  13. package/dist/{IngredientGroupView-BnPGvMNK.js → IngredientGroupView-EE8lN8JL.js} +2 -2
  14. package/dist/{IngredientsView-e_HgWPoP.js → IngredientsView-BkDpHVvn.js} +4 -4
  15. package/dist/{IntegrationView-DYkTeLDC.js → IntegrationView-Bj7sb1gO.js} +1141 -1170
  16. package/dist/{InventoryBindingForm-CBYmaiJ-.js → InventoryBindingForm-BkazprFH.js} +1 -1
  17. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-DfNnosnL.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-BbQqYyzL.js} +3 -3
  18. package/dist/{InventoryBindingSummary-DGjY9q0H.js → InventoryBindingSummary-D0XiOdR4.js} +1 -1
  19. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Cy0r8-gD.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Pf8BPDZw.js} +1 -1
  20. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-CO4-uU7s.js → PremiumBadge.vue_vue_type_script_setup_true_lang-D2Tx3xSj.js} +1 -1
  21. package/dist/{PublishView-CtPChk5P.js → PublishView-BUIcrw8m.js} +18 -18
  22. package/dist/{PurchaseOrderPrintPreview-DzivX4_W.js → PurchaseOrderPrintPreview-lO7Bilm5.js} +1 -1
  23. package/dist/{ReceiveRequestView-QCbdf08n.js → ReceiveRequestView-BZV-8Ib3.js} +694 -697
  24. package/dist/{RecipeView-D1NTlI0L.js → RecipeView-2Tm12Zuk.js} +3 -3
  25. package/dist/{StockView-CdfztIA6.js → StockView-DaWS_HQl.js} +6 -6
  26. package/dist/{SupplierView-CCqxkiW7.js → SupplierView-nfxqynuY.js} +3 -3
  27. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-g74nRiM0.js +2213 -0
  28. package/dist/{TransferTemplateView-AWGyqDnj.js → TransferTemplateView-CGjfCELA.js} +6 -6
  29. package/dist/{UnitView-D49BzCAv.js → UnitView-Cm5WuuEN.js} +3 -3
  30. package/dist/{WarehouseView-C5H3zy02.js → WarehouseView-BSLX0g3B.js} +1 -1
  31. package/dist/api/netsuite.d.ts +0 -1
  32. package/dist/{app-F90HTHJ6.js → app-CnDLBWW7.js} +27510 -27243
  33. package/dist/app.d.ts +0 -9
  34. package/dist/app.js +5 -5
  35. package/dist/components/FmMultiselectDialogTemporary.vue.d.ts +41 -0
  36. package/dist/{decimal-DMDoO7Rc.js → decimal-DmezA5YT.js} +1 -1
  37. package/dist/{format-unit-display-CyqyV_Q1.js → format-unit-display-Bcq6wldv.js} +2 -2
  38. package/dist/{index-Bq6I3lAV.js → index-C476dvi7.js} +2651 -2687
  39. package/dist/{index-DGNRUhaL.js → index-R97nRHsF.js} +1 -1
  40. package/dist/{stock-D53H7SeD.js → stock-Dd0YSjSF.js} +1 -1
  41. package/dist/style.css +1 -1
  42. package/dist/{supplier-CyLpu1Jk.js → supplier-C4s3SHui.js} +1 -1
  43. package/dist/tsconfig.app.tsbuildinfo +1 -1
  44. package/dist/{use-ingredient-select-dialog-Cp9Z0ZMi.js → use-ingredient-select-dialog-DaXBOLhz.js} +1 -1
  45. package/dist/{use-inventory-binding-dialog-DlFMZOnP.js → use-inventory-binding-dialog-CsFwoUbg.js} +1 -1
  46. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +1 -4
  47. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +0 -8
  48. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +0 -626
  49. package/dist/{vue-i18n-CH21Ql15.js → vue-i18n-CdkMdZ30.js} +393 -393
  50. package/package.json +4 -4
  51. package/dist/ApprovalView-DHpMEMs9.js +0 -219
  52. package/dist/ClosingDraftView-m5qcjTQQ.js +0 -1676
  53. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CKZam-tm.js +0 -2275
  54. package/dist/views/closing-draft/components/closing-draft-action/RefreshBalanceAction.vue.d.ts +0 -19
  55. package/dist/views/receive-request/composables/fn.d.ts +0 -8
@@ -0,0 +1,1520 @@
1
+ import { defineComponent as Te, ref as N, computed as P, onMounted as Ie, resolveComponent as I, openBlock as A, createElementBlock as R, Fragment as q, createTextVNode as pe, createBlock as Q, withCtx as Y, createElementVNode as r, toDisplayString as O, unref as D, createVNode as x, createCommentVNode as J, h as F, reactive as Ze, watch as Je, isRef as Le, normalizeClass as ve, renderList as he, normalizeStyle as Ee, Teleport as Qe, mergeProps as Xe } from "vue";
2
+ import { a3 as et, u as Se, am as M, ae as tt, an as at, m as nt, P as Re, j as L, t as ot, T as Ae, r as st, s as rt, v as lt, ao as He, ap as ze, a9 as Ne, aq as ne, af as ct, al as re, a0 as Be, D as Ue, i as _e, h as it, f as ut, a as dt, B as mt, _ as ft, C as pt, E as vt, G as we } from "./app-CnDLBWW7.js";
3
+ import { useCoreStore as yt, useI18n as Ve } from "@feedmepos/mf-common";
4
+ import { useSnackbar as Me, useDialog as gt, useProxiedModel as bt, components as fe, useBreakpoints as ht } from "@feedmepos/ui-library";
5
+ import { defineStore as Oe, storeToRefs as At } from "pinia";
6
+ import { a as Ye, u as Ke } from "./stock-Dd0YSjSF.js";
7
+ import { E as Dt } from "./empty-placeholder-wf6-BWE8.js";
8
+ const $e = et((s, l) => {
9
+ function e() {
10
+ return Se().currentLocation.dbName;
11
+ }
12
+ return {
13
+ async getDraft(d) {
14
+ const m = e(), k = `${s.inventoryBackendUrl}/${m}/closing-draft/${d}`;
15
+ return l.get(k);
16
+ },
17
+ async readDrafts() {
18
+ const d = e(), m = `${s.inventoryBackendUrl}/${d}/closing-draft`;
19
+ return l.get(m);
20
+ },
21
+ async runOperation(d) {
22
+ const m = e(), k = `${s.inventoryBackendUrl}/${m}/closing-draft/run-operation`;
23
+ return l.post(k, d);
24
+ },
25
+ async sync(d) {
26
+ const m = e(), k = `${s.inventoryBackendUrl}/${m}/closing-draft/sync`;
27
+ return l.post(k, d);
28
+ }
29
+ };
30
+ }), kt = { class: "fm-typo-en-body-lg-400" }, xt = { class: "fm-typo-en-body-lg-600" }, _t = {
31
+ key: 0,
32
+ class: "flex flex-col"
33
+ }, wt = { class: "flex gap-12 py-8 justify-end w-full" }, Fe = /* @__PURE__ */ Te({
34
+ __name: "ClosingDraftAction",
35
+ props: {
36
+ draft: {},
37
+ action: {},
38
+ onCancel: { type: Function },
39
+ onFinished: { type: Function }
40
+ },
41
+ setup(s) {
42
+ const l = s, e = N(), d = $e(), m = Me(), k = N(!1), p = N(null), U = N(!1), y = P(() => {
43
+ switch (l.action) {
44
+ case M.enum.approveDraft:
45
+ return "Approve";
46
+ case M.enum.rejectDraft:
47
+ return "Reject";
48
+ case M.enum.markAsFailed:
49
+ return "Mark as Failed";
50
+ }
51
+ throw new Error(`Unknown action: ${l.action}`);
52
+ }), B = P(() => {
53
+ switch (l.action) {
54
+ case M.enum.approveDraft:
55
+ return "primary";
56
+ case M.enum.rejectDraft:
57
+ return "destructive";
58
+ case M.enum.markAsFailed:
59
+ return "destructive";
60
+ }
61
+ throw new Error(`Unknown action: ${l.action}`);
62
+ });
63
+ Ie(() => {
64
+ if (l.draft.effectiveAt)
65
+ p.value = new Date(l.draft.effectiveAt);
66
+ else {
67
+ const o = new Date(l.draft.createdAt);
68
+ o.setHours(23, 59, 59, 999), p.value = o;
69
+ }
70
+ U.value = !0;
71
+ });
72
+ const T = P({
73
+ get() {
74
+ return p.value === null ? "" : tt(p.value);
75
+ },
76
+ set(o) {
77
+ if (o) {
78
+ const n = /* @__PURE__ */ new Date(`${o} ${E.value}`);
79
+ n.setSeconds(59, 999), p.value = n;
80
+ } else
81
+ p.value = null;
82
+ }
83
+ }), E = P({
84
+ get() {
85
+ return p.value === null ? "" : at(p.value);
86
+ },
87
+ set(o) {
88
+ if (o) {
89
+ const n = /* @__PURE__ */ new Date(`${T.value} ${o}`);
90
+ n.setSeconds(59, 999), p.value = n;
91
+ } else
92
+ p.value = null;
93
+ }
94
+ });
95
+ async function z() {
96
+ k.value = !0;
97
+ try {
98
+ await d.runOperation({
99
+ _id: l.draft._id,
100
+ _rev: l.draft._rev ?? "",
101
+ action: l.action,
102
+ data: {
103
+ effectiveAt: p.value ? p.value.toISOString() : null,
104
+ remark: e.value
105
+ }
106
+ }).delayed(500), m.open({
107
+ title: "Success",
108
+ message: "Action submitted",
109
+ type: "success"
110
+ }), l.onFinished();
111
+ } catch (o) {
112
+ m.open({
113
+ title: "Something went wrong",
114
+ message: "Unable to submit action. Please try again",
115
+ type: "error"
116
+ }), console.error("error on submit closing draft action", o);
117
+ } finally {
118
+ k.value = !1;
119
+ }
120
+ }
121
+ return (o, n) => {
122
+ const C = I("FmLabel"), g = I("FmDatePicker"), c = I("FmTimePicker"), H = I("FmTextField"), _ = I("FmButton"), $ = I("FmForm");
123
+ return U.value ? (A(), Q($, {
124
+ key: 1,
125
+ onValidationSuccess: z,
126
+ class: "flex flex-col gap-32",
127
+ disabled: k.value
128
+ }, {
129
+ default: Y(() => [
130
+ r("div", kt, [
131
+ n[4] || (n[4] = pe(" You are about to ")),
132
+ r("span", xt, O(y.value), 1),
133
+ n[5] || (n[5] = pe(" this draft. Please provide a remark to justify this action. "))
134
+ ]),
135
+ o.action === D(M).enum.approveDraft ? (A(), R("div", _t, [
136
+ x(C, { class: "fm-typo-en-body-lg-600" }, {
137
+ default: Y(() => n[6] || (n[6] = [
138
+ pe("Closing Date")
139
+ ])),
140
+ _: 1
141
+ }),
142
+ x(g, {
143
+ modelValue: T.value,
144
+ "onUpdate:modelValue": n[0] || (n[0] = (j) => T.value = j)
145
+ }, null, 8, ["modelValue"]),
146
+ x(C, { class: "fm-typo-en-body-lg-600" }, {
147
+ default: Y(() => n[7] || (n[7] = [
148
+ pe("Closing Time")
149
+ ])),
150
+ _: 1
151
+ }),
152
+ x(c, {
153
+ modelValue: E.value,
154
+ "onUpdate:modelValue": n[1] || (n[1] = (j) => E.value = j)
155
+ }, null, 8, ["modelValue"])
156
+ ])) : J("", !0),
157
+ x(H, {
158
+ modelValue: e.value,
159
+ "onUpdate:modelValue": n[2] || (n[2] = (j) => e.value = j),
160
+ label: "Remark",
161
+ "label-mark": "required",
162
+ rules: [D(nt)()]
163
+ }, null, 8, ["modelValue", "rules"]),
164
+ r("div", wt, [
165
+ x(_, {
166
+ label: "Cancel",
167
+ variant: "tertiary",
168
+ onClick: n[3] || (n[3] = (j) => o.onCancel())
169
+ }),
170
+ x(_, {
171
+ label: y.value,
172
+ type: "submit",
173
+ variant: B.value,
174
+ loading: k.value
175
+ }, null, 8, ["label", "variant", "loading"])
176
+ ])
177
+ ]),
178
+ _: 1
179
+ }, 8, ["disabled"])) : (A(), R(q, { key: 0 }, [
180
+ pe("Loading")
181
+ ], 64));
182
+ };
183
+ }
184
+ }), Ct = Ae(0);
185
+ function Ge(s) {
186
+ const l = s.measurementsAmounts.groupBy((d) => d.measurement.id), e = s.sku.unit.measurements.reduce((d, m) => {
187
+ var U, y;
188
+ const k = ((y = (U = l.get(m.id)) == null ? void 0 : U[0]) == null ? void 0 : y.amount) ?? Ct, p = Re(m.conversion, k);
189
+ return d + +L(p);
190
+ }, +L(s.baseAmount));
191
+ return ot(e, s.baseAmount.precision);
192
+ }
193
+ const jt = Ae(0), St = Ae(100);
194
+ function $t(s, l, e) {
195
+ const d = Ge(s), m = He(d, l), k = l.amount === 0 ? null : ze(m, {
196
+ ...l,
197
+ amount: Math.abs(l.amount)
198
+ }), p = k ? Re(k, St) : null;
199
+ return {
200
+ code: s.sku.code,
201
+ name: s.sku.name,
202
+ baseUnit: s.sku.unit.abbrev,
203
+ baseUnitAmount: +L(s.baseAmount),
204
+ ...s.measurementsAmounts.filter(
205
+ (y) => Ft(y.measurement) && e.includes(y.measurement.id)
206
+ ).reduce(
207
+ (y, B, T) => (y[`measurementAbbrev${T}`] = `(${B.measurement.abbrev}) × ${L(B.measurement.conversion)}`, y[`measurementAmount${T}`] = +L(B.amount), y),
208
+ {}
209
+ ),
210
+ systemBalance: +L(l),
211
+ physicalBalance: +L(d),
212
+ adjustedAmount: +L(m),
213
+ adjustedDiffPercentage: p ? +L(Ne(p, 2)) : null
214
+ };
215
+ }
216
+ function Ft(s) {
217
+ return !s.abbrev.toLocaleLowerCase().includes("inactive");
218
+ }
219
+ function Bt(s) {
220
+ const l = qe(s);
221
+ return s.reduce(
222
+ (e, d) => {
223
+ var m;
224
+ return Math.max(e, ((m = l == null ? void 0 : l.get(d.sku._id)) == null ? void 0 : m[0].length) ?? 0);
225
+ },
226
+ 0
227
+ );
228
+ }
229
+ function qe(s) {
230
+ return s.groupBy(
231
+ (l) => l.sku._id,
232
+ (l) => l.measurementsAmounts.filter((e) => !e.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((e) => e.measurement.id)
233
+ );
234
+ }
235
+ function Tt(s) {
236
+ return [
237
+ {
238
+ id: "code",
239
+ name: "Code"
240
+ },
241
+ {
242
+ id: "name",
243
+ name: "Name"
244
+ },
245
+ {
246
+ id: "systemBalance",
247
+ name: "Balance"
248
+ },
249
+ {
250
+ id: "physicalBalance",
251
+ name: "Actual balance"
252
+ },
253
+ {
254
+ id: "adjustedAmount",
255
+ name: "Adjusted balance"
256
+ },
257
+ {
258
+ id: "adjustedDiffPercentage",
259
+ name: "Diff (%)"
260
+ },
261
+ {
262
+ id: "baseUnitAmount",
263
+ name: "Base unit amount"
264
+ },
265
+ {
266
+ id: "baseUnit",
267
+ name: "Base unit"
268
+ },
269
+ ...Array.from({ length: s }).flatMap((e, d) => [
270
+ {
271
+ id: `measurementAmount${d}`,
272
+ name: `UOM amount ${d + 1}`
273
+ },
274
+ {
275
+ id: `measurementAbbrev${d}`,
276
+ name: `UOM ${d + 1}`
277
+ }
278
+ ])
279
+ ];
280
+ }
281
+ function Rt(s, l) {
282
+ var n, C, g, c, H, _, $;
283
+ const e = l.groupBy(
284
+ (j) => j.id,
285
+ (j) => j.balance
286
+ ), d = [...s.items, ...s.negativeStockItems ?? []], m = qe(d), k = d.map((j) => {
287
+ var X, oe;
288
+ const K = ((X = e.get(j.sku._id)) == null ? void 0 : X[0]) ?? jt, te = ((oe = m == null ? void 0 : m.get(j.sku._id)) == null ? void 0 : oe[0]) ?? [];
289
+ return $t(j, K, te);
290
+ }), p = Bt(d), y = yt().currentBusiness.value, B = Tt(p), T = [
291
+ ["Business name:", y == null ? void 0 : y.name],
292
+ ["Business ID:", y == null ? void 0 : y._id],
293
+ ["Menu version", y == null ? void 0 : y.menuVersion],
294
+ ["Created at", new Date(s.createdAt)],
295
+ ["Created by", (n = s.createdBy) == null ? void 0 : n.name],
296
+ ["Updated at", new Date(s.updatedAt)],
297
+ ["Updated by", (C = s.updatedBy) == null ? void 0 : C.name],
298
+ ["Recent action", s.approvedAt ? "Approve" : s.rejectionHistory ? "Reject" : ""],
299
+ [
300
+ "Action by",
301
+ s.approvedAt ? (g = s.approvedBy) == null ? void 0 : g.name : s.rejectionHistory ? (H = (c = s.rejectionHistory[0]) == null ? void 0 : c.rejectedBy) == null ? void 0 : H.name : ""
302
+ ],
303
+ [
304
+ "Action at",
305
+ s.approvedAt ? new Date(s.approvedAt) : s.rejectionHistory ? new Date((_ = s.rejectionHistory[0]) == null ? void 0 : _.rejectedAt) : ""
306
+ ],
307
+ [
308
+ "Action remark",
309
+ s.approvedAt ? s.approveRemark : s.rejectionHistory ? new Date(($ = s.rejectionHistory[0]) == null ? void 0 : $.rejectRemark) : ""
310
+ ],
311
+ [],
312
+ B.map((j) => j.name),
313
+ ...k.map((j) => B.map((K) => j[K.id]))
314
+ ], E = B.map((j) => `system:${j.id}`), z = st(T, E), o = `[${y == null ? void 0 : y.name}] closing draft (${rt(new Date(s.updatedAt))}).xlsx`;
315
+ return lt(z, o), o;
316
+ }
317
+ const je = Oe(
318
+ "closingDraftActions",
319
+ function() {
320
+ const l = gt(), e = Me(), d = Ye(), m = $e(), k = Ke(), p = N(!1), U = N();
321
+ function y(g) {
322
+ const c = {
323
+ draft: g
324
+ };
325
+ U.value = c, p.value = !0;
326
+ }
327
+ async function B(g) {
328
+ var H;
329
+ if (g.status === ne.enum.COMPLETED) {
330
+ const _ = g.closingAdjustmentId;
331
+ if (!_)
332
+ return e.open({
333
+ title: "Something went wrong",
334
+ message: "Closing draft is completed but closing document cannot be found.",
335
+ type: "error"
336
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
337
+ draftId: g._id
338
+ }), [];
339
+ const $ = await d.readAdjustmentById(_);
340
+ return (($ == null ? void 0 : $.skus) ?? []).map((K) => ({
341
+ id: K.sku._id,
342
+ balance: K.fromBalance,
343
+ costs: K.fromCostBalances
344
+ }));
345
+ } else
346
+ return await k.readStockBalance(), ((H = k.stockBalance) == null ? void 0 : H.skus) ?? [];
347
+ }
348
+ async function T(g, c) {
349
+ c || (e.open({
350
+ title: "Exporting",
351
+ message: "Fetching data..."
352
+ }), c = await B(g)), Rt(g, c);
353
+ }
354
+ function E(g, c) {
355
+ l.open({
356
+ title: "Approve draft",
357
+ contentComponent: Fe,
358
+ contentComponentProps: {
359
+ draft: g,
360
+ action: M.enum.approveDraft,
361
+ onFinished: () => {
362
+ l.close(), c == null || c();
363
+ },
364
+ onCancel: () => l.close()
365
+ }
366
+ });
367
+ }
368
+ function z(g, c) {
369
+ l.open({
370
+ title: "Reject draft",
371
+ contentComponent: Fe,
372
+ contentComponentProps: {
373
+ draft: g,
374
+ action: M.enum.rejectDraft,
375
+ onFinished: () => {
376
+ l.close(), c == null || c();
377
+ },
378
+ onCancel: () => l.close()
379
+ }
380
+ });
381
+ }
382
+ function o(g, c) {
383
+ l.open({
384
+ title: "Mark draft as failed",
385
+ contentComponent: Fe,
386
+ contentComponentProps: {
387
+ draft: g,
388
+ action: M.enum.markAsFailed,
389
+ onFinished: () => {
390
+ l.close(), c == null || c();
391
+ },
392
+ onCancel: () => l.close()
393
+ }
394
+ });
395
+ }
396
+ async function n(g, c) {
397
+ await m.sync({
398
+ _id: g._id,
399
+ _rev: g._rev ?? "",
400
+ action: M.enum.approveDraft,
401
+ data: {
402
+ remark: g.remark ?? ""
403
+ }
404
+ }).delayed(500), e.open({
405
+ title: "Success",
406
+ message: "Sync requested",
407
+ type: "success"
408
+ }), c == null || c();
409
+ }
410
+ function C() {
411
+ p.value = !1;
412
+ }
413
+ return {
414
+ viewDraft: y,
415
+ closeDraftDialog: C,
416
+ approveDraft: E,
417
+ rejectDraft: z,
418
+ markAsFailed: o,
419
+ syncDraft: n,
420
+ exportDraft: T,
421
+ viewClosingDraftShow: p,
422
+ viewClosingDraftProps: U
423
+ };
424
+ }
425
+ );
426
+ function Ce(s) {
427
+ switch (s) {
428
+ case "DRAFT":
429
+ return "fm-status-badge-draft";
430
+ case "PROCESSING":
431
+ return "fm-status-badge-processing";
432
+ case "FAILED":
433
+ return "fm-status-badge-cancel";
434
+ case "COMPLETED":
435
+ return "fm-status-badge-complete";
436
+ }
437
+ }
438
+ const Mt = Oe(
439
+ "closingDraftTable",
440
+ function() {
441
+ const { t: l } = Ve(), e = je(), d = N(new Array()), m = N(!1), k = Se(), p = $e();
442
+ async function U() {
443
+ if (d.value = [], !!k._currentLocation) {
444
+ m.value = !0;
445
+ try {
446
+ const [o] = await Promise.all([p.readDrafts()]).delayed(1e3);
447
+ d.value = o.reverse();
448
+ } catch (o) {
449
+ console.log("Something went wrong when fetching drafts:", o);
450
+ } finally {
451
+ m.value = !1;
452
+ }
453
+ }
454
+ }
455
+ async function y(o) {
456
+ if (!d.value.find((n) => n._id) && k._currentLocation) {
457
+ m.value = !0;
458
+ try {
459
+ const [n] = await Promise.all([
460
+ p.getDraft(o),
461
+ new Promise((C) => setTimeout(C, 1e3))
462
+ ]);
463
+ d.value = [n];
464
+ } catch (n) {
465
+ console.log("Something went wrong when fetching drafts:", n);
466
+ } finally {
467
+ m.value = !1;
468
+ }
469
+ }
470
+ }
471
+ function B(o) {
472
+ d.value = d.value.map((n) => n._id === o._id ? {
473
+ ...o,
474
+ _rev: n._rev
475
+ } : n);
476
+ }
477
+ function T() {
478
+ e.closeDraftDialog(), U();
479
+ }
480
+ function E(o, n) {
481
+ switch (n = ut(n), o) {
482
+ case _e.Details:
483
+ return e.viewDraft(n);
484
+ case _e.Export:
485
+ return e.exportDraft(n);
486
+ case M.enum.approveDraft:
487
+ return e.approveDraft(n, T);
488
+ case M.enum.rejectDraft:
489
+ return e.rejectDraft(n, T);
490
+ case M.enum.markAsFailed:
491
+ return e.markAsFailed(n, T);
492
+ }
493
+ }
494
+ return {
495
+ columnDefs: [
496
+ {
497
+ id: "_id",
498
+ accessorKey: "_id",
499
+ header: () => l("inventory.closing.table.createdAt"),
500
+ cell(o) {
501
+ return ct(`${o.getValue()}`);
502
+ },
503
+ enableSorting: !0
504
+ },
505
+ {
506
+ id: "updatedAt",
507
+ accessorFn: (o) => re(o.updatedAt),
508
+ header: () => "Updated at",
509
+ enableSorting: !0,
510
+ size: 200
511
+ },
512
+ {
513
+ id: "updatedBy",
514
+ accessorKey: "updatedBy.name",
515
+ header: () => "Last update by",
516
+ enableSorting: !0,
517
+ size: 200
518
+ },
519
+ {
520
+ id: "noOfItems",
521
+ accessorFn: (o) => {
522
+ var n;
523
+ return o.items.length + (((n = o.negativeStockItems) == null ? void 0 : n.length) ?? 0);
524
+ },
525
+ header: () => l("inventory.closing.table.noOfItems"),
526
+ enableSorting: !1,
527
+ meta: {
528
+ width: "10rem",
529
+ textAlign: "right"
530
+ }
531
+ },
532
+ {
533
+ id: "recentRemark",
534
+ accessorFn: (o) => {
535
+ var n;
536
+ return (o == null ? void 0 : o.approveRemark) ?? ((n = o == null ? void 0 : o.rejectionHistory) == null ? void 0 : n.computeFirst((C) => C.rejectRemark)) ?? o.remark;
537
+ },
538
+ header: () => "Recent remark"
539
+ },
540
+ {
541
+ id: "status",
542
+ accessorFn: (o) => o.status,
543
+ header: () => l("inventory.closing.table.status"),
544
+ enableSorting: !1,
545
+ cell(o) {
546
+ var _;
547
+ const n = o.row.original, C = n.status, g = new Date(n.updatedAt), c = (_ = n == null ? void 0 : n.rejectionHistory) == null ? void 0 : _.computeFirst(($) => $.rejectedAt), H = c ? new Date(c) : null;
548
+ return C === "DRAFT" && H ? H.getTime() > g.getTime() ? F(
549
+ "div",
550
+ {
551
+ class: "flex"
552
+ },
553
+ F(
554
+ "div",
555
+ {
556
+ class: ["fm-status-badge", Ce("FAILED")]
557
+ },
558
+ "Rejected"
559
+ )
560
+ ) : F(
561
+ "div",
562
+ {
563
+ class: "flex"
564
+ },
565
+ F(
566
+ "div",
567
+ {
568
+ class: ["fm-status-badge", Ce("PROCESSING")]
569
+ },
570
+ "Updated"
571
+ )
572
+ ) : F(
573
+ "div",
574
+ {
575
+ class: "flex"
576
+ },
577
+ F(
578
+ "div",
579
+ {
580
+ class: ["fm-status-badge", Ce(C)]
581
+ },
582
+ Be(C)
583
+ )
584
+ );
585
+ }
586
+ },
587
+ {
588
+ id: "action",
589
+ cell(o) {
590
+ const n = o.row.original, C = [
591
+ Ue[_e.Details],
592
+ Ue[_e.Export]
593
+ ], g = [
594
+ {
595
+ translationKey: "inventory.closing.draft.approveDraft",
596
+ color: "text-fm-color-typo-primary",
597
+ value: M.enum.approveDraft
598
+ },
599
+ {
600
+ translationKey: "inventory.closing.draft.rejectDraft",
601
+ color: "text-fm-color-typo-error",
602
+ value: M.enum.rejectDraft
603
+ },
604
+ {
605
+ translationKey: "inventory.closing.draft.markAsFailed",
606
+ color: "text-fm-color-typo-error",
607
+ value: M.enum.markAsFailed
608
+ }
609
+ ];
610
+ return it(
611
+ [
612
+ ...C,
613
+ ...n.status === ne.enum.DRAFT ? g : []
614
+ ],
615
+ (c) => E(c, n)
616
+ );
617
+ },
618
+ enableSorting: !1,
619
+ size: 40,
620
+ meta: {
621
+ cellClass: "",
622
+ headerClass: ""
623
+ }
624
+ }
625
+ ],
626
+ drafts: d,
627
+ loading: m,
628
+ fetchDrafts: U,
629
+ loadDraft: y,
630
+ updateDraftRef: B
631
+ };
632
+ }
633
+ ), Pt = { class: "w-full flex flex-col gap-32" }, Ut = { class: "flex justify-between" }, It = { class: "flex" }, Lt = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, Et = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ht = { class: "flex gap-1" }, zt = { class: "fm-typo-en-body-lg-600" }, Nt = { class: "flex flex-col gap-16" }, Vt = { class: "flex items-center" }, Ot = {
634
+ key: 0,
635
+ class: "flex gap-8"
636
+ }, Yt = {
637
+ key: 0,
638
+ class: "w-full flex flex-col items-center"
639
+ }, Kt = { class: "flex items-center gap-8" }, Gt = {
640
+ key: 0,
641
+ class: "flex gap-8"
642
+ }, qt = { class: "overflow-x-auto" }, Wt = {
643
+ key: 1,
644
+ class: "flex-1 xs:w-screen xs:max-w-full"
645
+ }, Zt = {
646
+ key: 0,
647
+ class: "flex flex-col items-center gap-8 h-full"
648
+ }, Jt = ["src"], Qt = {
649
+ key: 1,
650
+ class: "px-4 flex flex-col"
651
+ }, Xt = { class: "flex gap-12 content-stretch" }, ea = {
652
+ class: "flex flex-col w-24",
653
+ name: "circles"
654
+ }, ta = { class: "flex-1 flex flex-col items-center" }, aa = { class: "flex-1 flex flex-col items-center" }, na = {
655
+ class: "py-12 flex flex-col gap-4",
656
+ name: "received-at header"
657
+ }, oa = { class: "fm-typo-en-body-lg-400" }, sa = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, ra = { class: "flex gap-12 content-stretch" }, la = {
658
+ class: "flex flex-col w-24",
659
+ name: "circles"
660
+ }, ca = { class: "flex-1 flex flex-col items-center" }, ia = {
661
+ class: "py-12 flex flex-col gap-4 flex-1",
662
+ name: "delivery details"
663
+ }, ua = { class: "flex flex-col gap-8" }, da = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, ma = { class: "flex flex-col gap-4" }, fa = { class: "flex gap-8" }, pa = /* @__PURE__ */ Te({
664
+ __name: "ClosingDraftDialog",
665
+ props: {
666
+ show: { type: Boolean },
667
+ draft: {}
668
+ },
669
+ emits: ["submitted", "refresh"],
670
+ setup(s, { emit: l }) {
671
+ const e = s, d = Ke(), m = je(), k = bt(e, "show"), p = N(!1), U = N(!1), y = N(!1), B = N(new Array()), T = Ye(), E = $e(), z = Me(), o = dt(), n = Se(), C = Ze({}), g = P(() => new Set(
672
+ o.skus.filter((a) => {
673
+ var t;
674
+ return C[(t = a.customAttributes) == null ? void 0 : t.tag];
675
+ }).map((a) => a._id)
676
+ )), c = l, H = P(() => {
677
+ var t, i;
678
+ const a = [...((t = e.draft) == null ? void 0 : t.items) ?? [], ...((i = e.draft) == null ? void 0 : i.negativeStockItems) ?? []];
679
+ return g.value.size ? a.filter((f) => g.value.has(f.sku._id)) : a;
680
+ }), _ = P(() => {
681
+ const a = H.value.map((t) => t.sku);
682
+ return a.sort((t, i) => t.code.localeCompare(i.code)), a;
683
+ }), $ = P(() => H.value.groupBy(
684
+ (t) => t.sku._id,
685
+ (t) => t.measurementsAmounts.filter((i) => !i.measurement.abbrev.toLocaleLowerCase().includes("inactive")).map((i) => i.measurement.id)
686
+ ));
687
+ Ie(te), Je(
688
+ () => e.show,
689
+ (a) => {
690
+ a && (W.value = ue[0], te());
691
+ }
692
+ );
693
+ const j = Ae(0), K = Ae(100);
694
+ async function te() {
695
+ var t, i, f;
696
+ if (!n._currentLocation) return;
697
+ p.value = !0;
698
+ const a = ((t = e.draft) == null ? void 0 : t.status) === ne.enum.COMPLETED;
699
+ try {
700
+ if (await o.init(), a) {
701
+ const u = e.draft.closingAdjustmentId;
702
+ if (!u) {
703
+ z.open({
704
+ title: "Something went wrong",
705
+ message: "Closing draft is completed but closing document cannot be found.",
706
+ type: "error"
707
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
708
+ draftId: (i = e.draft) == null ? void 0 : i._id
709
+ });
710
+ return;
711
+ }
712
+ const v = await T.readAdjustmentById(u), b = (v == null ? void 0 : v.skus) ?? [];
713
+ B.value = b.map((h) => ({
714
+ id: h.sku._id,
715
+ balance: h.fromBalance,
716
+ costs: h.fromCostBalances
717
+ }));
718
+ } else
719
+ B.value = ((f = e.draft) == null ? void 0 : f.stockSnapshot) ?? [];
720
+ } catch (u) {
721
+ z.open({
722
+ title: "Something went wrong",
723
+ message: "Something went wrong when fetching info. Please try again.",
724
+ type: "error"
725
+ }), console.error("error on fetch stock balances", u);
726
+ } finally {
727
+ p.value = !1;
728
+ }
729
+ }
730
+ async function X() {
731
+ var u, v, b;
732
+ const a = ((u = e.draft) == null ? void 0 : u.effectiveAt) ?? ((v = e.draft) == null ? void 0 : v.updatedAt);
733
+ if (!a) {
734
+ z.open({
735
+ title: "Cannot refresh",
736
+ message: "Effective date is not available for this draft.",
737
+ type: "error"
738
+ });
739
+ return;
740
+ }
741
+ U.value = !0;
742
+ const t = (b = e.draft) == null ? void 0 : b._rev, i = 30, f = 2e3;
743
+ try {
744
+ await T.recalculation.scheduleCalculateStockSnapshotAtDate(
745
+ a,
746
+ e.draft._id
747
+ );
748
+ let h = null;
749
+ for (let w = 0; w < i && (h = await E.getDraft(e.draft._id).delayed(f), h._rev === t); w++)
750
+ ;
751
+ if (!h || h._rev === t) {
752
+ z.open({
753
+ title: "Refresh failed",
754
+ message: "Failed to refresh stock balance. Please try again.",
755
+ type: "error"
756
+ }), console.error("error refreshing stock balances: there is no change in _rev");
757
+ return;
758
+ }
759
+ c("refresh", h), B.value = h.stockSnapshot ?? [], z.open({
760
+ title: "Balance refreshed",
761
+ message: "Stock balance has been recalculated.",
762
+ type: "success"
763
+ });
764
+ } catch (h) {
765
+ z.open({
766
+ title: "Refresh failed",
767
+ message: "Failed to refresh stock balance. Please try again.",
768
+ type: "error"
769
+ }), console.error("error refreshing stock balances", h);
770
+ } finally {
771
+ U.value = !1;
772
+ }
773
+ }
774
+ const oe = P(
775
+ () => B.value.groupBy(
776
+ (a) => a.id,
777
+ (a) => a.balance
778
+ )
779
+ ), De = P(() => H.value.groupBy((a) => a.sku._id));
780
+ function le(a) {
781
+ return F(
782
+ fe.FmTooltip,
783
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
784
+ {
785
+ default() {
786
+ return a;
787
+ },
788
+ content() {
789
+ return "Differences are calculated using this formula: (Adjusted / System) × 100%";
790
+ }
791
+ }
792
+ );
793
+ }
794
+ const ye = P(() => {
795
+ const a = _.value.reduce((i, f) => {
796
+ var u, v;
797
+ return Math.max(i, ((v = (u = $.value) == null ? void 0 : u.get(f._id)) == null ? void 0 : v[0].length) ?? 0);
798
+ }, 0);
799
+ return [
800
+ {
801
+ id: "sku",
802
+ accessorFn: (i) => `${i.code} ${i.name}`,
803
+ header: () => "Name",
804
+ size: 350,
805
+ cell(i) {
806
+ const f = i.row.original, u = f.adjustedDiffPercentage, v = typeof u == "number" && Math.abs(u) > 10, b = F("div", { class: "flex flex-col gap-4" }, [
807
+ F(
808
+ "div",
809
+ {
810
+ class: [
811
+ "line-clamp-1 fm-typo-en-body-lg-400",
812
+ v ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
813
+ ]
814
+ },
815
+ f.name
816
+ ),
817
+ F(
818
+ "div",
819
+ {
820
+ class: [
821
+ "line-clamp-1 fm-typo-en-body-md-400",
822
+ v ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
823
+ ]
824
+ },
825
+ f.code
826
+ )
827
+ ]);
828
+ return F(
829
+ fe.FmTooltip,
830
+ {
831
+ zIndex: 51
832
+ },
833
+ {
834
+ content() {
835
+ return v ? "Adjustment difference is more than 10%." : `${f.code} - ${f.name}`;
836
+ },
837
+ default() {
838
+ return F("div", { class: "flex items-center gap-4 justify-start w-full" }, [
839
+ b
840
+ ]);
841
+ }
842
+ }
843
+ );
844
+ }
845
+ },
846
+ {
847
+ id: "baseUnit",
848
+ header: () => "Base unit",
849
+ accessorKey: "baseUnit"
850
+ },
851
+ {
852
+ id: "physicalBalance",
853
+ accessorKey: "physicalBalance",
854
+ header: () => le("Actual balance"),
855
+ size: 200,
856
+ meta: {
857
+ textAlign: "right"
858
+ }
859
+ },
860
+ {
861
+ id: "systemBalance",
862
+ accessorKey: "systemBalance",
863
+ header: () => le("Balance"),
864
+ size: 200,
865
+ meta: {
866
+ textAlign: "right"
867
+ }
868
+ },
869
+ {
870
+ id: "adjustedAmount",
871
+ accessorKey: "adjustedAmount",
872
+ header: () => le("Adjusted balance"),
873
+ size: 200,
874
+ meta: {
875
+ textAlign: "right"
876
+ }
877
+ },
878
+ {
879
+ id: "adjustedDiffPercentage",
880
+ accessorKey: "adjustedDiffPercentage",
881
+ header: () => F(
882
+ fe.FmTooltip,
883
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
884
+ {
885
+ default() {
886
+ return F("div", { class: "flex items-center gap-4" }, [
887
+ "Diff (%)",
888
+ F(fe.FmIcon, { name: "info", color: "neutral-gray-400", size: "sm" })
889
+ ]);
890
+ },
891
+ content() {
892
+ return "Differences are calculated using this formula: (Adjusted / System) × 100%";
893
+ }
894
+ }
895
+ ),
896
+ size: 200,
897
+ cell(i) {
898
+ const f = i.row.original.adjustedDiffPercentage;
899
+ if (!f) return "N/A";
900
+ const u = f.toFixed(2);
901
+ if (u === "0.00")
902
+ return F("div", { class: "flex items-center gap-4 justify-end" }, ["0.00"]);
903
+ const v = f > 0;
904
+ return F("div", { class: "flex items-center gap-4 justify-end" }, [
905
+ F(fe.FmIcon, {
906
+ name: v ? "arrow_drop_up" : "arrow_drop_down",
907
+ color: v ? "system-success-300" : "system-error-300",
908
+ size: "md"
909
+ }),
910
+ u
911
+ ]);
912
+ },
913
+ meta: {
914
+ textAlign: "right"
915
+ }
916
+ },
917
+ {
918
+ id: "physicalBalances",
919
+ header: () => "Amounts",
920
+ enableSorting: !1,
921
+ cell(i) {
922
+ const f = i.row.original, u = (b, h) => F(
923
+ fe.FmTooltip,
924
+ { zIndex: 50 },
925
+ {
926
+ default() {
927
+ return F(
928
+ "div",
929
+ {
930
+ 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"
931
+ },
932
+ [
933
+ F("span", { class: "text-fm-color-typo-primary" }, `${b} `),
934
+ F(
935
+ "span",
936
+ {
937
+ class: "text-fm-color-typo-secondary",
938
+ style: { maxWidth: "80px" }
939
+ },
940
+ h
941
+ )
942
+ ]
943
+ );
944
+ },
945
+ content() {
946
+ return `${b} ${h}`;
947
+ }
948
+ }
949
+ );
950
+ let v = Array.from({ length: a }).map((b, h) => {
951
+ if (!f[`measurementAmount${h}`])
952
+ return null;
953
+ const w = f[`measurementAmount${h}`], de = f[`measurementAbbrev${h}`];
954
+ return u(w, de);
955
+ }).filter((b) => b);
956
+ return (f.baseUnitAmount || !v.length) && (v = [u(f.baseUnitAmount, f.baseUnit), ...v]), F(
957
+ "div",
958
+ {
959
+ class: "flex gap-8 flex-nowrap",
960
+ style: {
961
+ minWidth: `${120 * v.length}px`
962
+ }
963
+ },
964
+ v
965
+ );
966
+ }
967
+ }
968
+ ];
969
+ }), ce = P(() => ye.value.map((a) => a.size ?? 0).reduce((a, t) => a + t)), ie = N(""), ge = P(() => _.value.map((a) => {
970
+ var w, de;
971
+ const t = (w = De.value.get(a._id)) == null ? void 0 : w[0], i = ((de = oe.value.get(a._id)) == null ? void 0 : de[0]) ?? j;
972
+ if (!t)
973
+ return {
974
+ code: a.code,
975
+ name: a.name,
976
+ baseUnit: a.unit.abbrev,
977
+ baseUnitAmount: 0,
978
+ systemBalance: +L(i),
979
+ physicalBalance: 0,
980
+ adjustedAmount: -+L(i),
981
+ adjustedDiffPercentage: -100
982
+ };
983
+ const f = Ge(t), u = He(f, i), v = i.amount === 0 ? null : ze(u, {
984
+ ...i,
985
+ amount: Math.abs(i.amount)
986
+ }), b = v ? Re(v, K) : null;
987
+ return {
988
+ code: a.code,
989
+ name: a.name,
990
+ baseUnit: a.unit.abbrev,
991
+ baseUnitAmount: +L(t.baseAmount),
992
+ ...t.measurementsAmounts.filter((ae) => {
993
+ var Z, se, xe;
994
+ return (xe = (se = (Z = $.value) == null ? void 0 : Z.get(a._id)) == null ? void 0 : se[0]) == null ? void 0 : xe.includes(ae.measurement.id);
995
+ }).reduce((ae, Z, se) => (ae[`measurementAbbrev${se}`] = `(${Z.measurement.abbrev}) × ${L(Z.measurement.conversion)}`, ae[`measurementAmount${se}`] = +L(Z.amount), ae), {}),
996
+ systemBalance: +L(i),
997
+ physicalBalance: +L(f),
998
+ adjustedAmount: +L(u),
999
+ adjustedDiffPercentage: b ? +L(Ne(b, 2)) : null
1000
+ };
1001
+ })), ke = P(() => {
1002
+ var t, i, f;
1003
+ if (!e.draft) return [];
1004
+ const a = e.draft.approvedAt ? {
1005
+ action: `Approve at ${re(e.draft.approvedAt)}`,
1006
+ // actionAt: props.draft.approvedAt,
1007
+ actionBy: e.draft.approvedBy,
1008
+ remark: e.draft.approveRemark
1009
+ } : (t = e.draft.rejectionHistory) == null ? void 0 : t.computeFirst((u) => ({
1010
+ action: `Reject at ${re(u.rejectedAt)}`,
1011
+ // actionAt: e.rejectedAt,
1012
+ actionBy: u.rejectedBy,
1013
+ remark: u.rejectRemark
1014
+ }));
1015
+ return [
1016
+ {
1017
+ label: "Created at",
1018
+ value: re(e.draft.createdAt)
1019
+ },
1020
+ {
1021
+ label: "Created by",
1022
+ value: e.draft.createdBy.name
1023
+ },
1024
+ {
1025
+ label: "Updated at",
1026
+ value: re(e.draft.updatedAt)
1027
+ },
1028
+ {
1029
+ label: "Updated by",
1030
+ value: e.draft.updatedBy.name
1031
+ },
1032
+ {
1033
+ label: "Effective at",
1034
+ value: re(e.draft.effectiveAt ?? e.draft.updatedAt)
1035
+ },
1036
+ {
1037
+ label: "Using template",
1038
+ value: ((i = e.draft.usingTemplates.find((u) => u)) == null ? void 0 : i.name) ?? "None"
1039
+ },
1040
+ e.draft.remark ? {
1041
+ label: "Remark",
1042
+ value: e.draft.remark
1043
+ } : null,
1044
+ a ? {
1045
+ label: "Last action",
1046
+ value: a.action
1047
+ } : null,
1048
+ a && a.actionBy ? {
1049
+ label: "Last action by",
1050
+ value: (f = a.actionBy) == null ? void 0 : f.name
1051
+ } : null,
1052
+ a && a.remark ? {
1053
+ label: "Action remark",
1054
+ value: a.remark
1055
+ } : null
1056
+ ].filter((u) => u).map((u) => u);
1057
+ }), ue = [
1058
+ {
1059
+ label: "Overview",
1060
+ value: "overview"
1061
+ },
1062
+ {
1063
+ label: "Action history",
1064
+ value: "history"
1065
+ }
1066
+ ], W = N(ue[0]), ee = P(() => {
1067
+ var f, u, v;
1068
+ const a = ((f = e.draft) == null ? void 0 : f.activityLogs) ?? [], t = ((u = e.draft) == null ? void 0 : u.rejectionHistory) ?? [];
1069
+ for (const b of t)
1070
+ a.find(
1071
+ (w) => `${w.action}_${w.performedAt}` == `${M.enum.rejectDraft}_${b.rejectedAt}`
1072
+ ) || a.push({
1073
+ action: M.enum.rejectDraft,
1074
+ performedAt: b.rejectedAt,
1075
+ performedBy: b.rejectedBy,
1076
+ remark: b.rejectRemark
1077
+ });
1078
+ return (v = e.draft) != null && v.approvedAt && (a.find(
1079
+ (h) => {
1080
+ var w;
1081
+ return `${h.action}_${h.performedAt}` == `${M.enum.approveDraft}_${(w = e.draft) == null ? void 0 : w.approvedAt}`;
1082
+ }
1083
+ ) || a.push({
1084
+ action: M.enum.approveDraft,
1085
+ performedAt: e.draft.approvedAt,
1086
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
1087
+ remark: e.draft.approveRemark
1088
+ })), a.sort((b, h) => new Date(h.performedAt).getTime() - new Date(b.performedAt).getTime()).map(
1089
+ (b) => ({
1090
+ header: Be(b.action),
1091
+ date: re(b.performedAt),
1092
+ info: [
1093
+ {
1094
+ label: "Performed by",
1095
+ values: [b.performedBy.name]
1096
+ },
1097
+ {
1098
+ label: "Remark",
1099
+ values: [b.remark ?? ""]
1100
+ }
1101
+ ]
1102
+ })
1103
+ );
1104
+ }), be = P(() => {
1105
+ var u, v, b, h;
1106
+ if ((u = e == null ? void 0 : e.draft) != null && u.approvedAt) return "Draft is already approved.";
1107
+ if (((v = e.draft) == null ? void 0 : v.status) !== ne.enum.DRAFT) return "Status is not draft.";
1108
+ const a = ge.value.some((w) => w.physicalBalance < 0), t = ((h = (b = d.stockBalance.skus) == null ? void 0 : b.filter((w) => w.balance.amount < 0)) == null ? void 0 : h.map((w) => w.id)) ?? [], i = new Set(_.value.map((w) => w._id)), f = t.filter((w) => !i.has(w)).length;
1109
+ return [
1110
+ a ? "Negative total exist." : null,
1111
+ f ? "Negative stock is not included in this draft. Reopen draft in POS and apply changes." : null
1112
+ ].filter((w) => w).join(" ");
1113
+ });
1114
+ return (a, t) => {
1115
+ const i = I("FmButtonGroup"), f = I("FmMenuDivider"), u = I("FmCard"), v = I("FmButton"), b = I("FmCircularProgress"), h = I("FmTextField"), w = I("FmIcon"), de = I("FmChip"), ae = I("FmTable"), Z = I("FmSpacer"), se = I("FmTooltip"), xe = I("FmSideSheet");
1116
+ return A(), Q(xe, {
1117
+ "dismiss-away": "",
1118
+ "max-width": 9999,
1119
+ "model-value": D(k),
1120
+ "onUpdate:modelValue": t[8] || (t[8] = (S) => Le(k) ? k.value = S : null),
1121
+ header: "Closing details"
1122
+ }, {
1123
+ "side-sheet-footer": Y(() => {
1124
+ var S, V, G, me;
1125
+ return [
1126
+ r("div", fa, [
1127
+ ((S = e.draft) == null ? void 0 : S.status) === D(ne).enum.DRAFT ? (A(), R(q, { key: 0 }, [
1128
+ be.value ? (A(), Q(se, {
1129
+ key: 0,
1130
+ "z-index": 51
1131
+ }, {
1132
+ content: Y(() => [
1133
+ pe(O(be.value), 1)
1134
+ ]),
1135
+ default: Y(() => [
1136
+ x(v, {
1137
+ disabled: "",
1138
+ key: "approve key",
1139
+ label: "Approve",
1140
+ onClick: t[3] || (t[3] = () => e.draft && D(m).approveDraft(e.draft, () => c("submitted")))
1141
+ })
1142
+ ]),
1143
+ _: 1
1144
+ })) : (A(), Q(v, {
1145
+ key: "approve key",
1146
+ label: "Approve",
1147
+ onClick: t[4] || (t[4] = () => e.draft && D(m).approveDraft(e.draft, () => c("submitted")))
1148
+ }))
1149
+ ], 64)) : J("", !0),
1150
+ ((V = e.draft) == null ? void 0 : V.status) === D(ne).enum.DRAFT ? (A(), Q(v, {
1151
+ key: 1,
1152
+ label: "Reject",
1153
+ variant: "destructive",
1154
+ onClick: t[5] || (t[5] = () => e.draft && D(m).rejectDraft(e.draft, () => c("submitted")))
1155
+ })) : J("", !0),
1156
+ (G = e.draft) != null && G.approvedAt && ((me = e.draft) == null ? void 0 : me.status) !== D(ne).enum.COMPLETED ? (A(), Q(v, {
1157
+ key: 2,
1158
+ label: "Sync",
1159
+ loading: y.value,
1160
+ onClick: t[6] || (t[6] = () => {
1161
+ e.draft && (y.value = !0, D(m).syncDraft(e.draft, () => {
1162
+ y.value = !1, c("submitted");
1163
+ }));
1164
+ })
1165
+ }, null, 8, ["loading"])) : J("", !0),
1166
+ x(v, {
1167
+ label: "Close",
1168
+ variant: "tertiary",
1169
+ onClick: t[7] || (t[7] = (Pe) => k.value = !1)
1170
+ })
1171
+ ])
1172
+ ];
1173
+ }),
1174
+ default: Y(() => [
1175
+ r("div", Pt, [
1176
+ r("div", null, [
1177
+ x(i, {
1178
+ items: ue,
1179
+ modelValue: W.value,
1180
+ "onUpdate:modelValue": t[0] || (t[0] = (S) => W.value = S)
1181
+ }, null, 8, ["modelValue"])
1182
+ ]),
1183
+ W.value.value === "overview" ? (A(), R(q, { key: 0 }, [
1184
+ x(u, {
1185
+ variant: "outlined",
1186
+ class: "flex flex-col gap-8 px-12 py-16"
1187
+ }, {
1188
+ default: Y(() => {
1189
+ var S, V;
1190
+ return [
1191
+ r("div", Ut, [
1192
+ t[9] || (t[9] = r("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
1193
+ r("div", It, [
1194
+ r("div", {
1195
+ class: ve(["fm-status-badge", D(Ce)(((S = a.draft) == null ? void 0 : S.status) ?? "DRAFT")])
1196
+ }, O(D(Be)(((V = a.draft) == null ? void 0 : V.status) ?? "")), 3)
1197
+ ])
1198
+ ]),
1199
+ x(f),
1200
+ r("div", Lt, [
1201
+ (A(!0), R(q, null, he(ke.value, (G, me) => (A(), R("div", {
1202
+ class: "flex flex-col gap-4",
1203
+ key: me
1204
+ }, [
1205
+ r("div", Et, [
1206
+ r("div", Ht, O(G.label), 1)
1207
+ ]),
1208
+ r("div", zt, O(G.value), 1)
1209
+ ]))), 128))
1210
+ ])
1211
+ ];
1212
+ }),
1213
+ _: 1
1214
+ }),
1215
+ r("div", Nt, [
1216
+ r("div", Vt, [
1217
+ t[10] || (t[10] = r("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
1218
+ p.value ? J("", !0) : (A(), R("div", Ot, [
1219
+ a.draft && a.draft.status !== D(ne).enum.COMPLETED ? (A(), Q(v, {
1220
+ key: 0,
1221
+ label: "Refresh balance",
1222
+ "prepend-icon": "refresh",
1223
+ variant: "secondary",
1224
+ "text-color": "primary",
1225
+ "bg-color": "transparent",
1226
+ "border-color": "primary",
1227
+ loading: U.value,
1228
+ onClick: X
1229
+ }, null, 8, ["loading"])) : J("", !0),
1230
+ x(v, {
1231
+ label: "Export data",
1232
+ "prepend-icon": "download",
1233
+ variant: "secondary",
1234
+ "text-color": "primary",
1235
+ "bg-color": "transparent",
1236
+ "border-color": "primary",
1237
+ onClick: t[1] || (t[1] = (S) => a.draft ? D(m).exportDraft(a.draft, B.value) : null)
1238
+ })
1239
+ ]))
1240
+ ]),
1241
+ p.value ? (A(), R("div", Yt, [
1242
+ t[12] || (t[12] = r("div", { class: "h-80" }, null, -1)),
1243
+ r("div", Kt, [
1244
+ r("div", null, [
1245
+ x(b, { size: "md" })
1246
+ ]),
1247
+ t[11] || (t[11] = r("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
1248
+ ]),
1249
+ t[13] || (t[13] = r("div", { class: "h-80" }, null, -1))
1250
+ ])) : (A(), R(q, { key: 1 }, [
1251
+ r("div", null, [
1252
+ x(h, {
1253
+ modelValue: ie.value,
1254
+ "onUpdate:modelValue": t[2] || (t[2] = (S) => ie.value = S),
1255
+ placeholder: "Filter items"
1256
+ }, null, 8, ["modelValue"])
1257
+ ]),
1258
+ D(o).skuTags.size ? (A(), R("div", Gt, [
1259
+ (A(!0), R(q, null, he(D(o).skuTags.keys(), (S) => (A(), Q(de, {
1260
+ key: `${S}`,
1261
+ label: `${S}`,
1262
+ selectable: "",
1263
+ selected: C[`${S}`],
1264
+ onClick: (V) => C[`${S}`] = !C[`${S}`]
1265
+ }, {
1266
+ default: Y(() => [
1267
+ C[`${S}`] ? (A(), Q(w, {
1268
+ key: 0,
1269
+ name: "check",
1270
+ class: "text-white",
1271
+ size: "sm"
1272
+ })) : J("", !0),
1273
+ r("span", {
1274
+ class: ve([
1275
+ "",
1276
+ {
1277
+ "text-white fm-typo-en-body-md-600": C[`${S}`],
1278
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !C[`${S}`]
1279
+ }
1280
+ ])
1281
+ }, O(S), 3)
1282
+ ]),
1283
+ _: 2
1284
+ }, 1032, ["label", "selected", "onClick"]))), 128))
1285
+ ])) : J("", !0),
1286
+ r("div", qt, [
1287
+ r("div", {
1288
+ style: Ee({ minWidth: `${ce.value}px` })
1289
+ }, [
1290
+ x(ae, {
1291
+ "column-defs": ye.value,
1292
+ "row-data": ge.value,
1293
+ "search-value": ie.value
1294
+ }, null, 8, ["column-defs", "row-data", "search-value"])
1295
+ ], 4)
1296
+ ])
1297
+ ], 64))
1298
+ ])
1299
+ ], 64)) : J("", !0),
1300
+ W.value.value === "history" ? (A(), R("div", Wt, [
1301
+ ee.value.length ? (A(), R("div", Qt, [
1302
+ (A(!0), R(q, null, he(ee.value, (S, V) => (A(), R(q, { key: V }, [
1303
+ r("div", Xt, [
1304
+ r("div", ea, [
1305
+ r("div", ta, [
1306
+ r("div", {
1307
+ class: ve([
1308
+ {
1309
+ "bg-fm-color-primary": V !== 0,
1310
+ "bg-white": V === 0
1311
+ },
1312
+ "w-[2px] h-full"
1313
+ ])
1314
+ }, null, 2)
1315
+ ]),
1316
+ t[16] || (t[16] = r("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
1317
+ r("div", aa, [
1318
+ r("div", {
1319
+ class: ve([
1320
+ {
1321
+ "bg-fm-color-primary": V < ee.value.length - 1,
1322
+ "bg-white": V >= ee.value.length - 1
1323
+ },
1324
+ "w-[2px] h-full"
1325
+ ])
1326
+ }, null, 2)
1327
+ ])
1328
+ ]),
1329
+ r("div", na, [
1330
+ r("div", oa, O(S.header), 1),
1331
+ r("div", sa, O(S.date), 1)
1332
+ ])
1333
+ ]),
1334
+ r("div", ra, [
1335
+ r("div", la, [
1336
+ r("div", ca, [
1337
+ r("div", {
1338
+ class: ve([
1339
+ {
1340
+ "bg-fm-color-primary": V < ee.value.length - 1,
1341
+ "bg-white": V >= ee.value.length - 1
1342
+ },
1343
+ "w-[2px] h-full"
1344
+ ])
1345
+ }, null, 2)
1346
+ ])
1347
+ ]),
1348
+ r("div", ia, [
1349
+ x(u, {
1350
+ variant: "outlined",
1351
+ class: "py-12 px-16"
1352
+ }, {
1353
+ default: Y(() => [
1354
+ r("div", ua, [
1355
+ (A(!0), R(q, null, he(S.info, (G, me) => (A(), R("div", {
1356
+ key: me,
1357
+ class: "flex flex-col gap-4"
1358
+ }, [
1359
+ r("div", da, O(G == null ? void 0 : G.label), 1),
1360
+ r("div", ma, [
1361
+ (A(!0), R(q, null, he(G == null ? void 0 : G.values, (Pe, We) => (A(), R("div", {
1362
+ key: We,
1363
+ class: "fm-typo-en-body-lg-600"
1364
+ }, O(Pe), 1))), 128))
1365
+ ])
1366
+ ]))), 128))
1367
+ ])
1368
+ ]),
1369
+ _: 2
1370
+ }, 1024)
1371
+ ])
1372
+ ])
1373
+ ], 64))), 128))
1374
+ ])) : (A(), R("div", Zt, [
1375
+ x(Z),
1376
+ r("div", null, [
1377
+ r("img", {
1378
+ src: D(Dt),
1379
+ alt: "List is empty"
1380
+ }, null, 8, Jt)
1381
+ ]),
1382
+ t[14] || (t[14] = r("div", { class: "fm-typo-en-body-lg-600" }, O("No records found"), -1)),
1383
+ t[15] || (t[15] = r("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, O("You can track approval and rejection history here"), -1)),
1384
+ x(Z),
1385
+ x(Z)
1386
+ ]))
1387
+ ])) : J("", !0)
1388
+ ])
1389
+ ]),
1390
+ _: 1
1391
+ }, 8, ["model-value"]);
1392
+ };
1393
+ }
1394
+ }), va = { class: "flex-1 flex flex-col gap-8" }, ya = { class: "flex flex-col" }, ga = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, ba = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, ha = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Aa = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Sa = /* @__PURE__ */ Te({
1395
+ __name: "ClosingDraftView",
1396
+ setup(s) {
1397
+ const { t: l } = Ve(), { viewDraft: e } = je(), { viewClosingDraftProps: d, viewClosingDraftShow: m } = At(je()), k = Se(), p = Mt(), U = mt(), { breakpoints: y } = ht();
1398
+ k.watchLocation(p.fetchDrafts);
1399
+ const B = P(() => p.loading), T = N(""), E = P(() => y.value.xs || y.value.sm), z = P(() => E.value ? 10 : 20);
1400
+ function o(g) {
1401
+ switch (g) {
1402
+ case "refresh":
1403
+ return p.fetchDrafts();
1404
+ }
1405
+ }
1406
+ function n(g) {
1407
+ return g;
1408
+ }
1409
+ const C = P(() => E.value ? [
1410
+ {
1411
+ label: l("inventory.common.refresh"),
1412
+ value: "refresh",
1413
+ isPrimary: !1
1414
+ }
1415
+ ] : [
1416
+ {
1417
+ label: l("inventory.common.refresh"),
1418
+ value: "refresh",
1419
+ isPrimary: !1
1420
+ }
1421
+ ]);
1422
+ return (g, c) => {
1423
+ const H = I("FmTable");
1424
+ return A(), R(q, null, [
1425
+ x(ft, {
1426
+ title: D(l)("inventory.closing.draft.title"),
1427
+ actions: C.value,
1428
+ "onClick:action": o
1429
+ }, {
1430
+ default: Y(() => [
1431
+ r("div", {
1432
+ class: ve([
1433
+ "flex flex-col gap-8 max-h-full",
1434
+ {
1435
+ "p-0": E.value,
1436
+ "px-24 ": !E.value
1437
+ }
1438
+ ])
1439
+ }, [
1440
+ x(pt, {
1441
+ "change-location": "",
1442
+ searchable: "",
1443
+ search: T.value,
1444
+ "onUpdate:search": c[0] || (c[0] = (_) => T.value = _)
1445
+ }, null, 8, ["search"]),
1446
+ x(H, {
1447
+ style: Ee(D(U).tableHeight),
1448
+ "column-defs": D(p).columnDefs,
1449
+ "row-data": D(p).drafts,
1450
+ "search-value": T.value,
1451
+ loading: B.value,
1452
+ onRowClick: c[1] || (c[1] = (_) => D(e)(_.original)),
1453
+ "page-size": z.value
1454
+ }, {
1455
+ "list-row": Y((_) => [
1456
+ x(vt, {
1457
+ row: _,
1458
+ onRowClick: ($) => D(e)($)
1459
+ }, {
1460
+ default: Y(($) => {
1461
+ var j, K, te, X, oe, De, le, ye, ce, ie, ge, ke, ue, W, ee, be, a, t, i, f;
1462
+ return [
1463
+ r("div", va, [
1464
+ r("div", ya, [
1465
+ r("div", ga, [
1466
+ x(D(we), {
1467
+ render: (te = (K = (j = $._id) == null ? void 0 : j.column) == null ? void 0 : K.columnDef) == null ? void 0 : te.cell,
1468
+ props: (oe = (X = $._id) == null ? void 0 : X.getContext) == null ? void 0 : oe.call(X)
1469
+ }, null, 8, ["render", "props"])
1470
+ ]),
1471
+ r("div", ba, [
1472
+ x(D(we), {
1473
+ render: (ye = (le = (De = $.name) == null ? void 0 : De.column) == null ? void 0 : le.columnDef) == null ? void 0 : ye.cell,
1474
+ props: (ie = (ce = $.name) == null ? void 0 : ce.getContext) == null ? void 0 : ie.call(ce)
1475
+ }, null, 8, ["render", "props"])
1476
+ ]),
1477
+ r("div", ha, O([
1478
+ ..._.original.items.slice(0, 3).map((u) => u.sku.name),
1479
+ ..._.original.items.length >= 3 ? [`and ${_.original.items.length - 3} more items`] : []
1480
+ ].join(", ")), 1),
1481
+ r("div", Aa, [
1482
+ x(D(we), {
1483
+ render: (ue = (ke = (ge = $.ref) == null ? void 0 : ge.column) == null ? void 0 : ke.columnDef) == null ? void 0 : ue.cell,
1484
+ props: (ee = (W = $.ref) == null ? void 0 : W.getContext) == null ? void 0 : ee.call(W)
1485
+ }, null, 8, ["render", "props"])
1486
+ ])
1487
+ ]),
1488
+ r("div", null, [
1489
+ x(D(we), {
1490
+ render: (t = (a = (be = $.status) == null ? void 0 : be.column) == null ? void 0 : a.columnDef) == null ? void 0 : t.cell,
1491
+ props: (f = (i = $.status) == null ? void 0 : i.getContext) == null ? void 0 : f.call(i)
1492
+ }, null, 8, ["render", "props"])
1493
+ ])
1494
+ ])
1495
+ ];
1496
+ }),
1497
+ _: 2
1498
+ }, 1032, ["row", "onRowClick"])
1499
+ ]),
1500
+ _: 1
1501
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"])
1502
+ ], 2)
1503
+ ]),
1504
+ _: 1
1505
+ }, 8, ["title", "actions"]),
1506
+ (A(), Q(Qe, { to: "body" }, [
1507
+ x(pa, Xe(D(d), {
1508
+ show: D(m),
1509
+ "onUpdate:show": c[2] || (c[2] = (_) => Le(m) ? m.value = _ : null),
1510
+ onSubmitted: c[3] || (c[3] = () => (m.value = !1, D(p).fetchDrafts())),
1511
+ onRefresh: c[4] || (c[4] = (_) => D(p).updateDraftRef(_))
1512
+ }), null, 16, ["show"])
1513
+ ]))
1514
+ ], 64);
1515
+ };
1516
+ }
1517
+ });
1518
+ export {
1519
+ Sa as default
1520
+ };