@feedmepos/mf-inventory-portal 0.0.23-dev.9 → 0.0.24-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 (140) hide show
  1. package/dist/App-D3sNH2MR.js +276 -0
  2. package/dist/{ApprovalView-e85YmdZN.js → ApprovalView-DHnRx0hJ.js} +17 -20
  3. package/dist/{BindingsDialog-giBUD0IH.js → BindingsDialog-oTeg2Dai.js} +6 -6
  4. package/dist/{BindingsPicker-CC4MmPbF.js → BindingsPicker-CWdjmMJ3.js} +8 -9
  5. package/dist/{BindingsTable-WphZdzrA.js → BindingsTable-bKLR1OKX.js} +18 -22
  6. package/dist/ClosingDraftView-CIQVz7lY.js +1225 -0
  7. package/dist/{ClosingTemplateView-1lzoDyet.js → ClosingTemplateView-D5pLzQwU.js} +259 -274
  8. package/dist/FmCustomAttribute.vue_vue_type_script_setup_true_lang-ClLDcchC.js +142 -0
  9. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-Cv-vvzr5.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-B_c6Vn6P.js} +23 -24
  10. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-DIFQcrc0.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DhpHOaRH.js} +50 -51
  11. package/dist/{IngredientGroupView-UegBM_JK.js → IngredientGroupView-4C437mso.js} +63 -70
  12. package/dist/IngredientsView-DoiGgjre.js +1706 -0
  13. package/dist/{IntegrationView-FYNNzKia.js → IntegrationView-8ZKE7MAM.js} +123 -126
  14. package/dist/{InventoryBindingForm-DsHv_IHG.js → InventoryBindingForm-CcnfliYQ.js} +1 -1
  15. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-BURSXafS.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-B_J-6C9x.js} +116 -108
  16. package/dist/{InventoryBindingSummary-BLb4MRPZ.js → InventoryBindingSummary-CRdHCzNE.js} +1 -1
  17. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-BG78-DHs.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B2-TypU0.js} +1 -1
  18. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-CqID5_7v.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BuQde75S.js} +20 -21
  19. package/dist/PublishView-t5gjGmK_.js +192 -0
  20. package/dist/{PurchaseOrderPrintPreview-BBMU3teq.js → PurchaseOrderPrintPreview-6i53Y-v1.js} +13 -14
  21. package/dist/ReceiveRequestView-uOeSh0Mr.js +1866 -0
  22. package/dist/RecipeView-BTWywckD.js +609 -0
  23. package/dist/StockView-DN2xk8ei.js +1817 -0
  24. package/dist/{SupplierView-B2aObtwK.js → SupplierView-l0XUg3J4.js} +185 -196
  25. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CWMn6fFf.js +1327 -0
  26. package/dist/TransferTemplateView-wDKXpCWZ.js +1263 -0
  27. package/dist/UnitView-CUI-k-tS.js +648 -0
  28. package/dist/{WarehouseView-G8pej6Y2.js → WarehouseView-WsI_eG5r.js} +190 -197
  29. package/dist/api/adjustment-template.d.ts +25 -0
  30. package/dist/api/bill.d.ts +240 -84
  31. package/dist/api/inventory.d.ts +19 -6
  32. package/dist/api/netsuite.d.ts +3 -3
  33. package/dist/app-DntcWR3_.js +85558 -0
  34. package/dist/app.d.ts +85 -0
  35. package/dist/app.js +2 -2
  36. package/dist/components/FmCustomAttribute.vue.d.ts +23 -0
  37. package/dist/components/FmLockableField.vue.d.ts +37 -0
  38. package/dist/components/FmMultiselectDialogProps.d.ts +1 -0
  39. package/dist/components/inventory-binding/InventoryBinding.vue.d.ts +3 -1
  40. package/dist/components/shell/inventory/binding-ui.vue.d.ts +3 -1
  41. package/dist/composable/defineDeepModel.d.ts +1 -1
  42. package/dist/{decimal-DC07xoJW.js → decimal-DTCTnMwO.js} +1 -1
  43. package/dist/format-unit-display-Hy48Iw5j.js +1215 -0
  44. package/dist/index-Bv9RYyTZ.js +29202 -0
  45. package/dist/{StockView-C5btudss.js → index-D4yJP9I2.js} +2220 -3863
  46. package/dist/layout/SingleColumnLayout.vue.d.ts +1 -0
  47. package/dist/router/name.d.ts +2 -0
  48. package/dist/stock-BsdmfT-b.js +125 -0
  49. package/dist/stores/feature.d.ts +41 -1
  50. package/dist/stores/integration/netsuite.d.ts +3 -2
  51. package/dist/stores/inventory.d.ts +20 -8
  52. package/dist/stores/location.d.ts +29 -1
  53. package/dist/stores/supplier.d.ts +1 -1
  54. package/dist/style.css +1 -1
  55. package/dist/supplier-CXhkgC4M.js +77 -0
  56. package/dist/tsconfig.app.tsbuildinfo +1 -1
  57. package/dist/{use-inventory-binding-dialog-B0G2XYSw.js → use-inventory-binding-dialog-DPMJmBCr.js} +10 -11
  58. package/dist/views/adjustment-template/import/AdjustmentTemplateImport.vue.d.ts +2 -0
  59. package/dist/views/adjustment-template/import/AdjustmentTemplateImportItem.vue.d.ts +18 -0
  60. package/dist/views/adjustment-template/import/export.d.ts +60 -0
  61. package/dist/views/adjustment-template/wastage-template/WastageTemplateDetails.vue.d.ts +2 -0
  62. package/dist/views/adjustment-template/wastage-template/WastageTemplateDialog.vue.d.ts +22 -0
  63. package/dist/views/adjustment-template/wastage-template/WastageTemplatePublish.vue.d.ts +6 -0
  64. package/dist/views/adjustment-template/wastage-template/WastageTemplateReason.vue.d.ts +18 -0
  65. package/dist/views/adjustment-template/wastage-template/WastageTemplateView.vue.d.ts +2 -0
  66. package/dist/views/adjustment-template/wastage-template/actions.d.ts +1377 -0
  67. package/dist/views/adjustment-template/wastage-template/form/WastageTemplateForm.vue.d.ts +16 -0
  68. package/dist/views/adjustment-template/wastage-template/form/WastageTemplateItemTable.vue.d.ts +35 -0
  69. package/dist/views/adjustment-template/wastage-template/form/useAdjustmentTemplateItems.d.ts +20 -0
  70. package/dist/views/adjustment-template/wastage-template/props.d.ts +36 -0
  71. package/dist/views/adjustment-template/wastage-template/table.d.ts +1351 -0
  72. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +198 -12
  73. package/dist/views/closing-draft/composables/use-closing-draft-actions.d.ts +7 -4
  74. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +1559 -467
  75. package/dist/views/closing-draft/helpers/export-draft.helper.d.ts +19 -0
  76. package/dist/views/closing-draft/helpers/get-calculated-total.helper.d.ts +4 -0
  77. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +2 -1
  78. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +72 -12
  79. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +73 -13
  80. package/dist/views/ingredient-group/composables/use-ingredient-group-table.d.ts +6 -3
  81. package/dist/views/ingredients/components/convert/ConvertFormProps.d.ts +1 -0
  82. package/dist/views/ingredients/components/ingredient-form/IngredientForm.vue.d.ts +4 -2
  83. package/dist/views/ingredients/components/inventory-binding/InventoryBindingForm.vue.d.ts +1 -0
  84. package/dist/views/ingredients/composables/use-ingredient-table.d.ts +2 -1
  85. package/dist/views/publish/PublishView.vue.d.ts +2 -0
  86. package/dist/views/receive-request/components/netsuite/NetSuiteInfo.vue.d.ts +12 -0
  87. package/dist/views/receive-request/components/netsuite/NetSuiteProps.d.ts +13 -0
  88. package/dist/views/receive-request/components/netsuite/NetSuiteSync.vue.d.ts +12 -0
  89. package/dist/views/receive-request/components/transfer-form/NetSuiteField.vue.d.ts +13 -0
  90. package/dist/views/receive-request/components/transfer-form/SparkIcon.vue.d.ts +1 -1
  91. package/dist/views/receive-request/components/transfer-form/TransferForm.vue.d.ts +86 -17
  92. package/dist/views/receive-request/components/transfer-form/components/ForecastStock.vue.d.ts +4 -2
  93. package/dist/views/receive-request/components/transfer-form/composables/use-transfer-items.d.ts +2 -1
  94. package/dist/views/receive-request/composables/use-receive-request-form.d.ts +126 -24
  95. package/dist/views/receive-request/composables/use-receive-request-table.d.ts +126 -24
  96. package/dist/views/recipe/components/recipe-form/RecipeForm.vue.d.ts +2 -0
  97. package/dist/views/stock/components/StockRecordCard.vue.d.ts +120 -42
  98. package/dist/views/stock/components/dialog/AdjustedItemForm.vue.d.ts +6 -4
  99. package/dist/views/stock/helper/compute-summary-total.d.ts +2 -2
  100. package/dist/views/transfer-template/components/transfer-template-form/composables/use-template-enabled-locations.d.ts +4 -0
  101. package/dist/views/transfer-template/components/transfer-template-form/composables/use-transfer-template-items.d.ts +2 -1
  102. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +72 -12
  103. package/dist/views/transfer-template/composables/use-transfer-template-table.d.ts +72 -12
  104. package/dist/views/transfer-template/helpers/import-export.helper.d.ts +2 -1
  105. package/dist/vue-i18n-ByVzHsI7.js +2365 -0
  106. package/package.json +5 -4
  107. package/dist/App-ByLgARNp.js +0 -259
  108. package/dist/ClosingDraftView-CQM1Sx45.js +0 -755
  109. package/dist/FmDroppableField-8RzKjEdL.js +0 -154
  110. package/dist/FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BvkN-71q.js +0 -436
  111. package/dist/FmMultiselectDialog-DScMA6iG.js +0 -415
  112. package/dist/IngredientBindedItem.vue_vue_type_script_setup_true_lang-t4pim_k9.js +0 -51
  113. package/dist/IngredientsView-BfW-jZLM.js +0 -1666
  114. package/dist/ReceiveRequestView-vbANEzne.js +0 -4165
  115. package/dist/RecipeView-DW4DY0C0.js +0 -598
  116. package/dist/TableActionableRow.vue_vue_type_script_setup_true_lang-DlNJ6kRg.js +0 -135
  117. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-B2LOvVef.js +0 -1229
  118. package/dist/TransferTemplateView-BKumN_p6.js +0 -1262
  119. package/dist/UnitView-CHLucv9s.js +0 -648
  120. package/dist/_plugin-vue_export-helper-CHgC5LLL.js +0 -9
  121. package/dist/app-BXjk74IB.js +0 -33538
  122. package/dist/date2-CWAt9bRf.js +0 -117
  123. package/dist/dayjs.min-D3jPOnu6.js +0 -282
  124. package/dist/defineDeepModel-CiD4GtOw.js +0 -13
  125. package/dist/feature-6tcLMotY.js +0 -92
  126. package/dist/form-mode.enum-BKiNVH6A.js +0 -4
  127. package/dist/format-time-from-id-CYU5Z9Mt.js +0 -15
  128. package/dist/format-unit-display-CY-0bznr.js +0 -1217
  129. package/dist/fuzzy-BMkhNYLR.js +0 -41
  130. package/dist/index-BXwQa14X.js +0 -45
  131. package/dist/index-CRLd5xyg.js +0 -22283
  132. package/dist/index-DqwAtOgI.js +0 -12087
  133. package/dist/netsuite-fYUUk_ss.js +0 -225
  134. package/dist/row-action.enum-7rGLGZ5v.js +0 -55
  135. package/dist/rules-BmRGm3yv.js +0 -203
  136. package/dist/stock-CEX0DP2B.js +0 -111
  137. package/dist/supplier-CdJmZr7w.js +0 -77
  138. package/dist/use-template-enabled-locations-2-xbPJWHCs.js +0 -86
  139. package/dist/xlsx-CTOKp7SQ.js +0 -24004
  140. package/dist/xlsx.util-D5NFSfDg.js +0 -78
