Beispiel #1
0
        public List <MostSallingProduct> ProductsMostSalling(DateTime FromDate, DateTime ToDate, int PageNo, int PageSize)
        {
            _myshopDb = new MyshopDb();
            var saleList = _myshopDb.Sale_Dtl_Invoice.Where(x => DbFunctions.TruncateTime(x.Sale_Tr_Invoice.InvoiceDate) >= FromDate && DbFunctions.TruncateTime(x.Sale_Tr_Invoice.InvoiceDate) <= ToDate && !x.IsDeleted && !(x.IsReturn ?? false) && !x.Sale_Tr_Invoice.IsCancelled && x.ShopId.Equals(WebSession.ShopId)).GroupBy(x => x.ProductId);
            var products = _myshopDb.Gbl_Master_Product.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)).ToList();
            List <MostSallingProduct> mostSallingProducts = new List <MostSallingProduct>();

            foreach (var item in saleList)
            {
                MostSallingProduct _InvoicePro = new MostSallingProduct();
                _InvoicePro.ProductId   = item.Key;
                _InvoicePro.ProductName = products.Where(x => x.ProductId.Equals(item.Key)).Select(x => x.ProductName).FirstOrDefault();
                _InvoicePro.TotalQty    = item.Sum(x => x.Qty);
                _InvoicePro.TotalRecord = saleList.Count();
                mostSallingProducts.Add(_InvoicePro);
            }

            return(mostSallingProducts.Skip((PageNo - 1) * PageSize).Take(PageSize).OrderByDescending(x => x.TotalQty).ToList());
        }
Beispiel #2
0
        public DashboardModel GetDashboardData(int Day)
        {
            myshop = new MyshopDb();
            DashboardModel _newModel = new DashboardModel();
            List <DashboardInvoiceModel> _newInvoiceModel = new List <DashboardInvoiceModel>();

            List <MostSallingProduct> mostSallingProduct = new List <MostSallingProduct>();
            List <TopCustomersData>   topCustomersData   = new List <TopCustomersData>();
            DateTime salesDate = DateTime.Now.AddDays(-Day);
            DateTime now       = DateTime.Now;
            var      firstDateOfCurrentMonth = new DateTime(now.Year, now.Month, 1);
            var      sales        = myshop.Sale_Tr_Invoice.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId) && !x.IsCancelled).ToList();
            var      salesDetails = myshop.Sale_Dtl_Invoice.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)).ToList();
            var      monthlyData  = sales.Where(x => x.CreatedDate >= firstDateOfCurrentMonth).ToList();
            var      products     = myshop.Gbl_Master_Product.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)).ToList();

            _newModel.TotalSales = sales.Where(x => x.InvoiceDate >= salesDate.Date).Count();

            _newModel.TotalIncome = sales.Where(x => x.InvoiceDate >= salesDate.Date).Sum(x => x.GrandTotal - x.RefundAmount);

            _newModel.TotalProduct = salesDetails.Where(x => x.CreatedDate >= salesDate.Date).Select(x => x.ProductId).Distinct().Count();

            _newModel.TotalQty = salesDetails.Where(x => x.CreatedDate >= salesDate.Date).Sum(x => x.Qty);

            _newModel.MonthlyIncome = monthlyData.Sum(x => x.GrandTotal - x.RefundAmount);

            _newModel.TotalIncomeTillNow = sales.Sum(x => x.GrandTotal - x.RefundAmount);
            foreach (var item in sales.Where(x => x.InvoiceDate >= salesDate.Date))
            {
                DashboardInvoiceModel _InvoiceModel = new DashboardInvoiceModel();
                _InvoiceModel.Amount       = item.GrandTotal;
                _InvoiceModel.CustomerName = string.Format("{0} {1} {2}", item.Gbl_Master_Customer.FirstName, item.Gbl_Master_Customer.FirstName ?? string.Empty, item.Gbl_Master_Customer.LastName);
                _InvoiceModel.InvoiceDate  = item.InvoiceDate;
                _InvoiceModel.InvoiceNo    = item.InvoiceId;
                _InvoiceModel.IsRefund     = item.IsAmountRefunded;
                _newInvoiceModel.Add(_InvoiceModel);

                //Top Customers Data
                if (topCustomersData.Where(x => x.CustomerId.Equals(item.CustomerId)).Count() == 0)
                {
                    TopCustomersData _newCustData = new TopCustomersData();
                    _newCustData.CustomerId           = item.CustomerId;
                    _newCustData.TotalPurchase        = sales.Where(x => x.CustomerId.Equals(item.CustomerId)).Count();
                    _newCustData.TotalPurchaseAmount  = sales.Where(x => x.CustomerId.Equals(item.CustomerId)).Sum(x => x.GrandTotal - x.RefundAmount);;
                    _newCustData.TotalPurchaseProduct = item.CustomerId;
                    _newCustData.CustomerId           = item.CustomerId;
                    _newCustData.CustomerName         = string.Format("{0} {1} {2}", item.Gbl_Master_Customer.FirstName, item.Gbl_Master_Customer.FirstName ?? string.Empty, item.Gbl_Master_Customer.LastName);
                    topCustomersData.Add(_newCustData);
                }
            }
            _newModel.InvoiceMDetals = _newInvoiceModel.OrderByDescending(x => x.InvoiceNo).Take(10).ToList();

            foreach (var item in salesDetails.GroupBy(x => x.ProductId))
            {
                MostSallingProduct _InvoicePro = new MostSallingProduct();
                _InvoicePro.ProductId   = item.Key;
                _InvoicePro.ProductName = products.Where(x => x.ProductId.Equals(item.Key)).Select(x => x.ProductName).FirstOrDefault();
                _InvoicePro.TotalQty    = item.Sum(x => x.Qty);
                mostSallingProduct.Add(_InvoicePro);
            }
            _newModel.SallingProducts  = mostSallingProduct.OrderByDescending(x => x.TotalQty).Take(10).ToList();
            _newModel.TopCustomersData = topCustomersData.OrderByDescending(x => x.TotalPurchaseAmount).Take(10).ToList();
            return(_newModel);
        }