diff --git a/.gitignore b/.gitignore index e69db04..e735fcc 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ yarn-error.log /.nova /.vscode /.zed +CLAUDE.md diff --git a/app/Http/Controllers/Repuve/ExcelController.php b/app/Http/Controllers/Repuve/ExcelController.php index f89f40e..edfc256 100644 --- a/app/Http/Controllers/Repuve/ExcelController.php +++ b/app/Http/Controllers/Repuve/ExcelController.php @@ -208,7 +208,7 @@ public function vehicleActualizaciones(Request $request) // BARRA ROJA $rowRedBar = 12; - $sheet->mergeCells("A{$rowRedBar}:I{$rowRedBar}"); + $sheet->mergeCells("A{$rowRedBar}:H{$rowRedBar}"); $sheet->getStyle("A{$rowRedBar}")->applyFromArray([ 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => '900000']], ]); @@ -304,12 +304,12 @@ public function constanciasSustituidas(Request $request) ->where('action_type', 'sustitucion') ->whereNotNull('cancellation_at') ->when($moduleId, function ($query) use ($moduleId) { - $query->whereHas('vehicle.records', function ($q) use ($moduleId) { + $query->whereHas('performedBy', function ($q) use ($moduleId) { $q->where('module_id', $moduleId); }); }) - ->whereBetween('created_at', [$fechaInicio, $fechaFin]) - ->orderBy('created_at', 'asc') + ->whereBetween('cancellation_at', [$fechaInicio, $fechaFin]) + ->orderBy('cancellation_at', 'asc') ->get(); if ($logs->isEmpty()) { @@ -617,14 +617,14 @@ public function constanciasCanceladas(Request $request) $data = $allLogs->map(function ($log) { return [ 'folio' => $log->tag->folio ?? 'S/F', - 'chip' => $log->tag->rfid ?? '', + 'tag_number' => $log->tag->tag_number ?? 'N/A', 'fecha' => $log->cancellation_at ? Carbon::parse($log->cancellation_at)->format('d/m/Y') : '', 'motivo' => $log->cancellationReason->name ?? 'DAÑADA', ]; }); // CONFIGURACIÓN EXCEL Y ESTILOS - $fileName = 'Constancias_Canceladas_' . $fechaInicio->format('Ymd') . '.xlsx'; + $fileName = 'Constancias_dañadas_' . $fechaInicio->format('Ymd') . '.xlsx'; $filePath = storage_path('app/temp/' . $fileName); if (!file_exists(dirname($filePath))) mkdir(dirname($filePath), 0755, true); @@ -781,13 +781,15 @@ public function constanciasCanceladas(Request $request) $sheet->setCellValue("C{$h1}", "FOLIO DE LA\nCONSTANCIA"); $sheet->mergeCells("G{$h1}:I{$h2}"); - $sheet->setCellValue("G{$h1}", "FECHA DE\nCANCELACIÓN"); + $sheet->setCellValue("G{$h1}", "ID DE LA\nCONSTANCIA (CHIP)"); - $sheet->mergeCells("J{$h1}:M{$h2}"); - $sheet->setCellValue("J{$h1}", "MOTIVO DE\nCANCELACIÓN"); + $sheet->mergeCells("J{$h1}:K{$h2}"); + $sheet->setCellValue("J{$h1}", "FECHA DE\nCANCELACIÓN"); + $sheet->mergeCells("L{$h1}:N{$h2}"); + $sheet->setCellValue("L{$h1}", "MOTIVO DE\nCANCELACIÓN"); // Aplicar estilo beige - $sheet->getStyle("A{$h1}:M{$h2}")->applyFromArray($styleTableHeader); + $sheet->getStyle("A{$h1}:N{$h2}")->applyFromArray($styleTableHeader); $sheet->getRowDimension($h1)->setRowHeight(20); $sheet->getRowDimension($h2)->setRowHeight(25); @@ -803,13 +805,16 @@ public function constanciasCanceladas(Request $request) $sheet->setCellValue("C{$row}", $item['folio']); $sheet->mergeCells("G{$row}:I{$row}"); - $sheet->setCellValue("G{$row}", $item['fecha']); + $sheet->setCellValue("G{$row}", $item['tag_number']); - $sheet->mergeCells("J{$row}:M{$row}"); - $sheet->setCellValue("J{$row}", $item['motivo']); + $sheet->mergeCells("J{$row}:K{$row}"); + $sheet->setCellValue("J{$row}", $item['fecha']); + + $sheet->mergeCells("L{$row}:N{$row}"); + $sheet->setCellValue("L{$row}", $item['motivo']); // Estilos de celda - $sheet->getStyle("A{$row}:M{$row}")->applyFromArray([ + $sheet->getStyle("A{$row}:N{$row}")->applyFromArray([ 'borders' => ['allBorders' => ['borderStyle' => PhpSpreadsheetBorder::BORDER_THIN]], 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER, 'vertical' => Alignment::VERTICAL_CENTER, 'wrapText' => true], 'font' => ['size' => 9] diff --git a/app/Http/Controllers/Repuve/RecordController.php b/app/Http/Controllers/Repuve/RecordController.php index bc602a9..f01aac2 100644 --- a/app/Http/Controllers/Repuve/RecordController.php +++ b/app/Http/Controllers/Repuve/RecordController.php @@ -425,6 +425,19 @@ private function cancellationData(Tag $tag) $data['id_chip'] = $tag->vehicle->id_chip ?? ''; $data['placa'] = $tag->vehicle->placa ?? ''; $data['niv'] = $tag->vehicle->niv ?? ''; + } else { + // Si el tag no tiene vehicle_id, buscar en el último log + $lastLog = $tag->vehicleTagLogs() + ->with('vehicle') + ->whereNotNull('vehicle_id') + ->latest('created_at') + ->first(); + + if ($lastLog && $lastLog->vehicle) { + $data['id_chip'] = $lastLog->vehicle->id_chip ?? ''; + $data['placa'] = $lastLog->vehicle->placa ?? ''; + $data['niv'] = $lastLog->vehicle->niv ?? ''; + } } // Buscar log de cancelación directa diff --git a/app/Http/Controllers/Repuve/UpdateController.php b/app/Http/Controllers/Repuve/UpdateController.php index 2bd574b..5b66016 100644 --- a/app/Http/Controllers/Repuve/UpdateController.php +++ b/app/Http/Controllers/Repuve/UpdateController.php @@ -45,7 +45,6 @@ public function tagSubstitution(Request $request) $request->validate([ 'folio' => 'required|string|exists:records,folio', 'new_tag_folio' => 'required|string|exists:tags,folio', - 'new_tag_folio' => 'required|string', 'cancellation_reason_id' => 'nullable|exists:catalog_cancellation_reasons,id', 'cancellation_observations' => 'nullable|string|max:500', ]); @@ -157,9 +156,8 @@ public function tagSubstitution(Request $request) ]); // Actualizar el folio del record con el folio del nuevo TAG - $record->update([ - 'folio' => $newTagFolio - ]); + $this->moveRecordFiles($record->id, $folio, $newTagFolio); + $record->update(['folio' => $newTagFolio]); if (!$newTag->tag_number) { $newTag->tag_number = $newTagNumber; diff --git a/resources/views/pdfs/tag.blade.php b/resources/views/pdfs/tag.blade.php index 6711fa9..cf6155e 100644 --- a/resources/views/pdfs/tag.blade.php +++ b/resources/views/pdfs/tag.blade.php @@ -121,7 +121,7 @@ {{ $cancellation['folio'] ?? '' }} - TAG NUMBER: + ID CONSTANCIA (CHIP): {{ $cancellation['tag_number'] ?? 'N/A' }} diff --git a/resources/views/pdfs/tag_cancelada.blade.php b/resources/views/pdfs/tag_cancelada.blade.php index 1d107b7..3015c58 100644 --- a/resources/views/pdfs/tag_cancelada.blade.php +++ b/resources/views/pdfs/tag_cancelada.blade.php @@ -121,9 +121,13 @@ {{ $cancellation['folio'] ?? '' }} - TAG NUMBER: + ID CONSTANCIA (CHIP): {{ $cancellation['tag_number'] ?? 'N/A' }} + + PLACA: + {{ $cancellation['placa'] ?? 'N/A' }} + MOTIVO: {{ mb_strtoupper($cancellation['motivo'] ?? '') }}