public ActionResult GetDataMonthlySCCompanyFromAndroid(int cmpId) { decimal monthlySales = 0; decimal monthlyCollection = 0; string todaysMonth = ""; int companyId = cmpId; DateTime today = DateTime.Now; todaysMonth = today.ToString("MM/yyyy"); IList<SlsSalesOrderViewModel> orderList = _SalesOrderService.GetAll().ToList(); IList<SlsCollectionViewModel> collectionList = _collectionEntryService.GetAll().ToList(); if (orderList != null && orderList.Count() > 0) { IList<SlsSalesOrderViewModel> orders = orderList.Where(i => i.SecCompnayId == companyId && i.OrderDate != null && ((DateTime)i.OrderDate).Year == today.Year && ((DateTime)i.OrderDate).Month == today.Month).ToList(); if (orders != null && orders.Count() > 0) { decimal totalOrder = orders.Sum(i => i.Total); monthlySales += totalOrder; } } if (collectionList != null && collectionList.Count() > 0) { IList<SlsCollectionViewModel> collections = collectionList.Where(i => i.SecCompanyId == companyId && i.CollectionDate != null && ((DateTime)i.CollectionDate).Year == today.Year && ((DateTime)i.CollectionDate).Month == today.Month).ToList(); if (collections != null && collections.Count() > 0) { decimal totalCollection = collections.Sum(i => i.Amount); monthlyCollection += totalCollection; } } ChartViewModel sales1 = new ChartViewModel() { label = todaysMonth, y = decimal.Round(monthlySales, 2), legendText = "", per = 0 }; //ChartViewModel target2 = new ChartViewModel() { label = "28/04/2015", y = 3000, legendText = "", per = 0 }; ChartViewModel collections1 = new ChartViewModel() { label = todaysMonth, y = decimal.Round(monthlyCollection, 2), legendText = "", per = 0 }; //ChartViewModel sales2 = new ChartViewModel() { label = "28/04/2015", y = 2000, legendText = "", per = 0 }; ChartSalesCollections chartObj = new ChartSalesCollections(); chartObj.Collections = new List<ChartViewModel>(); chartObj.Sales = new List<ChartViewModel>(); chartObj.Collections.Add(collections1); //chartObj.Targets.Add(target2); chartObj.Sales.Add(sales1); //chartObj.Sales.Add(sales2); return Json(chartObj, JsonRequestBehavior.AllowGet); }
public ActionResult GetDataMonthlySCBranch() { decimal monthlySales = 0; decimal monthlyCollection = 0; string todaysMonth = ""; int officeId = 0; int companyId = Convert.ToInt32(Session["companyId"]); int employeeId = Convert.ToInt32(Session["employeeId"]); DateTime today = DateTime.Now; todaysMonth = today.ToString("MM/yyyy"); //Get OfficeId var employee = _hrmEmployeeService.GetById(employeeId); if (employee != null && employee.SlsOfficeId != null) { officeId = (int)employee.SlsOfficeId; } var employees = _hrmEmployeeService.GetAllEmployeeIds(companyId, officeId); if (officeId > 0) { IList<SlsSalesOrderViewModel> orderList = _SalesOrderService.GetAll().ToList(); IList<SlsCollectionViewModel> collectionList = _collectionEntryService.GetAll().ToList(); if (orderList != null && orderList.Count() > 0) { IList<SlsSalesOrderViewModel> orders = orderList.Where(i => i.SecCompnayId == companyId && i.OrderDate != null && ((DateTime)i.OrderDate).Year == today.Year && ((DateTime)i.OrderDate).Month == today.Month && i.SlsOfficeId == officeId).ToList(); if (orders != null && orders.Count() > 0) { decimal totalOrder = orders.Sum(i => i.Total); monthlySales += totalOrder; } } if (collectionList != null && collectionList.Count() > 0) { IList<SlsCollectionViewModel> collections = collectionList.Where(i => i.SecCompanyId == companyId && i.CollectionDate != null && ((DateTime)i.CollectionDate).Year == today.Year && ((DateTime)i.CollectionDate).Month == today.Month && i.HrmEmployeeId != null && employees.Contains((int)i.HrmEmployeeId)).ToList(); if (collections != null && collections.Count() > 0) { decimal totalCollection = collections.Sum(i => i.Amount); monthlyCollection += totalCollection; } } } ChartViewModel sales1 = new ChartViewModel() { label = todaysMonth, y = decimal.Round(monthlySales, 2), legendText = "", per = 0 }; //ChartViewModel target2 = new ChartViewModel() { label = "28/04/2015", y = 3000, legendText = "", per = 0 }; ChartViewModel collections1 = new ChartViewModel() { label = todaysMonth, y = decimal.Round(monthlyCollection, 2), legendText = "", per = 0 }; //ChartViewModel sales2 = new ChartViewModel() { label = "28/04/2015", y = 2000, legendText = "", per = 0 }; ChartSalesCollections chartObj = new ChartSalesCollections(); chartObj.Collections = new List<ChartViewModel>(); chartObj.Sales = new List<ChartViewModel>(); chartObj.Collections.Add(collections1); //chartObj.Targets.Add(target2); chartObj.Sales.Add(sales1); //chartObj.Sales.Add(sales2); return Json(chartObj, JsonRequestBehavior.AllowGet); }