Esempio n. 1
0
  public void imprimiTexto(ResultSet rs, TYPE_PRINT bVisualizar, String sCab) {

    BigDecimal bTotal = new BigDecimal("0");
    BigDecimal bSaldo = new BigDecimal("0");
    BigDecimal bSaldoLinha = new BigDecimal("0");
    BigDecimal bVlrDeb = new BigDecimal("0");
    BigDecimal bVlrCred = new BigDecimal("0");
    BigDecimal bVlrTotDeb = new BigDecimal("0");
    BigDecimal bVlrTotCred = new BigDecimal("0");
    BigDecimal bAnt = buscaSaldoAnt();
    ImprimeOS imp = new ImprimeOS("", con);
    String linhafina = StringFunctions.replicate("-", 133);
    String sDataLanca = "";
    String sConta = "";
    String sCodConta = txtCodConta.getVlrString();

    boolean bPrim = true;
    int linPag = imp.verifLinPag() - 1;

    try {

      imp.limpaPags();
      imp.setTitulo("Extrato Bancário");
      imp.addSubTitulo("EXTRATO BANCÁRIO");
      sConta = "CONTA: " + sCodConta + " - " + txtDescConta.getVlrString();
      imp.addSubTitulo(sConta);

      while (rs.next()) {

        if (!bPrim) {

          if (!(sDataLanca.equals(rs.getString("DataSL")))) {
            bTotal = new BigDecimal(rs.getString("SaldoSL"));
          }
        } else {
          bTotal = new BigDecimal(rs.getString("SaldoSL"));
        }

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

          imp.montaCab();
          imp.impCab(136, true);

          imp.say(0, imp.comprimido());
          imp.say(0, "|" + linhafina + "|");
          imp.pulaLinha(1, imp.comprimido());
          imp.say(0, "| Data");
          imp.say(14, "| Historico");
          imp.say(69, "| Doc");
          imp.say(82, "| Débito");
          imp.say(100, "| Crédito");
          imp.say(118, "| Saldo");
          imp.say(135, "|");
          imp.pulaLinha(1, imp.comprimido());
          imp.say(0, "|" + linhafina + "|");

          if (bPrim) {

            imp.pulaLinha(1, imp.comprimido());
            imp.say(0, "|");
            imp.say(
                103,
                "Saldo Anterior: "
                    + Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bAnt.toString()));
            imp.say(135, "|");
            imp.pulaLinha(1, imp.comprimido());
            imp.say(0, "|" + linhafina + "|");
            bSaldoLinha = new BigDecimal(bAnt.toString());
          }
        }
        bPrim = false;
        bSaldo = new BigDecimal(rs.getBigDecimal("SaldoSL").toString());
        bAnt = bSaldo;
        sDataLanca = rs.getString("DataSL");
        bSaldoLinha = bSaldoLinha.add(rs.getBigDecimal("VlrSubLanca"));

        if (rs.getFloat("VlrSubLanca") < 0) {
          bVlrDeb = new BigDecimal(rs.getBigDecimal("VlrSubLanca").toString()).abs();
          bVlrCred = new BigDecimal("0.00");
          bVlrTotDeb = bVlrTotDeb.add(new BigDecimal(bVlrDeb.toString()));
        } else {
          bVlrCred = new BigDecimal(rs.getBigDecimal("VlrSubLanca").toString());
          bVlrDeb = new BigDecimal("0.00");
          bVlrTotCred = bVlrTotCred.add(new BigDecimal(bVlrCred.toString()));
        }

        imp.pulaLinha(1, imp.comprimido());
        imp.say(0, "| " + StringFunctions.sqlDateToStrDate(rs.getDate("DataSL")));
        imp.say(14, "| " + Funcoes.copy(rs.getString("HistBLanca"), 0, 50));
        imp.say(69, "| " + Funcoes.alinhaDir(rs.getString("DocLanca"), 10));
        imp.say(82, "|");
        if (bVlrDeb.floatValue() != 0) {
          imp.say(
              imp.pRow() + 0,
              84,
              Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bVlrDeb.toString()));
        }
        imp.say(100, "|");
        if (bVlrCred.floatValue() != 0) {
          imp.say(
              0,
              102,
              Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bVlrCred.toString()));
        }
        imp.say(
            118,
            "|"
                + Funcoes.strDecimalToStrCurrency(
                    15, Aplicativo.casasDecFin, bSaldoLinha.toString()));
        imp.say(135, "|");
      }
      imp.pulaLinha(1, imp.comprimido());
      imp.say(0, "|" + linhafina + "|");
      imp.pulaLinha(1, imp.comprimido());
      imp.say(0, "|");
      imp.say(82, "|");
      imp.say(
          84, Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bVlrTotDeb.toString()));
      imp.say(100, "|");
      imp.say(
          102, Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bVlrTotCred.toString()));
      imp.say(118, "|");
      imp.say(119, Funcoes.strDecimalToStrCurrency(15, Aplicativo.casasDecFin, bTotal.toString()));
      imp.say(135, "|");
      imp.pulaLinha(1, imp.comprimido());
      imp.say(0, "+" + linhafina + "+");

      imp.eject();
      imp.fechaGravacao();

      rs.close();
      con.commit();

    } catch (Exception e) {

      e.printStackTrace();
    }
    if (bVisualizar == TYPE_PRINT.VIEW) {
      imp.preview(this);
    } else {
      imp.print();
    }
  }
