库存扣减,根据包装单位自动计算
This commit is contained in:
1 parent
2a75f136af
commit
8f809fdea7
4 files changed
+24
-17
No files matched your search
+1
-1
@@ -45,7 +45,7 @@ public class SupermarketSpuUpdateStockReqDTO {
|
||||
* 负数:扣减库存
|
||||
*/
|
||||
@NotNull(message = "库存变化数量不能为空")
|
||||
private Integer incrCount;
|
||||
private Double incrCount;
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class UpdateStockDTO {
|
||||
* 负数:扣减库存
|
||||
*/
|
||||
@NotNull(message = "库存变化数量不能为空")
|
||||
private Integer incrCount;
|
||||
private Double incrCount;
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class SmErpInventoryRecordsItemEntity extends Model<SmErpInventoryRecords
|
||||
* 出入库数量
|
||||
*/
|
||||
@Schema(description="出入库数量")
|
||||
private Integer quantity;
|
||||
private Double quantity;
|
||||
|
||||
/**
|
||||
* 单价
|
||||
|
||||
+21
-14
@@ -234,8 +234,23 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
@Transactional
|
||||
public R updateSpuStock(SupermarketSpuUpdateStockReqDTO updateStockReqDTO) {
|
||||
List<UpdateStockDTO> updateStockDTOS = new ArrayList<UpdateStockDTO>();
|
||||
//出库主表数据
|
||||
SmErpInventoryRecordsEntity smErpInventoryRecordsEntity = new SmErpInventoryRecordsEntity();
|
||||
String s = sequence.nextNo();
|
||||
String result = InventoryTypeEnum.LSCK.getValue() + "-" + s;
|
||||
smErpInventoryRecordsEntity.setInventoryCode(result);
|
||||
smErpInventoryRecordsEntity.setInventoryDate(LocalDate.now());
|
||||
smErpInventoryRecordsEntity.setInventoryType(InventoryTypeEnum.LSCK.getType());
|
||||
smErpInventoryRecordsEntity.setOrderType(OrderTypeEnum.CK.getType());
|
||||
smErpInventoryRecordsEntity.setDeviceType(updateStockReqDTO.getDeviceType());
|
||||
//生成出入库记录
|
||||
smErpInventoryRecordsMapper.insert(smErpInventoryRecordsEntity);
|
||||
List<SmErpInventoryRecordsItemEntity> smErpInventoryRecordsItemEntityList = new ArrayList<>();
|
||||
|
||||
for (SupermarketSpuUpdateStockReqDTO.Item v : updateStockReqDTO.getItems()) {
|
||||
SmErpUnitEntity smErpUnitEntity = smErpUnitService.getById(v.getId());
|
||||
//计算包装单位实际需要扣减的库存
|
||||
Double incrCount = (smErpUnitEntity.getPackageNum()) * v.getIncrCount();
|
||||
// 查询当前库存
|
||||
Long spuId = smErpUnitEntity.getSpuId();
|
||||
SmErpSpuEntity spu = baseMapper.selectById(spuId);
|
||||
@@ -251,36 +266,28 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
|
||||
|
||||
|
||||
// 检查库存是否足够
|
||||
if (v.getIncrCount() < 0 && Math.abs(v.getIncrCount()) > smErpStockEntity.getCurrentStock()) {
|
||||
if (incrCount < 0 && Math.abs(incrCount) > smErpStockEntity.getCurrentStock()) {
|
||||
return R.failed(spu.getProductName() + "库存不足,无法完成操作");
|
||||
}
|
||||
|
||||
UpdateStockDTO updateStockDTO = new UpdateStockDTO(spuId, v.getIncrCount());
|
||||
UpdateStockDTO updateStockDTO = new UpdateStockDTO(spuId, incrCount);
|
||||
updateStockDTOS.add(updateStockDTO);
|
||||
smErpStockService.updateStock(updateStockDTOS);
|
||||
|
||||
//todo 生成出入库记录
|
||||
SmErpInventoryRecordsEntity smErpInventoryRecordsEntity = new SmErpInventoryRecordsEntity();
|
||||
String s = sequence.nextNo();
|
||||
String result = InventoryTypeEnum.LSCK.getValue() + "-" + s;
|
||||
smErpInventoryRecordsEntity.setInventoryCode(result);
|
||||
smErpInventoryRecordsEntity.setInventoryDate(LocalDate.now());
|
||||
smErpInventoryRecordsEntity.setInventoryType(InventoryTypeEnum.LSCK.getType());
|
||||
smErpInventoryRecordsEntity.setOrderType(OrderTypeEnum.CK.getType());
|
||||
smErpInventoryRecordsEntity.setDeviceType(updateStockReqDTO.getDeviceType());
|
||||
smErpInventoryRecordsMapper.insert(smErpInventoryRecordsEntity);
|
||||
//生成出入库记录
|
||||
SmErpInventoryRecordsItemEntity smErpInventoryRecordsItemEntity = new SmErpInventoryRecordsItemEntity();
|
||||
smErpInventoryRecordsItemEntity.setInventoryId(smErpInventoryRecordsEntity.getId());
|
||||
smErpInventoryRecordsItemEntity.setErpSpuId(spuId);
|
||||
smErpInventoryRecordsItemEntity.setQuantity(v.getIncrCount());
|
||||
smErpInventoryRecordsItemEntity.setQuantity(incrCount);
|
||||
smErpInventoryRecordsItemEntity.setUnitId(v.getId());
|
||||
smErpInventoryRecordsItemEntity.setOrderType(OrderTypeEnum.CK.getType());
|
||||
//todo 添加收款金额字段和会员卡号,用于记录零售业务
|
||||
smErpInventoryRecordsItemEntity.setUnitPrice
|
||||
(smErpUnitEntity.getPromotionPrice()==null || smErpUnitEntity.getPromotionPrice()==0
|
||||
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
|
||||
smErpInventoryRecordsItemMapper.insert(smErpInventoryRecordsItemEntity);
|
||||
smErpInventoryRecordsItemEntityList.add(smErpInventoryRecordsItemEntity);
|
||||
}
|
||||
smErpInventoryRecordsItemMapper.insert(smErpInventoryRecordsItemEntityList);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user