public CustomizeReportViewModel(CustomizeReportOptions cro, bool showCategoryTab, bool showTagsTab) { this.cro = cro; Initialize(); this.FromDate = cro.FromDate; this.ToDate = cro.ToDate; this.ShowCategoryTab = showCategoryTab; this.ShowTagsTab = showTagsTab; }
public void SyncCustomizeOptions(CustomizeReportOptions cro) { cro.FromDate = FromDate; cro.ToDate = ToDate; bool shiftsAllGood = cro.ShiftsAllGood = allShifts.FirstOrDefault(x => !x.IsChecked) == null; bool salesPersonsAllGood = cro.SalesPersonsAllGood = allSalesPersons.FirstOrDefault(x => !x.IsChecked) == null; bool categoriesAllGood = cro.CategoriesAllGood = allCategories.FirstOrDefault(x => !x.IsChecked) == null; bool tagsAllGood = cro.TagsAllGood = allTags.FirstOrDefault(x => !x.IsChecked) == null; cro.AllGood = shiftsAllGood && salesPersonsAllGood && categoriesAllGood && tagsAllGood; //admits no cro.AdmitsNoShift = allShifts[0].IsChecked; cro.AdmitsNoSalesPerson = allSalesPersons[0].IsChecked; cro.AdmitsNoCategory = allCategories[0].IsChecked; cro.AdmitsNoTag = allTags[0].IsChecked; using (var unitOfWork = base.GetNewUnitOfWork()) { //COPY SHIFT SELECTION cro.SelectedShifts.Clear(); foreach (var item in Shifts) { if (item.IsChecked) { if (item.Id == 0) { cro.AdmitsNoShift = true; } else { cro.SelectedShifts.Add(unitOfWork.ShiftRepository.GetById(item.Id)); } } } //COPY SALESPERSON SELECTION cro.SelectedSalesPersons.Clear(); foreach (var item in SalesPersons) { if (item.IsChecked) { if (item.Id == 0) { cro.AdmitsNoSalesPerson = true; } else { cro.SelectedSalesPersons.Add(unitOfWork.EmployeeRepository.GetById(item.Id)); } } } //COPY CATEGORY SELECTION cro.SelectedCategories.Clear(); foreach (var item in Categories) { if (item.IsChecked) { if (item.Id == 0) { cro.AdmitsNoCategory = true; } else { cro.SelectedCategories.Add(unitOfWork.CategoryRepository.GetById(item.Id)); } } } //COPY TAG SELECTION cro.SelectedTags.Clear(); foreach (var item in Tags) { if (item.IsChecked) { if (item.Id == 0) { cro.AdmitsNoTag = true; } else { cro.SelectedTags.Add(unitOfWork.TagRepository.GetById(item.Id)); } } } } }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { List <ReportLineViewModel> result = new List <ReportLineViewModel>(); var query = from item in filtered //orderby item.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)item.DayOfWeek group item by item.DayOfWeek; foreach (var dowGroup in query) { ReportLineViewModel lic = new ReportLineViewModel(); lic.DayOfWeek = dowGroup.Key; //MakeSum(dowGroup, lic); int days = dowGroup.GroupBy(x => x.Date).Count(); lic.Amount = dowGroup.Sum(x => x.Amount) / days; lic.Clients = dowGroup.Sum(x => x.Clients) / days; result.Add(lic); } return(result); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { return(filtered); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { var groupsByProduct = from item in filtered group item by item.Product; List <ReportLineViewModel> transformed = new List <ReportLineViewModel>(); double totalQtty = filtered.Sum(x => x.Quantity); foreach (var group in groupsByProduct) { ReportLineViewModel lic = new ReportLineViewModel(); lic.Product = group.Key; lic.Preference = group.Sum(x => x.Quantity) / totalQtty; MakeSum(group, lic); transformed.Add(lic); //salesByItemLines.Add(sbiLine); } double avePref = 0; decimal aveProfitMargin = 0; if (transformed.Count() == 0) { avePref = 0; aveProfitMargin = 0; } else { avePref = transformed.Average(x => x.Preference); aveProfitMargin = transformed.Average(x => x.ProfitMargin); } foreach (var item in transformed) { if (item.Preference >= avePref && item.ProfitMargin >= aveProfitMargin) { item.ProductClass = ProductClass.A; } else if (item.Preference >= avePref && item.ProfitMargin < aveProfitMargin) { item.ProductClass = ProductClass.B; } else if (item.Preference < avePref && item.ProfitMargin >= aveProfitMargin) { item.ProductClass = ProductClass.C; } else //if (item.Preference < avePref && item.ProfitMargin < aveProfitMargin) { item.ProductClass = ProductClass.D; } } return(transformed); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { int daysCount = filtered.GroupBy(x => x.Date.Date).Count(); int monthCount = filtered.GroupBy(x => x.Date.Month).Count(); List <ReportLineViewModel> result = new List <ReportLineViewModel>(); //group by month if (monthCount >= 3) { //months data var queryNestedGroups = from item in filtered group item by item.Date.Year into yearGroup from monthGroup in (from item in yearGroup orderby item.Date.Year, item.Date.Month group item by item.Date.Month) group monthGroup by yearGroup.Key; foreach (var yearGroup in queryNestedGroups) { foreach (var monthGroup in yearGroup) { ReportLineViewModel rLine = new ReportLineViewModel(); rLine.DateSpanString = monthGroup.First().Date.ToString("MMM/yyy"); MakeSum(monthGroup, rLine); result.Add(rLine); } } } //group by week else if (daysCount >= 21) { var query = from item in filtered group item by item.MondayDate; foreach (var weekGroup in query) { ReportLineViewModel rLine = new ReportLineViewModel(); rLine.DateSpanString = weekGroup.First().WeekString; MakeSum(weekGroup, rLine); result.Add(rLine); } } //group by date else { var query = from item in filtered group item by item.Date; foreach (var dateGroup in query) { ReportLineViewModel rLine = new ReportLineViewModel(); rLine.DateSpanString = dateGroup.Key.ToString("d/MMM"); MakeSum(dateGroup, rLine); result.Add(rLine); } } return(result); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { double projPct = cro.ProjectionPercent; List <ReportLineViewModel> transformed = new List <ReportLineViewModel>(); var queryProductGroups = from opi in filtered group opi by opi.Product; foreach (var productGroup in queryProductGroups) { var queryDowGroups = from line in productGroup group line by line.DayOfWeek; foreach (var dowGroup in queryDowGroups) { //create a line for each day of week ReportLineViewModel rivm = new ReportLineViewModel(); rivm.Product = productGroup.Key; //set date DayOfWeek dow = dowGroup.Key; int finalIndex = GetFinalIndex(dow); rivm.Date = DateTime.Today.AddDays(finalIndex); //group by date var queryDateGroups = from line in dowGroup group line by line.Date.Date; double min = double.MaxValue; double max = 0; double dowTotal = 0; List <double> dateTotals = new List <double>(); foreach (var dateGroup in queryDateGroups) { double dateTotal = dateGroup.Sum(x => x.Quantity * x.UnitMeasure.ToBaseConversion); if (dateTotal < min) { min = dateTotal; } if (dateTotal > max) { max = dateTotal; } dateTotals.Add(dateTotal); dowTotal += dateTotal; } //MIN rivm.MinimumQuantity = min; //rivm.MinQuantities[finalIndex] = min; //MAX rivm.MaximumQuantity = max; //rivm.MaxQuantities[finalIndex] = max; //AVERAGE //int numberofDays = innerGroup.Distinct(new SameDateComparer()).Count(); double averageInBase = dowTotal / queryDateGroups.Count(); rivm.AverageQuantity = averageInBase; //rivm.AveQuantities[finalIndex] = averageInBase;//Math.Round(tempQuantity, isQtty ? 0 : 1); //PROJECTED //rivm.ProjectedQuantity = averageInBase * (1 + projPct / 100); //rivm.ProjQuantities[finalIndex] = averageInBase * (1 + projPct / 100); if (rivm.Product.Name.Contains("Cerv.Cristal")) { Console.WriteLine(); } //CHANGE % rivm.ChangePercent = CalculateChangePercent(dateTotals); //add line transformed.Add(rivm); } }//outer foreach MakePretty(transformed); return(transformed.OrderBy(x => x.Product.Name).ToList()); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { var groupsByCategory = from item in filtered orderby item.CategoryName group item by item.Category; List <ReportLineViewModel> result = new List <ReportLineViewModel>(); foreach (var group in groupsByCategory) { ReportLineViewModel line = new ReportLineViewModel(); MakeSum(group, line); if (group.Key == null) { //UNCATEGORIZED line.CategoryName = "Sin CategorÃa"; //noCategoryLine.IsRootCategory = true; line.ChildrenProductsTotalSale = line.Amount; result.Add(line); } else { AddToCategoryBranch(line, group.Key, result, false); //lineitems_showing.Add(lic); } } return(result); }
private List <ReportLineViewModel> Filter(List <ReportLineViewModel> unfiltered, CustomizeReportOptions cro) { //filter data List <ReportLineViewModel> lines_filtered = new List <ReportLineViewModel>(); foreach (var item in unfiltered) { if (!OfflineFilter(item)) { continue; } if (!cro.AllGood && !CheckCustomizeReportOptions(item, cro)) { continue; } lines_filtered.Add(item); } return(lines_filtered); }
private bool CheckCustomizeReportOptions(ReportLineViewModel li, CustomizeReportOptions cro) { //PRODUCT TYPES //if (rType == ReportType.CostByItem || rType == ReportType.CostProjectionsByItem) //{ // if (li.ProductType != ProductType.RawMaterials && li.ProductType != ProductType.CompraVenta) return false; //} //else if (rType == ReportType.SalesProjectionsByItem) //{ // if (li.ProductType != ProductType.FinishedGoods && li.ProductType != ProductType.CompraVenta) return false; //} //else if (rType == ReportType.WIPByItem || rType == ReportType.WIPProjectionsByItem) //{ // if (li.ProductType != ProductType.WorkInProcess) return false; //} //CUSTOMIZE REPORT OPTIONS //SHIFTS if (!cro.ShiftsAllGood) { if (li.ShiftId == 0) { if (!cro.AdmitsNoShift) { return(false); } } else { if (cro.SelectedShifts.FirstOrDefault(x => x.Id == li.ShiftId) == null) { return(false); } } } //SALESPERSON if (!cro.SalesPersonsAllGood) { if (li.SalesPerson == null) { if (!cro.AdmitsNoSalesPerson) { return(false); } } else { if (cro.SelectedSalesPersons.FirstOrDefault(x => x.Id == li.SalesPerson.Id) == null) { return(false); } } } //CATEGORIES if (!IgnoreCategories && !cro.CategoriesAllGood) { if (li.Category == null) { if (!cro.AdmitsNoCategory) { return(false); } } else { if (cro.SelectedCategories.FirstOrDefault(x => x.Id == li.Category.Id) == null) { return(false); } } } //TAGS if (!IgnoreTags && !cro.TagsAllGood) { if (li.TagIds.Count == 0) { if (!cro.AdmitsNoTag) { return(false); } } else { if (cro.SelectedTags.Select(x => x.Id).Intersect(li.TagIds).Count() == 0) { return(false); } } } return(true); }
protected abstract List <ReportLineViewModel> Extract(IUnitOfWork unitOfWork, CustomizeReportOptions cro);
public List <ReportLineViewModel> GenerateReportData(IUnitOfWork unitOfWork, CustomizeReportOptions cro) { //Filter and Transform return(Load(Transform(Filter(Extract(unitOfWork, cro), cro), cro))); }
protected abstract List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro);
protected override List <ReportLineViewModel> Extract(IUnitOfWork unitOfWork, CustomizeReportOptions cro) { var queryService = ServiceContainer.GetService <IQueryService>(); return(queryService.GetSalesByItemData(unitOfWork, cro.FromDate, cro.ToDate, false)); }
protected override List <ReportLineViewModel> Extract(IUnitOfWork unitOfWork, CustomizeReportOptions cro) { throw new NotImplementedException(); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { var groupsByProduct = from item in filtered group item by item.Product; List <ReportLineViewModel> transformed = new List <ReportLineViewModel>(); foreach (var group in groupsByProduct) { ReportLineViewModel lic = new ReportLineViewModel(); lic.Product = group.Key; lic.ProductId = group.Key.Id; MakeSum(group, lic); transformed.Add(lic); } return(transformed); }
protected override List <ReportLineViewModel> Transform(List <ReportLineViewModel> filtered, CustomizeReportOptions cro) { List <ReportLineViewModel> result = new List <ReportLineViewModel>(); var query = from sale in filtered group sale by sale.SalesPerson; foreach (var salesPersonGroup in query) { ReportLineViewModel line = new ReportLineViewModel(); if (salesPersonGroup.Key == null) { //NO SALESPERSON line.SalesPersonName = "Sin Dependiente"; } else { line.SalesPerson = salesPersonGroup.Key; line.SalesPersonName = salesPersonGroup.Key.Name; } MakeSum(salesPersonGroup, line); result.Add(line); } return(result); }