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

+222 -50
View File
@@ -2360,8 +2360,10 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
#region ===== 物料交付维护 ===== #region ===== 物料交付维护 =====
/// <summary> /// <summary>
/// 获取物料交付列表(分页,全局物料维度) /// 获取物料交付列表(分页,全局物料维度合并版)
/// 日需求=所有生产排程对该物料的每日需求累计;ProductTypes=该物料关联的所有产品类型 /// 相同物料跨排程多行 → 按 ChildMaterialId 合并成 1 行;
/// 风险取最严重、停线日/到货日取最早、供应商/采购员逗号拼接去重;
/// 补充汇总字段:峰值日需求、申请单总量、PO总量、到货计划数量。
/// </summary> /// </summary>
[HttpGet] [HttpGet]
public IHttpActionResult GetDeliveryList(string productCode = "", string productType = "", string supplier = "", public IHttpActionResult GetDeliveryList(string productCode = "", string productType = "", string supplier = "",
@@ -2369,67 +2371,237 @@ LEFT JOIN #SupByMat SP ON SP.MaterialCode=D.ChildMaterialId;
{ {
try try
{ {
string where = " WHERE 1=1 "; if (page < 1) page = 1;
if (!string.IsNullOrEmpty(productType)) if (pageSize < 1 || pageSize > 100000) pageSize = 50;
where += $" AND D.ProductTypes LIKE '%{Sql(productType)}%' "; int offset = (page - 1) * pageSize;
if (!string.IsNullOrEmpty(supplier)) where += $" AND D.Supplier=N'{Sql(supplier)}' ";
if (!string.IsNullOrEmpty(purchaser)) where += $" AND D.Purchaser=N'{Sql(purchaser)}' "; string todayStr = DateTime.Now.ToString("yyyy-MM-dd");
string where = " WHERE S.PlanEndDate>='" + todayStr + "' ";
if (!string.IsNullOrEmpty(productType)) where += $" AND (','+ISNULL(D.ProductTypes,'')+',') LIKE '%,{Sql(productType)},%' ";
if (!string.IsNullOrEmpty(supplier)) where += $" AND ISNULL(D.Supplier,'') LIKE N'%{Sql(supplier)}%' ";
if (!string.IsNullOrEmpty(purchaser)) where += $" AND ISNULL(D.Purchaser,'') LIKE N'%{Sql(purchaser)}%' ";
if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' "; if (!string.IsNullOrEmpty(risk)) where += $" AND D.DeliveryRisk=N'{Sql(risk)}' ";
if (!string.IsNullOrEmpty(bomLevel)) where += $" AND D.BOMLevel={Int(bomLevel)} "; if (!string.IsNullOrEmpty(bomLevel)) where += $" AND D.BOMLevel={Int(bomLevel)} ";
if (!string.IsNullOrEmpty(keyword)) where += $" AND (D.ChildMaterialId LIKE '%{Sql(keyword)}%' OR D.MaterialName LIKE N'%{Sql(keyword)}%') "; if (!string.IsNullOrEmpty(keyword))
{
string kw = Sql(keyword);
where += $" AND (D.ChildMaterialId LIKE '%{kw}%' OR D.MaterialName LIKE N'%{kw}%' OR S.ProductCode LIKE '%{kw}%') ";
}
// 统计总记录数 // 1) 全量查 Material_Delivery + INNER JOIN Production_Schedule 过滤未结束排程
DataTable dtCount = db.ExecuteTable($"SELECT COUNT(*) AS CNT FROM Material_Delivery D {where}");
int total = Int(dtCount.Rows[0]["CNT"]);
int offset = (page - 1) * pageSize;
DataTable dt = db.ExecuteTable($@" DataTable dt = db.ExecuteTable($@"
SELECT D.*, SELECT D.Id, D.ScheduleId, D.ProductCode, D.BOMVersion,
(SELECT ISNULL(SUM(R.DailyRequirement),0) FROM Material_Requirement R D.ChildMaterialId, D.MaterialName, D.BOMLevel, D.DeliveryRisk,
WHERE R.ChildMaterialId=D.ChildMaterialId AND R.PlanDate>=CONVERT(date,GETDATE())) AS DailyRequirement, D.AvailableStock, D.ExpectedStopDate, D.ExpectedArrivalDate,
(SELECT MIN(PlanDate) FROM Material_Requirement R D.ZhenZeStock, D.JinJiangStock, D.ZiYangStock,
WHERE R.ChildMaterialId=D.ChildMaterialId AND R.PlanDate>=CONVERT(date,GETDATE())) AS FirstNeedDate D.MassInTransit, D.ResearchInTransit, D.LineSideStock, D.ReceivedQty,
D.ERPStockQty, D.Remark, D.ProductTypes, D.Supplier, D.Purchaser,
D.InTransitQty, D.DeliveryProgress
FROM Material_Delivery D FROM Material_Delivery D
INNER JOIN Production_Schedule S ON D.ScheduleId=S.Id
{where} {where}
ORDER BY D.BOMLevel, D.ChildMaterialId ORDER BY D.ChildMaterialId");
OFFSET {offset} ROWS FETCH NEXT {pageSize} ROWS ONLY");
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); // 2) 无数据直接返回
if (dt.Rows.Count == 0)
return Ok(new { success = true, data = new List<Dictionary<string, object>>(), total = 0, page, pageSize });
var allChildIds = dt.Rows.Cast<DataRow>().Select(r => "'" + Sql(r["ChildMaterialId"].ToString()) + "'").Distinct().ToList();
string allIdsList = string.Join(",", allChildIds);
var allDelIds = dt.Rows.Cast<DataRow>().Select(r => "'" + Sql(r["Id"].ToString()) + "'").Distinct().ToList();
string allDelIdsList = string.Join(",", allDelIds);
// 3) 批量聚合:该物料用于哪些产品(从 BOM 展开 Product_BOM_Detail.ProductCode)
Dictionary<string, List<string>> prodCodeMap = new Dictionary<string, List<string>>();
DataTable pcDt = db.ExecuteTable($@"
SELECT DISTINCT BD.ChildMaterialId, BD.ProductCode
FROM Product_BOM_Detail BD
WHERE BD.ChildMaterialId IN ({allIdsList}) AND ISNULL(BD.IsVirtual,0)=0");
foreach (DataRow pr in pcDt.Rows)
{
string mid = pr["ChildMaterialId"].ToString();
string pc = pr["ProductCode"].ToStringEx();
if (!prodCodeMap.ContainsKey(mid)) prodCodeMap[mid] = new List<string>();
if (!string.IsNullOrEmpty(pc) && !prodCodeMap[mid].Contains(pc)) prodCodeMap[mid].Add(pc);
}
// 4) 批量聚合:申请单总量 / PO总量 / 到货计划数量 / 峰值单日需求
string yearStart = new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd");
Dictionary<string, decimal> reqQtyMap = new Dictionary<string, decimal>();
Dictionary<string, decimal> poQtyMap = new Dictionary<string, decimal>();
Dictionary<string, decimal> arrivalQtyMap = new Dictionary<string, decimal>();
Dictionary<string, decimal> peakDailyMap = new Dictionary<string, decimal>();
// 申请单总量(量产 CGSQD01/20 + 研发 CGSQD07)
DataTable reqDt = db.ExecuteTable($@"
SELECT M.FNUMBER AS MaterialCode, SUM(ISNULL(S1.FQTY,0)) AS ReqQty
FROM P_PUR_Requisition S
INNER JOIN P_PUR_RequisitionENTRY S1 ON S.FINTERID=S1.FINTERID
INNER JOIN T_BAS_BILLTYPE S2 ON S.FBILLTYPEID=S2.FINTERID
INNER JOIN T_BD_MATERIAL M ON S1.FMATERIALID=M.FINTERID
WHERE S.FSTATUS='40' AND S.FDATE>='{yearStart}' AND S.FDELETED=0
AND S2.FNUMBER IN ('CGSQD01_SYS','CGSQD20_SYS','CGSQD07_SYS')
AND M.FNUMBER IN ({allIdsList})
GROUP BY M.FNUMBER");
foreach (DataRow rr in reqDt.Rows) reqQtyMap[rr["MaterialCode"].ToString()] = Dec(rr["ReqQty"]);
// PO 总量(量产 CGDD01/02/21 排除 GSSH + 研发 CGDD11)
DataTable poDt = db.ExecuteTable($@"
SELECT M.FNUMBER AS MaterialCode, SUM(ISNULL(S1.FQTY,0)) AS PoQty
FROM T_PUR_POORDER S
INNER JOIN T_PUR_POORDERENTRY S1 ON S.FINTERID=S1.FINTERID
INNER JOIN T_BAS_BILLTYPE S2 ON S.FBILLTYPEID=S2.FINTERID
LEFT JOIN T_BAS_ASSISTANTDATAENTRY S3 ON S1.F_RESEARCHPROJECT=S3.FINTERID
INNER JOIN T_BD_MATERIAL M ON S1.FMATERIALID=M.FINTERID
WHERE S.FSTATUS='40' AND S.FDATE>='{yearStart}' AND S.FDELETED=0
AND ((S2.FNUMBER IN ('CGDD01_SYS','CGDD02_SYS','CGDD21_SYS') AND ISNULL(S3.FNUMBER,'')<>'GSSH')
OR S2.FNUMBER='CGDD11_SYS')
AND M.FNUMBER IN ({allIdsList})
GROUP BY M.FNUMBER");
foreach (DataRow rr in poDt.Rows) poQtyMap[rr["MaterialCode"].ToString()] = Dec(rr["PoQty"]);
// 到货计划数量(按 DeliveryId 聚合 Arrival_Plan,只计有预计到货日的批次)
var delIdList = dt.Rows.Cast<DataRow>().Select(r => r["Id"].ToString()).Distinct().ToList();
foreach (string batch in BuildInBatches(delIdList))
{
DataTable arrDt = db.ExecuteTable($@"
SELECT DeliveryId, SUM(ISNULL(ArrivalQty,0)) AS ArrivalQty
FROM Arrival_Plan
WHERE DeliveryId IN ({batch}) AND ExpectedArrivalDate IS NOT NULL
GROUP BY DeliveryId");
foreach (DataRow rr in arrDt.Rows) arrivalQtyMap[rr["DeliveryId"].ToString()] = Dec(rr["ArrivalQty"]);
}
// 峰值单日需求:按日期汇总后取最大(口径与停线日计算一致)
DataTable peakDt = db.ExecuteTable($@"
SELECT T.ChildMaterialId, MAX(T.DayQty) AS PeakDaily
FROM (
SELECT R.ChildMaterialId, R.PlanDate, SUM(ISNULL(R.DailyRequirement,0)) AS DayQty
FROM Material_Requirement R
INNER JOIN Production_Schedule S ON R.ScheduleId=S.Id
WHERE R.ChildMaterialId IN ({allIdsList})
AND R.PlanDate >= '{todayStr}'
AND S.PlanEndDate >= '{todayStr}'
GROUP BY R.ChildMaterialId, R.PlanDate
) T
GROUP BY T.ChildMaterialId");
foreach (DataRow rr in peakDt.Rows) peakDailyMap[rr["ChildMaterialId"].ToString()] = Dec(rr["PeakDaily"]);
// 5) 内存按 ChildMaterialId 合并(相同物料多行 → 1 行)
List<string> matOrder = new List<string>();
Dictionary<string, List<DataRow>> matGroups = new Dictionary<string, List<DataRow>>();
foreach (DataRow r in dt.Rows) foreach (DataRow r in dt.Rows)
{ {
list.Add(new Dictionary<string, object> string mid = r["ChildMaterialId"].ToString();
if (!matGroups.ContainsKey(mid)) { matGroups[mid] = new List<DataRow>(); matOrder.Add(mid); }
matGroups[mid].Add(r);
}
List<Dictionary<string, object>> aggList = new List<Dictionary<string, object>>();
foreach (string mid in matOrder)
{
List<DataRow> rows = matGroups[mid];
string stopDate = "", arrDate = "";
string riskVal = rows[0]["DeliveryRisk"].ToStringEx();
string materialName = "";
int bomLevel = int.MaxValue;
decimal arrivalSum = 0;
HashSet<string> supSet = new HashSet<string>(), purSet = new HashSet<string>(),
ptSet = new HashSet<string>(), bvSet = new HashSet<string>(), rmkSet = new HashSet<string>();
List<string> delIdList = new List<string>();
foreach (DataRow r in rows)
{ {
["Id"] = r["Id"].ToStringEx(), string sd = DateStr(r["ExpectedStopDate"]);
["ScheduleId"] = r["ScheduleId"].ToStringEx(), if (!string.IsNullOrEmpty(sd) && (string.IsNullOrEmpty(stopDate) || string.Compare(sd, stopDate) < 0)) stopDate = sd;
["ProductCode"] = r["ProductCode"].ToStringEx(), string ad = DateStr(r["ExpectedArrivalDate"]);
["BOMVersion"] = r["BOMVersion"].ToStringEx(), if (!string.IsNullOrEmpty(ad) && (string.IsNullOrEmpty(arrDate) || string.Compare(ad, arrDate) < 0)) arrDate = ad;
["ChildMaterialId"] = r["ChildMaterialId"].ToStringEx(), string rk = r["DeliveryRisk"].ToStringEx();
["MaterialName"] = r["MaterialName"].ToStringEx(), if (RiskOrder(rk) < RiskOrder(riskVal)) riskVal = rk;
["BOMLevel"] = r["BOMLevel"].ToStringEx(), string mn = r["MaterialName"].ToStringEx();
["ProductTypes"] = r["ProductTypes"].ToStringEx(), if (mn.Length > materialName.Length) materialName = mn;
["Supplier"] = r["Supplier"].ToStringEx(), int bl = Int(r["BOMLevel"]);
["Purchaser"] = r["Purchaser"].ToStringEx(), if (bl < bomLevel) bomLevel = bl;
["ExpectedStopDate"] = DateStr(r["ExpectedStopDate"]), string sp = r["Supplier"].ToStringEx(); if (!string.IsNullOrEmpty(sp)) supSet.Add(sp);
["ExpectedArrivalDate"] = DateStr(r["ExpectedArrivalDate"]), string pu = r["Purchaser"].ToStringEx(); if (!string.IsNullOrEmpty(pu)) purSet.Add(pu);
["DeliveryRisk"] = r["DeliveryRisk"].ToStringEx(), string pt = r["ProductTypes"].ToStringEx(); if (!string.IsNullOrEmpty(pt)) ptSet.Add(pt);
["ZhenZeStock"] = NumStr(r["ZhenZeStock"]), string bv = r["BOMVersion"].ToStringEx(); if (!string.IsNullOrEmpty(bv)) bvSet.Add(bv);
["JinJiangStock"] = NumStr(r["JinJiangStock"]), string rm = r["Remark"].ToStringEx(); if (!string.IsNullOrEmpty(rm)) rmkSet.Add(rm);
["ZiYangStock"] = NumStr(r["ZiYangStock"]), string did = r["Id"].ToString();
["ERPStockQty"] = NumStr(r["ERPStockQty"]), delIdList.Add(did);
["InTransitQty"] = NumStr(r["InTransitQty"]), if (arrivalQtyMap.ContainsKey(did)) arrivalSum += arrivalQtyMap[did];
["LineSideStock"] = NumStr(r["LineSideStock"]), }
["MassInTransit"] = NumStr(r["MassInTransit"]),
["ResearchInTransit"] = NumStr(r["ResearchInTransit"]), decimal erpStock = rows.Max(r => Dec(r["ERPStockQty"]));
["ReceivedQty"] = NumStr(r["ReceivedQty"]), decimal received = rows.Max(r => Dec(r["ReceivedQty"]));
["AvailableStock"] = NumStr(r["AvailableStock"]), decimal lineSide = rows.Max(r => Dec(r["LineSideStock"]));
["DeliveryProgress"] = r["DeliveryProgress"].ToStringEx(), decimal massTransit = rows.Max(r => Dec(r["MassInTransit"]));
["Remark"] = r["Remark"].ToStringEx(), decimal researchTransit = rows.Max(r => Dec(r["ResearchInTransit"]));
["DailyRequirement"] = NumStr(r["DailyRequirement"]), decimal availStock = rows.Max(r => Dec(r["AvailableStock"]));
["FirstNeedDate"] = DateStr(r["FirstNeedDate"]) decimal reqQty = reqQtyMap.ContainsKey(mid) ? reqQtyMap[mid] : 0;
decimal poQty = poQtyMap.ContainsKey(mid) ? poQtyMap[mid] : 0;
decimal arrQty = arrivalSum;
string productCodes = prodCodeMap.ContainsKey(mid) ? string.Join(",", prodCodeMap[mid]) : "";
aggList.Add(new Dictionary<string, object>
{
// 主键 / 操作
["Id"] = rows[0]["Id"].ToStringEx(), // 第一行 DeliveryId(向后兼容 openEdit)
["DeliveryIds"] = string.Join(",", delIdList), // 所有 DeliveryId(逗号分隔)
["ChildMaterialId"] = mid,
["MaterialName"] = materialName,
["BOMLevel"] = bomLevel == int.MaxValue ? "" : bomLevel.ToString(),
["ProductCode"] = productCodes, // 该物料用于哪些产品(从 BOM 展开)
["BOMVersion"] = string.Join(",", bvSet),
// 风险 + 日期
["DeliveryRisk"] = riskVal,
["ExpectedStopDate"] = stopDate,
["ExpectedArrivalDate"] = arrDate,
// 库存明细(物料级,同一物料各排程行相同,取 MAX)
["AvailableStock"] = NumStr(availStock),
["ZhenZeStock"] = NumStr(rows.Max(r => Dec(r["ZhenZeStock"]))),
["JinJiangStock"] = NumStr(rows.Max(r => Dec(r["JinJiangStock"]))),
["ZiYangStock"] = NumStr(rows.Max(r => Dec(r["ZiYangStock"]))),
["LineSideStock"] = NumStr(lineSide),
["MassInTransit"] = NumStr(massTransit),
["ResearchInTransit"] = NumStr(researchTransit),
["InTransitQty"] = NumStr(rows.Max(r => Dec(r["InTransitQty"]))),
["ReceivedQty"] = NumStr(received),
["ERPStockQty"] = NumStr(erpStock),
// 汇总口径(GetBoardRiskList 同款)
["StockQty"] = NumStr(received + erpStock + lineSide), // 已收货 + 三地 + 线边
["TotalInTransitQty"] = NumStr(reqQty + poQty + erpStock), // 申请 + PO + 三地
["ArrivalPlanQty"] = NumStr(erpStock + arrQty), // 三地 + 到货计划
["ReqTotalQty"] = NumStr(reqQty), // 申请单总量
["PoTotalQty"] = NumStr(poQty), // PO 总量
["ArrivalQty"] = NumStr(arrQty), // 到货计划数量(汇总)
// 峰值日需求(所有排程按日期叠加后取 MAX)
["DailyRequirement"] = NumStr(peakDailyMap.ContainsKey(mid) ? peakDailyMap[mid] : 0),
// 去重拼接
["ProductTypes"] = string.Join(",", ptSet),
["Supplier"] = string.Join(",", supSet),
["Purchaser"] = string.Join(",", purSet),
["Remark"] = string.Join(",", rmkSet)
}); });
} }
return Ok(new { success = true, data = list, total = total, page = page, pageSize = pageSize }); // 6) 排序 + 内存分页(合并后的行数即总数)
aggList.Sort((a, b) =>
{
int ro = RiskOrder(a["DeliveryRisk"].ToStringEx()) - RiskOrder(b["DeliveryRisk"].ToStringEx());
if (ro != 0) return ro;
return string.Compare(a["ChildMaterialId"].ToStringEx(), b["ChildMaterialId"].ToStringEx());
});
int total = aggList.Count;
List<Dictionary<string, object>> pageList = aggList.Skip(offset).Take(pageSize).ToList();
return Ok(new { success = true, data = pageList, total = total, page = page, pageSize = pageSize });
} }
catch (Exception ex) catch (Exception ex)
{ {
+51 -20
View File
@@ -128,8 +128,11 @@ tbody tr:hover{background:#f0f6ff}
<tr> <tr>
<th style="width:48px">序号</th> <th style="width:48px">序号</th>
<th style="width:130px">操作</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: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: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: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> </tr>
</thead> </thead>
<tbody id="tbodyList"></tbody> <tbody id="tbodyList"></tbody>
@@ -306,34 +309,39 @@ function loadList(page){
var rows=res.data||[]; var rows=res.data||[];
curList=rows; curList=rows;
var html=''; 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){ rows.forEach(function(r,i){
var seq=(curPage-1)*curPageSize+i+1; var seq=(curPage-1)*curPageSize+i+1;
var rk=r.DeliveryRisk||'安全'; var rk=r.DeliveryRisk||'安全';
var cls=rk=='断线'?'badge-danger':(rk=='预警'?'badge-warning':'badge-success'); 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>'+ html+='<tr>'+
'<td>'+seq+'</td>'+ '<td>'+seq+'</td>'+
'<td style="white-space:nowrap">'+ '<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-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+',\''+r.MaterialName+'\')">到货计划</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>'+
'<td>'+r.ChildMaterialId+'</td>'+ '<td>'+r.ChildMaterialId+'</td>'+
'<td>'+r.MaterialName+'</td>'+ '<td>'+r.MaterialName+'</td>'+
'<td>'+(r.ProductTypes||'')+'</td>'+ '<td style="font-size:11px">'+(r.ProductCode||'')+'</td>'+
'<td>'+r.Supplier+'</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.Purchaser||'')+'</td>'+
'<td>'+r.ExpectedStopDate+'</td>'+ '<td>'+(r.ExpectedStopDate||'')+'</td>'+
'<td>'+r.ExpectedArrivalDate+'</td>'+ '<td>'+(r.ExpectedArrivalDate||'')+'</td>'+
'<td><span class="badge '+cls+'">'+rk+'</span></td>'+ '<td><span class="badge '+cls+'">'+rk+'</span></td>'+
'<td>'+r.DailyRequirement+'</td>'+ '<td>'+(r.DailyRequirement||'0')+'</td>'+
'<td>'+r.ZhenZeStock+'</td>'+ '<td>'+(r.ArrivalQty||'0')+'</td>'+
'<td>'+r.JinJiangStock+'</td>'+ '<td>'+(r.PoTotalQty||'0')+'</td>'+
'<td>'+r.ZiYangStock+'</td>'+ '<td>'+(r.ReqTotalQty||'0')+'</td>'+
'<td>'+r.AvailableStock+'</td>'+ '<td style="font-weight:600">'+(r.AvailableStock||'0')+'</td>'+
'<td>'+r.MassInTransit+'</td>'+ '<td>'+(r.MassInTransit||'0')+'</td>'+
'<td>'+r.ResearchInTransit+'</td>'+ '<td>'+(r.ResearchInTransit||'0')+'</td>'+
'<td>'+r.LineSideStock+'</td>'+ '<td>'+(r.LineSideStock||'0')+'</td>'+
'<td>'+r.ReceivedQty+'</td>'+ '<td>'+(r.ReceivedQty||'0')+'</td>'+
'<td>'+(r.ZhenZeStock||'0')+'</td>'+
'<td>'+(r.JinJiangStock||'0')+'</td>'+
'<td>'+(r.ZiYangStock||'0')+'</td>'+
'</tr>'; '</tr>';
}); });
document.getElementById('tbodyList').innerHTML=html; document.getElementById('tbodyList').innerHTML=html;
@@ -437,7 +445,30 @@ function calcAvailable(){
var m=parseFloat(document.getElementById('fMassInTransit').value)||0; var m=parseFloat(document.getElementById('fMassInTransit').value)||0;
var r=parseFloat(document.getElementById('fResearchInTransit').value)||0; var r=parseFloat(document.getElementById('fResearchInTransit').value)||0;
var l=parseFloat(document.getElementById('fLineSideStock').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(){ function saveDelivery(){