a.id,
a.INVOICE_TITLE,
a.SETTLE_DEPART_ID,
a.SETTLE_DEPART_NO,
a.SETTLE_DEPART_NAME,
a.declare_MONTH,
a.EMP_ID,
a.EMP_NAME,
a.EMP_IDCARD,
a.cost_reduction,
a.child_eduInfo_money,
a.housing_rentalInfo_money,
a.housing_loan_Interest_expense_money,
a.support_elderly_expense_money,
a.continuing_education_expense_money,
a.REAL_SALARY,
a.PERSONAL_PENSION_MONEY,
a.PERSONAL_MEDICAL_MONEY,
a.PERSONAL_UNEMPLOYMENT_MONEY,
a.PERSONAL_SOCIAL,
a.PERSONAL_PROVIDENT_FEE,
a.enterprise_annuity,
a.taxable,
a.tax_fee,
a.QUICK_DEDUCATION,
a.salary_tax,
a.UNIT_ID,
a.UNIT_NO,
a.UNIT_NAME,
a.SPECIAL_DEDU_MONEY,
a.sum_baby_money,
a.SUM_PRIVATE_PENSION,
a.IS_NEW_EMPLOYEE,
a.CREATE_MONTH,
a.EMP_PHONE
AND a.id = #{tStatisticsCurrentReport.id}
AND a.INVOICE_TITLE = #{tStatisticsCurrentReport.invoiceTitle}
AND a.SETTLE_DEPART_ID = #{tStatisticsCurrentReport.settleDepartId}
AND a.SETTLE_DEPART_NO = #{tStatisticsCurrentReport.settleDepartNo}
AND a.SETTLE_DEPART_NAME = #{tStatisticsCurrentReport.settleDepartName}
AND a.declare_MONTH = #{tStatisticsCurrentReport.declareMonth}
AND a.EMP_ID = #{tStatisticsCurrentReport.empId}
AND a.EMP_NAME = #{tStatisticsCurrentReport.empName}
AND a.EMP_IDCARD = #{tStatisticsCurrentReport.empIdcard}
AND a.cost_reduction = #{tStatisticsCurrentReport.costReduction}
AND a.child_eduInfo_money = #{tStatisticsCurrentReport.childEduinfoMoney}
AND a.housing_rentalInfo_money = #{tStatisticsCurrentReport.housingRentalinfoMoney}
AND a.housing_loan_Interest_expense_money = #{tStatisticsCurrentReport.housingLoanInterestExpenseMoney}
AND a.support_elderly_expense_money = #{tStatisticsCurrentReport.supportElderlyExpenseMoney}
AND a.continuing_education_expense_money = #{tStatisticsCurrentReport.continuingEducationExpenseMoney}
AND a.REAL_SALARY = #{tStatisticsCurrentReport.realSalary}
AND a.PERSONAL_PENSION_MONEY = #{tStatisticsCurrentReport.personalPensionMoney}
AND a.PERSONAL_MEDICAL_MONEY = #{tStatisticsCurrentReport.personalMedicalMoney}
AND a.PERSONAL_UNEMPLOYMENT_MONEY = #{tStatisticsCurrentReport.personalUnemploymentMoney}
AND a.PERSONAL_SOCIAL = #{tStatisticsCurrentReport.personalSocial}
AND a.PERSONAL_PROVIDENT_FEE = #{tStatisticsCurrentReport.personalProvidentFee}
AND a.enterprise_annuity = #{tStatisticsCurrentReport.enterpriseAnnuity}
AND a.taxable = #{tStatisticsCurrentReport.taxable}
AND a.tax_fee = #{tStatisticsCurrentReport.taxFee}
AND a.QUICK_DEDUCATION = #{tStatisticsCurrentReport.quickDeducation}
AND a.salary_tax = #{tStatisticsCurrentReport.salaryTax}
AND a.UNIT_ID = #{tStatisticsCurrentReport.unitId}
AND a.UNIT_NO = #{tStatisticsCurrentReport.unitNo}
AND a.UNIT_NAME = #{tStatisticsCurrentReport.unitName}
AND a.SPECIAL_DEDU_MONEY = #{tStatisticsCurrentReport.specialDeduMoney}
AND a.sum_baby_money = #{tStatisticsCurrentReport.sumBabyMoney}
AND a.SUM_PRIVATE_PENSION = #{tStatisticsCurrentReport.sumPrivatePension}
insert into t_statistics_current_report (
select
concat(s.id,#{declareMonth}) id,
s.INVOICE_TITLE,
s.SETTLE_DEPART_ID,
s.SETTLE_DEPART_NO,
s.SETTLE_DEPART_NAME,
s.DECLARE_MONTH,
s.EMP_ID,
if(s.EMP_NAME REGEXP '[0-9]',REPLACE(s.EMP_NAME,right(s.EMP_NAME,4),''),s.EMP_NAME) EMP_NAME,
s.EMP_IDCARD,
s.cost_reduction,
s.child_eduInfo_money,
s.housing_rentalInfo_money,
s.housing_loan_Interest_expense_money,
s.support_elderly_expense_money,
s.continuing_education_expense_money,
s.REAL_SALARY - ifnull(m.all_income,0) REAL_SALARY,
s.PERSONAL_PENSION_MONEY - ifnull(m.PERSONAL_PENSION_MONEY,0) PERSONAL_PENSION_MONEY,
s.PERSONAL_MEDICAL_MONEY - ifnull(m.PERSONAL_MEDICAL_MONEY,0) PERSONAL_MEDICAL_MONEY,
s.PERSONAL_UNEMPLOYMENT_MONEY - ifnull(m.PERSONAL_UNEMPLOYMENT_MONEY,0) PERSONAL_UNEMPLOYMENT_MONEY,
s.PERSONAL_SOCIAL,
s.PERSONAL_FUND - ifnull(m.PERSONAL_PROVIDENT_FEE,0) PERSONAL_PROVIDENT_FEE,
s.enterprise_annuity - ifnull(m.enterprise_annuity,0) enterprise_annuity,
s.taxable,
s.tax_fee,
s.QUICK_DEDUCATION,
s.salary_tax - ifnull(m.all_tax_prepaid,0) - ifnull(m.all_tax_payable,0) salary_tax,
s.UNIT_ID,
s.UNIT_NO,
s.UNIT_NAME,
s.SPECIAL_DEDU_MONEY,
s.sum_baby_money,
s.SUM_PRIVATE_PENSION,
if (#{lastMonth} = s.CREATE_MONTH,1,0) IS_NEW_EMPLOYEE,
s.CREATE_MONTH,
s.EMP_PHONE
from t_statistics_tax_salary s
left join
(
select m.INVOICE_TITLE,m.EMP_IDCARD,
sum(ifnull(m.PERSONAL_PENSION_MONEY,0)) PERSONAL_PENSION_MONEY,
sum(ifnull(m.PERSONAL_MEDICAL_MONEY,0)) PERSONAL_MEDICAL_MONEY,
sum(ifnull(m.PERSONAL_UNEMPLOYMENT_MONEY,0)) PERSONAL_UNEMPLOYMENT_MONEY,
sum(ifnull(m.PERSONAL_PROVIDENT_FEE,0)) PERSONAL_PROVIDENT_FEE,
sum(ifnull(m.enterprise_annuity,0)) enterprise_annuity,
sum(if(m.declare_MONTH = #{lastTwoMonth},all_income,0)) all_income,
sum(if(m.declare_MONTH = #{lastTwoMonth},all_tax_prepaid,0)) all_tax_prepaid,
sum(if(m.declare_MONTH = #{lastTwoMonth},all_tax_payable,0)) all_tax_payable
from t_statistics_current_report_market m
where m.declare_MONTH #{lastTwoMonth} and m.declare_MONTH like '${lastTwoYear}%'
GROUP BY m.EMP_IDCARD,m.INVOICE_TITLE
) m on m.EMP_IDCARD=s.EMP_IDCARD and m.INVOICE_TITLE = s.INVOICE_TITLE
left join t_statistics_declarer d on d.EMP_IDCARD=s.EMP_IDCARD and d.DECLARE_UNIT=s.INVOICE_TITLE
and d.OCCUPATION_TYPE='0' and d.DECLARE_MONTH=#{declareMonth}
where s.DECLARE_MONTH = #{declareMonth} and (d.id is null or d.IS_DECLARE = '0')
)
DELETE FROM t_statistics_current_report WHERE DECLARE_MONTH = #{yearMonth}