public virtual ActionResult ByCategory(string budgetId, string From, string To)
        {
            DateTime?from = null;
            DateTime?to   = null;

            if (From != null)
            {
                from = DateTime.Parse(From);
            }
            if (To != null)
            {
                to = DateTime.Parse(To);
            }

            var projection = ProjectionManager.GetBudgetLinesProjection(budgetId);
            IEnumerable <BudgetLine> lines = projection.GetAllLinesBetween(from, to);

            if (from == null)
            {
                from = lines.Select(s => s.Date).DefaultIfEmpty(DateTime.MinValue).Min(r => r.Date.Date);
            }
            if (to == null)
            {
                to = lines.Select(s => s.Date).DefaultIfEmpty(DateTime.MaxValue).Max(r => r.Date.Date);
            }

            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(budgetId);
            var model      = new BudgetStatsByCategoryViewModel(categories, lines, budgetId, "NA", from, to);

            return(View(model));
        }
Beispiel #2
0
        public virtual ActionResult Index(string id)
        {
            var readModel = ProjectionManager.GetBudgetLinesProjection(id);
            var lines     = readModel.GetAllLines();
            var model     = new BudgetLinesViewModel(id, lines);

            return(View(model));
        }
Beispiel #3
0
        public void Run(string budgetId, string userId, string file)
        {
            var excel     = new ExcelQueryFactory(file);
            var anni      = new[] { 2011, 2012, 2013, 2014 };
            var movements = new List <Movimento>();

            DateTime ld;
            int      count = 0;

            //"B3","F22",
            //foreach (var asd in excel.WorksheetRange<Movimento>("B3", "F300", 2020 + ""))
            //foreach (var asd in excel.Worksheet<Movimento>(2020 + ""))
            //{
            //    count++;
            //    if (asd.Data != DateTime.MinValue)
            //        ld = asd.Data;
            //}

            foreach (var anno in anni)
            {
                //movements.AddRange(excel.WorksheetRange<Movimento>("B3", "E300", anno + "").Where(r => r.Data != DateTime.MinValue));
                movements.AddRange(excel.Worksheet <Movimento>(anno + "").Where(r => r.Data != DateTime.MinValue));
            }
            movements = movements.OrderBy(d => d.Data).ToList();

            var stats = movements.GroupBy(g => g.Data.Year).ToList();
            var zero  = movements.Where(m => m.Spesa == decimal.Zero).ToList();

            Console.WriteLine("Read {0} movements from {1}", movements.Count, file);

            var importer  = new ImportManager(_cm, _pm);
            var categorie = movements.Select(s => s.Categoria).Where(r => r != "Arancio").ToArray();

            importer.ImportCategoriesByName(categorie, budgetId, userId);

            var categories = _pm.GetCategories().GetBudgetsCategories(budgetId);

            var      createLine = _cm.Create <CreateLine>();
            DateTime last       = DateTime.MinValue;

            foreach (var m in movements)
            {
                last = DateTime.Now;
                createLine(m.ToCreateLine(last, new BudgetId(budgetId), userId, categories));
            }
            var bp   = _pm.GetBudgetLinesProjection(budgetId);
            var galt = bp.GetAllLines(last);

            galt.Wait();
            var lines = galt.Result;

            Console.WriteLine("Loaded {0} movements into {1}", lines.Count(), budgetId);
        }
        public virtual ActionResult ByCategoryInTime(string budgetId, string From, string To, string GroupBy)
        {
            DateTime?from = null;
            DateTime?to   = null;

            if (From != null)
            {
                from = DateTime.Parse(From);
            }
            if (To != null)
            {
                to = DateTime.Parse(To);
            }

            GroupBy groupBy = MyBudget.Web.AspNet.Controllers.GroupBy.Year;

            try
            {
                groupBy = (GroupBy)Enum.Parse(typeof(GroupBy), GroupBy);
            }
            catch { }

            var projection = ProjectionManager.GetBudgetLinesProjection(budgetId);
            IEnumerable <BudgetLine> lines = projection.GetAllLinesBetween(from, to);

            if (from == null)
            {
                from = lines.Select(s => s.Date).DefaultIfEmpty(DateTime.MinValue).Min(r => r.Date.Date);
            }
            if (to == null)
            {
                to = lines.Select(s => s.Date).DefaultIfEmpty(DateTime.MaxValue).Max(r => r.Date.Date);
            }
            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(budgetId);
            var model      = new BudgetStatsByCategoryInTimeViewModel(categories, lines, budgetId, "NA", from, to, groupBy);

            return(View(model));
        }
Beispiel #5
0
        public virtual ActionResult Page(string id, string From, string To, int?pageIndex, string category)
        {
            DateTime?from = null;
            DateTime?to   = null;

            if (string.IsNullOrEmpty(From) == false)
            {
                from = DateTime.Parse(From);
            }

            if (string.IsNullOrEmpty(To) == false)
            {
                to = DateTime.Parse(To);
            }

            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(new Domain.Budgets.BudgetId(id));
            var readModel  = ProjectionManager.GetBudgetLinesProjection(id);
            var lines      = readModel.GetAllLinesPaged(pageIndex.GetValueOrDefault(), from, to, category);

            var model = new BudgetLinesPagedViewModel(id, lines, from, to, categories, category);

            return(View(model));
        }
        public void Run(string budgetId, string userId, string file)
        {
            var excel     = new ExcelQueryFactory(file);
            var anni      = new[] { 2013, 2014 };
            var movements = new List <Movimento>();

            foreach (var anno in anni)
            {
                //movements.AddRange(excel.Worksheet<Movement>(anno + "")
                //    .Where(r => r.Data != DateTime.MinValue));

                var laura = excel.WorksheetRange <Movimento>("B6", "E10000", anno + "")
                            .Where(r => r.Data != DateTime.MinValue)
                            .ToList();
                laura.ForEach(m => m.DistributionKey = "Laura");

                var valerio = excel.WorksheetRange <Movimento>("G6", "J10000", anno + "")
                              .Where(r => r.Data != DateTime.MinValue)
                              .ToList();
                valerio.ForEach(m => m.DistributionKey = "Valerio");

                var comune = excel.WorksheetRange <Movimento>("L6", "O10000", anno + "")
                             .Where(r => r.Data != DateTime.MinValue)
                             .ToList();


                movements.AddRange(laura);
                movements.AddRange(valerio);
                movements.AddRange(comune);
            }

            //var tasse = movements.GroupBy(g => g.Categoria).ToList();

            Console.WriteLine("Read {0} movements from {1}", movements.Count, file);
            movements = movements.Where(r => r.Categoria != "Arancio").OrderBy(d => d.Data).ToList();


            var importer  = new ImportManager(_cm, _pm);
            var categorie = movements.Select(s => s.Categoria).ToArray();

            importer.ImportCategoriesByName(categorie, budgetId, userId);

            var categories = _pm.GetCategories().GetBudgetsCategories(budgetId);

            var createLine = _cm.Create <CreateLine>();
            //foreach (var m in movements.Where(r=> r.Categoria != "Arancio"))
            //    createLine(m.ToCreateLine(new BudgetId(budgetId), userId, categories));

            DateTime last = DateTime.MinValue;

            foreach (var m in movements)
            {
                last = DateTime.Now;
                createLine(m.ToCreateLine(last, new BudgetId(budgetId), userId, categories));
            }


            var bp   = _pm.GetBudgetLinesProjection(budgetId);
            var galt = bp.GetAllLines(last);

            galt.Wait();
            var lines = galt.Result;

            Console.WriteLine("Loaded {0} movements into {1}", lines.Count(), budgetId);
        }