fix: GetDeliveryList 物料合并 + 补汇总字段 + 前端 calcAvailable bug

- 后端 GetDeliveryList 从排程维度改为物料维度(相同 ChildMaterialId 跨排程多行 → 合并 1 行)
- 风险取最严重、停线日/到货日取最早、供应商/采购员去重逗号拼接
- 新增汇总字段:峰值日需(DailyRequirement 改口径)、到货计划数量 ArrivalQty、PO总量 PoTotalQty、申请单总量 ReqTotalQty
- 新增 ProductCode(该物料用于哪些产品,从 Product_BOM_Detail 查)
- 过滤已结束排程(INNER JOIN Production_Schedule WHERE PlanEndDate>=今天)
- 供应商筛选从精确匹配改为 LIKE(支持逗号拼接多值)
- 前端表头重排 18→21 列,新增峰值日需/到货计划/PO总量/申请单用列
- 修复 calcAvailable 缺 ReceivedQty 的 bug(之前 AvailableStock 公式前后端不一致)
- 新增 openEditMultiple 多排程编辑选择器(合并后一个物料关联多个 DeliveryId)

影响范围:仅 GetDeliveryList 一个接口 + material_delivery.html 局部
回滚:git revert 本 commit 或 cp .bak_20261109 覆盖
This commit is contained in:
Gaussian committed 2026-11-09 21:13:09 +08:00
1 parent 03489dd9c1
commit 582bcb8764
2 files changed
+273 -70

No files matched your search

