|
|
@ -4,6 +4,7 @@ using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using AutoMapper; |
|
|
|
using CodeArts.Db.Lts; |
|
|
|
using DocumentFormat.OpenXml.Presentation; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
@ -34,7 +35,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
public decimal Amt { set; get; } |
|
|
|
public decimal TaxAmt { set; get; } |
|
|
|
|
|
|
|
public decimal Tax { set; get;} |
|
|
|
public decimal Tax { set; get; } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -116,7 +117,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
else//二次开票
|
|
|
|
{ |
|
|
|
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); |
|
|
|
var query = from b in _dbcontext.Set<BBAC_NOT_SA_DETAIL>() |
|
|
|
join a in (from d in _dbcontext.Set<BBAC_CAN_SA_DETAIL>() |
|
|
|
where d.BillNum == main.BillNum |
|
|
|
select d.GroupNum).Distinct() |
|
|
|
on b.GroupNum equals a |
|
|
|
group b by new { b.GroupNum, b.LU } into g |
|
|
|
select new TEMP_NOT_SA_DETAIL |
|
|
|
{ |
|
|
|
GroupNum = g.Key.GroupNum, |
|
|
|
LU = g.Key.LU, |
|
|
|
Qty = g.Sum(p => p.Qty), |
|
|
|
}; |
|
|
|
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); |
|
|
|
if (invs.Count > 0) |
|
|
|
{ |
|
|
|
main.State = SettleBillState.已开票; |
|
|
@ -126,7 +139,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_dbcontext.BulkUpdate(new List<BBAC_CAN_SA>() { main }); |
|
|
|
} |
|
|
|
} |
|
|
|
if(BussinessType== "JisHBPO") |
|
|
|
if (BussinessType == "JisHBPO") |
|
|
|
{ |
|
|
|
var main = _dbcontext.Set<HBPO_CAN_SA>().FirstOrDefault(p => p.InvGroupNum == billNum); |
|
|
|
//var main = await _bbacMng.GetMainAsync(invbillNum);
|
|
|
@ -155,7 +168,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
Qty = d.Qty, |
|
|
|
GroupNum = d.GroupNum, |
|
|
|
Amt = Math.Round(d.Qty * p.Price, 2), |
|
|
|
ContractDocID ="n", |
|
|
|
ContractDocID = "n", |
|
|
|
BeginDate = p.BeginTime, |
|
|
|
EndDate = p.EndTime, |
|
|
|
PartCode = d.PartCode |
|
|
@ -192,7 +205,21 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
else//二次开票
|
|
|
|
{ |
|
|
|
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); |
|
|
|
var query = from b in _dbcontext.Set<HBPO_NOT_SA_DETAIL>() |
|
|
|
join a in (from d in _dbcontext.Set<HBPO_CAN_SA_DETAIL>() |
|
|
|
where d.BillNum == main.BillNum |
|
|
|
select d.GroupNum).Distinct() |
|
|
|
on b.GroupNum equals a |
|
|
|
group b by new { b.GroupNum, b.LU } into g |
|
|
|
select new TEMP_NOT_SA_DETAIL |
|
|
|
{ |
|
|
|
GroupNum = g.Key.GroupNum, |
|
|
|
LU = g.Key.LU, |
|
|
|
Qty = g.Sum(p => p.Qty), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList()); |
|
|
|
if (invs.Count > 0) |
|
|
|
{ |
|
|
|
main.State = SettleBillState.已开票; |
|
|
@ -204,7 +231,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
return id.ToString(); |
|
|
|
} |
|
|
|
public List<string> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_ajdlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) |
|
|
|
public List<string> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_ajdlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, List<TEMP_NOT_SA_DETAIL> p_notlist = null) |
|
|
|
where TDetail : SA_CAN_BASE |
|
|
|
{ |
|
|
|
List<string> _invls = new List<string>(); |
|
|
@ -252,39 +279,45 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
&& group.BeginDate == group1.BeginDate |
|
|
|
&& group.EndDate == group1.EndDate |
|
|
|
&& group1.ContractDocID == group.ContractDocID |
|
|
|
&& group1.Price == group.Price |
|
|
|
&& group1.Qty == group.Qty |
|
|
|
&& group1.Amt == group.Amt |
|
|
|
) |
|
|
|
{ |
|
|
|
tempList.Add(group1); |
|
|
|
partCount++;//符合条件加入到零件中
|
|
|
|
continue; |
|
|
|
} |
|
|
|
//partCount++;
|
|
|
|
//if (partCount > 30)
|
|
|
|
//{
|
|
|
|
// continue;
|
|
|
|
//}
|
|
|
|
sum += group1.Amt; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
sum += group1.Amt; |
|
|
|
tempList.Add(group1); |
|
|
|
} |
|
|
|
invoiceMap.Add(invoiceBillNum, tempList); |
|
|
|
|
|
|
|
|
|
|
|
var query = from itm in groups1 //更新分组
|
|
|
|
join itm1 in tempList |
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID, itm.PartCode } |
|
|
|
equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID, itm1.PartCode } into temp |
|
|
|
from tm in temp |
|
|
|
on |
|
|
|
new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID, itm.PartCode, itm.Qty, itm.Price, itm.Amt } |
|
|
|
equals |
|
|
|
new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID, itm1.PartCode, itm1.Qty, itm1.Price, itm1.Amt } |
|
|
|
into temp |
|
|
|
from tm in temp.DefaultIfEmpty() |
|
|
|
where tm == null |
|
|
|
select new TMEP_INV |
|
|
|
{ |
|
|
|
LU = itm.LU, |
|
|
|
Amt = itm.Amt, |
|
|
|
Qty = itm.Qty, |
|
|
|
Price = itm.Price, |
|
|
|
BeginDate = itm.BeginDate, |
|
|
|
ContractDocID = itm.ContractDocID, |
|
|
|
EndDate = itm.EndDate |
|
|
|
EndDate = itm.EndDate, |
|
|
|
PartCode = itm.PartCode, |
|
|
|
|
|
|
|
}; |
|
|
|
groups1 = query.ToList(); |
|
|
|
} |
|
|
@ -297,6 +330,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
var salist = new List<TDetail>(); |
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
|
int count = invoiceMap.Keys.Count;//计算第几张发票计数器
|
|
|
|
int i = 1; |
|
|
|
foreach (var group in invoiceMap) |
|
|
|
{ |
|
|
|
var key = group.Key;//发票票号
|
|
|
@ -304,9 +339,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
//反向查找结算数据
|
|
|
|
var query = from itm in dtos |
|
|
|
join itm1 in ls |
|
|
|
on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate } |
|
|
|
on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate, itm.ContractDocID } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID } |
|
|
|
join itm2 in p_list on new { itm.PartCode, itm.PN, itm.SettleDate } equals new { itm2.PartCode, itm2.PN, itm2.SettleDate } |
|
|
|
select itm2; |
|
|
|
select itm2;//反向更新可计算数据
|
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
|
itm.InvbillNum = key; |
|
|
@ -351,27 +386,66 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
} |
|
|
|
List<tempAmt> amtList = new List<tempAmt>(); |
|
|
|
foreach (var itm in detailList) |
|
|
|
#region 发票不能结算的明细
|
|
|
|
var innotls = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var sq = query.GroupBy(p => new { p.LU, p.GroupNum }) |
|
|
|
.Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = group.Key, 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: group.Key |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
amtList.Add(new tempAmt() { |
|
|
|
Amt=itm.Amt, |
|
|
|
Tax=Math.Round(itm.Amt*0.13m,2), |
|
|
|
TaxAmt=itm.Amt+ Math.Round(itm.Amt * 0.13m, 2) |
|
|
|
}); |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
decimal amt = amtList.Sum(k => k.Amt);//金额
|
|
|
|
decimal txtAmt = amtList.Sum(k => k.TaxAmt) ;//税后金额
|
|
|
|
decimal readAmt = amtList.Sum(k=>k.Tax);//税额
|
|
|
|
if (p_notlist != null && p_notlist.Count > 0) |
|
|
|
{ |
|
|
|
var innotls1 = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
|
|
|
|
var grouplist = query.Select(p => p.GroupNum).ToList(); |
|
|
|
|
|
|
|
//decimal amt = detailList.Sum(k => k.Amt);
|
|
|
|
//decimal txtAmt = Math.Round(detailList.Sum(k => k.Amt), 2);
|
|
|
|
|
|
|
|
var contractList = ls.Select(p => p.ContractDocID).Distinct(); |
|
|
|
var _groupList = dtos.Where(p => contractList.Contains(p.ContractDocID)).GroupBy(p => new { p.GroupNum }) |
|
|
|
.Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct(); |
|
|
|
//var _groupList = dtos.GroupBy(p => new { p.GroupNum })
|
|
|
|
// .Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct();
|
|
|
|
var notlist = p_notlist.Where(p => grouplist.Contains(p.GroupNum)); |
|
|
|
|
|
|
|
foreach (var nitm in notlist) |
|
|
|
{ |
|
|
|
innotls1.Add(new INVOICE_NOT_SETTLE( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: nitm.GroupNum, |
|
|
|
lU: nitm.LU, |
|
|
|
lU1: nitm.LU, |
|
|
|
extend1: "不可结算", |
|
|
|
extend2: string.Empty, |
|
|
|
qty: nitm.Qty, |
|
|
|
p_invbillnum: group.Key |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls1); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
decimal amt = ls.Sum(k => k.Amt);//金额
|
|
|
|
decimal txtAmt = Math.Round(amt * 0.13m, 2);//税后金额
|
|
|
|
decimal readAmt = amt + Math.Round(amt * 0.13m, 2);//税额
|
|
|
|
|
|
|
|
//var contractList = ls.Select(p => p.ContractDocID).Distinct();
|
|
|
|
var _groupList = query.GroupBy(p => new { p.GroupNum }) |
|
|
|
.Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => Math.Round(itm.Qty * itm.Price, 2)) }).Distinct(); |
|
|
|
List<INVOICE_MAP_GROUP> group1 = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var en in _groupList) |
|
|
|
{ |
|
|
@ -390,7 +464,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
groupList.AddRange(group1); |
|
|
|
} |
|
|
|
|
|
|
|
var lst = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).ToList(); |
|
|
|
string site = lst.FirstOrDefault().Site; |
|
|
|
string clientCode = string.Empty; |
|
|
@ -434,6 +507,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_dbcontext.BulkInsert(invlist); |
|
|
|
_dbcontext.BulkInsert(groupList); |
|
|
|
_dbcontext.BulkInsert(detailList); |
|
|
|
_dbcontext.BulkInsert(notDetialList); |
|
|
|
|
|
|
|
if (salist.Count > 0) |
|
|
|
{ |
|
|
|
_dbcontext.BulkUpdate(salist); |
|
|
@ -447,7 +522,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
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) |
|
|
|
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>(); |
|
|
@ -552,7 +627,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
lsby.AddRange(grouplist); |
|
|
|
var nolist = p_notlist.Where(p => !grouplist.Contains(p.GroupNum)).Select(p => p.GroupNum).ToList();//不可结分组
|
|
|
|
int count = invoiceMap.Keys.Count;//计算第几张发票计数器
|
|
|
|
|
|
|
|
int i = 1; |
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
|
{ |
|
|
@ -585,14 +659,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
Price = itm.Key.Price, |
|
|
|
Amt = Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税前
|
|
|
|
Tax = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2),//税
|
|
|
|
TaxAmt = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2)+ Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税后进
|
|
|
|
TaxAmt = Math.Round(Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2) * 0.13m, 2) + Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2),//税后进
|
|
|
|
Qty = itm.Sum(k => k.Qty), |
|
|
|
BeginDate = itm.Key.BeginDate, |
|
|
|
EndDate = itm.Key.EndDate |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
decimal amt = detailDtos.Sum(k => k.Amt);//金额
|
|
|
|
decimal txtAmt = detailDtos.Sum(k => k.TaxAmt);//税后金额
|
|
|
|
decimal realAmt =detailDtos.Sum(k => k.Tax);//税额
|
|
|
|
decimal realAmt = detailDtos.Sum(k => k.Tax);//税额
|
|
|
|
|
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in ls) |
|
|
|