@feedmepos/mf-inventory-portal 1.1.9-dev.2 → 1.1.9

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