|
|
@ -142,6 +142,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
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>(); |
|
|
@ -162,7 +179,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
}; |
|
|
|
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) |
|
|
|
{ |
|
|
@ -177,24 +194,52 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (itm.Qty > first.Qty) |
|
|
|
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.Extend2 = "CC16"; |
|
|
|
} |
|
|
|
if (invoiceGrp.Site == "1040") |
|
|
|
{ |
|
|
|
inv.Extend2 ="CC11"; |
|
|
|
inv.Amt = Math.Round((itm.Qty - first.Qty) * itm.PRICE, 2); |
|
|
|
} |
|
|
|
//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.RealPartCode; |
|
|
|
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]; |
|
|
@ -224,8 +269,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
} |
|
|
|
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 a = tedsaInvs1.Sum(p => p.InvoiceNetAmount); |
|
|
|
|
|
|
|
var b=tedsaInvs1.Sum(p => p.InvoiceTaxAmount); |
|
|
|
var invafter = a + b; |
|
|
|
var invdiff = invbefore - invafter; |
|
|
|
var line1 = tedsaInvs1.FirstOrDefault(p => p.LINE == "1"); |
|
|
|
var line2 = tedsaInvs1.FirstOrDefault(p => p.LINE == "2"); |
|
|
|
line2.InvoiceTaxAmount += invdiff; |
|
|
@ -239,7 +288,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
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).ConfigureAwait(false); |
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
//await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false);
|
|
|
|
// var retryPolicyAsync = Policy.Handle<Exception>().WaitAndRetryAsync(new[] {
|
|
|
@ -299,6 +348,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
{ |
|
|
|
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"); |
|
|
@ -337,7 +390,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
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).ConfigureAwait(false); |
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode, invoiceGrp.CreationTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -402,6 +455,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
inv.Qty = itm.Qty - first.Qty;//发票总数中去除
|
|
|
|
inv.Amt = Math.Round(itm.Qty * itm.PRICE, 2); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inv.BussiessType = EnumBusinessType.MaiDanJianBBAC; |
|
|
|
if (invoiceGrp.Site == "1046") |
|
|
|
{ |
|
|
@ -460,7 +517,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
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).ConfigureAwait(false); |
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode,invoiceGrp.CreationTime).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
@ -533,7 +590,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
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).ConfigureAwait(false); |
|
|
|
await BindInvoiceSyncQadAsync(teaTaskSub, invoiceGrp.RealnvBillNum, invoiceGrp.InvbillNum, invoiceGrp.ClientCode,invoiceGrp.CreationTime).ConfigureAwait(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -542,9 +599,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
/// <summary>
|
|
|
|
/// 构建发票同步Qad状态表数据
|
|
|
|
/// </summary>
|
|
|
|
private async Task BindInvoiceSyncQadAsync(TEA_TASK_SUB teaTaskSub, string invoiceNumber, string sasInvoiceNumber, string customer) |
|
|
|
private async Task BindInvoiceSyncQadAsync(TEA_TASK_SUB teaTaskSub, string invoiceNumber, string sasInvoiceNumber, string customer,DateTime dateTime) |
|
|
|
{ |
|
|
|
var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber) |
|
|
|
var invoiceSyncQad = new InvoiceSyncQad(teaTaskSub.TaskID, invoiceNumber, sasInvoiceNumber,dateTime) |
|
|
|
{ |
|
|
|
|
|
|
|
TableName = teaTaskSub.TableName, |
|
|
@ -552,7 +609,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
Site = teaTaskSub.Site, |
|
|
|
Customer = customer |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
invoiceSyncQad.SetId(teaTaskSub.TaskID); |
|
|
|
|
|
|
|
|
|
|
|