Skip to content

Commit b38ff71

Browse files
authored
Merge pull request #45 from chechojgb/buttonsLovers
refactor: cambio llamada datos pedidos.
2 parents d71482d + ac530f0 commit b38ff71

File tree

8 files changed

+201
-52
lines changed

8 files changed

+201
-52
lines changed

app/Http/Controllers/BLClientesController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
use App\Models\BlEmpaque;
99
use App\Models\BlMovimiento;
1010
use App\Models\BLCliente; // Assuming you have a Cliente model
11-
use Illuminate\Container\Attributes\Auth;
11+
// use Illuminate\Container\Attributes\Auth;
1212
use Inertia\Inertia;
1313
use Illuminate\Support\Str;
14+
use Illuminate\Support\Facades\Auth;
1415

1516
class BLClientesController extends Controller
1617
{
1718
public function index()
1819
{
20+
$user = Auth::user();
1921
$clientes = BLCliente::all();
2022
$productos = BlProducto::with(['color', 'empaques.movimientos'])
2123
->get()
@@ -34,7 +36,7 @@ public function index()
3436
return Inertia::render('BLClientes', [
3537
'productos' => $productos,
3638
'colores' => BlColor::all(), // Para formularios
37-
'user' => auth()->user(),
39+
'user' => $user,
3840
'clientes' => $clientes, // Para mostrar los clientes
3941
]);
4042
}

app/Http/Controllers/BLPedidosController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,16 @@ public function index()
4040
});
4141

4242
$clientes = BLCliente::all();
43+
$pedidos = BLPedido::with([
44+
'items.empaque.producto', 'cliente'
45+
])->get();
4346

4447
return Inertia::render('BLPedidos', [
4548
'productos' => $productos,
4649
'colores' => BlColor::all(), // Para formularios
4750
'user' => $user,
4851
'clientes' => $clientes, // Para formularios
52+
'pedidos' => $pedidos,
4953
]);
5054
}
5155

app/Http/Controllers/BlProductoController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
use App\Models\BlColor;
99
use App\Models\BlEmpaque;
1010
use App\Models\BlMovimiento;
11-
use Illuminate\Container\Attributes\Auth;
11+
// use Illuminate\Container\Attributes\Auth;
1212
use Illuminate\Http\Request;
1313
use Inertia\Inertia;
1414
use Illuminate\Support\Str;
15+
use Illuminate\Support\Facades\Auth;
1516

1617

1718
class BlProductoController extends Controller
@@ -42,6 +43,7 @@ public function index()
4243

