Created
January 21, 2015 04:27
-
-
Save rezzafr33/f611e94c71d063d23cb4 to your computer and use it in GitHub Desktop.
Tax Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, document, $){ | |
'use strict'; | |
var CalculatorTax = function($container) { | |
this.$container = $container; | |
}; | |
CalculatorTax.prototype = { | |
init: function(){ | |
this.InitAutoNumeric(); | |
this.InitCalculateButton(); | |
this.InitResetButton(); | |
this.initBackButton(); | |
}, | |
InitAutoNumeric: function(){ | |
this.$container.find('#OfferTotal').autoNumeric('init', { | |
vMin: '0.00', | |
vMax: '999999999999999999999999' | |
}); | |
}, | |
InitCalculateButton: function() { | |
var self = this; | |
this.$container.find('form#tax_calculator').on('submit', function(e) { | |
e.preventDefault(); | |
self.Calculate(); | |
self.$container.find("#tbTaxCalc").addClass('fade'); | |
setTimeout(function(){ | |
self.$container.find("#tbTaxCalc").addClass('hide'); | |
self.$container.find("#tbResult").removeClass('hide').removeClass('fade'); | |
}, 500); | |
}); | |
}, | |
InitResetButton: function() { | |
var self = this; | |
this.$container.find('.tax_reset').on('click', function(e) { | |
e.preventDefault(); | |
self.Reset(); | |
}); | |
}, | |
initBackButton: function() { | |
var self = this; | |
this.$container.find('#tbResult .tax_back').on('click', function(e) { | |
e.preventDefault(); | |
$(this).parents('#tbResult').addClass('fade'); | |
setTimeout(function(){ | |
self.$container.find("#tbResult").addClass('hide'); | |
self.$container.find('#tbTaxCalc').removeClass('hide').removeClass('fade'); | |
}, 500); | |
}); | |
}, | |
formatCurrency: function(s, hasCurrencySymbol) { | |
if (/[^0-9\.]/.test(s)) { | |
return "N/A"; | |
} | |
s = s.replace(/^(\d*)$/, "$1."); | |
s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1"); | |
s = s.replace(".", ","); | |
var re = /(\d)(\d{3},)/; | |
while (re.test(s)) { | |
s = s.replace(re, "$1,$2"); | |
} | |
s = s.replace(/,(\d\d)$/, ".$1"); | |
return hasCurrencySymbol ? "¥" + s.replace(/^\./, "0.") : s.replace(/^\./, "0."); | |
}, | |
Reset: function() { | |
$("#BuyerPreOwnProperty").val("").trigger("chosen:updated"); | |
$("#BuyerChinese").val("").trigger("chosen:updated"); | |
$("#Mortgage").val("").trigger("chosen:updated"); | |
$("#OfferTotal").val("").trigger("chosen:updated"); | |
$("#Escrow").val("").trigger("chosen:updated"); | |
}, | |
Calculate: function() { | |
var self = this; | |
var Size = document.getElementById("Size").value; | |
var CertificateYear = document.getElementById("CertificateYear").value; | |
var OwnerChinese = document.getElementById("OwnerChinese").value; | |
var OwnerOtherProperty = document.getElementById("OwnerOtherProperty").value; | |
var OriginalPuchaseTotal = document.getElementById("OriginalPuchaseTotal").value; | |
var ExpectedSellingTotal = document.getElementById("ExpectedSellingTotal").value; | |
var EvaluationTotal = document.getElementById("EvaluationTotal").value; | |
var BuyerPreOwnProperty = document.getElementById("BuyerPreOwnProperty").value; | |
var BuyerChinese = document.getElementById("BuyerChinese").value; | |
var Mortgage = document.getElementById("Mortgage").value; | |
var Escrow = document.getElementById("Escrow").value; | |
// var OfferTotal = document.getElementById("OfferTotal").value; | |
var OfferTotal = this.$container.find('#OfferTotal').autoNumeric('get'); | |
//S&P Total (Escrow) | |
var totalescrow= this.Gettotalescrow(Escrow, EvaluationTotal, OfferTotal); | |
//Tax and Fees Base | |
var taxbase = this.Gettaxbase(Mortgage,Escrow, EvaluationTotal, OfferTotal); | |
//Deed Tax | |
var DeedTax = this.GetDeedTax(Size, taxbase, BuyerPreOwnProperty); | |
//Business Tax (Total) | |
var BusinessTaxTotal = this.GetBusinessTaxTotal(CertificateYear, Size, taxbase); | |
//Business Tax (Difference) | |
var BusinessTaxDifference = this.GetBusinessTaxDifference(CertificateYear, Size, taxbase, OriginalPuchaseTotal); | |
//Income Tax (Total) | |
var IncomeTaxTotal = this.GetIncomeTaxTotal(CertificateYear, OwnerOtherProperty, taxbase); | |
//Income Tax (Difference) | |
var IncomeTaxDifference = this.GetIncomeTaxDifference(CertificateYear, OwnerOtherProperty, taxbase, OriginalPuchaseTotal, Size); | |
//Minimum Business Tax+Income Tax | |
var MinimumBusinessTaxAndIncomeTax = this.GetMinimumBusinessTaxAndIncomeTax(Size, CertificateYear, BusinessTaxTotal, IncomeTaxTotal, BusinessTaxDifference, IncomeTaxDifference); | |
//Transaction Adminstration Fee | |
var TransactionAdminstrationFee = this.GetTransactionAdminstrationFee(Size); | |
//Equity Registration Fee | |
var EquityRegistrationFee = this.GetEquityRegistrationFee(); | |
//Encumbrance Mortgage Registration Fee | |
var EncumbranceMortgageRegistrationFee = this.GetEncumbranceMortgageRegistrationFee(); | |
//Evaluation Service Charge | |
var EvaluationServiceCharge = this.GetEvaluationServiceCharge(totalescrow); | |
//Contract Notarial Fee | |
var ContractNotarialFee = this.GetContractNotarialFee(OwnerChinese, totalescrow, BuyerChinese); | |
//Agency Service Charge | |
var AgencyServiceCharge = this.GetAgencyServiceCharge(OfferTotal); | |
//Most Mortgage | |
var MostMortgage = this.GetMostMortgage(Mortgage, BuyerPreOwnProperty); | |
//Most Mortgage Total | |
var MostMortgageTotal = parseFloat(MostMortgage)*parseFloat(totalescrow); | |
//Rest Cash pay to Owner above Evaluation | |
var RestCashpayToOwneraboveEvaluation = this.GetRestCashpayToOwneraboveEvaluation(OfferTotal, totalescrow); | |
//Mortgage Down Payment | |
var MortgageDownPayment = this.GetMortgageDownPayment(totalescrow, MostMortgage); | |
//TaxAndFeesTotal | |
var TaxAndFeesTotal = this.GetTaxAndFeesTotal(MinimumBusinessTaxAndIncomeTax, DeedTax, TransactionAdminstrationFee, EquityRegistrationFee, EncumbranceMortgageRegistrationFee, EvaluationServiceCharge, ContractNotarialFee, AgencyServiceCharge); | |
//Cash Needed Total | |
var CashNeededTotal = this.GetCashNeededTotal(TaxAndFeesTotal, RestCashpayToOwneraboveEvaluation, MortgageDownPayment); | |
var result = ""; | |
document.getElementById("totalescrow").innerText = totalescrow; | |
document.getElementById("taxbase").innerText = taxbase; | |
document.getElementById("DeedTax").innerText = DeedTax; | |
document.getElementById("BusinessTaxTotal").innerText = BusinessTaxTotal; | |
document.getElementById("BusinessTaxDifference").innerText = this.GetBusinessTaxDifference1(CertificateYear, Size, taxbase, OriginalPuchaseTotal); | |
document.getElementById("IncomeTaxTotal").innerText = IncomeTaxTotal; | |
document.getElementById("IncomeTaxDifference").innerText = this.GetIncomeTaxDifference1(CertificateYear, OwnerOtherProperty, taxbase, OriginalPuchaseTotal, Size); | |
document.getElementById("MinimumBusinessTaxAndIncomeTax").innerText = MinimumBusinessTaxAndIncomeTax; | |
document.getElementById("TransactionAdminstrationFee").innerText = TransactionAdminstrationFee; | |
document.getElementById("EquityRegistrationFee").innerText = EquityRegistrationFee; | |
document.getElementById("EncumbranceMortgageRegistrationFee").innerText = EncumbranceMortgageRegistrationFee; | |
document.getElementById("EvaluationServiceCharge").innerText = EvaluationServiceCharge; | |
document.getElementById("ContractNotarialFee").innerText = ContractNotarialFee; | |
document.getElementById("AgencyServiceCharge").innerText = AgencyServiceCharge; | |
document.getElementById("MostMortgage").innerText = MostMortgage*100; | |
document.getElementById("MostMortgageTotal").innerText = MostMortgageTotal;//CertificateYear | |
document.getElementById("RestCashpayToOwneraboveEvaluation").innerText = RestCashpayToOwneraboveEvaluation; | |
document.getElementById("MortgageDownPayment").innerText = MortgageDownPayment; | |
document.getElementById("TaxAndFeesTotal").innerText = TaxAndFeesTotal; | |
document.getElementById("CashNeededTotal").innerText = CashNeededTotal; | |
// alert("result: \n" + result); | |
this.$container.find("#tbResult span").each(function (i) { | |
$(this).text(self.formatCurrency($(this).text(), false)); | |
}); | |
}, | |
GetDeedTax: function(Size, EvaluationTotal, BuyerPreOwnProperty) { | |
//=if("Size">=144, "Evaluation Total"*3%, if("Buyer Pre-own Property">0, "Evaluation Total"*3%, if("Size">=90, "Evaluation Total"*1.5%, "Evaluation Total"*1%))) | |
if (parseFloat(Size) >= 144) { | |
return parseFloat(EvaluationTotal) * 0.03; | |
} | |
//else if (parseFloat(Size) >= 90 && parseFloat(Size) < 144) { | |
else { | |
if (BuyerPreOwnProperty > 0) { | |
return parseFloat(EvaluationTotal) * 0.03; | |
} | |
else { | |
if (parseFloat(Size) >= 90) { | |
return parseFloat(EvaluationTotal) * 0.015; | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.01; | |
} | |
} | |
} | |
}, | |
Gettotalescrow: function(Escrow, EvaluationTotal, OfferTotal){ | |
//=if("Size">=144, "Evaluation Total"*3%, if("Buyer Pre-own Property">0, "Evaluation Total"*3%, if("Size">=90, "Evaluation Total"*1.5%, "Evaluation Total"*1%))) | |
if (OfferTotal<EvaluationTotal) { | |
return OfferTotal; | |
} | |
//else if (parseFloat(Size) >= 90 && parseFloat(Size) < 144) { | |
else { | |
if (Escrow>0) { | |
return EvaluationTotal; | |
} | |
else | |
{ | |
return OfferTotal; | |
} | |
} | |
}, | |
Gettaxbase: function(Mortgage,Escrow, EvaluationTotal, OfferTotal) { | |
//=if("Size">=144, "Evaluation Total"*3%, if("Buyer Pre-own Property">0, "Evaluation Total"*3%, if("Size">=90, "Evaluation Total"*1.5%, "Evaluation Total"*1%))) | |
if (parseFloat(Mortgage) === 0){ | |
if (Escrow > 0){ | |
return EvaluationTotal; | |
} | |
else{ | |
if (OfferTotal<EvaluationTotal) | |
{ | |
return EvaluationTotal; | |
} | |
else | |
{ | |
return OfferTotal; | |
} | |
} | |
} | |
//else if (parseFloat(Size) >= 90 && parseFloat(Size) < 144) { | |
else { | |
if (Escrow > 0) { | |
return EvaluationTotal; | |
} | |
else | |
{ | |
if (OfferTotal<EvaluationTotal) | |
{ | |
return EvaluationTotal; | |
} | |
else | |
{ | |
return OfferTotal; | |
} | |
} | |
} | |
}, | |
GetBusinessTaxTotal: function(CertificateYear, Size, EvaluationTotal) { | |
//=if("Certificate Year">=5, if("Size"<144, 0, "Evaluation Total"*5.60%), "Evaluation Total"*5.60%) | |
if (parseFloat(CertificateYear) > 0) { | |
if (parseFloat(Size) < 144) { | |
return 0; | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.056; | |
} | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.056; | |
} | |
}, | |
GetBusinessTaxDifference: function(CertificateYear, Size, EvaluationTotal, OriginalPuchaseTotal) { | |
//=if("Certificate Year">=5, if("Size"<144, 0, ("Evaluation Total"-"Original Purchase Total")*5.60%), if("Size"<144, ("Evaluation Total"-"Original Purchase Total")*5.60%, N/A) | |
if (parseFloat(CertificateYear) >0) { | |
if (parseFloat(Size) < 144) { | |
return 0; | |
} | |
else { | |
//return 0; | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.056; | |
} | |
} | |
else { | |
if (parseFloat(Size) < 144) { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.056; | |
} | |
else { | |
return "N/A"; //wangyazhe | |
} | |
} | |
}, | |
GetBusinessTaxDifference1: function(CertificateYear, Size, EvaluationTotal, OriginalPuchaseTotal) { | |
//=if("Certificate Year">=5, if("Size"<144, 0, ("Evaluation Total"-"Original Purchase Total")*5.60%), if("Size"<144, ("Evaluation Total"-"Original Purchase Total")*5.60%, N/A) | |
if (parseFloat(CertificateYear) >0) { | |
if (parseFloat(Size) < 144) { | |
return 0; | |
} | |
else { | |
//return 0; | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.056; | |
} | |
} | |
else { | |
if (parseFloat(Size) < 144) { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.056; | |
} | |
else { | |
return "N/A"; //wangyazhe | |
} | |
} | |
}, | |
GetIncomeTaxTotal: function(CertificateYear, OwnerOtherProperty, EvaluationTotal) { | |
//=if("Certificate Year">=5, if("Owner Other Property"=0, 0, "Evaluation Total"*1.00%), "Evaluation Total"*1.00%) | |
if (parseFloat(CertificateYear) >0) { | |
if (parseFloat(OwnerOtherProperty) === 0) { | |
return 0; | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.01; | |
} | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.01; | |
} | |
}, | |
GetIncomeTaxDifference: function(CertificateYear, OwnerOtherProperty, EvaluationTotal, OriginalPuchaseTotal, Size) { | |
//=if("Certificate Year">=5, if("Owner Other Property"=0, 0, ("Evaluation Total"-"Original Purchase Total")*20%), if("Size"<144, ("Evaluation Total"-"Original Purchase Total")*20%, N/A)) | |
if (parseFloat(CertificateYear) >0) { | |
if (parseFloat(OwnerOtherProperty) === 0) { | |
return 0; | |
} | |
else { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.2; | |
} | |
} | |
else { | |
if (parseFloat(Size) < 144) { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.2; | |
} | |
else { | |
return 0; //wangyazhe | |
} | |
} | |
}, | |
GetIncomeTaxDifference1: function(CertificateYear, OwnerOtherProperty, EvaluationTotal, OriginalPuchaseTotal, Size) { | |
//=if("Certificate Year">=5, if("Owner Other Property"=0, 0, ("Evaluation Total"-"Original Purchase Total")*20%), if("Size"<144, ("Evaluation Total"-"Original Purchase Total")*20%, N/A)) | |
if (parseFloat(CertificateYear) >0) { | |
if (parseFloat(OwnerOtherProperty) === 0) { | |
return 0; | |
} | |
else { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.2; | |
} | |
} | |
else { | |
if (parseFloat(Size) < 144) { | |
return (parseFloat(EvaluationTotal) - parseFloat(OriginalPuchaseTotal)) * 0.2; | |
} | |
else { | |
return "N/A"; //wangyazhe | |
} | |
} | |
}, | |
GetMinimumBusinessTaxAndIncomeTax: function(Size, CertificateYear, BusinessTaxTotal, IncomeTaxTotal, BusinessTaxDifference, IncomeTaxDifference) { | |
//=if("Size">=144, // | |
//if("Certificate Year"<5, | |
//("Business Tax (Total)"+"Income Tax (Total)"), | |
//if(("Business Tax (Total)"+"Income Tax (Total)")<("Business Tax (Difference)"+"Income Tax (Difference)"), | |
//("Business Tax (Total)"+"Income Tax (Total)"), | |
//("Business Tax (Difference)"+"Income Tax (Difference)"))), | |
//if(("Business Tax (Total)"+"Income Tax (Total)")<("Business Tax (Difference)"+"Income Tax (Difference)"), | |
//("Business Tax (Total)"+"Income Tax (Total)"), | |
//("Business Tax (Difference)"+"Income Tax (Difference)"))) | |
if (parseFloat(Size) >= 144) { | |
if (parseFloat(CertificateYear) === 0) { | |
return parseFloat(BusinessTaxTotal) + parseFloat(IncomeTaxTotal); | |
} | |
else { | |
if (parseFloat(BusinessTaxTotal) + parseFloat(IncomeTaxTotal) < parseFloat(BusinessTaxDifference) + parseFloat(IncomeTaxDifference)) { | |
return parseFloat(BusinessTaxTotal) + parseFloat(IncomeTaxTotal); | |
} | |
else { | |
return parseFloat(BusinessTaxDifference) + parseFloat(IncomeTaxDifference); | |
} | |
} | |
} | |
else { | |
if (parseFloat(BusinessTaxTotal) + parseFloat(IncomeTaxTotal) < parseFloat(BusinessTaxDifference) + parseFloat(IncomeTaxDifference)) { | |
return parseFloat(BusinessTaxTotal) + parseFloat(IncomeTaxTotal); | |
} | |
else { | |
return parseFloat(BusinessTaxDifference) + parseFloat(IncomeTaxDifference); | |
} | |
} | |
}, | |
GetTransactionAdminstrationFee: function(Size) { | |
//="Size"*6 | |
return parseFloat(Size) * 6; | |
}, | |
GetEquityRegistrationFee: function() { | |
//Fixed | |
return 100; | |
}, | |
GetEncumbranceMortgageRegistrationFee: function() { | |
//Fixed | |
return 80; | |
}, | |
GetEvaluationServiceCharge: function(EvaluationTotal) { | |
//="Evaluation Total"*0.20% | |
if (parseFloat(Mortgage) === "0") { | |
return 0; | |
} | |
else { | |
return parseFloat(EvaluationTotal) * 0.002; | |
} | |
}, | |
GetContractNotarialFee: function(OwnerChinese, EvaluationTotal, BuyerChinese) { | |
//=if("Owner Chinese or Not"=0, (("Evaluation Total"-500000)*0.25%+1500), if("Buyer Chinese or Not"=0, (("Evaluation Total"-500000)*0.25%+1500), 0)) | |
if (parseFloat(OwnerChinese) === 0) { | |
return (parseFloat(EvaluationTotal) - 500000) * 0.0025 + 1500; | |
} | |
else { | |
if (parseFloat(BuyerChinese) === 0) { | |
return (parseFloat(EvaluationTotal) - 500000) * 0.0025 + 1500; | |
} | |
else { | |
return 0; | |
} | |
} | |
}, | |
GetAgencyServiceCharge: function(OfferTotal) { | |
return parseFloat(OfferTotal) * 0.01; | |
}, | |
GetMostMortgage: function(Mortgage, BuyerPreOwnProperty) { | |
//=if("Mortgage or Not"=0, 0, if("Buyer Pre-own Property"=0, 70%, 40%)) | |
if (parseFloat(Mortgage) === 0) { | |
return 0; | |
} | |
else { | |
if (parseFloat(BuyerPreOwnProperty) === 0) { | |
return 0.7; | |
} | |
else { | |
return 0.4; | |
} | |
} | |
}, | |
GetMostMortgageTotal: function(OfferTotal, EvaluationTotal, MostMortgage) { | |
//=if("Offer Total"<"Evaluation Total", "Offer Total", "Evaluation Total)*"Mortgage %" | |
if (parseFloat(OfferTotal) < parseFloat(EvaluationTotal)) { | |
return parseFloat(OfferTotal) * parseFloat(MostMortgage); | |
} | |
else { | |
return parseFloat(EvaluationTotal) * parseFloat(MostMortgage); | |
} | |
}, | |
GetRestCashpayToOwneraboveEvaluation: function(OfferTotal, EvaluationTotal) { | |
//=if("Offer Total"<"Evaluation Total", 0, ("Offer Total"-"Evaluation Total")) | |
return parseFloat(OfferTotal) - parseFloat(EvaluationTotal); | |
}, | |
GetMortgageDownPayment: function(OfferTotal, MostMortgage) { | |
//=if("Offer Total"<"Evaluation Total", "Offer Total", "Evaluation Total)*(1-"Mortgage %") | |
return parseFloat(OfferTotal) * (1 - parseFloat(MostMortgage)); | |
}, | |
GetTaxAndFeesTotal: function(MinimumBusinessTaxAndIncomeTax, DeedTax, TransactionAdminstrationFee, EquityRegistrationFee, EncumbranceMortgageRegistrationFee, EvaluationServiceCharge, ContractNotarialFee, AgencyServiceCharge) { | |
//=SUM("Minimum Business Tax+Income Tax" and rest Tax and Fees) | |
return parseFloat(MinimumBusinessTaxAndIncomeTax) + parseFloat(DeedTax) + parseFloat(TransactionAdminstrationFee) + parseFloat(EquityRegistrationFee) + parseFloat(EncumbranceMortgageRegistrationFee) + parseFloat(EvaluationServiceCharge) + parseFloat(ContractNotarialFee); | |
}, | |
GetCashNeededTotal: function(TaxAndFeesTotal, RestCashpayToOwneraboveEvaluation, MortgageDownPayment) { | |
//="Tax and Fees Total"+"Rest Cash pay to Owner above Evaluation"+"Mortgage Down Payment" | |
return parseFloat(TaxAndFeesTotal) + parseFloat(RestCashpayToOwneraboveEvaluation) + parseFloat(MortgageDownPayment); | |
} | |
}; | |
$(document).ready(function() { | |
var Calculator = new CalculatorTax($('.tax-calculator-wrapper')); | |
Calculator.init(); | |
}); | |
})(window, document, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment