protected virtual Livro_Caixa LoadFromControls() { Livro_Caixa Livro_Caixa = new Livro_Caixa(); if (Id != null) { Livro_Caixa.Id = Convert.ToInt32(txtId.Text); if (!string.IsNullOrEmpty(txtSaldoFinal.Text)) { Livro_Caixa.saldo_final = Convert.ToDecimal(txtSaldoFinal.Text); } Livro_Caixa.inclusao = Convert.ToDateTime(txtDtInc.Text); Livro_Caixa.usuario_inclusao = txtUsuarioInc.Text; } txtData.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; Livro_Caixa.data = Convert.ToDateTime(txtData.Text); Livro_Caixa.Id_empresa = Program.usuario_logado.Id_empresa; if (cbFilial.SelectedValue != null) { Livro_Caixa.Id_filial = Convert.ToInt64(cbFilial.SelectedValue); } Livro_Caixa.saldo_inicial = Convert.ToDecimal(txtSaldoInicial.Text); if (this.TipoMovimento == tpMovimentoLivroCaixa.Abertura) { if (!string.IsNullOrEmpty(txtStatus.Text)) { Livro_Caixa.status = txtStatus.Text; } else { Livro_Caixa.status = "A"; } } else if (this.TipoMovimento == tpMovimentoLivroCaixa.Encerramento) { Livro_Caixa.status = "F"; } return(Livro_Caixa); }
protected override bool salvar(object sender, EventArgs e) { if (TipoMovimento == tpMovimentoLivroCaixa.Abertura) { epValidaDados.SetObrigatorio(txtSaldoFinal, false); } if (epValidaDados.Validar()) { Livro_Caixa Livro_Caixa = new Livro_Caixa(); Livro_CaixaBLL = new Livro_CaixaBLL(); Livro_CaixaBLL.UsuarioLogado = Program.usuario_logado; Livro_Caixa = LoadFromControls(); if (Id != null) { Livro_CaixaBLL.AlterarLivro_Caixa(Livro_Caixa); } else { Livro_CaixaBLL.AdicionarLivro_Caixa(Livro_Caixa); } if (Livro_Caixa.Id != 0) { Id = Livro_Caixa.Id; txtId.Text = Livro_Caixa.Id.ToString(); } return(true); } else { return(false); } }
private void processaPagamento() { decimal saldo = 0; decimal saldo_inicial = 0; decimal entradas = 0; decimal saidas = 0; try { //Vamos realizar o processo de pagamento do contas a pagar. //Primeiro vamos ver se existe saldo no caixa para o pagamento da conta a pagar if (!chkPago.Checked) { Livro_CaixaBLL Livro_CaixaBLL = new Livro_CaixaBLL(); List <Livro_Caixa> lstLc = null; if (Id_filial != null) { lstLc = Livro_CaixaBLL.getLivro_Caixa(p => p.Id_filial == Id_filial & DbFunctions.TruncateTime(p.data) == DbFunctions.TruncateTime(DateTime.Now), true); } else { lstLc = Livro_CaixaBLL.getLivro_Caixa(p => DbFunctions.TruncateTime(p.data) == DbFunctions.TruncateTime(DateTime.Now), true); } Livro_Caixa Livro_Caixa = null; if (lstLc.Count > 0) { Livro_Caixa = lstLc.First(); } else { throw new Exception("Não existe movimentação aberta para realizar o pagamento."); } if (Livro_Caixa != null) { if (Livro_Caixa.status != "F") { entradas = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "E").Sum(c => c.valor)); saidas = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "S").Sum(c => c.valor)); saldo_inicial = Convert.ToDecimal(Livro_Caixa.saldo_inicial); //saldo obtido vamos comparar verificar se é suficinete para pagar saldo = ((saldo_inicial + entradas) - (-1 * saidas)); decimal valor = Convert.ToDecimal(txtValor.Text); if (valor <= saldo) { //Vamos registrar um item no livro de caixa e atualizar o conta a pagar //com a data de pagamento e o flag de pago. Item_Livro_CaixaBLL Item_LivroBLL = new Item_Livro_CaixaBLL(); try { Item_LivroBLL.UsuarioLogado = Program.usuario_logado; Item_Livro_Caixa Item_Livro = new Item_Livro_Caixa(); Item_Livro.Id_contaspagar = Convert.ToInt64(Id); Item_Livro.Id_empresa = Program.usuario_logado.Id_empresa; if (Id_filial != null) { Item_Livro.Id_filial = Id_filial; } Item_Livro.inclusao = DateTime.Now; Item_Livro.tipo = "S"; Item_Livro.descricao = "Contas a Pagar Documento: " + txtDocumento.Text; Item_Livro.usuario_inclusao = Program.usuario_logado.nome; Item_Livro.valor = valor; Item_Livro.Id_livro = Livro_Caixa.Id; Item_LivroBLL.AdicionarItem_Livro_Caixa(Item_Livro); if (Item_Livro.Id > 0) { Contas_PagarBLL = new Contas_PagarBLL(); Contas_PagarBLL.UsuarioLogado = Program.usuario_logado; Contas_Pagar cp = Contas_PagarBLL.Localizar(Id); cp.pago = "S"; cp.pagamento = DateTime.Now; cp.usuario_alteracao = Program.usuario_logado.nome; cp.alteracao = DateTime.Now; Contas_PagarBLL.AlterarContas_Pagar(cp); LoadToControls(); chkPago.Checked = true; chkPago.Enabled = false; chkPago.Visible = true; btnPagamento.Enabled = false; btnIncluir.Top = 40; btnIncluir.Visible = true; MessageBox.Show("Processo de Pagamento realizado com sucesso.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception) { throw; } } else { throw new Exception("saldo em caixa menor que o valor para pagamento."); } } else { throw new Exception("Não será possivel realizar o pagamento pois a movimentação diária está Fechada"); } } } } catch (Exception ex) { string mensagem = TrataException.getAllMessage(ex); MessageBox.Show(mensagem, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override void carregaConsulta() { base.carregaConsulta(); Item_Livro_CaixaBLL = new Item_Livro_CaixaBLL(); Livro_CaixaBLL = new Livro_CaixaBLL(); //Vamos listar as movimentações do dia. //Não existe mais de um livro caixa por dia. if (Parametro.UtilizaFilial()) { if (Id_Filial == null) { if (Program.usuario_logado.Id_filial != null) { Id_Filial = Program.usuario_logado.Id_filial; } else { frmUtilSelecionarFilial frm = new frmUtilSelecionarFilial(); if (frm.ExibeDialogo() == DialogResult.OK) { Id_Filial = frm.Id; } frm.Dispose(); } } if (Id_Filial != null) { List <Livro_Caixa> lstLC = null; lstLC = Livro_CaixaBLL.getLivro_Caixa(p => p.Id_filial == Id_Filial & DbFunctions.TruncateTime(p.data) == DbFunctions.TruncateTime(DateTime.Now) & p.status == "A", false, deslocamento, tamanhoPagina, out totalReg, c => c.Id.ToString()); if (lstLC.Count > 0) { Livro_Caixa Livro_Caixa = lstLC.First(); Id_Livro_Caixa = Livro_Caixa.Id; dgvDados.DataSource = Item_Livro_CaixaBLL.ToList_Item_Livro_CaixaView(Livro_Caixa.item_livro_caixa); } else { desabilitaBotoes(); //throw new Exception("Não existe movimentação de livro caixa aberta no momento."); MessageBox.Show("Não existe movimentação de livro caixa aberta para filial no momento.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Close(); } } } else { List <Livro_Caixa> lstLC = null; lstLC = Livro_CaixaBLL.getLivro_Caixa(p => DbFunctions.TruncateTime(p.data) == DbFunctions.TruncateTime(DateTime.Now) & p.status == "A", false, deslocamento, tamanhoPagina, out totalReg, c => c.Id.ToString()); if (lstLC.Count > 0) { Livro_Caixa Livro_Caixa = lstLC.First(); Id_Livro_Caixa = Livro_Caixa.Id; dgvDados.DataSource = Item_Livro_CaixaBLL.ToList_Item_Livro_CaixaView(Livro_Caixa.item_livro_caixa); } else { desabilitaBotoes(); //throw new Exception("Não existe movimentação de livro caixa aberta no momento."); MessageBox.Show("Não existe movimentação de livro caixa aberta no momento.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Close(); } } colOrdem = 0; }
private void LoadToControlsEmpresa() { Livro_CaixaBLL = new Livro_CaixaBLL(); List <Livro_Caixa> lstLc = Livro_CaixaBLL.getLivro_Caixa(p => DbFunctions.TruncateTime(p.data) == DbFunctions.TruncateTime(DateTime.Now), true); Livro_Caixa Livro_Caixa = null; if (lstLc.Count > 0) { Livro_Caixa = lstLc.First(); } if (Livro_Caixa != null) { Id = Livro_Caixa.Id; txtId.Text = Livro_Caixa.Id.ToString(); txtData.Text = Livro_Caixa.data.Value.ToShortDateString(); txtUsuarioInc.Text = Livro_Caixa.usuario_inclusao; txtDtInc.Text = Livro_Caixa.inclusao.Value.ToShortDateString(); txtStatus.Text = Livro_Caixa.status; if (Livro_Caixa.saldo_inicial != null) { txtSaldoInicial.Text = Livro_Caixa.saldo_inicial.Value.ToString("N2"); } if (Livro_Caixa.saldo_final != null) { txtSaldoFinal.Text = Livro_Caixa.saldo_final.Value.ToString("N2"); } lblFilial.Visible = false; cbFilial.Visible = false; cbFilial.Enabled = false; cbFilial.TabStop = false; if (TipoMovimento == tpMovimentoLivroCaixa.Abertura) { if (Livro_Caixa.status == "F") { if (Program.usuario_logado.perfil.administrativo == "S") { if (MessageBox.Show("Movimentação encerrada para a data: " + Livro_Caixa.data.Value.ToShortDateString() + "\n Deseja reabir a movimentação?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { txtSaldoFinal.Text = string.Empty; } else { txtSaldoInicial.Enabled = false; txtSaldoInicial.ReadOnly = true; btnSalvar.Enabled = false; } } else { MessageBox.Show("Movimentação encerrada para a data: " + Livro_Caixa.data.Value.ToShortDateString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtSaldoInicial.Enabled = false; txtSaldoInicial.ReadOnly = true; btnSalvar.Enabled = false; } } else { txtSaldoInicial.Enabled = true; txtSaldoInicial.ReadOnly = false; } txtSaldoFinal.Enabled = false; txtSaldoFinal.ReadOnly = true; } if (TipoMovimento == tpMovimentoLivroCaixa.Encerramento) { txtSaldoInicial.Enabled = false; txtSaldoInicial.ReadOnly = true; //Saldo inicial decimal sldIni = Convert.ToDecimal(txtSaldoInicial.Text); //Soma das entradas do dia decimal sumEnt = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "E").Sum(c => c.valor)); //Soma das saidas do dia decimal sumSaid = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "S").Sum(c => c.valor)); decimal total = ((sldIni + sumEnt) - (-1 * sumSaid)); txtSaldoFinal.Text = total.ToString("N2"); txtSaldoFinal.Enabled = true; txtSaldoFinal.ReadOnly = false; } } else { if (TipoMovimento == tpMovimentoLivroCaixa.Abertura) { txtData.Text = DateTime.Now.ToShortDateString(); lblFilial.Visible = false; cbFilial.Visible = false; cbFilial.Enabled = false; cbFilial.TabStop = false; long Id_empresa = Convert.ToInt64(Program.usuario_logado.Id_empresa); if (MessageBox.Show("Deseja utilizar como saldo de abertura, \n o saldo de encerramento da movimentação anterior?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //buscar a movimentação anterior Livro_CaixaBLL = new Livro_CaixaBLL(); lstLc = Livro_CaixaBLL.getLivro_Caixa(p => p.Id_empresa == Id_empresa, true, c => c.data.ToString()); if (lstLc.Count > 0) { Livro_Caixa = lstLc.First(); //Verifica se a movimentação do dia anterior foi fechada se não foi fecha. if (Livro_Caixa.status == "A") { //Saldo inicial decimal sldIni = Convert.ToDecimal(Livro_Caixa.saldo_inicial); //Soma das entradas do dia decimal sumEnt = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "E").Sum(c => c.valor)); //Soma das saidas do dia decimal sumSaid = Convert.ToDecimal(Livro_Caixa.item_livro_caixa.Where(p => p.tipo == "S").Sum(c => c.valor)); decimal total = ((sldIni + sumEnt) - (-1 * sumSaid)); Livro_Caixa.status = "F"; Livro_Caixa.saldo_final = total; Livro_CaixaBLL.AlterarLivro_Caixa(Livro_Caixa); } if (Livro_Caixa.saldo_final != null) { txtSaldoInicial.Text = Livro_Caixa.saldo_final.Value.ToString("N2"); } } } txtSaldoInicial.Enabled = true; txtSaldoInicial.ReadOnly = false; txtSaldoInicial.Focus(); } else if (TipoMovimento == tpMovimentoLivroCaixa.Encerramento) { MessageBox.Show("Não existe movimentação aberta para encerramento.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); DialogResult = DialogResult.Cancel; Close(); } } }