Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        //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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        static void Main(string[] args)
        {
            IReportService          reportService = new ReportService();
            StationeryStoreEntities context       = StationeryStoreEntities.Instance;

            // Test 1
            // Reorder Cost Report last 3 months
            //    Console.WriteLine("=== Test generateReorderCostReport ===");
            //   Console.WriteLine("1. PastThreeMonths report");

            // set up reorder request payload
            ReorderRequestPayload reqPayload = new ReorderRequestPayload();

            //reqPayload.category = 1;
            //reqPayload.department = new List<string> { "ALPA" };
            //reqPayload.duration = "PastThreeMonths";
            //reqPayload.option = null;

            //// Test
            // ReportResponsePayload respPayload = reportService.generateReorderCostReport(reqPayload);
            //Console.WriteLine(respPayload.labels[0]);
            //Console.WriteLine(respPayload.datasets[0].label);
            //Console.WriteLine(respPayload.datasets[0].backgroundColor);
            //respPayload.datasets[0].data.ForEach(d => Console.WriteLine(d));

            //Test for one month report

            //Console.WriteLine("1. One month report");
            //reqPayload.category = 1;
            //reqPayload.department = new List<string> { "ALPA" };
            //reqPayload.duration = "OneMonth";
            //reqPayload.option = new List<int> { 0 };

            //ReportResponsePayload respPayload = reportService.generateReorderCostReport(reqPayload);
            //Console.WriteLine(respPayload.labels[0]);

            //Console.WriteLine(respPayload.datasets[0].label);
            //Console.WriteLine(respPayload.datasets[0].backgroundColor);
            //respPayload.datasets[0].data.ForEach(d => Console.WriteLine(d));

            // Test 2
            // Requisition Cost Report last 3 months
            Console.WriteLine("=== Test generateRequisitionCostReport ===");
            //  Console.WriteLine("1. PastThreeMonths report");

            // set up requistion request payload
            RequisitionRequestPayload reqPayload1 = new RequisitionRequestPayload();

            reqPayload1.category   = 2;
            reqPayload1.department = new List <string> {
                "CHEM"
            };
            reqPayload1.duration = "PastThreeMonths";
            reqPayload1.option   = null;


            // Test
            ReportResponsePayload respPayload1 = reportService.generateRequisitionCostReport(reqPayload1);

            Console.WriteLine(respPayload1.labels[0]);
            Console.WriteLine(respPayload1.datasets[0].label);
            Console.WriteLine(respPayload1.datasets[0].backgroundColor);
            respPayload1.datasets[0].data.ForEach(d => Console.WriteLine(d));

            //Console.WriteLine("2. One month report");
            // RequisitionRequestPayload reqPayload1 = new RequisitionRequestPayload();

            //reqPayload1.category = 2;
            //reqPayload1.department = new List<string> { "CHEM" };
            //reqPayload1.duration = "OneMonth";
            //reqPayload1.option = new List<int> { 7 };


            // Test

            //ReportResponsePayload respPayload1 = reportService.generateRequisitionCostReport(reqPayload1);
            //Console.WriteLine(respPayload1.labels[0]);
            //Console.WriteLine(respPayload1.datasets[0].label);
            //Console.WriteLine(respPayload1.datasets[0].backgroundColor);
            //respPayload1.datasets[0].data.ForEach(d => Console.WriteLine(d));

            // Test 3
            // Requisition Quantity Report last 3 months
            Console.WriteLine("=== Test generateRequisitionQuantityReport ===");
            // Console.WriteLine("1. PastThreeMonths report");
            RequisitionItemPayload reqPayload2 = new RequisitionItemPayload();
            //reqPayload2.item = "T100";
            //reqPayload2.department = new List<string> { "CHEM" };
            //reqPayload2.duration = "PastThreeMonths";
            //reqPayload2.option = new List<int> { 7 };
            //reqPayload2.compareElement = "1";

            //ReportResponsePayload respPayload2 = reportService.generateRequisitionItemReport(reqPayload2);
            //Console.WriteLine(respPayload2.labels[0]);
            //Console.WriteLine(respPayload2.datasets[0].label);
            //Console.WriteLine(respPayload2.datasets[0].backgroundColor);
            //respPayload2.datasets[0].data.ForEach(d => Console.WriteLine(d));

            //Console.WriteLine("1. Onemonth report");
            //reqPayload2.item = "E006";
            //reqPayload2.department = new List<string> { "CHEM" };
            //reqPayload2.duration = "OneMonth";
            //reqPayload2.option = new List<int> { 8 };
            //reqPayload2.compareElement = "Costs";
            //ReportResponsePayload respPayload2 = reportService.generateRequisitionItemReport(reqPayload2);
            //Console.WriteLine(respPayload2.labels[0]);
            //Console.WriteLine(respPayload2.datasets[0].label);
            //Console.WriteLine(respPayload2.datasets[0].backgroundColor);
            //respPayload2.datasets[0].data.ForEach(d => Console.WriteLine(d));
        }