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");
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations