public ActionResult Add()
        {
            string name = HttpContext.User.Identity.Name;

            List <SalePoint> salePointList = new List <SalePoint>();

            salePointList = AgroExpressDBAccess.GetSalePointListForUSer(name);
            SalePointProductAdd salePointProductTransfer = new SalePointProductAdd();

            salePointProductTransfer.salepointlist = salePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            List <ProductTransferInfo> PTI = new List <ProductTransferInfo>();
            var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");

            if (MilkInfo != null)
            {
                PTI.Add(new ProductTransferInfo {
                    ProductId = MilkInfo.PKProductId, Amount = null
                });
            }
            else
            {
                Product MilkInfoAdd = new Product
                {
                    ProductName = "Milk",
                    SellingUnit = "Ltr",
                    Stock       = 0
                };
                AgroExpressDBAccess.AddProduct(MilkInfoAdd);
                MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");
                PTI.Add(new ProductTransferInfo {
                    ProductId = MilkInfo.PKProductId, Amount = null
                });
            }
            // Product dropdown list
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            ProductInf = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList();
            salePointProductTransfer.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });

            //
            int len = ProductInf.Count;

            for (int i = 0; i < len; i++)
            {
                PTI.Add(new ProductTransferInfo {
                    ProductId = null, Amount = null
                });
            }
            salePointProductTransfer.TransferedProductInfo = PTI;
            salePointProductTransfer.Date = System.DateTime.Now.Date;
            return(View(salePointProductTransfer));
        }
        public ActionResult Index([Bind(Exclude = "ProductSearchResult")] ProductListView SerchCriteria)
        {
            var             ProductList  = AgroExpressDBAccess.GetAllEnabledProduct();
            ProductListView ProductListV = new ProductListView();

            ProductListV.ProductList = ProductList.Select(x => new SelectListItem
            {
                Value    = x.PKProductId.ToString(),
                Text     = x.ProductName,
                Selected = x.PKProductId == SerchCriteria.SelectedProductID ? true : false
            });
            var SearchResult = AgroExpressDBAccess.SearchProduct(SerchCriteria.SelectedProductID, SerchCriteria.MinimumStock, SerchCriteria.MaximumStock);

            if (SearchResult != null)
            {
                ProductListV.ProductSearchResult = SearchResult;
            }
            else
            {
                ProductListV.ProductSearchResult = new List <Product>();
            }
            ProductListV.MaximumStock = SerchCriteria.MaximumStock;
            ProductListV.MinimumStock = SerchCriteria.MinimumStock;
            ModelState.Clear();
            return(View(ProductListV));
        }
        public ActionResult TransferList()
        {
            SalePointProductAddList request       = new SalePointProductAddList();
            List <SalePoint>        SalePointList = new List <SalePoint>();

            SalePointList = AgroExpressDBAccess.GetallEnabledSalePoint();

            request.salepointlist = SalePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            request.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            request.EntryDateMax = System.DateTime.Now;
            request.EntryDateMin = request.EntryDateMax.AddMonths(-1);
            request.SearchResult = AgroExpressDBAccess.GetSellPointProductAdd(request.EntryDateMin, request.EntryDateMax).OrderBy(a => a.Date).ToList();

            return(View(request));
        }
        public ActionResult Add()
        {
            AddOrderListView newentry = new AddOrderListView();

            List <Product> prlist     = AgroExpressDBAccess.GetAllEnabledProduct();
            var            ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            List <AddOrder> orders = new List <AddOrder>();
            int             len    = ProductInf.Count;

            for (int i = 0; i < len; i++)
            {
                orders.Add(new AddOrder
                {
                    productlist = ProductInf.Select(x => new SelectListItem
                    {
                        Value = x.PKProductId.ToString(),
                        Text  = x.ProductName
                    }),
                    OrderPlacingDateTime = DateTime.Now.Date,
                    Amount = 0
                });
            }

            newentry.orderlist = orders;
            return(View(newentry));
        }
        public ActionResult SingleOrderAdd(AddOrder newentry)
        {
            List <Product> prlist = AgroExpressDBAccess.GetAllEnabledProduct();

            if (prlist != null)
            {
                newentry.productlist = prlist.Select(x => new SelectListItem
                {
                    Value = x.PKProductId.ToString(),
                    Text  = x.ProductName
                });
            }

            if (ModelState.IsValid)
            {
                if (AgroExpressDBAccess.AddSingleOrder(newentry))
                {
                    ModelState.Clear();
                    ViewBag.success = "Order has been placed Successfully";
                }
                else
                {
                    ViewBag.success = "Sorry, Your order is not placed, Please try again";
                }
            }

            newentry.OrderPlacingDateTime = newentry.OrderPlacingDateTime;
            return(View(newentry));
        }
        public ActionResult Factory()
        {
            FactoryProduction productionInfo = new FactoryProduction();
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            ProductInf = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList();

            int len = ProductInf.Count;
            List <ProductionInfo> NewProduction = new List <ProductionInfo>();

            for (int i = 0; i < len; i++)
            {
                NewProduction.Add(new ProductionInfo
                {
                    productlist = ProductInf.Select(x => new SelectListItem
                    {
                        Value = x.PKProductId.ToString(),
                        Text  = x.ProductName
                    }),
                    Date   = System.DateTime.Now,
                    Amount = 0
                });
            }
            productionInfo.productionlist  = NewProduction;
            productionInfo.ConsumptionDate = System.DateTime.Now.Date;
            return(View(productionInfo));
        }
        public ActionResult FactoryList(FactoryProductionList request)
        {
            List <Production> ProductionInfo = AgroExpressDBAccess.ProductionInfoByDate(request.EntryDateMin, request.EntryDateMax);

            if (request.ProductID != null)
            {
                ProductionInfo = ProductionInfo.Where(a => a.ProductId == request.ProductID).ToList();
            }
            if (request.AmountMax != null)
            {
                ProductionInfo = ProductionInfo.Where(a => a.Amount <= request.AmountMax).ToList();
            }
            if (request.AmountMin != null)
            {
                ProductionInfo = ProductionInfo.Where(a => a.Amount >= request.AmountMin).ToList();
            }

            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            ProductInf          = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList();
            request.ProductList = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            request.SearchResult = ProductionInfo;
            return(View(request));
        }
        public ActionResult Stock()
        {
            SalePointProductStockList request       = new SalePointProductStockList();
            List <SalePoint>          SalePointList = new List <SalePoint>();

            SalePointList = AgroExpressDBAccess.GetallEnabledSalePoint();

            request.salepointlist = SalePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            request.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            List <SalePointProductStock> productStock = new List <SalePointProductStock>();

            productStock         = AgroExpressDBAccess.GetSalePointProductStock();
            request.SearchResult = productStock.OrderBy(o => o.SalePointId).ToList();
            return(View(request));
        }
        public ActionResult Add(AddOrderListView newentry)
        {
            List <Order> neworder = new List <Order>();

            for (int i = 0; i < newentry.orderlist.Count; i++)
            {
                if (newentry.orderlist[i].PKProductId != 0 && newentry.orderlist[i].Amount != 0 && newentry.orderlist[i].OrderPlacingDateTime != null)
                {
                    neworder.Add(new Order
                    {
                        CustomerId           = 1,
                        ProductId            = newentry.orderlist[i].PKProductId,
                        OrderPlacingDateTime = newentry.orderlist[i].OrderPlacingDateTime,
                        OrderDateTime        = System.DateTime.Now.Date,
                        Amount = newentry.orderlist[i].Amount
                    });
                }
            }

            if (AgroExpressDBAccess.AddOrder(neworder))
            {
                ViewBag.success("Order Successful");
            }
            else
            {
                ViewBag.success("Sorry, Your order is not placed, Please try again");
            }



            List <Product> prlist     = AgroExpressDBAccess.GetAllEnabledProduct();
            var            ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            List <AddOrder> orders = new List <AddOrder>();
            int             len    = ProductInf.Count;

            for (int i = 0; i < len; i++)
            {
                orders.Add(new AddOrder
                {
                    productlist = ProductInf.Select(x => new SelectListItem
                    {
                        Value = x.PKProductId.ToString(),
                        Text  = x.ProductName
                    }),
                    OrderPlacingDateTime = System.DateTime.Now.Date,
                    Amount = 0
                });
            }

            newentry.orderlist = orders;
            return(View(newentry));
        }
        //[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Factory(FactoryProduction productionInfo)
        {
            List <Production> ProductionList = new List <Production>();
            string            name           = HttpContext.User.Identity.Name;
            string            operatorName   = AgroExpressDBAccess.GetFullNamebyUserID(name);

            foreach (var production in productionInfo.productionlist)
            {
                if (production.PKProductId != null && production.Amount != null)
                {
                    ProductionList.Add(new Production
                    {
                        ProductId    = (int)production.PKProductId,
                        Amount       = (double)production.Amount,
                        Date         = production.Date,
                        OperatorName = operatorName
                    });
                }
            }
            if (productionInfo.ConsumptionDate != null && productionInfo.MilkConsumption != null)
            {
                AgroExpressDBAccess.AddFactoryMilkConsumption((DateTime)productionInfo.ConsumptionDate, (double)productionInfo.MilkConsumption);
            }
            string message = AgroExpressDBAccess.AddPoductionList(ProductionList);

            if (message == "yes")
            {
                return(RedirectToAction(nameof(Factory)));
            }
            else
            {
                var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();
                int len        = ProductInf.Count;
                List <ProductionInfo> NewProduction = new List <ProductionInfo>();
                for (int i = 0; i < len; i++)
                {
                    NewProduction.Add(new ProductionInfo
                    {
                        productlist = ProductInf.Select(x => new SelectListItem
                        {
                            Value = x.PKProductId.ToString(),
                            Text  = x.ProductName
                        }),
                        Date   = System.DateTime.Now,
                        Amount = 0
                    });
                }
                productionInfo.productionlist = NewProduction;
                ViewBag.message = message;
            }
            return(View(productionInfo));
        }
        public ActionResult SingleOrderAdd()
        {
            AddOrder       newentry = new AddOrder();
            List <Product> prlist   = AgroExpressDBAccess.GetAllEnabledProduct();

            if (prlist != null)
            {
                newentry.productlist = prlist.Select(x => new SelectListItem
                {
                    Value = x.PKProductId.ToString(),
                    Text  = x.ProductName
                });
            }
            newentry.OrderPlacingDateTime = System.DateTime.Now.Date;
            return(View(newentry));
        }
        public ActionResult FactoryList()
        {
            FactoryProductionList Production = new FactoryProductionList();

            Production.EntryDateMax = System.DateTime.Now;
            Production.EntryDateMin = System.DateTime.Now.AddDays(-30);
            List <Production> ProductionInfo = AgroExpressDBAccess.ProductionInfoByDate(Production.EntryDateMin, Production.EntryDateMax);

            Production.SearchResult = ProductionInfo;
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            ProductInf             = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList();
            Production.ProductList = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            return(View(Production));
        }
        public ActionResult TransferList(SalePointProductAddList request)
        {
            List <SalePoint> SalePointList = new List <SalePoint>();

            SalePointList = AgroExpressDBAccess.GetallEnabledSalePoint();

            request.salepointlist = SalePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            request.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            if (ModelState.IsValid)
            {
                var result = AgroExpressDBAccess.GetSellPointProductAdd(request.EntryDateMin, request.EntryDateMax).OrderBy(a => a.Date).ToList();
                if (request.ProductId != null)
                {
                    result = result.Where(a => a.ProductId == request.ProductId).ToList();
                }
                if (request.SalePointId != null)
                {
                    result = result.Where(a => a.SalePointId == request.SalePointId).ToList();
                }
                if (request.StockAmountMin != null)
                {
                    result = result.Where(a => a.Amount >= request.StockAmountMin).ToList();
                }
                if (request.StockAmountMAx != null)
                {
                    result = result.Where(a => a.Amount <= request.StockAmountMAx).ToList();
                }
                request.SearchResult = result.OrderBy(a => a.salepoint.SalePointName).ToList();
            }

            return(View(request));
        }
        public ActionResult Stock(SalePointProductStockList request)
        {
            List <SalePoint> SalePointList = new List <SalePoint>();

            SalePointList = AgroExpressDBAccess.GetallEnabledSalePoint();

            request.salepointlist = SalePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            request.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            List <SalePointProductStock> productStock = new List <SalePointProductStock>();

            productStock = AgroExpressDBAccess.GetSalePointProductStock();


            if (request.SalePointId != null)
            {
                productStock = productStock.Where(a => a.SalePointId == request.SalePointId).ToList();
            }
            if (request.ProductId != null)
            {
                productStock = productStock.Where(a => a.ProductId == request.ProductId).ToList();
            }
            if (request.StockAmountMin != null)
            {
                productStock = productStock.Where(a => a.ProductStock >= request.StockAmountMin).ToList();
            }
            if (request.StockAmountMAx != null)
            {
                productStock = productStock.Where(a => a.ProductStock <= request.StockAmountMAx).ToList();
            }
            request.SearchResult = productStock.OrderBy(o => o.SalePointId).ToList();
            return(View(request));
        }
        public ActionResult Index()
        {
            var             ProductList  = AgroExpressDBAccess.GetAllEnabledProduct();
            ProductListView ProductListV = new ProductListView();

            ProductListV.ProductList = ProductList.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });
            if (ProductList != null)
            {
                ProductListV.ProductSearchResult = ProductList;
            }
            else
            {
                ProductListV.ProductSearchResult = new List <Product>();
            }
            return(View(ProductListV));
        }
        private ProductSaleAdd ProductSaleInitial()
        {
            string name = HttpContext.User.Identity.Name;

            ProductSaleAdd ProductSale = new ProductSaleAdd();

            ProductSale.SaleDate = System.DateTime.UtcNow.AddHours(6);

            List <SalePoint> salePointList = new List <SalePoint>();

            salePointList = AgroExpressDBAccess.GetSalePointListForUSer(name);
            if (salePointList != null)
            {
                ProductSale.salepointlist = salePointList.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea();

            if (arealist != null)
            {
                arealist         = arealist.Where(a => salePointList.Any(b => b.PKSalePointID == a.SalePointId)).ToList();
                ProductSale.Area = arealist.Select(x => new SelectListItem
                {
                    Value = x.PKAreaId.ToString(),
                    Text  = x.AreaName
                });
            }

            List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea();

            if (sarealist != null)
            {
                sarealist           = sarealist.Where(a => arealist.Any(b => b.PKAreaId == a.AreaId)).ToList();
                ProductSale.SubArea = sarealist.Select(x => new SelectListItem
                {
                    Value = x.PKSubAreaId.ToString(),
                    Text  = x.SubAreaName
                });
            }

            List <Product>         productList = AgroExpressDBAccess.GetAllEnabledProduct();
            List <ProductSaleInfo> PSI         = new List <ProductSaleInfo>();
            var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");

            if (MilkInfo != null)
            {
                PSI.Add(new ProductSaleInfo {
                    ProductId = MilkInfo.PKProductId, Amount = null, Rate = null, Servicecharge = null
                });
            }
            else
            {
                Product MilkInfoAdd = new Product
                {
                    ProductName = "Milk",
                    SellingUnit = "Ltr",
                    Stock       = 0
                };
                AgroExpressDBAccess.AddProduct(MilkInfoAdd);
                MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");
                PSI.Add(new ProductSaleInfo {
                    ProductId = MilkInfo.PKProductId, Amount = null, Rate = null, Servicecharge = null
                });
            }
            // Product dropdown list

            productList         = productList.Where(a => a.ProductName.ToLower() != "milk").ToList();
            ProductSale.product = productList.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });

            //
            int len = productList.Count;

            for (int i = 0; i < len; i++)
            {
                PSI.Add(new ProductSaleInfo {
                    ProductId = null, Amount = null, Rate = null, Servicecharge = 0
                });
            }
            ProductSale.ProductSaleInfo = PSI;

            List <Customer> customer = AgroExpressDBAccess.GetallEnabledCustomer();

            customer             = customer.Where(a => sarealist.Any(b => b.PKSubAreaId == a.SubAreaId)).ToList();
            ProductSale.Customer = customer.Select(x => new SelectListItem
            {
                Value = x.PKCustomerId.ToString(),
                Text  = x.FullName
            });
            return(ProductSale);
        }
        public ActionResult SingleSale(SingleSaleAdd single)
        {
            List <SalePoint> salepointlist = AgroExpressDBAccess.GetallEnabledSalePoint();

            if (salepointlist != null)
            {
                single.salepointlist = salepointlist.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea();

            if (arealist != null)
            {
                single.arealist = arealist.Select(x => new SelectListItem
                {
                    Value = x.PKAreaId.ToString(),
                    Text  = x.AreaName
                });
            }

            List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea();

            if (sarealist != null)
            {
                single.subarealist = sarealist.Select(x => new SelectListItem
                {
                    Value = x.PKSubAreaId.ToString(),
                    Text  = x.SubAreaName
                });
            }

            List <Customer> culist = AgroExpressDBAccess.GetallEnabledCustomer();

            if (culist != null)
            {
                single.customerlist = culist.Select(x => new SelectListItem
                {
                    Value = x.PKCustomerId.ToString(),
                    Text  = x.FullName
                });
            }

            List <Product> prlist = AgroExpressDBAccess.GetAllEnabledProduct();

            if (prlist != null)
            {
                single.productlist = prlist.Select(x => new SelectListItem
                {
                    Value = x.PKProductId.ToString(),
                    Text  = x.ProductName
                });
            }

            if (ModelState.IsValid)
            {
            }


            return(View(single));
        }
        public ActionResult Add(SalePointProductAdd Request)
        {
            if (ModelState.IsValid)
            {
                string name                    = HttpContext.User.Identity.Name;
                string operatorName            = AgroExpressDBAccess.GetFullNamebyUserID(name);
                List <ProductTransferInfo> PTI = Request.TransferedProductInfo;
                int len = PTI.Count;
                List <SalePointProductConsume> newProduct = new List <SalePointProductConsume>();
                for (int i = 0; i < len; i++)
                {
                    if (PTI[i].ProductId != null && (PTI[i].Amount != null))
                    {
                        newProduct.Add(new SalePointProductConsume
                        {
                            SalePointId  = Request.SalePointId,
                            Date         = Request.Date,
                            ProductId    = (int)PTI[i].ProductId,
                            Amount       = (int)PTI[i].Amount,
                            OperatorName = operatorName
                        });
                    }
                }
                ViewBag.message = AgroExpressDBAccess.AddSalePointProduct(newProduct);
                if (ViewBag.message == "yes")
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            foreach (ModelState modelState in ViewData.ModelState.Values)
            {
                foreach (ModelError error in modelState.Errors)
                {
                    string errorme = error.ToString();
                }
            }
            List <SalePoint> salePointList = new List <SalePoint>();

            salePointList = AgroExpressDBAccess.GetSalePointListForUSer(HttpContext.User.Identity.Name);
            SalePointProductAdd salePointProductTransfer = new SalePointProductAdd();

            salePointProductTransfer.salepointlist = salePointList.Select(x => new SelectListItem
            {
                Value = x.PKSalePointID.ToString(),
                Text  = x.SalePointName
            });
            List <ProductTransferInfo> PTI1 = new List <ProductTransferInfo>();
            var MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");

            if (MilkInfo != null)
            {
                PTI1.Add(new ProductTransferInfo {
                    ProductId = MilkInfo.PKProductId, Amount = null
                });
            }
            else
            {
                Product MilkInfoAdd = new Product
                {
                    ProductName = "Milk",
                    SellingUnit = "Ltr",
                    Stock       = 0
                };
                AgroExpressDBAccess.AddProduct(MilkInfoAdd);
                MilkInfo = AgroExpressDBAccess.IsProductExist("Milk");
                PTI1.Add(new ProductTransferInfo {
                    ProductId = MilkInfo.PKProductId, Amount = 0
                });
            }
            // Product dropdown list
            var ProductInf = AgroExpressDBAccess.GetAllEnabledProduct();

            ProductInf = ProductInf.Where(a => a.ProductName.ToLower() != "milk").ToList();
            salePointProductTransfer.product = ProductInf.Select(x => new SelectListItem
            {
                Value = x.PKProductId.ToString(),
                Text  = x.ProductName
            });

            //
            int len1 = ProductInf.Count;

            for (int i = 0; i < len1; i++)
            {
                PTI1.Add(new ProductTransferInfo {
                    ProductId = null, Amount = null
                });
            }
            salePointProductTransfer.TransferedProductInfo = PTI1;
            return(View(salePointProductTransfer));
        }
        public ActionResult SaleHistory()
        {
            SaleListView     listview      = new SaleListView();
            List <SalePoint> salepointlist = AgroExpressDBAccess.GetallEnabledSalePoint();

            if (salepointlist != null)
            {
                listview.salepointlist = salepointlist.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea();

            if (arealist != null)
            {
                listview.arealist = arealist.Select(x => new SelectListItem
                {
                    Value = x.PKAreaId.ToString(),
                    Text  = x.AreaName
                });
            }

            List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea();

            if (sarealist != null)
            {
                listview.subarealist = sarealist.Select(x => new SelectListItem
                {
                    Value = x.PKSubAreaId.ToString(),
                    Text  = x.SubAreaName
                });
            }

            var customerlist = AgroExpressDBAccess.GetallEnabledCustomer();

            if (customerlist != null)
            {
                listview.selectedcustomerlist = customerlist.Select(x => new SelectListItem
                {
                    Value = x.PKCustomerId.ToString(),
                    Text  = x.FullName
                });
            }

            var productList = AgroExpressDBAccess.GetAllEnabledProduct();

            if (productList != null)
            {
                listview.selectedproductlist = productList.Select(x => new SelectListItem
                {
                    Value = x.PKProductId.ToString(),
                    Text  = x.ProductName
                });
            }

            listview.EntryDateMax = System.DateTime.Now.Date.AddDays(1);
            listview.EntryDateMin = listview.EntryDateMax.AddDays(-30);

            var             saleifo = AgroExpressDBAccess.GetSaleInfoByDate(listview.EntryDateMin, listview.EntryDateMax);
            List <SaleList> sale    = new List <SaleList>();

            if (saleifo != null)
            {
                foreach (var li in saleifo)
                {
                    sale.Add(new SaleList
                    {
                        DateTime     = li.DateTime,
                        CustomerName = li.customer.FullName,
                        ProductName  = li.product.ProductName,
                        Amount       = li.Amount,
                        Total        = (li.Amount * li.Rate) + (li.Amount * li.ServiceCharge),
                        SMSSent      = li.SMSSent,
                        OperatorName = li.OperatorName
                    });
                }
            }

            listview.salelist = sale;
            return(View(listview));
        }
        public ActionResult SaleHistory(SaleListView listview)
        {
            List <SalePoint> salepointlist = AgroExpressDBAccess.GetallEnabledSalePoint();

            if (salepointlist != null)
            {
                listview.salepointlist = salepointlist.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea();

            if (arealist != null)
            {
                listview.arealist = arealist.Select(x => new SelectListItem
                {
                    Value = x.PKAreaId.ToString(),
                    Text  = x.AreaName
                });
            }

            List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea();

            if (sarealist != null)
            {
                listview.subarealist = sarealist.Select(x => new SelectListItem
                {
                    Value = x.PKSubAreaId.ToString(),
                    Text  = x.SubAreaName
                });
            }

            var customerlist = AgroExpressDBAccess.GetallEnabledCustomer();

            if (customerlist != null)
            {
                listview.selectedcustomerlist = customerlist.Select(x => new SelectListItem
                {
                    Value = x.PKCustomerId.ToString(),
                    Text  = x.FullName
                });
            }
            var productList = AgroExpressDBAccess.GetAllEnabledProduct();

            if (productList != null)
            {
                listview.selectedproductlist = productList.Select(x => new SelectListItem
                {
                    Value = x.PKProductId.ToString(),
                    Text  = x.ProductName
                });
            }
            var saleifo = AgroExpressDBAccess.GetSaleInfoByDate(listview.EntryDateMin, listview.EntryDateMax.AddDays(1));

            if (listview.AmountVMax != null)
            {
                saleifo = saleifo.Where(a => a.Amount <= listview.AmountVMax).ToList();
            }
            if (listview.AmountVMin != null)
            {
                saleifo = saleifo.Where(a => a.Amount >= listview.AmountVMin).ToList();
            }

            if (listview.CustomerID != null)
            {
                saleifo = saleifo.Where(a => a.CustomerId == listview.CustomerID).ToList();
            }
            if (listview.SelectedProductID != null)
            {
                saleifo = saleifo.Where(a => a.ProductId == listview.SelectedProductID).ToList();
            }
            List <Area>    AreList    = new List <Area>();
            List <SubArea> subAreList = AgroExpressDBAccess.GetallEnabledSubArea();

            if (listview.SalePointId != null)
            {
                AreList = AgroExpressDBAccess.GetAreaBySalePointID((int)listview.SalePointId);

                if (AreList != null)
                {
                    subAreList = subAreList
                                 .Where(x => AreList.Any(y => y.PKAreaId == x.AreaId)).ToList();
                }
                customerlist = customerlist.Where(customer => subAreList.Any(subarea => subarea.PKSubAreaId == customer.SubAreaId)).ToList();
                saleifo      = saleifo.Where(salei => customerlist.Any(customer => customer.PKCustomerId == salei.CustomerId)).ToList();
            }
            if (listview.AreaId != null)
            {
                subAreList   = subAreList.Where(su => su.AreaId == listview.AreaId).ToList();
                customerlist = customerlist.Where(customer => subAreList.Any(subarea => subarea.PKSubAreaId == customer.SubAreaId)).ToList();
                saleifo      = saleifo.Where(salei => customerlist.Any(customer => customer.PKCustomerId == salei.CustomerId)).ToList();
            }
            if (listview.SubAreaId != null)
            {
                customerlist = customerlist.Where(customer => customer.SubAreaId == listview.SubAreaId).ToList();
                saleifo      = saleifo.Where(salei => customerlist.Any(customer => customer.PKCustomerId == salei.CustomerId)).ToList();
            }

            List <SaleList> sale = new List <SaleList>();

            if (saleifo != null)
            {
                foreach (var li in saleifo)
                {
                    sale.Add(new SaleList
                    {
                        DateTime     = li.DateTime,
                        CustomerName = li.customer.FullName,
                        ProductName  = li.product.ProductName,
                        Amount       = li.Amount,
                        SMSSent      = li.SMSSent,
                        OperatorName = li.OperatorName
                    });
                }
            }

            listview.salelist = sale;
            return(View(listview));
        }