|
|
@ -17,6 +17,7 @@ using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Auditing; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Domain.Services; |
|
|
@ -415,7 +416,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
} |
|
|
|
newlist = p_invs.Where(p => !oldlist.Contains(p)).ToList();//不存在扣减记录的发票号
|
|
|
|
List<BBAC_CAN_SA_DETAIL> entityList = new List<BBAC_CAN_SA_DETAIL>();//结算明细
|
|
|
|
var namelist = invList.Select(p => p.InvbillNum).ToList(); |
|
|
|
var namelist = invList.Select(p => p.InvbillNum).ToList(); |
|
|
|
if (oldlist.Count > 0) |
|
|
|
{ |
|
|
|
var involdList= invList.Where(p => oldinvs.Contains(p.ParentInvbillNum)).ToList(); |
|
|
@ -533,7 +534,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (inv.BusinessType == EnumBusinessType.JisHBPO) |
|
|
|
{ |
|
|
|
var pdlist = _pdhbpoRepository.Where(p => p_invs.Contains(p.BillNum)).ToList();//包含发票号的代扣减单
|
|
|
@ -889,6 +889,39 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public INVOICE_GRP FindAncestor(List<INVOICE_GRP> p_list,INVOICE_GRP currentNode, string invbillNum)
|
|
|
|
//{
|
|
|
|
// if (currentNode == null || currentNode.InvbillNum == invbillNum)
|
|
|
|
// {
|
|
|
|
// return currentNode;
|
|
|
|
// }
|
|
|
|
// var parentNode=p_list.Where(p => p.InvbillNum == currentNode.InvbillNum).FirstOrDefault();
|
|
|
|
|
|
|
|
// return FindAncestor(p_list, parentNode, invbillNum);
|
|
|
|
//}
|
|
|
|
//public virtual async Task<bool> IsSplittingMultipleInvoices(List<string> invs, string p_invbillnum)
|
|
|
|
//{
|
|
|
|
// _repository.Where(p=>)
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 返回到财务审核状态
|
|
|
|
/// </summary>
|
|
|
@ -1049,7 +1082,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
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 } |
|
|
|
join itm2 in p_list on new { itm.PartCode, itm.SettleDate } equals new { itm2.PartCode, itm2.SettleDate } |
|
|
|
join itm2 in p_list on new { itm.PartCode,itm.PN, itm.SettleDate } equals new { itm2.PartCode,itm2.PN, itm2.SettleDate } |
|
|
|
select itm2; |
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
@ -1062,7 +1095,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
var query1 = 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 } |
|
|
|
join itm2 in p_ajdlist on new { itm.PartCode, itm.SettleDate } equals new { itm2.PartCode, itm2.SettleDate } |
|
|
|
join itm2 in p_ajdlist on new { itm.PartCode, itm.PN, itm.SettleDate } equals new { itm2.PartCode, itm2.PN, itm2.SettleDate } |
|
|
|
select itm2; |
|
|
|
|
|
|
|
foreach (var itm in query1) |
|
|
@ -1167,11 +1200,217 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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>(); |
|
|
|
var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); |
|
|
|
Dictionary<string, decimal> dic = new Dictionary<string, decimal>();//原本
|
|
|
|
Dictionary<string, decimal> copyDic = new Dictionary<string, decimal>();//变换数组副本
|
|
|
|
foreach (var itm in _query.ToList()) |
|
|
|
{ |
|
|
|
dic.Add(itm.GroupNum, itm.Amt); |
|
|
|
copyDic.Add(itm.GroupNum, itm.Amt); |
|
|
|
} |
|
|
|
Dictionary<string, List<string>> invoiceMap = new Dictionary<string, List<string>>(); |
|
|
|
foreach (var itm in dic) |
|
|
|
{ |
|
|
|
string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); |
|
|
|
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
List<string> List = new List<string>(); |
|
|
|
decimal sum = itm.Value;//初始分组合计金额
|
|
|
|
// List<string> luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类
|
|
|
|
if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组
|
|
|
|
{ |
|
|
|
foreach (var _itm1 in copyDic) |
|
|
|
{ |
|
|
|
if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化
|
|
|
|
{ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
//var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类
|
|
|
|
//luList.AddRange(grouplist);
|
|
|
|
//luList = luList.Distinct().ToList();
|
|
|
|
//if (luList.Count > 20)//累加零件不超过20种
|
|
|
|
//{
|
|
|
|
// continue;
|
|
|
|
//}
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系
|
|
|
|
} |
|
|
|
invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系
|
|
|
|
foreach (var rem in invoiceGroupNumList)//移除
|
|
|
|
{ |
|
|
|
copyDic.Remove(rem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (invoiceMap.Keys.Count > 0) |
|
|
|
{ |
|
|
|
|
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
var salist = new List<TDetail>(); |
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
|
|
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
|
{ |
|
|
|
var key = itm.Key;//发票票号
|
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
|
//反向查找结算数据
|
|
|
|
var invdetails = p_list.Where(p => ls.Contains(p.GroupNum)).ToList(); |
|
|
|
foreach (var detail in invdetails) |
|
|
|
{ |
|
|
|
detail.InvbillNum = 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.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }) |
|
|
|
.Select(itm => new |
|
|
|
{ |
|
|
|
PartCode = itm.Key.PartCode, |
|
|
|
InvGroupNum = itm.Key.InvGroupNum, |
|
|
|
LU = itm.Key.PartCode, |
|
|
|
ContactDocID = itm.Key.ContractDocID, |
|
|
|
Price = itm.Key.Price, |
|
|
|
Amt = 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 = Math.Round(detailDtos.Sum(k => k.Amt), 2); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in ls) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: groupnum, |
|
|
|
amt: 0, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
if (mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
} |
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
foreach (var detail in detailDtos) |
|
|
|
{ |
|
|
|
_entityDetailList.Add( |
|
|
|
new INVOICE_WAIT_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
lU: detail.LU, |
|
|
|
qty: detail.Qty, |
|
|
|
bussiessType: businessType, |
|
|
|
amt: detail.Amt, |
|
|
|
pRICE: detail.Price, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
beginDate: detail.BeginDate, |
|
|
|
endDate: detail.EndDate, |
|
|
|
partcode: detail.PartCode |
|
|
|
)); |
|
|
|
} |
|
|
|
if (_entityDetailList.Count > 0) |
|
|
|
{ |
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
} |
|
|
|
var innotls = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
if (p_notlist != null && p_notlist.Count > 0) |
|
|
|
{ |
|
|
|
var notls = p_notlist.GroupBy(p => new { p.GroupNum, p.LU }).Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty) }); |
|
|
|
foreach (var nitm in notls) |
|
|
|
{ |
|
|
|
innotls.Add(new INVOICE_NOT_SETTLE( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: nitm.GroupNum, |
|
|
|
lU: string.Empty, |
|
|
|
lU1: nitm.LU, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
qty: nitm.Qty |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
} |
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
(guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: key, |
|
|
|
amt: amt, |
|
|
|
taxAmt: txtAmt, |
|
|
|
fileName: string.Empty, |
|
|
|
businessType: businessType, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常, |
|
|
|
tax: 0, |
|
|
|
parent: string.Empty, |
|
|
|
preTaxDiff: 0, |
|
|
|
taxDiff: 0, |
|
|
|
clientCode: string.Empty, |
|
|
|
realAmt: 0 |
|
|
|
); |
|
|
|
invlist.Add(invbill); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
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) |
|
|
|
{ |
|
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
|
} |
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// hbpojis,备件
|
|
|
|
/// hbpojis
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dtos">可结算明细列表</param>
|
|
|
|
/// <param name="p_version">版本号</param>
|
|
|
@ -1287,7 +1526,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
var query = from itm in dtos |
|
|
|
join itm1 in ls |
|
|
|
on new { LU=itm.PartCode, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.BeginDate, itm1.EndDate } |
|
|
|
join itm2 in details on new { itm.LU,itm.PartCode, itm.SettleDate } equals new { itm2.LU,itm2.PartCode,itm2.SettleDate } |
|
|
|
join itm2 in details on new { itm.LU,itm.PartCode,itm.PN, itm.SettleDate } equals new { itm2.LU,itm2.PartCode,itm2.PN,itm2.SettleDate } |
|
|
|
select itm2; |
|
|
|
foreach (var itm in query) |
|
|
|
{ |
|
|
@ -1411,7 +1650,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
/// <param name="p_parentInvBillNum"></param>
|
|
|
|
/// <param name="businessType"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
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) |
|
|
|
public async Task<List<string>> JITInvoice<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,bool p_first) |
|
|
|
where TDetail:SA_CAN_BASE |
|
|
|
{ |
|
|
|
List<string> _invls = new List<string>(); |
|
|
@ -1426,7 +1665,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
Dictionary<string, List<string>> invoiceMap = new Dictionary<string, List<string>>(); |
|
|
|
foreach (var itm in dic) |
|
|
|
{ |
|
|
|
string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); |
|
|
|
string invoiceBillNum = string.Empty; |
|
|
|
if (p_first == true) |
|
|
|
{ |
|
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); |
|
|
|
} |
|
|
|
|
|
|
|
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
List<string> List = new List<string>(); |
|
|
|
decimal sum = itm.Value;//初始分组合计金额
|
|
|
@ -1644,15 +1892,53 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
inv.InvoiceState = InvoiceBillState.报废; |
|
|
|
|
|
|
|
List<string> invlist = new List<string>(); |
|
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
|
{ |
|
|
|
invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
switch (inv.BusinessType) |
|
|
|
{ |
|
|
|
invlist = await FirstInvoice(p_list,p_adjlist,dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
|
|
|
|
case EnumBusinessType.MaiDanJianHBPO: |
|
|
|
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); |
|
|
|
break; |
|
|
|
case EnumBusinessType.MaiDanJianBBAC: |
|
|
|
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); |
|
|
|
break; |
|
|
|
case EnumBusinessType.ZhiGongJianBBAC: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.ZhiGongJianHBPO: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.BeiJian: |
|
|
|
invlist = await BJInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum,inv.InvbillNum, inv.BusinessType, true); |
|
|
|
break; |
|
|
|
case EnumBusinessType.JisBBAC: |
|
|
|
invlist = await FirstInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.JisHBPO: |
|
|
|
invlist = await FirstInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.YinDuJian: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO)
|
|
|
|
//{
|
|
|
|
// invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true);
|
|
|
|
//}
|
|
|
|
//if (inv.BusinessType == EnumBusinessType.BeiJian)
|
|
|
|
//{
|
|
|
|
// invlist = await BJInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true);
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// 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) |
|
|
|
{ |
|
|
|
return false; |
|
|
@ -1670,6 +1956,258 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<List<string>> BJInvoice<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,bool p_first=true) |
|
|
|
where TDetail : SA_CAN_BASE |
|
|
|
{ |
|
|
|
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) }); |
|
|
|
Dictionary<string, decimal> dic = new Dictionary<string, decimal>();//原本
|
|
|
|
Dictionary<string, decimal> copyDic = new Dictionary<string, decimal>();//变换数组副本
|
|
|
|
foreach (var itm in _query.ToList()) |
|
|
|
{ |
|
|
|
dic.Add(itm.GroupNum, itm.Amt); |
|
|
|
copyDic.Add(itm.GroupNum, itm.Amt); |
|
|
|
} |
|
|
|
Dictionary<string, List<string>> invoiceMap = new Dictionary<string, List<string>>(); |
|
|
|
foreach (var itm in dic) |
|
|
|
{ |
|
|
|
string invoiceBillNum = string.Empty; |
|
|
|
if (p_first == true) |
|
|
|
{ |
|
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); |
|
|
|
} |
|
|
|
|
|
|
|
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
List<string> List = new List<string>(); |
|
|
|
decimal sum = itm.Value;//初始分组合计金额
|
|
|
|
// List<string> luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类
|
|
|
|
if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组
|
|
|
|
{ |
|
|
|
foreach (var _itm1 in copyDic) |
|
|
|
{ |
|
|
|
if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化
|
|
|
|
{ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
//var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类
|
|
|
|
//luList.AddRange(grouplist);
|
|
|
|
//luList = luList.Distinct().ToList();
|
|
|
|
//if (luList.Count > 20)//累加零件不超过20种
|
|
|
|
//{
|
|
|
|
// continue;
|
|
|
|
//}
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系
|
|
|
|
} |
|
|
|
invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系
|
|
|
|
foreach (var rem in invoiceGroupNumList)//移除
|
|
|
|
{ |
|
|
|
copyDic.Remove(rem); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (invoiceMap.Keys.Count > 0) |
|
|
|
{ |
|
|
|
|
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
var invlist = new List<INVOICE_GRP>(); |
|
|
|
var salist = new List<TDetail>(); |
|
|
|
var adjlist = new List<PUB_ADJ_DETAIL>(); |
|
|
|
|
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
|
{ |
|
|
|
var key = itm.Key;//发票票号
|
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
|
//反向查找结算数据
|
|
|
|
var invdetails = p_list.Where(p => ls.Contains(p.GroupNum)).ToList(); |
|
|
|
foreach (var detail in invdetails) |
|
|
|
{ |
|
|
|
detail.InvbillNum = 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.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }) |
|
|
|
.Select(itm => new |
|
|
|
{ |
|
|
|
PartCode = itm.Key.PartCode, |
|
|
|
InvGroupNum = itm.Key.InvGroupNum, |
|
|
|
LU = itm.Key.PartCode, |
|
|
|
ContactDocID = itm.Key.ContractDocID, |
|
|
|
Price = itm.Key.Price, |
|
|
|
Amt = 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(); |
|
|
|
|
|
|
|
var query = from inv1 in invdetails |
|
|
|
join dto1 in dtos on |
|
|
|
new { inv1.LU, inv1.PN } equals new { dto1.LU, dto1.PN } |
|
|
|
select new |
|
|
|
{ |
|
|
|
PartCode = inv1.PartCode, |
|
|
|
InvGroupNum = inv1.InvGroupNum, |
|
|
|
LU = inv1.LU, |
|
|
|
GroupNum=inv1.GroupNum, |
|
|
|
Price = inv1.Price, |
|
|
|
Amt = dto1.Amt, |
|
|
|
Qty = dto1.Qty, |
|
|
|
BeginDate = dto1.BeginDate, |
|
|
|
EndDate = dto1.EndDate, |
|
|
|
DeliveryNumber = inv1.GetProperty("DeliveryNumber", ""),//交货号
|
|
|
|
InvoiceNumber = inv1.GetProperty("InvoiceNumber", ""),//发票号
|
|
|
|
VendorCode = inv1.GetProperty("VendorCode", ""),//供应商代码
|
|
|
|
VendorName = inv1.GetProperty("VendorName", ""),//供应商名称
|
|
|
|
PurchaseOrderNumber = inv1.GetProperty("PurchaseOrderNumber", ""),//采购订单号
|
|
|
|
DeliveryIndexNumber = inv1.GetProperty("DeliveryIndexNumber", ""),//交付索引号
|
|
|
|
PartName = inv1.GetProperty("PartName", ""),//零件名称
|
|
|
|
}; |
|
|
|
|
|
|
|
decimal amt = detailDtos.Sum(k => k.Amt); |
|
|
|
decimal txtAmt = Math.Round(detailDtos.Sum(k => k.Amt), 2); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in ls) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: groupnum, |
|
|
|
amt: 0, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
if (mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
} |
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
foreach (var detail in query.ToList()) |
|
|
|
{ |
|
|
|
|
|
|
|
var entity = new INVOICE_WAIT_DETAIL( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
lU: detail.LU, |
|
|
|
qty: detail.Qty, |
|
|
|
bussiessType: businessType, |
|
|
|
amt: detail.Amt, |
|
|
|
pRICE: detail.Price, |
|
|
|
extend1: detail.GroupNum, |
|
|
|
extend2: string.Empty, |
|
|
|
beginDate: detail.BeginDate, |
|
|
|
endDate: detail.EndDate, |
|
|
|
partcode: detail.PartCode); |
|
|
|
entity.SetProperty("DeliveryNumber", detail.DeliveryIndexNumber);//交货号
|
|
|
|
entity.SetProperty("VendorCode", detail.VendorCode);//供应商代码
|
|
|
|
entity.SetProperty("VendorName", detail.VendorName);//供应商名称
|
|
|
|
entity.SetProperty("PurchaseOrderNumber", "");//采购订单号
|
|
|
|
entity.SetProperty("DeliveryIndexNumber", "");//交付索引号
|
|
|
|
entity.SetProperty("PartName", "");//零件名称
|
|
|
|
|
|
|
|
_entityDetailList.Add( entity |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
if (_entityDetailList.Count > 0) |
|
|
|
{ |
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
} |
|
|
|
//var innotls = new List<INVOICE_NOT_SETTLE>();
|
|
|
|
//if (p_notlist != null && p_notlist.Count > 0)
|
|
|
|
//{
|
|
|
|
// var notls = p_notlist.GroupBy(p => new { p.GroupNum, p.LU }).Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty) });
|
|
|
|
// foreach (var nitm in notls)
|
|
|
|
// {
|
|
|
|
// innotls.Add(new INVOICE_NOT_SETTLE(
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// version: p_version,
|
|
|
|
// invGroupNum: p_InvGroupNum,
|
|
|
|
// settleGroupNum: nitm.GroupNum,
|
|
|
|
// lU: string.Empty,
|
|
|
|
// lU1: nitm.LU,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty,
|
|
|
|
// qty: nitm.Qty
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// if (innotls.Count > 0)
|
|
|
|
// {
|
|
|
|
// notDetialList.AddRange(innotls);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
(guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: key, |
|
|
|
amt: amt, |
|
|
|
taxAmt: txtAmt, |
|
|
|
fileName: string.Empty, |
|
|
|
businessType: businessType, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常, |
|
|
|
tax: 0, |
|
|
|
parent: string.Empty, |
|
|
|
preTaxDiff: 0, |
|
|
|
taxDiff: 0, |
|
|
|
clientCode: string.Empty, |
|
|
|
realAmt: 0 |
|
|
|
); |
|
|
|
invlist.Add(invbill); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
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) |
|
|
|
{ |
|
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
|
} |
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 重开二次开票
|
|
|
|
/// </summary>
|
|
|
@ -1696,14 +2234,36 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
inv.InvoiceState = InvoiceBillState.报废; |
|
|
|
|
|
|
|
List<string> invlist = new List<string>(); |
|
|
|
if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) |
|
|
|
{ |
|
|
|
invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
switch (inv.BusinessType) |
|
|
|
{ |
|
|
|
invlist = await SecInvoice(p_list,p_adjlist,dtos,p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
|
case EnumBusinessType.MaiDanJianHBPO: |
|
|
|
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); |
|
|
|
break; |
|
|
|
case EnumBusinessType.MaiDanJianBBAC: |
|
|
|
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); |
|
|
|
break; |
|
|
|
case EnumBusinessType.ZhiGongJianBBAC: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType,false);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.ZhiGongJianHBPO: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, false);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
case EnumBusinessType.BeiJian: |
|
|
|
invlist = await BJInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, false); |
|
|
|
break; |
|
|
|
case EnumBusinessType.JisBBAC: |
|
|
|
invlist = await SecInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
|
break; |
|
|
|
case EnumBusinessType.JisHBPO: |
|
|
|
invlist = await SecInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
|
break; |
|
|
|
case EnumBusinessType.YinDuJian: |
|
|
|
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, false);//重开可以变多张发票
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (invlist.Count == 0) |
|
|
|
{ |
|
|
|
return false; |
|
|
|