@feedmepos/mf-inventory-portal 0.0.14-dev.4 → 0.0.15-dev.1

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