import{r as m,j as e,e as n,T as y}from"./index-B1H8BCL7.js";import{i as f}from"./stockApi-D1nxeMJU.js";import{R as v}from"./ReportPageShell-B7ORyOeG.js";import{G as i}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 I=[{key:"itemCode",header:"Item Code",width:110},{key:"itemName",header:"Item Name"},{key:"stockPurpose",header:"Purpose",width:140},{key:"locationCode",header:"Location",width:140},{key:"totalQty",header:"Total Qty",align:"right",format:u},{key:"availableQty",header:"Available",align:"right",format:u},{key:"averageUnitCost",header:"Avg Cost",align:"right",format:r},{key:"totalValue",header:"Total Value",align:"right",format:r}],w=()=>{const[t,c]=m.useState(""),[l,d]=m.useState(""),{data:o,isFetching:h,refetch:g}=f({itemId:t,locationId:l}),s=(o==null?void 0:o.list)??[],p=s.reduce((a,x)=>a+(Number(x.totalValue)||0),0);return e.jsx(v,{title:"Stock Valuation",subtitle:`Total inventory value: ${r(p)}`,filters:e.jsxs(i,{container:!0,spacing:1.5,children:[e.jsx(i,{item:!0,xs:6,sm:3,children:e.jsx(n,{label:"Item ID",type:"number",size:"small",fullWidth:!0,value:t,onChange:a=>c(a.target.value)})}),e.jsx(i,{item:!0,xs:6,sm:3,children:e.jsx(n,{label:"Location ID",type:"number",size:"small",fullWidth:!0,value:l,onChange:a=>d(a.target.value)})}),e.jsx(i,{item:!0,xs:12,sm:6,sx:{display:"flex",alignItems:"center"},children:e.jsx(y,{sx:{fontSize:"0.72rem",color:"#94a3b8"},children:"Grouped by (item × location). Avg cost is weighted: total_value ÷ total_qty."})})]}),columns:I,rows:s,isFetching:h,refetch:g,csvFilenameStem:"stock-valuation"})};function u(t){return t==null?"0":Number(t).toLocaleString("en-IN",{minimumFractionDigits:0,maximumFractionDigits:3})}function r(t){return t==null?"0.00":Number(t).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}export{w as default};
