@accounter/client 0.0.9-alpha-20251209170231-980cc730914111644c9194dac5ac995a09e28c74 → 0.0.9-alpha-20251209180606-3a6955e2550a513499455f9b883fddde55c1d061

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 (94) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/assets/{Checkbox-CoEj3QSE.js → Checkbox-BHVKlxRj.js} +1 -1
  3. package/dist/assets/{MultiSelect-DRJD_QDr.js → MultiSelect-DY08OexD.js} +1 -1
  4. package/dist/assets/{Progress-CU1fWOjF.js → Progress-CkBW27DM.js} +1 -1
  5. package/dist/assets/{Table-C5b9rbOB.js → Table-bhKB4PFK.js} +1 -1
  6. package/dist/assets/{Typography-CJ6IUHKs.js → Typography-DclIL89E.js} +1 -1
  7. package/dist/assets/{YearPickerInput-DD-O605S.js → YearPickerInput-DgK0Ih6X.js} +1 -1
  8. package/dist/assets/{accordion-Csw2mWiO.js → accordion-CAxRDsFz.js} +1 -1
  9. package/dist/assets/{accountant-approvals-BeUBLtnd.js → accountant-approvals-Dgsw0WDb.js} +1 -1
  10. package/dist/assets/{accounter-table-CLNNqdXm.js → accounter-table-DIm6Wedu.js} +1 -1
  11. package/dist/assets/{addDays-oqtNz11p.js → addDays-CpwSVE6j.js} +1 -1
  12. package/dist/assets/{all-charges-BK_c2XcZ.js → all-charges-CS_0zCEZ.js} +1 -1
  13. package/dist/assets/{arrow-up-down-BepSQkkk.js → arrow-up-down-BCKzoFzo.js} +1 -1
  14. package/dist/assets/{building-2-DoYjr9zp.js → building-2-Cp2Es1mt.js} +1 -1
  15. package/dist/assets/{business-C49SW3ik.js → business-B1WVYc0i.js} +2 -2
  16. package/dist/assets/{business-extended-info-CaoOYPT8.js → business-extended-info-NwMS1Rj6.js} +1 -1
  17. package/dist/assets/{business-header-gf-FUFaN.js → business-header-D7w2Xzis.js} +1 -1
  18. package/dist/assets/{business-ledger-filters-Clr_J6Pb.js → business-ledger-filters-BBCKjVgu.js} +1 -1
  19. package/dist/assets/{business-ledger-single-CeMmKYhH.js → business-ledger-single-CjmguyFq.js} +1 -1
  20. package/dist/assets/{business-trip-DNDWlM8w.js → business-trip-BljjobKa.js} +1 -1
  21. package/dist/assets/charge-ChPubJah.js +1 -0
  22. package/dist/assets/{charges-filters-nFUpOOgf.js → charges-filters-D_ruML4x.js} +1 -1
  23. package/dist/assets/{charges-ledger-validation-zMQsg1pC.js → charges-ledger-validation-RNuvPfFo.js} +1 -1
  24. package/dist/assets/{charges-table-CTMLwet4.js → charges-table-Dmz1Fxim.js} +1 -1
  25. package/dist/assets/{chart-CcwcQbqJ.js → chart-MqLuc9m0.js} +1 -1
  26. package/dist/assets/{contracts-CAZC6d8B.js → contracts-DCmvv-5I.js} +1 -1
  27. package/dist/assets/{data-table-column-header-BxsKrjBX.js → data-table-column-header-CT7O7uRT.js} +1 -1
  28. package/dist/assets/{data-table-pagination-wIOuSOqc.js → data-table-pagination-Bn6-S7wX.js} +1 -1
  29. package/dist/assets/{deposits-transactions-table-jhVmfuNs.js → deposits-transactions-table-BAObjoYX.js} +1 -1
  30. package/dist/assets/{download-csv-button-CxFM5ZN1.js → download-csv-button-BsXK9P76.js} +1 -1
  31. package/dist/assets/{edit-issue-document-modal-CI2VPVkB.js → edit-issue-document-modal-CG9FH4t_.js} +1 -1
  32. package/dist/assets/{editable-business-trip-B388mlUw.js → editable-business-trip-CH61WHL7.js} +1 -1
  33. package/dist/assets/{eye-off-CfHy9jRk.js → eye-off-Cc-ssiRk.js} +1 -1
  34. package/dist/assets/{funnel-Cn1E8rCW.js → funnel-4UXATjU3.js} +1 -1
  35. package/dist/assets/{index-BbVwSP6k.js → index-BHTel4x6.js} +1 -1
  36. package/dist/assets/{index-U9BN8IFT.js → index-BNGi9a78.js} +1 -1
  37. package/dist/assets/{index-ITLfbYgx.js → index-BNMU0DUr.js} +1 -1
  38. package/dist/assets/{index-lzDrXIqE.js → index-BWtniMl1.js} +1 -1
  39. package/dist/assets/{index-W0j_QNs_.js → index-C3pJ0CeY.js} +1 -1
  40. package/dist/assets/{index-ultzcMfl.js → index-C9bDcLJk.js} +1 -1
  41. package/dist/assets/{index-DBLC9vCJ.js → index-CFOw7tWS.js} +1 -1
  42. package/dist/assets/{index-BYgtjSMY.js → index-CFrclniY.js} +1 -1
  43. package/dist/assets/{index-qAF5sGRO.js → index-CHtpNrAW.js} +4 -4
  44. package/dist/assets/{index-BM4xRMf6.js → index-CPuaqVQw.js} +1 -1
  45. package/dist/assets/{index-DuJJkBba.js → index-CjcufnQY.js} +1 -1
  46. package/dist/assets/{index-DAjmDqPJ.js → index-Cw81Wg3b.js} +1 -1
  47. package/dist/assets/{index-BcxhLoO7.js → index-Cz49agDK.js} +1 -1
  48. package/dist/assets/{index-DHYVY3Bq.js → index-D42PKeAo.js} +1 -1
  49. package/dist/assets/{index-BWtxBLCR.js → index-D8HuUMKu.js} +1 -1
  50. package/dist/assets/{index-bfQMiA8o.js → index-DPzHTlTo.js} +1 -1
  51. package/dist/assets/{index-CM5jGkPB.js → index-DQsGXPYg.js} +1 -1
  52. package/dist/assets/{index-D0scMlrm.js → index-DVU7w2C4.js} +1 -1
  53. package/dist/assets/{index-Bcc1EVhw.js → index-DYUcGCvp.js} +1 -1
  54. package/dist/assets/{index-BvTcJJXh.js → index-De4VpPkV.js} +1 -1
  55. package/dist/assets/{index-2Ym7mPTf.js → index-JJZ0k_k8.js} +1 -1
  56. package/dist/assets/{index-vQiKHr5F.js → index-SV9JUpu6.js} +1 -1
  57. package/dist/assets/{index-DrY2LoBX.js → index-YQXRLoVL.js} +1 -1
  58. package/dist/assets/{index-Bq4ew9mE.js → index-lpyXbMDd.js} +1 -1
  59. package/dist/assets/{index-MvqJWvoO.js → index-qyF0HH0t.js} +1 -1
  60. package/dist/assets/{index-oJIMvEL1.js → index-xOkwbA9z.js} +1 -1
  61. package/dist/assets/{index.es-Cbmre-3y.js → index.es-DnF4r6Dk.js} +1 -1
  62. package/dist/assets/{insert-business-trip-modal-_imZNOPq.js → insert-business-trip-modal-CQv_ZpxL.js} +1 -1
  63. package/dist/assets/issue-document-DJMGPj2s.js +1 -0
  64. package/dist/assets/{list-plus-DEqGGtBU.js → list-plus-DsfXaxO5.js} +1 -1
  65. package/dist/assets/{login-page-CUSymIR_.js → login-page-DKeixPVN.js} +1 -1
  66. package/dist/assets/{match-document-modal-CQ8I-zEU.js → match-document-modal-LhAEyv1y.js} +1 -1
  67. package/dist/assets/{missing-info-charges-CFt2F-LA.js → missing-info-charges-DCVKrfEr.js} +1 -1
  68. package/dist/assets/{modal-D_KAAYCr.js → modal-YTgF-R03.js} +1 -1
  69. package/dist/assets/{modify-contract-dialog-DSwRl9du.js → modify-contract-dialog-D7Z8bOws.js} +1 -1
  70. package/dist/assets/{page-layout-7iCtDTzs.js → page-layout-Cs7LzhPs.js} +1 -1
  71. package/dist/assets/{page-not-found-CsSbBsPd.js → page-not-found-Cs086tZP.js} +1 -1
  72. package/dist/assets/{panel-top-open-CVvVnpDH.js → panel-top-open-DfXV4xoB.js} +1 -1
  73. package/dist/assets/{pencil-CpYjq1NY.js → pencil-3H1z0dQ2.js} +1 -1
  74. package/dist/assets/{report-commentary-row-CgmMnDJu.js → report-commentary-row-DNTsFgf_.js} +1 -1
  75. package/dist/assets/{save-C6S-RD-9.js → save-D2KnX2aJ.js} +1 -1
  76. package/dist/assets/{similar-transactions-modal-Dn4dMAAO.js → similar-transactions-modal-DN6pAqBR.js} +1 -1
  77. package/dist/assets/{sub-DgacWlyb.js → sub-UiWBdxTZ.js} +1 -1
  78. package/dist/assets/subMonths-DZvdAXT7.js +1 -0
  79. package/dist/assets/{summary-ZTGFg2Jz.js → summary-DLRjO19t.js} +1 -1
  80. package/dist/assets/{toggle-expansion-button-DYABrNZG.js → toggle-expansion-button-ByfnT_sn.js} +1 -1
  81. package/dist/assets/tooltip-0-bix6mQ.js +1 -0
  82. package/dist/assets/{use-url-query-CYeryni6.js → use-url-query-DMunwqS4.js} +1 -1
  83. package/dist/index.html +1 -1
  84. package/package.json +1 -1
  85. package/src/components/business/admin/financial-account-section.tsx +0 -2
  86. package/src/components/financial-accounts/financial-account-card.tsx +0 -4
  87. package/src/components/financial-accounts/modify-financial-account-dialog.tsx +0 -19
  88. package/src/components/financial-accounts/types.ts +0 -1
  89. package/src/gql/gql.ts +3 -3
  90. package/src/gql/graphql.ts +2 -5
  91. package/dist/assets/charge-NQDW3QqJ.js +0 -1
  92. package/dist/assets/issue-document-BbxmF4sT.js +0 -1
  93. package/dist/assets/subMonths-oKYDpkY2.js +0 -1
  94. package/dist/assets/tooltip-Br1wJ5zm.js +0 -1
