Exemplo n.º 1
0
        private Available CalculateAvailable(DateTime entryDate, DailyAmount dailyAmount)
        {
            if (period == null)
            {
                return(Available.FromDecimal(0m));
            }
            var expenditures = totalExpenditure?.Amount ?? 0m;
            var elapsedDays  = period.ElapsedDays(entryDate);
            var available    = (elapsedDays * dailyAmount) - expenditures;

            return(Available.FromDecimal(available >= 0m ? available : 0m));
        }
Exemplo n.º 2
0
        private DailyAmount CalculateDaily()
        {
            if (period == null)
            {
                return(DailyAmount.FromDecimal(0m));
            }
            var income = totalIncome?.Amount ?? 0m;
            var outgo  = totalOutgo?.Amount ?? 0m;
            var daily  = Math.Round(((income - outgo) / period.Days), 2);

            return(DailyAmount.FromDecimal(daily));
        }
Exemplo n.º 3
0
        private void ApplySnapshotChanges(DateTime entryDate, DailyAmount daily)
        {
            var available = CalculateAvailable(entryDate, daily);

            Apply(new Events.SnapshotChanged
            {
                DailyBudgetId = ParentId,
                SnapshotId    = Id,
                Daily         = daily,
                Available     = available,
                EntryDate     = entryDate
            });
        }
Exemplo n.º 4
0
        protected override void When(object @event)
        {
            switch (@event)
            {
            case Events.DailyBudgetCreated e:
                ParentId  = new DailyBudgetId(e.Id);
                Id        = new SnapshotId(Guid.NewGuid());
                Daily     = DailyAmount.FromDecimal(0m);
                Available = Available.FromDecimal(0m);
                break;

            case Events.PeriodAddedToDailyBudget e:
                period = Period.Create(e.Start, e.End);
                SetPeriod(e.EntryDate);
                break;

            case Events.PeriodStartChanged e:
                period = Period.Create(e.Start, period.ToB);
                SetPeriod(e.EntryDate);
                break;

            case Events.PeriodEndChanged e:
                period = Period.Create(period.FromA, e.End);
                SetPeriod(e.EntryDate);
                break;

            case Events.IncomeAddedToDailyBudget e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.IncomeRemoved e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.IncomeAmountChanged e:
                SetTotalIncome(Amount.FromDecimal(e.TotalIncome), e.EntryDate);
                break;

            case Events.OutgoAddedToDailyBudget e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.OutgoRemoved e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.OutgoAmountChanged e:
                SetTotalOutgo(Amount.FromDecimal(e.TotalOutgo), e.EntryDate);
                break;

            case Events.ExpenditureAdded e:
                SetTotalExpenditures(Amount.FromDecimal(e.TotalExpenditure), e.EntryDate);
                break;

            case Events.ExpenditureAmountChanged e:
                SetTotalExpenditures(Amount.FromDecimal(e.TotalExpenditure), e.EntryDate);
                break;

            case Events.SnapshotChanged e:
                Daily     = DailyAmount.FromDecimal(e.Daily);
                Available = Available.FromDecimal(e.Available);
                break;
            }
        }