@feedmepos/mf-inventory-portal 1.7.13 → 1.7.15-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 (108) hide show
  1. package/dist/{App-tk0n6XzL.js → App-aeh6OigH.js} +471 -460
  2. package/dist/{ApprovalView-CdnT8CZe.js → ApprovalView-D9U2VmYa.js} +9 -9
  3. package/dist/{BindingsDialog-LfVK-lwi.js → BindingsDialog-Ddh44o3y.js} +2 -2
  4. package/dist/{BindingsPicker-DtFUIIp6.js → BindingsPicker-CFtdG6ld.js} +2 -2
  5. package/dist/{BindingsTable-SM-qs56h.js → BindingsTable-Dl44JUUS.js} +4 -4
  6. package/dist/{BulkReceiveRequestView-CxO4aceI.js → BulkReceiveRequestView-DzjYw8z3.js} +19 -19
  7. package/dist/{ChangeLocationComponent.vue_vue_type_script_setup_true_lang-B_dcsrft.js → ChangeLocationComponent.vue_vue_type_script_setup_true_lang-Bg8FBGzq.js} +6 -2
  8. package/dist/{ClosingDraftView-Bc9VEqFI.js → ClosingDraftView-D0SGlTkF.js} +19 -19
  9. package/dist/ClosingHistoryView-BKfhpOEw.js +761 -0
  10. package/dist/{ClosingTemplateView-Cf6BkJ1p.js → ClosingTemplateView-Ikq2OM4z.js} +16 -16
  11. package/dist/{CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-LtI-0ag-.js → CustomPrintTemplatePreview.vue_vue_type_script_setup_true_lang-BhTM2C3K.js} +1 -1
  12. package/dist/{DefaultView-zeN-SUL7.js → DefaultView-ClKfklyX.js} +2 -2
  13. package/dist/{DeliveryOrderPrintPreview-CPdBGfWd.js → DeliveryOrderPrintPreview-Cfz_N8Bf.js} +2 -2
  14. package/dist/{EmailDialog.vue_vue_type_script_setup_true_lang-CttfIuEb.js → EmailDialog.vue_vue_type_script_setup_true_lang-C-GPckzY.js} +23 -23
  15. package/dist/{FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-GYKs_eVT.js → FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-BxkzheM9.js} +1 -1
  16. package/dist/{FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-BlHeW9tQ.js → FmFilterableMenuOptions.vue_vue_type_script_setup_true_lang-CoFcZ-Zv.js} +2 -2
  17. package/dist/{FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-CSlAWGWz.js → FmInventoryTableToolbar.vue_vue_type_script_setup_true_lang-BAEpf31G.js} +2 -2
  18. package/dist/FmLockableField.vue_vue_type_script_setup_true_lang-FCg4K7y8.js +89 -0
  19. package/dist/{FmMultiselectDialog-DtvRQc96.js → FmMultiselectDialog-CiOdsRlf.js} +1 -1
  20. package/dist/{FmMultiselectDialog-gEkSoyOo.js → FmMultiselectDialog-Dr8wRNW7.js} +2 -2
  21. package/dist/{FmUnitInput.vue_vue_type_script_setup_true_lang-DEdVxDAl.js → FmUnitInput.vue_vue_type_script_setup_true_lang-D-Ycop6K.js} +6 -6
  22. package/dist/{ImportView-DvLVmruj.js → ImportView-BBqak01n.js} +6 -6
  23. package/dist/{IngredientBindedItem.vue_vue_type_script_setup_true_lang-C0eXC_7P.js → IngredientBindedItem.vue_vue_type_script_setup_true_lang-CAJDLjrN.js} +1 -1
  24. package/dist/{IngredientGroupView-4nVKjTVO.js → IngredientGroupView-CghsReO0.js} +5 -5
  25. package/dist/IngredientsView-DLxTWo-n.js +2239 -0
  26. package/dist/{IntegrationExplorerView-3wJ_2jLQ.js → IntegrationExplorerView-C05R8EzL.js} +4 -4
  27. package/dist/IntegrationView-DpN7PYPc.js +7623 -0
  28. package/dist/{InventoryBindingForm-BdbHMLKN.js → InventoryBindingForm-CnHzZu12.js} +1 -1
  29. package/dist/{InventoryBindingForm.vue_vue_type_script_setup_true_lang-mJ0hwtVM.js → InventoryBindingForm.vue_vue_type_script_setup_true_lang-Cls49Zgb.js} +5 -5
  30. package/dist/{InventoryBindingSummary-BKkBvlxM.js → InventoryBindingSummary-DK5Z9AKC.js} +1 -1
  31. package/dist/{NumberPrecisionInput.vue_vue_type_script_setup_true_lang-8kEGeYvD.js → NumberPrecisionInput.vue_vue_type_script_setup_true_lang-FsxbejSt.js} +1 -1
  32. package/dist/{PremiumBadge.vue_vue_type_script_setup_true_lang-BVX6226m.js → PremiumBadge.vue_vue_type_script_setup_true_lang-DvIbqRH9.js} +1 -1
  33. package/dist/{ProductionView-B4nPZTt9.js → ProductionView-DeUmELdm.js} +7 -7
  34. package/dist/{PublishView-do0VvwHk.js → PublishView-CGHFmmCG.js} +3 -3
  35. package/dist/{PurchaseOrderPrintPreview-VEJxKJZA.js → PurchaseOrderPrintPreview-xyXZU3oQ.js} +2 -2
  36. package/dist/{ReceiveRequestView-ycnbtRQp.js → ReceiveRequestView-CVmAUuqN.js} +14 -14
  37. package/dist/{RecipeView-Ce4AgrHT.js → RecipeView-BSd1V9En.js} +17 -17
  38. package/dist/{SettingsView-Bjx1z2gc.js → SettingsView-AI-JaGxh.js} +4 -4
  39. package/dist/{StockView-DqOEaJzz.js → StockView-CRrYes0h.js} +21 -21
  40. package/dist/{SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-DDT4AqtX.js → SubsidiaryTreeDialog.vue_vue_type_script_setup_true_lang-DNXdZVOA.js} +1 -1
  41. package/dist/{SupplierView-C07LyK32.js → SupplierView-BMupiPVi.js} +1156 -1035
  42. package/dist/{SurchargeView-BKapiG5x.js → SurchargeView-77KsLF2T.js} +6 -6
  43. package/dist/{SystemTrailDialog.vue_vue_type_script_setup_true_lang-BKE4I1gG.js → SystemTrailDialog.vue_vue_type_script_setup_true_lang-Brw98Ihw.js} +2 -2
  44. package/dist/{TemplatePublishDialog.vue_vue_type_script_setup_true_lang-XCYRCjQy.js → TemplatePublishDialog.vue_vue_type_script_setup_true_lang-Cjt4YAII.js} +1 -1
  45. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-BHeqFlka.js +4797 -0
  46. package/dist/{TransferTemplateView-r1gRvF7q.js → TransferTemplateView-BMF1_tLd.js} +20 -20
  47. package/dist/{UnitCostHistoryView-BzF5Ydfg.js → UnitCostHistoryView-Gp8uWjMQ.js} +4 -4
  48. package/dist/{UnitDisplayControl.vue_vue_type_script_setup_true_lang-D3Qc1b_g.js → UnitDisplayControl.vue_vue_type_script_setup_true_lang-mwAMQ0B3.js} +4 -4
  49. package/dist/{UnitView-CIus7XDF.js → UnitView-Cuk5oaOf.js} +7 -7
  50. package/dist/{WarehouseView-D0LAGPr6.js → WarehouseView-Bat0looR.js} +6 -6
  51. package/dist/{WastageTemplateView-CX_vY8lT.js → WastageTemplateView-Coag2jbG.js} +14 -14
  52. package/dist/api/netsuite.d.ts +2 -0
  53. package/dist/api/stock.d.ts +0 -6
  54. package/dist/{app-BFI89qx8.js → app-C3gNrduY.js} +464 -439
  55. package/dist/app.d.ts +32 -12
  56. package/dist/app.js +1 -1
  57. package/dist/{closing-template-BsT8mozh.js → closing-template-DKklbhBW.js} +1 -1
  58. package/dist/cypress/component/ChangelogPanel.cy.d.ts +1 -0
  59. package/dist/cypress/support/component.d.ts +1 -2
  60. package/dist/{date2-DRguSPlT.js → date2-Cx-YVc4N.js} +1 -1
  61. package/dist/{dayjs.min-CQchvANX.js → dayjs.min-Cj2Eh8Tj.js} +1 -1
  62. package/dist/{decimal-XTxcAfEO.js → decimal-OxPQV_Pd.js} +2 -2
  63. package/dist/{defineDeepModel-BRoQ53kt.js → defineDeepModel-Dud4PiVz.js} +1 -1
  64. package/dist/{duplicate-template-CjRLJUuX.js → duplicate-template-XAhspiYs.js} +1 -1
  65. package/dist/{feature-4NFlAslj.js → feature-gYL54g_K.js} +2 -2
  66. package/dist/{format-time-from-id-HjX4Uw5t.js → format-time-from-id-T7WHy_x1.js} +1 -1
  67. package/dist/{format-unit-display-Bv64TEgM.js → format-unit-display-BsjRSrAe.js} +12 -12
  68. package/dist/{import-export.helper-5GAs3g-u.js → import-export.helper-CEdt0BWR.js} +6 -6
  69. package/dist/{index-wBonClcq.js → index-BZynONs2.js} +3 -3
  70. package/dist/{index-DT7aF_IJ.js → index-CBcKeIhg.js} +1 -1
  71. package/dist/{index-Cy99iIzT.js → index-DQKbOIoT.js} +1 -1
  72. package/dist/{inventory-core-dart.default-aPOgM_iG.js → inventory-core-dart.default-D4zV0IQQ.js} +1428 -1322
  73. package/dist/{lz-string-D4H5yiwN.js → lz-string-BtyfM17N.js} +1 -1
  74. package/dist/{netsuite-CA6GsSZX.js → netsuite-BEW5HsxM.js} +477 -462
  75. package/dist/{number-wdTGPqVx.js → number-CQBgN-M7.js} +3 -3
  76. package/dist/{predefined-templates-5gDm-KTC.js → predefined-templates-CpP9HOqv.js} +1 -1
  77. package/dist/{purchase-order-template-NYXXge2I.js → purchase-order-template-PekDPb4u.js} +1 -1
  78. package/dist/{recalculationUtils-BYxkQ6y9.js → recalculationUtils-lfhKnVFx.js} +1 -1
  79. package/dist/{rules-CTPrTWcQ.js → rules-5x2UEFmU.js} +2 -2
  80. package/dist/{stock-B5SFlbu5.js → stock-Ch5c3jO9.js} +3 -3
  81. package/dist/{stock-BN60-dxD.js → stock-DqIRhhsu.js} +26 -36
  82. package/dist/stores/integration/netsuite.d.ts +54 -0
  83. package/dist/{supplier-qENTmxSk.js → supplier-DVxdFpgr.js} +2 -2
  84. package/dist/{surcharge-DqHTzQ4D.js → surcharge-CNGep-bs.js} +1 -1
  85. package/dist/tsconfig.app.tsbuildinfo +1 -1
  86. package/dist/{uom-rules-BQ2wBmPD.js → uom-rules-RPvKxFQI.js} +1 -1
  87. package/dist/{use-ingredient-select-dialog-DCLCw51r.js → use-ingredient-select-dialog-CPdwTQrN.js} +2 -2
  88. package/dist/{use-inventory-binding-dialog-BsbXZl-i.js → use-inventory-binding-dialog-CeyqcDPW.js} +2 -2
  89. package/dist/{use-template-enabled-locations-aNl_4Yzk.js → use-template-enabled-locations-DJ46fm8w.js} +2 -2
  90. package/dist/{use-transfer-locations-ChEibX9h.js → use-transfer-locations-DBIAb9MY.js} +2 -2
  91. package/dist/{useHrmPermission-DgjpLTc8.js → useHrmPermission-BEDY0i29.js} +1 -1
  92. package/dist/{useNavigationMenu-CMFZ-5F-.js → useNavigationMenu-xXANo9uC.js} +2 -2
  93. package/dist/{useSseClient-CT23c0Mu.js → useSseClient-B-dfDpdW.js} +1 -1
  94. package/dist/views/changelog/components/ChangelogFloatingButton.spec.d.ts +1 -0
  95. package/dist/views/changelog/composables/fab-position.d.ts +21 -0
  96. package/dist/views/changelog/composables/use-inventory-record-commits.d.ts +1 -1
  97. package/dist/views/integration/components/netsuite/business/vendor-publish.d.ts +7 -0
  98. package/dist/views/integration/components/netsuite/business/vendor-publish.spec.d.ts +1 -0
  99. package/dist/views/stock/components/dialog/RecalculationDialog.vue.d.ts +2 -17
  100. package/dist/{vue-i18n-Bj6Jb-Dc.js → vue-i18n-D64MVhs-.js} +295 -295
  101. package/dist/{xlsx.util-iqdZHANo.js → xlsx.util-BntGs-ye.js} +2 -2
  102. package/package.json +3 -3
  103. package/dist/ClosingHistoryView-BOjnPKtQ.js +0 -1112
  104. package/dist/IngredientsView-DQsn-GXv.js +0 -2322
  105. package/dist/IntegrationView-DOC5QhaQ.js +0 -7506
  106. package/dist/TransferDetails.vue_vue_type_script_setup_true_lang-CbaCIkH6.js +0 -4781
  107. package/dist/views/stock/components/StockRecalculateDialog.vue.d.ts +0 -9
  108. package/dist/views/stock/components/dialog/SnapshotRecalculationDialog.vue.d.ts +0 -24
