Ejemplo 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));
        }
Ejemplo n.º 2
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;
            }
        }