|
|
@ -1038,6 +1038,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
{ |
|
|
|
smalllist.Add(itm); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
@ -1600,13 +1601,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TDetail"></typeparam>
|
|
|
|
/// <param name="p_list">所有实体</param>
|
|
|
|
/// <param name="p_adjlist"></param>
|
|
|
|
/// <param name="dtos">有价格dto</param>
|
|
|
|
/// <param name="p_notlist"></param>
|
|
|
|
/// <param name="p_version"></param>
|
|
|
|
/// <param name="p_InvGroupNum"></param>
|
|
|
|
/// <param name="p_parentInvBillNum"></param>
|
|
|
|
/// <param name="businessType"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[UnitOfWork(false)] |
|
|
|
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>> BBACJitFirstInvoice<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) }); |
|
|
|
var _query = dtos.GroupBy(p => new { p.PartCode }).Select(p => new { GroupNum = p.Key.PartCode, 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()) |
|
|
@ -1634,7 +1648,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
@ -1652,9 +1665,294 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
{ |
|
|
|
int count = 1; |
|
|
|
|
|
|
|
foreach (var _itm1 in copyDic) |
|
|
|
{ |
|
|
|
if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化
|
|
|
|
{ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (count > 14) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系
|
|
|
|
count++; |
|
|
|
|
|
|
|
} |
|
|
|
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>(); |
|
|
|
List<string> lsby = new List<string>(); |
|
|
|
var grouplist = p_list.Select(p => p.PartCode).Distinct().ToList();//可结分组
|
|
|
|
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)//分组影响和
|
|
|
|
{ |
|
|
|
var key = itm.Key;//发票票号
|
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
|
//反向查找结算数据
|
|
|
|
var invdetails = p_list.Where(p => ls.Contains(p.PartCode)).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; |
|
|
|
adjlist.Add(detail); |
|
|
|
} |
|
|
|
} |
|
|
|
var detailDtos = dtos.Where(p => ls.Contains(p.PartCode)).GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细
|
|
|
|
.Select(itm => new |
|
|
|
{ |
|
|
|
PartCode = itm.Key.PartCode, |
|
|
|
InvGroupNum = itm.Key.InvGroupNum, |
|
|
|
LU = itm.Key.LU, |
|
|
|
ContactDocID = itm.Key.ContractDocID, |
|
|
|
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),//税后进
|
|
|
|
|
|
|
|
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);//税额
|
|
|
|
|
|
|
|
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: detail.ContactDocID, |
|
|
|
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>(); |
|
|
|
var sq = dtos.Where(p => itm.Value.Contains(p.PartCode)).GroupBy(p => new { p.LU, p.GroupNum }) |
|
|
|
.Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = itm.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: itm.Key |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
if (p_notlist != null && p_notlist.Count > 0) |
|
|
|
{ |
|
|
|
var innotls1 = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var groupnum = itm.Value; |
|
|
|
if (count == i)//最后一张发票追加
|
|
|
|
{ |
|
|
|
groupnum.AddRange(nolist);//追加完全不可结
|
|
|
|
} |
|
|
|
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), InvBillNum = itm.Key }); |
|
|
|
foreach (var nitm in notls) |
|
|
|
{ |
|
|
|
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: itm.Key |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls1); |
|
|
|
} |
|
|
|
} |
|
|
|
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.13m, |
|
|
|
parent: !string.IsNullOrEmpty(p_parentInvBillNum)?p_parentInvBillNum:string.Empty, |
|
|
|
preTaxDiff: 0, |
|
|
|
taxDiff: 0, |
|
|
|
clientCode: string.Empty, |
|
|
|
realAmt: realAmt |
|
|
|
|
|
|
|
); |
|
|
|
string site = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).FirstOrDefault().Site; |
|
|
|
string clientCode = string.Empty; |
|
|
|
switch (site) |
|
|
|
{ |
|
|
|
case "1040": |
|
|
|
clientCode = "C001"; |
|
|
|
break; |
|
|
|
case "1046": |
|
|
|
clientCode = "C171"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
clientCode = "C004"; |
|
|
|
break; |
|
|
|
} |
|
|
|
invbill.ClientCode = clientCode; |
|
|
|
invbill.Site = dtos.FirstOrDefault().Site; |
|
|
|
invbill.CreationTime =DateTime.MinValue; |
|
|
|
invbill.LastModificationTime = DateTime.Now; |
|
|
|
invlist.Add(invbill); |
|
|
|
i++; |
|
|
|
} |
|
|
|
//using (var transaction = _repository.DbContext.Database.BeginTransaction())
|
|
|
|
//{
|
|
|
|
// try
|
|
|
|
// {
|
|
|
|
// 执行批量数据操作
|
|
|
|
if (salist.Count > 0) |
|
|
|
{ |
|
|
|
await _repository.DbContext.BulkUpdateAsync(salist).ConfigureAwait(false); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist).ConfigureAwait(false); |
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList).ConfigureAwait(false); |
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList).ConfigureAwait(false); |
|
|
|
if (adjlist.Count > 0) |
|
|
|
{ |
|
|
|
await _repository.DbContext.BulkInsertAsync(adjlist).ConfigureAwait(false); |
|
|
|
} |
|
|
|
if (notDetialList.Count > 0) |
|
|
|
{ |
|
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList).ConfigureAwait(false); |
|
|
|
} |
|
|
|
// 提交事务
|
|
|
|
// transaction.Commit();
|
|
|
|
// }
|
|
|
|
// catch (Exception)
|
|
|
|
// {
|
|
|
|
// // 回滚事务
|
|
|
|
// transaction.Rollback();
|
|
|
|
// throw;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
} |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[UnitOfWork(false)] |
|
|
|
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>>(); |
|
|
|
var first = p_list.FirstOrDefault(); |
|
|
|
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)//是否存在分组
|
|
|
|
{ |
|
|
|
if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO || first.BusinessType == EnumBusinessType.ZhiGongJianBBAC) |
|
|
|
{ |
|
|
|
foreach (var _itm1 in copyDic) |
|
|
|
{ |
|
|
|
if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化
|
|
|
@ -1663,14 +1961,36 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系
|
|
|
|
} |
|
|
|
invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系
|
|
|
|
foreach (var rem in invoiceGroupNumList)//移除
|
|
|
|
{ |
|
|
|
copyDic.Remove(rem); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
int count = 1; |
|
|
|
|
|
|
|
foreach (var _itm1 in copyDic) |
|
|
|
{ |
|
|
|
if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化
|
|
|
|
{ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (count > 14) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
@ -1853,7 +2173,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常, |
|
|
|
tax: 0.13m, |
|
|
|
parent: !string.IsNullOrEmpty(p_parentInvBillNum)?p_parentInvBillNum:string.Empty, |
|
|
|
parent: !string.IsNullOrEmpty(p_parentInvBillNum) ? p_parentInvBillNum : string.Empty, |
|
|
|
preTaxDiff: 0, |
|
|
|
taxDiff: 0, |
|
|
|
clientCode: string.Empty, |
|
|
@ -1876,7 +2196,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
} |
|
|
|
invbill.ClientCode = clientCode; |
|
|
|
invbill.Site = dtos.FirstOrDefault().Site; |
|
|
|
invbill.CreationTime =DateTime.MinValue; |
|
|
|
invbill.CreationTime = DateTime.MinValue; |
|
|
|
invbill.LastModificationTime = DateTime.Now; |
|
|
|
invlist.Add(invbill); |
|
|
|
i++; |
|
|
@ -1916,6 +2236,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// hbpojis
|
|
|
|
/// </summary>
|
|
|
|