fix: cambios a excel, pdf de constancias dañadas y canceladas, logos a excel

This commit is contained in:
Juan Felipe Zapata Moreno 2026-01-26 09:21:10 -06:00
parent 392b155367
commit 64196c9d5b
6 changed files with 41 additions and 20 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ yarn-error.log
/.nova
/.vscode
/.zed
CLAUDE.md

View File

@ -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]

View File

@ -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

View File

@ -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;

View File

@ -121,7 +121,7 @@
<td class="data-value">{{ $cancellation['folio'] ?? '' }}</td>
</tr>
<tr class="data-row">
<td class="data-label">TAG NUMBER:</td>
<td class="data-label">ID CONSTANCIA (CHIP):</td>
<td class="data-value">{{ $cancellation['tag_number'] ?? 'N/A' }}</td>
</tr>
<tr class="data-row">

View File

@ -121,9 +121,13 @@
<td class="data-value">{{ $cancellation['folio'] ?? '' }}</td>
</tr>
<tr class="data-row">
<td class="data-label">TAG NUMBER:</td>
<td class="data-label">ID CONSTANCIA (CHIP):</td>
<td class="data-value">{{ $cancellation['tag_number'] ?? 'N/A' }}</td>
</tr>
<tr class="data-row">
<td class="data-label">PLACA:</td>
<td class="data-value">{{ $cancellation['placa'] ?? 'N/A' }}</td>
</tr>
<tr class="data-row">
<td class="data-label">MOTIVO:</td>
<td class="data-value">{{ mb_strtoupper($cancellation['motivo'] ?? '') }}</td>