Esempio n. 1
0
        private void CalculateAggregates(DateTime startDate, DateTime endDate)
        {
            // Balances:  Total made, less each quarters repayment, adding to Net Balance
            double dTotalLent        = 0D;
            double dRepaidPeriod     = 0D;
            double dRepaidPreviously = 0D;
            double dNetBalance       = 0D;
            double dTotalCommitted   = 0D;
            double dTotalRehabRemain = 0D;
            double dSaleContracts    = 0D;
            double dSaleListings     = 0D;
            double dPendingAcq       = 0D;
            double dPartialBalance   = 0D;

            // Accrued:   Total accrued FTD, less this period payments, less prior payments, (=accrued end of period),
            //            less accrued end of prev period,  adding to net accrued this period
            //            (+) paid this period (+) additional interest paid this period (+) add'l accrued this period = Net Income Period
            double dHardInterestPaidThisPeriod              = 0D;
            double dHardInterestPaidPreviously              = 0D;
            double dAccruedThisPeriod                       = 0D;
            double dAdditionalInterestPaidThisPeriod        = 0D;
            double dAdditionalInterestAccruedThisPeriod     = 0D;
            double dAdditionalInterestAccruedPreviousPeriod = 0D;
            double dPointsPaidThisPeriod                    = 0D;
            double dAccruedFTD            = 0D;
            double dAccruedNetAtStartDate = 0D;

            // Loan-by-loan:
            //            (+) Total Accrual FTD (+) interest paid this period (-) interest paid previous periods
            //            (+) Additional Paid this period (+) additional accrued this period (-) additional accrued last period
            int iStateCount = Enum.GetNames(typeof(clsLoan.State)).Length;

            int[,] iLoansByStatus = new int[iStateCount, 2];
            int[] iUncancelledCount = new int[2];
            for (int i = 0; i < iStateCount; i++)
            {
                iLoansByStatus[i, 0] = iLoansByStatus[i, 1] = 0;
            }

            // loop through loans
            clsCSVTable tbl = new clsCSVTable(clsLoan.strLoanPath);

            for (int i = 0; i < tbl.Length(); i++)
            {
                if (this.lenderLoanIDs.Contains(i))
                {
                    clsLoan loan            = new clsLoan(i);
                    clsLoan loanAsOfEndDate = loan.LoanAsOf(endDate);
                    if (loan.FindDate(clsCashflow.Type.AcquisitionPrice, true, false) <= endDate)
                    {
                        iLoansByStatus[(int)loan.LoanAsOf(startDate).Status(), 0]++;
                        iLoansByStatus[(int)loanAsOfEndDate.Status(), 1]++;
                        dTotalLent                               += loan.Balance(endDate) + loan.PrincipalPaid(endDate);
                        dTotalRehabRemain                        += loanAsOfEndDate.RehabRemain(endDate);
                        dRepaidPeriod                            += loan.PrincipalPaid(endDate) - loan.PrincipalPaid(startDate);
                        dRepaidPreviously                        += loan.PrincipalPaid(startDate);
                        dHardInterestPaidPreviously              += loan.HardInterestPaid(startDate);
                        dHardInterestPaidThisPeriod              += loan.HardInterestPaid(endDate) - loan.HardInterestPaid(startDate);
                        dPointsPaidThisPeriod                    += loan.PointsPaid(endDate) - loan.PointsPaid(startDate);
                        dAccruedThisPeriod                       += loan.AccruedInterest(endDate) - loan.AccruedInterest(startDate);
                        dAdditionalInterestPaidThisPeriod        += loan.AdditionalInterestPaid(endDate) - loan.AdditionalInterestPaid(startDate);
                        dAdditionalInterestAccruedThisPeriod     += loan.AccruedAdditionalInterest(endDate);   // needs fixing
                        dAdditionalInterestAccruedPreviousPeriod += loan.AccruedAdditionalInterest(startDate); // needs fixing
                        dAccruedFTD                              += loan.AccruedInterest(endDate) + loan.HardInterestPaid(endDate);
                        dAccruedNetAtStartDate                   += loan.AccruedInterest(startDate);
                        if (loanAsOfEndDate.Status() == clsLoan.State.Listed)
                        {
                            dSaleListings += loan.Balance(endDate);
                        }
                        if (loanAsOfEndDate.Status() == clsLoan.State.PendingSale)
                        {
                            dSaleContracts += loan.Balance(endDate);
                        }
                        if (loanAsOfEndDate.Status() == clsLoan.State.PendingAcquisition)
                        {
                            dPendingAcq += loan.AcquisitionCost(false);
                        }
                        if (loanAsOfEndDate.Status() == clsLoan.State.PartiallySold)
                        {
                            dPartialBalance += loan.Balance(endDate);
                        }
                    }
                }
            }
            dTotalCommitted = dTotalLent + dTotalRehabRemain + dPendingAcq;
            dNetBalance     = dTotalLent - dRepaidPeriod - dRepaidPreviously;
            for (int i = 0; i < 2; i++)
            {
                iUncancelledCount[i]  = iLoansByStatus[(int)clsLoan.State.Listed, i];
                iUncancelledCount[i] += iLoansByStatus[(int)clsLoan.State.PendingAcquisition, i];
                iUncancelledCount[i] += iLoansByStatus[(int)clsLoan.State.PendingSale, i];
                iUncancelledCount[i] += iLoansByStatus[(int)clsLoan.State.Rehab, i];
                iUncancelledCount[i] += iLoansByStatus[(int)clsLoan.State.Sold, i];
                iUncancelledCount[i] += iLoansByStatus[(int)clsLoan.State.PartiallySold, i];
            }
            int iRepaidCount      = iLoansByStatus[(int)clsLoan.State.Sold, 1] - iLoansByStatus[(int)clsLoan.State.Sold, 0];
            int iOutstandingCount = iUncancelledCount[1] - iLoansByStatus[(int)clsLoan.State.Sold, 1];

            // Display Results
            this.ReportSummaryTextLabel.StringValue = "";

            this.ReportSummaryTextLabel.StringValue += " Total Committed:    \t" + dTotalCommitted.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iUncancelledCount[1].ToString("000") + ")" + "\t";

            this.ReportSummaryTextLabel.StringValue += "\n Total Loan Given:   \t" + dTotalLent.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + (iUncancelledCount[1] - iLoansByStatus[(int)clsLoan.State.PendingAcquisition, 1]).ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "FTD Accrual:    \t" + dAccruedFTD.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n Repaid Period:     \t" + dRepaidPeriod.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iRepaidCount.ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "(-)Paid Period: \t" + dHardInterestPaidThisPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n Repaid Previously: \t" + dRepaidPreviously.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iLoansByStatus[(int)clsLoan.State.Sold, 0].ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "(-)Paid Prev:   \t" + dHardInterestPaidPreviously.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n Loans Outstanding: \t" + dNetBalance.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iOutstandingCount.ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "Net Accrued:    \t" + (dAccruedFTD - dHardInterestPaidThisPeriod - dHardInterestPaidPreviously).ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t";
            this.ReportSummaryTextLabel.StringValue += "(-)Start Accr:  \t" + dAccruedNetAtStartDate.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n Sale Contracts     \t" + dSaleContracts.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iLoansByStatus[(int)clsLoan.State.PendingSale, 1].ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "Period Accr:    \t" + (dAccruedFTD - dHardInterestPaidThisPeriod - dHardInterestPaidPreviously - dAccruedNetAtStartDate).ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n Sale Listings      \t" + dSaleListings.ToString("00,000,000.00");
            this.ReportSummaryTextLabel.StringValue += "(" + iLoansByStatus[(int)clsLoan.State.Listed, 1].ToString("000") + ")" + "\t";
            this.ReportSummaryTextLabel.StringValue += "                           \t";
            this.ReportSummaryTextLabel.StringValue += "(+) Addl Paid  : \t" + dAdditionalInterestPaidThisPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t                           \t";
            this.ReportSummaryTextLabel.StringValue += "(+) Addl Accrue: \t" + dAdditionalInterestAccruedThisPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t                           \t";
            this.ReportSummaryTextLabel.StringValue += "(-) Prior Accru: \t" + dAdditionalInterestAccruedPreviousPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t";
            this.ReportSummaryTextLabel.StringValue += "(+) Additional:  \t" + (dAdditionalInterestPaidThisPeriod + dAdditionalInterestAccruedThisPeriod - dAdditionalInterestAccruedPreviousPeriod).ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t";
            this.ReportSummaryTextLabel.StringValue += "(+) Hard Paid :  \t" + dHardInterestPaidThisPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t";
            this.ReportSummaryTextLabel.StringValue += "(+) Points Paid :\t" + dPointsPaidThisPeriod.ToString("000,000.00");

            this.ReportSummaryTextLabel.StringValue += "\n                    \t                   \t";
            this.ReportSummaryTextLabel.StringValue += "Net Income Per:  \t" + (dAccruedFTD - dHardInterestPaidPreviously - dAccruedNetAtStartDate + dAdditionalInterestPaidThisPeriod + dAdditionalInterestAccruedThisPeriod - dAdditionalInterestAccruedPreviousPeriod + dPointsPaidThisPeriod).ToString("000,000.00");
        }
