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 b6d22b73..2d437e5f 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 @@ -241,485 +241,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ - //[UnitOfWork(false)] - /// - /// 提交到QAD - /// - //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状态表数据 /// @@ -898,7 +419,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private async Task CreateBBACTaskAsync(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); + // 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(); @@ -906,17 +429,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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, invoice.Site, adj).ConfigureAwait(false); - ls.AddRange(adjlist); - } + //if (adj.Any())//假如存在调整单 + //{ + // var adjlist = await ChangedPrice(invoice.BusinessType, invoice.Site, adj).ConfigureAwait(false); + // ls.AddRange(adjlist); + //} foreach (var itm1 in ls) { if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1046") { - if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) + if (itm1.BussiessType == EnumBusinessType.MaiDanJianBBAC) { itm1.ErpLoc = "CC16"; } @@ -927,7 +450,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } if (string.IsNullOrEmpty(itm1.ErpLoc) && invoice.Site == "1040") { - if (itm1.BusinessType == EnumBusinessType.MaiDanJianBBAC) + if (itm1.BussiessType == EnumBusinessType.MaiDanJianBBAC) { itm1.ErpLoc = "CC11"; } @@ -937,8 +460,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } } } - 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 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() @@ -971,17 +495,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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.Erploc, + 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;// @@ -1003,7 +526,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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); + // 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(); @@ -1011,11 +536,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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, invoice.Site, adj).ConfigureAwait(false); - ls.AddRange(adjlist); - } + //if (adj.Any())//假如存在调整单 + //{ + // var adjlist = await ChangedPrice(invoice.BusinessType, invoice.Site, adj).ConfigureAwait(false); + // ls.AddRange(adjlist); + //} foreach (var itm1 in ls) { if (string.IsNullOrEmpty(itm1.ErpLoc)) @@ -1023,8 +548,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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 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(); @@ -1058,11 +584,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ 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.Erploc, + Location = invoiceGrpDetail.ErpLoc, begintime = DateTime.Now, endtime = DateTime.Now, domain = "BJBMPT", diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs index f49b63e7..cedbba01 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs @@ -28,6 +28,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Temp; using Win.Sfs.SettleAccount.Entities.CodeSettings; using Win.Sfs.SettleAccount.Entities.Prices; using Win.Sfs.Shared.RepositoryBase; +using static LinqToDB.Reflection.Methods.LinqToDB; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { @@ -262,6 +263,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs public List FirstInvoice(List p_list, List p_adjlist, List dtos, List p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) where TDetail : SA_CAN_BASE { + List _invls = new List(); var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); Dictionary dic = new Dictionary();//原本 @@ -279,8 +281,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs List invoiceGroupNumList = new List();//每个发票对应的结算分组号 List List = new List(); decimal sum = itm.Value;//初始分组合计金额 - //List luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类 - + if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组 { if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO) @@ -291,14 +292,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { invoiceGroupNumList.Add(itm.Key); continue; - } - //var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类 - //luList.AddRange(grouplist); - //luList = luList.Distinct().ToList(); - //if (luList.Count > 20)//累加零件不超过20种 - //{ - // continue; - //} + } sum += _itm1.Value; if (sum > 10000000) { @@ -327,20 +321,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { break; } - //var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类 - //luList.AddRange(grouplist); - //luList = luList.Distinct().ToList(); - //if (luList.Count > 20)//累加零件不超过20种 - //{ - // continue; - //} + sum += _itm1.Value; if (sum > 10000000) { break; } invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系 - //count++; + } invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系 @@ -551,6 +539,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs if (salist.Count > 0) { _dbcontext.BulkUpdate(salist); + //带库位发票 + var detailext=salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode,p.LU,p.Price, p.ErpLoc,p.BusinessType }) + .Select(p => new INVOICE_DETAIL_EXT + { + Version=p_version, + InvbillNum= p.Key.InvbillNum, + InvGroupNum= p.Key.InvGroupNum, + PartCode=p.Key.PartCode, + PRICE= p.Key.Price, + ErpLoc=p.Key.ErpLoc, + Qty = p.Sum(k => k.Qty), + BussiessType=p.Key.BusinessType, + Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前 + LU=p.Key.LU + + } + ).ToList(); + foreach (var itm in detailext) + { + itm.SetId(GuidGenerator.Create()); + itm.CreationTime = DateTime.Now; + } + _dbcontext.BulkInsert(detailext); } _dbcontext.BulkInsert(invlist); _dbcontext.BulkInsert(groupList); @@ -632,7 +643,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs var partlist = inv.Parts; if (partlist.Count > 0) { - var query = from itm in p_list + var query = from itm in partlist join itm1 in dtos on itm.Id equals itm1.Id select itm1; var Dtos = query.ToList(); @@ -656,6 +667,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs decimal txtAmt = detailDtos.Sum(k => k.TaxAmt);//税后金额 decimal realAmt = detailDtos.Sum(k => k.Tax);//税额 + var invoicegrup = partlist.Select(p => p.GroupNum); var mapList = new List(); foreach (var groupnum in invoicegrup) @@ -676,6 +688,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { groupList.AddRange(mapList); } + var innotls = new List(); + var sq = partlist.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum }) + .Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, GroupNum = p.Key.GroupNum }); + foreach (var sitm in sq) + { + innotls.Add(new INVOICE_NOT_SETTLE( + guid: GuidGenerator.Create(), + version: p_version, + invGroupNum: p_InvGroupNum, + settleGroupNum: sitm.GroupNum, + lU: sitm.LU, + lU1: sitm.LU, + extend1: "可结算", + extend2: string.Empty, + qty: sitm.Qty, + p_invbillnum: inv.InvBillNum + )); + } + if (innotls.Count > 0) + { + notDetialList.AddRange(innotls); + } + #region 发票明细 List _entityDetailList = new List(); foreach (var detail in detailDtos) @@ -760,6 +795,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs var entityList = query.ToList(); + foreach (var entity in entityList) + { + entity.InvbillNum = inv.InvBillNum; + } + + + salist.AddRange(entityList); if (partlist.Count > 0) @@ -788,6 +830,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { groupList.AddRange(mapList); } + var innotls = new List(); + var sq = entityList.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum }) + .Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, GroupNum = p.Key.GroupNum }); + foreach (var sitm in sq) + { + innotls.Add(new INVOICE_NOT_SETTLE( + guid: GuidGenerator.Create(), + version: p_version, + invGroupNum: p_InvGroupNum, + settleGroupNum: sitm.GroupNum, + lU: sitm.LU, + lU1: sitm.LU, + extend1: "可结算", + extend2: string.Empty, + qty: sitm.Qty, + p_invbillnum: sitm.InvBillNum + )); + } + if (innotls.Count > 0) + { + notDetialList.AddRange(innotls); + } + List _entityDetailList = new List(); foreach (var detail in partlist) @@ -852,19 +917,42 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs invbill.CreationTime = DateTime.MinValue; invbill.LastModificationTime = DateTime.Now; invlist.Add(invbill); - } - } if (salist.Count > 0) { _dbcontext.BulkUpdate(salist); + var detailext = salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode, p.LU, p.Price, p.ErpLoc, p.BusinessType }) + .Select(p => new INVOICE_DETAIL_EXT + { + Version = p_version, + InvbillNum = p.Key.InvbillNum, + InvGroupNum = p.Key.InvGroupNum, + PartCode = p.Key.PartCode, + PRICE = p.Key.Price, + ErpLoc = p.Key.ErpLoc, + Qty = p.Sum(k => k.Qty), + BussiessType = p.Key.BusinessType, + Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前 + LU = p.Key.LU + + } + ).ToList(); + foreach (var itm in detailext) + { + itm.SetId(GuidGenerator.Create()); + itm.CreationTime = DateTime.Now; + } + _dbcontext.BulkInsert(detailext); + + } _dbcontext.BulkInsert(invlist); _dbcontext.BulkInsert(groupList); _dbcontext.BulkInsert(detailList); + if (adjlist.Count > 0) { _dbcontext.BulkInsert(adjlist); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index cc2bf041..ba3e0861 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -1730,10 +1730,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [HttpPost] public async Task> GetSHIP_REC_SUMListAsync(RequestDto input) { - if(input!=null) - { - input.MaxResultCount = 100000; - } + //if(input!=null) + //{ + // input.MaxResultCount = 100000; + //} //return await _recRepository.ToListAsync().ConfigureAwait(false); var entities = await _recRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); @@ -1792,8 +1792,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ entity.SetId(Guid.NewGuid()); entity.CreationTime = DateTime.Now; } - entities=entities.Where(p=>p.PartCode==parcode).ToList(); - + if (!string.IsNullOrEmpty(parcode)) + { + entities = entities.Where(p => p.PartCode == parcode).ToList(); + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_DETAIL_EXT.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_DETAIL_EXT.cs new file mode 100644 index 00000000..f9e2b930 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_DETAIL_EXT.cs @@ -0,0 +1,83 @@ +using System; +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Domain.Entities.Auditing; +using Win.Sfs.SettleAccount; + +namespace SettleAccount.Domain.BQ +{ + + [Display(Name = "待开票明细")] + public class INVOICE_DETAIL_EXT : FullAuditedAggregateRoot + { + [Display(Name = "期间")] + public int Version { get; set; } + + [Display(Name = "发票号")] + public string InvbillNum { get; set; } = null!; + + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } = null!; + + [Display(Name = "零件号")] + public string LU { get; set; } = null!; + + [Display(Name = "客户零件号")] + public string PartCode { get; set; } = null!; + + [Display(Name = "单价")] + public decimal PRICE { get; set; } + + [Display(Name = "数量")] + public decimal Qty { get; set; } + + [Display(Name = "金额")] + public decimal Amt { get; set; } + + /// + /// 1、BBAC-JIS 2、HBPO-JIS 3、JIT 4、备件 5、印度件 + /// + [Display(Name = "业务分类")] + public EnumBusinessType BussiessType { get; set; } + + [Display(Name = "库位")] + public string ErpLoc { get; set; } = null!; + + [Display(Name = "扩展字段2")] + public string Extend2 { get; set; } = null!; + + [Display(Name = "价格开始日期")] + public DateTime BeginDate { get; set; } + [Display(Name = "价格结束日期")] + public DateTime EndDate { get; set; } + [Display(Name = "行号")] + public int LineCode { get; set; } + + public INVOICE_DETAIL_EXT(Guid guid, int version, string invbillNum, string invGroupNum, string lU, decimal pRICE, decimal qty, decimal amt, EnumBusinessType bussiessType, string extend1, string extend2, DateTime beginDate, DateTime endDate, string partcode) + { + Id = guid; + Version = version; + InvbillNum = invbillNum; + InvGroupNum = invGroupNum; + LU = lU; + PRICE = pRICE; + Qty = qty; + Amt = amt; + BussiessType = bussiessType; + ErpLoc = extend1; + Extend2 = extend2; + BeginDate = beginDate; + EndDate = endDate; + PartCode = partcode; + + } + + public INVOICE_DETAIL_EXT() + { + } + public void SetId(Guid guid) + { + Id = guid; + } + + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs index f48f4e66..89f56b2a 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs @@ -119,6 +119,7 @@ namespace Win.Sfs.SettleAccount builder.ConfigureVmiBalanceSumDetail(options); builder.ConfigureBalanceSum(options); builder.ConfigureREC_SHIP_SUM(options); + builder.ConfigureINVOICE_DETAIL_EXT(options); //builder.ConfigureTED_SA_INV(options); //大众发票导入 //builder.ConfigureInvoice(options); @@ -895,6 +896,25 @@ namespace Win.Sfs.SettleAccount b.Property(x => x.ConcurrencyStamp).HasMaxLength(50); }); } + private static void ConfigureINVOICE_DETAIL_EXT(this ModelBuilder builder, SettleAccountModelBuilderConfigurationOptions options) + { + builder.Entity(b => + { + b.ToTable($"{options.TablePrefix}_INVOICE_DETAIL_EXT", options.Schema); + + b.ConfigureByConvention(); + b.Property(x => x.InvbillNum).HasMaxLength(50); + b.Property(x => x.InvGroupNum).HasMaxLength(50); + b.Property(x => x.LU).HasMaxLength(50); + b.Property(x => x.BussiessType).HasMaxLength(50); + b.Property(x => x.ErpLoc).HasMaxLength(50); + b.Property(x => x.Extend2).HasMaxLength(50); + + b.Property(x => x.ConcurrencyStamp).HasMaxLength(50); + }); + } + + private static void ConfigureJIT_SE_SA_REPORT(this ModelBuilder builder, SettleAccountModelBuilderConfigurationOptions options) {