Browse Source

更新版本

master
zhaoxinyu 6 months ago
parent
commit
5e9eedfdb0
  1. 2
      code/src/AuthServer/AuthServer.Host/appsettings.json
  2. 2
      code/src/Modules/BaseService/BaseService.Host/appsettings.json
  3. 3
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs
  4. 10
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs
  5. 8
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs
  6. 25
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs
  7. 450
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs
  8. 49
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs

2
code/src/AuthServer/AuthServer.Host/appsettings.json

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Server=dev.ccwin-in.com,13319;Database=BJABP;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True"
"Default": "Server=dev.ccwin-in.com,13326;Database=BJABP;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True"
//"Default": "Server=localhost;Database=BJABP;User ID=sa;Password=aA123456!;Trusted_Connection=False;TrustServerCertificate=True"
},
"CorsOrigins": "http://localhost:9527,http://dev.ccwin-in.com:10588,http://localhost:44307",

2
code/src/Modules/BaseService/BaseService.Host/appsettings.json

@ -10,7 +10,7 @@
},
"ConnectionStrings": {
//"Default": "Server=localhost;Database=BJABP;User ID=sa;Password=aA123456!;Trusted_Connection=False;TrustServerCertificate=True",
"Default": "Server=dev.ccwin-in.com,13319;Database=BJABP;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True"
"Default": "Server=dev.ccwin-in.com,13326;Database=BJABP;User ID=ccwin-in;Password=Microsoft@2022;Trusted_Connection=False;TrustServerCertificate=True"
},
"ElasticSearch": {
"Url": "http://localhost:9200"

3
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs

@ -321,6 +321,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos
[Display(Name = "数量")]
public decimal Qty { set; get; }
[Display(Name = "状态")]
public string State { set; get; }
}
public class MAIDAN_HBPO_UNSETTLED_DETAIL_DTO

10
code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs

@ -152,7 +152,7 @@ namespace Win.Sfs.SettleAccount.Bases
/// <param name="p_version">版本号</param>
/// <param name="p_InvGroupNum">发票分组</param>
/// <param name="p_parentInvBillNum">原发票号</param>
protected async Task<bool> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) where TDetail : SA_CAN_BASE
protected async Task<bool> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, List<TEMP_NOT_SA_DETAIL> p_notlist = null) where TDetail : SA_CAN_BASE
{
List<string> invlist = new List<string>();
@ -166,19 +166,19 @@ namespace Win.Sfs.SettleAccount.Bases
invlist = await _invmng.MakeInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType, false).ConfigureAwait(false);
break;
case EnumBusinessType.ZhiGongJianBBAC:
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType).ConfigureAwait(false);//重开可以变多张发票
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType,p_notlist).ConfigureAwait(false);//重开可以变多张发票
break;
case EnumBusinessType.ZhiGongJianHBPO:
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType).ConfigureAwait(false);
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType, p_notlist).ConfigureAwait(false);
break;
case EnumBusinessType.BeiJian:
invlist = await _invmng.BJInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, p_InvGroupNum, string.Empty, businessType, false).ConfigureAwait(false);
break;
case EnumBusinessType.JisBBAC:
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType).ConfigureAwait(false);
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType, p_notlist).ConfigureAwait(false);
break;
case EnumBusinessType.JisHBPO:
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType).ConfigureAwait(false);
invlist = await _invmng.SecInvoice(p_list, p_adjlist, dtos, p_version, p_InvGroupNum, string.Empty, businessType, p_notlist).ConfigureAwait(false);
break;
case EnumBusinessType.YinDuJian:
invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, p_InvGroupNum, string.Empty, businessType, false).ConfigureAwait(false);//重开可以变多张发票

8
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs

@ -941,8 +941,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
//var part = mquery.ToList().Select(p => p.SettleGroupNum).Distinct().ToList();//发票对应分组号
//var unsettled = all.Where(p => !part.Contains(p));//排除发票对应分组号,都为不可结
var unsettledList = sdtos
.GroupBy(p => new { p.LU, p.SettleGroupNum })
.Select(p => new JIT_UNSETTLED_DETAIL_DTO { LU = p.Key.LU, GroupNum = p.Key.SettleGroupNum, Qty = p.Sum(itm => itm.Qty.Value) });
.GroupBy(p => new { p.LU, p.SettleGroupNum,p.Extend1 })
.Select(p => new JIT_UNSETTLED_DETAIL_DTO { LU = p.Key.LU, GroupNum = p.Key.SettleGroupNum, Qty = p.Sum(itm => itm.Qty.Value), State=p.Key.Extend1 });
entity.JIT_UNSETTLED_DETAIL = unsettledList.ToList().OrderBy(p => p.GroupNum).ThenBy(p => p.LU).ToList();
}
if (first.BusinessType == EnumBusinessType.JisHBPO || first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO)
@ -1060,7 +1060,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
#endregion
// 发票分组
if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.JisHBPO || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO || first.BusinessType == EnumBusinessType.ZhiGongJianBBAC )
if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.JisHBPO || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO )
{
if (m != null)
{
@ -1082,7 +1082,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
_excel.Append(hbpounsettle, "未结零件汇总");
}
}
if ( first.BusinessType == EnumBusinessType.YinDuJian)
if ( first.BusinessType == EnumBusinessType.YinDuJian || first.BusinessType == EnumBusinessType.ZhiGongJianBBAC)
{
if (jitunsettle != null)
{

25
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs

@ -211,7 +211,30 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
else//二次开票
{
await SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false);
var groupNums = dtos.Select(p => p.GroupNum).Distinct();
var notQuery = await _notRepository.Where(p => groupNums.Contains(p.GroupNum)).ToListAsync().ConfigureAwait(false);
var notlist = notQuery.Select(p => new TEMP_NOT_SA_DETAIL
{
KeyCode = p.KeyCode,
Version = p.Version,
SettleBillNum = p.SettleBillNum,
LU = p.LU,
PN = p.PN,
Site = p.Site,
Qty = p.Qty,
Price = p.Price,
BusinessType = p.BusinessType,
IsReturn = "",
InvGroupNum = p.InvGroupNum,
SettleDate = p.SettleDate,
GroupNum = p.GroupNum,
ContractDocID = string.Empty,
PartCode = p.PartCode
}).ToList();//不能结算
await SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType,notlist).ConfigureAwait(false);
}
}
}

450
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs

