public ActionResult TotalGastoERecebido() { try { int id = Convert.ToInt32(Session["user"].ToString()); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SELECT SUM(gastos.valor) AS 'totalGasto', pessoas.Id, cartoes.id_pessoas FROM gastos inner join pessoas on pessoas.Id = @ID inner join cartoes on cartoes.id_pessoas = pessoas.Id group by pessoas.id, cartoes.id_pessoas"; comando.Parameters.AddWithValue("@ID", id); DataTable tabelaGasto = new DataTable(); tabelaGasto.Load(comando.ExecuteReader()); comando.CommandText = @"SELECT SUM(recebimentos.valor) AS 'totalRecebido', pessoas.nome FROM recebimentos INNER JOIN pessoas ON recebimentos.id_pessoas = pessoas.Id WHERE pessoas.Id = @ID GROUP BY pessoas.nome"; DataTable tabelaRecebido = new DataTable(); tabelaRecebido.Load(comando.ExecuteReader()); double valorRecebido = 0, valorGasto = 0, porcentagemGasto = 0, porcentagemCarteira = 0; if (tabelaRecebido.Rows.Count == 1) { valorRecebido = Convert.ToDouble(tabelaRecebido.Rows[0]["totalRecebido"].ToString()); valorGasto = Convert.ToDouble(tabelaGasto.Rows[0]["totalGasto"].ToString()); } if (tabelaGasto.Rows.Count == 1) { porcentagemGasto = (valorRecebido - (valorRecebido - valorGasto)) * 100 / valorRecebido; porcentagemCarteira = (valorRecebido - valorGasto) / valorRecebido * 100; } return(Content(JsonConvert.SerializeObject(new { gastos = new { valor = valorGasto, percentual = porcentagemGasto }, recebidos = new { valor = valorRecebido, percentual = porcentagemCarteira } }))); } catch (Exception) { throw; } }
public Pessoas ObterPeloIdPessoas(int id) { Pessoas pessoas = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT nome, sexo, cpf, nascimento, telefone, cep FROM pessoas WHERE id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { pessoas = new Pessoas(); pessoas.Id = id; pessoas.Nome = tabela.Rows[0]["nome"].ToString(); pessoas.Sexo = Convert.ToChar(tabela.Rows[0]["sexo"].ToString()); pessoas.CPF = tabela.Rows[0]["cpf"].ToString(); pessoas.Nascimento = Convert.ToDateTime(tabela.Rows[0]["nascimento"].ToString()); pessoas.Telefone = tabela.Rows[0]["telefone"].ToString(); pessoas.Cep = tabela.Rows[0]["cep"].ToString(); } return(pessoas); }
public List <Pessoas> ObterTodosPessoas() { List <Pessoas> pessoas = new List <Pessoas>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id, nome, sexo, cpf, nascimento, telefone, cep FROM pessoas"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Pessoas pessoa = new Pessoas() { Id = Convert.ToInt32(linha["id"].ToString()), Nome = linha["nome"].ToString(), Sexo = Convert.ToChar(linha["sexo"].ToString()), CPF = linha["cpf"].ToString(), Nascimento = Convert.ToDateTime(linha["nascimento"].ToString()), Telefone = linha["telefone"].ToString(), Cep = linha["cep"].ToString() }; pessoas.Add(pessoa); } return(pessoas); }
public List <Object> FullcalendarRecebimento(int id) { List <Object> recebimentos = new List <object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SET LANGUAGE português SELECT rec.id AS 'idRecebimento', rec.valor AS 'valor', rec.data AS 'data', rec.id_categoria, rec.id_pessoas, cat.nome AS 'categoria', pes.Id FROM recebimentos rec INNER JOIN categorias cat ON cat.Id = rec.id_categoria INNER JOIN pessoas pes ON pes.Id = rec.id_pessoas WHERE pes.Id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { recebimentos.Add(new { id = Convert.ToInt32(linha["idRecebimento"].ToString()), title = linha["categoria"].ToString(), start = Convert.ToDateTime(linha["data"].ToString()), description = "recebimento", color = "#00FF00" }); } return(recebimentos); }
public List <Object> GraficoGastosMensais(int id) { List <Object> resultado = new List <Object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SET LANGUAGE português SELECT SUM(gt.valor) AS 'VALOR', DATENAME(MONTH, gt.entrada) AS 'MES', YEAR(gt.entrada) as 'ano' FROM gastos gt INNER JOIN pessoas pes ON pes.Id = @ID GROUP BY DATENAME(MONTH, gt.entrada),MONTH(gt.entrada), YEAR(gt.entrada) ORDER BY MONTH(gt.entrada)"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { resultado.Add(new { labels = linha["ano"].ToString(), datasets = new { label = linha["MES"].ToString(), data = Convert.ToDouble(linha["VALOR"].ToString()) } }); } return(resultado); }
public Cartoes GetIdpessoasCartao(int id) { Cartoes cartoes = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id, numero, conta, bandeira, banco FROM cartoes WHERE id_pessoas = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { cartoes = new Cartoes(); cartoes.IdPessoas = id; cartoes.Id = Convert.ToInt32(tabela.Rows[0]["id"].ToString()); cartoes.Numero = tabela.Rows[0]["numero"].ToString(); cartoes.Conta = tabela.Rows[0]["conta"].ToString(); cartoes.Bandeira = tabela.Rows[0]["bandeira"].ToString(); cartoes.Banco = tabela.Rows[0]["banco"].ToString(); } return(cartoes); }
public List <Gastos> ObterTodosGastos() { List <Gastos> gastos = new List <Gastos>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id, id_cartao, id_categoria, valor, entrada, vencimento, descricao FROM gastos"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Gastos gasto = new Gastos() { Id = Convert.ToInt32(linha["id"].ToString()), IdCartao = Convert.ToInt32(linha["id_cartao"].ToString()), IdCategoria = Convert.ToInt32(linha["id_categoria"].ToString()), Valor = Convert.ToDouble(linha["valor"].ToString()), Entrada = Convert.ToDateTime(linha["entrada"].ToString()), Vencimento = Convert.ToDateTime(linha["vencimento"].ToString()), Descricao = linha["descricao"].ToString() }; gastos.Add(gasto); } return(gastos); }
public List <Object> FullCalendarGastos(int id) { List <Object> gastos = new List <object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SET LANGUAGE português SELECT gastos.Id,pessoas.nome, cartoes.conta AS 'conta',categorias.nome AS 'categoria', valor, entrada, vencimento, descricao FROM gastos INNER JOIN categorias ON categorias.Id = gastos.id_categoria INNER JOIN cartoes ON cartoes.Id = gastos.id_cartao INNER JOIN pessoas ON pessoas.Id = cartoes.id_pessoas WHERE pessoas.Id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { gastos.Add(new { id = Convert.ToInt32(linha["id"].ToString()), title = linha["descricao"].ToString(), start = Convert.ToDateTime(linha["entrada"].ToString()), end = Convert.ToDateTime(linha["vencimento"].ToString()), description = "gastos", color = "#FFA500" }); } return(gastos); }
public List <Recebimento> GraficoRecebimentoMensal(int id) { List <Recebimento> recebimentos = new List <Recebimento>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT valor, data FROM recebimentos WHERE id_pessoas = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Recebimento recebimento = new Recebimento() { Id = Convert.ToInt32(linha[0].ToString()), IdPessoas = Convert.ToInt32(linha[1].ToString()), Valor = Convert.ToDouble(linha[1].ToString()), Data = Convert.ToDateTime(linha[2].ToString()), }; recebimentos.Add(recebimento); } return(recebimentos); }
//grafico recebimento public List <Object> RecebimentoPessoaJsonFormat(int id) { List <Object> resultado = new List <Object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SET LANGUAGE português SELECT SUM(recebimentos.valor) AS 'VALOR', DATENAME(MONTH, recebimentos.data) AS 'MES', YEAR(recebimentos.data) as 'ano' FROM recebimentos INNER JOIN pessoas ON pessoas.Id = recebimentos.id_pessoas WHERE pessoas.Id = @ID GROUP BY DATENAME(MONTH, recebimentos.data), MONTH(recebimentos.data), YEAR(recebimentos.data) ORDER BY MONTH(recebimentos.data)"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { resultado.Add(new { labels = linha["ano"].ToString(), datasets = new { label = linha["MES"].ToString(), data = Convert.ToDouble(linha["VALOR"].ToString()) } }); } return(resultado); }
public ActionResult SetorMaiorGasto() { int id = Convert.ToInt32(Session["user"].ToString()); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"select max(gastos.valor) as 'total', categorias.nome as 'categoria', cartoes.id_pessoas from gastos inner join categorias on categorias.Id = gastos.id_categoria inner join cartoes on cartoes.id_pessoas = @ID group by categorias.nome, cartoes.id_pessoas"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); return(Content(JsonConvert.SerializeObject(new { tabela }))); }
public ActionResult TotalRecebidoCategoria() { int id = Convert.ToInt32(Session["user"].ToString()); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"select sum(recebimentos.valor) AS 'valor', categorias.nome AS 'categoria', pessoas.nome from recebimentos INNER JOIN categorias ON categorias.Id = recebimentos.id_categoria INNER JOIN pessoas ON recebimentos.id_pessoas = pessoas.Id WHERE pessoas.Id = @ID GROUP BY categorias.nome, pessoas.nome"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); return(Content(JsonConvert.SerializeObject(new { tabela }))); }
public ActionResult GastosCategoria() { int id = Convert.ToInt32(Session["user"].ToString()); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SELECT categorias.nome AS 'categoria', SUM(gastos.valor) AS 'valor', cartoes.id_pessoas FROM categorias INNER JOIN gastos ON gastos.id_categoria = categorias.Id INNER JOIN cartoes ON cartoes.Id = gastos.id_cartao WHERE MONTH(gastos.entrada) = MONTH(GETDATE()) AND cartoes.id_pessoas = @ID GROUP BY categorias.nome, cartoes.id_pessoas"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); return(Content(JsonConvert.SerializeObject(new { tabela }))); }
public List <Gastos> ObterTodosParaJson(string start, string length, string search, string orderColumn, string orderDir, int id) { List <Gastos> gastos = new List <Gastos>(); //" + orderDir + " OFFSET " + start + " ROWS FETCH NEXT " + length + " ROWS ONLY " SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SELECT gas.Id, pes.nome AS 'pessoa', car.conta, cat.nome AS 'categoria', gas.valor, gas.entrada, gas.vencimento, gas.descricao, gas.id_categoria FROM gastos gas INNER JOIN categorias cat ON cat.Id = gas.id_categoria INNER JOIN cartoes car ON car.Id = gas.id_cartao INNER JOIN pessoas pes ON pes.Id = car.id_pessoas WHERE pes.Id = @ID AND ((car.conta LIKE @SEARCH) OR (cat.nome LIKE @SEARCH) OR (gas.valor LIKE @SEARCH)) ORDER BY " + orderColumn + ""; comando.Parameters.AddWithValue("@SEARCH", search); comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow line in tabela.Rows) { Gastos gasto = new Gastos() { Id = Convert.ToInt32(line["Id"].ToString()), IdCategoria = Convert.ToInt32(line["id_categoria"].ToString()), Descricao = line["descricao"].ToString(), Entrada = Convert.ToDateTime(line["entrada"].ToString()), Vencimento = Convert.ToDateTime(line["vencimento"].ToString()), Valor = Convert.ToDouble(line["valor"].ToString()), cartao = new Cartoes() { Id = Convert.ToInt32(line["id_categoria"].ToString()), Conta = line["conta"].ToString() }, Categoria = new Categoria() { Id = Convert.ToInt32(line["id_categoria"].ToString()), Nome = line["categoria"].ToString(), } }; gastos.Add(gasto); } return(gastos); }
public List <Object> ObterTodosCategoriaParaSelect2() { List <Object> registros = new List <object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id AS 'id', nome AS 'nome' FROM categorias"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { registros.Add(new { id = Convert.ToInt32(linha["id"].ToString()), text = linha["nome"].ToString() }); } return(registros); }
public Categoria ObterPeloIdCategoria(int id) { Categoria categoria = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT nome FROM categorias WHERE id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { categoria = new Categoria(); categoria.Id = id; categoria.Nome = tabela.Rows[0]["nome"].ToString(); } return(categoria); }
public List <Object> ObterTodosCartoesParaSelect2(int id) { List <Object> registros = new List <object>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id, conta FROM cartoes WHERE id_pessoas = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { registros.Add(new { id = Convert.ToInt32(linha["id"].ToString()), text = linha["conta"].ToString(), }); } return(registros); }
public List <Categoria> ObterTodosCategoria() { List <Categoria> categorias = new List <Categoria>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id AS 'id', nome AS 'nome' FROM categorias"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Categoria categoria = new Categoria() { Id = Convert.ToInt32(linha["id"].ToString()), Nome = linha["nome"].ToString() }; categorias.Add(categoria); } return(categorias); }
public Login ObterPeloIdLogin(int id) { Login login = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT usuario, senha,id_pessoas, email FROM login WHERE id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { login = new Login(); login.Id = id; login.IdPessoas = Convert.ToInt32(tabela.Rows[0]["id_pessoas"].ToString()); login.Usuario = tabela.Rows[0]["usuario"].ToString(); login.Senha = tabela.Rows[0]["senha"].ToString(); login.Email = tabela.Rows[0]["email"].ToString(); } return(login); }
public Recebimento ObterPeloIdRecebimento(int id) { Recebimento recebimento = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT valor, data FROM recebimentos WHERE id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { recebimento = new Recebimento(); recebimento.Id = id; recebimento.Valor = Convert.ToDouble(tabela.Rows[0][0].ToString()); recebimento.Data = Convert.ToDateTime(tabela.Rows[0][1].ToString()); } return(recebimento); }
public Gastos ObterPeloIdGastos(int id) { Gastos gastos = null; SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = @"SELECT gt.id_cartao, gt.id_categoria, gt.valor, gt.entrada, gt.vencimento, gt.descricao, gt.entrada, gt.vencimento, cat.nome, car.conta FROM gastos gt INNER JOIN categorias cat ON(cat.id = gt.id_categoria) INNER JOIN cartoes car ON(car.Id = gt.id_cartao) WHERE gt.id = @ID"; comando.Parameters.AddWithValue("@ID", id); DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); if (tabela.Rows.Count == 1) { gastos = new Gastos(); gastos.Id = id; gastos.IdCategoria = Convert.ToInt32(tabela.Rows[0]["id_categoria"].ToString()); gastos.cartao = new Cartoes() { Id = Convert.ToInt32(tabela.Rows[0]["id_cartao"].ToString()), Conta = tabela.Rows[0]["conta"].ToString() }; gastos.IdCartao = Convert.ToInt32(tabela.Rows[0]["id_cartao"].ToString()); gastos.Valor = Convert.ToDouble(tabela.Rows[0]["valor"].ToString()); gastos.Entrada = Convert.ToDateTime(tabela.Rows[0]["entrada"].ToString()); gastos.Vencimento = Convert.ToDateTime(tabela.Rows[0]["vencimento"].ToString()); gastos.Descricao = tabela.Rows[0]["descricao"].ToString(); gastos.Categoria = new Categoria() { Id = Convert.ToInt32(tabela.Rows[0]["id_categoria"].ToString()), Nome = tabela.Rows[0]["nome"].ToString() }; } return(gastos); }
public List <Cartoes> ObterTodosCartoes() { List <Cartoes> cartoes = new List <Cartoes>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id , id_pessoas, numero, conta, bandeira, banco FROM cartoes"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Cartoes cartao = new Cartoes() { Id = Convert.ToInt32(linha["id"].ToString()), IdPessoas = Convert.ToInt32(linha["id_pessoas"].ToString()), Numero = linha["numero"].ToString(), Conta = linha["conta"].ToString(), Bandeira = linha["bandeira"].ToString(), Banco = linha["banco"].ToString() }; cartoes.Add(cartao); } return(cartoes); }
public List <Recebimento> ObterTodosRecebimento() { List <Recebimento> recebimentos = new List <Recebimento>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT id, valor, data FROM recebimentos"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Recebimento recebimento = new Recebimento() { Id = Convert.ToInt32(linha[0].ToString()), // Id_recebimento = Convert.ToInt32(linha[1].ToString()), Valor = Convert.ToDouble(linha[1].ToString()), Data = Convert.ToDateTime(linha[2].ToString()), }; recebimentos.Add(recebimento); } return(recebimentos); }
public List <Login> ObterTodosLogin() { List <Login> logins = new List <Login>(); SqlCommand comando = new DBconnection().GetConnction(); comando.CommandText = "SELECT login.id, login.id_pessoas, login.usuario, login.senha, login.email FROM [login]"; DataTable tabela = new DataTable(); tabela.Load(comando.ExecuteReader()); foreach (DataRow linha in tabela.Rows) { Login login = new Login() { Id = Convert.ToInt32(linha["id"].ToString()), IdPessoas = Convert.ToInt32(linha["id_pessoas"].ToString()), Usuario = linha["usuario"].ToString(), Senha = linha["senha"].ToString(), Email = linha["email"].ToString() }; logins.Add(login); } return(logins); }