| | |
| | | import com.ruoyi.common.enums.ReviewStatusEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.FreightUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | |
| | | // 执行更新操作 |
| | | if (!updateList.isEmpty()) { |
| | | for (SalesLedgerProduct product : updateList) { |
| | | FreightUtils.fillFreightAmount(product); |
| | | product.setType(ledgerType); |
| | | salesLedgerProductMapper.updateById(product); |
| | | } |
| | |
| | | // 执行插入操作 |
| | | if (!insertList.isEmpty()) { |
| | | for (SalesLedgerProduct salesLedgerProduct : insertList) { |
| | | FreightUtils.fillFreightAmount(salesLedgerProduct); |
| | | salesLedgerProduct.setType(ledgerType); |
| | | Date entryDate = purchaseLedger.getEntryDate(); |
| | | |
| | |
| | | for (PurchaseLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) { |
| | | SalesLedgerProduct salesLedgerProduct = new SalesLedgerProduct(); |
| | | BeanUtils.copyProperties(salesLedgerProductImportDto, salesLedgerProduct); |
| | | FreightUtils.fillFreightAmount(salesLedgerProduct); |
| | | salesLedgerProduct.setSalesLedgerId(salesLedger.getId()); |
| | | salesLedgerProduct.setType(2); |
| | | // 计算不含税总价 |
| | |
| | | throw new BaseException("理论入库数量必须大于0"); |
| | | } |
| | | |
| | | BigDecimal approvedStockInNum = getApprovedPurchaseStockInNum( |
| | | BigDecimal occupiedStockInNum = getOccupiedPurchaseStockInNum( |
| | | purchaseLedger.getId(), |
| | | purchaseLedger.getPurchaseContractNumber(), |
| | | salesLedgerProduct.getId(), |
| | | salesLedgerProduct.getProductModelId() |
| | | ); |
| | | BigDecimal remainingStockInNum = salesLedgerProduct.getQuantity().subtract(approvedStockInNum); |
| | | BigDecimal remainingStockInNum = salesLedgerProduct.getQuantity().subtract(occupiedStockInNum); |
| | | if (remainingStockInNum.compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new BaseException("产品【" + productModel.getModel() + "】已完成入库"); |
| | | } |
| | |
| | | return count; |
| | | } |
| | | |
| | | private BigDecimal getApprovedPurchaseStockInNum(Long purchaseLedgerId, String purchaseContractNumber, Long productId, Long productModelId) { |
| | | private BigDecimal getOccupiedPurchaseStockInNum(Long purchaseLedgerId, String purchaseContractNumber, Long productId, Long productModelId) { |
| | | if (purchaseLedgerId == null || productId == null || productModelId == null || !StringUtils.hasText(purchaseContractNumber)) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | List<StockInRecord> stockRecords = findDirectStockRecords(purchaseLedgerId, purchaseContractNumber, productModelId, productId); |
| | | return stockRecords.stream() |
| | | .filter(Objects::nonNull) |
| | | .filter(item -> ReviewStatusEnum.APPROVED.getCode().equals(item.getApprovalStatus())) |
| | | .map(StockInRecord::getStockInNum) |
| | | .filter(item -> item.getApprovalStatus() == null |
| | | || ReviewStatusEnum.PENDING_REVIEW.getCode().equals(item.getApprovalStatus()) |
| | | || ReviewStatusEnum.APPROVED.getCode().equals(item.getApprovalStatus())) |
| | | .map(item -> item.getTheoryStockInNum() != null ? item.getTheoryStockInNum() : item.getStockInNum()) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | } |