@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
@@ -0,0 +1,4318 @@
1
+ import { defineComponent as Se, ref as q, computed as I, onMounted as Ft, resolveComponent as J, openBlock as f, createElementBlock as $, Fragment as le, createTextVNode as me, createBlock as oe, withCtx as te, createElementVNode as a, toDisplayString as N, unref as m, createVNode as D, createCommentVNode as Y, h as k, watch as Te, renderList as ge, onUnmounted as Mn, withModifiers as Un, normalizeStyle as dt, normalizeClass as he, isRef as vt, reactive as Xt, createSlots as Nn, Teleport as Vn, mergeProps as En } from "vue";
2
+ import { u as Ln, _ as zn } from "./SingleColumnLayout.vue_vue_type_script_setup_true_lang-DGlWE5I8.js";
3
+ import { useCoreStore as nn, useI18n as Xe } from "@feedmepos/mf-common";
4
+ import { useSnackbar as Ge, useDialog as on, components as ve, useProxiedModel as It, useBreakpoints as On } from "@feedmepos/ui-library";
5
+ import { m as Gn, u as He, L as de, w as ae, q as an, s as Ie, M as ke, B as Pe, c as Hn, a as Bt, j as Yn } from "./app-D-l9FM2n.js";
6
+ import { defineStore as sn, storeToRefs as Kn } from "pinia";
7
+ import { b as mt, e as rn, f as Wn, a as Fe } from "./date2-CRMgo5NH.js";
8
+ import { R as ln } from "./rules-BsVkaxL5.js";
9
+ import { e as yt, a as At, t as cn, c as Ze, l as un, m as dn, j as ft, k as mn, o as ue } from "./number-YiCgPFTE.js";
10
+ import { b as qn, d as Qn } from "./xlsx.util-D_XTOHMv.js";
11
+ import { i as Tt, u as jt } from "./uom-rules-DbhFLCUC.js";
12
+ import { u as Jn, a as Zn } from "./useSseClient-D1h38l_K.js";
13
+ import { u as gt } from "./stock-DlQopDTl.js";
14
+ import { D as en, R as Le } from "./row-action.enum-DQ9bJ_uv.js";
15
+ import { c as Xn } from "./component-kqxARxvM.js";
16
+ import { f as eo } from "./format-time-from-id-BuMdYlM9.js";
17
+ import { f as to } from "./recalculationUtils-DZLZlctO.js";
18
+ import { _ as no } from "./FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-QvgQwP6t.js";
19
+ import { _ as fn } from "./empty-placeholder-B0QU467o.js";
20
+ import { F as $t } from "./FmAdminBadge-DjnBAgyv.js";
21
+ import { u as oo } from "./vue-i18n-fX3C6wjd.js";
22
+ import { F as ao } from "./decimal-CsE7mms2.js";
23
+ import { r as so, u as ut, w as ro } from "./xlsx-BsL1DoEA.js";
24
+ import { d as lo } from "./dayjs.min-9bo3vPqj.js";
25
+ import { F as io } from "./FmDroppableField-J0xUsOTV.js";
26
+ import { _ as co } from "./FmConfirmationButton.vue_vue_type_script_setup_true_lang-DLrMEGFR.js";
27
+ import { F as qe, _ as uo } from "./TableActionableRow.vue_vue_type_script_setup_true_lang-Ca_eYa8-.js";
28
+ const Re = Gn((t, n) => {
29
+ function e() {
30
+ return He().currentLocation.dbName;
31
+ }
32
+ return {
33
+ getDbName: e,
34
+ async getDraft(o) {
35
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/${o}`;
36
+ return n.get(s);
37
+ },
38
+ async readDrafts() {
39
+ const o = e(), i = `${t.inventoryBackendUrl}/${o}/closing-draft`;
40
+ return n.get(i);
41
+ },
42
+ async runOperation(o) {
43
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/run-operation`;
44
+ return n.post(s, o);
45
+ },
46
+ async runOperationV1(o) {
47
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/v1/run-operation`;
48
+ return n.post(s, o);
49
+ },
50
+ async sync(o) {
51
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/sync`;
52
+ return n.post(s, o);
53
+ },
54
+ async cloneDraft(o) {
55
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/${o}/clone`;
56
+ return n.post(s, {});
57
+ },
58
+ /** Closing groups belonging to a parent closing draft. */
59
+ async getClosingGroups(o) {
60
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/${o}/groups`;
61
+ return n.get(s);
62
+ },
63
+ /** Approve a closing group (sub-closing): status -> COMPLETED, no recalculation. */
64
+ async approveClosingGroup(o, i) {
65
+ const s = e(), r = `${t.inventoryBackendUrl}/${s}/closing-draft/${o}/group/approve`;
66
+ return n.post(r, { remark: i });
67
+ },
68
+ /** Reject a closing group (sub-closing): records a rejection note, stays DRAFT. */
69
+ async rejectClosingGroup(o, i) {
70
+ const s = e(), r = `${t.inventoryBackendUrl}/${s}/closing-draft/${o}/group/reject`;
71
+ return n.post(r, { remark: i });
72
+ },
73
+ async createQuickModeDraftWithItems(o) {
74
+ const i = e(), s = `${t.inventoryBackendUrl}/${i}/closing-draft/quick-mode/new-with-items`;
75
+ return n.post(s, o);
76
+ },
77
+ initializeStockSnapshot(o, i) {
78
+ const s = e(), r = `${t.inventoryBackendUrl}/${s}/closing-draft/${encodeURIComponent(o)}/initialize-stock-snapshot`;
79
+ return n.post(r, { effectiveAt: i });
80
+ },
81
+ async getRefreshBalanceStatus(o, i) {
82
+ const s = e(), r = `${t.inventoryBackendUrl}/${s}/closing-draft/${o}/refresh-balance/status?closingDraftRevision=${encodeURIComponent(i)}`;
83
+ return n.get(r);
84
+ }
85
+ };
86
+ }), mo = { class: "fm-typo-en-body-lg-400" }, fo = { class: "fm-typo-en-body-lg-600" }, po = {
87
+ key: 0,
88
+ class: "flex flex-col"
89
+ }, vo = {
90
+ key: 0,
91
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
92
+ }, yo = { class: "flex gap-12 py-8 justify-end w-full" }, Ct = /* @__PURE__ */ Se({
93
+ __name: "ClosingDraftAction",
94
+ props: {
95
+ draft: {},
96
+ action: {},
97
+ onCancel: { type: Function },
98
+ onFinished: { type: Function }
99
+ },
100
+ setup(t) {
101
+ const n = t, e = q(), o = Re(), i = Ge(), s = q(!1), r = q(null), u = q(!1), c = I(() => {
102
+ switch (n.action) {
103
+ case de.enum.approveDraft:
104
+ return "Approve";
105
+ case de.enum.rejectDraft:
106
+ return "Reject";
107
+ case de.enum.markAsFailed:
108
+ return "Mark as Failed";
109
+ }
110
+ throw new Error(`Unknown action: ${n.action}`);
111
+ }), b = I(() => {
112
+ switch (n.action) {
113
+ case de.enum.approveDraft:
114
+ return "primary";
115
+ case de.enum.rejectDraft:
116
+ return "destructive";
117
+ case de.enum.markAsFailed:
118
+ return "destructive";
119
+ }
120
+ throw new Error(`Unknown action: ${n.action}`);
121
+ });
122
+ Ft(() => {
123
+ if (n.draft.effectiveAt)
124
+ r.value = new Date(n.draft.effectiveAt);
125
+ else {
126
+ const P = new Date(n.draft.createdAt);
127
+ P.setHours(23, 59, 59, 999), r.value = P;
128
+ }
129
+ u.value = !0;
130
+ });
131
+ const p = I({
132
+ get() {
133
+ return r.value === null ? "" : mt(r.value);
134
+ },
135
+ set(P) {
136
+ if (P) {
137
+ const S = /* @__PURE__ */ new Date(`${P} ${F.value}`);
138
+ S.setSeconds(59, 999), r.value = S;
139
+ } else
140
+ r.value = null;
141
+ }
142
+ }), F = I({
143
+ get() {
144
+ return r.value === null ? "" : rn(r.value);
145
+ },
146
+ set(P) {
147
+ if (P) {
148
+ const S = /* @__PURE__ */ new Date(`${p.value} ${P}`);
149
+ S.setSeconds(59, 999), r.value = S;
150
+ } else
151
+ r.value = null;
152
+ }
153
+ }), E = I(() => r.value ? r.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
154
+ async function U(P) {
155
+ s.value = !0;
156
+ try {
157
+ P ? await o.runOperationV1({
158
+ _id: n.draft._id,
159
+ _rev: n.draft._rev ?? "",
160
+ action: n.action,
161
+ data: {
162
+ effectiveAt: r.value ? r.value.toISOString() : null,
163
+ remark: e.value
164
+ }
165
+ }).delayed(500) : await o.runOperation({
166
+ _id: n.draft._id,
167
+ _rev: n.draft._rev ?? "",
168
+ action: n.action,
169
+ data: {
170
+ effectiveAt: r.value ? r.value.toISOString() : null,
171
+ remark: e.value
172
+ }
173
+ }).delayed(500), i.open({
174
+ title: "Success",
175
+ message: "Action submitted",
176
+ type: "success"
177
+ }), n.onFinished();
178
+ } catch (S) {
179
+ i.open({
180
+ title: "Something went wrong",
181
+ message: (S == null ? void 0 : S.message) ?? "Unable to submit action. Please try again",
182
+ type: "error"
183
+ }), console.error("error on submit closing draft action", S);
184
+ } finally {
185
+ s.value = !1;
186
+ }
187
+ }
188
+ return (P, S) => {
189
+ const L = J("FmLabel"), W = J("FmDatePicker"), T = J("FmTimePicker"), z = J("FmTextField"), C = J("FmButton"), x = J("FmForm");
190
+ return u.value ? (f(), oe(x, {
191
+ key: 1,
192
+ onValidationSuccess: U,
193
+ class: "flex flex-col gap-32",
194
+ disabled: s.value
195
+ }, {
196
+ default: te(() => [
197
+ a("div", mo, [
198
+ S[4] || (S[4] = me(" You are about to ")),
199
+ a("span", fo, N(c.value), 1),
200
+ S[5] || (S[5] = me(" this draft. Please provide a remark to justify this action. "))
201
+ ]),
202
+ P.action === m(de).enum.approveDraft ? (f(), $("div", po, [
203
+ D(L, { class: "fm-typo-en-body-lg-600" }, {
204
+ default: te(() => S[6] || (S[6] = [
205
+ me("Closing Date")
206
+ ])),
207
+ _: 1
208
+ }),
209
+ D(W, {
210
+ modelValue: p.value,
211
+ "onUpdate:modelValue": S[0] || (S[0] = (d) => p.value = d),
212
+ max: m(mt)(/* @__PURE__ */ new Date())
213
+ }, null, 8, ["modelValue", "max"]),
214
+ D(L, { class: "fm-typo-en-body-lg-600" }, {
215
+ default: te(() => S[7] || (S[7] = [
216
+ me("Closing Time")
217
+ ])),
218
+ _: 1
219
+ }),
220
+ D(T, {
221
+ modelValue: F.value,
222
+ "onUpdate:modelValue": S[1] || (S[1] = (d) => F.value = d)
223
+ }, null, 8, ["modelValue"]),
224
+ E.value ? (f(), $("div", vo, " Cannot select future date ")) : Y("", !0)
225
+ ])) : Y("", !0),
226
+ D(z, {
227
+ modelValue: e.value,
228
+ "onUpdate:modelValue": S[2] || (S[2] = (d) => e.value = d),
229
+ label: "Remark",
230
+ "label-mark": "required",
231
+ rules: [m(ln)()]
232
+ }, null, 8, ["modelValue", "rules"]),
233
+ a("div", yo, [
234
+ D(C, {
235
+ label: "Cancel",
236
+ variant: "tertiary",
237
+ onClick: S[3] || (S[3] = (d) => P.onCancel())
238
+ }),
239
+ D(C, {
240
+ label: c.value,
241
+ type: "submit",
242
+ variant: b.value,
243
+ loading: s.value
244
+ }, null, 8, ["label", "variant", "loading"])
245
+ ])
246
+ ]),
247
+ _: 1
248
+ }, 8, ["disabled"])) : (f(), $(le, { key: 0 }, [
249
+ me("Loading")
250
+ ], 64));
251
+ };
252
+ }
253
+ }), go = Ze(0);
254
+ function bt(t) {
255
+ const n = t.measurementsAmounts.groupBy((o) => o.measurement.id), e = t.sku.unit.measurements.reduce((o, i) => {
256
+ var u, c;
257
+ const s = ((c = (u = n.get(i.id)) == null ? void 0 : u[0]) == null ? void 0 : c.amount) ?? go, r = yt(i.conversion, s);
258
+ return o + +At(r);
259
+ }, +At(t.baseAmount));
260
+ return cn(e, t.baseAmount.precision);
261
+ }
262
+ const bo = Ze(0), ho = Ze(100);
263
+ function _o(t, n, e, o, i, s, r, u) {
264
+ var O, g, _, w, ne;
265
+ const c = bt(t), b = o ?? c, p = un(b, n), F = n.amount === 0 ? null : dn(p, {
266
+ ...n,
267
+ amount: Math.abs(n.amount)
268
+ }), E = F ? yt(F, ho) : null, U = ((O = t.sku.defaultCost) == null ? void 0 : O.costPerUnit) ?? { amount: 0, precision: 0 }, P = Number(ae.toFormatString({ value: U })), S = ((_ = (g = t.sku.defaultCost) == null ? void 0 : g.measurement) == null ? void 0 : _.conversion) ?? {
269
+ amount: 1,
270
+ precision: 0
271
+ }, L = Number(
272
+ ae.toFormatString({ value: S })
273
+ ), W = i ? Number(ae.toFormatString({ value: i })) : 0, T = Number(ae.toFormatString({ value: n })), z = Number(ae.toFormatString({ value: b })), C = z - T, x = C * P / L, d = z * P / L, h = T * P / L, B = {};
274
+ return r && s && r.forEach((Z) => {
275
+ const j = { amount: 0, precision: 0 }, H = s[Z];
276
+ if (H) {
277
+ const A = ft(j, H);
278
+ B[`adjustment_${Z}`] = At(A);
279
+ } else
280
+ B[`adjustment_${Z}`] = "0";
281
+ }), {
282
+ code: t.sku.code,
283
+ name: t.sku.name,
284
+ baseUnit: t.sku.unit.abbrev,
285
+ costUnit: ((ne = (w = t.sku.defaultCost) == null ? void 0 : w.measurement) == null ? void 0 : ne.abbrev) ?? null,
286
+ baseUnitAmount: Number(ae.toFormatString({ value: t.baseAmount })),
287
+ ...e.reduce(
288
+ (Z, j, H) => {
289
+ const A = ae.toFormatString({ value: j.conversion }), V = j.orphan ? " [invalid UOM]" : j.inactive ? " [NetSuite-inactive]" : "";
290
+ return Z[`measurementAbbrev${H}`] = `(${j.abbrev}) × ${A}${V}`, Z[`measurementAmount${H}`] = Number(ae.toFormatString({ value: j.amount })), Z;
291
+ },
292
+ {}
293
+ ),
294
+ systemBalance: T,
295
+ physicalBalance: z,
296
+ adjustedAmount: Number(ae.toFormatString({ value: p })),
297
+ adjustedDiffPercentage: E ? Number(
298
+ ae.toFormatString({
299
+ value: mn(E, 2)
300
+ })
301
+ ) : null,
302
+ costPerUnit: P,
303
+ opening: W,
304
+ ...B,
305
+ varianceQty: C,
306
+ varianceInCost: x,
307
+ stockTakeValue: d,
308
+ systemValue: h,
309
+ // Include custom attribute values
310
+ ...(u ?? []).reduce(
311
+ (Z, j) => {
312
+ var A;
313
+ const H = (A = t.sku.customAttributes) == null ? void 0 : A[j];
314
+ return Z[`customAttr_${j}`] = H != null ? String(H) : null, Z;
315
+ },
316
+ {}
317
+ )
318
+ };
319
+ }
320
+ function ko(t) {
321
+ let n = 0;
322
+ for (const e of t.values())
323
+ e.length > n && (n = e.length);
324
+ return n;
325
+ }
326
+ function xo(t, n) {
327
+ const e = /* @__PURE__ */ new Map();
328
+ for (const o of t) {
329
+ if (e.has(o.sku._id)) continue;
330
+ const i = new Map(o.sku.unit.measurements.map((u) => [u.id, u])), s = new Map(
331
+ o.measurementsAmounts.map((u) => [u.measurement.id, u.amount])
332
+ ), r = [];
333
+ for (const u of o.sku.unit.measurements) {
334
+ const c = s.get(u.id);
335
+ c && r.push({
336
+ id: u.id,
337
+ abbrev: u.abbrev,
338
+ conversion: u.conversion,
339
+ amount: c,
340
+ inactive: Tt(u, n),
341
+ orphan: !1
342
+ });
343
+ }
344
+ for (const u of o.measurementsAmounts)
345
+ i.has(u.measurement.id) || r.push({
346
+ id: u.measurement.id,
347
+ abbrev: u.measurement.abbrev,
348
+ conversion: u.measurement.conversion,
349
+ amount: u.amount,
350
+ inactive: !1,
351
+ orphan: !0
352
+ });
353
+ e.set(o.sku._id, r);
354
+ }
355
+ return e;
356
+ }
357
+ function wo(t, n = [], e = []) {
358
+ const o = an(), i = o === "MYR" ? "RM" : o;
359
+ return [
360
+ {
361
+ id: "code",
362
+ name: "Code"
363
+ },
364
+ {
365
+ id: "name",
366
+ name: "Name"
367
+ },
368
+ {
369
+ id: "baseUnit",
370
+ name: "Base unit"
371
+ },
372
+ {
373
+ id: "costPerUnit",
374
+ name: "Cost per unit"
375
+ },
376
+ {
377
+ id: "costUnit",
378
+ name: "UOM"
379
+ },
380
+ {
381
+ id: "opening",
382
+ name: "Opening (B/F)"
383
+ },
384
+ // Dynamic adjustment type columns
385
+ ...n.map((r) => ({
386
+ id: `adjustment_${r}`,
387
+ name: Ie(r)
388
+ })),
389
+ {
390
+ id: "systemBalance",
391
+ name: "System balance (Qty)"
392
+ },
393
+ {
394
+ id: "physicalBalance",
395
+ name: "Stock take (Qty)"
396
+ },
397
+ {
398
+ id: "adjustedAmount",
399
+ name: "Variance"
400
+ },
401
+ {
402
+ id: "varianceInCost",
403
+ name: `Variance (${i})`
404
+ },
405
+ {
406
+ id: "adjustedDiffPercentage",
407
+ name: "Variance (%)"
408
+ },
409
+ {
410
+ id: "stockTakeValue",
411
+ name: `Stock take value (${i})`
412
+ },
413
+ {
414
+ id: "systemValue",
415
+ name: `System value (${i})`
416
+ },
417
+ {
418
+ id: "baseUnitAmount",
419
+ name: "Base unit amount"
420
+ },
421
+ ...Array.from({ length: t }).flatMap((r, u) => [
422
+ {
423
+ id: `measurementAmount${u}`,
424
+ name: `UOM amount ${u + 1}`
425
+ },
426
+ {
427
+ id: `measurementAbbrev${u}`,
428
+ name: `UOM ${u + 1}`
429
+ }
430
+ ]),
431
+ // Dynamic custom attribute columns
432
+ ...e.map((r) => ({
433
+ id: `customAttr_${r}`,
434
+ name: Ie(r)
435
+ }))
436
+ ];
437
+ }
438
+ function Do(t, n, e, o = [], i) {
439
+ var M, O, g, _, w, ne, Z;
440
+ const s = n.groupBy(
441
+ (j) => j.id,
442
+ (j) => j.balance
443
+ ), r = e.groupBy(
444
+ (j) => j.id,
445
+ (j) => j.balance
446
+ ), u = /* @__PURE__ */ new Map();
447
+ if (t.opening)
448
+ for (const j of t.opening)
449
+ u.set(j.skuId, j.balance);
450
+ const c = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map();
451
+ if (t.adjustmentSnapshot)
452
+ for (const j of t.adjustmentSnapshot)
453
+ j.adjustmentsByType && (Object.keys(j.adjustmentsByType).forEach((H) => c.add(H)), b.set(j.skuId, j.adjustmentsByType));
454
+ const p = ["receive", "sales", "wastage"], F = [];
455
+ p.forEach((j) => {
456
+ c.has(j) && (F.push(j), c.delete(j));
457
+ });
458
+ const E = Array.from(c).sort(), U = [...F, ...E], P = [...t.items, ...t.negativeStockItems ?? []], L = nn().currentBusiness.value, W = xo(P, i), T = P.map((j) => {
459
+ var se, ye;
460
+ const H = ((se = s.get(j.sku._id)) == null ? void 0 : se[0]) ?? bo, A = W.get(j.sku._id) ?? [], V = u.get(j.sku._id), ie = b.get(j.sku._id);
461
+ return _o(
462
+ j,
463
+ H,
464
+ A,
465
+ (ye = r.get(j.sku._id)) == null ? void 0 : ye[0],
466
+ V,
467
+ ie,
468
+ U,
469
+ o
470
+ );
471
+ }), z = ko(W), C = wo(z, U, o), x = [
472
+ ["Business name:", L == null ? void 0 : L.name],
473
+ ["Business ID:", L == null ? void 0 : L._id],
474
+ ["Menu version", L == null ? void 0 : L.menuVersion],
475
+ ["Created at", new Date(t.createdAt)],
476
+ ["Created by", (M = t.createdBy) == null ? void 0 : M.name],
477
+ ["Updated at", new Date(t.updatedAt)],
478
+ ["Updated by", (O = t.updatedBy) == null ? void 0 : O.name],
479
+ ["Recent action", t.approvedAt ? "Approve" : t.rejectionHistory ? "Reject" : ""],
480
+ [
481
+ "Action by",
482
+ t.approvedAt ? (g = t.approvedBy) == null ? void 0 : g.name : t.rejectionHistory ? (w = (_ = t.rejectionHistory[0]) == null ? void 0 : _.rejectedBy) == null ? void 0 : w.name : ""
483
+ ],
484
+ [
485
+ "Action at",
486
+ t.approvedAt ? new Date(t.approvedAt) : t.rejectionHistory ? new Date((ne = t.rejectionHistory[0]) == null ? void 0 : ne.rejectedAt) : ""
487
+ ],
488
+ [
489
+ "Action remark",
490
+ t.approvedAt ? t.approveRemark : t.rejectionHistory ? new Date((Z = t.rejectionHistory[0]) == null ? void 0 : Z.rejectRemark) : ""
491
+ ],
492
+ [],
493
+ C.map((j) => j.name),
494
+ ...T.map((j) => C.map((H) => j[H.id]))
495
+ ], d = C.map((j) => `system:${j.id}`), h = qn(x, d), B = `[${L == null ? void 0 : L.name}] closing draft (${Wn(new Date(t.updatedAt))}).xlsx`;
496
+ return Qn(h, B), B;
497
+ }
498
+ const $o = { class: "flex flex-col" }, Co = {
499
+ key: 0,
500
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-error mt-4"
501
+ }, Ao = { class: "flex gap-12 py-8 justify-end w-full" }, So = /* @__PURE__ */ Se({
502
+ __name: "RefreshBalanceAction",
503
+ props: {
504
+ draft: {},
505
+ onCancel: { type: Function },
506
+ onFinished: { type: Function }
507
+ },
508
+ setup(t) {
509
+ const n = t;
510
+ gt();
511
+ const e = q(!1), o = q(null), i = q(!1);
512
+ Ft(() => {
513
+ if (n.draft.effectiveAt)
514
+ o.value = new Date(n.draft.effectiveAt);
515
+ else {
516
+ const b = new Date(n.draft.createdAt);
517
+ b.setHours(23, 59, 59, 999), o.value = b;
518
+ }
519
+ i.value = !0;
520
+ });
521
+ const s = I({
522
+ get() {
523
+ return o.value === null ? "" : mt(o.value);
524
+ },
525
+ set(b) {
526
+ if (b) {
527
+ const p = /* @__PURE__ */ new Date(`${b} ${r.value}`);
528
+ p.setSeconds(59, 999), o.value = p;
529
+ } else
530
+ o.value = null;
531
+ }
532
+ }), r = I({
533
+ get() {
534
+ return o.value === null ? "" : rn(o.value);
535
+ },
536
+ set(b) {
537
+ if (b) {
538
+ const p = /* @__PURE__ */ new Date(`${s.value} ${b}`);
539
+ p.setSeconds(59, 999), o.value = p;
540
+ } else
541
+ o.value = null;
542
+ }
543
+ }), u = I(() => o.value ? o.value.getTime() > (/* @__PURE__ */ new Date()).getTime() : !1);
544
+ async function c() {
545
+ e.value = !0, n.onFinished(o.value.toISOString());
546
+ }
547
+ return (b, p) => {
548
+ const F = J("FmLabel"), E = J("FmDatePicker"), U = J("FmTimePicker"), P = J("FmButton"), S = J("FmForm");
549
+ return i.value ? (f(), oe(S, {
550
+ key: 1,
551
+ onValidationSuccess: c,
552
+ class: "flex flex-col gap-32",
553
+ disabled: e.value
554
+ }, {
555
+ default: te(() => [
556
+ p[5] || (p[5] = a("div", { class: "fm-typo-en-body-lg-400" }, [
557
+ a("p", null, [
558
+ me(" Performing "),
559
+ a("span", { class: "fm-typo-en-body-lg-600" }, '"Refresh Balance"'),
560
+ me(" until closing effective date and time. ")
561
+ ]),
562
+ a("p", { class: "mt-2" }, [
563
+ me(" Please note that this action will "),
564
+ a("b", null, "update"),
565
+ me(" the effective date and time. ")
566
+ ])
567
+ ], -1)),
568
+ a("div", $o, [
569
+ D(F, { class: "fm-typo-en-body-lg-600" }, {
570
+ default: te(() => p[3] || (p[3] = [
571
+ me("Closing Date")
572
+ ])),
573
+ _: 1
574
+ }),
575
+ D(E, {
576
+ modelValue: s.value,
577
+ "onUpdate:modelValue": p[0] || (p[0] = (L) => s.value = L),
578
+ max: m(mt)(/* @__PURE__ */ new Date())
579
+ }, null, 8, ["modelValue", "max"]),
580
+ D(F, { class: "fm-typo-en-body-lg-600" }, {
581
+ default: te(() => p[4] || (p[4] = [
582
+ me("Closing Time")
583
+ ])),
584
+ _: 1
585
+ }),
586
+ D(U, {
587
+ modelValue: r.value,
588
+ "onUpdate:modelValue": p[1] || (p[1] = (L) => r.value = L)
589
+ }, null, 8, ["modelValue"]),
590
+ u.value ? (f(), $("div", Co, " Cannot select future date ")) : Y("", !0)
591
+ ]),
592
+ a("div", Ao, [
593
+ D(P, {
594
+ label: "Cancel",
595
+ variant: "tertiary",
596
+ onClick: p[2] || (p[2] = (L) => b.onCancel())
597
+ }),
598
+ D(P, {
599
+ label: "Refresh balance",
600
+ type: "submit",
601
+ variant: "primary",
602
+ loading: e.value,
603
+ disabled: u.value
604
+ }, null, 8, ["loading", "disabled"])
605
+ ])
606
+ ]),
607
+ _: 1
608
+ }, 8, ["disabled"])) : (f(), $(le, { key: 0 }, [
609
+ me("Loading")
610
+ ], 64));
611
+ };
612
+ }
613
+ }), pt = sn(
614
+ "closingDraftActions",
615
+ function() {
616
+ const n = on(), e = Ge(), o = gt(), i = Re(), s = Jn(), r = jt(), u = q(!1), c = q();
617
+ function b(C) {
618
+ const x = {
619
+ draft: C
620
+ };
621
+ c.value = x, u.value = !0;
622
+ }
623
+ async function p(C) {
624
+ var d;
625
+ if (C.status === ke.enum.COMPLETED) {
626
+ const h = C.closingAdjustmentId;
627
+ if (!h)
628
+ return e.open({
629
+ title: "Something went wrong",
630
+ message: "Closing draft is completed but closing document cannot be found.",
631
+ type: "error"
632
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
633
+ draftId: C._id
634
+ }), [];
635
+ const B = await o.readAdjustmentById(h);
636
+ return ((B == null ? void 0 : B.skus) ?? []).map((O) => ({
637
+ id: O.sku._id,
638
+ balance: O.fromBalance,
639
+ costs: O.fromCostBalances
640
+ }));
641
+ } else
642
+ return await s.readStockBalance(), ((d = s.stockBalance) == null ? void 0 : d.skus) ?? [];
643
+ }
644
+ async function F(C, x, d, h) {
645
+ x || (e.open({
646
+ title: "Exporting",
647
+ message: "Fetching data..."
648
+ }), x = await p(C)), Do(
649
+ C,
650
+ x,
651
+ d ?? [],
652
+ h ?? [],
653
+ r.value
654
+ );
655
+ }
656
+ function E(C, x, d) {
657
+ n.open({
658
+ title: "Approve draft",
659
+ contentComponent: Ct,
660
+ contentComponentProps: {
661
+ draft: C,
662
+ action: de.enum.approveDraft,
663
+ onFinished: () => {
664
+ n.close(), x == null || x();
665
+ },
666
+ onCancel: () => {
667
+ n.close();
668
+ }
669
+ }
670
+ }).onClose(() => {
671
+ d == null || d();
672
+ });
673
+ }
674
+ function U(C, x) {
675
+ n.open({
676
+ title: "Reject draft",
677
+ contentComponent: Ct,
678
+ contentComponentProps: {
679
+ draft: C,
680
+ action: de.enum.rejectDraft,
681
+ onFinished: () => {
682
+ n.close(), x == null || x();
683
+ },
684
+ onCancel: () => n.close()
685
+ }
686
+ });
687
+ }
688
+ function P(C, x) {
689
+ n.open({
690
+ title: "Mark draft as failed",
691
+ contentComponent: Ct,
692
+ contentComponentProps: {
693
+ draft: C,
694
+ action: de.enum.markAsFailed,
695
+ onFinished: () => {
696
+ n.close(), x == null || x();
697
+ },
698
+ onCancel: () => n.close()
699
+ }
700
+ });
701
+ }
702
+ async function S(C, x) {
703
+ await i.sync({
704
+ _id: C._id,
705
+ _rev: C._rev ?? "",
706
+ action: de.enum.approveDraft,
707
+ data: {
708
+ remark: C.remark ?? ""
709
+ }
710
+ }).delayed(500), e.open({
711
+ title: "Success",
712
+ message: "Sync requested",
713
+ type: "success"
714
+ }), x == null || x();
715
+ }
716
+ function L() {
717
+ u.value = !1;
718
+ }
719
+ async function W(C, x, d) {
720
+ await n.open({
721
+ title: "Refresh balance",
722
+ contentComponent: So,
723
+ contentComponentProps: {
724
+ draft: C,
725
+ onFinished: (h) => {
726
+ n.close(), d == null || d(h);
727
+ },
728
+ onCancel: async () => {
729
+ n.close(), x == null || x();
730
+ }
731
+ }
732
+ });
733
+ }
734
+ async function T(C) {
735
+ await n.open({
736
+ title: "Invalidate closing draft cache",
737
+ message: "It will invalidate opening and stock movement cache for this draft.",
738
+ primaryActions: { text: "Proceed", close: !0 },
739
+ secondaryActions: { text: "Cancel", close: !0 }
740
+ }).onPrimary(async () => {
741
+ await o.recalculation.scheduleInvalidateClosingDraftCache([C._id]), e.open({
742
+ title: "Success",
743
+ message: "Invalidate cache requested",
744
+ type: "success"
745
+ });
746
+ });
747
+ }
748
+ async function z(C, x) {
749
+ try {
750
+ e.open({
751
+ title: "Cloning",
752
+ message: "Creating a copy of the draft..."
753
+ }), await i.cloneDraft(C._id), e.open({
754
+ title: "Success",
755
+ message: "Draft cloned successfully",
756
+ type: "success"
757
+ }), x == null || x();
758
+ } catch (d) {
759
+ e.open({
760
+ title: "Error",
761
+ message: (d == null ? void 0 : d.message) || "Failed to clone draft",
762
+ type: "error"
763
+ });
764
+ }
765
+ }
766
+ return {
767
+ viewDraft: b,
768
+ closeDraftDialog: L,
769
+ approveDraft: E,
770
+ rejectDraft: U,
771
+ markAsFailed: P,
772
+ syncDraft: S,
773
+ exportDraft: F,
774
+ refreshBalance: W,
775
+ cloneDraft: z,
776
+ viewClosingDraftShow: u,
777
+ viewClosingDraftProps: c,
778
+ invalidateDraftCache: T
779
+ };
780
+ }
781
+ );
782
+ function Je(t) {
783
+ switch (t) {
784
+ case "DRAFT":
785
+ return "fm-status-badge-draft";
786
+ case "PROCESSING":
787
+ return "fm-status-badge-processing";
788
+ case "FAILED":
789
+ return "fm-status-badge-cancel";
790
+ case "COMPLETED":
791
+ return "fm-status-badge-complete";
792
+ }
793
+ }
794
+ function Fo(t) {
795
+ return t.baseAmount.amount > 0 ? !0 : t.measurementsAmounts.some((n) => n.amount.amount !== 0);
796
+ }
797
+ function Io(t) {
798
+ var i, s, r;
799
+ const n = Number(ae.toFormatString({ value: bt(t) })), e = Number(
800
+ ae.toFormatString({
801
+ value: ((i = t.sku.defaultCost) == null ? void 0 : i.costPerUnit) ?? { amount: 0, precision: 0 }
802
+ })
803
+ ), o = Number(
804
+ ae.toFormatString({
805
+ value: ((r = (s = t.sku.defaultCost) == null ? void 0 : s.measurement) == null ? void 0 : r.conversion) ?? { amount: 1, precision: 0 }
806
+ })
807
+ );
808
+ return n * e / o;
809
+ }
810
+ function Bo(t, n) {
811
+ return t.status === ke.enum.COMPLETED ? "COMPLETED" : (t.rejectionHistory ?? []).length > 0 ? "REJECTED" : n > 0 ? "IN_PROGRESS" : "PENDING";
812
+ }
813
+ function ht(t) {
814
+ var n, e;
815
+ return ((e = (n = t.usingTemplates) == null ? void 0 : n[0]) == null ? void 0 : e.name) || "Group";
816
+ }
817
+ function To(t) {
818
+ var e;
819
+ const n = (e = t.usingTemplates) == null ? void 0 : e[0];
820
+ return n != null && n.ref ? n.ref : ht(t).replace(/[^a-z0-9]/gi, "").slice(0, 6).toUpperCase() || "GROUP";
821
+ }
822
+ function St(t) {
823
+ var r, u, c;
824
+ const n = [...t.items, ...t.negativeStockItems ?? []], e = n.filter(Fo).length, o = Bo(t, e), i = n.reduce((b, p) => b + Io(p), 0), s = ((r = t.updatedBy) == null ? void 0 : r.name) || ((u = t.createdBy) == null ? void 0 : u.name) || void 0;
825
+ return {
826
+ id: t._id,
827
+ name: ht(t),
828
+ code: To(t),
829
+ status: o,
830
+ itemCount: n.length,
831
+ totalAmount: i,
832
+ countedCount: e,
833
+ countedBy: e > 0 ? s : void 0,
834
+ verifiedBy: (c = t.approvedBy) == null ? void 0 : c.name,
835
+ updatedBy: s,
836
+ updatedAt: t.updatedAt || t.createdAt
837
+ };
838
+ }
839
+ function jo(t) {
840
+ return t.reduce(
841
+ (n, e) => (n.totalItems += e.itemCount, n.totalAmount += e.totalAmount, e.status === "COMPLETED" ? n.completed++ : e.status === "IN_PROGRESS" ? n.inProgress++ : e.status === "REJECTED" ? n.rejected++ : n.pending++, n),
842
+ {
843
+ groupCount: t.length,
844
+ totalItems: 0,
845
+ totalAmount: 0,
846
+ completed: 0,
847
+ inProgress: 0,
848
+ pending: 0,
849
+ rejected: 0
850
+ }
851
+ );
852
+ }
853
+ const pn = sn(
854
+ "closingDraftTable",
855
+ function() {
856
+ const { t: n } = Xe(), e = nn(), o = pt(), i = q(new Array()), s = q(0), r = q(!1), u = He(), c = Re(), b = q({}), p = q({});
857
+ async function F() {
858
+ if (i.value = [], !!u._currentLocation) {
859
+ r.value = !0;
860
+ try {
861
+ const [g] = await Promise.all([c.readDrafts()]).delayed(1e3);
862
+ i.value = U(g.reverse()), s.value++, L(i.value);
863
+ } catch (g) {
864
+ console.log("Something went wrong when fetching drafts:", g);
865
+ } finally {
866
+ r.value = !1;
867
+ }
868
+ }
869
+ }
870
+ async function E(g) {
871
+ if (!i.value.find((_) => _._id) && u._currentLocation) {
872
+ r.value = !0;
873
+ try {
874
+ const [_] = await Promise.all([
875
+ c.getDraft(g),
876
+ new Promise((w) => setTimeout(w, 1e3))
877
+ ]);
878
+ i.value = U([_]), s.value++, L(i.value);
879
+ } catch (_) {
880
+ console.log("Something went wrong when fetching drafts:", _);
881
+ } finally {
882
+ r.value = !1;
883
+ }
884
+ }
885
+ }
886
+ function U(g) {
887
+ const _ = to(
888
+ g.filter((w) => !!w.closingId).map((w) => ({ closingId: w.closingId, draftCreatedAt: new Date(Pe(w._id)) }))
889
+ );
890
+ return g.map((w) => ({
891
+ ...w,
892
+ closingIdDisplay: w.closingId ? _.get(w.closingId) ?? null : null
893
+ }));
894
+ }
895
+ async function P(g) {
896
+ const _ = await Promise.all(
897
+ g.map(async (w) => {
898
+ try {
899
+ const ne = await c.getClosingGroups(w._id);
900
+ return [w._id, ne];
901
+ } catch (ne) {
902
+ return console.log(`Something went wrong when fetching groups for ${w._id}:`, ne), [w._id, []];
903
+ }
904
+ })
905
+ );
906
+ return Object.fromEntries(_);
907
+ }
908
+ function S(g, _) {
909
+ p.value = { ...p.value, [g]: _ }, b.value = { ...b.value, [g]: _.map(St) };
910
+ }
911
+ async function L(g) {
912
+ const _ = await P(g);
913
+ p.value = _, b.value = Object.fromEntries(
914
+ Object.entries(_).map(([w, ne]) => [w, ne.map(St)])
915
+ ), s.value++;
916
+ }
917
+ async function W(g) {
918
+ try {
919
+ const _ = await c.getClosingGroups(g);
920
+ S(g, _), s.value++;
921
+ } catch (_) {
922
+ console.log(`Something went wrong when refreshing groups for ${g}:`, _);
923
+ }
924
+ }
925
+ function T(g, _) {
926
+ var w;
927
+ return (w = p.value[g]) == null ? void 0 : w.find((ne) => ne._id === _);
928
+ }
929
+ function z(g) {
930
+ i.value = i.value.map((_) => _._id === g._id ? {
931
+ ...g,
932
+ _rev: g._rev,
933
+ closingIdDisplay: _.closingIdDisplay
934
+ } : _), W(g._id), s.value++;
935
+ }
936
+ function C(g) {
937
+ var ne, Z;
938
+ const _ = g.items.length + (((ne = g.negativeStockItems) == null ? void 0 : ne.length) ?? 0), w = (g == null ? void 0 : g.approveRemark) ?? ((Z = g == null ? void 0 : g.rejectionHistory) == null ? void 0 : Z.computeFirst((j) => j.rejectRemark)) ?? g.remark ?? "";
939
+ return { count: _, remark: w };
940
+ }
941
+ function x(g) {
942
+ return b.value[g] ?? [];
943
+ }
944
+ function d(g, _ = "") {
945
+ return k(
946
+ "span",
947
+ {
948
+ class: [
949
+ "inline-flex items-center rounded-sm bg-fm-color-neutral-gray-100 px-8 py-4 fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
950
+ _
951
+ ]
952
+ },
953
+ g
954
+ );
955
+ }
956
+ function h(g) {
957
+ if (!g.length) return null;
958
+ const _ = g.reduce(
959
+ (w, ne) => (ne.status === "COMPLETED" ? w.completed++ : ne.status === "IN_PROGRESS" ? w.inProgress++ : ne.status === "REJECTED" ? w.rejected++ : w.pending++, w),
960
+ { completed: 0, inProgress: 0, pending: 0, rejected: 0 }
961
+ );
962
+ return k("div", { class: "mt-8 flex flex-wrap gap-6" }, [
963
+ d(`${g.length} groups`),
964
+ _.completed ? d(`${_.completed} completed`, "text-fm-color-typo-success") : null,
965
+ _.inProgress ? d(`${_.inProgress} in progress`, "text-fm-color-typo-warning") : null,
966
+ _.pending ? d(`${_.pending} pending`) : null,
967
+ _.rejected ? d(`${_.rejected} rejected`, "text-fm-color-typo-error") : null
968
+ ]);
969
+ }
970
+ function B() {
971
+ o.closeDraftDialog(), F();
972
+ }
973
+ function M(g, _) {
974
+ switch (_ = Hn(_), g) {
975
+ case Le.Details:
976
+ return o.viewDraft(_);
977
+ case Le.Export:
978
+ return o.exportDraft(_);
979
+ case de.enum.approveDraft:
980
+ return o.approveDraft(_, B);
981
+ case de.enum.rejectDraft:
982
+ return o.rejectDraft(_, B);
983
+ case de.enum.markAsFailed:
984
+ return o.markAsFailed(_, B);
985
+ case Le.Duplicate:
986
+ return o.cloneDraft(_, B);
987
+ }
988
+ }
989
+ return {
990
+ columnDefs: [
991
+ {
992
+ id: "_id",
993
+ accessorKey: "_id",
994
+ header: () => n("inventory.closing.table.createdAt"),
995
+ cell(g) {
996
+ return eo(`${g.getValue()}`);
997
+ },
998
+ sortingFn: (g, _) => new Date(Pe(g.original._id)).getTime() - new Date(Pe(_.original._id)).getTime(),
999
+ enableSorting: !0
1000
+ },
1001
+ {
1002
+ id: "closingId",
1003
+ accessorFn: (g) => g.closingIdDisplay,
1004
+ size: 160,
1005
+ header: () => n("inventory.closing.draft.table.id"),
1006
+ cell(g) {
1007
+ return g.getValue();
1008
+ },
1009
+ enableSorting: !0
1010
+ },
1011
+ {
1012
+ accessorKey: "effectiveAt",
1013
+ header: () => n("inventory.closing.draft.table.effectiveAt"),
1014
+ cell(g) {
1015
+ const _ = g.row.original;
1016
+ let w = g.getValue();
1017
+ return w || (w = Pe(_._id)), Fe(w);
1018
+ },
1019
+ enableSorting: !0,
1020
+ size: 230
1021
+ },
1022
+ {
1023
+ id: "description",
1024
+ accessorFn: (g) => {
1025
+ const { count: _, remark: w } = C(g);
1026
+ return `${_} ${w}`;
1027
+ },
1028
+ header: () => n("inventory.closing.draft.table.description"),
1029
+ enableSorting: !0,
1030
+ size: 350,
1031
+ cell(g) {
1032
+ const { count: _, remark: w } = C(g.row.original), ne = x(g.row.original._id), Z = (j, H) => k("div", { class: "flex gap-4" }, [
1033
+ k(
1034
+ "span",
1035
+ { class: "fm-typo-en-body-sm-600 text-fm-color-typo-primary" },
1036
+ `${j}:`
1037
+ ),
1038
+ k(
1039
+ "span",
1040
+ {
1041
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary",
1042
+ style: "white-space: pre-wrap; word-break: break-word;"
1043
+ },
1044
+ `${H}`
1045
+ )
1046
+ ]);
1047
+ return k("div", { class: "flex flex-col gap-2", style: "width: 300px;" }, [
1048
+ Z(n("inventory.closing.draft.table.items"), _),
1049
+ w ? Z(n("inventory.closing.draft.table.remark"), w) : null,
1050
+ h(ne)
1051
+ ]);
1052
+ }
1053
+ },
1054
+ {
1055
+ id: "status",
1056
+ accessorFn: (g) => g.status,
1057
+ header: () => n("inventory.closing.table.status"),
1058
+ enableSorting: !1,
1059
+ cell(g) {
1060
+ var H;
1061
+ const _ = g.row.original, w = _.status, ne = new Date(_.updatedAt), Z = (H = _ == null ? void 0 : _.rejectionHistory) == null ? void 0 : H.computeFirst((A) => A.rejectedAt), j = Z ? new Date(Z) : null;
1062
+ return w === "DRAFT" && j ? j.getTime() > ne.getTime() ? k(
1063
+ "div",
1064
+ {
1065
+ class: "flex"
1066
+ },
1067
+ k(
1068
+ "div",
1069
+ {
1070
+ class: ["fm-status-badge", Je("FAILED")]
1071
+ },
1072
+ "Rejected"
1073
+ )
1074
+ ) : k(
1075
+ "div",
1076
+ {
1077
+ class: "flex"
1078
+ },
1079
+ k(
1080
+ "div",
1081
+ {
1082
+ class: ["fm-status-badge", Je("PROCESSING")]
1083
+ },
1084
+ "Updated"
1085
+ )
1086
+ ) : k(
1087
+ "div",
1088
+ {
1089
+ class: "flex"
1090
+ },
1091
+ k(
1092
+ "div",
1093
+ {
1094
+ class: ["fm-status-badge", Je(w)]
1095
+ },
1096
+ Ie(w)
1097
+ )
1098
+ );
1099
+ }
1100
+ },
1101
+ {
1102
+ id: "updatedAt",
1103
+ accessorFn: (g) => g.updatedAt,
1104
+ header: () => n("inventory.closing.draft.table.lastUpdate"),
1105
+ enableSorting: !0,
1106
+ size: 200,
1107
+ cell(g) {
1108
+ var w;
1109
+ const _ = g.row.original;
1110
+ return k("div", { class: "flex flex-col" }, [
1111
+ k(
1112
+ "div",
1113
+ { class: "fm-typo-en-body-md-600 text-fm-color-typo-primary" },
1114
+ ((w = _.updatedBy) == null ? void 0 : w.name) ?? ""
1115
+ ),
1116
+ k(
1117
+ "div",
1118
+ { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
1119
+ Fe(_.updatedAt)
1120
+ )
1121
+ ]);
1122
+ }
1123
+ },
1124
+ {
1125
+ id: "action",
1126
+ cell(g) {
1127
+ var H;
1128
+ const _ = g.row.original, w = ((H = e.sessionUser.value) == null ? void 0 : H.role.isAdmin) ?? !1, ne = [
1129
+ en[Le.Details],
1130
+ en[Le.Export]
1131
+ ], Z = [
1132
+ {
1133
+ translationKey: "inventory.closing.draft.approveDraft",
1134
+ color: "text-fm-color-typo-primary",
1135
+ value: de.enum.approveDraft
1136
+ },
1137
+ {
1138
+ translationKey: "inventory.closing.draft.rejectDraft",
1139
+ color: "text-fm-color-typo-error",
1140
+ value: de.enum.rejectDraft
1141
+ },
1142
+ {
1143
+ translationKey: "inventory.closing.draft.markAsFailed",
1144
+ color: "text-fm-color-typo-error",
1145
+ value: de.enum.markAsFailed
1146
+ }
1147
+ ], j = w && _.status !== ke.enum.DRAFT ? [
1148
+ {
1149
+ translationKey: "inventory.closing.draft.cloneDraft",
1150
+ color: "text-fm-color-typo-primary",
1151
+ value: Le.Duplicate
1152
+ }
1153
+ ] : [];
1154
+ return Xn(
1155
+ [
1156
+ ...ne,
1157
+ ..._.status === ke.enum.DRAFT ? Z : []
1158
+ ],
1159
+ (A) => M(A, _),
1160
+ j
1161
+ );
1162
+ },
1163
+ enableSorting: !1,
1164
+ size: 40,
1165
+ meta: {
1166
+ cellClass: "",
1167
+ headerClass: ""
1168
+ }
1169
+ }
1170
+ ],
1171
+ drafts: i,
1172
+ loading: r,
1173
+ tableKey: s,
1174
+ groupsByDraftId: b,
1175
+ getRawGroup: T,
1176
+ refreshDraftGroups: W,
1177
+ fetchDrafts: F,
1178
+ loadDraft: E,
1179
+ updateDraftRef: z
1180
+ };
1181
+ }
1182
+ );
1183
+ function Po(t) {
1184
+ const n = /* @__PURE__ */ new Map();
1185
+ for (const e of t)
1186
+ for (const o of e) {
1187
+ const i = n.get(o.sku._id);
1188
+ if (!i) {
1189
+ n.set(o.sku._id, {
1190
+ ...o,
1191
+ baseAmount: { ...o.baseAmount },
1192
+ measurementsAmounts: o.measurementsAmounts.map((s) => ({
1193
+ ...s,
1194
+ amount: { ...s.amount }
1195
+ }))
1196
+ });
1197
+ continue;
1198
+ }
1199
+ i.baseAmount = ft(i.baseAmount, o.baseAmount);
1200
+ for (const s of o.measurementsAmounts) {
1201
+ const r = i.measurementsAmounts.findIndex(
1202
+ (u) => u.measurement.id === s.measurement.id
1203
+ );
1204
+ r > -1 ? i.measurementsAmounts[r].amount = ft(
1205
+ i.measurementsAmounts[r].amount,
1206
+ s.amount
1207
+ ) : i.measurementsAmounts.push({ ...s, amount: { ...s.amount } });
1208
+ }
1209
+ }
1210
+ return [...n.values()];
1211
+ }
1212
+ const Ro = { class: "fm-typo-en-heading-lg-600" }, Mo = { class: "py-4" }, Uo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, No = { key: 0 }, Vo = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full mb-4" }, Eo = {
1213
+ key: 0,
1214
+ class: "text-fm-color-system-success-300"
1215
+ }, Lo = {
1216
+ key: 1,
1217
+ class: "text-fm-color-system-error-300"
1218
+ }, zo = { class: "fm-typo-en-body-md-400" }, Oo = { class: "mt-4 flex gap-4" }, Go = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Ho = { key: 0 }, Yo = { class: "mt-4 flex gap-4" }, Ko = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, Wo = { key: 0 }, qo = {
1219
+ key: 0,
1220
+ class: "mb-4"
1221
+ }, Qo = { class: "flex flex-col gap-1 max-h-200 overflow-auto w-full" }, Jo = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Zo = {
1222
+ key: 0,
1223
+ class: "text-fm-color-system-success-300 mr-1"
1224
+ }, Xo = {
1225
+ key: 1,
1226
+ class: "text-fm-color-system-error-300 mr-1"
1227
+ }, ea = { class: "fm-typo-en-body-md-400" }, ta = { class: "mt-4 flex gap-4" }, na = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary mb-4" }, oa = {
1228
+ key: 0,
1229
+ class: "flex gap-4"
1230
+ }, Qe = 1, ze = 2, Oe = 3, je = 4, aa = /* @__PURE__ */ Se({
1231
+ __name: "ClosingDraftApprovalDialog",
1232
+ props: {
1233
+ show: { type: Boolean },
1234
+ refreshing: { type: Boolean },
1235
+ approving: { type: Boolean },
1236
+ draft: {},
1237
+ groups: {}
1238
+ },
1239
+ emits: ["update:show", "refresh", "approve"],
1240
+ setup(t, { emit: n }) {
1241
+ const { FmStepper: e, FmStep: o, FmDialog: i, FmButton: s } = ve, { t: r } = oo(), u = Bt(), c = t, b = n, p = I(
1242
+ () => {
1243
+ var A, V;
1244
+ return ((A = c.draft) == null ? void 0 : A.stockSnapshot) && ((V = c.draft) == null ? void 0 : V.stockSnapshot) !== void 0;
1245
+ }
1246
+ ), F = I(() => {
1247
+ var ie, se, ye;
1248
+ const A = ((ie = c.draft) == null ? void 0 : ie.items.map((pe) => ({
1249
+ id: pe.sku._id,
1250
+ code: pe.sku.code,
1251
+ name: pe.sku.name
1252
+ }))) ?? [], V = ((ye = (se = c.draft) == null ? void 0 : se.negativeStockItems) == null ? void 0 : ye.map((pe) => ({
1253
+ id: pe.sku._id,
1254
+ code: pe.sku.code,
1255
+ name: pe.sku.name
1256
+ }))) ?? [];
1257
+ return [...A, ...V].reduce(
1258
+ (pe, De) => (pe[De.id] = De, pe),
1259
+ {}
1260
+ );
1261
+ }), E = I(
1262
+ () => {
1263
+ var A, V, ie;
1264
+ return (((ie = (V = (A = c.draft) == null ? void 0 : A.stockSnapshot) == null ? void 0 : V.filter((se) => se.balance.amount < 0)) == null ? void 0 : ie.map((se) => {
1265
+ const ye = u.skuById[se.id];
1266
+ return ye ? {
1267
+ id: ye._id,
1268
+ code: ye.code,
1269
+ name: ye.name
1270
+ } : null;
1271
+ })) ?? []).filter((se) => se !== null);
1272
+ }
1273
+ ), U = I(() => {
1274
+ var A;
1275
+ return p.value ? ((A = E.value) == null ? void 0 : A.filter((V) => !F.value[V.id]).map((V) => V.id)) ?? [] : [];
1276
+ }), P = I({
1277
+ get: () => c.show,
1278
+ set: (A) => b("update:show", A)
1279
+ }), S = I(() => {
1280
+ var A;
1281
+ return (((A = c.groups) == null ? void 0 : A.length) ?? 0) > 0;
1282
+ }), L = I(
1283
+ () => {
1284
+ var A;
1285
+ return ((A = c.groups) == null ? void 0 : A.filter((V) => V.status !== ke.enum.COMPLETED)) ?? [];
1286
+ }
1287
+ ), W = I(() => L.value.length === 0), T = q(Qe), z = () => T.value > Qe, C = () => T.value > ze, x = () => T.value > Oe, d = () => !1;
1288
+ function h(A) {
1289
+ return A === Qe ? !S.value : A === ze ? p.value : A === Oe ? U.value.length == 0 : !1;
1290
+ }
1291
+ const B = I(() => !p.value || U.value.length > 0 || S.value && !W.value);
1292
+ function M() {
1293
+ let A = 1;
1294
+ for (; A < je && h(A); ) A++;
1295
+ return A;
1296
+ }
1297
+ const O = I(() => T.value > M());
1298
+ function g(A) {
1299
+ let V = A + 1;
1300
+ for (; V <= je && h(V); ) V++;
1301
+ return V > je ? je : V;
1302
+ }
1303
+ function _(A) {
1304
+ let V = A - 1;
1305
+ for (; V >= 1 && h(V); ) V--;
1306
+ const ie = M();
1307
+ return V < ie ? ie : V;
1308
+ }
1309
+ function w() {
1310
+ return M();
1311
+ }
1312
+ Te(
1313
+ () => c.show,
1314
+ (A) => {
1315
+ A && (T.value = w());
1316
+ }
1317
+ ), Te(
1318
+ () => p.value,
1319
+ (A) => {
1320
+ A && T.value === ze && (T.value = g(ze));
1321
+ }
1322
+ ), Te(
1323
+ () => U.value.length,
1324
+ (A) => {
1325
+ A === 0 && T.value === Oe && (T.value = g(Oe));
1326
+ }
1327
+ );
1328
+ function ne() {
1329
+ b("refresh");
1330
+ }
1331
+ function Z() {
1332
+ T.value < je && (T.value = g(T.value));
1333
+ }
1334
+ function j() {
1335
+ T.value > 1 && (T.value = _(T.value));
1336
+ }
1337
+ function H() {
1338
+ b("approve");
1339
+ }
1340
+ return (A, V) => {
1341
+ const ie = J("FmIcon");
1342
+ return f(), oe(m(i), {
1343
+ modelValue: P.value,
1344
+ "onUpdate:modelValue": V[1] || (V[1] = (se) => P.value = se),
1345
+ "max-width": 600
1346
+ }, {
1347
+ "dialog-header": te(() => [
1348
+ a("div", Ro, N(m(r)("inventory.closing.approval.title")), 1)
1349
+ ]),
1350
+ default: te(() => [
1351
+ a("div", Mo, [
1352
+ D(m(e), {
1353
+ modelValue: T.value,
1354
+ "onUpdate:modelValue": V[0] || (V[0] = (se) => T.value = se),
1355
+ orientation: "vertical"
1356
+ }, {
1357
+ default: te(() => [
1358
+ S.value ? (f(), oe(m(o), {
1359
+ key: 0,
1360
+ value: Qe,
1361
+ title: m(r)("inventory.closing.approval.step.groups.title"),
1362
+ complete: z
1363
+ }, {
1364
+ default: te(() => [
1365
+ a("div", Uo, N(W.value ? m(r)("inventory.closing.approval.step.groups.completedMessage") : m(r)("inventory.closing.approval.step.groups.pendingMessage")), 1),
1366
+ T.value === Qe ? (f(), $("div", No, [
1367
+ a("div", Vo, [
1368
+ (f(!0), $(le, null, ge(A.groups ?? [], (se) => (f(), $("div", {
1369
+ key: se._id,
1370
+ class: "flex gap-8 items-center"
1371
+ }, [
1372
+ se.status === m(ke).enum.COMPLETED ? (f(), $("span", Eo, [
1373
+ D(ie, {
1374
+ name: "check_circle",
1375
+ size: "sm"
1376
+ })
1377
+ ])) : (f(), $("span", Lo, [
1378
+ D(ie, {
1379
+ name: "error",
1380
+ size: "sm"
1381
+ })
1382
+ ])),
1383
+ a("div", zo, N(m(ht)(se)), 1)
1384
+ ]))), 128))
1385
+ ]),
1386
+ a("div", Oo, [
1387
+ D(m(s), {
1388
+ label: m(r)("inventory.common.continue"),
1389
+ disabled: !W.value,
1390
+ onClick: Z
1391
+ }, null, 8, ["label", "disabled"])
1392
+ ])
1393
+ ])) : Y("", !0)
1394
+ ]),
1395
+ _: 1
1396
+ }, 8, ["title"])) : Y("", !0),
1397
+ D(m(o), {
1398
+ value: ze,
1399
+ title: m(r)("inventory.closing.approval.step.generateReport.title"),
1400
+ disabled: () => S.value && !W.value,
1401
+ complete: C
1402
+ }, {
1403
+ default: te(() => [
1404
+ a("div", Go, N(m(r)("inventory.closing.approval.step.generateReport.description")), 1),
1405
+ T.value === ze ? (f(), $("div", Ho, [
1406
+ D(m(s), {
1407
+ label: m(r)("inventory.stock.stock_balance.refreshBalance"),
1408
+ "prepend-icon": "refresh",
1409
+ variant: "secondary",
1410
+ loading: A.refreshing,
1411
+ disabled: A.refreshing,
1412
+ onClick: ne
1413
+ }, null, 8, ["label", "loading", "disabled"]),
1414
+ a("div", Yo, [
1415
+ O.value ? (f(), oe(m(s), {
1416
+ key: 0,
1417
+ label: m(r)("inventory.common.back"),
1418
+ variant: "secondary",
1419
+ onClick: j
1420
+ }, null, 8, ["label"])) : Y("", !0),
1421
+ D(m(s), {
1422
+ label: m(r)("inventory.common.continue"),
1423
+ disabled: !p.value,
1424
+ onClick: Z
1425
+ }, null, 8, ["label", "disabled"])
1426
+ ])
1427
+ ])) : Y("", !0)
1428
+ ]),
1429
+ _: 1
1430
+ }, 8, ["title", "disabled"]),
1431
+ D(m(o), {
1432
+ value: Oe,
1433
+ title: m(r)("inventory.closing.approval.step.negativeItems.title"),
1434
+ disabled: () => !p.value,
1435
+ complete: x
1436
+ }, {
1437
+ default: te(() => [
1438
+ a("div", Ko, N(E.value.length > 0 ? `${m(r)("inventory.closing.approval.step.negativeItems.resolveMessage")} [${m(r)("inventory.closing.approval.step.negativeItems.itemsHeader")} (${U.value.length})]` : m(r)("inventory.closing.approval.step.negativeItems.noItemsMessage")), 1),
1439
+ T.value === Oe ? (f(), $("div", Wo, [
1440
+ E.value.length > 0 ? (f(), $("div", qo, [
1441
+ V[2] || (V[2] = a("div", { class: "fm-typo-en-body-md-600 mb-2" }, null, -1)),
1442
+ a("div", Qo, [
1443
+ (f(!0), $(le, null, ge(E.value, (se) => (f(), $("div", {
1444
+ key: se.id,
1445
+ class: "flex gap-8"
1446
+ }, [
1447
+ a("div", Jo, [
1448
+ F.value[se.id] ? (f(), $("span", Zo, [
1449
+ D(ie, {
1450
+ name: "check_circle",
1451
+ size: "sm"
1452
+ })
1453
+ ])) : (f(), $("span", Xo, [
1454
+ D(ie, {
1455
+ name: "error",
1456
+ size: "sm"
1457
+ })
1458
+ ])),
1459
+ me(" " + N(se.code), 1)
1460
+ ]),
1461
+ a("div", ea, N(se.name), 1)
1462
+ ]))), 128))
1463
+ ])
1464
+ ])) : Y("", !0),
1465
+ a("div", ta, [
1466
+ O.value ? (f(), oe(m(s), {
1467
+ key: 0,
1468
+ label: m(r)("inventory.common.back"),
1469
+ variant: "secondary",
1470
+ onClick: j
1471
+ }, null, 8, ["label"])) : Y("", !0),
1472
+ D(m(s), {
1473
+ label: m(r)("inventory.common.continue"),
1474
+ disabled: B.value,
1475
+ onClick: Z
1476
+ }, null, 8, ["label", "disabled"])
1477
+ ])
1478
+ ])) : Y("", !0)
1479
+ ]),
1480
+ _: 1
1481
+ }, 8, ["title", "disabled"]),
1482
+ D(m(o), {
1483
+ value: je,
1484
+ title: m(r)("inventory.closing.approval.step.approval.title"),
1485
+ disabled: () => B.value,
1486
+ complete: d
1487
+ }, {
1488
+ default: te(() => [
1489
+ a("div", na, N(m(r)("inventory.closing.approval.step.approval.warning")), 1),
1490
+ T.value === je ? (f(), $("div", oa, [
1491
+ O.value ? (f(), oe(m(s), {
1492
+ key: 0,
1493
+ label: m(r)("inventory.common.back"),
1494
+ variant: "secondary",
1495
+ onClick: j
1496
+ }, null, 8, ["label"])) : Y("", !0),
1497
+ D(m(s), {
1498
+ label: m(r)("inventory.common.approve"),
1499
+ variant: "destructive",
1500
+ disabled: B.value,
1501
+ loading: A.approving,
1502
+ onClick: H
1503
+ }, null, 8, ["label", "disabled", "loading"])
1504
+ ])) : Y("", !0)
1505
+ ]),
1506
+ _: 1
1507
+ }, 8, ["title", "disabled"])
1508
+ ]),
1509
+ _: 1
1510
+ }, 8, ["modelValue"])
1511
+ ])
1512
+ ]),
1513
+ _: 1
1514
+ }, 8, ["modelValue"]);
1515
+ };
1516
+ }
1517
+ });
1518
+ function sa(t) {
1519
+ const n = Re(), e = Zn(), o = Ge(), { t: i } = Xe(), s = q(!1), r = q(null);
1520
+ let u = !1, c = null, b = !1, p = !1;
1521
+ function F() {
1522
+ L();
1523
+ const z = t.closingDraftId.value, C = t.currentRev.value;
1524
+ if (!z || !C)
1525
+ return;
1526
+ u = !1;
1527
+ const x = {
1528
+ type: "closing-draft",
1529
+ params: {
1530
+ draftId: z,
1531
+ locationId: n.getDbName(),
1532
+ closingDraftRevision: C
1533
+ }
1534
+ }, { unsubscribe: d, initialState: h } = e.subscribe(x, U);
1535
+ c = d, h.then((B) => {
1536
+ B != null && B.initialState && U(B.initialState);
1537
+ }).catch((B) => {
1538
+ console.error("Failed to fetch initial state", B);
1539
+ });
1540
+ }
1541
+ function E() {
1542
+ p = !0, F();
1543
+ }
1544
+ async function U(z) {
1545
+ var x;
1546
+ if (u || !z) {
1547
+ r.value = z, s.value = !1;
1548
+ return;
1549
+ }
1550
+ if (z.closingDraftId && z.closingDraftId !== t.closingDraftId.value)
1551
+ return;
1552
+ if (r.value = z, z.message === "processing" || !z.completedAt && !z.message) {
1553
+ b = !0, s.value = !0;
1554
+ return;
1555
+ }
1556
+ if (z.message === "completed" || z.completedAt) {
1557
+ if (!b) {
1558
+ s.value = !1;
1559
+ return;
1560
+ }
1561
+ b = !1, await P();
1562
+ return;
1563
+ }
1564
+ const C = b;
1565
+ b = !1, s.value = !1, C && (console.log("Closing draft balance refresh error:", z), o.open({
1566
+ title: i("inventory.common.refreshFailed"),
1567
+ message: i("inventory.stock.stock_balance.refreshBalanceError"),
1568
+ type: "error"
1569
+ }), (x = t.onError) == null || x.call(t, z.message ?? "Unknown error"));
1570
+ }
1571
+ async function P() {
1572
+ const z = t.closingDraftId.value;
1573
+ if (!z) {
1574
+ s.value = !1;
1575
+ return;
1576
+ }
1577
+ try {
1578
+ const C = await n.getDraft(z);
1579
+ s.value = !1, t.onCompleted(C), o.open({
1580
+ title: "Balance refreshed",
1581
+ message: "Stock balance has been recalculated.",
1582
+ type: "success"
1583
+ });
1584
+ } catch {
1585
+ s.value = !1, o.open({
1586
+ title: "Refresh completed",
1587
+ message: "Balance was refreshed but failed to load updated data. Please reload.",
1588
+ type: "warning"
1589
+ });
1590
+ }
1591
+ }
1592
+ async function S(z) {
1593
+ if (!(!t.closingDraftId.value || s.value || b)) {
1594
+ s.value = !0, b = !0, r.value = {
1595
+ requestId: "",
1596
+ closingDraftId: t.closingDraftId.value,
1597
+ closingDraftRevision: t.currentRev.value ?? "",
1598
+ message: "processing",
1599
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
1600
+ };
1601
+ try {
1602
+ await n.initializeStockSnapshot(t.closingDraftId.value, z);
1603
+ } catch (C) {
1604
+ b = !1, s.value = !1, o.open({
1605
+ title: i("inventory.common.refreshFailed"),
1606
+ message: i("inventory.stock.stock_balance.refreshBalanceError"),
1607
+ type: "error"
1608
+ }), console.error("error starting refresh", C);
1609
+ }
1610
+ }
1611
+ }
1612
+ function L() {
1613
+ u = !1, c && (c(), c = null);
1614
+ }
1615
+ function W() {
1616
+ L(), u = !0, s.value = !1, b = !1, r.value = null;
1617
+ }
1618
+ function T() {
1619
+ p = !1, W();
1620
+ }
1621
+ return Te(
1622
+ [t.closingDraftId, t.currentRev],
1623
+ ([z, C], [x, d]) => {
1624
+ p && (z === x && C === d || F());
1625
+ }
1626
+ ), Mn(() => {
1627
+ T();
1628
+ }), {
1629
+ refreshing: s,
1630
+ refreshStatus: r,
1631
+ startListening: E,
1632
+ startRefresh: S,
1633
+ cleanup: T
1634
+ };
1635
+ }
1636
+ function ra(t) {
1637
+ switch (t) {
1638
+ case "COMPLETED":
1639
+ return { label: "Completed", className: "fm-status-badge-complete" };
1640
+ case "IN_PROGRESS":
1641
+ return { label: "In Progress", className: "fm-status-badge-processing" };
1642
+ case "REJECTED":
1643
+ return { label: "Rejected", className: "fm-status-badge-error" };
1644
+ case "PENDING":
1645
+ return { label: "Pending", className: "fm-status-badge-draft" };
1646
+ }
1647
+ }
1648
+ const la = { class: "flex items-start justify-between gap-8" }, ia = { class: "flex items-center gap-8 min-w-0" }, ca = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary truncate" }, ua = { class: "fm-typo-en-body-md-400 text-fm-color-typo-primary" }, da = { class: "fm-typo-en-body-md-600" }, ma = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-tertiary" }, fa = /* @__PURE__ */ Se({
1649
+ __name: "ClosingGroupCard",
1650
+ props: {
1651
+ group: {}
1652
+ },
1653
+ emits: ["select"],
1654
+ setup(t, { emit: n }) {
1655
+ const e = t, o = n, i = I(() => ra(e.group.status)), s = I(
1656
+ () => `RM ${e.group.totalAmount.toLocaleString("en-MY", {
1657
+ minimumFractionDigits: 2,
1658
+ maximumFractionDigits: 2
1659
+ })}`
1660
+ ), r = I(() => {
1661
+ const u = e.group.updatedBy ?? "—", c = e.group.updatedAt ? Fe(e.group.updatedAt) : "—";
1662
+ return `Last updated by ${u} · ${c}`;
1663
+ });
1664
+ return (u, c) => (f(), $("div", {
1665
+ class: "flex flex-col gap-8 rounded-lg border border-fm-color-neutral-gray-200 bg-white p-16 cursor-pointer hover:border-fm-color-primary",
1666
+ onClick: c[0] || (c[0] = Un((b) => o("select", u.group.id), ["stop"]))
1667
+ }, [
1668
+ a("div", la, [
1669
+ a("div", ia, [
1670
+ u.group.color ? (f(), $("span", {
1671
+ key: 0,
1672
+ class: "w-8 h-8 rounded-full shrink-0",
1673
+ style: dt({ backgroundColor: u.group.color })
1674
+ }, null, 4)) : Y("", !0),
1675
+ a("span", ca, N(u.group.name), 1)
1676
+ ]),
1677
+ a("div", {
1678
+ class: he(["fm-status-badge shrink-0", i.value.className])
1679
+ }, N(i.value.label), 3)
1680
+ ]),
1681
+ a("div", ua, [
1682
+ a("span", da, N(u.group.itemCount), 1),
1683
+ me(" items · " + N(s.value), 1)
1684
+ ]),
1685
+ c[1] || (c[1] = a("div", { class: "border-t border-dashed border-fm-color-neutral-gray-200" }, null, -1)),
1686
+ a("div", ma, N(r.value), 1)
1687
+ ]));
1688
+ }
1689
+ }), pa = {
1690
+ key: 0,
1691
+ class: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-16"
1692
+ }, va = {
1693
+ key: 1,
1694
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
1695
+ }, ya = /* @__PURE__ */ Se({
1696
+ __name: "ClosingGroupGrid",
1697
+ props: {
1698
+ groups: {}
1699
+ },
1700
+ emits: ["select"],
1701
+ setup(t, { emit: n }) {
1702
+ const e = n;
1703
+ return (o, i) => o.groups.length ? (f(), $("div", pa, [
1704
+ (f(!0), $(le, null, ge(o.groups, (s) => (f(), oe(fa, {
1705
+ key: s.id,
1706
+ group: s,
1707
+ onSelect: i[0] || (i[0] = (r) => e("select", r))
1708
+ }, null, 8, ["group"]))), 128))
1709
+ ])) : (f(), $("div", va, "No closing groups"));
1710
+ }
1711
+ });
1712
+ function vn(t, n) {
1713
+ const e = t.sku, o = [], i = Number(ae.toFormatString({ value: t.baseAmount }));
1714
+ i && o.push({
1715
+ label: "Base",
1716
+ amount: i,
1717
+ abbrev: e.unit.abbrev,
1718
+ subtotal: i,
1719
+ inactive: !1,
1720
+ orphan: !1,
1721
+ counted: !0
1722
+ });
1723
+ const s = new Map(
1724
+ t.measurementsAmounts.map((c) => [c.measurement.id, c.amount])
1725
+ ), r = new Set(e.unit.measurements.map((c) => c.id)), u = (c, b, p, F, E) => {
1726
+ const U = Number(ae.toFormatString({ value: p }));
1727
+ if (!U) return;
1728
+ const P = ae.toFormatString({ value: b }), S = Number(
1729
+ ae.toFormatString({
1730
+ value: yt(p, b)
1731
+ })
1732
+ );
1733
+ o.push({
1734
+ label: E ? `${U} ${c}` : `${U} ${c} × ${P} ${e.unit.abbrev}`,
1735
+ amount: U,
1736
+ abbrev: c,
1737
+ subtotal: S,
1738
+ inactive: F,
1739
+ orphan: E,
1740
+ counted: !E
1741
+ });
1742
+ };
1743
+ for (const c of e.unit.measurements) {
1744
+ const b = s.get(c.id);
1745
+ b && u(c.abbrev, c.conversion, b, Tt(c, n), !1);
1746
+ }
1747
+ for (const c of t.measurementsAmounts)
1748
+ r.has(c.measurement.id) || u(c.measurement.abbrev, c.measurement.conversion, c.amount, !1, !0);
1749
+ return o;
1750
+ }
1751
+ const ct = (t) => ue(t, { minPrecision: 0, maxPrecision: 3 });
1752
+ function ga(t, n) {
1753
+ return n ? "text-fm-color-system-error-300" : t ? "text-purple-500" : "";
1754
+ }
1755
+ function ba(t, n) {
1756
+ return n ? k(ve.FmIcon, { name: "warning", size: "sm", color: "system-error-300" }) : t ? k(ve.FmIcon, { name: "rule", size: "sm" }) : null;
1757
+ }
1758
+ function yn(t, n, e) {
1759
+ return k(
1760
+ "div",
1761
+ {
1762
+ class: "p-12 flex flex-col gap-4 fm-typo-en-body-md-400 min-w-[280px] max-w-[420px]"
1763
+ },
1764
+ [
1765
+ k("div", { class: "fm-typo-en-body-sm-600 text-fm-color-typo-secondary mb-4" }, "Breakdown"),
1766
+ ...t.map(
1767
+ (o) => k("div", { class: "flex justify-between gap-12" }, [
1768
+ k(
1769
+ "div",
1770
+ { class: ["flex items-center gap-4", ga(o.inactive, o.orphan)] },
1771
+ [ba(o.inactive, o.orphan), k("span", o.label)]
1772
+ ),
1773
+ k(
1774
+ "div",
1775
+ { class: o.counted ? "" : "line-through text-fm-color-typo-tertiary" },
1776
+ o.orphan ? `${ct(o.amount)} ${o.abbrev} (no valid conversion)` : o.counted ? `${ct(o.subtotal)} ${e}` : `${ct(o.subtotal)} ${e} (ignored)`
1777
+ )
1778
+ ])
1779
+ ),
1780
+ k("hr", { class: "border-fm-color-typo-secondary my-4" }),
1781
+ k("div", { class: "flex justify-between fm-typo-en-body-lg-600" }, [
1782
+ k("span", "Total"),
1783
+ k("span", `${ct(n)} ${e}`)
1784
+ ])
1785
+ ]
1786
+ );
1787
+ }
1788
+ function Pt(t, n) {
1789
+ const e = t.sku, o = Number(ae.toFormatString({ value: t.baseAmount })), i = new Map(
1790
+ t.measurementsAmounts.map((c) => [c.measurement.id, c.amount])
1791
+ ), s = new Set(e.unit.measurements.map((c) => c.id)), r = [], u = (c, b, p, F, E) => {
1792
+ const U = Number(ae.toFormatString({ value: p })), P = ae.toFormatString({ value: b });
1793
+ r.push({
1794
+ abbrev: `(${c}) × ${P}`,
1795
+ amount: U,
1796
+ variant: E ? "orphan" : F ? "inactive" : "normal"
1797
+ });
1798
+ };
1799
+ for (const c of e.unit.measurements) {
1800
+ const b = i.get(c.id);
1801
+ b && u(c.abbrev, c.conversion, b, Tt(c, n), !1);
1802
+ }
1803
+ for (const c of t.measurementsAmounts)
1804
+ s.has(c.measurement.id) || u(c.measurement.abbrev, c.measurement.conversion, c.amount, !1, !0);
1805
+ return { baseUnitAmount: o, measurements: r };
1806
+ }
1807
+ function tn(t, n, e) {
1808
+ const o = t.sku, { baseUnitAmount: i, measurements: s } = Pt(t, e);
1809
+ return {
1810
+ id: o._id,
1811
+ code: o.code,
1812
+ name: o.name,
1813
+ baseUnit: o.unit.abbrev,
1814
+ baseUnitAmount: i,
1815
+ isTemplateItem: n,
1816
+ measurements: s,
1817
+ physicalBalance: Number(ae.toFormatString({ value: bt(t) })),
1818
+ breakdown: vn(t, e)
1819
+ };
1820
+ }
1821
+ function ha(t, n) {
1822
+ const e = [
1823
+ ...t.items.map((o) => tn(o, !0, n)),
1824
+ ...(t.negativeStockItems ?? []).map((o) => tn(o, !1, n))
1825
+ ];
1826
+ return e.sort((o, i) => o.code.localeCompare(i.code)), e;
1827
+ }
1828
+ function Rt(t, n, e) {
1829
+ const o = (r, u, c = "normal") => k(
1830
+ ve.FmTooltip,
1831
+ { zIndex: 50 },
1832
+ {
1833
+ default() {
1834
+ return k(
1835
+ "div",
1836
+ {
1837
+ class: [
1838
+ "fm-typo-en-body-lg-400 py-4 px-8 fm-corner-radius-md line-clamp-1 border-1",
1839
+ c === "orphan" ? "border-fm-color-system-error-300" : c === "inactive" ? "border-purple-500" : "border-fm-color-typo-secondary"
1840
+ ]
1841
+ },
1842
+ [
1843
+ k("span", { class: "text-fm-color-typo-primary" }, `${r} `),
1844
+ k(
1845
+ "span",
1846
+ { class: "text-fm-color-typo-secondary", style: { maxWidth: "80px" } },
1847
+ u
1848
+ )
1849
+ ]
1850
+ );
1851
+ },
1852
+ content() {
1853
+ return c === "orphan" ? `${r} ${u} (invalid UOM — not on SKU)` : c === "inactive" ? `${r} ${u} (NetSuite-inactive UOM)` : `${r} ${u}`;
1854
+ }
1855
+ }
1856
+ ), i = e.filter((r) => !!r.amount).map((r) => o(r.amount, r.abbrev, r.variant)), s = t || !i.length ? [o(t, n), ...i] : i;
1857
+ return k(
1858
+ "div",
1859
+ { class: "flex gap-8 flex-nowrap", style: { minWidth: `${120 * s.length}px` } },
1860
+ s
1861
+ );
1862
+ }
1863
+ function _a(t, n, e) {
1864
+ const o = [];
1865
+ for (const i of n) {
1866
+ const s = i.items.find((b) => b.sku._id === t);
1867
+ if (!s) continue;
1868
+ const { baseUnitAmount: r, measurements: u } = Pt(s, e);
1869
+ (r !== 0 || u.some((b) => b.amount !== 0)) && o.push({ label: i.label, isSub: i.isSub, baseUnitAmount: r, measurements: u });
1870
+ }
1871
+ return o;
1872
+ }
1873
+ function ka(t, n) {
1874
+ return k(
1875
+ "div",
1876
+ { class: "flex flex-col gap-8" },
1877
+ t.map(
1878
+ (e) => k("div", { class: "flex flex-col gap-4" }, [
1879
+ k(
1880
+ "div",
1881
+ { class: "fm-typo-en-body-sm-600 text-fm-color-typo-tertiary uppercase" },
1882
+ e.label
1883
+ ),
1884
+ Rt(e.baseUnitAmount, n, e.measurements)
1885
+ ])
1886
+ )
1887
+ );
1888
+ }
1889
+ const xa = "N/A";
1890
+ function gn(t, n) {
1891
+ var o, i;
1892
+ const e = t.approvedAt ? {
1893
+ action: `Approve at ${Fe(t.approvedAt)}`,
1894
+ actionBy: t.approvedBy,
1895
+ remark: t.approveRemark
1896
+ } : (o = t.rejectionHistory) == null ? void 0 : o.computeFirst((s) => ({
1897
+ action: `Reject at ${Fe(s.rejectedAt)}`,
1898
+ actionBy: s.rejectedBy,
1899
+ remark: s.rejectRemark
1900
+ }));
1901
+ return [
1902
+ n.idDisplay ? { label: "ID", value: n.idDisplay } : null,
1903
+ {
1904
+ label: "Location",
1905
+ value: n.locationName ?? xa
1906
+ },
1907
+ {
1908
+ label: "Created at",
1909
+ value: Fe(t.createdAt)
1910
+ },
1911
+ {
1912
+ label: "Created by",
1913
+ value: t.createdBy.name
1914
+ },
1915
+ {
1916
+ label: "Updated at",
1917
+ value: Fe(t.updatedAt)
1918
+ },
1919
+ {
1920
+ label: "Updated by",
1921
+ value: t.updatedBy.name
1922
+ },
1923
+ {
1924
+ label: "Effective at",
1925
+ value: Fe(t.effectiveAt ?? Pe(t._id))
1926
+ },
1927
+ {
1928
+ label: "Using template",
1929
+ value: ((i = t.usingTemplates.find((s) => s)) == null ? void 0 : i.name) ?? "None"
1930
+ },
1931
+ t.remark ? { label: "Remark", value: t.remark } : null,
1932
+ e ? { label: "Last action", value: e.action } : null,
1933
+ e && e.actionBy ? { label: "Last action by", value: e.actionBy.name } : null,
1934
+ e && e.remark ? { label: "Action remark", value: e.remark } : null
1935
+ ].filter((s) => !!s);
1936
+ }
1937
+ const wa = { class: "fm-typo-en-body-lg-400" }, Da = { class: "fm-typo-en-body-lg-600" }, $a = { class: "flex gap-12 py-8 justify-end w-full" }, Ca = /* @__PURE__ */ Se({
1938
+ __name: "ClosingGroupAction",
1939
+ props: {
1940
+ group: {},
1941
+ action: {},
1942
+ onCancel: { type: Function },
1943
+ onFinished: { type: Function }
1944
+ },
1945
+ setup(t) {
1946
+ const n = t, e = Re(), o = Ge(), i = q(), s = q(!1), r = I(() => n.action === "approve"), u = I(() => r.value ? "Approve" : "Reject"), c = I(() => r.value ? "primary" : "destructive");
1947
+ async function b() {
1948
+ s.value = !0;
1949
+ try {
1950
+ r.value ? await e.approveClosingGroup(n.group._id, i.value).delayed(500) : await e.rejectClosingGroup(n.group._id, i.value).delayed(500), o.open({ title: "Success", message: "Action submitted", type: "success" }), n.onFinished();
1951
+ } catch (p) {
1952
+ o.open({
1953
+ title: "Something went wrong",
1954
+ message: (p == null ? void 0 : p.message) ?? "Unable to submit action. Please try again",
1955
+ type: "error"
1956
+ }), console.error("error on submit closing group action", p);
1957
+ } finally {
1958
+ s.value = !1;
1959
+ }
1960
+ }
1961
+ return (p, F) => {
1962
+ const E = J("FmTextField"), U = J("FmButton"), P = J("FmForm");
1963
+ return f(), oe(P, {
1964
+ onValidationSuccess: b,
1965
+ class: "flex flex-col gap-32",
1966
+ disabled: s.value
1967
+ }, {
1968
+ default: te(() => [
1969
+ a("div", wa, [
1970
+ F[2] || (F[2] = me(" You are about to ")),
1971
+ a("span", Da, N(u.value), 1),
1972
+ F[3] || (F[3] = me(" this group. Please provide a remark to justify this action. "))
1973
+ ]),
1974
+ D(E, {
1975
+ modelValue: i.value,
1976
+ "onUpdate:modelValue": F[0] || (F[0] = (S) => i.value = S),
1977
+ label: "Remark",
1978
+ "label-mark": "required",
1979
+ rules: [m(ln)()]
1980
+ }, null, 8, ["modelValue", "rules"]),
1981
+ a("div", $a, [
1982
+ D(U, {
1983
+ label: "Cancel",
1984
+ variant: "tertiary",
1985
+ onClick: F[1] || (F[1] = (S) => p.onCancel())
1986
+ }),
1987
+ D(U, {
1988
+ label: u.value,
1989
+ type: "submit",
1990
+ variant: c.value,
1991
+ loading: s.value
1992
+ }, null, 8, ["label", "variant", "loading"])
1993
+ ])
1994
+ ]),
1995
+ _: 1
1996
+ }, 8, ["disabled"]);
1997
+ };
1998
+ }
1999
+ }), Aa = { class: "w-full flex flex-col gap-32" }, Sa = { class: "fm-typo-en-title-md-600" }, Fa = { class: "text-fm-color-typo-secondary" }, Ia = { class: "text-fm-color-primary" }, Ba = { class: "flex justify-between" }, Ta = { class: "flex" }, ja = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, Pa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ra = { class: "flex gap-1" }, Ma = {
2000
+ class: "fm-typo-en-body-lg-600",
2001
+ style: { "white-space": "pre-wrap", "word-break": "break-word" }
2002
+ }, Ua = { class: "fm-typo-en-body-lg-600" }, Na = { class: "flex gap-8" }, Va = { class: "overflow-x-auto" }, Ea = {
2003
+ key: 1,
2004
+ class: "flex-1 xs:w-screen xs:max-w-full"
2005
+ }, La = {
2006
+ key: 0,
2007
+ class: "flex flex-col items-center gap-8 h-full"
2008
+ }, za = ["src"], Oa = {
2009
+ key: 1,
2010
+ class: "px-4 flex flex-col"
2011
+ }, Ga = { class: "flex gap-12 content-stretch" }, Ha = {
2012
+ class: "flex flex-col w-24",
2013
+ name: "circles"
2014
+ }, Ya = { class: "flex-1 flex flex-col items-center" }, Ka = { class: "flex-1 flex flex-col items-center" }, Wa = {
2015
+ class: "py-12 flex flex-col gap-4",
2016
+ name: "received-at header"
2017
+ }, qa = { class: "fm-typo-en-body-lg-400" }, Qa = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Ja = { class: "flex gap-12 content-stretch" }, Za = {
2018
+ class: "flex flex-col w-24",
2019
+ name: "circles"
2020
+ }, Xa = { class: "flex-1 flex flex-col items-center" }, es = {
2021
+ class: "py-12 flex flex-col gap-4 flex-1",
2022
+ name: "delivery details"
2023
+ }, ts = { class: "flex flex-col gap-8" }, ns = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, os = { class: "flex flex-col gap-4" }, as = { class: "flex items-center gap-8 w-full" }, ss = /* @__PURE__ */ Se({
2024
+ __name: "ClosingGroupDetailSideSheet",
2025
+ props: {
2026
+ show: { type: Boolean },
2027
+ group: {},
2028
+ parentName: {}
2029
+ },
2030
+ emits: ["update:show", "updated"],
2031
+ setup(t, { emit: n }) {
2032
+ const e = t, o = n, i = It(e, "show"), s = jt(), r = He(), u = on(), c = I(() => {
2033
+ var d, h, B;
2034
+ return ((B = (h = (d = e.group) == null ? void 0 : d.usingTemplates) == null ? void 0 : h.find((M) => M)) == null ? void 0 : B.name) ?? "Group";
2035
+ }), b = I(() => {
2036
+ var d;
2037
+ return ((d = e.group) == null ? void 0 : d.status) === ke.enum.DRAFT;
2038
+ });
2039
+ function p(d) {
2040
+ e.group && u.open({
2041
+ title: d === "approve" ? "Approve group" : "Reject group",
2042
+ contentComponent: Ca,
2043
+ contentComponentProps: {
2044
+ group: e.group,
2045
+ action: d,
2046
+ onFinished: () => {
2047
+ u.close(), o("updated"), i.value = !1;
2048
+ },
2049
+ onCancel: () => u.close()
2050
+ }
2051
+ });
2052
+ }
2053
+ const F = I(() => {
2054
+ var d;
2055
+ return e.group ? gn(e.group, {
2056
+ locationName: (d = r._currentLocation) == null ? void 0 : d.name
2057
+ }) : [];
2058
+ }), E = [
2059
+ { label: "Overview", value: "overview" },
2060
+ { label: "Action history", value: "history" }
2061
+ ], U = q(E[0]), P = q(""), S = q({ templateItem: !0, nonTemplateItem: !0 }), L = q(null);
2062
+ function W(d, h) {
2063
+ L.value = h ? d : L.value === d ? null : L.value;
2064
+ }
2065
+ Te(
2066
+ () => e.show,
2067
+ (d) => {
2068
+ d && (U.value = E[0], P.value = "", S.value = { templateItem: !0, nonTemplateItem: !0 }, L.value = null);
2069
+ }
2070
+ );
2071
+ const T = I(
2072
+ () => e.group ? ha(e.group, s.value) : []
2073
+ ), z = I(
2074
+ () => T.value.filter((d) => !!(d.isTemplateItem && S.value.templateItem || !d.isTemplateItem && S.value.nonTemplateItem))
2075
+ ), C = I(() => [
2076
+ {
2077
+ id: "sku",
2078
+ accessorFn: (d) => `${d.code} ${d.name}`,
2079
+ header: () => "Name",
2080
+ size: 350,
2081
+ cell(d) {
2082
+ const h = d.row.original;
2083
+ return k("div", { class: "flex flex-col gap-4" }, [
2084
+ k(
2085
+ "div",
2086
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
2087
+ h.name
2088
+ ),
2089
+ k(
2090
+ "div",
2091
+ { class: "line-clamp-1 fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
2092
+ h.code
2093
+ )
2094
+ ]);
2095
+ }
2096
+ },
2097
+ {
2098
+ id: "uom",
2099
+ accessorFn: (d) => d.baseUnit,
2100
+ header: () => "UOM (base)",
2101
+ size: 120
2102
+ },
2103
+ {
2104
+ id: "physicalBalance",
2105
+ accessorKey: "physicalBalance",
2106
+ header: () => k(
2107
+ ve.FmTooltip,
2108
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
2109
+ {
2110
+ default: () => "Stock Take balance",
2111
+ content: () => "The physical balance recorded during stock take."
2112
+ }
2113
+ ),
2114
+ size: 180,
2115
+ cell(d) {
2116
+ const h = d.row.original, B = k(
2117
+ "div",
2118
+ { class: "text-right fm-typo-en-body-lg-400" },
2119
+ ue(h.physicalBalance)
2120
+ );
2121
+ return h.breakdown.length ? k(
2122
+ ve.FmPopover,
2123
+ {
2124
+ showPopover: L.value === h.id,
2125
+ placement: "bottom-end",
2126
+ zIndex: 9999,
2127
+ "onPopover-changed": (M) => W(h.id, M)
2128
+ },
2129
+ {
2130
+ "popover-button": () => k(
2131
+ "button",
2132
+ {
2133
+ type: "button",
2134
+ class: "flex items-center gap-4 ml-auto text-fm-color-typo-secondary hover:text-fm-color-typo-primary"
2135
+ },
2136
+ [B, k(ve.FmIcon, { name: "info", size: "sm", outline: !0 })]
2137
+ ),
2138
+ default: () => yn(h.breakdown, h.physicalBalance, h.baseUnit)
2139
+ }
2140
+ ) : B;
2141
+ },
2142
+ meta: { textAlign: "right" }
2143
+ },
2144
+ {
2145
+ id: "amounts",
2146
+ header: () => "Amounts",
2147
+ enableSorting: !1,
2148
+ cell(d) {
2149
+ const h = d.row.original;
2150
+ return Rt(h.baseUnitAmount, h.baseUnit, h.measurements);
2151
+ }
2152
+ }
2153
+ ]), x = I(() => {
2154
+ const d = e.group;
2155
+ if (!d) return [];
2156
+ const h = [...d.activityLogs ?? []], B = d.rejectionHistory ?? [];
2157
+ for (const M of B)
2158
+ h.find(
2159
+ (g) => `${g.action}_${g.performedAt}` == `${de.enum.rejectDraft}_${M.rejectedAt}`
2160
+ ) || h.push({
2161
+ action: de.enum.rejectDraft,
2162
+ performedAt: M.rejectedAt,
2163
+ performedBy: M.rejectedBy,
2164
+ remark: M.rejectRemark
2165
+ });
2166
+ return d.approvedAt && (h.find(
2167
+ (O) => `${O.action}_${O.performedAt}` == `${de.enum.approveDraft}_${d.approvedAt}`
2168
+ ) || h.push({
2169
+ action: de.enum.approveDraft,
2170
+ performedAt: d.approvedAt,
2171
+ performedBy: d.approvedBy ?? { name: "Unknown", id: "unknown" },
2172
+ remark: d.approveRemark
2173
+ })), h.sort((M, O) => new Date(O.performedAt).getTime() - new Date(M.performedAt).getTime()).map((M) => ({
2174
+ header: Ie(M.action),
2175
+ date: Fe(M.performedAt),
2176
+ info: [
2177
+ { label: "Performed by", values: [M.performedBy.name] },
2178
+ { label: "Remark", values: [M.remark ?? ""] }
2179
+ ]
2180
+ }));
2181
+ });
2182
+ return (d, h) => {
2183
+ const B = J("FmButtonGroup"), M = J("FmMenuDivider"), O = J("FmCard"), g = J("FmChip"), _ = J("FmTextField"), w = J("FmTable"), ne = J("FmSpacer"), Z = J("FmButton"), j = J("FmSideSheet");
2184
+ return f(), oe(j, {
2185
+ "dismiss-away": "",
2186
+ "max-width": 9999,
2187
+ "model-value": m(i),
2188
+ "onUpdate:modelValue": h[7] || (h[7] = (H) => vt(i) ? i.value = H : null),
2189
+ header: "Group details"
2190
+ }, {
2191
+ "side-sheet-footer": te(() => [
2192
+ a("div", as, [
2193
+ b.value ? (f(), oe(Z, {
2194
+ key: 0,
2195
+ label: "Approve",
2196
+ onClick: h[4] || (h[4] = (H) => p("approve"))
2197
+ })) : Y("", !0),
2198
+ b.value ? (f(), oe(Z, {
2199
+ key: 1,
2200
+ label: "Reject",
2201
+ variant: "destructive",
2202
+ onClick: h[5] || (h[5] = (H) => p("reject"))
2203
+ })) : Y("", !0),
2204
+ D(Z, {
2205
+ label: "Close",
2206
+ variant: "tertiary",
2207
+ onClick: h[6] || (h[6] = (H) => i.value = !1)
2208
+ })
2209
+ ])
2210
+ ]),
2211
+ default: te(() => [
2212
+ a("div", Aa, [
2213
+ a("div", Sa, [
2214
+ d.parentName ? (f(), $(le, { key: 0 }, [
2215
+ a("span", Fa, N(d.parentName), 1),
2216
+ h[8] || (h[8] = me(" · "))
2217
+ ], 64)) : Y("", !0),
2218
+ h[9] || (h[9] = me(" Group · ")),
2219
+ a("span", Ia, N(c.value), 1)
2220
+ ]),
2221
+ a("div", null, [
2222
+ D(B, {
2223
+ items: E,
2224
+ modelValue: U.value,
2225
+ "onUpdate:modelValue": h[0] || (h[0] = (H) => U.value = H)
2226
+ }, null, 8, ["modelValue"])
2227
+ ]),
2228
+ U.value.value === "overview" ? (f(), $(le, { key: 0 }, [
2229
+ D(O, {
2230
+ variant: "outlined",
2231
+ class: "flex flex-col gap-8 px-12 py-16"
2232
+ }, {
2233
+ default: te(() => {
2234
+ var H, A;
2235
+ return [
2236
+ a("div", Ba, [
2237
+ h[10] || (h[10] = a("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
2238
+ a("div", Ta, [
2239
+ a("div", {
2240
+ class: he(["fm-status-badge", m(Je)(((H = d.group) == null ? void 0 : H.status) ?? "DRAFT")])
2241
+ }, N(m(Ie)(((A = d.group) == null ? void 0 : A.status) ?? "")), 3)
2242
+ ])
2243
+ ]),
2244
+ D(M),
2245
+ a("div", ja, [
2246
+ (f(!0), $(le, null, ge(F.value, (V, ie) => (f(), $("div", {
2247
+ class: "flex flex-col gap-4",
2248
+ key: ie
2249
+ }, [
2250
+ a("div", Pa, [
2251
+ a("div", Ra, N(V.label), 1)
2252
+ ]),
2253
+ a("div", Ma, N(V.value), 1)
2254
+ ]))), 128))
2255
+ ])
2256
+ ];
2257
+ }),
2258
+ _: 1
2259
+ }),
2260
+ D(O, {
2261
+ variant: "outlined",
2262
+ class: "flex flex-col gap-16 px-12 py-16"
2263
+ }, {
2264
+ default: te(() => [
2265
+ a("div", Ua, N(c.value) + " items", 1),
2266
+ a("div", Na, [
2267
+ D(g, {
2268
+ label: "Template Item(s)",
2269
+ selected: S.value.templateItem,
2270
+ onClick: h[1] || (h[1] = (H) => S.value.templateItem = !S.value.templateItem)
2271
+ }, null, 8, ["selected"]),
2272
+ D(g, {
2273
+ label: "Non-template Item(s)",
2274
+ selected: S.value.nonTemplateItem,
2275
+ onClick: h[2] || (h[2] = (H) => S.value.nonTemplateItem = !S.value.nonTemplateItem)
2276
+ }, null, 8, ["selected"])
2277
+ ]),
2278
+ D(_, {
2279
+ modelValue: P.value,
2280
+ "onUpdate:modelValue": h[3] || (h[3] = (H) => P.value = H),
2281
+ placeholder: "Filter items"
2282
+ }, null, 8, ["modelValue"]),
2283
+ a("div", Va, [
2284
+ D(w, {
2285
+ "column-defs": C.value,
2286
+ "row-data": z.value,
2287
+ "search-value": P.value,
2288
+ "page-size": 10
2289
+ }, null, 8, ["column-defs", "row-data", "search-value"])
2290
+ ])
2291
+ ]),
2292
+ _: 1
2293
+ })
2294
+ ], 64)) : Y("", !0),
2295
+ U.value.value === "history" ? (f(), $("div", Ea, [
2296
+ x.value.length ? (f(), $("div", Oa, [
2297
+ (f(!0), $(le, null, ge(x.value, (H, A) => (f(), $(le, { key: A }, [
2298
+ a("div", Ga, [
2299
+ a("div", Ha, [
2300
+ a("div", Ya, [
2301
+ a("div", {
2302
+ class: he([
2303
+ { "bg-fm-color-primary": A !== 0, "bg-white": A === 0 },
2304
+ "w-[2px] h-full"
2305
+ ])
2306
+ }, null, 2)
2307
+ ]),
2308
+ h[13] || (h[13] = a("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
2309
+ a("div", Ka, [
2310
+ a("div", {
2311
+ class: he([
2312
+ {
2313
+ "bg-fm-color-primary": A < x.value.length - 1,
2314
+ "bg-white": A >= x.value.length - 1
2315
+ },
2316
+ "w-[2px] h-full"
2317
+ ])
2318
+ }, null, 2)
2319
+ ])
2320
+ ]),
2321
+ a("div", Wa, [
2322
+ a("div", qa, N(H.header), 1),
2323
+ a("div", Qa, N(H.date), 1)
2324
+ ])
2325
+ ]),
2326
+ a("div", Ja, [
2327
+ a("div", Za, [
2328
+ a("div", Xa, [
2329
+ a("div", {
2330
+ class: he([
2331
+ {
2332
+ "bg-fm-color-primary": A < x.value.length - 1,
2333
+ "bg-white": A >= x.value.length - 1
2334
+ },
2335
+ "w-[2px] h-full"
2336
+ ])
2337
+ }, null, 2)
2338
+ ])
2339
+ ]),
2340
+ a("div", es, [
2341
+ D(O, {
2342
+ variant: "outlined",
2343
+ class: "py-12 px-16"
2344
+ }, {
2345
+ default: te(() => [
2346
+ a("div", ts, [
2347
+ (f(!0), $(le, null, ge(H.info, (V, ie) => (f(), $("div", {
2348
+ key: ie,
2349
+ class: "flex flex-col gap-4"
2350
+ }, [
2351
+ a("div", ns, N(V.label), 1),
2352
+ a("div", os, [
2353
+ (f(!0), $(le, null, ge(V.values, (se, ye) => (f(), $("div", {
2354
+ key: ye,
2355
+ class: "fm-typo-en-body-lg-600"
2356
+ }, N(se), 1))), 128))
2357
+ ])
2358
+ ]))), 128))
2359
+ ])
2360
+ ]),
2361
+ _: 2
2362
+ }, 1024)
2363
+ ])
2364
+ ])
2365
+ ], 64))), 128))
2366
+ ])) : (f(), $("div", La, [
2367
+ D(ne),
2368
+ a("div", null, [
2369
+ a("img", {
2370
+ src: m(fn),
2371
+ alt: "List is empty"
2372
+ }, null, 8, za)
2373
+ ]),
2374
+ h[11] || (h[11] = a("div", { class: "fm-typo-en-body-lg-600" }, "No records found", -1)),
2375
+ h[12] || (h[12] = a("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, " You can track approval and rejection history here ", -1)),
2376
+ D(ne),
2377
+ D(ne)
2378
+ ]))
2379
+ ])) : Y("", !0)
2380
+ ])
2381
+ ]),
2382
+ _: 1
2383
+ }, 8, ["model-value"]);
2384
+ };
2385
+ }
2386
+ }), rs = { class: "w-full flex flex-col gap-32" }, ls = { class: "flex flex-col gap-4" }, is = { class: "flex justify-between" }, cs = { class: "flex" }, us = { class: "grid grid-cols-[repeat(4,1fr)] xs:flex xs:flex-col sm:flex sm:flex-col gap-8" }, ds = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, ms = { class: "flex gap-1" }, fs = {
2387
+ class: "fm-typo-en-body-lg-600",
2388
+ style: { "white-space": "pre-wrap", "word-break": "break-word" }
2389
+ }, ps = { class: "flex items-center justify-between" }, vs = { class: "fm-typo-en-body-lg-600" }, ys = {
2390
+ key: 1,
2391
+ class: "flex items-start gap-8 p-12 fm-corner-radius-md border-1 border-yellow-500 bg-yellow-50 text-yellow-700"
2392
+ }, gs = { class: "flex flex-col gap-2" }, bs = { class: "fm-typo-en-body-sm-400 list-disc pl-16" }, hs = { key: 0 }, _s = { key: 1 }, ks = { class: "flex flex-col gap-16" }, xs = { class: "flex items-center" }, ws = {
2393
+ key: 0,
2394
+ class: "flex gap-8"
2395
+ }, Ds = {
2396
+ key: 0,
2397
+ class: "w-full flex flex-col items-center"
2398
+ }, $s = { class: "flex items-center gap-8" }, Cs = { class: "flex flex-col gap-8" }, As = { class: "flex gap-8" }, Ss = {
2399
+ key: 0,
2400
+ class: "flex gap-8"
2401
+ }, Fs = {
2402
+ key: 1,
2403
+ class: "flex gap-8 flex-wrap"
2404
+ }, Is = { class: "overflow-x-auto" }, Bs = {
2405
+ key: 1,
2406
+ class: "flex-1 xs:w-screen xs:max-w-full"
2407
+ }, Ts = {
2408
+ key: 0,
2409
+ class: "flex flex-col items-center gap-8 h-full"
2410
+ }, js = ["src"], Ps = {
2411
+ key: 1,
2412
+ class: "px-4 flex flex-col"
2413
+ }, Rs = { class: "flex gap-12 content-stretch" }, Ms = {
2414
+ class: "flex flex-col w-24",
2415
+ name: "circles"
2416
+ }, Us = { class: "flex-1 flex flex-col items-center" }, Ns = { class: "flex-1 flex flex-col items-center" }, Vs = {
2417
+ class: "py-12 flex flex-col gap-4",
2418
+ name: "received-at header"
2419
+ }, Es = { class: "fm-typo-en-body-lg-400" }, Ls = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, zs = { class: "flex gap-12 content-stretch" }, Os = {
2420
+ class: "flex flex-col w-24",
2421
+ name: "circles"
2422
+ }, Gs = { class: "flex-1 flex flex-col items-center" }, Hs = {
2423
+ class: "py-12 flex flex-col gap-4 flex-1",
2424
+ name: "delivery details"
2425
+ }, Ys = { class: "flex flex-col gap-8" }, Ks = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Ws = { class: "flex flex-col gap-4" }, qs = { class: "flex items-center justify-between gap-8 w-full" }, Qs = { class: "flex items-center gap-8" }, Js = { class: "flex flex-col items-end" }, Zs = { class: "text-2xl font-semibold" }, Xs = "N/A", er = /* @__PURE__ */ Se({
2426
+ __name: "ClosingDraftDialog",
2427
+ props: {
2428
+ show: { type: Boolean },
2429
+ draft: {}
2430
+ },
2431
+ emits: ["submitted", "refresh"],
2432
+ setup(t, { emit: n }) {
2433
+ const e = t, o = I(() => {
2434
+ const y = an();
2435
+ return y === "MYR" ? "RM" : y;
2436
+ }), i = pn(), s = I(() => {
2437
+ var y, l;
2438
+ return (y = e.draft) != null && y.closingId ? ((l = i.drafts.find((v) => v._id === e.draft._id)) == null ? void 0 : l.closingIdDisplay) ?? null : null;
2439
+ }), r = pt(), u = Re(), c = It(e, "show"), b = q(!1), p = q(!1), F = q([]);
2440
+ let E = 0;
2441
+ async function U() {
2442
+ var v;
2443
+ const y = (v = e.draft) == null ? void 0 : v._id;
2444
+ if (F.value = [], !y) return;
2445
+ const l = ++E;
2446
+ try {
2447
+ const G = await u.getClosingGroups(y);
2448
+ if (l !== E) return;
2449
+ F.value = G;
2450
+ } catch (G) {
2451
+ if (l !== E) return;
2452
+ console.error("Failed to fetch closing groups", G);
2453
+ }
2454
+ }
2455
+ const P = I(() => F.value.map(St)), S = I(() => {
2456
+ var y, l, v;
2457
+ return (v = (l = (y = e.draft) == null ? void 0 : y.usingTemplates) == null ? void 0 : l.find((G) => G)) == null ? void 0 : v.name;
2458
+ }), L = q(null), W = q(!1);
2459
+ function T(y) {
2460
+ const l = F.value.find((v) => v._id === y);
2461
+ l && (L.value = l, W.value = !0);
2462
+ }
2463
+ const z = q(new Array()), C = q(new Array()), x = q([]), d = gt(), h = Ge(), B = Bt(), M = He(), O = Xt({}), g = I(() => new Set(
2464
+ B.skus.filter((y) => {
2465
+ var l;
2466
+ return O[(l = y.customAttributes) == null ? void 0 : l.tag];
2467
+ }).map((y) => y._id)
2468
+ )), _ = n, w = I(() => {
2469
+ var y;
2470
+ return (y = e.draft) == null ? void 0 : y._id;
2471
+ }), ne = I(() => {
2472
+ var y;
2473
+ return (y = e.draft) == null ? void 0 : y._rev;
2474
+ }), {
2475
+ refreshing: Z,
2476
+ startListening: j,
2477
+ startRefresh: H,
2478
+ cleanup: A
2479
+ } = sa({
2480
+ closingDraftId: w,
2481
+ currentRev: ne,
2482
+ onCompleted: (y) => {
2483
+ _("refresh", y), z.value = y.stockSnapshot ?? [], c.value = !1;
2484
+ }
2485
+ }), V = q({
2486
+ templateItem: !0,
2487
+ nonTemplateItem: !0
2488
+ }), ie = q(null);
2489
+ function se(y, l) {
2490
+ ie.value = l ? y : ie.value === y ? null : ie.value;
2491
+ }
2492
+ const ye = I(() => {
2493
+ var y, l;
2494
+ return [
2495
+ {
2496
+ label: "Main",
2497
+ isSub: !1,
2498
+ items: [...((y = e.draft) == null ? void 0 : y.items) ?? [], ...((l = e.draft) == null ? void 0 : l.negativeStockItems) ?? []]
2499
+ },
2500
+ ...F.value.map((v) => ({
2501
+ label: ht(v),
2502
+ isSub: !0,
2503
+ items: [...v.items ?? [], ...v.negativeStockItems ?? []]
2504
+ }))
2505
+ ];
2506
+ }), pe = I(() => {
2507
+ var G, X;
2508
+ const y = [
2509
+ ...((G = e.draft) == null ? void 0 : G.items) ?? [],
2510
+ ...((X = e.draft) == null ? void 0 : X.negativeStockItems) ?? []
2511
+ ], l = F.value.map((R) => [
2512
+ ...R.items ?? [],
2513
+ ...R.negativeStockItems ?? []
2514
+ ]), v = Po([y, ...l]);
2515
+ return g.value.size ? v.filter((R) => g.value.has(R.sku._id)) : v;
2516
+ }), De = I(() => {
2517
+ const y = pe.value.map((l) => l.sku);
2518
+ return y.sort((l, v) => l.code.localeCompare(v.code)), y;
2519
+ }), Me = jt();
2520
+ Ft(Ke), Te(
2521
+ () => e.show,
2522
+ async (y) => {
2523
+ if (!y) {
2524
+ A();
2525
+ return;
2526
+ }
2527
+ We.value = xt[0], Ke(), V.value = {
2528
+ templateItem: !0,
2529
+ nonTemplateItem: !0
2530
+ }, ie.value = null, j();
2531
+ },
2532
+ { immediate: !0 }
2533
+ ), Te(
2534
+ [() => e.show, w],
2535
+ ([y]) => {
2536
+ y && U();
2537
+ },
2538
+ { immediate: !0 }
2539
+ );
2540
+ const et = I(() => nt.value.reduce((y, l) => y + Number(l.stockTakeValue), 0)), Ye = Ze(0), Ue = Ze(100);
2541
+ async function Ke() {
2542
+ var l, v, G, X;
2543
+ if (!M._currentLocation) return;
2544
+ b.value = !0;
2545
+ const y = ((l = e.draft) == null ? void 0 : l.status) === ke.enum.COMPLETED;
2546
+ C.value = [];
2547
+ try {
2548
+ if (await B.init(), y) {
2549
+ const ee = e.draft.closingAdjustmentId;
2550
+ if (!ee) {
2551
+ h.open({
2552
+ title: "Something went wrong",
2553
+ message: "Closing draft is completed but closing document cannot be found.",
2554
+ type: "error"
2555
+ }), console.error("Closing draft is completed but closing document cannot be found.", {
2556
+ draftId: (v = e.draft) == null ? void 0 : v._id
2557
+ });
2558
+ return;
2559
+ }
2560
+ const _e = await d.readAdjustmentById(ee), Ce = (_e == null ? void 0 : _e.skus) ?? [];
2561
+ for (const Ae of Ce) {
2562
+ const Ve = {
2563
+ id: Ae.sku._id,
2564
+ balance: Ae.fromBalance,
2565
+ costs: Ae.fromCostBalances
2566
+ }, K = {
2567
+ id: Ae.sku._id,
2568
+ balance: Ae.toBalance,
2569
+ costs: Ae.toCostBalances
2570
+ };
2571
+ z.value.push(Ve), C.value.push(K);
2572
+ }
2573
+ } else
2574
+ z.value = ((G = e.draft) == null ? void 0 : G.stockSnapshot) ?? [];
2575
+ const R = /* @__PURE__ */ new Set();
2576
+ if ((X = e.draft) != null && X.adjustmentSnapshot)
2577
+ for (const ee of e.draft.adjustmentSnapshot)
2578
+ ee.adjustmentsByType && Object.keys(ee.adjustmentsByType).forEach((_e) => {
2579
+ R.add(_e);
2580
+ });
2581
+ const Q = ["receive", "sales", "wastage"], re = [];
2582
+ Q.forEach((ee) => {
2583
+ R.has(ee) && (re.push(ee), R.delete(ee));
2584
+ });
2585
+ const ce = Array.from(R).sort();
2586
+ x.value = [...re, ...ce];
2587
+ } catch (R) {
2588
+ h.open({
2589
+ title: "Something went wrong",
2590
+ message: "Something went wrong when fetching info. Please try again.",
2591
+ type: "error"
2592
+ }), console.error("error on fetch stock balances", R);
2593
+ } finally {
2594
+ b.value = !1;
2595
+ }
2596
+ }
2597
+ async function tt() {
2598
+ var l, v;
2599
+ if (Z.value)
2600
+ return;
2601
+ if (!(((l = e.draft) == null ? void 0 : l.effectiveAt) ?? (e.draft ? Pe((v = e.draft) == null ? void 0 : v._id) : null))) {
2602
+ h.open({
2603
+ title: "Cannot refresh",
2604
+ message: "Effective date is not available for this draft.",
2605
+ type: "error"
2606
+ });
2607
+ return;
2608
+ }
2609
+ await r.refreshBalance(
2610
+ e.draft,
2611
+ () => {
2612
+ },
2613
+ async (G) => {
2614
+ await H(G);
2615
+ }
2616
+ );
2617
+ }
2618
+ async function bn() {
2619
+ var l, v;
2620
+ if (!(((l = e.draft) == null ? void 0 : l.effectiveAt) ?? (e.draft ? Pe((v = e.draft) == null ? void 0 : v._id) : null))) {
2621
+ h.open({
2622
+ title: "Cannot refresh",
2623
+ message: "Effective date is not available for this draft.",
2624
+ type: "error"
2625
+ });
2626
+ return;
2627
+ }
2628
+ await r.invalidateDraftCache(e.draft);
2629
+ }
2630
+ const hn = I(
2631
+ () => z.value.groupBy(
2632
+ (y) => y.id,
2633
+ (y) => y.balance
2634
+ )
2635
+ ), _n = I(() => pe.value.groupBy((y) => y.sku._id)), kn = I(() => {
2636
+ var y;
2637
+ return (y = e.draft) != null && y.adjustmentSnapshot ? new Map(e.draft.adjustmentSnapshot.map((l) => [l.skuId, l.adjustmentsByType])) : /* @__PURE__ */ new Map();
2638
+ }), xn = I(() => {
2639
+ var y;
2640
+ return (y = e.draft) != null && y.opening ? new Map(e.draft.opening.map((l) => [l.skuId, l.balance])) : /* @__PURE__ */ new Map();
2641
+ });
2642
+ function $e(y, l) {
2643
+ return k(
2644
+ ve.FmTooltip,
2645
+ { zIndex: 51, placement: "left", class: "w-full flex justify-end" },
2646
+ {
2647
+ default() {
2648
+ return y;
2649
+ },
2650
+ content() {
2651
+ return l || y;
2652
+ }
2653
+ }
2654
+ );
2655
+ }
2656
+ const Mt = I(() => [
2657
+ {
2658
+ id: "sku",
2659
+ accessorFn: (l) => `${l.code} ${l.name}`,
2660
+ header: () => "Name",
2661
+ size: 350,
2662
+ cell(l) {
2663
+ const v = l.row.original, G = v.adjustedDiffPercentage, X = typeof G == "number" && Math.abs(G) > 10, R = k("div", { class: "flex flex-col gap-4" }, [
2664
+ k(
2665
+ "div",
2666
+ {
2667
+ class: [
2668
+ "line-clamp-1 fm-typo-en-body-lg-400",
2669
+ X ? " text-fm-color-system-error-300" : "text-fm-color-typo-primary"
2670
+ ]
2671
+ },
2672
+ v.name
2673
+ ),
2674
+ k(
2675
+ "div",
2676
+ {
2677
+ class: [
2678
+ "line-clamp-1 fm-typo-en-body-md-400",
2679
+ X ? " text-fm-color-system-error-300" : "text-fm-color-typo-secondary"
2680
+ ]
2681
+ },
2682
+ v.code
2683
+ ),
2684
+ // Flags items whose counts come from more than one sub — a heads-up
2685
+ // that the displayed total is summed across subs.
2686
+ v.subSources.length >= 2 ? k(
2687
+ "div",
2688
+ {
2689
+ class: "flex items-center gap-4 w-fit px-8 py-2 fm-corner-radius-md bg-orange-50 text-fm-color-primary fm-typo-en-body-md-600"
2690
+ },
2691
+ [
2692
+ k(ve.FmIcon, { name: "refresh", size: "sm" }),
2693
+ k("span", `Counted in ${v.subSources.length} subs: ${v.subSources.join(", ")}`)
2694
+ ]
2695
+ ) : null
2696
+ ]);
2697
+ return k(
2698
+ ve.FmTooltip,
2699
+ {
2700
+ zIndex: 51
2701
+ },
2702
+ {
2703
+ content() {
2704
+ return X ? "Adjustment difference is more than 10%." : `${v.code} - ${v.name}`;
2705
+ },
2706
+ default() {
2707
+ return k("div", { class: "flex items-center gap-4 justify-start w-full" }, [
2708
+ R
2709
+ ]);
2710
+ }
2711
+ }
2712
+ );
2713
+ }
2714
+ },
2715
+ // Dynamic custom attribute columns (toggled by user)
2716
+ ...Vt.value.map(
2717
+ (l) => ({
2718
+ id: `customAttr_${l}`,
2719
+ accessorFn: (v) => v.customAttributeValues[l],
2720
+ header: () => $e(Ie(l)),
2721
+ size: 160,
2722
+ cell(v) {
2723
+ const G = v.row.original.customAttributeValues[l];
2724
+ return G == null ? "N/A" : typeof G == "number" ? k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(G)) : k("div", { class: "text-right fm-typo-en-body-lg-400" }, String(G));
2725
+ },
2726
+ meta: {
2727
+ textAlign: "right"
2728
+ }
2729
+ })
2730
+ ),
2731
+ {
2732
+ id: "costPerUnit",
2733
+ accessorKey: "costPerUnit",
2734
+ header: () => $e("Cost per unit"),
2735
+ size: 160,
2736
+ cell(l) {
2737
+ const v = l.row.original.costPerUnit;
2738
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(v));
2739
+ },
2740
+ meta: {
2741
+ textAlign: "right"
2742
+ }
2743
+ },
2744
+ {
2745
+ id: "costUnit",
2746
+ header: () => "UOM",
2747
+ size: 120,
2748
+ cell(l) {
2749
+ var Q;
2750
+ const v = l.row.original, G = v.costUnit, X = v.baseUnit, R = G ?? X;
2751
+ if (G && G !== X) {
2752
+ const re = De.value.find((ee) => ee._id === v.id), ce = (Q = re == null ? void 0 : re.defaultCost) == null ? void 0 : Q.measurement;
2753
+ if (ce) {
2754
+ const ee = ce.conversion.amount / Math.pow(10, ce.conversion.precision);
2755
+ return k("div", { class: "flex flex-col" }, [
2756
+ k(
2757
+ "span",
2758
+ { class: "fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
2759
+ R
2760
+ ),
2761
+ k("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, [
2762
+ "1 ",
2763
+ k("span", { class: "fm-typo-en-body-sm-600" }, G),
2764
+ ` = ${ee} `,
2765
+ k("span", { class: "fm-typo-en-body-sm-600" }, X)
2766
+ ])
2767
+ ]);
2768
+ }
2769
+ }
2770
+ return R;
2771
+ }
2772
+ },
2773
+ {
2774
+ id: "opening",
2775
+ accessorKey: "opening",
2776
+ header: () => $e("Opening (B/F)", "The opening balance brought forward from previous period."),
2777
+ size: 150,
2778
+ cell(l) {
2779
+ const v = l.row.original.opening;
2780
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(v));
2781
+ },
2782
+ meta: {
2783
+ textAlign: "right"
2784
+ }
2785
+ },
2786
+ // Dynamic adjustment type columns
2787
+ ...x.value.map(
2788
+ (l) => ({
2789
+ id: `adjustment_${l}`,
2790
+ accessorFn: (v) => v.adjustmentAmounts[l] ?? { amount: 0, precision: 0 },
2791
+ header: () => $e(Ie(l)),
2792
+ size: 150,
2793
+ cell(v) {
2794
+ const G = v.row.original.adjustmentAmounts[l] ?? { amount: 0, precision: 0 };
2795
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(G));
2796
+ },
2797
+ meta: {
2798
+ textAlign: "right"
2799
+ }
2800
+ })
2801
+ ),
2802
+ {
2803
+ id: "systemBalance",
2804
+ accessorKey: "systemBalance",
2805
+ header: () => $e("System Balance", "The system calculated balance before stock take."),
2806
+ size: 200,
2807
+ cell(l) {
2808
+ const v = l.row.original.systemBalance;
2809
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(v));
2810
+ },
2811
+ meta: {
2812
+ textAlign: "right"
2813
+ }
2814
+ },
2815
+ {
2816
+ id: "physicalBalance",
2817
+ accessorFn: (l) => {
2818
+ var G;
2819
+ const v = (G = C.value.find((X) => X.id === l.id)) == null ? void 0 : G.balance;
2820
+ return v ? ao.toDouble(v) : l.physicalBalance;
2821
+ },
2822
+ header: () => $e("Stock Take balance", "The physical balance recorded during stock take."),
2823
+ cell(l) {
2824
+ var ce;
2825
+ const v = l.row.original, G = ae.fromNumber(v.physicalBalance);
2826
+ let X = !0;
2827
+ const R = (ce = C.value.find((ee) => ee.id === v.id)) == null ? void 0 : ce.balance;
2828
+ let Q;
2829
+ R && !ae.equals({ a: G, b: R }) ? (X = !1, Q = ue(R)) : Q = ue(v.physicalBalance);
2830
+ const re = k("div", { class: "flex flex-col items-end" }, [
2831
+ k(
2832
+ "span",
2833
+ { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-primary" },
2834
+ Q
2835
+ ),
2836
+ X ? null : k(
2837
+ "span",
2838
+ { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
2839
+ `Draft: ${ue(v.physicalBalance)}`
2840
+ )
2841
+ ]);
2842
+ return v.breakdown.length ? k(
2843
+ ve.FmPopover,
2844
+ {
2845
+ showPopover: ie.value === v.id,
2846
+ placement: "bottom-end",
2847
+ zIndex: 9999,
2848
+ "onPopover-changed": (ee) => se(v.id, ee)
2849
+ },
2850
+ {
2851
+ "popover-button": () => k(
2852
+ "button",
2853
+ {
2854
+ type: "button",
2855
+ class: "flex items-center gap-4 ml-auto text-fm-color-typo-secondary hover:text-fm-color-typo-primary"
2856
+ },
2857
+ [
2858
+ re,
2859
+ k(ve.FmIcon, { name: "info", size: "sm", outline: !0 })
2860
+ ]
2861
+ ),
2862
+ default: () => yn(v.breakdown, v.physicalBalance, v.baseUnit)
2863
+ }
2864
+ ) : re;
2865
+ },
2866
+ size: 200,
2867
+ meta: {
2868
+ textAlign: "right"
2869
+ }
2870
+ },
2871
+ {
2872
+ id: "adjustedAmount",
2873
+ accessorKey: "adjustedAmount",
2874
+ header: () => $e("Variance", "The difference between Stock Take balance and System Balance."),
2875
+ size: 200,
2876
+ cell(l) {
2877
+ const v = l.row.original.adjustedAmount;
2878
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(v));
2879
+ },
2880
+ meta: {
2881
+ textAlign: "right"
2882
+ }
2883
+ },
2884
+ {
2885
+ id: "varianceInCost",
2886
+ accessorKey: "varianceInCost",
2887
+ header: () => $e(`Variance (${o.value})`),
2888
+ size: 150,
2889
+ cell(l) {
2890
+ const v = l.row.original.varianceInCost;
2891
+ return k("div", { class: "text-right fm-typo-en-body-lg-400" }, ue(v));
2892
+ },
2893
+ meta: {
2894
+ textAlign: "right"
2895
+ }
2896
+ },
2897
+ {
2898
+ id: "adjustedDiffPercentage",
2899
+ accessorKey: "adjustedDiffPercentage",
2900
+ header: () => $e(
2901
+ "Variance (%)",
2902
+ "Difference between Stock Take balance and System Balance in percentage."
2903
+ ),
2904
+ size: 200,
2905
+ cell(l) {
2906
+ const v = l.row.original.adjustedDiffPercentage;
2907
+ if (v == null)
2908
+ return k(
2909
+ "div",
2910
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" },
2911
+ Xs
2912
+ );
2913
+ const G = ue(v);
2914
+ if (v === 0)
2915
+ return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
2916
+ ue(0)
2917
+ ]);
2918
+ const X = v > 0;
2919
+ return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-lg-400" }, [
2920
+ k(ve.FmIcon, {
2921
+ name: X ? "arrow_drop_up" : "arrow_drop_down",
2922
+ color: X ? "system-success-300" : "system-error-300",
2923
+ size: "md"
2924
+ }),
2925
+ G
2926
+ ]);
2927
+ },
2928
+ meta: {
2929
+ textAlign: "right"
2930
+ }
2931
+ },
2932
+ {
2933
+ id: "stockTakeValue",
2934
+ accessorKey: "stockTakeValue",
2935
+ header: () => $e(`Stock take value (${o.value})`),
2936
+ size: 180,
2937
+ cell(l) {
2938
+ var ce;
2939
+ const v = l.row.original, G = v.stockTakeValue, X = De.value.find((ee) => ee._id === v.id), R = (ce = X == null ? void 0 : X.defaultCost) == null ? void 0 : ce.measurement, Q = v.physicalBalance, re = v.costPerUnit;
2940
+ if (R) {
2941
+ const ee = ae.toFormatString({ value: R.conversion }), _e = `${ue(Q, { minPrecision: 2, maxPrecision: 4 })} ${v.baseUnit} ÷ ${ee} × ${re} ${o.value}`;
2942
+ return k(
2943
+ ve.FmTooltip,
2944
+ { zIndex: 51 },
2945
+ {
2946
+ content() {
2947
+ return _e;
2948
+ },
2949
+ default() {
2950
+ return k(
2951
+ "div",
2952
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
2953
+ ue(G)
2954
+ );
2955
+ }
2956
+ }
2957
+ );
2958
+ } else {
2959
+ const ee = `${ue(Q, { minPrecision: 2, maxPrecision: 4 })} ${v.baseUnit} × ${re} ${o.value}`;
2960
+ return k(
2961
+ ve.FmTooltip,
2962
+ { zIndex: 51 },
2963
+ {
2964
+ content() {
2965
+ return ee;
2966
+ },
2967
+ default() {
2968
+ return k(
2969
+ "div",
2970
+ { class: "text-right w-full fm-typo-en-body-lg-400" },
2971
+ ue(G)
2972
+ );
2973
+ }
2974
+ }
2975
+ );
2976
+ }
2977
+ },
2978
+ meta: {
2979
+ textAlign: "right"
2980
+ }
2981
+ },
2982
+ {
2983
+ id: "systemValue",
2984
+ accessorKey: "systemValue",
2985
+ header: () => $e(`System value (${o.value})`),
2986
+ size: 180,
2987
+ cell(l) {
2988
+ var ce;
2989
+ const v = l.row.original, G = v.systemValue, X = De.value.find((ee) => ee._id === v.id), R = (ce = X == null ? void 0 : X.defaultCost) == null ? void 0 : ce.measurement, Q = v.systemBalance, re = v.costPerUnit;
2990
+ if (R) {
2991
+ const ee = ae.toFormatString({ value: R.conversion }), _e = `${ue(Q, { minPrecision: 2, maxPrecision: 4 })} ${v.baseUnit} ÷ ${ee} × ${re} ${o.value}`;
2992
+ return k(
2993
+ ve.FmTooltip,
2994
+ { zIndex: 51 },
2995
+ {
2996
+ content() {
2997
+ return _e;
2998
+ },
2999
+ default() {
3000
+ return k(
3001
+ "div",
3002
+ { class: "text-right fm-typo-en-body-lg-400" },
3003
+ ue(G)
3004
+ );
3005
+ }
3006
+ }
3007
+ );
3008
+ } else {
3009
+ const ee = `${ue(Q, { minPrecision: 2, maxPrecision: 4 })} ${v.baseUnit} × ${re} ${o.value}`;
3010
+ return k(
3011
+ ve.FmTooltip,
3012
+ { zIndex: 51 },
3013
+ {
3014
+ content() {
3015
+ return ee;
3016
+ },
3017
+ default() {
3018
+ return k(
3019
+ "div",
3020
+ { class: "text-right fm-typo-en-body-lg-400" },
3021
+ ue(G)
3022
+ );
3023
+ }
3024
+ }
3025
+ );
3026
+ }
3027
+ },
3028
+ meta: {
3029
+ textAlign: "right"
3030
+ }
3031
+ },
3032
+ {
3033
+ id: "physicalBalances",
3034
+ header: () => "Amounts",
3035
+ enableSorting: !1,
3036
+ cell(l) {
3037
+ const v = l.row.original;
3038
+ return F.value.length && v.sourceBuckets.length ? ka(v.sourceBuckets, v.baseUnit) : Rt(v.baseUnitAmount, v.baseUnit, v.measurements);
3039
+ }
3040
+ }
3041
+ ]), wn = I(() => Mt.value.map((y) => y.size ?? 0).reduce((y, l) => y + l)), _t = q(""), Dn = I(() => {
3042
+ var G, X;
3043
+ const y = ((X = (G = e.draft) == null ? void 0 : G.negativeStockItems) == null ? void 0 : X.reduce(
3044
+ (R, Q) => (R[Q.sku._id] = Q, R),
3045
+ {}
3046
+ )) ?? {}, l = new Map(
3047
+ C.value.map((R) => [R.id, R.balance])
3048
+ );
3049
+ return De.value.map((R) => {
3050
+ var Gt, Ht, Yt, Kt, Wt, qt, Qt, Jt, Zt;
3051
+ const Q = (Gt = _n.value.get(R._id)) == null ? void 0 : Gt[0], re = ((Ht = hn.value.get(R._id)) == null ? void 0 : Ht[0]) ?? Ye, ce = ((Yt = R.defaultCost) == null ? void 0 : Yt.costPerUnit) ?? Ye, ee = Number(ae.toFormatString({ value: ce })), _e = ((Wt = (Kt = R.defaultCost) == null ? void 0 : Kt.measurement) == null ? void 0 : Wt.conversion) ?? {
3052
+ amount: 1,
3053
+ precision: 0
3054
+ }, Ce = Number(
3055
+ ae.toFormatString({ value: _e })
3056
+ ), Ae = xn.value.get(R._id), Ve = Ae ? Number(ae.toFormatString({ value: Ae })) : 0, K = kn.value.get(R._id), fe = {};
3057
+ if (x.value.forEach((xe) => {
3058
+ const lt = fe[xe] ?? { amount: 0, precision: 0 }, it = K == null ? void 0 : K[xe];
3059
+ it && (fe[xe] = ft(lt, it));
3060
+ }), !Q) {
3061
+ const xe = Number(ae.toFormatString({ value: re })), lt = 0 - xe, it = lt * ee / Ce, Pn = 0, Rn = xe * ee / Ce;
3062
+ return {
3063
+ id: R._id,
3064
+ code: R.code,
3065
+ name: R.name,
3066
+ costUnit: ((Qt = (qt = R.defaultCost) == null ? void 0 : qt.measurement) == null ? void 0 : Qt.abbrev) ?? null,
3067
+ baseUnit: R.unit.abbrev,
3068
+ baseUnitAmount: 0,
3069
+ systemBalance: xe,
3070
+ physicalBalance: 0,
3071
+ adjustedAmount: -xe,
3072
+ adjustedDiffPercentage: -100,
3073
+ isTemplateItem: !y[R._id],
3074
+ costPerUnit: ee,
3075
+ opening: Ve,
3076
+ varianceQty: lt,
3077
+ varianceInCost: it,
3078
+ stockTakeValue: Pn,
3079
+ systemValue: Rn,
3080
+ adjustmentAmounts: fe,
3081
+ customAttributeValues: R.customAttributes ?? {},
3082
+ measurements: [],
3083
+ breakdown: [],
3084
+ sourceBuckets: [],
3085
+ subSources: []
3086
+ };
3087
+ }
3088
+ const be = bt(Q), Be = l.get(R._id), Ee = un(
3089
+ Be ?? be,
3090
+ re
3091
+ ), rt = re.amount === 0 ? null : dn(Ee, {
3092
+ ...re,
3093
+ amount: Math.abs(re.amount)
3094
+ }), Lt = rt ? yt(rt, Ue) : null, wt = Number(ae.toFormatString({ value: re })), Dt = Number(ae.toFormatString({ value: be })), zt = Dt - wt, Sn = zt * ee / Ce, Fn = Dt * ee / Ce, In = wt * ee / Ce, { baseUnitAmount: Bn, measurements: Tn } = Pt(Q, Me.value), jn = vn(Q, Me.value), Ot = _a(R._id, ye.value, Me.value);
3095
+ return {
3096
+ id: R._id,
3097
+ code: R.code,
3098
+ name: R.name,
3099
+ costUnit: ((Zt = (Jt = R.defaultCost) == null ? void 0 : Jt.measurement) == null ? void 0 : Zt.abbrev) ?? null,
3100
+ baseUnit: R.unit.abbrev,
3101
+ baseUnitAmount: Bn,
3102
+ measurements: Tn,
3103
+ breakdown: jn,
3104
+ systemBalance: wt,
3105
+ physicalBalance: Dt,
3106
+ adjustedAmount: Number(ae.toFormatString({ value: Ee })),
3107
+ adjustedDiffPercentage: Lt ? Number(
3108
+ ae.toFormatString({
3109
+ value: mn(Lt, 2)
3110
+ })
3111
+ ) : null,
3112
+ isTemplateItem: !y[R._id],
3113
+ costPerUnit: ee,
3114
+ opening: Ve,
3115
+ varianceQty: zt,
3116
+ varianceInCost: Sn,
3117
+ stockTakeValue: Fn,
3118
+ systemValue: In,
3119
+ adjustmentAmounts: fe,
3120
+ customAttributeValues: R.customAttributes ?? {},
3121
+ sourceBuckets: Ot,
3122
+ subSources: Ot.filter((xe) => xe.isSub).map((xe) => xe.label)
3123
+ };
3124
+ });
3125
+ }), nt = I(() => Dn.value.filter((y) => !!(y.isTemplateItem && V.value.templateItem || !y.isTemplateItem && V.value.nonTemplateItem))), Ut = I(
3126
+ () => nt.value.some((y) => y.measurements.some((l) => l.variant === "inactive"))
3127
+ ), Nt = I(
3128
+ () => nt.value.some((y) => y.measurements.some((l) => l.variant === "orphan"))
3129
+ ), $n = I(
3130
+ () => Ut.value || Nt.value
3131
+ ), kt = I(() => {
3132
+ const y = /* @__PURE__ */ new Set();
3133
+ for (const l of De.value)
3134
+ if (l.customAttributes)
3135
+ for (const v of Object.keys(l.customAttributes))
3136
+ v !== "tag" && y.add(v);
3137
+ return Array.from(y).sort();
3138
+ }), ot = Xt({}), Vt = I(
3139
+ () => kt.value.filter((y) => ot[y])
3140
+ ), Cn = I(() => {
3141
+ var y;
3142
+ return e.draft ? gn(e.draft, {
3143
+ idDisplay: s.value,
3144
+ locationName: (y = M._currentLocation) == null ? void 0 : y.name
3145
+ }) : [];
3146
+ }), xt = [
3147
+ {
3148
+ label: "Overview",
3149
+ value: "overview"
3150
+ },
3151
+ {
3152
+ label: "Action history",
3153
+ value: "history"
3154
+ }
3155
+ ], We = q(xt[0]), Ne = I(() => {
3156
+ var G, X, R;
3157
+ const y = ((G = e.draft) == null ? void 0 : G.activityLogs) ?? [], l = ((X = e.draft) == null ? void 0 : X.rejectionHistory) ?? [];
3158
+ for (const Q of l)
3159
+ y.find(
3160
+ (ce) => `${ce.action}_${ce.performedAt}` == `${de.enum.rejectDraft}_${Q.rejectedAt}`
3161
+ ) || y.push({
3162
+ action: de.enum.rejectDraft,
3163
+ performedAt: Q.rejectedAt,
3164
+ performedBy: Q.rejectedBy,
3165
+ remark: Q.rejectRemark
3166
+ });
3167
+ return (R = e.draft) != null && R.approvedAt && (y.find(
3168
+ (re) => {
3169
+ var ce;
3170
+ return `${re.action}_${re.performedAt}` == `${de.enum.approveDraft}_${(ce = e.draft) == null ? void 0 : ce.approvedAt}`;
3171
+ }
3172
+ ) || y.push({
3173
+ action: de.enum.approveDraft,
3174
+ performedAt: e.draft.approvedAt,
3175
+ performedBy: e.draft.approvedBy ?? { name: "Unknown", id: "unknown" },
3176
+ remark: e.draft.approveRemark
3177
+ })), y.sort((Q, re) => new Date(re.performedAt).getTime() - new Date(Q.performedAt).getTime()).map(
3178
+ (Q) => ({
3179
+ header: Ie(Q.action),
3180
+ date: Fe(Q.performedAt),
3181
+ info: [
3182
+ {
3183
+ label: "Performed by",
3184
+ values: [Q.performedBy.name]
3185
+ },
3186
+ {
3187
+ label: "Remark",
3188
+ values: [Q.remark ?? ""]
3189
+ }
3190
+ ]
3191
+ })
3192
+ );
3193
+ }), at = q(!1), st = q(!1), Et = I(() => {
3194
+ var y;
3195
+ return ((y = e.draft) == null ? void 0 : y.status) !== ke.enum.DRAFT ? "Status is not draft." : null;
3196
+ });
3197
+ function An() {
3198
+ e.draft && (st.value = !0, r.approveDraft(
3199
+ e.draft,
3200
+ () => {
3201
+ st.value = !1, at.value = !1, _("submitted");
3202
+ },
3203
+ () => {
3204
+ st.value = !1;
3205
+ }
3206
+ ));
3207
+ }
3208
+ return (y, l) => {
3209
+ const v = J("FmButtonGroup"), G = J("FmMenuDivider"), X = J("FmCard"), R = J("FmIcon"), Q = J("FmButton"), re = J("FmCircularProgress"), ce = J("FmChip"), ee = J("FmTextField"), _e = J("FmTable"), Ce = J("FmSpacer"), Ae = J("FmTooltip"), Ve = J("FmSideSheet");
3210
+ return f(), $(le, null, [
3211
+ D(Ve, {
3212
+ "dismiss-away": "",
3213
+ "max-width": 9999,
3214
+ "model-value": m(c),
3215
+ "onUpdate:modelValue": l[9] || (l[9] = (K) => vt(c) ? c.value = K : null),
3216
+ header: "Closing details"
3217
+ }, {
3218
+ "side-sheet-footer": te(() => {
3219
+ var K, fe, be, Be;
3220
+ return [
3221
+ a("div", qs, [
3222
+ a("div", Qs, [
3223
+ ((K = e.draft) == null ? void 0 : K.status) === m(ke).enum.DRAFT ? (f(), $(le, { key: 0 }, [
3224
+ Et.value ? (f(), oe(Ae, {
3225
+ key: 0,
3226
+ "z-index": 51,
3227
+ placement: "right"
3228
+ }, {
3229
+ content: te(() => [
3230
+ me(N(Et.value), 1)
3231
+ ]),
3232
+ default: te(() => [
3233
+ D(Q, {
3234
+ disabled: "",
3235
+ key: "approve key",
3236
+ label: "Approve"
3237
+ })
3238
+ ]),
3239
+ _: 1
3240
+ })) : (f(), oe(Q, {
3241
+ key: "approve key",
3242
+ label: "Approve",
3243
+ onClick: l[5] || (l[5] = (Ee) => at.value = !0)
3244
+ }))
3245
+ ], 64)) : Y("", !0),
3246
+ ((fe = e.draft) == null ? void 0 : fe.status) === m(ke).enum.DRAFT ? (f(), oe(Q, {
3247
+ key: 1,
3248
+ label: "Reject",
3249
+ variant: "destructive",
3250
+ onClick: l[6] || (l[6] = () => e.draft && m(r).rejectDraft(e.draft, () => _("submitted")))
3251
+ })) : Y("", !0),
3252
+ D(Q, {
3253
+ label: "Close",
3254
+ variant: "tertiary",
3255
+ onClick: l[7] || (l[7] = (Ee) => c.value = !1)
3256
+ }),
3257
+ (be = e.draft) != null && be.approvedAt && ((Be = e.draft) == null ? void 0 : Be.status) !== m(ke).enum.COMPLETED ? (f(), oe($t, { key: 2 }, {
3258
+ default: te(() => [
3259
+ D(Q, {
3260
+ label: "Sync",
3261
+ loading: p.value,
3262
+ onClick: l[8] || (l[8] = () => {
3263
+ e.draft && (p.value = !0, m(r).syncDraft(e.draft, () => {
3264
+ p.value = !1, _("submitted");
3265
+ }));
3266
+ })
3267
+ }, null, 8, ["loading"])
3268
+ ]),
3269
+ _: 1
3270
+ })) : Y("", !0)
3271
+ ]),
3272
+ a("div", Js, [
3273
+ l[25] || (l[25] = a("div", { class: "text-xs text-gray-500 uppercase tracking-wide" }, "Total stock take value", -1)),
3274
+ a("div", Zs, N(o.value) + " " + N(et.value.toFixed(2)), 1)
3275
+ ])
3276
+ ])
3277
+ ];
3278
+ }),
3279
+ default: te(() => [
3280
+ a("div", rs, [
3281
+ a("div", null, [
3282
+ D(v, {
3283
+ items: xt,
3284
+ modelValue: We.value,
3285
+ "onUpdate:modelValue": l[0] || (l[0] = (K) => We.value = K)
3286
+ }, null, 8, ["modelValue"])
3287
+ ]),
3288
+ We.value.value === "overview" ? (f(), $(le, { key: 0 }, [
3289
+ D($t, { selectable: "" }, {
3290
+ default: te(() => {
3291
+ var K;
3292
+ return [
3293
+ a("div", ls, [
3294
+ l[12] || (l[12] = a("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, [
3295
+ a("div", { class: "flex gap-1" }, "Draft ID")
3296
+ ], -1)),
3297
+ me(" " + N((K = y.draft) == null ? void 0 : K._id), 1)
3298
+ ])
3299
+ ];
3300
+ }),
3301
+ _: 1
3302
+ }),
3303
+ D(X, {
3304
+ variant: "outlined",
3305
+ class: "flex flex-col gap-8 px-12 py-16"
3306
+ }, {
3307
+ default: te(() => {
3308
+ var K, fe;
3309
+ return [
3310
+ a("div", is, [
3311
+ l[13] || (l[13] = a("div", { class: "fm-typo-en-body-lg-600" }, "Closing summary", -1)),
3312
+ a("div", cs, [
3313
+ a("div", {
3314
+ class: he(["fm-status-badge", m(Je)(((K = y.draft) == null ? void 0 : K.status) ?? "DRAFT")])
3315
+ }, N(m(Ie)(((fe = y.draft) == null ? void 0 : fe.status) ?? "")), 3)
3316
+ ])
3317
+ ]),
3318
+ D(G),
3319
+ a("div", us, [
3320
+ (f(!0), $(le, null, ge(Cn.value, (be, Be) => (f(), $("div", {
3321
+ class: "flex flex-col gap-4",
3322
+ key: Be
3323
+ }, [
3324
+ a("div", ds, [
3325
+ a("div", ms, N(be.label), 1)
3326
+ ]),
3327
+ a("div", fs, N(be.value), 1)
3328
+ ]))), 128))
3329
+ ])
3330
+ ];
3331
+ }),
3332
+ _: 1
3333
+ }),
3334
+ P.value.length ? (f(), oe(X, {
3335
+ key: 0,
3336
+ variant: "outlined",
3337
+ class: "flex flex-col gap-8 px-12 py-16"
3338
+ }, {
3339
+ default: te(() => [
3340
+ a("div", ps, [
3341
+ a("div", vs, "Groups " + N(P.value.length), 1),
3342
+ l[14] || (l[14] = a("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, " Parent totals = sum of all groups ", -1))
3343
+ ]),
3344
+ D(G),
3345
+ D(ya, {
3346
+ groups: P.value,
3347
+ onSelect: T
3348
+ }, null, 8, ["groups"])
3349
+ ]),
3350
+ _: 1
3351
+ })) : Y("", !0),
3352
+ $n.value ? (f(), $("div", ys, [
3353
+ D(R, {
3354
+ name: "rule",
3355
+ size: "sm"
3356
+ }),
3357
+ a("div", gs, [
3358
+ l[16] || (l[16] = a("div", { class: "fm-typo-en-body-md-600" }, "UOM notes", -1)),
3359
+ a("ul", bs, [
3360
+ Ut.value ? (f(), $("li", hs, l[15] || (l[15] = [
3361
+ me(" Measurements highlighted in "),
3362
+ a("span", { class: "font-bold" }, "purple", -1),
3363
+ me(" are NetSuite-inactive UOMs (surfaced for audit; their amounts are part of the base total). ")
3364
+ ]))) : Y("", !0),
3365
+ Nt.value ? (f(), $("li", _s, " Red highlights are UOMs not on the SKU (ignored). ")) : Y("", !0)
3366
+ ])
3367
+ ])
3368
+ ])) : Y("", !0),
3369
+ a("div", ks, [
3370
+ a("div", xs, [
3371
+ l[17] || (l[17] = a("div", { class: "flex-1 fm-typo-en-title-sm-600 text-fm-color-typo-primary" }, " Closing items ", -1)),
3372
+ b.value ? Y("", !0) : (f(), $("div", ws, [
3373
+ y.draft && y.draft.status !== m(ke).enum.COMPLETED ? (f(), oe(Q, {
3374
+ key: 0,
3375
+ label: "Refresh balance",
3376
+ "prepend-icon": "refresh",
3377
+ variant: "secondary",
3378
+ "text-color": "primary",
3379
+ "bg-color": "transparent",
3380
+ "border-color": "primary",
3381
+ loading: m(Z),
3382
+ disabled: m(Z),
3383
+ onClick: tt
3384
+ }, null, 8, ["loading", "disabled"])) : Y("", !0),
3385
+ D($t, null, {
3386
+ default: te(() => [
3387
+ D(Q, {
3388
+ label: "Invalidate Draft Cache",
3389
+ "prepend-icon": "refresh",
3390
+ variant: "secondary",
3391
+ "text-color": "primary",
3392
+ "bg-color": "transparent",
3393
+ "border-color": "primary",
3394
+ loading: m(Z),
3395
+ onClick: bn
3396
+ }, null, 8, ["loading"])
3397
+ ]),
3398
+ _: 1
3399
+ }),
3400
+ D(Q, {
3401
+ label: "Export data",
3402
+ "prepend-icon": "download",
3403
+ variant: "secondary",
3404
+ "text-color": "primary",
3405
+ "bg-color": "transparent",
3406
+ "border-color": "primary",
3407
+ onClick: l[1] || (l[1] = (K) => y.draft ? m(r).exportDraft(
3408
+ y.draft,
3409
+ z.value,
3410
+ C.value,
3411
+ Vt.value
3412
+ ) : null)
3413
+ })
3414
+ ]))
3415
+ ]),
3416
+ b.value ? (f(), $("div", Ds, [
3417
+ l[19] || (l[19] = a("div", { class: "h-80" }, null, -1)),
3418
+ a("div", $s, [
3419
+ a("div", null, [
3420
+ D(re, { size: "md" })
3421
+ ]),
3422
+ l[18] || (l[18] = a("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Fetching info... ", -1))
3423
+ ]),
3424
+ l[20] || (l[20] = a("div", { class: "h-80" }, null, -1))
3425
+ ])) : (f(), $(le, { key: 1 }, [
3426
+ a("div", Cs, [
3427
+ a("div", As, [
3428
+ D(ce, {
3429
+ label: "Template Item(s)",
3430
+ selected: V.value.templateItem,
3431
+ onClick: l[2] || (l[2] = (K) => V.value.templateItem = !V.value.templateItem)
3432
+ }, null, 8, ["selected"]),
3433
+ D(ce, {
3434
+ label: "Non-template Item(s)",
3435
+ selected: V.value.nonTemplateItem,
3436
+ onClick: l[3] || (l[3] = (K) => V.value.nonTemplateItem = !V.value.nonTemplateItem)
3437
+ }, null, 8, ["selected"])
3438
+ ]),
3439
+ D(ee, {
3440
+ modelValue: _t.value,
3441
+ "onUpdate:modelValue": l[4] || (l[4] = (K) => _t.value = K),
3442
+ placeholder: "Filter items"
3443
+ }, null, 8, ["modelValue"])
3444
+ ]),
3445
+ m(B).skuTags.size ? (f(), $("div", Ss, [
3446
+ (f(!0), $(le, null, ge(m(B).skuTags.keys(), (K) => (f(), oe(ce, {
3447
+ key: `${K}`,
3448
+ label: `${K}`,
3449
+ selectable: "",
3450
+ selected: O[`${K}`],
3451
+ onClick: (fe) => O[`${K}`] = !O[`${K}`]
3452
+ }, {
3453
+ default: te(() => [
3454
+ O[`${K}`] ? (f(), oe(R, {
3455
+ key: 0,
3456
+ name: "check",
3457
+ class: "text-white",
3458
+ size: "sm"
3459
+ })) : Y("", !0),
3460
+ a("span", {
3461
+ class: he([
3462
+ "",
3463
+ {
3464
+ "text-white fm-typo-en-body-md-600": O[`${K}`],
3465
+ "text-fm-color-typo-primary fm-typo-en-body-md-400": !O[`${K}`]
3466
+ }
3467
+ ])
3468
+ }, N(K), 3)
3469
+ ]),
3470
+ _: 2
3471
+ }, 1032, ["label", "selected", "onClick"]))), 128))
3472
+ ])) : Y("", !0),
3473
+ kt.value.length ? (f(), $("div", Fs, [
3474
+ l[21] || (l[21] = a("span", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary self-center" }, "Extra columns:", -1)),
3475
+ (f(!0), $(le, null, ge(kt.value, (K) => (f(), oe(ce, {
3476
+ key: K,
3477
+ label: K,
3478
+ selectable: "",
3479
+ selected: ot[K],
3480
+ onClick: (fe) => ot[K] = !ot[K]
3481
+ }, null, 8, ["label", "selected", "onClick"]))), 128))
3482
+ ])) : Y("", !0),
3483
+ a("div", Is, [
3484
+ a("div", {
3485
+ style: dt({ height: "600px", minWidth: `${wn.value}px` })
3486
+ }, [
3487
+ D(_e, {
3488
+ "column-defs": Mt.value,
3489
+ "row-data": nt.value,
3490
+ "search-value": _t.value
3491
+ }, null, 8, ["column-defs", "row-data", "search-value"])
3492
+ ], 4)
3493
+ ])
3494
+ ], 64))
3495
+ ])
3496
+ ], 64)) : Y("", !0),
3497
+ We.value.value === "history" ? (f(), $("div", Bs, [
3498
+ Ne.value.length ? (f(), $("div", Ps, [
3499
+ (f(!0), $(le, null, ge(Ne.value, (K, fe) => (f(), $(le, { key: fe }, [
3500
+ a("div", Rs, [
3501
+ a("div", Ms, [
3502
+ a("div", Us, [
3503
+ a("div", {
3504
+ class: he([
3505
+ {
3506
+ "bg-fm-color-primary": fe !== 0,
3507
+ "bg-white": fe === 0
3508
+ },
3509
+ "w-[2px] h-full"
3510
+ ])
3511
+ }, null, 2)
3512
+ ]),
3513
+ l[24] || (l[24] = a("div", { class: "h-24 w-24 bg-fm-color-primary rounded-full" }, null, -1)),
3514
+ a("div", Ns, [
3515
+ a("div", {
3516
+ class: he([
3517
+ {
3518
+ "bg-fm-color-primary": fe < Ne.value.length - 1,
3519
+ "bg-white": fe >= Ne.value.length - 1
3520
+ },
3521
+ "w-[2px] h-full"
3522
+ ])
3523
+ }, null, 2)
3524
+ ])
3525
+ ]),
3526
+ a("div", Vs, [
3527
+ a("div", Es, N(K.header), 1),
3528
+ a("div", Ls, N(K.date), 1)
3529
+ ])
3530
+ ]),
3531
+ a("div", zs, [
3532
+ a("div", Os, [
3533
+ a("div", Gs, [
3534
+ a("div", {
3535
+ class: he([
3536
+ {
3537
+ "bg-fm-color-primary": fe < Ne.value.length - 1,
3538
+ "bg-white": fe >= Ne.value.length - 1
3539
+ },
3540
+ "w-[2px] h-full"
3541
+ ])
3542
+ }, null, 2)
3543
+ ])
3544
+ ]),
3545
+ a("div", Hs, [
3546
+ D(X, {
3547
+ variant: "outlined",
3548
+ class: "py-12 px-16"
3549
+ }, {
3550
+ default: te(() => [
3551
+ a("div", Ys, [
3552
+ (f(!0), $(le, null, ge(K.info, (be, Be) => (f(), $("div", {
3553
+ key: Be,
3554
+ class: "flex flex-col gap-4"
3555
+ }, [
3556
+ a("div", Ks, N(be == null ? void 0 : be.label), 1),
3557
+ a("div", Ws, [
3558
+ (f(!0), $(le, null, ge(be == null ? void 0 : be.values, (Ee, rt) => (f(), $("div", {
3559
+ key: rt,
3560
+ class: "fm-typo-en-body-lg-600"
3561
+ }, N(Ee), 1))), 128))
3562
+ ])
3563
+ ]))), 128))
3564
+ ])
3565
+ ]),
3566
+ _: 2
3567
+ }, 1024)
3568
+ ])
3569
+ ])
3570
+ ], 64))), 128))
3571
+ ])) : (f(), $("div", Ts, [
3572
+ D(Ce),
3573
+ a("div", null, [
3574
+ a("img", {
3575
+ src: m(fn),
3576
+ alt: "List is empty"
3577
+ }, null, 8, js)
3578
+ ]),
3579
+ l[22] || (l[22] = a("div", { class: "fm-typo-en-body-lg-600" }, N("No records found"), -1)),
3580
+ l[23] || (l[23] = a("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, N("You can track approval and rejection history here"), -1)),
3581
+ D(Ce),
3582
+ D(Ce)
3583
+ ]))
3584
+ ])) : Y("", !0)
3585
+ ])
3586
+ ]),
3587
+ _: 1
3588
+ }, 8, ["model-value"]),
3589
+ m(c) && e.draft ? (f(), oe(aa, {
3590
+ key: 0,
3591
+ show: at.value,
3592
+ "onUpdate:show": l[10] || (l[10] = (K) => at.value = K),
3593
+ refreshing: m(Z),
3594
+ approving: st.value,
3595
+ draft: e.draft,
3596
+ groups: F.value,
3597
+ onRefresh: tt,
3598
+ onApprove: An
3599
+ }, null, 8, ["show", "refreshing", "approving", "draft", "groups"])) : Y("", !0),
3600
+ D(ss, {
3601
+ show: W.value,
3602
+ "onUpdate:show": l[11] || (l[11] = (K) => W.value = K),
3603
+ group: L.value ?? void 0,
3604
+ "parent-name": S.value,
3605
+ onUpdated: U
3606
+ }, null, 8, ["show", "group", "parent-name"])
3607
+ ], 64);
3608
+ };
3609
+ }
3610
+ });
3611
+ var we = /* @__PURE__ */ ((t) => (t.ready = "ready", t.negative = "negative", t.systemNegative = "systemNegative", t))(we || {});
3612
+ async function tr(t) {
3613
+ return new Promise((n, e) => {
3614
+ const o = new FileReader();
3615
+ o.onload = (i) => {
3616
+ var s;
3617
+ try {
3618
+ const r = (s = i.target) == null ? void 0 : s.result, u = so(r, { type: "array" }), c = u.SheetNames[0], b = u.Sheets[c], p = ut.sheet_to_json(b, {
3619
+ header: 1,
3620
+ defval: ""
3621
+ }), F = (T) => String(T).trim().toLowerCase().replace(/^\uFEFF/, ""), E = p.findIndex(
3622
+ (T) => T.some((z) => F(z) === "code")
3623
+ );
3624
+ if (E === -1) {
3625
+ n([]);
3626
+ return;
3627
+ }
3628
+ const U = p[E], P = U.findIndex((T) => F(T) === "code"), S = U.findIndex((T) => F(T) === "balance");
3629
+ if (P === -1 || S === -1) {
3630
+ e(
3631
+ new Error(
3632
+ `Missing required columns: ${P === -1 ? '"Code" ' : ""}${S === -1 ? '"Balance"' : ""}.`.trim()
3633
+ )
3634
+ );
3635
+ return;
3636
+ }
3637
+ const W = p.slice(E + 1).filter((T) => String(T[P]).trim()).map((T) => ({
3638
+ itemCode: String(T[P]).trim(),
3639
+ quantity: Number(T[S]) || 0
3640
+ }));
3641
+ n(W);
3642
+ } catch (r) {
3643
+ e(r);
3644
+ }
3645
+ }, o.onerror = e, o.readAsArrayBuffer(t);
3646
+ });
3647
+ }
3648
+ function nr(t) {
3649
+ const n = /* @__PURE__ */ new Map();
3650
+ return t.forEach((e) => {
3651
+ const o = n.get(e.itemCode) || 0;
3652
+ n.set(e.itemCode, o + e.quantity);
3653
+ }), n;
3654
+ }
3655
+ function or(t, n) {
3656
+ const e = [], o = [];
3657
+ for (const [i, s] of n.entries()) {
3658
+ const r = t[i];
3659
+ if (!r) {
3660
+ o.push(i);
3661
+ continue;
3662
+ }
3663
+ const u = s < 0 ? "negative" : "ready";
3664
+ e.push({
3665
+ sku: r,
3666
+ physicalCount: s,
3667
+ // Note: filled by composable after readStockBalance()
3668
+ systemBalance: { amount: 0, precision: 0 },
3669
+ variance: s - 0,
3670
+ status: u
3671
+ });
3672
+ }
3673
+ return { mergedItems: e, unrecognisedItemCodes: o };
3674
+ }
3675
+ function ar(t, n) {
3676
+ const e = t.filter((c) => !c.isInactive), o = lo().format("YYYY-MM-DD"), i = `${n} - ${o}.csv`, s = [
3677
+ ["Code", "Name", "Balance"],
3678
+ ...e.map((c) => [c.code, c.name, ""])
3679
+ ], r = ut.aoa_to_sheet(s), u = ut.book_new();
3680
+ ut.book_append_sheet(u, r, "Template"), ro(u, i, { bookType: "csv" });
3681
+ }
3682
+ function sr() {
3683
+ const t = q([]), n = q([]), e = q(!1), o = Bt(), i = He(), s = gt(), r = I(
3684
+ () => t.value.some((p) => p.status === we.negative)
3685
+ );
3686
+ async function u(p) {
3687
+ t.value = [], n.value = [], e.value = !0;
3688
+ try {
3689
+ const F = await tr(p), E = nr(F), U = o.skuByCode, { mergedItems: P, unrecognisedItemCodes: S } = or(
3690
+ U,
3691
+ E
3692
+ ), L = await s.readStockBalance(), W = L.skus ?? [];
3693
+ W.length === 0 && console.warn(
3694
+ "No SKU balances found when importing closing draft. All system balances will be set to 0.",
3695
+ {
3696
+ stockBalance: L
3697
+ }
3698
+ );
3699
+ const T = new Map(
3700
+ W.map((C) => [C.id, C.balance])
3701
+ ), z = new Set(P.map((C) => C.sku._id));
3702
+ t.value = P.map((C) => {
3703
+ const x = T.get(C.sku._id) ?? { amount: 0, precision: 0 }, d = x.amount / Math.pow(10, x.precision);
3704
+ return { ...C, systemBalance: x, variance: C.physicalCount - d };
3705
+ });
3706
+ for (const C of Object.values(o.skuByCode)) {
3707
+ if (z.has(C._id)) continue;
3708
+ const x = T.get(C._id);
3709
+ if (!x) continue;
3710
+ const d = x.amount / Math.pow(10, x.precision);
3711
+ d >= 0 || t.value.push({
3712
+ sku: C,
3713
+ physicalCount: 0,
3714
+ systemBalance: x,
3715
+ variance: 0 - d,
3716
+ status: we.systemNegative
3717
+ });
3718
+ }
3719
+ n.value = S;
3720
+ } catch (F) {
3721
+ t.value = [], n.value = [], console.error("Error processing uploaded file", { error: F });
3722
+ } finally {
3723
+ e.value = !1;
3724
+ }
3725
+ }
3726
+ async function c() {
3727
+ const p = Re(), F = t.value.filter((W) => W.status === we.ready), E = t.value.filter(
3728
+ (W) => W.status === we.systemNegative
3729
+ ), U = (W) => ({
3730
+ sku: {
3731
+ _id: W.sku._id,
3732
+ code: W.sku.code,
3733
+ name: W.sku.name,
3734
+ unit: W.sku.unit
3735
+ },
3736
+ baseAmount: cn(W.physicalCount, W.sku.unit.precision),
3737
+ measurementsAmounts: []
3738
+ }), P = F.map(U), S = E.map(U), L = {
3739
+ effectiveAt: (/* @__PURE__ */ new Date()).toISOString(),
3740
+ items: P,
3741
+ negativeStockItems: S
3742
+ };
3743
+ return await p.createQuickModeDraftWithItems(L);
3744
+ }
3745
+ function b() {
3746
+ var F;
3747
+ const p = ((F = i.currentLocation) == null ? void 0 : F.name) ?? "template";
3748
+ ar(o.skus, p);
3749
+ }
3750
+ return { mergedItems: t, unrecognisedItemCodes: n, hasBlockingErrors: r, isLoading: e, onFileUpload: u, submit: c, downloadTemplate: b };
3751
+ }
3752
+ const rr = { class: "flex flex-col gap-16" }, lr = {
3753
+ key: 0,
3754
+ class: "px-16 py-12 rounded-8 bg-fm-color-danger-weak text-fm-color-danger-default"
3755
+ }, ir = { key: 1 }, cr = { class: "fm-typo-en-label-md-400 cursor-pointer" }, ur = { class: "mt-8 flex flex-col gap-4" }, dr = { key: 2 }, mr = { class: "fm-typo-en-label-md-400 cursor-pointer" }, fr = { class: "mt-8 flex flex-col gap-4" }, pr = /* @__PURE__ */ Se({
3756
+ __name: "ClosingDraftCreatePreviewTable",
3757
+ props: {
3758
+ items: {},
3759
+ unrecognisedItemCodes: {}
3760
+ },
3761
+ setup(t) {
3762
+ const n = t, { t: e } = Xe(), o = I(
3763
+ () => n.items.filter((u) => u.status === we.negative)
3764
+ ), i = I(
3765
+ () => n.items.filter((u) => u.status === we.systemNegative)
3766
+ ), s = I(() => ({
3767
+ [we.negative]: {
3768
+ bgColor: "bg-fm-color-danger-weak",
3769
+ textColor: "text-fm-color-danger-default",
3770
+ icon: "🚫",
3771
+ label: e("inventory.closing.draft.createDraft.previewTable.status.negative")
3772
+ },
3773
+ [we.systemNegative]: {
3774
+ bgColor: "bg-fm-color-warning-weak",
3775
+ textColor: "text-fm-color-warning-default",
3776
+ icon: "⚠️",
3777
+ label: e("inventory.closing.draft.createDraft.previewTable.status.systemNegative")
3778
+ }
3779
+ })), r = [
3780
+ {
3781
+ id: "name",
3782
+ header: () => e("inventory.ingredient.name"),
3783
+ cell: (u) => u.row.original.sku.name
3784
+ },
3785
+ {
3786
+ id: "uom",
3787
+ header: () => e("inventory.closing.draft.createDraft.previewTable.uom"),
3788
+ size: 80,
3789
+ cell: (u) => u.row.original.sku.unit.abbrev
3790
+ },
3791
+ {
3792
+ id: "systemBalance",
3793
+ header: () => e("inventory.closing.draft.createDraft.previewTable.systemBalance"),
3794
+ size: 180,
3795
+ cell: (u) => {
3796
+ const c = u.row.original;
3797
+ return k("div", ue(c.systemBalance));
3798
+ }
3799
+ },
3800
+ {
3801
+ id: "physicalCount",
3802
+ header: () => e("inventory.closing.draft.createDraft.previewTable.stockTakeBalance"),
3803
+ cell: (u) => {
3804
+ const c = u.row.original;
3805
+ return k("div", ue(c.physicalCount));
3806
+ }
3807
+ },
3808
+ {
3809
+ id: "variance",
3810
+ header: () => e("inventory.closing.draft.createDraft.previewTable.variance"),
3811
+ cell: (u) => {
3812
+ const b = u.row.original.variance, p = b < 0 ? "text-fm-color-danger-default" : b > 0 ? "text-fm-color-success-default" : "";
3813
+ return k("span", { class: p }, ue(b));
3814
+ }
3815
+ },
3816
+ {
3817
+ id: "variancePercentage",
3818
+ header: () => e("inventory.closing.draft.createDraft.previewTable.variancePercentage"),
3819
+ size: 130,
3820
+ cell: (u) => {
3821
+ const c = u.row.original, b = c.systemBalance.amount / Math.pow(10, c.systemBalance.precision), p = b === 0 ? null : Math.max(
3822
+ -100,
3823
+ Math.min(100, Math.round(c.variance / Math.abs(b) * 1e4) / 100)
3824
+ );
3825
+ if (p === null)
3826
+ return k(
3827
+ "div",
3828
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
3829
+ e("inventory.closing.draft.createDraft.previewTable.notApplicable")
3830
+ );
3831
+ const F = `${ue(p)}`;
3832
+ if (p === 0)
3833
+ return k(
3834
+ "div",
3835
+ { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" },
3836
+ F
3837
+ );
3838
+ const E = p > 0;
3839
+ return k("div", { class: "flex items-center gap-4 justify-end fm-typo-en-body-md-400" }, [
3840
+ k(ve.FmIcon, {
3841
+ name: E ? "arrow_drop_up" : "arrow_drop_down",
3842
+ color: E ? "system-success-300" : "system-error-300",
3843
+ size: "md"
3844
+ }),
3845
+ F
3846
+ ]);
3847
+ }
3848
+ },
3849
+ {
3850
+ id: "status",
3851
+ header: () => e("inventory.common.status"),
3852
+ cell: (u) => {
3853
+ const c = u.row.original.status, b = s.value[c];
3854
+ return b ? k(
3855
+ "span",
3856
+ {
3857
+ class: `px-8 py-2 rounded-4 ${b.bgColor} ${b.textColor} fm-typo-en-label-sm-400`
3858
+ },
3859
+ `${b.icon} ${b.label}`
3860
+ ) : null;
3861
+ }
3862
+ }
3863
+ ];
3864
+ return (u, c) => {
3865
+ const b = J("FmTable");
3866
+ return f(), $("div", rr, [
3867
+ o.value.length > 0 ? (f(), $("div", lr, [
3868
+ me(N(m(e)("inventory.closing.draft.createDraft.previewTable.cannotSubmitNegative")) + " ", 1),
3869
+ a("strong", null, N(o.value.map((p) => p.sku.code).join(", ")), 1)
3870
+ ])) : Y("", !0),
3871
+ i.value.length > 0 ? (f(), $("details", ir, [
3872
+ a("summary", cr, N(m(e)("inventory.closing.draft.createDraft.previewTable.systemNegativeNote", [i.value.length])), 1),
3873
+ a("ul", ur, [
3874
+ (f(!0), $(le, null, ge(i.value, (p) => (f(), $("li", {
3875
+ key: p.sku._id,
3876
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
3877
+ }, N(p.sku.code), 1))), 128))
3878
+ ])
3879
+ ])) : Y("", !0),
3880
+ u.unrecognisedItemCodes.length > 0 ? (f(), $("details", dr, [
3881
+ a("summary", mr, N(m(e)("inventory.closing.draft.createDraft.previewTable.unrecognisedNote", [u.unrecognisedItemCodes.length])), 1),
3882
+ a("ul", fr, [
3883
+ (f(!0), $(le, null, ge(u.unrecognisedItemCodes, (p) => (f(), $("li", {
3884
+ key: p,
3885
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
3886
+ }, N(p), 1))), 128))
3887
+ ])
3888
+ ])) : Y("", !0),
3889
+ D(b, {
3890
+ "row-data": n.items,
3891
+ "column-defs": r,
3892
+ pagination: { pageSize: 20 }
3893
+ }, null, 8, ["row-data"])
3894
+ ]);
3895
+ };
3896
+ }
3897
+ }), vr = { class: "flex flex-col gap-16" }, yr = { class: "flex flex-col gap-8" }, gr = { class: "fm-typo-en-body-lg-600" }, br = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, hr = { class: "fm-corner-radius-md p-16 flex items-center gap-16 border border-fm-color-border-default" }, _r = { class: "flex flex-col flex-1 gap-4" }, kr = { class: "fm-typo-en-body-md-600" }, xr = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, wr = {
3898
+ key: 0,
3899
+ class: "flex flex-col gap-8"
3900
+ }, Dr = { class: "fm-typo-en-body-lg-600" }, $r = {
3901
+ key: 0,
3902
+ class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 flex items-center gap-8"
3903
+ }, Cr = { class: "grid grid-cols-[repeat(3,1fr)] gap-12" }, Ar = { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary flex items-center gap-4" }, Sr = { class: "flex items-center gap-8 w-full" }, Fr = /* @__PURE__ */ Se({
3904
+ __name: "ClosingDraftCreateSideSheet",
3905
+ props: {
3906
+ show: { type: Boolean }
3907
+ },
3908
+ emits: ["update:show", "submitted"],
3909
+ setup(t, { emit: n }) {
3910
+ const e = t, o = n, i = It(e, "show"), { t: s } = Xe(), r = Ge(), u = q("upload"), c = q(null), b = q(!1), { mergedItems: p, unrecognisedItemCodes: F, hasBlockingErrors: E, isLoading: U, onFileUpload: P, submit: S, downloadTemplate: L } = sr(), W = I(
3911
+ () => c.value && !U.value && p.value.length > 0
3912
+ ), T = I(() => {
3913
+ const d = p.value.filter(
3914
+ (O) => O.status === we.ready
3915
+ ).length, h = p.value.filter(
3916
+ (O) => O.status === we.negative
3917
+ ).length, B = p.value.filter(
3918
+ (O) => O.status === we.systemNegative
3919
+ ).length, M = p.value.filter((O) => O.variance !== 0).length;
3920
+ return [
3921
+ { label: s("inventory.closing.draft.createDraft.summary.totalItems"), value: p.value.length },
3922
+ { label: s("inventory.closing.draft.createDraft.summary.itemsWithCount"), value: d },
3923
+ {
3924
+ label: s("inventory.closing.draft.createDraft.summary.unrecognisedItems"),
3925
+ value: F.value.length,
3926
+ isWarning: F.value.length > 0
3927
+ },
3928
+ { label: s("inventory.closing.draft.createDraft.summary.itemsWithVariance"), value: M },
3929
+ { label: s("inventory.closing.draft.createDraft.summary.negativeCounts"), value: h, isError: h > 0 },
3930
+ {
3931
+ label: s("inventory.closing.draft.createDraft.summary.systemNegative"),
3932
+ value: B,
3933
+ isWarning: B > 0
3934
+ }
3935
+ ];
3936
+ });
3937
+ async function z(d) {
3938
+ c.value = d, await P(d);
3939
+ }
3940
+ async function C() {
3941
+ b.value = !0;
3942
+ try {
3943
+ await S(), x(), o("submitted"), r.open({
3944
+ title: "Success",
3945
+ message: "Closing draft created successfully",
3946
+ type: "success"
3947
+ });
3948
+ } catch (d) {
3949
+ console.error("Failed to create closing draft", { error: d }), r.open({
3950
+ title: "Something went wrong",
3951
+ message: "Failed to create closing draft. Please try again",
3952
+ type: "error"
3953
+ });
3954
+ } finally {
3955
+ b.value = !1;
3956
+ }
3957
+ }
3958
+ Te(i, (d) => {
3959
+ d || (u.value = "upload", c.value = null);
3960
+ });
3961
+ function x() {
3962
+ i.value = !1;
3963
+ }
3964
+ return (d, h) => {
3965
+ const B = J("FmCircularProgress"), M = J("FmIcon"), O = J("FmButton"), g = J("FmCard"), _ = J("FmSideSheet");
3966
+ return f(), oe(_, {
3967
+ "dismiss-away": "",
3968
+ "max-width": 9999,
3969
+ "model-value": m(i),
3970
+ "onUpdate:modelValue": h[2] || (h[2] = (w) => vt(i) ? i.value = w : null),
3971
+ header: m(s)("inventory.closing.draft.createDraft.title")
3972
+ }, {
3973
+ default: te(() => [
3974
+ a("div", vr, [
3975
+ u.value === "upload" ? (f(), $(le, { key: 0 }, [
3976
+ a("div", yr, [
3977
+ a("div", gr, N(m(s)("inventory.closing.draft.createDraft.importCsv")), 1),
3978
+ a("div", br, N(m(s)("inventory.closing.draft.createDraft.uploadDescription")), 1),
3979
+ D(io, {
3980
+ class: he({ "h-[200px]": !c.value }),
3981
+ accept: ".csv",
3982
+ disabled: m(U),
3983
+ onFileUpload: z
3984
+ }, Nn({ _: 2 }, [
3985
+ c.value ? {
3986
+ name: "default",
3987
+ fn: te(({ openFileDialog: w }) => [
3988
+ a("div", hr, [
3989
+ m(U) ? (f(), oe(B, {
3990
+ key: 0,
3991
+ size: "md",
3992
+ color: "neutral-gray-200"
3993
+ })) : (f(), oe(M, {
3994
+ key: 1,
3995
+ name: "check_circle",
3996
+ color: "system-success-400",
3997
+ size: "lg"
3998
+ })),
3999
+ a("div", _r, [
4000
+ a("div", kr, N(c.value.name), 1),
4001
+ a("div", xr, N(m(U) ? m(s)("inventory.closing.draft.createDraft.processing") : m(s)("inventory.closing.draft.createDraft.itemsLoaded", [m(p).length])), 1)
4002
+ ]),
4003
+ m(U) ? Y("", !0) : (f(), oe(O, {
4004
+ key: 2,
4005
+ label: m(s)("inventory.closing.draft.createDraft.replaceFile"),
4006
+ variant: "secondary",
4007
+ "prepend-icon": "autorenew",
4008
+ onClick: w
4009
+ }, null, 8, ["label", "onClick"]))
4010
+ ])
4011
+ ]),
4012
+ key: "0"
4013
+ } : void 0
4014
+ ]), 1032, ["class", "disabled"])
4015
+ ]),
4016
+ W.value ? (f(), $("div", wr, [
4017
+ a("div", Dr, N(m(s)("inventory.closing.draft.createDraft.importSummary")), 1),
4018
+ m(E) ? (f(), $("div", $r, [
4019
+ D(M, {
4020
+ name: "error",
4021
+ size: "sm",
4022
+ color: "system-error-300"
4023
+ }),
4024
+ a("span", null, N(m(s)("inventory.closing.draft.createDraft.reviewIssues")), 1)
4025
+ ])) : Y("", !0),
4026
+ D(g, {
4027
+ variant: "outlined",
4028
+ class: "flex flex-col gap-12 px-16 py-12"
4029
+ }, {
4030
+ default: te(() => [
4031
+ a("div", Cr, [
4032
+ (f(!0), $(le, null, ge(T.value, (w) => (f(), $("div", {
4033
+ key: w.label,
4034
+ class: "flex flex-col gap-4"
4035
+ }, [
4036
+ a("div", Ar, [
4037
+ w.isError ? (f(), oe(M, {
4038
+ key: 0,
4039
+ name: "error",
4040
+ size: "sm",
4041
+ color: "system-error-300"
4042
+ })) : Y("", !0),
4043
+ w.isWarning && !w.isError ? (f(), oe(M, {
4044
+ key: 1,
4045
+ name: "warning",
4046
+ size: "sm",
4047
+ color: "system-warning-300"
4048
+ })) : Y("", !0),
4049
+ a("span", null, N(w.label), 1)
4050
+ ]),
4051
+ a("div", {
4052
+ class: he([
4053
+ "fm-typo-en-body-lg-600",
4054
+ {
4055
+ "text-fm-color-system-error-300": w.isError,
4056
+ "text-fm-color-system-warning-300": w.isWarning && !w.isError
4057
+ }
4058
+ ])
4059
+ }, N(w.value), 3)
4060
+ ]))), 128))
4061
+ ])
4062
+ ]),
4063
+ _: 1
4064
+ })
4065
+ ])) : Y("", !0)
4066
+ ], 64)) : Y("", !0),
4067
+ u.value === "preview" ? (f(), oe(pr, {
4068
+ key: 1,
4069
+ items: m(p),
4070
+ "unrecognised-item-codes": m(F)
4071
+ }, null, 8, ["items", "unrecognised-item-codes"])) : Y("", !0)
4072
+ ])
4073
+ ]),
4074
+ "side-sheet-footer": te(() => [
4075
+ a("div", Sr, [
4076
+ u.value === "preview" ? (f(), oe(O, {
4077
+ key: 0,
4078
+ variant: "secondary",
4079
+ label: m(s)("inventory.common.back"),
4080
+ "prepend-icon": "arrow_back",
4081
+ onClick: h[0] || (h[0] = (w) => u.value = "upload")
4082
+ }, null, 8, ["label"])) : Y("", !0),
4083
+ u.value === "upload" ? (f(), oe(O, {
4084
+ key: 1,
4085
+ variant: "primary",
4086
+ label: m(s)("inventory.common.next"),
4087
+ disabled: !c.value || m(U),
4088
+ onClick: h[1] || (h[1] = (w) => u.value = "preview")
4089
+ }, null, 8, ["label", "disabled"])) : Y("", !0),
4090
+ u.value === "preview" ? (f(), oe(co, {
4091
+ key: 2,
4092
+ label: m(s)("inventory.closing.draft.createDraft.submit"),
4093
+ disabled: m(E) || m(p).length === 0 || b.value,
4094
+ loading: b.value,
4095
+ "confirm-title": m(s)("inventory.closing.draft.createDraft.confirmTitle"),
4096
+ "confirm-message": m(s)("inventory.closing.draft.createDraft.confirmMessage"),
4097
+ onConfirm: C
4098
+ }, null, 8, ["label", "disabled", "loading", "confirm-title", "confirm-message"])) : Y("", !0),
4099
+ D(O, {
4100
+ variant: "tertiary",
4101
+ label: m(s)("inventory.common.close"),
4102
+ onClick: x
4103
+ }, null, 8, ["label"]),
4104
+ u.value === "upload" ? (f(), oe(O, {
4105
+ key: 3,
4106
+ class: "ml-auto",
4107
+ variant: "secondary",
4108
+ label: m(s)("inventory.closing.draft.createDraft.downloadTemplate"),
4109
+ "prepend-icon": "download",
4110
+ onClick: m(L)
4111
+ }, null, 8, ["label", "onClick"])) : Y("", !0)
4112
+ ])
4113
+ ]),
4114
+ _: 1
4115
+ }, 8, ["model-value", "header"]);
4116
+ };
4117
+ }
4118
+ }), Ir = ["onClick"], Br = { class: "flex items-start gap-8" }, Tr = { class: "fm-typo-body-md-400 line-clamp-3 w-full" }, jr = { class: "flex flex-col gap-8" }, Pr = { class: "flex items-start gap-4" }, Rr = { class: "flex-1 flex flex-col gap-8" }, Mr = { class: "flex flex-col" }, Ur = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Nr = { class: "fm-typo-en-body-lg-600 text-fm-color-typo-primary" }, Vr = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-2" }, Er = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Lr = {
4119
+ key: 0,
4120
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary"
4121
+ }, gl = /* @__PURE__ */ Se({
4122
+ __name: "ClosingDraftView",
4123
+ setup(t) {
4124
+ const { t: n } = Xe(), { viewDraft: e } = pt(), { viewClosingDraftProps: o, viewClosingDraftShow: i } = Kn(pt()), s = He(), r = pn(), u = Ln(), { breakpoints: c } = On();
4125
+ s.watchLocation(r.fetchDrafts);
4126
+ const b = I(() => r.loading), p = q(""), F = q(!1), E = I(() => c.value.xs || c.value.sm), U = I(() => E.value ? 10 : 20), P = I(
4127
+ () => {
4128
+ var x;
4129
+ return ((x = s._currentLocation) == null ? void 0 : x.type) === Yn.enum.warehouse;
4130
+ }
4131
+ );
4132
+ function S(x) {
4133
+ switch (x) {
4134
+ case "add":
4135
+ return F.value = !0;
4136
+ case "refresh":
4137
+ return r.fetchDrafts();
4138
+ }
4139
+ }
4140
+ function L(x) {
4141
+ return x;
4142
+ }
4143
+ function W(x) {
4144
+ return r.groupsByDraftId[x.original._id] ?? [];
4145
+ }
4146
+ function T(x) {
4147
+ return x.column.columnDef.meta;
4148
+ }
4149
+ function z(x) {
4150
+ const d = jo(W(x)), h = d.totalAmount.toLocaleString("en-MY", {
4151
+ minimumFractionDigits: 2,
4152
+ maximumFractionDigits: 2
4153
+ });
4154
+ return [
4155
+ `${d.totalItems} items`,
4156
+ `RM ${h}`,
4157
+ `${d.groupCount} groups`,
4158
+ `${d.completed} completed`,
4159
+ `${d.inProgress} in progress`,
4160
+ `${d.pending} pending`,
4161
+ d.rejected ? `${d.rejected} rejected` : null
4162
+ ].filter(Boolean).join(" · ");
4163
+ }
4164
+ const C = I(() => {
4165
+ const x = {
4166
+ label: n("inventory.closing.draft.createDraft.title"),
4167
+ value: "add",
4168
+ isPrimary: !0,
4169
+ prependIcon: "add"
4170
+ }, d = {
4171
+ label: n("inventory.common.refresh"),
4172
+ value: "refresh",
4173
+ isPrimary: !1
4174
+ };
4175
+ return [...P.value ? [x] : [], d];
4176
+ });
4177
+ return (x, d) => {
4178
+ const h = J("FmTable");
4179
+ return f(), $(le, null, [
4180
+ D(zn, {
4181
+ title: m(n)("inventory.closing.draft.title"),
4182
+ actions: C.value,
4183
+ "onClick:action": S
4184
+ }, {
4185
+ default: te(() => [
4186
+ a("div", {
4187
+ class: he([
4188
+ "flex flex-col gap-8 max-h-full",
4189
+ {
4190
+ "p-0": E.value,
4191
+ "px-24 ": !E.value
4192
+ }
4193
+ ])
4194
+ }, [
4195
+ D(no, {
4196
+ "change-location": "",
4197
+ searchable: "",
4198
+ search: p.value,
4199
+ "onUpdate:search": d[0] || (d[0] = (B) => p.value = B)
4200
+ }, null, 8, ["search"]),
4201
+ (f(), oe(h, {
4202
+ key: m(r).tableKey,
4203
+ style: dt(m(u).tableHeight),
4204
+ "column-defs": m(r).columnDefs,
4205
+ "row-data": m(r).drafts,
4206
+ "search-value": p.value,
4207
+ loading: b.value,
4208
+ onRowClick: d[1] || (d[1] = (B) => m(e)(B.original)),
4209
+ "page-size": U.value
4210
+ }, {
4211
+ "table-row": te((B) => [
4212
+ a("tr", {
4213
+ class: "border-b border-fm-color-neutral-gray-100 hover:bg-fm-color-opacity-sm cursor-pointer",
4214
+ onClick: (M) => m(e)(B.original)
4215
+ }, [
4216
+ (f(!0), $(le, null, ge(B.getVisibleCells(), (M) => {
4217
+ var O, g, _, w;
4218
+ return f(), $("td", {
4219
+ key: M.id,
4220
+ class: he([
4221
+ "h-[56px] text-fm-color-typo-primary align-top",
4222
+ ((O = T(M)) == null ? void 0 : O.cellClass) ?? "px-16 py-12"
4223
+ ]),
4224
+ style: dt({
4225
+ width: (g = T(M)) == null ? void 0 : g.width,
4226
+ maxWidth: (_ = T(M)) == null ? void 0 : _.maxWidth,
4227
+ textAlign: ((w = T(M)) == null ? void 0 : w.textAlign) ?? "left"
4228
+ })
4229
+ }, [
4230
+ a("div", Br, [
4231
+ a("span", Tr, [
4232
+ D(m(qe), {
4233
+ render: M.column.columnDef.cell,
4234
+ props: M.getContext()
4235
+ }, null, 8, ["render", "props"])
4236
+ ])
4237
+ ])
4238
+ ], 6);
4239
+ }), 128))
4240
+ ], 8, Ir)
4241
+ ]),
4242
+ "list-row": te((B) => [
4243
+ a("div", jr, [
4244
+ a("div", Pr, [
4245
+ D(uo, {
4246
+ class: "flex-1",
4247
+ row: B,
4248
+ onRowClick: (M) => m(e)(M)
4249
+ }, {
4250
+ default: te((M) => {
4251
+ var O, g, _, w, ne, Z, j, H, A, V, ie, se, ye, pe, De, Me, et, Ye, Ue, Ke;
4252
+ return [
4253
+ a("div", Rr, [
4254
+ a("div", Mr, [
4255
+ a("div", Ur, [
4256
+ D(m(qe), {
4257
+ render: (_ = (g = (O = M._id) == null ? void 0 : O.column) == null ? void 0 : g.columnDef) == null ? void 0 : _.cell,
4258
+ props: (ne = (w = M._id) == null ? void 0 : w.getContext) == null ? void 0 : ne.call(w)
4259
+ }, null, 8, ["render", "props"])
4260
+ ]),
4261
+ a("div", Nr, [
4262
+ D(m(qe), {
4263
+ render: (H = (j = (Z = M.name) == null ? void 0 : Z.column) == null ? void 0 : j.columnDef) == null ? void 0 : H.cell,
4264
+ props: (V = (A = M.name) == null ? void 0 : A.getContext) == null ? void 0 : V.call(A)
4265
+ }, null, 8, ["render", "props"])
4266
+ ]),
4267
+ a("div", Vr, N([
4268
+ ...B.original.items.slice(0, 3).map((tt) => tt.sku.name),
4269
+ ...B.original.items.length >= 3 ? [`and ${B.original.items.length - 3} more items`] : []
4270
+ ].join(", ")), 1),
4271
+ a("div", Er, [
4272
+ D(m(qe), {
4273
+ render: (ye = (se = (ie = M.ref) == null ? void 0 : ie.column) == null ? void 0 : se.columnDef) == null ? void 0 : ye.cell,
4274
+ props: (De = (pe = M.ref) == null ? void 0 : pe.getContext) == null ? void 0 : De.call(pe)
4275
+ }, null, 8, ["render", "props"])
4276
+ ])
4277
+ ]),
4278
+ W(B).length ? (f(), $("div", Lr, N(z(B)), 1)) : Y("", !0),
4279
+ a("div", null, [
4280
+ D(m(qe), {
4281
+ render: (Ye = (et = (Me = M.status) == null ? void 0 : Me.column) == null ? void 0 : et.columnDef) == null ? void 0 : Ye.cell,
4282
+ props: (Ke = (Ue = M.status) == null ? void 0 : Ue.getContext) == null ? void 0 : Ke.call(Ue)
4283
+ }, null, 8, ["render", "props"])
4284
+ ])
4285
+ ])
4286
+ ];
4287
+ }),
4288
+ _: 2
4289
+ }, 1032, ["row", "onRowClick"])
4290
+ ])
4291
+ ])
4292
+ ]),
4293
+ _: 1
4294
+ }, 8, ["style", "column-defs", "row-data", "search-value", "loading", "page-size"]))
4295
+ ], 2)
4296
+ ]),
4297
+ _: 1
4298
+ }, 8, ["title", "actions"]),
4299
+ D(Fr, {
4300
+ show: F.value,
4301
+ "onUpdate:show": d[2] || (d[2] = (B) => F.value = B),
4302
+ onSubmitted: m(r).fetchDrafts
4303
+ }, null, 8, ["show", "onSubmitted"]),
4304
+ (f(), oe(Vn, { to: "body" }, [
4305
+ D(er, En(m(o), {
4306
+ show: m(i),
4307
+ "onUpdate:show": d[3] || (d[3] = (B) => vt(i) ? i.value = B : null),
4308
+ onSubmitted: d[4] || (d[4] = () => (i.value = !1, m(r).fetchDrafts())),
4309
+ onRefresh: d[5] || (d[5] = (B) => m(r).updateDraftRef(B))
4310
+ }), null, 16, ["show"])
4311
+ ]))
4312
+ ], 64);
4313
+ };
4314
+ }
4315
+ });
4316
+ export {
4317
+ gl as default
4318
+ };