2023-08-14 20:07:29 +08:00
|
|
|
|
package com.engine.salary.entity.taxdeclaration.bo;
|
|
|
|
|
|
|
|
|
|
|
|
import com.engine.salary.annotation.SalaryFormulaVar;
|
|
|
|
|
|
import com.engine.salary.constant.SalaryDefaultTenantConstant;
|
|
|
|
|
|
import com.engine.salary.entity.datacollection.AddUpSituation;
|
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
|
|
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobAddUpRulePO;
|
|
|
|
|
|
import com.engine.salary.entity.salarysob.po.SalarySobTaxReportRulePO;
|
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO;
|
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationValuePO;
|
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxReportColumnPO;
|
|
|
|
|
|
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
|
|
|
|
|
|
import com.engine.salary.enums.salarysob.IncomeCategoryEnum;
|
|
|
|
|
|
import com.engine.salary.enums.sicategory.DeleteTypeEnum;
|
2023-08-21 19:35:14 +08:00
|
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
2023-08-14 20:07:29 +08:00
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
import dm.jdbc.util.IdGenerator;
|
2023-12-20 17:21:46 +08:00
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2023-08-14 20:07:29 +08:00
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-23 16:49:45 +08:00
|
|
|
|
* 通用:一般劳务报酬所得、全年一次性奖金
|
|
|
|
|
|
* <p>Copyright: Copyright (c) 2023</p>
|
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
|
*
|
|
|
|
|
|
* @author qiantao
|
|
|
|
|
|
* @version 1.0
|
|
|
|
|
|
**/
|
2023-08-14 20:07:29 +08:00
|
|
|
|
public class TaxDeclarationCommon implements TaxDeclarationStrategy {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public TaxDeclarationGenerateResult generate(TaxDeclareContext taxDeclareContext, Long employeeId) {
|
|
|
|
|
|
Date now = new Date();
|
|
|
|
|
|
// 薪资核算结果按照薪资核算人员id聚合分类
|
|
|
|
|
|
Map<Long, List<SalaryAcctResultPO>> salaryAcctResultValueMap = SalaryEntityUtil.group2Map(
|
|
|
|
|
|
taxDeclareContext.getSalaryAcctResultValues(), SalaryAcctResultPO::getSalaryAcctEmpId);
|
|
|
|
|
|
// 薪资核算人员按照人员id聚合分类
|
|
|
|
|
|
Map<Long, List<SalaryAcctEmployeePO>> employeeIdKeyMap = SalaryEntityUtil.group2Map(
|
|
|
|
|
|
taxDeclareContext.getSalaryAcctEmployees(), SalaryAcctEmployeePO::getEmployeeId);
|
|
|
|
|
|
|
|
|
|
|
|
List<TaxDeclarationValuePO> taxDeclarationValues = Lists.newArrayListWithExpectedSize(employeeIdKeyMap.size());
|
|
|
|
|
|
for (Map.Entry<Long, List<SalaryAcctEmployeePO>> 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<String, String> valueMap = Maps.newHashMap();
|
|
|
|
|
|
for (TaxReportColumnPO taxReportColumn : taxDeclareContext.getTaxReportColumns()) {
|
|
|
|
|
|
SalarySobTaxReportRulePO salarySobTaxReportRule = taxDeclareContext.getSalarySobTaxReportRuleMap()
|
|
|
|
|
|
.get(lastSalaryAcctEmployee.getSalarySobId() + "-" + taxReportColumn.getReportColumnDataIndex());
|
|
|
|
|
|
List<SalaryAcctResultPO> salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId());
|
2023-12-20 17:21:46 +08:00
|
|
|
|
String value = "";
|
2023-08-14 20:07:29 +08:00
|
|
|
|
if (salarySobTaxReportRule != null && salaryAcctResultValue != null) {
|
|
|
|
|
|
value = salaryAcctResultValue.stream()
|
|
|
|
|
|
.filter(result -> result.getSalaryItemId().equals(salarySobTaxReportRule.getSalaryItemId()))
|
|
|
|
|
|
.findFirst()
|
|
|
|
|
|
.orElse(new SalaryAcctResultPO())
|
|
|
|
|
|
.getResultValue();
|
|
|
|
|
|
}
|
2023-12-20 17:21:46 +08:00
|
|
|
|
value = StringUtils.isNotBlank(value) ? value : Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0.00" : "";
|
2023-08-14 20:07:29 +08:00
|
|
|
|
valueMap.put(taxReportColumn.getReportColumnDataIndex(), value);
|
|
|
|
|
|
}
|
|
|
|
|
|
TaxDeclarationValuePO taxDeclarationValue = TaxDeclarationValuePO.builder()
|
|
|
|
|
|
.id(IdGenerator.generate())
|
|
|
|
|
|
.taxDeclareRecordId(taxDeclareContext.getTaxDeclaration().getTaxDeclareRecordId())
|
|
|
|
|
|
.taxDeclarationId(taxDeclareContext.getTaxDeclaration().getId())
|
|
|
|
|
|
.employeeType(employeeIdEntry.getValue().get(0).getEmployeeType())
|
|
|
|
|
|
.employeeId(employeeIdEntry.getKey())
|
|
|
|
|
|
.resultValue(valueMap)
|
|
|
|
|
|
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
|
|
|
|
|
|
.creator(employeeId)
|
|
|
|
|
|
.deleteType(DeleteTypeEnum.NOT_DELETED.getValue())
|
|
|
|
|
|
.createTime(now)
|
|
|
|
|
|
.updateTime(now)
|
|
|
|
|
|
.build();
|
|
|
|
|
|
taxDeclarationValues.add(taxDeclarationValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 生成累计数据
|
|
|
|
|
|
List<AddUpSituation> addUpSituations = generateAddUpSituation(taxDeclareContext, salaryAcctResultValueMap, employeeIdKeyMap);
|
|
|
|
|
|
return new TaxDeclarationGenerateResult()
|
|
|
|
|
|
.setTaxDeclarationValues(taxDeclarationValues)
|
|
|
|
|
|
.setAddUpSituations(addUpSituations);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 生成往期累计数据
|
|
|
|
|
|
*
|
|
|
|
|
|
* @param taxDeclareContext
|
|
|
|
|
|
* @param salaryAcctResultValueMap
|
|
|
|
|
|
* @param employeeIdKeyMap
|
|
|
|
|
|
* @return
|
|
|
|
|
|
*/
|
|
|
|
|
|
private List<AddUpSituation> generateAddUpSituation(TaxDeclareContext taxDeclareContext,
|
|
|
|
|
|
Map<Long, List<SalaryAcctResultPO>> salaryAcctResultValueMap,
|
|
|
|
|
|
Map<Long, List<SalaryAcctEmployeePO>> employeeIdKeyMap) {
|
|
|
|
|
|
List<AddUpSituation> addUpSituations = Lists.newArrayList();
|
|
|
|
|
|
// 只有「工资工资薪金」、「保险营销员佣金收入」、「证券经纪人佣金收入」、「其他连续劳务报酬所得」需要累计计税
|
|
|
|
|
|
TaxDeclarationPO taxDeclaration = taxDeclareContext.getTaxDeclaration();
|
|
|
|
|
|
if (!Objects.equals(taxDeclaration.getIncomeCategory(), IncomeCategoryEnum.WAGES_AND_SALARIES.getValue())
|
|
|
|
|
|
&& !Objects.equals(taxDeclaration.getIncomeCategory(), IncomeCategoryEnum.INCOME_FOR_INSURANCE_SALESMAN.getValue())
|
|
|
|
|
|
&& !Objects.equals(taxDeclaration.getIncomeCategory(), IncomeCategoryEnum.INCOME_FOR_SECURITIES_BROKER.getValue())
|
|
|
|
|
|
&& !Objects.equals(taxDeclaration.getIncomeCategory(), IncomeCategoryEnum.REMUNERATION_FOR_OTHER_CONTINUOUS_LABOR.getValue())) {
|
|
|
|
|
|
return addUpSituations;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (Map.Entry<Long, List<SalaryAcctEmployeePO>> 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
List<SalaryAcctResultPO> salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId());
|
|
|
|
|
|
Map<String, String> valueMap = Maps.newHashMap();
|
|
|
|
|
|
for (Field declaredField : AddUpSituation.class.getDeclaredFields()) {
|
|
|
|
|
|
if (!declaredField.isAnnotationPresent(SalaryFormulaVar.class)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
SalarySobAddUpRulePO salarySobAddUpRule = taxDeclareContext.getSalarySobAddUpRuleMap()
|
|
|
|
|
|
.get(lastSalaryAcctEmployee.getSalarySobId() + "-" + declaredField.getName());
|
|
|
|
|
|
String value = BigDecimal.ZERO.toPlainString();
|
|
|
|
|
|
if (Objects.nonNull(salarySobAddUpRule) && Objects.nonNull(salaryAcctResultValue)) {
|
|
|
|
|
|
value = salaryAcctResultValue.stream()
|
|
|
|
|
|
.filter(e -> e.getSalaryItemId().equals(salarySobAddUpRule.getSalaryItemId()))
|
|
|
|
|
|
.findFirst()
|
|
|
|
|
|
.orElse(new SalaryAcctResultPO())
|
|
|
|
|
|
.getResultValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
valueMap.put(declaredField.getName(), value);
|
|
|
|
|
|
}
|
|
|
|
|
|
AddUpSituation addUpSituation = AddUpSituation.builder()
|
|
|
|
|
|
.id(IdGenerator.generate())
|
|
|
|
|
|
.employeeId(lastSalaryAcctEmployee.getEmployeeId())
|
2023-07-20 09:58:27 +08:00
|
|
|
|
// .employeeType(lastSalaryAcctEmployee.getEmployeeType())
|
2023-08-14 20:07:29 +08:00
|
|
|
|
.taxAgentId(lastSalaryAcctEmployee.getTaxAgentId())
|
|
|
|
|
|
.taxYearMonth(taxDeclaration.getTaxCycle())
|
2023-08-21 19:35:14 +08:00
|
|
|
|
.year(SalaryDateUtil.date2Year(taxDeclaration.getTaxCycle()))
|
2023-08-14 20:07:29 +08:00
|
|
|
|
.addUpIncome(valueMap.get("addUpIncome"))
|
|
|
|
|
|
.addUpSocialSecurityTotal(valueMap.get("addUpSocialSecurityTotal"))
|
|
|
|
|
|
.addUpAccumulationFundTotal(valueMap.get("addUpAccumulationFundTotal"))
|
|
|
|
|
|
.addUpEnterpriseAndOther(valueMap.get("addUpEnterpriseAndOther"))
|
|
|
|
|
|
.addUpSubtraction(valueMap.get("addUpSubtraction"))
|
|
|
|
|
|
.addUpOtherDeduction(valueMap.get("addUpOtherDeduction"))
|
|
|
|
|
|
.addUpTaxExemptIncome(valueMap.get("addUpTaxExemptIncome"))
|
|
|
|
|
|
.addUpAllowedDonation(valueMap.get("addUpAllowedDonation"))
|
2023-10-23 10:03:04 +08:00
|
|
|
|
.addUpTaxSavings(valueMap.get("addUpTaxSavings"))
|
2023-08-14 20:07:29 +08:00
|
|
|
|
.addUpAdvanceTax(valueMap.get("addUpAdvanceTax"))
|
2023-10-23 10:03:04 +08:00
|
|
|
|
.taxAdjustment(valueMap.get("taxAdjustment"))
|
2023-09-07 18:21:22 +08:00
|
|
|
|
.addUpTaxableIncome(valueMap.get("addUpTaxableIncome"))
|
2023-07-20 09:58:27 +08:00
|
|
|
|
// .modifier(taxDeclaration.getCreator())
|
2023-08-14 20:07:29 +08:00
|
|
|
|
.creator(taxDeclaration.getCreator())
|
|
|
|
|
|
.createTime(taxDeclaration.getCreateTime())
|
|
|
|
|
|
.updateTime(taxDeclaration.getUpdateTime())
|
|
|
|
|
|
.tenantKey(taxDeclaration.getTenantKey())
|
|
|
|
|
|
.deleteType(taxDeclaration.getDeleteType())
|
|
|
|
|
|
.build();
|
|
|
|
|
|
addUpSituations.add(addUpSituation);
|
|
|
|
|
|
}
|
|
|
|
|
|
return addUpSituations;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|