Пример #1
0
        public TableRowViewModel(IList <MoneyStateModel> item, List <MoneyColumnMetadataJsModel> headers, Dictionary <string, MoneyColumnMetadataJsModel> headersCached, Dictionary <MoneyColumnMetadataJsModel, Dictionary <DateTime, double> > paymentsToExempt)
        {
            var minDate = item.Select(v => v.When).Min();
            var maxDate = item.Select(v => v.When).Max();

            When = minDate.AddSeconds((maxDate - minDate).TotalSeconds / 2);

            When = When.Date.AddHours(12);

            var grouped = item.GroupBy(v => v.Column).ToDictionary(v => v.Key,
                                                                   s => s.OrderByDescending(t => t.When).First());

            CalculatedCells = new Dictionary <MoneyColumnMetadataJsModel, CalculatedResult>();
            foreach (var h in headers)
            {
                CalculatedResult cell = null;
                var money             = grouped.GetValueOrDefault(h.Column);

                if (money == null && h.IsComputed)
                {
                    cell = CalculatedResult.FromComputed(headersCached, h, CalculatedCells);
                }
                else if (money != null)
                {
                    var adj = paymentsToExempt.GetValueOrDefault(h)?.GetValueOrDefault(money.When.Date.AddDays(-1)) ?? 0;

                    cell = CalculatedResult.FromMoney(h, money, adj);
                }

                CalculatedCells[h] = cell ?? CalculatedResult.Missing(h);
            }

            // make a copy of dictionary to make it editable and to not lost references to dependencies
            CalculatedCells = CalculatedCells.ToDictionary(v => v.Key, v => v.Value);
        }
Пример #2
0
        public TableRowViewModel(IList <MoneyStateModel> item, List <MoneyColumnMetadataModel> headers, Dictionary <string, MoneyColumnMetadataModel> headersCached)
        {
            When  = item.OrderByDescending(v => v.When).Select(v => v.When).FirstOrDefault();
            Cells = new List <CalculatedResult>();

            foreach (var h in headers)
            {
                if (h.IsComputed)
                {
                    Cells.Add(CalculatedResult.FromComputed(headersCached, h));
                }
                else
                {
                    var money = item.Where(v => v.Provider == h.Provider && v.AccountName == h.AccountName).OrderByDescending(v => v.When).FirstOrDefault();
                    if (money != null)
                    {
                        Cells.Add(CalculatedResult.FromMoney(h, money));
                    }
                }
            }
        }