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

421 lines
10 KiB

  1. <template>
  2. <div id="new" class="page">
  3. <h2>New Loan</h2>
  4. <section class="loans-list">
  5. <h3 v-for="(l, indx) in loans"
  6. :class="sel == indx ? 'sel' : ''"
  7. @click="() => sel = indx"
  8. >
  9. {{l.title}}
  10. </h3>
  11. <div class="add">
  12. <svg @click="create"
  13. xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
  14. class="bi bi-plus" viewBox="0 0 16 16"> <path d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0
  15. 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"/> </svg>
  16. </div>
  17. </section>
  18. <section class="form inputs">
  19. <h3>Loan</h3>
  20. <label>Name</label>
  21. <input :value="loans[sel].title"
  22. @input="(e) => loans[sel].title = stripLetters(e)">
  23. <button @click="del">Delete</button>
  24. </section>
  25. <section class="form inputs">
  26. <div class="hint">
  27. <img class="icon" src="/assets/image/icon/question-circle.svg" alt="">
  28. <div class="tooltip">
  29. <p>Assumes borrower is not self employed, not bankrupt in the past 7
  30. years, a citizen, and intends to occupy the property.</p>
  31. </div>
  32. </div>
  33. <h3>Borrower</h3>
  34. <label>Number of Borrowers</label>
  35. <input :value="estimate.borrowers"
  36. @input="(e) => estimate.borrowers = stripInt(e)">
  37. <label>Credit Score</label>
  38. <input :value="estimate.creditScore"
  39. @input="(e) => estimate.creditScore = stripInt(e)">
  40. <label>Monthly Income ($)</label>
  41. <input :value="estimate.mIncome"
  42. @input="(e) => estimate.mIncome = strip(e)">
  43. </section>
  44. <section class="radios form">
  45. <h3>Transaction Type</h3>
  46. <input type="radio" name="transaction_type" value="estimate.transaction"
  47. @input="e => estimate.transaction = 0"
  48. selected="estimate.transaction == 0">
  49. <label>Purchase</label>
  50. <input type="radio" name="transaction_type" value="estimate.refinance"
  51. @input="e => estimate.transaction = 1"
  52. selected="estimate.transaction == 1">
  53. <label>Refinance</label>
  54. </section>
  55. <section class="form inputs">
  56. <h3>Property Details</h3>
  57. <label>Price ($)</label>
  58. <input :value="estimate.price" @input="setPrice">
  59. <label>Type</label>
  60. <select id="" name="" v-model="estimate.property">
  61. <option value="attched">Single Family Attached</option>
  62. <option value="detached">Single Family Detached</option>
  63. <option value="lorise">Lo-rise (4 stories or less)</option>
  64. <option value="hirise">Hi-rise (over 4 stories)</option>
  65. </select>
  66. </section>
  67. <section class="radios form">
  68. <h3>Loan Type</h3>
  69. <input type="radio" name="loan_type" value="conv" v-model="loans[sel].type"
  70. >
  71. <label>Conventional</label>
  72. <input type="radio" name="loan_type" value="fha" v-model="loans[sel].type">
  73. <label>FHA</label>
  74. <input type="radio" name="loan_type" value="va" v-model="loans[sel].type">
  75. <label>VA</label>
  76. <input type="radio" name="loan_type" value="usda" v-model="loans[sel].type">
  77. <label>USDA</label>
  78. </section>
  79. <section class="form inputs">
  80. <h3>Loan Details</h3>
  81. <label>Loan Term (years)</label>
  82. <input :value="loans[sel].term"
  83. @input="(e) => loans[sel].term = strip(e)">
  84. <label>Loan Program</label>
  85. <select id="" name="" v-model="loans[sel].program">
  86. <option value="none">None</option>
  87. </select>
  88. <label>Loan to Value (%)</label>
  89. <input :value="loans[sel].ltv" @input="setLtv">
  90. <label>Loan Amount ($)</label>
  91. <input :value="loans[sel].amount"
  92. @input="setAmount">
  93. <label>Housing Expense DTI (%) - Optional</label>
  94. <input :value="loans[sel].housingDti" @input="setHousingDti">
  95. <label>Total DTI (%) - Optional</label>
  96. <input :value="loans[sel].dti" @input="setDti">
  97. <label>Home Owner's Association ($/month)</label>
  98. <input :value="loans[sel].hoa"
  99. @input="(e) => { loans[sel].hoa = strip(e) }">
  100. <label>Interest Rate (%)</label>
  101. <input :value="loans[sel].interest"
  102. @input="(e) => { loans[sel].interest = stripPerc(e) }">
  103. <label>Days of Interest</label>
  104. <input :value="loans[sel].interestDays"
  105. @input="(e) => {loans[sel].interestDays = stripInt(e)}">
  106. <label>Hazard Insurance Escrow (months)</label>
  107. <input :value="loans[sel].hazardEscrow"
  108. @input="(e) => {loans[sel].hazardEscrow = stripInt(e)}">
  109. <label>Hazard Insurance ($/month)</label>
  110. <input :value="loans[sel].hazard"
  111. @input="(e) => {loans[sel].hazard = strip(e)}">
  112. <label>Real Estate Tax Escrow (months)</label>
  113. <input :value="loans[sel].taxEscrow"
  114. @input="e => {loans[sel].taxEscrow = stripInt(e)}">
  115. <label>Real Estate Tax ($/month)</label>
  116. <input :value="loans[sel].tax"
  117. @input="(e) => {loans[sel].tax = strip(e)}">
  118. </section>
  119. <section class="form inputs">
  120. <h3>Fees</h3>
  121. <div v-for="(fee, indx) in estimate.loans[sel].fees"
  122. :key="fee.name + indx" class="fee"
  123. >
  124. <label>
  125. ${{fee.amount}} - {{fee.name}}<br>
  126. {{fee.type}}
  127. </label>
  128. <img width="21" height="21" src="/assets/image/icon/x-red.svg"
  129. @click="() => estimate.loans[sel].fees.splice(indx, 1)">
  130. </div>
  131. <button @click="resetFees">Reset</button>
  132. <button @click="createFee">New</button>
  133. </section>
  134. <Dialog v-if="newFee" @close="() => newFee = null">
  135. <h3>New Fee</h3>
  136. <label>Name</label>
  137. <input type=""
  138. :value="newFee.name"
  139. @input="(e) => newFee.name = stripLetters(e)">
  140. <label>Amount</label>
  141. <input
  142. type=""
  143. :value="newFee.amount"
  144. @input="(e) => newFee.amount = strip(e)">
  145. <select id="" name="" v-model="newFee.type">
  146. <option value="title">Title Company</option>
  147. <option value="gov">Government</option>
  148. <option value="lender">Lender</option>
  149. <option value="lender_required">Required by Lender</option>
  150. <option value="other">Other</option>
  151. </select>
  152. <button :disabled="!validFee" @click="addFee(true)">Debit</button>
  153. <button :disabled="!validFee" @click="addFee(false)">Credit</button>
  154. </Dialog>
  155. <section class="form radios">
  156. <h3>Mortgage Insurance</h3>
  157. <input type="radio" name="transaction_type" value="transaction"
  158. @input="e => estimate.transaction = 0"
  159. selected="estimate.transaction == 0">
  160. <label>1.43% - National MI</label>
  161. <input type="radio" name="transaction_type" value="refinance"
  162. @input="e => estimate.transaction = 1"
  163. selected="estimate.transaction == 1">
  164. <label>0.73% - MGIC</label>
  165. </section>
  166. <section class="form inputs">
  167. <button>Generate</button>
  168. </section>
  169. </div>
  170. </template>
  171. <script>
  172. import Dialog from "./dialog.vue"
  173. const fees = [
  174. { name: 'Processing fee', type: 'Lender Fees', amount: 500 },
  175. { name: 'Underwriting fee', type: 'Lender Fees', amount: 500 },
  176. { name: 'Credit Report', type: 'Services Required by Lender',
  177. amount: 52.50 },
  178. { name: 'Appraisal', type: 'Services Required by Lender', amount: 52.50 },
  179. { name: 'Title Services', type: 'Title Company', amount: 1000 },
  180. { name: 'Lender\'s Title Insurance', type: 'Title Company', amount: 1599 },
  181. { name: 'Owner\'s Title Insurance', type: 'Title Company', amount: 451.00 },
  182. { name: 'Recording Charges', type: 'Government', amount: 99.00 },
  183. { name: 'State Tax', type: 'Government', amount: 2411.00 },
  184. ]
  185. const example = {
  186. title: "Example",
  187. type: "",
  188. term: 0,
  189. ltv: 0, // Loan to home value ratio
  190. dti: 0,
  191. housingDti: 0,
  192. amount: 0,
  193. interest: 0,
  194. interestDays: 0,
  195. hazard: 0, // Hazard insurance monthly payment
  196. hazardEscrow: 0, // Hazard insurance escrow in months (0 is none)
  197. tax: 0, // Real Estate taxes monthly payment
  198. taxEscrow: 0, // Months to escrow (0 is none)
  199. hoa: 0, // Home owner's association monthly fee
  200. program: "",
  201. pud: true, // Property under development
  202. zip: '',
  203. fees: fees,
  204. }
  205. const loans = [
  206. Object.assign({}, example, {fees: createFees()}),
  207. Object.assign(
  208. Object.assign({}, example),
  209. {title: "Another One", fees: createFees()}
  210. ),
  211. ]
  212. const estimate = {
  213. property: "",
  214. transaction: 0,
  215. price: 0,
  216. borrowers: 0,
  217. creditScore: 0,
  218. mIncome: 0,
  219. loans: loans,
  220. }
  221. const newFee = {
  222. name: '', type: '', amount: 0
  223. }
  224. // Clone loan from initial example as a new loan
  225. function create() {
  226. this.estimate.loans.push(
  227. Object.assign({}, loans[0], {fees: createFees()})
  228. )
  229. }
  230. function createFees() {
  231. return fees.map(f => Object.assign({}, f))
  232. }
  233. // Setup this.newFee for the creation dialog
  234. function createFee() {
  235. this.newFee = Object.assign({}, newFee)
  236. }
  237. function resetFees() {
  238. this.estimate.loans[this.sel].fees = createFees()
  239. }
  240. // If valid, add the current this.newFee to the array of fees and reset
  241. // this.newFee to null
  242. function addFee(isDebit) {
  243. const fee = this.newFee
  244. if (!this.validFee) {
  245. return
  246. }
  247. if (!isDebit) fee.amount = fee.amount * -1
  248. this.estimate.loans[this.sel].fees.push(fee)
  249. this.newFee = null
  250. }
  251. function validFee() {
  252. const fee = this.newFee
  253. if (!fee.name || !fee.type || !fee.amount) {
  254. return false
  255. }
  256. return true
  257. }
  258. // Strips non-digits from an input box event and returns it's rounded integer.
  259. // It also preserves current valid entry (.)
  260. function strip(e) {
  261. let valid = e.target.value.match(/\d+\.?\d?\d?/)?.[0] ?? ""
  262. e.target.value = valid
  263. return Number(valid || 0)
  264. }
  265. function stripInt(e) {
  266. let value = parseInt(e.target.value.replace(/\D/g, '') || 0)
  267. e.target.value = value
  268. return value
  269. }
  270. function stripPerc(e) {
  271. let num = strip(e)
  272. if (num > 100) {
  273. num = 100
  274. e.target.value = num
  275. }
  276. if (num < 0) {
  277. num = 0
  278. e.target.value = num
  279. }
  280. return num
  281. }
  282. function stripLetters(e) {
  283. let value = (e.target.value.replace(/[^\w\s]/g, '').slice(0, 20) || '')
  284. e.target.value = value
  285. return value
  286. }
  287. function del() {
  288. if (this.loans.length > 1) {
  289. let x = this.sel
  290. this.sel = 0
  291. this.loans.splice(x, 1)
  292. }
  293. }
  294. // Changes loan.ltv's <input> and data() values, then syncs with data.amount
  295. function setLtv(e) {
  296. let ltv = strip(e)
  297. let loan = this.loans[this.sel]
  298. if (!this.estimate.price) return
  299. if (ltv > 100) ltv = 100
  300. if (ltv < 0) ltv = 0
  301. loan.ltv = ltv
  302. loan.amount = (ltv / 100 * this.estimate.price).toFixed(2)
  303. }
  304. // Changes loan.amount's <input> and data() values, then syncs with data.ltv
  305. function setAmount(e) {
  306. let amount = strip(e)
  307. let loan = this.loans[this.sel]
  308. if (!this.estimate.price) return
  309. if (amount > loan.price) amount = loan.price
  310. if (amount < 0) amount = 0
  311. loan.amount = amount
  312. loan.ltv = (amount / this.estimate.price * 100).toFixed(2)
  313. }
  314. // Updates the property price for all loans
  315. function setPrice(e) {
  316. let value = strip(e)
  317. this.estimate.price = value
  318. }
  319. function setDti(e) {
  320. let dti = strip(e)
  321. let loan = this.loans[this.sel]
  322. if (!loan.price) return
  323. if (dti > 100) dti = 100
  324. if (dti < 0) dti = 0
  325. e.target.value = dti
  326. loan.dti = dti
  327. }
  328. function setHousingDti(e) {
  329. let housingDti = strip(e)
  330. let loan = this.loans[this.sel]
  331. if (!loan.price) return
  332. if (housingDti > 100) housingDti = 100
  333. if (housingDti < 0) housingDti = 0
  334. e.target.value = housingDti
  335. loan.housingDti = housingDti
  336. }
  337. export default {
  338. components: { Dialog },
  339. methods: {
  340. setPrice, setLtv, setAmount, setDti, setHousingDti, strip, stripInt,
  341. stripLetters, stripPerc, del, create, createFees, createFee, resetFees,
  342. addFee
  343. },
  344. computed: {
  345. validFee,
  346. },
  347. props: ['user'],
  348. data() {
  349. return {
  350. estimate: estimate,
  351. loans: estimate.loans,
  352. sel: 0,
  353. newFee: null,
  354. }
  355. },
  356. }
  357. </script>