TStatisticsTaxSalaryMapper.xml 14.6 KB
Newer Older
hongguangwu's avatar
hongguangwu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.yifu.salary.mapper.TStatisticsTaxSalaryMapper">

  <resultMap id="tStatisticsTaxSalaryMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TStatisticsTaxSalary">
    <id property="id" column="id"/>
    <result property="invoiceTitle" column="INVOICE_TITLE"/>
    <result property="settleDepartId" column="SETTLE_DEPART_ID"/>
    <result property="settleDepartNo" column="SETTLE_DEPART_NO"/>
    <result property="settleDepartName" column="SETTLE_DEPART_NAME"/>
    <result property="declareMonth" column="DECLARE_MONTH"/>
    <result property="empId" column="EMP_ID"/>
    <result property="empName" column="EMP_NAME"/>
    <result property="empIdcard" column="EMP_IDCARD"/>
    <result property="costReduction" column="cost_reduction"/>
    <result property="childEduinfoMoney" column="child_eduInfo_money"/>
    <result property="housingRentalinfoMoney" column="housing_rentalInfo_money"/>
    <result property="housingLoanInterestExpenseMoney" column="housing_loan_Interest_expense_money"/>
    <result property="supportElderlyExpenseMoney" column="support_elderly_expense_money"/>
    <result property="continuingEducationExpenseMoney" column="continuing_education_expense_money"/>
    <result property="realSalary" column="REAL_SALARY"/>
    <result property="personalPensionMoney" column="PERSONAL_PENSION_MONEY"/>
    <result property="personalMedicalMoney" column="PERSONAL_MEDICAL_MONEY"/>
    <result property="personalUnemploymentMoney" column="PERSONAL_UNEMPLOYMENT_MONEY"/>
    <result property="personalSocial" column="PERSONAL_SOCIAL"/>
    <result property="personalFund" column="PERSONAL_FUND"/>
    <result property="enterpriseAnnuity" column="enterprise_annuity"/>
    <result property="taxable" column="taxable"/>
    <result property="taxFee" column="tax_fee"/>
    <result property="quickDeducation" column="QUICK_DEDUCATION"/>
    <result property="salaryTax" column="salary_tax"/>
    <result property="unitId" column="UNIT_ID"/>
    <result property="unitNo" column="UNIT_NO"/>
    <result property="unitName" column="UNIT_NAME"/>
    <result property="specialDeduMoney" column="SPECIAL_DEDU_MONEY"/>
    <result property="sumBabyMoney" column="sum_baby_money"/>
hongguangwu's avatar
hongguangwu committed
58 59 60
    <result property="isNewEmployee" column="IS_NEW_EMPLOYEE"/>
    <result property="createMonth" column="CREATE_MONTH"/>
    <result property="empPhone" column="EMP_PHONE"/>
hongguangwu's avatar
hongguangwu committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  </resultMap>
    <sql id="Base_Column_List">
                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_FUND,
                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,
hongguangwu's avatar
hongguangwu committed
93 94 95 96
                a.sum_baby_money,
                a.IS_NEW_EMPLOYEE,
                a.CREATE_MONTH,
                a.EMP_PHONE
