@accounter/client 0.0.11-alpha-20260126140805-098cb12019a98fcf50be8b4f6d423adef45f1f8e → 0.0.11-alpha-20260126203116-e4ae2d445da89ef2194deb61fef02975089397cb

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 (87) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/assets/{Checkbox-Dmuz3t7B.js → Checkbox-De6ghCZT.js} +1 -1
  3. package/dist/assets/{MultiSelect-DBeIExB5.js → MultiSelect-Ca6lO0tL.js} +1 -1
  4. package/dist/assets/{Progress---sZILQb.js → Progress-26V_Zxr-.js} +1 -1
  5. package/dist/assets/{Table-BQv3frL8.js → Table-8-ldSKpC.js} +1 -1
  6. package/dist/assets/{Typography-B8Kph7eR.js → Typography-DyOGysfv.js} +1 -1
  7. package/dist/assets/{accordion-Bn08_4fN.js → accordion-DP7ZozTk.js} +1 -1
  8. package/dist/assets/{accountant-approvals-DuNl7y6H.js → accountant-approvals-DKeksuRo.js} +1 -1
  9. package/dist/assets/{accounter-table-DTsgtq5M.js → accounter-table-D91AAtb3.js} +1 -1
  10. package/dist/assets/{addDays-DTiBTTns.js → addDays-DbQpcl70.js} +1 -1
  11. package/dist/assets/{all-charges-DPyM-a74.js → all-charges-C25sw4Vw.js} +1 -1
  12. package/dist/assets/{arrow-up-down-VY6mkkTR.js → arrow-up-down-Du86WmzT.js} +1 -1
  13. package/dist/assets/{building-2-CMKd_bU8.js → building-2-BgbaTAJm.js} +1 -1
  14. package/dist/assets/{business-BVMKhHFx.js → business-B_k5j_ba.js} +1 -1
  15. package/dist/assets/{business-extended-info-B94y5ZK6.js → business-extended-info-Dn8Jjrlr.js} +1 -1
  16. package/dist/assets/{business-header-BC86M-9m.js → business-header-CVNY-ll1.js} +1 -1
  17. package/dist/assets/{business-ledger-filters-es3H4rPK.js → business-ledger-filters-Ctqgcwo5.js} +1 -1
  18. package/dist/assets/{business-ledger-single-U3zkqgW2.js → business-ledger-single-B2zYi6oe.js} +1 -1
  19. package/dist/assets/business-trip-BTFVFqTb.js +1 -0
  20. package/dist/assets/charge-BiCrKZ5S.js +1 -0
  21. package/dist/assets/{charges-filters-CFCAP-bP.js → charges-filters-Ss76EpGY.js} +1 -1
  22. package/dist/assets/{charges-ledger-validation-CCTNRpCE.js → charges-ledger-validation-829LsQIR.js} +1 -1
  23. package/dist/assets/charges-table-CmHxXzVR.js +7 -0
  24. package/dist/assets/{contracts-ljjcB_x7.js → contracts-CoybM2nI.js} +1 -1
  25. package/dist/assets/{data-table-column-header-CZ1dXiU0.js → data-table-column-header-_ZrN0Vs6.js} +1 -1
  26. package/dist/assets/{data-table-pagination-XAlQIbO9.js → data-table-pagination-DAvY_qBU.js} +1 -1
  27. package/dist/assets/{deposits-transactions-table-2rtRFZgK.js → deposits-transactions-table-DGuOHsiS.js} +1 -1
  28. package/dist/assets/{download-csv-BSGaUZsM.js → download-csv-CI8CQmZN.js} +1 -1
  29. package/dist/assets/{download-csv-button-CMQBUQeX.js → download-csv-button-C12VYNQh.js} +1 -1
  30. package/dist/assets/{editable-business-trip-CED1Su3d.js → editable-business-trip-DEIjhoGd.js} +1 -1
  31. package/dist/assets/{eye-off-Buv7eciz.js → eye-off-DPLQFIHz.js} +1 -1
  32. package/dist/assets/{funnel-Cfb9Pxmr.js → funnel-DrbTHWGk.js} +1 -1
  33. package/dist/assets/{index-GlUqZUgQ.js → index-6voPIuBc.js} +1 -1
  34. package/dist/assets/{index-X3RoQQa9.js → index-B48UbZgd.js} +1 -1
  35. package/dist/assets/{index-Dq33WQoi.js → index-B6dfuYIx.js} +1 -1
  36. package/dist/assets/{index-B0hZ0TDG.js → index-BFXVaxb0.js} +1 -1
  37. package/dist/assets/{index-BhFsGqUx.js → index-BWVeSaVH.js} +1 -1
  38. package/dist/assets/{index-Bui9zV-z.js → index-BfmxxMgF.js} +1 -1
  39. package/dist/assets/{index-X9rrwleE.js → index-BmpxpR0w.js} +1 -1
  40. package/dist/assets/{index-DIrLsKod.js → index-CPWGn2pz.js} +1 -1
  41. package/dist/assets/{index-DGAT1KYx.js → index-CTwMeBqF.js} +1 -1
  42. package/dist/assets/{index-Dal_ULkA.js → index-CWB4GuES.js} +1 -1
  43. package/dist/assets/{index-CSdQtH7c.js → index-Ci6HaxoD.js} +1 -1
  44. package/dist/assets/{index-3ev2Q3E9.js → index-Cl0HzH8n.js} +1 -1
  45. package/dist/assets/{index-BN-I0GSO.js → index-D3BVMctX.js} +1 -1
  46. package/dist/assets/{index-CcZll7L2.js → index-DAU5uvX5.js} +1 -1
  47. package/dist/assets/{index-CjG9JDZB.js → index-DJdqwTB-.js} +1 -1
  48. package/dist/assets/{index-C7p19nIa.js → index-DLG-Can3.js} +1 -1
  49. package/dist/assets/{index-7gCTV42h.js → index-DT0MsOt-.js} +1 -1
  50. package/dist/assets/{index-DRBzHdu9.js → index-DiURoW7Y.js} +1 -1
  51. package/dist/assets/{index-DJY6AKiM.js → index-EUnNrMjG.js} +1 -1
  52. package/dist/assets/{index-DOy0Yf1i.js → index-HzW6tFXv.js} +1 -1
  53. package/dist/assets/{index-B4OP8iL7.js → index-SeZ6e2IY.js} +1 -1
  54. package/dist/assets/{index-8fdLByFg.js → index-Tbw04SMm.js} +1 -1
  55. package/dist/assets/{index-CPMJQkvw.js → index-Y8bTnSrF.js} +1 -1
  56. package/dist/assets/{index-DzzUoyj4.js → index-ZKG76s7Z.js} +1 -1
  57. package/dist/assets/{index-rI994S3C.js → index-llwTvhRi.js} +6 -6
  58. package/dist/assets/{index-DokXNUuN.js → index-xFXxtg2C.js} +1 -1
  59. package/dist/assets/{index.es-C2YDJ0AL.js → index.es-CFgf-VWh.js} +1 -1
  60. package/dist/assets/issue-document-DVCemcvP.js +1 -0
  61. package/dist/assets/{login-page-BimTSmTC.js → login-page-BUNJ0vL_.js} +1 -1
  62. package/dist/assets/{missing-info-charges-CVhY60ZL.js → missing-info-charges-Dsy5oUHu.js} +1 -1
  63. package/dist/assets/{modal-BXR_xgUm.js → modal-B0cCJdW9.js} +1 -1
  64. package/dist/assets/{modify-contract-dialog-flMl2p_T.js → modify-contract-dialog-DNQYpsqS.js} +1 -1
  65. package/dist/assets/{page-layout-DMGj5xhW.js → page-layout-ClvcCJfx.js} +1 -1
  66. package/dist/assets/{page-not-found-B_GB5ntj.js → page-not-found-zY3WEMae.js} +1 -1
  67. package/dist/assets/{panel-top-open-Bf39HBrp.js → panel-top-open-pJuuLeLe.js} +1 -1
  68. package/dist/assets/{report-commentary-row-BMyeQR9J.js → report-commentary-row-CuMCzc7C.js} +1 -1
  69. package/dist/assets/{save-jkuyCWyY.js → save-Dlfry6XY.js} +1 -1
  70. package/dist/assets/{similar-transactions-modal-DX3CPrMo.js → similar-transactions-modal-DjIjqO-0.js} +1 -1
  71. package/dist/assets/{sub-CEXBz_OW.js → sub-D5WK8Yq6.js} +1 -1
  72. package/dist/assets/subMonths-Ft6EDjKW.js +1 -0
  73. package/dist/assets/{summary-CPKS_69D.js → summary-yl9MRbvK.js} +1 -1
  74. package/dist/assets/{toggle-expansion-button-Y2eS7nqg.js → toggle-expansion-button-CGwmL9mo.js} +1 -1
  75. package/dist/assets/{update-accountant-status-zL6vnwU9.js → update-accountant-status-QJ1upFTt.js} +1 -1
  76. package/dist/assets/{use-issue-monthly-documents-D9vQpbaZ.js → use-issue-monthly-documents-pV0tTZGQ.js} +1 -1
  77. package/dist/assets/{use-url-query-CqWra6gD.js → use-url-query-C70bqR6l.js} +1 -1
  78. package/dist/index.html +1 -1
  79. package/package.json +4 -4
  80. package/src/components/common/merge-charges/index.tsx +1 -1
  81. package/src/components/common/modals/preview-document-modal.tsx +5 -2
  82. package/src/gql/graphql.ts +1 -1
  83. package/dist/assets/business-trip-BUKYnQkG.js +0 -1
  84. package/dist/assets/charge-DuqIMfNm.js +0 -1
  85. package/dist/assets/charges-table-BJtpvXfL.js +0 -7
  86. package/dist/assets/issue-document-zNxGzRkY.js +0 -1
  87. package/dist/assets/subMonths-DY4HlBVa.js +0 -1
