Esempio n. 1
0
 public Vector<Object> loadProdItemVenda(
     Integer codempvd,
     Integer codfilialvd,
     Date dtemitvenda,
     Integer codempcl,
     Integer codfilialcl,
     Integer codcli,
     Integer codemppd,
     Integer codfilialpd,
     Integer codprod)
     throws Exception {
   Vector<Object> row = new Vector<Object>();
   try {
     StringBuilder sql = new StringBuilder();
     /*
     			STATUSVENDA, STATUSPGTO, CODVENDA, DOCVENDA, DTEMITVENDA, CODPROD, DESCPROD, QTDITVENDA, PRECOITVENDA, PERCDESCITVENDA
     , VLRDESCITVENDA, VLRLIQITVENDA, TIPOVENDA;*/
     sql.append("select first 1 vd.statusvenda, vd.codvenda, vd.docvenda, vd.dtemitvenda");
     sql.append(", pd.codprod, pd.descprod, iv.qtditvenda, iv.precoitvenda, iv.percdescitvenda ");
     sql.append(
         ", iv.vlrdescitvenda, iv.vlrliqitvenda, vd.tipovenda, vd.codplanopag, pg.descplanopag ");
     sql.append(", vo.codvend, vo.nomevend, ax.codalmox, ax.descalmox ");
     sql.append("from vdvenda vd ");
     sql.append("inner join vditvenda iv ");
     sql.append(
         "on iv.codemp=vd.codemp and iv.codfilial=vd.codfilial and iv.tipovenda=vd.tipovenda and iv.codvenda=vd.codvenda ");
     sql.append("and iv.codemppd=? and iv.codfilialpd=? and iv.codprod=? ");
     sql.append("inner join eqproduto pd ");
     sql.append(
         "on pd.codemp=iv.codemppd and pd.codfilial=iv.codfilialpd and pd.codprod=iv.codprod ");
     sql.append("inner join fnplanopag pg ");
     sql.append(
         "on pg.codemp=vd.codemppg and pg.codfilial=vd.codfilialpg and pg.codplanopag=vd.codplanopag ");
     sql.append("inner join vdvendedor vo ");
     sql.append(
         "on vo.codemp=vd.codempvd and vo.codfilial=vd.codfilialvd and vo.codvend=vd.codvend ");
     sql.append("inner join eqalmox ax ");
     sql.append(
         "on ax.codemp=pd.codempax and ax.codfilial=pd.codfilialax and ax.codalmox=pd.codalmox ");
     sql.append("where vd.codemp=? and vd.codfilial=? and vd.tipovenda='V' and dtemitvenda=? ");
     sql.append("and substring(vd.statusvenda from 1 for 1) not in ('C','N') ");
     sql.append("and vd.codempcl=? and vd.codfilialcl=? and vd.codcli=? ");
     sql.append("order by vd.dtemitvenda desc");
     PreparedStatement ps = getConn().prepareStatement(sql.toString());
     int iparam = 1;
     ps.setInt(iparam++, codemppd);
     ps.setInt(iparam++, codfilialpd);
     ps.setInt(iparam++, codprod);
     ps.setInt(iparam++, codempvd);
     ps.setInt(iparam++, codfilialvd);
     ps.setDate(iparam++, Funcoes.dateToSQLDate(dtemitvenda));
     ps.setInt(iparam++, codempcl);
     ps.setInt(iparam++, codfilialcl);
     ps.setInt(iparam++, codcli);
     ResultSet rs = ps.executeQuery();
     if (rs.next()) {
       String tipovenda = rs.getString("TIPOVENDA");
       Integer codvenda = rs.getInt("CODVENDA");
       String statusvenda = rs.getString("STATUSVENDA");
       java.sql.Date emaberto = null;
       Integer pago = null;
       Integer atraso = null;
       Object[] result_receber2 = loadReceber2(codempvd, codfilialvd, tipovenda, codvenda);
       if (result_receber2 != null) {
         pago = (Integer) result_receber2[RESULT_RECEBER2.PAGO.ordinal()];
         emaberto = (java.sql.Date) result_receber2[RESULT_RECEBER2.EMABERTO.ordinal()];
         atraso = (Integer) result_receber2[RESULT_RECEBER2.ATRASO.ordinal()];
       }
       imgColuna = getImgStatus(statusvenda);
       imgVencimento = getImgVencimento(statusvenda, emaberto, pago, atraso);
       row.addElement(imgColuna);
       row.addElement(imgVencimento);
       row.addElement(codvenda);
       row.addElement(rs.getString("DOCVENDA"));
       row.addElement(Funcoes.dateToStrDate(rs.getDate("DTEMITVENDA")));
       row.addElement(rs.getInt("CODPROD"));
       row.addElement(rs.getString("DESCPROD"));
       row.addElement(Funcoes.bdToStr(rs.getBigDecimal("QTDITVENDA")));
       row.addElement(Funcoes.bdToStr(rs.getBigDecimal("PRECOITVENDA")));
       row.addElement(Funcoes.bdToStr(rs.getBigDecimal("PERCDESCITVENDA")));
       row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRDESCITVENDA")));
       row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRLIQITVENDA")));
       row.addElement(tipovenda);
       row.addElement(rs.getInt("CODPLANOPAG"));
       row.addElement(rs.getString("DESCPLANOPAG"));
       row.addElement(rs.getInt("CODVEND"));
       row.addElement(rs.getString("NOMEVEND"));
       row.addElement(rs.getInt("CODALMOX"));
       row.addElement(rs.getString("DESCALMOX"));
     }
     rs.close();
     ps.close();
   } catch (SQLException e) {
     getConn().rollback();
     throw new Exception(e.getMessage());
   }
   return row;
 }