4344
public function indexAnalisis()
4445
{
46+
$user = Auth::user();
4547
$productos = BlProducto::with(['color', 'empaques.movimientos'])
4648
->get()
4749
->map(function ($producto) {
@@ -60,12 +62,13 @@ public function indexAnalisis()
6062
return Inertia::render('BLAnalisis', [
6163
'productos' => $productos,
6264
'colores' => BlColor::all(),
63-
'user' => auth()->user(), // Para formularios
65+
'user' => $user, // Para formularios
6466
]);
6567
}
6668

6769
public function indexHistorico()
6870
{
71+
$user = Auth::user();
6972
$productos = BlProducto::with(['color', 'empaques.movimientos'])
7073
->get()
7174
->map(function ($producto) {
@@ -82,11 +85,12 @@ public function indexHistorico()
8285
});
8386
$historico = BlMovimiento::with(['empaque.producto', 'usuario'])
8487
->where('tipo', 'entrada')
88+
->whereHas('empaque.producto')
8589
->get()
8690
->map(function ($movimiento) {
8791
return [
8892
'id' => $movimiento->id,
89-
'producto' => $movimiento->empaque->producto->tipo_producto,
93+
'producto' => $movimiento->empaque->producto->tipo_producto ,
9094
'tamanio' => $movimiento->empaque->producto->tamanio,
9195
'color' => $movimiento->empaque->producto->color->nombre,
9296
'cantidad' => $movimiento->cantidad,
@@ -102,7 +106,7 @@ public function indexHistorico()
102106
return Inertia::render('BLHistorico', [
103107
'productos' => $productos,
104108
'colores' => BlColor::all(),
105-
'user' => auth()->user(),
109+
'user' => $user,
106110
'historico' => $historico,
107111
]);
108112
}

resources/js/components/BL/historicoBL.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function EntradaBL({ historico }) {
2929
>
3030
<div className="space-y-1">
3131
<p className="font-semibold ">
32-
{item.producto} - {item.tamanio} - {item.color}
32+
{item.producto || 'No existe'} - {item.tamanio} - {item.color}
3333
</p>
3434
<p className="text-xs ">
3535
{item.fecha}{item.tipo || "sin tipo"}{" "}

resources/js/components/BL/modalesBL.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function ModalPedidosBL({ onClose, onSave, clientes, productos, s
2121
{ producto_id: '', cantidad: 1 },
2222
]);
2323

24+
2425
const handleProductoChange = (index, field, value) => {
2526
const nuevos = [...productosSeleccionados];
2627

@@ -101,7 +102,7 @@ export default function ModalPedidosBL({ onClose, onSave, clientes, productos, s
101102
console.log('productos seleccionados:', productosResumen);
102103

103104
return (
104-
<div className="bg-white rounded-lg shadow-xl w-full max-w-3xl max-h-[90vh] flex flex-col">
105+
<div className="max-h-[90vh] flex flex-col">
105106
{/* Encabezado */}
106107
<div className="px-6 py-4 border-b border-gray-200">
107108
<h2 className="text-2xl font-bold text-gray-800">Nuevo Pedido</h2>
@@ -197,7 +198,7 @@ export default function ModalPedidosBL({ onClose, onSave, clientes, productos, s
197198
</div>
198199

199200
{/* Cantidad */}
200-
<div className="md:col-span-3 space-y-1">
201+
<div className="md:col-span-6 space-y-1">
201202
<label className="block text-xs font-medium text-gray-500">Cantidad</label>
202203
<div className="relative">
203204
<input
@@ -209,7 +210,7 @@ export default function ModalPedidosBL({ onClose, onSave, clientes, productos, s
209210
className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm"
210211
/>
211212
{item.producto_id && (
212-
<span className="absolute right-3 top-2 text-xs text-gray-500">
213+
<span className="absolute right-2 top-2 text-xs text-gray-500">
213214
Stock: {productos.find(p => String(p.id) === String(item.producto_id))?.stock_total || 'N/A'}
214215
</span>
215216
)}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {
2+
useReactTable,
3+
getCoreRowModel,
4+
getSortedRowModel,
5+
getFilteredRowModel,
6+
flexRender,
7+
} from '@tanstack/react-table';
8+
import { useState } from 'react';
9+
import { themeByProject } from '../utils/theme';
10+
import { usePage } from '@inertiajs/react';
11+
12+
export default function TablaProductosBL({ productos, openModal, search }) {
13+
const { props } = usePage();
14+
const proyecto = props?.auth?.user?.proyecto || 'AZZU';
15+
const theme = themeByProject[proyecto];
16+
17+
const columns = [
18+
{ accessorKey: 'tipo_producto', header: 'Tipo de producto' },
19+
{ accessorKey: 'tamanio', header: 'Tamaño' },
20+
{ accessorKey: 'color_nombre', header: 'Colores' },
21+
{ accessorKey: 'stock_total', header: 'Cantidades' },
22+
{ accessorKey: 'descripcion', header: 'Descripción' },
23+
{
24+
id: 'acciones',
25+
header: 'Editar Producto',
26+
cell: ({ row }) => (
27+
<button
28+
className={`${theme.text} font-medium hover:underline cursor-pointer`}
29+
onClick={() => openModal(row.original.id)}
30+
>
31+
Editar
32+
</button>
33+
),
34+
},
35+
];
36+
37+
const [sorting, setSorting] = useState([]);
38+
39+
const table = useReactTable({
40+
data: productos,
41+
columns,
42+
state: {
43+
sorting,
44+
globalFilter: search,
45+
},
46+
onSortingChange: setSorting,
47+
getCoreRowModel: getCoreRowModel(),
48+
getSortedRowModel: getSortedRowModel(),
49+
getFilteredRowModel: getFilteredRowModel(),
50+
globalFilterFn: (row, columnId, value) => {
51+
const cellValue = String(row.getValue(columnId) ?? '').toLowerCase();
52+
return cellValue.includes(value.toLowerCase());
53+
},
54+
});
55+
56+
return (
57+
<table className="min-w-full text-sm text-left text-gray-500 dark:text-gray-400">
58+
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-800 dark:text-gray-400">
59+
{table.getHeaderGroups().map(headerGroup => (
60+
<tr key={headerGroup.id}>
61+
{headerGroup.headers.map(header => (
62+
<th
63+
key={header.id}
64+
className="px-6 py-3 cursor-pointer select-none"
65+
onClick={header.column.getToggleSortingHandler()}
66+
>
67+
{flexRender(header.column.columnDef.header, header.getContext())}
68+
{{
69+
asc: ' 🔼',
70+
desc: ' 🔽',
71+
}[header.column.getIsSorted()] ?? null}
72+
</th>
73+
))}
74+
</tr>
75+
))}
76+
</thead>
77+
<tbody>
78+
{table.getRowModel().rows.map((row, index) => (
79+
<tr
80+
key={row.id}
81+
className={`${
82+
index % 2 === 0
83+
? 'bg-white dark:bg-gray-800'
84+
: 'bg-gray-50 dark:bg-gray-700'
85+
} hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors`}
86+
>
87+
{row.getVisibleCells().map(cell => (
88+
<td key={cell.id} className="px-6 py-4 whitespace-nowrap">
89+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
90+
</td>
91+
))}
92+
</tr>
93+
))}
94+
</tbody>
95+
</table>
96+
);
97+
}

resources/js/pages/BLPedidos.jsx

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)