Skip to content

Commit 237ce46

Browse files
committed
Implementación del módulo de gestión de fechas importantes para expedientes legales. Se ha creado el controlador CaseImportantDateController con métodos para listar, crear, actualizar y eliminar fechas importantes. Además, se han añadido las migraciones necesarias para la tabla de fechas importantes y se ha actualizado la vista LegalCases para incluir la gestión de estas fechas, mejorando la funcionalidad y la experiencia del usuario.
1 parent 2f0e492 commit 237ce46

25 files changed

+979
-59
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\LegalCase;
6+
use App\Models\CaseImportantDate;
7+
use Illuminate\Http\Request;
8+
use Inertia\Inertia;
9+
use Illuminate\Support\Facades\Auth;
10+
11+
class CaseImportantDateController extends Controller
12+
{
13+
public function index(LegalCase $legalCase)
14+
{
15+
$importantDates = $legalCase->importantDates()
16+
->with('creator')
17+
->orderBy('end_date')
18+
->get();
19+
20+
$nextImportantDate = $legalCase->importantDates()
21+
->where('is_expired', false)
22+
->whereDate('end_date', '>=', now()->toDateString())
23+
->orderBy('end_date')
24+
->first();
25+
26+
return Inertia::render('LegalCases/ImportantDates', [
27+
'legalCase' => $legalCase,
28+
'importantDates' => $importantDates->map(function ($date) {
29+
return [
30+
'id' => $date->id,
31+
'title' => $date->title,
32+
'description' => $date->description,
33+
'start_date' => $date->start_date?->toDateString(),
34+
'end_date' => $date->end_date?->toDateString(),
35+
'is_expired' => (bool) $date->is_expired,
36+
'created_by' => $date->creator ? [
37+
'id' => $date->creator->id,
38+
'name' => $date->creator->name,
39+
] : null,
40+
];
41+
}),
42+
'nextImportantDate' => $nextImportantDate,
43+
]);
44+
}
45+
46+
public function store(Request $request, LegalCase $legalCase)
47+
{
48+
$validated = $request->validate([
49+
'title' => 'required|string|max:255',
50+
'description' => 'nullable|string',
51+
'start_date' => 'required|date',
52+
'end_date' => 'required|date|after_or_equal:start_date',
53+
]);
54+
55+
$importantDate = $legalCase->importantDates()->create([
56+
...$validated,
57+
'created_by' => Auth::id(),
58+
]);
59+
60+
return redirect()->back()->with('success', 'Fecha importante creada exitosamente');
61+
}
62+
63+
public function update(Request $request, LegalCase $legalCase, CaseImportantDate $importantDate)
64+
{
65+
$validated = $request->validate([
66+
'title' => 'required|string|max:255',
67+
'description' => 'nullable|string',
68+
'start_date' => 'required|date',
69+
'end_date' => 'required|date|after_or_equal:start_date',
70+
'is_expired' => 'required|boolean',
71+
]);
72+
73+
$importantDate->update($validated);
74+
75+
return redirect()->back()->with('success', 'Fecha importante actualizada exitosamente');
76+
}
77+
78+
public function destroy(LegalCase $legalCase, CaseImportantDate $importantDate)
79+
{
80+
$importantDate->delete();
81+
82+
return redirect()->back()->with('success', 'Fecha importante eliminada exitosamente');
83+
}
84+
85+
public function setExpired(Request $request, LegalCase $legalCase, CaseImportantDate $importantDate)
86+
{
87+
$request->validate([
88+
'is_expired' => 'required|boolean',
89+
]);
90+
$importantDate->is_expired = $request->input('is_expired');
91+
$importantDate->save();
92+
return redirect()->back()->with('success', 'Estado de vencimiento actualizado');
93+
}
94+
}

