Browse Source

更新版本

master
zhaoxinyu 4 months ago
parent
commit
256e019f36
  1. 530
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs
  2. 126
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs
  3. 14
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  4. 83
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_DETAIL_EXT.cs
  5. 20
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/EntityFrameworkCore/SettleAccountDbContextModelCreatingExtensions.cs

530
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs

@ -241,485 +241,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
//[UnitOfWork(false)]
/// <summary>
/// 提交到QAD
/// </summary>
//private async Task SubmitToQadSingle(string invbillNum)
//{
// var invoiceGrp = _settleAccountDbContext.Set<INVOICE_GRP>()
// .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<INVOICE_WAIT_DETAIL>().AsNoTracking()
// .Where(t => t.InvbillNum == invbillNum)
// .ToList();
// var invoiceGrpDetailsCopy = JsonConvert.DeserializeObject<List<INVOICE_WAIT_DETAIL>>(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<TED_SAS_INVOICE>();
// 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<INVOICE_WAIT_DETAIL> invdetials = new List<INVOICE_WAIT_DETAIL>();
// var invoiceGrpDetails1 = JsonConvert.DeserializeObject<List<INVOICE_WAIT_DETAIL>>(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<List<TED_SAS_INVOICE>>(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<TEA_TASK_SUB>() { teaTaskSub }).ConfigureAwait(false);
// await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false);
// invoiceGrp.State = SettleBillState.已提交QAD;
// await _repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp });
// await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false);
// }
// }
// else
// {
// var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>()
// .Where(t => t.InvbillNum == invbillNum)
// .ToList();
// if (invoiceGrpDetails.Any())
// {
// var tedSaInvs = new List<TED_SAS_INVOICE>();
// 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<TEA_TASK_SUB>() { teaTaskSub }).ConfigureAwait(false);
// await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false);
// invoiceGrp.State = SettleBillState.已提交QAD;
// await _repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp });
// await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false);
// }
// }
//}
/// <summary>
/// 红冲发票提交到QAD
/// </summary>
//private async Task SubmitToQadHongChongAsync(string invbillNum, List<BBAC_CAN_SA_DETAIL> p_detail = null)
//{
// var invoiceGrp = await _settleAccountDbContext.Set<INVOICE_GRP>()
// .Where(t => t.State == SettleBillState.红冲发票)
// .Where(t => t.InvbillNum == invbillNum)
// .FirstOrDefaultAsync().ConfigureAwait(false);
// List<PriceList> priceList = new List<PriceList>();
// 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<INVOICE_WAIT_DETAIL>().AsNoTracking()
// .Where(t => t.InvbillNum == invbillNum)
// .ToList();
// if (invoiceGrpDetails.Any())
// {
// var tedSaInvs = new List<TED_SAS_INVOICE>();
// 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<INVOICE_WAIT_DETAIL> invdetials = new List<INVOICE_WAIT_DETAIL>();
// var invoiceGrpDetails1 = JsonConvert.DeserializeObject<List<INVOICE_WAIT_DETAIL>>(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<List<TED_SAS_INVOICE>>(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<TEA_TASK_SUB>() { 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<INVOICE_GRP>() { invoiceGrp });
// await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false);
// }
// }
// else
// {
// var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>()
// .Where(t => t.InvbillNum == invbillNum)
// .ToList();
// if (invoiceGrpDetails.Any())
// {
// var tedSaInvs = new List<TED_SAS_INVOICE>();
// 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<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false);
// //await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().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<TEA_TASK_SUB>() { 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<INVOICE_GRP>() { invoiceGrp });
// await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false);
// }
// }
//}
/// <summary>
/// 构建发票同步Qad状态表数据
/// </summary>
@ -898,7 +419,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
private async Task CreateBBACTaskAsync(List<string> invoiceGrps)
{
var invDetails = await _settleAccountDbContext.Set<BBAC_CAN_SA_DETAIL>().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false);
var invDetails = await _settleAccountDbContext.Set<INVOICE_DETAIL_EXT>().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false);
// var invDetails = await _settleAccountDbContext.Set<BBAC_CAN_SA_DETAIL>().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<PUB_ADJ_DETAIL>().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量
if (ls.Any() && invoice != null)
{
if (adj.Any())//假如存在调整单
{
var adjlist = await ChangedPrice<BBAC_CAN_SA_DETAIL>(invoice.BusinessType, invoice.Site, adj).ConfigureAwait(false);
ls.AddRange(adjlist);
}
//if (adj.Any())//假如存在调整单
//{
// var adjlist = await ChangedPrice<INVOICE_DETAIL_EXT>(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<TED_SAS_INVOICE>();
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<string> invoiceGrps)
{
var invDetails=await _settleAccountDbContext.Set<HBPO_CAN_SA_DETAIL>().Where(p =>invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false);
var invDetails = await _settleAccountDbContext.Set<INVOICE_DETAIL_EXT>().Where(p => invoiceGrps.Contains(p.InvbillNum)).AsNoTracking().ToListAsync().ConfigureAwait(false);
// var invDetails=await _settleAccountDbContext.Set<HBPO_CAN_SA_DETAIL>().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<PUB_ADJ_DETAIL>().Where(p => p.InvBillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false); //调整数量
if (ls.Any() && invoice != null)
{
if (adj.Any())//假如存在调整单
{
var adjlist = await ChangedPrice<HBPO_CAN_SA_DETAIL>(invoice.BusinessType, invoice.Site, adj).ConfigureAwait(false);
ls.AddRange(adjlist);
}
//if (adj.Any())//假如存在调整单
//{
// var adjlist = await ChangedPrice<HBPO_CAN_SA_DETAIL>(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<TED_SAS_INVOICE>();
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",

126
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<string> FirstInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, List<TEMP_NOT_SA_DETAIL> p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType)
where TDetail : SA_CAN_BASE
{
List<string> _invls = new List<string>();
var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) });
Dictionary<string, decimal> dic = new Dictionary<string, decimal>();//原本
@ -279,7 +281,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
List<string> List = new List<string>();
decimal sum = itm.Value;//初始分组合计金额
//List<string> luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类
if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组
{
@ -292,13 +293,6 @@ 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<INVOICE_MAP_GROUP>();
foreach (var groupnum in invoicegrup)
@ -676,6 +688,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
{
groupList.AddRange(mapList);
}
var innotls = new List<INVOICE_NOT_SETTLE>();
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<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>();
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<INVOICE_NOT_SETTLE>();
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<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>();
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);

14
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<PagedResultDto<REC_SHIP_SUM>> 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();
}

83
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<Guid>
{
[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; }
/// <summary>
/// 1、BBAC-JIS 2、HBPO-JIS 3、JIT 4、备件 5、印度件
/// </summary>
[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;
}
}
}

20
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<INVOICE_DETAIL_EXT>(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)
{

Loading…
Cancel
Save