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

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