@feedmepos/mf-inventory-portal 1.2.19 → 1.2.20-dev.1

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