|
|
@@ -1018,11 +1018,66 @@ func insertBorrower(db *sql.DB, borrower Borrower) (int, error) { |
|
|
|
return id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func insertMi(db *sql.DB, mi MI) (int, error) { |
|
|
|
var id int |
|
|
|
|
|
|
|
query := `INSERT INTO mi |
|
|
|
( |
|
|
|
type, |
|
|
|
label, |
|
|
|
lender, |
|
|
|
rate, |
|
|
|
premium, |
|
|
|
upfront, |
|
|
|
five_year_total, |
|
|
|
initial_premium, |
|
|
|
initial_rate, |
|
|
|
initial_amount |
|
|
|
) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?) |
|
|
|
RETURNING id` |
|
|
|
|
|
|
|
row := db.QueryRow(query, |
|
|
|
&mi.Type, |
|
|
|
&mi.Label, |
|
|
|
&mi.Lender, |
|
|
|
&mi.Rate, |
|
|
|
&mi.Premium, |
|
|
|
&mi.Upfront, |
|
|
|
&mi.FiveYearTotal, |
|
|
|
&mi.InitialAllInPremium, |
|
|
|
&mi.InitialAllInRate, |
|
|
|
&mi.InitialAmount, |
|
|
|
) |
|
|
|
|
|
|
|
err := row.Scan(&id) |
|
|
|
if err != nil { return 0, err } |
|
|
|
|
|
|
|
return id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func insertFee(db *sql.DB, fee Fee) (int, error) { |
|
|
|
var id int |
|
|
|
|
|
|
|
query := `INSERT INTO fee |
|
|
|
id, loan_id, amount, perc, type, notes, name, category |
|
|
|
FROM fee |
|
|
|
WHERE loan_id = ?` |
|
|
|
(loan_id, amount, perc, type, notes, name, category) |
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?) |
|
|
|
RETURNING id` |
|
|
|
|
|
|
|
row := db.QueryRow(query, |
|
|
|
fee.LoanId, |
|
|
|
fee.Amount, |
|
|
|
fee.Perc, |
|
|
|
fee.Type, |
|
|
|
fee.Notes, |
|
|
|
fee.Name, |
|
|
|
fee.Category, |
|
|
|
) |
|
|
|
|
|
|
|
err := row.Scan(&id) |
|
|
|
if err != nil { return 0, err } |
|
|
|
|
|
|
|
return id, nil |
|
|
|
} |
|
|
|
|
|
|
|
func insertLoan(db *sql.DB, loan Loan) (Loan, error){ |
|
|
@@ -1061,7 +1116,13 @@ func insertLoan(db *sql.DB, loan Loan) (Loan, error){ |
|
|
|
) |
|
|
|
|
|
|
|
err = row.Scan(&id) |
|
|
|
if err != nil { return Loan{}, err } |
|
|
|
if err != nil { return loan, err } |
|
|
|
_, err = insertMi(db, loan.Mi) |
|
|
|
if err != nil { return loan, err } |
|
|
|
for i := range loan.Fees { |
|
|
|
_, err := insertFee(db, loan.Fees[i]) |
|
|
|
if err != nil { return loan, err } |
|
|
|
} |
|
|
|
|
|
|
|
loans, err := getLoans(db, id, 0) |
|
|
|
if err != nil { return Loan{}, err } |
|
|
|