@feedmepos/mf-inventory-portal 1.2.10-dev.1 → 1.2.10-dev.3

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