a.ID,
a.INVOICE_TITLE,
a.EMP_ID,
a.EMP_NAME,
a.EMP_IDCARD,
a.SETTLE_DEPART_ID,
a.SETTLE_DEPART_NO,
a.SETTLE_DEPART_NAME,
a.SETTLEMENT_MONTH,
a.TAX_MONTH,
a.REAL_SALARY,
a.cost_reduction,
a.SPECIAL_DEDU_MONEY,
a.child_eduInfo_money,
a.housing_loan_Interest_expense_money,
a.housing_rentalInfo_money,
a.continuing_education_expense_money,
a.support_elderly_expense_money,
a.PERSONAL_SOCIAL,
a.PERSONAL_FUND,
a.withholiding_person_social,
a.withholiding_person_fund,
a.enterprise_annuity,
a.salary_tax,
a.actual_salary_sum,
a.annual_bonus,
a.annual_bonus_tax,
a.exemption_persion_tax,
a.unit_id,
a.unit_no,
a.unit_name,
a.sum_baby_money,
a.IS_NEW_EMPLOYEE,
a.CREATE_MONTH,
a.EMP_PHONE,
a.SUM_PRIVATE_PENSION
AND a.ID = #{tSalaryAccount2022.id}
AND a.INVOICE_TITLE = #{tSalaryAccount2022.invoiceTitle}
AND a.EMP_ID = #{tSalaryAccount2022.empId}
AND a.EMP_NAME = #{tSalaryAccount2022.empName}
AND a.EMP_IDCARD = #{tSalaryAccount2022.empIdcard}
AND a.SETTLE_DEPART_ID = #{tSalaryAccount2022.settleDepartId}
AND a.SETTLE_DEPART_NO = #{tSalaryAccount2022.settleDepartNo}
AND a.SETTLE_DEPART_NAME = #{tSalaryAccount2022.settleDepartName}
AND a.SETTLEMENT_MONTH = #{tSalaryAccount2022.settlementMonth}
AND a.TAX_MONTH = #{tSalaryAccount2022.taxMonth}
AND a.REAL_SALARY = #{tSalaryAccount2022.realSalary}
AND a.cost_reduction = #{tSalaryAccount2022.costReduction}
AND a.SPECIAL_DEDU_MONEY = #{tSalaryAccount2022.specialDeduMoney}
AND a.child_eduInfo_money = #{tSalaryAccount2022.childEduinfoMoney}
AND a.housing_loan_Interest_expense_money = #{tSalaryAccount2022.housingLoanInterestExpenseMoney}
AND a.housing_rentalInfo_money = #{tSalaryAccount2022.housingRentalinfoMoney}
AND a.continuing_education_expense_money = #{tSalaryAccount2022.continuingEducationExpenseMoney}
AND a.support_elderly_expense_money = #{tSalaryAccount2022.supportElderlyExpenseMoney}
AND a.PERSONAL_SOCIAL = #{tSalaryAccount2022.personalSocial}
AND a.PERSONAL_FUND = #{tSalaryAccount2022.personalFund}
AND a.withholiding_person_social = #{tSalaryAccount2022.withholidingPersonSocial}
AND a.withholiding_person_fund = #{tSalaryAccount2022.withholidingPersonFund}
AND a.enterprise_annuity = #{tSalaryAccount2022.enterpriseAnnuity}
AND a.salary_tax = #{tSalaryAccount2022.salaryTax}
AND a.actual_salary_sum = #{tSalaryAccount2022.actualSalarySum}
AND a.annual_bonus = #{tSalaryAccount2022.annualBonus}
AND a.annual_bonus_tax = #{tSalaryAccount2022.annualBonusTax}
AND a.exemption_persion_tax = #{tSalaryAccount2022.exemptionPersionTax}
AND a.unit_id = #{tSalaryAccount2022.unitId}
AND a.unit_no = #{tSalaryAccount2022.unitNo}
AND a.unit_name = #{tSalaryAccount2022.unitName}
AND a.sum_baby_money = #{tSalaryAccount2022.sumBabyMoney}
AND a.SUM_PRIVATE_PENSION = #{tSalaryAccount2022.sumPrivatePension}
CREATE TABLE IF NOT EXISTS ${tableName} (
`ID` varchar(32) NOT NULL COMMENT '主键',
`INVOICE_TITLE` varchar(50) DEFAULT NULL COMMENT '封面抬头',
`EMP_ID` varchar(32) DEFAULT NULL COMMENT '员工 ID',
`EMP_NAME` varchar(50) DEFAULT NULL COMMENT '员工姓名',
`EMP_IDCARD` varchar(25) DEFAULT NULL COMMENT '员工身份证号',
`SETTLE_DEPART_ID` varchar(32) DEFAULT NULL COMMENT '结算部门id',
`SETTLE_DEPART_NO` varchar(50) DEFAULT NULL COMMENT '结算部门no',
`SETTLE_DEPART_NAME` varchar(50) DEFAULT NULL COMMENT '结算部门name',
`SETTLEMENT_MONTH` varchar(20) DEFAULT NULL COMMENT '结算月',
`TAX_MONTH` varchar(6) DEFAULT NULL COMMENT '计税月份',
`REAL_SALARY` decimal(12,2) DEFAULT '0.00' COMMENT '应发',
`cost_reduction` decimal(12,2) DEFAULT '0.00' COMMENT '减除',
`SPECIAL_DEDU_MONEY` decimal(12,2) DEFAULT '0.00' COMMENT '专项',
`child_eduInfo_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计子女教育',
`housing_loan_Interest_expense_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计住房贷款利息',
`housing_rentalInfo_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计住房租金',
`continuing_education_expense_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计继续教育',
`support_elderly_expense_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计赡养老人',
`PERSONAL_SOCIAL` decimal(12,2) DEFAULT '0.00' COMMENT '个人社保',
`PERSONAL_FUND` decimal(12,2) DEFAULT '0.00' COMMENT '个人公积金',
`withholiding_person_social` decimal(12,2) DEFAULT '0.00' COMMENT '代扣个人社保',
`withholiding_person_fund` decimal(12,2) DEFAULT '0.00' COMMENT '代扣个人公积金',
`enterprise_annuity` decimal(12,2) DEFAULT '0.00' COMMENT '企业年金',
`salary_tax` decimal(12,2) DEFAULT '0.00' COMMENT '个税',
`actual_salary_sum` decimal(12,2) DEFAULT '0.00' COMMENT '实发',
`annual_bonus` decimal(12,2) DEFAULT '0.00' COMMENT '年终奖(单独扣税的部分)',
`annual_bonus_tax` decimal(12,2) DEFAULT '0.00' COMMENT '年终奖单独扣税',
`exemption_persion_tax` decimal(12,2) DEFAULT '0.00' COMMENT '免个税个人代扣',
`unit_id` varchar(32) DEFAULT NULL COMMENT '单位id',
`unit_no` varchar(50) DEFAULT NULL COMMENT '单位no',
`unit_name` varchar(50) DEFAULT NULL COMMENT '单位name',
`sum_baby_money` decimal(12,2) DEFAULT '0.00' COMMENT '累计婴幼儿照护费用',
`SUM_PRIVATE_PENSION` decimal(12,2) DEFAULT '0.00' COMMENT '累计个人养老金',
`IS_NEW_EMPLOYEE` varchar(1) DEFAULT NULL COMMENT '是否当月新增人员(0否1是)',
`CREATE_MONTH` varchar(6) DEFAULT NULL COMMENT '入职年月',
`EMP_PHONE` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL COMMENT '手机号码',
PRIMARY KEY (`ID`) USING BTREE,
UNIQUE KEY `SY_ACCOUNT_ID` (`ID`) USING BTREE,
KEY `SY_ACCOUNT_SETTLEMENT_MONTH` (`SETTLEMENT_MONTH`) USING BTREE,
KEY `SY_ACCOUNT_SETTLE_DEPART_ID` (`SETTLE_DEPART_ID`) USING BTREE,
KEY `SY_ACCOUNT_EMP_IDCARD` (`EMP_IDCARD`) USING BTREE,
KEY `SY_ACCOUNT_EMP_NAME` (`EMP_NAME`) USING BTREE,
KEY `SY_ACCOUNT_INVOICETITLE` (`INVOICE_TITLE`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='工资报账年度表'
delete from ${tableName} where SETTLEMENT_MONTH = #{lastMonth};
insert into ${tableName} (
select
a.id,a.INVOICE_TITLE,a.EMP_ID,a.EMP_NAME,a.EMP_IDCARD,
a.DEPT_ID SETTLE_DEPART_ID,a.DEPT_NO SETTLE_DEPART_NO,a.DEPT_NAME SETTLE_DEPART_NAME,a.SETTLEMENT_MONTH,a.TAX_MONTH,
ifnull(sum(relaySalary.SALARY_MONEY),0) REAL_SALARY,
ifnull(max(costReduction.SALARY_MONEY),0) cost_reduction,
ifnull(max(specialDeduMoney.SALARY_MONEY),0) SPECIAL_DEDU_MONEY,
ifnull(max(sumChildEduMoney.SALARY_MONEY),0) child_eduInfo_money,
ifnull(max(sumHousingLoanMoney.SALARY_MONEY),0) housing_loan_Interest_expense_money,
ifnull(max(sumHousingRentMoney.SALARY_MONEY),0) housing_rentalInfo_money,
ifnull(max(sumContinuingEducationMoney.SALARY_MONEY),0) continuing_education_expense_money,
ifnull(max(sumSupportElderlyMoney.SALARY_MONEY),0) support_elderly_expense_money,
ifnull(sum(personalSocial.SALARY_MONEY),0) PERSONAL_SOCIAL,
ifnull(sum(personalFund.SALARY_MONEY),0) PERSONAL_FUND,
ifnull(sum(withholidingPersonSocial.SALARY_MONEY),0) withholiding_person_social,
ifnull(sum(withholidingPersonFund.SALARY_MONEY),0) withholiding_person_fund,
ifnull(sum(enterpriseAnnuity.SALARY_MONEY),0) enterprise_annuity,
ifnull(sum(salaryTax.SALARY_MONEY),0) salary_tax,
ifnull(sum(actualSalarySum.SALARY_MONEY),0) actual_salary_sum,
ifnull(sum(if(annualBonusTax.SALARY_MONEY > 0,annualBonus.SALARY_MONEY,0)),0) annual_bonus,
ifnull(sum(annualBonusTax.SALARY_MONEY),0) annual_bonus_tax,
ifnull(sum(exemptionPersionTax.SALARY_MONEY),0) exemption_persion_tax,
s.unit_id,s.unit_no,s.unit_name,
ifnull(max(sumBabyMoney.SALARY_MONEY),0) sum_baby_money,
ifnull(max(sumPrivatePension.SALARY_MONEY),0) SUM_PRIVATE_PENSION,
if(#{lastMonth} = DATE_FORMAT(e.CREATE_TIME,'%Y%m'),1,0) IS_NEW_EMPLOYEE,
DATE_FORMAT(e.CREATE_TIME,'%Y%m') CREATE_MONTH,
e.EMP_PHONE
from t_salary_account a
left join t_salary_standard s on s.id = a.SALARY_FORM_ID
left join t_salary_employee e on e.id = a.EMP_ID
left join t_salary_account_item relaySalary on relaySalary.SALARY_ACCOUNT_ID = a.id and relaySalary.JAVA_FIED_NAME='relaySalary'
left join t_salary_account_item exemptionPersionTax on exemptionPersionTax.SALARY_ACCOUNT_ID = a.id and exemptionPersionTax.JAVA_FIED_NAME='exemptionPersionTax'
left join t_salary_account_item costReduction on costReduction.SALARY_ACCOUNT_ID = a.id and costReduction.JAVA_FIED_NAME='costReduction'
left join t_salary_account_item sumChildEduMoney on sumChildEduMoney.SALARY_ACCOUNT_ID = a.id and sumChildEduMoney.JAVA_FIED_NAME='sumChildEduMoney'
left join t_salary_account_item sumHousingLoanMoney on sumHousingLoanMoney.SALARY_ACCOUNT_ID = a.id and sumHousingLoanMoney.JAVA_FIED_NAME='sumHousingLoanMoney'
left join t_salary_account_item sumHousingRentMoney on sumHousingRentMoney.SALARY_ACCOUNT_ID = a.id and sumHousingRentMoney.JAVA_FIED_NAME='sumHousingRentMoney'
left join t_salary_account_item sumSupportElderlyMoney on sumSupportElderlyMoney.SALARY_ACCOUNT_ID = a.id and sumSupportElderlyMoney.JAVA_FIED_NAME='sumSupportElderlyMoney'
left join t_salary_account_item sumContinuingEducationMoney on sumContinuingEducationMoney.SALARY_ACCOUNT_ID = a.id and sumContinuingEducationMoney.JAVA_FIED_NAME='sumContinuingEducationMoney'
left join t_salary_account_item sumBabyMoney on sumBabyMoney.SALARY_ACCOUNT_ID = a.id and sumBabyMoney.JAVA_FIED_NAME='sumBabyMoney'
left join t_salary_account_item sumPrivatePension on sumPrivatePension.SALARY_ACCOUNT_ID = a.id and sumPrivatePension.JAVA_FIED_NAME='sumPrivatePension'
left join t_salary_account_item personalSocial on personalSocial.SALARY_ACCOUNT_ID = a.id and personalSocial.JAVA_FIED_NAME='personalSocial'
left join t_salary_account_item personalFund on personalFund.SALARY_ACCOUNT_ID = a.id and personalFund.JAVA_FIED_NAME='personalFund'
left join t_salary_account_item withholidingPersonSocial on withholidingPersonSocial.SALARY_ACCOUNT_ID = a.id and withholidingPersonSocial.JAVA_FIED_NAME='withholidingPersonSocial'
left join t_salary_account_item withholidingPersonFund on withholidingPersonFund.SALARY_ACCOUNT_ID = a.id and withholidingPersonFund.JAVA_FIED_NAME='withholidingPersonFund'
left join t_salary_account_item actualSalarySum on actualSalarySum.SALARY_ACCOUNT_ID = a.id and actualSalarySum.JAVA_FIED_NAME='actualSalarySum'
left join t_salary_account_item salaryTax on salaryTax.SALARY_ACCOUNT_ID = a.id and salaryTax.JAVA_FIED_NAME='salaryTax'
left join t_salary_account_item specialDeduMoney on specialDeduMoney.SALARY_ACCOUNT_ID = a.id and specialDeduMoney.JAVA_FIED_NAME='specialDeduMoney'
left join t_salary_account_item enterpriseAnnuity on enterpriseAnnuity.SALARY_ACCOUNT_ID = a.id and enterpriseAnnuity.JAVA_FIED_NAME='enterpriseAnnuity'
left join t_salary_account_item annualBonusTax on annualBonusTax.SALARY_ACCOUNT_ID = a.id and annualBonusTax.JAVA_FIED_NAME='annualBonusTax'
left join t_salary_account_item annualBonus on annualBonus.SALARY_ACCOUNT_ID = a.id and annualBonus.JAVA_FIED_NAME='annualBonus'
where
a.SETTLEMENT_MONTH = #{lastMonth} and a.DELETE_FLAG = 0 and a.FORM_TYPE != '7' and a.FORM_TYPE != '3' and a.FORM_TYPE != '4' and s.DELETE_FLAG = 0
GROUP BY a.EMP_IDCARD,a.INVOICE_TITLE,a.SETTLEMENT_MONTH)