|
|
@ -5,6 +5,8 @@ using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using AutoMapper; |
|
|
|
using CodeArts.Db.Lts; |
|
|
|
using DocumentFormat.OpenXml.Bibliography; |
|
|
|
using DocumentFormat.OpenXml.Drawing.Diagrams; |
|
|
|
using DocumentFormat.OpenXml.Presentation; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
@ -18,6 +20,7 @@ using TaskJob.EventArgs; |
|
|
|
using TaskJob.Interfaces; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.Bases.DomainServices; |
|
|
@ -281,7 +284,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
List<string> invoiceGroupNumList = new List<string>();//每个发票对应的结算分组号
|
|
|
|
List<string> List = new List<string>(); |
|
|
|
decimal sum = itm.Value;//初始分组合计金额
|
|
|
|
|
|
|
|
|
|
|
|
if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组
|
|
|
|
{ |
|
|
|
if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO) |
|
|
@ -292,7 +295,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
invoiceGroupNumList.Add(itm.Key); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
@ -321,7 +324,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sum += _itm1.Value; |
|
|
|
if (sum > 10000000) |
|
|
|
{ |
|
|
@ -540,26 +543,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
_dbcontext.BulkUpdate(salist); |
|
|
|
//带库位发票
|
|
|
|
var detailext=salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode,p.LU,p.Price, p.ErpLoc,p.BusinessType }) |
|
|
|
var detailext = salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode, p.LU, p.Price, p.ErpLoc, p.BusinessType }) |
|
|
|
.Select(p => new INVOICE_DETAIL_EXT |
|
|
|
{ |
|
|
|
Version=p_version, |
|
|
|
InvbillNum= p.Key.InvbillNum, |
|
|
|
InvGroupNum= p.Key.InvGroupNum, |
|
|
|
PartCode=p.Key.PartCode, |
|
|
|
PRICE= p.Key.Price, |
|
|
|
ErpLoc=p.Key.ErpLoc, |
|
|
|
Qty = p.Sum(k => k.Qty), |
|
|
|
BussiessType=p.Key.BusinessType, |
|
|
|
Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
|
|
|
|
LU=p.Key.LU |
|
|
|
|
|
|
|
Version = p_version, |
|
|
|
InvbillNum = p.Key.InvbillNum, |
|
|
|
InvGroupNum = p.Key.InvGroupNum, |
|
|
|
PartCode = p.Key.PartCode, |
|
|
|
PRICE = p.Key.Price, |
|
|
|
ErpLoc = p.Key.ErpLoc, |
|
|
|
Qty = p.Sum(k => k.Qty), |
|
|
|
BussiessType = p.Key.BusinessType, |
|
|
|
Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
|
|
|
|
LU = p.Key.LU |
|
|
|
|
|
|
|
} |
|
|
|
).ToList(); |
|
|
|
foreach (var itm in detailext) |
|
|
|
{ |
|
|
|
itm.SetId(GuidGenerator.Create()); |
|
|
|
itm.CreationTime = DateTime.Now; |
|
|
|
itm.CreationTime = DateTime.Now; |
|
|
|
} |
|
|
|
_dbcontext.BulkInsert(detailext); |
|
|
|
} |
|
|
@ -613,177 +616,403 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
EndDate = itm.Key.EndDate |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
List<GroupPartCode> biglist = new List<GroupPartCode>(); |
|
|
|
List<GroupPartCode> smalllist = new List<GroupPartCode>(); |
|
|
|
foreach (var itm in groupDtos)//分类1000W以上或1000W以下
|
|
|
|
if (groupDtos.Sum(p => p.Amt) < 10000000) |
|
|
|
{ |
|
|
|
if (itm.Amt > 10000000) |
|
|
|
var ls = new List<GroupPartCode>(); |
|
|
|
var orderbyList = groupDtos.OrderBy(p => p.Qty).ToList(); |
|
|
|
int i = 0; |
|
|
|
int j = orderbyList.Count - 1; |
|
|
|
while (i <= j) |
|
|
|
{ |
|
|
|
biglist.Add(itm); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
smalllist.Add(itm); |
|
|
|
if (i == j) |
|
|
|
{ |
|
|
|
ls.Add(orderbyList[i]); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ls.Add(orderbyList[i]); |
|
|
|
ls.Add(orderbyList[j]); |
|
|
|
} |
|
|
|
i++; |
|
|
|
j--; |
|
|
|
} |
|
|
|
_invls = GenSecInvoice(orderbyList, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
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 big in biglist)//单条大于1000W的开票
|
|
|
|
else |
|
|
|
{ |
|
|
|
var list = p_list.Where(p => p.InvGroupNum == big.InvGroupNum && p.PartCode == big.PartCode && p.Price == big.Price && p.LU == big.LU); |
|
|
|
var gener = new InvoiceGeneratorSame<TDetail>(); |
|
|
|
gener.GenerateInvoices(p_list); |
|
|
|
var invList = gener.Invoices; |
|
|
|
foreach (var inv in invList) |
|
|
|
List<GroupPartCode> biglist = new List<GroupPartCode>(); |
|
|
|
List<GroupPartCode> smalllist = new List<GroupPartCode>(); |
|
|
|
foreach (var itm in groupDtos)//分类1000W以上或1000W以下
|
|
|
|
{ |
|
|
|
var partlist = inv.Parts; |
|
|
|
if (partlist.Count > 0) |
|
|
|
if (itm.Amt > 10000000) |
|
|
|
{ |
|
|
|
var query = from itm in partlist |
|
|
|
join itm1 in dtos on itm.Id equals itm1.Id |
|
|
|
select itm1; |
|
|
|
var Dtos = query.ToList(); |
|
|
|
var detailDtos = Dtos.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 invoicegrup = partlist.Select(p => p.GroupNum); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in invoicegrup) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: inv.InvBillNum, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: groupnum, |
|
|
|
amt: 0, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
if (mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
} |
|
|
|
var innotls = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var sq = partlist.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum }) |
|
|
|
.Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, 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: inv.InvBillNum |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
biglist.Add(itm); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
smalllist.Add(itm); |
|
|
|
} |
|
|
|
} |
|
|
|
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 big in biglist)//单条大于1000W的开票
|
|
|
|
{ |
|
|
|
var list = p_list.Where(p => p.InvGroupNum == big.InvGroupNum && p.PartCode == big.PartCode && p.Price == big.Price && p.LU == big.LU); |
|
|
|
var gener = new InvoiceGeneratorSame<TDetail>(); |
|
|
|
gener.GenerateInvoices(p_list); |
|
|
|
var invList = gener.Invoices; |
|
|
|
foreach (var inv in invList) |
|
|
|
{ |
|
|
|
var partlist = inv.Parts; |
|
|
|
if (partlist.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
var query = from itm in partlist |
|
|
|
join itm1 in dtos on itm.Id equals itm1.Id |
|
|
|
select itm1; |
|
|
|
var Dtos = query.ToList(); |
|
|
|
var detailDtos = Dtos.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(); |
|
|
|
|
|
|
|
#region 发票明细
|
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
foreach (var detail in detailDtos) |
|
|
|
{ |
|
|
|
_entityDetailList.Add( |
|
|
|
new INVOICE_WAIT_DETAIL( |
|
|
|
decimal amt = detailDtos.Sum(k => k.Amt);//金额
|
|
|
|
decimal txtAmt = detailDtos.Sum(k => k.TaxAmt);//税后金额
|
|
|
|
decimal realAmt = detailDtos.Sum(k => k.Tax);//税额
|
|
|
|
|
|
|
|
|
|
|
|
var invoicegrup = partlist.Select(p => p.GroupNum); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in invoicegrup) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: inv.InvBillNum, |
|
|
|
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); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 发票
|
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: inv.InvBillNum, |
|
|
|
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; |
|
|
|
settleGroupNum: groupnum, |
|
|
|
amt: 0, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
if (mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
} |
|
|
|
var innotls = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var sq = partlist.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum }) |
|
|
|
.Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, 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: inv.InvBillNum |
|
|
|
)); |
|
|
|
} |
|
|
|
if (innotls.Count > 0) |
|
|
|
{ |
|
|
|
notDetialList.AddRange(innotls); |
|
|
|
} |
|
|
|
|
|
|
|
#region 发票明细
|
|
|
|
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: inv.InvBillNum, |
|
|
|
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); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#region 发票
|
|
|
|
var invbill = new INVOICE_GRP |
|
|
|
( |
|
|
|
guid: GuidGenerator.Create(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: inv.InvBillNum, |
|
|
|
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); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
invbill.ClientCode = clientCode; |
|
|
|
invbill.Site = dtos.FirstOrDefault().Site; |
|
|
|
invbill.CreationTime = DateTime.MinValue; |
|
|
|
invbill.LastModificationTime = DateTime.Now; |
|
|
|
invlist.Add(invbill); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
smalllist = smalllist.OrderBy(p => p.Amt).ToList(); |
|
|
|
_invls= GenSecInvoice(smalllist, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType); |
|
|
|
|
|
|
|
|
|
|
|
//smalllist = smalllist.OrderBy(p => p.Amt).ToList();
|
|
|
|
//var gener1 = new InvoiceGeneratorDiff();
|
|
|
|
//gener1.GenerateInvoices(smalllist);
|
|
|
|
//var invList1 = gener1.Invoices;
|
|
|
|
//foreach (var inv in invList1)//小于1000W的开票
|
|
|
|
//{
|
|
|
|
// var partlist = inv.Parts;
|
|
|
|
// var query = from part in p_list
|
|
|
|
// join part1 in partlist on
|
|
|
|
// new { part.InvGroupNum, part.PartCode, part.LU, part.Price } equals new { part1.InvGroupNum, part1.PartCode, part1.LU, part1.Price }
|
|
|
|
// select part;
|
|
|
|
|
|
|
|
// var entityList = query.ToList();
|
|
|
|
|
|
|
|
// foreach (var entity in entityList)
|
|
|
|
// {
|
|
|
|
// entity.InvbillNum = inv.InvBillNum;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// salist.AddRange(entityList);
|
|
|
|
|
|
|
|
// if (partlist.Count > 0)
|
|
|
|
// {
|
|
|
|
// decimal amt = partlist.Sum(k => k.Amt);//金额
|
|
|
|
// decimal txtAmt = partlist.Sum(k => k.TaxAmt);//税后金额
|
|
|
|
// decimal realAmt = partlist.Sum(k => k.Tax);//税额
|
|
|
|
|
|
|
|
// var invoicegroupls = entityList.Select(p => p.GroupNum);
|
|
|
|
// var mapList = new List<INVOICE_MAP_GROUP>();
|
|
|
|
// foreach (var groupnum in invoicegroupls)
|
|
|
|
// {
|
|
|
|
// mapList.Add(new INVOICE_MAP_GROUP(
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// version: p_version,
|
|
|
|
// invbillNum: inv.InvBillNum,
|
|
|
|
// invGroupNum: p_InvGroupNum,
|
|
|
|
// settleGroupNum: groupnum,
|
|
|
|
// amt: 0,
|
|
|
|
// extend1: string.Empty,
|
|
|
|
// extend2: string.Empty
|
|
|
|
// )
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// if (mapList.Count > 0)
|
|
|
|
// {
|
|
|
|
// groupList.AddRange(mapList);
|
|
|
|
// }
|
|
|
|
// var innotls = new List<INVOICE_NOT_SETTLE>();
|
|
|
|
// var sq = entityList.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum })
|
|
|
|
// .Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, 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: sitm.InvBillNum
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// if (innotls.Count > 0)
|
|
|
|
// {
|
|
|
|
// notDetialList.AddRange(innotls);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>();
|
|
|
|
// foreach (var detail in partlist)
|
|
|
|
// {
|
|
|
|
// _entityDetailList.Add(
|
|
|
|
// new INVOICE_WAIT_DETAIL(
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// version: p_version,
|
|
|
|
// invbillNum: inv.InvBillNum,
|
|
|
|
// 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.Value,
|
|
|
|
// endDate: detail.EndDate.Value,
|
|
|
|
// partcode: detail.PartCode
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
// if (_entityDetailList.Count > 0)
|
|
|
|
// {
|
|
|
|
// detailList.AddRange(_entityDetailList);
|
|
|
|
// }
|
|
|
|
// var invbill = new INVOICE_GRP
|
|
|
|
// (
|
|
|
|
// guid: GuidGenerator.Create(),
|
|
|
|
// realnvBillNum: string.Empty,
|
|
|
|
// invbillNum: inv.InvBillNum,
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//if (salist.Count > 0)
|
|
|
|
//{
|
|
|
|
// _dbcontext.BulkUpdate(salist);
|
|
|
|
// var detailext = salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode, p.LU, p.Price, p.ErpLoc, p.BusinessType })
|
|
|
|
// .Select(p => new INVOICE_DETAIL_EXT
|
|
|
|
// {
|
|
|
|
// Version = p_version,
|
|
|
|
// InvbillNum = p.Key.InvbillNum,
|
|
|
|
// InvGroupNum = p.Key.InvGroupNum,
|
|
|
|
// PartCode = p.Key.PartCode,
|
|
|
|
// PRICE = p.Key.Price,
|
|
|
|
// ErpLoc = p.Key.ErpLoc,
|
|
|
|
// Qty = p.Sum(k => k.Qty),
|
|
|
|
// BussiessType = p.Key.BusinessType,
|
|
|
|
// Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
|
|
|
|
// LU = p.Key.LU
|
|
|
|
|
|
|
|
// }
|
|
|
|
// ).ToList();
|
|
|
|
// foreach (var itm in detailext)
|
|
|
|
// {
|
|
|
|
// itm.SetId(GuidGenerator.Create());
|
|
|
|
// itm.CreationTime = DateTime.Now;
|
|
|
|
// }
|
|
|
|
// _dbcontext.BulkInsert(detailext);
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
//_dbcontext.BulkInsert(invlist);
|
|
|
|
//_dbcontext.BulkInsert(groupList);
|
|
|
|
//_dbcontext.BulkInsert(detailList);
|
|
|
|
|
|
|
|
//if (adjlist.Count > 0)
|
|
|
|
//{
|
|
|
|
// _dbcontext.BulkInsert(adjlist);
|
|
|
|
//}
|
|
|
|
//if (notDetialList.Count > 0)
|
|
|
|
//{
|
|
|
|
// _dbcontext.BulkInsert(notDetialList);
|
|
|
|
//}
|
|
|
|
//_invls = invlist.Select(p => p.InvbillNum).ToList();
|
|
|
|
} |
|
|
|
smalllist = smalllist.OrderBy(p => p.Amt).ToList(); |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<string> GenSecInvoice<TDetail>(List<GroupPartCode> p_grouplist, 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, new() |
|
|
|
{ |
|
|
|
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> _invls = new List<string>(); |
|
|
|
|
|
|
|
var gener1 = new InvoiceGeneratorDiff(); |
|
|
|
gener1.GenerateInvoices(smalllist); |
|
|
|
gener1.GenerateInvoices(p_grouplist); |
|
|
|
var invList1 = gener1.Invoices; |
|
|
|
foreach (var inv in invList1)//小于1000W的开票
|
|
|
|
{ |
|
|
@ -800,8 +1029,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
entity.InvbillNum = inv.InvBillNum; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
salist.AddRange(entityList); |
|
|
|
|
|
|
|
if (partlist.Count > 0) |
|
|
@ -937,7 +1164,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
BussiessType = p.Key.BusinessType, |
|
|
|
Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
|
|
|
|
LU = p.Key.LU |
|
|
|
|
|
|
|
} |
|
|
|
).ToList(); |
|
|
|
foreach (var itm in detailext) |
|
|
@ -952,7 +1178,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_dbcontext.BulkInsert(invlist); |
|
|
|
_dbcontext.BulkInsert(groupList); |
|
|
|
_dbcontext.BulkInsert(detailList); |
|
|
|
|
|
|
|
|
|
|
|
if (adjlist.Count > 0) |
|
|
|
{ |
|
|
|
_dbcontext.BulkInsert(adjlist); |
|
|
@ -964,7 +1190,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|