计算个税
This commit is contained in:
@ -1,10 +1,8 @@
|
|||||||
package org.dromara.payment.bill.controller;
|
package org.dromara.payment.bill.controller;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.math.BigDecimal;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
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.domain.vo.MerTaskVo;
|
||||||
import org.dromara.payment.task.service.IMerTaskEnrollService;
|
import org.dromara.payment.task.service.IMerTaskEnrollService;
|
||||||
import org.dromara.payment.task.service.IMerTaskService;
|
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.UserWorkerAccount;
|
||||||
import org.dromara.payment.worker.domain.bo.UserWorkerAccountBo;
|
import org.dromara.payment.worker.domain.bo.UserWorkerAccountBo;
|
||||||
import org.dromara.payment.worker.domain.vo.UserWorkerVo;
|
import org.dromara.payment.worker.domain.vo.UserWorkerVo;
|
||||||
@ -318,25 +317,71 @@ public class MerBillController extends BaseController {
|
|||||||
this.merBillService.validateSysSyd(bo);
|
this.merBillService.validateSysSyd(bo);
|
||||||
ExcelResult<MerBillDetailBo> result = ExcelUtil.importExcel(file.getInputStream(),new BillImportListener(bo));
|
ExcelResult<MerBillDetailBo> result = ExcelUtil.importExcel(file.getInputStream(),new BillImportListener(bo));
|
||||||
|
|
||||||
List<MerBillDetailBo> list = result.getList();
|
for (MerBillDetailBo merBillDetailBo : result.getList()) {
|
||||||
for (MerBillDetailBo merBillDetailBo : list) {
|
|
||||||
|
|
||||||
UserWorkerVo userWorkerVo = userWorkerServiceImpl.queryByName(merBillDetailBo.getWorkerName());
|
UserWorkerVo userWorkerVo = userWorkerServiceImpl.queryByName(merBillDetailBo.getWorkerName());
|
||||||
|
|
||||||
UserWorkerAccountBo account = new UserWorkerAccountBo();
|
UserWorkerAccountBo account = new UserWorkerAccountBo();
|
||||||
account.setWorkId(userWorkerVo.getId());
|
account.setWorkId(userWorkerVo.getId());
|
||||||
account.setBankCard(merBillDetailBo.getBankCard());
|
account.setBankCard(merBillDetailBo.getBankCard());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
userWorkerAccountServiceImpl.updateByBo(account);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -586,4 +586,5 @@ public class MerBillDetailVo implements Serializable {
|
|||||||
|
|
||||||
@ExcelIgnore
|
@ExcelIgnore
|
||||||
private BigDecimal shServiceChargeRate;
|
private BigDecimal shServiceChargeRate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class TaxCalculatorUtils {
|
|||||||
* 计算当月应预扣税额
|
* 计算当月应预扣税额
|
||||||
*
|
*
|
||||||
* @param cumulativeIncome 累计收入(税前)
|
* @param cumulativeIncome 累计收入(税前)
|
||||||
* @param taxMonth 当前月份(1-12)
|
* @param taxMonth 第几个月(1-12)
|
||||||
* @param cumulativePrepaidTax 累计已预缴税额
|
* @param cumulativePrepaidTax 累计已预缴税额
|
||||||
* @return 当月应预扣税额(BigDecimal,保留2位小数)
|
* @return 当月应预扣税额(BigDecimal,保留2位小数)
|
||||||
*/
|
*/
|
||||||
@ -44,8 +44,8 @@ public class TaxCalculatorUtils {
|
|||||||
// 1. 参数校验
|
// 1. 参数校验
|
||||||
validateParams(cumulativeIncome, taxMonth, cumulativePrepaidTax);
|
validateParams(cumulativeIncome, taxMonth, cumulativePrepaidTax);
|
||||||
|
|
||||||
// 2. 计算累计减除费用:5000 * n(n为月份)
|
// 2. 计算累计减除费用:5000 * n(n为第几个月)
|
||||||
BigDecimal cumulativeDeduction = MONTHLY_DEDUCTION;
|
BigDecimal cumulativeDeduction = MONTHLY_DEDUCTION.multiply(new BigDecimal(taxMonth));
|
||||||
|
|
||||||
// 3. 计算应纳税所得额:累计收入 × (1 - 20%) - 累计减除费用
|
// 3. 计算应纳税所得额:累计收入 × (1 - 20%) - 累计减除费用
|
||||||
BigDecimal taxableIncome = cumulativeIncome
|
BigDecimal taxableIncome = cumulativeIncome
|
||||||
|
|||||||
Reference in New Issue
Block a user