|
@@ -217,6 +217,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
@Autowired
|
|
@Autowired
|
|
private ProductClassifyService productClassifyService;
|
|
private ProductClassifyService productClassifyService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ContractOutboundInfoService contractOutboundInfoService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ContractOutboundRecordsService contractOutboundRecordsService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 合同和样品单 下拉分页
|
|
* 合同和样品单 下拉分页
|
|
*/
|
|
*/
|
|
@@ -3061,19 +3066,50 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
|
|
|
@DSTransactional
|
|
@DSTransactional
|
|
@Override
|
|
@Override
|
|
- public void saleOutbound(ContractDto dto) {
|
|
|
|
- Long id = dto.getId();
|
|
|
|
- List<ContractProductDto> productDtoList = dto.getContractProductList();
|
|
|
|
|
|
+ public void saleOutbound(ContractOutboundInfoDto dto) {
|
|
|
|
+ Long contractId = dto.getContractId();
|
|
|
|
+ List<ContractOutboundRecords> productDtoList = dto.getOutboundRecordList();
|
|
|
|
+
|
|
|
|
+ dto.setStatus(FlowStatusEnum1.PASS.getKey());
|
|
|
|
+
|
|
|
|
+ ContractVo contract = baseMapper.detail(contractId);
|
|
|
|
+ Assert.notEmpty(contract, "查询不到销售订单信息!");
|
|
|
|
+ //创建出入库信息
|
|
|
|
+ createOutboundInfo(dto);
|
|
|
|
+
|
|
|
|
+ //校验是否能出货(非特批校验,特批跳过)
|
|
|
|
+ //数量*(1-预付比例%)*单价<=(累计收款金额-预付款金额)-已出货金额
|
|
|
|
+ //预付比例-小数
|
|
|
|
+ BigDecimal multiply = new BigDecimal(contract.getAdvanceRatio()).multiply(BigDecimal.valueOf(0.01));
|
|
|
|
+ //剩下比例-小数
|
|
|
|
+ BigDecimal subtract = BigDecimal.ONE.subtract(multiply);
|
|
|
|
+ //(累计收款金额-预付款金额)-已出货金额
|
|
|
|
+ BigDecimal subtract2 = contract.getSumClaimMoney().subtract(contract.getAmount().multiply(multiply)).subtract(contract.getShipmentAmount());
|
|
|
|
+ for (ContractOutboundRecords productDto : productDtoList) {
|
|
|
|
+ BigDecimal multiply1 = productDto.getQuantity().multiply(subtract).multiply(productDto.getPrice());
|
|
|
|
+ if (multiply1.compareTo(subtract2) > 0) {
|
|
|
|
+ throw new ServiceException(String.format("收款金额不满足出货条件,至少需再收款%s %s 才能出货!", contract.getCurrency(), multiply1.subtract(subtract2).setScale(4, RoundingMode.HALF_UP)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //创建待出库
|
|
|
|
+ saleOutboundComm(dto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void saleOutboundComm(ContractOutboundInfoDto dto) {
|
|
|
|
+ Long contractId = dto.getContractId();
|
|
|
|
+ List<ContractOutboundRecords> productDtoList = dto.getOutboundRecordList();
|
|
//补充数据
|
|
//补充数据
|
|
- for (ContractProductDto contractProductDto : productDtoList) {
|
|
|
|
- ContractProduct byId = contractProductService.getById(contractProductDto.getId());
|
|
|
|
- contractProductDto.setProductId(byId.getProductId());
|
|
|
|
- contractProductDto.setPrice(byId.getPrice());
|
|
|
|
|
|
+ for (ContractOutboundRecords outboundRecords : productDtoList) {
|
|
|
|
+ ContractProduct byId = contractProductService.getById(outboundRecords.getContractProductId());
|
|
|
|
+ outboundRecords.setProductId(byId.getProductId());
|
|
|
|
+ outboundRecords.setPrice(byId.getPrice());
|
|
}
|
|
}
|
|
|
|
|
|
//修改订单出库状态
|
|
//修改订单出库状态
|
|
this.update(q -> q
|
|
this.update(q -> q
|
|
- .eq(Contract::getId, id)
|
|
|
|
|
|
+ .eq(Contract::getId, contractId)
|
|
.set(Contract::getOutboundStatus, 1)
|
|
.set(Contract::getOutboundStatus, 1)
|
|
.set(Contract::getOutboundTime, new Date())
|
|
.set(Contract::getOutboundTime, new Date())
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
.set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
@@ -3081,27 +3117,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
);
|
|
);
|
|
|
|
|
|
//修改生产订单出库状态为出库中
|
|
//修改生产订单出库状态为出库中
|
|
- stockWaitDetailsMapper.updateOrderStatusByContractId(id, 5);
|
|
|
|
|
|
+ stockWaitDetailsMapper.updateOrderStatusByContractId(contractId, 5);
|
|
|
|
|
|
- ContractVo contract = baseMapper.detail(id);
|
|
|
|
|
|
+ ContractVo contract = baseMapper.detail(contractId);
|
|
Assert.notEmpty(contract, "查询不到销售订单信息!");
|
|
Assert.notEmpty(contract, "查询不到销售订单信息!");
|
|
|
|
|
|
- //校验是否能出货(非特批校验,特批跳过)
|
|
|
|
- if (ObjectUtil.isEmpty(dto.getSpecialOutbound()) || !dto.getSpecialOutbound()) {
|
|
|
|
- //数量*(1-预付比例%)*单价<=(累计收款金额-预付款金额)-已出货金额
|
|
|
|
- //预付比例-小数
|
|
|
|
- BigDecimal multiply = new BigDecimal(contract.getAdvanceRatio()).multiply(BigDecimal.valueOf(0.01));
|
|
|
|
- //剩下比例-小数
|
|
|
|
- BigDecimal subtract = BigDecimal.ONE.subtract(multiply);
|
|
|
|
- //(累计收款金额-预付款金额)-已出货金额
|
|
|
|
- BigDecimal subtract2 = contract.getSumClaimMoney().subtract(contract.getAmount().multiply(multiply)).subtract(contract.getShipmentAmount());
|
|
|
|
- for (ContractProduct productDto : productDtoList) {
|
|
|
|
- BigDecimal multiply1 = productDto.getQuantity().multiply(subtract).multiply(productDto.getPrice());
|
|
|
|
- if (multiply1.compareTo(subtract2) > 0) {
|
|
|
|
- throw new ServiceException(String.format("收款金额不满足出货条件,至少需再收款%s %s 才能出货!", contract.getCurrency(), multiply1.subtract(subtract2)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
//生成待出库数据
|
|
//生成待出库数据
|
|
StockWait stockWait = new StockWait();
|
|
StockWait stockWait = new StockWait();
|
|
@@ -3109,30 +3129,48 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
stockWait.setType(2);
|
|
stockWait.setType(2);
|
|
stockWait.setBusinessCode(contract.getCode());
|
|
stockWait.setBusinessCode(contract.getCode());
|
|
stockWait.setBusinessType(JournalType.SALE_OUT.getDetailType());
|
|
stockWait.setBusinessType(JournalType.SALE_OUT.getDetailType());
|
|
- stockWait.setBusinessId(id);
|
|
|
|
- stockWait.setContractId(id);
|
|
|
|
|
|
+ stockWait.setBusinessId(dto.getId());
|
|
|
|
+ stockWait.setContractId(contractId);
|
|
stockWait.setStatus(0);
|
|
stockWait.setStatus(0);
|
|
stockWaitService.save(stockWait);
|
|
stockWaitService.save(stockWait);
|
|
|
|
|
|
List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
List<StockWaitDetails> stockWaitDetailsList = new ArrayList<>();
|
|
- for (ContractProductDto contractProduct : productDtoList) {
|
|
|
|
- BigDecimal quantity = contractProduct.getQuantity();
|
|
|
|
|
|
+ for (ContractOutboundRecords outboundRecords : productDtoList) {
|
|
|
|
+ BigDecimal quantity = outboundRecords.getQuantity();
|
|
//跳过出库数量为空||出库数量为0
|
|
//跳过出库数量为空||出库数量为0
|
|
if (ObjectUtil.isEmpty(quantity) || quantity.compareTo(BigDecimal.ZERO) <= 0) {
|
|
if (ObjectUtil.isEmpty(quantity) || quantity.compareTo(BigDecimal.ZERO) <= 0) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
StockWaitDetails stockWaitDetails = new StockWaitDetails();
|
|
stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
stockWaitDetails.setStockWaitId(stockWait.getId());
|
|
- stockWaitDetails.setProductId(contractProduct.getProductId());
|
|
|
|
|
|
+ stockWaitDetails.setProductId(outboundRecords.getProductId());
|
|
stockWaitDetails.setQuantity(quantity);
|
|
stockWaitDetails.setQuantity(quantity);
|
|
stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
stockWaitDetails.setReceiptQuantity(BigDecimal.ZERO);
|
|
- stockWaitDetails.setBusinessDetailsId(contractProduct.getId());
|
|
|
|
- stockWaitDetails.setContractDetailId(contractProduct.getId());
|
|
|
|
|
|
+ stockWaitDetails.setBusinessDetailsId(outboundRecords.getId());
|
|
|
|
+ stockWaitDetails.setContractDetailId(outboundRecords.getContractProductId());
|
|
stockWaitDetailsList.add(stockWaitDetails);
|
|
stockWaitDetailsList.add(stockWaitDetails);
|
|
}
|
|
}
|
|
stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
stockWaitDetailsService.saveBatch(stockWaitDetailsList);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void createOutboundInfo(ContractOutboundInfoDto dto) {
|
|
|
|
+ Assert.notEmpty(dto.getContractId(), "合同id不能为空!");
|
|
|
|
+ contractOutboundInfoService.save(dto);
|
|
|
|
+ List<ContractOutboundRecords> outboundRecordList = dto.getOutboundRecordList();
|
|
|
|
+ for (ContractOutboundRecords records : outboundRecordList) {
|
|
|
|
+ Assert.notEmpty(records.getContractProductId(), "合同明细id不能为空!");
|
|
|
|
+ records.setContractId(records.getContractId());
|
|
|
|
+ records.setRecordId(dto.getId());
|
|
|
|
+ ContractProduct contractProduct = contractProductService.getById(records.getContractProductId());
|
|
|
|
+ Assert.notEmpty(contractProduct, "查询不到合同明细信息!");
|
|
|
|
+ records.setProductId(contractProduct.getProductId());
|
|
|
|
+ records.setPrice(contractProduct.getPrice());
|
|
|
|
+ }
|
|
|
|
+ contractOutboundRecordsService.saveBatch(outboundRecordList);
|
|
|
|
+ }
|
|
|
|
+
|
|
@DSTransactional
|
|
@DSTransactional
|
|
@Override
|
|
@Override
|
|
public void productionTermination(ContractDto dto) {
|
|
public void productionTermination(ContractDto dto) {
|