解决商品库存报表的单价为负数的问题
This commit is contained in:
@@ -336,31 +336,20 @@ public class DepotItemController {
|
||||
BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true));
|
||||
BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
|
||||
BigDecimal OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
|
||||
BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true));
|
||||
BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
|
||||
BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
|
||||
item.put("MaterialName", diEx.getMName());
|
||||
item.put("MaterialModel", diEx.getMModel());
|
||||
//扩展信息
|
||||
String materialOther = getOtherInfo(mpArr, diEx);
|
||||
item.put("MaterialOther", materialOther);
|
||||
item.put("MaterialColor", diEx.getMColor());
|
||||
item.put("MaterialUnit", diEx.getMaterialUnit());
|
||||
BigDecimal unitPrice = BigDecimal.ZERO;
|
||||
if ((prevSum .add(InSum).subtract(OutSum)).compareTo(BigDecimal.ZERO)!= 0) {
|
||||
unitPrice = (prevPrice.add(InPrice).subtract(OutPrice)).divide(prevSum.add(InSum).subtract(OutSum),2, BigDecimal.ROUND_HALF_UP);
|
||||
/**
|
||||
* 2019-01-15通过除法算出金额后,保留两位小数
|
||||
* */
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
unitPrice= new BigDecimal(df.format(unitPrice));
|
||||
}
|
||||
item.put("UnitPrice", unitPrice);
|
||||
item.put("unitName", getUName(diEx.getMaterialUnit(), diEx.getUName()));
|
||||
item.put("UnitPrice", getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy()));
|
||||
item.put("prevSum", prevSum);
|
||||
item.put("InSum", InSum);
|
||||
item.put("OutSum", OutSum);
|
||||
item.put("thisSum", prevSum.add(InSum).subtract(OutSum));
|
||||
item.put("thisAllPrice", prevPrice.add(InPrice).subtract(OutPrice));
|
||||
BigDecimal thisSum = prevSum.add(InSum).subtract(OutSum);
|
||||
item.put("thisSum", thisSum);
|
||||
item.put("thisAllPrice", thisSum.multiply(getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy())));
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
@@ -690,6 +679,47 @@ public class DepotItemController {
|
||||
}
|
||||
return sumPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单位
|
||||
* @param materialUnit
|
||||
* @param uName
|
||||
* @return
|
||||
*/
|
||||
public String getUName(String materialUnit, String uName) {
|
||||
String unitName = null;
|
||||
if(!StringUtil.isEmpty(materialUnit)) {
|
||||
unitName = materialUnit;
|
||||
} else if(!StringUtil.isEmpty(uName)) {
|
||||
unitName = uName.substring(0,uName.indexOf(","));
|
||||
}
|
||||
return unitName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单价
|
||||
* @param presetPriceOne
|
||||
* @param priceStrategy
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getUnitPrice(BigDecimal presetPriceOne, String priceStrategy) {
|
||||
BigDecimal unitPrice = BigDecimal.ZERO;
|
||||
if(presetPriceOne != null) {
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
unitPrice = new BigDecimal(df.format(presetPriceOne));
|
||||
} else {
|
||||
JSONArray priceArr = JSONArray.parseArray(priceStrategy);
|
||||
if(priceArr!=null && priceArr.get(0)!=null) {
|
||||
JSONObject priceObj = JSONObject.parseObject(priceArr.get(0).toString());
|
||||
BigDecimal basicPresetPriceOne = priceObj.getJSONObject("basic").getBigDecimal("PresetPriceOne");
|
||||
if(basicPresetPriceOne!=null) {
|
||||
unitPrice = basicPresetPriceOne;
|
||||
}
|
||||
}
|
||||
}
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* create by: qiankunpingtai
|
||||
* website:https://qiankunpingtai.cn
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class DepotItemVo4WithInfoEx extends DepotItem{
|
||||
|
||||
private Long MId;
|
||||
@@ -30,6 +32,10 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
|
||||
|
||||
private String UName;
|
||||
|
||||
private BigDecimal presetPriceOne;
|
||||
|
||||
private String priceStrategy;
|
||||
|
||||
public Long getMId() {
|
||||
return MId;
|
||||
}
|
||||
@@ -141,4 +147,20 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
|
||||
public void setUName(String UName) {
|
||||
this.UName = UName;
|
||||
}
|
||||
|
||||
public BigDecimal getPresetPriceOne() {
|
||||
return presetPriceOne;
|
||||
}
|
||||
|
||||
public void setPresetPriceOne(BigDecimal presetPriceOne) {
|
||||
this.presetPriceOne = presetPriceOne;
|
||||
}
|
||||
|
||||
public String getPriceStrategy() {
|
||||
return priceStrategy;
|
||||
}
|
||||
|
||||
public void setPriceStrategy(String priceStrategy) {
|
||||
this.priceStrategy = priceStrategy;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,10 @@
|
||||
<result column="MName" jdbcType="VARCHAR" property="MName" />
|
||||
<result column="MModel" jdbcType="VARCHAR" property="MModel" />
|
||||
<result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
|
||||
<result column="UName" jdbcType="VARCHAR" property="UName" />
|
||||
<result column="MColor" jdbcType="VARCHAR" property="MColor" />
|
||||
<result column="PresetPriceOne" jdbcType="DECIMAL" property="presetPriceOne" />
|
||||
<result column="PriceStrategy" jdbcType="VARCHAR" property="priceStrategy" />
|
||||
</resultMap>
|
||||
<resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount">
|
||||
<result column="MaterialName" jdbcType="VARCHAR" property="MaterialName" />
|
||||
@@ -180,9 +183,11 @@
|
||||
</select>
|
||||
|
||||
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial">
|
||||
select m.id MId, m.Name MName, m.Model MModel, m.Unit MaterialUnit, m.Color MColor
|
||||
select m.id MId, m.Name MName, m.Model MModel, m.Unit MaterialUnit, m.Color MColor,
|
||||
m.PresetPriceOne, m.PriceStrategy, u.UName UName
|
||||
from jsh_depotitem di
|
||||
inner join jsh_material m on di.MaterialId=m.id and ifnull(m.delete_Flag,'0') !='1'
|
||||
left join jsh_unit u on m.UnitId=u.id and ifnull(u.delete_Flag,'0') !='1'
|
||||
where 1=1
|
||||
<if test="headIds != null">
|
||||
and di.HeaderId in (${headIds})
|
||||
@@ -191,7 +196,7 @@
|
||||
and di.MaterialId in (${materialIds})
|
||||
</if>
|
||||
and ifnull(di.delete_Flag,'0') !='1'
|
||||
group by m.id,m.Name, m.Model, m.Unit, m.Color
|
||||
group by m.id,m.Name, m.Model, m.Unit, m.Color, m.PresetPriceOne, m.PriceStrategy, u.UName
|
||||
<if test="offset != null and rows != null">
|
||||
limit #{offset},#{rows}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user