|
|
@@ -157,4 +157,131 @@ return response()->streamDownload(function () use ($writer) {
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public function exportarAlumnosRegistro()
|
|
|
+ {
|
|
|
+ // === Reutilizamos tu lógica para obtener los datos ===
|
|
|
+ $data = DB::table('usuarios')
|
|
|
+ ->leftJoin('registroacademico', 'usuarios.idUsuario', '=', 'registroacademico.idAlumno')
|
|
|
+ ->leftJoin('usuarios as u2', 'u2.idUsuario', '=', 'registroacademico.usuarioRegistro')
|
|
|
+ ->select(
|
|
|
+ DB::raw("CONCAT(COALESCE(usuarios.primerNombre, ''), ' ', COALESCE(usuarios.segundoNombre, ''), ' ', COALESCE(usuarios.apellidoPaterno, ''), ' ', COALESCE(usuarios.apellidoMaterno, '')) AS nombreCompleto"),
|
|
|
+ DB::raw("CONCAT(COALESCE(u2.primerNombre, ''), ' ', COALESCE(u2.segundoNombre, ''), ' ', COALESCE(u2.apellidoPaterno, ''), ' ', COALESCE(u2.apellidoMaterno, '')) AS nombrePadre"),
|
|
|
+ 'usuarios.idUsuario',
|
|
|
+ 'registroacademico.*'
|
|
|
+ )
|
|
|
+ ->where('usuarios.tipoUsuario', 'AL')
|
|
|
+ ->get()
|
|
|
+ ->map(function($item) {
|
|
|
+ $hasEmptyField = collect($item)->some(fn($v) => $v === null || $v === '');
|
|
|
+ return [
|
|
|
+ 'idUsuario' => $item->idUsuario,
|
|
|
+ 'quienRegistra' => $item->nombrePadre ?: 'No Aplica',
|
|
|
+ 'ultActualizacion' => $item->lastUpdate ?: 'No Aplica',
|
|
|
+ 'nombreCompleto' => $item->nombreCompleto,
|
|
|
+ 'registroAcCompleto' => $hasEmptyField ? 'No' : 'Sí'
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ $dataAd = DB::table('usuarios')
|
|
|
+ ->select('usuarios.idUsuario','registroadministrativo.*')
|
|
|
+ ->leftJoin('registroadministrativo', 'usuarios.idUsuario', '=', 'registroadministrativo.idAlumno')
|
|
|
+ ->where('usuarios.tipoUsuario', 'AL')
|
|
|
+ ->get()
|
|
|
+ ->map(function($item) {
|
|
|
+ $hasEmptyField = collect($item)->some(fn($v) => $v === null || $v === '');
|
|
|
+ return [
|
|
|
+ 'idUsuario' => $item->idUsuario,
|
|
|
+ 'registroAdCompleto' => $hasEmptyField ? 'No' : 'Sí'
|
|
|
+ ];
|
|
|
+ });
|
|
|
+
|
|
|
+ $completo = $dataAd->map(function($item) use ($data) {
|
|
|
+ $registro = $data->firstWhere('idUsuario', $item['idUsuario']);
|
|
|
+ return [
|
|
|
+ 'idUsuario' => $item['idUsuario'],
|
|
|
+ 'quienRegistra' => $registro['quienRegistra'],
|
|
|
+ 'ultActualizacion' => $registro['ultActualizacion'],
|
|
|
+ 'nombreCompleto' => $registro['nombreCompleto'],
|
|
|
+ 'registroAcCompleto' => $registro['registroAcCompleto'],
|
|
|
+ 'registroAdCompleto' => $item['registroAdCompleto']
|
|
|
+ ];
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ // === Ahora formateamos el Excel ===
|
|
|
+ $spreadsheet = new Spreadsheet();
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
+
|
|
|
+ $titulo = "REPORTE DE ALUMNOS";
|
|
|
+ $headers = ['ID', 'Alumno', 'Quién Registró', 'Última Actualización', 'Académico Completo', 'Administrativo Completo'];
|
|
|
+
|
|
|
+ // Estilos título
|
|
|
+ $sheet->mergeCells('A1:F2');
|
|
|
+ $sheet->setCellValue('A1', $titulo);
|
|
|
+ $sheet->getStyle('A1:F2')->applyFromArray([
|
|
|
+ 'font' => ['bold' => true, 'size' => 18, 'name' => 'Century', 'color' => ['rgb' => 'FFFFFF']],
|
|
|
+ 'alignment' => ['horizontal' => 'center', 'vertical' => 'center'],
|
|
|
+ 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => '4F81BD']],
|
|
|
+ ]);
|
|
|
+ $sheet->getRowDimension(1)->setRowHeight(50);
|
|
|
+
|
|
|
+ // Logo
|
|
|
+ $logoPathS3 = DB::table('personalizar')->value('PERLOGO');
|
|
|
+ if ($logoPathS3 && Storage::disk('s3')->exists($logoPathS3)) {
|
|
|
+ $tempLogoPath = tempnam(sys_get_temp_dir(), 'logo');
|
|
|
+ file_put_contents($tempLogoPath, Storage::disk('s3')->get($logoPathS3));
|
|
|
+ $logo = new Drawing();
|
|
|
+ $logo->setPath($tempLogoPath);
|
|
|
+ $logo->setHeight(80);
|
|
|
+ $logo->setCoordinates('A1');
|
|
|
+ $logo->setWorksheet($sheet);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Encabezados
|
|
|
+ $sheet->fromArray($headers, null, 'A4');
|
|
|
+ $sheet->getStyle("A4:F4")->applyFromArray([
|
|
|
+ 'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF'], 'size' => 12],
|
|
|
+ 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => '4F81BD']],
|
|
|
+ 'alignment' => ['horizontal' => 'center'],
|
|
|
+ 'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN]],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // Datos
|
|
|
+ $row = 5;
|
|
|
+ foreach ($completo as $index => $item) {
|
|
|
+ $sheet->fromArray([
|
|
|
+ $item['idUsuario'],
|
|
|
+ $item['nombreCompleto'],
|
|
|
+ $item['quienRegistra'],
|
|
|
+ $item['ultActualizacion'],
|
|
|
+ $item['registroAcCompleto'],
|
|
|
+ $item['registroAdCompleto'],
|
|
|
+ ], null, "A$row");
|
|
|
+
|
|
|
+ $fillColor = $index % 2 === 0 ? 'F2F2F2' : 'FFFFFF';
|
|
|
+ $sheet->getStyle("A$row:F$row")->applyFromArray([
|
|
|
+ 'fill' => ['fillType' => Fill::FILL_SOLID, 'startColor' => ['rgb' => $fillColor]],
|
|
|
+ 'font' => ['name' => 'Calibri', 'size' => 11],
|
|
|
+ 'borders' => ['allBorders' => ['borderStyle' => Border::BORDER_THIN, 'color' => ['rgb' => 'BFBFBF']]],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $row++;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (range('A', 'F') as $col) {
|
|
|
+ $sheet->getColumnDimension($col)->setAutoSize(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ $sheet->setAutoFilter("A4:F4");
|
|
|
+
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $filename = "Alumnos_Registro.xlsx";
|
|
|
+
|
|
|
+ return response()->streamDownload(function () use ($writer) {
|
|
|
+ $writer->save('php://output');
|
|
|
+ }, $filename, [
|
|
|
+ 'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
}
|
|
|
+
|