Esempio n. 1
0
        public async Task <MoneyOperationShortInfo[]> CalculatePeriodCurrentDebts(long billingPeriodId)
        {
            MoneyOperation[] periodOperations = await _moneyOperationService.GetByBillingPeriodIdAsync(billingPeriodId);

            Receipt[] periodReceipts = (await _receiptService.GetByBillingPeriodIdAsync(billingPeriodId))
                                       .Where(x => x.Status.IsFinalStatus()).ToArray();
            Dictionary <long, long[]> consumerMap = await _receiptService.GetConsumerIdsByReceiptIdsMapAsync(periodReceipts.Select(x => x.Id).ToArray());

            return(await _debtsCalculator
                   .Calculate(periodOperations, periodReceipts
                              .Where(x => x.CustomerId.HasValue)
                              .Select(x => new ReceiptCalculatorInfo
            {
                Amount = x.TotalAmount,
                CustomerId = x.CustomerId.Value,
                ConsumerIds = consumerMap[x.Id]
            }).ToArray()));
        }