diff --git a/src/com/engine/salary/entity/taxdeclaration/bo/TaxDeclarationCommon.java b/src/com/engine/salary/entity/taxdeclaration/bo/TaxDeclarationCommon.java index e870f624e..19d0e742f 100644 --- a/src/com/engine/salary/entity/taxdeclaration/bo/TaxDeclarationCommon.java +++ b/src/com/engine/salary/entity/taxdeclaration/bo/TaxDeclarationCommon.java @@ -1,5 +1,7 @@ package com.engine.salary.entity.taxdeclaration.bo; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.StrUtil; import com.engine.salary.annotation.SalaryFormulaVar; import com.engine.salary.constant.SalaryDefaultTenantConstant; import com.engine.salary.entity.datacollection.AddUpSituation; @@ -20,7 +22,6 @@ import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.db.IdGenerator; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.apache.commons.lang3.StringUtils; import java.lang.reflect.Field; import java.math.BigDecimal; @@ -49,29 +50,116 @@ public class TaxDeclarationCommon implements TaxDeclarationStrategy { List taxDeclarationValues = Lists.newArrayListWithExpectedSize(employeeIdKeyMap.size()); for (Map.Entry> employeeIdEntry : employeeIdKeyMap.entrySet()) { - // 取最后一次薪资核算记录的核算结果作为个税申报表的数据来源 - SalaryAcctEmployeePO lastSalaryAcctEmployee = SalaryEntityUtil.findFirst(employeeIdEntry.getValue()); - for (SalaryAcctEmployeePO salaryAcctEmployee : employeeIdEntry.getValue()) { - SalaryAcctRecordPO salaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(salaryAcctEmployee.getSalaryAcctRecordId()); - SalaryAcctRecordPO lastSalaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(lastSalaryAcctEmployee.getSalaryAcctRecordId()); - if (salaryAcctRecord.getCreateTime().compareTo(lastSalaryAcctRecord.getCreateTime()) > 0) { - lastSalaryAcctEmployee = salaryAcctEmployee; - } - } + Map valueMap = Maps.newHashMap(); for (TaxReportColumnPO taxReportColumn : taxDeclareContext.getTaxReportColumns()) { - SalarySobTaxReportRulePO salarySobTaxReportRule = taxDeclareContext.getSalarySobTaxReportRuleMap() - .get(lastSalaryAcctEmployee.getSalarySobId() + "-" + taxReportColumn.getReportColumnDataIndex()); - List salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId()); String value = ""; - if (salarySobTaxReportRule != null && salaryAcctResultValue != null) { - value = salaryAcctResultValue.stream() - .filter(result -> result.getSalaryItemId().equals(salarySobTaxReportRule.getSalaryItemId())) - .findFirst() - .orElse(new SalaryAcctResultPO()) - .getResultValue(); + + List firstValueList = Lists.newArrayList( + "taxFreeIncome", + "endowmentInsurance", + "medicalInsurance", + "unemploymentInsurance", + "housingProvidentFund", + "addUpChildEducation", + "addUpHousingLoanInterest", + "addUpHousingRent", + "addUpSupportElderly", + "addUpContinuingEducation", + "addUpInfantCare", + "annuity", + "commercialHealthInsurance", + "taxDeferredEndowmentInsurance", + "other", + "allowedDonation", + "taxDeduction", + "description", + "addUpAdvanceTax"); + + List lastValueList = Lists.newArrayList( + "addUpIncome", + "addUpTaxFreeIncome", + "addUpSubtraction", + "addUpSpecialDeduction", + "addUpOtherDeduction", + "addUpAllowedDonation", + "addUpTaxableIncome", + "taxRate", + "quickDeductionFactor", + "addUpTaxPayable", + "addUpTaxDeduction" + ); + + List mergeValueList = Lists.newArrayList( + "income", + "refundedOrSupplementedTax" + ); + + //取第一次值 + if (firstValueList.contains(taxReportColumn.getReportColumnDataIndex())) { + SalaryAcctEmployeePO lastSalaryAcctEmployee = SalaryEntityUtil.findFirst(employeeIdEntry.getValue()); + for (SalaryAcctEmployeePO salaryAcctEmployee : employeeIdEntry.getValue()) { + SalaryAcctRecordPO salaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(salaryAcctEmployee.getSalaryAcctRecordId()); + SalaryAcctRecordPO lastSalaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(lastSalaryAcctEmployee.getSalaryAcctRecordId()); + if (salaryAcctRecord.getCreateTime().compareTo(lastSalaryAcctRecord.getCreateTime()) < 0) { + lastSalaryAcctEmployee = salaryAcctEmployee; + } + } + SalarySobTaxReportRulePO salarySobTaxReportRule = taxDeclareContext.getSalarySobTaxReportRuleMap() + .get(lastSalaryAcctEmployee.getSalarySobId() + "-" + taxReportColumn.getReportColumnDataIndex()); + List salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId()); + if (salarySobTaxReportRule != null && salaryAcctResultValue != null) { + value = salaryAcctResultValue.stream() + .filter(result -> result.getSalaryItemId().equals(salarySobTaxReportRule.getSalaryItemId())) + .findFirst() + .orElse(new SalaryAcctResultPO()) + .getResultValue(); + } + value = StrUtil.isNotBlank(value) ? value : Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0.00" : ""; + } + //取多次累计值 + else if (mergeValueList.contains(taxReportColumn.getReportColumnDataIndex()) && Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue())) { + List employeePOS = employeeIdEntry.getValue(); + BigDecimal income = new BigDecimal("0.00"); + for (SalaryAcctEmployeePO salaryAcctEmployeePO : employeePOS) { + SalarySobTaxReportRulePO incomeRule = taxDeclareContext.getSalarySobTaxReportRuleMap() + .get(salaryAcctEmployeePO.getSalarySobId() + "-" + taxReportColumn.getReportColumnDataIndex()); + List salaryAcctResultValue = salaryAcctResultValueMap.get(salaryAcctEmployeePO.getId()); + if (incomeRule != null && salaryAcctResultValue != null) { + String incomeValue = salaryAcctResultValue.stream() + .filter(result -> result.getSalaryItemId().equals(incomeRule.getSalaryItemId())) + .findFirst() + .orElse(new SalaryAcctResultPO()) + .getResultValue(); + if (StrUtil.isNotBlank(incomeValue) && NumberUtil.isNumber(incomeValue)) { + income = income.add(new BigDecimal(incomeValue)); + } + } + } + value = income.toPlainString(); + } + //取最后一次值 + else { + SalaryAcctEmployeePO lastSalaryAcctEmployee = SalaryEntityUtil.findFirst(employeeIdEntry.getValue()); + for (SalaryAcctEmployeePO salaryAcctEmployee : employeeIdEntry.getValue()) { + SalaryAcctRecordPO salaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(salaryAcctEmployee.getSalaryAcctRecordId()); + SalaryAcctRecordPO lastSalaryAcctRecord = taxDeclareContext.getSalaryAcctRecordMap().get(lastSalaryAcctEmployee.getSalaryAcctRecordId()); + if (salaryAcctRecord.getCreateTime().compareTo(lastSalaryAcctRecord.getCreateTime()) > 0) { + lastSalaryAcctEmployee = salaryAcctEmployee; + } + } + SalarySobTaxReportRulePO salarySobTaxReportRule = taxDeclareContext.getSalarySobTaxReportRuleMap() + .get(lastSalaryAcctEmployee.getSalarySobId() + "-" + taxReportColumn.getReportColumnDataIndex()); + List salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId()); + if (salarySobTaxReportRule != null && salaryAcctResultValue != null) { + value = salaryAcctResultValue.stream() + .filter(result -> result.getSalaryItemId().equals(salarySobTaxReportRule.getSalaryItemId())) + .findFirst() + .orElse(new SalaryAcctResultPO()) + .getResultValue(); + } + value = StrUtil.isNotBlank(value) ? value : Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0.00" : ""; } - value = StringUtils.isNotBlank(value) ? value : Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0.00" : ""; valueMap.put(taxReportColumn.getReportColumnDataIndex(), value); } TaxDeclarationValuePO taxDeclarationValue = TaxDeclarationValuePO.builder()