diff --git a/YLErpWeb/Controllers/margin_template_v2Controller.cs b/YLErpWeb/Controllers/margin_template_v2Controller.cs index a0452fae..698c8b88 100644 --- a/YLErpWeb/Controllers/margin_template_v2Controller.cs +++ b/YLErpWeb/Controllers/margin_template_v2Controller.cs @@ -493,12 +493,16 @@ namespace YLErp.Web.Controllers //BUG-14:明细生效日期回写——前端新增行只带占位日期(2020-01-01 前后),此前不回写使新行(含模板拷贝) //落库 0001-01-01,被取数侧 Max(ValueDate) 分组静默丢弃;占位日期对齐本次提交行的最新生效日期,无有效行时用模板生效日期 + //明细生效日期跟主表走:主表有真实生效日期时全部行强制对齐(含复制带入的源模板行日期、行上残留的旧日期), + //否则只改主表日期会出现"模板已生效但明细未生效"的取数断档;主表仍为占位日期时保持原兜底 var placeholderDate = new DateTime(2020, 1, 1); - var effectiveValueDate = marginTemplate.Details - .Where(d => d.ValueDate > placeholderDate) - .Select(d => d.ValueDate) - .DefaultIfEmpty(marginTemplate.ValueDate > placeholderDate ? marginTemplate.ValueDate : placeholderDate) - .Max(); + var detailValueDate = marginTemplate.ValueDate > placeholderDate + ? marginTemplate.ValueDate + : marginTemplate.Details + .Where(d => d.ValueDate > placeholderDate) + .Select(d => d.ValueDate) + .DefaultIfEmpty(placeholderDate) + .Max(); marginTemplate.Details.ForEach(x => { @@ -509,7 +513,7 @@ namespace YLErp.Web.Controllers detail = new margin_template_detail(); yldb.margin_template_detail.Add(detail); } - detail.ValueDate = x.ValueDate > placeholderDate ? x.ValueDate : effectiveValueDate; + detail.ValueDate = detailValueDate; detail.MarginTemplateId = marginTemplate.id; detail.GroupRatio = x.GroupRatio; detail.MarginRatio1 = x.MarginRatio1;