完善单据保存中增加更新成本价的逻辑
This commit is contained in:
@@ -1065,16 +1065,33 @@ public class DepotItemService {
|
|||||||
for(DepotItemVo4DetailByTypeAndMId item: itemList) {
|
for(DepotItemVo4DetailByTypeAndMId item: itemList) {
|
||||||
//入库
|
//入库
|
||||||
if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) {
|
if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(item.getType())) {
|
||||||
currentAllPrice = currentAllPrice.add(item.getAllPrice());
|
//零售退货、销售退货
|
||||||
currentNumber = currentNumber.add(item.getBnum());
|
if(BusinessConstants.SUB_TYPE_RETAIL_RETURN.equals(item.getSubType())||BusinessConstants.SUB_TYPE_SALES_RETURN.equals(item.getSubType())) {
|
||||||
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
|
//数量*当前的成本单价
|
||||||
|
currentNumber = currentNumber.add(item.getBnum());
|
||||||
|
BigDecimal inNum = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO;
|
||||||
|
currentAllPrice = currentAllPrice.add(inNum.multiply(currentUnitPrice));
|
||||||
|
} else {
|
||||||
|
//数量*单价 另外计算新的成本价
|
||||||
|
currentAllPrice = currentAllPrice.add(item.getAllPrice());
|
||||||
|
currentNumber = currentNumber.add(item.getBnum());
|
||||||
|
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//出库
|
//出库
|
||||||
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) {
|
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(item.getType())) {
|
||||||
currentNumber = currentNumber.add(item.getBnum());
|
//采购退货
|
||||||
BigDecimal outNum = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO;
|
if(BusinessConstants.SUB_TYPE_PURCHASE_RETURN.equals(item.getSubType())) {
|
||||||
//出库的数量*当前的成本单价
|
//数量*单价 另外计算新的成本价
|
||||||
currentAllPrice = currentAllPrice.add(outNum.multiply(currentUnitPrice));
|
currentAllPrice = currentAllPrice.add(item.getAllPrice());
|
||||||
|
currentNumber = currentNumber.add(item.getBnum());
|
||||||
|
currentUnitPrice = currentAllPrice.divide(currentNumber, 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
} else {
|
||||||
|
currentNumber = currentNumber.add(item.getBnum());
|
||||||
|
BigDecimal outNum = item.getBnum()!=null?item.getBnum():BigDecimal.ZERO;
|
||||||
|
//数量*当前的成本单价
|
||||||
|
currentAllPrice = currentAllPrice.add(outNum.multiply(currentUnitPrice));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//更新实时库存中的当前单价
|
//更新实时库存中的当前单价
|
||||||
|
|||||||
@@ -145,7 +145,8 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findDetailByDepotIdsAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
|
<select id="findDetailByDepotIdsAndMaterialIdList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="DetailByTypeAndMIdResultMap">
|
||||||
select tb.* from
|
select tb.number, tb.bar_code, tb.material_name, tb.type, tb.sub_type, tb.b_num, tb.unit_price,
|
||||||
|
tb.b_num*tb.unit_price as all_price, tb.depotName, tb.oTime from
|
||||||
(select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
|
(select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
|
||||||
case
|
case
|
||||||
when type='入库' then ifnull(di.basic_number,0)
|
when type='入库' then ifnull(di.basic_number,0)
|
||||||
@@ -157,7 +158,7 @@
|
|||||||
when dh.sub_type='盘点复盘' then ifnull(di.basic_number,0)
|
when dh.sub_type='盘点复盘' then ifnull(di.basic_number,0)
|
||||||
else 0
|
else 0
|
||||||
end
|
end
|
||||||
as b_num, di.unit_price, di.all_price,
|
as b_num, di.unit_price,
|
||||||
(select name from jsh_depot d where d.id=di.depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
|
(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
|
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
|
||||||
from jsh_depot_head dh
|
from jsh_depot_head dh
|
||||||
@@ -200,7 +201,7 @@
|
|||||||
union all
|
union all
|
||||||
--单独构造记录:调拨入库
|
--单独构造记录:调拨入库
|
||||||
select dh.number,me.bar_code,m.name material_name,dh.type,dh.sub_type,
|
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, di.all_price,
|
ifnull(di.basic_number,0) as b_num, di.unit_price,
|
||||||
(select concat(name,'[调入]') from jsh_depot d where d.id=di.another_depot_id and ifnull(d.delete_flag,'0') !='1') as depotName,
|
(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
|
date_format(dh.oper_time,'%Y-%m-%d %H:%i:%S') as oTime
|
||||||
from jsh_depot_head dh
|
from jsh_depot_head dh
|
||||||
|
|||||||
Reference in New Issue
Block a user