Skip to main content
GET
/
api
/
reports
/
summary
Summary Report
curl --request GET \
  --url https://api.example.com/api/reports/summary
{
  "total_registros": 123,
  "total_cantidad": 123,
  "total_costo": 123
}

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

fecha_inicio
string
Start date filter (YYYY-MM-DD format)
fecha_fin
string
End date filter (YYYY-MM-DD format)
area
string
Filter by specific area
turno
string
Filter by shift (A, B, C, etc.)
cadena
string
Filter by production chain
categoria
string
Filter by scrap category

Request Example

curl -X GET "http://localhost:3001/api/reports/summary" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response

total_registros
number
Total number of scrap records matching the filters
total_cantidad
number
Sum of all TOTAL_PZAS (total pieces scrapped)
total_costo
number
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"
}

Performance Notes

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).

Build docs developers (and LLMs) love