From 1e44cebc3b2431651a2ac78df376d5cdbf3015fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Fri, 1 Dec 2023 17:04:01 +0800 Subject: [PATCH] =?UTF-8?q?QAD=E6=8E=A5=E5=8F=A3=E6=8B=86=E5=88=86BBAC=20J?= =?UTF-8?q?IS=E5=92=8CBBAC=E4=B9=B0=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bases/BA_SERVICE.cs | 15 - .../Entities/BQ/INVOICE_SERVICE.cs | 331 ++++++++++++++---- .../Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs | 7 + 3 files changed, 277 insertions(+), 76 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs index 856307bb..47beae43 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs @@ -604,21 +604,6 @@ namespace Win.Sfs.SettleAccount.Bases { errors.Add(new ERR_EXP_DTO() { Message = $"零件号{itm.LU},标识号(生产码){itm.PN}有重复数据!" }); } - - - - - - - - - - - - - - - return errors; } 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 5f1aea36..528f416a 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 @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Omu.ValueInjecter; using Polly; using SettleAccount.Domain.BQ; using Shouldly; @@ -126,81 +127,197 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// private async Task SubmitToQadSingle(string invbillNum) { + var invoiceGrp = _settleAccountDbContext.Set() .Where(t => t.InvbillNum == invbillNum) .Where(t => t.State == SettleBillState.已扣减) .FirstOrDefault(); - + if (invoiceGrp.BusinessType == EnumBusinessType.JisBBAC) + { + + var _detail = await _bbacMng.GetDetailAsync(invbillNum, EnumBusinessType.MaiDanJianBBAC).ConfigureAwait(false);//查出买单数量 + var invoiceGrpDetails = _settleAccountDbContext.Set() + .Where(t => t.InvbillNum == invbillNum) + .ToList(); + if (invoiceGrpDetails.Any()) + { + var tedSaInvs = new List(); + var taskId = GuidGenerator.Create(); + var teaTaskSub = new TEA_TASK_SUB() + { + GUID = taskId, + TaskState = 0, + TaskID = taskId, + TableName = "TED_SAS_INVOICE", + Creator = "SAS", + Subscriber = "QAD", + Domain = "BJBMPT", + Site = "BJ02", + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, + }; + List invdetials = new List(); + foreach (var itm in invoiceGrpDetails) + { + invdetials.Add(itm);//添加发票明细 + + + var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode ); + if (first == null) + { + continue; + } + itm.Qty = itm.Qty - first.Qty;//发票总数中去除 + itm.Amt = Math.Round(itm.Qty * itm.PRICE, 2); + var inv = new INVOICE_WAIT_DETAIL();//添加买单件 + inv.InjectFrom(itm); + inv.Qty= first.Qty; + inv.Amt = Math.Round(first.Qty * itm.PRICE, 2); + inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; + if (invoiceGrp.Site == "1046") + { + inv.SetProperty("ErpToLoc", "CC16"); + } + if (invoiceGrp.Site == "1040") + { + inv.SetProperty("ErpToLoc", "CC11"); + } + invdetials.Add(inv); + + } + + + for (var i = 0; i < invdetials.Count; i++) + { + var invoiceGrpDetail = invdetials[i]; + + tedSaInvs.Add(new TED_SAS_INVOICE() + { + GUID = GuidGenerator.Create(), + Dataid = GuidGenerator.Create(), + Taskid = taskId, + invoiceNumber = invoiceGrp.RealnvBillNum, + sasInvoiceNumber = invoiceGrp.InvbillNum, + Customer = invoiceGrp.ClientCode, + BillTo = invoiceGrp.ClientCode, + InvoiceDate = invoiceGrp.CreationTime, + Site = "BJ02", + PartNumber = invoiceGrpDetail.PartCode, + InvoiceQuatity = invoiceGrpDetail.Qty, + Price = invoiceGrpDetail.PRICE, + InvoiceNetAmount = invoiceGrpDetail.Amt, + InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), + TaxRate = 0.13m, + Location = invoiceGrp.GetProperty("ErpToLoc", string.Empty), + begintime = invoiceGrpDetail.BeginDate, + endtime = invoiceGrpDetail.EndDate, + domain = "BJBMPT", + LINE = (i + 1).ToString() + }); + } + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; + //红冲发票提交QAD + if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + { + await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + } + + await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); + await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + invoiceGrp.State = SettleBillState.已提交QAD; + //构建发票同步Qad状态表数据 + await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); + + await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); + var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { + TimeSpan.FromSeconds(1), + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(5) + }, (exception, timeSpan, retryCount, context) => + { + _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试"); + }); + await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); + } + + - if (invoiceGrp == null) - { - return; } - var invoiceGrpDetails = _settleAccountDbContext.Set() - .Where(t => t.InvbillNum == invbillNum) - .ToList(); - if (invoiceGrpDetails.Any()) + else { - var tedSaInvs = new List(); - var taskId = GuidGenerator.Create(); - var teaTaskSub = new TEA_TASK_SUB() + var invoiceGrpDetails = _settleAccountDbContext.Set() + .Where(t => t.InvbillNum == invbillNum) + .ToList(); + if (invoiceGrpDetails.Any()) { - GUID = taskId, - TaskState = 0, - TaskID = taskId, - TableName = "TED_SAS_INVOICE", - Creator = "SAS", - Subscriber = "QAD", - Domain = "BJBMPT", - Site = "BJ02", - CreateTime = DateTime.Now, - UpdateTime = DateTime.Now, - }; - for (var i = 0; i < invoiceGrpDetails.Count; i++) - { - var invoiceGrpDetail = invoiceGrpDetails[i]; - tedSaInvs.Add(new TED_SAS_INVOICE() + var tedSaInvs = new List(); + var taskId = GuidGenerator.Create(); + var teaTaskSub = new TEA_TASK_SUB() { - GUID = GuidGenerator.Create(), - Dataid = GuidGenerator.Create(), - Taskid = taskId, - invoiceNumber = invoiceGrp.RealnvBillNum, - sasInvoiceNumber = invoiceGrp.InvbillNum, - Customer = invoiceGrp.ClientCode, - BillTo = invoiceGrp.ClientCode, - InvoiceDate = invoiceGrp.CreationTime, + GUID = taskId, + TaskState = 0, + TaskID = taskId, + TableName = "TED_SAS_INVOICE", + Creator = "SAS", + Subscriber = "QAD", + Domain = "BJBMPT", Site = "BJ02", - PartNumber = invoiceGrpDetail.PartCode, - InvoiceQuatity = invoiceGrpDetail.Qty, - Price = invoiceGrpDetail.PRICE, - InvoiceNetAmount = invoiceGrpDetail.Amt, - InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), - TaxRate = 0.13m, - Location = invoiceGrp.GetProperty("ErpToLoc",string.Empty), - begintime = invoiceGrpDetail.BeginDate, - endtime = invoiceGrpDetail.EndDate, - domain = "BJBMPT", - LINE = (i + 1).ToString() - }); - } - tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; - //红冲发票提交QAD - if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) - { - await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); - } + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, + }; - await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); - await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); - invoiceGrp.State = SettleBillState.已提交QAD; - //构建发票同步Qad状态表数据 - await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); - await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); - var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { + + for (var i = 0; i < invoiceGrpDetails.Count; i++) + { + var invoiceGrpDetail = invoiceGrpDetails[i]; + + + + + tedSaInvs.Add(new TED_SAS_INVOICE() + { + GUID = GuidGenerator.Create(), + Dataid = GuidGenerator.Create(), + Taskid = taskId, + invoiceNumber = invoiceGrp.RealnvBillNum, + sasInvoiceNumber = invoiceGrp.InvbillNum, + Customer = invoiceGrp.ClientCode, + BillTo = invoiceGrp.ClientCode, + InvoiceDate = invoiceGrp.CreationTime, + Site = "BJ02", + PartNumber = invoiceGrpDetail.PartCode, + InvoiceQuatity = invoiceGrpDetail.Qty, + Price = invoiceGrpDetail.PRICE, + InvoiceNetAmount = invoiceGrpDetail.Amt, + InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), + TaxRate = 0.13m, + Location = invoiceGrp.GetProperty("ErpToLoc", string.Empty), + begintime = invoiceGrpDetail.BeginDate, + endtime = invoiceGrpDetail.EndDate, + domain = "BJBMPT", + LINE = (i + 1).ToString() + }); + } + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; + //红冲发票提交QAD + if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + { + await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + } + + await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); + await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + invoiceGrp.State = SettleBillState.已提交QAD; + //构建发票同步Qad状态表数据 + await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); + + await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); + var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), @@ -209,8 +326,100 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试"); }); - await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); + await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); + } + + + } + + + + + + //if (invoiceGrp == null) + //{ + // return; + //} + //var invoiceGrpDetails = _settleAccountDbContext.Set() + // .Where(t => t.InvbillNum == invbillNum) + // .ToList(); + //if (invoiceGrpDetails.Any()) + //{ + // var tedSaInvs = new List(); + // var taskId = GuidGenerator.Create(); + // var teaTaskSub = new TEA_TASK_SUB() + // { + // GUID = taskId, + // TaskState = 0, + // TaskID = taskId, + // TableName = "TED_SAS_INVOICE", + // Creator = "SAS", + // Subscriber = "QAD", + // Domain = "BJBMPT", + // Site = "BJ02", + // CreateTime = DateTime.Now, + // UpdateTime = DateTime.Now, + // }; + + + + // for (var i = 0; i < invoiceGrpDetails.Count; i++) + // { + // var invoiceGrpDetail = invoiceGrpDetails[i]; + + + + + // tedSaInvs.Add(new TED_SAS_INVOICE() + // { + // GUID = GuidGenerator.Create(), + // Dataid = GuidGenerator.Create(), + // Taskid = taskId, + // invoiceNumber = invoiceGrp.RealnvBillNum, + // sasInvoiceNumber = invoiceGrp.InvbillNum, + // Customer = invoiceGrp.ClientCode, + // BillTo = invoiceGrp.ClientCode, + // InvoiceDate = invoiceGrp.CreationTime, + // Site = "BJ02", + // PartNumber = invoiceGrpDetail.PartCode, + // InvoiceQuatity = invoiceGrpDetail.Qty, + // Price = invoiceGrpDetail.PRICE, + // InvoiceNetAmount = invoiceGrpDetail.Amt, + // InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), + // TaxRate = 0.13m, + // Location = invoiceGrp.GetProperty("ErpToLoc",string.Empty), + // begintime = invoiceGrpDetail.BeginDate, + // endtime = invoiceGrpDetail.EndDate, + // domain = "BJBMPT", + // LINE = (i + 1).ToString() + // }); + // } + // tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; + // //红冲发票提交QAD + // if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + // { + // await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + // } + + // await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); + // await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); + // invoiceGrp.State = SettleBillState.已提交QAD; + // //构建发票同步Qad状态表数据 + // await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); + + // await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); + // var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { + // TimeSpan.FromSeconds(1), + // TimeSpan.FromSeconds(5), + // TimeSpan.FromSeconds(5), + // TimeSpan.FromSeconds(5) + // }, (exception, timeSpan, retryCount, context) => + // { + // _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试"); + // }); + // await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); + //} } /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs index c85ee5b9..2b39bcaf 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs @@ -263,6 +263,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers return await _detailRepository.Where(p => p_invs.Contains(p.InvbillNum)).ToListAsync().ConfigureAwait(false); } + public virtual async Task> GetDetailAsync(string p_invbillnum,EnumBusinessType p_bussinesstype) + { + return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum && p.BusinessType==p_bussinesstype) + .GroupBy(p=>new { p.PartCode ,p.ContractDocID }).Select(p=> new BBAC_CAN_SA_DETAIL { Qty=p.Sum(itm=>itm.Qty),PartCode=p.Key.PartCode,ContractDocID=p.Key.ContractDocID }).ToListAsync(); + } + + } }