@feedmepos/mf-inventory-portal 0.0.7-dev.3 → 0.0.7-dev.4

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