app/Http/Controllers/LegalCaseController.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public function show(string $id)
3838
{
3939
$legalCase = \App\Models\LegalCase::with(['caseType', 'individuals', 'legalEntities'])->findOrFail($id);
4040
$events = $legalCase->events()->with('user')->orderByDesc('date')->get();
41+
42+
// Obtener la próxima fecha importante directamente de la base de datos
43+
$nextImportantDate = $legalCase->importantDates()
44+
->where('is_expired', false)
45+
->whereDate('end_date', '>=', now()->toDateString())
46+
->orderBy('end_date')
47+
->first();
4148

4249
// Depurar los datos de roles
4350
Log::debug('Individuos con roles:', $legalCase->individuals->map(function($individual) {
@@ -59,6 +66,11 @@ public function show(string $id)
5966
return \Inertia\Inertia::render('LegalCases/Show', [
6067
'legalCase' => $legalCase,
6168
'events' => $events,
69+
'nextImportantDate' => $nextImportantDate ? [
70+
'id' => $nextImportantDate->id,
71+
'title' => $nextImportantDate->title,
72+
'end_date' => $nextImportantDate->end_date->toDateString(),
73+
] : null,
6274
]);
6375
}
6476

app/Models/CaseImportantDate.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9+
10+
class CaseImportantDate extends Model
11+
{
12+
use HasFactory, SoftDeletes;
13+
14+
protected $fillable = [
15+
'legal_case_id',
16+
'title',
17+
'description',
18+
'start_date',
19+
'end_date',
20+
'is_expired',
21+
'created_by'
22+
];
23+
24+
protected $casts = [
25+
'start_date' => 'date',
26+
'end_date' => 'date',
27+
'is_expired' => 'boolean',
28+
];
29+
30+
public function legalCase(): BelongsTo
31+
{
32+
return $this->belongsTo(LegalCase::class);
33+
}
34+
35+
public function creator(): BelongsTo
36+
{
37+
return $this->belongsTo(User::class, 'created_by');
38+
}
39+
40+
public function isExpired(): bool
41+
{
42+
return $this->is_expired;
43+
}
44+
45+
public function isActive(): bool
46+
{
47+
return !$this->is_expired;
48+
}
49+
50+
public function getDaysRemaining(): int
51+
{
52+
if (!$this->isActive()) {
53+
return 0;
54+
}
55+
56+
return now()->diffInDays($this->end_date, false);
57+
}
58+
}

app/Models/LegalCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ public function events()
6363
{
6464
return $this->hasMany(CaseEvent::class);
6565
}
66+
67+
public function importantDates()
68+
{
69+
return $this->hasMany(CaseImportantDate::class);
70+
}
6671
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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('case_important_dates', function (Blueprint $table) {
12+
$table->id();
13+
$table->foreignId('legal_case_id')->constrained()->cascadeOnDelete();
14+
$table->string('title');
15+
$table->text('description')->nullable();
16+
$table->date('start_date');
17+
$table->date('end_date');
18+
$table->boolean('is_expired')->default(false);
19+
$table->foreignId('created_by')->constrained('users');
20+
$table->timestamps();
21+
$table->softDeletes();
22+
});
23+
}
24+
25+
public function down(): void
26+
{
27+
Schema::dropIfExists('case_important_dates');
28+
}
29+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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('case_important_dates', function (Blueprint $table) {
15+
$table->softDeletes();
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('case_important_dates', function (Blueprint $table) {
25+
$table->dropSoftDeletes();
26+
});
27+
}
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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('case_important_dates', function (Blueprint $table) {
15+
$table->date('end_date')->nullable();
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('case_important_dates', function (Blueprint $table) {
25+
$table->dropColumn('end_date');
26+
});
27+
}
28+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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('case_important_dates', function (Blueprint $table) {
15+
$table->date('start_date')->nullable()->after('description');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('case_important_dates', function (Blueprint $table) {
25+
$table->dropColumn('start_date');
26+
});
27+
}
28+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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('case_important_dates', function (Blueprint $table) {
15+
$table->foreignId('created_by')->nullable()->constrained('users');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('case_important_dates', function (Blueprint $table) {
25+
$table->dropForeign(['created_by']);
26+
$table->dropColumn('created_by');
27+
});
28+
}
29+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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('case_important_dates', function (Blueprint $table) {
15+
$table->dropColumn('date');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('case_important_dates', function (Blueprint $table) {
25+
$table->date('date')->nullable();
26+
});
27+
}
28+
};

0 commit comments

Comments
 (0)