Overview
Retrieve aggregated scrap statistics including total records, total quantity, and total cost. Supports filtering by date range, area, shift, chain, and category.
Authentication
Requires valid JWT token.
Authorization: Bearer <token>
Query Parameters
Start date filter (YYYY-MM-DD format)
End date filter (YYYY-MM-DD format)
Filter by shift (A, B, C, etc.)
Filter by production chain
Request Example
cURL - All Time
cURL - Date Range
cURL - With Filters
JavaScript
TypeScript
curl -X GET "http://localhost:3001/api/reports/summary" \
-H "Authorization: Bearer YOUR_TOKEN"
Response
Total number of scrap records matching the filters
Sum of all TOTAL_PZAS (total pieces scrapped)
Sum of all COSTO values (total cost in USD)
Success Response Example
{
"total_registros" : 1547 ,
"total_cantidad" : 48923 ,
"total_costo" : 125487.65
}
Dashboard Integration
const DashboardSummary : React . FC = () => {
const [ summary , setSummary ] = useState < SummaryResponse | null >( null );
const [ period , setPeriod ] = useState < 'today' | 'week' | 'month' >( 'today' );
useEffect (() => {
const fetchData = async () => {
const now = new Date ();
let filters : SummaryFilters = {};
switch ( period ) {
case 'today' :
filters . fecha_inicio = now . toISOString (). split ( 'T' )[ 0 ];
break ;
case 'week' :
const weekAgo = new Date ( now . getTime () - 7 * 24 * 60 * 60 * 1000 );
filters . fecha_inicio = weekAgo . toISOString (). split ( 'T' )[ 0 ];
break ;
case 'month' :
const monthAgo = new Date ( now . getTime () - 30 * 24 * 60 * 60 * 1000 );
filters . fecha_inicio = monthAgo . toISOString (). split ( 'T' )[ 0 ];
break ;
}
const data = await getSummary ( filters );
setSummary ( data );
};
fetchData ();
}, [ period ]);
return (
< div className = "dashboard" >
< div className = "card" >
< h3 > Total Records </ h3 >
< p className = "metric" > {summary?.total_registros || 0 } </ p >
</ div >
< div className = "card" >
< h3 > Total Quantity </ h3 >
< p className = "metric" > {summary?.total_cantidad || 0 } pcs </ p >
</ div >
< div className = "card" >
< h3 > Total Cost </ h3 >
< p className = "metric" > $ {(summary?.total_costo || 0 ).toFixed ( 2 ) } </ p >
</ div >
</ div >
);
};
Comparative Analysis
const comparePerio ds = async ( period1 , period2 ) => {
const [ data1 , data2 ] = await Promise . all ([
getSummary ( period1 ),
getSummary ( period2 )
]);
return {
records: {
current: data1 . total_registros ,
previous: data2 . total_registros ,
change: (( data1 . total_registros - data2 . total_registros ) / data2 . total_registros * 100 ). toFixed ( 1 )
},
cost: {
current: data1 . total_costo ,
previous: data2 . total_costo ,
change: (( data1 . total_costo - data2 . total_costo ) / data2 . total_costo * 100 ). toFixed ( 1 )
}
};
};
// Compare this month vs last month
const now = new Date ();
const thisMonth = {
fecha_inicio: new Date ( now . getFullYear (), now . getMonth (), 1 ). toISOString (). split ( 'T' )[ 0 ],
fecha_fin: now . toISOString (). split ( 'T' )[ 0 ]
};
const lastMonth = {
fecha_inicio: new Date ( now . getFullYear (), now . getMonth () - 1 , 1 ). toISOString (). split ( 'T' )[ 0 ],
fecha_fin: new Date ( now . getFullYear (), now . getMonth (), 0 ). toISOString (). split ( 'T' )[ 0 ]
};
const comparison = await comparePeriods ( thisMonth , lastMonth );
console . log ( `Cost change: ${ comparison . cost . change } %` );
Error Responses
401 Unauthorized
{
"error" : "Token requerido"
}
500 Internal Server Error
{
"error" : "Database query failed"
}
This endpoint performs aggregation queries on the pesaje table. For large datasets (>100k records), consider adding database indexes on FECHA_REGISTRO, AREA, TURNO, and CADENA columns.
The query excludes soft-deleted records (ELIMINADO = 0 OR ELIMINADO IS NULL).