@feedmepos/mf-inventory-portal 1.3.9-dev.2 → 1.3.10

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 (87) hide show
  1. package/dist/{App-BdI67_JN.js → App-AMCLoiCx.js} +3 -3
  2. package/dist/{ApprovalView-B1NNaLLy.js → ApprovalView-Ck5sbwhv.js} +7 -7
  3. package/dist/{BindingsDialog-jE-dghzD.js → BindingsDialog-E5UFxBQJ.js} +2 -2
  4. package/dist/{BindingsPicker-BjzQVedz.js → BindingsPicker-Dtm9YX11.js} +2 -2
  5. package/dist/{BindingsTable-BeNHq3Cs.js → BindingsTable-Bl2Oy_78.js} +3 -3
  6. package/dist/ClosingDraftView-BBJPae1z.js +2460 -0
  7. package/dist/ClosingHistoryView-B0Ceyn5l.js +1099 -0
  8. package/dist/{ClosingTemplateView-BUjDyYGl.js → ClosingTemplateView-B0nxOAiX.js} +14 -14
  9. package/dist/{DeliveryOrderPrintPreview-Czt1MLZ_.js → DeliveryOrderPrintPreview-Ca0H1Ohm.js} +2 -2
  10. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BHoMk9oO.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Bd4RuhVn.js} +3 -3
  11. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CSuTIhFr.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BhN9g4ed.js} +2 -2
  12. package/dist/{FmMultiselectDialog-_mQIndQU.js → FmMultiselectDialog-Cth3pVpH.js} +2 -2
  13. package/dist/{FmMultiselectDialog-CLjJFmL2.js → FmMultiselectDialog-D4gPja33.js} +1 -1
  14. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-Db3KL1J4.js → FmUnitInput.vue_vue_type_script_setup_true_lang-Ckg0Bk7q.js} +4 -4
  15. package/dist/{ImportView-Hmv8oOwi.js → ImportView-DNZHXGqI.js} +6 -6
  16. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-DJ74tTtu.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CtgvXj7S.js} +1 -1
  17. package/dist/{IngredientGroupView-D_fdrAir.js → IngredientGroupView-CJqntGUb.js} +5 -5
  18. package/dist/{IngredientsView-Ci5oxdy3.js → IngredientsView-rnlLpT0N.js} +15 -15
  19. package/dist/{IntegrationExplorerView-CVPV3V6E.js → IntegrationExplorerView-Df1bUIb_.js} +5 -5
  20. package/dist/{IntegrationView-8e450eho.js → IntegrationView-D7hpS7rk.js} +15 -15
  21. package/dist/{InventoryBindingForm-DQ8v7_rx.js → InventoryBindingForm-O2Aa9sTu.js} +1 -1
  22. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-B6EgVlRx.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-CNfQNVWa.js} +5 -5
  23. package/dist/{InventoryBindingSummary-CUQurNIf.js → InventoryBindingSummary-BeW6UPMa.js} +1 -1
  24. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-Gva5TitS.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CmkR9Kwv.js} +1 -1
  25. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-DWnVDWYN.js → PremiumBadge.vue_vue_type_script_setup_true_lang-8HEq6wUL.js} +1 -1
  26. package/dist/{PublishView-BOqcyvXi.js → PublishView-BWVQj7KV.js} +3 -3
  27. package/dist/{PurchaseOrderPrintPreview-BSmCNsRd.js → PurchaseOrderPrintPreview-Buu_XKZ6.js} +2 -2
  28. package/dist/{ReceiveRequestView-CSpbpF8o.js → ReceiveRequestView-BFMr29ao.js} +23 -23
  29. package/dist/{RecipeView-n8O74vm0.js → RecipeView-CKwIiPvs.js} +15 -15
  30. package/dist/{SettingsView-Cd-XI85I.js → SettingsView-D9sl-8ky.js} +6 -5
  31. package/dist/{StockView-C6EC-gfN.js → StockView-DW-XdEFn.js} +18 -18
  32. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CCDPVBEk.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CM68SEVE.js} +1 -1
  33. package/dist/{SupplierView-CIhoOaRm.js → SupplierView-cFigezy0.js} +12 -12
  34. package/dist/{SurchargeView-CMsPGwN6.js → SurchargeView-esXeVFYR.js} +6 -6
  35. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-Co-QAzlC.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-B6WHfp7s.js} +2 -2
  36. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-C-PNgED3.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-WkcGwhKF.js} +1 -1
  37. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-6hlwPSZr.js → TransferDetails.vue_vue_type_script_setup_true_lang-C6wgnpjA.js} +19 -19
  38. package/dist/{TransferTemplateView-Ba7bZICY.js → TransferTemplateView-ORJYkbik.js} +17 -17
  39. package/dist/{UnitCostHistoryView-BlpAzQC9.js → UnitCostHistoryView-lOjkEykk.js} +4 -4
  40. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-xiUvPYVX.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-DHP8-Qeq.js} +4 -4
  41. package/dist/{UnitView-BR0uGHcU.js → UnitView-BciDe30E.js} +7 -7
  42. package/dist/{WarehouseView-Cn8W93kO.js → WarehouseView-LrZMhOZ3.js} +5 -5
  43. package/dist/{WastageTemplateView-B3Rlhrgt.js → WastageTemplateView-_XtPd3w7.js} +14 -14
  44. package/dist/{app-Dbe7V63L.js → app-BwuCotIT.js} +47 -15
  45. package/dist/app.d.ts +32 -0
  46. package/dist/app.js +1 -1
  47. package/dist/{closing-template-C60HJnuG.js → closing-template-CrwrQRVT.js} +1 -1
  48. package/dist/{date2-DYdjU4Dj.js → date2-CN6oeiND.js} +1 -1
  49. package/dist/{dayjs.min-Dg5QmVd4.js → dayjs.min-DXr7vZ0q.js} +1 -1
  50. package/dist/{decimal-QkHGtq6S.js → decimal-cbUB1bNB.js} +2 -2
  51. package/dist/{defineDeepModel-DHKXLKo8.js → defineDeepModel-DbejVC8E.js} +1 -1
  52. package/dist/{duplicate-template-Dq4BRUUL.js → duplicate-template-UfjN1u1a.js} +1 -1
  53. package/dist/{export-DPp8BiEP.js → export-CgVMsyty.js} +1 -1
  54. package/dist/{feature-BK5cMjRG.js → feature-DvDCwJgX.js} +2 -2
  55. package/dist/{format-time-from-id-BpQopXAH.js → format-time-from-id-fDBus_Pv.js} +1 -1
  56. package/dist/{format-unit-display-Cd6ytcux.js → format-unit-display-DoSgnu6k.js} +11 -11
  57. package/dist/{import-export.helper-altzSoJ6.js → import-export.helper-BCgj8CQm.js} +6 -6
  58. package/dist/{index-CN0nHrpu.js → index-BA5L3Wrg.js} +1 -1
  59. package/dist/{index-BIpODgwB.js → index-DNiI_HP3.js} +3 -3
  60. package/dist/{index-CPiqET5G.js → index-bEeIRiah.js} +1 -1
  61. package/dist/{inventory-core-dart.default-D70169Bu.js → inventory-core-dart.default-DU0ShPuP.js} +6 -6
  62. package/dist/{lodash-Bxf-HD6Z.js → lodash-BGuKCADh.js} +1 -1
  63. package/dist/{lz-string-9T-4wD-Z.js → lz-string-DeRM387a.js} +1 -1
  64. package/dist/{netsuite-BKXgpKUj.js → netsuite-C42sBtDq.js} +3 -3
  65. package/dist/{number-8SeP62VA.js → number-C272zRB2.js} +3 -3
  66. package/dist/{predefined-templates-fq9IwL3Z.js → predefined-templates-BVtb9AuB.js} +1 -1
  67. package/dist/{purchase-order-template-B5nDbemx.js → purchase-order-template-Dit4HCbR.js} +1 -1
  68. package/dist/recalculationUtils-TOCl7HAN.js +93 -0
  69. package/dist/{rules-CkEGsMeN.js → rules-BWuA1LhO.js} +2 -2
  70. package/dist/{stock-gVGvyX7k.js → stock-OdR_zYes.js} +1 -1
  71. package/dist/{stock-6in8sQP7.js → stock-tStZ6BaN.js} +3 -3
  72. package/dist/{supplier-LPpRbpiG.js → supplier-J5zLFk0g.js} +2 -2
  73. package/dist/{surcharge-C6hh2TF1.js → surcharge-Opp82HwR.js} +1 -1
  74. package/dist/tsconfig.app.tsbuildinfo +1 -1
  75. package/dist/{use-ingredient-select-dialog-Cu-MKKsF.js → use-ingredient-select-dialog-Bj07pe0e.js} +2 -2
  76. package/dist/{use-inventory-binding-dialog-D_nkJQuf.js → use-inventory-binding-dialog-BrqmqQsH.js} +2 -2
  77. package/dist/{use-template-enabled-locations-VtfLGQ5g.js → use-template-enabled-locations-CJ0YnZF0.js} +2 -2
  78. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +178 -2502
  79. package/dist/views/integration/components/netsuite/business/AddLocationDialog.vue.d.ts +4 -22
  80. package/dist/views/integration/components/netsuite/business/AddVendorDialog.vue.d.ts +4 -22
  81. package/dist/views/stock/components/dialog/recalculationUtils.d.ts +13 -0
  82. package/dist/{vue-i18n-DCT1ZMkA.js → vue-i18n-Duedc0G3.js} +292 -292
  83. package/dist/{xlsx-B7ycJmBG.js → xlsx-BxSTEHnr.js} +398 -398
  84. package/dist/{xlsx.util-CaSNWKSp.js → xlsx.util-BytvgbQg.js} +1 -1
  85. package/package.json +2 -2
  86. package/dist/ClosingDraftView-CzEtmv80.js +0 -2423
  87. package/dist/ClosingHistoryView-BKF0J6Ks.js +0 -1158
