import React from 'react'; import { useNavigate } from 'react-router-dom'; import { Card, CardHeader, CardBody } from '../../ui/Card'; import { Button } from '../../ui/Button'; import { FileText, CheckCircle, Clock, Truck, AlertCircle, ChevronRight, Euro, Calendar, Package } from 'lucide-react'; import { useProcurementDashboard } from '../../../api/hooks/orders'; import { useCurrentTenant } from '../../../stores/tenant.store'; const PurchaseOrdersTracking: React.FC = () => { const navigate = useNavigate(); const currentTenant = useCurrentTenant(); const tenantId = currentTenant?.id || ''; const { data: dashboard, isLoading } = useProcurementDashboard(tenantId); const getStatusIcon = (status: string) => { switch (status) { case 'draft': return ; case 'pending_approval': return ; case 'approved': return ; case 'in_execution': return ; case 'completed': return ; default: return ; } }; const getStatusColor = (status: string) => { switch (status) { case 'draft': return 'text-[var(--text-tertiary)] bg-[var(--bg-tertiary)]'; case 'pending_approval': return 'text-yellow-700 bg-yellow-100'; case 'approved': return 'text-green-700 bg-green-100'; case 'in_execution': return 'text-blue-700 bg-blue-100'; case 'completed': return 'text-green-700 bg-green-100'; case 'cancelled': return 'text-red-700 bg-red-100'; default: return 'text-[var(--text-secondary)] bg-[var(--bg-secondary)]'; } }; const getStatusLabel = (status: string) => { const labels: Record = { draft: 'Borrador', pending_approval: 'Pendiente Aprobación', approved: 'Aprobado', in_execution: 'En Ejecución', completed: 'Completado', cancelled: 'Cancelado' }; return labels[status] || status; }; const handleViewAllPOs = () => { navigate('/app/operations/procurement'); }; const handleViewPODetails = (planId: string) => { navigate(`/app/operations/procurement?plan=${planId}`); }; if (isLoading) { return (

Órdenes de Compra

Seguimiento de órdenes de compra

); } const recentPlans = dashboard?.recent_plans || []; return (

Órdenes de Compra

Seguimiento de órdenes de compra

{recentPlans.length === 0 ? (

No hay órdenes de compra recientes

) : (
{recentPlans.slice(0, 5).map((plan: any) => (
handleViewPODetails(plan.id)} >
{getStatusIcon(plan.status)}
{plan.plan_number} {getStatusLabel(plan.status)}
{new Date(plan.plan_date).toLocaleDateString('es-ES')}
{plan.total_requirements} items
€{plan.total_estimated_cost?.toFixed(2) || '0.00'}
))}
)} {/* Summary Stats */} {dashboard?.stats && (
{dashboard.stats.total_plans || 0}
Total Planes
{dashboard.stats.approved_plans || 0}
Aprobados
{dashboard.stats.pending_plans || 0}
Pendientes
)}
); }; export default PurchaseOrdersTracking;