var today = new Date(); var todayYear = today.getFullYear(); var todayMonth = today.getMonth(); var todayDate = today.getDate(); var todayHour = today.getHours(); var todayMin = today.getMinutes(); var todayMSec = today.getMilliseconds(); var calt = new Vue({ methods: { InitStaticJsonData($this) { $.getJSON('data/products/products.asp', function (res) { console.log('InitStaticJsonData'); let _mainProds = [] res.data.forEach(p => { let prods = p.products.filter(q => q.type == $this.prodType) console.log(prods); if (prods && prods.length > 0) { let mProd = JSON.parse(JSON.stringify(p)) mProd.products = prods _mainProds.push(JSON.parse(JSON.stringify(mProd))) } }) console.log(_mainProds); $this.mainProds = _mainProds }.bind($this)); //$.getJSON('data/table/fjm1_iam.json', function (res) {$this.fjm1Popup = res.data}.bind($this)); //$.getJSON('data/table/ibo_iam.json', function (res) {$this.iboPopup = res.data}.bind($this)); //$.getJSON('data/table/fam_iam.json', function (res) {$this.famPopup = res.data}.bind($this)); $.getJSON('data/table/iam_json.asp?ids=10&table=p3', function (res) {$this.PAA____1____月____3____Popup = res.data}.bind($this)); $.getJSON('data/table/iam_json.asp?ids=11&table=p3', function (res) {$this.PAG____1____月____3____Popup = res.data}.bind($this)); $.getJSON('data/table/products_modal.json', function (res) {$this.prodsModal = res.data}.bind($this)); $.getJSON('data/table/ibj_iam.json', function (res) {$this.ibjPopup = res.data}.bind($this)); $.getJSON('data/table/laborInsurancePension.json', function (res) {$this.lip = res.data}.bind($this)); $.getJSON('data/table/oneTakeOutRights.json', function (res) {$this.otr = res.data}.bind($this)); $.getJSON('data/table/ideal_life.json', function (res) {$this.idealLife = res.data}.bind($this)); $.getJSON('data/table/table2.json', function (res) {$this.table2 = res.data}.bind($this)); $.getJSON('data/table/table4.json', function (res) {$this.table4 = res.data}.bind($this)); $.getJSON('data/table/table5.json', function (res) {$this.table5 = res.data}.bind($this)); $.getJSON('data/table/table12.json', function (res) {$this.table12 = res.data}.bind($this)); }, //老年年金給付 GetOldAgeBenefit($this) { //準備退休差距(年) = 預計退休年齡 - 法定請領年齡 let gapYear = $this.step1Data.retireAge - $this.step1Data.pensionAge //勞保年金 = 總年資 & 月投保薪資級距 取資料 console.log(`totalSeniority ${$this.step3Data.totalSeniority}`); console.log(`avgMonthSalaryLevel ${$this.step3Data.avgMonthSalaryLevel}`); let lia = $this.lip[`year${$this.step3Data.totalSeniority}`][$this.step3Data.avgMonthSalaryLevel - 1] //老年年金給付 console.log(`老年年金給付: (${lia} * (1 + 0.04 * ${gapYear})): ${(lia * (1 + 0.04 * gapYear))}`); $this.step3Data.laborInsurance.oldAgeBenefit = Math.round(lia * (1 + 0.04 * gapYear)) }, //一次請領老年給付 GetOnceTakeOutOldAge($this) { let ts = $this.step3Data.totalSeniority if (ts > 32) ts = 33; //32.5 $this.step3Data.laborInsurance.onceTakeOutOldAge = $this.otr[`year${ts}`][$this.step3Data.avgMonthSalaryLevel - 1] }, //老年一次金給付 GetOldAgeOnceTakeOut($this) { if ($this.step3Data.totalSeniority > 15) return console.log(`GetOldAgeOnceTakeOut-----------`); //餘命(年) = 平均壽命 - 預計退休年齡 var remainLife = $this.step1Data.genderLife - $this.step1Data.retireAge; console.log(`${remainLife} = ${$this.step1Data.genderLife} - ${$this.step1Data.retireAge}`); console.log(`totalSeniority ${$this.step3Data.totalSeniority}`); console.log(`avgMonthSalaryLevel ${$this.step3Data.avgMonthSalaryLevel}`); $this.step3Data.laborInsurance.oldAgeOnceTakeOut = $this.otr[`year${$this.step3Data.totalSeniority}`][$this.step3Data.avgMonthSalaryLevel - 1] console.log(`勞保:老年一次金給付 ${$this.step3Data.laborInsurance.oldAgeOnceTakeOut}`); $this.step3Data.laborInsurance.oldAgeOnceTakeOutMonth = Math.round($this.step3Data.laborInsurance.oldAgeOnceTakeOut / remainLife / 12) }, MonthPreMoney($this) { var preparePensionY = $this.step1Data.prePensionYear //準備退休金時間(年) var idealCost = $this.step2Data.costOfLiving //生活花費 var reserve = $this.step2Data.reserve //預備金 var inflation = $this.step2Data.inflation / 100 //通膨率 if ($this.prodType == 'month') $this.step4Data.monthPreMoney = Math.round(idealCost * (1 + inflation) ** preparePensionY) else{ $this.step4Data.monthPreMoney = Math.round(reserve * (1 + inflation) ** preparePensionY) console.log(`理想生活的應備金為: Math.round(${reserve} * (1 + ${inflation}) ** ${preparePensionY}) = ${$this.step4Data.monthPreMoney}`) } console.log(`準備退休金時間: ${preparePensionY}`); console.log($this.prodType == 'month' ? `生活花費: ${idealCost}` : `預備金: ${reserve}`); console.log(`通膨率: ${inflation}`); console.log(`應備金: ${$this.step4Data.monthPreMoney}`); }, //計算所有輸入項目 CalculateInput($this) { //step1 info get var bornYear = $this.step1Data.birthYear; //出生年 var retireAge = $this.step1Data.retireAge; //預計退休年齡 var pensionAge = $this.step1Data.pensionAge; //法定請領年齡 var life = $this.step1Data.genderLife; //平均壽命 //step1 calc var howOldAreYou = todayYear - bornYear - 1911; //現在年齡 var preparePensionY = retireAge - howOldAreYou; //準備退休金時間(年) var gapYear = retireAge - pensionAge; //準備退休差距(年) var remainLife = life - retireAge; //餘命(年) console.log('餘命(年) '+remainLife); //step2 info get var idealCost = $this.step2Data.costOfLiving; //用戶理想月花費 var inflation = $this.step2Data.inflation / 100; //通膨率 //step2 calc jq //step3 info get var ts = $this.step3Data.totalSeniority; //總年資 var os = $this.step3Data.oldSeniority; //舊年資 var wh = $this.step3Data.sixMonthSalary; //平均提繳工資 var rp = $this.step3Data.contributionRate; //勞退自行提撥率 var irFactor = $this.table2[`age${retireAge}`]; //期初年金現值因子 //step3 calc var ns = ts - os; //新年資 this.GetOnceTakeOutOldAge($this); //laborA 勞保:一次請領老年給付 this.GetOldAgeOnceTakeOut($this); //laborB 勞保:老年一次金給付 this.GetOldAgeBenefit($this); //laborC 勞保:老年年金給付 $this.step3Data.laborPension.pensionBenefit = Math.round(wh * (0.06 + rp) * 12 * ns / irFactor / 12) //laborD 勞退:年金給付(新制) $this.step3Data.laborPension.newOnceTakeOut = Math.round(wh * (0.06 + rp) * 12 * ns) //laborE 勞退:新制一次領 console.log(`$this.step3Data.laborPension.pensionBenefit = Math.round(wh * (0.06 + rp) * 12 * ns / irFactor / 12)`); console.log(`${wh} * (0.06 + ${rp}) * ${12} * ${ns} / ${irFactor} / 12 = ${$this.step3Data.laborPension.pensionBenefit}`); var oos = 15 * 2 + (os - 15) * 1; //基數 if (oos > 44) { oos = 45; } if (os < 15) { $this.step3Data.laborPension.oldOnceTakeOut = os * 2 * wh; } else { $this.step3Data.laborPension.oldOnceTakeOut = oos * wh; } $this.step3Data.laborPension.newOnceTakeOutMonth = Math.round($this.step3Data.laborPension.newOnceTakeOut / remainLife / 12) //laborF 勞退:新制一次領 $this.step3Data.laborPension.oldOnceTakeOutMonth = Math.round($this.step3Data.laborPension.oldOnceTakeOut / remainLife / 12) $this.step1Data.age = howOldAreYou; $this.step1Data.prePensionYear = preparePensionY; $this.step1Data.remainLife = remainLife; console.log('年紀', howOldAreYou, '歲') console.log('出生年 民國:', bornYear) console.log('想退休', retireAge, '歲') console.log('法定請領', pensionAge, '歲') console.log('準備退休金 有幾年', preparePensionY) console.log('退休差距 年:', gapYear) console.log('餘命', remainLife, '年') console.log('理想月花費 通膨', idealCost, inflation) console.log('新年資', ns, wh, rp, ns) }, //理想生活的每月已備金 CalculateMonthReadyMoney($this) { console.log('理想生活的每月已備金'); var n1 = this.toNumber($this.step3Data.extraIncome.bank) //每月房租收入 var n2 = this.toNumber($this.step3Data.extraIncome.foreign) //每月定存收入 var n3 = this.toNumber($this.step3Data.extraIncome.stock) //每月股息收入 var n4 = this.toNumber($this.step3Data.extraIncome.other) //每月其他收入 var extraIncome = n1 + n2 + n3 + n4; var tsy = this.toNumber($this.step3Data.totalSeniority) //勞保總年資 var osy = this.toNumber($this.step3Data.oldSeniority) //舊制年資 var nsy = tsy - osy; //新制年資 //other var op = this.toNumber($this.step3Data.jobPension) //月職業退休金 var oi = this.toNumber($this.step3Data.societyPension) //月社會保險金 //labor var lcN = this.toNumber($this.step3Data.laborInsurance.oldAgeBenefit) //t>14 老年年金給付 (元/月) var ldN = this.toNumber($this.step3Data.laborPension.pensionBenefit) //n>14 年金給付 (元/月) var lbN = this.toNumber($this.step3Data.laborInsurance.oldAgeOnceTakeOutMonth) //t<15 老年一次金給付(元/月) var lfN = this.toNumber($this.step3Data.laborPension.oldOnceTakeOutMonth) //o>0 舊制一次領(元/月) var leN = this.toNumber($this.step3Data.laborPension.newOnceTakeOutMonth) //n<15 新制一次領(元/月) var c1 = tsy < 15; var c2 = nsy < 15; var c3 = osy > 0; console.log('extraIncome', extraIncome, n1, n2, n3, n4) if ($this.step3Data.calculate == 0) { $this.step4Data.monthReadyMoney = extraIncome; $this.chartItems.ohterAssets.value = extraIncome } else { $this.chartItems.ohterAssets.value = extraIncome if ($this.step3Data.jobType == 'labor') { if (!c1 && !c2 && !c3) { console.log('s1', !c1 && !c2 && !c3) //s1(t>14 n>14 o=0) $this.step4Data.monthReadyMoney = extraIncome + lcN + ldN $this.chartItems.laborInsurance.value = lcN $this.chartItems.laborPension.value = ldN } if (c1 && c2 && !c3) { console.log('s2', c1 && c2 && !c3) //s2(t<15 n<15 o=0) $this.step4Data.monthReadyMoney = extraIncome + lbN + leN $this.chartItems.laborInsurance.value = lbN $this.chartItems.laborPension.value = leN } if (!c1 && !c2 && c3) { console.log('s3', !c1 && !c2 && c3) //s3(t>14 n>14 o>0) $this.step4Data.monthReadyMoney = extraIncome + lcN + ldN + lfN $this.chartItems.laborInsurance.value = lcN $this.chartItems.laborPension.value = ldN + lfN } if (c1 && c2 && c3) { console.log('s4', c1 && c2 && c3) //s4(t<15 n<15 o>0) $this.step4Data.monthReadyMoney = extraIncome + lbN + leN + lfN $this.chartItems.laborInsurance.value = lbN $this.chartItems.laborPension.value = leN + lfN } if (!c1 && c2 && c3) { console.log('s5', !c1 && c2 && c3) //s5(t>14 n<14 o>0) $this.step4Data.monthReadyMoney = extraIncome + lcN + leN + lfN $this.chartItems.laborInsurance.value = lcN $this.chartItems.laborPension.value = leN + lfN } } else { $this.step4Data.monthReadyMoney = extraIncome + op + oi $this.chartItems.laborInsurance.value = oi $this.chartItems.laborPension.value = op } } $this.ResetChart() }, //理想生活的累積已備金 CalculateAccReadyMoney($this) { console.log('理想生活的累積已備金') var n1 = this.toNumber($this.step3Data.totalAssets.bank) //銀行存款總額 var n2 = this.toNumber($this.step3Data.totalAssets.foreign) //外幣存款總額 var n3 = this.toNumber($this.step3Data.totalAssets.stock) //股票價值總額 var n4 = this.toNumber($this.step3Data.totalAssets.other) //其他價值總額 var extraIncome = n1 + n2 + n3 + n4; //other var op = this.toNumber($this.step3Data.accJobPension) //累積職業退休金 var oi = this.toNumber($this.step3Data.accSocietyPension) //累積社會保險金 // labor var tAB = this.toNumber($this.step3Data.laborInsurance.onceTakeOutOldAge) //laborA 勞保:一次請領老年給付 var tF = this.toNumber($this.step3Data.laborPension.oldOnceTakeOut) //laborF 勞退:舊制一次領 var tE = this.toNumber($this.step3Data.laborPension.newOnceTakeOut) //laborE 勞退:新制一次領 if ($this.step3Data.calculate == 0) { $this.step4Data.monthReadyMoney = extraIncome; $this.chartItems.ohterAssets.value = extraIncome } else { $this.chartItems.ohterAssets.value = extraIncome if ($this.step3Data.jobType == 'labor') { $this.step4Data.monthReadyMoney = extraIncome + tAB + tF + tE; $this.chartItems.laborInsurance.value = tAB $this.chartItems.laborPension.value = tF + tE } else { $this.step4Data.monthReadyMoney = extraIncome + op + oi; $this.chartItems.laborInsurance.value = oi $this.chartItems.laborPension.value = op } } $this.ResetChart() }, //計算商品 CalculateProduct($this) { this.CalculateProduct1($this) this.CalculateProduct2($this) this.CalculateProduct3($this) this.CalculateProduct4($this) }, //計算 利變型 CalculateProduct1($this) { console.log('CalculateProduct1'); var i = 0; $this.chartItems.product1.value = 0 $this.chartItems.product1.items = [] $this.step4Data.products.filter(f => f.type == 1).forEach(p => { p.idx = i++; //將第一個 year 記錄到 if ($this.prodType == 'total' && p.idx == 0 && p.sProds) $this.sumPolicyYear1 = p.year; else if ($this.prodType == 'total' && p.sProds) p.year = $this.sumPolicyYear1 console.log(`sumPolicyYear1: ${$this.sumPolicyYear1}, year: ${p.year}`); if (!p.sProds) return console.log(p); console.log(p.code, p.iam, p.year); //計算金額 //if (p.code == 'FJM1') p.money = Math.round(p.iam * p.sProds.exchangeRate / 12) //if (p.code == 'IBO') p.money = Math.round(p.iam / 12) //if (p.code == 'FAM') p.money = Math.round(p.iam * p.sProds.exchangeRate / 12) //if (p.code == 'FAN') p.money = p.year > 0 && p.iam > 0 ? p.sProds.table[`year${p.year}`][p.iam - 1] * p.sProds.exchangeRate : 0 //if (p.code == 'IBK') p.money = p.year > 0 && p.iam > 0 ? p.sProds.table[`year${p.year}`][p.iam - 1] : 0 if (p.code == 'IBJ') p.money = Math.round(p.iam / 12) if (p.code == 'FAG') p.money = p.year > 0 && p.iam > 0 ? p.sProds.table[`year${p.year}`][p.iam - 1] * p.sProds.exchangeRate : 0 //加入圖表資料 $this.chartItems.product1.value += p.money $this.chartItems.product1.items.push({ title: p.sProds.title, money: p.money }) }) $this.ResetChart() }, //計算 投資型 CalculateProduct2($this) { console.log('CalculateProduct2'); var i = 0; $this.chartItems.product2.value = 0 $this.chartItems.product2.items = [] $this.step4Data.products.filter(f => f.type == 2).forEach(p => { p.idx = i++; console.log(p); if (!p.sProds || !p.tProds || !p.uProds || p.iam <= 0) { console.log(!p.sProds || !p.tProds || !p.uProds); p.result = { unitMoney: 0, //單位金額 monthBackMoney: 0, //月提解(美金) raiseMoney: 0, //加碼(美金) monthRaiseMoney: 0, //月化加碼(美金) avgMonthMoney: 0, //平均月領(美金) avgMonthNTD: 0, //平均月領(台幣) } return } console.log(p.code, p.iam, p.year); //投入金額 p.iam = isNaN(parseInt(p.iam)) ? 0 : parseInt(p.iam) //計算金額 //轉換美元 = 投入金額 * 匯率 p.result.usd = p.sProds.currency == '美元' ? p.iam : this.MathRound2(p.iam / p.tProds.exchangeRate) //單位金額 = 轉換美元 / 10 p.result.unitMoney = this.MathRound2(p.result.usd / 10) //月提解(美金) = 換算後的單位金額 * 月提解 p.result.monthBackMoney = this.MathRound2(p.result.unitMoney * p.uProds.back) //加碼(美金) = 換算後的單位金額 * 加碼 p.result.raiseMoney = this.MathRound2(p.result.unitMoney * p.uProds.raise) //月化加碼(美金) = 加碼(美金) if (p.target == 'MLD2') p.result.monthRaiseMoney = this.MathRound2(p.result.raiseMoney) //月化加碼(美金) = 加碼(美金) / 3 else p.result.monthRaiseMoney = this.MathRound2(p.result.raiseMoney / 3) //平均月領(美金) p.result.avgMonthMoney = p.result.raiseMoney == 0 ? this.MathRound2(p.result.monthBackMoney) : this.MathRound2(p.result.monthBackMoney + p.result.monthRaiseMoney) //平均月領(台幣) p.result.avgMonthNTD = Math.round(p.result.avgMonthMoney * p.tProds.exchangeRate) console.log(p); //加入圖表資料 $this.chartItems.product2.value += p.result.avgMonthNTD $this.chartItems.product2.items.push({ title: p.sProds.title, money: p.result.avgMonthNTD }) }) $this.ResetChart() }, //計算 投資附保證型 CalculateProduct3($this) { console.log('CalculateProduct3'); var i = 0; $this.chartItems.product3.value = 0 $this.chartItems.product3.items = [] $this.step4Data.products.filter(f => f.type == 3).forEach(p => { p.idx = i++; console.log(p); if (!p.sProds || !p.tProds || !p.uProds || p.iam <= 0) { console.log(!p.sProds || !p.tProds || !p.uProds); p.result = { unitMoney: 0, //單位金額 monthBackMoney: 0, //月提解(美金) raiseMoney: 0, //加碼(美金) monthRaiseMoney: 0, //月化加碼(美金) avgMonthMoney: 0, //平均月領(美金) avgMonthNTD: 0, //平均月領(台幣) } return } console.log(p.code, p.iam, p.year); //投入金額 (新台幣/元) p.iam = isNaN(parseInt(p.iam)) ? 0 : parseInt(p.iam) //計算金額 //轉換美元 = 投入金額 * 匯率 if (p.sProds.currency == '新台幣') p.result.usd = this.MathRound2(p.iam / p.tProds.exchangeRate) else p.result.usd = p.iam //單位金額 = 轉換美元 / 10 p.result.unitMoney = this.MathRound2(p.result.usd / 10) //月提解(美金) = 換算後的單位金額 * 月提解 p.result.monthBackMoney = this.MathRound2(p.result.unitMoney * p.uProds.back) //加碼(美金) = 換算後的單位金額 * 加碼 p.result.raiseMoney = this.MathRound2(p.result.unitMoney * p.uProds.raise) //月化加碼(美金) = 加碼(美金) / 3 p.result.monthRaiseMoney = this.MathRound2(p.result.raiseMoney / 3) //平均月領(美金) p.result.avgMonthMoney = p.result.raiseMoney == 0 ? this.MathRound2(p.result.monthBackMoney) : this.MathRound2(p.result.monthBackMoney + p.result.monthRaiseMoney) //平均月領(台幣) p.result.avgMonthNTD = Math.round(p.result.avgMonthMoney * p.tProds.exchangeRate) console.log(p); //加入圖表資料 $this.chartItems.product3.value += p.result.avgMonthNTD $this.chartItems.product3.items.push({ title: p.sProds.title, money: p.result.avgMonthNTD }) }) $this.ResetChart() }, //計算 分紅型 CalculateProduct4($this) { console.log('CalculateProduct4'); var i = 0; $this.chartItems.product4.value = 0 $this.chartItems.product4.items = [] $this.step4Data.products.filter(f => f.type == 4).forEach(p => { p.idx = i++; //將第一個 year 記錄到 if ($this.prodType == 'total' && p.idx == 0 && p.sProds) $this.sumPolicyYear1 = p.year; else if ($this.prodType == 'total' && p.sProds) p.year = $this.sumPolicyYear1 console.log(`sumPolicyYear1: ${$this.sumPolicyYear1}, year: ${p.year}`); if (!p.sProds) return console.log(p); console.log(p.code, p.iam, p.year); //計算金額 if (p.code == 'PAA____1____月____3____') p.money = Math.round(p.iam / 12) if (p.code == 'PAG____1____月____3____') p.money = Math.round(p.iam / 12) if (p.code == 'PAA') p.money = p.year > 0 && p.iam > 0 ? p.sProds.table[`year${p.year}`][p.iam - 1] : 0 if (p.code == 'PFB') p.money = p.year > 0 && p.iam > 0 ? p.sProds.table[`year${p.year}`][p.iam - 1] * p.sProds.exchangeRate : 0 //加入圖表資料 $this.chartItems.product4.value += p.money $this.chartItems.product4.items.push({ title: p.sProds.title, money: p.money }) }) $this.ResetChart() }, GetQuotaGap($this) { if ($this.prodType == 'month') { $this.chartItems.quotaGap.value = (helper.toNumber($this.chartItems.laborInsurance.value) + //勞保 helper.toNumber($this.chartItems.laborPension.value) + //勞退 helper.toNumber($this.chartItems.ohterAssets.value) + //自備 helper.toNumber($this.chartItems.product1.value) + //利變型 helper.toNumber($this.chartItems.product2.value) + //投資型 helper.toNumber($this.chartItems.product3.value) + //投資附保證型 helper.toNumber($this.chartItems.product4.value)) - //分紅型 helper.toNumber($this.step4Data.monthPreMoney) //應備金 console.log(`(${helper.toNumber($this.chartItems.laborInsurance.value)} + ${helper.toNumber($this.chartItems.laborPension.value)} + ${helper.toNumber($this.chartItems.ohterAssets.value)} + ${helper.toNumber($this.chartItems.product1.value)} + ${helper.toNumber($this.chartItems.product2.value)} + ${helper.toNumber($this.chartItems.product3.value)} + ${helper.toNumber($this.chartItems.product4.value)}) - ${helper.toNumber($this.step4Data.monthPreMoney)} = ${$this.chartItems.quotaGap.value}`) } else { $this.chartItems.quotaGap.value = (helper.toNumber($this.chartItems.laborInsurance.value) + //勞保 helper.toNumber($this.chartItems.laborPension.value) + //勞退 helper.toNumber($this.chartItems.ohterAssets.value) + //自備 helper.toNumber($this.chartItems.product1.value) + //利變型 helper.toNumber($this.chartItems.product2.value) + //投資型 helper.toNumber($this.chartItems.product3.value) + //投資附保證型 helper.toNumber($this.chartItems.product4.value)) - //分紅型 helper.toNumber($this.step4Data.monthPreMoney) //應備金 } }, MathRound2(val) { return (Math.round(val * 100) / 100) }, toNumber(val) { if (isNaN(parseInt(val))) return 0 else return parseInt(val) }, } })