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