@feedmepos/mf-inventory-portal 1.7.21 → 1.7.22

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