|
|
@@ -125,8 +125,6 @@ type Result struct { |
|
|
|
Fees int `json:"fees"` |
|
|
|
Credits int `json:"credits"` |
|
|
|
CashToClose int `json:"cashToClose"` |
|
|
|
Zip string `json:"zip"` |
|
|
|
Pud bool `json:"pud"` |
|
|
|
} |
|
|
|
|
|
|
|
type Estimate struct { |
|
|
@@ -140,6 +138,7 @@ type Estimate struct { |
|
|
|
Zip string `json:"zip"` |
|
|
|
Pud bool `json:"pud"` |
|
|
|
Loans []Loan `json:"loans"` |
|
|
|
Result []Result `json:"result"` |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
@@ -221,27 +220,35 @@ func summarize(w http.ResponseWriter, db *sql.DB, r *http.Request) { |
|
|
|
exp := math.Pow(1+rate, periods) |
|
|
|
return int(principle * rate * exp / (exp - 1)) |
|
|
|
} |
|
|
|
loan := estimate.Loans[0] |
|
|
|
result.LoanPayment = amortize(float64(loan.Amount), |
|
|
|
|
|
|
|
for _, loan := range estimate.Loans { |
|
|
|
// Monthly payments use amortized loan payment formula plus monthly MI, |
|
|
|
// plus all other recurring fees |
|
|
|
result.LoanPayment = amortize(float64(loan.Amount), |
|
|
|
float64(loan.Interest / 100 / 12), |
|
|
|
float64(loan.Term * 12)) |
|
|
|
result.TotalMonthly = result.LoanPayment + loan.Hoi + loan.Tax + loan.Hazard |
|
|
|
if loan.Mi.Monthly { |
|
|
|
result.TotalMonthly = result.TotalMonthly + |
|
|
|
int(loan.Mi.Rate/100*float32(loan.Amount)) |
|
|
|
} |
|
|
|
|
|
|
|
result.TotalMonthly = result.LoanPayment + loan.Hoi + loan.Tax + loan.Hazard |
|
|
|
if loan.Mi.Monthly { |
|
|
|
result.TotalMonthly = result.TotalMonthly + |
|
|
|
int(loan.Mi.Rate/100*float32(loan.Amount)) |
|
|
|
} |
|
|
|
|
|
|
|
for i := range loan.Fees { |
|
|
|
if loan.Fees[i].Amount > 0 { |
|
|
|
result.Fees = result.Fees + loan.Fees[i].Amount |
|
|
|
} else { |
|
|
|
result.Credits = result.Credits + loan.Fees[i].Amount |
|
|
|
for i := range loan.Fees { |
|
|
|
if loan.Fees[i].Amount > 0 { |
|
|
|
result.Fees = result.Fees + loan.Fees[i].Amount |
|
|
|
} else { |
|
|
|
result.Credits = result.Credits + loan.Fees[i].Amount |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
result.CashToClose = |
|
|
|
result.Fees + result.Credits + (estimate.Price - loan.Amount) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
result.CashToClose = |
|
|
|
result.Fees + result.Credits + (estimate.Price - loan.Amount) |
|
|
|
loan := estimate.Loans[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json.NewEncoder(w).Encode(result) |
|
|
|
} |
|
|
|