@feedmepos/mf-inventory-portal 1.7.9 → 1.7.11-dev.0

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