gaoluyang
6 天以前 2eeeb70e4733e7fc41635c3aa2143f13cbc43d58
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/purchase/ErpPurchaseInvoiceServiceImpl.java
@@ -132,18 +132,16 @@
        }
        // 1.2 校验所有采购订单必须是同一供应商(来票对应一个供应商)
        validateSameSupplier(orders);
        // 2. 校验分摊合计 = 来票金额
        // 2. 校验分摊合计不能大于来票金额(允许小于:未分摊部分可后续编辑来票时再补充采购订单)
        BigDecimal allocationTotal = allocations.stream().map(ErpPurchaseInvoiceOrderReqVO::getPrice)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
        if (allocationTotal.compareTo(reqVO.getPrice()) != 0) {
            BigDecimal diff = reqVO.getPrice().subtract(allocationTotal);
            String detail = diff.compareTo(BigDecimal.ZERO) > 0
                    ? StrUtil.format("还有 {} 元未分摊到订单,请为订单填写分摊金额或改选订单", diff.stripTrailingZeros().toPlainString())
                    : StrUtil.format("分摊合计比来票金额多 {} 元,请减少分摊金额", diff.negate().stripTrailingZeros().toPlainString());
        if (allocationTotal.compareTo(reqVO.getPrice()) > 0) {
            throw new ServiceException(PURCHASE_INVOICE_ALLOCATION_SUM_MISMATCH.getCode(),
                    StrUtil.format("来票金额 {} 元,各订单分摊合计 {} 元,两者必须相等(差额:{})。",
                    StrUtil.format("来票金额 {} 元,各订单分摊合计 {} 元,分摊合计不能大于来票金额(超出 {} 元)。"
                                    + "请减少订单的分摊金额,或提高来票金额后重试;未分摊的部分可以留待以后再编辑来票补充采购订单。",
                            reqVO.getPrice().stripTrailingZeros().toPlainString(),
                            allocationTotal.stripTrailingZeros().toPlainString(), detail));
                            allocationTotal.stripTrailingZeros().toPlainString(),
                            allocationTotal.subtract(reqVO.getPrice()).stripTrailingZeros().toPlainString()));
        }
        // 3. 主订单、供应商取分摊明细第一张(一张来票涉及多个供应商时,列表/付款沿用第一家)
        reqVO.setPurchaseOrderId(allocations.get(0).getPurchaseOrderId());