Esempio n. 2
0
 partial void UpdateButtonPushed(AppKit.NSButton sender)
 {
     this.SummaryMessageField.StringValue = "";
     if (this.loanToUpdate == null)
     {
         this.SummaryMessageField.StringValue = "No loan selected.  No updates made.";
     }
     else if (this.loanToUpdate.Status() != clsLoan.State.Cancelled)
     {
         // only validaton is:  are any cashflows ACTUAL
         bool   bAnyActuals = false;
         double oldAcqCost  = this.loanToUpdate.AcquisitionCost(false);
         foreach (clsCashflow cf in this.loanToUpdate.Cashflows())
         {
             if (cf.Actual())
             {
                 bAnyActuals = true;
             }
         }
         if (bAnyActuals)
         {
             this.SummaryMessageField.StringValue = "Can't update - some cashflows are marked Actual";
         }
         else
         {
             int delayDays = ((DateTime)this.ClosingDatePicker.DateValue - this.loanToUpdate.OriginationDate()).Days;
             List <clsCashflow> newCashflows = new List <clsCashflow>();
             // delete all existing scheduled cashflows
             foreach (clsCashflow cf in this.loanToUpdate.Cashflows())
             {
                 if (cf.DeleteDate() > System.DateTime.Today.AddYears(50))
                 {
                     if ((cf.TypeID() == clsCashflow.Type.NetDispositionProj) ||
                         (cf.TypeID() == clsCashflow.Type.RehabDraw))
                     {
                         newCashflows.Add(new clsCashflow(cf.PayDate().AddDays(delayDays),
                                                          System.DateTime.Today, System.DateTime.MaxValue,
                                                          this.loanToUpdate.ID(), cf.Amount(), false, cf.TypeID()));
                     }
                     cf.Delete(System.DateTime.Today);
                 }
             }
             // create all the new cashflows
             this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                           System.DateTime.Now, System.DateTime.MaxValue,
                                                           this.loanToUpdate.ID(), -this.PriceField.DoubleValue,
                                                           false, clsCashflow.Type.AcquisitionPrice));
             if (this.ConcessionField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), this.ConcessionField.DoubleValue,
                                                               false, clsCashflow.Type.AcquisitionConcession));
             }
             if (this.HOIField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.HOIField.DoubleValue,
                                                               false, clsCashflow.Type.HomeownersInsurance));
             }
             if (this.AcqTaxField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.AcqTaxField.DoubleValue,
                                                               false, clsCashflow.Type.AcquisitionTaxes));
             }
             if (this.RecordingField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.RecordingField.DoubleValue,
                                                               false, clsCashflow.Type.AcquisitionRecording));
             }
             if (this.ProcessingField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.ProcessingField.DoubleValue,
                                                               false, clsCashflow.Type.AcquisitionProcessing));
             }
             if (this.TitlePolicyField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.TitlePolicyField.DoubleValue,
                                                               false, clsCashflow.Type.TitlePolicy));
             }
             if (this.InitialDrawField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.InitialDrawField.DoubleValue,
                                                               false, clsCashflow.Type.InitialExpenseDraw));
             }
             if (this.PropertyTaxField.DoubleValue > 0)
             {
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               System.DateTime.Now, System.DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), -this.PropertyTaxField.DoubleValue,
                                                               false, clsCashflow.Type.PropertyTax));
             }
             if (loanToUpdate.Points() > 0)
             {
                 if (this.loanToUpdate.PointsCapitalized()) // if points were capitalized, capitalize them on update
                 {
                     this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                                   DateTime.Now, DateTime.MaxValue,
                                                                   this.loanToUpdate.ID(), -this.UpdatedPointsLabel.DoubleValue,
                                                                   false, clsCashflow.Type.Points));
                 }
                 // either way, add points paid at closing (to lender)
                 this.loanToUpdate.AddCashflow(new clsCashflow((DateTime)this.ClosingDatePicker.DateValue,
                                                               DateTime.Now, DateTime.MaxValue,
                                                               this.loanToUpdate.ID(), this.UpdatedPointsLabel.DoubleValue,
                                                               false, clsCashflow.Type.Points));
             }
             foreach (clsCashflow cf in newCashflows)
             {
                 if (cf.TypeID() == clsCashflow.Type.NetDispositionProj)
                 {
                     DateTime newDate = (DateTime)this.ClosingDatePicker.DateValue;
                     clsLoan  l       = loanToUpdate.LoanAsOf(newDate.AddDays(1), true);
                     this.loanToUpdate.AddCashflow(new clsCashflow(cf.PayDate(), cf.RecordDate(), cf.DeleteDate(), cf.LoanID(),
                                                                   cf.Amount() + loanToUpdate.LoanAsOf(newDate.AddDays(1), true).Balance(newDate.AddDays(1)) - oldAcqCost,
                                                                   false, clsCashflow.Type.NetDispositionProj));
                     //                                cf.Amount() + loanToUpdate.AcquisitionCost(false) - oldAcqCost, false, clsCashflow.Type.NetDispositionProj));
                 }
                 else
                 {
                     this.loanToUpdate.AddCashflow(cf);
                 }
             }
             // Update origination Date and Save
             this.loanToUpdate.SetNewOriginationDate((DateTime)this.ClosingDatePicker.DateValue);
             this.loanToUpdate.LenderID   = clsEntity.EntityID((String)(NSString)this.LenderComboBox.SelectedValue);
             this.loanToUpdate.BorrowerID = clsEntity.EntityID((String)(NSString)this.BorrowerComboBox.SelectedValue);
             if (this.loanToUpdate.Save())
             {
                 this.SummaryMessageField.StringValue += "\nSave successful.  " + this.loanToUpdate.Property().Address();
                 this.SummaryMessageField.StringValue += "\nOld / New Acquisition Cost = ";
                 this.SummaryMessageField.StringValue += oldAcqCost.ToString("#,##0.00") + " / ";
                 this.SummaryMessageField.StringValue += this.loanToUpdate.AcquisitionCost(false).ToString("#,##0.00");
                 this.UpdateTotalCostLabel();
             }
             else
             {
                 this.SummaryMessageField.StringValue += "\nSave Failed.";
             }
         }
     }
     else
     {
         this.SummaryMessageField.StringValue = "Update failed.  Loan has already been cancelled.  " + this.loanToUpdate.Property().Address();
     }
 }