From 12144334c0c61756d0a2f8f155254607689932f5 Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Wed, 22 May 2024 09:22:13 +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 --- .../appsettings.json | 2 +- .../Entities/BQ/INVOICE_SERVICE.cs | 1321 +++++++++++++---- .../Entities/BQ/JobHostdService.cs | 3 +- .../BQ/Syncs/MakeCanSettlementService.cs | 498 ++++--- .../Entities/BQ/Managers/INV_MNG.cs | 5 - .../Entities/BQ/Managers/PUB_NOT_SA_MNG.cs | 10 +- 6 files changed, 1302 insertions(+), 537 deletions(-) diff --git a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json index 79136466..77d7a65d 100644 --- a/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json +++ b/code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json @@ -5,7 +5,7 @@ "ConnectionStrings": { "Default": "Server=dev.ccwin-in.com,13326;Database=BJABP;User ID=sa;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True", //"SettleAccountService": "Server=dev.ccwin-in.com,13326;Database=BQ_SA;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True;", - "SettleAccountService": "Server=dev.ccwin-in.com,13326;Database=BQ_SA;User ID=sa;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True;", + "SettleAccountService": "Server=dev.ccwin-in.com,13326;Database=BQ_SA;User ID=sa;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True;Connection Timeout=120", "ExChangeCenterService": "Server=dev.ccwin-in.com,13326;Database=ExChangeCenter;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True;", "WMSBJBMPT": "Server=dev.ccwin-in.com,6208;Database=WMS_BJBMPT_2;User ID=sa;Password=ChangkeTec@2021;Trusted_Connection=False;TrustServerCertificate=True;", "questdb": "host=dev.ccwin-in.com;port=10580;username=admin;password=quest;database=vmi;ServerCompatibilityMode=NoTypeLoading;" 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 aeb41ea9..1261432e 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 @@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using System.Threading.Tasks; +using DocumentFormat.OpenXml.Bibliography; using DocumentFormat.OpenXml.Office2013.Word; using DocumentFormat.OpenXml.Presentation; using EFCore.BulkExtensions; @@ -20,6 +21,7 @@ using Microsoft.Extensions.Options; using Newtonsoft.Json; using Omu.ValueInjecter; using Polly; +using SettleAccount.Bases; using SettleAccount.Domain.BQ; using Shouldly; using SqlSugar; @@ -34,10 +36,13 @@ using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Managers; +using Win.Sfs.SettleAccount.Entities.Invoices; +using Win.Sfs.SettleAccount.Entities.Prices; using Win.Sfs.SettleAccount.EntityFrameworkCore; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.Options; +using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; using Win.Sfs.Shared.Filter; using Win.Sfs.Shared.RepositoryBase; @@ -67,6 +72,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private readonly HBPO_CAN_SA_MNG _hbpoMng; private readonly INV_MNG _invMng; private readonly BaseDomainService _baseservice; + + private readonly INormalEfCoreRepository _priceRepository; + private readonly INormalEfCoreRepository _priceYinDuRepository; + private readonly INormalEfCoreRepository _pricebjRepository; + + + public INVOICE_SERVICE( ILogger logger, SettleAccountDbContext settleAccountDbContext, @@ -80,7 +92,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ INormalEfCoreRepository sRepository, INormalEfCoreRepository mRepository, INormalEfCoreRepository adjRepository, - BaseDomainService baseservice, + INormalEfCoreRepository priceRepository, + INormalEfCoreRepository priceYinDuRepository, + INormalEfCoreRepository pricebjRepository, + + + + + BaseDomainService baseservice, PUB_CAN_SA_MNG pubMng, BBAC_CAN_SA_MNG bbacMng, HBPO_CAN_SA_MNG hbpoMng, @@ -101,6 +120,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _bbacMng = bbacMng; _hbpoMng = hbpoMng; _invMng = invMng; + _pricebjRepository = pricebjRepository; + _priceRepository = priceRepository; + _priceYinDuRepository= priceYinDuRepository; } /// @@ -119,49 +141,619 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public virtual async Task SubmitToQad(List invbillNums) { _globalConfigOptions.IsSyncInvoiceQadState = true; - for (var i = 0; i < invbillNums.Count; i++) + + var invoiceGrps = _settleAccountDbContext.Set() + .Where(t => invbillNums.Contains(t.InvbillNum)); + var invoiceBBACGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisBBAC).Where(t => t.State == SettleBillState.已扣减).Select(p=>p.InvbillNum); + var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO) + .Where(t => t.State == SettleBillState.已扣减).Select(p=>p.InvbillNum); + var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO).Where(t => t.State == SettleBillState.已扣减).Select(p=>p.InvbillNum); + if (invoiceBBACGrps.Any()) + { + await CreateBBACTaskAsync(invoiceBBACGrps.ToList()).ConfigureAwait(false); + } + if (invoicePubGrps.Any()) + { + await CreatePubTaskAsync(invoicePubGrps.ToList()).ConfigureAwait(false); + } + if (invoiceHbpoGrps.Any()) { - await SubmitToQadSingle(invbillNums[i]).ConfigureAwait(false); + await CreateHBPOTaskAsync(invoiceHbpoGrps.ToList()).ConfigureAwait(false); } + return new OkResult(); } - [UnitOfWork(false)] + //[UnitOfWork(false)] /// /// 提交到QAD /// - private async Task SubmitToQadSingle(string invbillNum) + //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().AsNoTracking() + // .Where(t => t.InvbillNum == invbillNum) + // .ToList(); + // var invoiceGrpDetailsCopy = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); + + // var invmaidanlist= await _bbacMng.GetOnlyMaiDanAsync(invbillNum); + // if (invmaidanlist != null && invmaidanlist.Count() > 0) + // { + // var query = from itm1 in invoiceGrpDetails + // join itm2 in invmaidanlist + // on new { PartCode = itm1.PartCode, ContractDocID = itm1.Extend1 } + // equals new { PartCode = itm2.PartCode, itm2.ContractDocID } + // into temp + // from j in temp.DefaultIfEmpty() + // where j == null + // select itm1; + // invoiceGrpDetails = query.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, + // Remark=string.IsNullOrEmpty(invoiceGrp.FileName)?string.Empty:invoiceGrp.FileName + // }; + // List invdetials = new List(); + // var invoiceGrpDetails1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); + // foreach (var itm in invoiceGrpDetails1) + // { + // var inv = new INVOICE_WAIT_DETAIL();//添加买单件 + // inv.InjectFrom(itm); + // var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode); + // if (first == null) + // { + // inv.Extend2= $"C{invoiceGrp.ClientCode}"; + // invdetials.Add(inv);//添加发票明细 + // continue; + // } + // else + // { + // if (itm.Qty >= first.Qty) + // { + // inv.Qty = itm.Qty - first.Qty;//发票总数中去除 + // inv.Amt = Math.Round((itm.Qty - first.Qty) * itm.PRICE, 2); + // inv.Extend2 = $"C{invoiceGrp.ClientCode}"; + // } + // //inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; + // //if (invoiceGrp.Site == "1046") + // //{ + // // inv.Extend2 = "CC16"; + // //} + // //if (invoiceGrp.Site == "1040") + // //{ + // // inv.Extend2 ="CC11"; + // //} + // invdetials.Add(inv); + // } + // } + // foreach (var itm in _detail) + // { + // var inv = new INVOICE_WAIT_DETAIL(); + + // var first= invoiceGrpDetailsCopy.FirstOrDefault(p=>p.PartCode==itm.PartCode); + // inv.InjectFrom(first); + // inv.LU = itm.LU; + // inv.PartCode = itm.PartCode; + // inv.Qty = itm.Qty; + // inv.PRICE = first.PRICE; + // inv.Amt = Math.Round(itm.Qty * first.PRICE, 2); + // inv.Extend1 = itm.ContractDocID; + // inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; + + // if (invoiceGrp.Site == "1046") + // { + // inv.Extend2 = "CC16"; + // } + // if (invoiceGrp.Site == "1040") + // { + // inv.Extend2 = "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, + // Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName, + // Location = invoiceGrpDetail.Extend2, + // begintime = invoiceGrpDetail.BeginDate, + // endtime = invoiceGrpDetail.EndDate, + // domain = "BJBMPT", + // LINE = (i + 1).ToString() + // }); + // } + // var tedsaInvs1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(tedSaInvs)); + // //var invbefore = invoiceGrp.TaxAmt + invoiceGrp.TaxDiff; + + // var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + // var invafter = tedsaInvs1.Sum(p => p.InvoiceTaxAmount); + // var invdiff = invbefore - invafter; + + // //invoiceGrp.RealAmt + invoiceGrp.TaxDiff-invafter; + // tedsaInvs1.FirstOrDefault().InvoiceTaxAmount += invdiff; + // //红冲发票提交QAD + // if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + // { + // await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + // } + // await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + // await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false); + // invoiceGrp.State = SettleBillState.已提交QAD; + // await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); + // await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); + // } + // } + // else + // { + // 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, + // Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName + // }; + // for (var i = 0; i < invoiceGrpDetails.Count; i++) + // { + // var invoiceGrpDetail = invoiceGrpDetails[i]; + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.MaiDanJianHBPO) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", "CC14"); + // } + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.BeiJian) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", "CC005"); + // } + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.JisHBPO) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); + // } + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.ZhiGongJianBBAC) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); + // } + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.ZhiGongJianHBPO) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); + // } + // if (invoiceGrpDetail.BussiessType == EnumBusinessType.YinDuJian) + // { + // invoiceGrpDetail.SetProperty("ErpToLoc", "CC001"); + // } + // 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 = invoiceGrpDetail.GetProperty("ErpToLoc", string.Empty), + // begintime = invoiceGrpDetail.BeginDate, + // endtime = invoiceGrpDetail.EndDate, + // domain = "BJBMPT", + // LINE = (i + 1).ToString() + // }); + // } + + // var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + // var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); + // var invdiff = invbefore - invafter; + + + // tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + + + // //tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; + // //红冲发票提交QAD + // if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + // { + // await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + // } + // await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + // await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + // invoiceGrp.State = SettleBillState.已提交QAD; + // await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); + // await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); + // } + // } + //} + + /// + /// 红冲发票提交到QAD + /// + //private async Task SubmitToQadHongChongAsync(string invbillNum, List p_detail = null) + //{ + // var invoiceGrp = await _settleAccountDbContext.Set() + // .Where(t => t.State == SettleBillState.红冲发票) + // .Where(t => t.InvbillNum == invbillNum) + // .FirstOrDefaultAsync().ConfigureAwait(false); + // List priceList = new List(); + + // if (first.BusinessType == EnumBusinessType.BeiJian) + // { + // var priceListbj = _pricebjRepository.Where(p => p.IsCancel == false).ToList(); //价格单 + // foreach (var itm in priceListbj) + // { + // priceList.Add(new PriceList() { LU = itm.LU, BeginTime = itm.BeginDate, EndTime = itm.EndDate, Price = itm.Price, ClientCode = itm.ClientCode }); + // } + // } + // else if (first.BusinessType == EnumBusinessType.YinDuJian) + // { + // var priceListyd = _priceydRepository.Where(p => p.IsCancel == false).ToList(); //价格单 + // foreach (var itm in priceListyd) + // { + // priceList.Add(new PriceList() { LU = itm.LU, BeginTime = itm.BeginDate, EndTime = itm.EndDate, Price = itm.Price, ClientCode = itm.ClientCode }); + // } + // } + // else + // { + // priceList = _priceRepository.Where(p => p.IsCancel == false).ToList();//价格单 + // } + // if (invoiceGrp == null) + // { + // return; + // } + // if (p_detail != null && p_detail.Count > 0) + // { + // var _detail = p_detail.ToList(); + // var invoiceGrpDetails = _settleAccountDbContext.Set().AsNoTracking() + // .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, + // Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName + // }; + // List invdetials = new List(); + + // var invoiceGrpDetails1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); + // foreach (var itm in invoiceGrpDetails1) + // { + // var inv = new INVOICE_WAIT_DETAIL();//添加买单件 + // inv.InjectFrom(itm); + // var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode); + // if (first == null) + // { + // inv.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); + // invdetials.Add(itm);//添加发票明细 + // continue; + // } + // else + // { + // if (itm.Qty > first.Qty) + // { + // inv.Qty = itm.Qty - first.Qty;//发票总数中去除 + // inv.Amt = Math.Round(itm.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 = invoiceGrpDetail.GetProperty("ErpToLoc", string.Empty), + // begintime = invoiceGrpDetail.BeginDate, + // endtime = invoiceGrpDetail.EndDate, + // Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName, + // domain = "BJBMPT", + // LINE = (i + 1).ToString() + // }); + // } + + // var tedsaInvs1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(tedSaInvs)); + // var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + // var invafter = tedsaInvs1.Sum(p => p.InvoiceTaxAmount); + // var invdiff = invbefore - invafter; + // tedsaInvs1.FirstOrDefault().InvoiceTaxAmount += invdiff; + // //invbefore= invafter +x; + // //var line1 = tedsaInvs1.FirstOrDefault(p => p.LINE == "1"); + // //var line2 = tedsaInvs1.FirstOrDefault(p => p.LINE == "2"); + // ////line2.InvoiceTaxAmount += invdiff; + // //line1.InvoiceTaxAmount += invdiff; + // //红冲发票提交QAD + // await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + // foreach (var itm in tedsaInvs1) + // { + // itm.InvoiceQuatity = -itm.InvoiceQuatity; + // itm.InvoiceNetAmount = -itm.InvoiceNetAmount; + // itm.InvoiceTaxAmount = -itm.InvoiceTaxAmount; + // } + // await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false); + // invoiceGrp.State = SettleBillState.已提交QAD; + // await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); + // await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); + // } + // } + // else + // { + + // 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, + // Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName + // }; + // 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 = DateTime.Now, + // endtime = DateTime.Now, + // domain = "BJBMPT", + // LINE = (i + 1).ToString() + // }); + // } + // var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + // var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); + // var invdiff = invbefore - invafter; + + // tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + + + // //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.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + // foreach (var itm in tedSaInvs) + // { + // itm.InvoiceQuatity = -itm.InvoiceQuatity; + // itm.InvoiceNetAmount = -itm.InvoiceNetAmount; + // itm.InvoiceTaxAmount = -itm.InvoiceTaxAmount; + // } + // await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + // invoiceGrp.State = SettleBillState.已提交QAD; + // await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); + // await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); + + // } + // } + //} + + /// + /// 构建发票同步Qad状态表数据 + /// + private async Task BindInvoiceSyncQadAsync(TEA_TASK_SUB teaTaskSub, string invoiceNumber, string sasInvoiceNumber, string customer,DateTime dateTime) { - var invoiceGrp = _settleAccountDbContext.Set() - .Where(t => t.InvbillNum == invbillNum) - .Where(t => t.State == SettleBillState.已扣减) - .FirstOrDefault(); - if (invoiceGrp.BusinessType == EnumBusinessType.JisBBAC) + var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber,dateTime) { - var _detail = await _bbacMng.GetDetailAsync(invbillNum, EnumBusinessType.MaiDanJianBBAC).ConfigureAwait(false);//查出买单数量 - var invoiceGrpDetails = _settleAccountDbContext.Set().AsNoTracking() - .Where(t => t.InvbillNum == invbillNum) - .ToList(); - var invoiceGrpDetailsCopy = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); - - var invmaidanlist= await _bbacMng.GetOnlyMaiDanAsync(invbillNum); - if (invmaidanlist != null && invmaidanlist.Count() > 0) + + TableName = teaTaskSub.TableName, + Domain = teaTaskSub.Domain, + Site = teaTaskSub.Site, + Customer = customer + }; + invoiceSyncQad.SetId(teaTaskSub.TaskID); + await _settleAccountDbContext.BulkInsertAsync(new List() { invoiceSyncQad }).ConfigureAwait(false); + } + + + private async Task> ChangedPrice(EnumBusinessType businessType, List p_list) where T : SA_CAN_BASE, new() + { + List priceList = new List(); + if (businessType == EnumBusinessType.BeiJian) + { + var priceListbj =await _pricebjRepository.Where(p => p.IsCancel == false).ToListAsync().ConfigureAwait(false); //价格单 + foreach (var itm in priceListbj) { - var query = from itm1 in invoiceGrpDetails - join itm2 in invmaidanlist - on new { PartCode = itm1.PartCode, ContractDocID = itm1.Extend1 } - equals new { PartCode = itm2.PartCode, itm2.ContractDocID } - into temp - from j in temp.DefaultIfEmpty() - where j == null - select itm1; - invoiceGrpDetails = query.ToList(); + priceList.Add(new PriceList() { LU = itm.LU, BeginTime = itm.BeginDate, EndTime = itm.EndDate, Price = itm.Price, ClientCode = itm.ClientCode }); } - if (invoiceGrpDetails.Any()) + } + else if (businessType == EnumBusinessType.YinDuJian) + { + var priceListyd =await _priceYinDuRepository.Where(p => p.IsCancel == false).ToListAsync().ConfigureAwait(false); //价格单 + foreach (var itm in priceListyd) { + priceList.Add(new PriceList() { LU = itm.LU, BeginTime = itm.BeginDate, EndTime = itm.EndDate, Price = itm.Price, ClientCode = itm.ClientCode }); + } + } + else + { + priceList =await _priceRepository.Where(p => p.IsCancel == false).ToListAsync().ConfigureAwait(false);//价格单 + } + List priceLists = new List(); + foreach (var itm in p_list) + { + var priceListEntity = priceList.Where(p => p.IsCancel == false) + .Where(t => t.LU == itm.LU) + .Where(t => itm.SettleDate >= t.BeginTime && itm.SettleDate <= t.EndTime && t.ClientCode == itm.Site) + .OrderByDescending(t => t.Date) + .ThenByDescending(t => t.CreationTime) + .FirstOrDefault(); + if (priceListEntity != null) + { + itm.Price = priceListEntity.Price; + } + else + { + itm.Price = 0; + } + } + var ls = new List(); + foreach (var itm in p_list) + { + ls.Add( + new T() + { + Price = itm.Price, + ErpLoc = string.Empty, + BusinessType = businessType, + Qty = itm.Qty, + } + ); + } + return ls; + } + + + private async Task CreatePubTaskAsync(List invoiceGrps) + { + // 对发票组进行处理 + 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); + // 获取调整明细 + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 + if (ls.Any() && invoice != null) + { + if (adj.Any())//假如存在调整单 + { + var adjlist= await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + // 获取所属站点信息 + var site = ls.FirstOrDefault().Site; + foreach (var itm1 in ls) + { + // 若ErpLoc为空则根据客户代码构建ErpLoc + if (string.IsNullOrEmpty(itm1.ErpLoc)) + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } + } + // 按照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, @@ -172,138 +764,193 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Site = "BJ02", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, - Remark=string.IsNullOrEmpty(invoiceGrp.FileName)?string.Empty:invoiceGrp.FileName + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName }; - List invdetials = new List(); - - - var invoiceGrpDetails1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); - foreach (var itm in invoiceGrpDetails1) + for (var i = 0; i < details.Count; i++) { - var inv = new INVOICE_WAIT_DETAIL();//添加买单件 - inv.InjectFrom(itm); - var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode); - if (first == null) - { - inv.Extend2= $"C{invoiceGrp.ClientCode}"; - invdetials.Add(inv);//添加发票明细 - continue; - } - else + // 构建TED_SAS_INVOICE集合 + var invoiceGrpDetail = details[i]; + tedSaInvs.Add(new TED_SAS_INVOICE() { - if (itm.Qty >= first.Qty) - { - inv.Qty = itm.Qty - first.Qty;//发票总数中去除 - inv.Amt = Math.Round((itm.Qty - first.Qty) * itm.PRICE, 2); - inv.Extend2 = $"C{invoiceGrp.ClientCode}"; - } - //inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; - //if (invoiceGrp.Site == "1046") - //{ - // inv.Extend2 = "CC16"; - //} - //if (invoiceGrp.Site == "1040") - //{ - // inv.Extend2 ="CC11"; - //} - invdetials.Add(inv); - } + 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() + }); } - foreach (var itm in _detail) + 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)) { - var inv = new INVOICE_WAIT_DETAIL(); - - var first= invoiceGrpDetailsCopy.FirstOrDefault(p=>p.PartCode==itm.PartCode); - inv.InjectFrom(first); - inv.LU = itm.LU; - inv.PartCode = itm.PartCode; - inv.Qty = itm.Qty; - inv.PRICE = first.PRICE; - inv.Amt = Math.Round(itm.Qty * first.PRICE, 2); - inv.Extend1 = itm.ContractDocID; - inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; - - if (invoiceGrp.Site == "1046") + 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 CreateBBACTaskAsync(List invoiceGrps) + { + var invDetails = await _settleAccountDbContext.Set().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); + foreach (var itm in invoiceGrps) + { + var ls = invDetails.Where(p => p.InvbillNum == itm).ToList(); + var invoice = await _settleAccountDbContext.Set().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false); + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 + if (ls.Any() && invoice != null) + { + if (adj.Any())//假如存在调整单 + { + var adjlist = await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + + foreach (var itm1 in ls) + { + if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1046") { - inv.Extend2 = "CC16"; + if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) + { + itm1.ErpLoc = "CC16"; + } + else + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } } - if (invoiceGrp.Site == "1040") + if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1040") { - inv.Extend2 = "CC11"; + if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) + { + itm1.ErpLoc = "CC11"; + } + else + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } } - invdetials.Add(inv); } - for (var i = 0; i < invdetials.Count; i++) + 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() { - var invoiceGrpDetail = invdetials[i]; + 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++) + { + var invoiceGrpDetail = details[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, + 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, + Price = invoiceGrpDetail.Price, InvoiceNetAmount = invoiceGrpDetail.Amt, InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), TaxRate = 0.13m, - Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName, - Location = invoiceGrpDetail.Extend2, - begintime = invoiceGrpDetail.BeginDate, - endtime = invoiceGrpDetail.EndDate, + Location = invoiceGrpDetail.Erploc, + begintime = DateTime.Now, + endtime = DateTime.Now, domain = "BJBMPT", LINE = (i + 1).ToString() }); } - - var tedsaInvs1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(tedSaInvs)); - //var invbefore = invoiceGrp.TaxAmt + invoiceGrp.TaxDiff; - - var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// - var invafter = tedsaInvs1.Sum(p => p.InvoiceTaxAmount); + var invbefore = invoice.RealAmt + invoice.TaxDiff;// + var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); var invdiff = invbefore - invafter; - - //invoiceGrp.RealAmt + invoiceGrp.TaxDiff-invafter; - tedsaInvs1.FirstOrDefault().InvoiceTaxAmount += invdiff; - //红冲发票提交QAD - if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + if (!string.IsNullOrEmpty(invoice.ParentInvbillNum)) { - await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); + await CreateBBACHongChongTaskAsync(new List(){invoice.ParentInvbillNum}).ConfigureAwait(false); } await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); - await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false); - invoiceGrp.State = SettleBillState.已提交QAD; - await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); - await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); - - + await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + invoice.State = SettleBillState.已提交QAD; + await _repository.DbContext.BulkUpdateAsync(new List() { invoice }).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false); } } - else - { - - var invoiceGrpDetails = _settleAccountDbContext.Set() - .Where(t => t.InvbillNum == invbillNum) - .ToList(); - - - + } + private async Task CreateHBPOTaskAsync(List invoiceGrps) + { + var invDetails=await _settleAccountDbContext.Set().Where(p =>invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); + foreach (var itm in invoiceGrps) + { + var ls = invDetails.Where(p => p.InvbillNum == itm).ToList(); + var invoice = await _settleAccountDbContext.Set().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false); + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 + if (ls.Any() && invoice != null) + { + if (adj.Any())//假如存在调整单 + { + var adjlist = await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + foreach (var itm1 in ls) + { + if (string.IsNullOrEmpty(itm1.ErpLoc)) + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } + } + 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(); - if (invoiceGrpDetails.Any()) - { - var tedSaInvs = new List(); var taskId = GuidGenerator.Create(); var teaTaskSub = new TEA_TASK_SUB() { @@ -317,111 +964,90 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Site = "BJ02", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, - Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName - + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName }; - for (var i = 0; i < invoiceGrpDetails.Count; i++) + for (var i = 0; i < details.Count; i++) { - var invoiceGrpDetail = invoiceGrpDetails[i]; - - if (invoiceGrpDetail.BussiessType == EnumBusinessType.MaiDanJianHBPO) - { - invoiceGrpDetail.SetProperty("ErpToLoc", "CC14"); - } - if (invoiceGrpDetail.BussiessType == EnumBusinessType.BeiJian) - { - invoiceGrpDetail.SetProperty("ErpToLoc", "CC005"); - } - if (invoiceGrpDetail.BussiessType == EnumBusinessType.JisHBPO) - { - invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); - } - if (invoiceGrpDetail.BussiessType == EnumBusinessType.ZhiGongJianBBAC) - { - invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); - } - if (invoiceGrpDetail.BussiessType == EnumBusinessType.ZhiGongJianHBPO) - { - invoiceGrpDetail.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); - } - if (invoiceGrpDetail.BussiessType == EnumBusinessType.YinDuJian) - { - invoiceGrpDetail.SetProperty("ErpToLoc", "CC001"); - } + var invoiceGrpDetail = details[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, + 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, + Price = invoiceGrpDetail.Price, InvoiceNetAmount = invoiceGrpDetail.Amt, InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), TaxRate = 0.13m, - Location = invoiceGrpDetail.GetProperty("ErpToLoc", string.Empty), - begintime = invoiceGrpDetail.BeginDate, - endtime = invoiceGrpDetail.EndDate, + Location = invoiceGrpDetail.Erploc, + begintime = DateTime.Now, + endtime = DateTime.Now, domain = "BJBMPT", LINE = (i + 1).ToString() }); } - - var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + var invbefore = invoice.RealAmt + invoice.TaxDiff;// var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); var invdiff = invbefore - invafter; - - tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; - - - //tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; - //红冲发票提交QAD - if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) + if (!string.IsNullOrEmpty(invoice.ParentInvbillNum)) { - await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); - } - await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + await CreateHBPOHongChongTaskAsync(new List() { invoice.ParentInvbillNum }).ConfigureAwait(false); + } + await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); - invoiceGrp.State = SettleBillState.已提交QAD; - await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); - await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); + invoice.State = SettleBillState.已提交QAD; + await _repository.DbContext.BulkUpdateAsync(new List() { invoice }).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false); } } - } - /// - /// 红冲发票提交到QAD - /// - private async Task SubmitToQadHongChongAsync(string invbillNum, List p_detail = null) + + + private async Task CreatePubHongChongTaskAsync(List invoiceGrps) { - var invoiceGrp = _settleAccountDbContext.Set() - .Where(t => t.State == SettleBillState.红冲发票) - .Where(t => t.InvbillNum == invbillNum) - .FirstOrDefault(); - if (invoiceGrp == null) - { - return; - } - if (p_detail != null && p_detail.Count > 0) + // 对发票组进行处理 + foreach (var itm in invoiceGrps) { - var _detail = p_detail.ToList(); - var invoiceGrpDetails = _settleAccountDbContext.Set().AsNoTracking() - .Where(t => t.InvbillNum == invbillNum) - .ToList(); - if (invoiceGrpDetails.Any()) + // 获取发票相关的结算明细 + 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); + // 获取调整明细 + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 + if (ls.Any() && invoice != null) { + if (adj.Any())//假如存在调整单 + { + var adjlist = await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + // 获取所属站点信息 + var site = ls.FirstOrDefault().Site; + foreach (var itm1 in ls) + { + // 若ErpLoc为空则根据客户代码构建ErpLoc + if (string.IsNullOrEmpty(itm1.ErpLoc)) + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } + } + // 按照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, @@ -432,104 +1058,206 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Site = "BJ02", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, - Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName }; - List invdetials = new List(); - - var invoiceGrpDetails1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(invoiceGrpDetails)); - foreach (var itm in invoiceGrpDetails1) + for (var i = 0; i < details.Count; i++) { - var inv = new INVOICE_WAIT_DETAIL();//添加买单件 - inv.InjectFrom(itm); - var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode); - if (first == null) + // 构建TED_SAS_INVOICE集合 + var invoiceGrpDetail = details[i]; + tedSaInvs.Add(new TED_SAS_INVOICE() { - inv.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); - invdetials.Add(itm);//添加发票明细 - continue; - } - else + 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() + }); + } + var invbefore = invoice.RealAmt + invoice.TaxDiff;// + var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); + var invdiff = invbefore - invafter; + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + foreach (var sainv in tedSaInvs) + { + sainv.InvoiceQuatity = -sainv.InvoiceQuatity; + sainv.InvoiceNetAmount = -sainv.InvoiceNetAmount; + sainv.InvoiceTaxAmount = -sainv.InvoiceTaxAmount; + } + + // 批量插入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 CreateBBACHongChongTaskAsync(List invoiceGrps) + { + var invDetails = await _settleAccountDbContext.Set().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); + foreach (var itm in invoiceGrps) + { + var ls = invDetails.Where(p => p.InvbillNum == itm).ToList(); + var invoice = await _settleAccountDbContext.Set().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false); + + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 + + if (ls.Any() && invoice != null) + { + + if (adj.Any())//假如存在调整单 + { + var adjlist = await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + + foreach (var itm1 in ls) + { + if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1046") { - if (itm.Qty > first.Qty) + if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) { - inv.Qty = itm.Qty - first.Qty;//发票总数中去除 - inv.Amt = Math.Round(itm.Qty * itm.PRICE, 2); + itm1.ErpLoc = "CC16"; } - inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; - if (invoiceGrp.Site == "1046") + else { - inv.SetProperty("ErpToLoc", "CC16"); + itm1.ErpLoc = $"C{invoice.ClientCode}"; } - if (invoiceGrp.Site == "1040") + } + if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1040") + { + if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) { - inv.SetProperty("ErpToLoc", "CC11"); + itm1.ErpLoc = "CC11"; + } + else + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; } - invdetials.Add(inv); } } - for (var i = 0; i < invdetials.Count; i++) + 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() { - var invoiceGrpDetail = invdetials[i]; - + 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++) + { + var invoiceGrpDetail = details[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, + 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, + Price = invoiceGrpDetail.Price, InvoiceNetAmount = invoiceGrpDetail.Amt, InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), TaxRate = 0.13m, - Location = invoiceGrpDetail.GetProperty("ErpToLoc", string.Empty), - begintime = invoiceGrpDetail.BeginDate, - endtime = invoiceGrpDetail.EndDate, - Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName, + Location = invoiceGrpDetail.Erploc, + begintime = DateTime.Now, + endtime = DateTime.Now, domain = "BJBMPT", LINE = (i + 1).ToString() }); } - - var tedsaInvs1 = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(tedSaInvs)); - var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// - var invafter = tedsaInvs1.Sum(p => p.InvoiceTaxAmount); + var invbefore = invoice.RealAmt + invoice.TaxDiff;// + var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); var invdiff = invbefore - invafter; - tedsaInvs1.FirstOrDefault().InvoiceTaxAmount += invdiff; - //invbefore= invafter +x; - //var line1 = tedsaInvs1.FirstOrDefault(p => p.LINE == "1"); - //var line2 = tedsaInvs1.FirstOrDefault(p => p.LINE == "2"); - ////line2.InvoiceTaxAmount += invdiff; - //line1.InvoiceTaxAmount += invdiff; - //红冲发票提交QAD - await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); - foreach (var itm in tedsaInvs1) + tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; + + foreach (var sainv in tedSaInvs) { - itm.InvoiceQuatity = -itm.InvoiceQuatity; - itm.InvoiceNetAmount = -itm.InvoiceNetAmount; - itm.InvoiceTaxAmount=-itm.InvoiceTaxAmount; + sainv.InvoiceQuatity = -sainv.InvoiceQuatity; + sainv.InvoiceNetAmount = -sainv.InvoiceNetAmount; + sainv.InvoiceTaxAmount = -sainv.InvoiceTaxAmount; } - await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false); - invoiceGrp.State = SettleBillState.已提交QAD; - await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); - await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode,invoiceGrp.CreationTime).ConfigureAwait(false); + + + + + await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + invoice.State = SettleBillState.已提交QAD; + await _repository.DbContext.BulkUpdateAsync(new List() { invoice }).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false); } } - else + } + + private async Task CreateHBPOHongChongTaskAsync(List invoiceGrps) + { + + var invDetails = await _settleAccountDbContext.Set().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false); + + foreach (var itm in invoiceGrps) { + var ls = invDetails.Where(p => p.InvbillNum == itm).ToList(); + var invoice = await _settleAccountDbContext.Set().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false); + var adj = await _settleAccountDbContext.Set().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量 - var invoiceGrpDetails = _settleAccountDbContext.Set() - .Where(t => t.InvbillNum == invbillNum) - .ToList(); - if (invoiceGrpDetails.Any()) + if (ls.Any() && invoice != null) { + + if (adj.Any())//假如存在调整单 + { + var adjlist = await ChangedPrice(invoice.BusinessType, adj).ConfigureAwait(false); + ls.AddRange(adjlist); + } + foreach (var itm1 in ls) + { + if (string.IsNullOrEmpty(itm1.ErpLoc)) + { + itm1.ErpLoc = $"C{invoice.ClientCode}"; + } + } + 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() { @@ -543,80 +1271,61 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Site = "BJ02", CreateTime = DateTime.Now, UpdateTime = DateTime.Now, - Remark = string.IsNullOrEmpty(invoiceGrp.FileName) ? string.Empty : invoiceGrp.FileName + Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName }; - for (var i = 0; i < invoiceGrpDetails.Count; i++) + for (var i = 0; i < details.Count; i++) { - var invoiceGrpDetail = invoiceGrpDetails[i]; - + var invoiceGrpDetail = details[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, + 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, + 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, + Location = invoiceGrpDetail.Erploc, + begintime = DateTime.Now, + endtime = DateTime.Now, domain = "BJBMPT", LINE = (i + 1).ToString() }); } - var invbefore = invoiceGrp.RealAmt + invoiceGrp.TaxDiff;// + var invbefore = invoice.RealAmt + invoice.TaxDiff;// var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount); var invdiff = invbefore - invafter; - tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff; - - - //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.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); - foreach (var itm in tedSaInvs) + foreach (var sainv in tedSaInvs) { - itm.InvoiceQuatity = -itm.InvoiceQuatity; - itm.InvoiceNetAmount = -itm.InvoiceNetAmount; - itm.InvoiceTaxAmount = -itm.InvoiceTaxAmount; + sainv.InvoiceQuatity = -sainv.InvoiceQuatity; + sainv.InvoiceNetAmount = -sainv.InvoiceNetAmount; + sainv.InvoiceTaxAmount = -sainv.InvoiceTaxAmount; } - await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); - invoiceGrp.State = SettleBillState.已提交QAD; - await _repository.DbContext.BulkUpdateAsync(new List() { invoiceGrp }); - await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode,invoiceGrp.CreationTime).ConfigureAwait(false); + + + + await _exChangeCenterDbContext.BulkInsertAsync(new List() { teaTaskSub }).ConfigureAwait(false); + await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); + invoice.State = SettleBillState.已提交QAD; + await _repository.DbContext.BulkUpdateAsync(new List() { invoice }).ConfigureAwait(false); + await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false); } } } - /// - /// 构建发票同步Qad状态表数据 - /// - private async Task BindInvoiceSyncQadAsync(TEA_TASK_SUB teaTaskSub, string invoiceNumber, string sasInvoiceNumber, string customer,DateTime dateTime) - { - var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber,dateTime) - { - TableName = teaTaskSub.TableName, - Domain = teaTaskSub.Domain, - Site = teaTaskSub.Site, - Customer = customer - }; - invoiceSyncQad.SetId(teaTaskSub.TaskID); - await _settleAccountDbContext.BulkInsertAsync(new List() { invoiceSyncQad }); - } + + /// /// 通过审核 @@ -826,15 +1535,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ ContractID = itm.ContractID, }; entity.INVOICE_WAIT_DETAIL_BJ = bjquery.OrderBy(p => p.LineCode).ToList(); - var notlist= await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false); - - - - - - - } else { @@ -870,10 +1571,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var sdtos = ObjectMapper.Map, List>(s);//不可结 var adjs = await _adjRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false);//调整数据 var adjdtos = ObjectMapper.Map, List>(adjs);//调整数据DTO - - - - var notquery = from itm in sdtos join itm1 in invs on itm.InvBillNum equals itm1.InvbillNum select diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/JobHostdService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/JobHostdService.cs index 0717ef53..fe472801 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/JobHostdService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/JobHostdService.cs @@ -248,9 +248,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { var connectionString = this._serviceProvider.GetRequiredService().GetConnectionString("SettleAccountService"); using var connection = new SqlConnection(connectionString); + var options = new DbContextOptionsBuilder().UseSqlServer(connection).Options; using var db = new SettleAccountDbContext(options); - + db.Database.SetCommandTimeout(new TimeSpan(2, 0, 0)); // 通过id查找作业项实体 var entity = db.Set().FirstOrDefault(o => o.Id == id); if (entity != null) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MakeCanSettlementService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MakeCanSettlementService.cs index 3b40dcaf..f8091c73 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MakeCanSettlementService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/MakeCanSettlementService.cs @@ -60,6 +60,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs _dbcontext.BulkDelete(ls); } } + var jis1 = p_list.Where(p => p.Site == "1040").ToList(); var jis2 = p_list.Where(p => p.Site == "1046").ToList(); List notlist = new List(); @@ -106,79 +107,118 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs var part_group_small = t1.Where(p => p.Amt < 10000000).ToList(); if (part_group_big.Count > 0) { - foreach (var itm in part_group_big) + var partlist = part_group_big.Select(p => p.LU).ToList(); + var ls = bbac_can_list.Where(p => partlist.Contains(p.LU)).ToList(); + var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + var bbac_sa = new BBAC_CAN_SA(); + bbac_sa.SetId(Guid.NewGuid()); + bbac_sa.BillNum = billNum; + bbac_sa.InvGroupNum = billNum; + bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + bbac_sa.State = SettleBillState.未结状态; + bbac_sa.SettleBillNum = string.Empty; + bbac_sa.Site = "1040"; + bbac_sa.BusinessType = EnumBusinessType.JisBBAC; + billList.Add(bbac_sa); + foreach (var itm1 in ls) { - var ls = bbac_can_list.Where(p => p.LU == itm.LU).ToList(); - decimal sum = 0; - List details = new List(); - foreach (var itm1 in ls) - { - sum += (itm1.Qty * itm1.Price); - if (sum > 10000000) - { - var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa = new BBAC_CAN_SA(); - bbac_sa.SetId(Guid.NewGuid()); - bbac_sa.BillNum = billNum; - bbac_sa.InvGroupNum = billNum; - bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa.State = SettleBillState.未结状态; - bbac_sa.SettleBillNum = string.Empty; - bbac_sa.Site = "1040"; - bbac_sa.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa); - foreach (var itm2 in details) - { - itm2.SetBillNum(billNum); - itm2.SetGroupNum(billNum); - billDetails.Add(itm2); - } - var test = details.Sum(p => p.Price * p.Qty); - var count = details.Count; - details = new List(); - sum = itm1.Qty * itm1.Price; - } - var _detailEntity = new BBAC_CAN_SA_DETAIL( - guid: GuidGenerator.Create(), - keyCode: itm1.KeyCode, - version: itm1.Version, - billNum: string.Empty, - settleBillNum: itm1.SettleBillNum, - lU: itm1.LU, - pN: itm1.PN, - site: itm1.Site, - qty: itm1.Qty, - price: itm1.Price, - category: itm1.BusinessType, - isReturn: itm1.IsReturn, - settleDate: itm1.SettleDate, - groupNum: itm1.GroupNum, - invGroupNum: string.Empty, - contactid: itm1.ContractDocID, - invbillnum: string.Empty, - partcode: itm1.PartCode - ); - _detailEntity.RealPartCode = itm1.RealPartCode; - details.Add(_detailEntity); - } - var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa1 = new BBAC_CAN_SA(); - bbac_sa1.SetId(Guid.NewGuid()); - bbac_sa1.BillNum = billNum1; - bbac_sa1.InvGroupNum = billNum1; - bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa1.State = SettleBillState.未结状态; - bbac_sa1.SettleBillNum = string.Empty; - bbac_sa1.Site = "1040"; - bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa1); - foreach (var detail in details) - { - detail.SetBillNum(billNum1); - detail.SetGroupNum(billNum1); - billDetails.Add(detail); - } + var _detailEntity = new BBAC_CAN_SA_DETAIL( + guid: GuidGenerator.Create(), + keyCode: itm1.KeyCode, + version: itm1.Version, + billNum: billNum, + settleBillNum: itm1.SettleBillNum, + lU: itm1.LU, + pN: itm1.PN, + site: itm1.Site, + qty: itm1.Qty, + price: itm1.Price, + category: itm1.BusinessType, + isReturn: itm1.IsReturn, + settleDate: itm1.SettleDate, + groupNum: itm1.GroupNum, + invGroupNum: billNum, + contactid: itm1.ContractDocID, + invbillnum: string.Empty, + partcode: itm1.PartCode + ); + _detailEntity.RealPartCode = itm1.RealPartCode; + billDetails.Add(_detailEntity); } + + //foreach (var itm in part_group_big) + //{ + // var ls = bbac_can_list.Where(p => p.LU == itm.LU).ToList(); + // decimal sum = 0; + // List details = new List(); + // foreach (var itm1 in ls) + // { + // sum += (itm1.Qty * itm1.Price); + // if (sum > 10000000) + // { + // var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa = new BBAC_CAN_SA(); + // bbac_sa.SetId(Guid.NewGuid()); + // bbac_sa.BillNum = billNum; + // bbac_sa.InvGroupNum = billNum; + // bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa.State = SettleBillState.未结状态; + // bbac_sa.SettleBillNum = string.Empty; + // bbac_sa.Site = "1040"; + // bbac_sa.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa); + // foreach (var itm2 in details) + // { + // itm2.SetBillNum(billNum); + // itm2.SetGroupNum(billNum); + // billDetails.Add(itm2); + // } + // var test = details.Sum(p => p.Price * p.Qty); + // var count = details.Count; + // details = new List(); + // sum = itm1.Qty * itm1.Price; + // } + // var _detailEntity = new BBAC_CAN_SA_DETAIL( + // guid: GuidGenerator.Create(), + // keyCode: itm1.KeyCode, + // version: itm1.Version, + // billNum: string.Empty, + // settleBillNum: itm1.SettleBillNum, + // lU: itm1.LU, + // pN: itm1.PN, + // site: itm1.Site, + // qty: itm1.Qty, + // price: itm1.Price, + // category: itm1.BusinessType, + // isReturn: itm1.IsReturn, + // settleDate: itm1.SettleDate, + // groupNum: itm1.GroupNum, + // invGroupNum: string.Empty, + // contactid: itm1.ContractDocID, + // invbillnum: string.Empty, + // partcode: itm1.PartCode + // ); + // _detailEntity.RealPartCode = itm1.RealPartCode; + // details.Add(_detailEntity); + // } + // var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa1 = new BBAC_CAN_SA(); + // bbac_sa1.SetId(Guid.NewGuid()); + // bbac_sa1.BillNum = billNum1; + // bbac_sa1.InvGroupNum = billNum1; + // bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa1.State = SettleBillState.未结状态; + // bbac_sa1.SettleBillNum = string.Empty; + // bbac_sa1.Site = "1040"; + // bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa1); + // foreach (var detail in details) + // { + // detail.SetBillNum(billNum1); + // detail.SetGroupNum(billNum1); + // billDetails.Add(detail); + // } + //} } if (part_group_small.Count > 0) { @@ -335,77 +375,117 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs var part_group_small = t1.Where(p => p.Amt < 10000000).ToList(); if (part_group_big.Count > 0) { - foreach (var itm in part_group_big) + + var partlist = part_group_big.Select(p => p.LU).ToList(); + var ls = bbac_can_list.Where(p => partlist.Contains(p.LU)).ToList(); + var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + var bbac_sa = new BBAC_CAN_SA(); + bbac_sa.SetId(Guid.NewGuid()); + bbac_sa.BillNum = billNum; + bbac_sa.InvGroupNum = billNum; + bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + bbac_sa.State = SettleBillState.未结状态; + bbac_sa.SettleBillNum = string.Empty; + bbac_sa.Site = "1046"; + bbac_sa.BusinessType = EnumBusinessType.JisBBAC; + billList.Add(bbac_sa); + foreach (var itm1 in ls) { - var ls = bbac_can_list.Where(p => p.LU == itm.LU).ToList(); - decimal sum = 0; - List details = new List(); - foreach (var itm1 in ls) - { - sum += (itm1.Qty * itm1.Price); - if (sum > 10000000) - { - var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa = new BBAC_CAN_SA(); - bbac_sa.SetId(Guid.NewGuid()); - bbac_sa.BillNum = billNum; - bbac_sa.InvGroupNum = billNum; - bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa.State = SettleBillState.未结状态; - bbac_sa.SettleBillNum = string.Empty; - bbac_sa.Site = "1046"; - bbac_sa.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa); - foreach (var itm2 in details) - { - itm2.SetBillNum(billNum); - itm2.SetGroupNum(billNum); - billDetails.Add(itm2); - } - details = new List(); - sum = itm1.Qty * itm1.Price; - } - var _detailEntity = new BBAC_CAN_SA_DETAIL( - guid: GuidGenerator.Create(), - keyCode: itm1.KeyCode, - version: itm1.Version, - billNum: string.Empty, - settleBillNum: itm1.SettleBillNum, - lU: itm1.LU, - pN: itm1.PN, - site: itm1.Site, - qty: itm1.Qty, - price: itm1.Price, - category: itm1.BusinessType, - isReturn: itm1.IsReturn, - settleDate: itm1.SettleDate, - groupNum: itm1.GroupNum, - invGroupNum: string.Empty, - contactid: itm1.ContractDocID, - invbillnum: string.Empty, - partcode: itm1.PartCode - ); - _detailEntity.RealPartCode = itm1.RealPartCode; - details.Add(_detailEntity); - } - var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa1 = new BBAC_CAN_SA(); - bbac_sa1.SetId(Guid.NewGuid()); - bbac_sa1.BillNum = billNum1; - bbac_sa1.InvGroupNum = billNum1; - bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa1.State = SettleBillState.未结状态; - bbac_sa1.SettleBillNum = string.Empty; - bbac_sa1.Site = "1046"; - bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa1); - foreach (var detail in details) - { - detail.SetBillNum(billNum1); - detail.SetGroupNum(billNum1); - billDetails.Add(detail); - } + var _detailEntity = new BBAC_CAN_SA_DETAIL( + guid: GuidGenerator.Create(), + keyCode: itm1.KeyCode, + version: itm1.Version, + billNum: billNum, + settleBillNum: itm1.SettleBillNum, + lU: itm1.LU, + pN: itm1.PN, + site: itm1.Site, + qty: itm1.Qty, + price: itm1.Price, + category: itm1.BusinessType, + isReturn: itm1.IsReturn, + settleDate: itm1.SettleDate, + groupNum: itm1.GroupNum, + invGroupNum: billNum, + contactid: itm1.ContractDocID, + invbillnum: string.Empty, + partcode: itm1.PartCode + ); + _detailEntity.RealPartCode = itm1.RealPartCode; + billDetails.Add(_detailEntity); } + + //foreach (var itm in part_group_big) + //{ + // var ls = bbac_can_list.Where(p => p.LU == itm.LU).ToList(); + // decimal sum = 0; + // List details = new List(); + // foreach (var itm1 in ls) + // { + // sum += (itm1.Qty * itm1.Price); + // if (sum > 10000000) + // { + // var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa = new BBAC_CAN_SA(); + // bbac_sa.SetId(Guid.NewGuid()); + // bbac_sa.BillNum = billNum; + // bbac_sa.InvGroupNum = billNum; + // bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa.State = SettleBillState.未结状态; + // bbac_sa.SettleBillNum = string.Empty; + // bbac_sa.Site = "1046"; + // bbac_sa.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa); + // foreach (var itm2 in details) + // { + // itm2.SetBillNum(billNum); + // itm2.SetGroupNum(billNum); + // billDetails.Add(itm2); + // } + // details = new List(); + // sum = itm1.Qty * itm1.Price; + // } + // var _detailEntity = new BBAC_CAN_SA_DETAIL( + // guid: GuidGenerator.Create(), + // keyCode: itm1.KeyCode, + // version: itm1.Version, + // billNum: string.Empty, + // settleBillNum: itm1.SettleBillNum, + // lU: itm1.LU, + // pN: itm1.PN, + // site: itm1.Site, + // qty: itm1.Qty, + // price: itm1.Price, + // category: itm1.BusinessType, + // isReturn: itm1.IsReturn, + // settleDate: itm1.SettleDate, + // groupNum: itm1.GroupNum, + // invGroupNum: string.Empty, + // contactid: itm1.ContractDocID, + // invbillnum: string.Empty, + // partcode: itm1.PartCode + // ); + // _detailEntity.RealPartCode = itm1.RealPartCode; + // details.Add(_detailEntity); + // } + // var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa1 = new BBAC_CAN_SA(); + // bbac_sa1.SetId(Guid.NewGuid()); + // bbac_sa1.BillNum = billNum1; + // bbac_sa1.InvGroupNum = billNum1; + // bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa1.State = SettleBillState.未结状态; + // bbac_sa1.SettleBillNum = string.Empty; + // bbac_sa1.Site = "1046"; + // bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa1); + // foreach (var detail in details) + // { + // detail.SetBillNum(billNum1); + // detail.SetGroupNum(billNum1); + // billDetails.Add(detail); + // } + //} } if (part_group_small.Count > 0) { @@ -635,75 +715,75 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs var part_group_small = t1.Where(p => p.Amt < 10000000).ToList(); if (part_group_big.Count > 0) { - foreach (var itm in part_group_big) - { - var ls = hbpo_can_list.Where(p => p.LU == itm.LU).ToList(); - decimal sum = 0; - List details = new List(); - foreach (var itm1 in ls) - { - sum += (itm1.Qty * itm1.Price); - if (sum > 10000000) - { - var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa = new HBPO_CAN_SA(); - bbac_sa.SetId(Guid.NewGuid()); - bbac_sa.BillNum = billNum; - bbac_sa.InvGroupNum = billNum; - bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa.State = SettleBillState.未结状态; - bbac_sa.SettleBillNum = string.Empty; - bbac_sa.Site = "104T"; - bbac_sa.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa); - foreach (var itm2 in details) - { - itm2.SetBillNum(billNum); - itm2.SetGroupNum(billNum); - billDetails.Add(itm2); - } - details = new List(); - sum = itm1.Qty * itm1.Price; - } - var _detailEntity = new HBPO_CAN_SA_DETAIL( - guid: GuidGenerator.Create(), - keyCode: itm1.KeyCode, - version: itm1.Version, - billNum: string.Empty, - settleBillNum: itm1.SettleBillNum, - lU: itm1.LU, - pN: itm1.PN, - site: itm1.Site, - qty: itm1.Qty, - price: itm1.Price, - businessType: itm1.BusinessType, - settleDate: itm1.SettleDate, - groupNum: itm1.GroupNum, - invGroupNum: string.Empty, - invbillnum: string.Empty, - partcode: itm1.PartCode - ); - _detailEntity.RealPartCode = itm1.RealPartCode; - details.Add(_detailEntity); - } - var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); - var bbac_sa1 = new HBPO_CAN_SA(); - bbac_sa1.SetId(Guid.NewGuid()); - bbac_sa1.BillNum = billNum1; - bbac_sa1.InvGroupNum = billNum1; - bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); - bbac_sa1.State = SettleBillState.未结状态; - bbac_sa1.SettleBillNum = string.Empty; - bbac_sa1.Site = "104T"; - bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; - billList.Add(bbac_sa1); - foreach (var detail in details) - { - detail.SetBillNum(billNum1); - detail.SetGroupNum(billNum1); - billDetails.Add(detail); - } - } + //foreach (var itm in part_group_big) + //{ + // var ls = hbpo_can_list.Where(p => p.LU == itm.LU).ToList(); + // decimal sum = 0; + // List details = new List(); + // foreach (var itm1 in ls) + // { + // sum += (itm1.Qty * itm1.Price); + // if (sum > 10000000) + // { + // var billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa = new HBPO_CAN_SA(); + // bbac_sa.SetId(Guid.NewGuid()); + // bbac_sa.BillNum = billNum; + // bbac_sa.InvGroupNum = billNum; + // bbac_sa.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa.State = SettleBillState.未结状态; + // bbac_sa.SettleBillNum = string.Empty; + // bbac_sa.Site = "104T"; + // bbac_sa.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa); + // foreach (var itm2 in details) + // { + // itm2.SetBillNum(billNum); + // itm2.SetGroupNum(billNum); + // billDetails.Add(itm2); + // } + // details = new List(); + // sum = itm1.Qty * itm1.Price; + // } + // var _detailEntity = new HBPO_CAN_SA_DETAIL( + // guid: GuidGenerator.Create(), + // keyCode: itm1.KeyCode, + // version: itm1.Version, + // billNum: string.Empty, + // settleBillNum: itm1.SettleBillNum, + // lU: itm1.LU, + // pN: itm1.PN, + // site: itm1.Site, + // qty: itm1.Qty, + // price: itm1.Price, + // businessType: itm1.BusinessType, + // settleDate: itm1.SettleDate, + // groupNum: itm1.GroupNum, + // invGroupNum: string.Empty, + // invbillnum: string.Empty, + // partcode: itm1.PartCode + // ); + // _detailEntity.RealPartCode = itm1.RealPartCode; + // details.Add(_detailEntity); + // } + // var billNum1 = OrderNumberGenerator.GenerateOrderNumber("N"); + // var bbac_sa1 = new HBPO_CAN_SA(); + // bbac_sa1.SetId(Guid.NewGuid()); + // bbac_sa1.BillNum = billNum1; + // bbac_sa1.InvGroupNum = billNum1; + // bbac_sa1.Version = int.Parse(DateTime.Now.ToString("yyyyMM")); + // bbac_sa1.State = SettleBillState.未结状态; + // bbac_sa1.SettleBillNum = string.Empty; + // bbac_sa1.Site = "104T"; + // bbac_sa1.BusinessType = EnumBusinessType.JisBBAC; + // billList.Add(bbac_sa1); + // foreach (var detail in details) + // { + // detail.SetBillNum(billNum1); + // detail.SetGroupNum(billNum1); + // billDetails.Add(detail); + // } + //} } if (part_group_small.Count > 0) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs index 8a3a1afe..b21a3cd5 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs @@ -38,11 +38,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers private readonly INormalEfCoreRepository _repository; private readonly INormalEfCoreRepository _groupRepository; private readonly INormalEfCoreRepository _detailRepository; - private readonly INormalEfCoreRepository _nothbpoRepository; - private readonly INormalEfCoreRepository _notpubRepository; - private readonly INormalEfCoreRepository _relationRepository; private readonly INormalEfCoreRepository _notRepository; private readonly INormalEfCoreRepository _adjRepository; @@ -501,8 +498,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers invGroupNum: itm.InvGroupNum, site: itm.Site, enumBusinessType:itm.BusinessType - - ); bbac.SetBusinessType(itm.BusinessType); bbacmainlist.Add(bbac); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs index c9be5721..cc1ec190 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs @@ -105,12 +105,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { priceList = _priceRepository.Where(p => p.IsCancel == false).ToList();//价格单 } - - if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.YinDuJian) { var ls = p_list.Select(p => p.GroupNum).Distinct().ToList(); - var notlist = _notRepository.Where(p => ls.Contains(p.GroupNum) && p.BusinessType==first.BusinessType).AsNoTracking().ToList();//JIT_ASN整发 + var notlist = p_list;//JIT_ASN整发 if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC) { var subqueryA = (from a in notlist @@ -152,14 +150,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers List priceLists = new List(); foreach (var itm in notlist) { - var priceListEntity = priceList.Where(p => p.IsCancel == false) .Where(t => t.LU == itm.LU) .Where(t => itm.SettleDate >= t.BeginTime && itm.SettleDate <= t.EndTime && t.ClientCode == itm.Site) .OrderByDescending(t => t.Date) .ThenByDescending(t => t.CreationTime) .FirstOrDefault(); - if (priceListEntity != null) { itm.Price = priceListEntity.Price; @@ -168,9 +164,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { itm.Price = 0; } - } - var result1 = notlist.Where(p=>p.Price!=0); var jit1 = result1.Where(p => p.Site == "1040").ToList(); var jit2 = result1.Where(p => p.Site == "1046").ToList(); @@ -456,8 +450,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } } - - await _repository.DbContext.BulkDeleteAsync(notList).ConfigureAwait(false); await _repository.DbContext.BulkInsertAsync(billList).ConfigureAwait(false);