解决多单位商品的移动平均价计算的bug
This commit is contained in:
@@ -21,6 +21,8 @@ public class DepotItemVo4DetailByTypeAndMId {
|
||||
|
||||
private BigDecimal allPrice;
|
||||
|
||||
private String materialUnit;
|
||||
|
||||
private String depotName;
|
||||
|
||||
private Date otime;
|
||||
@@ -89,6 +91,14 @@ public class DepotItemVo4DetailByTypeAndMId {
|
||||
this.allPrice = allPrice;
|
||||
}
|
||||
|
||||
public String getMaterialUnit() {
|
||||
return materialUnit;
|
||||
}
|
||||
|
||||
public void setMaterialUnit(String materialUnit) {
|
||||
this.materialUnit = materialUnit;
|
||||
}
|
||||
|
||||
public String getDepotName() {
|
||||
return depotName;
|
||||
}
|
||||
|
||||
@@ -585,6 +585,7 @@ public class DepotItemService {
|
||||
BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(depotHead.getSubType())) {
|
||||
boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
|
||||
BigDecimal currentUnitPrice = materialCurrentStockMapperEx.getCurrentUnitPriceByMId(materialExtend.getMaterialId());
|
||||
currentUnitPrice = unitService.parseUnitPriceByUnit(currentUnitPrice, unitInfo, depotItem.getMaterialUnit());
|
||||
BigDecimal unitPrice = moveAvgPriceFlag? currentUnitPrice: materialExtend.getPurchaseDecimal();
|
||||
depotItem.setPurchaseUnitPrice(unitPrice);
|
||||
if(StringUtil.isNotEmpty(depotItem.getBatchNumber())) {
|
||||
@@ -1066,6 +1067,8 @@ public class DepotItemService {
|
||||
public void updateCurrentUnitPrice(DepotItem depotItem) throws Exception {
|
||||
Boolean forceFlag = systemConfigService.getForceApprovalFlag();
|
||||
Boolean inOutManageFlag = systemConfigService.getInOutManageFlag();
|
||||
//查询计量单位信息
|
||||
Unit unitInfo = materialService.findUnit(depotItem.getMaterialId());
|
||||
List<DepotItemVo4DetailByTypeAndMId> itemList = findDetailByDepotIdsAndMaterialIdList(null, forceFlag, inOutManageFlag, depotItem.getSku(),
|
||||
depotItem.getBatchNumber(), null, null, null, depotItem.getMaterialId(), null, null);
|
||||
Collections.reverse(itemList); //倒序之后变成按时间从前往后排序
|
||||
@@ -1083,7 +1086,8 @@ public class DepotItemService {
|
||||
currentAllPrice = currentAllPrice.add(basicNumber.multiply(currentUnitPrice));
|
||||
} else {
|
||||
//数量*单价 另外计算新的成本价
|
||||
currentAllPrice = currentAllPrice.add(item.getAllPrice());
|
||||
BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice(), unitInfo, item.getMaterialUnit());
|
||||
currentAllPrice = currentAllPrice.add(allPrice);
|
||||
currentNumber = currentNumber.add(basicNumber);
|
||||
if(currentNumber.compareTo(BigDecimal.ZERO)!=0) {
|
||||
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
|
||||
@@ -1095,7 +1099,8 @@ public class DepotItemService {
|
||||
//采购退货
|
||||
if(BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(item.getSubType())) {
|
||||
//数量*单价 另外计算新的成本价
|
||||
currentAllPrice = currentAllPrice.add(item.getAllPrice());
|
||||
BigDecimal allPrice = unitService.parseAllPriceByUnit(item.getAllPrice(), unitInfo, item.getMaterialUnit());
|
||||
currentAllPrice = currentAllPrice.add(allPrice);
|
||||
currentNumber = currentNumber.add(basicNumber);
|
||||
if(currentNumber.compareTo(BigDecimal.ZERO)!=0) {
|
||||
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
|
||||
|
||||
@@ -249,6 +249,46 @@ public class UnitService {
|
||||
return stock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据多单位的比例进行单价换算(保留两位小数),变大
|
||||
* @param unitPrice
|
||||
* @param unitInfo
|
||||
* @param materialUnit
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal parseUnitPriceByUnit(BigDecimal unitPrice, Unit unitInfo, String materialUnit) {
|
||||
if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
|
||||
unitPrice = unitPrice.multiply(unitInfo.getRatio());
|
||||
}
|
||||
if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
|
||||
unitPrice = unitPrice.multiply(unitInfo.getRatioTwo());
|
||||
}
|
||||
if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
|
||||
unitPrice = unitPrice.multiply(unitInfo.getRatioThree());
|
||||
}
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据多单位的比例进行总金额换算(保留两位小数),变小
|
||||
* @param allPrice
|
||||
* @param unitInfo
|
||||
* @param materialUnit
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal parseAllPriceByUnit(BigDecimal allPrice, Unit unitInfo, String materialUnit) {
|
||||
if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
|
||||
allPrice = allPrice.divide(unitInfo.getRatio(), 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
|
||||
allPrice = allPrice.divide(unitInfo.getRatioTwo(), 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
|
||||
allPrice = allPrice.divide(unitInfo.getRatioThree(), 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
return allPrice;
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int batchSetStatus(Boolean status, String ids)throws Exception {
|
||||
logService.insertLog("计量单位",
|
||||
|
||||
Reference in New Issue
Block a user