@feedmepos/mf-inventory-portal 1.8.0-dev.17 → 1.8.0-dev.18

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 (101) hide show
  1. package/dist/{App-CRmKXhRV.js → App-Djr9dJ9q.js} +9 -9
  2. package/dist/{ApprovalView-tDkNN-Cd.js → ApprovalView-VIVSr66P.js} +9 -9
  3. package/dist/{BindingsDialog-DrB0U9F6.js → BindingsDialog-NKiZKKA1.js} +2 -2
  4. package/dist/{BindingsPicker-tjjgijNe.js → BindingsPicker-WLdfNtim.js} +2 -2
  5. package/dist/{BindingsTable-D7EGgWxE.js → BindingsTable-DGikPjdP.js} +10 -10
  6. package/dist/{BulkReceiveRequestPage-B7GEE9qI.js → BulkReceiveRequestPage-GmZ7yxnK.js} +21 -21
  7. package/dist/{ChangeLocationComponent.vue_vue_type_script_setup_true_lang-B4j6Acmo.js → ChangeLocationComponent.vue_vue_type_script_setup_true_lang-6n-R2gAL.js} +1 -1
  8. package/dist/{ClosingDraftView-DH0eBMZ8.js → ClosingDraftView-Biir_xEx.js} +19 -19
  9. package/dist/{ClosingHistoryView-FmdYCiLI.js → ClosingHistoryView-ZMXQesn4.js} +7 -7
  10. package/dist/{ClosingTemplateView-BGmFG2-y.js → ClosingTemplateView-B-c3FkLX.js} +18 -18
  11. package/dist/{CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-DHboInU_.js → CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-D2bp6pW-.js} +1 -1
  12. package/dist/{DefaultView-CsNlHUlf.js → DefaultView-D_Jhtw_c.js} +2 -2
  13. package/dist/{DeliveryOrderPrintPreview-CMe2DpP1.js → DeliveryOrderPrintPreview-D5-9lzBd.js} +9 -9
  14. package/dist/{EmailDialog.vue_vue_type_script_setup_true_lang-Yen9u78U.js → EmailDialog.vue_vue_type_script_setup_true_lang-DEqUAhaS.js} +23 -23
  15. package/dist/{FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-BJy8_H2s.js → FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-CCzJ6Awz.js} +1 -1
  16. package/dist/{FeatureCapabilityGate-DN8b1697.js → FeatureCapabilityGate-iW8fvX19.js} +28 -28
  17. package/dist/{FeaturePageGate.vue_vue_type_script_setup_true_lang-DmNFZYam.js → FeaturePageGate.vue_vue_type_script_setup_true_lang-f3Y9lCSv.js} +1 -1
  18. package/dist/{FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-2zOATqzb.js → FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-1mVLSzDy.js} +1 -1
  19. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CVBUkN02.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-D6jnR8Rx.js} +2 -2
  20. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BuE-1qd6.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-tMoK_Ce8.js} +2 -2
  21. package/dist/{FmMultiselectDialog-C3B8pd2Z.js → FmMultiselectDialog-B8P_qEAQ.js} +2 -2
  22. package/dist/{FmMultiselectDialog-LI5ekHzQ.js → FmMultiselectDialog-DP480e0e.js} +2 -2
  23. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-DQZ7aJGJ.js → FmUnitInput.vue_vue_type_script_setup_true_lang-D7pb8F_A.js} +5 -5
  24. package/dist/{ImportView-DYoeJLdr.js → ImportView-BISXn7Th.js} +6 -6
  25. package/dist/{IngredientsView-u3KHfALO.js → IngredientsView-C3LrzIuS.js} +15 -15
  26. package/dist/{IntegrationExplorerView-Bl0Z8sxM.js → IntegrationExplorerView-B_4Af6OW.js} +6 -6
  27. package/dist/{IntegrationPlatformView-CybBB3RA.js → IntegrationPlatformView-CQUi7sRi.js} +2 -2
  28. package/dist/{IntegrationView-Dxy7QhCp.js → IntegrationView-CYkZq_tq.js} +14 -14
  29. package/dist/{InventoryBindingForm-DyUvyOsa.js → InventoryBindingForm-D2s_z-6Q.js} +1 -1
  30. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-Dmch1sfA.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-DXsyVclI.js} +4 -4
  31. package/dist/{InventoryBindingSummary-DwY3vUf_.js → InventoryBindingSummary-BOBGDwSm.js} +1 -1
  32. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B2UtnJtf.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-gAd41m7W.js} +2 -2
  33. package/dist/{ProductionRunDetailPage-Cdi4hv3E.js → ProductionRunDetailPage-COncuigP.js} +4 -4
  34. package/dist/{ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-D5jlF5x4.js → ProductionRunLifecycleDialogs.vue_vue_type_script_setup_true_lang-B3PSF7-H.js} +8 -8
  35. package/dist/{ProductionRunPage-RcbHy0Mj.js → ProductionRunPage-RUkgXlmL.js} +4 -4
  36. package/dist/{PublishView-CyJ_rE-5.js → PublishView-B0QVNasT.js} +3 -3
  37. package/dist/{PurchaseOrderPrintPreview-ZlbV3YfE.js → PurchaseOrderPrintPreview-CbjbKRS2.js} +13 -13
  38. package/dist/{ReceiveRequestView-BKz8N6yK.js → ReceiveRequestView-DAiOgbUO.js} +13 -13
  39. package/dist/{RecipeView-D3IEyQoK.js → RecipeView-B-Qr9p-i.js} +15 -15
  40. package/dist/{SettingsView-A0eozTq3.js → SettingsView-BnWul5uf.js} +7 -7
  41. package/dist/StockView-raj4WifG.js +2756 -0
  42. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CD11VzXa.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CYLgevQO.js} +1 -1
  43. package/dist/{SupplierView-Cg60vwsj.js → SupplierView-CxAwhXEg.js} +13 -13
  44. package/dist/{SurchargeView-Dxvg-RnC.js → SurchargeView-B7R7_JVv.js} +7 -7
  45. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-DDLGEaa2.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-CrYxhm0y.js} +2 -2
  46. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-DfYoaT5a.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-BSglNZaK.js} +1 -1
  47. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-D3wClK8t.js → TransferDetails.vue_vue_type_script_setup_true_lang-CoOidQMw.js} +809 -788
  48. package/dist/{TransferTemplateView-DfCJzLHt.js → TransferTemplateView-BXu5OhXF.js} +19 -19
  49. package/dist/{UnitCostHistoryView-BkNnwNUc.js → UnitCostHistoryView-BAfxgkjF.js} +4 -4
  50. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-Clufqvr_.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-DTS06g9i.js} +4 -4
  51. package/dist/{UnitView-D_agG3Kd.js → UnitView-BnCe1kBW.js} +7 -7
  52. package/dist/{WarehouseView-DE_CaJCb.js → WarehouseView-D3y9EDWW.js} +8 -8
  53. package/dist/{WastageTemplateView-r3b6angy.js → WastageTemplateView-BShli8bj.js} +15 -15
  54. package/dist/{app-CLTXsVH_.js → app-FPg0KzwG.js} +23668 -25024
  55. package/dist/app.d.ts +1 -0
  56. package/dist/app.js +1 -1
  57. package/dist/{closing-template-yP6QT_6M.js → closing-template-Db-KNAjB.js} +1 -1
  58. package/dist/components/FeatureCapabilityGate.vue.d.ts +1 -0
  59. package/dist/{date2-9jq_OKuv.js → date2-YICloR2o.js} +1 -1
  60. package/dist/{dayjs.min-CAxu5-hQ.js → dayjs.min-CefWSTKK.js} +1 -1
  61. package/dist/{decimal-BhGvDuWQ.js → decimal-CBsXxlpr.js} +2 -2
  62. package/dist/defineDeepModel-DdUeiux0.js +19 -0
  63. package/dist/{duplicate-template-X72Zob-u.js → duplicate-template-BvMZ2ilL.js} +1 -1
  64. package/dist/{feature-CC2pF6VK.js → feature-HJuftceg.js} +2 -2
  65. package/dist/{format-time-from-id-DhZOfLN4.js → format-time-from-id-BUJJn9WM.js} +1 -1
  66. package/dist/{format-unit-display-BalKqHYj.js → format-unit-display-vkauUh5a.js} +12 -12
  67. package/dist/{id-to-date-Cb9v4BtX.js → id-to-date-BFOeIS4x.js} +1 -1
  68. package/dist/{import-export.helper-9D5DLoaq.js → import-export.helper-C48DsrFq.js} +5 -5
  69. package/dist/{index-CnjRz458.js → index--e5sOJ5N.js} +3 -3
  70. package/dist/{index-B0T8iGU6.js → index-4EWcUZB2.js} +1 -1
  71. package/dist/{index-DqV626Os.js → index-COy6Gu_M.js} +1 -1
  72. package/dist/{lz-string-CK_kK0b8.js → lz-string-CX9VutYB.js} +1 -1
  73. package/dist/{netsuite-Czq6x14E.js → netsuite-BOb6Ek6I.js} +247 -262
  74. package/dist/{netsuite-explorer-BugWV6N7.js → netsuite-explorer-Czbq3dDh.js} +1 -1
  75. package/dist/{predefined-templates-D5qjNE4o.js → predefined-templates-Cb97vyso.js} +1 -1
  76. package/dist/{purchase-order-template-Bc0QP-bq.js → purchase-order-template-CBjU0dUO.js} +1 -1
  77. package/dist/{recalculationUtils-CJknKvb-.js → recalculationUtils-CyoKTNie.js} +1 -1
  78. package/dist/{row-action.enum-Cz1k6Kht.js → row-action.enum-DoY1An1e.js} +1 -1
  79. package/dist/{rules-BQscySfb.js → rules-C23j4F0_.js} +3 -3
  80. package/dist/{stock--68mu-M1.js → stock-CN-acijK.js} +1 -1
  81. package/dist/stock-DClY4hP_.js +78 -0
  82. package/dist/style.css +1 -1
  83. package/dist/{supplier-U06ZrnoC.js → supplier-OCIcWTkA.js} +2 -2
  84. package/dist/{surcharge-B5DGPlf5.js → surcharge-CCqME8iu.js} +1 -1
  85. package/dist/tsconfig.app.tsbuildinfo +1 -1
  86. package/dist/{uom-rules-DfBYytl6.js → uom-rules-DyRkdoii.js} +1 -1
  87. package/dist/{use-ingredient-select-dialog-BRTxaEaQ.js → use-ingredient-select-dialog-B9SD-Gfg.js} +2 -2
  88. package/dist/{use-inventory-binding-dialog-DQDv8yOS.js → use-inventory-binding-dialog-Dx8nYVH0.js} +2 -2
  89. package/dist/{use-template-enabled-locations-DzQVNhev.js → use-template-enabled-locations-C7vIH0p-.js} +2 -2
  90. package/dist/{use-transfer-locations-CGvKssyQ.js → use-transfer-locations-DfZI178Y.js} +2 -2
  91. package/dist/{useHrmPermission-BkOtYcLu.js → useHrmPermission-BF87diqS.js} +1 -1
  92. package/dist/{useNavigationMenu-korDNdFf.js → useNavigationMenu-hmVbINp6.js} +4 -4
  93. package/dist/{useSseClient-BjoRcYKu.js → useSseClient-D-dJYaOl.js} +1 -1
  94. package/dist/views/stock/components/StockRecordCard.vue.d.ts +16 -2
  95. package/dist/{vue-hPU91AHR.js → vue-_3HY6f-w.js} +2 -2
  96. package/dist/{vue-i18n-VFYpKHHB.js → vue-i18n-B8eq3KRC.js} +1 -1
  97. package/dist/{xlsx.util-VlHt05TU.js → xlsx.util-BbyZEE1S.js} +2 -2
  98. package/package.json +5 -5
  99. package/dist/StockView-DrxkHTH4.js +0 -2651
  100. package/dist/defineDeepModel-Czbczabc.js +0 -19
  101. package/dist/stock-DCz3ZTmd.js +0 -74
