public List <DashboardInvoiceModel> GetSalesList(int PageNo = 1, int PageSize = 10) { _myshopDb = new MyshopDb(); var _list = _myshopDb.Sale_Tr_Invoice.Where(x => !x.IsDeleted && x.ShopId.Equals(WebSession.ShopId)).ToList().OrderByDescending(x => x.InvoiceDate); List <DashboardInvoiceModel> salesList = new List <DashboardInvoiceModel>(); foreach (var item in _list.Skip((PageNo - 1) * PageSize).Take(PageSize)) { DashboardInvoiceModel _newItem = new DashboardInvoiceModel(); _newItem.Amount = item.GrandTotal; _newItem.CustomerName = string.Format("{0} {1} {2}", item.Gbl_Master_Customer.FirstName, item.Gbl_Master_Customer.MiddleName, item.Gbl_Master_Customer.LastName); //; _newItem.InvoiceDate = item.InvoiceDate; _newItem.InvoiceNo = item.InvoiceId; _newItem.IsCancelled = item.IsCancelled; _newItem.BalanceAmount = item.BalanceAmount; _newItem.RefundAmount = item.RefundAmount; _newItem.IsRefund = item.IsAmountRefunded; _newItem.PaymentMode = item.Gbl_Master_PayMode.PayMode; _newItem.TotalInvoice = _list.Count(); salesList.Add(_newItem); } return(salesList); }
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); }