@@ -0,0 +1,4797 @@
1
+ import { f as lt, p as ks } from "./format-time-from-id-T7WHy_x1.js";
2
+ import { defineComponent as Ve, ref as ne, watch as Ye, createElementBlock as v, openBlock as i, createCommentVNode as V, createElementVNode as e, withDirectives as Os, toDisplayString as k, unref as h, vModelText as xs, toRaw as ws, shallowRef as dt, onUnmounted as rs, triggerRef as $s, computed as H, readonly as Cs, h as re, resolveComponent as oe, createVNode as T, Fragment as Ce, renderList as Te, reactive as As, onMounted as os, createBlock as he, withCtx as ce, createTextVNode as Ge, normalizeClass as We, renderSlot as Ds, isRef as Rs, resolveDynamicComponent as Ns } from "vue";
3
+ import { c as Ht } from "./component-BmLAdDiY.js";
4
+ import { D as qe, R as Re } from "./row-action.enum-ncgDYAjP.js";
5
+ import { q as Ae, H as st, d as Ps, u as ze, V as z, _ as ns, $ as yt, U as ge, a as Dt, a0 as Gt, a1 as Fs, a2 as Is, G as Ts, s as Rt, c as wt, M as Wt, a3 as as, r as at, C as Ue, w as Pe, B as mt, a4 as Es } from "./app-C3gNrduY.js";
6
+ import { h as Nt, a as qs, t as Vs, b as et } from "./date2-Cx-YVc4N.js";
7
+ import { j as Ls, c as js, a as $e, t as Qe, d as ut } from "./number-CQBgN-M7.js";
8
+ import { F as Be, a as Us, b as Qt, d as St } from "./inventory-core-dart.default-D4zV0IQQ.js";
9
+ import { L as Ms } from "./lz-string-BtyfM17N.js";
10
+ import { useI18n as ht, useCoreStore as bt } from "@feedmepos/mf-common";
11
+ import { useDialog as gt, useSnackbar as Je, components as pt, FmButtonVariant as je, useProxiedModel as Bs } from "@feedmepos/ui-library";
12
+ import { u as _t, a as Pt, S as Me } from "./netsuite-BEW5HsxM.js";
13
+ import { F as tt } from "./FmAdminBadge-DlplQOHb.js";
14
+ import { u as Xe } from "./feature-gYL54g_K.js";
15
+ import { _ as Yt } from "./empty-placeholder-B0QU467o.js";
16
+ import { a as zs, b as Ks, f as ft } from "./format-unit-display-BsjRSrAe.js";
17
+ import { u as Ze, _ as Hs } from "./SystemTrailDialog.vue_vue_type_script_setup_true_lang-Brw98Ihw.js";
18
+ import { _ as Gs, a as Ws, b as Qs } from "./FmUnitInput.vue_vue_type_script_setup_true_lang-D-Ycop6K.js";
19
+ import { u as Ys, R as Jt } from "./usePromise-CbVUCxhj.js";
20
+ import { e as Js } from "./index-BZynONs2.js";
21
+ import { i as Xs } from "./FmDateRangePickerChip.vue_vue_type_script_setup_true_lang-BxkzheM9.js";
22
+ import { F as Xt } from "./form-mode.enum-BKiNVH6A.js";
23
+ import { u as ls } from "./supplier-DVxdFpgr.js";
24
+ import { u as Zs } from "./surcharge-CNGep-bs.js";
25
+ import { f as er, h as tr, r as sr, s as rr } from "./predefined-templates-CpP9HOqv.js";
26
+ import { F as or } from "./decimal-OxPQV_Pd.js";
27
+ import { d as is } from "./defineDeepModel-Dud4PiVz.js";
28
+ import { u as nr } from "./vue-i18n-D64MVhs-.js";
29
+ import { u as ar } from "./useHrmPermission-BEDY0i29.js";
30
+ function us(d, t) {
31
+ return t.reduce(
32
+ (n, m) => {
33
+ const u = m.received.find((c) => c.sku._id === d._id);
34
+ return u && (n = Ls(n, u.amount)), n;
35
+ },
36
+ or.toPrecision(js(0), d.unit.precision)
37
+ );
38
+ }
39
+ function cs(d) {
40
+ var n;
41
+ const t = Ae(), r = (n = d.supplier.supplyItems) != null && n.length ? { ...d.supplier, registrationNumber: d.supplier.registrationNumber ?? "" } : void 0;
42
+ return (m) => {
43
+ var u, c;
44
+ if ((u = m.totalCost) != null && u.amount) return m.totalCost;
45
+ if (!m.isCustomCost)
46
+ try {
47
+ const { cost: s } = Be.calculateDefaultCost({
48
+ item: m.sku,
49
+ amount: m.quantity,
50
+ measurement: m.measurement,
51
+ overrides: r ? { supplier: r } : void 0,
52
+ defaultCurrency: t
53
+ });
54
+ return s.amount ? s : void 0;
55
+ } catch (s) {
56
+ console.warn("[print] cost auto-calculation failed for item", (c = m.sku) == null ? void 0 : c._id, s);
57
+ return;
58
+ }
59
+ };
60
+ }
61
+ function lr(d) {
62
+ var Se, De, K, ve, P, x, w;
63
+ const { po: t, currentLocation: r, business: n, fulfilling: m, por: u } = d, c = r.doc.profile || {}, { name: s, address: a, regNo: O, legalName: f } = c, R = {
64
+ name: s || r.name || "",
65
+ legalName: f || void 0,
66
+ registrationNumber: O || void 0,
67
+ line1: (a == null ? void 0 : a.line1) || "",
68
+ line2: (a == null ? void 0 : a.line2) || void 0,
69
+ postcode: (a == null ? void 0 : a.postcode) || "",
70
+ city: (a == null ? void 0 : a.city) || "",
71
+ state: (a == null ? void 0 : a.state) || "",
72
+ country: (a == null ? void 0 : a.country) || ""
73
+ }, N = {
74
+ name: t.supplier.name,
75
+ phoneNumber: t.supplier.phoneNumber || void 0,
76
+ registrationNumber: t.supplier.registrationNumber || void 0,
77
+ line1: ((Se = t.supplier.address) == null ? void 0 : Se.line1) || "",
78
+ line2: ((De = t.supplier.address) == null ? void 0 : De.line2) || void 0,
79
+ postcode: ((K = t.supplier.address) == null ? void 0 : K.postcode) || "",
80
+ city: ((ve = t.supplier.address) == null ? void 0 : ve.city) || "",
81
+ state: ((P = t.supplier.address) == null ? void 0 : P.state) || "",
82
+ country: ((x = t.supplier.address) == null ? void 0 : x.country) || ""
83
+ }, F = cs(t), _ = [], B = t.items.filter((A) => A.sku).map((A) => {
84
+ var D;
85
+ const { sku: G, measurement: Z } = A, le = $e(
86
+ us(A.sku, t.deliveryOrder || []),
87
+ !1
88
+ ), b = F(A);
89
+ return b && _.push(b), {
90
+ code: G.code,
91
+ description: G.name,
92
+ quantity: $e(A.quantity, !1),
93
+ unit: (Z == null ? void 0 : Z.abbrev) || ((D = G.unit) == null ? void 0 : D.abbrev) || "",
94
+ received: le,
95
+ unitCost: b ? `${b.currency} ${Be.toFormatString({
96
+ value: A.quantity.amount === 0 ? Be.fromNumber(0) : Be.divide([b, A.quantity])
97
+ })}` : void 0,
98
+ cost: b ? `${b.currency} ${Be.toFormatString({
99
+ value: b
100
+ })}` : void 0
101
+ };
102
+ }), E = _.length ? `${_[0].currency} ${Be.toFormatString({
103
+ value: _.reduce((A, G) => Be.add([A, G]), Be.reset())
104
+ })}` : void 0, te = (t.deliveryOrder || []).map((A) => ({
105
+ createdAt: Nt(new Date(A.createdAt)),
106
+ ref: A.deliveryOrderNumber,
107
+ remark: A.remark || "",
108
+ items: (A.received || []).map((G) => {
109
+ var Z, le, b, D, ie;
110
+ return {
111
+ code: ((Z = G.sku) == null ? void 0 : Z.code) || "",
112
+ description: ((le = G.sku) == null ? void 0 : le.name) || "",
113
+ quantity: $e(G.amount),
114
+ unit: ((b = G.measurement) == null ? void 0 : b.abbrev) || ((ie = (D = G.sku) == null ? void 0 : D.unit) == null ? void 0 : ie.abbrev) || ""
115
+ };
116
+ })
117
+ }));
118
+ let se = st.Enum.purchaseOrder, Q = "Inventory Receive Note";
119
+ if (t.supplier.internal ? (Q = "Inventory Transfer Note", se = st.Enum.transferOrder) : (Q = "Purchase Order", se = st.Enum.purchaseOrder), (w = u == null ? void 0 : u.from) != null && w.dbName) {
120
+ const A = u.from.dbName;
121
+ r.dbName === A || (Q = "Inventory Receive Note", se = st.Enum.goodsReceivedNote);
122
+ }
123
+ const Oe = {
124
+ title: Q,
125
+ businessName: n == null ? void 0 : n.name,
126
+ logo: n == null ? void 0 : n.thumbnail,
127
+ orderNumber: t.seqNumber.toString(),
128
+ createdAt: lt(t._id),
129
+ ref: t.ref || "",
130
+ remark: t.remark || "",
131
+ buyer: R,
132
+ supplier: N,
133
+ items: B,
134
+ grandTotal: E,
135
+ status: t.status,
136
+ deliveryOrders: te
137
+ }, ae = m && (t.deliveryFullfillment || []).length > 0;
138
+ return ae && (se = st.Enum.deliveryOrder), { printData: Oe, templateType: se, isDeliveryPrint: ae };
139
+ }
140
+ function ds(d) {
141
+ var f;
142
+ const { printData: t, templateType: r } = lr(d), m = er().getTemplateByType(r), u = !!((f = m == null ? void 0 : m.blocks) != null && f.length), c = tr(r), s = u ? m.blocks : c.blocks, a = u ? m.name : c.name, O = !u;
143
+ try {
144
+ const R = sr(s, t), N = R.match(/<style>([\s\S]*?)<\/style>/), F = N ? `<style>${N[1]}</style>` : "", _ = R.replace(/<style>[\s\S]*?<\/style>/, "");
145
+ return {
146
+ html: `<!DOCTYPE html>
147
+ <html>
148
+ <head>
149
+ <meta charset="utf-8">
150
+ <title>Print Preview</title>
151
+ <style>
152
+ @page { margin: 0; }
153
+ @media print {
154
+ body { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
155
+ }
156
+ * { box-sizing: border-box; margin: 0; padding: 0; }
157
+ </style>
158
+ ${F}
159
+ </head>
160
+ <body>${_}</body>
161
+ </html>`,
162
+ templateName: a,
163
+ isDefault: O
164
+ };
165
+ } catch {
166
+ return alert("Failed to render print template. Please try recreating the template."), null;
167
+ }
168
+ }
169
+ const ir = Ps((d, t) => {
170
+ const r = ze();
171
+ return {
172
+ async getShipments({
173
+ start: n,
174
+ end: m
175
+ }) {
176
+ const u = r.currentLocationDBName, c = `${d.inventoryBackendUrl}/${u}/shipments`;
177
+ return await t.get(`${c}?start=${n}&end=${m}`);
178
+ },
179
+ async getShipmentsByIds(n) {
180
+ if (n.length === 0)
181
+ return [];
182
+ const m = r.currentLocationDBName, u = `${d.inventoryBackendUrl}/${m}/shipments/get`;
183
+ return await t.post(u, { shipmentIds: n });
184
+ }
185
+ };
186
+ }), ms = {
187
+ [z.enum.confirmDraft]: {
188
+ primaryActions: {
189
+ text: "Confirm draft",
190
+ close: !0
191
+ },
192
+ title: "Confirm draft?",
193
+ message: "Purchase order cannot be changed after confirm draft.",
194
+ successMessage: "Purchase order draft has been confirmed"
195
+ },
196
+ [z.enum.cancelDraft]: {
197
+ primaryActions: {
198
+ text: "Cancel draft",
199
+ close: !0,
200
+ variant: "destructive"
201
+ },
202
+ title: "Cancel draft?",
203
+ message: "Purchase order cannot be changed after cancelled draft.",
204
+ successMessage: "Purchase order draft has been cancelled"
205
+ },
206
+ [z.enum.approveDraft]: {
207
+ primaryActions: {
208
+ text: "Approve draft",
209
+ close: !0
210
+ },
211
+ title: "Approve draft?",
212
+ message: "Purchase order request will be accepted.",
213
+ successMessage: "Purchase order has been approved"
214
+ },
215
+ [z.enum.rejectDraft]: {
216
+ primaryActions: {
217
+ text: "Reject draft",
218
+ close: !0
219
+ },
220
+ title: "Reject draft?",
221
+ message: "Purchase order request will be rejected. You may provide an optional reason for rejection.",
222
+ successMessage: "Purchase order has been rejected"
223
+ },
224
+ [z.enum.submitRequest]: {
225
+ primaryActions: {
226
+ text: "Submit request",
227
+ close: !0
228
+ },
229
+ title: "Confirm draft?",
230
+ message: "Purchase order cannot be changed after confirm draft.",
231
+ successMessage: "Purchase order draft has been submitted"
232
+ },
233
+ [z.enum.completeReceive]: {
234
+ primaryActions: {
235
+ text: "Mark received",
236
+ close: !0
237
+ },
238
+ title: "Mark as received",
239
+ message: "Purchase order cannot be changed after it has complete receiving.",
240
+ successMessage: "Purchase order has been marked as received"
241
+ },
242
+ [z.enum.approveRequest]: {
243
+ primaryActions: {
244
+ text: "Accept request",
245
+ close: !0
246
+ },
247
+ title: "Accept request?",
248
+ message: "Transfer out request will be accepted.",
249
+ successMessage: "Transfer out request has been approved"
250
+ },
251
+ [z.enum.rejectRequest]: {
252
+ primaryActions: {
253
+ text: "Reject request",
254
+ close: !0,
255
+ variant: "destructive"
256
+ },
257
+ title: "Reject request?",
258
+ message: "Purchase order will be rejected.",
259
+ successMessage: "Purchase order has been rejected"
260
+ },
261
+ [z.enum.processRequest]: {
262
+ primaryActions: {
263
+ text: "Process request",
264
+ close: !0,
265
+ variant: "destructive"
266
+ },
267
+ title: "Process request?",
268
+ message: "Purchase order will be processed.",
269
+ successMessage: "Purchase order has been processed"
270
+ }
271
+ }, ur = { class: "p-4" }, cr = {
272
+ key: 0,
273
+ class: "fm-typo-en-body-md-400 mb-3"
274
+ }, dr = { class: "fm-typo-en-body-md-400" }, ps = /* @__PURE__ */ Ve({
275
+ __name: "RejectDraftForm",
276
+ props: {
277
+ message: {},
278
+ confirm: { type: Function },
279
+ onChange: { type: Function }
280
+ },
281
+ setup(d) {
282
+ const t = d, { t: r } = ht(), n = ne("");
283
+ Ye(n, (u) => {
284
+ var c;
285
+ (c = t.onChange) == null || c.call(t, u ?? "");
286
+ });
287
+ function m() {
288
+ n.value = "";
289
+ }
290
+ return (u, c) => (i(), v("div", ur, [
291
+ t.message ? (i(), v("div", cr, k(t.message), 1)) : V("", !0),
292
+ e("label", dr, k(h(r)("inventory.transfer.receiveRequest.details.rejectionReason")) + " (" + k(h(r)("inventory.common.optional")) + ")", 1),
293
+ Os(e("textarea", {
294
+ "onUpdate:modelValue": c[0] || (c[0] = (s) => n.value = s),
295
+ rows: "4",
296
+ class: "w-full mt-2 p-2 border rounded"
297
+ }, null, 512), [
298
+ [xs, n.value]
299
+ ]),
300
+ e("div", { class: "mt-3 flex gap-2" }, [
301
+ e("button", {
302
+ type: "button",
303
+ class: "fm-btn fm-btn-tertiary",
304
+ onClick: m
305
+ }, "Clear")
306
+ ])
307
+ ]));
308
+ }
309
+ });
310
+ function vt(d) {
311
+ if (d.items == null)
312
+ return {};
313
+ const t = ns.safeParse(d);
314
+ if (!t.success) {
315
+ const r = t.error.issues.map((n) => `${n.path.join(".") || "(root)"}: ${n.message}`).join("; ");
316
+ return console.error(
317
+ `Cannot compute receive status for PO ${d == null ? void 0 : d._id}: invalid shape at ${r}`
318
+ ), {};
319
+ }
320
+ return yt.generatedPOReceivedMap({
321
+ purchaseOrder: d
322
+ });
323
+ }
324
+ function mr(d) {
325
+ return yt.validatePOItemReceivedStatus({
326
+ dto: d
327
+ });
328
+ }
329
+ function $t(d) {
330
+ return yt.validatePOReceivedStatus({
331
+ receivedMap: d
332
+ });
333
+ }
334
+ function Ct(d, t, r) {
335
+ if (!ge.safeParse(d).success)
336
+ throw new Error(`Invalid purchase order status: ${d}`);
337
+ const n = ge.parse(d);
338
+ return yt.orderStatusCombination({
339
+ status: n,
340
+ isPOPartialReceive: t,
341
+ isPOOverReceive: r
342
+ });
343
+ }
344
+ function fs() {
345
+ const d = ze(), t = Ze(), r = Xe();
346
+ async function n(u, c) {
347
+ const s = d.currentLocationDBName;
348
+ return u.doc.supplier.internal && u.operation === z.enum.confirmDraft && (u.operation = z.enum.submitRequest), await t.processPurchaseOrder(u, c || s);
349
+ }
350
+ async function m(u, c) {
351
+ const s = d.currentLocationDBName;
352
+ return await t.processPurchaseOrderV2(u, c || s);
353
+ }
354
+ return (u) => r.useOperatePurchaseOrderV2 ? m(u.operateV2, u.transferTo) : n(u.operate, u.transferTo);
355
+ }
356
+ function He(d) {
357
+ const t = ws(d);
358
+ if (Array.isArray(t))
359
+ return t.map(He);
360
+ if (t !== null && typeof t == "object") {
361
+ const r = {};
362
+ for (const n in t)
363
+ Object.prototype.hasOwnProperty.call(t, n) && (r[n] = He(t[n]));
364
+ return r;
365
+ }
366
+ return t;
367
+ }
368
+ const kt = {
369
+ set: "set",
370
+ add: "add",
371
+ delete: "delete"
372
+ };
373
+ function Zt(d) {
374
+ return {
375
+ dbName: d.dbName,
376
+ type: d.type,
377
+ name: d.name,
378
+ acceptRequest: d.acceptRequest ?? !1,
379
+ doc: d.doc
380
+ };
381
+ }
382
+ const vs = { line1: "", state: "", city: "", postcode: "", country: "" };
383
+ function rt(d) {
384
+ return d == null ? "" : String(d);
385
+ }
386
+ function ys(d) {
387
+ const t = d.address, r = t != null ? {
388
+ ...t,
389
+ line1: rt(t.line1),
390
+ state: rt(t.state),
391
+ city: rt(t.city),
392
+ postcode: rt(t.postcode),
393
+ country: rt(t.country)
394
+ } : { ...vs };
395
+ return {
396
+ ...d,
397
+ registrationNumber: d.registrationNumber ?? "",
398
+ address: r
399
+ };
400
+ }
401
+ function es(d, t, r, n, m) {
402
+ const u = He(d.suppliers ?? []).map(ys), c = He(t.allLocations ?? []).map(Zt), s = t._currentLocation ? Zt(He(t._currentLocation)) : null, a = r.inventory ? [He(r.inventory)] : [], O = n.state.setting ? He(n.state.setting) : null, f = He(m.surcharges ?? []);
403
+ return {
404
+ suppliers: u,
405
+ locations: c,
406
+ currentLocation: s,
407
+ inventoryDoc: a,
408
+ netSuiteSetting: O,
409
+ surcharges: f
410
+ };
411
+ }
412
+ function hs() {
413
+ const d = ls(), t = ze(), r = Dt(), n = _t(), m = Zs(), u = es(
414
+ d,
415
+ t,
416
+ r,
417
+ n,
418
+ m
419
+ ), c = dt(Us({ env: u }));
420
+ c.value.setUsePartialUpdates(!0);
421
+ const s = dt(c.value.state()), a = (N) => {
422
+ s.value = c.value.state();
423
+ };
424
+ c.value.addListener(a);
425
+ const O = (N, F, _) => {
426
+ switch (N) {
427
+ case kt.set:
428
+ Gt(s.value, F, _);
429
+ break;
430
+ case kt.add:
431
+ Is(s.value, F, _);
432
+ break;
433
+ case kt.delete:
434
+ Fs(s.value, F);
435
+ break;
436
+ default:
437
+ console.warn(`Unknown partial update operation: ${N}, falling back to 'set'`), Gt(s.value, F, _);
438
+ }
439
+ F !== "remark" && F !== "ref" && $s(s);
440
+ };
441
+ c.value.addPartialListener(O);
442
+ function f() {
443
+ const N = es(
444
+ d,
445
+ t,
446
+ r,
447
+ n,
448
+ m
449
+ );
450
+ try {
451
+ c.value.updateFullEnv(N), s.value = c.value.state();
452
+ } catch (F) {
453
+ console.error("[PurchaseOrderFormController] updateFullEnv failed", F);
454
+ }
455
+ }
456
+ Ye(
457
+ [
458
+ () => d.suppliers,
459
+ () => t.allLocations,
460
+ () => t._currentLocation,
461
+ () => r.inventory,
462
+ () => n.state.setting,
463
+ () => m.surcharges
464
+ ],
465
+ () => {
466
+ f();
467
+ },
468
+ { deep: !0 }
469
+ ), rs(() => {
470
+ c.value.removeListener(a), c.value.removePartialListener(O);
471
+ });
472
+ function R(N) {
473
+ var F;
474
+ if (N != null && N._id) {
475
+ const _ = /* @__PURE__ */ new Set(["1", "2"]), B = N, E = B.supplier, te = E != null ? ys(E) : { _id: "", name: "", registrationNumber: "", address: { ...vs } }, se = {
476
+ ...N,
477
+ version: _.has(N.version) ? N.version : null,
478
+ supplier: te,
479
+ // items/deliveryOrder may be absent or contain null/corrupted elements.
480
+ // The Dart bridge has no null guards on sku, sku.unit, and quantity —
481
+ // all three produce "Uncaught (in promise) TypeError: $index on null".
482
+ items: (B.items ?? []).filter((Q) => {
483
+ if (Q == null || Q.sku == null || typeof Q.sku != "object") return !1;
484
+ const de = Q;
485
+ return de.sku.unit != null && de.quantity != null && typeof de.quantity == "object";
486
+ }),
487
+ // received[].sku/sku.unit/amount have the exact same Dart-bridge null-guard
488
+ // gap as items[].sku/sku.unit/quantity above — filter the same way.
489
+ deliveryOrder: (B.deliveryOrder ?? []).filter((Q) => Q != null).map((Q) => ({
490
+ ...Q,
491
+ received: (Q.received ?? []).filter((de) => {
492
+ if (de == null || de.sku == null || typeof de.sku != "object") return !1;
493
+ const Oe = de;
494
+ return Oe.sku.unit != null && Oe.amount != null && typeof Oe.amount == "object";
495
+ })
496
+ }))
497
+ };
498
+ try {
499
+ c.value.loadPurchaseOrder(se);
500
+ } catch (Q) {
501
+ console.error("[PurchaseOrderFormController] loadPurchaseOrder failed", Q);
502
+ }
503
+ return;
504
+ }
505
+ if (!Xe().mustUsePoTemplate) {
506
+ c.value.init();
507
+ return;
508
+ }
509
+ N != null && N.template && ((F = N.templateDoc) != null && F.purchaseOrder) ? (N.items = N.templateDoc.purchaseOrder.items, c.value.initFromTemplate(N)) : c.value.initOutletToOutlet();
510
+ }
511
+ return {
512
+ controller: c,
513
+ state: s,
514
+ init: R
515
+ };
516
+ }
517
+ var At = /* @__PURE__ */ ((d) => (d.RECEIVE_REQUEST = "receive/request", d.APPROVAL = "approval", d))(At || {});
518
+ const ot = ne(), Ot = ne(), xt = ne();
519
+ function bi(d, t) {
520
+ const r = gt(), n = ze(), m = Xe(), u = ls(), c = bt(), s = zs(), a = Ks(), O = ne(!1), f = Je(), R = Ze(), N = ir(), F = ne(new Array()), _ = ne(new Array()), B = ne(
521
+ t != null && t.startDate && (t != null && t.endDate) ? t : Xs()
522
+ ), E = H(() => {
523
+ const b = new Date(B.value.startDate), D = new Date(B.value.endDate);
524
+ return {
525
+ start: Vs(b).toISOString(),
526
+ end: qs(D).toISOString()
527
+ };
528
+ }), te = ne(new Array()), se = Ts(), Q = ne(null);
529
+ async function de(b) {
530
+ function D(ee) {
531
+ const L = {
532
+ mode: Xt.CREATE,
533
+ modelValue: b || void 0,
534
+ show: !0,
535
+ "onUpdate:show"(g) {
536
+ ot.value.show = g;
537
+ },
538
+ templateId: ee,
539
+ lastClosingDate: Q.value
540
+ };
541
+ ot.value = L;
542
+ }
543
+ let ie;
544
+ m.mustUsePoTemplate && !(b != null && b.template) ? r.open({
545
+ title: "Create transfer",
546
+ message: "",
547
+ primaryActions: {
548
+ text: "Select a template",
549
+ close: !0
550
+ },
551
+ secondaryActions: {
552
+ text: "Outlet to Outlet",
553
+ variant: "secondary",
554
+ close: !0
555
+ }
556
+ }).onPrimary(async () => {
557
+ ie = await s.getTemplateId(), ie && D(ie);
558
+ }).onSecondary(() => {
559
+ D(void 0);
560
+ }) : D(ie);
561
+ }
562
+ function Oe(b) {
563
+ const D = {
564
+ mode: Xt.UPDATE,
565
+ modelValue: wt(b),
566
+ show: !0,
567
+ "onUpdate:show"(ie) {
568
+ ot.value.show = ie;
569
+ },
570
+ lastClosingDate: Q.value
571
+ };
572
+ ot.value = D;
573
+ }
574
+ function ae(b) {
575
+ if (!c.currentBusiness.value) return;
576
+ const D = n.currentLocation;
577
+ if (D.type === "restaurant") {
578
+ const j = n.locationRestaurantFromCore(D.doc._id);
579
+ j !== null && (D.doc = j);
580
+ }
581
+ const ie = ds({
582
+ po: b,
583
+ currentLocation: D,
584
+ business: c.currentBusiness.value,
585
+ fulfilling: d === "approval",
586
+ por: b.request
587
+ });
588
+ if (!ie) return;
589
+ const ee = rr(ie.html), L = u.supplierById[b.supplier._id], g = {
590
+ recipientName: L.name,
591
+ email: (L == null ? void 0 : L.email) ?? "",
592
+ business: c.currentBusiness.value,
593
+ modelValue: ee,
594
+ show: !0,
595
+ "onUpdate:show"(j) {
596
+ Ot.value.show = j;
597
+ }
598
+ };
599
+ Ot.value = g;
600
+ }
601
+ async function Se() {
602
+ F.value = [], _.value = [], O.value = !0;
603
+ try {
604
+ const b = await R.getPurchaseOrders(E.value);
605
+ F.value = b.sort((j, J) => J._id.localeCompare(j._id));
606
+ const D = b.flatMap((j) => j.shipmentIds || []).filter(Boolean), ie = D.length > 0 ? await N.getShipmentsByIds(D) : [];
607
+ _.value = ie;
608
+ const ee = await se.readCurrentLocationLastClosing(!0), L = ee == null ? void 0 : ee._id;
609
+ L && (Q.value = ks(L)), await m.awaitFeatureLoaded(() => m.mustUsePoTemplate) && await a.fetchTemplates();
610
+ const g = F.value.map((j) => {
611
+ var J;
612
+ return ((J = j.request) == null ? void 0 : J.id) ?? "";
613
+ }).filter((j) => j);
614
+ te.value = await R.readRequestByIds(g);
615
+ } catch {
616
+ f.open({
617
+ title: "Something went wrong",
618
+ message: "Error at fetching purchase orders",
619
+ type: "error"
620
+ });
621
+ } finally {
622
+ O.value = !1;
623
+ }
624
+ }
625
+ async function De() {
626
+ te.value = [], O.value = !0;
627
+ try {
628
+ te.value = await R.readRequests(
629
+ void 0,
630
+ E.value.start,
631
+ E.value.end
632
+ ).then((b) => b.reverse());
633
+ } catch {
634
+ f.open({
635
+ title: "Something went wrong",
636
+ message: "Error at fetching purchase requests",
637
+ type: "error"
638
+ });
639
+ } finally {
640
+ O.value = !1;
641
+ }
642
+ }
643
+ function K() {
644
+ switch (d) {
645
+ case "receive/request":
646
+ return Se();
647
+ case "approval":
648
+ return De();
649
+ }
650
+ }
651
+ function ve(b, D) {
652
+ B.value = {
653
+ startDate: b,
654
+ endDate: D
655
+ }, K();
656
+ }
657
+ n.watchLocation(async (b) => {
658
+ if (!b) {
659
+ F.value = [];
660
+ return;
661
+ }
662
+ await K();
663
+ });
664
+ async function P(b) {
665
+ return b;
666
+ }
667
+ const x = ne(), w = ne(Math.random().toString());
668
+ async function A(b, D) {
669
+ const ie = Math.random().toString();
670
+ w.value = ie, D ?? (D = te.value.computeFirst(
671
+ (j) => j.purchaseOrderId === b._id ? j : null
672
+ ) ?? void 0);
673
+ const ee = d === "receive/request" ? n.currentLocation : D == null ? void 0 : D.to, L = d === "approval", g = {
674
+ poRequest: D,
675
+ purchaseOrder: {
676
+ ...b,
677
+ status: L && (D != null && D.rejectedAt) ? ge.Enum.REJECT : b.status
678
+ },
679
+ transferTo: ee == null ? void 0 : ee.name,
680
+ transferToDbName: ee == null ? void 0 : ee.dbName,
681
+ show: !0,
682
+ canResubmit: !1,
683
+ canApprove: L,
684
+ "onUpdate:show"(j) {
685
+ x.value && (x.value = { ...x.value, show: j });
686
+ },
687
+ scope: d,
688
+ receivedMap: vt(b) ?? {},
689
+ shipments: _.value
690
+ };
691
+ x.value = g;
692
+ }
693
+ async function G(b, D, ie, ee, L) {
694
+ const g = fs();
695
+ O.value = !0;
696
+ try {
697
+ await g({
698
+ operate: {
699
+ operation: D,
700
+ doc: b,
701
+ options: (
702
+ // auto receive for supplier to warehouse
703
+ (D === z.enum.confirmDraft || // auto receive for warehouse to warehouse
704
+ D === z.enum.completeReceive) && m.autoReceiveWarehouse ? {
705
+ autoReceive: !0
706
+ } : void 0
707
+ )
708
+ },
709
+ operateV2: {
710
+ _id: b._id,
711
+ _rev: b._rev ?? "",
712
+ action: D === z.enum.submitRequest ? z.enum.confirmDraft : D,
713
+ payloads: L ?? []
714
+ },
715
+ transferTo: ee
716
+ }), await new Promise((me) => setTimeout(me, 1e3));
717
+ const J = ze().currentLocationDBName.startsWith("restaurant_");
718
+ D === z.enum.confirmDraft && b.effectiveAt && J ? f.open({
719
+ title: "Success",
720
+ message: `${ie}. The backdate will be reflected once your POS has received this change.`,
721
+ type: "success"
722
+ }) : f.open({
723
+ title: "Success",
724
+ message: ie,
725
+ type: "success"
726
+ });
727
+ } catch (j) {
728
+ f.open({
729
+ title: "Something went wrong",
730
+ message: j instanceof Error ? j.message : "Please try again.",
731
+ type: "error"
732
+ }), console.error("Error when submitting PO operation", D, b, j);
733
+ } finally {
734
+ O.value = !1, K();
735
+ }
736
+ }
737
+ async function Z(b, D, ie) {
738
+ const ee = ms[D];
739
+ if (!ee) {
740
+ f.open({
741
+ title: "Something went wrong",
742
+ message: `Cannot process order: ${Rt(D)}`,
743
+ type: "error"
744
+ });
745
+ return;
746
+ }
747
+ const { successMessage: L, ...g } = ee;
748
+ if (D === z.enum.rejectDraft) {
749
+ let me = "";
750
+ r.open({
751
+ title: g.title,
752
+ message: g.message,
753
+ primaryActions: g.primaryActions,
754
+ contentComponent: ps,
755
+ contentComponentProps: {
756
+ message: g.message,
757
+ onChange: (ke) => me = ke
758
+ }
759
+ }).onPrimary(() => {
760
+ const ke = [];
761
+ ke.push({
762
+ action: "rejectDraft",
763
+ payload: {
764
+ rejectReason: me
765
+ }
766
+ }), G(b, D, L, ie, ke);
767
+ });
768
+ return;
769
+ }
770
+ const j = [], J = hs();
771
+ J.init(b), (D === z.enum.confirmDraft || D === z.enum.submitRequest) && j.push({
772
+ action: "confirmDraft",
773
+ payload: J.controller.value.toConfirmDraftData(Ae())
774
+ }), r.open({
775
+ title: g.title,
776
+ message: g.message,
777
+ primaryActions: g.primaryActions
778
+ }).onPrimary(() => {
779
+ G(b, D, L, ie, j);
780
+ });
781
+ }
782
+ async function le() {
783
+ r.open({
784
+ title: "Upload Transfer",
785
+ primaryActions: {
786
+ text: "Xilnex transfer note",
787
+ close: !0
788
+ },
789
+ secondaryActions: {
790
+ text: "Cancel",
791
+ close: !0
792
+ }
793
+ }).onPrimary(() => {
794
+ const b = {
795
+ show: !0,
796
+ "onUpdate:show"(D) {
797
+ xt.value.show = D;
798
+ }
799
+ };
800
+ xt.value = b;
801
+ });
802
+ }
803
+ return {
804
+ purchaseOrders: F,
805
+ shipments: _,
806
+ purchaseRequests: te,
807
+ updateDateRange: ve,
808
+ fetchData: K,
809
+ loading: O,
810
+ transferDialogProps: ot,
811
+ promptCreateTransferDialog: de,
812
+ promptUpdateTransferDialog: Oe,
813
+ transferDetailsProps: x,
814
+ promptShowTransferDetails: A,
815
+ resolvePO: P,
816
+ submitAction: Z,
817
+ xilnexImportDialogProps: xt,
818
+ promptUploadTransferDialog: le,
819
+ emailDialogProps: Ot,
820
+ promptEmailDialog: ae
821
+ };
822
+ }
823
+ function pr(d) {
824
+ var ae, Se, De, K, ve, P;
825
+ const { po: t, currentLocation: r, business: n, fulfilling: m, por: u } = d, { name: c, address: s, regNo: a, legalName: O } = r.doc.profile, f = {
826
+ name: c,
827
+ legalName: O,
828
+ registrationNumber: a,
829
+ line1: s == null ? void 0 : s.line1,
830
+ line2: s == null ? void 0 : s.line2,
831
+ postcode: s == null ? void 0 : s.postcode,
832
+ city: s == null ? void 0 : s.city,
833
+ state: s == null ? void 0 : s.state,
834
+ country: s == null ? void 0 : s.country
835
+ }, R = {
836
+ name: t.supplier.name,
837
+ phoneNumber: t.supplier.phoneNumber,
838
+ registrationNumber: t.supplier.registrationNumber,
839
+ line1: (ae = t.supplier.address) == null ? void 0 : ae.line1,
840
+ line2: (Se = t.supplier.address) == null ? void 0 : Se.line2,
841
+ postcode: (De = t.supplier.address) == null ? void 0 : De.postcode,
842
+ city: (K = t.supplier.address) == null ? void 0 : K.city,
843
+ state: (ve = t.supplier.address) == null ? void 0 : ve.state,
844
+ country: (P = t.supplier.address) == null ? void 0 : P.country
845
+ }, N = cs(t), F = t.items.map((x) => {
846
+ const { sku: w, measurement: A } = x, G = $e(
847
+ us(x.sku, t.deliveryOrder || []),
848
+ !1
849
+ ), Z = N(x);
850
+ return {
851
+ code: w.code,
852
+ description: w.name,
853
+ quantity: $e(x.quantity, !1),
854
+ unit: (A == null ? void 0 : A.abbrev) || w.unit.abbrev,
855
+ received: G,
856
+ cost: Z ? `${Z.currency} ${Be.toFormatString({
857
+ value: Z
858
+ })}` : void 0
859
+ };
860
+ }), _ = t.deliveryOrder.map((x) => ({
861
+ createdAt: Nt(new Date(x.createdAt)),
862
+ ref: x.deliveryOrderNumber,
863
+ remark: x.remark || "",
864
+ items: x.received.map((w) => {
865
+ var A;
866
+ return {
867
+ code: w.sku.code,
868
+ description: w.sku.name,
869
+ quantity: $e(w.amount),
870
+ unit: ((A = w.measurement) == null ? void 0 : A.abbrev) || w.sku.unit.abbrev
871
+ };
872
+ })
873
+ })), B = [
874
+ // Production
875
+ "67ca5d2c80bd0e001c5bf5bc",
876
+ // Dev
877
+ "6880b36a3054c5001db19218"
878
+ ];
879
+ let E = "Inventory Receive Note";
880
+ if (t.supplier.internal ? (E = "Inventory Transfer Note", B.includes((n == null ? void 0 : n._id) || "") && (E = "Stock Request")) : E = "Purchase Order", u) {
881
+ const x = u.from.dbName;
882
+ r.dbName === x || (E = "Inventory Receive Note");
883
+ }
884
+ const se = {
885
+ title: E,
886
+ businessName: n == null ? void 0 : n.name,
887
+ logo: n == null ? void 0 : n.thumbnail,
888
+ orderNumber: t.seqNumber.toString(),
889
+ createdAt: lt(t._id),
890
+ ref: t.ref || "",
891
+ remark: t.remark || "",
892
+ buyer: f,
893
+ supplier: R,
894
+ items: F,
895
+ status: t.status,
896
+ deliveryOrders: _
897
+ }, Q = new URL(window.location.href), de = m && (t.deliveryFullfillment || []).length > 0 ? "receive-request/delivery-print-preview" : "receive-request/print-preview";
898
+ Q.pathname = Q.hostname.includes("portal.feedme") ? `/inventory/${de}` : `/${de}`;
899
+ const Oe = Ms.compressToEncodedURIComponent(JSON.stringify(se));
900
+ Q.searchParams.append("data", Oe), window.open(Q.href, "_blank", "noreferrer");
901
+ }
902
+ const Ke = {
903
+ submitRequest: {
904
+ translationKey: "inventory.transfer.receiveRequest.actions.submitRequest",
905
+ color: "text-fm-color-typo-primary",
906
+ value: z.enum.submitRequest
907
+ },
908
+ confirmDraft: {
909
+ translationKey: "inventory.transfer.receiveRequest.actions.confirmDraft",
910
+ color: "text-fm-color-typo-primary",
911
+ value: z.enum.confirmDraft
912
+ },
913
+ cancelDraft: {
914
+ translationKey: "inventory.transfer.receiveRequest.actions.cancelDraft",
915
+ color: "text-fm-color-typo-error",
916
+ value: z.enum.cancelDraft
917
+ },
918
+ approveRequest: {
919
+ translationKey: "inventory.transfer.receiveRequest.actions.approveRequest",
920
+ color: "text-fm-color-typo-primary",
921
+ value: z.enum.approveRequest
922
+ },
923
+ rejectRequest: {
924
+ translationKey: "inventory.transfer.receiveRequest.actions.rejectRequest",
925
+ color: "text-fm-color-typo-error",
926
+ value: z.enum.rejectRequest
927
+ },
928
+ processRequest: {
929
+ translationKey: "inventory.transfer.receiveRequest.actions.processRequest",
930
+ color: "text-fm-color-typo-primary",
931
+ value: z.enum.processRequest
932
+ },
933
+ receiveStock: {
934
+ translationKey: "inventory.transfer.receiveRequest.actions.receiveStock",
935
+ color: "text-fm-color-typo-primary",
936
+ value: z.enum.receiveStock
937
+ },
938
+ completeReceive: {
939
+ translationKey: "inventory.transfer.receiveRequest.actions.completeReceive",
940
+ color: "text-fm-color-typo-primary",
941
+ value: z.enum.completeReceive
942
+ },
943
+ closeRequest: {
944
+ translationKey: "inventory.transfer.receiveRequest.actions.closeRequest",
945
+ color: "system-error-300",
946
+ value: z.enum.closeRequest
947
+ },
948
+ approveDraft: {
949
+ translationKey: "inventory.transfer.receiveRequest.actions.approveDraft",
950
+ color: "text-fm-color-typo-primary",
951
+ value: z.enum.approveDraft
952
+ },
953
+ rejectDraft: {
954
+ translationKey: "inventory.transfer.receiveRequest.actions.rejectDraft",
955
+ color: "text-fm-color-typo-error",
956
+ value: z.enum.rejectDraft
957
+ },
958
+ returnStock: {
959
+ translationKey: "inventory.transfer.receiveRequest.actions.returnStock",
960
+ color: "text-fm-color-typo-primary",
961
+ value: z.enum.returnStock
962
+ }
963
+ };
964
+ function bs() {
965
+ const d = Xe();
966
+ return {
967
+ ableToMarkReceived(t) {
968
+ if (!t || t.status !== ge.enum.RECEIVING || d.useOperatePurchaseOrderV2) return !1;
969
+ const n = ze().currentLocationDBName;
970
+ return `${t.supplier.internal}_${t.supplier._id}` !== n;
971
+ },
972
+ ableToMarkApproved(t) {
973
+ return !(!t || (t == null ? void 0 : t.status) !== ge.enum.REQUESTING);
974
+ },
975
+ ableToCreateFulfillment(t, r) {
976
+ var u, c;
977
+ if (!d.acceptRequireFulfillment || !t || !r || t.status !== ge.enum.PROCESSING || !r.processedAt)
978
+ return !1;
979
+ const n = (u = r == null ? void 0 : r.from) == null ? void 0 : u.dbName, m = (c = r == null ? void 0 : r.to) == null ? void 0 : c.dbName;
980
+ return !(n.startsWith("restaurant_") && m.startsWith("restaurant_"));
981
+ }
982
+ };
983
+ }
984
+ function gs() {
985
+ const d = H(() => [
986
+ {
987
+ action: Wt.Action.manage,
988
+ subject: Wt.Subject.Business.inventory_orderDraftApproval
989
+ }
990
+ ]), { hasPermission: t } = ar(d);
991
+ return {
992
+ hasOrderDraftPermission: Cs(t)
993
+ };
994
+ }
995
+ function gi(d, t, r, n) {
996
+ const m = ze(), u = _t(), c = bt(), s = bs(), { t: a } = ht(), O = Je(), { hasOrderDraftPermission: f } = gs(), R = Xe(), N = H(
997
+ () => R.enablePrintTemplate ? [qe[Re.PrintCustom]] : []
998
+ ), F = H(
999
+ () => R.enablePurchaseOrderEmail ? [qe[Re.Email]] : []
1000
+ );
1001
+ function _(K) {
1002
+ const ve = B(K), P = n == null ? void 0 : n.excludeRowActions;
1003
+ return P != null && P.length ? ve.filter(
1004
+ (x) => !P.includes(x.value)
1005
+ ) : ve;
1006
+ }
1007
+ function B(K) {
1008
+ switch (K.status) {
1009
+ case "DRAFT":
1010
+ return [
1011
+ qe[Re.Update],
1012
+ qe[Re.Details],
1013
+ K.supplier.internal === "restaurant" || K.supplier.internal === "warehouse" ? Ke[z.enum.submitRequest] : Ke[z.enum.confirmDraft],
1014
+ Ke[z.enum.cancelDraft]
1015
+ ];
1016
+ case "RECEIVING":
1017
+ return [
1018
+ ...s.ableToMarkReceived(K) ? [Ke[z.enum.completeReceive]] : [],
1019
+ qe[Re.Details],
1020
+ qe[Re.Print],
1021
+ ...N.value,
1022
+ ...F.value
1023
+ ];
1024
+ case "PENDING_APPROVAL": {
1025
+ const P = [qe[Re.Details]];
1026
+ return f.value && P.push(
1027
+ qe[Re.Update],
1028
+ Ke[z.enum.approveDraft],
1029
+ Ke[z.enum.rejectDraft]
1030
+ ), P;
1031
+ }
1032
+ case "REQUESTING":
1033
+ return d === "receive/request" ? [
1034
+ qe[Re.Details],
1035
+ qe[Re.Print],
1036
+ ...N.value
1037
+ ] : [
1038
+ Ke[z.enum.approveRequest],
1039
+ Ke[z.enum.rejectRequest],
1040
+ qe[Re.Details]
1041
+ // DefaultRowActions[RowActionEnum.Print]
1042
+ ];
1043
+ case "PROCESSING":
1044
+ return [
1045
+ qe[Re.Details],
1046
+ qe[Re.Print],
1047
+ ...N.value
1048
+ ];
1049
+ case "COMPLETE":
1050
+ case "CANCEL":
1051
+ default:
1052
+ return [
1053
+ qe[Re.Details],
1054
+ qe[Re.Print],
1055
+ ...N.value
1056
+ ];
1057
+ }
1058
+ }
1059
+ function E(K) {
1060
+ return Object.values(z.enum).includes(K);
1061
+ }
1062
+ async function te(K, ve, P) {
1063
+ var A, G, Z, le, b, D, ie, ee, L;
1064
+ let x;
1065
+ try {
1066
+ x = t.resolvePO ? await t.resolvePO(ve) : ve;
1067
+ } catch (g) {
1068
+ console.error("Failed to load full purchase order for action", g), O.open({
1069
+ title: a("inventory.common.somethingWentWrong"),
1070
+ message: (g == null ? void 0 : g.message) || a("inventory.common.tryAgain"),
1071
+ type: "error"
1072
+ });
1073
+ return;
1074
+ }
1075
+ const w = wt(x);
1076
+ if (!(n != null && n.onCustomAction && await n.onCustomAction(K, w))) {
1077
+ if (K === Re.Print || K === Re.PrintCustom) {
1078
+ let g = w;
1079
+ if (g.items == null && (n != null && n.fetchFullPo)) {
1080
+ const o = await n.fetchFullPo(w);
1081
+ if (o == null) return;
1082
+ g = wt(o);
1083
+ }
1084
+ const j = (A = n == null ? void 0 : n.resolveLocation) == null ? void 0 : A.call(n, w), me = { ...(P == null ? void 0 : P.toInventoryLocation) ?? j ?? m.currentLocation };
1085
+ if (me.type === "restaurant") {
1086
+ const o = m.locationRestaurantFromCore(me.doc._id);
1087
+ o !== null && (me.doc = o);
1088
+ }
1089
+ ((G = P == null ? void 0 : P.netSuite) != null && G.refNo || (Z = g.netSuite) != null && Z.refNo) && (g.ref = [((le = P == null ? void 0 : P.netSuite) == null ? void 0 : le.refNo) || ((b = g.netSuite) == null ? void 0 : b.refNo)].filter((o) => o).join(" "));
1090
+ const ke = P ?? ((D = n == null ? void 0 : n.resolvePurchaseRequest) == null ? void 0 : D.call(n, w)), we = {
1091
+ po: g,
1092
+ currentLocation: me,
1093
+ business: c.currentBusiness.value,
1094
+ fulfilling: d === "approval",
1095
+ por: ke
1096
+ };
1097
+ if (K === Re.PrintCustom) {
1098
+ const o = ds(we);
1099
+ o && (ae.value = o.html, Se.value = o.templateName, De.value = o.isDefault, Oe.value = !0);
1100
+ } else
1101
+ pr(we);
1102
+ return;
1103
+ }
1104
+ if (K === Re.Details) {
1105
+ t.promptShowTransferDetails(w, P);
1106
+ return;
1107
+ }
1108
+ if (K === Re.Update) {
1109
+ (ie = t.promptUpdateTransferDialog) == null || ie.call(t, w);
1110
+ return;
1111
+ }
1112
+ if (K === Re.Email) {
1113
+ (ee = t.promptEmailDialog) == null || ee.call(t, w);
1114
+ return;
1115
+ }
1116
+ if (E(K)) {
1117
+ t.submitAction(x, K, (L = P == null ? void 0 : P.to) == null ? void 0 : L.dbName);
1118
+ return;
1119
+ }
1120
+ }
1121
+ }
1122
+ function se() {
1123
+ var ve;
1124
+ const K = [
1125
+ {
1126
+ accessorKey: "seqNumber",
1127
+ header: () => a("inventory.transfer.table.seqNo"),
1128
+ enableSorting: !0,
1129
+ size: 80,
1130
+ sortUndefined: "last"
1131
+ },
1132
+ {
1133
+ accessorKey: "_id",
1134
+ header: () => a("inventory.transfer.table.createdAt"),
1135
+ cell(P) {
1136
+ return lt(`${P.getValue()}`);
1137
+ },
1138
+ enableSorting: !0
1139
+ },
1140
+ {
1141
+ accessorKey: "supplier.name",
1142
+ header: () => a("inventory.transfer.table.transferFrom"),
1143
+ enableSorting: !0,
1144
+ size: 200
1145
+ },
1146
+ {
1147
+ // Bulk-view summary rows carry itemCount instead of the items array
1148
+ id: "noOfItems",
1149
+ accessorFn: (P) => {
1150
+ var x;
1151
+ return P.itemCount ?? ((x = P.items) == null ? void 0 : x.length) ?? 0;
1152
+ },
1153
+ header: () => a("inventory.transfer.table.noOfItems"),
1154
+ cell: (P) => {
1155
+ const x = P.row.original.version || "1", w = P.getValue();
1156
+ return re("div", { class: "flex items-center gap-2" }, [
1157
+ w,
1158
+ x !== "1" ? re(
1159
+ "div",
1160
+ { class: "py-3" },
1161
+ re(
1162
+ tt,
1163
+ {},
1164
+ () => re(
1165
+ "div",
1166
+ {
1167
+ class: ["fm-status-badge", "fm-status-badge-draft"].join(" ")
1168
+ },
1169
+ `v${x}`
1170
+ )
1171
+ )
1172
+ ) : null
1173
+ ]);
1174
+ },
1175
+ enableSorting: !1,
1176
+ meta: {
1177
+ width: "10rem"
1178
+ }
1179
+ },
1180
+ {
1181
+ accessorKey: "ref",
1182
+ header: () => a("inventory.transfer.table.reference"),
1183
+ enableSorting: !1,
1184
+ size: "auto"
1185
+ },
1186
+ ...(ve = c.sessionUser.value) != null && ve.role.isAdmin ? [
1187
+ {
1188
+ id: "statusForAdmin",
1189
+ header: () => re(tt, {}, () => `${a("inventory.transfer.table.status")}`),
1190
+ cell(P) {
1191
+ return P.row.original.status;
1192
+ },
1193
+ enableSorting: !0,
1194
+ size: 200
1195
+ }
1196
+ ] : [],
1197
+ {
1198
+ accessorKey: "status",
1199
+ header: () => a("inventory.transfer.table.status"),
1200
+ cell(P) {
1201
+ const x = P.getValue(), w = P.row.original, { partial: A, over: G } = w.items == null ? { partial: !!w.partialReceived, over: !!w.overReceived } : $t(vt(w)), Z = Ct(x ?? "", A, G);
1202
+ let le = a(`inventory.transfer.status.${Z}`), b = `${x ?? ""}`.toLocaleLowerCase("en-us");
1203
+ Z === ge.enum.CLOSE && (le = `${a(`inventory.transfer.status.${ge.enum.COMPLETE}`)}`), Z === "PARTIAL_RECEIVED" && b === ge.enum.PROCESSING.toLocaleLowerCase("en-us") && (b = ge.enum.RECEIVING.toLocaleLowerCase("en-us"));
1204
+ let D = null;
1205
+ const ie = r.value.find((ee) => ee.ref === P.row.original._id);
1206
+ if (ie != null && ie.milestones && ie.milestones.length > 0) {
1207
+ const ee = ie.milestones[ie.milestones.length - 1];
1208
+ if (ee.estimatedTime) {
1209
+ const L = new Date(ee.estimatedTime), g = L.getDate().toString().padStart(2, "0");
1210
+ D = `${L.toLocaleString("en-US", { month: "short" })} ${g}`;
1211
+ }
1212
+ }
1213
+ return re(
1214
+ "div",
1215
+ {
1216
+ class: "flex"
1217
+ },
1218
+ [
1219
+ re(
1220
+ "div",
1221
+ { class: "flex items-center" },
1222
+ re(
1223
+ "div",
1224
+ {
1225
+ class: [
1226
+ "fm-status-badge",
1227
+ `fm-status-badge-${b}`,
1228
+ G && "fm-status-badge-error"
1229
+ ].filter(Boolean).join(" ")
1230
+ },
1231
+ `${le}`
1232
+ )
1233
+ ),
1234
+ ...D ? [
1235
+ re(
1236
+ "div",
1237
+ {
1238
+ class: "flex items-center gap-1 ml-2"
1239
+ },
1240
+ [
1241
+ re(pt.FmIcon, {
1242
+ name: "local_shipping",
1243
+ size: "md",
1244
+ color: "neutral-gray-400"
1245
+ }),
1246
+ re(
1247
+ "span",
1248
+ { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" },
1249
+ D
1250
+ )
1251
+ ]
1252
+ )
1253
+ ] : []
1254
+ ]
1255
+ );
1256
+ },
1257
+ enableSorting: !0,
1258
+ size: 150
1259
+ },
1260
+ {
1261
+ id: "action",
1262
+ cell(P) {
1263
+ var A;
1264
+ const x = P.row.original, w = [
1265
+ ..._(x),
1266
+ ...((A = n == null ? void 0 : n.appendRowActions) == null ? void 0 : A.call(n, x)) ?? []
1267
+ ];
1268
+ return Ht(w, (G) => te(G, x));
1269
+ },
1270
+ enableSorting: !1,
1271
+ size: 40,
1272
+ meta: {
1273
+ cellClass: "",
1274
+ headerClass: ""
1275
+ }
1276
+ }
1277
+ ];
1278
+ if (u.isEnabled) {
1279
+ const P = [
1280
+ {
1281
+ id: "netsuiteTransferOrder",
1282
+ accessorFn: (x) => {
1283
+ var w;
1284
+ return (w = x.netSuite) != null && w.id ? `${x.netSuite.refNo} (${x.netSuite.id})` : "N/A";
1285
+ },
1286
+ header: () => "NetSuite Order (ID)",
1287
+ cell(x) {
1288
+ var A;
1289
+ const w = x.row.original;
1290
+ return (A = w.netSuite) != null && A.id ? `${w.netSuite.refNo} (${w.netSuite.id})` : "N/A";
1291
+ },
1292
+ enableSorting: !1,
1293
+ size: 200,
1294
+ meta: {
1295
+ cellClass: "",
1296
+ headerClass: ""
1297
+ }
1298
+ },
1299
+ {
1300
+ id: "netsuiteTransactionNumber",
1301
+ accessorFn: (x) => {
1302
+ var w, A;
1303
+ return ((A = (w = x.netSuite) == null ? void 0 : w.additionalInfo) == null ? void 0 : A.transactionnumber) ?? "N/A";
1304
+ },
1305
+ header: () => "NetSuite Transaction No.",
1306
+ cell(x) {
1307
+ var A, G;
1308
+ return ((G = (A = x.row.original.netSuite) == null ? void 0 : A.additionalInfo) == null ? void 0 : G.transactionnumber) ?? "N/A";
1309
+ },
1310
+ enableSorting: !1,
1311
+ size: 200,
1312
+ meta: {
1313
+ cellClass: "",
1314
+ headerClass: ""
1315
+ }
1316
+ },
1317
+ {
1318
+ id: "netsuiteRefNo",
1319
+ accessorFn: (x) => {
1320
+ var A, G;
1321
+ const w = (A = x.deliveryOrder) == null ? void 0 : A.filter((Z) => {
1322
+ var le;
1323
+ return (le = Z.netSuite) == null ? void 0 : le.id;
1324
+ });
1325
+ return w != null && w.length ? w.map((Z) => {
1326
+ var le, b;
1327
+ return `${((le = Z.netSuite) == null ? void 0 : le.refNo) ?? "N/A"} (${((b = Z.netSuite) == null ? void 0 : b.id) ?? "-"})`;
1328
+ }).join(", ") : (G = x.netSuite) != null && G.id ? `${x.netSuite.refNo} (${x.netSuite.id})` : "N/A";
1329
+ },
1330
+ header: () => "Netsuite ref no.",
1331
+ cell(x) {
1332
+ var G, Z;
1333
+ const w = x.row.original, A = (G = w.deliveryOrder) == null ? void 0 : G.filter((le) => {
1334
+ var b;
1335
+ return (b = le.netSuite) == null ? void 0 : b.id;
1336
+ });
1337
+ return A != null && A.length ? A.map((le) => {
1338
+ var b, D;
1339
+ return `${((b = le.netSuite) == null ? void 0 : b.refNo) ?? "N/A"} (${((D = le.netSuite) == null ? void 0 : D.id) ?? "-"})`;
1340
+ }).join(", ") : (Z = w.netSuite) != null && Z.id ? `${w.netSuite.refNo} (${w.netSuite.id})` : "N/A";
1341
+ },
1342
+ enableSorting: !1,
1343
+ size: 200,
1344
+ meta: {
1345
+ cellClass: "",
1346
+ headerClass: ""
1347
+ }
1348
+ }
1349
+ ];
1350
+ K.splice(K.length - 1, 0, ...P);
1351
+ }
1352
+ return K;
1353
+ }
1354
+ function Q() {
1355
+ var ve;
1356
+ const K = [
1357
+ {
1358
+ accessorKey: "purchaseOrder.seqNumber",
1359
+ header: () => a("inventory.transfer.table.seqNo"),
1360
+ enableSorting: !0,
1361
+ size: 80,
1362
+ sortUndefined: "last"
1363
+ },
1364
+ {
1365
+ accessorKey: "purchaseOrder._id",
1366
+ header: () => a("inventory.transfer.table.createdAt"),
1367
+ cell(P) {
1368
+ return lt(`${P.getValue()}`);
1369
+ },
1370
+ enableSorting: !0
1371
+ },
1372
+ {
1373
+ accessorKey: "to.name",
1374
+ header: () => a("inventory.transfer.table.transferTo"),
1375
+ enableSorting: !1,
1376
+ size: 200
1377
+ },
1378
+ {
1379
+ accessorKey: "purchaseOrder.items.length",
1380
+ header: () => a("inventory.transfer.table.noOfItems"),
1381
+ enableSorting: !1
1382
+ },
1383
+ {
1384
+ accessorKey: "purchaseOrder.ref",
1385
+ header: () => a("inventory.transfer.table.reference"),
1386
+ enableSorting: !1,
1387
+ size: "auto"
1388
+ },
1389
+ ...(ve = c.sessionUser.value) != null && ve.role.isAdmin ? [
1390
+ {
1391
+ id: "statusForAdmin",
1392
+ header: () => re(tt, {}, () => `${a("inventory.transfer.table.status")}`),
1393
+ cell(P) {
1394
+ return P.row.original.status;
1395
+ },
1396
+ enableSorting: !0,
1397
+ size: 200
1398
+ }
1399
+ ] : [],
1400
+ {
1401
+ accessorKey: "purchaseOrder.status",
1402
+ header: () => a("inventory.transfer.table.status"),
1403
+ cell(P) {
1404
+ const x = P.row.original, w = P.getValue();
1405
+ if (!x.purchaseOrder)
1406
+ return re(pt.FmChip, {
1407
+ label: "N/A",
1408
+ compact: !0
1409
+ });
1410
+ const A = vt(x.purchaseOrder), { partial: G, over: Z } = $t(A), le = Ct(w ?? "", G, Z);
1411
+ let b = a(`inventory.transfer.status.${le}`), D = `${w ?? ""}`.toLocaleLowerCase("en-us");
1412
+ return le === ge.enum.CLOSE && (b = `${a(`inventory.transfer.status.${ge.enum.COMPLETE}`)}`), le === "PARTIAL_RECEIVED" && D === ge.enum.PROCESSING.toLocaleLowerCase("en-us") && (D = ge.enum.RECEIVING.toLocaleLowerCase("en-us")), x.rejectedAt && (b = a("inventory.transfer.status.REJECT"), D = ge.enum.REJECT.toLocaleLowerCase("en-us")), re(
1413
+ "div",
1414
+ {
1415
+ class: "flex"
1416
+ },
1417
+ re(
1418
+ "div",
1419
+ {
1420
+ class: [
1421
+ "fm-status-badge",
1422
+ `fm-status-badge-${D}`,
1423
+ Z && "fm-status-badge-error"
1424
+ ].filter(Boolean).join(" ")
1425
+ },
1426
+ `${b}`
1427
+ )
1428
+ );
1429
+ },
1430
+ enableSorting: !0
1431
+ },
1432
+ {
1433
+ id: "action",
1434
+ cell(P) {
1435
+ const x = P.row.original, A = (x.purchaseOrder ? _(x.purchaseOrder) : []).map((G) => G.value === Re.Print ? {
1436
+ ...G,
1437
+ translationKey: "inventory.transfer.receiveRequest.details.printDeliveryOrder"
1438
+ } : G);
1439
+ return Ht(
1440
+ A,
1441
+ (G) => x.purchaseOrder ? te(G, x.purchaseOrder, x) : void 0
1442
+ );
1443
+ },
1444
+ enableSorting: !1,
1445
+ size: 40,
1446
+ meta: {
1447
+ cellClass: "",
1448
+ headerClass: ""
1449
+ }
1450
+ }
1451
+ ];
1452
+ if (u.isEnabled) {
1453
+ const P = [
1454
+ {
1455
+ id: "netsuiteTransferOrder",
1456
+ accessorFn: (x) => {
1457
+ var w;
1458
+ return (w = x.netSuite) != null && w.id ? `${x.netSuite.refNo} (${x.netSuite.id})` : "N/A";
1459
+ },
1460
+ header: () => "NetSuite Order (ID)",
1461
+ cell(x) {
1462
+ var A;
1463
+ const w = x.row.original;
1464
+ return (A = w.netSuite) != null && A.id ? `${w.netSuite.refNo} (${w.netSuite.id})` : "N/A";
1465
+ },
1466
+ enableSorting: !1,
1467
+ size: 200,
1468
+ meta: {
1469
+ cellClass: "",
1470
+ headerClass: ""
1471
+ }
1472
+ },
1473
+ {
1474
+ id: "netsuiteTransactionNumber",
1475
+ accessorFn: (x) => {
1476
+ var w, A;
1477
+ return ((A = (w = x.netSuite) == null ? void 0 : w.additionalInfo) == null ? void 0 : A.transactionnumber) ?? "N/A";
1478
+ },
1479
+ header: () => "NetSuite Transaction No.",
1480
+ cell(x) {
1481
+ var A, G;
1482
+ return ((G = (A = x.row.original.netSuite) == null ? void 0 : A.additionalInfo) == null ? void 0 : G.transactionnumber) ?? "N/A";
1483
+ },
1484
+ enableSorting: !1,
1485
+ size: 200,
1486
+ meta: {
1487
+ cellClass: "",
1488
+ headerClass: ""
1489
+ }
1490
+ },
1491
+ {
1492
+ id: "netsuiteRefNo",
1493
+ accessorFn: (x) => {
1494
+ var A, G, Z;
1495
+ const w = (G = (A = x.purchaseOrder) == null ? void 0 : A.deliveryOrder) == null ? void 0 : G.filter((le) => {
1496
+ var b;
1497
+ return (b = le.netSuite) == null ? void 0 : b.id;
1498
+ });
1499
+ return w != null && w.length ? w.map((le) => {
1500
+ var b, D;
1501
+ return `${((b = le.netSuite) == null ? void 0 : b.refNo) ?? "N/A"} (${((D = le.netSuite) == null ? void 0 : D.id) ?? "-"})`;
1502
+ }).join(", ") : (Z = x.netSuite) != null && Z.id ? `${x.netSuite.refNo} (${x.netSuite.id})` : "N/A";
1503
+ },
1504
+ header: () => "Netsuite ref no.",
1505
+ cell(x) {
1506
+ var G, Z, le;
1507
+ const w = x.row.original, A = (Z = (G = w.purchaseOrder) == null ? void 0 : G.deliveryOrder) == null ? void 0 : Z.filter((b) => {
1508
+ var D;
1509
+ return (D = b.netSuite) == null ? void 0 : D.id;
1510
+ });
1511
+ return A != null && A.length ? A.map((b) => {
1512
+ var D, ie;
1513
+ return `${((D = b.netSuite) == null ? void 0 : D.refNo) ?? "N/A"} (${((ie = b.netSuite) == null ? void 0 : ie.id) ?? "-"})`;
1514
+ }).join(", ") : (le = w.netSuite) != null && le.id ? `${w.netSuite.refNo} (${w.netSuite.id})` : "N/A";
1515
+ },
1516
+ enableSorting: !1,
1517
+ size: 200,
1518
+ meta: {
1519
+ cellClass: "",
1520
+ headerClass: ""
1521
+ }
1522
+ }
1523
+ ];
1524
+ K.splice(K.length - 2, 0, ...P);
1525
+ }
1526
+ return K;
1527
+ }
1528
+ const de = H(() => d === "receive/request" ? se() : Q()), Oe = ne(!1), ae = ne(""), Se = ne(""), De = ne(!1);
1529
+ return {
1530
+ columnDefs: de,
1531
+ showCustomPrintDialog: Oe,
1532
+ customPrintHtml: ae,
1533
+ customPrintTemplateName: Se,
1534
+ customPrintIsDefault: De
1535
+ };
1536
+ }
1537
+ const fr = { class: "flex flex-col gap-4 border border-fm-color-neutral-gray-200 fm-corner-radius-lg p-16" }, vr = { class: "flex items-center justify-between" }, yr = {
1538
+ key: 0,
1539
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-tertiary"
1540
+ }, hr = { class: "flex justify-between items-start py-1 gap-4" }, br = { class: "flex-1 min-w-0 flex flex-col gap-2" }, gr = { class: "flex flex-col gap-2 items-end w-52 shrink-0" }, _r = {
1541
+ key: 0,
1542
+ class: "border-b border-fm-color-stroke-secondary"
1543
+ }, Ft = /* @__PURE__ */ Ve({
1544
+ __name: "PriceAdjustmentEditor",
1545
+ props: {
1546
+ controller: {},
1547
+ state: {}
1548
+ },
1549
+ setup(d) {
1550
+ const t = d, r = H(() => t.state.adjustments ?? []);
1551
+ function n(a) {
1552
+ return +$e(a.dinero);
1553
+ }
1554
+ function m() {
1555
+ t.controller.addAdjustment();
1556
+ }
1557
+ function u(a, O) {
1558
+ t.controller.updateAdjustment(a, O);
1559
+ }
1560
+ function c(a, O) {
1561
+ t.controller.updateAdjustment(a, null, O);
1562
+ }
1563
+ function s(a) {
1564
+ t.controller.removeAdjustment(a);
1565
+ }
1566
+ return (a, O) => {
1567
+ const f = oe("FmButton"), R = oe("FmTextField"), N = oe("FmStepperField");
1568
+ return i(), v("div", fr, [
1569
+ e("div", vr, [
1570
+ O[0] || (O[0] = e("div", { class: "fm-typo-en-body-lg-600 text-fm-color-typo-secondary" }, "Price adjustments", -1)),
1571
+ T(f, {
1572
+ variant: "tertiary",
1573
+ label: "Add adjustment",
1574
+ "prepend-icon": "add",
1575
+ size: "md",
1576
+ onClick: m
1577
+ })
1578
+ ]),
1579
+ r.value.length === 0 ? (i(), v("div", yr, " No price adjustments ")) : V("", !0),
1580
+ (i(!0), v(Ce, null, Te(r.value, (F, _) => (i(), v("div", {
1581
+ key: F.id
1582
+ }, [
1583
+ e("div", hr, [
1584
+ e("div", br, [
1585
+ T(R, {
1586
+ "model-value": F.name,
1587
+ "onUpdate:modelValue": (B) => u(F.id, B),
1588
+ label: "Name",
1589
+ placeholder: "e.g. Freight, Discount",
1590
+ size: "md"
1591
+ }, null, 8, ["model-value", "onUpdate:modelValue"])
1592
+ ]),
1593
+ e("div", gr, [
1594
+ T(N, {
1595
+ "model-value": n(F),
1596
+ "onUpdate:modelValue": (B) => c(F.id, B),
1597
+ label: "Amount (+/-)",
1598
+ step: 0.01,
1599
+ placeholder: "0.00",
1600
+ size: "md",
1601
+ "append-text": h(Ae)()
1602
+ }, null, 8, ["model-value", "onUpdate:modelValue", "append-text"])
1603
+ ]),
1604
+ T(f, {
1605
+ variant: "tertiary",
1606
+ "prepend-icon": "delete",
1607
+ size: "md",
1608
+ class: "mt-6",
1609
+ onClick: (B) => s(F.id)
1610
+ }, null, 8, ["onClick"])
1611
+ ]),
1612
+ _ < r.value.length - 1 ? (i(), v("div", _r)) : V("", !0)
1613
+ ]))), 128))
1614
+ ]);
1615
+ };
1616
+ }
1617
+ });
1618
+ function It(d) {
1619
+ const t = dt(
1620
+ Qt({
1621
+ currency: d.currency,
1622
+ adjustments: d.adjustments ?? []
1623
+ })
1624
+ ), r = dt(t.value.state());
1625
+ function n(c) {
1626
+ const s = () => {
1627
+ r.value = c.state();
1628
+ };
1629
+ return c.addListener(s), () => c.removeListener(s);
1630
+ }
1631
+ let m = n(t.value);
1632
+ function u(c) {
1633
+ m(), t.value = Qt({
1634
+ currency: d.currency,
1635
+ adjustments: c ?? []
1636
+ }), m = n(t.value), r.value = t.value.state();
1637
+ }
1638
+ return rs(() => m()), { controller: t, state: r, reset: u };
1639
+ }
1640
+ const Sr = { class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg p-16" }, kr = { class: "flex flex-col gap-8" }, Or = { class: "flex w-full justify-end gap-16" }, xr = /* @__PURE__ */ Ve({
1641
+ __name: "FulfillmentForm",
1642
+ props: {
1643
+ purchaseOrder: {},
1644
+ confirm: { type: Function }
1645
+ },
1646
+ emits: ["update:show"],
1647
+ setup(d, { emit: t }) {
1648
+ const r = d, n = As({
1649
+ id: "",
1650
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1651
+ items: []
1652
+ }), m = ne(), u = t, c = (a) => a != null && a !== "";
1653
+ os(() => {
1654
+ r.purchaseOrder && (n.items = r.purchaseOrder.items.map((a) => ({
1655
+ id: a.id,
1656
+ sku: a.sku,
1657
+ measurement: a.measurement,
1658
+ amount: a.quantity ?? { amount: 1, precision: 0 }
1659
+ })));
1660
+ });
1661
+ const s = H(() => n.items.length <= 10);
1662
+ return (a, O) => {
1663
+ const f = oe("FmTable"), R = oe("FmButton"), N = oe("FmForm");
1664
+ return i(), he(N, {
1665
+ ref_key: "formRef",
1666
+ ref: m,
1667
+ class: "bg-white flex flex-col gap-32 rounded-3xl p-24 w-[800px]",
1668
+ onValidationFailed: console.log,
1669
+ onValidationSuccess: O[1] || (O[1] = () => r.confirm(n))
1670
+ }, {
1671
+ default: ce(() => [
1672
+ O[2] || (O[2] = e("div", { class: "fm-typo-en-title-sm-600" }, "Confirm the transfer amount", -1)),
1673
+ e("div", Sr, [
1674
+ e("div", kr, [
1675
+ T(f, {
1676
+ "column-defs": [
1677
+ {
1678
+ header: "Code",
1679
+ cell: (F) => {
1680
+ const _ = r.purchaseOrder.items.find((B) => c(F.row.original.id) ? B.id === F.row.original.id : B.sku._id === F.row.original.sku._id);
1681
+ return re(
1682
+ h(pt).FmTooltip,
1683
+ {
1684
+ content: _.code,
1685
+ placement: "top",
1686
+ variant: "plain",
1687
+ zIndex: 50
1688
+ },
1689
+ re(
1690
+ "span",
1691
+ {
1692
+ class: "flex-auto line-clamp-2 text-ellipsis break-all"
1693
+ },
1694
+ _.code
1695
+ )
1696
+ );
1697
+ }
1698
+ },
1699
+ {
1700
+ header: "Name",
1701
+ cell: (F) => {
1702
+ const _ = r.purchaseOrder.items.find((B) => c(F.row.original.id) ? B.id === F.row.original.id : B.sku._id === F.row.original.sku._id);
1703
+ return re(
1704
+ h(pt).FmTooltip,
1705
+ {
1706
+ content: _.name,
1707
+ placement: "top",
1708
+ variant: "plain",
1709
+ zIndex: 50
1710
+ },
1711
+ re(
1712
+ "span",
1713
+ {
1714
+ class: "flex-auto line-clamp-2 text-ellipsis break-all"
1715
+ },
1716
+ _.name
1717
+ )
1718
+ );
1719
+ }
1720
+ },
1721
+ {
1722
+ header: "Amount",
1723
+ cell: (F) => {
1724
+ const _ = F.row.original, B = r.purchaseOrder.items.find((te) => c(_.id) ? te.id === _.id : te.sku._id === _.sku._id), E = _.amount ?? {
1725
+ amount: 1,
1726
+ precision: 0
1727
+ };
1728
+ return re(Gs, {
1729
+ style: {
1730
+ flex: "1 1 0%"
1731
+ },
1732
+ modelValue: {
1733
+ amount: E,
1734
+ measurement: _.measurement ?? null
1735
+ },
1736
+ key: c(_.id) ? _.id : _.sku._id,
1737
+ unit: _.sku.unit,
1738
+ "onUpdate:modelValue": (te) => {
1739
+ if (!te) return;
1740
+ const se = n.items.find((Q) => c(_.id) ? Q.id === _.id : Q.sku._id === _.sku._id);
1741
+ se && (se.amount = te.amount);
1742
+ },
1743
+ disableUnit: !0,
1744
+ rules: [
1745
+ h(Ws)(
1746
+ +h($e)({ amount: 0, precision: 0 })
1747
+ ),
1748
+ h(Qs)(+h($e)(B.quantity))
1749
+ ],
1750
+ applyDefaultRules: !0
1751
+ });
1752
+ }
1753
+ }
1754
+ ],
1755
+ "row-data": n.items,
1756
+ "hide-footer": s.value
1757
+ }, null, 8, ["column-defs", "row-data", "hide-footer"])
1758
+ ])
1759
+ ]),
1760
+ e("div", Or, [
1761
+ T(R, {
1762
+ class: "px-16",
1763
+ label: "Confirm",
1764
+ size: "md",
1765
+ variant: "primary",
1766
+ type: "submit"
1767
+ }),
1768
+ T(R, {
1769
+ class: "px-16",
1770
+ label: "Cancel",
1771
+ size: "md",
1772
+ variant: "secondary",
1773
+ onClick: O[0] || (O[0] = () => u("update:show", !1))
1774
+ })
1775
+ ])
1776
+ ]),
1777
+ _: 1
1778
+ }, 8, ["onValidationFailed"]);
1779
+ };
1780
+ }
1781
+ }), nt = {
1782
+ submitRequest: {
1783
+ translationKey: "inventory.transfer.receiveRequest.actions.submitRequest",
1784
+ color: "primary",
1785
+ buttonVariant: je.Primary
1786
+ },
1787
+ confirmDraft: {
1788
+ translationKey: "inventory.transfer.receiveRequest.actions.confirmDraft",
1789
+ color: "primary",
1790
+ buttonVariant: je.Primary
1791
+ },
1792
+ cancelDraft: {
1793
+ translationKey: "inventory.transfer.receiveRequest.actions.cancelDraft",
1794
+ color: "system-error-300",
1795
+ buttonVariant: je.Destructive
1796
+ },
1797
+ approveDraft: {
1798
+ translationKey: "inventory.transfer.receiveRequest.actions.approveDraft",
1799
+ color: "primary",
1800
+ buttonVariant: je.Primary
1801
+ },
1802
+ rejectDraft: {
1803
+ translationKey: "inventory.transfer.receiveRequest.actions.rejectDraft",
1804
+ color: "system-error-300",
1805
+ buttonVariant: je.Destructive
1806
+ },
1807
+ approveRequest: {
1808
+ translationKey: "inventory.transfer.receiveRequest.actions.approveRequest",
1809
+ color: "primary",
1810
+ buttonVariant: je.Primary
1811
+ },
1812
+ processRequest: {
1813
+ translationKey: "inventory.transfer.receiveRequest.actions.processRequest",
1814
+ color: "primary",
1815
+ buttonVariant: je.Primary
1816
+ },
1817
+ receiveStock: {
1818
+ translationKey: "inventory.transfer.receiveRequest.actions.receiveStock",
1819
+ color: "primary",
1820
+ buttonVariant: je.Primary,
1821
+ available: !1
1822
+ },
1823
+ completeReceive: {
1824
+ translationKey: "inventory.transfer.receiveRequest.actions.completeReceive",
1825
+ color: "primary",
1826
+ buttonVariant: je.Plain
1827
+ },
1828
+ rejectRequest: {
1829
+ translationKey: "inventory.transfer.receiveRequest.actions.rejectRequest",
1830
+ color: "system-error-300",
1831
+ buttonVariant: je.Destructive
1832
+ },
1833
+ closeRequest: {
1834
+ translationKey: "inventory.transfer.receiveRequest.actions.closeRequest",
1835
+ color: "system-error-300",
1836
+ buttonVariant: je.Destructive,
1837
+ available: !1
1838
+ },
1839
+ returnStock: {
1840
+ translationKey: "inventory.transfer.receiveRequest.actions.returnStock",
1841
+ color: "primary",
1842
+ buttonVariant: je.Primary,
1843
+ available: !1
1844
+ }
1845
+ }, wr = { class: "flex flex-row-reverse" }, $r = /* @__PURE__ */ Ve({
1846
+ __name: "NetSuiteSync",
1847
+ props: {
1848
+ poRequest: {},
1849
+ purchaseOrder: {},
1850
+ isTransferBetweenOutlets: { type: Boolean },
1851
+ scope: {}
1852
+ },
1853
+ setup(d) {
1854
+ const t = d, r = _t(), n = Je(), m = gt(), u = ne(!1);
1855
+ H(() => {
1856
+ var f, R, N, F;
1857
+ let s = !0;
1858
+ r.isEnabled || (s = !1);
1859
+ const a = t.purchaseOrder, O = t.poRequest;
1860
+ return a && ((f = a == null ? void 0 : a.supplier) != null && f.internal ? (!O && a.status == ge.enum.DRAFT && (s = !1), O && !((R = O == null ? void 0 : O.netSuite) != null && R.id) && (s = !1), t.isTransferBetweenOutlets && (s = !1)) : ((a == null ? void 0 : a.status) !== ge.enum.REQUESTING && a.supplier.internal && (s = !1), !O && !((N = a == null ? void 0 : a.netSuite) != null && N.id) && (s = !1), !O && ((F = a == null ? void 0 : a.netSuite) != null && F.id) && (a == null ? void 0 : a.status) == ge.enum.REQUESTING && (s = !1))), s;
1861
+ });
1862
+ async function c() {
1863
+ u.value || m.open({
1864
+ title: "Sync with NetSuite",
1865
+ contentComponent: re("div", [
1866
+ re("p", "Are you sure you want to sync now?"),
1867
+ re("br"),
1868
+ re(
1869
+ "p",
1870
+ { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" },
1871
+ "Please wait a moment before syncing manually to avoid unnecessary actions."
1872
+ )
1873
+ ]),
1874
+ primaryActions: {
1875
+ text: "Sync",
1876
+ close: !0,
1877
+ variant: "destructive"
1878
+ },
1879
+ secondaryActions: { text: "Not now", close: !0 }
1880
+ }).onPrimary(async () => {
1881
+ var s, a, O, f, R, N, F;
1882
+ try {
1883
+ u.value = !0;
1884
+ const _ = ((s = t.purchaseOrder) == null ? void 0 : s._id) || ((a = t.poRequest) == null ? void 0 : a.purchaseOrderId) || "", B = (O = t.poRequest) == null ? void 0 : O.to.dbName;
1885
+ await r.syncPurchaseOrder({
1886
+ purchaseOrderId: _,
1887
+ locationId: t.scope === "approval" ? B : void 0,
1888
+ netsuiteId: ((R = (f = t.purchaseOrder) == null ? void 0 : f.netSuite) == null ? void 0 : R.id) || ((F = (N = t.poRequest) == null ? void 0 : N.netSuite) == null ? void 0 : F.id)
1889
+ }), n.open({
1890
+ title: "Sync with NetSuite",
1891
+ message: "Requested to sync with NetSuite. Please wait a moment.",
1892
+ type: "success"
1893
+ }), await new Promise((E) => setTimeout(E, 5e3)), u.value = !1;
1894
+ } catch (_) {
1895
+ console.log("Failed to sync with NetSuite", _), n.open({
1896
+ title: "Error",
1897
+ message: "Failed to sync with NetSuite",
1898
+ type: "error"
1899
+ }), u.value = !1;
1900
+ }
1901
+ });
1902
+ }
1903
+ return (s, a) => {
1904
+ const O = oe("FmButton");
1905
+ return i(), v("div", wr, [
1906
+ T(O, {
1907
+ "prepend-icon": "sync",
1908
+ variant: "secondary",
1909
+ label: "Sync",
1910
+ loading: u.value,
1911
+ onClick: c,
1912
+ "text-color": "primary",
1913
+ "bg-color": "transparent",
1914
+ "border-color": "primary"
1915
+ }, null, 8, ["loading"])
1916
+ ]);
1917
+ };
1918
+ }
1919
+ }), Cr = {
1920
+ key: 0,
1921
+ class: "flex flex-col gap-8"
1922
+ }, Ar = { class: "flex flex-col gap-4" }, Dr = { class: "fm-typo-en-body-lg-600" }, Rr = {
1923
+ key: 0,
1924
+ class: "flex flex-col gap-4"
1925
+ }, Nr = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Pr = { class: "fm-typo-en-body-lg-600" }, Fr = { key: 0 }, Ir = { key: 1 }, Tr = {
1926
+ key: 1,
1927
+ class: "flex flex-col gap-4"
1928
+ }, Er = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, qr = { class: "fm-typo-en-body-lg-600" }, Vr = { key: 0 }, Lr = { key: 1 }, jr = {
1929
+ key: 2,
1930
+ class: "flex flex-col gap-4"
1931
+ }, Ur = { class: "fm-typo-en-body-lg-600" }, Mr = {
1932
+ key: 3,
1933
+ class: "flex flex-col gap-4"
1934
+ }, Br = { class: "fm-typo-en-body-lg-600" }, zr = /* @__PURE__ */ Ve({
1935
+ __name: "NetSuiteInfo",
1936
+ props: {
1937
+ transferType: {},
1938
+ transferToDbName: {},
1939
+ poRequest: {},
1940
+ purchaseOrder: {},
1941
+ isTransferBetweenOutlets: { type: Boolean },
1942
+ scope: {}
1943
+ },
1944
+ setup(d) {
1945
+ const t = d, r = _t(), n = Ze(), m = ne(t.poRequest);
1946
+ os(async () => {
1947
+ var a;
1948
+ if (!t.poRequest && ((a = t.purchaseOrder) != null && a._id)) {
1949
+ const O = await n.getLatestPurchaseOrderRequest(t.purchaseOrder._id);
1950
+ m.value = O;
1951
+ }
1952
+ });
1953
+ const u = H(
1954
+ () => {
1955
+ var a, O, f, R, N, F;
1956
+ return r.getSubsidiaryFullName(
1957
+ ((f = (O = (a = t.purchaseOrder) == null ? void 0 : a.netSuite) == null ? void 0 : O.subsidiary) == null ? void 0 : f.id) || ((F = (N = (R = t.poRequest) == null ? void 0 : R.netSuite) == null ? void 0 : N.subsidiary) == null ? void 0 : F.id)
1958
+ ).fullName;
1959
+ }
1960
+ ), c = H(() => {
1961
+ var a, O, f, R, N, F, _, B, E, te, se, Q;
1962
+ return (f = (O = (a = t.purchaseOrder) == null ? void 0 : a.netSuite) == null ? void 0 : O.additionalInfo) != null && f.transactionnumber ? (F = (N = (R = t.purchaseOrder) == null ? void 0 : R.netSuite) == null ? void 0 : N.additionalInfo) == null ? void 0 : F.transactionnumber : (E = (B = (_ = m.value) == null ? void 0 : _.netSuite) == null ? void 0 : B.additionalInfo) != null && E.transactionnumber ? (Q = (se = (te = m.value) == null ? void 0 : te.netSuite) == null ? void 0 : se.additionalInfo) == null ? void 0 : Q.transactionnumber : null;
1963
+ }), s = H(() => {
1964
+ var a, O, f, R, N, F;
1965
+ return (O = (a = t.purchaseOrder) == null ? void 0 : a.deliveryFullfillment) != null && O.length && ((R = (f = t.purchaseOrder) == null ? void 0 : f.deliveryFullfillment) == null ? void 0 : R.length) > 0 ? (F = (N = t.purchaseOrder) == null ? void 0 : N.deliveryFullfillment) == null ? void 0 : F.map((_) => {
1966
+ var B;
1967
+ return (B = _.netSuite) == null ? void 0 : B.refNo;
1968
+ }).join(", ") : "N/A";
1969
+ });
1970
+ return (a, O) => {
1971
+ var f, R, N, F, _, B, E, te, se, Q, de, Oe, ae, Se, De, K;
1972
+ return h(r).isEnabled ? (i(), v("div", Cr, [
1973
+ e("div", Ar, [
1974
+ O[0] || (O[0] = e("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, "NetSuite subsidiary", -1)),
1975
+ e("div", Dr, k(u.value || "N/A"), 1)
1976
+ ]),
1977
+ !a.isTransferBetweenOutlets && a.scope === h(At).RECEIVE_REQUEST ? (i(), v("div", Rr, [
1978
+ e("div", Nr, " NetSuite " + k((R = (f = a.purchaseOrder) == null ? void 0 : f.netSuite) != null && R.recordType ? h(as)((F = (N = a.purchaseOrder) == null ? void 0 : N.netSuite) == null ? void 0 : F.recordType) : a.transferType === h(at).enum.purchase ? "Purchase Order" : "Transfer Order") + " (ID) ", 1),
1979
+ e("div", Pr, [
1980
+ (B = (_ = a.purchaseOrder) == null ? void 0 : _.netSuite) != null && B.id ? (i(), v("span", Fr, k((te = (E = a.purchaseOrder) == null ? void 0 : E.netSuite) == null ? void 0 : te.refNo) + " (" + k((Q = (se = a.purchaseOrder) == null ? void 0 : se.netSuite) == null ? void 0 : Q.id) + ") ", 1)) : (i(), v("span", Ir, "N/A"))
1981
+ ])
1982
+ ])) : V("", !0),
1983
+ !a.isTransferBetweenOutlets && m.value || a.scope === h(At).APPROVAL ? (i(), v("div", Tr, [
1984
+ e("div", Er, " (Request) NetSuite " + k(a.transferType === h(at).enum.purchase ? "Purchase Order" : "Transfer Order") + " (ID) ", 1),
1985
+ e("div", qr, [
1986
+ (Oe = (de = m.value) == null ? void 0 : de.netSuite) != null && Oe.id ? (i(), v("span", Vr, k((Se = (ae = m.value) == null ? void 0 : ae.netSuite) == null ? void 0 : Se.refNo) + " (" + k((K = (De = m.value) == null ? void 0 : De.netSuite) == null ? void 0 : K.id) + ") ", 1)) : (i(), v("span", Lr, "N/A"))
1987
+ ])
1988
+ ])) : V("", !0),
1989
+ c.value ? (i(), v("div", jr, [
1990
+ O[1] || (O[1] = e("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, " NetSuite Transaction Number ", -1)),
1991
+ e("div", Ur, k(c.value), 1)
1992
+ ])) : V("", !0),
1993
+ h(r).isEnabled && a.transferType === h(at).enum.transfer && !a.isTransferBetweenOutlets ? (i(), v("div", Mr, [
1994
+ O[2] || (O[2] = e("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, " NetSuite fulfillment IDs ", -1)),
1995
+ e("div", Br, k(s.value), 1)
1996
+ ])) : V("", !0)
1997
+ ])) : V("", !0);
1998
+ };
1999
+ }
2000
+ }), Kr = { class: "flex flex-row-reverse" }, Hr = /* @__PURE__ */ Ve({
2001
+ __name: "NetSuiteLog",
2002
+ props: {
2003
+ netsuiteId: {},
2004
+ purchaseOrderId: {}
2005
+ },
2006
+ setup(d) {
2007
+ const t = Je(), r = Pt();
2008
+ async function n(m, u) {
2009
+ const c = [];
2010
+ if (m && c.push(`body.message:*${m}*`), u) {
2011
+ const f = u.replace(/:/g, "\\:");
2012
+ c.push(`${f}`);
2013
+ }
2014
+ if (c.length === 0) {
2015
+ t.open({
2016
+ message: "Cannot open logs without valid filters.",
2017
+ type: "error"
2018
+ });
2019
+ return;
2020
+ }
2021
+ const a = `attributes.pod:netsuite* AND (${c.join(" OR ")})`, { url: O } = await r.getSyncLogs(a);
2022
+ t.open(
2023
+ {
2024
+ message: "Opening NetSuite logs...",
2025
+ type: "info"
2026
+ },
2027
+ 800
2028
+ ), await new Promise((f) => setTimeout(f, 800)), window.open(O, "_blank");
2029
+ }
2030
+ return (m, u) => {
2031
+ const c = oe("FmButton");
2032
+ return i(), v("div", Kr, [
2033
+ T(c, {
2034
+ "prepend-icon": "history",
2035
+ variant: "secondary",
2036
+ label: "Logs",
2037
+ onClick: u[0] || (u[0] = (s) => n(m.netsuiteId, m.purchaseOrderId)),
2038
+ "text-color": "primary",
2039
+ "bg-color": "transparent",
2040
+ "border-color": "primary"
2041
+ })
2042
+ ]);
2043
+ };
2044
+ }
2045
+ }), Gr = { class: "flex flex-row-reverse" }, Wr = { key: 0 }, Qr = { key: 1 }, Yr = { class: "mb-6" }, Jr = { class: "fm-typo-en-body-md-400" }, Xr = { key: 0 }, Zr = { key: 1 }, eo = {
2046
+ key: 0,
2047
+ class: "flex"
2048
+ }, to = {
2049
+ key: 1,
2050
+ class: "border-t pt-6"
2051
+ }, so = { class: "fm-typo-en-body-lg-600 mb-4 flex items-center gap-2" }, ro = { class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg overflow-y-auto" }, oo = { class: "w-full" }, no = {
2052
+ class: "p-3 fm-typo-en-body-sm-600",
2053
+ style: { "min-width": "130px" }
2054
+ }, ao = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, lo = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, io = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, uo = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, co = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, mo = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, po = { class: "p-3 fm-typo-en-body-sm-600" }, fo = { key: 2 }, vo = { key: 1 }, yo = /* @__PURE__ */ Ve({
2055
+ __name: "NetSuiteLatestInfo",
2056
+ props: {
2057
+ netsuiteId: {},
2058
+ purchaseOrderId: {}
2059
+ },
2060
+ setup(d) {
2061
+ const t = d, r = Pt(), n = ne(!1), m = ze(), u = ne(!0), c = ne(!1), s = ne(!1), a = ne(!1), O = ne(null), f = ne([]);
2062
+ async function R() {
2063
+ if (!O.value) {
2064
+ n.value = !0;
2065
+ try {
2066
+ u.value = !0;
2067
+ const B = await r.getMoreInfo(
2068
+ m.currentLocation.dbName,
2069
+ t.purchaseOrderId
2070
+ );
2071
+ O.value = B, c.value = !1;
2072
+ } catch {
2073
+ c.value = !0;
2074
+ } finally {
2075
+ u.value = !1;
2076
+ }
2077
+ await N();
2078
+ }
2079
+ }
2080
+ async function N() {
2081
+ if (!(f.value.length > 0))
2082
+ try {
2083
+ s.value = !0;
2084
+ const B = await r.getChangeLogs(t.netsuiteId);
2085
+ f.value = B, a.value = !1;
2086
+ } catch {
2087
+ a.value = !0;
2088
+ } finally {
2089
+ s.value = !1;
2090
+ }
2091
+ }
2092
+ function F(B) {
2093
+ switch (B) {
2094
+ case Me.Create:
2095
+ return "text-green-600 bg-green-100";
2096
+ case Me.Set:
2097
+ return "text-blue-600 bg-blue-100";
2098
+ case Me.Change:
2099
+ return "text-yellow-600 bg-yellow-100";
2100
+ case Me.Unset:
2101
+ return "text-red-600 bg-red-100";
2102
+ default:
2103
+ return "text-gray-600 bg-gray-100";
2104
+ }
2105
+ }
2106
+ function _(B) {
2107
+ return new Date(B).toLocaleDateString("en-US", {
2108
+ year: "numeric",
2109
+ month: "short",
2110
+ day: "numeric",
2111
+ hour: "2-digit",
2112
+ minute: "2-digit"
2113
+ });
2114
+ }
2115
+ return (B, E) => {
2116
+ const te = oe("FmButton"), se = oe("FmLabel"), Q = oe("FmCircularProgress"), de = oe("FmIcon"), Oe = oe("FmDialog");
2117
+ return i(), v("div", Gr, [
2118
+ T(Oe, {
2119
+ modelValue: n.value,
2120
+ "onUpdate:modelValue": E[2] || (E[2] = (ae) => n.value = ae),
2121
+ overlay: !0,
2122
+ "max-width": 800
2123
+ }, {
2124
+ "dialog-button": ce(() => [
2125
+ T(te, {
2126
+ "prepend-icon": "info",
2127
+ variant: "secondary",
2128
+ label: "Latest Info",
2129
+ onClick: E[0] || (E[0] = (ae) => R()),
2130
+ "text-color": "primary",
2131
+ "bg-color": "transparent",
2132
+ "border-color": "primary"
2133
+ })
2134
+ ]),
2135
+ "dialog-header": ce(() => E[3] || (E[3] = [
2136
+ e("div", null, "NetSuite latest info", -1)
2137
+ ])),
2138
+ default: ce(() => [
2139
+ u.value ? (i(), v("div", Wr, "Loading...")) : (i(), v("div", Qr, [
2140
+ c.value ? (i(), v("p", vo, "Something went wrong.")) : (i(), v(Ce, { key: 0 }, [
2141
+ e("div", Yr, [
2142
+ E[4] || (E[4] = e("h3", { class: "fm-typo-en-body-lg-600 mb-4" }, "NetSuite Order Details", -1)),
2143
+ (i(!0), v(Ce, null, Te(O.value, (ae, Se) => (i(), v("div", {
2144
+ key: Se,
2145
+ class: "mb-2"
2146
+ }, [
2147
+ e("div", null, [
2148
+ T(se, {
2149
+ label: h(Rt)(Se)
2150
+ }, null, 8, ["label"]),
2151
+ e("div", Jr, [
2152
+ Array.isArray(ae) ? (i(), v("span", Xr, k(ae.length > 0 ? ae.join(", ") : "N/A"), 1)) : (i(), v("span", Zr, k(ae), 1))
2153
+ ])
2154
+ ])
2155
+ ]))), 128))
2156
+ ]),
2157
+ s.value ? (i(), v("div", eo, [
2158
+ E[5] || (E[5] = e("span", null, "Change Log Loading...", -1)),
2159
+ T(Q, { size: "md" })
2160
+ ])) : V("", !0),
2161
+ !s.value && f.value.length > 0 ? (i(), v("div", to, [
2162
+ e("h3", so, [
2163
+ T(de, {
2164
+ name: "error",
2165
+ color: "#ff9500",
2166
+ size: "sm"
2167
+ }),
2168
+ E[6] || (E[6] = Ge(" Change Logs "))
2169
+ ]),
2170
+ e("div", ro, [
2171
+ e("table", oo, [
2172
+ E[7] || (E[7] = e("thead", { class: "bg-fm-color-neutral-gray-50" }, [
2173
+ e("tr", { class: "border-b border-fm-color-neutral-gray-200" }, [
2174
+ e("th", {
2175
+ class: "text-left p-3 fm-typo-en-body-md-600",
2176
+ style: { "min-width": "130px" }
2177
+ }, " Date "),
2178
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Role"),
2179
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Name"),
2180
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Context"),
2181
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Type"),
2182
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Line ID"),
2183
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Field"),
2184
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Old Value"),
2185
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "New Value")
2186
+ ])
2187
+ ], -1)),
2188
+ e("tbody", null, [
2189
+ (i(!0), v(Ce, null, Te(f.value, (ae, Se) => (i(), v("tr", {
2190
+ key: Se,
2191
+ class: "border-b border-fm-color-neutral-gray-200 last:border-b-0"
2192
+ }, [
2193
+ e("td", no, k(_(ae._dateiso8601)), 1),
2194
+ e("td", ao, k(ae._rolename), 1),
2195
+ e("td", lo, k(ae._employeename), 1),
2196
+ e("td", io, k(ae._contextname), 1),
2197
+ e("td", {
2198
+ class: We(`p-3 fm-typo-en-body-sm-600 ${F(Number(ae.type) - 1)}`)
2199
+ }, k(h(Me)[Number(ae.type) - 1]), 3),
2200
+ e("td", uo, k(ae.lineid || ""), 1),
2201
+ e("td", co, k(ae._fieldname), 1),
2202
+ e("td", mo, k(ae.oldvalue || ""), 1),
2203
+ e("td", po, k(ae.newvalue || ""), 1)
2204
+ ]))), 128))
2205
+ ])
2206
+ ])
2207
+ ])
2208
+ ])) : (i(), v("div", fo, E[8] || (E[8] = [
2209
+ e("p", null, "No change logs available.", -1)
2210
+ ])))
2211
+ ], 64))
2212
+ ]))
2213
+ ]),
2214
+ "dialog-footer": ce(() => [
2215
+ T(te, {
2216
+ class: "ml-auto sm:w-full xs:w-full",
2217
+ label: "Close",
2218
+ size: "md",
2219
+ variant: "primary",
2220
+ onClick: E[1] || (E[1] = (ae) => n.value = !1)
2221
+ })
2222
+ ]),
2223
+ _: 1
2224
+ }, 8, ["modelValue"])
2225
+ ]);
2226
+ };
2227
+ }
2228
+ }), ho = {
2229
+ key: 0,
2230
+ class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg p-16 flex flex-col gap-8"
2231
+ }, bo = { class: "flex gap-8 items-center" }, go = { class: "ml-auto" }, _o = { class: "flex gap-3" }, So = /* @__PURE__ */ Ve({
2232
+ __name: "NetSuitePanel",
2233
+ props: {
2234
+ poRequest: {},
2235
+ purchaseOrder: {},
2236
+ transferType: {},
2237
+ transferToDbName: {},
2238
+ scope: {}
2239
+ },
2240
+ setup(d) {
2241
+ const t = d, r = Js(), n = H(() => r.isNetSuiteEnabled);
2242
+ return (m, u) => {
2243
+ var s, a;
2244
+ const c = oe("FmMenuDivider");
2245
+ return n.value ? (i(), v("div", ho, [
2246
+ e("div", bo, [
2247
+ u[0] || (u[0] = e("span", { class: "flex-1 fm-typo-en-body-lg-600" }, "NetSuite Info", -1)),
2248
+ e("div", go, [
2249
+ e("div", _o, [
2250
+ (a = (s = t.purchaseOrder) == null ? void 0 : s.netSuite) != null && a.id ? (i(), he(tt, { key: 0 }, {
2251
+ default: ce(() => {
2252
+ var O, f, R;
2253
+ return [
2254
+ T(yo, {
2255
+ "netsuite-id": (f = (O = m.purchaseOrder) == null ? void 0 : O.netSuite) == null ? void 0 : f.id,
2256
+ "purchase-order-id": (R = m.purchaseOrder) == null ? void 0 : R._id
2257
+ }, null, 8, ["netsuite-id", "purchase-order-id"])
2258
+ ];
2259
+ }),
2260
+ _: 1
2261
+ })) : V("", !0),
2262
+ T(tt, null, {
2263
+ default: ce(() => {
2264
+ var O, f, R;
2265
+ return [
2266
+ T(Hr, {
2267
+ "netsuite-id": (f = (O = m.purchaseOrder) == null ? void 0 : O.netSuite) == null ? void 0 : f.id,
2268
+ "purchase-order-id": (R = m.purchaseOrder) == null ? void 0 : R._id
2269
+ }, null, 8, ["netsuite-id", "purchase-order-id"])
2270
+ ];
2271
+ }),
2272
+ _: 1
2273
+ }),
2274
+ T($r, {
2275
+ "po-request": m.poRequest,
2276
+ "purchase-order": m.purchaseOrder,
2277
+ "is-transfer-between-outlets": !n.value,
2278
+ scope: m.scope
2279
+ }, null, 8, ["po-request", "purchase-order", "is-transfer-between-outlets", "scope"])
2280
+ ])
2281
+ ])
2282
+ ]),
2283
+ T(c),
2284
+ T(zr, {
2285
+ "po-request": m.poRequest,
2286
+ "purchase-order": m.purchaseOrder,
2287
+ "transfer-type": m.transferType,
2288
+ "transfer-to-db-name": m.transferToDbName,
2289
+ "is-transfer-between-outlets": !n.value,
2290
+ scope: m.scope
2291
+ }, null, 8, ["po-request", "purchase-order", "transfer-type", "transfer-to-db-name", "is-transfer-between-outlets", "scope"])
2292
+ ])) : V("", !0);
2293
+ };
2294
+ }
2295
+ }), ko = ["open"], Oo = { class: "fm-typo-en-body-sm-600 cursor-pointer select-none" }, ts = /* @__PURE__ */ Ve({
2296
+ __name: "FmAdminCollapsiblePanel",
2297
+ props: {
2298
+ title: { default: "Admin" },
2299
+ open: { type: Boolean, default: !1 },
2300
+ selectable: { type: Boolean, default: !0 },
2301
+ class: { default: void 0 },
2302
+ contentClass: { default: void 0 }
2303
+ },
2304
+ setup(d) {
2305
+ const t = d;
2306
+ return (r, n) => (i(), he(tt, {
2307
+ selectable: t.selectable,
2308
+ class: We(t.class)
2309
+ }, {
2310
+ default: ce(() => [
2311
+ e("details", {
2312
+ open: t.open,
2313
+ class: "w-full"
2314
+ }, [
2315
+ e("summary", Oo, k(t.title), 1),
2316
+ e("div", {
2317
+ class: We(["mt-4 flex flex-col gap-2", t.contentClass])
2318
+ }, [
2319
+ Ds(r.$slots, "default")
2320
+ ], 2)
2321
+ ], 8, ko)
2322
+ ]),
2323
+ _: 3
2324
+ }, 8, ["selectable", "class"]));
2325
+ }
2326
+ });
2327
+ function _s(d) {
2328
+ if (!(d != null && d.itemsAtSubmission)) return [];
2329
+ const t = new Set(d.itemsAtSubmission.map((m) => m.sku._id)), r = /* @__PURE__ */ new Set(), n = [];
2330
+ for (const m of d.items) {
2331
+ const u = m.sku._id;
2332
+ t.has(u) || r.has(u) || (r.add(u), n.push(m));
2333
+ }
2334
+ return n;
2335
+ }
2336
+ function Ss(d, t) {
2337
+ var m;
2338
+ if (!d || t.length === 0) return {};
2339
+ const r = new Set(t.map((u) => u.sku._id)), n = {};
2340
+ for (const u of d.deliveryOrder ?? [])
2341
+ for (const c of u.received ?? []) {
2342
+ const s = c.sku._id;
2343
+ s && r.has(s) && (n[s] = (n[s] ?? 0) + (((m = c.amount) == null ? void 0 : m.amount) ?? 0));
2344
+ }
2345
+ return t.reduce(
2346
+ (u, c) => {
2347
+ var R, N;
2348
+ const s = c.sku._id ?? "", a = ((R = c.quantity) == null ? void 0 : R.amount) ?? 0, O = n[s] ?? 0, f = ((N = c.quantity) == null ? void 0 : N.precision) ?? 0;
2349
+ return u[s] = {
2350
+ key: s,
2351
+ total: { amount: a, precision: f },
2352
+ received: { amount: O, precision: f },
2353
+ remaining: { amount: a - O, precision: f }
2354
+ }, u;
2355
+ },
2356
+ {}
2357
+ );
2358
+ }
2359
+ const xo = { class: "flex flex-col gap-3" }, wo = { class: "flex flex-col gap-4" }, $o = { class: "flex flex-col gap-4 fm-typo-en-body-lg-600" }, Co = { class: "flex flex-col gap-4" }, Ao = { class: "flex justify-between items-start py-1 gap-4" }, Do = { class: "flex flex-col flex-1 min-w-0" }, Ro = { class: "fm-typo-en-body-lg-600 truncate" }, No = { class: "fm-typo-en-body-md-400 truncate" }, Po = { class: "flex flex-col gap-2 items-end w-52 shrink-0" }, Fo = {
2360
+ key: 0,
2361
+ class: "flex items-center gap-2"
2362
+ }, Io = {
2363
+ key: 0,
2364
+ class: "border-b border-fm-color-stroke-secondary"
2365
+ }, To = { class: "flex flex-col gap-4" }, Eo = { class: "flex items-center justify-between" }, qo = {
2366
+ key: 0,
2367
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-tertiary"
2368
+ }, Vo = { class: "flex justify-between items-start py-1 gap-4" }, Lo = { class: "flex-1 min-w-0 flex flex-col gap-2" }, jo = { class: "flex flex-col gap-2 items-end w-52 shrink-0" }, Uo = {
2369
+ key: 0,
2370
+ class: "flex items-center gap-2"
2371
+ }, Mo = {
2372
+ key: 0,
2373
+ class: "border-b border-fm-color-stroke-secondary"
2374
+ }, Bo = { class: "flex flex-col gap-4" }, zo = { class: "flex flex-col gap-4" }, Ko = { class: "flex flex-col gap-4" }, Ho = { class: "flex flex-col gap-4 fm-typo-en-body-lg-600" }, Go = {
2375
+ key: 1,
2376
+ class: "flex flex-col gap-4"
2377
+ }, Wo = { class: "flex flex-col gap-4 fm-typo-en-body-lg-600" }, ct = "Will be ignored on save (zero or negative quantity)", Qo = /* @__PURE__ */ Ve({
2378
+ __name: "EditForm",
2379
+ props: {
2380
+ purchaseOrder: {},
2381
+ deliveryOrder: {},
2382
+ receivedInfoMap: {}
2383
+ },
2384
+ emits: ["submitted"],
2385
+ setup(d, { emit: t }) {
2386
+ var ee;
2387
+ const { t: r } = nr(), n = Xe(), m = Je(), u = ne(!1), c = Dt(), s = d, a = (((ee = s.purchaseOrder) == null ? void 0 : ee.version) ?? Ue.enum[1]) === Ue.enum[2], O = t, f = is("deliveryOrder"), R = Ze(), {
2388
+ controller: N,
2389
+ state: F,
2390
+ reset: _
2391
+ } = It({
2392
+ currency: Ae(),
2393
+ adjustments: s.deliveryOrder.priceAdjustments
2394
+ }), B = H(
2395
+ () => {
2396
+ var L;
2397
+ return ((L = s.purchaseOrder.deliveryFullfillment) == null ? void 0 : L.findIndex(
2398
+ (g) => s.deliveryOrder.fullfillmentId && g.id === s.deliveryOrder.fullfillmentId
2399
+ )) ?? -1;
2400
+ }
2401
+ ), E = n.enablePurchaseOrderReceiveWithCustomCost, te = n.enablePortalDeliveryOrderWrite, se = ne({}), Q = H(
2402
+ () => (s.purchaseOrder.itemsAtSubmission ?? s.purchaseOrder.items).length
2403
+ ), de = H(() => _s(s.purchaseOrder)), Oe = H(
2404
+ () => Ss(s.purchaseOrder, de.value)
2405
+ ), ae = H(
2406
+ () => s.purchaseOrder.items.map(
2407
+ (L, g) => H({
2408
+ get: () => {
2409
+ var J;
2410
+ const j = (J = f.received[g]) == null ? void 0 : J.amount;
2411
+ return j ? +$e(j) : 0;
2412
+ },
2413
+ set: (j) => {
2414
+ f.received[g].amount = Qe(j, L.sku.unit.precision);
2415
+ }
2416
+ })
2417
+ )
2418
+ ), Se = H(
2419
+ () => s.purchaseOrder.items.map(
2420
+ (L, g) => H({
2421
+ get: () => {
2422
+ var J;
2423
+ const j = (J = f.received[g]) == null ? void 0 : J.cost;
2424
+ return j ? +$e(j) : 0;
2425
+ },
2426
+ set: (j) => {
2427
+ f.received[g].cost = {
2428
+ currency: Ae(),
2429
+ ...Qe(j, 4)
2430
+ };
2431
+ }
2432
+ })
2433
+ )
2434
+ );
2435
+ function De(L) {
2436
+ var j;
2437
+ const g = !se.value[L];
2438
+ if (se.value[L] = g, g) {
2439
+ const J = (j = f.received[L]) == null ? void 0 : j.cost;
2440
+ f.received[L].cost = J ? { ...J, precision: 4 } : { currency: Ae(), amount: 0, precision: 4 };
2441
+ } else
2442
+ delete f.received[L].cost;
2443
+ }
2444
+ const K = ne([]), ve = H(
2445
+ () => c.skus.filter((L) => !L.isInactive).map((L) => ({ label: `${L.name} (${L.code})`, value: L._id }))
2446
+ );
2447
+ function P() {
2448
+ K.value.push({ skuId: null, costEnabled: !1 }), f.received.push({
2449
+ sku: null,
2450
+ amount: Pe.fromNumber(0),
2451
+ measurement: null
2452
+ });
2453
+ }
2454
+ function x(L) {
2455
+ K.value.splice(L, 1), f.received.splice(Q.value + L, 1);
2456
+ }
2457
+ function w(L, g) {
2458
+ K.value[L].skuId = g;
2459
+ const j = g ? c.skuById[g] : null;
2460
+ f.received[Q.value + L].sku = j;
2461
+ }
2462
+ function A(L, g) {
2463
+ var ke, we;
2464
+ const j = (ke = s.receivedInfoMap) == null ? void 0 : ke[g.sku._id], J = j ? `${r("inventory.transfer.receiveRequest.details.received")} ${Pe.toFormatString({ value: j.received })} / ${ft(g.quantity, g.sku.unit, g.measurement)}` : void 0;
2465
+ return (((we = ae.value[L]) == null ? void 0 : we.value) ?? 0) > 0 ? J : J ? `${J} · ${ct}` : ct;
2466
+ }
2467
+ function G(L, g) {
2468
+ var ke;
2469
+ const J = (((ke = Z.value[g]) == null ? void 0 : ke.value) ?? 0) <= 0;
2470
+ let me;
2471
+ if (L.skuId && Oe.value[L.skuId]) {
2472
+ const we = Oe.value[L.skuId], o = Pe.toFormatString({ value: we.received });
2473
+ me = `${r("inventory.transfer.receiveRequest.details.received")} ${o}`;
2474
+ }
2475
+ return J ? me ? `${me} · ${ct}` : ct : me;
2476
+ }
2477
+ const Z = H(
2478
+ () => K.value.map((L, g) => {
2479
+ const j = Q.value + g;
2480
+ return H({
2481
+ get: () => {
2482
+ var me;
2483
+ const J = (me = f.received[j]) == null ? void 0 : me.amount;
2484
+ return J ? +$e(J) : 0;
2485
+ },
2486
+ set: (J) => {
2487
+ var ke, we, o;
2488
+ const me = ((ke = L.historyItem) == null ? void 0 : ke.sku.unit.precision) ?? (L.skuId ? (o = (we = c.skuById[L.skuId]) == null ? void 0 : we.unit) == null ? void 0 : o.precision : void 0) ?? 2;
2489
+ f.received[j].amount = Qe(J, me);
2490
+ }
2491
+ });
2492
+ })
2493
+ ), le = H(
2494
+ () => K.value.map((L, g) => {
2495
+ const j = Q.value + g;
2496
+ return H({
2497
+ get: () => {
2498
+ var me;
2499
+ const J = (me = f.received[j]) == null ? void 0 : me.cost;
2500
+ return J ? +$e(J) : 0;
2501
+ },
2502
+ set: (J) => {
2503
+ f.received[j].cost = {
2504
+ currency: Ae(),
2505
+ ...Qe(J, 4)
2506
+ };
2507
+ }
2508
+ });
2509
+ })
2510
+ );
2511
+ function b(L) {
2512
+ const g = K.value[L], j = Q.value + L;
2513
+ g.costEnabled = !g.costEnabled, g.costEnabled ? f.received[j].cost = { currency: Ae(), amount: 0, precision: 4 } : delete f.received[j].cost;
2514
+ }
2515
+ Ye(
2516
+ () => u.value,
2517
+ (L) => {
2518
+ var o, l, $;
2519
+ if (!L) {
2520
+ K.value = [], se.value = {};
2521
+ return;
2522
+ }
2523
+ _(s.deliveryOrder.priceAdjustments);
2524
+ const g = s.purchaseOrder.itemsAtSubmission ?? s.purchaseOrder.items, j = new Set(g.map((C) => C.sku._id)), J = {}, me = [];
2525
+ for (const C of s.deliveryOrder.received ?? []) {
2526
+ const q = (o = C.sku) == null ? void 0 : o._id;
2527
+ q && (j.has(q) ? J[q] = C : me.push(C));
2528
+ }
2529
+ f.received = g.map((C) => {
2530
+ const q = J[C.sku._id];
2531
+ return q ? { ...q } : {
2532
+ // Propagate the stable id so V2 submissions match this existing PO line
2533
+ // instead of the backend treating it as a new extra item (see CreateForm.vue).
2534
+ ...a && C.id ? { id: C.id } : {},
2535
+ sku: C.sku,
2536
+ amount: Pe.fromNumber(0),
2537
+ measurement: C.measurement ?? null
2538
+ };
2539
+ });
2540
+ const ke = {};
2541
+ for (let C = 0; C < g.length; C++)
2542
+ (l = J[g[C].sku._id]) != null && l.cost && (ke[C] = !0);
2543
+ se.value = ke, K.value = [];
2544
+ const we = de.value;
2545
+ for (const C of me) {
2546
+ const q = we.find((Y) => {
2547
+ var ye;
2548
+ return Y.sku._id === ((ye = C.sku) == null ? void 0 : ye._id);
2549
+ });
2550
+ K.value.push({
2551
+ skuId: (($ = C.sku) == null ? void 0 : $._id) ?? null,
2552
+ costEnabled: !!C.cost,
2553
+ locked: !0,
2554
+ quantityLocked: !0,
2555
+ historyItem: q
2556
+ }), f.received.push({ ...C });
2557
+ }
2558
+ if (we.length) {
2559
+ const C = new Set(me.map((q) => {
2560
+ var Y;
2561
+ return (Y = q.sku) == null ? void 0 : Y._id;
2562
+ }));
2563
+ for (const q of we)
2564
+ C.has(q.sku._id) || (K.value.push({
2565
+ skuId: q.sku._id,
2566
+ costEnabled: !1,
2567
+ locked: !0,
2568
+ historyItem: q
2569
+ }), f.received.push({
2570
+ ...a && q.id ? { id: q.id } : {},
2571
+ sku: q.sku,
2572
+ amount: Pe.fromNumber(0),
2573
+ measurement: q.measurement ?? null
2574
+ }));
2575
+ }
2576
+ }
2577
+ );
2578
+ const D = ne(!1);
2579
+ function ie() {
2580
+ D.value = !0, R.updateDeliveryOrder({
2581
+ deliveryOrder: {
2582
+ ...s.deliveryOrder,
2583
+ ...f,
2584
+ priceAdjustments: N.value.state().adjustments
2585
+ },
2586
+ purchaseOrderId: s.purchaseOrder._id,
2587
+ purchaseOrderRev: s.purchaseOrder._rev
2588
+ }).then(() => {
2589
+ m.open(
2590
+ {
2591
+ title: "Success",
2592
+ message: `PO# ${s.purchaseOrder.seqNumber} Changes have been saved`,
2593
+ type: "success"
2594
+ },
2595
+ 1e4
2596
+ ), u.value = !1, O("submitted");
2597
+ }).finally(() => {
2598
+ D.value = !1;
2599
+ });
2600
+ }
2601
+ return (L, g) => {
2602
+ const j = oe("FmButton"), J = oe("FmStepperField"), me = oe("FmSwitch"), ke = oe("FmSelect"), we = oe("FmTextField"), o = oe("FmDialog");
2603
+ return i(), he(o, {
2604
+ modelValue: u.value,
2605
+ "onUpdate:modelValue": g[1] || (g[1] = (l) => u.value = l),
2606
+ overlay: !0,
2607
+ "min-width": 800
2608
+ }, {
2609
+ "dialog-button": ce(() => [
2610
+ h(te) ? (i(), he(j, {
2611
+ key: 0,
2612
+ variant: "plain",
2613
+ label: "Edit",
2614
+ size: "md",
2615
+ "prepend-icon": "edit"
2616
+ })) : V("", !0)
2617
+ ]),
2618
+ "dialog-header": ce(() => [
2619
+ e("div", null, "Received on " + k(h(et)(s.deliveryOrder.createdAt)), 1)
2620
+ ]),
2621
+ "dialog-footer": ce(() => [
2622
+ T(j, {
2623
+ class: "ml-auto",
2624
+ label: "Apply changes",
2625
+ size: "md",
2626
+ variant: "destructive",
2627
+ disabled: D.value,
2628
+ loading: D.value,
2629
+ onClick: ie
2630
+ }, null, 8, ["disabled", "loading"])
2631
+ ]),
2632
+ default: ce(() => [
2633
+ e("div", xo, [
2634
+ e("div", wo, [
2635
+ g[2] || (g[2] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Adjustment date", -1)),
2636
+ e("div", $o, k(s.deliveryOrder.adjustment ? h(et)(new Date(h(mt)(s.deliveryOrder.adjustment))) : "-"), 1)
2637
+ ]),
2638
+ e("div", Co, [
2639
+ g[4] || (g[4] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Items going to receive ", -1)),
2640
+ (i(!0), v(Ce, null, Te(s.purchaseOrder.items, (l, $) => {
2641
+ var C;
2642
+ return i(), v("div", { key: $ }, [
2643
+ e("div", Ao, [
2644
+ e("div", Do, [
2645
+ e("span", Ro, k(l.sku.name), 1),
2646
+ e("span", No, k(l.sku.code), 1)
2647
+ ]),
2648
+ e("div", Po, [
2649
+ T(J, {
2650
+ label: "Receive Quantity",
2651
+ modelValue: ae.value[$].value,
2652
+ "onUpdate:modelValue": (q) => ae.value[$].value = q,
2653
+ "append-text": ((C = l.measurement) == null ? void 0 : C.abbrev) ?? l.sku.unit.abbrev,
2654
+ "helper-text": A($, l)
2655
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text", "helper-text"]),
2656
+ h(E) ? (i(), v("div", Fo, [
2657
+ T(me, {
2658
+ "model-value": se.value[$],
2659
+ "onUpdate:modelValue": (q) => De($),
2660
+ size: "sm"
2661
+ }, null, 8, ["model-value", "onUpdate:modelValue"]),
2662
+ g[3] || (g[3] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Override cost ", -1))
2663
+ ])) : V("", !0),
2664
+ h(E) && se.value[$] ? (i(), he(J, {
2665
+ key: 1,
2666
+ modelValue: Se.value[$].value,
2667
+ "onUpdate:modelValue": (q) => Se.value[$].value = q,
2668
+ label: "Total Cost",
2669
+ step: 1e-4,
2670
+ min: 0,
2671
+ placeholder: "0.0000",
2672
+ size: "sm",
2673
+ "append-text": h(Ae)()
2674
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text"])) : V("", !0)
2675
+ ])
2676
+ ]),
2677
+ $ < s.purchaseOrder.items.length - 1 ? (i(), v("div", Io)) : V("", !0)
2678
+ ]);
2679
+ }), 128))
2680
+ ]),
2681
+ e("div", To, [
2682
+ e("div", Eo, [
2683
+ g[5] || (g[5] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Extra items", -1)),
2684
+ T(j, {
2685
+ variant: "tertiary",
2686
+ label: "Add item",
2687
+ "prepend-icon": "add",
2688
+ size: "md",
2689
+ onClick: P
2690
+ })
2691
+ ]),
2692
+ K.value.length === 0 ? (i(), v("div", qo, " No extra items added ")) : V("", !0),
2693
+ (i(!0), v(Ce, null, Te(K.value, (l, $) => {
2694
+ var C, q;
2695
+ return i(), v("div", { key: $ }, [
2696
+ e("div", Vo, [
2697
+ e("div", Lo, [
2698
+ T(ke, {
2699
+ "model-value": l.skuId,
2700
+ "onUpdate:modelValue": (Y) => w($, Y),
2701
+ label: "Ingredient",
2702
+ items: ve.value,
2703
+ searchable: "",
2704
+ searchTarget: "label",
2705
+ placeholder: "Select ingredient",
2706
+ disabled: l.locked
2707
+ }, null, 8, ["model-value", "onUpdate:modelValue", "items", "disabled"])
2708
+ ]),
2709
+ e("div", jo, [
2710
+ T(J, {
2711
+ label: "Receive Quantity",
2712
+ modelValue: Z.value[$].value,
2713
+ "onUpdate:modelValue": (Y) => Z.value[$].value = Y,
2714
+ "append-text": l.skuId ? ((q = (C = h(c).skuById[l.skuId]) == null ? void 0 : C.unit) == null ? void 0 : q.abbrev) ?? "" : "",
2715
+ "helper-text": G(l, $),
2716
+ disabled: l.quantityLocked || !l.skuId
2717
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text", "helper-text", "disabled"]),
2718
+ h(E) ? (i(), v("div", Uo, [
2719
+ T(me, {
2720
+ "model-value": l.costEnabled,
2721
+ "onUpdate:modelValue": (Y) => b($),
2722
+ size: "sm"
2723
+ }, null, 8, ["model-value", "onUpdate:modelValue"]),
2724
+ g[6] || (g[6] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Override cost ", -1))
2725
+ ])) : V("", !0),
2726
+ h(E) && l.costEnabled ? (i(), he(J, {
2727
+ key: 1,
2728
+ modelValue: le.value[$].value,
2729
+ "onUpdate:modelValue": (Y) => le.value[$].value = Y,
2730
+ label: "Total Cost",
2731
+ step: 1e-4,
2732
+ min: 0,
2733
+ placeholder: "0.0000",
2734
+ size: "sm",
2735
+ "append-text": h(Ae)()
2736
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text"])) : V("", !0)
2737
+ ]),
2738
+ l.locked ? V("", !0) : (i(), he(j, {
2739
+ key: 0,
2740
+ variant: "tertiary",
2741
+ "prepend-icon": "delete",
2742
+ size: "md",
2743
+ class: "mt-6",
2744
+ onClick: (Y) => x($)
2745
+ }, null, 8, ["onClick"]))
2746
+ ]),
2747
+ $ < K.value.length - 1 ? (i(), v("div", Mo)) : V("", !0)
2748
+ ]);
2749
+ }), 128))
2750
+ ]),
2751
+ e("div", Bo, [
2752
+ g[7] || (g[7] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Delivery order no.", -1)),
2753
+ e("div", zo, [
2754
+ T(we, {
2755
+ modelValue: h(f).deliveryOrderNumber,
2756
+ "onUpdate:modelValue": g[0] || (g[0] = (l) => h(f).deliveryOrderNumber = l),
2757
+ size: "md",
2758
+ placeholder: s.deliveryOrder.deliveryOrderNumber
2759
+ }, null, 8, ["modelValue", "placeholder"])
2760
+ ])
2761
+ ]),
2762
+ e("div", Ko, [
2763
+ g[8] || (g[8] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Remark", -1)),
2764
+ e("div", Ho, k(s.deliveryOrder.remark || "N/A"), 1)
2765
+ ]),
2766
+ h(n).enablePurchaseOrderPriceAdjustment ? (i(), he(Ft, {
2767
+ key: 0,
2768
+ controller: h(N),
2769
+ state: h(F)
2770
+ }, null, 8, ["controller", "state"])) : V("", !0),
2771
+ B.value >= 0 ? (i(), v("div", Go, [
2772
+ g[9] || (g[9] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Fulfilment's sequence", -1)),
2773
+ e("div", Wo, k(B.value + 1), 1)
2774
+ ])) : V("", !0)
2775
+ ])
2776
+ ]),
2777
+ _: 1
2778
+ }, 8, ["modelValue"]);
2779
+ };
2780
+ }
2781
+ }), Yo = { class: "flex flex-col gap-3" }, Jo = { class: "flex flex-col gap-4" }, Xo = { class: "flex flex-col gap-4 fm-typo-en-body-lg-600" }, Zo = {
2782
+ key: 0,
2783
+ class: "flex flex-col gap-4"
2784
+ }, en = { class: "flex items-center justify-between" }, tn = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, sn = {
2785
+ key: 0,
2786
+ class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
2787
+ }, rn = { class: "flex gap-4" }, on = { class: "flex-1" }, nn = { class: "flex-1" }, an = {
2788
+ key: 0,
2789
+ class: "flex items-center text-fm-color-system-error-300"
2790
+ }, ln = { class: "fm-typo-en-body-md-400" }, un = { class: "flex flex-col gap-4" }, cn = { class: "flex justify-between items-start py-1 gap-4" }, dn = { class: "flex flex-col flex-1 min-w-0" }, mn = { class: "fm-typo-en-body-lg-600 truncate" }, pn = { class: "fm-typo-en-body-md-400 truncate" }, fn = { class: "flex flex-col gap-2 items-end w-52 shrink-0" }, vn = {
2791
+ key: 0,
2792
+ class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 self-end text-right"
2793
+ }, yn = {
2794
+ key: 1,
2795
+ class: "flex items-center gap-2"
2796
+ }, hn = {
2797
+ key: 0,
2798
+ class: "border-b border-fm-color-stroke-secondary"
2799
+ }, bn = { class: "flex flex-col gap-4" }, gn = { class: "flex items-center justify-between" }, _n = {
2800
+ key: 0,
2801
+ class: "fm-typo-en-body-md-400 text-fm-color-typo-tertiary"
2802
+ }, Sn = { class: "flex justify-between items-start py-1 gap-4" }, kn = { class: "flex-1 min-w-0 flex flex-col gap-2" }, On = { class: "flex flex-col gap-2 items-end w-52 shrink-0" }, xn = {
2803
+ key: 0,
2804
+ class: "fm-typo-en-body-sm-400 text-fm-color-system-error-300 self-end text-right"
2805
+ }, wn = {
2806
+ key: 1,
2807
+ class: "flex items-center gap-2"
2808
+ }, $n = {
2809
+ key: 0,
2810
+ class: "border-b border-fm-color-stroke-secondary"
2811
+ }, Cn = { class: "flex flex-col gap-4" }, An = { class: "flex flex-col gap-4" }, Dn = { class: "flex flex-col gap-4" }, Rn = { class: "flex flex-col gap-4 fm-typo-en-body-lg-600" }, ss = "Will be ignored on save (zero or negative quantity)", Nn = /* @__PURE__ */ Ve({
2812
+ __name: "CreateForm",
2813
+ props: {
2814
+ purchaseOrder: {},
2815
+ receivedInfoMap: {},
2816
+ receivedMap: {}
2817
+ },
2818
+ emits: ["submitted"],
2819
+ setup(d, { emit: t }) {
2820
+ var ye, I, pe;
2821
+ const { t: r } = ht(), n = ne(!1), m = bt(), u = d, c = t, s = is("", {
2822
+ default: {
2823
+ deliveryOrderNumber: "",
2824
+ remark: "",
2825
+ received: (u.purchaseOrder.itemsAtSubmission ?? u.purchaseOrder.items).map((y) => {
2826
+ var p;
2827
+ return {
2828
+ // Propagate the stable id so V2 submissions match this existing PO line instead
2829
+ // of the backend's classify-received.ts treating it as a new extra item (which
2830
+ // appends a duplicate item record with quantity = this delivery's amount, on
2831
+ // every single delivery — inflating the PO's total ordered quantity forever).
2832
+ ...(((p = u.purchaseOrder) == null ? void 0 : p.version) ?? Ue.enum[1]) === Ue.enum[2] && y.id ? { id: y.id } : {},
2833
+ sku: y.sku,
2834
+ amount: Pe.fromNumber(0),
2835
+ measurement: y.measurement
2836
+ };
2837
+ }),
2838
+ createdBy: {
2839
+ id: ((ye = m.sessionUser.value) == null ? void 0 : ye.id) || "",
2840
+ name: ((I = m.sessionUser.value) == null ? void 0 : I.displayName) || ""
2841
+ },
2842
+ createdAt: ""
2843
+ }
2844
+ }), a = Ze(), O = gt(), f = Xe(), R = Dt(), {
2845
+ controller: N,
2846
+ state: F,
2847
+ reset: _
2848
+ } = It({ currency: Ae() }), B = H(
2849
+ () => u.purchaseOrder.deliveryFullfillment != null
2850
+ ), E = H(
2851
+ () => f.enablePortalDeliveryOrderWrite && (u.purchaseOrder.status === ge.Enum.RECEIVING || u.purchaseOrder.status === ge.Enum.COMPLETE) && !B.value
2852
+ ), te = f.enablePurchaseOrderReceiveWithCustomCost, se = f.enableBackdateReceive, Q = ne({}), de = H(
2853
+ () => u.purchaseOrder.itemsAtSubmission ?? u.purchaseOrder.items
2854
+ ), Oe = H(() => _s(u.purchaseOrder)), ae = H(
2855
+ () => Ss(u.purchaseOrder, Oe.value)
2856
+ );
2857
+ function Se(y) {
2858
+ return y.sku._id ?? null;
2859
+ }
2860
+ const De = (((pe = u.purchaseOrder) == null ? void 0 : pe.version) ?? Ue.enum[1]) === Ue.enum[2], K = Je(), ve = H({
2861
+ get() {
2862
+ if (!s.createdAt) return "";
2863
+ const y = new Date(s.createdAt), p = y.getFullYear(), S = String(y.getMonth() + 1).padStart(2, "0"), U = String(y.getDate()).padStart(2, "0");
2864
+ return `${p}-${S}-${U}`;
2865
+ },
2866
+ set(y) {
2867
+ if (y) {
2868
+ const p = s.createdAt ? new Date(s.createdAt) : /* @__PURE__ */ new Date(), [S, U, M] = y.split("-");
2869
+ p.setFullYear(parseInt(S)), p.setMonth(parseInt(U) - 1), p.setDate(parseInt(M)), s.createdAt = p.toISOString();
2870
+ }
2871
+ }
2872
+ }), P = H({
2873
+ get() {
2874
+ if (!s.createdAt) return "";
2875
+ const y = new Date(s.createdAt), p = String(y.getHours()).padStart(2, "0"), S = String(y.getMinutes()).padStart(2, "0");
2876
+ return `${p}:${S}`;
2877
+ },
2878
+ set(y) {
2879
+ if (y) {
2880
+ const p = s.createdAt ? new Date(s.createdAt) : /* @__PURE__ */ new Date(), [S, U] = y.split(":");
2881
+ p.setHours(parseInt(S)), p.setMinutes(parseInt(U)), s.createdAt = p.toISOString();
2882
+ }
2883
+ }
2884
+ }), x = H(() => {
2885
+ const y = mt(u.purchaseOrder._id);
2886
+ if (!y) return "";
2887
+ const p = new Date(y), S = p.getFullYear(), U = String(p.getMonth() + 1).padStart(2, "0"), M = String(p.getDate()).padStart(2, "0");
2888
+ return `${S}-${U}-${M}`;
2889
+ }), w = H(() => {
2890
+ const y = mt(u.purchaseOrder._id);
2891
+ return y ? new Date(y) : null;
2892
+ }), A = H(() => {
2893
+ if (!ve.value || !P.value || !w.value) return null;
2894
+ if (/* @__PURE__ */ new Date(`${ve.value}T${P.value}:00`) < w.value) {
2895
+ const p = x.value, S = w.value.getHours(), U = w.value.getMinutes(), M = S >= 12 ? "PM" : "AM", _e = S % 12 || 12, xe = `${String(_e).padStart(2, "0")}:${String(U).padStart(2, "0")} ${M}`;
2896
+ return `Delivery date & time cannot be earlier than order creation (${p} ${xe})`;
2897
+ }
2898
+ return null;
2899
+ }), G = H(() => A.value || ee.value.some((p) => !p.skuId) ? !1 : s.received.some((p) => {
2900
+ const S = p.amount;
2901
+ return S ? +$e(S) > 0 : !1;
2902
+ }));
2903
+ function Z(y) {
2904
+ var U;
2905
+ const p = (U = u.receivedInfoMap[y.sku._id]) == null ? void 0 : U.received, S = p != null ? Pe.toFormatString({ value: p }) : "0";
2906
+ return `${r("inventory.transfer.receiveRequest.details.received")} ${S} / ${ft(y.quantity, y.sku.unit, y.measurement)}`;
2907
+ }
2908
+ function le() {
2909
+ s.createdAt = "";
2910
+ }
2911
+ const b = H(() => de.value.map((y, p) => H({
2912
+ get: () => {
2913
+ var U;
2914
+ const S = (U = s.received[p]) == null ? void 0 : U.amount;
2915
+ return S ? +$e(S) : 0;
2916
+ },
2917
+ set: (S) => {
2918
+ var M;
2919
+ const U = ((M = de.value[p]) == null ? void 0 : M.sku.unit.precision) ?? 2;
2920
+ s.received[p].amount = Qe(S, U);
2921
+ }
2922
+ })));
2923
+ function D(y) {
2924
+ const p = !Q.value[y];
2925
+ if (Q.value[y] = p, p) {
2926
+ const S = de.value[y];
2927
+ S.totalCost ? s.received[y].cost = {
2928
+ currency: S.totalCost.currency,
2929
+ amount: S.totalCost.amount,
2930
+ precision: 4
2931
+ // Standardize to 4 decimals
2932
+ } : s.received[y].cost = {
2933
+ currency: Ae(),
2934
+ amount: 0,
2935
+ precision: 4
2936
+ };
2937
+ } else
2938
+ delete s.received[y].cost;
2939
+ }
2940
+ const ie = H(() => de.value.map((y, p) => H({
2941
+ get: () => {
2942
+ var U;
2943
+ const S = (U = s.received[p]) == null ? void 0 : U.cost;
2944
+ return S ? +$e(S) : 0;
2945
+ },
2946
+ set: (S) => {
2947
+ s.received[p].cost = {
2948
+ currency: Ae(),
2949
+ ...Qe(S, 4)
2950
+ };
2951
+ }
2952
+ }))), ee = ne([]), L = H(
2953
+ () => R.skus.filter((y) => !y.isInactive).map((y) => ({ label: `${y.name} (${y.code})`, value: y._id }))
2954
+ ), g = H(() => de.value.length);
2955
+ function j() {
2956
+ ee.value.push({ skuId: null, stableKey: null, costEnabled: !1 }), s.received.push({
2957
+ sku: null,
2958
+ amount: Pe.fromNumber(0),
2959
+ measurement: null
2960
+ });
2961
+ }
2962
+ function J(y) {
2963
+ ee.value.splice(y, 1), s.received.splice(g.value + y, 1);
2964
+ }
2965
+ function me(y, p) {
2966
+ ee.value[y].skuId = p;
2967
+ const S = p ? R.skuById[p] : null;
2968
+ s.received[g.value + y].sku = S;
2969
+ }
2970
+ function ke(y) {
2971
+ const p = y.stableKey;
2972
+ if (p && ae.value[p]) {
2973
+ const S = ae.value[p], U = Pe.toFormatString({ value: S.received });
2974
+ return `${r("inventory.transfer.receiveRequest.details.received")} ${U}`;
2975
+ }
2976
+ }
2977
+ const we = H(
2978
+ () => ee.value.map((y, p) => {
2979
+ const S = g.value + p;
2980
+ return H({
2981
+ get: () => {
2982
+ var M;
2983
+ const U = (M = s.received[S]) == null ? void 0 : M.amount;
2984
+ return U ? +$e(U) : 0;
2985
+ },
2986
+ set: (U) => {
2987
+ var xe, W, X;
2988
+ const M = ee.value[p], _e = ((xe = M == null ? void 0 : M.historyItem) == null ? void 0 : xe.sku.unit.precision) ?? (M != null && M.skuId ? (X = (W = R.skuById[M.skuId]) == null ? void 0 : W.unit) == null ? void 0 : X.precision : void 0) ?? 2;
2989
+ s.received[S].amount = Qe(U, _e);
2990
+ }
2991
+ });
2992
+ })
2993
+ ), o = H(
2994
+ () => ee.value.map((y, p) => {
2995
+ const S = g.value + p;
2996
+ return H({
2997
+ get: () => {
2998
+ var M;
2999
+ const U = (M = s.received[S]) == null ? void 0 : M.cost;
3000
+ return U ? +$e(U) : 0;
3001
+ },
3002
+ set: (U) => {
3003
+ s.received[S].cost = {
3004
+ currency: Ae(),
3005
+ ...Qe(U, 4)
3006
+ };
3007
+ }
3008
+ });
3009
+ })
3010
+ );
3011
+ function l(y) {
3012
+ const p = ee.value[y], S = g.value + y;
3013
+ p.costEnabled = !p.costEnabled, p.costEnabled ? s.received[S].cost = { currency: Ae(), amount: 0, precision: 4 } : delete s.received[S].cost;
3014
+ }
3015
+ function $() {
3016
+ Y() && O.open({
3017
+ title: "Confirm Create Delivery Order",
3018
+ message: `Are you sure you want to create delivery order for PO# ${u.purchaseOrder.seqNumber}?`,
3019
+ primaryActions: {
3020
+ text: "Create",
3021
+ close: !0,
3022
+ variant: "primary"
3023
+ },
3024
+ secondaryActions: {
3025
+ text: "Cancel",
3026
+ close: !0
3027
+ }
3028
+ }).onPrimary(() => q());
3029
+ }
3030
+ const C = ne(!1);
3031
+ function q() {
3032
+ Y() && (C.value = !0, a.createDeliveryOrder({
3033
+ deliveryOrder: {
3034
+ ...s,
3035
+ priceAdjustments: N.value.state().adjustments
3036
+ },
3037
+ purchaseOrderId: u.purchaseOrder._id,
3038
+ purchaseOrderRev: u.purchaseOrder._rev,
3039
+ currency: Ae()
3040
+ }).then(() => {
3041
+ K.open(
3042
+ {
3043
+ title: "Success",
3044
+ message: `New delivery order created for PO# ${u.purchaseOrder.seqNumber}`,
3045
+ type: "success"
3046
+ },
3047
+ 1e4
3048
+ ), n.value = !1, c("submitted");
3049
+ }).finally(() => {
3050
+ C.value = !1;
3051
+ }));
3052
+ }
3053
+ function Y() {
3054
+ return B.value ? (n.value = !1, K.open(
3055
+ {
3056
+ title: "Purchase order updated",
3057
+ message: "This purchase order now uses fulfillment receiving. Refresh and receive stock from the fulfillment section.",
3058
+ type: "error"
3059
+ },
3060
+ 1e4
3061
+ ), !1) : !0;
3062
+ }
3063
+ return Ye(B, (y) => {
3064
+ !y || !n.value || Y();
3065
+ }), Ye(
3066
+ () => n.value,
3067
+ (y) => {
3068
+ var U;
3069
+ if (!y) {
3070
+ ee.value = [], _([]), s.received = de.value.map((M) => ({
3071
+ ...De && M.id ? { id: M.id } : {},
3072
+ sku: M.sku,
3073
+ amount: Pe.fromNumber(0),
3074
+ measurement: M.measurement
3075
+ }));
3076
+ return;
3077
+ }
3078
+ const p = de.value;
3079
+ for (let M = 0; M < p.length; M++) {
3080
+ const _e = p[M], W = (((U = u.purchaseOrder) == null ? void 0 : U.version) ?? Ue.enum[1]) === Ue.enum[2] ? _e.id : _e.sku._id, X = u.receivedMap[W], be = +$e(_e.quantity), Fe = X ? +$e(X.received) : 0;
3081
+ b.value[M].value = Math.max(0, be - Fe);
3082
+ }
3083
+ const S = Oe.value;
3084
+ if (S.length) {
3085
+ for (const M of S) {
3086
+ const _e = Se(M);
3087
+ ee.value.push({
3088
+ skuId: M.sku._id,
3089
+ stableKey: _e,
3090
+ costEnabled: !1,
3091
+ historyItem: M
3092
+ }), s.received.push({
3093
+ // Propagate the stable id so V2 submissions align with the existing PO line.
3094
+ ...De && M.id ? { id: M.id } : {},
3095
+ sku: M.sku,
3096
+ amount: Pe.fromNumber(0),
3097
+ measurement: M.measurement ?? null
3098
+ });
3099
+ }
3100
+ for (let M = 0; M < S.length; M++) {
3101
+ const _e = Se(S[M]), xe = _e ? ae.value[_e] : void 0;
3102
+ if (xe) {
3103
+ const W = Math.pow(10, xe.remaining.precision ?? 2);
3104
+ we.value[M].value = Math.max(0, xe.remaining.amount / W);
3105
+ }
3106
+ }
3107
+ }
3108
+ }
3109
+ ), (y, p) => {
3110
+ const S = oe("FmButton"), U = oe("FmDatePicker"), M = oe("FmTimePicker"), _e = oe("FmIcon"), xe = oe("FmStepperField"), W = oe("FmSwitch"), X = oe("FmSelect"), be = oe("FmTextField"), Fe = oe("FmDialog");
3111
+ return i(), he(Fe, {
3112
+ modelValue: n.value,
3113
+ "onUpdate:modelValue": p[4] || (p[4] = (Ie) => n.value = Ie),
3114
+ overlay: !0,
3115
+ "min-width": 800
3116
+ }, {
3117
+ "dialog-button": ce(() => [
3118
+ E.value ? (i(), he(S, {
3119
+ key: 0,
3120
+ variant: "primary",
3121
+ label: "Create",
3122
+ size: "md",
3123
+ "prepend-icon": "add",
3124
+ class: "w-full"
3125
+ })) : V("", !0)
3126
+ ]),
3127
+ "dialog-header": ce(() => [
3128
+ e("div", null, "Order #" + k(u.purchaseOrder.seqNumber) + " (New Delivery Order)", 1)
3129
+ ]),
3130
+ "dialog-footer": ce(() => [
3131
+ T(S, {
3132
+ class: "ml-auto",
3133
+ label: "Create",
3134
+ size: "md",
3135
+ variant: "destructive",
3136
+ disabled: !G.value || C.value,
3137
+ loading: C.value,
3138
+ onClick: $
3139
+ }, null, 8, ["disabled", "loading"])
3140
+ ]),
3141
+ default: ce(() => {
3142
+ var Ie;
3143
+ return [
3144
+ e("div", Yo, [
3145
+ e("div", Jo, [
3146
+ p[5] || (p[5] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Received by", -1)),
3147
+ e("div", Xo, k((Ie = h(m).sessionUser.value) == null ? void 0 : Ie.displayName), 1)
3148
+ ]),
3149
+ h(se) ? (i(), v("div", Zo, [
3150
+ e("div", en, [
3151
+ e("div", tn, [
3152
+ p[6] || (p[6] = Ge(" Delivery Date & Time ")),
3153
+ !ve.value && !P.value ? (i(), v("div", sn, " Leave blank to use current date & time ")) : V("", !0)
3154
+ ]),
3155
+ ve.value || P.value ? (i(), he(S, {
3156
+ key: 0,
3157
+ variant: "tertiary",
3158
+ label: "Clear",
3159
+ "prepend-icon": "close",
3160
+ onClick: le
3161
+ })) : V("", !0)
3162
+ ]),
3163
+ e("div", rn, [
3164
+ e("div", on, [
3165
+ T(U, {
3166
+ modelValue: ve.value,
3167
+ "onUpdate:modelValue": p[0] || (p[0] = (fe) => ve.value = fe)
3168
+ }, null, 8, ["modelValue"])
3169
+ ]),
3170
+ e("div", nn, [
3171
+ T(M, {
3172
+ modelValue: P.value,
3173
+ "onUpdate:modelValue": p[1] || (p[1] = (fe) => P.value = fe)
3174
+ }, null, 8, ["modelValue"])
3175
+ ])
3176
+ ]),
3177
+ A.value ? (i(), v("div", an, [
3178
+ T(_e, {
3179
+ name: "error",
3180
+ class: "inline-block mr-1",
3181
+ size: "sm"
3182
+ }),
3183
+ e("div", ln, k(A.value), 1)
3184
+ ])) : V("", !0)
3185
+ ])) : V("", !0),
3186
+ e("div", un, [
3187
+ p[8] || (p[8] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, " Items going to receive ", -1)),
3188
+ (i(!0), v(Ce, null, Te(de.value, (fe, ue) => {
3189
+ var Ne;
3190
+ return i(), v("div", { key: ue }, [
3191
+ e("div", cn, [
3192
+ e("div", dn, [
3193
+ e("span", mn, k(fe.sku.name), 1),
3194
+ e("span", pn, k(fe.sku.code), 1)
3195
+ ]),
3196
+ e("div", fn, [
3197
+ T(xe, {
3198
+ label: "Receive Quantity",
3199
+ modelValue: b.value[ue].value,
3200
+ "onUpdate:modelValue": (Ee) => b.value[ue].value = Ee,
3201
+ "helper-text": Z(fe),
3202
+ "append-text": ((Ne = fe.measurement) == null ? void 0 : Ne.abbrev) ?? fe.sku.unit.abbrev
3203
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "helper-text", "append-text"]),
3204
+ b.value[ue].value <= 0 ? (i(), v("div", vn, k(ss))) : V("", !0),
3205
+ h(te) ? (i(), v("div", yn, [
3206
+ T(W, {
3207
+ "model-value": Q.value[ue],
3208
+ "onUpdate:modelValue": (Ee) => D(ue),
3209
+ size: "sm"
3210
+ }, null, 8, ["model-value", "onUpdate:modelValue"]),
3211
+ p[7] || (p[7] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Override cost ", -1))
3212
+ ])) : V("", !0),
3213
+ h(te) && Q.value[ue] ? (i(), he(xe, {
3214
+ key: 2,
3215
+ modelValue: ie.value[ue].value,
3216
+ "onUpdate:modelValue": (Ee) => ie.value[ue].value = Ee,
3217
+ label: "Total Cost",
3218
+ step: 1e-4,
3219
+ min: 0,
3220
+ placeholder: "0.0000",
3221
+ size: "sm",
3222
+ "append-text": h(Ae)()
3223
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text"])) : V("", !0)
3224
+ ])
3225
+ ]),
3226
+ ue < de.value.length - 1 ? (i(), v("div", hn)) : V("", !0)
3227
+ ]);
3228
+ }), 128))
3229
+ ]),
3230
+ e("div", bn, [
3231
+ e("div", gn, [
3232
+ p[9] || (p[9] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Extra items", -1)),
3233
+ T(S, {
3234
+ variant: "tertiary",
3235
+ label: "Add item",
3236
+ "prepend-icon": "add",
3237
+ size: "md",
3238
+ onClick: j
3239
+ })
3240
+ ]),
3241
+ ee.value.length === 0 ? (i(), v("div", _n, " No extra items added ")) : V("", !0),
3242
+ (i(!0), v(Ce, null, Te(ee.value, (fe, ue) => {
3243
+ var Ne, Ee;
3244
+ return i(), v("div", { key: ue }, [
3245
+ e("div", Sn, [
3246
+ e("div", kn, [
3247
+ T(X, {
3248
+ "model-value": fe.skuId,
3249
+ "onUpdate:modelValue": (Le) => me(ue, Le),
3250
+ label: "Ingredient",
3251
+ items: L.value,
3252
+ searchable: "",
3253
+ searchTarget: "label",
3254
+ placeholder: "Select ingredient",
3255
+ disabled: !!fe.historyItem
3256
+ }, null, 8, ["model-value", "onUpdate:modelValue", "items", "disabled"])
3257
+ ]),
3258
+ e("div", On, [
3259
+ T(xe, {
3260
+ label: "Receive Quantity",
3261
+ modelValue: we.value[ue].value,
3262
+ "onUpdate:modelValue": (Le) => we.value[ue].value = Le,
3263
+ "append-text": fe.skuId ? ((Ee = (Ne = h(R).skuById[fe.skuId]) == null ? void 0 : Ne.unit) == null ? void 0 : Ee.abbrev) ?? "" : "",
3264
+ "helper-text": ke(fe)
3265
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text", "helper-text"]),
3266
+ we.value[ue].value <= 0 ? (i(), v("div", xn, k(ss))) : V("", !0),
3267
+ h(te) ? (i(), v("div", wn, [
3268
+ T(W, {
3269
+ "model-value": fe.costEnabled,
3270
+ "onUpdate:modelValue": (Le) => l(ue),
3271
+ size: "sm"
3272
+ }, null, 8, ["model-value", "onUpdate:modelValue"]),
3273
+ p[10] || (p[10] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Override cost ", -1))
3274
+ ])) : V("", !0),
3275
+ h(te) && fe.costEnabled ? (i(), he(xe, {
3276
+ key: 2,
3277
+ modelValue: o.value[ue].value,
3278
+ "onUpdate:modelValue": (Le) => o.value[ue].value = Le,
3279
+ label: "Total Cost",
3280
+ step: 1e-4,
3281
+ min: 0,
3282
+ placeholder: "0.0000",
3283
+ size: "sm",
3284
+ "append-text": h(Ae)()
3285
+ }, null, 8, ["modelValue", "onUpdate:modelValue", "append-text"])) : V("", !0)
3286
+ ]),
3287
+ fe.historyItem ? V("", !0) : (i(), he(S, {
3288
+ key: 0,
3289
+ variant: "tertiary",
3290
+ "prepend-icon": "delete",
3291
+ size: "md",
3292
+ class: "mt-6",
3293
+ onClick: (Le) => J(ue)
3294
+ }, null, 8, ["onClick"]))
3295
+ ]),
3296
+ ue < ee.value.length - 1 ? (i(), v("div", $n)) : V("", !0)
3297
+ ]);
3298
+ }), 128))
3299
+ ]),
3300
+ e("div", Cn, [
3301
+ p[11] || (p[11] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Delivery order no.", -1)),
3302
+ e("div", An, [
3303
+ T(be, {
3304
+ modelValue: h(s).deliveryOrderNumber,
3305
+ "onUpdate:modelValue": p[2] || (p[2] = (fe) => h(s).deliveryOrderNumber = fe),
3306
+ size: "md"
3307
+ }, null, 8, ["modelValue"])
3308
+ ])
3309
+ ]),
3310
+ e("div", Dn, [
3311
+ p[12] || (p[12] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Remark", -1)),
3312
+ e("div", Rn, [
3313
+ T(be, {
3314
+ modelValue: h(s).remark,
3315
+ "onUpdate:modelValue": p[3] || (p[3] = (fe) => h(s).remark = fe),
3316
+ size: "md"
3317
+ }, null, 8, ["modelValue"])
3318
+ ])
3319
+ ]),
3320
+ h(f).enablePurchaseOrderPriceAdjustment ? (i(), he(Ft, {
3321
+ key: 1,
3322
+ controller: h(N),
3323
+ state: h(F)
3324
+ }, null, 8, ["controller", "state"])) : V("", !0)
3325
+ ])
3326
+ ];
3327
+ }),
3328
+ _: 1
3329
+ }, 8, ["modelValue"]);
3330
+ };
3331
+ }
3332
+ }), Pn = {
3333
+ key: 0,
3334
+ class: "flex flex-col gap-1"
3335
+ }, Fn = { class: "truncate" }, In = { class: "shrink-0" }, Tn = /* @__PURE__ */ Ve({
3336
+ __name: "PriceAdjustmentList",
3337
+ props: {
3338
+ adjustments: {}
3339
+ },
3340
+ setup(d) {
3341
+ const t = d, r = H(() => t.adjustments ?? []);
3342
+ function n(m) {
3343
+ const u = m.amount < 0 ? "-" : "+", c = $e({ ...m, amount: Math.abs(m.amount) });
3344
+ return `${u}${m.currency} ${c}`;
3345
+ }
3346
+ return (m, u) => r.value.length ? (i(), v("div", Pn, [
3347
+ (i(!0), v(Ce, null, Te(r.value, (c) => (i(), v("div", {
3348
+ key: c.id,
3349
+ class: "flex justify-between gap-4 fm-typo-en-body-sm-400 text-fm-color-typo-secondary"
3350
+ }, [
3351
+ e("span", Fn, k(c.name), 1),
3352
+ e("span", In, k(n(c.dinero)), 1)
3353
+ ]))), 128))
3354
+ ])) : V("", !0);
3355
+ }
3356
+ }), En = { class: "flex flex-col gap-3" }, qn = /* @__PURE__ */ Ve({
3357
+ __name: "PriceAdjustmentEditForm",
3358
+ props: {
3359
+ purchaseOrder: {}
3360
+ },
3361
+ emits: ["submitted"],
3362
+ setup(d, { emit: t }) {
3363
+ const r = d, n = t, m = Ze(), u = Je(), c = ne(!1), s = ne(!1), { controller: a, state: O, reset: f } = It({
3364
+ currency: Ae(),
3365
+ adjustments: r.purchaseOrder.priceAdjustments
3366
+ });
3367
+ Ye(
3368
+ () => c.value,
3369
+ (N) => {
3370
+ N && f(r.purchaseOrder.priceAdjustments);
3371
+ }
3372
+ );
3373
+ function R() {
3374
+ s.value = !0, m.updatePurchaseOrder({
3375
+ ...r.purchaseOrder,
3376
+ priceAdjustments: a.value.state().adjustments
3377
+ }).then(() => {
3378
+ u.open(
3379
+ {
3380
+ title: "Success",
3381
+ message: `PO# ${r.purchaseOrder.seqNumber} price adjustments saved`,
3382
+ type: "success"
3383
+ },
3384
+ 1e4
3385
+ ), c.value = !1, n("submitted");
3386
+ }).finally(() => {
3387
+ s.value = !1;
3388
+ });
3389
+ }
3390
+ return (N, F) => {
3391
+ const _ = oe("FmButton"), B = oe("FmDialog");
3392
+ return i(), he(B, {
3393
+ modelValue: c.value,
3394
+ "onUpdate:modelValue": F[0] || (F[0] = (E) => c.value = E),
3395
+ overlay: !0,
3396
+ "min-width": 600
3397
+ }, {
3398
+ "dialog-button": ce(() => [
3399
+ T(_, {
3400
+ variant: "plain",
3401
+ label: "Edit price adjustments",
3402
+ size: "md",
3403
+ "prepend-icon": "edit"
3404
+ })
3405
+ ]),
3406
+ "dialog-header": ce(() => [
3407
+ e("div", null, "Price adjustments — PO# " + k(r.purchaseOrder.seqNumber), 1)
3408
+ ]),
3409
+ "dialog-footer": ce(() => [
3410
+ T(_, {
3411
+ class: "ml-auto",
3412
+ label: "Apply changes",
3413
+ size: "md",
3414
+ variant: "destructive",
3415
+ disabled: s.value,
3416
+ loading: s.value,
3417
+ onClick: R
3418
+ }, null, 8, ["disabled", "loading"])
3419
+ ]),
3420
+ default: ce(() => [
3421
+ e("div", En, [
3422
+ T(Ft, {
3423
+ controller: h(a),
3424
+ state: h(O)
3425
+ }, null, 8, ["controller", "state"])
3426
+ ])
3427
+ ]),
3428
+ _: 1
3429
+ }, 8, ["modelValue"]);
3430
+ };
3431
+ }
3432
+ }), Vn = { class: "flex flex-row-reverse" }, Ln = {
3433
+ key: 0,
3434
+ class: "flex"
3435
+ }, jn = {
3436
+ key: 1,
3437
+ class: "border-t pt-6"
3438
+ }, Un = { class: "fm-typo-en-body-lg-600 mb-4 flex items-center gap-2" }, Mn = { class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg overflow-y-auto" }, Bn = { class: "w-full" }, zn = {
3439
+ class: "p-3 fm-typo-en-body-sm-600",
3440
+ style: { "min-width": "130px" }
3441
+ }, Kn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Hn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Gn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Wn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Qn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Yn = { class: "p-3 fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, Jn = { class: "p-3 fm-typo-en-body-sm-600" }, Xn = { key: 2 }, Zn = /* @__PURE__ */ Ve({
3442
+ __name: "NetSuiteTransactionChangeLog",
3443
+ props: {
3444
+ netsuiteId: {}
3445
+ },
3446
+ setup(d) {
3447
+ const t = d, r = Pt(), n = ne(!1), m = ne(!1), u = ne(!1), c = ne([]);
3448
+ async function s() {
3449
+ if (!(c.value.length > 0))
3450
+ try {
3451
+ m.value = !0;
3452
+ const f = await r.getChangeLogs(t.netsuiteId);
3453
+ c.value = f, u.value = !1;
3454
+ } catch {
3455
+ u.value = !0;
3456
+ } finally {
3457
+ m.value = !1;
3458
+ }
3459
+ }
3460
+ function a(f) {
3461
+ switch (f) {
3462
+ case Me.Create:
3463
+ return "text-green-600 bg-green-100";
3464
+ case Me.Set:
3465
+ return "text-blue-600 bg-blue-100";
3466
+ case Me.Change:
3467
+ return "text-yellow-600 bg-yellow-100";
3468
+ case Me.Unset:
3469
+ return "text-red-600 bg-red-100";
3470
+ default:
3471
+ return "text-gray-600 bg-gray-100";
3472
+ }
3473
+ }
3474
+ function O(f) {
3475
+ return new Date(f).toLocaleDateString("en-US", {
3476
+ year: "numeric",
3477
+ month: "short",
3478
+ day: "numeric",
3479
+ hour: "2-digit",
3480
+ minute: "2-digit"
3481
+ });
3482
+ }
3483
+ return (f, R) => {
3484
+ const N = oe("FmButton"), F = oe("FmCircularProgress"), _ = oe("FmIcon"), B = oe("FmDialog");
3485
+ return i(), v("div", Vn, [
3486
+ T(B, {
3487
+ modelValue: n.value,
3488
+ "onUpdate:modelValue": R[2] || (R[2] = (E) => n.value = E),
3489
+ overlay: !0,
3490
+ "max-width": 800
3491
+ }, {
3492
+ "dialog-button": ce(() => [
3493
+ T(N, {
3494
+ "prepend-icon": "info",
3495
+ variant: "secondary",
3496
+ label: "NetSuite",
3497
+ onClick: R[0] || (R[0] = (E) => s()),
3498
+ "text-color": "primary",
3499
+ "bg-color": "transparent",
3500
+ "border-color": "primary"
3501
+ })
3502
+ ]),
3503
+ "dialog-header": ce(() => R[3] || (R[3] = [
3504
+ e("div", null, "NetSuite info", -1)
3505
+ ])),
3506
+ default: ce(() => [
3507
+ m.value ? (i(), v("div", Ln, [
3508
+ R[4] || (R[4] = e("span", null, "Change Log Loading...", -1)),
3509
+ T(F, { size: "md" })
3510
+ ])) : V("", !0),
3511
+ !m.value && c.value.length > 0 ? (i(), v("div", jn, [
3512
+ e("h3", Un, [
3513
+ T(_, {
3514
+ name: "error",
3515
+ color: "#ff9500",
3516
+ size: "sm"
3517
+ }),
3518
+ R[5] || (R[5] = Ge(" Change Logs "))
3519
+ ]),
3520
+ e("div", Mn, [
3521
+ e("table", Bn, [
3522
+ R[6] || (R[6] = e("thead", { class: "bg-fm-color-neutral-gray-50" }, [
3523
+ e("tr", { class: "border-b border-fm-color-neutral-gray-200" }, [
3524
+ e("th", {
3525
+ class: "text-left p-3 fm-typo-en-body-md-600",
3526
+ style: { "min-width": "130px" }
3527
+ }, " Date "),
3528
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Role"),
3529
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Name"),
3530
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Context"),
3531
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Type"),
3532
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Line ID"),
3533
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Field"),
3534
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "Old Value"),
3535
+ e("th", { class: "text-left p-3 fm-typo-en-body-md-600" }, "New Value")
3536
+ ])
3537
+ ], -1)),
3538
+ e("tbody", null, [
3539
+ (i(!0), v(Ce, null, Te(c.value, (E, te) => (i(), v("tr", {
3540
+ key: te,
3541
+ class: "border-b border-fm-color-neutral-gray-200 last:border-b-0"
3542
+ }, [
3543
+ e("td", zn, k(O(E._dateiso8601)), 1),
3544
+ e("td", Kn, k(E._rolename), 1),
3545
+ e("td", Hn, k(E._employeename), 1),
3546
+ e("td", Gn, k(E._contextname), 1),
3547
+ e("td", {
3548
+ class: We(`p-3 fm-typo-en-body-sm-600 ${a(Number(E.type) - 1)}`)
3549
+ }, k(h(Me)[Number(E.type) - 1]), 3),
3550
+ e("td", Wn, k(E.lineid || ""), 1),
3551
+ e("td", Qn, k(E._fieldname), 1),
3552
+ e("td", Yn, k(E.oldvalue || ""), 1),
3553
+ e("td", Jn, k(E.newvalue || ""), 1)
3554
+ ]))), 128))
3555
+ ])
3556
+ ])
3557
+ ])
3558
+ ])) : (i(), v("div", Xn, R[7] || (R[7] = [
3559
+ e("p", null, "No change logs available.", -1)
3560
+ ])))
3561
+ ]),
3562
+ "dialog-footer": ce(() => [
3563
+ T(N, {
3564
+ class: "ml-auto sm:w-full xs:w-full",
3565
+ label: "Close",
3566
+ size: "md",
3567
+ variant: "primary",
3568
+ onClick: R[1] || (R[1] = (E) => n.value = !1)
3569
+ })
3570
+ ]),
3571
+ _: 1
3572
+ }, 8, ["modelValue"])
3573
+ ]);
3574
+ };
3575
+ }
3576
+ }), ea = { class: "flex flex-col w-full gap-3" }, ta = { class: "flex" }, sa = { class: "fm-typo-en-title-md-600 text-fm-color-typo-primary" }, ra = { class: "flex flex-col gap-16 w-full h-full" }, oa = { class: "flex justify-between" }, na = { class: "fm-typo-en-body-lg-600" }, aa = { class: "flex gap-2" }, la = {
3577
+ key: 0,
3578
+ class: "flex items-center gap-1"
3579
+ }, ia = { class: "fm-typo-en-body-md-400" }, ua = { class: "flex flex-col gap-8" }, ca = {
3580
+ key: 0,
3581
+ class: "flex items-start justify-between gap-6"
3582
+ }, da = { class: "text-xs font-mono text-right break-all" }, ma = {
3583
+ key: 1,
3584
+ class: "flex items-start justify-between gap-6"
3585
+ }, pa = { class: "fm-typo-en-body-sm-600" }, fa = {
3586
+ key: 2,
3587
+ class: "flex items-start justify-between gap-6"
3588
+ }, va = { class: "text-xs font-mono text-right break-all" }, ya = {
3589
+ key: 3,
3590
+ class: "flex items-start justify-between gap-6"
3591
+ }, ha = { class: "text-xs font-mono text-right break-all" }, ba = { class: "flex flex-col gap-4" }, ga = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, _a = { class: "flex gap-1" }, Sa = { class: "fm-typo-en-body-lg-600" }, ka = {
3592
+ key: 0,
3593
+ class: "flex flex-col gap-4"
3594
+ }, Oa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, xa = { class: "fm-typo-en-body-lg-600" }, wa = { class: "flex flex-col gap-4" }, $a = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ca = { class: "fm-typo-en-body-lg-600" }, Aa = {
3595
+ key: 1,
3596
+ class: "flex flex-col gap-4"
3597
+ }, Da = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ra = { class: "fm-typo-en-body-lg-600" }, Na = {
3598
+ key: 2,
3599
+ class: "flex flex-col gap-4"
3600
+ }, Pa = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Fa = { class: "fm-typo-en-body-lg-600" }, Ia = {
3601
+ key: 3,
3602
+ class: "flex flex-col gap-4"
3603
+ }, Ta = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ea = { class: "fm-typo-en-body-lg-600" }, qa = {
3604
+ key: 4,
3605
+ class: "flex flex-col gap-4"
3606
+ }, Va = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, La = { class: "fm-typo-en-body-lg-600" }, ja = {
3607
+ key: 5,
3608
+ class: "flex flex-col gap-4"
3609
+ }, Ua = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ma = { class: "fm-typo-en-body-lg-600" }, Ba = { class: "border border-fm-color-neutral-gray-200 fm-corner-radius-lg p-16" }, za = { class: "flex flex-col gap-8" }, Ka = { class: "flex gap-8 items-center" }, Ha = { class: "flex-1 fm-typo-en-body-lg-600" }, Ga = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary flex flex-col gap-4" }, Wa = { class: "flex w-full gap-4" }, Qa = { class: "basis-1/2 shrink-0 grow fm-typo-en-body-lg-400 line-clamp-2 flex items-center gap-2" }, Ya = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary flex flex-col gap-2" }, Ja = { class: "fm-typo-en-body-lg-400 line-clamp-2" }, Xa = ["innerHTML"], Za = { class: "flex w-full gap-4 fm-typo-en-body-sm-400" }, el = { class: "grow fm-typo-en-body-lg-400 text-fm-color-typo-secondary line-clamp-1" }, tl = {
3610
+ key: 0,
3611
+ class: "flex items-center gap-4"
3612
+ }, sl = { class: "line-clamp-1 fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, rl = {
3613
+ key: 0,
3614
+ class: "inline-flex items-center gap-1 text-xs font-medium text-gray-500 bg-gray-100 px-2 py-0.5 rounded-full"
3615
+ }, ol = { class: "py-8" }, nl = { class: "flex justify-end gap-4 items-center" }, al = { class: "fm-typo-en-body-lg-600" }, ll = {
3616
+ key: 0,
3617
+ class: "flex justify-end"
3618
+ }, il = {
3619
+ key: 1,
3620
+ class: "flex-1 xs:w-screen xs:max-w-full"
3621
+ }, ul = {
3622
+ key: 0,
3623
+ class: "flex flex-col items-center gap-8 h-full"
3624
+ }, cl = ["src"], dl = { class: "fm-typo-en-body-lg-600" }, ml = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary px-16" }, pl = {
3625
+ key: 1,
3626
+ class: "px-4 flex flex-col"
3627
+ }, fl = { class: "flex gap-12 content-stretch" }, vl = {
3628
+ class: "flex flex-col w-40",
3629
+ name: "circles"
3630
+ }, yl = { class: "flex-1 flex flex-col items-center" }, hl = { class: "h-40 w-40 bg-fm-color-primary rounded-full flex items-center justify-center" }, bl = { class: "flex-1 flex flex-col items-center" }, gl = { class: "flex w-full items-center gap-4" }, _l = {
3631
+ class: "py-12 flex flex-col gap-4",
3632
+ name: "received-at header"
3633
+ }, Sl = { class: "fm-typo-en-body-lg-400" }, kl = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Ol = { class: "ml-auto flex gap-1" }, xl = { class: "flex gap-12 content-stretch" }, wl = {
3634
+ class: "flex flex-col w-40",
3635
+ name: "circles"
3636
+ }, $l = { class: "flex-1 flex flex-col items-center" }, Cl = {
3637
+ class: "py-12 flex flex-col gap-4 flex-1",
3638
+ name: "delivery details"
3639
+ }, Al = { class: "flex flex-col gap-8" }, Dl = { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, Rl = { class: "flex flex-col gap-4" }, Nl = {
3640
+ key: 2,
3641
+ class: "flex-1 xs:w-screen xs:max-w-full"
3642
+ }, Pl = {
3643
+ key: 0,
3644
+ class: "flex flex-col items-center gap-8 h-full"
3645
+ }, Fl = ["src"], Il = { class: "fm-typo-en-body-lg-600" }, Tl = {
3646
+ key: 1,
3647
+ class: "px-4 flex flex-col gap-12"
3648
+ }, El = { class: "flex flex-col gap-4" }, ql = { class: "flex justify-between gap-8" }, Vl = { class: "fm-typo-en-body-lg-600" }, Ll = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary whitespace-nowrap" }, jl = { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, Ul = {
3649
+ key: 0,
3650
+ class: "fm-typo-en-body-md-400"
3651
+ }, Ml = { class: "flex gap-8 xs:flex-col" }, _i = /* @__PURE__ */ Ve({
3652
+ __name: "TransferDetails",
3653
+ props: {
3654
+ poRequest: {},
3655
+ purchaseOrder: {},
3656
+ transferTo: {},
3657
+ transferToDbName: {},
3658
+ show: { type: Boolean },
3659
+ canResubmit: { type: Boolean },
3660
+ canApprove: { type: Boolean },
3661
+ scope: {},
3662
+ receivedMap: {},
3663
+ shipments: {}
3664
+ },
3665
+ emits: ["update:show", "submitted"],
3666
+ setup(d, { emit: t }) {
3667
+ const r = d, n = t, m = gt(), u = Je(), c = Xe(), s = ze(), a = bt(), { hasOrderDraftPermission: O } = gs(), f = hs();
3668
+ function R(o) {
3669
+ const l = o.isCustomCost, $ = o.totalCost;
3670
+ return l != null ? l === !0 : $ != null;
3671
+ }
3672
+ Ye(
3673
+ () => r.purchaseOrder,
3674
+ (o) => {
3675
+ f.init(o);
3676
+ },
3677
+ { immediate: !0 }
3678
+ );
3679
+ const N = H(
3680
+ () => {
3681
+ var o, l;
3682
+ return {
3683
+ id: ((o = a.sessionUser.value) == null ? void 0 : o.id) ?? "",
3684
+ name: ((l = a.sessionUser.value) == null ? void 0 : l.displayName) ?? ""
3685
+ };
3686
+ }
3687
+ ), F = bs(), { t: _ } = ht(), B = H(
3688
+ () => {
3689
+ var o, l, $, C;
3690
+ return ((l = (o = r.purchaseOrder) == null ? void 0 : o.supplier) == null ? void 0 : l.internal) === "restaurant" || ((C = ($ = r.purchaseOrder) == null ? void 0 : $.supplier) == null ? void 0 : C.internal) === "warehouse" ? at.enum.transfer : at.enum.purchase;
3691
+ }
3692
+ ), E = H(() => {
3693
+ var $;
3694
+ const o = ($ = r.shipments) == null ? void 0 : $.find((C) => {
3695
+ var q;
3696
+ return C.ref === ((q = r.purchaseOrder) == null ? void 0 : q._id);
3697
+ });
3698
+ let l = null;
3699
+ if (o != null && o.milestones && o.milestones.length > 0) {
3700
+ const C = o.milestones[o.milestones.length - 1];
3701
+ if (C.estimatedTime) {
3702
+ const q = new Date(C.estimatedTime), Y = q.getDate().toString().padStart(2, "0");
3703
+ l = `${q.toLocaleString("en-US", { month: "short" })} ${Y}`;
3704
+ }
3705
+ }
3706
+ return l;
3707
+ }), te = ne(!1), se = ne(""), Q = ne(!0), de = Ze(), Oe = Ys(de.getWorkflowConfig), ae = fs(), Se = [
3708
+ z.enum.receiveStock,
3709
+ z.enum.processRequest,
3710
+ z.enum.closeRequest
3711
+ ], De = H(() => {
3712
+ var pe, y, p, S, U, M, _e, xe, W;
3713
+ if (!r.purchaseOrder)
3714
+ return [];
3715
+ const o = Oe.result.value;
3716
+ if (o.state === Jt.loading)
3717
+ return [];
3718
+ let l;
3719
+ const $ = ns.safeParse(r.purchaseOrder);
3720
+ if ($.success)
3721
+ l = $.data;
3722
+ else {
3723
+ const X = /* @__PURE__ */ new Set(["1", "2"]), be = { line1: "", state: "", city: "", postcode: "", country: "" };
3724
+ l = {
3725
+ _id: ((pe = r.purchaseOrder) == null ? void 0 : pe._id) ?? "",
3726
+ status: ((y = r.purchaseOrder) == null ? void 0 : y.status) ?? ge.enum.DRAFT,
3727
+ version: X.has((p = r.purchaseOrder) == null ? void 0 : p.version) ? (S = r.purchaseOrder) == null ? void 0 : S.version : null,
3728
+ seqNumber: typeof ((U = r.purchaseOrder) == null ? void 0 : U.seqNumber) == "number" ? r.purchaseOrder.seqNumber : 0,
3729
+ supplier: {
3730
+ _id: ((_e = (M = r.purchaseOrder) == null ? void 0 : M.supplier) == null ? void 0 : _e._id) ?? "",
3731
+ name: ((W = (xe = r.purchaseOrder) == null ? void 0 : xe.supplier) == null ? void 0 : W.name) ?? "",
3732
+ address: be
3733
+ },
3734
+ items: [],
3735
+ deliveryOrder: []
3736
+ };
3737
+ }
3738
+ const C = {
3739
+ user: N.value,
3740
+ executedAt: s.locations.computeFirst(
3741
+ (X) => {
3742
+ var be;
3743
+ return X.dbName === ((be = s._currentLocation) == null ? void 0 : be.dbName) ? X : null;
3744
+ }
3745
+ ),
3746
+ // Strip purchaseOrder and netSuite from the POR before passing to the Dart
3747
+ // bridge — both can carry legacy PO snapshots with "" fields that fail the
3748
+ // bridge's unguarded `as Map<String,dynamic>` casts. Also validate the POR
3749
+ // itself through Zod first: legacy PORs can have null required string fields
3750
+ // (e.g. purchaseOrderId, from.dbName) that cause Dart's _asString to throw.
3751
+ // The workflow engine only needs from/to/processedAt/rejectedAt — passing
3752
+ // null for an unvalidatable POR yields the same available actions.
3753
+ purchaseOrderRequest: (() => {
3754
+ if (r.poRequest == null) return r.poRequest;
3755
+ const X = Es.safeParse(r.poRequest);
3756
+ return X.success ? { ...X.data, purchaseOrder: null, netSuite: null } : null;
3757
+ })(),
3758
+ purchaseOrder: l
3759
+ }, q = c.useOperatePurchaseOrderV2, Y = c.poWorkflowAllowToMarkCompleted, ye = [...Se];
3760
+ q && !Y && ye.push(z.enum.completeReceive);
3761
+ let I = [];
3762
+ try {
3763
+ o.state === Jt.error ? (console.error("Error fetching workflow config:", o.error), I = St.getAvailableActions({
3764
+ ...C,
3765
+ orderConfig: St.getDefaultConfig()
3766
+ }).actions.filter((X) => !ye.includes(X))) : I = St.getAvailableActions({
3767
+ ...C,
3768
+ orderConfig: o.data
3769
+ }).actions.filter((X) => !ye.includes(X));
3770
+ } catch (X) {
3771
+ console.error("Error getting available actions:", X);
3772
+ }
3773
+ return r.scope === "approval" && (I = I.filter((X) => X !== z.enum.completeReceive)), O.value || (I = I.filter(
3774
+ (X) => X !== z.enum.approveDraft && X !== z.enum.rejectDraft
3775
+ )), I;
3776
+ }), K = Bs(r, "show"), ve = H(() => [
3777
+ {
3778
+ label: _("inventory.transfer.receiveRequest.details.overview"),
3779
+ value: "overview"
3780
+ },
3781
+ {
3782
+ label: _("inventory.transfer.receiveRequest.details.deliveryHistory"),
3783
+ value: "deliveryHistory"
3784
+ },
3785
+ {
3786
+ label: _("inventory.transfer.receiveRequest.details.actionLogs"),
3787
+ value: "actionLogs"
3788
+ }
3789
+ ]), P = ne(ve.value[0]);
3790
+ Ye(
3791
+ () => r.show,
3792
+ (o) => {
3793
+ o && (P.value = ve.value[0]);
3794
+ }
3795
+ );
3796
+ function x(o) {
3797
+ return o.map((l) => ({
3798
+ ...l,
3799
+ amount: {
3800
+ ...l.amount,
3801
+ amount: -Math.abs(l.amount.amount)
3802
+ }
3803
+ }));
3804
+ }
3805
+ async function w(o, l, $, C, q) {
3806
+ return new Promise((Y, ye) => {
3807
+ const I = {
3808
+ closeButton: !1,
3809
+ title: C.title,
3810
+ message: C.message,
3811
+ primaryActions: C.primaryActions,
3812
+ secondaryActions: { text: "No", close: !1 }
3813
+ };
3814
+ let pe = l.rejectReason ?? "";
3815
+ $ === z.enum.rejectDraft && (I.contentComponent = ps, I.contentComponentProps = {
3816
+ message: C.message,
3817
+ onChange: (y) => {
3818
+ pe = y ?? "";
3819
+ }
3820
+ }), m.open(I).onPrimary(async () => {
3821
+ var p, S, U, M;
3822
+ const y = [];
3823
+ $ === z.enum.confirmDraft || $ === z.enum.submitRequest ? y.push({
3824
+ action: "confirmDraft",
3825
+ payload: f.controller.value.toConfirmDraftData(Ae())
3826
+ }) : $ === z.enum.approveRequest ? (y.push({
3827
+ action: "approveRequest",
3828
+ payload: null
3829
+ }), l.fulfillment && y.push({
3830
+ action: "processRequest",
3831
+ payload: {
3832
+ fulfillmentId: "",
3833
+ deliveryOrderNumber: "",
3834
+ deliveryRemark: null,
3835
+ items: x(l.fulfillment.items),
3836
+ createdBy: N.value
3837
+ }
3838
+ })) : $ === z.enum.processRequest ? l.fulfillment && y.push({
3839
+ action: "processRequest",
3840
+ payload: {
3841
+ fulfillmentId: "",
3842
+ deliveryOrderNumber: "",
3843
+ deliveryRemark: null,
3844
+ items: x(l.fulfillment.items),
3845
+ createdBy: N.value
3846
+ }
3847
+ }) : $ === z.enum.rejectRequest ? y.push({
3848
+ action: "rejectRequest",
3849
+ payload: null
3850
+ }) : $ === z.enum.closeRequest ? y.push({
3851
+ action: "closeRequest",
3852
+ payload: null
3853
+ }) : $ === z.enum.rejectDraft && y.push({
3854
+ action: "rejectDraft",
3855
+ payload: {
3856
+ rejectReason: pe ?? ""
3857
+ }
3858
+ });
3859
+ try {
3860
+ await ae({
3861
+ operate: {
3862
+ operation: $,
3863
+ doc: o,
3864
+ options: l
3865
+ },
3866
+ operateV2: {
3867
+ _id: ((p = r.purchaseOrder) == null ? void 0 : p._id) ?? "",
3868
+ _rev: ((S = r.purchaseOrder) == null ? void 0 : S._rev) ?? "",
3869
+ action: $ === z.enum.submitRequest ? z.enum.confirmDraft : $,
3870
+ payloads: y
3871
+ // add payload if action is receiveStock or processRequest
3872
+ },
3873
+ transferTo: (M = (U = r.poRequest) == null ? void 0 : U.to) == null ? void 0 : M.dbName
3874
+ }).delayed(1e3), Y("submitted");
3875
+ } catch (_e) {
3876
+ ye(_e);
3877
+ }
3878
+ }).onSecondary(() => {
3879
+ Y("cancelled");
3880
+ for (let y = 0; y < q + 2; y++)
3881
+ m.close();
3882
+ }).onClose(() => {
3883
+ });
3884
+ });
3885
+ }
3886
+ async function A(o) {
3887
+ var q, Y, ye, I;
3888
+ if (o === z.enum.receiveStock)
3889
+ return;
3890
+ const l = ms[o];
3891
+ if (!l) {
3892
+ u.open({
3893
+ title: "Something went wrong",
3894
+ message: `Cannot process order: ${Rt(o)}`,
3895
+ type: "error"
3896
+ });
3897
+ return;
3898
+ }
3899
+ const { successMessage: $, ...C } = l;
3900
+ if (r.purchaseOrder) {
3901
+ se.value = `${o}`, te.value = !0, Q.value = !1;
3902
+ const pe = {};
3903
+ let y = 0;
3904
+ if ((o === z.enum.confirmDraft || // auto receive for warehouse to warehouse
3905
+ o === z.enum.completeReceive) && c.autoReceiveWarehouse)
3906
+ pe.autoReceive = !0;
3907
+ else if ((o === z.enum.approveRequest || o === z.enum.processRequest) && c.acceptRequireFulfillment) {
3908
+ const p = (Y = (q = r.poRequest) == null ? void 0 : q.from) == null ? void 0 : Y.dbName, S = (I = (ye = r.poRequest) == null ? void 0 : ye.to) == null ? void 0 : I.dbName;
3909
+ if (p && S && (p.startsWith("warehouse_") || S.startsWith("warehouse_"))) {
3910
+ const U = await new Promise((M, _e) => {
3911
+ m.open({
3912
+ closeButton: !1,
3913
+ title: "Confirm transfer amount",
3914
+ dialogComponent: xr,
3915
+ dialogComponentProps: {
3916
+ purchaseOrder: r.purchaseOrder,
3917
+ confirm: M,
3918
+ "onUpdate:show": (xe) => {
3919
+ xe || (se.value = "", te.value = !1, Q.value = !0, y++, m.close()), _e("cancelled");
3920
+ }
3921
+ }
3922
+ });
3923
+ });
3924
+ pe.fulfillment = U;
3925
+ }
3926
+ }
3927
+ try {
3928
+ await w(
3929
+ r.purchaseOrder,
3930
+ pe,
3931
+ o,
3932
+ l,
3933
+ y
3934
+ ) === "submitted" && (u.open({
3935
+ title: "Success",
3936
+ message: $,
3937
+ type: "success"
3938
+ }), n("update:show", !1), n("submitted"));
3939
+ } catch (p) {
3940
+ u.open({
3941
+ title: "Something went wrong",
3942
+ message: p instanceof Error ? p.message : "Please try again.",
3943
+ type: "error"
3944
+ }), console.error("Error when submitting PO operation", o, r.purchaseOrder, p);
3945
+ } finally {
3946
+ se.value = "", te.value = !1, Q.value = !0;
3947
+ }
3948
+ }
3949
+ }
3950
+ const G = H(() => {
3951
+ var o, l;
3952
+ return ((o = r.purchaseOrder) == null ? void 0 : o.status) === ge.enum.RECEIVING || ((l = r.purchaseOrder) == null ? void 0 : l.status) === ge.enum.COMPLETE;
3953
+ }), Z = H(() => r.purchaseOrder ? vt(r.purchaseOrder) : {}), le = H(() => {
3954
+ const o = r.purchaseOrder;
3955
+ if (!o) return { status: "", statusClass: "" };
3956
+ const { partial: l, over: $ } = $t(Z.value), C = Ct(o.status, l, $);
3957
+ let q = _(`inventory.transfer.status.${C}`), Y = `${o.status}`.toLocaleLowerCase("en-us");
3958
+ return C === ge.enum.CLOSE && (q = `${_(`inventory.transfer.status.${ge.enum.COMPLETE}`)}`), C === "PARTIAL_RECEIVED" && Y === ge.enum.PROCESSING.toLocaleLowerCase("en-us") && (Y = ge.enum.RECEIVING.toLocaleLowerCase("en-us")), {
3959
+ status: q,
3960
+ statusClass: `fm-status-badge fm-status-badge-${Y}`
3961
+ };
3962
+ }), b = H(() => {
3963
+ var Y, ye;
3964
+ const o = ((Y = r.purchaseOrder) == null ? void 0 : Y.deliveryOrder) ?? [], l = ((ye = r.purchaseOrder) == null ? void 0 : ye.deliveryFullfillment) ?? [], $ = [
3965
+ ...o.map((I) => ({
3966
+ createdAt: I.createdAt,
3967
+ type: "grn",
3968
+ doc: I
3969
+ })),
3970
+ ...l.map((I) => ({
3971
+ createdAt: I.createdAt,
3972
+ type: "fulfillment",
3973
+ doc: I
3974
+ }))
3975
+ ];
3976
+ $.reverse().sort((I, pe) => I.createdAt.localeCompare(pe.createdAt));
3977
+ function C(I) {
3978
+ var p, S, U, M, _e, xe, W, X, be, Fe, Ie, fe;
3979
+ const pe = l.findIndex((ue) => ue.id === I.fullfillmentId), y = [
3980
+ (S = (p = l[pe]) == null ? void 0 : p.netSuite) != null && S.id ? {
3981
+ label: "Fulfillment's ref no. (Netsuite)",
3982
+ values: [
3983
+ `${((M = (U = l[pe]) == null ? void 0 : U.netSuite) == null ? void 0 : M.refNo) ?? "N/A"} (${((xe = (_e = l[pe]) == null ? void 0 : _e.netSuite) == null ? void 0 : xe.id) ?? "-"})`
3984
+ ]
3985
+ } : null,
3986
+ (W = I == null ? void 0 : I.netSuite) != null && W.id ? {
3987
+ label: "Netsuite ref no.",
3988
+ values: [`${((X = I == null ? void 0 : I.netSuite) == null ? void 0 : X.refNo) ?? "N/A"} (${((be = I == null ? void 0 : I.netSuite) == null ? void 0 : be.id) ?? "-"})`]
3989
+ } : null,
3990
+ (Fe = I == null ? void 0 : I.netSuite) != null && Fe.recordType ? {
3991
+ label: "Netsuite Type",
3992
+ values: [as((Ie = I == null ? void 0 : I.netSuite) == null ? void 0 : Ie.recordType)]
3993
+ } : null
3994
+ ];
3995
+ return {
3996
+ header: "Received",
3997
+ deliveryOrder: I,
3998
+ date: et(new Date(I.createdAt)),
3999
+ info: [
4000
+ {
4001
+ label: "Adjustment date",
4002
+ values: [
4003
+ I.adjustment ? et(new Date(mt(I.adjustment))) : "-"
4004
+ ]
4005
+ },
4006
+ {
4007
+ label: "Received by",
4008
+ values: [(fe = I.createdBy) == null ? void 0 : fe.name]
4009
+ },
4010
+ {
4011
+ label: "Received items",
4012
+ values: I.received.map((ue) => {
4013
+ var Ne;
4014
+ return re("div", [
4015
+ re(
4016
+ "div",
4017
+ {
4018
+ class: "flex gap-4"
4019
+ },
4020
+ [
4021
+ re(
4022
+ "div",
4023
+ {
4024
+ class: "flex flex-col"
4025
+ },
4026
+ [
4027
+ re(
4028
+ "span",
4029
+ {
4030
+ class: "fm-typo-en-body-lg-800 basis-1/2 shrink-0 grow"
4031
+ },
4032
+ `${ue.sku.name}`
4033
+ ),
4034
+ re(
4035
+ "span",
4036
+ {
4037
+ class: "fm-typo-en-body-md-400"
4038
+ },
4039
+ `${ue.sku.code} `
4040
+ )
4041
+ ]
4042
+ ),
4043
+ re(
4044
+ "div",
4045
+ {
4046
+ class: "ml-auto flex flex-col"
4047
+ },
4048
+ [
4049
+ re(
4050
+ "div",
4051
+ {
4052
+ class: "ml-auto flex gap-1"
4053
+ },
4054
+ [
4055
+ re(
4056
+ "span",
4057
+ {
4058
+ class: "fm-typo-en-body-lg-600 self-end"
4059
+ },
4060
+ $e(ue.amount, !1)
4061
+ ),
4062
+ re(
4063
+ "span",
4064
+ {
4065
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary"
4066
+ },
4067
+ ((Ne = ue.measurement) == null ? void 0 : Ne.abbrev) ?? ue.sku.unit.abbrev
4068
+ )
4069
+ ]
4070
+ ),
4071
+ re(
4072
+ "div",
4073
+ {
4074
+ class: "flex self-end fm-typo-en-body-md-400 text-fm-color-typo-secondary"
4075
+ },
4076
+ `${ue.cost ? `(${ut(ue.cost)})` : ""}`
4077
+ )
4078
+ ]
4079
+ )
4080
+ ]
4081
+ )
4082
+ ]);
4083
+ })
4084
+ },
4085
+ {
4086
+ label: "Delivery order no.",
4087
+ values: [I.deliveryOrderNumber || "N/A"]
4088
+ },
4089
+ {
4090
+ label: "Remark",
4091
+ values: [I.remark || "N/A"]
4092
+ },
4093
+ pe > -1 ? {
4094
+ label: "Fulfilment's sequence",
4095
+ values: [`${pe + 1}`]
4096
+ } : null,
4097
+ ...y
4098
+ ].filter((ue) => !!ue)
4099
+ };
4100
+ }
4101
+ function q(I) {
4102
+ var y, p, S;
4103
+ const pe = l.findIndex((U) => U.id === I.id);
4104
+ return {
4105
+ header: "Fulfillment",
4106
+ date: et(new Date(I.createdAt)),
4107
+ info: [
4108
+ {
4109
+ label: "Sequence",
4110
+ values: [String(pe + 1)]
4111
+ },
4112
+ {
4113
+ label: "Receiveable items",
4114
+ values: I.items.map((U) => {
4115
+ var M;
4116
+ return re("div", [
4117
+ re(
4118
+ "div",
4119
+ {
4120
+ class: "flex gap-4"
4121
+ },
4122
+ [
4123
+ re(
4124
+ "div",
4125
+ {
4126
+ class: "flex flex-col"
4127
+ },
4128
+ [
4129
+ re(
4130
+ "span",
4131
+ {
4132
+ class: "fm-typo-en-body-lg-800 basis-1/2 shrink-0 grow"
4133
+ },
4134
+ `${U.sku.name}`
4135
+ ),
4136
+ re(
4137
+ "span",
4138
+ {
4139
+ class: "fm-typo-en-body-md-400"
4140
+ },
4141
+ `${U.sku.code} `
4142
+ )
4143
+ ]
4144
+ ),
4145
+ re(
4146
+ "div",
4147
+ {
4148
+ class: "ml-auto flex flex-col"
4149
+ },
4150
+ [
4151
+ re(
4152
+ "div",
4153
+ {
4154
+ class: "ml-auto flex gap-1"
4155
+ },
4156
+ [
4157
+ re(
4158
+ "span",
4159
+ {
4160
+ class: "fm-typo-en-body-lg-600 self-end"
4161
+ },
4162
+ $e(U.amount, !1)
4163
+ ),
4164
+ re(
4165
+ "span",
4166
+ {
4167
+ class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary"
4168
+ },
4169
+ ((M = U.measurement) == null ? void 0 : M.abbrev) ?? U.sku.unit.abbrev
4170
+ )
4171
+ ]
4172
+ ),
4173
+ re(
4174
+ "div",
4175
+ {
4176
+ class: "flex self-end fm-typo-en-body-md-400 text-fm-color-typo-secondary"
4177
+ },
4178
+ `${U.cost ? `(${ut(U.cost)})` : ""}`
4179
+ )
4180
+ ]
4181
+ )
4182
+ ]
4183
+ )
4184
+ ]);
4185
+ })
4186
+ },
4187
+ (y = I.netSuite) != null && y.refNo ? {
4188
+ label: "Netsuite Ref no. (ID)",
4189
+ values: [`${(p = I.netSuite) == null ? void 0 : p.refNo} (${((S = I.netSuite) == null ? void 0 : S.id) ?? "-"})`]
4190
+ } : null
4191
+ ].filter((U) => !!U)
4192
+ };
4193
+ }
4194
+ return $.map(
4195
+ (I) => I.type === "grn" ? C(I.doc) : q(I.doc)
4196
+ );
4197
+ }), D = H(() => {
4198
+ const o = r.purchaseOrder;
4199
+ if (!o) return [];
4200
+ if (!o.itemsAtSubmission) return o.items ?? [];
4201
+ const l = new Set(o.itemsAtSubmission.map((C) => C.sku._id)), $ = [];
4202
+ for (const C of o.items ?? [])
4203
+ l.has(C.sku._id) || (l.add(C.sku._id), $.push(C));
4204
+ return [...o.itemsAtSubmission, ...$];
4205
+ }), ie = H(() => {
4206
+ const o = r.purchaseOrder;
4207
+ if (!o || o.version !== Ue.enum[2]) return r.receivedMap;
4208
+ const l = {}, $ = {};
4209
+ for (const q of o.items ?? [])
4210
+ l[q.sku._id] || (l[q.sku._id] = []), $[q.sku._id] = q.sku.unit.precision, q.id && l[q.sku._id].push(q.id);
4211
+ const C = {};
4212
+ for (const [q, Y] of Object.entries(l)) {
4213
+ const ye = Y.map((p) => r.receivedMap[p]).filter(Boolean);
4214
+ if (ye.length === 0) continue;
4215
+ const I = { amount: 0, precision: $[q] ?? 0 }, pe = ye.reduce((p, S) => Pe.add([p, S.total]), I), y = ye.reduce((p, S) => Pe.add([p, S.received]), I);
4216
+ C[q] = {
4217
+ key: q,
4218
+ total: pe,
4219
+ received: y,
4220
+ remaining: Pe.subtract([pe, y])
4221
+ };
4222
+ }
4223
+ return C;
4224
+ });
4225
+ function ee(o) {
4226
+ const l = ie.value[o.sku._id], $ = g(o);
4227
+ return l ? `<span class="${$} fm-typo-en-body-lg-600">${Pe.toFormatString({ value: l.received })}</span>/${ft(o.quantity, o.sku.unit, o.measurement)}` : `<span class="fm-typo-en-body-lg-600">-</span>/${ft(o.quantity, o.sku.unit, o.measurement)}`;
4228
+ }
4229
+ function L(o) {
4230
+ const l = r.purchaseOrder;
4231
+ return l != null && l.itemsAtSubmission ? !l.itemsAtSubmission.some(($) => $.sku._id === o.sku._id) : !1;
4232
+ }
4233
+ function g(o) {
4234
+ const l = ie.value[o.sku._id];
4235
+ if (!l)
4236
+ return "text-fm-color-typo-tertiary";
4237
+ const { isPartialReceive: $, isNoReceive: C, isOverReceive: q, isFullReceive: Y } = mr(l);
4238
+ return C ? "text-fm-color-typo-tertiary" : $ ? "text-fm-color-system-warning-300" : q ? "text-fm-color-system-error-300" : Y ? "text-fm-color-system-success-300" : "";
4239
+ }
4240
+ const j = H(() => {
4241
+ var o, l, $;
4242
+ return (o = r.purchaseOrder) != null && o.itemsAtSubmission ? ((l = r.purchaseOrder) == null ? void 0 : l.version) === Ue.enum[2] ? r.purchaseOrder.items.reduce((C, q) => {
4243
+ var ye, I;
4244
+ const Y = (I = (ye = r.purchaseOrder) == null ? void 0 : ye.itemsAtSubmission) == null ? void 0 : I.find(
4245
+ (pe) => pe.id === q.id
4246
+ );
4247
+ return Y && Y.quantity !== q.quantity && C.set(q.sku.code, {
4248
+ originalAmount: Number(Pe.toFormatString({ value: Y.quantity })),
4249
+ newAmount: Number(Pe.toFormatString({ value: q.quantity }))
4250
+ }), C;
4251
+ }, /* @__PURE__ */ new Map()) : ($ = r.purchaseOrder) == null ? void 0 : $.items.reduce((C, q) => {
4252
+ var pe, y;
4253
+ const Y = (y = (pe = r.purchaseOrder) == null ? void 0 : pe.itemsAtSubmission) == null ? void 0 : y.find(
4254
+ (p) => p.sku._id === q.sku._id
4255
+ ), ye = Y ? Number(Pe.toFormatString({ value: Y.quantity })) : 0, I = Number(Pe.toFormatString({ value: q.quantity }));
4256
+ return Y && ye !== I && C.set(q.sku.code, {
4257
+ originalAmount: ye,
4258
+ newAmount: I
4259
+ }), C;
4260
+ }, /* @__PURE__ */ new Map()) : /* @__PURE__ */ new Map();
4261
+ }), J = (o) => {
4262
+ var $, C;
4263
+ const l = j.value;
4264
+ return (($ = r.purchaseOrder) == null ? void 0 : $.version) === Ue.enum[2] ? l.has(o.id) : l.has((C = o.sku) == null ? void 0 : C.code);
4265
+ }, me = (o) => {
4266
+ var $, C;
4267
+ const l = j.value;
4268
+ return (($ = r.purchaseOrder) == null ? void 0 : $.version) === Ue.enum[2] ? l.get(o.id) : l.get((C = o.sku) == null ? void 0 : C.code);
4269
+ }, ke = H(() => {
4270
+ const o = r.purchaseOrder;
4271
+ if (!o) return "";
4272
+ const l = o.actionChangelogs ?? [], $ = l.length ? l[l.length - 1] : null;
4273
+ if ($ && $.action === "rejectDraft") {
4274
+ const C = $.remarks ?? "";
4275
+ return C && C.toString().trim() !== "" ? C.toString() : "-";
4276
+ }
4277
+ return "";
4278
+ }), we = H(() => {
4279
+ const o = r.purchaseOrder;
4280
+ return o ? [...o.actionChangelogs ?? []].reverse() : [];
4281
+ });
4282
+ return (o, l) => {
4283
+ const $ = oe("FmButton"), C = oe("FmButtonGroup"), q = oe("FmChip"), Y = oe("FmIcon"), ye = oe("FmMenuDivider"), I = oe("FmCard"), pe = oe("FmTooltip"), y = oe("FmSpacer"), p = oe("FmSideSheet");
4284
+ return i(), he(p, {
4285
+ modelValue: h(K),
4286
+ "onUpdate:modelValue": l[9] || (l[9] = (S) => Rs(K) ? K.value = S : null),
4287
+ "dismiss-away": Q.value,
4288
+ "max-width": 600,
4289
+ "close-button": !1
4290
+ }, {
4291
+ "side-sheet-header": ce(() => {
4292
+ var S, U;
4293
+ return [
4294
+ e("div", ea, [
4295
+ e("div", ta, [
4296
+ e("div", sa, k(h(_)("inventory.transfer.receiveRequest.details.title") + ((S = o.purchaseOrder) != null && S.seqNumber ? ` #${(U = o.purchaseOrder) == null ? void 0 : U.seqNumber}` : "")), 1),
4297
+ T($, {
4298
+ class: "ml-auto -m-2",
4299
+ variant: "tertiary",
4300
+ "prepend-icon": "close",
4301
+ onClick: l[0] || (l[0] = (M) => n("update:show", !1))
4302
+ })
4303
+ ]),
4304
+ T(C, {
4305
+ items: ve.value,
4306
+ modelValue: P.value,
4307
+ "onUpdate:modelValue": l[1] || (l[1] = (M) => P.value = M)
4308
+ }, null, 8, ["items", "modelValue"]),
4309
+ o.purchaseOrder && P.value.value === "deliveryHistory" ? (i(), he(Nn, {
4310
+ key: 0,
4311
+ "purchase-order": o.purchaseOrder,
4312
+ "received-info-map": Z.value,
4313
+ "received-map": o.receivedMap,
4314
+ onSubmitted: l[2] || (l[2] = () => {
4315
+ n("update:show", !1), n("submitted");
4316
+ })
4317
+ }, null, 8, ["purchase-order", "received-info-map", "received-map"])) : V("", !0)
4318
+ ])
4319
+ ];
4320
+ }),
4321
+ default: ce(() => {
4322
+ var S, U, M, _e, xe;
4323
+ return [
4324
+ e("div", ra, [
4325
+ P.value.value === "overview" ? (i(), v(Ce, { key: 0 }, [
4326
+ e("div", null, [
4327
+ T(I, {
4328
+ variant: "outlined",
4329
+ class: "flex flex-col gap-8 px-12 py-16"
4330
+ }, {
4331
+ default: ce(() => {
4332
+ var W, X, be, Fe, Ie, fe, ue, Ne, Ee, Le;
4333
+ return [
4334
+ e("div", oa, [
4335
+ e("div", na, k(h(_)("inventory.transfer.receiveRequest.details.requestSummary")), 1),
4336
+ e("div", aa, [
4337
+ T(q, {
4338
+ label: le.value.status,
4339
+ class: We(le.value.statusClass),
4340
+ compact: ""
4341
+ }, null, 8, ["label", "class"]),
4342
+ E.value ? (i(), v("div", la, [
4343
+ T(Y, {
4344
+ name: "local_shipping",
4345
+ color: "#666666"
4346
+ }),
4347
+ e("span", ia, k(E.value), 1)
4348
+ ])) : V("", !0)
4349
+ ])
4350
+ ]),
4351
+ T(ye),
4352
+ e("div", ua, [
4353
+ T(ts, { title: "Debug Info" }, {
4354
+ default: ce(() => {
4355
+ var it, Tt, Et, qt, Vt, Lt, jt, Ut, Mt, Bt, zt, Kt;
4356
+ return [
4357
+ (it = o.purchaseOrder) != null && it._id ? (i(), v("div", ca, [
4358
+ l[10] || (l[10] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Purchase Order ID ", -1)),
4359
+ e("span", da, k((Tt = o.purchaseOrder) == null ? void 0 : Tt._id), 1)
4360
+ ])) : V("", !0),
4361
+ (Et = o.purchaseOrder) != null && Et.status ? (i(), v("div", ma, [
4362
+ l[11] || (l[11] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Purchase Order Status ", -1)),
4363
+ e("span", pa, k((qt = o.purchaseOrder) == null ? void 0 : qt.status), 1)
4364
+ ])) : V("", !0),
4365
+ (Lt = (Vt = o.purchaseOrder) == null ? void 0 : Vt.supplier) != null && Lt._id ? (i(), v("div", fa, [
4366
+ l[12] || (l[12] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Source Location ID ", -1)),
4367
+ e("span", va, k(((Ut = (jt = o.purchaseOrder) == null ? void 0 : jt.supplier) == null ? void 0 : Ut.internal) != null ? `${(Bt = (Mt = o.purchaseOrder) == null ? void 0 : Mt.supplier) == null ? void 0 : Bt.internal}_` : "") + k((Kt = (zt = o.purchaseOrder) == null ? void 0 : zt.supplier) == null ? void 0 : Kt._id), 1)
4368
+ ])) : V("", !0),
4369
+ o.transferToDbName ? (i(), v("div", ya, [
4370
+ l[13] || (l[13] = e("span", { class: "fm-typo-en-body-sm-400 text-fm-color-typo-secondary" }, " Destination Location ID ", -1)),
4371
+ e("span", ha, k(o.transferToDbName), 1)
4372
+ ])) : V("", !0)
4373
+ ];
4374
+ }),
4375
+ _: 1
4376
+ }),
4377
+ e("div", ba, [
4378
+ e("div", ga, [
4379
+ e("div", _a, k(h(_)("inventory.transfer.receiveRequest.details.createdAt")), 1)
4380
+ ]),
4381
+ e("div", Sa, k(h(lt)(((W = o.purchaseOrder) == null ? void 0 : W._id) ?? "")), 1)
4382
+ ]),
4383
+ (X = o.purchaseOrder) != null && X.effectiveAt ? (i(), v("div", ka, [
4384
+ e("div", Oa, k(h(_)("inventory.transfer.receiveRequest.details.date")), 1),
4385
+ e("div", xa, k(h(Nt)(new Date((be = o.purchaseOrder) == null ? void 0 : be.effectiveAt))), 1)
4386
+ ])) : V("", !0),
4387
+ e("div", wa, [
4388
+ e("div", $a, k(h(_)("inventory.transfer.receiveRequest.details.type.title")), 1),
4389
+ e("div", Ca, k(h(_)(
4390
+ `inventory.transfer.receiveRequest.details.type.${B.value.toLocaleLowerCase("en-US")}`
4391
+ )), 1)
4392
+ ]),
4393
+ (Ie = (Fe = o.purchaseOrder) == null ? void 0 : Fe.supplier) != null && Ie.name ? (i(), v("div", Aa, [
4394
+ e("div", Da, k(h(_)("inventory.transfer.receiveRequest.details.from")), 1),
4395
+ e("div", Ra, k((ue = (fe = o.purchaseOrder) == null ? void 0 : fe.supplier) == null ? void 0 : ue.name), 1)
4396
+ ])) : V("", !0),
4397
+ o.transferTo ? (i(), v("div", Na, [
4398
+ e("div", Pa, k(h(_)("inventory.transfer.receiveRequest.details.to")), 1),
4399
+ e("div", Fa, k(o.transferTo), 1)
4400
+ ])) : V("", !0),
4401
+ (Ne = o.purchaseOrder) != null && Ne.ref ? (i(), v("div", Ia, [
4402
+ e("div", Ta, k(h(_)("inventory.transfer.receiveRequest.details.reference")), 1),
4403
+ e("div", Ea, k(o.purchaseOrder.ref), 1)
4404
+ ])) : V("", !0),
4405
+ (Ee = o.purchaseOrder) != null && Ee.remark ? (i(), v("div", qa, [
4406
+ e("div", Va, k(h(_)("inventory.transfer.receiveRequest.details.remark")), 1),
4407
+ e("div", La, k(o.purchaseOrder.remark), 1)
4408
+ ])) : V("", !0),
4409
+ ((Le = o.purchaseOrder) == null ? void 0 : Le.status) === h(ge).enum.DRAFT && ke.value ? (i(), v("div", ja, [
4410
+ e("div", Ua, k(h(_)("inventory.transfer.receiveRequest.details.rejectionReason")), 1),
4411
+ e("div", Ma, k(ke.value !== "" ? ke.value : "-"), 1)
4412
+ ])) : V("", !0)
4413
+ ])
4414
+ ];
4415
+ }),
4416
+ _: 1
4417
+ })
4418
+ ]),
4419
+ T(So, {
4420
+ "po-request": o.poRequest,
4421
+ purchaseOrder: o.purchaseOrder,
4422
+ transferType: B.value,
4423
+ transferToDbName: o.transferToDbName,
4424
+ scope: o.scope
4425
+ }, null, 8, ["po-request", "purchaseOrder", "transferType", "transferToDbName", "scope"]),
4426
+ e("div", Ba, [
4427
+ e("div", za, [
4428
+ e("div", Ka, [
4429
+ e("span", Ha, [
4430
+ Ge(k(G.value ? h(_)("inventory.transfer.receiveRequest.details.receivedItems") : h(_)("inventory.transfer.receiveRequest.details.requestedItems")) + " ", 1),
4431
+ (U = (S = o.purchaseOrder) == null ? void 0 : S.netSuite) != null && U.missingItems && ((_e = (M = o.purchaseOrder) == null ? void 0 : M.netSuite) == null ? void 0 : _e.missingItems.length) > 0 ? (i(), he(pe, {
4432
+ key: 0,
4433
+ variant: "rich",
4434
+ placement: "top",
4435
+ "z-index": 51
4436
+ }, {
4437
+ content: ce(() => {
4438
+ var W, X;
4439
+ return [
4440
+ e("div", Ga, [
4441
+ (i(!0), v(Ce, null, Te((X = (W = o.purchaseOrder) == null ? void 0 : W.netSuite) == null ? void 0 : X.missingItems, (be, Fe) => (i(), v("div", {
4442
+ class: "flex justify-center align-middle",
4443
+ key: Fe
4444
+ }, [
4445
+ T(Y, {
4446
+ name: "arrow_right",
4447
+ size: "sm"
4448
+ }),
4449
+ Ge(" " + k(`(${be.netSuiteId}) ${be.name}: ${be.reason}`), 1)
4450
+ ]))), 128))
4451
+ ])
4452
+ ];
4453
+ }),
4454
+ default: ce(() => [
4455
+ T(Y, {
4456
+ name: "error",
4457
+ color: "#ff2c2c",
4458
+ size: "sm"
4459
+ })
4460
+ ]),
4461
+ _: 1
4462
+ })) : V("", !0)
4463
+ ])
4464
+ ]),
4465
+ T(ye),
4466
+ (i(!0), v(Ce, null, Te(D.value, (W, X) => {
4467
+ var be, Fe;
4468
+ return i(), v("div", {
4469
+ key: X,
4470
+ class: "flex flex-col"
4471
+ }, [
4472
+ e("div", Wa, [
4473
+ e("div", Qa, [
4474
+ Ge(k(W.name) + " ", 1),
4475
+ L(W) ? (i(), he(pe, {
4476
+ key: 0,
4477
+ variant: "rich",
4478
+ placement: "top",
4479
+ "z-index": 51
4480
+ }, {
4481
+ content: ce(() => l[14] || (l[14] = [
4482
+ e("div", { class: "fm-typo-en-body-md-400 text-fm-color-typo-secondary" }, " Extra item (added during delivery) ", -1)
4483
+ ])),
4484
+ default: ce(() => [
4485
+ T(Y, {
4486
+ name: "add_circle",
4487
+ color: "#6b7280",
4488
+ size: "sm"
4489
+ })
4490
+ ]),
4491
+ _: 1
4492
+ })) : V("", !0),
4493
+ J(W) ? (i(), he(pe, {
4494
+ key: 1,
4495
+ variant: "rich",
4496
+ placement: "top",
4497
+ "z-index": 51
4498
+ }, {
4499
+ content: ce(() => {
4500
+ var Ie, fe;
4501
+ return [
4502
+ e("div", Ya, [
4503
+ l[15] || (l[15] = e("div", { class: "font-semibold" }, "Submission changes", -1)),
4504
+ e("div", null, "Original Amount: " + k((Ie = me(W)) == null ? void 0 : Ie.originalAmount), 1),
4505
+ e("div", null, " New Amount: " + k((fe = me(W)) == null ? void 0 : fe.newAmount), 1)
4506
+ ])
4507
+ ];
4508
+ }),
4509
+ default: ce(() => [
4510
+ T(Y, {
4511
+ name: "error",
4512
+ color: "#ff9500",
4513
+ size: "sm"
4514
+ })
4515
+ ]),
4516
+ _: 2
4517
+ }, 1024)) : V("", !0)
4518
+ ]),
4519
+ e("div", Ja, [
4520
+ e("span", {
4521
+ innerHTML: ee(W)
4522
+ }, null, 8, Xa)
4523
+ ])
4524
+ ]),
4525
+ e("div", Za, [
4526
+ e("div", el, k(W.code), 1),
4527
+ h(c).enableTotalCost && ((be = W.totalCost) != null && be.amount || typeof W.sku == "object" && W.sku != null) ? (i(), v("div", tl, [
4528
+ e("span", sl, k(h(ut)(
4529
+ (Fe = W.totalCost) != null && Fe.amount ? W.totalCost : h(f).controller.value.getItemCost(W, h(Ae)()).cost
4530
+ )), 1),
4531
+ R(W) ? V("", !0) : (i(), v("span", rl, [
4532
+ l[16] || (l[16] = e("span", { class: "w-1.5 h-1.5 rounded-full bg-gray-400" }, null, -1)),
4533
+ Ge(" " + k(h(_)("inventory.transfer.form.items.autoCalculated")), 1)
4534
+ ]))
4535
+ ])) : V("", !0)
4536
+ ])
4537
+ ]);
4538
+ }), 128)),
4539
+ +h($e)(h(f).controller.value.getTotalCosts()) ? (i(), v(Ce, { key: 0 }, [
4540
+ e("div", ol, [
4541
+ T(ye)
4542
+ ]),
4543
+ e("div", nl, [
4544
+ l[17] || (l[17] = e("div", { class: "fm-typo-en-body-lg-400 text-fm-color-typo-secondary" }, "Total:", -1)),
4545
+ e("div", al, k(h(Ae)()) + " " + k(h(ut)({
4546
+ ...h(f).controller.value.getTotalCosts(),
4547
+ currency: h(Ae)()
4548
+ }).replace(/[^0-9.,]/g, "")), 1)
4549
+ ])
4550
+ ], 64)) : V("", !0),
4551
+ h(c).enablePurchaseOrderPriceAdjustment ? (i(), v(Ce, { key: 1 }, [
4552
+ T(Tn, {
4553
+ adjustments: (xe = o.purchaseOrder) == null ? void 0 : xe.priceAdjustments
4554
+ }, null, 8, ["adjustments"]),
4555
+ o.purchaseOrder ? (i(), v("div", ll, [
4556
+ T(qn, {
4557
+ "purchase-order": o.purchaseOrder,
4558
+ onSubmitted: l[3] || (l[3] = () => {
4559
+ n("update:show", !1), n("submitted");
4560
+ })
4561
+ }, null, 8, ["purchase-order"])
4562
+ ])) : V("", !0)
4563
+ ], 64)) : V("", !0)
4564
+ ])
4565
+ ])
4566
+ ], 64)) : P.value.value === "deliveryHistory" ? (i(), v("div", il, [
4567
+ b.value.length ? (i(), v("div", pl, [
4568
+ (i(!0), v(Ce, null, Te(b.value, (W, X) => {
4569
+ var be, Fe, Ie, fe, ue;
4570
+ return i(), v(Ce, { key: X }, [
4571
+ e("div", fl, [
4572
+ e("div", vl, [
4573
+ e("div", yl, [
4574
+ e("div", {
4575
+ class: We([
4576
+ {
4577
+ "bg-fm-color-primary": X !== 0,
4578
+ "bg-white": X === 0
4579
+ },
4580
+ "w-[2px] h-full"
4581
+ ])
4582
+ }, null, 2)
4583
+ ]),
4584
+ e("div", hl, [
4585
+ W.header === "Received" ? (i(), he(Y, {
4586
+ key: 0,
4587
+ name: "local_shipping",
4588
+ outline: "",
4589
+ color: "#ffffff"
4590
+ })) : V("", !0)
4591
+ ]),
4592
+ e("div", bl, [
4593
+ e("div", {
4594
+ class: We([
4595
+ {
4596
+ "bg-fm-color-primary": X < b.value.length - 1,
4597
+ "bg-white": X >= b.value.length - 1
4598
+ },
4599
+ "w-[2px] h-full"
4600
+ ])
4601
+ }, null, 2)
4602
+ ])
4603
+ ]),
4604
+ e("div", gl, [
4605
+ e("div", _l, [
4606
+ e("div", Sl, k(W.header), 1),
4607
+ e("div", kl, k(W.date), 1)
4608
+ ]),
4609
+ e("div", Ol, [
4610
+ W.header === "Received" && W.deliveryOrder && o.purchaseOrder ? (i(), he(Qo, {
4611
+ key: 0,
4612
+ deliveryOrder: W.deliveryOrder,
4613
+ purchaseOrder: o.purchaseOrder,
4614
+ "received-info-map": Z.value,
4615
+ onSubmitted: l[4] || (l[4] = () => {
4616
+ n("update:show", !1), n("submitted");
4617
+ })
4618
+ }, null, 8, ["deliveryOrder", "purchaseOrder", "received-info-map"])) : V("", !0),
4619
+ (Fe = (be = W.deliveryOrder) == null ? void 0 : be.netSuite) != null && Fe.id ? (i(), he(ts, {
4620
+ key: 1,
4621
+ title: "Admin",
4622
+ class: "min-w-[140px]"
4623
+ }, {
4624
+ default: ce(() => {
4625
+ var Ne, Ee;
4626
+ return [
4627
+ T(Zn, {
4628
+ "netsuite-id": (Ee = (Ne = W.deliveryOrder) == null ? void 0 : Ne.netSuite) == null ? void 0 : Ee.id
4629
+ }, null, 8, ["netsuite-id"])
4630
+ ];
4631
+ }),
4632
+ _: 2
4633
+ }, 1024)) : V("", !0),
4634
+ o.purchaseOrder && ((Ie = W.deliveryOrder) != null && Ie.id) ? (i(), he(Hs, {
4635
+ key: 2,
4636
+ "purchase-order-id": (fe = o.purchaseOrder) == null ? void 0 : fe._id,
4637
+ "delivery-order-id": (ue = W.deliveryOrder) == null ? void 0 : ue.id
4638
+ }, null, 8, ["purchase-order-id", "delivery-order-id"])) : V("", !0)
4639
+ ])
4640
+ ])
4641
+ ]),
4642
+ e("div", xl, [
4643
+ e("div", wl, [
4644
+ e("div", $l, [
4645
+ e("div", {
4646
+ class: We([
4647
+ {
4648
+ "bg-fm-color-primary": X < b.value.length - 1,
4649
+ "bg-white": X >= b.value.length - 1
4650
+ },
4651
+ "w-[2px] h-full"
4652
+ ])
4653
+ }, null, 2)
4654
+ ])
4655
+ ]),
4656
+ e("div", Cl, [
4657
+ T(I, {
4658
+ variant: "outlined",
4659
+ class: "py-12 px-16"
4660
+ }, {
4661
+ default: ce(() => [
4662
+ e("div", Al, [
4663
+ (i(!0), v(Ce, null, Te(W.info, (Ne, Ee) => (i(), v("div", {
4664
+ key: Ee,
4665
+ class: "flex flex-col gap-4"
4666
+ }, [
4667
+ e("div", Dl, k(Ne == null ? void 0 : Ne.label), 1),
4668
+ e("div", Rl, [
4669
+ (i(!0), v(Ce, null, Te(Ne == null ? void 0 : Ne.values, (Le, it) => (i(), v("div", {
4670
+ key: it,
4671
+ class: "fm-typo-en-body-lg-600"
4672
+ }, [
4673
+ typeof Le == "string" ? (i(), v(Ce, { key: 0 }, [
4674
+ Ge(k(Le), 1)
4675
+ ], 64)) : (i(), he(Ns(Le), { key: 1 }))
4676
+ ]))), 128))
4677
+ ])
4678
+ ]))), 128))
4679
+ ])
4680
+ ]),
4681
+ _: 2
4682
+ }, 1024)
4683
+ ])
4684
+ ])
4685
+ ], 64);
4686
+ }), 128))
4687
+ ])) : (i(), v("div", ul, [
4688
+ T(y),
4689
+ e("div", null, [
4690
+ e("img", {
4691
+ src: h(Yt),
4692
+ alt: "List is empty"
4693
+ }, null, 8, cl)
4694
+ ]),
4695
+ e("div", dl, k(h(_)("inventory.transfer.receiveRequest.details.noRecordsFound")), 1),
4696
+ e("div", ml, k(h(_)("inventory.transfer.receiveRequest.details.trackDeliveryMessage")), 1),
4697
+ T(y),
4698
+ T(y)
4699
+ ]))
4700
+ ])) : P.value.value === "actionLogs" ? (i(), v("div", Nl, [
4701
+ we.value.length ? (i(), v("div", Tl, [
4702
+ (i(!0), v(Ce, null, Te(we.value, (W, X) => (i(), he(I, {
4703
+ key: X,
4704
+ variant: "outlined",
4705
+ class: "py-12 px-16"
4706
+ }, {
4707
+ default: ce(() => {
4708
+ var be;
4709
+ return [
4710
+ e("div", El, [
4711
+ e("div", ql, [
4712
+ e("div", Vl, k(h(nt)[W.action] ? h(_)(h(nt)[W.action].translationKey) : W.action), 1),
4713
+ e("div", Ll, k(h(et)(W.changedAt)), 1)
4714
+ ]),
4715
+ e("div", jl, k((be = W.changedBy) == null ? void 0 : be.name), 1),
4716
+ W.remarks ? (i(), v("div", Ul, k(W.remarks), 1)) : V("", !0)
4717
+ ])
4718
+ ];
4719
+ }),
4720
+ _: 2
4721
+ }, 1024))), 128))
4722
+ ])) : (i(), v("div", Pl, [
4723
+ T(y),
4724
+ e("div", null, [
4725
+ e("img", {
4726
+ src: h(Yt),
4727
+ alt: "List is empty"
4728
+ }, null, 8, Fl)
4729
+ ]),
4730
+ e("div", Il, k(h(_)("inventory.transfer.receiveRequest.details.noActionLogs")), 1),
4731
+ T(y),
4732
+ T(y)
4733
+ ]))
4734
+ ])) : V("", !0)
4735
+ ])
4736
+ ];
4737
+ }),
4738
+ "side-sheet-footer": ce(() => [
4739
+ e("div", Ml, [
4740
+ (i(!0), v(Ce, null, Te(De.value, (S) => (i(), v(Ce, null, [
4741
+ h(nt)[S].available != !1 ? (i(), he($, {
4742
+ key: S,
4743
+ label: h(_)(h(nt)[S].translationKey),
4744
+ onClick: (U) => A(S),
4745
+ loading: se.value === S,
4746
+ disabled: se.value !== S && te.value,
4747
+ variant: h(nt)[S].buttonVariant
4748
+ }, null, 8, ["label", "onClick", "loading", "disabled", "variant"])) : V("", !0)
4749
+ ], 64))), 256)),
4750
+ h(F).ableToMarkReceived(o.purchaseOrder) && !De.value.includes("completeReceive") ? (i(), he($, {
4751
+ key: 0,
4752
+ label: h(_)("inventory.transfer.receiveRequest.actions.completeReceive"),
4753
+ onClick: l[5] || (l[5] = (S) => A("completeReceive")),
4754
+ loading: se.value === "completeReceive",
4755
+ disabled: se.value !== "completeReceive" && te.value
4756
+ }, null, 8, ["label", "loading", "disabled"])) : V("", !0),
4757
+ h(F).ableToMarkApproved(o.purchaseOrder) && o.canApprove && !De.value.includes("approveRequest") ? (i(), he($, {
4758
+ key: 1,
4759
+ label: h(_)("inventory.transfer.approval.actions.approveRequest"),
4760
+ onClick: l[6] || (l[6] = (S) => A("approveRequest")),
4761
+ loading: se.value === "approveRequest",
4762
+ disabled: se.value !== "approveRequest" && te.value
4763
+ }, null, 8, ["label", "loading", "disabled"])) : V("", !0),
4764
+ h(F).ableToCreateFulfillment(o.purchaseOrder, o.poRequest) && r.scope === "approval" ? (i(), he($, {
4765
+ key: 2,
4766
+ label: h(_)("inventory.transfer.receiveRequest.actions.processRequest"),
4767
+ onClick: l[7] || (l[7] = (S) => A("processRequest")),
4768
+ loading: se.value === "processRequest",
4769
+ disabled: se.value !== "processRequest" && te.value
4770
+ }, null, 8, ["label", "loading", "disabled"])) : V("", !0),
4771
+ T($, {
4772
+ label: h(_)("common.close"),
4773
+ variant: "tertiary",
4774
+ onClick: l[8] || (l[8] = (S) => n("update:show", !1))
4775
+ }, null, 8, ["label"])
4776
+ ])
4777
+ ]),
4778
+ _: 1
4779
+ }, 8, ["modelValue", "dismiss-away"]);
4780
+ };
4781
+ }
4782
+ });
4783
+ export {
4784
+ At as P,
4785
+ _i as _,
4786
+ gi as a,
4787
+ ir as b,
4788
+ ps as c,
4789
+ ms as d,
4790
+ hs as e,
4791
+ vt as f,
4792
+ us as g,
4793
+ fs as h,
4794
+ It as i,
4795
+ Ft as j,
4796
+ bi as u
4797
+ };