1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/factory-BWHjANeo.js","assets/ag-grid-react-Cvi7zz2g.js","assets/ag-grid-community-DgkugROF.js","assets/index-Chjiymov.js","assets/core-F0dFXLJB.js","assets/constants-vsKlIItW.js","assets/react-pdf-CiRvGOjn.js","assets/jspdf-D30lQ_ys.js","assets/constants-vHLx566B.css","assets/index-COM4puVY.js","assets/index-Be3QRc1T.js","assets/marker_colorbar-KdxIT3gQ.js","assets/domain-CQ9thS4r.js","assets/scatter-EWGr4fLR.js","assets/bar-c51HhJQO.js","assets/uniform_text-DVdXb7dv.js","assets/plot-BIp8QPNu.js"])))=>i.map(i=>d[i]); 2import{j as t}from"./react-pdf-CiRvGOjn.js";import{r as a,h as ee}from"./ag-grid-react-Cvi7zz2g.js";import{l as oe}from"./loadPlotlyTreemap-DujRodrq.js";import{f as h,k as L,T as A,O as T,W as M,$ as V,a0 as ie,a1 as le,a2 as de,V as ce}from"./index-BeCDJ2GY.js";import{C as ue,a as me}from"./CardContent-GKLn5Lh1.js";import{P as fe}from"./ProgressBarCellRenderer-CokuxPPG.js";import{_ as D}from"./jspdf-D30lQ_ys.js";import{l as he}from"./loadPlotlyPie-BZSo_6bg.js";import{u as pe}from"./useFetchVendors-s7UUcBM1.js";import{A as K}from"./Autocomplete-BdHFHlqd.js";import{M as X}from"./MenuItem-BooRt6AV.js";import{G as z}from"./Grid-BBMrhGf-.js";import{T as xe,a as q}from"./Tabs-DVjYnumP.js";import"./ag-grid-community-DgkugROF.js";import"./ag-grid-enterprise-BRKZrOzu.js";import"./ag-charts-B9701BJR.js";import"./microsoft-BQSsBj1o.js";import"./Chip-RgG0-0Mv.js";import"./KeyboardArrowRight-DX6dh-af.js";const ye=({purchaseOrders:e,loading:r,error:n,onLoaded:i})=>{const[u,c]=a.useState(null);a.useEffect(()=>{let o=!0;return oe().then(s=>{o&&c(()=>s)}),()=>{o=!1}},[]);const l=a.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return null;const o=e.reduce((x,p)=>{if(!p?.vendorname||p?.netamount===void 0)return x;const d=p.vendorname,m=Number(p.netamount)||0;return x[d]=(x[d]||0)+m,x},{}),s=Object.keys(o);if(s.length===0)return null;const f=["Root",...s],P=["",...s.map(()=>"Root")],j=[0,...s.map(x=>o[x])];return{data:[{type:"treemap",labels:f,parents:P,values:j,textinfo:"label+value+percent parent+percent entry",outsidetextfont:{size:18,color:"#377eb8"},marker:{line:{width:2}},pathbar:{visible:!1}}],layout:{title:"Purchase Orders by Vendor",autosize:!0,paper_bgcolor:"rgba(0,0,0,0)",plot_bgcolor:"rgba(0,0,0,0)",margin:{l:10,r:10,b:10,t:40}},config:{responsive:!0,displaylogo:!1}}},[e]);return a.useEffect(()=>{!r&&u&&i?.()},[r,u,i]),r||!u?t.jsx(h,{sx:{height:580,width:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:t.jsx(L,{})}):t.jsx(h,{sx:{height:580,width:"100%",display:"flex",justifyContent:"center"},children:t.jsx(ue,{sx:{width:"100%",boxShadow:"none",borderRadius:2},children:t.jsxs(me,{sx:{height:"100%"},children:[t.jsx(A,{variant:"h6",gutterBottom:!0,children:"Vendor Purchase Orders"}),n?t.jsx(A,{color:"error",children:"Error loading purchase orders."}):l?t.jsx(h,{sx:{width:"100%",height:500,minHeight:500},children:t.jsx(u,{data:l.data,layout:l.layout,config:l.config,useResizeHandler:!0,style:{width:"100%",height:"100%"}})}):t.jsx(A,{children:"No data available."})]})})})},w=e=>{const r=Number(e.value||0);return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(r)},ge=({purchaseOrders:e,loading:r,error:n,onLoaded:i})=>{const u=a.useRef(!1);a.useEffect(()=>{!r&&Array.isArray(e)&&!u.current&&(u.current=!0,i?.())},[r,e,i]);const c=a.useMemo(()=>({flex:1,minWidth:300,filter:!0,sortable:!0,resizable:!0}),[]),l=a.useMemo(()=>[{headerName:"Subsidiary",field:"subsidiaryname",hide:!0,enableRowGroup:!0,rowGroup:!0},{headerName:"Net Amount",field:"netamount",valueFormatter:w,aggFunc:"sum",enableValue:!0},{headerName:"Quantity Billed",field:"quantitybilled",valueFormatter:w,aggFunc:"sum",enableValue:!0},{headerName:"PO Over/Under",field:"valOverUnder",valueGetter:o=>{if(!o.data||o.data.quantitybilled===void 0||o.data.netamount===void 0)return 0;const s=o.data.quantitybilled??0,f=o.data.netamount??0;return f!==0?s-f:0},valueFormatter:w,cellStyle:o=>o.value<0?{color:"#00BBA1",fontWeight:"bold"}:o.value>0?{color:"#FF594B",fontWeight:"bold"}:null,enableRowGroup:!0,aggFunc:"sum",enableValue:!0},{headerName:"% Billed",field:"pctBilled",cellRenderer:fe,valueGetter:o=>{if(!o.node.group&&o.data){const s=o.data.quantitybilled??0,f=o.data.netamount??0;return f!==0?s/f*100:0}return 0},aggFunc:o=>{let s=0,f=0;return Array.isArray(o.rowNode.allLeafChildren)&&o.rowNode.allLeafChildren.forEac
2h(P=>{s+=P.data?.quantitybilled??0,f+=P.data?.netamount??0}),f!==0?s/f*100:0},enableValue:!0},{headerName:"Total Unbilled",field:"unbilled",valueFormatter:w,cellStyle:o=>o.value>0?{color:"#00BBA1",fontWeight:"bold"}:o.value<0?{color:"#FF594B",fontWeight:"bold"}:null,aggFunc:"sum",enableValue:!0},{headerName:"Total Accrued",field:"totalaccruedamount",valueFormatter:w,aggFunc:"sum",enableValue:!0},{headerName:"Tax Amount",field:"taxamount",valueFormatter:w,aggFunc:"sum",enableValue:!0},{headerName:"AFE Number",field:"afenumber"},{headerName:"AFE Name",field:"afename"},{headerName:"Purchase Order Date",field:"trandate"},{headerName:"Required By Date",field:"requiredbydate"},{headerName:"Vendor",field:"vendorname"},{headerName:"Purchase Order Status",field:"transactionstatus",rowGroup:!0,enableRowGroup:!0},{headerName:"Purchase Order",field:"trandisplayname",rowGroup:!0,enableRowGroup:!0},{headerName:"Acct Number",field:"acctnumber"},{headerName:"Acct Type",field:"accttype"},{headerName:"Acct Name",field:"accountsearchdisplayname"},{headerName:"Memo",field:"memo"},{headerName:"AFE is Complete",field:"iscomplete",sortable:!0,filter:!0,enableRowGroup:!0,pivot:!0,hide:!0}],[]);return r?t.jsxs(h,{sx:{textAlign:"center",p:3},children:[t.jsx(L,{}),t.jsx(A,{variant:"h6",children:"Loading Data..."})]}):n?t.jsx(h,{sx:{textAlign:"center",color:"error.main",p:3},children:t.jsxs(A,{variant:"h6",children:["Error: ",n]})}):t.jsx(h,{className:"ag-theme-alpine",sx:{width:"100%"},children:t.jsx(ee,{columnDefs:l,rowData:e,defaultColDef:c,rowGroupPanelShow:"always",sideBar:"filters",domLayout:"autoHeight"})})},be=e=>e?.name==="CanceledError"||T.isCancel?.(e),ve=()=>{const[e,r]=a.useState(!1),[n,i]=a.useState(null);return{fetchProjectAudits:a.useCallback(async c=>{try{r(!0),i(null);const l=await T.get("/api/Audit/project-audits",{signal:c});return Array.isArray(l.data)?l.data:[]}catch(l){if(be(l)||c?.aborted)return[];const o=l?.response?.data?.message||l?.message||"An error occurred while fetching project audits.";throw i(o),l}finally{c?.aborted||r(!1)}},[]),loadingFetchProjectAudits:e,errorFetchProjectAudits:n}},Pe=({onLoaded:e})=>{const{fetchProjectAudits:r,loadingFetchProjectAudits:n,errorFetchProjectAudits:i}=ve(),[u,c]=a.useState([]);a.useEffect(()=>{const s=new AbortController;return(async()=>{try{const P=await r(s.signal);if(s.signal.aborted)return;c(P),e?.()}catch(P){s.signal.aborted||console.error("Error fetching project audits:",P)}})(),()=>{s.abort()}},[r,e]);const l=a.useMemo(()=>[{headerName:"Project Name",field:"projectName",editable:!1},{headerName:"Table Name",field:"tableName",editable:!1},{headerName:"Column Name",field:"columnName",editable:!1},{headerName:"Row Id",field:"rowId",editable:!1},{headerName:"Old Value",field:"oldValue",editable:!1},{headerName:"New Value",field:"newValue",editable:!1},{headerName:"Date Modified",field:"lastModifiedDate_CST",editable:!1},{headerName:"Date Day Modified",field:"lastModifiedDay",editable:!1},{headerName:"Modified By",field:"name",editable:!1}],[]),o=a.useMemo(()=>({sortable:!0,filter:!0,resizable:!0,minWidth:160}),[]);return t.jsx(h,{children:n?t.jsxs(h,{sx:{textAlign:"center",p:3},children:[t.jsx(L,{}),t.jsx(A,{variant:"h6",children:"Loading Data..."})]}):i?t.jsx(h,{sx:{textAlign:"center",color:"error.main",p:3},children:t.jsxs(A,{variant:"h6",children:["Error: ",i]})}):t.jsx(M,{children:t.jsx(h,{className:"ag-theme-alpine",sx:{height:"100vh",width:"100%"},children:t.jsx(ee,{columnDefs:l,rowData:u,defaultColDef:o})})})})};let U;const I=e=>e?.default??e,je=e=>{const r=I(e);return I(r)};function Ae(){return U||(U=Promise.all([D(()=>import("./factory-BWHjANeo.js").then(e=>e.f),__vite__mapDeps([0,1,2,3])),D(()=>import("./core-F0dFXLJB.js").then(e=>e.c),__vite__mapDeps([4,1,2,5,6,7,8,9,10,11,12])),D(()=>import("./scatter-EWGr4fLR.js").then(e=>e.s),__vite__mapDeps([13,1,2,10,5,6,7,8,9,11]))]).then(([e,r,n])=>{const i=je(e),u=I(r),c=I(n);if(typeof i!="function")throw new TypeError("react-plotly.js/factory did not resolve to a function.");return u.register([c]),i(u)})),U}const Ce=e=>{if(!e)return"";if(typeof e=="string")return e;const r=e?.response?.data;return typeof r=="string"?r:typeof r?.message=="string"?r.message:typeof r?.detail=="string"?r.detail:typeof r?.title=="string"?r.title:e?.message||"An unexpected error occurred."},Ne=({title:e,message:r="No data available for current filters.",height:n=400})=>t.jsxs(h,{sx:{width:"100%",height:n},children:[t.jsx(A,{variant:"h6",sx:{fontSize:18,fontWeight:500,textAlign:"center",mb:2},children:e}),t.jsx(h,{sx:{height:`calc(${typeof n=="number"?`${n}px`:n} - 56px)`,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed",borderColor:"divider",borderRadius:2,px:2},children:t.jsx(A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:r})})]}),Se=({data:e,loading:r,error:n,onLoaded:i,setHoveredPeriod:u})=>{const[c,l]=a.useState(null);a.useEffect(()=>{let j=!0;return Ae().then(x=>{j&&l(()=>x)}),()=>{j=!1}},[]);const o="Late Payments vs On-Time Payments Over Payment Period",s=a.useMemo(()=>
2{if(!Array.isArray(e)||e.length===0)return null;const x=[...e].sort((d,m)=>(d.paymentDatePeriodEpoch??0)-(m.paymentDatePeriodEpoch??0)).reduce((d,{paymentDatePeriod:m,lateOnTime:y})=>{if(!m)return d;d[m]||(d[m]={Late:0,OnTime:0,Total:0});const b=String(y||"").toLowerCase();return b==="late payment"?d[m].Late+=1:b==="on time"&&(d[m].OnTime+=1),d[m].Total+=1,d},{}),p=Object.keys(x);return p.length===0?null:[{x:p,y:p.map(d=>x[d].Total),type:"scatter",mode:"lines",name:"Total Payments",fill:"tozeroy",line:{shape:"spline",color:"#CFC6C6",smoothing:.8},opacity:.8,hoverinfo:"x+y+name"},{x:p,y:p.map(d=>x[d].Late),type:"scatter",mode:"lines+markers",name:"Late Payments",marker:{color:"#0E2756"},line:{shape:"spline",smoothing:.8},hoverinfo:"x+y+name"},{x:p,y:p.map(d=>x[d].OnTime),type:"scatter",mode:"lines+markers",name:"On Time Payments",marker:{color:"#B0C3E5"},line:{shape:"spline",smoothing:.8},hoverinfo:"x+y+name"}]},[e]);a.useEffect(()=>{!r&&c&&i?.()},[r,c,i]);const f=a.useMemo(()=>({title:{text:o,font:{size:18}},xaxis:{title:{text:"Payment Date Period"},type:"category"},yaxis:{title:{text:"Number of Payments"}},showlegend:!0,autosize:!0,margin:{r:100},legend:{orientation:"v",x:1.05,y:1,xanchor:"center"},hovermode:"x unified"}),[]),P=a.useMemo(()=>({responsive:!0,displaylogo:!1,modeBarButtonsToRemove:["zoom2d","pan2d","select2d","lasso2d"],displayModeBar:"hover"}),[]);return r||!c?t.jsx(h,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:t.jsx(L,{})}):n?t.jsxs(A,{color:"error",variant:"body2",children:["Error: ",Ce(n)]}):s?t.jsx(h,{sx:{width:"100%",height:600},children:t.jsx(c,{data:s,layout:f,config:P,useResizeHandler:!0,style:{width:"100%",height:"100%"},onHover:j=>{const x=j?.points?.[0]?.x;u?.(x)},onUnhover:()=>{u?.(null)}})}):t.jsx(Ne,{title:o,message:"No data available for the selected date range and filters.",height:600})},Le=e=>{if(!e)return"";if(typeof e=="string")return e;const r=e?.response?.data;return typeof r=="string"?r:typeof r?.message=="string"?r.message:typeof r?.detail=="string"?r.detail:typeof r?.title=="string"?r.title:e?.message||"An unexpected error occurred."},Ee=e=>{if(!e)return"Latest Period";const[r,n]=String(e).split("-"),i=new Date(Number(r),Number(n)-1);return Number.isNaN(i.getTime())?String(e):i.toLocaleDateString("en-US",{month:"long",year:"numeric"})},we=({title:e,message:r="No data available for current filters.",height:n=400})=>t.jsxs(h,{sx:{width:"100%",height:n},children:[t.jsx(A,{variant:"h6",sx:{fontSize:18,fontWeight:500,textAlign:"center",mb:2},children:e}),t.jsx(h,{sx:{height:`calc(${typeof n=="number"?`${n}px`:n} - 56px)`,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed",borderColor:"divider",borderRadius:2,px:2},children:t.jsx(A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:r})})]}),De=({data:e,loading:r,error:n,chartTitle:i="Late vs On-Time Payments: ",onLoaded:u,hoveredPeriod:c})=>{const[l,o]=a.useState(null);a.useEffect(()=>{let p=!0;return he().then(d=>{p&&o(()=>d)}),()=>{p=!1}},[]);const{chartData:s,usedPeriod:f}=a.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return{chartData:null,usedPeriod:null};let p=c;p||(p=e.filter(N=>N.paymentDatePeriodEpoch).sort((N,v)=>(v.paymentDatePeriodEpoch??0)-(N.paymentDatePeriodEpoch??0))[0]?.paymentDatePeriod);const m=(p?e.filter(b=>b.paymentDatePeriod===p):e).reduce((b,{lateOnTime:N})=>{const v=String(N||"").toLowerCase();return v==="late payment"?b["Late Payment"]+=1:v==="on time"&&(b["On Time"]+=1),b},{"Late Payment":0,"On Time":0});return m["Late Payment"]+m["On Time"]===0?{chartData:null,usedPeriod:p}:{usedPeriod:p,chartData:[{labels:Object.keys(m),values:Object.values(m),type:"pie",name:i,marker:{colors:["#0E2756","#B0C3E5"]},hoverinfo:"label+percent+value",textinfo:"label+percent"}]}},[e,c,i]);a.useEffect(()=>{!r&&l&&u?.()},[r,l,u]);const P=f?`${i} ${Ee(f)}`:i,j=a.useMemo(()=>({title:{text:P,font:{size:18}},margin:{l:10,r:10,t:80,b:10},showlegend:!0,autosize:!0,legend:{orientation:"v",x:1.05,y:1,xanchor:"center"}}),[P]),x=a.useMemo(()=>({responsive:!0,displaylogo:!1,displayModeBar:"hover",modeBarButtonsToRemove:["zoom2d","pan2d","select2d","lasso2d"]}),[]);return r||!l?t.jsx(h,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:t.jsx(L,{})}):n?t.jsxs(A,{color:"error",variant:"body2",children:["Error: ",Le(n)]}):s?t.jsx(h,{sx:{width:"100%",height:400},children:t.jsx(l,{data:s,layout:j,config:x,useResizeHandler:!0,style:{width:"100%",height:"100%"}})}):t.jsx(we,{title:P,message:"No data available for the selected date range and filters.",height:400})};let H;const $=e=>e?.default??e,Te=e=>{const r=$(e);return $(r)};function te(){return H||(H=Promise.all([D(()=>import("./factory-BWHjANeo.js").then(e=>e.f),__vite__mapDeps([0,1,2,3])),D(()=>import("./core-F0dFXLJB.js").then(e=>e.c),__vite__mapDeps([4,1,2,5,6,7,8,9,10,11,12])),D(()=>import("./bar-c51HhJQO.js").then(e=>e.b),__vite__mapDeps([14,1,2,15,5,6,7,8,9,11,16]))]).then(([e,r,n])=>
2{const i=Te(e),u=$(r),c=$(n);if(typeof i!="function")throw new TypeError("react-plotly.js/factory did not resolve to a function.");return u.register([c]),i(u)})),H}const Oe=e=>{if(!e)return"";if(typeof e=="string")return e;const r=e?.response?.data;return typeof r=="string"?r:typeof r?.message=="string"?r.message:typeof r?.detail=="string"?r.detail:typeof r?.title=="string"?r.title:e?.message||"An unexpected error occurred."},Fe=({title:e,message:r="No data available for current filters.",height:n=400})=>t.jsxs(h,{sx:{width:"100%",height:n},children:[t.jsx(A,{variant:"h6",sx:{fontSize:18,fontWeight:500,textAlign:"center",mb:2},children:e}),t.jsx(h,{sx:{height:`calc(${typeof n=="number"?`${n}px`:n} - 56px)`,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed",borderColor:"divider",borderRadius:2,px:2},children:t.jsx(A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:r})})]}),ze=({data:e,loading:r,error:n,onLoaded:i,setHoveredPeriod:u,chartTitle:c="Late vs On-Time Payments by Per
2iod"})=>{const[l,o]=a.useState(null);a.useEffect(()=>{let j=!0;return te().then(x=>{j&&o(()=>x)}),()=>{j=!1}},[]);const s=a.useMemo(()=>{if(!Array.isArray(e)||e.length===0)return null;const x=[...e].sort((y,b)=>(y.paymentDatePeriodEpoch??0)-(b.paymentDatePeriodEpoch??0)).reduce((y,{paymentDatePeriod:b,lateOnTime:N})=>{if(!b)return y;y[b]||(y[b]={Late:0,OnTime:0,Total:0});const v=String(N||"").toLowerCase();return v==="late payment"?y[b].Late+=1:v==="on time"&&(y[b].OnTime+=1),y[b].Total+=1,y},{}),p=Object.keys(x);if(p.length===0)return null;const d=p.map(y=>{const b=x[y].Total||1;return Number((x[y].Late/b*100).toFixed(2))}),m=p.map(y=>{const b=x[y].Total||1;return Number((x[y].OnTime/b*100).toFixed(2))});return[{x:p,y:d,type:"bar",name:"Percent Late (%)",marker:{color:"#0E2756"},text:d.map(y=>`${y}%`),textposition:"auto",hovertemplate:"Percent Late: %{text}<extra></extra>"},{x:p,y:m,type:"bar",name:"Percent On Time (%)",marker:{color:"#B0C3E5"},text:m.map(y=>`${y}%`),textposition:"auto",hovertemplate:"Percent On Time: %{text}<extra></extra>"}]},[e]);a.useEffect(()=>{!r&&l&&i?.()},[r,l,i]);const f=a.useMemo(()=>({title:{text:c,font:{size:18}},xaxis:{title:{text:"Payment Date Period"},type:"category"},yaxis:{title:{text:"Percent On Time | Late (%)"}},barmode:"stack",autosize:!0,margin:{r:100},bargap:.3,showlegend:!0,legend:{orientation:"v",x:1.05,y:1,xanchor:"center"},hovermode:"x unified"}),[c]),P=a.useMemo(()=>({responsive:!0,displaylogo:!1,modeBarButtonsToRemove:["zoom2d","pan2d","select2d","lasso2d"],displayModeBar:"hover"}),[]);return r||!l?t.jsx(h,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:t.jsx(L,{})}):n?t.jsxs(A,{color:"error",variant:"body2",children:["Error: ",Oe(n)]}):s?t.jsx(h,{sx:{width:"100%",height:600},children:t.jsx(l,{data:s,layout:f,config:P,useResizeHandler:!0,style:{width:"100%",height:"100%"},onHover:j=>{const x=j?.points?.[0]?.x;u?.(x)},onUnhover:()=>{u?.(null)}})}):t.jsx(Fe,{title:c,message:"No data available for the selected date range and filters.",height:600})},Me=e=>{if(!e)return"";if(typeof e=="string")return e;const r=e?.response?.data;return typeof r=="string"?r:typeof r?.message=="string"?r.message:typeof r?.detail=="string"?r.detail:typeof r?.title=="string"?r.title:e?.message||"An unexpected error occurred."},Be=e=>{if(!e)return"Latest Period";const[r,n]=String(e).split("-"),i=new Date(Number(r),Number(n)-1);return Number.isNaN(i.getTime())?String(e):i.toLocaleDateString("en-US",{month:"long",year:"numeric"})},_e=({title:e,message:r="No data available for current filters.",height:n=400})=>t.jsxs(h,{sx:{width:"100%",height:n},children:[t.jsx(A,{variant:"h6",sx:{fontSize:18,fontWeight:500,textAlign:"center",mb:2},children:e}),t.jsx(h,{sx:{height:`calc(${typeof n=="number"?`${n}px`:n} - 56px)`,display:"flex",alignItems:"center",justifyContent:"center",border:"1px dashed",borderColor:"divider",borderRadius:2,px:2},children:t.jsx(A,{variant:"body2",sx:{color:"text.secondary",textAlign:"center"},children:r})})]}),Re=({data:e,loading:r,error:n,onLoaded:i,hoveredPeriod:u,setLatestPeriod:c})=>{const[l,o]=a.useState(null);a.useEffect(()=>{let d=!0;return te().then(m=>{d&&o(()=>m)}),()=>{d=!1}},[]);const s=a.useMemo(()=>!Array.isArray(e)||e.length===0?null:e.filter(m=>m.paymentDatePeriodEpoch).sort((m,y)=>(y.paymentDatePeriodEpoch??0)-(m.paymentDatePeriodEpoch??0))[0]?.paymentDatePeriod??null,[e]);a.useEffect(()=>{s&&c?.(s)},[s,c]),a.useEffect(()=>{!r&&l&&i?.()},[r,l,i]);const f=u||s,P=`Late Payments Binned for: ${Be(f)}`,j=a.useMemo(()=>{if(!f||!Array.isArray(e)||e.length===0)return null;const d=e.filter(v=>v.paymentDatePeriod===f&&String(v.lateOnTime||"").toLowerCase()==="late payment");if(d.length===0)return null;const m=["Invoices","Approvals","Payments"],y=[d.filter(v=>v.invoiceProcessing==="Invoice Processing On Time").length,d.filter(v=>v.approvals==="Approval On Time").length,d.filter(v=>v.paymentProcessing==="Payment processed on Time").length],b=[d.filter(v=>v.invoiceProcessing==="Late Invoice Processing").length,d.filter(v=>v.approvals==="Late Approval").length,d.filter(v=>v.paymentProcessing==="Payment Processing Delays").length];return[...b,...y].reduce((v,E)=>v+E,0)===0?null:[{x:m,y:b,type:"bar",name:"Late",marker:{color:"#112856"},text:b.map(String),textposition:"auto",showlegend:!0,hovertemplate:"Late: %{text}<extra></extra>"},{x:m,y,type:"bar",name:"On Time",marker:{color:"#B0C3E5"},text:y.map(String),textposition:"auto",showlegend:!0,hovertemplate:"On Time: %{text}<extra></extra>"}]},[f,e]),x=a.useMemo(()=>({title:{text:P,font:{size:18}},xaxis:{title:{text:"Processing Stages"}},yaxis:{title:{text:"Number of Payments"}},bargap:.3,barmode:"stack",autosize:!0,margin:{r:100},legend:{orientation:"v",x:1.05,y:1,xanchor:"center"},hovermode:"x unified"}),[P]),p=a.useMemo(()=>({responsive:!0,displaylogo:!1,modeBarButtonsToRemove:["zoom2d","pan2d","select2d","lasso2d"],displayModeBar:"hover"}),[]);return r||!l?t.jsx(h,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:300},children:t.jsx(L,{size:28})}):n?t.jsxs(A,{color:"error",variant:"body2",children:["Error: ",Me(n)]}):j?t.jsx(h,{sx:{width:"100%",height:400},children:t.jsx(l,{data:j,layout:x,config:p,useResizeHandler:!0,style:{width:"100%",height:"100%"}})}):t.jsx(_e,{title:P,message:"No data available for the selected date range and filters.",height:400})},ke=e=>e?.name==="CanceledError"||T.isCancel?.(e),Ve=e=>(Array.isArray(e)?e:[]).map(r=>({...r,invoiceProcessing:r.invoiceProcessing??r.invoiceProcessingStatus,approvals:r.approvals??r.approvalStatus,paymentProcessing:r.paymentProcessing??r.paymentProcessingStatus})),Ie=()=>{const[e,r]=a.useState(!1),[n,i]=a.useState(null),u=a.useCallback(async(l,{normalizeForCharts:o=!1}={})=>{try{r(!0),i(null);const s=await T.get("/api/LandingWarehouse/NetSuite/SavedSearch/LatePayments",{signal:l}),f=Array.isArray(s.data)?s.data:[];return o?Ve(f):f}catch(s){if(ke(s)||l?.aborted)return[];const f=s instanceof Error?s.message:"An error occurred";throw i(f),s}finally{l?.aborted||r(!1)}},[]),c=a.useCallback(l=>u(l,{normalizeForCharts:!0}),[u]);return{fetchLatePayments:u,fetchLatePaymentsForPie:c,loadingLatePayments:e,errorLatePayments:n}},$e={line:!1,pie:!1,bar:!1,status:!1},Y=e=>e?.name??e?.vendorName??e?.vendorname??e?.companyName??"",Z=e=>e?.subsidiary??e?.subsidiaryName??e?.subsidiaryname??e?.subsidiaryfullname??"",We=({onLoaded:e})=>{const{fetchLatePayments:r,loadingLatePayments:n,errorLatePayments:i}=Ie(),{fetchVendorData:u}=pe(),[c,l]=a.useState([]),[o,s]=a.useState(null),[,f]=a.useState(null),[P,j]=a.useState([]),[x,p]=a.use
2State([]),[d,m]=a.useState([]),[y,b]=a.useState([]),[N,v]=a.useState(""),[E,Q]=a.useState(""),[B,J]=a.useState(""),[Qe,re]=a.useState($e),_=a.useCallback(g=>{re(C=>{if(C[g])return C;const S={...C,[g]:!0};return Object.values(S).every(Boolean)&&setTimeout(()=>e?.(),0),S})},[e]);a.useEffect(()=>{const g=new AbortController;return(async()=>{try{const S=await r(g.signal,{normalizeForCharts:!0});if(g.signal.aborted)return;const O=Array.isArray(S)?S:[];l(O);const k=await u();if(g.signal.aborted)return;const W=(Array.isArray(k)?k:[]).map(F=>F?.companyName).filter(Boolean),G=O.map(F=>Y(F)).filter(Boolean);j([...new Set([...W,...G])].sort());const se=O.map(F=>Z(F)).filter(Boolean);p([...new Set(se)].sort())}catch(S){g.signal.aborted||console.error("Error loading payment analysis data:",S)}})(),()=>{g.abort()}},[r]);const ae=a.useMemo(()=>{const g=new Set;return c.forEach(C=>{C?.terms&&g.add(C.terms)}),[...g].sort()},[c]),R=a.useMemo(()=>c.filter(g=>{const C=g?.paymentDate?new Date(g.paymentDate):null,S=N?C&&C>=new Date(N):!0,O=E?C&&C<=new Date(E):!0,k=d.length===0||d.includes(Y(g)),W=y.length===0||y.includes(Z(g)),G=B?g?.terms===B:!0;return S&&O&&k&&W&&G}),[c,N,E,d,y,B]),ne=()=>{v(""),Q(""),m([]),b([]),J(""),s(null)};return t.jsxs(h,{sx:{p:3},children:[t.jsxs(h,{sx:{display:"flex",flexWrap:"wrap",gap:2,mb:3,alignItems:"center"},children:[t.jsx(V,{label:"Start Date",type:"date",size:"small",value:N,onChange:g=>v(g.target.value),slotProps:{inputLabel:{shrink:!0}}}),t.jsx(V,{label:"End Date",type:"date",size:"small",value:E,onChange:g=>Q(g.target.value),slotProps:{inputLabel:{shrink:!0}}}),t.jsx(K,{multiple:!0,size:"small",options:P,value:d,onChange:(g,C)=>m(C),renderInput:g=>t.jsx(V,{...g,variant:"outlined",label:"Vendors",placeholder:"Select Vendors",size:"small"}),sx:{minWidth:300}}),t.jsx(K,{multiple:!0,size:"small",options:x,value:y,onChange:(g,C)=>b(C),renderInput:g=>t.jsx(V,{...g,variant:"outlined",label:"Subsidiaries",placeholder:"Select Subsidiaries",size:"small"}),sx:{minWidth:300}}),t.jsxs(ie,{size:"small",sx:{minWidth:180},children:[t.jsx(le,{id:"payment-terms-label",children:"Terms"}),t.jsxs(de,{labelId:"payment-terms-label",label:"Terms",value:B,onChange:g=>J(g.target.value),children:[t.jsx(X,{value:"",children:"All"}),ae.map(g=>t.jsx(X,{value:g,children:g},g))]})]}),t.jsx(ce,{variant:"outlined",onClick:ne,size:"small",sx:{height:40},children:"Clear Filters"})]}),t.jsxs(z,{container:!0,spacing:2,children:[t.jsx(z,{size:{xs:12,md:6},children:t.jsx(M,{sx:{p:2,height:"100%"},children:t.jsx(Se,{data:R,loading:n,error:i,onLoaded:()=>_("line"),setHoveredPeriod:s})})}),t.jsx(z,{size:{xs:12,md:6},children:t.jsx(M,{sx:{p:2,height:"100%"},children:t.jsx(De,{data:R,loading:n,error:i,onLoaded:()=>_("pie"),hoveredPeriod:o})})}),t.jsx(z,{size:{xs:12,md:6},children:t.jsx(M,{sx:{p:2,height:"100%"},children:t.jsx(ze,{data:R,loading:n,error:i,onLoaded:()=>_("bar"),setHoveredPeriod:s})})}),t.jsx(z,{size:{xs:12,md:6},children:t.jsx(M,{sx:{p:2,height:"100%"},children:t.jsx(Re,{data:R,loading:n,error:i,hoveredPeriod:o,setLatestPeriod:f,onLoaded:()=>_("status")})})})]})]})},Ge=e=>e?.name==="CanceledError"||T.isCancel?.(e),qe=()=>{const[e,r]=a.useState([]),[n,i]=a.useState(!1),[u,c]=a.useState(null),l=a.useCallback(async o=>{i(!0),c(null);try{const s=await T.get("/api/LandingWarehouse/Netsuite/ExecutiveSummary",{signal:o}),f=Array.isArray(s.data)?s.data:[];return o?.aborted||r(f),f}catch(s){return Ge(s)||o?.aborted?[]:(console.error("Error fetching purchase orders:",s),c("Failed to fetch purchase orders"),r([]),[])}finally{o?.aborted||i(!1)}},[]);return a.useEffect(()=>{const o=new AbortController;return l(o.signal),()=>{o.abort()}},[l]),{purchaseOrders:e,loading:n,error:u,refetch:l}},Ue=()=>{const e=()=>{window.dispatchEvent(new Event("resize"))};window.requestAnimationFrame(()=>{e(),window.requestAnimationFrame(()=>{e()})}),[50,150,300,600].forEach(r=>{window.setTimeout(e,r)})},He=["treeMap","grid","payment","audit"];function ht(){const[e,r]=a.useState(0),{purchaseOrders:n,loading:i,error:u}=qe(),[c,l]=a.useState({}),o=a.useMemo(()=>He.every(d=>c[d]),[c]),s=a.useCallback(d=>{l(m=>m[d]?m:{...m,[d]:!0})},[]),f=a.useCallback(()=>{s("treeMap")},[s]),P=a.useCallback(()=>{s("grid")},[s]),j=a.useCallback(()=>{s("payment")},[s]),x=a.useCallback(()=>{s("audit")},[s]),p=(d,m)=>{r(m),m===1&&Ue()};return t.jsxs(h,{sx:{width:"100%",p:"20px",position:"relative"},children:[t.jsx(h,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2}
2,children:t.jsxs(xe,{value:e,onChange:p,variant:"scrollable",scrollButtons:"auto",sx:{minWidth:0,"& .MuiTab-root":{minWidth:"180px",fontSize:"16px",p:"12px 20px",textTransform:"none"},"& .MuiTabs-indicator":{height:"4px",borderRadius:"2px"}},children:[t.jsx(q,{label:"Overview"}),t.jsx(q,{label:"Procurement Payment Process Analysis"}),t.jsx(q,{label:"Pirate Audits"})]})}),!o&&t.jsxs(h,{sx:{position:"fixed",inset:0,zIndex:2e3,width:"100vw",height:"100vh",bgcolor:"rgba(255, 255, 255, 0.5)",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"},children:[t.jsx(A,{variant:"h6",sx:{mb:2,color:"text.secondary"},children:"Loading PO Summary, Please Standby"}),t.jsx(L,{size:60,thickness:5})]}),t.jsxs(h,{sx:{visibility:o?"visible":"hidden"},children:[t.jsxs(h,{hidden:e!==0,children:[t.jsx(ye,{purchaseOrders:n,loading:i,error:u,onLoaded:f}),t.jsx(ge,{purchaseOrders:n,loading:i,error:u,onLoaded:P})]}),t.jsx(h,{hidden:e!==1,children:t.jsx(We,{onLoaded:j})}),t.jsx(h,{hidden:e!==2,children:t.jsx(Pe,{onLoaded:x})})]})]})}export{ht as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.