@feedmepos/mf-inventory-portal 1.5.12 → 1.6.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/{App-DBEmTaMX.js → App-BWiKiRD2.js} +4 -4
  2. package/dist/{ApprovalView-BvzIwH1r.js → ApprovalView-TFet-Rht.js} +7 -7
  3. package/dist/{BindingsDialog-DnqHoU0Y.js → BindingsDialog-ByO16R7B.js} +2 -2
  4. package/dist/{BindingsPicker-Bjpj0zdJ.js → BindingsPicker-BzeipJDM.js} +2 -2
  5. package/dist/{BindingsTable-S5Nqq4Qv.js → BindingsTable-CATRwDGx.js} +3 -3
  6. package/dist/ClosingDraftView-Bilo3C7N.js +4318 -0
  7. package/dist/{ClosingHistoryView-B2ccrB2K.js → ClosingHistoryView-DJEhuzBh.js} +5 -5
  8. package/dist/ClosingTemplateView-DTS__1eO.js +2221 -0
  9. package/dist/{DefaultView-DQhLe6LE.js → DefaultView-Dpwvllot.js} +2 -2
  10. package/dist/{DeliveryOrderPrintPreview-Cup9mzpO.js → DeliveryOrderPrintPreview-BZ-BDWlS.js} +2 -2
  11. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-DuZFuSbw.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BMJVOiL_.js} +2 -2
  12. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-DoPyc0aE.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-QvgQwP6t.js} +2 -2
  13. package/dist/{FmMultiselectDialog-Cwazmlw3.js → FmMultiselectDialog-B1rAOXTC.js} +2 -2
  14. package/dist/{FmMultiselectDialog-DnuUrW7h.js → FmMultiselectDialog-W0_FfMmH.js} +1 -1
  15. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-BMzzUsa4.js → FmUnitInput.vue_vue_type_script_setup_true_lang-DNpKzzVC.js} +5 -5
  16. package/dist/{ImportView-CXtrdABV.js → ImportView-B_3OeL5b.js} +6 -6
  17. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-Cfp95IvX.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CdNdnCp-.js} +1 -1
  18. package/dist/{IngredientGroupView-Bm-2yK8J.js → IngredientGroupView-B_v-UNeR.js} +5 -5
  19. package/dist/{IngredientsView-Bo8w9LSr.js → IngredientsView-DTXevc-8.js} +15 -15
  20. package/dist/{IntegrationExplorerView-DUqQ64CE.js → IntegrationExplorerView-C6JUipFs.js} +352 -352
  21. package/dist/IntegrationView-DX4hhKYv.js +5100 -0
  22. package/dist/{InventoryBindingForm-DWJRCTf8.js → InventoryBindingForm-BpNKhiGF.js} +1 -1
  23. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-DH-xUQ5m.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-BWy-YpCv.js} +5 -5
  24. package/dist/{InventoryBindingSummary-DSwCvTnu.js → InventoryBindingSummary-BL4AkZY3.js} +1 -1
  25. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-KDWRZCxm.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-DURnZteR.js} +1 -1
  26. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-Wuv2teWn.js → PremiumBadge.vue_vue_type_script_setup_true_lang-BR0Hc9cL.js} +1 -1
  27. package/dist/{PublishView-BSahQbqy.js → PublishView-CELngZXP.js} +3 -3
  28. package/dist/{PurchaseOrderPrintPreview-C8umjCEU.js → PurchaseOrderPrintPreview-HCGMQWdo.js} +2 -2
  29. package/dist/{ReceiveRequestView-Bf5dAcun.js → ReceiveRequestView-DfrpsGeI.js} +26 -26
  30. package/dist/{RecipeView-wU9u23Zp.js → RecipeView-DCrrdrhp.js} +1104 -1117
  31. package/dist/{SettingsView-C5Uc6h0A.js → SettingsView-CHoDkUIF.js} +4 -4
  32. package/dist/{StockView-QF68mXtU.js → StockView-DlP1-pbq.js} +19 -19
  33. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-Cgw8EDXb.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-NZcNoQ6u.js} +1 -1
  34. package/dist/{SupplierView-xBONJSsg.js → SupplierView-DqQbgLqh.js} +12 -12
  35. package/dist/{SurchargeView-BK8aNKZl.js → SurchargeView-CtlXOPJ3.js} +6 -6
  36. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-tsuedeNl.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-BRrHPAJj.js} +2 -2
  37. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-BXVa7pt5.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Bw3UN_Zn.js} +1 -1
  38. package/dist/{TransferDetails.vue_vue_type_script_setup_true_lang-CVRD5iri.js → TransferDetails.vue_vue_type_script_setup_true_lang-atZZPJBf.js} +20 -20
  39. package/dist/TransferTemplateView-Dl0k38tD.js +2327 -0
  40. package/dist/{UnitCostHistoryView-BS0nrbkD.js → UnitCostHistoryView-Dh-yAgvG.js} +4 -4
  41. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-CeD0qWRC.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-FqnqY9bU.js} +5 -5
  42. package/dist/{UnitView-DsKX7DM0.js → UnitView-D5Zvz2xm.js} +7 -7
  43. package/dist/{WarehouseView-DRZaGu80.js → WarehouseView-s5g9AQq5.js} +5 -5
  44. package/dist/{WastageTemplateView-CtMSWKFj.js → WastageTemplateView-XzJSsB29.js} +14 -14
  45. package/dist/api/closing-draft.d.ts +6 -0
  46. package/dist/api/codemax.d.ts +11 -0
  47. package/dist/api/inventory.d.ts +1 -0
  48. package/dist/api/netsuite.d.ts +5 -4
  49. package/dist/api/surcharge.d.ts +1 -0
  50. package/dist/{app-DYMYQwvV.js → app-D-l9FM2n.js} +15762 -13683
  51. package/dist/app.d.ts +288 -0
  52. package/dist/app.js +1 -1
  53. package/dist/{closing-template-Cxsa4j_W.js → closing-template-C56_2aLc.js} +1 -1
  54. package/dist/{date2-BdXL0GG5.js → date2-CRMgo5NH.js} +1 -1
  55. package/dist/{dayjs.min-LoBFKjU2.js → dayjs.min-9bo3vPqj.js} +1 -1
  56. package/dist/{decimal-BFFta-yv.js → decimal-CsE7mms2.js} +2 -2
  57. package/dist/{defineDeepModel-CCZ3fqXQ.js → defineDeepModel-DDX70CM6.js} +1 -1
  58. package/dist/{duplicate-template-C2Qho2Ig.js → duplicate-template-BrEOP-1V.js} +1 -1
  59. package/dist/{feature-Dt5ZFkZR.js → feature-Bl6yUhw_.js} +2 -2
  60. package/dist/{format-time-from-id-LqoWbcB4.js → format-time-from-id-BuMdYlM9.js} +1 -1
  61. package/dist/format-unit-display-CMfuvGP6.js +1432 -0
  62. package/dist/{import-export.helper-DogBd6aS.js → import-export.helper-C9F9d-rh.js} +6 -6
  63. package/dist/{index-IMHyRNdu.js → index-BcOtIfdU.js} +1 -1
  64. package/dist/index-BdSVteJV.js +257 -0
  65. package/dist/{index-D0xsiYLO.js → index-cbmIhZ6F.js} +1 -1
  66. package/dist/{inventory-core-dart.default-BkcD7c_a.js → inventory-core-dart.default-DewosGoK.js} +1 -1
  67. package/dist/{lz-string-CgecKowu.js → lz-string-Ye-dLAix.js} +1 -1
  68. package/dist/modules/print-template/api/print-template.d.ts +1 -0
  69. package/dist/{netsuite-9qEVrdMv.js → netsuite-Dyw1JtQL.js} +2 -2
  70. package/dist/{number-DSMFbPf0.js → number-YiCgPFTE.js} +3 -3
  71. package/dist/{predefined-templates-OZoiOUoA.js → predefined-templates-B0Eto9Jx.js} +1 -1
  72. package/dist/{purchase-order-template-CUee1L_x.js → purchase-order-template-zHPLRQDQ.js} +1 -1
  73. package/dist/{recalculationUtils-CPcCUHIm.js → recalculationUtils-DZLZlctO.js} +1 -1
  74. package/dist/{rules-CMNaUkUU.js → rules-BsVkaxL5.js} +2 -2
  75. package/dist/{stock-BOaUT0Y3.js → stock-DlQopDTl.js} +1 -1
  76. package/dist/stores/api.d.ts +1 -0
  77. package/dist/stores/helper/generate-backend-urls.d.ts +1 -0
  78. package/dist/stores/integration/codemax.d.ts +432 -0
  79. package/dist/stores/integration/index.d.ts +4 -1
  80. package/dist/{supplier-BAbQZL7x.js → supplier-UPX_1aFs.js} +2 -2
  81. package/dist/{surcharge-C5tQ0vs0.js → surcharge-DO3-kAit.js} +1 -1
  82. package/dist/tsconfig.app.tsbuildinfo +1 -1
  83. package/dist/{uom-rules-CSmRb5Ds.js → uom-rules-DbhFLCUC.js} +1 -1
  84. package/dist/{use-ingredient-select-dialog-B9XYlxjA.js → use-ingredient-select-dialog-BASkk3-u.js} +16 -16
  85. package/dist/{use-inventory-binding-dialog-BzIb4yxm.js → use-inventory-binding-dialog-DTc48xUU.js} +2 -2
  86. package/dist/use-template-enabled-locations-gwYjb6_p.js +132 -0
  87. package/dist/{use-transfer-locations-Di5ozOgU.js → use-transfer-locations-BJ0xIECi.js} +2 -2
  88. package/dist/{useHrmPermission-N8GPw9P_.js → useHrmPermission-G4mfvYF8.js} +1 -1
  89. package/dist/{useNavigationMenu-BLnGMLsm.js → useNavigationMenu-Be-99JmQ.js} +2 -2
  90. package/dist/{useSseClient-BQtJfryY.js → useSseClient-D1h38l_K.js} +3 -3
  91. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftApprovalDialog.vue.d.ts +800 -0
  92. package/dist/views/closing-draft/components/closing-draft-dialog/ClosingDraftDialog.vue.d.ts +40 -0
  93. package/dist/views/closing-draft/components/closing-draft-groups/ClosingGroupAction.vue.d.ts +21 -0
  94. package/dist/views/closing-draft/components/closing-draft-groups/ClosingGroupCard.vue.d.ts +20 -0
  95. package/dist/views/closing-draft/components/closing-draft-groups/ClosingGroupDetailSideSheet.vue.d.ts +823 -0
  96. package/dist/views/closing-draft/components/closing-draft-groups/ClosingGroupGrid.vue.d.ts +20 -0
  97. package/dist/views/closing-draft/composables/use-closing-draft-import.d.ts +10 -0
  98. package/dist/views/closing-draft/composables/use-closing-draft-table.d.ts +1400 -133
  99. package/dist/views/closing-draft/helpers/closing-draft-summary.helper.d.ts +11 -0
  100. package/dist/views/closing-draft/helpers/closing-group-detail.helper.d.ts +68 -0
  101. package/dist/views/closing-draft/helpers/closing-group-status.helper.d.ts +6 -0
  102. package/dist/views/closing-draft/helpers/closing-groups.helper.d.ts +28 -0
  103. package/dist/views/closing-draft/helpers/merge-closing-draft-items.helper.d.ts +9 -0
  104. package/dist/views/closing-template/components/closing-template-form/components/ClosingTemplateGroupsEditor.vue.d.ts +31 -0
  105. package/dist/views/closing-template/components/closing-template-form/components/ClosingTemplateItem.vue.d.ts +164 -7
  106. package/dist/views/closing-template/components/closing-template-form/composables/use-closing-template-items.d.ts +24 -88
  107. package/dist/views/closing-template/composables/use-closing-template-actions.d.ts +108 -0
  108. package/dist/views/closing-template/composables/use-closing-template-table.d.ts +108 -0
  109. package/dist/views/ingredients/composables/use-ingredient-select-dialog.d.ts +3 -3
  110. package/dist/views/integration/Codemax.vue.d.ts +2 -0
  111. package/dist/views/integration/components/ApplyProductCodemax.vue.d.ts +341 -0
  112. package/dist/views/integration/components/ApplyProductDialogCodemax.vue.d.ts +298 -0
  113. package/dist/views/integration/components/ApplyProductDialogPropsCodemax.d.ts +17 -0
  114. package/dist/views/integration/components/CodemaxDialog.vue.d.ts +519 -0
  115. package/dist/views/recipe/composables/use-recipe-bulk-editor.d.ts +3 -3
  116. package/dist/views/transfer-template/components/template-item-bulk-editor/TemplateItemBulkEditorDialog.vue.d.ts +2 -0
  117. package/dist/views/transfer-template/components/template-item-bulk-editor/TemplateItemBulkEditorStep1.vue.d.ts +2 -0
  118. package/dist/views/transfer-template/components/template-item-bulk-editor/TemplateItemBulkEditorStep2.vue.d.ts +8 -0
  119. package/dist/views/transfer-template/components/template-item-bulk-editor/TemplateItemBulkEditorStep3.vue.d.ts +2 -0
  120. package/dist/views/transfer-template/composables/use-template-item-bulk-editor.d.ts +3225 -0
  121. package/dist/views/transfer-template/composables/use-transfer-template-actions.d.ts +4 -1
  122. package/dist/views/transfer-template/helpers/template-item-bulk-editor-export.d.ts +9 -0
  123. package/dist/{vue-i18n-DR8I1LQH.js → vue-i18n-fX3C6wjd.js} +306 -306
  124. package/dist/{xlsx-D5-Cqx-l.js → xlsx-BsL1DoEA.js} +1 -1
  125. package/dist/{xlsx.util-DEdsfN6W.js → xlsx.util-D_XTOHMv.js} +3 -3
  126. package/package.json +4 -4
  127. package/dist/ClosingDraftView-Y074sSoz.js +0 -3343
  128. package/dist/ClosingTemplateView-BcvKBWVJ.js +0 -2077
  129. package/dist/IntegrationView-CtkbKPzC.js +0 -4586
  130. package/dist/TransferTemplateView-Cm4evaK3.js +0 -1564
  131. package/dist/format-unit-display-CWqmpVa_.js +0 -1268
  132. package/dist/index-2DNXazDV.js +0 -164
  133. package/dist/use-template-enabled-locations-V5iE0ywc.js +0 -146
