| | |
| | | import com.ruoyi.common.enums.ApplyTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.tax.VatTaxUtils; |
| | | import com.ruoyi.common.utils.HttpClientKit; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.DtoConversionUtils; |
| | |
| | | |
| | | List<VExpertfeeDonor> list2 = vExpertfeeDonorMapper.selectVExpertfeeDonorList2(faxId); |
| | | // 打印模板视图不含“增值税 / 城建税 / 劳务税前”,按 fund_tax_id 从明细表汇总后回填 |
| | | fillDonorTaxAmounts(list2, faxId); |
| | | fillDonorTaxAmounts(list2); |
| | | ExcelUtil<VExpertfeeDonor> util2 = new ExcelUtil<VExpertfeeDonor>(VExpertfeeDonor.class); |
| | | AjaxResult ajaxResult2 = util2.exportExcel(list2, "VExpertfeeDonor"); |
| | | |
| | | List<VExpertfeeExpert> list3 = vExpertfeeExpertMapper.selectVExpertfeeExpertListByFaxId(faxId); |
| | | fillExpertTaxAmounts(list3, faxId); |
| | | fillExpertTaxAmounts(list3); |
| | | ExcelUtil<VExpertfeeExpert> util3 = new ExcelUtil<VExpertfeeExpert>(VExpertfeeExpert.class); |
| | | AjaxResult ajaxResult3 = util3.exportExcel(list3, "vExpertfeeExpert"); |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 专家费汇总单打印(专家明细 sheet):回填增值税 / 城建税 / 劳务税前,并把视图的「扣税金额」拆回劳务个税。 |
| | | * 专家费汇总单打印(专家明细 sheet):增值税、城建税直接取视图列,劳务税前按差额计算。 |
| | | * <p> |
| | | * 口径说明: |
| | | * 2026-11-18:视图 {@code v_expertfee_expert} 已独立提供 {@code vat_amount}、{@code city_tax_amount}, |
| | | * 且 {@code TaxAmount} 恢复为<b>纯劳务个税</b>,因此: |
| | | * <ul> |
| | | * <li>视图 {@code v_expertfee_expert} 的 {@code TaxAmount} 已改为 |
| | | * <b>增值税 + 城建税 + 劳务个税</b>(2026-11-12 业务方修改),而打印要分别展示, |
| | | * 因此 {@code 劳务个税 = TaxAmount − 增值税 − 城建税};</li> |
| | | * <li>增值税/城建税/劳务税前 视图未单独提供,按 <b>与视图相同的分组</b> |
| | | * (受益人 + 证件号 + 卡号 + 开户行 + 单位)从 {@code service_funddetail} 汇总后匹配回填;</li> |
| | | * <li>「合计」行按各行的值累加(不依赖视图 UNION 的合计列)。</li> |
| | | * <li>增值税 / 城建税 / 劳务税后 直接用视图值,不再从明细表二次汇总;</li> |
| | | * <li>劳务税前 = 税前金额 − 增值税 − 城建税;</li> |
| | | * <li>「合计」行按各行累加。</li> |
| | | * </ul> |
| | | */ |
| | | private void fillExpertTaxAmounts(List<VExpertfeeExpert> rows, Integer fundTaxId) { |
| | | private void fillExpertTaxAmounts(List<VExpertfeeExpert> rows) { |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return; |
| | | } |
| | | Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByBeneficiary(fundTaxId.longValue())); |
| | | BigDecimal vatTotal = BigDecimal.ZERO; |
| | | BigDecimal cityTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTaxTotal = BigDecimal.ZERO; |
| | | for (VExpertfeeExpert row : rows) { |
| | | if (isTotalRow(row.getBeneficiaryname())) { |
| | | continue; |
| | | } |
| | | FundTaxAmountSum s = sumMap.get(expertGroupKey(row)); |
| | | BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount()); |
| | | BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount()); |
| | | BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount()); |
| | | // 视图的扣税金额含增值税、城建税,这里拆回劳务个税 |
| | | BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city); |
| | | BigDecimal vat = nvl(row.getVatAmount()); |
| | | BigDecimal city = nvl(row.getCityTaxAmount()); |
| | | BigDecimal labor = VatTaxUtils.roundMoney( |
| | | nvl(row.getPretaxamount()).subtract(vat).subtract(city)); |
| | | row.setVatAmount(vat); |
| | | row.setCityTaxAmount(city); |
| | | row.setLaborPretaxAmount(labor); |
| | | row.setTaxamount(laborTax); |
| | | vatTotal = vatTotal.add(vat); |
| | | cityTotal = cityTotal.add(city); |
| | | laborTotal = laborTotal.add(labor); |
| | | laborTaxTotal = laborTaxTotal.add(laborTax); |
| | | } |
| | | for (VExpertfeeExpert row : rows) { |
| | | if (isTotalRow(row.getBeneficiaryname())) { |
| | | row.setVatAmount(vatTotal); |
| | | row.setCityTaxAmount(cityTotal); |
| | | row.setLaborPretaxAmount(laborTotal); |
| | | row.setTaxamount(laborTaxTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 专家费汇总单打印(捐献者 sheet):同 {@link #fillExpertTaxAmounts},分组为「捐献者 + 案例ID」。 |
| | | * 专家费汇总单打印(捐献者 sheet):口径同 {@link #fillExpertTaxAmounts},合计行按「捐献者」行的值累加。 |
| | | */ |
| | | private void fillDonorTaxAmounts(List<VExpertfeeDonor> rows, Integer fundTaxId) { |
| | | private void fillDonorTaxAmounts(List<VExpertfeeDonor> rows) { |
| | | if (CollectionUtils.isEmpty(rows)) { |
| | | return; |
| | | } |
| | | Map<String, FundTaxAmountSum> sumMap = toSumMap(serviceFundMapper.selectTaxSumByDonor(fundTaxId.longValue())); |
| | | BigDecimal vatTotal = BigDecimal.ZERO; |
| | | BigDecimal cityTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTotal = BigDecimal.ZERO; |
| | | BigDecimal laborTaxTotal = BigDecimal.ZERO; |
| | | for (VExpertfeeDonor row : rows) { |
| | | if (isTotalRow(row.getDonorname())) { |
| | | continue; |
| | | } |
| | | FundTaxAmountSum s = sumMap.get(donorGroupKey(row.getDonorname(), row.getInfoid())); |
| | | BigDecimal vat = s == null ? BigDecimal.ZERO : nvl(s.getVatAmount()); |
| | | BigDecimal city = s == null ? BigDecimal.ZERO : nvl(s.getCityTaxAmount()); |
| | | BigDecimal labor = s == null ? BigDecimal.ZERO : nvl(s.getLaborPretaxAmount()); |
| | | BigDecimal laborTax = nvl(row.getTaxamount()).subtract(vat).subtract(city); |
| | | BigDecimal vat = nvl(row.getVatAmount()); |
| | | BigDecimal city = nvl(row.getCityTaxAmount()); |
| | | BigDecimal labor = VatTaxUtils.roundMoney( |
| | | nvl(row.getPretaxamount()).subtract(vat).subtract(city)); |
| | | row.setVatAmount(vat); |
| | | row.setCityTaxAmount(city); |
| | | row.setLaborPretaxAmount(labor); |
| | | row.setTaxamount(laborTax); |
| | | vatTotal = vatTotal.add(vat); |
| | | cityTotal = cityTotal.add(city); |
| | | laborTotal = laborTotal.add(labor); |
| | | laborTaxTotal = laborTaxTotal.add(laborTax); |
| | | } |
| | | for (VExpertfeeDonor row : rows) { |
| | | if (isTotalRow(row.getDonorname())) { |
| | | row.setVatAmount(vatTotal); |
| | | row.setCityTaxAmount(cityTotal); |
| | | row.setLaborPretaxAmount(laborTotal); |
| | | row.setTaxamount(laborTaxTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static Map<String, FundTaxAmountSum> toSumMap(List<FundTaxAmountSum> sums) { |
| | | Map<String, FundTaxAmountSum> map = new HashMap<>(); |
| | | if (!CollectionUtils.isEmpty(sums)) { |
| | | for (FundTaxAmountSum s : sums) { |
| | | map.put(s.getGroupKey(), s); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 专家明细分组键,必须与视图 {@code v_expertfee_expert} 的 GROUP BY 完全一致: |
| | | * BeneficiaryName + IDCardNo + BankCardNo + DepositBank + UnitName。 |
| | | */ |
| | | private static String expertGroupKey(VExpertfeeExpert row) { |
| | | return joinKey(row.getBeneficiaryname(), row.getIdcardno(), row.getBankcardno(), |
| | | row.getDepositbank(), row.getUnitname()); |
| | | } |
| | | |
| | | /** |
| | | * 捐献者分组键,与视图 {@code v_expertfee_donor} 的 GROUP BY 一致:DonorName + InfoID。 |
| | | */ |
| | | private static String donorGroupKey(String donorname, Long infoid) { |
| | | return joinKey(donorname, infoid == null ? "" : String.valueOf(infoid)); |
| | | } |
| | | |
| | | /** |
| | | * 用 "|" 拼接分组键;null 统一按空串处理(与 SQL 的 IFNULL(x,'') 对齐) |
| | | */ |
| | | private static String joinKey(Object... parts) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (int i = 0; i < parts.length; i++) { |
| | | if (i > 0) { |
| | | sb.append('|'); |
| | | } |
| | | Object p = parts[i]; |
| | | sb.append(p == null ? "" : String.valueOf(p).trim()); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |