private List <ToplineViewModel> BindToplinesViewModel(List <BPSR_Topline> toplines, DateTime dueDate, string approverName, bool isAdmin, bool isApprover)
        {
            var results = new List <ToplineViewModel>();

            foreach (var t in toplines)
            {
                var item = new ToplineViewModel()
                {
                    ToplineId           = t.BPSR_ToplineID,
                    StoreId             = t.LocalStoreID,
                    Status              = FormatHelpers.FormatStatus(t.BPSR_StatusID),
                    PeriodEndDate       = FormatHelpers.FormatPeriodDate(t.PeriodEndDate),
                    NetSales            = FormatHelpers.FormatMoney(t.NetSales),
                    FranCalcRoyalty     = FormatHelpers.FormatMoney(t.FranCalcRoyalty),
                    FranCalcAdvertising = FormatHelpers.FormatMoney(t.FranCalcAdvertising),
                    TotalTickets        = FormatHelpers.FormatNumber(t.TotalTickets),
                    SalesTypeCode       = FormatHelpers.FormatSalesType(t.SalesTypeID), //t.SalesType.SalesTypeCode, //FormatSalesType
                    IsPastDue           = this.IsPastDue(dueDate, t.PeriodEndDate),

                    //CanEdit = this.CanEditTopline(t.BPSR_StatusID, isAdmin, isApprover),
                    //CanApprove = this.CanApproveTopline(t.BPSR_StatusID, isAdmin, isApprover),
                    //CanSubmit = this.CanSubmitTopline(t.BPSR_StatusID, isAdmin, isApprover)

                    CanEdit    = this.CanEditTopline(t.BPSR_StatusID, isAdmin, isApprover),
                    CanApprove = this.CanApproveTopline(t.BPSR_StatusID, isAdmin, isApprover),
                    CanSubmit  = this.CanSubmitTopline(t.BPSR_StatusID, t.SubmitterName, approverName, isAdmin, isApprover)
                };

                results.Add(item);
            }

            return(results);
        }
        public ActionResult Index()
        {
            var subBrandId    = GetCurrentSubBrandId();
            var userViewModel = GetCurrentUserViewModel();

            var myStatuses = _brandPeriodSalesService.GetStatuses().ToList();
            var myPeriods  = _brandPeriodSalesService.GetPeriodEndDates(subBrandId).ToList();
            var myStores   = _brandPeriodSalesService.GetStoreIds(subBrandId).OrderBy(x => x, new SemiNumericComparer());

            var userAuthStores = (!userViewModel.IsAdmin && !userViewModel.IsApprover && userViewModel.UserType == "FZ")
                    ? myStores.Intersect(userViewModel.UserAuthStores)
                    : myStores;

            var model = new ToplineListViewModel();

            model.StoreIds = (from c in userAuthStores select new SelectListItem()
            {
                Text = c, Value = c
            }).ToList();
            model.StoreId  = string.Empty;

            var allowedStatus  = Enum.GetValues(typeof(ToplineStatus)).Cast <int>();
            var filteredStatus = myStatuses.Where(o => allowedStatus.Contains(o.BPSR_StatusID));

            model.StatusIds = (from c in filteredStatus select new SelectListItem()
            {
                Text = c.BPSR_StatusDescription, Value = c.BPSR_StatusID.ToString()
            }).ToList();
            //model.StatusIds = (from c in myStatuses select new SelectListItem() { Text = c.BPSR_StatusDescription, Value = c.BPSR_StatusID.ToString() }).ToList();
            model.StatusId = string.Empty;

            model.PeriodEndDates = (from c in myPeriods select new SelectListItem()
            {
                Text = FormatHelpers.FormatPeriodDate(c), Value = FormatHelpers.FormatPeriodDate(c)
            }).ToList();
            model.PeriodEndDate  = (model.PeriodEndDates != null && model.PeriodEndDates.Count > 0) ? model.PeriodEndDates.FirstOrDefault().Value : string.Empty;

            model.IsPastDue  = false;
            model.IsAdmin    = userViewModel.IsAdmin;
            model.IsApprover = userViewModel.IsApprover;

            return(View(model));
        }
 private string FormatTitle(string operation, string store, DateTime periodEndDate)
 {
     return(String.Format("{0} - Store #{1} - Reporting Period {2}", operation, store, FormatHelpers.FormatPeriodDate(periodEndDate)));
 }