| | |
| | | import com.ruoyi.basic.service.ICustomerRegionsService; |
| | | import com.ruoyi.common.enums.FileNameType; |
| | | import com.ruoyi.common.enums.SaleEnum; |
| | | import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | |
| | | import com.ruoyi.sales.service.ISalesLedgerProductProcessBindService; |
| | | import com.ruoyi.sales.service.ISalesLedgerProductProcessService; |
| | | import com.ruoyi.sales.service.ISalesLedgerService; |
| | | import com.ruoyi.stock.dto.StockInventoryDto; |
| | | import com.ruoyi.stock.service.StockInventoryService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | |
| | | private final ISalesLedgerProductProcessBindService salesLedgerProductProcessBindService; |
| | | |
| | | private final ISalesLedgerProcessRouteService salesLedgerProcessRouteService; |
| | | |
| | | private final StockInventoryService stockInventoryService; |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | |
| | | .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | // 发货状态 |
| | | salesLedger.setDeliveryStatus(0); |
| | | salesLedger.setDeliveryStatus(1); |
| | | salesLedgerMapper.insert(salesLedger); |
| | | |
| | | for (SalesLedgerProductImportDto salesLedgerProductImportDto : salesLedgerProductImportDtos) { |
| | |
| | | if (salesLedger.getId() == null) { |
| | | String contractNo = generateSalesContractNo(); |
| | | salesLedger.setSalesContractNo(contractNo); |
| | | salesLedger.setDeliveryStatus(0); |
| | | salesLedger.setDeliveryStatus(1); |
| | | salesLedger.setStockStatus(0); |
| | | salesLedgerMapper.insert(salesLedger); |
| | | } else { |
| | | if (salesLedger.getDeliveryStatus() == 1) { |
| | | if (salesLedger.getDeliveryStatus() == 5) { |
| | | throw new ServiceException("订单已发货,禁止编辑"); |
| | | } |
| | | salesLedgerMapper.updateById(salesLedger); |
| | |
| | | return totalAmount; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void salesStock(SalesLedger salesLedger) { |
| | | if (salesLedger == null || salesLedger.getId() == null) { |
| | | throw new NullPointerException("入库失败,请选择需要入库的销售订单"); |
| | | } |
| | | // 查询销售订单是否存在 |
| | | SalesLedger ledger = baseMapper.selectById(salesLedger.getId()); |
| | | if (ledger == null) { |
| | | throw new ServiceException("入库失败,销售订单不存在"); |
| | | } |
| | | if (ledger.getStockStatus() == null) { |
| | | throw new ServiceException("入库失败,销售订单入库状态异常"); |
| | | } |
| | | if (ledger.getStockStatus() == 1) { |
| | | throw new ServiceException("入库失败,该销售订单已入库,请勿重复入库"); |
| | | } |
| | | // 查询销售订单的产品 |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(Wrappers.<SalesLedgerProduct>lambdaQuery().eq(SalesLedgerProduct::getSalesLedgerId, ledger.getId())); |
| | | if (salesLedgerProducts == null || salesLedgerProducts.isEmpty()) { |
| | | throw new ServiceException("入库失败,未查询到该销售订单的销售产品"); |
| | | } |
| | | for (SalesLedgerProduct product : salesLedgerProducts) { |
| | | if (product.getProductModelId() == null) { |
| | | continue; |
| | | } |
| | | StockInventoryDto dto = new StockInventoryDto(); |
| | | dto.setRecordId(product.getId()); |
| | | dto.setRecordType(StockInQualifiedRecordTypeEnum.SALE_STOCK_IN.getCode()); |
| | | dto.setQualitity(product.getQuantity()); |
| | | dto.setProductModelId(product.getProductModelId()); |
| | | stockInventoryService.addstockInventory(dto); |
| | | } |
| | | // 更新销售订单入库状态 |
| | | ledger.setStockStatus(1); |
| | | baseMapper.updateById(ledger); |
| | | } |
| | | } |