@@ -0,0 +1,1099 @@
1
+ import { defineComponent as ne, ref as g, computed as D, watch as de, resolveComponent as w, openBlock as n, createElementBlock as p, createBlock as M, withModifiers as ue, createCommentVNode as b, createVNode as _, withCtx as T, createElementVNode as o, toDisplayString as l, unref as i, Fragment as z, createTextVNode as Z, renderList as le, normalizeClass as me, h as X, Teleport as pe } from "vue";
2
+ import { _ as ve } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-sUxHOj47.js";
3
+ import { useI18n as se, useCoreStore as ge } from "@feedmepos/mf-common";
4
+ import { H as ie, D as P, a as he, u as _e } from "./app-BwuCotIT.js";
5
+ import { F as re } from "./FmAdminBadge-DjnBAgyv.js";
6
+ import { _ as be } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BhN9g4ed.js";
7
+ import { useSnackbar as ce, useDialog as ke } from "@feedmepos/ui-library";
8
+ import { u as fe } from "./stock-OdR_zYes.js";
9
+ import { g as ye, f as xe } from "./recalculationUtils-TOCl7HAN.js";
10
+ import { _ as De } from "./UnitDisplayControl.vue_vue_type_script_setup_true_lang-DHP8-Qeq.js";
11
+ const we = { class: "fm-typo-en-heading-lg-600" }, Se = { class: "flex flex-col gap-16" }, Ce = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ve = { class: "flex flex-col gap-8" }, $e = { class: "fm-typo-en-body-md-600" }, Ae = { class: "flex flex-col gap-8" }, Fe = { class: "fm-typo-en-body-md-600" }, Re = { class: "flex items-center gap-8 mb-8" }, Ie = {
12
+ key: 2,
13
+ class: "text-red-500 text-sm mt-2"
14
+ }, Te = { class: "fm-typo-en-body-sm-400" }, Be = {
15
+ key: 1,
16
+ class: "p-12 border border-fm-color-border-primary rounded-8 bg-fm-color-background-secondary"
17
+ }, Le = {
18
+ key: 0,
19
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
20
+ }, Oe = {
21
+ key: 1,
22
+ class: "flex flex-col gap-8"
23
+ }, Ee = { class: "fm-typo-en-body-sm-600" }, Pe = { class: "flex flex-col gap-4" }, Ue = { key: 0 }, Ne = {
24
+ key: 1,
25
+ class: "flex flex-col gap-8"
26
+ }, Me = { class: "fm-typo-en-body-md-600" }, Ke = { class: "flex flex-col gap-8 max-h-[300px] overflow-y-auto" }, He = { class: "flex items-center justify-between" }, je = { class: "fm-typo-en-body-sm-600" }, ze = { class: "flex items-center gap-8" }, We = {
27
+ key: 0,
28
+ class: "fm-typo-en-body-xs-600 px-8 py-4 rounded-4 bg-fm-color-neutral-100 text-fm-color-typo-secondary"
29
+ }, Ye = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Ge = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Je = {
30
+ key: 0,
31
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
32
+ }, Qe = {
33
+ key: 1,
34
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
35
+ }, Xe = {
36
+ key: 2,
37
+ class: "fm-typo-en-body-xs-400 text-fm-color-system-error-500"
38
+ }, Ze = {
39
+ key: 0,
40
+ class: "flex gap-8 ml-auto"
41
+ }, qe = {
42
+ key: 1,
43
+ class: "flex gap-8 ml-auto"
44
+ }, et = /* @__PURE__ */ ne({
45
+ __name: "RecalculationDialog",
46
+ props: {
47
+ showButton: { type: Boolean }
48
+ },
49
+ emits: ["submitted"],
50
+ setup(ae, { expose: S, emit: C }) {
51
+ const U = C, { t } = se(), L = fe(), O = ie(), V = ce(), $ = g(!1), f = g(""), m = g(""), F = g(!1), v = g([]), a = g(!1), k = g([]), A = g(!1), h = g([]), x = g(!1), W = D(() => ye(v.value)), Y = D(() => {
52
+ if (!f.value) return [];
53
+ const d = W.value.find((e) => e.value === f.value);
54
+ return d ? W.value.filter((e) => e.date.getTime() > d.date.getTime()).sort((e, c) => c.date.getTime() - e.date.getTime()) : [];
55
+ }), G = D({
56
+ get: () => {
57
+ if (F.value && m.value) {
58
+ const d = v.value.find((e) => P(e._id) === m.value);
59
+ return (d == null ? void 0 : d._id) || m.value;
60
+ }
61
+ return m.value;
62
+ },
63
+ set: (d) => {
64
+ F.value && d ? m.value = P(d) : m.value = d;
65
+ }
66
+ }), K = D(() => {
67
+ if (f.value)
68
+ try {
69
+ const d = P(f.value);
70
+ if (d)
71
+ return d;
72
+ } catch (d) {
73
+ console.error("Error parsing date from closing ID:", d);
74
+ }
75
+ }), E = D(() => {
76
+ if (!f.value || !m.value) return "";
77
+ const d = P(f.value), e = m.value;
78
+ if (d && e) {
79
+ const c = new Date(d).getTime();
80
+ if (new Date(e).getTime() <= c)
81
+ return t("inventory.stock.recalculation.error.endDateBeforeOpening");
82
+ }
83
+ return "";
84
+ }), N = D(() => !!f.value && !!m.value && !E.value), J = D(() => k.value.some(
85
+ (d) => !d.completedAt && !d.failedReason
86
+ ));
87
+ async function Q() {
88
+ $.value = !0, await Promise.all([ee(), H()]), f.value = "", m.value = "", F.value = !1;
89
+ }
90
+ function q() {
91
+ $.value = !1;
92
+ }
93
+ S({
94
+ open: Q,
95
+ close: q
96
+ });
97
+ async function ee() {
98
+ a.value = !0;
99
+ try {
100
+ const d = await O.getLastNClosings(30);
101
+ v.value = d;
102
+ } catch (d) {
103
+ console.error("Error fetching recent closings:", d), V.open({
104
+ title: t("common.error"),
105
+ message: "Failed to fetch recent closings",
106
+ type: "error"
107
+ });
108
+ } finally {
109
+ a.value = !1;
110
+ }
111
+ }
112
+ async function H() {
113
+ A.value = !0;
114
+ try {
115
+ const d = await L.recalculation.recalculationRequests();
116
+ k.value = d;
117
+ } catch (d) {
118
+ console.error("Error fetching recalculation requests:", d);
119
+ } finally {
120
+ A.value = !1;
121
+ }
122
+ }
123
+ async function j() {
124
+ if (!f.value || !m.value) {
125
+ h.value = [];
126
+ return;
127
+ }
128
+ x.value = !0;
129
+ try {
130
+ const d = await L.recalculation.getAffectedClosingDrafts(
131
+ f.value,
132
+ m.value
133
+ );
134
+ h.value = d;
135
+ } catch {
136
+ V.open({
137
+ title: t("common.error"),
138
+ message: "Failed to fetch affected closing drafts",
139
+ type: "error"
140
+ }), h.value = [];
141
+ } finally {
142
+ x.value = !1;
143
+ }
144
+ }
145
+ de(
146
+ [f, m],
147
+ () => {
148
+ f.value && m.value && !E.value ? j() : h.value = [];
149
+ },
150
+ { immediate: !1 }
151
+ );
152
+ async function te() {
153
+ if (N.value) {
154
+ a.value = !0;
155
+ try {
156
+ if (await L.recalculation.scheduleRecalculation({
157
+ openingId: f.value,
158
+ untilDate: m.value
159
+ }), h.value.length > 0) {
160
+ const d = h.value.map((e) => e._id);
161
+ await L.recalculation.scheduleInvalidateClosingDraftCache(d);
162
+ }
163
+ V.open({
164
+ title: t("common.success"),
165
+ message: "Stock recalculation has been scheduled successfully",
166
+ type: "success"
167
+ }), await H(), $.value = !1, U("submitted");
168
+ } catch (d) {
169
+ console.error("Error scheduling recalculation:", d), V.open({
170
+ title: t("common.error"),
171
+ message: "Failed to schedule stock recalculation",
172
+ type: "error"
173
+ });
174
+ } finally {
175
+ a.value = !1;
176
+ }
177
+ }
178
+ }
179
+ return (d, e) => {
180
+ const c = w("FmButton"), s = w("FmSelect"), u = w("FmRadio"), I = w("FmDatePicker"), B = w("FmAlert"), oe = w("FmDialog");
181
+ return n(), p("div", null, [
182
+ d.showButton ? (n(), M(c, {
183
+ key: 0,
184
+ "prepend-icon": "info",
185
+ variant: "tertiary",
186
+ onClick: ue(Q, ["stop"])
187
+ })) : b("", !0),
188
+ _(oe, {
189
+ modelValue: $.value,
190
+ "onUpdate:modelValue": e[7] || (e[7] = (r) => $.value = r),
191
+ "close-button": "",
192
+ dismissAway: "",
193
+ "max-width": "600px"
194
+ }, {
195
+ "dialog-header": T(() => [
196
+ o("div", we, l(i(t)("inventory.stock.recalculation.title")), 1)
197
+ ]),
198
+ "dialog-footer": T(() => [
199
+ J.value ? (n(), p("div", qe, [
200
+ _(c, {
201
+ variant: "tertiary",
202
+ onClick: e[6] || (e[6] = (r) => $.value = !1),
203
+ label: i(t)("common.close")
204
+ }, null, 8, ["label"])
205
+ ])) : (n(), p("div", Ze, [
206
+ _(c, {
207
+ variant: "tertiary",
208
+ onClick: e[5] || (e[5] = (r) => $.value = !1),
209
+ disabled: a.value,
210
+ label: i(t)("common.cancel")
211
+ }, null, 8, ["disabled", "label"]),
212
+ _(c, {
213
+ variant: "primary",
214
+ onClick: te,
215
+ disabled: !N.value || a.value,
216
+ loading: a.value,
217
+ label: i(t)("inventory.stock.recalculation.schedule")
218
+ }, null, 8, ["disabled", "loading", "label"])
219
+ ]))
220
+ ]),
221
+ default: T(() => [
222
+ o("div", Se, [
223
+ o("div", Ce, l(i(t)("inventory.stock.recalculation.description")), 1),
224
+ J.value ? b("", !0) : (n(), p(z, { key: 0 }, [
225
+ o("div", Ve, [
226
+ o("p", $e, [
227
+ Z(l(i(t)("inventory.stock.recalculation.openingDate")) + " ", 1),
228
+ e[8] || (e[8] = o("span", { class: "text-fm-color-system-error-300" }, "*", -1))
229
+ ]),
230
+ e[9] || (e[9] = o("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary mb-4" }, " Showing the last 30 closing records. Select the opening date to start recalculation. ", -1)),
231
+ _(s, {
232
+ modelValue: f.value,
233
+ "onUpdate:modelValue": e[0] || (e[0] = (r) => f.value = r),
234
+ items: W.value,
235
+ placeholder: i(t)("inventory.stock.recalculation.selectOpening"),
236
+ loading: a.value,
237
+ disabled: a.value
238
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])
239
+ ]),
240
+ o("div", Ae, [
241
+ o("p", Fe, [
242
+ Z(l(i(t)("inventory.stock.recalculation.untilDate")) + " ", 1),
243
+ e[10] || (e[10] = o("span", { class: "text-fm-color-system-error-300" }, "*", -1))
244
+ ]),
245
+ o("div", Re, [
246
+ _(u, {
247
+ modelValue: F.value,
248
+ "onUpdate:modelValue": e[1] || (e[1] = (r) => F.value = r),
249
+ value: !1,
250
+ label: i(t)("inventory.stock.recalculation.selectByDate")
251
+ }, null, 8, ["modelValue", "label"]),
252
+ _(u, {
253
+ modelValue: F.value,
254
+ "onUpdate:modelValue": e[2] || (e[2] = (r) => F.value = r),
255
+ value: !0,
256
+ label: i(t)("inventory.stock.recalculation.selectByClosing")
257
+ }, null, 8, ["modelValue", "label"])
258
+ ]),
259
+ F.value ? (n(), M(s, {
260
+ key: 1,
261
+ modelValue: G.value,
262
+ "onUpdate:modelValue": e[4] || (e[4] = (r) => G.value = r),
263
+ items: Y.value,
264
+ placeholder: i(t)("inventory.stock.recalculation.selectClosing"),
265
+ loading: a.value,
266
+ disabled: !f.value || a.value
267
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])) : (n(), M(I, {
268
+ key: 0,
269
+ modelValue: m.value,
270
+ "onUpdate:modelValue": e[3] || (e[3] = (r) => m.value = r),
271
+ placeholder: i(t)("inventory.stock.recalculation.selectDate"),
272
+ min: K.value,
273
+ disabled: !f.value || a.value
274
+ }, null, 8, ["modelValue", "placeholder", "min", "disabled"])),
275
+ E.value ? (n(), p("div", Ie, l(E.value), 1)) : b("", !0)
276
+ ]),
277
+ f.value && m.value && !E.value ? (n(), M(B, {
278
+ key: 0,
279
+ type: "info"
280
+ }, {
281
+ default: T(() => [
282
+ o("div", Te, l(i(t)("inventory.stock.recalculation.info")), 1)
283
+ ]),
284
+ _: 1
285
+ })) : b("", !0),
286
+ h.value.length > 0 ? (n(), p("div", Be, [
287
+ x.value ? (n(), p("div", Le, " Loading affected closing drafts... ")) : (n(), p("div", Oe, [
288
+ o("div", Ee, " Affected closing draft(s): " + l(h.value.length), 1),
289
+ o("div", Pe, [
290
+ (n(!0), p(z, null, le(h.value, (r) => (n(), p("div", {
291
+ key: r._id,
292
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
293
+ }, [
294
+ Z(" • " + l(r._id) + " ", 1),
295
+ r.effectiveAt ? (n(), p("span", Ue, " (" + l(new Date(r.effectiveAt).toLocaleString()) + ") ", 1)) : b("", !0)
296
+ ]))), 128))
297
+ ])
298
+ ]))
299
+ ])) : b("", !0)
300
+ ], 64)),
301
+ k.value.length > 0 ? (n(), p("div", Ne, [
302
+ o("p", Me, l(i(t)("inventory.stock.recalculation.recentRequests")), 1),
303
+ o("div", Ke, [
304
+ (n(!0), p(z, null, le(k.value, (r) => {
305
+ var y;
306
+ return n(), p("div", {
307
+ key: r._id,
308
+ class: "p-12 border border-fm-color-border-primary rounded-8 flex flex-col gap-4"
309
+ }, [
310
+ o("div", He, [
311
+ o("div", je, l(i(t)("inventory.stock.recalculation.requestedAt")) + ": " + l(new Date(r.createdAt).toLocaleString()), 1),
312
+ o("div", ze, [
313
+ (y = r.meta) != null && y.openingType ? (n(), p("div", We, l(r.meta.openingType === "stockSnapshot" ? "Snapshot" : "Closing"), 1)) : b("", !0),
314
+ o("div", {
315
+ class: me(["fm-typo-en-body-xs-600 px-8 py-4 rounded-4", {
316
+ "bg-fm-color-system-error-100 text-fm-color-system-error-500": r.failedReason,
317
+ "bg-fm-color-system-success-100 text-fm-color-system-success-500": r.completedAt,
318
+ "bg-fm-color-system-info-100 text-fm-color-system-info-500": !r.failedReason && !r.completedAt
319
+ }])
320
+ }, l(r.failedReason ? i(t)("inventory.stock.recalculation.status.failed") : r.completedAt ? i(t)("inventory.stock.recalculation.status.completed") : i(t)("inventory.stock.recalculation.status.inProgress")), 3)
321
+ ])
322
+ ]),
323
+ o("div", Ye, l(i(t)("inventory.stock.recalculation.from")) + ": " + l(new Date(r.recalculateStartDate).toLocaleDateString()), 1),
324
+ o("div", Ge, l(i(t)("inventory.stock.recalculation.to")) + ": " + l(new Date(r.recalculateEndDate).toLocaleDateString()), 1),
325
+ r.createdBy ? (n(), p("div", Je, l(i(t)("inventory.stock.recalculation.requestedBy")) + ": " + l(r.createdBy.name || r.createdBy.id), 1)) : b("", !0),
326
+ r.completedAt ? (n(), p("div", Qe, l(i(t)("inventory.stock.recalculation.completedAt")) + ": " + l(new Date(r.completedAt).toLocaleString()), 1)) : b("", !0),
327
+ r.failedReason ? (n(), p("div", Xe, l(r.failedReason), 1)) : b("", !0)
328
+ ]);
329
+ }), 128))
330
+ ])
331
+ ])) : b("", !0)
332
+ ])
333
+ ]),
334
+ _: 1
335
+ }, 8, ["modelValue"])
336
+ ]);
337
+ };
338
+ }
339
+ }), tt = { class: "fm-typo-en-heading-lg-600" }, ot = { class: "flex flex-col gap-16" }, at = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, lt = { class: "flex flex-col gap-8" }, nt = { class: "fm-typo-en-body-md-600" }, st = { class: "flex flex-col gap-8" }, it = { class: "fm-typo-en-body-md-600" }, ct = {
340
+ key: 0,
341
+ class: "text-red-500 text-sm mt-2"
342
+ }, rt = { class: "fm-typo-en-body-sm-400" }, dt = {
343
+ key: 1,
344
+ class: "p-12 border border-fm-color-border-primary rounded-8 bg-fm-color-background-secondary"
345
+ }, ut = {
346
+ key: 0,
347
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
348
+ }, mt = {
349
+ key: 1,
350
+ class: "flex flex-col gap-8"
351
+ }, ft = { class: "fm-typo-en-body-sm-600" }, yt = { class: "flex flex-col gap-4" }, pt = { key: 0 }, vt = { key: 1 }, gt = { key: 2 }, ht = {
352
+ key: 1,
353
+ class: "flex flex-col gap-8"
354
+ }, _t = { class: "fm-typo-en-body-md-600" }, bt = { class: "flex flex-col gap-8 max-h-[300px] overflow-y-auto" }, kt = { class: "flex items-center justify-between" }, xt = { class: "fm-typo-en-body-sm-600" }, Dt = { class: "flex items-center gap-8" }, wt = {
355
+ key: 0,
356
+ class: "fm-typo-en-body-xs-600 px-8 py-4 rounded-4 bg-fm-color-neutral-100 text-fm-color-typo-secondary"
357
+ }, St = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Ct = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Vt = {
358
+ key: 0,
359
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
360
+ }, $t = {
361
+ key: 1,
362
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
363
+ }, At = {
364
+ key: 2,
365
+ class: "fm-typo-en-body-xs-400 text-fm-color-system-error-500"
366
+ }, Ft = {
367
+ key: 0,
368
+ class: "flex gap-8 ml-auto"
369
+ }, Rt = {
370
+ key: 1,
371
+ class: "flex gap-8 ml-auto"
372
+ }, It = /* @__PURE__ */ ne({
373
+ __name: "SnapshotRecalculationDialog",
374
+ props: {
375
+ showButton: { type: Boolean }
376
+ },
377
+ emits: ["submitted"],
378
+ setup(ae, { expose: S, emit: C }) {
379
+ const U = C, { t } = se(), L = fe(), O = ie(), V = ce(), $ = g(!1), f = g(""), m = g(""), F = g([]), v = g([]), a = g(!1), k = g([]), A = g(!1), h = g([]), x = g(!1), W = D(
380
+ () => ye(F.value, v.value)
381
+ ), Y = D(() => {
382
+ const e = h.value.map((c) => c.closingId).filter((c) => !!c);
383
+ return xe(e);
384
+ }), G = D(() => {
385
+ if (f.value)
386
+ try {
387
+ const e = P(f.value);
388
+ if (e)
389
+ return e;
390
+ } catch (e) {
391
+ console.error("Error parsing date from opening ID:", e);
392
+ }
393
+ }), K = D(() => {
394
+ if (!f.value || !m.value) return "";
395
+ const e = P(f.value);
396
+ if (e && m.value) {
397
+ const c = new Date(e).getTime();
398
+ if (new Date(m.value).getTime() <= c)
399
+ return t("inventory.stock.recalculation.error.endDateBeforeOpening");
400
+ }
401
+ return "";
402
+ }), E = D(() => {
403
+ if (!m.value) return !1;
404
+ const e = new Date(m.value), c = /* @__PURE__ */ new Date();
405
+ return c.setHours(0, 0, 0, 0), e.setHours(0, 0, 0, 0), e >= c;
406
+ }), N = D(() => !!f.value && !!m.value && !K.value), J = D(() => k.value.some(
407
+ (e) => !e.completedAt && !e.failedReason
408
+ ));
409
+ async function Q() {
410
+ $.value = !0, await Promise.all([ee(), H(), j()]), f.value = "", m.value = "";
411
+ }
412
+ function q() {
413
+ $.value = !1;
414
+ }
415
+ S({
416
+ open: Q,
417
+ close: q
418
+ });
419
+ async function ee() {
420
+ a.value = !0;
421
+ try {
422
+ const e = await O.getLastNClosings(30);
423
+ F.value = e;
424
+ } catch (e) {
425
+ console.error("Error fetching recent closings:", e), V.open({
426
+ title: t("common.error"),
427
+ message: "Failed to fetch recent closings",
428
+ type: "error"
429
+ });
430
+ } finally {
431
+ a.value = !1;
432
+ }
433
+ }
434
+ async function H() {
435
+ try {
436
+ const e = await O.getLastNStockSnapshots(30);
437
+ v.value = e;
438
+ } catch (e) {
439
+ console.error("Error fetching recent snapshots:", e);
440
+ }
441
+ }
442
+ async function j() {
443
+ A.value = !0;
444
+ try {
445
+ const e = await L.recalculation.recalculationRequests();
446
+ k.value = e;
447
+ } catch (e) {
448
+ console.error("Error fetching recalculation requests:", e);
449
+ } finally {
450
+ A.value = !1;
451
+ }
452
+ }
453
+ async function te() {
454
+ if (!f.value || !m.value) {
455
+ h.value = [];
456
+ return;
457
+ }
458
+ x.value = !0;
459
+ try {
460
+ const e = new Date(m.value);
461
+ e.setHours(23, 59, 59, 999);
462
+ const c = await L.recalculation.getAffectedClosingDrafts(
463
+ f.value,
464
+ e.toISOString()
465
+ );
466
+ h.value = c;
467
+ } catch {
468
+ V.open({
469
+ title: t("common.error"),
470
+ message: "Failed to fetch affected closing drafts",
471
+ type: "error"
472
+ }), h.value = [];
473
+ } finally {
474
+ x.value = !1;
475
+ }
476
+ }
477
+ de(
478
+ [f, m],
479
+ () => {
480
+ f.value && m.value && !K.value ? te() : h.value = [];
481
+ },
482
+ { immediate: !1 }
483
+ );
484
+ async function d() {
485
+ if (!(!N.value || !m.value)) {
486
+ a.value = !0;
487
+ try {
488
+ if (await L.recalculation.scheduleRecalculation({
489
+ openingId: f.value,
490
+ untilDate: new Date(m.value).toISOString(),
491
+ recalculateBySnapshot: !0
492
+ }), h.value.length > 0) {
493
+ const e = h.value.map((c) => c._id);
494
+ await L.recalculation.scheduleInvalidateClosingDraftCache(e);
495
+ }
496
+ V.open({
497
+ title: t("common.success"),
498
+ message: "Stock recalculation has been scheduled successfully",
499
+ type: "success"
500
+ }), await j(), $.value = !1, U("submitted");
501
+ } catch (e) {
502
+ console.error("Error scheduling recalculation:", e), V.open({
503
+ title: t("common.error"),
504
+ message: "Failed to schedule stock recalculation",
505
+ type: "error"
506
+ });
507
+ } finally {
508
+ a.value = !1;
509
+ }
510
+ }
511
+ }
512
+ return (e, c) => {
513
+ const s = w("FmButton"), u = w("FmSelect"), I = w("FmDatePicker"), B = w("FmSnackbar"), oe = w("FmAlert"), r = w("FmDialog");
514
+ return n(), p("div", null, [
515
+ e.showButton ? (n(), M(s, {
516
+ key: 0,
517
+ "prepend-icon": "info",
518
+ variant: "tertiary",
519
+ onClick: ue(Q, ["stop"])
520
+ })) : b("", !0),
521
+ _(r, {
522
+ modelValue: $.value,
523
+ "onUpdate:modelValue": c[4] || (c[4] = (y) => $.value = y),
524
+ "close-button": "",
525
+ dismissAway: "",
526
+ "max-width": "600px"
527
+ }, {
528
+ "dialog-header": T(() => [
529
+ o("div", tt, l(i(t)("inventory.stock.recalculation.title")), 1)
530
+ ]),
531
+ "dialog-footer": T(() => [
532
+ J.value ? (n(), p("div", Rt, [
533
+ _(s, {
534
+ variant: "tertiary",
535
+ onClick: c[3] || (c[3] = (y) => $.value = !1),
536
+ label: i(t)("common.close")
537
+ }, null, 8, ["label"])
538
+ ])) : (n(), p("div", Ft, [
539
+ _(s, {
540
+ variant: "tertiary",
541
+ onClick: c[2] || (c[2] = (y) => $.value = !1),
542
+ disabled: a.value,
543
+ label: i(t)("common.cancel")
544
+ }, null, 8, ["disabled", "label"]),
545
+ _(s, {
546
+ variant: "primary",
547
+ onClick: d,
548
+ disabled: !N.value || a.value,
549
+ loading: a.value,
550
+ label: i(t)("inventory.stock.recalculation.schedule")
551
+ }, null, 8, ["disabled", "loading", "label"])
552
+ ]))
553
+ ]),
554
+ default: T(() => [
555
+ o("div", ot, [
556
+ o("div", at, l(i(t)("inventory.stock.recalculation.description")), 1),
557
+ J.value ? b("", !0) : (n(), p(z, { key: 0 }, [
558
+ o("div", lt, [
559
+ o("p", nt, [
560
+ Z(l(i(t)("inventory.stock.recalculation.openingDate")) + " ", 1),
561
+ c[5] || (c[5] = o("span", { class: "text-fm-color-system-error-300" }, "*", -1))
562
+ ]),
563
+ c[6] || (c[6] = o("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary mb-4" }, " Select from the last 30 closing or snapshot records as the opening date for recalculation. ", -1)),
564
+ _(u, {
565
+ modelValue: f.value,
566
+ "onUpdate:modelValue": c[0] || (c[0] = (y) => f.value = y),
567
+ items: W.value,
568
+ placeholder: i(t)("inventory.stock.recalculation.selectOpening"),
569
+ loading: a.value,
570
+ disabled: a.value
571
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])
572
+ ]),
573
+ o("div", st, [
574
+ o("p", it, [
575
+ Z(l(i(t)("inventory.stock.recalculation.untilDate")) + " ", 1),
576
+ c[7] || (c[7] = o("span", { class: "text-fm-color-system-error-300" }, "*", -1))
577
+ ]),
578
+ c[8] || (c[8] = o("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary mb-4" }, " Select the end date for recalculation. Must be after the selected opening date. ", -1)),
579
+ _(I, {
580
+ modelValue: m.value,
581
+ "onUpdate:modelValue": c[1] || (c[1] = (y) => m.value = y),
582
+ placeholder: i(t)("inventory.stock.recalculation.selectDate"),
583
+ min: G.value,
584
+ disabled: !f.value || a.value
585
+ }, null, 8, ["modelValue", "placeholder", "min", "disabled"]),
586
+ K.value ? (n(), p("div", ct, l(K.value), 1)) : b("", !0),
587
+ E.value ? (n(), M(B, {
588
+ key: 1,
589
+ title: "Warning",
590
+ variant: "warning",
591
+ description: "You have selected today or a future date. The stock balance will be refreshed accordingly."
592
+ })) : b("", !0)
593
+ ]),
594
+ f.value && m.value && !K.value ? (n(), M(oe, {
595
+ key: 0,
596
+ type: "info"
597
+ }, {
598
+ default: T(() => [
599
+ o("div", rt, l(i(t)("inventory.stock.recalculation.info")), 1)
600
+ ]),
601
+ _: 1
602
+ })) : b("", !0),
603
+ h.value.length > 0 ? (n(), p("div", dt, [
604
+ x.value ? (n(), p("div", ut, " Loading affected closing drafts... ")) : (n(), p("div", mt, [
605
+ o("div", ft, " Affected closing draft(s): " + l(h.value.length), 1),
606
+ o("div", yt, [
607
+ (n(!0), p(z, null, le(h.value, (y) => (n(), p("div", {
608
+ key: y._id,
609
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
610
+ }, [
611
+ c[9] || (c[9] = Z(" • ")),
612
+ y.closingId && Y.value.get(y.closingId) ? (n(), p("span", pt, l(Y.value.get(y.closingId)), 1)) : (n(), p("span", vt, l(y._id), 1)),
613
+ y.effectiveAt ? (n(), p("span", gt, " (" + l(new Date(y.effectiveAt).toLocaleString()) + ") ", 1)) : b("", !0)
614
+ ]))), 128))
615
+ ])
616
+ ]))
617
+ ])) : b("", !0)
618
+ ], 64)),
619
+ k.value.length > 0 ? (n(), p("div", ht, [
620
+ o("p", _t, l(i(t)("inventory.stock.recalculation.recentRequests")), 1),
621
+ o("div", bt, [
622
+ (n(!0), p(z, null, le(k.value, (y) => {
623
+ var R;
624
+ return n(), p("div", {
625
+ key: y._id,
626
+ class: "p-12 border border-fm-color-border-primary rounded-8 flex flex-col gap-4"
627
+ }, [
628
+ o("div", kt, [
629
+ o("div", xt, l(i(t)("inventory.stock.recalculation.requestedAt")) + ": " + l(new Date(y.createdAt).toLocaleString()), 1),
630
+ o("div", Dt, [
631
+ (R = y.meta) != null && R.openingType ? (n(), p("div", wt, l(y.meta.openingType === "stockSnapshot" ? "Snapshot" : "Closing"), 1)) : b("", !0),
632
+ o("div", {
633
+ class: me(["fm-typo-en-body-xs-600 px-8 py-4 rounded-4", {
634
+ "bg-fm-color-system-error-100 text-fm-color-system-error-500": y.failedReason,
635
+ "bg-fm-color-system-success-100 text-fm-color-system-success-500": y.completedAt,
636
+ "bg-fm-color-system-info-100 text-fm-color-system-info-500": !y.failedReason && !y.completedAt
637
+ }])
638
+ }, l(y.failedReason ? i(t)("inventory.stock.recalculation.status.failed") : y.completedAt ? i(t)("inventory.stock.recalculation.status.completed") : i(t)("inventory.stock.recalculation.status.inProgress")), 3)
639
+ ])
640
+ ]),
641
+ o("div", St, l(i(t)("inventory.stock.recalculation.from")) + ": " + l(new Date(y.recalculateStartDate).toLocaleDateString()), 1),
642
+ o("div", Ct, l(i(t)("inventory.stock.recalculation.to")) + ": " + l(new Date(y.recalculateEndDate).toLocaleDateString()), 1),
643
+ y.createdBy ? (n(), p("div", Vt, l(i(t)("inventory.stock.recalculation.requestedBy")) + ": " + l(y.createdBy.name || y.createdBy.id), 1)) : b("", !0),
644
+ y.completedAt ? (n(), p("div", $t, l(i(t)("inventory.stock.recalculation.completedAt")) + ": " + l(new Date(y.completedAt).toLocaleString()), 1)) : b("", !0),
645
+ y.failedReason ? (n(), p("div", At, l(y.failedReason), 1)) : b("", !0)
646
+ ]);
647
+ }), 128))
648
+ ])
649
+ ])) : b("", !0)
650
+ ])
651
+ ]),
652
+ _: 1
653
+ }, 8, ["modelValue"])
654
+ ]);
655
+ };
656
+ }
657
+ }), Tt = { class: "fm-typo-en-heading-lg-600" }, Bt = { class: "flex flex-col gap-16" }, Lt = { class: "flex flex-col gap-4" }, Ot = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Et = { class: "fm-typo-en-body-md-400" }, Pt = { class: "flex flex-col gap-4" }, Ut = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Nt = { class: "fm-typo-en-body-md-400" }, Mt = { class: "flex flex-col gap-4" }, Kt = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Ht = { class: "flex gap-8 ml-auto" }, jt = /* @__PURE__ */ ne({
658
+ __name: "ClosingDetailDialog",
659
+ props: {
660
+ modelValue: { type: Boolean },
661
+ type: {},
662
+ data: {}
663
+ },
664
+ emits: ["update:modelValue"],
665
+ setup(ae, { emit: S }) {
666
+ const { t: C } = se(), U = he(), t = ae, L = S, O = D({
667
+ get: () => t.modelValue,
668
+ set: (v) => L("update:modelValue", v)
669
+ }), V = D(() => {
670
+ var v;
671
+ return ((v = t.data) == null ? void 0 : v.skus) ?? [];
672
+ }), $ = D(() => {
673
+ var A;
674
+ const v = (A = t.data) == null ? void 0 : A._id;
675
+ if (!v) return "-";
676
+ const a = P(v);
677
+ return new Date(a).toLocaleString();
678
+ }), f = D(() => t.type === "closing" ? C("inventory.closing.history.closingDetail", "Closing Detail") : C("inventory.closing.history.snapshotDetail", "Snapshot Detail")), m = D(() => V.value.map((v) => {
679
+ const a = U.skuById[v.id] ?? null, k = !a;
680
+ return {
681
+ id: v.id,
682
+ sku: a,
683
+ skuName: (a == null ? void 0 : a.name) ?? v.id,
684
+ skuCode: (a == null ? void 0 : a.code) ?? "-",
685
+ balance: v.balance ?? { amount: 0, precision: 0 },
686
+ isMissing: k,
687
+ costs: v.costs,
688
+ weightedAverage: v.weightedAverage
689
+ };
690
+ })), F = [
691
+ {
692
+ accessorKey: "skuName",
693
+ header: () => C("inventory.ingredient.name", "Ingredient Name"),
694
+ cell: (v) => {
695
+ const a = v.row.original;
696
+ return a.isMissing ? X("div", { class: "flex items-center gap-8" }, [
697
+ X("span", {}, a.id),
698
+ X(
699
+ "span",
700
+ {
701
+ class: "px-8 py-2 rounded-4 bg-fm-color-danger-weak text-fm-color-danger-default fm-typo-en-label-sm-400"
702
+ },
703
+ "Missing"
704
+ )
705
+ ]) : v.getValue();
706
+ }
707
+ },
708
+ {
709
+ accessorKey: "skuCode",
710
+ header: () => C("inventory.ingredient.code", "Code")
711
+ },
712
+ {
713
+ id: "balance",
714
+ header: () => C("inventory.closing.history.balance", "Balance"),
715
+ cell: (v) => {
716
+ var A;
717
+ const a = v.row.original;
718
+ if (a.isMissing || !((A = a.sku) != null && A.unit))
719
+ return `${a.balance.amount / Math.pow(10, a.balance.precision)}`;
720
+ const k = {
721
+ unit: a.sku.unit,
722
+ sku: a.sku,
723
+ amount: a.balance,
724
+ defaultTrackingMeasurement: a.sku.trackingMeasurement ?? void 0
725
+ };
726
+ return X(De, k);
727
+ },
728
+ size: 180
729
+ },
730
+ {
731
+ accessorKey: "weightedAverage",
732
+ header: () => C("inventory.closing.history.weightedAvgCost", "Weighted Avg Cost"),
733
+ cell: (v) => {
734
+ const a = v.getValue();
735
+ if (!a) return "-";
736
+ const k = a.amount ?? 0, A = a.precision ?? 0, h = a.currency ?? "", x = k / Math.pow(10, A);
737
+ return `${h} ${x.toFixed(2)}`;
738
+ }
739
+ }
740
+ ];
741
+ return (v, a) => {
742
+ const k = w("FmTable"), A = w("FmButton"), h = w("FmDialog");
743
+ return n(), M(h, {
744
+ modelValue: O.value,
745
+ "onUpdate:modelValue": a[1] || (a[1] = (x) => O.value = x),
746
+ "close-button": "",
747
+ dismissAway: "",
748
+ "max-width": "900px"
749
+ }, {
750
+ "dialog-header": T(() => [
751
+ o("div", Tt, l(f.value), 1)
752
+ ]),
753
+ default: T(() => {
754
+ var x;
755
+ return [
756
+ o("div", Bt, [
757
+ o("div", Lt, [
758
+ o("div", Ot, l(t.type === "closing" ? i(C)("inventory.closing.history.closingId") : i(C)("inventory.closing.history.snapshotId", "Snapshot ID")), 1),
759
+ o("div", Et, l(((x = t.data) == null ? void 0 : x._id) ?? "-"), 1)
760
+ ]),
761
+ o("div", Pt, [
762
+ o("div", Ut, l(i(C)("inventory.closing.history.date")), 1),
763
+ o("div", Nt, l($.value), 1)
764
+ ]),
765
+ o("div", Mt, [
766
+ o("div", Kt, l(i(C)("inventory.closing.history.ingredientBalances", "Ingredient Balances")) + " (" + l(V.value.length) + ") ", 1),
767
+ _(k, {
768
+ "row-data": m.value,
769
+ "column-defs": F,
770
+ pagination: { pageSize: 10 }
771
+ }, null, 8, ["row-data"])
772
+ ])
773
+ ])
774
+ ];
775
+ }),
776
+ "dialog-footer": T(() => [
777
+ o("div", Ht, [
778
+ _(A, {
779
+ variant: "tertiary",
780
+ onClick: a[0] || (a[0] = (x) => O.value = !1),
781
+ label: "Close"
782
+ })
783
+ ])
784
+ ]),
785
+ _: 1
786
+ }, 8, ["modelValue"]);
787
+ };
788
+ }
789
+ }), zt = { class: "flex flex-col gap-16 p-16" }, Wt = { class: "flex flex-col gap-16" }, Yt = { class: "flex gap-8 ml-auto" }, lo = /* @__PURE__ */ ne({
790
+ __name: "ClosingHistoryView",
791
+ setup(ae) {
792
+ var e, c;
793
+ const { t: S } = se(), C = ie(), U = _e(), t = ge(), L = ke(), O = ce(), V = g("closings"), $ = [
794
+ { label: "Closings", value: "closings" },
795
+ { label: "Snapshots", value: "snapshots" }
796
+ ], f = g([]), m = g(!1), F = g([]), v = g(!1), a = g(!1), k = g("closing"), A = g(null), h = new Date(Date.now() - 864e5), x = g(h.toISOString().split("T")[0]), W = D(() => {
797
+ const s = [];
798
+ return V.value === "closings" ? s.push(
799
+ {
800
+ label: S("inventory.stock.recalculation.title"),
801
+ value: "recalculation",
802
+ prependIcon: "history",
803
+ isAdminOnly: !0
804
+ },
805
+ {
806
+ label: S("inventory.closing.history.initiate_opening"),
807
+ value: "initiateOpening",
808
+ prependIcon: "add_box",
809
+ isAdminOnly: !0
810
+ },
811
+ {
812
+ label: "Refresh",
813
+ value: "refreshOpening",
814
+ prependIcon: "refresh"
815
+ }
816
+ ) : s.push(
817
+ {
818
+ label: `${S("inventory.stock.recalculation.title")} (BETA)`,
819
+ value: "recalculation",
820
+ prependIcon: "history",
821
+ isAdminOnly: !0
822
+ },
823
+ {
824
+ label: `${S("inventory.closing.history.initiate_snapshot")} (BETA)`,
825
+ value: "initiateStockSnapshot",
826
+ prependIcon: "camera",
827
+ isAdminOnly: !0
828
+ },
829
+ {
830
+ label: "Refresh",
831
+ value: "refreshStockSnapshot",
832
+ prependIcon: "refresh"
833
+ }
834
+ ), s;
835
+ }), Y = g(), G = g();
836
+ function K(s) {
837
+ var u, I;
838
+ switch (s) {
839
+ case "recalculation":
840
+ return V.value === "closings" ? (u = Y.value) == null ? void 0 : u.open() : (I = G.value) == null ? void 0 : I.open();
841
+ case "initiateOpening": {
842
+ L.open({
843
+ title: "Initiate Opening Balance",
844
+ message: "Initiate opening balance if no opening balance exists for the current location.",
845
+ primaryActions: { text: "Confirm", close: !0 }
846
+ }).onPrimary(async () => {
847
+ try {
848
+ await C.initiateClosing(), O.open({
849
+ message: "Opening balance initiated successfully.",
850
+ type: "success"
851
+ }), await H();
852
+ } catch (B) {
853
+ O.open({
854
+ message: B.message || "Failed to initiate opening balance. Please try again.",
855
+ type: "error"
856
+ });
857
+ }
858
+ });
859
+ break;
860
+ }
861
+ case "initiateStockSnapshot": {
862
+ const B = new Date(Date.now() - 864e5);
863
+ x.value = B.toISOString().split("T")[0], E.value = !0;
864
+ break;
865
+ }
866
+ case "refreshOpening": {
867
+ H();
868
+ break;
869
+ }
870
+ case "refreshStockSnapshot": {
871
+ j();
872
+ break;
873
+ }
874
+ }
875
+ }
876
+ const E = g(!1), N = g(!1), J = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
877
+ async function Q() {
878
+ N.value = !0;
879
+ try {
880
+ const s = new Date(x.value).toISOString();
881
+ await C.initiateStockSnapshot(s), O.open({
882
+ message: "Stock snapshot created successfully.",
883
+ type: "success"
884
+ }), E.value = !1, await j();
885
+ } catch (s) {
886
+ O.open({
887
+ message: s.message || "Failed to create stock snapshot. Please try again.",
888
+ type: "error"
889
+ });
890
+ } finally {
891
+ N.value = !1;
892
+ }
893
+ }
894
+ const q = [
895
+ ...(e = t.sessionUser.value) != null && e.role.isAdmin ? [
896
+ {
897
+ accessorKey: "_id",
898
+ header: () => X(re, {}, () => `${S("inventory.closing.history.closingId")}`),
899
+ cell: (s) => s.getValue()
900
+ }
901
+ ] : [],
902
+ {
903
+ accessorKey: "_id",
904
+ id: "date",
905
+ header: () => S("inventory.closing.history.date"),
906
+ cell: (s) => {
907
+ const u = s.getValue(), I = P(u);
908
+ return new Date(I).toLocaleDateString();
909
+ }
910
+ },
911
+ {
912
+ accessorKey: "_id",
913
+ id: "time",
914
+ header: () => S("inventory.closing.history.time"),
915
+ cell: (s) => {
916
+ const u = s.getValue(), I = P(u);
917
+ return new Date(I).toLocaleTimeString();
918
+ }
919
+ },
920
+ {
921
+ accessorKey: "ref",
922
+ header: () => S("inventory.closing.history.createdFrom"),
923
+ cell: (s) => s.getValue() || "-"
924
+ }
925
+ ], ee = [
926
+ ...(c = t.sessionUser.value) != null && c.role.isAdmin ? [
927
+ {
928
+ accessorKey: "_id",
929
+ header: () => X(
930
+ re,
931
+ {},
932
+ () => `${S("inventory.closing.history.snapshotId", "Snapshot ID")}`
933
+ ),
934
+ cell: (s) => s.getValue()
935
+ }
936
+ ] : [],
937
+ {
938
+ accessorKey: "_id",
939
+ id: "date",
940
+ header: () => S("inventory.closing.history.date"),
941
+ cell: (s) => {
942
+ const u = s.getValue(), I = P(u);
943
+ return new Date(I).toLocaleDateString();
944
+ }
945
+ },
946
+ {
947
+ accessorKey: "_id",
948
+ id: "time",
949
+ header: () => S("inventory.closing.history.time"),
950
+ cell: (s) => {
951
+ const u = s.getValue(), I = P(u);
952
+ return new Date(I).toLocaleTimeString();
953
+ }
954
+ },
955
+ {
956
+ accessorKey: "remark",
957
+ header: () => S("inventory.closing.history.createdFrom"),
958
+ cell: (s) => s.getValue() || "-"
959
+ }
960
+ ];
961
+ async function H() {
962
+ if (U.currentLocationDBName) {
963
+ m.value = !0;
964
+ try {
965
+ const s = await C.getLastNClosings(30);
966
+ f.value = s;
967
+ } catch (s) {
968
+ console.error("Error fetching closings:", s), f.value = [];
969
+ } finally {
970
+ m.value = !1;
971
+ }
972
+ }
973
+ }
974
+ async function j() {
975
+ if (U.currentLocationDBName) {
976
+ v.value = !0;
977
+ try {
978
+ const s = await C.getLastNStockSnapshots(30);
979
+ F.value = s;
980
+ } catch (s) {
981
+ console.error("Error fetching stock snapshots:", s), F.value = [];
982
+ } finally {
983
+ v.value = !1;
984
+ }
985
+ }
986
+ }
987
+ function te(s) {
988
+ k.value = "closing", A.value = s, a.value = !0;
989
+ }
990
+ function d(s) {
991
+ k.value = "snapshot", A.value = s, a.value = !0;
992
+ }
993
+ return U.watchLocation(async () => {
994
+ U.currentLocationDBName && (await H(), await j());
995
+ }), (s, u) => {
996
+ const I = w("FmTabs"), B = w("FmTable"), oe = w("FmDatePicker"), r = w("FmButton"), y = w("FmDialog");
997
+ return n(), M(ve, {
998
+ actions: W.value,
999
+ title: i(S)("inventory.closing.history.title"),
1000
+ "onClick:action": K
1001
+ }, {
1002
+ default: T(() => [
1003
+ o("div", zt, [
1004
+ _(be, {
1005
+ "change-location": "",
1006
+ "hide-filter-options": !0
1007
+ }),
1008
+ _(I, {
1009
+ "model-value": V.value,
1010
+ "onUpdate:modelValue": u[0] || (u[0] = (R) => V.value = R),
1011
+ items: $
1012
+ }, null, 8, ["model-value"]),
1013
+ V.value === "closings" ? (n(), p(z, { key: 0 }, [
1014
+ u[9] || (u[9] = o("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Displaying the last 30 closing records. Click on a row to view details. ", -1)),
1015
+ _(B, {
1016
+ loading: m.value,
1017
+ "row-data": f.value,
1018
+ "column-defs": q,
1019
+ onRowClick: u[1] || (u[1] = (R) => te(R.original))
1020
+ }, null, 8, ["loading", "row-data"])
1021
+ ], 64)) : b("", !0),
1022
+ V.value === "snapshots" ? (n(), p(z, { key: 1 }, [
1023
+ u[10] || (u[10] = o("div", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Displaying the last 30 stock snapshot records. Snapshots are generated based on adjustments from the last 60 days. Click on a row to view details. ", -1)),
1024
+ _(B, {
1025
+ loading: v.value,
1026
+ "row-data": F.value,
1027
+ "column-defs": ee,
1028
+ onRowClick: u[2] || (u[2] = (R) => d(R.original))
1029
+ }, null, 8, ["loading", "row-data"])
1030
+ ], 64)) : b("", !0)
1031
+ ]),
1032
+ (n(), M(pe, { to: "body" }, [
1033
+ _(et, {
1034
+ "show-button": !1,
1035
+ ref_key: "recalculationDialogRef",
1036
+ ref: Y,
1037
+ onSubmitted: u[3] || (u[3] = (R) => H())
1038
+ }, null, 512),
1039
+ _(It, {
1040
+ "show-button": !1,
1041
+ ref_key: "snapshotRecalculationDialogRef",
1042
+ ref: G,
1043
+ onSubmitted: u[4] || (u[4] = (R) => j())
1044
+ }, null, 512),
1045
+ _(jt, {
1046
+ modelValue: a.value,
1047
+ "onUpdate:modelValue": u[5] || (u[5] = (R) => a.value = R),
1048
+ type: k.value,
1049
+ data: A.value
1050
+ }, null, 8, ["modelValue", "type", "data"]),
1051
+ _(y, {
1052
+ modelValue: E.value,
1053
+ "onUpdate:modelValue": u[8] || (u[8] = (R) => E.value = R),
1054
+ "close-button": "",
1055
+ dismissAway: "",
1056
+ "max-width": "400px"
1057
+ }, {
1058
+ "dialog-header": T(() => u[11] || (u[11] = [
1059
+ o("div", { class: "fm-typo-en-heading-lg-600" }, "Initiate Stock Snapshot", -1)
1060
+ ])),
1061
+ default: T(() => [
1062
+ o("div", Wt, [
1063
+ u[12] || (u[12] = o("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, " Create a stock snapshot for the selected date. The snapshot will capture stock balances based on adjustments from the last 60 days before the selected date. ", -1)),
1064
+ _(oe, {
1065
+ modelValue: x.value,
1066
+ "onUpdate:modelValue": u[6] || (u[6] = (R) => x.value = R),
1067
+ label: "Snapshot Date",
1068
+ max: i(J)
1069
+ }, null, 8, ["modelValue", "max"])
1070
+ ])
1071
+ ]),
1072
+ "dialog-footer": T(() => [
1073
+ o("div", Yt, [
1074
+ _(r, {
1075
+ variant: "tertiary",
1076
+ onClick: u[7] || (u[7] = (R) => E.value = !1),
1077
+ label: "Cancel",
1078
+ disabled: N.value
1079
+ }, null, 8, ["disabled"]),
1080
+ _(r, {
1081
+ variant: "primary",
1082
+ onClick: Q,
1083
+ label: "Confirm",
1084
+ loading: N.value
1085
+ }, null, 8, ["loading"])
1086
+ ])
1087
+ ]),
1088
+ _: 1
1089
+ }, 8, ["modelValue"])
1090
+ ]))
1091
+ ]),
1092
+ _: 1
1093
+ }, 8, ["actions", "title"]);
1094
+ };
1095
+ }
1096
+ });
1097
+ export {
1098
+ lo as default
1099
+ };