168 lines
11 KiB
Java
168 lines
11 KiB
Java
|
|
//package com.engine.salary.entity.taxdeclaration.bo;
|
||
|
|
//
|
||
|
|
//import com.engine.salary.entity.salaryacct.po.SalaryAcctEmployeePO;
|
||
|
|
//import com.engine.salary.entity.salaryacct.po.SalaryAcctResultPO;
|
||
|
|
//import com.engine.salary.util.SalaryEntityUtil;
|
||
|
|
//import com.google.common.collect.Lists;
|
||
|
|
//import com.google.common.collect.Maps;
|
||
|
|
//import com.weaver.common.distribution.genid.IdGenerator;
|
||
|
|
//import com.weaver.common.elog.util.Util;
|
||
|
|
//import com.weaver.hrm.salary.annotation.SalaryFormulaVar;
|
||
|
|
//import com.weaver.hrm.salary.entity.datacollection.po.AddUpSituationPO;
|
||
|
|
//import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
||
|
|
//import com.weaver.hrm.salary.entity.salaryacct.po.SalaryAcctResultValuePO;
|
||
|
|
//import com.weaver.hrm.salary.entity.salarysob.po.SalarySobAddUpRulePO;
|
||
|
|
//import com.weaver.hrm.salary.entity.salarysob.po.SalarySobTaxReportRulePO;
|
||
|
|
//import com.weaver.hrm.salary.entity.taxdeclaration.po.TaxDeclarationPO;
|
||
|
|
//import com.weaver.hrm.salary.entity.taxdeclaration.po.TaxDeclarationValuePO;
|
||
|
|
//import com.weaver.hrm.salary.entity.taxdeclaration.po.TaxReportColumnPO;
|
||
|
|
//import com.weaver.hrm.salary.enums.salaryitem.SalaryDataTypeEnum;
|
||
|
|
//import com.weaver.hrm.salary.enums.salarysob.IncomeCategoryEnum;
|
||
|
|
//import com.weaver.hrm.salary.enums.sicategory.DeleteTypeEnum;
|
||
|
|
//
|
||
|
|
//import java.lang.reflect.Field;
|
||
|
|
//import java.math.BigDecimal;
|
||
|
|
//import java.time.LocalDateTime;
|
||
|
|
//import java.time.YearMonth;
|
||
|
|
//import java.util.List;
|
||
|
|
//import java.util.Map;
|
||
|
|
//import java.util.Objects;
|
||
|
|
//
|
||
|
|
///**
|
||
|
|
// * @description: 通用:一般劳务报酬所得、全年一次性奖金
|
||
|
|
// * @author: xiajun
|
||
|
|
// * @modified By: xiajun
|
||
|
|
// * @date: Created in 2022/12/2 3:16 PM
|
||
|
|
// * @version:v1.0
|
||
|
|
// */
|
||
|
|
//public class TaxDeclarationCommon implements TaxDeclarationStrategy {
|
||
|
|
//
|
||
|
|
// @Override
|
||
|
|
// public TaxDeclarationGenerateResult generate(TaxDeclareContext taxDeclareContext, Long employeeId, String tenantKey) {
|
||
|
|
// LocalDateTime now = LocalDateTime.now();
|
||
|
|
// // 薪资核算结果按照薪资核算人员id聚合分类
|
||
|
|
// Map<Long, SalaryAcctResultPO> salaryAcctResultValueMap = SalaryEntityUtil.convert2Map(
|
||
|
|
// 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());
|
||
|
|
// SalaryAcctResultValuePO salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId());
|
||
|
|
// String defaultValue = Objects.equals(taxReportColumn.getDataType(), SalaryDataTypeEnum.NUMBER.getValue()) ? "0" : "";
|
||
|
|
// String value = defaultValue;
|
||
|
|
// if (salarySobTaxReportRule != null && salaryAcctResultValue != null) {
|
||
|
|
// value = salaryAcctResultValue.getResultValue().getOrDefault(Util.null2String(salarySobTaxReportRule.getSalaryItemId()), defaultValue);
|
||
|
|
// }
|
||
|
|
// valueMap.put(taxReportColumn.getReportColumnDataIndex(), value);
|
||
|
|
// }
|
||
|
|
// TaxDeclarationValuePO taxDeclarationValue = new TaxDeclarationValuePO()
|
||
|
|
// .setId(IdGenerator.generate())
|
||
|
|
// .setTaxDeclareRecordId(taxDeclareContext.getTaxDeclaration().getTaxDeclareRecordId())
|
||
|
|
// .setTaxDeclarationId(taxDeclareContext.getTaxDeclaration().getId())
|
||
|
|
// .setEmployeeType(employeeIdEntry.getValue().get(0).getEmployeeType())
|
||
|
|
// .setEmployeeId(employeeIdEntry.getKey())
|
||
|
|
// .setResultValue(valueMap)
|
||
|
|
// .setTenantKey(tenantKey)
|
||
|
|
// .setCreator(employeeId)
|
||
|
|
// .setDeleteType(DeleteTypeEnum.NOT_DELETED.getValue())
|
||
|
|
// .setCreateTime(now)
|
||
|
|
// .setUpdateTime(now);
|
||
|
|
// taxDeclarationValues.add(taxDeclarationValue);
|
||
|
|
// }
|
||
|
|
// // 生成累计数据
|
||
|
|
// List<AddUpSituationPO> addUpSituations = generateAddUpSituation(taxDeclareContext, salaryAcctResultValueMap, employeeIdKeyMap);
|
||
|
|
// return new TaxDeclarationGenerateResult()
|
||
|
|
// .setTaxDeclarationValues(taxDeclarationValues)
|
||
|
|
// .setAddUpSituations(addUpSituations);
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// /**
|
||
|
|
// * 生成往期累计数据
|
||
|
|
// *
|
||
|
|
// * @param taxDeclareContext
|
||
|
|
// * @param salaryAcctResultValueMap
|
||
|
|
// * @param employeeIdKeyMap
|
||
|
|
// * @return
|
||
|
|
// */
|
||
|
|
// private List<AddUpSituationPO> generateAddUpSituation(TaxDeclareContext taxDeclareContext,
|
||
|
|
// Map<Long, SalaryAcctResultValuePO> salaryAcctResultValueMap,
|
||
|
|
// Map<Long, List<SalaryAcctEmployeePO>> employeeIdKeyMap) {
|
||
|
|
// List<AddUpSituationPO> 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;
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// SalaryAcctResultValuePO salaryAcctResultValue = salaryAcctResultValueMap.get(lastSalaryAcctEmployee.getId());
|
||
|
|
// Map<String, String> valueMap = Maps.newHashMap();
|
||
|
|
// for (Field declaredField : AddUpSituationPO.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.getResultValue()
|
||
|
|
// .getOrDefault(Util.null2String(salarySobAddUpRule.getSalaryItemId()), BigDecimal.ZERO.toPlainString());
|
||
|
|
// }
|
||
|
|
// valueMap.put(declaredField.getName(), value);
|
||
|
|
// }
|
||
|
|
// AddUpSituationPO addUpSituation = AddUpSituationPO.builder()
|
||
|
|
// .id(IdGenerator.generate())
|
||
|
|
// .employeeId(lastSalaryAcctEmployee.getEmployeeId())
|
||
|
|
// .employeeType(lastSalaryAcctEmployee.getEmployeeType())
|
||
|
|
// .taxAgentId(lastSalaryAcctEmployee.getTaxAgentId())
|
||
|
|
// .taxYearMonth(YearMonth.parse(taxDeclaration.getTaxCycle()).atDay(1))
|
||
|
|
// .year(YearMonth.parse(taxDeclaration.getTaxCycle()).getYear())
|
||
|
|
// .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"))
|
||
|
|
// .addUpAdvanceTax(valueMap.get("addUpAdvanceTax"))
|
||
|
|
// .addUpTaxableIncome(valueMap.get("addUpTaxableIncome"))
|
||
|
|
// .modifier(taxDeclaration.getCreator())
|
||
|
|
// .creator(taxDeclaration.getCreator())
|
||
|
|
// .createTime(taxDeclaration.getCreateTime())
|
||
|
|
// .updateTime(taxDeclaration.getUpdateTime())
|
||
|
|
// .tenantKey(taxDeclaration.getTenantKey())
|
||
|
|
// .deleteType(taxDeclaration.getDeleteType())
|
||
|
|
// .build();
|
||
|
|
// addUpSituations.add(addUpSituation);
|
||
|
|
// }
|
||
|
|
// return addUpSituations;
|
||
|
|
// }
|
||
|
|
//}
|