fix: actualizar tipos de acción en registros de vehículos y migración para 'sustitucion_primera_vez'
This commit is contained in:
parent
23ba2a03f9
commit
04c9fe2d5a
@ -868,10 +868,10 @@ public function excelGeneral(Request $request)
|
|||||||
'tag',
|
'tag',
|
||||||
'cancellationReason'
|
'cancellationReason'
|
||||||
])
|
])
|
||||||
->whereIn('action_type', ['inscripcion', 'sustitucion', 'actualizacion', 'cancelacion'])
|
->whereIn('action_type', ['sustitucion_primera_vez', 'sustitucion', 'actualizacion', 'cancelacion'])
|
||||||
->where(function ($query) use ($fechaInicio, $fechaFin) {
|
->where(function ($query) use ($fechaInicio, $fechaFin) {
|
||||||
$query->where(function ($q) use ($fechaInicio, $fechaFin) {
|
$query->where(function ($q) use ($fechaInicio, $fechaFin) {
|
||||||
$q->whereIn('action_type', ['inscripcion', 'sustitucion', 'actualizacion'])
|
$q->whereIn('action_type', ['sustitucion_primera_vez', 'sustitucion', 'actualizacion'])
|
||||||
->whereBetween('created_at', [$fechaInicio, $fechaFin]);
|
->whereBetween('created_at', [$fechaInicio, $fechaFin]);
|
||||||
})
|
})
|
||||||
->orWhere(function ($q) use ($fechaInicio, $fechaFin) {
|
->orWhere(function ($q) use ($fechaInicio, $fechaFin) {
|
||||||
@ -946,7 +946,7 @@ public function excelGeneral(Request $request)
|
|||||||
// Motivo
|
// Motivo
|
||||||
$motivo = $log->cancellationReason->reason ?? $log->cancellationReason->name ?? '';
|
$motivo = $log->cancellationReason->reason ?? $log->cancellationReason->name ?? '';
|
||||||
if ($log->action_type == 'sustitucion') $motivo = 'SUSTITUCIÓN';
|
if ($log->action_type == 'sustitucion') $motivo = 'SUSTITUCIÓN';
|
||||||
if ($log->action_type == 'inscripcion') $motivo = 'INSCRIPCIÓN';
|
if ($log->action_type == 'sustitucion_primera_vez') $motivo = 'SUSTITUCIÓN POR PRIMERA VEZ';
|
||||||
if ($log->action_type == 'actualizacion') $motivo = 'ACTUALIZACIÓN';
|
if ($log->action_type == 'actualizacion') $motivo = 'ACTUALIZACIÓN';
|
||||||
if ($log->action_type == 'cancelacion' && empty($motivo)) $motivo = 'DAÑADA';
|
if ($log->action_type == 'cancelacion' && empty($motivo)) $motivo = 'DAÑADA';
|
||||||
|
|
||||||
@ -1186,7 +1186,7 @@ public function exportSearchRecords(Request $request)
|
|||||||
'vin' => 'nullable|string',
|
'vin' => 'nullable|string',
|
||||||
'tag_number' => 'nullable|string',
|
'tag_number' => 'nullable|string',
|
||||||
'module_id' => 'nullable|integer|exists:modules,id',
|
'module_id' => 'nullable|integer|exists:modules,id',
|
||||||
'action_type' => 'nullable|string|in:inscripcion,sustitucion,cancelacion',
|
'action_type' => 'nullable|string|in:sustitucion_primera_vez,sustitucion,cancelacion',
|
||||||
'status' => 'nullable|string',
|
'status' => 'nullable|string',
|
||||||
'start_date' => 'nullable|date',
|
'start_date' => 'nullable|date',
|
||||||
'end_date' => 'nullable|date|after_or_equal:start_date',
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||||||
@ -1284,7 +1284,7 @@ public function exportSearchRecords(Request $request)
|
|||||||
|
|
||||||
// Obtener logs ordenados por fecha, excluyendo actualizaciones
|
// Obtener logs ordenados por fecha, excluyendo actualizaciones
|
||||||
$vehicleLogs = $vehicle->vehicleTagLogs
|
$vehicleLogs = $vehicle->vehicleTagLogs
|
||||||
->whereIn('action_type', ['inscripcion', 'sustitucion', 'cancelacion'])
|
->whereIn('action_type', ['sustitucion_primera_vez', 'sustitucion', 'cancelacion'])
|
||||||
->sortBy('created_at');
|
->sortBy('created_at');
|
||||||
|
|
||||||
// Generar una fila por cada log (cada acción en el historial)
|
// Generar una fila por cada log (cada acción en el historial)
|
||||||
|
|||||||
@ -162,7 +162,7 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
|||||||
VehicleTagLog::create([
|
VehicleTagLog::create([
|
||||||
'vehicle_id' => $vehicle->id,
|
'vehicle_id' => $vehicle->id,
|
||||||
'tag_id' => $tag->id,
|
'tag_id' => $tag->id,
|
||||||
'action_type' => 'sustitucion',
|
'action_type' => 'sustitucion_primera_vez',
|
||||||
'performed_by' => Auth::id(),
|
'performed_by' => Auth::id(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ public function searchRecord(Request $request)
|
|||||||
'vin' => 'nullable|string',
|
'vin' => 'nullable|string',
|
||||||
'tag_number' => 'nullable|string',
|
'tag_number' => 'nullable|string',
|
||||||
'module_id' => 'nullable|integer|exists:modules,id',
|
'module_id' => 'nullable|integer|exists:modules,id',
|
||||||
'action_type' => 'nullable|string|in:inscripcion,actualizacion,sustitucion,cancelacion',
|
'action_type' => 'nullable|string|in:sustitucion_primera_vez,actualizacion,sustitucion,cancelacion',
|
||||||
'status' => 'nullable|string',
|
'status' => 'nullable|string',
|
||||||
'start_date' => 'nullable|date',
|
'start_date' => 'nullable|date',
|
||||||
'end_date' => 'nullable|date|after_or_equal:start_date',
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
||||||
@ -426,7 +426,7 @@ public function searchRecord(Request $request)
|
|||||||
'tag_number' => $tag?->tag_number,
|
'tag_number' => $tag?->tag_number,
|
||||||
'status' => $tag?->status?->code ?? 'unknown',
|
'status' => $tag?->status?->code ?? 'unknown',
|
||||||
'assigned_at' => $vehicleLogs->where('tag_id', $tagId)
|
'assigned_at' => $vehicleLogs->where('tag_id', $tagId)
|
||||||
->whereIn('action_type', ['inscripcion', 'sustitucion'])
|
->whereIn('action_type', ['sustitucion_primera_vez', 'sustitucion'])
|
||||||
->first()?->created_at,
|
->first()?->created_at,
|
||||||
'cancelled_at' => $cancelLog?->cancellation_at,
|
'cancelled_at' => $cancelLog?->cancellation_at,
|
||||||
'is_current' => $tag?->id === $record->vehicle->tag?->id,
|
'is_current' => $tag?->id === $record->vehicle->tag?->id,
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public function cancellationReason()
|
|||||||
|
|
||||||
public function isInscription()
|
public function isInscription()
|
||||||
{
|
{
|
||||||
return $this->action_type === 'inscripcion';
|
return $this->action_type === 'sustitucion_primera_vez';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isUpdate()
|
public function isUpdate()
|
||||||
|
|||||||
@ -84,6 +84,10 @@
|
|||||||
"@php artisan migrate:fresh --seed",
|
"@php artisan migrate:fresh --seed",
|
||||||
"@php artisan passport:client --personal --name=Holos"
|
"@php artisan passport:client --personal --name=Holos"
|
||||||
],
|
],
|
||||||
|
"db:update": [
|
||||||
|
"@php artisan migrate",
|
||||||
|
"@php artisan migrate --path=database/migrations/data"
|
||||||
|
],
|
||||||
"jobs:start": [
|
"jobs:start": [
|
||||||
"pm2 start \"php artisan schedule:work\" --name holos-schedules",
|
"pm2 start \"php artisan schedule:work\" --name holos-schedules",
|
||||||
"pm2 start \"php artisan queue:work\" --name holos-queue"
|
"pm2 start \"php artisan queue:work\" --name holos-queue"
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// Paso 1: PRIMERO ampliar el ENUM para incluir 'sustitucion_primera_vez' (temporal)
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE vehicle_tags_logs
|
||||||
|
MODIFY COLUMN action_type ENUM(
|
||||||
|
'inscripcion',
|
||||||
|
'sustitucion_primera_vez',
|
||||||
|
'actualizacion',
|
||||||
|
'sustitucion',
|
||||||
|
'cancelacion'
|
||||||
|
) NOT NULL DEFAULT 'cancelacion'
|
||||||
|
");
|
||||||
|
|
||||||
|
// Paso 2: AHORA actualizar los datos existentes
|
||||||
|
DB::statement("UPDATE vehicle_tags_logs SET action_type = 'sustitucion_primera_vez' WHERE action_type = 'inscripcion'");
|
||||||
|
|
||||||
|
// Paso 3: FINALMENTE remover 'inscripcion' del ENUM
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE vehicle_tags_logs
|
||||||
|
MODIFY COLUMN action_type ENUM(
|
||||||
|
'sustitucion_primera_vez',
|
||||||
|
'actualizacion',
|
||||||
|
'sustitucion',
|
||||||
|
'cancelacion'
|
||||||
|
) NOT NULL DEFAULT 'cancelacion'
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
// Paso 1: PRIMERO agregar 'inscripcion' de vuelta al ENUM (temporal)
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE vehicle_tags_logs
|
||||||
|
MODIFY COLUMN action_type ENUM(
|
||||||
|
'inscripcion',
|
||||||
|
'sustitucion_primera_vez',
|
||||||
|
'actualizacion',
|
||||||
|
'sustitucion',
|
||||||
|
'cancelacion'
|
||||||
|
) NOT NULL DEFAULT 'cancelacion'
|
||||||
|
");
|
||||||
|
|
||||||
|
// Paso 2: AHORA revertir los datos
|
||||||
|
DB::statement("UPDATE vehicle_tags_logs SET action_type = 'inscripcion' WHERE action_type = 'sustitucion_primera_vez'");
|
||||||
|
|
||||||
|
// Paso 3: FINALMENTE remover 'sustitucion_primera_vez' del ENUM
|
||||||
|
DB::statement("
|
||||||
|
ALTER TABLE vehicle_tags_logs
|
||||||
|
MODIFY COLUMN action_type ENUM(
|
||||||
|
'inscripcion',
|
||||||
|
'actualizacion',
|
||||||
|
'sustitucion',
|
||||||
|
'cancelacion'
|
||||||
|
) NOT NULL DEFAULT 'cancelacion'
|
||||||
|
");
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -40,7 +40,6 @@ public function run(): void
|
|||||||
] = $this->onCRUD('users', $users, 'api');
|
] = $this->onCRUD('users', $users, 'api');
|
||||||
|
|
||||||
$userSettings = $this->onPermission('users.settings', 'Configuración de usuarios', $users, 'api');
|
$userSettings = $this->onPermission('users.settings', 'Configuración de usuarios', $users, 'api');
|
||||||
$userOnline = $this->onPermission('users.online', 'Usuarios en linea', $users, 'api');
|
|
||||||
|
|
||||||
$roles = PermissionType::firstOrCreate([
|
$roles = PermissionType::firstOrCreate([
|
||||||
'name' => 'Roles'
|
'name' => 'Roles'
|
||||||
@ -53,23 +52,6 @@ public function run(): void
|
|||||||
$roleDestroy
|
$roleDestroy
|
||||||
] = $this->onCRUD('roles', $roles, 'api');
|
] = $this->onCRUD('roles', $roles, 'api');
|
||||||
|
|
||||||
$pulse = PermissionType::firstOrCreate([
|
|
||||||
'name' => 'Sistema'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$systemPulse = $this->onPermission('pulse', 'Monitoreo de Pulse', $pulse, 'api');
|
|
||||||
|
|
||||||
$pulse = PermissionType::firstOrCreate([
|
|
||||||
'name' => 'Historial de actividades'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$activityIndex = $this->onIndex(
|
|
||||||
code: 'activities',
|
|
||||||
type: $pulse,
|
|
||||||
guardName: 'api'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$modules = PermissionType::firstOrCreate([ // Modulos
|
$modules = PermissionType::firstOrCreate([ // Modulos
|
||||||
'name' => 'Módulos'
|
'name' => 'Módulos'
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user