@feedmepos/mf-inventory-portal 1.2.0 → 1.2.2-5.dev-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/App-DMkUg806.js +297 -0
  2. package/dist/{ApprovalView-Dr-qd_Ai.js → ApprovalView-DWJh2K6W.js} +65 -64
  3. package/dist/{BindingsDialog-Chh00-83.js → BindingsDialog-EmHCvqJI.js} +2 -2
  4. package/dist/{BindingsPicker-DCTGJ8eM.js → BindingsPicker-h_9jm1s0.js} +3 -3
  5. package/dist/{BindingsTable-BsDs5d0V.js → BindingsTable-BAVWGUoa.js} +1 -1
  6. package/dist/ClosingDraftView-Du4kOwIg.js +1899 -0
  7. package/dist/ClosingHistoryView-DuW2Vtrs.js +355 -0
  8. package/dist/ClosingTemplateView-CfPY8R5M.js +2001 -0
  9. package/dist/{DeliveryOrderPrintPreview-CrH9UVdW.js → DeliveryOrderPrintPreview-C6Cj8mOp.js} +9 -9
  10. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-WWIrybw_.js +230 -0
  11. package/dist/{FmMultiselectDialog-ypgaHejh.js → FmMultiselectDialog-BzWrQOS4.js} +1 -1
  12. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-DJctVhvZ.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DwqVRUFz.js} +36 -36
  13. package/dist/ImportView-lKlYeLay.js +1291 -0
  14. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-D59M4Bl1.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-_2WZMZU2.js} +5 -5
  15. package/dist/{IngredientGroupView-Cf9ePE7_.js → IngredientGroupView-CrmwR2Xt.js} +34 -35
  16. package/dist/IngredientsView-1bAsyz-b.js +2254 -0
  17. package/dist/{IntegrationView-DEDn2mc5.js → IntegrationView-D16qeEc_.js} +1773 -1635
  18. package/dist/{InventoryBindingForm-AB8rum4-.js → InventoryBindingForm-BRwOXV_P.js} +1 -1
  19. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-BgZt_9h1.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-NDbtbtqK.js} +28 -28
  20. package/dist/{InventoryBindingSummary-CWOG5DIz.js → InventoryBindingSummary-DKM2gX8_.js} +1 -1
  21. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CmN30iEZ.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CdaiYTdf.js} +4 -4
  22. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-C1cUDp0u.js → PremiumBadge.vue_vue_type_script_setup_true_lang-B0OKeK5O.js} +7 -7
  23. package/dist/{PublishView-FHyjjevA.js → PublishView-D0NnU22l.js} +73 -63
  24. package/dist/{PurchaseOrderPrintPreview-BPvvkjkR.js → PurchaseOrderPrintPreview-BmuwNbeL.js} +4 -4
  25. package/dist/{ReceiveRequestView-CoWU2g0R.js → ReceiveRequestView-j79m7TKk.js} +343 -333
  26. package/dist/RecipeView-D_fNQQ-C.js +636 -0
  27. package/dist/StockView-DX_xeFBT.js +2385 -0
  28. package/dist/SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Bg49isUy.js +172 -0
  29. package/dist/{SupplierView-CJG2Idbl.js → SupplierView-DuFTqbOg.js} +1193 -1073
  30. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-c428GXwc.js +3233 -0
  31. package/dist/{TransferTemplateView-DZnPt5b5.js → TransferTemplateView-Ccsfcetz.js} +104 -103
  32. package/dist/UnitView-BklpNsFN.js +674 -0
  33. package/dist/WarehouseView-BrURbU67.js +1066 -0
  34. package/dist/api/adjustment-template.d.ts +1 -0
  35. package/dist/api/bill.d.ts +140 -2
  36. package/dist/api/closing-template.d.ts +1 -0
  37. package/dist/api/closing.d.ts +1 -0
  38. package/dist/api/inventory.d.ts +405 -0
  39. package/dist/api/netsuite.d.ts +5 -1
  40. package/dist/api/purchase-order-template.d.ts +1 -0
  41. package/dist/api/purchase-order.d.ts +3 -0
  42. package/dist/api/shipment.d.ts +11 -0
  43. package/dist/api/stock.d.ts +2 -44
  44. package/dist/api/warehouse.d.ts +3 -1
  45. package/dist/{app-B6mXF-3v.js → app-a9r50k3U.js} +68557 -67576
  46. package/dist/app.d.ts +646 -15
  47. package/dist/app.js +6 -6
  48. package/dist/components/FmAdminBadge.vue.d.ts +1 -4
  49. package/dist/components/FmEnhancedSelect.vue.d.ts +30 -0
  50. package/dist/components/FmInventoryTableToolbar.vue.d.ts +16 -2
  51. package/dist/components/FmLockableField.vue.d.ts +3 -0
  52. package/dist/components/netsuite/ItemSubsidiaryTreeDialog.vue.d.ts +16 -0
  53. package/dist/components/netsuite/SubsidiaryTreeDialog.vue.d.ts +2 -0
  54. package/dist/composable/defineApi.d.ts +1 -1
  55. package/dist/composable/useIframe.d.ts +2 -2
  56. package/dist/{decimal-DErYDfEJ.js → decimal-AusUnA1W.js} +1 -1
  57. package/dist/{format-unit-display-BtjJtmQp.js → format-unit-display-BqkHL-ph.js} +397 -429
  58. package/dist/helper/array.d.ts +1 -0
  59. package/dist/helper/core/country/utils.d.ts +3 -4
  60. package/dist/helper/country.d.ts +6 -255
  61. package/dist/helper/number.d.ts +1 -0
  62. package/dist/import-export.helper-PIyNeHfa.js +238 -0
  63. package/dist/{index-lj4ClRIU.js → index-CjxirPvn.js} +283 -268
  64. package/dist/{index-CvfUsVdt.js → index-Dj9-pdT9.js} +1 -1
  65. package/dist/layout/SingleColumnLayout.vue.d.ts +6 -3
  66. package/dist/purchase-order-template-CQikvY1p.js +41 -0
  67. package/dist/router/name.d.ts +2 -0
  68. package/dist/stock-CDZ2uWSF.js +83 -0
  69. package/dist/stock-Dw908dIC.js +74 -0
  70. package/dist/stores/feature.d.ts +12 -0
  71. package/dist/stores/integration/netsuite.d.ts +42 -0
  72. package/dist/stores/inventory.d.ts +28 -199
  73. package/dist/stores/location.d.ts +331 -1
  74. package/dist/stores/supplier.d.ts +96 -0
  75. package/dist/stores/warehouse.d.ts +4 -0
  76. package/dist/style.css +1 -1
  77. package/dist/{supplier-D_2yzArc.js → supplier-BPPBUudN.js} +1 -1
  78. package/dist/tsconfig.app.tsbuildinfo +1 -1
  79. package/dist/{use-ingredient-select-dialog-C9iEMCVA.js → use-ingredient-select-dialog-C_fSKN3_.js} +5 -5
  80. package/dist/{use-inventory-binding-dialog-CavX3SFd.js → use-inventory-binding-dialog-ClAkJ864.js} +8 -8
  81. package/dist/views/adjustment-template/wastage-template/actions.d.ts +60 -0
  82. package/dist/views/adjustment-template/wastage-template/table.d.ts +60 -0
  83. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +56 -0
  84. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +3 -3
  85. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +468 -0
  86. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +9 -2
  87. package/dist/views/closing-history/ClosingHistoryView.vue.d.ts +2 -0
  88. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +4 -1
  89. package/dist/views/closing-template/helpers/import-export.helper.d.ts +5 -0
  90. package/dist/views/import/ImportView.vue.d.ts +3 -0
  91. package/dist/views/import/components/ImportDialog.vue.d.ts +2 -0
  92. package/dist/views/import/helper/import-export.helper.d.ts +4 -0
  93. package/dist/views/ingredients/components/ingredient-dialog/IngredientDialogProps.d.ts +1 -1
  94. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +181 -12
  95. package/dist/views/ingredients/components/ingredient-form/IngredientFormProps.d.ts +6 -0
  96. package/dist/views/ingredients/helper/import-export.helper.d.ts +4 -1
  97. package/dist/views/integration/components/netsuite/business/BusinessNetSuiteSideSheet.vue.d.ts +2 -0
  98. package/dist/views/receive-request/components/delivery-order-form/CreateForm.vue.d.ts +16 -0
  99. package/dist/views/receive-request/components/delivery-order-form/CreateFormProps.d.ts +4 -0
  100. package/dist/views/receive-request/components/delivery-order-form/EditForm.vue.d.ts +16 -0
  101. package/dist/views/receive-request/components/delivery-order-form/EditFormProps.d.ts +4 -0
  102. package/dist/views/receive-request/components/delivery-order-form/SystemTrailDialog.vue.d.ts +21 -0
  103. package/dist/views/receive-request/components/netsuite/NetSuiteTransactionChangeLog.vue.d.ts +15 -0
  104. package/dist/views/receive-request/components/transfer-details/TransferDetailsProps.d.ts +1 -0
  105. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +420 -2
  106. package/dist/views/receive-request/composables/use-process-purchase-order.d.ts +99 -0
  107. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +644 -13
  108. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +711 -14
  109. package/dist/views/recipe/RecipeView.vue.d.ts +1 -0
  110. package/dist/views/recipe/components/import-recipes/ImportRecipeItem.vue.d.ts +16 -0
  111. package/dist/views/recipe/components/import-recipes/ImportRecipes.vue.d.ts +2 -0
  112. package/dist/views/recipe/helper/import-recipe.d.ts +48 -0
  113. package/dist/views/stock/components/StockRecordCard.vue.d.ts +70 -1
  114. package/dist/views/stock/components/dialog/RecalculationDialog.vue.d.ts +11 -0
  115. package/dist/views/stock/components/dialog/RecalculationDialogProps.d.ts +3 -0
  116. package/dist/views/stock/components/dialog/StockAdjustmentSideSheet.vue.d.ts +20 -0
  117. package/dist/views/supplier/components/SupplierForm.vue.d.ts +8 -0
  118. package/dist/views/supplier/components/SupplierSupplyItemField.vue.d.ts +3 -0
  119. package/dist/views/supplier/composables/use-supplier-table.d.ts +4 -0
  120. package/dist/views/transfer-template/components/transfer-template-dialog/TransferTemplateDialog.vue.d.ts +8 -0
  121. package/dist/views/transfer-template/components/transfer-template-form/components/NetSuiteCustomCodeSelection.vue.d.ts +2 -0
  122. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-locations.d.ts +16 -0
  123. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +48 -0
  124. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +48 -0
  125. package/dist/views/unit/UnitView.vue.d.ts +1 -0
  126. package/dist/views/unit/components/import-units/ImportUnitItem.vue.d.ts +12 -0
  127. package/dist/views/unit/components/import-units/ImportUnitItemProps.d.ts +6 -0
  128. package/dist/views/unit/components/import-units/ImportUnits.vue.d.ts +9 -0
  129. package/dist/views/unit/components/import-units/ImportUnitsProps.d.ts +5 -0
  130. package/dist/views/unit/helper/import-export.helper.d.ts +40 -0
  131. package/dist/views/warehouse/components/WarehouseForm.vue.d.ts +8 -0
  132. package/package.json +3 -3
  133. package/dist/App-Bs0pR0sL.js +0 -276
  134. package/dist/ClosingDraftView-Dyr4hrHk.js +0 -1687
  135. package/dist/ClosingTemplateView-Dw0Lld6E.js +0 -1908
  136. package/dist/FmAdminBadge-BUJh40aj.js +0 -34
  137. package/dist/FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-B-p9ffPK.js +0 -224
  138. package/dist/IngredientsView-61WfWyGy.js +0 -1858
  139. package/dist/RecipeView-CznjQMrS.js +0 -621
  140. package/dist/StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js +0 -59
  141. package/dist/StockView-N-84Q5Ih.js +0 -2086
  142. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-BmU-VLNN.js +0 -2336
  143. package/dist/UnitView-BrLjAWNq.js +0 -667
  144. package/dist/WarehouseView-CI-RuaPq.js +0 -1034
  145. package/dist/array-Ca8T3f_G.js +0 -44
  146. package/dist/helper/core/country/codes.d.ts +0 -255
  147. package/dist/stock-CIpuon0m.js +0 -146