@@ -1 +1 @@
1
- import{v as ve,cj as We,ck as qe,r as x,j as e,B as v,L as Be,g as w,cl as Ge,t as m,i as B,H as Se,u as ie,cm as ge,bE as b,bH as Y,cn as oe,co as Ne,cp as Ie,aC as Ye,bF as q,bG as G,w as F,ay as Fe,cq as Me,l as U,T as C,a3 as J,E as N,n as E,V as S,Y as M,Z as z,_ as Q,$ as P,I as ee,a1 as H,b7 as ze,cr as Z,d as K,cs as Ze,ct as Ke,cu as Xe,bv as D,cv as Qe,bX as Pe,cw as $e,ah as be,R as ye,a6 as A,cx as Je,ag as se,e as te,cy as es,cz as ss,cA as ts,cB as ns,bD as Oe,cC as rs,cD as is,cE as as,cF as Re,cG as os,cH as cs,cI as ds,cJ as ls,cK as us,cL as hs,at as je,cM as xs,cN as ps,cO as ms,cP as gs,cQ as js,cR as fs,cS as vs,cT as bs,cU as ys,cV as Ts,cW as Es,cX as Cs,cY as As,cZ as Ds,c_ as ws,c$ as Bs,d0 as Ss,d1 as Ns,d2 as Is,q as Fs,d3 as Ms,d4 as zs,d5 as Ps,d6 as $s,d7 as Os,d8 as fe,d9 as Rs,da as ks}from"./index-rI994S3C.js";import{G as re,L as me,C as ke,R as Hs,S as Vs}from"./summary-CPKS_69D.js";import{T as ne}from"./Table-BQv3frL8.js";import{T as Us}from"./toggle-expansion-button-Y2eS7nqg.js";import{M as He}from"./MultiSelect-DBeIExB5.js";import{a as Ls,u as _s,S as Ws}from"./similar-transactions-modal-DX3CPrMo.js";import{A as qs,a as L,b as _,c as W}from"./accordion-Bn08_4fN.js";const Gs=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],Ys=ve("car",Gs);const Zs=[["path",{d:"M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5",key:"1wtuz0"}],["path",{d:"M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16",key:"e09ifn"}],["path",{d:"M2 21h13",key:"1x0fut"}],["path",{d:"M3 9h11",key:"1p7c0w"}]],Ks=ve("fuel",Zs);const Xs=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],Qs=ve("printer",Xs);var k=3.77952755906,xe={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},Js=class{pdf;canvas;options;constructor(a,n){this.canvas=a,this.options=n,this.pdf=new qe({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(a)}getMarginLeftMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(a)}getMarginRightMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(a)}getMarginBottomMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(a)}getMarginTop(){return this.getMarginTopMM()*k}getMarginBottom(){return this.getMarginBottomMM()*k}getMarginLeft(){return this.getMarginLeftMM()*k}getMarginRight(){return this.getMarginRightMM()*k}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*k}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*k}getOriginalCanvasWidth(){return this.canvas.width/this.getScale()}getOriginalCanvasHeight(){return this.canvas.height/this.getScale()}getCanvasPageAvailableHeight(){return this.getPageAvailableHeight()*this.getScale()*this.getHorizontalFitFactor()}getPageAvailableWidth(){return this.getPageWidth()-(this.getMarginLeft()+this.getMarginRight())}getPageAvailableHeight(){return this.getPageHeight()-(this.getMarginTop()+this.getMarginBottom())}getPageAvailableWidthMM(){return this.getPageAvailableWidth()/k}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/k}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(a){return this.getCanvasPageAvailableHeight()*(a-1)}getCanvasHeightLeft(a){return this.canvas.height-this.getCanvasOffsetY(a)}getCanvasPageHeight(a){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(a);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(a){const n=this.getCanvasPageWidth(),i=this.getCanvasPageHeight(a),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(i)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(a),this.canvas.width,i,0,0,this.canvas.width,i),t}convert(){let a=1;const n=this.getNumberPages();for(;a<=n;){a>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const i=this.createCanvasPage(a),t=i.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(a),this.pdf.addImage({imageData:t,width:i.width/(this.getScale()*k*this.getHorizontalFitFactor()),height:i.height/(this.getScale()*k*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),a+=1}return this.pdf}},et=a=>a?{...xe,...a,canvas:{...xe.canvas,...a.canvas},page:{...xe.page,...a.page}}:xe,st=a=>typeof a=="function"?a():a?.current,tt=async(a,n)=>{const i=et(n),t=st(a);if(!t){console.error("Unable to get the target element.");return}const s=await We(t,{useCORS:i.canvas.useCORS,logging:i.canvas.logging,scale:i.resolution,...i.overrides?.canvas}),o=new Js(s,i).convert();switch(i.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;default:{const d=i.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},nt=tt;const rt={method:"open",overrides:{pdf:{compress:!0}}},it=()=>document.getElementById("main-page"),Dn=({filename:a})=>{const[n,i]=x.useState(!1),t=async()=>{i(!0),await nt(it,{...rt,filename:a}),i(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(Qs,{className:"size-5"})})},at="addBusinessTripAccommodationsExpense",ot=()=>{const[{fetching:a},n]=w(Ge),i=x.useCallback(async t=>{const s="Error adding business trip accommodations expense",r=at;m.loading("Adding Business Trip Accommodations Expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripAccommodationsExpense:i}};function Ve({formManager:a,attendeesStayPath:n,attendeesData:i,fetchingAttendees:t=!1,businessTripId:s}){const{control:r,watch:o,trigger:d}=a,{fields:g,append:j,remove:h}=Se({control:r,name:n}),[l,c]=x.useState(t),[u,p]=x.useState(i??[]),f=o(n),T=g.map((I,O)=>({...I,...f[O]}));x.useEffect(()=>{i&&p(i)},[i]),x.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:$},X]=ie({query:ge,pause:!0,variables:{businessTripId:s??""}});return x.useEffect(()=>{if(y?.businessTrip?.attendees.length){const I=y.businessTrip.attendees.map(O=>({value:O.id,label:O.name}))??[];p(I)}},[y?.businessTrip?.attendees]),x.useEffect(()=>{c($)},[$]),x.useEffect(()=>{!i&&!y&&!t&&!$&&X({businessTripId:s})},[i,t,$,X,s,y]),!s&&!i?e.jsx("div",{children:"Cannot edit attendees stay, lacking some mandatory information!"}):e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Employees Stay"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[T?.map((I,O)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{name:`${n}.${O}.attendeeId`,control:r,rules:{required:"Required"},render:({field:R,fieldState:ae})=>e.jsx(Y,{...R,disabled:l,data:u,value:R.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:ae.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:r,name:`${n}.${O}.nightsCount`,render:({field:R,fieldState:ae})=>e.jsx(oe,{className:"w-full",...R,min:0,label:"Nights Count",value:R.value??void 0,hideControls:!0,precision:0,error:ae.error?.message,required:!0,onChange:V=>R.onChange(V&&typeof V=="number"?V:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(O),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},I.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{j({}),d(n)},children:e.jsx(Ie,{className:"size-5"})})]})]})}function ce({businessTripId:a,control:n,setFetching:i}){const[t,s]=x.useState([]),[{data:r,fetching:o,error:d}]=ie({query:ge,variables:{businessTripId:a}}),{userContext:g}=x.useContext(Ye);x.useEffect(()=>{r?.businessTrip?.attendees.length&&s(r.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[r,s]),x.useEffect(()=>{i(o)},[i,o]),x.useEffect(()=>{d&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const j=x.useMemo(()=>g?.context.ledgerLock,[g]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:j?{value:j,message:`Date must be after ${j}`}:void 0,pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(G,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:n,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"},min:j?{value:j,message:`Date must be after ${j}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(G,{...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Value Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"amount",control:n,render:({field:h,fieldState:l})=>e.jsx(b,{name:"currency",control:n,defaultValue:Fe.Ils,render:({field:c,fieldState:u})=>e.jsx(Me,{...h,value:h.value??void 0,error:l.error?.message||u.error?.message,label:"Amount",currencyCodeProps:{...c,label:"Currency"}})})}),e.jsx(b,{name:"employeeBusinessId",control:n,render:({field:h,fieldState:l})=>e.jsx(Y,{...h,data:t,value:h.value,disabled:o,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]})}function Te(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(ct,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function ct({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripAccommodationsExpense:j,fetching:h}=ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Accommodation Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{control:r,name:"country",render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Country"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{name:"nightsCount",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Nights Count"}),e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})}),e.jsx(Ve,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:a}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const dt="updateBusinessTripAccommodationsExpense",lt=()=>{const[{fetching:a},n]=w(Ze),i=x.useCallback(async t=>{const s="Error updating business trip accommodations expense",r=dt;m.loading("Updating trip accommodations expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAccommodationsExpense:i}},ut="categorizeIntoExistingBusinessTripExpense",ht=()=>{const[{fetching:a},n]=w(Ke),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=ut;m.loading("Updating business trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeIntoExistingBusinessTripExpense:i}};function de(a){const{businessTripExpenseId:n,businessTripId:i,onChange:t}=a,[s,{close:r,open:o}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(xt,{businessTripExpenseId:n,businessTripId:i,opened:s,close:r,onChange:t})]})}function xt({businessTripExpenseId:a,businessTripId:n,opened:i,close:t,onChange:s}){const{control:r,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:a}}),[g,j]=x.useState([]),[{data:h,fetching:l,error:c}]=ie({query:Xe,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:p}=ht(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return x.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);j(T.map(({transaction:y})=>({eventDate:y.eventDate,sourceDescription:y.sourceDescription,referenceKey:y.referenceKey,counterparty:y.counterparty?.name,amount:y.amount.formatted,rawAmount:y.amount.raw,value:y.id,label:`${y.eventDate} | ${y.counterparty?.name} | ${y.amount.formatted}`})).sort((y,$)=>y.eventDate.localeCompare($.eventDate)))}},[h,j]),x.useEffect(()=>{c&&m.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(E,{opened:i,onClose:t,centered:!0,children:[e.jsx(E.Title,{children:"Set Transaction Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:r,render:({field:T,fieldState:y})=>e.jsx(Y,{...T,itemComponent:pt,data:g??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:$=>{const X=g.find(I=>I.value===$);X?.rawAmount&&d("amount",X.rawAmount),T.onChange($)}})}),e.jsx(b,{name:"amount",control:r,render:({field:T,fieldState:y})=>e.jsx(oe,{...T,value:T.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:y.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),p&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const pt=x.forwardRef(({eventDate:a,sourceDescription:n,referenceKey:i,counterparty:t,amount:s,...r},o)=>e.jsx("div",{ref:o,...r,children:e.jsxs(re,{children:[e.jsx(re.Col,{span:4,children:a}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(re.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(re.Col,{span:4,children:["Reference: ",i]})]})})),mt="deleteBusinessTripExpense",gt=()=>{const[{fetching:a},n]=w(Qe),i=x.useCallback(async t=>{const s="Error deleting business trip expense",r=`${mt}-${t.businessTripExpenseId}`;m.loading("Deleting trip expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripExpense:i}};function le(a){const{fetching:n,deleteBusinessTripExpense:i}=gt(),t=x.useCallback(()=>{i({businessTripExpenseId:a.businessTripExpenseId}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Expense",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const ue=({data:a,isEditMode:n=!1,control:i,businessTripId:t})=>{const s=A(Je,a),[r,o]=x.useState([]),[{data:d,fetching:g,error:j}]=ie({query:ge,variables:{businessTripId:t}});x.useEffect(()=>{d?.businessTrip?.attendees.length&&o(d.businessTrip.attendees.map(l=>({value:l.id,label:l.name})).sort((l,c)=>l.label>c.label?1:-1))},[d,o]),x.useEffect(()=>{j&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[j]);const h=Array.from(new Set(s.charges?.map(l=>l.id)));return e.jsxs(e.Fragment,{children:[e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:i,defaultValue:s.date,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:i,defaultValue:s.valueDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Value Date",error:c.error?.message,popoverProps:{withinPortal:!0}})})]}):e.jsxs(e.Fragment,{children:[s.date&&F(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&F(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:i,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:i,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:p})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||p.error?.message,label:"Amount",currencyCodeProps:{...u,label:"Currency",form:`form ${s.id}`}})})}):e.jsx("div",{children:s.amount?.formatted})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsx(b,{name:"employeeBusinessId",control:i,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(Y,{form:`form ${s.id}`,...l,data:r,value:l.value,disabled:g,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}):e.jsx("div",{className:"flex flex-row gap-2 items-center",children:s.payedByEmployee&&e.jsx(D,{c:s.employee?.name?void 0:"red",children:s.employee?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:h.map(l=>e.jsx(be,{to:ye.CHARGES.DETAIL(l),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"},l))})})]})},he=()=>e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Payed By Attendee"}),e.jsx("th",{children:"Charges"})]}),jt=({data:a,businessTripId:n,onChange:i})=>{const t=A(es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:g}=o,{updateBusinessTripAccommodationsExpense:j,fetching:h}=lt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(Ve,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(me,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(me.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})})]},t.id)},Ue=({businessTripId:a,expenses:n,onChange:i})=>{if(!n?.length)return i?e.jsx(Te,{businessTripId:a,onAdd:i}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ss,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Location"}),e.jsx("th",{children:"Nights"}),e.jsx("th",{children:"Attendees Stay"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(jt,{data:s,businessTripId:a,onChange:i},s.id)),i&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Te,{businessTripId:a,onAdd:i})})})]})]})})},ft=({data:a,onChange:n})=>{const{accommodationExpenses:i,id:t}=A(ts,a);return e.jsx(Ue,{businessTripId:t,expenses:i,onChange:n})},vt="insertBusinessTripAttendee",bt=()=>{const[{fetching:a},n]=w(ns),i=x.useCallback(async t=>{const s="Error adding attendee to business trip",r=vt;m.loading("Adding attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,insertBusinessTripAttendee:i}};function Ee(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function yt({businessTripId:a,opened:n,close:i,onAdd:t}){const{selectableBusinesses:s,fetching:r}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a}}),{insertBusinessTripAttendee:g,fetching:j}=bt(),h=l=>{g({fields:l}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,children:[e.jsx(E.Title,{children:"Add Attendee"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:r,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withAsterisk:!0,withinPortal:!0})}),e.jsx(b,{name:"arrivalDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"departureDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})}),(j||r)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Tt="updateBusinessTripAttendee",Et=()=>{const[{fetching:a},n]=w(rs),i=x.useCallback(async t=>{const s="Error updating business trip attendee",r=Tt;m.loading("Updating trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAttendee:i}},Ct="deleteBusinessTripAttendee",At=()=>{const[{fetching:a},n]=w(is),i=x.useCallback(async t=>{const s="Error removing business trip attendee",r=Ct;m.loading("Removing business trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripAttendee:i}};function Dt(a){const{fetching:n,deleteBusinessTripAttendee:i}=At(),t=x.useCallback(()=>{i({fields:{businessTripId:a.businessTripId,attendeeId:a.attendeeId}}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Attendee",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const wt="addBusinessTripFlightsExpense",Bt=()=>{const[{fetching:a},n]=w(as),i=x.useCallback(async t=>{const s="Error adding business trip flight expense",r=wt;m.loading("Adding business trip flight expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripFlightsExpense:i}};function Le({formManager:a,flightPathPath:n,flightPathData:i}){const{control:t,watch:s,trigger:r}=a,{fields:o,append:d,remove:g}=Se({control:t,name:n}),j=s(n),h=o.map((l,c)=>({...l,...j[c]}));return i?e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Flight Path"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[h?.map((l,c)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(M,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(H,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{g(c),r(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),r(n)},children:e.jsx(Ie,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ce(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Nt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}const St=Object.entries(Re).map(([a,n])=>({value:n,label:a}));function Nt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),[{data:j,fetching:h}]=ie({query:ge,variables:{businessTripId:a}}),{addBusinessTripFlightsExpense:l,fetching:c}=Bt(),u=f=>{l({fields:f}).then(()=>{t?.(),i()})},p=j?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Flight Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(Le,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:r,render:({field:f,fieldState:T})=>e.jsx(Y,{...f,data:St,value:f.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx(b,{name:"attendeeIds",control:r,render:({field:f,fieldState:T})=>e.jsx(He,{...f,disabled:h,data:p,value:f.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(c||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const It="updateBusinessTripFlightsExpense",Ft=()=>{const[{fetching:a},n]=w(os),i=x.useCallback(async t=>{const s="Error updating business trip flights expense",r=It;m.loading("Updating trip flights expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripFlightsExpense:i}},Mt=Object.entries(Re).map(([a,n])=>({value:n,label:a})),zt=({data:a,businessTripId:n,onChange:i,attendees:t})=>{const s=A(cs,a),[r,o]=x.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(p=>p.id)??[],path:s.path??[]}}),{control:g,handleSubmit:j}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Ft(),c=p=>{h({fields:p}).then(()=>{i?.(),o(!1)})},u=t.map(p=>({value:p.id,label:p.name}));return e.jsxs("tr",{children:[e.jsx(ue,{data:s,isEditMode:r,control:g,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:j(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[r?e.jsx(Le,{formManager:d,flightPathPath:"path",flightPathData:s.path??void 0}):e.jsx("div",{className:"flex gap-2 items-center",children:s.path?.length?s.path.map((p,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:p},f),f<s.path.length-1&&(p===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),r?e.jsx(b,{name:"flightClass",control:g,defaultValue:s.class??void 0,render:({field:p,fieldState:f})=>e.jsx(Y,{form:`form ${s.id}`,"data-autofocus":!0,...p,data:Mt,value:p.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(D,{c:s.class?void 0:"red",fz:"sm",children:`Class: ${s.class??"Missing"}`})]})})})}),e.jsx("td",{children:r?e.jsx(b,{name:"attendeeIds",control:g,defaultValue:s.attendees?.map(p=>p.id)??void 0,render:({field:p,fieldState:f})=>e.jsx(He,{...p,form:`form ${s.id}`,data:u,value:p.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(me,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(p=>e.jsx(me.Item,{children:p.name},p.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:r?"default":"outline",size:"icon",className:"size-7.5",onClick:p=>{p.stopPropagation(),o(f=>!f)},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${s.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:s.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:s.id,onDelete:i})]})})]},s.id)},_e=({businessTripId:a,expenses:n,attendees:i,onChange:t})=>{if(!n?.length)return t?e.jsx(Ce,{businessTripId:a,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(r=>A(ds,r));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((r,o)=>r.date&&o.date?r.date<o.date?1:-1:r.date?-1:o.date?1:0).map(r=>e.jsx(zt,{data:r,businessTripId:a,onChange:t,attendees:i},r.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ce,{businessTripId:a,onAdd:t})})})]})]})})},Pt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ls,a),[s,r]=x.useState(!1),[o,d]=x.useState(!1),{control:g,handleSubmit:j}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=Et(),c=u=>{h({fields:u}).then(()=>{i?.(),r(!1)})};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{children:s?e.jsx("form",{id:`form ${t.id}`,onSubmit:j(c),children:e.jsx(b,{name:"arrivalDate",control:g,defaultValue:t.arrivalDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},"data-autofocus":!0,value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:g,defaultValue:t.departureDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),r(p=>!p)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(Dt,{businessTripId:n,attendeeId:t.id,onDelete:i}),e.jsx(Us,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(ke,{shadow:"sm",withBorder:!0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[t.flights&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Flights:"}),e.jsx(_e,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(Ue,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},$t=({data:a,onChange:n})=>{const{attendees:i,id:t}=A(us,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Arrival Date"}),e.jsx("th",{children:"Departure Date"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.name.toLocaleLowerCase()>r.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Pt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ee,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ee,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Ot=()=>{const[{fetching:a},n]=w(hs),i=x.useCallback(async t=>{const s="Error adding business trip car rental expense";m.loading("Adding car rental expense...",{id:pe});try{const r=await n(t),o=B(r,s,pe);if(o)return m.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(r){console.error(`${s}: ${r}`),m.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripCarRentalExpense:i}};function Ae(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Rt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Rt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripCarRentalExpense:j,fetching:h}=Ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Car Rental Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(b,{name:"days",control:r,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(M,{name:"isFuelExpense",control:r,render:({field:{value:c,...u}})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const kt="updateBusinessTripCarRentalExpense",Ht=()=>{const[{fetching:a},n]=w(xs),i=x.useCallback(async t=>{const s="Error updating business trip car rental expense",r=kt;m.loading("Updating trip car rental expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripCarRentalExpense:i}},Vt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ps,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripCarRentalExpense:j,fetching:h}=Ht(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:t.isFuelExpense!==!0&&(s?e.jsx(b,{name:"days",control:d,defaultValue:t.days,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,placeholder:"Rent Days"})}):e.jsx(D,{c:t.days?void 0:"red",children:t.days??"Missing"}))})})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(Ks,{}):e.jsx(Ys,{})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Ut=({data:a,onChange:n})=>{const{carRentalExpenses:i,id:t}=A(ms,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Vt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ae,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ae,{businessTripId:t,onAdd:n})},Lt=({data:a,onChange:n})=>{const{flightExpenses:i,id:t,attendees:s}=A(gs,a);return e.jsx(_e,{businessTripId:t,attendees:s,expenses:i,onChange:n})},_t="addBusinessTripOtherExpense",Wt=()=>{const[{fetching:a},n]=w(js),i=x.useCallback(async t=>{const s='Error adding business trip "other" expense',r=_t;m.loading('Adding trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripOtherExpense:i}};function De(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(qt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function qt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripOtherExpense:j,fetching:h}=Wt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Other Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"description",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Description"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Deductible Expense"})}),e.jsx(P,{children:e.jsx(je,{checked:c.value===!0,onCheckedChange:c.onChange})})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Gt="updateBusinessTripOtherExpense",Yt=()=>{const[{fetching:a},n]=w(fs),i=x.useCallback(async t=>{const s='Error updating business trip "other" expense',r=Gt;m.loading('Updating business trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripOtherExpense:i}},Zt=({data:a,businessTripId:n,onChange:i})=>{const t=A(vs,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripOtherExpense:j,fetching:h}=Yt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.description?void 0:"red",children:t.description??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(z,{children:e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})})})}):e.jsx(D,{c:t.deductibleExpense?void 0:"red",children:t.deductibleExpense===!0?"Yes":t.deductibleExpense===!1?"No":"Missing"})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Kt=({data:a,onChange:n})=>{const{otherExpenses:i,id:t}=A(bs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Zt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(De,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(De,{businessTripId:t,onAdd:n})},Xt="addBusinessTripTravelAndSubsistenceExpense",Qt=()=>{const[{fetching:a},n]=w(ys),i=x.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",r=Xt;m.loading("Adding trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripTravelAndSubsistenceExpense:i}};function we(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Jt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Jt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=Qt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"expenseType",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Expense Type"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const en="updateBusinessTripTravelAndSubsistenceExpense",sn=()=>{const[{fetching:a},n]=w(Ts),i=x.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",r=en;m.loading("Updating trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripTravelAndSubsistenceExpense:i}},tn=({data:a,businessTripId:n,onChange:i})=>{const t=A(Es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=sn(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},nn=({data:a,onChange:n})=>{const{travelAndSubsistenceExpenses:i,id:t}=A(Cs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(tn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(we,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(we,{businessTripId:t,onAdd:n})},rn=({data:a})=>{const n=A(As,a),i="effectiveDate"in n?n.effectiveDate:void 0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col justify-center",children:[e.jsx("div",{children:i&&F(new Date(i),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",F(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},an=({data:a})=>{const n=A(Ds,a),i="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:i&&F(new Date(i),"dd/MM/yy")})})},on=({data:a})=>{const n=A(ws,a),{account:i}=n,t=Ls(i.type),s=i.name;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2 items-center",children:[e.jsx("p",{children:t}),e.jsx("p",{children:s})]})})},cn=({data:a})=>{const n=A(Bs,a),i="sourceDescription"in n?n.sourceDescription:"Missing";return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:i})})})},dn=({data:a})=>{const n=A(Ss,a);return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:n.referenceKey})})})};function ln({data:a,onChange:n,enableEdit:i}){const{id:t,counterparty:s,missingInfoSuggestions:r,id:o,sourceDescription:d}=A(Ns,a),g=!!r?.business&&i,j=g?r?.business?.name:"Missing",h=g?r?.business?.id:null,l=s?.name??j,[c,u]=x.useState(!1),{updateTransaction:p,fetching:f}=_s(),T=x.useCallback(async V=>{await p({transactionId:o,fields:{counterpartyId:V}}),u(!0)},[o,p]),y=x.useCallback(async V=>{await T(V),n?.()},[T,n]),{selectableBusinesses:$,fetching:X}=Oe(),[I,O]=x.useState(h??null),[R,ae]=x.useState(d);return e.jsxs("td",{children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center justify-center",children:s?.id?e.jsx(be,{to:ye.BUSINESSES.DETAIL(s.id),target:"_blank",rel:"noreferrer",onClick:V=>V.stopPropagation(),className:"inline-flex items-center font-semibold",children:l}):e.jsxs(e.Fragment,{children:[e.jsx(Is,{options:$,value:I,onChange:O,search:R,onSearchChange:ae,placeholder:"Choose or create a business",empty:R?e.jsx(Fs,{description:R,onAdd:y}):null}),e.jsx(C,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>I&&T(I),disabled:f||X||!I,children:e.jsx(te,{className:"size-4"})})})]})}),e.jsx(Ws,{transactionId:t,counterpartyId:s?.id??I,open:c,onOpenChange:u,onClose:n})]})}const un="categorizeBusinessTripExpense",hn=()=>{const[{fetching:a},n]=w(Ms),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=un;m.loading("Updating trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeBusinessTripExpense:i}};function xn(a){const{businessTripId:n,transactionId:i,onChange:t,defaultAmount:s}=a,[r,{close:o,open:d}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),d()},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(mn,{businessTripId:n,transactionId:i,opened:r,close:o,onChange:t,defaultAmount:s})]})}const pn=Object.entries(zs).map(([a,n])=>({value:n,label:a}));function mn({businessTripId:a,transactionId:n,defaultAmount:i,opened:t,close:s,onChange:r}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a,transactionId:n}}),{categorizeBusinessTripExpense:g,fetching:j}=hn(),h=l=>{g({fields:l}).then(()=>{r?.(),s()})};return e.jsxs(E,{opened:t,onClose:s,centered:!0,children:[e.jsx(E.Title,{children:"Set Expense Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"category",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:pn,value:l.value,label:"Category",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}),e.jsx(b,{name:"amount",control:o,defaultValue:i,render:({field:l,fieldState:c})=>e.jsx(oe,{...l,value:l.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:c.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),j&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const gn=({data:a,onChange:n})=>{const{uncategorizedTransactions:i,id:t}=A(Ps,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Event Date"}),e.jsx("th",{children:"Debit Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Reference#"}),e.jsx("th",{children:"Counterparty"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.sort((s,r)=>s.transaction.eventDate.localeCompare(r.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(an,{data:s.transaction}),e.jsx(rn,{data:s.transaction}),e.jsx(jn,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(on,{data:s.transaction}),e.jsx(cn,{data:s.transaction}),e.jsx(dn,{data:s.transaction}),e.jsx(ln,{data:s.transaction}),e.jsx("td",{children:e.jsx(xn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},jn=({data:a})=>{const{transaction:n,categorizedAmount:i,errors:t}=A($s,a),s="amount"in n?n.amount:void 0,r=s?.raw!==i.raw&&i.raw!==0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col whitespace-nowrap",style:{color:Number(s?.raw)>0?"green":"red"},children:[e.jsxs("div",{className:"flex gap-1",children:[s?.formatted,t.length>0&&e.jsx(fn,{errors:t})]}),r&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[i.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Os(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},fn=({errors:a})=>{const[n,{close:i,open:t}]=U(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(Rs,{onMouseEnter:t,onMouseLeave:i})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:a.map((s,r)=>e.jsx(D,{size:"sm",children:s},r))})]})};function wn({tripId:a,isExtended:n=!1}){const[i,t]=x.useState(),[{data:s},r]=ie({query:ks,variables:{businessTripId:a}}),o=r;return x.useEffect(()=>{s?.businessTrip&&t(s.businessTrip)},[s?.businessTrip]),e.jsx(ke,{shadow:"sm",radius:"md",withBorder:!0,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{data:i,onChange:o}),e.jsxs(qs,{className:"w-full",type:"multiple",children:[e.jsxs(L,{value:"attendees",children:[e.jsx(_,{children:"Attendees"}),e.jsx(W,{children:e.jsx($t,{data:i,onChange:o})})]}),n&&e.jsxs(L,{value:"uncategorized-transactions",children:[e.jsx(_,{disabled:!i.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(W,{children:e.jsx(gn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"flights",children:[e.jsx(_,{children:"Flights"}),e.jsx(W,{children:e.jsx(Lt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"accommodations",children:[e.jsx(_,{children:"Accommodations"}),e.jsx(W,{children:e.jsx(ft,{data:i,onChange:o})})]}),e.jsxs(L,{value:"travelAndSubsistence",children:[e.jsx(_,{children:"Travel & Subsistence"}),e.jsx(W,{children:e.jsx(nn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"other",children:[e.jsx(_,{children:"Other"}),e.jsx(W,{children:e.jsx(Kt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"carRental",children:[e.jsx(_,{children:"Car Rental"}),e.jsx(W,{children:e.jsx(Ut,{data:i,onChange:o})})]}),e.jsxs(L,{value:"summary",children:[e.jsx(_,{children:"Summary"}),e.jsx(W,{children:e.jsx(Vs,{data:i})})]})]})]}):e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{wn as E,Dn as P};
1
+ import{v as ve,cj as We,ck as qe,r as x,j as e,B as v,L as Be,g as w,cl as Ge,t as m,i as B,H as Se,u as ie,cm as ge,bE as b,bH as Y,cn as oe,co as Ne,cp as Ie,aC as Ye,bF as q,bG as G,w as F,ay as Fe,cq as Me,l as U,T as C,a3 as J,E as N,n as E,V as S,Y as M,Z as z,_ as Q,$ as P,I as ee,a1 as H,b7 as ze,cr as Z,d as K,cs as Ze,ct as Ke,cu as Xe,bv as D,cv as Qe,bX as Pe,cw as $e,ah as be,R as ye,a6 as A,cx as Je,ag as se,e as te,cy as es,cz as ss,cA as ts,cB as ns,bD as Oe,cC as rs,cD as is,cE as as,cF as Re,cG as os,cH as cs,cI as ds,cJ as ls,cK as us,cL as hs,at as je,cM as xs,cN as ps,cO as ms,cP as gs,cQ as js,cR as fs,cS as vs,cT as bs,cU as ys,cV as Ts,cW as Es,cX as Cs,cY as As,cZ as Ds,c_ as ws,c$ as Bs,d0 as Ss,d1 as Ns,d2 as Is,q as Fs,d3 as Ms,d4 as zs,d5 as Ps,d6 as $s,d7 as Os,d8 as fe,d9 as Rs,da as ks}from"./index-llwTvhRi.js";import{G as re,L as me,C as ke,R as Hs,S as Vs}from"./summary-yl9MRbvK.js";import{T as ne}from"./Table-8-ldSKpC.js";import{T as Us}from"./toggle-expansion-button-CGwmL9mo.js";import{M as He}from"./MultiSelect-Ca6lO0tL.js";import{a as Ls,u as _s,S as Ws}from"./similar-transactions-modal-DjIjqO-0.js";import{A as qs,a as L,b as _,c as W}from"./accordion-DP7ZozTk.js";const Gs=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],Ys=ve("car",Gs);const Zs=[["path",{d:"M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5",key:"1wtuz0"}],["path",{d:"M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16",key:"e09ifn"}],["path",{d:"M2 21h13",key:"1x0fut"}],["path",{d:"M3 9h11",key:"1p7c0w"}]],Ks=ve("fuel",Zs);const Xs=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],Qs=ve("printer",Xs);var k=3.77952755906,xe={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},Js=class{pdf;canvas;options;constructor(a,n){this.canvas=a,this.options=n,this.pdf=new qe({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(a)}getMarginLeftMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(a)}getMarginRightMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(a)}getMarginBottomMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(a)}getMarginTop(){return this.getMarginTopMM()*k}getMarginBottom(){return this.getMarginBottomMM()*k}getMarginLeft(){return this.getMarginLeftMM()*k}getMarginRight(){return this.getMarginRightMM()*k}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*k}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*k}getOriginalCanvasWidth(){return this.canvas.width/this.getScale()}getOriginalCanvasHeight(){return this.canvas.height/this.getScale()}getCanvasPageAvailableHeight(){return this.getPageAvailableHeight()*this.getScale()*this.getHorizontalFitFactor()}getPageAvailableWidth(){return this.getPageWidth()-(this.getMarginLeft()+this.getMarginRight())}getPageAvailableHeight(){return this.getPageHeight()-(this.getMarginTop()+this.getMarginBottom())}getPageAvailableWidthMM(){return this.getPageAvailableWidth()/k}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/k}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(a){return this.getCanvasPageAvailableHeight()*(a-1)}getCanvasHeightLeft(a){return this.canvas.height-this.getCanvasOffsetY(a)}getCanvasPageHeight(a){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(a);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(a){const n=this.getCanvasPageWidth(),i=this.getCanvasPageHeight(a),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(i)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(a),this.canvas.width,i,0,0,this.canvas.width,i),t}convert(){let a=1;const n=this.getNumberPages();for(;a<=n;){a>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const i=this.createCanvasPage(a),t=i.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(a),this.pdf.addImage({imageData:t,width:i.width/(this.getScale()*k*this.getHorizontalFitFactor()),height:i.height/(this.getScale()*k*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),a+=1}return this.pdf}},et=a=>a?{...xe,...a,canvas:{...xe.canvas,...a.canvas},page:{...xe.page,...a.page}}:xe,st=a=>typeof a=="function"?a():a?.current,tt=async(a,n)=>{const i=et(n),t=st(a);if(!t){console.error("Unable to get the target element.");return}const s=await We(t,{useCORS:i.canvas.useCORS,logging:i.canvas.logging,scale:i.resolution,...i.overrides?.canvas}),o=new Js(s,i).convert();switch(i.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;default:{const d=i.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},nt=tt;const rt={method:"open",overrides:{pdf:{compress:!0}}},it=()=>document.getElementById("main-page"),Dn=({filename:a})=>{const[n,i]=x.useState(!1),t=async()=>{i(!0),await nt(it,{...rt,filename:a}),i(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(Qs,{className:"size-5"})})},at="addBusinessTripAccommodationsExpense",ot=()=>{const[{fetching:a},n]=w(Ge),i=x.useCallback(async t=>{const s="Error adding business trip accommodations expense",r=at;m.loading("Adding Business Trip Accommodations Expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripAccommodationsExpense:i}};function Ve({formManager:a,attendeesStayPath:n,attendeesData:i,fetchingAttendees:t=!1,businessTripId:s}){const{control:r,watch:o,trigger:d}=a,{fields:g,append:j,remove:h}=Se({control:r,name:n}),[l,c]=x.useState(t),[u,p]=x.useState(i??[]),f=o(n),T=g.map((I,O)=>({...I,...f[O]}));x.useEffect(()=>{i&&p(i)},[i]),x.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:$},X]=ie({query:ge,pause:!0,variables:{businessTripId:s??""}});return x.useEffect(()=>{if(y?.businessTrip?.attendees.length){const I=y.businessTrip.attendees.map(O=>({value:O.id,label:O.name}))??[];p(I)}},[y?.businessTrip?.attendees]),x.useEffect(()=>{c($)},[$]),x.useEffect(()=>{!i&&!y&&!t&&!$&&X({businessTripId:s})},[i,t,$,X,s,y]),!s&&!i?e.jsx("div",{children:"Cannot edit attendees stay, lacking some mandatory information!"}):e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Employees Stay"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[T?.map((I,O)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{name:`${n}.${O}.attendeeId`,control:r,rules:{required:"Required"},render:({field:R,fieldState:ae})=>e.jsx(Y,{...R,disabled:l,data:u,value:R.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:ae.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:r,name:`${n}.${O}.nightsCount`,render:({field:R,fieldState:ae})=>e.jsx(oe,{className:"w-full",...R,min:0,label:"Nights Count",value:R.value??void 0,hideControls:!0,precision:0,error:ae.error?.message,required:!0,onChange:V=>R.onChange(V&&typeof V=="number"?V:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(O),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},I.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{j({}),d(n)},children:e.jsx(Ie,{className:"size-5"})})]})]})}function ce({businessTripId:a,control:n,setFetching:i}){const[t,s]=x.useState([]),[{data:r,fetching:o,error:d}]=ie({query:ge,variables:{businessTripId:a}}),{userContext:g}=x.useContext(Ye);x.useEffect(()=>{r?.businessTrip?.attendees.length&&s(r.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[r,s]),x.useEffect(()=>{i(o)},[i,o]),x.useEffect(()=>{d&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const j=x.useMemo(()=>g?.context.ledgerLock,[g]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:j?{value:j,message:`Date must be after ${j}`}:void 0,pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(G,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:n,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"},min:j?{value:j,message:`Date must be after ${j}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(G,{...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Value Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"amount",control:n,render:({field:h,fieldState:l})=>e.jsx(b,{name:"currency",control:n,defaultValue:Fe.Ils,render:({field:c,fieldState:u})=>e.jsx(Me,{...h,value:h.value??void 0,error:l.error?.message||u.error?.message,label:"Amount",currencyCodeProps:{...c,label:"Currency"}})})}),e.jsx(b,{name:"employeeBusinessId",control:n,render:({field:h,fieldState:l})=>e.jsx(Y,{...h,data:t,value:h.value,disabled:o,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]})}function Te(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(ct,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function ct({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripAccommodationsExpense:j,fetching:h}=ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Accommodation Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{control:r,name:"country",render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Country"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{name:"nightsCount",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Nights Count"}),e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})}),e.jsx(Ve,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:a}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const dt="updateBusinessTripAccommodationsExpense",lt=()=>{const[{fetching:a},n]=w(Ze),i=x.useCallback(async t=>{const s="Error updating business trip accommodations expense",r=dt;m.loading("Updating trip accommodations expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAccommodationsExpense:i}},ut="categorizeIntoExistingBusinessTripExpense",ht=()=>{const[{fetching:a},n]=w(Ke),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=ut;m.loading("Updating business trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeIntoExistingBusinessTripExpense:i}};function de(a){const{businessTripExpenseId:n,businessTripId:i,onChange:t}=a,[s,{close:r,open:o}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(xt,{businessTripExpenseId:n,businessTripId:i,opened:s,close:r,onChange:t})]})}function xt({businessTripExpenseId:a,businessTripId:n,opened:i,close:t,onChange:s}){const{control:r,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:a}}),[g,j]=x.useState([]),[{data:h,fetching:l,error:c}]=ie({query:Xe,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:p}=ht(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return x.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);j(T.map(({transaction:y})=>({eventDate:y.eventDate,sourceDescription:y.sourceDescription,referenceKey:y.referenceKey,counterparty:y.counterparty?.name,amount:y.amount.formatted,rawAmount:y.amount.raw,value:y.id,label:`${y.eventDate} | ${y.counterparty?.name} | ${y.amount.formatted}`})).sort((y,$)=>y.eventDate.localeCompare($.eventDate)))}},[h,j]),x.useEffect(()=>{c&&m.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(E,{opened:i,onClose:t,centered:!0,children:[e.jsx(E.Title,{children:"Set Transaction Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:r,render:({field:T,fieldState:y})=>e.jsx(Y,{...T,itemComponent:pt,data:g??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:$=>{const X=g.find(I=>I.value===$);X?.rawAmount&&d("amount",X.rawAmount),T.onChange($)}})}),e.jsx(b,{name:"amount",control:r,render:({field:T,fieldState:y})=>e.jsx(oe,{...T,value:T.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:y.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),p&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const pt=x.forwardRef(({eventDate:a,sourceDescription:n,referenceKey:i,counterparty:t,amount:s,...r},o)=>e.jsx("div",{ref:o,...r,children:e.jsxs(re,{children:[e.jsx(re.Col,{span:4,children:a}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(re.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(re.Col,{span:4,children:["Reference: ",i]})]})})),mt="deleteBusinessTripExpense",gt=()=>{const[{fetching:a},n]=w(Qe),i=x.useCallback(async t=>{const s="Error deleting business trip expense",r=`${mt}-${t.businessTripExpenseId}`;m.loading("Deleting trip expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripExpense:i}};function le(a){const{fetching:n,deleteBusinessTripExpense:i}=gt(),t=x.useCallback(()=>{i({businessTripExpenseId:a.businessTripExpenseId}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Expense",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const ue=({data:a,isEditMode:n=!1,control:i,businessTripId:t})=>{const s=A(Je,a),[r,o]=x.useState([]),[{data:d,fetching:g,error:j}]=ie({query:ge,variables:{businessTripId:t}});x.useEffect(()=>{d?.businessTrip?.attendees.length&&o(d.businessTrip.attendees.map(l=>({value:l.id,label:l.name})).sort((l,c)=>l.label>c.label?1:-1))},[d,o]),x.useEffect(()=>{j&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[j]);const h=Array.from(new Set(s.charges?.map(l=>l.id)));return e.jsxs(e.Fragment,{children:[e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:i,defaultValue:s.date,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:i,defaultValue:s.valueDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Value Date",error:c.error?.message,popoverProps:{withinPortal:!0}})})]}):e.jsxs(e.Fragment,{children:[s.date&&F(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&F(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:i,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:i,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:p})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||p.error?.message,label:"Amount",currencyCodeProps:{...u,label:"Currency",form:`form ${s.id}`}})})}):e.jsx("div",{children:s.amount?.formatted})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsx(b,{name:"employeeBusinessId",control:i,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(Y,{form:`form ${s.id}`,...l,data:r,value:l.value,disabled:g,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}):e.jsx("div",{className:"flex flex-row gap-2 items-center",children:s.payedByEmployee&&e.jsx(D,{c:s.employee?.name?void 0:"red",children:s.employee?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:h.map(l=>e.jsx(be,{to:ye.CHARGES.DETAIL(l),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"},l))})})]})},he=()=>e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Payed By Attendee"}),e.jsx("th",{children:"Charges"})]}),jt=({data:a,businessTripId:n,onChange:i})=>{const t=A(es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:g}=o,{updateBusinessTripAccommodationsExpense:j,fetching:h}=lt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(Ve,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(me,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(me.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})})]},t.id)},Ue=({businessTripId:a,expenses:n,onChange:i})=>{if(!n?.length)return i?e.jsx(Te,{businessTripId:a,onAdd:i}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ss,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Location"}),e.jsx("th",{children:"Nights"}),e.jsx("th",{children:"Attendees Stay"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(jt,{data:s,businessTripId:a,onChange:i},s.id)),i&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Te,{businessTripId:a,onAdd:i})})})]})]})})},ft=({data:a,onChange:n})=>{const{accommodationExpenses:i,id:t}=A(ts,a);return e.jsx(Ue,{businessTripId:t,expenses:i,onChange:n})},vt="insertBusinessTripAttendee",bt=()=>{const[{fetching:a},n]=w(ns),i=x.useCallback(async t=>{const s="Error adding attendee to business trip",r=vt;m.loading("Adding attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,insertBusinessTripAttendee:i}};function Ee(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function yt({businessTripId:a,opened:n,close:i,onAdd:t}){const{selectableBusinesses:s,fetching:r}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a}}),{insertBusinessTripAttendee:g,fetching:j}=bt(),h=l=>{g({fields:l}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,children:[e.jsx(E.Title,{children:"Add Attendee"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:r,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withAsterisk:!0,withinPortal:!0})}),e.jsx(b,{name:"arrivalDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"departureDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})}),(j||r)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Tt="updateBusinessTripAttendee",Et=()=>{const[{fetching:a},n]=w(rs),i=x.useCallback(async t=>{const s="Error updating business trip attendee",r=Tt;m.loading("Updating trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAttendee:i}},Ct="deleteBusinessTripAttendee",At=()=>{const[{fetching:a},n]=w(is),i=x.useCallback(async t=>{const s="Error removing business trip attendee",r=Ct;m.loading("Removing business trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripAttendee:i}};function Dt(a){const{fetching:n,deleteBusinessTripAttendee:i}=At(),t=x.useCallback(()=>{i({fields:{businessTripId:a.businessTripId,attendeeId:a.attendeeId}}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Attendee",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const wt="addBusinessTripFlightsExpense",Bt=()=>{const[{fetching:a},n]=w(as),i=x.useCallback(async t=>{const s="Error adding business trip flight expense",r=wt;m.loading("Adding business trip flight expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripFlightsExpense:i}};function Le({formManager:a,flightPathPath:n,flightPathData:i}){const{control:t,watch:s,trigger:r}=a,{fields:o,append:d,remove:g}=Se({control:t,name:n}),j=s(n),h=o.map((l,c)=>({...l,...j[c]}));return i?e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Flight Path"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[h?.map((l,c)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(M,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(H,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{g(c),r(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),r(n)},children:e.jsx(Ie,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ce(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Nt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}const St=Object.entries(Re).map(([a,n])=>({value:n,label:a}));function Nt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),[{data:j,fetching:h}]=ie({query:ge,variables:{businessTripId:a}}),{addBusinessTripFlightsExpense:l,fetching:c}=Bt(),u=f=>{l({fields:f}).then(()=>{t?.(),i()})},p=j?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Flight Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(Le,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:r,render:({field:f,fieldState:T})=>e.jsx(Y,{...f,data:St,value:f.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx(b,{name:"attendeeIds",control:r,render:({field:f,fieldState:T})=>e.jsx(He,{...f,disabled:h,data:p,value:f.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(c||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const It="updateBusinessTripFlightsExpense",Ft=()=>{const[{fetching:a},n]=w(os),i=x.useCallback(async t=>{const s="Error updating business trip flights expense",r=It;m.loading("Updating trip flights expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripFlightsExpense:i}},Mt=Object.entries(Re).map(([a,n])=>({value:n,label:a})),zt=({data:a,businessTripId:n,onChange:i,attendees:t})=>{const s=A(cs,a),[r,o]=x.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(p=>p.id)??[],path:s.path??[]}}),{control:g,handleSubmit:j}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Ft(),c=p=>{h({fields:p}).then(()=>{i?.(),o(!1)})},u=t.map(p=>({value:p.id,label:p.name}));return e.jsxs("tr",{children:[e.jsx(ue,{data:s,isEditMode:r,control:g,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:j(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[r?e.jsx(Le,{formManager:d,flightPathPath:"path",flightPathData:s.path??void 0}):e.jsx("div",{className:"flex gap-2 items-center",children:s.path?.length?s.path.map((p,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:p},f),f<s.path.length-1&&(p===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),r?e.jsx(b,{name:"flightClass",control:g,defaultValue:s.class??void 0,render:({field:p,fieldState:f})=>e.jsx(Y,{form:`form ${s.id}`,"data-autofocus":!0,...p,data:Mt,value:p.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(D,{c:s.class?void 0:"red",fz:"sm",children:`Class: ${s.class??"Missing"}`})]})})})}),e.jsx("td",{children:r?e.jsx(b,{name:"attendeeIds",control:g,defaultValue:s.attendees?.map(p=>p.id)??void 0,render:({field:p,fieldState:f})=>e.jsx(He,{...p,form:`form ${s.id}`,data:u,value:p.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(me,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(p=>e.jsx(me.Item,{children:p.name},p.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:r?"default":"outline",size:"icon",className:"size-7.5",onClick:p=>{p.stopPropagation(),o(f=>!f)},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${s.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:s.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:s.id,onDelete:i})]})})]},s.id)},_e=({businessTripId:a,expenses:n,attendees:i,onChange:t})=>{if(!n?.length)return t?e.jsx(Ce,{businessTripId:a,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(r=>A(ds,r));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((r,o)=>r.date&&o.date?r.date<o.date?1:-1:r.date?-1:o.date?1:0).map(r=>e.jsx(zt,{data:r,businessTripId:a,onChange:t,attendees:i},r.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ce,{businessTripId:a,onAdd:t})})})]})]})})},Pt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ls,a),[s,r]=x.useState(!1),[o,d]=x.useState(!1),{control:g,handleSubmit:j}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=Et(),c=u=>{h({fields:u}).then(()=>{i?.(),r(!1)})};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{children:s?e.jsx("form",{id:`form ${t.id}`,onSubmit:j(c),children:e.jsx(b,{name:"arrivalDate",control:g,defaultValue:t.arrivalDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},"data-autofocus":!0,value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:g,defaultValue:t.departureDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),r(p=>!p)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(Dt,{businessTripId:n,attendeeId:t.id,onDelete:i}),e.jsx(Us,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(ke,{shadow:"sm",withBorder:!0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[t.flights&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Flights:"}),e.jsx(_e,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(Ue,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},$t=({data:a,onChange:n})=>{const{attendees:i,id:t}=A(us,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Arrival Date"}),e.jsx("th",{children:"Departure Date"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.name.toLocaleLowerCase()>r.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Pt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ee,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ee,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Ot=()=>{const[{fetching:a},n]=w(hs),i=x.useCallback(async t=>{const s="Error adding business trip car rental expense";m.loading("Adding car rental expense...",{id:pe});try{const r=await n(t),o=B(r,s,pe);if(o)return m.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(r){console.error(`${s}: ${r}`),m.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripCarRentalExpense:i}};function Ae(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Rt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Rt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripCarRentalExpense:j,fetching:h}=Ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Car Rental Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(b,{name:"days",control:r,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(M,{name:"isFuelExpense",control:r,render:({field:{value:c,...u}})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const kt="updateBusinessTripCarRentalExpense",Ht=()=>{const[{fetching:a},n]=w(xs),i=x.useCallback(async t=>{const s="Error updating business trip car rental expense",r=kt;m.loading("Updating trip car rental expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripCarRentalExpense:i}},Vt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ps,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripCarRentalExpense:j,fetching:h}=Ht(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:t.isFuelExpense!==!0&&(s?e.jsx(b,{name:"days",control:d,defaultValue:t.days,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,placeholder:"Rent Days"})}):e.jsx(D,{c:t.days?void 0:"red",children:t.days??"Missing"}))})})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(Ks,{}):e.jsx(Ys,{})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Ut=({data:a,onChange:n})=>{const{carRentalExpenses:i,id:t}=A(ms,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Vt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ae,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ae,{businessTripId:t,onAdd:n})},Lt=({data:a,onChange:n})=>{const{flightExpenses:i,id:t,attendees:s}=A(gs,a);return e.jsx(_e,{businessTripId:t,attendees:s,expenses:i,onChange:n})},_t="addBusinessTripOtherExpense",Wt=()=>{const[{fetching:a},n]=w(js),i=x.useCallback(async t=>{const s='Error adding business trip "other" expense',r=_t;m.loading('Adding trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripOtherExpense:i}};function De(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(qt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function qt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripOtherExpense:j,fetching:h}=Wt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Other Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"description",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Description"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Deductible Expense"})}),e.jsx(P,{children:e.jsx(je,{checked:c.value===!0,onCheckedChange:c.onChange})})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Gt="updateBusinessTripOtherExpense",Yt=()=>{const[{fetching:a},n]=w(fs),i=x.useCallback(async t=>{const s='Error updating business trip "other" expense',r=Gt;m.loading('Updating business trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripOtherExpense:i}},Zt=({data:a,businessTripId:n,onChange:i})=>{const t=A(vs,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripOtherExpense:j,fetching:h}=Yt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.description?void 0:"red",children:t.description??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(z,{children:e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})})})}):e.jsx(D,{c:t.deductibleExpense?void 0:"red",children:t.deductibleExpense===!0?"Yes":t.deductibleExpense===!1?"No":"Missing"})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Kt=({data:a,onChange:n})=>{const{otherExpenses:i,id:t}=A(bs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Zt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(De,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(De,{businessTripId:t,onAdd:n})},Xt="addBusinessTripTravelAndSubsistenceExpense",Qt=()=>{const[{fetching:a},n]=w(ys),i=x.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",r=Xt;m.loading("Adding trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripTravelAndSubsistenceExpense:i}};function we(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Jt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Jt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=Qt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"expenseType",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Expense Type"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const en="updateBusinessTripTravelAndSubsistenceExpense",sn=()=>{const[{fetching:a},n]=w(Ts),i=x.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",r=en;m.loading("Updating trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripTravelAndSubsistenceExpense:i}},tn=({data:a,businessTripId:n,onChange:i})=>{const t=A(Es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=sn(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},nn=({data:a,onChange:n})=>{const{travelAndSubsistenceExpenses:i,id:t}=A(Cs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(tn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(we,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(we,{businessTripId:t,onAdd:n})},rn=({data:a})=>{const n=A(As,a),i="effectiveDate"in n?n.effectiveDate:void 0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col justify-center",children:[e.jsx("div",{children:i&&F(new Date(i),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",F(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},an=({data:a})=>{const n=A(Ds,a),i="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:i&&F(new Date(i),"dd/MM/yy")})})},on=({data:a})=>{const n=A(ws,a),{account:i}=n,t=Ls(i.type),s=i.name;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2 items-center",children:[e.jsx("p",{children:t}),e.jsx("p",{children:s})]})})},cn=({data:a})=>{const n=A(Bs,a),i="sourceDescription"in n?n.sourceDescription:"Missing";return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:i})})})},dn=({data:a})=>{const n=A(Ss,a);return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:n.referenceKey})})})};function ln({data:a,onChange:n,enableEdit:i}){const{id:t,counterparty:s,missingInfoSuggestions:r,id:o,sourceDescription:d}=A(Ns,a),g=!!r?.business&&i,j=g?r?.business?.name:"Missing",h=g?r?.business?.id:null,l=s?.name??j,[c,u]=x.useState(!1),{updateTransaction:p,fetching:f}=_s(),T=x.useCallback(async V=>{await p({transactionId:o,fields:{counterpartyId:V}}),u(!0)},[o,p]),y=x.useCallback(async V=>{await T(V),n?.()},[T,n]),{selectableBusinesses:$,fetching:X}=Oe(),[I,O]=x.useState(h??null),[R,ae]=x.useState(d);return e.jsxs("td",{children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center justify-center",children:s?.id?e.jsx(be,{to:ye.BUSINESSES.DETAIL(s.id),target:"_blank",rel:"noreferrer",onClick:V=>V.stopPropagation(),className:"inline-flex items-center font-semibold",children:l}):e.jsxs(e.Fragment,{children:[e.jsx(Is,{options:$,value:I,onChange:O,search:R,onSearchChange:ae,placeholder:"Choose or create a business",empty:R?e.jsx(Fs,{description:R,onAdd:y}):null}),e.jsx(C,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>I&&T(I),disabled:f||X||!I,children:e.jsx(te,{className:"size-4"})})})]})}),e.jsx(Ws,{transactionId:t,counterpartyId:s?.id??I,open:c,onOpenChange:u,onClose:n})]})}const un="categorizeBusinessTripExpense",hn=()=>{const[{fetching:a},n]=w(Ms),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=un;m.loading("Updating trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeBusinessTripExpense:i}};function xn(a){const{businessTripId:n,transactionId:i,onChange:t,defaultAmount:s}=a,[r,{close:o,open:d}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),d()},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(mn,{businessTripId:n,transactionId:i,opened:r,close:o,onChange:t,defaultAmount:s})]})}const pn=Object.entries(zs).map(([a,n])=>({value:n,label:a}));function mn({businessTripId:a,transactionId:n,defaultAmount:i,opened:t,close:s,onChange:r}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a,transactionId:n}}),{categorizeBusinessTripExpense:g,fetching:j}=hn(),h=l=>{g({fields:l}).then(()=>{r?.(),s()})};return e.jsxs(E,{opened:t,onClose:s,centered:!0,children:[e.jsx(E.Title,{children:"Set Expense Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"category",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:pn,value:l.value,label:"Category",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}),e.jsx(b,{name:"amount",control:o,defaultValue:i,render:({field:l,fieldState:c})=>e.jsx(oe,{...l,value:l.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:c.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),j&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const gn=({data:a,onChange:n})=>{const{uncategorizedTransactions:i,id:t}=A(Ps,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Event Date"}),e.jsx("th",{children:"Debit Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Reference#"}),e.jsx("th",{children:"Counterparty"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.sort((s,r)=>s.transaction.eventDate.localeCompare(r.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(an,{data:s.transaction}),e.jsx(rn,{data:s.transaction}),e.jsx(jn,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(on,{data:s.transaction}),e.jsx(cn,{data:s.transaction}),e.jsx(dn,{data:s.transaction}),e.jsx(ln,{data:s.transaction}),e.jsx("td",{children:e.jsx(xn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},jn=({data:a})=>{const{transaction:n,categorizedAmount:i,errors:t}=A($s,a),s="amount"in n?n.amount:void 0,r=s?.raw!==i.raw&&i.raw!==0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col whitespace-nowrap",style:{color:Number(s?.raw)>0?"green":"red"},children:[e.jsxs("div",{className:"flex gap-1",children:[s?.formatted,t.length>0&&e.jsx(fn,{errors:t})]}),r&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[i.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Os(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},fn=({errors:a})=>{const[n,{close:i,open:t}]=U(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(Rs,{onMouseEnter:t,onMouseLeave:i})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:a.map((s,r)=>e.jsx(D,{size:"sm",children:s},r))})]})};function wn({tripId:a,isExtended:n=!1}){const[i,t]=x.useState(),[{data:s},r]=ie({query:ks,variables:{businessTripId:a}}),o=r;return x.useEffect(()=>{s?.businessTrip&&t(s.businessTrip)},[s?.businessTrip]),e.jsx(ke,{shadow:"sm",radius:"md",withBorder:!0,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{data:i,onChange:o}),e.jsxs(qs,{className:"w-full",type:"multiple",children:[e.jsxs(L,{value:"attendees",children:[e.jsx(_,{children:"Attendees"}),e.jsx(W,{children:e.jsx($t,{data:i,onChange:o})})]}),n&&e.jsxs(L,{value:"uncategorized-transactions",children:[e.jsx(_,{disabled:!i.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(W,{children:e.jsx(gn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"flights",children:[e.jsx(_,{children:"Flights"}),e.jsx(W,{children:e.jsx(Lt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"accommodations",children:[e.jsx(_,{children:"Accommodations"}),e.jsx(W,{children:e.jsx(ft,{data:i,onChange:o})})]}),e.jsxs(L,{value:"travelAndSubsistence",children:[e.jsx(_,{children:"Travel & Subsistence"}),e.jsx(W,{children:e.jsx(nn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"other",children:[e.jsx(_,{children:"Other"}),e.jsx(W,{children:e.jsx(Kt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"carRental",children:[e.jsx(_,{children:"Car Rental"}),e.jsx(W,{children:e.jsx(Ut,{data:i,onChange:o})})]}),e.jsxs(L,{value:"summary",children:[e.jsx(_,{children:"Summary"}),e.jsx(W,{children:e.jsx(Vs,{data:i})})]})]})]}):e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{wn as E,Dn as P};
@@ -1 +1 @@
1
- import{v as e}from"./index-rI994S3C.js";const a=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],t=e("eye-off",a);export{t as E};
1
+ import{v as e}from"./index-llwTvhRi.js";const a=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],t=e("eye-off",a);export{t as E};
@@ -1 +1 @@
1
- import{v as e}from"./index-rI994S3C.js";const n=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],a=e("funnel",n);export{a as F};
1
+ import{v as e}from"./index-llwTvhRi.js";const n=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],a=e("funnel",n);export{a as F};
@@ -1 +1 @@
1
- import{v as j,r as l,F as C,u as S,j as e,T as f,B as g,bv as m,ay as n,L as N,bw as v,bx as R}from"./index-rI994S3C.js";import{u as T}from"./use-url-query-CqWra6gD.js";import{A as E}from"./accounter-table-DTsgtq5M.js";import{P as L}from"./page-layout-DMGj5xhW.js";import{B as k}from"./business-extended-info-B94y5ZK6.js";import{B as F,M as z}from"./business-ledger-filters-es3H4rPK.js";import{P as B,a as I}from"./panel-top-open-Bf39HBrp.js";import{T as A}from"./Table-BQv3frL8.js";import"./data-table-column-header-CZ1dXiU0.js";import"./eye-off-Buv7eciz.js";import"./download-csv-button-CMQBUQeX.js";import"./modal-BXR_xgUm.js";import"./funnel-Cfb9Pxmr.js";import"./MultiSelect-DBeIExB5.js";const M=[["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"m17 7 5 5-5 5",key:"1xlxn0"}],["path",{d:"m7 7-5 5 5 5",key:"19njba"}],["path",{d:"M8 12h.01",key:"czm47f"}]],_=j("chevrons-left-right-ellipsis",M);const O=[["path",{d:"m20 17-5-5 5-5",key:"30x0n2"}],["path",{d:"m4 17 5-5-5-5",key:"16spf4"}]],P=j("chevrons-right-left",O),se=()=>{const{get:t}=T(),{setFiltersContext:i}=l.useContext(C),[r,o]=l.useState(!1),[p,w]=l.useState(!1),[u,x]=l.useState(t("ledgerRecordsFilters")?JSON.parse(decodeURIComponent(t("ledgerRecordsFilters"))):{}),[{data:c,fetching:b}]=S({query:v,variables:{filters:u}});l.useEffect(()=>{i(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(F,{filter:u,setFilter:x}),e.jsx(f,{content:"Expand all accounts",asChild:!0,children:e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(s=>!s),children:r?e.jsx(B,{className:"size-5"}):e.jsx(I,{className:"size-5"})})}),e.jsx(f,{content:"Expand all currencies",asChild:!0,children:e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>w(s=>!s),children:p?e.jsx(P,{className:"size-5"}):e.jsx(_,{className:"size-5"})})})]}))},[c,u,i,x,r,o,p]);const y=l.useMemo(()=>c?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:c?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?c.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((s,d)=>s.business.name.localeCompare(d.business.name)):[],[c?.businessTransactionsSumFromLedgerRecords]),h=[{title:"Business Name",value:s=>s.business.name},{title:"Debit / Credit",value:s=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:s.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:s.credit.formatted})})]}),style:{whiteSpace:"nowrap"}},{title:"Total",value:s=>e.jsx(m,{c:s.total.raw<-1e-4?"red":s.total.raw>1e-4?"green":void 0,fw:700,children:s.total.formatted}),style:{whiteSpace:"nowrap"}},...a(n.Eur),...a(n.Usd),...a(n.Gbp),...a(n.Cad),...a(n.Jpy),...a(n.Aud),...a(n.Sek),...D(p)];return e.jsx(L,{title:"Business Ledger Records",description:"Business Ledger Records Summary",children:b?e.jsx(N,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(A,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"tracking-wider font-medium text-gray-900 text-sm bg-gray-100",children:[h.map((s,d)=>s.disabled?null:e.jsx("th",{children:s.title},String(d))),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:y.map((s,d)=>e.jsx(E,{columns:h,item:s,moreInfo:()=>e.jsx(k,{businessID:s.business.id,filter:u}),isShowAll:r},d))})]})})};function a(t){return[{title:`${t} Debit / Credit`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:r.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:r.credit.formatted})})]}):null},style:{whiteSpace:"nowrap"}},{title:`${t} Total`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?e.jsx(z,{color:r.total.raw>0?"green":"red",children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:"nowrap"}}]}function D(t){return t?Object.values(n).filter(r=>!R.includes(r)).map(a).flat():[]}export{se as BusinessLedgerRecordsSummery};
1
+ import{v as j,r as l,F as C,u as S,j as e,T as f,B as g,bv as m,ay as n,L as N,bw as v,bx as R}from"./index-llwTvhRi.js";import{u as T}from"./use-url-query-C70bqR6l.js";import{A as E}from"./accounter-table-D91AAtb3.js";import{P as L}from"./page-layout-ClvcCJfx.js";import{B as k}from"./business-extended-info-Dn8Jjrlr.js";import{B as F,M as z}from"./business-ledger-filters-Ctqgcwo5.js";import{P as B,a as I}from"./panel-top-open-pJuuLeLe.js";import{T as A}from"./Table-8-ldSKpC.js";import"./data-table-column-header-_ZrN0Vs6.js";import"./eye-off-DPLQFIHz.js";import"./download-csv-button-C12VYNQh.js";import"./modal-B0cCJdW9.js";import"./funnel-DrbTHWGk.js";import"./MultiSelect-Ca6lO0tL.js";const M=[["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"m17 7 5 5-5 5",key:"1xlxn0"}],["path",{d:"m7 7-5 5 5 5",key:"19njba"}],["path",{d:"M8 12h.01",key:"czm47f"}]],_=j("chevrons-left-right-ellipsis",M);const O=[["path",{d:"m20 17-5-5 5-5",key:"30x0n2"}],["path",{d:"m4 17 5-5-5-5",key:"16spf4"}]],P=j("chevrons-right-left",O),se=()=>{const{get:t}=T(),{setFiltersContext:i}=l.useContext(C),[r,o]=l.useState(!1),[p,w]=l.useState(!1),[u,x]=l.useState(t("ledgerRecordsFilters")?JSON.parse(decodeURIComponent(t("ledgerRecordsFilters"))):{}),[{data:c,fetching:b}]=S({query:v,variables:{filters:u}});l.useEffect(()=>{i(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(F,{filter:u,setFilter:x}),e.jsx(f,{content:"Expand all accounts",asChild:!0,children:e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(s=>!s),children:r?e.jsx(B,{className:"size-5"}):e.jsx(I,{className:"size-5"})})}),e.jsx(f,{content:"Expand all currencies",asChild:!0,children:e.jsx(g,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>w(s=>!s),children:p?e.jsx(P,{className:"size-5"}):e.jsx(_,{className:"size-5"})})})]}))},[c,u,i,x,r,o,p]);const y=l.useMemo(()=>c?.businessTransactionsSumFromLedgerRecords.__typename==="CommonError"?[]:c?.businessTransactionsSumFromLedgerRecords.businessTransactionsSum?c.businessTransactionsSumFromLedgerRecords.businessTransactionsSum.sort((s,d)=>s.business.name.localeCompare(d.business.name)):[],[c?.businessTransactionsSumFromLedgerRecords]),h=[{title:"Business Name",value:s=>s.business.name},{title:"Debit / Credit",value:s=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:s.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:s.credit.formatted})})]}),style:{whiteSpace:"nowrap"}},{title:"Total",value:s=>e.jsx(m,{c:s.total.raw<-1e-4?"red":s.total.raw>1e-4?"green":void 0,fw:700,children:s.total.formatted}),style:{whiteSpace:"nowrap"}},...a(n.Eur),...a(n.Usd),...a(n.Gbp),...a(n.Cad),...a(n.Jpy),...a(n.Aud),...a(n.Sek),...D(p)];return e.jsx(L,{title:"Business Ledger Records",description:"Business Ledger Records Summary",children:b?e.jsx(N,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(A,{striped:!0,highlightOnHover:!0,children:[e.jsx("thead",{className:"sticky top-0 z-20",children:e.jsxs("tr",{className:"tracking-wider font-medium text-gray-900 text-sm bg-gray-100",children:[h.map((s,d)=>s.disabled?null:e.jsx("th",{children:s.title},String(d))),e.jsx("th",{children:"More Info"})]})}),e.jsx("tbody",{children:y.map((s,d)=>e.jsx(E,{columns:h,item:s,moreInfo:()=>e.jsx(k,{businessID:s.business.id,filter:u}),isShowAll:r},d))})]})})};function a(t){return[{title:`${t} Debit / Credit`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"red",children:r.debit.formatted})}),e.jsx("p",{className:"flex flex-row gap-2 whitespace-nowrap",children:e.jsx(m,{c:"green",children:r.credit.formatted})})]}):null},style:{whiteSpace:"nowrap"}},{title:`${t} Total`,value:i=>{const r=i.foreignCurrenciesSum.find(o=>o.currency===t);return r?.total?.raw&&(r.total.raw<-1e-4||r.total.raw>1e-4)?e.jsx(z,{color:r.total.raw>0?"green":"red",children:r.total.formatted}):r?.total?.formatted},style:{whiteSpace:"nowrap"}}]}function D(t){return t?Object.values(n).filter(r=>!R.includes(r)).map(a).flat():[]}export{se as BusinessLedgerRecordsSummery};
@@ -1 +1 @@
1
- import{r,bB as w,bI as A,j as e,bC as K,B as c,aC as U,E as _,w as v,dr as z,V as B,ds as H,bE as D,bF as M,bG as I,Y as L,Z as G,_ as Q,$ as q,at as J,F as Y,u as Z,bY as X,L as $,dt as W,du as ee,bO as te,bP as se,bQ as S,bR as ae,c2 as T,bS as ne,bT as k,bZ as re,b_ as ie,c0 as le,c1 as oe,dv as ce,c5 as de,c4 as me,c6 as ue}from"./index-rI994S3C.js";import{u as P}from"./use-url-query-CqWra6gD.js";import{a as ge}from"./accounter-table-DTsgtq5M.js";import{D as he}from"./data-table-pagination-XAlQIbO9.js";import{P as V}from"./modal-BXR_xgUm.js";import{P as xe}from"./page-layout-DMGj5xhW.js";import{F as pe}from"./funnel-Cfb9Pxmr.js";import{M as E}from"./MultiSelect-DBeIExB5.js";import{s as je}from"./sub-CEXBz_OW.js";import{A as b}from"./arrow-up-down-VY6mkkTR.js";import"./Table-BQv3frL8.js";import"./addDays-DTiBTTns.js";import"./subMonths-DY4HlBVa.js";function fe({filter:t,setFilter:s,closeModal:x}){const{userContext:p}=r.useContext(U),h=_({defaultValues:{ownerIDs:p?.context.adminBusinessId?[p.context.adminBusinessId]:void 0,toDate:v(new Date,"yyyy-MM-dd"),fromDate:v(je(new Date,{years:1}),"yyyy-MM-dd"),...t}}),{control:o,handleSubmit:y}=h,{selectableFinancialEntities:i,fetching:d}=z(),C=a=>{s(a),x()};function m(){s({}),x()}return e.jsxs(e.Fragment,{children:[d?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(B,{...h,children:e.jsxs("form",{onSubmit:y(C),children:[e.jsxs(H,{cols:2,children:[e.jsx(D,{name:"ownerIDs",control:o,defaultValue:t.ownerIDs,render:({field:a,fieldState:g})=>e.jsx(E,{...a,data:i,value:a.value??[],disabled:d,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"businessIDs",control:o,defaultValue:t.businessIDs,render:({field:a,fieldState:g})=>e.jsx(E,{...a,data:i,value:a.value??[],disabled:d,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"fromDate",control:o,defaultValue:t.fromDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:v(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(D,{name:"toDate",control:o,defaultValue:t.toDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:v(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(L,{name:"unmatched",control:o,render:({field:a})=>e.jsxs(G,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Unmatched only"})}),e.jsx(q,{children:e.jsx(J,{defaultChecked:t.unmatched??!1,onCheckedChange:a.onChange})})]})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:d,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:m,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:x,children:"Cancel"})]})]})})]})}function be({filter:t={},setFilter:s,initiallyOpened:x=!1}){const[p,h]=r.useState(x),[o,y]=r.useState(!w(t)),{get:i,set:d}=P();r.useEffect(()=>{const m=w(t)?null:encodeURIComponent(JSON.stringify(t)),a=i("documentsFilters");m!==a&&d("documentsFilters",m)},[t,i,d]);const C=r.useCallback(m=>{A(m,t)||(s(m),y(!w(m)))},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(V,{opened:p,onClose:()=>h(!1),content:e.jsx(fe,{filter:t,setFilter:C,closeModal:()=>h(!1)}),modalSize:"xl"}),e.jsx(K,{inline:!0,size:16,disabled:!o,children:e.jsx(c,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>h(!0),children:e.jsx(pe,{className:"size-5"})})})]})}const R=[{accessorKey:"__typename",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Type"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>{const{__typename:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s})}},{accessorKey:"image",header:()=>e.jsx("div",{className:"text-left",children:"Image"}),cell:({row:t})=>{const{image:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s?e.jsx("img",{alt:"missing img",src:s?.toString(),height:80,width:80}):"No image"})}},{accessorKey:"file",header:()=>e.jsx("div",{className:"text-left",children:"File"}),cell:({row:t})=>{const{file:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s&&e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("a",{target:"_blank",rel:"noreferrer",href:s?.toString(),children:"Open"})})})}},{accessorKey:"date",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Date"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"date"in t.original&&t.original.date?e.jsx("div",{className:"text-left font-medium",children:v(new Date(t.original.date),"dd/MM/yy")}):null},{accessorKey:"serialNumber",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Serial Number"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"serialNumber"in t.original&&t.original.serialNumber?e.jsx("div",{className:"text-left font-medium",children:t.original.serialNumber}):null},{accessorKey:"vat.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"VAT"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"vat"in t.original&&t.original.vat?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.vat.formatted}):null},{accessorKey:"amount.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Amount"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"amount"in t.original&&t.original.amount?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.amount.formatted}):null},{accessorKey:"creditor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Creditor"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"creditor"in t.original&&t.original.creditor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.creditor.name}):null},{accessorKey:"debtor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Debtor"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"debtor"in t.original&&t.original.debtor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.debtor.name}):null},{accessorKey:"charge.transactions[0].id",header:()=>e.jsx("div",{className:"text-left",children:"Related Transaction"}),cell:({row:t})=>t.original.charge?.transactions?.[0]?.id?e.jsx(ge,{items:t.original.charge?.transactions??[],columns:[{title:"Transaction Amount",value:s=>s?.amount.formatted},{title:"Transaction Created At",value:s=>s?.eventDate?v(new Date(s.eventDate),"dd/MM/yy"):null},{title:"Transaction Effective Date",value:s=>s?.effectiveDate?v(new Date(s.effectiveDate),"dd/MM/yy"):null},{title:"Transaction Description",value:s=>s?.sourceDescription}]}):"No Related Transaction"}],Re=()=>{const[t,s]=r.useState(null),[x,p]=r.useState(!1),{get:h}=P(),o=h("documentsFilters"),y=r.useMemo(()=>{if(o)try{return JSON.parse(decodeURIComponent(o))}catch{return}},[o]),[i,d]=r.useState(y),[C,m]=r.useState([]),[a,g]=r.useState({}),{setFiltersContext:l}=r.useContext(Y),[{data:j,fetching:F},N]=Z({query:ce,variables:{filters:i??{}},pause:!0});r.useEffect(()=>{i&&N()},[i,N]);const f=X({data:j?.documentsByFilters??[],columns:R,getCoreRowModel:ue(),getPaginationRowModel:me(),onSortingChange:m,getSortedRowModel:de(),onColumnVisibilityChange:g,state:{sorting:C,columnVisibility:a}}),O=f.getState().pagination.pageIndex;return r.useEffect(()=>{l(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(he,{table:f}),e.jsx(be,{filter:i,setFilter:d,initiallyOpened:!i})]}))},[f,F,i,l,d,y,O]),e.jsx(xe,{title:"Documents",description:"All documents",headerActions:e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsxs(re,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(c,{className:"ml-auto",children:"Columns"})}),e.jsx(le,{align:"end",children:f.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(oe,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:u=>n.toggleVisibility(!!u),children:n.id},n.id))})]}),e.jsx(c,{onClick:()=>p(!0),children:"Upload Documents"})]}),children:F?e.jsx($,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx(W,{open:x,onOpenChange:p,onChange:N}),t&&e.jsx(V,{modalSize:"45%",content:e.jsx(ee,{src:t}),opened:!!t,onClose:()=>s(null)}),e.jsxs(te,{children:[e.jsx(se,{children:f.getHeaderGroups().map(n=>e.jsx(S,{children:n.headers.map(u=>e.jsx(ae,{children:u.isPlaceholder?null:T(u.column.columnDef.header,u.getContext())},u.id))},n.id))}),e.jsx(ne,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(n=>e.jsx(S,{"data-state":n.getIsSelected()&&"selected",children:n.getVisibleCells().map(u=>e.jsx(k,{children:T(u.column.columnDef.cell,u.getContext())},u.id))},n.id)):e.jsx(S,{children:e.jsx(k,{colSpan:R.length,className:"h-24 text-center",children:"No results."})})})]})]})})};export{Re as DocumentsReport,R as columns};
1
+ import{r,bB as w,bI as A,j as e,bC as K,B as c,aC as U,E as _,w as v,dr as z,V as B,ds as H,bE as D,bF as M,bG as I,Y as L,Z as G,_ as Q,$ as q,at as J,F as Y,u as Z,bY as X,L as $,dt as W,du as ee,bO as te,bP as se,bQ as S,bR as ae,c2 as T,bS as ne,bT as k,bZ as re,b_ as ie,c0 as le,c1 as oe,dv as ce,c5 as de,c4 as me,c6 as ue}from"./index-llwTvhRi.js";import{u as P}from"./use-url-query-C70bqR6l.js";import{a as ge}from"./accounter-table-D91AAtb3.js";import{D as he}from"./data-table-pagination-DAvY_qBU.js";import{P as V}from"./modal-B0cCJdW9.js";import{P as xe}from"./page-layout-ClvcCJfx.js";import{F as pe}from"./funnel-DrbTHWGk.js";import{M as E}from"./MultiSelect-Ca6lO0tL.js";import{s as je}from"./sub-D5WK8Yq6.js";import{A as b}from"./arrow-up-down-Du86WmzT.js";import"./Table-8-ldSKpC.js";import"./addDays-DbQpcl70.js";import"./subMonths-Ft6EDjKW.js";function fe({filter:t,setFilter:s,closeModal:x}){const{userContext:p}=r.useContext(U),h=_({defaultValues:{ownerIDs:p?.context.adminBusinessId?[p.context.adminBusinessId]:void 0,toDate:v(new Date,"yyyy-MM-dd"),fromDate:v(je(new Date,{years:1}),"yyyy-MM-dd"),...t}}),{control:o,handleSubmit:y}=h,{selectableFinancialEntities:i,fetching:d}=z(),C=a=>{s(a),x()};function m(){s({}),x()}return e.jsxs(e.Fragment,{children:[d?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(B,{...h,children:e.jsxs("form",{onSubmit:y(C),children:[e.jsxs(H,{cols:2,children:[e.jsx(D,{name:"ownerIDs",control:o,defaultValue:t.ownerIDs,render:({field:a,fieldState:g})=>e.jsx(E,{...a,data:i,value:a.value??[],disabled:d,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"businessIDs",control:o,defaultValue:t.businessIDs,render:({field:a,fieldState:g})=>e.jsx(E,{...a,data:i,value:a.value??[],disabled:d,label:"Financial Entities",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:g.error?.message,withinPortal:!0})}),e.jsx(D,{name:"fromDate",control:o,defaultValue:t.fromDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:v(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"From Date",popoverProps:{withinPortal:!0}})}),e.jsx(D,{name:"toDate",control:o,defaultValue:t.toDate,rules:{pattern:{value:M,message:"Date must be im format yyyy-mm-dd"}},render:({field:a,fieldState:g})=>e.jsx(I,{...a,onChange:l=>{const j=l?typeof l=="string"?l:v(l,"yyyy-MM-dd"):void 0;j!==a.value&&a.onChange(j)},value:a.value?new Date(a.value):void 0,error:g.error?.message,label:"To Date",popoverProps:{withinPortal:!0}})}),e.jsx(L,{name:"unmatched",control:o,render:({field:a})=>e.jsxs(G,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Unmatched only"})}),e.jsx(q,{children:e.jsx(J,{defaultChecked:t.unmatched??!1,onCheckedChange:a.onChange})})]})})]}),e.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[e.jsx("button",{type:"submit",disabled:d,className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Filter"}),e.jsx("button",{type:"button",className:"text-white bg-orange-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-orange-600 rounded-sm text-lg",onClick:m,children:"Clear"}),e.jsx("button",{type:"button",className:"text-white bg-rose-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-rose-600 rounded-sm text-lg",onClick:x,children:"Cancel"})]})]})})]})}function be({filter:t={},setFilter:s,initiallyOpened:x=!1}){const[p,h]=r.useState(x),[o,y]=r.useState(!w(t)),{get:i,set:d}=P();r.useEffect(()=>{const m=w(t)?null:encodeURIComponent(JSON.stringify(t)),a=i("documentsFilters");m!==a&&d("documentsFilters",m)},[t,i,d]);const C=r.useCallback(m=>{A(m,t)||(s(m),y(!w(m)))},[t,s]);return e.jsxs("div",{className:"flex flex-row gap-5 items-center",children:[e.jsx(V,{opened:p,onClose:()=>h(!1),content:e.jsx(fe,{filter:t,setFilter:C,closeModal:()=>h(!1)}),modalSize:"xl"}),e.jsx(K,{inline:!0,size:16,disabled:!o,children:e.jsx(c,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>h(!0),children:e.jsx(pe,{className:"size-5"})})})]})}const R=[{accessorKey:"__typename",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Type"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>{const{__typename:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s})}},{accessorKey:"image",header:()=>e.jsx("div",{className:"text-left",children:"Image"}),cell:({row:t})=>{const{image:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s?e.jsx("img",{alt:"missing img",src:s?.toString(),height:80,width:80}):"No image"})}},{accessorKey:"file",header:()=>e.jsx("div",{className:"text-left",children:"File"}),cell:({row:t})=>{const{file:s}=t.original;return e.jsx("div",{className:"text-left font-medium",children:s&&e.jsx(c,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("a",{target:"_blank",rel:"noreferrer",href:s?.toString(),children:"Open"})})})}},{accessorKey:"date",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Date"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"date"in t.original&&t.original.date?e.jsx("div",{className:"text-left font-medium",children:v(new Date(t.original.date),"dd/MM/yy")}):null},{accessorKey:"serialNumber",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Serial Number"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"serialNumber"in t.original&&t.original.serialNumber?e.jsx("div",{className:"text-left font-medium",children:t.original.serialNumber}):null},{accessorKey:"vat.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"VAT"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"vat"in t.original&&t.original.vat?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.vat.formatted}):null},{accessorKey:"amount.raw",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Amount"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"amount"in t.original&&t.original.amount?.formatted?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.amount.formatted}):null},{accessorKey:"creditor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Creditor"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"creditor"in t.original&&t.original.creditor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.creditor.name}):null},{accessorKey:"debtor.name",header:({column:t})=>e.jsxs(c,{variant:"ghost",onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[e.jsx("div",{className:"text-left",children:"Debtor"}),e.jsx(b,{className:"ml-2 h-4 w-4"})]}),cell:({row:t})=>"debtor"in t.original&&t.original.debtor?.name?e.jsx("div",{className:"text-left font-medium whitespace-nowrap",children:t.original.debtor.name}):null},{accessorKey:"charge.transactions[0].id",header:()=>e.jsx("div",{className:"text-left",children:"Related Transaction"}),cell:({row:t})=>t.original.charge?.transactions?.[0]?.id?e.jsx(ge,{items:t.original.charge?.transactions??[],columns:[{title:"Transaction Amount",value:s=>s?.amount.formatted},{title:"Transaction Created At",value:s=>s?.eventDate?v(new Date(s.eventDate),"dd/MM/yy"):null},{title:"Transaction Effective Date",value:s=>s?.effectiveDate?v(new Date(s.effectiveDate),"dd/MM/yy"):null},{title:"Transaction Description",value:s=>s?.sourceDescription}]}):"No Related Transaction"}],Re=()=>{const[t,s]=r.useState(null),[x,p]=r.useState(!1),{get:h}=P(),o=h("documentsFilters"),y=r.useMemo(()=>{if(o)try{return JSON.parse(decodeURIComponent(o))}catch{return}},[o]),[i,d]=r.useState(y),[C,m]=r.useState([]),[a,g]=r.useState({}),{setFiltersContext:l}=r.useContext(Y),[{data:j,fetching:F},N]=Z({query:ce,variables:{filters:i??{}},pause:!0});r.useEffect(()=>{i&&N()},[i,N]);const f=X({data:j?.documentsByFilters??[],columns:R,getCoreRowModel:ue(),getPaginationRowModel:me(),onSortingChange:m,getSortedRowModel:de(),onColumnVisibilityChange:g,state:{sorting:C,columnVisibility:a}}),O=f.getState().pagination.pageIndex;return r.useEffect(()=>{l(e.jsxs("div",{className:"flex flex-row gap-x-5",children:[e.jsx(he,{table:f}),e.jsx(be,{filter:i,setFilter:d,initiallyOpened:!i})]}))},[f,F,i,l,d,y,O]),e.jsx(xe,{title:"Documents",description:"All documents",headerActions:e.jsxs("div",{className:"flex items-center py-4 gap-4",children:[e.jsxs(re,{children:[e.jsx(ie,{asChild:!0,children:e.jsx(c,{className:"ml-auto",children:"Columns"})}),e.jsx(le,{align:"end",children:f.getAllColumns().filter(n=>n.getCanHide()).map(n=>e.jsx(oe,{className:"capitalize",checked:n.getIsVisible(),onCheckedChange:u=>n.toggleVisibility(!!u),children:n.id},n.id))})]}),e.jsx(c,{onClick:()=>p(!0),children:"Upload Documents"})]}),children:F?e.jsx($,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsxs(e.Fragment,{children:[e.jsx(W,{open:x,onOpenChange:p,onChange:N}),t&&e.jsx(V,{modalSize:"45%",content:e.jsx(ee,{src:t}),opened:!!t,onClose:()=>s(null)}),e.jsxs(te,{children:[e.jsx(se,{children:f.getHeaderGroups().map(n=>e.jsx(S,{children:n.headers.map(u=>e.jsx(ae,{children:u.isPlaceholder?null:T(u.column.columnDef.header,u.getContext())},u.id))},n.id))}),e.jsx(ne,{children:f.getRowModel().rows?.length?f.getRowModel().rows.map(n=>e.jsx(S,{"data-state":n.getIsSelected()&&"selected",children:n.getVisibleCells().map(u=>e.jsx(k,{children:T(u.column.columnDef.cell,u.getContext())},u.id))},n.id)):e.jsx(S,{children:e.jsx(k,{colSpan:R.length,className:"h-24 text-center",children:"No results."})})})]})]})})};export{Re as DocumentsReport,R as columns};
@@ -1 +1 @@
1
- import{r as c,j as e,g9 as p,B as u,a as y,F as g,u as P,L as D,ga as w}from"./index-rI994S3C.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-DMGj5xhW.js";import{R as d}from"./report-commentary-row-BMyeQR9J.js";import{P as v}from"./modal-BXR_xgUm.js";import{F}from"./funnel-Cfb9Pxmr.js";import{T as C}from"./Table-BQv3frL8.js";import"./toggle-expansion-button-Y2eS7nqg.js";import"./panel-top-open-Bf39HBrp.js";function A({year:l,setYear:h,referenceYears:o,setReferenceYears:j}){const[m,x]=c.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(v,{opened:m,onClose:()=>x(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change report year",value:new Date(l,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(p,{type:"multiple",label:"Pick reference years",value:o?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(i=>i.getFullYear()).filter(i=>l!==i)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(F,{className:"size-5"})})]})}const G=()=>{const{year:l}=y(),{setFiltersContext:h}=c.useContext(g),[o,j]=c.useState(l?Number(l):new Date().getFullYear()),[m,x]=c.useState([]),[{data:n,fetching:i}]=P({query:R(w),variables:{reportYear:o,referenceYears:m}});c.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(A,{year:o,setYear:j,referenceYears:m,setReferenceYears:x})}))},[o,i,h,m,x]);const f=n?.profitAndLossReport,r=f?.report,s=f?.reference??[];return e.jsx(E,{title:"Profit and Loss Report",children:i?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:r&&e.jsxs(C,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:o},o),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Revenue"}),e.jsx("th",{children:r.revenue.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("th",{children:a.revenue.amount.formatted},a.year))]}),commentaryData:r.revenue}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Cost of Sales"}),e.jsx("td",{children:r.costOfSales.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.costOfSales.amount.formatted},a.year))]}),commentaryData:r.costOfSales}),e.jsxs("tr",{children:[e.jsx("th",{children:"Gross Profit"}),e.jsx("th",{children:r.grossProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.grossProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses"}),e.jsx("td",{children:r.researchAndDevelopmentExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpenses.amount.formatted},a.year))]}),commentaryData:r.researchAndDevelopmentExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Marketing Expenses"}),e.jsx("td",{children:r.marketingExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.marketingExpenses.amount.formatted},a.year))]}),commentaryData:r.marketingExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Management and General Expenses"}),e.jsx("td",{children:r.managementAndGeneralExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.managementAndGeneralExpenses.amount.formatted},a.year))]}),commentaryData:r.managementAndGeneralExpenses}),e.jsxs("tr",{children:[e.jsx("th",{children:"Operating Profit"}),e.jsx("th",{children:r.operatingProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.operatingProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Financial Expenses"}),e.jsx("td",{children:r.financialExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.financialExpenses.amount.formatted},a.year))]}),commentaryData:r.financialExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Other Income"}),e.jsx("td",{children:r.otherIncome.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.otherIncome.amount.formatted},a.year))]}),commentaryData:r.otherIncome}),e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:r.profitBeforeTax.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.profitBeforeTax.formatted},t.year))]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax"}),e.jsx("td",{children:r.tax.formatted}),e.jsx("td",{}),s.map(t=>e.jsx("td",{children:t.tax.formatted},t.year))]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Net Profit"}),e.jsx("th",{children:r.netProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.netProfit.formatted},t.year))]})})]})})})};export{G as ProfitAndLossReport};
1
+ import{r as c,j as e,g9 as p,B as u,a as y,F as g,u as P,L as D,ga as w}from"./index-llwTvhRi.js";import{d as R}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as E}from"./page-layout-ClvcCJfx.js";import{R as d}from"./report-commentary-row-CuMCzc7C.js";import{P as v}from"./modal-B0cCJdW9.js";import{F}from"./funnel-DrbTHWGk.js";import{T as C}from"./Table-8-ldSKpC.js";import"./toggle-expansion-button-CGwmL9mo.js";import"./panel-top-open-pJuuLeLe.js";function A({year:l,setYear:h,referenceYears:o,setReferenceYears:j}){const[m,x]=c.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsx(v,{opened:m,onClose:()=>x(!1),withCloseButton:!0,content:e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change report year",value:new Date(l,0,1),onChange:n=>n&&h(n?.getFullYear()),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date}),e.jsx(p,{type:"multiple",label:"Pick reference years",value:o?.map(n=>new Date(n,0,1)),onChange:n=>j(n.map(i=>i.getFullYear()).filter(i=>l!==i)),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})]})}),e.jsx(u,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>x(!0),children:e.jsx(F,{className:"size-5"})})]})}const G=()=>{const{year:l}=y(),{setFiltersContext:h}=c.useContext(g),[o,j]=c.useState(l?Number(l):new Date().getFullYear()),[m,x]=c.useState([]),[{data:n,fetching:i}]=P({query:R(w),variables:{reportYear:o,referenceYears:m}});c.useEffect(()=>{h(e.jsx("div",{className:"flex flex-row gap-2",children:e.jsx(A,{year:o,setYear:j,referenceYears:m,setReferenceYears:x})}))},[o,i,h,m,x]);const f=n?.profitAndLossReport,r=f?.report,s=f?.reference??[];return e.jsx(E,{title:"Profit and Loss Report",children:i?e.jsx(D,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx("div",{className:"flex flex-col gap-4",children:r&&e.jsxs(C,{highlightOnHover:!0,fontSize:"md",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{}),e.jsx("th",{children:o},o),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.year},t.year))]})}),e.jsxs("tbody",{children:[e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("th",{children:"Revenue"}),e.jsx("th",{children:r.revenue.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("th",{children:a.revenue.amount.formatted},a.year))]}),commentaryData:r.revenue}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Cost of Sales"}),e.jsx("td",{children:r.costOfSales.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.costOfSales.amount.formatted},a.year))]}),commentaryData:r.costOfSales}),e.jsxs("tr",{children:[e.jsx("th",{children:"Gross Profit"}),e.jsx("th",{children:r.grossProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.grossProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"R&D Expenses"}),e.jsx("td",{children:r.researchAndDevelopmentExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.researchAndDevelopmentExpenses.amount.formatted},a.year))]}),commentaryData:r.researchAndDevelopmentExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Marketing Expenses"}),e.jsx("td",{children:r.marketingExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.marketingExpenses.amount.formatted},a.year))]}),commentaryData:r.marketingExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Management and General Expenses"}),e.jsx("td",{children:r.managementAndGeneralExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.managementAndGeneralExpenses.amount.formatted},a.year))]}),commentaryData:r.managementAndGeneralExpenses}),e.jsxs("tr",{children:[e.jsx("th",{children:"Operating Profit"}),e.jsx("th",{children:r.operatingProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.operatingProfit.formatted},t.year))]}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Financial Expenses"}),e.jsx("td",{children:r.financialExpenses.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.financialExpenses.amount.formatted},a.year))]}),commentaryData:r.financialExpenses}),e.jsx(d,{dataRow:t=>e.jsxs("tr",{children:[e.jsx("td",{children:"Other Income"}),e.jsx("td",{children:r.otherIncome.amount.formatted}),e.jsx("th",{children:t}),s.map(a=>e.jsx("td",{children:a.otherIncome.amount.formatted},a.year))]}),commentaryData:r.otherIncome}),e.jsxs("tr",{children:[e.jsx("th",{children:"Profit Before Tax"}),e.jsx("th",{children:r.profitBeforeTax.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.profitBeforeTax.formatted},t.year))]}),e.jsxs("tr",{children:[e.jsx("td",{children:"Tax"}),e.jsx("td",{children:r.tax.formatted}),e.jsx("td",{}),s.map(t=>e.jsx("td",{children:t.tax.formatted},t.year))]})]}),e.jsx("tfoot",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Net Profit"}),e.jsx("th",{children:r.netProfit.formatted}),e.jsx("th",{}),s.map(t=>e.jsx("th",{children:t.netProfit.formatted},t.year))]})})]})})})};export{G as ProfitAndLossReport};