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

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