import{x as B,y as I,r as f,z as L,j as e,B as T,g as R,C as D,T as z,P as H}from"./index-B1H8BCL7.js";import{L as A,A as M,D as v,d as l}from"./AdapterDayjs-Bd3f3Uku.js";import{d as V}from"./Search-B5Qac1u3.js";import{d as U}from"./FileDownloadOutlined-B1TjRPKt.js";import{d as q}from"./PictureAsPdfOutlined-CVvvjkcz.js";import{E as G}from"./jspdf.es.min-BnkKWiZd.js";import"./jspdf.plugin.autotable-BG0-8GHU.js";import{F as J}from"./FileSaver.min-B0uEGt1F.js";import{T as K}from"./TableContainer-CXAjhAg6.js";import{T as Q,c as X,b as y,a as Z}from"./TableRow-BfKE_xn9.js";import{T as s}from"./TableCell-D8CotAsC.js";import{T as ee}from"./TablePagination-CVPyh-M-.js";import"./useThemeProps-DcBTMaaC.js";import"./useThemeProps-DL_l3A7P.js";import"./Grid-CTEl0Elf.js";import"./colorManipulator-B4HuGLt1.js";import"./useSlotProps-eBp3I9mO.js";import"./InputAdornment-BMBVR6Ec.js";import"./KeyboardArrowRight-DXPl9fjq.js";import"./LastPage-BEvmfPvn.js";const r={fontSize:"0.7rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1.25,px:2,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},i={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};function Re(){const d=B(I),u=(d==null?void 0:d.navType)==="dark"||(d==null?void 0:d.navType)==="ultra-dark",[c,w]=f.useState(null),[p,F]=f.useState(null),[a,C]=f.useState([]),[P,h]=f.useState(""),[g,Y]=f.useState(0),[m,N]=f.useState(10),[k]=L(),W=()=>{if(!c||!p){h("Please select both dates.");return}h(""),k({startDate:l(c).format("YYYY-MM-DD"),endDate:l(p).format("YYYY-MM-DD")}).unwrap().then(t=>{if(t.code===200){const n=(t.list||[]).filter(o=>Number(o.refundedAmount||0)>0||o.billStatus==="refunded"||o.billStatus==="cancelled");C(n)}else C([]),h(t.message)}).catch(()=>h("Something went wrong"))},b=a.reduce((t,n)=>t+Number(n.refundedAmount||0),0),$=a.reduce((t,n)=>t+Number(n.netAmount||n.amount||0),0),E=a.slice(g*m,g*m+m),S=t=>t?l(t).format("DD MMM YYYY"):"-",x=t=>`₹ ${Number(t||0).toFixed(2)}`,O=()=>{const t=new G("landscape"),n=t.internal.pageSize.getWidth();t.setFillColor(29,78,216),t.rect(0,0,n,28,"F"),t.setFont("helvetica","bold"),t.setFontSize(14),t.setTextColor(255,255,255),t.text("REFUND REPORT",14,18),t.setFontSize(9),t.setFont("helvetica","normal"),t.text(`${l(c).format("DD MMM YYYY")} - ${l(p).format("DD MMM YYYY")}  |  ${a.length} records`,n-14,18,{align:"right"}),t.autoTable({startY:34,head:[["#","Report No","Patient","Phone","Original Amt","Refund Amt","Reason","Status","Date"]],body:a.map((o,j)=>[j+1,o.reportNo,o.patientName||"-",o.phone||"-",x(o.netAmount||o.amount),x(o.refundedAmount),o.cancellationReason||"-",o.billStatus||"-",S(o.createdDate)]),foot:[["","","","TOTAL",x($),x(b),"","",""]],headStyles:{fillColor:[29,78,216],fontSize:7.5},bodyStyles:{fontSize:7.5},footStyles:{fillColor:[254,242,242],textColor:[239,68,68],fontStyle:"bold",fontSize:7.5},theme:"grid",styles:{lineColor:[226,232,240],lineWidth:.3},margin:{left:10,right:10}}),t.save(`Refund_Report_${l(c).format("YYYY-MM-DD")}.pdf`)},_=()=>{const n=[["#","Report No","Patient","Phone","Original Amount","Refund Amount","Reason","Status","Date"].join(",")];a.forEach((o,j)=>n.push([j+1,o.reportNo,`"${o.patientName||"-"}"`,o.phone||"-",Number(o.netAmount||o.amount||0).toFixed(2),Number(o.refundedAmount||0).toFixed(2),`"${o.cancellationReason||"-"}"`,o.billStatus||"-",S(o.createdDate)].join(","))),J.saveAs(new Blob([n.join(`
`)],{type:"text/csv;charset=utf-8"}),`Refund_Report_${l(c).format("YYYY-MM-DD")}.csv`)};return e.jsxs(T,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(T,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,mb:2,alignItems:"center"},children:[e.jsx(A,{dateAdapter:M,children:e.jsx(v,{label:"From",value:c,onChange:w,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(A,{dateAdapter:M,children:e.jsx(v,{label:"To",value:p,onChange:F,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(R,{variant:"contained",disableElevation:!0,startIcon:e.jsx(V,{}),onClick:W,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(R,{variant:"outlined",size:"small",startIcon:e.jsx(q,{}),onClick:O,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"PDF"}),e.jsx(R,{variant:"outlined",size:"small",startIcon:e.jsx(U,{}),onClick:_,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"CSV"})]}),e.jsx(D,{label:`${a.length} refunds`,size:"small",sx:{backgroundColor:"#fef2f2",color:"#ef4444",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}}),b>0&&e.jsx(D,{label:`₹ ${b.toFixed(2)} refunded`,size:"small",sx:{backgroundColor:"#fef2f2",color:"#ef4444",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}})]}),P&&e.jsx(z,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:P}),a.length>0&&e.jsxs(K,{component:H,variant:"outlined",sx:{borderRadius:2,borderColor:u?"rgba(255,255,255,0.08)":"#e2e8f0",boxShadow:"none"},children:[e.jsxs(Q,{size:"small",children:[e.jsx(X,{children:e.jsxs(y,{sx:{backgroundColor:u?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(s,{sx:r,children:"#"}),e.jsx(s,{sx:r,children:"Report No"}),e.jsx(s,{sx:r,children:"Patient"}),e.jsx(s,{sx:r,children:"Phone"}),e.jsx(s,{sx:{...r,textAlign:"right"},children:"Original Amt"}),e.jsx(s,{sx:{...r,textAlign:"right"},children:"Refund Amt"}),e.jsx(s,{sx:r,children:"Reason"}),e.jsx(s,{sx:r,children:"Status"}),e.jsx(s,{sx:r,children:"Date"})]})}),e.jsx(Z,{children:E.map((t,n)=>e.jsxs(y,{hover:!0,sx:{"&:hover":{backgroundColor:u?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[e.jsx(s,{sx:i,children:g*m+n+1}),e.jsx(s,{sx:i,children:t.reportNo}),e.jsx(s,{sx:{...i,fontWeight:500},children:t.patientName||"-"}),e.jsx(s,{sx:{...i,color:"#64748b"},children:t.phone||"-"}),e.jsx(s,{sx:{...i,textAlign:"right"},children:x(t.netAmount||t.amount)}),e.jsx(s,{sx:{...i,textAlign:"right",fontWeight:600,color:"#ef4444"},children:x(t.refundedAmount)}),e.jsx(s,{sx:{...i,color:"#64748b",maxWidth:150},children:e.jsx(z,{sx:{fontSize:"0.8125rem",color:"inherit"},noWrap:!0,children:t.cancellationReason||"-"})}),e.jsx(s,{sx:i,children:e.jsx(D,{label:t.billStatus||"-",size:"small",sx:{fontSize:"0.68rem",fontWeight:600,height:20,borderRadius:"4px",backgroundColor:"#fef2f2",color:"#ef4444"}})}),e.jsx(s,{sx:{...i,color:"#94a3b8"},children:S(t.createdDate)})]},t.reportNo))})]}),e.jsx(ee,{component:"div",count:a.length,page:g,onPageChange:(t,n)=>Y(n),rowsPerPage:m,onRowsPerPageChange:t=>{N(parseInt(t.target.value,10)),Y(0)},rowsPerPageOptions:[5,10,25],sx:{borderTop:`1px solid ${u?"rgba(255,255,255,0.06)":"#f1f5f9"}`,"& .MuiTablePagination-selectLabel, & .MuiTablePagination-displayedRows":{fontSize:"0.75rem"}}})]})]})}export{Re as default};
