2022-04-16 15:33:51 +08:00
package com.engine.salary.entity.taxdeclaration.bo ;
2022-06-09 19:02:18 +08:00
import com.engine.salary.constant.SalaryDefaultTenantConstant ;
import com.engine.salary.constant.TaxDeclarationDataIndexConstant ;
2022-12-13 13:34:22 +08:00
import com.engine.salary.encrypt.EncryptUtil ;
2022-04-16 15:33:51 +08:00
import com.engine.salary.entity.datacollection.AddUpSituation ;
import com.engine.salary.entity.datacollection.DataCollectionEmployee ;
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO ;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO ;
import com.engine.salary.entity.salarysob.po.SalarySobPO ;
2022-06-09 19:02:18 +08:00
import com.engine.salary.entity.taxagent.po.TaxAgentPO ;
2022-04-18 18:56:17 +08:00
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationDetailListDTO ;
2022-04-16 15:33:51 +08:00
import com.engine.salary.entity.taxdeclaration.dto.TaxDeclarationListDTO ;
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationSaveParam ;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationDetailPO ;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO ;
2022-06-09 19:02:18 +08:00
import com.engine.salary.enums.salaryaccounting.EmployeeTypeEnum ;
import com.engine.salary.enums.salarysob.IncomeCategoryEnum ;
2022-04-16 15:33:51 +08:00
import com.engine.salary.util.SalaryDateUtil ;
import com.engine.salary.util.SalaryEntityUtil ;
2022-04-18 18:56:17 +08:00
import com.engine.salary.util.SalaryI18nUtil ;
import com.engine.salary.util.page.PageInfo ;
2022-04-16 15:33:51 +08:00
import com.google.common.collect.Lists ;
2022-06-09 19:02:18 +08:00
import com.google.common.collect.Maps ;
2024-01-25 11:38:38 +08:00
import com.engine.salary.util.db.IdGenerator ;
2022-04-16 15:33:51 +08:00
import lombok.Data ;
import org.apache.commons.collections4.CollectionUtils ;
2022-06-09 19:02:18 +08:00
import org.apache.commons.collections4.MapUtils ;
import org.apache.commons.lang3.StringUtils ;
2022-05-31 18:27:33 +08:00
import org.apache.commons.lang3.math.NumberUtils ;
2022-04-20 21:36:27 +08:00
import weaver.hrm.User ;
2022-05-31 18:27:33 +08:00
2022-04-16 15:33:51 +08:00
import java.math.BigDecimal ;
import java.time.LocalDateTime ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
2022-06-09 19:02:18 +08:00
* 个税申报表
* < p > Copyright : Copyright ( c ) 2022 < / p >
* < p > Company : 泛微软件 < / p >
*
* @author qiantao
* @version 1 . 0
* * /
2022-04-16 15:33:51 +08:00
public class TaxDeclarationBO {
2022-12-13 13:34:22 +08:00
private static EncryptUtil encryptUtil = new EncryptUtil ( ) ;
2022-04-16 15:33:51 +08:00
public static List < TaxDeclarationListDTO > convert2ListDTO ( List < TaxDeclarationPO > taxDeclarations ,
List < DataCollectionEmployee > simpleEmployees ,
2022-06-09 19:02:18 +08:00
List < TaxAgentPO > taxAgents ) {
if ( CollectionUtils . isEmpty ( simpleEmployees ) ) {
2023-04-25 10:43:40 +08:00
simpleEmployees = new ArrayList < > ( ) ;
2022-06-09 19:02:18 +08:00
}
Map < Long , String > taxAgentNameMap = SalaryEntityUtil . convert2Map ( taxAgents , TaxAgentPO : : getId ,
TaxAgentPO : : getName ) ;
2022-04-16 15:33:51 +08:00
Map < Long , String > employeeNameMap = SalaryEntityUtil . convert2Map ( simpleEmployees , DataCollectionEmployee : : getEmployeeId , DataCollectionEmployee : : getUsername ) ;
2022-06-09 19:02:18 +08:00
return taxDeclarations . stream ( )
. map ( taxDeclarationPO - > {
IncomeCategoryEnum incomeCategoryEnum = IncomeCategoryEnum . parseByValue ( taxDeclarationPO . getIncomeCategory ( ) ) ;
return TaxDeclarationListDTO . builder ( )
. id ( taxDeclarationPO . getId ( ) )
. incomeCategory ( Optional . ofNullable ( incomeCategoryEnum )
. map ( o - > SalaryI18nUtil . getI18nLabel ( o . getLabelId ( ) , o . getDefaultLabel ( ) ) )
. orElse ( StringUtils . EMPTY ) )
. salaryMonth ( taxDeclarationPO . getSalaryMonth ( ) )
. taxAgentId ( taxDeclarationPO . getTaxAgentId ( ) )
. taxAgentName ( taxAgentNameMap . getOrDefault ( taxDeclarationPO . getTaxAgentId ( ) , " " ) )
. taxCycle ( taxDeclarationPO . getTaxCycle ( ) )
. operateEmployeeId ( taxDeclarationPO . getCreator ( ) )
. operateEmployeeName ( employeeNameMap . getOrDefault ( taxDeclarationPO . getCreator ( ) , " " ) )
. operateTime ( SalaryDateUtil . getFormatLocalDateTime ( taxDeclarationPO . getCreateTime ( ) ) )
. description ( taxDeclarationPO . getDescription ( ) )
2024-09-05 18:14:02 +08:00
. opts ( taxDeclarationPO . getOpts ( ) )
2022-06-09 19:02:18 +08:00
. build ( ) ;
} )
. collect ( Collectors . toList ( ) ) ;
2022-04-16 15:33:51 +08:00
}
2022-06-08 16:36:50 +08:00
public static void buildDetailListDTO ( Long taxDeclarationId ,
2022-04-18 18:56:17 +08:00
PageInfo < TaxDeclarationDetailListDTO > page ,
2022-04-16 15:33:51 +08:00
List < TaxDeclarationDetailPO > taxDeclarationDetails ,
2022-04-18 18:56:17 +08:00
List < DataCollectionEmployee > simpleEmployees ) {
2022-04-16 15:33:51 +08:00
if ( CollectionUtils . isEmpty ( taxDeclarationDetails ) ) {
return ;
}
2022-04-18 18:56:17 +08:00
int index = ( page . getNextPage ( ) - 1 ) * page . getSize ( ) ;
2022-04-16 15:33:51 +08:00
List < TaxDeclarationDetailListDTO > dtos = Lists . newArrayListWithExpectedSize ( simpleEmployees . size ( ) ) ;
Map < Long , List < TaxDeclarationDetailPO > > taxDeclarationDetailMap = SalaryEntityUtil . group2Map ( taxDeclarationDetails , TaxDeclarationDetailPO : : getEmployeeId ) ;
2022-04-18 18:56:17 +08:00
for ( DataCollectionEmployee simpleEmployee : simpleEmployees ) {
2022-04-16 15:33:51 +08:00
Map < String , String > valueMap = SalaryEntityUtil . convert2Map ( taxDeclarationDetailMap . get ( simpleEmployee . getEmployeeId ( ) ) , TaxDeclarationDetailPO : : getFieldCode , TaxDeclarationDetailPO : : getFieldValue ) ;
TaxDeclarationDetailListDTO dto = new TaxDeclarationDetailListDTO ( ) ;
dto . setId ( simpleEmployee . getEmployeeId ( ) ) ;
dto . setTaxDeclarationId ( taxDeclarationId ) ;
dto . setSeq ( + + index ) ;
dto . setEmployeeId ( simpleEmployee . getEmployeeId ( ) ) ;
dto . setEmployeeName ( simpleEmployee . getUsername ( ) ) ;
2022-06-08 16:36:50 +08:00
dto . setIdCardType ( SalaryI18nUtil . getI18nLabel ( 101696 , " 身份证 " ) ) ;
2022-04-16 15:33:51 +08:00
dto . setIdCardNo ( " " ) ;
dto . setTaxpayerIdNo ( " " ) ;
2022-06-08 16:36:50 +08:00
dto . setResidentType ( SalaryI18nUtil . getI18nLabel ( 101697 , " 居民 " ) ) ;
dto . setIncomeType ( SalaryI18nUtil . getI18nLabel ( 101698 , " 工资、薪金 " ) ) ;
dto . setIncome ( valueMap . getOrDefault ( " income " , " " ) ) ;
2022-04-16 15:33:51 +08:00
dto . setFee ( valueMap . getOrDefault ( " fee " , " " ) ) ;
dto . setTaxFreeIncome ( valueMap . getOrDefault ( " taxFreeIncome " , " " ) ) ;
dto . setSubtraction ( valueMap . getOrDefault ( " subtraction " , " " ) ) ;
dto . setEndowmentInsurance ( valueMap . getOrDefault ( " endowmentInsurance " , " " ) ) ;
2022-06-08 16:36:50 +08:00
dto . setMedicalInsurance ( valueMap . getOrDefault ( " medicalInsurance " , " " ) ) ;
dto . setUnemploymentInsurance ( valueMap . getOrDefault ( " unemploymentInsurance " , " " ) ) ;
dto . setHousingProvidentFund ( valueMap . getOrDefault ( " housingProvidentFund " , " " ) ) ;
dto . setAnnuity ( valueMap . getOrDefault ( " annuity " , " " ) ) ;
dto . setCommercialHealthInsurance ( valueMap . getOrDefault ( " commercialHealthInsurance " , " " ) ) ;
dto . setTaxDeferredEndowmentInsurance ( valueMap . getOrDefault ( " taxDeferredEndowmentInsurance " , " " ) ) ;
dto . setOriginalValueOfProperty ( valueMap . getOrDefault ( " originalValueOfProperty " , " " ) ) ;
dto . setDeductedTax ( valueMap . getOrDefault ( " deductedTax " , " " ) ) ;
dto . setOther ( valueMap . getOrDefault ( " other " , " " ) ) ;
dto . setAddUpIncome ( valueMap . getOrDefault ( " addUpIncome " , " " ) ) ;
dto . setAddUpSubtraction ( valueMap . getOrDefault ( " addUpSubtraction " , " " ) ) ;
dto . setAddUpSpecialDeduction ( valueMap . getOrDefault ( " addUpSpecialDeduction " , " " ) ) ;
dto . setAddUpChildEducation ( valueMap . getOrDefault ( " addUpChildEducation " , " " ) ) ;
dto . setAddUpContinuingEducation ( valueMap . getOrDefault ( " addUpContinuingEducation " , " " ) ) ;
dto . setAddUpHousingLoanInterest ( valueMap . getOrDefault ( " addUpHousingLoanInterest " , " " ) ) ;
dto . setAddUpHousingRent ( valueMap . getOrDefault ( " addUpHousingRent " , " " ) ) ;
dto . setAddUpSupportElderly ( valueMap . getOrDefault ( " addUpSupportElderly " , " " ) ) ;
dto . setAddUpOther ( valueMap . getOrDefault ( " addUpOtherDeduction " , " " ) ) ;
dto . setLessTaxProportion ( valueMap . getOrDefault ( " lessTaxProportion " , " " ) ) ;
dto . setAllowedDonation ( valueMap . getOrDefault ( " addUpAllowedDonation " , " " ) ) ;
dto . setTaxableIncome ( valueMap . getOrDefault ( " addUpTaxableIncome " , " " ) ) ;
dto . setTaxRate ( valueMap . getOrDefault ( " taxRate " , " " ) ) ;
dto . setQuickDeductionFactor ( valueMap . getOrDefault ( " quickDeductionFactor " , " " ) ) ;
dto . setTaxPayable ( valueMap . getOrDefault ( " addUpTaxPayable " , " " ) ) ;
dto . setTaxSavings ( valueMap . getOrDefault ( " addUpTaxDeduction " , " " ) ) ;
dto . setTaxWithheld ( valueMap . getOrDefault ( " taxWithheld " , " " ) ) ;
dto . setRefundedOrSupplementedTax ( valueMap . getOrDefault ( " refundedOrSupplementedTax " , " " ) ) ;
2022-04-16 15:33:51 +08:00
dtos . add ( dto ) ;
}
2022-04-18 18:56:17 +08:00
page . setList ( dtos ) ;
}
2022-04-16 15:33:51 +08:00
public static Result handle ( TaxDeclarationSaveParam saveParam ,
Date taxCycle ,
2022-04-20 21:36:27 +08:00
User user ,
2022-04-16 15:33:51 +08:00
List < SalaryItemPO > salaryItems ,
List < SalarySobPO > salarySobs ,
2022-06-09 19:02:18 +08:00
List < SalaryAcctResultPO > salaryAcctResults ) {
2022-04-16 15:33:51 +08:00
Result result = new Result ( ) ;
if ( CollectionUtils . isEmpty ( salaryAcctResults ) ) {
return result ;
}
// 薪资项目聚合成map( 为了根据code获取id)
Map < String , Long > salaryItemMap = SalaryEntityUtil . convert2Map ( salaryItems , SalaryItemPO : : getCode , SalaryItemPO : : getId ) ;
// 薪资账套聚合成map( 为了根据id获取incomeCategory)
Map < Long , SalarySobPO > salarySobPOMap = SalaryEntityUtil . convert2Map ( salarySobs , SalarySobPO : : getId ) ;
// 薪资核算结果按照个税扣缴义务人id、所用薪资账套的incomeCategory聚合成map
2022-06-09 19:02:18 +08:00
Map < Long , Map < Integer , List < SalaryAcctResultPO > > > taxAgentIdKeyAcctResultMap = salaryAcctResults . stream ( )
2022-04-16 15:33:51 +08:00
. collect ( Collectors . groupingBy ( SalaryAcctResultPO : : getTaxAgentId ,
Collectors . groupingBy ( salaryAcctResultPO - > salarySobPOMap . get ( salaryAcctResultPO . getSalarySobId ( ) ) . getIncomeCategory ( ) ) ) ) ;
2022-06-09 19:02:18 +08:00
// 一个个税扣缴义务人,一种薪资类型生成一张个税申报表
taxAgentIdKeyAcctResultMap . forEach ( ( taxAgentId , incomeCategoryKeyAcctResultPOMap ) - > {
incomeCategoryKeyAcctResultPOMap . forEach ( ( incomeCategory , salaryAcctResultPOS ) - > {
// 新增的个税申报表
TaxDeclarationPO taxDeclaration = convert2PO ( saveParam , user , taxCycle , taxAgentId , incomeCategory ) ;
result . getNeedInsertTaxDeclarations ( ) . add ( taxDeclaration ) ;
if ( Objects . equals ( incomeCategory , IncomeCategoryEnum . WAGES_AND_SALARIES . getValue ( ) ) ) {
// 生成个税申报表
handleTaxDeclaration4Wage ( result , taxDeclaration , salaryAcctResultPOS , salaryItemMap ) ;
// 生成往期累计情况
handleAddUpSituation ( result , taxDeclaration , salaryAcctResultPOS , salaryItemMap ) ;
}
if ( Objects . equals ( incomeCategory , IncomeCategoryEnum . REMUNERATION_FOR_LABOR . getValue ( ) ) ) {
// 生成个税申报表
handleTaxDeclaration4Labor ( result , taxDeclaration , salaryAcctResultPOS , salaryItemMap ) ;
}
2023-01-29 14:58:51 +08:00
if ( Objects . equals ( incomeCategory , IncomeCategoryEnum . ONETIME_ANNUAL_BONUS . getValue ( ) ) ) {
// 生成个税申报表
2023-01-30 17:32:58 +08:00
handleTaxDeclaration4Annual ( result , taxDeclaration , salaryAcctResultPOS , salaryItemMap ) ;
2023-01-29 14:58:51 +08:00
}
2022-06-09 19:02:18 +08:00
} ) ;
2022-04-16 15:33:51 +08:00
} ) ;
return result ;
}
2022-06-09 19:02:18 +08:00
/ * *
* 生成个税申报表明细 ( 正常工资薪金所得 )
*
* @param result
* @param taxDeclaration
* @param salaryAcctResults
* @param salaryItemMap
* /
private static void handleTaxDeclaration4Wage ( Result result ,
TaxDeclarationPO taxDeclaration ,
List < SalaryAcctResultPO > salaryAcctResults ,
Map < String , Long > salaryItemMap ) {
if ( CollectionUtils . isEmpty ( salaryAcctResults ) ) {
return ;
}
// 核算结果按照人员id分类
Map < String , List < SalaryAcctResultPO > > salaryAcctResultPOMap = SalaryEntityUtil . group2Map ( salaryAcctResults ,
salaryAcctResultPO - > EmployeeTypeEnum . ORGANIZATION . getValue ( ) + " _ " + salaryAcctResultPO . getEmployeeId ( ) ) ;
salaryAcctResultPOMap . forEach ( ( key , salaryAcctResultPOS ) - > {
String [ ] keyArray = StringUtils . split ( key , " _ " ) ;
// 员工类型
Integer employeeType = Integer . parseInt ( keyArray [ 0 ] ) ;
// 员工id
Long employeeId = Long . parseLong ( keyArray [ 1 ] ) ;
Map < String , String > valueMap = Maps . newHashMapWithExpectedSize ( 17 ) ;
Map < Long , List < SalaryAcctResultPO > > resultMap = SalaryEntityUtil . group2Map ( salaryAcctResultPOS , SalaryAcctResultPO : : getSalaryItemId ) ;
// 本期收入
BigDecimal income = SalaryEntityUtil . reduce ( resultMap . get ( salaryItemMap . getOrDefault ( TaxDeclarationDataIndexConstant . INCOME , 0L ) ) ,
salaryAcctResultPO - > SalaryEntityUtil . empty2Zero ( salaryAcctResultPO . getResultValue ( ) ) ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . INCOME , income . toPlainString ( ) ) ;
// 本期免税收入
BigDecimal taxFreeIncome = findValue ( TaxDeclarationDataIndexConstant . TAX_FREE_INCOME , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . TAX_FREE_INCOME , taxFreeIncome . toPlainString ( ) ) ;
// 基本养老保险
BigDecimal endowmentInsurance = findValue ( TaxDeclarationDataIndexConstant . ENDOWMENT_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ENDOWMENT_INSURANCE , endowmentInsurance . toPlainString ( ) ) ;
// 基本医疗保险
BigDecimal medicalInsurance = findValue ( TaxDeclarationDataIndexConstant . MEDICAL_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . MEDICAL_INSURANCE , medicalInsurance . toPlainString ( ) ) ;
// 失业保险费
BigDecimal unemploymentInsurance = findValue ( TaxDeclarationDataIndexConstant . UNEMPLOYMENT_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . UNEMPLOYMENT_INSURANCE , unemploymentInsurance . toPlainString ( ) ) ;
// 住房公积金
BigDecimal housingProvidentFund = findValue ( TaxDeclarationDataIndexConstant . HOUSING_PROVIDENT_FUND , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . HOUSING_PROVIDENT_FUND , housingProvidentFund . toPlainString ( ) ) ;
// 累计子女教育
BigDecimal addUpChildEducation = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_CHILD_EDUCATION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_CHILD_EDUCATION , addUpChildEducation . toPlainString ( ) ) ;
// 累计继续教育
BigDecimal addUpContinuingEducation = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_CONTINUING_EDUCATION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_CONTINUING_EDUCATION , addUpContinuingEducation . toPlainString ( ) ) ;
// 累计住房贷款利息
BigDecimal addUpHousingLoanInterest = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_LOAN_INTEREST , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_LOAN_INTEREST , addUpHousingLoanInterest . toPlainString ( ) ) ;
// 累计住房租金
BigDecimal addUpHousingRent = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_RENT , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_RENT , addUpHousingRent . toPlainString ( ) ) ;
// 累计赡养老人
BigDecimal addUpSupportElderly = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_SUPPORT_ELDERLY , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_SUPPORT_ELDERLY , addUpSupportElderly . toPlainString ( ) ) ;
// 累计大病医疗
BigDecimal addUpIllnessMedical = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_ILLNESS_MEDICAL , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_ILLNESS_MEDICAL , addUpIllnessMedical . toPlainString ( ) ) ;
// 累计婴幼儿照护
BigDecimal addUpInfantCare = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_INFANT_CARE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_INFANT_CARE , addUpInfantCare . toPlainString ( ) ) ;
2023-04-13 17:14:58 +08:00
// 累计个人养老金
BigDecimal addUpPrivatePension = findValue ( TaxDeclarationDataIndexConstant . ADD_UP_PRIVATE_PENSION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ADD_UP_PRIVATE_PENSION , addUpPrivatePension . toPlainString ( ) ) ;
2022-06-09 19:02:18 +08:00
// 企业(职业)年金
BigDecimal annuity = findValue ( TaxDeclarationDataIndexConstant . ANNUITY , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUITY , annuity . toPlainString ( ) ) ;
// 商业健康保险
BigDecimal commercialHealthInsurance = findValue ( TaxDeclarationDataIndexConstant . COMMERCIAL_HEALTH_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . COMMERCIAL_HEALTH_INSURANCE , commercialHealthInsurance . toPlainString ( ) ) ;
// 税延养老保险
BigDecimal taxDeferredEndowmentInsurance = findValue ( TaxDeclarationDataIndexConstant . TAX_DEFERRED_ENDOWMENT_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . TAX_DEFERRED_ENDOWMENT_INSURANCE , taxDeferredEndowmentInsurance . toPlainString ( ) ) ;
// 其他
BigDecimal other = findValue ( TaxDeclarationDataIndexConstant . OTHER , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . OTHER , other . toPlainString ( ) ) ;
// 准予扣除的捐赠额
BigDecimal allowedDonation = findValue ( TaxDeclarationDataIndexConstant . ALLOWED_DONATION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ALLOWED_DONATION , allowedDonation . toPlainString ( ) ) ;
// 减免税额
BigDecimal taxDeduction = findValue ( TaxDeclarationDataIndexConstant . TAX_DEDUCTION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . TAX_DEDUCTION , taxDeduction . toPlainString ( ) ) ;
// 生成个税申报表详情
result . getNeedInsertTaxDeclarationDetails ( ) . addAll ( convert2DetailPO ( taxDeclaration , employeeType , employeeId , valueMap ) ) ;
} ) ;
}
/ * *
* 生成个税申报表明细 ( 劳务报酬所得 )
*
* @param result
* @param taxDeclaration
* @param salaryAcctResults
* @param salaryItemMap
* /
private static void handleTaxDeclaration4Labor ( Result result ,
2022-04-16 15:33:51 +08:00
TaxDeclarationPO taxDeclaration ,
List < SalaryAcctResultPO > salaryAcctResults ,
Map < String , Long > salaryItemMap ) {
if ( CollectionUtils . isEmpty ( salaryAcctResults ) ) {
return ;
}
// 核算结果按照人员id分类
2022-06-09 19:02:18 +08:00
Map < String , List < SalaryAcctResultPO > > salaryAcctResultPOMap = SalaryEntityUtil . group2Map ( salaryAcctResults , salaryAcctResultPO - > EmployeeTypeEnum . ORGANIZATION . getValue ( ) + " _ " + salaryAcctResultPO . getEmployeeId ( ) ) ;
salaryAcctResultPOMap . forEach ( ( key , salaryAcctResultPOS ) - > {
String [ ] keyArray = StringUtils . split ( key , " _ " ) ;
Integer employeeType = Integer . parseInt ( keyArray [ 0 ] ) ;
Long employeeId = Long . parseLong ( keyArray [ 1 ] ) ;
Map < String , String > valueMap = Maps . newHashMapWithExpectedSize ( 7 ) ;
Map < Long , List < SalaryAcctResultPO > > resultMap = SalaryEntityUtil . group2Map ( salaryAcctResultPOS , SalaryAcctResultPO : : getSalaryItemId ) ;
// 所得项目
String incomeItems = resultMap . getOrDefault ( salaryItemMap . getOrDefault ( TaxDeclarationDataIndexConstant . INCOME_ITEMS , 0L ) , Collections . emptyList ( ) ) . stream ( )
. map ( SalaryAcctResultPO : : getResultValue )
. findAny ( )
. orElse ( StringUtils . EMPTY ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . INCOME_ITEMS , incomeItems ) ;
2022-04-16 15:33:51 +08:00
// 收入
2022-06-09 19:02:18 +08:00
BigDecimal laborIncome = findValue ( TaxDeclarationDataIndexConstant . LABOR_INCOME , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . LABOR_INCOME , laborIncome . toPlainString ( ) ) ;
2022-04-16 15:33:51 +08:00
// 免税收入
2022-06-09 19:02:18 +08:00
BigDecimal laborTaxFreeIncome = findValue ( TaxDeclarationDataIndexConstant . LABOR_TAX_FREE_INCOME , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . LABOR_TAX_FREE_INCOME , laborTaxFreeIncome . toPlainString ( ) ) ;
2022-04-16 15:33:51 +08:00
// 商业健康保险
2022-06-09 19:02:18 +08:00
BigDecimal commercialHealthInsurance = findValue ( TaxDeclarationDataIndexConstant . COMMERCIAL_HEALTH_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . COMMERCIAL_HEALTH_INSURANCE , commercialHealthInsurance . toPlainString ( ) ) ;
2022-04-16 15:33:51 +08:00
// 税延养老保险
2022-06-09 19:02:18 +08:00
BigDecimal taxDeferredEndowmentInsurance = findValue ( TaxDeclarationDataIndexConstant . TAX_DEFERRED_ENDOWMENT_INSURANCE , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . TAX_DEFERRED_ENDOWMENT_INSURANCE , taxDeferredEndowmentInsurance . toPlainString ( ) ) ;
2022-04-16 15:33:51 +08:00
// 其他
2022-06-09 19:02:18 +08:00
BigDecimal other = findValue ( TaxDeclarationDataIndexConstant . OTHER , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . OTHER , other . toPlainString ( ) ) ;
// 准予扣除的捐赠额
BigDecimal allowedDonation = findValue ( TaxDeclarationDataIndexConstant . ALLOWED_DONATION , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ALLOWED_DONATION , allowedDonation . toPlainString ( ) ) ;
// 生成个税申报表详情
result . getNeedInsertTaxDeclarationDetails ( ) . addAll ( convert2DetailPO ( taxDeclaration , employeeType , employeeId , valueMap ) ) ;
} ) ;
}
2023-01-29 14:58:51 +08:00
/ * *
* 生成个税申报表明细 ( 年终奖 )
*
* @param result
* @param taxDeclaration
* @param salaryAcctResults
* @param salaryItemMap
* /
2023-01-30 17:32:58 +08:00
private static void handleTaxDeclaration4Annual ( Result result ,
2023-01-29 14:58:51 +08:00
TaxDeclarationPO taxDeclaration ,
List < SalaryAcctResultPO > salaryAcctResults ,
Map < String , Long > salaryItemMap ) {
if ( CollectionUtils . isEmpty ( salaryAcctResults ) ) {
return ;
}
// 核算结果按照人员id分类
Map < String , List < SalaryAcctResultPO > > salaryAcctResultPOMap = SalaryEntityUtil . group2Map ( salaryAcctResults , salaryAcctResultPO - > EmployeeTypeEnum . ORGANIZATION . getValue ( ) + " _ " + salaryAcctResultPO . getEmployeeId ( ) ) ;
salaryAcctResultPOMap . forEach ( ( key , salaryAcctResultPOS ) - > {
String [ ] keyArray = StringUtils . split ( key , " _ " ) ;
Integer employeeType = Integer . parseInt ( keyArray [ 0 ] ) ;
Long employeeId = Long . parseLong ( keyArray [ 1 ] ) ;
Map < String , String > valueMap = Maps . newHashMapWithExpectedSize ( 7 ) ;
Map < Long , List < SalaryAcctResultPO > > resultMap = SalaryEntityUtil . group2Map ( salaryAcctResultPOS , SalaryAcctResultPO : : getSalaryItemId ) ;
// 全年一次性奖金额
2023-01-30 17:32:58 +08:00
BigDecimal laborIncome = findValue ( TaxDeclarationDataIndexConstant . ANNUAL_INCOME , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_INCOME , laborIncome . toPlainString ( ) ) ;
2023-01-29 14:58:51 +08:00
// 免税收入
2023-01-30 17:32:58 +08:00
BigDecimal laborTaxFreeIncome = findValue ( TaxDeclarationDataIndexConstant . ANNUAL_TAX_FREE_INCOME , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_TAX_FREE_INCOME , laborTaxFreeIncome . toPlainString ( ) ) ;
2023-01-29 14:58:51 +08:00
// 其他
2023-01-30 17:32:58 +08:00
BigDecimal other = findValue ( TaxDeclarationDataIndexConstant . ANNUAL_OTHER , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_OTHER , other . toPlainString ( ) ) ;
2023-01-29 14:58:51 +08:00
// 准予扣除的捐赠额
2023-01-30 17:32:58 +08:00
BigDecimal allowedDonation = findValue ( TaxDeclarationDataIndexConstant . ANNUAL_DONATE_TAX , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_DONATE_TAX , allowedDonation . toPlainString ( ) ) ;
// 减免税额
BigDecimal annualTaxSavings = findValue ( TaxDeclarationDataIndexConstant . ANNUAL_TAX_SAVINGS , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_TAX_SAVINGS , annualTaxSavings . toPlainString ( ) ) ;
// 备注
2023-02-09 19:03:53 +08:00
String annualRemark = findStringValue ( TaxDeclarationDataIndexConstant . ANNUAL_REMARK , resultMap , salaryItemMap ) ;
valueMap . put ( TaxDeclarationDataIndexConstant . ANNUAL_REMARK , annualRemark ) ;
2023-01-29 14:58:51 +08:00
// 生成个税申报表详情
result . getNeedInsertTaxDeclarationDetails ( ) . addAll ( convert2DetailPO ( taxDeclaration , employeeType , employeeId , valueMap ) ) ;
} ) ;
}
2022-06-09 19:02:18 +08:00
/ * *
* 往期累计情况
*
* @param result
* @param taxDeclaration
* @param salaryAcctResults
* @param salaryItemMap
* /
private static void handleAddUpSituation ( Result result ,
TaxDeclarationPO taxDeclaration ,
List < SalaryAcctResultPO > salaryAcctResults ,
Map < String , Long > salaryItemMap ) {
if ( CollectionUtils . isEmpty ( salaryAcctResults ) ) {
return ;
}
// 核算结果按照人员id分类
Map < String , List < SalaryAcctResultPO > > salaryAcctResultPOMap = SalaryEntityUtil . group2Map ( salaryAcctResults , salaryAcctResultPO - > EmployeeTypeEnum . ORGANIZATION . getValue ( ) + " _ " + salaryAcctResultPO . getEmployeeId ( ) ) ;
salaryAcctResultPOMap . forEach ( ( key , salaryAcctResultPOS ) - > {
String [ ] keyArray = key . split ( " _ " ) ;
Integer employeeType = Integer . parseInt ( keyArray [ 0 ] ) ;
Long employeeId = Long . parseLong ( keyArray [ 1 ] ) ;
Map < Long , List < SalaryAcctResultPO > > resultMap = SalaryEntityUtil . group2Map ( salaryAcctResultPOS , SalaryAcctResultPO : : getSalaryItemId ) ;
// 累计收入额
BigDecimal addUpIncome = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_INCOME , resultMap , salaryItemMap ) ;
2022-05-31 18:27:33 +08:00
// 累计免税收入
2022-06-09 19:02:18 +08:00
BigDecimal addUpTaxFreeIncome = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_TAX_FREE_INCOME , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计减除费用
2022-06-09 19:02:18 +08:00
BigDecimal addUpSubtraction = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_SUBTRACTION , resultMap , salaryItemMap ) ;
// 累计社保个人合计
BigDecimal addUpSocialSecurityTotal = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_SOCIAL_SECURITY_TOTAL , resultMap , salaryItemMap ) ;
// 累计公积金个人合计
BigDecimal addUpAccumulationFundTotal = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_ACCUMULATION_FUND_TOTAL , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计子女教育
2022-06-09 19:02:18 +08:00
BigDecimal addUpChildEducation = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_CHILD_EDUCATION , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计继续教育
2022-06-09 19:02:18 +08:00
BigDecimal addUpContinuingEducation = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_CONTINUING_EDUCATION , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计住房贷款利息
2022-06-09 19:02:18 +08:00
BigDecimal addUpHousingLoanInterest = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_LOAN_INTEREST , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计住房租金
2022-06-09 19:02:18 +08:00
BigDecimal addUpHousingRent = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_HOUSING_RENT , resultMap , salaryItemMap ) ;
2022-04-16 15:33:51 +08:00
// 累计赡养老人
2022-06-09 19:02:18 +08:00
BigDecimal addUpSupportElderly = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_SUPPORT_ELDERLY , resultMap , salaryItemMap ) ;
2022-05-31 18:27:33 +08:00
// 累计大病医疗
2022-06-09 19:02:18 +08:00
BigDecimal addUpIllnessMedical = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_ILLNESS_MEDICAL , resultMap , salaryItemMap ) ;
2022-05-31 18:27:33 +08:00
// 累计婴幼儿照护
2022-06-09 19:02:18 +08:00
BigDecimal addUpInfantCare = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_INFANT_CARE , resultMap , salaryItemMap ) ;
2023-04-13 17:14:58 +08:00
// 累计个人养老金
BigDecimal addUpPrivatePension = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_PRIVATE_PENSION , resultMap , salaryItemMap ) ;
2022-06-09 19:02:18 +08:00
// 累计企业(职业)年金及其他福利
BigDecimal addUpEnterpriseAndOther = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_ENTERPRISE_AND_OTHER , resultMap , salaryItemMap ) ;
// 累计其他免税扣除
BigDecimal addUpOtherDeduction = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_OTHER_DEDUCTION , resultMap , salaryItemMap ) ;
// 累计准予扣除的捐赠额
BigDecimal addUpAllowedDonation = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_ALLOWED_DONATION , resultMap , salaryItemMap ) ;
// 累计应纳税所得额
BigDecimal addUpTaxableIncome = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_TAXABLE_INCOME , resultMap , salaryItemMap ) ;
// 累计应纳税额
BigDecimal addUpTaxPayable = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_TAX_PAYABLE , resultMap , salaryItemMap ) ;
2022-06-10 18:16:11 +08:00
//累计减免税额
BigDecimal addUpTaxDeduction = findAddUpValue ( TaxDeclarationDataIndexConstant . ADD_UP_TAX_DEDUCTION , resultMap , salaryItemMap ) ;
2022-06-09 19:02:18 +08:00
// 累计已预扣预缴税额
2022-08-29 16:06:56 +08:00
List < SalaryAcctResultPO > resultPOS = resultMap . get ( salaryItemMap . getOrDefault ( TaxDeclarationDataIndexConstant . ADD_UP_ADVANCE_TAX , 0L ) ) ;
BigDecimal addUpAdvanceTax = resultPOS = = null ? BigDecimal . ZERO : resultPOS . stream ( )
. map ( salaryAcctResultPO - > SalaryEntityUtil . empty2Zero ( salaryAcctResultPO . getResultValue ( ) ) )
. min ( BigDecimal : : compareTo )
. orElse ( BigDecimal . ZERO ) ;
// 本月(次)应补(退)税额
BigDecimal refundedOrSupplementedTax = SalaryEntityUtil . reduce ( resultMap . get ( salaryItemMap . getOrDefault ( TaxDeclarationDataIndexConstant . REFUNDED_OR_SUPPLEMENTED_TAX , 0L ) ) ,
salaryAcctResultPO - > SalaryEntityUtil . empty2Zero ( salaryAcctResultPO . getResultValue ( ) ) ) ;
2022-06-09 19:02:18 +08:00
// 生成往期累计情况
2022-04-16 15:33:51 +08:00
AddUpSituation accumulatedSituation = AddUpSituation . builder ( )
2022-05-31 18:27:33 +08:00
. employeeId ( employeeId )
2022-06-09 19:02:18 +08:00
// .employeeType(employeeType)
2022-04-16 15:33:51 +08:00
. taxAgentId ( taxDeclaration . getTaxAgentId ( ) )
2022-06-08 16:36:50 +08:00
. taxYearMonth ( taxDeclaration . getTaxCycle ( ) )
. year ( SalaryDateUtil . date2Year ( taxDeclaration . getTaxCycle ( ) ) )
2022-04-16 15:33:51 +08:00
. addUpIncome ( addUpIncome . toPlainString ( ) )
. addUpSocialSecurityTotal ( addUpSocialSecurityTotal . toPlainString ( ) )
. addUpAccumulationFundTotal ( addUpAccumulationFundTotal . toPlainString ( ) )
. addUpEnterpriseAndOther ( addUpEnterpriseAndOther . toPlainString ( ) )
. addUpSubtraction ( addUpSubtraction . toPlainString ( ) )
. addUpChildEducation ( addUpChildEducation . toPlainString ( ) )
. addUpContinuingEducation ( addUpContinuingEducation . toPlainString ( ) )
. addUpHousingLoanInterest ( addUpHousingLoanInterest . toPlainString ( ) )
. addUpHousingRent ( addUpHousingRent . toPlainString ( ) )
. addUpSupportElderly ( addUpSupportElderly . toPlainString ( ) )
2022-05-31 18:27:33 +08:00
. addUpIllnessMedical ( addUpIllnessMedical . toPlainString ( ) )
. addUpInfantCare ( addUpInfantCare . toPlainString ( ) )
2023-04-13 17:14:58 +08:00
. addUpPrivatePension ( addUpPrivatePension . toPlainString ( ) )
2022-04-16 15:33:51 +08:00
. addUpOtherDeduction ( addUpOtherDeduction . toPlainString ( ) )
2022-05-31 18:27:33 +08:00
. addUpTaxExemptIncome ( addUpTaxFreeIncome . toPlainString ( ) )
2022-04-16 15:33:51 +08:00
. addUpAllowedDonation ( addUpAllowedDonation . toPlainString ( ) )
2022-08-29 16:06:56 +08:00
. addUpAdvanceTax ( addUpAdvanceTax . add ( refundedOrSupplementedTax ) . toPlainString ( ) )
2022-06-10 18:16:11 +08:00
. addUpTaxSavings ( addUpTaxDeduction . toPlainString ( ) )
2022-04-16 15:33:51 +08:00
. creator ( taxDeclaration . getCreator ( ) )
. createTime ( taxDeclaration . getCreateTime ( ) )
. updateTime ( taxDeclaration . getUpdateTime ( ) )
. tenantKey ( taxDeclaration . getTenantKey ( ) )
2022-05-31 18:27:33 +08:00
. deleteType ( NumberUtils . INTEGER_ZERO )
2022-04-16 15:33:51 +08:00
. build ( ) ;
2022-12-13 13:34:22 +08:00
encryptUtil . encrypt ( accumulatedSituation , AddUpSituation . class ) ;
2022-06-09 19:02:18 +08:00
result . getNeedInsertAddUpSituations ( ) . add ( accumulatedSituation ) ;
2022-04-16 15:33:51 +08:00
} ) ;
}
2022-06-09 19:02:18 +08:00
// private static void handleTaxDeclarationDetail(Result result,
// TaxDeclarationPO taxDeclaration,
// List<SalaryAcctResultPO> salaryAcctResults,
// Map<String, Long> salaryItemMap) {
// if (CollectionUtils.isEmpty(salaryAcctResults)) {
// return;
// }
// // 核算结果按照人员id分类
// Map<Long, List<SalaryAcctResultPO>> acctResultMap = SalaryEntityUtil.group2Map(salaryAcctResults, SalaryAcctResultPO::getEmployeeId);
// acctResultMap.forEach((k, v) -> {
// Long employeeId = k;
// Map<String, BigDecimal> valueMap = new HashMap<>();
// Map<Long, List<SalaryAcctResultPO>> resultMap = SalaryEntityUtil.group2Map(v, SalaryAcctResultPO::getSalaryItemId);
// // 收入
// BigDecimal income = SalaryEntityUtil.reduce(resultMap.get(salaryItemMap.getOrDefault("income", 0L)), e -> SalaryEntityUtil.empty2Zero(e.getResultValue()));
// valueMap.put("income", income);
// // 费用
// BigDecimal fee = BigDecimal.ZERO;
// valueMap.put("fee", fee);
// // 免税收入
// BigDecimal taxFreeIncome = BigDecimal.ZERO;
// valueMap.put("taxFreeIncome", taxFreeIncome);
// // 减除费用
// BigDecimal subtraction = findValue("subtraction", resultMap, salaryItemMap);
// valueMap.put("subtraction", subtraction);
// // 基本养老保险
// BigDecimal endowmentInsurance = findValue("endowmentInsurance", resultMap, salaryItemMap);
// valueMap.put("endowmentInsurance", endowmentInsurance);
// // 基本医疗保险
// BigDecimal medicalInsurance = findValue("medicalInsurance", resultMap, salaryItemMap);
// valueMap.put("medicalInsurance", medicalInsurance);
// // 失业保险
// BigDecimal unemploymentInsurance = findValue("unemploymentInsurance", resultMap, salaryItemMap);
// valueMap.put("unemploymentInsurance", unemploymentInsurance);
// // 住房公积金
// BigDecimal housingProvidentFund = findValue("housingProvidentFund", resultMap, salaryItemMap);
// valueMap.put("housingProvidentFund", housingProvidentFund);
// // 年金
// BigDecimal annuity = findValue("annuity", resultMap, salaryItemMap);
// valueMap.put("annuity", annuity);
// // 商业健康保险
// BigDecimal commercialHealthInsurance = findValue("commercialHealthInsurance", resultMap, salaryItemMap);
// valueMap.put("commercialHealthInsurance", commercialHealthInsurance);
// // 税延养老保险
// BigDecimal taxDeferredEndowmentInsurance = findValue("taxDeferredEndowmentInsurance", resultMap, salaryItemMap);
// valueMap.put("taxDeferredEndowmentInsurance", taxDeferredEndowmentInsurance);
// // 财产原值
// BigDecimal originalValueOfProperty = findValue("originalValueOfProperty", resultMap, salaryItemMap);
// valueMap.put("originalValueOfProperty", originalValueOfProperty);
// // 允许扣除的税费
// BigDecimal deductedTax = findValue("deductedTax", resultMap, salaryItemMap);
// valueMap.put("deductedTax", deductedTax);
// // 其他
// BigDecimal other = findValue("other", resultMap, salaryItemMap);
// valueMap.put("other", other);
// // 累计收入
// BigDecimal addUpIncome = findAddUpValue("addUpIncome", resultMap, salaryItemMap);
// valueMap.put("addUpIncome", addUpIncome);
// // 累计免税收入
// BigDecimal addUpTaxFreeIncome = findAddUpValue("addUpTaxFreeIncome", resultMap, salaryItemMap);
// valueMap.put("addUpTaxFreeIncome", addUpTaxFreeIncome);
// // 累计减除费用
// BigDecimal addUpSubtraction = findAddUpValue("addUpSubtraction", resultMap, salaryItemMap);
// valueMap.put("addUpSubtraction", addUpSubtraction);
// // 累计专项扣除
// BigDecimal addUpSpecialDeduction = findAddUpValue("addUpSpecialDeduction", resultMap, salaryItemMap);
// valueMap.put("addUpSpecialDeduction", addUpSpecialDeduction);
// // 累计子女教育
// BigDecimal addUpChildEducation = findAddUpValue("addUpChildEducation", resultMap, salaryItemMap);
// valueMap.put("addUpChildEducation", addUpChildEducation);
// // 累计继续教育
// BigDecimal addUpContinuingEducation = findAddUpValue("addUpContinuingEducation", resultMap, salaryItemMap);
// valueMap.put("addUpContinuingEducation", addUpContinuingEducation);
// // 累计住房贷款利息
// BigDecimal addUpHousingLoanInterest = findAddUpValue("addUpHousingLoanInterest", resultMap, salaryItemMap);
// valueMap.put("addUpHousingLoanInterest", addUpHousingLoanInterest);
// // 累计住房租金
// BigDecimal addUpHousingRent = findAddUpValue("addUpHousingRent", resultMap, salaryItemMap);
// valueMap.put("addUpHousingRent", addUpHousingRent);
// // 累计赡养老人
// BigDecimal addUpSupportElderly = findAddUpValue("addUpSupportElderly", resultMap, salaryItemMap);
// valueMap.put("addUpSupportElderly", addUpSupportElderly);
// // 累计大病医疗
// BigDecimal addUpIllnessMedical = findAddUpValue("addUpIllnessMedical", resultMap, salaryItemMap);
// valueMap.put("addUpIllnessMedical", addUpIllnessMedical);
// // 累计婴幼儿照护
// BigDecimal addUpInfantCare = findAddUpValue("addUpInfantCare", resultMap, salaryItemMap);
// valueMap.put("addUpInfantCare", addUpInfantCare);
// // 累计其他扣除
// BigDecimal addUpOtherDeduction = findAddUpValue("addUpOtherDeduction", resultMap, salaryItemMap);
// valueMap.put("addUpOtherDeduction", addUpOtherDeduction);
// // 减按计税比例
// BigDecimal lessTaxProportion = BigDecimal.ONE;
// valueMap.put("lessTaxProportion", lessTaxProportion);
// // 准允扣除的捐赠额
// BigDecimal addUpAllowedDonation = findAddUpValue("addUpAllowedDonation", resultMap, salaryItemMap);
// valueMap.put("addUpAllowedDonation", addUpAllowedDonation);
// // 应纳税所得额
// BigDecimal addUpTaxableIncome = findAddUpValue("addUpTaxableIncome", resultMap, salaryItemMap);
// valueMap.put("addUpTaxableIncome", addUpTaxableIncome);
// // 税率
// BigDecimal taxRate = findAddUpValue("taxRate", resultMap, salaryItemMap);
// valueMap.put("taxRate", taxRate);
// // 速算扣除数
// BigDecimal quickDeductionFactor = findAddUpValue("quickDeductionFactor", resultMap, salaryItemMap);
// valueMap.put("quickDeductionFactor", quickDeductionFactor);
// // 应纳税额
// BigDecimal addUpTaxPayable = findAddUpValue("addUpTaxPayable", resultMap, salaryItemMap);
// valueMap.put("addUpTaxPayable", addUpTaxPayable);
// // 减免税额
// BigDecimal addUpTaxDeduction = BigDecimal.ZERO;
// valueMap.put("addUpTaxDeduction", addUpTaxDeduction);
// // 减免税额
// BigDecimal taxDeduction = findValue("taxDeduction", resultMap, salaryItemMap);
// valueMap.put("taxDeduction", taxDeduction);
// // 应补缴税额
// BigDecimal refundedOrSupplementedTax = SalaryEntityUtil.reduce(resultMap.get(salaryItemMap.getOrDefault("refundedOrSupplementedTax", 0L)),
// e -> SalaryEntityUtil.empty2Zero(e.getResultValue()));
// valueMap.put("refundedOrSupplementedTax", refundedOrSupplementedTax);
// // 已扣缴税额
// BigDecimal taxWithheld = addUpTaxPayable.subtract(refundedOrSupplementedTax);
// valueMap.put("taxWithheld", taxWithheld);
//
// valueMap.forEach((key, value) -> {
// TaxDeclarationDetailPO detailPO = TaxDeclarationDetailPO.builder()
// .taxDeclarationId(taxDeclaration.getId())
// .employeeId(k)
// .fieldCode(key)
// .fieldValue(value.toPlainString())
// .creator(taxDeclaration.getCreator())
// .createTime(taxDeclaration.getCreateTime())
// .updateTime(taxDeclaration.getUpdateTime())
// .deleteType(0)
// .tenantKey(taxDeclaration.getTenantKey())
// .build();
// result.getNeedInsertTaxDeclarationDetails().add(detailPO);
// });
// // 累计社保个人合计
// BigDecimal addUpSocialSecurityTotal = findAddUpValue("addUpSocialSecurityTotal", resultMap, salaryItemMap);
// // 累计公积金个人合计
// BigDecimal addUpAccumulationFundTotal = findAddUpValue("addUpAccumulationFundTotal", resultMap, salaryItemMap);
// // 累计年金及其他福利合计
// BigDecimal addUpEnterpriseAndOther = findAddUpValue("addUpEnterpriseAndOther", resultMap, salaryItemMap);
//
// // 更新累计情况
// AddUpSituation accumulatedSituation = AddUpSituation.builder()
// .employeeId(employeeId)
// .taxAgentId(taxDeclaration.getTaxAgentId())
// .taxYearMonth(taxDeclaration.getTaxCycle())
// .year(SalaryDateUtil.date2Year(taxDeclaration.getTaxCycle()))
// .addUpIncome(addUpIncome.toPlainString())
// .addUpSocialSecurityTotal(addUpSocialSecurityTotal.toPlainString())
// .addUpAccumulationFundTotal(addUpAccumulationFundTotal.toPlainString())
// .addUpEnterpriseAndOther(addUpEnterpriseAndOther.toPlainString())
// .addUpSubtraction(addUpSubtraction.toPlainString())
// .addUpChildEducation(addUpChildEducation.toPlainString())
// .addUpContinuingEducation(addUpContinuingEducation.toPlainString())
// .addUpHousingLoanInterest(addUpHousingLoanInterest.toPlainString())
// .addUpHousingRent(addUpHousingRent.toPlainString())
// .addUpSupportElderly(addUpSupportElderly.toPlainString())
// .addUpIllnessMedical(addUpIllnessMedical.toPlainString())
// .addUpInfantCare(addUpInfantCare.toPlainString())
// .addUpOtherDeduction(addUpOtherDeduction.toPlainString())
// .addUpTaxExemptIncome(addUpTaxFreeIncome.toPlainString())
// .addUpAllowedDonation(addUpAllowedDonation.toPlainString())
// .addUpAdvanceTax(addUpTaxPayable.toPlainString())
//// .addUpTaxSavings(taxDeduction.toPlainString())
// .creator(taxDeclaration.getCreator())
// .createTime(taxDeclaration.getCreateTime())
// .updateTime(taxDeclaration.getUpdateTime())
// .tenantKey(taxDeclaration.getTenantKey())
// .deleteType(NumberUtils.INTEGER_ZERO)
// .build();
// result.getNeedInsertAccumulatedSituations().add(accumulatedSituation);
// });
// }
private static TaxDeclarationPO convert2PO ( TaxDeclarationSaveParam saveParam , User user , Date taxCycle , Long taxAgentId , Integer incomeCategory ) {
2022-04-16 15:33:51 +08:00
LocalDateTime now = LocalDateTime . now ( ) ;
2022-06-08 16:36:50 +08:00
if ( saveParam . getDescription ( ) = = null ) {
2022-04-20 21:36:27 +08:00
saveParam . setDescription ( " " ) ;
}
2022-04-16 15:33:51 +08:00
return TaxDeclarationPO . builder ( )
. id ( IdGenerator . generate ( ) )
2022-06-09 19:02:18 +08:00
. incomeCategory ( incomeCategory )
2022-04-16 15:33:51 +08:00
. taxAgentId ( taxAgentId )
. salaryMonth ( SalaryDateUtil . localDateToDate ( saveParam . getSalaryMonth ( ) . atDay ( 1 ) ) )
. taxCycle ( taxCycle )
. description ( saveParam . getDescription ( ) )
2022-06-08 16:36:50 +08:00
. creator ( ( long ) user . getUID ( ) )
2022-04-16 15:33:51 +08:00
. createTime ( SalaryDateUtil . localDateTimeToDate ( now ) )
. updateTime ( SalaryDateUtil . localDateTimeToDate ( now ) )
. deleteType ( 0 )
2022-06-09 19:02:18 +08:00
. tenantKey ( SalaryDefaultTenantConstant . DEFAULT_TENANT_KEY )
2022-04-16 15:33:51 +08:00
. build ( ) ;
}
2022-06-09 19:02:18 +08:00
/ * *
* 根据参数生成个税申报表详情po
*
* @param taxDeclaration
* @param employeeId
* @param valueMap
* @return
* /
private static List < TaxDeclarationDetailPO > convert2DetailPO ( TaxDeclarationPO taxDeclaration , Integer employeeType , Long employeeId , Map < String , String > valueMap ) {
if ( MapUtils . isEmpty ( valueMap ) ) {
return Collections . emptyList ( ) ;
}
List < TaxDeclarationDetailPO > taxDeclarationDetailPOS = Lists . newArrayListWithExpectedSize ( valueMap . size ( ) ) ;
valueMap . forEach ( ( fieldCode , fieldValue ) - > {
TaxDeclarationDetailPO taxDeclarationDetailPO = TaxDeclarationDetailPO . builder ( )
. id ( IdGenerator . generate ( ) )
. taxDeclarationId ( taxDeclaration . getId ( ) )
2022-06-10 13:33:48 +08:00
. employeeType ( employeeType )
2022-06-09 19:02:18 +08:00
. employeeId ( employeeId )
. fieldCode ( fieldCode )
. fieldValue ( fieldValue )
. creator ( taxDeclaration . getCreator ( ) )
. createTime ( taxDeclaration . getCreateTime ( ) )
. updateTime ( taxDeclaration . getUpdateTime ( ) )
. deleteType ( NumberUtils . INTEGER_ZERO )
. tenantKey ( taxDeclaration . getTenantKey ( ) )
. build ( ) ;
taxDeclarationDetailPOS . add ( taxDeclarationDetailPO ) ;
} ) ;
return taxDeclarationDetailPOS ;
}
2022-04-16 15:33:51 +08:00
private static BigDecimal findValue ( String fieldCode , Map < Long , List < SalaryAcctResultPO > > resultMap , Map < String , Long > salaryItemMap ) {
return resultMap . getOrDefault ( salaryItemMap . getOrDefault ( fieldCode , 0L ) , Collections . emptyList ( ) ) . stream ( )
. map ( e - > SalaryEntityUtil . empty2Zero ( e . getResultValue ( ) ) )
. filter ( e - > e . compareTo ( BigDecimal . ZERO ) > 0 )
. findAny ( )
. orElse ( BigDecimal . ZERO ) ;
}
private static BigDecimal findAddUpValue ( String fieldCode , Map < Long , List < SalaryAcctResultPO > > resultMap , Map < String , Long > salaryItemMap ) {
return resultMap . getOrDefault ( salaryItemMap . getOrDefault ( fieldCode , 0L ) , Collections . emptyList ( ) ) . stream ( )
. map ( e - > SalaryEntityUtil . empty2Zero ( e . getResultValue ( ) ) )
. max ( Comparator . comparingDouble ( BigDecimal : : doubleValue ) )
. orElse ( BigDecimal . ZERO ) ;
}
2023-02-09 19:03:53 +08:00
private static String findStringValue ( String fieldCode , Map < Long , List < SalaryAcctResultPO > > resultMap , Map < String , Long > salaryItemMap ) {
return resultMap . getOrDefault ( salaryItemMap . getOrDefault ( fieldCode , 0L ) , Collections . emptyList ( ) ) . stream ( )
. map ( SalaryAcctResultPO : : getResultValue )
2025-11-28 15:41:42 +08:00
. filter ( Objects : : nonNull )
2023-02-09 19:03:53 +08:00
. findFirst ( ) . orElse ( " " ) ;
}
2022-04-16 15:33:51 +08:00
@Data
public static class Result {
private Collection < TaxDeclarationPO > needInsertTaxDeclarations ;
private Collection < TaxDeclarationDetailPO > needInsertTaxDeclarationDetails ;
2022-06-09 19:02:18 +08:00
private Collection < AddUpSituation > needInsertAddUpSituations ;
2022-04-16 15:33:51 +08:00
public Result ( ) {
this . needInsertTaxDeclarations = Lists . newArrayList ( ) ;
this . needInsertTaxDeclarationDetails = Lists . newArrayList ( ) ;
2022-06-09 19:02:18 +08:00
this . needInsertAddUpSituations = Lists . newArrayList ( ) ;
2022-04-16 15:33:51 +08:00
}
}
}