@feedmepos/mf-inventory-portal 0.0.17-dev.9 → 0.0.18-dev.3

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