@feedmepos/mf-inventory-portal 0.0.19-dev.1 → 0.0.19-dev.2

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