private async Task <decimal> CalculateInterestAndPenalty(Bill bill) { var interest = await _interestRepository.GetAllAsync(); decimal adjustedValue = bill.OriginalValue; int numberOfDaysLate = 0; double interestPorcent = 0; double penaltyPorcent = 0; numberOfDaysLate = CalculateDaysofLate(bill); if (numberOfDaysLate <= 3) { interestPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.ATE3DIAS).InterestPorcent; penaltyPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.ATE3DIAS).PenaltyPorcent; } else if (numberOfDaysLate > 3 && numberOfDaysLate < 5) { interestPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.DE4A5DIAS).InterestPorcent; penaltyPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.DE4A5DIAS).PenaltyPorcent; } else if (numberOfDaysLate > 5) { interestPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.SUPERIORA5DIAS).InterestPorcent; penaltyPorcent = interest.FirstOrDefault(x => x.DayOfDelay == DayOfDelayStatus.SUPERIORA5DIAS).PenaltyPorcent; } adjustedValue += (adjustedValue * Convert.ToDecimal(penaltyPorcent)); adjustedValue += (adjustedValue * Convert.ToDecimal(interestPorcent)) / (BUSINESS_MONTH_DAYS * numberOfDaysLate); return(Decimal.Round(adjustedValue, 2)); }