@feedmepos/mf-inventory-portal 0.0.6 → 0.0.7-dev.2

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 (39) hide show
  1. package/dist/{ApprovalView-7XAT5-7o.js → ApprovalView-PgJmPjWr.js} +6 -6
  2. package/dist/{BindingsDialog-DgHuffxZ.js → BindingsDialog-Ch42kY-Z.js} +2 -2
  3. package/dist/{BindingsPicker-CdG1FKt3.js → BindingsPicker-CjKJb9Iu.js} +2 -2
  4. package/dist/{BindingsTable-DnhyMeyT.js → BindingsTable-PvwPN2Vu.js} +3 -3
  5. package/dist/{ChangeLocationComponent.vue_vue_type_script_setup_true_lang-aicACi6T.js → ChangeLocationComponent.vue_vue_type_script_setup_true_lang-Dyl7UXMT.js} +1 -1
  6. package/dist/{FmMultiselectDialog.vue_vue_type_script_setup_true_lang-BeCBc3ie.js → FmMultiselectDialog.vue_vue_type_script_setup_true_lang-BCUjOxSy.js} +2 -2
  7. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-DS9A38-m.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CDi5O9gb.js} +1 -1
  8. package/dist/{IngredientsView-CC2M-Oxt.js → IngredientsView--902oYCN.js} +35 -39
  9. package/dist/{IntegrationView-C0eXkb_X.js → IntegrationView-DzfSwX2I.js} +3 -3
  10. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-BqkpGRQG.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-jBbeI4Xr.js} +5 -5
  11. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DZshbzqT.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-VIcbJgay.js} +1 -1
  12. package/dist/{PurchaseOrderPrintPreview-BChxLASs.js → PurchaseOrderPrintPreview-sr4WLbNL.js} +1 -1
  13. package/dist/{ReceiveRequestView-B2T-K9on.js → ReceiveRequestView-B3n0s9JC.js} +11 -11
  14. package/dist/{RecipeView-DGS0-kll.js → RecipeView-DjHRoOJv.js} +58 -58
  15. package/dist/StockView-CtJ1iGfy.js +1807 -0
  16. package/dist/{SupplierView-C-qEfLPr.js → SupplierView-DXn13XBW.js} +7 -7
  17. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-BQvyTSZC.js → TransferDetails.vue_vue_type_script_setup_true_lang-BdTcFpfV.js} +5 -5
  18. package/dist/{UnitView-zTo6Jwgy.js → UnitView-DVrscPTQ.js} +190 -177
  19. package/dist/{WarehouseView-h92-OZ8y.js → WarehouseView-B1n-2vW4.js} +3 -3
  20. package/dist/api/stock.d.ts +0 -8
  21. package/dist/{app-D_R27XfK.js → app-D-4-R23d.js} +10467 -10461
  22. package/dist/app.js +1 -1
  23. package/dist/core.d.ts +3 -3
  24. package/dist/{date2-CsVyh2xw.js → date2-B0vvvXGT.js} +8 -8
  25. package/dist/{dayjs.min-DJF3Prun.js → dayjs.min-BJNynOI_.js} +145 -145
  26. package/dist/{decimal-esXdd4p7.js → decimal-MudMBQgK.js} +1 -1
  27. package/dist/{fuzzy-5drv5SZI.js → fuzzy-CToOYwhA.js} +1 -1
  28. package/dist/{init-date-range-BWVT2UgA.js → init-date-range-D5SkV2p4.js} +1 -1
  29. package/dist/{layout-Cf3iZuvk.js → layout-C7Dvo6EU.js} +1 -1
  30. package/dist/{rules-QzzL5oLu.js → rules-D4pouPya.js} +1 -1
  31. package/dist/{stock-estimate-DqJKQ1Jf.js → stock-estimate-Cpumo92_.js} +2 -2
  32. package/dist/style.css +1 -1
  33. package/dist/{supplier-Df899fpy.js → supplier-lu9adAbr.js} +1 -1
  34. package/dist/tsconfig.app.tsbuildinfo +1 -1
  35. package/dist/{use-inventory-binding-dialog-CYQrVeOf.js → use-inventory-binding-dialog-C-4l8D01.js} +2 -2
  36. package/dist/{xlsx-DqpZNivg.js → xlsx-BIvEkCPF.js} +1087 -1087
  37. package/package.json +4 -4
  38. package/dist/StockView-Byeg5Lmo.js +0 -1919
  39. package/dist/views/stock/components/StockRecalculateDialog.vue.d.ts +0 -9
