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 e384fef0..b137542f 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 @@ -64,7 +64,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; /// - /// 数据中心S数据上下文 + /// 数据中心数据上下文 /// private readonly ExChangeCenterDbContext _exChangeCenterDbContext; @@ -118,6 +118,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// /// /// 已扣减发票提交到QAD + /// 查询状态为已扣减的数据 + /// 判断ParentInvbillNum是否有数据 + /// 有数据查询出对应发票数据状态为已提交QAD(置换成负数据)需要提交到QAD + /// 已扣减的数据提交到QAD /// 成功提交后修改状态为已提交QAD /// [HttpPost] @@ -161,18 +165,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ BillTo = y.ClientCode, InvoiceDate = y.CreationTime, Site = "BJ02", - TYPE = default, PartNumber = x.LU, InvoiceQuatity = x.Qty, Price = x.PRICE, - Supplier = default, - Remark = default, InvoiceNetAmount = x.Amt, - InvoiceTaxAmount = x.Amt * 0.13m, + InvoiceTaxAmount = Math.Round(x.Amt * 0.13m, 2), TaxRate = 0.13m, Location = $"C{y.ClientCode}", - InvoiceNet = default, - InvoiceTax = default, begintime = x.BeginDate, endtime = x.EndDate, Domain = "BJBMPT" @@ -185,27 +184,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { GUID = GuidGenerator.Create(), TaskID = taskId, - UID = default, InvoiceNumber = t.RealnvBillNum, SASInvoiceNumber = t.InvbillNum, Customer = t.ClientCode, BillTo = t.ClientCode, InvoiceDate = t.CreationTime, Site = "BJ02", - TYPE = default, - PartNumber = default, - InvoiceQuatity = default, - Price = default, - Supplier = default, - Remark = default, - InvoiceNetAmount = default, - InvoiceTaxAmount = default, TaxRate = 0.13m, Location = $"C{t.ClientCode}", - InvoiceNet = t.Amt, - InvoiceTax = default, - begintime = default, - endtime = default, + InvoiceTax = t.Amt, Domain = "BJBMPT" }; }); @@ -213,10 +200,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ tedSaInvs.AddRange(invoiceGrpTedSaInvs); if (tedSaInvs.Any()) { + //红冲发票提交QAD + 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.SaveChangesAsync().ConfigureAwait(false); invoiceGrps.ForEach(t => t.State = SettleBillState.已提交QAD); + + await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false); } @@ -224,6 +215,69 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return new OkResult(); } + /// + /// 红冲发票提交到QAD + /// + private async Task SubmitToQadHongChong(List invbillNums) + { + var invoiceGrps = _settleAccountDbContext.Set() + .Where(t => t.State == SettleBillState.已提交QAD) + .Where(t => invbillNums.Contains(t.InvbillNum)) + .ToList(); + + invbillNums = invoiceGrps.Select(t => t.InvbillNum).ToList(); + + var invoiceGrpDetails = _settleAccountDbContext.Set() + .Where(t => invbillNums.Contains(t.InvbillNum)) + .ToList(); + + var taskId = GuidGenerator.Create(); + var teaTaskSub = new TEA_TASK_SUB() + { + GUID = taskId, + TaskState = 0, + TaskID = taskId, + TableName = "TED_SA_INV", + Creator = "SAS", + Subscriber = "QAD", + Domain = "BJBMPT", + Site = "BJ02", + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, + }; + + var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => + { + return new TED_SA_INV() + { + GUID = GuidGenerator.Create(), + TaskID = taskId, + InvoiceNumber = y.RealnvBillNum, + SASInvoiceNumber = y.InvbillNum, + Customer = y.ClientCode, + BillTo = y.ClientCode, + InvoiceDate = y.CreationTime, + Site = "BJ02", + PartNumber = x.LU, + InvoiceQuatity = -x.Qty, + Price = x.PRICE, + InvoiceNetAmount = x.Amt, + InvoiceTaxAmount = Math.Round(x.Amt * 0.13m, 2), + TaxRate = 0.13m, + Location = $"C{y.ClientCode}", + begintime = x.BeginDate, + endtime = x.EndDate, + Domain = "BJBMPT" + }; + }).ToList(); + + if (tedSaInvs.Any()) + { + await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); + await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + } + } + /// /// 通过审核 /// @@ -599,7 +653,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { IExporter _csv = new CsvExporter(); ExcelExporter _excel = new ExcelExporter(); - // var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false); + // var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false); var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); var first = entities.FirstOrDefault(); var dtoDetails = ObjectMapper.Map, List>(entities);