Ejemplo n.º 1
0
        // QUITAR A PAGAR AND INSERT NEW SAIDA
        //------------------------------------------------------------------------------------------------------------
        public long QuitarAPagar(
            objAPagar apagar,
            objMovimentacao saida,
            Action <int, decimal> ContaSldLocalUpdate,
            Action <int, decimal> SetorSldLocalUpdate)
        {
            AcessoDados dbTran = null;

            try
            {
                dbTran = new AcessoDados();
                dbTran.BeginTransaction();

                // Verifica CONTA SALDO
                ContaBLL cBLL = new ContaBLL();

                decimal saldoAtual = cBLL.ContaSaldoGet((int)saida.IDConta, dbTran);

                if (Math.Abs(saida.MovValor) > saldoAtual)
                {
                    throw new AppException("Não existe SALDO SUFICIENTE na conta para realizar esse débito...", 1);
                }

                // Verifica CONTA BLOQUEIO
                if (!cBLL.ContaDateBlockPermit((int)saida.IDConta, saida.MovData, dbTran))
                {
                    throw new AppException("A Data da Conta está BLOQUEADA nesta Data de Débito proposto...", 2);
                }

                // Inserir SAIDA
                saida.DescricaoOrigem = apagar.DespesaDescricao;
                long newID = new MovimentacaoBLL().InsertMovimentacao(saida, ContaSldLocalUpdate, SetorSldLocalUpdate, dbTran);
                saida.IDMovimentacao = newID;

                // Change APAGAR
                decimal DoValor = Math.Abs(saida.MovValor) - (saida.AcrescimoValor ?? 0);

                apagar.ValorAcrescimo += saida.AcrescimoValor ?? 0;
                apagar.ValorPago      += DoValor;
                if (apagar.ValorPago >= apagar.APagarValor - apagar.ValorDesconto)
                {
                    apagar.PagamentoData = saida.MovData;
                    apagar.IDSituacao    = 2;
                    apagar.Situacao      = "Quitada";
                }

                // Update APAGAR
                UpdateAPagar(apagar, dbTran);

                dbTran.CommitTransaction();

                return(newID);
            }
            catch (Exception ex)
            {
                dbTran.RollBackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        // ESTORNAR A PAGAR AND DELETE SAIDA
        //------------------------------------------------------------------------------------------------------------
        public bool EstornarAPagar(
            objAPagar apagar,
            objMovimentacao saida,
            Action <int, decimal> ContaSldLocalUpdate,
            Action <int, decimal> SetorSldLocalUpdate)
        {
            AcessoDados dbTran = null;

            try
            {
                dbTran = new AcessoDados();
                dbTran.BeginTransaction();

                // Verifica CONTA BLOQUEIO
                ContaBLL cBLL = new ContaBLL();

                if (!cBLL.ContaDateBlockPermit((int)saida.IDConta, saida.MovData, dbTran))
                {
                    throw new AppException("A Data da Conta está BLOQUEADA nesta Data proposta...", 2);
                }

                // CHECK SOURCE DESPESA IS DESPESA COMUM AND CHANGE SITUACAO
                if (apagar.DespesaOrigem == 1)
                {
                    var dBLL = new DespesaComumBLL();
                    dBLL.ChangeSituacaoDespesa(apagar.IDDespesa, 1, dbTran);
                }

                // DELETE REMOVE SAIDA
                new MovimentacaoBLL().DeleteMovimentacao((long)saida.IDMovimentacao, ContaSldLocalUpdate, SetorSldLocalUpdate, dbTran);

                // Change APAGAR
                decimal DoValor = saida.MovValor - (saida.AcrescimoValor ?? 0);

                apagar.ValorAcrescimo -= saida.AcrescimoValor ?? 0;
                apagar.ValorPago      += DoValor;
                apagar.PagamentoData   = null;
                apagar.IDSituacao      = 1;
                apagar.Situacao        = "Em Aberto";

                // Update APAGAR
                UpdateAPagar(apagar, dbTran);

                dbTran.CommitTransaction();

                return(true);
            }
            catch (Exception ex)
            {
                dbTran.RollBackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 3
0
        // GET LAST CAIXA CONTA
        //------------------------------------------------------------------------------------------------------------
        public objCaixa GetLastCaixa(int IDConta)
        {
            try
            {
                AcessoDados db = new AcessoDados();
                db.BeginTransaction();

                //--- get the MAXDATE to verify movimentacao and continue
                DateTime?MaxDate = GetMaxDateContaMov(IDConta, db);

                if (MaxDate == null)
                {
                    throw new AppException("Essa Conta não possui nenhuma movimentação pendente de caixa...");
                }

                //--- get lastCaixa
                objCaixa LastCaixa = null;
                string   query     = "SELECT TOP 1 * FROM qryCaixa WHERE IDConta = @IDConta ORDER BY IDCaixa DESC";

                db.LimparParametros();
                db.AdicionarParametros("@IDConta", IDConta);

                DataTable dt = db.ExecutarConsulta(CommandType.Text, query);

                //--- if LASTCaixa => NULL construct new objCaixa to return
                if (dt.Rows.Count == 0)
                {
                    objConta conta = new ContaBLL().GetConta(IDConta, db);

                    LastCaixa = new objCaixa(null)
                    {
                        DataFinal         = (DateTime)MaxDate,
                        DataInicial       = GetMinDateContaMov(IDConta, db),
                        IDConta           = IDConta,
                        CaixaFinalDoDia   = false,
                        Conta             = conta.Conta,
                        ContaBloqueioData = conta.BloqueioData,
                        ContaSaldo        = conta.ContaSaldo,
                        FechamentoData    = DateTime.Today,
                        IDSituacao        = 0,
                        SaldoAnterior     = 0,
                        SaldoFinal        = 0,
                        Situacao          = "Iniciado",
                    };

                    return(LastCaixa);
                }

                //--- else convert DataRow in objCaixa
                LastCaixa = ConvertRowInClass(dt.Rows[0]);

                //--- Redefine control Dates
                LastCaixa.DataInicial = LastCaixa.CaixaFinalDoDia ? LastCaixa.DataFinal.AddDays(1) : LastCaixa.DataFinal;
                LastCaixa.DataFinal   = (DateTime)MaxDate;

                return(LastCaixa);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        // INSERT DESPESA REALIZADA | GASTO | DESPESA QUITADA
        //------------------------------------------------------------------------------------------------------------
        public long InsertDespesaRealizada(
            objDespesaComum despesa,
            objAPagar pagar,
            objMovimentacao saida,
            Action <int, decimal> ContaSldLocalUpdate,
            Action <int, decimal> SetorSldLocalUpdate,
            object dbTran = null)
        {
            bool IsTran = dbTran != null;

            try
            {
                // create transaction
                if (!IsTran)
                {
                    dbTran = new AcessoDados();
                }
                if (!IsTran)
                {
                    ((AcessoDados)dbTran).BeginTransaction();
                }

                // Verifica CONTA SALDO
                ContaBLL cBLL = new ContaBLL();

                decimal saldoAtual = cBLL.ContaSaldoGet((int)saida.IDConta, dbTran);

                if (saida.MovValor > saldoAtual)
                {
                    throw new AppException("Não existe SALDO SUFICIENTE na conta para realizar esse débito...", 1);
                }

                // Verifica CONTA BLOQUEIO
                if (!cBLL.ContaDateBlockPermit((int)saida.IDConta, saida.MovData, dbTran))
                {
                    throw new AppException("A Data da Conta está BLOQUEADA nesta Data de Débito proposto...", 2);
                }

                // create APagar list
                List <objAPagar> listPag = new List <objAPagar>();
                listPag.Add(pagar);

                // insert Despesa AND APagar
                despesa.IDSituacao = 2;                 // quitada
                long newID = InsertDespesaComum(despesa, ref listPag, dbTran);

                // insert Saida
                saida.MovTipo         = 2;
                saida.Origem          = EnumMovOrigem.APagar;
                saida.IDOrigem        = (long)listPag[0].IDAPagar;
                saida.DescricaoOrigem = $"DESPESA: {despesa.DespesaDescricao}";
                if (saida.DescricaoOrigem.Length > 250)
                {
                    saida.DescricaoOrigem = saida.DescricaoOrigem.Substring(0, 250);
                }

                new MovimentacaoBLL().InsertMovimentacao(saida, ContaSldLocalUpdate, SetorSldLocalUpdate, dbTran);

                // commit and return
                if (!IsTran)
                {
                    ((AcessoDados)dbTran).CommitTransaction();
                }
                return(newID);
            }
            catch (Exception ex)
            {
                if (!IsTran)
                {
                    ((AcessoDados)dbTran).RollBackTransaction();
                }
                throw ex;
            }
        }