Ejemplo n.º 1
0
        private void UpdataDataByDateRange()
        {
            _saleCollection = _model.Sales.ToList().FindAll(new Predicate <object>(FilterByDateRange));
            _saleCollection.Sort(new SaleComparer());
            _budgetCollection         = _model.Budget.ToList().FindAll(new Predicate <object>(FilterByDateRange));
            _opportunityCollection    = _model.Opportunities.ToList().FindAll(new Predicate <object>(FilterByDateRange));
            _regionWiseSaleCollection = _model.RegionWiseSales.ToList().FindAll(new Predicate <object>(FilterByDateRange));
            _regionSaleGoalCollection = _model.RegionSales.ToList().FindAll(new Predicate <object>(FilterByDateRange));
            _opportunityList          = new List <Opportunity>();
            foreach (OpportunityLevel value in Enum.GetValues(typeof(OpportunityLevel)))
            {
                _opportunityList.Add(new Opportunity {
                    Level = value, Sales = 0
                });
            }

            var campainTaskItems = new List <CampainTaskItem>();
            var productSaleMap   = new Dictionary <int, SaleItem>();
            var customerSaleMap  = new Dictionary <int, SaleItem>();

            foreach (var sale in _saleCollection)
            {
                var profit  = FindProfitFormCurrentSale(_model, sale);
                var campain = _model.Campaigns.First(x => x.Id == sale.CampaignId);
                if (campain.Name != "None")
                {
                    campainTaskItems.Add(new CampainTaskItem(_model, sale));
                }

                if (customerSaleMap.ContainsKey(sale.CustomerId))
                {
                    customerSaleMap[sale.CustomerId].Sales  += sale.Summ;
                    customerSaleMap[sale.CustomerId].Profit += profit;
                }
                else
                {
                    var customer = sale.GetCustomer(_model);
                    customerSaleMap.Add(sale.CustomerId, new SaleItem {
                        Id = sale.CustomerId, Sales = sale.Summ, Profit = profit, Name = customer.ToString(), Date = sale.Date
                    });
                }

                if (productSaleMap.ContainsKey(sale.ProductId))
                {
                    productSaleMap[sale.ProductId].Sales  += sale.Summ;
                    productSaleMap[sale.ProductId].Profit += profit;
                }
                else
                {
                    var product = sale.GetProduct(_model);
                    productSaleMap.Add(sale.ProductId, new SaleItem {
                        Id = sale.ProductId, Sales = sale.Summ, Profit = profit, Name = product.ToString(), Date = sale.Date
                    });
                }
            }

            var regionSaleMap   = new Dictionary <int, SaleGoalItem>();
            var categorySaleMap = new Dictionary <int, SaleGoalItem>();

            foreach (var budget in _budgetCollection)
            {
                if (categorySaleMap.ContainsKey(budget.CategoryId))
                {
                    categorySaleMap[budget.CategoryId].Sales  += budget.Sales;
                    categorySaleMap[budget.CategoryId].Profit += budget.Profit;
                    categorySaleMap[budget.CategoryId].Goal   += budget.Goal;
                }
                else
                {
                    var item     = new SaleGoalItem();
                    var category = _model.Categories.First(x => x.Id == budget.CategoryId);
                    item.Name   = category.ToString();
                    item.Goal   = budget.Goal;
                    item.Sales  = budget.Sales;
                    item.Profit = budget.Profit;
                    categorySaleMap.Add(budget.CategoryId, item);
                }
            }

            foreach (var region in _regionSaleGoalCollection)
            {
                if (regionSaleMap.ContainsKey(region.RegionId))
                {
                    regionSaleMap[region.RegionId].Sales  += region.Sales;
                    regionSaleMap[region.RegionId].Profit += region.Profit;
                    regionSaleMap[region.RegionId].Goal   += region.Goal;
                }
                else
                {
                    var item      = new SaleGoalItem();
                    var objRegion = _model.Regions.First(x => x.Id == region.RegionId);
                    item.Name   = objRegion.ToString();
                    item.Goal   = region.Goal;
                    item.Sales  = region.Sales;
                    item.Profit = region.Profit;
                    regionSaleMap.Add(region.RegionId, item);
                }
            }

            _campainTaskCollection = new List <CampainTaskItem>(campainTaskItems);
            _productSaleCollection = new List <SaleItem>(productSaleMap.Values.ToList());
            _productSaleCollection.Sort(new SaleItemComparer());
            _customerSaleCollection = new List <SaleItem>(customerSaleMap.Values.ToList());
            _customerSaleCollection.Sort(new SaleItemComparer());
            _regionSalesVsGoal   = regionSaleMap.Values.ToList();
            _categorySalesVsGoal = categorySaleMap.Values.ToList();
            foreach (var opportunity in _opportunityCollection)
            {
                OpportunityItemList[opportunity.LevelId].Sales += opportunity.Sales;
            }
        }
Ejemplo n.º 2
0
        public async Task UpdataDataByDateRangeAsync()
