|
|
@ -13,9 +13,11 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Minio.DataModel; |
|
|
|
using Org.BouncyCastle.Asn1.Cmp; |
|
|
|
using SettleAccount.Bases; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using ShardingCore.Sharding.MergeContexts; |
|
|
|
using SqlSugar; |
|
|
|
using TaskJob.EventArgs; |
|
|
|
using TaskJob.Interfaces; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
@ -638,8 +640,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
_invls = GenSecInvoice(ls, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
@ -656,6 +656,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
smalllist.Add(itm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var groupList = new List<INVOICE_MAP_GROUP>(); |
|
|
|
var notDetialList = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
var detailList = new List<INVOICE_WAIT_DETAIL>(); |
|
|
@ -666,15 +668,21 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
{ |
|
|
|
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 entitylist=list.ToList(); |
|
|
|
|
|
|
|
gener.GenerateInvoices(entitylist); |
|
|
|
var invList = gener.Invoices; |
|
|
|
foreach (var inv in invList) |
|
|
|
{ |
|
|
|
var partlist = inv.Parts; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var query = from itm in p_list join itm1 in partlist on itm.Id equals itm1.Id select itm;
|
|
|
|
foreach (var detail in partlist) |
|
|
|
{ |
|
|
|
var entity = entitylist.FirstOrDefault(p => p.Id == detail.Id); |
|
|
|
entity.InvbillNum = inv.InvBillNum; |
|
|
|
salist.Add(entity); |
|
|
|
} |
|
|
|
if (partlist.Count > 0) |
|
|
|
{ |
|
|
|
var query = from itm in partlist |
|
|
@ -724,11 +732,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
} |
|
|
|
var innotls = new List<INVOICE_NOT_SETTLE>(); |
|
|
|
|
|
|
|
|
|
|
|
//if (partlist is List<BBAC_CAN_SA_DETAIL>)
|
|
|
|
//{
|
|
|
|
var partlist1 = partlist as List<BBAC_CAN_SA_DETAIL>; |
|
|
|
var sq = partlist1.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum}) |
|
|
|
var parlist = partlist.ToList(); |
|
|
|
if (parlist is List<BBAC_CAN_SA_DETAIL>) |
|
|
|
{ |
|
|
|
var partlist1 = parlist as List<BBAC_CAN_SA_DETAIL>; |
|
|
|
var sq = partlist1.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) |
|
|
|
{ |
|
|
@ -817,107 +825,132 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
invbill.LastModificationTime = DateTime.Now; |
|
|
|
invlist.Add(invbill); |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
// 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
|
|
|
|
//}
|
|
|
|
#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
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_dbcontext.BulkInsert(invlist); |
|
|
|
_dbcontext.BulkInsert(groupList); |
|
|
|
_dbcontext.BulkInsert(detailList); |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
if (adjlist.Count > 0) |
|
|
|
{ |
|
|
|
_dbcontext.BulkInsert(adjlist); |
|
|
@ -927,17 +960,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs |
|
|
|
_dbcontext.BulkInsert(notDetialList); |
|
|
|
} |
|
|
|
_invls = invlist.Select(p => p.InvbillNum).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
if (smalllist.Count > 0) |
|
|
|
{ |
|
|
|
smalllist = smalllist.OrderBy(p => p.Amt).ToList(); |
|
|
|
_invls = GenSecInvoice(smalllist, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
return _invls; |
|
|
|
} |
|
|
|