@@ -0,0 +1,2756 @@
1
+ import { defineComponent as _e, createElementBlock as X, openBlock as A, createElementVNode as t, createVNode as p, toDisplayString as d, unref as s, ref as Y, h as Fe, computed as z, watch as Se, resolveComponent as H, createBlock as ee, isRef as Ne, withCtx as P, Fragment as ce, renderList as ye, createCommentVNode as oe, normalizeClass as $e, reactive as yt, mergeModels as ot, useModel as jt, onMounted as Qe, createTextVNode as ve, nextTick as Ct, normalizeStyle as _t, watchEffect as Vt, renderSlot as nt, onUnmounted as Bt, Teleport as Dt, normalizeProps as st, mergeProps as Ke } from "vue";
2
+ import { u as It, _ as Mt } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DpwneGOV.js";
3
+ import { u as je, c as Oe, a as Le, F as at, v as Tt, s as K, E as ie, t as Ht, d as Et, B as Ut, h as Te, i as rt, e as lt, M as Ae, O as He } from "./app-FPg0KzwG.js";
4
+ import { u as Ye } from "./stock-DClY4hP_.js";
5
+ import { c as Pt } from "./component-BmLAdDiY.js";
6
+ import { _ as kt, o as Rt } from "./UnitDisplayControl.vue_vue_type_script_setup_true_lang-DTS06g9i.js";
7
+ import { _ as Je, S as qe, g as ht, a as Nt } from "./SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-CYLgevQO.js";
8
+ import { _ as Ot } from "./FeatureCapabilityBadge.vue_vue_type_script_setup_true_lang-CCzJ6Awz.js";
9
+ import { useI18n as ke, useCoreStore as Ze } from "@feedmepos/mf-common";
10
+ import { u as bt, i as Re } from "./id-to-date-BFOeIS4x.js";
11
+ import { useSnackbar as we, useDialog as ze, useProxiedModel as Ge, useBreakpoints as Lt } from "@feedmepos/ui-library";
12
+ import { defineStore as Yt } from "pinia";
13
+ import { F as We } from "./FmAdminBadge-DlplQOHb.js";
14
+ import { g as Be, a as xe, h as zt, t as De, I as it, f as et, A as Gt, M as Wt, i as Kt, j as ut, k as gt, l as tt, R as qt, d as Ue, m as Xt } from "./rules-C23j4F0_.js";
15
+ import { u as Ce } from "./stock-CN-acijK.js";
16
+ import { u as Jt } from "./use-inventory-binding-dialog-Dx8nYVH0.js";
17
+ import { a as xt } from "./FmMultiselectDialog-DP480e0e.js";
18
+ import { d as ge } from "./dayjs.min-CefWSTKK.js";
19
+ import { _ as Qt } from "./NumberPrecisionInput.vue_vue_type_script_setup_true_lang-gAd41m7W.js";
20
+ import { g as Zt } from "./decimal-CBsXxlpr.js";
21
+ import { b as eo, d as to, f as St, t as ct, a as dt, p as oo, n as no, c as so } from "./date2-YICloR2o.js";
22
+ import { i as ao } from "./FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-1mVLSzDy.js";
23
+ import { _ as ro } from "./empty-placeholder-B0QU467o.js";
24
+ import { F as wt } from "./FeatureCapabilityGate-iW8fvX19.js";
25
+ import "./feature-HJuftceg.js";
26
+ import { u as Ft } from "./useHrmPermission-BF87diqS.js";
27
+ import { F as mt } from "./index-eGvSlWMU.js";
28
+ import { _ as lo } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-gJQQKKAC.js";
29
+ import { _ as io } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-tMoK_Ce8.js";
30
+ import { u as uo } from "./useSseClient-D-dJYaOl.js";
31
+ import { u as co } from "./netsuite-BOb6Ek6I.js";
32
+ import { P as mo, J as fo } from "./app-C39bYJmq.js";
33
+ var Pe = /* @__PURE__ */ (($) => ($.History = "History", $.Convert = "Convert", $.Adjust = "Adjust", $))(Pe || {});
34
+ const vo = [
35
+ {
36
+ translationKey: "inventory.stock.action.history",
37
+ color: "text-neutral-700",
38
+ value: "History"
39
+ /* History */
40
+ }
41
+ ], po = [
42
+ {
43
+ translationKey: "inventory.stock.action.history",
44
+ color: "text-neutral-700",
45
+ value: "History"
46
+ /* History */
47
+ },
48
+ {
49
+ translationKey: "inventory.stock.action.convert",
50
+ color: "text-neutral-700",
51
+ value: "Convert"
52
+ /* Convert */
53
+ },
54
+ {
55
+ translationKey: "inventory.stock.action.adjust",
56
+ color: "text-neutral-700",
57
+ value: "Adjust"
58
+ /* Adjust */
59
+ }
60
+ ], yo = { class: "flex items-center gap-8" }, _o = { class: "whitespace-nowrap" }, ko = /* @__PURE__ */ _e({
61
+ __name: "StockHeaderPreview",
62
+ setup($) {
63
+ const { t: a } = ke();
64
+ return (k, y) => (A(), X("div", yo, [
65
+ t("div", _o, d(s(a)("inventory.stock.prediction.daysRemaining")), 1),
66
+ p(Ot, {
67
+ tier: "standard",
68
+ category: "beta"
69
+ })
70
+ ]));
71
+ }
72
+ }), At = Yt("stockActions", () => {
73
+ const $ = Y(!1), a = je(), k = Ye(), y = bt(), w = we(), j = ze(), { t: n } = ke();
74
+ async function u() {
75
+ if (a._currentLocation) {
76
+ $.value = !0;
77
+ try {
78
+ await k.readStockBalance(), await y.readStockEstimateBalance();
79
+ } catch {
80
+ w.open({
81
+ title: n("inventory.stock.error.title"),
82
+ message: n("inventory.stock.error.message"),
83
+ type: "error"
84
+ });
85
+ } finally {
86
+ $.value = !1;
87
+ }
88
+ }
89
+ }
90
+ const V = Y();
91
+ async function q(c) {
92
+ var f, M, E;
93
+ if (!!!((M = (f = c.convert) == null ? void 0 : f.inventoryBindings) != null && M.length)) {
94
+ j.open({
95
+ title: n("inventory.stock.error.convert.title"),
96
+ message: n("inventory.stock.error.convert.message")
97
+ });
98
+ return;
99
+ }
100
+ try {
101
+ await k.readProductBalance();
102
+ } catch (N) {
103
+ w.open({
104
+ title: n("inventory.stock.error.title"),
105
+ message: n("inventory.stock.error.message"),
106
+ type: "error"
107
+ }), console.error("error on compute convert balance", N);
108
+ return;
109
+ }
110
+ const e = {
111
+ maxCount: ((E = k.productBalance.find(({ id: N }) => N === c._id)) == null ? void 0 : E.count) || 0,
112
+ sku: c,
113
+ show: !0,
114
+ "onUpdate:show"(N) {
115
+ V.value.show = N;
116
+ },
117
+ onSubmitted() {
118
+ u();
119
+ }
120
+ };
121
+ V.value = e;
122
+ }
123
+ const I = Y();
124
+ async function x(c) {
125
+ const m = {
126
+ stock: c,
127
+ show: !0,
128
+ "onUpdate:show"(o) {
129
+ I.value.show = o;
130
+ },
131
+ onSubmitted() {
132
+ u();
133
+ }
134
+ };
135
+ I.value = m;
136
+ }
137
+ const i = Y();
138
+ async function F(c) {
139
+ const m = {
140
+ sku: c,
141
+ show: !0,
142
+ "onUpdate:show"(o) {
143
+ i.value.show = o;
144
+ }
145
+ };
146
+ i.value = m;
147
+ }
148
+ function g(c, m) {
149
+ const o = Oe(m);
150
+ switch (c) {
151
+ case Pe.History:
152
+ F(o);
153
+ return;
154
+ case Pe.Convert:
155
+ q(o);
156
+ return;
157
+ case Pe.Adjust:
158
+ x(o);
159
+ return;
160
+ }
161
+ }
162
+ return {
163
+ fetchStockBalance: u,
164
+ onActionMenu: g,
165
+ stockHistoryProps: i,
166
+ showSkuHistory: F,
167
+ convertSkuDialogProps: V,
168
+ adjustSkuDialogProps: I
169
+ };
170
+ });
171
+ function ho() {
172
+ var j;
173
+ const $ = je(), a = At(), k = Ze(), { t: y } = ke();
174
+ return {
175
+ columnDefs: [
176
+ {
177
+ accessorKey: "code",
178
+ header: () => y("inventory.stock.code"),
179
+ enableSorting: !0,
180
+ size: 300
181
+ },
182
+ {
183
+ accessorKey: "name",
184
+ header: () => y("inventory.stock.product"),
185
+ enableSorting: !0,
186
+ size: "auto"
187
+ },
188
+ {
189
+ id: "UOM",
190
+ header: () => y("inventory.stock.balance"),
191
+ cell(n) {
192
+ const u = n.row.original, V = {
193
+ unit: u.unit,
194
+ sku: u,
195
+ amount: u.balance,
196
+ defaultTrackingMeasurement: u.trackingMeasurement ?? void 0
197
+ };
198
+ return Fe(kt, V);
199
+ },
200
+ size: 180
201
+ },
202
+ ...(j = k.sessionUser.value) != null && j.role.isAdmin ? [
203
+ {
204
+ accessorKey: "isInactive",
205
+ header: () => Fe(We, {}, () => `${y("inventory.ingredient.status.title")}`),
206
+ cell(n) {
207
+ const u = n.row.original.isInactive;
208
+ return Fe(
209
+ "span",
210
+ {
211
+ class: [
212
+ "inline-block px-3 py-1 rounded-full text-xs font-semibold",
213
+ u ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"
214
+ ].join(" ")
215
+ },
216
+ y(u ? "inventory.ingredient.status.inactive" : "inventory.ingredient.status.active")
217
+ );
218
+ },
219
+ enableSorting: !0
220
+ }
221
+ ] : [],
222
+ {
223
+ accessorKey: "day",
224
+ id: "expireDate",
225
+ header: () => Fe(ko),
226
+ enableSorting: !0,
227
+ sortUndefined: "last",
228
+ cell(n) {
229
+ var F, g;
230
+ const u = n.row.original.day, V = n.row.original.operator, q = (F = n.row.original.thresholds) == null ? void 0 : F.low, I = (g = n.row.original.thresholds) == null ? void 0 : g.mid;
231
+ if (typeof u != "number" || typeof q != "number" || typeof I != "number")
232
+ return Fe(Je, {
233
+ days: u,
234
+ operator: V
235
+ });
236
+ const x = u <= q ? qe.low : u <= I ? qe.mid : qe.high;
237
+ return Fe(Je, {
238
+ days: u,
239
+ level: x
240
+ });
241
+ },
242
+ size: 200
243
+ },
244
+ {
245
+ id: "action",
246
+ cell(n) {
247
+ var u;
248
+ return Pt(
249
+ ((u = $._currentLocation) == null ? void 0 : u.type) === "restaurant" ? vo : po,
250
+ (V) => a.onActionMenu(V, n.row.original)
251
+ );
252
+ },
253
+ enableSorting: !1,
254
+ size: 40,
255
+ meta: {
256
+ cellClass: "",
257
+ headerClass: ""
258
+ }
259
+ }
260
+ ]
261
+ };
262
+ }
263
+ const bo = {
264
+ context: null,
265
+ error: null,
266
+ isRequired($ = "This field is required") {
267
+ return `${this.context ?? ""}`.length === 0 && (this.error = $), this;
268
+ },
269
+ isString($ = "Must be a valid string") {
270
+ return this.error ? this : (typeof this.context != "string" && (this.error ?? (this.error = $)), this);
271
+ },
272
+ toInt() {
273
+ return this.error ? this : (this.context = +this.context, this);
274
+ },
275
+ isInteger($ = "Must be an integer") {
276
+ return this.error ? this : (this.toInt(), isNaN(this.context) && (this.error = $), this);
277
+ },
278
+ min($, a) {
279
+ if (this.error) return this;
280
+ try {
281
+ typeof this.context == "number" ? +this.context < $ && (this.error = a ?? `Must be at least ${$}`) : Object.prototype.hasOwnProperty.call(this.context, "length") ? +this.context.length < $ && (this.error = a ?? `Must be at least ${$}`) : this.error = "Length cannot be determined";
282
+ } catch {
283
+ this.error = "Length cannot be determined";
284
+ }
285
+ return this;
286
+ },
287
+ max($, a) {
288
+ if (this.error) return this;
289
+ try {
290
+ typeof this.context == "number" ? +this.context > $ && (this.error = a ?? `Must be at most ${$}`) : "length" in this.context ? +this.context.length > $ && (this.error = a ?? `Must be at most ${$}`) : this.error = "Length cannot be determined";
291
+ } catch {
292
+ this.error = "Length cannot be determined";
293
+ }
294
+ return this;
295
+ }
296
+ };
297
+ function ft($) {
298
+ return { ...bo, context: $ };
299
+ }
300
+ const go = { class: "flex items-center" }, xo = { class: "fm-typo-en-title-md-800" }, So = { class: "flex flex-col gap-24 w-full" }, wo = { class: "flex flex-col gap-8" }, Fo = { class: "fm-typo-en-body-lg-600" }, Ao = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary flex-grow" }, $o = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-error" }, jo = { class: "flex flex-col p-16 gap-8" }, Co = { class: "flex flex-col gap-4" }, Vo = { class: "fm-typo-en-body-md-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 border-b py-12 px-16" }, Bo = { class: "grid grid-cols-[auto_100px_100px_48px] xs:grid-cols-[auto_80px_120px_48px] gap-8 px-8 items-center" }, Do = { class: "xs:col-span-3" }, Io = { class: "flex gap-8" }, Mo = /* @__PURE__ */ _e({
301
+ __name: "ConvertSkuDialog",
302
+ props: {
303
+ sku: {},
304
+ maxCount: {},
305
+ show: { type: Boolean }
306
+ },
307
+ emits: ["update:show", "submitted"],
308
+ setup($, { expose: a, emit: k }) {
309
+ const y = $, w = k, j = Jt(), n = Le(), u = Ce(), V = we(), { t: q } = ke(), I = Y(0), x = Y(null), i = z(() => n.skus), F = z(
310
+ () => {
311
+ var v, h;
312
+ return (((h = (v = y.sku) == null ? void 0 : v.convert) == null ? void 0 : h.inventoryBindings) ?? []).filter(
313
+ (T) => T.type === at.enum.SKU
314
+ );
315
+ }
316
+ ), g = z({
317
+ get() {
318
+ return !!x.value;
319
+ },
320
+ set(v) {
321
+ v ? x.value = Oe(F.value) : (x.value = null, m.value = {}, I.value = Math.min(I.value, y.maxCount ?? 0));
322
+ }
323
+ }), c = Y(!1);
324
+ Se([() => y.show], ([v]) => {
325
+ v && (I.value = 0);
326
+ });
327
+ const m = Y({});
328
+ function o(v) {
329
+ return String(v ?? "").trim().length === 0;
330
+ }
331
+ function e(v) {
332
+ if (o(v)) return "Required";
333
+ const h = it()(String(v));
334
+ return h !== !0 ? h : Number(v) >= 0 || "Must be zero or greater";
335
+ }
336
+ function f(v) {
337
+ const h = { ...m.value };
338
+ delete h[v], m.value = h;
339
+ }
340
+ function M() {
341
+ if (x.value && (Object.keys(m.value).length > 0 || x.value.some((v) => v.amount.amount < 0))) {
342
+ V.open({
343
+ title: "Invalid amount",
344
+ message: "Please correct the highlighted ingredient amounts.",
345
+ type: "error"
346
+ });
347
+ return;
348
+ }
349
+ O(y.sku, De(I.value), x.value);
350
+ }
351
+ function E(v) {
352
+ if (x.value)
353
+ return !0;
354
+ const h = ft(v).isInteger().max(y.maxCount ?? 0).error ?? "";
355
+ return h || !0;
356
+ }
357
+ function N(v) {
358
+ var R;
359
+ const h = (R = y.sku.convert) != null && R.measurement ? y.sku.unit.measurements.find((r) => {
360
+ var _;
361
+ return r.id === ((_ = y.sku.convert) == null ? void 0 : _.measurement);
362
+ }) ?? null : null, T = Be(y.sku.unit, h), W = Kt(+v);
363
+ return ft(W).isInteger().max(T).error ? "Precision cannot be more than " + T : !0;
364
+ }
365
+ const G = z(
366
+ () => {
367
+ var v, h;
368
+ return (v = y.sku.convert) != null && v.measurement ? (h = y.sku.unit.measurements.find((T) => {
369
+ var W;
370
+ return T.id === ((W = y.sku.convert) == null ? void 0 : W.measurement);
371
+ })) == null ? void 0 : h.abbrev : y.sku.unit.abbrev;
372
+ }
373
+ ), J = z(() => {
374
+ var W, D;
375
+ const h = Tt({
376
+ bindings: ((W = y.sku.convert) == null ? void 0 : W.inventoryBindings) ?? [],
377
+ skus: n.skus,
378
+ skuGroups: [],
379
+ recipes: n.recipes
380
+ }).inventoryBindings.filter((R) => "success" in R && R.success).map((R) => R).map((R) => R.binding);
381
+ return (D = x.value ?? h) == null ? void 0 : D.map((R) => {
382
+ var te, ae, Q, se, re;
383
+ const r = n.skus.find((ue) => ue._id === R.id), _ = ((te = R.measurement) == null ? void 0 : te.abbrev) ?? ((ae = r == null ? void 0 : r.unit) == null ? void 0 : ae.abbrev), B = (Q = y.sku.convert) != null && Q.measurement ? y.sku.unit.measurements.find((ue) => {
384
+ var be;
385
+ return ue.id === ((be = y.sku.convert) == null ? void 0 : be.measurement);
386
+ }) ?? null : null, b = Be(y.sku.unit, B), l = N(`${I.value}`) === !0 ? xe(
387
+ zt(
388
+ R.amount,
389
+ De(+I.value, b)
390
+ ),
391
+ !1
392
+ ) : "0", S = (re = (se = x.value) == null ? void 0 : se.find((ue) => ue.id === (r == null ? void 0 : r._id))) == null ? void 0 : re.amount, C = S ? xe(S, !1) : null;
393
+ return {
394
+ sku: r,
395
+ convertAmount: C ?? l,
396
+ abbrev: _
397
+ };
398
+ });
399
+ }), U = Y();
400
+ a({
401
+ validateInputs: () => {
402
+ var v, h;
403
+ (h = (v = U.value) == null ? void 0 : v.validateInputs) == null || h.call(v);
404
+ },
405
+ resetInputsValidation: () => {
406
+ var v, h;
407
+ (h = (v = U.value) == null ? void 0 : v.resetInputsValidation) == null || h.call(v);
408
+ },
409
+ resetInputs: () => {
410
+ var v, h;
411
+ (h = (v = U.value) == null ? void 0 : v.resetInputs) == null || h.call(v);
412
+ }
413
+ });
414
+ const L = Ge(y, "show");
415
+ async function O(v, h, T) {
416
+ c.value = !0;
417
+ try {
418
+ await u.convertSku({
419
+ conversions: [
420
+ {
421
+ doc: v,
422
+ amount: h,
423
+ overrides: T == null ? void 0 : T.map((W) => ({
424
+ ...W,
425
+ amount: {
426
+ ...W.amount,
427
+ amount: -1 * Math.abs(W.amount.amount)
428
+ // ensure truly negative
429
+ }
430
+ }))
431
+ }
432
+ ]
433
+ }), w("update:show", !1), w("submitted");
434
+ } catch (W) {
435
+ V.open({
436
+ title: "Something went wrong",
437
+ message: `Cannot convert ${v.name}. Please try again.`,
438
+ type: "error"
439
+ }), console.error("error at converting stock amount", v, h, W);
440
+ } finally {
441
+ c.value = !1;
442
+ }
443
+ }
444
+ function Z(v, h, T) {
445
+ if (e(h) !== !0) {
446
+ m.value = { ...m.value, [v]: h };
447
+ return;
448
+ }
449
+ f(v);
450
+ const W = +h;
451
+ x.value = T.map((D) => (D.id !== v || (D.amount = K.fromNumber(W)), D));
452
+ }
453
+ function ne(v) {
454
+ const h = i.value.find((T) => T._id === v);
455
+ return h ? ht(h.unit, !0) : [];
456
+ }
457
+ function me(v, h) {
458
+ const T = ne(v), W = T.find((D) => D.value === h) ?? T.find((D) => D.value === null);
459
+ return W ? {
460
+ ...W,
461
+ label: W.abbrev
462
+ } : null;
463
+ }
464
+ function fe(v, h, T) {
465
+ let W;
466
+ if (h === null)
467
+ W = T.map((D) => (D.id !== v || (D.measurement = null), D)) ?? [];
468
+ else {
469
+ const D = i.value.find((R) => R._id === v);
470
+ W = T.map((R) => {
471
+ var r, _;
472
+ return R.id !== v || (R.measurement = (_ = (r = D == null ? void 0 : D.unit) == null ? void 0 : r.measurements) == null ? void 0 : _.find((B) => B.id === h)), R;
473
+ }) ?? [];
474
+ }
475
+ x.value = W;
476
+ }
477
+ function le(v, h) {
478
+ const T = h.filter((W) => W.id !== v);
479
+ f(v), x.value = T;
480
+ }
481
+ function he() {
482
+ const v = (x.value ?? []).map((h) => ({
483
+ ...h,
484
+ type: at.enum.SKU
485
+ }));
486
+ j.promptIngredientsBinding(
487
+ v,
488
+ (h) => x.value = h,
489
+ y.sku._id
490
+ );
491
+ }
492
+ return Se(
493
+ () => y.show,
494
+ (v) => {
495
+ v || (x.value = null, m.value = {}, I.value = 0);
496
+ }
497
+ ), (v, h) => {
498
+ const T = H("FmTextField"), W = H("FmForm"), D = H("FmCard"), R = H("FmSwitch"), r = H("FmFormGroup"), _ = H("FmSelect"), B = H("FmButton"), b = H("FmSideSheet");
499
+ return A(), ee(b, {
500
+ "dismiss-away": "",
501
+ modelValue: s(L),
502
+ "onUpdate:modelValue": h[3] || (h[3] = (l) => Ne(L) ? L.value = l : null),
503
+ "max-width": 500
504
+ }, {
505
+ "side-sheet-header": P(() => [
506
+ t("div", go, [
507
+ t("div", xo, d(s(q)("inventory.stock.convert.title", { name: v.sku.name })), 1)
508
+ ])
509
+ ]),
510
+ default: P(() => [
511
+ t("div", So, [
512
+ p(W, {
513
+ ref_key: "formRef",
514
+ ref: U,
515
+ onValidationSuccess: M
516
+ }, {
517
+ default: P(() => [
518
+ p(T, {
519
+ disabled: c.value,
520
+ "model-value": I.value,
521
+ "onUpdate:modelValue": h[0] || (h[0] = (l) => I.value = l),
522
+ label: s(q)("inventory.stock.convert.amount"),
523
+ rules: [s(it)(), E, N, s(et)(0)],
524
+ "append-text": G.value,
525
+ "helper-text": x.value ? void 0 : `Max ${v.maxCount} ${G.value}`
526
+ }, null, 8, ["disabled", "model-value", "label", "rules", "append-text", "helper-text"])
527
+ ]),
528
+ _: 1
529
+ }, 512),
530
+ p(D, {
531
+ variant: "outlined",
532
+ class: "p-16"
533
+ }, {
534
+ default: P(() => [
535
+ t("div", wo, [
536
+ t("div", Fo, d(s(q)("inventory.stock.convert.deductionSummary")), 1),
537
+ (A(!0), X(ce, null, ye(J.value, (l) => {
538
+ var S, C;
539
+ return A(), X("div", {
540
+ key: (S = l.sku) == null ? void 0 : S._id,
541
+ class: "flex items-center"
542
+ }, [
543
+ t("div", Ao, d((C = l.sku) == null ? void 0 : C.name), 1),
544
+ t("div", $o, " -" + d(l.convertAmount) + " " + d(l.abbrev), 1)
545
+ ]);
546
+ }), 128))
547
+ ])
548
+ ]),
549
+ _: 1
550
+ }),
551
+ p(D, { variant: "outlined" }, {
552
+ default: P(() => [
553
+ t("div", jo, [
554
+ p(R, {
555
+ value: "",
556
+ modelValue: g.value,
557
+ "onUpdate:modelValue": h[1] || (h[1] = (l) => g.value = l),
558
+ label: s(q)("inventory.stock.convert.overrideDeduction"),
559
+ "label-placement": "right"
560
+ }, null, 8, ["modelValue", "label"]),
561
+ g.value ? (A(), X(ce, { key: 0 }, [
562
+ p(r, {
563
+ modelValue: x.value,
564
+ rules: [s(Gt)(1, "Must have at least one ingredient binding")]
565
+ }, null, 8, ["modelValue", "rules"]),
566
+ t("div", Co, [
567
+ t("div", Vo, d(s(q)("inventory.stock.convert.ingredients")), 1),
568
+ (A(!0), X(ce, null, ye(x.value, (l) => (A(), ee(r, {
569
+ key: l.id,
570
+ disabled: c.value,
571
+ modelValue: m.value[l.id] ?? +s(xe)(l.amount ?? { amount: 1, precision: 0 }),
572
+ rules: [
573
+ e,
574
+ s(Wt)(
575
+ i.value.find((S) => S._id === l.id).unit,
576
+ l.measurement
577
+ )
578
+ ]
579
+ }, {
580
+ default: P(({ invalid: S }) => {
581
+ var C, te, ae;
582
+ return [
583
+ t("div", Bo, [
584
+ t("div", Do, d((C = i.value.find((Q) => Q._id === l.id)) == null ? void 0 : C.name), 1),
585
+ p(T, {
586
+ class: "xs:col-span-2",
587
+ disabled: c.value,
588
+ modelValue: m.value[l.id] ?? +s(xe)(
589
+ l.amount ?? { amount: 1, precision: 0 }
590
+ ),
591
+ "onUpdate:modelValue": (Q) => Z(l.id, Q, x.value ?? []),
592
+ invalid: S
593
+ }, null, 8, ["disabled", "modelValue", "onUpdate:modelValue", "invalid"]),
594
+ p(_, {
595
+ disabled: c.value,
596
+ class: "translate-y-[2px]",
597
+ items: ne(l.id),
598
+ "model-value": (ae = me(l.id, (te = l.measurement) == null ? void 0 : te.id)) == null ? void 0 : ae.value,
599
+ "onUpdate:modelValue": (Q) => fe(l.id, Q, x.value ?? []),
600
+ invalid: S
601
+ }, {
602
+ "helper-text": P(() => h[4] || (h[4] = [])),
603
+ _: 2
604
+ }, 1032, ["disabled", "items", "model-value", "onUpdate:modelValue", "invalid"]),
605
+ p(B, {
606
+ disabled: c.value,
607
+ type: "button",
608
+ variant: "tertiary",
609
+ icon: "delete",
610
+ onClick: (Q) => le(l.id, x.value ?? [])
611
+ }, null, 8, ["disabled", "onClick"])
612
+ ])
613
+ ];
614
+ }),
615
+ _: 2
616
+ }, 1032, ["disabled", "modelValue", "rules"]))), 128))
617
+ ]),
618
+ t("div", null, [
619
+ p(B, {
620
+ icon: "link",
621
+ label: s(q)("inventory.stock.convert.linkIngredient"),
622
+ variant: "plain",
623
+ onClick: he
624
+ }, null, 8, ["label"])
625
+ ])
626
+ ], 64)) : oe("", !0)
627
+ ])
628
+ ]),
629
+ _: 1
630
+ })
631
+ ])
632
+ ]),
633
+ "side-sheet-footer": P(() => [
634
+ t("div", Io, [
635
+ p(B, {
636
+ loading: c.value,
637
+ label: s(q)("inventory.stock.convert.convertButton"),
638
+ onClick: h[2] || (h[2] = (l) => {
639
+ var S, C;
640
+ return (C = (S = U.value) == null ? void 0 : S.validateInputs) == null ? void 0 : C.call(S);
641
+ })
642
+ }, null, 8, ["loading", "label"])
643
+ ])
644
+ ]),
645
+ _: 1
646
+ }, 8, ["modelValue"]);
647
+ };
648
+ }
649
+ });
650
+ function Ee($, a) {
651
+ const k = De($, a);
652
+ return { ...k, amount: -k.amount };
653
+ }
654
+ function vt($, a) {
655
+ return De(Math.abs($), a);
656
+ }
657
+ const Xe = {
658
+ [ie.enum.DAMAGE]: {
659
+ label: "Damage",
660
+ toAdjustmentAmount: Ee
661
+ },
662
+ [ie.enum.WASTAGE]: {
663
+ label: "Wastage",
664
+ toAdjustmentAmount: Ee
665
+ },
666
+ [ie.enum.THEFT]: {
667
+ label: "Theft",
668
+ toAdjustmentAmount: Ee
669
+ },
670
+ [ie.enum.LOSE]: {
671
+ label: "Lose",
672
+ toAdjustmentAmount: Ee
673
+ },
674
+ [ie.enum.EXTRA]: {
675
+ label: "Extra",
676
+ toAdjustmentAmount: vt
677
+ },
678
+ [ie.enum.PURCHASE]: {
679
+ label: "Purchase",
680
+ toAdjustmentAmount: vt
681
+ }
682
+ }, To = { class: "col-span-2 flex" }, Ho = { class: "flex-1" }, Eo = { class: "fm-typo-en-body-lg-600" }, Uo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Po = { class: "col-span-2 flex flex-col gap-4" }, Ro = { class: "flex gap-4 text-fm-color-typo-primary fm-typo-en-body-lg-600" }, No = {
683
+ key: 0,
684
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-warning"
685
+ }, $t = /* @__PURE__ */ _e({
686
+ __name: "AdjustedItemForm",
687
+ props: {
688
+ modelValue: {},
689
+ disabled: { type: Boolean },
690
+ isBackdate: { type: Boolean }
691
+ },
692
+ emits: ["update:modelValue", "click:delete"],
693
+ setup($, { emit: a }) {
694
+ const k = $, y = a, { t: w } = ke(), j = Ye(), n = z(
695
+ () => Object.keys(Xe).map((o) => ({
696
+ label: Ht(o),
697
+ value: o
698
+ }))
699
+ ), u = z(() => ht(k.modelValue.doc.unit, !0)), V = z({
700
+ get() {
701
+ return k.modelValue.type ?? ie.enum.PURCHASE;
702
+ },
703
+ set(o) {
704
+ const e = {
705
+ ...k.modelValue
706
+ };
707
+ e.type = o;
708
+ const f = ut(k.modelValue.amount);
709
+ e.amount = Xe[e.type].toAdjustmentAmount(
710
+ +xe(f),
711
+ f.precision
712
+ ), y("update:modelValue", e);
713
+ }
714
+ }), q = z({
715
+ get() {
716
+ const o = ut(k.modelValue.amount);
717
+ return +xe(o);
718
+ },
719
+ set(o) {
720
+ const e = {
721
+ ...k.modelValue
722
+ }, f = K.fromNumber(o);
723
+ e.amount = Xe[V.value].toAdjustmentAmount(
724
+ o,
725
+ f.precision
726
+ ), y("update:modelValue", e);
727
+ }
728
+ }), I = z({
729
+ get() {
730
+ var o;
731
+ return ((o = k.modelValue.measurement) == null ? void 0 : o.id) ?? null;
732
+ },
733
+ set(o) {
734
+ var f, M;
735
+ const e = {
736
+ ...k.modelValue
737
+ };
738
+ e.measurement = ((M = (f = k.modelValue.doc.unit) == null ? void 0 : f.measurements) == null ? void 0 : M.find((E) => E.id === o)) ?? null, y("update:modelValue", e);
739
+ }
740
+ }), x = z({
741
+ get() {
742
+ return k.modelValue.remark ?? "";
743
+ },
744
+ set(o) {
745
+ const e = {
746
+ ...k.modelValue
747
+ };
748
+ e.remark = o, y("update:modelValue", e);
749
+ }
750
+ }), i = z(() => {
751
+ var e;
752
+ const o = (e = j.stockBalance.skus) == null ? void 0 : e.find((f) => f.id === k.modelValue.doc._id);
753
+ return (o == null ? void 0 : o.balance) ?? { amount: 0, precision: 0 };
754
+ }), F = z(() => {
755
+ const o = k.modelValue.amount, e = k.modelValue.measurement;
756
+ return e ? gt(o, e.conversion) : o;
757
+ }), g = z(
758
+ () => k.isBackdate ? i.value : tt(i.value, F.value)
759
+ ), c = z(
760
+ () => Zt(g.value, k.modelValue.doc.unit)
761
+ ), m = z(
762
+ () => !k.isBackdate && F.value.amount < 0
763
+ );
764
+ return (o, e) => {
765
+ const f = H("FmButton"), M = H("FmSelect"), E = H("FmTextarea"), N = H("FmCard");
766
+ return A(), ee(N, {
767
+ variant: "outlined",
768
+ class: "grid grid-cols-2 gap-8 p-16"
769
+ }, {
770
+ default: P(() => [
771
+ t("div", To, [
772
+ t("div", Ho, [
773
+ t("div", Eo, d(o.modelValue.doc.name), 1),
774
+ t("div", Uo, d(o.modelValue.doc.code), 1)
775
+ ]),
776
+ p(f, {
777
+ variant: "tertiary",
778
+ "prepend-icon": "delete",
779
+ onClick: e[0] || (e[0] = (G) => y("click:delete"))
780
+ })
781
+ ]),
782
+ p(M, {
783
+ disabled: o.disabled,
784
+ class: "col-span-2",
785
+ label: "Type",
786
+ items: n.value,
787
+ modelValue: V.value,
788
+ "onUpdate:modelValue": e[1] || (e[1] = (G) => V.value = G),
789
+ rules: [s(qt)()],
790
+ "label-mark": "required"
791
+ }, null, 8, ["disabled", "items", "modelValue", "rules"]),
792
+ p(Qt, {
793
+ disabled: o.disabled,
794
+ label: "Amount",
795
+ step: +s(xe)({
796
+ amount: 1,
797
+ precision: s(Be)(o.modelValue.doc.unit, o.modelValue.measurement)
798
+ }),
799
+ modelValue: q.value,
800
+ "onUpdate:modelValue": e[2] || (e[2] = (G) => q.value = G),
801
+ rules: [s(et)(0)]
802
+ }, null, 8, ["disabled", "step", "modelValue", "rules"]),
803
+ p(M, {
804
+ disabled: o.disabled,
805
+ label: "Unit",
806
+ items: u.value,
807
+ modelValue: I.value,
808
+ "onUpdate:modelValue": e[3] || (e[3] = (G) => I.value = G)
809
+ }, null, 8, ["disabled", "items", "modelValue"]),
810
+ p(E, {
811
+ class: "col-span-2",
812
+ disabled: o.disabled,
813
+ label: "Remark",
814
+ modelValue: x.value,
815
+ "onUpdate:modelValue": e[4] || (e[4] = (G) => x.value = G),
816
+ "label-mark": "optional"
817
+ }, null, 8, ["disabled", "modelValue"]),
818
+ t("div", Po, [
819
+ t("div", Ro, d(s(w)("inventory.stock.stock_adjustment.stockAfter")), 1),
820
+ t("div", {
821
+ class: $e(["fm-typo-en-body-lg-600", m.value ? "text-red-700" : "text-green-700"])
822
+ }, d(c.value), 3),
823
+ o.isBackdate ? (A(), X("div", No, d(s(w)("inventory.stock.stock_adjustment.backdatePreviewWarning")), 1)) : oe("", !0)
824
+ ])
825
+ ]),
826
+ _: 1
827
+ });
828
+ };
829
+ }
830
+ }), Oo = { class: "flex items-center" }, Lo = { class: "fm-typo-en-title-md-800" }, Yo = { class: "flex items-center" }, zo = { class: "fm-typo-en-title-sm-800 flex-1" }, Go = { class: "flex gap-8" }, Wo = /* @__PURE__ */ _e({
831
+ __name: "AdjustSkuDialog",
832
+ props: {
833
+ stock: {},
834
+ show: { type: Boolean }
835
+ },
836
+ emits: ["update:show", "submitted"],
837
+ setup($, { expose: a, emit: k }) {
838
+ const y = $, w = k, j = Le(), n = ze(), u = Ce(), V = we(), q = Y(!1), { t: I } = ke();
839
+ function x() {
840
+ c(Oe(g));
841
+ }
842
+ const i = Y();
843
+ a({
844
+ validateInputs: () => {
845
+ var e, f;
846
+ (f = (e = i.value) == null ? void 0 : e.validateInputs) == null || f.call(e);
847
+ },
848
+ resetInputsValidation: () => {
849
+ var e, f;
850
+ (f = (e = i.value) == null ? void 0 : e.resetInputsValidation) == null || f.call(e);
851
+ },
852
+ resetInputs: () => {
853
+ var e, f;
854
+ (f = (e = i.value) == null ? void 0 : e.resetInputs) == null || f.call(e);
855
+ }
856
+ });
857
+ const F = Ge(y, "show"), g = yt({
858
+ remark: "",
859
+ adjustments: [
860
+ {
861
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
862
+ type: ie.enum.PURCHASE,
863
+ doc: y.stock,
864
+ measurement: null,
865
+ remark: "",
866
+ amount: K.fromNumber(1)
867
+ }
868
+ ]
869
+ });
870
+ Se([() => y.show], ([e]) => {
871
+ e && (g.remark = "", g.adjustments = [
872
+ {
873
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
874
+ type: ie.enum.PURCHASE,
875
+ doc: y.stock,
876
+ measurement: null,
877
+ remark: "",
878
+ amount: K.fromNumber(1)
879
+ }
880
+ ]);
881
+ });
882
+ async function c(e) {
883
+ q.value = !0;
884
+ try {
885
+ await u.adjustSku({
886
+ remark: e.remark,
887
+ adjustments: e.adjustments.map(({ doc: f, remark: M, type: E, amount: N, measurement: G }) => ({
888
+ id: f._id,
889
+ amount: N,
890
+ measurement: G,
891
+ remark: M,
892
+ doc: f,
893
+ type: E
894
+ }))
895
+ }), w("update:show", !1), w("submitted");
896
+ } catch (f) {
897
+ V.open({
898
+ title: I("inventory.stock.adjust.error.title"),
899
+ message: I("inventory.stock.adjust.error.message"),
900
+ type: "error"
901
+ }), console.log("error on adjust ingredients", e, f);
902
+ } finally {
903
+ q.value = !1;
904
+ }
905
+ }
906
+ function m() {
907
+ const e = j.skus.map((M) => ({
908
+ label: M.name,
909
+ sublabel: M.code,
910
+ value: M._id
911
+ })), f = e.filter((M) => g.adjustments.find((E) => E.doc._id === M.value)).map((M) => M.value);
912
+ n.open({
913
+ title: "Select ingredients",
914
+ contentComponent: xt,
915
+ contentComponentProps: {
916
+ items: e,
917
+ modelValue: f
918
+ },
919
+ overlay: !0,
920
+ closeButton: !0,
921
+ dismissAway: !0,
922
+ primaryActions: {
923
+ text: "Confirm",
924
+ close: !0
925
+ },
926
+ secondaryActions: {
927
+ text: "Close",
928
+ close: !0,
929
+ variant: "tertiary"
930
+ }
931
+ }).onPrimary((M) => {
932
+ g.adjustments = M.map(
933
+ (E) => g.adjustments.find((N) => N.doc._id === E) ?? {
934
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
935
+ type: ie.enum.PURCHASE,
936
+ doc: j.skus.find((N) => N._id === E),
937
+ measurement: null,
938
+ remark: "",
939
+ amount: K.fromNumber(1)
940
+ }
941
+ );
942
+ });
943
+ }
944
+ function o(e) {
945
+ g.adjustments.splice(e, 1);
946
+ }
947
+ return (e, f) => {
948
+ const M = H("FmTextarea"), E = H("FmButton"), N = H("FmForm"), G = H("FmSideSheet");
949
+ return A(), ee(G, {
950
+ modelValue: s(F),
951
+ "onUpdate:modelValue": f[2] || (f[2] = (J) => Ne(F) ? F.value = J : null),
952
+ "dismiss-away": "",
953
+ "max-width": 500
954
+ }, {
955
+ "side-sheet-header": P(() => [
956
+ t("div", Oo, [
957
+ t("div", Lo, d(s(I)("inventory.stock.adjust.title")), 1)
958
+ ])
959
+ ]),
960
+ default: P(() => [
961
+ p(N, {
962
+ class: "w-full flex flex-col gap-12",
963
+ ref_key: "formRef",
964
+ ref: i,
965
+ onValidationSuccess: x
966
+ }, {
967
+ default: P(() => [
968
+ p(M, {
969
+ label: s(I)("inventory.stock.adjust.remark"),
970
+ modelValue: g.remark,
971
+ "onUpdate:modelValue": f[0] || (f[0] = (J) => g.remark = J)
972
+ }, null, 8, ["label", "modelValue"]),
973
+ t("div", Yo, [
974
+ t("div", zo, d(s(I)("inventory.stock.adjust.adjustedItems")), 1),
975
+ p(E, {
976
+ "prepend-icon": "add",
977
+ variant: "tertiary",
978
+ size: "md",
979
+ onClick: m
980
+ })
981
+ ]),
982
+ (A(!0), X(ce, null, ye(g.adjustments, (J, U) => (A(), ee($t, {
983
+ key: J.id,
984
+ modelValue: g.adjustments[U],
985
+ "onUpdate:modelValue": (L) => g.adjustments[U] = L,
986
+ "onClick:delete": (L) => o(U)
987
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onClick:delete"]))), 128))
988
+ ]),
989
+ _: 1
990
+ }, 512)
991
+ ]),
992
+ "side-sheet-footer": P(() => [
993
+ t("div", Go, [
994
+ p(E, {
995
+ label: s(I)("inventory.stock.adjust.adjustButton"),
996
+ loading: q.value,
997
+ onClick: f[1] || (f[1] = (J) => {
998
+ var U, L;
999
+ return (L = (U = i.value) == null ? void 0 : U.validateInputs) == null ? void 0 : L.call(U);
1000
+ })
1001
+ }, null, 8, ["label", "loading"])
1002
+ ])
1003
+ ]),
1004
+ _: 1
1005
+ }, 8, ["modelValue"]);
1006
+ };
1007
+ }
1008
+ }), Ko = { class: "flex items-center w-full gap-8" }, qo = { class: "fm-typo-en-title-md-800 flex-1" }, Xo = {
1009
+ key: 0,
1010
+ class: "flex flex-col gap-4"
1011
+ }, Jo = { class: "fm-typo-en-body-md-600" }, Qo = { class: "flex gap-8 items-start" }, Zo = { class: "flex-1 min-w-0" }, en = { class: "flex-1 min-w-0" }, tn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, on = { class: "flex items-center" }, nn = { class: "fm-typo-en-title-sm-800 flex-1" }, sn = { class: "flex gap-8" }, pt = 14, an = /* @__PURE__ */ _e({
1012
+ __name: "StockAdjustmentSideSheet",
1013
+ props: {
1014
+ show: { type: Boolean }
1015
+ },
1016
+ emits: ["update:show", "submitted"],
1017
+ setup($, { emit: a }) {
1018
+ const k = $, y = a, { t: w } = ke(), j = Le(), n = Ce(), u = ze(), V = we(), q = Ge(k, "show"), I = Y(!1), x = yt({
1019
+ remark: "",
1020
+ effectiveAt: /* @__PURE__ */ new Date(),
1021
+ adjustments: []
1022
+ }), i = Y(!1), F = Y(ge().format("YYYY-MM-DD")), g = Y(ge().format("HH:mm")), c = Y();
1023
+ Se([F, g], () => {
1024
+ if (F.value && g.value) {
1025
+ const L = ge(`${F.value} ${g.value}`, "YYYY-MM-DD HH:mm");
1026
+ L.isValid() && (x.effectiveAt = L.toDate());
1027
+ }
1028
+ });
1029
+ const m = z(() => `${F.value} ${g.value}`);
1030
+ function o() {
1031
+ if (!i.value) return !0;
1032
+ const L = ge(`${F.value} ${g.value}`, "YYYY-MM-DD HH:mm");
1033
+ if (!L.isValid()) return w("inventory.stock.stock_adjustment.invalidDateTime");
1034
+ const O = ge();
1035
+ if (L.isAfter(O))
1036
+ return w("inventory.stock.stock_adjustment.futureDateNotAllowed");
1037
+ const Z = O.subtract(pt, "day");
1038
+ return L.isBefore(Z) ? w("inventory.stock.stock_adjustment.backdateLimitError", { days: pt }) : !0;
1039
+ }
1040
+ const e = z(() => [() => o()]), f = z(() => x.adjustments.length === 0 || o() !== !0);
1041
+ function M() {
1042
+ x.remark = "", x.effectiveAt = /* @__PURE__ */ new Date(), x.adjustments = [], i.value = !1, F.value = ge(x.effectiveAt).format("YYYY-MM-DD"), g.value = ge(x.effectiveAt).format("HH:mm");
1043
+ }
1044
+ function E() {
1045
+ M();
1046
+ }
1047
+ const N = z(() => {
1048
+ const L = {};
1049
+ return j.skus.forEach((O) => {
1050
+ L[O._id] = O;
1051
+ }), L;
1052
+ });
1053
+ function G() {
1054
+ const L = j.skus.map((Z) => ({
1055
+ label: Z.name,
1056
+ sublabel: Z.code,
1057
+ value: Z._id
1058
+ })), O = x.adjustments.map((Z) => Z.doc._id);
1059
+ u.open({
1060
+ title: w("inventory.stock.adjust.selectIngredients"),
1061
+ contentComponent: xt,
1062
+ contentComponentProps: {
1063
+ items: L,
1064
+ modelValue: O,
1065
+ virtualScroll: !0
1066
+ },
1067
+ overlay: !0,
1068
+ closeButton: !0,
1069
+ dismissAway: !0,
1070
+ primaryActions: {
1071
+ text: w("common.confirm"),
1072
+ close: !0
1073
+ },
1074
+ secondaryActions: {
1075
+ text: w("common.close"),
1076
+ close: !0,
1077
+ variant: "tertiary"
1078
+ }
1079
+ }).onPrimary((Z) => {
1080
+ x.adjustments = Z.map(
1081
+ (ne) => x.adjustments.find((me) => me.doc._id === ne) ?? {
1082
+ id: "",
1083
+ type: ie.enum.PURCHASE,
1084
+ doc: N.value[ne],
1085
+ measurement: null,
1086
+ remark: "",
1087
+ amount: K.fromNumber(1)
1088
+ }
1089
+ );
1090
+ });
1091
+ }
1092
+ function J(L) {
1093
+ x.adjustments.splice(L, 1);
1094
+ }
1095
+ async function U() {
1096
+ if (x.adjustments.length === 0) {
1097
+ V.open({
1098
+ title: w("inventory.stock.error.title"),
1099
+ message: w("inventory.stock.stock_adjustment.noAdjustments"),
1100
+ type: "warning"
1101
+ });
1102
+ return;
1103
+ }
1104
+ I.value = !0;
1105
+ try {
1106
+ const L = x.adjustments.map(
1107
+ ({ doc: Z, remark: ne, type: me, amount: fe, measurement: le }) => ({
1108
+ id: Z._id,
1109
+ amount: fe,
1110
+ measurement: le,
1111
+ remark: ne,
1112
+ doc: Z,
1113
+ type: me
1114
+ })
1115
+ ), O = {
1116
+ remark: x.remark,
1117
+ adjustments: L,
1118
+ ...i.value ? { effectiveAt: x.effectiveAt.toISOString() } : {}
1119
+ };
1120
+ await n.adjustSku(Oe(O)), y("submitted"), y("update:show", !1);
1121
+ } catch (L) {
1122
+ V.open({
1123
+ title: w("inventory.stock.adjust.error.title"),
1124
+ message: w("inventory.stock.adjust.error.message"),
1125
+ type: "error"
1126
+ }), console.error("error on stock adjustment", L);
1127
+ } finally {
1128
+ I.value = !1;
1129
+ }
1130
+ }
1131
+ return (L, O) => {
1132
+ const Z = H("FmTextarea"), ne = H("FmSwitch"), me = H("FmDatePicker"), fe = H("FmTimePicker"), le = H("FmFormGroup"), he = H("FmButton"), v = H("FmForm"), h = H("FmSideSheet");
1133
+ return A(), ee(h, {
1134
+ modelValue: s(q),
1135
+ "onUpdate:modelValue": O[6] || (O[6] = (T) => Ne(q) ? q.value = T : null),
1136
+ "dismiss-away": "",
1137
+ "max-width": 560,
1138
+ onAfterEnter: E
1139
+ }, {
1140
+ "side-sheet-header": P(() => [
1141
+ t("div", Ko, [
1142
+ t("div", qo, d(s(w)("inventory.stock.stock_adjustment.title")), 1)
1143
+ ])
1144
+ ]),
1145
+ default: P(() => [
1146
+ p(v, {
1147
+ class: "flex flex-col gap-16",
1148
+ ref_key: "formRef",
1149
+ ref: c,
1150
+ onValidationSuccess: U
1151
+ }, {
1152
+ default: P(() => [
1153
+ p(Z, {
1154
+ label: s(w)("inventory.stock.adjust.remark"),
1155
+ modelValue: x.remark,
1156
+ "onUpdate:modelValue": O[0] || (O[0] = (T) => x.remark = T),
1157
+ "label-mark": "optional"
1158
+ }, null, 8, ["label", "modelValue"]),
1159
+ p(ne, {
1160
+ value: "",
1161
+ "model-value": i.value,
1162
+ "onUpdate:modelValue": O[1] || (O[1] = (T) => i.value = T),
1163
+ label: s(w)("inventory.stock.stock_adjustment.backdateLabel"),
1164
+ sublabel: s(w)("inventory.stock.stock_adjustment.backdateSublabel"),
1165
+ labelPlacement: "right"
1166
+ }, null, 8, ["model-value", "label", "sublabel"]),
1167
+ i.value ? (A(), X("div", Xo, [
1168
+ t("label", Jo, d(s(w)("inventory.stock.stock_adjustment.effectiveAt")), 1),
1169
+ t("div", Qo, [
1170
+ t("div", Zo, [
1171
+ p(me, {
1172
+ class: "w-full",
1173
+ modelValue: F.value,
1174
+ "onUpdate:modelValue": O[2] || (O[2] = (T) => F.value = T),
1175
+ clearable: !1
1176
+ }, null, 8, ["modelValue"])
1177
+ ]),
1178
+ t("div", en, [
1179
+ p(fe, {
1180
+ class: "w-full",
1181
+ modelValue: g.value,
1182
+ "onUpdate:modelValue": O[3] || (O[3] = (T) => g.value = T),
1183
+ format: "HH:mm"
1184
+ }, null, 8, ["modelValue"])
1185
+ ])
1186
+ ]),
1187
+ p(le, {
1188
+ "model-value": m.value,
1189
+ rules: e.value
1190
+ }, null, 8, ["model-value", "rules"]),
1191
+ t("div", tn, d(s(w)("inventory.stock.stock_adjustment.immediateHint")), 1)
1192
+ ])) : oe("", !0),
1193
+ t("div", on, [
1194
+ t("div", nn, d(s(w)("inventory.stock.adjust.adjustedItems")), 1),
1195
+ p(he, {
1196
+ "prepend-icon": "add",
1197
+ variant: "tertiary",
1198
+ size: "md",
1199
+ onClick: G
1200
+ })
1201
+ ]),
1202
+ (A(!0), X(ce, null, ye(x.adjustments, (T, W) => (A(), ee($t, {
1203
+ key: T.doc._id,
1204
+ modelValue: x.adjustments[W],
1205
+ "onUpdate:modelValue": (D) => x.adjustments[W] = D,
1206
+ "is-backdate": i.value,
1207
+ "onClick:delete": (D) => J(W)
1208
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "is-backdate", "onClick:delete"]))), 128))
1209
+ ]),
1210
+ _: 1
1211
+ }, 512)
1212
+ ]),
1213
+ "side-sheet-footer": P(() => [
1214
+ t("div", sn, [
1215
+ p(he, {
1216
+ label: s(w)("common.confirm"),
1217
+ loading: I.value,
1218
+ disabled: f.value,
1219
+ onClick: O[4] || (O[4] = (T) => {
1220
+ var W, D;
1221
+ return (D = (W = c.value) == null ? void 0 : W.validateInputs) == null ? void 0 : D.call(W);
1222
+ })
1223
+ }, null, 8, ["label", "loading", "disabled"]),
1224
+ p(he, {
1225
+ label: s(w)("common.close"),
1226
+ variant: "tertiary",
1227
+ onClick: O[5] || (O[5] = (T) => y("update:show", !1))
1228
+ }, null, 8, ["label"])
1229
+ ])
1230
+ ]),
1231
+ _: 1
1232
+ }, 8, ["modelValue"]);
1233
+ };
1234
+ }
1235
+ }), rn = Et(($, a) => ({
1236
+ // TODO: remove once latest inventory backend has been push
1237
+ async findBillsByBusinessId(k, y, w) {
1238
+ const j = `${$.businessesBackendUrl}/${k}/reports/find-many`, n = {
1239
+ // type: TYPE.bill,
1240
+ type: "bill",
1241
+ restaurantIds: y,
1242
+ ids: w
1243
+ };
1244
+ return await a.post(j, n);
1245
+ },
1246
+ async findBillsById(k) {
1247
+ const w = je().currentLocationDBName, j = `${$.inventoryBackendUrl}/${w}/bill/search`, n = {
1248
+ ids: k
1249
+ };
1250
+ return await a.post(j, n);
1251
+ }
1252
+ })), ln = {
1253
+ key: 0,
1254
+ class: "flex justify-center items-center h-32"
1255
+ }, un = { class: "mb-3" }, cn = { class: "flex flex-col gap-8" }, dn = { class: "flex flex-col text-fm-color-typo-primary mb-3 text-center" }, mn = { class: "text-fm-color-neutral-gray-400 fm-typo-en-body-sm-600" }, fn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, vn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, pn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, yn = { class: "flex flex-col w-full px-2" }, _n = { class: "flex gap-2" }, kn = /* @__PURE__ */ _e({
1256
+ __name: "AmendAdjustmentForm",
1257
+ props: /* @__PURE__ */ ot({
1258
+ adjustmentId: {}
1259
+ }, {
1260
+ modelValue: {},
1261
+ modelModifiers: {}
1262
+ }),
1263
+ emits: /* @__PURE__ */ ot(["refreshHistory"], ["update:modelValue"]),
1264
+ setup($, { emit: a }) {
1265
+ const k = $, y = a, w = Ce(), j = jt($, "modelValue"), n = Y(!1), u = Y(!1), V = Y(!1), q = Y({
1266
+ _id: `inventoryAdjustment_${(/* @__PURE__ */ new Date()).toISOString()}_XXXXX`,
1267
+ skus: []
1268
+ }), I = Y();
1269
+ Qe(async () => {
1270
+ n.value = !0;
1271
+ const m = await w.readSingleAdjustment(k.adjustmentId);
1272
+ if (!m) throw new Error("Adjustment not found");
1273
+ q.value = m, n.value = !1;
1274
+ });
1275
+ async function x() {
1276
+ var o, e;
1277
+ if ((e = (o = I == null ? void 0 : I.value) == null ? void 0 : o.validateInputs) == null || e.call(o), !u.value) return;
1278
+ const m = {};
1279
+ Object.keys(j.value || {}).forEach((f) => {
1280
+ var M;
1281
+ Object.keys(((M = j.value) == null ? void 0 : M[f]) || {}).forEach((E) => {
1282
+ var G, J;
1283
+ const N = (J = (G = j.value) == null ? void 0 : G[f]) == null ? void 0 : J[Number(E)];
1284
+ N && F(N.amount) > 0 && (m[f] || (m[f] = []), m[f].push(N));
1285
+ });
1286
+ }), await w.revertWastageAdjustment({
1287
+ targetWastageAdjustmentId: k.adjustmentId,
1288
+ amountsGoingToAdjust: m
1289
+ }), y("refreshHistory"), V.value = !1, j.value = {};
1290
+ }
1291
+ function i(m) {
1292
+ const { skuId: o, idx: e, unit: f, measurement: M } = m;
1293
+ return z({
1294
+ get: () => {
1295
+ var G, J, U;
1296
+ const E = (U = (J = (G = j.value) == null ? void 0 : G[o]) == null ? void 0 : J[e]) == null ? void 0 : U.amount;
1297
+ return E ? Number(K.toFormatString({ value: E })) : 0;
1298
+ },
1299
+ set: (E) => {
1300
+ const N = E ?? 0;
1301
+ j.value || (j.value = {});
1302
+ const G = { ...j.value };
1303
+ G[o] || (G[o] = {});
1304
+ const J = Be(f);
1305
+ let U;
1306
+ try {
1307
+ U = K.fromNumber(N);
1308
+ } catch (L) {
1309
+ if (!Number.isFinite(N)) throw L;
1310
+ const O = De(N, J, !0);
1311
+ U = K.fromNumber(O.amount / 10 ** J);
1312
+ }
1313
+ G[o][e] = {
1314
+ amount: K.convertPrecision({
1315
+ value: U,
1316
+ precision: J
1317
+ }),
1318
+ type: ie.Enum.WASTAGE,
1319
+ measurement: M
1320
+ }, j.value = G;
1321
+ }
1322
+ });
1323
+ }
1324
+ function F(m, o = !0) {
1325
+ const e = Number(K.toFormatString({ value: m }));
1326
+ return o ? Math.abs(e) : e;
1327
+ }
1328
+ function g(m, o) {
1329
+ return o.measurement ? o.measurement.abbrev : m.sku.unit.abbrev;
1330
+ }
1331
+ function c(m, o) {
1332
+ if (o.amount === 0) return "N/A";
1333
+ const e = K.add([m, o]);
1334
+ return e ? K.toFormatString({ value: e }) : "N/A";
1335
+ }
1336
+ return (m, o) => {
1337
+ const e = H("FmIcon"), f = H("FmStepperField"), M = H("FmCard"), E = H("FmForm"), N = H("FmSpacer"), G = H("FmButton"), J = H("FmDialog");
1338
+ return A(), ee(J, {
1339
+ modelValue: V.value,
1340
+ "onUpdate:modelValue": o[4] || (o[4] = (U) => V.value = U),
1341
+ overlay: !0
1342
+ }, {
1343
+ "dialog-button": P(() => [
1344
+ p(We, null, {
1345
+ default: P(() => [
1346
+ t("button", {
1347
+ onClick: o[0] || (o[0] = (U) => V.value = !0),
1348
+ class: "rounded-md hover:bg-gray-100 transition-colors"
1349
+ }, [
1350
+ p(e, {
1351
+ name: "edit",
1352
+ size: "sm"
1353
+ })
1354
+ ])
1355
+ ]),
1356
+ _: 1
1357
+ })
1358
+ ]),
1359
+ "dialog-header": P(() => o[5] || (o[5] = [
1360
+ t("div", null, "Amend Adjustment", -1)
1361
+ ])),
1362
+ "dialog-footer": P(() => [
1363
+ t("div", yn, [
1364
+ o[13] || (o[13] = t("span", { class: "text-fm-color-system-warning-400 fm-typo-en-body-sm-400" }, "1. New adjustment EXTRA will be created for each reversal", -1)),
1365
+ t("div", _n, [
1366
+ p(N),
1367
+ p(G, {
1368
+ class: "sm:w-full xs:w-full",
1369
+ label: "Close",
1370
+ size: "md",
1371
+ variant: "tertiary",
1372
+ onClick: o[3] || (o[3] = (U) => V.value = !1)
1373
+ }),
1374
+ p(G, {
1375
+ class: "sm:w-full xs:w-full",
1376
+ label: "Submit",
1377
+ size: "md",
1378
+ variant: "primary",
1379
+ onClick: x
1380
+ })
1381
+ ])
1382
+ ])
1383
+ ]),
1384
+ default: P(() => [
1385
+ n.value ? (A(), X("div", ln)) : (A(), ee(E, {
1386
+ key: 1,
1387
+ ref_key: "formRef",
1388
+ ref: I,
1389
+ onValidationFailed: o[1] || (o[1] = () => {
1390
+ u.value = !1;
1391
+ }),
1392
+ onValidationSuccess: o[2] || (o[2] = () => {
1393
+ u.value = !0;
1394
+ }),
1395
+ blameFormChildOnValidationFailed: ""
1396
+ }, {
1397
+ default: P(() => [
1398
+ t("p", un, [
1399
+ o[6] || (o[6] = t("b", null, "Date:", -1)),
1400
+ o[7] || (o[7] = t("br", null, null, -1)),
1401
+ ve(" " + d(s(eo)(s(Ut)(q.value._id))), 1)
1402
+ ]),
1403
+ t("div", cn, [
1404
+ (A(!0), X(ce, null, ye(q.value.skus, (U, L) => (A(), X(ce, { key: L }, [
1405
+ (A(!0), X(ce, null, ye(U.amounts, (O, Z) => (A(), ee(M, {
1406
+ key: Z,
1407
+ variant: "outlined",
1408
+ class: "p-2"
1409
+ }, {
1410
+ default: P(() => [
1411
+ t("div", dn, [
1412
+ t("span", mn, d(U.sku.code), 1),
1413
+ t("span", null, d(U.sku.name), 1)
1414
+ ]),
1415
+ o[12] || (o[12] = t("hr", { class: "m-2" }, null, -1)),
1416
+ t("div", fn, [
1417
+ o[8] || (o[8] = t("span", { class: "fm-typo-en-body-lg-600" }, "Adjustment type:", -1)),
1418
+ t("span", null, d(O.type), 1)
1419
+ ]),
1420
+ t("div", vn, [
1421
+ o[9] || (o[9] = t("span", { class: "fm-typo-en-body-lg-600" }, "Current amount:", -1)),
1422
+ t("span", null, d(s(K).toFormatString({ value: O.amount })) + " " + d(g(U, O)), 1)
1423
+ ]),
1424
+ p(f, {
1425
+ "max-fraction-digits": s(Be)(U.sku.unit),
1426
+ "model-value": i({
1427
+ skuId: U.sku._id,
1428
+ idx: Z,
1429
+ unit: U.sku.unit
1430
+ }).value,
1431
+ "onUpdate:modelValue": (ne) => i({
1432
+ skuId: U.sku._id,
1433
+ idx: Z,
1434
+ unit: U.sku.unit
1435
+ }).value = ne,
1436
+ class: "mb-3",
1437
+ label: "Adjust Amount (Leave 0 to skip)",
1438
+ "helper-text": `Max: ${F(O.amount)}`,
1439
+ "append-text": g(U, O),
1440
+ rules: [
1441
+ (ne) => ne <= F(O.amount) || `Cannot be more than ${F(O.amount)}`,
1442
+ (ne) => s(et)(-1)(ne ?? 0)
1443
+ ]
1444
+ }, null, 8, ["max-fraction-digits", "model-value", "onUpdate:modelValue", "helper-text", "append-text", "rules"]),
1445
+ t("div", pn, [
1446
+ o[10] || (o[10] = t("span", { class: "fm-typo-en-body-lg-600" }, "Amount after amend:", -1)),
1447
+ o[11] || (o[11] = t("span", { class: "text-fm-color-system-warning-400 fm-typo-en-body-sm-400" }, "* It's an estimate for your reference, as it didn't include all the reversals related to this adjustment", -1)),
1448
+ ve(" " + d(c(
1449
+ O.amount,
1450
+ s(K).fromNumber(
1451
+ i({
1452
+ skuId: U.sku._id,
1453
+ idx: Z,
1454
+ unit: U.sku.unit
1455
+ }).value
1456
+ )
1457
+ )) + " " + d(g(U, O)), 1)
1458
+ ])
1459
+ ]),
1460
+ _: 2
1461
+ }, 1024))), 128))
1462
+ ], 64))), 128))
1463
+ ])
1464
+ ]),
1465
+ _: 1
1466
+ }, 512))
1467
+ ]),
1468
+ _: 1
1469
+ }, 8, ["modelValue"]);
1470
+ };
1471
+ }
1472
+ }), hn = { class: "p-16" }, bn = { class: "fm-typo-en-body-md-600 flex-grow" }, gn = ["onClick"], xn = { class: "flex-grow text-fm-color-typo-secondary" }, Sn = {
1473
+ key: 0,
1474
+ class: "my-5"
1475
+ }, wn = { class: "shrink-0 whitespace-nowrap text-neutral-400" }, Fn = { class: "flex-grow min-w-0" }, An = { class: "flex gap-1" }, $n = { class: "flex flex-wrap items-center gap-x-1 min-w-0 break-words" }, jn = ["onClick"], Cn = { class: "flex flex-col gap-1" }, Vn = {
1476
+ key: 1,
1477
+ class: "t-system text-fsecondary"
1478
+ }, Bn = {
1479
+ key: 2,
1480
+ class: "text-xs text-gray-400"
1481
+ }, Dn = { key: 3 }, In = { key: 4 }, Mn = { class: "inline-flex items-center gap-0.5 text-fm-color-typo-secondary" }, Tn = {
1482
+ key: 6,
1483
+ class: "inline-flex items-center rounded-md bg-yellow-400/10 px-2 text-xs font-medium text-yellow-500 inset-ring inset-ring-yellow-400/20"
1484
+ }, Hn = { class: "shrink-0 whitespace-nowrap text-fm-color-typo-secondary" }, En = ["onClick"], Un = /* @__PURE__ */ _e({
1485
+ __name: "StockRecordCard",
1486
+ props: {
1487
+ record: {},
1488
+ sku: {},
1489
+ bills: { default: () => [] },
1490
+ unitCostHistory: { default: () => [] },
1491
+ costMechanism: { default: "adjustment" },
1492
+ typeFilter: { default: null },
1493
+ debug: { type: Boolean, default: !1 }
1494
+ },
1495
+ emits: ["refreshHistory", "toggleType"],
1496
+ setup($) {
1497
+ const a = $;
1498
+ function k(i, F) {
1499
+ if (a.costMechanism === "adjustment")
1500
+ return null;
1501
+ const g = a.unitCostHistory.filter(
1502
+ (o) => o.mechanism === a.costMechanism && o.skuId === a.sku._id
1503
+ );
1504
+ if (g.length === 0) return null;
1505
+ const c = g.find((o) => {
1506
+ const e = o.meta;
1507
+ return (e == null ? void 0 : e.adjustmentId) === i;
1508
+ });
1509
+ if (c) return c.cost;
1510
+ const m = [...g].filter((o) => new Date(o.snapshotAt) <= new Date(F)).sort((o, e) => new Date(e.snapshotAt).getTime() - new Date(o.snapshotAt).getTime());
1511
+ return m.length > 0 ? m[0].cost : null;
1512
+ }
1513
+ const y = Y(!1), w = Y(), j = Y(null), n = z(() => j.value === null ? "unset" : y.value ? `${j.value}px` : "0px");
1514
+ Qe(() => {
1515
+ var i;
1516
+ j.value = ((i = w.value) == null ? void 0 : i.scrollHeight) || 0;
1517
+ });
1518
+ const u = z(() => {
1519
+ var o;
1520
+ const i = a.record.adjustments, F = a.sku, g = {}, m = i.flatMap((e) => {
1521
+ var f;
1522
+ return ((f = e.skus) == null ? void 0 : f.filter((M) => M.sku._id === F._id)) ?? [];
1523
+ }).flatMap((e) => e.amounts);
1524
+ for (const e of m) {
1525
+ const f = e.measurement ? gt(e.measurement.conversion, e.amount) : e.amount;
1526
+ g[o = e.type] ?? (g[o] = { amount: 0, precision: 0 }), g[e.type] = tt(f, g[e.type]);
1527
+ }
1528
+ return Object.entries(g).reduce(
1529
+ (e, [f, M]) => (e[f] = /// comment, because without it formatter makes code uglier
1530
+ `${K.toFormatString({
1531
+ value: M,
1532
+ precision: 4
1533
+ })} ${F.unit.abbrev}`, e),
1534
+ {}
1535
+ );
1536
+ }), { t: V } = ke(), q = we();
1537
+ async function I(i) {
1538
+ await navigator.clipboard.writeText(i), q.open({ message: `Copied ${i}`, type: "success" });
1539
+ }
1540
+ const x = z(() => a.record.adjustmentsByTime.map(({ date: F, adjustments: g }) => ({
1541
+ time: to(new Date(F)),
1542
+ adjustments: g.flatMap(
1543
+ (c) => {
1544
+ var m, o;
1545
+ return ((o = (m = c.skus) == null ? void 0 : m.map) == null ? void 0 : o.call(m, (e) => {
1546
+ var f, M;
1547
+ return {
1548
+ ...e,
1549
+ ref: c.ref,
1550
+ reason: c.reason,
1551
+ adjustmentRemark: c.remark,
1552
+ backdateFrom: c.effectiveAt != null ? Re(c._id) : null,
1553
+ toBalance: (M = (f = c.skus) == null ? void 0 : f[0]) == null ? void 0 : M.toBalance,
1554
+ adjustmentId: c._id,
1555
+ adjustmentTime: c.effectiveAt ?? Re(c._id),
1556
+ createdBy: c.createdBy
1557
+ };
1558
+ })) ?? [];
1559
+ }
1560
+ ).flatMap((c) => {
1561
+ var M;
1562
+ const m = (M = a.bills.find((E) => E._id === c.ref)) == null ? void 0 : M.seqNumber, o = m ? V("inventory.stock.record.bill", [m]) : "", e = c.adjustmentTime ?? (/* @__PURE__ */ new Date()).toISOString(), f = k(c.adjustmentId, e);
1563
+ return (c.amounts || []).filter((E) => E != null).filter((E) => !a.typeFilter || E.type === a.typeFilter).map((E) => {
1564
+ var J;
1565
+ let N = E.cost;
1566
+ if (f) {
1567
+ const U = K.fromDinero(f), L = E.amount, O = E.measurement ? K.multiply([L, E.measurement.conversion]) : L;
1568
+ N = {
1569
+ ...K.multiply([
1570
+ U,
1571
+ O
1572
+ ]),
1573
+ currency: f.currency
1574
+ };
1575
+ }
1576
+ let G = "";
1577
+ return o ? G = E.remark || "" : G = [c.adjustmentRemark, E.remark].filter((L) => L).join("/"), {
1578
+ amount: `${K.toFormatString({ value: E.amount, precision: 4 })} ${((J = E.measurement) == null ? void 0 : J.abbrev) ?? c.sku.unit.abbrev}`,
1579
+ backdateFrom: c.backdateFrom,
1580
+ name: E.type,
1581
+ billRemark: o,
1582
+ remark: G,
1583
+ reason: c.reason || "",
1584
+ cost: N,
1585
+ toBalance: K.toFormatString({
1586
+ value: c.toBalance ?? K.fromNumber(0),
1587
+ precision: 4
1588
+ }),
1589
+ baseUnit: c.sku.unit.abbrev,
1590
+ adjustmentId: c.adjustmentId,
1591
+ createdBy: c.createdBy
1592
+ };
1593
+ });
1594
+ })
1595
+ })).filter((F) => F.adjustments.length > 0));
1596
+ return Se(
1597
+ () => a.typeFilter,
1598
+ (i) => {
1599
+ i && (y.value = !0);
1600
+ },
1601
+ { immediate: !0 }
1602
+ ), Se([x, () => a.debug], async () => {
1603
+ var i;
1604
+ await Ct(), j.value = ((i = w.value) == null ? void 0 : i.scrollHeight) || 0;
1605
+ }), (i, F) => {
1606
+ const g = H("FmIcon"), c = H("FmTooltip"), m = H("FmCard");
1607
+ return A(), ee(m, {
1608
+ variant: "outlined",
1609
+ style: { overflow: "clip" }
1610
+ }, {
1611
+ default: P(() => [
1612
+ t("div", hn, [
1613
+ t("div", {
1614
+ class: "sticky top-0 z-10 bg-white flex items-center cursor-pointer py-4 mb-1",
1615
+ onClick: F[0] || (F[0] = (o) => y.value = !y.value)
1616
+ }, [
1617
+ t("div", bn, d(i.record.date), 1),
1618
+ p(g, {
1619
+ name: y.value ? "expand_more" : "expand_less",
1620
+ color: "#777777",
1621
+ size: "md"
1622
+ }, null, 8, ["name"])
1623
+ ]),
1624
+ (A(!0), X(ce, null, ye(u.value, (o, e) => (A(), X("div", {
1625
+ key: e,
1626
+ class: $e(["flex flex-row py-1 px-8 -mx-8 rounded-md cursor-pointer select-none transition-colors hover:bg-gray-100", {
1627
+ "opacity-40": i.typeFilter && i.typeFilter !== e,
1628
+ "font-bold bg-gray-100": i.typeFilter === e
1629
+ }]),
1630
+ style: { "font-size": "0.8rem" },
1631
+ onClick: (f) => i.$emit("toggleType", e)
1632
+ }, [
1633
+ t("div", xn, d(s(V)(`inventory.inventoryAdjustment.type.${e}`)), 1),
1634
+ t("div", {
1635
+ class: $e({
1636
+ "text-fm-color-typo-error": o.startsWith("-"),
1637
+ "text-fm-color-typo-success": !o.startsWith("-"),
1638
+ "ml-auto": !0
1639
+ })
1640
+ }, d(o), 3)
1641
+ ], 10, gn))), 128)),
1642
+ t("div", {
1643
+ ref_key: "detailRef",
1644
+ ref: w,
1645
+ style: _t({
1646
+ fontSize: "0.8rem",
1647
+ maxHeight: n.value,
1648
+ overflow: "hidden",
1649
+ transition: "max-height 0.2s ease-out"
1650
+ })
1651
+ }, [
1652
+ x.value.length ? (A(), X("hr", Sn)) : oe("", !0),
1653
+ (A(!0), X(ce, null, ye(x.value, (o) => (A(), X("div", {
1654
+ key: o.time,
1655
+ class: "flex gap-1 w-full"
1656
+ }, [
1657
+ t("div", wn, d(o.time), 1),
1658
+ t("div", Fn, [
1659
+ (A(!0), X(ce, null, ye(o.adjustments, (e) => {
1660
+ var f;
1661
+ return A(), X("div", {
1662
+ key: e.name
1663
+ }, [
1664
+ t("div", An, [
1665
+ t("div", $n, [
1666
+ t("span", {
1667
+ class: "cursor-pointer hover:underline",
1668
+ onClick: (M) => i.$emit("toggleType", e.name)
1669
+ }, d(s(V)(`inventory.inventoryAdjustment.type.${e.name}`)), 9, jn),
1670
+ e.backdateFrom ? (A(), ee(c, {
1671
+ key: 0,
1672
+ variant: "plain",
1673
+ placement: "top",
1674
+ "z-index": 50
1675
+ }, {
1676
+ content: P(() => [
1677
+ t("div", Cn, d(s(V)("inventory.stock.record.backdate", [
1678
+ s(St)(new Date(e.backdateFrom))
1679
+ ])), 1)
1680
+ ]),
1681
+ default: P(() => [
1682
+ p(g, {
1683
+ name: "info",
1684
+ size: "sm",
1685
+ color: "primary"
1686
+ })
1687
+ ]),
1688
+ _: 2
1689
+ }, 1024)) : oe("", !0),
1690
+ e.billRemark ? (A(), X("span", Vn, " # " + d(e.billRemark), 1)) : oe("", !0),
1691
+ e.billRemark && e.remark ? (A(), X("span", Bn, " (" + d(e.remark) + ") ", 1)) : oe("", !0),
1692
+ !e.billRemark && e.reason ? (A(), X("span", Dn, " (" + d(e.reason) + ") ", 1)) : oe("", !0),
1693
+ !e.billRemark && e.remark ? (A(), X("span", In, " # " + d(e.remark), 1)) : oe("", !0),
1694
+ (f = e.createdBy) != null && f.name ? (A(), ee(c, {
1695
+ key: 5,
1696
+ variant: "plain",
1697
+ placement: "top",
1698
+ "z-index": 50
1699
+ }, {
1700
+ content: P(() => [
1701
+ ve(d(s(V)("inventory.stock.record.createdBy", [e.createdBy.name])), 1)
1702
+ ]),
1703
+ default: P(() => [
1704
+ t("span", Mn, [
1705
+ p(g, {
1706
+ name: "person",
1707
+ size: "sm",
1708
+ color: "primary"
1709
+ }),
1710
+ ve(" " + d(e.createdBy.name), 1)
1711
+ ])
1712
+ ]),
1713
+ _: 2
1714
+ }, 1024)) : oe("", !0),
1715
+ e.name === s(ie).Enum.CLOSING ? (A(), X("span", Tn, " Actual Balance: " + d(e.toBalance) + " " + d(e.baseUnit), 1)) : oe("", !0)
1716
+ ]),
1717
+ t("div", {
1718
+ class: $e({
1719
+ "text-fm-color-typo-error": e.amount.startsWith("-"),
1720
+ "text-fm-color-typo-success": !e.amount.startsWith("-"),
1721
+ "ml-auto shrink-0 whitespace-nowrap": !0
1722
+ })
1723
+ }, d(e.amount), 3),
1724
+ e.name === s(ie).Enum.WASTAGE ? (A(), ee(kn, {
1725
+ key: 0,
1726
+ adjustmentId: e.adjustmentId,
1727
+ onRefreshHistory: F[1] || (F[1] = (M) => i.$emit("refreshHistory"))
1728
+ }, null, 8, ["adjustmentId"])) : oe("", !0),
1729
+ e.cost ? (A(), ee(wt, {
1730
+ key: 1,
1731
+ "feature-key": "total-cost",
1732
+ compact: ""
1733
+ }, {
1734
+ default: P(() => [
1735
+ t("div", Hn, " (" + d(s(Ue)(e.cost, !1, e.cost.precision)) + ") ", 1)
1736
+ ]),
1737
+ _: 2
1738
+ }, 1024)) : oe("", !0)
1739
+ ]),
1740
+ i.debug ? (A(), X("button", {
1741
+ key: 0,
1742
+ class: "flex items-center gap-1 mb-2 font-mono text-[11px] text-neutral-400 hover:text-neutral-600",
1743
+ onClick: (M) => I(e.adjustmentId)
1744
+ }, [
1745
+ ve(d(e.adjustmentId) + " ", 1),
1746
+ p(g, {
1747
+ name: "content_copy",
1748
+ size: "sm"
1749
+ })
1750
+ ], 8, En)) : oe("", !0)
1751
+ ]);
1752
+ }), 128))
1753
+ ])
1754
+ ]))), 128))
1755
+ ], 4)
1756
+ ])
1757
+ ]),
1758
+ _: 1
1759
+ });
1760
+ };
1761
+ }
1762
+ });
1763
+ function Pn($, a) {
1764
+ var j;
1765
+ const k = Object.keys(ie.enum).reduce(
1766
+ (n, u) => (n[u] = { amount: 0, precision: 0 }, n),
1767
+ {}
1768
+ );
1769
+ if (!a)
1770
+ return Object.entries(k).reduce(
1771
+ (n, [u]) => (n[u] = K.fromNumber(0), n),
1772
+ {}
1773
+ );
1774
+ const w = $.flatMap((n) => {
1775
+ var u;
1776
+ return ((u = n.skus) == null ? void 0 : u.filter((V) => V.sku._id === a._id)) ?? [];
1777
+ }).flatMap((n) => n.amounts);
1778
+ for (const n of w) {
1779
+ const u = n.measurement ? K.multiply([n.measurement.conversion, n.amount]) : n.amount;
1780
+ k[j = n.type] ?? (k[j] = { amount: 0, precision: 0 }), k[n.type] = K.add([u, k[n.type]]);
1781
+ }
1782
+ return Object.entries(k).reduce(
1783
+ (n, [u, V]) => {
1784
+ const q = {
1785
+ ...V,
1786
+ amount: Math.abs(V.amount)
1787
+ };
1788
+ return n[u] = /// comment, because without it formatter makes code uglier
1789
+ `${K.toFormatString({
1790
+ value: q,
1791
+ precision: 4
1792
+ })} ${a.unit.abbrev}`, n;
1793
+ },
1794
+ {}
1795
+ );
1796
+ }
1797
+ function Rn($, a) {
1798
+ if (!a)
1799
+ return null;
1800
+ let k = null;
1801
+ const w = $.flatMap((j) => {
1802
+ var n;
1803
+ return ((n = j.skus) == null ? void 0 : n.filter((u) => u.sku._id === a._id)) ?? [];
1804
+ }).flatMap((j) => {
1805
+ var n;
1806
+ return !j.history || ((n = j.history) == null ? void 0 : n.length) === 0 ? [] : j.history[0];
1807
+ });
1808
+ for (const j of w) {
1809
+ const n = j.amounts;
1810
+ for (const u of n) {
1811
+ if (u.type !== ie.Enum.SALES)
1812
+ continue;
1813
+ const V = u.measurement ? K.multiply([u.measurement.conversion, u.amount]) : u.amount;
1814
+ k ?? (k = K.fromNumber(0)), k = K.add([k, V]);
1815
+ }
1816
+ }
1817
+ return k != null ? (k.amount = Math.abs(k.amount), `${K.toFormatString({
1818
+ value: k,
1819
+ precision: 4
1820
+ })} ${a.unit.abbrev}`) : null;
1821
+ }
1822
+ const Nn = { class: "flex items-center w-full fm-typo-en-title-md-800" }, On = { class: "flex-1 line-clamp-2" }, Ln = { class: "flex flex-col gap-32 w-full h-full" }, Yn = { class: "flex flex-col gap-16" }, zn = { class: "flex items-center relative gap-4" }, Gn = { class: "flex-1" }, Wn = { class: "flex items-center gap-8" }, Kn = { class: "flex items-center gap-8" }, qn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Xn = { class: "fm-typo-cn-body-lg-600 flex-grow" }, Jn = {
1823
+ key: 0,
1824
+ class: "grid gap-12 fm-typo-en-body-md-400",
1825
+ style: { "grid-template-columns": "auto auto auto", "grid-auto-rows": "1fr" }
1826
+ }, Qn = { class: "flex flex-col gap-1" }, Zn = { class: "text-fm-color-typo-secondary" }, es = { class: "font-bold" }, ts = { class: "flex flex-col gap-1" }, os = { class: "text-fm-color-typo-secondary flex" }, ns = { class: "font-bold" }, ss = { class: "flex flex-col gap-1" }, as = { class: "text-fm-color-typo-secondary" }, rs = { class: "font-bold" }, ls = { class: "flex flex-col gap-1" }, is = { class: "text-fm-color-typo-secondary" }, us = { class: "font-bold" }, cs = { class: "flex flex-col gap-1" }, ds = { class: "text-fm-color-typo-secondary" }, ms = { class: "font-bold" }, fs = { class: "flex flex-col gap-1" }, vs = { class: "text-fm-color-typo-secondary" }, ps = { class: "font-bold" }, ys = { class: "flex flex-col gap-1" }, _s = { class: "text-fm-color-typo-secondary" }, ks = { class: "font-bold" }, hs = { class: "flex flex-col gap-1" }, bs = { class: "text-fm-color-typo-secondary" }, gs = { class: "font-bold" }, xs = { class: "flex flex-col gap-1" }, Ss = { class: "text-fm-color-typo-secondary" }, ws = { class: "font-bold" }, Fs = { class: "flex flex-col gap-8" }, As = { class: "flex" }, $s = { class: "flex-1 flex flex-col gap-1" }, js = { class: "flex items-center gap-8" }, Cs = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, Vs = { class: "font-bold" }, Bs = { class: "flex-1 flex flex-col gap-1" }, Ds = { class: "flex items-center gap-8" }, Is = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, Ms = { class: "flex flex-col gap-1" }, Ts = { class: "font-bold" }, Hs = {
1827
+ key: 0,
1828
+ class: "flex-1 flex flex-col items-center gap-16"
1829
+ }, Es = { class: "fm-typo-en-body-lg-400 translate-x-4" }, Us = {
1830
+ key: 1,
1831
+ class: "flex flex-col gap-12"
1832
+ }, Ps = {
1833
+ key: 2,
1834
+ class: "flex-1 flex flex-col items-center gap-8"
1835
+ }, Rs = ["src"], Ns = { class: "font-bold text-lg" }, Os = { class: "text-xs text-neutral-400 text-center" }, Ls = /* @__PURE__ */ _e({
1836
+ __name: "StockHistory",
1837
+ props: {
1838
+ sku: {},
1839
+ show: { type: Boolean }
1840
+ },
1841
+ emits: ["update:show"],
1842
+ setup($) {
1843
+ const a = Ze(), k = Ye(), y = Ce(), w = rn(), j = je(), { t: n } = ke(), u = $, V = Y(!1), q = we(), I = Y("adjustment"), x = Y([
1844
+ { label: "Adjustment (Default)", value: "adjustment" }
1845
+ ]), i = Y([]), F = Y(ao(0));
1846
+ async function g() {
1847
+ V.value = !0;
1848
+ try {
1849
+ await M(), await k.readStockBalance();
1850
+ } catch (r) {
1851
+ q.open({
1852
+ title: "Something went wrong",
1853
+ message: "Cannot fetch stock history. Please try again.",
1854
+ type: "error"
1855
+ }), console.log("failed at fetching item adjustment history", u.sku, F, r);
1856
+ } finally {
1857
+ V.value = !1;
1858
+ }
1859
+ }
1860
+ Qe(() => {
1861
+ g();
1862
+ }), Se([() => F.value, () => u.sku], () => {
1863
+ g();
1864
+ });
1865
+ const c = Y([]), m = Y([]), o = Y(new Array());
1866
+ function e(r, _) {
1867
+ return _ === "day" ? so(r) : St(r);
1868
+ }
1869
+ function f(r, _) {
1870
+ const B = r.reduce(
1871
+ (b, l) => {
1872
+ const S = l.effectiveAt ?? Re(l._id);
1873
+ if (!S)
1874
+ return b;
1875
+ const C = e(new Date(S), _);
1876
+ return b[C] ?? (b[C] = []), b[C].push(l), b;
1877
+ },
1878
+ {}
1879
+ );
1880
+ return Object.keys(B).map((b) => ({
1881
+ date: b,
1882
+ adjustments: B[b]
1883
+ }));
1884
+ }
1885
+ async function M() {
1886
+ let r = await y.readStockAdjustment(
1887
+ u.sku._id,
1888
+ ct(new Date(F.value.startDate)).toISOString(),
1889
+ dt(new Date(F.value.endDate)).toISOString()
1890
+ );
1891
+ c.value = r;
1892
+ const _ = r.filter(({ ref: B }) => B == null ? void 0 : B.startsWith("bill_")).map(({ ref: B }) => B);
1893
+ await E(_), m.value = f(r, "day").map(({ date: B, adjustments: b }) => ({
1894
+ date: B,
1895
+ adjustments: b,
1896
+ adjustmentsByTime: f(b, "minute")
1897
+ }));
1898
+ try {
1899
+ const B = await y.readUnitCostHistory(
1900
+ u.sku._id,
1901
+ ct(new Date(F.value.startDate)).toISOString(),
1902
+ dt(new Date(F.value.endDate)).toISOString()
1903
+ );
1904
+ i.value = B;
1905
+ const b = /* @__PURE__ */ new Set();
1906
+ B.forEach((S) => {
1907
+ b.add(S.mechanism);
1908
+ });
1909
+ const l = [{ label: "Default", value: "adjustment" }];
1910
+ b.has(Ae.Enum.weightedAverage) && l.push({
1911
+ label: "Weighted Average (Beta)",
1912
+ value: Ae.Enum.weightedAverage
1913
+ }), b.has(Ae.Enum.netsuite) && l.push({ label: "NetSuite (Beta)", value: Ae.Enum.netsuite }), b.has(Ae.Enum["netsuite-average"]) && l.push({
1914
+ label: "NetSuite Average (Beta)",
1915
+ value: Ae.Enum["netsuite-average"]
1916
+ }), x.value = l, !b.has(I.value) && I.value !== "adjustment" && (I.value = "adjustment");
1917
+ } catch (B) {
1918
+ console.error("Failed to fetch unit cost history:", B);
1919
+ }
1920
+ }
1921
+ async function E(r) {
1922
+ r.length && (o.value = await w.findBillsById(r).catch((_) => {
1923
+ var l;
1924
+ console.error("Error on using latest bill API, retrying using legacy api", _);
1925
+ const B = ((l = a.currentBusiness.value) == null ? void 0 : l._id) ?? "", b = j.currentLocation.doc._id;
1926
+ return w.findBillsByBusinessId(B, [b], r);
1927
+ }));
1928
+ }
1929
+ const N = z(() => {
1930
+ const r = c.value, _ = u.sku;
1931
+ return Pn(r, _);
1932
+ }), G = z(() => {
1933
+ const r = c.value, _ = u.sku;
1934
+ return Rn(r, _);
1935
+ }), J = z(() => {
1936
+ const r = [...c.value].computeFirst((B) => {
1937
+ var l, S;
1938
+ const b = (S = (l = B.skus) == null ? void 0 : l.find) == null ? void 0 : S.call(l, (C) => C.sku._id === u.sku._id);
1939
+ return b == null ? void 0 : b.fromBalance;
1940
+ }) ?? {
1941
+ amount: 0,
1942
+ precision: 0
1943
+ }, _ = u.sku;
1944
+ return _ ? `${K.toFormatString({
1945
+ value: r,
1946
+ precision: 4
1947
+ })} ${_.unit.abbrev}` : "";
1948
+ }), U = z(() => {
1949
+ const r = [...c.value].reverse().computeFirst((B) => {
1950
+ var l, S;
1951
+ const b = (S = (l = B.skus) == null ? void 0 : l.find) == null ? void 0 : S.call(l, (C) => C.sku._id === u.sku._id);
1952
+ return b == null ? void 0 : b.toBalance;
1953
+ }) ?? {
1954
+ amount: 0,
1955
+ precision: 0
1956
+ }, _ = u.sku;
1957
+ return _ ? `${K.toFormatString({ value: r, precision: 4 })} ${_.unit.abbrev}` : "";
1958
+ }), L = z(() => {
1959
+ var B;
1960
+ const _ = c.value.flatMap((b) => {
1961
+ var l;
1962
+ return ((l = b.skus) == null ? void 0 : l.flatMap((S) => S.amounts)) ?? [];
1963
+ }).filter((b) => b.amount.amount < 0).reduce(
1964
+ (b, l) => {
1965
+ const S = l.cost;
1966
+ if (!S) return b;
1967
+ const C = {
1968
+ ...Xt(b, Math.max(b.precision, S.precision)),
1969
+ currency: S.currency
1970
+ };
1971
+ return {
1972
+ ...tt(C, S),
1973
+ currency: b.currency
1974
+ };
1975
+ },
1976
+ {
1977
+ amount: 0,
1978
+ precision: 0,
1979
+ currency: Te((B = a.currentCountry) == null ? void 0 : B.value)
1980
+ }
1981
+ );
1982
+ return Ue(_, !1, _.precision);
1983
+ });
1984
+ function O() {
1985
+ const { startDate: r, endDate: _ } = oo(F.value);
1986
+ r !== null && _ !== null && (F.value = {
1987
+ startDate: r,
1988
+ endDate: _
1989
+ });
1990
+ }
1991
+ const Z = z(() => n("inventory.ingredient.valuationMethod.WAVG"));
1992
+ function ne(r, _) {
1993
+ if (I.value === "adjustment")
1994
+ return null;
1995
+ const B = i.value.filter(
1996
+ (S) => S.mechanism === I.value && S.skuId === u.sku._id
1997
+ );
1998
+ if (B.length === 0) return null;
1999
+ const b = B.find((S) => {
2000
+ const C = S.meta;
2001
+ return (C == null ? void 0 : C.adjustmentId) === r;
2002
+ });
2003
+ if (b) return b.cost;
2004
+ const l = [...B].filter((S) => new Date(S.snapshotAt) <= new Date(_)).sort((S, C) => new Date(C.snapshotAt).getTime() - new Date(S.snapshotAt).getTime());
2005
+ return l.length > 0 ? l[0].cost : null;
2006
+ }
2007
+ const me = z(() => {
2008
+ var b, l, S, C, te, ae;
2009
+ const r = [...c.value].reverse().find((Q) => {
2010
+ var se, re;
2011
+ return (re = (se = Q.skus) == null ? void 0 : se.find) == null ? void 0 : re.call(se, (ue) => ue.sku._id === u.sku._id);
2012
+ });
2013
+ if (!r) return "No data";
2014
+ const _ = (b = r.skus) == null ? void 0 : b.find((Q) => Q.sku._id === u.sku._id);
2015
+ if (!_) return "No data";
2016
+ const B = _.toBalance;
2017
+ if (I.value === "adjustment") {
2018
+ const Q = [..._.amounts].reverse()[0], se = {
2019
+ amount: ((l = Q.cost) == null ? void 0 : l.amount) ?? 0,
2020
+ precision: ((S = Q.cost) == null ? void 0 : S.precision) ?? 0
2021
+ }, re = Q.amount, ue = re.amount == 0 ? K.fromNumber(0) : K.divide([se, re]);
2022
+ return {
2023
+ ...K.multiply([ue, B]),
2024
+ currency: ((C = Q.cost) == null ? void 0 : C.currency) || Te(((te = a.currentCountry) == null ? void 0 : te.value) ?? rt)
2025
+ };
2026
+ } else {
2027
+ const Q = r.effectiveAt ?? Re(r._id), se = ne(
2028
+ r._id,
2029
+ Q ?? (/* @__PURE__ */ new Date()).toISOString()
2030
+ );
2031
+ if (!se) return "No data";
2032
+ const re = K.fromDinero(se);
2033
+ return {
2034
+ ...K.multiply([re, B]),
2035
+ currency: se.currency || Te(((ae = a.currentCountry) == null ? void 0 : ae.value) ?? rt)
2036
+ };
2037
+ }
2038
+ }), fe = z(() => {
2039
+ var B;
2040
+ const r = [...c.value].reverse().computeFirst((b) => {
2041
+ var S, C;
2042
+ const l = (C = (S = b.skus) == null ? void 0 : S.find) == null ? void 0 : C.call(S, (te) => te.sku._id === u.sku._id);
2043
+ return l == null ? void 0 : l.toCostBalances;
2044
+ });
2045
+ return !r || r.some((b) => b.cost == null) ? "No data" : {
2046
+ ...r.reduce((b, l) => K.add([b, K.fromDinero(l.cost)]), {
2047
+ amount: 0,
2048
+ precision: 0
2049
+ }),
2050
+ currency: Te((B = a.currentCountry) == null ? void 0 : B.value)
2051
+ };
2052
+ }), le = z(() => u.sku.valuation === lt.Enum.FIFO ? fe.value : me.value);
2053
+ function he() {
2054
+ const { startDate: r, endDate: _ } = no(F.value);
2055
+ r !== null && _ !== null && (F.value = {
2056
+ startDate: r,
2057
+ endDate: _
2058
+ });
2059
+ }
2060
+ const v = Y(!0), h = Y(!1), T = Y(null);
2061
+ function W(r) {
2062
+ T.value = T.value === r ? null : r;
2063
+ }
2064
+ const D = z(() => {
2065
+ const r = T.value;
2066
+ return r ? m.value.filter(
2067
+ (_) => _.adjustments.some(
2068
+ (B) => {
2069
+ var b;
2070
+ return (b = B.skus) == null ? void 0 : b.some(
2071
+ (l) => l.sku._id === u.sku._id && l.amounts.some((S) => S.type === r)
2072
+ );
2073
+ }
2074
+ )
2075
+ ) : m.value;
2076
+ }), R = Ge(u, "show");
2077
+ return (r, _) => {
2078
+ const B = H("FmButton"), b = H("FmField"), l = H("FmDateRangePicker"), S = H("FmSpacer"), C = H("FmSwitch"), te = H("FmIcon"), ae = H("FmTooltip"), Q = H("FmMenuDivider"), se = H("FmChip"), re = H("FmSelect"), ue = H("FmCardSection"), be = H("FmCard"), Ie = H("FmCircularProgress"), Me = H("FmSideSheet");
2079
+ return A(), ee(Me, {
2080
+ "dismiss-away": "",
2081
+ modelValue: s(R),
2082
+ "onUpdate:modelValue": _[8] || (_[8] = (pe) => Ne(R) ? R.value = pe : null),
2083
+ "close-button": !1,
2084
+ "max-width": 800
2085
+ }, {
2086
+ "side-sheet-header": P(() => [
2087
+ t("div", Nn, [
2088
+ t("div", On, d(s(n)("inventory.stock.history.title", [r.sku.name])), 1),
2089
+ p(B, {
2090
+ variant: "tertiary",
2091
+ "prepend-icon": "close",
2092
+ onClick: _[0] || (_[0] = (pe) => R.value = !1)
2093
+ })
2094
+ ])
2095
+ ]),
2096
+ default: P(() => {
2097
+ var pe, Ve;
2098
+ return [
2099
+ t("div", Ln, [
2100
+ t("div", Yn, [
2101
+ t("div", zn, [
2102
+ t("div", Gn, [
2103
+ p(l, {
2104
+ modelValue: F.value,
2105
+ "onUpdate:modelValue": _[1] || (_[1] = (de) => F.value = de),
2106
+ "show-predefined-range": "",
2107
+ "start-label": "",
2108
+ "end-label": "",
2109
+ "z-index": 50
2110
+ }, {
2111
+ "trigger-button": P(({ opened: de }) => [
2112
+ p(b, {
2113
+ "prepend-icon": "calendar_month",
2114
+ focused: de
2115
+ }, {
2116
+ default: P(() => [
2117
+ ve(d(F.value.startDate) + " - " + d(F.value.endDate), 1)
2118
+ ]),
2119
+ _: 2
2120
+ }, 1032, ["focused"])
2121
+ ]),
2122
+ _: 1
2123
+ }, 8, ["modelValue"])
2124
+ ]),
2125
+ p(B, {
2126
+ variant: "tertiary",
2127
+ onClick: _[2] || (_[2] = (de) => O()),
2128
+ "prepend-icon": "navigate_before"
2129
+ }),
2130
+ p(B, {
2131
+ variant: "tertiary",
2132
+ onClick: _[3] || (_[3] = (de) => he()),
2133
+ "prepend-icon": "navigate_next"
2134
+ })
2135
+ ]),
2136
+ t("div", Wn, [
2137
+ T.value ? (A(), ee(B, {
2138
+ key: 0,
2139
+ variant: "secondary",
2140
+ label: s(n)(`inventory.inventoryAdjustment.type.${T.value}`),
2141
+ "append-icon": "close",
2142
+ onClick: _[4] || (_[4] = (de) => T.value = null)
2143
+ }, null, 8, ["label"])) : oe("", !0),
2144
+ p(S),
2145
+ p(We, null, {
2146
+ default: P(() => [
2147
+ t("div", Kn, [
2148
+ t("div", qn, d(s(n)("inventory.stock.history.debug")), 1),
2149
+ p(C, {
2150
+ modelValue: h.value,
2151
+ "onUpdate:modelValue": _[5] || (_[5] = (de) => h.value = de)
2152
+ }, null, 8, ["modelValue"])
2153
+ ])
2154
+ ]),
2155
+ _: 1
2156
+ })
2157
+ ]),
2158
+ !V.value && ((pe = m.value) != null && pe.length) ? (A(), ee(be, {
2159
+ key: 0,
2160
+ variant: "outlined"
2161
+ }, {
2162
+ default: P(() => [
2163
+ p(ue, { class: "flex flex-col gap-4" }, {
2164
+ default: P(() => [
2165
+ t("div", {
2166
+ class: $e(["flex items-center cursor-pointer", { "pb-16": v.value }]),
2167
+ onClick: _[6] || (_[6] = (de) => v.value = !v.value)
2168
+ }, [
2169
+ t("div", Xn, d(s(n)("inventory.stock.history.summary.title")), 1),
2170
+ p(te, {
2171
+ name: v.value ? "expand_more" : "expand_less",
2172
+ color: "#777777",
2173
+ size: "md"
2174
+ }, null, 8, ["name"])
2175
+ ], 2),
2176
+ v.value ? (A(), X("div", Jn, [
2177
+ t("div", Qn, [
2178
+ t("div", Zn, d(s(n)("inventory.stock.history.summary.totalPurchase")), 1),
2179
+ t("div", es, d(N.value.PURCHASE), 1)
2180
+ ]),
2181
+ t("div", ts, [
2182
+ t("div", os, [
2183
+ ve(d(s(n)("inventory.stock.history.summary.totalSales")) + "  ", 1),
2184
+ G.value != null ? (A(), ee(ae, {
2185
+ key: 0,
2186
+ variant: "plain",
2187
+ placement: "top",
2188
+ content: `Before: ${G.value}`,
2189
+ "z-index": 50
2190
+ }, {
2191
+ default: P(() => [
2192
+ p(te, {
2193
+ name: "warning",
2194
+ size: "sm"
2195
+ })
2196
+ ]),
2197
+ _: 1
2198
+ }, 8, ["content"])) : oe("", !0)
2199
+ ]),
2200
+ t("div", ns, d(N.value.SALES), 1)
2201
+ ]),
2202
+ t("div", ss, [
2203
+ t("div", as, d(s(n)("inventory.stock.history.summary.totalLose")), 1),
2204
+ t("div", rs, d(N.value.LOSE), 1)
2205
+ ]),
2206
+ t("div", ls, [
2207
+ t("div", is, d(s(n)("inventory.stock.history.summary.totalRequest")), 1),
2208
+ t("div", us, d(N.value.REQUEST), 1)
2209
+ ]),
2210
+ t("div", cs, [
2211
+ t("div", ds, d(s(n)("inventory.stock.history.summary.totalReceive")), 1),
2212
+ t("div", ms, d(N.value.RECEIVE), 1)
2213
+ ]),
2214
+ t("div", fs, [
2215
+ t("div", vs, d(s(n)("inventory.stock.history.summary.totalConvert")), 1),
2216
+ t("div", ps, d(N.value.CONVERT), 1)
2217
+ ]),
2218
+ t("div", ys, [
2219
+ t("div", _s, d(s(n)("inventory.stock.history.summary.totalDamage")), 1),
2220
+ t("div", ks, d(N.value.DAMAGE), 1)
2221
+ ]),
2222
+ t("div", hs, [
2223
+ t("div", bs, d(s(n)("inventory.stock.history.summary.openingBalance")), 1),
2224
+ t("div", gs, d(J.value), 1)
2225
+ ]),
2226
+ t("div", xs, [
2227
+ t("div", Ss, d(s(n)("inventory.stock.history.summary.lastStockBalance")), 1),
2228
+ t("div", ws, d(U.value), 1)
2229
+ ])
2230
+ ])) : oe("", !0),
2231
+ v.value ? (A(), ee(wt, {
2232
+ key: 1,
2233
+ "feature-key": "total-cost"
2234
+ }, {
2235
+ default: P(() => [
2236
+ t("div", Fs, [
2237
+ p(Q, { class: "w-full" }),
2238
+ t("div", As, [
2239
+ t("div", $s, [
2240
+ t("div", js, [
2241
+ t("div", Cs, [
2242
+ ve(d(s(n)("inventory.stock.history.estimatedValue")) + " ", 1),
2243
+ p(ae, {
2244
+ variant: "plain",
2245
+ placement: "top",
2246
+ content: `[${Z.value}] ${s(n)("inventory.stock.history.estimatedValueTooltip")}`,
2247
+ "z-index": 50
2248
+ }, {
2249
+ default: P(() => [
2250
+ p(te, {
2251
+ name: "help",
2252
+ size: "sm"
2253
+ })
2254
+ ]),
2255
+ _: 1
2256
+ }, 8, ["content"])
2257
+ ])
2258
+ ]),
2259
+ t("div", Vs, [
2260
+ r.sku.valuation === s(lt).Enum.FIFO ? (A(), X(ce, { key: 0 }, [
2261
+ p(se, {
2262
+ label: "FIFO",
2263
+ compact: ""
2264
+ }),
2265
+ ve(" " + d(typeof le.value != "string" ? s(Ue)(
2266
+ le.value,
2267
+ !1,
2268
+ le.value.precision
2269
+ ) : le.value), 1)
2270
+ ], 64)) : (A(), X(ce, { key: 1 }, [
2271
+ ve(d(typeof le.value != "string" ? s(Ue)(
2272
+ le.value,
2273
+ !1,
2274
+ le.value.precision
2275
+ ) : le.value), 1)
2276
+ ], 64))
2277
+ ]),
2278
+ p(re, {
2279
+ modelValue: I.value,
2280
+ "onUpdate:modelValue": _[7] || (_[7] = (de) => I.value = de),
2281
+ items: x.value,
2282
+ compact: "",
2283
+ size: "sm",
2284
+ style: { width: "200px" }
2285
+ }, null, 8, ["modelValue", "items"])
2286
+ ]),
2287
+ t("div", Bs, [
2288
+ t("div", Ds, [
2289
+ t("div", Is, [
2290
+ ve(d(s(n)("inventory.stock.history.costSold")) + " ", 1),
2291
+ p(ae, {
2292
+ variant: "plain",
2293
+ placement: "top",
2294
+ "z-index": 50
2295
+ }, {
2296
+ content: P(() => [
2297
+ t("div", Ms, d(s(n)("inventory.stock.history.costSoldTooltip")), 1)
2298
+ ]),
2299
+ default: P(() => [
2300
+ p(te, {
2301
+ name: "help",
2302
+ size: "sm"
2303
+ })
2304
+ ]),
2305
+ _: 1
2306
+ })
2307
+ ])
2308
+ ]),
2309
+ t("div", Ts, d(L.value), 1)
2310
+ ])
2311
+ ])
2312
+ ])
2313
+ ]),
2314
+ _: 1
2315
+ })) : oe("", !0)
2316
+ ]),
2317
+ _: 1
2318
+ })
2319
+ ]),
2320
+ _: 1
2321
+ })) : oe("", !0)
2322
+ ]),
2323
+ V.value ? (A(), X("div", Hs, [
2324
+ p(S),
2325
+ p(Ie, { size: "xl" }),
2326
+ t("div", Es, d(s(n)("inventory.stock.history.loading")), 1),
2327
+ p(S),
2328
+ p(S)
2329
+ ])) : m.value && ((Ve = m.value) == null ? void 0 : Ve.length) > 0 ? (A(), X("div", Us, [
2330
+ (A(!0), X(ce, null, ye(D.value, (de) => (A(), X(ce, {
2331
+ key: de.date
2332
+ }, [
2333
+ r.sku ? (A(), ee(Un, {
2334
+ key: 0,
2335
+ record: de,
2336
+ sku: r.sku,
2337
+ bills: o.value,
2338
+ "unit-cost-history": i.value,
2339
+ "cost-mechanism": I.value,
2340
+ "type-filter": T.value,
2341
+ debug: h.value,
2342
+ onRefreshHistory: g,
2343
+ onToggleType: W
2344
+ }, null, 8, ["record", "sku", "bills", "unit-cost-history", "cost-mechanism", "type-filter", "debug"])) : oe("", !0)
2345
+ ], 64))), 128))
2346
+ ])) : (A(), X("div", Ps, [
2347
+ p(S),
2348
+ t("div", null, [
2349
+ t("img", {
2350
+ src: s(ro),
2351
+ alt: "List is empty"
2352
+ }, null, 8, Rs)
2353
+ ]),
2354
+ t("div", Ns, d(s(n)("inventory.stock.history.noRecords")), 1),
2355
+ t("div", Os, d(s(n)("inventory.stock.history.changeDateRange")), 1),
2356
+ p(S),
2357
+ p(S)
2358
+ ]))
2359
+ ])
2360
+ ];
2361
+ }),
2362
+ _: 1
2363
+ }, 8, ["modelValue"]);
2364
+ };
2365
+ }
2366
+ }), Ys = /* @__PURE__ */ _e({
2367
+ __name: "HrmPermissionGuard",
2368
+ props: {
2369
+ permission: { default: void 0 },
2370
+ permissions: { default: void 0 },
2371
+ mode: { default: "all" }
2372
+ },
2373
+ setup($) {
2374
+ const a = $, k = z(() => {
2375
+ const w = [];
2376
+ return a.permission && w.push(a.permission), a.permissions && w.push(...a.permissions), w;
2377
+ });
2378
+ Vt(() => {
2379
+ });
2380
+ const { hasPermission: y } = Ft(k, () => a.mode);
2381
+ return (w, j) => s(y) ? nt(w.$slots, "default", { key: 0 }) : nt(w.$slots, "fallback", { key: 1 });
2382
+ }
2383
+ });
2384
+ function zs($) {
2385
+ const a = uo(), k = je(), y = Y(!1), w = Y(null), j = Y(null);
2386
+ let n = null, u = !1, V = !1;
2387
+ function q() {
2388
+ if (V) return;
2389
+ const i = k.currentLocationDBName;
2390
+ if (!i) return;
2391
+ V = !0;
2392
+ const F = {
2393
+ type: "refresh-balance",
2394
+ params: { locationId: i }
2395
+ }, { unsubscribe: g, initialState: c } = a.subscribe(
2396
+ F,
2397
+ I
2398
+ );
2399
+ n = g, c.then((m) => {
2400
+ m != null && m.initialState && I(m.initialState);
2401
+ }).catch((m) => {
2402
+ console.error("Failed to fetch refresh-balance initial state", m);
2403
+ });
2404
+ }
2405
+ async function I(i) {
2406
+ var F, g, c;
2407
+ if (!(!V || !i)) {
2408
+ if (w.value = i, i.completedAt && (j.value = i.completedAt), i.message === "processing" || !i.completedAt && !i.message) {
2409
+ u = !0, y.value = !0;
2410
+ return;
2411
+ }
2412
+ if (i.message === "completed" || i.completedAt) {
2413
+ if (!u) return;
2414
+ x();
2415
+ try {
2416
+ await $.onCompleted();
2417
+ } catch (m) {
2418
+ console.error("Failed to reload after refresh", m);
2419
+ }
2420
+ return;
2421
+ }
2422
+ if (i.message === "error" || (F = i.message) != null && F.startsWith("error:")) {
2423
+ console.log("Stock balance refresh error:", i.message);
2424
+ const m = (g = i.message) != null && g.startsWith("error:") ? i.message.slice(6).trim() : "Failed to refresh stock balance.";
2425
+ x(), await ((c = $.onError) == null ? void 0 : c.call($, m));
2426
+ }
2427
+ }
2428
+ }
2429
+ function x() {
2430
+ n && (n(), n = null), V = !1, u = !1, y.value = !1, w.value = null;
2431
+ }
2432
+ return Bt(() => {
2433
+ x();
2434
+ }), {
2435
+ refreshing: y,
2436
+ refreshStatus: w,
2437
+ lastCompletedAt: j,
2438
+ startListening: q,
2439
+ stopListening: x
2440
+ };
2441
+ }
2442
+ const Gs = {
2443
+ key: 0,
2444
+ class: "flex items-center gap-1"
2445
+ }, Ws = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ks = { class: "flex flex-col gap-8" }, qs = { class: "flex flex-col" }, Xs = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Js = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary line-clamp-1" }, Va = /* @__PURE__ */ _e({
2446
+ __name: "StockView",
2447
+ setup($) {
2448
+ const { t: a } = ke(), k = Le(), y = je(), w = Ye(), j = At(), n = Ce(), u = bt(), V = co(), { columnDefs: q } = ho(), I = Ze(), { hasPermission: x } = Ft(
2449
+ z(() => [
2450
+ {
2451
+ action: He.Action.manage,
2452
+ subject: He.Subject.Business.inventory_stockAdjustment
2453
+ }
2454
+ ])
2455
+ ), i = z(
2456
+ () => {
2457
+ var D;
2458
+ return x.value || ((D = I.sessionUser.value) == null ? void 0 : D.role.isAdmin);
2459
+ }
2460
+ ), F = ze(), g = we();
2461
+ y.watchLocation(J);
2462
+ const c = z(
2463
+ () => new Set(V.getAvailableItems(V.businessSubsidiaryId))
2464
+ ), m = Y(!1), o = Y(!1), { refreshing: e, lastCompletedAt: f, startListening: M, stopListening: E } = zs({
2465
+ onCompleted: async () => {
2466
+ await J(), o.value = !1, g.open({
2467
+ title: "Balance refreshed",
2468
+ message: "Stock balance has been recalculated.",
2469
+ type: "success"
2470
+ });
2471
+ },
2472
+ onError: (D) => {
2473
+ o.value = !1, console.log("Error refreshing stock balance", D), g.open({
2474
+ title: a("inventory.common.refreshFailed"),
2475
+ message: D || a("inventory.stock.stock_balance.refreshBalanceError"),
2476
+ type: "error"
2477
+ });
2478
+ }
2479
+ }), N = z(() => e.value || o.value);
2480
+ async function G() {
2481
+ M();
2482
+ const D = a("inventory.stock.stock_balance.refreshBalanceDescription"), R = f.value ? `${D}
2483
+
2484
+ Last refreshed: ${new Date(f.value).toLocaleString()}` : D;
2485
+ F.open({
2486
+ title: a("inventory.stock.stock_balance.refreshBalance"),
2487
+ message: R,
2488
+ closeButton: !0,
2489
+ primaryActions: {
2490
+ text: a("common.confirm"),
2491
+ close: !1,
2492
+ isLoading: N,
2493
+ disabled: N
2494
+ },
2495
+ secondaryActions: {
2496
+ text: a("common.close"),
2497
+ close: !0,
2498
+ variant: "tertiary",
2499
+ disabled: N
2500
+ }
2501
+ }).onPrimary(async () => {
2502
+ if (!o.value) {
2503
+ o.value = !0;
2504
+ try {
2505
+ await n.recalculation.refreshCurrentBalances();
2506
+ } catch (r) {
2507
+ console.log("Failed to queue refresh balan22ce", typeof r);
2508
+ const _ = typeof r == "object" ? JSON.stringify(r) : String(r);
2509
+ console.log("Error details:", _), o.value = !1, g.open({
2510
+ title: a("inventory.common.refreshFailed"),
2511
+ message: (r instanceof Error ? r.message : null) ?? a("inventory.stock.stock_balance.refreshBalanceError"),
2512
+ type: "error"
2513
+ });
2514
+ }
2515
+ }
2516
+ }).onClose(() => {
2517
+ o.value = !1, E();
2518
+ });
2519
+ }
2520
+ async function J() {
2521
+ if (y._currentLocation) {
2522
+ m.value = !0;
2523
+ try {
2524
+ await w.readStockBalance(), await u.readStockEstimateBalance();
2525
+ } catch (D) {
2526
+ g.open({
2527
+ title: a("inventory.stock.error.title"),
2528
+ message: a("inventory.stock.error.message"),
2529
+ type: "error"
2530
+ }), console.error("error on fetch stock balance", D);
2531
+ } finally {
2532
+ m.value = !1;
2533
+ }
2534
+ }
2535
+ }
2536
+ const U = z(() => [
2537
+ {
2538
+ type: "string",
2539
+ key: "status",
2540
+ entity: "sku",
2541
+ values: ["Active", "Inactive"]
2542
+ }
2543
+ ]), L = Y({
2544
+ logic: "AND",
2545
+ rules: [
2546
+ {
2547
+ property: "status",
2548
+ operator: "$in",
2549
+ value: ["Active"],
2550
+ type: "string"
2551
+ }
2552
+ ]
2553
+ }), O = z(() => {
2554
+ var r, _, B;
2555
+ const D = L.value ? mo.build(L.value) : null, R = [];
2556
+ for (const b of k.skus) {
2557
+ let l = !0;
2558
+ if (V.isEnabled && ne.value && c.value && l && (l = c.value.has(b._id)), D && l && (l = fo(
2559
+ {
2560
+ status: b.isInactive ? "Inactive" : "Active"
2561
+ },
2562
+ D
2563
+ )), l) {
2564
+ const S = b.trackingMeasurement;
2565
+ let C = (_ = (r = w.stockBalance.skus) == null ? void 0 : r.find(
2566
+ (Q) => Q.id === b._id
2567
+ )) == null ? void 0 : _.balance, te = u.inventoryForecast.skus.find(
2568
+ (Q) => Q.id === b._id
2569
+ );
2570
+ const ae = {
2571
+ ...b,
2572
+ balance: C ?? {
2573
+ amount: 0,
2574
+ precision: 0
2575
+ },
2576
+ operator: te == null ? void 0 : te.operator,
2577
+ day: (te == null ? void 0 : te.depletionDays) ?? void 0,
2578
+ trackingUnitAbbrev: S ? ((B = b.unit.measurements.find((Q) => Q.id === S)) == null ? void 0 : B.abbrev) ?? "" : b.unit.abbrev
2579
+ };
2580
+ R.push(ae);
2581
+ }
2582
+ }
2583
+ return R;
2584
+ }), Z = Y(""), ne = Y(!0), { breakpoints: me } = Lt(), fe = z(() => me.value.xs || me.value.sm), le = z(() => fe.value ? 10 : 20), he = It(), v = z(() => {
2585
+ const D = [
2586
+ {
2587
+ label: a("inventory.stock.stock_balance.refreshBalance"),
2588
+ value: "refresh-balance",
2589
+ isPrimary: !0,
2590
+ prependIcon: "calculate"
2591
+ },
2592
+ {
2593
+ label: a("inventory.common.refresh"),
2594
+ value: "refresh"
2595
+ },
2596
+ {
2597
+ label: a("inventory.common.export"),
2598
+ value: "export"
2599
+ }
2600
+ ];
2601
+ return i.value && D.push({
2602
+ label: a("inventory.stock.stock_adjustment.title"),
2603
+ value: "stockAdjustment"
2604
+ }), D;
2605
+ }), h = Y(!1);
2606
+ function T() {
2607
+ h.value = !0;
2608
+ }
2609
+ function W(D) {
2610
+ switch (D) {
2611
+ case "refresh-balance":
2612
+ return G();
2613
+ case "refresh":
2614
+ return J();
2615
+ case "export":
2616
+ return Rt(O.value);
2617
+ case "stockAdjustment":
2618
+ return T();
2619
+ }
2620
+ }
2621
+ return (D, R) => {
2622
+ const r = H("FmSwitch"), _ = H("FmTable");
2623
+ return A(), ee(Mt, {
2624
+ title: s(a)("inventory.stock.title"),
2625
+ actions: v.value,
2626
+ "onClick:action": W
2627
+ }, {
2628
+ default: P(() => {
2629
+ var B, b, l, S;
2630
+ return [
2631
+ t("div", {
2632
+ class: $e([
2633
+ "flex flex-col gap-8 max-h-full",
2634
+ {
2635
+ "p-0": fe.value,
2636
+ "px-24 ": !fe.value
2637
+ }
2638
+ ])
2639
+ }, [
2640
+ p(io, {
2641
+ searchable: "",
2642
+ "change-location": "",
2643
+ search: Z.value,
2644
+ "onUpdate:search": R[1] || (R[1] = (C) => Z.value = C),
2645
+ "hide-filter-options": !0,
2646
+ filterable: "",
2647
+ "filter-attributes": U.value,
2648
+ filter: L.value,
2649
+ "onUpdate:filter": R[2] || (R[2] = (C) => L.value = C)
2650
+ }, {
2651
+ default: P(() => [
2652
+ s(V).isEnabled ? (A(), X("div", Gs, [
2653
+ t("span", Ws, d(s(a)("inventory.integration.netsuite.subsidiaryHierarchy.filtering")), 1),
2654
+ p(Nt),
2655
+ p(We, null, {
2656
+ default: P(() => [
2657
+ p(r, {
2658
+ modelValue: ne.value,
2659
+ "onUpdate:modelValue": R[0] || (R[0] = (C) => ne.value = C)
2660
+ }, null, 8, ["modelValue"])
2661
+ ]),
2662
+ _: 1
2663
+ })
2664
+ ])) : oe("", !0)
2665
+ ]),
2666
+ _: 1
2667
+ }, 8, ["search", "filter-attributes", "filter"]),
2668
+ (A(), ee(_, {
2669
+ style: _t(s(he).tableHeight),
2670
+ "column-defs": s(q),
2671
+ "row-data": O.value,
2672
+ "search-value": Z.value,
2673
+ loading: m.value || s(e) || !s(y)._currentLocation,
2674
+ key: (B = s(y)._currentLocation) == null ? void 0 : B.dbName,
2675
+ onRowClick: R[3] || (R[3] = (C) => s(j).showSkuHistory(C.original)),
2676
+ "page-size": le.value
2677
+ }, {
2678
+ "list-row": P((C) => [
2679
+ p(lo, {
2680
+ row: C,
2681
+ onRowClick: s(j).showSkuHistory
2682
+ }, {
2683
+ default: P((te) => {
2684
+ var ae, Q, se, re, ue, be, Ie, Me, pe, Ve;
2685
+ return [
2686
+ t("div", Ks, [
2687
+ t("div", qs, [
2688
+ t("div", Xs, [
2689
+ p(s(mt), {
2690
+ render: (se = (Q = (ae = te.code) == null ? void 0 : ae.column) == null ? void 0 : Q.columnDef) == null ? void 0 : se.cell,
2691
+ props: (ue = (re = te.code) == null ? void 0 : re.getContext) == null ? void 0 : ue.call(re)
2692
+ }, null, 8, ["render", "props"])
2693
+ ]),
2694
+ t("div", Js, [
2695
+ p(s(mt), {
2696
+ render: (Me = (Ie = (be = te.name) == null ? void 0 : be.column) == null ? void 0 : Ie.columnDef) == null ? void 0 : Me.cell,
2697
+ props: (Ve = (pe = te.name) == null ? void 0 : pe.getContext) == null ? void 0 : Ve.call(pe)
2698
+ }, null, 8, ["render", "props"])
2699
+ ])
2700
+ ]),
2701
+ t("div", null, [
2702
+ p(Je, {
2703
+ days: C.original.day
2704
+ }, null, 8, ["days"])
2705
+ ]),
2706
+ t("div", null, [
2707
+ p(kt, {
2708
+ class: "xs:w-[160px]",
2709
+ unit: C.original.unit,
2710
+ sku: C.original,
2711
+ amount: C.original.balance,
2712
+ "default-tracking-measurement": C.original.trackingMeasurement ?? void 0
2713
+ }, null, 8, ["unit", "sku", "amount", "default-tracking-measurement"])
2714
+ ])
2715
+ ])
2716
+ ];
2717
+ }),
2718
+ _: 2
2719
+ }, 1032, ["row", "onRowClick"])
2720
+ ]),
2721
+ _: 1
2722
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
2723
+ ], 2),
2724
+ (A(), ee(Dt, { to: "body" }, [
2725
+ (b = s(j).stockHistoryProps) != null && b.sku ? (A(), ee(Ls, st(Ke({ key: 0 }, s(j).stockHistoryProps)), null, 16)) : oe("", !0),
2726
+ (l = s(j).convertSkuDialogProps) != null && l.sku ? (A(), ee(Mo, st(Ke({ key: 1 }, s(j).convertSkuDialogProps)), null, 16)) : oe("", !0),
2727
+ (S = s(j).adjustSkuDialogProps) != null && S.stock ? (A(), ee(Wo, Ke({ key: 2 }, s(j).adjustSkuDialogProps, {
2728
+ onSubmitted: R[4] || (R[4] = (C) => J())
2729
+ }), null, 16)) : oe("", !0),
2730
+ p(Ys, {
2731
+ permission: {
2732
+ action: s(He).Action.manage,
2733
+ subject: s(He).Subject.Business.inventory_stockAdjustment
2734
+ }
2735
+ }, {
2736
+ default: P(() => [
2737
+ h.value ? (A(), ee(an, {
2738
+ key: 0,
2739
+ show: h.value,
2740
+ "onUpdate:show": R[5] || (R[5] = (C) => h.value = C),
2741
+ onSubmitted: R[6] || (R[6] = (C) => J())
2742
+ }, null, 8, ["show"])) : oe("", !0)
2743
+ ]),
2744
+ _: 1
2745
+ }, 8, ["permission"])
2746
+ ]))
2747
+ ];
2748
+ }),
2749
+ _: 1
2750
+ }, 8, ["title", "actions"]);
2751
+ };
2752
+ }
2753
+ });
2754
+ export {
2755
+ Va as default
2756
+ };