|
@ -5,6 +5,8 @@ using System.ComponentModel.DataAnnotations; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Reflection; |
|
|
using System.Reflection; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using DocumentFormat.OpenXml.Office2013.Word; |
|
|
|
|
|
using DocumentFormat.OpenXml.Presentation; |
|
|
using EFCore.BulkExtensions; |
|
|
using EFCore.BulkExtensions; |
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
using Magicodes.ExporterAndImporter.Csv; |
|
|
using Magicodes.ExporterAndImporter.Csv; |
|
@ -12,8 +14,10 @@ using Magicodes.ExporterAndImporter.Excel; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Options; |
|
|
using Microsoft.Extensions.Options; |
|
|
|
|
|
using Newtonsoft.Json; |
|
|
using Omu.ValueInjecter; |
|
|
using Omu.ValueInjecter; |
|
|
using Polly; |
|
|
using Polly; |
|
|
using SettleAccount.Domain.BQ; |
|
|
using SettleAccount.Domain.BQ; |
|
@ -112,6 +116,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
/// * 成功提交后修改状态为已提交QAD
|
|
|
/// * 成功提交后修改状态为已提交QAD
|
|
|
/// </remarks>
|
|
|
/// </remarks>
|
|
|
[HttpPost] |
|
|
[HttpPost] |
|
|
|
|
|
[UnitOfWork(false)] |
|
|
public virtual async Task<IActionResult> SubmitToQad(List<string> invbillNums) |
|
|
public virtual async Task<IActionResult> SubmitToQad(List<string> invbillNums) |
|
|
{ |
|
|
{ |
|
|
_globalConfigOptions.IsSyncInvoiceQadState = true; |
|
|
_globalConfigOptions.IsSyncInvoiceQadState = true; |
|
@ -121,7 +126,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
} |
|
|
} |
|
|
return new OkResult(); |
|
|
return new OkResult(); |
|
|
} |
|
|
} |
|
|
|
|
|
[UnitOfWork(false)] |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 提交到QAD
|
|
|
/// 提交到QAD
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
@ -135,7 +140,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
var _detail = await _bbacMng.GetDetailAsync(invbillNum, EnumBusinessType.MaiDanJianBBAC).ConfigureAwait(false);//查出买单数量
|
|
|
var _detail = await _bbacMng.GetDetailAsync(invbillNum, EnumBusinessType.MaiDanJianBBAC).ConfigureAwait(false);//查出买单数量
|
|
|
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>() |
|
|
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>().AsNoTracking() |
|
|
.Where(t => t.InvbillNum == invbillNum) |
|
|
.Where(t => t.InvbillNum == invbillNum) |
|
|
.ToList(); |
|
|
.ToList(); |
|
|
if (invoiceGrpDetails.Any()) |
|
|
if (invoiceGrpDetails.Any()) |
|
@ -156,32 +161,38 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
UpdateTime = DateTime.Now, |
|
|
UpdateTime = DateTime.Now, |
|
|
}; |
|
|
}; |
|
|
List<INVOICE_WAIT_DETAIL> invdetials = new List<INVOICE_WAIT_DETAIL>(); |
|
|
List<INVOICE_WAIT_DETAIL> invdetials = new List<INVOICE_WAIT_DETAIL>(); |
|
|
foreach (var itm in invoiceGrpDetails) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var invoiceGrpDetails1 = JsonConvert.DeserializeObject<List<INVOICE_WAIT_DETAIL>>(JsonConvert.SerializeObject(invoiceGrpDetails)); |
|
|
|
|
|
foreach (var itm in invoiceGrpDetails1) |
|
|
{ |
|
|
{ |
|
|
itm.SetProperty("ErpToLoc",$"C{invoiceGrp.ClientCode}"); |
|
|
|
|
|
invdetials.Add(itm);//添加发票明细
|
|
|
|
|
|
var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode ); |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
itm.Qty = itm.Qty - first.Qty;//发票总数中去除
|
|
|
|
|
|
itm.Amt = Math.Round(itm.Qty * itm.PRICE, 2); |
|
|
|
|
|
var inv = new INVOICE_WAIT_DETAIL();//添加买单件
|
|
|
var inv = new INVOICE_WAIT_DETAIL();//添加买单件
|
|
|
inv.InjectFrom(itm); |
|
|
inv.InjectFrom(itm); |
|
|
inv.Qty= first.Qty; |
|
|
var first = _detail.FirstOrDefault(p => p.ContractDocID == itm.Extend1 && p.PartCode == itm.PartCode); |
|
|
inv.Amt = Math.Round(first.Qty * itm.PRICE, 2); |
|
|
if (first == null) |
|
|
inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; |
|
|
|
|
|
if (invoiceGrp.Site == "1046") |
|
|
|
|
|
{ |
|
|
{ |
|
|
inv.SetProperty("ErpToLoc", "CC16"); |
|
|
inv.SetProperty("ErpToLoc", $"C{invoiceGrp.ClientCode}"); |
|
|
|
|
|
invdetials.Add(itm);//添加发票明细
|
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
if (invoiceGrp.Site == "1040") |
|
|
else |
|
|
{ |
|
|
{ |
|
|
inv.SetProperty("ErpToLoc", "CC11"); |
|
|
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); |
|
|
} |
|
|
} |
|
|
invdetials.Add(inv); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
for (var i = 0; i < invdetials.Count; i++) |
|
|
for (var i = 0; i < invdetials.Count; i++) |
|
|
{ |
|
|
{ |
|
@ -212,50 +223,39 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var invbefore = invoiceGrp.TaxAmt + invoiceGrp.TaxDiff; |
|
|
|
|
|
var invafter=tedSaInvs.Sum(p => p.InvoiceNetAmount) + tedSaInvs.Sum(p => p.InvoiceTaxAmount); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var tedsaInvs1 = JsonConvert.DeserializeObject<List<TED_SAS_INVOICE>>(JsonConvert.SerializeObject(tedSaInvs)); |
|
|
|
|
|
var invbefore = invoiceGrp.TaxAmt + invoiceGrp.TaxDiff; |
|
|
|
|
|
var invafter = tedsaInvs1.Sum(p => p.InvoiceNetAmount) + tedsaInvs1.Sum(p => p.InvoiceTaxAmount); |
|
|
var invdiff = invbefore - invafter; |
|
|
var invdiff = invbefore - invafter; |
|
|
|
|
|
var line1 = tedsaInvs1.FirstOrDefault(p => p.LINE == "1"); |
|
|
|
|
|
var line2 = tedsaInvs1.FirstOrDefault(p => p.LINE == "2"); |
|
|
|
|
|
line2.InvoiceTaxAmount += invdiff; |
|
|
tedSaInvs.FirstOrDefault(p => p.LINE == "2").InvoiceTaxAmount +=invdiff; |
|
|
line1.InvoiceTaxAmount += invoiceGrp.TaxDiff; |
|
|
tedSaInvs.FirstOrDefault(p => p.LINE == "1").InvoiceTaxAmount += invoiceGrp.TaxDiff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//红冲发票提交QAD
|
|
|
//红冲发票提交QAD
|
|
|
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) |
|
|
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) |
|
|
{ |
|
|
{ |
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
await _exChangeCenterDbContext.BulkInsertAsync(new List<TEA_TASK_SUB>() { teaTaskSub }).ConfigureAwait(false); |
|
|
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false); |
|
|
await _exChangeCenterDbContext.BulkInsertAsync(tedsaInvs1).ConfigureAwait(false); |
|
|
await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().AddRangeAsync(tedSaInvs).ConfigureAwait(false); |
|
|
|
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
//构建发票同步Qad状态表数据
|
|
|
_repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp }); |
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); |
|
|
//await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false);
|
|
|
var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] { |
|
|
// var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] {
|
|
|
TimeSpan.FromSeconds(1), |
|
|
// TimeSpan.FromSeconds(1),
|
|
|
TimeSpan.FromSeconds(5), |
|
|
// TimeSpan.FromSeconds(5),
|
|
|
TimeSpan.FromSeconds(5), |
|
|
// TimeSpan.FromSeconds(5),
|
|
|
TimeSpan.FromSeconds(5) |
|
|
// TimeSpan.FromSeconds(5)
|
|
|
}, (exception, timeSpan, retryCount, context) => |
|
|
//}, (exception, timeSpan, retryCount, context) =>
|
|
|
{ |
|
|
//{
|
|
|
_logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试"); |
|
|
// _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试");
|
|
|
}); |
|
|
//});
|
|
|
await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); |
|
|
// await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
@ -279,9 +279,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
CreateTime = DateTime.Now, |
|
|
CreateTime = DateTime.Now, |
|
|
UpdateTime = DateTime.Now, |
|
|
UpdateTime = DateTime.Now, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < invoiceGrpDetails.Count; i++) |
|
|
for (var i = 0; i < invoiceGrpDetails.Count; i++) |
|
|
{ |
|
|
{ |
|
|
var invoiceGrpDetail = invoiceGrpDetails[i]; |
|
|
var invoiceGrpDetail = invoiceGrpDetails[i]; |
|
@ -314,125 +311,52 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
//红冲发票提交QAD
|
|
|
//红冲发票提交QAD
|
|
|
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) |
|
|
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) |
|
|
{ |
|
|
{ |
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
if (invoiceGrp.BusinessType == EnumBusinessType.JisBBAC) |
|
|
} |
|
|
{ |
|
|
|
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false); |
|
|
} |
|
|
await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().AddRangeAsync(tedSaInvs).ConfigureAwait(false); |
|
|
//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); |
|
|
|
|
|
await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); |
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
//构建发票同步Qad状态表数据
|
|
|
_repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp }); |
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); |
|
|
// await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false);
|
|
|
var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] { |
|
|
// var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] {
|
|
|
TimeSpan.FromSeconds(1), |
|
|
// TimeSpan.FromSeconds(1),
|
|
|
TimeSpan.FromSeconds(5), |
|
|
// TimeSpan.FromSeconds(5),
|
|
|
TimeSpan.FromSeconds(5), |
|
|
// TimeSpan.FromSeconds(5),
|
|
|
TimeSpan.FromSeconds(5) |
|
|
// TimeSpan.FromSeconds(5)
|
|
|
}, (exception, timeSpan, retryCount, context) => |
|
|
//}, (exception, timeSpan, retryCount, context) =>
|
|
|
{ |
|
|
//{
|
|
|
_logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试"); |
|
|
// _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试");
|
|
|
}); |
|
|
//});
|
|
|
await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false); |
|
|
// await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false);
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (invoiceGrp == null)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
|
|
|
|
|
//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,
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 = invoiceGrpDetail.BeginDate,
|
|
|
|
|
|
// endtime = invoiceGrpDetail.EndDate,
|
|
|
|
|
|
// domain = "BJBMPT",
|
|
|
|
|
|
// LINE = (i + 1).ToString()
|
|
|
|
|
|
// });
|
|
|
|
|
|
// }
|
|
|
|
|
|
// tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff;
|
|
|
|
|
|
// //红冲发票提交QAD
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 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.SaveChangesAsync().ConfigureAwait(false);
|
|
|
|
|
|
// var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] {
|
|
|
|
|
|
// TimeSpan.FromSeconds(1),
|
|
|
|
|
|
// TimeSpan.FromSeconds(5),
|
|
|
|
|
|
// TimeSpan.FromSeconds(5),
|
|
|
|
|
|
// TimeSpan.FromSeconds(5)
|
|
|
|
|
|
// }, (exception, timeSpan, retryCount, context) =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _logger.LogError($"提交到QAD,修改发票状态执行失败,第 {retryCount} 次重试");
|
|
|
|
|
|
// });
|
|
|
|
|
|
// await retryPolicyAsync.ExecuteAsync(async () => await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false)).ConfigureAwait(false);
|
|
|
|
|
|
//}
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 红冲发票提交到QAD
|
|
|
/// 红冲发票提交到QAD
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private async Task SubmitToQadHongChongAsync(string invbillNum) |
|
|
private async Task SubmitToQadHongChongAsync(string invbillNum, List<BBAC_CAN_SA_DETAIL> p_detail = null) |
|
|
{ |
|
|
{ |
|
|
var invoiceGrp = _settleAccountDbContext.Set<INVOICE_GRP>() |
|
|
var invoiceGrp = _settleAccountDbContext.Set<INVOICE_GRP>() |
|
|
.Where(t => t.State == SettleBillState.红冲发票) |
|
|
.Where(t => t.State == SettleBillState.红冲发票) |
|
@ -442,59 +366,189 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
{ |
|
|
{ |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>() |
|
|
|
|
|
|
|
|
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) |
|
|
.Where(t => t.InvbillNum == invbillNum) |
|
|
.ToList(); |
|
|
.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, |
|
|
|
|
|
}; |
|
|
|
|
|
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]; |
|
|
|
|
|
|
|
|
if (invoiceGrpDetails.Any()) |
|
|
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 tedsaInvs1 = JsonConvert.DeserializeObject<List<TED_SAS_INVOICE>>(JsonConvert.SerializeObject(tedSaInvs)); |
|
|
|
|
|
var invbefore = invoiceGrp.TaxAmt + invoiceGrp.TaxDiff; |
|
|
|
|
|
var invafter = tedsaInvs1.Sum(p => p.InvoiceNetAmount) + tedsaInvs1.Sum(p => p.InvoiceTaxAmount); |
|
|
|
|
|
var invdiff = invbefore - invafter; |
|
|
|
|
|
var line1 = tedsaInvs1.FirstOrDefault(p => p.LINE == "1"); |
|
|
|
|
|
var line2 = tedsaInvs1.FirstOrDefault(p => p.LINE == "2"); |
|
|
|
|
|
line2.InvoiceTaxAmount += invdiff; |
|
|
|
|
|
line1.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(tedsaInvs1).ConfigureAwait(false); |
|
|
|
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
|
|
|
_repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp }); |
|
|
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
{ |
|
|
{ |
|
|
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, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < invoiceGrpDetails.Count; i++) |
|
|
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>() |
|
|
|
|
|
.Where(t => t.InvbillNum == invbillNum) |
|
|
|
|
|
.ToList(); |
|
|
|
|
|
if (invoiceGrpDetails.Any()) |
|
|
{ |
|
|
{ |
|
|
var invoiceGrpDetail = invoiceGrpDetails[i]; |
|
|
var tedSaInvs = new List<TED_SAS_INVOICE>(); |
|
|
tedSaInvs.Add(new TED_SAS_INVOICE() |
|
|
var taskId = GuidGenerator.Create(); |
|
|
|
|
|
var teaTaskSub = new TEA_TASK_SUB() |
|
|
{ |
|
|
{ |
|
|
GUID = GuidGenerator.Create(), |
|
|
GUID = taskId, |
|
|
Dataid = GuidGenerator.Create(), |
|
|
TaskState = 0, |
|
|
Taskid = taskId, |
|
|
TaskID = taskId, |
|
|
invoiceNumber = invoiceGrp.RealnvBillNum, |
|
|
TableName = "TED_SAS_INVOICE", |
|
|
sasInvoiceNumber = invoiceGrp.InvbillNum, |
|
|
Creator = "SAS", |
|
|
Customer = invoiceGrp.ClientCode, |
|
|
Subscriber = "QAD", |
|
|
BillTo = invoiceGrp.ClientCode, |
|
|
Domain = "BJBMPT", |
|
|
InvoiceDate = invoiceGrp.CreationTime, |
|
|
|
|
|
Site = "BJ02", |
|
|
Site = "BJ02", |
|
|
PartNumber = invoiceGrpDetail.PartCode, |
|
|
CreateTime = DateTime.Now, |
|
|
InvoiceQuatity = -invoiceGrpDetail.Qty, |
|
|
UpdateTime = DateTime.Now, |
|
|
Price = invoiceGrpDetail.PRICE, |
|
|
}; |
|
|
InvoiceNetAmount = invoiceGrpDetail.Amt, |
|
|
for (var i = 0; i < invoiceGrpDetails.Count; i++) |
|
|
InvoiceTaxAmount = Math.Round(invoiceGrpDetail.Amt * 0.13m, 2), |
|
|
{ |
|
|
TaxRate = 0.13m, |
|
|
var invoiceGrpDetail = invoiceGrpDetails[i]; |
|
|
Location = $"C{invoiceGrp.ClientCode}", |
|
|
|
|
|
begintime = invoiceGrpDetail.BeginDate, |
|
|
tedSaInvs.Add(new TED_SAS_INVOICE() |
|
|
endtime = invoiceGrpDetail.EndDate, |
|
|
{ |
|
|
domain = "BJBMPT", |
|
|
GUID = GuidGenerator.Create(), |
|
|
LINE = (i + 1).ToString() |
|
|
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 = invoiceGrpDetail.BeginDate, |
|
|
|
|
|
endtime = invoiceGrpDetail.EndDate, |
|
|
|
|
|
domain = "BJBMPT", |
|
|
|
|
|
LINE = (i + 1).ToString() |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
tedSaInvs.FirstOrDefault().InvoiceTaxAmount += invoiceGrp.TaxDiff; |
|
|
|
|
|
//红冲发票提交QAD
|
|
|
|
|
|
if (!string.IsNullOrEmpty(invoiceGrp.ParentInvbillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (invoiceGrp.BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
|
|
{ |
|
|
|
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
await SubmitToQadHongChongAsync(invoiceGrp.ParentInvbillNum).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//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); |
|
|
|
|
|
await _exChangeCenterDbContext.BulkInsertAsync(tedSaInvs).ConfigureAwait(false); |
|
|
|
|
|
invoiceGrp.State = SettleBillState.已提交QAD; |
|
|
|
|
|
_repository.DbContext.BulkUpdateAsync(new List<INVOICE_GRP>() { invoiceGrp }); |
|
|
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false); |
|
|
|
|
|
await _exChangeCenterDbContext.Set<TED_SAS_INVOICE>().AddRangeAsync(tedSaInvs).ConfigureAwait(false); |
|
|
|
|
|
//构建发票同步Qad状态表数据
|
|
|
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -505,12 +559,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
{ |
|
|
{ |
|
|
var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber) |
|
|
var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
TableName = teaTaskSub.TableName, |
|
|
TableName = teaTaskSub.TableName, |
|
|
Domain = teaTaskSub.Domain, |
|
|
Domain = teaTaskSub.Domain, |
|
|
Site = teaTaskSub.Site, |
|
|
Site = teaTaskSub.Site, |
|
|
Customer = customer |
|
|
Customer = customer |
|
|
}; |
|
|
}; |
|
|
await _settleAccountDbContext.Set<InvoiceSyncQad>().AddAsync(invoiceSyncQad).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
await _settleAccountDbContext.BulkInsertAsync(new List<InvoiceSyncQad>() { invoiceSyncQad }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|