public ReportResponsePayload oneMonthReportQuantity(List <RequisitionDetail> requisitionDetails, int month) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); month++; // month integer in months is indexed from 0 // Get list of departments from requisition details List <Department> departments = requisitionDetails .Select(d => d.Requisition.Requester.Department) .Distinct() .OrderBy(d => d.DepartmentName) .ToList(); // Get years required for data generation. If month has not past for current year, start // from 4 years ago, if month has past for current year, start for month of this year reportResponsePayload.labels = new List <string>(); int excludeCurrentYear = month > DateTime.Today.Month ? 1 : 0; for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddYears(-i - excludeCurrentYear).Year.ToString()); } reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Department d in departments) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = d.DepartmentName; reportDataPayload.backgroundColor = colors[departments.IndexOf(d)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int year = DateTime.Today.AddYears(-i - excludeCurrentYear).Year; decimal?sum = requisitionDetails .Where(rd => rd.Requisition.Requester.DepartmentID == d.DepartmentID && rd.Requisition.RequestedDate.HasValue && rd.Requisition.RequestedDate.Value.Month == month && rd.Requisition.RequestedDate.Value.Year == year) .Sum(rd => rd.Quantity); chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }
public ReportResponsePayload oneMonthReport(List <OrderSupplierDetail> orderSupplierDetails, int month) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); month++; // month integer in months is indexed from 0 // Get list of suppliers from orderSupplierDetails List <Supplier> suppliers = orderSupplierDetails .Select(s => s.OrderSupplier.Supplier) .Distinct() .OrderBy(s => s.SupplierName) .ToList(); // Get years required for data generation. If month has not past for current year, start // from 4 years ago, if month has past for current year, start for month of this year reportResponsePayload.labels = new List <string>(); int excludeCurrentYear = month > DateTime.Today.Month ? 1 : 0; for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddYears(-i - excludeCurrentYear).Year.ToString()); } reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Supplier s in suppliers) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = s.SupplierName; reportDataPayload.backgroundColor = colors[suppliers.IndexOf(s)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int year = DateTime.Today.AddYears(-i - excludeCurrentYear).Year; decimal?sum = orderSupplierDetails .Where(si => si.OrderSupplier.SupplierID == s.SupplierID && si.OrderSupplier.Order.OrderDate.Year == year && si.OrderSupplier.Order.OrderDate.Month == month) .Sum(si => si.UnitCost * si.ActualQuantityReceived); chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }
public ReportResponsePayload pastThreeMonthsReport(List <OrderSupplierDetail> orderSupplierDetails) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); // get distinct list of suppliers from orderSupplierDetails List <Supplier> suppliers = orderSupplierDetails .Select(s => s.OrderSupplier.Supplier) .Distinct() .OrderBy(s => s.SupplierName) .ToList(); // Prepare the list of months to generate data for reportResponsePayload.labels = new List <string>(); for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddMonths(-i).ToString("MMMM")); } // Prepare the dataset to be displayed on web reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Supplier s in suppliers) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = s.SupplierName; reportDataPayload.backgroundColor = colors[suppliers.IndexOf(s)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int month = DateTime.Today.AddMonths(-i).Month; decimal?sum = orderSupplierDetails .Where(si => si.OrderSupplier.SupplierID == s.SupplierID && si.OrderSupplier.Order.OrderDate.Month == month) .Sum(si => si.UnitCost * si.ActualQuantityReceived); chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }
public ReportResponsePayload pastThreeMonthsReportQuantity(List <RequisitionDetail> requisitionDetails) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); //Distinct list of departments List <Department> departments = requisitionDetails .Select(d => d.Requisition.Requester.Department) .Distinct().OrderBy(d => d.DepartmentName) .ToList(); reportResponsePayload.labels = new List <string>(); for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddMonths(-i).ToString("MMMM")); } reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Department d in departments) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = d.DepartmentName; reportDataPayload.backgroundColor = colors[departments.IndexOf(d)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int month = DateTime.Today.AddMonths(-i).Month; //summing up the quantitities filtered based on department id,month chosen decimal?sum = requisitionDetails .Where(rd => rd.Requisition.Requester.DepartmentID == d.DepartmentID && rd.Requisition.RequestedDate.HasValue && rd.Requisition.RequestedDate.Value.Month == month) .Sum(rd => rd.Quantity); chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }
//One month report for requisition cost analysis public ReportResponsePayload oneMonthReport(List <RequisitionDetail> requisitionDetails, int month) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); month++; // month integer in months is indexed from 0 // Get list of departments from requisition details List <Department> departments = requisitionDetails .Select(d => d.Requisition.Requester.Department) .Distinct() .OrderBy(d => d.DepartmentName) .ToList(); // Get years required for data generation. If month has not past for current year, start // from 4 years ago, if month has past for current year, start for month of this year reportResponsePayload.labels = new List <string>(); int excludeCurrentYear = month > DateTime.Today.Month ? 1 : 0; for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddYears(-i - excludeCurrentYear).Year.ToString()); } reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Department d in departments) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = d.DepartmentName; reportDataPayload.backgroundColor = colors[departments.IndexOf(d)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int year = DateTime.Today.AddYears(-i - excludeCurrentYear).Year; int j = 0; List <RequisitionDetail> newList = requisitionDetails .Where(r => r.Requisition.RequestedDate.HasValue && r.Requisition.RequestedDate.Value.Month == month && r.Requisition.Requester.DepartmentID == d.DepartmentID && r.Requisition.RequestedDate.Value.Year == year) .ToList(); var count = newList.Where(ri => ri.Quantity > 0).Count(); int[] quantity = new int[count]; decimal?[] cost = new decimal?[count]; SupplierItem supItem = new SupplierItem(); foreach (RequisitionDetail rdetail in newList) { quantity[j] = rdetail.Quantity; supItem = context.SupplierItems.Where(s => s.Rank == 1 && s.ItemID == rdetail.ItemID).FirstOrDefault(); cost[j] = (supItem.Cost == null) ? (decimal?)null : Convert.ToDecimal(supItem.Cost); j++; } decimal?sum = 0; for (int m = 0; m < newList.Count; m++) { sum = sum + cost[m] * quantity[m]; } chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }
public ReportResponsePayload pastThreeMonthsReport(List <RequisitionDetail> requisitionDetails) { ReportResponsePayload reportResponsePayload = new ReportResponsePayload(); //Distinct list of departments List <Department> departments = requisitionDetails .Select(d => d.Requisition.Requester.Department) .Distinct().OrderBy(d => d.DepartmentName) .ToList(); reportResponsePayload.labels = new List <string>(); for (int i = 3; i >= 0; i--) { reportResponsePayload.labels.Add(DateTime.Today.AddMonths(-i).ToString("MMMM")); } reportResponsePayload.datasets = new List <ReportDataPayload>(); ReportDataPayload reportDataPayload; foreach (Department d in departments) { reportDataPayload = new ReportDataPayload(); reportDataPayload.label = d.DepartmentName; reportDataPayload.backgroundColor = colors[departments.IndexOf(d)]; List <decimal> chartValues = new List <decimal>(); for (int i = 3; i >= 0; i--) { int j = 0; int month = DateTime.Today.AddMonths(-i).Month; List <RequisitionDetail> newList = new List <RequisitionDetail>(); newList = requisitionDetails .Where(r => r.Requisition.RequestedDate.HasValue && r.Requisition.RequestedDate.Value.Month == month && r.Requisition.Requester.DepartmentID.Equals(d.DepartmentID)) .ToList(); var count = newList.Where(ri => ri.Quantity > 0).Count(); int[] quantity = new int[count]; decimal?[] cost = new decimal?[count]; SupplierItem supItem = new SupplierItem(); foreach (RequisitionDetail rdetail in newList) { quantity[j] = rdetail.Quantity; supItem = context.SupplierItems.Where(s => s.Rank == 1 && s.ItemID == rdetail.ItemID).FirstOrDefault(); cost[j] = (supItem.Cost == null) ? (decimal?)null : Convert.ToDecimal(supItem.Cost); j++; } decimal?sum = 0; for (int m = 0; m < newList.Count; m++) { sum = sum + cost[m] * quantity[m]; } chartValues.Add(sum == null ? 0 : (decimal)sum); } reportDataPayload.data = chartValues; reportResponsePayload.datasets.Add(reportDataPayload); } return(reportResponsePayload); }