@feedmepos/mf-inventory-portal 1.7.13-dev.4 → 1.7.14

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