public ActionResult OwnerStatement(DateTime month, string propertyCode)
        {
            if (!AuthorizationProvider.CanViewStatement())
            {
                return(Forbidden());
            }

            try
            {
                var provider  = new OwnerStatementProvider(_dbContext);
                var viewModel = provider.GetOwnerStatement(month, propertyCode);

                // get the edit freeze flag
                viewModel.IsEditFreezed = (new StatementCompletionProvider(_dbContext)).IsEditFreezed(month);

                // statement owner can only see own statement and summary
                if (AuthorizationProvider.IsStatementOwner() && !AuthorizationProvider.IsStatementAdmin() && !AuthorizationProvider.IsStatementViewer())
                {
                    // TODO: filter the viewModel for the owner account
                }
                return(PartialView("_StatementPartial", viewModel));
            }
            catch
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult BackFillStatements(DateTime month)
        {
            if (!AuthorizationProvider.IsDataImporter())
            {
                return(Forbidden());
            }

            try
            {
                var statementProvider = new OwnerStatementProvider(_dbContext);
                var propertyProvider  = new PropertyProvider(_dbContext);
                var properties        = propertyProvider.All();
                foreach (CPL property in properties)
                {
                    if (property.PropertyStatus != "Dead")
                    {
                        try
                        {
                            // create/update owner statement record
                            var model = statementProvider.GetOwnerStatement(month, property.PropertyCode);
                            model.PropertyName = model.PropertyName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
                            var entity = statementProvider.Retrieve(model);
                            if (entity != null)
                            {
                                statementProvider.MapData(model, ref entity);
                                statementProvider.Update(entity.OwnerStatementId, entity);
                            }
                            else
                            {
                                entity = new OwnerStatement();
                                statementProvider.MapData(model, ref entity);
                                statementProvider.Create(entity);
                            }
                            statementProvider.Commit();
                        }
                        catch (Exception ex)
                        {
                            return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                return(Json("success-Statement", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult StatementLink(DateTime month, string propertyCode)
        {
            if (!AuthorizationProvider.CanViewStatement())
            {
                return(Forbidden());
            }

            var tokens = propertyCode.Split(new char[] { '-' });

            if (tokens.Length > 0)
            {
                propertyCode = tokens[0].Trim();
            }
            var provider  = new OwnerStatementProvider(_dbContext);
            var viewModel = provider.GetOwnerStatement(month, propertyCode);

            return(View("OwnerStatement", viewModel));
        }
        public ActionResult PrintStatement(DateTime month, string propertyCode)
        {
            if (!AuthorizationProvider.CanViewStatement())
            {
                return(Forbidden());
            }

            try
            {
                var provider  = new OwnerStatementProvider(_dbContext);
                var viewModel = provider.GetOwnerStatement(month, propertyCode);
                viewModel.IsPrint = true;
                return(View(viewModel));
            }
            catch
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(new OwnerStatementViewModel(), JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult Finalize(DateTime month, string propertyCode, string note, bool isFinalized = true)
        {
            if (!AuthorizationProvider.CanEditStatement())
            {
                return(Forbidden());
            }

            try
            {
                var provider  = new OwnerStatementProvider(_dbContext);
                var viewModel = provider.GetOwnerStatement(month, propertyCode);
                var result    = provider.FinalizeStatement(month, propertyCode, note, viewModel.EndingBalance, isFinalized);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }