|
|
@@ -34,7 +34,7 @@ type FeeTemplate struct { |
|
|
|
Branch int `json:"branch"` |
|
|
|
Amount int `json:"amount"` |
|
|
|
Perc int `json:"perc"` |
|
|
|
Ftype string `json:"type"` |
|
|
|
Type string `json:"type"` |
|
|
|
Notes string `json:"notes"` |
|
|
|
Name string `json:"name"` |
|
|
|
Category string `json:"category"` |
|
|
@@ -63,7 +63,7 @@ type Loan struct { |
|
|
|
Id int `json:id` |
|
|
|
EstimateId int `json:estimate_id` |
|
|
|
Type LoanType `json:"loanType"` |
|
|
|
LoanAmount int `json:"loanAmount"` |
|
|
|
Amount int `json:"loanAmount"` |
|
|
|
Term int `json:"term"` |
|
|
|
Ltv int `json:"ltv"` |
|
|
|
Dti int `json:"dti"` |
|
|
@@ -224,14 +224,14 @@ func getFees(db *sql.DB, loan int) ([]Fee, error) { |
|
|
|
defer rows.Close() |
|
|
|
|
|
|
|
for rows.Next() { |
|
|
|
var fee FeeTemplate |
|
|
|
var fee Fee |
|
|
|
|
|
|
|
if err := rows.Scan( |
|
|
|
&fee.Id, |
|
|
|
&fee.LoanId, |
|
|
|
&fee.Amount, |
|
|
|
&fee.Perc, |
|
|
|
&fee.Ftype, |
|
|
|
&fee.Type, |
|
|
|
&fee.Notes, |
|
|
|
&fee.Name, |
|
|
|
&fee.Category, |
|
|
@@ -289,15 +289,17 @@ func getFeesTemp(db *sql.DB, user int) ([]FeeTemplate, error) { |
|
|
|
return fees, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getLoans(db *sql.DB, estimate int) { |
|
|
|
func getLoans(db *sql.DB, estimate int) ([]Loan, error) { |
|
|
|
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) |
|
|
|
query := `SELECT |
|
|
|
loan.id, loan.amount, loan.term, loan.interest, loan.ltv, loan.dti, |
|
|
|
loan.hoi, loan.mi_name, loan.mi_amount |
|
|
|
loan_type.id, loan_type.user_id, loan_type.branch_id, loan_type.name |
|
|
|
FROM loan INNER JOIN loan_type ON loan.type_id = loan_type(id) |
|
|
|
WHERE loan.estimate_id = ? |
|
|
|
` |
|
|
|
rows, err := db.Query(query, estimate) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return nil, fmt.Errorf("Loan query error %v", err) |
|
|
@@ -310,27 +312,31 @@ func getLoans(db *sql.DB, estimate int) { |
|
|
|
|
|
|
|
if err := rows.Scan( |
|
|
|
&loan.Id, |
|
|
|
&loan.EstimateId, |
|
|
|
&loan.Branch, |
|
|
|
&fee.Amount, |
|
|
|
&fee.Perc, |
|
|
|
&fee.Ftype, |
|
|
|
&fee.Notes, |
|
|
|
&fee.Name, |
|
|
|
&fee.Category, |
|
|
|
&fee.Auto) |
|
|
|
&loan.Amount, |
|
|
|
&loan.Term, |
|
|
|
&loan.Interest, |
|
|
|
&loan.Ltv, |
|
|
|
&loan.Dti, |
|
|
|
&loan.Hoi, |
|
|
|
&loan.MiName, |
|
|
|
&loan.MiAmount, |
|
|
|
&loan.Type.Id, |
|
|
|
&loan.Type.User, |
|
|
|
&loan.Type.Branch, |
|
|
|
&loan.Type.Name, |
|
|
|
) |
|
|
|
err != nil { |
|
|
|
return nil, fmt.Errorf("FeesTemplate scanning error: %v", err) |
|
|
|
return loans, fmt.Errorf("Loans scanning error: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
fees = append(fees, fee) |
|
|
|
loans = append(loans, loan) |
|
|
|
} |
|
|
|
|
|
|
|
est, err := getEstimate(db, 1) |
|
|
|
fmt.Printf("the estimate: %v,\nthe error %v\n", est, err) |
|
|
|
fmt.Printf("the loan: %v,\nthe error %v\n", est, err) |
|
|
|
// getMi(db, getEstimate(db, 1), getBorrower(db, 1)) |
|
|
|
|
|
|
|
return fees, nil |
|
|
|
return loans, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getBorrower(db *sql.DB, id int) (Borrower, error) { |
|
|
@@ -403,7 +409,7 @@ func getMi(db *sql.DB, estimate Estimate, borrower Borrower) { |
|
|
|
"propertyTypeCode": propertyCodes[estimate.Property], |
|
|
|
"occupancyTypeCode": "PRS", |
|
|
|
"loanPurposeCode": "PUR", |
|
|
|
"loanAmount": strconv.Itoa(estimate.LoanAmount / 100), |
|
|
|
"loanAmount": strconv.Itoa(500000 / 100), |
|
|
|
"loanToValue": "LTV95", |
|
|
|
"amortizationTerm": "A30", |
|
|
|
"loanTypeCode": "FXD", |
|
|
|