2022-03-01 18:49:22 +08:00
|
|
|
package com.engine.salary.service.impl;
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
import com.engine.common.util.ServiceUtil;
|
2022-03-01 18:49:22 +08:00
|
|
|
import com.engine.core.impl.Service;
|
2022-04-16 15:33:51 +08:00
|
|
|
import com.engine.salary.common.LocalDateRange;
|
2022-06-08 16:36:50 +08:00
|
|
|
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
2022-06-10 13:33:48 +08:00
|
|
|
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-02 18:02:27 +08:00
|
|
|
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
|
2022-06-10 13:33:48 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.bo.TaxDeclarationBO;
|
2022-04-16 15:33:51 +08:00
|
|
|
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationListQueryParam;
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.param.TaxDeclarationSaveParam;
|
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationPO;
|
2022-06-10 13:33:48 +08:00
|
|
|
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
|
2022-05-09 11:46:49 +08:00
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2022-06-10 13:33:48 +08:00
|
|
|
import com.engine.salary.mapper.datacollection.AddUpSituationMapper;
|
|
|
|
|
import com.engine.salary.mapper.salaryacct.SalaryAcctRecordMapper;
|
2022-04-16 15:33:51 +08:00
|
|
|
import com.engine.salary.mapper.taxdeclaration.TaxDeclarationMapper;
|
2022-06-10 13:33:48 +08:00
|
|
|
import com.engine.salary.service.*;
|
2022-04-16 15:33:51 +08:00
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
2022-05-09 11:46:49 +08:00
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2022-04-16 15:33:51 +08:00
|
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
2022-05-25 13:10:03 +08:00
|
|
|
import com.engine.salary.util.page.SalaryPageUtil;
|
2022-09-21 14:58:59 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-04-16 15:33:51 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2022-06-10 13:33:48 +08:00
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
2022-09-21 14:58:59 +08:00
|
|
|
import weaver.general.BaseBean;
|
2022-05-09 11:46:49 +08:00
|
|
|
import weaver.hrm.User;
|
2022-03-01 18:49:22 +08:00
|
|
|
|
2022-08-08 17:45:18 +08:00
|
|
|
import java.time.YearMonth;
|
2022-04-16 15:33:51 +08:00
|
|
|
import java.util.*;
|
2022-06-10 13:33:48 +08:00
|
|
|
import java.util.stream.Collectors;
|
2022-03-01 18:49:22 +08:00
|
|
|
|
2022-09-21 14:58:59 +08:00
|
|
|
@Slf4j
|
2022-03-01 18:49:22 +08:00
|
|
|
public class TaxDeclarationServiceImpl extends Service implements TaxDeclarationService {
|
|
|
|
|
|
2022-09-21 14:58:59 +08:00
|
|
|
private final Boolean isLog = "true".equals(new BaseBean().getPropValue("hrmSalary", "log"));
|
|
|
|
|
|
2022-04-16 15:33:51 +08:00
|
|
|
private TaxDeclarationMapper getTaxDeclarationMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(TaxDeclarationMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-10 13:33:48 +08:00
|
|
|
private SalaryAcctRecordMapper getSalaryAcctRecordMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(SalaryAcctRecordMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AddUpSituationMapper getAddUpSituationMapper() {
|
|
|
|
|
return MapperProxyFactory.getProxy(AddUpSituationMapper.class);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
private TaxDeclarationDetailService getTaxDeclarationDetailService(User user) {
|
2022-06-02 18:02:27 +08:00
|
|
|
return ServiceUtil.getService(TaxDeclarationDetailServiceImpl.class, user);
|
2022-05-09 11:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private AddUpSituationService getAddUpSituationService(User user) {
|
2022-06-02 18:02:27 +08:00
|
|
|
return ServiceUtil.getService(AddUpSituationServiceImpl.class, user);
|
2022-05-09 11:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 18:02:27 +08:00
|
|
|
private TaxAgentService getTaxAgentService(User user) {
|
|
|
|
|
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
|
2022-03-01 18:49:22 +08:00
|
|
|
}
|
|
|
|
|
|
2022-06-10 13:33:48 +08:00
|
|
|
private SalarySobService getSalarySobService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryAcctResultService getSalaryAcctResultService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryAcctResultServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryItemService getSalaryItemService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
|
|
|
|
|
}
|
2022-06-02 18:02:27 +08:00
|
|
|
|
2022-08-08 17:45:18 +08:00
|
|
|
private SalaryAcctEmployeeService getSalaryAcctEmployeeService(User user) {
|
|
|
|
|
return ServiceUtil.getService(SalaryAcctEmployeeServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TaxDeclarationPO> listByTaxCycleAndTaxAgentIds(YearMonth taxCycle, Collection<Long> taxAgentIds) {
|
|
|
|
|
if (Objects.isNull(taxCycle) || CollectionUtils.isEmpty(taxAgentIds)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
|
|
|
|
|
}
|
|
|
|
|
TaxDeclarationPO po = TaxDeclarationPO.builder().taxCycle(SalaryDateUtil.toDate(taxCycle, 1)).taxAgentIds(taxAgentIds).build();
|
|
|
|
|
List<TaxDeclarationPO> taxDeclarationPOS = getTaxDeclarationMapper().listSome(po);
|
|
|
|
|
return taxDeclarationPOS;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 18:49:22 +08:00
|
|
|
@Override
|
2022-04-16 15:33:51 +08:00
|
|
|
public PageInfo<TaxDeclarationPO> listPageByParam(TaxDeclarationListQueryParam queryParam) {
|
2022-06-02 18:02:27 +08:00
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
|
2022-04-16 15:33:51 +08:00
|
|
|
// 分页参数
|
|
|
|
|
TaxDeclarationPO po = TaxDeclarationPO.builder().build();
|
|
|
|
|
LocalDateRange localDateRange = new LocalDateRange();
|
|
|
|
|
if (Objects.nonNull(queryParam.getFromSalaryMonth())) {
|
|
|
|
|
localDateRange.setFromDate(SalaryDateUtil.localDateToDate(queryParam.getFromSalaryMonth().atDay(1)));
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(queryParam.getEndSalaryMonth())) {
|
|
|
|
|
localDateRange.setEndDate(SalaryDateUtil.localDateToDate(queryParam.getEndSalaryMonth().atEndOfMonth()));
|
|
|
|
|
}
|
|
|
|
|
po.setSalaryMonths(localDateRange);
|
2022-06-02 18:02:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// 分权
|
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
|
|
|
|
|
if (openDevolution) {
|
|
|
|
|
// 查询负责管理的个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAllTaxAgents(currentEmployeeId);
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentPOS)) {
|
|
|
|
|
return new PageInfo<>(new ArrayList<>());
|
|
|
|
|
}
|
|
|
|
|
Set<Long> taxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId);
|
|
|
|
|
po.setTaxAgentIds(taxAgentIds);
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 15:33:51 +08:00
|
|
|
// 查询个税申报表
|
|
|
|
|
List<TaxDeclarationPO> taxDeclarationPOS = getTaxDeclarationMapper().listSome(po);
|
2022-12-12 10:25:55 +08:00
|
|
|
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
|
|
|
|
|
taxDeclarationPOS, TaxDeclarationPO.class);
|
2022-04-16 15:33:51 +08:00
|
|
|
|
|
|
|
|
}
|
2022-05-09 11:46:49 +08:00
|
|
|
|
2022-04-16 15:33:51 +08:00
|
|
|
//根据id查询taxAgents
|
|
|
|
|
@Override
|
2022-06-09 19:02:18 +08:00
|
|
|
public List<TaxAgentPO> countByTaxDeclarationId(Collection<Long> taxAgentIds) {
|
2022-04-16 15:33:51 +08:00
|
|
|
if (CollectionUtils.isEmpty(taxAgentIds)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
2022-06-09 19:02:18 +08:00
|
|
|
return getTaxAgentService(user).listByIds(taxAgentIds);
|
2022-04-16 15:33:51 +08:00
|
|
|
}
|
2022-05-09 11:46:49 +08:00
|
|
|
|
2022-04-16 15:33:51 +08:00
|
|
|
//根据id获取TaxDeclaration
|
|
|
|
|
@Override
|
2022-06-10 13:33:48 +08:00
|
|
|
public TaxDeclarationPO getById(Long id) {
|
2022-04-16 15:33:51 +08:00
|
|
|
return getTaxDeclarationMapper().getById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void save(TaxDeclarationSaveParam saveParam) {
|
2022-06-10 13:33:48 +08:00
|
|
|
long currentEmployeeId = user.getUID();
|
|
|
|
|
|
|
|
|
|
// 个税扣缴义务人id
|
|
|
|
|
Set<Long> taxAgentIds;
|
2022-07-06 16:42:13 +08:00
|
|
|
|
|
|
|
|
Long taxAgentId = saveParam.getTaxAgentId();
|
2023-03-07 17:44:21 +08:00
|
|
|
|
|
|
|
|
if (taxAgentId == null) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "请选择要申报的扣缴义务人!"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-08 17:45:18 +08:00
|
|
|
if (taxAgentId != null) {
|
2022-07-06 16:42:13 +08:00
|
|
|
taxAgentIds = Collections.singleton(taxAgentId);
|
2022-08-08 17:45:18 +08:00
|
|
|
} else {
|
2023-03-07 17:44:21 +08:00
|
|
|
//管理的扣缴义务人一次性申报逻辑
|
2022-07-06 16:42:13 +08:00
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
|
if (BooleanUtils.isFalse(openDevolution)) {
|
|
|
|
|
taxAgentIds = SalaryEntityUtil.properties(getTaxAgentService(user).listAll(), TaxAgentPO::getId);
|
|
|
|
|
} else {
|
|
|
|
|
taxAgentIds = SalaryEntityUtil.properties(getTaxAgentService(user).listAllTaxAgentsAsAdmin(currentEmployeeId), TaxAgentPO::getId);
|
|
|
|
|
}
|
2022-06-10 13:33:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否具有权限
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentIds)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(0, "对不起,您不具备任何个税扣缴义务人的管理权限"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询个税扣缴义务人
|
|
|
|
|
List<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listByIds(taxAgentIds);
|
|
|
|
|
Map<Long, String> taxAgentNameMap = SalaryEntityUtil.convert2Map(taxAgentPOS, TaxAgentPO::getId, TaxAgentPO::getName);
|
|
|
|
|
|
|
|
|
|
// 薪资所属月的日期范围
|
|
|
|
|
LocalDateRange salaryMonthDateRange = SalaryDateUtil.localDate2Range(SalaryDateUtil.localDateToDate(saveParam.getSalaryMonth().atDay(1)));
|
|
|
|
|
if (Objects.isNull(salaryMonthDateRange)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "薪资所属月参数错误"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询薪资所属月个税扣缴义务人已经生成过的个税申报表
|
|
|
|
|
List<TaxDeclarationPO> taxDeclarationPOS = listBySalaryMonthTax(TaxDeclarationPO.builder().salaryMonths(salaryMonthDateRange).taxAgentIds(taxAgentNameMap.keySet()).build());
|
|
|
|
|
// 已经生成过个税申报表,不允许再次生成个税申报表
|
|
|
|
|
if (CollectionUtils.isNotEmpty(taxDeclarationPOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(107986, "{0}在{1}已经生成过个税申报表,不允许再次生成")
|
|
|
|
|
.replace("{0}", taxAgentNameMap.get(taxDeclarationPOS.get(0).getTaxAgentId()))
|
|
|
|
|
.replace("{1}", saveParam.getSalaryMonth().toString()));
|
|
|
|
|
}
|
|
|
|
|
// 查询薪资所属月的薪资核算记录
|
|
|
|
|
List<SalaryAcctRecordPO> salaryAcctRecordPOS = listBySalaryMonth(SalaryAcctRecordPO.builder().salaryMonths(salaryMonthDateRange).build());
|
|
|
|
|
// 无薪资核算记录,不允许生成个税申报表
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctRecordPOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98874, "{0}无申报数据").replace("{0}", saveParam.getSalaryMonth().toString()));
|
|
|
|
|
}
|
|
|
|
|
// 查询薪资核算结果
|
|
|
|
|
List<SalaryAcctResultPO> salaryAcctResultPOS = getSalaryAcctResultService(user)
|
|
|
|
|
.listBySalaryAcctRecordIdsAndTaxAgentIds(SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getId), taxAgentIds);
|
|
|
|
|
|
|
|
|
|
// 无薪资核算结果,不允许生成个税申报表
|
|
|
|
|
if (CollectionUtils.isEmpty(salaryAcctResultPOS)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(110093, "{0}无可申报数据")
|
|
|
|
|
.replace("{0}", saveParam.getSalaryMonth().toString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<Long> salaryAcctRecordIds = SalaryEntityUtil.properties(salaryAcctResultPOS, SalaryAcctResultPO::getSalaryAcctRecordId);
|
|
|
|
|
salaryAcctRecordPOS = salaryAcctRecordPOS.stream().filter(salaryAcctRecordPO -> salaryAcctRecordIds.contains(salaryAcctRecordPO.getId())).collect(Collectors.toList());
|
|
|
|
|
// 如果存在未归档的,也不允许生成个税申报表
|
2022-07-06 16:42:13 +08:00
|
|
|
boolean notArchived = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> Objects.equals(salaryAcctRecordPO.getStatus(), SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()));
|
2022-06-10 13:33:48 +08:00
|
|
|
if (notArchived) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98875, "{0}有未归档数据,请全部归档后再申报")
|
|
|
|
|
.replace("{0}", saveParam.getSalaryMonth().toString()));
|
|
|
|
|
}
|
|
|
|
|
// 如果当前薪资所属月下存在不同的税款所属期,属于异常业务场景,不允许生成个税申报表
|
|
|
|
|
Date taxCycle = salaryAcctRecordPOS.get(0).getTaxCycle();
|
|
|
|
|
boolean differentTaxCycle = salaryAcctRecordPOS.stream().anyMatch(salaryAcctRecordPO -> salaryAcctRecordPO.getTaxCycle().compareTo(taxCycle) != 0);
|
|
|
|
|
if (differentTaxCycle) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98876, "{0}存在不同的税款所属期,无法正常生成个税申报表,请调整账套设置,重新核算后再生成个税申报表")
|
|
|
|
|
.replace("{0}", saveParam.getSalaryMonth().toString()));
|
|
|
|
|
}
|
|
|
|
|
// 查询薪资账套
|
|
|
|
|
Set<Long> salarySobIds = SalaryEntityUtil.properties(salaryAcctRecordPOS, SalaryAcctRecordPO::getSalarySobId);
|
|
|
|
|
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByIds(salarySobIds);
|
|
|
|
|
|
|
|
|
|
// 查询所有薪资项目
|
|
|
|
|
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listAll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理要保存的数据
|
|
|
|
|
TaxDeclarationBO.Result result = TaxDeclarationBO.handle(saveParam, taxCycle, user, salaryItemPOS, salarySobPOS, salaryAcctResultPOS);
|
|
|
|
|
// 保存个税申报表
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxDeclarations())) {
|
2022-09-21 14:58:59 +08:00
|
|
|
if (isLog) {
|
|
|
|
|
log.info("salary TaxDeclaration step1 save {}", result.getNeedInsertTaxDeclarations().size());
|
|
|
|
|
}
|
2022-06-10 13:33:48 +08:00
|
|
|
getTaxDeclarationMapper().batchInsert(result.getNeedInsertTaxDeclarations());
|
|
|
|
|
}
|
|
|
|
|
// 保存个税申报表明细
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertTaxDeclarationDetails())) {
|
2022-09-21 14:58:59 +08:00
|
|
|
if (isLog) {
|
|
|
|
|
log.info("salary TaxDeclaration step2 detail save {}", result.getNeedInsertTaxDeclarationDetails().size());
|
|
|
|
|
}
|
2022-06-10 13:33:48 +08:00
|
|
|
getTaxDeclarationDetailService(user).batchSave(result.getNeedInsertTaxDeclarationDetails());
|
|
|
|
|
}
|
|
|
|
|
// 保存累计情况
|
|
|
|
|
if (CollectionUtils.isNotEmpty(result.getNeedInsertAddUpSituations())) {
|
2022-09-21 14:58:59 +08:00
|
|
|
if (isLog) {
|
|
|
|
|
log.info("salary TaxDeclaration step3 AddUpSituations save {}", result.getNeedInsertAddUpSituations().size());
|
|
|
|
|
}
|
2022-06-10 13:33:48 +08:00
|
|
|
getAddUpSituationService(user).deleteByTaxYearMonthAndTaxAgentIds(SalaryDateUtil.localDate2YearMonth(taxCycle), taxAgentIds);
|
2022-08-08 17:45:18 +08:00
|
|
|
getAddUpSituationService(user).batchSave((List) result.getNeedInsertAddUpSituations());
|
2022-06-10 13:33:48 +08:00
|
|
|
}
|
|
|
|
|
// 更新薪资核算记录的状态
|
2022-09-21 14:58:59 +08:00
|
|
|
if (isLog) {
|
|
|
|
|
log.info("salary TaxDeclaration step4 AcctRecordStatus save {}", salaryAcctRecordIds.size());
|
|
|
|
|
}
|
2022-06-10 13:33:48 +08:00
|
|
|
getSalaryAcctRecordService(user).updateStatusByIds(salaryAcctRecordIds, SalaryAcctRecordStatusEnum.DECLARED);
|
2022-03-01 18:49:22 +08:00
|
|
|
}
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
@Override
|
2022-08-08 17:45:18 +08:00
|
|
|
public void delete(SalaryAcctRecordPO salaryAcctRecordPO) {
|
|
|
|
|
SalarySobPO sobPO = getSalarySobService(user).getById(salaryAcctRecordPO.getSalarySobId());
|
|
|
|
|
if (sobPO == null || sobPO.getTaxAgentId() == null) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "账套信息异常"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
// 薪资所属月的日期范围
|
2022-08-08 17:45:18 +08:00
|
|
|
LocalDateRange taxCycleDateRange = SalaryDateUtil.localDate2Range(salaryAcctRecordPO.getTaxCycle());
|
|
|
|
|
if (Objects.isNull(taxCycleDateRange)) {
|
2022-05-09 11:46:49 +08:00
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(84026, "参数错误"));
|
|
|
|
|
}
|
2022-08-08 17:45:18 +08:00
|
|
|
List<TaxDeclarationPO> taxDeclarationPOS = listByTaxCycleAndTaxAgentIds(SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getTaxCycle()), Collections.singleton(sobPO.getTaxAgentId()));
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
Set<Long> taxDeclarationIds = SalaryEntityUtil.properties(taxDeclarationPOS, TaxDeclarationPO::getId);
|
2022-08-08 17:45:18 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(taxDeclarationIds)) {
|
|
|
|
|
// 删除个税申报表
|
|
|
|
|
getTaxDeclarationMapper().deleteByIds(taxDeclarationIds);
|
|
|
|
|
// 删除个税申报表详情
|
|
|
|
|
getTaxDeclarationDetailService(user).deleteByTaxDeclarationIds(taxDeclarationIds);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-09 11:46:49 +08:00
|
|
|
// 删除往期累计情况
|
2022-08-08 17:45:18 +08:00
|
|
|
getAddUpSituationService(user).deleteAddUpSituationList(salaryAcctRecordPO.getTaxCycle(), sobPO.getTaxAgentId());
|
2022-05-09 11:46:49 +08:00
|
|
|
}
|
|
|
|
|
|
2022-06-10 13:33:48 +08:00
|
|
|
|
|
|
|
|
public List<TaxDeclarationPO> listBySalaryMonthTax(TaxDeclarationPO build) {
|
|
|
|
|
return getTaxDeclarationMapper().listSome(build);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SalaryAcctRecordPO> listBySalaryMonth(SalaryAcctRecordPO po) {
|
|
|
|
|
return getSalaryAcctRecordMapper().listSome(po);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 10:59:12 +08:00
|
|
|
@Override
|
|
|
|
|
public boolean checkByAuthority(TaxDeclarationPO taxDeclarationPO, Long employeeId) {
|
|
|
|
|
// 判断是否开启了分权
|
|
|
|
|
Boolean openDevolution = getTaxAgentService(user).isOpenDevolution();
|
|
|
|
|
// 判断是否是总管理员
|
|
|
|
|
Boolean isChief = getTaxAgentService(user).isChief(employeeId);
|
|
|
|
|
if (openDevolution && !isChief) {
|
|
|
|
|
// 查询负责管理的个税扣缴义务人
|
|
|
|
|
Collection<TaxAgentPO> taxAgentPOS = getTaxAgentService(user).listAllTaxAgentsAsAdmin(employeeId);
|
|
|
|
|
if (CollectionUtils.isEmpty(taxAgentPOS)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
Set<Long> taxAgentIds = SalaryEntityUtil.properties(taxAgentPOS, TaxAgentPO::getId);
|
|
|
|
|
return taxAgentIds.contains(taxDeclarationPO.getTaxAgentId());
|
|
|
|
|
}
|
|
|
|
|
// 查询个税申报表
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 10:40:01 +08:00
|
|
|
@Override
|
|
|
|
|
public void withDrawTaxDeclaration(Long taxDeclarationId) {
|
|
|
|
|
TaxDeclarationPO po = getTaxDeclarationMapper().getById(taxDeclarationId);
|
|
|
|
|
if(Objects.isNull(po)){
|
|
|
|
|
throw new SalaryRunTimeException("个税申报表不存在");
|
|
|
|
|
}
|
|
|
|
|
// 获取当前个税扣缴义务人下的薪资账套
|
|
|
|
|
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByTaxAgentId(po.getTaxAgentId());
|
|
|
|
|
List<Long> salarySobIds = salarySobPOS.stream().map(SalarySobPO::getId).collect(Collectors.toList());
|
|
|
|
|
// 获取记录
|
|
|
|
|
LocalDateRange dateRange = new LocalDateRange(po.getSalaryMonth(), po.getSalaryMonth());
|
|
|
|
|
List<SalaryAcctRecordPO> salaryAcctRecords = getSalaryAcctRecordService(user).listBySalarySobIdsAndSalaryMonth(salarySobIds, dateRange);
|
|
|
|
|
List<Long> salaryAcctRecordIds = salaryAcctRecords.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList());
|
|
|
|
|
// 删除个税申报表
|
|
|
|
|
getTaxDeclarationMapper().deleteByIdZj(po.getId());
|
|
|
|
|
// 修改薪资核算记录状态为已归档
|
|
|
|
|
if(CollectionUtils.isNotEmpty(salaryAcctRecordIds)){
|
|
|
|
|
getSalaryAcctRecordService(user).updateStatusByIds(salaryAcctRecordIds,SalaryAcctRecordStatusEnum.ARCHIVED);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-01 18:49:22 +08:00
|
|
|
}
|