Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

summary.vue 2.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div v-if="downpayment && totalMonthly > 0">
  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: ${{(loan.amount*loan.mi.rate/100/12).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 v-if="credits">Credits: ${{credits}}</label>
  15. <label>Down payment: ${{downpayment.toFixed(2)}}</label>
  16. <label v-if="!loan.mi.monthly">
  17. Mortgage insurance: ${{(loanPayment*loan.mi.rate/100).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', 'valid'])
  29. function amortize(principle, rate, periods) {
  30. return principle * rate*(1+rate)**periods / ((1+rate)**periods - 1)
  31. }
  32. const loanPayment = computed(() => {
  33. let amount = props.loan.amount
  34. if (!props.loan.mi.monthly) amount =
  35. amount + props.loan.mi.rate/100*(amount+props.downpayment)
  36. return amortize(props.loan.amount,
  37. props.loan.interest / 100 / 12,
  38. props.loan.term*12)
  39. })
  40. const totalMonthly = computed (
  41. () => (loanPayment.value +
  42. props.loan.tax +
  43. props.loan.hoa +
  44. props.loan.hazard).toFixed(2)
  45. )
  46. const totalCash = computed (
  47. () => (fees.value +
  48. credits.value +
  49. props.downpayment).toFixed(2)
  50. )
  51. // Closing costs
  52. const fees = computed(() => {
  53. return props.loan.fees.reduce((total, x) => {
  54. return x.amount > 0 ? total + x.amount : 0
  55. }, 0
  56. ).toFixed(2)
  57. })
  58. const credits = computed(() => {
  59. return props.loan.fees.reduce((total, x) => {
  60. return x.amount < 0 ? total + x.amount : 0
  61. }, 0
  62. ).toFixed(2)
  63. })
  64. const cashToClose = computed(() => {
  65. return fees + credits + downpayment
  66. })
  67. </script>