@@ -1,1919 +0,0 @@
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 W, s as rt, d as Ne, a as it, C as Se, I as Xe } from "./app-D_R27XfK.js";
4
- import { useCoreStore as Je } 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-Cf3iZuvk.js";
7
- import { g as ge } from "./decimal-esXdd4p7.js";
8
- import { d as pt, F as Ye } from "./dayjs.min-DJF3Prun.js";
9
- import { e as ft, i as Qe, u as vt } from "./stock-estimate-DqJKQ1Jf.js";
10
- import { _ as yt } from "./ChangeLocationComponent.vue_vue_type_script_setup_true_lang-aicACi6T.js";
11
- import { g as Ce, a as Z, 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-CsVyh2xw.js";
12
- import { a as Be, A as Ft, M as Bt, R as At } from "./rules-QzzL5oLu.js";
13
- import { u as Vt, g as tt } from "./use-inventory-binding-dialog-CYQrVeOf.js";
14
- import { _ as Dt } from "./FmMultiselectDialog.vue_vue_type_script_setup_true_lang-BeCBc3ie.js";
15
- import { _ as Mt } from "./NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DZshbzqT.js";
16
- import { i as jt } from "./init-date-range-BWVT2UgA.js";
17
- import { E as Rt } from "./empty-placeholder-wf6-BWE8.js";
18
- const fe = We((c, l) => {
19
- const r = le(), o = Je(), 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, d = `${c.inventoryBackendUrl}/${g}/stock-balance`;
29
- return await l.get(d);
30
- },
31
- async readSkuBalance() {
32
- var S;
33
- const g = r.currentLocationDBName, d = `${c.inventoryBackendUrl}/${g}/sku/balance`;
34
- return (((S = o.currentBusiness.value) == null ? void 0 : S.menuVersion) ?? "") === "v3" ? await l.get(d) : await l.get(`${d}?useInventoryDoc=true`);
35
- },
36
- async readSingleAdjustment(g) {
37
- const d = r.currentLocationDBName, h = `${c.inventoryBackendUrl}/${d}/adjustment`;
38
- return await l.get(`${h}?adjustmentId=${g}`);
39
- },
40
- async readStockAdjustment(g, d, h) {
41
- const S = r.currentLocationDBName, p = `${c.inventoryBackendUrl}/${S}/sku`;
42
- return await l.get(`${p}?skuId=${g}&start=${d}&end=${h}`);
43
- },
44
- async convertSku(g) {
45
- var p;
46
- const d = r.currentLocationDBName, h = `${c.inventoryBackendUrl}/${d}/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 d = r.currentLocationDBName, h = `${c.inventoryBackendUrl}/${d}/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, d = `${c.inventoryBackendUrl}/${g}/stock/operations/recalculate`;
57
- return l.get(d);
58
- },
59
- startRecalculateTask() {
60
- const g = r.currentLocationDBName, d = `${c.inventoryBackendUrl}/${g}/stock/operations/recalculate?refundFromPreviousAdjustment=true`;
61
- return l.post(d);
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 c = 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 c.readStockBalance();
94
- },
95
- async readProductBalance() {
96
- this.productBalance = await c.readSkuBalance();
97
- }
98
- };
99
- };
100
- var ye = /* @__PURE__ */ ((c) => (c.History = "History", c.Convert = "Convert", c.Adjust = "Adjust", c))(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(c) {
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: c,
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((d) => d.id === v.measurement)) == null ? void 0 : g.abbrev) || "";
152
- }
153
- }
154
- ]
155
- }
156
- ],
157
- r
158
- );
159
- }
160
- function be(c, l) {
161
- const r = localStorage.getItem(`uom:${c._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
- } : c.trackingMeasurement && l.measurements.find((o) => o.id === c.trackingMeasurement) ? {
170
- type: "measurement",
171
- measurement: c.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(c) {
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 = c, 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 d({ 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) => d(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": d(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(c) {
263
- const l = c, 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, d) => 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(c) {
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 d = 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
- d.value.show = U;
306
- },
307
- onSubmitted() {
308
- c();
309
- }
310
- };
311
- d.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
- c();
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: d,
402
- adjustSkuDialogProps: S,
403
- showSkuHistory: g
404
- };
405
- }
406
- const zt = {
407
- context: null,
408
- error: null,
409
- isRequired(c = "This field is required") {
410
- return `${this.context ?? ""}`.length === 0 && (this.error = c), this;
411
- },
412
- isString(c = "Must be a valid string") {
413
- return this.error ? this : (typeof this.context != "string" && (this.error ?? (this.error = c)), this);
414
- },
415
- toInt() {
416
- return this.error ? this : (this.context = +this.context, this);
417
- },
418
- isInteger(c = "Must be an integer") {
419
- return this.error ? this : (this.toInt(), isNaN(this.context) && (this.error = c), this);
420
- },
421
- min(c, l) {
422
- if (this.error) return this;
423
- try {
424
- typeof this.context == "number" ? +this.context < c && (this.error = l ?? `Must be at least ${c}`) : Object.prototype.hasOwnProperty.call(this.context, "length") ? +this.context.length < c && (this.error = l ?? `Must be at least ${c}`) : this.error = "Length cannot be determined";
425
- } catch {
426
- this.error = "Length cannot be determined";
427
- }
428
- return this;
429
- },
430
- max(c, l) {
431
- if (this.error) return this;
432
- try {
433
- typeof this.context == "number" ? +this.context > c && (this.error = l ?? `Must be at most ${c}`) : "length" in this.context ? +this.context.length > c && (this.error = l ?? `Must be at most ${c}`) : this.error = "Length cannot be determined";
434
- } catch {
435
- this.error = "Length cannot be determined";
436
- }
437
- return this;
438
- }
439
- };
440
- function qe(c) {
441
- return { ...zt, context: c };
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" }, Xt = /* @__PURE__ */ n("div", { class: "fm-typo-en-body-lg-600" }, "Deduction summary", -1), Jt = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary flex-grow" }, Qt = { 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(c, { expose: l, emit: r }) {
452
- const o = c, v = r, g = Vt(), d = Me(), h = fe(), S = ie(), p = P(0), t = P(null), f = R(() => d.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
- (u) => u.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, u = Ce(o.sku.unit, s), m = gt(+e);
485
- return qe(m).isInteger().max(u).error ? "Precision cannot be more than " + u : !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((u) => {
491
- var m;
492
- return u.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 u, m, _;
497
- const e = (m = (u = o.sku.convert) == null ? void 0 : u.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 = d.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 ? Z(
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 ? Z(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, u) {
533
- a.value = !0;
534
- try {
535
- await h.convertSku({
536
- conversions: [
537
- {
538
- doc: e,
539
- amount: s,
540
- overrides: u == null ? void 0 : u.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, u) {
562
- const m = +s;
563
- let _ = u;
564
- s.length > 0 && isFinite(m) ? _ = u.map((x) => (x.id !== e || (x.amount = me(m)), x)) : _ = u.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((u) => u._id === e);
568
- return s ? tt(s.unit, !0) : [];
569
- }
570
- function q(e, s) {
571
- const u = Y(e), m = u.find((_) => _.value === s) ?? u.find((_) => _.value === null);
572
- return m ? {
573
- ...m,
574
- label: m.abbrev
575
- } : null;
576
- }
577
- function te(e, s, u) {
578
- let m;
579
- if (s === null)
580
- m = u.map((_) => (_.id !== e || (_.measurement = null), _)) ?? [];
581
- else {
582
- const _ = f.value.find((x) => x._id === e);
583
- m = u.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 X(e, s) {
591
- const u = s.filter((m) => m.id !== e);
592
- t.value = u;
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 u = 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(u, {
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
- Xt,
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", Jt, V((H = A.sku) == null ? void 0 : H.name), 1),
657
- n("div", Qt, " -" + 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(Z)(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(u, {
699
- class: "xs:col-span-2",
700
- disabled: a.value,
701
- modelValue: +C(Z)(
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) => X(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(c, l) {
764
- const r = he(c, l);
765
- return { ...r, amount: -r.amount };
766
- }
767
- function Ke(c, l) {
768
- return he(Math.abs(c), l);
769
- }
770
- const we = {
771
- [W.enum.DAMAGE]: {
772
- label: "Waste",
773
- toAdjustmentAmount: $e
774
- },
775
- [W.enum.THEFT]: {
776
- label: "Theft",
777
- toAdjustmentAmount: $e
778
- },
779
- [W.enum.LOSE]: {
780
- label: "Lose",
781
- toAdjustmentAmount: $e
782
- },
783
- [W.enum.EXTRA]: {
784
- label: "Extra",
785
- toAdjustmentAmount: Ke
786
- },
787
- [W.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(c, { emit: l }) {
799
- const r = c, 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)), d = R({
805
- get() {
806
- return r.modelValue.type ?? W.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
- +Z(y),
816
- y.precision
817
- ), o("update:modelValue", f);
818
- }
819
- }), h = R({
820
- get() {
821
- const t = ze(r.modelValue.amount);
822
- return +Z(t);
823
- },
824
- set(t) {
825
- const f = {
826
- ...r.modelValue
827
- }, y = me(t);
828
- f.amount = we[d.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: d.value,
877
- "onUpdate:modelValue": f[1] || (f[1] = (j) => d.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(Z)({
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(c, { expose: l, emit: r }) {
922
- const o = c, v = r, g = Me(), d = 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: W.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: W.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
- d.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: W.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((c, l) => ({
1091
- // TODO: remove once latest inventory backend has been push
1092
- async findBillsByBusinessId(r, o, v) {
1093
- const g = `${c.businessesBackendUrl}/${r}/reports/find-many`, d = {
1094
- // type: TYPE.bill,
1095
- type: "bill",
1096
- restaurantIds: o,
1097
- ids: v
1098
- };
1099
- return await l.post(g, d);
1100
- },
1101
- async findBillsById(r) {
1102
- const v = le().currentLocationDBName, g = `${c.inventoryBackendUrl}/${v}/bill/search`, d = {
1103
- ids: r
1104
- };
1105
- return await l.post(g, d);
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(c) {
1124
- const l = c, 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 d = 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
- `${Z(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 ? Qe(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: `${Z(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(d.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(c, l) {
1263
- var g;
1264
- const r = Object.keys(W.enum).reduce(
1265
- (d, h) => (d[h] = { amount: 0, precision: 0 }, d),
1266
- {}
1267
- );
1268
- if (!l)
1269
- return Object.entries(r).reduce(
1270
- (d, [h]) => (d[h] = "", d),
1271
- {}
1272
- );
1273
- const v = c.flatMap((d) => {
1274
- var h;
1275
- return ((h = d.skus) == null ? void 0 : h.filter((S) => S.sku._id === l._id)) ?? [];
1276
- }).flatMap((d) => d.amounts);
1277
- for (const d of v) {
1278
- const h = d.measurement ? Ze(d.measurement.conversion, d.amount) : d.amount;
1279
- r[g = d.type] ?? (r[g] = { amount: 0, precision: 0 }), r[d.type] = Ue(h, r[d.type]);
1280
- }
1281
- return Object.entries(r).reduce(
1282
- (d, [h, S]) => {
1283
- const p = {
1284
- ...S,
1285
- amount: Math.abs(S.amount)
1286
- };
1287
- return d[h] = /// comment, because without it formatter makes code uglier
1288
- `${Z(p, !1)} ${l.unit.abbrev}`, d;
1289
- },
1290
- {}
1291
- );
1292
- }
1293
- Array.prototype.computeFirst = function(c) {
1294
- const l = this.length;
1295
- for (let r = 0; r < l; r++) {
1296
- const o = this.at(r), v = c(o, r, this);
1297
- if (v != null)
1298
- return v;
1299
- }
1300
- };
1301
- Array.prototype.computeLast = function(c) {
1302
- const l = this.length - 1;
1303
- for (let r = l; r >= 0; r--) {
1304
- const o = this.at(r), v = c(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" }, Xn = {
1321
- class: "flex flex-col gap-1",
1322
- style: { "grid-column-end": "span 2" }
1323
- }, Jn = /* @__PURE__ */ n("div", { class: "text-fm-color-typo-secondary" }, "Total receive", -1), Qn = { 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(c) {
1344
- const l = Je(), r = Ie(), o = fe(), v = vn(), g = le(), d = it(), h = c, 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
- (u, m) => {
1371
- const _ = m.effectiveAt ?? Qe(m._id);
1372
- if (!_)
1373
- return u;
1374
- const x = I(new Date(_), e);
1375
- return u[x] ?? (u[x] = []), u[x].push(m), u;
1376
- },
1377
- {}
1378
- );
1379
- return Object.keys(s).map((u) => ({
1380
- date: u,
1381
- adjustments: s[u]
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: u }) => ({
1393
- date: s,
1394
- adjustments: u,
1395
- adjustmentsByTime: j(u, "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) ?? "", u = g.currentLocation.doc._id;
1403
- return v.findBillsByBusinessId(s, [u], $);
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 u = (_ = (m = s.skus) == null ? void 0 : m.find) == null ? void 0 : _.call(m, (x) => x.sku._id === h.sku._id);
1413
- return u == null ? void 0 : u.fromBalance;
1414
- }) ?? {
1415
- amount: 0,
1416
- precision: 0
1417
- }, e = h.sku;
1418
- return e ? `${Z($, !1)} ${e.unit.abbrev}` : "";
1419
- }), L = R(() => {
1420
- const $ = [...y.value].reverse().computeFirst((s) => {
1421
- var m, _;
1422
- const u = (_ = (m = s.skus) == null ? void 0 : m.find) == null ? void 0 : _.call(m, (x) => x.sku._id === h.sku._id);
1423
- return u == null ? void 0 : u.toBalance;
1424
- }) ?? {
1425
- amount: 0,
1426
- precision: 0
1427
- }, e = h.sku;
1428
- return e ? `${Z($, !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((u) => {
1445
- var m;
1446
- return ((m = u.skus) == null ? void 0 : m.flatMap((_) => _.amounts)) ?? [];
1447
- }).filter(
1448
- (u) => u.type !== W.enum.RECEIVE && u.type !== W.enum.PURCHASE && u.type !== W.enum.EXTRA
1449
- ).reduce(
1450
- (u, m) => {
1451
- const _ = m.cost;
1452
- if (!_) return u;
1453
- const x = {
1454
- ...bt(u, Math.max(u.precision, _.precision)),
1455
- currency: _.currency
1456
- };
1457
- return {
1458
- ...Ue(x, _),
1459
- currency: u.currency
1460
- };
1461
- },
1462
- {
1463
- amount: 0,
1464
- precision: 0,
1465
- currency: N(((s = l.currentCountry) == null ? void 0 : s.value) ?? Ne)
1466
- }
1467
- );
1468
- return Fe(e, !1, e.precision);
1469
- });
1470
- function Y() {
1471
- const { startDate: $, endDate: e } = St(t.value);
1472
- $ !== null && e !== null && (t.value = {
1473
- startDate: $,
1474
- endDate: e
1475
- });
1476
- }
1477
- const q = R(() => {
1478
- var s;
1479
- const $ = [...y.value].reverse().computeFirst((u) => {
1480
- var _, x;
1481
- const m = (x = (_ = u.skus) == null ? void 0 : _.find) == null ? void 0 : x.call(_, (E) => E.sku._id === h.sku._id);
1482
- return m == null ? void 0 : m.toCostBalances;
1483
- });
1484
- return $ ? $.reduce((u, m) => Ye.add([u, Ye.fromDinero(m.cost)]), {
1485
- amount: 0,
1486
- precision: 0,
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 X = Re(h, "show");
1498
- return ($, e) => {
1499
- const s = F("FmButton"), u = 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(X),
1503
- "onUpdate:modelValue": e[4] || (e[4] = (T) => Ae(X) ? X.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) => X.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
- }, {
1530
- "trigger-button": D(({ opened: H }) => [
1531
- b(u, {
1532
- "prepend-icon": "calendar_month",
1533
- focused: H
1534
- }, {
1535
- default: D(() => [
1536
- pe(V(t.value.startDate) + " - " + V(t.value.endDate), 1)
1537
- ]),
1538
- _: 2
1539
- }, 1032, ["focused"])
1540
- ]),
1541
- _: 1
1542
- }, 8, ["modelValue"])
1543
- ]),
1544
- b(s, {
1545
- variant: "tertiary",
1546
- onClick: e[2] || (e[2] = (H) => Y()),
1547
- "prepend-icon": "navigate_before"
1548
- }),
1549
- b(s, {
1550
- variant: "tertiary",
1551
- onClick: e[3] || (e[3] = (H) => te()),
1552
- "prepend-icon": "navigate_next"
1553
- })
1554
- ]),
1555
- S.value ? (k(), M("div", jn, [
1556
- b(_),
1557
- b(x, { size: "xl" }),
1558
- Rn,
1559
- b(_),
1560
- b(_)
1561
- ])) : i.value && ((T = i.value) == null ? void 0 : T.length) > 0 ? (k(), M("div", Un, [
1562
- b(se, { variant: "outlined" }, {
1563
- default: D(() => [
1564
- b(J, null, {
1565
- default: D(() => [
1566
- In,
1567
- n("div", Tn, [
1568
- n("div", Pn, [
1569
- En,
1570
- n("div", Ln, V(U.value.PURCHASE), 1)
1571
- ]),
1572
- n("div", Hn, [
1573
- Nn,
1574
- n("div", On, V(U.value.SALES), 1)
1575
- ]),
1576
- n("div", Yn, [
1577
- zn,
1578
- n("div", qn, V(U.value.LOSE), 1)
1579
- ]),
1580
- n("div", Kn, [
1581
- Gn,
1582
- n("div", Wn, V(U.value.REQUEST), 1)
1583
- ]),
1584
- n("div", Xn, [
1585
- Jn,
1586
- n("div", Qn, V(U.value.RECEIVE), 1)
1587
- ]),
1588
- n("div", Zn, [
1589
- eo,
1590
- n("div", to, V(O.value), 1)
1591
- ]),
1592
- n("div", no, [
1593
- oo,
1594
- n("div", so, V(L.value), 1)
1595
- ]),
1596
- C(d).enableTotalCost ? (k(), M("div", ao, [
1597
- n("div", lo, [
1598
- pe(" Estimated value  "),
1599
- b(K, {
1600
- variant: "plain",
1601
- placement: "top",
1602
- content: "Estimated value is calculated starting from last closing value.",
1603
- "z-index": 50
1604
- }, {
1605
- default: D(() => [
1606
- b(E, {
1607
- name: "help",
1608
- size: "sm"
1609
- })
1610
- ]),
1611
- _: 1
1612
- })
1613
- ]),
1614
- n("div", ro, V(typeof q.value != "string" ? C(Fe)(
1615
- q.value,
1616
- !1,
1617
- q.value.precision
1618
- ) : q.value), 1)
1619
- ])) : Q("", !0),
1620
- C(d).enableTotalCost ? (k(), M("div", io, [
1621
- n("div", uo, [
1622
- co,
1623
- b(K, {
1624
- variant: "plain",
1625
- placement: "top",
1626
- "z-index": 50
1627
- }, {
1628
- content: D(() => [
1629
- mo
1630
- ]),
1631
- default: D(() => [
1632
- b(E, {
1633
- name: "help",
1634
- size: "sm"
1635
- })
1636
- ]),
1637
- _: 1
1638
- })
1639
- ]),
1640
- n("div", po, V(G.value), 1)
1641
- ])) : Q("", !0)
1642
- ])
1643
- ]),
1644
- _: 1
1645
- })
1646
- ]),
1647
- _: 1
1648
- }),
1649
- fo,
1650
- (k(!0), M(ee, null, ae(i.value, (H) => (k(), M(ee, {
1651
- key: H.date
1652
- }, [
1653
- $.sku ? (k(), z(Cn, {
1654
- key: 0,
1655
- record: H,
1656
- sku: $.sku,
1657
- bills: a.value
1658
- }, null, 8, ["record", "sku", "bills"])) : Q("", !0)
1659
- ], 64))), 128))
1660
- ])) : (k(), M("div", vo, [
1661
- b(_),
1662
- n("div", null, [
1663
- n("img", {
1664
- src: C(Rt),
1665
- alt: "List is empty"
1666
- }, null, 8, yo)
1667
- ]),
1668
- _o,
1669
- go,
1670
- b(_),
1671
- b(_)
1672
- ]))
1673
- ])
1674
- ];
1675
- }),
1676
- _: 1
1677
- }, 8, ["modelValue"]);
1678
- };
1679
- }
1680
- }), 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({
1681
- __name: "StockRecalculateDialog",
1682
- emits: ["close"],
1683
- setup(c, { emit: l }) {
1684
- const r = l, o = le(), v = fe(), g = R(() => {
1685
- var i;
1686
- return ((i = o == null ? void 0 : o._currentLocation) == null ? void 0 : i.type) === Xe.restaurant;
1687
- }), d = P(null), h = P(!1), S = P(""), p = ie(), t = P(null);
1688
- Ve(f);
1689
- async function f() {
1690
- d.value = !0;
1691
- try {
1692
- const [i] = await Promise.all([
1693
- v.recalculation.getRecalculateAbility(),
1694
- new Promise((a) => setTimeout(a, 1e3))
1695
- ]);
1696
- h.value = i.canRecalculate, S.value = i.reason ?? "", t.value = i.lastClosing ? new Date(i.lastClosing) : null;
1697
- } catch {
1698
- p.open({
1699
- type: "error",
1700
- title: "Unable to fetch recalculate ability",
1701
- message: "Please try again later."
1702
- }), S.value = "Something went wrong.";
1703
- } finally {
1704
- d.value = !1;
1705
- }
1706
- }
1707
- function y() {
1708
- r("close"), p.open({
1709
- title: "Request submitted",
1710
- message: "Please wait for 15 minutes for all the changes to be reflected."
1711
- }), v.recalculation.startRecalculateTask();
1712
- }
1713
- return (i, a) => {
1714
- const I = F("FmCircularProgress"), j = F("FmButton");
1715
- return k(), M("div", bo, [
1716
- g.value ? (k(), M("div", ko, [
1717
- d.value === null || d.value === !0 ? (k(), M("div", xo, [
1718
- n("div", So, [
1719
- n("div", null, [
1720
- b(I, { size: "lg" })
1721
- ]),
1722
- $o
1723
- ])
1724
- ])) : h.value ? (k(), M("div", Co, [
1725
- n("div", Fo, [
1726
- n("div", Bo, [
1727
- pe(" Last closing was at: "),
1728
- n("span", Ao, V(C(Ct)(t.value)), 1),
1729
- pe(". You may submit a recalculation task to the backend for all adjustments after this date. ")
1730
- ]),
1731
- Vo
1732
- ])
1733
- ])) : (k(), M("div", wo, V(S.value), 1))
1734
- ])) : (k(), M("div", Do, "Cannot recalculate adjustment history on a non-restaurant outlet.")),
1735
- n("div", Mo, [
1736
- h.value ? (k(), z(j, {
1737
- key: 0,
1738
- label: "Submit",
1739
- onClick: y
1740
- })) : Q("", !0),
1741
- b(j, {
1742
- variant: "tertiary",
1743
- label: "Close",
1744
- onClick: a[0] || (a[0] = (w) => r("close"))
1745
- })
1746
- ])
1747
- ]);
1748
- };
1749
- }
1750
- }), 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({
1751
- __name: "StockView",
1752
- setup(c) {
1753
- const l = Me(), r = le(), o = Ie(), v = vt(), {
1754
- columnDefs: g,
1755
- stockHistoryProps: d,
1756
- convertSkuDialogProps: h,
1757
- adjustSkuDialogProps: S,
1758
- showSkuHistory: p
1759
- } = Yt(i);
1760
- r.watchLocation(i);
1761
- const t = P(!1), f = ie(), y = je();
1762
- async function i() {
1763
- if (r._currentLocation) {
1764
- t.value = !0;
1765
- try {
1766
- await o.readStockBalance(), await o.readProductBalance(), await v.readStockEstimateBalance();
1767
- } catch {
1768
- f.open({
1769
- title: "Something went wrong",
1770
- message: "Please refresh the page to retry.",
1771
- type: "error"
1772
- });
1773
- } finally {
1774
- t.value = !1;
1775
- }
1776
- }
1777
- }
1778
- const a = R(
1779
- () => l.skus.map((L) => {
1780
- var te, X, $;
1781
- const N = L.trackingMeasurement;
1782
- let G = (X = (te = o.stockBalance.skus) == null ? void 0 : te.find(
1783
- (e) => e.id === L._id
1784
- )) == null ? void 0 : X.balance, Y = v.inventoryForecast.skus.find(
1785
- (e) => e.id === L._id
1786
- );
1787
- return {
1788
- ...L,
1789
- balance: G ?? {
1790
- amount: 0,
1791
- precision: 0
1792
- },
1793
- day: (Y == null ? void 0 : Y.depletionDays) ?? void 0,
1794
- trackingUnitAbbrev: N ? (($ = L.unit.measurements.find((e) => e.id === N)) == null ? void 0 : $.abbrev) ?? "" : L.unit.abbrev
1795
- };
1796
- })
1797
- ), I = P(""), { breakpoints: j } = ut(), w = R(() => j.value.xs || j.value.sm ? 10 : 20), B = mt(), U = R(() => {
1798
- var N;
1799
- return ((N = r._currentLocation) == null ? void 0 : N.type) === Xe.restaurant ? [
1800
- {
1801
- label: "Refresh",
1802
- icon: "refresh",
1803
- key: "refresh"
1804
- },
1805
- {
1806
- label: "Recalculate",
1807
- icon: "calculate",
1808
- key: "recalculate"
1809
- }
1810
- ] : [];
1811
- });
1812
- function O() {
1813
- y.open({
1814
- title: "Recalculate stock",
1815
- contentComponent: jo,
1816
- contentComponentProps: {
1817
- onClose() {
1818
- y.close();
1819
- }
1820
- },
1821
- overlay: !0,
1822
- dismissAway: !0
1823
- });
1824
- }
1825
- return (L, N) => {
1826
- const G = F("FmTableToolbar"), Y = F("FmMenuDivider"), q = F("FmTable");
1827
- return k(), z(lt, { title: "Stock" }, {
1828
- default: D(() => {
1829
- var te, X, $, e;
1830
- return [
1831
- n("div", Ro, [
1832
- n("div", Uo, [
1833
- n("div", Io, [
1834
- b(yt)
1835
- ]),
1836
- n("div", To, [
1837
- b(G, {
1838
- searchable: "",
1839
- "search-model": I.value,
1840
- "onUpdate:searchModel": N[0] || (N[0] = (s) => I.value = s),
1841
- actions: [{ label: "Export", icon: "ios_share", key: "export" }, ...U.value],
1842
- "onClick:actionExport": N[1] || (N[1] = (s) => C(Pt)(a.value)),
1843
- "onClick:actionRefresh": i,
1844
- "onClick:actionRecalculate": O
1845
- }, null, 8, ["search-model", "actions"]),
1846
- b(Y, { class: "hidden xs:block" })
1847
- ])
1848
- ]),
1849
- (k(), z(q, {
1850
- style: Ge(C(B).tableHeight),
1851
- "column-defs": C(g),
1852
- "row-data": a.value,
1853
- "search-value": I.value,
1854
- loading: t.value || !C(r)._currentLocation,
1855
- key: (te = C(r)._currentLocation) == null ? void 0 : te.dbName,
1856
- onRowClick: N[2] || (N[2] = (s) => C(p)(s.original)),
1857
- "page-size": w.value
1858
- }, {
1859
- "list-row": D((s) => [
1860
- b(dt, {
1861
- row: s,
1862
- onRowClick: C(p)
1863
- }, {
1864
- default: D((u) => {
1865
- var m, _, x, E, K, J, se, A, T, H;
1866
- return [
1867
- n("div", Po, [
1868
- n("div", Eo, [
1869
- n("div", Lo, [
1870
- b(C(Oe), {
1871
- render: (x = (_ = (m = u.code) == null ? void 0 : m.column) == null ? void 0 : _.columnDef) == null ? void 0 : x.cell,
1872
- props: (K = (E = u.code) == null ? void 0 : E.getContext) == null ? void 0 : K.call(E)
1873
- }, null, 8, ["render", "props"])
1874
- ]),
1875
- n("div", Ho, [
1876
- b(C(Oe), {
1877
- render: (A = (se = (J = u.name) == null ? void 0 : J.column) == null ? void 0 : se.columnDef) == null ? void 0 : A.cell,
1878
- props: (H = (T = u.name) == null ? void 0 : T.getContext) == null ? void 0 : H.call(T)
1879
- }, null, 8, ["render", "props"])
1880
- ])
1881
- ]),
1882
- n("div", null, [
1883
- b(ot, {
1884
- days: s.original.day
1885
- }, null, 8, ["days"])
1886
- ]),
1887
- n("div", null, [
1888
- b(nt, {
1889
- class: "xs:w-[160px]",
1890
- unit: s.original.unit,
1891
- sku: s.original,
1892
- amount: s.original.balance,
1893
- "default-tracking-measurement": s.original.trackingMeasurement ?? void 0
1894
- }, null, 8, ["unit", "sku", "amount", "default-tracking-measurement"])
1895
- ])
1896
- ])
1897
- ];
1898
- }),
1899
- _: 2
1900
- }, 1032, ["row", "onRowClick"])
1901
- ]),
1902
- _: 1
1903
- }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
1904
- ]),
1905
- (k(), z(at, { to: "body" }, [
1906
- (X = C(d)) != null && X.sku ? (k(), z(ho, ke(xe({ key: 0 }, C(d))), null, 16)) : Q("", !0),
1907
- ($ = C(h)) != null && $.sku ? (k(), z(an, ke(xe({ key: 1 }, C(h))), null, 16)) : Q("", !0),
1908
- (e = C(S)) != null && e.stock ? (k(), z(fn, ke(xe({ key: 2 }, C(S))), null, 16)) : Q("", !0)
1909
- ]))
1910
- ];
1911
- }),
1912
- _: 1
1913
- });
1914
- };
1915
- }
1916
- });
1917
- export {
1918
- as as default
1919
- };