|
|
@ -1,15 +1,26 @@ |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Components; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Security.Policy; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Win.Abp.Snowflakes; |
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Managers; |
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices; |
|
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
@ -21,8 +32,491 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class BBAC_BA_SERVICE : BA_SERVICE |
|
|
|
{ |
|
|
|
public BBAC_BA_SERVICE(INormalEfCoreRepository<INVOICE_GRP, Guid> repository, INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> wRepository, INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository, INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository, IExcelImportAppService excelImportService, BBAC_CAN_SA_MNG pubMng, HBPO_CAN_SA_MNG bbacMng, PUB_CAN_SA_MNG hbpoMng, INV_MNG invMng) : base(repository, wRepository, sRepository, mRepository, excelImportService, pubMng, bbacMng, hbpoMng, invMng) |
|
|
|
|
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _adjRepository; |
|
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceRepository; |
|
|
|
|
|
|
|
|
|
|
|
public BBAC_BA_SERVICE(IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager, |
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> pubRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> wRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository, |
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository, |
|
|
|
BBAC_CAN_SA_MNG pubMng, |
|
|
|
HBPO_CAN_SA_MNG bbacMng, |
|
|
|
PUB_CAN_SA_MNG hbpoMng, |
|
|
|
INV_MNG invMng, |
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository, |
|
|
|
INormalEfCoreRepository<PriceList, Guid> priceRepository |
|
|
|
|
|
|
|
) : base(excelImportService, snowflakeIdGenerator, commonManager, pubRepository, repository, wRepository, sRepository, mRepository, pubMng, bbacMng, hbpoMng, invMng) |
|
|
|
{ |
|
|
|
_adjRepository = adjRepository; |
|
|
|
_priceRepository = priceRepository; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 发票重开
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<string> ReissueInvoice(string p_invbillnum) |
|
|
|
{ |
|
|
|
var mappingList= await GetMapGroupAsync(p_invbillnum);//结算分组
|
|
|
|
if (mappingList != null && mappingList.Count() > 0) |
|
|
|
{ |
|
|
|
var version=int.Parse(DateTime.Now.ToString("yyyymm")); |
|
|
|
var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
|
|
|
|
var inv= await GetInvoiceGroupByInvBillNum(p_invbillnum); |
|
|
|
if (inv != null) |
|
|
|
{ |
|
|
|
var bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件
|
|
|
|
var adjlist=await _adjRepository.Where(p=>p.InvBillNum==inv.InvbillNum).ToListAsync(); |
|
|
|
if(adjlist!=null && adjlist.Count()>0) |
|
|
|
{ |
|
|
|
foreach (var itm in adjlist) |
|
|
|
{ |
|
|
|
bbaclist.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//生产号
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据
|
|
|
|
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); |
|
|
|
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
|
|
|
|
//var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算
|
|
|
|
var dto1s = ObjectMapper.Map<List<BBAC_CAN_SA_DETAIL>, List<BBAC_CAN_SA_DETAIL_DTO>>(entitys); |
|
|
|
|
|
|
|
var priceList = _priceRepository.ToList();//价格单
|
|
|
|
|
|
|
|
var inner = from d in dto1s |
|
|
|
join p in priceList on d.LU equals p.LU |
|
|
|
where |
|
|
|
d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime |
|
|
|
select d; |
|
|
|
var left = from d in dto1s |
|
|
|
join p in inner on new { d.LU, d.PN } equals new { p.LU, p.PN } |
|
|
|
into temp |
|
|
|
from tm in temp.DefaultIfEmpty()//校验错误项
|
|
|
|
where tm == null |
|
|
|
select d; |
|
|
|
|
|
|
|
List<ERR_EXP_DTO> errorList = new List<ERR_EXP_DTO>(); |
|
|
|
|
|
|
|
foreach (var error in left) |
|
|
|
{ |
|
|
|
errorList.Add(new ERR_EXP_DTO() { ItemCode = error.LU, CustomCode = "业务类别BBAC", Version = version.ToString(), Message = "LU:{0}PN:{1},下线日期:{2}没有对应区间销售价格表!" }); |
|
|
|
} |
|
|
|
if (errorList.Count() > 0) |
|
|
|
{ |
|
|
|
return await ExportErrorReportAsync(errorList); |
|
|
|
} |
|
|
|
var q = from d in dto1s |
|
|
|
join p in priceList on d.LU equals p.LU |
|
|
|
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime |
|
|
|
select new TEMP_CAN_SA_DETAIL |
|
|
|
{ |
|
|
|
SettleBillNum = d.SettleBillNum, |
|
|
|
Site = d.Site, |
|
|
|
Version = d.Version, |
|
|
|
Price = p.Price, |
|
|
|
BillNum = d.BillNum, |
|
|
|
SettleDate = d.SettleDate, |
|
|
|
InvGroupNum = d.InvGroupNum, |
|
|
|
LU = d.LU, |
|
|
|
MaterialDesc = d.MaterialDesc, |
|
|
|
PN = d.PN, |
|
|
|
Qty = d.Qty, |
|
|
|
GroupNum = d.GroupNum, |
|
|
|
Amt = Math.Round(d.Qty * p.Price, 2), |
|
|
|
ContractDocID = d.ContractDocID, |
|
|
|
BeginDate = p.BeginTime, |
|
|
|
EndDate = p.EndTime |
|
|
|
}; |
|
|
|
var dtos = q.ToList(); |
|
|
|
|
|
|
|
if (dtos != null && dtos.Count > 0) |
|
|
|
{ |
|
|
|
if (p_invbillnum.Substring(0, 1) == "INV")//一次开票
|
|
|
|
{ |
|
|
|
// dtos = dtos.OrderBy(p => p.SettleDate).ToList();
|
|
|
|
var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).OrderBy(p => p.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) |
|
|
|
{ |
|
|
|
if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组
|
|
|
|
{ |
|
|
|
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 + p.ContractDocID).Distinct().ToList(); //初始LU种类
|
|
|
|
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 + p.ContractDocID).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>(); |
|
|
|
// string str = JsonConvert.SerializeObject(invoiceMap);
|
|
|
|
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.ContractDocID, p.BeginDate, p.EndDate }) |
|
|
|
.Select(itm => new |
|
|
|
{ |
|
|
|
InvGroupNum = itm.Key.InvGroupNum, |
|
|
|
LU = itm.Key.LU, |
|
|
|
ContactDocID = itm.Key.ContractDocID, |
|
|
|
Price = itm.Key.Price, |
|
|
|
Amt = itm.Sum(p => p.Amt), |
|
|
|
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) * 0.13m, 2); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in ls) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: inv.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: version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum:inv.InvGroupNum, |
|
|
|
lU: detail.LU, |
|
|
|
qty: detail.Qty, |
|
|
|
bussiessType: EnumBusinessType.JisHBPO, |
|
|
|
amt: detail.Amt, |
|
|
|
pRICE: detail.Price, |
|
|
|
extend1: detail.ContactDocID, |
|
|
|
extend2: string.Empty, |
|
|
|
beginDate: detail.BeginDate, |
|
|
|
endDate: detail.EndDate |
|
|
|
)); |
|
|
|
} |
|
|
|
if (_entityDetailList.Count > 0) |
|
|
|
{ |
|
|
|
detailList.AddRange(_entityDetailList); |
|
|
|
} |
|
|
|
|
|
|
|
#region 原有新发票生成时
|
|
|
|
//var notls = 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) });
|
|
|
|
//var innotls = new List<INVOICE_NOT_SETTLE>();
|
|
|
|
//foreach (var nitm in notls)
|
|
|
|
//{
|
|
|
|
// innotls.Add(new INVOICE_NOT_SETTLE(
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// version: main.Version,
|
|
|
|
// invGroupNum: main.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);
|
|
|
|
//}
|
|
|
|
#endregion
|
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
(guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: key, |
|
|
|
amt: amt, |
|
|
|
taxAmt: txtAmt, |
|
|
|
fileName: string.Empty, |
|
|
|
businessType: EnumBusinessType.JisBBAC, |
|
|
|
invGroupNum: inv.InvGroupNum, |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常, |
|
|
|
tax:0, |
|
|
|
parent:inv.InvbillNum |
|
|
|
); |
|
|
|
invlist.Add(invbill); |
|
|
|
} |
|
|
|
var notlist=await GetNotDetailAsync(p_invbillnum); |
|
|
|
if (notlist != null && notlist.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var nitm in notlist) |
|
|
|
{ |
|
|
|
notDetialList.Add(new INVOICE_NOT_SETTLE( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: version, |
|
|
|
invGroupNum: nitm.InvGroupNum, |
|
|
|
settleGroupNum: nitm.SettleGroupNum, |
|
|
|
lU: string.Empty, |
|
|
|
lU1: nitm.LU, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
qty: nitm.Qty |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
await _repository.DbContext.BulkInsertAsync(notDetialList); |
|
|
|
} |
|
|
|
} |
|
|
|
else//二次开票
|
|
|
|
{ |
|
|
|
var groups1 = dtos.GroupBy(p => new { p.LU, p.ContractDocID, p.Price, p.BeginDate, p.EndDate }).Select(p => new TMEP_INV |
|
|
|
{ |
|
|
|
BeginDate = p.Key.BeginDate, |
|
|
|
EndDate = p.Key.EndDate, |
|
|
|
LU = p.Key.LU, |
|
|
|
ContractDocID = p.Key.ContractDocID, |
|
|
|
Amt = p.Sum(itm => itm.Amt), |
|
|
|
Qty = p.Sum(itm => itm.Qty), |
|
|
|
Price = p.Key.Price |
|
|
|
}).ToList();//汇总记录不出现重复值
|
|
|
|
var groups = dtos.GroupBy(p => new { p.LU, p.ContractDocID, p.Price, p.BeginDate, p.EndDate }).Select(p => new TMEP_INV |
|
|
|
{ |
|
|
|
BeginDate = p.Key.BeginDate, |
|
|
|
EndDate = p.Key.EndDate, |
|
|
|
LU = p.Key.LU, |
|
|
|
ContractDocID = p.Key.ContractDocID, |
|
|
|
Amt = p.Sum(itm => itm.Amt), |
|
|
|
Qty = p.Sum(itm => itm.Qty), |
|
|
|
Price = p.Key.Price |
|
|
|
}).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.ContractDocID == group.ContractDocID |
|
|
|
&& p.BeginDate == group.BeginDate |
|
|
|
&& p.EndDate == group.EndDate |
|
|
|
); |
|
|
|
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 && group1.ContractDocID == group.ContractDocID |
|
|
|
&& group.BeginDate == group1.BeginDate |
|
|
|
&& group.EndDate == group1.EndDate |
|
|
|
) |
|
|
|
{ |
|
|
|
tempList.Add(group1); |
|
|
|
partCount++;//符合条件加入到零件中
|
|
|
|
continue; |
|
|
|
} |
|
|
|
partCount++; |
|
|
|
if (partCount > 30) |
|
|
|
{ |
|
|
|
continue; |
|
|
|
} |
|
|
|
sum += group1.Amt; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
tempList.Add(group1); |
|
|
|
} |
|
|
|
invoiceMap.Add(invoiceBillNum, tempList); |
|
|
|
var query = from itm in groups1 |
|
|
|
join itm1 in tempList |
|
|
|
on new { itm.LU, itm.ContractDocID, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.ContractDocID, itm1.BeginDate, itm1.EndDate } into temp |
|
|
|
from tm in temp |
|
|
|
where tm == null |
|
|
|
select new TMEP_INV |
|
|
|
{ |
|
|
|
LU = itm.LU, |
|
|
|
ContractDocID = itm.ContractDocID, |
|
|
|
Price = itm.Price, |
|
|
|
Amt = itm.Amt, |
|
|
|
Qty = itm.Qty, |
|
|
|
BeginDate = itm.BeginDate, |
|
|
|
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: version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: inv.InvGroupNum, |
|
|
|
lU: detail.LU, |
|
|
|
qty: detail.Qty, |
|
|
|
bussiessType: EnumBusinessType.JisBBAC, |
|
|
|
amt: detail.Amt, |
|
|
|
pRICE: detail.Price, |
|
|
|
extend1: detail.ContractDocID, |
|
|
|
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(); |
|
|
|
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: version, |
|
|
|
invbillNum: key, |
|
|
|
invGroupNum: inv.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: EnumBusinessType.JisBBAC, |
|
|
|
invGroupNum: inv.InvGroupNum, |
|
|
|
state: SettleBillState.已开票, |
|
|
|
invoiceBillState: InvoiceBillState.正常, |
|
|
|
tax: 0, |
|
|
|
parent: inv.InvbillNum |
|
|
|
); |
|
|
|
invlist.Add(invbill); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(invlist); |
|
|
|
await _repository.DbContext.BulkInsertAsync(groupList); |
|
|
|
await _repository.DbContext.BulkInsertAsync(detailList); |
|
|
|
//await _repository.DbContext.BulkInsertAsync(notDetialList);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", $"不存发票号为:{p_invbillnum}发票"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号"); |
|
|
|
} |
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|