Using x++ code calculate the personal tax of salary

The following X++ code using calculate the personal tax of salary.

wrote by Jimmy on March 21th 2011

static void Jimmy_CalcPersonalIncomeTax2011(Args _args)
{
Dialog Dialog
= new Dialog("计算个人所得税[2011-9开始实施]");
DialogField dlgSalerly
= Dialog.addField(typeid(Amount),"工资收入","工资收入");
DialogField dlgTaxStar
= Dialog.addField(typeid(Amount),"个税起征点","个税起征额");
DialogField dlgHoursePer
= Dialog.addField(typeid(Percent),"住房公积金比例","住房公积金比例..");
DialogField dlgSocialIn
= Dialog.addField(typeid(Amount),"医保社保","各项医保社保");
DialogField dlgNew2011
= Dialog.addField(typeid(Noyes),"新个税算法","2011年09月开始实施");

Amount SalaryIncome,SocialAmount,TaxStart;
Amount taxBefored,taxAfter,HoursePer,HourseAmount,Others;
Noyes New2011;
Amount Taxed;

Amount CalcTaxNew(Amount _taxBefore)
//2011年9月份起,个税按3500元/月的起征标准算
{
Amount tax;
;
if(_taxBefore > 0 && _taxBefore <= 1500) // 1
tax = _taxBefore * 0.03 - 0;
if(_taxBefore > 1500 && _taxBefore <= 4500) // 2
tax = _taxBefore * 0.10 - 105;
if(_taxBefore > 4500 && _taxBefore <= 9000) // 3
tax = _taxBefore * 0.20 - 555;
if(_taxBefore > 9000 && _taxBefore <= 35000)// 4
tax = _taxBefore * 0.25 - 1005;
if(_taxBefore > 35000 && _taxBefore <= 55000)// 5
tax = _taxBefore * 0.30 - 2755;
if(_taxBefore > 55000 && _taxBefore <= 80000)// 6
tax = _taxBefore * 0.35 - 5505;
if(_taxBefore > 80000) // 7
tax = _taxBefore * 0.45 - 13505;
return tax;
//个人所得税 = 需缴税工资 * 税率 - 速算扣除数
}
Amount CalcTax(Amount _taxBefore)
// 2008年3月份起,个税按2000元/月的起征标准算
{
Amount tax;
;
if(_taxBefore > 0 && _taxBefore <= 500)
tax
= _taxBefore * 0.05 - 0;
if(_taxBefore > 500 && _taxBefore <= 2000)
tax
= _taxBefore * 0.10 - 25;
if(_taxBefore > 2000 && _taxBefore <= 5000)
tax
= _taxBefore * 0.15 - 125;
if(_taxBefore > 5000 && _taxBefore <= 20000)
tax
= _taxBefore * 0.20 - 375;
if(_taxBefore > 20000 && _taxBefore <= 40000)
tax
= _taxBefore * 0.25 - 1375;
if(_taxBefore > 40000 && _taxBefore <= 60000)
tax
= _taxBefore * 0.30 - 3375;
if(_taxBefore > 60000 && _taxBefore <= 80000)
tax
= _taxBefore * 0.35 - 6375;
if(_taxBefore > 80000 && _taxBefore <= 100000)
tax
= _taxBefore * 0.40 - 10375;
if(_taxBefore > 100000)
tax
= _taxBefore * 0.45 - 15375;
return tax;
//个人所得税 = 需缴税工资 * 税率 - 速算扣除数
}
;
Dialog.doInit();
dlgNew2011.value(Noyes::Yes);

dlgSalerly.value(
20000);
dlgTaxStar.value(
3500);
dlgHoursePer.value(
12);
dlgSocialIn.value(
102);//102 + (5500 * 5.00%) = 377
if(!Dialog.run())
return;

New2011
= dlgNew2011.value();
SalaryIncome
= dlgSalerly.value();
TaxStart
= dlgTaxStar.value();
HoursePer
= dlgHoursePer.value();
SocialAmount
= dlgSocialIn.value();

if(New2011 && TaxStart != 3500)
throw Error("请输入新个税起征点 [3500]");

if(!New2011 && TaxStart != 2000)
throw Error("请输入个税起征点 [2000]");

HourseAmount
= SalaryIncome * (HoursePer / 100);
Others
= SocialAmount + HourseAmount;

taxBefored
= SalaryIncome - (Others + TaxStart);
//需缴税的工资部分 = 工资收入 - (其他非含税 + 个税起征额)

if(TaxStart <= 0)
Taxed
= 0;
else
{
if(New2011)
Taxed
= CalcTaxNew(taxBefored);
else
Taxed
= CalcTax(taxBefored);
}
taxAfter
= SalaryIncome - (Others + Taxed);//税后工资 = 工资收入 - (其他非含税 + 个人所得税)


box::info(strfmt(
"%1[%2]\n%3[%4]\n%5[%6]\n%7[%8]\n\n%9[%10]\n\n%11",
"工资收入", num2str(SalaryIncome,1,2,1,1),
"个人所得税", num2str(Taxed,1,2,1,1),
"住房公积金", num2str(HourseAmount,1,2,1,2),
"总扣金额", num2str(Others + Taxed,1,2,1,1),
"实际工资", num2str(taxAfter,1,2,1,1),

global::numeralsToTxt_CN(taxAfter,false,true,strlen(num2str(taxAfter,1,2,1,1)))),
"纳税光荣!");
}

posted @ 2011-03-21 10:39  Fandy Xie  Views(335)  Comments(0Edit  收藏  举报