From 1df4c6c32a4fdff041a4d27590f4f7d39de7e46d Mon Sep 17 00:00:00 2001 From: mahao Date: Wed, 27 Sep 2023 17:55:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=90=E4=BA=A4QAD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/INVOICE_SERVICE.cs | 236 +++++++++--------- 1 file changed, 117 insertions(+), 119 deletions(-) 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 9adcfd7e..1b81d1fd 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 @@ -129,89 +129,91 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public virtual async Task SubmitToQad(List invbillNums) { - var invoiceGrps = _settleAccountDbContext.Set() - .Where(t => invbillNums.Contains(t.InvbillNum)) + for (var i = 0; i < invbillNums.Count; i++) + { + await SubmitToQadSingle(invbillNums[i]).ConfigureAwait(false); + } + return new OkResult(); + } + + /// + /// 提交到QAD + /// + private async Task SubmitToQadSingle(string invbillNum) + { + var invoiceGrp = _settleAccountDbContext.Set() + .Where(t => t.InvbillNum == invbillNum) .Where(t => t.State == SettleBillState.已扣减) - .ToList(); + .FirstOrDefault(); - invbillNums = invoiceGrps.Select(t => t.InvbillNum).ToList(); + if (invoiceGrp == null) + { + return; + } var invoiceGrpDetails = _settleAccountDbContext.Set() - .Where(t => invbillNums.Contains(t.InvbillNum)) + .Where(t => t.InvbillNum == invbillNum) .ToList(); - var taskId = GuidGenerator.Create(); - var teaTaskSub = new TEA_TASK_SUB() + 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, - }; - - var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => - { - return 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 = y.RealnvBillNum, - sasInvoiceNumber = y.InvbillNum, - Customer = y.ClientCode, - BillTo = y.ClientCode, - InvoiceDate = y.CreationTime, + GUID = taskId, + TaskState = 0, + TaskID = taskId, + TableName = "TED_SAS_INVOICE", + Creator = "SAS", + Subscriber = "QAD", + Domain = "BJBMPT", 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" + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, }; - }).ToList(); - var invoiceGrpTedSaInvs = invoiceGrps.Select(t => - { - return new TED_SAS_INVOICE() + for (var i = 0; i < invoiceGrpDetails.Count; i++) { - GUID = GuidGenerator.Create(), - 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.TaxDiff, - domain = "BJBMPT" - }; - }); + 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 = $"C{invoiceGrp.ClientCode}", + begintime = invoiceGrpDetail.BeginDate, + endtime = invoiceGrpDetail.EndDate, + domain = "BJBMPT", + LINE = (i + 1).ToString() + }); + } + + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; - tedSaInvs.AddRange(invoiceGrpTedSaInvs); - if (tedSaInvs.Any()) - { //红冲发票提交QAD - await SubmitToQadHongChong(invoiceGrps.Select(t => t.ParentInvbillNum).ToList()).ConfigureAwait(false); + if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + { + await SubmitToQadHongChong(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + } await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); - invoiceGrps.ForEach(t => t.State = SettleBillState.已提交QAD); + //invoiceGrp.State = SettleBillState.已提交QAD; await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); - var retryPolicyAsync = Policy.Handle().WaitAndRetryAsync(new[] { TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), @@ -223,74 +225,70 @@ namespace Win.Sfs.SettleAccount.Entities.BQ }); await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); } - - await Task.CompletedTask.ConfigureAwait(false); - return new OkResult(); } /// /// 红冲发票提交到QAD /// - private async Task SubmitToQadHongChong(List invbillNums) + private async Task SubmitToQadHongChong(string invbillNum) { - if (!invbillNums.Any()) + var invoiceGrp = _settleAccountDbContext.Set() + .Where(t => t.State == SettleBillState.已提交QAD) + .Where(t => t.InvbillNum == invbillNum) + .FirstOrDefault(); + if (invoiceGrp == null) { return; } - 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)) + .Where(t => t.InvbillNum == invbillNum) .ToList(); - 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, - }; - - var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => + if (invoiceGrpDetails.Any()) { - return 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 = y.RealnvBillNum, - sasInvoiceNumber = y.InvbillNum, - Customer = y.ClientCode, - BillTo = y.ClientCode, - InvoiceDate = y.CreationTime, + GUID = taskId, + TaskState = 0, + TaskID = taskId, + TableName = "TED_SAS_INVOICE", + Creator = "SAS", + Subscriber = "QAD", + Domain = "BJBMPT", 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" + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, }; - }).ToList(); - if (tedSaInvs.Any()) - { + 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 = $"C{invoiceGrp.ClientCode}", + begintime = invoiceGrpDetail.BeginDate, + endtime = invoiceGrpDetail.EndDate, + domain = "BJBMPT", + LINE = (i + 1).ToString() + }); + } await _exChangeCenterDbContext.Set().AddAsync(teaTaskSub).ConfigureAwait(false); await _exChangeCenterDbContext.Set().AddRangeAsync(tedSaInvs).ConfigureAwait(false); } @@ -492,8 +490,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ SettleDate = itm.SettleDate, ProductionGroup = itm.ProductionGroup, LineCode = itm.LineCode, - ContractID=itm.ContractID - + ContractID = itm.ContractID + }; entity.INVOICE_WAIT_DETAIL_BJ = bjquery.OrderBy(p => p.LineCode).ToList(); @@ -588,7 +586,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ SettleGroupNum = p.FirstOrDefault().SettleGroupNum, } ); - if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType==EnumBusinessType.YinDuJian)//BBAC直供未结 + if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.YinDuJian)//BBAC直供未结 { entity.INVOICE_MAP_GROUP = mdtos; //var all = entity.INVOICE_NOT_SETTLE.Select(p => p.SettleGroupNum).Distinct().ToList();//全部分组号 @@ -755,7 +753,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _excel.Append(hbpounsettle, "未结零件汇总"); } } - if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType== EnumBusinessType.YinDuJian) + if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.YinDuJian) { if (jitunsettle != null) {