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 IsFinalized(DateTime date, string propertyCode)
 {
     try
     {
         var statementProvider = new OwnerStatementProvider(_dbContext);
         var finalizeFlag      = statementProvider.IsFinalized(date, propertyCode) == true ? "1" : "0";
         return(Json(finalizeFlag, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json("0", JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult OwnerSummary(DateTime month, string payoutMethod)
        {
            if (!AuthorizationProvider.CanViewStatement())
            {
                return(Forbidden(new OwnerStatementSummaryModel()));
            }

            var provider  = new OwnerStatementProvider(_dbContext);
            var viewModel = provider.GetOwnerSummary(month, payoutMethod, false);

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

            return(PartialView("_SummaryPartial", viewModel));
        }
        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 JsonResult BackFillOwnerSummaries(DateTime month)
        {
            if (!AuthorizationProvider.IsDataImporter())
            {
                return(Forbidden());
            }

            try
            {
                var summaryProvider = new OwnerStatementProvider(_dbContext);
                var paymentProvider = new OwnerPaymentProvider(_dbContext);
                var payoutMethods   = paymentProvider.All();
                foreach (PayoutMethod method in payoutMethods)
                {
                    if (method.PayoutMethodName != null)
                    {
                        try
                        {
                            var summary = summaryProvider.GetOwnerSummary(month, method.PayoutMethodName, true);
                            var model   = new OwnerStatement();
                            summaryProvider.MapData(summary.ItemTotal, ref model, month, method.PayoutMethodName);

                            var entity = summaryProvider.Retrieve(model);
                            if (entity != null)
                            {
                                model.OwnerStatementId = entity.OwnerStatementId;
                                summaryProvider.Update(model.OwnerStatementId, model);
                            }
                            else
                            {
                                summaryProvider.Create(model);
                            }
                            summaryProvider.Commit();
                        }
                        catch (Exception ex)
                        {
                            return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                        }
                    }
                }
                return(Json("success-Summary", 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 JsonResult FinalizeSummary(DateTime month, string payoutMethod, string note, bool isFinalized = true)
        {
            if (!AuthorizationProvider.CanEditStatement())
            {
                return(Forbidden());
            }

            try
            {
                var statementProvider = new OwnerStatementProvider(_dbContext);
                statementProvider.FinalizeSummary(month, payoutMethod, note, isFinalized);
                return(Json("success", JsonRequestBehavior.AllowGet));
            }
            catch
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json("fail", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult PrintSummary(DateTime month, string payoutMethod)
        {
            if (!AuthorizationProvider.CanViewStatement())
            {
                return(Forbidden(new OwnerStatementSummaryModel()));
            }

            try
            {
                var provider  = new OwnerStatementProvider(_dbContext);
                var viewModel = provider.GetOwnerSummary(month, payoutMethod, false);
                viewModel.IsPrint = true;
                return(View(viewModel));
            }
            catch
            {
                Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return(Json(new OwnerStatementSummaryModel(), 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));
            }
        }