#endif
        {
#if !XF
            saleCollection.Filter = new Predicate <object>(FilterByDateRange);
            saleCollection.SortDescriptions.Add(new SortDescription("Date", ListSortDirection.Ascending));
            budgetCollection.Filter         = new Predicate <object>(FilterByDateRange);
            opportunityCollection.Filter    = new Predicate <object>(FilterByDateRange);
            regionWiseSaleCollection.Filter = new Predicate <object>(FilterByDateRange);
            regionSaleGoalCollection.Filter = new Predicate <object>(FilterByDateRange);
#else
            await saleCollection.FilterAsync(FilterByDateRange);

            await saleCollection.SortAsync("Date");

            await budgetCollection.FilterAsync(FilterByDateRange);

            await opportunityCollection.FilterAsync(FilterByDateRange);

            await regionWiseSaleCollection.FilterAsync(FilterByDateRange);

            await regionSaleGoalCollection.FilterAsync(FilterByDateRange);
#endif
            opportunityList = new List <Opportunity>();
            foreach (OpportunityLevel value in Enum.GetValues(typeof(OpportunityLevel)))
            {
                opportunityList.Add(new Opportunity {
                    Level = value, Sales = 0
                });
            }


            var campainTaskItems = new List <CampainTaskItem>();
            var productSaleMap   = new Dictionary <int, SaleItem>();
            var customerSaleMap  = new Dictionary <int, SaleItem>();

            foreach (Sale sale in saleCollection)
            {
                var profit = DataService.GetService().FindProfitFormCurrentSale(sale);
                if (sale.Campaign.Name != "None")
                {
                    campainTaskItems.Add(new CampainTaskItem(sale));
                }
                if (customerSaleMap.ContainsKey(sale.CustomerId))
                {
                    customerSaleMap[sale.CustomerId].Sales  += sale.Summ;
                    customerSaleMap[sale.CustomerId].Profit += profit;
                }
                else
                {
                    customerSaleMap.Add(sale.CustomerId, new SaleItem {
                        Id = sale.CustomerId, Sales = sale.Summ, Profit = profit, Name = sale.Customer.ToString(), Date = sale.Date
                    });
                }
                if (productSaleMap.ContainsKey(sale.ProductId))
                {
                    productSaleMap[sale.ProductId].Sales  += sale.Summ;
                    productSaleMap[sale.ProductId].Profit += profit;
                }
                else
                {
                    productSaleMap.Add(sale.ProductId, new SaleItem {
                        Id = sale.ProductId, Sales = sale.Summ, Profit = profit, Name = sale.Product.ToString(), Date = sale.Date
                    });
                }
            }

            var regionSaleMap   = new Dictionary <int, SaleGoalItem>();
            var categorySaleMap = new Dictionary <int, SaleGoalItem>();

            foreach (BudgetItem budget in budgetCollection)
            {
                if (categorySaleMap.ContainsKey(budget.CategoryId))
                {
                    categorySaleMap[budget.CategoryId].Sales  += budget.Sales;
                    categorySaleMap[budget.CategoryId].Profit += budget.Profit;
                    categorySaleMap[budget.CategoryId].Goal   += budget.Goal;
                }
                else
                {
                    SaleGoalItem item = new SaleGoalItem();
                    item.Name   = budget.Category.ToString();
                    item.Goal   = budget.Goal;
                    item.Sales  = budget.Sales;
                    item.Profit = budget.Profit;
                    categorySaleMap.Add(budget.CategoryId, item);
                }
            }
            foreach (RegionSalesGoal region in regionSaleGoalCollection)
            {
                if (regionSaleMap.ContainsKey(region.RegionId))
                {
                    regionSaleMap[region.RegionId].Sales  += region.Sales;
                    regionSaleMap[region.RegionId].Profit += region.Profit;
                    regionSaleMap[region.RegionId].Goal   += region.Goal;
                }
                else
                {
                    SaleGoalItem item = new SaleGoalItem();
                    item.Name   = region.Region.ToString();
                    item.Goal   = region.Goal;
                    item.Sales  = region.Sales;
                    item.Profit = region.Profit;
                    regionSaleMap.Add(region.RegionId, item);
                }
            }
#if !XF
            campainTaskCollection        = new ListCollectionView(campainTaskItems);
            campainTaskCollection.Filter = new Predicate <object>(FilterByCampainTaskType);
            productSaleCollection        = new ListCollectionView(productSaleMap.Values.ToList());
            productSaleCollection.SortDescriptions.Add(new SortDescription("Sales", ListSortDirection.Descending));
            customerSaleCollection = new ListCollectionView(customerSaleMap.Values.ToList());
            customerSaleCollection.SortDescriptions.Add(new SortDescription("Sales", ListSortDirection.Descending));
#else
            campainTaskCollection = new C1CollectionView <CampainTaskItem>(campainTaskItems);
            await campainTaskCollection.FilterAsync(FilterByCampainTaskType);

            productSaleCollection = new C1CollectionView <SaleItem>(productSaleMap.Values.ToList());
            await productSaleCollection.SortAsync("Sales", SortDirection.Descending);

            customerSaleCollection = new C1CollectionView <SaleItem>(customerSaleMap.Values.ToList());
            await customerSaleCollection.SortAsync("Sales", SortDirection.Descending);
#endif
            regionSalesVsGoal   = regionSaleMap.Values.ToList();
            categorySalesVsGoal = categorySaleMap.Values.ToList();

            foreach (OpportunityItem opportunity in opportunityCollection)
            {
                OpportunityItemList[opportunity.LevelId].Sales += opportunity.Sales;
            }
        }