Browse Source

修改提交QAD接口

master
mahao 1 year ago
parent
commit
1df4c6c32a
  1. 160
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs

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

@ -129,17 +129,35 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[HttpPost]
public virtual async Task<IActionResult> SubmitToQad(List<string> invbillNums)
{
var invoiceGrps = _settleAccountDbContext.Set<INVOICE_GRP>()
.Where(t => invbillNums.Contains(t.InvbillNum))
for (var i = 0; i < invbillNums.Count; i++)
{
await SubmitToQadSingle(invbillNums[i]).ConfigureAwait(false);
}
return new OkResult();
}
/// <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.)
.ToList();
.FirstOrDefault();
invbillNums = invoiceGrps.Select(t => t.InvbillNum).ToList();
if (invoiceGrp == null)
{
return;
}
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>()
.Where(t => invbillNums.Contains(t.InvbillNum))
.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()
{
@ -155,63 +173,47 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
UpdateTime = DateTime.Now,
};
var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) =>
for (var i = 0; i < invoiceGrpDetails.Count; i++)
{
return new TED_SAS_INVOICE()
var invoiceGrpDetail = invoiceGrpDetails[i];
tedSaInvs.Add(new TED_SAS_INVOICE()
{
GUID = GuidGenerator.Create(),
Dataid = GuidGenerator.Create(),
Taskid = taskId,
invoiceNumber = y.RealnvBillNum,
sasInvoiceNumber = y.InvbillNum,
Customer = y.ClientCode,
BillTo = y.ClientCode,
InvoiceDate = y.CreationTime,
Site = "BJ02",
PartNumber = x.LU,
InvoiceQuatity = x.Qty,
Price = x.PRICE,
InvoiceNetAmount = x.Amt,
InvoiceTaxAmount = Math.Round(x.Amt * 0.13m, 2),
TaxRate = 0.13m,
Location = $"C{y.ClientCode}",
begintime = x.BeginDate,
endtime = x.EndDate,
domain = "BJBMPT"
};
}).ToList();
var invoiceGrpTedSaInvs = invoiceGrps.Select(t =>
{
return new TED_SAS_INVOICE()
{
GUID = GuidGenerator.Create(),
Taskid = taskId,
invoiceNumber = t.RealnvBillNum,
sasInvoiceNumber = t.InvbillNum,
Customer = t.ClientCode,
BillTo = t.ClientCode,
InvoiceDate = t.CreationTime,
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 = $"C{t.ClientCode}",
InvoiceTax = t.TaxDiff,
domain = "BJBMPT"
};
Location = $"C{invoiceGrp.ClientCode}",
begintime = invoiceGrpDetail.BeginDate,
endtime = invoiceGrpDetail.EndDate,
domain = "BJBMPT",
LINE = (i + 1).ToString()
});
}
tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff;
tedSaInvs.AddRange(invoiceGrpTedSaInvs);
if (tedSaInvs.Any())
{
//红冲发票提交QAD
await SubmitToQadHongChong(invoiceGrps.Select(t => t.ParentInvbillNum).ToList()).ConfigureAwait(false);
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum))
{
await SubmitToQadHongChong(invoiceGrp.ParentInvbillNum).ConfigureAwait(false);
}
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false);
await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().AddRangeAsync(tedSaInvs).ConfigureAwait(false);
invoiceGrps.ForEach(t => t.State = SettleBillState.QAD);
//invoiceGrp.State = SettleBillState.已提交QAD;
await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false);
var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] {
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
@ -223,31 +225,28 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
});
await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false);
}
await Task.CompletedTask.ConfigureAwait(false);
return new OkResult();
}
/// <summary>
/// 红冲发票提交到QAD
/// </summary>
private async Task SubmitToQadHongChong(List<string> invbillNums)
private async Task SubmitToQadHongChong(string invbillNum)
{
if (!invbillNums.Any())
var invoiceGrp = _settleAccountDbContext.Set<INVOICE_GRP>()
.Where(t => t.State == SettleBillState.QAD)
.Where(t => t.InvbillNum == invbillNum)
.FirstOrDefault();
if (invoiceGrp == null)
{
return;
}
var invoiceGrps = _settleAccountDbContext.Set<INVOICE_GRP>()
.Where(t => t.State == SettleBillState.QAD)
.Where(t => invbillNums.Contains(t.InvbillNum))
.ToList();
invbillNums = invoiceGrps.Select(t => t.InvbillNum).ToList();
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>()
.Where(t => invbillNums.Contains(t.InvbillNum))
.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()
{
@ -263,34 +262,33 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
UpdateTime = DateTime.Now,
};
var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) =>
for (var i = 0; i < invoiceGrpDetails.Count; i++)
{
return new TED_SAS_INVOICE()
var invoiceGrpDetail = invoiceGrpDetails[i];
tedSaInvs.Add(new TED_SAS_INVOICE()
{
GUID = GuidGenerator.Create(),
Dataid = GuidGenerator.Create(),
Taskid = taskId,
invoiceNumber = y.RealnvBillNum,
sasInvoiceNumber = y.InvbillNum,
Customer = y.ClientCode,
BillTo = y.ClientCode,
InvoiceDate = y.CreationTime,
invoiceNumber = invoiceGrp.RealnvBillNum,
sasInvoiceNumber = invoiceGrp.InvbillNum,
Customer = invoiceGrp.ClientCode,
BillTo = invoiceGrp.ClientCode,
InvoiceDate = invoiceGrp.CreationTime,
Site = "BJ02",
PartNumber = x.LU,
InvoiceQuatity = -x.Qty,
Price = x.PRICE,
InvoiceNetAmount = x.Amt,
InvoiceTaxAmount = Math.Round(x.Amt * 0.13m, 2),
PartNumber = invoiceGrpDetail.PartCode,
InvoiceQuatity = -invoiceGrpDetail.Qty,
Price = invoiceGrpDetail.PRICE,
InvoiceNetAmount = invoiceGrpDetail.Amt,
InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2),
TaxRate = 0.13m,
Location = $"C{y.ClientCode}",
begintime = x.BeginDate,
endtime = x.EndDate,
domain = "BJBMPT"
};
}).ToList();
if (tedSaInvs.Any())
{
Location = $"C{invoiceGrp.ClientCode}",
begintime = invoiceGrpDetail.BeginDate,
endtime = invoiceGrpDetail.EndDate,
domain = "BJBMPT",
LINE = (i + 1).ToString()
});
}
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false);
await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().AddRangeAsync(tedSaInvs).ConfigureAwait(false);
}

Loading…
Cancel
Save