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