@@ -0,0 +1,1817 @@
1
+ import { defineComponent as re, ref as H, computed as I, resolveComponent as B, openBlock as $, createBlock as z, withCtx as D, createElementVNode as n, normalizeClass as he, toDisplayString as k, createVNode as g, createElementBlock as O, Fragment as ne, renderList as ae, unref as u, h as ye, watch as ke, isRef as je, createCommentVNode as te, reactive as at, onMounted as qe, normalizeStyle as Je, createTextVNode as pe, Teleport as rt, normalizeProps as Se, mergeProps as we } from "vue";
2
+ import { u as ce, O as lt, f as Ue, h as it, a as Ie, F as Le, P as Ce, j as ie, K as ut, t as ge, N as Me, A as ct, M as dt, L as ve, Q as mt, T as ee, V as pt, W as ze, m as vt, J as ft, X as yt, Y as _t, Z as Qe, $ as q, a0 as ht, r as Xe, a1 as De, a2 as kt, a3 as gt, o as Ne, c as bt, a4 as xt, a5 as St, C as Fe, a6 as wt, a7 as Ft, a8 as $t, z as At, _ as Vt, B as Ct, E as Mt, G as Ye } from "./app-DntcWR3_.js";
3
+ import { u as Pe, a as Te } from "./stock-BsdmfT-b.js";
4
+ import { g as be } from "./decimal-DTCTnMwO.js";
5
+ import { e as Dt, u as Ze, i as et, _ as Ke } from "./PremiumBadge.vue_vue_type_script_setup_true_lang-BuQde75S.js";
6
+ import { _ as Be, S as $e, g as tt } from "./StockForecast.vue_vue_type_style_index_0_lang-KLXSWvo5.js";
7
+ import { _ as Bt } from "./PreviewBadge.vue_vue_type_script_setup_true_lang-CRZiQHjx.js";
8
+ import { useI18n as le, useCoreStore as jt } from "@feedmepos/mf-common";
9
+ import { useSnackbar as fe, useDialog as nt, useProxiedModel as Re, useBreakpoints as Ut } from "@feedmepos/ui-library";
10
+ import { defineStore as It } from "pinia";
11
+ import { u as Pt } from "./use-inventory-binding-dialog-DPMJmBCr.js";
12
+ import { _ as Tt } from "./NumberPrecisionInput.vue_vue_type_script_setup_true_lang-B2-TypU0.js";
13
+ import { E as Rt } from "./empty-placeholder-wf6-BWE8.js";
14
+ import "./index-D4yJP9I2.js";
15
+ import "./array-hChJVZLE.js";
16
+ var _e = /* @__PURE__ */ ((p) => (p.History = "History", p.Convert = "Convert", p.Adjust = "Adjust", p))(_e || {});
17
+ const Ht = [
18
+ {
19
+ translationKey: "inventory.stock.action.history",
20
+ color: "text-neutral-700",
21
+ value: "History"
22
+ /* History */
23
+ }
24
+ ], Et = [
25
+ {
26
+ translationKey: "inventory.stock.action.history",
27
+ color: "text-neutral-700",
28
+ value: "History"
29
+ /* History */
30
+ },
31
+ {
32
+ translationKey: "inventory.stock.action.convert",
33
+ color: "text-neutral-700",
34
+ value: "Convert"
35
+ /* Convert */
36
+ },
37
+ {
38
+ translationKey: "inventory.stock.action.adjust",
39
+ color: "text-neutral-700",
40
+ value: "Adjust"
41
+ /* Adjust */
42
+ }
43
+ ];
44
+ async function Ot(p) {
45
+ const r = `${(ce().currentLocation.name || "").replace(
46
+ / /g,
47
+ "_"
48
+ )}_${lt().format("DD_MM_YYYY_HHmm")}.xlsx`;
49
+ await Dt(
50
+ [
51
+ {
52
+ name: "stock",
53
+ data: p,
54
+ columns: [
55
+ {
56
+ name: "Code",
57
+ selector: "code"
58
+ },
59
+ {
60
+ name: "Name",
61
+ selector: "name"
62
+ },
63
+ {
64
+ name: "Balance",
65
+ selector: (s) => {
66
+ const x = xe(s, s.unit);
67
+ return x.type === "unit" ? be(s.balance, s.unit, null, !1) : be(s.balance, s.unit, x.measurement, !1);
68
+ }
69
+ },
70
+ {
71
+ name: "Unit",
72
+ selector: (s) => {
73
+ var y;
74
+ const x = xe(s, s.unit);
75
+ return x.type === "unit" ? s.unit.abbrev : ((y = s.unit.measurements.find((c) => c.id === x.measurement)) == null ? void 0 : y.abbrev) || "";
76
+ }
77
+ }
78
+ ]
79
+ }
80
+ ],
81
+ r
82
+ );
83
+ }
84
+ function xe(p, h) {
85
+ const r = localStorage.getItem(`uom:${p._id}`);
86
+ return r ? r === h._id ? {
87
+ type: "unit"
88
+ } : h.measurements.find((s) => s.id === r) ? {
89
+ type: "measurement",
90
+ measurement: r
91
+ } : {
92
+ type: "unit"
93
+ } : p.trackingMeasurement && h.measurements.find((s) => s.id === p.trackingMeasurement) ? {
94
+ type: "measurement",
95
+ measurement: p.trackingMeasurement
96
+ } : {
97
+ type: "unit"
98
+ };
99
+ }
100
+ const Lt = { class: "fm-typo-en-body-md-400 flex-grow" }, ot = /* @__PURE__ */ re({
101
+ __name: "UnitDisplayControl",
102
+ props: {
103
+ unit: {},
104
+ sku: {},
105
+ amount: {},
106
+ defaultTrackingMeasurement: {}
107
+ },
108
+ setup(p) {
109
+ function h(b) {
110
+ return `uom:${b._id}`;
111
+ }
112
+ function r(b) {
113
+ const a = h(s.sku);
114
+ b ? localStorage.setItem(a, b) : localStorage.setItem(a, s.unit._id), x.value = xe(s.sku, s.unit);
115
+ }
116
+ const s = p, x = H(xe(s.sku, s.unit)), y = I(() => {
117
+ const { measurements: b } = s.unit;
118
+ return [
119
+ {
120
+ label: `${be(s.amount, s.unit)}`,
121
+ value: null
122
+ },
123
+ ...b.map(({ id: a }) => ({
124
+ label: `${be(s.amount, s.unit, a)}`,
125
+ value: a
126
+ }))
127
+ ];
128
+ });
129
+ function c({ value: b }) {
130
+ return u(x).type === "unit" ? b === null : b === u(x).measurement;
131
+ }
132
+ const d = I(
133
+ () => {
134
+ var b;
135
+ return ((b = y.value.find((a) => c(a))) == null ? void 0 : b.label) ?? "";
136
+ }
137
+ ), F = H(!1);
138
+ return (b, a) => {
139
+ const o = B("FmIcon"), S = B("FmMenuItem"), A = B("FmMenu");
140
+ return $(), z(A, {
141
+ "stop-click-propagation": "",
142
+ onMenuChanged: a[0] || (a[0] = (_) => F.value = _)
143
+ }, {
144
+ "menu-button": D(() => [
145
+ n("button", {
146
+ type: "button",
147
+ class: he([
148
+ "w-full text-left flex items-center gap-8 cursor-pointer fm-corner-radius-sm px-8 py-4 border bg-white",
149
+ F.value ? "border-fm-color-primary" : "border-fm-color-neutral-gray-100"
150
+ ])
151
+ }, [
152
+ n("div", Lt, k(d.value), 1),
153
+ g(o, {
154
+ class: "text-fm-color-neutral-gray-400",
155
+ name: "expand_more"
156
+ })
157
+ ], 2)
158
+ ]),
159
+ default: D(() => [
160
+ ($(!0), O(ne, null, ae(y.value, (_) => ($(), z(S, {
161
+ key: _.value ?? 0,
162
+ label: _.label,
163
+ "model-value": c(_),
164
+ onClick: (i) => r(_.value)
165
+ }, null, 8, ["label", "model-value", "onClick"]))), 128))
166
+ ]),
167
+ _: 1
168
+ });
169
+ };
170
+ }
171
+ }), zt = { class: "whitespace-nowrap" }, Nt = /* @__PURE__ */ re({
172
+ __name: "StockHeaderPreview",
173
+ setup(p) {
174
+ const { t: h } = le();
175
+ return (r, s) => ($(), z(Bt, null, {
176
+ default: D(() => [
177
+ n("div", zt, k(u(h)("inventory.stock.prediction.daysRemaining")), 1)
178
+ ]),
179
+ _: 1
180
+ }));
181
+ }
182
+ }), st = It("stockActions", () => {
183
+ const p = H(!1), h = ce(), r = Pe(), s = Ze(), x = fe(), y = nt(), { t: c } = le();
184
+ async function d() {
185
+ if (h._currentLocation) {
186
+ p.value = !0;
187
+ try {
188
+ await r.readStockBalance(), await r.readProductBalance(), await s.readStockEstimateBalance();
189
+ } catch {
190
+ x.open({
191
+ title: c("inventory.stock.error.title"),
192
+ message: c("inventory.stock.error.message"),
193
+ type: "error"
194
+ });
195
+ } finally {
196
+ p.value = !1;
197
+ }
198
+ }
199
+ }
200
+ const F = H();
201
+ async function b(i) {
202
+ var w, M, P;
203
+ if (!!!((M = (w = i.convert) == null ? void 0 : w.inventoryBindings) != null && M.length)) {
204
+ y.open({
205
+ title: c("inventory.stock.error.convert.title"),
206
+ message: c("inventory.stock.error.convert.message")
207
+ });
208
+ return;
209
+ }
210
+ const C = {
211
+ maxCount: ((P = r.productBalance.find(({ id: T }) => T === i._id)) == null ? void 0 : P.count) || 0,
212
+ sku: i,
213
+ show: !0,
214
+ "onUpdate:show"(T) {
215
+ F.value.show = T;
216
+ },
217
+ onSubmitted() {
218
+ d();
219
+ }
220
+ };
221
+ F.value = C;
222
+ }
223
+ const a = H();
224
+ async function o(i) {
225
+ const j = {
226
+ stock: i,
227
+ show: !0,
228
+ "onUpdate:show"(E) {
229
+ a.value.show = E;
230
+ },
231
+ onSubmitted() {
232
+ d();
233
+ }
234
+ };
235
+ a.value = j;
236
+ }
237
+ const S = H();
238
+ async function A(i) {
239
+ const j = {
240
+ sku: i,
241
+ show: !0,
242
+ "onUpdate:show"(E) {
243
+ S.value.show = E;
244
+ }
245
+ };
246
+ S.value = j;
247
+ }
248
+ function _(i, j) {
249
+ const E = Ue(j);
250
+ switch (i) {
251
+ case _e.History:
252
+ A(E);
253
+ return;
254
+ case _e.Convert:
255
+ b(E);
256
+ return;
257
+ case _e.Adjust:
258
+ o(E);
259
+ return;
260
+ }
261
+ }
262
+ return {
263
+ fetchStockBalance: d,
264
+ onActionMenu: _,
265
+ stockHistoryProps: S,
266
+ showSkuHistory: A,
267
+ convertSkuDialogProps: F,
268
+ adjustSkuDialogProps: a
269
+ };
270
+ });
271
+ function Yt() {
272
+ const p = ce(), h = st(), { t: r } = le();
273
+ return {
274
+ columnDefs: [
275
+ {
276
+ accessorKey: "code",
277
+ header: () => r("inventory.stock.code"),
278
+ enableSorting: !0,
279
+ size: 300
280
+ },
281
+ {
282
+ accessorKey: "name",
283
+ header: () => r("inventory.stock.product"),
284
+ enableSorting: !0,
285
+ size: "auto"
286
+ },
287
+ {
288
+ id: "UOM",
289
+ header: () => r("inventory.stock.balance"),
290
+ cell(x) {
291
+ const y = x.row.original, c = {
292
+ unit: y.unit,
293
+ sku: y,
294
+ amount: y.balance,
295
+ defaultTrackingMeasurement: y.trackingMeasurement ?? void 0
296
+ };
297
+ return ye(ot, c);
298
+ },
299
+ size: 180
300
+ },
301
+ {
302
+ accessorKey: "day",
303
+ id: "expireDate",
304
+ header: () => ye(Nt),
305
+ enableSorting: !0,
306
+ sortUndefined: "last",
307
+ cell(x) {
308
+ var a, o;
309
+ const y = x.row.original.day, c = (a = x.row.original.thresholds) == null ? void 0 : a.low, d = (o = x.row.original.thresholds) == null ? void 0 : o.mid;
310
+ if (typeof y != "number" || typeof c != "number" || typeof d != "number")
311
+ return ye(Be, {
312
+ days: y
313
+ });
314
+ const F = y <= c ? $e.low : y <= d ? $e.mid : $e.high;
315
+ return ye(Be, {
316
+ days: y,
317
+ level: F
318
+ });
319
+ },
320
+ size: 200
321
+ },
322
+ {
323
+ id: "action",
324
+ cell(x) {
325
+ var y;
326
+ return it(
327
+ ((y = p._currentLocation) == null ? void 0 : y.type) === "restaurant" ? Ht : Et,
328
+ (c) => h.onActionMenu(c, x.row.original)
329
+ );
330
+ },
331
+ enableSorting: !1,
332
+ size: 40,
333
+ meta: {
334
+ cellClass: "",
335
+ headerClass: ""
336
+ }
337
+ }
338
+ ]
339
+ };
340
+ }
341
+ const Kt = {
342
+ context: null,
343
+ error: null,
344
+ isRequired(p = "This field is required") {
345
+ return `${this.context ?? ""}`.length === 0 && (this.error = p), this;
346
+ },
347
+ isString(p = "Must be a valid string") {
348
+ return this.error ? this : (typeof this.context != "string" && (this.error ?? (this.error = p)), this);
349
+ },
350
+ toInt() {
351
+ return this.error ? this : (this.context = +this.context, this);
352
+ },
353
+ isInteger(p = "Must be an integer") {
354
+ return this.error ? this : (this.toInt(), isNaN(this.context) && (this.error = p), this);
355
+ },
356
+ min(p, h) {
357
+ if (this.error) return this;
358
+ try {
359
+ typeof this.context == "number" ? +this.context < p && (this.error = h ?? `Must be at least ${p}`) : Object.prototype.hasOwnProperty.call(this.context, "length") ? +this.context.length < p && (this.error = h ?? `Must be at least ${p}`) : this.error = "Length cannot be determined";
360
+ } catch {
361
+ this.error = "Length cannot be determined";
362
+ }
363
+ return this;
364
+ },
365
+ max(p, h) {
366
+ if (this.error) return this;
367
+ try {
368
+ typeof this.context == "number" ? +this.context > p && (this.error = h ?? `Must be at most ${p}`) : "length" in this.context ? +this.context.length > p && (this.error = h ?? `Must be at most ${p}`) : this.error = "Length cannot be determined";
369
+ } catch {
370
+ this.error = "Length cannot be determined";
371
+ }
372
+ return this;
373
+ }
374
+ };
375
+ function Ge(p) {
376
+ return { ...Kt, context: p };
377
+ }
378
+ const Gt = { class: "flex items-center" }, Wt = { class: "fm-typo-en-title-md-800" }, qt = { class: "flex flex-col gap-24 w-full" }, Jt = { class: "flex flex-col gap-8" }, Qt = { class: "fm-typo-en-body-lg-600" }, Xt = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary flex-grow" }, Zt = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-error" }, en = { class: "flex flex-col p-16 gap-8" }, tn = { class: "flex flex-col gap-4" }, nn = { class: "fm-typo-en-body-md-600 text-fm-color-typo-secondary bg-fm-color-neutral-gray-100 border-b py-12 px-16" }, on = { class: "grid grid-cols-[auto_100px_100px_48px] xs:grid-cols-[auto_80px_120px_48px] gap-8 px-8 items-center" }, sn = { class: "xs:col-span-3" }, an = { class: "flex gap-8" }, rn = /* @__PURE__ */ re({
379
+ __name: "ConvertSkuDialog",
380
+ props: {
381
+ sku: {},
382
+ maxCount: {},
383
+ show: { type: Boolean }
384
+ },
385
+ emits: ["update:show", "submitted"],
386
+ setup(p, { expose: h, emit: r }) {
387
+ const s = p, x = r, y = Pt(), c = Ie(), d = Te(), F = fe(), { t: b } = le(), a = H(0), o = H(null), S = I(() => c.skus), A = I(
388
+ () => {
389
+ var t, e;
390
+ return (((e = (t = s.sku) == null ? void 0 : t.convert) == null ? void 0 : e.inventoryBindings) ?? []).filter(
391
+ (m) => m.type === Le.enum.SKU
392
+ );
393
+ }
394
+ ), _ = I({
395
+ get() {
396
+ return !!o.value;
397
+ },
398
+ set(t) {
399
+ t ? o.value = Ue(A.value) : (o.value = null, a.value = Math.min(a.value, s.maxCount ?? 0));
400
+ }
401
+ }), i = H(!1);
402
+ ke([() => s.show], ([t]) => {
403
+ t && (a.value = 0);
404
+ });
405
+ function j() {
406
+ Q(s.sku, ge(a.value), o.value);
407
+ }
408
+ function E(t) {
409
+ if (o.value)
410
+ return !0;
411
+ const e = Ge(t).isInteger().max(s.maxCount ?? 0).error ?? "";
412
+ return e || !0;
413
+ }
414
+ function C(t) {
415
+ var v;
416
+ const e = (v = s.sku.convert) != null && v.measurement ? s.sku.unit.measurements.find((V) => {
417
+ var N;
418
+ return V.id === ((N = s.sku.convert) == null ? void 0 : N.measurement);
419
+ }) ?? null : null, m = Ce(s.sku.unit, e), l = mt(+t);
420
+ return Ge(l).isInteger().max(m).error ? "Precision cannot be more than " + m : !0;
421
+ }
422
+ const w = I(
423
+ () => {
424
+ var t, e;
425
+ return (t = s.sku.convert) != null && t.measurement ? (e = s.sku.unit.measurements.find((m) => {
426
+ var l;
427
+ return m.id === ((l = s.sku.convert) == null ? void 0 : l.measurement);
428
+ })) == null ? void 0 : e.abbrev : s.sku.unit.abbrev;
429
+ }
430
+ ), M = I(() => {
431
+ var m, l, f;
432
+ const t = (l = (m = s.sku.convert) == null ? void 0 : m.inventoryBindings) == null ? void 0 : l.filter((v) => v.type === "SKU");
433
+ return (f = o.value ?? t) == null ? void 0 : f.map((v) => {
434
+ var Z, W, se, He, Ee;
435
+ const V = c.skus.find((me) => me._id === v.id), N = ((Z = v.measurement) == null ? void 0 : Z.abbrev) ?? ((W = V == null ? void 0 : V.unit) == null ? void 0 : W.abbrev), X = (se = s.sku.convert) != null && se.measurement ? s.sku.unit.measurements.find((me) => {
436
+ var Oe;
437
+ return me.id === ((Oe = s.sku.convert) == null ? void 0 : Oe.measurement);
438
+ }) ?? null : null, de = Ce(s.sku.unit, X), U = C(`${a.value}`) === !0 ? ie(
439
+ ut(
440
+ v.amount,
441
+ ge(+a.value, de)
442
+ ),
443
+ !1
444
+ ) : "0", G = (Ee = (He = o.value) == null ? void 0 : He.find((me) => me.id === (V == null ? void 0 : V._id))) == null ? void 0 : Ee.amount, J = G ? ie(G, !1) : null;
445
+ return {
446
+ sku: V,
447
+ convertAmount: J ?? U,
448
+ abbrev: N
449
+ };
450
+ });
451
+ }), P = H();
452
+ h({
453
+ validateInputs: () => {
454
+ var t, e;
455
+ (e = (t = P.value) == null ? void 0 : t.validateInputs) == null || e.call(t);
456
+ },
457
+ resetInputsValidation: () => {
458
+ var t, e;
459
+ (e = (t = P.value) == null ? void 0 : t.resetInputsValidation) == null || e.call(t);
460
+ },
461
+ resetInputs: () => {
462
+ var t, e;
463
+ (e = (t = P.value) == null ? void 0 : t.resetInputs) == null || e.call(t);
464
+ }
465
+ });
466
+ const T = Re(s, "show");
467
+ async function Q(t, e, m) {
468
+ i.value = !0;
469
+ try {
470
+ await d.convertSku({
471
+ conversions: [
472
+ {
473
+ doc: t,
474
+ amount: e,
475
+ overrides: m == null ? void 0 : m.map((l) => ({
476
+ ...l,
477
+ amount: {
478
+ ...l.amount,
479
+ amount: -1 * Math.abs(l.amount.amount)
480
+ // ensure truly negative
481
+ }
482
+ }))
483
+ }
484
+ ]
485
+ }), x("update:show", !1), x("submitted");
486
+ } catch (l) {
487
+ F.open({
488
+ title: "Something went wrong",
489
+ message: `Cannot convert ${t.name}. Please try again.`,
490
+ type: "error"
491
+ }), console.error("error at converting stock amount", t, e, l);
492
+ } finally {
493
+ i.value = !1;
494
+ }
495
+ }
496
+ function Y(t, e, m) {
497
+ const l = +e;
498
+ let f = m;
499
+ e.length > 0 && isFinite(l) ? f = m.map((v) => (v.id !== t || (v.amount = ve(l)), v)) : f = m.map((v) => (v.id !== t || (v.amount = { amount: 0, precision: 0 }), v)), o.value = f;
500
+ }
501
+ function L(t) {
502
+ const e = S.value.find((m) => m._id === t);
503
+ return e ? tt(e.unit, !0) : [];
504
+ }
505
+ function R(t, e) {
506
+ const m = L(t), l = m.find((f) => f.value === e) ?? m.find((f) => f.value === null);
507
+ return l ? {
508
+ ...l,
509
+ label: l.abbrev
510
+ } : null;
511
+ }
512
+ function K(t, e, m) {
513
+ let l;
514
+ if (e === null)
515
+ l = m.map((f) => (f.id !== t || (f.measurement = null), f)) ?? [];
516
+ else {
517
+ const f = S.value.find((v) => v._id === t);
518
+ l = m.map((v) => {
519
+ var V, N;
520
+ return v.id !== t || (v.measurement = (N = (V = f == null ? void 0 : f.unit) == null ? void 0 : V.measurements) == null ? void 0 : N.find((X) => X.id === e)), v;
521
+ }) ?? [];
522
+ }
523
+ o.value = l;
524
+ }
525
+ function ue(t, e) {
526
+ const m = e.filter((l) => l.id !== t);
527
+ o.value = m;
528
+ }
529
+ function oe() {
530
+ const t = (o.value ?? []).map((e) => ({
531
+ ...e,
532
+ type: Le.enum.SKU
533
+ }));
534
+ y.promptIngredientsBinding(
535
+ t,
536
+ (e) => o.value = e,
537
+ s.sku._id
538
+ );
539
+ }
540
+ return ke(
541
+ () => s.show,
542
+ (t) => {
543
+ t || (o.value = null, a.value = 0);
544
+ }
545
+ ), (t, e) => {
546
+ const m = B("FmTextField"), l = B("FmForm"), f = B("FmCard"), v = B("FmSwitch"), V = B("FmFormGroup"), N = B("FmSelect"), X = B("FmButton"), de = B("FmSideSheet");
547
+ return $(), z(de, {
548
+ "dismiss-away": "",
549
+ modelValue: u(T),
550
+ "onUpdate:modelValue": e[3] || (e[3] = (U) => je(T) ? T.value = U : null),
551
+ "max-width": 500
552
+ }, {
553
+ "side-sheet-header": D(() => [
554
+ n("div", Gt, [
555
+ n("div", Wt, k(u(b)("inventory.stock.convert.title", { name: t.sku.name })), 1)
556
+ ])
557
+ ]),
558
+ default: D(() => [
559
+ n("div", qt, [
560
+ g(l, {
561
+ ref_key: "formRef",
562
+ ref: P,
563
+ onValidationSuccess: j
564
+ }, {
565
+ default: D(() => [
566
+ g(m, {
567
+ disabled: i.value,
568
+ "model-value": a.value,
569
+ "onUpdate:modelValue": e[0] || (e[0] = (U) => a.value = U),
570
+ label: u(b)("inventory.stock.convert.amount"),
571
+ rules: [E, C, u(Me)(0)],
572
+ "append-text": w.value,
573
+ "helper-text": o.value ? void 0 : `Max ${t.maxCount} ${w.value}`
574
+ }, null, 8, ["disabled", "model-value", "label", "rules", "append-text", "helper-text"])
575
+ ]),
576
+ _: 1
577
+ }, 512),
578
+ g(f, {
579
+ variant: "outlined",
580
+ class: "p-16"
581
+ }, {
582
+ default: D(() => [
583
+ n("div", Jt, [
584
+ n("div", Qt, k(u(b)("inventory.stock.convert.deductionSummary")), 1),
585
+ ($(!0), O(ne, null, ae(M.value, (U) => {
586
+ var G, J;
587
+ return $(), O("div", {
588
+ key: (G = U.sku) == null ? void 0 : G._id,
589
+ class: "flex items-center"
590
+ }, [
591
+ n("div", Xt, k((J = U.sku) == null ? void 0 : J.name), 1),
592
+ n("div", Zt, " -" + k(U.convertAmount) + " " + k(U.abbrev), 1)
593
+ ]);
594
+ }), 128))
595
+ ])
596
+ ]),
597
+ _: 1
598
+ }),
599
+ g(f, { variant: "outlined" }, {
600
+ default: D(() => [
601
+ n("div", en, [
602
+ g(v, {
603
+ value: "",
604
+ modelValue: _.value,
605
+ "onUpdate:modelValue": e[1] || (e[1] = (U) => _.value = U),
606
+ label: u(b)("inventory.stock.convert.overrideDeduction"),
607
+ "label-placement": "right"
608
+ }, null, 8, ["modelValue", "label"]),
609
+ _.value ? ($(), O(ne, { key: 0 }, [
610
+ g(V, {
611
+ modelValue: o.value,
612
+ rules: [u(ct)(1, "Must have at least one ingredient binding")]
613
+ }, null, 8, ["modelValue", "rules"]),
614
+ n("div", tn, [
615
+ n("div", nn, k(u(b)("inventory.stock.convert.ingredients")), 1),
616
+ ($(!0), O(ne, null, ae(o.value, (U) => ($(), z(V, {
617
+ key: U.id,
618
+ disabled: i.value,
619
+ modelValue: +u(ie)(U.amount ?? { amount: 1, precision: 0 }),
620
+ rules: [
621
+ u(dt)(
622
+ S.value.find((G) => G._id === U.id).unit,
623
+ U.measurement
624
+ ),
625
+ u(Me)(0)
626
+ ]
627
+ }, {
628
+ default: D(({ invalid: G }) => {
629
+ var J, Z, W;
630
+ return [
631
+ n("div", on, [
632
+ n("div", sn, k((J = S.value.find((se) => se._id === U.id)) == null ? void 0 : J.name), 1),
633
+ g(m, {
634
+ class: "xs:col-span-2",
635
+ disabled: i.value,
636
+ modelValue: +u(ie)(
637
+ U.amount ?? { amount: 1, precision: 0 }
638
+ ),
639
+ "onUpdate:modelValue": (se) => Y(U.id, se, o.value ?? []),
640
+ invalid: G
641
+ }, null, 8, ["disabled", "modelValue", "onUpdate:modelValue", "invalid"]),
642
+ g(N, {
643
+ disabled: i.value,
644
+ class: "translate-y-[2px]",
645
+ items: L(U.id),
646
+ "model-value": (W = R(U.id, (Z = U.measurement) == null ? void 0 : Z.id)) == null ? void 0 : W.value,
647
+ "onUpdate:modelValue": (se) => K(U.id, se, o.value ?? []),
648
+ invalid: G
649
+ }, {
650
+ "helper-text": D(() => e[4] || (e[4] = [])),
651
+ _: 2
652
+ }, 1032, ["disabled", "items", "model-value", "onUpdate:modelValue", "invalid"]),
653
+ g(X, {
654
+ disabled: i.value,
655
+ type: "button",
656
+ variant: "tertiary",
657
+ icon: "delete",
658
+ onClick: (se) => ue(U.id, o.value ?? [])
659
+ }, null, 8, ["disabled", "onClick"])
660
+ ])
661
+ ];
662
+ }),
663
+ _: 2
664
+ }, 1032, ["disabled", "modelValue", "rules"]))), 128))
665
+ ]),
666
+ n("div", null, [
667
+ g(X, {
668
+ icon: "link",
669
+ label: u(b)("inventory.stock.convert.linkIngredient"),
670
+ variant: "plain",
671
+ onClick: oe
672
+ }, null, 8, ["label"])
673
+ ])
674
+ ], 64)) : te("", !0)
675
+ ])
676
+ ]),
677
+ _: 1
678
+ })
679
+ ])
680
+ ]),
681
+ "side-sheet-footer": D(() => [
682
+ n("div", an, [
683
+ g(X, {
684
+ loading: i.value,
685
+ label: u(b)("inventory.stock.convert.convertButton"),
686
+ onClick: e[2] || (e[2] = (U) => {
687
+ var G, J;
688
+ return (J = (G = P.value) == null ? void 0 : G.validateInputs) == null ? void 0 : J.call(G);
689
+ })
690
+ }, null, 8, ["loading", "label"])
691
+ ])
692
+ ]),
693
+ _: 1
694
+ }, 8, ["modelValue"]);
695
+ };
696
+ }
697
+ });
698
+ function Ae(p, h) {
699
+ const r = ge(p, h);
700
+ return { ...r, amount: -r.amount };
701
+ }
702
+ function We(p, h) {
703
+ return ge(Math.abs(p), h);
704
+ }
705
+ const Ve = {
706
+ [ee.enum.DAMAGE]: {
707
+ label: "Waste",
708
+ toAdjustmentAmount: Ae
709
+ },
710
+ [ee.enum.THEFT]: {
711
+ label: "Theft",
712
+ toAdjustmentAmount: Ae
713
+ },
714
+ [ee.enum.LOSE]: {
715
+ label: "Lose",
716
+ toAdjustmentAmount: Ae
717
+ },
718
+ [ee.enum.EXTRA]: {
719
+ label: "Extra",
720
+ toAdjustmentAmount: We
721
+ },
722
+ [ee.enum.PURCHASE]: {
723
+ label: "Purchase",
724
+ toAdjustmentAmount: We
725
+ }
726
+ }, ln = { class: "col-span-2 flex" }, un = { class: "fm-typo-en-body-lg-600 flex-1" }, cn = /* @__PURE__ */ re({
727
+ __name: "AdjustedItemForm",
728
+ props: {
729
+ modelValue: {},
730
+ disabled: { type: Boolean }
731
+ },
732
+ emits: ["update:modelValue", "click:delete"],
733
+ setup(p, { emit: h }) {
734
+ const r = p, s = h, x = I(
735
+ () => Object.keys(Ve).map((a) => ({
736
+ label: pt(a),
737
+ value: a
738
+ }))
739
+ ), y = I(() => tt(r.modelValue.doc.unit, !0)), c = I({
740
+ get() {
741
+ return r.modelValue.type ?? ee.enum.PURCHASE;
742
+ },
743
+ set(a) {
744
+ const o = {
745
+ ...r.modelValue
746
+ };
747
+ o.type = a;
748
+ const S = ze(r.modelValue.amount);
749
+ o.amount = Ve[o.type].toAdjustmentAmount(
750
+ +ie(S),
751
+ S.precision
752
+ ), s("update:modelValue", o);
753
+ }
754
+ }), d = I({
755
+ get() {
756
+ const a = ze(r.modelValue.amount);
757
+ return +ie(a);
758
+ },
759
+ set(a) {
760
+ const o = {
761
+ ...r.modelValue
762
+ }, S = ve(a);
763
+ o.amount = Ve[c.value].toAdjustmentAmount(
764
+ a,
765
+ S.precision
766
+ ), s("update:modelValue", o);
767
+ }
768
+ }), F = I({
769
+ get() {
770
+ var a;
771
+ return ((a = r.modelValue.measurement) == null ? void 0 : a.id) ?? null;
772
+ },
773
+ set(a) {
774
+ var S, A;
775
+ const o = {
776
+ ...r.modelValue
777
+ };
778
+ o.measurement = ((A = (S = r.modelValue.doc.unit) == null ? void 0 : S.measurements) == null ? void 0 : A.find((_) => _.id === a)) ?? null, s("update:modelValue", o);
779
+ }
780
+ }), b = I({
781
+ get() {
782
+ return r.modelValue.remark ?? "";
783
+ },
784
+ set(a) {
785
+ const o = {
786
+ ...r.modelValue
787
+ };
788
+ o.remark = a, s("update:modelValue", o);
789
+ }
790
+ });
791
+ return (a, o) => {
792
+ const S = B("FmButton"), A = B("FmSelect"), _ = B("FmTextarea"), i = B("FmCard");
793
+ return $(), z(i, {
794
+ variant: "outlined",
795
+ class: "grid grid-cols-2 gap-8 p-16"
796
+ }, {
797
+ default: D(() => [
798
+ n("div", ln, [
799
+ n("div", un, k(a.modelValue.doc.name), 1),
800
+ g(S, {
801
+ variant: "tertiary",
802
+ "prepend-icon": "delete",
803
+ onClick: o[0] || (o[0] = (j) => s("click:delete"))
804
+ })
805
+ ]),
806
+ g(A, {
807
+ disabled: a.disabled,
808
+ class: "col-span-2",
809
+ label: "Type",
810
+ items: x.value,
811
+ modelValue: c.value,
812
+ "onUpdate:modelValue": o[1] || (o[1] = (j) => c.value = j),
813
+ rules: [u(vt)()],
814
+ "label-mark": "required"
815
+ }, null, 8, ["disabled", "items", "modelValue", "rules"]),
816
+ g(Tt, {
817
+ disabled: a.disabled,
818
+ label: "Amount",
819
+ step: +u(ie)({
820
+ amount: 1,
821
+ precision: u(Ce)(a.modelValue.doc.unit, a.modelValue.measurement)
822
+ }),
823
+ modelValue: d.value,
824
+ "onUpdate:modelValue": o[2] || (o[2] = (j) => d.value = j),
825
+ rules: [u(Me)(0)]
826
+ }, null, 8, ["disabled", "step", "modelValue", "rules"]),
827
+ g(A, {
828
+ disabled: a.disabled,
829
+ label: "Unit",
830
+ items: y.value,
831
+ modelValue: F.value,
832
+ "onUpdate:modelValue": o[3] || (o[3] = (j) => F.value = j)
833
+ }, null, 8, ["disabled", "items", "modelValue"]),
834
+ g(_, {
835
+ class: "col-span-2",
836
+ disabled: a.disabled,
837
+ label: "Remark",
838
+ modelValue: b.value,
839
+ "onUpdate:modelValue": o[4] || (o[4] = (j) => b.value = j),
840
+ "label-mark": "optional"
841
+ }, null, 8, ["disabled", "modelValue"])
842
+ ]),
843
+ _: 1
844
+ });
845
+ };
846
+ }
847
+ }), dn = { class: "flex items-center" }, mn = { class: "fm-typo-en-title-md-800" }, pn = { class: "flex items-center" }, vn = { class: "fm-typo-en-title-sm-800 flex-1" }, fn = { class: "flex gap-8" }, yn = /* @__PURE__ */ re({
848
+ __name: "AdjustSkuDialog",
849
+ props: {
850
+ stock: {},
851
+ show: { type: Boolean }
852
+ },
853
+ emits: ["update:show", "submitted"],
854
+ setup(p, { expose: h, emit: r }) {
855
+ const s = p, x = r, y = Ie(), c = nt(), d = Te(), F = fe(), b = H(!1), { t: a } = le();
856
+ function o() {
857
+ i(Ue(_));
858
+ }
859
+ const S = H();
860
+ h({
861
+ validateInputs: () => {
862
+ var C, w;
863
+ (w = (C = S.value) == null ? void 0 : C.validateInputs) == null || w.call(C);
864
+ },
865
+ resetInputsValidation: () => {
866
+ var C, w;
867
+ (w = (C = S.value) == null ? void 0 : C.resetInputsValidation) == null || w.call(C);
868
+ },
869
+ resetInputs: () => {
870
+ var C, w;
871
+ (w = (C = S.value) == null ? void 0 : C.resetInputs) == null || w.call(C);
872
+ }
873
+ });
874
+ const A = Re(s, "show"), _ = at({
875
+ remark: "",
876
+ adjustments: [
877
+ {
878
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
879
+ type: ee.enum.PURCHASE,
880
+ doc: s.stock,
881
+ measurement: null,
882
+ remark: "",
883
+ amount: ve(1)
884
+ }
885
+ ]
886
+ });
887
+ ke([() => s.show], ([C]) => {
888
+ C && (_.remark = "", _.adjustments = [
889
+ {
890
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
891
+ type: ee.enum.PURCHASE,
892
+ doc: s.stock,
893
+ measurement: null,
894
+ remark: "",
895
+ amount: ve(1)
896
+ }
897
+ ]);
898
+ });
899
+ async function i(C) {
900
+ b.value = !0;
901
+ try {
902
+ await d.adjustSku({
903
+ remark: C.remark,
904
+ adjustments: C.adjustments.map(({ doc: w, remark: M, type: P, amount: T, measurement: Q }) => ({
905
+ id: w._id,
906
+ amount: T,
907
+ measurement: Q,
908
+ remark: M,
909
+ doc: w,
910
+ type: P
911
+ }))
912
+ }), x("update:show", !1), x("submitted");
913
+ } catch (w) {
914
+ F.open({
915
+ title: a("inventory.stock.adjust.error.title"),
916
+ message: a("inventory.stock.adjust.error.message"),
917
+ type: "error"
918
+ }), console.log("error on adjust ingredients", C, w);
919
+ } finally {
920
+ b.value = !1;
921
+ }
922
+ }
923
+ function j() {
924
+ const C = y.skus.map((M) => ({
925
+ label: M.name,
926
+ sublabel: M.code,
927
+ value: M._id
928
+ })), w = C.filter((M) => _.adjustments.find((P) => P.doc._id === M.value)).map((M) => M.value);
929
+ c.open({
930
+ title: "Select ingredients",
931
+ contentComponent: ft,
932
+ contentComponentProps: {
933
+ items: C,
934
+ modelValue: w
935
+ },
936
+ overlay: !0,
937
+ closeButton: !0,
938
+ dismissAway: !0,
939
+ primaryActions: {
940
+ text: "Confirm",
941
+ close: !0
942
+ },
943
+ secondaryActions: {
944
+ text: "Close",
945
+ close: !0,
946
+ variant: "tertiary"
947
+ }
948
+ }).onPrimary((M) => {
949
+ _.adjustments = M.map(
950
+ (P) => _.adjustments.find((T) => T.doc._id === P) ?? {
951
+ id: `sku_${(/* @__PURE__ */ new Date()).toISOString()}_${Math.random().toString(16).slice(2, 8)}`,
952
+ type: ee.enum.PURCHASE,
953
+ doc: y.skus.find((T) => T._id === P),
954
+ measurement: null,
955
+ remark: "",
956
+ amount: ve(1)
957
+ }
958
+ );
959
+ });
960
+ }
961
+ function E(C) {
962
+ _.adjustments.splice(C, 1);
963
+ }
964
+ return (C, w) => {
965
+ const M = B("FmTextarea"), P = B("FmButton"), T = B("FmForm"), Q = B("FmSideSheet");
966
+ return $(), z(Q, {
967
+ modelValue: u(A),
968
+ "onUpdate:modelValue": w[2] || (w[2] = (Y) => je(A) ? A.value = Y : null),
969
+ "dismiss-away": "",
970
+ "max-width": 500
971
+ }, {
972
+ "side-sheet-header": D(() => [
973
+ n("div", dn, [
974
+ n("div", mn, k(u(a)("inventory.stock.adjust.title")), 1)
975
+ ])
976
+ ]),
977
+ default: D(() => [
978
+ g(T, {
979
+ class: "w-full flex flex-col gap-12",
980
+ ref_key: "formRef",
981
+ ref: S,
982
+ onValidationSuccess: o
983
+ }, {
984
+ default: D(() => [
985
+ g(M, {
986
+ label: u(a)("inventory.stock.adjust.remark"),
987
+ modelValue: _.remark,
988
+ "onUpdate:modelValue": w[0] || (w[0] = (Y) => _.remark = Y)
989
+ }, null, 8, ["label", "modelValue"]),
990
+ n("div", pn, [
991
+ n("div", vn, k(u(a)("inventory.stock.adjust.adjustedItems")), 1),
992
+ g(P, {
993
+ "prepend-icon": "add",
994
+ variant: "tertiary",
995
+ size: "md",
996
+ onClick: j
997
+ })
998
+ ]),
999
+ ($(!0), O(ne, null, ae(_.adjustments, (Y, L) => ($(), z(cn, {
1000
+ key: Y.id,
1001
+ modelValue: _.adjustments[L],
1002
+ "onUpdate:modelValue": (R) => _.adjustments[L] = R,
1003
+ "onClick:delete": (R) => E(L)
1004
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "onClick:delete"]))), 128))
1005
+ ]),
1006
+ _: 1
1007
+ }, 512)
1008
+ ]),
1009
+ "side-sheet-footer": D(() => [
1010
+ n("div", fn, [
1011
+ g(P, {
1012
+ label: u(a)("inventory.stock.adjust.adjustButton"),
1013
+ loading: b.value,
1014
+ onClick: w[1] || (w[1] = (Y) => {
1015
+ var L, R;
1016
+ return (R = (L = S.value) == null ? void 0 : L.validateInputs) == null ? void 0 : R.call(L);
1017
+ })
1018
+ }, null, 8, ["label", "loading"])
1019
+ ])
1020
+ ]),
1021
+ _: 1
1022
+ }, 8, ["modelValue"]);
1023
+ };
1024
+ }
1025
+ }), _n = yt((p, h) => ({
1026
+ // TODO: remove once latest inventory backend has been push
1027
+ async findBillsByBusinessId(r, s, x) {
1028
+ const y = `${p.businessesBackendUrl}/${r}/reports/find-many`, c = {
1029
+ // type: TYPE.bill,
1030
+ type: "bill",
1031
+ restaurantIds: s,
1032
+ ids: x
1033
+ };
1034
+ return await h.post(y, c);
1035
+ },
1036
+ async findBillsById(r) {
1037
+ const x = ce().currentLocationDBName, y = `${p.inventoryBackendUrl}/${x}/bill/search`, c = {
1038
+ ids: r
1039
+ };
1040
+ return await h.post(y, c);
1041
+ }
1042
+ })), hn = { class: "p-16" }, kn = { class: "fm-typo-en-body-md-600 flex-grow" }, gn = { class: "flex-grow text-fm-color-typo-secondary" }, bn = {
1043
+ key: 0,
1044
+ class: "my-5"
1045
+ }, xn = { class: "text-neutral-400" }, Sn = { class: "flex-grow" }, wn = { class: "flex gap-1" }, Fn = { class: "flex flex-col gap-1" }, $n = {
1046
+ key: 1,
1047
+ class: "t-system text-fsecondary"
1048
+ }, An = {
1049
+ key: 0,
1050
+ class: "shrink-0 text-fm-color-typo-secondary"
1051
+ }, Vn = /* @__PURE__ */ re({
1052
+ __name: "StockRecordCard",
1053
+ props: {
1054
+ record: {},
1055
+ sku: {},
1056
+ bills: { default: () => [] }
1057
+ },
1058
+ setup(p) {
1059
+ const h = p, r = H(!1), s = H(), x = H(null), y = I(() => x.value === null ? "unset" : r.value ? `${x.value}px` : "0px");
1060
+ qe(() => {
1061
+ var b;
1062
+ x.value = ((b = s.value) == null ? void 0 : b.scrollHeight) || 0;
1063
+ });
1064
+ const c = I(() => {
1065
+ var _;
1066
+ const b = h.record.adjustments, a = h.sku, o = {}, A = b.flatMap((i) => {
1067
+ var j;
1068
+ return ((j = i.skus) == null ? void 0 : j.filter((E) => E.sku._id === a._id)) ?? [];
1069
+ }).flatMap((i) => i.amounts);
1070
+ for (const i of A) {
1071
+ const j = i.measurement ? _t(i.measurement.conversion, i.amount) : i.amount;
1072
+ o[_ = i.type] ?? (o[_] = { amount: 0, precision: 0 }), o[i.type] = Qe(j, o[i.type]);
1073
+ }
1074
+ return Object.entries(o).reduce(
1075
+ (i, [j, E]) => (i[j] = /// comment, because without it formatter makes code uglier
1076
+ `${q.toFormatString({
1077
+ value: E,
1078
+ precision: 4
1079
+ })} ${a.unit.abbrev}`, i),
1080
+ {}
1081
+ );
1082
+ }), { t: d } = le(), F = I(() => h.record.adjustmentsByTime.map(({ date: b, adjustments: a }) => ({
1083
+ time: ht(new Date(b)),
1084
+ adjustments: a.flatMap(
1085
+ (o) => {
1086
+ var S, A;
1087
+ return ((A = (S = o.skus) == null ? void 0 : S.map) == null ? void 0 : A.call(S, (_) => ({
1088
+ ..._,
1089
+ ref: o.ref,
1090
+ backdateFrom: o.effectiveAt != null ? et(o._id) : null
1091
+ }))) ?? [];
1092
+ }
1093
+ ).flatMap((o) => {
1094
+ var _;
1095
+ const S = (_ = h.bills.find((i) => i._id === o.ref)) == null ? void 0 : _.seqNumber, A = S ? d("inventory.stock.record.bill", [S]) : "";
1096
+ return o.amounts.map((i) => {
1097
+ var j;
1098
+ return {
1099
+ amount: `${q.toFormatString({ value: i.amount, precision: 4 })} ${((j = i.measurement) == null ? void 0 : j.abbrev) ?? o.sku.unit.abbrev}`,
1100
+ backdateFrom: o.backdateFrom,
1101
+ name: i.type,
1102
+ remark: i.remark || A || "",
1103
+ cost: i.cost
1104
+ };
1105
+ });
1106
+ })
1107
+ })));
1108
+ return (b, a) => {
1109
+ const o = B("FmIcon"), S = B("FmTooltip"), A = B("FmCard");
1110
+ return $(), z(A, { variant: "outlined" }, {
1111
+ default: D(() => [
1112
+ n("div", hn, [
1113
+ n("div", {
1114
+ class: "flex items-center cursor-pointer mb-1",
1115
+ onClick: a[0] || (a[0] = (_) => r.value = !r.value)
1116
+ }, [
1117
+ n("div", kn, k(b.record.date), 1),
1118
+ g(o, {
1119
+ name: r.value ? "expand_more" : "expand_less",
1120
+ color: "#777777",
1121
+ size: "md"
1122
+ }, null, 8, ["name"])
1123
+ ]),
1124
+ ($(!0), O(ne, null, ae(c.value, (_, i) => ($(), O("div", {
1125
+ key: i,
1126
+ class: "flex flex-row py-1",
1127
+ style: { "font-size": "0.8rem" }
1128
+ }, [
1129
+ n("div", gn, k(u(d)(`inventory.inventoryAdjustment.type.${i}`)), 1),
1130
+ n("div", {
1131
+ class: he({
1132
+ "text-fm-color-typo-error": _.startsWith("-"),
1133
+ "text-fm-color-typo-success": !_.startsWith("-"),
1134
+ "ml-auto": !0
1135
+ })
1136
+ }, k(_), 3)
1137
+ ]))), 128)),
1138
+ n("div", {
1139
+ ref_key: "detailRef",
1140
+ ref: s,
1141
+ style: Je({
1142
+ fontSize: "0.8rem",
1143
+ maxHeight: y.value,
1144
+ overflow: "hidden",
1145
+ transition: "max-height 0.2s ease-out"
1146
+ })
1147
+ }, [
1148
+ F.value.length ? ($(), O("hr", bn)) : te("", !0),
1149
+ ($(!0), O(ne, null, ae(F.value, (_) => ($(), O("div", {
1150
+ key: _.time,
1151
+ class: "flex gap-1 w-full"
1152
+ }, [
1153
+ n("div", xn, k(_.time), 1),
1154
+ n("div", Sn, [
1155
+ ($(!0), O(ne, null, ae(_.adjustments, (i) => ($(), O("div", {
1156
+ key: i.name,
1157
+ class: "flex gap-1"
1158
+ }, [
1159
+ n("div", wn, [
1160
+ pe(k(u(d)(`inventory.inventoryAdjustment.type.${i.name}`)) + " ", 1),
1161
+ i.backdateFrom ? ($(), z(S, {
1162
+ key: 0,
1163
+ variant: "plain",
1164
+ placement: "top",
1165
+ "z-index": 50
1166
+ }, {
1167
+ content: D(() => [
1168
+ n("div", Fn, k(u(d)("inventory.stock.record.backdate", [u(Xe)(new Date(i.backdateFrom))])), 1)
1169
+ ]),
1170
+ default: D(() => [
1171
+ g(o, {
1172
+ name: "info",
1173
+ size: "sm",
1174
+ color: "primary"
1175
+ })
1176
+ ]),
1177
+ _: 2
1178
+ }, 1024)) : te("", !0),
1179
+ i.remark ? ($(), O("span", $n, " # " + k(i.remark), 1)) : te("", !0)
1180
+ ]),
1181
+ n("div", {
1182
+ class: he({
1183
+ "text-fm-color-typo-error": i.amount.startsWith("-"),
1184
+ "text-fm-color-typo-success": !i.amount.startsWith("-"),
1185
+ "ml-auto": !0
1186
+ })
1187
+ }, k(i.amount), 3),
1188
+ i.cost ? ($(), O("div", An, " (" + k(u(De)(i.cost, !1, i.cost.precision)) + ") ", 1)) : te("", !0)
1189
+ ]))), 128))
1190
+ ])
1191
+ ]))), 128))
1192
+ ], 4)
1193
+ ])
1194
+ ]),
1195
+ _: 1
1196
+ });
1197
+ };
1198
+ }
1199
+ });
1200
+ function Cn(p, h) {
1201
+ var y;
1202
+ const r = Object.keys(ee.enum).reduce(
1203
+ (c, d) => (c[d] = { amount: 0, precision: 0 }, c),
1204
+ {}
1205
+ );
1206
+ if (!h)
1207
+ return Object.entries(r).reduce(
1208
+ (c, [d]) => (c[d] = q.fromNumber(0), c),
1209
+ {}
1210
+ );
1211
+ const x = p.flatMap((c) => {
1212
+ var d;
1213
+ return ((d = c.skus) == null ? void 0 : d.filter((F) => F.sku._id === h._id)) ?? [];
1214
+ }).flatMap((c) => c.amounts);
1215
+ for (const c of x) {
1216
+ const d = c.measurement ? q.multiply([c.measurement.conversion, c.amount]) : c.amount;
1217
+ r[y = c.type] ?? (r[y] = { amount: 0, precision: 0 }), r[c.type] = q.add([d, r[c.type]]);
1218
+ }
1219
+ return Object.entries(r).reduce(
1220
+ (c, [d, F]) => {
1221
+ const b = {
1222
+ ...F,
1223
+ amount: Math.abs(F.amount)
1224
+ };
1225
+ return c[d] = /// comment, because without it formatter makes code uglier
1226
+ `${q.toFormatString({
1227
+ value: b,
1228
+ precision: 4
1229
+ })} ${h.unit.abbrev}`, c;
1230
+ },
1231
+ {}
1232
+ );
1233
+ }
1234
+ function Mn(p, h) {
1235
+ if (!h)
1236
+ return null;
1237
+ let r = null;
1238
+ const x = p.flatMap((y) => {
1239
+ var c;
1240
+ return ((c = y.skus) == null ? void 0 : c.filter((d) => d.sku._id === h._id)) ?? [];
1241
+ }).flatMap((y) => {
1242
+ var c;
1243
+ return !y.history || ((c = y.history) == null ? void 0 : c.length) === 0 ? [] : y.history[0];
1244
+ });
1245
+ for (const y of x) {
1246
+ const c = y.amounts;
1247
+ for (const d of c) {
1248
+ if (d.type !== ee.Enum.SALES)
1249
+ continue;
1250
+ const F = d.measurement ? q.multiply([d.measurement.conversion, d.amount]) : d.amount;
1251
+ r ?? (r = q.fromNumber(0)), r = q.add([r, F]);
1252
+ }
1253
+ }
1254
+ return r != null ? (r.amount = Math.abs(r.amount), `${q.toFormatString({
1255
+ value: r,
1256
+ precision: 4
1257
+ })} ${h.unit.abbrev}`) : null;
1258
+ }
1259
+ const Dn = { class: "flex items-center w-full fm-typo-en-title-md-800" }, Bn = { class: "flex-1 line-clamp-2" }, jn = { class: "flex flex-col gap-32 w-full h-full" }, Un = { class: "flex items-center relative gap-4" }, In = { class: "flex-1" }, Pn = {
1260
+ key: 0,
1261
+ class: "flex-1 flex flex-col items-center gap-16"
1262
+ }, Tn = { class: "fm-typo-en-body-lg-400 translate-x-4" }, Rn = {
1263
+ key: 1,
1264
+ class: "flex flex-col gap-12"
1265
+ }, Hn = { class: "pb-16" }, En = { class: "fm-typo-cn-body-lg-600" }, On = {
1266
+ class: "grid gap-12 fm-typo-en-body-md-400",
1267
+ style: { "grid-template-columns": "auto auto auto", "grid-auto-rows": "1fr" }
1268
+ }, Ln = { class: "flex flex-col gap-1" }, zn = { class: "text-fm-color-typo-secondary" }, Nn = { class: "font-bold" }, Yn = { class: "flex flex-col gap-1" }, Kn = { class: "text-fm-color-typo-secondary flex" }, Gn = { class: "font-bold" }, Wn = { class: "flex flex-col gap-1" }, qn = { class: "text-fm-color-typo-secondary" }, Jn = { class: "font-bold" }, Qn = { class: "flex flex-col gap-1" }, Xn = { class: "text-fm-color-typo-secondary" }, Zn = { class: "font-bold" }, eo = { class: "flex flex-col gap-1" }, to = { class: "text-fm-color-typo-secondary" }, no = { class: "font-bold" }, oo = { class: "flex flex-col gap-1" }, so = { class: "text-fm-color-typo-secondary" }, ao = { class: "font-bold" }, ro = { class: "flex flex-col gap-1" }, lo = { class: "text-fm-color-typo-secondary" }, io = { class: "font-bold" }, uo = { class: "flex flex-col gap-1" }, co = { class: "text-fm-color-typo-secondary" }, mo = { class: "font-bold" }, po = { class: "flex flex-col gap-1" }, vo = { class: "text-fm-color-typo-secondary" }, fo = { class: "font-bold" }, yo = {
1269
+ key: 0,
1270
+ class: "flex flex-col gap-8"
1271
+ }, _o = { class: "flex" }, ho = { class: "flex-1 flex flex-col gap-1" }, ko = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, go = { class: "font-bold" }, bo = { class: "flex-1 flex flex-col gap-1" }, xo = { class: "flex gap-1 items-center text-fm-color-typo-secondary" }, So = { class: "flex flex-col gap-1" }, wo = { class: "font-bold" }, Fo = {
1272
+ key: 2,
1273
+ class: "flex-1 flex flex-col items-center gap-8"
1274
+ }, $o = ["src"], Ao = { class: "font-bold text-lg" }, Vo = { class: "text-xs text-neutral-400 text-center" }, Co = /* @__PURE__ */ re({
1275
+ __name: "StockHistory",
1276
+ props: {
1277
+ sku: {},
1278
+ show: { type: Boolean }
1279
+ },
1280
+ emits: ["update:show"],
1281
+ setup(p) {
1282
+ const h = jt(), r = Pe(), s = Te(), x = _n(), y = ce(), c = bt(), { t: d } = le(), F = p, b = H(!1), a = fe(), o = H(kt(0));
1283
+ async function S() {
1284
+ b.value = !0;
1285
+ try {
1286
+ await C(), await r.readStockBalance();
1287
+ } catch (t) {
1288
+ a.open({
1289
+ title: "Something went wrong",
1290
+ message: "Cannot fetch stock history. Please try again.",
1291
+ type: "error"
1292
+ }), console.log("failed at fetching item adjustment history", F.sku, o, t);
1293
+ } finally {
1294
+ b.value = !1;
1295
+ }
1296
+ }
1297
+ qe(() => {
1298
+ S();
1299
+ }), ke([() => o.value, () => F.sku], () => {
1300
+ S();
1301
+ });
1302
+ const A = H([]), _ = H([]), i = H(new Array());
1303
+ function j(t, e) {
1304
+ return e === "day" ? $t(t) : Xe(t);
1305
+ }
1306
+ function E(t, e) {
1307
+ const m = t.reduce(
1308
+ (l, f) => {
1309
+ const v = f.effectiveAt ?? et(f._id);
1310
+ if (!v)
1311
+ return l;
1312
+ const V = j(new Date(v), e);
1313
+ return l[V] ?? (l[V] = []), l[V].push(f), l;
1314
+ },
1315
+ {}
1316
+ );
1317
+ return Object.keys(m).map((l) => ({
1318
+ date: l,
1319
+ adjustments: m[l]
1320
+ }));
1321
+ }
1322
+ async function C() {
1323
+ let t = await s.readStockAdjustment(
1324
+ F.sku._id,
1325
+ xt(new Date(o.value.startDate)).toISOString(),
1326
+ St(new Date(o.value.endDate)).toISOString()
1327
+ );
1328
+ A.value = t;
1329
+ const e = t.filter(({ ref: m }) => m == null ? void 0 : m.startsWith("bill_")).map(({ ref: m }) => m);
1330
+ await w(e), _.value = E(t, "day").map(({ date: m, adjustments: l }) => ({
1331
+ date: m,
1332
+ adjustments: l,
1333
+ adjustmentsByTime: E(l, "minute")
1334
+ }));
1335
+ }
1336
+ async function w(t) {
1337
+ t.length && (i.value = await x.findBillsById(t).catch((e) => {
1338
+ var f;
1339
+ console.error("Error on using latest bill API, retrying using legacy api", e);
1340
+ const m = ((f = h.currentBusiness.value) == null ? void 0 : f._id) ?? "", l = y.currentLocation.doc._id;
1341
+ return x.findBillsByBusinessId(m, [l], t);
1342
+ }));
1343
+ }
1344
+ const M = I(() => {
1345
+ const t = A.value, e = F.sku;
1346
+ return Cn(t, e);
1347
+ }), P = I(() => {
1348
+ const t = A.value, e = F.sku;
1349
+ return Mn(t, e);
1350
+ }), T = I(() => {
1351
+ const t = [...A.value].computeFirst((m) => {
1352
+ var f, v;
1353
+ const l = (v = (f = m.skus) == null ? void 0 : f.find) == null ? void 0 : v.call(f, (V) => V.sku._id === F.sku._id);
1354
+ return l == null ? void 0 : l.fromBalance;
1355
+ }) ?? {
1356
+ amount: 0,
1357
+ precision: 0
1358
+ }, e = F.sku;
1359
+ return e ? `${q.toFormatString({
1360
+ value: t,
1361
+ precision: 4
1362
+ })} ${e.unit.abbrev}` : "";
1363
+ }), Q = I(() => {
1364
+ const t = [...A.value].reverse().computeFirst((m) => {
1365
+ var f, v;
1366
+ const l = (v = (f = m.skus) == null ? void 0 : f.find) == null ? void 0 : v.call(f, (V) => V.sku._id === F.sku._id);
1367
+ return l == null ? void 0 : l.toBalance;
1368
+ }) ?? {
1369
+ amount: 0,
1370
+ precision: 0
1371
+ }, e = F.sku;
1372
+ return e ? `${q.toFormatString({ value: t, precision: 4 })} ${e.unit.abbrev}` : "";
1373
+ });
1374
+ function Y(t) {
1375
+ switch (t) {
1376
+ case Fe.MY:
1377
+ return "MYR";
1378
+ case Fe.SG:
1379
+ return "SGD";
1380
+ case Fe.ID:
1381
+ return "IDR";
1382
+ default:
1383
+ return "MYR";
1384
+ }
1385
+ }
1386
+ const L = I(() => {
1387
+ var m;
1388
+ const e = A.value.flatMap((l) => {
1389
+ var f;
1390
+ return ((f = l.skus) == null ? void 0 : f.flatMap((v) => v.amounts)) ?? [];
1391
+ }).filter((l) => l.amount.amount < 0).reduce(
1392
+ (l, f) => {
1393
+ const v = f.cost;
1394
+ if (!v) return l;
1395
+ const V = {
1396
+ ...gt(l, Math.max(l.precision, v.precision)),
1397
+ currency: v.currency
1398
+ };
1399
+ return {
1400
+ ...Qe(V, v),
1401
+ currency: l.currency
1402
+ };
1403
+ },
1404
+ {
1405
+ amount: 0,
1406
+ precision: 0,
1407
+ currency: Y(((m = h.currentCountry) == null ? void 0 : m.value) ?? Ne)
1408
+ }
1409
+ );
1410
+ return De(e, !1, e.precision);
1411
+ });
1412
+ function R() {
1413
+ const { startDate: t, endDate: e } = wt(o.value);
1414
+ t !== null && e !== null && (o.value = {
1415
+ startDate: t,
1416
+ endDate: e
1417
+ });
1418
+ }
1419
+ const K = I(() => {
1420
+ var m;
1421
+ const t = [...A.value].reverse().computeFirst((l) => {
1422
+ var v, V;
1423
+ const f = (V = (v = l.skus) == null ? void 0 : v.find) == null ? void 0 : V.call(v, (N) => N.sku._id === F.sku._id);
1424
+ return f == null ? void 0 : f.toCostBalances;
1425
+ });
1426
+ return t ? {
1427
+ ...t.reduce((l, f) => q.add([l, q.fromDinero(f.cost)]), {
1428
+ amount: 0,
1429
+ precision: 0
1430
+ }),
1431
+ currency: Y(((m = h.currentCountry) == null ? void 0 : m.value) ?? Ne)
1432
+ } : "No data";
1433
+ });
1434
+ function ue() {
1435
+ const { startDate: t, endDate: e } = Ft(o.value);
1436
+ t !== null && e !== null && (o.value = {
1437
+ startDate: t,
1438
+ endDate: e
1439
+ });
1440
+ }
1441
+ const oe = Re(F, "show");
1442
+ return (t, e) => {
1443
+ const m = B("FmButton"), l = B("FmField"), f = B("FmDateRangePicker"), v = B("FmSpacer"), V = B("FmCircularProgress"), N = B("FmIcon"), X = B("FmTooltip"), de = B("FmMenuDivider"), U = B("FmCardSection"), G = B("FmCard"), J = B("FmSideSheet");
1444
+ return $(), z(J, {
1445
+ "dismiss-away": "",
1446
+ modelValue: u(oe),
1447
+ "onUpdate:modelValue": e[4] || (e[4] = (Z) => je(oe) ? oe.value = Z : null),
1448
+ "close-button": !1,
1449
+ "max-width": 560
1450
+ }, {
1451
+ "side-sheet-header": D(() => [
1452
+ n("div", Dn, [
1453
+ n("div", Bn, k(u(d)("inventory.stock.history.title", [t.sku.name])), 1),
1454
+ g(m, {
1455
+ variant: "tertiary",
1456
+ "prepend-icon": "close",
1457
+ onClick: e[0] || (e[0] = (Z) => oe.value = !1)
1458
+ })
1459
+ ])
1460
+ ]),
1461
+ default: D(() => {
1462
+ var Z;
1463
+ return [
1464
+ n("div", jn, [
1465
+ n("div", Un, [
1466
+ n("div", In, [
1467
+ g(f, {
1468
+ modelValue: o.value,
1469
+ "onUpdate:modelValue": e[1] || (e[1] = (W) => o.value = W),
1470
+ "show-predefined-range": "",
1471
+ "start-label": "",
1472
+ "end-label": "",
1473
+ "z-index": 50
1474
+ }, {
1475
+ "trigger-button": D(({ opened: W }) => [
1476
+ g(l, {
1477
+ "prepend-icon": "calendar_month",
1478
+ focused: W
1479
+ }, {
1480
+ default: D(() => [
1481
+ pe(k(o.value.startDate) + " - " + k(o.value.endDate), 1)
1482
+ ]),
1483
+ _: 2
1484
+ }, 1032, ["focused"])
1485
+ ]),
1486
+ _: 1
1487
+ }, 8, ["modelValue"])
1488
+ ]),
1489
+ g(m, {
1490
+ variant: "tertiary",
1491
+ onClick: e[2] || (e[2] = (W) => R()),
1492
+ "prepend-icon": "navigate_before"
1493
+ }),
1494
+ g(m, {
1495
+ variant: "tertiary",
1496
+ onClick: e[3] || (e[3] = (W) => ue()),
1497
+ "prepend-icon": "navigate_next"
1498
+ })
1499
+ ]),
1500
+ b.value ? ($(), O("div", Pn, [
1501
+ g(v),
1502
+ g(V, { size: "xl" }),
1503
+ n("div", Tn, k(u(d)("inventory.stock.history.loading")), 1),
1504
+ g(v),
1505
+ g(v)
1506
+ ])) : _.value && ((Z = _.value) == null ? void 0 : Z.length) > 0 ? ($(), O("div", Rn, [
1507
+ g(G, { variant: "outlined" }, {
1508
+ default: D(() => [
1509
+ g(U, { class: "flex flex-col gap-4" }, {
1510
+ default: D(() => [
1511
+ n("div", Hn, [
1512
+ n("div", En, k(u(d)("inventory.stock.history.summary.title")), 1)
1513
+ ]),
1514
+ n("div", On, [
1515
+ n("div", Ln, [
1516
+ n("div", zn, k(u(d)("inventory.stock.history.summary.totalPurchase")), 1),
1517
+ n("div", Nn, k(M.value.PURCHASE), 1)
1518
+ ]),
1519
+ n("div", Yn, [
1520
+ n("div", Kn, [
1521
+ pe(k(u(d)("inventory.stock.history.summary.totalSales")) + "  ", 1),
1522
+ P.value != null ? ($(), z(X, {
1523
+ key: 0,
1524
+ variant: "plain",
1525
+ placement: "top",
1526
+ content: `Before: ${P.value}`,
1527
+ "z-index": 50
1528
+ }, {
1529
+ default: D(() => [
1530
+ g(N, {
1531
+ name: "warning",
1532
+ size: "sm"
1533
+ })
1534
+ ]),
1535
+ _: 1
1536
+ }, 8, ["content"])) : te("", !0)
1537
+ ]),
1538
+ n("div", Gn, k(M.value.SALES), 1)
1539
+ ]),
1540
+ n("div", Wn, [
1541
+ n("div", qn, k(u(d)("inventory.stock.history.summary.totalLose")), 1),
1542
+ n("div", Jn, k(M.value.LOSE), 1)
1543
+ ]),
1544
+ n("div", Qn, [
1545
+ n("div", Xn, k(u(d)("inventory.stock.history.summary.totalRequest")), 1),
1546
+ n("div", Zn, k(M.value.REQUEST), 1)
1547
+ ]),
1548
+ n("div", eo, [
1549
+ n("div", to, k(u(d)("inventory.stock.history.summary.totalReceive")), 1),
1550
+ n("div", no, k(M.value.RECEIVE), 1)
1551
+ ]),
1552
+ n("div", oo, [
1553
+ n("div", so, k(u(d)("inventory.stock.history.summary.totalConvert")), 1),
1554
+ n("div", ao, k(M.value.CONVERT), 1)
1555
+ ]),
1556
+ n("div", ro, [
1557
+ n("div", lo, k(u(d)("inventory.stock.history.summary.totalDamage")), 1),
1558
+ n("div", io, k(M.value.DAMAGE), 1)
1559
+ ]),
1560
+ n("div", uo, [
1561
+ n("div", co, k(u(d)("inventory.stock.history.summary.openingBalance")), 1),
1562
+ n("div", mo, k(T.value), 1)
1563
+ ]),
1564
+ n("div", po, [
1565
+ n("div", vo, k(u(d)("inventory.stock.history.summary.lastStockBalance")), 1),
1566
+ n("div", fo, k(Q.value), 1)
1567
+ ])
1568
+ ]),
1569
+ u(c).enableTotalCost ? ($(), O("div", yo, [
1570
+ g(de, { class: "w-full" }),
1571
+ n("div", _o, [
1572
+ n("div", ho, [
1573
+ g(Ke, { "z-index": 50 }, {
1574
+ default: D(() => [
1575
+ n("div", ko, [
1576
+ pe(k(u(d)("inventory.stock.history.estimatedValue")) + " ", 1),
1577
+ g(X, {
1578
+ variant: "plain",
1579
+ placement: "top",
1580
+ content: u(d)("inventory.stock.history.estimatedValueTooltip"),
1581
+ "z-index": 50
1582
+ }, {
1583
+ default: D(() => [
1584
+ g(N, {
1585
+ name: "help",
1586
+ size: "sm"
1587
+ })
1588
+ ]),
1589
+ _: 1
1590
+ }, 8, ["content"])
1591
+ ])
1592
+ ]),
1593
+ _: 1
1594
+ }),
1595
+ n("div", go, k(typeof K.value != "string" ? u(De)(K.value, !1, K.value.precision) : K.value), 1)
1596
+ ]),
1597
+ n("div", bo, [
1598
+ g(Ke, { "z-index": 50 }, {
1599
+ default: D(() => [
1600
+ n("div", xo, [
1601
+ pe(k(u(d)("inventory.stock.history.costSold")) + " ", 1),
1602
+ g(X, {
1603
+ variant: "plain",
1604
+ placement: "top",
1605
+ "z-index": 50
1606
+ }, {
1607
+ content: D(() => [
1608
+ n("div", So, k(u(d)("inventory.stock.history.costSoldTooltip")), 1)
1609
+ ]),
1610
+ default: D(() => [
1611
+ g(N, {
1612
+ name: "help",
1613
+ size: "sm"
1614
+ })
1615
+ ]),
1616
+ _: 1
1617
+ })
1618
+ ])
1619
+ ]),
1620
+ _: 1
1621
+ }),
1622
+ n("div", wo, k(L.value), 1)
1623
+ ])
1624
+ ])
1625
+ ])) : te("", !0)
1626
+ ]),
1627
+ _: 1
1628
+ })
1629
+ ]),
1630
+ _: 1
1631
+ }),
1632
+ e[5] || (e[5] = n("div", null, null, -1)),
1633
+ ($(!0), O(ne, null, ae(_.value, (W) => ($(), O(ne, {
1634
+ key: W.date
1635
+ }, [
1636
+ t.sku ? ($(), z(Vn, {
1637
+ key: 0,
1638
+ record: W,
1639
+ sku: t.sku,
1640
+ bills: i.value
1641
+ }, null, 8, ["record", "sku", "bills"])) : te("", !0)
1642
+ ], 64))), 128))
1643
+ ])) : ($(), O("div", Fo, [
1644
+ g(v),
1645
+ n("div", null, [
1646
+ n("img", {
1647
+ src: u(Rt),
1648
+ alt: "List is empty"
1649
+ }, null, 8, $o)
1650
+ ]),
1651
+ n("div", Ao, k(u(d)("inventory.stock.history.noRecords")), 1),
1652
+ n("div", Vo, k(u(d)("inventory.stock.history.changeDateRange")), 1),
1653
+ g(v),
1654
+ g(v)
1655
+ ]))
1656
+ ])
1657
+ ];
1658
+ }),
1659
+ _: 1
1660
+ }, 8, ["modelValue"]);
1661
+ };
1662
+ }
1663
+ }), Mo = { class: "flex flex-col gap-8" }, Do = { class: "flex flex-col" }, Bo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, jo = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary line-clamp-1" }, qo = /* @__PURE__ */ re({
1664
+ __name: "StockView",
1665
+ setup(p) {
1666
+ const { t: h } = le(), r = Ie(), s = ce(), x = Pe(), y = st(), c = Ze(), { columnDefs: d } = Yt();
1667
+ s.watchLocation(a);
1668
+ const F = H(!1), b = fe();
1669
+ async function a() {
1670
+ if (s._currentLocation) {
1671
+ F.value = !0;
1672
+ try {
1673
+ await x.readStockBalance(), await x.readProductBalance(), await c.readStockEstimateBalance();
1674
+ } catch (w) {
1675
+ b.open({
1676
+ title: h("inventory.stock.error.title"),
1677
+ message: h("inventory.stock.error.message"),
1678
+ type: "error"
1679
+ }), console.error("error on fetch stock balance", w);
1680
+ } finally {
1681
+ F.value = !1;
1682
+ }
1683
+ }
1684
+ }
1685
+ const o = I(
1686
+ () => r.skus.map((w) => {
1687
+ var Y, L, R;
1688
+ const M = w.trackingMeasurement;
1689
+ let P = (L = (Y = x.stockBalance.skus) == null ? void 0 : Y.find(
1690
+ (K) => K.id === w._id
1691
+ )) == null ? void 0 : L.balance, T = c.inventoryForecast.skus.find(
1692
+ (K) => K.id === w._id
1693
+ );
1694
+ return {
1695
+ ...w,
1696
+ balance: P ?? {
1697
+ amount: 0,
1698
+ precision: 0
1699
+ },
1700
+ day: (T == null ? void 0 : T.depletionDays) ?? void 0,
1701
+ trackingUnitAbbrev: M ? ((R = w.unit.measurements.find((K) => K.id === M)) == null ? void 0 : R.abbrev) ?? "" : w.unit.abbrev
1702
+ };
1703
+ })
1704
+ ), S = H(""), { breakpoints: A } = Ut(), _ = I(() => A.value.xs || A.value.sm), i = I(() => _.value ? 10 : 20), j = At(), E = I(() => [
1705
+ {
1706
+ label: "Refresh",
1707
+ value: "refresh"
1708
+ },
1709
+ {
1710
+ label: "Export",
1711
+ value: "export"
1712
+ }
1713
+ ]);
1714
+ function C(w) {
1715
+ switch (w) {
1716
+ case "refresh":
1717
+ return a();
1718
+ case "export":
1719
+ return Ot(o.value);
1720
+ }
1721
+ }
1722
+ return (w, M) => {
1723
+ const P = B("FmTable");
1724
+ return $(), z(Vt, {
1725
+ title: u(h)("inventory.stock.title"),
1726
+ actions: E.value,
1727
+ "onClick:action": C
1728
+ }, {
1729
+ default: D(() => {
1730
+ var T, Q, Y, L;
1731
+ return [
1732
+ n("div", {
1733
+ class: he([
1734
+ "flex flex-col gap-8 max-h-full",
1735
+ {
1736
+ "p-0": _.value,
1737
+ "px-24 ": !_.value
1738
+ }
1739
+ ])
1740
+ }, [
1741
+ g(Ct, {
1742
+ searchable: "",
1743
+ "change-location": "",
1744
+ search: S.value,
1745
+ "onUpdate:search": M[0] || (M[0] = (R) => S.value = R)
1746
+ }, null, 8, ["search"]),
1747
+ ($(), z(P, {
1748
+ style: Je(u(j).tableHeight),
1749
+ "column-defs": u(d),
1750
+ "row-data": o.value,
1751
+ "search-value": S.value,
1752
+ loading: F.value || !u(s)._currentLocation,
1753
+ key: (T = u(s)._currentLocation) == null ? void 0 : T.dbName,
1754
+ onRowClick: M[1] || (M[1] = (R) => u(y).showSkuHistory(R.original)),
1755
+ "page-size": i.value
1756
+ }, {
1757
+ "list-row": D((R) => [
1758
+ g(Mt, {
1759
+ row: R,
1760
+ onRowClick: u(y).showSkuHistory
1761
+ }, {
1762
+ default: D((K) => {
1763
+ var ue, oe, t, e, m, l, f, v, V, N;
1764
+ return [
1765
+ n("div", Mo, [
1766
+ n("div", Do, [
1767
+ n("div", Bo, [
1768
+ g(u(Ye), {
1769
+ render: (t = (oe = (ue = K.code) == null ? void 0 : ue.column) == null ? void 0 : oe.columnDef) == null ? void 0 : t.cell,
1770
+ props: (m = (e = K.code) == null ? void 0 : e.getContext) == null ? void 0 : m.call(e)
1771
+ }, null, 8, ["render", "props"])
1772
+ ]),
1773
+ n("div", jo, [
1774
+ g(u(Ye), {
1775
+ render: (v = (f = (l = K.name) == null ? void 0 : l.column) == null ? void 0 : f.columnDef) == null ? void 0 : v.cell,
1776
+ props: (N = (V = K.name) == null ? void 0 : V.getContext) == null ? void 0 : N.call(V)
1777
+ }, null, 8, ["render", "props"])
1778
+ ])
1779
+ ]),
1780
+ n("div", null, [
1781
+ g(Be, {
1782
+ days: R.original.day
1783
+ }, null, 8, ["days"])
1784
+ ]),
1785
+ n("div", null, [
1786
+ g(ot, {
1787
+ class: "xs:w-[160px]",
1788
+ unit: R.original.unit,
1789
+ sku: R.original,
1790
+ amount: R.original.balance,
1791
+ "default-tracking-measurement": R.original.trackingMeasurement ?? void 0
1792
+ }, null, 8, ["unit", "sku", "amount", "default-tracking-measurement"])
1793
+ ])
1794
+ ])
1795
+ ];
1796
+ }),
1797
+ _: 2
1798
+ }, 1032, ["row", "onRowClick"])
1799
+ ]),
1800
+ _: 1
1801
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
1802
+ ], 2),
1803
+ ($(), z(rt, { to: "body" }, [
1804
+ (Q = u(y).stockHistoryProps) != null && Q.sku ? ($(), z(Co, Se(we({ key: 0 }, u(y).stockHistoryProps)), null, 16)) : te("", !0),
1805
+ (Y = u(y).convertSkuDialogProps) != null && Y.sku ? ($(), z(rn, Se(we({ key: 1 }, u(y).convertSkuDialogProps)), null, 16)) : te("", !0),
1806
+ (L = u(y).adjustSkuDialogProps) != null && L.stock ? ($(), z(yn, Se(we({ key: 2 }, u(y).adjustSkuDialogProps)), null, 16)) : te("", !0)
1807
+ ]))
1808
+ ];
1809
+ }),
1810
+ _: 1
1811
+ }, 8, ["title", "actions"]);
1812
+ };
1813
+ }
1814
+ });
1815
+ export {
1816
+ qo as default
1817
+ };