Esempio n. 2
0
  public Vector<Vector<Object>> loadVendas(
      Integer codempvd,
      Integer codfilialvd,
      Integer codempcl,
      Integer codfilialcl,
      Integer codcli,
      Integer codemppd,
      Integer codfilialpd,
      Integer codprod,
      Date dtini,
      Date dtfim)
      throws Exception {
    Vector<Vector<Object>> result = new Vector<Vector<Object>>();
    try {
      StringBuilder sql = new StringBuilder();
      sql.append("select v.codvenda, v.docvenda, v.dtemitvenda, v.statusvenda, v.codplanopag");
      sql.append(
          ", p.descplanopag, v.codvend, vd.nomevend, coalesce(v.vlrprodvenda,0) vlrprodvenda, coalesce(v.vlrdescvenda,0) vlrdescvenda");
      sql.append(
          ", coalesce(v.vlradicvenda,0) vlradicvenda , coalesce(v.vlrfretevenda,0) vlrfretevenda, coalesce(v.vlrliqvenda,0) vlrliqvenda, v.tipovenda");
      sql.append(
          " , coalesce((select vf.tipofretevd from vdfretevd vf where vf.codemp = v.codemp and vf.codfilial = v.codfilial and vf.tipovenda = v.tipovenda and vf.codvenda = v.codvenda), 'N')  as tipofrete ");
      sql.append("from vdvenda v, fnplanopag p, vdvendedor vd, eqtipomov tm ");
      sql.append(
          "where v.codemp=? and v.codfilial=? and v.tipovenda='V' and v.dtemitvenda between ? and ?");
      // sql.append( "and substring( v.statusvenda from 1 for 1) not in ('D','C') ");
      sql.append(
          "and p.codemp=v.codemppg and p.codfilial=v.codfilialpg and p.codplanopag=v.codplanopag ");
      sql.append(
          "and vd.codemp=v.codempvd and vd.codfilial=v.codfilialvd and vd.codvend=v.codvend");
      if (codcli.intValue() > 0) {
        sql.append(" and v.codempcl=? and v.codfilialcl=? AND codcli=? ");
      }
      if (codprod > 0) {
        sql.append(" and exists (");
        sql.append(" select codvenda from vditvenda iv where ");
        sql.append(
            " iv.codemp=v.codemp and iv.codfilial=v.codfilial and iv.codvenda=v.codvenda and iv.tipovenda=v.tipovenda ");
        sql.append(" and iv.codemppd=? and iv.codfilialpd=? and iv.codprod=? ) ");
      }
      sql.append(
          " and tm.codemp=v.codemptm and tm.codfilial=v.codfilialtm and tm.codtipomov=v.codtipomov ");
      sql.append(" and tm.somavdtipomov='S' ");
      sql.append(" order by v.dtemitvenda desc, v.docvenda desc");
      PreparedStatement ps = getConn().prepareStatement(sql.toString());
      int iparam = 1;
      ps.setInt(iparam++, codempvd);
      ps.setInt(iparam++, codfilialvd);
      ps.setDate(iparam++, Funcoes.dateToSQLDate(dtini));
      ps.setDate(iparam++, Funcoes.dateToSQLDate(dtfim));
      if (codcli.intValue() > 0) {
        ps.setInt(iparam++, codempcl);
        ps.setInt(iparam++, codfilialcl);
        ps.setInt(iparam++, codcli);
      }
      if (codprod.intValue() > 0) {
        ps.setInt(iparam++, codemppd);
        ps.setInt(iparam++, codfilialpd);
        ps.setInt(iparam++, codprod);
      }
      ResultSet rs = ps.executeQuery();

      while (rs.next()) {
        Vector<Object> row = new Vector<Object>();
        String tipovenda = rs.getString("TIPOVENDA");
        Integer codvenda = rs.getInt("CODVENDA");
        String statusvenda = rs.getString("STATUSVENDA");
        java.sql.Date emaberto = null;
        Integer pago = null;
        Integer atraso = null;
        StringDireita stratraso = new StringDireita("");
        Object[] result_receber2 = loadReceber2(codempvd, codfilialvd, tipovenda, codvenda);
        if (result_receber2 != null) {
          pago = (Integer) result_receber2[RESULT_RECEBER2.PAGO.ordinal()];
          emaberto = (java.sql.Date) result_receber2[RESULT_RECEBER2.EMABERTO.ordinal()];
          atraso = (Integer) result_receber2[RESULT_RECEBER2.ATRASO.ordinal()];
          if ((atraso != null) && (atraso.intValue() != 0)) {
            stratraso = new StringDireita(atraso.toString());
          }
        }
        imgColuna = getImgStatus(statusvenda);
        imgVencimento = getImgVencimento(statusvenda, emaberto, pago, atraso);
        row.addElement(imgColuna);
        row.addElement(imgVencimento);
        row.addElement(stratraso);
        row.addElement(codvenda);
        row.addElement(rs.getString("DOCVENDA"));
        row.addElement(Funcoes.dateToStrDate(rs.getDate("DTEMITVENDA")));
        row.addElement(rs.getString("DESCPLANOPAG"));
        row.addElement(rs.getString("NOMEVEND"));
        row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRPRODVENDA")));
        row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRDESCVENDA")));
        row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRADICVENDA")));
        row.addElement(getTipoFrete(rs.getString("TIPOFRETE")));
        row.addElement(Funcoes.bdToStr(rs.getBigDecimal("VLRLIQVENDA")));
        row.addElement(tipovenda);
        result.addElement(row);
      }
      rs.close();
      ps.close();
      getConn().commit();
    } catch (SQLException e) {
      getConn().rollback();
      throw new Exception(e.getMessage());
    }
    return result;
  }
