Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

291 lines
7.4 KiB

  1. <template>
  2. <div>
  3. <section class="form inputs">
  4. <h3>Loan</h3>
  5. <label>Name</label>
  6. <input :value="loan.title" required
  7. @input="(e) => $emit('update:name', stripLetters(e))">
  8. <button @click="() => $emit('del')">Delete</button>
  9. </section>
  10. <section class="form inputs">
  11. <div class="hint">
  12. <img class="icon" src="/assets/image/icon/question-circle.svg" alt="">
  13. <div class="tooltip">
  14. <p>Assumes borrower is not self employed, not bankrupt in the past 7
  15. years, a citizen, and intends to occupy the property.</p>
  16. </div>
  17. </div>
  18. <h3>Borrower</h3>
  19. <label>Number of Borrowers</label>
  20. <input :value="estimate.borrower.num"
  21. @input="(e) => $emit('update:borrowerNum', stripInt(e))">
  22. <label>Credit Score</label>
  23. <input :value="estimate.borrower.credit"
  24. @input="(e) => $emit('update:borrowerCredit', stripInt(e))">
  25. <label>Monthly Income ($)</label>
  26. <input :value="estimate.borrower.income"
  27. @input="(e) => $emit('update:borrowerIncome', strip(e))">
  28. </section>
  29. <section class="radios form">
  30. <h3>Transaction Type</h3>
  31. <input selected type="radio" name="transaction_type" value="0"
  32. :value="estimate.transaction"
  33. @input="() => $emit('update:transaction', 0)"
  34. >
  35. <label>Purchase</label>
  36. <input type="radio" name="transaction_type" value="1"
  37. :value="estimate.transaction"
  38. @input="() => $emit('update:transaction', 1)"
  39. >
  40. <label>Refinance</label>
  41. </section>
  42. <section class="form inputs">
  43. <h3>Property Details</h3>
  44. <label>Price ($)</label>
  45. <input :value="estimate.price" @input="(e) => $emit('update:price', strip(e))">
  46. <label>Type</label>
  47. <select id="" name=""
  48. :value="estimate.property"
  49. @change="(e) => $emit('update:property', e.target.value)">
  50. <option value="attched">Single Family Attached</option>
  51. <option value="detached">Single Family Detached</option>
  52. <option value="lorise">Lo-rise (4 stories or less)</option>
  53. <option value="hirise">Hi-rise (over 4 stories)</option>
  54. </select>
  55. </section>
  56. <section class="radios form">
  57. <h3>Loan Type</h3>
  58. <input type="radio"
  59. name="loan_type"
  60. :checked="loan.type.id == 1"
  61. value="1"
  62. @change="(e) => $emit('update:loanType', e.target.value)"
  63. >
  64. <label>Conventional</label>
  65. <input type="radio"
  66. name="loan_type"
  67. value="2"
  68. :checked="loan.type.id == 2"
  69. @change="(e) => $emit('update:loanType', e.target.value)">
  70. <label>FHA</label>
  71. <input type="radio"
  72. name="loan_type"
  73. value="3"
  74. :checked="loan.type.id == 3"
  75. @change="(e) => $emit('update:loanType', e.target.value)">
  76. <label>VA</label>
  77. <input type="radio"
  78. name="loan_type"
  79. value="4"
  80. :checked="loan.type.id == 4"
  81. @change="(e) => $emit('update:loanType', e.target.value)">
  82. <label>USDA</label>
  83. </section>
  84. <section class="form inputs">
  85. <h3>Loan Details</h3>
  86. <label>Loan Term (years)</label>
  87. <input :value="loan.term"
  88. @input="(e) => $emit('update:term', stripInt(e))">
  89. <label>Loan Program</label>
  90. <select id="" name=""
  91. :value="loan.program"
  92. @change="(e) => $emit('update:program', e.target.value)">
  93. <option value="none">None</option>
  94. </select>
  95. <label>Loan to Value (%)</label>
  96. <input :value="loan.ltv" @input="(e) => $emit('update:ltv', e)">
  97. <label>Loan Amount ($)</label>
  98. <input :value="loan.amount"
  99. @input="(e) => $emit('update:amount', e)">
  100. <label>Housing Expense DTI (%) - Optional</label>
  101. <input :value="loan.housingDti"
  102. @input="(e) => $emit('update:housingDti', e)">
  103. <label>Total DTI (%) - Optional</label>
  104. <input :value="loan.dti" @input="(e) => $emit('update:dti', e)">
  105. <label>Home Owner's Association ($/month)</label>
  106. <input :value="loan.hoa"
  107. @input="(e) => { $emit('update:hoa', strip(e)) }">
  108. <label>Interest Rate (%)</label>
  109. <input :value="loan.interest"
  110. @input="(e) => { $emit('update:interest', stripPerc(e)) }">
  111. <label>Days of Interest</label>
  112. <input :value="loan.interestDays"
  113. @input="(e) => $emit('update:interestDays', stripInt(e))">
  114. <label>Hazard Insurance Escrow (months)</label>
  115. <input :value="loan.hazardEscrow"
  116. @input="(e) => { $emit('update:hazardEscrow', stripInt(e)) }">
  117. <label>Hazard Insurance ($/month)</label>
  118. <input :value="loan.hazard"
  119. @input="(e) => $emit('update:hazard', strip(e))">
  120. <label>Real Estate Tax Escrow (months)</label>
  121. <input :value="loan.taxEscrow"
  122. @input="e => $emit('update:taxEscrow', stripInt(e))">
  123. <label>Real Estate Tax ($/month)</label>
  124. <input :value="loan.tax"
  125. @input="(e) => $emit('update:tax', strip(e))">
  126. </section>
  127. <section class="form inputs">
  128. <h3>Fees</h3>
  129. <div v-for="(fee, indx) in loan.fees"
  130. :key="fee.name + indx" class="fee"
  131. >
  132. <label>
  133. ${{fee.amount}}{{ fee.perc ? ` ${fee.perc}%` : ''}} - {{fee.name}}<br>
  134. {{fee.type}}
  135. </label>
  136. <img width="21" height="21" src="/assets/image/icon/x-red.svg"
  137. @click="() => loan.fees.splice(indx, 1)">
  138. </div>
  139. <button @click="resetFees">Reset</button>
  140. <button @click="createFee">New</button>
  141. </section>
  142. <fee-dialog v-if="newFee"
  143. :heading="'New Fee'"
  144. :initial="{}"
  145. :price="estimate.price"
  146. @close="() => newFee = null"
  147. @save="addFee"
  148. />
  149. <section class="form inputs mi">
  150. <h3>Mortgage Insurance</h3>
  151. <div class="row">
  152. <input checked type="radio" name="mi"/><label>Manual %</label>
  153. <input type="checkbox" :checked="loan.mi.monthly"
  154. @change="e => $emit('toggle:manualMIMonthly')" />
  155. <label>monthly</label>
  156. </div>
  157. <div class="row">
  158. <input :value="loan.mi.rate" @input="e => $emit('update:manualMI', stripPerc(e))" />
  159. </div>
  160. </section>
  161. <section class="form inputs">
  162. <button @click="validate">Continue</button>
  163. <ul class="errors">
  164. <li v-for="e in errors">{{e}}</li>
  165. </ul>
  166. </section>
  167. </div>
  168. </template>
  169. <script>
  170. import FeeDialog from "../fee-dialog.vue"
  171. import { stripLetters, strip, stripInt, stripPerc } from "../../helpers.js"
  172. const newFee = {
  173. name: '', type: '', amount: 0, perc: 0
  174. }
  175. // Setup this.newFee for the creation dialog
  176. function createFee() {
  177. this.newFee = Object.assign({}, newFee)
  178. }
  179. // If valid, add the current this.newFee to the array of fees and reset
  180. // this.newFee to null
  181. function addFee(fee, isDebit) {
  182. if (!isDebit) fee.amount = fee.amount * -1
  183. this.loan.fees.push(fee)
  184. this.newFee = null
  185. }
  186. function validate() {
  187. fetch(`/api/estimate/validate`,
  188. {method: 'POST',
  189. body: JSON.stringify(this.estimate),
  190. headers: {
  191. "Accept": "application/json",
  192. "Authorization": `Bearer ${this.token}`,
  193. },
  194. }).then(resp => {
  195. if (resp.ok && resp.status == 200) {
  196. this.errors = []
  197. this.$emit('continue')
  198. return
  199. } else {
  200. resp.text().then(t => this.errors = [t])
  201. }
  202. })
  203. }
  204. function generate() {
  205. const errors = this.validate()
  206. if (errors.length) {
  207. this.errors = errors
  208. return
  209. }
  210. }
  211. export default {
  212. components: { FeeDialog },
  213. methods: {
  214. strip, stripInt, stripLetters, stripPerc, createFee, addFee, validate,
  215. generate
  216. },
  217. props: ['estimate', 'loan', 'token'],
  218. // Loan updates assume the currently selected loan is being modified, and
  219. // $emit has no need to clarify.
  220. emits: [
  221. 'del',
  222. 'update:name',
  223. 'update:borrowerNum',
  224. 'update:borrowerCredit',
  225. 'update:borrowerIncome',
  226. 'update:transaction',
  227. 'update:price',
  228. 'update:property',
  229. // Loan specific emits
  230. 'update:loanType',
  231. 'update:term',
  232. 'update:program',
  233. 'update:ltv',
  234. 'update:amount',
  235. 'update:housingDti',
  236. 'update:dti',
  237. 'update:hoa',
  238. 'update:interest',
  239. 'update:interestDays',
  240. 'update:hazardEscrow',
  241. 'update:hazard',
  242. 'update:taxEscrow',
  243. 'update:tax',
  244. 'update:manualMI',
  245. 'toggle:manualMIMonthly',
  246. 'continue'
  247. ],
  248. data() {
  249. return {
  250. newFee: null,
  251. errors: [],
  252. hash: window.location.hash
  253. }
  254. },
  255. created() {
  256. }
  257. }
  258. </script>