Esempio n. 2
0
  private void montaRel() {

    imprimeRodape(false);
    Vector<Vector<Object>> vData = new Vector<Vector<Object>>();
    double dVlrOutros = 0.0;
    double dVlrTotal = 0.0;
    double dValor = 0.0;
    double dValorPerc = 0.0;
    String sLabel = "";
    try {
      while (rs.next()) {
        Vector<Object> vLinha = new Vector<Object>();
        vLinha.addElement(rs.getString(2).trim());
        vLinha.addElement(new Double(rs.getDouble(4)));
        vData.addElement(vLinha);
        dVlrTotal += rs.getDouble(4);
      }
    } catch (SQLException e) {
      Funcoes.mensagemInforma(this, "Erro na consulta de valores!\n" + e.getMessage());
    }

    for (int i2 = 0; vData.size() > i2; i2++) {
      dValor = ((Double) vData.elementAt(i2).elementAt(1)).doubleValue();
      dValorPerc = (dValor * 100) / dVlrTotal;
      if (dValorPerc < 3.0) {
        dVlrOutros += dValor;
      } else {
        sLabel = ((String) vData.elementAt(i2).elementAt(0));
        sLabel = sLabel + " (" + Funcoes.strDecimalToStrCurrency(14, 2, dValor + "") + " ) ";
        datasetBar.addValue(dValor, sLabel, "");
      }
    }
    if (dVlrOutros > 0.0) datasetBar.addValue(dVlrOutros, "Outros valores", "");

    JFreeChart chart = createChart(datasetBar);

    setBordaRel();

    int iY = 35;

    drawLinha(0, iY, 0, 0, AL_LL);

    iY += 14;

    setFonte(fnTopEmp);
    drawTexto(
        sTitulo1, 0, iY, getFontMetrics(fnCabEmp).stringWidth("  " + sTitulo1 + "  "), AL_CEN);
    setFonte(fnCabEmpNeg);

    iY += 6;

    drawLinha(0, iY, 0, 0, AL_LL);

    iY += 14;

    setFonte(fnTopEmp);
    drawTexto(
        sTitulo2, 0, iY, getFontMetrics(fnCabEmp).stringWidth("  " + sTitulo2 + "  "), AL_CEN);
    setFonte(fnCabEmpNeg);

    iY += 6;

    drawLinha(0, iY, 0, 0, AL_LL);

    iY += 50;

    drawGrafico(chart, 15, iY, 500, 550);

    iY += 12;

    setFonte(fnTopEmp);
    drawTexto(
        "Valor total:" + Funcoes.strDecimalToStrCurrency(14, 2, dVlrTotal + ""),
        0,
        iY,
        getFontMetrics(fnCabEmp)
            .stringWidth(
                "  Valor total:" + Funcoes.strDecimalToStrCurrency(14, 2, dVlrTotal + "") + "  "),
        AL_CEN);

    termPagina();
    finaliza();
  }
Esempio n. 3
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();
    }
  }