Esempio n. 3
0
  private void carregaItens() {

    try {
      tabDet.limpa();

      ResultSet rs =
          daopush.carregaItens(
              Aplicativo.iCodEmp,
              ListaCampos.getMasterFilial("EQPRODUTO"),
              txtCodProd.getVlrInteger(),
              lcSecao.getCodEmp(),
              lcSecao.getCodFilial(),
              txtCodSecao.getVlrString());

      int row = 0;

      BigDecimal totqtdminimo = new BigDecimal(0);
      BigDecimal totqtdestoq = new BigDecimal(0);
      BigDecimal totqtdreq = new BigDecimal(0);
      BigDecimal totqtdemprod = new BigDecimal(0);
      BigDecimal totqtdaprod = new BigDecimal(0);

      ResultSet rs2 = null;

      PreparedStatement ps2 = null;

      while (rs.next()) {

        BigDecimal qtdreserv = new BigDecimal(0);

        BigDecimal qtdminimo =
            rs.getBigDecimal(DETALHAMENTO.QTDMINPROD.toString()).setScale(Aplicativo.casasDec);
        BigDecimal qtdestoque =
            rs.getBigDecimal(DETALHAMENTO.QTDESTOQUE.toString()).setScale(Aplicativo.casasDec);

        BigDecimal qtdemprod =
            rs.getBigDecimal(DETALHAMENTO.QTDEMPROD.toString()).setScale(Aplicativo.casasDec);
        BigDecimal qtdreq =
            rs.getBigDecimal(DETALHAMENTO.QTDREQ.toString()).setScale(Aplicativo.casasDec);

        BigDecimal qtdaprod =
            new BigDecimal(
                qtdminimo.floatValue()
                    + qtdreq.floatValue()
                    - qtdestoque.floatValue()
                    - qtdemprod.floatValue());

        totqtdminimo = totqtdminimo.add(qtdminimo);
        totqtdestoq = totqtdestoq.add(qtdestoque);
        totqtdreq = totqtdreq.add(qtdreq);
        totqtdemprod = totqtdemprod.add(qtdemprod);
        totqtdaprod = totqtdaprod.add(qtdaprod);

        if (qtdaprod.floatValue() > 0) {
          tabDet.adicLinha();
          tabDet.setColColor(-1, DETALHAMENTO.DTFABROP.ordinal(), Color.WHITE, Color.RED);
          tabDet.setColColor(-1, DETALHAMENTO.QTDAPROD.ordinal(), Color.WHITE, Color.RED);

          tabDet.setValor(new Boolean(false), row, DETALHAMENTO.MARCACAO.ordinal());

          if (qtdreq.floatValue() > 0) {
            imgColuna = imgUrgente;
          } else {
            imgColuna = imgNormal;
          }

          tabDet.setValor(imgColuna, row, DETALHAMENTO.STATUS.ordinal());

          tabDet.setValor(Funcoes.dateToStrDate(new Date()), row, DETALHAMENTO.DTFABROP.ordinal());
          tabDet.setValor(
              rs.getInt(DETALHAMENTO.CODEMPPD.toString()), row, DETALHAMENTO.CODEMPPD.ordinal());
          tabDet.setValor(
              rs.getInt(DETALHAMENTO.CODFILIALPD.toString()),
              row,
              DETALHAMENTO.CODFILIALPD.ordinal());
          tabDet.setValor(
              rs.getInt(DETALHAMENTO.CODPROD.toString()), row, DETALHAMENTO.CODPROD.ordinal());
          tabDet.setValor(
              rs.getString(DETALHAMENTO.REFPROD.toString()), row, DETALHAMENTO.REFPROD.ordinal());
          tabDet.setValor(
              rs.getInt(DETALHAMENTO.SEQEST.toString()), row, DETALHAMENTO.SEQEST.ordinal());
          tabDet.setValor(
              rs.getString(DETALHAMENTO.DESCPROD.toString().trim()),
              row,
              DETALHAMENTO.DESCPROD.ordinal());

          tabDet.setValor(qtdminimo, row, DETALHAMENTO.QTDMINPROD.ordinal());
          tabDet.setValor(qtdestoque, row, DETALHAMENTO.QTDESTOQUE.ordinal());
          tabDet.setValor(qtdreq, row, DETALHAMENTO.QTDREQ.ordinal());
          tabDet.setValor(qtdemprod, row, DETALHAMENTO.QTDEMPROD.ordinal());
          tabDet.setValor(qtdaprod, row, DETALHAMENTO.QTDAPROD.ordinal());

          row++;
        }

        if (totqtdaprod.floatValue() < 0) {
          totqtdaprod = new BigDecimal(0);
        }

        txtQtdRequisitada.setVlrBigDecimal(totqtdreq);
        txtQtdEstoque.setVlrBigDecimal(totqtdestoq);

        if (txtCodProd.getVlrInteger() > 0) {

          txtQtdProducao.setVlrBigDecimal(totqtdemprod);
          txtQtdProduzir.setVlrBigDecimal(totqtdaprod);

        } else {

          txtQtdProducao.setVlrString("-");
          txtQtdProduzir.setVlrString("-");
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void imprimir(TYPE_PRINT bVisualizar) {

    if (txtDatafim.getVlrDate().before(txtDataini.getVlrDate())) {
      Funcoes.mensagemInforma(this, "Data final maior que a data inicial!");
      return;
    }

    PreparedStatement ps = null;
    ResultSet rs = null;
    StringBuffer sql = new StringBuffer();
    StringBuffer sCab = new StringBuffer();

    sCab.append(
        "Período de : "
            + Funcoes.dateToStrDate(txtDataini.getVlrDate())
            + "Até : "
            + Funcoes.dateToStrDate(txtDatafim.getVlrDate()));

    try {

      sql.append(
          "SELECT CL.CODVEND, VO.NOMEVEND, CL.CODCLI, CL.RAZCLI, ( SELECT MAX(DTEMITVENDA) FROM VDVENDA VD, VDCLIENTE SB ");
      sql.append("WHERE SB.CODEMPPQ=CL.CODEMP AND ");
      sql.append("SB.CODFILIALPQ=CL.CODFILIAL AND ");
      sql.append("SB.CODPESQ=CL.CODCLI AND ");
      sql.append(
          "VD.CODEMPCL=SB.CODEMP AND VD.CODFILIALCL=SB.CODFILIAL AND VD.CODCLI=SB.CODCLI) ULTIMACOMPRA ");
      sql.append("FROM VDCLIENTE CL LEFT OUTER JOIN VDVENDEDOR VO ON ");
      sql.append(
          "VO.CODEMP=CL.CODEMPVD AND VO.CODFILIAL=CL.CODFILIALVD AND VO.CODVEND=CL.CODVEND ");
      sql.append("WHERE ");
      sql.append(
          "CL.CODEMP=CL.CODEMPPQ AND CL.CODFILIAL=CL.CODFILIALPQ AND CL.CODCLI=CL.CODPESQ AND ");
      sql.append("NOT EXISTS( SELECT * FROM VDVENDA VD, VDCLIENTE SB ");
      sql.append("WHERE SB.CODEMPPQ=CL.CODEMP AND ");
      sql.append("SB.CODFILIALPQ=CL.CODFILIAL AND ");
      sql.append("SB.CODPESQ=CL.CODCLI AND ");
      sql.append(
          "VD.CODEMPCL=SB.CODEMP AND VD.CODFILIALCL=SB.CODFILIAL AND VD.CODCLI=SB.CODCLI AND ");
      sql.append("VD.DTEMITVENDA BETWEEN ? AND ? ) ");
      sql.append("AND CL.ATIVOCLI='S' ");

      if (txtCodComiss.getVlrInteger() > 0) {
        sql.append(" and cl.codempvd=? and cl.codfilialvd=? and cl.codvend=? ");
      }

      sql.append("order by cl.codvend, cl.razcli ");

      ps = con.prepareStatement(sql.toString());

      int param = 1;

      ps.setDate(param++, Funcoes.dateToSQLDate(txtDataini.getVlrDate()));
      ps.setDate(param++, Funcoes.dateToSQLDate(txtDatafim.getVlrDate()));

      if (txtCodComiss.getVlrInteger() > 0) {
        ps.setInt(param++, lcComiss.getCodEmp());
        ps.setInt(param++, lcComiss.getCodFilial());
        ps.setInt(param++, txtCodComiss.getVlrInteger());
      }

      rs = ps.executeQuery();

      imprimiGrafico(bVisualizar, rs, sCab.toString());

      con.commit();

    } catch (Exception e) {
      e.printStackTrace();
      Funcoes.mensagemInforma(this, "Erro ao buscar dados do relatório!");
    }
  }
Esempio n. 5
0
  public void imprimir(TYPE_PRINT bVisualizar) {

    if (txtDatafim.getVlrDate().before(txtDataini.getVlrDate())) {
      Funcoes.mensagemInforma(this, "Data final maior que a data inicial!");
      return;
    }

    ImprimeOS imp = new ImprimeOS("", con);
    int linPag = imp.verifLinPag() - 1;
    int numcheque = 0;
    boolean pass = false;

    String sPag = "";

    String sDataini = "";
    String sDatafim = "";

    sDataini = txtDataini.getVlrString();
    sDatafim = txtDatafim.getVlrString();

    ResultSet rs = getResultSet();

    try {

      imp.limpaPags();

      while (rs.next()) {

        if (numcheque != rs.getInt("NCHEQUE")) {
          pass = true;
          numcheque = rs.getInt("NCHEQUE");
        } else pass = false;

        if (imp.pRow() >= (linPag - 1)) {
          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 89) + "|");
          imp.incPags();
          imp.eject();
        }
        if (imp.pRow() == 0) {
          imp.montaCab();
          imp.setTitulo("Relatório de saida x retorno" + sPag);
          imp.addSubTitulo(
              "RELATÓRIO DE SAIDA X RETORNO "
                  + sPag
                  + "   -   PERIODO DE :"
                  + sDataini
                  + " ATE: "
                  + sDatafim);
          imp.impCab(91, true);
          imp.say(imp.pRow() + 0, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 88) + "|");
        }

        if (pass == true) {

          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, StringFunctions.replicate("=", 90));
          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());

          imp.say(imp.pRow() + 0, 0, " Cliente:");
          imp.say(imp.pRow() + 0, 2, rs.getString("NOMECLI"));

          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());

          imp.say(imp.pRow() + 0, 2, "Num.Cheque:");
          imp.say(imp.pRow() + 0, 2, rs.getString("NCHEQUE"));
          imp.say(imp.pRow() + 0, 3, "Valor:");
          imp.say(imp.pRow() + 0, 2, rs.getString("VALOR"));
          imp.say(imp.pRow() + 0, 3, "Banco:");
          imp.say(imp.pRow() + 0, 2, rs.getString("banco"));

          imp.say(imp.pRow() + 2, 0, "" + imp.comprimido());

          imp.say(imp.pRow() + 0, 2, "Data/Saída");
          imp.say(imp.pRow() + 0, 3, "Descrição");
          imp.say(imp.pRow() + 0, 42, "Data/Retorno");
          imp.say(imp.pRow() + 0, 5, "Cód.Retorno");
          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, StringFunctions.replicate("-", 90));
        }

        imp.say(imp.pRow() + 1, 0, "" + imp.normal());
        imp.say(imp.pRow() + 0, 2, Funcoes.dateToStrDate(rs.getDate("Dates")));
        imp.say(imp.pRow() + 0, 3, rs.getString("DESCRICAO"));
        imp.say(imp.pRow() + 0, 5, Funcoes.dateToStrDate(rs.getDate("Dater")));
        imp.say(imp.pRow() + 0, 11, rs.getString("Codigor"));

        if (imp.pRow() >= linPag) {
          imp.incPags();
          imp.eject();
        }
      }

      imp.say(imp.pRow() + 1, 0, "" + imp.normal());
      imp.say(imp.pRow() + 0, 0, StringFunctions.replicate("=", 90));

      imp.eject();

      imp.fechaGravacao();

      con.commit();

    } catch (SQLException err) {
      Funcoes.mensagemErro(this, "Erro consulta tabela de Cheques!" + err.getMessage());
    }

    if (bVisualizar == TYPE_PRINT.VIEW) {
      imp.preview(this);
    } else {
      imp.print();
    }
  }
