import React, { useState } from 'react'; import { Plus, Search, Filter, Download, ShoppingCart, Truck, DollarSign, Calendar } from 'lucide-react'; import { Button, Input, Card, Badge } from '../../../../components/ui'; import { PageHeader } from '../../../../components/layout'; const ProcurementPage: React.FC = () => { const [activeTab, setActiveTab] = useState('orders'); const [searchTerm, setSearchTerm] = useState(''); const mockPurchaseOrders = [ { id: 'PO-2024-001', supplier: 'Molinos del Sur', status: 'pending', orderDate: '2024-01-25', deliveryDate: '2024-01-28', totalAmount: 1250.00, items: [ { name: 'Harina de Trigo', quantity: 50, unit: 'kg', price: 1.20, total: 60.00 }, { name: 'Harina Integral', quantity: 100, unit: 'kg', price: 1.30, total: 130.00 }, ], paymentStatus: 'pending', notes: 'Entrega en horario de mañana', }, { id: 'PO-2024-002', supplier: 'Levaduras SA', status: 'delivered', orderDate: '2024-01-20', deliveryDate: '2024-01-23', totalAmount: 425.50, items: [ { name: 'Levadura Fresca', quantity: 5, unit: 'kg', price: 8.50, total: 42.50 }, { name: 'Mejorante', quantity: 10, unit: 'kg', price: 12.30, total: 123.00 }, ], paymentStatus: 'paid', notes: '', }, { id: 'PO-2024-003', supplier: 'Lácteos Frescos', status: 'in_transit', orderDate: '2024-01-24', deliveryDate: '2024-01-26', totalAmount: 320.75, items: [ { name: 'Mantequilla', quantity: 20, unit: 'kg', price: 5.80, total: 116.00 }, { name: 'Nata', quantity: 15, unit: 'L', price: 3.25, total: 48.75 }, ], paymentStatus: 'pending', notes: 'Producto refrigerado', }, ]; const mockSuppliers = [ { id: '1', name: 'Molinos del Sur', contact: 'Juan Pérez', email: 'juan@molinosdelsur.com', phone: '+34 91 234 5678', category: 'Harinas', rating: 4.8, totalOrders: 24, totalSpent: 15600.00, paymentTerms: '30 días', leadTime: '2-3 días', location: 'Sevilla', status: 'active', }, { id: '2', name: 'Levaduras SA', contact: 'María González', email: 'maria@levaduras.com', phone: '+34 93 456 7890', category: 'Levaduras', rating: 4.6, totalOrders: 18, totalSpent: 8450.00, paymentTerms: '15 días', leadTime: '1-2 días', location: 'Barcelona', status: 'active', }, { id: '3', name: 'Lácteos Frescos', contact: 'Carlos Ruiz', email: 'carlos@lacteosfrescos.com', phone: '+34 96 789 0123', category: 'Lácteos', rating: 4.4, totalOrders: 32, totalSpent: 12300.00, paymentTerms: '20 días', leadTime: '1 día', location: 'Valencia', status: 'active', }, ]; const getStatusBadge = (status: string) => { const statusConfig = { pending: { color: 'yellow', text: 'Pendiente' }, approved: { color: 'blue', text: 'Aprobado' }, in_transit: { color: 'purple', text: 'En Tránsito' }, delivered: { color: 'green', text: 'Entregado' }, cancelled: { color: 'red', text: 'Cancelado' }, }; const config = statusConfig[status as keyof typeof statusConfig]; return {config?.text || status}; }; const getPaymentStatusBadge = (status: string) => { const statusConfig = { pending: { color: 'yellow', text: 'Pendiente' }, paid: { color: 'green', text: 'Pagado' }, overdue: { color: 'red', text: 'Vencido' }, }; const config = statusConfig[status as keyof typeof statusConfig]; return {config?.text || status}; }; const stats = { totalOrders: mockPurchaseOrders.length, pendingOrders: mockPurchaseOrders.filter(o => o.status === 'pending').length, totalSpent: mockPurchaseOrders.reduce((sum, order) => sum + order.totalAmount, 0), activeSuppliers: mockSuppliers.filter(s => s.status === 'active').length, }; return (
Nueva Orden de Compra } /> {/* Stats Cards */}

Órdenes Totales

{stats.totalOrders}

Órdenes Pendientes

{stats.pendingOrders}

Gasto Total

€{stats.totalSpent.toLocaleString()}

Proveedores Activos

{stats.activeSuppliers}

{/* Tabs Navigation */}
{/* Search and Filters */}
setSearchTerm(e.target.value)} className="pl-10" />
{/* Tab Content */} {activeTab === 'orders' && (
{mockPurchaseOrders.map((order) => ( ))}
Orden Proveedor Estado Fecha Pedido Fecha Entrega Monto Total Pago Acciones
{order.id}
{order.notes && (
{order.notes}
)}
{order.supplier} {getStatusBadge(order.status)} {new Date(order.orderDate).toLocaleDateString('es-ES')} {new Date(order.deliveryDate).toLocaleDateString('es-ES')} €{order.totalAmount.toLocaleString()} {getPaymentStatusBadge(order.paymentStatus)}
)} {activeTab === 'suppliers' && (
{mockSuppliers.map((supplier) => (

{supplier.name}

{supplier.category}

Activo
Contacto: {supplier.contact}
Email: {supplier.email}
Teléfono: {supplier.phone}
Ubicación: {supplier.location}

Valoración

{supplier.rating}

Pedidos

{supplier.totalOrders}

Total Gastado

€{supplier.totalSpent.toLocaleString()}

Tiempo Entrega

{supplier.leadTime}

Condiciones de Pago

{supplier.paymentTerms}

))}
)} {activeTab === 'analytics' && (

Gastos por Mes

Gráfico de gastos mensuales

Top Proveedores

{mockSuppliers .sort((a, b) => b.totalSpent - a.totalSpent) .slice(0, 5) .map((supplier, index) => (
{index + 1}. {supplier.name}
€{supplier.totalSpent.toLocaleString()}
))}

Gastos por Categoría

Gráfico de gastos por categoría

)}
); }; export default ProcurementPage;