优化商品的库存计算

This commit is contained in:
季圣华
2020-12-25 22:26:49 +08:00
parent fd8219fd9d
commit d0f56f8413
5 changed files with 36 additions and 32 deletions

View File

@@ -434,7 +434,8 @@
{ {
title: '库存', field: 'stock', width: 70, formatter: function (value, rec) { title: '库存', field: 'stock', width: 70, formatter: function (value, rec) {
var str = ''; var str = '';
str += '<span title="查看库存及明细" class="n-link" onclick="findStockList(' + rec.id + ');">' + rec.stock + '</span>'; str += '<span title="查看库存及明细" class="n-link" ' +
'onclick="findStockList(' + rec.id + ',' + rec.mBarCode + ',\'' + rec.name + '\');">' + rec.stock + '</span>';
return str; return str;
} }
}, },
@@ -643,8 +644,9 @@
} }
} }
function findStockList(mId) { function findStockList(mId, barCode, name) {
$('#materialDetailListDlg').dialog('open').dialog('setTitle', '<img src="/js/easyui/themes/icons/pencil.png"/>&nbsp;查看库存及明细'); var titleInfo = "&nbsp;" + name + "[" + barCode + "]库存及明细";
$('#materialDetailListDlg').dialog('open').dialog('setTitle', '<img src="/js/easyui/themes/icons/pencil.png"/>' + titleInfo);
$(".window-mask").css({width: webW, height: webH}); $(".window-mask").css({width: webW, height: webH});
initDepotList(mId, "show"); //加载仓库及库存数量 initDepotList(mId, "show"); //加载仓库及库存数量
initMaterialDetailData(mId); initMaterialDetailData(mId);
@@ -1321,7 +1323,7 @@
} else if(type == "show"){ } else if(type == "show"){
$.ajax({ $.ajax({
type: "get", type: "get",
url: "../../../pages/template/init_depot_show_list.html?888", url: "../../../pages/template/init_depot_show_list.html?555",
async: false, async: false,
success: function (tem) { success: function (tem) {
if (tem) { if (tem) {

View File

@@ -9,8 +9,8 @@
<td style="width:130px;height:30px;line-height:30px;padding:8px;float:left;" title="{{name}}"> <td style="width:130px;height:30px;line-height:30px;padding:8px;float:left;" title="{{name}}">
<p style="width:110px;overflow: hidden;white-space:nowrap;text-overflow: ellipsis;">{{name}}</p> <p style="width:110px;overflow: hidden;white-space:nowrap;text-overflow: ellipsis;">{{name}}</p>
</td> </td>
<td style="width:120px;height:30px;line-height:30px;padding:8px;float:left;">{{stock}}</td> <td style="width:120px;height:30px;line-height:30px;padding:8px;float:left;">{{initStock}}</td>
<td style="width:120px;height:30px;line-height:30px;padding:8px;float:left;">{{allStock}}</td> <td style="width:120px;height:30px;line-height:30px;padding:8px;float:left;">{{currentStock}}</td>
</tr> </tr>
{{/depotList}} {{/depotList}}
</table> </table>

View File

@@ -198,13 +198,13 @@ public class DepotController {
for(Depot depot: list) { for(Depot depot: list) {
DepotEx de = new DepotEx(); DepotEx de = new DepotEx();
if(mId!=0) { if(mId!=0) {
BigDecimal stock = materialService.getInitStock(mId, depot.getId()); BigDecimal initStock = materialService.getInitStock(mId, depot.getId());
BigDecimal currentStock = materialService.getCurrentStock(mId, depot.getId()); BigDecimal currentStock = materialService.getCurrentStock(mId, depot.getId());
de.setStock(stock); de.setInitStock(initStock);
de.setAllStock(stock.add(currentStock)); de.setCurrentStock(currentStock);
} else { } else {
de.setStock(BigDecimal.ZERO); de.setInitStock(BigDecimal.ZERO);
de.setAllStock(BigDecimal.ZERO); de.setCurrentStock(BigDecimal.ZERO);
} }
de.setId(depot.getId()); de.setId(depot.getId());
de.setName(depot.getName()); de.setName(depot.getName());

View File

@@ -15,8 +15,8 @@ public class DepotEx extends Depot{
//负责人名字 //负责人名字
private String principalName; private String principalName;
private BigDecimal stock; private BigDecimal initStock;
private BigDecimal allStock; private BigDecimal currentStock;
} }

View File

@@ -742,25 +742,7 @@ public class MaterialService {
} }
/** /**
* 根据商品和仓库获取初始库存 * 根据商品获取初始库存,仓库为空的时候查全部库存
* @param materialId
* @param depotId
* @return
*/
public BigDecimal getInitStock(Long materialId, Long depotId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
stock = list.get(0).getNumber();
}
return stock;
}
/**
* 根据商品获取初始库存
* @param materialId * @param materialId
* @return * @return
*/ */
@@ -785,6 +767,24 @@ public class MaterialService {
return stock; return stock;
} }
/**
* 根据商品和仓库获取初始库存
* @param materialId
* @param depotId
* @return
*/
public BigDecimal getInitStock(Long materialId, Long depotId) {
BigDecimal stock = BigDecimal.ZERO;
MaterialInitialStockExample example = new MaterialInitialStockExample();
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<MaterialInitialStock> list = materialInitialStockMapper.selectByExample(example);
if(list!=null && list.size()>0) {
stock = list.get(0).getNumber();
}
return stock;
}
/** /**
* 根据商品和仓库获取当前库存 * 根据商品和仓库获取当前库存
* @param materialId * @param materialId
@@ -799,6 +799,8 @@ public class MaterialService {
List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example); List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
if(list!=null && list.size()>0) { if(list!=null && list.size()>0) {
stock = list.get(0).getCurrentNumber(); stock = list.get(0).getCurrentNumber();
} else {
stock = getInitStock(materialId,depotId);
} }
return stock; return stock;
} }