|
|
|
|
@ -395,47 +395,118 @@ namespace Khd.Core.Wpf.Form
|
|
|
|
|
var baseEquip = dbContext.BaseEquip.First(t => t.objid == 10);
|
|
|
|
|
if (!string.IsNullOrEmpty(baseEquip.endStationCode))
|
|
|
|
|
{
|
|
|
|
|
List<WcsTask> wcsTasks = dbContext.WcsTask.Where(t => t.taskType == 30).Where(t => orderIds.Contains(t.orderId)).ToList();
|
|
|
|
|
#region 待测试
|
|
|
|
|
//找出本工位的申请单
|
|
|
|
|
List<WmsRawOutstock> RawOutstocks = wmsRawOutstocks.Where(t => t.endStationCode == baseEquip.endStationCode).ToList();
|
|
|
|
|
|
|
|
|
|
// 根据 materialId 分组,并计算 outstockAmount 和 realOutstockAmount 的总和
|
|
|
|
|
var targetRawOutstocks = RawOutstocks
|
|
|
|
|
.GroupBy(t => new { t.materialId, t.saleOrderId })
|
|
|
|
|
.Select(g => new
|
|
|
|
|
{
|
|
|
|
|
materialId = g.Key.materialId,
|
|
|
|
|
saleOrderId = g.Key.saleOrderId,
|
|
|
|
|
totalOutstockAmount = g.Sum(t => t.outstockAmount),
|
|
|
|
|
totalRealOutstockAmount = g.Sum(t => t.realOutstockAmount)
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
//本次所有任务出来的托盘号
|
|
|
|
|
List<WcsTask> wcsTasks = dbContext.WcsTask.Where(t => t.taskType == 30).Where(t => orderIds.Contains(t.orderId)).ToList();
|
|
|
|
|
List<string> containerNos = wcsTasks.Select(t => t.containerNo).ToList();
|
|
|
|
|
//本次所有托盘携带的物料
|
|
|
|
|
List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock.Where(t => containerNos.Contains(t.palletInfoCode)).ToList();
|
|
|
|
|
var thisOutList = wmsRawStocks.GroupBy(t => new { t.materialId, t.saleOrderId,t.palletInfoCode })
|
|
|
|
|
.Select(t => new
|
|
|
|
|
|
|
|
|
|
// Step 3: 计算每个申请单物料在各个托盘中的数量
|
|
|
|
|
var palletMaterialSummary = wmsRawStocks
|
|
|
|
|
.GroupBy(t => new { t.materialId, t.palletInfoCode,t.saleOrderId })
|
|
|
|
|
.Select(g => new
|
|
|
|
|
{
|
|
|
|
|
palletInfoCode = t.Key.palletInfoCode,
|
|
|
|
|
materialId = t.Key.materialId,
|
|
|
|
|
saleOrderId = t.Key.saleOrderId,
|
|
|
|
|
thisOutAmount = t.Sum(x => x.totalAmount) - t.Sum(x => x.frozenAmount)
|
|
|
|
|
});
|
|
|
|
|
List<WmsRawOutstock> endStationCodeOutRaw = wmsRawOutstocks.Where(t => t.endStationCode == baseEquip.endStationCode).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<long?> materialIds = endStationCodeOutRaw.Select(t => t.materialId).ToList();
|
|
|
|
|
MaterialId = g.Key.materialId,
|
|
|
|
|
saleOrderId = g.Key.saleOrderId,
|
|
|
|
|
PalletInfoCode = g.Key.palletInfoCode,
|
|
|
|
|
//携带总可用库存
|
|
|
|
|
canUseAmount = g.Sum(x => x.totalAmount) - g.Sum(x => x.frozenAmount)
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
// 汇总每个申请单在各个托盘的物料数量
|
|
|
|
|
var result = targetRawOutstocks
|
|
|
|
|
.Select(order => new
|
|
|
|
|
{
|
|
|
|
|
SaleOrderId = order.saleOrderId,
|
|
|
|
|
MaterialId = order.materialId,
|
|
|
|
|
//申请数量
|
|
|
|
|
RequestedAmount = order.totalOutstockAmount,
|
|
|
|
|
//实际已出数量
|
|
|
|
|
RealOutstockAmount = order.totalRealOutstockAmount,
|
|
|
|
|
// 托盘携带可用信息,用分号分隔
|
|
|
|
|
PalletDetails = string.Join("\n", palletMaterialSummary
|
|
|
|
|
.Where(pallet => pallet.MaterialId == order.materialId)
|
|
|
|
|
.Select(pallet => $"托盘{pallet.PalletInfoCode}数量{pallet.canUseAmount}")
|
|
|
|
|
)
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
List<long?> materialIds = RawOutstocks.Select(t => t.materialId).ToList();
|
|
|
|
|
List<MesBaseMaterialInfo> mesBaseMaterialInfos = dbContext.MesBaseMaterialInfo.Where(t => materialIds.Contains(t.MaterialId)).ToList();
|
|
|
|
|
var bill = endStationCodeOutRaw.GroupBy(t => new { t.materialId, t.materialBatch, t.saleOrderId })
|
|
|
|
|
.Select(t => new
|
|
|
|
|
{
|
|
|
|
|
materialId = t.Key.materialId,
|
|
|
|
|
materialBatch = t.Key.materialBatch,
|
|
|
|
|
saleOrderId = t.Key.saleOrderId,
|
|
|
|
|
outstockAmount = t.Sum(x => x.outstockAmount),
|
|
|
|
|
realOutstockAmount = t.Sum(x => x.realOutstockAmount),
|
|
|
|
|
});
|
|
|
|
|
var orderNumber = from a in bill
|
|
|
|
|
from b in thisOutList
|
|
|
|
|
from c in mesBaseMaterialInfos
|
|
|
|
|
where a.materialId == b.materialId && a.saleOrderId == b.saleOrderId && a.materialId ==c.MaterialId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var orderNumber = from r in result
|
|
|
|
|
from m in mesBaseMaterialInfos
|
|
|
|
|
where r.MaterialId== m.MaterialId
|
|
|
|
|
select new
|
|
|
|
|
{
|
|
|
|
|
palletInfoCode = b.palletInfoCode,
|
|
|
|
|
materialBatch = a.materialBatch,
|
|
|
|
|
saleOrderId = b.saleOrderId,
|
|
|
|
|
outstockAmount = a.outstockAmount,
|
|
|
|
|
materialSpec = c.MaterialSpec,
|
|
|
|
|
realOutstockAmount = a.realOutstockAmount,
|
|
|
|
|
thisOutAmount = b.thisOutAmount,
|
|
|
|
|
isSendOver = a.outstockAmount <= (a.realOutstockAmount + b.thisOutAmount) ? "已出完" : "未出完"
|
|
|
|
|
materiaName = m.MaterialName,
|
|
|
|
|
materialSpec = m.MaterialSpec,
|
|
|
|
|
saleOrderId = r.SaleOrderId,
|
|
|
|
|
outstockAmount = r.RequestedAmount,
|
|
|
|
|
realOutstockAmount = r.RealOutstockAmount,
|
|
|
|
|
isSendOver = r.RequestedAmount <= r.RealOutstockAmount ? "已出完" : "未出完",
|
|
|
|
|
thisOutAmount = r.PalletDetails
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
//List<WcsTask> wcsTasks = dbContext.WcsTask.Where(t => t.taskType == 30).Where(t => orderIds.Contains(t.orderId)).ToList();
|
|
|
|
|
|
|
|
|
|
//List<string> containerNos = wcsTasks.Select(t => t.containerNo).ToList();
|
|
|
|
|
//List<WmsRawStock> wmsRawStocks = dbContext.WmsRawStock.Where(t => containerNos.Contains(t.palletInfoCode)).ToList();
|
|
|
|
|
//var thisOutList = wmsRawStocks.GroupBy(t => new { t.materialId, t.saleOrderId,t.palletInfoCode })
|
|
|
|
|
// .Select(t => new
|
|
|
|
|
// {
|
|
|
|
|
// palletInfoCode = t.Key.palletInfoCode,
|
|
|
|
|
// materialId = t.Key.materialId,
|
|
|
|
|
// saleOrderId = t.Key.saleOrderId,
|
|
|
|
|
// thisOutAmount = t.Sum(x => x.totalAmount) - t.Sum(x => x.frozenAmount)
|
|
|
|
|
// });
|
|
|
|
|
//List<WmsRawOutstock> endStationCodeOutRaw = wmsRawOutstocks.Where(t => t.endStationCode == baseEquip.endStationCode).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//List<long?> materialIds = endStationCodeOutRaw.Select(t => t.materialId).ToList();
|
|
|
|
|
//List<MesBaseMaterialInfo> mesBaseMaterialInfos = dbContext.MesBaseMaterialInfo.Where(t => materialIds.Contains(t.MaterialId)).ToList();
|
|
|
|
|
//var bill = endStationCodeOutRaw.GroupBy(t => new { t.materialId, t.materialBatch, t.saleOrderId })
|
|
|
|
|
// .Select(t => new
|
|
|
|
|
// {
|
|
|
|
|
// materialId = t.Key.materialId,
|
|
|
|
|
// materialBatch = t.Key.materialBatch,
|
|
|
|
|
// saleOrderId = t.Key.saleOrderId,
|
|
|
|
|
// outstockAmount = t.Sum(x => x.outstockAmount),
|
|
|
|
|
// realOutstockAmount = t.Sum(x => x.realOutstockAmount),
|
|
|
|
|
// });
|
|
|
|
|
//var orderNumber = from a in bill
|
|
|
|
|
// from b in thisOutList
|
|
|
|
|
// from c in mesBaseMaterialInfos
|
|
|
|
|
// where a.materialId == b.materialId && a.saleOrderId == b.saleOrderId && a.materialId ==c.MaterialId
|
|
|
|
|
// select new
|
|
|
|
|
// {
|
|
|
|
|
// palletInfoCode = b.palletInfoCode,
|
|
|
|
|
// materialBatch = a.materialBatch,
|
|
|
|
|
// saleOrderId = b.saleOrderId,
|
|
|
|
|
// outstockAmount = a.outstockAmount,
|
|
|
|
|
// materialSpec = c.MaterialSpec,
|
|
|
|
|
// realOutstockAmount = a.realOutstockAmount,
|
|
|
|
|
// thisOutAmount = b.thisOutAmount,
|
|
|
|
|
// isSendOver = a.outstockAmount <= (a.realOutstockAmount + b.thisOutAmount) ? "已出完" : "未出完"
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
Dispatcher.Invoke(() =>
|
|
|
|
|
{
|
|
|
|
|
|