//SALES
        public ActionResult SalesList(int page = 1, int?good = null)
        {
            ViewBag.Goods = new SelectList(repository.PureGoods().ToList(), "Id", "Title");//категории для формирования DropListDown
            List <Sale> itemsperpage = new List <Sale>();

            itemsperpage = repository.Sales(page, good).ToList();//все элементы на странице
            List <Sale> totalitems = new List <Sale>();

            totalitems = repository.Sales(good).ToList();//всего элементов в категории
            //формируем модель для отображения

            SaleListView model = new SaleListView()
            {
                good       = good,
                Sales      = itemsperpage,
                paginginfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = totalitems.Count()
                }
            };

            return(View(model));
        }
        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));
        }
        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));
        }