@feedmepos/mf-inventory-portal 1.3.12-dev.1 → 1.3.12-dev.2

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