解决多单位商品的移动平均价计算的bug
This commit is contained in:
parent
4442ad7d26
commit
8bbf79c613
@ -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("计量单位",
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
<result column="b_num" jdbcType="DECIMAL" property="bnum" />
|
||||
<result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
|
||||
<result column="all_price" jdbcType="DECIMAL" property="allPrice" />
|
||||
<result column="material_unit" jdbcType="VARCHAR" property="materialUnit" />
|
||||
<result column="depotName" jdbcType="VARCHAR" property="depotName" />
|
||||
<result column="oTime" jdbcType="TIMESTAMP" property="otime" />
|
||||
</resultMap>
|
||||
@ -147,7 +148,7 @@
|
||||
|
||||
<select id="findDetailByDepotIdsAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
|
||||
select tb.number, tb.bar_code, tb.material_name, tb.type, tb.sub_type, tb.b_num, tb.unit_price,
|
||||
ifnull(tb.b_num*tb.unit_price,0) as all_price, tb.depotName, tb.oTime from
|
||||
ifnull(tb.b_num*tb.unit_price,0) as all_price, tb.material_unit, tb.depotName, tb.oTime from
|
||||
(select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
|
||||
case
|
||||
when type='入库' then ifnull(di.basic_number,0)
|
||||
@ -159,7 +160,7 @@
|
||||
when dh.sub_type='盘点复盘' then ifnull(di.basic_number,0)
|
||||
else 0
|
||||
end
|
||||
as b_num, di.unit_price,
|
||||
as b_num, di.unit_price, di.material_unit,
|
||||
(select name from jsh_depot d where d.id=di.depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
|
||||
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
|
||||
from jsh_depot_head dh
|
||||
@ -202,7 +203,7 @@
|
||||
union all
|
||||
--单独构造记录:调拨入库
|
||||
select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
|
||||
ifnull(di.basic_number,0) as b_num, di.unit_price,
|
||||
ifnull(di.basic_number,0) as b_num, di.unit_price, di.material_unit,
|
||||
(select concat(name,'[调入]') from jsh_depot d where d.id=di.another_depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
|
||||
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
|
||||
from jsh_depot_head dh
|
||||
|
||||
Loading…
Reference in New Issue
Block a user