var loan = {
init:function(){
$("#calculate").bind({
"click":function(){
loan.displayBasic();
}
});
loan.funcBtn();
loan.inputCheck();
},
displayBasic:function(){
if(loan.formCheck())
{
var P = $("#p").val();
var R = $("#r").val()/100;
var D = $("#d").val();
P = parseFloat(P);
D = parseInt(D);
var expectedInterest = loan.calExpectedInterest(P,R,D);
$("#pDisplay").html(extraMath.formatMoney($("#p").val(),2,".",","));
$("#rDisplay").html(extraMath.formatMoney($("#r").val(),4,".",",")+"%");
$("#dDisplay").html($("#d").val());
$("#ExpectedInterestDisplay").html(extraMath.formatMoney(expectedInterest,2,".",","));
}
},
calExpectedInterest:function(P,R,D){
return P * R / 365 * D;
},
checkDecimal:function(num,fix){
var check1, check2=true;
factor = Math.pow(10, fix);
check1 = Math.floor(num * factor) === num * factor;
str = ""+num;
if(str.indexOf(".")!=-1)
if(str.length-str.indexOf(".") > (fix+1)) check2=false;
if(check1==false && check2==false)
return false;
else
return true;
},
inputCheck:function(){
$("#p,#r,#d").on({
"keyup":function(){
if(!$(this).val()) $(this).val("");
},
"blur":function(){
if(!$(this).val()) $(this).val("");
}
});
},
formCheck:function(){
var check = true;
var errorText = "";
if($("#p").val().trim()=="")
errorText += "- "+loanDisplayText.InputLoanAmount[lang]+"\n";
else if(isNaN($("#p").val()))
errorText += "- "+loanDisplayText.InvalidLoanAmount[lang]+"\n";
else if($("#p").val() < 1000 || $("#p").val() > 9999999)
errorText += "- "+loanDisplayText.InvalidLoanAmountRange[lang]+"\n";
if($("#r").val().trim()=="")
errorText += "- "+loanDisplayText.InputAnnualisedInterestRate[lang]+"\n";
else if(isNaN($("#r").val()))
errorText += "- "+loanDisplayText.InvalidAnnualisedInterestRate[lang]+"\n";
else if($("#r").val() < 0.0001 || $("#r").val() > 100)
errorText += "- "+loanDisplayText.InvalidAnnualisedInterestRateRange[lang]+"\n";
else if(!loan.checkDecimal($("#r").val(),4))
errorText += "- "+loanDisplayText.InvalidAnnualisedInterestRateRange[lang]+"\n";
if($("#d").val().trim()=="")
errorText += "- "+loanDisplayText.InputDay[lang]+"\n";
else if(isNaN($("#d").val()))
errorText += "- "+loanDisplayText.InvalidDay[lang]+"\n";
else if($("#d").val() < 1 || $("#d").val() > 1000)
errorText += "- "+loanDisplayText.InvalidDayRange[lang]+"\n";
else if(!Number.isInteger(Number($("#d").val())))
errorText += "- "+loanDisplayText.InvalidDayRange[lang]+"\n";
if(errorText)
{
errorText = errorText;
check = false;
alert(errorText)
}
return check;
},
funcBtn:function(){
$(".image").on({
"click":function(){
var node = document.getElementById("imgExportArea");
domtoimage.toPng(node)
.then(function (dataUrl) {
var link = document.createElement('a');
link.download = 'Image.png';
link.href = dataUrl;
link.click();
})
.catch(function (error) {
console.error('oops, something went wrong!', error);
});
}
});
$(".print").on({
"click":function(){
window.print();
}
});
}
};
var loanDisplayText = {
index:function(){
$("title").text(loanDisplayText.metaTitle[lang]);
$("#header").html('

');
$(".LoanAmount").text(loanDisplayText.LoanAmount[lang]);
$(".AnnualisedInterestRate").text(loanDisplayText.AnnualisedInterestRate[lang]);
$(".Days").text(loanDisplayText.Days[lang]);
$("#calculate").val(loanDisplayText.Calculate[lang]);
$("#clear").val(loanDisplayText.Clear[lang]);
$(".CalculationResult").text(loanDisplayText.CalculationResult[lang]);
$("#YourInput").text(loanDisplayText.YourInput[lang]);
$("#ExpectedInterest").text(loanDisplayText.ExpectedInterest[lang]);
$("#FuncBtn").html(''+loanDisplayText.SaveAsImage[lang]+' '+loanDisplayText.Print[lang]+'');
$("#CloseBtn").html(''+loanDisplayText.CloseBtn[lang]+'');
$(".LoanHeader").text(loanDisplayText.LoanHeader[lang]);
$("#note1").html(loanDisplayText.note1[lang]);
},
metaTitle:{
"en":"Personal Line of Credit Interest Calculator ",
"tc":"支票透支服務利息計算機",
"sc":"支票透支服务利息计算机"
},
LoanHeader:{
"en":"Personal Line of Credit Interest Calculator ",
"tc":"支票透支服務利息計算機",
"sc":"支票透支服务利息计算机"
},
LoanAmount:{
"en":"Loan Amount (HKD)",
"tc":"貸款額 (港幣)",
"sc":"贷款额 (港币)"
},
AnnualisedInterestRate:{
"en":"Annualised Interest Rate (%)",
"tc":"年化利率 (%)",
"sc":"年化利率 (%)"
},
Days:{
"en":"Days",
"tc":"日",
"sc":"日"
},
Calculate:{
"en":"Calculate",
"tc":"計算",
"sc":"计算"
},
Clear:{
"en":"Clear",
"tc":"重新輸入",
"sc":"重新输入"
},
CalculationResult:{
"en":"Calculation Result",
"tc":"計算結果",
"sc":"计算结果"
},
YourInput:{
"en":"Your Input",
"tc":"你的資料",
"sc":"你的资料"
},
ExpectedInterest:{
"en":"Expected Interest (HKD)",
"tc":"預期利息 (港幣)",
"sc":"预期利息 (港币)"
},
InputLoanAmount:{
"en":"Please input the Loan Amount.",
"tc":"請輸入貸款額。",
"sc":"请输入贷款额。"
},
InputDay:{
"en":"Please input the Day.",
"tc":"請輸入日數。",
"sc":"请输入日数。"
},
InputAnnualisedInterestRate:{
"en":"Please input the Annualised Interest Rate.",
"tc":"請輸入年化利率。",
"sc":"请输入年化利率。"
},
InvalidLoanAmount:{
"en":"The amount you inputted is invalid. Please re-enter.",
"tc":"你所輸入的貸款額不正確,請重新輸入。",
"sc":"你所输入的贷款额不正确,请重新输入。"
},
InvalidDay:{
"en":"The day you inputted is invalid. Please re-enter.",
"tc":"你所輸入的日數不正確,請重新輸入。",
"sc":"你所输入的日数不正确,请重新输入。"
},
InvalidAnnualisedInterestRate:{
"en":"The rate you inputted is invalid. Please re-enter.",
"tc":"你所輸入的年化利率不正確,請重新輸入。",
"sc":"你所输入的年化利率不正确,请重新输入。"
},
InvalidLoanAmountRange:{
"en":"Loan Amount must be between 1,000 to 9,999,999.",
"tc":"貸款額須在1,000至9,999,999內。",
"sc":"贷款额须在1,000至9,999,999内。"
},
InvalidDayRange:{
"en":"Days must be between 1 to 1000 and in whole integer",
"tc":"日數值須在1至1000之間且為整數。",
"sc":"日数值须在1至1000之间且为整数。"
},
InvalidAnnualisedInterestRateRange:{
"en":"Annualised Interest Rate (%) must be between 0.0001 and 100 and upto 4 decimal places.",
"tc":"年化利率須大於0.0001至100之間且最多 4 位小數。",
"sc":"年化利率须大于0.0001至100之间且最多 4 位小数。"
},
note1:{
"en":"Note: (1) The calculation is based on the information provided by customer and the calculator result is for reference only. The actual repayment liability depends on the actual terms of each borrowing arrangement. (2) Expected interest shown is calculated based on 365-day year only (3) The interest will be debited from the account on the last day of each month. If the date falls on Sunday or public holiday, interest will be debited on the preceding working day.",
"tc":"註: (1) 以上的計算結果是根據客戶提供之資料計算及計算結果只供參考。實際還款責任取決於各項借款安排的實際條款。(2) 所顯示的預期利息僅適用於以一年 365 天計算 (3) 利息將於每月最後一天從帳戶中扣除。如果該日期恰逢星期日或公眾假期,則將在前一個工作天扣除利息。",
"sc":"注: (1) 以上的计算结果是根据客户提供之资料计算及计算结果只供参考。实际还款责任取决于各项借款安排的实际条款。 (2) 所显示的预期利息仅适用于以一年 365 天计算 (3) 利息将于每月最后一天从帐户中扣除。如果该日期恰逢星期日或公众假期,则将在前一个工作天扣除利息。"
},
CloseBtn:{
"en":"Close",
"tc":"關閉",
"sc":"关闭"
},
CloseBtnLink:{
"en":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html",
"tc":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html",
"sc":"https://ibanking.cncbinternational.com/CKWPortal/resources/personal/common/winclose.html"
},
SaveAsImage:{
"en":"Save As Image",
"tc":"保存圖片",
"sc":"保存图片"
},
Print:{
"en":"Print",
"tc":"列印",
"sc":"打印"
}
};