Skip to content

Commit a775f4c

Browse files
authored
Merge pull request #72 from chechojgb/buttonsLovers
refactor: cambios estructura busqueda pedido
2 parents 7c4861f + 702be92 commit a775f4c

19 files changed

+839
-142
lines changed

app/Http/Controllers/BLMarcacionController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function index()
2020
$orderCustomer = BLCliente::with(['pedidos.items.empaque.producto', 'pedidos.items.marcaciones.trabajador'])->get();
2121
$buttonUser = User::whereIn('proyecto', ['Button LoversM', 'Button LoversMN'])->get();
2222
$itemsPedidos = BLPedidoItem::with(['pedido.cliente', 'empaque.producto', 'marcaciones.trabajador'])->get();
23+
// dd($itemsPedidos, $orderCustomer, $buttonUser);
2324
// dd($buttonUser);
2425
return Inertia::render('BLMarcacion', [
2526
'user' => $user,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\BlCuentaCobro;
6+
use App\Models\BlCuentaCobroItem;
7+
use App\Models\BLMarcacion;
8+
use Illuminate\Http\Request;
9+
10+
use Illuminate\Support\Facades\DB;
11+
12+
class BlCuentaCobroController extends Controller
13+
{
14+
public function pasarPagados(Request $request)
15+
{
16+
$items = $request->input('items', []);
17+
if (empty($items)) {
18+
return back()->withErrors(['items' => 'No hay ítems seleccionados']);
19+
}
20+
$trabajadorId = $items[0]['user_id'];
21+
$total = collect($items)->sum('total');
22+
DB::transaction(function () use ($trabajadorId, $total, $items) {
23+
$cuenta = BLCuentaCobro::create([
24+
'user_id' => $trabajadorId,
25+
'fecha' => now(),
26+
'total' => $total,
27+
]);
28+
foreach ($items as $item) {
29+
BLCuentaCobroItem::create([
30+
'cuenta_cobro_id' => $cuenta->id,
31+
'marcacion_id' => $item['marcacion_id'],
32+
]);
33+
BLMarcacion::where('id', $item['marcacion_id'])->update(['pagado' => 1]);
34+
}
35+
});
36+
return back()->with('success', 'Cuenta de cobro creada y items marcados como pagados.');
37+
}
38+
// public function update($items)
39+
// {
40+
// foreach ($items as $item) {
41+
// $registro = BLMarcacion::findOrFail($item['marcacion_id']);
42+
// $registro->validate([
43+
// 'marcacion_id' => 'required|integer|min:1'
44+
// ]);
45+
// $registro->update(['pagado' => 1]);
46+
// }
47+
// }
48+
}

app/Models/BLMarcacion.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ public function trabajador()
3838
{
3939
return $this->belongsTo(User::class, 'user_id');
4040
}
41+
public function itemsCuenta()
42+
{
43+
return $this->hasMany(BlCuentaCobroItem::class, 'marcacion_id');
44+
}
4145
}

app/Models/BlCuentaCobro.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class BlCuentaCobro extends Model
8+
{
9+
protected $table = 'bl_cuentas_cobro';
10+
protected $fillable = ['user_id', 'fecha', 'total'];
11+
12+
public function usuario()
13+
{
14+
return $this->belongsTo(User::class, 'user_id');
15+
}
16+
17+
public function items()
18+
{
19+
return $this->hasMany(BlCuentaCobroItem::class, 'cuenta_cobro_id');
20+
}
21+
}

app/Models/BlCuentaCobroItem.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class BlCuentaCobroItem extends Model
8+
{
9+
protected $fillable = ['cuenta_cobro_id', 'marcacion_id'];
10+
11+
public function cuenta()
12+
{
13+
return $this->belongsTo(BlCuentaCobro::class, 'cuenta_cobro_id');
14+
}
15+
16+
public function marcacion()
17+
{
18+
return $this->belongsTo(BlMarcacion::class, 'marcacion_id');
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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::table('bl_marcacion', function (Blueprint $table) {
15+
$table->boolean('pagado')->default(false)->after('costo_total');
16+
});
17+
}
18+
19+
public function down(): void
20+
{
21+
Schema::table('bl_marcacion', function (Blueprint $table) {
22+
$table->dropColumn('pagado');
23+
});
24+
}
25+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
public function up(): void
10+
{
11+
Schema::create('bl_cuentas_cobro', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('user_id')->constrained('users'); // trabajador
14+
$table->date('fecha');
15+
$table->decimal('total', 12, 2)->default(0);
16+
$table->timestamps();
17+
});
18+
}
19+
20+
public function down(): void
21+
{
22+
Schema::dropIfExists('bl_cuentas_cobro');
23+
}
24+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
public function up(): void
10+
{
11+
Schema::create('bl_cuenta_cobro_items', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('cuenta_cobro_id')->constrained('bl_cuentas_cobro');
14+
$table->foreignId('marcacion_id')->constrained('bl_marcacion');
15+
$table->timestamps();
16+
});
17+
}
18+
19+
public function down(): void
20+
{
21+
Schema::dropIfExists('bl_cuenta_cobro_items');
22+
}
23+
};

package-lock.json

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"typescript": "^5.7.2",
8484
"vite": "^6.0",
8585
"ws": "^8.18.3",
86+
"xlsx": "^0.18.5",
8687
"xterm": "^5.3.0",
8788
"xterm-addon-fit": "^0.8.0",
8889
"xterm-addon-search": "^0.13.0",

0 commit comments

Comments
 (0)