Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuiantw1212 committed May 9, 2024
1 parent 3d124c0 commit cf67dc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
2 changes: 1 addition & 1 deletion components/calculator/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ const userForm = reactive({
age: 65,
lifeExpectancy: 0,
yearToRetirement: 0,
annuitySum: 0,
insurance: {
annuitySum: 0,
monthlyAnnuity: 0,
presentSeniority: 0,
futureSeniority: 0
Expand Down
53 changes: 16 additions & 37 deletions components/calculator/retirement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<el-form-item label="每月年金">
<el-text v-if="['employee', 'entrepreneur'].includes(profile.careerInsuranceType)">{{
Number(retirement.insurance.monthlyAnnuity).toLocaleString() }} /
月</el-text>
Expand All @@ -71,7 +71,7 @@
</el-col>
<el-col :span="12">
<el-form-item label="餘命 x 年金現值">
<el-text>{{ Number(retirement.insurance.annuitySum).toLocaleString() }}</el-text>
<el-text>{{ Number(retirement.annuitySum).toLocaleString() }}</el-text>
</el-form-item>
</el-col>
</el-row>
Expand Down Expand Up @@ -296,9 +296,7 @@ const unableToDraw = computed(() => {
lifeExpectancy,
annualExpense,
} = retirement.value
const {
monthlyAnnuity,
} = retirement.value.insurance
const monthlyAnnuity = retirement.value.insurance.monthlyAnnuity || retirement.value.pension.monthlyAnnuity
const noBefore = !monthlyContribution || !irrOverDecade || !yearToRetirement
const noAfter = !lifeExpectancy || !annualExpense || !monthlyAnnuity
return noBefore || noAfter
Expand Down Expand Up @@ -342,10 +340,6 @@ function calculateCivilServantRetirement() {
*/
const baseSalary = salary * 2
let lumpSum = 0
console.log({
lumpSum,
futureSeniority
})
if (futureSeniority <= 35) {
lumpSum = 1.5 * futureSeniority
lumpSum = Math.min(53, lumpSum)
Expand All @@ -372,7 +366,6 @@ function calculateCivilServantRetirement() {
/**
* 再計算月退休金
*/
// retirement.value.insurance.monthlyAnnuity = 0
switch (type) {
case 'lumpSum': {
retirement.value.pension.lumpSum = Math.floor(lumpSum)
Expand All @@ -388,34 +381,18 @@ function calculateCivilServantRetirement() {
}
case 'halfAndHalf': {
incomeReplacementMaxRatio /= 2
console.log({
incomeReplacementMaxRatio
})
monthlyAnnuity = Math.min(incomeReplacementMaxRatio, monthlyAnnuity)
monthlyAnnuity *= baseSalary / 100
retirement.value.pension.lumpSum = Math.floor(lumpSum / 2)
retirement.value.pension.monthlyAnnuity = Math.floor(monthlyAnnuity)
break;
}
}
/**
* 先計算上限與撫卹退休金
* https://law.moj.gov.tw/LawClass/LawSingle.aspx?pcode=S0080034&flno=39
*/
// incomeReplacementMaxRatio = 60 + (futureSeniority - 35) * 0.5
// incomeReplacementMaxRatio = Math.min(62.5, incomeReplacementMaxRatio)
// 30 + (futureSeniority - 30)
// console.log({
// futureSeniority,
// salary,
// percentage,
// })
// /**
// * 新制年資
// * https://law.moj.gov.tw/LawClass/LawSingle.aspx?pcode=S0080034&flno=27
// */
// const monthlyAnnuity = Math.floor(salary * 2 * percentage / 100)
// retirement.value.insurance.monthlyAnnuity = monthlyAnnuity
const { lifeExpectancy, age } = retirement.value
const inflationRate = 1 + props.config.inflationRate / 100
const pvModifier = Math.pow(inflationRate, age - 60)
retirement.value.annuitySum = Math.floor(monthlyAnnuity * 12 * Number(lifeExpectancy) / pvModifier)
retirement.value.insurance.annuity = 0 // 避免勞保資料干擾
}
function calculateExpenseQuartileMarks() {
props.config.retirementQuartile.forEach((item, index) => {
Expand Down Expand Up @@ -459,7 +436,7 @@ function calculateLaborInsuranceMonthlyAnnuity() {
if (lifeExpectancy) { // 勞保年金請領總和
const inflationRate = 1 + props.config.inflationRate / 100
const pvModifier = Math.pow(inflationRate, age - 60)
retirement.value.insurance.annuitySum = Math.floor(retirement.value.insurance.monthlyAnnuity * 12 * Number(lifeExpectancy) / pvModifier)
retirement.value.annuitySum = Math.floor(retirement.value.insurance.monthlyAnnuity * 12 * Number(lifeExpectancy) / pvModifier)
}
}
function calculateRetirementExpense() {
Expand Down Expand Up @@ -489,9 +466,7 @@ async function drawRetirementAssetChart(propagate = false) {
lifeExpectancy,
annualExpense,
} = retirement.value
const {
monthlyAnnuity,
} = retirement.value.insurance
const monthlyAnnuity = retirement.value.insurance.monthlyAnnuity || retirement.value.pension.monthlyAnnuity
// 計算資料
const inflationRate = 1 + props.config.inflationRate / 100
Expand Down Expand Up @@ -522,7 +497,11 @@ async function drawRetirementAssetChart(propagate = false) {
pv = fv
inflationModifier *= inflationRate
}
calculatePensionFinalValue(fv)
const { careerInsuranceType } = props.profile
if (['employee', 'entrepreneur'].includes(careerInsuranceType)) {
calculateLaborPensionLumpSum(fv)
}
// 退休後退休支出
let insuranceAnnuityInflationModifier = 1
Expand Down Expand Up @@ -595,7 +574,7 @@ async function drawRetirementAssetChart(propagate = false) {
})
pensionChartInstance = shallowRef(chartInstance)
}
function calculatePensionFinalValue(fv = 0) {
function calculateLaborPensionLumpSum(fv = 0) {
retirement.value.pension.lumpSum = Number(fv)
const { futureSeniority } = retirement.value.insurance
const taxFreeLevel = 19.8 * 10000 * futureSeniority
Expand Down

0 comments on commit cf67dc5

Please sign in to comment.