hongguangwu's avatar
hongguangwu committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    </sql>
    <sql id="tStatisticsTaxSalary_where">
        <if test="tStatisticsTaxSalary != null">
                    <if test="tStatisticsTaxSalary.id != null and tStatisticsTaxSalary.id.trim() != ''">
                        AND a.id = #{tStatisticsTaxSalary.id}
                    </if>
                    <if test="tStatisticsTaxSalary.invoiceTitle != null and tStatisticsTaxSalary.invoiceTitle.trim() != ''">
                        AND a.INVOICE_TITLE = #{tStatisticsTaxSalary.invoiceTitle}
                    </if>
                    <if test="tStatisticsTaxSalary.settleDepartId != null and tStatisticsTaxSalary.settleDepartId.trim() != ''">
                        AND a.SETTLE_DEPART_ID = #{tStatisticsTaxSalary.settleDepartId}
                    </if>
                    <if test="tStatisticsTaxSalary.settleDepartNo != null and tStatisticsTaxSalary.settleDepartNo.trim() != ''">
                        AND a.SETTLE_DEPART_NO = #{tStatisticsTaxSalary.settleDepartNo}
                    </if>
                    <if test="tStatisticsTaxSalary.settleDepartName != null and tStatisticsTaxSalary.settleDepartName.trim() != ''">
                        AND a.SETTLE_DEPART_NAME = #{tStatisticsTaxSalary.settleDepartName}
                    </if>
                    <if test="tStatisticsTaxSalary.declareMonth != null and tStatisticsTaxSalary.declareMonth.trim() != ''">
                        AND a.DECLARE_MONTH = #{tStatisticsTaxSalary.declareMonth}
                    </if>
                    <if test="tStatisticsTaxSalary.empId != null and tStatisticsTaxSalary.empId.trim() != ''">
                        AND a.EMP_ID = #{tStatisticsTaxSalary.empId}
                    </if>
                    <if test="tStatisticsTaxSalary.empName != null and tStatisticsTaxSalary.empName.trim() != ''">
                        AND a.EMP_NAME = #{tStatisticsTaxSalary.empName}
                    </if>
                    <if test="tStatisticsTaxSalary.empIdcard != null and tStatisticsTaxSalary.empIdcard.trim() != ''">
                        AND a.EMP_IDCARD = #{tStatisticsTaxSalary.empIdcard}
                    </if>
                    <if test="tStatisticsTaxSalary.costReduction != null">
                        AND a.cost_reduction = #{tStatisticsTaxSalary.costReduction}
                    </if>
                    <if test="tStatisticsTaxSalary.childEduinfoMoney != null">
                        AND a.child_eduInfo_money = #{tStatisticsTaxSalary.childEduinfoMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.housingRentalinfoMoney != null">
                        AND a.housing_rentalInfo_money = #{tStatisticsTaxSalary.housingRentalinfoMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.housingLoanInterestExpenseMoney != null">
                        AND a.housing_loan_Interest_expense_money = #{tStatisticsTaxSalary.housingLoanInterestExpenseMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.supportElderlyExpenseMoney != null">
                        AND a.support_elderly_expense_money = #{tStatisticsTaxSalary.supportElderlyExpenseMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.continuingEducationExpenseMoney != null">
                        AND a.continuing_education_expense_money = #{tStatisticsTaxSalary.continuingEducationExpenseMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.realSalary != null">
                        AND a.REAL_SALARY = #{tStatisticsTaxSalary.realSalary}
                    </if>
                    <if test="tStatisticsTaxSalary.personalPensionMoney != null">
                        AND a.PERSONAL_PENSION_MONEY = #{tStatisticsTaxSalary.personalPensionMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.personalMedicalMoney != null">
                        AND a.PERSONAL_MEDICAL_MONEY = #{tStatisticsTaxSalary.personalMedicalMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.personalUnemploymentMoney != null">
                        AND a.PERSONAL_UNEMPLOYMENT_MONEY = #{tStatisticsTaxSalary.personalUnemploymentMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.personalSocial != null">
                        AND a.PERSONAL_SOCIAL = #{tStatisticsTaxSalary.personalSocial}
                    </if>
                    <if test="tStatisticsTaxSalary.personalFund != null">
                        AND a.PERSONAL_FUND = #{tStatisticsTaxSalary.personalFund}
                    </if>
                    <if test="tStatisticsTaxSalary.enterpriseAnnuity != null">
                        AND a.enterprise_annuity = #{tStatisticsTaxSalary.enterpriseAnnuity}
                    </if>
                    <if test="tStatisticsTaxSalary.taxable != null">
                        AND a.taxable = #{tStatisticsTaxSalary.taxable}
                    </if>
                    <if test="tStatisticsTaxSalary.taxFee != null">
                        AND a.tax_fee = #{tStatisticsTaxSalary.taxFee}
                    </if>
                    <if test="tStatisticsTaxSalary.quickDeducation != null">
                        AND a.QUICK_DEDUCATION = #{tStatisticsTaxSalary.quickDeducation}
                    </if>
                    <if test="tStatisticsTaxSalary.salaryTax != null">
                        AND a.salary_tax = #{tStatisticsTaxSalary.salaryTax}
                    </if>
                    <if test="tStatisticsTaxSalary.unitId != null and tStatisticsTaxSalary.unitId.trim() != ''">
                        AND a.UNIT_ID = #{tStatisticsTaxSalary.unitId}
                    </if>
                    <if test="tStatisticsTaxSalary.unitNo != null and tStatisticsTaxSalary.unitNo.trim() != ''">
                        AND a.UNIT_NO = #{tStatisticsTaxSalary.unitNo}
                    </if>
                    <if test="tStatisticsTaxSalary.unitName != null and tStatisticsTaxSalary.unitName.trim() != ''">
                        AND a.UNIT_NAME = #{tStatisticsTaxSalary.unitName}
                    </if>
                    <if test="tStatisticsTaxSalary.specialDeduMoney != null">
                        AND a.SPECIAL_DEDU_MONEY = #{tStatisticsTaxSalary.specialDeduMoney}
                    </if>
                    <if test="tStatisticsTaxSalary.sumBabyMoney != null">
                        AND a.sum_baby_money = #{tStatisticsTaxSalary.sumBabyMoney}
                    </if>
        </if>
    </sql>
    <!--tStatisticsTaxSalary简单分页查询-->
    <select id="getTStatisticsTaxSalaryPage" resultMap="tStatisticsTaxSalaryMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM t_statistics_tax_salary a
        <where>
            1=1
            <include refid="tStatisticsTaxSalary_where"/>
        </where>
    </select>
