Exemplo n.º 1
0
        public async Task <FeeRuleDto> GetOne(Guid id)
        {
            var feeRule = await _feeRuleRepositoryRepository.GetById(id);

            if (feeRule == null)
            {
                throw new KeyNotFoundException($"Fee Rule with id: {id} not found.");
            }

            return(_mapper.Map <FeeRule, FeeRuleDto>(feeRule));
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <FeesReportDto> > GetFeesReport(FeesReportsFiltersDto filtersDto)
        {
            List <FeesReportDto> feesReports = new List <FeesReportDto>();

            var sales = (await _saleRepositoryRepository
                         .Find(x => x.PaymentType == ePaymentTypes.OwnFees, x => x.Include(s => s.Details))
                         ).AsQueryable().Where(filtersDto.GetExpresion()).OrderBy(x => x.Date);

            foreach (var sale in sales)
            {
                FeesReportDto feesReport = new FeesReportDto();
                feesReport.Date       = sale.Date;
                feesReport.ClientId   = sale.ClientId;
                feesReport.ClientName = sale.ClientName;

                var ownFee = (await _ownFeesRepository.Find(x => x.SaleId == sale.Id, x => x.Include(s => s.FeeList))).FirstOrDefault();
                feesReport.FeesQty     = ownFee.Quantity;
                feesReport.TotalAmount = ownFee.Amount;
                feesReport.FeeValue    = ownFee.FeeList.OrderBy(x => x.ExpirationDate).FirstOrDefault().Value;

                decimal percentage = 0;
                foreach (var detail in sale.Details)
                {
                    if (!detail.FeeRuleId.HasValue)
                    {
                        throw new InvalidOperationException("FeeRuleId is empty");
                    }

                    var rule = await _feeRuleRepository.GetById(detail.FeeRuleId.Value);

                    if (rule == null)
                    {
                        rule = (await _feeRuleRepository.FindDeleted(x => x.Id == detail.FeeRuleId.Value)).FirstOrDefault();
                    }
                    if (rule == null)
                    {
                        throw new KeyNotFoundException($"Fee Rule with id: {detail.FeeRuleId.Value} not found.");
                    }

                    percentage += rule.Percentage;
                }

                feesReport.Interest = feesReport.FeeValue * (percentage * ownFee.Quantity / 100);
                feesReport.Capital  = feesReport.FeeValue - feesReport.Interest;

                feesReports.Add(feesReport);
            }

            return(feesReports);
        }