Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
 
 
 
 
 
 

71 lines
1.7 KiB

  1. <template>
  2. <div>
  3. <section class="form inputs">
  4. <h3>Monthly Payment - ${{totalMonthly}}</h3>
  5. <label>Loan payment: ${{loanPayment.toFixed(2)}}</label>
  6. <label v-if="loan.mi.monthly">
  7. Mortgage insurance: ${{(loanPayment*loan.mi.rate/100).toFixed(2)}}
  8. </label>
  9. <label>Property taxes: ${{loan.tax}}</label>
  10. </section>
  11. <section class="form inputs">
  12. <h3>Cash to Close - ${{totalMonthly}}</h3>
  13. <label>Closing costs: ${{fees}}</label>
  14. <label>Credits: ${{credits}}</label>
  15. <label>Downpayment: ${{downpayment.toFixed(2)}}</label>
  16. <label v-if="!loan.mi.monthly">
  17. Mortgage insurance: ${{(loanPayment*loan.mi.rate).toFixed(2)}}
  18. </label>
  19. </section>
  20. <section class="form inputs">
  21. <button>Save Estimate</button>
  22. <button>Generate PDF</button>
  23. </section>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { ref, computed } from 'vue'
  28. const props = defineProps(['downpayment', 'loan'])
  29. function amortize(principle, rate, periods) {
  30. return principle * rate*(1+rate)**periods / ((1+rate)**periods - 1)
  31. }
  32. const loanPayment = computed(() => amortize(props.loan.amount,
  33. props.loan.interest / 100 / 12,
  34. props.loan.term*12)
  35. )
  36. const totalMonthly = computed (
  37. () => (loanPayment.value +
  38. props.loan.tax +
  39. props.loan.hoa +
  40. props.loan.hazard).toFixed(2)
  41. )
  42. // Closing costs
  43. const fees = computed(() => {
  44. return props.loan.fees.reduce((total, x) => {
  45. return x.amount > 0 ? total + x.amount : 0
  46. }, 0
  47. ).toFixed(2)
  48. })
  49. const credits = computed(() => {
  50. return props.loan.fees.reduce((total, x) => {
  51. return x.amount < 0 ? total + x.amount : 0
  52. }, 0
  53. ).toFixed(2)
  54. })
  55. const cashToClose = computed(() => {
  56. return fees + credits + downpayment
  57. })
  58. </script>