import{x as O,y as G,r as m,z as L,j as e,B as N,g as S,C as P,T,P as H}from"./index-B1H8BCL7.js";import{L as Y,A as z,D as M,d}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 J}from"./jspdf.es.min-BnkKWiZd.js";import"./jspdf.plugin.autotable-BG0-8GHU.js";import{F as K}from"./FileSaver.min-B0uEGt1F.js";import{T as Q}from"./TableContainer-CXAjhAg6.js";import{T as X,c as Z,b as v,a as ee}from"./TableRow-BfKE_xn9.js";import{T as s}from"./TableCell-D8CotAsC.js";import{T as te}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 a={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 Ae(){const c=O(G),h=(c==null?void 0:c.navType)==="dark"||(c==null?void 0:c.navType)==="ultra-dark",[x,y]=m.useState(null),[p,w]=m.useState(null),[n,A]=m.useState([]),[C,f]=m.useState(""),[g,R]=m.useState(0),[u,F]=m.useState(10),[k]=L(),$=()=>{if(!x||!p){f("Please select both dates.");return}f(""),k({startDate:d(x).format("YYYY-MM-DD"),endDate:d(p).format("YYYY-MM-DD")}).unwrap().then(t=>{if(t.code===200){const r=(t.list||[]).filter(o=>Number(o.discountAmount||0)>0);A(r)}else A([]),f(t.message)}).catch(()=>f("Something went wrong"))},b=n.reduce((t,r)=>t+Number(r.discountAmount||0),0),W=n.reduce((t,r)=>t+Number(r.amount||0),0),E=n.reduce((t,r)=>t+Number(r.netAmount||r.amount||0),0),_=n.slice(g*u,g*u+u),j=t=>t?d(t).format("DD MMM YYYY"):"-",l=t=>`₹ ${Number(t||0).toFixed(2)}`,I=()=>{const t=new J("landscape"),r=t.internal.pageSize.getWidth();t.setFillColor(29,78,216),t.rect(0,0,r,28,"F"),t.setFont("helvetica","bold"),t.setFontSize(14),t.setTextColor(255,255,255),t.text("DISCOUNT REPORT",14,18),t.setFontSize(9),t.setFont("helvetica","normal"),t.text(`${d(x).format("DD MMM YYYY")} - ${d(p).format("DD MMM YYYY")}  |  ${n.length} records`,r-14,18,{align:"right"}),t.autoTable({startY:34,head:[["#","Report No","Patient","Doctor","Gross Amt","Disc %","Disc Amt","Net Amt","Reason","Date"]],body:n.map((o,D)=>[D+1,o.reportNo,o.patientName||"-",o.doctorName||"-",l(o.amount),`${Number(o.discountPercent||0).toFixed(1)}%`,l(o.discountAmount),l(o.netAmount),o.discountReason||"-",j(o.createdDate)]),foot:[["","","","TOTAL",l(W),"",l(b),l(E),"",""]],headStyles:{fillColor:[29,78,216],fontSize:7},bodyStyles:{fontSize:7},footStyles:{fillColor:[248,250,252],textColor:[15,23,42],fontStyle:"bold",fontSize:7},theme:"grid",styles:{lineColor:[226,232,240],lineWidth:.3},margin:{left:10,right:10}}),t.save(`Discount_Report_${d(x).format("YYYY-MM-DD")}.pdf`)},B=()=>{const r=[["#","Report No","Patient","Doctor","Gross Amount","Discount %","Discount Amount","Net Amount","Reason","Date"].join(",")];n.forEach((o,D)=>r.push([D+1,o.reportNo,`"${o.patientName||"-"}"`,`"${o.doctorName||"-"}"`,Number(o.amount||0).toFixed(2),Number(o.discountPercent||0).toFixed(1),Number(o.discountAmount||0).toFixed(2),Number(o.netAmount||0).toFixed(2),`"${o.discountReason||"-"}"`,j(o.createdDate)].join(","))),K.saveAs(new Blob([r.join(`
`)],{type:"text/csv;charset=utf-8"}),`Discount_Report_${d(x).format("YYYY-MM-DD")}.csv`)};return e.jsxs(N,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(N,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,mb:2,alignItems:"center"},children:[e.jsx(Y,{dateAdapter:z,children:e.jsx(M,{label:"From",value:x,onChange:y,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(Y,{dateAdapter:z,children:e.jsx(M,{label:"To",value:p,onChange:w,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(S,{variant:"contained",disableElevation:!0,startIcon:e.jsx(V,{}),onClick:$,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"}),n.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outlined",size:"small",startIcon:e.jsx(q,{}),onClick:I,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"PDF"}),e.jsx(S,{variant:"outlined",size:"small",startIcon:e.jsx(U,{}),onClick:B,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"CSV"})]}),e.jsx(P,{label:`${n.length} discounted`,size:"small",sx:{backgroundColor:"#fffbeb",color:"#d97706",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}}),b>0&&e.jsx(P,{label:`₹ ${b.toFixed(2)} total discount`,size:"small",sx:{backgroundColor:"#fef3c7",color:"#d97706",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}})]}),C&&e.jsx(T,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:C}),n.length>0&&e.jsxs(Q,{component:H,variant:"outlined",sx:{borderRadius:2,borderColor:h?"rgba(255,255,255,0.08)":"#e2e8f0",boxShadow:"none"},children:[e.jsxs(X,{size:"small",children:[e.jsx(Z,{children:e.jsxs(v,{sx:{backgroundColor:h?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(s,{sx:a,children:"#"}),e.jsx(s,{sx:a,children:"Report No"}),e.jsx(s,{sx:a,children:"Patient"}),e.jsx(s,{sx:a,children:"Doctor"}),e.jsx(s,{sx:{...a,textAlign:"right"},children:"Gross Amt"}),e.jsx(s,{sx:{...a,textAlign:"right"},children:"Disc %"}),e.jsx(s,{sx:{...a,textAlign:"right"},children:"Disc Amt"}),e.jsx(s,{sx:{...a,textAlign:"right"},children:"Net Amt"}),e.jsx(s,{sx:a,children:"Reason"}),e.jsx(s,{sx:a,children:"Date"})]})}),e.jsx(ee,{children:_.map((t,r)=>e.jsxs(v,{hover:!0,sx:{"&:hover":{backgroundColor:h?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[e.jsx(s,{sx:i,children:g*u+r+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.doctorName||"-"}),e.jsx(s,{sx:{...i,textAlign:"right"},children:l(t.amount)}),e.jsxs(s,{sx:{...i,textAlign:"right",color:"#d97706"},children:[Number(t.discountPercent||0).toFixed(1),"%"]}),e.jsx(s,{sx:{...i,textAlign:"right",fontWeight:600,color:"#d97706"},children:l(t.discountAmount)}),e.jsx(s,{sx:{...i,textAlign:"right"},children:l(t.netAmount)}),e.jsx(s,{sx:{...i,color:"#64748b",maxWidth:150},children:e.jsx(T,{sx:{fontSize:"0.8125rem",color:"inherit"},noWrap:!0,children:t.discountReason||"-"})}),e.jsx(s,{sx:{...i,color:"#94a3b8"},children:j(t.createdDate)})]},t.reportNo))})]}),e.jsx(te,{component:"div",count:n.length,page:g,onPageChange:(t,r)=>R(r),rowsPerPage:u,onRowsPerPageChange:t=>{F(parseInt(t.target.value,10)),R(0)},rowsPerPageOptions:[5,10,25],sx:{borderTop:`1px solid ${h?"rgba(255,255,255,0.06)":"#f1f5f9"}`,"& .MuiTablePagination-selectLabel, & .MuiTablePagination-displayedRows":{fontSize:"0.75rem"}}})]})]})}export{Ae as default};
