完善关联请购单中的数量计算逻辑

This commit is contained in:
jishenghua
2024-04-23 00:44:25 +08:00
parent eeec934787
commit 6fad68f20c
8 changed files with 180 additions and 38 deletions

View File

@@ -514,7 +514,7 @@ public class DepotHeadService {
BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
DepotHead dh = new DepotHead();
//获取分批操作后单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), depotHead.getType());
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), "normal", depotHead.getType());
if(batchList.size()>0) {
dh.setPurchaseStatus(BusinessConstants.PURCHASE_STATUS_SKIPING);
} else {
@@ -1004,6 +1004,11 @@ public class DepotHeadService {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
//校验是否同时录入关联请购单号和关联订单号
if(StringUtil.isNotEmpty(depotHead.getLinkNumber()) && StringUtil.isNotEmpty(depotHead.getLinkApply())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG));
}
String subType = depotHead.getSubType();
//结算账户校验
if("采购".equals(subType) || "采购退货".equals(subType) || "销售".equals(subType) || "销售退货".equals(subType)) {
@@ -1100,7 +1105,12 @@ public class DepotHeadService {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
}
//校验单据状态,如何不是未审核则提示
//校验是否同时录入关联请购单号和关联订单号
if(StringUtil.isNotEmpty(depotHead.getLinkNumber()) && StringUtil.isNotEmpty(depotHead.getLinkApply())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_CODE,
String.format(ExceptionConstants.DEPOT_ITEM_EXIST_REPEAT_NO_FAILED_MSG));
}
//校验单据状态,如果不是未审核则提示
if(!"0".equals(getDepotHead(depotHead.getId()).getStatus())) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_MSG));

View File

