解决商品库存报表的单价为负数的问题

This commit is contained in:
季圣华
2019-08-13 00:07:27 +08:00
parent 0a0f346931
commit f8781f36ed
4 changed files with 78 additions and 30 deletions

View File

@@ -218,22 +218,13 @@
{title: '名称', field: 'MaterialName', width: 60}, {title: '名称', field: 'MaterialName', width: 60},
{title: '型号', field: 'MaterialModel', width: 80}, {title: '型号', field: 'MaterialModel', width: 80},
{title: '扩展信息', field: 'MaterialOther', width: 150}, {title: '扩展信息', field: 'MaterialOther', width: 150},
{title: '单位', field: 'MaterialUnit', width: 80}, {title: '单位', field: 'unitName', width: 80},
{ {title: '单价', field: 'UnitPrice', width: 60},
title: '单价', field: 'UnitPrice', width: 60, formatter: function (value, row, index) {
return value.toFixed(2);
}
},
{title: '上月结存数量', field: 'prevSum', width: 80}, {title: '上月结存数量', field: 'prevSum', width: 80},
{title: '入库数量', field: 'InSum', width: 60}, {title: '入库数量', field: 'InSum', width: 60},
{title: '出库数量', field: 'OutSum', width: 60}, {title: '出库数量', field: 'OutSum', width: 60},
{title: '本月结存数量', field: 'thisSum', width: 80}, {title: '本月结存数量', field: 'thisSum', width: 80},
{ {title: '结存金额', field: 'thisAllPrice', width: 60}
title: '结存金额', field: 'thisAllPrice', width: 60,
formatter: function (value, row, index) {
return value.toFixed(2);
}
}
]], ]],
onLoadError: function () { onLoadError: function () {
$.messager.alert('页面加载提示', '页面加载异常,请稍后再试!', 'error'); $.messager.alert('页面加载提示', '页面加载异常,请稍后再试!', 'error');

View File

@@ -336,31 +336,20 @@ public class DepotItemController {
BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true)); BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false); BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutSum = 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("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel()); item.put("MaterialModel", diEx.getMModel());
//扩展信息 //扩展信息
String materialOther = getOtherInfo(mpArr, diEx); String materialOther = getOtherInfo(mpArr, diEx);
item.put("MaterialOther", materialOther); item.put("MaterialOther", materialOther);
item.put("MaterialColor", diEx.getMColor()); item.put("MaterialColor", diEx.getMColor());
item.put("MaterialUnit", diEx.getMaterialUnit()); item.put("unitName", getUName(diEx.getMaterialUnit(), diEx.getUName()));
BigDecimal unitPrice = BigDecimal.ZERO; item.put("UnitPrice", getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy()));
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("prevSum", prevSum); item.put("prevSum", prevSum);
item.put("InSum", InSum); item.put("InSum", InSum);
item.put("OutSum", OutSum); item.put("OutSum", OutSum);
item.put("thisSum", prevSum.add(InSum).subtract(OutSum)); BigDecimal thisSum = prevSum.add(InSum).subtract(OutSum);
item.put("thisAllPrice", prevPrice.add(InPrice).subtract(OutPrice)); item.put("thisSum", thisSum);
item.put("thisAllPrice", thisSum.multiply(getUnitPrice(diEx.getPresetPriceOne(), diEx.getPriceStrategy())));
dataArray.add(item); dataArray.add(item);
} }
} }
@@ -690,6 +679,47 @@ public class DepotItemController {
} }
return sumPrice; 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 * create by: qiankunpingtai
* websitehttps://qiankunpingtai.cn * websitehttps://qiankunpingtai.cn

View File

@@ -1,5 +1,7 @@
package com.jsh.erp.datasource.entities; package com.jsh.erp.datasource.entities;
import java.math.BigDecimal;
public class DepotItemVo4WithInfoEx extends DepotItem{ public class DepotItemVo4WithInfoEx extends DepotItem{
private Long MId; private Long MId;
@@ -30,6 +32,10 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
private String UName; private String UName;
private BigDecimal presetPriceOne;
private String priceStrategy;
public Long getMId() { public Long getMId() {
return MId; return MId;
} }
@@ -141,4 +147,20 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
public void setUName(String UName) { public void setUName(String UName) {
this.UName = 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;
}
} }

View File

@@ -35,7 +35,10 @@
<result column="MName" jdbcType="VARCHAR" property="MName" /> <result column="MName" jdbcType="VARCHAR" property="MName" />
<result column="MModel" jdbcType="VARCHAR" property="MModel" /> <result column="MModel" jdbcType="VARCHAR" property="MModel" />
<result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" /> <result column="MaterialUnit" jdbcType="VARCHAR" property="MaterialUnit" />
<result column="UName" jdbcType="VARCHAR" property="UName" />
<result column="MColor" jdbcType="VARCHAR" property="MColor" /> <result column="MColor" jdbcType="VARCHAR" property="MColor" />
<result column="PresetPriceOne" jdbcType="DECIMAL" property="presetPriceOne" />
<result column="PriceStrategy" jdbcType="VARCHAR" property="priceStrategy" />
</resultMap> </resultMap>
<resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount"> <resultMap id="ResultStockWarningCount" type="com.jsh.erp.datasource.vo.DepotItemStockWarningCount">
<result column="MaterialName" jdbcType="VARCHAR" property="MaterialName" /> <result column="MaterialName" jdbcType="VARCHAR" property="MaterialName" />
@@ -180,9 +183,11 @@
</select> </select>
<select id="findByAll" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultByMaterial"> <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 from jsh_depotitem di
inner join jsh_material m on di.MaterialId=m.id and ifnull(m.delete_Flag,'0') !='1' 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 where 1=1
<if test="headIds != null"> <if test="headIds != null">
and di.HeaderId in (${headIds}) and di.HeaderId in (${headIds})
@@ -191,7 +196,7 @@
and di.MaterialId in (${materialIds}) and di.MaterialId in (${materialIds})
</if> </if>
and ifnull(di.delete_Flag,'0') !='1' 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"> <if test="offset != null and rows != null">
limit #{offset},#{rows} limit #{offset},#{rows}
</if> </if>