@@ -14,14 +14,16 @@ const breadcrumbs = [
1414 { title : "Pedidos BL" , href : "/BLproductosInventario/pedidos" }
1515] ;
1616
17- export default function BLPedidos ( { user, productos, colores, clientes } ) {
17+ export default function BLPedidos ( { user, productos, colores, clientes, pedidos } ) {
1818 const { props } = usePage ( ) ;
1919 const proyecto = props ?. auth ?. user ?. proyecto || 'AZZU' ;
2020 const theme = themeByProject [ proyecto ] ;
2121 const [ modalOpen , setModalOpen ] = useState ( false ) ;
2222 console . log ( "Colores disponibles:" , colores ) ;
2323 console . log ( "Productos disponibles:" , productos ) ;
2424 console . log ( "clientes disponibles:" , clientes ) ;
25+ console . log ( 'pedidos disponibles:' , pedidos ) ;
26+
2527
2628 const handleGuardarPedido = ( clientData ) => {
2729 console . log ( 'datos cliente' , clientData ) ;
@@ -104,35 +106,57 @@ export default function BLPedidos({ user, productos, colores, clientes }) {
104106 </ tr >
105107 </ thead >
106108 < tbody >
107- < tr className = "border-b hover:bg-gray-50 dark:hover:bg-gray-900" >
108- < td className = "px-6 py-4" > Textiles Zuluaga</ td >
109- < td className = "px-6 py-4 space-y-1" >
110- < div > Botón Azul < span className = "text-gray-500" > x300</ span > </ div >
111- < div > Botón Rojo < span className = "text-gray-500" > x150</ span > </ div >
112- </ td >
113- < td className = "px-6 py-4" > 2025-08-08</ td >
114- < td className = "px-6 py-4" >
115- < span className = "inline-flex px-2 py-1 text-xs font-semibold text-yellow-800 bg-yellow-100 rounded-full" >
116- En proceso
117- </ span >
118- </ td >
119- </ tr >
109+ { pedidos . map ( cliente => {
110+ // Agrupar items por producto_id y sumar cantidades
111+ const productosAgrupados = cliente . items . reduce ( ( acc , item ) => {
112+ const productoId = item . empaque . producto . id ;
113+ const nombreProducto = item . empaque . producto . descripcion ;
120114
121- < tr className = "border-b hover:bg-gray-50 dark:hover:bg-gray-900" >
122- < td className = "px-6 py-4" > Confecciones Lara</ td >
123- < td className = "px-6 py-4 space-y-1" >
124- < div > Botón Negro < span className = "text-gray-500" > x100</ span > </ div >
125- </ td >
126- < td className = "px-6 py-4" > 2025-08-10</ td >
127- < td className = "px-6 py-4" >
128- < span className = "inline-flex px-2 py-1 text-xs font-semibold text-green-800 bg-green-100 rounded-full" >
129- Entregado
130- </ span >
131- </ td >
132- </ tr >
115+ if ( ! acc [ productoId ] ) {
116+ acc [ productoId ] = {
117+ nombre : nombreProducto ,
118+ cantidad : 0
119+ } ;
120+ }
121+ acc [ productoId ] . cantidad += item . cantidad_empaques ;
122+ return acc ;
123+ } , { } ) ;
124+ const listaProductos = Object . values ( productosAgrupados ) ;
125+ const estadosStyle = {
126+ pendiente : 'text-yellow-800 bg-yellow-100' ,
127+ entregado : 'text-green-800 bg-green-100' ,
128+ cancelado : 'text-red-800 bg-red-100'
129+ }
130+ return (
131+ < tr
132+ className = "border-b hover:bg-gray-50 dark:hover:bg-gray-900"
133+ key = { cliente . id }
134+ >
135+ < td className = "px-6 py-4" > { cliente . cliente . nombre } </ td >
136+
137+ < td className = "px-6 py-4 space-y-1" >
138+ { listaProductos . map ( ( prod , idx ) => (
139+ < div key = { idx } >
140+ { prod . nombre } { " " }
141+ < span className = "text-gray-500" > x{ prod . cantidad } </ span >
142+ </ div >
143+ ) ) }
144+ </ td >
145+
146+ < td className = "px-6 py-4" > { cliente . fecha_pedido } </ td >
147+
148+ < td className = "px-6 py-4" >
149+ < span className = { `inline-flex px-2 py-1 text-xs font-semibold ${ estadosStyle [ cliente . estado ] || 'text-gray-800 bg-gray-100' } rounded-full` } >
150+ { cliente . estado }
151+ </ span >
152+ </ td >
153+ </ tr >
154+ ) ;
155+ } ) }
133156 </ tbody >
134157 </ table >
135158 </ div >
159+ { /* //MODALES Y TOAST */ }
136160 { modalOpen && (
137161 < AgentModalWrapper closeModal = { closeModal } >
138162 < ModalPedidosBL clientes = { clientes } productos = { productos } onClose = { closeModal } setToast = { setToast } onSave = { handleGuardarPedido } />
0 commit comments