Skip to content

Commit

Permalink
add bankrupt mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuiantw1212 committed May 10, 2024
1 parent 74282aa commit d9a2277
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 36 deletions.
27 changes: 16 additions & 11 deletions components/calculator/asset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="儲蓄投資">
<el-form-item label="定期定額">
<el-text>{{ Number(career.monthlySaving).toLocaleString() }} NTD / 月</el-text>
</el-form-item>
</el-col>
Expand Down Expand Up @@ -221,7 +221,7 @@ function drawLifeAssetChart(propagate = true) {
const spouseAnnualContribution = monthlyContribution * 12
const irrModifier = 1 + irr / 100
const inflatoinRatio = 1 + inflationRate / 100
let inflationModifier = 1
let valueModifier = 1
let pv = presentAsset
let fv = 0
Expand All @@ -235,13 +235,13 @@ function drawLifeAssetChart(propagate = true) {
const childExpenseData: number[] = []
for (let year = currentYear; year < currentYear + period; year++) {
inflationModifier *= inflatoinRatio
valueModifier *= inflatoinRatio
/**
* 影響存量重大事件
*/
if (year === downpayYear) {
const calculatedDownpay = downpayGoal || downpay
const inflatedDownpay = calculatedDownpay * inflationModifier
const inflatedDownpay = calculatedDownpay * valueModifier
pv -= inflatedDownpay
downpayData.push(Math.floor(-inflatedDownpay))
} else {
Expand All @@ -253,7 +253,7 @@ function drawLifeAssetChart(propagate = true) {
// 執業收支
const { monthlySaving } = props.career
const annualSaving = monthlySaving * 12
let calculatedPmt = annualSaving * inflationModifier
let calculatedPmt = annualSaving * valueModifier
investingData.push(calculatedPmt)
// 育兒開支影響每月儲蓄
Expand All @@ -264,13 +264,13 @@ function drawLifeAssetChart(propagate = true) {
const hasSecondBorn = currentYear <= secondBornYear && secondBornYear && secondBornYear <= year && year < secondBornEndYear
let childExpense = 0
if (hasFirstBorn) {
childExpense += childAnnualExpense * inflationModifier
childExpense += childAnnualExpense * valueModifier
}
if (hasSecondBorn) {
childExpense += childAnnualExpense * inflationModifier
childExpense += childAnnualExpense * valueModifier
}
if (hasFirstBorn || hasSecondBorn) {
const inflatedContribution = Math.floor(spouseAnnualContribution * inflationModifier)
const inflatedContribution = Math.floor(spouseAnnualContribution * valueModifier)
childExpense -= inflatedContribution
calculatedPmt -= childExpense
spouseContribution.push(inflatedContribution)
Expand All @@ -280,7 +280,7 @@ function drawLifeAssetChart(propagate = true) {
childExpenseData.push(0)
}
// 加計通貨膨脹
calculatedPmt *= inflationModifier
calculatedPmt *= valueModifier
/**
* 不受到通膨影響的PMT
*/
Expand All @@ -289,11 +289,11 @@ function drawLifeAssetChart(propagate = true) {
const mortgageEndYear = downpayYear + loanTerm
let mortgagePmt = 0
let inflatedTotalPrice = 0
if (mortgageStartYear <= year) {
if (mortgageStartYear <= year && fv > 0) {
if (year < mortgageEndYear) {
mortgagePmt = monthlyRepay * 12
}
inflatedTotalPrice = Math.floor(totalPrice * inflationModifier)
inflatedTotalPrice = Math.floor(totalPrice * valueModifier)
}
estateData.push(inflatedTotalPrice)
mortgageData.push(Math.floor(-mortgagePmt))
Expand All @@ -303,6 +303,11 @@ function drawLifeAssetChart(propagate = true) {
fv = pv * irrModifier
datasetData.push(Math.floor(fv))
fv += calculatedPmt
if (fv <= 0) {
fv = 0
valueModifier = 0
}
labels.push(year)
pv = fv
}
Expand Down
26 changes: 26 additions & 0 deletions components/calculator/benchmark.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<el-card>
<template #header>
<div class="card-header card-header--custom">
<span>非專業建議
</span>
<div>
<!-- <el-button @click="exportUserForm()">匯出</el-button> -->
<!-- <el-button>但你怎麼知道左邊這顆按鈕不是強制登入?</el-button> -->
</div>
</div>
</template>
<el-form label-width="auto">
<!-- <ul>
<li>
買房的最佳時機:未來六年都會在同一個地點居住。
</li>
</ul> -->
<el-row>
<el-col>

</el-col>
</el-row>
</el-form>
</el-card>
</template>
46 changes: 22 additions & 24 deletions components/calculator/dataCenter.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
<template>
<div>
<el-card>
<template #header>
<div class="card-header card-header--custom">
<span>資料中心
</span>
<div>
<el-button @click="exportUserForm()">匯出</el-button>
<!-- <el-button>但你怎麼知道左邊這顆按鈕不是強制登入?</el-button> -->
</div>
<el-card>
<template #header>
<div class="card-header card-header--custom">
<span>資料中心
</span>
<div>
<el-button @click="exportUserForm()">匯出</el-button>
<!-- <el-button>但你怎麼知道左邊這顆按鈕不是強制登入?</el-button> -->
</div>
</template>
<el-form ref="ruleFormRef" label-width="auto">
<el-row>
<el-col>
給不敢登入又想保留紀錄的用戶使用。
<ol>
<li>按下匯出,會取得一包"開源財務規劃.json"。</li>
<li>下次使用就可直接匯入</li>
</ol>
</el-col>
</el-row>
</el-form>
</el-card>
</div>
</div>
</template>
<el-form ref="ruleFormRef" label-width="auto">
<el-row>
<el-col>
給不敢登入又想保留紀錄的用戶使用。
<ol>
<li>按下匯出,會取得一包"開源財務規劃.json"。</li>
<li>下次使用就可直接匯入</li>
</ol>
</el-col>
</el-row>
</el-form>
</el-card>
</template>
<script setup lang="ts">
const emits = defineEmits(['export'])
Expand Down
4 changes: 3 additions & 1 deletion components/calculator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@

<h2 id="_試算結果" tabindex="-1">試算結果<a class="header-anchor" href="#試算結果"
aria-label="Permalink to &quot;試算結果&quot;">&ZeroWidthSpace;</a></h2>

<Bechmark></Bechmark>
<br>
<DataCenter @export="exportUserForm()"></DataCenter>
</div>
</template>
Expand All @@ -100,6 +101,7 @@ import Spouse from './spouse.vue'
import Parenting from './parenting.vue'
import Mortgage from './mortgage.vue'
import EstateDialogContent from './estateDialog.vue'
import Bechmark from './benchmark.vue'
import DataCenter from './dataCenter.vue'
const { VITE_BASE_URL } = import.meta.env
const ProfileRef = ref()
Expand Down

0 comments on commit d9a2277

Please sign in to comment.