@@ -691,15 +691,21 @@ public class DepotItemService {
|| BusinessConstants.SUB_TYPE_OTHER.equals(depotHead.getSubType())) {
if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
//单据状态:是否全部完成 2-全部完成 3-部分完成(针对订单的分批出入库)
String billStatus = getBillStatusByParam(depotHead);
changeBillStatus(depotHead, billStatus);
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
changeBillStatus(depotHead.getLinkNumber(), billStatus);
}
}
//如果关联单据号非空则更新订单的状态,此处针对销售订单转采购订单的场景
//当前单据类型为采购订单的逻辑
if(BusinessConstants.SUB_TYPE_PURCHASE_ORDER.equals(depotHead.getSubType())) {
//如果关联单据号非空则更新订单的状态,此处针对销售订单转采购订单的场景
if(StringUtil.isNotEmpty(depotHead.getLinkNumber())) {
String billStatus = getBillStatusByParam(depotHead);
changeBillPurchaseStatus(depotHead, billStatus);
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkNumber(), "normal");
changeBillPurchaseStatus(depotHead.getLinkNumber(), billStatus);
}
//如果关联单据号非空则更新订单的状态,此处针对请购单转采购订单的场景
if(StringUtil.isNotEmpty(depotHead.getLinkApply())) {
String billStatus = getBillStatusByParam(depotHead, depotHead.getLinkApply(), "apply");
changeBillStatus(depotHead.getLinkApply(), billStatus);
}
}
} else {
@@ -711,15 +717,16 @@ public class DepotItemService {
* 判断单据的状态
* 通过数组对比:原单据的商品和商品数量(汇总) 与 分批操作后单据的商品和商品数量(汇总)
* @param depotHead
* @param linkStr
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String getBillStatusByParam(DepotHead depotHead) {
public String getBillStatusByParam(DepotHead depotHead, String linkStr, String linkType) {
String res = BusinessConstants.BILLS_STATUS_SKIPED;
//获取原单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(depotHead.getLinkNumber());
List<DepotItemVo4MaterialAndSum> linkList = depotItemMapperEx.getLinkBillDetailMaterialSum(linkStr);
//获取分批操作后单据的商品和商品数量(汇总)
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(depotHead.getLinkNumber(), depotHead.getType());
List<DepotItemVo4MaterialAndSum> batchList = depotItemMapperEx.getBatchBillDetailMaterialSum(linkStr, linkType, depotHead.getType());
//将分批操作后的单据的商品和商品数据构造成Map
Map<Long, BigDecimal> materialSumMap = new HashMap<>();
for(DepotItemVo4MaterialAndSum materialAndSum : batchList) {
@@ -743,16 +750,16 @@ public class DepotItemService {
/**
* 更新单据状态
* @param depotHead
* @param linkStr
* @param billStatus
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void changeBillStatus(DepotHead depotHead, String billStatus) {
public void changeBillStatus(String linkStr, String billStatus) {
DepotHead depotHeadOrders = new DepotHead();
depotHeadOrders.setStatus(billStatus);
DepotHeadExample example = new DepotHeadExample();
List<String> linkNumberList = StringUtil.strToStringList(depotHead.getLinkNumber());
example.createCriteria().andNumberIn(linkNumberList);
List<String> linkNoList = StringUtil.strToStringList(linkStr);
example.createCriteria().andNumberIn(linkNoList);
try{
depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
}catch(Exception e){
@@ -765,16 +772,16 @@ public class DepotItemService {
/**
* 更新单据状态,此处针对销售订单转采购订单的场景
* @param depotHead
* @param linkStr
* @param billStatus
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void changeBillPurchaseStatus(DepotHead depotHead, String billStatus) {
public void changeBillPurchaseStatus(String linkStr, String billStatus) {
DepotHead depotHeadOrders = new DepotHead();
depotHeadOrders.setPurchaseStatus(billStatus);
DepotHeadExample example = new DepotHeadExample();
List<String> linkNumberList = StringUtil.strToStringList(depotHead.getLinkNumber());
example.createCriteria().andNumberIn(linkNumberList);
List<String> linkNoList = StringUtil.strToStringList(linkStr);
example.createCriteria().andNumberIn(linkNoList);
try{
depotHeadMapper.updateByExampleSelective(depotHeadOrders, example);
}catch(Exception e){
@@ -1085,7 +1092,7 @@ public class DepotItemService {
Long linkId = id;
String goToType = "";
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
String linkNumber = depotHead.getNumber(); //订单号
String linkStr = depotHead.getNumber(); //订单号
if("purchase".equals(linkType)) {
//针对以销定购的情况
if(BusinessConstants.SUB_TYPE_SALES_ORDER.equals(depotHead.getSubType())) {
@@ -1117,7 +1124,11 @@ public class DepotItemService {
goToType = BusinessConstants.SUB_TYPE_SALES_RETURN;
}
}
BigDecimal count = depotItemMapperEx.getFinishNumber(meId, linkId, linkNumber, goToType);
String noType = "normal";
if(linkStr.contains("QGD")) {
noType = "apply";
}
BigDecimal count = depotItemMapperEx.getFinishNumber(meId, linkId, linkStr, noType, goToType);
//根据多单位情况进行数量的转换
if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
@@ -1146,8 +1157,12 @@ public class DepotItemService {
public BigDecimal getRealFinishNumber(String currentSubType, Long meId, Long linkId, Long preHeaderId, Long currentHeaderId, Unit unitInfo, String materialUnit) {
String goToType = currentSubType;
DepotHead depotHead =depotHeadMapper.selectByPrimaryKey(preHeaderId);
String linkNumber = depotHead.getNumber(); //订单号
BigDecimal count = depotItemMapperEx.getRealFinishNumber(meId, linkId, linkNumber, currentHeaderId, goToType);
String linkStr = depotHead.getNumber(); //订单号
String linkType = "normal";
if(linkStr.contains("QGD")) {
linkType = "apply";
}
BigDecimal count = depotItemMapperEx.getRealFinishNumber(meId, linkId, linkStr, linkType, currentHeaderId, goToType);
//根据多单位情况进行数量的转换
if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
count = count.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);