Search in sources :

Example 1 with Venda

use of br.senac.tads3.pi03b.gruposete.models.Venda in project Loja_Agencia_De_Viagens by ArtCouSan.

the class VendaServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileNotFoundException {
    double totalP = Double.parseDouble(request.getParameter("totalP"));
    if (totalP != 0) {
        String cpf = request.getParameter("cpf");
        ClienteDAO clienteData = new ClienteDAO();
        Cliente cliente = null;
        try {
            cliente = clienteData.getClienteByCPF(cpf);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        HttpSession sessao = request.getSession();
        int identificacaoF = (int) sessao.getAttribute("id_func");
        Venda venda = new Venda(cliente.getId(), identificacaoF, totalP);
        VendaDAO vendaData = new VendaDAO();
        try {
            vendaData.inserir(venda);
            RelatorioDAO relatorioDAO = new RelatorioDAO();
            RelatorioMudancas relatorio = new RelatorioMudancas();
            relatorio.setId_func(identificacaoF);
            relatorio.setMudanca("Venda efetuada!");
            relatorioDAO.inserir(relatorio);
        } catch (SQLException | ClassNotFoundException | ParseException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        int idLista = 0;
        try {
            idLista = vendaData.maiorIdVenda();
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        String idsVoos = request.getParameter("idsVoos");
        String idsHoteis = request.getParameter("idsHoteis");
        String precosVoos = request.getParameter("precosVoos");
        String precosHoteis = request.getParameter("precosHoteis");
        String quantidadeVoos = request.getParameter("quantidadeVoos");
        String quantidadeHoteis = request.getParameter("quantidadeHoteis");
        if (idsVoos.length() != 0) {
            String[] idsV = idsVoos.split(",");
            String[] precosV = precosVoos.split(",");
            String[] quantidadesV = quantidadeVoos.split(",");
            for (int i = 0; i < idsV.length; i++) {
                try {
                    VooDAO voo = new VooDAO();
                    int idV = Integer.parseInt(idsV[i]);
                    Voo vooEncontrado = voo.getVooById(idV);
                    int qtd_encontradaV = vooEncontrado.getQuantidade_passagens();
                    int quantidadeV = Integer.parseInt(quantidadesV[i]);
                    float precoV = Float.parseFloat(precosV[i]);
                    int novaQtdVoo = qtd_encontradaV - quantidadeV;
                    vendaData.inserirLista(idV, quantidadeV, precoV, idLista, "V");
                    vendaData.removerEstoqueVoo(idV, novaQtdVoo);
                } catch (SQLException | ClassNotFoundException ex) {
                    Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (idsHoteis.length() != 0) {
            String[] idsH = idsHoteis.split(",");
            String[] precosH = precosHoteis.split(",");
            String[] quantidadesH = quantidadeHoteis.split(",");
            for (int i = 0; i < idsH.length; i++) {
                try {
                    HotelDAO hotel = new HotelDAO();
                    int idH = Integer.parseInt(idsH[i]);
                    Hotel hotelEncontrado = hotel.getHotelById(idH);
                    int qtd_encontradaH = hotelEncontrado.getQuantidade_quartos();
                    int quantidadeH = Integer.parseInt(quantidadesH[i]);
                    float precoH = Float.parseFloat(precosH[i]);
                    int novaQtdHotel = qtd_encontradaH - quantidadeH;
                    vendaData.inserirLista(idH, quantidadeH, precoH, idLista, "H");
                    vendaData.removerEstoqueHotel(idH, novaQtdHotel);
                } catch (SQLException | ClassNotFoundException ex) {
                    Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        response.sendRedirect(request.getContextPath() + "/inicio");
    } else {
        response.sendRedirect(request.getContextPath() + "/inicio");
    }
}
Also used : SQLException(java.sql.SQLException) HotelDAO(br.senac.tads3.pi03b.gruposete.dao.HotelDAO) HttpSession(javax.servlet.http.HttpSession) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) VooDAO(br.senac.tads3.pi03b.gruposete.dao.VooDAO) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) Venda(br.senac.tads3.pi03b.gruposete.models.Venda) RelatorioDAO(br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) RelatorioMudancas(br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas) ParseException(java.text.ParseException) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente) Hotel(br.senac.tads3.pi03b.gruposete.models.Hotel)

Example 2 with Venda

use of br.senac.tads3.pi03b.gruposete.models.Venda in project Loja_Agencia_De_Viagens by ArtCouSan.

the class RelatorioDAO method procurarRelatorioAno.

public ArrayList<RelatorioValores> procurarRelatorioAno() throws SQLException, ClassNotFoundException {
    // Conecta.
    connection = DbUtil.getConnection();
    // Lista que ira receber vendas.
    ArrayList<RelatorioValores> listaResultado = new ArrayList<>();
    // Comando SQL.
    String slq = "SELECT (SELECT SUBSTRING(venda.data_venda,1,4 )) AS Ano, " + "ROUND (SUM(venda.total_preco), 2) AS SOMA, filial " + "FROM venda " + "INNER JOIN funcionario " + "ON funcionario.id_funcionario = venda.id_funcionario " + "GROUP BY funcionario.filial, (SELECT SUBSTRING(venda.data_venda,1,4))" + "ORDER BY (SELECT SUBSTRING(venda.data_venda,1,4)) " + "DESC LIMIT 100";
    preparedStatement = connection.prepareStatement(slq);
    // Executa e recebe resultado.
    resultSet = preparedStatement.executeQuery();
    // Loop com resultados.
    while (resultSet.next()) {
        // Declara objeto.
        RelatorioValores relatorio = new RelatorioValores();
        // Prenche.
        relatorio.setValor(resultSet.getFloat("SOMA"));
        relatorio.setData(resultSet.getString("Ano"));
        relatorio.setFilial(resultSet.getString("filial"));
        // Adiciona a lista.
        listaResultado.add(relatorio);
    }
    // Fecha conexao.
    connection.close();
    // Retorna lista.
    return listaResultado;
}
Also used : RelatorioValores(br.senac.tads3.pi03b.gruposete.models.RelatorioValores) ArrayList(java.util.ArrayList)

Example 3 with Venda

use of br.senac.tads3.pi03b.gruposete.models.Venda in project Loja_Agencia_De_Viagens by ArtCouSan.

the class VendaDAO method procurarVendas.

public ArrayList<Venda> procurarVendas(String inicio, String fim) throws SQLException, ClassNotFoundException {
    // Conecta.
    connection = DbUtil.getConnection();
    // Lista que ira receber vendas.
    ArrayList<Venda> listaResultado = new ArrayList<>();
    // Comando SQL.
    String slq = "SELECT * FROM venda WHERE data_venda BETWEEN ? AND ? AND ATIVO = ?";
    preparedStatement = connection.prepareStatement(slq);
    // Insercoes.
    preparedStatement.setString(1, inicio);
    preparedStatement.setString(2, fim);
    preparedStatement.setBoolean(3, true);
    // Executa e recebe resultado.
    resultSet = preparedStatement.executeQuery();
    // Loop com resultados.
    while (resultSet.next()) {
        // Declara objeto.
        Venda venda = new Venda();
        // Prenche.
        venda.setId_venda(resultSet.getInt("id_venda"));
        venda.setId_cliente(resultSet.getInt("id_cliente"));
        venda.setId_func(resultSet.getInt("id_funcionario"));
        venda.setPreco(resultSet.getFloat("total_preco"));
        venda.setData(resultSet.getString("data_venda"));
        // Adiciona a lista.
        listaResultado.add(venda);
    }
    // Fecha conexao.
    connection.close();
    // Retorna lista.
    return listaResultado;
}
Also used : Venda(br.senac.tads3.pi03b.gruposete.models.Venda) ArrayList(java.util.ArrayList)

Example 4 with Venda

use of br.senac.tads3.pi03b.gruposete.models.Venda in project Loja_Agencia_De_Viagens by ArtCouSan.

the class VendaDAO method procurarVenda.

public Venda procurarVenda(int id) throws SQLException, ClassNotFoundException {
    // Conecta.
    connection = DbUtil.getConnection();
    Venda venda = new Venda();
    // Comando SQL.
    String slq = "SELECT * FROM venda WHERE id_venda = ?";
    PreparedStatement stmt = connection.prepareStatement(slq);
    // Insercoes.
    stmt.setInt(1, id);
    // Executa e recebe resultado.
    ResultSet result = stmt.executeQuery();
    // Loop com resultados.
    while (result.next()) {
        // Prenche.
        venda.setId_venda(result.getInt("id_venda"));
        venda.setId_cliente(result.getInt("id_cliente"));
        venda.setPreco(result.getFloat("total"));
        // venda.setTotal_quantidade(result.getInt("total_quantidade"));
        // Fecha conexao.
        connection.close();
        return venda;
    }
    // Fecha conexao.
    connection.close();
    return null;
}
Also used : Venda(br.senac.tads3.pi03b.gruposete.models.Venda)

Example 5 with Venda

use of br.senac.tads3.pi03b.gruposete.models.Venda in project Loja_Agencia_De_Viagens by ArtCouSan.

the class RelatorioDAO method procurarRelatorioMes.

public ArrayList<RelatorioValores> procurarRelatorioMes() throws SQLException, ClassNotFoundException {
    // Conecta.
    connection = DbUtil.getConnection();
    // Lista que ira receber vendas.
    ArrayList<RelatorioValores> listaResultado = new ArrayList<>();
    // Comando SQL.
    String slq = "SELECT (SELECT SUBSTRING(venda.data_venda,1,7 )) AS Mes," + "ROUND (SUM(venda.total_preco), 2) AS SOMA, filial " + "FROM venda " + "INNER JOIN funcionario " + "ON funcionario.id_funcionario = venda.id_funcionario " + "GROUP BY funcionario.filial, (SELECT SUBSTRING(venda.data_venda,1,7)) " + "ORDER BY (SELECT SUBSTRING(venda.data_venda,1,7)) " + "DESC LIMIT 100";
    preparedStatement = connection.prepareStatement(slq);
    // Executa e recebe resultado.
    resultSet = preparedStatement.executeQuery();
    // Loop com resultados.
    while (resultSet.next()) {
        // Declara objeto.
        RelatorioValores relatorio = new RelatorioValores();
        // Prenche.
        relatorio.setValor(resultSet.getFloat("SOMA"));
        relatorio.setData(resultSet.getString("Mes"));
        relatorio.setFilial(resultSet.getString("filial"));
        // Adiciona a lista.
        listaResultado.add(relatorio);
    }
    // Fecha conexao.
    connection.close();
    // Retorna lista.
    return listaResultado;
}
Also used : RelatorioValores(br.senac.tads3.pi03b.gruposete.models.RelatorioValores) ArrayList(java.util.ArrayList)

Aggregations

Venda (br.senac.tads3.pi03b.gruposete.models.Venda)6 ArrayList (java.util.ArrayList)5 ClienteDAO (br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)2 VendaDAO (br.senac.tads3.pi03b.gruposete.dao.VendaDAO)2 Cliente (br.senac.tads3.pi03b.gruposete.models.Cliente)2 RelatorioValores (br.senac.tads3.pi03b.gruposete.models.RelatorioValores)2 SQLException (java.sql.SQLException)2 FuncionarioDAO (br.senac.tads3.pi03b.gruposete.dao.FuncionarioDAO)1 HotelDAO (br.senac.tads3.pi03b.gruposete.dao.HotelDAO)1 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)1 VooDAO (br.senac.tads3.pi03b.gruposete.dao.VooDAO)1 Funcionario (br.senac.tads3.pi03b.gruposete.models.Funcionario)1 Hotel (br.senac.tads3.pi03b.gruposete.models.Hotel)1 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)1 Voo (br.senac.tads3.pi03b.gruposete.models.Voo)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ParseException (java.text.ParseException)1 ServletException (javax.servlet.ServletException)1