示例#1
0
        private async Task Execute(FinancialEntryEntity entity)
        {
            try
            {
                var financialEntryRepository = _container.GetInstance <IFinancialEntryRepository>();
                var dayBalanceBusiness       = _container.GetInstance <IDayBalanceBusiness>();
                var dayBalanceRepository     = _container.GetInstance <IDayBalanceRepository>();

                entity.Conciled   = true;
                entity.ConciledAt = DateTime.Now;
                await financialEntryRepository.Update(entity);

                var dayBalance = await dayBalanceRepository.GetByDate(entity.EntryDate);

                if (dayBalance == null)
                {
                    await dayBalanceBusiness.Insert(entity);
                }
                else
                {
                    await dayBalanceBusiness.Update(entity, dayBalance);
                }
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        public async Task <DayBalanceEntity> FillDayBalance(FinancialEntryEntity entity, DayBalanceEntity dayBalanceEntity = null)
        {
            try
            {
                var isPayment = entity.EntryType == FinancialEntryTypeEnum.Payment;
                if (dayBalanceEntity == null)
                {
                    dayBalanceEntity = await _dayBalanceRepository.GetByDate(entity.EntryDate);
                }

                if (dayBalanceEntity == null)
                {
                    dayBalanceEntity = new DayBalanceEntity();
                }

                dayBalanceEntity.Date = entity.EntryDate;

                if (isPayment)
                {
                    dayBalanceEntity.TotalOut += entity.Value;
                }
                else
                {
                    dayBalanceEntity.TotalEntry += entity.Value;
                }

                dayBalanceEntity.Balance  = CalculateBalance(dayBalanceEntity);
                dayBalanceEntity.Interest = CalculateInterest(dayBalanceEntity);
                return(dayBalanceEntity);
            }
            catch
            {
                throw;
            }
        }
示例#3
0
        public async Task AddToQueue(FinancialEntryEntity financialEntryEntity)
        {
            try
            {
                var dayAccountLimit = Convert.ToDecimal(Configuration.GetSection("Business:DayAccountLimit").Value);
                if (_financialEntryValidateService.IsEntryInThePast(financialEntryEntity.EntryDate, DateTime.Now))
                {
                    throw new ApiException("Você não pode fazer lançamentos no passado!", HttpStatusCode.BadRequest);
                }

                if (financialEntryEntity.EntryType == FinancialEntryTypeEnum.Payment)
                {
                    var dayBalanceEntity = await _dayBalanceBusiness.FillDayBalance(financialEntryEntity);

                    if (_financialEntryValidateService.IsDayAccountLimitReached(dayBalanceEntity))
                    {
                        throw new ApiException(string.Format("O valor ultrapassa o limite de pagamento diário no valor de {0}.", FinancialConverter.ToRealFormat(dayAccountLimit)), HttpStatusCode.UnprocessableEntity);
                    }

                    await _paymentQueue.Publish(financialEntryEntity);
                }

                if (financialEntryEntity.EntryType == FinancialEntryTypeEnum.Receipt)
                {
                    await _receiptQueue.Publish(financialEntryEntity);
                }
            }
            catch
            {
                throw;
            }
        }
示例#4
0
 public async Task <long> Create(FinancialEntryEntity entity)
 {
     try
     {
         return(await _financialEntryRepository.Create(entity));
     }
     catch
     {
         throw;
     }
 }
示例#5
0
 public async Task <long> Create(FinancialEntryEntity entity)
 {
     try
     {
         var sql = @"INSERT INTO financial_entry 
         (
             entry_type,
             description,
             destination_account,
             destination_bank,
             destination_cpf_cnpj,
             account_type,
             value,
             charge,
             entry_date,
             created_at,
             conciled
         )
         VALUES
         (
             @EntryType,
             @Description,
             @DestinationAccount,
             @DestinationBank,
             @DestinationCpfCnpj,
             @AccountType,
             @Value,
             @Charge,
             @EntryDate,
             @CreatedAt,
             @Conciled
         );
         SELECT LAST_INSERT_ID();";
         return(await _connection.ExecuteScalarAsync <long>(sql, new
         {
             EntryType = entity.EntryType,
             Description = entity.Description,
             DestinationAccount = entity.DestinationAccount,
             DestinationBank = entity.DestinationBank,
             DestinationCpfCnpj = entity.DestinationCpfCnpj,
             AccountType = entity.AccountType,
             Value = entity.Value,
             Charge = entity.Charge,
             EntryDate = entity.EntryDate.ToString("yyyy-MM-dd HH:mm:ss"),
             CreatedAt = entity.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss"),
             Conciled = entity.Conciled
         }));
     }
     catch
     {
         throw;
     }
 }
示例#6
0
        public async Task <bool> Update(FinancialEntryEntity financialEntryEntity, DayBalanceEntity dayBalanceEntity)
        {
            try
            {
                var dayInterest = Convert.ToDecimal(Configuration.GetSection("Business:DayInterest").Value);
                dayBalanceEntity = await FillDayBalance(financialEntryEntity, dayBalanceEntity);

                return(await _dayBalanceRepository.Update(dayBalanceEntity));
            }
            catch
            {
                throw;
            }
        }
示例#7
0
        public async Task <long> Insert(FinancialEntryEntity entity)
        {
            try
            {
                var isPayment        = entity.EntryType == FinancialEntryTypeEnum.Payment;
                var dayBalanceEntity = await FillDayBalance(entity);

                return(await _dayBalanceRepository.Insert(dayBalanceEntity));
            }
            catch
            {
                throw;
            }
        }
示例#8
0
        private async Task Execute(FinancialEntryEntity entity)
        {
            try
            {
                var financialEntryBusiness = _container.GetInstance <IFinancialEntryBusiness>();
                var conciliateQueue        = _container.GetInstance <IConciliateQueue>();
                entity.Id = await financialEntryBusiness.Create(entity);

                await conciliateQueue.Publish(entity);
            }
            catch
            {
                throw;
            }
        }
示例#9
0
 public void AddToQueueDayAccountLimitException()
 {
     try
     {
         var financialEntryEntity = new FinancialEntryEntity()
         {
             EntryType = FinancialEntryTypeEnum.Payment
         };
         var now      = DateTime.Now;
         var tomorrow = now.AddDays(1);
         _configuration.Setup(x => x.GetSection("Business:DayAccountLimit").Value).Returns("20000,00");
         _financialEntryValidateService.Setup(x => x.IsEntryInThePast(tomorrow, now)).Returns(false);
         var financialEntryBusiness = new FinancialEntryBusiness(_paymentQueue.Object, _receiptQueue.Object, _financialEntryRepository.Object, _financialEntryValidateService.Object, _dayBalanceBusiness.Object, _configuration.Object);
         financialEntryBusiness.AddToQueue(financialEntryEntity).GetAwaiter().GetResult();
     }
     catch (ApiException ex)
     {
         Assert.Equal(HttpStatusCode.UnprocessableEntity, ex.HttpStatusCode);
     }
 }
示例#10
0
        public void FillDayBalance(decimal currentValue, decimal totalOut, decimal totalEntry, decimal expectedBalance, decimal expectedInterest)
        {
            _configuration.Setup(x => x.GetSection("Business:DayInterest").Value).Returns("0,83");
            var dayBalanceBusiness   = new DayBalanceBusiness(_dayBalanceRepository.Object, _financialEntryValidateService.Object, _configuration.Object);
            var financialEntryEntity = new FinancialEntryEntity()
            {
                EntryType = FinancialEntryTypeEnum.Payment,
                Value     = currentValue
            };
            var dayBalanceEntity = new DayBalanceEntity()
            {
                TotalOut   = totalOut,
                TotalEntry = totalEntry
            };
            var result = dayBalanceBusiness.FillDayBalance(financialEntryEntity, dayBalanceEntity).GetAwaiter().GetResult();

            Assert.Equal(expectedBalance, result.Balance);
            Assert.Equal(expectedInterest, result.Interest);
            Assert.Equal((currentValue + totalOut), result.TotalOut);
            Assert.Equal(totalEntry, result.TotalEntry);
        }
示例#11
0
        public async Task <bool> Update(FinancialEntryEntity entity)
        {
            try
            {
                var sql    = @"UPDATE financial_entry SET
                                conciled =  @Conciled,
                                conciled_at = @ConciledAt
                            WHERE id = @Id;";
                var result = await _connection.ExecuteAsync(sql, new
                {
                    Id         = entity.Id,
                    Conciled   = entity.Conciled,
                    ConciledAt = entity.ConciledAt.ToString("yyyy-MM-dd HH:mm:ss")
                });

                return(result == 1);
            }
            catch
            {
                throw;
            }
        }