From 8184215bbaf5db857ccbc2eb601ac2f1e3f21b6e Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Thu, 11 Jul 2024 15:19:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BQ/Syncs/GenerateJisInvoiceService.cs | 320 ++++++++++++++++-- .../Entities/BQ/VmiAppService.cs | 6 +- 2 files changed, 293 insertions(+), 33 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs index f4eb5c6b..7c028fc3 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs @@ -1215,13 +1215,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs public List FirstInvoiceExtend1(List p_list, List p_adjlist, List dtos, List p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) where TDetail : SA_CAN_BASE, new() { - //var gener = new InvoiceGeneratorSame(); - //var list =p_list.OrderBy(p => p.LU).ThenBy(p=>p.PartCode).ToList(); - //gener.GenerateInvoices(p_list); - //var invList = gener.Invoices; + - - var detailDtos = dtos.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细 + var groupDtos = dtos.GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细 .Select(itm => new GroupPartCode { PartCode = itm.Key.PartCode, @@ -1237,10 +1233,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs EndDate = itm.Key.EndDate }).ToList(); - List biglist = new List(); List smalllist = new List(); - foreach (var itm in detailDtos) + foreach (var itm in groupDtos)//分类1000W以上或1000W以下 { if (itm.Amt > 10000000) { @@ -1251,18 +1246,281 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs smalllist.Add(itm); } } + var groupList = new List(); + var notDetialList = new List(); + var detailList = new List(); + var invlist = new List(); + var salist = new List(); + var adjlist = new List(); + + + - foreach (var itm in biglist) + foreach (var big in biglist)//单条大于1000W的开票 { - var list = p_list.Where(p => p.InvGroupNum == itm.InvGroupNum && p.PartCode == itm.PartCode && p.Price == itm.Price && p.LU == itm.LU); - var gener = new InvoiceGeneratorSame(); + 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(); gener.GenerateInvoices(p_list); - var invList = gener.Invoices; + var invList = gener.Invoices; + foreach (var inv in invList) + { + var partlist = inv.Parts; + if (partlist.Count > 0) + { + var query = from itm in p_list + 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(); + 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); + } + + + + #region 发票明细 + List _entityDetailList = new List(); + 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 + } + } } 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(); + + 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(); + 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); + } + + List _entityDetailList = new List(); + 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); + } + _dbcontext.BulkInsert(invlist); + _dbcontext.BulkInsert(groupList); + _dbcontext.BulkInsert(detailList); + if (adjlist.Count > 0) + { + _dbcontext.BulkInsert(adjlist); + } + if (notDetialList.Count > 0) + { + _dbcontext.BulkInsert(notDetialList); + } + + + + + + + + + + @@ -1402,47 +1660,47 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } - public class InvoiceBySame + public class InvoiceBySame where T : SA_CAN_BASE, new() { public string InvBillNum { set; get; } public InvoiceBySame() { } - private List parts = new List(); - public IReadOnlyList Parts => parts.AsReadOnly(); + private List parts = new List(); + public IReadOnlyList Parts => parts.AsReadOnly(); public decimal TotalAmount => parts.Sum(p => p.Price); - public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); - public bool CanAddPart(SA_CAN_BASE part) + // public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); + public bool CanAddPart(T part) { - return TotalAmount + part.Price <= 10000000 && PartCount < 15; ; + return TotalAmount + part.Price <= 10000000 ; } - public void AddPart(SA_CAN_BASE part) + public void AddPart(T part) { if (CanAddPart(part)) { part.InvbillNum = InvBillNum; parts.Add(part); - //throw new InvalidOperationException("Cannot add part to invoice. Check constraints."); + } } } - public class InvoiceGeneratorSame + public class InvoiceGeneratorSame where T : SA_CAN_BASE, new() { - private List invoices = new List(); + private List> invoices = new List>(); - public IReadOnlyList Invoices => invoices.AsReadOnly(); + public IReadOnlyList> Invoices => invoices.AsReadOnly(); - public void GenerateInvoices(List parts) where TDetail : SA_CAN_BASE, new() + public void GenerateInvoices(List parts) { - InvoiceBySame currentInvoice = new InvoiceBySame(); + InvoiceBySame currentInvoice = new InvoiceBySame(); invoices.Add(currentInvoice); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); foreach (var part in parts) { if (!currentInvoice.CanAddPart(part)) { - currentInvoice = new InvoiceBySame(); + currentInvoice = new InvoiceBySame(); currentInvoice.InvBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); invoices.Add(currentInvoice); } @@ -1453,7 +1711,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs { } - public InvoiceGeneratorSame(List invoices) + public InvoiceGeneratorSame(List> invoices) { this.invoices = invoices; } @@ -1466,18 +1724,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs private List parts = new List(); public IReadOnlyList Parts => parts.AsReadOnly(); public decimal TotalAmount => parts.Sum(p => p.Amt); - // public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); + public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count(); public bool CanAddPart(GroupPartCode part) { - return TotalAmount + part.Amt <= 10000000; + return TotalAmount + part.Amt < 10000000 && PartCount<15; } public void AddPart(GroupPartCode part) { if (CanAddPart(part)) { - //part.InvbillNum = InvBillNum; + parts.Add(part); - //throw new InvalidOperationException("Cannot add part to invoice. Check constraints."); + } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs index 6e25f3d9..d3a3a7c7 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs @@ -1571,8 +1571,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ "isnull([200],0) CANQty,\n" + "isnull([800],0) NOTQty,\n" + "case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)=0 then ISNULL([100],0)\n" + + "when ISNULL([10], 0) + isnull([20], 0) + isnull([100], 0) + ISNULL([150], 0) - ISNULL([200], 0) = ISNULL([10], 0) + isnull([20], 0) + isnull([100], 0) + ISNULL([150], 0) then 0\n"+ "ELSE 0 END SE_SA_CAN_QTY,\n" + "case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([800],0)=0 then ISNULL([100],0)\n" + + "when ISNULL([10], 0) + isnull([20], 0) + isnull([100], 0) + ISNULL([150], 0) - ISNULL([800], 0) = ISNULL([10], 0) + isnull([20], 0) + isnull([100], 0) + ISNULL([150], 0) then 0\n"+ "ELSE 0 END SE_SA_NOT_QTY,\n" + "case when ISNULL([10],0)+isnull([20],0)+isnull([100],0)+ISNULL([150],0)-ISNULL([200],0)-ISNULL([800],0)>0 then ISNULL([100],0)\n" + "ElSE 0 END SE_SA_DIFF_QTY,\n" + @@ -1674,7 +1676,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ "SUM(qty)\n" + "FOR Type IN ([10],[20],[100],[150],[200],[800])\n" + ") AS piv\n" + - $") temp1 left join (select LU,PN,PartCode,InvbillNum,Qty from {satablename} WITH(NOLOCK) where BusinessType={(int)p_businessType}"; + $") temp1 left join (select LU,PN,PartCode,'已存在' InvbillNum,Sum(qty) qty from {satablename} WITH(NOLOCK) where BusinessType={(int)p_businessType} "; if (!string.IsNullOrEmpty(sabegin)) { @@ -1688,7 +1690,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } - sql += ") temp2 on temp1.PN=temp2.PN and temp1.LU=temp2.LU\n"; + sql += " AND InvbillNum like 'INV%' GROUP BY LU,PN ,PartCode ) temp2 on temp1.PN=temp2.PN and temp1.LU=temp2.LU\n"; sql += $" left join (SELECT MAX(BillTime) BillTime, Max(FactoryPartCode) PartCode, LU FROM {setablename} WHERE BusinessType = {(int)p_businessType} GROUP BY LU) temp3 on temp1.LU = temp3.LU";