|
|
@ -24,6 +24,7 @@ using TaskJob.EventArgs; |
|
|
|
using TaskJob.Interfaces; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Guids; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win.Sfs.SettleAccount.Bases; |
|
|
@ -162,7 +163,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
}).ToList();//不能结算
|
|
|
|
|
|
|
|
entitys = entitys.OrderBy(p => p.LU).ToList(); |
|
|
|
var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); |
|
|
|
var invs = BBACSecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); |
|
|
|
// var invs = SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, query.ToList());
|
|
|
|
if (invs.Count > 0) |
|
|
|
{ |
|
|
@ -269,6 +270,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public 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 |
|
|
|
{ |
|
|
@ -1217,20 +1219,172 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
public List<string> BBACSecInvoice<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, new() |
|
|
|
{ |
|
|
|
List<string> _invls = new List<string>(); |
|
|
|
int totalRecords = dtos.Count; |
|
|
|
int pageSize = 9999; // 每页记录数
|
|
|
|
int totalSize = (totalRecords + pageSize - 1) / pageSize; |
|
|
|
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>(); |
|
|
|
for (int pageNumber = 1; pageNumber <= totalSize; pageNumber++) |
|
|
|
{ |
|
|
|
var pagedDetails = dtos |
|
|
|
.OrderBy(p => p.GroupNum) |
|
|
|
.Skip((pageNumber - 1) * pageSize) |
|
|
|
.Take(pageSize) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
var invBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); |
|
|
|
|
|
|
|
var detailDtos = pagedDetails.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 = pagedDetails.Select(p => p.GroupNum); |
|
|
|
var mapList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
foreach (var groupnum in invoicegrup) |
|
|
|
{ |
|
|
|
mapList.Add(new INVOICE_MAP_GROUP( |
|
|
|
guid: Guid.NewGuid(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: invBillNum, |
|
|
|
invGroupNum: p_InvGroupNum, |
|
|
|
settleGroupNum: groupnum, |
|
|
|
amt: 0, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
if (mapList.Count > 0) |
|
|
|
{ |
|
|
|
groupList.AddRange(mapList); |
|
|
|
} |
|
|
|
#region 发票明细
|
|
|
|
List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
|
foreach (var detail in detailDtos) |
|
|
|
{ |
|
|
|
_entityDetailList.Add( |
|
|
|
new INVOICE_WAIT_DETAIL( |
|
|
|
guid: Guid.NewGuid(), |
|
|
|
version: p_version, |
|
|
|
invbillNum: 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: Guid.NewGuid(), |
|
|
|
realnvBillNum: string.Empty, |
|
|
|
invbillNum: 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
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (salist.Count > 0) |
|
|
|
{ |
|
|
|
_dbcontext.BulkUpdate(salist); |
|
|
|
} |
|
|
|
_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(); |
|
|
|
return _invls; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|