@feedmepos/mf-inventory-portal 1.2.64 → 1.2.66-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/dist/{App-apJIvz1w.js → App-BUNonuLz.js} +82 -78
  2. package/dist/{ApprovalView-CnT6gEI8.js → ApprovalView-BlS1tfbh.js} +6 -6
  3. package/dist/{BindingsDialog-DLEGDbV2.js → BindingsDialog-tRpsVTm0.js} +5 -5
  4. package/dist/{BindingsPicker-1Xt1vCu9.js → BindingsPicker-CUvkqcAG.js} +3 -3
  5. package/dist/{BindingsTable-_0cOM0Kx.js → BindingsTable-B86pWYMk.js} +5 -5
  6. package/dist/{ClosingDraftView-DsVPsN87.js → ClosingDraftView-gMVnQcWw.js} +226 -224
  7. package/dist/ClosingHistoryView-DhbE1pEl.js +1147 -0
  8. package/dist/{ClosingTemplateView-DB3F1wul.js → ClosingTemplateView-Ywbdj05y.js} +15 -15
  9. package/dist/{DeliveryOrderPrintPreview-CglCMgHc.js → DeliveryOrderPrintPreview-BPhVNc_r.js} +7 -7
  10. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-MMPTJodu.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BrPh_Nvx.js} +16 -16
  11. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CCID5O2Y.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CkUwLhut.js} +3 -3
  12. package/dist/{FmMultiselectDialog-B8xFmCsH.js → FmMultiselectDialog-C6E_KMFO.js} +1 -1
  13. package/dist/{FmMultiselectDialog-lQM1qEEW.js → FmMultiselectDialog-DBXpkw5b.js} +16 -16
  14. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-BLDz8wwK.js → FmUnitInput.vue_vue_type_script_setup_true_lang-D-ZqJ8sU.js} +23 -22
  15. package/dist/{ImportView-DeC-MPFn.js → ImportView-DV1e51qk.js} +7 -7
  16. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-BGDZlmsr.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-DkQL7hK2.js} +1 -1
  17. package/dist/{IngredientGroupView-CuFwQ8Bo.js → IngredientGroupView-CdXGO34J.js} +6 -6
  18. package/dist/{IngredientsView-CfloqEqn.js → IngredientsView-D2qffNiJ.js} +26 -25
  19. package/dist/{IntegrationView-CFU0yG6C.js → IntegrationView-RFJIHXQv.js} +19 -18
  20. package/dist/{InventoryBindingForm-i7eNurS2.js → InventoryBindingForm-CPn-IXgg.js} +1 -1
  21. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-zOo9YVJe.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-0Vrih8D5.js} +17 -16
  22. package/dist/{InventoryBindingSummary-BbHLCdjj.js → InventoryBindingSummary-B_WUQ6By.js} +1 -1
  23. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-NEPqmkHR.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BmDuR4Yb.js} +5 -5
  24. package/dist/PremiumBadge.vue_vue_type_script_setup_true_lang-DhIHSpzG.js +93 -0
  25. package/dist/{PublishView-CbwCLtph.js → PublishView-BtTSOUyL.js} +9 -9
  26. package/dist/{PurchaseOrderPrintPreview-DLhgjhHB.js → PurchaseOrderPrintPreview-CxhMPx5u.js} +11 -11
  27. package/dist/{ReceiveRequestView-CE2aQR-o.js → ReceiveRequestView-CsqEjf7r.js} +144 -142
  28. package/dist/RecipeView-DASoba97.js +1558 -0
  29. package/dist/SingleColumnLayout.vue_vue_type_script_setup_true_lang-mvRR4CrP.js +254 -0
  30. package/dist/StockView-B4Km4DgB.js +2395 -0
  31. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-D0BDdq4d.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Cki-LAZR.js} +1 -1
  32. package/dist/{SupplierView-wSzWjZLY.js → SupplierView-CrzFvBIx.js} +21 -20
  33. package/dist/{SurchargeView-G8OyE60y.js → SurchargeView-BoNWpxFY.js} +7 -7
  34. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-CROQL761.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-Dcp5vZPM.js} +3 -3
  35. package/dist/TemplatePublishDialog.vue_vue_type_script_setup_true_lang-IAknr-ye.js +292 -0
  36. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-D1AGDeEP.js → TransferDetails.vue_vue_type_script_setup_true_lang-D9aNX0oM.js} +131 -130
  37. package/dist/{TransferTemplateView-CVfi8jsk.js → TransferTemplateView-DwIU0paO.js} +23 -22
  38. package/dist/UnitCostHistoryView-Bjs4RwyR.js +651 -0
  39. package/dist/UnitDisplayControl.vue_vue_type_script_setup_true_lang-BH0PxivU.js +137 -0
  40. package/dist/{UnitView-Dn3nuQHm.js → UnitView-BbQ0jOgS.js} +12 -10
  41. package/dist/{WarehouseView-GSxQ_Ev2.js → WarehouseView-DzPttKzE.js} +6 -6
  42. package/dist/WastageTemplateView-CxyZz5JC.js +2327 -0
  43. package/dist/api/adjustment-template.d.ts +1 -0
  44. package/dist/api/closing.d.ts +2 -0
  45. package/dist/api/inventory.d.ts +126 -36
  46. package/dist/api/netsuite.d.ts +8 -1
  47. package/dist/api/stock.d.ts +5 -1
  48. package/dist/api/unit-cost-history.d.ts +28 -0
  49. package/dist/{app-CYbiMVcX.js → app-EoCCjoRh.js} +9021 -7945
  50. package/dist/app.d.ts +236 -0
  51. package/dist/app.js +1 -1
  52. package/dist/{closing-template-Dq16W8vW.js → closing-template-O_hzhisU.js} +5 -1
  53. package/dist/components/TemplatePublishDialog.d.ts +1 -0
  54. package/dist/components/inventory-binding/InventoryBinding.vue.d.ts +37 -1
  55. package/dist/components/shell/inventory/binding-dialog.vue.d.ts +14 -0
  56. package/dist/components/shell/inventory/binding-ui.vue.d.ts +16 -1
  57. package/dist/{date2-De3BHKh5.js → date2-CTHKdfXp.js} +1 -1
  58. package/dist/{dayjs.min-DxdfVXA-.js → dayjs.min-Ccv4NdEp.js} +16 -16
  59. package/dist/decimal-tRyklLh0.js +99 -0
  60. package/dist/{defineDeepModel-2n_afItE.js → defineDeepModel-rmOd66to.js} +1 -1
  61. package/dist/{duplicate-template-DM7YIgor.js → duplicate-template-k8Erwdzo.js} +1 -1
  62. package/dist/export-TmaGpV98.js +25 -0
  63. package/dist/{feature-_nNpSZuh.js → feature-D4-lt7R6.js} +94 -89
  64. package/dist/{format-time-from-id-D5HSMsS-.js → format-time-from-id-Cru7cG1h.js} +1 -1
  65. package/dist/{format-unit-display-CQUFDxVm.js → format-unit-display-DZDD796a.js} +16 -15
  66. package/dist/{import-export.helper-BoxczUsX.js → import-export.helper-BjzXGudc.js} +16 -15
  67. package/dist/{index-B6nDUCCe.js → index-BeEz64I1.js} +3 -3
  68. package/dist/{index-Cp_mpu5S.js → index-DKCY6354.js} +1471 -1412
  69. package/dist/{index-CdfF5GGW.js → index-gGbN4qbt.js} +1 -1
  70. package/dist/{lodash-2R7Rgorb.js → lodash-BSCFf0k7.js} +1 -1
  71. package/dist/{netsuite-Bss4fURp.js → netsuite-DwoCq3Mv.js} +92 -92
  72. package/dist/number-CEUoMyIk.js +138 -0
  73. package/dist/{purchase-order-template-CBSvv0b2.js → purchase-order-template-DWTdjo9l.js} +1 -1
  74. package/dist/router/name.d.ts +1 -0
  75. package/dist/rules-CyW1Bx31.js +98 -0
  76. package/dist/{stock-DMX_hH5c.js → stock-DYWJ4DZW.js} +28 -27
  77. package/dist/stock-Ds3GNgHG.js +75 -0
  78. package/dist/stores/feature.d.ts +2 -0
  79. package/dist/stores/integration/netsuite.d.ts +8 -1
  80. package/dist/stores/inventory.d.ts +120 -30
  81. package/dist/{supplier-Cf5HW15s.js → supplier-DwUb1oVo.js} +2 -2
  82. package/dist/{surcharge-CyReT8lG.js → surcharge-UTJFNBLN.js} +1 -1
  83. package/dist/tsconfig.app.tsbuildinfo +1 -1
  84. package/dist/{use-ingredient-select-dialog-BCyydlHR.js → use-ingredient-select-dialog-D8A3bPTe.js} +2 -2
  85. package/dist/{use-inventory-binding-dialog-WGQs-_2i.js → use-inventory-binding-dialog-DFmiAQ9d.js} +2 -2
  86. package/dist/{use-template-enabled-locations-2-B0nlqUjb.js → use-template-enabled-locations-2-snlITfW8.js} +2 -2
  87. package/dist/views/adjustment-template/wastage-template/table.d.ts +10 -1
  88. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +68 -12
  89. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +204 -36
  90. package/dist/views/closing-history/ClosingDetailDialog.vue.d.ts +23 -0
  91. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +8 -1
  92. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +96 -12
  93. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +96 -12
  94. package/dist/views/ingredient-group/composables/use-ingredient-group-table.d.ts +18 -18
  95. package/dist/views/ingredients/components/convert/ConvertForm.vue.d.ts +14 -0
  96. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +32 -4
  97. package/dist/views/ingredients/components/inventory-binding/InventoryBindingForm.vue.d.ts +28 -0
  98. package/dist/views/ingredients/components/inventory-binding/v2/InventoryBindingFormV2.vue.d.ts +169 -0
  99. package/dist/views/ingredients/components/inventory-binding/v2/components/InventoryBindingAlternative.vue.d.ts +43 -0
  100. package/dist/views/ingredients/components/inventory-binding/v2/components/InventoryBindingRule.vue.d.ts +25 -0
  101. package/dist/views/ingredients/components/inventory-binding/v2/components/InventoryRecipeBindingV2Field.vue.d.ts +125 -0
  102. package/dist/views/ingredients/components/inventory-binding/v2/components/InventorySkuBindingV2Field.vue.d.ts +129 -0
  103. package/dist/views/ingredients/components/inventory-binding/v2/composables/use-inventory-binding-alternative-table.d.ts +30 -0
  104. package/dist/views/ingredients/components/inventory-binding/v2/composables/use-inventory-binding-dialog.d.ts +4 -0
  105. package/dist/views/ingredients/composables/use-ingredient-table.d.ts +8 -1
  106. package/dist/views/integration/components/netsuite/InventoryTransferIngredientTable.vue.d.ts +16 -2
  107. package/dist/views/receive-request/components/transfer-form/TransferFormWithController.vue.d.ts +33 -5
  108. package/dist/views/receive-request/components/transfer-form/components/ForecastStock.vue.d.ts +16 -2
  109. package/dist/views/receive-request/components/transfer-form/components/TransferItemTable.vue.d.ts +32 -4
  110. package/dist/views/receive-request/components/transfer-form/composables/use-transfer-items.d.ts +8 -1
  111. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +41 -6
  112. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +246 -36
  113. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +287 -42
  114. package/dist/views/recipe/components/recipe-form/RecipeForm.vue.d.ts +16 -0
  115. package/dist/views/stock/components/StockRecordCard.vue.d.ts +1 -0
  116. package/dist/views/stock/components/dialog/AdjustedItemForm.vue.d.ts +16 -2
  117. package/dist/views/stock/components/dialog/SnapshotRecalculationDialog.vue.d.ts +11 -0
  118. package/dist/views/stock/components/dialog/recalculationUtils.d.ts +16 -0
  119. package/dist/views/transfer-template/components/transfer-template-dialog/TransferTemplateDialog.vue.d.ts +16 -2
  120. package/dist/views/transfer-template/components/transfer-template-form/components/NetSuiteCustomCodeSelection.vue.d.ts +16 -2
  121. package/dist/views/transfer-template/components/transfer-template-form/components/TransferTemplateItemTable.vue.d.ts +16 -2
  122. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.d.ts +8 -1
  123. package/dist/views/transfer-template/composables/use-netsuite-custom-field.d.ts +24 -3
  124. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +96 -12
  125. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +96 -12
  126. package/dist/views/unit-cost-history/UnitCostHistoryView.vue.d.ts +2 -0
  127. package/dist/views/unit-cost-history/components/UnitCostDetailsSideSheet.vue.d.ts +19 -0
  128. package/dist/views/unit-cost-history/components/UnitCostRecalculationDialog.vue.d.ts +11 -0
  129. package/dist/views/unit-cost-history/composables/use-unit-cost-history.d.ts +65 -0
  130. package/dist/{vue-i18n-DwS_fjo9.js → vue-i18n-CY4442Fb.js} +510 -510
  131. package/dist/{xlsx-9MOvXxhT.js → xlsx-Kc1XotGV.js} +1 -1
  132. package/dist/{xlsx.util-D1DdGA1N.js → xlsx.util-Dy4jmPyv.js} +1 -1
  133. package/package.json +1 -1
  134. package/dist/ClosingHistoryView-YrEVWvGu.js +0 -447
  135. package/dist/PremiumBadge.vue_vue_type_script_setup_true_lang-BDVHkTSE.js +0 -116
  136. package/dist/RecipeView-B-gmrXHR.js +0 -646
  137. package/dist/SingleColumnLayout.vue_vue_type_script_setup_true_lang-CWZkVCAj.js +0 -251
  138. package/dist/StockView-BNe2_5bA.js +0 -2520
  139. package/dist/TemplatePublishDialog.vue_vue_type_script_setup_true_lang-CwV2luel.js +0 -263
  140. package/dist/WastageTemplateView-BG-y48uc.js +0 -2388
  141. package/dist/rules-T-fs8_4_.js +0 -327
  142. package/dist/stock-CFWu5bRA.js +0 -75
