计算个税

This commit is contained in:
Anlin
2025-07-17 17:30:54 +08:00
parent ec49ca06fc
commit 9b4c2a808e
3 changed files with 64 additions and 18 deletions

View File

@ -1,10 +1,8 @@
package org.dromara.payment.bill.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.io.IoUtil;
@ -32,6 +30,7 @@ import org.dromara.payment.task.domain.vo.MerTaskEnrollVo;
import org.dromara.payment.task.domain.vo.MerTaskVo;
import org.dromara.payment.task.service.IMerTaskEnrollService;
import org.dromara.payment.task.service.IMerTaskService;
import org.dromara.payment.util.TaxCalculatorUtils;
import org.dromara.payment.worker.domain.UserWorkerAccount;
import org.dromara.payment.worker.domain.bo.UserWorkerAccountBo;
import org.dromara.payment.worker.domain.vo.UserWorkerVo;
@ -318,25 +317,71 @@ public class MerBillController extends BaseController {
this.merBillService.validateSysSyd(bo);
ExcelResult<MerBillDetailBo> result = ExcelUtil.importExcel(file.getInputStream(),new BillImportListener(bo));
List<MerBillDetailBo> list = result.getList();
for (MerBillDetailBo merBillDetailBo : list) {
for (MerBillDetailBo merBillDetailBo : result.getList()) {
UserWorkerVo userWorkerVo = userWorkerServiceImpl.queryByName(merBillDetailBo.getWorkerName());
UserWorkerAccountBo account = new UserWorkerAccountBo();
account.setWorkId(userWorkerVo.getId());
account.setBankCard(merBillDetailBo.getBankCard());
userWorkerAccountServiceImpl.updateByBo(account);
MerBillDetailBo billDetailBo = new MerBillDetailBo();
billDetailBo.setWorkerName(merBillDetailBo.getWorkerName());
billDetailBo.setCardId(merBillDetailBo.getCardId());
List<MerBillDetailVo> merBillDetailVos = billDetailService.queryList(billDetailBo);
BigDecimal totalRaise = BigDecimal.valueOf(merBillDetailVos.stream()
.filter(Objects::nonNull)
.mapToLong(MerBillDetailVo::getRaise)
.sum());
BigDecimal totalMoney = BigDecimal.valueOf(merBillDetailVos.stream()
.filter(Objects::nonNull)
.mapToLong(MerBillDetailVo::getMoney)
.sum());
BigDecimal accumulatedIncome = totalMoney.add(merBillDetailBo.getMoneyDecimal());
String billNo = merBillDetailBo.getBillNo();
String year = billNo.substring(0, 4);
String month = billNo.substring(4, 6);
List<MerBillDetailVo> uniqueMonthRecords = merBillDetailVos.stream()
.filter(record -> {
String batchNo = record.getBillNo();
int year1 = Integer.parseInt(batchNo.substring(7, 11));
return year1 == Integer.parseInt(year);
})
.collect(Collectors.toMap(
record -> record.getBillNo().substring(7, 13),
record -> record,
(existing, replacement) -> existing,
LinkedHashMap::new
))
.values()
.stream()
.collect(Collectors.toList());
boolean hasCurrentMonthRecord = uniqueMonthRecords.stream()
.anyMatch(record -> {
String batchNo = record.getBillNo();
String recordYearMonth = batchNo.substring(7, 13);
return recordYearMonth.equals(year + month);
});
int size = uniqueMonthRecords.size();
BigDecimal personalIncomeTax;
if (hasCurrentMonthRecord){
personalIncomeTax = TaxCalculatorUtils.calculateMonthlyWithholdingTax(accumulatedIncome, 0, totalRaise);
}else {
personalIncomeTax = TaxCalculatorUtils.calculateMonthlyWithholdingTax(accumulatedIncome,size+1,totalRaise);
}
Long amount = (merBillDetailBo.getMoneyDecimal().subtract(personalIncomeTax)).multiply(new BigDecimal("100")).longValue();
merBillDetailBo.setRaise(personalIncomeTax.multiply(new BigDecimal("100")).longValue());
merBillDetailBo.setAmount(amount);
}
return R.ok(result);
return R.ok(result);
}
/**

View File

@ -586,4 +586,5 @@ public class MerBillDetailVo implements Serializable {
@ExcelIgnore
private BigDecimal shServiceChargeRate;
}

View File

@ -32,7 +32,7 @@ public class TaxCalculatorUtils {
* 计算当月应预扣税额
*
* @param cumulativeIncome 累计收入税前
* @param taxMonth 当前月份1-12
* @param taxMonth 第几个月1-12
* @param cumulativePrepaidTax 累计已预缴税额
* @return 当月应预扣税额BigDecimal保留2位小数
*/
@ -44,8 +44,8 @@ public class TaxCalculatorUtils {
// 1. 参数校验
validateParams(cumulativeIncome, taxMonth, cumulativePrepaidTax);
// 2. 计算累计减除费用5000 * nn为
BigDecimal cumulativeDeduction = MONTHLY_DEDUCTION;
// 2. 计算累计减除费用5000 * nn为第几个
BigDecimal cumulativeDeduction = MONTHLY_DEDUCTION.multiply(new BigDecimal(taxMonth));
// 3. 计算应纳税所得额累计收入 × (1 - 20%) - 累计减除费用
BigDecimal taxableIncome = cumulativeIncome