Browse Source

更新版本

master
学 赵 1 week ago
parent
commit
59ffbbf09e
  1. 136
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs

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

@ -159,8 +159,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var invoiceBBACGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisBBAC);
var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO);
var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO);
var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO && p.BusinessType != EnumBusinessType.MaiDanJianHBPO);
var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO || p.BusinessType == EnumBusinessType.MaiDanJianHBPO);
if (invoiceBBACGrps.Any())
{
var invlist = await invoiceBBACGrps.ToListAsync().ConfigureAwait(false);
@ -189,21 +189,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
_globalConfigOptions.IsSyncInvoiceQadState = true;
var invoiceGrps1 = _settleAccountDbContext.Set<INVOICE_GRP>()
.Where(t => invbillNums.Contains(t.InvbillNum) && t.State == SettleBillState.);
//var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组
//var invList=_settleAccountDbContext.Set<INVOICE_GRP>().Where(p => grouplist.Contains(p.InvGroupNum)).ToList();
//var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum }
// into temp
// from tm in temp.DefaultIfEmpty()
// where tm == null
// select itm;
//var invoices = query.ToList();
//if (invoices.Count > 0)
//{
// var invbilllist=invoices.Select(p => p.InvGroupNum).ToList();
// var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList();
// throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400");
//}
foreach (var itm in invoiceGrps1)
{
itm.State = SettleBillState.QAD退回到已开票;
@ -216,11 +203,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var invoiceBBACGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisBBAC);
var invoicePubGrps = invoiceGrps.Where(p => p.BusinessType != EnumBusinessType.JisBBAC && p.BusinessType != EnumBusinessType.JisHBPO);
var invoiceHbpoGrps = invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.JisHBPO);
var invoiceMaidanGrps=invoiceGrps.Where(p => p.BusinessType == EnumBusinessType.MaiDanJianHBPO);
if (invoiceBBACGrps.Any())
{
var invlist = await invoiceBBACGrps.ToListAsync().ConfigureAwait(false);
var billinvs = invlist.Select(p => p.InvbillNum).ToList();
//await CreateBBACTaskAsync(billinvs).ConfigureAwait(false);
await CreateBBACHongChongTaskAsync(billinvs).ConfigureAwait(false);
}
@ -236,6 +226,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var billinvs = invlist.Select(p => p.InvbillNum).ToList();
await CreateHBPOHongChongTaskAsync(billinvs).ConfigureAwait(false);
}
if (invoiceMaidanGrps.Any())
{
var invlist = await invoiceMaidanGrps.ToListAsync().ConfigureAwait(false);
var billinvs = invlist.Select(p => p.InvbillNum).ToList();
await CreateHBPOMaidanTaskAsync(billinvs).ConfigureAwait(false);
}
return new OkResult();
}
@ -564,10 +560,109 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
}
private async Task CreateHBPOTaskAsync(List<string> invoiceGrps)
private async Task CreateHBPOMaidanTaskAsync(List<string> invoiceGrps)
{
var codelist = _settleAccountDbContext.Set<CodeSetting>().Where(p => p.Project == "库位").ToList();
var maidan = codelist.Where(p => p.Value == "MaiDanJianHBPO").FirstOrDefault().Description;
// 对发票组进行处理
foreach (var itm in invoiceGrps)
{
// 获取发票相关的结算明细
var ls = await _settleAccountDbContext.Set<HBPO_CAN_SA_DETAIL>().Where(p => p.InvbillNum == itm).AsNoTracking().ToListAsync().ConfigureAwait(false);
// 获取发票信息
var invoice = await _settleAccountDbContext.Set<INVOICE_GRP>().FirstOrDefaultAsync(p => p.InvbillNum == itm).ConfigureAwait(false);
// 获取调整明细
if (ls.Any() && invoice != null)
{
// 获取所属站点信息
var site = ls.FirstOrDefault().Site;
foreach (var itm1 in ls)
{
// 若ErpLoc为空则根据客户代码构建ErpLoc
if (string.IsNullOrEmpty(itm1.ErpLoc))
{
itm1.ErpLoc = maidan;
}
}
// 按照ErpLoc、PartCode、BusinessType和Price对结算明细进行分组,并计算相关数据
var details = ls.GroupBy(p => new { p.ErpLoc, p.PartCode, p.BusinessType, p.Price })
.Select(p => new { Erploc = p.Key.ErpLoc, p.Key.PartCode, p.Key.BusinessType, Amt = Math.Round(p.Sum(t => t.Qty * t.Price), 2), Price = p.Key.Price, Qty = p.Sum(t => t.Qty) }).ToList();
var tedSaInvs = new List<TED_SAS_INVOICE>();
var taskId = GuidGenerator.Create();
var teaTaskSub = new TEA_TASK_SUB()
{
// 初始化TEA_TASK_SUB对象
GUID = taskId,
TaskState = 0,
TaskID = taskId,
TableName = "TED_SAS_INVOICE",
Creator = "SAS",
Subscriber = "QAD",
Domain = "BJBMPT",
Site = "BJ02",
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName
};
for (var i = 0; i < details.Count; i++)
{
// 构建TED_SAS_INVOICE集合
var invoiceGrpDetail = details[i];
tedSaInvs.Add(new TED_SAS_INVOICE()
{
GUID = GuidGenerator.Create(),
Dataid = GuidGenerator.Create(),
Taskid = taskId,
invoiceNumber = invoice.RealnvBillNum,
sasInvoiceNumber = invoice.InvbillNum,
Customer = invoice.ClientCode,
BillTo = invoice.ClientCode,
InvoiceDate = invoice.CreationTime,
Site = "BJ02",
PartNumber = invoiceGrpDetail.PartCode,
InvoiceQuatity = invoiceGrpDetail.Qty,
Price = invoiceGrpDetail.Price,
InvoiceNetAmount = invoiceGrpDetail.Amt,
InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2),
TaxRate = 0.13m,
Location = invoiceGrpDetail.Erploc,
begintime = DateTime.Now,
endtime = DateTime.Now,
domain = "BJBMPT",
LINE = (i + 1).ToString(),
Remark = string.IsNullOrEmpty(invoice.FileName) ? string.Empty : invoice.FileName
});
}
var invbefore = invoice.RealAmt + invoice.TaxDiff;//
var invafter = tedSaInvs.Sum(p => p.InvoiceTaxAmount);
var invdiff = invbefore - invafter;
tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invdiff;
if (!string.IsNullOrEmpty(invoice.ParentInvbillNum))
{
await CreatePubHongChongTaskAsync(new List<string>() { invoice.ParentInvbillNum }).ConfigureAwait(false);
}
// 批量插入TEA_TASK_SUB记录
await _exChangeCenterDbContext.BulkInsertAsync(new List<TEA_TASK_SUB>() { 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_GRP>() { invoice }).ConfigureAwait(false);
// 异步绑定发票与QAD同步
await BindInvoiceSyncQadAsync(teaTaskSub, invoice.RealnvBillNum, invoice.InvbillNum, invoice.ClientCode, invoice.CreationTime).ConfigureAwait(false);
}
}
}
private async Task CreateHBPOTaskAsync(List<string> invoiceGrps)
{
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)
{
@ -652,6 +747,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
}
}
private async Task CreatePubHongChongTaskAsync(List<string> invoiceGrps)
{
// 对发票组进行处理

Loading…
Cancel
Save