@feedmepos/mf-inventory-portal 0.0.19-dev.1 → 0.0.19-dev.3

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