@feedmepos/mf-inventory-portal 0.0.5 → 0.0.7-dev.1

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