@@ -1,3343 +0,0 @@
1
- import { defineComponent as je, ref as W, computed as M, onMounted as kt, resolveComponent as Z, openBlock as h, createElementBlock as T, Fragment as ce, createTextVNode as de, createBlock as ae, withCtx as X, createElementVNode as o, toDisplayString as H, unref as u, createVNode as $, createCommentVNode as K, h as k, watch as ze, renderList as he, onUnmounted as hn, reactive as Et, isRef as _t, normalizeClass as Se, normalizeStyle as Ht, createSlots as kn, Teleport as _n, mergeProps as wn } from "vue";
2
- import { u as xn, _ as Dn } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DGlWE5I8.js";
3
- import { useCoreStore as Yt, useI18n as Ye } from "@feedmepos/mf-common";
4
- import { useSnackbar as Ke, useDialog as An, components as pe, useProxiedModel as Kt, useBreakpoints as Cn } from "@feedmepos/ui-library";
5
- import { m as Sn, u as We, L as oe, w as te, q as Wt, s as Be, M as _e, B as Te, c as $n, a as wt, j as In } from "./app-DYMYQwvV.js";
6
- import { defineStore as qt, storeToRefs as Fn } from "pinia";
7
- import { b as rt, e as Gt, f as Bn, a as Ce } from "./date2-BdXL0GG5.js";
8
- import { R as Tn } from "./rules-CMNaUkUU.js";
9
- import { e as lt, a as ht, t as Qt, c as He, l as Zt, m as Jt, j as Xt, k as en, o as ne } from "./number-DSMFbPf0.js";
10
- import { b as jn, d as Mn } from "./xlsx.util-DEdsfN6W.js";
11
- import { i as tn, u as nn } from "./uom-rules-CSmRb5Ds.js";
12
- import { u as Un, a as Rn } from "./useSseClient-BQtJfryY.js";
13
- import { u as ct } from "./stock-BOaUT0Y3.js";
14
- import { D as Lt, R as Ne } from "./row-action.enum-DQ9bJ_uv.js";
15
- import { c as Pn } from "./component-kqxARxvM.js";
16
- import { f as Vn } from "./format-time-from-id-LqoWbcB4.js";
17
- import { f as Nn } from "./recalculationUtils-CPcCUHIm.js";
18
- import { _ as zn } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-DoPyc0aE.js";
19
- import { _ as En } from "./empty-placeholder-B0QU467o.js";
20
- import { F as gt } from "./FmAdminBadge-DjnBAgyv.js";
21
- import { u as Ln } from "./vue-i18n-DR8I1LQH.js";
22
- import { F as On } from "./decimal-BFFta-yv.js";
23
- import { r as Hn, u as ot, w as Yn } from "./xlsx-D5-Cqx-l.js";
24
- import { d as Kn } from "./dayjs.min-LoBFKjU2.js";
25
- import { F as Wn } from "./FmDroppableField-J0xUsOTV.js";
26
- import { _ as qn } from "./FmConfirmationButton.vue_vue_type_script_setup_true_lang-DLrMEGFR.js";
27
- import { _ as Gn, F as at } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
28
- const qe = Sn((n, l) => {
29
- function t() {
30
- return We().currentLocation.dbName;
31
- }
32
- return {
33
- getDbName: t,
34
- async getDraft(s) {
35
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/${s}`;
36
- return l.get(i);
37
- },
38
- async readDrafts() {
39
- const s = t(), g = `${n.inventoryBackendUrl}/${s}/closing-draft`;
40
- return l.get(g);
41
- },
42
- async runOperation(s) {
43
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/run-operation`;
44
- return l.post(i, s);
45
- },
46
- async runOperationV1(s) {
47
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/v1/run-operation`;
48
- return l.post(i, s);
49
- },
50
- async sync(s) {
51
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/sync`;
52
- return l.post(i, s);
53
- },
54
- async cloneDraft(s) {
55
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/${s}/clone`;
56
- return l.post(i, {});
57
- },
58
- async createQuickModeDraftWithItems(s) {
59
- const g = t(), i = `${n.inventoryBackendUrl}/${g}/closing-draft/quick-mode/new-with-items`;
60
- return l.post(i, s);
61
- },
62
- initializeStockSnapshot(s, g) {
63
- const i = t(), r = `${n.inventoryBackendUrl}/${i}/closing-draft/${encodeURIComponent(s)}/initialize-stock-snapshot`;
64
- return l.post(r, { effectiveAt: g });
65
- },
66
- async getRefreshBalanceStatus(s, g) {
67
- const i = t(), r = `${n.inventoryBackendUrl}/${i}/closing-draft/${s}/refresh-balance/status?closingDraftRevision=${encodeURIComponent(g)}`;
68
- return l.get(r);
69
- }
70
- };
71
- }), Qn = { class: "fm-typo-en-body-lg-400" }, Zn = { class: "fm-typo-en-body-lg-600" }, Jn = {
72
- key: 0,
73
- class: "flex flex-col"
74
- }, Xn = {
75
- key: 0,
76
- class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
77
- }, ea = { class: "flex gap-12 py-8 justify-end w-full" }, bt = /* @__PURE__ */ je({
78
- __name: "ClosingDraftAction",
79
- props: {
80
- draft: {},
81
- action: {},
82
- onCancel: { type: Function },
83
- onFinished: { type: Function }
84
- },
85
- setup(n) {
86
- const l = n, t = W(), s = qe(), g = Ke(), i = W(!1), r = W(null), c = W(!1), x = M(() => {
87
- switch (l.action) {
88
- case oe.enum.approveDraft:
89
- return "Approve";
90
- case oe.enum.rejectDraft:
91
- return "Reject";
92
- case oe.enum.markAsFailed:
93
- return "Mark as Failed";
94
- }
95
- throw new Error(`Unknown action: ${l.action}`);
96
- }), A = M(() => {
97
- switch (l.action) {
98
- case oe.enum.approveDraft:
99
- return "primary";
100
- case oe.enum.rejectDraft:
101
- return "destructive";
102
- case oe.enum.markAsFailed:
103
- return "destructive";
104
- }
105
- throw new Error(`Unknown action: ${l.action}`);
106
- });
107
- kt(() => {
108
- if (l.draft.effectiveAt)
109
- r.value = new Date(l.draft.effectiveAt);
110
- else {
111
- const F = new Date(l.draft.createdAt);
112
- F.setHours(23, 59, 59, 999), r.value = F;
113
- }
114
- c.value = !0;
115
- });
116
- const f = M({
117
- get() {
118
- return r.value === null ? "" : rt(r.value);
119
- },
120
- set(F) {
121
- if (F) {
122
- const _ = /* @__PURE__ */ new Date(`${F} ${B.value}`);
123
- _.setSeconds(59, 999), r.value = _;
124
- } else
125
- r.value = null;
126
- }
127
- }), B = M({
128
- get() {
129
- return r.value === null ? "" : Gt(r.value);
130
- },
131
- set(F) {
132
- if (F) {
133
- const _ = /* @__PURE__ */ new Date(`${f.value} ${F}`);
134
- _.setSeconds(59, 999), r.value = _;
135
- } else
136
- r.value = null;
137
- }
138
- }), N = M(() => r.value ? r.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
139
- async function E(F) {
140
- i.value = !0;
141
- try {
142
- F ? await s.runOperationV1({
143
- _id: l.draft._id,
144
- _rev: l.draft._rev ?? "",
145
- action: l.action,
146
- data: {
147
- effectiveAt: r.value ? r.value.toISOString() : null,
148
- remark: t.value
149
- }
150
- }).delayed(500) : await s.runOperation({
151
- _id: l.draft._id,
152
- _rev: l.draft._rev ?? "",
153
- action: l.action,
154
- data: {
155
- effectiveAt: r.value ? r.value.toISOString() : null,
156
- remark: t.value
157
- }
158
- }).delayed(500), g.open({
159
- title: "Success",
160
- message: "Action submitted",
161
- type: "success"
162
- }), l.onFinished();
163
- } catch (_) {
164
- g.open({
165
- title: "Something went wrong",
166
- message: (_ == null ? void 0 : _.message) ?? "Unable to submit action. Please try again",
167
- type: "error"
168
- }), console.error("error on submit closing draft action", _);
169
- } finally {
170
- i.value = !1;
171
- }
172
- }
173
- return (F, _) => {
174
- const R = Z("FmLabel"), p = Z("FmDatePicker"), v = Z("FmTimePicker"), d = Z("FmTextField"), b = Z("FmButton"), y = Z("FmForm");
175
- return c.value ? (h(), ae(y, {
176
- key: 1,
177
- onValidationSuccess: E,
178
- class: "flex flex-col gap-32",
179
- disabled: i.value
180
- }, {
181
- default: X(() => [
182
- o("div", Qn, [
183
- _[4] || (_[4] = de(" You are about to ")),
184
- o("span", Zn, H(x.value), 1),
185
- _[5] || (_[5] = de(" this draft. Please provide a remark to justify this action. "))
186
- ]),
187
- F.action === u(oe).enum.approveDraft ? (h(), T("div", Jn, [
188
- $(R, { class: "fm-typo-en-body-lg-600" }, {
189
- default: X(() => _[6] || (_[6] = [
190
- de("Closing Date")
191
- ])),
192
- _: 1
193
- }),
194
- $(p, {
195
- modelValue: f.value,
196
- "onUpdate:modelValue": _[0] || (_[0] = (w) => f.value = w),
197
- max: u(rt)(/* @__PURE__ */ new Date())
198
- }, null, 8, ["modelValue", "max"]),
199
- $(R, { class: "fm-typo-en-body-lg-600" }, {
200
- default: X(() => _[7] || (_[7] = [
201
- de("Closing Time")
202
- ])),
203
- _: 1
204
- }),
205
- $(v, {
206
- modelValue: B.value,
207
- "onUpdate:modelValue": _[1] || (_[1] = (w) => B.value = w)
208
- }, null, 8, ["modelValue"]),
209
- N.value ? (h(), T("div", Xn, " Cannot select future date ")) : K("", !0)
210
- ])) : K("", !0),
211
- $(d, {
212
- modelValue: t.value,
213
- "onUpdate:modelValue": _[2] || (_[2] = (w) => t.value = w),
214
- label: "Remark",
215
- "label-mark": "required",
216
- rules: [u(Tn)()]
217
- }, null, 8, ["modelValue", "rules"]),
218
- o("div", ea, [
219
- $(b, {
220
- label: "Cancel",
221
- variant: "tertiary",
222
- onClick: _[3] || (_[3] = (w) => F.onCancel())
223
- }),
224
- $(b, {
225
- label: x.value,
226
- type: "submit",
227
- variant: A.value,
228
- loading: i.value
229
- }, null, 8, ["label", "variant", "loading"])
230
- ])
231
- ]),
232
- _: 1
233
- }, 8, ["disabled"])) : (h(), T(ce, { key: 0 }, [
234
- de("Loading")
235
- ], 64));
236
- };
237
- }
238
- }), ta = He(0);
239
- function an(n) {
240
- const l = n.measurementsAmounts.groupBy((s) => s.measurement.id), t = n.sku.unit.measurements.reduce((s, g) => {
241
- var c, x;
242
- const i = ((x = (c = l.get(g.id)) == null ? void 0 : c[0]) == null ? void 0 : x.amount) ?? ta, r = lt(g.conversion, i);
243
- return s + +ht(r);
244
- }, +ht(n.baseAmount));
245
- return Qt(t, n.baseAmount.precision);
246
- }
247
- const na = He(0), aa = He(100);
248
- function oa(n, l, t, s, g, i, r, c) {
249
- var z, le, P, S, ie;
250
- const x = an(n), A = s ?? x, f = Zt(A, l), B = l.amount === 0 ? null : Jt(f, {
251
- ...l,
252
- amount: Math.abs(l.amount)
253
- }), N = B ? lt(B, aa) : null, E = ((z = n.sku.defaultCost) == null ? void 0 : z.costPerUnit) ?? { amount: 0, precision: 0 }, F = Number(te.toFormatString({ value: E })), _ = ((P = (le = n.sku.defaultCost) == null ? void 0 : le.measurement) == null ? void 0 : P.conversion) ?? {
254
- amount: 1,
255
- precision: 0
256
- }, R = Number(
257
- te.toFormatString({ value: _ })
258
- ), p = g ? Number(te.toFormatString({ value: g })) : 0, v = Number(te.toFormatString({ value: l })), d = Number(te.toFormatString({ value: A })), b = d - v, y = b * F / R, w = d * F / R, Y = v * F / R, q = {};
259
- return r && i && r.forEach((L) => {
260
- const I = { amount: 0, precision: 0 }, Q = i[L];
261
- if (Q) {
262
- const se = Xt(I, Q);
263
- q[`adjustment_${L}`] = ht(se);
264
- } else
265
- q[`adjustment_${L}`] = "0";
266
- }), {
267
- code: n.sku.code,
268
- name: n.sku.name,
269
- baseUnit: n.sku.unit.abbrev,
270
- costUnit: ((ie = (S = n.sku.defaultCost) == null ? void 0 : S.measurement) == null ? void 0 : ie.abbrev) ?? null,
271
- baseUnitAmount: Number(te.toFormatString({ value: n.baseAmount })),
272
- ...t.reduce(
273
- (L, I, Q) => {
274
- const se = te.toFormatString({ value: I.conversion }), we = I.orphan ? " [invalid UOM]" : I.inactive ? " [NetSuite-inactive]" : "";
275
- return L[`measurementAbbrev${Q}`] = `(${I.abbrev}) × ${se}${we}`, L[`measurementAmount${Q}`] = Number(te.toFormatString({ value: I.amount })), L;
276
- },
277
- {}
278
- ),
279
- systemBalance: v,
280
- physicalBalance: d,
281
- adjustedAmount: Number(te.toFormatString({ value: f })),
282
- adjustedDiffPercentage: N ? Number(
283
- te.toFormatString({
284
- value: en(N, 2)
285
- })
286
- ) : null,
287
- costPerUnit: F,
288
- opening: p,
289
- ...q,
290
- varianceQty: b,
291
- varianceInCost: y,
292
- stockTakeValue: w,
293
- systemValue: Y,
294
- // Include custom attribute values
295
- ...(c ?? []).reduce(
296
- (L, I) => {
297
- var se;
298
- const Q = (se = n.sku.customAttributes) == null ? void 0 : se[I];
299
- return L[`customAttr_${I}`] = Q != null ? String(Q) : null, L;
300
- },
301
- {}
302
- )
303
- };
304
- }
305
- function sa(n) {
306
- let l = 0;
307
- for (const t of n.values())
308
- t.length > l && (l = t.length);
309
- return l;
310
- }
311
- function ra(n, l) {
312
- const t = /* @__PURE__ */ new Map();
313
- for (const s of n) {
314
- if (t.has(s.sku._id)) continue;
315
- const g = new Map(s.sku.unit.measurements.map((c) => [c.id, c])), i = new Map(
316
- s.measurementsAmounts.map((c) => [c.measurement.id, c.amount])
317
- ), r = [];
318
- for (const c of s.sku.unit.measurements) {
319
- const x = i.get(c.id);
320
- x && r.push({
321
- id: c.id,
322
- abbrev: c.abbrev,
323
- conversion: c.conversion,
324
- amount: x,
325
- inactive: tn(c, l),
326
- orphan: !1
327
- });
328
- }
329
- for (const c of s.measurementsAmounts)
330
- g.has(c.measurement.id) || r.push({
331
- id: c.measurement.id,
332
- abbrev: c.measurement.abbrev,
333
- conversion: c.measurement.conversion,
334
- amount: c.amount,
335
- inactive: !1,
336
- orphan: !0
337
- });
338
- t.set(s.sku._id, r);
339
- }
340
- return t;
341
- }
342
- function la(n, l = [], t = []) {
343
- const s = Wt(), g = s === "MYR" ? "RM" : s;
344
- return [
345
- {
346
- id: "code",
347
- name: "Code"
348
- },
349
- {
350
- id: "name",
351
- name: "Name"
352
- },
353
- {
354
- id: "baseUnit",
355
- name: "Base unit"
356
- },
357
- {
358
- id: "costPerUnit",
359
- name: "Cost per unit"
360
- },
361
- {
362
- id: "costUnit",
363
- name: "UOM"
364
- },
365
- {
366
- id: "opening",
367
- name: "Opening (B/F)"
368
- },
369
- // Dynamic adjustment type columns
370
- ...l.map((r) => ({
371
- id: `adjustment_${r}`,
372
- name: Be(r)
373
- })),
374
- {
375
- id: "systemBalance",
376
- name: "System balance (Qty)"
377
- },
378
- {
379
- id: "physicalBalance",
380
- name: "Stock take (Qty)"
381
- },
382
- {
383
- id: "adjustedAmount",
384
- name: "Variance"
385
- },
386
- {
387
- id: "varianceInCost",
388
- name: `Variance (${g})`
389
- },
390
- {
391
- id: "adjustedDiffPercentage",
392
- name: "Variance (%)"
393
- },
394
- {
395
- id: "stockTakeValue",
396
- name: `Stock take value (${g})`
397
- },
398
- {
399
- id: "systemValue",
400
- name: `System value (${g})`
401
- },
402
- {
403
- id: "baseUnitAmount",
404
- name: "Base unit amount"
405
- },
406
- ...Array.from({ length: n }).flatMap((r, c) => [
407
- {
408
- id: `measurementAmount${c}`,
409
- name: `UOM amount ${c + 1}`
410
- },
411
- {
412
- id: `measurementAbbrev${c}`,
413
- name: `UOM ${c + 1}`
414
- }
415
- ]),
416
- // Dynamic custom attribute columns
417
- ...t.map((r) => ({
418
- id: `customAttr_${r}`,
419
- name: Be(r)
420
- }))
421
- ];
422
- }
423
- function ia(n, l, t, s = [], g) {
424
- var re, z, le, P, S, ie, L;
425
- const i = l.groupBy(
426
- (I) => I.id,
427
- (I) => I.balance
428
- ), r = t.groupBy(
429
- (I) => I.id,
430
- (I) => I.balance
431
- ), c = /* @__PURE__ */ new Map();
432
- if (n.opening)
433
- for (const I of n.opening)
434
- c.set(I.skuId, I.balance);
435
- const x = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Map();
436
- if (n.adjustmentSnapshot)
437
- for (const I of n.adjustmentSnapshot)
438
- I.adjustmentsByType && (Object.keys(I.adjustmentsByType).forEach((Q) => x.add(Q)), A.set(I.skuId, I.adjustmentsByType));
439
- const f = ["receive", "sales", "wastage"], B = [];
440
- f.forEach((I) => {
441
- x.has(I) && (B.push(I), x.delete(I));
442
- });
443
- const N = Array.from(x).sort(), E = [...B, ...N], F = [...n.items, ...n.negativeStockItems ?? []], R = Yt().currentBusiness.value, p = ra(F, g), v = F.map((I) => {
444
- var De, $e;
445
- const Q = ((De = i.get(I.sku._id)) == null ? void 0 : De[0]) ?? na, se = p.get(I.sku._id) ?? [], we = c.get(I.sku._id), xe = A.get(I.sku._id);
446
- return oa(
447
- I,
448
- Q,
449
- se,
450
- ($e = r.get(I.sku._id)) == null ? void 0 : $e[0],
451
- we,
452
- xe,
453
- E,
454
- s
455
- );
456
- }), d = sa(p), b = la(d, E, s), y = [
457
- ["Business name:", R == null ? void 0 : R.name],
458
- ["Business ID:", R == null ? void 0 : R._id],
459
- ["Menu version", R == null ? void 0 : R.menuVersion],
460
- ["Created at", new Date(n.createdAt)],
461
- ["Created by", (re = n.createdBy) == null ? void 0 : re.name],
462
- ["Updated at", new Date(n.updatedAt)],
463
- ["Updated by", (z = n.updatedBy) == null ? void 0 : z.name],
464
- ["Recent action", n.approvedAt ? "Approve" : n.rejectionHistory ? "Reject" : ""],
465
- [
466
- "Action by",
467
- n.approvedAt ? (le = n.approvedBy) == null ? void 0 : le.name : n.rejectionHistory ? (S = (P = n.rejectionHistory[0]) == null ? void 0 : P.rejectedBy) == null ? void 0 : S.name : ""
468
- ],
469
- [
470
- "Action at",
471
- n.approvedAt ? new Date(n.approvedAt) : n.rejectionHistory ? new Date((ie = n.rejectionHistory[0]) == null ? void 0 : ie.rejectedAt) : ""
472
- ],
473
- [
474
- "Action remark",
475
- n.approvedAt ? n.approveRemark : n.rejectionHistory ? new Date((L = n.rejectionHistory[0]) == null ? void 0 : L.rejectRemark) : ""
476
- ],
477
- [],
478
- b.map((I) => I.name),
479
- ...v.map((I) => b.map((Q) => I[Q.id]))
480
- ], w = b.map((I) => `system:${I.id}`), Y = jn(y, w), q = `[${R == null ? void 0 : R.name}] closing draft (${Bn(new Date(n.updatedAt))}).xlsx`;
481
- return Mn(Y, q), q;
482
- }
483
- const ca = { class: "flex flex-col" }, ua = {
484
- key: 0,
485
- class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
486
- }, da = { class: "flex gap-12 py-8 justify-end w-full" }, ma = /* @__PURE__ */ je({
487
- __name: "RefreshBalanceAction",
488
- props: {
489
- draft: {},
490
- onCancel: { type: Function },
491
- onFinished: { type: Function }
492
- },
493
- setup(n) {
494
- const l = n;
495
- ct();
496
- const t = W(!1), s = W(null), g = W(!1);
497
- kt(() => {
498
- if (l.draft.effectiveAt)
499
- s.value = new Date(l.draft.effectiveAt);
500
- else {
501
- const A = new Date(l.draft.createdAt);
502
- A.setHours(23, 59, 59, 999), s.value = A;
503
- }
504
- g.value = !0;
505
- });
506
- const i = M({
507
- get() {
508
- return s.value === null ? "" : rt(s.value);
509
- },
510
- set(A) {
511
- if (A) {
512
- const f = /* @__PURE__ */ new Date(`${A} ${r.value}`);
513
- f.setSeconds(59, 999), s.value = f;
514
- } else
515
- s.value = null;
516
- }
517
- }), r = M({
518
- get() {
519
- return s.value === null ? "" : Gt(s.value);
520
- },
521
- set(A) {
522
- if (A) {
523
- const f = /* @__PURE__ */ new Date(`${i.value} ${A}`);
524
- f.setSeconds(59, 999), s.value = f;
525
- } else
526
- s.value = null;
527
- }
528
- }), c = M(() => s.value ? s.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
529
- async function x() {
530
- t.value = !0, l.onFinished(s.value.toISOString());
531
- }
532
- return (A, f) => {
533
- const B = Z("FmLabel"), N = Z("FmDatePicker"), E = Z("FmTimePicker"), F = Z("FmButton"), _ = Z("FmForm");
534
- return g.value ? (h(), ae(_, {
535
- key: 1,
536
- onValidationSuccess: x,
537
- class: "flex flex-col gap-32",
538
- disabled: t.value
539
- }, {
540
- default: X(() => [
541
- f[5] || (f[5] = o("div", { class: "fm-typo-en-body-lg-400" }, [
542
- o("p", null, [
543
- de(" Performing "),
544
- o("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
545
- de(" until closing effective date and time. ")
546
- ]),
547
- o("p", { class: "mt-2" }, [
548
- de(" Please note that this action will "),
549
- o("b", null, "update"),
550
- de(" the effective date and time. ")
551
- ])
552
- ], -1)),
553
- o("div", ca, [
554
- $(B, { class: "fm-typo-en-body-lg-600" }, {
555
- default: X(() => f[3] || (f[3] = [
556
- de("Closing Date")
557
- ])),
558
- _: 1
559
- }),
560
- $(N, {
561
- modelValue: i.value,
562
- "onUpdate:modelValue": f[0] || (f[0] = (R) => i.value = R),
563
- max: u(rt)(/* @__PURE__ */ new Date())
564
- }, null, 8, ["modelValue", "max"]),
565
- $(B, { class: "fm-typo-en-body-lg-600" }, {
566
- default: X(() => f[4] || (f[4] = [
567
- de("Closing Time")
568
- ])),
569
- _: 1
570
- }),
571
- $(E, {
572
- modelValue: r.value,
573
- "onUpdate:modelValue": f[1] || (f[1] = (R) => r.value = R)
574
- }, null, 8, ["modelValue"]),
575
- c.value ? (h(), T("div", ua, " Cannot select future date ")) : K("", !0)
576
- ]),
577
- o("div", da, [
578
- $(F, {
579
- label: "Cancel",
580
- variant: "tertiary",
581
- onClick: f[2] || (f[2] = (R) => A.onCancel())
582
- }),
583
- $(F, {
584
- label: "Refresh balance",
585
- type: "submit",
586
- variant: "primary",
587
- loading: t.value,
588
- disabled: c.value
589
- }, null, 8, ["loading", "disabled"])
590
- ])
591
- ]),
592
- _: 1
593
- }, 8, ["disabled"])) : (h(), T(ce, { key: 0 }, [
594
- de("Loading")
595
- ], 64));
596
- };
597
- }
598
- }), it = qt(
599
- "closingDraftActions",
600
- function() {
601
- const l = An(), t = Ke(), s = ct(), g = qe(), i = Un(), r = nn(), c = W(!1), x = W();
602
- function A(b) {
603
- const y = {
604
- draft: b
605
- };
606
- x.value = y, c.value = !0;
607
- }
608
- async function f(b) {
609
- var w;
610
- if (b.status === _e.enum.COMPLETED) {
611
- const Y = b.closingAdjustmentId;
612
- if (!Y)
613
- return t.open({
614
- title: "Something went wrong",
615
- message: "Closing draft is completed but closing document cannot be found.",
616
- type: "error"
617
- }), console.error("Closing draft is completed but closing document cannot be found.", {
618
- draftId: b._id
619
- }), [];
620
- const q = await s.readAdjustmentById(Y);
621
- return ((q == null ? void 0 : q.skus) ?? []).map((z) => ({
622
- id: z.sku._id,
623
- balance: z.fromBalance,
624
- costs: z.fromCostBalances
625
- }));
626
- } else
627
- return await i.readStockBalance(), ((w = i.stockBalance) == null ? void 0 : w.skus) ?? [];
628
- }
629
- async function B(b, y, w, Y) {
630
- y || (t.open({
631
- title: "Exporting",
632
- message: "Fetching data..."
633
- }), y = await f(b)), ia(
634
- b,
635
- y,
636
- w ?? [],
637
- Y ?? [],
638
- r.value
639
- );
640
- }
641
- function N(b, y, w) {
642
- l.open({
643
- title: "Approve draft",
644
- contentComponent: bt,
645
- contentComponentProps: {
646
- draft: b,
647
- action: oe.enum.approveDraft,
648
- onFinished: () => {
649
- l.close(), y == null || y();
650
- },
651
- onCancel: () => {
652
- l.close();
653
- }
654
- }
655
- }).onClose(() => {
656
- w == null || w();
657
- });
658
- }
659
- function E(b, y) {
660
- l.open({
661
- title: "Reject draft",
662
- contentComponent: bt,
663
- contentComponentProps: {
664
- draft: b,
665
- action: oe.enum.rejectDraft,
666
- onFinished: () => {
667
- l.close(), y == null || y();
668
- },
669
- onCancel: () => l.close()
670
- }
671
- });
672
- }
673
- function F(b, y) {
674
- l.open({
675
- title: "Mark draft as failed",
676
- contentComponent: bt,
677
- contentComponentProps: {
678
- draft: b,
679
- action: oe.enum.markAsFailed,
680
- onFinished: () => {
681
- l.close(), y == null || y();
682
- },
683
- onCancel: () => l.close()
684
- }
685
- });
686
- }
687
- async function _(b, y) {
688
- await g.sync({
689
- _id: b._id,
690
- _rev: b._rev ?? "",
691
- action: oe.enum.approveDraft,
692
- data: {
693
- remark: b.remark ?? ""
694
- }
695
- }).delayed(500), t.open({
696
- title: "Success",
697
- message: "Sync requested",
698
- type: "success"
699
- }), y == null || y();
700
- }
701
- function R() {
702
- c.value = !1;
703
- }
704
- async function p(b, y, w) {
705
- await l.open({
706
- title: "Refresh balance",
707
- contentComponent: ma,
708
- contentComponentProps: {
709
- draft: b,
710
- onFinished: (Y) => {
711
- l.close(), w == null || w(Y);
712
- },
713
- onCancel: async () => {
714
- l.close(), y == null || y();
715
- }
716
- }
717
- });
718
- }
719
- async function v(b) {
720
- await l.open({
721
- title: "Invalidate closing draft cache",
722
- message: "It will invalidate opening and stock movement cache for this draft.",
723
- primaryActions: { text: "Proceed", close: !0 },
724
- secondaryActions: { text: "Cancel", close: !0 }
725
- }).onPrimary(async () => {
726
- await s.recalculation.scheduleInvalidateClosingDraftCache([b._id]), t.open({
727
- title: "Success",
728
- message: "Invalidate cache requested",
729
- type: "success"
730
- });
731
- });
732
- }
733
- async function d(b, y) {
734
- try {
735
- t.open({
736
- title: "Cloning",
737
- message: "Creating a copy of the draft..."
738
- }), await g.cloneDraft(b._id), t.open({
739
- title: "Success",
740
- message: "Draft cloned successfully",
741
- type: "success"
742
- }), y == null || y();
743
- } catch (w) {
744
- t.open({
745
- title: "Error",
746
- message: (w == null ? void 0 : w.message) || "Failed to clone draft",
747
- type: "error"
748
- });
749
- }
750
- }
751
- return {
752
- viewDraft: A,
753
- closeDraftDialog: R,
754
- approveDraft: N,
755
- rejectDraft: E,
756
- markAsFailed: F,
757
- syncDraft: _,
758
- exportDraft: B,
759
- refreshBalance: p,
760
- cloneDraft: d,
761
- viewClosingDraftShow: c,
762
- viewClosingDraftProps: x,
763
- invalidateDraftCache: v
764
- };
765
- }
766
- );
767
- function st(n) {
768
- switch (n) {
769
- case "DRAFT":
770
- return "fm-status-badge-draft";
771
- case "PROCESSING":
772
- return "fm-status-badge-processing";
773
- case "FAILED":
774
- return "fm-status-badge-cancel";
775
- case "COMPLETED":
776
- return "fm-status-badge-complete";
777
- }
778
- }
779
- const on = qt(
780
- "closingDraftTable",
781
- function() {
782
- const { t: l } = Ye(), t = Yt(), s = it(), g = W(new Array()), i = W(0), r = W(!1), c = We(), x = qe();
783
- async function A() {
784
- if (g.value = [], !!c._currentLocation) {
785
- r.value = !0;
786
- try {
787
- const [p] = await Promise.all([x.readDrafts()]).delayed(1e3);
788
- g.value = B(p.reverse());
789
- } catch (p) {
790
- console.log("Something went wrong when fetching drafts:", p);
791
- } finally {
792
- r.value = !1;
793
- }
794
- }
795
- }
796
- async function f(p) {
797
- if (!g.value.find((v) => v._id) && c._currentLocation) {
798
- r.value = !0;
799
- try {
800
- const [v] = await Promise.all([
801
- x.getDraft(p),
802
- new Promise((d) => setTimeout(d, 1e3))
803
- ]);
804
- g.value = B([v]);
805
- } catch (v) {
806
- console.log("Something went wrong when fetching drafts:", v);
807
- } finally {
808
- r.value = !1;
809
- }
810
- }
811
- }
812
- function B(p) {
813
- const v = Nn(
814
- p.filter((d) => !!d.closingId).map((d) => ({ closingId: d.closingId, draftCreatedAt: new Date(Te(d._id)) }))
815
- );
816
- return p.map((d) => ({
817
- ...d,
818
- closingIdDisplay: d.closingId ? v.get(d.closingId) ?? null : null
819
- }));
820
- }
821
- function N(p) {
822
- g.value = g.value.map((v) => v._id === p._id ? {
823
- ...p,
824
- _rev: p._rev,
825
- closingIdDisplay: v.closingIdDisplay
826
- } : v), i.value++;
827
- }
828
- function E(p) {
829
- var b, y;
830
- const v = p.items.length + (((b = p.negativeStockItems) == null ? void 0 : b.length) ?? 0), d = (p == null ? void 0 : p.approveRemark) ?? ((y = p == null ? void 0 : p.rejectionHistory) == null ? void 0 : y.computeFirst((w) => w.rejectRemark)) ?? p.remark ?? "";
831
- return { count: v, remark: d };
832
- }
833
- function F() {
834
- s.closeDraftDialog(), A();
835
- }
836
- function _(p, v) {
837
- switch (v = $n(v), p) {
838
- case Ne.Details:
839
- return s.viewDraft(v);
840
- case Ne.Export:
841
- return s.exportDraft(v);
842
- case oe.enum.approveDraft:
843
- return s.approveDraft(v, F);
844
- case oe.enum.rejectDraft:
845
- return s.rejectDraft(v, F);
846
- case oe.enum.markAsFailed:
847
- return s.markAsFailed(v, F);
848
- case Ne.Duplicate:
849
- return s.cloneDraft(v, F);
850
- }
851
- }
852
- return {
853
- columnDefs: [
854
- {
855
- id: "_id",
856
- accessorKey: "_id",
857
- header: () => l("inventory.closing.table.createdAt"),
858
- cell(p) {
859
- return Vn(`${p.getValue()}`);
860
- },
861
- sortingFn: (p, v) => new Date(Te(p.original._id)).getTime() - new Date(Te(v.original._id)).getTime(),
862
- enableSorting: !0
863
- },
864
- {
865
- id: "closingId",
866
- accessorFn: (p) => p.closingIdDisplay,
867
- size: 160,
868
- header: () => l("inventory.closing.draft.table.id"),
869
- cell(p) {
870
- return p.getValue();
871
- },
872
- enableSorting: !0
873
- },
874
- {
875
- accessorKey: "effectiveAt",
876
- header: () => l("inventory.closing.draft.table.effectiveAt"),
877
- cell(p) {
878
- const v = p.row.original;
879
- let d = p.getValue();
880
- return d || (d = Te(v._id)), Ce(d);
881
- },
882
- enableSorting: !0,
883
- size: 230
884
- },
885
- {
886
- id: "description",
887
- accessorFn: (p) => {
888
- const { count: v, remark: d } = E(p);
889
- return `${v} ${d}`;
890
- },
891
- header: () => l("inventory.closing.draft.table.description"),
892
- enableSorting: !0,
893
- size: 350,
894
- cell(p) {
895
- const { count: v, remark: d } = E(p.row.original), b = (y, w) => k("div", { class: "flex gap-4" }, [
896
- k(
897
- "span",
898
- { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" },
899
- `${y}:`
900
- ),
901
- k(
902
- "span",
903
- {
904
- class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
905
- style: "white-space: pre-wrap; word-break: break-word;"
906
- },
907
- `${w}`
908
- )
909
- ]);
910
- return k("div", { class: "flex flex-col gap-2", style: "width: 300px;" }, [
911
- b(l("inventory.closing.draft.table.items"), v),
912
- d ? b(l("inventory.closing.draft.table.remark"), d) : null
913
- ]);
914
- }
915
- },
916
- {
917
- id: "status",
918
- accessorFn: (p) => p.status,
919
- header: () => l("inventory.closing.table.status"),
920
- enableSorting: !1,
921
- cell(p) {
922
- var Y;
923
- const v = p.row.original, d = v.status, b = new Date(v.updatedAt), y = (Y = v == null ? void 0 : v.rejectionHistory) == null ? void 0 : Y.computeFirst((q) => q.rejectedAt), w = y ? new Date(y) : null;
924
- return d === "DRAFT" && w ? w.getTime() > b.getTime() ? k(
925
- "div",
926
- {
927
- class: "flex"
928
- },
929
- k(
930
- "div",
931
- {
932
- class: ["fm-status-badge", st("FAILED")]
933
- },
934
- "Rejected"
935
- )
936
- ) : k(
937
- "div",
938
- {
939
- class: "flex"
940
- },
941
- k(
942
- "div",
943
- {
944
- class: ["fm-status-badge", st("PROCESSING")]
945
- },
946
- "Updated"
947
- )
948
- ) : k(
949
- "div",
950
- {
951
- class: "flex"
952
- },
953
- k(
954
- "div",
955
- {
956
- class: ["fm-status-badge", st(d)]
957
- },
958
- Be(d)
959
- )
960
- );
961
- }
962
- },
963
- {
964
- id: "updatedAt",
965
- accessorFn: (p) => p.updatedAt,
966
- header: () => l("inventory.closing.draft.table.lastUpdate"),
967
- enableSorting: !0,
968
- size: 200,
969
- cell(p) {
970
- var d;
971
- const v = p.row.original;
972
- return k("div", { class: "flex flex-col" }, [
973
- k(
974
- "div",
975
- { class: "fm-typo-en-body-md-600 text-fm-color-typo-primary" },
976
- ((d = v.updatedBy) == null ? void 0 : d.name) ?? ""
977
- ),
978
- k(
979
- "div",
980
- { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
981
- Ce(v.updatedAt)
982
- )
983
- ]);
984
- }
985
- },
986
- {
987
- id: "action",
988
- cell(p) {
989
- var Y;
990
- const v = p.row.original, d = ((Y = t.sessionUser.value) == null ? void 0 : Y.role.isAdmin) ?? !1, b = [
991
- Lt[Ne.Details],
992
- Lt[Ne.Export]
993
- ], y = [
994
- {
995
- translationKey: "inventory.closing.draft.approveDraft",
996
- color: "text-fm-color-typo-primary",
997
- value: oe.enum.approveDraft
998
- },
999
- {
1000
- translationKey: "inventory.closing.draft.rejectDraft",
1001
- color: "text-fm-color-typo-error",
1002
- value: oe.enum.rejectDraft
1003
- },
1004
- {
1005
- translationKey: "inventory.closing.draft.markAsFailed",
1006
- color: "text-fm-color-typo-error",
1007
- value: oe.enum.markAsFailed
1008
- }
1009
- ], w = d && v.status !== _e.enum.DRAFT ? [
1010
- {
1011
- translationKey: "inventory.closing.draft.cloneDraft",
1012
- color: "text-fm-color-typo-primary",
1013
- value: Ne.Duplicate
1014
- }
1015
- ] : [];
1016
- return Pn(
1017
- [
1018
- ...b,
1019
- ...v.status === _e.enum.DRAFT ? y : []
1020
- ],
1021
- (q) => _(q, v),
1022
- w
1023
- );
1024
- },
1025
- enableSorting: !1,
1026
- size: 40,
1027
- meta: {
1028
- cellClass: "",
1029
- headerClass: ""
1030
- }
1031
- }
1032
- ],
1033
- drafts: g,
1034
- loading: r,
1035
- tableKey: i,
1036
- fetchDrafts: A,
1037
- loadDraft: f,
1038
- updateDraftRef: N
1039
- };
1040
- }
1041
- ), fa = { class: "fm-typo-en-heading-lg-600" }, pa = { class: "py-4" }, va = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, ya = { key: 0 }, ga = { class: "mt-4 flex gap-4" }, ba = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, ha = { key: 0 }, ka = {
1042
- key: 0,
1043
- class: "mb-4"
1044
- }, _a = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full" }, wa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, xa = {
1045
- key: 0,
1046
- class: "text-fm-color-system-success-300 mr-1"
1047
- }, Da = {
1048
- key: 1,
1049
- class: "text-fm-color-system-error-300 mr-1"
1050
- }, Aa = { class: "fm-typo-en-body-md-400" }, Ca = { class: "mt-4 flex gap-4" }, Sa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, $a = {
1051
- key: 0,
1052
- class: "flex gap-4"
1053
- }, Ia = /* @__PURE__ */ je({
1054
- __name: "ClosingDraftApprovalDialog",
1055
- props: {
1056
- show: { type: Boolean },
1057
- refreshing: { type: Boolean },
1058
- approving: { type: Boolean },
1059
- draft: {}
1060
- },
1061
- emits: ["update:show", "refresh", "approve"],
1062
- setup(n, { emit: l }) {
1063
- const { FmStepper: t, FmStep: s, FmDialog: g, FmButton: i } = pe, { t: r } = Ln(), c = wt(), x = n, A = l, f = M(
1064
- () => {
1065
- var P, S;
1066
- return ((P = x.draft) == null ? void 0 : P.stockSnapshot) && ((S = x.draft) == null ? void 0 : S.stockSnapshot) !== void 0;
1067
- }
1068
- ), B = M(() => {
1069
- var ie, L, I;
1070
- const P = ((ie = x.draft) == null ? void 0 : ie.items.map((Q) => ({
1071
- id: Q.sku._id,
1072
- code: Q.sku.code,
1073
- name: Q.sku.name
1074
- }))) ?? [], S = ((I = (L = x.draft) == null ? void 0 : L.negativeStockItems) == null ? void 0 : I.map((Q) => ({
1075
- id: Q.sku._id,
1076
- code: Q.sku.code,
1077
- name: Q.sku.name
1078
- }))) ?? [];
1079
- return [...P, ...S].reduce(
1080
- (Q, se) => (Q[se.id] = se, Q),
1081
- {}
1082
- );
1083
- }), N = M(
1084
- () => {
1085
- var P, S, ie;
1086
- return (((ie = (S = (P = x.draft) == null ? void 0 : P.stockSnapshot) == null ? void 0 : S.filter((L) => L.balance.amount < 0)) == null ? void 0 : ie.map((L) => {
1087
- const I = c.skuById[L.id];
1088
- return I ? {
1089
- id: I._id,
1090
- code: I.code,
1091
- name: I.name
1092
- } : null;
1093
- })) ?? []).filter((L) => L !== null);
1094
- }
1095
- ), E = M(() => {
1096
- var P;
1097
- return f.value ? ((P = N.value) == null ? void 0 : P.filter((S) => !B.value[S.id]).map((S) => S.id)) ?? [] : [];
1098
- }), F = M({
1099
- get: () => x.show,
1100
- set: (P) => A("update:show", P)
1101
- }), _ = W(1), R = () => _.value > 1, p = () => _.value > 2, v = () => !1;
1102
- function d(P) {
1103
- return P === 1 ? f.value : P === 2 ? E.value.length == 0 : !1;
1104
- }
1105
- const b = M(() => !f.value || E.value.length > 0);
1106
- function y(P) {
1107
- let S = P + 1;
1108
- for (; S <= 3 && d(S); ) S++;
1109
- return S > 3 ? 3 : S;
1110
- }
1111
- function w(P) {
1112
- let S = P - 1;
1113
- for (; S >= 1 && d(S); ) S--;
1114
- return S < 1 ? 1 : S;
1115
- }
1116
- function Y() {
1117
- return f.value ? b.value ? 3 : 2 : 1;
1118
- }
1119
- ze(
1120
- () => x.show,
1121
- (P) => {
1122
- P && (_.value = Y());
1123
- }
1124
- ), ze(
1125
- () => f.value,
1126
- (P) => {
1127
- P && _.value === 1 && (_.value = y(1));
1128
- }
1129
- ), ze(
1130
- () => E.value.length,
1131
- (P) => {
1132
- P === 0 && _.value === 2 && (_.value = y(2));
1133
- }
1134
- );
1135
- function q() {
1136
- A("refresh");
1137
- }
1138
- function re() {
1139
- _.value < 3 && (_.value = y(_.value));
1140
- }
1141
- function z() {
1142
- _.value > 1 && (_.value = w(_.value));
1143
- }
1144
- function le() {
1145
- A("approve");
1146
- }
1147
- return (P, S) => {
1148
- const ie = Z("FmIcon");
1149
- return h(), ae(u(g), {
1150
- modelValue: F.value,
1151
- "onUpdate:modelValue": S[1] || (S[1] = (L) => F.value = L),
1152
- "max-width": 600
1153
- }, {
1154
- "dialog-header": X(() => [
1155
- o("div", fa, H(u(r)("inventory.closing.approval.title")), 1)
1156
- ]),
1157
- default: X(() => [
1158
- o("div", pa, [
1159
- $(u(t), {
1160
- modelValue: _.value,
1161
- "onUpdate:modelValue": S[0] || (S[0] = (L) => _.value = L),
1162
- orientation: "vertical"
1163
- }, {
1164
- default: X(() => [
1165
- $(u(s), {
1166
- value: 1,
1167
- title: u(r)("inventory.closing.approval.step.generateReport.title"),
1168
- complete: R
1169
- }, {
1170
- default: X(() => [
1171
- o("div", va, H(u(r)("inventory.closing.approval.step.generateReport.description")), 1),
1172
- _.value === 1 ? (h(), T("div", ya, [
1173
- $(u(i), {
1174
- label: u(r)("inventory.stock.stock_balance.refreshBalance"),
1175
- "prepend-icon": "refresh",
1176
- variant: "secondary",
1177
- loading: P.refreshing,
1178
- disabled: P.refreshing,
1179
- onClick: q
1180
- }, null, 8, ["label", "loading", "disabled"]),
1181
- o("div", ga, [
1182
- $(u(i), {
1183
- label: u(r)("inventory.common.continue"),
1184
- disabled: !f.value,
1185
- onClick: re
1186
- }, null, 8, ["label", "disabled"])
1187
- ])
1188
- ])) : K("", !0)
1189
- ]),
1190
- _: 1
1191
- }, 8, ["title"]),
1192
- $(u(s), {
1193
- value: 2,
1194
- title: u(r)("inventory.closing.approval.step.negativeItems.title"),
1195
- disabled: () => !f.value,
1196
- complete: p
1197
- }, {
1198
- default: X(() => [
1199
- o("div", ba, H(N.value.length > 0 ? `${u(r)("inventory.closing.approval.step.negativeItems.resolveMessage")} [${u(r)("inventory.closing.approval.step.negativeItems.itemsHeader")} (${E.value.length})]` : u(r)("inventory.closing.approval.step.negativeItems.noItemsMessage")), 1),
1200
- _.value === 2 ? (h(), T("div", ha, [
1201
- N.value.length > 0 ? (h(), T("div", ka, [
1202
- S[2] || (S[2] = o("div", { class: "fm-typo-en-body-md-600 mb-2" }, null, -1)),
1203
- o("div", _a, [
1204
- (h(!0), T(ce, null, he(N.value, (L) => (h(), T("div", {
1205
- key: L.id,
1206
- class: "flex gap-8"
1207
- }, [
1208
- o("div", wa, [
1209
- B.value[L.id] ? (h(), T("span", xa, [
1210
- $(ie, {
1211
- name: "check_circle",
1212
- size: "sm"
1213
- })
1214
- ])) : (h(), T("span", Da, [
1215
- $(ie, {
1216
- name: "error",
1217
- size: "sm"
1218
- })
1219
- ])),
1220
- de(" " + H(L.code), 1)
1221
- ]),
1222
- o("div", Aa, H(L.name), 1)
1223
- ]))), 128))
1224
- ])
1225
- ])) : K("", !0),
1226
- o("div", Ca, [
1227
- $(u(i), {
1228
- label: u(r)("inventory.common.back"),
1229
- variant: "secondary",
1230
- onClick: z
1231
- }, null, 8, ["label"]),
1232
- $(u(i), {
1233
- label: u(r)("inventory.common.continue"),
1234
- disabled: b.value,
1235
- onClick: re
1236
- }, null, 8, ["label", "disabled"])
1237
- ])
1238
- ])) : K("", !0)
1239
- ]),
1240
- _: 1
1241
- }, 8, ["title", "disabled"]),
1242
- $(u(s), {
1243
- value: 3,
1244
- title: u(r)("inventory.closing.approval.step.approval.title"),
1245
- disabled: () => b.value,
1246
- complete: v
1247
- }, {
1248
- default: X(() => [
1249
- o("div", Sa, H(u(r)("inventory.closing.approval.step.approval.warning")), 1),
1250
- _.value === 3 ? (h(), T("div", $a, [
1251
- $(u(i), {
1252
- label: u(r)("inventory.common.back"),
1253
- variant: "secondary",
1254
- onClick: z
1255
- }, null, 8, ["label"]),
1256
- $(u(i), {
1257
- label: u(r)("inventory.common.approve"),
1258
- variant: "destructive",
1259
- disabled: b.value,
1260
- loading: P.approving,
1261
- onClick: le
1262
- }, null, 8, ["label", "disabled", "loading"])
1263
- ])) : K("", !0)
1264
- ]),
1265
- _: 1
1266
- }, 8, ["title", "disabled"])
1267
- ]),
1268
- _: 1
1269
- }, 8, ["modelValue"])
1270
- ])
1271
- ]),
1272
- _: 1
1273
- }, 8, ["modelValue"]);
1274
- };
1275
- }
1276
- });
1277
- function Fa(n) {
1278
- const l = qe(), t = Rn(), s = Ke(), { t: g } = Ye(), i = W(!1), r = W(null);
1279
- let c = !1, x = null, A = !1, f = !1;
1280
- function B() {
1281
- R();
1282
- const d = n.closingDraftId.value, b = n.currentRev.value;
1283
- if (!d || !b)
1284
- return;
1285
- c = !1;
1286
- const y = {
1287
- type: "closing-draft",
1288
- params: {
1289
- draftId: d,
1290
- locationId: l.getDbName(),
1291
- closingDraftRevision: b
1292
- }
1293
- }, { unsubscribe: w, initialState: Y } = t.subscribe(y, E);
1294
- x = w, Y.then((q) => {
1295
- q != null && q.initialState && E(q.initialState);
1296
- }).catch((q) => {
1297
- console.error("Failed to fetch initial state", q);
1298
- });
1299
- }
1300
- function N() {
1301
- f = !0, B();
1302
- }
1303
- async function E(d) {
1304
- var y;
1305
- if (c || !d) {
1306
- r.value = d, i.value = !1;
1307
- return;
1308
- }
1309
- if (d.closingDraftId && d.closingDraftId !== n.closingDraftId.value)
1310
- return;
1311
- if (r.value = d, d.message === "processing" || !d.completedAt && !d.message) {
1312
- A = !0, i.value = !0;
1313
- return;
1314
- }
1315
- if (d.message === "completed" || d.completedAt) {
1316
- if (!A) {
1317
- i.value = !1;
1318
- return;
1319
- }
1320
- A = !1, await F();
1321
- return;
1322
- }
1323
- const b = A;
1324
- A = !1, i.value = !1, b && (console.log("Closing draft balance refresh error:", d), s.open({
1325
- title: g("inventory.common.refreshFailed"),
1326
- message: g("inventory.stock.stock_balance.refreshBalanceError"),
1327
- type: "error"
1328
- }), (y = n.onError) == null || y.call(n, d.message ?? "Unknown error"));
1329
- }
1330
- async function F() {
1331
- const d = n.closingDraftId.value;
1332
- if (!d) {
1333
- i.value = !1;
1334
- return;
1335
- }
1336
- try {
1337
- const b = await l.getDraft(d);
1338
- i.value = !1, n.onCompleted(b), s.open({
1339
- title: "Balance refreshed",
1340
- message: "Stock balance has been recalculated.",
1341
- type: "success"
1342
- });
1343
- } catch {
1344
- i.value = !1, s.open({
1345
- title: "Refresh completed",
1346
- message: "Balance was refreshed but failed to load updated data. Please reload.",
1347
- type: "warning"
1348
- });
1349
- }
1350
- }
1351
- async function _(d) {
1352
- if (!(!n.closingDraftId.value || i.value || A)) {
1353
- i.value = !0, A = !0, r.value = {
1354
- requestId: "",
1355
- closingDraftId: n.closingDraftId.value,
1356
- closingDraftRevision: n.currentRev.value ?? "",
1357
- message: "processing",
1358
- startedAt: (/* @__PURE__ */ new Date()).toISOString()
1359
- };
1360
- try {
1361
- await l.initializeStockSnapshot(n.closingDraftId.value, d);
1362
- } catch (b) {
1363
- A = !1, i.value = !1, s.open({
1364
- title: g("inventory.common.refreshFailed"),
1365
- message: g("inventory.stock.stock_balance.refreshBalanceError"),
1366
- type: "error"
1367
- }), console.error("error starting refresh", b);
1368
- }
1369
- }
1370
- }
1371
- function R() {
1372
- c = !1, x && (x(), x = null);
1373
- }
1374
- function p() {
1375
- R(), c = !0, i.value = !1, A = !1, r.value = null;
1376
- }
1377
- function v() {
1378
- f = !1, p();
1379
- }
1380
- return ze(
1381
- [n.closingDraftId, n.currentRev],
1382
- ([d, b], [y, w]) => {
1383
- f && (d === y && b === w || B());
1384
- }
1385
- ), hn(() => {
1386
- v();
1387
- }), {
1388
- refreshing: i,
1389
- refreshStatus: r,
1390
- startListening: N,
1391
- startRefresh: _,
1392
- cleanup: v
1393
- };
1394
- }
1395
- const Ba = { class: "w-full flex flex-col gap-32" }, Ta = { class: "flex flex-col gap-4" }, ja = { class: "flex justify-between" }, Ma = { class: "flex" }, Ua = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, Ra = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Pa = { class: "flex gap-1" }, Va = {
1396
- class: "fm-typo-en-body-lg-600",
1397
- style: { "white-space": "pre-wrap", "word-break": "break-word" }
1398
- }, Na = {
1399
- key: 0,
1400
- class: "flex items-start gap-8 p-12 fm-corner-radius-md border-1 border-yellow-500 bg-yellow-50 text-yellow-700"
1401
- }, za = { class: "flex flex-col gap-2" }, Ea = { class: "fm-typo-en-body-sm-400 list-disc pl-16" }, La = { key: 0 }, Oa = { key: 1 }, Ha = { class: "flex flex-col gap-16" }, Ya = { class: "flex items-center" }, Ka = {
1402
- key: 0,
1403
- class: "flex gap-8"
1404
- }, Wa = {
1405
- key: 0,
1406
- class: "w-full flex flex-col items-center"
1407
- }, qa = { class: "flex items-center gap-8" }, Ga = { class: "flex flex-col gap-8" }, Qa = { class: "flex gap-8" }, Za = {
1408
- key: 0,
1409
- class: "flex gap-8"
1410
- }, Ja = {
1411
- key: 1,
1412
- class: "flex gap-8 flex-wrap"
1413
- }, Xa = { class: "overflow-x-auto" }, eo = {
1414
- key: 1,
1415
- class: "flex-1 xs:w-screen xs:max-w-full"
1416
- }, to = {
1417
- key: 0,
1418
- class: "flex flex-col items-center gap-8 h-full"
1419
- }, no = ["src"], ao = {
1420
- key: 1,
1421
- class: "px-4 flex flex-col"
1422
- }, oo = { class: "flex gap-12 content-stretch" }, so = {
1423
- class: "flex flex-col w-24",
1424
- name: "circles"
1425
- }, ro = { class: "flex-1 flex flex-col items-center" }, lo = { class: "flex-1 flex flex-col items-center" }, io = {
1426
- class: "py-12 flex flex-col gap-4",
1427
- name: "received-at header"
1428
- }, co = { class: "fm-typo-en-body-lg-400" }, uo = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, mo = { class: "flex gap-12 content-stretch" }, fo = {
1429
- class: "flex flex-col w-24",
1430
- name: "circles"
1431
- }, po = { class: "flex-1 flex flex-col items-center" }, vo = {
1432
- class: "py-12 flex flex-col gap-4 flex-1",
1433
- name: "delivery details"
1434
- }, yo = { class: "flex flex-col gap-8" }, go = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, bo = { class: "flex flex-col gap-4" }, ho = { class: "flex items-center justify-between gap-8 w-full" }, ko = { class: "flex items-center gap-8" }, _o = { class: "flex flex-col items-end" }, wo = { class: "text-2xl font-semibold" }, Ot = "N/A", xo = /* @__PURE__ */ je({
1435
- __name: "ClosingDraftDialog",
1436
- props: {
1437
- show: { type: Boolean },
1438
- draft: {}
1439
- },
1440
- emits: ["submitted", "refresh"],
1441
- setup(n, { emit: l }) {
1442
- const t = n, s = M(() => {
1443
- const a = Wt();
1444
- return a === "MYR" ? "RM" : a;
1445
- }), g = on(), i = M(() => {
1446
- var a, e;
1447
- return (a = t.draft) != null && a.closingId ? ((e = g.drafts.find((m) => m._id === t.draft._id)) == null ? void 0 : e.closingIdDisplay) ?? null : null;
1448
- }), r = it(), c = Kt(t, "show"), x = W(!1), A = W(!1), f = W(new Array()), B = W(new Array()), N = W([]), E = ct(), F = Ke(), _ = wt(), R = We(), p = Et({}), v = M(() => new Set(
1449
- _.skus.filter((a) => {
1450
- var e;
1451
- return p[(e = a.customAttributes) == null ? void 0 : e.tag];
1452
- }).map((a) => a._id)
1453
- )), d = l, b = M(() => {
1454
- var a;
1455
- return (a = t.draft) == null ? void 0 : a._id;
1456
- }), y = M(() => {
1457
- var a;
1458
- return (a = t.draft) == null ? void 0 : a._rev;
1459
- }), {
1460
- refreshing: w,
1461
- startListening: Y,
1462
- startRefresh: q,
1463
- cleanup: re
1464
- } = Fa({
1465
- closingDraftId: b,
1466
- currentRev: y,
1467
- onCompleted: (a) => {
1468
- d("refresh", a), f.value = a.stockSnapshot ?? [], c.value = !1;
1469
- }
1470
- }), z = W({
1471
- templateItem: !0,
1472
- nonTemplateItem: !0
1473
- }), le = W(null);
1474
- function P(a, e) {
1475
- le.value = e ? a : le.value === a ? null : le.value;
1476
- }
1477
- const S = (a) => ne(a, { minPrecision: 0, maxPrecision: 3 });
1478
- function ie(a, e) {
1479
- return e ? "text-fm-color-system-error-300" : a ? "text-purple-500" : "";
1480
- }
1481
- function L(a, e) {
1482
- return e ? k(pe.FmIcon, { name: "warning", size: "sm", color: "system-error-300" }) : a ? k(pe.FmIcon, { name: "rule", size: "sm" }) : null;
1483
- }
1484
- function I(a) {
1485
- return k(
1486
- "div",
1487
- {
1488
- class: "p-12 flex flex-col gap-4 fm-typo-en-body-md-400 min-w-[280px] max-w-[420px]"
1489
- },
1490
- [
1491
- k("div", { class: "fm-typo-en-body-sm-600 text-fm-color-typo-secondary mb-4" }, "Breakdown"),
1492
- ...a.breakdown.map(
1493
- (e) => k("div", { class: "flex justify-between gap-12" }, [
1494
- k(
1495
- "div",
1496
- { class: ["flex items-center gap-4", ie(e.inactive, e.orphan)] },
1497
- [L(e.inactive, e.orphan), k("span", e.label)]
1498
- ),
1499
- k(
1500
- "div",
1501
- { class: e.counted ? "" : "line-through text-fm-color-typo-tertiary" },
1502
- e.orphan ? `${S(e.amount)} ${e.abbrev} (no valid conversion)` : e.counted ? `${S(e.subtotal)} ${a.baseUnit}` : `${S(e.subtotal)} ${a.baseUnit} (ignored)`
1503
- )
1504
- ])
1505
- ),
1506
- k("hr", { class: "border-fm-color-typo-secondary my-4" }),
1507
- k("div", { class: "flex justify-between fm-typo-en-body-lg-600" }, [
1508
- k("span", "Total"),
1509
- k("span", `${S(a.physicalBalance)} ${a.baseUnit}`)
1510
- ])
1511
- ]
1512
- );
1513
- }
1514
- const Q = M(() => {
1515
- var e, m;
1516
- const a = [...((e = t.draft) == null ? void 0 : e.items) ?? [], ...((m = t.draft) == null ? void 0 : m.negativeStockItems) ?? []];
1517
- return v.value.size ? a.filter((j) => v.value.has(j.sku._id)) : a;
1518
- }), se = M(() => {
1519
- const a = Q.value.map((e) => e.sku);
1520
- return a.sort((e, m) => e.code.localeCompare(m.code)), a;
1521
- }), we = nn();
1522
- kt(Ee), ze(
1523
- () => t.show,
1524
- async (a) => {
1525
- if (!a) {
1526
- re();
1527
- return;
1528
- }
1529
- Oe.value = ft[0], Ee(), z.value = {
1530
- templateItem: !0,
1531
- nonTemplateItem: !0
1532
- }, le.value = null, Y();
1533
- },
1534
- { immediate: !0 }
1535
- );
1536
- const xe = M(() => Qe.value.reduce((a, e) => a + Number(e.stockTakeValue), 0)), De = He(0), $e = He(100);
1537
- async function Ee() {
1538
- var e, m, j, D;
1539
- if (!R._currentLocation) return;
1540
- x.value = !0;
1541
- const a = ((e = t.draft) == null ? void 0 : e.status) === _e.enum.COMPLETED;
1542
- B.value = [];
1543
- try {
1544
- if (await _.init(), a) {
1545
- const G = t.draft.closingAdjustmentId;
1546
- if (!G) {
1547
- F.open({
1548
- title: "Something went wrong",
1549
- message: "Closing draft is completed but closing document cannot be found.",
1550
- type: "error"
1551
- }), console.error("Closing draft is completed but closing document cannot be found.", {
1552
- draftId: (m = t.draft) == null ? void 0 : m._id
1553
- });
1554
- return;
1555
- }
1556
- const me = await E.readAdjustmentById(G), Ae = (me == null ? void 0 : me.skus) ?? [];
1557
- for (const ge of Ae) {
1558
- const Ie = {
1559
- id: ge.sku._id,
1560
- balance: ge.fromBalance,
1561
- costs: ge.fromCostBalances
1562
- }, U = {
1563
- id: ge.sku._id,
1564
- balance: ge.toBalance,
1565
- costs: ge.toCostBalances
1566
- };
1567
- f.value.push(Ie), B.value.push(U);
1568
- }
1569
- } else
1570
- f.value = ((j = t.draft) == null ? void 0 : j.stockSnapshot) ?? [];
1571
- const V = /* @__PURE__ */ new Set();
1572
- if ((D = t.draft) != null && D.adjustmentSnapshot)
1573
- for (const G of t.draft.adjustmentSnapshot)
1574
- G.adjustmentsByType && Object.keys(G.adjustmentsByType).forEach((me) => {
1575
- V.add(me);
1576
- });
1577
- const C = ["receive", "sales", "wastage"], J = [];
1578
- C.forEach((G) => {
1579
- V.has(G) && (J.push(G), V.delete(G));
1580
- });
1581
- const O = Array.from(V).sort();
1582
- N.value = [...J, ...O];
1583
- } catch (V) {
1584
- F.open({
1585
- title: "Something went wrong",
1586
- message: "Something went wrong when fetching info. Please try again.",
1587
- type: "error"
1588
- }), console.error("error on fetch stock balances", V);
1589
- } finally {
1590
- x.value = !1;
1591
- }
1592
- }
1593
- async function Le() {
1594
- var e, m;
1595
- if (w.value)
1596
- return;
1597
- if (!(((e = t.draft) == null ? void 0 : e.effectiveAt) ?? (t.draft ? Te((m = t.draft) == null ? void 0 : m._id) : null))) {
1598
- F.open({
1599
- title: "Cannot refresh",
1600
- message: "Effective date is not available for this draft.",
1601
- type: "error"
1602
- });
1603
- return;
1604
- }
1605
- await r.refreshBalance(
1606
- t.draft,
1607
- () => {
1608
- },
1609
- async (j) => {
1610
- await q(j);
1611
- }
1612
- );
1613
- }
1614
- async function Me() {
1615
- var e, m;
1616
- if (!(((e = t.draft) == null ? void 0 : e.effectiveAt) ?? (t.draft ? Te((m = t.draft) == null ? void 0 : m._id) : null))) {
1617
- F.open({
1618
- title: "Cannot refresh",
1619
- message: "Effective date is not available for this draft.",
1620
- type: "error"
1621
- });
1622
- return;
1623
- }
1624
- await r.invalidateDraftCache(t.draft);
1625
- }
1626
- const Ge = M(
1627
- () => f.value.groupBy(
1628
- (a) => a.id,
1629
- (a) => a.balance
1630
- )
1631
- ), ut = M(() => Q.value.groupBy((a) => a.sku._id)), sn = M(() => {
1632
- var a;
1633
- return (a = t.draft) != null && a.adjustmentSnapshot ? new Map(t.draft.adjustmentSnapshot.map((e) => [e.skuId, e.adjustmentsByType])) : /* @__PURE__ */ new Map();
1634
- }), rn = M(() => {
1635
- var a;
1636
- return (a = t.draft) != null && a.opening ? new Map(t.draft.opening.map((e) => [e.skuId, e.balance])) : /* @__PURE__ */ new Map();
1637
- });
1638
- function ye(a, e) {
1639
- return k(
1640
- pe.FmTooltip,
1641
- { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
1642
- {
1643
- default() {
1644
- return a;
1645
- },
1646
- content() {
1647
- return e || a;
1648
- }
1649
- }
1650
- );
1651
- }
1652
- const xt = M(() => [
1653
- {
1654
- id: "sku",
1655
- accessorFn: (e) => `${e.code} ${e.name}`,
1656
- header: () => "Name",
1657
- size: 350,
1658
- cell(e) {
1659
- const m = e.row.original, j = m.adjustedDiffPercentage, D = typeof j == "number" && Math.abs(j) > 10, V = k("div", { class: "flex flex-col gap-4" }, [
1660
- k(
1661
- "div",
1662
- {
1663
- class: [
1664
- "line-clamp-1 fm-typo-en-body-lg-400",
1665
- D ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
1666
- ]
1667
- },
1668
- m.name
1669
- ),
1670
- k(
1671
- "div",
1672
- {
1673
- class: [
1674
- "line-clamp-1 fm-typo-en-body-md-400",
1675
- D ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
1676
- ]
1677
- },
1678
- m.code
1679
- )
1680
- ]);
1681
- return k(
1682
- pe.FmTooltip,
1683
- {
1684
- zIndex: 51
1685
- },
1686
- {
1687
- content() {
1688
- return D ? "Adjustment difference is more than 10%." : `${m.code} - ${m.name}`;
1689
- },
1690
- default() {
1691
- return k("div", { class: "flex items-center gap-4 justify-start w-full" }, [
1692
- V
1693
- ]);
1694
- }
1695
- }
1696
- );
1697
- }
1698
- },
1699
- // Dynamic custom attribute columns (toggled by user)
1700
- ...Ct.value.map(
1701
- (e) => ({
1702
- id: `customAttr_${e}`,
1703
- accessorFn: (m) => m.customAttributeValues[e],
1704
- header: () => ye(Be(e)),
1705
- size: 160,
1706
- cell(m) {
1707
- const j = m.row.original.customAttributeValues[e];
1708
- return j == null ? "N/A" : typeof j == "number" ? k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(j)) : k("div", { class: "text-right fm-typo-en-body-lg-400" }, String(j));
1709
- },
1710
- meta: {
1711
- textAlign: "right"
1712
- }
1713
- })
1714
- ),
1715
- {
1716
- id: "costPerUnit",
1717
- accessorKey: "costPerUnit",
1718
- header: () => ye("Cost per unit"),
1719
- size: 160,
1720
- cell(e) {
1721
- const m = e.row.original.costPerUnit;
1722
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(m));
1723
- },
1724
- meta: {
1725
- textAlign: "right"
1726
- }
1727
- },
1728
- {
1729
- id: "costUnit",
1730
- header: () => "UOM",
1731
- size: 120,
1732
- cell(e) {
1733
- var C;
1734
- const m = e.row.original, j = m.costUnit, D = m.baseUnit, V = j ?? D;
1735
- if (j && j !== D) {
1736
- const J = se.value.find((G) => G._id === m.id), O = (C = J == null ? void 0 : J.defaultCost) == null ? void 0 : C.measurement;
1737
- if (O) {
1738
- const G = O.conversion.amount / Math.pow(10, O.conversion.precision);
1739
- return k("div", { class: "flex flex-col" }, [
1740
- k(
1741
- "span",
1742
- { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1743
- V
1744
- ),
1745
- k("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, [
1746
- "1 ",
1747
- k("span", { class: "fm-typo-en-body-sm-600" }, j),
1748
- ` = ${G} `,
1749
- k("span", { class: "fm-typo-en-body-sm-600" }, D)
1750
- ])
1751
- ]);
1752
- }
1753
- }
1754
- return V;
1755
- }
1756
- },
1757
- {
1758
- id: "opening",
1759
- accessorKey: "opening",
1760
- header: () => ye("Opening (B/F)", "The opening balance brought forward from previous period."),
1761
- size: 150,
1762
- cell(e) {
1763
- const m = e.row.original.opening;
1764
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(m));
1765
- },
1766
- meta: {
1767
- textAlign: "right"
1768
- }
1769
- },
1770
- // Dynamic adjustment type columns
1771
- ...N.value.map(
1772
- (e) => ({
1773
- id: `adjustment_${e}`,
1774
- accessorFn: (m) => m.adjustmentAmounts[e] ?? { amount: 0, precision: 0 },
1775
- header: () => ye(Be(e)),
1776
- size: 150,
1777
- cell(m) {
1778
- const j = m.row.original.adjustmentAmounts[e] ?? { amount: 0, precision: 0 };
1779
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(j));
1780
- },
1781
- meta: {
1782
- textAlign: "right"
1783
- }
1784
- })
1785
- ),
1786
- {
1787
- id: "systemBalance",
1788
- accessorKey: "systemBalance",
1789
- header: () => ye("System Balance", "The system calculated balance before stock take."),
1790
- size: 200,
1791
- cell(e) {
1792
- const m = e.row.original.systemBalance;
1793
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(m));
1794
- },
1795
- meta: {
1796
- textAlign: "right"
1797
- }
1798
- },
1799
- {
1800
- id: "physicalBalance",
1801
- accessorFn: (e) => {
1802
- var j;
1803
- const m = (j = B.value.find((D) => D.id === e.id)) == null ? void 0 : j.balance;
1804
- return m ? On.toDouble(m) : e.physicalBalance;
1805
- },
1806
- header: () => ye("Stock Take balance", "The physical balance recorded during stock take."),
1807
- cell(e) {
1808
- var O;
1809
- const m = e.row.original, j = te.fromNumber(m.physicalBalance);
1810
- let D = !0;
1811
- const V = (O = B.value.find((G) => G.id === m.id)) == null ? void 0 : O.balance;
1812
- let C;
1813
- V && !te.equals({ a: j, b: V }) ? (D = !1, C = ne(V)) : C = ne(m.physicalBalance);
1814
- const J = k("div", { class: "flex flex-col items-end" }, [
1815
- k(
1816
- "span",
1817
- { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
1818
- C
1819
- ),
1820
- D ? null : k(
1821
- "span",
1822
- { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
1823
- `Draft: ${ne(m.physicalBalance)}`
1824
- )
1825
- ]);
1826
- return m.breakdown.length ? k(
1827
- pe.FmPopover,
1828
- {
1829
- showPopover: le.value === m.id,
1830
- placement: "bottom-end",
1831
- zIndex: 9999,
1832
- "onPopover-changed": (G) => P(m.id, G)
1833
- },
1834
- {
1835
- "popover-button": () => k(
1836
- "button",
1837
- {
1838
- type: "button",
1839
- class: "flex items-center gap-4 ml-auto text-fm-color-typo-secondary hover:text-fm-color-typo-primary"
1840
- },
1841
- [
1842
- J,
1843
- k(pe.FmIcon, { name: "info", size: "sm", outline: !0 })
1844
- ]
1845
- ),
1846
- default: () => I(m)
1847
- }
1848
- ) : J;
1849
- },
1850
- size: 200,
1851
- meta: {
1852
- textAlign: "right"
1853
- }
1854
- },
1855
- {
1856
- id: "adjustedAmount",
1857
- accessorKey: "adjustedAmount",
1858
- header: () => ye("Variance", "The difference between Stock Take balance and System Balance."),
1859
- size: 200,
1860
- cell(e) {
1861
- const m = e.row.original.adjustedAmount;
1862
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(m));
1863
- },
1864
- meta: {
1865
- textAlign: "right"
1866
- }
1867
- },
1868
- {
1869
- id: "varianceInCost",
1870
- accessorKey: "varianceInCost",
1871
- header: () => ye(`Variance (${s.value})`),
1872
- size: 150,
1873
- cell(e) {
1874
- const m = e.row.original.varianceInCost;
1875
- return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ne(m));
1876
- },
1877
- meta: {
1878
- textAlign: "right"
1879
- }
1880
- },
1881
- {
1882
- id: "adjustedDiffPercentage",
1883
- accessorKey: "adjustedDiffPercentage",
1884
- header: () => ye(
1885
- "Variance (%)",
1886
- "Difference between Stock Take balance and System Balance in percentage."
1887
- ),
1888
- size: 200,
1889
- cell(e) {
1890
- const m = e.row.original.adjustedDiffPercentage;
1891
- if (m == null)
1892
- return k(
1893
- "div",
1894
- { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" },
1895
- Ot
1896
- );
1897
- const j = ne(m);
1898
- if (m === 0)
1899
- return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
1900
- ne(0)
1901
- ]);
1902
- const D = m > 0;
1903
- return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
1904
- k(pe.FmIcon, {
1905
- name: D ? "arrow_drop_up" : "arrow_drop_down",
1906
- color: D ? "system-success-300" : "system-error-300",
1907
- size: "md"
1908
- }),
1909
- j
1910
- ]);
1911
- },
1912
- meta: {
1913
- textAlign: "right"
1914
- }
1915
- },
1916
- {
1917
- id: "stockTakeValue",
1918
- accessorKey: "stockTakeValue",
1919
- header: () => ye(`Stock take value (${s.value})`),
1920
- size: 180,
1921
- cell(e) {
1922
- var O;
1923
- const m = e.row.original, j = m.stockTakeValue, D = se.value.find((G) => G._id === m.id), V = (O = D == null ? void 0 : D.defaultCost) == null ? void 0 : O.measurement, C = m.physicalBalance, J = m.costPerUnit;
1924
- if (V) {
1925
- const G = te.toFormatString({ value: V.conversion }), me = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${m.baseUnit} ÷ ${G} × ${J} ${s.value}`;
1926
- return k(
1927
- pe.FmTooltip,
1928
- { zIndex: 51 },
1929
- {
1930
- content() {
1931
- return me;
1932
- },
1933
- default() {
1934
- return k(
1935
- "div",
1936
- { class: "text-right w-full fm-typo-en-body-lg-400" },
1937
- ne(j)
1938
- );
1939
- }
1940
- }
1941
- );
1942
- } else {
1943
- const G = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${m.baseUnit} × ${J} ${s.value}`;
1944
- return k(
1945
- pe.FmTooltip,
1946
- { zIndex: 51 },
1947
- {
1948
- content() {
1949
- return G;
1950
- },
1951
- default() {
1952
- return k(
1953
- "div",
1954
- { class: "text-right w-full fm-typo-en-body-lg-400" },
1955
- ne(j)
1956
- );
1957
- }
1958
- }
1959
- );
1960
- }
1961
- },
1962
- meta: {
1963
- textAlign: "right"
1964
- }
1965
- },
1966
- {
1967
- id: "systemValue",
1968
- accessorKey: "systemValue",
1969
- header: () => ye(`System value (${s.value})`),
1970
- size: 180,
1971
- cell(e) {
1972
- var O;
1973
- const m = e.row.original, j = m.systemValue, D = se.value.find((G) => G._id === m.id), V = (O = D == null ? void 0 : D.defaultCost) == null ? void 0 : O.measurement, C = m.systemBalance, J = m.costPerUnit;
1974
- if (V) {
1975
- const G = te.toFormatString({ value: V.conversion }), me = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${m.baseUnit} ÷ ${G} × ${J} ${s.value}`;
1976
- return k(
1977
- pe.FmTooltip,
1978
- { zIndex: 51 },
1979
- {
1980
- content() {
1981
- return me;
1982
- },
1983
- default() {
1984
- return k(
1985
- "div",
1986
- { class: "text-right fm-typo-en-body-lg-400" },
1987
- ne(j)
1988
- );
1989
- }
1990
- }
1991
- );
1992
- } else {
1993
- const G = `${ne(C, { minPrecision: 2, maxPrecision: 4 })} ${m.baseUnit} × ${J} ${s.value}`;
1994
- return k(
1995
- pe.FmTooltip,
1996
- { zIndex: 51 },
1997
- {
1998
- content() {
1999
- return G;
2000
- },
2001
- default() {
2002
- return k(
2003
- "div",
2004
- { class: "text-right fm-typo-en-body-lg-400" },
2005
- ne(j)
2006
- );
2007
- }
2008
- }
2009
- );
2010
- }
2011
- },
2012
- meta: {
2013
- textAlign: "right"
2014
- }
2015
- },
2016
- {
2017
- id: "physicalBalances",
2018
- header: () => "Amounts",
2019
- enableSorting: !1,
2020
- cell(e) {
2021
- const m = e.row.original, j = (C, J, O = "normal") => k(
2022
- pe.FmTooltip,
2023
- { zIndex: 50 },
2024
- {
2025
- default() {
2026
- return k(
2027
- "div",
2028
- {
2029
- class: [
2030
- "fm-typo-en-body-lg-400 py-4 px-8 fm-corner-radius-md line-clamp-1 border-1",
2031
- O === "orphan" ? "border-fm-color-system-error-300" : O === "inactive" ? "border-purple-500" : "border-fm-color-typo-secondary"
2032
- ]
2033
- },
2034
- [
2035
- k("span", { class: "text-fm-color-typo-primary" }, `${C} `),
2036
- k(
2037
- "span",
2038
- {
2039
- class: "text-fm-color-typo-secondary",
2040
- style: { maxWidth: "80px" }
2041
- },
2042
- J
2043
- )
2044
- ]
2045
- );
2046
- },
2047
- content() {
2048
- return O === "orphan" ? `${C} ${J} (invalid UOM — not on SKU)` : O === "inactive" ? `${C} ${J} (NetSuite-inactive UOM)` : `${C} ${J}`;
2049
- }
2050
- }
2051
- ), D = m.measurements.filter((C) => !!C.amount).map((C) => j(C.amount, C.abbrev, C.variant)), V = m.baseUnitAmount || !D.length ? [j(m.baseUnitAmount, m.baseUnit), ...D] : D;
2052
- return k(
2053
- "div",
2054
- {
2055
- class: "flex gap-8 flex-nowrap",
2056
- style: { minWidth: `${120 * V.length}px` }
2057
- },
2058
- V
2059
- );
2060
- }
2061
- }
2062
- ]), ln = M(() => xt.value.map((a) => a.size ?? 0).reduce((a, e) => a + e)), dt = W(""), cn = M(() => {
2063
- var m, j;
2064
- const a = ((j = (m = t.draft) == null ? void 0 : m.negativeStockItems) == null ? void 0 : j.reduce(
2065
- (D, V) => (D[V.sku._id] = V, D),
2066
- {}
2067
- )) ?? {}, e = new Map(
2068
- B.value.map((D) => [D.id, D.balance])
2069
- );
2070
- return se.value.map((D) => {
2071
- var Bt, Tt, jt, Mt, Ut, Rt, Pt, Vt, Nt;
2072
- const V = (Bt = ut.value.get(D._id)) == null ? void 0 : Bt[0], C = ((Tt = Ge.value.get(D._id)) == null ? void 0 : Tt[0]) ?? De, J = ((jt = D.defaultCost) == null ? void 0 : jt.costPerUnit) ?? De, O = Number(te.toFormatString({ value: J })), G = ((Ut = (Mt = D.defaultCost) == null ? void 0 : Mt.measurement) == null ? void 0 : Ut.conversion) ?? {
2073
- amount: 1,
2074
- precision: 0
2075
- }, me = Number(
2076
- te.toFormatString({ value: G })
2077
- ), Ae = rn.value.get(D._id), ge = Ae ? Number(te.toFormatString({ value: Ae })) : 0, Ie = sn.value.get(D._id), U = {};
2078
- if (N.value.forEach((ee) => {
2079
- const be = U[ee] ?? { amount: 0, precision: 0 }, Fe = Ie == null ? void 0 : Ie[ee];
2080
- Fe && (U[ee] = Xt(be, Fe));
2081
- }), !V) {
2082
- const ee = Number(te.toFormatString({ value: C })), be = 0 - ee, Fe = be * O / me, nt = 0, Pe = ee * O / me;
2083
- return {
2084
- id: D._id,
2085
- code: D.code,
2086
- name: D.name,
2087
- costUnit: ((Pt = (Rt = D.defaultCost) == null ? void 0 : Rt.measurement) == null ? void 0 : Pt.abbrev) ?? null,
2088
- baseUnit: D.unit.abbrev,
2089
- baseUnitAmount: 0,
2090
- systemBalance: ee,
2091
- physicalBalance: 0,
2092
- adjustedAmount: -ee,
2093
- adjustedDiffPercentage: -100,
2094
- isTemplateItem: !a[D._id],
2095
- costPerUnit: O,
2096
- opening: ge,
2097
- varianceQty: be,
2098
- varianceInCost: Fe,
2099
- stockTakeValue: nt,
2100
- systemValue: Pe,
2101
- adjustmentAmounts: U,
2102
- customAttributeValues: D.customAttributes ?? {},
2103
- measurements: [],
2104
- breakdown: []
2105
- };
2106
- }
2107
- const ue = an(V), fe = e.get(D._id), ke = Zt(
2108
- fe ?? ue,
2109
- C
2110
- ), Re = C.amount === 0 ? null : Jt(ke, {
2111
- ...C,
2112
- amount: Math.abs(C.amount)
2113
- }), et = Re ? lt(Re, $e) : null, pt = Number(te.toFormatString({ value: C })), vt = Number(te.toFormatString({ value: ue })), $t = vt - pt, fn = $t * O / me, pn = vt * O / me, vn = pt * O / me, tt = Number(te.toFormatString({ value: V.baseAmount })), It = [], yt = [];
2114
- tt && yt.push({
2115
- label: "Base",
2116
- amount: tt,
2117
- abbrev: D.unit.abbrev,
2118
- subtotal: tt,
2119
- inactive: !1,
2120
- orphan: !1,
2121
- counted: !0
2122
- });
2123
- const yn = new Map(
2124
- V.measurementsAmounts.map((ee) => [ee.measurement.id, ee.amount])
2125
- ), gn = new Set(D.unit.measurements.map((ee) => ee.id)), Ft = (ee, be, Fe, nt, Pe) => {
2126
- const Ve = Number(te.toFormatString({ value: Fe })), zt = te.toFormatString({ value: be });
2127
- if (It.push({
2128
- abbrev: `(${ee}) × ${zt}`,
2129
- amount: Ve,
2130
- variant: Pe ? "orphan" : nt ? "inactive" : "normal"
2131
- }), !Ve) return;
2132
- const bn = Number(
2133
- te.toFormatString({ value: lt(Fe, be) })
2134
- );
2135
- yt.push({
2136
- label: Pe ? `${Ve} ${ee}` : `${Ve} ${ee} × ${zt} ${D.unit.abbrev}`,
2137
- amount: Ve,
2138
- abbrev: ee,
2139
- subtotal: bn,
2140
- inactive: nt,
2141
- orphan: Pe,
2142
- counted: !Pe
2143
- });
2144
- };
2145
- for (const ee of D.unit.measurements) {
2146
- const be = yn.get(ee.id);
2147
- be && Ft(ee.abbrev, ee.conversion, be, tn(ee, we.value), !1);
2148
- }
2149
- for (const ee of V.measurementsAmounts)
2150
- gn.has(ee.measurement.id) || Ft(ee.measurement.abbrev, ee.measurement.conversion, ee.amount, !1, !0);
2151
- return {
2152
- id: D._id,
2153
- code: D.code,
2154
- name: D.name,
2155
- costUnit: ((Nt = (Vt = D.defaultCost) == null ? void 0 : Vt.measurement) == null ? void 0 : Nt.abbrev) ?? null,
2156
- baseUnit: D.unit.abbrev,
2157
- baseUnitAmount: tt,
2158
- measurements: It,
2159
- breakdown: yt,
2160
- systemBalance: pt,
2161
- physicalBalance: vt,
2162
- adjustedAmount: Number(te.toFormatString({ value: ke })),
2163
- adjustedDiffPercentage: et ? Number(
2164
- te.toFormatString({
2165
- value: en(et, 2)
2166
- })
2167
- ) : null,
2168
- isTemplateItem: !a[D._id],
2169
- costPerUnit: O,
2170
- opening: ge,
2171
- varianceQty: $t,
2172
- varianceInCost: fn,
2173
- stockTakeValue: pn,
2174
- systemValue: vn,
2175
- adjustmentAmounts: U,
2176
- customAttributeValues: D.customAttributes ?? {}
2177
- };
2178
- });
2179
- }), Qe = M(() => cn.value.filter((a) => !!(a.isTemplateItem && z.value.templateItem || !a.isTemplateItem && z.value.nonTemplateItem))), Dt = M(
2180
- () => Qe.value.some((a) => a.measurements.some((e) => e.variant === "inactive"))
2181
- ), At = M(
2182
- () => Qe.value.some((a) => a.measurements.some((e) => e.variant === "orphan"))
2183
- ), un = M(
2184
- () => Dt.value || At.value
2185
- ), mt = M(() => {
2186
- const a = /* @__PURE__ */ new Set();
2187
- for (const e of se.value)
2188
- if (e.customAttributes)
2189
- for (const m of Object.keys(e.customAttributes))
2190
- m !== "tag" && a.add(m);
2191
- return Array.from(a).sort();
2192
- }), Ze = Et({}), Ct = M(
2193
- () => mt.value.filter((a) => Ze[a])
2194
- ), dn = M(() => {
2195
- var e, m, j, D, V;
2196
- if (!t.draft) return [];
2197
- const a = t.draft.approvedAt ? {
2198
- action: `Approve at ${Ce(t.draft.approvedAt)}`,
2199
- // actionAt: props.draft.approvedAt,
2200
- actionBy: t.draft.approvedBy,
2201
- remark: t.draft.approveRemark
2202
- } : (e = t.draft.rejectionHistory) == null ? void 0 : e.computeFirst((C) => ({
2203
- action: `Reject at ${Ce(C.rejectedAt)}`,
2204
- // actionAt: e.rejectedAt,
2205
- actionBy: C.rejectedBy,
2206
- remark: C.rejectRemark
2207
- }));
2208
- return [
2209
- i.value ? {
2210
- label: "ID",
2211
- value: i.value
2212
- } : null,
2213
- {
2214
- label: "Location",
2215
- value: ((m = R._currentLocation) == null ? void 0 : m.name) ?? Ot
2216
- },
2217
- {
2218
- label: "Created at",
2219
- value: Ce(t.draft.createdAt)
2220
- },
2221
- {
2222
- label: "Created by",
2223
- value: t.draft.createdBy.name
2224
- },
2225
- {
2226
- label: "Updated at",
2227
- value: Ce(t.draft.updatedAt)
2228
- },
2229
- {
2230
- label: "Updated by",
2231
- value: t.draft.updatedBy.name
2232
- },
2233
- {
2234
- label: "Effective at",
2235
- value: Ce(t.draft.effectiveAt ?? Te((j = t.draft) == null ? void 0 : j._id))
2236
- },
2237
- {
2238
- label: "Using template",
2239
- value: ((D = t.draft.usingTemplates.find((C) => C)) == null ? void 0 : D.name) ?? "None"
2240
- },
2241
- t.draft.remark ? {
2242
- label: "Remark",
2243
- value: t.draft.remark
2244
- } : null,
2245
- a ? {
2246
- label: "Last action",
2247
- value: a.action
2248
- } : null,
2249
- a && a.actionBy ? {
2250
- label: "Last action by",
2251
- value: (V = a.actionBy) == null ? void 0 : V.name
2252
- } : null,
2253
- a && a.remark ? {
2254
- label: "Action remark",
2255
- value: a.remark
2256
- } : null
2257
- ].filter((C) => C).map((C) => C);
2258
- }), ft = [
2259
- {
2260
- label: "Overview",
2261
- value: "overview"
2262
- },
2263
- {
2264
- label: "Action history",
2265
- value: "history"
2266
- }
2267
- ], Oe = W(ft[0]), Ue = M(() => {
2268
- var j, D, V;
2269
- const a = ((j = t.draft) == null ? void 0 : j.activityLogs) ?? [], e = ((D = t.draft) == null ? void 0 : D.rejectionHistory) ?? [];
2270
- for (const C of e)
2271
- a.find(
2272
- (O) => `${O.action}_${O.performedAt}` == `${oe.enum.rejectDraft}_${C.rejectedAt}`
2273
- ) || a.push({
2274
- action: oe.enum.rejectDraft,
2275
- performedAt: C.rejectedAt,
2276
- performedBy: C.rejectedBy,
2277
- remark: C.rejectRemark
2278
- });
2279
- return (V = t.draft) != null && V.approvedAt && (a.find(
2280
- (J) => {
2281
- var O;
2282
- return `${J.action}_${J.performedAt}` == `${oe.enum.approveDraft}_${(O = t.draft) == null ? void 0 : O.approvedAt}`;
2283
- }
2284
- ) || a.push({
2285
- action: oe.enum.approveDraft,
2286
- performedAt: t.draft.approvedAt,
2287
- performedBy: t.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
2288
- remark: t.draft.approveRemark
2289
- })), a.sort((C, J) => new Date(J.performedAt).getTime() - new Date(C.performedAt).getTime()).map(
2290
- (C) => ({
2291
- header: Be(C.action),
2292
- date: Ce(C.performedAt),
2293
- info: [
2294
- {
2295
- label: "Performed by",
2296
- values: [C.performedBy.name]
2297
- },
2298
- {
2299
- label: "Remark",
2300
- values: [C.remark ?? ""]
2301
- }
2302
- ]
2303
- })
2304
- );
2305
- }), Je = W(!1), Xe = W(!1), St = M(() => {
2306
- var a;
2307
- return ((a = t.draft) == null ? void 0 : a.status) !== _e.enum.DRAFT ? "Status is not draft." : null;
2308
- });
2309
- function mn() {
2310
- t.draft && (Xe.value = !0, r.approveDraft(
2311
- t.draft,
2312
- () => {
2313
- Xe.value = !1, Je.value = !1, d("submitted");
2314
- },
2315
- () => {
2316
- Xe.value = !1;
2317
- }
2318
- ));
2319
- }
2320
- return (a, e) => {
2321
- const m = Z("FmButtonGroup"), j = Z("FmMenuDivider"), D = Z("FmCard"), V = Z("FmIcon"), C = Z("FmButton"), J = Z("FmCircularProgress"), O = Z("FmChip"), G = Z("FmTextField"), me = Z("FmTable"), Ae = Z("FmSpacer"), ge = Z("FmTooltip"), Ie = Z("FmSideSheet");
2322
- return h(), T(ce, null, [
2323
- $(Ie, {
2324
- "dismiss-away": "",
2325
- "max-width": 9999,
2326
- "model-value": u(c),
2327
- "onUpdate:modelValue": e[9] || (e[9] = (U) => _t(c) ? c.value = U : null),
2328
- header: "Closing details"
2329
- }, {
2330
- "side-sheet-footer": X(() => {
2331
- var U, ue, fe, ke;
2332
- return [
2333
- o("div", ho, [
2334
- o("div", ko, [
2335
- ((U = t.draft) == null ? void 0 : U.status) === u(_e).enum.DRAFT ? (h(), T(ce, { key: 0 }, [
2336
- St.value ? (h(), ae(ge, {
2337
- key: 0,
2338
- "z-index": 51,
2339
- placement: "right"
2340
- }, {
2341
- content: X(() => [
2342
- de(H(St.value), 1)
2343
- ]),
2344
- default: X(() => [
2345
- $(C, {
2346
- disabled: "",
2347
- key: "approve key",
2348
- label: "Approve"
2349
- })
2350
- ]),
2351
- _: 1
2352
- })) : (h(), ae(C, {
2353
- key: "approve key",
2354
- label: "Approve",
2355
- onClick: e[5] || (e[5] = (Re) => Je.value = !0)
2356
- }))
2357
- ], 64)) : K("", !0),
2358
- ((ue = t.draft) == null ? void 0 : ue.status) === u(_e).enum.DRAFT ? (h(), ae(C, {
2359
- key: 1,
2360
- label: "Reject",
2361
- variant: "destructive",
2362
- onClick: e[6] || (e[6] = () => t.draft && u(r).rejectDraft(t.draft, () => d("submitted")))
2363
- })) : K("", !0),
2364
- $(C, {
2365
- label: "Close",
2366
- variant: "tertiary",
2367
- onClick: e[7] || (e[7] = (Re) => c.value = !1)
2368
- }),
2369
- (fe = t.draft) != null && fe.approvedAt && ((ke = t.draft) == null ? void 0 : ke.status) !== u(_e).enum.COMPLETED ? (h(), ae(gt, { key: 2 }, {
2370
- default: X(() => [
2371
- $(C, {
2372
- label: "Sync",
2373
- loading: A.value,
2374
- onClick: e[8] || (e[8] = () => {
2375
- t.draft && (A.value = !0, u(r).syncDraft(t.draft, () => {
2376
- A.value = !1, d("submitted");
2377
- }));
2378
- })
2379
- }, null, 8, ["loading"])
2380
- ]),
2381
- _: 1
2382
- })) : K("", !0)
2383
- ]),
2384
- o("div", _o, [
2385
- e[23] || (e[23] = o("div", { class: "text-xs text-gray-500 uppercase tracking-wide" }, "Total stock take value", -1)),
2386
- o("div", wo, H(s.value) + " " + H(xe.value.toFixed(2)), 1)
2387
- ])
2388
- ])
2389
- ];
2390
- }),
2391
- default: X(() => [
2392
- o("div", Ba, [
2393
- o("div", null, [
2394
- $(m, {
2395
- items: ft,
2396
- modelValue: Oe.value,
2397
- "onUpdate:modelValue": e[0] || (e[0] = (U) => Oe.value = U)
2398
- }, null, 8, ["modelValue"])
2399
- ]),
2400
- Oe.value.value === "overview" ? (h(), T(ce, { key: 0 }, [
2401
- $(gt, { selectable: "" }, {
2402
- default: X(() => {
2403
- var U;
2404
- return [
2405
- o("div", Ta, [
2406
- e[11] || (e[11] = o("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, [
2407
- o("div", { class: "flex gap-1" }, "Draft ID")
2408
- ], -1)),
2409
- de(" " + H((U = a.draft) == null ? void 0 : U._id), 1)
2410
- ])
2411
- ];
2412
- }),
2413
- _: 1
2414
- }),
2415
- $(D, {
2416
- variant: "outlined",
2417
- class: "flex flex-col gap-8 px-12 py-16"
2418
- }, {
2419
- default: X(() => {
2420
- var U, ue;
2421
- return [
2422
- o("div", ja, [
2423
- e[12] || (e[12] = o("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
2424
- o("div", Ma, [
2425
- o("div", {
2426
- class: Se(["fm-status-badge", u(st)(((U = a.draft) == null ? void 0 : U.status) ?? "DRAFT")])
2427
- }, H(u(Be)(((ue = a.draft) == null ? void 0 : ue.status) ?? "")), 3)
2428
- ])
2429
- ]),
2430
- $(j),
2431
- o("div", Ua, [
2432
- (h(!0), T(ce, null, he(dn.value, (fe, ke) => (h(), T("div", {
2433
- class: "flex flex-col gap-4",
2434
- key: ke
2435
- }, [
2436
- o("div", Ra, [
2437
- o("div", Pa, H(fe.label), 1)
2438
- ]),
2439
- o("div", Va, H(fe.value), 1)
2440
- ]))), 128))
2441
- ])
2442
- ];
2443
- }),
2444
- _: 1
2445
- }),
2446
- un.value ? (h(), T("div", Na, [
2447
- $(V, {
2448
- name: "rule",
2449
- size: "sm"
2450
- }),
2451
- o("div", za, [
2452
- e[14] || (e[14] = o("div", { class: "fm-typo-en-body-md-600" }, "UOM notes", -1)),
2453
- o("ul", Ea, [
2454
- Dt.value ? (h(), T("li", La, e[13] || (e[13] = [
2455
- de(" Measurements highlighted in "),
2456
- o("span", { class: "font-bold" }, "purple", -1),
2457
- de(" are NetSuite-inactive UOMs (surfaced for audit; their amounts are part of the base total). ")
2458
- ]))) : K("", !0),
2459
- At.value ? (h(), T("li", Oa, " Red highlights are UOMs not on the SKU (ignored). ")) : K("", !0)
2460
- ])
2461
- ])
2462
- ])) : K("", !0),
2463
- o("div", Ha, [
2464
- o("div", Ya, [
2465
- e[15] || (e[15] = o("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
2466
- x.value ? K("", !0) : (h(), T("div", Ka, [
2467
- a.draft && a.draft.status !== u(_e).enum.COMPLETED ? (h(), ae(C, {
2468
- key: 0,
2469
- label: "Refresh balance",
2470
- "prepend-icon": "refresh",
2471
- variant: "secondary",
2472
- "text-color": "primary",
2473
- "bg-color": "transparent",
2474
- "border-color": "primary",
2475
- loading: u(w),
2476
- disabled: u(w),
2477
- onClick: Le
2478
- }, null, 8, ["loading", "disabled"])) : K("", !0),
2479
- $(gt, null, {
2480
- default: X(() => [
2481
- $(C, {
2482
- label: "Invalidate Draft Cache",
2483
- "prepend-icon": "refresh",
2484
- variant: "secondary",
2485
- "text-color": "primary",
2486
- "bg-color": "transparent",
2487
- "border-color": "primary",
2488
- loading: u(w),
2489
- onClick: Me
2490
- }, null, 8, ["loading"])
2491
- ]),
2492
- _: 1
2493
- }),
2494
- $(C, {
2495
- label: "Export data",
2496
- "prepend-icon": "download",
2497
- variant: "secondary",
2498
- "text-color": "primary",
2499
- "bg-color": "transparent",
2500
- "border-color": "primary",
2501
- onClick: e[1] || (e[1] = (U) => a.draft ? u(r).exportDraft(
2502
- a.draft,
2503
- f.value,
2504
- B.value,
2505
- Ct.value
2506
- ) : null)
2507
- })
2508
- ]))
2509
- ]),
2510
- x.value ? (h(), T("div", Wa, [
2511
- e[17] || (e[17] = o("div", { class: "h-80" }, null, -1)),
2512
- o("div", qa, [
2513
- o("div", null, [
2514
- $(J, { size: "md" })
2515
- ]),
2516
- e[16] || (e[16] = o("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
2517
- ]),
2518
- e[18] || (e[18] = o("div", { class: "h-80" }, null, -1))
2519
- ])) : (h(), T(ce, { key: 1 }, [
2520
- o("div", Ga, [
2521
- o("div", Qa, [
2522
- $(O, {
2523
- label: "Template Item(s)",
2524
- selected: z.value.templateItem,
2525
- onClick: e[2] || (e[2] = (U) => z.value.templateItem = !z.value.templateItem)
2526
- }, null, 8, ["selected"]),
2527
- $(O, {
2528
- label: "Non-template Item(s)",
2529
- selected: z.value.nonTemplateItem,
2530
- onClick: e[3] || (e[3] = (U) => z.value.nonTemplateItem = !z.value.nonTemplateItem)
2531
- }, null, 8, ["selected"])
2532
- ]),
2533
- $(G, {
2534
- modelValue: dt.value,
2535
- "onUpdate:modelValue": e[4] || (e[4] = (U) => dt.value = U),
2536
- placeholder: "Filter items"
2537
- }, null, 8, ["modelValue"])
2538
- ]),
2539
- u(_).skuTags.size ? (h(), T("div", Za, [
2540
- (h(!0), T(ce, null, he(u(_).skuTags.keys(), (U) => (h(), ae(O, {
2541
- key: `${U}`,
2542
- label: `${U}`,
2543
- selectable: "",
2544
- selected: p[`${U}`],
2545
- onClick: (ue) => p[`${U}`] = !p[`${U}`]
2546
- }, {
2547
- default: X(() => [
2548
- p[`${U}`] ? (h(), ae(V, {
2549
- key: 0,
2550
- name: "check",
2551
- class: "text-white",
2552
- size: "sm"
2553
- })) : K("", !0),
2554
- o("span", {
2555
- class: Se([
2556
- "",
2557
- {
2558
- "text-white fm-typo-en-body-md-600": p[`${U}`],
2559
- "text-fm-color-typo-primary fm-typo-en-body-md-400": !p[`${U}`]
2560
- }
2561
- ])
2562
- }, H(U), 3)
2563
- ]),
2564
- _: 2
2565
- }, 1032, ["label", "selected", "onClick"]))), 128))
2566
- ])) : K("", !0),
2567
- mt.value.length ? (h(), T("div", Ja, [
2568
- e[19] || (e[19] = o("span", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary self-center" }, "Extra columns:", -1)),
2569
- (h(!0), T(ce, null, he(mt.value, (U) => (h(), ae(O, {
2570
- key: U,
2571
- label: U,
2572
- selectable: "",
2573
- selected: Ze[U],
2574
- onClick: (ue) => Ze[U] = !Ze[U]
2575
- }, null, 8, ["label", "selected", "onClick"]))), 128))
2576
- ])) : K("", !0),
2577
- o("div", Xa, [
2578
- o("div", {
2579
- style: Ht({ height: "600px", minWidth: `${ln.value}px` })
2580
- }, [
2581
- $(me, {
2582
- "column-defs": xt.value,
2583
- "row-data": Qe.value,
2584
- "search-value": dt.value
2585
- }, null, 8, ["column-defs", "row-data", "search-value"])
2586
- ], 4)
2587
- ])
2588
- ], 64))
2589
- ])
2590
- ], 64)) : K("", !0),
2591
- Oe.value.value === "history" ? (h(), T("div", eo, [
2592
- Ue.value.length ? (h(), T("div", ao, [
2593
- (h(!0), T(ce, null, he(Ue.value, (U, ue) => (h(), T(ce, { key: ue }, [
2594
- o("div", oo, [
2595
- o("div", so, [
2596
- o("div", ro, [
2597
- o("div", {
2598
- class: Se([
2599
- {
2600
- "bg-fm-color-primary": ue !== 0,
2601
- "bg-white": ue === 0
2602
- },
2603
- "w-[2px] h-full"
2604
- ])
2605
- }, null, 2)
2606
- ]),
2607
- e[22] || (e[22] = o("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
2608
- o("div", lo, [
2609
- o("div", {
2610
- class: Se([
2611
- {
2612
- "bg-fm-color-primary": ue < Ue.value.length - 1,
2613
- "bg-white": ue >= Ue.value.length - 1
2614
- },
2615
- "w-[2px] h-full"
2616
- ])
2617
- }, null, 2)
2618
- ])
2619
- ]),
2620
- o("div", io, [
2621
- o("div", co, H(U.header), 1),
2622
- o("div", uo, H(U.date), 1)
2623
- ])
2624
- ]),
2625
- o("div", mo, [
2626
- o("div", fo, [
2627
- o("div", po, [
2628
- o("div", {
2629
- class: Se([
2630
- {
2631
- "bg-fm-color-primary": ue < Ue.value.length - 1,
2632
- "bg-white": ue >= Ue.value.length - 1
2633
- },
2634
- "w-[2px] h-full"
2635
- ])
2636
- }, null, 2)
2637
- ])
2638
- ]),
2639
- o("div", vo, [
2640
- $(D, {
2641
- variant: "outlined",
2642
- class: "py-12 px-16"
2643
- }, {
2644
- default: X(() => [
2645
- o("div", yo, [
2646
- (h(!0), T(ce, null, he(U.info, (fe, ke) => (h(), T("div", {
2647
- key: ke,
2648
- class: "flex flex-col gap-4"
2649
- }, [
2650
- o("div", go, H(fe == null ? void 0 : fe.label), 1),
2651
- o("div", bo, [
2652
- (h(!0), T(ce, null, he(fe == null ? void 0 : fe.values, (Re, et) => (h(), T("div", {
2653
- key: et,
2654
- class: "fm-typo-en-body-lg-600"
2655
- }, H(Re), 1))), 128))
2656
- ])
2657
- ]))), 128))
2658
- ])
2659
- ]),
2660
- _: 2
2661
- }, 1024)
2662
- ])
2663
- ])
2664
- ], 64))), 128))
2665
- ])) : (h(), T("div", to, [
2666
- $(Ae),
2667
- o("div", null, [
2668
- o("img", {
2669
- src: u(En),
2670
- alt: "List is empty"
2671
- }, null, 8, no)
2672
- ]),
2673
- e[20] || (e[20] = o("div", { class: "fm-typo-en-body-lg-600" }, H("No records found"), -1)),
2674
- e[21] || (e[21] = o("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, H("You can track approval and rejection history here"), -1)),
2675
- $(Ae),
2676
- $(Ae)
2677
- ]))
2678
- ])) : K("", !0)
2679
- ])
2680
- ]),
2681
- _: 1
2682
- }, 8, ["model-value"]),
2683
- u(c) && t.draft ? (h(), ae(Ia, {
2684
- key: 0,
2685
- show: Je.value,
2686
- "onUpdate:show": e[10] || (e[10] = (U) => Je.value = U),
2687
- refreshing: u(w),
2688
- approving: Xe.value,
2689
- draft: t.draft,
2690
- onRefresh: Le,
2691
- onApprove: mn
2692
- }, null, 8, ["show", "refreshing", "approving", "draft"])) : K("", !0)
2693
- ], 64);
2694
- };
2695
- }
2696
- });
2697
- var ve = /* @__PURE__ */ ((n) => (n.ready = "ready", n.negative = "negative", n.systemNegative = "systemNegative", n))(ve || {});
2698
- async function Do(n) {
2699
- return new Promise((l, t) => {
2700
- const s = new FileReader();
2701
- s.onload = (g) => {
2702
- var i;
2703
- try {
2704
- const r = (i = g.target) == null ? void 0 : i.result, c = Hn(r, { type: "array" }), x = c.SheetNames[0], A = c.Sheets[x], f = ot.sheet_to_json(A, {
2705
- header: 1,
2706
- defval: ""
2707
- }), B = (v) => String(v).trim().toLowerCase().replace(/^\uFEFF/, ""), N = f.findIndex(
2708
- (v) => v.some((d) => B(d) === "code")
2709
- );
2710
- if (N === -1) {
2711
- l([]);
2712
- return;
2713
- }
2714
- const E = f[N], F = E.findIndex((v) => B(v) === "code"), _ = E.findIndex((v) => B(v) === "balance");
2715
- if (F === -1 || _ === -1) {
2716
- t(
2717
- new Error(
2718
- `Missing required columns: ${F === -1 ? '"Code" ' : ""}${_ === -1 ? '"Balance"' : ""}.`.trim()
2719
- )
2720
- );
2721
- return;
2722
- }
2723
- const p = f.slice(N + 1).filter((v) => String(v[F]).trim()).map((v) => ({
2724
- itemCode: String(v[F]).trim(),
2725
- quantity: Number(v[_]) || 0
2726
- }));
2727
- l(p);
2728
- } catch (r) {
2729
- t(r);
2730
- }
2731
- }, s.onerror = t, s.readAsArrayBuffer(n);
2732
- });
2733
- }
2734
- function Ao(n) {
2735
- const l = /* @__PURE__ */ new Map();
2736
- return n.forEach((t) => {
2737
- const s = l.get(t.itemCode) || 0;
2738
- l.set(t.itemCode, s + t.quantity);
2739
- }), l;
2740
- }
2741
- function Co(n, l) {
2742
- const t = [], s = [];
2743
- for (const [g, i] of l.entries()) {
2744
- const r = n[g];
2745
- if (!r) {
2746
- s.push(g);
2747
- continue;
2748
- }
2749
- const c = i < 0 ? "negative" : "ready";
2750
- t.push({
2751
- sku: r,
2752
- physicalCount: i,
2753
- // Note: filled by composable after readStockBalance()
2754
- systemBalance: { amount: 0, precision: 0 },
2755
- variance: i - 0,
2756
- status: c
2757
- });
2758
- }
2759
- return { mergedItems: t, unrecognisedItemCodes: s };
2760
- }
2761
- function So(n, l) {
2762
- const t = n.filter((x) => !x.isInactive), s = Kn().format("YYYY-MM-DD"), g = `${l} - ${s}.csv`, i = [
2763
- ["Code", "Name", "Balance"],
2764
- ...t.map((x) => [x.code, x.name, ""])
2765
- ], r = ot.aoa_to_sheet(i), c = ot.book_new();
2766
- ot.book_append_sheet(c, r, "Template"), Yn(c, g, { bookType: "csv" });
2767
- }
2768
- function $o() {
2769
- const n = W([]), l = W([]), t = W(!1), s = wt(), g = We(), i = ct(), r = M(
2770
- () => n.value.some((f) => f.status === ve.negative)
2771
- );
2772
- async function c(f) {
2773
- n.value = [], l.value = [], t.value = !0;
2774
- try {
2775
- const B = await Do(f), N = Ao(B), E = s.skuByCode, { mergedItems: F, unrecognisedItemCodes: _ } = Co(
2776
- E,
2777
- N
2778
- ), R = await i.readStockBalance(), p = R.skus ?? [];
2779
- p.length === 0 && console.warn(
2780
- "No SKU balances found when importing closing draft. All system balances will be set to 0.",
2781
- {
2782
- stockBalance: R
2783
- }
2784
- );
2785
- const v = new Map(
2786
- p.map((b) => [b.id, b.balance])
2787
- ), d = new Set(F.map((b) => b.sku._id));
2788
- n.value = F.map((b) => {
2789
- const y = v.get(b.sku._id) ?? { amount: 0, precision: 0 }, w = y.amount / Math.pow(10, y.precision);
2790
- return { ...b, systemBalance: y, variance: b.physicalCount - w };
2791
- });
2792
- for (const b of Object.values(s.skuByCode)) {
2793
- if (d.has(b._id)) continue;
2794
- const y = v.get(b._id);
2795
- if (!y) continue;
2796
- const w = y.amount / Math.pow(10, y.precision);
2797
- w >= 0 || n.value.push({
2798
- sku: b,
2799
- physicalCount: 0,
2800
- systemBalance: y,
2801
- variance: 0 - w,
2802
- status: ve.systemNegative
2803
- });
2804
- }
2805
- l.value = _;
2806
- } catch (B) {
2807
- n.value = [], l.value = [], console.error("Error processing uploaded file", { error: B });
2808
- } finally {
2809
- t.value = !1;
2810
- }
2811
- }
2812
- async function x() {
2813
- const f = qe(), B = n.value.filter((p) => p.status === ve.ready), N = n.value.filter(
2814
- (p) => p.status === ve.systemNegative
2815
- ), E = (p) => ({
2816
- sku: {
2817
- _id: p.sku._id,
2818
- code: p.sku.code,
2819
- name: p.sku.name,
2820
- unit: p.sku.unit
2821
- },
2822
- baseAmount: Qt(p.physicalCount, p.sku.unit.precision),
2823
- measurementsAmounts: []
2824
- }), F = B.map(E), _ = N.map(E), R = {
2825
- effectiveAt: (/* @__PURE__ */ new Date()).toISOString(),
2826
- items: F,
2827
- negativeStockItems: _
2828
- };
2829
- return await f.createQuickModeDraftWithItems(R);
2830
- }
2831
- function A() {
2832
- var B;
2833
- const f = ((B = g.currentLocation) == null ? void 0 : B.name) ?? "template";
2834
- So(s.skus, f);
2835
- }
2836
- return { mergedItems: n, unrecognisedItemCodes: l, hasBlockingErrors: r, isLoading: t, onFileUpload: c, submit: x, downloadTemplate: A };
2837
- }
2838
- const Io = { class: "flex flex-col gap-16" }, Fo = {
2839
- key: 0,
2840
- class: "px-16 py-12 rounded-8 bg-fm-color-danger-weak text-fm-color-danger-default"
2841
- }, Bo = { key: 1 }, To = { class: "fm-typo-en-label-md-400 cursor-pointer" }, jo = { class: "mt-8 flex flex-col gap-4" }, Mo = { key: 2 }, Uo = { class: "fm-typo-en-label-md-400 cursor-pointer" }, Ro = { class: "mt-8 flex flex-col gap-4" }, Po = /* @__PURE__ */ je({
2842
- __name: "ClosingDraftCreatePreviewTable",
2843
- props: {
2844
- items: {},
2845
- unrecognisedItemCodes: {}
2846
- },
2847
- setup(n) {
2848
- const l = n, { t } = Ye(), s = M(
2849
- () => l.items.filter((c) => c.status === ve.negative)
2850
- ), g = M(
2851
- () => l.items.filter((c) => c.status === ve.systemNegative)
2852
- ), i = M(() => ({
2853
- [ve.negative]: {
2854
- bgColor: "bg-fm-color-danger-weak",
2855
- textColor: "text-fm-color-danger-default",
2856
- icon: "🚫",
2857
- label: t("inventory.closing.draft.createDraft.previewTable.status.negative")
2858
- },
2859
- [ve.systemNegative]: {
2860
- bgColor: "bg-fm-color-warning-weak",
2861
- textColor: "text-fm-color-warning-default",
2862
- icon: "⚠️",
2863
- label: t("inventory.closing.draft.createDraft.previewTable.status.systemNegative")
2864
- }
2865
- })), r = [
2866
- {
2867
- id: "name",
2868
- header: () => t("inventory.ingredient.name"),
2869
- cell: (c) => c.row.original.sku.name
2870
- },
2871
- {
2872
- id: "uom",
2873
- header: () => t("inventory.closing.draft.createDraft.previewTable.uom"),
2874
- size: 80,
2875
- cell: (c) => c.row.original.sku.unit.abbrev
2876
- },
2877
- {
2878
- id: "systemBalance",
2879
- header: () => t("inventory.closing.draft.createDraft.previewTable.systemBalance"),
2880
- size: 180,
2881
- cell: (c) => {
2882
- const x = c.row.original;
2883
- return k("div", ne(x.systemBalance));
2884
- }
2885
- },
2886
- {
2887
- id: "physicalCount",
2888
- header: () => t("inventory.closing.draft.createDraft.previewTable.stockTakeBalance"),
2889
- cell: (c) => {
2890
- const x = c.row.original;
2891
- return k("div", ne(x.physicalCount));
2892
- }
2893
- },
2894
- {
2895
- id: "variance",
2896
- header: () => t("inventory.closing.draft.createDraft.previewTable.variance"),
2897
- cell: (c) => {
2898
- const A = c.row.original.variance, f = A < 0 ? "text-fm-color-danger-default" : A > 0 ? "text-fm-color-success-default" : "";
2899
- return k("span", { class: f }, ne(A));
2900
- }
2901
- },
2902
- {
2903
- id: "variancePercentage",
2904
- header: () => t("inventory.closing.draft.createDraft.previewTable.variancePercentage"),
2905
- size: 130,
2906
- cell: (c) => {
2907
- const x = c.row.original, A = x.systemBalance.amount / Math.pow(10, x.systemBalance.precision), f = A === 0 ? null : Math.max(
2908
- -100,
2909
- Math.min(100, Math.round(x.variance / Math.abs(A) * 1e4) / 100)
2910
- );
2911
- if (f === null)
2912
- return k(
2913
- "div",
2914
- { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
2915
- t("inventory.closing.draft.createDraft.previewTable.notApplicable")
2916
- );
2917
- const B = `${ne(f)}`;
2918
- if (f === 0)
2919
- return k(
2920
- "div",
2921
- { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
2922
- B
2923
- );
2924
- const N = f > 0;
2925
- return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" }, [
2926
- k(pe.FmIcon, {
2927
- name: N ? "arrow_drop_up" : "arrow_drop_down",
2928
- color: N ? "system-success-300" : "system-error-300",
2929
- size: "md"
2930
- }),
2931
- B
2932
- ]);
2933
- }
2934
- },
2935
- {
2936
- id: "status",
2937
- header: () => t("inventory.common.status"),
2938
- cell: (c) => {
2939
- const x = c.row.original.status, A = i.value[x];
2940
- return A ? k(
2941
- "span",
2942
- {
2943
- class: `px-8 py-2 rounded-4 ${A.bgColor} ${A.textColor} fm-typo-en-label-sm-400`
2944
- },
2945
- `${A.icon} ${A.label}`
2946
- ) : null;
2947
- }
2948
- }
2949
- ];
2950
- return (c, x) => {
2951
- const A = Z("FmTable");
2952
- return h(), T("div", Io, [
2953
- s.value.length > 0 ? (h(), T("div", Fo, [
2954
- de(H(u(t)("inventory.closing.draft.createDraft.previewTable.cannotSubmitNegative")) + " ", 1),
2955
- o("strong", null, H(s.value.map((f) => f.sku.code).join(", ")), 1)
2956
- ])) : K("", !0),
2957
- g.value.length > 0 ? (h(), T("details", Bo, [
2958
- o("summary", To, H(u(t)("inventory.closing.draft.createDraft.previewTable.systemNegativeNote", [g.value.length])), 1),
2959
- o("ul", jo, [
2960
- (h(!0), T(ce, null, he(g.value, (f) => (h(), T("li", {
2961
- key: f.sku._id,
2962
- class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
2963
- }, H(f.sku.code), 1))), 128))
2964
- ])
2965
- ])) : K("", !0),
2966
- c.unrecognisedItemCodes.length > 0 ? (h(), T("details", Mo, [
2967
- o("summary", Uo, H(u(t)("inventory.closing.draft.createDraft.previewTable.unrecognisedNote", [c.unrecognisedItemCodes.length])), 1),
2968
- o("ul", Ro, [
2969
- (h(!0), T(ce, null, he(c.unrecognisedItemCodes, (f) => (h(), T("li", {
2970
- key: f,
2971
- class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
2972
- }, H(f), 1))), 128))
2973
- ])
2974
- ])) : K("", !0),
2975
- $(A, {
2976
- "row-data": l.items,
2977
- "column-defs": r,
2978
- pagination: { pageSize: 20 }
2979
- }, null, 8, ["row-data"])
2980
- ]);
2981
- };
2982
- }
2983
- }), Vo = { class: "flex flex-col gap-16" }, No = { class: "flex flex-col gap-8" }, zo = { class: "fm-typo-en-body-lg-600" }, Eo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Lo = { class: "fm-corner-radius-md p-16 flex items-center gap-16 border border-fm-color-border-default" }, Oo = { class: "flex flex-col flex-1 gap-4" }, Ho = { class: "fm-typo-en-body-md-600" }, Yo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Ko = {
2984
- key: 0,
2985
- class: "flex flex-col gap-8"
2986
- }, Wo = { class: "fm-typo-en-body-lg-600" }, qo = {
2987
- key: 0,
2988
- class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 flex items-center gap-8"
2989
- }, Go = { class: "grid grid-cols-[repeat(3,1fr)] gap-12" }, Qo = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary flex items-center gap-4" }, Zo = { class: "flex items-center gap-8 w-full" }, Jo = /* @__PURE__ */ je({
2990
- __name: "ClosingDraftCreateSideSheet",
2991
- props: {
2992
- show: { type: Boolean }
2993
- },
2994
- emits: ["update:show", "submitted"],
2995
- setup(n, { emit: l }) {
2996
- const t = n, s = l, g = Kt(t, "show"), { t: i } = Ye(), r = Ke(), c = W("upload"), x = W(null), A = W(!1), { mergedItems: f, unrecognisedItemCodes: B, hasBlockingErrors: N, isLoading: E, onFileUpload: F, submit: _, downloadTemplate: R } = $o(), p = M(
2997
- () => x.value && !E.value && f.value.length > 0
2998
- ), v = M(() => {
2999
- const w = f.value.filter(
3000
- (z) => z.status === ve.ready
3001
- ).length, Y = f.value.filter(
3002
- (z) => z.status === ve.negative
3003
- ).length, q = f.value.filter(
3004
- (z) => z.status === ve.systemNegative
3005
- ).length, re = f.value.filter((z) => z.variance !== 0).length;
3006
- return [
3007
- { label: i("inventory.closing.draft.createDraft.summary.totalItems"), value: f.value.length },
3008
- { label: i("inventory.closing.draft.createDraft.summary.itemsWithCount"), value: w },
3009
- {
3010
- label: i("inventory.closing.draft.createDraft.summary.unrecognisedItems"),
3011
- value: B.value.length,
3012
- isWarning: B.value.length > 0
3013
- },
3014
- { label: i("inventory.closing.draft.createDraft.summary.itemsWithVariance"), value: re },
3015
- { label: i("inventory.closing.draft.createDraft.summary.negativeCounts"), value: Y, isError: Y > 0 },
3016
- {
3017
- label: i("inventory.closing.draft.createDraft.summary.systemNegative"),
3018
- value: q,
3019
- isWarning: q > 0
3020
- }
3021
- ];
3022
- });
3023
- async function d(w) {
3024
- x.value = w, await F(w);
3025
- }
3026
- async function b() {
3027
- A.value = !0;
3028
- try {
3029
- await _(), y(), s("submitted"), r.open({
3030
- title: "Success",
3031
- message: "Closing draft created successfully",
3032
- type: "success"
3033
- });
3034
- } catch (w) {
3035
- console.error("Failed to create closing draft", { error: w }), r.open({
3036
- title: "Something went wrong",
3037
- message: "Failed to create closing draft. Please try again",
3038
- type: "error"
3039
- });
3040
- } finally {
3041
- A.value = !1;
3042
- }
3043
- }
3044
- ze(g, (w) => {
3045
- w || (c.value = "upload", x.value = null);
3046
- });
3047
- function y() {
3048
- g.value = !1;
3049
- }
3050
- return (w, Y) => {
3051
- const q = Z("FmCircularProgress"), re = Z("FmIcon"), z = Z("FmButton"), le = Z("FmCard"), P = Z("FmSideSheet");
3052
- return h(), ae(P, {
3053
- "dismiss-away": "",
3054
- "max-width": 9999,
3055
- "model-value": u(g),
3056
- "onUpdate:modelValue": Y[2] || (Y[2] = (S) => _t(g) ? g.value = S : null),
3057
- header: u(i)("inventory.closing.draft.createDraft.title")
3058
- }, {
3059
- default: X(() => [
3060
- o("div", Vo, [
3061
- c.value === "upload" ? (h(), T(ce, { key: 0 }, [
3062
- o("div", No, [
3063
- o("div", zo, H(u(i)("inventory.closing.draft.createDraft.importCsv")), 1),
3064
- o("div", Eo, H(u(i)("inventory.closing.draft.createDraft.uploadDescription")), 1),
3065
- $(Wn, {
3066
- class: Se({ "h-[200px]": !x.value }),
3067
- accept: ".csv",
3068
- disabled: u(E),
3069
- onFileUpload: d
3070
- }, kn({ _: 2 }, [
3071
- x.value ? {
3072
- name: "default",
3073
- fn: X(({ openFileDialog: S }) => [
3074
- o("div", Lo, [
3075
- u(E) ? (h(), ae(q, {
3076
- key: 0,
3077
- size: "md",
3078
- color: "neutral-gray-200"
3079
- })) : (h(), ae(re, {
3080
- key: 1,
3081
- name: "check_circle",
3082
- color: "system-success-400",
3083
- size: "lg"
3084
- })),
3085
- o("div", Oo, [
3086
- o("div", Ho, H(x.value.name), 1),
3087
- o("div", Yo, H(u(E) ? u(i)("inventory.closing.draft.createDraft.processing") : u(i)("inventory.closing.draft.createDraft.itemsLoaded", [u(f).length])), 1)
3088
- ]),
3089
- u(E) ? K("", !0) : (h(), ae(z, {
3090
- key: 2,
3091
- label: u(i)("inventory.closing.draft.createDraft.replaceFile"),
3092
- variant: "secondary",
3093
- "prepend-icon": "autorenew",
3094
- onClick: S
3095
- }, null, 8, ["label", "onClick"]))
3096
- ])
3097
- ]),
3098
- key: "0"
3099
- } : void 0
3100
- ]), 1032, ["class", "disabled"])
3101
- ]),
3102
- p.value ? (h(), T("div", Ko, [
3103
- o("div", Wo, H(u(i)("inventory.closing.draft.createDraft.importSummary")), 1),
3104
- u(N) ? (h(), T("div", qo, [
3105
- $(re, {
3106
- name: "error",
3107
- size: "sm",
3108
- color: "system-error-300"
3109
- }),
3110
- o("span", null, H(u(i)("inventory.closing.draft.createDraft.reviewIssues")), 1)
3111
- ])) : K("", !0),
3112
- $(le, {
3113
- variant: "outlined",
3114
- class: "flex flex-col gap-12 px-16 py-12"
3115
- }, {
3116
- default: X(() => [
3117
- o("div", Go, [
3118
- (h(!0), T(ce, null, he(v.value, (S) => (h(), T("div", {
3119
- key: S.label,
3120
- class: "flex flex-col gap-4"
3121
- }, [
3122
- o("div", Qo, [
3123
- S.isError ? (h(), ae(re, {
3124
- key: 0,
3125
- name: "error",
3126
- size: "sm",
3127
- color: "system-error-300"
3128
- })) : K("", !0),
3129
- S.isWarning && !S.isError ? (h(), ae(re, {
3130
- key: 1,
3131
- name: "warning",
3132
- size: "sm",
3133
- color: "system-warning-300"
3134
- })) : K("", !0),
3135
- o("span", null, H(S.label), 1)
3136
- ]),
3137
- o("div", {
3138
- class: Se([
3139
- "fm-typo-en-body-lg-600",
3140
- {
3141
- "text-fm-color-system-error-300": S.isError,
3142
- "text-fm-color-system-warning-300": S.isWarning && !S.isError
3143
- }
3144
- ])
3145
- }, H(S.value), 3)
3146
- ]))), 128))
3147
- ])
3148
- ]),
3149
- _: 1
3150
- })
3151
- ])) : K("", !0)
3152
- ], 64)) : K("", !0),
3153
- c.value === "preview" ? (h(), ae(Po, {
3154
- key: 1,
3155
- items: u(f),
3156
- "unrecognised-item-codes": u(B)
3157
- }, null, 8, ["items", "unrecognised-item-codes"])) : K("", !0)
3158
- ])
3159
- ]),
3160
- "side-sheet-footer": X(() => [
3161
- o("div", Zo, [
3162
- c.value === "preview" ? (h(), ae(z, {
3163
- key: 0,
3164
- variant: "secondary",
3165
- label: u(i)("inventory.common.back"),
3166
- "prepend-icon": "arrow_back",
3167
- onClick: Y[0] || (Y[0] = (S) => c.value = "upload")
3168
- }, null, 8, ["label"])) : K("", !0),
3169
- c.value === "upload" ? (h(), ae(z, {
3170
- key: 1,
3171
- variant: "primary",
3172
- label: u(i)("inventory.common.next"),
3173
- disabled: !x.value || u(E),
3174
- onClick: Y[1] || (Y[1] = (S) => c.value = "preview")
3175
- }, null, 8, ["label", "disabled"])) : K("", !0),
3176
- c.value === "preview" ? (h(), ae(qn, {
3177
- key: 2,
3178
- label: u(i)("inventory.closing.draft.createDraft.submit"),
3179
- disabled: u(N) || u(f).length === 0 || A.value,
3180
- loading: A.value,
3181
- "confirm-title": u(i)("inventory.closing.draft.createDraft.confirmTitle"),
3182
- "confirm-message": u(i)("inventory.closing.draft.createDraft.confirmMessage"),
3183
- onConfirm: b
3184
- }, null, 8, ["label", "disabled", "loading", "confirm-title", "confirm-message"])) : K("", !0),
3185
- $(z, {
3186
- variant: "tertiary",
3187
- label: u(i)("inventory.common.close"),
3188
- onClick: y
3189
- }, null, 8, ["label"]),
3190
- c.value === "upload" ? (h(), ae(z, {
3191
- key: 3,
3192
- class: "ml-auto",
3193
- variant: "secondary",
3194
- label: u(i)("inventory.closing.draft.createDraft.downloadTemplate"),
3195
- "prepend-icon": "download",
3196
- onClick: u(R)
3197
- }, null, 8, ["label", "onClick"])) : K("", !0)
3198
- ])
3199
- ]),
3200
- _: 1
3201
- }, 8, ["model-value", "header"]);
3202
- };
3203
- }
3204
- }), Xo = { class: "flex-1 flex flex-col gap-8" }, es = { class: "flex flex-col" }, ts = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, ns = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, as = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, os = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, js = /* @__PURE__ */ je({
3205
- __name: "ClosingDraftView",
3206
- setup(n) {
3207
- const { t: l } = Ye(), { viewDraft: t } = it(), { viewClosingDraftProps: s, viewClosingDraftShow: g } = Fn(it()), i = We(), r = on(), c = xn(), { breakpoints: x } = Cn();
3208
- i.watchLocation(r.fetchDrafts);
3209
- const A = M(() => r.loading), f = W(""), B = W(!1), N = M(() => x.value.xs || x.value.sm), E = M(() => N.value ? 10 : 20), F = M(
3210
- () => {
3211
- var v;
3212
- return ((v = i.currentLocation) == null ? void 0 : v.type) === In.enum.warehouse;
3213
- }
3214
- );
3215
- function _(v) {
3216
- switch (v) {
3217
- case "add":
3218
- return B.value = !0;
3219
- case "refresh":
3220
- return r.fetchDrafts();
3221
- }
3222
- }
3223
- function R(v) {
3224
- return v;
3225
- }
3226
- const p = M(() => {
3227
- const v = {
3228
- label: l("inventory.closing.draft.createDraft.title"),
3229
- value: "add",
3230
- isPrimary: !0,
3231
- prependIcon: "add"
3232
- }, d = {
3233
- label: l("inventory.common.refresh"),
3234
- value: "refresh",
3235
- isPrimary: !1
3236
- };
3237
- return [...F.value ? [v] : [], d];
3238
- });
3239
- return (v, d) => {
3240
- const b = Z("FmTable");
3241
- return h(), T(ce, null, [
3242
- $(Dn, {
3243
- title: u(l)("inventory.closing.draft.title"),
3244
- actions: p.value,
3245
- "onClick:action": _
3246
- }, {
3247
- default: X(() => [
3248
- o("div", {
3249
- class: Se([
3250
- "flex flex-col gap-8 max-h-full",
3251
- {
3252
- "p-0": N.value,
3253
- "px-24 ": !N.value
3254
- }
3255
- ])
3256
- }, [
3257
- $(zn, {
3258
- "change-location": "",
3259
- searchable: "",
3260
- search: f.value,
3261
- "onUpdate:search": d[0] || (d[0] = (y) => f.value = y)
3262
- }, null, 8, ["search"]),
3263
- (h(), ae(b, {
3264
- key: u(r).tableKey,
3265
- style: Ht(u(c).tableHeight),
3266
- "column-defs": u(r).columnDefs,
3267
- "row-data": u(r).drafts,
3268
- "search-value": f.value,
3269
- loading: A.value,
3270
- onRowClick: d[1] || (d[1] = (y) => u(t)(y.original)),
3271
- "page-size": E.value
3272
- }, {
3273
- "list-row": X((y) => [
3274
- $(Gn, {
3275
- row: y,
3276
- onRowClick: (w) => u(t)(w)
3277
- }, {
3278
- default: X((w) => {
3279
- var Y, q, re, z, le, P, S, ie, L, I, Q, se, we, xe, De, $e, Ee, Le, Me, Ge;
3280
- return [
3281
- o("div", Xo, [
3282
- o("div", es, [
3283
- o("div", ts, [
3284
- $(u(at), {
3285
- render: (re = (q = (Y = w._id) == null ? void 0 : Y.column) == null ? void 0 : q.columnDef) == null ? void 0 : re.cell,
3286
- props: (le = (z = w._id) == null ? void 0 : z.getContext) == null ? void 0 : le.call(z)
3287
- }, null, 8, ["render", "props"])
3288
- ]),
3289
- o("div", ns, [
3290
- $(u(at), {
3291
- render: (ie = (S = (P = w.name) == null ? void 0 : P.column) == null ? void 0 : S.columnDef) == null ? void 0 : ie.cell,
3292
- props: (I = (L = w.name) == null ? void 0 : L.getContext) == null ? void 0 : I.call(L)
3293
- }, null, 8, ["render", "props"])
3294
- ]),
3295
- o("div", as, H([
3296
- ...y.original.items.slice(0, 3).map((ut) => ut.sku.name),
3297
- ...y.original.items.length >= 3 ? [`and ${y.original.items.length - 3} more items`] : []
3298
- ].join(", ")), 1),
3299
- o("div", os, [
3300
- $(u(at), {
3301
- render: (we = (se = (Q = w.ref) == null ? void 0 : Q.column) == null ? void 0 : se.columnDef) == null ? void 0 : we.cell,
3302
- props: (De = (xe = w.ref) == null ? void 0 : xe.getContext) == null ? void 0 : De.call(xe)
3303
- }, null, 8, ["render", "props"])
3304
- ])
3305
- ]),
3306
- o("div", null, [
3307
- $(u(at), {
3308
- render: (Le = (Ee = ($e = w.status) == null ? void 0 : $e.column) == null ? void 0 : Ee.columnDef) == null ? void 0 : Le.cell,
3309
- props: (Ge = (Me = w.status) == null ? void 0 : Me.getContext) == null ? void 0 : Ge.call(Me)
3310
- }, null, 8, ["render", "props"])
3311
- ])
3312
- ])
3313
- ];
3314
- }),
3315
- _: 2
3316
- }, 1032, ["row", "onRowClick"])
3317
- ]),
3318
- _: 1
3319
- }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
3320
- ], 2)
3321
- ]),
3322
- _: 1
3323
- }, 8, ["title", "actions"]),
3324
- $(Jo, {
3325
- show: B.value,
3326
- "onUpdate:show": d[2] || (d[2] = (y) => B.value = y),
3327
- onSubmitted: u(r).fetchDrafts
3328
- }, null, 8, ["show", "onSubmitted"]),
3329
- (h(), ae(_n, { to: "body" }, [
3330
- $(xo, wn(u(s), {
3331
- show: u(g),
3332
- "onUpdate:show": d[3] || (d[3] = (y) => _t(g) ? g.value = y : null),
3333
- onSubmitted: d[4] || (d[4] = () => (g.value = !1, u(r).fetchDrafts())),
3334
- onRefresh: d[5] || (d[5] = (y) => u(r).updateDraftRef(y))
3335
- }), null, 16, ["show"])
3336
- ]))
3337
- ], 64);
3338
- };
3339
- }
3340
- });
3341
- export {
3342
- js as default
3343
- };