connect_error) { die("Conexión fallida: " . $conn->connect_error); } class PDF extends FPDF { // Cabecera de página function Header() { global $conn; // Acceder a $conn dentro de la función $consulta_info = $conn->query("select * from trabajadores"); $dato_info = $consulta_info->fetch_object(); $this->Image('ibcs.jpg', 270, 5, 20); // Logo de la empresa, moverDerecha, moverAbajo, tamañoIMG $this->SetFont('Arial', 'B', 19); $this->Cell(95); $this->SetTextColor(0, 0, 0); $this->Cell(110, 15, utf8_decode($dato_info->nombre), 1, 1, 'C', 0); // AnchoCelda, AltoCelda, titulo, borde, saltoLinea, posicion, ColorFondo $this->Ln(3); $this->SetTextColor(103); $this->Cell(180); $this->SetFont('Arial', 'B', 10); $this->Cell(96, 10, utf8_decode("Ubicación : " . $dato_info->ubicacion), 0, 0, '', 0); $this->Ln(5); $this->Cell(180); $this->SetFont('Arial', 'B', 10); $this->Cell(59, 10, utf8_decode("Teléfono : " . $dato_info->telefono), 0, 0, '', 0); $this->Ln(5); $this->Cell(180); $this->SetFont('Arial', 'B', 10); $this->Cell(85, 10, utf8_decode("RUC : " . $dato_info->ruc), 0, 0, '', 0); $this->Ln(10); $this->SetTextColor(0, 95, 189); $this->Cell(100); $this->SetFont('Arial', 'B', 15); $this->Cell(100, 10, utf8_decode("REPORTE DE TRABAJADORES "), 0, 1, 'C', 0); $this->Ln(7); $this->SetFillColor(21, 32, 54); $this->SetTextColor(0, 0, 0); $this->SetDrawColor(163, 163, 163); $this->SetFont('Arial', 'B', 11); $this->Cell(15, 10, utf8_decode('ID'), 1, 0, 'C', 1); $this->Cell(80, 10, utf8_decode('nombre'), 1, 0, 'C', 1); $this->Cell(30, 10, utf8_decode('apellido'), 1, 0, 'C', 1); $this->Cell(50, 10, utf8_decode('seguro_social'), 1, 0, 'C', 1); $this->Cell(50, 10, utf8_decode('cargo'), 1, 1, 'C', 1); } // Pie de página function Footer() { $this->SetY(-15); $this->SetFont('Arial', 'I', 8); $this->Cell(0, 10, utf8_decode('Página ') . $this->PageNo() . '/{nb}', 0, 0, 'C'); $this->SetY(-15); $this->SetFont('Arial', 'I', 8); $hoy = date('d/m/Y'); $this->Cell(540, 10, utf8_decode($hoy), 0, 0, 'C'); } } $pdf = new PDF(); $pdf->AddPage("landscape"); $pdf->AliasNbPages(); // Consulta de datos $consulta_reporte_asistencia = $conn->query("SELECT * FROM trabajadores"); while ($datos_reporte = $consulta_reporte_asistencia->fetch_object()) { $pdf->Cell(15, 10, utf8_decode($datos_reporte->ID), 1, 0, 'C', 0); $pdf->Cell(80, 10, utf8_decode($datos_reporte->nombre), 1, 0, 'C', 0); $pdf->Cell(30, 10, utf8_decode($datos_reporte->apellido), 1, 0, 'C', 0); $pdf->Cell(50, 10, utf8_decode($datos_reporte->seguro_social), 1, 0, 'C', 0); $pdf->Cell(50, 10, utf8_decode($datos_reporte->cargo), 1, 1, 'C', 0); } // Consulta de datos para la gráfica $consulta_cargos = $conn->query("SELECT cargo, COUNT(*) AS cantidad FROM trabajadores GROUP BY cargo"); $cargos = array(); $pdf->Output('Reporte_Trabajadores.pdf', 'I'); ?>