@feedmepos/mf-inventory-portal 0.0.19-dev.2 → 0.0.19-dev.4

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