diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs index 18d44caf..47711d1b 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMaterialReceiptD.cs @@ -68,17 +68,14 @@ public partial class PrdMaterialReceiptD : BaseEntity /// /// 供应商 /// - [SugarColumn(IsIgnore = true)] public string supplier_id { get; set; } /// /// 入库时间 /// - [SugarColumn(IsIgnore = true)] public DateTime instock_time { get; set; } /// /// 检验结论 /// - [SugarColumn(IsIgnore = true)] public string check_conclusion { get; set; } } \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs index d2135450..05bad995 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs @@ -192,5 +192,10 @@ public partial class PrdMoTask : BaseEntity /// 物料单位 /// public string? unit_id { get; set; } + + /// + /// 物料清单id + /// + public string? ebom_id { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index 29bcb5d6..fbc0b711 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -550,7 +550,8 @@ namespace Tnb.ProductionMgr return await _db.Queryable() .LeftJoin((a, b) => a.create_id == b.Id) .WhereIF(!string.IsNullOrEmpty(mo_task_id), (a, b) => a.mo_task_id == mo_task_id) - .WhereIF(ids!=null && ids.Count>0,(a,b)=>ids.Contains(a.mo_task_id)) + // .WhereIF(ids!=null && ids.Count>0,(a,b)=>ids.Contains(a.mo_task_id)) + .WhereIF(!string.IsNullOrEmpty(batch),(a,b)=>a.batch.Contains(batch)) .GroupBy((a,b)=>new {a.create_id,employee_name = b.RealName}) .Select((a, b) => new PrdMoFromManListOutput() { @@ -608,24 +609,226 @@ namespace Tnb.ProductionMgr { ids = await _db.Queryable().Where(x => x.batch.Contains(batch)).Select(x=>x.mo_task_id).ToListAsync(); } - - return await _db.Queryable() - .LeftJoin((a, b) => a.material_id == b.id) - .LeftJoin((a,b,c)=>a.material_receipt_detail_id==c.id) - .LeftJoin((a,b,c,d)=>c.supplier_id==d.id) - .LeftJoin((a,b,c,d,e)=>a.feeding_id==e.id) - .WhereIF(!string.IsNullOrEmpty(mo_task_id), (a, b,c,d,e) => e.mo_task_id == mo_task_id) - .WhereIF(ids!=null && ids.Count>0,(a,b,c,d,e)=>ids.Contains(a.id)) - .Select((a,b,c,d,e)=>new PrdMoFromMaterialListOutput() + PrdMoTask prdMoTask = await _db.Queryable().SingleAsync(x => x.id == mo_task_id); + PrdMo prdMo = await _db.Queryable().SingleAsync(x => x.id == prdMoTask.mo_id); + /* + * 注塑投料记录 1产出物料二维码为精确搜索 + * 2 不填产出物料二维码 则投入物料列表不计算批次等 + * 3 物料二维码为精确搜索时 按照先进先出的规则计算投入物料 + * 4 组装包装可投入物料组成 1)直接从生产线上流转下来的物料 2)投入的物料 + */ + if (string.IsNullOrEmpty(batch)) + { + if (prdMoTask.schedule_type == 1) { - material_code = b.code, - material_name = b.name, - batch = a.batch, - supplier_name = d.supplier_name, - check_conclusion = c.check_conclusion, - instock_time = c.instock_time.ToString("yyyy-MM-dd HH:mm:ss"), - feeding_time = e.create_time==null ? "" : e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), - }).ToListAsync(); + return await _db.Queryable() + .LeftJoin((a,b)=>a.id==b.ebom_id) + .LeftJoin((a,b,c)=>b.material_id==c.id) + .Where((a,b,c)=>a.id==prdMoTask.ebom_id) + .Select((a,b,c)=>new PrdMoFromMaterialListOutput() + { + material_code = c.code, + material_name = c.name, + }).ToListAsync(); + } + else + { + return await _db.Queryable() + .LeftJoin((a,b)=>a.material_id==b.id) + .Where((a,b)=>a.mbom_id==prdMoTask.bom_id) + .Select((a,b)=>new PrdMoFromMaterialListOutput() + { + material_code = b.code, + material_name = b.name, + }).ToListAsync(); + } + } + else + { + PrdReport prdReport = await _db.Queryable().Where(x => x.batch == batch).FirstAsync(); + List prdReports = await _db.Queryable().Where(x=>x.create_time<=prdReport.create_time && x.batch!=batch && x.mo_task_id==mo_task_id).ToListAsync(); + int? beforeReportNum = prdReports.Sum(x => x.reported_qty); + List prdFeedingIds = new List(); + if (prdMoTask.schedule_type == 1) + { + BasEbomH basEbomH = await _db.Queryable().SingleAsync(x => x.id == prdMoTask.ebom_id); + List basEbomDs = await _db.Queryable().Where(x => x.ebom_id == prdMoTask.ebom_id).ToListAsync(); + + foreach (var item in basEbomDs) + { + decimal? num1 = beforeReportNum / basEbomH.quantity * item.quantity; + List prdFeedingDs = await _db.Queryable() + .LeftJoin((a, b) => a.feeding_id == b.id) + .Where((a, b) => a.material_id == item.material_id && b.mo_task_id == mo_task_id) + .OrderBy((a,b)=>b.create_time) + .Select((a, b) => a).ToListAsync(); + decimal sum1 = 0; + decimal sum2 = 0; + foreach (var prdFeedingD in prdFeedingDs) + { + if (sum1 <= num1) + { + sum1 += prdFeedingD.num; + } + else + { + decimal? num2 = prdReport.reported_qty / basEbomH.quantity * item.quantity; + if (sum2 <= num2) + { + prdFeedingIds.Add(item.id); + } + else + { + break; + } + } + } + } + + return await _db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .LeftJoin((a, b, c) => a.material_receipt_detail_id == c.id) + .LeftJoin((a, b, c, d) => c.supplier_id == d.id) + .LeftJoin((a, b, c, d, e) => a.feeding_id == e.id) + .WhereIF(prdFeedingIds != null && prdFeedingIds.Count > 0, (a, b, c, d, e) => prdFeedingIds.Contains(a.id)) + .Select((a, b, c, d, e) => new PrdMoFromMaterialListOutput() + { + material_code = b.code, + material_name = b.name, + batch = a.batch, + supplier_name = d.supplier_name, + check_conclusion = c.check_conclusion, + instock_time = c.instock_time.ToString("yyyy-MM-dd HH:mm:ss"), + feeding_time = e.create_time == null ? "" : e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), + }).ToListAsync(); + + } + else + { + List basMbomInputs = await _db.Queryable().Where(x=>x.mbom_process_id==prdMoTask.mbom_process_id).ToListAsync(); + BasMbom basMbom = await _db.Queryable().SingleAsync(x => x.id == prdMoTask.bom_id); + BasMbomProcess basMbomProcess = await _db.Queryable().SingleAsync(x => x.id == prdMoTask.mbom_process_id); + List lastPrdReportIds = new List(); + foreach (var item in basMbomInputs) + { + decimal? num1 = beforeReportNum / basMbom.num * item.num; + List prdFeedingDs = await _db.Queryable() + .LeftJoin((a, b) => a.feeding_id == b.id) + .Where((a, b) => a.material_id == item.material_id && b.mo_task_id == mo_task_id) + .OrderBy((a,b)=>b.create_time) + .Select((a, b) => a).ToListAsync(); + + if (prdFeedingDs == null || prdFeedingDs.Count <= 0) + { + if (string.IsNullOrEmpty(basMbomProcess.last_process_no)) continue; + + List lastBasMbomProcesses = await _db.Queryable().Where(x=>x.no==basMbomProcess.last_process_no && x.mbom_id==prdMoTask.bom_id).ToListAsync(); + foreach (var lastBasMbomProcess in lastBasMbomProcesses) + { + List lastPrdReports = await _db.Queryable() + .Where(x=>x.mbom_process_id==lastBasMbomProcess.id && x.material_id==item.material_id) + .OrderBy(x=>x.create_time) + .ToListAsync(); + if (lastPrdReports == null || lastPrdReports.Count <= 0) continue; + + PrdMoTask lastPrdMoTask = await _db.Queryable().FirstAsync(x=>x.mo_id==prdMo.id && x.mbom_process_id==lastBasMbomProcess.id); + + decimal sum1 = 0; + decimal sum2 = 0; + foreach (var lastPrdReport in lastPrdReports) + { + if (sum1 <= num1) + { + sum1 += lastPrdReport.reported_qty ?? 0; + } + else + { + decimal? num2 = lastPrdReport.reported_qty / basMbom.num * item.num; + if (sum2 <= num2) + { + lastPrdReportIds.Add(lastPrdReport.id); + } + else + { + break; + } + } + } + + } + + + } + else + { + decimal sum1 = 0; + decimal sum2 = 0; + foreach (var prdFeedingD in prdFeedingDs) + { + if (sum1 <= num1) + { + sum1 += prdFeedingD.num; + } + else + { + decimal? num2 = prdReport.reported_qty / basMbom.num * item.num; + if (sum2 <= num2) + { + prdFeedingIds.Add(item.id); + } + else + { + break; + } + } + } + } + } + + var queryable1 = _db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .LeftJoin((a, b, c) => a.material_receipt_detail_id == c.id) + .LeftJoin((a, b, c, d) => c.supplier_id == d.id) + .LeftJoin((a, b, c, d, e) => a.feeding_id == e.id) + .WhereIF(!string.IsNullOrEmpty(mo_task_id), (a, b, c, d, e) => e.mo_task_id == mo_task_id) + .WhereIF(prdFeedingIds != null && prdFeedingIds.Count > 0, (a, b, c, d, e) => prdFeedingIds.Contains(a.id)) + .Select((a, b, c, d, e) => new PrdMoFromMaterialListOutput() + { + material_code = b.code, + material_name = b.name, + batch = a.batch, + supplier_name = d.supplier_name, + check_conclusion = c.check_conclusion, + instock_time = c.instock_time.ToString("yyyy-MM-dd HH:mm:ss"), + feeding_time = e.create_time == null ? "" : e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), + }); + + if (lastPrdReportIds != null && lastPrdReportIds.Count > 0) + { + var queryable2 = _db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .Where((a, b) => lastPrdReportIds.Contains(a.id)) + .Select((a, b) => new PrdMoFromMaterialListOutput() + { + material_code = b.code, + material_name = b.name, + batch = a.batch, + }); + + return await _db.UnionAll(queryable1, queryable2).ToListAsync(); + } + else + { + return await queryable1.ToListAsync(); + } + + } + } + + + + return null; + } #endregion