Esempio n. 6
0
  public void imprimir(TYPE_PRINT bVisualizar) {

    if (txtDatafim.getVlrDate().before(txtDataini.getVlrDate())) {
      Funcoes.mensagemInforma(this, "Data final maior que a data inicial!");
      return;
    }

    ImprimeOS imp = new ImprimeOS("", con);
    int linPag = imp.verifLinPag() - 1;
    boolean bFimDia = false;
    String sSQL = "";

    BigDecimal bTotalDiaVal = new BigDecimal("0");
    BigDecimal bTotalDiaDesc = new BigDecimal("0");
    BigDecimal bTotalDiaLiq = new BigDecimal("0");

    BigDecimal bTotalVal = new BigDecimal("0");
    BigDecimal bTotalDesc = new BigDecimal("0");
    BigDecimal bTotalLiq = new BigDecimal("0");

    imp.montaCab();
    String sDataini = "";
    String sDatafim = "";
    String sDtemitvenda = "";

    sDataini = txtDataini.getVlrString();
    sDatafim = txtDatafim.getVlrString();

    imp.setTitulo("Resumo Diário de Vendas");
    if (rgFormato.getVlrString().equals("D")) {
      sSQL =
          "SELECT V.DTEMITVENDA,V.CODTIPOMOV,V.CODVENDA,V.DOCVENDA,V.SERIE,"
              + "V.STATUSVENDA,V.DOCVENDA,"
              + "V.DTEMITVENDA,V.VLRPRODVENDA,V.VLRLIQVENDA,"
              + "V.CODPLANOPAG,P.DESCPLANOPAG,"
              + "V.VLRCOMISVENDA,V.VLRDESCITVENDA,"
              + "V.CODCLI,C.RAZCLI,V.STATUSVENDA"
              + " FROM VDVENDA V,VDCLIENTE C,FNPLANOPAG P, EQTIPOMOV TM "
              + "WHERE TM.CODTIPOMOV=V.CODTIPOMOV"
              + " AND TM.CODEMP=V.CODEMPTM"
              + " AND TM.CODFILIAL=V.CODFILIALTM"
              + " AND C.CODCLI=V.CODCLI"
              + " AND C.CODEMP=V.CODEMPCL AND C.CODFILIAL=V.CODFILIALCL"
              + " AND V.DTEMITVENDA BETWEEN ? AND ? AND "
              + "P.CODPLANOPAG=V.CODPLANOPAG AND V.FLAG IN "
              + AplicativoPD.carregaFiltro(con, org.freedom.library.swing.frame.Aplicativo.iCodEmp)
              + " AND V.CODEMP=? AND V.CODFILIAL=?"
              + " AND TM.TIPOMOV IN ('VD','PV','VT','SE')"
              + " AND NOT SUBSTR(V.STATUSVENDA,1,1)='C' ORDER BY V.DTEMITVENDA,V.DOCVENDA";
    } else if (rgFormato.getVlrString().equals("R")) {
      sSQL =
          "SELECT V.DTEMITVENDA,SUM(V.VLRLIQVENDA) FROM VDVENDA V,"
              + " EQTIPOMOV TM WHERE V.DTEMITVENDA BETWEEN ? AND ? AND V.FLAG IN "
              + AplicativoPD.carregaFiltro(con, org.freedom.library.swing.frame.Aplicativo.iCodEmp)
              + " AND TM.CODEMP=V.CODEMPTM"
              + " AND TM.CODFILIAL=V.CODFILIALTM"
              + " AND TM.CODTIPOMOV=V.CODTIPOMOV"
              + " AND TM.TIPOMOV IN ('VD','PV','VT','SE')"
              + " AND V.CODEMP=? AND V.CODFILIAL=? GROUP BY V.DTEMITVENDA";
      System.out.println(sSQL);
    }

    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
      ps = con.prepareStatement(sSQL);
      ps.setDate(1, Funcoes.dateToSQLDate(txtDataini.getVlrDate()));
      ps.setDate(2, Funcoes.dateToSQLDate(txtDatafim.getVlrDate()));
      ps.setInt(3, Aplicativo.iCodEmp);
      ps.setInt(4, ListaCampos.getMasterFilial("VDVENDA"));
      rs = ps.executeQuery();
      imp.limpaPags();

      if (rgFormato.getVlrString().equals("D")) {

        while (rs.next()) {

          if ((!StringFunctions.sqlDateToStrDate(rs.getDate("dtemitvenda")).equals(sDtemitvenda))
              & (bFimDia)) {
            imp.impCab(136, false);
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|");
            imp.say(
                imp.pRow() + 0,
                61,
                "Totais do Dia-> "
                    + sDtemitvenda
                    + " |"
                    + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalDiaVal)
                    + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalDiaDesc)
                    + Funcoes.strDecimalToStrCurrency(11, 2, "" + bTotalDiaLiq));
            imp.say(imp.pRow(), 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            bTotalDiaVal = new BigDecimal("0");
            bTotalDiaDesc = new BigDecimal("0");
            bTotalDiaLiq = new BigDecimal("0");
            bFimDia = false;
          }

          if (imp.pRow() >= (linPag - 1)) {
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            imp.incPags();
            imp.eject();
          }

          if (imp.pRow() == 0) {
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "+" + StringFunctions.replicate("-", 134) + "+");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|   Emitido em :" + Funcoes.dateToStrDate(new Date()));
            imp.say(imp.pRow() + 0, 120, "Pagina : " + (imp.getNumPags()));
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|");
            imp.say(
                imp.pRow() + 0,
                5,
                "RESUMO DIARIO DE VENDAS   -   PERIODO DE :" + sDataini + " Até: " + sDatafim);
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|");
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "| Dt. Emissao");
            imp.say(imp.pRow() + 0, 17, "NF./Ped.");
            imp.say(imp.pRow() + 0, 31, "Cliente");
            imp.say(imp.pRow() + 0, 88, "|    Valor   Desconto " + "   Liquido F.Pagto.");
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
          }

          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, "|");
          if (!StringFunctions.sqlDateToStrDate(rs.getDate("dtemitvenda")).equals(sDtemitvenda)) {
            imp.say(imp.pRow() + 0, 3, StringFunctions.sqlDateToStrDate(rs.getDate("dtemitvenda")));
          }

          imp.say(
              imp.pRow() + 0,
              17,
              rs.getString("StatusVenda").substring(0, 1).equals("P")
                  ? "P-" + Funcoes.copy(rs.getString("codvenda"), 0, 6)
                  : "V-" + Funcoes.copy(rs.getString("docvenda"), 0, 6));

          imp.say(
              imp.pRow() + 0,
              31,
              Funcoes.copy(rs.getString("codcli"), 0, 7)
                  + "-"
                  + Funcoes.copy(rs.getString("razcli"), 0, 49)
                  + "|"
                  + Funcoes.strDecimalToStrCurrency(10, 2, rs.getString("vlrprodvenda"))
                  + Funcoes.strDecimalToStrCurrency(10, 2, rs.getString("vlrdescitvenda"))
                  + Funcoes.strDecimalToStrCurrency(11, 2, rs.getString("vlrliqvenda"))
                  + " "
                  + Funcoes.copy(rs.getString("descplanopag"), 0, 15)
                  + "|");

          if (rs.getString("VlrProdVenda") != null) {
            bTotalDiaVal = bTotalDiaVal.add(new BigDecimal(rs.getString("VlrProdVenda")));
            bTotalVal = bTotalVal.add(new BigDecimal(rs.getString("VlrProdVenda")));
          }

          if (rs.getString("VlrDescitvenda") != null) {
            bTotalDiaDesc = bTotalDiaDesc.add(new BigDecimal(rs.getString("VlrDescitVenda")));
            bTotalDesc = bTotalDesc.add(new BigDecimal(rs.getString("VlrDescitVenda")));
          }

          if (rs.getString("VlrLiqVenda") != null) {
            bTotalDiaLiq = bTotalDiaLiq.add(new BigDecimal(rs.getString("VlrLiqVenda")));
            bTotalLiq = bTotalLiq.add(new BigDecimal(rs.getString("VlrLiqVenda")));
          }

          bFimDia = true;
          sDtemitvenda = StringFunctions.sqlDateToStrDate(rs.getDate("Dtemitvenda"));
        }

        if (bFimDia) {
          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
          imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
          imp.say(imp.pRow() + 0, 0, "|");
          imp.say(
              imp.pRow() + 0,
              61,
              "Totais do Dia-> "
                  + sDtemitvenda
                  + " |"
                  + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalDiaVal)
                  + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalDiaDesc)
                  + Funcoes.strDecimalToStrCurrency(11, 2, "" + bTotalDiaLiq));
          imp.say(imp.pRow(), 136, "|");
        }

        imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
        imp.say(imp.pRow(), 0, "|" + StringFunctions.replicate("-", 134) + "|");
        imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
        imp.say(imp.pRow() + 0, 0, "|");
        imp.say(
            imp.pRow() + 0,
            72,
            "Totais Geral    |"
                + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalVal)
                + Funcoes.strDecimalToStrCurrency(10, 2, "" + bTotalDesc)
                + Funcoes.strDecimalToStrCurrency(11, 2, "" + bTotalLiq));
        imp.say(imp.pRow(), 136, "|");

        imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
        imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");

      } else if (rgFormato.getVlrString().equals("R")) {
        iLinha = 1;
        iCol = 0;
        while (rs.next()) {
          if (imp.pRow() >= (linPag - 1)) {
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            imp.incPags();
            imp.eject();
          }
          if (imp.pRow() == 0) {
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "+" + StringFunctions.replicate("-", 134) + "+");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|   Emitido em :" + Funcoes.dateToStrDate(new Date()));
            imp.say(imp.pRow() + 0, 120, "Pagina : " + (imp.getNumPags()));
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|");
            imp.say(
                imp.pRow() + 0,
                5,
                "RESUMO DE TOTAL DE VENDAS - PERIODO DE :" + sDataini + " Até: " + sDatafim);
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "|" + StringFunctions.replicate("-", 134) + "|");
            imp.say(imp.pRow() + 1, 0, "" + imp.comprimido());
            imp.say(imp.pRow() + 0, 0, "|  Data");
            imp.say(imp.pRow() + 0, 14, "        Valor");
            imp.say(imp.pRow() + 0, 35, "|  Data");
            imp.say(imp.pRow() + 0, 49, "        Valor");
            imp.say(imp.pRow() + 0, 70, "|  Data");
            imp.say(imp.pRow() + 0, 84, "        Valor");
            imp.say(imp.pRow() + 0, 105, "|  Data");
            imp.say(imp.pRow() + 0, 119, "       Valor");
            imp.say(imp.pRow() + 0, 136, "|");
            imp.say(imp.pRow() + 1, 0, "|" + StringFunctions.replicate("-", 134) + "|");
          }

          imp.say(
              imp.pRow() + iLinha, iCol, "|  " + StringFunctions.sqlDateToStrDate(rs.getDate(1)));
          imp.say(
              imp.pRow() + 0,
              iCol + 14,
              " " + Funcoes.strDecimalToStrCurrency(15, 2, "" + rs.getString(2)));
          if (iCol == 0) {
            iLinha = 0;
            iCol = 35;
          } else if (iCol == 35) iCol = 70;
          else if (iCol == 70) iCol = 105;
          else {
            imp.say(imp.pRow() + 0, 136, "|");
            iCol = 0;
            iLinha = 1;
          }

          if (rs.getString(2) != null) {
            bTotalDiaLiq = bTotalDiaLiq.add(new BigDecimal(rs.getString(2)));
            bTotalLiq = bTotalLiq.add(new BigDecimal(rs.getString(2)));
          }
        }
      }
      if ((iCol < 105) && (iLinha == 0)) {
        imp.say(imp.pRow() + 0, 136, "|");
      }
      imp.say(imp.pRow() + 1, 0, "+" + StringFunctions.replicate("-", 134) + "+");
      imp.say(imp.pRow() + 1, 0, "|");
      imp.say(
          imp.pRow() + 0,
          88,
          "| Total Geral do Período   | " + Funcoes.strDecimalToStrCurrency(11, 2, "" + bTotalLiq));
      imp.say(imp.pRow(), 136, "|");
      imp.say(imp.pRow() + 1, 0, "+" + StringFunctions.replicate("-", 134) + "+");

      imp.eject();

      imp.fechaGravacao();

      // rs.close();
      // ps.close();
      con.commit();
      // dl.dispose();
    } catch (SQLException err) {
      Funcoes.mensagemErro(
          this, "Erro consulta tabela de vendas!" + err.getMessage(), true, con, err);
    }

    if (bVisualizar == TYPE_PRINT.VIEW) {
      imp.preview(this);
    } else {
      imp.print();
    }
  }