KumbiaPHP beta2-dev
Framework PHP en español
|
00001 <?php 00027 include_once LIBRARY_PATH.'fpdf/fpdf.php'; 00028 00029 class PDF extends FPDF 00030 { 00031 //Cabecera de página 00032 function Header() 00033 { 00034 $this->Ln(10); 00035 } 00036 00037 //Pie de página 00038 function Footer() 00039 { 00040 00041 $config = Config::read('config'); 00042 $active_app = Router::get_application(); 00043 //Posición: a 1,5 cm del final 00044 $this->SetY(-21); 00045 //Arial italic 8 00046 $this->SetFont('Arial', '', 7); 00047 00048 //Posición: a 1,5 cm del final 00049 $this->SetY(-18); 00050 //Arial italic 8 00051 $this->SetFont('Arial','',7); 00052 //Número de página 00053 $this->Cell(0,10, $config->$active_app->name,0,0,'C'); 00054 00055 //Posición: a 1,5 cm del final 00056 $this->SetY(-10); 00057 //Arial italic 8 00058 $this->SetFont('Arial','',8); 00059 //Número de página 00060 $this->Cell(0,10,'-- '.$this->PageNo().' --',0,0,'C'); 00061 00062 } 00063 00064 } 00065 00075 function pdf($result, $sumArray, $title, $weightArray, $headerArray){ 00076 00077 $config = Config::read('config'); 00078 $active_app = Router::get_application(); 00079 00080 //Orientación 00081 if($sumArray>200) { 00082 $orientation = 'L'; 00083 } else { 00084 $orientation = 'P'; 00085 } 00086 00087 $numRows = 140; 00088 //Tipo de Papel 00089 if($sumArray>250) { 00090 $paper = 'legal'; 00091 } else { 00092 $paper = 'letter'; 00093 } 00094 00095 if($paper=='letter'&&$orientation=='P'){ 00096 $widthPage = 220; 00097 $numRows = 42; 00098 } 00099 00100 if($paper=='legal'&&$orientation=='L'){ 00101 $widthPage = 355; 00102 $numRows = 30; 00103 } 00104 00105 if($paper=='letter'&&$orientation=='L'){ 00106 $widthPage = 270; 00107 $numRows = 30; 00108 } 00109 00110 //Crear Documento PDF 00111 $pdf = new PDF($orientation, 'mm', $paper); 00112 00113 $pdf->Open(); 00114 $pdf->AddPage(); 00115 00116 //Nombre del Listado 00117 $pdf->SetFillColor(255, 255, 255); 00118 $pdf->AddFont('Verdana','','verdana.php'); 00119 $pdf->SetFont('Verdana','', 14); 00120 $pdf->SetY(20); 00121 $pdf->SetX(0); 00122 00123 00124 $pdf->Ln(); 00125 00126 if($config->$active_app->name){ 00127 $pdf->MultiCell(0, 6, strtoupper($config->$active_app->name), 0, "C", 0); 00128 } 00129 $pdf->MultiCell(0, 6, "REPORTE DE ".strtoupper($title), 0, "C", 0); 00130 $pdf->SetFont('Verdana','', 12); 00131 if(isset($_SESSION['fecsis'])){ 00132 $pdf->MultiCell(0, 6, "FECHA ".date("Y-m-d"), 0, "C", 0); 00133 } 00134 $pdf->Ln(); 00135 00136 //Colores, ancho de línea y fuente en negrita 00137 $pdf->SetFillColor(0xF2,0xF2, 0xF2); 00138 $pdf->SetTextColor(0); 00139 $pdf->SetDrawColor(0,0,0); 00140 $pdf->SetLineWidth(.2); 00141 $pdf->SetFont('Arial', 'B', 10); 00142 00143 if($weightArray[0]<11){ 00144 $weightArray[0] = 11; 00145 } 00146 00147 //Parametros del Reporte 00148 $pos = floor(($widthPage/2)-($sumArray/2)); 00149 $pdf->SetX($pos); 00150 for($i=0;$i<=count($headerArray)-1;$i++){ 00151 $pdf->Cell($weightArray[$i],7,$headerArray[$i], 1, 0, 'C', 1); 00152 } 00153 $pdf->Ln(); 00154 00155 //Restauración de colores y fuentes 00156 $pdf->SetFillColor(224, 235, 255); 00157 $pdf->SetTextColor(0); 00158 $pdf->SetFont('Arial','B', 7); 00159 00160 //print_r($weightArray); 00161 00162 //Buscamos y listamos 00163 $n = 1; 00164 $p = 1; 00165 $t = 0; 00166 foreach($result as $row){ 00167 //$pdf->Cell(Ancho, Alto, contenido, ?, ?, Align) 00168 if($n>$numRows||($p==1&&($n>$numRows-3))){ 00169 $pdf->AddPage($orientation); 00170 $pdf->SetY(30); 00171 $pdf->SetX($pos); 00172 $pdf->SetFillColor(0xF2,0xF2, 0xF2); 00173 $pdf->SetTextColor(0); 00174 $pdf->SetDrawColor(0,0,0); 00175 $pdf->SetLineWidth(.2); 00176 $pdf->SetFont('Arial', 'B', 10); 00177 for($i=0;$i<count($headerArray);$i++){ 00178 $pdf->Cell($weightArray[$i], 7, $headerArray[$i], 1, 0, 'C', 1); 00179 } 00180 $pdf->Ln(); 00181 $pdf->SetFillColor(224, 235, 255); 00182 $pdf->SetTextColor(0); 00183 $pdf->SetFont('Arial', 'B', 7); 00184 $n = 1; 00185 $p++; 00186 } 00187 $pdf->SetX($pos); 00188 for($i=0;$i<=count($row)-1;$i++){ 00189 if(is_numeric($row[$i])){ 00190 $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'C'); 00191 } else { 00192 $pdf->Cell($weightArray[$i], 5, trim($row[$i]),'LRTB', 0, 'L'); 00193 } 00194 } 00195 $n++; 00196 $t++; 00197 $pdf->Ln(); 00198 00199 } 00200 00201 $pdf->SetX($pos); 00202 $pdf->SetFont('Arial', 'B', 7); 00203 $pdf->SetFillColor(0xF2,0xF2, 0xF2); 00204 $pdf->Cell($weightArray[0], 5, "TOTAL",'LRTB', 0, 'R'); 00205 $pdf->Cell($weightArray[1], 5, $t,'LRTB', 0, 'L'); 00206 00207 /*print "<div style='background: url(img/bg2.jpg) #F2f2f2;border:1px solid #c0c0c0'> 00208 <table><td><img src='img/information.gif' width='64' height='64'/></td><td>"; 00209 print "Papel: $paper<br>"; 00210 print "Orientación: $orientation<br>"; 00211 print "Ancho Página: $widthPage mm<br>"; 00212 print "Número Páginas: $p<br>"; 00213 print "</td></table></div><br>";*/ 00214 00215 $file = md5(uniqid()); 00216 $pdf->Output(CORE_PATH.'public/temp/'.$file .".pdf", 'F'); 00217 if(isset($raw_output)){ 00218 print "<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>"; 00219 } else { 00220 Generator::forms_print("<script type='text/javascript'> window.open('".KUMBIA_PATH."temp/".$file.".pdf', null); </script>"); 00221 } 00222 00223 } 00224 ?>