예제 #1
0
        public List <List <ProductSales> > GetProductSalesDetailsForSelectedDate(DateTime fromDate, DateTime toDate)
        {
            List <List <ProductSales> >     productSales = new List <List <ProductSales> >();
            List <RetailBillSalesDetail>    retail       = new List <RetailBillSalesDetail>(accessDB.RetrieveAllRetailProductSalesDetails());
            List <WholeSaleBillSalesDetail> wholesale    = new List <WholeSaleBillSalesDetail>(accessDB.RetrieveAllWholesaleProductSalesDetails());
            List <CreditBillSalesDetail>    credit       = new List <CreditBillSalesDetail>(accessDB.RetrieveAllCreditProductSalesDetails());

            if (retail != null && retail.Count > 0)
            {
                productSales.AddRange(retail.Where(obj => obj.SoldDate.Date >= fromDate.Date && obj.SoldDate.Date <= toDate.Date)
                                      .GroupBy(obj => new { obj.ProductId, obj.SoldDate.Date })
                                      .OrderBy(obj => obj.Key.Date)
                                      .ThenBy(obj => obj.Key.ProductId)
                                      .Select(obj => obj.Select(o => new ProductSales
                {
                    BillType    = "Retail",
                    Date        = o.SoldDate,
                    ProductId   = o.ProductId,
                    ProductName = o.ProductName,
                    Quantity    = o.Quantity,
                    BillAmount  = o.BillAmount,
                    GstAmount   = o.GSTAmount,
                    TotalAmount = o.TotalAmount
                }).ToList()).ToList());
            }
            if (wholesale != null && wholesale.Count > 0)
            {
                productSales.AddRange(wholesale.Where(obj => obj.SoldDate.Date >= fromDate.Date && obj.SoldDate.Date <= toDate.Date)
                                      .GroupBy(obj => new { obj.ProductId, obj.SoldDate.Date })
                                      .OrderBy(obj => obj.Key.Date)
                                      .ThenBy(obj => obj.Key.ProductId)
                                      .Select(obj => obj.Select(o => new ProductSales
                {
                    BillType    = "WholeSale",
                    Date        = o.SoldDate,
                    ProductId   = o.ProductId,
                    ProductName = o.ProductName,
                    Quantity    = o.Quantity,
                    BillAmount  = o.BillAmount,
                    GstAmount   = o.GSTAmount,
                    TotalAmount = o.TotalAmount
                }).ToList()).ToList());
            }
            if (credit != null && credit.Count > 0)
            {
                productSales.AddRange(credit.Where(obj => obj.SoldDate.Date >= fromDate.Date && obj.SoldDate.Date <= toDate.Date)
                                      .GroupBy(obj => new { obj.ProductId, obj.SoldDate.Date })
                                      .OrderBy(obj => obj.Key.Date)
                                      .ThenBy(obj => obj.Key.ProductId)
                                      .Select(obj => obj.Select(o => new ProductSales
                {
                    BillType    = "Credit",
                    Date        = o.SoldDate,
                    ProductId   = o.ProductId,
                    ProductName = o.ProductName,
                    Quantity    = o.Quantity,
                    BillAmount  = o.BillAmount,
                    GstAmount   = o.GSTAmount,
                    TotalAmount = o.TotalAmount
                }).ToList()).ToList());
            }

            return(productSales);
        }