From b1f41c066b0b7c38faffddbfe73b9be8d0bd508e Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期日, 08 十一月 2026 23:42:09 +0800
Subject: [PATCH] 修改了增值税城建税
---
ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java | 553 +++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 512 insertions(+), 41 deletions(-)
diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
index 1c94fde..6bf6c64 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
@@ -1,11 +1,29 @@
package com.ruoyi.project.service.impl;
-import java.util.List;
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.TemporalAdjusters;
+import java.util.*;
-import com.ruoyi.project.domain.ServiceFund;
-import com.ruoyi.project.domain.ServiceReimbursement;
-import com.ruoyi.project.domain.ServiceReimbursementdetail;
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.tax.PerformanceTaxtUtils;
+import com.ruoyi.common.tax.TaxtUtils;
+import com.ruoyi.common.tax.VatTaxUtils;
+import com.ruoyi.common.utils.bean.DtoConversionUtils;
+import com.ruoyi.project.domain.*;
+import com.ruoyi.project.domain.vo.*;
import com.ruoyi.project.mapper.ServiceFundMapper;
+import com.ruoyi.project.mapper.SpStatBonusMapper;
+import lombok.extern.flogger.Flogger;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -13,67 +31,187 @@
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.mapper.ServiceFunddetailMapper;
-import com.ruoyi.project.domain.ServiceFunddetail;
import com.ruoyi.project.service.IServiceFunddetailService;
+import org.springframework.transaction.annotation.Transactional;
/**
* 璐圭敤鐢宠鏄庣粏Service涓氬姟灞傚鐞�
- *
+ *
* @author ruoyi
* @date 2022-01-25
*/
+@Slf4j
@Service
-public class ServiceFunddetailServiceImpl extends ServiceImpl<ServiceFunddetailMapper, ServiceFunddetail> implements IServiceFunddetailService
-{
-
+public class ServiceFunddetailServiceImpl extends ServiceImpl<ServiceFunddetailMapper, ServiceFunddetail> implements IServiceFunddetailService {
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
ServiceFunddetailMapper serviceFunddetailMapper;
@Autowired
ServiceFundMapper serviceFundMapper;
+ @Autowired
+ SpStatBonusMapper spStatBonusMapper;
+
/**
* 鏌ヨ璐圭敤鐢宠鏄庣粏鍒楄〃
- *
+ *
* @param serviceFunddetail 璐圭敤鐢宠鏄庣粏
* @return 璐圭敤鐢宠鏄庣粏
*/
@Override
public List<ServiceFunddetail> queryList(ServiceFunddetail serviceFunddetail) {
LambdaQueryWrapper<ServiceFunddetail> wrappers = Wrappers.lambdaQuery();
- if (StringUtils.isNotBlank(serviceFunddetail.getBeneficiaryname())){
- wrappers.like(ServiceFunddetail::getBeneficiaryname ,serviceFunddetail.getBeneficiaryname());
+ if (StringUtils.isNotBlank(serviceFunddetail.getBeneficiaryname())) {
+ wrappers.like(ServiceFunddetail::getBeneficiaryname, serviceFunddetail.getBeneficiaryname());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getUnitname())){
- wrappers.like(ServiceFunddetail::getUnitname ,serviceFunddetail.getUnitname());
+ if (StringUtils.isNotBlank(serviceFunddetail.getUnitname())) {
+ wrappers.like(ServiceFunddetail::getUnitname, serviceFunddetail.getUnitname());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getApplytype())){
- wrappers.eq(ServiceFunddetail::getApplytype ,serviceFunddetail.getApplytype());
+ if (StringUtils.isNotBlank(serviceFunddetail.getApplytype())) {
+ wrappers.eq(ServiceFunddetail::getApplytype, serviceFunddetail.getApplytype());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getItemname())){
- wrappers.like(ServiceFunddetail::getItemname ,serviceFunddetail.getItemname());
+ if (StringUtils.isNotBlank(serviceFunddetail.getItemname())) {
+ wrappers.like(ServiceFunddetail::getItemname, serviceFunddetail.getItemname());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getItemtype())){
- wrappers.eq(ServiceFunddetail::getItemtype ,serviceFunddetail.getItemtype());
+ if (StringUtils.isNotBlank(serviceFunddetail.getItemtype())) {
+ wrappers.eq(ServiceFunddetail::getItemtype, serviceFunddetail.getItemtype());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getRecordstatus())){
- wrappers.eq(ServiceFunddetail::getRecordstatus ,serviceFunddetail.getRecordstatus());
+ if (StringUtils.isNotBlank(serviceFunddetail.getRecordstatus())) {
+ wrappers.eq(ServiceFunddetail::getRecordstatus, serviceFunddetail.getRecordstatus());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getCreateBy())){
- wrappers.eq(ServiceFunddetail::getCreateBy ,serviceFunddetail.getCreateBy());
+ if (StringUtils.isNotBlank(serviceFunddetail.getCreateBy())) {
+ wrappers.eq(ServiceFunddetail::getCreateBy, serviceFunddetail.getCreateBy());
}
- if (serviceFunddetail.getCreateTime() != null){
- wrappers.eq(ServiceFunddetail::getCreateTime ,serviceFunddetail.getCreateTime());
+ if (serviceFunddetail.getCreateTime() != null) {
+ wrappers.eq(ServiceFunddetail::getCreateTime, serviceFunddetail.getCreateTime());
}
- if (StringUtils.isNotBlank(serviceFunddetail.getUploadflag())){
- wrappers.eq(ServiceFunddetail::getUploadflag ,serviceFunddetail.getUploadflag());
+ if (StringUtils.isNotBlank(serviceFunddetail.getUploadflag())) {
+ wrappers.eq(ServiceFunddetail::getUploadflag, serviceFunddetail.getUploadflag());
}
- if (serviceFunddetail.getUploadtime() != null){
- wrappers.eq(ServiceFunddetail::getUploadtime ,serviceFunddetail.getUploadtime());
+ if (serviceFunddetail.getUploadtime() != null) {
+ wrappers.eq(ServiceFunddetail::getUploadtime, serviceFunddetail.getUploadtime());
+ }
+ if (serviceFunddetail.getJxrq() != null) {
+ wrappers.like(ServiceFunddetail::getJxrq, serviceFunddetail.getJxrq());
+ }
+ if (StringUtils.isNotBlank(serviceFunddetail.getIdcardno())) {
+ wrappers.eq(ServiceFunddetail::getIdcardno, serviceFunddetail.getIdcardno());
+ }
+ if (StringUtils.isNotBlank(serviceFunddetail.getApplytype())) {
+ wrappers.eq(ServiceFunddetail::getApplytype, serviceFunddetail.getApplytype());
+ }
+ if (serviceFunddetail.getDel_flag() != null) {
+ wrappers.eq(ServiceFunddetail::getDel_flag, serviceFunddetail.getDel_flag());
+ }
+ if (serviceFunddetail.getDeptId() != null) {
+ wrappers.eq(ServiceFunddetail::getDeptId, serviceFunddetail.getDeptId());
+ }
+ if (serviceFunddetail.getDeptName() != null) {
+ wrappers.eq(ServiceFunddetail::getDeptName, serviceFunddetail.getDeptName());
}
return this.list(wrappers);
}
+
+ @Override
+ public List<ServiceFunddetail> getDataBybeneficiaryNo(FunddetailReqVo funddetailReqVo) {
+ if (StringUtils.isEmpty(funddetailReqVo.getStarttime())) {
+ // 鑾峰彇褰撴湀绗竴澶╂棩鏈�
+ funddetailReqVo.setStarttime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString());
+ }
+ if (StringUtils.isEmpty(funddetailReqVo.getEndtime())) {
+ // 鑾峰彇褰撴湀鏈�鍚庝竴澶╂棩鏈�
+ funddetailReqVo.setEndtime(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).toString());
+ }
+ List<ServiceFunddetail> dataBybeneficiaryNo = serviceFunddetailMapper.getDataBybeneficiaryNo(funddetailReqVo);
+
+ return dataBybeneficiaryNo;
+ }
+
+ /**
+ * 鏍规嵁鍙楃泭浜鸿韩浠借瘉缂栧彿鑾峰彇绋庤垂閲戦
+ *
+ * @param taxMoneyVo
+ * @return
+ */
+ @Override
+ public Double getTaxByBeneFiciaryNo(TaxMoneyVO taxMoneyVo) {
+ // 閲戦绱姞蹇呴』鐢� BigDecimal锛歞ouble 绱姞浼氬紩鍏ユ诞鐐瑰熬宸紝瀵艰嚧绠楀嚭鐨勪釜绋庡嚭鐜板垎浠ヤ笅璇樊
+ BigDecimal sum = BigDecimal.ZERO;
+ BigDecimal totalScore = BigDecimal.ZERO;
+ List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
+ if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
+ //璁$畻鐢宠閲戦鎬诲拰锛屼笉鍖呮嫭褰撳墠浼犺繘鏉ョ殑
+ sum = taxationByBeneFiciaryNo.stream()
+ .map(ServiceFunddetail::getAmount)
+ .filter(java.util.Objects::nonNull)
+ .map(BigDecimal::valueOf)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ //涓嶅姞鏈钖叕鐨勪釜绋�
+ totalScore = taxationByBeneFiciaryNo.stream()
+ .map(ServiceFunddetail::getTaxamount)
+ .filter(java.util.Objects::nonNull)
+ .map(BigDecimal::valueOf)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+
+ sum = sum.add(new BigDecimal(taxMoneyVo.getMoney()));
+ //鍔犱笂鏈钖叕鐨勬�讳釜绋�
+ String taxation = TaxtUtils.getTaxation(sum);
+
+ Double tax = new BigDecimal(taxation).subtract(totalScore).doubleValue();
+ return tax;
+ }
+
+ /**
+ * 鏍规嵁绋庡悗宸ヨ祫锛岀畻鍑虹◣鍓嶅伐璧�
+ *
+ * @param taxMoneyVo
+ * @return
+ */
+ @Override
+ public TaxedMoneyVO getTaxBeforeByAfterMoney(TaxMoneyVO taxMoneyVo) {
+ TaxedMoneyVO taxedMoneyVO = new TaxedMoneyVO();
+ // 閲戦绱姞蹇呴』鐢� BigDecimal锛岄伩鍏嶆诞鐐瑰熬宸奖鍝嶇◣鍓�/绋庨缁撴灉
+ BigDecimal sum = BigDecimal.ZERO;
+ BigDecimal totalScore = BigDecimal.ZERO;
+ List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
+ if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
+ //璁$畻鍑虹◣鍚庢�婚噾棰濓紙涓嶅寘鍚湰娆★級
+ sum = taxationByBeneFiciaryNo.stream()
+ .map(ServiceFunddetail::getTaxedamount)
+ .filter(java.util.Objects::nonNull)
+ .map(BigDecimal::valueOf)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ //姹傚嚭涔嬪墠鐨勬�荤殑涓◣
+ totalScore = taxationByBeneFiciaryNo.stream()
+ .map(ServiceFunddetail::getTaxamount)
+ .filter(java.util.Objects::nonNull)
+ .map(BigDecimal::valueOf)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+ //璁$畻鍑烘�荤殑绋庡悗钖叕锛堝寘鍚湰娆★級
+ sum = sum.add(new BigDecimal(taxMoneyVo.getMoney()));
+ //绋庡墠鎬婚噾棰�
+ String taxationBefore = TaxtUtils.getTaxationBefore(sum);
+ //鎬讳釜绋�
+ BigDecimal tax = new BigDecimal(taxationBefore).subtract(sum);
+
+ //鏈鐨勭◣鍓嶉噾棰�
+ String nowTaxMoney = TaxtUtils.getTaxationBefore(new BigDecimal(taxMoneyVo.getMoney()));
+ //鏈鐨勭◣璐�
+ BigDecimal subtract = new BigDecimal(nowTaxMoney).subtract(new BigDecimal(taxMoneyVo.getMoney()));
+
+ taxedMoneyVO.setAllTax(tax.toString());
+ taxedMoneyVO.setAllTaxbeforeMoney(taxationBefore);
+ taxedMoneyVO.setAllAaxAfterMoney(sum.toString());
+ taxedMoneyVO.setNowTaxBeforeMoney(nowTaxMoney);
+ taxedMoneyVO.setNowTax(subtract.toString());
+
+ return taxedMoneyVO;
+ }
+
@Override
public List<ServiceFunddetail> getAllDetailsByFDIDLW(Long id) {
@@ -115,20 +253,353 @@
ServiceFunddetail serviceFunddetail = serviceFunddetailMapper.selectById(id);
Long fundid = serviceFunddetail.getFundid();
ServiceFund serviceFund = serviceFundMapper.selectById(fundid);
+ if (ObjectUtils.isNotEmpty(serviceFund)) {
+ // 閲戦涓�寰嬬敤 BigDecimal 绱姞/鎵e噺锛岄伩鍏嶆诞鐐瑰熬宸�
+ BigDecimal pretax = toMoney(serviceFund.getPretaxcost()).subtract(toMoney(serviceFunddetail.getAmount()));
+ BigDecimal aftertax = toMoney(serviceFund.getTaxedcost()).subtract(toMoney(serviceFunddetail.getTaxedamount()));
+ BigDecimal vat = toMoney(serviceFund.getVatCost()).subtract(toMoney(serviceFunddetail.getVatAmount()));
+ BigDecimal cityTax = toMoney(serviceFund.getCityTaxCost()).subtract(toMoney(serviceFunddetail.getCityTaxAmount()));
+ BigDecimal laborPretax = toMoney(serviceFund.getLaborPretaxCost()).subtract(toMoney(serviceFunddetail.getLaborPretaxAmount()));
+ BigDecimal tax = toMoney(serviceFund.getTaxcost()).subtract(toMoney(serviceFunddetail.getTaxamount()));
+ BigDecimal amount = pretax.add(aftertax);
- Double pretax = serviceFund.getPretaxcost();
- Double aftertax = serviceFund.getTaxedcost();
- pretax = pretax - serviceFunddetail.getAmount();
- aftertax = aftertax - serviceFunddetail.getTaxedamount();
- Double amount = pretax + aftertax;
-
- serviceFund.setPretaxcost(pretax);
- serviceFund.setTaxedcost(aftertax);
- serviceFund.setAmountrequested(amount);
- int updateAmount = serviceFundMapper.updateById(serviceFund);
-
+ serviceFund.setPretaxcost(pretax.doubleValue());
+ serviceFund.setTaxedcost(aftertax.doubleValue());
+ serviceFund.setVatCost(vat.doubleValue());
+ serviceFund.setCityTaxCost(cityTax.doubleValue());
+ serviceFund.setLaborPretaxCost(laborPretax.doubleValue());
+ serviceFund.setTaxcost(tax.doubleValue());
+ serviceFund.setAmountrequested(amount.doubleValue());
+ int updateAmount = serviceFundMapper.updateById(serviceFund);
+ }
return serviceFunddetailMapper.deleteById(id);
}
+ @Override
+ public List<ServiceFunddetailVO> getFundDetail(Long id) {
+ List<ServiceFunddetail> serviceFunddetails = serviceFunddetailMapper.selectFundDetailListById(id);
+ List<ServiceFunddetailVO> serviceFunddetailVOS = DtoConversionUtils.sourceToTarget(serviceFunddetails, ServiceFunddetailVO.class);
+ for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetailVOS) {
+ if (!StringUtils.isEmpty(serviceFunddetailVO.getAnnexfiles())) {
+ List<RbDetailFile> rbDetailFiles = JSONArray.parseArray(serviceFunddetailVO.getAnnexfiles(), RbDetailFile.class);
+ serviceFunddetailVO.setAnnexfilesList(rbDetailFiles);
+ }
+ if (!StringUtils.isEmpty(serviceFunddetailVO.getInvoicefiles())) {
+ List<RbDetailFile> rbDetailFiles = JSONArray.parseArray(serviceFunddetailVO.getInvoicefiles(), RbDetailFile.class);
+ serviceFunddetailVO.setInvoicefilesList(rbDetailFiles);
+ }
+ }
+ return serviceFunddetailVOS;
+ }
+ /**
+ * 鎵归噺绠楃◣涓绘柟娉曪紙鍔冲姟涓◣ + 澧炲�肩◣ + 鍩庡缓绋庯紝v2 鍙e緞锛�
+ * <p>
+ * 閲戦妯″瀷锛�
+ * <pre>
+ * 绋庡墠褰曞叆锛歏 = ceil(P 脳 1%)銆丆 = ceil(V 脳 3.5%)銆丩 = P - V - C銆�
+ * T = 鍔冲姟涓◣(褰撴湀绱 L) - 鍘熺疮璁� T銆丯 = L - T
+ * 绋庡悗褰曞叆锛歂绱 = 鍘熺疮璁� N + N銆丩绱 = getTaxationBefore(N绱)銆�
+ * L = L绱 - 鍘熺疮璁� L銆乀 = L - N銆丳/V/C = solveGross(L)
+ * 鏃犺韩浠借瘉锛歏 = C = T = 0锛孡 = N = P
+ * </pre>
+ *
+ * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃
+ * @param tempTaxSumMap 鏈湀绱閲戦缂撳瓨锛堟寜韬唤璇佸彿锛�
+ * @return 鏄惁绠楃◣鎴愬姛
+ */
+ @Override
+ public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails, Map<String, TaxMoneySumEO> tempTaxSumMap) {
+ return calculateTax(serviceFunddetails, tempTaxSumMap, new Date());
+ }
+
+ /**
+ * 鎵归噺绠楃◣锛堟寚瀹氭湰鎵圭畻绋庢椂闂达紝淇濊瘉鍚屾壒鏄庣粏 tax_time 涓�鑷达級
+ *
+ * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃
+ * @param tempTaxSumMap 鏈湀绱閲戦缂撳瓨锛堟寜韬唤璇佸彿锛�
+ * @param taxTime 鏈绠楃◣鏃堕棿
+ * @return 鏄惁绠楃◣鎴愬姛
+ */
+ @Override
+ public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails, Map<String, TaxMoneySumEO> tempTaxSumMap, Date taxTime) {
+ // 1. 鏍¢獙鍙傛暟
+ if (CollectionUtils.isEmpty(serviceFunddetails)) {
+ throw new BaseException("绠楃◣鏉′欢涓虹┖锛岃妫�鏌ュ悗锛屽啀杩涜璁$畻");
+ }
+ // 2. 鎺掑簭锛氱◣鏃堕棿涓虹┖鐨勬帓鍚庨潰锛屽啀鎸� id 淇濊瘉鍚屾壒椤哄簭绋冲畾
+ serviceFunddetails.sort(Comparator
+ .comparing((ServiceFunddetail obj) -> ObjectUtils.isEmpty(obj.getTaxTime()) ? 1 : 0)
+ .thenComparing(obj -> obj.getId() == null ? Long.MAX_VALUE : obj.getId()));
+
+ // 3. 鑾峰彇鏈壒娆� fundid 鍙婁富琛ㄤ俊鎭�
+ Long fundid = serviceFunddetails.get(0).getFundid();
+ log.info("绠楃◣鐨刦undid鐨勫�间负锛歿}", fundid);
+ ServiceFund serviceFund1 = serviceFundMapper.selectById(fundid);
+ if (serviceFund1 == null) {
+ throw new BaseException("鏈壘鍒拌垂鐢ㄧ敵璇峰崟锛孖D=" + fundid);
+ }
+ // 鏄庣粏 tax_time 缁熶竴浣跨敤鏈绠楃◣鏃堕棿
+ if (taxTime == null) {
+ taxTime = new Date();
+ }
+
+ // 4. 鏈壒娆″悎璁★紙鍏ㄩ儴鐢� BigDecimal锛岀姝� double 绱姞锛�
+ BigDecimal pretaxTotal = BigDecimal.ZERO;
+ BigDecimal vatTotal = BigDecimal.ZERO;
+ BigDecimal cityTaxTotal = BigDecimal.ZERO;
+ BigDecimal laborPretaxTotal = BigDecimal.ZERO;
+ BigDecimal taxTotal = BigDecimal.ZERO;
+ BigDecimal taxedTotal = BigDecimal.ZERO;
+
+ List<ServiceFunddetail> updateList = new ArrayList<>();
+
+ // 5. 閬嶅巻姣忔潯鏄庣粏
+ for (ServiceFunddetail detail : serviceFunddetails) {
+ if (detail.getAmount() == null) {
+ detail.setAmount(0.0);
+ }
+ if (detail.getTaxedamount() == null) {
+ detail.setTaxedamount(0.0);
+ }
+ // 鏈嶅姟璇存槑涓虹┖鎸夆�滈潪绋庡悗鈥濆鐞�
+ String scopeName = detail.getServicesscopename() == null ? "" : detail.getServicesscopename().trim();
+ boolean afterTax = scopeName.contains("绋庡悗");
+
+ // 5.1 韬唤璇佸彿涓虹┖锛氫笉鎵e鍊肩◣/鍩庡缓绋�/鍔冲姟涓◣
+ if (StringUtils.isEmpty(detail.getIdcardno())) {
+ BigDecimal p = afterTax ? toMoney(detail.getTaxedamount()) : toMoney(detail.getAmount());
+ detail.setAmount(p.doubleValue());
+ detail.setVatAmount(0.0);
+ detail.setCityTaxAmount(0.0);
+ detail.setLaborPretaxAmount(p.doubleValue());
+ detail.setTaxamount(0.0);
+ detail.setTaxedamount(p.doubleValue());
+ detail.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+ detail.setTaxTime(taxTime);
+ updateList.add(detail);
+
+ pretaxTotal = pretaxTotal.add(p);
+ laborPretaxTotal = laborPretaxTotal.add(p);
+ taxedTotal = taxedTotal.add(p);
+ continue;
+ }
+
+ // 5.2 韬唤璇佸彿涓嶄负绌猴細鏈湀绱 + 鍒嗘。绠楃◣
+ String idcard = detail.getIdcardno().trim();
+
+ // 5.2.1 鍙栨湰鏈堢疮璁★紙缂撳瓨閬垮厤閲嶅鏌ュ簱锛�
+ TaxMoneySumEO taxSum = tempTaxSumMap.get(idcard);
+ if (taxSum == null) {
+ taxSum = new TaxMoneySumEO();
+ taxSum.setXh(0L);
+ tempTaxSumMap.put(idcard, taxSum);
+ }
+ long xh = (taxSum.getXh() == null ? 0L : taxSum.getXh()) + 1;
+ taxSum.setXh(xh);
+ detail.setXh(xh);
+ // 绱绋庡墠閲戦锛堜笉鍚湰绗旓級锛岀敤浜庨〉闈㈠睍绀�
+ detail.setAllAmount(taxSum.getAmounts());
+
+ BigDecimal prevAmount = toMoney(taxSum.getAmounts());
+ BigDecimal prevLaborPretax = toMoney(taxSum.getLaborPretaxAmounts());
+ BigDecimal prevTax = toMoney(taxSum.getTaxAmounts());
+ BigDecimal prevTaxed = toMoney(taxSum.getTaxedAmounts());
+ BigDecimal prevVat = toMoney(taxSum.getVatAmounts());
+ BigDecimal prevCityTax = toMoney(taxSum.getCityTaxAmounts());
+
+ BigDecimal pretax;
+ BigDecimal vat;
+ BigDecimal cityTax;
+ BigDecimal laborPretax;
+ BigDecimal taxAmount;
+ BigDecimal taxedAmount;
+
+ if (afterTax) {
+ // 5.2.2 绋庡悗褰曞叆锛氬厛鍙嶇畻鍔冲姟绋庡墠锛屽啀寰幆鍙嶈В绋庡墠/澧炲�肩◣/鍩庡缓绋�
+ taxedAmount = toMoney(detail.getTaxedamount());
+ BigDecimal sumTaxed = prevTaxed.add(taxedAmount);
+ BigDecimal sumLaborPretax = new BigDecimal(TaxtUtils.getTaxationBefore(sumTaxed));
+ laborPretax = VatTaxUtils.roundMoney(sumLaborPretax.subtract(prevLaborPretax));
+ if (laborPretax.signum() < 0) {
+ // 閫愮瑪鍚戜笂鍙栨暣鍙兘甯︽潵鍑犲垎閽辩殑鍙嶇畻璇樊锛屽宸唴鎸� 0 澶勭悊锛涜秴鍑哄宸鏄庢暟鎹紓甯�
+ if (laborPretax.abs().compareTo(new BigDecimal("0.05")) <= 0) {
+ log.warn("绋庡悗閲戦鍙嶇畻鍔冲姟绋庡墠鍑虹幇璐熷熬宸紝宸叉寜 0 澶勭悊銆備汉鍛橈細{}锛屽弽绠楀姵鍔$◣鍓�={}锛屽師绱鍔冲姟绋庡墠={}",
+ safeName(detail), sumLaborPretax, prevLaborPretax);
+ laborPretax = BigDecimal.ZERO;
+ } else {
+ throw new BaseException("绋庡悗閲戦鍙嶇畻鍔冲姟绋庡墠澶辫触锛屼汉鍛橈細" + safeName(detail));
+ }
+ }
+ taxAmount = VatTaxUtils.roundMoney(laborPretax.subtract(taxedAmount));
+ if (taxAmount.signum() < 0) {
+ taxAmount = BigDecimal.ZERO;
+ }
+ VatTaxUtils.GrossAmount gross = VatTaxUtils.solveGross(laborPretax);
+ pretax = gross.getPretax();
+ vat = gross.getVat();
+ cityTax = gross.getCityTax();
+ } else {
+ // 5.2.3 绋庡墠褰曞叆锛氬厛绠楀鍊肩◣/鍩庡缓绋�/鍔冲姟绋庡墠锛屽啀鎸夌疮璁″姵鍔$◣鍓嶇畻鍔冲姟涓◣
+ pretax = toMoney(detail.getAmount());
+ vat = VatTaxUtils.calcVat(pretax);
+ cityTax = VatTaxUtils.calcCityTax(vat);
+ laborPretax = VatTaxUtils.roundMoney(pretax.subtract(vat).subtract(cityTax));
+ BigDecimal sumLaborPretax = prevLaborPretax.add(laborPretax);
+ BigDecimal sumTax = new BigDecimal(TaxtUtils.getTaxation(sumLaborPretax));
+ taxAmount = VatTaxUtils.roundMoney(sumTax.subtract(prevTax));
+ if (taxAmount.signum() < 0) {
+ taxAmount = BigDecimal.ZERO;
+ }
+ taxedAmount = VatTaxUtils.roundMoney(laborPretax.subtract(taxAmount));
+ }
+
+ detail.setAmount(pretax.doubleValue());
+ detail.setVatAmount(vat.doubleValue());
+ detail.setCityTaxAmount(cityTax.doubleValue());
+ detail.setLaborPretaxAmount(laborPretax.doubleValue());
+ detail.setTaxamount(taxAmount.doubleValue());
+ detail.setTaxedamount(taxedAmount.doubleValue());
+ detail.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+ detail.setTaxTime(taxTime);
+ updateList.add(detail);
+
+ // 5.2.4 鏇存柊鏈湀绱
+ taxSum.setAmounts(prevAmount.add(pretax).doubleValue());
+ taxSum.setVatAmounts(prevVat.add(vat).doubleValue());
+ taxSum.setCityTaxAmounts(prevCityTax.add(cityTax).doubleValue());
+ taxSum.setLaborPretaxAmounts(prevLaborPretax.add(laborPretax).doubleValue());
+ taxSum.setTaxAmounts(prevTax.add(taxAmount).doubleValue());
+ taxSum.setTaxedAmounts(prevTaxed.add(taxedAmount).doubleValue());
+
+ pretaxTotal = pretaxTotal.add(pretax);
+ vatTotal = vatTotal.add(vat);
+ cityTaxTotal = cityTaxTotal.add(cityTax);
+ laborPretaxTotal = laborPretaxTotal.add(laborPretax);
+ taxTotal = taxTotal.add(taxAmount);
+ taxedTotal = taxedTotal.add(taxedAmount);
+ }
+
+ // 6. 鎵归噺鏇存柊鎵�鏈夋槑缁�
+ for (ServiceFunddetail d : updateList) {
+ this.updateById(d);
+ }
+
+ // 7. 鏇存柊涓昏〃 service_fund 鐨� 6 涓噾棰濄�佺畻绋庢椂闂淬�佺姸鎬併�佺増鏈�
+ ServiceFund serviceFund = new ServiceFund();
+ serviceFund.setId(fundid);
+ serviceFund.setPretaxcost(pretaxTotal.doubleValue());
+ serviceFund.setVatCost(vatTotal.doubleValue());
+ serviceFund.setCityTaxCost(cityTaxTotal.doubleValue());
+ serviceFund.setLaborPretaxCost(laborPretaxTotal.doubleValue());
+ serviceFund.setTaxcost(taxTotal.doubleValue());
+ serviceFund.setTaxedcost(taxedTotal.doubleValue());
+ serviceFund.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+ serviceFund.setFundtaxtime(taxTime);
+ serviceFund.setIstax(1);
+ serviceFundMapper.updateById(serviceFund);
+ return true;
+ }
+
+ /**
+ * null 瀹夊叏鐨勯噾棰濊浆鎹�
+ */
+ private static BigDecimal toMoney(Double value) {
+ return value == null ? BigDecimal.ZERO : BigDecimal.valueOf(value);
+ }
+
+ /**
+ * 鎶ラ敊鏃惰兘瀹氫綅鍒板叿浣撲汉鍛�
+ */
+ private static String safeName(ServiceFunddetail detail) {
+ String name = detail.getBeneficiaryname() == null ? "" : detail.getBeneficiaryname();
+ String idcard = detail.getIdcardno() == null ? "" : detail.getIdcardno();
+ return name + "(" + idcard + ")";
+ }
+
+// @Override
+// public Boolean calculateTax2(List<ServiceFunddetail> serviceFunddetails) {
+// //鐢ㄤ簬缂撳瓨姣忎釜韬唤璇佸彿锛坕dcardno锛夋湰鏈堢疮璁$殑绋庡墠銆佺◣閲戙�佺◣鍚庨噾棰濓紙TaxMoneySumEO瀵硅薄锛�
+// Map<String, TaxMoneySumEO> tempTaxSumMap = new HashMap<>();
+//
+// TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO();
+// Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
+// taxMoneyVO.setFirstDay(firstDay);
+// taxMoneyVO.setTaxTime(new Date());
+//
+// List<TaxMoneySumEO> taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO);
+// for (TaxMoneySumEO taxMoneySumEO : taxSum) {
+// tempTaxSumMap.put(taxMoneySumEO.getIDCardNo(), taxMoneySumEO);
+// }
+//
+// return calculateTax(serviceFunddetails, tempTaxSumMap);
+// }
+
+
+ @Override
+ public Map<String, Double> performance(ServiceFunddetail serviceFunddetail) {
+ //鏍规嵁"韬唤璇佸彿"鍜�"缁╂晥鏃ユ湡(骞翠唤)"鏌ヨ涓汉鍘嗗彶缁╂晥
+ ServiceFunddetail serviceFunddetailEo = new ServiceFunddetail();
+ serviceFunddetailEo.setIdcardno(serviceFunddetail.getIdcardno());
+ serviceFunddetailEo.setApplytype("5");
+ Calendar cal = Calendar.getInstance();
+ //榛樿鏈勾搴�
+ serviceFunddetailEo.setJxrq(String.valueOf(cal.get(Calendar.YEAR)));
+ List<ServiceFunddetail> serviceFunddetails = queryList(serviceFunddetailEo);
+
+ //缁熻鍘嗗彶鐨勭◣
+ BigDecimal historyTax = BigDecimal.valueOf(0.00);
+ //璁$畻鎵e幓姣忔湀5000鐨勫巻鍙茬◣鍓嶉噾棰�
+ BigDecimal historyTaxBefore = BigDecimal.valueOf(0.00);
+ //鏈湀鏄惁宸茬粡绠楄繃缁╂晥锛堜笅闈㈡墸闄�5000闇�瑕佺敤鍒拌繖涓紝濡傛灉鏈湀宸茬粡鎵h繃5000锛屽氨涓嶅啀鎵d簡锛�
+ Boolean deduct = false;
+ //鑾峰彇褰撳墠鏈堜唤
+ Date date = new Date();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+ String nowMonth = sdf.format(date);
+
+ for (ServiceFunddetail serviceFunddetail1 : serviceFunddetails) {
+ historyTaxBefore = historyTaxBefore.add(BigDecimal.valueOf(serviceFunddetail1.getAmount())).subtract(BigDecimal.valueOf(5000));
+ historyTax = historyTax.add(BigDecimal.valueOf(serviceFunddetail1.getTaxamount()));
+ if (serviceFunddetail1.getJxrq().equals(nowMonth)) {
+ deduct = true;
+ }
+ }
+ BigDecimal allValue = BigDecimal.valueOf(0.00);
+ //鍏堟煡璇竴涓嬫湰鏈堟槸鍚﹀凡缁忕畻杩囩哗鏁堬紙涓�涓湀鍙噺涓�娆�5000锛屽鏋滀笂涓�娆″凡缁忓噺杩囷紝杩欎竴娆″氨涓嶅湪鍑忎簡锛�
+ if (deduct == true) {
+ //鏈湀宸茬粡鍑忚繃5000浜�
+ allValue = historyTaxBefore.add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
+ } else {
+ BigDecimal subtract = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(5000));
+ allValue = historyTaxBefore.add(subtract);
+ }
+ //璁$畻鍔犱笂鏈鐨勭◣鍓嶉噾棰濈殑鎬荤◣
+ BigDecimal personTaxation = PerformanceTaxtUtils.getPersonTaxation(allValue);
+ //璁$畻鏈鐨勭◣
+ BigDecimal nowSingleTax = personTaxation.subtract(historyTax);
+ //璁$畻鏈鐨勭◣鍚�
+ BigDecimal taxAfter = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(nowSingleTax);
+
+ //灏嗚绠楀嚭鏉ョ殑鏁版嵁鏀惧埌serviceFunddetail涓�
+ serviceFunddetail.setTaxamount(nowSingleTax.doubleValue());
+ serviceFunddetail.setTaxedamount(taxAfter.doubleValue());
+ // 缁╂晥涓嶅睘浜庝笓瀹惰垂锛氫笉璁$畻澧炲�肩◣/鍩庡缓绋庯紝鍔冲姟绋庡墠 = 绋庡墠閲戦
+ serviceFunddetail.setVatAmount(0.0);
+ serviceFunddetail.setCityTaxAmount(0.0);
+ serviceFunddetail.setLaborPretaxAmount(serviceFunddetail.getAmount());
+ serviceFunddetail.setJxrq(nowMonth);
+
+ save(serviceFunddetail);
+ Map map = new HashMap();
+ map.put("amount", serviceFunddetail.getAmount());
+ map.put("taxedamount", taxAfter.doubleValue());
+ return map;
+ }
+
+
+ @Override
+ public List<SpStatBonus> getListBySpStatBonus(SpStatBonusReq spStatBonusReq) {
+ return spStatBonusMapper.getListBySpStatBonus(spStatBonusReq.getPabegtime(), spStatBonusReq.getPaendtime(), spStatBonusReq.getPadeptno(), spStatBonusReq.getPausername());
+ }
}
--
Gitblit v1.9.3