import{x as w,y as k,r as f,z as W,R as O,j as e,B as Y,g as p,C as E,T as B,P}from"./index-B1H8BCL7.js";import{d as a,L as S,A as C,D as M}from"./AdapterDayjs-Bd3f3Uku.js";import{d as _}from"./Search-B5Qac1u3.js";import{d as N}from"./FileDownloadOutlined-B1TjRPKt.js";import{d as $}from"./PictureAsPdfOutlined-CVvvjkcz.js";import{E as I}from"./jspdf.es.min-BnkKWiZd.js";import"./jspdf.plugin.autotable-BG0-8GHU.js";import{F as L}from"./FileSaver.min-B0uEGt1F.js";import{T as G}from"./TableContainer-CXAjhAg6.js";import{T as H,c as V,b,a as U}from"./TableRow-BfKE_xn9.js";import{T as n}from"./TableCell-D8CotAsC.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";const c={fontSize:"0.7rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1.25,px:2,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},r={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};function xt(){const x=w(k),u=(x==null?void 0:x.navType)==="dark"||(x==null?void 0:x.navType)==="ultra-dark",[m,T]=f.useState(null),[g,v]=f.useState(null),[A,j]=f.useState([]),[D,h]=f.useState(""),[F]=W(),y=()=>{if(!m||!g){h("Please select both dates.");return}h(""),F({startDate:a(m).format("YYYY-MM-DD"),endDate:a(g).format("YYYY-MM-DD")}).unwrap().then(t=>{t.code===200?j(t.list||[]):(j([]),h(t.message))}).catch(()=>h("Something went wrong"))},d=O.useMemo(()=>{const t={};return A.forEach(s=>{const o=s.createdDate?a(s.createdDate).format("DD MMM YYYY"):"Unknown";t[o]||(t[o]={date:o,bills:0,grossAmount:0,discount:0,netAmount:0,collected:0,outstanding:0}),t[o].bills++,t[o].grossAmount+=Number(s.amount||0),t[o].discount+=Number(s.discountAmount||0),t[o].netAmount+=Number(s.netAmount||s.amount||0),t[o].collected+=Number(s.paidAmount||0),t[o].outstanding+=Number(s.balanceAmount||0)}),Object.values(t).sort((s,o)=>a(o.date,"DD MMM YYYY").valueOf()-a(s.date,"DD MMM YYYY").valueOf())},[A]),l=d.reduce((t,s)=>({bills:t.bills+s.bills,grossAmount:t.grossAmount+s.grossAmount,discount:t.discount+s.discount,netAmount:t.netAmount+s.netAmount,collected:t.collected+s.collected,outstanding:t.outstanding+s.outstanding}),{bills:0,grossAmount:0,discount:0,netAmount:0,collected:0,outstanding:0}),i=t=>`₹ ${t.toFixed(2)}`,z=()=>{const t=new I("landscape"),s=t.internal.pageSize.getWidth();t.setFillColor(29,78,216),t.rect(0,0,s,28,"F"),t.setFont("helvetica","bold"),t.setFontSize(14),t.setTextColor(255,255,255),t.text("COLLECTION REPORT",14,18),t.setFontSize(9),t.setFont("helvetica","normal"),t.text(`${a(m).format("DD MMM YYYY")} - ${a(g).format("DD MMM YYYY")}`,s-14,18,{align:"right"}),t.autoTable({startY:34,head:[["Date","Bills","Gross Amount","Discount","Net Amount","Collected","Outstanding"]],body:d.map(o=>[o.date,o.bills,i(o.grossAmount),i(o.discount),i(o.netAmount),i(o.collected),i(o.outstanding)]),foot:[["TOTAL",l.bills,i(l.grossAmount),i(l.discount),i(l.netAmount),i(l.collected),i(l.outstanding)]],headStyles:{fillColor:[29,78,216],fontSize:8},bodyStyles:{fontSize:8},footStyles:{fillColor:[248,250,252],textColor:[15,23,42],fontStyle:"bold",fontSize:8},theme:"grid",styles:{lineColor:[226,232,240],lineWidth:.3},margin:{left:14,right:14}}),t.save(`Collection_Report_${a(m).format("YYYY-MM-DD")}_to_${a(g).format("YYYY-MM-DD")}.pdf`)},R=()=>{const s=[["Date","Bills","Gross Amount","Discount","Net Amount","Collected","Outstanding"].join(",")];d.forEach(o=>s.push([o.date,o.bills,o.grossAmount.toFixed(2),o.discount.toFixed(2),o.netAmount.toFixed(2),o.collected.toFixed(2),o.outstanding.toFixed(2)].join(","))),s.push(["TOTAL",l.bills,l.grossAmount.toFixed(2),l.discount.toFixed(2),l.netAmount.toFixed(2),l.collected.toFixed(2),l.outstanding.toFixed(2)].join(",")),L.saveAs(new Blob([s.join(`
`)],{type:"text/csv;charset=utf-8"}),`Collection_Report_${a(m).format("YYYY-MM-DD")}.csv`)};return e.jsxs(Y,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(Y,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,mb:2,alignItems:"center"},children:[e.jsx(S,{dateAdapter:C,children:e.jsx(M,{label:"From",value:m,onChange:T,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(S,{dateAdapter:C,children:e.jsx(M,{label:"To",value:g,onChange:v,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(p,{variant:"contained",disableElevation:!0,startIcon:e.jsx(_,{}),onClick:y,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(p,{variant:"outlined",size:"small",startIcon:e.jsx($,{}),onClick:z,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"PDF"}),e.jsx(p,{variant:"outlined",size:"small",startIcon:e.jsx(N,{}),onClick:R,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"CSV"})]}),e.jsx(E,{label:`${d.length} days`,size:"small",sx:{backgroundColor:u?"rgba(255,255,255,0.08)":"#f1f5f9",color:u?"#e2e8f0":"#475569",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}})]}),D&&e.jsx(B,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:D}),d.length>0&&e.jsx(G,{component:P,variant:"outlined",sx:{borderRadius:2,borderColor:u?"rgba(255,255,255,0.08)":"#e2e8f0",boxShadow:"none"},children:e.jsxs(H,{size:"small",children:[e.jsx(V,{children:e.jsxs(b,{sx:{backgroundColor:u?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(n,{sx:c,children:"Date"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Bills"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Gross Amount"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Discount"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Net Amount"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Collected"}),e.jsx(n,{sx:{...c,textAlign:"right"},children:"Outstanding"})]})}),e.jsxs(U,{children:[d.map(t=>e.jsxs(b,{hover:!0,sx:{"&:hover":{backgroundColor:u?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[e.jsx(n,{sx:r,children:t.date}),e.jsx(n,{sx:{...r,textAlign:"right"},children:t.bills}),e.jsx(n,{sx:{...r,textAlign:"right"},children:i(t.grossAmount)}),e.jsx(n,{sx:{...r,textAlign:"right",color:t.discount>0?"#f59e0b":void 0},children:i(t.discount)}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:500},children:i(t.netAmount)}),e.jsx(n,{sx:{...r,textAlign:"right",color:"#059669"},children:i(t.collected)}),e.jsx(n,{sx:{...r,textAlign:"right",color:t.outstanding>0?"#ef4444":"#94a3b8"},children:i(t.outstanding)})]},t.date)),e.jsxs(b,{sx:{backgroundColor:u?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(n,{sx:{...r,fontWeight:700},children:"TOTAL"}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700},children:l.bills}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700},children:i(l.grossAmount)}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700,color:"#f59e0b"},children:i(l.discount)}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700},children:i(l.netAmount)}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700,color:"#059669"},children:i(l.collected)}),e.jsx(n,{sx:{...r,textAlign:"right",fontWeight:700,color:l.outstanding>0?"#ef4444":"#94a3b8"},children:i(l.outstanding)})]})]})]})})]})}export{xt as default};