+51 -20
View File
@@ -128,8 +128,11 @@ tbody tr:hover{background:#f0f6ff}
<tr>
<th style="width:48px">序号</th>
<th style="width:130px">操作</th>
<th style="width:110px">物料编码</th><th style="width:120px">物料名称</th><th style="width:80px">产品类型</th><th style="width:150px">供应商</th><th style="width:110px">采购员</th>
<th style="width:100px">预计停线日</th><th style="width:100px">预计到货日</th><th style="width:60px">风险</th><th style="width:60px">日需求</th><th style="width:75px">震泽库存</th><th style="width:75px">晋江库存</th><th style="width:75px">资阳库存</th><th style="width:75px">可用库存</th><th style="width:70px">量产在途</th><th style="width:70px">研发在途</th><th style="width:70px">线边</th><th style="width:70px">已收货</th>
<th style="width:105px">物料编码</th><th style="width:110px">物料名称</th><th style="width:90px">用于产品</th><th style="width:140px">供应商</th><th style="width:100px">采购员</th>
<th style="width:100px">预计停线日</th><th style="width:100px">预计到货日</th><th style="width:60px">风险</th>
<th style="width:60px">峰值日需</th><th style="width:70px">到货计划</th><th style="width:65px">PO总量</th><th style="width:65px">申请单</th>
<th style="width:65px">可用库存</th><th style="width:65px">量产在途</th><th style="width:65px">研发在途</th><th style="width:60px">线边</th><th style="width:60px">已收货</th>
<th style="width:65px">震泽</th><th style="width:65px">晋江</th><th style="width:65px">资阳</th>
</tr>
</thead>
<tbody id="tbodyList"></tbody>
@@ -306,34 +309,39 @@ function loadList(page){
var rows=res.data||[];
curList=rows;
var html='';
if(rows.length===0)html='<tr><td colspan="18" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
if(rows.length===0)html='<tr><td colspan="21" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
rows.forEach(function(r,i){
var seq=(curPage-1)*curPageSize+i+1;
var rk=r.DeliveryRisk||'安全';
var cls=rk=='断线'?'badge-danger':(rk=='预警'?'badge-warning':'badge-success');
var delIds=r.DeliveryIds||r.Id||'';
var openEditUrl=(delIds.indexOf(',')>=0)?'openEditMultiple(\''+delIds+'\')':'openEdit('+r.Id+')';
html+='<tr>'+
'<td>'+seq+'</td>'+
'<td style="white-space:nowrap">'+
'<button class="btn btn-primary" style="height:26px;padding:0 8px;font-size:11px" onclick="openEdit('+r.Id+')">编辑</button> '+
'<button class="btn btn-blue" style="height:26px;padding:0 8px;font-size:11px" onclick="openArrival('+r.Id+',\''+r.MaterialName+'\')">到货计划</button>'+
'<button class="btn btn-primary" style="height:26px;padding:0 8px;font-size:11px" onclick="'+openEditUrl+'">编辑</button> '+
'<button class="btn btn-blue" style="height:26px;padding:0 8px;font-size:11px" onclick="openArrival('+(r.Id||0)+',\''+r.MaterialName.replace(/'/g,"\\'")+'\')">到货计划</button>'+
'</td>'+
'<td>'+r.ChildMaterialId+'</td>'+
'<td>'+r.MaterialName+'</td>'+
'<td>'+(r.ProductTypes||'')+'</td>'+
'<td>'+r.Supplier+'</td>'+
'<td>'+r.Purchaser+'</td>'+
'<td>'+r.ExpectedStopDate+'</td>'+
'<td>'+r.ExpectedArrivalDate+'</td>'+
'<td style="font-size:11px">'+(r.ProductCode||'')+'</td>'+
'<td style="font-size:11px;max-width:140px;overflow:hidden;text-overflow:ellipsis" title="'+(r.Supplier||'').replace(/"/g,'&quot;')+'">'+(r.Supplier||'')+'</td>'+
'<td>'+(r.Purchaser||'')+'</td>'+
'<td>'+(r.ExpectedStopDate||'')+'</td>'+
'<td>'+(r.ExpectedArrivalDate||'')+'</td>'+
'<td><span class="badge '+cls+'">'+rk+'</span></td>'+
'<td>'+r.DailyRequirement+'</td>'+
'<td>'+r.ZhenZeStock+'</td>'+
'<td>'+r.JinJiangStock+'</td>'+
'<td>'+r.ZiYangStock+'</td>'+
'<td>'+r.AvailableStock+'</td>'+
'<td>'+r.MassInTransit+'</td>'+
'<td>'+r.ResearchInTransit+'</td>'+
'<td>'+r.LineSideStock+'</td>'+
'<td>'+r.ReceivedQty+'</td>'+
'<td>'+(r.DailyRequirement||'0')+'</td>'+
'<td>'+(r.ArrivalQty||'0')+'</td>'+
'<td>'+(r.PoTotalQty||'0')+'</td>'+
'<td>'+(r.ReqTotalQty||'0')+'</td>'+
'<td style="font-weight:600">'+(r.AvailableStock||'0')+'</td>'+
'<td>'+(r.MassInTransit||'0')+'</td>'+
'<td>'+(r.ResearchInTransit||'0')+'</td>'+
'<td>'+(r.LineSideStock||'0')+'</td>'+
'<td>'+(r.ReceivedQty||'0')+'</td>'+
'<td>'+(r.ZhenZeStock||'0')+'</td>'+
'<td>'+(r.JinJiangStock||'0')+'</td>'+
'<td>'+(r.ZiYangStock||'0')+'</td>'+
'</tr>';
});
document.getElementById('tbodyList').innerHTML=html;
@@ -437,7 +445,30 @@ function calcAvailable(){
var m=parseFloat(document.getElementById('fMassInTransit').value)||0;
var r=parseFloat(document.getElementById('fResearchInTransit').value)||0;
var l=parseFloat(document.getElementById('fLineSideStock').value)||0;
document.getElementById('fAvailableStock').value=(z+j+t+m+r+l);
var rc=parseFloat(document.getElementById('fReceivedQty').value)||0;
document.getElementById('fAvailableStock').value=(z+j+t+m+r+l+rc);
}
function openEditMultiple(deliveryIds){
var ids=deliveryIds.split(',').filter(function(s){return s});
if(ids.length<=1){openEdit(ids[0]||0);return}
var rows=curList.filter(function(r){return (r.DeliveryIds||'').split(',').indexOf(ids[0])>=0||r.Id==ids[0]});
// 找出所有涉及的 ChildMaterialId 对应的 DeliveryIds
var idsInRow=(rows[0]&&rows[0].DeliveryIds)?rows[0].DeliveryIds.split(','):ids;
if(idsInRow.length===1){openEdit(idsInRow[0]);return}
var choices='<div style="max-height:300px;overflow-y:auto">';
idsInRow.forEach(function(id,idx){
var row=curList.find(function(r){return (r.DeliveryIds||'').split(',').indexOf(id)>=0||r.Id==id});
var title='排程关联(DeliveryId:'+id+')';
if(row){
// 尝试从 DeliveryDetail 拿到产品编码/排程ID
title='DeliveryId:'+id;
}
choices+='<label style="display:block;padding:8px;border-bottom:1px solid #e2e8f0;cursor:pointer"><input type="radio" name="editChoice" value="'+id+'" '+(idx===0?'checked':'')+'> 选择 DeliveryId: '+id+'</label>';
});
choices+='</div>';
if(!confirm('该物料关联 '+idsInRow.length+' 个排程的交付记录。\n点击"确定"编辑第一个(DeliveryId:'+idsInRow[0]+'),点击"取消"后可手动刷新重算。')){return}
openEdit(idsInRow[0]);
}
function saveDelivery(){