コード例 #1
0
 /// <summary>
 /// Tilføjer budgetoplysinger.
 /// </summary>
 /// <param name="budgetoplysninger">Budgetoplysninger.</param>
 public virtual void TilføjBudgetoplysninger(Budgetoplysninger budgetoplysninger)
 {
     if (budgetoplysninger == null)
     {
         throw new ArgumentNullException("budgetoplysninger");
     }
     budgetoplysninger.SætBudgetkonto(this);
     _budgetoplysninger.Add(budgetoplysninger);
 }
コード例 #2
0
        /// <summary>
        /// Kalkulering af status på et givent tidspunkt.
        /// </summary>
        /// <param name="statusDato">Statusdato.</param>
        /// <param name="løbenr">Den unikke identifikation af bogføringslinjen, som indgår i beregningen.</param>
        public virtual void Calculate(DateTime statusDato, int løbenr)
        {
            foreach (var budgetoplysninger in Budgetoplysninger)
            {
                if (budgetoplysninger.År > statusDato.Year || (budgetoplysninger.År == statusDato.Year && budgetoplysninger.Måned > statusDato.Month))
                {
                    budgetoplysninger.SætBogførtPrStatusdato(0);
                    continue;
                }
                var fraDato = new DateTime(budgetoplysninger.År, budgetoplysninger.Måned, 1);
                if (budgetoplysninger.År == statusDato.Year && budgetoplysninger.Måned == statusDato.Month)
                {
                    budgetoplysninger.SætBogførtPrStatusdato(CalculateBogført(fraDato, statusDato, løbenr));
                    continue;
                }
                var tilDato = new DateTime(budgetoplysninger.År, budgetoplysninger.Måned, DateTime.DaysInMonth(budgetoplysninger.År, budgetoplysninger.Måned));
                budgetoplysninger.SætBogførtPrStatusdato(CalculateBogført(fraDato, tilDato, løbenr));
            }
            var aktuelBudgetoplysninger = Budgetoplysninger.SingleOrDefault(m => m.År == statusDato.Year && m.Måned == statusDato.Month);

            BudgetPrStatusdato  = aktuelBudgetoplysninger == null ? 0M : aktuelBudgetoplysninger.Budget;
            BogførtPrStatusdato = aktuelBudgetoplysninger == null?CalculateBogført(new DateTime(statusDato.Year, statusDato.Month, 1), statusDato, løbenr) : aktuelBudgetoplysninger.BogførtPrStatusdato;

            var sidsteMånedStatusDato        = new DateTime(statusDato.AddMonths(-1).Year, statusDato.AddMonths(-1).Month, DateTime.DaysInMonth(statusDato.AddMonths(-1).Year, statusDato.AddMonths(-1).Month));
            var sidsteMånedBudgetoplysninger = Budgetoplysninger.SingleOrDefault(m => m.År == sidsteMånedStatusDato.Year && m.Måned == sidsteMånedStatusDato.Month);

            BudgetSidsteMåned  = sidsteMånedBudgetoplysninger == null ? 0M : sidsteMånedBudgetoplysninger.Budget;
            BogførtSidsteMåned = sidsteMånedBudgetoplysninger == null?CalculateBogført(new DateTime(sidsteMånedStatusDato.Year, sidsteMånedStatusDato.Month, 1), sidsteMånedStatusDato, løbenr) : sidsteMånedBudgetoplysninger.BogførtPrStatusdato;

            BudgetÅrTilStatusdato  = Budgetoplysninger.Where(m => m.År == statusDato.Year && m.Måned <= statusDato.Month).Sum(m => m.Budget);
            BogførtÅrTilStatusdato = CalculateBogført(new DateTime(statusDato.Year, 1, 1), statusDato, løbenr);

            var sidsteÅrStatusDato = new DateTime(statusDato.AddYears(-1).Year, 12, 31);

            BudgetSidsteÅr  = Budgetoplysninger.Where(m => m.År == sidsteÅrStatusDato.Year).Sum(m => m.Budget);
            BogførtSidsteÅr = CalculateBogført(new DateTime(sidsteÅrStatusDato.Year, 1, 1), sidsteÅrStatusDato, løbenr);
        }