@@ -48,11 +48,11 @@ ${{(estimate.price / 100).toLocaleString()}} | |||
<label>Credit: {{estimate.borrower.credit}}</label> | |||
<label>Income: {{(estimate.borrower.income/100).toLocaleString()}}</label> | |||
<div v-for="(l, i) in estimate.loans" class="details"> | |||
<div v-for="l in estimate.loans" class="details"> | |||
<h4>{{l.title}}</h4> | |||
<label>{{l.type.name}}</label> | |||
<label>Total monthly: ${{format(estimate.results[i].totalMonthly)}}</label> | |||
<label>Cash to close: ${{format(estimate.results[i].cashToClose)}}</label> | |||
<label>Total monthly: ${{format(l.result.totalMonthly)}}</label> | |||
<label>Cash to close: ${{format(l.result.cashToClose)}}</label> | |||
</div> | |||
<button @click="() => $emit('preview', estimate)">Preview</button> | |||
<button @click="() => estimate = null">Cancel</button> | |||
@@ -130,8 +130,8 @@ type MI struct { | |||
Label string `json:"label"` | |||
Lender string `json:"lender"` | |||
Rate float32 `json:"rate"` | |||
Premium float32 `json:"premium"` | |||
Upfront float32 `json:"upfront"` | |||
Premium int `json:"premium"` | |||
Upfront int `json:"upfront"` | |||
Monthly bool `json:"monthly"` | |||
FiveYearTotal float32 `json:"fiveYearTotal"` | |||
InitialAllInPremium float32 `json:"initialAllInPremium"` | |||
@@ -212,17 +212,17 @@ func cache(name string, title string) Page { | |||
} | |||
func cachePdf(name string) Page { | |||
// Money is stored in cents, so it must be converted to dollars in reports | |||
dollars := func(cents int) string { | |||
return strconv.FormatFloat(float64(cents)/100, 'f', 2, 32) | |||
} | |||
// For calculating down payments | |||
diff := func(a, b int) string { | |||
return strconv.FormatFloat(float64(b - a)/100, 'f', 2, 32) | |||
} | |||
fm := template.FuncMap{ | |||
"dollars": dollars, | |||
"diff": diff, | |||
} | |||
fm := template.FuncMap{ "dollars": dollars, "diff": diff } | |||
var p = []string{"views/report/master.tpl", paths[name]} | |||
tpl := template.Must(template.New("master.tpl").Funcs(fm).ParseFiles(p...)) | |||
@@ -1837,7 +1837,7 @@ func showPDF(w http.ResponseWriter, r *http.Request) { | |||
// maybe os.Exit(1) instead | |||
} | |||
page := pages["test"] | |||
page := cachePdf("comparison") | |||
estimates, err := getEstimates(db, 1, 0) | |||
if err != nil { w.WriteHeader(500); return } | |||
@@ -1894,14 +1894,6 @@ func getPdf(w http.ResponseWriter, db *sql.DB, r *http.Request) { | |||
log.Fatal(err) | |||
} | |||
fm := template.FuncMap{ | |||
"dollars": func(cents int) string { | |||
return strconv.FormatFloat(float64(cents)/100, 'f', 2, 32) | |||
}} | |||
t := template.New("master.tpl").Funcs(fm) | |||
var pa = template.Must(t.ParseFiles("views/report/master.tpl", "views/report/comparison.tpl")) | |||
claims, err := getClaims(r) | |||
if err != nil { | |||
w.WriteHeader(500); | |||
@@ -1931,7 +1923,7 @@ func getPdf(w http.ResponseWriter, db *sql.DB, r *http.Request) { | |||
base64.StdEncoding.EncodeToString(letterhead) | |||
err = pa.ExecuteTemplate(stdin, "master.tpl", info) | |||
err = pages["test"].tpl.ExecuteTemplate(stdin, "master.tpl", info) | |||
if err != nil { | |||
w.WriteHeader(500); | |||
log.Println(err) | |||
@@ -39,41 +39,32 @@ | |||
<tr><td>Interest rate</td> | |||
{{range .Estimate.Loans}}<td>{{.Interest}}%</td>{{end}}</tr> | |||
<tr><td>Monthly MI</td> | |||
{{range .Estimate.Loans}}<td>${{.Mi.Premium}}/month</td>{{end}}</tr> | |||
<tr><td>MI Premium</td> | |||
{{range .Estimate.Loans}}<td>${{.Mi.Upfront}}</td>{{end}}</tr> | |||
{{range .Estimate.Loans}}<td>${{dollars .Mi.Premium}}/month</td>{{end}}</tr> | |||
<tr><td>Real estate taxes</td> | |||
{{range .Estimate.Loans}}<td>${{.Tax}}</td>{{end}}</tr> | |||
{{range .Estimate.Loans}}<td>${{dollars .Tax}}</td>{{end}}</tr> | |||
<tr class="total"><td>Total monthly payment</td> | |||
{{range .Estimate.Loans}}<td>{{.Result}}</td>{{end}}</tr> | |||
{{range .Estimate.Loans}}<td>${{dollars .Result.TotalMonthly}}</td>{{end}}</tr> | |||
<tr class="gap"></tr> | |||
<tr><td>Purchase price</td> | |||
{{range .Estimate.Loans}}<td>${{dollars $.Estimate.Price}}</td>{{end}}</tr> | |||
<tr><td>Loan amount</td> | |||
{{range .Estimate.Loans}}<td>${{dollars .Amount}}</td>{{end}}</tr> | |||
<tr><td>Term</td> | |||
{{range .Estimate.Loans}}<td>{{.Term}} Years</td>{{end}}</tr> | |||
<tr><td>Amortization</td> | |||
{{range .Estimate.Loans}}<td>{{.Amortization}}</td>{{end}}</tr> | |||
<tr><td>Interest rate</td> | |||
{{range .Estimate.Loans}}<td>{{.Interest}}%</td>{{end}}</tr> | |||
<tr><td>Monthly MI</td> | |||
{{range .Estimate.Loans}}<td>${{.Mi.Premium}}/month</td>{{end}}</tr> | |||
<tr><td>Down payment</td> | |||
{{range .Estimate.Loans}}<td>${{diff .Amount $.Estimate.Price}}</td>{{end}}</tr> | |||
<tr><td>Closing costs</td> | |||
{{range .Estimate.Loans}}<td>${{dollars .Result.TotalFees}}</td>{{end}}</tr> | |||
<tr><td>MI Premium</td> | |||
{{range .Estimate.Loans}}<td>${{.Mi.Upfront}}</td>{{end}}</tr> | |||
<tr><td>Real estate taxes</td> | |||
{{range .Estimate.Loans}}<td>${{.Tax}}</td>{{end}}</tr> | |||
<tr class="total"><td>Total monthly payment</td> | |||
{{range .Estimate.Loans}}<td>{{.Result.TotalMonthly}}</td>{{end}}</tr> | |||
<tr><td>Purchase price</td> | |||
{{range .Estimate.Loans}}<td>${{dollars $.Estimate.Price}}</td>{{end}}</tr> | |||
<tr><td>Credits</td> | |||
{{range .Estimate.Loans}}<td>${{dollars .Result.TotalCredits}}</td>{{end}}</tr> | |||
</tbody> | |||
</table> | |||
<div class="break"></div> | |||
<section class="summary"> | |||
<div class="box"> | |||
{{.Estimate}} | |||
hello | |||
</div> | |||
</section> | |||
@@ -116,6 +107,31 @@ header.heading { | |||
header.heading .user-info { | |||
margin-right: 8px; | |||
} | |||
table { | |||
width: 100%; | |||
margin-top: 20px; | |||
} | |||
tr.gap { | |||
height: 20px; | |||
} | |||
table td:first-child { | |||
font-weight: bold; | |||
} | |||
tbody tr:nth-child(odd) { | |||
background: #F5F5F3; | |||
} | |||
table td { | |||
padding: 4px; | |||
} | |||
div.break { | |||
page-break-after: always; | |||
} | |||
</style> | |||
{{end}} | |||