@accounter/client 0.0.11-alpha-20260125180828-ba6265251b2d2e84e3355b96352f5bf83918317f → 0.0.11-alpha-20260126094406-5e339d8e89f94400c777170c689d55bd9dd5f95c
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.
- package/CHANGELOG.md +1 -1
- package/dist/assets/{Checkbox-DWmOT4mx.js → Checkbox-Dmuz3t7B.js} +1 -1
- package/dist/assets/{MultiSelect-DhEZHYxn.js → MultiSelect-DBeIExB5.js} +1 -1
- package/dist/assets/{Progress-DE13gAJ5.js → Progress---sZILQb.js} +1 -1
- package/dist/assets/{Table-rNmO5bBI.js → Table-BQv3frL8.js} +1 -1
- package/dist/assets/{Typography-C1pdNNG8.js → Typography-B8Kph7eR.js} +1 -1
- package/dist/assets/accordion-Bn08_4fN.js +1 -0
- package/dist/assets/{accountant-approvals-DXUA4Z8R.js → accountant-approvals-DuNl7y6H.js} +1 -1
- package/dist/assets/{accounter-table-CGncq_73.js → accounter-table-DTsgtq5M.js} +1 -1
- package/dist/assets/{addDays-DpkzPtfc.js → addDays-DTiBTTns.js} +1 -1
- package/dist/assets/{all-charges-CAf5Sz2_.js → all-charges-DPyM-a74.js} +1 -1
- package/dist/assets/{arrow-up-down-MrfN0fhR.js → arrow-up-down-VY6mkkTR.js} +1 -1
- package/dist/assets/{building-2-CWrl-iq9.js → building-2-CMKd_bU8.js} +1 -1
- package/dist/assets/{business-CnobDfUp.js → business-BVMKhHFx.js} +1 -1
- package/dist/assets/{business-extended-info-6Ykvm7VT.js → business-extended-info-B94y5ZK6.js} +1 -1
- package/dist/assets/business-header-BC86M-9m.js +1 -0
- package/dist/assets/{business-ledger-filters-Bi9mwcxM.js → business-ledger-filters-es3H4rPK.js} +1 -1
- package/dist/assets/{business-ledger-single-SwmnJ5M-.js → business-ledger-single-U3zkqgW2.js} +1 -1
- package/dist/assets/business-trip-BUKYnQkG.js +1 -0
- package/dist/assets/charge-DuqIMfNm.js +1 -0
- package/dist/assets/charges-filters-CFCAP-bP.js +1 -0
- package/dist/assets/{charges-ledger-validation-ClbJGvF9.js → charges-ledger-validation-CCTNRpCE.js} +1 -1
- package/dist/assets/{charges-table-zGkVW5or.js → charges-table-BJtpvXfL.js} +3 -3
- package/dist/assets/contracts-ljjcB_x7.js +1 -0
- package/dist/assets/{data-table-column-header-DDRUwuwC.js → data-table-column-header-CZ1dXiU0.js} +1 -1
- package/dist/assets/{data-table-pagination-DxOcd13P.js → data-table-pagination-XAlQIbO9.js} +1 -1
- package/dist/assets/deposits-transactions-table-2rtRFZgK.js +1 -0
- package/dist/assets/{download-csv-BmamqJJW.js → download-csv-BSGaUZsM.js} +1 -1
- package/dist/assets/{download-csv-button-BFfxSTjQ.js → download-csv-button-CMQBUQeX.js} +1 -1
- package/dist/assets/{editable-business-trip-CPfdEl45.js → editable-business-trip-CED1Su3d.js} +1 -1
- package/dist/assets/{eye-off-DtXkBVx1.js → eye-off-Buv7eciz.js} +1 -1
- package/dist/assets/{funnel-B1ZA9LM9.js → funnel-Cfb9Pxmr.js} +1 -1
- package/dist/assets/index-3ev2Q3E9.js +1 -0
- package/dist/assets/{index-Cs7XgdTM.js → index-7gCTV42h.js} +2 -2
- package/dist/assets/{index-Bsnch-zI.js → index-8fdLByFg.js} +1 -1
- package/dist/assets/index-B0hZ0TDG.js +1 -0
- package/dist/assets/{index-DCmEMj8e.js → index-B4OP8iL7.js} +3 -3
- package/dist/assets/{index-DKmgIoB5.js → index-BN-I0GSO.js} +2 -2
- package/dist/assets/index-BhFsGqUx.js +1 -0
- package/dist/assets/{index-Chao5nQb.js → index-Bui9zV-z.js} +1 -1
- package/dist/assets/{index-ciP7vurq.js → index-C7p19nIa.js} +1 -1
- package/dist/assets/{index-DwGxsIkH.js → index-CPMJQkvw.js} +1 -1
- package/dist/assets/{index-BBOAkvDK.js → index-CSdQtH7c.js} +1 -1
- package/dist/assets/index-CcZll7L2.js +1 -0
- package/dist/assets/index-CjG9JDZB.js +2 -0
- package/dist/assets/{index-DqoPYGJE.js → index-DGAT1KYx.js} +1 -1
- package/dist/assets/index-DIrLsKod.js +1 -0
- package/dist/assets/{index-DfBrqs5_.js → index-DJY6AKiM.js} +2 -2
- package/dist/assets/{index-Bv5ZyMGd.js → index-DOy0Yf1i.js} +1 -1
- package/dist/assets/{index-CywvUChw.js → index-DRBzHdu9.js} +1 -1
- package/dist/assets/index-Dal_ULkA.js +1 -0
- package/dist/assets/{index-DJQjDgkB.js → index-DokXNUuN.js} +1 -1
- package/dist/assets/{index-DjsqV-Fn.js → index-Dq33WQoi.js} +1 -1
- package/dist/assets/{index-C60AFYOu.js → index-DzzUoyj4.js} +1 -1
- package/dist/assets/{index-Vxd58TOQ.js → index-GlUqZUgQ.js} +1 -1
- package/dist/assets/index-X3RoQQa9.js +1 -0
- package/dist/assets/index-X9rrwleE.js +1 -0
- package/dist/assets/{index-DRqooPz9.js → index-rI994S3C.js} +4 -4
- package/dist/assets/{index.es-C6H8Q1nD.js → index.es-C2YDJ0AL.js} +1 -1
- package/dist/assets/issue-document-zNxGzRkY.js +1 -0
- package/dist/assets/login-page-BimTSmTC.js +1 -0
- package/dist/assets/{missing-info-charges-Dr8TvB2G.js → missing-info-charges-CVhY60ZL.js} +1 -1
- package/dist/assets/{modal-CPrQ9jQu.js → modal-BXR_xgUm.js} +1 -1
- package/dist/assets/modify-contract-dialog-flMl2p_T.js +1 -0
- package/dist/assets/{page-layout-Dp9Tr43G.js → page-layout-DMGj5xhW.js} +1 -1
- package/dist/assets/{page-not-found-BIERJkiT.js → page-not-found-B_GB5ntj.js} +1 -1
- package/dist/assets/{panel-top-open-lnF5tdL1.js → panel-top-open-Bf39HBrp.js} +1 -1
- package/dist/assets/report-commentary-row-BMyeQR9J.js +1 -0
- package/dist/assets/{save-BaXyzRSW.js → save-jkuyCWyY.js} +1 -1
- package/dist/assets/{similar-transactions-modal-DilkLkpx.js → similar-transactions-modal-DX3CPrMo.js} +1 -1
- package/dist/assets/{sub-764RJPt0.js → sub-CEXBz_OW.js} +1 -1
- package/dist/assets/subMonths-DY4HlBVa.js +1 -0
- package/dist/assets/summary-CPKS_69D.js +1 -0
- package/dist/assets/{toggle-expansion-button-BquTpOYj.js → toggle-expansion-button-Y2eS7nqg.js} +1 -1
- package/dist/assets/{update-accountant-status-Btcm95Uc.js → update-accountant-status-zL6vnwU9.js} +1 -1
- package/dist/assets/use-issue-monthly-documents-D9vQpbaZ.js +1 -0
- package/dist/assets/{use-url-query-A8PE3FMA.js → use-url-query-CqWra6gD.js} +1 -1
- package/dist/index.html +1 -1
- package/package.json +1 -1
- package/dist/assets/accordion-Air1oXnF.js +0 -1
- package/dist/assets/business-header-CAJaQahQ.js +0 -1
- package/dist/assets/business-trip-ADSYpFTM.js +0 -1
- package/dist/assets/charge-CLyQ-8f8.js +0 -1
- package/dist/assets/charges-filters-CYR6-jcu.js +0 -1
- package/dist/assets/contracts-DCd159UE.js +0 -1
- package/dist/assets/deposits-transactions-table-Dhm74qLm.js +0 -1
- package/dist/assets/index-5Ht40D_c.js +0 -1
- package/dist/assets/index-BL8siR4m.js +0 -1
- package/dist/assets/index-C0Bd8nM_.js +0 -1
- package/dist/assets/index-CFLkhm3K.js +0 -1
- package/dist/assets/index-CXZphjyK.js +0 -1
- package/dist/assets/index-Cd9YArsS.js +0 -1
- package/dist/assets/index-DynC0Vxq.js +0 -1
- package/dist/assets/index-cd89pXq_.js +0 -1
- package/dist/assets/index-d-FcvOUD.js +0 -2
- package/dist/assets/issue-document-B8SLRY9w.js +0 -1
- package/dist/assets/login-page-DF0c_Pay.js +0 -1
- package/dist/assets/modify-contract-dialog-BMTCgQ3i.js +0 -1
- package/dist/assets/report-commentary-row-BsA3JSzG.js +0 -1
- package/dist/assets/subMonths-CZ2djAnO.js +0 -1
- package/dist/assets/summary-BvHHpnIR.js +0 -1
- package/dist/assets/use-issue-monthly-documents-Dx6_0gyN.js +0 -1
package/dist/assets/{editable-business-trip-CPfdEl45.js → editable-business-trip-CED1Su3d.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as ve,cj as We,ck as qe,r as x,j as e,B as v,L as Be,g as w,cl as Ge,t as m,i as B,J as Se,u as ie,cm as ge,bE as b,bH as Z,cn as oe,co as Ne,cp as Ie,aC as Ze,bF as q,bG as G,w as F,ay as Fe,cq as Me,l as V,T as C,a4 as Q,E as N,n as E,W as S,Z as M,_ as z,$ as J,a0 as P,I as ee,a2 as H,b7 as ze,cr as Y,d as K,cs as Ye,ct as Ke,cu as Xe,bv as D,cv as Je,bX as Pe,cw as $e,H as A,ah as be,R as ye,cx as Qe,ag as se,e as te,cy as es,cz as ss,cA as ts,cB as ns,bD as Oe,cC as rs,cD as is,cE as as,cF as Re,cG as os,cH as cs,cI as ds,cJ as ls,cK as us,cL as hs,at as je,cM as xs,cN as ps,cO as ms,cP as gs,cQ as js,cR as fs,cS as vs,cT as bs,cU as ys,cV as Ts,cW as Es,cX as Cs,cY as As,cZ as Ds,c_ as ws,c$ as Bs,d0 as Ss,d1 as Ns,d2 as Is,q as Fs,d3 as Ms,d4 as zs,d5 as Ps,d6 as $s,d7 as Os,d8 as fe,d9 as Rs,da as ks}from"./index-DRqooPz9.js";import{G as re,L as me,C as ke,R as Hs,S as Us}from"./summary-BvHHpnIR.js";import{T as ne}from"./Table-rNmO5bBI.js";import{T as Vs}from"./toggle-expansion-button-BquTpOYj.js";import{M as He}from"./MultiSelect-DhEZHYxn.js";import{a as Ls,u as _s,S as Ws}from"./similar-transactions-modal-DilkLkpx.js";import{A as qs,a as L,b as _,c as W}from"./accordion-Air1oXnF.js";const Gs=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],Zs=ve("car",Gs);const Ys=[["path",{d:"M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5",key:"1wtuz0"}],["path",{d:"M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16",key:"e09ifn"}],["path",{d:"M2 21h13",key:"1x0fut"}],["path",{d:"M3 9h11",key:"1p7c0w"}]],Ks=ve("fuel",Ys);const Xs=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],Js=ve("printer",Xs);var k=3.77952755906,xe={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},Qs=class{pdf;canvas;options;constructor(a,n){this.canvas=a,this.options=n,this.pdf=new qe({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(a)}getMarginLeftMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(a)}getMarginRightMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(a)}getMarginBottomMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(a)}getMarginTop(){return this.getMarginTopMM()*k}getMarginBottom(){return this.getMarginBottomMM()*k}getMarginLeft(){return this.getMarginLeftMM()*k}getMarginRight(){return this.getMarginRightMM()*k}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*k}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*k}getOriginalCanvasWidth(){return this.canvas.width/this.getScale()}getOriginalCanvasHeight(){return this.canvas.height/this.getScale()}getCanvasPageAvailableHeight(){return this.getPageAvailableHeight()*this.getScale()*this.getHorizontalFitFactor()}getPageAvailableWidth(){return this.getPageWidth()-(this.getMarginLeft()+this.getMarginRight())}getPageAvailableHeight(){return this.getPageHeight()-(this.getMarginTop()+this.getMarginBottom())}getPageAvailableWidthMM(){return this.getPageAvailableWidth()/k}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/k}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(a){return this.getCanvasPageAvailableHeight()*(a-1)}getCanvasHeightLeft(a){return this.canvas.height-this.getCanvasOffsetY(a)}getCanvasPageHeight(a){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(a);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(a){const n=this.getCanvasPageWidth(),i=this.getCanvasPageHeight(a),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(i)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(a),this.canvas.width,i,0,0,this.canvas.width,i),t}convert(){let a=1;const n=this.getNumberPages();for(;a<=n;){a>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const i=this.createCanvasPage(a),t=i.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(a),this.pdf.addImage({imageData:t,width:i.width/(this.getScale()*k*this.getHorizontalFitFactor()),height:i.height/(this.getScale()*k*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),a+=1}return this.pdf}},et=a=>a?{...xe,...a,canvas:{...xe.canvas,...a.canvas},page:{...xe.page,...a.page}}:xe,st=a=>typeof a=="function"?a():a?.current,tt=async(a,n)=>{const i=et(n),t=st(a);if(!t){console.error("Unable to get the target element.");return}const s=await We(t,{useCORS:i.canvas.useCORS,logging:i.canvas.logging,scale:i.resolution,...i.overrides?.canvas}),o=new Qs(s,i).convert();switch(i.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;default:{const d=i.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},nt=tt;const rt={method:"open",overrides:{pdf:{compress:!0}}},it=()=>document.getElementById("main-page"),Dn=({filename:a})=>{const[n,i]=x.useState(!1),t=async()=>{i(!0),await nt(it,{...rt,filename:a}),i(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(Js,{className:"size-5"})})},at="addBusinessTripAccommodationsExpense",ot=()=>{const[{fetching:a},n]=w(Ge),i=x.useCallback(async t=>{const s="Error adding business trip accommodations expense",r=at;m.loading("Adding Business Trip Accommodations Expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripAccommodationsExpense:i}};function Ue({formManager:a,attendeesStayPath:n,attendeesData:i,fetchingAttendees:t=!1,businessTripId:s}){const{control:r,watch:o,trigger:d}=a,{fields:g,append:j,remove:h}=Se({control:r,name:n}),[l,c]=x.useState(t),[u,p]=x.useState(i??[]),f=o(n),T=g.map((I,O)=>({...I,...f[O]}));x.useEffect(()=>{i&&p(i)},[i]),x.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:$},X]=ie({query:ge,pause:!0,variables:{businessTripId:s??""}});return x.useEffect(()=>{if(y?.businessTrip?.attendees.length){const I=y.businessTrip.attendees.map(O=>({value:O.id,label:O.name}))??[];p(I)}},[y?.businessTrip?.attendees]),x.useEffect(()=>{c($)},[$]),x.useEffect(()=>{!i&&!y&&!t&&!$&&X({businessTripId:s})},[i,t,$,X,s,y]),!s&&!i?e.jsx("div",{children:"Cannot edit attendees stay, lacking some mandatory information!"}):e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Employees Stay"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[T?.map((I,O)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{name:`${n}.${O}.attendeeId`,control:r,rules:{required:"Required"},render:({field:R,fieldState:ae})=>e.jsx(Z,{...R,disabled:l,data:u,value:R.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:ae.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:r,name:`${n}.${O}.nightsCount`,render:({field:R,fieldState:ae})=>e.jsx(oe,{className:"w-full",...R,min:0,label:"Nights Count",value:R.value??void 0,hideControls:!0,precision:0,error:ae.error?.message,required:!0,onChange:U=>R.onChange(U&&typeof U=="number"?U:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(O),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},I.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{j({}),d(n)},children:e.jsx(Ie,{className:"size-5"})})]})]})}function ce({businessTripId:a,control:n,setFetching:i}){const[t,s]=x.useState([]),[{data:r,fetching:o,error:d}]=ie({query:ge,variables:{businessTripId:a}}),{userContext:g}=x.useContext(Ze);x.useEffect(()=>{r?.businessTrip?.attendees.length&&s(r.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[r,s]),x.useEffect(()=>{i(o)},[i,o]),x.useEffect(()=>{d&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const j=x.useMemo(()=>g?.context.ledgerLock,[g]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:j?{value:j,message:`Date must be after ${j}`}:void 0,pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(G,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:n,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"},min:j?{value:j,message:`Date must be after ${j}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(G,{...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Value Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"amount",control:n,render:({field:h,fieldState:l})=>e.jsx(b,{name:"currency",control:n,defaultValue:Fe.Ils,render:({field:c,fieldState:u})=>e.jsx(Me,{...h,value:h.value??void 0,error:l.error?.message||u.error?.message,label:"Amount",currencyCodeProps:{...c,label:"Currency"}})})}),e.jsx(b,{name:"employeeBusinessId",control:n,render:({field:h,fieldState:l})=>e.jsx(Z,{...h,data:t,value:h.value,disabled:o,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]})}function Te(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(ct,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function ct({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripAccommodationsExpense:j,fetching:h}=ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Accommodation Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{control:r,name:"country",render:({field:c})=>e.jsxs(z,{children:[e.jsx(J,{children:"Country"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{name:"nightsCount",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(J,{children:"Nights Count"}),e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})}),e.jsx(Ue,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:a}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const dt="updateBusinessTripAccommodationsExpense",lt=()=>{const[{fetching:a},n]=w(Ye),i=x.useCallback(async t=>{const s="Error updating business trip accommodations expense",r=dt;m.loading("Updating trip accommodations expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAccommodationsExpense:i}},ut="categorizeIntoExistingBusinessTripExpense",ht=()=>{const[{fetching:a},n]=w(Ke),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=ut;m.loading("Updating business trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeIntoExistingBusinessTripExpense:i}};function de(a){const{businessTripExpenseId:n,businessTripId:i,onChange:t}=a,[s,{close:r,open:o}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(Q,{className:"size-5"})})}),s&&e.jsx(xt,{businessTripExpenseId:n,businessTripId:i,opened:s,close:r,onChange:t})]})}function xt({businessTripExpenseId:a,businessTripId:n,opened:i,close:t,onChange:s}){const{control:r,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:a}}),[g,j]=x.useState([]),[{data:h,fetching:l,error:c}]=ie({query:Xe,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:p}=ht(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return x.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);j(T.map(({transaction:y})=>({eventDate:y.eventDate,sourceDescription:y.sourceDescription,referenceKey:y.referenceKey,counterparty:y.counterparty?.name,amount:y.amount.formatted,rawAmount:y.amount.raw,value:y.id,label:`${y.eventDate} | ${y.counterparty?.name} | ${y.amount.formatted}`})).sort((y,$)=>y.eventDate.localeCompare($.eventDate)))}},[h,j]),x.useEffect(()=>{c&&m.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(E,{opened:i,onClose:t,centered:!0,children:[e.jsx(E.Title,{children:"Set Transaction Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:r,render:({field:T,fieldState:y})=>e.jsx(Z,{...T,itemComponent:pt,data:g??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:$=>{const X=g.find(I=>I.value===$);X?.rawAmount&&d("amount",X.rawAmount),T.onChange($)}})}),e.jsx(b,{name:"amount",control:r,render:({field:T,fieldState:y})=>e.jsx(oe,{...T,value:T.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:y.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),p&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const pt=x.forwardRef(({eventDate:a,sourceDescription:n,referenceKey:i,counterparty:t,amount:s,...r},o)=>e.jsx("div",{ref:o,...r,children:e.jsxs(re,{children:[e.jsx(re.Col,{span:4,children:a}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(re.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(re.Col,{span:4,children:["Reference: ",i]})]})})),mt="deleteBusinessTripExpense",gt=()=>{const[{fetching:a},n]=w(Je),i=x.useCallback(async t=>{const s="Error deleting business trip expense",r=`${mt}-${t.businessTripExpenseId}`;m.loading("Deleting trip expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripExpense:i}};function le(a){const{fetching:n,deleteBusinessTripExpense:i}=gt(),t=x.useCallback(()=>{i({businessTripExpenseId:a.businessTripExpenseId}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Expense",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const ue=({data:a,isEditMode:n=!1,control:i,businessTripId:t})=>{const s=A(Qe,a),[r,o]=x.useState([]),[{data:d,fetching:g,error:j}]=ie({query:ge,variables:{businessTripId:t}});x.useEffect(()=>{d?.businessTrip?.attendees.length&&o(d.businessTrip.attendees.map(l=>({value:l.id,label:l.name})).sort((l,c)=>l.label>c.label?1:-1))},[d,o]),x.useEffect(()=>{j&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[j]);const h=Array.from(new Set(s.charges?.map(l=>l.id)));return e.jsxs(e.Fragment,{children:[e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:i,defaultValue:s.date,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:i,defaultValue:s.valueDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Value Date",error:c.error?.message,popoverProps:{withinPortal:!0}})})]}):e.jsxs(e.Fragment,{children:[s.date&&F(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&F(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:i,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:i,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:p})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||p.error?.message,label:"Amount",currencyCodeProps:{...u,label:"Currency",form:`form ${s.id}`}})})}):e.jsx("div",{children:s.amount?.formatted})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsx(b,{name:"employeeBusinessId",control:i,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(Z,{form:`form ${s.id}`,...l,data:r,value:l.value,disabled:g,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}):e.jsx("div",{className:"flex flex-row gap-2 items-center",children:s.payedByEmployee&&e.jsx(D,{c:s.employee?.name?void 0:"red",children:s.employee?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:h.map(l=>e.jsx(be,{to:ye.CHARGES.DETAIL(l),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"},l))})})]})},he=()=>e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Payed By Attendee"}),e.jsx("th",{children:"Charges"})]}),jt=({data:a,businessTripId:n,onChange:i})=>{const t=A(es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:g}=o,{updateBusinessTripAccommodationsExpense:j,fetching:h}=lt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(Ue,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(me,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(me.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})})]},t.id)},Ve=({businessTripId:a,expenses:n,onChange:i})=>{if(!n?.length)return i?e.jsx(Te,{businessTripId:a,onAdd:i}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ss,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Location"}),e.jsx("th",{children:"Nights"}),e.jsx("th",{children:"Attendees Stay"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(jt,{data:s,businessTripId:a,onChange:i},s.id)),i&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Te,{businessTripId:a,onAdd:i})})})]})]})})},ft=({data:a,onChange:n})=>{const{accommodationExpenses:i,id:t}=A(ts,a);return e.jsx(Ve,{businessTripId:t,expenses:i,onChange:n})},vt="insertBusinessTripAttendee",bt=()=>{const[{fetching:a},n]=w(ns),i=x.useCallback(async t=>{const s="Error adding attendee to business trip",r=vt;m.loading("Adding attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,insertBusinessTripAttendee:i}};function Ee(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function yt({businessTripId:a,opened:n,close:i,onAdd:t}){const{selectableBusinesses:s,fetching:r}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a}}),{insertBusinessTripAttendee:g,fetching:j}=bt(),h=l=>{g({fields:l}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,children:[e.jsx(E.Title,{children:"Add Attendee"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(Z,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:r,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withAsterisk:!0,withinPortal:!0})}),e.jsx(b,{name:"arrivalDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"departureDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})}),(j||r)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Tt="updateBusinessTripAttendee",Et=()=>{const[{fetching:a},n]=w(rs),i=x.useCallback(async t=>{const s="Error updating business trip attendee",r=Tt;m.loading("Updating trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAttendee:i}},Ct="deleteBusinessTripAttendee",At=()=>{const[{fetching:a},n]=w(is),i=x.useCallback(async t=>{const s="Error removing business trip attendee",r=Ct;m.loading("Removing business trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripAttendee:i}};function Dt(a){const{fetching:n,deleteBusinessTripAttendee:i}=At(),t=x.useCallback(()=>{i({fields:{businessTripId:a.businessTripId,attendeeId:a.attendeeId}}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Attendee",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const wt="addBusinessTripFlightsExpense",Bt=()=>{const[{fetching:a},n]=w(as),i=x.useCallback(async t=>{const s="Error adding business trip flight expense",r=wt;m.loading("Adding business trip flight expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripFlightsExpense:i}};function Le({formManager:a,flightPathPath:n,flightPathData:i}){const{control:t,watch:s,trigger:r}=a,{fields:o,append:d,remove:g}=Se({control:t,name:n}),j=s(n),h=o.map((l,c)=>({...l,...j[c]}));return i?e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Flight Path"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[h?.map((l,c)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(M,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(H,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{g(c),r(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),r(n)},children:e.jsx(Ie,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ce(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(Nt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}const St=Object.entries(Re).map(([a,n])=>({value:n,label:a}));function Nt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),[{data:j,fetching:h}]=ie({query:ge,variables:{businessTripId:a}}),{addBusinessTripFlightsExpense:l,fetching:c}=Bt(),u=f=>{l({fields:f}).then(()=>{t?.(),i()})},p=j?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Flight Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(Le,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:r,render:({field:f,fieldState:T})=>e.jsx(Z,{...f,data:St,value:f.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx(b,{name:"attendeeIds",control:r,render:({field:f,fieldState:T})=>e.jsx(He,{...f,disabled:h,data:p,value:f.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(c||d)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const It="updateBusinessTripFlightsExpense",Ft=()=>{const[{fetching:a},n]=w(os),i=x.useCallback(async t=>{const s="Error updating business trip flights expense",r=It;m.loading("Updating trip flights expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripFlightsExpense:i}},Mt=Object.entries(Re).map(([a,n])=>({value:n,label:a})),zt=({data:a,businessTripId:n,onChange:i,attendees:t})=>{const s=A(cs,a),[r,o]=x.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(p=>p.id)??[],path:s.path??[]}}),{control:g,handleSubmit:j}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Ft(),c=p=>{h({fields:p}).then(()=>{i?.(),o(!1)})},u=t.map(p=>({value:p.id,label:p.name}));return e.jsxs("tr",{children:[e.jsx(ue,{data:s,isEditMode:r,control:g,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:j(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[r?e.jsx(Le,{formManager:d,flightPathPath:"path",flightPathData:s.path??void 0}):e.jsx("div",{className:"flex gap-2 items-center",children:s.path?.length?s.path.map((p,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:p},f),f<s.path.length-1&&(p===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),r?e.jsx(b,{name:"flightClass",control:g,defaultValue:s.class??void 0,render:({field:p,fieldState:f})=>e.jsx(Z,{form:`form ${s.id}`,"data-autofocus":!0,...p,data:Mt,value:p.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(D,{c:s.class?void 0:"red",fz:"sm",children:`Class: ${s.class??"Missing"}`})]})})})}),e.jsx("td",{children:r?e.jsx(b,{name:"attendeeIds",control:g,defaultValue:s.attendees?.map(p=>p.id)??void 0,render:({field:p,fieldState:f})=>e.jsx(He,{...p,form:`form ${s.id}`,data:u,value:p.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(me,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(p=>e.jsx(me.Item,{children:p.name},p.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:r?"default":"outline",size:"icon",className:"size-7.5",onClick:p=>{p.stopPropagation(),o(f=>!f)},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${s.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:s.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:s.id,onDelete:i})]})})]},s.id)},_e=({businessTripId:a,expenses:n,attendees:i,onChange:t})=>{if(!n?.length)return t?e.jsx(Ce,{businessTripId:a,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(r=>A(ds,r));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((r,o)=>r.date&&o.date?r.date<o.date?1:-1:r.date?-1:o.date?1:0).map(r=>e.jsx(zt,{data:r,businessTripId:a,onChange:t,attendees:i},r.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ce,{businessTripId:a,onAdd:t})})})]})]})})},Pt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ls,a),[s,r]=x.useState(!1),[o,d]=x.useState(!1),{control:g,handleSubmit:j}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=Et(),c=u=>{h({fields:u}).then(()=>{i?.(),r(!1)})};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{children:s?e.jsx("form",{id:`form ${t.id}`,onSubmit:j(c),children:e.jsx(b,{name:"arrivalDate",control:g,defaultValue:t.arrivalDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},"data-autofocus":!0,value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:g,defaultValue:t.departureDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),r(p=>!p)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(Dt,{businessTripId:n,attendeeId:t.id,onDelete:i}),e.jsx(Vs,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(ke,{shadow:"sm",withBorder:!0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[t.flights&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Flights:"}),e.jsx(_e,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(Ve,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},$t=({data:a,onChange:n})=>{const{attendees:i,id:t}=A(us,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Arrival Date"}),e.jsx("th",{children:"Departure Date"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.name.toLocaleLowerCase()>r.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Pt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ee,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ee,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Ot=()=>{const[{fetching:a},n]=w(hs),i=x.useCallback(async t=>{const s="Error adding business trip car rental expense";m.loading("Adding car rental expense...",{id:pe});try{const r=await n(t),o=B(r,s,pe);if(o)return m.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(r){console.error(`${s}: ${r}`),m.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripCarRentalExpense:i}};function Ae(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(Rt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Rt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripCarRentalExpense:j,fetching:h}=Ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Car Rental Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(b,{name:"days",control:r,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(M,{name:"isFuelExpense",control:r,render:({field:{value:c,...u}})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(J,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const kt="updateBusinessTripCarRentalExpense",Ht=()=>{const[{fetching:a},n]=w(xs),i=x.useCallback(async t=>{const s="Error updating business trip car rental expense",r=kt;m.loading("Updating trip car rental expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripCarRentalExpense:i}},Ut=({data:a,businessTripId:n,onChange:i})=>{const t=A(ps,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripCarRentalExpense:j,fetching:h}=Ht(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:t.isFuelExpense!==!0&&(s?e.jsx(b,{name:"days",control:d,defaultValue:t.days,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,placeholder:"Rent Days"})}):e.jsx(D,{c:t.days?void 0:"red",children:t.days??"Missing"}))})})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(J,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(Ks,{}):e.jsx(Zs,{})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Vt=({data:a,onChange:n})=>{const{carRentalExpenses:i,id:t}=A(ms,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Ut,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ae,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ae,{businessTripId:t,onAdd:n})},Lt=({data:a,onChange:n})=>{const{flightExpenses:i,id:t,attendees:s}=A(gs,a);return e.jsx(_e,{businessTripId:t,attendees:s,expenses:i,onChange:n})},_t="addBusinessTripOtherExpense",Wt=()=>{const[{fetching:a},n]=w(js),i=x.useCallback(async t=>{const s='Error adding business trip "other" expense',r=_t;m.loading('Adding trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripOtherExpense:i}};function De(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(qt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function qt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripOtherExpense:j,fetching:h}=Wt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Other Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"description",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(J,{children:"Description"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(J,{children:"Deductible Expense"})}),e.jsx(P,{children:e.jsx(je,{checked:c.value===!0,onCheckedChange:c.onChange})})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Gt="updateBusinessTripOtherExpense",Zt=()=>{const[{fetching:a},n]=w(fs),i=x.useCallback(async t=>{const s='Error updating business trip "other" expense',r=Gt;m.loading('Updating business trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripOtherExpense:i}},Yt=({data:a,businessTripId:n,onChange:i})=>{const t=A(vs,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripOtherExpense:j,fetching:h}=Zt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.description?void 0:"red",children:t.description??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(z,{children:e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})})})}):e.jsx(D,{c:t.deductibleExpense?void 0:"red",children:t.deductibleExpense===!0?"Yes":t.deductibleExpense===!1?"No":"Missing"})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Kt=({data:a,onChange:n})=>{const{otherExpenses:i,id:t}=A(bs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Yt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(De,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(De,{businessTripId:t,onAdd:n})},Xt="addBusinessTripTravelAndSubsistenceExpense",Jt=()=>{const[{fetching:a},n]=w(ys),i=x.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",r=Xt;m.loading("Adding trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripTravelAndSubsistenceExpense:i}};function we(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(Q,{className:"size-5"})})}),t&&e.jsx(Qt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Qt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=Jt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"expenseType",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(J,{children:"Expense Type"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const en="updateBusinessTripTravelAndSubsistenceExpense",sn=()=>{const[{fetching:a},n]=w(Ts),i=x.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",r=en;m.loading("Updating trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripTravelAndSubsistenceExpense:i}},tn=({data:a,businessTripId:n,onChange:i})=>{const t=A(Es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=sn(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},nn=({data:a,onChange:n})=>{const{travelAndSubsistenceExpenses:i,id:t}=A(Cs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(tn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(we,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(we,{businessTripId:t,onAdd:n})},rn=({data:a})=>{const n=A(As,a),i="effectiveDate"in n?n.effectiveDate:void 0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col justify-center",children:[e.jsx("div",{children:i&&F(new Date(i),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",F(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},an=({data:a})=>{const n=A(Ds,a),i="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:i&&F(new Date(i),"dd/MM/yy")})})},on=({data:a})=>{const n=A(ws,a),{account:i}=n,t=Ls(i.type),s=i.name;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2 items-center",children:[e.jsx("p",{children:t}),e.jsx("p",{children:s})]})})},cn=({data:a})=>{const n=A(Bs,a),i="sourceDescription"in n?n.sourceDescription:"Missing";return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:i})})})},dn=({data:a})=>{const n=A(Ss,a);return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:n.referenceKey})})})};function ln({data:a,onChange:n,enableEdit:i}){const{id:t,counterparty:s,missingInfoSuggestions:r,id:o,sourceDescription:d}=A(Ns,a),g=!!r?.business&&i,j=g?r?.business?.name:"Missing",h=g?r?.business?.id:null,l=s?.name??j,[c,u]=x.useState(!1),{updateTransaction:p,fetching:f}=_s(),T=x.useCallback(async U=>{await p({transactionId:o,fields:{counterpartyId:U}}),u(!0)},[o,p]),y=x.useCallback(async U=>{await T(U),n?.()},[T,n]),{selectableBusinesses:$,fetching:X}=Oe(),[I,O]=x.useState(h??null),[R,ae]=x.useState(d);return e.jsxs("td",{children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center justify-center",children:s?.id?e.jsx(be,{to:ye.BUSINESSES.DETAIL(s.id),target:"_blank",rel:"noreferrer",onClick:U=>U.stopPropagation(),className:"inline-flex items-center font-semibold",children:l}):e.jsxs(e.Fragment,{children:[e.jsx(Is,{options:$,value:I,onChange:O,search:R,onSearchChange:ae,placeholder:"Choose or create a business",empty:R?e.jsx(Fs,{description:R,onAdd:y}):null}),e.jsx(C,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>I&&T(I),disabled:f||X||!I,children:e.jsx(te,{className:"size-4"})})})]})}),e.jsx(Ws,{transactionId:t,counterpartyId:s?.id??I,open:c,onOpenChange:u,onClose:n})]})}const un="categorizeBusinessTripExpense",hn=()=>{const[{fetching:a},n]=w(Ms),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=un;m.loading("Updating trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeBusinessTripExpense:i}};function xn(a){const{businessTripId:n,transactionId:i,onChange:t,defaultAmount:s}=a,[r,{close:o,open:d}]=V(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),d()},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(mn,{businessTripId:n,transactionId:i,opened:r,close:o,onChange:t,defaultAmount:s})]})}const pn=Object.entries(zs).map(([a,n])=>({value:n,label:a}));function mn({businessTripId:a,transactionId:n,defaultAmount:i,opened:t,close:s,onChange:r}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a,transactionId:n}}),{categorizeBusinessTripExpense:g,fetching:j}=hn(),h=l=>{g({fields:l}).then(()=>{r?.(),s()})};return e.jsxs(E,{opened:t,onClose:s,centered:!0,children:[e.jsx(E.Title,{children:"Set Expense Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"category",control:o,render:({field:l,fieldState:c})=>e.jsx(Z,{"data-autofocus":!0,...l,data:pn,value:l.value,label:"Category",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}),e.jsx(b,{name:"amount",control:o,defaultValue:i,render:({field:l,fieldState:c})=>e.jsx(oe,{...l,value:l.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:c.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),j&&e.jsx(Y,{blur:1,center:!0,children:e.jsx(K,{})})]})}const gn=({data:a,onChange:n})=>{const{uncategorizedTransactions:i,id:t}=A(Ps,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Event Date"}),e.jsx("th",{children:"Debit Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Reference#"}),e.jsx("th",{children:"Counterparty"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.sort((s,r)=>s.transaction.eventDate.localeCompare(r.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(an,{data:s.transaction}),e.jsx(rn,{data:s.transaction}),e.jsx(jn,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(on,{data:s.transaction}),e.jsx(cn,{data:s.transaction}),e.jsx(dn,{data:s.transaction}),e.jsx(ln,{data:s.transaction}),e.jsx("td",{children:e.jsx(xn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},jn=({data:a})=>{const{transaction:n,categorizedAmount:i,errors:t}=A($s,a),s="amount"in n?n.amount:void 0,r=s?.raw!==i.raw&&i.raw!==0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col whitespace-nowrap",style:{color:Number(s?.raw)>0?"green":"red"},children:[e.jsxs("div",{className:"flex gap-1",children:[s?.formatted,t.length>0&&e.jsx(fn,{errors:t})]}),r&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[i.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Os(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},fn=({errors:a})=>{const[n,{close:i,open:t}]=V(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(Rs,{onMouseEnter:t,onMouseLeave:i})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:a.map((s,r)=>e.jsx(D,{size:"sm",children:s},r))})]})};function wn({tripId:a,isExtended:n=!1}){const[i,t]=x.useState(),[{data:s},r]=ie({query:ks,variables:{businessTripId:a}}),o=r;return x.useEffect(()=>{s?.businessTrip&&t(s.businessTrip)},[s?.businessTrip]),e.jsx(ke,{shadow:"sm",radius:"md",withBorder:!0,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{data:i,onChange:o}),e.jsxs(qs,{className:"w-full",type:"multiple",children:[e.jsxs(L,{value:"attendees",children:[e.jsx(_,{children:"Attendees"}),e.jsx(W,{children:e.jsx($t,{data:i,onChange:o})})]}),n&&e.jsxs(L,{value:"uncategorized-transactions",children:[e.jsx(_,{disabled:!i.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(W,{children:e.jsx(gn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"flights",children:[e.jsx(_,{children:"Flights"}),e.jsx(W,{children:e.jsx(Lt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"accommodations",children:[e.jsx(_,{children:"Accommodations"}),e.jsx(W,{children:e.jsx(ft,{data:i,onChange:o})})]}),e.jsxs(L,{value:"travelAndSubsistence",children:[e.jsx(_,{children:"Travel & Subsistence"}),e.jsx(W,{children:e.jsx(nn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"other",children:[e.jsx(_,{children:"Other"}),e.jsx(W,{children:e.jsx(Kt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"carRental",children:[e.jsx(_,{children:"Car Rental"}),e.jsx(W,{children:e.jsx(Vt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"summary",children:[e.jsx(_,{children:"Summary"}),e.jsx(W,{children:e.jsx(Us,{data:i})})]})]})]}):e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{wn as E,Dn as P};
|
|
1
|
+
import{v as ve,cj as We,ck as qe,r as x,j as e,B as v,L as Be,g as w,cl as Ge,t as m,i as B,H as Se,u as ie,cm as ge,bE as b,bH as Y,cn as oe,co as Ne,cp as Ie,aC as Ye,bF as q,bG as G,w as F,ay as Fe,cq as Me,l as U,T as C,a3 as J,E as N,n as E,V as S,Y as M,Z as z,_ as Q,$ as P,I as ee,a1 as H,b7 as ze,cr as Z,d as K,cs as Ze,ct as Ke,cu as Xe,bv as D,cv as Qe,bX as Pe,cw as $e,ah as be,R as ye,a6 as A,cx as Je,ag as se,e as te,cy as es,cz as ss,cA as ts,cB as ns,bD as Oe,cC as rs,cD as is,cE as as,cF as Re,cG as os,cH as cs,cI as ds,cJ as ls,cK as us,cL as hs,at as je,cM as xs,cN as ps,cO as ms,cP as gs,cQ as js,cR as fs,cS as vs,cT as bs,cU as ys,cV as Ts,cW as Es,cX as Cs,cY as As,cZ as Ds,c_ as ws,c$ as Bs,d0 as Ss,d1 as Ns,d2 as Is,q as Fs,d3 as Ms,d4 as zs,d5 as Ps,d6 as $s,d7 as Os,d8 as fe,d9 as Rs,da as ks}from"./index-rI994S3C.js";import{G as re,L as me,C as ke,R as Hs,S as Vs}from"./summary-CPKS_69D.js";import{T as ne}from"./Table-BQv3frL8.js";import{T as Us}from"./toggle-expansion-button-Y2eS7nqg.js";import{M as He}from"./MultiSelect-DBeIExB5.js";import{a as Ls,u as _s,S as Ws}from"./similar-transactions-modal-DX3CPrMo.js";import{A as qs,a as L,b as _,c as W}from"./accordion-Bn08_4fN.js";const Gs=[["path",{d:"M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9C18.7 10.6 16 10 16 10s-1.3-1.4-2.2-2.3c-.5-.4-1.1-.7-1.8-.7H5c-.6 0-1.1.4-1.4.9l-1.4 2.9A3.7 3.7 0 0 0 2 12v4c0 .6.4 1 1 1h2",key:"5owen"}],["circle",{cx:"7",cy:"17",r:"2",key:"u2ysq9"}],["path",{d:"M9 17h6",key:"r8uit2"}],["circle",{cx:"17",cy:"17",r:"2",key:"axvx0g"}]],Ys=ve("car",Gs);const Zs=[["path",{d:"M14 13h2a2 2 0 0 1 2 2v2a2 2 0 0 0 4 0v-6.998a2 2 0 0 0-.59-1.42L18 5",key:"1wtuz0"}],["path",{d:"M14 21V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v16",key:"e09ifn"}],["path",{d:"M2 21h13",key:"1x0fut"}],["path",{d:"M3 9h11",key:"1p7c0w"}]],Ks=ve("fuel",Zs);const Xs=[["path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2",key:"143wyd"}],["path",{d:"M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6",key:"1itne7"}],["rect",{x:"6",y:"14",width:"12",height:"8",rx:"1",key:"1ue0tg"}]],Qs=ve("printer",Xs);var k=3.77952755906,xe={method:"save",resolution:3,page:{margin:0,format:"A4",orientation:"portrait"},canvas:{mimeType:"image/jpeg",qualityRatio:1,useCORS:!0,logging:!1},overrides:{}},Js=class{pdf;canvas;options;constructor(a,n){this.canvas=a,this.options=n,this.pdf=new qe({format:this.options.page.format,orientation:this.options.page.orientation,...this.options.overrides?.pdf,unit:"mm"})}getMarginTopMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.top:this.options.page.margin;return Number(a)}getMarginLeftMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.left:this.options.page.margin;return Number(a)}getMarginRightMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.right:this.options.page.margin;return Number(a)}getMarginBottomMM(){const a=typeof this.options.page.margin=="object"?this.options.page.margin.bottom:this.options.page.margin;return Number(a)}getMarginTop(){return this.getMarginTopMM()*k}getMarginBottom(){return this.getMarginBottomMM()*k}getMarginLeft(){return this.getMarginLeftMM()*k}getMarginRight(){return this.getMarginRightMM()*k}getScale(){return this.options.resolution}getPageHeight(){return this.getPageHeightMM()*k}getPageHeightMM(){return this.pdf.internal.pageSize.height}getPageWidthMM(){return this.pdf.internal.pageSize.width}getPageWidth(){return this.getPageWidthMM()*k}getOriginalCanvasWidth(){return this.canvas.width/this.getScale()}getOriginalCanvasHeight(){return this.canvas.height/this.getScale()}getCanvasPageAvailableHeight(){return this.getPageAvailableHeight()*this.getScale()*this.getHorizontalFitFactor()}getPageAvailableWidth(){return this.getPageWidth()-(this.getMarginLeft()+this.getMarginRight())}getPageAvailableHeight(){return this.getPageHeight()-(this.getMarginTop()+this.getMarginBottom())}getPageAvailableWidthMM(){return this.getPageAvailableWidth()/k}getPageAvailableHeightMM(){return this.getPageAvailableHeight()/k}getNumberPages(){return Math.ceil(this.canvas.height/this.getCanvasPageAvailableHeight())}getHorizontalFitFactor(){return this.getPageAvailableWidth()<this.getOriginalCanvasWidth()?this.getOriginalCanvasWidth()/this.getPageAvailableWidth():1}getCanvasOffsetY(a){return this.getCanvasPageAvailableHeight()*(a-1)}getCanvasHeightLeft(a){return this.canvas.height-this.getCanvasOffsetY(a)}getCanvasPageHeight(a){if(this.canvas.height<this.getCanvasPageAvailableHeight())return this.canvas.height;const n=this.getCanvasHeightLeft(a);return n<this.getCanvasPageAvailableHeight()?n:this.getCanvasPageAvailableHeight()}getCanvasPageWidth(){return this.canvas.width}createCanvasPage(a){const n=this.getCanvasPageWidth(),i=this.getCanvasPageHeight(a),t=document.createElement("canvas");return t.setAttribute("width",String(n)),t.setAttribute("height",String(i)),t.getContext("2d").drawImage(this.canvas,0,this.getCanvasOffsetY(a),this.canvas.width,i,0,0,this.canvas.width,i),t}convert(){let a=1;const n=this.getNumberPages();for(;a<=n;){a>1&&this.pdf.addPage(this.options.page.format,this.options.page.orientation);const i=this.createCanvasPage(a),t=i.toDataURL(this.options.canvas.mimeType,this.options.canvas.qualityRatio);this.pdf.setPage(a),this.pdf.addImage({imageData:t,width:i.width/(this.getScale()*k*this.getHorizontalFitFactor()),height:i.height/(this.getScale()*k*this.getHorizontalFitFactor()),x:this.getMarginLeftMM(),y:this.getMarginTopMM()}),a+=1}return this.pdf}},et=a=>a?{...xe,...a,canvas:{...xe.canvas,...a.canvas},page:{...xe.page,...a.page}}:xe,st=a=>typeof a=="function"?a():a?.current,tt=async(a,n)=>{const i=et(n),t=st(a);if(!t){console.error("Unable to get the target element.");return}const s=await We(t,{useCORS:i.canvas.useCORS,logging:i.canvas.logging,scale:i.resolution,...i.overrides?.canvas}),o=new Js(s,i).convert();switch(i.method){case"build":return o;case"open":return window.open(o.output("bloburl"),"_blank"),o;default:{const d=i.filename??`${new Date().getTime()}.pdf`;return await o.save(d,{returnPromise:!0}),o}}},nt=tt;const rt={method:"open",overrides:{pdf:{compress:!0}}},it=()=>document.getElementById("main-page"),Dn=({filename:a})=>{const[n,i]=x.useState(!1),t=async()=>{i(!0),await nt(it,{...rt,filename:a}),i(!1)};return e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:t,disabled:n,children:n?e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"}):e.jsx(Qs,{className:"size-5"})})},at="addBusinessTripAccommodationsExpense",ot=()=>{const[{fetching:a},n]=w(Ge),i=x.useCallback(async t=>{const s="Error adding business trip accommodations expense",r=at;m.loading("Adding Business Trip Accommodations Expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense added"}),d.addBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripAccommodationsExpense:i}};function Ve({formManager:a,attendeesStayPath:n,attendeesData:i,fetchingAttendees:t=!1,businessTripId:s}){const{control:r,watch:o,trigger:d}=a,{fields:g,append:j,remove:h}=Se({control:r,name:n}),[l,c]=x.useState(t),[u,p]=x.useState(i??[]),f=o(n),T=g.map((I,O)=>({...I,...f[O]}));x.useEffect(()=>{i&&p(i)},[i]),x.useEffect(()=>{c(t)},[t]);const[{data:y,fetching:$},X]=ie({query:ge,pause:!0,variables:{businessTripId:s??""}});return x.useEffect(()=>{if(y?.businessTrip?.attendees.length){const I=y.businessTrip.attendees.map(O=>({value:O.id,label:O.name}))??[];p(I)}},[y?.businessTrip?.attendees]),x.useEffect(()=>{c($)},[$]),x.useEffect(()=>{!i&&!y&&!t&&!$&&X({businessTripId:s})},[i,t,$,X,s,y]),!s&&!i?e.jsx("div",{children:"Cannot edit attendees stay, lacking some mandatory information!"}):e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Employees Stay"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[T?.map((I,O)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{name:`${n}.${O}.attendeeId`,control:r,rules:{required:"Required"},render:({field:R,fieldState:ae})=>e.jsx(Y,{...R,disabled:l,data:u,value:R.value??void 0,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:ae.error?.message,withinPortal:!0,required:!0})})}),e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(b,{control:r,name:`${n}.${O}.nightsCount`,render:({field:R,fieldState:ae})=>e.jsx(oe,{className:"w-full",...R,min:0,label:"Nights Count",value:R.value??void 0,hideControls:!0,precision:0,error:ae.error?.message,required:!0,onChange:V=>R.onChange(V&&typeof V=="number"?V:void 0)})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{h(O),d(n)},children:e.jsx(Ne,{className:"size-5"})})]},I.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{j({}),d(n)},children:e.jsx(Ie,{className:"size-5"})})]})]})}function ce({businessTripId:a,control:n,setFetching:i}){const[t,s]=x.useState([]),[{data:r,fetching:o,error:d}]=ie({query:ge,variables:{businessTripId:a}}),{userContext:g}=x.useContext(Ye);x.useEffect(()=>{r?.businessTrip?.attendees.length&&s(r.businessTrip.attendees.map(h=>({value:h.id,label:h.name})).sort((h,l)=>h.label>l.label?1:-1))},[r,s]),x.useEffect(()=>{i(o)},[i,o]),x.useEffect(()=>{d&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[d]);const j=x.useMemo(()=>g?.context.ledgerLock,[g]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:n,rules:{min:j?{value:j,message:`Date must be after ${j}`}:void 0,pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:h,fieldState:l})=>e.jsx(G,{"data-autofocus":!0,...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:n,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"},min:j?{value:j,message:`Date must be after ${j}`}:void 0},render:({field:h,fieldState:l})=>e.jsx(G,{...h,onChange:c=>{const u=c?typeof c=="string"?c:F(c,"yyyy-MM-dd"):void 0;u!==h.value&&h.onChange(u)},value:h.value?new Date(h.value):void 0,error:l.error?.message,label:"Value Date",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"amount",control:n,render:({field:h,fieldState:l})=>e.jsx(b,{name:"currency",control:n,defaultValue:Fe.Ils,render:({field:c,fieldState:u})=>e.jsx(Me,{...h,value:h.value??void 0,error:l.error?.message||u.error?.message,label:"Amount",currencyCodeProps:{...c,label:"Currency"}})})}),e.jsx(b,{name:"employeeBusinessId",control:n,render:({field:h,fieldState:l})=>e.jsx(Y,{...h,data:t,value:h.value,disabled:o,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:l.error?.message,withinPortal:!0})})]})}function Te(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Accommodations Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(ct,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function ct({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripAccommodationsExpense:j,fetching:h}=ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Accommodation Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{control:r,name:"country",render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Country"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{name:"nightsCount",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Nights Count"}),e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})}),e.jsx(Ve,{formManager:s,attendeesStayPath:"attendeesStay",businessTripId:a}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const dt="updateBusinessTripAccommodationsExpense",lt=()=>{const[{fetching:a},n]=w(Ze),i=x.useCallback(async t=>{const s="Error updating business trip accommodations expense",r=dt;m.loading("Updating trip accommodations expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip accommodations expense was updated"}),d.updateBusinessTripAccommodationsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAccommodationsExpense:i}},ut="categorizeIntoExistingBusinessTripExpense",ht=()=>{const[{fetching:a},n]=w(Ke),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=ut;m.loading("Updating business trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeIntoExistingBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeIntoExistingBusinessTripExpense:i}};function de(a){const{businessTripExpenseId:n,businessTripId:i,onChange:t}=a,[s,{close:r,open:o}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Attach Uncategorized Transaction",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:d=>{d.stopPropagation(),o()},children:e.jsx(J,{className:"size-5"})})}),s&&e.jsx(xt,{businessTripExpenseId:n,businessTripId:i,opened:s,close:r,onChange:t})]})}function xt({businessTripExpenseId:a,businessTripId:n,opened:i,close:t,onChange:s}){const{control:r,handleSubmit:o,setValue:d}=N({defaultValues:{businessTripExpenseId:a}}),[g,j]=x.useState([]),[{data:h,fetching:l,error:c}]=ie({query:Xe,variables:{businessTripId:n}}),{categorizeIntoExistingBusinessTripExpense:u,fetching:p}=ht(),f=T=>{u({fields:T}).then(()=>{s?.(),t()})};return x.useEffect(()=>{if(h?.businessTrip?.uncategorizedTransactions.length){const T=h.businessTrip.uncategorizedTransactions.filter(y=>y?.transaction);j(T.map(({transaction:y})=>({eventDate:y.eventDate,sourceDescription:y.sourceDescription,referenceKey:y.referenceKey,counterparty:y.counterparty?.name,amount:y.amount.formatted,rawAmount:y.amount.raw,value:y.id,label:`${y.eventDate} | ${y.counterparty?.name} | ${y.amount.formatted}`})).sort((y,$)=>y.eventDate.localeCompare($.eventDate)))}},[h,j]),x.useEffect(()=>{c&&m.error("Error",{description:"Oops, we have an error fetching transactions to categorize"})},[c]),e.jsxs(E,{opened:i,onClose:t,centered:!0,children:[e.jsx(E.Title,{children:"Set Transaction Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:o(f),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"transactionId",control:r,render:({field:T,fieldState:y})=>e.jsx(Y,{...T,itemComponent:pt,data:g??[],disabled:l,label:"Transactions",placeholder:"Scroll to see all options",maxDropdownHeight:160,error:y.error?.message,withAsterisk:!0,withinPortal:!0,onChange:$=>{const X=g.find(I=>I.value===$);X?.rawAmount&&d("amount",X.rawAmount),T.onChange($)}})}),e.jsx(b,{name:"amount",control:r,render:({field:T,fieldState:y})=>e.jsx(oe,{...T,value:T.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:y.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),p&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const pt=x.forwardRef(({eventDate:a,sourceDescription:n,referenceKey:i,counterparty:t,amount:s,...r},o)=>e.jsx("div",{ref:o,...r,children:e.jsxs(re,{children:[e.jsx(re.Col,{span:4,children:a}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:t})}),e.jsx(re.Col,{span:4,children:e.jsx(D,{size:"sm",children:s})}),e.jsx(re.Col,{span:8,children:e.jsx(D,{size:"xs",opacity:.65,children:n})}),e.jsxs(re.Col,{span:4,children:["Reference: ",i]})]})})),mt="deleteBusinessTripExpense",gt=()=>{const[{fetching:a},n]=w(Qe),i=x.useCallback(async t=>{const s="Error deleting business trip expense",r=`${mt}-${t.businessTripExpenseId}`;m.loading("Deleting trip expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense was deleted"}),d.deleteBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripExpense:i}};function le(a){const{fetching:n,deleteBusinessTripExpense:i}=gt(),t=x.useCallback(()=>{i({businessTripExpenseId:a.businessTripExpenseId}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Expense",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove expense?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const ue=({data:a,isEditMode:n=!1,control:i,businessTripId:t})=>{const s=A(Je,a),[r,o]=x.useState([]),[{data:d,fetching:g,error:j}]=ie({query:ge,variables:{businessTripId:t}});x.useEffect(()=>{d?.businessTrip?.attendees.length&&o(d.businessTrip.attendees.map(l=>({value:l.id,label:l.name})).sort((l,c)=>l.label>c.label?1:-1))},[d,o]),x.useEffect(()=>{j&&m.error("Error",{description:"Oops, we have an error fetching attendees"})},[j]);const h=Array.from(new Set(s.charges?.map(l=>l.id)));return e.jsxs(e.Fragment,{children:[e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"date",control:i,defaultValue:s.date,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,"data-autofocus":!0,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Date",error:c.error?.message,popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"valueDate",control:i,defaultValue:s.valueDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,form:`form ${s.id}`,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,label:"Value Date",error:c.error?.message,popoverProps:{withinPortal:!0}})})]}):e.jsxs(e.Fragment,{children:[s.date&&F(new Date(s.date),"dd/MM/yy"),e.jsx(D,{fz:"sm",c:"dimmed",children:s.valueDate&&F(new Date(s.valueDate),"dd/MM/yy")})]})})}),e.jsx("td",{children:n&&s.payedByEmployee?e.jsx(b,{name:"amount",control:i,defaultValue:s.amount?.raw??void 0,render:({field:l,fieldState:c})=>e.jsx(b,{name:"currency",control:i,defaultValue:s.amount?.currency??Fe.Ils,render:({field:u,fieldState:p})=>e.jsx(Me,{form:`form ${s.id}`,...l,value:l.value??void 0,error:c.error?.message||p.error?.message,label:"Amount",currencyCodeProps:{...u,label:"Currency",form:`form ${s.id}`}})})}):e.jsx("div",{children:s.amount?.formatted})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:n&&s.payedByEmployee?e.jsx(b,{name:"employeeBusinessId",control:i,defaultValue:s.employee?.id,render:({field:l,fieldState:c})=>e.jsx(Y,{form:`form ${s.id}`,...l,data:r,value:l.value,disabled:g,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}):e.jsx("div",{className:"flex flex-row gap-2 items-center",children:s.payedByEmployee&&e.jsx(D,{c:s.employee?.name?void 0:"red",children:s.employee?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2",children:h.map(l=>e.jsx(be,{to:ye.CHARGES.DETAIL(l),target:"_blank",rel:"noreferrer",onClick:c=>c.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"},l))})})]})},he=()=>e.jsxs(e.Fragment,{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Payed By Attendee"}),e.jsx("th",{children:"Charges"})]}),jt=({data:a,businessTripId:n,onChange:i})=>{const t=A(es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n,attendeesStay:t.attendeesStay.map(c=>({attendeeId:c.id,nightsCount:c.nightsCount}))}}),{control:d,handleSubmit:g}=o,{updateBusinessTripAccommodationsExpense:j,fetching:h}=lt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"country",control:d,defaultValue:t.country,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.country?void 0:"red",children:t.country?.name??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"nightsCount",control:d,defaultValue:t.nightsCount,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ze,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,decimalScale:0,thousandSeparator:","})}),e.jsx(H,{})]})})}):e.jsx(D,{c:t.nightsCount?void 0:"red",children:t.nightsCount??"Missing"})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(Ve,{formManager:o,attendeesStayPath:"attendeesStay",businessTripId:n})}):e.jsx(me,{listStyleType:"disc",children:t.attendeesStay?.length?t.attendeesStay.map(c=>e.jsxs(me.Item,{children:[c.attendee.name," (",c.nightsCount,")"]},c.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})})]},t.id)},Ue=({businessTripId:a,expenses:n,onChange:i})=>{if(!n?.length)return i?e.jsx(Te,{businessTripId:a,onAdd:i}):e.jsx(e.Fragment,{});const t=n.map(s=>A(ss,s));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Location"}),e.jsx("th",{children:"Nights"}),e.jsx("th",{children:"Attendees Stay"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(jt,{data:s,businessTripId:a,onChange:i},s.id)),i&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Te,{businessTripId:a,onAdd:i})})})]})]})})},ft=({data:a,onChange:n})=>{const{accommodationExpenses:i,id:t}=A(ts,a);return e.jsx(Ue,{businessTripId:t,expenses:i,onChange:n})},vt="insertBusinessTripAttendee",bt=()=>{const[{fetching:a},n]=w(ns),i=x.useCallback(async t=>{const s="Error adding attendee to business trip",r=vt;m.loading("Adding attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Attendee was added to the business trip"}),d.insertBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,insertBusinessTripAttendee:i}};function Ee(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Attendee",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(yt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function yt({businessTripId:a,opened:n,close:i,onAdd:t}){const{selectableBusinesses:s,fetching:r}=Oe(),{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a}}),{insertBusinessTripAttendee:g,fetching:j}=bt(),h=l=>{g({fields:l}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,children:[e.jsx(E.Title,{children:"Add Attendee"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(b,{name:"attendeeId",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:s,value:l.value,disabled:r,label:"Attendee",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withAsterisk:!0,withinPortal:!0})}),e.jsx(b,{name:"arrivalDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})}),e.jsx(b,{name:"departureDate",control:o,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:l,fieldState:c})=>e.jsx(G,{...l,onChange:u=>{const p=u?typeof u=="string"?u:F(u,"yyyy-MM-dd"):void 0;p!==l.value&&l.onChange(p)},value:l.value?new Date(l.value):void 0,error:c.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})}),(j||r)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Tt="updateBusinessTripAttendee",Et=()=>{const[{fetching:a},n]=w(rs),i=x.useCallback(async t=>{const s="Error updating business trip attendee",r=Tt;m.loading("Updating trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was updated"}),d.updateBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripAttendee:i}},Ct="deleteBusinessTripAttendee",At=()=>{const[{fetching:a},n]=w(is),i=x.useCallback(async t=>{const s="Error removing business trip attendee",r=Ct;m.loading("Removing business trip attendee",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip attendee was removed"}),d.deleteBusinessTripAttendee}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,deleteBusinessTripAttendee:i}};function Dt(a){const{fetching:n,deleteBusinessTripAttendee:i}=At(),t=x.useCallback(()=>{i({fields:{businessTripId:a.businessTripId,attendeeId:a.attendeeId}}).then(()=>{a.onDelete?.()})},[a,i]);return e.jsx(C,{content:"Remove Attendee",children:e.jsx(Pe,{onConfirm:t,title:"Are you sure you want to remove attendee?",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5 text-red-500",disabled:n,children:e.jsx($e,{className:"size-5"})})})})}const wt="addBusinessTripFlightsExpense",Bt=()=>{const[{fetching:a},n]=w(as),i=x.useCallback(async t=>{const s="Error adding business trip flight expense",r=wt;m.loading("Adding business trip flight expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flight expense added"}),d.addBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripFlightsExpense:i}};function Le({formManager:a,flightPathPath:n,flightPathData:i}){const{control:t,watch:s,trigger:r}=a,{fields:o,append:d,remove:g}=Se({control:t,name:n}),j=s(n),h=o.map((l,c)=>({...l,...j[c]}));return i?e.jsxs("div",{children:[e.jsx("span",{className:"mantine-InputWrapper-label mantine-Select-label",children:"Flight Path"}),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[h?.map((l,c)=>e.jsxs("div",{className:"flex items-end gap-2 text-gray-600 mb-2",children:[e.jsx("div",{className:"w-full mt-1 relative rounded-md shadow-xs",children:e.jsx(M,{name:`${n}.${c}`,control:t,rules:{required:"Required"},render:({field:u})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{...u,value:u.value??void 0,placeholder:"Destination"})}),e.jsx(H,{})]})})}),e.jsx(v,{variant:"ghost",size:"icon",className:"mb-2 size-7.5",onClick:()=>{g(c),r(n)},children:e.jsx(Ne,{className:"size-5"})})]},l.id)),e.jsx(v,{variant:"ghost",size:"icon",className:"size-7.5",onClick:()=>{d(""),r(n)},children:e.jsx(Ie,{className:"size-5"})})]})]}):e.jsx("div",{children:"Cannot edit flight path stay, lacking some mandatory information!"})}function Ce(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Flight Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Nt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}const St=Object.entries(Re).map(([a,n])=>({value:n,label:a}));function Nt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),[{data:j,fetching:h}]=ie({query:ge,variables:{businessTripId:a}}),{addBusinessTripFlightsExpense:l,fetching:c}=Bt(),u=f=>{l({fields:f}).then(()=>{t?.(),i()})},p=j?.businessTrip?.attendees.map(f=>({value:f.id,label:f.name}))??[];return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Flight Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(u),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(Le,{formManager:s,flightPathPath:"path"}),e.jsx(b,{name:"flightClass",control:r,render:({field:f,fieldState:T})=>e.jsx(Y,{...f,data:St,value:f.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx(b,{name:"attendeeIds",control:r,render:({field:f,fieldState:T})=>e.jsx(He,{...f,disabled:h,data:p,value:f.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:T.error?.message,withinPortal:!0})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(c||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const It="updateBusinessTripFlightsExpense",Ft=()=>{const[{fetching:a},n]=w(os),i=x.useCallback(async t=>{const s="Error updating business trip flights expense",r=It;m.loading("Updating trip flights expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip flights expense was updated"}),d.updateBusinessTripFlightsExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripFlightsExpense:i}},Mt=Object.entries(Re).map(([a,n])=>({value:n,label:a})),zt=({data:a,businessTripId:n,onChange:i,attendees:t})=>{const s=A(cs,a),[r,o]=x.useState(!1),d=N({defaultValues:{id:s.id,businessTripId:n,attendeeIds:s.attendees?.map(p=>p.id)??[],path:s.path??[]}}),{control:g,handleSubmit:j}=d,{updateBusinessTripFlightsExpense:h,fetching:l}=Ft(),c=p=>{h({fields:p}).then(()=>{i?.(),o(!1)})},u=t.map(p=>({value:p.id,label:p.name}));return e.jsxs("tr",{children:[e.jsx(ue,{data:s,isEditMode:r,control:g,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...d,children:e.jsx("form",{id:`form ${s.id}`,onSubmit:j(c),children:e.jsxs("div",{className:"flex flex-col gap-2 justify-center",children:[r?e.jsx(Le,{formManager:d,flightPathPath:"path",flightPathData:s.path??void 0}):e.jsx("div",{className:"flex gap-2 items-center",children:s.path?.length?s.path.map((p,f)=>e.jsxs(e.Fragment,{children:[e.jsx(D,{fw:700,children:p},f),f<s.path.length-1&&(p===s.path[f+1]?" | ":" → ")]})):e.jsx(D,{fw:700,className:"flex gap-2 items-center",c:"red",children:"Missing"})}),r?e.jsx(b,{name:"flightClass",control:g,defaultValue:s.class??void 0,render:({field:p,fieldState:f})=>e.jsx(Y,{form:`form ${s.id}`,"data-autofocus":!0,...p,data:Mt,value:p.value,label:"Flight Class",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(D,{c:s.class?void 0:"red",fz:"sm",children:`Class: ${s.class??"Missing"}`})]})})})}),e.jsx("td",{children:r?e.jsx(b,{name:"attendeeIds",control:g,defaultValue:s.attendees?.map(p=>p.id)??void 0,render:({field:p,fieldState:f})=>e.jsx(He,{...p,form:`form ${s.id}`,data:u,value:p.value??[],label:"Attendees",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:f.error?.message,withinPortal:!0})}):e.jsx(me,{listStyleType:"disc",children:s.attendees?.length?s.attendees.map(p=>e.jsx(me.Item,{children:p.name},p.id)):e.jsx(D,{c:"red",fz:"sm",children:"Missing"})})}),e.jsx("td",{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:r?"default":"outline",size:"icon",className:"size-7.5",onClick:p=>{p.stopPropagation(),o(f=>!f)},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${s.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:s.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:s.id,onDelete:i})]})})]},s.id)},_e=({businessTripId:a,expenses:n,attendees:i,onChange:t})=>{if(!n?.length)return t?e.jsx(Ce,{businessTripId:a,onAdd:t}):e.jsx(e.Fragment,{});const s=n.map(r=>A(ds,r));return e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Flight"}),e.jsx("th",{children:"Attendees"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[s.sort((r,o)=>r.date&&o.date?r.date<o.date?1:-1:r.date?-1:o.date?1:0).map(r=>e.jsx(zt,{data:r,businessTripId:a,onChange:t,attendees:i},r.id)),t&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,children:e.jsx(Ce,{businessTripId:a,onAdd:t})})})]})]})})},Pt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ls,a),[s,r]=x.useState(!1),[o,d]=x.useState(!1),{control:g,handleSubmit:j}=N({defaultValues:{businessTripId:n,attendeeId:t.id,arrivalDate:t.arrivalDate,departureDate:t.departureDate}}),{updateBusinessTripAttendee:h,fetching:l}=Et(),c=u=>{h({fields:u}).then(()=>{i?.(),r(!1)})};return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{children:s?e.jsx("form",{id:`form ${t.id}`,onSubmit:j(c),children:e.jsx(b,{name:"arrivalDate",control:g,defaultValue:t.arrivalDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},"data-autofocus":!0,value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Arrival",popoverProps:{withinPortal:!0}})})}):t.arrivalDate}),e.jsx("td",{children:s?e.jsx(b,{name:"departureDate",control:g,defaultValue:t.departureDate,rules:{pattern:{value:q,message:"Date must be im format yyyy-mm-dd"}},render:({field:u,fieldState:p})=>e.jsx(G,{...u,onChange:f=>{const T=f?typeof f=="string"?f:F(f,"yyyy-MM-dd"):void 0;T!==u.value&&u.onChange(T)},value:u.value?new Date(u.value):void 0,error:p.error?.message,label:"Departure",popoverProps:{withinPortal:!0}})}):t.departureDate}),e.jsxs("td",{className:"flex items-center gap-2",children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:l,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:u=>{u.stopPropagation(),r(p=>!p)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(Dt,{businessTripId:n,attendeeId:t.id,onDelete:i}),e.jsx(Us,{toggleExpansion:d,isExpanded:o})]})]},t.id),o&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(ke,{shadow:"sm",withBorder:!0,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[t.flights&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Flights:"}),e.jsx(_e,{businessTripId:n,attendees:[],expenses:t.flights})]}),t.accommodations&&e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Accommodations:"}),e.jsx(Ue,{businessTripId:n,expenses:t.accommodations})]})]})})})},`${t.id}-expension`)]})},$t=({data:a,onChange:n})=>{const{attendees:i,id:t}=A(us,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Arrival Date"}),e.jsx("th",{children:"Departure Date"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.name.toLocaleLowerCase()>r.name.toLocaleLowerCase()?1:-1).map(s=>e.jsx(Pt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:4,children:e.jsx(Ee,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ee,{businessTripId:t,onAdd:n})},pe="addBusinessTripCarRentalExpense",Ot=()=>{const[{fetching:a},n]=w(hs),i=x.useCallback(async t=>{const s="Error adding business trip car rental expense";m.loading("Adding car rental expense...",{id:pe});try{const r=await n(t),o=B(r,s,pe);if(o)return m.success("Success",{id:pe,description:"Car rental expense added"}),o.addBusinessTripCarRentalExpense}catch(r){console.error(`${s}: ${r}`),m.error("Error",{id:pe,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripCarRentalExpense:i}};function Ae(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Car Rental Expense",children:e.jsx(v,{variant:"outline",size:"icon",onClick:o=>{o.stopPropagation(),r()},className:"size-7.5",children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Rt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Rt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripCarRentalExpense:j,fetching:h}=Ot(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Car Rental Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(b,{name:"days",control:r,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,label:"Rent Days"})}),e.jsx(M,{name:"isFuelExpense",control:r,render:({field:{value:c,...u}})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{...u,checked:c===!0,onCheckedChange:u.onChange})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const kt="updateBusinessTripCarRentalExpense",Ht=()=>{const[{fetching:a},n]=w(xs),i=x.useCallback(async t=>{const s="Error updating business trip car rental expense",r=kt;m.loading("Updating trip car rental expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip car rental expense was updated"}),d.updateBusinessTripCarRentalExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripCarRentalExpense:i}},Vt=({data:a,businessTripId:n,onChange:i})=>{const t=A(ps,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripCarRentalExpense:j,fetching:h}=Ht(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:t.isFuelExpense!==!0&&(s?e.jsx(b,{name:"days",control:d,defaultValue:t.days,render:({field:c,fieldState:u})=>e.jsx(oe,{...c,value:c.value??void 0,form:`form ${t.id}`,hideControls:!0,precision:2,removeTrailingZeros:!0,error:u.error?.message,placeholder:"Rent Days"})}):e.jsx(D,{c:t.days?void 0:"red",children:t.days??"Missing"}))})})})}),e.jsx("td",{children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"isFuelExpense",control:d,defaultValue:t.isFuelExpense,render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Is Fuel Expense"})}),e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})]})})}):t.isFuelExpense===!0?e.jsx(Ks,{}):e.jsx(Ys,{})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Ut=({data:a,onChange:n})=>{const{carRentalExpenses:i,id:t}=A(ms,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Days"}),e.jsx("th",{children:"Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Vt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(Ae,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(Ae,{businessTripId:t,onAdd:n})},Lt=({data:a,onChange:n})=>{const{flightExpenses:i,id:t,attendees:s}=A(gs,a);return e.jsx(_e,{businessTripId:t,attendees:s,expenses:i,onChange:n})},_t="addBusinessTripOtherExpense",Wt=()=>{const[{fetching:a},n]=w(js),i=x.useCallback(async t=>{const s='Error adding business trip "other" expense',r=_t;m.loading('Adding trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was added'}),d.addBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripOtherExpense:i}};function De(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add Other Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(qt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function qt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripOtherExpense:j,fetching:h}=Wt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Other Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"description",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Description"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx(M,{control:s.control,name:"deductibleExpense",render:({field:c})=>e.jsxs(z,{className:"flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm",children:[e.jsx("div",{className:"space-y-0.5",children:e.jsx(Q,{children:"Deductible Expense"})}),e.jsx(P,{children:e.jsx(je,{checked:c.value===!0,onCheckedChange:c.onChange})})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const Gt="updateBusinessTripOtherExpense",Yt=()=>{const[{fetching:a},n]=w(fs),i=x.useCallback(async t=>{const s='Error updating business trip "other" expense',r=Gt;m.loading('Updating business trip "other" expense',{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:'Business trip "other" expense was updated'}),d.updateBusinessTripOtherExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripOtherExpense:i}},Zt=({data:a,businessTripId:n,onChange:i})=>{const t=A(vs,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripOtherExpense:j,fetching:h}=Yt(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"description",control:d,defaultValue:t.description,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.description?void 0:"red",children:t.description??"Missing"})})})}),e.jsx("td",{children:e.jsx("div",{className:"flex flex-col gap-2 justify-center",children:s?e.jsx(S,{...o,children:e.jsx(M,{name:"deductibleExpense",control:o.control,defaultValue:t.deductibleExpense,render:({field:c})=>e.jsx(z,{children:e.jsx(P,{children:e.jsx(je,{form:`form ${t.id}`,checked:c.value===!0,onCheckedChange:c.onChange})})})})}):e.jsx(D,{c:t.deductibleExpense?void 0:"red",children:t.deductibleExpense===!0?"Yes":t.deductibleExpense===!1?"No":"Missing"})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},Kt=({data:a,onChange:n})=>{const{otherExpenses:i,id:t}=A(bs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Deductible Expense"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(Zt,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(De,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(De,{businessTripId:t,onAdd:n})},Xt="addBusinessTripTravelAndSubsistenceExpense",Qt=()=>{const[{fetching:a},n]=w(ys),i=x.useCallback(async t=>{const s="Error adding business trip travel&subsistence expense",r=Xt;m.loading("Adding trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was added"}),d.addBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,addBusinessTripTravelAndSubsistenceExpense:i}};function we(a){const{businessTripId:n,onAdd:i}=a,[t,{close:s,open:r}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Add T&S Expense",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:o=>{o.stopPropagation(),r()},children:e.jsx(J,{className:"size-5"})})}),t&&e.jsx(Jt,{businessTripId:n,opened:t,close:s,onAdd:i})]})}function Jt({businessTripId:a,opened:n,close:i,onAdd:t}){const s=N({defaultValues:{businessTripId:a}}),{control:r,handleSubmit:o}=s,[d,g]=x.useState(!1),{addBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=Qt(),l=c=>{j({fields:c}).then(()=>{t?.(),i()})};return e.jsxs(E,{opened:n,onClose:i,centered:!0,lockScroll:!0,children:[e.jsx(E.Title,{children:"Add Travel & Subsistence Expense"}),e.jsx(E.Body,{children:e.jsx(S,{...s,children:e.jsxs("form",{onSubmit:o(l),className:"space-y-3",children:[e.jsx(ce,{businessTripId:a,control:r,setFetching:g}),e.jsx(M,{name:"expenseType",control:r,render:({field:c})=>e.jsxs(z,{children:[e.jsx(Q,{children:"Expense Type"}),e.jsx(P,{children:e.jsx(ee,{...c,value:c.value??void 0})}),e.jsx(H,{})]})}),e.jsx("div",{className:"flex justify-center mt-5 gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Add"})})]})})}),(h||d)&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const en="updateBusinessTripTravelAndSubsistenceExpense",sn=()=>{const[{fetching:a},n]=w(Ts),i=x.useCallback(async t=>{const s="Error updating business trip travel&subsistence expense",r=en;m.loading("Updating trip travel&subsistence expense",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip travel&subsistence expense was updated"}),d.updateBusinessTripTravelAndSubsistenceExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,updateBusinessTripTravelAndSubsistenceExpense:i}},tn=({data:a,businessTripId:n,onChange:i})=>{const t=A(Es,a),[s,r]=x.useState(!1),o=N({defaultValues:{id:t.id,businessTripId:n}}),{control:d,handleSubmit:g}=o,{updateBusinessTripTravelAndSubsistenceExpense:j,fetching:h}=sn(),l=c=>{j({fields:c}).then(()=>{i?.(),r(!1)})};return e.jsxs("tr",{children:[e.jsx(ue,{data:t,isEditMode:s,control:d,businessTripId:n}),e.jsx("td",{children:e.jsx(S,{...o,children:e.jsx("form",{id:`form ${t.id}`,onSubmit:g(l),children:s?e.jsx(M,{name:"expenseType",control:d,defaultValue:t.expenseType,render:({field:c})=>e.jsxs(z,{children:[e.jsx(P,{children:e.jsx(ee,{form:`form ${t.id}`,...c,value:c.value??void 0})}),e.jsx(H,{})]})}):e.jsx(D,{c:t.expenseType?void 0:"red",children:t.expenseType??"Missing"})})})}),e.jsxs("td",{children:[e.jsx(C,{content:"Edit",children:e.jsx(v,{disabled:h,variant:s?"default":"outline",size:"icon",className:"size-7.5",onClick:c=>{c.stopPropagation(),r(u=>!u)},children:e.jsx(se,{className:"size-5"})})}),s&&e.jsx(C,{content:"Confirm Changes",children:e.jsx(v,{type:"submit",form:`form ${t.id}`,variant:"outline",size:"icon",className:"size-7.5 text-green-500",children:e.jsx(te,{className:"size-5"})})}),e.jsx(de,{businessTripExpenseId:t.id,businessTripId:n,onChange:i}),e.jsx(le,{businessTripExpenseId:t.id,onDelete:i})]})]},t.id)},nn=({data:a,onChange:n})=>{const{travelAndSubsistenceExpenses:i,id:t}=A(Cs,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx(he,{}),e.jsx("th",{children:"Expense Type"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[i.sort((s,r)=>s.date&&r.date?s.date<r.date?1:-1:s.date?-1:r.date?1:0).map(s=>e.jsx(tn,{data:s,businessTripId:t,onChange:n},s.id)),e.jsx("tr",{children:e.jsx("td",{colSpan:6,children:e.jsx(we,{businessTripId:t,onAdd:n})})})]})]})}):e.jsx(we,{businessTripId:t,onAdd:n})},rn=({data:a})=>{const n=A(As,a),i="effectiveDate"in n?n.effectiveDate:void 0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col justify-center",children:[e.jsx("div",{children:i&&F(new Date(i),"dd/MM/yy")}),n.sourceEffectiveDate&&e.jsxs("div",{className:"text-xs text-gray-500",children:["(Originally ",F(new Date(n.sourceEffectiveDate),"dd/MM/yy"),")"]})]})})},an=({data:a})=>{const n=A(Ds,a),i="eventDate"in n?n.eventDate:void 0;return e.jsx("td",{children:e.jsx("div",{className:"flex flex-col justify-center",children:i&&F(new Date(i),"dd/MM/yy")})})},on=({data:a})=>{const n=A(ws,a),{account:i}=n,t=Ls(i.type),s=i.name;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col gap-2 items-center",children:[e.jsx("p",{children:t}),e.jsx("p",{children:s})]})})},cn=({data:a})=>{const n=A(Bs,a),i="sourceDescription"in n?n.sourceDescription:"Missing";return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:i})})})},dn=({data:a})=>{const n=A(Ss,a);return e.jsx("td",{children:e.jsx("div",{className:"flex flex-wrap",children:e.jsx("div",{className:"flex flex-col justify-center",children:n.referenceKey})})})};function ln({data:a,onChange:n,enableEdit:i}){const{id:t,counterparty:s,missingInfoSuggestions:r,id:o,sourceDescription:d}=A(Ns,a),g=!!r?.business&&i,j=g?r?.business?.name:"Missing",h=g?r?.business?.id:null,l=s?.name??j,[c,u]=x.useState(!1),{updateTransaction:p,fetching:f}=_s(),T=x.useCallback(async V=>{await p({transactionId:o,fields:{counterpartyId:V}}),u(!0)},[o,p]),y=x.useCallback(async V=>{await T(V),n?.()},[T,n]),{selectableBusinesses:$,fetching:X}=Oe(),[I,O]=x.useState(h??null),[R,ae]=x.useState(d);return e.jsxs("td",{children:[e.jsx("div",{className:"flex flex-wrap gap-1 items-center justify-center",children:s?.id?e.jsx(be,{to:ye.BUSINESSES.DETAIL(s.id),target:"_blank",rel:"noreferrer",onClick:V=>V.stopPropagation(),className:"inline-flex items-center font-semibold",children:l}):e.jsxs(e.Fragment,{children:[e.jsx(Is,{options:$,value:I,onChange:O,search:R,onSearchChange:ae,placeholder:"Choose or create a business",empty:R?e.jsx(Fs,{description:R,onAdd:y}):null}),e.jsx(C,{content:"Approve",children:e.jsx(v,{variant:"outline",size:"icon",onClick:()=>I&&T(I),disabled:f||X||!I,children:e.jsx(te,{className:"size-4"})})})]})}),e.jsx(Ws,{transactionId:t,counterpartyId:s?.id??I,open:c,onOpenChange:u,onClose:n})]})}const un="categorizeBusinessTripExpense",hn=()=>{const[{fetching:a},n]=w(Ms),i=x.useCallback(async t=>{const s="Error updating business trip expense category",r=un;m.loading("Updating trip expense category",{id:r});try{const o=await n(t),d=B(o,s,r);if(d)return m.success("Success",{id:r,description:"Business trip expense category was updated"}),d.categorizeBusinessTripExpense}catch(o){console.error(`${s}: ${o}`),m.error("Error",{id:r,description:s,duration:1e5,closeButton:!0})}},[n]);return{fetching:a,categorizeBusinessTripExpense:i}};function xn(a){const{businessTripId:n,transactionId:i,onChange:t,defaultAmount:s}=a,[r,{close:o,open:d}]=U(!1);return e.jsxs(e.Fragment,{children:[e.jsx(C,{content:"Categorize",children:e.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:g=>{g.stopPropagation(),d()},children:e.jsx(se,{className:"size-5"})})}),r&&e.jsx(mn,{businessTripId:n,transactionId:i,opened:r,close:o,onChange:t,defaultAmount:s})]})}const pn=Object.entries(zs).map(([a,n])=>({value:n,label:a}));function mn({businessTripId:a,transactionId:n,defaultAmount:i,opened:t,close:s,onChange:r}){const{control:o,handleSubmit:d}=N({defaultValues:{businessTripId:a,transactionId:n}}),{categorizeBusinessTripExpense:g,fetching:j}=hn(),h=l=>{g({fields:l}).then(()=>{r?.(),s()})};return e.jsxs(E,{opened:t,onClose:s,centered:!0,children:[e.jsx(E.Title,{children:"Set Expense Category"}),e.jsx(E.Body,{children:e.jsxs("form",{onSubmit:d(h),className:"flex flex-col gap-3 mt-3",children:[e.jsx(b,{name:"category",control:o,render:({field:l,fieldState:c})=>e.jsx(Y,{"data-autofocus":!0,...l,data:pn,value:l.value,label:"Category",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:c.error?.message,withinPortal:!0})}),e.jsx(b,{name:"amount",control:o,defaultValue:i,render:({field:l,fieldState:c})=>e.jsx(oe,{...l,value:l.value??void 0,hideControls:!0,precision:2,removeTrailingZeros:!0,error:c.error?.message,label:"Amount"})}),e.jsx("div",{className:"flex justify-center gap-3",children:e.jsx("button",{type:"submit",className:"text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-hidden hover:bg-indigo-600 rounded-sm text-lg",children:"Confirm"})})]})}),j&&e.jsx(Z,{blur:1,center:!0,children:e.jsx(K,{})})]})}const gn=({data:a,onChange:n})=>{const{uncategorizedTransactions:i,id:t}=A(Ps,a);return i?.length?e.jsx("div",{className:"flex flex-col gap-2 mt-5",children:e.jsxs(ne,{highlightOnHover:!0,withBorder:!0,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Event Date"}),e.jsx("th",{children:"Debit Date"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{}),e.jsx("th",{children:"Account"}),e.jsx("th",{children:"Description"}),e.jsx("th",{children:"Reference#"}),e.jsx("th",{children:"Counterparty"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:i.sort((s,r)=>s.transaction.eventDate.localeCompare(r.transaction.eventDate)).map(s=>e.jsxs("tr",{children:[e.jsx(an,{data:s.transaction}),e.jsx(rn,{data:s.transaction}),e.jsx(jn,{data:s}),e.jsx("td",{children:e.jsx(be,{to:ye.CHARGES.DETAIL(s.transaction.chargeId),target:"_blank",rel:"noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center font-semibold",children:"To Charge"})}),e.jsx(on,{data:s.transaction}),e.jsx(cn,{data:s.transaction}),e.jsx(dn,{data:s.transaction}),e.jsx(ln,{data:s.transaction}),e.jsx("td",{children:e.jsx(xn,{businessTripId:t,transactionId:s.transaction.id,onChange:n,defaultAmount:s.transaction.amount.raw})})]},s.transaction.id))})]})}):e.jsx(e.Fragment,{})},jn=({data:a})=>{const{transaction:n,categorizedAmount:i,errors:t}=A($s,a),s="amount"in n?n.amount:void 0,r=s?.raw!==i.raw&&i.raw!==0;return e.jsx("td",{children:e.jsxs("div",{className:"flex flex-col whitespace-nowrap",style:{color:Number(s?.raw)>0?"green":"red"},children:[e.jsxs("div",{className:"flex gap-1",children:[s?.formatted,t.length>0&&e.jsx(fn,{errors:t})]}),r&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[i.formatted," categorized "]}),n.cryptoExchangeRate&&e.jsxs("div",{className:"text-gray-500 ml-2",children:[`(Rate: ${n.cryptoExchangeRate.rate})`,e.jsx("br",{}),s?.raw?`${Os(s.raw*n.cryptoExchangeRate.rate)}$`:null]})]})})},fn=({errors:a})=>{const[n,{close:i,open:t}]=U(!1);return e.jsxs(fe,{width:200,position:"bottom",shadow:"md",opened:n,children:[e.jsx(fe.Target,{children:e.jsx(Rs,{onMouseEnter:t,onMouseLeave:i})}),e.jsx(fe.Dropdown,{sx:{pointerEvents:"none"},className:"whitespace-normal text-red-500",children:a.map((s,r)=>e.jsx(D,{size:"sm",children:s},r))})]})};function wn({tripId:a,isExtended:n=!1}){const[i,t]=x.useState(),[{data:s},r]=ie({query:ks,variables:{businessTripId:a}}),o=r;return x.useEffect(()=>{s?.businessTrip&&t(s.businessTrip)},[s?.businessTrip]),e.jsx(ke,{shadow:"sm",radius:"md",withBorder:!0,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{data:i,onChange:o}),e.jsxs(qs,{className:"w-full",type:"multiple",children:[e.jsxs(L,{value:"attendees",children:[e.jsx(_,{children:"Attendees"}),e.jsx(W,{children:e.jsx($t,{data:i,onChange:o})})]}),n&&e.jsxs(L,{value:"uncategorized-transactions",children:[e.jsx(_,{disabled:!i.uncategorizedTransactions?.length,children:"Uncategorized Transactions"}),e.jsx(W,{children:e.jsx(gn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"flights",children:[e.jsx(_,{children:"Flights"}),e.jsx(W,{children:e.jsx(Lt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"accommodations",children:[e.jsx(_,{children:"Accommodations"}),e.jsx(W,{children:e.jsx(ft,{data:i,onChange:o})})]}),e.jsxs(L,{value:"travelAndSubsistence",children:[e.jsx(_,{children:"Travel & Subsistence"}),e.jsx(W,{children:e.jsx(nn,{data:i,onChange:o})})]}),e.jsxs(L,{value:"other",children:[e.jsx(_,{children:"Other"}),e.jsx(W,{children:e.jsx(Kt,{data:i,onChange:o})})]}),e.jsxs(L,{value:"carRental",children:[e.jsx(_,{children:"Car Rental"}),e.jsx(W,{children:e.jsx(Ut,{data:i,onChange:o})})]}),e.jsxs(L,{value:"summary",children:[e.jsx(_,{children:"Summary"}),e.jsx(W,{children:e.jsx(Vs,{data:i})})]})]})]}):e.jsx(Be,{className:"h-10 w-10 animate-spin mr-2 self-center"})})}export{wn as E,Dn as P};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as e}from"./index-
|
|
1
|
+
import{v as e}from"./index-rI994S3C.js";const a=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],t=e("eye-off",a);export{t as E};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v as e}from"./index-
|
|
1
|
+
import{v as e}from"./index-rI994S3C.js";const n=[["path",{d:"M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",key:"sc7q7i"}]],a=e("funnel",n);export{a as F};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as n,r as x,g9 as g,B as v,a6 as h,gB as j,a as D,F as R,u as E,L as y,bC as w,T as f,dZ as C,gC as T}from"./index-rI994S3C.js";import{d as A}from"./graphql-document-dedupe-fragments-ByT8-wlV.js";import{P as b}from"./page-layout-DMGj5xhW.js";import{P as F}from"./modal-BXR_xgUm.js";import{F as N}from"./funnel-Cfb9Pxmr.js";import{T as I}from"./Table-BQv3frL8.js";const i=({originalAmount:a,diffAmount:t})=>!t||a===t?n.jsx("td",{children:a}):n.jsx("td",{children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:t?"line-through":"",children:a}),t&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md",children:t})]})});function P({years:a,setYears:t}){const[r,o]=x.useState(!1);return n.jsxs(n.Fragment,{children:[n.jsx(F,{opened:r,onClose:()=>o(!1),withCloseButton:!0,content:n.jsx(g,{type:"multiple",label:"Pick years",value:a?.map(c=>new Date(c,0,1)),onChange:c=>t(c.map(p=>p.getFullYear())),popoverProps:{withinPortal:!0},minDate:new Date(2010,0,1),maxDate:new Date})}),n.jsx(v,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>o(!0),children:n.jsx(N,{className:"size-5"})})]})}const u=({originalRuleData:a,diffRuleData:t})=>{const r=h(j,a),o=h(j,t),c=o?.isCompliant!==r.isCompliant||o?.percentage.formatted!==r.percentage.formatted;return!o||!c?n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:r.percentage.formatted}):n.jsx("td",{className:r.isCompliant?"text-green-500":"text-red-500",children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("p",{className:"line-through ".concat(r.isCompliant?"text-green-500":"text-red-500"),children:r.percentage.formatted}),o&&n.jsx("div",{className:"border-2 border-yellow-500 rounded-md ".concat(o.isCompliant?"text-green-500":"text-red-500"),children:o.percentage.formatted})]})})},d=(a,t)=>C(t).format(a);function m(a,t){if(a.length!==0)return d(a.reduce((r,o)=>r+o,0),t)}const O=()=>{const{year:a}=D(),{setFiltersContext:t}=x.useContext(R),[r,o]=x.useState(a?[Number(a)]:[new Date().getFullYear()]),[{data:c,fetching:p}]=E({query:A(T),variables:{years:r}});x.useEffect(()=>{t(n.jsx("div",{className:"flex flex-row gap-2",children:n.jsx(P,{years:r,setYears:o})}))},[r,p,t]);const s=c?.corporateTaxRulingComplianceReport??[];return n.jsx(b,{title:"Corporate Tax Ruling Compliance Report",children:p?n.jsx(y,{className:"h-10 w-10 animate-spin mr-2 self-center"}):n.jsx("div",{className:"flex flex-col gap-4",children:s&&n.jsxs(I,{highlightOnHover:!0,fontSize:"md",children:[n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{}),r.map(e=>n.jsx("th",{children:n.jsx(w,{inline:!0,size:12,processing:!s.find(l=>l.year===e)?.differences,disabled:!!s.find(l=>l.year===e)?.differences,color:"orange",zIndex:"auto",children:e})},e)),n.jsx("th",{children:"Summary"},"sum")]})}),n.jsxs("tbody",{children:[n.jsxs("tr",{children:[n.jsx("td",{children:"Total Income"}),s.map(e=>n.jsx(i,{originalAmount:e.totalIncome.formatted,diffAmount:e.differences?.totalIncome?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:d(s.map(e=>e.totalIncome.raw).reduce((e,l)=>e+l,0),s[0].totalIncome.currency),diffAmount:m(s.map(e=>e.differences?.totalIncome?.raw??e.totalIncome.raw).filter(e=>!!e),s[0].totalIncome.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Total R&D Expensess"}),s.map(e=>n.jsx(i,{originalAmount:e.researchAndDevelopmentExpenses.formatted,diffAmount:e.differences?.researchAndDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:d(s.map(e=>e.researchAndDevelopmentExpenses.raw).reduce((e,l)=>e+l,0),s[0].researchAndDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.researchAndDevelopmentExpenses?.raw??e.researchAndDevelopmentExpenses.raw).filter(e=>!!e),s[0].researchAndDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(f,{content:s[0]?.rndRelativeToIncome.rule,className:"max-w-[220px] whitespace-normal",children:n.jsx("p",{children:"R&D Expenses out of Income"})})}),s.map(e=>n.jsx(u,{originalRuleData:e.rndRelativeToIncome,diffRuleData:e.differences?.rndRelativeToIncome??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Local Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.localDevelopmentExpenses.formatted,diffAmount:e.differences?.localDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:d(s.map(e=>e.localDevelopmentExpenses.raw).reduce((e,l)=>e+l,0),s[0].localDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.localDevelopmentExpenses?.raw??e.localDevelopmentExpenses.raw).filter(e=>!!e),s[0].localDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(f,{content:s[0]?.localDevelopmentRelativeToRnd.rule,className:"max-w-[220px] whitespace-normal",children:n.jsx("p",{children:"Local Development out of R&D"})})}),s.map(e=>n.jsx(u,{originalRuleData:e.localDevelopmentRelativeToRnd,diffRuleData:e.differences?.localDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"Foreign Development Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.foreignDevelopmentExpenses.formatted,diffAmount:e.differences?.foreignDevelopmentExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:d(s.map(e=>e.foreignDevelopmentExpenses.raw).reduce((e,l)=>e+l,0),s[0].foreignDevelopmentExpenses.currency),diffAmount:m(s.map(e=>e.differences?.foreignDevelopmentExpenses?.raw??e.foreignDevelopmentExpenses.raw).filter(e=>!!e),s[0].foreignDevelopmentExpenses.currency)},"sum")]}),n.jsxs("tr",{children:[n.jsx("th",{children:n.jsx(f,{content:s[0]?.foreignDevelopmentRelativeToRnd.rule,className:"max-w-[220px] whitespace-normal",children:n.jsx("p",{children:"Foreign Development out of R&D"})})}),s.map(e=>n.jsx(u,{originalRuleData:e.foreignDevelopmentRelativeToRnd,diffRuleData:e.differences?.foreignDevelopmentRelativeToRnd??void 0},e.year)),n.jsx("td",{})]}),n.jsxs("tr",{children:[n.jsx("td",{children:"R&D Business Trips Expenses"}),s.map(e=>n.jsx(i,{originalAmount:e.businessTripRndExpenses.formatted,diffAmount:e.differences?.businessTripRndExpenses?.formatted??void 0},e.year)),n.jsx(i,{originalAmount:d(s.map(e=>e.businessTripRndExpenses.raw).reduce((e,l)=>e+l,0),s[0].businessTripRndExpenses.currency),diffAmount:m(s.map(e=>e.differences?.businessTripRndExpenses?.raw??e.businessTripRndExpenses.raw).filter(e=>!!e),s[0].businessTripRndExpenses.currency)},"sum")]})]})]})})})};export{O as CorporateTaxRulingComplianceReport};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as P,j as r,e as
|
|
2
|
-
`);i.length===1?n.push(r.jsx(s,{children:t},`unchanged-${n.length}`)):i.map((l,o)=>{n.push(r.jsx(s,{children:l},o)),p.push(r.jsx("div",{children:n},p.length-1)),n=[]})}return n.length>0&&p.push(r.jsx("div",{children:n},p.length-1)),p},[c,m]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"text-sm text-gray-500 flex flex-row gap-2",children:[r.jsx("span",{className:"font-bold",children:"Month:"}),r.jsx("span",{children:D.slice(0,7)}),!d.length&&r.jsx(
|
|
1
|
+
import{r as P,j as r,e as H,u as Q,h7 as q,L,aC as $,bB as K,B as U,E as X,bD as ee,bE as te,bH as ne,bN as O,w as S,h8 as G,bI as se,F as oe,J as re,O as ie,W as le}from"./index-rI994S3C.js";import{u as J}from"./use-url-query-CqWra6gD.js";import{P as ae}from"./page-layout-DMGj5xhW.js";import{A as ce,a as fe,b as ue,c as he}from"./accordion-Bn08_4fN.js";import{P as de}from"./modal-BXR_xgUm.js";import{F as pe}from"./funnel-Cfb9Pxmr.js";var v={},z;function ye(){if(z)return v;z=1,Object.defineProperty(v,"__esModule",{value:!0}),v.calcSlices=v.applyPatch=v.calcPatch=v.lcs=v.diff=v.diff_core=void 0;function c(e,n){const{b:t,eq:s,stack_base:i}=e;let{i:l,N:o,j:h,M:a,Z:f,stack_top:x}=e;for(;;)switch(n){case 0:{e:for(;o>0&&a>0;){t.fill(0,0,2*f);const R=o-a,_=o+a,V=_&1,W=l+o-1,Y=h+a-1,Z=(_+V)/2;let F;t:for(let M=0;M<=Z;M++){const E=2*Math.max(0,M-a)-M,I=M-2*Math.max(0,M-o);for(let u=E;u<=I;u+=2){const A=t[u-1-f*Math.floor((u-1)/f)],B=t[u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<B?B:A+1,k=w-u;let b=w,C=k;for(;b<o&&C<a&&s(l+b,h+C);)b++,C++;if(t[u-f*Math.floor(u/f)]=b,V===1&&(F=R-u)>=1-M&&F<M&&b+t[f+F-f*Math.floor(F/f)]>=o)if(M>1||b!==w){i[x++]=l+b,i[x++]=o-b,i[x++]=h+C,i[x++]=a-C,o=w,a=k,f=2*(Math.min(o,a)+1);continue e}else break t}for(let u=E;u<=I;u+=2){const A=t[f+u-1-f*Math.floor((u-1)/f)],B=t[f+u+1-f*Math.floor((u+1)/f)],w=u===-M||u!==M&&A<B?B:A+1,k=w-u;let b=w,C=k;for(;b<o&&C<a&&s(W-b,Y-C);)b++,C++;if(t[f+u-f*Math.floor(u/f)]=b,V===0&&(F=R-u)>=-M&&F<=M&&b+t[F-f*Math.floor(F/f)]>=o)if(M>0||b!==w){i[x++]=l+o-w,i[x++]=w,i[x++]=h+a-k,i[x++]=k,o=o-b,a=a-C,f=2*(Math.min(o,a)+1);continue e}else break t}}if(o!==a){a>o?(l+=o,h+=o,a-=o,o=0):(l+=a,h+=a,o-=a,a=0);break}}if(o+a!==0)if(e.pxe===l||e.pye===h)e.pxe=l+o,e.pye=h+a;else{const R=e.pxs;if(e.oxs=e.pxs,e.oxe=e.pxe,e.oys=e.pys,e.oye=e.pye,e.pxs=l,e.pxe=l+o,e.pys=h,e.pye=h+a,R>=0)return e.i=l,e.N=o,e.j=h,e.M=a,e.Z=f,e.stack_top=x,1}}case 1:{if(x===0)return 2;a=i[--x],h=i[--x],o=i[--x],l=i[--x],f=2*(Math.min(o,a)+1),n=0}}}class m{constructor(n){this.state=n,this.c=0,this.result={value:null,done:!1}}[Symbol.iterator](){return this}next(){const{state:n,result:t}=this;if(this.c>1)return t.done=!0,t.value=void 0,t;const s=c(n,this.c);return this.c=s,s===1?(t.value=[n.oxs,n.oxe,n.oys,n.oye],t):n.pxs>=0?(t.value=[n.pxs,n.pxe,n.pys,n.pye],t):(t.done=!0,t.value=void 0,t)}}function D(e,n,t,s,i){const l=(Math.min(n,s)+1)*2,o=n+s,h=new(o<256?Uint8Array:o<65536?Uint16Array:Uint32Array)(2*l);return new m({i:e,N:n,j:t,M:s,Z:l,b:h,eq:i,pxs:-1,pxe:-1,pys:-1,pye:-1,oxs:-1,oxe:-1,oys:-1,oye:-1,stack_top:0,stack_base:[]})}v.diff_core=D;function d(e,n,t){let[s,i,l]=[0,e.length,n.length];if(typeof t=="function"){for(;s<i&&s<l&&t(s,s);)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;t(--i,--l)&&i>s&&l>s;);}else{for(;s<i&&s<l&&e[s]===n[s];)s++;if(s===i&&s===l)return[][Symbol.iterator]();for(;e[--i]===n[--l]&&i>s&&l>s;);t=(o,h)=>e[o]===n[h]}return D(s,i+1-s,s,l+1-s,t)}v.diff=d;class p{constructor(n,t){this.diff=n,this.N=t,this.i=0,this.j=0}[Symbol.iterator](){return this}next(){const n=this.diff.next();if(n.done){const{i:a,j:f,N:x}=this;return a<x&&(n.done=!1,n.value=[a,f,x-a],this.i=x),n}const t=n.value,s=t[0],i=t[1],l=t[3],{i:o,j:h}=this;return o!==s&&(t.length--,t[0]=o,t[1]=h,t[2]=s-o),this.i=i,this.j=l,n}}function y(e,n,t){return new p(d(e,n,t),e.length)}v.lcs=y;function*g(e,n,t){const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const i of d(e,n,t))i[2]=s.call(n,i[2],i[3]),yield i}v.calcPatch=g;function*N(e,n){let t=0;const s=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[i,l,o]of n)t<i&&(yield s.call(e,t,i)),o.length>0&&(yield o),t=l;t<e.length&&(yield s.call(e,t))}v.applyPatch=N;function*j(e,n,t){let s=0;const i=ArrayBuffer.isView(e)?Uint8Array.prototype.subarray:e.slice;for(const[l,o,h,a]of d(e,n,t))s<l&&(yield[0,i.call(e,s,l)]),l<o&&(yield[-1,i.call(e,l,o)]),h<a&&(yield[1,i.call(n,h,a)]),s=o;s<e.length&&(yield[0,e.slice(s)])}return v.calcSlices=j,v}var xe=ye();const me=({children:c})=>r.jsx("span",{className:"bg-green-100",children:c}),je=({children:c})=>r.jsx("span",{className:"bg-red-100 line-through",children:c}),T=({children:c})=>r.jsx("span",{children:c}),ge=({content:c,contentOrigin:m,monthDate:D})=>{const d=P.useMemo(()=>{const p=[];if(!m)return p;const y=c.split(""),g=m.split(""),N=Array.from(xe.calcPatch(g,y)),j=[];let e=0;for(const[t,s,i]of N)if(j.length===0&&t>=17&&s<=25&&i.length===s-t){if(N.length===1)return p;continue}else e<t&&j.push([g.slice(e,t).join(""),T]),s>t&&j.push([g.slice(t,s).join(""),je]),i.length>0&&j.push([i.join(""),me]),e=s;e<g.length&&j.push([g.slice(e).join(""),T]);let n=[];for(const[t,s]of j){const i=t.split(`
|
|
2
|
+
`);i.length===1?n.push(r.jsx(s,{children:t},`unchanged-${n.length}`)):i.map((l,o)=>{n.push(r.jsx(s,{children:l},o)),p.push(r.jsx("div",{children:n},p.length-1)),n=[]})}return n.length>0&&p.push(r.jsx("div",{children:n},p.length-1)),p},[c,m]);return r.jsxs("div",{className:"flex flex-col",children:[r.jsxs("div",{className:"text-sm text-gray-500 flex flex-row gap-2",children:[r.jsx("span",{className:"font-bold",children:"Month:"}),r.jsx("span",{children:D.slice(0,7)}),!d.length&&r.jsx(H,{className:"text-green-500"})]}),!!d.length&&d]})},Me=({filter:c})=>{const[{data:m,fetching:D,hasNext:d}]=Q({query:q,variables:c}),p=P.useMemo(()=>m?.pcnByDate?m.pcnByDate.sort((y,g)=>g.date>y.date?1:g.date<y.date?-1:0):[],[m?.pcnByDate]);return D?r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(L,{className:"h-10 w-10 animate-spin mr-2 self-center"})}):r.jsxs("div",{className:"flex flex-col gap-4",children:[!!m&&d&&r.jsx("div",{className:"w-full h-full flex justify-center",children:r.jsx(L,{className:"h-10 w-10 animate-spin mr-2 self-center"})}),p.map((y,g)=>r.jsx(ge,{content:y.content,contentOrigin:y.diffContent,monthDate:y.date},g))]})};function be({filter:c,setFilter:m,closeModal:D}){const{control:d,handleSubmit:p,setValue:y}=X({defaultValues:{...c}}),{selectableBusinesses:g,fetching:N}=ee(),j=e=>{m(e),D()};return r.jsxs(r.Fragment,{children:[N?r.jsx("div",{children:"Loading..."}):r.jsx("div",{}),r.jsxs("form",{onSubmit:p(j),children:[r.jsx(te,{name:"businessId",control:d,defaultValue:void 0,render:({field:e,fieldState:n})=>r.jsx(ne,{...e,data:g,value:e.value,disabled:N,label:"Businesses",placeholder:"Scroll to see all options",maxDropdownHeight:160,searchable:!0,error:n.error?.message})}),r.jsx(O,{label:"From date",defaultValue:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,defaultDate:c?.fromMonthDate?new Date(c.fromMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("fromMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsx(O,{label:"To date",defaultValue:c?.toMonthDate?new Date(c.toMonthDate):new Date,defaultDate:c?.toMonthDate?new Date(c.toMonthDate):new Date,onChange:e=>{const n=new Date(e.getFullYear(),e.getMonth(),15);y("toMonthDate",S(n,"yyyy-MM-dd"))},popoverProps:{withinPortal:!0}}),r.jsxs("div",{className:"flex justify-center mt-5 gap-3",children:[r.jsx(U,{type:"submit",children:"Filter"}),r.jsx(U,{type:"button",onClick:D,children:"Cancel"})]})]})]})}function ve({filter:c,setFilter:m}){const[D,d]=P.useState(!1),{get:p,set:y}=J(),{userContext:g}=P.useContext($);function N(j){j||={businessId:g?.context.adminBusinessId??c.businessId,fromMonthDate:S(G(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")},se(j,c)||m(j)}return P.useEffect(()=>{const j=K(c??{})?null:encodeURIComponent(JSON.stringify(c)),e=p("validateReportsFilters");j!==e&&y("validateReportsFilters",j)},[c,p,y]),r.jsxs(r.Fragment,{children:[r.jsx(de,{opened:D,onClose:()=>d(!1),content:r.jsx(be,{filter:c,setFilter:N,closeModal:()=>d(!1)})}),r.jsx(U,{variant:"outline",size:"icon",className:"size-7.5",onClick:()=>d(!0),children:r.jsx(pe,{className:"size-5"})})]})}const ke=()=>{const{get:c}=J(),{setFiltersContext:m}=P.useContext(oe),D=P.useMemo(()=>{try{if(c("validateReportsFilters"))return JSON.parse(decodeURIComponent(c("validateReportsFilters")))}catch(y){console.error("Error parsing filter from URL",y)}return{fromMonthDate:S(G(new Date),"yyyy-MM-15"),toMonthDate:S(new Date,"yyyy-MM-15")}},[c]),[d,p]=P.useState(D);return P.useEffect(()=>{m(r.jsx("div",{className:"flex flex-row gap-2",children:r.jsx(ve,{filter:{...d},setFilter:p})}))},[d,m]),r.jsx(ae,{title:"Report Validations",children:r.jsx(ce,{type:"single",collapsible:!0,children:r.jsx(fe,{value:"pcn874",children:r.jsxs(re,{className:"p-4",children:[r.jsx(ue,{children:r.jsx(ie,{children:"Monthly VAT (PCN874)"})}),r.jsx(he,{children:r.jsx(le,{children:r.jsx(Me,{filter:d})})})]})})})})};export{ke as ValidateReportsScreen};
|