Skip to content

Commit b01901f

Browse files
authored
Merge pull request #58 from chechojgb/buttonsLovers
add: create new database for MarcacionController
2 parents c6a0772 + 83e87d2 commit b01901f

File tree

7 files changed

+368
-118
lines changed

7 files changed

+368
-118
lines changed

app/Http/Controllers/BLMarcacionController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\BLCliente;
6+
use App\Models\User;
57
use Illuminate\Http\Request;
68
use Inertia\Inertia;
79
use Illuminate\Support\Facades\Auth;
@@ -11,8 +13,12 @@ class BLMarcacionController extends Controller
1113
public function index()
1214
{
1315
$user = Auth::user();
16+
$orderCustomer = BLCliente::with('pedidos.items.empaque.producto')->get();
17+
$buttonUser = User::where('proyecto', 'Button LoversM')->get();
1418
return Inertia::render('BLMarcacion', [
1519
'user' => $user,
20+
'orderCustomer' => $orderCustomer,
21+
'buttonUser' => $buttonUser
1622
]);
1723
}
1824
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class MarcacionController extends Controller
8+
{
9+
public function store(Request $request)
10+
{
11+
// ✅ Validamos los datos que vienen desde React
12+
$validated = $request->validate([
13+
'clienteId' => 'required|exists:bl_clientes,id',
14+
'pedidoId' => 'required|exists:bl_pedidos,id',
15+
'trabajadorId' => 'required|exists:users,id',
16+
'itemsMarcados' => 'required|array|min:1',
17+
'itemsMarcados.*.itemId' => 'required|integer',
18+
'itemsMarcados.*.referencia' => 'required|string|max:255',
19+
'itemsMarcados.*.cantidad' => 'required|integer|min:1',
20+
'itemsMarcados.*.nota' => 'nullable|string|max:500',
21+
'fecha' => 'required|date',
22+
]);
23+
24+
// ✅ Creamos la marcación
25+
$marcacion = BLMarcacion::create([
26+
'cliente_id' => $validated['clienteId'],
27+
'pedido_id' => $validated['pedidoId'],
28+
'trabajador_id' => $validated['trabajadorId'],
29+
'items_marcados' => json_encode($validated['itemsMarcados']), // guardamos array como JSON
30+
'fecha' => $validated['fecha'],
31+
]);
32+
33+
// ✅ Respuesta para Inertia/React
34+
return back()->with('success', 'Marcación registrada correctamente.');
35+
}
36+
}

database/migrations/2025_08_08_182325_drop_precio_unitario_to_bl_pedido_items_table.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
/**
1010
* Run the migrations.
1111
*/
12-
public function up(): void
13-
{
14-
Schema::table('bl_pedido_items', function (Blueprint $table) {
15-
$table->dropColumn('precio_unitario');
16-
});
17-
}
12+
// public function up(): void
13+
// {
14+
// Schema::table('bl_pedido_items', function (Blueprint $table) {
15+
// $table->dropColumn('precio_unitario');
16+
// });
17+
// }
1818

1919
/**
2020
* Reverse the migrations.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('bl_marcacion', function (Blueprint $table) {
15+
$table->id();
16+
17+
// relaciones
18+
$table->unsignedBigInteger('pedido_id');
19+
$table->unsignedBigInteger('pedido_item_id');
20+
$table->unsignedBigInteger('user_id'); // trabajador
21+
// info de marcación
22+
$table->integer('cantidad')->default(0);
23+
$table->date('fecha');
24+
$table->timestamps();
25+
// índices
26+
$table->index('pedido_id');
27+
$table->index('pedido_item_id');
28+
$table->index('user_id');
29+
$table->index('fecha');
30+
// foreign keys
31+
$table->foreign('pedido_id')
32+
->references('id')->on('bl_pedidos')
33+
->onDelete('cascade');
34+
$table->foreign('pedido_item_id')
35+
->references('id')->on('bl_pedido_items')
36+
->onDelete('cascade');
37+
$table->foreign('user_id')
38+
->references('id')->on('users')
39+
->onDelete('cascade');
40+
});
41+
}
42+
43+
public function down(): void
44+
{
45+
Schema::dropIfExists('bl_marcacion');
46+
}
47+
};

resources/js/components/app-sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const staticNavItems = [
9090
{ title: 'Historico', href: '/BLproductosInventario/BLHistorico' },
9191
],
9292
icon: CalendarHeart,
93+
proyectosPermitidos: ['Button Lovers', 'AZZU'],
9394

9495
},
9596
{
@@ -108,7 +109,7 @@ const staticNavItems = [
108109
title: 'Marcacion',
109110
href: '/BLproductosInventario/BLMarcacion',
110111
icon: BadgeCheck,
111-
proyectosPermitidos: ['Button Lovers', 'AZZU'],
112+
proyectosPermitidos: ['Button Lovers', 'AZZU', 'Button LoversM'],
112113
}
113114
];
114115

0 commit comments

Comments
 (0)