|
@@ -54,6 +54,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -148,12 +149,6 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
.setWhId(outboundItemVO.getWhId())
|
|
.setWhId(outboundItemVO.getWhId())
|
|
|
.setNonStdCode(outboundItemVO.getNonStdCode()));
|
|
.setNonStdCode(outboundItemVO.getNonStdCode()));
|
|
|
}
|
|
}
|
|
|
- //库存不存在
|
|
|
|
|
- if(inventoryResponse ==null){
|
|
|
|
|
- //当前出库商品中在库存中不存在
|
|
|
|
|
- throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
|
|
|
|
|
- ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
return inventoryResponse;
|
|
return inventoryResponse;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -193,19 +188,34 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
if(outboundItemVO.getSkuId()!=null){
|
|
if(outboundItemVO.getSkuId()!=null){
|
|
|
//查询库存是否存在
|
|
//查询库存是否存在
|
|
|
InventoryResponse inventoryResponse = this.checkInventoryExist(outboundItemVO);
|
|
InventoryResponse inventoryResponse = this.checkInventoryExist(outboundItemVO);
|
|
|
- BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
|
|
|
|
|
- // (库存量 大于等于 本次出库数量不用做任何处理)
|
|
|
|
|
- //库存量 小于 本次出库数量
|
|
|
|
|
- if (invQty.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
- outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
|
|
|
|
|
|
|
+ if (inventoryResponse != null) {
|
|
|
|
|
+ BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
|
|
|
|
|
+ // (库存量 大于等于 本次出库数量不用做任何处理)
|
|
|
|
|
+ //库存量 小于 本次出库数量
|
|
|
|
|
+ if (invQty.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
+ outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
|
|
|
|
|
+ //不够库存数量----新建出库中数量
|
|
|
|
|
+ outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
//不够库存数量----新建出库中数量
|
|
//不够库存数量----新建出库中数量
|
|
|
- outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
|
|
|
|
|
|
|
+ outboundItemVO.setNotEnoughInventoryQty(outboundItemVO.getOutingQty());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ //过滤出库存量足够的数据
|
|
|
|
|
+ List<OutboundItemVO> itemList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()==null ).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
//region 过滤出不够出库的每条明细数量 ------新建出库中数据
|
|
//region 过滤出不够出库的每条明细数量 ------新建出库中数据
|
|
|
List<OutboundItemVO> outboundIngList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()!=null && it.getNotEnoughInventoryQty().compareTo(BigDecimal.ZERO)>0).collect(Collectors.toList());
|
|
List<OutboundItemVO> outboundIngList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()!=null && it.getNotEnoughInventoryQty().compareTo(BigDecimal.ZERO)>0).collect(Collectors.toList());
|
|
|
if(outboundIngList != null && outboundIngList.size()>0){
|
|
if(outboundIngList != null && outboundIngList.size()>0){
|
|
|
|
|
+ //赋值箱片
|
|
|
|
|
+ for (OutboundItemVO outboundItemVO : outboundIngList) {
|
|
|
|
|
+ //箱
|
|
|
|
|
+ outboundItemVO.setOutingBox(Integer.valueOf(outboundItemVO.getOutingQty().divide(outboundItemVO.getPackBox(),RoundingMode.DOWN).toString()) );
|
|
|
|
|
+ //片
|
|
|
|
|
+ outboundItemVO.setOutingPiece(outboundItemVO.getOutingQty().remainder(outboundItemVO.getPackBox()));
|
|
|
|
|
+ }
|
|
|
outboundVO.setFlgAutoHandle(false);
|
|
outboundVO.setFlgAutoHandle(false);
|
|
|
outboundVO.setItemList(outboundIngList);
|
|
outboundVO.setItemList(outboundIngList);
|
|
|
//销售出库新建
|
|
//销售出库新建
|
|
@@ -215,8 +225,21 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
|
|
|
|
|
//region 库存够扣减的明细 -----------新建已出库数据并扣减库存
|
|
//region 库存够扣减的明细 -----------新建已出库数据并扣减库存
|
|
|
//销售出库新建
|
|
//销售出库新建
|
|
|
- this.saleOrderOutboundInsert(outboundVO,true);
|
|
|
|
|
|
|
+ if (itemList!=null && itemList.size() > 0) {
|
|
|
|
|
+ for (OutboundItemVO outboundItemVO : itemList) {
|
|
|
|
|
+ if(outboundItemVO.getSkuId()!=null){ //过滤外协品 外协品没有箱片
|
|
|
|
|
+ //箱
|
|
|
|
|
+ outboundItemVO.setOutBox(Integer.valueOf(outboundItemVO.getOutingQty().divide(outboundItemVO.getPackBox(),RoundingMode.DOWN).toString()) );
|
|
|
|
|
+ //片
|
|
|
|
|
+ outboundItemVO.setOutPiece(outboundItemVO.getOutingQty().remainder(outboundItemVO.getPackBox()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ outboundVO.setFlgAutoHandle(true);
|
|
|
|
|
+ outboundVO.setItemList(itemList);
|
|
|
|
|
+ this.saleOrderOutboundInsert(outboundVO, true);
|
|
|
|
|
+ }
|
|
|
//endregion
|
|
//endregion
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
/*****************************************先判断库存*****************************************/
|
|
/*****************************************先判断库存*****************************************/
|
|
@@ -297,6 +320,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
inboundVO.setMakeStaff(outboundVO.getMakeStaff());
|
|
inboundVO.setMakeStaff(outboundVO.getMakeStaff());
|
|
|
//公司
|
|
//公司
|
|
|
inboundVO.setCpId(outboundVO.getCpId());
|
|
inboundVO.setCpId(outboundVO.getCpId());
|
|
|
|
|
+ // 来源Id
|
|
|
|
|
+ inboundVO.setFromId(outboundVO.getFromId());
|
|
|
|
|
+ inboundVO.setFromNo(outboundVO.getFromNo());
|
|
|
//实体转换
|
|
//实体转换
|
|
|
Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
Inbound inbound = inboundConvert.convertToPo(inboundVO);
|
|
|
inboundMapper.insert(inbound);
|
|
inboundMapper.insert(inbound);
|
|
@@ -311,14 +337,18 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
//入库类型
|
|
//入库类型
|
|
|
inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
inboundItemVO.setIntoType(inboundVO.getIntoType());
|
|
|
//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
//入库状态等于已入库 更新合计入库数量/金额 = 入库中数量/入库中金额
|
|
|
|
|
+ BigDecimal costAmount = outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
inboundItemVO
|
|
inboundItemVO
|
|
|
|
|
+ .setFromId(outboundItemVO.getFromId())
|
|
|
|
|
+ .setFromItemId(outboundItemVO.getFromItemId())
|
|
|
.setPriceInto(outboundItemVO.getPriceOut())
|
|
.setPriceInto(outboundItemVO.getPriceOut())
|
|
|
.setIntoQty(outboundItemVO.getOutQty())
|
|
.setIntoQty(outboundItemVO.getOutQty())
|
|
|
- .setIntoAmt(outboundItemVO.getOutQty())
|
|
|
|
|
|
|
+ .setIntoAmt(outboundItemVO.getOutAmt())
|
|
|
|
|
+ .setIntoAmt(costAmount)
|
|
|
.setIntoingQty(BigDecimal.ZERO)
|
|
.setIntoingQty(BigDecimal.ZERO)
|
|
|
.setIntoingAmt(BigDecimal.ZERO)
|
|
.setIntoingAmt(BigDecimal.ZERO)
|
|
|
.setCostPrice(outboundItemVO.getPriceOut())
|
|
.setCostPrice(outboundItemVO.getPriceOut())
|
|
|
- .setCostAmt(outboundItemVO.getOutQty().multiply(outboundItemVO.getPriceOut()).setScale(2, BigDecimal.ROUND_HALF_UP))
|
|
|
|
|
|
|
+ .setCostAmt(costAmount)
|
|
|
;
|
|
;
|
|
|
//入库状态
|
|
//入库状态
|
|
|
inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
inboundItemVO.setIntoStatus(inboundVO.getIntoStatus());
|
|
@@ -339,6 +369,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
// 商品
|
|
// 商品
|
|
|
inboundItemVO.setSkuModel(outboundItemVO.getSkuModel());
|
|
inboundItemVO.setSkuModel(outboundItemVO.getSkuModel());
|
|
|
inboundItemVO.setSkuName(outboundItemVO.getSkuName());
|
|
inboundItemVO.setSkuName(outboundItemVO.getSkuName());
|
|
|
|
|
+ // 来源Id
|
|
|
//实体转换
|
|
//实体转换
|
|
|
InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
inboundItemMapper.insert(inboundItem);
|
|
inboundItemMapper.insert(inboundItem);
|
|
@@ -383,6 +414,14 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
//endregion
|
|
//endregion
|
|
|
|
|
|
|
|
//region 总单
|
|
//region 总单
|
|
|
|
|
+ //出库数量
|
|
|
|
|
+ BigDecimal sumIntoQty = BigDecimal.ZERO;
|
|
|
|
|
+ //出库金额
|
|
|
|
|
+ BigDecimal sumIntoPriceAmt = BigDecimal.ZERO;
|
|
|
|
|
+ if(orderTransmitFlag){
|
|
|
|
|
+ sumIntoQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ sumIntoPriceAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getPriceOut).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
+ }
|
|
|
//获取 id/单号
|
|
//获取 id/单号
|
|
|
Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
|
|
Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
|
|
|
outboundVO.setOutId(codeMap.get("outId").toString()).
|
|
outboundVO.setOutId(codeMap.get("outId").toString()).
|
|
@@ -400,8 +439,8 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
//出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
|
|
//出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
|
|
|
if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
|
|
if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
|
|
|
outboundVO
|
|
outboundVO
|
|
|
- .setOutQty(outboundVO.getOutingQty())
|
|
|
|
|
- .setOutAmt(outboundVO.getOutingAmt())
|
|
|
|
|
|
|
+ .setOutQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
|
|
|
|
|
+ .setOutAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
|
|
|
.setOutingQty(BigDecimal.ZERO)
|
|
.setOutingQty(BigDecimal.ZERO)
|
|
|
.setOutingAmt(BigDecimal.ZERO)
|
|
.setOutingAmt(BigDecimal.ZERO)
|
|
|
;
|
|
;
|
|
@@ -409,6 +448,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
outboundVO
|
|
outboundVO
|
|
|
.setOutQty(BigDecimal.ZERO)
|
|
.setOutQty(BigDecimal.ZERO)
|
|
|
.setOutAmt(BigDecimal.ZERO)
|
|
.setOutAmt(BigDecimal.ZERO)
|
|
|
|
|
+ //用于销售订单自动创建出库单
|
|
|
|
|
+ .setOutingQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
|
|
|
|
|
+ .setOutingAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
|
|
|
;
|
|
;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -462,7 +504,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
|
|
|
ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
|
|
ErrorCodeEnum.OUTBOUND_ITEM_NOT_EXIST.getMessage());
|
|
|
}
|
|
}
|
|
|
for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
for (OutboundItemVO outboundItemVO : outboundVO.getItemList()) {
|
|
|
-
|
|
|
|
|
|
|
+ outboundItemVO.setItemId(null );
|
|
|
//region 将库存需要的参数赋值
|
|
//region 将库存需要的参数赋值
|
|
|
outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
|
|
outboundItemVO.setInventoryType(Constant.InventoryType.OUTBOUND.getName());
|
|
|
outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
|
|
outboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.SALE_ORDER.getValue());
|