@@ -0,0 +1,1147 @@
1
+ import { defineComponent as le, ref as g, computed as V, watch as me, resolveComponent as $, openBlock as d, createElementBlock as y, createVNode as h, withModifiers as fe, withCtx as B, createElementVNode as n, toDisplayString as i, unref as c, Fragment as j, createTextVNode as Z, createBlock as z, createCommentVNode as D, renderList as ne, normalizeClass as pe, h as X, Teleport as ge } from "vue";
2
+ import { F as de, _ as he } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-mvRR4CrP.js";
3
+ import { useI18n as se, useCoreStore as _e } from "@feedmepos/mf-common";
4
+ import { D as P, H as ce, a as be, u as ke } from "./app-EoCCjoRh.js";
5
+ import { _ as xe } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CkUwLhut.js";
6
+ import { useSnackbar as re, useDialog as De } from "@feedmepos/ui-library";
7
+ import { u as ye } from "./stock-DYWJ4DZW.js";
8
+ import { _ as Se } from "./UnitDisplayControl.vue_vue_type_script_setup_true_lang-BH0PxivU.js";
9
+ function ie(I) {
10
+ return Math.floor(I.getTime() / 1e3) * 1e3;
11
+ }
12
+ function ue(I) {
13
+ const k = [
14
+ "Jan",
15
+ "Feb",
16
+ "Mar",
17
+ "Apr",
18
+ "May",
19
+ "Jun",
20
+ "Jul",
21
+ "Aug",
22
+ "Sep",
23
+ "Oct",
24
+ "Nov",
25
+ "Dec"
26
+ ], x = I.getFullYear(), L = k[I.getMonth()], o = I.getDate();
27
+ let _ = I.getHours();
28
+ const A = I.getMinutes().toString().padStart(2, "0"), p = I.getSeconds().toString().padStart(2, "0"), u = _ >= 12 ? "PM" : "AM";
29
+ return _ = _ % 12, _ = _ || 12, `${x} ${L} ${o} ${_}:${A}:${p} ${u}`;
30
+ }
31
+ function ve(I, k = []) {
32
+ const x = I.map((p) => {
33
+ const u = P(p._id), s = new Date(u);
34
+ return {
35
+ label: "",
36
+ // Will be set after grouping
37
+ value: p._id,
38
+ type: "closing",
39
+ date: s
40
+ };
41
+ }), L = k.map((p) => {
42
+ const u = P(p._id), s = new Date(u);
43
+ return {
44
+ label: "",
45
+ // Will be set after grouping
46
+ value: p._id,
47
+ type: "snapshot",
48
+ date: s
49
+ };
50
+ }), o = [...x, ...L].sort(
51
+ (p, u) => u.date.getTime() - p.date.getTime()
52
+ ), _ = /* @__PURE__ */ new Map();
53
+ for (const p of o) {
54
+ const u = ie(p.date);
55
+ _.has(u) || _.set(u, []), _.get(u).push(p);
56
+ }
57
+ const A = k.length > 0;
58
+ for (const [, p] of _)
59
+ if (p.length > 1)
60
+ p.sort((u, s) => u.date.getTime() - s.date.getTime()), p.forEach((u, s) => {
61
+ const r = A ? u.type === "closing" ? " (Closing)" : " (Snapshot)" : "";
62
+ u.label = `${ue(u.date)}${r} (Rev ${s + 1})`;
63
+ });
64
+ else {
65
+ const u = p[0], s = A ? u.type === "closing" ? " (Closing)" : " (Snapshot)" : "";
66
+ u.label = `${ue(u.date)}${s}`;
67
+ }
68
+ return o.sort((p, u) => {
69
+ const s = ie(p.date), r = ie(u.date);
70
+ return s !== r ? r - s : u.date.getTime() - p.date.getTime();
71
+ });
72
+ }
73
+ const we = { class: "fm-typo-en-heading-lg-600" }, $e = { 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" }, Ae = { class: "fm-typo-en-body-md-600" }, Fe = { class: "flex flex-col gap-8" }, Te = { class: "fm-typo-en-body-md-600" }, Re = { class: "flex items-center gap-8 mb-8" }, Ie = {
74
+ key: 2,
75
+ class: "text-red-500 text-sm mt-2"
76
+ }, Be = { class: "fm-typo-en-body-sm-400" }, Le = {
77
+ key: 1,
78
+ class: "p-12 border border-fm-color-border-primary rounded-8 bg-fm-color-background-secondary"
79
+ }, Oe = {
80
+ key: 0,
81
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
82
+ }, Ee = {
83
+ key: 1,
84
+ class: "flex flex-col gap-8"
85
+ }, Me = { class: "fm-typo-en-body-sm-600" }, Pe = { class: "flex flex-col gap-4" }, Ue = { key: 0 }, Ne = {
86
+ key: 1,
87
+ class: "flex flex-col gap-8"
88
+ }, Ke = { class: "fm-typo-en-body-md-600" }, He = { class: "flex flex-col gap-8 max-h-[300px] overflow-y-auto" }, je = { class: "flex items-center justify-between" }, ze = { class: "fm-typo-en-body-sm-600" }, Je = { class: "flex items-center gap-8" }, We = {
89
+ key: 0,
90
+ class: "fm-typo-en-body-xs-600 px-8 py-4 rounded-4 bg-fm-color-neutral-100 text-fm-color-typo-secondary"
91
+ }, 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" }, Qe = {
92
+ key: 0,
93
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
94
+ }, Xe = {
95
+ key: 1,
96
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
97
+ }, Ze = {
98
+ key: 2,
99
+ class: "fm-typo-en-body-xs-400 text-fm-color-system-error-500"
100
+ }, qe = {
101
+ key: 0,
102
+ class: "flex gap-8 ml-auto"
103
+ }, et = {
104
+ key: 1,
105
+ class: "flex gap-8 ml-auto"
106
+ }, tt = /* @__PURE__ */ le({
107
+ __name: "RecalculationDialog",
108
+ emits: ["submitted"],
109
+ setup(I, { expose: k, emit: x }) {
110
+ const L = x, { t: o } = se(), _ = ye(), A = ce(), p = re(), u = g(!1), s = g(""), r = g(""), T = g(!1), v = g([]), l = g(!1), S = g([]), C = g(!1), b = g([]), w = g(!1), J = V(() => ve(v.value)), G = V(() => {
111
+ if (!s.value) return [];
112
+ const e = J.value.find((a) => a.value === s.value);
113
+ return e ? J.value.filter((a) => a.date.getTime() > e.date.getTime()).sort((a, F) => F.date.getTime() - a.date.getTime()) : [];
114
+ }), U = V({
115
+ get: () => {
116
+ if (T.value && r.value) {
117
+ const e = v.value.find((a) => P(a._id) === r.value);
118
+ return (e == null ? void 0 : e._id) || r.value;
119
+ }
120
+ return r.value;
121
+ },
122
+ set: (e) => {
123
+ T.value && e ? r.value = P(e) : r.value = e;
124
+ }
125
+ }), q = V(() => {
126
+ if (s.value)
127
+ try {
128
+ const e = P(s.value);
129
+ if (e)
130
+ return e;
131
+ } catch (e) {
132
+ console.error("Error parsing date from closing ID:", e);
133
+ }
134
+ }), O = V(() => {
135
+ if (!s.value || !r.value) return "";
136
+ const e = P(s.value), a = r.value;
137
+ if (e && a) {
138
+ const F = new Date(e).getTime();
139
+ if (new Date(a).getTime() <= F)
140
+ return o("inventory.stock.recalculation.error.endDateBeforeOpening");
141
+ }
142
+ return "";
143
+ }), N = V(() => !!s.value && !!r.value && !O.value), W = V(() => S.value.some(
144
+ (e) => !e.completedAt && !e.failedReason
145
+ ));
146
+ async function Q() {
147
+ u.value = !0, await Promise.all([te(), K()]), s.value = "", r.value = "", T.value = !1;
148
+ }
149
+ function ee() {
150
+ u.value = !1;
151
+ }
152
+ k({
153
+ open: Q,
154
+ close: ee
155
+ });
156
+ async function te() {
157
+ l.value = !0;
158
+ try {
159
+ const e = await A.getLastNClosings(30);
160
+ v.value = e;
161
+ } catch (e) {
162
+ console.error("Error fetching recent closings:", e), p.open({
163
+ title: o("common.error"),
164
+ message: "Failed to fetch recent closings",
165
+ type: "error"
166
+ });
167
+ } finally {
168
+ l.value = !1;
169
+ }
170
+ }
171
+ async function K() {
172
+ C.value = !0;
173
+ try {
174
+ const e = await _.recalculation.recalculationRequests();
175
+ S.value = e;
176
+ } catch (e) {
177
+ console.error("Error fetching recalculation requests:", e);
178
+ } finally {
179
+ C.value = !1;
180
+ }
181
+ }
182
+ async function H() {
183
+ if (!s.value || !r.value) {
184
+ b.value = [];
185
+ return;
186
+ }
187
+ w.value = !0;
188
+ try {
189
+ const e = await _.recalculation.getAffectedClosingDrafts(
190
+ s.value,
191
+ r.value
192
+ );
193
+ b.value = e;
194
+ } catch {
195
+ p.open({
196
+ title: o("common.error"),
197
+ message: "Failed to fetch affected closing drafts",
198
+ type: "error"
199
+ }), b.value = [];
200
+ } finally {
201
+ w.value = !1;
202
+ }
203
+ }
204
+ me(
205
+ [s, r],
206
+ () => {
207
+ s.value && r.value && !O.value ? H() : b.value = [];
208
+ },
209
+ { immediate: !1 }
210
+ );
211
+ async function oe() {
212
+ if (N.value) {
213
+ l.value = !0;
214
+ try {
215
+ if (await _.recalculation.scheduleRecalculation({
216
+ openingId: s.value,
217
+ untilDate: r.value
218
+ }), b.value.length > 0) {
219
+ const e = b.value.map((a) => a._id);
220
+ await _.recalculation.scheduleInvalidateClosingDraftCache(e);
221
+ }
222
+ p.open({
223
+ title: o("common.success"),
224
+ message: "Stock recalculation has been scheduled successfully",
225
+ type: "success"
226
+ }), await K(), u.value = !1, L("submitted");
227
+ } catch (e) {
228
+ console.error("Error scheduling recalculation:", e), p.open({
229
+ title: o("common.error"),
230
+ message: "Failed to schedule stock recalculation",
231
+ type: "error"
232
+ });
233
+ } finally {
234
+ l.value = !1;
235
+ }
236
+ }
237
+ }
238
+ return (e, a) => {
239
+ const F = $("FmButton"), m = $("FmSelect"), f = $("FmRadio"), R = $("FmDatePicker"), E = $("FmAlert"), ae = $("FmDialog");
240
+ return d(), y("div", null, [
241
+ h(F, {
242
+ "prepend-icon": "info",
243
+ variant: "tertiary",
244
+ onClick: fe(Q, ["stop"])
245
+ }),
246
+ h(ae, {
247
+ modelValue: u.value,
248
+ "onUpdate:modelValue": a[7] || (a[7] = (t) => u.value = t),
249
+ "close-button": "",
250
+ dismissAway: "",
251
+ "max-width": "600px"
252
+ }, {
253
+ "dialog-header": B(() => [
254
+ n("div", we, i(c(o)("inventory.stock.recalculation.title")), 1)
255
+ ]),
256
+ "dialog-footer": B(() => [
257
+ W.value ? (d(), y("div", et, [
258
+ h(F, {
259
+ variant: "tertiary",
260
+ onClick: a[6] || (a[6] = (t) => u.value = !1),
261
+ label: c(o)("common.close")
262
+ }, null, 8, ["label"])
263
+ ])) : (d(), y("div", qe, [
264
+ h(F, {
265
+ variant: "tertiary",
266
+ onClick: a[5] || (a[5] = (t) => u.value = !1),
267
+ disabled: l.value,
268
+ label: c(o)("common.cancel")
269
+ }, null, 8, ["disabled", "label"]),
270
+ h(F, {
271
+ variant: "primary",
272
+ onClick: oe,
273
+ disabled: !N.value || l.value,
274
+ loading: l.value,
275
+ label: c(o)("inventory.stock.recalculation.schedule")
276
+ }, null, 8, ["disabled", "loading", "label"])
277
+ ]))
278
+ ]),
279
+ default: B(() => [
280
+ n("div", $e, [
281
+ n("div", Ce, i(c(o)("inventory.stock.recalculation.description")), 1),
282
+ W.value ? D("", !0) : (d(), y(j, { key: 0 }, [
283
+ n("div", Ve, [
284
+ n("p", Ae, [
285
+ Z(i(c(o)("inventory.stock.recalculation.openingDate")) + " ", 1),
286
+ a[8] || (a[8] = n("span", { class: "text-fm-color-system-error-300" }, "*", -1))
287
+ ]),
288
+ a[9] || (a[9] = n("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)),
289
+ h(m, {
290
+ modelValue: s.value,
291
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => s.value = t),
292
+ items: J.value,
293
+ placeholder: c(o)("inventory.stock.recalculation.selectOpening"),
294
+ loading: l.value,
295
+ disabled: l.value
296
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])
297
+ ]),
298
+ n("div", Fe, [
299
+ n("p", Te, [
300
+ Z(i(c(o)("inventory.stock.recalculation.untilDate")) + " ", 1),
301
+ a[10] || (a[10] = n("span", { class: "text-fm-color-system-error-300" }, "*", -1))
302
+ ]),
303
+ n("div", Re, [
304
+ h(f, {
305
+ modelValue: T.value,
306
+ "onUpdate:modelValue": a[1] || (a[1] = (t) => T.value = t),
307
+ value: !1,
308
+ label: c(o)("inventory.stock.recalculation.selectByDate")
309
+ }, null, 8, ["modelValue", "label"]),
310
+ h(f, {
311
+ modelValue: T.value,
312
+ "onUpdate:modelValue": a[2] || (a[2] = (t) => T.value = t),
313
+ value: !0,
314
+ label: c(o)("inventory.stock.recalculation.selectByClosing")
315
+ }, null, 8, ["modelValue", "label"])
316
+ ]),
317
+ T.value ? (d(), z(m, {
318
+ key: 1,
319
+ modelValue: U.value,
320
+ "onUpdate:modelValue": a[4] || (a[4] = (t) => U.value = t),
321
+ items: G.value,
322
+ placeholder: c(o)("inventory.stock.recalculation.selectClosing"),
323
+ loading: l.value,
324
+ disabled: !s.value || l.value
325
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])) : (d(), z(R, {
326
+ key: 0,
327
+ modelValue: r.value,
328
+ "onUpdate:modelValue": a[3] || (a[3] = (t) => r.value = t),
329
+ placeholder: c(o)("inventory.stock.recalculation.selectDate"),
330
+ min: q.value,
331
+ disabled: !s.value || l.value
332
+ }, null, 8, ["modelValue", "placeholder", "min", "disabled"])),
333
+ O.value ? (d(), y("div", Ie, i(O.value), 1)) : D("", !0)
334
+ ]),
335
+ s.value && r.value && !O.value ? (d(), z(E, {
336
+ key: 0,
337
+ type: "info"
338
+ }, {
339
+ default: B(() => [
340
+ n("div", Be, i(c(o)("inventory.stock.recalculation.info")), 1)
341
+ ]),
342
+ _: 1
343
+ })) : D("", !0),
344
+ b.value.length > 0 ? (d(), y("div", Le, [
345
+ w.value ? (d(), y("div", Oe, " Loading affected closing drafts... ")) : (d(), y("div", Ee, [
346
+ n("div", Me, " Affected closing draft(s): " + i(b.value.length), 1),
347
+ n("div", Pe, [
348
+ (d(!0), y(j, null, ne(b.value, (t) => (d(), y("div", {
349
+ key: t._id,
350
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
351
+ }, [
352
+ Z(" • " + i(t._id) + " ", 1),
353
+ t.effectiveAt ? (d(), y("span", Ue, " (" + i(new Date(t.effectiveAt).toLocaleString()) + ") ", 1)) : D("", !0)
354
+ ]))), 128))
355
+ ])
356
+ ]))
357
+ ])) : D("", !0)
358
+ ], 64)),
359
+ S.value.length > 0 ? (d(), y("div", Ne, [
360
+ n("p", Ke, i(c(o)("inventory.stock.recalculation.recentRequests")), 1),
361
+ n("div", He, [
362
+ (d(!0), y(j, null, ne(S.value, (t) => {
363
+ var Y;
364
+ return d(), y("div", {
365
+ key: t._id,
366
+ class: "p-12 border border-fm-color-border-primary rounded-8 flex flex-col gap-4"
367
+ }, [
368
+ n("div", je, [
369
+ n("div", ze, i(c(o)("inventory.stock.recalculation.requestedAt")) + ": " + i(new Date(t.createdAt).toLocaleString()), 1),
370
+ n("div", Je, [
371
+ (Y = t.meta) != null && Y.openingType ? (d(), y("div", We, i(t.meta.openingType === "stockSnapshot" ? "Snapshot" : "Closing"), 1)) : D("", !0),
372
+ n("div", {
373
+ class: pe(["fm-typo-en-body-xs-600 px-8 py-4 rounded-4", {
374
+ "bg-fm-color-system-error-100 text-fm-color-system-error-500": t.failedReason,
375
+ "bg-fm-color-system-success-100 text-fm-color-system-success-500": t.completedAt,
376
+ "bg-fm-color-system-info-100 text-fm-color-system-info-500": !t.failedReason && !t.completedAt
377
+ }])
378
+ }, i(t.failedReason ? c(o)("inventory.stock.recalculation.status.failed") : t.completedAt ? c(o)("inventory.stock.recalculation.status.completed") : c(o)("inventory.stock.recalculation.status.inProgress")), 3)
379
+ ])
380
+ ]),
381
+ n("div", Ye, i(c(o)("inventory.stock.recalculation.from")) + ": " + i(new Date(t.recalculateStartDate).toLocaleDateString()), 1),
382
+ n("div", Ge, i(c(o)("inventory.stock.recalculation.to")) + ": " + i(new Date(t.recalculateEndDate).toLocaleDateString()), 1),
383
+ t.createdBy ? (d(), y("div", Qe, i(c(o)("inventory.stock.recalculation.requestedBy")) + ": " + i(t.createdBy.name || t.createdBy.id), 1)) : D("", !0),
384
+ t.completedAt ? (d(), y("div", Xe, i(c(o)("inventory.stock.recalculation.completedAt")) + ": " + i(new Date(t.completedAt).toLocaleString()), 1)) : D("", !0),
385
+ t.failedReason ? (d(), y("div", Ze, i(t.failedReason), 1)) : D("", !0)
386
+ ]);
387
+ }), 128))
388
+ ])
389
+ ])) : D("", !0)
390
+ ])
391
+ ]),
392
+ _: 1
393
+ }, 8, ["modelValue"])
394
+ ]);
395
+ };
396
+ }
397
+ }), ot = { class: "fm-typo-en-heading-lg-600" }, at = { class: "flex flex-col gap-16" }, nt = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, lt = { class: "flex flex-col gap-8" }, st = { class: "fm-typo-en-body-md-600" }, it = { class: "flex flex-col gap-8" }, ct = { class: "fm-typo-en-body-md-600" }, rt = {
398
+ key: 0,
399
+ class: "text-red-500 text-sm mt-2"
400
+ }, dt = { class: "fm-typo-en-body-sm-400" }, ut = {
401
+ key: 1,
402
+ class: "p-12 border border-fm-color-border-primary rounded-8 bg-fm-color-background-secondary"
403
+ }, mt = {
404
+ key: 0,
405
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
406
+ }, ft = {
407
+ key: 1,
408
+ class: "flex flex-col gap-8"
409
+ }, pt = { class: "fm-typo-en-body-sm-600" }, yt = { class: "flex flex-col gap-4" }, vt = { key: 0 }, gt = {
410
+ key: 1,
411
+ class: "flex flex-col gap-8"
412
+ }, ht = { class: "fm-typo-en-body-md-600" }, _t = { class: "flex flex-col gap-8 max-h-[300px] overflow-y-auto" }, bt = { class: "flex items-center justify-between" }, kt = { class: "fm-typo-en-body-sm-600" }, xt = { class: "flex items-center gap-8" }, Dt = {
413
+ key: 0,
414
+ class: "fm-typo-en-body-xs-600 px-8 py-4 rounded-4 bg-fm-color-neutral-100 text-fm-color-typo-secondary"
415
+ }, St = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, wt = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, $t = {
416
+ key: 0,
417
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
418
+ }, Ct = {
419
+ key: 1,
420
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
421
+ }, Vt = {
422
+ key: 2,
423
+ class: "fm-typo-en-body-xs-400 text-fm-color-system-error-500"
424
+ }, At = {
425
+ key: 0,
426
+ class: "flex gap-8 ml-auto"
427
+ }, Ft = {
428
+ key: 1,
429
+ class: "flex gap-8 ml-auto"
430
+ }, Tt = /* @__PURE__ */ le({
431
+ __name: "SnapshotRecalculationDialog",
432
+ emits: ["submitted"],
433
+ setup(I, { expose: k, emit: x }) {
434
+ const L = x, { t: o } = se(), _ = ye(), A = ce(), p = re(), u = g(!1), s = g(""), r = g(""), T = g([]), v = g([]), l = g(!1), S = g([]), C = g(!1), b = g([]), w = g(!1), J = V(
435
+ () => ve(T.value, v.value)
436
+ ), G = V(() => {
437
+ if (s.value)
438
+ try {
439
+ const e = P(s.value);
440
+ if (e)
441
+ return e;
442
+ } catch (e) {
443
+ console.error("Error parsing date from opening ID:", e);
444
+ }
445
+ }), U = V(() => {
446
+ if (!s.value || !r.value) return "";
447
+ const e = P(s.value);
448
+ if (e && r.value) {
449
+ const a = new Date(e).getTime();
450
+ if (new Date(r.value).getTime() <= a)
451
+ return o("inventory.stock.recalculation.error.endDateBeforeOpening");
452
+ }
453
+ return "";
454
+ }), q = V(() => {
455
+ if (!r.value) return !1;
456
+ const e = new Date(r.value), a = /* @__PURE__ */ new Date();
457
+ return a.setHours(0, 0, 0, 0), e.setHours(0, 0, 0, 0), e >= a;
458
+ }), O = V(() => !!s.value && !!r.value && !U.value), N = V(() => S.value.some(
459
+ (e) => !e.completedAt && !e.failedReason
460
+ ));
461
+ async function W() {
462
+ u.value = !0, await Promise.all([ee(), te(), K()]), s.value = "", r.value = "";
463
+ }
464
+ function Q() {
465
+ u.value = !1;
466
+ }
467
+ k({
468
+ open: W,
469
+ close: Q
470
+ });
471
+ async function ee() {
472
+ l.value = !0;
473
+ try {
474
+ const e = await A.getLastNClosings(30);
475
+ T.value = e;
476
+ } catch (e) {
477
+ console.error("Error fetching recent closings:", e), p.open({
478
+ title: o("common.error"),
479
+ message: "Failed to fetch recent closings",
480
+ type: "error"
481
+ });
482
+ } finally {
483
+ l.value = !1;
484
+ }
485
+ }
486
+ async function te() {
487
+ try {
488
+ const e = await A.getLastNStockSnapshots(30);
489
+ v.value = e;
490
+ } catch (e) {
491
+ console.error("Error fetching recent snapshots:", e);
492
+ }
493
+ }
494
+ async function K() {
495
+ C.value = !0;
496
+ try {
497
+ const e = await _.recalculation.recalculationRequests();
498
+ S.value = e;
499
+ } catch (e) {
500
+ console.error("Error fetching recalculation requests:", e);
501
+ } finally {
502
+ C.value = !1;
503
+ }
504
+ }
505
+ async function H() {
506
+ if (!s.value || !r.value) {
507
+ b.value = [];
508
+ return;
509
+ }
510
+ w.value = !0;
511
+ try {
512
+ const e = new Date(r.value);
513
+ e.setHours(23, 59, 59, 999);
514
+ const a = await _.recalculation.getAffectedClosingDrafts(
515
+ s.value,
516
+ e.toISOString()
517
+ );
518
+ b.value = a;
519
+ } catch {
520
+ p.open({
521
+ title: o("common.error"),
522
+ message: "Failed to fetch affected closing drafts",
523
+ type: "error"
524
+ }), b.value = [];
525
+ } finally {
526
+ w.value = !1;
527
+ }
528
+ }
529
+ me(
530
+ [s, r],
531
+ () => {
532
+ s.value && r.value && !U.value ? H() : b.value = [];
533
+ },
534
+ { immediate: !1 }
535
+ );
536
+ async function oe() {
537
+ if (!(!O.value || !r.value)) {
538
+ l.value = !0;
539
+ try {
540
+ if (await _.recalculation.scheduleRecalculation({
541
+ openingId: s.value,
542
+ untilDate: new Date(r.value).toISOString(),
543
+ recalculateBySnapshot: !0
544
+ }), b.value.length > 0) {
545
+ const e = b.value.map((a) => a._id);
546
+ await _.recalculation.scheduleInvalidateClosingDraftCache(e);
547
+ }
548
+ p.open({
549
+ title: o("common.success"),
550
+ message: "Stock recalculation has been scheduled successfully",
551
+ type: "success"
552
+ }), await K(), u.value = !1, L("submitted");
553
+ } catch (e) {
554
+ console.error("Error scheduling recalculation:", e), p.open({
555
+ title: o("common.error"),
556
+ message: "Failed to schedule stock recalculation",
557
+ type: "error"
558
+ });
559
+ } finally {
560
+ l.value = !1;
561
+ }
562
+ }
563
+ }
564
+ return (e, a) => {
565
+ const F = $("FmButton"), m = $("FmSelect"), f = $("FmDatePicker"), R = $("FmSnackbar"), E = $("FmAlert"), ae = $("FmDialog");
566
+ return d(), y("div", null, [
567
+ h(F, {
568
+ "prepend-icon": "info",
569
+ variant: "tertiary",
570
+ onClick: fe(W, ["stop"])
571
+ }),
572
+ h(ae, {
573
+ modelValue: u.value,
574
+ "onUpdate:modelValue": a[4] || (a[4] = (t) => u.value = t),
575
+ "close-button": "",
576
+ dismissAway: "",
577
+ "max-width": "600px"
578
+ }, {
579
+ "dialog-header": B(() => [
580
+ n("div", ot, i(c(o)("inventory.stock.recalculation.title")), 1)
581
+ ]),
582
+ "dialog-footer": B(() => [
583
+ N.value ? (d(), y("div", Ft, [
584
+ h(F, {
585
+ variant: "tertiary",
586
+ onClick: a[3] || (a[3] = (t) => u.value = !1),
587
+ label: c(o)("common.close")
588
+ }, null, 8, ["label"])
589
+ ])) : (d(), y("div", At, [
590
+ h(F, {
591
+ variant: "tertiary",
592
+ onClick: a[2] || (a[2] = (t) => u.value = !1),
593
+ disabled: l.value,
594
+ label: c(o)("common.cancel")
595
+ }, null, 8, ["disabled", "label"]),
596
+ h(F, {
597
+ variant: "primary",
598
+ onClick: oe,
599
+ disabled: !O.value || l.value,
600
+ loading: l.value,
601
+ label: c(o)("inventory.stock.recalculation.schedule")
602
+ }, null, 8, ["disabled", "loading", "label"])
603
+ ]))
604
+ ]),
605
+ default: B(() => [
606
+ n("div", at, [
607
+ n("div", nt, i(c(o)("inventory.stock.recalculation.description")), 1),
608
+ N.value ? D("", !0) : (d(), y(j, { key: 0 }, [
609
+ n("div", lt, [
610
+ n("p", st, [
611
+ Z(i(c(o)("inventory.stock.recalculation.openingDate")) + " ", 1),
612
+ a[5] || (a[5] = n("span", { class: "text-fm-color-system-error-300" }, "*", -1))
613
+ ]),
614
+ a[6] || (a[6] = n("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)),
615
+ h(m, {
616
+ modelValue: s.value,
617
+ "onUpdate:modelValue": a[0] || (a[0] = (t) => s.value = t),
618
+ items: J.value,
619
+ placeholder: c(o)("inventory.stock.recalculation.selectOpening"),
620
+ loading: l.value,
621
+ disabled: l.value
622
+ }, null, 8, ["modelValue", "items", "placeholder", "loading", "disabled"])
623
+ ]),
624
+ n("div", it, [
625
+ n("p", ct, [
626
+ Z(i(c(o)("inventory.stock.recalculation.untilDate")) + " ", 1),
627
+ a[7] || (a[7] = n("span", { class: "text-fm-color-system-error-300" }, "*", -1))
628
+ ]),
629
+ a[8] || (a[8] = n("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)),
630
+ h(f, {
631
+ modelValue: r.value,
632
+ "onUpdate:modelValue": a[1] || (a[1] = (t) => r.value = t),
633
+ placeholder: c(o)("inventory.stock.recalculation.selectDate"),
634
+ min: G.value,
635
+ disabled: !s.value || l.value
636
+ }, null, 8, ["modelValue", "placeholder", "min", "disabled"]),
637
+ U.value ? (d(), y("div", rt, i(U.value), 1)) : D("", !0),
638
+ q.value ? (d(), z(R, {
639
+ key: 1,
640
+ title: "Warning",
641
+ variant: "warning",
642
+ description: "You have selected today or a future date. The stock balance will be refreshed accordingly."
643
+ })) : D("", !0)
644
+ ]),
645
+ s.value && r.value && !U.value ? (d(), z(E, {
646
+ key: 0,
647
+ type: "info"
648
+ }, {
649
+ default: B(() => [
650
+ n("div", dt, i(c(o)("inventory.stock.recalculation.info")), 1)
651
+ ]),
652
+ _: 1
653
+ })) : D("", !0),
654
+ b.value.length > 0 ? (d(), y("div", ut, [
655
+ w.value ? (d(), y("div", mt, " Loading affected closing drafts... ")) : (d(), y("div", ft, [
656
+ n("div", pt, " Affected closing draft(s): " + i(b.value.length), 1),
657
+ n("div", yt, [
658
+ (d(!0), y(j, null, ne(b.value, (t) => (d(), y("div", {
659
+ key: t._id,
660
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
661
+ }, [
662
+ Z(" • " + i(t._id) + " ", 1),
663
+ t.effectiveAt ? (d(), y("span", vt, " (" + i(new Date(t.effectiveAt).toLocaleString()) + ") ", 1)) : D("", !0)
664
+ ]))), 128))
665
+ ])
666
+ ]))
667
+ ])) : D("", !0)
668
+ ], 64)),
669
+ S.value.length > 0 ? (d(), y("div", gt, [
670
+ n("p", ht, i(c(o)("inventory.stock.recalculation.recentRequests")), 1),
671
+ n("div", _t, [
672
+ (d(!0), y(j, null, ne(S.value, (t) => {
673
+ var Y;
674
+ return d(), y("div", {
675
+ key: t._id,
676
+ class: "p-12 border border-fm-color-border-primary rounded-8 flex flex-col gap-4"
677
+ }, [
678
+ n("div", bt, [
679
+ n("div", kt, i(c(o)("inventory.stock.recalculation.requestedAt")) + ": " + i(new Date(t.createdAt).toLocaleString()), 1),
680
+ n("div", xt, [
681
+ (Y = t.meta) != null && Y.openingType ? (d(), y("div", Dt, i(t.meta.openingType === "stockSnapshot" ? "Snapshot" : "Closing"), 1)) : D("", !0),
682
+ n("div", {
683
+ class: pe(["fm-typo-en-body-xs-600 px-8 py-4 rounded-4", {
684
+ "bg-fm-color-system-error-100 text-fm-color-system-error-500": t.failedReason,
685
+ "bg-fm-color-system-success-100 text-fm-color-system-success-500": t.completedAt,
686
+ "bg-fm-color-system-info-100 text-fm-color-system-info-500": !t.failedReason && !t.completedAt
687
+ }])
688
+ }, i(t.failedReason ? c(o)("inventory.stock.recalculation.status.failed") : t.completedAt ? c(o)("inventory.stock.recalculation.status.completed") : c(o)("inventory.stock.recalculation.status.inProgress")), 3)
689
+ ])
690
+ ]),
691
+ n("div", St, i(c(o)("inventory.stock.recalculation.from")) + ": " + i(new Date(t.recalculateStartDate).toLocaleDateString()), 1),
692
+ n("div", wt, i(c(o)("inventory.stock.recalculation.to")) + ": " + i(new Date(t.recalculateEndDate).toLocaleDateString()), 1),
693
+ t.createdBy ? (d(), y("div", $t, i(c(o)("inventory.stock.recalculation.requestedBy")) + ": " + i(t.createdBy.name || t.createdBy.id), 1)) : D("", !0),
694
+ t.completedAt ? (d(), y("div", Ct, i(c(o)("inventory.stock.recalculation.completedAt")) + ": " + i(new Date(t.completedAt).toLocaleString()), 1)) : D("", !0),
695
+ t.failedReason ? (d(), y("div", Vt, i(t.failedReason), 1)) : D("", !0)
696
+ ]);
697
+ }), 128))
698
+ ])
699
+ ])) : D("", !0)
700
+ ])
701
+ ]),
702
+ _: 1
703
+ }, 8, ["modelValue"])
704
+ ]);
705
+ };
706
+ }
707
+ }), Rt = { class: "fm-typo-en-heading-lg-600" }, It = { class: "flex flex-col gap-16" }, Bt = { class: "flex flex-col gap-4" }, Lt = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Ot = { class: "fm-typo-en-body-md-400" }, Et = { class: "flex flex-col gap-4" }, Mt = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Pt = { class: "fm-typo-en-body-md-400" }, Ut = { class: "flex flex-col gap-4" }, Nt = { class: "fm-typo-en-label-md-400 text-fm-color-typo-secondary" }, Kt = { class: "flex gap-8 ml-auto" }, Ht = /* @__PURE__ */ le({
708
+ __name: "ClosingDetailDialog",
709
+ props: {
710
+ modelValue: { type: Boolean },
711
+ type: {},
712
+ data: {}
713
+ },
714
+ emits: ["update:modelValue"],
715
+ setup(I, { emit: k }) {
716
+ const { t: x } = se(), L = be(), o = I, _ = k, A = V({
717
+ get: () => o.modelValue,
718
+ set: (v) => _("update:modelValue", v)
719
+ }), p = V(() => {
720
+ var v;
721
+ return ((v = o.data) == null ? void 0 : v.skus) ?? [];
722
+ }), u = V(() => {
723
+ var C;
724
+ const v = (C = o.data) == null ? void 0 : C._id;
725
+ if (!v) return "-";
726
+ const l = P(v);
727
+ return new Date(l).toLocaleString();
728
+ }), s = V(() => o.type === "closing" ? x("inventory.closing.history.closingDetail", "Closing Detail") : x("inventory.closing.history.snapshotDetail", "Snapshot Detail")), r = V(() => p.value.map((v) => {
729
+ const l = L.skuById[v.id] ?? null, S = !l;
730
+ return {
731
+ id: v.id,
732
+ sku: l,
733
+ skuName: (l == null ? void 0 : l.name) ?? v.id,
734
+ skuCode: (l == null ? void 0 : l.code) ?? "-",
735
+ balance: v.balance ?? { amount: 0, precision: 0 },
736
+ isMissing: S,
737
+ costs: v.costs,
738
+ weightedAverage: v.weightedAverage
739
+ };
740
+ })), T = [
741
+ {
742
+ accessorKey: "skuName",
743
+ header: () => x("inventory.ingredient.name", "Ingredient Name"),
744
+ cell: (v) => {
745
+ const l = v.row.original;
746
+ return l.isMissing ? X("div", { class: "flex items-center gap-8" }, [
747
+ X("span", {}, l.id),
748
+ X(
749
+ "span",
750
+ {
751
+ class: "px-8 py-2 rounded-4 bg-fm-color-danger-weak text-fm-color-danger-default fm-typo-en-label-sm-400"
752
+ },
753
+ "Missing"
754
+ )
755
+ ]) : v.getValue();
756
+ }
757
+ },
758
+ {
759
+ accessorKey: "skuCode",
760
+ header: () => x("inventory.ingredient.code", "Code")
761
+ },
762
+ {
763
+ id: "balance",
764
+ header: () => x("inventory.closing.history.balance", "Balance"),
765
+ cell: (v) => {
766
+ var C;
767
+ const l = v.row.original;
768
+ if (l.isMissing || !((C = l.sku) != null && C.unit))
769
+ return `${l.balance.amount / Math.pow(10, l.balance.precision)}`;
770
+ const S = {
771
+ unit: l.sku.unit,
772
+ sku: l.sku,
773
+ amount: l.balance,
774
+ defaultTrackingMeasurement: l.sku.trackingMeasurement ?? void 0
775
+ };
776
+ return X(Se, S);
777
+ },
778
+ size: 180
779
+ },
780
+ {
781
+ accessorKey: "weightedAverage",
782
+ header: () => x("inventory.closing.history.weightedAvgCost", "Weighted Avg Cost"),
783
+ cell: (v) => {
784
+ const l = v.getValue();
785
+ if (!l) return "-";
786
+ const S = l.amount ?? 0, C = l.precision ?? 0, b = l.currency ?? "", w = S / Math.pow(10, C);
787
+ return `${b} ${w.toFixed(2)}`;
788
+ }
789
+ }
790
+ ];
791
+ return (v, l) => {
792
+ const S = $("FmTable"), C = $("FmButton"), b = $("FmDialog");
793
+ return d(), z(b, {
794
+ modelValue: A.value,
795
+ "onUpdate:modelValue": l[1] || (l[1] = (w) => A.value = w),
796
+ "close-button": "",
797
+ dismissAway: "",
798
+ "max-width": "900px"
799
+ }, {
800
+ "dialog-header": B(() => [
801
+ n("div", Rt, i(s.value), 1)
802
+ ]),
803
+ default: B(() => {
804
+ var w;
805
+ return [
806
+ n("div", It, [
807
+ n("div", Bt, [
808
+ n("div", Lt, i(o.type === "closing" ? c(x)("inventory.closing.history.closingId") : c(x)("inventory.closing.history.snapshotId", "Snapshot ID")), 1),
809
+ n("div", Ot, i(((w = o.data) == null ? void 0 : w._id) ?? "-"), 1)
810
+ ]),
811
+ n("div", Et, [
812
+ n("div", Mt, i(c(x)("inventory.closing.history.date")), 1),
813
+ n("div", Pt, i(u.value), 1)
814
+ ]),
815
+ n("div", Ut, [
816
+ n("div", Nt, i(c(x)("inventory.closing.history.ingredientBalances", "Ingredient Balances")) + " (" + i(p.value.length) + ") ", 1),
817
+ h(S, {
818
+ "row-data": r.value,
819
+ "column-defs": T,
820
+ pagination: { pageSize: 10 }
821
+ }, null, 8, ["row-data"])
822
+ ])
823
+ ])
824
+ ];
825
+ }),
826
+ "dialog-footer": B(() => [
827
+ n("div", Kt, [
828
+ h(C, {
829
+ variant: "tertiary",
830
+ onClick: l[0] || (l[0] = (w) => A.value = !1),
831
+ label: "Close"
832
+ })
833
+ ])
834
+ ]),
835
+ _: 1
836
+ }, 8, ["modelValue"]);
837
+ };
838
+ }
839
+ }), jt = { class: "flex flex-col gap-16 p-16" }, zt = { class: "flex flex-col gap-16" }, Jt = { class: "flex gap-8 ml-auto" }, to = /* @__PURE__ */ le({
840
+ __name: "ClosingHistoryView",
841
+ setup(I) {
842
+ var a, F;
843
+ const { t: k } = se(), x = ce(), L = ke(), o = _e(), _ = De(), A = re(), p = g("closings"), u = [
844
+ { label: "Closings", value: "closings" },
845
+ { label: "Snapshots", value: "snapshots" }
846
+ ], s = g([]), r = g(!1), T = g([]), v = g(!1), l = g(!1), S = g("closing"), C = g(null), b = new Date(Date.now() - 864e5), w = g(b.toISOString().split("T")[0]), J = V(() => {
847
+ const m = [];
848
+ return p.value === "closings" ? m.push(
849
+ {
850
+ label: k("inventory.stock.recalculation.title"),
851
+ value: "recalculation",
852
+ prependIcon: "history",
853
+ isAdminOnly: !0
854
+ },
855
+ {
856
+ label: k("inventory.closing.history.initiate_opening"),
857
+ value: "initiateOpening",
858
+ prependIcon: "add_box",
859
+ isAdminOnly: !0
860
+ },
861
+ {
862
+ label: "Refresh",
863
+ value: "refreshOpening",
864
+ prependIcon: "refresh"
865
+ }
866
+ ) : m.push(
867
+ {
868
+ label: `${k("inventory.stock.recalculation.title")} (BETA)`,
869
+ value: "recalculation",
870
+ prependIcon: "history",
871
+ isAdminOnly: !0
872
+ },
873
+ {
874
+ label: `${k("inventory.closing.history.initiate_snapshot")} (BETA)`,
875
+ value: "initiateStockSnapshot",
876
+ prependIcon: "camera",
877
+ isAdminOnly: !0
878
+ },
879
+ {
880
+ label: "Refresh",
881
+ value: "refreshStockSnapshot",
882
+ prependIcon: "refresh"
883
+ }
884
+ ), m;
885
+ }), G = g(), U = g();
886
+ function q(m) {
887
+ var f, R;
888
+ switch (m) {
889
+ case "recalculation":
890
+ return p.value === "closings" ? (f = G.value) == null ? void 0 : f.open() : (R = U.value) == null ? void 0 : R.open();
891
+ case "initiateOpening": {
892
+ _.open({
893
+ title: "Initiate Opening Balance",
894
+ message: "Initiate opening balance if no opening balance exists for the current location.",
895
+ primaryActions: { text: "Confirm", close: !0 }
896
+ }).onPrimary(async () => {
897
+ try {
898
+ await x.initiateClosing(), A.open({
899
+ message: "Opening balance initiated successfully.",
900
+ type: "success"
901
+ }), await K();
902
+ } catch (E) {
903
+ A.open({
904
+ message: E.message || "Failed to initiate opening balance. Please try again.",
905
+ type: "error"
906
+ });
907
+ }
908
+ });
909
+ break;
910
+ }
911
+ case "initiateStockSnapshot": {
912
+ const E = new Date(Date.now() - 864e5);
913
+ w.value = E.toISOString().split("T")[0], O.value = !0;
914
+ break;
915
+ }
916
+ case "refreshOpening": {
917
+ K();
918
+ break;
919
+ }
920
+ case "refreshStockSnapshot": {
921
+ H();
922
+ break;
923
+ }
924
+ }
925
+ }
926
+ const O = g(!1), N = g(!1), W = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
927
+ async function Q() {
928
+ N.value = !0;
929
+ try {
930
+ const m = new Date(w.value).toISOString();
931
+ await x.initiateStockSnapshot(m), A.open({
932
+ message: "Stock snapshot created successfully.",
933
+ type: "success"
934
+ }), O.value = !1, await H();
935
+ } catch (m) {
936
+ A.open({
937
+ message: m.message || "Failed to create stock snapshot. Please try again.",
938
+ type: "error"
939
+ });
940
+ } finally {
941
+ N.value = !1;
942
+ }
943
+ }
944
+ const ee = [
945
+ ...(a = o.sessionUser.value) != null && a.role.isAdmin ? [
946
+ {
947
+ accessorKey: "_id",
948
+ header: () => X(de, {}, () => `${k("inventory.closing.history.closingId")}`),
949
+ cell: (m) => m.getValue()
950
+ }
951
+ ] : [],
952
+ {
953
+ accessorKey: "_id",
954
+ id: "date",
955
+ header: () => k("inventory.closing.history.date"),
956
+ cell: (m) => {
957
+ const f = m.getValue(), R = P(f);
958
+ return new Date(R).toLocaleDateString();
959
+ }
960
+ },
961
+ {
962
+ accessorKey: "_id",
963
+ id: "time",
964
+ header: () => k("inventory.closing.history.time"),
965
+ cell: (m) => {
966
+ const f = m.getValue(), R = P(f);
967
+ return new Date(R).toLocaleTimeString();
968
+ }
969
+ },
970
+ {
971
+ accessorKey: "ref",
972
+ header: () => k("inventory.closing.history.createdFrom"),
973
+ cell: (m) => m.getValue() || "-"
974
+ }
975
+ ], te = [
976
+ ...(F = o.sessionUser.value) != null && F.role.isAdmin ? [
977
+ {
978
+ accessorKey: "_id",
979
+ header: () => X(
980
+ de,
981
+ {},
982
+ () => `${k("inventory.closing.history.snapshotId", "Snapshot ID")}`
983
+ ),
984
+ cell: (m) => m.getValue()
985
+ }
986
+ ] : [],
987
+ {
988
+ accessorKey: "_id",
989
+ id: "date",
990
+ header: () => k("inventory.closing.history.date"),
991
+ cell: (m) => {
992
+ const f = m.getValue(), R = P(f);
993
+ return new Date(R).toLocaleDateString();
994
+ }
995
+ },
996
+ {
997
+ accessorKey: "_id",
998
+ id: "time",
999
+ header: () => k("inventory.closing.history.time"),
1000
+ cell: (m) => {
1001
+ const f = m.getValue(), R = P(f);
1002
+ return new Date(R).toLocaleTimeString();
1003
+ }
1004
+ },
1005
+ {
1006
+ accessorKey: "remark",
1007
+ header: () => k("inventory.closing.history.createdFrom"),
1008
+ cell: (m) => m.getValue() || "-"
1009
+ }
1010
+ ];
1011
+ async function K() {
1012
+ if (L.currentLocationDBName) {
1013
+ r.value = !0;
1014
+ try {
1015
+ const m = await x.getLastNClosings(30);
1016
+ s.value = m;
1017
+ } catch (m) {
1018
+ console.error("Error fetching closings:", m), s.value = [];
1019
+ } finally {
1020
+ r.value = !1;
1021
+ }
1022
+ }
1023
+ }
1024
+ async function H() {
1025
+ if (L.currentLocationDBName) {
1026
+ v.value = !0;
1027
+ try {
1028
+ const m = await x.getLastNStockSnapshots(30);
1029
+ T.value = m;
1030
+ } catch (m) {
1031
+ console.error("Error fetching stock snapshots:", m), T.value = [];
1032
+ } finally {
1033
+ v.value = !1;
1034
+ }
1035
+ }
1036
+ }
1037
+ function oe(m) {
1038
+ S.value = "closing", C.value = m, l.value = !0;
1039
+ }
1040
+ function e(m) {
1041
+ S.value = "snapshot", C.value = m, l.value = !0;
1042
+ }
1043
+ return L.watchLocation(async () => {
1044
+ L.currentLocationDBName && (await K(), await H());
1045
+ }), (m, f) => {
1046
+ const R = $("FmTabs"), E = $("FmTable"), ae = $("FmDatePicker"), t = $("FmButton"), Y = $("FmDialog");
1047
+ return d(), z(he, {
1048
+ actions: J.value,
1049
+ title: c(k)("inventory.closing.history.title"),
1050
+ "onClick:action": q
1051
+ }, {
1052
+ default: B(() => [
1053
+ n("div", jt, [
1054
+ h(xe, {
1055
+ "change-location": "",
1056
+ "hide-filter-options": !0
1057
+ }),
1058
+ h(R, {
1059
+ "model-value": p.value,
1060
+ "onUpdate:modelValue": f[0] || (f[0] = (M) => p.value = M),
1061
+ items: u
1062
+ }, null, 8, ["model-value"]),
1063
+ p.value === "closings" ? (d(), y(j, { key: 0 }, [
1064
+ f[9] || (f[9] = n("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)),
1065
+ h(E, {
1066
+ loading: r.value,
1067
+ "row-data": s.value,
1068
+ "column-defs": ee,
1069
+ onRowClick: f[1] || (f[1] = (M) => oe(M.original))
1070
+ }, null, 8, ["loading", "row-data"])
1071
+ ], 64)) : D("", !0),
1072
+ p.value === "snapshots" ? (d(), y(j, { key: 1 }, [
1073
+ f[10] || (f[10] = n("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)),
1074
+ h(E, {
1075
+ loading: v.value,
1076
+ "row-data": T.value,
1077
+ "column-defs": te,
1078
+ onRowClick: f[2] || (f[2] = (M) => e(M.original))
1079
+ }, null, 8, ["loading", "row-data"])
1080
+ ], 64)) : D("", !0)
1081
+ ]),
1082
+ (d(), z(ge, { to: "body" }, [
1083
+ h(tt, {
1084
+ ref_key: "recalculationDialogRef",
1085
+ ref: G,
1086
+ onSubmitted: f[3] || (f[3] = (M) => K())
1087
+ }, null, 512),
1088
+ h(Tt, {
1089
+ ref_key: "snapshotRecalculationDialogRef",
1090
+ ref: U,
1091
+ onSubmitted: f[4] || (f[4] = (M) => H())
1092
+ }, null, 512),
1093
+ h(Ht, {
1094
+ modelValue: l.value,
1095
+ "onUpdate:modelValue": f[5] || (f[5] = (M) => l.value = M),
1096
+ type: S.value,
1097
+ data: C.value
1098
+ }, null, 8, ["modelValue", "type", "data"]),
1099
+ h(Y, {
1100
+ modelValue: O.value,
1101
+ "onUpdate:modelValue": f[8] || (f[8] = (M) => O.value = M),
1102
+ "close-button": "",
1103
+ dismissAway: "",
1104
+ "max-width": "400px"
1105
+ }, {
1106
+ "dialog-header": B(() => f[11] || (f[11] = [
1107
+ n("div", { class: "fm-typo-en-heading-lg-600" }, "Initiate Stock Snapshot", -1)
1108
+ ])),
1109
+ default: B(() => [
1110
+ n("div", zt, [
1111
+ f[12] || (f[12] = n("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)),
1112
+ h(ae, {
1113
+ modelValue: w.value,
1114
+ "onUpdate:modelValue": f[6] || (f[6] = (M) => w.value = M),
1115
+ label: "Snapshot Date",
1116
+ max: c(W)
1117
+ }, null, 8, ["modelValue", "max"])
1118
+ ])
1119
+ ]),
1120
+ "dialog-footer": B(() => [
1121
+ n("div", Jt, [
1122
+ h(t, {
1123
+ variant: "tertiary",
1124
+ onClick: f[7] || (f[7] = (M) => O.value = !1),
1125
+ label: "Cancel",
1126
+ disabled: N.value
1127
+ }, null, 8, ["disabled"]),
1128
+ h(t, {
1129
+ variant: "primary",
1130
+ onClick: Q,
1131
+ label: "Confirm",
1132
+ loading: N.value
1133
+ }, null, 8, ["loading"])
1134
+ ])
1135
+ ]),
1136
+ _: 1
1137
+ }, 8, ["modelValue"])
1138
+ ]))
1139
+ ]),
1140
+ _: 1
1141
+ }, 8, ["actions", "title"]);
1142
+ };
1143
+ }
1144
+ });
1145
+ export {
1146
+ to as default
1147
+ };