@feedmepos/mf-inventory-portal 0.0.23-dev.36 → 0.0.23-dev.38

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