From 9e594a87e1c83755ed817b2dfd16177443bb7024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Thu, 14 Sep 2023 15:46:14 +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 --- .../Entities/BQ/Dtos/INVOICE_GRP_DTO.cs | 23 +- .../Bases/CAN_SA_SERVICE.cs | 13 +- .../Entities/BQ/BBAC_BA_SERVICE.cs | 23 +- .../Entities/BQ/BBAC_CAN_SA_SERVICE.cs | 10 +- .../Entities/BQ/HBPO_BA_SERVICE.cs | 196 ++++++++---------- .../Entities/BQ/HBPO_CAN_SA_SERVICE.cs | 4 +- .../Entities/BQ/INVOICE_SERVICE.cs | 193 ++++++----------- .../Entities/BQ/PUB_CAN_SA_SERVICE.cs | 32 ++- .../Entities/BQ/Managers/INV_MNG.cs | 124 ++++------- 9 files changed, 267 insertions(+), 351 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs index e26b4a18..c2eb6c63 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/INVOICE_GRP_DTO.cs @@ -263,7 +263,24 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public List ADJ_DETAIL { get; set; } - + /// + /// 全部未结明细 + /// + public List UNSETTLED_DETAIL { get; set; } + + + + + + } + public class UNSETTLED_DETAIL_DTO + { + + public string GroupNum { set; get; } + public string LU { set; get; } + + public decimal Qty { set; get; } + } @@ -279,8 +296,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public int Version { get; set; } [Display(Name = "金税发票号")] public string RealInvbillNum { get; set; } - - [Display(Name = "发票日期")] public DateTime? InvDate { set; get; } @@ -556,8 +571,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos [Display(Name = "发票日期")] public DateTime? InvDate { set; get; } - - /// ///发票号 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs index 6467f925..78d11d5b 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/CAN_SA_SERVICE.cs @@ -89,6 +89,11 @@ namespace Win.Sfs.SettleAccount.Bases return new PagedResultDto(totalCount, dtos); } + + + + + /// /// 导出 /// @@ -227,13 +232,13 @@ namespace Win.Sfs.SettleAccount.Bases invlist = await _invmng.MakeInvoice(p_list, p_adjlist, dtos, p_version, p_invGroupNum, string.Empty, businessType, true); break; case EnumBusinessType.ZhiGongJianBBAC: - invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, new List(), p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 + invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, p_notlist, p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 break; case EnumBusinessType.ZhiGongJianHBPO: - invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, new List(), p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 + invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, p_notlist, p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 break; case EnumBusinessType.BeiJian: - invlist = await _invmng.BJInvoice(p_list, p_adjlist, dtos, new List(), p_version, p_invGroupNum, string.Empty, businessType, true); + invlist = await _invmng.BJInvoice(p_list, p_adjlist, dtos, p_notlist, p_version, p_invGroupNum, string.Empty, businessType, true); break; case EnumBusinessType.JisBBAC: invlist = await _invmng.FirstInvoice(p_list, p_adjlist, dtos,p_notlist , p_version, p_invGroupNum, string.Empty, businessType);//重开可以变多张发票 @@ -242,7 +247,7 @@ namespace Win.Sfs.SettleAccount.Bases invlist = await _invmng.FirstInvoice(p_list, p_adjlist, dtos,p_notlist, p_version, p_invGroupNum, string.Empty, businessType);//重开可以变多张发票 break; case EnumBusinessType.YinDuJian: - invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, new List(), p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 + invlist = await _invmng.JITInvoice(p_list, p_adjlist, dtos, p_notlist, p_version, p_invGroupNum, string.Empty, businessType, true);//重开可以变多张发票 break; } if (invlist.Count > 0) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs index 00ba8d47..512bc3c0 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs @@ -43,10 +43,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { private readonly INormalEfCoreRepository _priceRepository; - private readonly ADJ_SERVICE _adjservice; - - public BBAC_BA_SERVICE(IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, @@ -64,8 +61,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ BaseDomainService baseservice, INormalEfCoreRepository priceRepository, ADJ_SERVICE adjservice - - ) : base( excelImportService, snowflakeIdGenerator, @@ -95,11 +90,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// public override async Task ReissueInvoice([FromBody] string p_invbillnum) { - //var mappingList= await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 - //if (mappingList != null && mappingList.Count() > 0) - //{ + var version = int.Parse(DateTime.Now.ToString("yyyymm")); - //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 + var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum); var settle = await _bbacMng.GetMainAsync(inv.InvGroupNum); @@ -107,7 +100,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ if (settle == null) { throw new UserFriendlyException($"选择发票:{p_invbillnum}对应的可结算单不在请检查!","400"); - } version = settle.Version; if (inv != null) @@ -126,7 +118,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { foreach (var itm in adjlist) { - var entity = new BBAC_CAN_SA_DETAIL( guid: itm.Id, keyCode: itm.KeyCode, @@ -153,6 +144,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据 var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); + + //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); //var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算 var priceList = _priceRepository.Where(p=>p.IsCancel==false).ToList();//价格单 @@ -162,9 +155,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType); if (errorList.Count() > 0) { - return new JsonResult(new { Code = ApplicationConsts.ImportFailCode,Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList) }); - } var dto1s = ObjectMapper.Map, List>(entitys); var q = from d in dto1s @@ -478,10 +469,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } var als= invBilllist.Where(p => string.IsNullOrEmpty(p.PartCode)).ToList(); - - - var invlist=invBilllist.OrderBy(p => p.PartCode).ToList(); - return new JsonResult(new { Code = 200, Data= invlist }); + var invlist=invBilllist.OrderBy(p => p.PartCode).ToList(); + return new JsonResult(new { Code = 200, Data= invlist }); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs index a323f932..50358f32 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs @@ -32,6 +32,7 @@ using Volo.Abp; using Win.Sfs.SettleAccount.Entities.BQ.Temp; using Volo.Abp.Uow; using Win.Sfs.SettleAccount.Bases.DomainServices; +using LinqToDB; namespace Win.Sfs.SettleAccount.Entities.BQ { @@ -82,7 +83,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// /// /// - [UnitOfWork(false)] + [UnitOfWork(false)] [HttpPost] public async Task GenerateInvoice([FromBody] string invbillNum) @@ -106,8 +107,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ if (await _bbacMng.SetForwardState(main, SettleBillState.已开票)) { var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); - var notQuery = _notRepository.Where(p => groupNumList.Contains(p.GroupNum)).ToList();//不能结算 + + + var notQuery =await _notRepository.Where(p => p.SettleBillNum == main.SettleBillNum).ToListAsync(); + + var dto1s = ObjectMapper.Map, List>(entitys); var q = from d in dto1s join p in priceList on d.LU equals p.LU diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs index 9fe32c0f..9a057873 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs @@ -48,13 +48,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _priceRepository= priceRepository; _adjservice = adjservice; } - - - - - - - /// /// 发票重开 /// @@ -65,106 +58,103 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 //if (mappingList != null && mappingList.Count() > 0) //{ - var version = int.Parse(DateTime.Now.ToString("yyyymm")); - //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 - var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum); - var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum); - if (settle == null) + var version = int.Parse(DateTime.Now.ToString("yyyymm")); + //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 + var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum); + var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum); + if (settle == null) + { + throw new UserFriendlyException($"选择发票:{p_invbillnum}对应的可结算单不存在请检查!", "400"); + } + version = settle.Version; + if (inv != null) + { + if (inv.InvoiceState == InvoiceBillState.报废) { - throw new UserFriendlyException( $"选择发票:{p_invbillnum}对应的可结算单不存在请检查!","400"); + throw new UserFriendlyException($"选择发票:{p_invbillnum}状态为报废状态不能重开!", "400"); } - version = settle.Version; - if (inv != null) + if (inv.State == SettleBillState.商务已审核 || inv.State == SettleBillState.已开票) { - if (inv.InvoiceState == InvoiceBillState.报废) - { - throw new UserFriendlyException( $"选择发票:{p_invbillnum}状态为报废状态不能重开!", "400"); - } - if (inv.State == SettleBillState.商务已审核 || inv.State == SettleBillState.已开票) + throw new UserFriendlyException($"选择发票:{p_invbillnum}状态在财务审核后可以报废重开,之前请退回重开!", "400"); + } + var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件 + var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 + if (adjlist != null && adjlist.Count > 0) + { + foreach (var itm in adjlist) { - throw new UserFriendlyException( $"选择发票:{p_invbillnum}状态在财务审核后可以报废重开,之前请退回重开!", "400"); + hbpolist.Add(new HBPO_CAN_SA_DETAIL( + guid: GuidGenerator.Create(), + keyCode: itm.KeyCode, + version: itm.Version, + billNum: itm.InvGroupNum, + settleBillNum: itm.SettleBillNum, + lU: itm.LU, + pN: itm.PN, + site: itm.Site, + qty: itm.Qty, + price: itm.Price, + businessType: itm.BusinessType, + settleDate: itm.SettleDate, + groupNum: itm.GroupNum, + invGroupNum: itm.InvGroupNum, + invbillnum: string.Empty, + partcode: itm.PartCode + )); } - var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件 - var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 - if (adjlist != null && adjlist.Count > 0) - { - foreach (var itm in adjlist) + } + var entitys = hbpolist;//合并库存调整单和就发票可结算明细数据 + var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); + //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); + //var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算 + var priceList = _priceRepository.ToList();//价格单 + var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType); + if (errorList.Count() > 0) + { + return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList) }); + } + // var dto1s = ObjectMapper.Map, List>(entitys); + var q = from d in entitys + join p in priceList on d.LU equals p.LU + where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime + select new TEMP_CAN_SA_DETAIL { - hbpolist.Add(new HBPO_CAN_SA_DETAIL( - guid: GuidGenerator.Create(), - keyCode: itm.KeyCode, - version: itm.Version, - billNum: itm.InvGroupNum, - settleBillNum: itm.SettleBillNum, - lU: itm.LU, - pN: itm.PN, - site: itm.Site, - qty: itm.Qty, - price: itm.Price, - businessType: itm.BusinessType, - settleDate: itm.SettleDate, - groupNum: itm.GroupNum, - invGroupNum: itm.InvGroupNum, - invbillnum: string.Empty, - partcode:itm.PartCode - )); - } - } - var entitys = hbpolist;//合并库存调整单和就发票可结算明细数据 - var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); - //var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算 - var priceList = _priceRepository.ToList();//价格单 - var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType); - if (errorList.Count() > 0) + SettleBillNum = d.SettleBillNum, + Site = d.Site, + Version = d.Version, + Price = p.Price, + BillNum = d.BillNum, + SettleDate = d.SettleDate, + InvGroupNum = d.InvGroupNum, + LU = d.LU, + // MaterialDesc = d.MaterialDesc, + PN = d.PN, + Qty = d.Qty, + GroupNum = d.GroupNum, + Amt = Math.Round(d.Qty * p.Price, 2), + ContractDocID = "n", + BeginDate = p.BeginTime, + EndDate = p.EndTime, + PartCode = d.PartCode + }; + var dtos = q.ToList(); + if (dtos != null && dtos.Count > 0) + { + if (p_invbillnum.Substring(0, 3) == "INV")//一次开票重开 { + await ReissueFirstInvoice(hbpolist, adjlist, dtos, version, p_invbillnum); - return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList) }); - - ; } - // var dto1s = ObjectMapper.Map, List>(entitys); - var q = from d in entitys - join p in priceList on d.LU equals p.LU - where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime - select new TEMP_CAN_SA_DETAIL - { - SettleBillNum = d.SettleBillNum, - Site = d.Site, - Version = d.Version, - Price = p.Price, - BillNum = d.BillNum, - SettleDate = d.SettleDate, - InvGroupNum = d.InvGroupNum, - LU = d.LU, - // MaterialDesc = d.MaterialDesc, - PN = d.PN, - Qty = d.Qty, - GroupNum = d.GroupNum, - Amt = Math.Round(d.Qty * p.Price, 2), - ContractDocID = "n", - BeginDate = p.BeginTime, - EndDate = p.EndTime, - PartCode=d.PartCode - }; - var dtos = q.ToList(); - if (dtos != null && dtos.Count > 0) + else//二次开票 { - if (p_invbillnum.Substring(0, 3) == "INV")//一次开票重开 - { - await ReissueFirstInvoice(hbpolist,adjlist ,dtos, version, p_invbillnum); - - } - else//二次开票 - { - await ReissueSecInvoice(hbpolist,adjlist ,dtos, version, p_invbillnum); - } + await ReissueSecInvoice(hbpolist, adjlist, dtos, version, p_invbillnum); } } - else - { - throw new UserFriendlyException( $"不存发票号为:{p_invbillnum}发票", "400"); - } + } + else + { + throw new UserFriendlyException($"不存发票号为:{p_invbillnum}发票", "400"); + } //} //else //{ @@ -195,8 +185,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } var first = p_list.FirstOrDefault(); var invbillnum = first.InvBillNum; - - //var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 //if (mappingList != null && mappingList.Count() > 0) //{ @@ -314,7 +302,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ /// public virtual async Task ReissueInvoiceList(List p_list) { - var result = await _adjservice.CheckImport(p_list); if (result != "OK") { @@ -328,16 +315,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } var first = p_list.FirstOrDefault(); var invbillnum = first.InvBillNum; - - //var mappingList = await GetMapGroupAsync(invbillnum);//发票对应结算分组 - //if (mappingList != null && mappingList.Count() > 0) - //{ + var version = int.Parse(DateTime.Now.ToString("yyyymm")); - //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 + var inv = await GetInvoiceGroupByInvBillNum(invbillnum); - var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum); - if (settle == null) { throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不在请检查!", "400"); @@ -353,9 +335,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前请退回重开!", "400"); } - - var bbaclist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件 - //var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 + var bbaclist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件 //var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 if (adjlist != null && adjlist.Count() > 0) { foreach (var itm in adjlist) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs index 88a49041..ae2eee1a 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_CAN_SA_SERVICE.cs @@ -96,12 +96,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList) }); } - if (await _hbpoMng.SetForwardState(main, SettleBillState.已开票)) { - var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - var notQuery = _notRepository.Where(p => groupNumList.Contains(p.GroupNum)).ToList(); + var notQuery = _notRepository.Where(p =>p.SettleBillNum==main.SettleBillNum).ToList(); var dto1s = ObjectMapper.Map, List>(entitys); var q = from d in dto1s join p in priceList on d.LU equals p.LU diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs index 59f3b0aa..8929c24d 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/INVOICE_SERVICE.cs @@ -1,6 +1,7 @@ using CodeArts.Db; using DocumentFormat.OpenXml.Bibliography; using DocumentFormat.OpenXml.Drawing.Diagrams; +using DocumentFormat.OpenXml.Office.Drawing; using DocumentFormat.OpenXml.Spreadsheet; using DocumentFormat.OpenXml.Wordprocessing; using EFCore.BulkExtensions; @@ -13,6 +14,7 @@ using Microsoft.AspNetCore.Mvc; using NPOI.HPSF; using SettleAccount.Domain.BQ; using Shouldly; +using SqlSugar; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -161,13 +163,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var invs = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); var mdtos = ObjectMapper.Map, List>(m); + var first = invs.FirstOrDefault(); + + + if (invs.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) { var A = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); var AMap = ObjectMapper.Map, List>(A); var wquery = from itm in AMap join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum - join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp + join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp from tm in temp.DefaultIfEmpty() select new INVOICE_WAIT_DETAIL_BBAC_DTO() @@ -198,7 +204,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var wquery = from itm in BMap join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp - from tm in temp.DefaultIfEmpty() + from tm in temp.DefaultIfEmpty() select new INVOICE_WAIT_DETAIL_BJ_DTO() { @@ -249,17 +255,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ BeginDate = itm.BeginDate, EndDate = itm.EndDate, }; - - - - - entity.INVOICE_WAIT_DETAIL= wquery.OrderBy(p=>p.LU).ToList(); + entity.INVOICE_WAIT_DETAIL = wquery.OrderBy(p => p.LU).ToList(); } - var s = await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount); - var sdtos = ObjectMapper.Map, List>(s); - var adjs =await _adjRepository.GetListByFilterAsync(input.Filters); - var adjdtos = ObjectMapper.Map, List>(adjs); + var sdtos = ObjectMapper.Map, List>(s);//不可结 + var adjs = await _adjRepository.GetListByFilterAsync(input.Filters);//调整数据 + var adjdtos = ObjectMapper.Map, List>(adjs);//调整数据DTO + var notquery = from itm in sdtos join itm1 in invs on itm.InvBillNum equals itm1.InvbillNum select @@ -274,8 +276,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Qty = itm.Qty, Extend1 = itm.Extend1, }; - - var mquery = from itm in mdtos join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum select @@ -304,12 +304,32 @@ namespace Win.Sfs.SettleAccount.Entities.BQ Price = itm.Price }; - entity.INVOICE_NOT_SETTLE = notquery.ToList(); - entity.INVOICE_MAP_GROUP = mquery.ToList(); - entity.ADJ_DETAIL = adjQuery.ToList(); - return entity; + entity.INVOICE_NOT_SETTLE = notquery.OrderBy(p=>p.SettleGroupNum).ThenBy(p=>p.LU).ToList(); + + var lscompare = entity.INVOICE_NOT_SETTLE.GroupBy(x => new { x.InvBillNum, x.SettleGroupNum }).Select(p => + new INVOICE_MAP_GROUP_DTO() + { + InvbillNum = p.FirstOrDefault().InvBillNum, + InvGroupNum = p.FirstOrDefault().InvGroupNum, + RealInvBillNum = p.FirstOrDefault().RealInvBillNum, + InvDate = p.FirstOrDefault().InvDate, + SettleGroupNum = p.FirstOrDefault().SettleGroupNum, + } + ); + + var all= entity.INVOICE_NOT_SETTLE.Select(p => p.SettleGroupNum).Distinct().ToList();//全部分组号 + var part = mquery.ToList().Select(p => p.SettleGroupNum).Distinct().ToList();//发票对应分组号 + var unsettled= all.Where(p => !part.Contains(p));//排除发票对应分组号,都为不可结 + var unsettledList= entity.INVOICE_NOT_SETTLE.Where(p => unsettled.Contains(p.SettleGroupNum)) + .GroupBy(p => new { p.LU, p.SettleGroupNum }) + .Select(p => new UNSETTLED_DETAIL_DTO { LU = p.Key.LU, GroupNum = p.Key.SettleGroupNum, Qty = p.Sum(itm => itm.Qty.Value) }); + entity.UNSETTLED_DETAIL = unsettledList.ToList().OrderBy(p=>p.GroupNum).ThenBy(p=>p.LU).ToList(); + + entity.INVOICE_MAP_GROUP = lscompare.ToList().OrderBy(p => p.SettleGroupNum).ToList();//包含不可结结算分组号 + entity.ADJ_DETAIL = adjQuery.ToList().OrderBy(p=>p.GroupNum).ThenBy(p=>p.LU).ToList(); + return entity; } [HttpPost] public virtual async Task ExportAsync(INVOICE_GRP_REQ_DTO input) @@ -350,9 +370,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return _fileName; } - - - /// /// 导出发票组明细 /// @@ -363,26 +380,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { IExporter _csv = new CsvExporter(); ExcelExporter _excel = new ExcelExporter(); - var materialList = await _baseservice.GetMaterialList(); - var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); - var first=entities.FirstOrDefault(); - var dtoDetails = ObjectMapper.Map, List>(entities); var invdetail= await DetailQueryAsync(input); var m = invdetail.INVOICE_MAP_GROUP; - var not=invdetail.INVOICE_NOT_SETTLE; - var detail =invdetail.INVOICE_WAIT_DETAIL; - var adj = invdetail.ADJ_DETAIL; - var bbac = invdetail.INVOICE_WAIT_DETAIL_BBAC; - var bj = invdetail.INVOICE_WAIT_DETAIL_BJ; + var not=invdetail.INVOICE_NOT_SETTLE;//零件结算对应关系 + var detail =invdetail.INVOICE_WAIT_DETAIL;//常规明细 + var adj = invdetail.ADJ_DETAIL;//调整表 + var bbac = invdetail.INVOICE_WAIT_DETAIL_BBAC;//BBACJIS明细 + var bj = invdetail.INVOICE_WAIT_DETAIL_BJ;//备件明细 + var unsettle = invdetail.UNSETTLED_DETAIL;//未结明细 + + var classDisplayName = typeof(INVOICE_GRP_DTO).GetCustomAttribute()?.Name ?? typeof(INVOICE_GRP_DTO).Name; string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx"; + + //发票明细 if (entities.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) { - _excel.Append(bbac, "发票明细"); } else if (entities.FirstOrDefault().BusinessType == EnumBusinessType.BeiJian) @@ -393,6 +410,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { _excel.Append(detail, "发票明细"); } + _excel.Append(m, "发票结算分组对应");//发票分组对应结算号 + if (first.BusinessType == EnumBusinessType.ZhiGongJianBBAC || first.BusinessType == EnumBusinessType.ZhiGongJianHBPO) + { + _excel.Append(unsettle, "未结零件分组汇总"); + } foreach (var itm in entities) { var mgroup =m.Where(p => p.InvbillNum == itm.InvbillNum).ToList(); @@ -412,11 +434,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ RealInvBillNum =p.Key.RealInvBillNum, InvDate =p.Key.InvDate, InvBillNum =p.Key.InvBillNum, + InvGroupNum =p.Key.InvGroupNum, Qty=p.Sum(itm=>itm.Qty) - }).ToList(); - + }).ToList(); var lsN = nolist.Where(p => p.Extend1 == "不可结算").ToList() .GroupBy(p => new { @@ -435,8 +457,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ InvGroupNum = p.Key.InvGroupNum, Qty = p.Sum(itm => itm.Qty) }).ToList(); - - var lineC = lsC.Count; var lineN = lsN.Count; List ls = new List(); @@ -456,10 +476,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ ls.Add(invnot); } var entity= nolist.FirstOrDefault(); - var disList = mgroup.Select(p => p.SettleGroupNum).Distinct().ToList(); - - - for (int i = 0; i < lineC; i++) + var disList = mgroup.Select(p => p.SettleGroupNum).Distinct().ToList(); + for (int i = 0; i < lineC; i++)//更新可结信息 { ls[i].RealInvBillNum = entity.RealInvBillNum; ls[i].InvDate = entity.InvDate; @@ -469,110 +487,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ ls[i].SettleLU = lsC[i].LU; ls[i].SettleQty = lsC[i].Qty == null ? string.Empty : lsC[i].Qty.ToString(); } - for (int i = 0; i < lineN; i++) + for (int i = 0; i < lineN; i++)//更新不可结信息 { ls[i].RealInvBillNum = entity.RealInvBillNum; ls[i].InvDate = entity.InvDate; ls[i].InvBillNum = entity.InvBillNum; ls[i].InvGroupNum = entity.InvGroupNum; - // ls[i].SettleGroupNum = entity.SettleGroupNum; + // ls[i].SettleGroupNum = entity.SettleGroupNum; ls[i].NotSettleLU = lsN[i].LU; ls[i].Qty = lsN[i].Qty == null ? string.Empty : lsN[i].Qty.ToString(); } - - for (int i = 0; i < disList.Count; i++) + for (int i = 0; i < disList.Count; i++)//更新结算分组 { ls[i].SettleGroupNum = disList[i]; } + if (first.BusinessType == EnumBusinessType.JisBBAC || first.BusinessType == EnumBusinessType.JisHBPO) + { + _excel.Append(ls, "结算分组零件" + itm.InvbillNum); + } - - - - //if (lineC > lineN)//可结大于不可结行数时 - //{ - // for (int number = 0; number < lineC; number++) - // { - // if (number + 1 > lineN) - // { - // INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO(); - // entity.RealInvBillNum = lsC[number].RealInvBillNum; - // entity.InvDate = lsC[number].InvDate; - // entity.InvBillNum = lsC[number].InvBillNum; - // entity.InvGroupNum = lsC[number].InvGroupNum; - // entity.SettleGroupNum = lsC[number].SettleGroupNum; - // entity.SettleLU = lsC[number].LU; - // entity.SettleQty = lsC[number].Qty == null ? string.Empty : lsC[number].Qty.ToString(); - // entity.NotSettleLU = string.Empty; - // entity.Qty = string.Empty; - // ls.Add(entity); - - // } - // else - // { - // INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO(); - // entity.RealInvBillNum = lsC[number].RealInvBillNum; - // entity.InvDate = lsC[number].InvDate; - // entity.InvBillNum = lsC[number].InvBillNum; - // entity.InvGroupNum = lsC[number].InvGroupNum; - // entity.SettleGroupNum = lsC[number].SettleGroupNum; - // entity.SettleLU = lsC[number].LU; - // entity.SettleQty= lsC[number].Qty==null?string.Empty:lsC[number].Qty.ToString(); - // entity.NotSettleLU = lsN[number].LU; - // entity.Qty = lsN[number].Qty == null ? string.Empty : lsC[number].Qty.ToString(); - // ls.Add(entity); - // } - // } - //} - //else - //{ - // for (int number = 0; number < lineN; number++) - // { - // if (number + 1 > lineC)//不可结大于可结行数时 - // { - // INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO(); - // entity.RealInvBillNum = lsN[number].RealInvBillNum; - // entity.InvDate = lsN[number].InvDate; - // entity.InvBillNum = lsN[number].InvBillNum; - // entity.InvGroupNum = lsN[number].InvGroupNum; - // entity.SettleGroupNum = lsN[number].SettleGroupNum; - // entity.SettleLU = string.Empty; - // entity.SettleQty = string.Empty; - // entity.NotSettleLU = lsN[number].LU; - // entity.Qty = lsN[number].Qty == null ? string.Empty : lsN[number].Qty.ToString(); - // ls.Add(entity); - // } - // else - // { - // INVOICE_NOT_SETTLE_EXT_DTO entity = new INVOICE_NOT_SETTLE_EXT_DTO(); - // entity.RealInvBillNum = lsN[number].RealInvBillNum; - // entity.InvDate = lsN[number].InvDate; - // entity.InvBillNum = lsN[number].InvBillNum; - // entity.InvGroupNum = lsN[number].InvGroupNum; - // entity.SettleGroupNum = lsN[number].SettleGroupNum; - // entity.SettleLU = lsC[number].LU; - // entity.NotSettleLU = lsN[number].LU; - // entity.Qty = lsN[number].Qty == null ? string.Empty : lsN[number].Qty.ToString(); ; - // entity.SettleQty = lsC[number].Qty == null ? string.Empty : lsC[number].Qty.ToString(); ; - // ls.Add(entity); - // } - // } - //} - - //var disList= ls.Select(p => p.SettleGroupNum).Distinct().ToList(); - //foreach (var de in ls) - //{ - // de.SettleGroupNum = string.Empty; - //} - //for (int i = 0; i < disList.Count; i++) - //{ - // ls[i].SettleGroupNum = disList[i]; - //} - _excel.Append(ls, "结算分组零件" + itm.InvbillNum); - _excel.Append(mgroup, "发票结算分组对应" + itm.InvbillNum).SeparateBySheet(); + _excel.Append(adjp, "发票调整数据" + itm.InvbillNum).SeparateBySheet(); - } - + var result = _excel.ExportAppendDataAsByteArray(); result.ShouldNotBeNull(); //保存导出文件到服务器存成二进制 diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs index 05276240..b9624d59 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_CAN_SA_SERVICE.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.LinqAsync; using System.Threading.Tasks; using EFCore.BulkExtensions; using Microsoft.AspNetCore.Authorization; @@ -50,6 +51,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private readonly PUB_CAN_SA_MNG _pubMng; private readonly INormalEfCoreRepository _priceRepository; private readonly INormalEfCoreRepository _pricebjRepository; + private readonly INormalEfCoreRepository _notRepository; public PUB_CAN_SA_SERVICE (IExcelImportAppService excelImportService, @@ -61,13 +63,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ INormalEfCoreRepository priceRepository, INormalEfCoreRepository pricebjRepository, PUB_CAN_SA_MNG pubMng, - BaseDomainService baseservice + BaseDomainService baseservice, + INormalEfCoreRepository notRepository ) : base(excelImportService, snowflakeIdGenerator, commonManager, repository, detailRepository, invmng,baseservice) { _pubMng = pubMng; _priceRepository = priceRepository; _pricebjRepository = pricebjRepository; + _notRepository = notRepository; } [HttpPost] [UnitOfWork(false)] @@ -132,7 +136,31 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { if (billnum.Substring(0, 1) == "C")//一次开票 { - await FirstInvoice(entitys, new List(), dtos, new List(), main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + + var notQuery = await _notRepository.Where(p => p.SettleBillNum == main.SettleBillNum).ToListAsync(); + 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 FirstInvoice(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); } else//二次开票 { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs index d1d9b4f9..745a0300 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs @@ -743,10 +743,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers await _repository.DbContext.BulkUpdateAsync(invList); return true; } - - - - else { var pdlist = _pdpubRepository.Where(p => p_invs.Contains(p.BillNum)).ToList();//包含发票号的代扣减单 @@ -1238,9 +1234,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers groupList.AddRange(group1); } - string site = dtos.FirstOrDefault().Site; + var lst=dtos.Where(p => !string.IsNullOrEmpty(p.Site)).ToList(); + string site = lst.FirstOrDefault().Site; string clientCode = string.Empty; - switch (site) { case "1040": @@ -1255,7 +1251,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } - var invbill = new INVOICE_GRP (guid: GuidGenerator.Create(), realnvBillNum: string.Empty, @@ -1358,6 +1353,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers var invlist = new List(); var salist = new List(); var adjlist = new List(); + + + List lsby = new List(); + var grouplist = p_list.Select(p => p.GroupNum).Distinct().ToList();//可结分组 + lsby.AddRange(grouplist); + var nolist = p_notlist.Where(p => !grouplist.Contains(p.GroupNum)).Select(p => p.GroupNum).ToList();//不可结分组 + + int count = invoiceMap.Keys.Count;//计算第几张发票计数器 + + int i = 0; foreach (var itm in invoiceMap)//分组影响和 { var key = itm.Key;//发票票号 @@ -1379,7 +1384,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers adjlist.Add(detail); } } - var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU }) + var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID, p.LU })//明细 .Select(itm => new { PartCode = itm.Key.PartCode, @@ -1396,8 +1401,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers decimal txtAmt =detailDtos.Sum(k => k.Amt) + Math.Round(detailDtos.Sum(k => k.Amt) * 0.13m, 2);//税后金额 decimal realAmt = Math.Round(detailDtos.Sum(k => k.Amt) * 0.13m, 2);//税额 - //decimal amt = detailDtos.Sum(k => k.Amt); - //decimal txtAmt = Math.Round(detailDtos.Sum(k => k.Amt), 2); + var mapList = new List(); foreach (var groupnum in ls) { @@ -1469,6 +1473,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { var innotls1 = new List(); var groupnum = itm.Value; + if (count == i)//最后一张发票追加 + { + groupnum.AddRange(nolist);//追加完全不可结 + } var notls = p_notlist.Where(p => groupnum.Contains(p.GroupNum)).GroupBy(p => new { p.GroupNum, p.LU }) .Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = itm.Key }); foreach (var nitm in notls) @@ -1510,7 +1518,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers realAmt: realAmt ); - string site = dtos.FirstOrDefault().Site; + string site = dtos.Where(p=>!string.IsNullOrEmpty(p.Site)).FirstOrDefault().Site; string clientCode = string.Empty; switch(site) @@ -1524,14 +1532,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers default: clientCode = "C004"; break; - } - - invbill.ClientCode = clientCode; invbill.Site= dtos.FirstOrDefault().Site; invbill.CreationTime = DateTime.Now; invlist.Add(invbill); + i++; } //using (var transaction = _repository.DbContext.Database.BeginTransaction()) //{ @@ -1554,7 +1560,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { await _repository.DbContext.BulkInsertAsync(notDetialList); } - // 提交事务 + // 提交事务 // transaction.Commit(); // } // catch (Exception) @@ -1567,11 +1573,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers _invls = invlist.Select(p => p.InvbillNum).ToList(); } - - - - - return _invls; } @@ -1752,34 +1753,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers decimal realAmt = Math.Round(detailList.Sum(k => k.Amt) * 0.13m, 2);//税额 - //decimal amt = detailList.Sum(k => k.Amt); - //decimal txtAmt = Math.Round(detailList.Sum(k => k.Amt), 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(); - //var _groupList = dtos.GroupBy(p => new { p.GroupNum }) - // .Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct(); - //List group1 = new List(); - - //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 invbill = new INVOICE_GRP (guid: GuidGenerator.Create(), realnvBillNum: string.Empty, @@ -1920,7 +1893,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers adjlist.Add(detail); } } - var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.PartCode, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }) .Select(itm => new { @@ -1938,7 +1910,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers decimal amt = detailDtos.Sum(k => k.Amt);//金额 decimal txtAmt = detailDtos.Sum(k => k.Amt)+ Math.Round(detailDtos.Sum(k => k.Amt)*0.13m, 2);//税后金额 decimal realAmt = Math.Round(detailDtos.Sum(k => k.Amt) * 0.13m, 2);//税额 - var mapList = new List(); foreach (var groupnum in ls) { @@ -1983,31 +1954,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { detailList.AddRange(_entityDetailList); } - var innotls = new List(); - if (p_notlist != null && p_notlist.Count > 0) - { - var notls = p_notlist.Where(p=>ls.Contains(p.GroupNum)).GroupBy(p => new { p.GroupNum, p.LU }).Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty) }); - foreach (var nitm in notls) - { - innotls.Add(new INVOICE_NOT_SETTLE( - guid: GuidGenerator.Create(), - version: p_version, - invGroupNum: p_InvGroupNum, - settleGroupNum: nitm.GroupNum, - lU: string.Empty, - lU1: nitm.LU, - extend1: string.Empty, - extend2: string.Empty, - qty: nitm.Qty, - p_invbillnum:key - - )); - } - if (innotls.Count > 0) - { - notDetialList.AddRange(innotls); - } - } + string site = dtos.FirstOrDefault().Site; string clientCode = string.Empty; @@ -2022,11 +1969,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers default: clientCode = "C004"; break; - } - - - var invbill = new INVOICE_GRP (guid: GuidGenerator.Create(), realnvBillNum: string.Empty, @@ -2063,9 +2006,28 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { await _repository.DbContext.BulkUpdateAsync(adjlist); } - if (notDetialList.Count > 0) + if (p_notlist.Count > 0) { - await _repository.DbContext.BulkInsertAsync(notDetialList); + + var innotls = new List(); + var notls = p_notlist.GroupBy(p => new { p.GroupNum, p.LU }).Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty) }); + foreach (var nitm in notls) + { + innotls.Add(new INVOICE_NOT_SETTLE( + guid: GuidGenerator.Create(), + version: p_version, + invGroupNum: p_InvGroupNum, + settleGroupNum: nitm.GroupNum, + lU: string.Empty, + lU1: nitm.LU, + extend1: string.Empty, + extend2: string.Empty, + qty: nitm.Qty, + p_invbillnum: string.Empty + + )); + } + await _repository.DbContext.BulkInsertAsync(innotls); } _invls = invlist.Select(p => p.InvbillNum).ToList(); }