protected void btnFecharComandaAsp_Click(object sender, EventArgs e) { float valorPago; if (float.TryParse(txtPago.Text, out valorPago)) { int comandaID = Convert.ToInt32(Request.QueryString["id"]); float valorTotal = Dal.ServicoComanda.selectByIdComanda(comandaID).Sum(s => s.valorServico) + Dal.ProdutoComandaDAL.selectByComandaID(comandaID).Sum(s => s.valorProduto * s.quantidade); float descontoTotal = Dal.ServicoComanda.selectByIdComanda(comandaID).Sum(s => s.desconto) + Dal.ProdutoComandaDAL.selectByComandaID(comandaID).Sum(s => s.desconto); Model.Comanda comanda = Dal.ComandaDAL.selectByID(comandaID); Model.Caixa caixa = Dal.CaixaDal.select().First(c => c.aberto); Model.ComandaCaixa comandaCaixa = new Model.ComandaCaixa(); comandaCaixa.caixaID = caixa.id; comandaCaixa.valorPago = valorPago; comandaCaixa.comandaID = comandaID; Dal.ComandaCaixa.insert(comandaCaixa); comanda.valorTotal = valorTotal; comanda.descontoTotal = descontoTotal; comanda.aberta = false; Dal.ComandaDAL.update(comanda); float credito = valorTotal - descontoTotal - valorPago; if (credito != 0) { Model.Cliente cliente = Dal.ClienteDAL.selectById(comanda.clienteID); cliente.credito -= credito; Dal.ClienteDAL.uptade(cliente); } Response.Redirect("viewComanda.aspx?ad=true"); } else { ClientScript.RegisterStartupScript(this.GetType(), "Erro", "alert('É necessário colocar um valor válido');", true); } }
public List <Model.Caixa> Select() { List <Model.Caixa> lstCaixa = new List <Model.Caixa>(); SqlConnection conexao = new SqlConnection(strcon); string sql = "select * from caixa;"; SqlCommand cmd = new SqlCommand(sql, conexao); conexao.Open(); try { SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { Model.Caixa caixa = new Model.Caixa(); caixa.id = Convert.ToInt32(reader["id"]); caixa.cliente = reader["cliente"].ToString(); caixa.data = Convert.ToDateTime(reader["data"]); caixa.total = reader["total"].ToString(); caixa.pagamento = reader["pagamento"].ToString(); lstCaixa.Add(caixa); } } catch { Console.WriteLine("Erro - Caixas nao localizados"); } finally { conexao.Close(); } return(lstCaixa); }
public void Insert(Model.Caixa caixa) { SqlConnection conexao = new SqlConnection(strcon); string sql = "Insert into caixa values "; sql = sql + " (@cliente, @data, @total, @pagamento);"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@cliente", caixa.cliente); cmd.Parameters.AddWithValue("@data", caixa.data); cmd.Parameters.AddWithValue("@total", caixa.total); cmd.Parameters.AddWithValue("@pagamento", caixa.pagamento); conexao.Open(); try { cmd.ExecuteNonQuery(); } catch { Console.WriteLine("Deu Erro ao cadastrar o caixa"); } finally { conexao.Close(); } }
protected void btnAbrirCaixa_Click(object sender, EventArgs e) { Model.Caixa caixa = new Model.Caixa(); caixa.aberto = true; caixa.dataAbertura = DateTime.Today; caixa.dataFechamento = DateTime.Today; Dal.CaixaDal.insert(caixa); verificarCaixa(); }
private void LoadData() { _modelCaixa = _modelCaixa.FindById(idCaixa).FirstOrDefault <Model.Caixa>(); //var Dinheiro = Validation.ConvertToDouble(_controllerCaixa.SumEntradasDinheiro(_modelCaixa.Id) + _modelCaixa.Saldo_Inicial - _controllerCaixa.SumSaidas(_modelCaixa.Id)); //txtSaldoDinheiro.Text = Validation.FormatPrice(Dinheiro, true); txtSaldoDinheiro.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 1) + ((_modelCaixa.Saldo_Inicial + _controllerCaixa.SumEntradas(idCaixa)) - _controllerCaixa.SumSaidas(idCaixa)), true); //txtSaldoTotal.Text = Validation.FormatPrice(_controllerCaixa.SumSaldoFinal(idCaixa), true); txtSaldoTotal.Text = Validation.FormatPrice(_controllerCaixa.SumVendasTotal(idCaixa) + ((_modelCaixa.Saldo_Inicial + _controllerCaixa.SumEntradas(idCaixa)) - _controllerCaixa.SumSaidas(idCaixa)), true); }
public void update(Model.Caixa caixa) { string sql = "UPDATE caixa SET dataFechamento=@dataFechamento, aberto=@aberto where id=@id"; Conexao conexao = new Bll.Conexao(); SqlCommand command = new SqlCommand(sql, conexao.getConexao()); command.Parameters.AddWithValue("dataFechamento", caixa.dataFechamento); command.Parameters.AddWithValue("aberto", Convert.ToInt32(caixa.aberto)); command.Parameters.AddWithValue("id", caixa.id); command.ExecuteNonQuery(); conexao.Dispose(); }
public void insert(Model.Caixa caixa) { string sql = "INSERT INTO Caixa VALUES(@dataAbertura, @dataFechamento, @aberto)"; Conexao conexao = new Conexao(); SqlCommand command = new SqlCommand(sql, conexao.getConexao()); command.Parameters.AddWithValue("dataAbertura", caixa.dataAbertura); command.Parameters.AddWithValue("dataFechamento", caixa.dataFechamento); command.Parameters.AddWithValue("aberto", Convert.ToInt32(caixa.aberto)); command.ExecuteNonQuery(); conexao.Dispose(); }
private static void CheckCaixa() { // Verifica se o caixa do usuário está aberto if (Home.idCaixa == 0) { var caixa = new Model.Caixa().Query().Where("tipo", "Aberto").Where("usuario", Settings.Default.user_id) .WhereFalse("excluir").FirstOrDefault(); if (caixa != null) { Home.idCaixa = caixa.ID; } } }
public void CheckCaixaDate() { CheckCaixa(); var caixa = new Model.Caixa().Query().Where("tipo", "Aberto").Where("usuario", Settings.Default.user_id) .Where("criado", "<", Validation.ConvertDateToSql(DateTime.Now)).WhereFalse("excluir").FirstOrDefault(); if (caixa != null) { Home.idCaixa = caixa.ID; var msg = $"Antes de começar, há um caixa aberto do dia: {Validation.ConvertDateToForm(caixa.CRIADO)}. {Environment.NewLine}Deseja realizar o FECHAMENTO agora?"; var Title = "Atenção!"; var result = AlertOptions.Message(Title, msg, AlertBig.AlertType.warning, AlertBig.AlertBtn.YesNo); if (result) { DetailsCaixa.idCaixa = Home.idCaixa; using (var f = new DetailsCaixa()) { f.ShowDialog(); } } else { AlertOptions.Message("Atenção!", "Os recebimentos gerados a partir de vendas serão lançados no caixa aberto!", AlertBig.AlertType.info, AlertBig.AlertBtn.OK); } } var caixaAberto = new Model.Caixa().Query().Where("tipo", "Aberto") .Where("usuario", Settings.Default.user_id).WhereFalse("excluir").FirstOrDefault(); if (caixaAberto == null) { var result = AlertOptions.Message("Atenção!", $"Você não possui um Caixa aberto.{Environment.NewLine} Deseja abrir agora?", AlertBig.AlertType.info, AlertBig.AlertBtn.YesNo); if (result) { using (var f = new AbrirCaixa()) { f.ShowDialog(); } } } }
protected void btnFecharCaixa_Click(object sender, EventArgs e) { if (Dal.ComandaDAL.select().Count(c => c.aberta) == 0) { Model.Caixa caixa = Dal.CaixaDal.select().First(c => c.aberto); caixa.aberto = false; caixa.dataFechamento = DateTime.Today; Dal.CaixaDal.update(caixa); verificarCaixa(); } else { ClientScript.RegisterStartupScript(this.GetType(), "Erro", "alert('É necessário fechar as comandas para fechar o caixa');", true); } }
private void LoadData() { _modelCaixa = _modelCaixa.FindById(idCaixa).FirstOrDefault <Model.Caixa>(); caixa.Text = _modelCaixa.Id.ToString(Program.cultura); nrCaixa.Text = _modelCaixa.Id.ToString(Program.cultura); terminal.Text = _modelCaixa.Terminal; aberto.Text = Validation.ConvertDateToForm(_modelCaixa.Criado, true); label7.Text = _modelCaixa.Tipo == "Aberto" ? "Caixa Aberto" : "Caixa Fechado"; if (_modelCaixa.Tipo == "Fechado") { panel7.BackColor = Color.FromArgb(192, 0, 0); txtFechado.Text = Validation.ConvertDateToForm(_modelCaixa.Fechado, true); FecharCaixa.Visible = false; btnLancamentos.Visible = false; btnEditar.Visible = false; } LoadUsuario(_modelCaixa.Usuario); txtSaldoInicial.Text = Validation.FormatPrice(_modelCaixa.Saldo_Inicial, true); txtEntradas.Text = Validation.FormatPrice(_controllerCaixa.SumEntradas(idCaixa), true); txtSaidas.Text = Validation.FormatPrice(_controllerCaixa.SumSaidas(idCaixa), true); //txtSaldoFinal.Text = Validation.FormatPrice(_controllerCaixa.SumSaldoFinal(idCaixa), true); txtSaldoFinal.Text = Validation.FormatPrice(_controllerCaixa.SumVendasTotal(idCaixa) + ((_modelCaixa.Saldo_Inicial + _controllerCaixa.SumEntradas(idCaixa)) - _controllerCaixa.SumSaidas(idCaixa)), true); txtVendasTotal.Text = Validation.FormatPrice(_controllerCaixa.SumVendasTotal(idCaixa), true); txtVendasAcrescimos.Text = Validation.FormatPrice(_controllerCaixa.SumVendasAcrescimos(idCaixa), true); txtVendasDescontos.Text = Validation.FormatPrice(_controllerCaixa.SumVendasDescontos(idCaixa), true); txtVendasGeradas.Text = _controllerCaixa.SumVendasGeradas(idCaixa).ToString(); txtVendasMedia.Text = Validation.FormatPrice(_controllerCaixa.SumVendasMedia(idCaixa), true); txtVendasCanceladasTotal.Text = Validation.FormatPrice(_controllerCaixa.SumVendasCanceladasTotal(idCaixa), true); txtVendasCanceladas.Text = _controllerCaixa.SumVendasCanceladasGeradas(idCaixa).ToString(); txtTotalRecebimento.Text = Validation.FormatPrice(_controllerCaixa.SumPagamentoTodos(idCaixa), true); txtDinheiro.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 1), true); txtCheque.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 2), true); txtCarDeb.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 3), true); txtCarCred.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 4), true); txtCrediario.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 5), true); txtBoleto.Text = Validation.FormatPrice(_controllerCaixa.SumPagamento(idCaixa, 6), true); }
public Model.Caixa selectById(int idCaixa) { string sql = "SELECT * FROM Caixa where id=@id"; Conexao conexao = new Bll.Conexao(); SqlCommand command = new SqlCommand(sql, conexao.getConexao()); command.Parameters.AddWithValue("id", idCaixa); SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); reader.Read(); Model.Caixa caixa = new Model.Caixa(); caixa.id = Convert.ToInt32(reader["id"]); caixa.dataAbertura = Convert.ToDateTime(reader["dataAbertura"]); caixa.dataFechamento = Convert.ToDateTime(reader["dataFechamento"]); caixa.aberto = Convert.ToBoolean(reader["aberto"]); conexao.Dispose(); return(caixa); }
public List <Model.Caixa> select() { List <Model.Caixa> lstCaixa = new List <Model.Caixa>(); string sql = "SELECT * FROM Caixa"; Conexao conexao = new Bll.Conexao(); SqlCommand command = new SqlCommand(sql, conexao.getConexao()); SqlDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.CloseConnection); while (reader.Read()) { Model.Caixa caixa = new Model.Caixa(); caixa.id = Convert.ToInt32(reader["id"]); caixa.dataAbertura = Convert.ToDateTime(reader["dataAbertura"]); caixa.dataFechamento = Convert.ToDateTime(reader["dataFechamento"]); caixa.aberto = Convert.ToBoolean(reader["aberto"]); lstCaixa.Add(caixa); } conexao.Dispose(); return(lstCaixa); }
private void Eventos() { KeyDown += KeyDowns; KeyPreview = true; Masks.SetToUpper(this); Load += (s, e) => { Start(); }; Tipo1.Click += (s, e) => { Categorias.Enabled = true; Fornecedor.Enabled = true; imprimir.Visible = false; label4.Text = @"Despesa:"; LoadCategorias("Despesas"); }; Tipo2.Click += (s, e) => { Categorias.Enabled = true; Fornecedor.Enabled = false; imprimir.Visible = true; label4.Text = @"Despesa:"; LoadCategorias("Despesas"); }; Tipo3.Click += (s, e) => { Categorias.Enabled = false; Fornecedor.Enabled = false; imprimir.Visible = false; label4.Text = @"Receita:"; LoadCategorias("Receitas"); }; btnAddCategoria.Click += (s, e) => { string categoriasdeContas; if (Tipo1.Checked || Tipo2.Checked) { categoriasdeContas = "Despesas"; } else { categoriasdeContas = "Receitas"; } Home.CategoriaPage = categoriasdeContas; var f = new AddCategorias { FormBorderStyle = FormBorderStyle.FixedSingle, StartPosition = FormStartPosition.CenterScreen }; if (f.ShowDialog() == DialogResult.OK) { LoadCategorias(categoriasdeContas); } }; btnAddFornecedor.Click += (s, e) => { Home.pessoaPage = "Fornecedores"; AddClientes.Id = 0; var f = new AddClientes { FormBorderStyle = FormBorderStyle.FixedSingle, StartPosition = FormStartPosition.CenterScreen }; if (f.ShowDialog() == DialogResult.OK) { LoadFornecedores(); } }; btnSalvar.Click += (s, e) => { _modelCaixaMov.id_caixa = idCaixa; _modelCaixaMov.id_formapgto = Dinheiro.Checked ? 1 : Cheque.Checked ? 2 : 1; _modelCaixaMov.id_categoria = Validation.ConvertToInt32(Categorias.SelectedValue); _modelCaixaMov.id_pessoa = Validation.ConvertToInt32(Fornecedor.SelectedValue); _modelCaixaMov.Tipo = Tipo1.Checked ? 1 : Tipo2.Checked ? 2 : Tipo3.Checked ? 3 : 1; var tipo = ""; if (Tipo1.Checked) { tipo = "Saída - Lançamento de Despesa"; } else if (Tipo2.Checked) { tipo = "Saída - Sangria"; } else if (Tipo3.Checked) { tipo = "Entrada - Acréscimo"; } var formaPgto = ""; if (Dinheiro.Checked) { formaPgto = "Dinheiro"; } else if (Cheque.Checked) { formaPgto = "Cheque"; } _modelCaixaMov.Descricao = $"{formaPgto} - {tipo}"; _modelCaixaMov.Valor = Validation.ConvertToDouble(Valor.Text); _modelCaixaMov.Obs = Obs.Text; if (_modelCaixaMov.Save(_modelCaixaMov)) { if (Tipo1.Checked) { if (_modelCaixaMov.Id != 0) { _modelTitulo = _modelTitulo.Query().Where("id_caixa_mov", _modelCaixaMov.Id) .Where("excluir", 0).FirstOrDefault <Titulo>(); } _modelTitulo.Tipo = "Pagar"; _modelTitulo.Emissao = Validation.DateNowToSql(); _modelTitulo.Id_Categoria = _modelCaixaMov.id_categoria; _modelTitulo.Id_Pessoa = _modelCaixaMov.id_pessoa; _modelTitulo.Total = _modelCaixaMov.Valor; _modelTitulo.Id_FormaPgto = _modelCaixaMov.id_formapgto; _modelTitulo.Vencimento = Validation.DateNowToSql(); _modelTitulo.Baixa_data = Validation.DateNowToSql(); _modelTitulo.Baixa_id_formapgto = _modelCaixaMov.id_formapgto; _modelTitulo.Baixa_total = _modelCaixaMov.Valor; _modelTitulo.Id_Caixa = idCaixa; _modelTitulo.Id_Caixa_Mov = _modelCaixaMov.GetLastId(); _modelTitulo.Obs = $"Pagamento gerado a partir de um lançamento do caixa. {Obs.Text}"; _modelTitulo.Save(_modelTitulo, false); } DialogResult = DialogResult.OK; Close(); } }; Valor.TextChanged += (s, e) => { var txt = (TextBox)s; Masks.MaskPrice(ref txt); }; btnApagar.Click += (s, e) => { if (_modelCaixaMov.Remove(idMov)) { var titulo = _modelTitulo.Query().Where("ID_CAIXA_MOV", idMov).FirstOrDefault(); if (titulo != null) { _modelTitulo.RemoveIdCaixaMov(idMov); } DialogResult = DialogResult.OK; Close(); } }; imprimir.Click += (s, e) => { _modelCaixa = _modelCaixa.FindById(idCaixa).FirstOrDefault <Model.Caixa>(); var user = _modelUsuarios.FindByUserId(_modelCaixa.Usuario).FirstOrDefault(); var userName = ""; if (user != null) { userName = user.NOME; } var html = Template.Parse(File.ReadAllText($@"{Program.PATH_BASE}\html\CupomAssinaturaCaixaMov.html")); var render = html.Render(Hash.FromAnonymousObject(new { INCLUDE_PATH = Program.PATH_BASE, URL_BASE = Program.PATH_BASE, Emissao = DateTime.Now.ToString("dd/MM/yyyy HH:mm"), nrTerminal = _modelCaixa.Terminal, nrCaixa = _modelCaixa.Id.ToString(), Responsavel = userName, Valor = Valor.Text })); Browser.htmlRender = render; var f = new Browser(); f.ShowDialog(); }; }
public static void insert(Model.Caixa caixa) { Bll.CaixaBLL caixaBll = new Bll.CaixaBLL(); caixaBll.insert(caixa); }
public static void update(Model.Caixa caixa) { Bll.CaixaBLL caixaBll = new Bll.CaixaBLL(); caixaBll.update(caixa); }
private void Eventos() { KeyDown += KeyDowns; KeyPreview = true; Masks.SetToUpper(this); Load += (s, e) => { Caixas.SelectedValue = "1"; Caixas.Enabled = false; var caixas = new Model.Caixa().Query() .LeftJoin("USUARIOS", "USUARIOS.ID_USER", "CAIXA.USUARIO") .SelectRaw("USUARIOS.NOME, CAIXA.*") .Where("CAIXA.tipo", "Aberto") .WhereFalse("CAIXA.excluir") .OrderByDesc("CAIXA.criado") .Get(); if (caixas.Any()) { Caixas.DataSource = caixas; Caixas.DisplayMember = "NOME"; Caixas.ValueMember = "ID"; } else { OutroCaixa.Enabled = false; Caixas.Enabled = false; label3.Visible = true; } }; OutroCaixa.Click += (s, e) => { btnCriar.Text = @"Vincular Caixa"; EnableDisableCampos(false, true); }; MeuCaixa.Click += (s, e) => { btnCriar.Text = @"Abrir Caixa"; EnableDisableCampos(true, false); }; btnCriar.Click += (s, e) => { if (!MeuCaixa.Checked) { if (OutroCaixa.Checked) { Home.idCaixa = Validation.ConvertToInt32(Caixas.SelectedValue); Alert.Message("Pronto!", "Seu usuário foi vinculado ao caixa aberto.", Alert.AlertType.success); DialogResult = DialogResult.OK; Close(); return; } } _modelCaixa.Tipo = "Aberto"; _modelCaixa.Usuario = Settings.Default.user_id; _modelCaixa.Saldo_Inicial = Validation.ConvertToDouble(ValorInicial.Text); _modelCaixa.Terminal = Terminal.Text; _modelCaixa.Observacao = Obs.Text; if (_modelCaixa.Save(_modelCaixa)) { Home.idCaixa = _modelCaixa.GetLastId(); DialogResult = DialogResult.OK; Close(); } }; ValorInicial.TextChanged += (s, e) => { var txt = (TextBox)s; Masks.MaskPrice(ref txt); }; }