예제 #1
0
        private void UpdateOwnerStatement(string propertyCode, int month, int year, double amount)
        {
            var provider  = new OwnerStatementProvider(_dbContext);
            var statement = provider.GetOwnerStatement(propertyCode, month, year);

            if (statement != null)
            {
                statement.UnitExpenseItems += amount;
                statement.Balance          += amount;
                provider.Update(statement.OwnerStatementId, statement);
            }
        }
예제 #2
0
        public OwnerStatementSummaryModel GetOwnerSummary(DateTime month, string payoutMethod, bool redo)
        {
            try
            {
                SqlParameter[] sqlParams = new SqlParameter[1];
                sqlParams[0]       = new SqlParameter("@PayoutMethod", SqlDbType.NVarChar);
                sqlParams[0].Value = payoutMethod;
                var ownerProperties = _context.Database.SqlQuery <OwnerPropertyModel>("GetPropertiesForOwnerSummary @PayoutMethod", sqlParams).ToList();

                // get paid payout amount
                var    paymentProvider = new OwnerPaymentProvider(_context);
                double?paidPayout      = paymentProvider.GetMonthlyPayout(month, payoutMethod);

                var statementProvider = new OwnerStatementProvider(_context);
                var ownerSummary      = new OwnerStatementSummaryModel();

                // banner data
                ownerSummary.StatementMonth = month;
                ownerSummary.OwnerName      = payoutMethod;
                ownerSummary.PaidPayout     = paidPayout == null ? 0 : paidPayout.Value;
                ownerSummary.TotalPayout    = 0;

                // sum up owner statement belonging to the summary if the statement has been finalized
                int signFlag       = 0;
                var entityProvider = new PropertyEntityProvider(_context);
                foreach (var property in ownerProperties)
                {
                    var model = new OwnerStatementViewModel(_context)
                    {
                        PropertyName   = property.PropertyCode,
                        StatementMonth = month
                    };

                    var ownerStatement = statementProvider.Retrieve(model);

                    if (ownerStatement != null && ownerStatement.StatementStatus == StatementStatus.Finalized)
                    {
                        var summaryItem = MapOwnerStatementToSummaryItem(ownerStatement);
                        summaryItem.Address    = property.Address;
                        summaryItem.PropertyID = property.PropertyCode + '-' + property.Vertical;

                        summaryItem.EntityName   = entityProvider.GetEntityName(property.PropertyCode, model.StatementMonth);
                        summaryItem.PayoutMethod = payoutMethod;

                        ownerSummary.SummaryItems.Add(summaryItem);

                        signFlag |= summaryItem.EndingBalance > 0 ? 0x0001 : (summaryItem.EndingBalance < 0 ? 0x0002 : 0);
                    }
                }

                // retrive statement summary row if it exist; otherwise compute it
                var summaryRowModel = new OwnerStatementViewModel(_context)
                {
                    PropertyName   = payoutMethod,
                    StatementMonth = month
                };
                var summaryRow = statementProvider.Retrieve(summaryRowModel);

                if (summaryRow != null)
                {
                    ownerSummary.SummaryNotes = summaryRow.StatementNotes;
                }

                if (!redo && summaryRow != null) // get it from the record stored in ownerstatement table if exists
                {
                    ownerSummary.SetSumTotal(summaryRow);
                    ownerSummary.IsFinalized = summaryRow.StatementStatus == StatementStatus.Finalized;
                }
                else // compute it
                {
                    ownerSummary.SetSumTotal();
                    if (!redo)
                    {
                        ownerSummary.IsFinalized = false;
                    }
                }

                // if the summary has been finalized, we check if the total of all statements matches
                if (ownerSummary.IsFinalized)
                {
                    var itemTotal = ownerSummary.SumTotal(ownerSummary.SummaryItems); // the total of all the statements
                    ownerSummary.IsModified = IsSummaryModified(ownerSummary.ItemTotal, itemTotal);
                }

                ownerSummary.IsRebalanced = !(ownerSummary.TotalPayout < 0 && (signFlag & 0x0003) == 0x0003);

                return(ownerSummary);
            }
            catch (Exception ex)
            {
                throw; // let caller handle the error
            }
        }