@@ -0,0 +1,2385 @@
1
+ import { defineComponent as ue, ref as O, computed as P, resolveComponent as U, openBlock as A, createBlock as z, withCtx as T, createElementVNode as e, normalizeClass as he, toDisplayString as v, createVNode as y, createElementBlock as L, Fragment as ne, renderList as ie, unref as s, h as ye, watch as xe, isRef as je, createCommentVNode as se, reactive as nt, mergeModels as qe, useModel as pt, onMounted as Le, createTextVNode as de, normalizeStyle as ot, Teleport as ft, normalizeProps as Te, mergeProps as He } from "vue";
2
+ import { u as ke, a2 as fe, f as De, h as ze, i as vt, a as Be, F as Xe, a3 as yt, z as Ne, n as ve, Z as _t, t as Ae, a1 as Ve, A as kt, M as bt, a0 as _e, a4 as gt, a5 as te, a6 as ht, a7 as Je, a8 as st, a9 as Ge, r as xt, x as at, aa as St, ab as wt, ac as Ft, ad as Ee, $ as Z, ae as $t, Y as lt, af as Fe, ag as At, ah as Vt, v as Pe, w as Ct, q as jt, c as Dt, ai as Bt, aj as Mt, ak as It, al as Ut, am as Tt, b as Ht, N as Et, H as Pt, G as Rt, I as Ot, J as Nt, K as Yt, L as Qe } from "./app-a9r50k3U.js";
3
+ import { u as Me } from "./stock-Dw908dIC.js";
4
+ import { g as Se } from "./decimal-AusUnA1W.js";
5
+ import { e as Lt, u as rt, i as it, _ as Ze } from "./PremiumBadge.vue_vue_type_script_setup_true_lang-B0OKeK5O.js";
6
+ import { _ as Ye, S as Re, g as ut, a as zt } from "./SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Bg49isUy.js";
7
+ import { _ as Gt } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-CRZiQHjx.js";
8
+ import { useI18n as ce, useCoreStore as Ke } from "@feedmepos/mf-common";
9
+ import { useSnackbar as be, useDialog as Ie, useProxiedModel as Ue, useBreakpoints as Kt } from "@feedmepos/ui-library";
10
+ import { defineStore as Wt } from "pinia";
11
+ import { u as ge } from "./stock-CDZ2uWSF.js";
12
+ import { u as qt } from "./use-inventory-binding-dialog-ClAkJ864.js";
13
+ import { _ as Xt } from "./NumberPrecisionInput.vue_vue_type_script_setup_true_lang-CdaiYTdf.js";
14
+ import { E as Jt } from "./empty-placeholder-wf6-BWE8.js";
15
+ var $e = /* @__PURE__ */ ((_) => (_.History = "History", _.Convert = "Convert", _.Adjust = "Adjust", _))($e || {});
16
+ const Qt = [
17
+ {
18
+ translationKey: "inventory.stock.action.history",
19
+ color: "text-neutral-700",
20
+ value: "History"
21
+ /* History */
22
+ }
23
+ ], Zt = [
24
+ {
25
+ translationKey: "inventory.stock.action.history",
26
+ color: "text-neutral-700",
27
+ value: "History"
28
+ /* History */
29
+ },
30
+ {
31
+ translationKey: "inventory.stock.action.convert",
32
+ color: "text-neutral-700",
33
+ value: "Convert"
34
+ /* Convert */
35
+ },
36
+ {
37
+ translationKey: "inventory.stock.action.adjust",
38
+ color: "text-neutral-700",
39
+ value: "Adjust"
40
+ /* Adjust */
41
+ }
42
+ ];
43
+ async function en(_) {
44
+ const d = `${(ke().currentLocation.name || "").replace(
45
+ / /g,
46
+ "_"
47
+ )}_${fe().format("DD_MM_YYYY_HHmm")}.xlsx`;
48
+ await Lt(
49
+ [
50
+ {
51
+ name: "stock",
52
+ data: _,
53
+ columns: [
54
+ {
55
+ name: "Code",
56
+ selector: "code"
57
+ },
58
+ {
59
+ name: "Name",
60
+ selector: "name"
61
+ },
62
+ {
63
+ name: "Balance",
64
+ selector: (o) => {
65
+ const $ = Ce(o, o.unit);
66
+ return $.type === "unit" ? Se(o.balance, o.unit, null, !1) : Se(o.balance, o.unit, $.measurement, !1);
67
+ }
68
+ },
69
+ {
70
+ name: "Unit",
71
+ selector: (o) => {
72
+ var S;
73
+ const $ = Ce(o, o.unit);
74
+ return $.type === "unit" ? o.unit.abbrev : ((S = o.unit.measurements.find((m) => m.id === $.measurement)) == null ? void 0 : S.abbrev) || "";
75
+ }
76
+ }
77
+ ]
78
+ }
79
+ ],
80
+ d
81
+ );
82
+ }
83
+ function Ce(_, g) {
84
+ const d = localStorage.getItem(`uom:${_._id}`);
85
+ return d ? d === g._id ? {
86
+ type: "unit"
87
+ } : g.measurements.find((o) => o.id === d) ? {
88
+ type: "measurement",
89
+ measurement: d
90
+ } : {
91
+ type: "unit"
92
+ } : _.trackingMeasurement && g.measurements.find((o) => o.id === _.trackingMeasurement) ? {
93
+ type: "measurement",
94
+ measurement: _.trackingMeasurement
95
+ } : {
96
+ type: "unit"
97
+ };
98
+ }
99
+ const tn = { class: "fm-typo-en-body-md-400 flex-grow" }, ct = /* @__PURE__ */ ue({
100
+ __name: "UnitDisplayControl",
101
+ props: {
102
+ unit: {},
103
+ sku: {},
104
+ amount: {},
105
+ defaultTrackingMeasurement: {}
106
+ },
107
+ setup(_) {
108
+ function g(j) {
109
+ return `uom:${j._id}`;
110
+ }
111
+ function d(j) {
112
+ const F = g(o.sku);
113
+ j ? localStorage.setItem(F, j) : localStorage.setItem(F, o.unit._id), $.value = Ce(o.sku, o.unit);
114
+ }
115
+ const o = _, $ = O(Ce(o.sku, o.unit)), S = P(() => {
116
+ const { measurements: j } = o.unit;
117
+ return [
118
+ {
119
+ label: `${Se(o.amount, o.unit)}`,
120
+ value: null
121
+ },
122
+ ...j.map(({ id: F }) => ({
123
+ label: `${Se(o.amount, o.unit, F)}`,
124
+ value: F
125
+ }))
126
+ ];
127
+ });
128
+ function m({ value: j }) {
129
+ return s($).type === "unit" ? j === null : j === s($).measurement;
130
+ }
131
+ const i = P(
132
+ () => {
133
+ var j;
134
+ return ((j = S.value.find((F) => m(F))) == null ? void 0 : j.label) ?? "";
135
+ }
136
+ ), w = O(!1);
137
+ return (j, F) => {
138
+ const u = U("FmIcon"), k = U("FmMenuItem"), V = U("FmMenu");
139
+ return A(), z(V, {
140
+ "stop-click-propagation": "",
141
+ onMenuChanged: F[0] || (F[0] = (B) => w.value = B)
142
+ }, {
143
+ "menu-button": T(() => [
144
+ e("button", {
145
+ type: "button",
146
+ class: he([
147
+ "w-full text-left flex items-center gap-8 cursor-pointer fm-corner-radius-sm px-8 py-4 border bg-white",
148
+ w.value ? "border-fm-color-primary" : "border-fm-color-neutral-gray-100"
149
+ ])
150
+ }, [
151
+ e("div", tn, v(i.value), 1),
152
+ y(u, {
153
+ class: "text-fm-color-neutral-gray-400",
154
+ name: "expand_more"
155
+ })
156
+ ], 2)
157
+ ]),
158
+ default: T(() => [
159
+ (A(!0), L(ne, null, ie(S.value, (B) => (A(), z(k, {
160
+ key: B.value ?? 0,
161
+ label: B.label,
162
+ "model-value": m(B),
163
+ onClick: (D) => d(B.value)
164
+ }, null, 8, ["label", "model-value", "onClick"]))), 128))
165
+ ]),
166
+ _: 1
167
+ });
168
+ };
169
+ }
170
+ }), nn = { class: "whitespace-nowrap" }, on = /* @__PURE__ */ ue({
171
+ __name: "StockHeaderPreview",
172
+ setup(_) {
173
+ const { t: g } = ce();
174
+ return (d, o) => (A(), z(Gt, null, {
175
+ default: T(() => [
176
+ e("div", nn, v(s(g)("inventory.stock.prediction.daysRemaining")), 1)
177
+ ]),
178
+ _: 1
179
+ }));
180
+ }
181
+ }), dt = Wt("stockActions", () => {
182
+ const _ = O(!1), g = ke(), d = Me(), o = rt(), $ = be(), S = Ie(), { t: m } = ce();
183
+ async function i() {
184
+ if (g._currentLocation) {
185
+ _.value = !0;
186
+ try {
187
+ await d.readStockBalance(), await d.readProductBalance(), await o.readStockEstimateBalance();
188
+ } catch {
189
+ $.open({
190
+ title: m("inventory.stock.error.title"),
191
+ message: m("inventory.stock.error.message"),
192
+ type: "error"
193
+ });
194
+ } finally {
195
+ _.value = !1;
196
+ }
197
+ }
198
+ }
199
+ const w = O();
200
+ async function j(D) {
201
+ var x, b, C;
202
+ if (!!!((b = (x = D.convert) == null ? void 0 : x.inventoryBindings) != null && b.length)) {
203
+ S.open({
204
+ title: m("inventory.stock.error.convert.title"),
205
+ message: m("inventory.stock.error.convert.message")
206
+ });
207
+ return;
208
+ }
209
+ const l = {
210
+ maxCount: ((C = d.productBalance.find(({ id: H }) => H === D._id)) == null ? void 0 : C.count) || 0,
211
+ sku: D,
212
+ show: !0,
213
+ "onUpdate:show"(H) {
214
+ w.value.show = H;
215
+ },
216
+ onSubmitted() {
217
+ i();
218
+ }
219
+ };
220
+ w.value = l;
221
+ }
222
+ const F = O();
223
+ async function u(D) {
224
+ const a = {
225
+ stock: D,
226
+ show: !0,
227
+ "onUpdate:show"(t) {
228
+ F.value.show = t;
229
+ },
230
+ onSubmitted() {
231
+ i();
232
+ }
233
+ };
234
+ F.value = a;
235
+ }
236
+ const k = O();
237
+ async function V(D) {
238
+ const a = {
239
+ sku: D,
240
+ show: !0,
241
+ "onUpdate:show"(t) {
242
+ k.value.show = t;
243
+ }
244
+ };
245
+ k.value = a;
246
+ }
247
+ function B(D, a) {
248
+ const t = De(a);
249
+ switch (D) {
250
+ case $e.History:
251
+ V(t);
252
+ return;
253
+ case $e.Convert:
254
+ j(t);
255
+ return;
256
+ case $e.Adjust:
257
+ u(t);
258
+ return;
259
+ }
260
+ }
261
+ return {
262
+ fetchStockBalance: i,
263
+ onActionMenu: B,
264
+ stockHistoryProps: k,
265
+ showSkuHistory: V,
266
+ convertSkuDialogProps: w,
267
+ adjustSkuDialogProps: F
268
+ };
269
+ });
270
+ function sn() {
271
+ var S;
272
+ const _ = ke(), g = dt(), d = Ke(), { t: o } = ce();
273
+ return {
274
+ columnDefs: [
275
+ {
276
+ accessorKey: "code",
277
+ header: () => o("inventory.stock.code"),
278
+ enableSorting: !0,
279
+ size: 300
280
+ },
281
+ {
282
+ accessorKey: "name",
283
+ header: () => o("inventory.stock.product"),
284
+ enableSorting: !0,
285
+ size: "auto"
286
+ },
287
+ {
288
+ id: "UOM",
289
+ header: () => o("inventory.stock.balance"),
290
+ cell(m) {
291
+ const i = m.row.original, w = {
292
+ unit: i.unit,
293
+ sku: i,
294
+ amount: i.balance,
295
+ defaultTrackingMeasurement: i.trackingMeasurement ?? void 0
296
+ };
297
+ return ye(ct, w);
298
+ },
299
+ size: 180
300
+ },
301
+ ...(S = d.sessionUser.value) != null && S.role.isAdmin ? [
302
+ {
303
+ accessorKey: "isInactive",
304
+ header: () => ye(ze, {}, () => `${o("inventory.ingredient.status.title")}`),
305
+ cell(m) {
306
+ const i = m.row.original.isInactive;
307
+ return ye(
308
+ "span",
309
+ {
310
+ class: [
311
+ "inline-block px-3 py-1 rounded-full text-xs font-semibold",
312
+ i ? "bg-red-100 text-red-700" : "bg-green-100 text-green-700"
313
+ ].join(" ")
314
+ },
315
+ o(i ? "inventory.ingredient.status.inactive" : "inventory.ingredient.status.active")
316
+ );
317
+ },
318
+ enableSorting: !0
319
+ }
320
+ ] : [],
321
+ {
322
+ accessorKey: "day",
323
+ id: "expireDate",
324
+ header: () => ye(on),
325
+ enableSorting: !0,
326
+ sortUndefined: "last",
327
+ cell(m) {
328
+ var k, V;
329
+ const i = m.row.original.day, w = (k = m.row.original.thresholds) == null ? void 0 : k.low, j = (V = m.row.original.thresholds) == null ? void 0 : V.mid;
330
+ if (typeof i != "number" || typeof w != "number" || typeof j != "number")
331
+ return ye(Ye, {
332
+ days: i
333
+ });
334
+ const F = i <= w ? Re.low : i <= j ? Re.mid : Re.high;
335
+ return ye(Ye, {
336
+ days: i,
337
+ level: F
338
+ });
339
+ },
340
+ size: 200
341
+ },
342
+ {
343
+ id: "action",
344
+ cell(m) {
345
+ var i;
346
+ return vt(
347
+ ((i = _._currentLocation) == null ? void 0 : i.type) === "restaurant" ? Qt : Zt,
348
+ (w) => g.onActionMenu(w, m.row.original)
349
+ );
350
+ },
351
+ enableSorting: !1,
352
+ size: 40,
353
+ meta: {
354
+ cellClass: "",
355
+ headerClass: ""
356
+ }
357
+ }
358
+ ]
359
+ };
360
+ }
361
+ const an = {
362
+ context: null,
363
+ error: null,
364
+ isRequired(_ = "This field is required") {
365
+ return `${this.context ?? ""}`.length === 0 && (this.error = _), this;
366
+ },
367
+ isString(_ = "Must be a valid string") {
368
+ return this.error ? this : (typeof this.context != "string" && (this.error ?? (this.error = _)), this);
369
+ },
370
+ toInt() {
371
+ return this.error ? this : (this.context = +this.context, this);
372
+ },
373
+ isInteger(_ = "Must be an integer") {
374
+ return this.error ? this : (this.toInt(), isNaN(this.context) && (this.error = _), this);
375
+ },
376
+ min(_, g) {
377
+ if (this.error) return this;
378
+ try {
379
+ typeof this.context == "number" ? +this.context < _ && (this.error = g ?? `Must be at least ${_}`) : Object.prototype.hasOwnProperty.call(this.context, "length") ? +this.context.length < _ && (this.error = g ?? `Must be at least ${_}`) : this.error = "Length cannot be determined";
380
+ } catch {
381
+ this.error = "Length cannot be determined";
382
+ }
383
+ return this;
384
+ },
385
+ max(_, g) {
386
+ if (this.error) return this;
387
+ try {
388
+ typeof this.context == "number" ? +this.context > _ && (this.error = g ?? `Must be at most ${_}`) : "length" in this.context ? +this.context.length > _ && (this.error = g ?? `Must be at most ${_}`) : this.error = "Length cannot be determined";
389
+ } catch {
390
+ this.error = "Length cannot be determined";
391
+ }
392
+ return this;
393
+ }
394
+ };
395
+ function et(_) {
396
+ return { ...an, context: _ };
397
+ }
398
+ const ln = { class: "flex items-center" }, rn = { class: "fm-typo-en-title-md-800" }, un = { class: "flex flex-col gap-24 w-full" }, cn = { class: "flex flex-col gap-8" }, dn = { class: "fm-typo-en-body-lg-600" }, mn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary flex-grow" }, pn = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-error" }, fn = { class: "flex flex-col p-16 gap-8" }, vn = { class: "flex flex-col gap-4" }, yn = { class: "fm-typo-en-body-md-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 border-b py-12 px-16" }, _n = { class: "grid grid-cols-[auto_100px_100px_48px] xs:grid-cols-[auto_80px_120px_48px] gap-8 px-8 items-center" }, kn = { class: "xs:col-span-3" }, bn = { class: "flex gap-8" }, gn = /* @__PURE__ */ ue({
399
+ __name: "ConvertSkuDialog",
400
+ props: {
401
+ sku: {},
402
+ maxCount: {},
403
+ show: { type: Boolean }
404
+ },
405
+ emits: ["update:show", "submitted"],
406
+ setup(_, { expose: g, emit: d }) {
407
+ const o = _, $ = d, S = qt(), m = Be(), i = ge(), w = be(), { t: j } = ce(), F = O(0), u = O(null), k = P(() => m.skus), V = P(
408
+ () => {
409
+ var p, n;
410
+ return (((n = (p = o.sku) == null ? void 0 : p.convert) == null ? void 0 : n.inventoryBindings) ?? []).filter(
411
+ (r) => r.type === Xe.enum.SKU
412
+ );
413
+ }
414
+ ), B = P({
415
+ get() {
416
+ return !!u.value;
417
+ },
418
+ set(p) {
419
+ p ? u.value = De(V.value) : (u.value = null, F.value = Math.min(F.value, o.maxCount ?? 0));
420
+ }
421
+ }), D = O(!1);
422
+ xe([() => o.show], ([p]) => {
423
+ p && (F.value = 0);
424
+ });
425
+ function a() {
426
+ N(o.sku, Ae(F.value), u.value);
427
+ }
428
+ function t(p) {
429
+ if (u.value)
430
+ return !0;
431
+ const n = et(p).isInteger().max(o.maxCount ?? 0).error ?? "";
432
+ return n || !0;
433
+ }
434
+ function l(p) {
435
+ var f;
436
+ const n = (f = o.sku.convert) != null && f.measurement ? o.sku.unit.measurements.find((M) => {
437
+ var I;
438
+ return M.id === ((I = o.sku.convert) == null ? void 0 : I.measurement);
439
+ }) ?? null : null, r = Ne(o.sku.unit, n), h = gt(+p);
440
+ return et(h).isInteger().max(r).error ? "Precision cannot be more than " + r : !0;
441
+ }
442
+ const x = P(
443
+ () => {
444
+ var p, n;
445
+ return (p = o.sku.convert) != null && p.measurement ? (n = o.sku.unit.measurements.find((r) => {
446
+ var h;
447
+ return r.id === ((h = o.sku.convert) == null ? void 0 : h.measurement);
448
+ })) == null ? void 0 : n.abbrev : o.sku.unit.abbrev;
449
+ }
450
+ ), b = P(() => {
451
+ var h, c;
452
+ const n = yt({
453
+ bindings: ((h = o.sku.convert) == null ? void 0 : h.inventoryBindings) ?? [],
454
+ skus: m.skus,
455
+ skuGroups: m.skuGroups,
456
+ recipes: m.recipes
457
+ }).inventoryBindings.filter((f) => "success" in f && f.success).map((f) => f).map((f) => f.binding);
458
+ return (c = u.value ?? n) == null ? void 0 : c.map((f) => {
459
+ var le, re, ee, ae, pe;
460
+ const M = m.skus.find((me) => me._id === f.id), I = ((le = f.measurement) == null ? void 0 : le.abbrev) ?? ((re = M == null ? void 0 : M.unit) == null ? void 0 : re.abbrev), G = (ee = o.sku.convert) != null && ee.measurement ? o.sku.unit.measurements.find((me) => {
461
+ var We;
462
+ return me.id === ((We = o.sku.convert) == null ? void 0 : We.measurement);
463
+ }) ?? null : null, oe = Ne(o.sku.unit, G), E = l(`${F.value}`) === !0 ? ve(
464
+ _t(
465
+ f.amount,
466
+ Ae(+F.value, oe)
467
+ ),
468
+ !1
469
+ ) : "0", W = (pe = (ae = u.value) == null ? void 0 : ae.find((me) => me.id === (M == null ? void 0 : M._id))) == null ? void 0 : pe.amount, q = W ? ve(W, !1) : null;
470
+ return {
471
+ sku: M,
472
+ convertAmount: q ?? E,
473
+ abbrev: I
474
+ };
475
+ });
476
+ }), C = O();
477
+ g({
478
+ validateInputs: () => {
479
+ var p, n;
480
+ (n = (p = C.value) == null ? void 0 : p.validateInputs) == null || n.call(p);
481
+ },
482
+ resetInputsValidation: () => {
483
+ var p, n;
484
+ (n = (p = C.value) == null ? void 0 : p.resetInputsValidation) == null || n.call(p);
485
+ },
486
+ resetInputs: () => {
487
+ var p, n;
488
+ (n = (p = C.value) == null ? void 0 : p.resetInputs) == null || n.call(p);
489
+ }
490
+ });
491
+ const H = Ue(o, "show");
492
+ async function N(p, n, r) {
493
+ D.value = !0;
494
+ try {
495
+ await i.convertSku({
496
+ conversions: [
497
+ {
498
+ doc: p,
499
+ amount: n,
500
+ overrides: r == null ? void 0 : r.map((h) => ({
501
+ ...h,
502
+ amount: {
503
+ ...h.amount,
504
+ amount: -1 * Math.abs(h.amount.amount)
505
+ // ensure truly negative
506
+ }
507
+ }))
508
+ }
509
+ ]
510
+ }), $("update:show", !1), $("submitted");
511
+ } catch (h) {
512
+ w.open({
513
+ title: "Something went wrong",
514
+ message: `Cannot convert ${p.name}. Please try again.`,
515
+ type: "error"
516
+ }), console.error("error at converting stock amount", p, n, h);
517
+ } finally {
518
+ D.value = !1;
519
+ }
520
+ }
521
+ function K(p, n, r) {
522
+ const h = +n;
523
+ let c = r;
524
+ n.length > 0 && isFinite(h) ? c = r.map((f) => (f.id !== p || (f.amount = _e(h)), f)) : c = r.map((f) => (f.id !== p || (f.amount = { amount: 0, precision: 0 }), f)), u.value = c;
525
+ }
526
+ function R(p) {
527
+ const n = k.value.find((r) => r._id === p);
528
+ return n ? ut(n.unit, !0) : [];
529
+ }
530
+ function X(p, n) {
531
+ const r = R(p), h = r.find((c) => c.value === n) ?? r.find((c) => c.value === null);
532
+ return h ? {
533
+ ...h,
534
+ label: h.abbrev
535
+ } : null;
536
+ }
537
+ function Y(p, n, r) {
538
+ let h;
539
+ if (n === null)
540
+ h = r.map((c) => (c.id !== p || (c.measurement = null), c)) ?? [];
541
+ else {
542
+ const c = k.value.find((f) => f._id === p);
543
+ h = r.map((f) => {
544
+ var M, I;
545
+ return f.id !== p || (f.measurement = (I = (M = c == null ? void 0 : c.unit) == null ? void 0 : M.measurements) == null ? void 0 : I.find((G) => G.id === n)), f;
546
+ }) ?? [];
547
+ }
548
+ u.value = h;
549
+ }
550
+ function J(p, n) {
551
+ const r = n.filter((h) => h.id !== p);
552
+ u.value = r;
553
+ }
554
+ function Q() {
555
+ const p = (u.value ?? []).map((n) => ({
556
+ ...n,
557
+ type: Xe.enum.SKU
558
+ }));
559
+ S.promptIngredientsBinding(
560
+ p,
561
+ (n) => u.value = n,
562
+ o.sku._id
563
+ );
564
+ }
565
+ return xe(
566
+ () => o.show,
567
+ (p) => {
568
+ p || (u.value = null, F.value = 0);
569
+ }
570
+ ), (p, n) => {
571
+ const r = U("FmTextField"), h = U("FmForm"), c = U("FmCard"), f = U("FmSwitch"), M = U("FmFormGroup"), I = U("FmSelect"), G = U("FmButton"), oe = U("FmSideSheet");
572
+ return A(), z(oe, {
573
+ "dismiss-away": "",
574
+ modelValue: s(H),
575
+ "onUpdate:modelValue": n[3] || (n[3] = (E) => je(H) ? H.value = E : null),
576
+ "max-width": 500
577
+ }, {
578
+ "side-sheet-header": T(() => [
579
+ e("div", ln, [
580
+ e("div", rn, v(s(j)("inventory.stock.convert.title", { name: p.sku.name })), 1)
581
+ ])
582
+ ]),
583
+ default: T(() => [
584
+ e("div", un, [
585
+ y(h, {
586
+ ref_key: "formRef",
587
+ ref: C,
588
+ onValidationSuccess: a
589
+ }, {
590
+ default: T(() => [
591
+ y(r, {
592
+ disabled: D.value,
593
+ "model-value": F.value,
594
+ "onUpdate:modelValue": n[0] || (n[0] = (E) => F.value = E),
595
+ label: s(j)("inventory.stock.convert.amount"),
596
+ rules: [t, l, s(Ve)(0)],
597
+ "append-text": x.value,
598
+ "helper-text": u.value ? void 0 : `Max ${p.maxCount} ${x.value}`
599
+ }, null, 8, ["disabled", "model-value", "label", "rules", "append-text", "helper-text"])
600
+ ]),
601
+ _: 1
602
+ }, 512),
603
+ y(c, {
604
+ variant: "outlined",
605
+ class: "p-16"
606
+ }, {
607
+ default: T(() => [
608
+ e("div", cn, [
609
+ e("div", dn, v(s(j)("inventory.stock.convert.deductionSummary")), 1),
610
+ (A(!0), L(ne, null, ie(b.value, (E) => {
611
+ var W, q;
612
+ return A(), L("div", {
613
+ key: (W = E.sku) == null ? void 0 : W._id,
614
+ class: "flex items-center"
615
+ }, [
616
+ e("div", mn, v((q = E.sku) == null ? void 0 : q.name), 1),
617
+ e("div", pn, " -" + v(E.convertAmount) + " " + v(E.abbrev), 1)
618
+ ]);
619
+ }), 128))
620
+ ])
621
+ ]),
622
+ _: 1
623
+ }),
624
+ y(c, { variant: "outlined" }, {
625
+ default: T(() => [
626
+ e("div", fn, [
627
+ y(f, {
628
+ value: "",
629
+ modelValue: B.value,
630
+ "onUpdate:modelValue": n[1] || (n[1] = (E) => B.value = E),
631
+ label: s(j)("inventory.stock.convert.overrideDeduction"),
632
+ "label-placement": "right"
633
+ }, null, 8, ["modelValue", "label"]),
634
+ B.value ? (A(), L(ne, { key: 0 }, [
635
+ y(M, {
636
+ modelValue: u.value,
637
+ rules: [s(kt)(1, "Must have at least one ingredient binding")]
638
+ }, null, 8, ["modelValue", "rules"]),
639
+ e("div", vn, [
640
+ e("div", yn, v(s(j)("inventory.stock.convert.ingredients")), 1),
641
+ (A(!0), L(ne, null, ie(u.value, (E) => (A(), z(M, {
642
+ key: E.id,
643
+ disabled: D.value,
644
+ modelValue: +s(ve)(E.amount ?? { amount: 1, precision: 0 }),
645
+ rules: [
646
+ s(bt)(
647
+ k.value.find((W) => W._id === E.id).unit,
648
+ E.measurement
649
+ ),
650
+ s(Ve)(0)
651
+ ]
652
+ }, {
653
+ default: T(({ invalid: W }) => {
654
+ var q, le, re;
655
+ return [
656
+ e("div", _n, [
657
+ e("div", kn, v((q = k.value.find((ee) => ee._id === E.id)) == null ? void 0 : q.name), 1),
658
+ y(r, {
659
+ class: "xs:col-span-2",
660
+ disabled: D.value,
661
+ modelValue: +s(ve)(
662
+ E.amount ?? { amount: 1, precision: 0 }
663
+ ),
664
+ "onUpdate:modelValue": (ee) => K(E.id, ee, u.value ?? []),
665
+ invalid: W
666
+ }, null, 8, ["disabled", "modelValue", "onUpdate:modelValue", "invalid"]),
667
+ y(I, {
668
+ disabled: D.value,
669
+ class: "translate-y-[2px]",
670
+ items: R(E.id),
671
+ "model-value": (re = X(E.id, (le = E.measurement) == null ? void 0 : le.id)) == null ? void 0 : re.value,
672
+ "onUpdate:modelValue": (ee) => Y(E.id, ee, u.value ?? []),
673
+ invalid: W
674
+ }, {
675
+ "helper-text": T(() => n[4] || (n[4] = [])),
676
+ _: 2
677
+ }, 1032, ["disabled", "items", "model-value", "onUpdate:modelValue", "invalid"]),
678
+ y(G, {
679
+ disabled: D.value,
680
+ type: "button",
681
+ variant: "tertiary",
682
+ icon: "delete",
683
+ onClick: (ee) => J(E.id, u.value ?? [])
684
+ }, null, 8, ["disabled", "onClick"])
685
+ ])
686
+ ];
687
+ }),
688
+ _: 2
689
+ }, 1032, ["disabled", "modelValue", "rules"]))), 128))
690
+ ]),
691
+ e("div", null, [
692
+ y(G, {
693
+ icon: "link",
694
+ label: s(j)("inventory.stock.convert.linkIngredient"),
695
+ variant: "plain",
696
+ onClick: Q
697
+ }, null, 8, ["label"])
698
+ ])
699
+ ], 64)) : se("", !0)
700
+ ])
701
+ ]),
702
+ _: 1
703
+ })
704
+ ])
705
+ ]),
706
+ "side-sheet-footer": T(() => [
707
+ e("div", bn, [
708
+ y(G, {
709
+ loading: D.value,
710
+ label: s(j)("inventory.stock.convert.convertButton"),
711
+ onClick: n[2] || (n[2] = (E) => {
712
+ var W, q;
713
+ return (q = (W = C.value) == null ? void 0 : W.validateInputs) == null ? void 0 : q.call(W);
714
+ })
715
+ }, null, 8, ["loading", "label"])
716
+ ])
717
+ ]),
718
+ _: 1
719
+ }, 8, ["modelValue"]);
720
+ };
721
+ }
722
+ });
723
+ function we(_, g) {
724
+ const d = Ae(_, g);
725
+ return { ...d, amount: -d.amount };
726
+ }
727
+ function tt(_, g) {
728
+ return Ae(Math.abs(_), g);
729
+ }
730
+ const Oe = {
731
+ [te.enum.DAMAGE]: {
732
+ label: "Damage",
733
+ toAdjustmentAmount: we
734
+ },
735
+ [te.enum.WASTAGE]: {
736
+ label: "Wastage",
737
+ toAdjustmentAmount: we
738
+ },
739
+ [te.enum.THEFT]: {
740
+ label: "Theft",
741
+ toAdjustmentAmount: we
742
+ },
743
+ [te.enum.LOSE]: {
744
+ label: "Lose",
745
+ toAdjustmentAmount: we
746
+ },
747
+ [te.enum.EXTRA]: {
748
+ label: "Extra",
749
+ toAdjustmentAmount: tt
750
+ },
751
+ [te.enum.PURCHASE]: {
752
+ label: "Purchase",
753
+ toAdjustmentAmount: tt
754
+ }
755
+ }, hn = { class: "col-span-2 flex" }, xn = { class: "fm-typo-en-body-lg-600 flex-1" }, Sn = { class: "col-span-2 flex flex-col gap-4" }, wn = { class: "flex gap-4 text-fm-color-typo-primary fm-typo-en-body-lg-600" }, mt = /* @__PURE__ */ ue({
756
+ __name: "AdjustedItemForm",
757
+ props: {
758
+ modelValue: {},
759
+ disabled: { type: Boolean }
760
+ },
761
+ emits: ["update:modelValue", "click:delete"],
762
+ setup(_, { emit: g }) {
763
+ const d = _, o = g, { t: $ } = ce(), S = Me(), m = P(
764
+ () => Object.keys(Oe).map((t) => ({
765
+ label: ht(t),
766
+ value: t
767
+ }))
768
+ ), i = P(() => ut(d.modelValue.doc.unit, !0)), w = P({
769
+ get() {
770
+ return d.modelValue.type ?? te.enum.PURCHASE;
771
+ },
772
+ set(t) {
773
+ const l = {
774
+ ...d.modelValue
775
+ };
776
+ l.type = t;
777
+ const x = Je(d.modelValue.amount);
778
+ l.amount = Oe[l.type].toAdjustmentAmount(
779
+ +ve(x),
780
+ x.precision
781
+ ), o("update:modelValue", l);
782
+ }
783
+ }), j = P({
784
+ get() {
785
+ const t = Je(d.modelValue.amount);
786
+ return +ve(t);
787
+ },
788
+ set(t) {
789
+ const l = {
790
+ ...d.modelValue
791
+ }, x = _e(t);
792
+ l.amount = Oe[w.value].toAdjustmentAmount(
793
+ t,
794
+ x.precision
795
+ ), o("update:modelValue", l);
796
+ }
797
+ }), F = P({
798
+ get() {
799
+ var t;
800
+ return ((t = d.modelValue.measurement) == null ? void 0 : t.id) ?? null;
801
+ },
802
+ set(t) {
803
+ var x, b;
804
+ const l = {
805
+ ...d.modelValue
806
+ };
807
+ l.measurement = ((b = (x = d.modelValue.doc.unit) == null ? void 0 : x.measurements) == null ? void 0 : b.find((C) => C.id === t)) ?? null, o("update:modelValue", l);
808
+ }
809
+ }), u = P({
810
+ get() {
811
+ return d.modelValue.remark ?? "";
812
+ },
813
+ set(t) {
814
+ const l = {
815
+ ...d.modelValue
816
+ };
817
+ l.remark = t, o("update:modelValue", l);
818
+ }
819
+ }), k = P(() => {
820
+ var l;
821
+ const t = (l = S.stockBalance.skus) == null ? void 0 : l.find((x) => x.id === d.modelValue.doc._id);
822
+ return (t == null ? void 0 : t.balance) ?? { amount: 0, precision: 0 };
823
+ }), V = P(() => {
824
+ const t = d.modelValue.amount, l = d.modelValue.measurement;
825
+ return l ? st(t, l.conversion) : t;
826
+ }), B = P(
827
+ () => Ge(k.value, V.value)
828
+ ), D = P(
829
+ () => Se(B.value, d.modelValue.doc.unit)
830
+ ), a = P(() => V.value.amount < 0);
831
+ return (t, l) => {
832
+ const x = U("FmButton"), b = U("FmSelect"), C = U("FmTextarea"), H = U("FmCard");
833
+ return A(), z(H, {
834
+ variant: "outlined",
835
+ class: "grid grid-cols-2 gap-8 p-16"
836
+ }, {
837
+ default: T(() => [
838
+ e("div", hn, [
839
+ e("div", xn, v(t.modelValue.doc.name), 1),
840
+ y(x, {
841
+ variant: "tertiary",
842
+ "prepend-icon": "delete",
843
+ onClick: l[0] || (l[0] = (N) => o("click:delete"))
844
+ })
845
+ ]),
846
+ y(b, {
847
+ disabled: t.disabled,
848
+ class: "col-span-2",
849
+ label: "Type",
850
+ items: m.value,
851
+ modelValue: w.value,
852
+ "onUpdate:modelValue": l[1] || (l[1] = (N) => w.value = N),
853
+ rules: [s(xt)()],
854
+ "label-mark": "required"
855
+ }, null, 8, ["disabled", "items", "modelValue", "rules"]),
856
+ y(Xt, {
857
+ disabled: t.disabled,
858
+ label: "Amount",
859
+ step: +s(ve)({
860
+ amount: 1,
861
+ precision: s(Ne)(t.modelValue.doc.unit, t.modelValue.measurement)
862
+ }),
863
+ modelValue: j.value,
864
+ "onUpdate:modelValue": l[2] || (l[2] = (N) => j.value = N),
865
+ rules: [s(Ve)(0)]
866
+ }, null, 8, ["disabled", "step", "modelValue", "rules"]),
867
+ y(b, {
868
+ disabled: t.disabled,
869
+ label: "Unit",
870
+ items: i.value,
871
+ modelValue: F.value,
872
+ "onUpdate:modelValue": l[3] || (l[3] = (N) => F.value = N)
873
+ }, null, 8, ["disabled", "items", "modelValue"]),
874
+ y(C, {
875
+ class: "col-span-2",
876
+ disabled: t.disabled,
877
+ label: "Remark",
878
+ modelValue: u.value,
879
+ "onUpdate:modelValue": l[4] || (l[4] = (N) => u.value = N),
880
+ "label-mark": "optional"
881
+ }, null, 8, ["disabled", "modelValue"]),
882
+ e("div", Sn, [
883
+ e("div", wn, v(s($)("inventory.stock.stock_adjustment.stockAfter")), 1),
884
+ e("div", {
885
+ class: he(["fm-typo-en-body-lg-600", a.value ? "text-red-700" : "text-green-700"])
886
+ }, v(D.value), 3)
887
+ ])
888
+ ]),
889
+ _: 1
890
+ });
891
+ };
892
+ }
893
+ }), Fn = { class: "flex items-center" }, $n = { class: "fm-typo-en-title-md-800" }, An = { class: "flex items-center" }, Vn = { class: "fm-typo-en-title-sm-800 flex-1" }, Cn = { class: "flex gap-8" }, jn = /* @__PURE__ */ ue({
894
+ __name: "AdjustSkuDialog",
895
+ props: {
896
+ stock: {},
897
+ show: { type: Boolean }
898
+ },
899
+ emits: ["update:show", "submitted"],
900
+ setup(_, { expose: g, emit: d }) {
901
+ const o = _, $ = d, S = Be(), m = Ie(), i = ge(), w = be(), j = O(!1), { t: F } = ce();
902
+ function u() {
903
+ D(De(B));
904
+ }
905
+ const k = O();
906
+ g({
907
+ validateInputs: () => {
908
+ var l, x;
909
+ (x = (l = k.value) == null ? void 0 : l.validateInputs) == null || x.call(l);
910
+ },
911
+ resetInputsValidation: () => {
912
+ var l, x;
913
+ (x = (l = k.value) == null ? void 0 : l.resetInputsValidation) == null || x.call(l);
914
+ },
915
+ resetInputs: () => {
916
+ var l, x;
917
+ (x = (l = k.value) == null ? void 0 : l.resetInputs) == null || x.call(l);
918
+ }
919
+ });
920
+ const V = Ue(o, "show"), B = nt({
921
+ remark: "",
922
+ adjustments: [
923
+ {
924
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
925
+ type: te.enum.PURCHASE,
926
+ doc: o.stock,
927
+ measurement: null,
928
+ remark: "",
929
+ amount: _e(1)
930
+ }
931
+ ]
932
+ });
933
+ xe([() => o.show], ([l]) => {
934
+ l && (B.remark = "", B.adjustments = [
935
+ {
936
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
937
+ type: te.enum.PURCHASE,
938
+ doc: o.stock,
939
+ measurement: null,
940
+ remark: "",
941
+ amount: _e(1)
942
+ }
943
+ ]);
944
+ });
945
+ async function D(l) {
946
+ j.value = !0;
947
+ try {
948
+ await i.adjustSku({
949
+ remark: l.remark,
950
+ adjustments: l.adjustments.map(({ doc: x, remark: b, type: C, amount: H, measurement: N }) => ({
951
+ id: x._id,
952
+ amount: H,
953
+ measurement: N,
954
+ remark: b,
955
+ doc: x,
956
+ type: C
957
+ }))
958
+ }), $("update:show", !1), $("submitted");
959
+ } catch (x) {
960
+ w.open({
961
+ title: F("inventory.stock.adjust.error.title"),
962
+ message: F("inventory.stock.adjust.error.message"),
963
+ type: "error"
964
+ }), console.log("error on adjust ingredients", l, x);
965
+ } finally {
966
+ j.value = !1;
967
+ }
968
+ }
969
+ function a() {
970
+ const l = S.skus.map((b) => ({
971
+ label: b.name,
972
+ sublabel: b.code,
973
+ value: b._id
974
+ })), x = l.filter((b) => B.adjustments.find((C) => C.doc._id === b.value)).map((b) => b.value);
975
+ m.open({
976
+ title: "Select ingredients",
977
+ contentComponent: at,
978
+ contentComponentProps: {
979
+ items: l,
980
+ modelValue: x
981
+ },
982
+ overlay: !0,
983
+ closeButton: !0,
984
+ dismissAway: !0,
985
+ primaryActions: {
986
+ text: "Confirm",
987
+ close: !0
988
+ },
989
+ secondaryActions: {
990
+ text: "Close",
991
+ close: !0,
992
+ variant: "tertiary"
993
+ }
994
+ }).onPrimary((b) => {
995
+ B.adjustments = b.map(
996
+ (C) => B.adjustments.find((H) => H.doc._id === C) ?? {
997
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
998
+ type: te.enum.PURCHASE,
999
+ doc: S.skus.find((H) => H._id === C),
1000
+ measurement: null,
1001
+ remark: "",
1002
+ amount: _e(1)
1003
+ }
1004
+ );
1005
+ });
1006
+ }
1007
+ function t(l) {
1008
+ B.adjustments.splice(l, 1);
1009
+ }
1010
+ return (l, x) => {
1011
+ const b = U("FmTextarea"), C = U("FmButton"), H = U("FmForm"), N = U("FmSideSheet");
1012
+ return A(), z(N, {
1013
+ modelValue: s(V),
1014
+ "onUpdate:modelValue": x[2] || (x[2] = (K) => je(V) ? V.value = K : null),
1015
+ "dismiss-away": "",
1016
+ "max-width": 500
1017
+ }, {
1018
+ "side-sheet-header": T(() => [
1019
+ e("div", Fn, [
1020
+ e("div", $n, v(s(F)("inventory.stock.adjust.title")), 1)
1021
+ ])
1022
+ ]),
1023
+ default: T(() => [
1024
+ y(H, {
1025
+ class: "w-full flex flex-col gap-12",
1026
+ ref_key: "formRef",
1027
+ ref: k,
1028
+ onValidationSuccess: u
1029
+ }, {
1030
+ default: T(() => [
1031
+ y(b, {
1032
+ label: s(F)("inventory.stock.adjust.remark"),
1033
+ modelValue: B.remark,
1034
+ "onUpdate:modelValue": x[0] || (x[0] = (K) => B.remark = K)
1035
+ }, null, 8, ["label", "modelValue"]),
1036
+ e("div", An, [
1037
+ e("div", Vn, v(s(F)("inventory.stock.adjust.adjustedItems")), 1),
1038
+ y(C, {
1039
+ "prepend-icon": "add",
1040
+ variant: "tertiary",
1041
+ size: "md",
1042
+ onClick: a
1043
+ })
1044
+ ]),
1045
+ (A(!0), L(ne, null, ie(B.adjustments, (K, R) => (A(), z(mt, {
1046
+ key: K.id,
1047
+ modelValue: B.adjustments[R],
1048
+ "onUpdate:modelValue": (X) => B.adjustments[R] = X,
1049
+ "onClick:delete": (X) => t(R)
1050
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onClick:delete"]))), 128))
1051
+ ]),
1052
+ _: 1
1053
+ }, 512)
1054
+ ]),
1055
+ "side-sheet-footer": T(() => [
1056
+ e("div", Cn, [
1057
+ y(C, {
1058
+ label: s(F)("inventory.stock.adjust.adjustButton"),
1059
+ loading: j.value,
1060
+ onClick: x[1] || (x[1] = (K) => {
1061
+ var R, X;
1062
+ return (X = (R = k.value) == null ? void 0 : R.validateInputs) == null ? void 0 : X.call(R);
1063
+ })
1064
+ }, null, 8, ["label", "loading"])
1065
+ ])
1066
+ ]),
1067
+ _: 1
1068
+ }, 8, ["modelValue"]);
1069
+ };
1070
+ }
1071
+ }), Dn = { class: "flex items-center w-full gap-8" }, Bn = { class: "fm-typo-en-title-md-800 flex-1" }, Mn = { class: "flex flex-col gap-16" }, In = { class: "flex flex-col gap-4" }, Un = { class: "fm-typo-en-body-md-600" }, Tn = { class: "flex gap-8 items-start" }, Hn = { class: "flex-1 min-w-0" }, En = { class: "flex-1 min-w-0" }, Pn = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Rn = { class: "flex items-center" }, On = { class: "fm-typo-en-title-sm-800 flex-1" }, Nn = { class: "flex gap-8" }, Yn = /* @__PURE__ */ ue({
1072
+ __name: "StockAdjustmentSideSheet",
1073
+ props: {
1074
+ show: { type: Boolean }
1075
+ },
1076
+ emits: ["update:show", "submitted"],
1077
+ setup(_, { emit: g }) {
1078
+ const d = _, o = g, { t: $ } = ce(), S = Be(), m = ge(), i = Ie(), w = be(), j = Ue(d, "show"), F = O(!1), u = nt({
1079
+ remark: "",
1080
+ effectiveAt: /* @__PURE__ */ new Date(),
1081
+ adjustments: []
1082
+ }), k = O(fe().format("YYYY-MM-DD")), V = O(fe().format("HH:mm"));
1083
+ xe([k, V], () => {
1084
+ if (k.value && V.value) {
1085
+ const b = fe(`${k.value} ${V.value}`, "YYYY-MM-DD HH:mm");
1086
+ b.isValid() && (u.effectiveAt = b.toDate());
1087
+ }
1088
+ });
1089
+ function B() {
1090
+ u.remark = "", u.effectiveAt = /* @__PURE__ */ new Date(), u.adjustments = [], k.value = fe(u.effectiveAt).format("YYYY-MM-DD"), V.value = fe(u.effectiveAt).format("HH:mm");
1091
+ }
1092
+ function D() {
1093
+ B();
1094
+ }
1095
+ const a = P(() => {
1096
+ const b = {};
1097
+ return S.skus.forEach((C) => {
1098
+ b[C._id] = C;
1099
+ }), b;
1100
+ });
1101
+ function t() {
1102
+ const b = S.skus.map((H) => ({
1103
+ label: H.name,
1104
+ sublabel: H.code,
1105
+ value: H._id
1106
+ })), C = u.adjustments.map((H) => H.doc._id);
1107
+ i.open({
1108
+ title: $("inventory.stock.adjust.selectIngredients"),
1109
+ contentComponent: at,
1110
+ contentComponentProps: {
1111
+ items: b,
1112
+ modelValue: C,
1113
+ virtualScroll: !0
1114
+ },
1115
+ overlay: !0,
1116
+ closeButton: !0,
1117
+ dismissAway: !0,
1118
+ primaryActions: {
1119
+ text: $("common.confirm"),
1120
+ close: !0
1121
+ },
1122
+ secondaryActions: {
1123
+ text: $("common.close"),
1124
+ close: !0,
1125
+ variant: "tertiary"
1126
+ }
1127
+ }).onPrimary((H) => {
1128
+ u.adjustments = H.map(
1129
+ (N) => u.adjustments.find((K) => K.doc._id === N) ?? {
1130
+ id: "",
1131
+ type: te.enum.PURCHASE,
1132
+ doc: a.value[N],
1133
+ measurement: null,
1134
+ remark: "",
1135
+ amount: _e(1)
1136
+ }
1137
+ );
1138
+ });
1139
+ }
1140
+ function l(b) {
1141
+ u.adjustments.splice(b, 1);
1142
+ }
1143
+ async function x() {
1144
+ if (u.adjustments.length === 0) {
1145
+ w.open({
1146
+ title: $("inventory.stock.error.title"),
1147
+ message: $("inventory.stock.stock_adjustment.noAdjustments"),
1148
+ type: "warning"
1149
+ });
1150
+ return;
1151
+ }
1152
+ F.value = !0;
1153
+ try {
1154
+ const b = Date.now(), C = u.effectiveAt.getTime() <= b, H = u.adjustments.map(
1155
+ ({ doc: K, remark: R, type: X, amount: Y, measurement: J }) => ({
1156
+ id: K._id,
1157
+ amount: Y,
1158
+ measurement: J,
1159
+ remark: R,
1160
+ doc: K,
1161
+ type: X
1162
+ })
1163
+ ), N = {
1164
+ remark: u.remark,
1165
+ adjustments: H
1166
+ };
1167
+ C || (N.effectiveAt = u.effectiveAt.toISOString()), await m.adjustSku(De(N)), o("submitted"), o("update:show", !1);
1168
+ } catch (b) {
1169
+ w.open({
1170
+ title: $("inventory.stock.adjust.error.title"),
1171
+ message: $("inventory.stock.adjust.error.message"),
1172
+ type: "error"
1173
+ }), console.error("error on stock adjustment", b);
1174
+ } finally {
1175
+ F.value = !1;
1176
+ }
1177
+ }
1178
+ return (b, C) => {
1179
+ const H = U("FmTextarea"), N = U("FmDatePicker"), K = U("FmTimePicker"), R = U("FmButton"), X = U("FmSideSheet");
1180
+ return A(), z(X, {
1181
+ modelValue: s(j),
1182
+ "onUpdate:modelValue": C[4] || (C[4] = (Y) => je(j) ? j.value = Y : null),
1183
+ "dismiss-away": "",
1184
+ "max-width": 560,
1185
+ onAfterEnter: D
1186
+ }, {
1187
+ "side-sheet-header": T(() => [
1188
+ e("div", Dn, [
1189
+ e("div", Bn, v(s($)("inventory.stock.stock_adjustment.title")), 1)
1190
+ ])
1191
+ ]),
1192
+ default: T(() => [
1193
+ e("div", Mn, [
1194
+ y(H, {
1195
+ label: s($)("inventory.stock.adjust.remark"),
1196
+ modelValue: u.remark,
1197
+ "onUpdate:modelValue": C[0] || (C[0] = (Y) => u.remark = Y),
1198
+ "label-mark": "optional"
1199
+ }, null, 8, ["label", "modelValue"]),
1200
+ e("div", In, [
1201
+ e("label", Un, v(s($)("inventory.stock.stock_adjustment.effectiveAt")), 1),
1202
+ e("div", Tn, [
1203
+ e("div", Hn, [
1204
+ y(N, {
1205
+ class: "w-full",
1206
+ modelValue: k.value,
1207
+ "onUpdate:modelValue": C[1] || (C[1] = (Y) => k.value = Y),
1208
+ clearable: !1,
1209
+ max: s(fe)().format("YYYY-MM-DD")
1210
+ }, null, 8, ["modelValue", "max"])
1211
+ ]),
1212
+ e("div", En, [
1213
+ y(K, {
1214
+ class: "w-full",
1215
+ modelValue: V.value,
1216
+ "onUpdate:modelValue": C[2] || (C[2] = (Y) => V.value = Y),
1217
+ format: "HH:mm"
1218
+ }, null, 8, ["modelValue"])
1219
+ ])
1220
+ ]),
1221
+ e("div", Pn, v(s($)("inventory.stock.stock_adjustment.immediateHint")), 1)
1222
+ ]),
1223
+ e("div", Rn, [
1224
+ e("div", On, v(s($)("inventory.stock.adjust.adjustedItems")), 1),
1225
+ y(R, {
1226
+ "prepend-icon": "add",
1227
+ variant: "tertiary",
1228
+ size: "md",
1229
+ onClick: t
1230
+ })
1231
+ ]),
1232
+ (A(!0), L(ne, null, ie(u.adjustments, (Y, J) => (A(), z(mt, {
1233
+ key: Y.id,
1234
+ modelValue: u.adjustments[J],
1235
+ "onUpdate:modelValue": (Q) => u.adjustments[J] = Q,
1236
+ "onClick:delete": (Q) => l(J)
1237
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onClick:delete"]))), 128))
1238
+ ])
1239
+ ]),
1240
+ "side-sheet-footer": T(() => [
1241
+ e("div", Nn, [
1242
+ y(R, {
1243
+ label: s($)("common.confirm"),
1244
+ loading: F.value,
1245
+ onClick: x
1246
+ }, null, 8, ["label", "loading"]),
1247
+ y(R, {
1248
+ label: s($)("common.close"),
1249
+ variant: "tertiary",
1250
+ onClick: C[3] || (C[3] = (Y) => o("update:show", !1))
1251
+ }, null, 8, ["label"])
1252
+ ])
1253
+ ]),
1254
+ _: 1
1255
+ }, 8, ["modelValue"]);
1256
+ };
1257
+ }
1258
+ }), Ln = St((_, g) => ({
1259
+ // TODO: remove once latest inventory backend has been push
1260
+ async findBillsByBusinessId(d, o, $) {
1261
+ const S = `${_.businessesBackendUrl}/${d}/reports/find-many`, m = {
1262
+ // type: TYPE.bill,
1263
+ type: "bill",
1264
+ restaurantIds: o,
1265
+ ids: $
1266
+ };
1267
+ return await g.post(S, m);
1268
+ },
1269
+ async findBillsById(d) {
1270
+ const $ = ke().currentLocationDBName, S = `${_.inventoryBackendUrl}/${$}/bill/search`, m = {
1271
+ ids: d
1272
+ };
1273
+ return await g.post(S, m);
1274
+ }
1275
+ })), zn = {
1276
+ key: 0,
1277
+ class: "flex justify-center items-center h-32"
1278
+ }, Gn = { class: "mb-3" }, Kn = { class: "flex flex-col gap-8" }, Wn = { class: "flex flex-col text-fm-color-typo-primary mb-3 text-center" }, qn = { class: "text-fm-color-neutral-gray-400 fm-typo-en-body-sm-600" }, Xn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, Jn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, Qn = { class: "flex flex-col gap-4 text-fm-color-typo-primary mb-3" }, Zn = { class: "flex flex-col w-full px-2" }, eo = { class: "flex gap-2" }, to = /* @__PURE__ */ ue({
1279
+ __name: "AmendAdjustmentForm",
1280
+ props: /* @__PURE__ */ qe({
1281
+ adjustmentId: {}
1282
+ }, {
1283
+ modelValue: {},
1284
+ modelModifiers: {}
1285
+ }),
1286
+ emits: /* @__PURE__ */ qe(["refreshHistory"], ["update:modelValue"]),
1287
+ setup(_, { emit: g }) {
1288
+ const d = _, o = g, $ = ge(), S = pt(_, "modelValue"), m = O(!1), i = O(!1), w = O(!1), j = O({
1289
+ _id: `inventoryAdjustment_${(/* @__PURE__ */ new Date()).toISOString()}_XXXXX`,
1290
+ skus: []
1291
+ }), F = O();
1292
+ Le(async () => {
1293
+ m.value = !0;
1294
+ const a = await $.readSingleAdjustment(d.adjustmentId);
1295
+ if (!a) throw new Error("Adjustment not found");
1296
+ j.value = a, m.value = !1;
1297
+ });
1298
+ async function u() {
1299
+ var t, l;
1300
+ if ((l = (t = F == null ? void 0 : F.value) == null ? void 0 : t.validateInputs) == null || l.call(t), !i.value) return;
1301
+ const a = {};
1302
+ Object.keys(S.value || {}).forEach((x) => {
1303
+ var b;
1304
+ Object.keys(((b = S.value) == null ? void 0 : b[x]) || {}).forEach((C) => {
1305
+ var N, K;
1306
+ const H = (K = (N = S.value) == null ? void 0 : N[x]) == null ? void 0 : K[Number(C)];
1307
+ H && V(H.amount) > 0 && (a[x] || (a[x] = []), a[x].push(H));
1308
+ });
1309
+ }), await $.revertWastageAdjustment({
1310
+ targetWastageAdjustmentId: d.adjustmentId,
1311
+ amountsGoingToAdjust: a
1312
+ }), o("refreshHistory"), w.value = !1, S.value = {};
1313
+ }
1314
+ function k(a, t, l) {
1315
+ return P({
1316
+ get: () => {
1317
+ var b, C, H;
1318
+ const x = (H = (C = (b = S.value) == null ? void 0 : b[a]) == null ? void 0 : C[t]) == null ? void 0 : H.amount;
1319
+ return x ? V(x, !0) : 0;
1320
+ },
1321
+ set: (x) => {
1322
+ S.value || (S.value = {});
1323
+ const b = { ...S.value };
1324
+ b[a] || (b[a] = {}), b[a][t] = {
1325
+ amount: Ee.fromNumber(x),
1326
+ type: te.Enum.WASTAGE,
1327
+ measurement: l
1328
+ }, S.value = b;
1329
+ }
1330
+ });
1331
+ }
1332
+ function V(a, t = !0) {
1333
+ const l = Number(Ee.toFormatString({ value: a }));
1334
+ return t ? Math.abs(l) : l;
1335
+ }
1336
+ function B(a, t) {
1337
+ return t.measurement ? t.measurement.abbrev : a.sku.unit.abbrev;
1338
+ }
1339
+ function D(a, t) {
1340
+ return t === 0 ? "N/A" : (a + t).toString();
1341
+ }
1342
+ return (a, t) => {
1343
+ const l = U("FmIcon"), x = U("FmStepperField"), b = U("FmCard"), C = U("FmForm"), H = U("FmSpacer"), N = U("FmButton"), K = U("FmDialog");
1344
+ return A(), z(K, {
1345
+ modelValue: w.value,
1346
+ "onUpdate:modelValue": t[4] || (t[4] = (R) => w.value = R),
1347
+ overlay: !0
1348
+ }, {
1349
+ "dialog-button": T(() => [
1350
+ y(ze, null, {
1351
+ default: T(() => [
1352
+ e("button", {
1353
+ onClick: t[0] || (t[0] = (R) => w.value = !0),
1354
+ class: "rounded-md hover:bg-gray-100 transition-colors"
1355
+ }, [
1356
+ y(l, {
1357
+ name: "edit",
1358
+ size: "sm"
1359
+ })
1360
+ ])
1361
+ ]),
1362
+ _: 1
1363
+ })
1364
+ ]),
1365
+ "dialog-header": T(() => t[5] || (t[5] = [
1366
+ e("div", null, "Amend Adjustment", -1)
1367
+ ])),
1368
+ "dialog-footer": T(() => [
1369
+ e("div", Zn, [
1370
+ t[13] || (t[13] = e("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)),
1371
+ e("div", eo, [
1372
+ y(H),
1373
+ y(N, {
1374
+ class: "sm:w-full xs:w-full",
1375
+ label: "Close",
1376
+ size: "md",
1377
+ variant: "tertiary",
1378
+ onClick: t[3] || (t[3] = (R) => w.value = !1)
1379
+ }),
1380
+ y(N, {
1381
+ class: "sm:w-full xs:w-full",
1382
+ label: "Submit",
1383
+ size: "md",
1384
+ variant: "primary",
1385
+ onClick: u
1386
+ })
1387
+ ])
1388
+ ])
1389
+ ]),
1390
+ default: T(() => [
1391
+ m.value ? (A(), L("div", zn)) : (A(), z(C, {
1392
+ key: 1,
1393
+ ref_key: "formRef",
1394
+ ref: F,
1395
+ onValidationFailed: t[1] || (t[1] = () => {
1396
+ i.value = !1;
1397
+ }),
1398
+ onValidationSuccess: t[2] || (t[2] = () => {
1399
+ i.value = !0;
1400
+ }),
1401
+ blameFormChildOnValidationFailed: ""
1402
+ }, {
1403
+ default: T(() => [
1404
+ e("p", Gn, [
1405
+ t[6] || (t[6] = e("b", null, "Date:", -1)),
1406
+ t[7] || (t[7] = e("br", null, null, -1)),
1407
+ de(" " + v(s(wt)(s(Ft)(j.value._id))), 1)
1408
+ ]),
1409
+ e("div", Kn, [
1410
+ (A(!0), L(ne, null, ie(j.value.skus, (R, X) => (A(), L(ne, { key: X }, [
1411
+ (A(!0), L(ne, null, ie(R.amounts, (Y, J) => (A(), z(b, {
1412
+ key: J,
1413
+ variant: "outlined",
1414
+ class: "p-2"
1415
+ }, {
1416
+ default: T(() => [
1417
+ e("div", Wn, [
1418
+ e("span", qn, v(R.sku.code), 1),
1419
+ e("span", null, v(R.sku.name), 1)
1420
+ ]),
1421
+ t[12] || (t[12] = e("hr", { class: "m-2" }, null, -1)),
1422
+ e("div", Xn, [
1423
+ t[8] || (t[8] = e("span", { class: "fm-typo-en-body-lg-600" }, "Adjustment type:", -1)),
1424
+ e("span", null, v(Y.type), 1)
1425
+ ]),
1426
+ e("div", Jn, [
1427
+ t[9] || (t[9] = e("span", { class: "fm-typo-en-body-lg-600" }, "Current amount:", -1)),
1428
+ e("span", null, v(s(Ee).toFormatString({ value: Y.amount })) + " " + v(B(R, Y)), 1)
1429
+ ]),
1430
+ y(x, {
1431
+ "model-value": k(R.sku._id, J).value,
1432
+ "onUpdate:modelValue": (Q) => k(R.sku._id, J).value = Q,
1433
+ class: "mb-3",
1434
+ label: "Adjust Amount (Leave 0 to skip)",
1435
+ "helper-text": `Max: ${V(Y.amount)}`,
1436
+ "append-text": B(R, Y),
1437
+ rules: [
1438
+ (Q) => Q <= V(Y.amount) || `Cannot be more than ${V(Y.amount)}`,
1439
+ s(Ve)(-1)
1440
+ ]
1441
+ }, null, 8, ["model-value", "onUpdate:modelValue", "helper-text", "append-text", "rules"]),
1442
+ e("div", Qn, [
1443
+ t[10] || (t[10] = e("span", { class: "fm-typo-en-body-lg-600" }, "Amount after amend:", -1)),
1444
+ t[11] || (t[11] = e("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)),
1445
+ de(" " + v(D(
1446
+ V(Y.amount, !1),
1447
+ k(R.sku._id, J).value
1448
+ )) + " " + v(B(R, Y)), 1)
1449
+ ])
1450
+ ]),
1451
+ _: 2
1452
+ }, 1024))), 128))
1453
+ ], 64))), 128))
1454
+ ])
1455
+ ]),
1456
+ _: 1
1457
+ }, 512))
1458
+ ]),
1459
+ _: 1
1460
+ }, 8, ["modelValue"]);
1461
+ };
1462
+ }
1463
+ }), no = { class: "p-16" }, oo = { class: "fm-typo-en-body-md-600 flex-grow" }, so = { class: "flex-grow text-fm-color-typo-secondary" }, ao = {
1464
+ key: 0,
1465
+ class: "my-5"
1466
+ }, lo = { class: "text-neutral-400" }, ro = { class: "flex-grow" }, io = { class: "flex gap-1" }, uo = { class: "flex flex-col gap-1" }, co = {
1467
+ key: 1,
1468
+ class: "t-system text-fsecondary"
1469
+ }, mo = {
1470
+ key: 2,
1471
+ 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"
1472
+ }, po = {
1473
+ key: 1,
1474
+ class: "shrink-0 text-fm-color-typo-secondary"
1475
+ }, fo = /* @__PURE__ */ ue({
1476
+ __name: "StockRecordCard",
1477
+ props: {
1478
+ record: {},
1479
+ sku: {},
1480
+ bills: { default: () => [] }
1481
+ },
1482
+ emits: ["refreshHistory"],
1483
+ setup(_, { emit: g }) {
1484
+ const d = _, o = O(!1);
1485
+ Ke();
1486
+ const $ = O(), S = O(null), m = P(() => S.value === null ? "unset" : o.value ? `${S.value}px` : "0px");
1487
+ Le(() => {
1488
+ var F;
1489
+ S.value = ((F = $.value) == null ? void 0 : F.scrollHeight) || 0;
1490
+ });
1491
+ const i = P(() => {
1492
+ var D;
1493
+ const F = d.record.adjustments, u = d.sku, k = {}, B = F.flatMap((a) => {
1494
+ var t;
1495
+ return ((t = a.skus) == null ? void 0 : t.filter((l) => l.sku._id === u._id)) ?? [];
1496
+ }).flatMap((a) => a.amounts);
1497
+ for (const a of B) {
1498
+ const t = a.measurement ? st(a.measurement.conversion, a.amount) : a.amount;
1499
+ k[D = a.type] ?? (k[D] = { amount: 0, precision: 0 }), k[a.type] = Ge(t, k[a.type]);
1500
+ }
1501
+ return Object.entries(k).reduce(
1502
+ (a, [t, l]) => (a[t] = /// comment, because without it formatter makes code uglier
1503
+ `${Z.toFormatString({
1504
+ value: l,
1505
+ precision: 4
1506
+ })} ${u.unit.abbrev}`, a),
1507
+ {}
1508
+ );
1509
+ }), { t: w } = ce(), j = P(() => d.record.adjustmentsByTime.map(({ date: F, adjustments: u }) => ({
1510
+ time: $t(new Date(F)),
1511
+ adjustments: u.flatMap(
1512
+ (k) => {
1513
+ var V, B;
1514
+ return ((B = (V = k.skus) == null ? void 0 : V.map) == null ? void 0 : B.call(V, (D) => {
1515
+ var a, t;
1516
+ return {
1517
+ ...D,
1518
+ ref: k.ref,
1519
+ backdateFrom: k.effectiveAt != null ? it(k._id) : null,
1520
+ toBalance: (t = (a = k.skus) == null ? void 0 : a[0]) == null ? void 0 : t.toBalance,
1521
+ adjustmentId: k._id
1522
+ };
1523
+ })) ?? [];
1524
+ }
1525
+ ).flatMap((k) => {
1526
+ var D;
1527
+ const V = (D = d.bills.find((a) => a._id === k.ref)) == null ? void 0 : D.seqNumber, B = V ? w("inventory.stock.record.bill", [V]) : "";
1528
+ return k.amounts.map((a) => {
1529
+ var t;
1530
+ return {
1531
+ amount: `${Z.toFormatString({ value: a.amount, precision: 4 })} ${((t = a.measurement) == null ? void 0 : t.abbrev) ?? k.sku.unit.abbrev}`,
1532
+ backdateFrom: k.backdateFrom,
1533
+ name: a.type,
1534
+ remark: a.remark || B || "",
1535
+ cost: a.cost,
1536
+ toBalance: Z.toFormatString({
1537
+ value: k.toBalance ?? Z.fromNumber(0),
1538
+ precision: 4
1539
+ }),
1540
+ baseUnit: k.sku.unit.abbrev,
1541
+ adjustmentId: k.adjustmentId
1542
+ };
1543
+ });
1544
+ })
1545
+ })));
1546
+ return (F, u) => {
1547
+ const k = U("FmIcon"), V = U("FmTooltip"), B = U("FmCard");
1548
+ return A(), z(B, { variant: "outlined" }, {
1549
+ default: T(() => [
1550
+ e("div", no, [
1551
+ e("div", {
1552
+ class: "flex items-center cursor-pointer mb-1",
1553
+ onClick: u[0] || (u[0] = (D) => o.value = !o.value)
1554
+ }, [
1555
+ e("div", oo, v(F.record.date), 1),
1556
+ y(k, {
1557
+ name: o.value ? "expand_more" : "expand_less",
1558
+ color: "#777777",
1559
+ size: "md"
1560
+ }, null, 8, ["name"])
1561
+ ]),
1562
+ (A(!0), L(ne, null, ie(i.value, (D, a) => (A(), L("div", {
1563
+ key: a,
1564
+ class: "flex flex-row py-1",
1565
+ style: { "font-size": "0.8rem" }
1566
+ }, [
1567
+ e("div", so, v(s(w)(`inventory.inventoryAdjustment.type.${a}`)), 1),
1568
+ e("div", {
1569
+ class: he({
1570
+ "text-fm-color-typo-error": D.startsWith("-"),
1571
+ "text-fm-color-typo-success": !D.startsWith("-"),
1572
+ "ml-auto": !0
1573
+ })
1574
+ }, v(D), 3)
1575
+ ]))), 128)),
1576
+ e("div", {
1577
+ ref_key: "detailRef",
1578
+ ref: $,
1579
+ style: ot({
1580
+ fontSize: "0.8rem",
1581
+ maxHeight: m.value,
1582
+ overflow: "hidden",
1583
+ transition: "max-height 0.2s ease-out"
1584
+ })
1585
+ }, [
1586
+ j.value.length ? (A(), L("hr", ao)) : se("", !0),
1587
+ (A(!0), L(ne, null, ie(j.value, (D) => (A(), L("div", {
1588
+ key: D.time,
1589
+ class: "flex gap-1 w-full"
1590
+ }, [
1591
+ e("div", lo, v(D.time), 1),
1592
+ e("div", ro, [
1593
+ (A(!0), L(ne, null, ie(D.adjustments, (a) => (A(), L("div", {
1594
+ key: a.name,
1595
+ class: "flex gap-1"
1596
+ }, [
1597
+ e("div", io, [
1598
+ de(v(s(w)(`inventory.inventoryAdjustment.type.${a.name}`)) + " ", 1),
1599
+ a.backdateFrom ? (A(), z(V, {
1600
+ key: 0,
1601
+ variant: "plain",
1602
+ placement: "top",
1603
+ "z-index": 50
1604
+ }, {
1605
+ content: T(() => [
1606
+ e("div", uo, v(s(w)("inventory.stock.record.backdate", [
1607
+ s(lt)(new Date(a.backdateFrom))
1608
+ ])), 1)
1609
+ ]),
1610
+ default: T(() => [
1611
+ y(k, {
1612
+ name: "info",
1613
+ size: "sm",
1614
+ color: "primary"
1615
+ })
1616
+ ]),
1617
+ _: 2
1618
+ }, 1024)) : se("", !0),
1619
+ a.remark ? (A(), L("span", co, " # " + v(a.remark), 1)) : se("", !0),
1620
+ a.name === s(te).Enum.CLOSING ? (A(), L("span", mo, " Actual Balance: " + v(a.toBalance) + " " + v(a.baseUnit), 1)) : se("", !0)
1621
+ ]),
1622
+ e("div", {
1623
+ class: he({
1624
+ "text-fm-color-typo-error": a.amount.startsWith("-"),
1625
+ "text-fm-color-typo-success": !a.amount.startsWith("-"),
1626
+ "ml-auto": !0
1627
+ })
1628
+ }, v(a.amount), 3),
1629
+ a.name === s(te).Enum.WASTAGE ? (A(), z(to, {
1630
+ key: 0,
1631
+ adjustmentId: a.adjustmentId,
1632
+ onRefreshHistory: u[1] || (u[1] = (t) => F.$emit("refreshHistory"))
1633
+ }, null, 8, ["adjustmentId"])) : se("", !0),
1634
+ a.cost ? (A(), L("div", po, " (" + v(s(Fe)(a.cost, !1, a.cost.precision)) + ") ", 1)) : se("", !0)
1635
+ ]))), 128))
1636
+ ])
1637
+ ]))), 128))
1638
+ ], 4)
1639
+ ])
1640
+ ]),
1641
+ _: 1
1642
+ });
1643
+ };
1644
+ }
1645
+ });
1646
+ function vo(_, g) {
1647
+ var S;
1648
+ const d = Object.keys(te.enum).reduce(
1649
+ (m, i) => (m[i] = { amount: 0, precision: 0 }, m),
1650
+ {}
1651
+ );
1652
+ if (!g)
1653
+ return Object.entries(d).reduce(
1654
+ (m, [i]) => (m[i] = Z.fromNumber(0), m),
1655
+ {}
1656
+ );
1657
+ const $ = _.flatMap((m) => {
1658
+ var i;
1659
+ return ((i = m.skus) == null ? void 0 : i.filter((w) => w.sku._id === g._id)) ?? [];
1660
+ }).flatMap((m) => m.amounts);
1661
+ for (const m of $) {
1662
+ const i = m.measurement ? Z.multiply([m.measurement.conversion, m.amount]) : m.amount;
1663
+ d[S = m.type] ?? (d[S] = { amount: 0, precision: 0 }), d[m.type] = Z.add([i, d[m.type]]);
1664
+ }
1665
+ return Object.entries(d).reduce(
1666
+ (m, [i, w]) => {
1667
+ const j = {
1668
+ ...w,
1669
+ amount: Math.abs(w.amount)
1670
+ };
1671
+ return m[i] = /// comment, because without it formatter makes code uglier
1672
+ `${Z.toFormatString({
1673
+ value: j,
1674
+ precision: 4
1675
+ })} ${g.unit.abbrev}`, m;
1676
+ },
1677
+ {}
1678
+ );
1679
+ }
1680
+ function yo(_, g) {
1681
+ if (!g)
1682
+ return null;
1683
+ let d = null;
1684
+ const $ = _.flatMap((S) => {
1685
+ var m;
1686
+ return ((m = S.skus) == null ? void 0 : m.filter((i) => i.sku._id === g._id)) ?? [];
1687
+ }).flatMap((S) => {
1688
+ var m;
1689
+ return !S.history || ((m = S.history) == null ? void 0 : m.length) === 0 ? [] : S.history[0];
1690
+ });
1691
+ for (const S of $) {
1692
+ const m = S.amounts;
1693
+ for (const i of m) {
1694
+ if (i.type !== te.Enum.SALES)
1695
+ continue;
1696
+ const w = i.measurement ? Z.multiply([i.measurement.conversion, i.amount]) : i.amount;
1697
+ d ?? (d = Z.fromNumber(0)), d = Z.add([d, w]);
1698
+ }
1699
+ }
1700
+ return d != null ? (d.amount = Math.abs(d.amount), `${Z.toFormatString({
1701
+ value: d,
1702
+ precision: 4
1703
+ })} ${g.unit.abbrev}`) : null;
1704
+ }
1705
+ const _o = { class: "flex items-center w-full fm-typo-en-title-md-800" }, ko = { class: "flex-1 line-clamp-2" }, bo = { class: "flex flex-col gap-32 w-full h-full" }, go = { class: "flex items-center relative gap-4" }, ho = { class: "flex-1" }, xo = {
1706
+ key: 0,
1707
+ class: "flex-1 flex flex-col items-center gap-16"
1708
+ }, So = { class: "fm-typo-en-body-lg-400 translate-x-4" }, wo = {
1709
+ key: 1,
1710
+ class: "flex flex-col gap-12"
1711
+ }, Fo = { class: "pb-16" }, $o = { class: "fm-typo-cn-body-lg-600" }, Ao = {
1712
+ class: "grid gap-12 fm-typo-en-body-md-400",
1713
+ style: { "grid-template-columns": "auto auto auto", "grid-auto-rows": "1fr" }
1714
+ }, Vo = { class: "flex flex-col gap-1" }, Co = { class: "text-fm-color-typo-secondary" }, jo = { class: "font-bold" }, Do = { class: "flex flex-col gap-1" }, Bo = { class: "text-fm-color-typo-secondary flex" }, Mo = { class: "font-bold" }, Io = { class: "flex flex-col gap-1" }, Uo = { class: "text-fm-color-typo-secondary" }, To = { class: "font-bold" }, Ho = { class: "flex flex-col gap-1" }, Eo = { class: "text-fm-color-typo-secondary" }, Po = { class: "font-bold" }, Ro = { class: "flex flex-col gap-1" }, Oo = { class: "text-fm-color-typo-secondary" }, No = { class: "font-bold" }, Yo = { class: "flex flex-col gap-1" }, Lo = { class: "text-fm-color-typo-secondary" }, zo = { class: "font-bold" }, Go = { class: "flex flex-col gap-1" }, Ko = { class: "text-fm-color-typo-secondary" }, Wo = { class: "font-bold" }, qo = { class: "flex flex-col gap-1" }, Xo = { class: "text-fm-color-typo-secondary" }, Jo = { class: "font-bold" }, Qo = { class: "flex flex-col gap-1" }, Zo = { class: "text-fm-color-typo-secondary" }, es = { class: "font-bold" }, ts = {
1715
+ key: 0,
1716
+ class: "flex flex-col gap-8"
1717
+ }, ns = { class: "flex" }, os = { class: "flex-1 flex flex-col gap-1" }, ss = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, as = { class: "font-bold" }, ls = { class: "flex-1 flex flex-col gap-1" }, rs = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, is = { class: "flex flex-col gap-1" }, us = { class: "font-bold" }, cs = {
1718
+ key: 2,
1719
+ class: "flex-1 flex flex-col items-center gap-8"
1720
+ }, ds = ["src"], ms = { class: "font-bold text-lg" }, ps = { class: "text-xs text-neutral-400 text-center" }, fs = /* @__PURE__ */ ue({
1721
+ __name: "StockHistory",
1722
+ props: {
1723
+ sku: {},
1724
+ show: { type: Boolean }
1725
+ },
1726
+ emits: ["update:show"],
1727
+ setup(_) {
1728
+ const g = Ke(), d = Me(), o = ge(), $ = Ln(), S = ke(), m = Dt(), { t: i } = ce(), w = _, j = O(!1), F = be(), u = O(At(0));
1729
+ async function k() {
1730
+ j.value = !0;
1731
+ try {
1732
+ await l(), await d.readStockBalance();
1733
+ } catch (n) {
1734
+ F.open({
1735
+ title: "Something went wrong",
1736
+ message: "Cannot fetch stock history. Please try again.",
1737
+ type: "error"
1738
+ }), console.log("failed at fetching item adjustment history", w.sku, u, n);
1739
+ } finally {
1740
+ j.value = !1;
1741
+ }
1742
+ }
1743
+ Le(() => {
1744
+ k();
1745
+ }), xe([() => u.value, () => w.sku], () => {
1746
+ k();
1747
+ });
1748
+ const V = O([]), B = O([]), D = O(new Array());
1749
+ function a(n, r) {
1750
+ return r === "day" ? Tt(n) : lt(n);
1751
+ }
1752
+ function t(n, r) {
1753
+ const h = n.reduce(
1754
+ (c, f) => {
1755
+ const M = f.effectiveAt ?? it(f._id);
1756
+ if (!M)
1757
+ return c;
1758
+ const I = a(new Date(M), r);
1759
+ return c[I] ?? (c[I] = []), c[I].push(f), c;
1760
+ },
1761
+ {}
1762
+ );
1763
+ return Object.keys(h).map((c) => ({
1764
+ date: c,
1765
+ adjustments: h[c]
1766
+ }));
1767
+ }
1768
+ async function l() {
1769
+ let n = await o.readStockAdjustment(
1770
+ w.sku._id,
1771
+ Bt(new Date(u.value.startDate)).toISOString(),
1772
+ Mt(new Date(u.value.endDate)).toISOString()
1773
+ );
1774
+ V.value = n;
1775
+ const r = n.filter(({ ref: h }) => h == null ? void 0 : h.startsWith("bill_")).map(({ ref: h }) => h);
1776
+ await x(r), B.value = t(n, "day").map(({ date: h, adjustments: c }) => ({
1777
+ date: h,
1778
+ adjustments: c,
1779
+ adjustmentsByTime: t(c, "minute")
1780
+ }));
1781
+ }
1782
+ async function x(n) {
1783
+ n.length && (D.value = await $.findBillsById(n).catch((r) => {
1784
+ var f;
1785
+ console.error("Error on using latest bill API, retrying using legacy api", r);
1786
+ const h = ((f = g.currentBusiness.value) == null ? void 0 : f._id) ?? "", c = S.currentLocation.doc._id;
1787
+ return $.findBillsByBusinessId(h, [c], n);
1788
+ }));
1789
+ }
1790
+ const b = P(() => {
1791
+ const n = V.value, r = w.sku;
1792
+ return vo(n, r);
1793
+ }), C = P(() => {
1794
+ const n = V.value, r = w.sku;
1795
+ return yo(n, r);
1796
+ }), H = P(() => {
1797
+ const n = [...V.value].computeFirst((h) => {
1798
+ var f, M;
1799
+ const c = (M = (f = h.skus) == null ? void 0 : f.find) == null ? void 0 : M.call(f, (I) => I.sku._id === w.sku._id);
1800
+ return c == null ? void 0 : c.fromBalance;
1801
+ }) ?? {
1802
+ amount: 0,
1803
+ precision: 0
1804
+ }, r = w.sku;
1805
+ return r ? `${Z.toFormatString({
1806
+ value: n,
1807
+ precision: 4
1808
+ })} ${r.unit.abbrev}` : "";
1809
+ }), N = P(() => {
1810
+ const n = [...V.value].reverse().computeFirst((h) => {
1811
+ var f, M;
1812
+ const c = (M = (f = h.skus) == null ? void 0 : f.find) == null ? void 0 : M.call(f, (I) => I.sku._id === w.sku._id);
1813
+ return c == null ? void 0 : c.toBalance;
1814
+ }) ?? {
1815
+ amount: 0,
1816
+ precision: 0
1817
+ }, r = w.sku;
1818
+ return r ? `${Z.toFormatString({ value: n, precision: 4 })} ${r.unit.abbrev}` : "";
1819
+ }), K = P(() => {
1820
+ var h;
1821
+ const r = V.value.flatMap((c) => {
1822
+ var f;
1823
+ return ((f = c.skus) == null ? void 0 : f.flatMap((M) => M.amounts)) ?? [];
1824
+ }).filter((c) => c.amount.amount < 0).reduce(
1825
+ (c, f) => {
1826
+ const M = f.cost;
1827
+ if (!M) return c;
1828
+ const I = {
1829
+ ...Vt(c, Math.max(c.precision, M.precision)),
1830
+ currency: M.currency
1831
+ };
1832
+ return {
1833
+ ...Ge(I, M),
1834
+ currency: c.currency
1835
+ };
1836
+ },
1837
+ {
1838
+ amount: 0,
1839
+ precision: 0,
1840
+ currency: Pe((h = g.currentCountry) == null ? void 0 : h.value)
1841
+ }
1842
+ );
1843
+ return Fe(r, !1, r.precision);
1844
+ });
1845
+ function R() {
1846
+ const { startDate: n, endDate: r } = It(u.value);
1847
+ n !== null && r !== null && (u.value = {
1848
+ startDate: n,
1849
+ endDate: r
1850
+ });
1851
+ }
1852
+ const X = P(() => i("inventory.ingredient.valuationMethod.WAVG")), Y = P(() => {
1853
+ var I, G, oe, E;
1854
+ const n = [...V.value].reverse().computeFirst((W) => {
1855
+ var q, le;
1856
+ return (le = (q = W.skus) == null ? void 0 : q.find) == null ? void 0 : le.call(q, (re) => re.sku._id === w.sku._id);
1857
+ });
1858
+ if (!n) return "No data";
1859
+ const r = [...n.amounts].reverse()[0], h = {
1860
+ amount: ((I = r.cost) == null ? void 0 : I.amount) ?? 0,
1861
+ precision: ((G = r.cost) == null ? void 0 : G.precision) ?? 0
1862
+ }, c = r.amount, f = c.amount == 0 ? Z.fromNumber(0) : Z.divide([h, c]);
1863
+ return {
1864
+ ...Z.multiply([f, c]),
1865
+ currency: ((oe = r.cost) == null ? void 0 : oe.currency) || Pe(((E = g.currentCountry) == null ? void 0 : E.value) ?? Ct)
1866
+ };
1867
+ }), J = P(() => {
1868
+ var h;
1869
+ const n = [...V.value].reverse().computeFirst((c) => {
1870
+ var M, I;
1871
+ const f = (I = (M = c.skus) == null ? void 0 : M.find) == null ? void 0 : I.call(M, (G) => G.sku._id === w.sku._id);
1872
+ return f == null ? void 0 : f.toCostBalances;
1873
+ });
1874
+ return n ? {
1875
+ ...n.reduce((c, f) => Z.add([c, Z.fromDinero(f.cost)]), {
1876
+ amount: 0,
1877
+ precision: 0
1878
+ }),
1879
+ currency: Pe((h = g.currentCountry) == null ? void 0 : h.value)
1880
+ } : "No data";
1881
+ });
1882
+ function Q() {
1883
+ const { startDate: n, endDate: r } = Ut(u.value);
1884
+ n !== null && r !== null && (u.value = {
1885
+ startDate: n,
1886
+ endDate: r
1887
+ });
1888
+ }
1889
+ const p = Ue(w, "show");
1890
+ return (n, r) => {
1891
+ const h = U("FmButton"), c = U("FmField"), f = U("FmDateRangePicker"), M = U("FmSpacer"), I = U("FmCircularProgress"), G = U("FmIcon"), oe = U("FmTooltip"), E = U("FmMenuDivider"), W = U("FmChip"), q = U("FmCardSection"), le = U("FmCard"), re = U("FmSideSheet");
1892
+ return A(), z(re, {
1893
+ "dismiss-away": "",
1894
+ modelValue: s(p),
1895
+ "onUpdate:modelValue": r[4] || (r[4] = (ee) => je(p) ? p.value = ee : null),
1896
+ "close-button": !1,
1897
+ "max-width": 560
1898
+ }, {
1899
+ "side-sheet-header": T(() => [
1900
+ e("div", _o, [
1901
+ e("div", ko, v(s(i)("inventory.stock.history.title", [n.sku.name])), 1),
1902
+ y(h, {
1903
+ variant: "tertiary",
1904
+ "prepend-icon": "close",
1905
+ onClick: r[0] || (r[0] = (ee) => p.value = !1)
1906
+ })
1907
+ ])
1908
+ ]),
1909
+ default: T(() => {
1910
+ var ee;
1911
+ return [
1912
+ e("div", bo, [
1913
+ e("div", go, [
1914
+ e("div", ho, [
1915
+ y(f, {
1916
+ modelValue: u.value,
1917
+ "onUpdate:modelValue": r[1] || (r[1] = (ae) => u.value = ae),
1918
+ "show-predefined-range": "",
1919
+ "start-label": "",
1920
+ "end-label": "",
1921
+ "z-index": 50
1922
+ }, {
1923
+ "trigger-button": T(({ opened: ae }) => [
1924
+ y(c, {
1925
+ "prepend-icon": "calendar_month",
1926
+ focused: ae
1927
+ }, {
1928
+ default: T(() => [
1929
+ de(v(u.value.startDate) + " - " + v(u.value.endDate), 1)
1930
+ ]),
1931
+ _: 2
1932
+ }, 1032, ["focused"])
1933
+ ]),
1934
+ _: 1
1935
+ }, 8, ["modelValue"])
1936
+ ]),
1937
+ y(h, {
1938
+ variant: "tertiary",
1939
+ onClick: r[2] || (r[2] = (ae) => R()),
1940
+ "prepend-icon": "navigate_before"
1941
+ }),
1942
+ y(h, {
1943
+ variant: "tertiary",
1944
+ onClick: r[3] || (r[3] = (ae) => Q()),
1945
+ "prepend-icon": "navigate_next"
1946
+ })
1947
+ ]),
1948
+ j.value ? (A(), L("div", xo, [
1949
+ y(M),
1950
+ y(I, { size: "xl" }),
1951
+ e("div", So, v(s(i)("inventory.stock.history.loading")), 1),
1952
+ y(M),
1953
+ y(M)
1954
+ ])) : B.value && ((ee = B.value) == null ? void 0 : ee.length) > 0 ? (A(), L("div", wo, [
1955
+ y(le, { variant: "outlined" }, {
1956
+ default: T(() => [
1957
+ y(q, { class: "flex flex-col gap-4" }, {
1958
+ default: T(() => [
1959
+ e("div", Fo, [
1960
+ e("div", $o, v(s(i)("inventory.stock.history.summary.title")), 1)
1961
+ ]),
1962
+ e("div", Ao, [
1963
+ e("div", Vo, [
1964
+ e("div", Co, v(s(i)("inventory.stock.history.summary.totalPurchase")), 1),
1965
+ e("div", jo, v(b.value.PURCHASE), 1)
1966
+ ]),
1967
+ e("div", Do, [
1968
+ e("div", Bo, [
1969
+ de(v(s(i)("inventory.stock.history.summary.totalSales")) + "  ", 1),
1970
+ C.value != null ? (A(), z(oe, {
1971
+ key: 0,
1972
+ variant: "plain",
1973
+ placement: "top",
1974
+ content: `Before: ${C.value}`,
1975
+ "z-index": 50
1976
+ }, {
1977
+ default: T(() => [
1978
+ y(G, {
1979
+ name: "warning",
1980
+ size: "sm"
1981
+ })
1982
+ ]),
1983
+ _: 1
1984
+ }, 8, ["content"])) : se("", !0)
1985
+ ]),
1986
+ e("div", Mo, v(b.value.SALES), 1)
1987
+ ]),
1988
+ e("div", Io, [
1989
+ e("div", Uo, v(s(i)("inventory.stock.history.summary.totalLose")), 1),
1990
+ e("div", To, v(b.value.LOSE), 1)
1991
+ ]),
1992
+ e("div", Ho, [
1993
+ e("div", Eo, v(s(i)("inventory.stock.history.summary.totalRequest")), 1),
1994
+ e("div", Po, v(b.value.REQUEST), 1)
1995
+ ]),
1996
+ e("div", Ro, [
1997
+ e("div", Oo, v(s(i)("inventory.stock.history.summary.totalReceive")), 1),
1998
+ e("div", No, v(b.value.RECEIVE), 1)
1999
+ ]),
2000
+ e("div", Yo, [
2001
+ e("div", Lo, v(s(i)("inventory.stock.history.summary.totalConvert")), 1),
2002
+ e("div", zo, v(b.value.CONVERT), 1)
2003
+ ]),
2004
+ e("div", Go, [
2005
+ e("div", Ko, v(s(i)("inventory.stock.history.summary.totalDamage")), 1),
2006
+ e("div", Wo, v(b.value.DAMAGE), 1)
2007
+ ]),
2008
+ e("div", qo, [
2009
+ e("div", Xo, v(s(i)("inventory.stock.history.summary.openingBalance")), 1),
2010
+ e("div", Jo, v(H.value), 1)
2011
+ ]),
2012
+ e("div", Qo, [
2013
+ e("div", Zo, v(s(i)("inventory.stock.history.summary.lastStockBalance")), 1),
2014
+ e("div", es, v(N.value), 1)
2015
+ ])
2016
+ ]),
2017
+ s(m).enableTotalCost ? (A(), L("div", ts, [
2018
+ y(E, { class: "w-full" }),
2019
+ e("div", ns, [
2020
+ e("div", os, [
2021
+ y(Ze, { "z-index": 50 }, {
2022
+ default: T(() => [
2023
+ e("div", ss, [
2024
+ de(v(s(i)("inventory.stock.history.estimatedValue")) + " ", 1),
2025
+ y(oe, {
2026
+ variant: "plain",
2027
+ placement: "top",
2028
+ content: `[${X.value}] ${s(i)("inventory.stock.history.estimatedValueTooltip")}`,
2029
+ "z-index": 50
2030
+ }, {
2031
+ default: T(() => [
2032
+ y(G, {
2033
+ name: "help",
2034
+ size: "sm"
2035
+ })
2036
+ ]),
2037
+ _: 1
2038
+ }, 8, ["content"])
2039
+ ])
2040
+ ]),
2041
+ _: 1
2042
+ }),
2043
+ e("div", as, [
2044
+ n.sku.valuation === s(jt).Enum.FIFO ? (A(), L(ne, { key: 0 }, [
2045
+ y(W, {
2046
+ label: "FIFO",
2047
+ compact: ""
2048
+ }),
2049
+ de(" " + v(typeof J.value != "string" ? s(Fe)(
2050
+ J.value,
2051
+ !1,
2052
+ J.value.precision
2053
+ ) : J.value), 1)
2054
+ ], 64)) : (A(), L(ne, { key: 1 }, [
2055
+ de(v(typeof Y.value != "string" ? s(Fe)(
2056
+ Y.value,
2057
+ !1,
2058
+ Y.value.precision
2059
+ ) : Y.value), 1)
2060
+ ], 64))
2061
+ ])
2062
+ ]),
2063
+ e("div", ls, [
2064
+ y(Ze, { "z-index": 50 }, {
2065
+ default: T(() => [
2066
+ e("div", rs, [
2067
+ de(v(s(i)("inventory.stock.history.costSold")) + " ", 1),
2068
+ y(oe, {
2069
+ variant: "plain",
2070
+ placement: "top",
2071
+ "z-index": 50
2072
+ }, {
2073
+ content: T(() => [
2074
+ e("div", is, v(s(i)("inventory.stock.history.costSoldTooltip")), 1)
2075
+ ]),
2076
+ default: T(() => [
2077
+ y(G, {
2078
+ name: "help",
2079
+ size: "sm"
2080
+ })
2081
+ ]),
2082
+ _: 1
2083
+ })
2084
+ ])
2085
+ ]),
2086
+ _: 1
2087
+ }),
2088
+ e("div", us, v(K.value), 1)
2089
+ ])
2090
+ ])
2091
+ ])) : se("", !0)
2092
+ ]),
2093
+ _: 1
2094
+ })
2095
+ ]),
2096
+ _: 1
2097
+ }),
2098
+ r[5] || (r[5] = e("div", null, null, -1)),
2099
+ (A(!0), L(ne, null, ie(B.value, (ae) => (A(), L(ne, {
2100
+ key: ae.date
2101
+ }, [
2102
+ n.sku ? (A(), z(fo, {
2103
+ key: 0,
2104
+ record: ae,
2105
+ sku: n.sku,
2106
+ bills: D.value,
2107
+ onRefreshHistory: k
2108
+ }, null, 8, ["record", "sku", "bills"])) : se("", !0)
2109
+ ], 64))), 128))
2110
+ ])) : (A(), L("div", cs, [
2111
+ y(M),
2112
+ e("div", null, [
2113
+ e("img", {
2114
+ src: s(Jt),
2115
+ alt: "List is empty"
2116
+ }, null, 8, ds)
2117
+ ]),
2118
+ e("div", ms, v(s(i)("inventory.stock.history.noRecords")), 1),
2119
+ e("div", ps, v(s(i)("inventory.stock.history.changeDateRange")), 1),
2120
+ y(M),
2121
+ y(M)
2122
+ ]))
2123
+ ])
2124
+ ];
2125
+ }),
2126
+ _: 1
2127
+ }, 8, ["modelValue"]);
2128
+ };
2129
+ }
2130
+ }), vs = {
2131
+ key: 0,
2132
+ class: "flex items-center gap-1"
2133
+ }, ys = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, _s = { class: "flex flex-col gap-8" }, ks = { class: "flex flex-col" }, bs = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, gs = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary line-clamp-1" }, Us = /* @__PURE__ */ ue({
2134
+ __name: "StockView",
2135
+ setup(_) {
2136
+ const { t: g } = ce(), d = Be(), o = ke(), $ = Me(), S = dt(), m = ge(), i = rt(), w = Ht(), { columnDefs: j } = sn(), F = Ie(), u = be();
2137
+ o.watchLocation(D);
2138
+ const k = P(
2139
+ () => new Set(w.getAvailableItems(w.businessSubsidiaryId))
2140
+ ), V = O(!1);
2141
+ async function B() {
2142
+ F.open({
2143
+ title: g("inventory.stock.stock_balance.refreshBalance"),
2144
+ message: g("inventory.stock.stock_balance.refreshBalanceDescription"),
2145
+ closeButton: !0,
2146
+ primaryActions: {
2147
+ text: g("common.confirm"),
2148
+ close: !0
2149
+ },
2150
+ secondaryActions: {
2151
+ text: g("common.close"),
2152
+ close: !0,
2153
+ variant: "tertiary"
2154
+ }
2155
+ }).onPrimary(async () => {
2156
+ await m.recalculation.refreshCurrentBalances(), u.open({
2157
+ title: "Refresh Stock Balance",
2158
+ message: "Stock balance refresh has been queued. This may take a moment to complete.",
2159
+ type: "success"
2160
+ });
2161
+ });
2162
+ }
2163
+ async function D() {
2164
+ if (o._currentLocation) {
2165
+ V.value = !0;
2166
+ try {
2167
+ await $.readStockBalance(), await $.readProductBalance(), await i.readStockEstimateBalance();
2168
+ } catch (Q) {
2169
+ u.open({
2170
+ title: g("inventory.stock.error.title"),
2171
+ message: g("inventory.stock.error.message"),
2172
+ type: "error"
2173
+ }), console.error("error on fetch stock balance", Q);
2174
+ } finally {
2175
+ V.value = !1;
2176
+ }
2177
+ }
2178
+ }
2179
+ const a = P(() => [
2180
+ {
2181
+ type: "string",
2182
+ key: "status",
2183
+ entity: "sku",
2184
+ values: ["Active", "Inactive"]
2185
+ }
2186
+ ]), t = O({
2187
+ logic: "AND",
2188
+ rules: [
2189
+ {
2190
+ property: "status",
2191
+ operator: "$in",
2192
+ value: ["Active"],
2193
+ type: "string"
2194
+ }
2195
+ ]
2196
+ }), l = P(() => {
2197
+ var n, r, h;
2198
+ const Q = t.value ? Et.build(t.value) : null, p = [];
2199
+ for (const c of d.skus) {
2200
+ let f = !0;
2201
+ if (w.isEnabled && b.value && k.value && f && (f = k.value.has(c._id)), Q && f && (f = Pt(
2202
+ {
2203
+ status: c.isInactive ? "Inactive" : "Active"
2204
+ },
2205
+ Q
2206
+ )), f) {
2207
+ const M = c.trackingMeasurement;
2208
+ let I = (r = (n = $.stockBalance.skus) == null ? void 0 : n.find(
2209
+ (E) => E.id === c._id
2210
+ )) == null ? void 0 : r.balance, G = i.inventoryForecast.skus.find(
2211
+ (E) => E.id === c._id
2212
+ );
2213
+ const oe = {
2214
+ ...c,
2215
+ balance: I ?? {
2216
+ amount: 0,
2217
+ precision: 0
2218
+ },
2219
+ day: (G == null ? void 0 : G.depletionDays) ?? void 0,
2220
+ trackingUnitAbbrev: M ? ((h = c.unit.measurements.find((E) => E.id === M)) == null ? void 0 : h.abbrev) ?? "" : c.unit.abbrev
2221
+ };
2222
+ p.push(oe);
2223
+ }
2224
+ }
2225
+ return p;
2226
+ }), x = O(""), b = O(!0), { breakpoints: C } = Kt(), H = P(() => C.value.xs || C.value.sm), N = P(() => H.value ? 10 : 20), K = Rt(), R = P(() => [
2227
+ {
2228
+ label: g("inventory.stock.stock_balance.refreshBalance"),
2229
+ value: "refresh-balance",
2230
+ isPrimary: !0,
2231
+ prependIcon: "calculate"
2232
+ },
2233
+ {
2234
+ label: g("inventory.common.refresh"),
2235
+ value: "refresh"
2236
+ },
2237
+ {
2238
+ label: g("inventory.common.export"),
2239
+ value: "export"
2240
+ },
2241
+ {
2242
+ label: g("inventory.stock.stock_adjustment.title"),
2243
+ value: "stockAdjustment",
2244
+ isAdminOnly: !0
2245
+ }
2246
+ ]), X = O(!1);
2247
+ function Y() {
2248
+ X.value = !0;
2249
+ }
2250
+ function J(Q) {
2251
+ switch (Q) {
2252
+ case "refresh-balance":
2253
+ return B();
2254
+ case "refresh":
2255
+ return D();
2256
+ case "export":
2257
+ return en(l.value);
2258
+ case "stockAdjustment":
2259
+ return Y();
2260
+ }
2261
+ }
2262
+ return (Q, p) => {
2263
+ const n = U("FmSwitch"), r = U("FmTable");
2264
+ return A(), z(Ot, {
2265
+ title: s(g)("inventory.stock.title"),
2266
+ actions: R.value,
2267
+ "onClick:action": J
2268
+ }, {
2269
+ default: T(() => {
2270
+ var h, c, f, M;
2271
+ return [
2272
+ e("div", {
2273
+ class: he([
2274
+ "flex flex-col gap-8 max-h-full",
2275
+ {
2276
+ "p-0": H.value,
2277
+ "px-24 ": !H.value
2278
+ }
2279
+ ])
2280
+ }, [
2281
+ y(Nt, {
2282
+ searchable: "",
2283
+ "change-location": "",
2284
+ search: x.value,
2285
+ "onUpdate:search": p[1] || (p[1] = (I) => x.value = I),
2286
+ "hide-filter-options": !0,
2287
+ filterable: "",
2288
+ "filter-attributes": a.value,
2289
+ filter: t.value,
2290
+ "onUpdate:filter": p[2] || (p[2] = (I) => t.value = I)
2291
+ }, {
2292
+ default: T(() => [
2293
+ s(w).isEnabled ? (A(), L("div", vs, [
2294
+ e("span", ys, v(s(g)("inventory.integration.netsuite.subsidiaryHierarchy.filtering")), 1),
2295
+ y(zt),
2296
+ y(ze, null, {
2297
+ default: T(() => [
2298
+ y(n, {
2299
+ modelValue: b.value,
2300
+ "onUpdate:modelValue": p[0] || (p[0] = (I) => b.value = I)
2301
+ }, null, 8, ["modelValue"])
2302
+ ]),
2303
+ _: 1
2304
+ })
2305
+ ])) : se("", !0)
2306
+ ]),
2307
+ _: 1
2308
+ }, 8, ["search", "filter-attributes", "filter"]),
2309
+ (A(), z(r, {
2310
+ style: ot(s(K).tableHeight),
2311
+ "column-defs": s(j),
2312
+ "row-data": l.value,
2313
+ "search-value": x.value,
2314
+ loading: V.value || !s(o)._currentLocation,
2315
+ key: (h = s(o)._currentLocation) == null ? void 0 : h.dbName,
2316
+ onRowClick: p[3] || (p[3] = (I) => s(S).showSkuHistory(I.original)),
2317
+ "page-size": N.value
2318
+ }, {
2319
+ "list-row": T((I) => [
2320
+ y(Yt, {
2321
+ row: I,
2322
+ onRowClick: s(S).showSkuHistory
2323
+ }, {
2324
+ default: T((G) => {
2325
+ var oe, E, W, q, le, re, ee, ae, pe, me;
2326
+ return [
2327
+ e("div", _s, [
2328
+ e("div", ks, [
2329
+ e("div", bs, [
2330
+ y(s(Qe), {
2331
+ render: (W = (E = (oe = G.code) == null ? void 0 : oe.column) == null ? void 0 : E.columnDef) == null ? void 0 : W.cell,
2332
+ props: (le = (q = G.code) == null ? void 0 : q.getContext) == null ? void 0 : le.call(q)
2333
+ }, null, 8, ["render", "props"])
2334
+ ]),
2335
+ e("div", gs, [
2336
+ y(s(Qe), {
2337
+ render: (ae = (ee = (re = G.name) == null ? void 0 : re.column) == null ? void 0 : ee.columnDef) == null ? void 0 : ae.cell,
2338
+ props: (me = (pe = G.name) == null ? void 0 : pe.getContext) == null ? void 0 : me.call(pe)
2339
+ }, null, 8, ["render", "props"])
2340
+ ])
2341
+ ]),
2342
+ e("div", null, [
2343
+ y(Ye, {
2344
+ days: I.original.day
2345
+ }, null, 8, ["days"])
2346
+ ]),
2347
+ e("div", null, [
2348
+ y(ct, {
2349
+ class: "xs:w-[160px]",
2350
+ unit: I.original.unit,
2351
+ sku: I.original,
2352
+ amount: I.original.balance,
2353
+ "default-tracking-measurement": I.original.trackingMeasurement ?? void 0
2354
+ }, null, 8, ["unit", "sku", "amount", "default-tracking-measurement"])
2355
+ ])
2356
+ ])
2357
+ ];
2358
+ }),
2359
+ _: 2
2360
+ }, 1032, ["row", "onRowClick"])
2361
+ ]),
2362
+ _: 1
2363
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
2364
+ ], 2),
2365
+ (A(), z(ft, { to: "body" }, [
2366
+ (c = s(S).stockHistoryProps) != null && c.sku ? (A(), z(fs, Te(He({ key: 0 }, s(S).stockHistoryProps)), null, 16)) : se("", !0),
2367
+ (f = s(S).convertSkuDialogProps) != null && f.sku ? (A(), z(gn, Te(He({ key: 1 }, s(S).convertSkuDialogProps)), null, 16)) : se("", !0),
2368
+ (M = s(S).adjustSkuDialogProps) != null && M.stock ? (A(), z(jn, Te(He({ key: 2 }, s(S).adjustSkuDialogProps)), null, 16)) : se("", !0),
2369
+ X.value ? (A(), z(Yn, {
2370
+ key: 3,
2371
+ show: X.value,
2372
+ "onUpdate:show": p[4] || (p[4] = (I) => X.value = I),
2373
+ onSubmitted: p[5] || (p[5] = (I) => D())
2374
+ }, null, 8, ["show"])) : se("", !0)
2375
+ ]))
2376
+ ];
2377
+ }),
2378
+ _: 1
2379
+ }, 8, ["title", "actions"]);
2380
+ };
2381
+ }
2382
+ });
2383
+ export {
2384
+ Us as default
2385
+ };