Example #1
0
/**
 * Generador de Reportes
 *
 * @category Kumbia
 * @package Report
 * @copyright Copyright (c) 2005-2007 Andres Felipe Gutierrez (andresfelipe at vagoogle.net)
 * @license http://www.kumbia.org/license.txt GNU/GPL
 *
 */
function htm($result, $sumArray, $title, $weighArray, $headerArray)
{
    $config = Config::read('config');
    $active_app = Router::get_application();
    $file = md5(uniqid());
    $content = "\n<html>\n <head>\n   <title>REPORTE DE " . strtoupper($title) . "</title>\n </head>\n <body bgcolor='white'>\n <div style='font-size:20px;font-family:Verdana;color:#000000'>" . strtoupper($config->{$active_app}->name) . "</div>\n\n <div style='font-size:18px;font-family:Verdana;color:#000000'>REPORTE DE " . strtoupper($title) . "</div>\n\n <div style='font-size:18px;font-family:Verdana;color:#000000'>" . date("Y-m-d") . "</div>\n\n <br/>\n <table cellspacing='0' border=1 style='border:1px solid #969696'>\n ";
    $content .= "<tr bgcolor='#F2F2F2'>\n";
    for ($i = 0; $i <= count($headerArray) - 1; $i++) {
        $content .= "<th style='font-family:Verdana;font-size:12px'>" . $headerArray[$i] . "</th>\n";
    }
    $content .= "</tr>\n";
    $l = 5;
    foreach ($result as $row) {
        $content .= "<tr bgcolor='white'>\n";
        for ($i = 0; $i <= count($row) - 1; $i++) {
            if (is_numeric($row[$i])) {
                $content .= "<td style='font-family:Verdana;font-size:12px' align='center'>{$row[$i]}</td>";
            } else {
                $content .= "<td style='font-family:Verdana;font-size:12px'>{$row[$i]}&nbsp;</td>";
            }
        }
        $content .= "</tr>\n";
        $l++;
    }
    file_put_contents("public/temp/{$file}.html", $content);
    if (isset($raw_output)) {
        print "<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".html', null);  </script>";
    } else {
        Generator::forms_print("<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".html', null);  </script>");
    }
}
Example #2
0
File: xls.php Project: acampos9/SGC
/**
 * Genera un reporte en Excel
 *
 * @param array $result
 * @param array $sumArray
 * @param string $title
 * @param array $weightArray
 * @param array $headerArray
 */
function xls($result, $sumArray, $title, $weightArray, $headerArray)
{
    error_reporting(0);
    $file = md5(uniqid());
    $config = Config::read('config');
    $active_app = Router::get_application();
    $workbook = new Spreadsheet_Excel_Writer("public/temp/{$file}.xls");
    $worksheet =& $workbook->addWorksheet();
    $titulo_verdana =& $workbook->addFormat(array('fontfamily' => 'Verdana', 'size' => 20));
    $titulo_verdana2 =& $workbook->addFormat(array('fontfamily' => 'Verdana', 'size' => 18));
    $workbook->setCustomColor(12, 0xf2, 0xf2, 0xf2);
    $column_title =& $workbook->addFormat(array('fontfamily' => 'Verdana', 'size' => 12, 'fgcolor' => 12, 'border' => 1, 'bordercolor' => 'black', "halign" => 'center'));
    $column =& $workbook->addFormat(array('fontfamily' => 'Verdana', 'size' => 11, 'border' => 1, 'bordercolor' => 'black'));
    $column_centered =& $workbook->addFormat(array('fontfamily' => 'Verdana', 'size' => 11, 'border' => 1, 'bordercolor' => 'black', "halign" => 'center'));
    $worksheet->write(0, 0, strtoupper($config->{$active_app}->name), $titulo_verdana);
    $worksheet->write(1, 0, "REPORTE DE " . strtoupper($title), $titulo_verdana2);
    $worksheet->write(2, 0, "FECHA " . date("Y-m-d"), $titulo_verdana2);
    for ($i = 0; $i <= count($headerArray) - 1; $i++) {
        $worksheet->setColumn($i, $i, $weightArray[$i]);
        $worksheet->write(4, $i, $headerArray[$i], $column_title);
    }
    $l = 5;
    foreach ($result as $row) {
        for ($i = 0; $i <= count($row) - 1; $i++) {
            if (!is_numeric($row[$i])) {
                $worksheet->writeString($l, $i, $row[$i], $column);
            } else {
                $worksheet->writeString($l, $i, $row[$i], $column_centered);
            }
        }
        $l++;
    }
    $workbook->close();
    error_reporting(E_ALL ^ E_STRICT);
    if (isset($raw_output)) {
        print "<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".xls', null);  </script>";
    } else {
        Generator::forms_print("<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".xls', null);  </script>");
    }
}
Example #3
0
/**
 * Genera un reporte en PDF
 *
 * @param array $result
 * @param array $sumArray
 * @param string $title
 * @param array $weightArray
 * @param array $headerArray
 */
function pdf($result, $sumArray, $title, $weightArray, $headerArray)
{
    $config = Config::read('config');
    $active_app = Router::get_application();
    //Orientación
    if ($sumArray > 200) {
        $orientation = 'L';
    } else {
        $orientation = 'P';
    }
    $numRows = 140;
    //Tipo de Papel
    if ($sumArray > 250) {
        $paper = 'legal';
    } else {
        $paper = 'letter';
    }
    if ($paper == 'letter' && $orientation == 'P') {
        $widthPage = 220;
        $numRows = 42;
    }
    if ($paper == 'legal' && $orientation == 'L') {
        $widthPage = 355;
        $numRows = 30;
    }
    if ($paper == 'letter' && $orientation == 'L') {
        $widthPage = 270;
        $numRows = 30;
    }
    //Crear Documento PDF
    $pdf = new PDF($orientation, 'mm', $paper);
    $pdf->Open();
    $pdf->AddPage();
    //Nombre del Listado
    $pdf->SetFillColor(255, 255, 255);
    $pdf->AddFont('Verdana', '', 'verdana.php');
    $pdf->SetFont('Verdana', '', 14);
    $pdf->SetY(20);
    $pdf->SetX(0);
    $pdf->Ln();
    if ($config->{$active_app}->name) {
        $pdf->MultiCell(0, 6, strtoupper($config->{$active_app}->name), 0, "C", 0);
    }
    $pdf->MultiCell(0, 6, "REPORTE DE " . strtoupper($title), 0, "C", 0);
    $pdf->SetFont('Verdana', '', 12);
    if (isset($_SESSION['fecsis'])) {
        $pdf->MultiCell(0, 6, "FECHA " . date("Y-m-d"), 0, "C", 0);
    }
    $pdf->Ln();
    //Colores, ancho de línea y fuente en negrita
    $pdf->SetFillColor(0xf2, 0xf2, 0xf2);
    $pdf->SetTextColor(0);
    $pdf->SetDrawColor(0, 0, 0);
    $pdf->SetLineWidth(0.2);
    $pdf->SetFont('Arial', 'B', 10);
    if ($weightArray[0] < 11) {
        $weightArray[0] = 11;
    }
    //Parametros del Reporte
    $pos = floor($widthPage / 2 - $sumArray / 2);
    $pdf->SetX($pos);
    for ($i = 0; $i <= count($headerArray) - 1; $i++) {
        $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1);
    }
    $pdf->Ln();
    //Restauración de colores y fuentes
    $pdf->SetFillColor(224, 235, 255);
    $pdf->SetTextColor(0);
    $pdf->SetFont('Arial', 'B', 7);
    //print_r($weightArray);
    //Buscamos y listamos
    $n = 1;
    $p = 1;
    $t = 0;
    foreach ($result as $row) {
        //$pdf->Cell(Ancho, Alto, contenido, ?, ?, Align)
        if ($n > $numRows || $p == 1 && $n > $numRows - 3) {
            $pdf->AddPage($orientation);
            $pdf->SetY(30);
            $pdf->SetX($pos);
            $pdf->SetFillColor(0xf2, 0xf2, 0xf2);
            $pdf->SetTextColor(0);
            $pdf->SetDrawColor(0, 0, 0);
            $pdf->SetLineWidth(0.2);
            $pdf->SetFont('Arial', 'B', 10);
            for ($i = 0; $i < count($headerArray); $i++) {
                $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1);
            }
            $pdf->Ln();
            $pdf->SetFillColor(224, 235, 255);
            $pdf->SetTextColor(0);
            $pdf->SetFont('Arial', 'B', 7);
            $n = 1;
            $p++;
        }
        $pdf->SetX($pos);
        for ($i = 0; $i <= count($row) - 1; $i++) {
            if (is_numeric($row[$i])) {
                $pdf->Cell($weightArray[$i], 5, trim($row[$i]), 'LRTB', 0, 'C');
            } else {
                $pdf->Cell($weightArray[$i], 5, trim($row[$i]), 'LRTB', 0, 'L');
            }
        }
        $n++;
        $t++;
        $pdf->Ln();
    }
    $pdf->SetX($pos);
    $pdf->SetFont('Arial', 'B', 7);
    $pdf->SetFillColor(0xf2, 0xf2, 0xf2);
    $pdf->Cell($weightArray[0], 5, "TOTAL", 'LRTB', 0, 'R');
    $pdf->Cell($weightArray[1], 5, $t, 'LRTB', 0, 'L');
    /*print "<div style='background: url(img/bg2.jpg) #F2f2f2;border:1px solid #c0c0c0'>
    	<table><td><img src='img/information.gif' width='64' height='64'/></td><td>";
    	print "Papel: $paper<br>";
    	print "Orientación: $orientation<br>";
    	print "Ancho Página: $widthPage mm<br>";
    	print "Número Páginas: $p<br>";
    	print "</td></table></div><br>";*/
    $file = md5(uniqid());
    $pdf->Output(CORE_PATH . 'public/temp/' . $file . ".pdf", 'F');
    if (isset($raw_output)) {
        print "<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".pdf', null); </script>";
    } else {
        Generator::forms_print("<script type='text/javascript'> window.open('" . KUMBIA_PATH . "temp/" . $file . ".pdf', null); </script>");
    }
}