|
@ -1,4 +1,5 @@ |
|
|
using EFCore.BulkExtensions; |
|
|
using EFCore.BulkExtensions; |
|
|
|
|
|
using EmptyFiles; |
|
|
using Hangfire; |
|
|
using Hangfire; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax; |
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax; |
|
@ -8,8 +9,10 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; |
|
|
using SettleAccount.Bases; |
|
|
using SettleAccount.Bases; |
|
|
using SettleAccount.Domain.BQ; |
|
|
using SettleAccount.Domain.BQ; |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Security.Policy; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Volo.Abp; |
|
|
using Volo.Abp; |
|
@ -31,9 +34,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
private readonly INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> _groupRepository; |
|
|
private readonly INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> _groupRepository; |
|
|
private readonly INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> _detailRepository; |
|
|
private readonly INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> _detailRepository; |
|
|
private readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _notRepository; |
|
|
private readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _notRepository; |
|
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _adjRepository; |
|
|
private readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _adjRepository; |
|
|
|
|
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_PD, Guid> _pdRepository; |
|
|
|
|
|
|
|
|
private readonly PUB_CAN_SA_MNG _pubMng; |
|
|
private readonly PUB_CAN_SA_MNG _pubMng; |
|
|
private readonly BBAC_CAN_SA_MNG _bbacMng; |
|
|
private readonly BBAC_CAN_SA_MNG _bbacMng; |
|
|
private readonly HBPO_CAN_SA_MNG _hbpoMng; |
|
|
private readonly HBPO_CAN_SA_MNG _hbpoMng; |
|
@ -42,6 +46,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
PUB_CAN_SA_MNG pubMng, |
|
|
PUB_CAN_SA_MNG pubMng, |
|
|
BBAC_CAN_SA_MNG bbacMng, |
|
|
BBAC_CAN_SA_MNG bbacMng, |
|
|
HBPO_CAN_SA_MNG hbpoMng, |
|
|
HBPO_CAN_SA_MNG hbpoMng, |
|
|
|
|
|
INormalEfCoreRepository<PUB_PD, Guid> pdRepository, |
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> groupRepository, |
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> groupRepository, |
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> detailRepository, |
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> detailRepository, |
|
@ -49,6 +54,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository |
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository |
|
|
) |
|
|
) |
|
|
{ |
|
|
{ |
|
|
|
|
|
_pdRepository= pdRepository; |
|
|
//_canRepository = canRepository;
|
|
|
//_canRepository = canRepository;
|
|
|
_repository = repository; |
|
|
_repository = repository; |
|
|
_detailRepository = detailRepository; |
|
|
_detailRepository = detailRepository; |
|
@ -234,21 +240,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
var flag = await SetSettleState(p_entiy, p_State, false); |
|
|
//var flag = await SetSettleState(p_entiy, p_State, false);
|
|
|
|
|
|
|
|
|
if (flag == true) |
|
|
//if (flag == true)
|
|
|
{ |
|
|
//{
|
|
|
var invlist = await _repository.Where(p => p.InvGroupNum == p_entiy.InvGroupNum).ToListAsync();//选择审批时只能整组审批
|
|
|
// var invlist = await _repository.Where(p => p.InvGroupNum == p_entiy.InvGroupNum).ToListAsync();//选择审批时只能整组审批
|
|
|
foreach (var itm in invlist) |
|
|
// foreach (var itm in invlist)
|
|
|
{ |
|
|
// {
|
|
|
itm.State = p_entiy.State; |
|
|
// itm.State = p_entiy.State;
|
|
|
} |
|
|
// }
|
|
|
await _repository.BatchUpdateAsync(invlist); |
|
|
|
|
|
|
|
|
await _repository.BatchUpdateAsync(p_entiy); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -289,33 +296,112 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 客户已收票
|
|
|
/// 客户已收票
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="p_groupbillnum">发票分组号</param>
|
|
|
/// <param name="p_groupbillnum">发票分组号</param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public virtual async Task<bool> ReceivedAsync(string p_groupbillnum) |
|
|
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 inv=invList.FirstOrDefault();
|
|
|
//var inv = _repository.Where(p => p.InvGroupNum == p_groupbillnum).FirstOrDefault();
|
|
|
|
|
|
//if (inv.BusinessType == EnumBusinessType.JisBBAC)
|
|
|
//if (inv.BusinessType == EnumBusinessType.JisBBAC)
|
|
|
//{
|
|
|
//{
|
|
|
// var entity = await _bbacMng.GetMainAsync(inv.InvGroupNum);
|
|
|
// var namelist=invList.Select(p => p.InvbillNum).ToList();
|
|
|
// if (entity == null)
|
|
|
// var entityDetail = await _bbacMng.GetDetailByInbillNumAsync(namelist);//结算明细
|
|
|
|
|
|
// var adjlist=_adjRepository.Where(p => namelist.Contains(p.OldInvBillNum)).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//生产号
|
|
|
|
|
|
// ));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
//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 entityDetail = await _bbacMng.GetDetalListAsync(inv.InvGroupNum);
|
|
|
|
|
|
// var bbac = new BBAC_PD(
|
|
|
// var bbac = new BBAC_PD(
|
|
|
// guid: entity.Id,
|
|
|
// guid: entity.Id,
|
|
|
// version: entity.Version,
|
|
|
// version: entity.Version,
|
|
@ -354,7 +440,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
// await _repository.DbContext.BulkInsertAsync(bbacDetail);
|
|
|
// await _repository.DbContext.BulkInsertAsync(bbacDetail);
|
|
|
// return true;
|
|
|
// return true;
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
//}
|
|
|
//else if (inv.BusinessType == EnumBusinessType.JisHBPO)
|
|
|
//else if (inv.BusinessType == EnumBusinessType.JisHBPO)
|
|
|
//{
|
|
|
//{
|
|
@ -572,7 +658,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <param name="p_version">版本号</param>
|
|
|
/// <param name="p_version">版本号</param>
|
|
|
/// <param name="p_InvGroupNum">发票分组</param>
|
|
|
/// <param name="p_InvGroupNum">发票分组</param>
|
|
|
/// <param name="p_parentInvBillNum">原发票号</param>
|
|
|
/// <param name="p_parentInvBillNum">原发票号</param>
|
|
|
public async Task<List<string>> SecInvoice(List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) |
|
|
public async Task<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) |
|
|
|
|
|
where TDetail : SA_CAN_BASE |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
List<string> _invls = new List<string>(); |
|
|
List<string> _invls = new List<string>(); |
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
@ -634,7 +722,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
tempList.Add(group1); |
|
|
tempList.Add(group1); |
|
|
} |
|
|
} |
|
|
invoiceMap.Add(invoiceBillNum, tempList); |
|
|
invoiceMap.Add(invoiceBillNum, tempList); |
|
|
var query = from itm in groups1 |
|
|
var query = from itm in groups1 //更新分组
|
|
|
join itm1 in tempList |
|
|
join itm1 in tempList |
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID } |
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID } |
|
|
equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID } into temp |
|
|
equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID } into temp |
|
@ -654,15 +742,46 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
} |
|
|
} |
|
|
if (invoiceMap.Count > 0) |
|
|
if (invoiceMap.Count > 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
|
|
var salist = new List<TDetail>(); |
|
|
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
foreach (var group in invoiceMap) |
|
|
foreach (var group in invoiceMap) |
|
|
{ |
|
|
{ |
|
|
var key = group.Key;//发票票号
|
|
|
var key = group.Key;//发票票号
|
|
|
var ls = group.Value;//发票明细
|
|
|
var ls = group.Value;//发票明细
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = from itm in dtos |
|
|
|
|
|
join itm1 in ls |
|
|
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.BeginDate, itm1.EndDate } |
|
|
|
|
|
join itm2 in p_list on new { itm.LU, itm.SettleDate } equals new { itm2.LU, itm2.SettleDate } |
|
|
|
|
|
select itm2; |
|
|
|
|
|
foreach (var itm in query) |
|
|
|
|
|
{ |
|
|
|
|
|
itm.BillNum = key; |
|
|
|
|
|
salist.Add(itm); |
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
var query1 = from itm in dtos |
|
|
|
|
|
join itm1 in ls |
|
|
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.BeginDate, itm1.EndDate } |
|
|
|
|
|
join itm2 in p_ajdlist on new { itm.LU, itm.SettleDate } equals new { itm2.LU, itm2.SettleDate } |
|
|
|
|
|
select itm2; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var itm in query1) |
|
|
|
|
|
{ |
|
|
|
|
|
itm.InvBillNum = key; |
|
|
|
|
|
adjlist.Add(itm); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List < INVOICE_WAIT_DETAIL > _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
foreach (var detail in ls) |
|
|
foreach (var detail in ls) |
|
|
{ |
|
|
{ |
|
|
_entityDetailList.Add( |
|
|
_entityDetailList.Add( |
|
@ -730,9 +849,20 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
); |
|
|
); |
|
|
invlist.Add(invbill); |
|
|
invlist.Add(invbill); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
|
|
if(salist.Count>0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(salist); |
|
|
|
|
|
} |
|
|
|
|
|
if (adjlist.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(adjlist); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
} |
|
|
} |
|
@ -750,7 +880,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <param name="p_version">版本号</param>
|
|
|
/// <param name="p_version">版本号</param>
|
|
|
/// <param name="p_InvGroupNum">发票分组</param>
|
|
|
/// <param name="p_InvGroupNum">发票分组</param>
|
|
|
/// <param name="p_parentInvBillNum">原发票号</param>
|
|
|
/// <param name="p_parentInvBillNum">原发票号</param>
|
|
|
public async Task<List<string>> MakeInvoice(List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, bool p_first) |
|
|
public async Task<List<string>> MakeInvoice<TDetail>(List<TDetail> details,List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, bool p_first) where TDetail : SA_CAN_BASE |
|
|
{ |
|
|
{ |
|
|
List<string> _invls = new List<string>(); |
|
|
List<string> _invls = new List<string>(); |
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
@ -792,7 +922,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
{ |
|
|
{ |
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); |
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<TMEP_INV> tempList = new List<TMEP_INV>(); |
|
|
List<TMEP_INV> tempList = new List<TMEP_INV>(); |
|
|
decimal sum = group.Amt;//初始合计金额
|
|
|
decimal sum = group.Amt;//初始合计金额
|
|
|
int partCount = 0; |
|
|
int partCount = 0; |
|
@ -845,10 +974,41 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
|
|
var salist = new List<TDetail>(); |
|
|
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
foreach (var group in invoiceMap) |
|
|
foreach (var group in invoiceMap) |
|
|
{ |
|
|
{ |
|
|
var key = group.Key;//发票票号
|
|
|
var key = group.Key;//发票票号
|
|
|
var ls = group.Value;//发票明细
|
|
|
var ls = group.Value;//发票明细
|
|
|
|
|
|
|
|
|
|
|
|
//更新结算记录更新
|
|
|
|
|
|
var query = from itm in dtos |
|
|
|
|
|
join itm1 in ls |
|
|
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.BeginDate, itm1.EndDate } |
|
|
|
|
|
join itm2 in details on new { itm.LU, itm.SettleDate } equals new { itm2.LU, itm2.SettleDate } |
|
|
|
|
|
select itm2; |
|
|
|
|
|
foreach (var itm in query) |
|
|
|
|
|
{ |
|
|
|
|
|
itm.BillNum = key; |
|
|
|
|
|
|
|
|
|
|
|
salist.Add(itm); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
var query1 = from itm in dtos |
|
|
|
|
|
join itm1 in ls |
|
|
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.BeginDate, itm1.EndDate } |
|
|
|
|
|
join itm2 in p_adjlist on new { itm.LU, itm.SettleDate } equals new { itm2.LU, itm2.SettleDate } |
|
|
|
|
|
select itm2; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var itm in query1) |
|
|
|
|
|
{ |
|
|
|
|
|
itm.InvBillNum = key; |
|
|
|
|
|
adjlist.Add(itm); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
foreach (var detail in ls) |
|
|
foreach (var detail in ls) |
|
|
{ |
|
|
{ |
|
@ -920,6 +1080,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
//await _repository.DbContext.BulkInsertAsync(groupList);
|
|
|
//await _repository.DbContext.BulkInsertAsync(groupList);
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
|
|
if (salist.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(salist); |
|
|
|
|
|
} |
|
|
|
|
|
if (adjlist.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(adjlist); |
|
|
|
|
|
} |
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
} |
|
|
} |
|
@ -942,7 +1110,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <param name="p_parentInvBillNum"></param>
|
|
|
/// <param name="p_parentInvBillNum"></param>
|
|
|
/// <param name="businessType"></param>
|
|
|
/// <param name="businessType"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public async Task<List<string>> FirstInvoice(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 async Task<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>(); |
|
|
List<string> _invls = new List<string>(); |
|
|
var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); |
|
|
var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); |
|
@ -998,14 +1167,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
|
|
var salist = new List<TDetail>(); |
|
|
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
|
|
|
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
{ |
|
|
{ |
|
|
var key = itm.Key;//发票票号
|
|
|
var key = itm.Key;//发票票号
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
//if(businessType==EnumBusinessType.JisBBAC)
|
|
|
var invdetails = p_list.Where(p => ls.Contains(p.GroupNum)).ToList(); |
|
|
//{
|
|
|
foreach (var detail in invdetails) |
|
|
|
|
|
{ |
|
|
|
|
|
detail.BillNum = key; |
|
|
|
|
|
salist.Add(detail); |
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(p_parentInvBillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
var adjdetails = p_adjlist.Where(p => ls.Contains(p.GroupNum)).ToList(); |
|
|
|
|
|
foreach (var detail in adjdetails) |
|
|
|
|
|
{ |
|
|
|
|
|
detail.InvBillNum = key; |
|
|
|
|
|
adjdetails.Add(detail); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }) |
|
|
var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }) |
|
|
.Select(itm => new |
|
|
.Select(itm => new |
|
|
{ |
|
|
{ |
|
@ -1106,10 +1290,21 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
|
|
|
|
|
|
|
|
if(salist.Count>0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(salist); |
|
|
|
|
|
} |
|
|
|
|
|
if (adjlist.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkUpdateAsync(adjlist); |
|
|
|
|
|
} |
|
|
if (notDetialList.Count > 0) |
|
|
if (notDetialList.Count > 0) |
|
|
{ |
|
|
{ |
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -1124,7 +1319,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <param name="p_version"></param>
|
|
|
/// <param name="p_version"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
public async Task<bool> ReissueFirstInvoice(List<TEMP_CAN_SA_DETAIL> dtos, List<PUB_ADJ_DETAIL> p_adjlist, string p_OldInvBillNum, int p_version) |
|
|
public async Task<bool> ReissueFirstInvoice<TDetail>(List<TDetail> p_list,List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, string p_OldInvBillNum, int p_version) |
|
|
|
|
|
where TDetail:SA_CAN_BASE |
|
|
{ |
|
|
{ |
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
{ |
|
|
{ |
|
@ -1143,11 +1339,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
List<string> invlist = new List<string>(); |
|
|
List<string> invlist = new List<string>(); |
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
{ |
|
|
{ |
|
|
invlist = await MakeInvoice(dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); |
|
|
invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
invlist = await FirstInvoice(dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
|
|
|
invlist = await FirstInvoice(p_list,p_adjlist,dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (invlist.Count == 0) |
|
|
if (invlist.Count == 0) |
|
@ -1175,7 +1371,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <param name="p_version"></param>
|
|
|
/// <param name="p_version"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
public async Task<bool> ReissueSecInvoice(List<TEMP_CAN_SA_DETAIL> dtos, List<PUB_ADJ_DETAIL> p_adjlist, string p_OldInvBillNum, int p_version) |
|
|
public async Task<bool> ReissueSecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, string p_OldInvBillNum, int p_version) |
|
|
|
|
|
where TDetail : SA_CAN_BASE |
|
|
{ |
|
|
{ |
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
{ |
|
|
{ |
|
@ -1194,14 +1391,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
List<string> invlist = new List<string>(); |
|
|
List<string> invlist = new List<string>(); |
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
{ |
|
|
{ |
|
|
invlist = await MakeInvoice(dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); |
|
|
invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
invlist = await SecInvoice(dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
invlist = await SecInvoice(p_list,p_adjlist,dtos,p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (invlist.Count == 0) |
|
|
if (invlist.Count == 0) |
|
|
{ |
|
|
{ |
|
|
return false; |
|
|
return false; |
|
@ -1209,10 +1404,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
|
_repository.DbContext.BulkUpdate(new List<INVOICE_GRP> { inv }); |
|
|
_repository.DbContext.BulkUpdate(new List<INVOICE_GRP> { inv }); |
|
|
|
|
|
|
|
|
foreach (var adj in p_adjlist) |
|
|
//foreach (var adj in p_adjlist)
|
|
|
{ |
|
|
//{
|
|
|
adj.InvBillNum = string.Join(",", invlist); |
|
|
// adj.InvBillNum = string.Join(",", invlist);
|
|
|
} |
|
|
//}
|
|
|
_repository.DbContext.BulkUpdate(p_adjlist); |
|
|
_repository.DbContext.BulkUpdate(p_adjlist); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|