| | |
| | | package com.ruoyi.project.service.impl; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.ruoyi.common.tax.TaxtUtils; |
| | | import com.ruoyi.common.utils.bean.DtoConversionUtils; |
| | | import com.ruoyi.project.domain.*; |
| | | import com.ruoyi.project.domain.vo.TaxMoneyVO; |
| | | import com.ruoyi.project.domain.vo.TaxedMoneyVO; |
| | | import com.ruoyi.project.domain.vo.*; |
| | | import com.ruoyi.project.mapper.ServiceFundMapper; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.project.mapper.ServiceFunddetailMapper; |
| | | import com.ruoyi.project.service.IServiceFunddetailService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 费用申请明细Service业务层处理 |
| | |
| | | /** |
| | | * 根据税后工资,算出税前工资 |
| | | * |
| | | * @param money |
| | | * @param taxMoneyVo |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum(); |
| | | } |
| | | //计算出总的税后薪酬(包含本次) |
| | | sum = sum + taxMoneyVo.getMoney(); |
| | | sum = sum + Double.valueOf(taxMoneyVo.getMoney()); |
| | | //税前总金额 |
| | | String taxationBefore = TaxtUtils.getTaxationBefore(new BigDecimal(sum)); |
| | | //总个税 |
| | |
| | | ServiceFunddetail serviceFunddetail = serviceFunddetailMapper.selectById(id); |
| | | Long fundid = serviceFunddetail.getFundid(); |
| | | ServiceFund serviceFund = serviceFundMapper.selectById(fundid); |
| | | if (ObjectUtils.isNotEmpty(serviceFund)) { |
| | | Double pretax = serviceFund.getPretaxcost(); |
| | | Double aftertax = serviceFund.getTaxedcost(); |
| | | pretax = pretax - serviceFunddetail.getAmount(); |
| | | aftertax = aftertax - serviceFunddetail.getTaxedamount(); |
| | | Double amount = pretax + 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); |
| | | serviceFund.setTaxedcost(aftertax); |
| | | serviceFund.setAmountrequested(amount); |
| | | 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); |
| | | } |
| | | } |
| | | return serviceFunddetailVOS; |
| | | } |
| | | |
| | | /** |
| | | * 根据条件算税 |
| | | * |
| | | * @param serviceFunddetails |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails) { |
| | | //用于临时保存已经算好的"费用详情数据" |
| | | List<ServiceFunddetail> temporarySave = new ArrayList<>(); |
| | | |
| | | for (ServiceFunddetail serviceFunddetail : serviceFunddetails) { |
| | | //获取当月的第一天 |
| | | Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant()); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String firstDatStr = dateFormat.format(firstDay); |
| | | TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO(); |
| | | |
| | | taxMoneyVO.setTaxTime(new Date()); |
| | | taxMoneyVO.setFirstDay(firstDay); |
| | | // taxMoneyVO.setApplyType(Long.valueOf(serviceFunddetail.getApplytype())); |
| | | taxMoneyVO.setFundID(serviceFunddetail.getFundid()); |
| | | taxMoneyVO.setBeneficiaryNo(serviceFunddetail.getBeneficiaryno()); |
| | | //查出税前、税、税后的总额(不包含本次) |
| | | TaxMoneySumEO taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO); |
| | | if (ObjectUtils.isEmpty(taxSum)) { |
| | | taxSum = new TaxMoneySumEO(); |
| | | } |
| | | |
| | | //判断临时集合temporarySave中,有没有已经算过的数据 |
| | | if (CollectionUtils.isNotEmpty(temporarySave)) { |
| | | for (ServiceFunddetail serviceFunddetail1 : temporarySave) { |
| | | //如果本次的”人员类型“、”受益人编号“在临时集合中存在,则将集合数据中的该受益人的,税前、税金、税后,和总的相加,并将老的覆盖 |
| | | // if (serviceFunddetail1.getApplytype().equals(serviceFunddetail.getApplytype()) && serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) { |
| | | if (serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) { |
| | | //将集合数据中的该受益人的,税前、税金、税后,和总的相加 |
| | | BigDecimal amounts = BigDecimal.valueOf(taxSum.getAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getAmount()))); |
| | | BigDecimal taxAmounts = BigDecimal.valueOf(taxSum.getTaxAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getTaxamount()))); |
| | | BigDecimal TaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getTaxedamount()))); |
| | | //将老的覆盖 |
| | | taxSum.setAmounts(amounts.doubleValue()); |
| | | taxSum.setTaxAmounts(taxAmounts.doubleValue()); |
| | | taxSum.setTaxedAmounts(TaxedAmounts.doubleValue()); |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (!serviceFunddetail.getServicesscopename().contains("税后")) { |
| | | // 如何税前金额不为空,用之前的”总税前金额“,加上当前”税前金额“ |
| | | BigDecimal newAmounts = BigDecimal.valueOf(taxSum.getAmounts()).add(BigDecimal.valueOf(serviceFunddetail.getAmount())); |
| | | |
| | | // 计算总税金(包含本次) |
| | | String taxation = TaxtUtils.getTaxation(newAmounts); |
| | | //计算本次税金(总税金(包含本次) - 总税金(不包含本次)) |
| | | BigDecimal taxAmountNow = new BigDecimal(taxation).subtract(new BigDecimal(String.valueOf(taxSum.getTaxAmounts()))); |
| | | |
| | | //计算本次的税后金额(本次的税前金额 - 税金) |
| | | BigDecimal texdAfterNow = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(taxAmountNow); |
| | | |
| | | //将循环的数据重新放到一个新对象中 |
| | | ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class); |
| | | serviceFunddetail3.setTaxamount(taxAmountNow.doubleValue()); |
| | | serviceFunddetail3.setTaxedamount(texdAfterNow.doubleValue()); |
| | | serviceFunddetail3.setTaxTime(new Date()); |
| | | // 将该条数据更新 |
| | | updateById(serviceFunddetail3); |
| | | // 把该数据,放到临时的集合中 |
| | | temporarySave.add(serviceFunddetail3); |
| | | } else if (serviceFunddetail.getServicesscopename().contains("税后")) { |
| | | //税后不为空, 用之前的”总税后金额“,加上当前”税后金额“ |
| | | BigDecimal newTaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())); |
| | | |
| | | //通过总税后(包含本次)算出总税前 |
| | | String taxationBefore = TaxtUtils.getTaxationBefore(newTaxedAmounts); |
| | | //算出本次税前(总税前(包含本次) - 总税前(不包含本次)) |
| | | BigDecimal amountNow = new BigDecimal(taxationBefore).subtract(BigDecimal.valueOf(taxSum.getAmounts())); |
| | | |
| | | //算出本次税金(本次税前 - 本次税后) |
| | | BigDecimal tax = amountNow.subtract(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())); |
| | | |
| | | //将循环的数据重新放到一个新对象中 |
| | | ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class); |
| | | serviceFunddetail3.setAmount(amountNow.doubleValue()); |
| | | serviceFunddetail3.setTaxamount(tax.doubleValue()); |
| | | serviceFunddetail3.setTaxTime(new Date()); |
| | | // 将该条数据更新 |
| | | updateById(serviceFunddetail3); |
| | | // 把该数据,放到临时的集合中 |
| | | temporarySave.add(serviceFunddetail3); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | } |