gongchunyi
21 小时以前 2d9dbba1a9137c137340d6aa58aa7e5b70bd26a9
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1867,6 +1867,12 @@
            if (selectedProduct.getProductModelId() == null) {
                throw new ServiceException("入库失败,产品规格未维护,无法入库");
            }
            BigDecimal orderQty = selectedProduct.getQuantity() == null ? BigDecimal.ZERO : selectedProduct.getQuantity();
            BigDecimal qualifiedStocked = selectedProduct.getStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getStockedQuantity();
            BigDecimal inboundQty = inboundQtyByLineId.getOrDefault(selectedProduct.getId(), BigDecimal.ZERO);
            if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && qualifiedStocked.add(inboundQty).compareTo(orderQty) > 0) {
                throw new ServiceException("入库失败,合格入库数量之和不能大于订单数量");
            }
        }
        String approveUserIds = resolveApproveUserIds(dto.getApproveUserIds(), salesLedger.getId(), INBOUND_BIZ_TYPE_SCAN_QUALIFIED);
        if (StringUtils.isEmpty(approveUserIds)) {
@@ -1924,6 +1930,10 @@
            }
            BigDecimal oldStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity();
            BigDecimal newStocked = oldStocked.add(inboundThisLine);
            BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity();
            if (newStocked.compareTo(orderQty) > 0) {
                throw new ServiceException("入库失败,合格入库数量之和不能大于订单数量");
            }
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setRecordId(dbProduct.getId());
@@ -1934,7 +1944,6 @@
            stockInventoryDto.setSalesLedgerProductId(dbProduct.getId());
            stockInventoryService.addstockInventory(stockInventoryDto);
            BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity();
            int lineStockStatus;
            if (newStocked.compareTo(BigDecimal.ZERO) <= 0) {
                lineStockStatus = 0;
@@ -2005,6 +2014,20 @@
            if (selectedProduct.getProductModelId() == null) {
                throw new ServiceException("不合格入库失败,产品规格未维护,无法入库");
            }
            BigDecimal orderQty = selectedProduct.getQuantity() == null ? BigDecimal.ZERO : selectedProduct.getQuantity();
            BigDecimal qualifiedStocked = selectedProduct.getStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getStockedQuantity();
            BigDecimal unqualifiedStocked = selectedProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : selectedProduct.getUnqualifiedStockedQuantity();
            BigDecimal inboundQty = inboundQtyByLineId.getOrDefault(selectedProduct.getId(), BigDecimal.ZERO);
            BigDecimal remainForUnqualified = orderQty.subtract(qualifiedStocked);
            if (remainForUnqualified.compareTo(BigDecimal.ZERO) <= 0 && inboundQty.compareTo(BigDecimal.ZERO) > 0) {
                throw new ServiceException("不合格入库失败,该产品已无可入不合格库数量");
            }
            if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && unqualifiedStocked.add(inboundQty).compareTo(orderQty) > 0) {
                throw new ServiceException("不合格入库失败,不合格入库数量之和不能大于订单数量");
            }
            if (inboundQty.compareTo(BigDecimal.ZERO) > 0 && unqualifiedStocked.add(inboundQty).compareTo(remainForUnqualified) > 0) {
                throw new ServiceException("不合格入库失败,不合格入库数量不能大于订单数量减去合格入库数量");
            }
        }
        String approveUserIds = resolveApproveUserIds(dto.getApproveUserIds(), salesLedger.getId(), INBOUND_BIZ_TYPE_SCAN_UNQUALIFIED);
        if (StringUtils.isEmpty(approveUserIds)) {
@@ -2060,9 +2083,22 @@
            if (dbProduct.getProductModelId() == null) {
                throw new ServiceException("不合格入库失败,产品规格未维护,无法入库");
            }
            stockUtils.addUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), inboundThisLine, StockInUnQualifiedRecordTypeEnum.SALES_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId());
            BigDecimal orderQty = dbProduct.getQuantity() == null ? BigDecimal.ZERO : dbProduct.getQuantity();
            BigDecimal qualifiedStocked = dbProduct.getStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getStockedQuantity();
            BigDecimal oldUnStocked = dbProduct.getUnqualifiedStockedQuantity() == null ? BigDecimal.ZERO : dbProduct.getUnqualifiedStockedQuantity();
            dbProduct.setUnqualifiedStockedQuantity(oldUnStocked.add(inboundThisLine));
            BigDecimal newUnStocked = oldUnStocked.add(inboundThisLine);
            BigDecimal remainForUnqualified = orderQty.subtract(qualifiedStocked);
            if (remainForUnqualified.compareTo(BigDecimal.ZERO) <= 0) {
                throw new ServiceException("不合格入库失败,该产品已无可入不合格库数量");
            }
            if (newUnStocked.compareTo(orderQty) > 0) {
                throw new ServiceException("不合格入库失败,不合格入库数量之和不能大于订单数量");
            }
            if (newUnStocked.compareTo(remainForUnqualified) > 0) {
                throw new ServiceException("不合格入库失败,不合格入库数量不能大于订单数量减去合格入库数量");
            }
            stockUtils.addUnStock(ledgerId, dbProduct.getId(), dbProduct.getProductModelId(), inboundThisLine, StockInUnQualifiedRecordTypeEnum.SALES_SCAN_UNSTOCK_IN.getCode(), dbProduct.getId());
            dbProduct.setUnqualifiedStockedQuantity(newUnStocked);
            dbProduct.fillRemainingQuantity();
            salesLedgerProductMapper.updateById(dbProduct);
        }