|
@ -1,6 +1,7 @@ |
|
|
using EFCore.BulkExtensions; |
|
|
using EFCore.BulkExtensions; |
|
|
using Hangfire; |
|
|
using Hangfire; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using NPOI.SS.Formula.Functions; |
|
|
using NPOI.SS.Formula.Functions; |
|
|
using SettleAccount.Bases; |
|
|
using SettleAccount.Bases; |
|
@ -14,6 +15,9 @@ using Volo.Abp; |
|
|
using Volo.Abp.Auditing; |
|
|
using Volo.Abp.Auditing; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Domain.Repositories; |
|
|
using Volo.Abp.Domain.Services; |
|
|
using Volo.Abp.Domain.Services; |
|
|
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Temp; |
|
|
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
@ -36,9 +40,6 @@ 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<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, |
|
@ -133,12 +134,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
public virtual async Task<bool> SetForwardState(INVOICE_GRP p_entiy, SettleBillState p_State) |
|
|
public virtual async Task<bool> SetForwardState(INVOICE_GRP p_entiy, SettleBillState p_State) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (p_entiy.InvoiceState == InvoiceBillState.报废) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989", "当前发票已报废不能进行操作"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var state = p_State; |
|
|
var state = p_State; |
|
|
switch (p_State) |
|
|
switch (p_State) |
|
|
{ |
|
|
{ |
|
|
case SettleBillState.财务已审核: |
|
|
case SettleBillState.财务已审核: |
|
|
if (p_entiy.State == SettleBillState.商务已审核) |
|
|
if (p_entiy.State == SettleBillState.商务已审核) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
p_entiy.State = state; |
|
|
p_entiy.State = state; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
@ -167,8 +174,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var flag = await SetSettleState(p_entiy, p_State, true); |
|
|
var flag = await SetSettleState(p_entiy, p_State, true); |
|
|
if (flag == true) |
|
|
if (flag == true) |
|
|
{ |
|
|
{ |
|
@ -242,9 +247,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="p_billNum"></param>
|
|
|
/// <param name="p_billNum"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public virtual async Task<INVOICE_GRP> GetMainAsync(string p_groupbillNum) |
|
|
public virtual async Task<INVOICE_GRP> GetMainAsync(string p_invbillNum) |
|
|
{ |
|
|
{ |
|
|
return await _repository.Where(p => p.InvbillNum == p_groupbillNum).FirstOrDefaultAsync(); |
|
|
return await _repository.Where(p => p.InvbillNum == p_invbillNum).FirstOrDefaultAsync(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -431,12 +436,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public virtual async Task<bool> Reject(string groupbillNum) |
|
|
public virtual async Task<bool> Reject(string groupbillNum) |
|
|
{ |
|
|
{ |
|
|
|
|
|
var ls = await _repository.Where(p => p.InvGroupNum == groupbillNum).ToListAsync(); |
|
|
var _ls=await _repository.Where(p => p.InvGroupNum == groupbillNum).ToListAsync(); |
|
|
if (ls != null && ls.Count > 0) |
|
|
|
|
|
|
|
|
if (_ls != null && _ls.Count > 0) |
|
|
|
|
|
{ |
|
|
{ |
|
|
foreach (var p_entity in _ls) |
|
|
var first = ls.FirstOrDefault(); |
|
|
|
|
|
if(first.State==SettleBillState.客户已收票 || first.State== SettleBillState.已扣减) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989",$"发票分组{groupbillNum}客户已经是客户已收票或已扣减状态不能退回"); |
|
|
|
|
|
} |
|
|
|
|
|
foreach (var p_entity in ls) |
|
|
{ |
|
|
{ |
|
|
if (p_entity.State == SettleBillState.财务已审核 |
|
|
if (p_entity.State == SettleBillState.财务已审核 |
|
|
|| p_entity.State == SettleBillState.已开票 || p_entity.State == SettleBillState.商务已审核) |
|
|
|| p_entity.State == SettleBillState.已开票 || p_entity.State == SettleBillState.商务已审核) |
|
@ -445,26 +453,30 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
var groupList = _groupRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
var groupList = _groupRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
var notList = _notRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
var notList = _notRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
var detailList = _detailRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
var detailList = _detailRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList(); |
|
|
//var canList = _canRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
|
|
//foreach (var itm in canList)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// itm.State = SettleBillState.未结状态;
|
|
|
|
|
|
//}
|
|
|
|
|
|
await _repository.DbContext.BulkDeleteAsync(entList); |
|
|
await _repository.DbContext.BulkDeleteAsync(entList); |
|
|
await _repository.DbContext.BulkDeleteAsync(groupList); |
|
|
await _repository.DbContext.BulkDeleteAsync(groupList); |
|
|
await _repository.DbContext.BulkDeleteAsync(notList); |
|
|
await _repository.DbContext.BulkDeleteAsync(notList); |
|
|
await _repository.DbContext.BulkDeleteAsync(detailList); |
|
|
await _repository.DbContext.BulkDeleteAsync(detailList); |
|
|
//await _repository.DbContext.BulkUpdateAsync(canList);
|
|
|
if (first.BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
|
|
{ |
|
|
|
|
|
await _bbacMng.SetNewState(groupbillNum); |
|
|
} |
|
|
} |
|
|
if (p_entity.State == SettleBillState.已扣减) |
|
|
else if (first.BusinessType == EnumBusinessType.JisHBPO) |
|
|
{ |
|
|
{ |
|
|
|
|
|
await _hbpoMng.SetNewState(groupbillNum); |
|
|
} |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
await _pubMng.SetNewState(groupbillNum); |
|
|
|
|
|
} |
|
|
|
|
|
//await _repository.DbContext.BulkUpdateAsync(canList);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989",$"查询不到发票分组号为{groupbillNum}发票分组"); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -533,11 +545,421 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// hbpo、jit、备件等
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dtos">可结算明细列表</param>
|
|
|
|
|
|
/// <param name="p_version">版本号</param>
|
|
|
|
|
|
/// <param name="p_InvGroupNum">发票分组</param>
|
|
|
|
|
|
/// <param name="p_parentInvBillNum">原发票号</param>
|
|
|
|
|
|
public async Task<bool> SecInvoice(List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
|
|
|
|
{ |
|
|
|
|
|
LU = p.Key.LU, |
|
|
|
|
|
Amt = p.Sum(itm => itm.Amt), |
|
|
|
|
|
Qty = p.Sum(itm => itm.Qty), |
|
|
|
|
|
ContractDocID = p.Key.ContractDocID, |
|
|
|
|
|
Price = p.Key.Price, |
|
|
|
|
|
BeginDate = p.Key.BeginDate, |
|
|
|
|
|
EndDate = p.Key.EndDate |
|
|
|
|
|
|
|
|
|
|
|
}).ToList();//汇总记录不出现重复值
|
|
|
|
|
|
var groups = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV |
|
|
|
|
|
{ |
|
|
|
|
|
LU = p.Key.LU, |
|
|
|
|
|
Amt = p.Sum(itm => itm.Amt), |
|
|
|
|
|
Qty = p.Sum(itm => itm.Qty), |
|
|
|
|
|
Price = p.Key.Price, |
|
|
|
|
|
BeginDate = p.Key.BeginDate, |
|
|
|
|
|
EndDate = p.Key.EndDate |
|
|
|
|
|
}).ToList();//汇总记录不出现重复值
|
|
|
|
|
|
Dictionary<string, List<TMEP_INV>> invoiceMap = new Dictionary<string, List<TMEP_INV>>();//发票和发票明细关系
|
|
|
|
|
|
foreach (var group in groups) |
|
|
|
|
|
{ |
|
|
|
|
|
int i = groups1.Count(p => p.LU == group.LU |
|
|
|
|
|
&& p.BeginDate == group.BeginDate |
|
|
|
|
|
&& p.EndDate == group.EndDate |
|
|
|
|
|
&& p.ContractDocID == group.ContractDocID |
|
|
|
|
|
); |
|
|
|
|
|
if (i > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); |
|
|
|
|
|
List<TMEP_INV> tempList = new List<TMEP_INV>(); |
|
|
|
|
|
decimal sum = group.Amt;//初始合计金额
|
|
|
|
|
|
int partCount = 0; |
|
|
|
|
|
foreach (var group1 in groups1) |
|
|
|
|
|
{ |
|
|
|
|
|
if (group.LU == group1.LU |
|
|
|
|
|
&& group.BeginDate == group1.BeginDate |
|
|
|
|
|
&& group.EndDate == group1.EndDate |
|
|
|
|
|
&& group1.ContractDocID == group.ContractDocID |
|
|
|
|
|
) |
|
|
|
|
|
{ |
|
|
|
|
|
tempList.Add(group1); |
|
|
|
|
|
partCount++;//符合条件加入到零件中
|
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
partCount++; |
|
|
|
|
|
if (partCount > 30) |
|
|
|
|
|
{ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (sum > 10000000) |
|
|
|
|
|
{ |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
sum += group1.Amt; |
|
|
|
|
|
tempList.Add(group1); |
|
|
|
|
|
} |
|
|
|
|
|
invoiceMap.Add(invoiceBillNum, tempList); |
|
|
|
|
|
var query = from itm in groups1 |
|
|
|
|
|
join itm1 in tempList |
|
|
|
|
|
on new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID } |
|
|
|
|
|
equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID } into temp |
|
|
|
|
|
from tm in temp |
|
|
|
|
|
where tm == null |
|
|
|
|
|
select new TMEP_INV |
|
|
|
|
|
{ |
|
|
|
|
|
LU = itm.LU, |
|
|
|
|
|
Amt = itm.Amt, |
|
|
|
|
|
Qty = itm.Qty, |
|
|
|
|
|
BeginDate = itm.BeginDate, |
|
|
|
|
|
ContractDocID = itm.ContractDocID, |
|
|
|
|
|
EndDate = itm.EndDate |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
groups1 = query.ToList(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (invoiceMap.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>(); |
|
|
|
|
|
foreach (var group in invoiceMap) |
|
|
|
|
|
{ |
|
|
|
|
|
var key = group.Key;//发票票号
|
|
|
|
|
|
var ls = group.Value;//发票明细
|
|
|
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
|
|
foreach (var detail in ls) |
|
|
|
|
|
{ |
|
|
|
|
|
_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 |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
if (_entityDetailList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
|
|
} |
|
|
|
|
|
decimal amt = detailList.Sum(k => k.Amt); |
|
|
|
|
|
decimal txtAmt = Math.Round(detailList.Sum(k => k.Amt), 2); |
|
|
|
|
|
var contractList = ls.Select(p => p.ContractDocID).Distinct(); |
|
|
|
|
|
var _groupList = dtos.Where(p => contractList.Contains(p.ContractDocID)).GroupBy(p => new { p.GroupNum }) |
|
|
|
|
|
.Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct(); |
|
|
|
|
|
//var _groupList = dtos.GroupBy(p => new { p.GroupNum })
|
|
|
|
|
|
// .Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct();
|
|
|
|
|
|
List<INVOICE_MAP_GROUP> group1 = new List<INVOICE_MAP_GROUP>(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var en in _groupList) |
|
|
|
|
|
{ |
|
|
|
|
|
group1.Add( |
|
|
|
|
|
new INVOICE_MAP_GROUP( |
|
|
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
|
|
version: p_version, |
|
|
|
|
|
invbillNum: key, |
|
|
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
|
|
settleGroupNum: en.GroupNum, |
|
|
|
|
|
amt: en.Amt, |
|
|
|
|
|
extend1: string.Empty, |
|
|
|
|
|
extend2: string.Empty)); |
|
|
|
|
|
} |
|
|
|
|
|
if (group1.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
groupList.AddRange(group1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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: p_parentInvBillNum |
|
|
|
|
|
); |
|
|
|
|
|
invlist.Add(invbill); |
|
|
|
|
|
} |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 第一次开票
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dtos"></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>
|
|
|
|
|
|
public async Task<bool> 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) |
|
|
|
|
|
{ |
|
|
|
|
|
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>(); |
|
|
|
|
|
foreach (var itm in invoiceMap)//分组影响和
|
|
|
|
|
|
{ |
|
|
|
|
|
var key = itm.Key;//发票票号
|
|
|
|
|
|
var ls = itm.Value;//结算分组号列表
|
|
|
|
|
|
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 |
|
|
|
|
|
{ |
|
|
|
|
|
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), |
|
|
|
|
|
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 |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
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 |
|
|
|
|
|
); |
|
|
|
|
|
invlist.Add(invbill); |
|
|
|
|
|
} |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
|
|
if (notDetialList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
|
/// <param name="p_OldInvBillNum"></param>
|
|
|
|
|
|
/// <param name="p_version"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
|
|
public async Task<bool> ReissueFirstInvoice(List<TEMP_CAN_SA_DETAIL> dtos, string p_OldInvBillNum, int p_version) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
var inv = await GetInvoiceAsync(p_OldInvBillNum); |
|
|
|
|
|
if (inv == null) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
throw new BusinessException("8989", $"找不到选择要重开发票号{p_OldInvBillNum}不能重开"); |
|
|
|
|
|
} |
|
|
|
|
|
if (inv.InvoiceState == InvoiceBillState.报废) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989", $"选择要重开发票号{p_OldInvBillNum}已经作废不能重开"); |
|
|
|
|
|
} |
|
|
|
|
|
inv.InvoiceState = InvoiceBillState.报废; |
|
|
|
|
|
await FirstInvoice(dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
|
|
|
_repository.DbContext.BulkUpdate(new List<INVOICE_GRP> { inv }); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
|
/// <param name="p_OldInvBillNum"></param>
|
|
|
|
|
|
/// <param name="p_version"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
|
|
public async Task<bool> ReissueSecInvoice(List<TEMP_CAN_SA_DETAIL> dtos, string p_OldInvBillNum, int p_version) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!string.IsNullOrEmpty(p_OldInvBillNum)) |
|
|
|
|
|
{ |
|
|
|
|
|
var inv = await GetInvoiceAsync(p_OldInvBillNum); |
|
|
|
|
|
if (inv == null) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
throw new BusinessException("8989", $"找不到选择要重开发票号{p_OldInvBillNum}不能重开"); |
|
|
|
|
|
} |
|
|
|
|
|
if (inv.InvoiceState == InvoiceBillState.报废) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("8989", $"选择要重开发票号{p_OldInvBillNum}已经作废不能重开"); |
|
|
|
|
|
} |
|
|
|
|
|
inv.InvoiceState = InvoiceBillState.报废; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await FirstInvoice(dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); |
|
|
|
|
|
_repository.DbContext.BulkUpdate(new List<INVOICE_GRP> { inv }); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|