import{r as l,j as r,e as u}from"./index-B1H8BCL7.js";import{k as y}from"./stockApi-D1nxeMJU.js";import{R as k}from"./ReportPageShell-B7ORyOeG.js";import{G as a}from"./Grid-CTEl0Elf.js";import"./FileDownloadOutlined-B1TjRPKt.js";import"./Refresh-942gtAB1.js";import"./Stack-BIAbaqpj.js";import"./useThemeProps-DL_l3A7P.js";import"./TableContainer-CXAjhAg6.js";import"./TableRow-BfKE_xn9.js";import"./TableCell-D8CotAsC.js";const N=[{key:"invoiceNo",header:"Invoice No",width:120},{key:"invoiceDate",header:"Date",width:110},{key:"customerName",header:"Customer"},{key:"itemCode",header:"Item Code",width:110},{key:"itemName",header:"Item"},{key:"qty",header:"Qty",align:"right",format:v},{key:"sellingPrice",header:"Sell Price",align:"right",format:i},{key:"costPrice",header:"Cost Price",align:"right",format:i},{key:"lineTotal",header:"Line Total",align:"right",format:i},{key:"margin",header:"Margin",align:"right",format:e=>(Number(e)||0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}],z=()=>{const[e,c]=l.useState(b()),[g,p]=l.useState(F()),[h,f]=l.useState(""),{data:o,isFetching:x,refetch:S}=y({from:e,to:g,customer:h}),n=(o==null?void 0:o.list)??[],s=n.reduce((t,m)=>t+(Number(m.lineTotal)||0),0),d=n.reduce((t,m)=>t+(Number(m.margin)||0),0);return r.jsx(k,{title:"Resale Sales",subtitle:`Revenue: ${i(s)} · Margin: ${i(d)}${s>0?` (${(d/s*100).toFixed(1)}%)`:""}`,filters:r.jsxs(a,{container:!0,spacing:1.5,children:[r.jsx(a,{item:!0,xs:6,sm:3,children:r.jsx(u,{label:"From",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:e,onChange:t=>c(t.target.value)})}),r.jsx(a,{item:!0,xs:6,sm:3,children:r.jsx(u,{label:"To",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:g,onChange:t=>p(t.target.value)})}),r.jsx(a,{item:!0,xs:12,sm:6,children:r.jsx(u,{label:"Customer name (contains)",size:"small",fullWidth:!0,value:h,onChange:t=>f(t.target.value)})})]}),columns:N,rows:n,isFetching:x,refetch:S,csvFilenameStem:"resale-sales"})};function v(e){return e==null?"0":Number(e).toLocaleString("en-IN",{minimumFractionDigits:0,maximumFractionDigits:3})}function i(e){return e==null?"0.00":Number(e).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}function F(){return new Date().toISOString().slice(0,10)}function b(){const e=new Date;return e.setDate(1),e.toISOString().slice(0,10)}export{z as default};
