From 61b4246dc758119f76cf88d7d55c1da07f6f019b Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Mon, 1 Jul 2024 10:07:44 +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/BBAC_CAN_SA_DTO.cs | 17 ++ .../Entities/BQ/Dtos/HBPO_CAN_SA_DTO.cs | 9 + .../Entities/BQ/Dtos/PUB_CAN_SA_DTO.cs | 12 ++ .../Bases/CAN_SA_SERVICE.cs | 20 ++- .../Entities/BQ/INVOICE_SERVICE.cs | 155 +++++++++--------- .../Entities/BQ/VmiAppService.cs | 11 +- ...ttleAccountApplicationAutoMapperProfile.cs | 25 ++- .../src/SettleAccount.Domain/EnumBillState.cs | 2 + 8 files changed, 165 insertions(+), 86 deletions(-) diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs index a52905aa..feea7215 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs @@ -33,6 +33,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [Display(Name = "发票分组号")] public string InvGroupNum { get; set; } + + + [Display(Name = "来源可结算单号")] + public string ParentBillNum { get; set; } + + [Display(Name = "来源发票号")] + public string InvBillNum { get; set; } + + + [Display(Name = "是否退回单")] + public string IsReturn { get; set; } + + + + + + } public class BBAC_CAN_SA_DETAIL_DTO : EntityDto { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_CAN_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_CAN_SA_DTO.cs index 8c861064..1513fa9c 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_CAN_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_CAN_SA_DTO.cs @@ -33,6 +33,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [Display(Name = "发票分组号")] public string InvGroupNum { get; set; } + [Display(Name = "来源可结算单号")] + public string ParentBillNum { get; set; } + [Display(Name = "来源发票号")] + public string InvBillNum { get; set; } + [Display(Name = "是否退回单")] + public string IsReturn { get; set; } + + + } public class HBPO_CAN_SA_DETAIL_DTO : EntityDto { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_CAN_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_CAN_SA_DTO.cs index 13630258..7427fcf0 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_CAN_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_CAN_SA_DTO.cs @@ -38,6 +38,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [Display(Name = "明细记录行数")] public string InvGroupNum { get; set; } + [Display(Name = "来源可结算单号")] + public string ParentBillNum { get; set; } + + [Display(Name = "来源发票号")] + public string InvBillNum { get; set; } + + + [Display(Name = "是否退回单")] + public string IsReturn { get; set; } + + + } public class PUB_CAN_SA_REQ_DTO : RequestInputBase 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 076e78ed..b61d74ff 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 @@ -8,6 +8,7 @@ using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Csv; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Mvc; +using Omu.ValueInjecter; using SettleAccount.Bases; using SettleAccount.Domain.BQ; using Shouldly; @@ -86,10 +87,22 @@ namespace Win.Sfs.SettleAccount.Bases { IExporter _csv = new CsvExporter(); IExporter _excel = new ExcelExporter(); - var entities = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); var dtoDetails = ObjectMapper.Map, List>(entities); + + + + + + + + + + + + + var classDisplayName = typeof(TEntityDetailExportDto).GetCustomAttribute()?.Name ?? typeof(TEntityDetailExportDto).Name; string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx"; byte[] result = null; @@ -142,6 +155,11 @@ namespace Win.Sfs.SettleAccount.Bases var entitys = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount).ConfigureAwait(false); var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); var dtos = ObjectMapper.Map, List>(entitys); + + + + + return new PagedResultDto(totalCount, dtos); } [UnitOfWork(false)] 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 13010e5e..e6cd2129 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 @@ -188,22 +188,21 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _globalConfigOptions.IsSyncInvoiceQadState = true; var invoiceGrps1 = _settleAccountDbContext.Set() .Where(t => invbillNums.Contains(t.InvbillNum) && t.State == SettleBillState.红冲发票); - var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组 - var invList=_settleAccountDbContext.Set().Where(p => grouplist.Contains(p.InvGroupNum)).ToList(); - var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum } - into temp - from tm in temp.DefaultIfEmpty() - where tm == null - select itm; - - var invoices = query.ToList(); - if (invoices.Count > 0) - { - var invbilllist=invoices.Select(p => p.InvGroupNum).ToList(); - var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList(); - throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400"); - } - + //var grouplist=invoiceGrps1.Select(p => p.InvGroupNum).ToList();//发票分组 + //var invList=_settleAccountDbContext.Set().Where(p => grouplist.Contains(p.InvGroupNum)).ToList(); + //var query =from itm in invList join itm1 in invoiceGrps1 on new { itm.InvGroupNum, itm.InvbillNum } equals new { itm1.InvGroupNum, itm1.InvbillNum } + // into temp + // from tm in temp.DefaultIfEmpty() + // where tm == null + // select itm; + + //var invoices = query.ToList(); + //if (invoices.Count > 0) + //{ + // var invbilllist=invoices.Select(p => p.InvGroupNum).ToList(); + // var invs = invoiceGrps1.Where(p => invbilllist.Contains(p.InvGroupNum)).Select(p => p.InvbillNum).ToList(); + // throw new UserFriendlyException($"发票{string.Join(",", invs.ToArray())}对应结算单(发票分组)有其他发票状态不在撤销状态,不能退回", "400"); + //} foreach (var itm in invoiceGrps1) { itm.State = SettleBillState.提交QAD退回到已开票; @@ -2001,67 +2000,78 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return new JsonResult(new { Code = 200, Message = "退回成功" }); ; } - //[HttpPost] - //public virtual async Task RejectAsync(INVOICE_GRP_DTO p_dto) - //{ - - // var invgrouplist=_repository.Where(p=>p.InvGroupNum==p_dto.InvGroupNum); - - // if (invgrouplist.Count(p => p.State < SettleBillState.财务已审核) == invgrouplist.Count())//所有发票分组下的放票全为财务已审核的 - // { - // await RejectAsync(p_dto.InvGroupNum).ConfigureAwait(false); - // } - // else - // { - // var inv= _repository.FirstOrDefault(p => p.InvbillNum == p_dto.InvbillNum); - // if (inv == null) - // { - // return new JsonResult(new { Code = 500, Message = "发票不存在" }); - // } - - - - - // } - - - - - + private async Task RejectionAsync(Tmain main,List details) + where Tdetail: SA_CAN_BASE, new() where Tmain : SA_CAN_BASE_MAIN, new() + { + var billNum = string.Empty; + if (main.BillNum.Substring(0,1)=="N") + { + billNum = OrderNumberGenerator.GenerateOrderNumber("N"); + } + if (main.BillNum.Substring(0, 1) == "C") + { + billNum = OrderNumberGenerator.GenerateOrderNumber("C"); + } + Tmain newmain = new Tmain(); + newmain.InjectFrom(main); + newmain.SetId(Guid.NewGuid()); + newmain.BillNum = billNum; + newmain.CreationTime = DateTime.Now; + newmain.State = SettleBillState.已退回; + newmain.ExtraProperties.TryAdd("ParentBillNum", main.BillNum); + newmain.ExtraProperties.TryAdd("InvBillNum", details.FirstOrDefault().InvbillNum); + newmain.ExtraProperties.TryAdd("IsReturn", "是"); + var _dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); + var list = details; + foreach (var item in list) + { + item.InvbillNum = billNum; + } + await _dbcontext.BulkInsertAsync(new List() { newmain }).ConfigureAwait(false); + await _dbcontext.BulkUpdateAsync(list).ConfigureAwait(false); + } + [HttpPost] + public virtual async Task ReturnAsync(INVOICE_GRP_DTO p_dto) + { + var invgrouplist = _repository.Where(p => p.InvGroupNum == p_dto.InvGroupNum); + if (invgrouplist.Count(p => p.State < SettleBillState.财务已审核) == invgrouplist.Count())//所有发票分组下的发票全为财务已审核的 + { + await RejectAsync(p_dto.InvGroupNum).ConfigureAwait(false); + } + else + { + var inv = _repository.FirstOrDefault(p => p.InvbillNum == p_dto.InvbillNum); + if (inv == null) + { + return new JsonResult(new { Code = 500, Message = "发票不存在" }); + } + var dbcontext = await _repository.GetDbContextAsync().ConfigureAwait(false); + switch(inv.BusinessType) + { + case EnumBusinessType.JisBBAC: + var bbaclist = await dbcontext.Set().Where(p => p.InvbillNum == p_dto.InvbillNum).AsNoTracking().ToListAsync().ConfigureAwait(false); + var bbacfirst = await dbcontext.Set().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); + await RejectionAsync(bbacfirst, bbaclist.ToList()).ConfigureAwait(false); + break; + case EnumBusinessType.JisHBPO: + var hbpolist = await dbcontext.Set().Where(p => p.InvbillNum == p_dto.InvbillNum).AsNoTracking().ToListAsync().ConfigureAwait(false); + var hbpofirst = await dbcontext.Set().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); + await RejectionAsync(hbpofirst, hbpolist.ToList()).ConfigureAwait(false); + break; + default: + var publist = await dbcontext.Set().Where(p => p.InvbillNum == p_dto.InvbillNum).ToListAsync().ConfigureAwait(false); + var pubfirst = await dbcontext.Set().FirstOrDefaultAsync(p => p.BillNum == p_dto.InvGroupNum).ConfigureAwait(false); + await RejectionAsync(pubfirst, publist.ToList()).ConfigureAwait(false); + break; + } + } - // //var entities = await _invMng.GetMainListAsync(p_invGroupNum).ConfigureAwait(false); - // //var entity = entities.FirstOrDefault(); - // //bool state = await _invMng.Reject(p_invGroupNum).ConfigureAwait(false); - // //if (state == true) - // //{ - // // switch (entity.BusinessType) - // // { - // // case EnumBusinessType.BeiJian: - // // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // case EnumBusinessType.ZhiGongJianBBAC: - // // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // case EnumBusinessType.ZhiGongJianHBPO: - // // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // case EnumBusinessType.YinDuJian: - // // await _pubMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // case EnumBusinessType.JisBBAC: - // // await _bbacMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // case EnumBusinessType.JisHBPO: - // // await _hbpoMng.SetNewState(p_invGroupNum).ConfigureAwait(false); - // // break; - // // } - // //} - // return new JsonResult(new { Code = 200, Message = "退回成功" }); ; - //} + return new JsonResult(new { Code = 200, Message = "退回成功" }); ; + } @@ -2115,7 +2125,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var newinv1 = result.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); var newinv = ls.Where(p => p.InvbillNum == inv.InvbillNum).FirstOrDefault(); - inv.Tax = 0.13m; inv.RealnvBillNum = newinv.RealnvBillNum; inv.TaxDiff = newinv.PreTaxDiff; 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 54e19429..7e148ddb 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 @@ -271,11 +271,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ input.Filters.Remove(itm); } - - - - var first = input.Filters.FirstOrDefault(p => p.Column == "BillTime"); + var first = input.Filters.FirstOrDefault(p => p.Column == "BillTime"); if (first != null) { input.Filters.Remove(first); @@ -303,7 +300,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var entities = await _vmiBalanceSumDetailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount, true).ConfigureAwait(false); var dtos = _maper.Map, List>(entities); dtos = dtos.OrderByDescending(p => p.BillTime).ToList(); - var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.zip"; + var fileName = $"库存余额_{DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")}.xlsx"; ExportImporter _exportImporter = new ExportImporter(); var result = await _exportImporter.ExcelExporter(dtos).ConfigureAwait(false); result.ShouldNotBeNull(); @@ -2264,7 +2261,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { var datas = data.Skip((i - 1) * 1000000).Take(1000000).ToList(); var chunks = datas.ChunkBy(chunkSize); - Parallel.ForEach(chunks, async chunk => + Parallel.ForEach(chunks, chunk => { var fileName = $"{sheetName}_{i - 1}_{Guid.NewGuid()}.xlsx"; var fileinfogroup = new FileInfoGroup((fileName), $"{sheetName}_{i - 1}"); @@ -2281,8 +2278,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ archive.CreateEntryFromFile(file, Path.GetFileName(file)); } } - - //for (var i = 0; i < count; i++) //{ diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index 4a24d619..c4bf73a8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -190,7 +190,13 @@ namespace Win.Sfs.SettleAccount private void CreateMapBBAC_CAN_SA() { - CreateMap().ReverseMap(); + // CreateMap().ReverseMap(); + CreateMap() + .ForMember(dest => dest.ParentBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("ParentBillNum") == true ? src.ExtraProperties.GetOrDefault("ParentBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.InvBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("InvBillNum") == true ? src.ExtraProperties.GetOrDefault("InvBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.IsReturn, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("IsReturn") == true ? src.ExtraProperties.GetOrDefault("IsReturn").ToString() : string.Empty)); + + CreateMap().ReverseMap(); } @@ -213,8 +219,15 @@ namespace Win.Sfs.SettleAccount private void CreateMapHBPO_CAN_SA() { - CreateMap().ReverseMap(); - CreateMap().ReverseMap(); + + CreateMap() + .ForMember(dest => dest.ParentBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("ParentBillNum") == true ? src.ExtraProperties.GetOrDefault("ParentBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.InvBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("InvBillNum") == true ? src.ExtraProperties.GetOrDefault("InvBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.IsReturn, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("IsReturn")==true? src.ExtraProperties.GetOrDefault("IsReturn").ToString() : string.Empty)); + + + + CreateMap().ReverseMap(); } private void CreateMapHBPO_CAN_SA_DETAIL() @@ -274,7 +287,11 @@ namespace Win.Sfs.SettleAccount private void CreateMapPUB_CAN_SA() { - CreateMap().ReverseMap(); + CreateMap() + .ForMember(dest => dest.ParentBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("ParentBillNum") == true ? src.ExtraProperties.GetOrDefault("ParentBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.InvBillNum, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("InvBillNum") == true ? src.ExtraProperties.GetOrDefault("InvBillNum").ToString() : string.Empty)) + .ForMember(dest => dest.IsReturn, opt => opt.MapFrom(src => src.ExtraProperties.ContainsKey("IsReturn") == true ? src.ExtraProperties.GetOrDefault("IsReturn").ToString() : string.Empty)); + CreateMap().ReverseMap(); } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs index 5a6f58e7..aa55903d 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs @@ -43,6 +43,8 @@ namespace Win.Sfs.SettleAccount 可结退回不可结同步中 = 13, [Description("提交QAD退回到已开票")] 提交QAD退回到已开票 = 14, + [Description("已退回")] + 已退回 = 15,