|
|
@@ -21,11 +21,11 @@ type Page struct { |
|
|
|
Name string |
|
|
|
} |
|
|
|
|
|
|
|
type LoanType struct { |
|
|
|
Id int `json:"id"` |
|
|
|
User int `json:"user"` |
|
|
|
Branch int `json:"branch"` |
|
|
|
Name string `json:"name"` |
|
|
|
type Borrower struct { |
|
|
|
Id int `json:"id"` |
|
|
|
Credit int `json:"credit"` |
|
|
|
Income int `json:"income"` |
|
|
|
Num int `json:"num"` |
|
|
|
} |
|
|
|
|
|
|
|
type FeeTemplate struct { |
|
|
@@ -41,34 +41,52 @@ type FeeTemplate struct { |
|
|
|
Auto bool `json:"auto"` |
|
|
|
} |
|
|
|
|
|
|
|
type Fee struct { |
|
|
|
Id int `json:"id"` |
|
|
|
LoanId int `json:"loan_id"` |
|
|
|
Amount int `json:"amount"` |
|
|
|
Perc int `json:"perc"` |
|
|
|
Type string `json:"type"` |
|
|
|
Notes string `json:"notes"` |
|
|
|
Name string `json:"name"` |
|
|
|
Category string `json:"category"` |
|
|
|
} |
|
|
|
|
|
|
|
type LoanType struct { |
|
|
|
Id int `json:"id"` |
|
|
|
User int `json:"user"` |
|
|
|
Branch int `json:"branch"` |
|
|
|
Name string `json:"name"` |
|
|
|
} |
|
|
|
|
|
|
|
type Loan struct { |
|
|
|
Id int `json:id` |
|
|
|
EstimateId int `json:estimate_id` |
|
|
|
Type LoanType `json:"loanType"` |
|
|
|
LoanAmount int `json:"loanAmount"` |
|
|
|
Term int `json:"term"` |
|
|
|
Ltv int `json:"ltv"` |
|
|
|
Dti int `json:"dti"` |
|
|
|
Hoi int `json:"hoi"` |
|
|
|
Interest int `json:"interest"` |
|
|
|
Lender string `json:"lender"` |
|
|
|
MiName string `json:"miName"` |
|
|
|
MiAmount int `json:"miAmount"` |
|
|
|
Fees []Fee `json:"fees"` |
|
|
|
Name string `json:"name"` |
|
|
|
} |
|
|
|
|
|
|
|
type Estimate struct { |
|
|
|
Id int `json:"id"` |
|
|
|
User int `json:"user"` |
|
|
|
Borrower Borrower `json:"borrower"` |
|
|
|
Comparison int `json:"comparison"` |
|
|
|
Transaction string `json:"transaction"` |
|
|
|
LoanType LoanType `json:"loanType"` |
|
|
|
LoanAmount int `json:"loanAmount"` |
|
|
|
Price int `json:"price"` |
|
|
|
Property string `json:"property"` |
|
|
|
Occupancy string `json:"occupancy"` |
|
|
|
Zip string `json:"zip"` |
|
|
|
Pud bool `json:"pud"` |
|
|
|
Term int `json:"term"` |
|
|
|
Interest int `json:"interest"` |
|
|
|
Hoi int `json:"hoi"` |
|
|
|
MiName string `json:"miName"` |
|
|
|
MiAmount int `json:"miAmount"` |
|
|
|
Lender string `json:"lender"` |
|
|
|
Name string `json:"name"` |
|
|
|
Fees []Fee `json:"fees"` |
|
|
|
} |
|
|
|
|
|
|
|
type Borrower struct { |
|
|
|
Id int `json:"id"` |
|
|
|
Credit int `json:"credit"` |
|
|
|
Income int `json:"income"` |
|
|
|
Num int `json:"num"` |
|
|
|
Loans []Loan `json:"loans"` |
|
|
|
} |
|
|
|
|
|
|
|
var ( |
|
|
@@ -165,31 +183,24 @@ func getLoanType( |
|
|
|
func getEstimate(db *sql.DB, id int) (Estimate, error) { |
|
|
|
var estimate Estimate |
|
|
|
|
|
|
|
// Inner join should always be valid because a borrower is a required |
|
|
|
// foreign key. |
|
|
|
row := db.QueryRow( |
|
|
|
"SELECT * FROM estimate " + |
|
|
|
"WHERE id = ? LIMIT 1", |
|
|
|
"SELECT * FROM estimate "+ |
|
|
|
"WHERE id = ? " + |
|
|
|
"INNER JOIN borrower ON estimate.borrower = borrower.id", |
|
|
|
id) |
|
|
|
|
|
|
|
if err := row.Scan( |
|
|
|
&estimate.Id, |
|
|
|
&estimate.User, |
|
|
|
&estimate.Borrower.Id, |
|
|
|
&estimate.Comparison, |
|
|
|
&estimate.Transaction, |
|
|
|
&estimate.LoanType.Id, |
|
|
|
&estimate.LoanAmount, |
|
|
|
&estimate.Price, |
|
|
|
&estimate.Property, |
|
|
|
&estimate.Occupancy, |
|
|
|
&estimate.Zip, |
|
|
|
&estimate.Pud, |
|
|
|
&estimate.Term, |
|
|
|
&estimate.Interest, |
|
|
|
&estimate.Hoi, |
|
|
|
&estimate.MiName, |
|
|
|
&estimate.MiAmount, |
|
|
|
&estimate.Lender, |
|
|
|
&estimate.Name, |
|
|
|
) |
|
|
|
err != nil { |
|
|
|
return estimate, fmt.Errorf("Estimate scanning error: %v", err) |
|
|
@@ -198,8 +209,45 @@ func getEstimate(db *sql.DB, id int) (Estimate, error) { |
|
|
|
return estimate, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getFees(db *sql.DB, loan int) ([]Fee, error) { |
|
|
|
var fees []Fee |
|
|
|
|
|
|
|
rows, err := db.Query( |
|
|
|
"SELECT * FROM fees " + |
|
|
|
"WHERE loan_id = ?", |
|
|
|
loan) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("Fee query error %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
for rows.Next() { |
|
|
|
var fee FeeTemplate |
|
|
|
|
|
|
|
if err := rows.Scan( |
|
|
|
&fee.Id, |
|
|
|
&fee.LoanId, |
|
|
|
&fee.Amount, |
|
|
|
&fee.Perc, |
|
|
|
&fee.Ftype, |
|
|
|
&fee.Notes, |
|
|
|
&fee.Name, |
|
|
|
&fee.Category, |
|
|
|
) |
|
|
|
err != nil { |
|
|
|
return nil, fmt.Errorf("Fees scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
|
} |
|
|
|
|
|
|
|
return fees, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Fetch fees from the database |
|
|
|
func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
func getFeesTemp(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
var fees []FeeTemplate |
|
|
|
|
|
|
|
rows, err := db.Query( |
|
|
@@ -208,7 +256,7 @@ func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
user) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("Fee query error %v", err) |
|
|
|
return nil, fmt.Errorf("Fee template query error %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
defer rows.Close() |
|
|
@@ -222,13 +270,57 @@ func getFees(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
&fee.Branch, |
|
|
|
&fee.Amount, |
|
|
|
&fee.Perc, |
|
|
|
&fee.Type, |
|
|
|
&fee.Notes, |
|
|
|
&fee.Name, |
|
|
|
&fee.Category, |
|
|
|
&fee.Auto) |
|
|
|
err != nil { |
|
|
|
return nil, fmt.Errorf("FeesTemplate scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
|
} |
|
|
|
|
|
|
|
est, err := getEstimate(db, 1) |
|
|
|
fmt.Printf("the estimate: %v,\nthe error %v\n", est, err) |
|
|
|
// getMi(db, getEstimate(db, 1), getBorrower(db, 1)) |
|
|
|
|
|
|
|
return fees, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getLoans(db *sql.DB, estimate int) { |
|
|
|
var loans []Loan |
|
|
|
|
|
|
|
rows, err := db.Query( |
|
|
|
"SELECT loan.id, loan.amount, loan.term, loan.interest, loan.ltv, |
|
|
|
loan.dti, loan.hoi, loan.mi_name, loan.mi_amount FROM loan " + |
|
|
|
"INNER JOIN loan_type ON loan.type_id = loan_type(id)" + |
|
|
|
"WHERE loan.estimate_id = ?", |
|
|
|
estimate) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("Loan query error %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
for rows.Next() { |
|
|
|
var loan Loan |
|
|
|
|
|
|
|
if err := rows.Scan( |
|
|
|
&loan.Id, |
|
|
|
&loan.EstimateId, |
|
|
|
&loan.Branch, |
|
|
|
&fee.Amount, |
|
|
|
&fee.Perc, |
|
|
|
&fee.Ftype, |
|
|
|
&fee.Notes, |
|
|
|
&fee.Name, |
|
|
|
&fee.Category, |
|
|
|
&fee.Auto) |
|
|
|
err != nil { |
|
|
|
return nil, fmt.Errorf("Fees scanning error: %v", err) |
|
|
|
return nil, fmt.Errorf("FeesTemplate scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
@@ -387,7 +479,7 @@ func api(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
case match(p, "/api/fees", &args): |
|
|
|
resp, err := getFees(db, 0) |
|
|
|
resp, err := getFeesTemp(db, 0) |
|
|
|
|
|
|
|
if resp != nil { |
|
|
|
json.NewEncoder(w).Encode(resp) |
|
|
|