public function imprimirRelatorioAction() { $this->intTamPag = 30; //DEFINE PARAMETROS DE ORDENACAO / QTDE. REG POR PAG. / PAGINACAO if ($this->_request->getParam("qtde")) { $this->intTamPag = $this->_request->getParam("qtde"); } $order = array(); //==== parametro de ordenacao ======// if ($this->_request->getParam("ordem")) { $ordem = $this->_request->getParam("ordem"); if ($ordem == "ASC") { $novaOrdem = "DESC"; } else { $novaOrdem = "ASC"; } } else { $ordem = "ASC"; $novaOrdem = "ASC"; } //==== campo de ordenacao ======// if ($this->_request->getParam("campo")) { $campo = $this->_request->getParam("campo"); $order = array($campo . " " . $ordem); $ordenacao = "&campo=" . $campo . "&ordem=" . $ordem; } else { $campo = null; $order = array(2); //Pronac $ordenacao = null; } $pag = 1; $get = Zend_Registry::get('post'); if (isset($get->pag)) { $pag = $get->pag; } $inicio = $pag > 1 ? ($pag - 1) * $this->intTamPag : 0; $where = array(); if (isset($get->pronac) && !empty($get->pronac)) { $where['pr.AnoProjeto+pr.Sequencial = ?'] = $get->pronac; $this->view->pronac = $get->pronac; } if (isset($get->cnpfcpf) && !empty($get->cnpfcpf)) { $where['pr.CgcCpf = ?'] = retiraMascara($get->cnpfcpf); $this->view->cnpfcpf = $get->cnpfcpf; } if (isset($get->nomeProjeto) && !empty($get->nomeProjeto)) { $where['pr.NomeProjeto like (?)'] = "%" . $get->nomeProjeto . "%"; $this->view->nomeProjeto = $get->nomeProjeto; } if (isset($get->nomeProponente) && !empty($get->nomeProponente)) { $where['nm.Descricao like (?)'] = "%" . $get->nomeProponente . "%"; $this->view->nomeProponente = $get->nomeProponente; } if (isset($get->area) && !empty($get->area)) { $where['ar.Codigo = ?'] = $get->area; $this->view->area = $get->area; } if (isset($get->segmento) && !empty($get->segmento)) { $where['sg.Codigo = ?'] = $get->segmento; $this->view->segmento = $get->segmento; } if (isset($get->mecanismo) && !empty($get->mecanismo)) { $where['pr.Mecanismo = ?'] = $get->mecanismo; $this->view->mecanismo = $get->mecanismo; } if (isset($get->uf) && !empty($get->uf)) { $where['uf.CodUfIbge = ?'] = $get->uf; $this->view->uf = $get->uf; } if (isset($get->municipio) && !empty($get->municipio)) { $where['u.idMunicipio = ?'] = $get->municipio; $this->view->municipio = $get->municipio; } if (isset($get->situacao) && !empty($get->situacao)) { $where['pr.Situacao = ?'] = $get->situacao; $this->view->situacao = $get->situacao; } $where = GenericControllerNew::montaBuscaData($get, "tpDtSituacao", "dtSituacao", "pr.DtSituacao", "dtSituacao_Final", $where); $where = GenericControllerNew::montaBuscaData($get, "tpDtPublicacao", "dtPublicacao", "ap.DtPublicacaoAprovacao", "dtPublicacao_Final", $where); $where = GenericControllerNew::montaBuscaData($get, "tpDtPortaria", "dtPortaria", "ap.DtPortariaAprovacao", "dtPortaria_Final", $where); if (isset($get->dtInicioExec) && isset($get->dtFimExec) && !empty($get->dtInicioExec) && !empty($get->dtFimExec)) { $di = data::dataAmericana($get->dtInicioExec); $df = data::dataAmericana($get->dtFimExec); $where["pr.DtInicioExecucao BETWEEN '{$di}' AND '{$df}'"] = ''; $where["pr.DtFimExecucao BETWEEN '{$di}' AND '{$df}'"] = ''; $this->view->dtInicioExec = $get->dtInicioExec; $this->view->dtFimExec = $get->dtFimExec; } if (isset($get->propRegular) && !empty($get->propRegular)) { $where['inab.Habilitado = ?'] = $get->propRegular; $this->view->propRegular = $get->propRegular; } if (isset($get->planoAnual) && !empty($get->planoAnual)) { $where['p.stPlanoAnual = ?'] = $get->planoAnual; $this->view->planoAnual = $get->planoAnual; } if (isset($get->datafixa) && !empty($get->datafixa)) { $where['p.stDataFixa = ?'] = $get->datafixa; $this->view->datafixa = $get->datafixa; } $Projetos = new Projetos(); $total = $Projetos->relatorioProjeto($where, $order, null, null, true); $fim = $inicio + $this->intTamPag; $totalPag = (int) ($total % $this->intTamPag == 0 ? $total / $this->intTamPag : $total / $this->intTamPag + 1); $tamanho = $fim > $total ? $total - $inicio : $this->intTamPag; $busca = $Projetos->relatorioProjeto($where, $order, $tamanho, $inicio); if (isset($get->xls) && $get->xls) { $colunas = 12; if ($campo != 12) { $colunas++; } $html = ''; $html .= '<table style="border: 1px">'; $html .= '<tr><td style="border: 1px dotted black; background-color: #EAF1DD; font-size: 16; font-weight: bold;" colspan="' . $colunas . '">Relatório de Projetos - Resultado da pesquisa</td></tr>'; $html .= '<tr><td style="border: 1px dotted black; background-color: #EAF1DD; font-size: 10" colspan="' . $colunas . '">Data do Arquivo: ' . Data::mostraData() . '</td></tr>'; $html .= '<tr><td colspan="' . $colunas . '"></td></tr>'; $html .= '<tr>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;"> </th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">PRONAC</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Nome do Projeto</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Agente</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Área</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Segmento</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">UF</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Município</th>'; if ($campo != 12) { $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Situação</th>'; } $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Vl. Solicitado</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Vl. Aprovado</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Vl. Captado</th>'; $html .= '<th style="border: 1px dotted black; background-color: #9BBB59;">Habilitado</th>'; $html .= '</tr>'; $ds = ''; $i = 1; foreach ($busca as $v) { if ($v->Situacao != $ds && $campo == 12) { $html .= '<tr><td style="border: 1px dotted black; background-color: #EAF1DD;" colspan="12">' . $v->Situacao . ' - ' . $v->dsSituacao . '</td></tr>'; } $html .= '<tr>'; $html .= '<td style="border: 1px dotted black;">' . $i . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->Pronac . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->NomeProjeto . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->NomeAgente . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->Area . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->Segmento . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->UfProjeto . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->Municipio . '</td>'; if ($campo != 12) { $html .= '<td style="border: 1px dotted black;">' . $v->Situacao . ' - ' . $v->dsSituacao . '</td>'; } $html .= '<td style="border: 1px dotted black;">' . @number_format($v->ValorSolicitado, 2, ",", ".") . '</td>'; $html .= '<td style="border: 1px dotted black;">' . @number_format($v->ValorAprovado, 2, ",", ".") . '</td>'; $html .= '<td style="border: 1px dotted black;">' . @number_format($v->ValorCaptado, 2, ",", ".") . '</td>'; $html .= '<td style="border: 1px dotted black;">' . $v->Habilitado . '</td>'; $html .= '</tr>'; $i++; $ds = $v->Situacao; } $html .= '</table>'; header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: inline; filename=Resultado_Relatorio_Projetos.xls;"); echo $html; die; } else { $this->view->qtdRegistros = $total; $this->view->dados = $busca; $this->view->campo = $campo; $this->_helper->layout->disableLayout(); // Desabilita o Zend Layout } }