Advertisement
lordjackson

RelatorioProjetosSituacaoPDF

Jul 30th, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 15.23 KB | None | 0 0
  1. <?php
  2.  
  3. require_once("app.library/fpdf/fpdf.php");
  4. include_once "app.ado/TConnection.class.php";
  5. include_once "app.ado/TTransaction.class.php";
  6. include_once "app.ado/TRecord.class.php";
  7. include_once "app.ado/TSqlInstruction.class.php";
  8. include_once "app.ado/TSqlSelect.class.php";
  9. include_once "app.ado/TRepository.class.php";
  10. include_once "app.ado/TExpression.class.php";
  11. include_once "app.ado/TCriteria.class.php";
  12. include_once "app.ado/TFilter.class.php";
  13. include_once "app.model/vw_nota_entrega_leiteRecord.class.php";
  14. include_once "app.library/funcdate.php";
  15.  
  16. session_start();
  17. //define o diretorio de fontes que s�o utilizadas pelo FPDF
  18. define('FPDF_FONTPATH', 'app.library/fpdf/font/');
  19.  
  20. class PDF extends FPDF {
  21.  
  22. //Page header
  23.     function Header() {
  24.  
  25.         $situacao = $_REQUEST["situacao"];
  26.         $mes = $_REQUEST["mes"];
  27.         $ano = $_REQUEST["ano"];
  28.  
  29.         //endereco da imagem,posicao X(horizontal),posicao Y(vertical), tamanho altura, tamanho largura
  30.         $this->Image("app.images/logo_relatorio.jpg", 8, 11, 26, 18);
  31.  
  32.         //Arial bold 15
  33.         $this->SetFont('Arial', 'B', 12);
  34.         $this->SetY("12");
  35.         $this->SetX("35");
  36.         $this->Cell(0, 5, utf8_decode("GOVERNO DO ESTADO DO RIO GRANDE DO NORTE"), 0, 1, 'C');
  37.  
  38.         if ($situacao == "0") {
  39.             $situacao = "TODAS";
  40.         }
  41.         if ($mes == "0") {
  42.             $mes = "TODOS OS MESES";
  43.         } else if ($mes == "1") {
  44.             $mes = "JANEIRO";
  45.         } else if ($mes == "2") {
  46.             $mes = "FEVEREIRO";
  47.         } else if ($mes == "3") {
  48.             $mes = "MARÇO";
  49.         } else if ($mes == "4") {
  50.             $mes = "ABRIL";
  51.         } else if ($mes == "5") {
  52.             $mes = "MAIO";
  53.         } else if ($mes == "6") {
  54.             $mes = "JUNHO";
  55.         } else if ($mes == "7") {
  56.             $mes = "JULHO";
  57.         } else if ($mes == "8") {
  58.             $mes = "AGOSTO";
  59.         } else if ($mes == "9") {
  60.             $mes = "SETEMBRO";
  61.         } else if ($mes == "10") {
  62.             $mes = "OUTUBRO";
  63.         } else if ($mes == "11") {
  64.             $mes = "NOVEMBRO";
  65.         } else if ($mes == "12") {
  66.             $mes = "DEZEMBRO";
  67.         }
  68.  
  69.         $this->SetY("17");
  70.         $this->SetX("35");
  71.         $this->Cell(0, 5, utf8_decode("INSTITUTO DE ASSISTÊNCIA TÉCNICA E EXTENSÃO RURAL - EMATER"), 0, 1, 'C');
  72.  
  73.         $this->SetY("22");
  74.         $this->SetX("35");
  75.         $this->Cell(0, 5, utf8_decode("SIAP"), 0, 1, 'C');
  76.  
  77.         $this->SetY("27");
  78.         $this->SetX("35");
  79.         $this->Cell(0, 5, utf8_decode("RELATÓRIO DE PROJETOS POR SITUAÇÃO: " . $situacao), 0, 1, 'C');
  80.  
  81.         $this->SetY("32");
  82.         $this->SetX("35");
  83.         $this->Cell(0, 5, utf8_decode($mes." - ". $ano), 0, 1, 'C');
  84.     }
  85.  
  86.     function ColumnHeader() {
  87.         //define a fonte a ser usada
  88.         $this->SetFont('arial', 'B', 11);
  89.         $this->Cell(0, 0, '', 1, 1, 'L');
  90.     }
  91.  
  92.     function ColumnDetail() {
  93.  
  94.         $agenciamunicipio_id = $_REQUEST["agenciamunicipio_id"];
  95.         $municipio_id = $_REQUEST["municipio_id"];
  96.         $regional_id = $_REQUEST["regional_id"];
  97.         $servidor_id = $_REQUEST["servidor_id"];
  98.         $situacao = $_REQUEST["situacao"];
  99.         $laudosemitidos = $_REQUEST["laudosemitidos"];
  100.         $mes = $_REQUEST["mes"];
  101.         $ano = $_REQUEST["ano"];
  102.  
  103.         // inicia transacao com o banco 'pg_ceres'
  104.         TTransaction::open('pg_ceres');
  105.  
  106.         // instancia um repositorio para Carros
  107.         $repository = new TRepository('vw_relatorio_projetos_situacao');
  108.         $filtros = "";
  109.         $filtros2 = "";
  110.         $numerofiltros = 0;
  111.  
  112.         $criteria = new TCriteria;
  113.  
  114.         if ($agenciamunicipio_id >= 1) {
  115.             $criteria->add(new TFilter('agenciamunicipio_id', '=', $agenciamunicipio_id));
  116.             /* $numerofiltros ++;
  117.               $rows2 = $repository->load($criteria);
  118.               foreach($rows2 as $row2){
  119.               $filtros .= 'Agencia Municipio: '.$row2->nome_agenciamunicipio;
  120.               break;
  121.               } */
  122.         }
  123.  
  124.  
  125.         if ($municipio_id >= 1) {
  126.             $criteria->add(new TFilter('municipio_id', '=', $municipio_id));
  127.             /* $numerofiltros ++;
  128.               $rows2 = $repository->load($criteria);
  129.               foreach($rows2 as $row2){
  130.               if($filtros == ""){
  131.               $filtros .= 'Municipio: '.$row2->nome_municipio;
  132.               } else {
  133.               $filtros .= ' - Municipio: '.$row2->nome_municipio;
  134.               }
  135.               break;
  136.               } */
  137.         }
  138.  
  139.         if ($regional_id >= 1) {
  140.             $criteria->add(new TFilter('regional_id', '=', $regional_id));
  141.             /* $numerofiltros ++;
  142.               $rows2 = $repository->load($criteria);
  143.               foreach($rows2 as $row2){
  144.               if($filtros == ""){
  145.               $filtros .= 'Regional: '.$row2->nome_regional;
  146.               } else {
  147.               $filtros .= ' - Regional: '.$row2->nome_regional;
  148.               }
  149.               break;
  150.               } */
  151.         }
  152.  
  153.         if ($servidor_id >= 1) {
  154.             $criteria->add(new TFilter('servidor_id', '=', $servidor_id));
  155.             /* $numerofiltros ++;
  156.               $rows2 = $repository->load($criteria);
  157.  
  158.               foreach($rows2 as $row2){
  159.  
  160.               if($filtros == ''){
  161.               $filtros .= 'Tecnico: '.$row2->nome_servidor;
  162.               } else {
  163.               $filtros .= ' - Tecnico: '.$row2->nome_servidor;
  164.               }
  165.               break;
  166.               } */
  167.         }
  168.         if ($situacao != "TODAS") {
  169.             $criteria->add(new TFilter('situacao', '=', $situacao));
  170.         }
  171.  
  172.         if ($ano != "") {
  173.             if ($situacao == 'CONTRATADO') {
  174.                 $criteria->add(new TFilter('ano_cont', '=', $ano));
  175.             } else {
  176.                 $criteria->add(new TFilter('ano_elab', '=', $ano));
  177.             }
  178.         }
  179.  
  180.         if ($laudosemitidos === 0) {
  181.             $criteria->add(new TFilter('laudosemitidos', '=', 0));
  182.         } elseif ($laudosemitidos >= 1) {
  183.             $criteria->add(new TFilter('laudosemitidos', '>=', 1));
  184.         }
  185.  
  186.  
  187.         /*
  188.           if($filtros != ''){
  189.           $this->SetFont('Arial','I',10);
  190.           $this->SetY("37");
  191.           $this->SetX("35");
  192.           $this->Cell(0,5,utf8_decode("FILTRADO POR: ".$filtros),0,1,'C');
  193.           }
  194.  
  195.           if($filtros2 != ''){
  196.           $this->SetFont('Arial','I',10);
  197.           $this->SetY("42");
  198.           $this->SetX("35");
  199.           $this->Cell(0,5,utf8_decode($filtros2),0,1,'C');
  200.           } */
  201.  
  202.  
  203.         //FINALIZANDO O CABEÇALHO DA PAGINA
  204.         $this->Ln();
  205.         $this->ColumnHeader();
  206.         $this->Ln();
  207.  
  208.         $criteria->setProperty('order', 'nome_servidor,nome_regional,nome_municipio,nome_produtor');
  209.  
  210.         // carrega os objetos de acordo com o criterio
  211.         $rows = $repository->load($criteria);
  212.  
  213.         if ($rows) {
  214.             $regional = '';
  215.             $municipio = '';
  216.             $nome_servidor = '';
  217.             $agenciamunicipio = '';
  218.             $projeto_id_anterior = '';
  219.             $contMunicipio = 0;
  220.             $contRegional = 0;
  221.             $contTotal = 0;
  222.             $contador = 0;
  223.  
  224.             // percorre os objetos retornados
  225.             foreach ($rows as $row) {
  226.  
  227.  
  228.  
  229.                 //define a fonte a ser usada
  230.                 $this->SetFont('arial', '', 11);
  231.                 if ($regional != $row->nome_regional) {
  232.  
  233.                     if ($contRegional != 0) {
  234.                         $this->SetFont('Arial', 'B', 10);
  235.                         $this->SetX("10");
  236.                         $this->Ln(5);
  237.                         $this->SetFillColor(215, 215, 215);
  238.                         $this->Cell(0, 5, "Total de Produtores por Municipio: " . $contMunicipio, 1, 1, 'L', 1);
  239.                         $this->Cell(0, 5, "Total de Produtores por Regional: " . $contRegional, 1, 1, 'L', 1);
  240.                         $contRegional = 0;
  241.                     }
  242.                     $municipio = '';
  243.                     $agenciamunicipio = '';
  244.  
  245.                     $this->Ln();
  246.                     $this->SetX("10");
  247.                     $this->SetFont('arial', 'B', 11);
  248.  
  249.                    
  250.                      $this->SetFillColor(100, 180, 118);
  251.                     $this->Cell(0, 5, utf8_decode("REGIONAL: " . $row->nome_regional), 1, 1, 'J', 1);
  252.                     $regional = $row->nome_regional;
  253.                 }
  254.                 if (($regional == $row->nome_regional) && ($municipio != $row->nome_municipio)) {
  255.  
  256.                     if ($municipio != '') {
  257.  
  258.                         $this->SetFont('Arial', 'B', 10);
  259.                         $this->SetX("10");
  260.                         $this->Ln(5);
  261.                         $this->Cell(0, 0, '', 1, 1, 'L');
  262.                         $this->SetFillColor(215, 215, 215);
  263.  
  264.                         $this->Cell(0, 5, "Total de Produtores por Municipio: " . $contMunicipio, 1, 1, 'L', 1);
  265.                         $contMunicipio = 0;
  266.                         // $contMun=0;
  267.                     }
  268.                     $municipio = $row->nome_municipio;
  269.                     $agenciamunicipio = '';
  270.  
  271.                     $this->Ln();
  272.                     $this->SetX("10");
  273.                     $this->SetFont('arial', 'B', 10);
  274.                    
  275. //                    $this->SetFillColor(124, 205, 124);
  276.                     $this->SetFillColor(162, 234, 150);
  277.                     $this->Cell(0, 5, utf8_decode("MUNICÃ�PIO: " . $row->nome_municipio), 1, 1, 'J', 1);
  278.  
  279.                     $this->Cell(0, 0, '', 1, 1, 'L');
  280.                 }
  281.  
  282.                 //exibir produtores por tecnico
  283.                 if ($nome_servidor != $row->nome_servidor) {
  284.                     $this->Ln();
  285.                     $this->SetX("10");
  286.                     $this->SetFont('arial', 'B', 10);
  287.                    $this->SetFillColor(162, 234, 150);
  288. //                    $this->SetFillColor(215, 215, 215);
  289. //                     $this->SetFillColor(124, 205, 124);
  290.                     $this->Cell(0, 5, utf8_decode("TÉCNICO: " . strtoupper($row->nome_servidor)), 1, 1, 'J', 1);
  291.                     $this->Cell(0, 0, '', 1, 1, 'L');
  292.                     $this->SetFont('arial', '', 9);
  293.                 }
  294.                 $nome_servidor = $row->nome_servidor;
  295.  
  296.                 if (($regional == $row->nome_regional) && ($municipio == $row->nome_municipio) && ($agenciamunicipio != $row->nome_agenciamunicipio)) {
  297.                     //$contador = 1;
  298. //                    $contMunicipio+=$contador;
  299.                     $agenciamunicipio = $row->nome_agenciamunicipio;
  300.  
  301.                     $this->Ln();
  302.                     $this->SetX("10");
  303.                     $this->SetFont('arial', 'B', 10);
  304.                     $this->SetFillColor(215, 215, 215);
  305.                     $this->Cell(0, 5, utf8_decode("AGÊNCIA: " . $row->agencia . " - " . $row->nome_agenciamunicipio), 1, 1, 'J', 1);
  306.  
  307.                     $this->SetFont('arial', 'B', 9);
  308.                     $this->SetX("10");
  309.                     $this->Cell(0, 5, utf8_decode("PRODUTOR"), 1, 0, 'J');
  310.  
  311.                     $this->SetX("68");
  312.                     $this->Cell(0, 5, utf8_decode("CPF"), 1, 0, 'J');
  313.  
  314.                     $this->SetX("93");
  315.                     $this->Cell(0, 5, utf8_decode("DATA SITUACÃO"), 1, 0, 'J');
  316.  
  317.                     $this->SetX("124");
  318.                     $this->Cell(0, 5, utf8_decode("SITUACÃO"), 1, 0, 'J');
  319.  
  320.                     $this->SetX("150");
  321.                     $this->Cell(0, 5, utf8_decode("TX/ATER"), 1, 0, 'J');
  322.                     $this->SetX("170");
  323.                     $this->Cell(0, 5, utf8_decode("VALOR PROJETO"), 1, 0, 'J');
  324.                 }
  325.  
  326.                 if ($contador % 2 == 0) {
  327.                     $this->SetFillColor(235, 235, 235);
  328.                 } else {
  329.                     $this->SetFillColor(255, 255, 255);
  330.                 }
  331.  
  332.                 $this->SetFont('arial', '', 9);
  333.                 if ($row->id != $projeto_id_anterior) {
  334.                     $this->Ln();
  335.                     $this->SetX("10");
  336.                     $this->Cell(0, 5, utf8_decode(strtoupper(substr($row->nome_produtor, 0, 26))), 1, 0, 'J', 1);
  337.  
  338.                     $this->SetX("68");
  339.                     $this->Cell(0, 5, utf8_decode($row->cpf_produtor), 1, 0, 'J');
  340.  
  341.                     $this->SetX("93");
  342.                     if ($row->datasituacao != null) {
  343.                         $this->Cell(0, 5, utf8_decode(formatar_data($row->datasituacao)), 1, 0, 'J', 1);
  344.                     } else {
  345.                         $this->Cell(0, 5, utf8_decode(formatar_data($row->dataelaboracao)), 1, 0, 'J', 1);
  346.                     }
  347.  
  348.                     $this->SetX("124");
  349.                     $this->Cell(0, 5, utf8_decode($row->situacao), 1, 0, 'J');
  350.                    
  351.                     $this->SetX("150");
  352.                     $this->Cell(0, 5, utf8_decode("R$ ".$row->valortaxa), 1, 0, 'J');
  353.                    
  354.                     $this->SetX("170");
  355.                     $this->Cell(0, 5, utf8_decode("R$ ".$row->valorprojeto), 1, 0, 'J');
  356.  
  357.                     $contRegional++;
  358.                     $contMunicipio++;
  359.                     $contador++;
  360.                 }
  361.  
  362.  
  363.                 $projeto_id_anterior = $row->id;
  364.             }
  365.             $this->Ln(5);
  366.             $this->SetFont('arial', 'B', 10);
  367.             $this->SetX("10");
  368.             $this->Cell(0, 0, '', 1, 1, 'L');
  369.             $this->SetFillColor(215, 215, 215);
  370.             $this->Cell(0, 5, "Total de Produtores por Municipio: " . $contMunicipio, 1, 1, 'J', 1);
  371.             $this->Cell(0, 5, "Total de Produtores por Regional: " . $contRegional, 1, 1, 'J', 1);
  372.         } else {
  373.             $this->SetFont('arial', 'B', 14);
  374.             $this->Cell(0, 5, utf8_decode("NENHUM REGISTRO FOI ENCONTRADO."), 0, 0, 'C');
  375.         }
  376.         $contTotal +=$contador;
  377.         $this->SetFont('arial', 'B', 10);
  378.         $this->SetX("10");
  379.         $this->Ln(5);
  380.         $this->Cell(0, 0, '', 1, 1, 'L');
  381.         $this->SetFillColor(215, 215, 215);
  382.  
  383.         $this->Cell(0, 5, "Total de Produtores: " . $contador, 1, 1, 'J', 1);
  384.  
  385.  
  386.         TTransaction::close();
  387.     }
  388.  
  389.     function Footer() {
  390.         //Position at 1.5 cm from bottom
  391.         $this->SetY(-15);
  392.         //Arial italic 8
  393.         $this->SetFont('Arial', 'I', 8);
  394.         //Page number
  395.         //data atual
  396.         $data = date("d/m/Y H:i:s");
  397.         $conteudo = "impresso em " . $data;
  398.         $texto = "http://www.emater.rn.gov.br";
  399.         //imprime uma linha... largura,altura, texto,borda,quebra de linha, alinhamento
  400.         $this->Cell(0, 0, '', 1, 1, 'L');
  401.  
  402.         //imprime uma celula... largura,altura, texto,borda,quebra de linha, alinhamento
  403.         $this->Cell(0, 5, $texto, 0, 0, 'L');
  404.         $this->Cell(0, 5, 'Pag. ' . $this->PageNo() . ' de ' . '{nb}' . ' - ' . $conteudo, 0, 0, 'R');
  405.         $this->Ln();
  406.     }
  407.  
  408. }
  409.  
  410. $pdf = new PDF("P", "mm", "A4");
  411.  
  412. $pdf->SetTitle(utf8_decode("Relatorio Projeto Situação - EMATER-RN"));
  413.  
  414. $pdf->SetSubject(utf8_decode("Relatorio Projeto Situação - EMATER-RN"));
  415.  
  416.  
  417. $pdf->AliasNbPages();
  418. $pdf->AddPage();
  419. $pdf->SetFont('Times', '', 12);
  420. $pdf->ColumnDetail();
  421. $pdf->Output();
  422. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement