Esempio n. 1
0
        public Decimal Total(Sum sum)
        {
            var collection = _database.GetCollection<Earning>(EARNING_COLLECTION);

            var earnings = collection.FindAllAs<Earning>();

            var earningsTotal = earnings.Where(e => e.Date.CompareTo(sum.End) <= 0).Sum(e => e.Amount);
            var onusesTotal = earnings.SelectMany(e => e.Onuses).Where(o => o.Date.CompareTo(sum.End) <= 0).Sum(o => o.Amount);

            if (sum.includeOnlyCleared)
            {
                var unclearedTotal = earnings.SelectMany(e => e.Onuses).Where(o => o.Date.CompareTo(sum.End) <= 0 && !o.Cleared).Sum(o => o.Amount);
                onusesTotal -= unclearedTotal;
            }

            Decimal balance = 0;

            if (sum.IncludeBalance)
            {
                var balanceCollection = _database.GetCollection(BALANCE_COLLECTION);
               
                balance = Decimal.Parse(balanceCollection.FindOne().Elements.FirstOrDefault(a => a.Name == "Amount").Value.ToString());
            }



            return earningsTotal + onusesTotal + balance;
        }
Esempio n. 2
0
 public Decimal Sum(Sum sum)
 {
     return _mongoContext.Total(sum);
 }