205 206 207 208 209 210 211 212 213 214 215

	<insert id="insertStatisticsTaxSalaryByTableName">
		insert into t_statistics_tax_salary (
			select
				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_FUND,a.enterprise_annuity,a.taxable,ifnull(c.WITHHOLDING_RATE,0) tax_fee
				 ,ifnull(c.QUICK_DEDUCATION,0) QUICK_DEDUCATION,a.salary_tax,a.unit_id,a.unit_no,a.unit_name,a.SPECIAL_DEDU_MONEY
hongguangwu's avatar
hongguangwu committed
216 217 218 219
				 ,a.sum_baby_money,
				a.IS_NEW_EMPLOYEE,
				a.CREATE_MONTH,
				a.EMP_PHONE
220 221
			from (
					 SELECT
hongguangwu's avatar
hongguangwu committed
222 223
						 concat(a.id,#{declareMonth}) id,
						 #{declareMonth} DECLARE_MONTH,
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
						 a.INVOICE_TITLE,
						 a.EMP_ID,
						 a.EMP_NAME,
						 a.EMP_IDCARD,
						 a.SETTLE_DEPART_ID,
						 a.SETTLE_DEPART_NO,
						 a.SETTLE_DEPART_NAME,
						 sum(a.REAL_SALARY) - sum(a.exemption_persion_tax) - sum(if(a.annual_bonus_tax > 0,a.annual_bonus,0)) REAL_SALARY,
						 max(a.cost_reduction) cost_reduction,
						 max(a.SPECIAL_DEDU_MONEY) SPECIAL_DEDU_MONEY,
						 max(a.child_eduInfo_money) child_eduInfo_money,
						 max(a.housing_loan_Interest_expense_money) housing_loan_Interest_expense_money,
						 max(a.housing_rentalInfo_money) housing_rentalInfo_money,
						 max(a.continuing_education_expense_money) continuing_education_expense_money,
						 max(a.support_elderly_expense_money) support_elderly_expense_money,
						 max(a.sum_baby_money) sum_baby_money,
						 sum(a.PERSONAL_SOCIAL) + sum(a.withholiding_person_social) PERSONAL_SOCIAL,
						 round(((sum(a.PERSONAL_SOCIAL) + sum(a.withholiding_person_social)) * 0.75),2) PERSONAL_PENSION_MONEY,
						 round(((sum(a.PERSONAL_SOCIAL) + sum(a.withholiding_person_social)) * 0.2),2) PERSONAL_MEDICAL_MONEY,
						 round(((sum(a.PERSONAL_SOCIAL) + sum(a.withholiding_person_social)) * 0.05),2) PERSONAL_UNEMPLOYMENT_MONEY,
						 sum(a.PERSONAL_FUND) + sum(a.withholiding_person_fund) PERSONAL_FUND,
						 sum(a.REAL_SALARY) - sum(a.exemption_persion_tax)
							 - max(a.SPECIAL_DEDU_MONEY)
							 - sum(a.PERSONAL_SOCIAL) - sum(a.withholiding_person_social)
							 - sum(a.PERSONAL_FUND) - sum(a.withholiding_person_fund)
							 - max(a.cost_reduction)
							 - sum(a.enterprise_annuity)
							 - sum(if(a.annual_bonus_tax > 0,a.annual_bonus,0)) taxable,
						 sum(a.salary_tax) salary_tax,
						 sum(a.enterprise_annuity) enterprise_annuity,
						 a.unit_id,
						 a.unit_no,
hongguangwu's avatar
hongguangwu committed
256 257 258 259
						 a.unit_name,
						 a.IS_NEW_EMPLOYEE,
						 a.CREATE_MONTH,
						 a.EMP_PHONE
260
					 FROM ${tableName} a
hongguangwu's avatar
hongguangwu committed
261
					 where a.SETTLEMENT_MONTH <![CDATA[ <= ]]>  #{lastMonth} and a.SETTLEMENT_MONTH like concat(#{lastYear},'%')
262 263 264 265 266 267 268 269 270 271 272
					 GROUP BY a.EMP_IDCARD,a.INVOICE_TITLE ORDER BY a.settle_depart_id asc
				 ) a
					 left join t_salary_tax_config c on c.MIN_INCOME <![CDATA[ < ]]> a.taxable and c.MAX_INCOME >= a.taxable and c.TYPE=0
		)
	</insert>

	<!-- 删除-按申报月份 -->
	<delete id="deleteByYearMonth">
		DELETE FROM t_statistics_tax_salary WHERE DECLARE_MONTH = #{yearMonth}
	</delete>

hongguangwu's avatar
hongguangwu committed
273
</mapper>