@feedmepos/mf-inventory-portal 1.2.7 → 1.2.8-dev.1

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