|
|
@ -36,8 +36,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
private readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _notRepository; |
|
|
|
private readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _adjRepository; |
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_PD, Guid> _pdRepository; |
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<BBAC_PD, Guid> _pdbbacRepository; |
|
|
|
private readonly INormalEfCoreRepository<HBPO_PD, Guid> _pdhbpoRepository; |
|
|
|
private readonly INormalEfCoreRepository<PUB_PD, Guid> _pdpubRepository; |
|
|
|
private readonly PUB_CAN_SA_MNG _pubMng; |
|
|
|
private readonly BBAC_CAN_SA_MNG _bbacMng; |
|
|
|
private readonly HBPO_CAN_SA_MNG _hbpoMng; |
|
|
@ -46,15 +47,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
PUB_CAN_SA_MNG pubMng, |
|
|
|
BBAC_CAN_SA_MNG bbacMng, |
|
|
|
HBPO_CAN_SA_MNG hbpoMng, |
|
|
|
INormalEfCoreRepository<PUB_PD, Guid> pdRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
|
INormalEfCoreRepository<BBAC_PD, Guid> pdbbacRepository, |
|
|
|
INormalEfCoreRepository<HBPO_PD, Guid> pdhbpoRepository, |
|
|
|
INormalEfCoreRepository<PUB_PD, Guid> pdpubRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> groupRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> detailRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> notRepository, |
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository |
|
|
|
) |
|
|
|
{ |
|
|
|
_pdRepository= pdRepository; |
|
|
|
|
|
|
|
//_canRepository = canRepository;
|
|
|
|
_repository = repository; |
|
|
|
_detailRepository = detailRepository; |
|
|
@ -64,6 +67,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
_pubMng = pubMng; |
|
|
|
_bbacMng = bbacMng; |
|
|
|
_hbpoMng = hbpoMng; |
|
|
|
_pdbbacRepository=pdbbacRepository; |
|
|
|
_pdhbpoRepository=pdhbpoRepository; |
|
|
|
_pdpubRepository =pdpubRepository; |
|
|
|
} |
|
|
|
|
|
|
|
public INV_MNG() |
|
|
@ -301,246 +307,439 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_groupbillnum">发票分组号</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<bool> ReceivedAsync(List<string> p_invs) |
|
|
|
public virtual async Task<bool> ReceivedAsync(List<string> p_invs) |
|
|
|
{ |
|
|
|
//var invList = _repository.Where(p =>p_invs.Contains(p.InvbillNum)).ToList();//所有提交发票信息
|
|
|
|
//int count = invList.Select(p => p.InvGroupNum).Count();
|
|
|
|
//if (count > 0)
|
|
|
|
//{
|
|
|
|
// throw new UserFriendlyException($"发票不属于一个发票分组");
|
|
|
|
//}
|
|
|
|
//var parentList = invList.Select(p => p.ParentInvbillNum).ToList();//父发票号
|
|
|
|
//List<string> oldinvs = new List<string>();
|
|
|
|
//oldinvs.AddRange(p_invs);
|
|
|
|
//if (parentList != null && parentList.Count > 0)
|
|
|
|
//{
|
|
|
|
// oldinvs.AddRange(parentList);
|
|
|
|
//}
|
|
|
|
//List<string> seclist = new List<string>();
|
|
|
|
//List<string> firstlist = new List<string>();
|
|
|
|
//var pdlist = _pdRepository.Where(p => oldinvs.Contains(p.BillNum)).ToList();
|
|
|
|
//if (pdlist != null && pdlist.Count > 0)
|
|
|
|
//{
|
|
|
|
// seclist = pdlist.Select(p => p.BillNum).ToList();//那些在待扣减里已经有了属于作废重开
|
|
|
|
//}
|
|
|
|
//firstlist = p_invs.Where(p => !seclist.Contains(p)).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var invList = _repository.Where(p => p_invs.Contains(p.InvbillNum)).ToList();//所有提交发票信息
|
|
|
|
int count = invList.Select(p => p.InvGroupNum).Distinct().Count(); |
|
|
|
if (count > 1) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException($"发票不属于一个发票分组"); |
|
|
|
} |
|
|
|
var lostlist = invList.Where(p => p.InvoiceState == InvoiceBillState.报废).ToList(); |
|
|
|
if (lostlist.Count > 0) |
|
|
|
{ |
|
|
|
var invs=lostlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
throw new UserFriendlyException($"发票{string.Join(",",invs)}"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var inv=invList.FirstOrDefault();
|
|
|
|
//if (inv.BusinessType == EnumBusinessType.JisBBAC)
|
|
|
|
//{
|
|
|
|
// var namelist=invList.Select(p => p.InvbillNum).ToList();
|
|
|
|
// var entityDetail = await _bbacMng.GetDetailByInbillNumAsync(namelist);//结算明细
|
|
|
|
// var adjlist=_adjRepository.Where(p => namelist.Contains(p.OldInvBillNum)).ToList();//调整表明细明细
|
|
|
|
var inv = invList.FirstOrDefault(); |
|
|
|
if (inv.BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
{ |
|
|
|
var pdlist = _pdbbacRepository.Where(p => p_invs.Contains(p.BillNum)).ToList();//包含发票号的代扣减单
|
|
|
|
if (pdlist != null && pdlist.Count > 0) |
|
|
|
{ |
|
|
|
var invs = pdlist.Select(p => p.BillNum).ToList(); |
|
|
|
throw new UserFriendlyException($"发票{string.Join(",", invs)}已经生成待扣减过不能再次提交"); |
|
|
|
} |
|
|
|
var parentList = invList.Select(p => p.ParentInvbillNum).ToList();//所有发票存在父发票号
|
|
|
|
List<string> oldinvs = new List<string>(); |
|
|
|
oldinvs.AddRange(p_invs); |
|
|
|
if (parentList != null && parentList.Count > 0) |
|
|
|
{ |
|
|
|
oldinvs.AddRange(parentList); |
|
|
|
} |
|
|
|
List<string> oldlist = new List<string>();//以前提交过的发票
|
|
|
|
List<string> newlist = new List<string>();//没有提交过的发票
|
|
|
|
var pdoldlist = pdlist.Where(p => oldinvs.Contains(p.BillNum)).ToList(); |
|
|
|
if (pdoldlist != null && pdoldlist.Count > 0) |
|
|
|
{ |
|
|
|
oldlist = pdoldlist.Select(p => p.BillNum).ToList();//已经存在扣减记录,的发票号
|
|
|
|
} |
|
|
|
newlist = p_invs.Where(p => !oldlist.Contains(p)).ToList();//不存在扣减记录的发票号
|
|
|
|
|
|
|
|
|
|
|
|
// if (adjlist != null && adjlist.Count() > 0)
|
|
|
|
// {
|
|
|
|
// foreach (var itm in adjlist)
|
|
|
|
// {
|
|
|
|
// entityDetail.Add(new BBAC_CAN_SA_DETAIL(
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// keyCode: itm.KeyCode,
|
|
|
|
// version: itm.Version,
|
|
|
|
// billNum: itm.InvGroupNum,
|
|
|
|
// settleBillNum: itm.SettleBillNum,
|
|
|
|
// lU: itm.LU,
|
|
|
|
// pN: itm.PN,
|
|
|
|
// site: itm.Site,
|
|
|
|
// qty: itm.Qty,
|
|
|
|
// price: itm.Price,
|
|
|
|
// category: itm.BusinessType,
|
|
|
|
// isReturn: itm.Qty > 0 ? false : true,
|
|
|
|
// settleDate: itm.SettleDate,
|
|
|
|
// groupNum: itm.GroupNum,
|
|
|
|
// invGroupNum: itm.InvGroupNum,
|
|
|
|
// contactid: itm.Extend1//生产号
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
List<BBAC_CAN_SA_DETAIL> entityList = new List<BBAC_CAN_SA_DETAIL>();//结算明细
|
|
|
|
var namelist = invList.Select(p => p.InvbillNum).ToList(); |
|
|
|
if (oldlist.Count > 0) |
|
|
|
{ |
|
|
|
var involdList= invList.Where(p => oldinvs.Contains(p.ParentInvbillNum)).ToList(); |
|
|
|
var involdname=involdList.Select(p => p.InvbillNum); |
|
|
|
var adjlist=_adjRepository.Where(p => involdname.Contains(p.InvBillNum)); |
|
|
|
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityList.Add(new BBAC_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
category: itm.BusinessType, |
|
|
|
isReturn: itm.Qty > 0 ? false : true, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
contactid: itm.Extend1,//生产号
|
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (newlist.Count > 0) |
|
|
|
{ |
|
|
|
var entitys = invList.Where(p => newlist.Contains(p.InvbillNum)).ToList(); |
|
|
|
var entityDetail = await _bbacMng.GetDetailByInbillNumAsync(newlist);//结算明细
|
|
|
|
var adjlist = _adjRepository.Where(p => newlist.Contains(p.InvBillNum)).ToList();//发票关联调整表明细
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityDetail.Add(new BBAC_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
category: itm.BusinessType, |
|
|
|
isReturn: itm.Qty > 0 ? false : true, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
contactid: itm.Extend1,//生产号
|
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
|
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
entityList.AddRange(entityDetail); |
|
|
|
|
|
|
|
//entityDetail.GroupBy(p =>new {
|
|
|
|
// p.LU,
|
|
|
|
// p.PN,
|
|
|
|
// p.Site,
|
|
|
|
// p.Qty,
|
|
|
|
// p.BusinessType
|
|
|
|
//}).Select(p =>new BBAC_PD_DETAIL(
|
|
|
|
} |
|
|
|
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// keyCode: p.Key.PN.Trim()+p.Key.LU,
|
|
|
|
// version: p.Key.Version,
|
|
|
|
// billNum: string.Empty,
|
|
|
|
// lU: p.Key.LU,
|
|
|
|
// rELU: string.Empty,
|
|
|
|
// pN: p.Key.PN,
|
|
|
|
// rEPN: string.Empty,
|
|
|
|
// site: string.Empty,
|
|
|
|
// qty:p.Sum(itm=>itm.Qty),
|
|
|
|
// price: 0,
|
|
|
|
// invGroupNum: p.Key.,
|
|
|
|
// settleDate: p.SettleDate,
|
|
|
|
// groupNum: p.GroupNum,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty,
|
|
|
|
// extend3: string.Empty,
|
|
|
|
// extend4: string.Empty
|
|
|
|
var bbacmainlist = new List<BBAC_PD>(); |
|
|
|
foreach (var itm in invList) |
|
|
|
{ |
|
|
|
var bbac = new BBAC_PD( |
|
|
|
guid: itm.Id, |
|
|
|
version:int.Parse(DateTime.Now.ToString("yyyyMM")), |
|
|
|
billNum: itm.InvbillNum, |
|
|
|
settleBillNum: itm.InvGroupNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
site: string.Empty |
|
|
|
); |
|
|
|
bbacmainlist.Add( bbac ); |
|
|
|
|
|
|
|
} |
|
|
|
var bbacDetail = new List<BBAC_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityList) |
|
|
|
{ |
|
|
|
bbacDetail.Add( |
|
|
|
new BBAC_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacmainlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacDetail); |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (inv.BusinessType == EnumBusinessType.JisHBPO) |
|
|
|
{ |
|
|
|
var pdlist = _pdhbpoRepository.Where(p => p_invs.Contains(p.BillNum)).ToList();//包含发票号的代扣减单
|
|
|
|
if (pdlist != null && pdlist.Count > 0) |
|
|
|
{ |
|
|
|
var invs = pdlist.Select(p => p.BillNum).ToList(); |
|
|
|
throw new UserFriendlyException($"发票{string.Join(",", invs)}已经生成待扣减过不能再次提交"); |
|
|
|
} |
|
|
|
var parentList = invList.Select(p => p.ParentInvbillNum).ToList();//所有发票存在父发票号
|
|
|
|
List<string> oldinvs = new List<string>(); |
|
|
|
oldinvs.AddRange(p_invs); |
|
|
|
if (parentList != null && parentList.Count > 0) |
|
|
|
{ |
|
|
|
oldinvs.AddRange(parentList); |
|
|
|
} |
|
|
|
List<string> oldlist = new List<string>();//以前提交过的发票
|
|
|
|
List<string> newlist = new List<string>();//没有提交过的发票
|
|
|
|
var pdoldlist = pdlist.Where(p => oldinvs.Contains(p.BillNum)).ToList(); |
|
|
|
if (pdoldlist != null && pdoldlist.Count > 0) |
|
|
|
{ |
|
|
|
oldlist = pdoldlist.Select(p => p.BillNum).ToList();//已经存在扣减记录,的发票号
|
|
|
|
} |
|
|
|
newlist = p_invs.Where(p => !oldlist.Contains(p)).ToList();//不存在扣减记录的发票号
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<HBPO_CAN_SA_DETAIL> entityList = new List<HBPO_CAN_SA_DETAIL>();//结算明细
|
|
|
|
var namelist = invList.Select(p => p.InvbillNum).ToList(); |
|
|
|
if (oldlist.Count > 0) |
|
|
|
{ |
|
|
|
var involdList = invList.Where(p => oldinvs.Contains(p.ParentInvbillNum)).ToList(); |
|
|
|
var involdname = involdList.Select(p => p.InvbillNum); |
|
|
|
var adjlist = _adjRepository.Where(p => involdname.Contains(p.InvBillNum)); |
|
|
|
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityList.Add(new HBPO_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
businessType: itm.BusinessType, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (newlist.Count > 0) |
|
|
|
{ |
|
|
|
var entitys = invList.Where(p => newlist.Contains(p.InvbillNum)).ToList(); |
|
|
|
var entityDetail = await _hbpoMng.GetDetailByInbillNumAsync(newlist);//结算明细
|
|
|
|
var adjlist = _adjRepository.Where(p => newlist.Contains(p.InvBillNum)).ToList();//发票关联调整表明细
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityDetail.Add(new HBPO_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
businessType: itm.BusinessType, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
entityList.AddRange(entityDetail); |
|
|
|
|
|
|
|
//);
|
|
|
|
} |
|
|
|
|
|
|
|
var bbacmainlist = new List<HBPO_PD>(); |
|
|
|
foreach (var itm in invList) |
|
|
|
{ |
|
|
|
var bbac = new HBPO_PD( |
|
|
|
guid: itm.Id, |
|
|
|
version: int.Parse(DateTime.Now.ToString("yyyyMM")), |
|
|
|
billNum: itm.InvbillNum, |
|
|
|
settleBillNum: itm.InvGroupNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
site: string.Empty |
|
|
|
); |
|
|
|
bbacmainlist.Add(bbac); |
|
|
|
|
|
|
|
} |
|
|
|
var bbacDetail = new List<HBPO_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityList) |
|
|
|
{ |
|
|
|
bbacDetail.Add( |
|
|
|
new HBPO_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacmainlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacDetail); |
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var pdlist = _pdpubRepository.Where(p => p_invs.Contains(p.BillNum)).ToList();//包含发票号的代扣减单
|
|
|
|
if (pdlist != null && pdlist.Count > 0) |
|
|
|
{ |
|
|
|
var invs = pdlist.Select(p => p.BillNum).ToList(); |
|
|
|
throw new UserFriendlyException($"发票{string.Join(",", invs)}已经生成待扣减过不能再次提交"); |
|
|
|
} |
|
|
|
var parentList = invList.Select(p => p.ParentInvbillNum).ToList();//所有发票存在父发票号
|
|
|
|
List<string> oldinvs = new List<string>(); |
|
|
|
oldinvs.AddRange(p_invs); |
|
|
|
if (parentList != null && parentList.Count > 0) |
|
|
|
{ |
|
|
|
oldinvs.AddRange(parentList); |
|
|
|
} |
|
|
|
List<string> oldlist = new List<string>();//以前提交过的发票
|
|
|
|
List<string> newlist = new List<string>();//没有提交过的发票
|
|
|
|
var pdoldlist = pdlist.Where(p => oldinvs.Contains(p.BillNum)).ToList(); |
|
|
|
if (pdoldlist != null && pdoldlist.Count > 0) |
|
|
|
{ |
|
|
|
oldlist = pdoldlist.Select(p => p.BillNum).ToList();//已经存在扣减记录,的发票号
|
|
|
|
} |
|
|
|
newlist = p_invs.Where(p => !oldlist.Contains(p)).ToList();//不存在扣减记录的发票号
|
|
|
|
|
|
|
|
List<PUB_CAN_SA_DETAIL> entityList = new List<PUB_CAN_SA_DETAIL>();//结算明细
|
|
|
|
var namelist = invList.Select(p => p.InvbillNum).ToList(); |
|
|
|
if (oldlist.Count > 0) |
|
|
|
{ |
|
|
|
var involdList = invList.Where(p => oldinvs.Contains(p.ParentInvbillNum)).ToList(); |
|
|
|
var involdname = involdList.Select(p => p.InvbillNum); |
|
|
|
var adjlist = _adjRepository.Where(p => involdname.Contains(p.InvBillNum)); |
|
|
|
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityList.Add(new PUB_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
businessType: itm.BusinessType, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (newlist.Count > 0) |
|
|
|
{ |
|
|
|
var entitys = invList.Where(p => newlist.Contains(p.InvbillNum)).ToList(); |
|
|
|
var entityDetail = await _pubMng.GetDetailByInbillNumAsync(newlist);//结算明细
|
|
|
|
var adjlist = _adjRepository.Where(p => newlist.Contains(p.InvBillNum)).ToList();//发票关联调整表明细
|
|
|
|
if (adjlist != null && adjlist.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
entityDetail.Add(new PUB_CAN_SA_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.InvGroupNum, |
|
|
|
settleBillNum: itm.SettleBillNum, |
|
|
|
lU: itm.LU, |
|
|
|
pN: itm.PN, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
businessType: itm.BusinessType, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
invbillnum: itm.InvBillNum |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
entityList.AddRange(entityDetail); |
|
|
|
|
|
|
|
// var bbac = new BBAC_PD(
|
|
|
|
// guid: entity.Id,
|
|
|
|
// version: entity.Version,
|
|
|
|
// billNum: entity.BillNum,
|
|
|
|
// settleBillNum: entity.SettleBillNum,
|
|
|
|
// state: SettleBillState.客户已收票,
|
|
|
|
// invGroupNum: entity.InvGroupNum,
|
|
|
|
// site: entity.Site
|
|
|
|
// );
|
|
|
|
// var bbacDetail = new List<BBAC_PD_DETAIL>();
|
|
|
|
} |
|
|
|
|
|
|
|
// foreach (var itm in entityDetail)
|
|
|
|
// {
|
|
|
|
// bbacDetail.Add(
|
|
|
|
// new BBAC_PD_DETAIL(
|
|
|
|
// guid: itm.Id,
|
|
|
|
// keyCode: itm.KeyCode,
|
|
|
|
// version: itm.Version,
|
|
|
|
// billNum: itm.BillNum,
|
|
|
|
// lU: itm.LU,
|
|
|
|
// rELU: string.Empty,
|
|
|
|
// pN: itm.PN,
|
|
|
|
// rEPN: string.Empty,
|
|
|
|
// site: itm.Site,
|
|
|
|
// qty: itm.Qty,
|
|
|
|
// price: itm.Price,
|
|
|
|
// invGroupNum: itm.InvGroupNum,
|
|
|
|
// settleDate: itm.SettleDate,
|
|
|
|
// groupNum: itm.GroupNum,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty,
|
|
|
|
// extend3: string.Empty,
|
|
|
|
// extend4: string.Empty
|
|
|
|
// ));
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(new List<BBAC_PD>() { bbac });
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(bbacDetail);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
var bbacmainlist = new List<PUB_PD>(); |
|
|
|
foreach (var itm in invList) |
|
|
|
{ |
|
|
|
var pub = new PUB_PD( |
|
|
|
guid: itm.Id, |
|
|
|
version: int.Parse(DateTime.Now.ToString("yyyyMM")), |
|
|
|
billNum: itm.InvbillNum, |
|
|
|
settleBillNum: itm.InvGroupNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
site: string.Empty |
|
|
|
); |
|
|
|
bbacmainlist.Add(pub); |
|
|
|
|
|
|
|
//}
|
|
|
|
//else if (inv.BusinessType == EnumBusinessType.JisHBPO)
|
|
|
|
//{
|
|
|
|
// var entity = await _hbpoMng.GetMainAsync(inv.InvGroupNum);
|
|
|
|
// if (entity != null)
|
|
|
|
// {
|
|
|
|
} |
|
|
|
var bbacDetail = new List<PUB_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityList) |
|
|
|
{ |
|
|
|
bbacDetail.Add( |
|
|
|
new PUB_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: 0, |
|
|
|
businessType:itm.BusinessType, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacmainlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacDetail); |
|
|
|
return true; |
|
|
|
|
|
|
|
// var entityDetail = await _hbpoMng.GetDetalListAsync(inv.InvGroupNum);
|
|
|
|
// if (entityDetail != null && entityDetail.Count() > 0)
|
|
|
|
// {
|
|
|
|
// var hbpo = new HBPO_PD(
|
|
|
|
// guid: entity.Id,
|
|
|
|
// version: entity.Version,
|
|
|
|
// billNum: entity.BillNum,
|
|
|
|
// settleBillNum: entity.SettleBillNum,
|
|
|
|
// state: SettleBillState.客户已收票,
|
|
|
|
// invGroupNum: entity.InvGroupNum,
|
|
|
|
// site: entity.Site
|
|
|
|
// );
|
|
|
|
// var hbpoDetail = new List<HBPO_PD_DETAIL>();
|
|
|
|
// foreach (var itm in entityDetail)
|
|
|
|
// {
|
|
|
|
// hbpoDetail.Add(
|
|
|
|
// new HBPO_PD_DETAIL(
|
|
|
|
// guid: itm.Id,
|
|
|
|
// keyCode: itm.KeyCode,
|
|
|
|
// version: itm.Version,
|
|
|
|
// billNum: itm.BillNum,
|
|
|
|
// lU: itm.LU,
|
|
|
|
// rELU: string.Empty,
|
|
|
|
// pN: itm.PN,
|
|
|
|
// rEPN: string.Empty,
|
|
|
|
// site: itm.Site,
|
|
|
|
// qty: itm.Qty,
|
|
|
|
// price: itm.Price,
|
|
|
|
// invGroupNum: itm.InvGroupNum,
|
|
|
|
// settleDate: itm.SettleDate,
|
|
|
|
// groupNum: itm.GroupNum,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty,
|
|
|
|
// extend3: string.Empty,
|
|
|
|
// extend4: string.Empty
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(new List<HBPO_PD>() { hbpo });
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(hbpoDetail);
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// var entity = await _pubMng.GetMainAsync(inv.InvGroupNum);
|
|
|
|
// if (entity != null)
|
|
|
|
// {
|
|
|
|
// var entityDetail = await _pubMng.GetDetalListAsync(inv.InvGroupNum);
|
|
|
|
// if (entityDetail != null && entityDetail.Count() > 0)
|
|
|
|
// {
|
|
|
|
// var pub = new PUB_PD(
|
|
|
|
// guid: entity.Id,
|
|
|
|
// version: entity.Version,
|
|
|
|
// billNum: entity.BillNum,
|
|
|
|
// settleBillNum: entity.SettleBillNum,
|
|
|
|
// state: SettleBillState.客户已收票,
|
|
|
|
// invGroupNum: entity.InvGroupNum,
|
|
|
|
// site: entity.Site
|
|
|
|
// );
|
|
|
|
// var pubDetail = new List<PUB_PD_DETAIL>();
|
|
|
|
// foreach (var itm in entityDetail)
|
|
|
|
// {
|
|
|
|
// pubDetail.Add(
|
|
|
|
// new PUB_PD_DETAIL(
|
|
|
|
// guid: itm.Id,
|
|
|
|
// keyCode: itm.KeyCode,
|
|
|
|
// version: itm.Version,
|
|
|
|
// billNum: itm.BillNum,
|
|
|
|
// lU: itm.LU,
|
|
|
|
// rELU: string.Empty,
|
|
|
|
// pN: itm.PN,
|
|
|
|
// rEPN: string.Empty,
|
|
|
|
// site: itm.Site,
|
|
|
|
// qty: itm.Qty,
|
|
|
|
// price: itm.Price,
|
|
|
|
// invGroupNum: itm.InvGroupNum,
|
|
|
|
// settleDate: itm.SettleDate,
|
|
|
|
// groupNum: itm.GroupNum,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty,
|
|
|
|
// extend3: string.Empty,
|
|
|
|
// extend4: string.Empty,
|
|
|
|
// businessType: itm.BusinessType
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(new List<PUB_PD>() { pub });
|
|
|
|
// await _repository.DbContext.BulkInsertAsync(pubDetail);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
public virtual async Task<bool> Reject(INVOICE_GRP p_entity) |
|
|
@ -762,7 +961,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
select itm2; |
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
|
itm.BillNum = key; |
|
|
|
itm.InvbillNum = key; |
|
|
|
salist.Add(itm); |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
@ -989,10 +1188,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
select itm2; |
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
|
itm.BillNum = key; |
|
|
|
|
|
|
|
itm.InvbillNum = key; |
|
|
|
salist.Add(itm); |
|
|
|
|
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
|
{ |
|
|
@ -1177,7 +1374,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
var invdetails = p_list.Where(p => ls.Contains(p.GroupNum)).ToList(); |
|
|
|
foreach (var detail in invdetails) |
|
|
|
{ |
|
|
|
detail.BillNum = key; |
|
|
|
detail.InvbillNum = key; |
|
|
|
salist.Add(detail); |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
@ -1351,12 +1548,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var adj in p_adjlist) |
|
|
|
{ |
|
|
|
adj.InvBillNum = string.Join(",", invlist);//调整单更新发票信息
|
|
|
|
} |
|
|
|
//foreach (var adj in p_adjlist)
|
|
|
|
//{
|
|
|
|
// adj.InvBillNum = string.Join(",", invlist);//调整单更新发票信息
|
|
|
|
//}
|
|
|
|
|
|
|
|
_repository.DbContext.BulkUpdate(p_adjlist); |
|
|
|
//_repository.DbContext.BulkUpdate(p_adjlist);
|
|
|
|
|
|
|
|
_repository.DbContext.BulkUpdate(new List<INVOICE_GRP> { inv }); |
|
|
|
return true; |
|
|
@ -1408,7 +1605,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
//{
|
|
|
|
// adj.InvBillNum = string.Join(",", invlist);
|
|
|
|
//}
|
|
|
|
_repository.DbContext.BulkUpdate(p_adjlist); |
|
|
|
//_repository.DbContext.BulkUpdate(p_adjlist);
|
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|