private static void SalesReportTest()
        {
            FakeOrdersService   ordersService = new FakeOrdersService();
            IEnumerable <Order> orders        = ordersService.Get();

            SalesReport salesReport = new SalesReport();


            // Header
            salesReport.Title            = "Raport sprzedaży";
            salesReport.CreateDate       = DateTime.Now;
            salesReport.TotalSalesAmount = orders.Sum(s => s.Amount);


            // By Gender
            salesReport.GenderDetails = orders
                                        .GroupBy(o => o.Customer.Gender)
                                        .Select(g => new GenderReportDetail(
                                                    g.Key,
                                                    g.Sum(x => x.Details.Sum(d => d.Quantity)),
                                                    g.Sum(x => x.Details.Sum(d => d.LineTotal))));

            // By Product
            salesReport.ProductDetails = orders
                                         .SelectMany(o => o.Details)
                                         .GroupBy(o => o.Product)
                                         .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal)));

            Console.WriteLine(salesReport);
        }
Example #2
0
        public SalesReport Build()
        {
            SalesReport salesReport = new SalesReport();

            // Header
            if (!string.IsNullOrEmpty(title))
            {
                salesReport.Title            = title;
                salesReport.CreateDate       = DateTime.Now;
                salesReport.TotalSalesAmount = orders.Sum(s => s.Amount);
            }

            // Section By Gender
            if (hasSectionByGender)
            {
                salesReport.GenderDetails = orders
                                            .GroupBy(o => o.Customer.Gender)
                                            .Select(g => new GenderReportDetail(
                                                        g.Key,
                                                        g.Sum(x => x.Details.Sum(d => d.Quantity)),
                                                        g.Sum(x => x.Details.Sum(d => d.LineTotal))));
            }

            // Section By Product
            if (hasSectionByProduct)
            {
                salesReport.ProductDetails = orders
                                             .SelectMany(o => o.Details)
                                             .GroupBy(o => o.Product)
                                             .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal)));
            }

            return(salesReport);
        }
Example #3
0
        // Create product
        public SalesReportBase Build()
        {
            SalesReport salesReport = new SalesReport();

            if (hasHeader)
            {
                salesReport.Title            = "Raport sprzedaży";
                salesReport.CreateDate       = DateTime.Now;
                salesReport.TotalSalesAmount = orders.Sum(s => s.Amount);
            }

            if (hasGenderTotals)
            {
                salesReport.GenderDetails = orders
                                            .GroupBy(o => o.Customer.Gender)
                                            .Select(g => new GenderReportDetail(
                                                        g.Key,
                                                        g.Sum(x => x.Details.Sum(d => d.Quantity)),
                                                        g.Sum(x => x.Details.Sum(d => d.LineTotal))));
            }

            if (hasProductTotals)
            {
                salesReport.ProductDetails = orders
                                             .SelectMany(o => o.Details)
                                             .GroupBy(o => o.Product)
                                             .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal)));
            }

            return(salesReport);
        }
        public SalesReport Build()
        {
            SalesReport result = salesReport;

            salesReport = null;

            return(result);
        }
        private static void SalesReportBuilderTest()
        {
            FakeOrdersService   ordersService      = new FakeOrdersService();
            IEnumerable <Order> orders             = ordersService.Get();
            ISalesReportBuilder salesReportBuilder = new SalesReportBuilder(orders);

            salesReportBuilder.AddHeader();
            salesReportBuilder.AddSectionByGender();
            salesReportBuilder.AddSectionByProduct();

            SalesReport salesReport = salesReportBuilder.Build();
        }
Example #6
0
        private static void SalesReportTest()
        {
            FakeOrdersService   ordersService = new FakeOrdersService();
            IEnumerable <Order> orders        = ordersService.Get();

            ISalesReportBuilder salesReportBuilder = new MySalesReportBuilder(orders);

            salesReportBuilder.AddHeader("Raport sprzedaży");
            salesReportBuilder.AddSectionByGender();
            salesReportBuilder.AddSectionByProduct();

            SalesReport salesReport = salesReportBuilder.Build();

            Console.WriteLine(salesReport);
        }
Example #7
0
        public SalesReport Build()
        {
            SalesReport salesReport = new SalesReport();

            if (hasHeader)
            {
                CreateHeader(salesReport);
            }

            if (hasSectionByGender)
            {
            }

            return(salesReport);
        }
Example #8
0
        private static void SalesReportTest()
        {
            FakeOrdersService   ordersService = new FakeOrdersService();
            IEnumerable <Order> orders        = ordersService.Get();

            ISalesReportBuilder salesReportBuilder = new SalesReportBuilder(orders);

            salesReportBuilder.AddHeader();

            if (true)
            {
                salesReportBuilder.AddSectionByGender();
            }


            salesReportBuilder.AddSectionByProduct();

            SalesReport salesReport = salesReportBuilder.Build();


            //SalesReport salesReport = new SalesReport();
            //salesReport.Title = "Raport sprzedaży";
            //salesReport.CreateDate = DateTime.Now;
            //salesReport.TotalSalesAmount = orders.Sum(s => s.Amount);

            //salesReport.GenderDetails = orders
            //    .GroupBy(o => o.Customer.Gender)
            //    .Select(g => new GenderReportDetail(
            //                g.Key,
            //                g.Sum(x => x.Details.Sum(d => d.Quantity)),
            //                g.Sum(x => x.Details.Sum(d => d.LineTotal))));

            //salesReport.ProductDetails = orders
            //    .SelectMany(o => o.Details)
            //    .GroupBy(o => o.Product)
            //    .Select(g => new ProductReportDetail(g.Key, g.Sum(p => p.Quantity), g.Sum(p => p.LineTotal)));

            Console.WriteLine(salesReport);
        }
Example #9
0
        private static void SalesReportTest()
        {
            bool hasSectionByGender = true;

            FakeOrdersService   ordersService = new FakeOrdersService();
            IEnumerable <Order> orders        = ordersService.Get();

            ISalesReportBuilder salesReportBuilder = new MySalesReportBuilder(orders);

            salesReportBuilder.AddHeader();

            if (hasSectionByGender)
            {
                salesReportBuilder.AddSectionByGender();
            }

            salesReportBuilder.AddSectionByProduct();

            SalesReport salesReport = salesReportBuilder.Build();

            Console.WriteLine(salesReport);
        }
 private SalesReportBuilder()
 {
     salesReport = new SalesReport();
 }
Example #11
0
        public SalesReportBuilder(IEnumerable <Order> orders)
        {
            this.orders = orders;

            salesReport = new SalesReport();
        }
Example #12
0
 private void CreateHeader(SalesReport salesReport)
 {
     salesReport.Title            = "Raport sprzedaży";
     salesReport.CreateDate       = DateTime.Now;
     salesReport.TotalSalesAmount = orders.Sum(s => s.Amount);
 }