import{r as a,j as e,e as s,T as d}from"./index-B1H8BCL7.js";import{p as g}from"./stockApi-D1nxeMJU.js";import{R as h}from"./ReportPageShell-B7ORyOeG.js";import{G as r}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 f=[{key:"departmentId",header:"Dept #",width:100,align:"right",format:t=>t??e.jsx("span",{style:{color:"#94a3b8"},children:"(unattributed)"})},{key:"itemCode",header:"Item Code",width:110},{key:"itemName",header:"Item"},{key:"totalConsumed",header:"Consumed",align:"right",format:x},{key:"totalValue",header:"Value",align:"right",format:y},{key:"entriesCount",header:"Entries",align:"right"}],L=()=>{const[t,m]=a.useState(b()),[o,l]=a.useState(S()),{data:i,isFetching:u,refetch:p}=g({from:t,to:o}),c=(i==null?void 0:i.list)??[];return e.jsx(h,{title:"Department-wise Consumption",subtitle:"Splits stock_ledger consumption rows across departments via test_item_consumption_mapping.department_id (proportional to quantity_per_test). Items without a department mapping appear as (unattributed).",filters:e.jsxs(r,{container:!0,spacing:1.5,children:[e.jsx(r,{item:!0,xs:6,sm:3,children:e.jsx(s,{label:"From",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:t,onChange:n=>m(n.target.value)})}),e.jsx(r,{item:!0,xs:6,sm:3,children:e.jsx(s,{label:"To",type:"date",size:"small",fullWidth:!0,InputLabelProps:{shrink:!0},value:o,onChange:n=>l(n.target.value)})}),e.jsx(r,{item:!0,xs:12,sm:6,sx:{display:"flex",alignItems:"center"},children:e.jsx(d,{sx:{fontSize:"0.72rem",color:"#94a3b8"},children:"Set department_id on the Test Consumption mapping to get full attribution coverage."})})]}),columns:f,rows:c,isFetching:u,refetch:p,csvFilenameStem:"department-consumption"})};function x(t){return t==null?"0":Number(t).toLocaleString("en-IN",{minimumFractionDigits:0,maximumFractionDigits:3})}function y(t){return t==null?"0.00":Number(t).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}function S(){return new Date().toISOString().slice(0,10)}function b(){const t=new Date;return t.setDate(t.getDate()-30),t.toISOString().slice(0,10)}export{L as default};