@@ -1 +1 @@
1
- import{v as ve,bt as Ye,ce as Ze,r as p,bu as Ke,cf as ie,aF as Xe,bv as Qe,cg as Je,ch as es,j as e,B as v,L as Se,g as B,ci as ss,t as j,i as S,H as Ie,u as ne,cj as ge,bz as b,bC as q,ck as ae,cl as Ne,aC as ts,bA as U,bB as W,w as M,ay as Fe,cm as Me,l as L,T as w,a3 as G,y as N,n as C,V as I,Y as z,Z as P,_ as X,$,I as Q,a1 as _,b3 as ze,cn as Y,d as Z,co as ns,cp as rs,cq as is,bq as D,cr as as,bT as Pe,cs as $e,G as A,ai as be,R as ye,ct as os,ah as J,e as ee,cu as cs,cv as ds,cw as ls,cx as us,by as Oe,cy as hs,cz as ps,cA as xs,cB as Re,cC as ms,cD as gs,cE as js,cF as fs,cG as vs,cH as bs,at as je,cI as ys,cJ as Ts,cK as Es,cL as Cs,cM as As,cN as ws,cO as Ds,cP as Bs,cQ as Ss,cR as Is,cS as Ns,cT as Fs,cU as Ms,cV as zs,cW as Ps,cX as $s,cY as Os,cZ as Rs,c_ as ks,q as Hs,c$ as _s,d0 as Vs,d1 as Ls,d2 as Us,d3 as Ws,d4 as fe,d5 as qs,d6 as Gs}from"./index-qAF5sGRO.js";import{L as ke}from"./list-plus-DEqGGtBU.js";import{G as te,L as xe,C as He,R as Ys,A as E,S as Zs}from"./summary-ZTGFg2Jz.js";import{T as se}from"./Table-C5b9rbOB.js";import{T as Ks}from"./toggle-expansion-button-DYABrNZG.js";import{M as _e}from"./MultiSelect-DRJD_QDr.js";import{u as Xs,S as Qs}from"./similar-transactions-modal-Dn4dMAAO.js";import{T as Js}from"./tooltip-Br1wJ5zm.js";const et=[["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"}]],st=ve("car",et);const tt=[["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"}]],nt=ve("fuel",tt);const rt=[["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"}]],it=ve("printer",rt);var at=Ye((i,{fluid:n,sizes:r},{size:t})=>({root:{paddingLeft:i.spacing.md,paddingRight:i.spacing.md,maxWidth:n?"100%":Ze({size:t,sizes:r}),marginLeft:"auto",marginRight:"auto"}})),ot=Object.defineProperty,me=Object.getOwnPropertySymbols,Ve=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable,Te=(i,n,r)=>n in i?ot(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,ct=(i,n)=>{for(var r in n||(n={}))Ve.call(n,r)&&Te(i,r,n[r]);if(me)for(var r of me(n))Le.call(n,r)&&Te(i,r,n[r]);return i},dt=(i,n)=>{var r={};for(var t in i)Ve.call(i,t)&&n.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&me)for(var t of me(i))n.indexOf(t)<0&&Le.call(i,t)&&(r[t]=i[t]);return r};const lt={sizes:{xs:ie(540),sm:ie(720),md:ie(960),lg:ie(1140),xl:ie(1320)}},ut=p.forwardRef((i,n)=>{const r=Ke("Container",lt,i),{className:t,fluid:s,size:a,unstyled:o,sizes:d,variant:x}=r,m=dt(r,["className","fluid","size","unstyled","sizes","variant"]),{classes:h,cx:l}=at({fluid:s,sizes:d},{unstyled:o,name:"Container",variant:x,size:a});return Xe.createElement(Qe,ct({className:l(h.root,t),ref:n},m))});ut.displayName="@mantine/core/Container";var H=3.77952755906,he={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},ht=class{pdf;canvas;options;constructor(i,n){this.canvas=i,this.options=n,this.pdf=new es({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(i)}getMarginLeftMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(i)}getMarginRightMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(i)}getMarginBottomMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(i)}getMarginTop(){return this.getMarginTopMM()*H}getMarginBottom(){return this.getMarginBottomMM()*H}getMarginLeft(){return this.getMarginLeftMM()*H}getMarginRight(){return this.getMarginRightMM()*H}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*H}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*H}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()/H}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/H}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(i){return this.getCanvasPageAvailableHeight()*(i-1)}getCanvasHeightLeft(i){return this.canvas.height-this.getCanvasOffsetY(i)}getCanvasPageHeight(i){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(i);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(i){const n=this.getCanvasPageWidth(),r=this.getCanvasPageHeight(i),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(r)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(i),this.canvas.width,r,0,0,this.canvas.width,r),t}convert(){let i=1;const n=this.getNumberPages();for(;i<=n;){i>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const r=this.createCanvasPage(i),t=r.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(i),this.pdf.addImage({imageData:t,width:r.width/(this.getScale()*H*this.getHorizontalFitFactor()),height:r.height/(this.getScale()*H*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),i+=1}return this.pdf}},pt=i=>i?{...he,...i,canvas:{...he.canvas,...i.canvas},page:{...he.page,...i.page}}:he,xt=i=>typeof i=="function"?i():i?.current,mt=async(i,n)=>{const r=pt(n),t=xt(i);if(!t){console.error("Unable to get the target element.");return}const s=await Je(t,{useCORS:r.canvas.useCORS,logging:r.canvas.logging,scale:r.resolution,...r.overrides?.canvas}),o=new ht(s,r).convert();switch(r.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;case"save":default:{const d=r.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},gt=mt;const jt={method:"open",overrides:{pdf:{compress:!0}}},ft=()=>document.getElementById("main-page"),Hn=({filename:i})=>{const[n,r]=p.useState(!1),t=async()=>{r(!0),await gt(ft,{...jt,filename:i}),r(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(it,{className:"size-5"})})},vt="addBusinessTripAccommodationsExpense",bt=()=>{const[{fetching:i},n]=B(ss),r=p.useCallback(async t=>{const s="Error adding business trip accommodations expense",a=vt;j.loading("Adding Business Trip Accommodations Expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripAccommodationsExpense:r}};function Ue({formManager:i,attendeesStayPath:n,attendeesData:r,fetchingAttendees:t=!1,businessTripId:s}){const{control:a,watch:o,trigger:d}=i,{fields:x,append:m,remove:h}=Ie({control:a,name:n}),[l,c]=p.useState(t),[u,g]=p.useState(r??[]),f=o(n),T=x.map((F,R)=>({...F,...f[R]}));p.useEffect(()=>{r&&g(r)},[r]),p.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:O},K]=ne({query:ge,pause:!0,variables:{businessTripId:s??""}});return p.useEffect(()=>{if(y?.businessTrip?.attendees.length){const F=y.businessTrip.attendees.map(R=>({value:R.id,label:R.name}))??[];g(F)}},[y?.businessTrip?.attendees]),p.useEffect(()=>{c(O)},[O]),p.useEffect(()=>{!r&&!y&&!t&&!O&&K({businessTripId:s})},[r,t,O,K,s,y]),!s&&!r?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((F,R)=>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}.${R}.attendeeId`,control:a,rules:{required:"Required"},render:({field:k,fieldState:re})=>e.jsx(q,{...k,disabled:l,data:u,value:k.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:re.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:a,name:`${n}.${R}.nightsCount`,render:({field:k,fieldState:re})=>e.jsx(ae,{className:"w-full",...k,min:0,label:"Nights Count",value:k.value??void 0,hideControls:!0,precision:0,error:re.error?.message,required:!0,onChange:V=>k.onChange(V&&typeof V=="number"?V:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(R),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},F.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{m({}),d(n)},children:e.jsx(ke,{className:"size-5"})})]})]})}function oe({businessTripId:i,control:n,setFetching:r}){const[t,s]=p.useState([]),[{data:a,fetching:o,error:d}]=ne({query:ge,variables:{businessTripId:i}}),{userContext:x}=p.useContext(ts);p.useEffect(()=>{a?.businessTrip?.attendees.length&&s(a.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[a,s]),p.useEffect(()=>{r(o)},[r,o]),p.useEffect(()=>{d&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const m=p.useMemo(()=>x?.context.ledgerLock,[x]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:m?{value:m,message:`Date must be after ${m}`}:void 0,pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(W,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:M(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:U,message:"Date must be im format yyyy-mm-dd"},min:m?{value:m,message:`Date must be after ${m}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(W,{...h,onChange:c=>{const u=c?typeof c=="string"?c:M(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(q,{...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 Ee(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function yt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripAccommodationsExpense:m,fetching:h}=bt(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Accommodation Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{control:a,name:"country",render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Country"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),e.jsx(z,{name:"nightsCount",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Nights Count"}),e.jsx($,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(_,{})]})}),e.jsx(Ue,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:i}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Tt="updateBusinessTripAccommodationsExpense",Et=()=>{const[{fetching:i},n]=B(ns),r=p.useCallback(async t=>{const s="Error updating business trip accommodations expense",a=Tt;j.loading("Updating trip accommodations expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAccommodationsExpense:r}},Ct="categorizeIntoExistingBusinessTripExpense",At=()=>{const[{fetching:i},n]=B(rs),r=p.useCallback(async t=>{const s="Error updating business trip expense category",a=Ct;j.loading("Updating business trip expense category",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeIntoExistingBusinessTripExpense:r}};function ce(i){const{businessTripExpenseId:n,businessTripId:r,onChange:t}=i,[s,{close:a,open:o}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(G,{className:"size-5"})})}),s&&e.jsx(wt,{businessTripExpenseId:n,businessTripId:r,opened:s,close:a,onChange:t})]})}function wt({businessTripExpenseId:i,businessTripId:n,opened:r,close:t,onChange:s}){const{control:a,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:i}}),[x,m]=p.useState([]),[{data:h,fetching:l,error:c}]=ne({query:is,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:g}=At(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return p.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);m(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,O)=>y.eventDate.localeCompare(O.eventDate)))}},[h,m]),p.useEffect(()=>{c&&j.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(C,{opened:r,onClose:t,centered:!0,children:[e.jsx(C.Title,{children:"Set Transaction Category"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:a,render:({field:T,fieldState:y})=>e.jsx(q,{...T,itemComponent:Dt,data:x??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:O=>{const K=x.find(F=>F.value===O);K?.rawAmount&&d("amount",K.rawAmount),T.onChange(O)}})}),e.jsx(b,{name:"amount",control:a,render:({field:T,fieldState:y})=>e.jsx(ae,{...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"})})]})}),g&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Dt=p.forwardRef(({eventDate:i,sourceDescription:n,referenceKey:r,counterparty:t,amount:s,...a},o)=>e.jsx("div",{ref:o,...a,children:e.jsxs(te,{children:[e.jsx(te.Col,{span:4,children:i}),e.jsx(te.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(te.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(te.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(te.Col,{span:4,children:["Reference: ",r]})]})})),Bt="deleteBusinessTripExpense",St=()=>{const[{fetching:i},n]=B(as),r=p.useCallback(async t=>{const s="Error deleting business trip expense",a=`${Bt}-${t.businessTripExpenseId}`;j.loading("Deleting trip expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripExpense:r}};function de(i){const{fetching:n,deleteBusinessTripExpense:r}=St(),t=p.useCallback(()=>{r({businessTripExpenseId:i.businessTripExpenseId}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(w,{label:"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 le=({data:i,isEditMode:n=!1,control:r,businessTripId:t})=>{const s=A(os,i),[a,o]=p.useState([]),[{data:d,fetching:x,error:m}]=ne({query:ge,variables:{businessTripId:t}});p.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]),p.useEffect(()=>{m&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[m]);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:r,defaultValue:s.date,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:r,defaultValue:s.valueDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,form:`form ${s.id}`,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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&&M(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&M(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:r,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:r,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:g})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||g.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:r,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(q,{form:`form ${s.id}`,...l,data:a,value:l.value,disabled:x,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))})})]})},ue=()=>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"})]}),It=({data:i,businessTripId:n,onChange:r})=>{const t=A(cs,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:x}=o,{updateBusinessTripAccommodationsExpense:m,fetching:h}=Et(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(I,{...o,children:e.jsx(z,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(_,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(I,{...o,children:e.jsx(Ue,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(xe,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(xe.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})})]},t.id)},We=({businessTripId:i,expenses:n,onChange:r})=>{if(!n?.length)return r?e.jsx(Ee,{businessTripId:i,onAdd:r}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ds,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),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,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(It,{data:s,businessTripId:i,onChange:r},s.id)),r&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ee,{businessTripId:i,onAdd:r})})})]})]})})},Nt=({data:i,onChange:n})=>{const{accommodationExpenses:r,id:t}=A(ls,i);return e.jsx(We,{businessTripId:t,expenses:r,onChange:n})},Ft="insertBusinessTripAttendee",Mt=()=>{const[{fetching:i},n]=B(us),r=p.useCallback(async t=>{const s="Error adding attendee to business trip",a=Ft;j.loading("Adding attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,insertBusinessTripAttendee:r}};function Ce(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(zt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function zt({businessTripId:i,opened:n,close:r,onAdd:t}){const{selectableBusinesses:s,fetching:a}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:i}}),{insertBusinessTripAttendee:x,fetching:m}=Mt(),h=l=>{x({fields:l}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,children:[e.jsx(C.Title,{children:"Add Attendee"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(q,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:a,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:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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"})})]})}),(m||a)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Pt="updateBusinessTripAttendee",$t=()=>{const[{fetching:i},n]=B(hs),r=p.useCallback(async t=>{const s="Error updating business trip attendee",a=Pt;j.loading("Updating trip attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAttendee:r}},Ot="deleteBusinessTripAttendee",Rt=()=>{const[{fetching:i},n]=B(ps),r=p.useCallback(async t=>{const s="Error removing business trip attendee",a=Ot;j.loading("Removing business trip attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripAttendee:r}};function kt(i){const{fetching:n,deleteBusinessTripAttendee:r}=Rt(),t=p.useCallback(()=>{r({fields:{businessTripId:i.businessTripId,attendeeId:i.attendeeId}}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(w,{label:"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 Ht="addBusinessTripFlightsExpense",_t=()=>{const[{fetching:i},n]=B(xs),r=p.useCallback(async t=>{const s="Error adding business trip flight expense",a=Ht;j.loading("Adding business trip flight expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripFlightsExpense:r}};function qe({formManager:i,flightPathPath:n,flightPathData:r}){const{control:t,watch:s,trigger:a}=i,{fields:o,append:d,remove:x}=Ie({control:t,name:n}),m=s(n),h=o.map((l,c)=>({...l,...m[c]}));return r?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(z,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(_,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{x(c),a(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),a(n)},children:e.jsx(ke,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ae(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(Lt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}const Vt=Object.entries(Re).map(([i,n])=>({value:n,label:i}));function Lt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),[{data:m,fetching:h}]=ne({query:ge,variables:{businessTripId:i}}),{addBusinessTripFlightsExpense:l,fetching:c}=_t(),u=f=>{l({fields:f}).then(()=>{t?.(),r()})},g=m?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Flight Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(qe,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:a,render:({field:f,fieldState:T})=>e.jsx(q,{...f,data:Vt,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:a,render:({field:f,fieldState:T})=>e.jsx(_e,{...f,disabled:h,data:g,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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Ut="updateBusinessTripFlightsExpense",Wt=()=>{const[{fetching:i},n]=B(ms),r=p.useCallback(async t=>{const s="Error updating business trip flights expense",a=Ut;j.loading("Updating trip flights expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripFlightsExpense:r}},qt=Object.entries(Re).map(([i,n])=>({value:n,label:i})),Gt=({data:i,businessTripId:n,onChange:r,attendees:t})=>{const s=A(gs,i),[a,o]=p.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(g=>g.id)??[],path:s.path??[]}}),{control:x,handleSubmit:m}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Wt(),c=g=>{h({fields:g}).then(()=>{r?.(),o(!1)})},u=t.map(g=>({value:g.id,label:g.name}));return e.jsxs("tr",{children:[e.jsx(le,{data:s,isEditMode:a,control:x,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:m(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[a?e.jsx(qe,{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((g,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:g},f),f<s.path.length-1&&(g===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),a?e.jsx(b,{name:"flightClass",control:x,defaultValue:s.class??void 0,render:({field:g,fieldState:f})=>e.jsx(q,{form:`form ${s.id}`,"data-autofocus":!0,...g,data:qt,value:g.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:a?e.jsx(b,{name:"attendeeIds",control:x,defaultValue:s.attendees?.map(g=>g.id)??void 0,render:({field:g,fieldState:f})=>e.jsx(_e,{...g,form:`form ${s.id}`,data:u,value:g.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(xe,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(g=>e.jsx(xe.Item,{children:g.name},g.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:l,variant:a?"default":"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),o(f=>!f)},children:e.jsx(J,{className:"size-5"})})}),a&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:s.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:s.id,onDelete:r})]})})]},s.id)},Ge=({businessTripId:i,expenses:n,attendees:r,onChange:t})=>{if(!n?.length)return t?e.jsx(Ae,{businessTripId:i,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(a=>A(js,a));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((a,o)=>a.date&&o.date?a.date<o.date?1:-1:a.date?-1:o.date?1:0).map(a=>e.jsx(Gt,{data:a,businessTripId:i,onChange:t,attendees:r},a.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ae,{businessTripId:i,onAdd:t})})})]})]})})},Yt=({data:i,businessTripId:n,onChange:r})=>{const t=A(fs,i),[s,a]=p.useState(!1),[o,d]=p.useState(!1),{control:x,handleSubmit:m}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=$t(),c=u=>{h({fields:u}).then(()=>{r?.(),a(!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:m(c),children:e.jsx(b,{name:"arrivalDate",control:x,defaultValue:t.arrivalDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(W,{...u,onChange:f=>{const T=f?typeof f=="string"?f:M(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:g.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:x,defaultValue:t.departureDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(W,{...u,onChange:f=>{const T=f?typeof f=="string"?f:M(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:g.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),a(g=>!g)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(kt,{businessTripId:n,attendeeId:t.id,onDelete:r}),e.jsx(Ks,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(He,{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(Ge,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(We,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},Zt=({data:i,onChange:n})=>{const{attendees:r,id:t}=A(vs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{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:[r.sort((s,a)=>s.name.toLocaleLowerCase()>a.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Yt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ce,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ce,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Kt=()=>{const[{fetching:i},n]=B(bs),r=p.useCallback(async t=>{const s="Error adding business trip car rental expense";j.loading("Adding car rental expense...",{id:pe});try{const a=await n(t),o=S(a,s,pe);if(o)return j.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(a){console.error(`${s}: ${a}`),j.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripCarRentalExpense:r}};function we(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(Xt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function Xt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripCarRentalExpense:m,fetching:h}=Kt(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Car Rental Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(b,{name:"days",control:a,render:({field:c,fieldState:u})=>e.jsx(ae,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(z,{name:"isFuelExpense",control:a,render:({field:{value:c,...u}})=>e.jsxs(P,{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(X,{children:"Is Fuel Expense"})}),e.jsx($,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(_,{})]})}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Qt="updateBusinessTripCarRentalExpense",Jt=()=>{const[{fetching:i},n]=B(ys),r=p.useCallback(async t=>{const s="Error updating business trip car rental expense",a=Qt;j.loading("Updating trip car rental expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripCarRentalExpense:r}},en=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ts,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripCarRentalExpense:m,fetching:h}=Jt(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(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(ae,{...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(I,{...o,children:e.jsx(z,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(P,{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(X,{children:"Is Fuel Expense"})}),e.jsx($,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(nt,{}):e.jsx(st,{})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},sn=({data:i,onChange:n})=>{const{carRentalExpenses:r,id:t}=A(Es,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(en,{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})},tn=({data:i,onChange:n})=>{const{flightExpenses:r,id:t,attendees:s}=A(Cs,i);return e.jsx(Ge,{businessTripId:t,attendees:s,expenses:r,onChange:n})},nn="addBusinessTripOtherExpense",rn=()=>{const[{fetching:i},n]=B(As),r=p.useCallback(async t=>{const s='Error adding business trip "other" expense',a=nn;j.loading('Adding trip "other" expense',{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripOtherExpense:r}};function De(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(an,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function an({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripOtherExpense:m,fetching:h}=rn(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Other Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{name:"description",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Description"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),e.jsx(z,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(P,{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(X,{children:"Deductible Expense"})}),e.jsx($,{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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const on="updateBusinessTripOtherExpense",cn=()=>{const[{fetching:i},n]=B(ws),r=p.useCallback(async t=>{const s='Error updating business trip "other" expense',a=on;j.loading('Updating business trip "other" expense',{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripOtherExpense:r}},dn=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ds,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripOtherExpense:m,fetching:h}=cn(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):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(I,{...o,children:e.jsx(z,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(P,{children:e.jsx($,{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(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},ln=({data:i,onChange:n})=>{const{otherExpenses:r,id:t}=A(Bs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(dn,{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})},un="addBusinessTripTravelAndSubsistenceExpense",hn=()=>{const[{fetching:i},n]=B(Ss),r=p.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",a=un;j.loading("Adding trip travel&subsistence expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripTravelAndSubsistenceExpense:r}};function Be(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(pn,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function pn({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:m,fetching:h}=hn(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{name:"expenseType",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Expense Type"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const xn="updateBusinessTripTravelAndSubsistenceExpense",mn=()=>{const[{fetching:i},n]=B(Is),r=p.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",a=xn;j.loading("Updating trip travel&subsistence expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripTravelAndSubsistenceExpense:r}},gn=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ns,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripTravelAndSubsistenceExpense:m,fetching:h}=mn(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},jn=({data:i,onChange:n})=>{const{travelAndSubsistenceExpenses:r,id:t}=A(Fs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(gn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Be,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Be,{businessTripId:t,onAdd:n})},fn=({data:i})=>{const n=A(Ms,i),r="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:r&&M(new Date(r),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",M(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},vn=({data:i})=>{const n=A(zs,i),r="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:r&&M(new Date(r),"dd/MM/yy")})})},bn=({data:i})=>{const n=A(Ps,i),{account:r}=n,t=r.type,s=r.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})]})})},yn=({data:i})=>{const n=A($s,i),r="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:r})})})},Tn=({data:i})=>{const n=A(Os,i);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 En({data:i,onChange:n,enableEdit:r}){const{id:t,counterparty:s,missingInfoSuggestions:a,id:o,sourceDescription:d}=A(Rs,i),x=!!a?.business&&r,m=x?a?.business?.name:"Missing",h=x?a?.business?.id:null,l=s?.name??m,[c,u]=p.useState(!1),{updateTransaction:g,fetching:f}=Xs(),T=p.useCallback(async V=>{await g({transactionId:o,fields:{counterpartyId:V}}),u(!0)},[o,g]),y=p.useCallback(async V=>{await T(V),n?.()},[T,n]),{selectableBusinesses:O,fetching:K}=Oe(),[F,R]=p.useState(h??null),[k,re]=p.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(ks,{options:O,value:F,onChange:R,search:k,onSearchChange:re,placeholder:"Choose or create a business",empty:k?e.jsx(Hs,{description:k,onAdd:y}):null}),e.jsx(Js,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>F&&T(F),disabled:f||K||!F,children:e.jsx(ee,{className:"size-4"})})})]})}),e.jsx(Qs,{transactionId:t,counterpartyId:s?.id??F,open:c,onOpenChange:u,onClose:n})]})}const Cn="categorizeBusinessTripExpense",An=()=>{const[{fetching:i},n]=B(_s),r=p.useCallback(async t=>{const s="Error updating business trip expense category",a=Cn;j.loading("Updating trip expense category",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeBusinessTripExpense:r}};function wn(i){const{businessTripId:n,transactionId:r,onChange:t,defaultAmount:s}=i,[a,{close:o,open:d}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:x=>{x.stopPropagation(),d()},children:e.jsx(J,{className:"size-5"})})}),a&&e.jsx(Bn,{businessTripId:n,transactionId:r,opened:a,close:o,onChange:t,defaultAmount:s})]})}const Dn=Object.entries(Vs).map(([i,n])=>({value:n,label:i}));function Bn({businessTripId:i,transactionId:n,defaultAmount:r,opened:t,close:s,onChange:a}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:i,transactionId:n}}),{categorizeBusinessTripExpense:x,fetching:m}=An(),h=l=>{x({fields:l}).then(()=>{a?.(),s()})};return e.jsxs(C,{opened:t,onClose:s,centered:!0,children:[e.jsx(C.Title,{children:"Set Expense Category"}),e.jsx(C.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(q,{"data-autofocus":!0,...l,data:Dn,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:r,render:({field:l,fieldState:c})=>e.jsx(ae,{...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"})})]})}),m&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Sn=({data:i,onChange:n})=>{const{uncategorizedTransactions:r,id:t}=A(Ls,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{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:r.sort((s,a)=>s.transaction.eventDate.localeCompare(a.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(vn,{data:s.transaction}),e.jsx(fn,{data:s.transaction}),e.jsx(In,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:a=>a.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(bn,{data:s.transaction}),e.jsx(yn,{data:s.transaction}),e.jsx(Tn,{data:s.transaction}),e.jsx(En,{data:s.transaction}),e.jsx("td",{children:e.jsx(wn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},In=({data:i})=>{const{transaction:n,categorizedAmount:r,errors:t}=A(Us,i),s="amount"in n?n.amount:void 0,a=s?.raw!==r.raw&&r.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(Nn,{errors:t})]}),a&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[r.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Ws(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},Nn=({errors:i})=>{const[n,{close:r,open:t}]=L(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(qs,{onMouseEnter:t,onMouseLeave:r})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:i.map((s,a)=>e.jsx(D,{size:"sm",children:s},a))})]})};function _n({tripId:i,isExtended:n=!1}){const[r,t]=p.useState(),[s,a]=p.useState([]),[{data:o},d]=ne({query:Gs,variables:{businessTripId:i}});function x(h){s.includes(h)?a(l=>l.filter(c=>c!==h)):a(l=>[...l,h])}const m=d;return p.useEffect(()=>{o?.businessTrip&&t(o.businessTrip)},[o?.businessTrip]),e.jsx(He,{shadow:"sm",radius:"md",withBorder:!0,children:r?e.jsxs(e.Fragment,{children:[e.jsx(Ys,{data:r,onChange:m}),e.jsxs(E,{className:"w-full",multiple:!0,value:s,chevron:e.jsx(G,{size:"1rem"}),styles:{chevron:{"&[data-rotate]":{transform:"rotate(45deg)"}}},children:[e.jsxs(E.Item,{value:"attendees",children:[e.jsx(E.Control,{onClick:()=>x("attendees"),children:"Attendees"}),e.jsx(E.Panel,{children:e.jsx(Zt,{data:r,onChange:m})})]}),n&&e.jsxs(E.Item,{value:"uncategorized-transactions",children:[e.jsx(E.Control,{onClick:()=>x("uncategorized-transactions"),disabled:!r.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(E.Panel,{children:e.jsx(Sn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"flights",children:[e.jsx(E.Control,{onClick:()=>x("flights"),children:"Flights"}),e.jsx(E.Panel,{children:e.jsx(tn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"accommodations",children:[e.jsx(E.Control,{onClick:()=>x("accommodations"),children:"Accommodations"}),e.jsx(E.Panel,{children:e.jsx(Nt,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"travelAndSubsistence",children:[e.jsx(E.Control,{onClick:()=>x("travelAndSubsistence"),children:"Travel & Subsistence"}),e.jsx(E.Panel,{children:e.jsx(jn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"other",children:[e.jsx(E.Control,{onClick:()=>x("other"),children:"Other"}),e.jsx(E.Panel,{children:e.jsx(ln,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"carRental",children:[e.jsx(E.Control,{onClick:()=>x("carRental"),children:"Car Rental"}),e.jsx(E.Panel,{children:e.jsx(sn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"summary",children:[e.jsx(E.Control,{onClick:()=>x("summary"),children:"Summary"}),e.jsx(E.Panel,{children:e.jsx(Zs,{data:r})})]})]})]}):e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{ut as C,_n as E,Hn as P};
1
+ import{v as ve,bt as Ye,ce as Ze,r as p,bu as Ke,cf as ie,aF as Xe,bv as Qe,cg as Je,ch as es,j as e,B as v,L as Se,g as B,ci as ss,t as j,i as S,H as Ie,u as ne,cj as ge,bz as b,bC as q,ck as ae,cl as Ne,aC as ts,bA as U,bB as W,w as M,ay as Fe,cm as Me,l as L,T as w,a3 as G,y as N,n as C,V as I,Y as z,Z as P,_ as X,$,I as Q,a1 as _,b3 as ze,cn as Y,d as Z,co as ns,cp as rs,cq as is,bq as D,cr as as,bT as Pe,cs as $e,G as A,ai as be,R as ye,ct as os,ah as J,e as ee,cu as cs,cv as ds,cw as ls,cx as us,by as Oe,cy as hs,cz as ps,cA as xs,cB as Re,cC as ms,cD as gs,cE as js,cF as fs,cG as vs,cH as bs,at as je,cI as ys,cJ as Ts,cK as Es,cL as Cs,cM as As,cN as ws,cO as Ds,cP as Bs,cQ as Ss,cR as Is,cS as Ns,cT as Fs,cU as Ms,cV as zs,cW as Ps,cX as $s,cY as Os,cZ as Rs,c_ as ks,q as Hs,c$ as _s,d0 as Vs,d1 as Ls,d2 as Us,d3 as Ws,d4 as fe,d5 as qs,d6 as Gs}from"./index-CHtpNrAW.js";import{L as ke}from"./list-plus-DsfXaxO5.js";import{G as te,L as xe,C as He,R as Ys,A as E,S as Zs}from"./summary-DLRjO19t.js";import{T as se}from"./Table-bhKB4PFK.js";import{T as Ks}from"./toggle-expansion-button-ByfnT_sn.js";import{M as _e}from"./MultiSelect-DY08OexD.js";import{u as Xs,S as Qs}from"./similar-transactions-modal-DN6pAqBR.js";import{T as Js}from"./tooltip-0-bix6mQ.js";const et=[["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"}]],st=ve("car",et);const tt=[["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"}]],nt=ve("fuel",tt);const rt=[["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"}]],it=ve("printer",rt);var at=Ye((i,{fluid:n,sizes:r},{size:t})=>({root:{paddingLeft:i.spacing.md,paddingRight:i.spacing.md,maxWidth:n?"100%":Ze({size:t,sizes:r}),marginLeft:"auto",marginRight:"auto"}})),ot=Object.defineProperty,me=Object.getOwnPropertySymbols,Ve=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable,Te=(i,n,r)=>n in i?ot(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,ct=(i,n)=>{for(var r in n||(n={}))Ve.call(n,r)&&Te(i,r,n[r]);if(me)for(var r of me(n))Le.call(n,r)&&Te(i,r,n[r]);return i},dt=(i,n)=>{var r={};for(var t in i)Ve.call(i,t)&&n.indexOf(t)<0&&(r[t]=i[t]);if(i!=null&&me)for(var t of me(i))n.indexOf(t)<0&&Le.call(i,t)&&(r[t]=i[t]);return r};const lt={sizes:{xs:ie(540),sm:ie(720),md:ie(960),lg:ie(1140),xl:ie(1320)}},ut=p.forwardRef((i,n)=>{const r=Ke("Container",lt,i),{className:t,fluid:s,size:a,unstyled:o,sizes:d,variant:x}=r,m=dt(r,["className","fluid","size","unstyled","sizes","variant"]),{classes:h,cx:l}=at({fluid:s,sizes:d},{unstyled:o,name:"Container",variant:x,size:a});return Xe.createElement(Qe,ct({className:l(h.root,t),ref:n},m))});ut.displayName="@mantine/core/Container";var H=3.77952755906,he={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},ht=class{pdf;canvas;options;constructor(i,n){this.canvas=i,this.options=n,this.pdf=new es({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(i)}getMarginLeftMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(i)}getMarginRightMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(i)}getMarginBottomMM(){const i=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(i)}getMarginTop(){return this.getMarginTopMM()*H}getMarginBottom(){return this.getMarginBottomMM()*H}getMarginLeft(){return this.getMarginLeftMM()*H}getMarginRight(){return this.getMarginRightMM()*H}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*H}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*H}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()/H}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/H}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(i){return this.getCanvasPageAvailableHeight()*(i-1)}getCanvasHeightLeft(i){return this.canvas.height-this.getCanvasOffsetY(i)}getCanvasPageHeight(i){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(i);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(i){const n=this.getCanvasPageWidth(),r=this.getCanvasPageHeight(i),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(r)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(i),this.canvas.width,r,0,0,this.canvas.width,r),t}convert(){let i=1;const n=this.getNumberPages();for(;i<=n;){i>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const r=this.createCanvasPage(i),t=r.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(i),this.pdf.addImage({imageData:t,width:r.width/(this.getScale()*H*this.getHorizontalFitFactor()),height:r.height/(this.getScale()*H*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),i+=1}return this.pdf}},pt=i=>i?{...he,...i,canvas:{...he.canvas,...i.canvas},page:{...he.page,...i.page}}:he,xt=i=>typeof i=="function"?i():i?.current,mt=async(i,n)=>{const r=pt(n),t=xt(i);if(!t){console.error("Unable to get the target element.");return}const s=await Je(t,{useCORS:r.canvas.useCORS,logging:r.canvas.logging,scale:r.resolution,...r.overrides?.canvas}),o=new ht(s,r).convert();switch(r.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;case"save":default:{const d=r.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},gt=mt;const jt={method:"open",overrides:{pdf:{compress:!0}}},ft=()=>document.getElementById("main-page"),Hn=({filename:i})=>{const[n,r]=p.useState(!1),t=async()=>{r(!0),await gt(ft,{...jt,filename:i}),r(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(it,{className:"size-5"})})},vt="addBusinessTripAccommodationsExpense",bt=()=>{const[{fetching:i},n]=B(ss),r=p.useCallback(async t=>{const s="Error adding business trip accommodations expense",a=vt;j.loading("Adding Business Trip Accommodations Expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripAccommodationsExpense:r}};function Ue({formManager:i,attendeesStayPath:n,attendeesData:r,fetchingAttendees:t=!1,businessTripId:s}){const{control:a,watch:o,trigger:d}=i,{fields:x,append:m,remove:h}=Ie({control:a,name:n}),[l,c]=p.useState(t),[u,g]=p.useState(r??[]),f=o(n),T=x.map((F,R)=>({...F,...f[R]}));p.useEffect(()=>{r&&g(r)},[r]),p.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:O},K]=ne({query:ge,pause:!0,variables:{businessTripId:s??""}});return p.useEffect(()=>{if(y?.businessTrip?.attendees.length){const F=y.businessTrip.attendees.map(R=>({value:R.id,label:R.name}))??[];g(F)}},[y?.businessTrip?.attendees]),p.useEffect(()=>{c(O)},[O]),p.useEffect(()=>{!r&&!y&&!t&&!O&&K({businessTripId:s})},[r,t,O,K,s,y]),!s&&!r?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((F,R)=>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}.${R}.attendeeId`,control:a,rules:{required:"Required"},render:({field:k,fieldState:re})=>e.jsx(q,{...k,disabled:l,data:u,value:k.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:re.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:a,name:`${n}.${R}.nightsCount`,render:({field:k,fieldState:re})=>e.jsx(ae,{className:"w-full",...k,min:0,label:"Nights Count",value:k.value??void 0,hideControls:!0,precision:0,error:re.error?.message,required:!0,onChange:V=>k.onChange(V&&typeof V=="number"?V:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(R),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},F.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{m({}),d(n)},children:e.jsx(ke,{className:"size-5"})})]})]})}function oe({businessTripId:i,control:n,setFetching:r}){const[t,s]=p.useState([]),[{data:a,fetching:o,error:d}]=ne({query:ge,variables:{businessTripId:i}}),{userContext:x}=p.useContext(ts);p.useEffect(()=>{a?.businessTrip?.attendees.length&&s(a.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[a,s]),p.useEffect(()=>{r(o)},[r,o]),p.useEffect(()=>{d&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const m=p.useMemo(()=>x?.context.ledgerLock,[x]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:m?{value:m,message:`Date must be after ${m}`}:void 0,pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(W,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:M(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:U,message:"Date must be im format yyyy-mm-dd"},min:m?{value:m,message:`Date must be after ${m}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(W,{...h,onChange:c=>{const u=c?typeof c=="string"?c:M(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(q,{...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 Ee(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function yt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripAccommodationsExpense:m,fetching:h}=bt(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Accommodation Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{control:a,name:"country",render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Country"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),e.jsx(z,{name:"nightsCount",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Nights Count"}),e.jsx($,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(_,{})]})}),e.jsx(Ue,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:i}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Tt="updateBusinessTripAccommodationsExpense",Et=()=>{const[{fetching:i},n]=B(ns),r=p.useCallback(async t=>{const s="Error updating business trip accommodations expense",a=Tt;j.loading("Updating trip accommodations expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAccommodationsExpense:r}},Ct="categorizeIntoExistingBusinessTripExpense",At=()=>{const[{fetching:i},n]=B(rs),r=p.useCallback(async t=>{const s="Error updating business trip expense category",a=Ct;j.loading("Updating business trip expense category",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeIntoExistingBusinessTripExpense:r}};function ce(i){const{businessTripExpenseId:n,businessTripId:r,onChange:t}=i,[s,{close:a,open:o}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(G,{className:"size-5"})})}),s&&e.jsx(wt,{businessTripExpenseId:n,businessTripId:r,opened:s,close:a,onChange:t})]})}function wt({businessTripExpenseId:i,businessTripId:n,opened:r,close:t,onChange:s}){const{control:a,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:i}}),[x,m]=p.useState([]),[{data:h,fetching:l,error:c}]=ne({query:is,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:g}=At(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return p.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);m(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,O)=>y.eventDate.localeCompare(O.eventDate)))}},[h,m]),p.useEffect(()=>{c&&j.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(C,{opened:r,onClose:t,centered:!0,children:[e.jsx(C.Title,{children:"Set Transaction Category"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:a,render:({field:T,fieldState:y})=>e.jsx(q,{...T,itemComponent:Dt,data:x??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:O=>{const K=x.find(F=>F.value===O);K?.rawAmount&&d("amount",K.rawAmount),T.onChange(O)}})}),e.jsx(b,{name:"amount",control:a,render:({field:T,fieldState:y})=>e.jsx(ae,{...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"})})]})}),g&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Dt=p.forwardRef(({eventDate:i,sourceDescription:n,referenceKey:r,counterparty:t,amount:s,...a},o)=>e.jsx("div",{ref:o,...a,children:e.jsxs(te,{children:[e.jsx(te.Col,{span:4,children:i}),e.jsx(te.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(te.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(te.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(te.Col,{span:4,children:["Reference: ",r]})]})})),Bt="deleteBusinessTripExpense",St=()=>{const[{fetching:i},n]=B(as),r=p.useCallback(async t=>{const s="Error deleting business trip expense",a=`${Bt}-${t.businessTripExpenseId}`;j.loading("Deleting trip expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripExpense:r}};function de(i){const{fetching:n,deleteBusinessTripExpense:r}=St(),t=p.useCallback(()=>{r({businessTripExpenseId:i.businessTripExpenseId}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(w,{label:"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 le=({data:i,isEditMode:n=!1,control:r,businessTripId:t})=>{const s=A(os,i),[a,o]=p.useState([]),[{data:d,fetching:x,error:m}]=ne({query:ge,variables:{businessTripId:t}});p.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]),p.useEffect(()=>{m&&j.error("Error",{description:"Oops, we have an error fetching attendees"})},[m]);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:r,defaultValue:s.date,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:r,defaultValue:s.valueDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,form:`form ${s.id}`,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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&&M(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&M(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:r,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:r,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:g})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||g.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:r,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(q,{form:`form ${s.id}`,...l,data:a,value:l.value,disabled:x,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))})})]})},ue=()=>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"})]}),It=({data:i,businessTripId:n,onChange:r})=>{const t=A(cs,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:x}=o,{updateBusinessTripAccommodationsExpense:m,fetching:h}=Et(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(I,{...o,children:e.jsx(z,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(_,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(I,{...o,children:e.jsx(Ue,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(xe,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(xe.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})})]},t.id)},We=({businessTripId:i,expenses:n,onChange:r})=>{if(!n?.length)return r?e.jsx(Ee,{businessTripId:i,onAdd:r}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ds,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),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,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(It,{data:s,businessTripId:i,onChange:r},s.id)),r&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ee,{businessTripId:i,onAdd:r})})})]})]})})},Nt=({data:i,onChange:n})=>{const{accommodationExpenses:r,id:t}=A(ls,i);return e.jsx(We,{businessTripId:t,expenses:r,onChange:n})},Ft="insertBusinessTripAttendee",Mt=()=>{const[{fetching:i},n]=B(us),r=p.useCallback(async t=>{const s="Error adding attendee to business trip",a=Ft;j.loading("Adding attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,insertBusinessTripAttendee:r}};function Ce(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(zt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function zt({businessTripId:i,opened:n,close:r,onAdd:t}){const{selectableBusinesses:s,fetching:a}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:i}}),{insertBusinessTripAttendee:x,fetching:m}=Mt(),h=l=>{x({fields:l}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,children:[e.jsx(C.Title,{children:"Add Attendee"}),e.jsx(C.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(q,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:a,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:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(W,{...l,onChange:u=>{const g=u?typeof u=="string"?u:M(u,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},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"})})]})}),(m||a)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Pt="updateBusinessTripAttendee",$t=()=>{const[{fetching:i},n]=B(hs),r=p.useCallback(async t=>{const s="Error updating business trip attendee",a=Pt;j.loading("Updating trip attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripAttendee:r}},Ot="deleteBusinessTripAttendee",Rt=()=>{const[{fetching:i},n]=B(ps),r=p.useCallback(async t=>{const s="Error removing business trip attendee",a=Ot;j.loading("Removing business trip attendee",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,deleteBusinessTripAttendee:r}};function kt(i){const{fetching:n,deleteBusinessTripAttendee:r}=Rt(),t=p.useCallback(()=>{r({fields:{businessTripId:i.businessTripId,attendeeId:i.attendeeId}}).then(()=>{i.onDelete?.()})},[i,r]);return e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(w,{label:"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 Ht="addBusinessTripFlightsExpense",_t=()=>{const[{fetching:i},n]=B(xs),r=p.useCallback(async t=>{const s="Error adding business trip flight expense",a=Ht;j.loading("Adding business trip flight expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripFlightsExpense:r}};function qe({formManager:i,flightPathPath:n,flightPathData:r}){const{control:t,watch:s,trigger:a}=i,{fields:o,append:d,remove:x}=Ie({control:t,name:n}),m=s(n),h=o.map((l,c)=>({...l,...m[c]}));return r?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(z,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(_,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{x(c),a(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),a(n)},children:e.jsx(ke,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ae(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(Lt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}const Vt=Object.entries(Re).map(([i,n])=>({value:n,label:i}));function Lt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),[{data:m,fetching:h}]=ne({query:ge,variables:{businessTripId:i}}),{addBusinessTripFlightsExpense:l,fetching:c}=_t(),u=f=>{l({fields:f}).then(()=>{t?.(),r()})},g=m?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Flight Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(qe,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:a,render:({field:f,fieldState:T})=>e.jsx(q,{...f,data:Vt,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:a,render:({field:f,fieldState:T})=>e.jsx(_e,{...f,disabled:h,data:g,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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Ut="updateBusinessTripFlightsExpense",Wt=()=>{const[{fetching:i},n]=B(ms),r=p.useCallback(async t=>{const s="Error updating business trip flights expense",a=Ut;j.loading("Updating trip flights expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripFlightsExpense:r}},qt=Object.entries(Re).map(([i,n])=>({value:n,label:i})),Gt=({data:i,businessTripId:n,onChange:r,attendees:t})=>{const s=A(gs,i),[a,o]=p.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(g=>g.id)??[],path:s.path??[]}}),{control:x,handleSubmit:m}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Wt(),c=g=>{h({fields:g}).then(()=>{r?.(),o(!1)})},u=t.map(g=>({value:g.id,label:g.name}));return e.jsxs("tr",{children:[e.jsx(le,{data:s,isEditMode:a,control:x,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:m(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[a?e.jsx(qe,{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((g,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:g},f),f<s.path.length-1&&(g===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),a?e.jsx(b,{name:"flightClass",control:x,defaultValue:s.class??void 0,render:({field:g,fieldState:f})=>e.jsx(q,{form:`form ${s.id}`,"data-autofocus":!0,...g,data:qt,value:g.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:a?e.jsx(b,{name:"attendeeIds",control:x,defaultValue:s.attendees?.map(g=>g.id)??void 0,render:({field:g,fieldState:f})=>e.jsx(_e,{...g,form:`form ${s.id}`,data:u,value:g.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(xe,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(g=>e.jsx(xe.Item,{children:g.name},g.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:r&&e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:l,variant:a?"default":"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),o(f=>!f)},children:e.jsx(J,{className:"size-5"})})}),a&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:s.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:s.id,onDelete:r})]})})]},s.id)},Ge=({businessTripId:i,expenses:n,attendees:r,onChange:t})=>{if(!n?.length)return t?e.jsx(Ae,{businessTripId:i,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(a=>A(js,a));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((a,o)=>a.date&&o.date?a.date<o.date?1:-1:a.date?-1:o.date?1:0).map(a=>e.jsx(Gt,{data:a,businessTripId:i,onChange:t,attendees:r},a.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ae,{businessTripId:i,onAdd:t})})})]})]})})},Yt=({data:i,businessTripId:n,onChange:r})=>{const t=A(fs,i),[s,a]=p.useState(!1),[o,d]=p.useState(!1),{control:x,handleSubmit:m}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=$t(),c=u=>{h({fields:u}).then(()=>{r?.(),a(!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:m(c),children:e.jsx(b,{name:"arrivalDate",control:x,defaultValue:t.arrivalDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(W,{...u,onChange:f=>{const T=f?typeof f=="string"?f:M(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:g.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:x,defaultValue:t.departureDate,rules:{pattern:{value:U,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:g})=>e.jsx(W,{...u,onChange:f=>{const T=f?typeof f=="string"?f:M(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:g.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),a(g=>!g)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(kt,{businessTripId:n,attendeeId:t.id,onDelete:r}),e.jsx(Ks,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(He,{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(Ge,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(We,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},Zt=({data:i,onChange:n})=>{const{attendees:r,id:t}=A(vs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{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:[r.sort((s,a)=>s.name.toLocaleLowerCase()>a.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Yt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ce,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ce,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Kt=()=>{const[{fetching:i},n]=B(bs),r=p.useCallback(async t=>{const s="Error adding business trip car rental expense";j.loading("Adding car rental expense...",{id:pe});try{const a=await n(t),o=S(a,s,pe);if(o)return j.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(a){console.error(`${s}: ${a}`),j.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripCarRentalExpense:r}};function we(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),a()},className:"size-7.5",children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(Xt,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function Xt({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripCarRentalExpense:m,fetching:h}=Kt(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Car Rental Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(b,{name:"days",control:a,render:({field:c,fieldState:u})=>e.jsx(ae,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(z,{name:"isFuelExpense",control:a,render:({field:{value:c,...u}})=>e.jsxs(P,{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(X,{children:"Is Fuel Expense"})}),e.jsx($,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(_,{})]})}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Qt="updateBusinessTripCarRentalExpense",Jt=()=>{const[{fetching:i},n]=B(ys),r=p.useCallback(async t=>{const s="Error updating business trip car rental expense",a=Qt;j.loading("Updating trip car rental expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripCarRentalExpense:r}},en=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ts,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripCarRentalExpense:m,fetching:h}=Jt(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(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(ae,{...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(I,{...o,children:e.jsx(z,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(P,{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(X,{children:"Is Fuel Expense"})}),e.jsx($,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(nt,{}):e.jsx(st,{})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},sn=({data:i,onChange:n})=>{const{carRentalExpenses:r,id:t}=A(Es,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(en,{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})},tn=({data:i,onChange:n})=>{const{flightExpenses:r,id:t,attendees:s}=A(Cs,i);return e.jsx(Ge,{businessTripId:t,attendees:s,expenses:r,onChange:n})},nn="addBusinessTripOtherExpense",rn=()=>{const[{fetching:i},n]=B(As),r=p.useCallback(async t=>{const s='Error adding business trip "other" expense',a=nn;j.loading('Adding trip "other" expense',{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripOtherExpense:r}};function De(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(an,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function an({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripOtherExpense:m,fetching:h}=rn(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Other Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{name:"description",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Description"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),e.jsx(z,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(P,{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(X,{children:"Deductible Expense"})}),e.jsx($,{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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const on="updateBusinessTripOtherExpense",cn=()=>{const[{fetching:i},n]=B(ws),r=p.useCallback(async t=>{const s='Error updating business trip "other" expense',a=on;j.loading('Updating business trip "other" expense',{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripOtherExpense:r}},dn=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ds,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripOtherExpense:m,fetching:h}=cn(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):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(I,{...o,children:e.jsx(z,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(P,{children:e.jsx($,{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(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},ln=({data:i,onChange:n})=>{const{otherExpenses:r,id:t}=A(Bs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(dn,{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})},un="addBusinessTripTravelAndSubsistenceExpense",hn=()=>{const[{fetching:i},n]=B(Ss),r=p.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",a=un;j.loading("Adding trip travel&subsistence expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,addBusinessTripTravelAndSubsistenceExpense:r}};function Be(i){const{businessTripId:n,onAdd:r}=i,[t,{close:s,open:a}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),a()},children:e.jsx(G,{className:"size-5"})})}),t&&e.jsx(pn,{businessTripId:n,opened:t,close:s,onAdd:r})]})}function pn({businessTripId:i,opened:n,close:r,onAdd:t}){const s=N({defaultValues:{businessTripId:i}}),{control:a,handleSubmit:o}=s,[d,x]=p.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:m,fetching:h}=hn(),l=c=>{m({fields:c}).then(()=>{t?.(),r()})};return e.jsxs(C,{opened:n,onClose:r,centered:!0,lockScroll:!0,children:[e.jsx(C.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(C.Body,{children:e.jsx(I,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(oe,{businessTripId:i,control:a,setFetching:x}),e.jsx(z,{name:"expenseType",control:a,render:({field:c})=>e.jsxs(P,{children:[e.jsx(X,{children:"Expense Type"}),e.jsx($,{children:e.jsx(Q,{...c,value:c.value??void 0})}),e.jsx(_,{})]})}),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(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const xn="updateBusinessTripTravelAndSubsistenceExpense",mn=()=>{const[{fetching:i},n]=B(Is),r=p.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",a=xn;j.loading("Updating trip travel&subsistence expense",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,updateBusinessTripTravelAndSubsistenceExpense:r}},gn=({data:i,businessTripId:n,onChange:r})=>{const t=A(Ns,i),[s,a]=p.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:x}=o,{updateBusinessTripTravelAndSubsistenceExpense:m,fetching:h}=mn(),l=c=>{m({fields:c}).then(()=>{r?.(),a(!1)})};return e.jsxs("tr",{children:[e.jsx(le,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(I,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:x(l),children:s?e.jsx(z,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(P,{children:[e.jsx($,{children:e.jsx(Q,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(_,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(w,{label:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),a(u=>!u)},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(w,{label:"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(ee,{className:"size-5"})})}),e.jsx(ce,{businessTripExpenseId:t.id,businessTripId:n,onChange:r}),e.jsx(de,{businessTripExpenseId:t.id,onDelete:r})]})]},t.id)},jn=({data:i,onChange:n})=>{const{travelAndSubsistenceExpenses:r,id:t}=A(Fs,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(ue,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[r.sort((s,a)=>s.date&&a.date?s.date<a.date?1:-1:s.date?-1:a.date?1:0).map(s=>e.jsx(gn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Be,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Be,{businessTripId:t,onAdd:n})},fn=({data:i})=>{const n=A(Ms,i),r="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:r&&M(new Date(r),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",M(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},vn=({data:i})=>{const n=A(zs,i),r="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:r&&M(new Date(r),"dd/MM/yy")})})},bn=({data:i})=>{const n=A(Ps,i),{account:r}=n,t=r.type,s=r.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})]})})},yn=({data:i})=>{const n=A($s,i),r="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:r})})})},Tn=({data:i})=>{const n=A(Os,i);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 En({data:i,onChange:n,enableEdit:r}){const{id:t,counterparty:s,missingInfoSuggestions:a,id:o,sourceDescription:d}=A(Rs,i),x=!!a?.business&&r,m=x?a?.business?.name:"Missing",h=x?a?.business?.id:null,l=s?.name??m,[c,u]=p.useState(!1),{updateTransaction:g,fetching:f}=Xs(),T=p.useCallback(async V=>{await g({transactionId:o,fields:{counterpartyId:V}}),u(!0)},[o,g]),y=p.useCallback(async V=>{await T(V),n?.()},[T,n]),{selectableBusinesses:O,fetching:K}=Oe(),[F,R]=p.useState(h??null),[k,re]=p.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(ks,{options:O,value:F,onChange:R,search:k,onSearchChange:re,placeholder:"Choose or create a business",empty:k?e.jsx(Hs,{description:k,onAdd:y}):null}),e.jsx(Js,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>F&&T(F),disabled:f||K||!F,children:e.jsx(ee,{className:"size-4"})})})]})}),e.jsx(Qs,{transactionId:t,counterpartyId:s?.id??F,open:c,onOpenChange:u,onClose:n})]})}const Cn="categorizeBusinessTripExpense",An=()=>{const[{fetching:i},n]=B(_s),r=p.useCallback(async t=>{const s="Error updating business trip expense category",a=Cn;j.loading("Updating trip expense category",{id:a});try{const o=await n(t),d=S(o,s,a);if(d)return j.success("Success",{id:a,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),j.error("Error",{id:a,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:i,categorizeBusinessTripExpense:r}};function wn(i){const{businessTripId:n,transactionId:r,onChange:t,defaultAmount:s}=i,[a,{close:o,open:d}]=L(!1);return e.jsxs(e.Fragment,{children:[e.jsx(w,{label:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:x=>{x.stopPropagation(),d()},children:e.jsx(J,{className:"size-5"})})}),a&&e.jsx(Bn,{businessTripId:n,transactionId:r,opened:a,close:o,onChange:t,defaultAmount:s})]})}const Dn=Object.entries(Vs).map(([i,n])=>({value:n,label:i}));function Bn({businessTripId:i,transactionId:n,defaultAmount:r,opened:t,close:s,onChange:a}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:i,transactionId:n}}),{categorizeBusinessTripExpense:x,fetching:m}=An(),h=l=>{x({fields:l}).then(()=>{a?.(),s()})};return e.jsxs(C,{opened:t,onClose:s,centered:!0,children:[e.jsx(C.Title,{children:"Set Expense Category"}),e.jsx(C.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(q,{"data-autofocus":!0,...l,data:Dn,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:r,render:({field:l,fieldState:c})=>e.jsx(ae,{...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"})})]})}),m&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(Z,{})})]})}const Sn=({data:i,onChange:n})=>{const{uncategorizedTransactions:r,id:t}=A(Ls,i);return r?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(se,{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:r.sort((s,a)=>s.transaction.eventDate.localeCompare(a.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(vn,{data:s.transaction}),e.jsx(fn,{data:s.transaction}),e.jsx(In,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:a=>a.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(bn,{data:s.transaction}),e.jsx(yn,{data:s.transaction}),e.jsx(Tn,{data:s.transaction}),e.jsx(En,{data:s.transaction}),e.jsx("td",{children:e.jsx(wn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},In=({data:i})=>{const{transaction:n,categorizedAmount:r,errors:t}=A(Us,i),s="amount"in n?n.amount:void 0,a=s?.raw!==r.raw&&r.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(Nn,{errors:t})]}),a&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[r.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Ws(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},Nn=({errors:i})=>{const[n,{close:r,open:t}]=L(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(qs,{onMouseEnter:t,onMouseLeave:r})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:i.map((s,a)=>e.jsx(D,{size:"sm",children:s},a))})]})};function _n({tripId:i,isExtended:n=!1}){const[r,t]=p.useState(),[s,a]=p.useState([]),[{data:o},d]=ne({query:Gs,variables:{businessTripId:i}});function x(h){s.includes(h)?a(l=>l.filter(c=>c!==h)):a(l=>[...l,h])}const m=d;return p.useEffect(()=>{o?.businessTrip&&t(o.businessTrip)},[o?.businessTrip]),e.jsx(He,{shadow:"sm",radius:"md",withBorder:!0,children:r?e.jsxs(e.Fragment,{children:[e.jsx(Ys,{data:r,onChange:m}),e.jsxs(E,{className:"w-full",multiple:!0,value:s,chevron:e.jsx(G,{size:"1rem"}),styles:{chevron:{"&[data-rotate]":{transform:"rotate(45deg)"}}},children:[e.jsxs(E.Item,{value:"attendees",children:[e.jsx(E.Control,{onClick:()=>x("attendees"),children:"Attendees"}),e.jsx(E.Panel,{children:e.jsx(Zt,{data:r,onChange:m})})]}),n&&e.jsxs(E.Item,{value:"uncategorized-transactions",children:[e.jsx(E.Control,{onClick:()=>x("uncategorized-transactions"),disabled:!r.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(E.Panel,{children:e.jsx(Sn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"flights",children:[e.jsx(E.Control,{onClick:()=>x("flights"),children:"Flights"}),e.jsx(E.Panel,{children:e.jsx(tn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"accommodations",children:[e.jsx(E.Control,{onClick:()=>x("accommodations"),children:"Accommodations"}),e.jsx(E.Panel,{children:e.jsx(Nt,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"travelAndSubsistence",children:[e.jsx(E.Control,{onClick:()=>x("travelAndSubsistence"),children:"Travel & Subsistence"}),e.jsx(E.Panel,{children:e.jsx(jn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"other",children:[e.jsx(E.Control,{onClick:()=>x("other"),children:"Other"}),e.jsx(E.Panel,{children:e.jsx(ln,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"carRental",children:[e.jsx(E.Control,{onClick:()=>x("carRental"),children:"Car Rental"}),e.jsx(E.Panel,{children:e.jsx(sn,{data:r,onChange:m})})]}),e.jsxs(E.Item,{value:"summary",children:[e.jsx(E.Control,{onClick:()=>x("summary"),children:"Summary"}),e.jsx(E.Panel,{children:e.jsx(Zs,{data:r})})]})]})]}):e.jsx(Se,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{ut as C,_n as E,Hn as P};
@@ -1 +1 @@
1
- import{v as e}from"./index-qAF5sGRO.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-CHtpNrAW.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-qAF5sGRO.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-CHtpNrAW.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,4 +1,4 @@
1
- import{v as it,r as m,dd as Nc,aF as V,dh as kc,aG as ae,j as v,dg as vn,dG as It,dH as ge,dI as Ho,di as Lc,dJ as Vc,dK as nn,dL as jc,bw as Fi,D as _r,aU as zr,bx as Fc,B as ee,x as $r,al as Ur,am as Hr,y as Wo,by as Bc,aC as _c,bz as An,bA as Bi,bB as _i,w as rn,at as Go,a2 as Ko,bD as zc,g as qo,dM as $c,t as Pe,i as Yo,u as rr,dN as Uc,bU as Hc,b$ as Wc,c1 as Gc,c0 as Kc,c2 as qc,L as Xo,I as Wr,bK as Yc,bL as Xc,bM as Nn,bN as Zc,b_ as zi,bO as Jc,bP as $i,bV as Zo,bW as Jo,bY as Qo,dO as Qc,dP as eu,dQ as sn,dR as tu,z as nu,a7 as ru,V as iu,Y as su,Z as ou,_ as au,$ as lu,a1 as cu,au as uu,ab as Ui,dS as du,e as hu,a4 as fu,ag as Hi,dT as pu,dU as gu,dV as Wi,cs as mu,ay as vu,F as yu,a$ as bu,dW as Tu,dX as xu}from"./index-qAF5sGRO.js";import{u as ea}from"./use-url-query-CYeryni6.js";import{T as yn}from"./tooltip-Br1wJ5zm.js";import{A as Gi}from"./arrow-up-down-BepSQkkk.js";import{D as Su}from"./download-csv-button-CxFM5ZN1.js";import{B as wu}from"./business-extended-info-CaoOYPT8.js";import{_ as Du,a as bn,s as we,g as Gr,u as Ki,c as Kr,m as wt,d as ir,T as sr}from"./Typography-CJ6IUHKs.js";import{P as Cu}from"./pencil-CpYjq1NY.js";import{P as Eu,a as Ou}from"./panel-top-open-CVvVnpDH.js";import{F as Pu}from"./funnel-Cn1E8rCW.js";import{M as Mu}from"./MultiSelect-DRJD_QDr.js";import"./data-table-column-header-BxsKrjBX.js";import"./eye-off-CfHy9jRk.js";const Iu=[["path",{d:"m10.852 19.772-.383.924",key:"r7sl7d"}],["path",{d:"m13.148 14.228.383-.923",key:"1d5zpm"}],["path",{d:"M13.148 19.772a3 3 0 1 0-2.296-5.544l-.383-.923",key:"1ydik7"}],["path",{d:"m13.53 20.696-.382-.924a3 3 0 1 1-2.296-5.544",key:"1m1vsf"}],["path",{d:"m14.772 15.852.923-.383",key:"660p6e"}],["path",{d:"m14.772 18.148.923.383",key:"hrcpis"}],["path",{d:"M4.2 15.1a7 7 0 1 1 9.93-9.858A7 7 0 0 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.2",key:"j2q98n"}],["path",{d:"m9.228 15.852-.923-.383",key:"1p9ong"}],["path",{d:"m9.228 18.148-.923.383",key:"6558rz"}]],Ru=it("cloud-cog",Iu);const Au=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],Nu=it("cloud-upload",Au);const ku=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],ta=it("ellipsis",ku);const Lu=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Vu=it("folder-open",Lu);const ju=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Fu=it("folder-plus",ju);const Bu=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],_u=it("folder",Bu);function Gt(t){const e=m.useRef(t);return Nc(()=>{e.current=t}),m.useRef((...n)=>(0,e.current)(...n)).current}function or(t,e){return or=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},or(t,e)}function zu(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,or(t,e)}const qi=V.createContext(null);function $u(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function qr(t,e){var n=function(s){return e&&m.isValidElement(s)?e(s):s},r=Object.create(null);return t&&m.Children.map(t,function(i){return i}).forEach(function(i){r[i.key]=n(i)}),r}function Uu(t,e){t=t||{},e=e||{};function n(u){return u in e?e[u]:t[u]}var r=Object.create(null),i=[];for(var s in t)s in e?i.length&&(r[s]=i,i=[]):i.push(s);var o,a={};for(var l in e){if(r[l])for(o=0;o<r[l].length;o++){var c=r[l][o];a[r[l][o]]=n(c)}a[l]=n(l)}for(o=0;o<i.length;o++)a[i[o]]=n(i[o]);return a}function _e(t,e,n){return n[e]!=null?n[e]:t.props[e]}function Hu(t,e){return qr(t.children,function(n){return m.cloneElement(n,{onExited:e.bind(null,n),in:!0,appear:_e(n,"appear",t),enter:_e(n,"enter",t),exit:_e(n,"exit",t)})})}function Wu(t,e,n){var r=qr(t.children),i=Uu(e,r);return Object.keys(i).forEach(function(s){var o=i[s];if(m.isValidElement(o)){var a=s in e,l=s in r,c=e[s],u=m.isValidElement(c)&&!c.props.in;l&&(!a||u)?i[s]=m.cloneElement(o,{onExited:n.bind(null,o),in:!0,exit:_e(o,"exit",t),enter:_e(o,"enter",t)}):!l&&a&&!u?i[s]=m.cloneElement(o,{in:!1}):l&&a&&m.isValidElement(c)&&(i[s]=m.cloneElement(o,{onExited:n.bind(null,o),in:c.props.in,exit:_e(o,"exit",t),enter:_e(o,"enter",t)}))}}),i}var Gu=Object.values||function(t){return Object.keys(t).map(function(e){return t[e]})},Ku={component:"div",childFactory:function(e){return e}},Yr=(function(t){zu(e,t);function e(r,i){var s;s=t.call(this,r,i)||this;var o=s.handleExited.bind($u(s));return s.state={contextValue:{isMounting:!0},handleExited:o,firstRender:!0},s}var n=e.prototype;return n.componentDidMount=function(){this.mounted=!0,this.setState({contextValue:{isMounting:!1}})},n.componentWillUnmount=function(){this.mounted=!1},e.getDerivedStateFromProps=function(i,s){var o=s.children,a=s.handleExited,l=s.firstRender;return{children:l?Hu(i,a):Wu(i,o,a),firstRender:!1}},n.handleExited=function(i,s){var o=qr(this.props.children);i.key in o||(i.props.onExited&&i.props.onExited(s),this.mounted&&this.setState(function(a){var l=kc({},a.children);return delete l[i.key],{children:l}}))},n.render=function(){var i=this.props,s=i.component,o=i.childFactory,a=Du(i,["component","childFactory"]),l=this.state.contextValue,c=Gu(this.state.children).map(o);return delete a.appear,delete a.enter,delete a.exit,s===null?V.createElement(qi.Provider,{value:l},c):V.createElement(qi.Provider,{value:l},V.createElement(s,a,c))},e})(V.Component);Yr.propTypes={};Yr.defaultProps=Ku;const Yi={};function na(t,e){const n=m.useRef(Yi);return n.current===Yi&&(n.current=t(e)),n}const qu=[];function Yu(t){m.useEffect(t,qu)}class Xr{static create(){return new Xr}currentId=null;start(e,n){this.clear(),this.currentId=setTimeout(()=>{this.currentId=null,n()},e)}clear=()=>{this.currentId!==null&&(clearTimeout(this.currentId),this.currentId=null)};disposeEffect=()=>this.clear}function Xu(){const t=na(Xr.create).current;return Yu(t.disposeEffect),t}function Xi(t){try{return t.matches(":focus-visible")}catch{}return!1}class on{static create(){return new on}static use(){const e=na(on.create).current,[n,r]=m.useState(!1);return e.shouldMount=n,e.setShouldMount=r,m.useEffect(e.mountEffect,[n]),e}constructor(){this.ref={current:null},this.mounted=null,this.didMount=!1,this.shouldMount=!1,this.setShouldMount=null}mount(){return this.mounted||(this.mounted=Ju(),this.shouldMount=!0,this.setShouldMount(this.shouldMount)),this.mounted}mountEffect=()=>{this.shouldMount&&!this.didMount&&this.ref.current!==null&&(this.didMount=!0,this.mounted.resolve())};start(...e){this.mount().then(()=>this.ref.current?.start(...e))}stop(...e){this.mount().then(()=>this.ref.current?.stop(...e))}pulsate(...e){this.mount().then(()=>this.ref.current?.pulsate(...e))}}function Zu(){return on.use()}function Ju(){let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n}function Qu(t){const{className:e,classes:n,pulsate:r=!1,rippleX:i,rippleY:s,rippleSize:o,in:a,onExited:l,timeout:c}=t,[u,d]=m.useState(!1),h=ae(e,n.ripple,n.rippleVisible,r&&n.ripplePulsate),f={width:o,height:o,top:-(o/2)+s,left:-(o/2)+i},p=ae(n.child,u&&n.childLeaving,r&&n.childPulsate);return!a&&!u&&d(!0),m.useEffect(()=>{if(!a&&l!=null){const g=setTimeout(l,c);return()=>{clearTimeout(g)}}},[l,a,c]),v.jsx("span",{className:h,style:f,children:v.jsx("span",{className:p})})}const le=bn("MuiTouchRipple",["root","ripple","rippleVisible","ripplePulsate","child","childLeaving","childPulsate"]),ar=550,ed=80,td=It`
1
+ import{v as it,r as m,dd as Nc,aF as V,dh as kc,aG as ae,j as v,dg as vn,dG as It,dH as ge,dI as Ho,di as Lc,dJ as Vc,dK as nn,dL as jc,bw as Fi,D as _r,aU as zr,bx as Fc,B as ee,x as $r,al as Ur,am as Hr,y as Wo,by as Bc,aC as _c,bz as An,bA as Bi,bB as _i,w as rn,at as Go,a2 as Ko,bD as zc,g as qo,dM as $c,t as Pe,i as Yo,u as rr,dN as Uc,bU as Hc,b$ as Wc,c1 as Gc,c0 as Kc,c2 as qc,L as Xo,I as Wr,bK as Yc,bL as Xc,bM as Nn,bN as Zc,b_ as zi,bO as Jc,bP as $i,bV as Zo,bW as Jo,bY as Qo,dO as Qc,dP as eu,dQ as sn,dR as tu,z as nu,a7 as ru,V as iu,Y as su,Z as ou,_ as au,$ as lu,a1 as cu,au as uu,ab as Ui,dS as du,e as hu,a4 as fu,ag as Hi,dT as pu,dU as gu,dV as Wi,cs as mu,ay as vu,F as yu,a$ as bu,dW as Tu,dX as xu}from"./index-CHtpNrAW.js";import{u as ea}from"./use-url-query-DMunwqS4.js";import{T as yn}from"./tooltip-0-bix6mQ.js";import{A as Gi}from"./arrow-up-down-BCKzoFzo.js";import{D as Su}from"./download-csv-button-BsXK9P76.js";import{B as wu}from"./business-extended-info-NwMS1Rj6.js";import{_ as Du,a as bn,s as we,g as Gr,u as Ki,c as Kr,m as wt,d as ir,T as sr}from"./Typography-DclIL89E.js";import{P as Cu}from"./pencil-3H1z0dQ2.js";import{P as Eu,a as Ou}from"./panel-top-open-DfXV4xoB.js";import{F as Pu}from"./funnel-4UXATjU3.js";import{M as Mu}from"./MultiSelect-DY08OexD.js";import"./data-table-column-header-CT7O7uRT.js";import"./eye-off-Cc-ssiRk.js";const Iu=[["path",{d:"m10.852 19.772-.383.924",key:"r7sl7d"}],["path",{d:"m13.148 14.228.383-.923",key:"1d5zpm"}],["path",{d:"M13.148 19.772a3 3 0 1 0-2.296-5.544l-.383-.923",key:"1ydik7"}],["path",{d:"m13.53 20.696-.382-.924a3 3 0 1 1-2.296-5.544",key:"1m1vsf"}],["path",{d:"m14.772 15.852.923-.383",key:"660p6e"}],["path",{d:"m14.772 18.148.923.383",key:"hrcpis"}],["path",{d:"M4.2 15.1a7 7 0 1 1 9.93-9.858A7 7 0 0 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.2",key:"j2q98n"}],["path",{d:"m9.228 15.852-.923-.383",key:"1p9ong"}],["path",{d:"m9.228 18.148-.923.383",key:"6558rz"}]],Ru=it("cloud-cog",Iu);const Au=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],Nu=it("cloud-upload",Au);const ku=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]],ta=it("ellipsis",ku);const Lu=[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]],Vu=it("folder-open",Lu);const ju=[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],Fu=it("folder-plus",ju);const Bu=[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]],_u=it("folder",Bu);function Gt(t){const e=m.useRef(t);return Nc(()=>{e.current=t}),m.useRef((...n)=>(0,e.current)(...n)).current}function or(t,e){return or=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},or(t,e)}function zu(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,or(t,e)}const qi=V.createContext(null);function $u(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function qr(t,e){var n=function(s){return e&&m.isValidElement(s)?e(s):s},r=Object.create(null);return t&&m.Children.map(t,function(i){return i}).forEach(function(i){r[i.key]=n(i)}),r}function Uu(t,e){t=t||{},e=e||{};function n(u){return u in e?e[u]:t[u]}var r=Object.create(null),i=[];for(var s in t)s in e?i.length&&(r[s]=i,i=[]):i.push(s);var o,a={};for(var l in e){if(r[l])for(o=0;o<r[l].length;o++){var c=r[l][o];a[r[l][o]]=n(c)}a[l]=n(l)}for(o=0;o<i.length;o++)a[i[o]]=n(i[o]);return a}function _e(t,e,n){return n[e]!=null?n[e]:t.props[e]}function Hu(t,e){return qr(t.children,function(n){return m.cloneElement(n,{onExited:e.bind(null,n),in:!0,appear:_e(n,"appear",t),enter:_e(n,"enter",t),exit:_e(n,"exit",t)})})}function Wu(t,e,n){var r=qr(t.children),i=Uu(e,r);return Object.keys(i).forEach(function(s){var o=i[s];if(m.isValidElement(o)){var a=s in e,l=s in r,c=e[s],u=m.isValidElement(c)&&!c.props.in;l&&(!a||u)?i[s]=m.cloneElement(o,{onExited:n.bind(null,o),in:!0,exit:_e(o,"exit",t),enter:_e(o,"enter",t)}):!l&&a&&!u?i[s]=m.cloneElement(o,{in:!1}):l&&a&&m.isValidElement(c)&&(i[s]=m.cloneElement(o,{onExited:n.bind(null,o),in:c.props.in,exit:_e(o,"exit",t),enter:_e(o,"enter",t)}))}}),i}var Gu=Object.values||function(t){return Object.keys(t).map(function(e){return t[e]})},Ku={component:"div",childFactory:function(e){return e}},Yr=(function(t){zu(e,t);function e(r,i){var s;s=t.call(this,r,i)||this;var o=s.handleExited.bind($u(s));return s.state={contextValue:{isMounting:!0},handleExited:o,firstRender:!0},s}var n=e.prototype;return n.componentDidMount=function(){this.mounted=!0,this.setState({contextValue:{isMounting:!1}})},n.componentWillUnmount=function(){this.mounted=!1},e.getDerivedStateFromProps=function(i,s){var o=s.children,a=s.handleExited,l=s.firstRender;return{children:l?Hu(i,a):Wu(i,o,a),firstRender:!1}},n.handleExited=function(i,s){var o=qr(this.props.children);i.key in o||(i.props.onExited&&i.props.onExited(s),this.mounted&&this.setState(function(a){var l=kc({},a.children);return delete l[i.key],{children:l}}))},n.render=function(){var i=this.props,s=i.component,o=i.childFactory,a=Du(i,["component","childFactory"]),l=this.state.contextValue,c=Gu(this.state.children).map(o);return delete a.appear,delete a.enter,delete a.exit,s===null?V.createElement(qi.Provider,{value:l},c):V.createElement(qi.Provider,{value:l},V.createElement(s,a,c))},e})(V.Component);Yr.propTypes={};Yr.defaultProps=Ku;const Yi={};function na(t,e){const n=m.useRef(Yi);return n.current===Yi&&(n.current=t(e)),n}const qu=[];function Yu(t){m.useEffect(t,qu)}class Xr{static create(){return new Xr}currentId=null;start(e,n){this.clear(),this.currentId=setTimeout(()=>{this.currentId=null,n()},e)}clear=()=>{this.currentId!==null&&(clearTimeout(this.currentId),this.currentId=null)};disposeEffect=()=>this.clear}function Xu(){const t=na(Xr.create).current;return Yu(t.disposeEffect),t}function Xi(t){try{return t.matches(":focus-visible")}catch{}return!1}class on{static create(){return new on}static use(){const e=na(on.create).current,[n,r]=m.useState(!1);return e.shouldMount=n,e.setShouldMount=r,m.useEffect(e.mountEffect,[n]),e}constructor(){this.ref={current:null},this.mounted=null,this.didMount=!1,this.shouldMount=!1,this.setShouldMount=null}mount(){return this.mounted||(this.mounted=Ju(),this.shouldMount=!0,this.setShouldMount(this.shouldMount)),this.mounted}mountEffect=()=>{this.shouldMount&&!this.didMount&&this.ref.current!==null&&(this.didMount=!0,this.mounted.resolve())};start(...e){this.mount().then(()=>this.ref.current?.start(...e))}stop(...e){this.mount().then(()=>this.ref.current?.stop(...e))}pulsate(...e){this.mount().then(()=>this.ref.current?.pulsate(...e))}}function Zu(){return on.use()}function Ju(){let t,e;const n=new Promise((r,i)=>{t=r,e=i});return n.resolve=t,n.reject=e,n}function Qu(t){const{className:e,classes:n,pulsate:r=!1,rippleX:i,rippleY:s,rippleSize:o,in:a,onExited:l,timeout:c}=t,[u,d]=m.useState(!1),h=ae(e,n.ripple,n.rippleVisible,r&&n.ripplePulsate),f={width:o,height:o,top:-(o/2)+s,left:-(o/2)+i},p=ae(n.child,u&&n.childLeaving,r&&n.childPulsate);return!a&&!u&&d(!0),m.useEffect(()=>{if(!a&&l!=null){const g=setTimeout(l,c);return()=>{clearTimeout(g)}}},[l,a,c]),v.jsx("span",{className:h,style:f,children:v.jsx("span",{className:p})})}const le=bn("MuiTouchRipple",["root","ripple","rippleVisible","ripplePulsate","child","childLeaving","childPulsate"]),ar=550,ed=80,td=It`
2
2
  0% {
3
3
  transform: scale(0);
4
4
  opacity: 0.1;
@@ -1,4 +1,4 @@
1
- import{r as h,bw as D,j as e,bx as N,B as y,y as $,by as k,aC as R,V as O,bz as f,bA as S,bB as C,w as F,Y as A,Z as E,_ as z,$ as P,at as M,bD as L,bq as w,T as B,aK as j,ay as p,G as V,dD as _,d3 as v,F as G,u as q,dE as U,bX as Z,L as H,dF as J}from"./index-qAF5sGRO.js";import{u as I}from"./use-url-query-CYeryni6.js";import{P as K}from"./page-layout-7iCtDTzs.js";import{P as Q}from"./modal-D_KAAYCr.js";import{F as X}from"./funnel-Cn1E8rCW.js";import{M as T}from"./MultiSelect-DRJD_QDr.js";import{D as W}from"./download-csv-button-CxFM5ZN1.js";import{B as Y}from"./business-extended-info-CaoOYPT8.js";import{P as ee,a as te}from"./panel-top-open-CVvVnpDH.js";import{T as se}from"./Table-C5b9rbOB.js";import"./data-table-column-header-BxsKrjBX.js";import"./eye-off-CfHy9jRk.js";function re({filter:t,setFilter:s,closeModal:i}){const n=$({defaultValues:{...t}}),{control:a,handleSubmit:o}=n,{selectableBusinesses:r,fetching:u}=k(),{userContext:m}=h.useContext(R),c=l=>{l.fromDate?.trim()===""&&(l.fromDate=void 0),l.toDate?.trim()===""&&(l.toDate=void 0),s(l),i()};function d(){s({}),i()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(O,{...n,children:e.jsxs("form",{onSubmit:o(c),className:"space-y-2",children:[e.jsx(f,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:S,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(f,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:S,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(A,{name:"isShowZeroedAccounts",control:a,render:({field:l})=>e.jsxs(E,{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(z,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(P,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:l.onChange,checked:l.value===!0})}),e.jsx("span",{children:l.value?"show":"remove"})]})]})}),e.jsxs("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:"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:d,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:i,children:"Cancel"})]})]})})]})}function ae({filter:t,setFilter:s}){const[i,n]=h.useState(!1),[a,o]=h.useState(!D(t)),{get:r,set:u}=I();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){L(d,t)||(s(d),o(m(d)))}return h.useEffect(()=>{const d=D(t)?null:encodeURIComponent(JSON.stringify(t)),l=r("trialBalanceReportFilters");d!==l&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(Q,{opened:i,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(y,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(X,{size:20})})})]})}const ne=({data:t,fromDate:s,toDate:i})=>{const n=h.useCallback(async()=>{const a=oe(t),o=`trial_balance_report${s?`_${s}`:""}${i?`_${i}`:""}`;return{fileContent:a,fileName:o}},[t,s,i]);return e.jsx(W,{createFileVariables:n})},oe=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
1
+ import{r as h,bw as D,j as e,bx as N,B as y,y as $,by as k,aC as R,V as O,bz as f,bA as S,bB as C,w as F,Y as A,Z as E,_ as z,$ as P,at as M,bD as L,bq as w,T as B,aK as j,ay as p,G as V,dD as _,d3 as v,F as G,u as q,dE as U,bX as Z,L as H,dF as J}from"./index-CHtpNrAW.js";import{u as I}from"./use-url-query-DMunwqS4.js";import{P as K}from"./page-layout-Cs7LzhPs.js";import{P as Q}from"./modal-YTgF-R03.js";import{F as X}from"./funnel-4UXATjU3.js";import{M as T}from"./MultiSelect-DY08OexD.js";import{D as W}from"./download-csv-button-BsXK9P76.js";import{B as Y}from"./business-extended-info-NwMS1Rj6.js";import{P as ee,a as te}from"./panel-top-open-DfXV4xoB.js";import{T as se}from"./Table-bhKB4PFK.js";import"./data-table-column-header-CT7O7uRT.js";import"./eye-off-Cc-ssiRk.js";function re({filter:t,setFilter:s,closeModal:i}){const n=$({defaultValues:{...t}}),{control:a,handleSubmit:o}=n,{selectableBusinesses:r,fetching:u}=k(),{userContext:m}=h.useContext(R),c=l=>{l.fromDate?.trim()===""&&(l.fromDate=void 0),l.toDate?.trim()===""&&(l.toDate=void 0),s(l),i()};function d(){s({}),i()}return e.jsxs(e.Fragment,{children:[u?e.jsx("div",{children:"Loading..."}):e.jsx("div",{}),e.jsx(O,{...n,children:e.jsxs("form",{onSubmit:o(c),className:"space-y-2",children:[e.jsx(f,{name:"ownerIds",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??(m?.context.adminBusinessId?[m?.context.adminBusinessId]:void 0),disabled:u,label:"Owners",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"businessIDs",control:a,defaultValue:void 0,render:({field:l,fieldState:b})=>e.jsx(T,{...l,data:r,value:l.value??void 0,disabled:u,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:b.error?.message})}),e.jsx(f,{name:"fromDate",control:a,defaultValue:t.fromDate,rules:{required:"Required",pattern:{value:S,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"From Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(f,{name:"toDate",control:a,defaultValue:t.toDate,rules:{pattern:{value:S,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:b})=>e.jsx(C,{...l,onChange:x=>{const g=x?typeof x=="string"?x:F(x,"yyyy-MM-dd"):void 0;g!==l.value&&l.onChange(g)},value:l.value?new Date(l.value):void 0,label:"To Date",error:b.error?.message,required:!0,popoverProps:{withinPortal:!0}})}),e.jsx(A,{name:"isShowZeroedAccounts",control:a,render:({field:l})=>e.jsxs(E,{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(z,{children:"Show zeroed accounts"})}),e.jsxs("div",{className:"flex flex-row items-center gap-1",children:[e.jsx(P,{children:e.jsx(M,{defaultChecked:t.isShowZeroedAccounts??!1,onCheckedChange:l.onChange,checked:l.value===!0})}),e.jsx("span",{children:l.value?"show":"remove"})]})]})}),e.jsxs("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:"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:d,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:i,children:"Cancel"})]})]})})]})}function ae({filter:t,setFilter:s}){const[i,n]=h.useState(!1),[a,o]=h.useState(!D(t)),{get:r,set:u}=I();function m(d){return Object.entries(d??{}).filter(([b,x])=>x!==void 0&&Array.isArray(x)&&x.length>0).length>0}function c(d){L(d,t)||(s(d),o(m(d)))}return h.useEffect(()=>{const d=D(t)?null:encodeURIComponent(JSON.stringify(t)),l=r("trialBalanceReportFilters");d!==l&&u("trialBalanceReportFilters",d)},[t,r,u]),e.jsxs(e.Fragment,{children:[e.jsx(Q,{opened:i,onClose:()=>n(!1),content:e.jsx(re,{filter:t,setFilter:c,closeModal:()=>n(!1)})}),e.jsx(N,{inline:!0,size:16,disabled:!a,children:e.jsx(y,{variant:"outline",onClick:()=>n(!0),className:"p-2",children:e.jsx(X,{size:20})})})]})}const ne=({data:t,fromDate:s,toDate:i})=>{const n=h.useCallback(async()=>{const a=oe(t),o=`trial_balance_report${s?`_${s}`:""}${i?`_${i}`:""}`;return{fileContent:a,fileName:o}},[t,s,i]);return e.jsx(W,{createFileVariables:n})},oe=t=>{let s="";s+=`Sort Code,Account Name,Debit,Credit,Balance\r
2
2
  `;for(const[i,n]of Object.entries(t)){const a=ie(i,n);s+=a}return s+=`Report total:,,${Object.values(t).reduce((i,n)=>i+n.totalDebit,0)},${Object.values(t).reduce((i,n)=>i+n.totalCredit,0)},${Object.values(t).reduce((i,n)=>i+n.sum,0)}\r
3
3
  `,s};function ie(t,s){let i="";return Object.values(s.sortCodes).sort((n,a)=>n.key-a.key).map(n=>{const a=le(n);i+=a}),i+=`${t.replaceAll("0","*")},Group Total:,${s.totalDebit??""},${s.totalCredit??""},${s.sum}\r
4
4
  `,i}function le(t){let s="";s+=`${t.name}\r
@@ -1 +1 @@
1
- import{r as b,by as z,j as e,D as G,aU as W,B as g,x as _,al as J,am as Q,a2 as T,b1 as K,aJ as R,ao as A,ap as O,aq as k,ar as E,as as D,d3 as X,G as j,bm as w,go as I,gp as Z,gq as S,gr as ee,gs as M,gt as L,gu as B,gv as N,gw as p,gx as P,gy as q,dA as se,gm as re,bh as te,bi as ae,bj as v,gz as V,F as le,u as de,J as ne,K as oe,W as ce,gA as ie}from"./index-qAF5sGRO.js";import{F as Y}from"./funnel-Cn1E8rCW.js";import{B as me}from"./building-2-DoYjr9zp.js";import{E as ue}from"./eye-off-CfHy9jRk.js";import{S as xe}from"./save-C6S-RD-9.js";const C=["2020","2021","2022","2023"];function he({selectedBusiness:t,setSelectedBusiness:d,selectedYear:s,setSelectedYear:c,referenceYear:l,setReferenceYear:o}){const[n,r]=b.useState(!s||!t),{selectableBusinesses:a,fetching:i}=z(),h=b.useMemo(()=>t?a.find(f=>f.value===t)?.label??"":"",[a,t]);return e.jsxs(G,{open:n,onOpenChange:r,children:[e.jsx(W,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-4 w-4"}),"מסננים",e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded-full",children:[h," • ",s]})]})}),e.jsxs(_,{className:"sm:max-w-md",dir:"rtl",children:[e.jsx(J,{children:e.jsxs(Q,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-5 w-5"}),"מסנני דוח"]})}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"business-select",className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"בחירת עסק"]}),e.jsx(K,{onChange:x=>d(x??void 0),data:a,value:t,disabled:i,placeholder:"Scroll to see all options",triggerProps:{className:"w-full"}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"year-select",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"שנת דיווח"]}),e.jsxs(A,{value:s,onValueChange:c,children:[e.jsx(O,{id:"year-select",children:e.jsx(k,{})}),e.jsx(E,{children:C.map(x=>e.jsx(D,{value:x,children:x},x))})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"reference-year-select",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"שנת השוואה"]}),e.jsxs(A,{value:l,onValueChange:x=>o(x==="none"?void 0:x),children:[e.jsx(O,{id:"reference-year-select",children:e.jsx(k,{})}),e.jsxs(E,{children:[e.jsx(D,{value:"none",children:"ללא"},"none"),C.map(x=>e.jsx(D,{value:x,children:x},x))]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(g,{variant:"outline",onClick:()=>r(!1),children:"ביטול"}),e.jsx(g,{onClick:()=>r(!1),children:"אישור"})]})]})]})]})}const m=({label:t,value:d,code:s,referenceValue:c,showEmptyFields:l,showChange:o=!1})=>{const n=h=>l?!0:!r(h),r=h=>!h||h.trim()===""||h==="0"||h==="0.00",a=(h,x)=>{if(!x)return null;const f=U=>Number.parseFloat(U.replace(/[,\s₪]/g,""))||0,H=f(h),F=f(x);return F===0?null:(H-F)/F*100};if(!n(d))return null;const i=o?a(d,c):null;return e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-gray-200",dir:"rtl",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[t," ",s&&`(${s})`]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${r(d)?"text-gray-400":""}`,children:r(d)?"0":d}),i!==null&&e.jsxs("span",{className:`text-xs px-1 py-0.5 rounded ${i>0?"text-green-700 bg-green-100":i<0?"text-red-700 bg-red-100":"text-gray-700 bg-gray-100"}`,children:[i>0?"+":"",i.toFixed(1),"%"]})]})]})},u=({codes:t,referenceCodes:d,code:s,showEmptyFields:c})=>{const{value:l,label:o}=b.useMemo(()=>{const r=t.find(a=>a.code===s);return{value:r?.amount||0,label:r?.label||"לא זוהה קוד"}},[t,s]),n=b.useMemo(()=>d?.find(r=>r.code===s)?.amount.toString()||"",[d,s]);return e.jsx(m,{label:o,value:X(l,0),code:String(s),showChange:!0,showEmptyFields:c,referenceValue:n})},be=[{title:"מזומנים ושווי מזומנים",codes:[7110,7120,7150],sumCode:7100},{title:"ניירות ערך",codes:[7215,7225,7230,7290,7295],sumCode:7200},{title:"לקוחות",codes:[7310,7320,7330,7350,7360,7380,7390],sumCode:7300},{title:"חייבים ויתרות חובה",codes:[7410,7420,7430,7440,7450,7461,7462,7470,7490],sumCode:7400},{title:"מסים נדחים לזמן קצר",codes:[7610,7620,7690],sumCode:7600},{title:"הלוואות לזמן קצר",codes:[7711,7712,7720],sumCode:7700},{title:"מלאי",codes:[7805,7810,7815,7820,7825,7830,7840,7850,7860,7870,7890],sumCode:7800}],je=[{title:"רכוש קבוע",codes:[8010,8020,8025,8030,8040,8050,8060,8080,8090,8095,8100,8105,8110,8120,8130,8140,8150,8160,8170,8180,8190],sumCode:8e3},{title:"נכסים לא שוטפים מוחזקים למכירה",codes:[8710],sumCode:8700},{title:"הוצאות מראש לזמן ארוך",codes:[8210,8220,8290],sumCode:8200},{title:"השקעות בחברות מוחזקות כלולות ומאוחדות",codes:[8315,8325,8335,8340,8350],sumCode:8300},{title:'השקעות בחברות אחרות כולל ני"ע סחירים מוחזקים לזמן ארוך',codes:[8410,8420,8440,8450,8460,8490],sumCode:8400},{title:"מסים נדחים לזמן ארוך",codes:[8510,8520,8590],sumCode:8500},{title:"הוצאות נדחות ורכוש אחר",codes:[8610,8620,8630,8640,8690],sumCode:8600}],pe=[{title:"בנקים והלואות לזמן קצר",codes:[9110,9120,9130,9140,9151,9152,9190],sumCode:9100},{title:"ספקים ונותני שירותים",codes:[9210,9220,9230,9290],sumCode:9200},{title:"זכאים ויתרות זכות",codes:[9310,9320,9330,9340,9350,9360,9370,9410,9420,9431,9432,9435,9440,9450,9460,9470,9480,9490],sumCode:9400},{title:"עתודה למסים נדחים לזמן קצר",codes:[9510,9520,9530],sumCode:9500}],ge=[{title:"התחייבויות לזמן ארוך",codes:[9605,9610,9620,9631,9632,9640,9650,9660,9670,9690],sumCode:9600},{title:"התחייבויות בשל סיום יחסי עובד-מעביד",codes:[9710,9720,9790],sumCode:9700},{title:"עתודה למסים נדחים לזמן ארוך",codes:[9810,9820,9890],sumCode:9800}],fe=[{title:"הון עצמי",codes:[9910,9920,9930,9940,9950,9960,9980],sumCode:9900}];function Ne({data:t,referenceData:d,showEmptyFields:s=!1}){const l=j(I,t).balanceSheet||[],n=j(I,d)?.balanceSheet||[];return e.jsx(w,{value:"balanceSheet",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני המאזן"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-blue-800 border-b pb-2",children:"נכסים"}),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx("h5",{className:"font-bold",children:"רכוש שוטף"})}),be.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(u,{codes:l,code:7e3,showEmptyFields:s})}),je.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(u,{codes:l,code:8888,showEmptyFields:s})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-red-800 border-b pb-2",children:"התחייבויות והון"}),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx("h5",{className:"font-bold",children:"התחייבויות שוטפות"})}),pe.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(u,{codes:l,code:9e3,showEmptyFields:s})}),ge.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),fe.map(r=>e.jsxs("div",{className:"bg-green-50 p-4 rounded-md",children:[e.jsx("h5",{className:"font-bold mb-3",children:r.title}),e.jsx("div",{className:"space-y-2",children:r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a))})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(u,{codes:l,code:9999,showEmptyFields:s})})]})]})]})})}const ve=t=>{switch(t){case"1":return"תעשייתי";case"2":return"מסחרי";case"3":return"נותני שירותים";case"99":return"הדיווח כולל יותר מעסק אחד";default:return""}},Ce=t=>{switch(t){case S.Cash:return"מזומן";case S.Accrual:return"מצטבר";case S.DollarRegulations:return"לפי תקנות דולריות";default:return""}},ye=t=>{switch(t){case M.Shekels:return"שקלים";case M.Dollars:return"דולרים";default:return""}},Se=t=>{switch(t){case L.DoubleEntry:return"כפולה";case L.SingleEntry:return"חד-צידית";default:return""}},we=t=>{switch(t){case B.Computerized:return"ממוחשב";case B.Manual:return"ידני";default:return""}},Fe=t=>{switch(t){case N.Option_1:return"חלופה 1";case N.Option_2Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010";case N.Option_3Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010";case N.None:return"ללא חלופה";default:return""}},Te=t=>{switch(t){case p.Unqualified:return"נוסח אחיד (בלתי מסוייג)";case p.UnqualifiedWithGoingConcern:return"בנוסח אחיד עם הפניית תשומת לב להערת עסק חי";case p.UnqualifiedWithOtherEmphases:return"בנוסח אחיד עם הפניות תשומת לב אחרת";case p.Qualified:return"הסתייגות";case p.Adverse:return"שלילית";case p.Disclaimer:return"המנעות";case p.None:return"אין חוות דעת";default:return""}},y=t=>t==null?"":t?"כן":"לא";function De({data:t,businessInfo:d}){const{header:s}=j(Z,t),c=j(ee,d);return e.jsx(w,{value:"header",className:"border rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",dir:"rtl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטים מזהים"}),e.jsx(m,{label:"השם הרשום",value:c.name,showEmptyFields:!0}),e.jsx(m,{label:"תיאור העיסוק המדווח",value:s.businessDescription??"",showEmptyFields:!0}),e.jsx(m,{label:"מספר זהות",value:s.idNumber,showEmptyFields:!0}),e.jsx(m,{label:"מספר תיק",value:s.taxFileNumber,showEmptyFields:!0}),e.jsx(m,{label:'תיק מדווח למע"מ',value:s.vatFileNumber??"",showEmptyFields:!0}),e.jsx(m,{label:"מספר תיק ניכויים",value:s.withholdingTaxFileNumber??"",showEmptyFields:!0})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטי העסק"}),e.jsx(m,{value:ve(s.businessType),label:"סוג העסק המדווח",showEmptyFields:!0}),e.jsx(m,{label:"שיטת דיווח",value:Ce(s.reportingMethod),showEmptyFields:!0}),s.reportingMethod===S.DollarRegulations&&e.jsx(m,{label:"מטבע הסכומים",value:ye(s.currencyType),showEmptyFields:!0}),e.jsx(m,{label:"הסכום באלפים",value:y(s.amountsInThousands),showEmptyFields:!0}),e.jsx(m,{label:"שיטת חשבונאות",value:Se(s.accountingMethod),showEmptyFields:!0}),e.jsx(m,{label:"הנהלת חשבונות",value:we(s.accountingSystem),showEmptyFields:!0}),e.jsx(m,{label:"חייב ברישום תוכנה",value:y(!!s.softwareRegistrationNumber),showEmptyFields:!0}),s.softwareRegistrationNumber&&e.jsx(m,{label:"מספר תעודת רישום",value:s.softwareRegistrationNumber,showEmptyFields:!0}),e.jsx(m,{label:"דוח בגין שותפות",value:y(!!s.isPartnership),showEmptyFields:!0}),s.isPartnership&&e.jsxs(e.Fragment,{children:[e.jsx(m,{label:"מספר שותפים",value:s.partnershipCount?.toString()??"",showEmptyFields:!0}),e.jsx(m,{label:"חלקי ברווחי השותפות",value:`${s.partnershipProfitShare}%`,showEmptyFields:!0})]}),e.jsx(m,{label:"יישום תקני חשבונאות (IFRS)",value:y(!!s.ifrsImplementationYear||!!s.ifrsReportingOption),showEmptyFields:!0}),(!!s.ifrsImplementationYear||!!s.ifrsReportingOption)&&e.jsxs(e.Fragment,{children:[e.jsx(m,{label:"החל משנת המס",value:s.ifrsImplementationYear??"",showEmptyFields:!0}),e.jsx(m,{label:"דווח בחלופה",value:Fe(s.ifrsReportingOption),showEmptyFields:!0})]}),e.jsx(m,{label:"מספר ענף כלכלי של המדווח",value:s.industryCode,showEmptyFields:!0}),e.jsx(m,{label:"חוות דעת המבקר",value:Te(s.auditOpinionType),showEmptyFields:!0})]})]})})}const Re=[{title:"הכנסות ממכירות ומתן שירותים",color:"text-blue-700",codes:[1010,1015,1020,1025,1030,1040,1051,1052,1090],sumCode:1e3},{title:"עלות המכירות ומתן השירותים וביצוע עבודות",color:"text-purple-700",codes:[1306,1308,1307,1310,1320,1330,1340,1350,1360,1371,1372,1390,1400,1450],sumCode:1300},{title:"עלויות ייצור ועלויות אצל קבלן בונה",color:"text-rose-700",codes:[2005,2006,2011,2012,2015,2020,2025,2030,2035,2040,2045,2050,2060,2066,2067,2068,2070,2075,2080,2085,2090,2095],sumCode:2e3},{title:"הוצאות מחקר ופיתוח",color:"text-amber-700",codes:[2510,2520,2530,2540,2550,2560,2570,2590],sumCode:2500},{title:"הוצאות מכירה",color:"text-green-700",codes:[3011,3013,3012,3015,3020,3025,3030,3040,3045,3050,3060,3066,3067,3068,3070,3075,3080,3085,3090,3100,3120,3190],sumCode:3e3},{title:"הוצאות הנהלה וכלליות",color:"text-cyan-700",codes:[3511,3513,3512,3515,3520,3530,3535,3540,3545,3550,3560,3566,3567,3568,3570,3575,3580,3590,3595,3600,3610,3620,3625,3631,3632,3640,3650,3660,3665,3680,3685,3690],sumCode:3500},{title:"הוצאות מימון",color:"text-indigo-700",codes:[5010,5020,5025,5030,5040,5050,5051,5090],sumCode:5e3},{title:"הכנסות מימון",color:"text-fuchsia-700",codes:[5110,5121,5122,5130,5150,5160,5190],sumCode:5100},{title:"הכנסות אחרות",color:"text-red-700",codes:[5210,5220,5230,5236,5237,5240,5250,5260,5270,5290],sumCode:5200},{title:"הוצאות אחרות",color:"text-yellow-700",codes:[5310,5320,5330,5390],sumCode:5300}],Ae=[{title:"מסים על הכנסה",color:"text-sky-700",codes:[5610,5620,5630],sumCode:5600},{title:"ייעוד הרווחים",color:"text-violet-700",codes:[5710],sumCode:5700},{title:"רווח/הפסד אקויטי",color:"text-pink-700",codes:[5810],sumCode:5800}];function Oe({selectedYear:t,referenceYear:d,data:s,referenceData:c,showEmptyFields:l=!1}){const{profitAndLoss:o}=j(P,s),r=j(P,c)?.profitAndLoss||[];return e.jsx(w,{value:"profitLoss",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני רווח והפסד"}),d&&t!==d&&e.jsxs("span",{className:"text-sm text-blue-600 bg-blue-50 px-2 py-1 rounded",children:["מציג שינויים לעומת ",d]})]}),Re.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(u,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title)),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(u,{codes:o,referenceCodes:r,code:6666,showEmptyFields:l})}),Ae.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(u,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title))]})})}const ke=[{title:"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010 בנושא IFRS",color:"red",codes:[103,104]},{title:"התאמות נדרשות לצרכי מס (הוסף/הפחת)",color:"yellow",codes:[110,120,130,135,140,150,160,170,180,181,182,183,184,190,200,300,310,320,330,350,360],sumCode:370},{title:"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010 בנושא IFRS שלא מצאו את ביטויין בהתאמות הנדרשות לצרכי מס",color:"emerald",codes:[383],sumCode:400},{title:"יישום הוראות חוקי מס נוספים",color:"sky",codes:[430,480,490],sumCode:500},{title:"נתונים נוספים",color:"violet",codes:[510,520,530,540,550,570,575,580,585,590]},{title:"בשותפות",color:"pink",codes:[600]}],$={red:{header:"text-red-700",sum:"bg-red-50 border-red-200"},yellow:{header:"text-yellow-700",sum:"bg-yellow-50 border-yellow-200"},emerald:{header:"text-emerald-700",sum:"bg-emerald-50 border-emerald-200"},sky:{header:"text-sky-700",sum:"bg-sky-50 border-sky-200"},violet:{header:"text-violet-700",sum:"bg-violet-50 border-violet-200"},pink:{header:"text-pink-700",sum:"bg-pink-50 border-pink-200"}};function Ee({data:t,referenceData:d,showEmptyFields:s=!1}){const{taxAdjustment:c}=j(q,t),o=j(q,d)?.taxAdjustment||[];return e.jsx(w,{value:"taxAdjustment",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:'נתוני דו"ח התאמה למס'}),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(u,{codes:c,referenceCodes:o,code:100,showEmptyFields:s})}),ke.map(n=>{const{header:r,sum:a}=$[n.color]||$.red;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:"font-bold mb-4 "+r,children:n.title}),e.jsx("div",{className:"space-y-2",children:n.codes.map(i=>e.jsx(u,{codes:c,referenceCodes:o,code:i,showEmptyFields:s},i))})]}),n.sumCode&&e.jsx("div",{className:"p-4 rounded-md border-2 "+a,children:e.jsx(u,{codes:c,referenceCodes:o,code:n.sumCode,showEmptyFields:s})})]},n.title)})]})})}function Ie({data:t,referenceData:d,businessInfo:s,selectedYear:c,referenceYear:l}){const o=j(V,t),n=j(V,d),[r,a]=b.useState("header"),[i,h]=b.useState(!0);return e.jsxs("div",{className:"p-4 border-gray-300",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{variant:i?"outline":"default",size:"sm",onClick:()=>h(!i),className:"flex items-center gap-2",children:[i?e.jsx(ue,{className:"h-4 w-4"}):e.jsx(se,{className:"h-4 w-4"}),i?"הסתר שדות ריקים":"הצג שדות ריקים"]}),e.jsx("span",{className:"text-sm text-gray-500",children:i?"מציג את כל השדות":"מציג רק שדות עם נתונים"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4"}),"הורד"]}),e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"שמור"]})]})]}),e.jsxs(te,{value:r,onValueChange:a,className:"w-full",children:[e.jsxs(ae,{className:"grid grid-cols-4 w-full",dir:"rtl",children:[e.jsx(v,{value:"header",children:"פרטים מזהים"}),e.jsx(v,{value:"profitLoss",children:"רווח והפסד"}),e.jsx(v,{value:"taxAdjustment",children:"התאמה למס"}),e.jsx(v,{value:"balanceSheet",children:"מאזן"})]}),e.jsx(De,{data:o,businessInfo:s}),e.jsx(Oe,{selectedYear:c,referenceYear:l,data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ee,{data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ne,{data:o,referenceData:n,showEmptyFields:i})]})]})}function $e(){const{setFiltersContext:t}=b.useContext(le),[d,s]=b.useState(void 0),[c,l]=b.useState(void 0),[o,n]=b.useState(void 0),[{data:r,fetching:a}]=de({query:ie,variables:{year:c?Number.parseInt(c,10):0,businessId:d},pause:!c||!d});return b.useEffect(()=>{t(e.jsx("div",{className:"flex flex-row gap-x-5",dir:"rtl",children:e.jsx(he,{selectedBusiness:d,setSelectedBusiness:s,selectedYear:c,setSelectedYear:l,referenceYear:o,setReferenceYear:n})}))},[t,d,c,o]),e.jsx("div",{className:"container mx-auto",dir:"rtl",children:e.jsxs(ne,{className:"border-2 border-gray-300",children:[e.jsx(oe,{className:"bg-gray-100 border-b-2 border-gray-300 flex flex-row justify-between items-center",children:e.jsxs("div",{className:"text-center w-full",children:[e.jsx("h1",{className:"text-2xl font-bold",children:'נספח לטופס הדו"ח השנתי ליחיד ולחבר בני אדם'}),e.jsxs("h2",{className:"text-xl",children:["לשנת המס ",c]}),e.jsx("p",{className:"text-sm",children:'נתוני הדוחות הכספיים, מאזן, רווח והפסד ודו"ח ההתאמה למס'})]})}),e.jsx(ce,{className:"p-0",children:e.jsx(Me,{fetching:a,data:r,selectedBusiness:d,selectedYear:c,referenceYear:o})})]})})}function Me({fetching:t,data:d,selectedBusiness:s,selectedYear:c,referenceYear:l}){if(t)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"טוען נתונים..."})});if(!c||!s)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"יש לבחור עסק ושנת דיווח"})});const o=d?.shaam6111.data;return o?e.jsx(Ie,{data:o,businessInfo:d.shaam6111.business,selectedBusiness:s,selectedYear:c,referenceYear:l}):e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"אין נתונים זמינים עבור העסק והשנה שנבחרו"})})}export{$e as Shaam6111Report};
1
+ import{r as b,by as z,j as e,D as G,aU as W,B as g,x as _,al as J,am as Q,a2 as T,b1 as K,aJ as R,ao as A,ap as O,aq as k,ar as E,as as D,d3 as X,G as j,bm as w,go as I,gp as Z,gq as S,gr as ee,gs as M,gt as L,gu as B,gv as N,gw as p,gx as P,gy as q,dA as se,gm as re,bh as te,bi as ae,bj as v,gz as V,F as le,u as de,J as ne,K as oe,W as ce,gA as ie}from"./index-CHtpNrAW.js";import{F as Y}from"./funnel-4UXATjU3.js";import{B as me}from"./building-2-Cp2Es1mt.js";import{E as ue}from"./eye-off-Cc-ssiRk.js";import{S as xe}from"./save-D2KnX2aJ.js";const C=["2020","2021","2022","2023"];function he({selectedBusiness:t,setSelectedBusiness:d,selectedYear:s,setSelectedYear:c,referenceYear:l,setReferenceYear:o}){const[n,r]=b.useState(!s||!t),{selectableBusinesses:a,fetching:i}=z(),h=b.useMemo(()=>t?a.find(f=>f.value===t)?.label??"":"",[a,t]);return e.jsxs(G,{open:n,onOpenChange:r,children:[e.jsx(W,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-4 w-4"}),"מסננים",e.jsxs("span",{className:"text-xs bg-blue-100 text-blue-800 px-2 py-0.5 rounded-full",children:[h," • ",s]})]})}),e.jsxs(_,{className:"sm:max-w-md",dir:"rtl",children:[e.jsx(J,{children:e.jsxs(Q,{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-5 w-5"}),"מסנני דוח"]})}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"business-select",className:"flex items-center gap-2",children:[e.jsx(me,{className:"h-4 w-4"}),"בחירת עסק"]}),e.jsx(K,{onChange:x=>d(x??void 0),data:a,value:t,disabled:i,placeholder:"Scroll to see all options",triggerProps:{className:"w-full"}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"year-select",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"שנת דיווח"]}),e.jsxs(A,{value:s,onValueChange:c,children:[e.jsx(O,{id:"year-select",children:e.jsx(k,{})}),e.jsx(E,{children:C.map(x=>e.jsx(D,{value:x,children:x},x))})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(T,{htmlFor:"reference-year-select",className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4"}),"שנת השוואה"]}),e.jsxs(A,{value:l,onValueChange:x=>o(x==="none"?void 0:x),children:[e.jsx(O,{id:"reference-year-select",children:e.jsx(k,{})}),e.jsxs(E,{children:[e.jsx(D,{value:"none",children:"ללא"},"none"),C.map(x=>e.jsx(D,{value:x,children:x},x))]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["זמינות נתונים: ",C.join(", ")]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(g,{variant:"outline",onClick:()=>r(!1),children:"ביטול"}),e.jsx(g,{onClick:()=>r(!1),children:"אישור"})]})]})]})]})}const m=({label:t,value:d,code:s,referenceValue:c,showEmptyFields:l,showChange:o=!1})=>{const n=h=>l?!0:!r(h),r=h=>!h||h.trim()===""||h==="0"||h==="0.00",a=(h,x)=>{if(!x)return null;const f=U=>Number.parseFloat(U.replace(/[,\s₪]/g,""))||0,H=f(h),F=f(x);return F===0?null:(H-F)/F*100};if(!n(d))return null;const i=o?a(d,c):null;return e.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-gray-200",dir:"rtl",children:[e.jsxs("span",{className:"text-sm text-gray-600",children:[t," ",s&&`(${s})`]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`font-medium ${r(d)?"text-gray-400":""}`,children:r(d)?"0":d}),i!==null&&e.jsxs("span",{className:`text-xs px-1 py-0.5 rounded ${i>0?"text-green-700 bg-green-100":i<0?"text-red-700 bg-red-100":"text-gray-700 bg-gray-100"}`,children:[i>0?"+":"",i.toFixed(1),"%"]})]})]})},u=({codes:t,referenceCodes:d,code:s,showEmptyFields:c})=>{const{value:l,label:o}=b.useMemo(()=>{const r=t.find(a=>a.code===s);return{value:r?.amount||0,label:r?.label||"לא זוהה קוד"}},[t,s]),n=b.useMemo(()=>d?.find(r=>r.code===s)?.amount.toString()||"",[d,s]);return e.jsx(m,{label:o,value:X(l,0),code:String(s),showChange:!0,showEmptyFields:c,referenceValue:n})},be=[{title:"מזומנים ושווי מזומנים",codes:[7110,7120,7150],sumCode:7100},{title:"ניירות ערך",codes:[7215,7225,7230,7290,7295],sumCode:7200},{title:"לקוחות",codes:[7310,7320,7330,7350,7360,7380,7390],sumCode:7300},{title:"חייבים ויתרות חובה",codes:[7410,7420,7430,7440,7450,7461,7462,7470,7490],sumCode:7400},{title:"מסים נדחים לזמן קצר",codes:[7610,7620,7690],sumCode:7600},{title:"הלוואות לזמן קצר",codes:[7711,7712,7720],sumCode:7700},{title:"מלאי",codes:[7805,7810,7815,7820,7825,7830,7840,7850,7860,7870,7890],sumCode:7800}],je=[{title:"רכוש קבוע",codes:[8010,8020,8025,8030,8040,8050,8060,8080,8090,8095,8100,8105,8110,8120,8130,8140,8150,8160,8170,8180,8190],sumCode:8e3},{title:"נכסים לא שוטפים מוחזקים למכירה",codes:[8710],sumCode:8700},{title:"הוצאות מראש לזמן ארוך",codes:[8210,8220,8290],sumCode:8200},{title:"השקעות בחברות מוחזקות כלולות ומאוחדות",codes:[8315,8325,8335,8340,8350],sumCode:8300},{title:'השקעות בחברות אחרות כולל ני"ע סחירים מוחזקים לזמן ארוך',codes:[8410,8420,8440,8450,8460,8490],sumCode:8400},{title:"מסים נדחים לזמן ארוך",codes:[8510,8520,8590],sumCode:8500},{title:"הוצאות נדחות ורכוש אחר",codes:[8610,8620,8630,8640,8690],sumCode:8600}],pe=[{title:"בנקים והלואות לזמן קצר",codes:[9110,9120,9130,9140,9151,9152,9190],sumCode:9100},{title:"ספקים ונותני שירותים",codes:[9210,9220,9230,9290],sumCode:9200},{title:"זכאים ויתרות זכות",codes:[9310,9320,9330,9340,9350,9360,9370,9410,9420,9431,9432,9435,9440,9450,9460,9470,9480,9490],sumCode:9400},{title:"עתודה למסים נדחים לזמן קצר",codes:[9510,9520,9530],sumCode:9500}],ge=[{title:"התחייבויות לזמן ארוך",codes:[9605,9610,9620,9631,9632,9640,9650,9660,9670,9690],sumCode:9600},{title:"התחייבויות בשל סיום יחסי עובד-מעביד",codes:[9710,9720,9790],sumCode:9700},{title:"עתודה למסים נדחים לזמן ארוך",codes:[9810,9820,9890],sumCode:9800}],fe=[{title:"הון עצמי",codes:[9910,9920,9930,9940,9950,9960,9980],sumCode:9900}];function Ne({data:t,referenceData:d,showEmptyFields:s=!1}){const l=j(I,t).balanceSheet||[],n=j(I,d)?.balanceSheet||[];return e.jsx(w,{value:"balanceSheet",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני המאזן"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-blue-800 border-b pb-2",children:"נכסים"}),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx("h5",{className:"font-bold",children:"רכוש שוטף"})}),be.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(u,{codes:l,code:7e3,showEmptyFields:s})}),je.map(r=>e.jsxs("div",{className:"bg-blue-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-blue-100 p-4 rounded-md border-2 border-blue-300",children:e.jsx(u,{codes:l,code:8888,showEmptyFields:s})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-lg font-bold text-red-800 border-b pb-2",children:"התחייבויות והון"}),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx("h5",{className:"font-bold",children:"התחייבויות שוטפות"})}),pe.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(u,{codes:l,code:9e3,showEmptyFields:s})}),ge.map(r=>e.jsxs("div",{className:"bg-red-50 p-4 rounded-md",children:[e.jsx("h6",{className:"font-bold mb-3",children:r.title}),e.jsxs("div",{className:"space-y-2",children:[r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:l,referenceCodes:n,code:r.sumCode,showEmptyFields:s})})]})]},r.title)),fe.map(r=>e.jsxs("div",{className:"bg-green-50 p-4 rounded-md",children:[e.jsx("h5",{className:"font-bold mb-3",children:r.title}),e.jsx("div",{className:"space-y-2",children:r.codes.map(a=>e.jsx(u,{codes:l,referenceCodes:n,code:a,showEmptyFields:s},a))})]},r.title)),e.jsx("div",{className:"bg-red-100 p-4 rounded-md border-2 border-red-300",children:e.jsx(u,{codes:l,code:9999,showEmptyFields:s})})]})]})]})})}const ve=t=>{switch(t){case"1":return"תעשייתי";case"2":return"מסחרי";case"3":return"נותני שירותים";case"99":return"הדיווח כולל יותר מעסק אחד";default:return""}},Ce=t=>{switch(t){case S.Cash:return"מזומן";case S.Accrual:return"מצטבר";case S.DollarRegulations:return"לפי תקנות דולריות";default:return""}},ye=t=>{switch(t){case M.Shekels:return"שקלים";case M.Dollars:return"דולרים";default:return""}},Se=t=>{switch(t){case L.DoubleEntry:return"כפולה";case L.SingleEntry:return"חד-צידית";default:return""}},we=t=>{switch(t){case B.Computerized:return"ממוחשב";case B.Manual:return"ידני";default:return""}},Fe=t=>{switch(t){case N.Option_1:return"חלופה 1";case N.Option_2Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010";case N.Option_3Adjustments:return"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010";case N.None:return"ללא חלופה";default:return""}},Te=t=>{switch(t){case p.Unqualified:return"נוסח אחיד (בלתי מסוייג)";case p.UnqualifiedWithGoingConcern:return"בנוסח אחיד עם הפניית תשומת לב להערת עסק חי";case p.UnqualifiedWithOtherEmphases:return"בנוסח אחיד עם הפניות תשומת לב אחרת";case p.Qualified:return"הסתייגות";case p.Adverse:return"שלילית";case p.Disclaimer:return"המנעות";case p.None:return"אין חוות דעת";default:return""}},y=t=>t==null?"":t?"כן":"לא";function De({data:t,businessInfo:d}){const{header:s}=j(Z,t),c=j(ee,d);return e.jsx(w,{value:"header",className:"border rounded-md p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",dir:"rtl",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטים מזהים"}),e.jsx(m,{label:"השם הרשום",value:c.name,showEmptyFields:!0}),e.jsx(m,{label:"תיאור העיסוק המדווח",value:s.businessDescription??"",showEmptyFields:!0}),e.jsx(m,{label:"מספר זהות",value:s.idNumber,showEmptyFields:!0}),e.jsx(m,{label:"מספר תיק",value:s.taxFileNumber,showEmptyFields:!0}),e.jsx(m,{label:'תיק מדווח למע"מ',value:s.vatFileNumber??"",showEmptyFields:!0}),e.jsx(m,{label:"מספר תיק ניכויים",value:s.withholdingTaxFileNumber??"",showEmptyFields:!0})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"פרטי העסק"}),e.jsx(m,{value:ve(s.businessType),label:"סוג העסק המדווח",showEmptyFields:!0}),e.jsx(m,{label:"שיטת דיווח",value:Ce(s.reportingMethod),showEmptyFields:!0}),s.reportingMethod===S.DollarRegulations&&e.jsx(m,{label:"מטבע הסכומים",value:ye(s.currencyType),showEmptyFields:!0}),e.jsx(m,{label:"הסכום באלפים",value:y(s.amountsInThousands),showEmptyFields:!0}),e.jsx(m,{label:"שיטת חשבונאות",value:Se(s.accountingMethod),showEmptyFields:!0}),e.jsx(m,{label:"הנהלת חשבונות",value:we(s.accountingSystem),showEmptyFields:!0}),e.jsx(m,{label:"חייב ברישום תוכנה",value:y(!!s.softwareRegistrationNumber),showEmptyFields:!0}),s.softwareRegistrationNumber&&e.jsx(m,{label:"מספר תעודת רישום",value:s.softwareRegistrationNumber,showEmptyFields:!0}),e.jsx(m,{label:"דוח בגין שותפות",value:y(!!s.isPartnership),showEmptyFields:!0}),s.isPartnership&&e.jsxs(e.Fragment,{children:[e.jsx(m,{label:"מספר שותפים",value:s.partnershipCount?.toString()??"",showEmptyFields:!0}),e.jsx(m,{label:"חלקי ברווחי השותפות",value:`${s.partnershipProfitShare}%`,showEmptyFields:!0})]}),e.jsx(m,{label:"יישום תקני חשבונאות (IFRS)",value:y(!!s.ifrsImplementationYear||!!s.ifrsReportingOption),showEmptyFields:!0}),(!!s.ifrsImplementationYear||!!s.ifrsReportingOption)&&e.jsxs(e.Fragment,{children:[e.jsx(m,{label:"החל משנת המס",value:s.ifrsImplementationYear??"",showEmptyFields:!0}),e.jsx(m,{label:"דווח בחלופה",value:Fe(s.ifrsReportingOption),showEmptyFields:!0})]}),e.jsx(m,{label:"מספר ענף כלכלי של המדווח",value:s.industryCode,showEmptyFields:!0}),e.jsx(m,{label:"חוות דעת המבקר",value:Te(s.auditOpinionType),showEmptyFields:!0})]})]})})}const Re=[{title:"הכנסות ממכירות ומתן שירותים",color:"text-blue-700",codes:[1010,1015,1020,1025,1030,1040,1051,1052,1090],sumCode:1e3},{title:"עלות המכירות ומתן השירותים וביצוע עבודות",color:"text-purple-700",codes:[1306,1308,1307,1310,1320,1330,1340,1350,1360,1371,1372,1390,1400,1450],sumCode:1300},{title:"עלויות ייצור ועלויות אצל קבלן בונה",color:"text-rose-700",codes:[2005,2006,2011,2012,2015,2020,2025,2030,2035,2040,2045,2050,2060,2066,2067,2068,2070,2075,2080,2085,2090,2095],sumCode:2e3},{title:"הוצאות מחקר ופיתוח",color:"text-amber-700",codes:[2510,2520,2530,2540,2550,2560,2570,2590],sumCode:2500},{title:"הוצאות מכירה",color:"text-green-700",codes:[3011,3013,3012,3015,3020,3025,3030,3040,3045,3050,3060,3066,3067,3068,3070,3075,3080,3085,3090,3100,3120,3190],sumCode:3e3},{title:"הוצאות הנהלה וכלליות",color:"text-cyan-700",codes:[3511,3513,3512,3515,3520,3530,3535,3540,3545,3550,3560,3566,3567,3568,3570,3575,3580,3590,3595,3600,3610,3620,3625,3631,3632,3640,3650,3660,3665,3680,3685,3690],sumCode:3500},{title:"הוצאות מימון",color:"text-indigo-700",codes:[5010,5020,5025,5030,5040,5050,5051,5090],sumCode:5e3},{title:"הכנסות מימון",color:"text-fuchsia-700",codes:[5110,5121,5122,5130,5150,5160,5190],sumCode:5100},{title:"הכנסות אחרות",color:"text-red-700",codes:[5210,5220,5230,5236,5237,5240,5250,5260,5270,5290],sumCode:5200},{title:"הוצאות אחרות",color:"text-yellow-700",codes:[5310,5320,5330,5390],sumCode:5300}],Ae=[{title:"מסים על הכנסה",color:"text-sky-700",codes:[5610,5620,5630],sumCode:5600},{title:"ייעוד הרווחים",color:"text-violet-700",codes:[5710],sumCode:5700},{title:"רווח/הפסד אקויטי",color:"text-pink-700",codes:[5810],sumCode:5800}];function Oe({selectedYear:t,referenceYear:d,data:s,referenceData:c,showEmptyFields:l=!1}){const{profitAndLoss:o}=j(P,s),r=j(P,c)?.profitAndLoss||[];return e.jsx(w,{value:"profitLoss",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:"נתוני רווח והפסד"}),d&&t!==d&&e.jsxs("span",{className:"text-sm text-blue-600 bg-blue-50 px-2 py-1 rounded",children:["מציג שינויים לעומת ",d]})]}),Re.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(u,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title)),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(u,{codes:o,referenceCodes:r,code:6666,showEmptyFields:l})}),Ae.map(a=>e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:`font-bold mb-4 ${a.color}`,children:a.title}),e.jsxs("div",{className:"space-y-2",children:[a.codes.map(i=>e.jsx(u,{codes:o,referenceCodes:r,code:i,showEmptyFields:l},i)),e.jsx("div",{className:"border-2 rounded-md border-gray-300",children:e.jsx(u,{codes:o,referenceCodes:r,code:a.sumCode,showEmptyFields:l})})]})]},a.title))]})})}const ke=[{title:"התאמות חשבונאיות למי שיישם את חלופה 2 בהוראת ביצוע 7/2010 בנושא IFRS",color:"red",codes:[103,104]},{title:"התאמות נדרשות לצרכי מס (הוסף/הפחת)",color:"yellow",codes:[110,120,130,135,140,150,160,170,180,181,182,183,184,190,200,300,310,320,330,350,360],sumCode:370},{title:"התאמות חשבונאיות למי שיישם את חלופה 3 בהוראת ביצוע 7/2010 בנושא IFRS שלא מצאו את ביטויין בהתאמות הנדרשות לצרכי מס",color:"emerald",codes:[383],sumCode:400},{title:"יישום הוראות חוקי מס נוספים",color:"sky",codes:[430,480,490],sumCode:500},{title:"נתונים נוספים",color:"violet",codes:[510,520,530,540,550,570,575,580,585,590]},{title:"בשותפות",color:"pink",codes:[600]}],$={red:{header:"text-red-700",sum:"bg-red-50 border-red-200"},yellow:{header:"text-yellow-700",sum:"bg-yellow-50 border-yellow-200"},emerald:{header:"text-emerald-700",sum:"bg-emerald-50 border-emerald-200"},sky:{header:"text-sky-700",sum:"bg-sky-50 border-sky-200"},violet:{header:"text-violet-700",sum:"bg-violet-50 border-violet-200"},pink:{header:"text-pink-700",sum:"bg-pink-50 border-pink-200"}};function Ee({data:t,referenceData:d,showEmptyFields:s=!1}){const{taxAdjustment:c}=j(q,t),o=j(q,d)?.taxAdjustment||[];return e.jsx(w,{value:"taxAdjustment",className:"border rounded-md p-4",children:e.jsxs("div",{className:"space-y-6",dir:"rtl",children:[e.jsx("h3",{className:"text-lg font-bold border-b pb-2",children:'נתוני דו"ח התאמה למס'}),e.jsx("div",{className:"bg-emerald-50 p-4 rounded-md border-2 border-emerald-200",children:e.jsx(u,{codes:c,referenceCodes:o,code:100,showEmptyFields:s})}),ke.map(n=>{const{header:r,sum:a}=$[n.color]||$.red;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsx("h4",{className:"font-bold mb-4 "+r,children:n.title}),e.jsx("div",{className:"space-y-2",children:n.codes.map(i=>e.jsx(u,{codes:c,referenceCodes:o,code:i,showEmptyFields:s},i))})]}),n.sumCode&&e.jsx("div",{className:"p-4 rounded-md border-2 "+a,children:e.jsx(u,{codes:c,referenceCodes:o,code:n.sumCode,showEmptyFields:s})})]},n.title)})]})})}function Ie({data:t,referenceData:d,businessInfo:s,selectedYear:c,referenceYear:l}){const o=j(V,t),n=j(V,d),[r,a]=b.useState("header"),[i,h]=b.useState(!0);return e.jsxs("div",{className:"p-4 border-gray-300",dir:"rtl",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(g,{variant:i?"outline":"default",size:"sm",onClick:()=>h(!i),className:"flex items-center gap-2",children:[i?e.jsx(ue,{className:"h-4 w-4"}):e.jsx(se,{className:"h-4 w-4"}),i?"הסתר שדות ריקים":"הצג שדות ריקים"]}),e.jsx("span",{className:"text-sm text-gray-500",children:i?"מציג את כל השדות":"מציג רק שדות עם נתונים"})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4"}),"הורד"]}),e.jsxs(g,{variant:"outline",className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"שמור"]})]})]}),e.jsxs(te,{value:r,onValueChange:a,className:"w-full",children:[e.jsxs(ae,{className:"grid grid-cols-4 w-full",dir:"rtl",children:[e.jsx(v,{value:"header",children:"פרטים מזהים"}),e.jsx(v,{value:"profitLoss",children:"רווח והפסד"}),e.jsx(v,{value:"taxAdjustment",children:"התאמה למס"}),e.jsx(v,{value:"balanceSheet",children:"מאזן"})]}),e.jsx(De,{data:o,businessInfo:s}),e.jsx(Oe,{selectedYear:c,referenceYear:l,data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ee,{data:o,referenceData:n,showEmptyFields:i}),e.jsx(Ne,{data:o,referenceData:n,showEmptyFields:i})]})]})}function $e(){const{setFiltersContext:t}=b.useContext(le),[d,s]=b.useState(void 0),[c,l]=b.useState(void 0),[o,n]=b.useState(void 0),[{data:r,fetching:a}]=de({query:ie,variables:{year:c?Number.parseInt(c,10):0,businessId:d},pause:!c||!d});return b.useEffect(()=>{t(e.jsx("div",{className:"flex flex-row gap-x-5",dir:"rtl",children:e.jsx(he,{selectedBusiness:d,setSelectedBusiness:s,selectedYear:c,setSelectedYear:l,referenceYear:o,setReferenceYear:n})}))},[t,d,c,o]),e.jsx("div",{className:"container mx-auto",dir:"rtl",children:e.jsxs(ne,{className:"border-2 border-gray-300",children:[e.jsx(oe,{className:"bg-gray-100 border-b-2 border-gray-300 flex flex-row justify-between items-center",children:e.jsxs("div",{className:"text-center w-full",children:[e.jsx("h1",{className:"text-2xl font-bold",children:'נספח לטופס הדו"ח השנתי ליחיד ולחבר בני אדם'}),e.jsxs("h2",{className:"text-xl",children:["לשנת המס ",c]}),e.jsx("p",{className:"text-sm",children:'נתוני הדוחות הכספיים, מאזן, רווח והפסד ודו"ח ההתאמה למס'})]})}),e.jsx(ce,{className:"p-0",children:e.jsx(Me,{fetching:a,data:r,selectedBusiness:d,selectedYear:c,referenceYear:o})})]})})}function Me({fetching:t,data:d,selectedBusiness:s,selectedYear:c,referenceYear:l}){if(t)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"טוען נתונים..."})});if(!c||!s)return e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"יש לבחור עסק ושנת דיווח"})});const o=d?.shaam6111.data;return o?e.jsx(Ie,{data:o,businessInfo:d.shaam6111.business,selectedBusiness:s,selectedYear:c,referenceYear:l}):e.jsx("div",{className:"container mx-auto p-8 text-center",dir:"rtl",children:e.jsx("p",{className:"text-lg text-gray-600",children:"אין נתונים זמינים עבור העסק והשנה שנבחרו"})})}export{$e as Shaam6111Report};