public List<Socios> getListaSocios() {
    SocioCarteirinhaDao db = new SocioCarteirinhaDao();
    FilialCidadeDao dbC = new FilialCidadeDao();
    PessoaEnderecoDao dbE = new PessoaEnderecoDao();
    FilialCidade filCidade;
    List result;
    if (listaSoc.isEmpty() && carregar) {
      if (Registro.get().isCarteirinhaDependente()) {
        result = db.pesquisaSocioSemCarteirinhaDependente();
      } else {
        result = db.pesquisaSocioSemCarteirinha();
      }
      for (int i = 0; i < result.size(); i++) {
        PessoaEndereco pesEnde =
            dbE.pesquisaEndPorPessoaTipo(
                ((Socios) result.get(i)).getServicoPessoa().getPessoa().getId(), 1);
        if (pesEnde != null) {
          filCidade = dbC.findPrincipal(pesEnde.getEndereco().getCidade().getId());
        } else {
          filCidade = new FilialCidade();
        }

        listaSoc.add(new DataObject(true, (Socios) result.get(i), filCidade, null, null, null));
      }
    }
    return listaSoc;
  }
 public String adicionarSocio() {
   for (Object listaSoc1 : listaSoc) {
     if (((Socios) ((DataObject) listaSoc1).getArgumento1()).getServicoPessoa().getId()
         == socioCarteirinha.getPessoa().getId()) {
       renderAdc = false;
       return "emissaoCarteirinha";
     }
   }
   FilialCidadeDao dbC = new FilialCidadeDao();
   PessoaEnderecoDao dbE = new PessoaEnderecoDao();
   PessoaEndereco pesEnde = dbE.pesquisaEndPorPessoaTipo(socioCarteirinha.getPessoa().getId(), 1);
   FilialCidade filCidade;
   if (pesEnde != null) {
     filCidade = dbC.findPrincipal(pesEnde.getEndereco().getCidade().getId());
   } else {
     filCidade = new FilialCidade();
   }
   listaSoc.add(new DataObject(true, socioCarteirinha.getPessoa(), filCidade, null, null, null));
   renderAdc = false;
   socioCarteirinha = new SocioCarteirinha();
   return "emissaoCarteirinha";
 }
  public String recibo(Integer id_movimento, Map parameter) {
    MovimentoDao db = new MovimentoDao();
    Movimento movimento = db.pesquisaCodigo(id_movimento);
    try {
      Collection vetor = new ArrayList();
      Juridica sindicato = (Juridica) (new Dao()).find(new Juridica(), 1);
      PessoaEnderecoDao dbp = new PessoaEnderecoDao();

      PessoaEndereco pe = dbp.pesquisaEndPorPessoaTipo(1, 2);

      // PESQUISA FORMA DE PAGAMENTO
      List<FormaPagamento> fp = db.pesquisaFormaPagamento(movimento.getBaixa().getId());
      String formas[] = new String[10];
      float soma_dinheiro = 0, soma_outros = 0;
      for (int i = 0; i < fp.size(); i++) {
        // 4 - CHEQUE
        if (fp.get(i).getTipoPagamento().getId() == 4) {
          formas[i] =
              fp.get(i).getTipoPagamento().getDescricao()
                  + ": R$ "
                  + Moeda.converteR$Float(fp.get(i).getValor())
                  + " (B: "
                  + fp.get(i).getChequeRec().getBanco().getNumero()
                  + " Ag: "
                  + fp.get(i).getChequeRec().getAgencia()
                  + " C: "
                  + fp.get(i).getChequeRec().getConta()
                  + " CH: "
                  + fp.get(i).getChequeRec().getCheque()
                  + ")";
          // 5 - CHEQUE PRÉ
        } else if (fp.get(i).getTipoPagamento().getId() == 5) {
          formas[i] =
              fp.get(i).getTipoPagamento().getDescricao()
                  + ": R$ "
                  + Moeda.converteR$Float(fp.get(i).getValor())
                  + " (B: "
                  + fp.get(i).getChequeRec().getBanco().getNumero()
                  + " Ag: "
                  + fp.get(i).getChequeRec().getAgencia()
                  + " C: "
                  + fp.get(i).getChequeRec().getConta()
                  + " CH: "
                  + fp.get(i).getChequeRec().getCheque()
                  + " P: "
                  + fp.get(i).getChequeRec().getVencimento()
                  + ")";
          // QUALQUER OUTRO
        } else {
          formas[i] =
              fp.get(i).getTipoPagamento().getDescricao()
                  + ": R$ "
                  + Moeda.converteR$Float(fp.get(i).getValor());
          if (fp.get(i).getTipoPagamento().getId() == 3) {
            soma_dinheiro = soma_dinheiro + fp.get(i).getValor();
          }
        }

        if (fp.get(i).getTipoPagamento().getId() != 3) {
          soma_outros = soma_outros + fp.get(i).getValor();
        }
      }
      String lblVencimento = "";
      String vencimento = "";
      DataHoje dataHoje = new DataHoje();
      List<Movimento> lista = db.listaMovimentoBaixaOrder(movimento.getBaixa().getId());
      for (int i = 0; i < lista.size(); i++) {
        // tem casos de ter responsaveis diferentes, resultando em empresas conveniadas diferentes
        Guia gu = db.pesquisaGuias(lista.get(i).getLote().getId());
        String conveniada = "", mensagemConvenio = "";
        if (gu.getId() != -1) {
          if (gu.getPessoa() != null) {
            conveniada = gu.getPessoa().getNome();
          }
        }

        if (lista.get(i).getLote().getRotina().getId() == 132) {
          if (lista.get(i).getServicos().isValidadeGuias()
              && !lista.get(i).getServicos().isValidadeGuiasVigente()) {
            lblVencimento = "Validade";
            vencimento =
                dataHoje.incrementarDias(
                    lista.get(i).getServicos().getValidade(), lista.get(i).getLote().getEmissao());
          } else if (lista.get(i).getServicos().isValidadeGuias()
              && lista.get(i).getServicos().isValidadeGuiasVigente()) {
            lblVencimento = "Validade";
            vencimento = DataHoje.converteData(DataHoje.lastDayOfMonth(DataHoje.dataHoje()));
          } else {
            lblVencimento = "Validade";
            vencimento = "";
          }

          // MOSTRANDO MENSAGEM APENAS SE VIER DA PAGINA EMISSÃO DE GUIAS --- by rogerinho
          // 17/03/2015 -- chamado 579
          mensagemConvenio = lista.get(i).getLote().getHistorico();
        } else {
          lblVencimento = "Vencimento";
          vencimento = lista.get(i).getVencimento();
        }
        String servico_descricao = "";
        if (lista.get(i).getServicos() != null) {
          servico_descricao = lista.get(i).getServicos().getDescricao();
        }
        vetor.add(
            new ParametroRecibo(
                ((ServletContext)
                        FacesContext.getCurrentInstance().getExternalContext().getContext())
                    .getRealPath(
                        "/Cliente/"
                            + ControleUsuarioBean.getCliente()
                            + "/Imagens/LogoCliente.png"),
                sindicato.getPessoa().getNome(),
                pe.getEndereco().getDescricaoEndereco().getDescricao(),
                pe.getEndereco().getLogradouro().getDescricao(),
                pe.getNumero(),
                pe.getComplemento(),
                pe.getEndereco().getBairro().getDescricao(),
                pe.getEndereco().getCep().substring(0, 5)
                    + "-"
                    + pe.getEndereco().getCep().substring(5),
                pe.getEndereco().getCidade().getCidade(),
                pe.getEndereco().getCidade().getUf(),
                sindicato.getPessoa().getTelefone1(),
                sindicato.getPessoa().getEmail1(),
                sindicato.getPessoa().getSite(),
                sindicato.getPessoa().getDocumento(),
                lista.get(i).getPessoa().getNome(), // RESPONSÁVEL
                String.valueOf(lista.get(i).getPessoa().getId()), // ID_RESPONSAVEL
                String.valueOf(lista.get(i).getBaixa().getId()), // ID_BAIXA
                lista.get(i).getBeneficiario().getNome(), // BENEFICIÁRIO
                servico_descricao, // SERVICO
                vencimento, // VENCIMENTO
                new BigDecimal(lista.get(i).getValorBaixa()), // VALOR BAIXA
                lista.get(i).getBaixa().getUsuario().getLogin(),
                lista.get(i).getBaixa().getBaixa(),
                DataHoje.horaMinuto(),
                formas[0],
                formas[1],
                formas[2],
                formas[3],
                formas[4],
                formas[5],
                formas[6],
                formas[7],
                formas[8],
                formas[9],
                (conveniada.isEmpty()) ? "" : "Empresa Conveniada: " + conveniada,
                lblVencimento,
                mensagemConvenio,
                lista.get(i).getPessoa().getDocumento(),
                Moeda.converteR$Float(soma_dinheiro + lista.get(i).getBaixa().getTroco()),
                Moeda.converteR$Float(lista.get(i).getBaixa().getTroco()),
                Moeda.converteR$Float(soma_outros)));
      }

      File fl =
          new File(
              ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
                  .getRealPath("/Relatorios/RECIBO.jasper"));
      JasperReport jasper = (JasperReport) JRLoader.loadObject(fl);

      JRBeanCollectionDataSource dtSource = new JRBeanCollectionDataSource(vetor);
      if (parameter == null) {
        parameter = new HashedMap();
      }
      JasperPrint print = JasperFillManager.fillReport(jasper, parameter, dtSource);

      boolean printPdf = true;

      if (printPdf) {
        byte[] arquivo = JasperExportManager.exportReportToPdf(print);
        salvarRecibo(arquivo, lista.get(0).getBaixa());
        HttpServletResponse res =
            (HttpServletResponse)
                FacesContext.getCurrentInstance().getExternalContext().getResponse();
        res.setContentType("application/pdf");
        res.setHeader("Content-disposition", "inline; filename=\"" + "recibo" + ".pdf\"");
        res.getOutputStream().write(arquivo);
        res.getCharacterEncoding();

        FacesContext.getCurrentInstance().responseComplete();
      } else {
        // CASO QUEIRA IMPRIMIR EM HTML HTMLPRINT PRINTHTML IMPRIMIRRECIBOHTML TOHTML
        if (lista.get(0).getBaixa().getCaixa() == null) {
          return null;
        }

        String caminho =
            ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
                .getRealPath(
                    "/Cliente/"
                        + ControleUsuarioBean.getCliente()
                        + "/"
                        + "Arquivos/recibo/"
                        + lista.get(0).getBaixa().getCaixa().getCaixa()
                        + "/"
                        + DataHoje.converteData(lista.get(0).getBaixa().getDtBaixa())
                            .replace("/", "-"));
        Diretorio.criar(
            "Arquivos/recibo/"
                + lista.get(0).getBaixa().getCaixa().getCaixa()
                + "/"
                + DataHoje.converteData(lista.get(0).getBaixa().getDtBaixa()).replace("/", "-"));

        String path_arquivo =
            caminho
                + String.valueOf(lista.get(0).getBaixa().getUsuario().getId())
                + "_"
                + String.valueOf(lista.get(0).getBaixa().getId())
                + ".html";
        File file_arquivo = new File(path_arquivo);

        String n =
            String.valueOf(lista.get(0).getBaixa().getUsuario().getId())
                + "_"
                + String.valueOf(lista.get(0).getBaixa().getId())
                + ".html";
        if (file_arquivo.exists()) {
          path_arquivo =
              caminho
                  + String.valueOf(lista.get(0).getBaixa().getUsuario().getId())
                  + "_"
                  + String.valueOf(lista.get(0).getBaixa().getId())
                  + "_(2).html";
          n =
              String.valueOf(lista.get(0).getBaixa().getUsuario().getId())
                  + "_"
                  + String.valueOf(lista.get(0).getBaixa().getId())
                  + "_(2).html";
        }
        JasperExportManager.exportReportToHtmlFile(print, path_arquivo);

        Download download =
            new Download(n, caminho, "text/html", FacesContext.getCurrentInstance());
        download.baixar();

        //                String reportPath =JasperRunManager.runReportToHtmlFile(fl.getPath(),
        // null, dtSource);
        //                File reportHtmlFile = new File(reportPath);
        //                FileInputStream fis = new FileInputStream(reportHtmlFile);
        //                byte[] arquivo =  new byte[(int)reportHtmlFile.length()];
        //                fis.read(arquivo);
        //                HttpServletResponse res = (HttpServletResponse)
        // FacesContext.getCurrentInstance().getExternalContext().getResponse();
        //                res.setHeader("Content-Disposition","inline; filename=myReport.html");
        //                res.setContentType("text/html");
        //                res.setContentLength(arquivo.length);
        //                res.getOutputStream().write(arquivo);
        //                res.getCharacterEncoding();
        //
        //                FacesContext.getCurrentInstance().responseComplete();
        //                FacesContext.getCurrentInstance().responseComplete();
        //                HttpServletResponse response = (HttpServletResponse)
        // FacesContext.getCurrentInstance().getExternalContext().getResponse();
        //
        // response.sendRedirect("http://localhost:8080/Sindical/Cliente/Sindical/Arquivos/recibo/0/16-06-2015/1_683382.html");
        // FacesContext.getCurrentInstance().getExternalContext().redirect("/Sindical/baixaGeral.jsf");
      }

    } catch (JRException | IOException ex) {
      ex.getMessage();
    }

    return null;
  }
  public void imprimirCarteirinhaSemDependente() {
    Fisica fisica = new Fisica();
    Juridica sindicato = new Juridica();
    FisicaDao db = new FisicaDao();
    PessoaEndereco pesEndereco,
        pesDestinatario,
        pesEndEmpresa,
        pesEndSindicato = new PessoaEndereco();
    PessoaEnderecoDao dbEnd = new PessoaEnderecoDao();
    PessoaEmpresa pesEmpresa = new PessoaEmpresa();
    PessoaEmpresaDao dbEmp = new PessoaEmpresaDao();
    String dados[] = new String[32];
    try {
      FacesContext faces = FacesContext.getCurrentInstance();
      HttpServletResponse response = (HttpServletResponse) faces.getExternalContext().getResponse();
      Collection listaSocios = new ArrayList();

      File fl =
          new File(
              ((ServletContext) faces.getExternalContext().getContext())
                  .getRealPath(
                      "/Cliente/"
                          + ControleUsuarioBean.getCliente()
                          + "/Relatorios/FICHACADASTRO.jasper"));
      JasperReport jasper = (JasperReport) JRLoader.loadObject(fl);

      sindicato = (Juridica) new Dao().find(new Juridica(), 1);
      pesEndSindicato = dbEnd.pesquisaEndPorPessoaTipo(sindicato.getPessoa().getId(), 2);

      for (int i = 0; i < listaSoc.size(); i++) {
        if ((Boolean) ((DataObject) listaSoc.get(i)).getArgumento0()) {
          fisica =
              db.pesquisaFisicaPorPessoa(
                  ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                      .getServicoPessoa()
                      .getPessoa()
                      .getId());
          pesEndereco = dbEnd.pesquisaEndPorPessoaTipo(fisica.getPessoa().getId(), 1);
          pesEmpresa = dbEmp.pesquisaPessoaEmpresaPorFisica(fisica.getId());
          if (pesEmpresa.getId() != -1) {
            pesEndEmpresa =
                dbEnd.pesquisaEndPorPessoaTipo(pesEmpresa.getJuridica().getPessoa().getId(), 2);
          } else {
            pesEndEmpresa = new PessoaEndereco();
          }

          pesDestinatario = dbEnd.pesquisaEndPorPessoaTipo(fisica.getPessoa().getId(), 1);

          try {
            dados[0] = pesEndereco.getEndereco().getLogradouro().getDescricao();
            dados[1] = pesEndereco.getEndereco().getDescricaoEndereco().getDescricao();
            dados[2] = pesEndereco.getNumero();
            dados[3] = pesEndereco.getComplemento();
            dados[4] = pesEndereco.getEndereco().getBairro().getDescricao();
            dados[5] = pesEndereco.getEndereco().getCidade().getCidade();
            dados[6] = pesEndereco.getEndereco().getCidade().getUf();
            dados[7] = pesEndereco.getEndereco().getCep();
          } catch (Exception e) {
            dados[0] = "";
            dados[1] = "";
            dados[2] = "";
            dados[3] = "";
            dados[4] = "";
            dados[5] = "";
            dados[6] = "";
            dados[7] = "";
          }
          try {
            dados[8] = pesDestinatario.getEndereco().getLogradouro().getDescricao();
            dados[9] = pesDestinatario.getEndereco().getDescricaoEndereco().getDescricao();
            dados[10] = pesDestinatario.getNumero();
            dados[11] = pesDestinatario.getComplemento();
            dados[12] = pesDestinatario.getEndereco().getBairro().getDescricao();
            dados[13] = pesDestinatario.getEndereco().getCidade().getCidade();
            dados[14] = pesDestinatario.getEndereco().getCidade().getUf();
            dados[15] = pesDestinatario.getEndereco().getCep();
            dados[26] = pesDestinatario.getPessoa().getDocumento();
            dados[27] = pesDestinatario.getPessoa().getNome();
          } catch (Exception e) {
            dados[8] = "";
            dados[9] = "";
            dados[10] = "";
            dados[11] = "";
            dados[12] = "";
            dados[13] = "";
            dados[14] = "";
            dados[15] = "";
            dados[26] = "";
            dados[27] = "";
          }
          try {
            dados[16] = pesEmpresa.getJuridica().getPessoa().getNome();
            dados[17] = pesEmpresa.getJuridica().getPessoa().getTelefone1();
            dados[18] = pesEmpresa.getFuncao().getProfissao();
            dados[19] = pesEndEmpresa.getEndereco().getDescricaoEndereco().getDescricao();
            dados[20] = pesEndEmpresa.getNumero();
            dados[21] = pesEndEmpresa.getComplemento();
            dados[22] = pesEndEmpresa.getEndereco().getBairro().getDescricao();
            dados[23] = pesEndEmpresa.getEndereco().getCidade().getCidade();
            dados[24] = pesEndEmpresa.getEndereco().getCidade().getUf();
            dados[25] = pesEndEmpresa.getEndereco().getCep();
            dados[28] = pesEmpresa.getAdmissao();
            dados[29] = pesEmpresa.getJuridica().getPessoa().getDocumento();
            dados[30] = pesEmpresa.getJuridica().getFantasia();
            dados[31] = pesEndEmpresa.getEndereco().getLogradouro().getDescricao();
            dados[32] = pesEmpresa.getCodigo();
          } catch (Exception e) {
            dados[16] = "";
            dados[17] = "";
            dados[18] = "";
            dados[19] = "";
            dados[20] = "";
            dados[21] = "";
            dados[22] = "";
            dados[23] = "";
            dados[24] = "";
            dados[25] = "";
            dados[28] = "";
            dados[29] = "";
            dados[30] = "";
            dados[31] = "";
            dados[32] = "";
          }

          try {
            listaSocios.add(
                new FichaSocial(
                    0,
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1()).getId(),
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                        .getMatriculaSocios()
                        .getNrMatricula(),
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                        .getServicoPessoa()
                        .getEmissao(),
                    null,
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                        .getMatriculaSocios()
                        .getCategoria()
                        .getGrupoCategoria()
                        .getGrupoCategoria(),
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                        .getMatriculaSocios()
                        .getCategoria()
                        .getCategoria(),
                    fisica.getPessoa().getNome(),
                    fisica.getSexo(),
                    fisica.getNascimento(),
                    fisica.getNaturalidade(),
                    fisica.getNacionalidade(),
                    fisica.getRg(),
                    fisica.getPessoa().getDocumento(),
                    fisica.getCarteira(),
                    fisica.getSerie(),
                    fisica.getEstadoCivil(),
                    fisica.getPai(),
                    fisica.getMae(),
                    fisica.getPessoa().getTelefone1(),
                    fisica.getPessoa().getTelefone3(),
                    fisica.getPessoa().getEmail1(),
                    dados[0],
                    dados[1],
                    dados[2],
                    dados[3],
                    dados[4],
                    dados[5],
                    dados[6],
                    dados[7],
                    false,
                    dados[26],
                    dados[27],
                    dados[8],
                    dados[9],
                    dados[10],
                    dados[11],
                    dados[12],
                    dados[13],
                    dados[14],
                    dados[15],
                    dados[16],
                    dados[17],
                    null, // fax
                    dados[28],
                    dados[18],
                    dados[19],
                    dados[20],
                    dados[21],
                    dados[22],
                    dados[23],
                    dados[24],
                    dados[25],
                    ((ServletContext) faces.getExternalContext().getContext())
                        .getRealPath("/Imagens/LogoCliente.png"),
                    "", // obs
                    ((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())
                        .getParentesco()
                        .getParentesco(),
                    sindicato.getPessoa().getNome(),
                    pesEndSindicato.getEndereco().getDescricaoEndereco().getDescricao(),
                    pesEndSindicato.getNumero(),
                    pesEndSindicato.getComplemento(),
                    pesEndSindicato.getEndereco().getBairro().getDescricao(),
                    pesEndSindicato.getEndereco().getCidade().getCidade(),
                    pesEndSindicato.getEndereco().getCidade().getUf(),
                    pesEndSindicato.getEndereco().getCep(),
                    sindicato.getPessoa().getDocumento(),
                    "",
                    ((ServletContext) faces.getExternalContext().getContext())
                        .getRealPath("/Imagens/LogoCliente.png"),
                    getFotoSocio(((Socios) ((DataObject) listaSoc.get(i)).getArgumento1())),
                    sindicato.getPessoa().getEmail1(),
                    sindicato.getPessoa().getSite(),
                    sindicato.getPessoa().getTelefone1(),
                    ((ServletContext) faces.getExternalContext().getContext())
                        .getRealPath(
                            "/Cliente/"
                                + ControleUsuarioBean.getCliente()
                                + "/Relatorios/FICHACADASTRO.jasper"),
                    dados[29],
                    fisica.getPessoa().getRecadastroString(),
                    dados[30],
                    pesEndSindicato.getEndereco().getLogradouro().getDescricao(),
                    dados[31],
                    "",
                    dados[32],
                    fisica.getPis()));

          } catch (Exception erro) {
            System.err.println("O arquivo não foi gerado corretamente! Erro: " + erro.getMessage());
            continue;
          }
        }
      }
      JRBeanCollectionDataSource dtSource = new JRBeanCollectionDataSource(listaSocios);
      JasperPrint print = JasperFillManager.fillReport(jasper, null, dtSource);
      byte[] arquivo = JasperExportManager.exportReportToPdf(print);
      response.setContentType("application/pdf");
      response.setContentLength(arquivo.length);
      ServletOutputStream saida = response.getOutputStream();
      saida.write(arquivo, 0, arquivo.length);
      saida.flush();
      saida.close();

      FacesContext.getCurrentInstance().responseComplete();
      Download download =
          new Download(
              "Ficha Social " + fisica.getPessoa().getId() + ".pdf",
              ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext())
                  .getRealPath("/socios.jsf"),
              "application/pdf",
              FacesContext.getCurrentInstance());
      download.baixar();
    } catch (Exception erro) {
      System.err.println("O arquivo não foi gerado corretamente! Erro: " + erro.getMessage());
    }
  }