|
|
@@ -27,6 +27,41 @@ |
|
|
|
@save="newFee" |
|
|
|
/> |
|
|
|
|
|
|
|
<section class="inputs estimates"> |
|
|
|
<h3>Templates</h3> |
|
|
|
|
|
|
|
<div class="entry" v-for="t in templates" v-if="!template" |
|
|
|
@click="() => template = t" key="t.id"> |
|
|
|
<span> |
|
|
|
{{t.estimate.id}} - {{t.estimate.property}} - ${{(t.estimate.price/100).toLocaleString()}} |
|
|
|
</span> |
|
|
|
</div> |
|
|
|
|
|
|
|
<div class="details" v-if="template"> |
|
|
|
<label> |
|
|
|
#{{template.estimate.id}} - |
|
|
|
|
|
|
|
|
|
|
|
{{template.estimate.transaction}} - |
|
|
|
{{template.estimate.property}} - |
|
|
|
${{(template.estimate.price / 100).toLocaleString()}} |
|
|
|
</label> |
|
|
|
<label>Borrowers: {{template.estimate.borrower.num}}</label> |
|
|
|
<label>Credit: {{template.estimate.borrower.credit}}</label> |
|
|
|
<label>Income: {{(template.estimate.borrower.income/100).toLocaleString()}}</label> |
|
|
|
|
|
|
|
<div v-for="l in template.estimate.loans" class="details"> |
|
|
|
<h4>{{l.title}}</h4> |
|
|
|
<label>{{l.type.name}}</label> |
|
|
|
<label>Total monthly: ${{format(l.result.totalMonthly)}}</label> |
|
|
|
<label>Cash to close: ${{format(l.result.cashToClose)}}</label> |
|
|
|
</div> |
|
|
|
<button @click="() => download(template.estimate)">Generate PDF</button> |
|
|
|
<button @click="() => deleting = true">Remove</button> |
|
|
|
<button @click="() => template = null">Cancel</button> |
|
|
|
</div> |
|
|
|
</section> |
|
|
|
|
|
|
|
<section class="inputs estimates"> |
|
|
|
<h3>Saved Estimates</h3> |
|
|
|
|
|
|
@@ -55,7 +90,8 @@ ${{(estimate.price / 100).toLocaleString()}} |
|
|
|
<label>Cash to close: ${{format(l.result.cashToClose)}}</label> |
|
|
|
</div> |
|
|
|
<button @click="() => download(estimate)">Generate PDF</button> |
|
|
|
<button @click="() => deleting = true">Delete</button> |
|
|
|
<button @click="() => saveTemplate(estimate)">Save As Template</button> |
|
|
|
<button @click="() => deleting = true" :disabled="isTemplate()">Delete</button> |
|
|
|
<button @click="() => estimate = null">Cancel</button> |
|
|
|
</div> |
|
|
|
|
|
|
@@ -67,7 +103,7 @@ ${{(estimate.price / 100).toLocaleString()}} |
|
|
|
|
|
|
|
<Dialog v-if="deleting" @close="() => deleting = false"> |
|
|
|
<h3>Are you sure you want to delete this estimate?</h3> |
|
|
|
<button @click="() => del(estimate)">Confirm</button> |
|
|
|
<button @click="() => del(estimate ?? template.estimate)">Confirm</button> |
|
|
|
</Dialog> |
|
|
|
|
|
|
|
</div> |
|
|
@@ -84,7 +120,9 @@ const props = defineProps(['user', 'fees', 'token']) |
|
|
|
const emit = defineEmits(['addFeeTemp', 'removeFeeTemp', 'preview']) |
|
|
|
let edit = ref(null) |
|
|
|
let estimates = ref([]) |
|
|
|
let templates = ref([]) |
|
|
|
let estimate = ref() |
|
|
|
let template = ref() |
|
|
|
let dlink = ref("") |
|
|
|
let deleting = ref() |
|
|
|
|
|
|
@@ -146,7 +184,37 @@ function getEstimates() { |
|
|
|
}).then (result => { |
|
|
|
if (!result || !result.length) return // Exit if token is invalid or no fees are saved |
|
|
|
estimates.value = result |
|
|
|
// console.log(result) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function getTemplates() { |
|
|
|
fetch(`/api/estimate/templates`, |
|
|
|
{method: 'GET', |
|
|
|
headers: { |
|
|
|
"Accept": "application/json", |
|
|
|
"Authorization": `Bearer ${props.token}`, |
|
|
|
}, |
|
|
|
}).then(response => { |
|
|
|
if (response.ok) { return response.json() } else { |
|
|
|
response.text().then(t => console.log(t)) |
|
|
|
} |
|
|
|
}).then (result => { |
|
|
|
if (!result || !result.length) return // Exit if token is invalid or no fees are saved |
|
|
|
templates.value = result |
|
|
|
console.log(result) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function saveTemplate(e) { |
|
|
|
fetch(`/api/estimate/templates`, |
|
|
|
{method: 'POST', |
|
|
|
body: JSON.stringify(e), |
|
|
|
headers: { |
|
|
|
"Accept": "application/json", |
|
|
|
"Authorization": `Bearer ${props.token}`, |
|
|
|
}, |
|
|
|
}).then(response => { |
|
|
|
if (response.ok) { getTemplates() } |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@@ -167,6 +235,23 @@ function del(e) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function remove(t) { |
|
|
|
fetch(`/api/estimate/template/remove`, |
|
|
|
{method: 'DELETE', |
|
|
|
body: JSON.stringify(t), |
|
|
|
headers: { |
|
|
|
"Accept": "application/json", |
|
|
|
"Authorization": `Bearer ${props.token}`, |
|
|
|
}, |
|
|
|
}).then(response => { |
|
|
|
if (response.ok) { |
|
|
|
estimates.value = estimates.value.filter(e => e.id != estimate.value.id) |
|
|
|
estimate.value = null |
|
|
|
deleting.value = false |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function download(estimate) { |
|
|
|
fetch(`/api/pdf`, |
|
|
|
{method: 'POST', |
|
|
@@ -183,8 +268,13 @@ function download(estimate) { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function isTemplate() { |
|
|
|
return templates.value.some( t => t.estimate.id == estimate.value.id ) |
|
|
|
} |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
getEstimates() |
|
|
|
getTemplates() |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|