Ejemplo n.º 1
0
        private static List <OperationSet> AggregateOperations(
            decimal initialBalance,
            DateRange range,
            RecurrenceFamily recurrence,
            IEnumerable <UnifiedAccountOperation> orderedOperations)
        {
            var result = new List <OperationSet>();

            var start = recurrence.GetPeriod(range.Min);

            var currentBpd = new OperationSet(recurrence, start, initialBalance);

            result.Add(currentBpd);

            using (var operationEnumerator = orderedOperations.GetEnumerator())
            {
                while (operationEnumerator.MoveNext())
                {
                    var operation = operationEnumerator.Current;
                    if (operation == null)
                    {
                        continue;
                    }

                    var operationPeriod = recurrence.GetPeriod(operation.ExecutionDate);

                    while (currentBpd.Period < operationPeriod)
                    {
                        currentBpd = OperationSet.CreateForNextStep(currentBpd);
                        result.Add(currentBpd);
                    }

                    currentBpd.Add(operation);
                }
            }

            start = currentBpd.Period;
            var end = recurrence.GetPeriod(range.Max);

            while (start < end)
            {
                currentBpd = OperationSet.CreateForNextStep(currentBpd);
                result.Add(currentBpd);
                start = currentBpd.Period;
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static OperationSet CreateForNextStep(OperationSet currentBpd)
        {
            DateTime nextStepDay;

            switch (currentBpd.Recurrence)
            {
            case RecurrenceFamily.Daily:
                nextStepDay = currentBpd.Period.AddDays(1);
                break;

            case RecurrenceFamily.Monthly:
                nextStepDay = currentBpd.Period.AddMonths(1);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new OperationSet(currentBpd.Recurrence, nextStepDay, currentBpd.Balance)
            {
                Balance = currentBpd.Balance
            });
        }