Beispiel #1
0
        public void ImportCategoriesByName(IEnumerable <string> categoryNames, string budgetId, string userId)
        {
            var cp             = _projectionManager.GetCategories();
            var createCategory = _commandManager.Create <CreateCategory>();

            DateTime lastUpdate = cp.LastUpdate;
            var      cleaned    = categoryNames.Select(s => s.Trim().Replace((char)160, ' ')).Distinct(StringComparer.CurrentCultureIgnoreCase)
                                  .OrderBy(d => d)
                                  .ToList();

            foreach (var categoryName in cleaned)
            {
                var task = cp.GetBudgetsCategories(budgetId, lastUpdate);
                task.Wait();
                if (task.Result.Any(r => string.Compare(r.Name, categoryName, true) == 0) == false)
                {
                    lastUpdate = DateTime.Now;
                    System.Diagnostics.Debug.Assert(lastUpdate > cp.LastUpdate);
                    createCategory(new CreateCategory
                    {
                        Id                  = Guid.NewGuid(),
                        Timestamp           = lastUpdate,
                        BudgetId            = budgetId,
                        CategoryId          = "Category-" + Guid.NewGuid(),
                        UserId              = userId,
                        CategoryDescription = "",
                        CategoryName        = categoryName
                    });
                }
            }

            //cp.GetBudgetsCategories(budgetId, lastUpdate).Wait();
        }
        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 #3
0
        public virtual ActionResult Edit(string budgetId, string lineId)
        {
            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(new Domain.Budgets.BudgetId(budgetId));
            var budget     = ProjectionManager.GetBudgetsList().GetBudgetById(new Domain.Budgets.BudgetId(budgetId));

            var model = new EditBudgetLineViewModel(budget.Name, budget.Id, budget.CurrencyISOCode, ProjectionManager.GetStreamEvents(lineId), categories, budget.GetDistributionKeys(), Currencies.GetAll());

            return(View(model));
        }
        public virtual ActionResult ByDistribution(string budgetId)
        {
            var budget = ProjectionManager.GetBudgetProjection(budgetId);

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

            var model = new DistributionTimeViewModel(budgetId, budget, categories);

            return(View(model));
        }
Beispiel #5
0
        EditBudgetLineViewModel Prepare_EditBudgetLineViewModel(string id)
        {
            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(new Domain.Budgets.BudgetId(id));
            var budget     = ProjectionManager.GetBudgetsList().GetBudgetById(new Domain.Budgets.BudgetId(id));

            var model = new EditBudgetLineViewModel(budget.Name, id, budget.CurrencyISOCode, categories, budget.GetDistributionKeys(),
                                                    Currencies.GetAll());

            return(model);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public virtual ActionResult Details(string id)
        {
            var budgetId   = new BudgetId(id);
            var budget     = ProjectionManager.GetBudgetsList().GetBudgetById(budgetId);
            var categories = ProjectionManager.GetCategories().GetBudgetsCategories(budgetId);

            var model = new BudgetDetailsViewModel
            {
                Budget           = budget,
                Categories       = categories,
                DistributionKeys = budget.GetDistributionKeys(),
            };

            return(View(model));
        }
Beispiel #8
0
        public virtual ActionResult Edit(string budgetId, string categoryId)
        {
            var bid      = new Domain.Budgets.BudgetId(budgetId);
            var category = ProjectionManager.GetCategories().GetBudgetsCategories(bid)
                           .Single(r => r.Id == categoryId);
            var budget = ProjectionManager.GetBudgetsList().GetBudgetById(bid);
            var model  = new CategoryViewModel
            {
                Id          = categoryId,
                BudgetId    = budgetId,
                BudgetName  = budget.Name,
                Description = category.Description,
                Name        = category.Name,
            };

            return(View(model));
        }
        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 #10
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));
        }
Beispiel #11
0
        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);
        }