@ -1014,8 +1014,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
/// <param name="p_InvGroupNum">发票分组</param>
/// <param name="p_parentInvBillNum">原发票号</param>
[UnitOfWork(false)]
public async Task<List<string>> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_ajdlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType)
where TDetail : SA_CAN_BASE
public async Task<List<string>> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_ajdlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, List<TEMP_NOT_SA_DETAIL> p_notlist = null)
where TDetail : SA_CAN_BASE
{
List<string> _invls = new List<string>();
var groups1 = dtos.GroupBy(p => new { p.PartCode, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV
@ -1028,7 +1028,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
Price = p.Key.Price,
BeginDate = p.Key.BeginDate,
EndDate = p.Key.EndDate
}).ToList();//汇总记录不出现重复值
var groups = dtos.GroupBy(p => new { p.PartCode, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV
{
@ -1040,30 +1039,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
ContractDocID = p.Key.ContractDocID,
BeginDate = p.Key.BeginDate,
EndDate = p.Key.EndDate
}).ToList();//汇总记录不出现重复值
//var t1 = groups1.GroupBy(p => p.LU).Select(p => new { LU = p.Key, Amt = p.Sum(itm => itm.Qty * itm.Price) }).OrderByDescending(p => p.Amt).ToList();
//var group= t1.Where(p => p.Amt > 10000000).ToList();
////var t1 = groups1.GroupBy(p => p.LU).Select(p => new { LU = p.Key, Amt = p.Sum(itm => itm.Qty * itm.Price) }).OrderByDescending(p => p.Amt).ToList();
////var t2 = groups.GroupBy(p => p.LU).Select(p => new { LU = p.Key, Amt = p.Sum(itm => itm.Qty * itm.Price) }).OrderByDescending(p => p.Amt).ToList();
////foreach (var itm in t1)
////{
////}
////foreach (var itm in t2)
////{
////}
Dictionary<string, List<TMEP_INV>> invoiceMap = new Dictionary<string, List<TMEP_INV>>();//发票和发票明细关系
foreach (var group in groups)
{
@ -1086,39 +1062,45 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
&& group.BeginDate == group1.BeginDate
&& group.EndDate == group1.EndDate
&& group1.ContractDocID == group.ContractDocID
&& group1.Price == group.Price
&& group1.Qty == group.Qty
&& group1.Amt == group.Amt
)
{
tempList.Add(group1);
partCount++;//符合条件加入到零件中
continue;
}
partCount++;
if (partCount > 30)
{
continue;
}
sum += group1.Amt;
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, itm.PartCode }
equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID, itm1.PartCode } into temp
from tm in temp
on
new { itm.LU, itm.BeginDate, itm.EndDate, itm.ContractDocID, itm.PartCode, itm.Qty, itm.Price, itm.Amt }
equals
new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID, itm1.PartCode, itm1.Qty, itm1.Price, itm1.Amt }
into temp
from tm in temp.DefaultIfEmpty()
where tm == null
select new TMEP_INV
{
LU = itm.LU,
Amt = itm.Amt,
Qty = itm.Qty,
Price = itm.Price,
BeginDate = itm.BeginDate,
ContractDocID = itm.ContractDocID,
EndDate = itm.EndDate
EndDate = itm.EndDate,
PartCode = itm.PartCode,
};
groups1 = query.ToList();
}
@ -1131,6 +1113,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
var invlist = new List<INVOICE_GRP>();
var salist = new List<TDetail>();
var adjlist = new List<PUB_ADJ_DETAIL>();
int count = invoiceMap.Keys.Count;//计算第几张发票计数器
int i = 1;
foreach (var group in invoiceMap)
{
var key = group.Key;//发票票号
@ -1138,9 +1122,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
//反向查找结算数据
var query = from itm in dtos
join itm1 in ls
on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate }
on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate, itm.ContractDocID } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID }
join itm2 in p_list on new { itm.PartCode, itm.PN, itm.SettleDate } equals new { itm2.PartCode, itm2.PN, itm2.SettleDate }
select itm2;
select itm2;//反向更新可计算数据
foreach (var itm in query)
{
itm.InvbillNum = key;
@ -1157,7 +1141,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
foreach (var itm in query1)
{
itm.InvBillNum = key;
itm.InvGroupNum = dtos.FirstOrDefault().InvGroupNum;
adjlist.Add(itm);
}
}
@ -1186,30 +1169,67 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
{
detailList.AddRange(_entityDetailList);
}
List<tempAmt1> amtList = new List<tempAmt1>();
foreach (var itm in detailList)
#region 发票不能结算的明细
var innotls = new List<INVOICE_NOT_SETTLE>();
var sq = query.GroupBy(p => new { p.LU, p.GroupNum })
.Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = group.Key, GroupNum = p.Key.GroupNum });
foreach (var sitm in sq)
{
amtList.Add(new tempAmt1()
{
Amt = itm.Amt,
Tax = Math.Round(itm.Amt * 0.13m, 2),
TaxAmt = itm.Amt + Math.Round(itm.Amt * 0.13m, 2)
});
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: group.Key
));
}
decimal amt = amtList.Sum(k => k.Amt);//金额
decimal txtAmt = amtList.Sum(k => k.TaxAmt);//税后金额
decimal readAmt = amtList.Sum(k => k.Tax);//税额
if (innotls.Count > 0)
{
notDetialList.AddRange(innotls);
}
if (p_notlist != null && p_notlist.Count > 0)
{
var innotls1 = new List<INVOICE_NOT_SETTLE>();
//decimal amt = detailList.Sum(k => k.Amt);//金额
//decimal txtAmt = detailList.Sum(k => k.Amt) + Math.Round(detailList.Sum(k => k.Amt) * 0.13m, 2);//税后金额
//decimal readAmt = Math.Round(detailList.Sum(k => k.Amt) * 0.13m, 2);//税额
var grouplist = query.Select(p => p.GroupNum).ToList();
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>();
var notlist = p_notlist.Where(p => grouplist.Contains(p.GroupNum));
foreach (var nitm in notlist)
{
innotls1.Add(new INVOICE_NOT_SETTLE(
guid: GuidGenerator.Create(),
version: p_version,
invGroupNum: p_InvGroupNum,
settleGroupNum: nitm.GroupNum,
lU: nitm.LU,
lU1: nitm.LU,
extend1: "不可结算",
extend2: string.Empty,
qty: nitm.Qty,
p_invbillnum: group.Key
));
}
if (innotls.Count > 0)
{
notDetialList.AddRange(innotls1);
}
}
#endregion
decimal amt = ls.Sum(k => k.Amt);//金额
decimal txtAmt = Math.Round(amt * 0.13m, 2);//税后金额
decimal readAmt = amt + Math.Round(amt * 0.13m, 2);//税额
//var contractList = ls.Select(p => p.ContractDocID).Distinct();
var _groupList = query.GroupBy(p => new { p.GroupNum })
.Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => Math.Round(itm.Qty * itm.Price, 2)) }).Distinct();
List<INVOICE_MAP_GROUP> group1 = new List<INVOICE_MAP_GROUP>();
foreach (var en in _groupList)
{
group1.Add(
@ -1227,7 +1247,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
{
groupList.AddRange(group1);
}
var lst = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).ToList();
string site = lst.FirstOrDefault().Site;
string clientCode = string.Empty;
@ -1244,47 +1263,310 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
break;
}
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.13m,
parent: p_parentInvBillNum,
preTaxDiff: 0,
taxDiff: 0,
clientCode: string.Empty,
realAmt: readAmt
);
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.13m,
parent: p_parentInvBillNum,
preTaxDiff: 0,
taxDiff: 0,
clientCode: string.Empty,
realAmt: readAmt
);
invbill.ClientCode = clientCode;
invbill.CreationTime = DateTime.MinValue;
invbill.Site = dtos.FirstOrDefault().Site;
invbill.LastModificationTime = DateTime.Now;
invbill.Site = dtos.FirstOrDefault().Site;
invlist.Add(invbill);
}
await _repository.DbContext.BulkInsertAsync(invlist).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(groupList).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(detailList).ConfigureAwait(false);
var dbcontxt = await _repository.GetDbContextAsync().ConfigureAwait(false);
//_dbcontext.BulkInsert(invlist);
//_dbcontext.BulkInsert(groupList);
//_dbcontext.BulkInsert(detailList);
//_dbcontext.BulkInsert(notDetialList);
//if (salist.Count > 0)
//{
// _dbcontext.BulkUpdate(salist);
//}
//if (adjlist.Count > 0)
//{
// _dbcontext.BulkUpdate(adjlist);
//}
await dbcontxt.BulkInsertAsync(invlist).ConfigureAwait(false);
await dbcontxt.BulkInsertAsync(groupList).ConfigureAwait(false);
await dbcontxt.BulkInsertAsync(detailList).ConfigureAwait(false);
await dbcontxt.BulkInsertAsync(notDetialList).ConfigureAwait(false);
if (salist.Count > 0)
{
await _repository.DbContext.BulkUpdateAsync(salist).ConfigureAwait(false);
await dbcontxt.BulkUpdateAsync(salist).ConfigureAwait(false);
}
if (adjlist.Count > 0)
{
await _repository.DbContext.BulkUpdateAsync(adjlist).ConfigureAwait(false);
await dbcontxt.BulkUpdateAsync(adjlist).ConfigureAwait(false);
}
//await _repository.DbContext.BulkInsertAsync(notDetialList);
_invls = invlist.Select(p => p.InvbillNum).ToList();
}
return _invls;
}
//public async Task<List<string>> SecInvoice<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_ajdlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType)
// where TDetail : SA_CAN_BASE
//{
// List<string> _invls = new List<string>();
// var groups1 = dtos.GroupBy(p => new { p.PartCode, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV
// {
// PartCode = p.Key.PartCode,
// 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.PartCode, p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV
// {
// PartCode = p.Key.PartCode,
// LU = p.Key.LU,
// Amt = p.Sum(itm => itm.Amt),
// Qty = p.Sum(itm => itm.Qty),
// Price = p.Key.Price,
// ContractDocID = p.Key.ContractDocID,
// 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.PartCode == group.PartCode
// && 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.PartCode == group1.PartCode
// && 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, itm.PartCode }
// equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID, itm1.PartCode } 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>();
// var salist = new List<TDetail>();
// var adjlist = new List<PUB_ADJ_DETAIL>();
// foreach (var group in invoiceMap)
// {
// var key = group.Key;//发票票号
// var ls = group.Value;//发票明细
// //反向查找结算数据
// var query = from itm in dtos
// join itm1 in ls
// on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate }
// join itm2 in p_list on new { itm.PartCode, itm.PN, itm.SettleDate } equals new { itm2.PartCode, itm2.PN, itm2.SettleDate }
// select itm2;
// foreach (var itm in query)
// {
// itm.InvbillNum = key;
// salist.Add(itm);
// }
// if (!string.IsNullOrEmpty(p_parentInvBillNum))
// {
// //反向查找调整数据
// var query1 = from itm in dtos
// join itm1 in ls
// on new { itm.LU, itm.PartCode, itm.BeginDate, itm.EndDate } equals new { itm1.LU, itm1.PartCode, itm1.BeginDate, itm1.EndDate }
// join itm2 in p_ajdlist on new { itm.PartCode, itm.PN, itm.SettleDate } equals new { itm2.PartCode, itm2.PN, itm2.SettleDate }
// select itm2;
// foreach (var itm in query1)
// {
// itm.InvBillNum = key;
// itm.InvGroupNum = dtos.FirstOrDefault().InvGroupNum;
// adjlist.Add(itm);
// }
// }
// 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: detail.ContractDocID,
// extend2: string.Empty,
// beginDate: detail.BeginDate,
// endDate: detail.EndDate,
// partcode: detail.PartCode
// ));
// }
// if (_entityDetailList.Count > 0)
// {
// detailList.AddRange(_entityDetailList);
// }
// List<tempAmt1> amtList = new List<tempAmt1>();
// foreach (var itm in detailList)
// {
// amtList.Add(new tempAmt1()
// {
// Amt = itm.Amt,
// Tax = Math.Round(itm.Amt * 0.13m, 2),
// TaxAmt = itm.Amt + Math.Round(itm.Amt * 0.13m, 2)
// });
// }
// decimal amt = amtList.Sum(k => k.Amt);//金额
// decimal txtAmt = amtList.Sum(k => k.TaxAmt);//税后金额
// decimal readAmt = amtList.Sum(k => k.Tax);//税额
// //decimal amt = detailList.Sum(k => k.Amt);//金额
// //decimal txtAmt = detailList.Sum(k => k.Amt) + Math.Round(detailList.Sum(k => k.Amt) * 0.13m, 2);//税后金额
// //decimal readAmt = Math.Round(detailList.Sum(k => k.Amt) * 0.13m, 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: 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 lst = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).ToList();
// string site = lst.FirstOrDefault().Site;
// string clientCode = string.Empty;
// switch (site)
// {
// case "1040":
// clientCode = "C001";
// break;
// case "1046":
// clientCode = "C171";
// break;
// default:
// clientCode = "C004";
// break;
// }
// 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.13m,
// parent: p_parentInvBillNum,
// preTaxDiff: 0,
// taxDiff: 0,
// clientCode: string.Empty,
// realAmt: readAmt
// );
// invbill.ClientCode = clientCode;
// invbill.CreationTime = DateTime.MinValue;
// invbill.Site = dtos.FirstOrDefault().Site;
// invbill.LastModificationTime = DateTime.Now;
// invlist.Add(invbill);
// }
// await _repository.DbContext.BulkInsertAsync(invlist).ConfigureAwait(false);
// await _repository.DbContext.BulkInsertAsync(groupList).ConfigureAwait(false);
// await _repository.DbContext.BulkInsertAsync(detailList).ConfigureAwait(false);
// if (salist.Count > 0)
// {
// await _repository.DbContext.BulkUpdateAsync(salist).ConfigureAwait(false);
// }
// if (adjlist.Count > 0)
// {
// await _repository.DbContext.BulkUpdateAsync(adjlist).ConfigureAwait(false);
// }
// //await _repository.DbContext.BulkInsertAsync(notDetialList);
// _invls = invlist.Select(p => p.InvbillNum).ToList();
// }
// return _invls;
//}
[UnitOfWork(false)]
public async Task<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

