From 59ffbbf09ede44ecca516318a80682e060bfe076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Wed, 22 Jan 2025 13:30:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/INVOICE_SERVICE.cs | 136 +++++++++++++++--- 1 file changed, 117 insertions(+), 19 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 227a3e9c..8df06c33 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 @@ -159,8 +159,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var invoiceBBACGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisBBAC); - var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO); - var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO); + var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO && p.BusinessType != EnumBusinessType.MaiDanJianHBPO); + var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO || p.BusinessType == EnumBusinessType.MaiDanJianHBPO); if (invoiceBBACGrps.Any()) { var invlist = await invoiceBBACGrps.ToListAsync().ConfigureAwait(false); @@ -189,21 +189,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _globalConfigOptions.IsSyncInvoiceQadState = true; var invoiceGrps1 = _settleAccountDbContext.Set() .Where(t => invbillNums.Contains(t.InvbillNum) && t.State == SettleBillState.红冲发票); - //var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组 - //var invList=_settleAccountDbContext.Set().Where(p => grouplist.Contains(p.InvGroupNum)).ToList(); - //var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum } - // into temp - // from tm in temp.DefaultIfEmpty() - // where tm == null - // select itm; - - //var invoices = query.ToList(); - //if (invoices.Count > 0) - //{ - // var invbilllist=invoices.Select(p => p.InvGroupNum).ToList(); - // var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList(); - // throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400"); - //} + + foreach (var itm in invoiceGrps1) { itm.State = SettleBillState.提交QAD退回到已开票; @@ -216,11 +203,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var invoiceBBACGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisBBAC); var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO); var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO); + var invoiceMaidanGrps=invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.MaiDanJianHBPO); + + + if (invoiceBBACGrps.Any()) { var invlist = await invoiceBBACGrps.ToListAsync().ConfigureAwait(false); var billinvs = invlist.Select(p => p.InvbillNum).ToList(); - //await CreateBBACTaskAsync(billinvs).ConfigureAwait(false); await CreateBBACHongChongTaskAsync(billinvs).ConfigureAwait(false); } @@ -236,6 +226,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var billinvs = invlist.Select(p => p.InvbillNum).ToList(); await CreateHBPOHongChongTaskAsync(billinvs).ConfigureAwait(false); } + if (invoiceMaidanGrps.Any()) + { + var invlist = await invoiceMaidanGrps.ToListAsync().ConfigureAwait(false); + var billinvs = invlist.Select(p => p.InvbillNum).ToList(); + await CreateHBPOMaidanTaskAsync(billinvs).ConfigureAwait(false); + } return new OkResult(); } @@ -564,10 +560,109 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } } - private async Task CreateHBPOTaskAsync(List invoiceGrps) + private async Task CreateHBPOMaidanTaskAsync(List invoiceGrps) { + var codelist = _settleAccountDbContext.Set().Where(p => p.Project == "库位").ToList(); + var maidan = codelist.Where(p => p.Value == "MaiDanJianHBPO").FirstOrDefault().Description; + // 对发票组进行处理 + foreach (var itm in invoiceGrps) + { + // 获取发票相关的结算明细 + var ls = await _settleAccountDbContext.Set().Where(p => p.InvbillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); + // 获取发票信息 + var invoice = await _settleAccountDbContext.Set().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false); + // 获取调整明细 + if (ls.Any() && invoice != null) + { + // 获取所属站点信息 + var site = ls.FirstOrDefault().Site; + foreach (var itm1 in ls) + { + // 若ErpLoc为空则根据客户代码构建ErpLoc + if (string.IsNullOrEmpty(itm1.ErpLoc)) + { + itm1.ErpLoc = maidan; + } + } + // 按照ErpLoc、PartCode、BusinessType和Price对结算明细进行分组,并计算相关数据 + var details = ls.GroupBy(p => new { p.ErpLoc, p.PartCode, p.BusinessType, p.Price }) + .Select(p => new { Erploc = p.Key.ErpLoc, p.Key.PartCode, p.Key.BusinessType, Amt = Math.Round(p.Sum(t => t.Qty * t.Price), 2), Price = p.Key.Price, Qty = p.Sum(t => t.Qty) }).ToList(); + var tedSaInvs = new List(); + var taskId = GuidGenerator.Create(); + var teaTaskSub = new TEA_TASK_SUB() + { + // 初始化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, + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName + }; + for (var i = 0; i < details.Count; i++) + { + // 构建TED_SAS_INVOICE集合 + var invoiceGrpDetail = details[i]; + tedSaInvs.Add(new TED_SAS_INVOICE() + { + GUID = GuidGenerator.Create(), + Dataid = GuidGenerator.Create(), + Taskid = taskId, + invoiceNumber = invoice.RealnvBillNum, + sasInvoiceNumber = invoice.InvbillNum, + Customer = invoice.ClientCode, + BillTo = invoice.ClientCode, + InvoiceDate = invoice.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 = invoiceGrpDetail.Erploc, + begintime = DateTime.Now, + endtime = DateTime.Now, + domain = "BJBMPT", + LINE = (i + 1).ToString(), + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName + }); + } + var invbefore = invoice.RealAmt + invoice.TaxDiff;// + var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); + var invdiff = invbefore - invafter; + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + if (!string.IsNullOrEmpty(invoice.ParentInvbillNum)) + { + await CreatePubHongChongTaskAsync(new List() { invoice.ParentInvbillNum }).ConfigureAwait(false); + } + // 批量插入TEA_TASK_SUB记录 + await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + // 批量插入TED_SAS_INVOICE记录 + await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + // 设置发票状态为"已提交QAD" + invoice.State = SettleBillState.已提交QAD; + // 批量更新INVOICE_GRP记录 + await _repository.DbContext.BulkUpdateAsync(new List() { invoice }).ConfigureAwait(false); + // 异步绑定发票与QAD同步 + await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false); + } + } + + } + + + + private async Task CreateHBPOTaskAsync(List invoiceGrps) + { var invDetails = await _settleAccountDbContext.Set().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); + // var invDetails=await _settleAccountDbContext.Set().Where(p =>invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); foreach (var itm in invoiceGrps) { @@ -652,6 +747,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } } } + + + private async Task CreatePubHongChongTaskAsync(List invoiceGrps) { // 对发票组进行处理