diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs index c60480d0..9adcfd7e 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs @@ -49,6 +49,7 @@ using static Dm.parser.LVal; using static LinqToDB.Sql; using Win.Sfs.Shared.Filter; using Polly; +using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing; namespace Win.Sfs.SettleAccount.Entities.BQ { @@ -145,7 +146,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ GUID = taskId, TaskState = 0, TaskID = taskId, - TableName = "TED_SA_INV", + TableName = "TED_SAS_INVOICE", Creator = "SAS", Subscriber = "QAD", Domain = "BJBMPT", @@ -156,12 +157,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => { - return new TED_SA_INV() + return new TED_SAS_INVOICE() { GUID = GuidGenerator.Create(), - TaskID = taskId, - InvoiceNumber = y.RealnvBillNum, - SASInvoiceNumber = y.InvbillNum, + Dataid = GuidGenerator.Create(), + Taskid = taskId, + invoiceNumber = y.RealnvBillNum, + sasInvoiceNumber = y.InvbillNum, Customer = y.ClientCode, BillTo = y.ClientCode, InvoiceDate = y.CreationTime, @@ -175,26 +177,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Location = $"C{y.ClientCode}", begintime = x.BeginDate, endtime = x.EndDate, - Domain = "BJBMPT" + domain = "BJBMPT" }; }).ToList(); var invoiceGrpTedSaInvs = invoiceGrps.Select(t => { - return new TED_SA_INV() + return new TED_SAS_INVOICE() { GUID = GuidGenerator.Create(), - TaskID = taskId, - InvoiceNumber = t.RealnvBillNum, - SASInvoiceNumber = t.InvbillNum, + Taskid = taskId, + invoiceNumber = t.RealnvBillNum, + sasInvoiceNumber = t.InvbillNum, Customer = t.ClientCode, BillTo = t.ClientCode, InvoiceDate = t.CreationTime, Site = "BJ02", TaxRate = 0.13m, Location = $"C{t.ClientCode}", - InvoiceTax = t.Amt, - Domain = "BJBMPT" + InvoiceTax = t.TaxDiff, + domain = "BJBMPT" }; }); @@ -205,7 +207,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ await SubmitToQadHongChong(invoiceGrps.Select(t => t.ParentInvbillNum).ToList()).ConfigureAwait(false); await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); - await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); invoiceGrps.ForEach(t => t.State = SettleBillState.已提交QAD); await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); @@ -252,7 +254,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ GUID = taskId, TaskState = 0, TaskID = taskId, - TableName = "TED_SA_INV", + TableName = "TED_SAS_INVOICE", Creator = "SAS", Subscriber = "QAD", Domain = "BJBMPT", @@ -263,12 +265,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => { - return new TED_SA_INV() + return new TED_SAS_INVOICE() { GUID = GuidGenerator.Create(), - TaskID = taskId, - InvoiceNumber = y.RealnvBillNum, - SASInvoiceNumber = y.InvbillNum, + Dataid = GuidGenerator.Create(), + Taskid = taskId, + invoiceNumber = y.RealnvBillNum, + sasInvoiceNumber = y.InvbillNum, Customer = y.ClientCode, BillTo = y.ClientCode, InvoiceDate = y.CreationTime, @@ -282,14 +285,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Location = $"C{y.ClientCode}", begintime = x.BeginDate, endtime = x.EndDate, - Domain = "BJBMPT" + domain = "BJBMPT" }; }).ToList(); if (tedSaInvs.Any()) { await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); - await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TED_SAS_INVOICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TED_SAS_INVOICE.cs new file mode 100644 index 00000000..8be53ead --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/TED_SAS_INVOICE.cs @@ -0,0 +1,38 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Win.Sfs.SettleAccount.Entities.BQ +{ + public class TED_SAS_INVOICE + { + public int UID { get; set; } + public string invoiceNumber { get; set; } + public string sasInvoiceNumber { get; set; } + public string Customer { get; set; } + public string BillTo { get; set; } + public DateTime InvoiceDate { get; set; } + public string Site { get; set; } + public string TYPE { get; set; } + public string PartNumber { get; set; } + public decimal InvoiceQuatity { get; set; } + public decimal Price { get; set; } + public string Supplier { get; set; } + public string Remark { get; set; } + public decimal InvoiceNetAmount { get; set; } + public decimal InvoiceTaxAmount { get; set; } + public decimal TaxRate { get; set; } + public string Location { get; set; } + public decimal InvoiceNet { get; set; } + public decimal InvoiceTax { get; set; } + public DateTime begintime { get; set; } + public DateTime endtime { get; set; } + public string commandtype { get; set; } + public string domain { get; set; } + public string LINE { get; set; } + public Guid Taskid { get; set; } + public Guid Dataid { get; set; } + [Key] + public Guid GUID { get; set; } + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/ExChangeCenterDbContext.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/ExChangeCenterDbContext.cs index 0f98d446..ca27f1e5 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/ExChangeCenterDbContext.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/ExChangeCenterDbContext.cs @@ -10,6 +10,7 @@ namespace Win.Sfs.SettleAccount.EntityFrameworkCore public class ExChangeCenterDbContext : DbContext { public DbSet TEA_TASK_SUB { get; set; } + public DbSet TED_SAS_INVOICE { set; get; } public DbSet TED_SA_INV { set; get; } public ExChangeCenterDbContext(DbContextOptions options) : base(options) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs index c0400037..fbfdced1 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/PubSaSeCompareExportService.cs @@ -176,6 +176,11 @@ namespace SettleAccount.Job.Services.Report { return GetSaSeCompareDataYinDu(version); } + //备件对比 + if (businessType == EnumBusinessType.BeiJian) + { + return GetSaSeCompareDataBeiJian(version); + } //结算 var saGroup = from sa in _settleAccountDbContext.Set() where sa.BusinessType == businessType @@ -412,6 +417,163 @@ namespace SettleAccount.Job.Services.Report }).ToList(); return haveSaHaveSeList.Union(haveSaNotHaveSeList).Union(notHaveSaHaveSeList).ToList(); } + + /// + /// 获取比对数据备件 + /// + private List GetSaSeCompareDataBeiJian(int version) + { + var businessType = EnumBusinessType.BeiJian; + //结算 + var saGroup = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType + group sa by new { sa.PN, sa.PartCode } into groupItem + select new + { + groupItem.Key.PN, + FactoryPartCode = groupItem.Key.PartCode, + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + LU = groupItem.Max(t => t.LU), + SettleDate = groupItem.Max(t => t.SettleDate) + }; + + var saGroupByMappingType = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType && sa.MappingType == EnumMappingType.None + group sa by new { sa.PN, sa.PartCode } into groupItem + select new + { + groupItem.Key.PN, + FactoryPartCode = groupItem.Key.PartCode, + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + LU = groupItem.Max(t => t.LU), + SettleDate = groupItem.Max(t => t.SettleDate) + }; + var saGroupByVersion = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType && sa.Version == version + group sa by new { sa.PN, sa.PartCode } into groupItem + select new + { + groupItem.Key.PN, + FactoryPartCode = groupItem.Key.PartCode, + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + LU = groupItem.Max(t => t.LU), + SettleDate = groupItem.Max(t => t.SettleDate) + }; + + //发运 + var seGroup = from se in _settleAccountDbContext.Set() + where se.BusinessType == businessType + group se by new { se.PN, se.FactoryPartCode } into groupItem + select new + { + groupItem.Key.PN, + groupItem.Key.FactoryPartCode, + Qty = groupItem.Sum(t => t.Qty), + LU = groupItem.Max(t => t.LU), + WmsBillNum = groupItem.Max(t => t.WmsBillNum), + ShippingDate = groupItem.Max(t => t.ShippingDate), + ToLocCode = groupItem.Max(t => t.ToLocCode), + ToErpLocCode = groupItem.Max(t => t.ToErpLocCode) + }; + + //有结算无发运 + var haveSaNotHaveSeList = (from sa in saGroupByMappingType + join se in seGroup + on new { sa.PN, sa.FactoryPartCode } equals new { se.PN, se.FactoryPartCode } + into temp + from se in temp.DefaultIfEmpty() + where se.PN == null + select new SaSeCompareDiff() + { + Version = sa.Version, + CustomerOfflineTime = sa.SettleDate, + PN = sa.PN, + SAQty = sa.Qty, + SaCustomerPartCode = sa.LU, + SaFactoryPartCode = sa.FactoryPartCode, + CustomerPartCode = sa.LU + }).ToList(); + //无结算有发运 + var notHaveSaHaveSeList = (from se in seGroup + join sa in saGroup + on new { se.PN, se.FactoryPartCode } equals new { sa.PN, sa.FactoryPartCode } + into temp + from sa in temp.DefaultIfEmpty() + where sa.PN == null + select new SaSeCompareDiff() + { + WmsBillNum = se.WmsBillNum, + ShippingDate = se.ShippingDate, + PN = se.PN, + SEQty = se.Qty, + ToLocCode = se.ToLocCode, + ToErpLocCode = se.ToErpLocCode, + SeCustomerPartCode = se.LU, + SeFactoryPartCode = se.FactoryPartCode, + CustomerPartCode = se.LU + }).ToList(); + + //有结算有发运 + var haveSaHaveSeList = (from sa in saGroupByVersion + from se in seGroup + where sa.PN == se.PN && sa.FactoryPartCode == se.FactoryPartCode + select new SaSeCompareDiff() + { + Version = sa.Version, + WmsBillNum = se.WmsBillNum, + ShippingDate = se.ShippingDate, + CustomerOfflineTime = sa.SettleDate, + PN = sa.PN, + SAQty = sa.Qty, + SEQty = se.Qty, + ToLocCode = se.ToLocCode, + ToErpLocCode = se.ToErpLocCode, + SeCustomerPartCode = se.LU, + SeFactoryPartCode = se.FactoryPartCode, + SaCustomerPartCode = sa.LU, + SaFactoryPartCode = sa.FactoryPartCode, + CustomerPartCode = sa.LU + }).ToList(); + + var saGroupByPnPartCodeLu = from sa in _settleAccountDbContext.Set() + where sa.BusinessType == businessType && sa.Version == version + group sa by new { sa.PN, sa.PartCode, sa.LU } into groupItem + select new + { + groupItem.Key.PN, + FactoryPartCode = groupItem.Key.PartCode, + groupItem.Key.LU, + Qty = groupItem.Sum(t => t.Qty), + Version = groupItem.Max(t => t.Version), + SettleDate = groupItem.Max(t => t.SettleDate) + }; + var replaceLus = saGroupByPnPartCodeLu.ToList().GroupBy(t => new { t.PN, t.FactoryPartCode }).Select(t => + { + return new + { + t.Key.PN, + t.Key.FactoryPartCode, + LU = t.Select(t => t.LU).Distinct() + }; + }).Where(t => t.LU.Count() > 1); + + if (replaceLus.Any()) + { + haveSaHaveSeList.ForEach(haveSaHaveSe => + { + var replaceLu = replaceLus.FirstOrDefault(t => t.PN == haveSaHaveSe.PN && t.FactoryPartCode == haveSaHaveSe.SaFactoryPartCode); + if (replaceLu != null) + { + haveSaHaveSe.SaCustomerPartCode = string.Join(",", replaceLu.LU); + } + }); + } + + return haveSaHaveSeList.Union(haveSaNotHaveSeList).Union(notHaveSaHaveSeList).ToList(); + } #endregion } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs index 9bfa21f3..b3faf532 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SaSeCompareExportBaseService.cs @@ -323,7 +323,7 @@ namespace SettleAccount.Job.Services.Report select sa).ToList(); if (canSaDetails.Any()) { - var canSaDetailsUpdate = canSaDetails.Join(haveSaHaveSes, o => new { o.PN, o.LU }, i => new { i.PN, LU = i.CustomerPartCode }, (o, i) => + var canSaDetailsUpdate = canSaDetails.Join(haveSaHaveSes, o => new { o.PN, o.PartCode }, i => new { i.PN, PartCode = i.FactoryPartCode }, (o, i) => { o.ErpLoc = i.ToErpLocCode; o.RealPartCode = i.ReplaceFactoryPartCode; @@ -338,7 +338,7 @@ namespace SettleAccount.Job.Services.Report select sa).ToList(); if (notSaDetails.Any()) { - var notSaDetailsUpdate = notSaDetails.Join(haveSaHaveSes, o => new { o.PN, o.LU }, i => new { i.PN, LU = i.CustomerPartCode }, (o, i) => + var notSaDetailsUpdate = notSaDetails.Join(haveSaHaveSes, o => new { o.PN, o.PartCode }, i => new { i.PN, PartCode = i.FactoryPartCode }, (o, i) => { o.ErpLoc = i.ToErpLocCode; o.RealPartCode = i.ReplaceFactoryPartCode; @@ -368,7 +368,7 @@ namespace SettleAccount.Job.Services.Report .ToList(); if (saDetails.Any()) { - var saDetailsUpdate = saDetails.Join(haveSaHaveSes, o => new { o.PN, o.LU }, i => new { i.PN, LU = i.CustomerPartCode }, (o, i) => + var saDetailsUpdate = saDetails.Join(haveSaHaveSes, o => new { o.PN, o.PartCode }, i => new { i.PN, PartCode = i.FactoryPartCode }, (o, i) => { var mappingType = (i.SAQty - i.SEQty) switch {