49
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_NOT_SA_MNG.cs

@ -69,6 +69,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
List<string> errors = new List<string>();
var entityList = new List<PUB_CAN_SA_DETAIL>();
var notList = new List<PUB_NOT_SA_DETAIL>();
var deletenotList = new List<PUB_NOT_SA_DETAIL>();
var billList = new List<PUB_CAN_SA>();
List<PUB_CAN_SA_DETAIL> billDetails = new List<PUB_CAN_SA_DETAIL>();
var query = p_list.Select(p => p.BusinessType).Distinct().ToList();
@ -104,10 +105,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
{
priceList = _priceRepository.Where(p => p.IsCancel == false).ToList();//价格单
}
if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.YinDuJian)
{
var ls = p_list.Select(p => p.GroupNum).Distinct().ToList();
var notlist = _notRepository.Where(p => ls.Contains(p.GroupNum) && p.BusinessType==first.BusinessType).ToList();//JIT_ASN整发
var notlist = _notRepository.Where(p => ls.Contains(p.GroupNum) && p.BusinessType==first.BusinessType).AsNoTracking().ToList();//JIT_ASN整发
if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC)
{
var subqueryA = (from a in notlist
@ -146,12 +149,35 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
})
on new { tmp1.GroupNum, tmp1.SettleBillNum } equals new { tmp2.GroupNum, tmp2.SettleBillNum }
select tmp1;//不可结
var jit1 = result.Where(p => p.Site == "1040").ToList();
var jit2 = result.Where(p => p.Site == "1046").ToList();
List<PriceList> priceLists = new List<PriceList>();
foreach (var itm in notlist)
{
var priceListEntity = priceList.Where(p => p.IsCancel == false)
.Where(t => t.LU == itm.LU)
.Where(t => itm.SettleDate >= t.BeginTime && itm.SettleDate <= t.EndTime && t.ClientCode == itm.Site)
.OrderByDescending(t => t.Date)
.ThenByDescending(t => t.CreationTime)
.FirstOrDefault();
if (priceListEntity != null)
{
itm.Price = priceListEntity.Price;
}
else
{
itm.Price = 0;
}
}
var result1 = notlist.Where(p=>p.Price!=0);
var jit1 = result1.Where(p => p.Site == "1040").ToList();
var jit2 = result1.Where(p => p.Site == "1046").ToList();
var jit3 = result.Where(p => p.Site == "1041").ToList();
if (jit1.Count > 0)
{
notlist.AddRange(jit1);
deletenotList.AddRange(jit1);
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N");
var entity = new PUB_CAN_SA();
entity.SetId(Guid.NewGuid());
@ -175,7 +201,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == first.Site).Price,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "1040").Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
@ -191,7 +217,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
}
if (jit2.Count > 0)
{
notlist.AddRange(jit2);
deletenotList.AddRange(jit2);
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N");
var entity = new PUB_CAN_SA();
entity.SetId(Guid.NewGuid());
@ -215,7 +241,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == first.Site).Price,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "1046").Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
@ -231,7 +257,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
}
if (jit3.Count > 0)
{
notlist.AddRange(jit3);
deletenotList.AddRange(jit3);
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N");
var entity = new PUB_CAN_SA();
entity.SetId(Guid.NewGuid());
@ -255,7 +281,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == first.Site).Price,
price: priceList.FirstOrDefault(p => itm.SettleDate >= p.BeginTime && itm.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == "1041").Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
@ -269,7 +295,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
entityList.Add(detailEntity);
}
}
await _repository.DbContext.BulkDeleteAsync(notlist).ConfigureAwait(false);
await _repository.DbContext.BulkDeleteAsync(deletenotList).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(billList).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(entityList).ConfigureAwait(false);
}
@ -430,6 +456,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
}
}
await _repository.DbContext.BulkDeleteAsync(notList).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(billList).ConfigureAwait(false);
await _repository.DbContext.BulkInsertAsync(entityList).ConfigureAwait(false);

Loading…
Cancel
Save