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 280879d2..a19c6e05 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 @@ -14,7 +14,6 @@ using Win.Sfs.Shared.Filter; namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos { public class INVOICE_GRP_DTO : EntityDto - { [Display(Name = "期间")] public int Version { set; get; } @@ -61,11 +60,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos } - - public class INVOICE_GRP_EXP_DTO { - /// ///实际纸质发票号 /// @@ -91,9 +87,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [ExporterHeader(DisplayName = "税后金额")] public decimal TaxAmt { get; set; } - - - } @@ -104,7 +97,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [ImporterHeader(Name = "实际纸质发票号", FixAllSpace = true)] [Required(ErrorMessage = "{0}是必填项")] - [MaxLength(CommonConsts.MaxNameLength, ErrorMessage = "{0}最多输入{1}个字符")] + [MaxLength(CommonConsts.MaxNameLength, ErrorMessage = "{0}最多输入{1}个字符")] public string RealnvBillNum { get; set; } /// @@ -119,17 +112,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos /// [ImporterHeader(Name = "税额", FixAllSpace = true)] [Required(ErrorMessage = "{0}是必填项")] - - public decimal Tax { get; set; } + + public decimal Tax { get; set; } } public class INVOICE_GRP_REQ_DTO : RequestInputBase { - [Display(Name = "实际纸质发票号")] public string RealnvBillNum { get; set; } - [Display(Name = "未税金额")] public decimal Amt { get; set; } [Display(Name = "税后金额")] @@ -142,19 +133,31 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public int State { set; get; } [Display(Name = "业务类别")] public EnumBusinessType BusinessType { get; set; } - - - } - + /// + /// 结算明细 + /// public class INVOICE_GRP_DETAIL_DTO : EntityDto { + /// + /// 发票明细 + /// public List INVOICE_WAIT_DETAIL { get; set; } + + /// + /// 发票和结算分组对应关系 + /// public List INVOICE_MAP_GROUP { get; set; } + /// + /// 已结分组包含不可结算零件 + /// public List INVOICE_NOT_SETTLE { get; set; } + /// + /// 发票调整明细 + /// public List ADJ_DETAIL { get; set; } @@ -164,252 +167,244 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public class INVOICE_WAIT_DETAIL_DTO : EntityDto - { - - /// - ///期间 - /// - [Display(Name = "期间")] - public int Version { get; set; } - /// - ///发票号 - /// - [Display(Name = "发票号")] - public string InvbillNum { get; set; } - /// - ///发票分组号 - /// - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - /// - ///零件号 - /// - [Display(Name = "零件号")] - public string LU { get; set; } - /// - ///单价 - /// - [Display(Name = "单价")] - public decimal PRICE { get; set; } - /// - ///数量 - /// - [Display(Name = "数量")] - public decimal Qty { get; set; } - /// - ///金额 - /// - [Display(Name = "金额")] - public decimal Amt { get; set; } - /// - ///业务分类 - /// - [Display(Name = "业务分类")] - public string BussiessType { get; set; } - /// - ///扩展字段1 - /// - [Display(Name = "扩展字段1")] - public string Extend1 { get; set; } - /// - ///扩展字段2 - /// - [Display(Name = "扩展字段2")] - public string Extend2 { get; set; } - /// - ///扩展字段3 - /// - [Display(Name = "扩展字段3")] - public DateTime BeginDate { get; set; } - /// - ///扩展字段4 - /// - [Display(Name = "扩展字段4")] - public DateTime EndDate { get; set; } - - } - public class INVOICE_WAIT_DETAIL_REQ_DTO : RequestInputBase - { - [Display(Name = "发票号")] - public string InvbillNum { get; set; } - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - [Display(Name = "零件号")] - public string LU { get; set; } - - } - - - - - - - public class INVOICE_MAP_GROUP_DTO : EntityDto - - { - - /// - ///期间 - /// - [Display(Name = "期间")] - public int Version { get; set; } - /// - ///发票号 - /// - [Display(Name = "发票号")] - public string InvbillNum { get; set; } - /// - ///发票分组号 - /// - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - /// - ///结算分组号 - /// - [Display(Name = "结算分组号")] - public string SettleGroupNum { get; set; } - /// - ///金额 - /// - [Display(Name = "金额")] - public decimal Amt { get; set; } - /// - ///扩展字段1 - /// - [Display(Name = "扩展字段1")] - public string Extend1 { get; set; } - /// - ///扩展字段2 - /// - [Display(Name = "扩展字段2")] - public string Extend2 { get; set; } - public bool IsDeleted { get; set; } - - } - - - - public class INVOICE_MAP_GROUP_EXP_DTO - - { - - /// - ///期间 - /// - [ExporterHeader(DisplayName = "期间")] - public int Version { get; set; } - /// - ///发票号 - /// - [ExporterHeader(DisplayName = "发票号")] - public string InvbillNum { get; set; } - /// - ///发票分组号 - /// - [ExporterHeader(DisplayName = "发票分组号")] - public string InvGroupNum { get; set; } - /// - ///结算分组号 - /// - [ExporterHeader(DisplayName = "结算分组号")] - public string SettleGroupNum { get; set; } - /// - ///金额 - /// - [ExporterHeader(DisplayName = "金额")] - public decimal Amt { get; set; } - /// - ///扩展字段1 - /// - [ExporterHeader(DisplayName = "扩展字段1")] - public string Extend1 { get; set; } - /// - ///扩展字段2 - /// - [ExporterHeader(DisplayName = "扩展字段2")] - public string Extend2 { get; set; } - - - } - - - public class INVOICE_MAP_GROUP_REQ_DTO : PagedAndSortedResultRequestDto - { - public int Version { get; set; } - [Display(Name = "发票号")] - public string InvbillNum { get; set; } - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - } - - public class INVOICE_NOT_SETTLE_DTO : EntityDto - { - - /// - ///期间 - /// - [Display(Name = "期间")] - public int Version { get; set; } - /// - ///发票分组号 - /// - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - /// - ///结算分组号 - /// - [Display(Name = "结算分组号")] - public string SettleGroupNum { get; set; } - /// - ///可结算零件号 - /// - [Display(Name = "可结算零件号")] - public string LU { get; set; } - /// - ///不可结算零件号 - /// - [Display(Name = "不可结算零件号")] - public string LU1 { get; set; } - /// - ///扩展字段1 - /// - [Display(Name = "扩展字段1")] - public string Extend1 { get; set; } - /// - ///扩展字段2 - /// - [Display(Name = "扩展字段2")] - public string Extend2 { get; set; } - - } - - - - - - - - - - public class INVOICE_NOT_SETTLE_REQ_DTO : PagedAndSortedResultRequestDto - - { - - - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - [Display(Name = "结算分组号")] - public string SettleGroupNum { get; set; } - - - public virtual List Filters { get; set; } = new List(); - } + { + + /// + ///期间 + /// + [Display(Name = "期间")] + public int Version { get; set; } + /// + ///发票号 + /// + [Display(Name = "发票号")] + public string InvbillNum { get; set; } + /// + ///发票分组号 + /// + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } + /// + ///零件号 + /// + [Display(Name = "零件号")] + public string LU { get; set; } + /// + ///单价 + /// + [Display(Name = "单价")] + public decimal PRICE { get; set; } + /// + ///数量 + /// + [Display(Name = "数量")] + public decimal Qty { get; set; } + /// + ///金额 + /// + [Display(Name = "金额")] + public decimal Amt { get; set; } + /// + ///业务分类 + /// + [Display(Name = "业务分类")] + public string BussiessType { get; set; } + /// + ///扩展字段1 + /// + [Display(Name = "扩展字段1")] + public string Extend1 { get; set; } + /// + ///扩展字段2 + /// + [Display(Name = "扩展字段2")] + public string Extend2 { get; set; } + /// + ///扩展字段3 + /// + [Display(Name = "扩展字段3")] + public DateTime BeginDate { get; set; } + /// + ///扩展字段4 + /// + [Display(Name = "扩展字段4")] + public DateTime EndDate { get; set; } + + } + public class INVOICE_WAIT_DETAIL_REQ_DTO : RequestInputBase + { + [Display(Name = "发票号")] + public string InvbillNum { get; set; } + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } + [Display(Name = "零件号")] + public string LU { get; set; } + + } + + public class INVOICE_MAP_GROUP_DTO : EntityDto + + { + + /// + ///期间 + /// + [Display(Name = "期间")] + public int Version { get; set; } + /// + ///发票号 + /// + [Display(Name = "发票号")] + public string InvbillNum { get; set; } + /// + ///发票分组号 + /// + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } + /// + ///结算分组号 + /// + [Display(Name = "结算分组号")] + public string SettleGroupNum { get; set; } + /// + ///金额 + /// + [Display(Name = "金额")] + public decimal Amt { get; set; } + /// + ///扩展字段1 + /// + [Display(Name = "扩展字段1")] + public string Extend1 { get; set; } + /// + ///扩展字段2 + /// + [Display(Name = "扩展字段2")] + public string Extend2 { get; set; } + public bool IsDeleted { get; set; } + + } + public class INVOICE_MAP_GROUP_EXP_DTO + { + /// + ///期间 + /// + [ExporterHeader(DisplayName = "期间")] + public int Version { get; set; } + /// + ///发票号 + /// + [ExporterHeader(DisplayName = "发票号")] + public string InvbillNum { get; set; } + /// + ///发票分组号 + /// + [ExporterHeader(DisplayName = "发票分组号")] + public string InvGroupNum { get; set; } + /// + ///结算分组号 + /// + [ExporterHeader(DisplayName = "结算分组号")] + public string SettleGroupNum { get; set; } + /// + ///金额 + /// + [ExporterHeader(DisplayName = "金额")] + public decimal Amt { get; set; } + /// + ///扩展字段1 + /// + [ExporterHeader(DisplayName = "扩展字段1")] + public string Extend1 { get; set; } + /// + ///扩展字段2 + /// + [ExporterHeader(DisplayName = "扩展字段2")] + public string Extend2 { get; set; } + + } + + public class INVOICE_MAP_GROUP_REQ_DTO : PagedAndSortedResultRequestDto + { + public int Version { get; set; } + [Display(Name = "发票号")] + public string InvbillNum { get; set; } + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } } + public class INVOICE_NOT_SETTLE_DTO : EntityDto + { + + /// + ///期间 + /// + [Display(Name = "期间")] + public int Version { get; set; } + /// + ///发票分组号 + /// + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } + /// + ///结算分组号 + /// + [Display(Name = "结算分组号")] + public string SettleGroupNum { get; set; } + /// + ///可结算零件号 + /// + [Display(Name = "可结算零件号")] + public string LU { get; set; } + /// + ///不可结算零件号 + /// + [Display(Name = "不可结算零件号")] + public string LU1 { get; set; } + /// + ///扩展字段1 + /// + [Display(Name = "扩展字段1")] + public string Extend1 { get; set; } + /// + ///扩展字段2 + /// + [Display(Name = "扩展字段2")] + public string Extend2 { get; set; } + + } + + + + + + + + + + public class INVOICE_NOT_SETTLE_REQ_DTO : PagedAndSortedResultRequestDto + + { + + + [Display(Name = "发票分组号")] + public string InvGroupNum { get; set; } + [Display(Name = "结算分组号")] + public string SettleGroupNum { get; set; } + + + public virtual List Filters { get; set; } = new List(); + } + + + + +} + diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs index db805fa8..d1d22c2c 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs @@ -10,37 +10,37 @@ using Win.Sfs.SettleAccount.Bases; using Win.Sfs.Shared.Filter; namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos; - public class PUB_ADJ_DETAIL_DTO : EntityDto - { - /// - ///作废发票号 - /// - [Display(Name = "作废发票号")] - public string OldInvBillNum { get; set; } - /// - ///发票号 - /// - [Display(Name = "发票号")] - public string InvBillNum { get; set; } - - /// - /// 下线日期 - /// - [Display(Name = "下线日期")] - public DateTime SettleDate { get; set; } - - [Display(Name = "发票分组号")] - public string InvGroupNum { get; set; } - [Display(Name = "零件号")] - public string LU { get; set; } - [Display(Name = "标识号")] - public string PN { get; set; } - [Display(Name = "数量")] - public decimal Qty { get; set; } - [Display(Name = "结算分组")] - public string GroupNum { get; set; } - - } + +public class PUB_ADJ_DETAIL_DTO : EntityDto +{ + ///// + /////作废发票号 + ///// + //[Display(Name = "作废发票号")] + //public string OldInvBillNum { get; set; } + /// + ///发票号 + /// + [Display(Name = "发票号")] + public string InvBillNum { get; set; } + + /// + /// 下线日期 + /// + [Display(Name = "下线日期")] + public DateTime SettleDate { get; set; } + + //[Display(Name = "发票分组号")] + //public string InvGroupNum { get; set; } + [Display(Name = "零件号")] + public string LU { get; set; } + [Display(Name = "标识号")] + public string PN { get; set; } + [Display(Name = "数量")] + public decimal Qty { get; set; } + [Display(Name = "结算分组")] + public string GroupNum { get; set; } +} public class PUB_ADJ_DETAIL_EXP_DTO { /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs index 12e4e116..fddce994 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using DocumentFormat.OpenXml.Office2010.Excel; using EFCore.BulkExtensions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -17,6 +18,7 @@ using Win.Sfs.SettleAccount.Bases.DomainServices; using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; +using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.Shared.RepositoryBase; @@ -31,16 +33,21 @@ public class ADJ_SERVICE : BASE_SERVICE { protected readonly INormalEfCoreRepository _repository; protected readonly BaseDomainService _baseDomainService; + protected readonly INormalEfCoreRepository _invRepository; + public ADJ_SERVICE( INormalEfCoreRepository repository, BaseDomainService baseDomainService, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, - ICommonManager commonManager + ICommonManager commonManager, + INormalEfCoreRepository invRepository + ) : base(excelImportService, snowflakeIdGenerator, commonManager) { - _repository = repository; + _invRepository = invRepository; + _repository = repository; _baseDomainService = baseDomainService; } /// @@ -74,12 +81,19 @@ public class ADJ_SERVICE : BASE_SERVICE { throw new BusinessException("8989", "导入数据记录为0条"); } - var deletels = _repository.Where(p => p.OldInvBillNum == result.FirstOrDefault().OldInvBillNum).ToList(); - var first = deletels.FirstOrDefault(); - if (!string.IsNullOrEmpty(first.InvBillNum)) + var invs=result.Select(p => p.OldInvBillNum).ToList();//所有发票号 + var deletels = _repository.Where(p =>invs.Contains(p.OldInvBillNum) ).ToList();//所有关联发票号的调整表 + var invlist= _invRepository.Where(p => invs.Contains(p.InvbillNum)).ToList();//所有发票 + var dlists= deletels.Where(p=>string.IsNullOrEmpty(p.InvBillNum)).ToList();//所有新发票号不为空的调整记录 + foreach (var itm in dlists) { - throw new BusinessException("8989", $"调整记录已经新发票号:{first.InvBillNum}"); + errorList.Add(new ErrorExportDto() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}记录已经被重新开票,新发票号为:{itm.InvBillNum}" }); } + //var first = deletels.FirstOrDefault(); + //if (!string.IsNullOrEmpty(first.InvBillNum)) + //{ + // throw new BusinessException("8989", $"调整记录已经生成新发票号:{first.InvBillNum}"); + //} var entityList = ObjectMapper.Map, List>(result); var codelist = entityList.Select(p => p.LU).ToList(); var errors = await _baseDomainService.CheckBase(codelist, new BASE_CONF() { IsRelationShip = true }); @@ -96,8 +110,28 @@ public class ADJ_SERVICE : BASE_SERVICE errorList.Add(new ErrorExportDto() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}不存在价格单记录" }); } } + var query = from itm in entityList + join itm1 in invlist + on itm.InvBillNum equals itm1.InvbillNum + select new PUB_ADJ_DETAIL( + id: GuidGenerator.Create(), + keyCode: itm.PN + itm.LU, + version: itm.Version, + settleBillNum: itm.SettleBillNum, + lU: itm.LU, + pN: itm.PN, + site: itm.Site, + qty: itm.Qty, + extend1: string.Empty, + price: 0, + invGroupNum: itm1.InvGroupNum, + settleDate: itm.SettleDate, + businessType: itm1.BusinessType, + groupNum: itm.GroupNum, + oldinv: itm.InvBillNum, + inv: string.Empty); await _repository.DbContext.BulkDeleteAsync(deletels);//删除发票下所有调整明细 - await _repository.DbContext.BulkInsertAsync(entityList); + await _repository.DbContext.BulkInsertAsync(query.ToList()); return ApplicationConsts.SuccessStr; } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs index 94ca80d4..d5c27193 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs @@ -1,5 +1,6 @@ using CodeArts.Db.Lts; using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing.Charts; using EFCore.BulkExtensions; using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Csv; @@ -7,8 +8,11 @@ using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using NPOI.SS.Formula.Functions; +using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using SettleAccount.Bases; using SettleAccount.Domain.BQ; +using SettleAccount.Job.Services; +using SettleAccount.Job.Services.Report; using Shouldly; using System; using System.Collections.Generic; @@ -18,10 +22,13 @@ using System.LinqAsync; using System.Reflection; using System.Text; using System.Threading.Tasks; +using TaskJob.EventArgs; +using TaskJob.Services; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.CommonManagers; @@ -30,6 +37,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.SettleAccount.Entities.BQ.Temp; using Win.Sfs.SettleAccount.Entities.Prices; +using Win.Sfs.SettleAccount.Entities.TaskJobs; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.Migrations; @@ -51,7 +59,7 @@ namespace Win.Sfs.SettleAccount.Bases protected readonly BBAC_CAN_SA_MNG _bbacMng; protected readonly PUB_CAN_SA_MNG _pubMng; protected readonly INV_MNG _invMng; - + private readonly TaskJobService _service; @@ -62,16 +70,17 @@ namespace Win.Sfs.SettleAccount.Bases INormalEfCoreRepository sRepository, INormalEfCoreRepository mRepository, IExcelImportAppService excelImportService, - HBPO_CAN_SA_MNG hbpoMng, - BBAC_CAN_SA_MNG bbacMng, - PUB_CAN_SA_MNG pubMng, - INV_MNG invMng + HBPO_CAN_SA_MNG hbpoMng, + BBAC_CAN_SA_MNG bbacMng, + PUB_CAN_SA_MNG pubMng, + INV_MNG invMng, + TaskJobService service //INormalEfCoreRepository detailRepository ) { - + _service= service; _repository = repository; _wRepository = wRepository; @@ -223,14 +232,47 @@ namespace Win.Sfs.SettleAccount.Bases [HttpPost] public virtual async Task ReceivedAsync(INVOICE_GRP_REQ_DTO input) { - var entity = await _invMng.GetMainAsync(input.InvGroupNum); + var entity = await _invMng.GetMainAsync(input.InvbillNum); + if (entity.InvoiceState == InvoiceBillState.报废) + { + throw new BusinessException("8989", $"发票号{entity.InvbillNum}为报废状态, 不能提交!"); + } + + if (entity.InvoiceState == InvoiceBillState.提交 ) + { + throw new BusinessException("8989", $"发票号{entity.InvbillNum}所在发票分组{entity.InvGroupNum}已提交过收票!"); + } + if (entity.State == SettleBillState.财务已审核) + { + throw new BusinessException("8989", $"发票号{entity.InvbillNum}所在发票分组{entity.InvGroupNum}不是财务已审核状态,不能收票!"); + } + if (entity != null) { - bool flag = await _invMng.ReceivedAsync(entity.InvGroupNum); - if (flag == true) - { - await _invMng.SetForwardState(entity, SettleBillState.客户已收票); + + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "InvGroupNum", Value = input.InvGroupNum ?? string.Empty }); + var invlist= _repository.Where(p => p.InvGroupNum == entity.InvGroupNum).ToList(); + foreach (var inv in invlist) { + + if (inv.InvoiceState != InvoiceBillState.报废) + { + inv.InvoiceState = InvoiceBillState.提交; + } } + await _repository.DbContext.BulkUpdateAsync(invlist); + var _taskid = await _service.ExportEnqueueAsync($"发票分组{entity.InvGroupNum}收票任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyymm"), string.Empty, CurrentUser, typeof(PD_SERVICE), customConditionList, (rs) => + { + + }); + + + return _taskid; + //bool flag = await _invMng.ReceivedAsync(entity.InvGroupNum); + //if (flag == true) + //{ + // await _invMng.SetForwardState(entity, SettleBillState.客户已收票); + //} } return ApplicationConsts.SuccessStr; } @@ -259,8 +301,6 @@ namespace Win.Sfs.SettleAccount.Bases filters.Add(new FilterCondition("InvBillNum", p_invbillNum, EnumFilterAction.Equal, EnumFilterLogic.And)); return await _sRepository.GetListByFilterAsync(filters); - - } protected virtual async Task> GetAjdmentDetail(INVOICE_GRP_REQ_DTO input) @@ -313,11 +353,17 @@ namespace Win.Sfs.SettleAccount.Bases /// 版本号 /// 发票分组 /// 原发票号 - protected async Task ReissueSecInvoice(List p_list, List p_adjlist, int p_version, string p_parentInvBillNum) + protected async Task ReissueSecInvoice(List p_list, List p_adjlist, int p_version, string p_parentInvBillNum) { + var flag=await _invMng.ReissueSecInvoice(p_list, p_adjlist, p_parentInvBillNum, p_version); + if (flag) + { + return true; + } - return await _invMng.ReissueSecInvoice(p_list,p_adjlist,p_parentInvBillNum, p_version); + throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容"); + } /// @@ -332,7 +378,17 @@ namespace Win.Sfs.SettleAccount.Bases /// protected async Task ReissueFirstInvoice(List dtos, List p_adjlist, int p_version, string p_parentInvBillNum) { - return await _invMng.ReissueFirstInvoice(dtos,p_adjlist,p_parentInvBillNum,p_version); + + var flag = await _invMng.ReissueFirstInvoice(dtos, p_adjlist, p_parentInvBillNum, p_version); + if (flag==true) + { + return true; + } + + throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容"); + + + } /// @@ -354,7 +410,6 @@ namespace Win.Sfs.SettleAccount.Bases from tm in temp.DefaultIfEmpty()//校验错误项 where tm == null select d; - List errorList = new List(); string name = string.Empty; @@ -389,9 +444,7 @@ namespace Win.Sfs.SettleAccount.Bases name = "备件"; keyname = "交付识别号"; break; - } - foreach (var error in left) { errorList.Add(new ERR_EXP_DTO() { ItemCode = error.LU, CustomCode = $"{name}", Message = $"LU:{error.LU}{keyname}:{error.PN},下线日期:{error.SettleDate}没有对应区间销售价格表!" }); 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 69ba186c..7f731f50 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 @@ -166,13 +166,13 @@ namespace Win.Sfs.SettleAccount.Bases /// 原发票号 protected async Task SecInvoice(List p_list, int p_version, string p_InvGroupNum, string p_parentInvBillNum,EnumBusinessType businessType) { - var ls= await _invmng.SecInvoice(p_list, p_version, p_InvGroupNum, p_parentInvBillNum, businessType); if (ls.Count > 0) { return true; } - return false; + + throw new BusinessException("8989", "生成失败,请检可结算单明细数据是否结算分组存在"); } @@ -194,7 +194,8 @@ namespace Win.Sfs.SettleAccount.Bases { return true; } - return false; + throw new BusinessException("8989", "生成失败,请检可结算单明细数据是否结算分组存在"); + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs index 5e369036..0686b126 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/PD_SERVICE.cs @@ -1,9 +1,12 @@ using AutoMapper; +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing.Charts; using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Csv; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; using SettleAccount.Bases; using Shouldly; using System; @@ -13,6 +16,8 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using TaskJob.EventArgs; +using TaskJob.Services; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Entities; @@ -113,6 +118,21 @@ namespace Win.Sfs.SettleAccount.Bases //[Route("generateinvoice")] public virtual async Task ApprovalPassed(TRequestMainInput input) { + + + + + + + + + + + + + + + return ApplicationConsts.SuccessStr; } /// @@ -137,6 +157,19 @@ namespace Win.Sfs.SettleAccount.Bases [HttpPost] public virtual async Task RejectAsync(TRequestMainInput input) { + + + + + + + + + + + + + return ApplicationConsts.SuccessStr; } 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 cea5892e..0d6515aa 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 @@ -153,9 +153,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } else//二次开票 { - await SecInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); - } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs index b6db52bb..9d5e565c 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_NOT_SA_SERVICE.cs @@ -34,12 +34,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ BBAC_NOT_SA_DETAIL_EXP_DTO> { - private readonly BBAC_NOT_SA_MNG _bbacNotMng; - - - public BBAC_NOT_SA_SERVICE(IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository detailRepository, BBAC_NOT_SA_MNG bbacNotMng) : diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs index 7d59a57d..015537ec 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs @@ -27,6 +27,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { public BBAC_PD_SERVICE(IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, INormalEfCoreRepository detailRepository) : base(excelImportService, snowflakeIdGenerator, commonManager, repository, detailRepository) { + + + + + + + } + } } 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 5f488907..155b392b 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 @@ -77,8 +77,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!"); } var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件 - var adjlist = await _adjRepository.Where(p => p.InvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 - if (adjlist != null && adjlist.Count() > 0) + var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 + if (adjlist != null && adjlist.Count > 0) { foreach (var itm in adjlist) { @@ -97,8 +97,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ settleDate: itm.SettleDate, groupNum: itm.GroupNum, - invGroupNum: itm.InvGroupNum - + invGroupNum: itm.InvGroupNum )); } } @@ -140,7 +139,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { if (p_invbillnum.Substring(0, 3) == "INV")//一次开票重开 { - await ReissueFirstInvoice(dtos,adjlist, version, p_invbillnum); + await ReissueFirstInvoice(dtos,adjlist, version, p_invbillnum); + } else//二次开票 { 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 027f0243..b72c12cc 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 @@ -59,8 +59,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ INormalEfCoreRepository notRepository, INormalEfCoreRepository priceRepository, HBPO_CAN_SA_MNG hbpoMng - - ) : base(excelImportService, snowflakeIdGenerator, commonManager, repository, detailRepository, invmng) { @@ -139,11 +137,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ ContractDocID = string.Empty }).ToList();//不能结算 - await FirstInvoice(dtos, notlist, main.Version, main.InvGroupNum, string.Empty,main.BusinessType); + var falg= await FirstInvoice(dtos, notlist, main.Version, main.InvGroupNum, string.Empty,main.BusinessType); } else//二次开票 { - await SecInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + var flag=await SecInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_PD_SERVICE.cs index 1f7ff5b1..55856361 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_PD_SERVICE.cs @@ -1,3 +1,5 @@ +using DocumentFormat.OpenXml.Bibliography; +using DocumentFormat.OpenXml.Drawing.Charts; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components; using SettleAccount.Domain.BQ; @@ -6,6 +8,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TaskJob.EventArgs; +using TaskJob.Services; using Volo.Abp.Application.Services; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; @@ -14,7 +18,6 @@ using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Dtos.SettleAccount.Domain.BQ; using Win.Sfs.Shared.RepositoryBase; - namespace Win.Sfs.SettleAccount.Entities.BQ { [AllowAnonymous] @@ -25,6 +28,33 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { public HBPO_PD_SERVICE(IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, INormalEfCoreRepository detailRepository) : base(excelImportService, snowflakeIdGenerator, commonManager, repository, detailRepository) { + //List customConditionList = new List(); + //customConditionList.Add(new CustomCondition() { Name = "Version", Value = version ?? string.Empty }); + //customConditionList.Add(new CustomCondition() { Name = "CustomerCode", Value = customerCode ?? string.Empty }); + //customConditionList.Add(new CustomCondition() { Name = "Year", Value = year ?? string.Empty }); + //customConditionList.Add(new CustomCondition() { Name = "Period", Value = period ?? string.Empty }); + //customConditionList.Add(new CustomCondition() { Name = "Factory", Value = factory ?? string.Empty }); + //var _versionQuery = _versionRepository.Where(p => p.Version == version); + //if (_versionQuery.Count() > 0) + //{ + // _versionQuery.BatchDelete(); + //} + + //var _query = _repository.Where(p => p.Version == version); + //if (_query.Count() > 0) + //{ + // await _query.BatchDeleteAsync(); + //} + //var _taskid = await _service.ImportEnqueueAsync(files, "结算数据", CurrentUser, typeof(SettleAccountImportService), customConditionList, (rs) => + //{ + + + + + //}); + + + } } } 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 afde8a3f..fb9a7431 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 @@ -70,6 +70,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ _invMng = invMng; } + + + + + /// + /// 通过审核 + /// + /// + /// [HttpPost] public virtual async Task ApprovalPassed(INVOICE_GRP_REQ_DTO input) { @@ -78,6 +87,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return ApplicationConsts.SuccessStr; } + /// + /// 主表查询 + /// + /// + /// [HttpPost] //[Route("mainquery")] public virtual async Task> MainQueryAsync(INVOICE_GRP_REQ_DTO input) @@ -87,6 +101,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var dtos = ObjectMapper.Map, List>(entitys); return new PagedResultDto(totalCount, dtos); } + /// + /// 明细查询 + /// + /// + /// [HttpPost] public virtual async Task DetailQueryAsync(INVOICE_GRP_REQ_DTO input) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs index d47b4640..dc1f360b 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs @@ -77,7 +77,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!"); } var hbpolist = await _pubMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件 - var adjlist = await _adjRepository.Where(p => p.InvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 + var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 if (adjlist != null && adjlist.Count() > 0) { foreach (var itm in adjlist) @@ -108,7 +108,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var priceList = _priceRepository.ToList();//价格单 var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType); - if (errorList.Count() > 0) + if (errorList.Count > 0) { return await ExportErrorReportAsync(errorList); } 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 2fcd29a4..6f0cb6df 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 @@ -118,12 +118,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { if (input.BillNum.Substring(0, 1) == "C")//一次开票 { - - await FirstInvoice(dtos, new List(), main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + if (main.BusinessType == EnumBusinessType.MaiDanJianHBPO || main.BusinessType == EnumBusinessType.BeiJian) + { + var strs=await _invmng.MakeInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, true); + } + else + { + await FirstInvoice(dtos, new List(), main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + } } else//二次开票 { - await SecInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + if (main.BusinessType == EnumBusinessType.MaiDanJianHBPO || main.BusinessType==EnumBusinessType.BeiJian ) + { + var strs=await _invmng.MakeInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType, true); + } + else + { + await SecInvoice(dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + } + } } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs index b2b937af..d9889370 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Jobs/TaskJobService.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; @@ -197,7 +197,8 @@ namespace Win.Sfs.SettleAccount.Entities.TaskJobs ServiceName = _serviceName, InputConditions=conditions }; - + + var _taskId = await _backgroundJobManager.EnqueueAsync(args,BackgroundJobPriority.Normal,TimeSpan.FromSeconds(3)); var options = new JsonSerializerOptions diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs index b911f33d..51df5926 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs @@ -192,7 +192,11 @@ namespace Win.Sfs.SettleAccount CreateMapPUB_NOT_SA_DETAIL(); - + + + CreateMapPUB_ADJ_DETAIL(); + + @@ -299,7 +303,6 @@ namespace Win.Sfs.SettleAccount CreateMap().ReverseMap(); } private void CreateMapPUB_NOT_SA_DETAIL() - { CreateMap().ReverseMap(); CreateMap().ReverseMap(); @@ -307,7 +310,13 @@ namespace Win.Sfs.SettleAccount CreateMap().ReverseMap(); } - + private void CreateMapPUB_ADJ_DETAIL() + { + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/CAN_SA_MNG.cs deleted file mode 100644 index 4ca2c9cf..00000000 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/CAN_SA_MNG.cs +++ /dev/null @@ -1,269 +0,0 @@ -using EFCore.BulkExtensions; -using Hangfire.Annotations; -using Microsoft.EntityFrameworkCore; -using SettleAccount.Bases; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.Abp; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Entities; -using Volo.Abp.Domain.Services; -using Volo.Abp.Guids; -using Volo.Abp.ObjectMapping; -using Win.Sfs.SettleAccount.Bases.DomainServices; -using Win.Sfs.SettleAccount.Boms; -using Win.Sfs.SettleAccount.Entities.Materials; -using Win.Sfs.SettleAccount.MaterialRelationships; -using Win.Sfs.Shared.RepositoryBase; - -namespace Win.Sfs.SettleAccount.Entities.BQ.Managers -{ - public class CAN_SA_MNG : DomainService,ITransientDependency - where TEntity : SA_CAN_BASE_MAIN,new() - where TEntityDetail : SA_CAN_BASE,new() - { - private readonly INormalEfCoreRepository _repository; - private readonly INormalEfCoreRepository _detailRepository; - public CAN_SA_MNG - ( - INormalEfCoreRepository repository, - INormalEfCoreRepository detailRepository - ) - { - _repository = repository; - _detailRepository = detailRepository; - } - - public CAN_SA_MNG() - { - } - - public virtual async Task SetForwardState(TEntity p_entiy, SettleBillState state) - { - if (await SetForwardState(p_entiy.InvGroupNum, state) == true) - { - return true; - } - return false; - - } - - - - - /// - /// 向前流程 - /// - /// - /// - /// - /// - public virtual async Task SetForwardState(string p_billNum, SettleBillState state) - { - - var ls = _repository.Where(p => p.InvGroupNum == p_billNum).ToList(); - if (ls != null && ls.Count > 0) - { - throw new BusinessException("8989", string.Format("不存在编号为{0}",p_billNum)); - } - foreach (TEntity p_entiy in ls) - { - switch (p_entiy.State) - { - case SettleBillState.财务已审核: - if (state == SettleBillState.商务已审核) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【商务已审核】,无法设置成【财务已审核】状态"); - } - break; - case SettleBillState.商务已审核: - if (state == SettleBillState.已开票) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【商务已审核】"); - } - break; - case SettleBillState.已开票: - if (state == SettleBillState.未结状态) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【未结状态】状态,无法设置成【已开票】"); - } - break; - case SettleBillState.已扣减: - if (state == SettleBillState.客户已收票) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是[客户收票],无法设置成【财务已审核】状态"); - } - break; - case SettleBillState.客户已收票: - if (state == SettleBillState.财务已审核) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是[财务已审核],无法设置成【客户已收票】状态"); - } - break; - } - await _repository.UpdateAsync(p_entiy); - return true; - } - return false; - } - /// - /// 向后流程 - /// - /// - /// - /// - /// - public virtual async Task SetBackwardState(string p_billNum, SettleBillState state) - { - - var ls = _repository.Where(p => p.InvGroupNum == p_billNum).ToList(); - if (ls != null && ls.Count > 0) - { - throw new BusinessException("8989", string.Format("不存在发票分组号为{0}的可结算单", p_billNum)); - } - foreach (TEntity p_entiy in ls) - { - - switch (p_entiy.State) - { - case SettleBillState.商务已审核: - if (state == SettleBillState.财务已审核) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【财务已审核】,无法设置成【商务已审核】状态"); - } - break; - case SettleBillState.已开票: - if (state == SettleBillState.商务已审核) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【商务已审核】状态,无法设置成【已开票】"); - } - break; - case SettleBillState.未结状态: - if (state == SettleBillState.已开票) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【未结状态】"); - } - break; - case SettleBillState.客户已收票: - if (state == SettleBillState.已扣减) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是[财务已审核],无法设置成【财务已审核客户收票】状态"); - } - break; - case SettleBillState.财务已审核: - if (state == SettleBillState.客户已收票) - { - p_entiy.State = state; - } - else - { - throw new BusinessException("8989", "当前状态不是[客户已收票],无法设置成【财务已审核】状态"); - } - break; - } - await _repository.UpdateAsync(p_entiy); - return true; - } - return false; - } - - - public virtual async Task SetNewState(TEntity p_entiy) - { - - return await SetNewState(p_entiy.BillNum); - } - - public virtual async Task SetNewState(string billNum) - { - - var entity= await GetMainAsync(billNum); - if (entity != null ) - { - - entity.State = SettleBillState.未结状态; - - - await _repository.UpdateAsync(entity); - return true; - } - return false; - ; - } - /// - /// 获得所有明细 - /// - /// - /// - public virtual async Task> GetDetalListAsync(string billNum) - { - return await _detailRepository.Where(p=>p.InvGroupNum==billNum).ToListAsync(); - } - /// - /// 获得主表信息 - /// - /// - /// - public virtual async Task GetMainAsync(string billNum) - { - return await _repository.Where(p => p.InvGroupNum == billNum).FirstOrDefaultAsync(); - } - - - - - - } - - -} - - - - - - - - - - - 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 cf99b5a9..e5180bdf 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 @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.SignalR; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.EntityFrameworkCore; using NPOI.SS.Formula.Functions; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SettleAccount.Bases; using SettleAccount.Domain.BQ; using System; @@ -13,6 +14,7 @@ using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Auditing; +using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Services; using Win.Sfs.SettleAccount.Bases; @@ -145,7 +147,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers case SettleBillState.财务已审核: if (p_entiy.State == SettleBillState.商务已审核) { - + p_entiy.State = state; } else @@ -177,9 +179,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers var flag = await SetSettleState(p_entiy, p_State, true); if (flag == true) { - await _repository.UpdateAsync(p_entiy); + var invlist = await _repository.Where(p => p.InvGroupNum == p_entiy.InvGroupNum).ToListAsync();//选择审批时只能整组审批 + foreach (var itm in invlist) + { + itm.State = p_entiy.State; + } + await _repository.BatchUpdateAsync(invlist); - return false; + return true; } return false; } @@ -228,13 +235,20 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers break; } var flag = await SetSettleState(p_entiy, p_State, false); - if (flag == false) + + if (flag == true) { - return false; + var invlist = await _repository.Where(p => p.InvGroupNum == p_entiy.InvGroupNum).ToListAsync();//选择审批时只能整组审批 + foreach (var itm in invlist) + { + itm.State = p_entiy.State; + } + await _repository.BatchUpdateAsync(invlist); + + return true; } - await _repository.UpdateAsync(p_entiy); - return true; + return false; } @@ -252,6 +266,18 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers return await _repository.Where(p => p.InvbillNum == p_invbillNum).FirstOrDefaultAsync(); } + /// + /// 获得发票主表 + /// + /// + /// + public virtual async Task> GetMainListAsync(string p_invgroupNum) + { + return await _repository.Where(p => p.InvGroupNum == p_invgroupNum).ToListAsync(); + } + + + /// /// 获得发票主表 /// @@ -263,7 +289,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } - + @@ -276,154 +302,159 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers /// public virtual async Task ReceivedAsync(string p_groupbillnum) { - - var inv = _repository.Where(p => p.InvGroupNum == p_groupbillnum).FirstOrDefault(); - if (inv.BusinessType == EnumBusinessType.JisBBAC) - { - var entity = await _bbacMng.GetMainAsync(inv.InvGroupNum); - if (entity == null) - { - var entityDetail = await _bbacMng.GetDetalListAsync(inv.InvGroupNum); - var bbac = new BBAC_PD( - guid: entity.Id, - version: entity.Version, - billNum: entity.BillNum, - settleBillNum: entity.SettleBillNum, - state: SettleBillState.客户已收票, - invGroupNum: entity.InvGroupNum, - site: entity.Site - ); - var bbacDetail = new List(); - foreach (var itm in entityDetail) - { - bbacDetail.Add( - new BBAC_PD_DETAIL( - guid: itm.Id, - keyCode: itm.KeyCode, - version: itm.Version, - billNum: itm.BillNum, - lU: itm.LU, - rELU: string.Empty, - pN: itm.PN, - rEPN: string.Empty, - site: itm.Site, - qty: itm.Qty, - price: itm.Price, - invGroupNum: itm.InvGroupNum, - settleDate: itm.SettleDate, - groupNum: itm.GroupNum, - extend1: string.Empty, - extend2: string.Empty, - extend3: string.Empty, - extend4: string.Empty - )); - await _repository.DbContext.BulkInsertAsync(new List() { bbac }); - await _repository.DbContext.BulkInsertAsync(bbacDetail); - return true; - } - } - } - else if (inv.BusinessType == EnumBusinessType.JisHBPO) - { - var entity = await _hbpoMng.GetMainAsync(inv.InvGroupNum); - if (entity != null) - { - var entityDetail = await _hbpoMng.GetDetalListAsync(inv.InvGroupNum); - if (entityDetail != null && entityDetail.Count() > 0) - { - var hbpo = new HBPO_PD( - guid: entity.Id, - version: entity.Version, - billNum: entity.BillNum, - settleBillNum: entity.SettleBillNum, - state: SettleBillState.客户已收票, - invGroupNum: entity.InvGroupNum, - site: entity.Site - ); - var hbpoDetail = new List(); - foreach (var itm in entityDetail) - { - hbpoDetail.Add( - new HBPO_PD_DETAIL( - guid: itm.Id, - keyCode: itm.KeyCode, - version: itm.Version, - billNum: itm.BillNum, - lU: itm.LU, - rELU: string.Empty, - pN: itm.PN, - rEPN: string.Empty, - site: itm.Site, - qty: itm.Qty, - price: itm.Price, - invGroupNum: itm.InvGroupNum, - settleDate: itm.SettleDate, - groupNum: itm.GroupNum, - extend1: string.Empty, - extend2: string.Empty, - extend3: string.Empty, - extend4: string.Empty - )); - } - await _repository.DbContext.BulkInsertAsync(new List() { hbpo }); - await _repository.DbContext.BulkInsertAsync(hbpoDetail); - return true; - } - } - } - else - { - var entity = await _pubMng.GetMainAsync(inv.InvGroupNum); - if (entity != null) - { - var entityDetail = await _pubMng.GetDetalListAsync(inv.InvGroupNum); - if (entityDetail != null && entityDetail.Count() > 0) - { - var pub = new PUB_PD( - guid: entity.Id, - version: entity.Version, - billNum: entity.BillNum, - settleBillNum: entity.SettleBillNum, - state: SettleBillState.客户已收票, - invGroupNum: entity.InvGroupNum, - site: entity.Site - ); - var pubDetail = new List(); - foreach (var itm in entityDetail) - { - pubDetail.Add( - new PUB_PD_DETAIL( - guid: itm.Id, - keyCode: itm.KeyCode, - version: itm.Version, - billNum: itm.BillNum, - lU: itm.LU, - rELU: string.Empty, - pN: itm.PN, - rEPN: string.Empty, - site: itm.Site, - qty: itm.Qty, - price: itm.Price, - invGroupNum: itm.InvGroupNum, - settleDate: itm.SettleDate, - groupNum: itm.GroupNum, - extend1: string.Empty, - extend2: string.Empty, - extend3: string.Empty, - extend4: string.Empty, - businessType: itm.BusinessType - )); - } - await _repository.DbContext.BulkInsertAsync(new List() { pub }); - await _repository.DbContext.BulkInsertAsync(pubDetail); - return true; - } - } - } + + + //var inv = _repository.Where(p => p.InvGroupNum == p_groupbillnum).FirstOrDefault(); + //if (inv.BusinessType == EnumBusinessType.JisBBAC) + //{ + // var entity = await _bbacMng.GetMainAsync(inv.InvGroupNum); + // if (entity == null) + // { + + // var entityDetail = await _bbacMng.GetDetalListAsync(inv.InvGroupNum); + // var bbac = new BBAC_PD( + // guid: entity.Id, + // version: entity.Version, + // billNum: entity.BillNum, + // settleBillNum: entity.SettleBillNum, + // state: SettleBillState.客户已收票, + // invGroupNum: entity.InvGroupNum, + // site: entity.Site + // ); + // var bbacDetail = new List(); + + // foreach (var itm in entityDetail) + // { + // bbacDetail.Add( + // new BBAC_PD_DETAIL( + // guid: itm.Id, + // keyCode: itm.KeyCode, + // version: itm.Version, + // billNum: itm.BillNum, + // lU: itm.LU, + // rELU: string.Empty, + // pN: itm.PN, + // rEPN: string.Empty, + // site: itm.Site, + // qty: itm.Qty, + // price: itm.Price, + // invGroupNum: itm.InvGroupNum, + // settleDate: itm.SettleDate, + // groupNum: itm.GroupNum, + // extend1: string.Empty, + // extend2: string.Empty, + // extend3: string.Empty, + // extend4: string.Empty + // )); + // await _repository.DbContext.BulkInsertAsync(new List() { bbac }); + // await _repository.DbContext.BulkInsertAsync(bbacDetail); + // return true; + // } + // } + //} + //else if (inv.BusinessType == EnumBusinessType.JisHBPO) + //{ + // var entity = await _hbpoMng.GetMainAsync(inv.InvGroupNum); + // if (entity != null) + // { + + // var entityDetail = await _hbpoMng.GetDetalListAsync(inv.InvGroupNum); + // if (entityDetail != null && entityDetail.Count() > 0) + // { + // var hbpo = new HBPO_PD( + // guid: entity.Id, + // version: entity.Version, + // billNum: entity.BillNum, + // settleBillNum: entity.SettleBillNum, + // state: SettleBillState.客户已收票, + // invGroupNum: entity.InvGroupNum, + // site: entity.Site + // ); + // var hbpoDetail = new List(); + // foreach (var itm in entityDetail) + // { + // hbpoDetail.Add( + // new HBPO_PD_DETAIL( + // guid: itm.Id, + // keyCode: itm.KeyCode, + // version: itm.Version, + // billNum: itm.BillNum, + // lU: itm.LU, + // rELU: string.Empty, + // pN: itm.PN, + // rEPN: string.Empty, + // site: itm.Site, + // qty: itm.Qty, + // price: itm.Price, + // invGroupNum: itm.InvGroupNum, + // settleDate: itm.SettleDate, + // groupNum: itm.GroupNum, + // extend1: string.Empty, + // extend2: string.Empty, + // extend3: string.Empty, + // extend4: string.Empty + // )); + // } + // await _repository.DbContext.BulkInsertAsync(new List() { hbpo }); + // await _repository.DbContext.BulkInsertAsync(hbpoDetail); + + // return true; + // } + // } + //} + //else + //{ + // var entity = await _pubMng.GetMainAsync(inv.InvGroupNum); + // if (entity != null) + // { + // var entityDetail = await _pubMng.GetDetalListAsync(inv.InvGroupNum); + // if (entityDetail != null && entityDetail.Count() > 0) + // { + // var pub = new PUB_PD( + // guid: entity.Id, + // version: entity.Version, + // billNum: entity.BillNum, + // settleBillNum: entity.SettleBillNum, + // state: SettleBillState.客户已收票, + // invGroupNum: entity.InvGroupNum, + // site: entity.Site + // ); + // var pubDetail = new List(); + // foreach (var itm in entityDetail) + // { + // pubDetail.Add( + // new PUB_PD_DETAIL( + // guid: itm.Id, + // keyCode: itm.KeyCode, + // version: itm.Version, + // billNum: itm.BillNum, + // lU: itm.LU, + // rELU: string.Empty, + // pN: itm.PN, + // rEPN: string.Empty, + // site: itm.Site, + // qty: itm.Qty, + // price: itm.Price, + // invGroupNum: itm.InvGroupNum, + // settleDate: itm.SettleDate, + // groupNum: itm.GroupNum, + // extend1: string.Empty, + // extend2: string.Empty, + // extend3: string.Empty, + // extend4: string.Empty, + // businessType: itm.BusinessType + // )); + // } + // await _repository.DbContext.BulkInsertAsync(new List() { pub }); + // await _repository.DbContext.BulkInsertAsync(pubDetail); + // return true; + // } + // } + //} return false; } public virtual async Task Reject(INVOICE_GRP p_entity) @@ -445,9 +476,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers if (ls != null && ls.Count > 0) { var first = ls.FirstOrDefault(); - if(first.State==SettleBillState.客户已收票 || first.State== SettleBillState.已扣减) + if (first.State == SettleBillState.客户已收票 || first.State == SettleBillState.已扣减) { - throw new BusinessException("8989",$"发票分组{groupbillNum}客户已经是客户已收票或已扣减状态不能退回"); + throw new BusinessException("8989", $"发票分组{groupbillNum}客户已经是客户已收票或已扣减状态不能退回"); } foreach (var p_entity in ls) { @@ -464,7 +495,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers await _repository.DbContext.BulkDeleteAsync(detailList); if (first.BusinessType == EnumBusinessType.JisBBAC) { - await _bbacMng.SetNewState(groupbillNum); + await _bbacMng.SetNewState(groupbillNum); } else if (first.BusinessType == EnumBusinessType.JisHBPO) { @@ -476,12 +507,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } //await _repository.DbContext.BulkUpdateAsync(canList); } - + } } else { - throw new BusinessException("8989",$"查询不到发票分组号为{groupbillNum}发票分组"); + throw new BusinessException("8989", $"查询不到发票分组号为{groupbillNum}发票分组"); } return true; } @@ -533,7 +564,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers //{ //} return true; - } /// /// hbpo、jit、备件等 @@ -545,7 +575,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers public async Task> SecInvoice(List dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) { List _invls = new List(); - var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV { LU = p.Key.LU, @@ -555,7 +584,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.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV { @@ -712,6 +740,198 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } + + + + /// + /// hbpojis,备件 + /// + /// 可结算明细列表 + /// 版本号 + /// 发票分组 + /// 原发票号 + public async Task> MakeInvoice(List dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType, bool p_first) + { + List _invls = new List(); + var groups1 = dtos.GroupBy(p => new { p.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV + { + 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.LU, p.Price, p.BeginDate, p.EndDate, p.ContractDocID }).Select(p => new TMEP_INV + { + 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> invoiceMap = new Dictionary>();//发票和发票明细关系 + foreach (var group in groups) + { + int i = groups1.Count(p => p.LU == group.LU + && p.BeginDate == group.BeginDate + && p.EndDate == group.EndDate + && p.ContractDocID == group.ContractDocID + ); + if (i > 0) + { + string invoiceBillNum = string.Empty; + if (p_first == true) + { + invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + } + else + { + invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("CINV"); + } + + List tempList = new List(); + decimal sum = group.Amt;//初始合计金额 + int partCount = 0; + foreach (var group1 in groups1) + { + if (group.LU == group1.LU + && 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 } + equals new { itm1.LU, itm1.BeginDate, itm1.EndDate, itm1.ContractDocID } 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(); + var notDetialList = new List(); + var detailList = new List(); + var invlist = new List(); + foreach (var group in invoiceMap) + { + var key = group.Key;//发票票号 + var ls = group.Value;//发票明细 + List _entityDetailList = new List(); + 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: string.Empty, + extend2: string.Empty, + beginDate: detail.BeginDate, + endDate: detail.EndDate + )); + } + if (_entityDetailList.Count > 0) + { + detailList.AddRange(_entityDetailList); + } + 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, + invbillNum: key, + amt: amt, + taxAmt: txtAmt, + fileName: string.Empty, + businessType: businessType, + invGroupNum: p_InvGroupNum, + state: SettleBillState.已开票, + invoiceBillState: InvoiceBillState.正常, + tax: 0, + parent: p_parentInvBillNum + ); + invlist.Add(invbill); + } + await _repository.DbContext.BulkInsertAsync(invlist); + //await _repository.DbContext.BulkInsertAsync(groupList); + await _repository.DbContext.BulkInsertAsync(detailList); + //await _repository.DbContext.BulkInsertAsync(notDetialList); + _invls = invlist.Select(p => p.InvbillNum).ToList(); + } + return _invls; + + } + + + + + + /// /// 第一次开票 /// @@ -844,10 +1064,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.GroupBy(p => new { p.GroupNum, p.LU }).Select(p => new { GroupNum = p.Key.GroupNum, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty) }); @@ -893,9 +1110,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { await _repository.DbContext.BulkInsertAsync(notDetialList); } - _invls =invlist.Select(p => p.InvbillNum).ToList(); + _invls = invlist.Select(p => p.InvbillNum).ToList(); } - + return _invls; } @@ -907,7 +1124,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers /// /// /// - public async Task ReissueFirstInvoice(List dtos,List p_adjlist, string p_OldInvBillNum, int p_version) + public async Task ReissueFirstInvoice(List dtos, List p_adjlist, string p_OldInvBillNum, int p_version) { if (!string.IsNullOrEmpty(p_OldInvBillNum)) { @@ -922,7 +1139,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers throw new BusinessException("8989", $"选择要重开发票号{p_OldInvBillNum}已经作废不能重开"); } inv.InvoiceState = InvoiceBillState.报废; - var invlist=await FirstInvoice(dtos, new List(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票 + + List invlist = new List(); + if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) + { + invlist = await MakeInvoice(dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); + } + else + { + invlist = await FirstInvoice(dtos, new List(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票 + } + if (invlist.Count == 0) { return false; @@ -930,11 +1157,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers foreach (var adj in p_adjlist) { - adj.InvBillNum = string.Join(",", invlist); + adj.InvBillNum = string.Join(",", invlist);//调整单更新发票信息 } _repository.DbContext.BulkUpdate(p_adjlist); - + _repository.DbContext.BulkUpdate(new List { inv }); return true; } @@ -964,7 +1191,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } inv.InvoiceState = InvoiceBillState.报废; - var invlist =await SecInvoice(dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); + List invlist = new List(); + if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO || inv.BusinessType == EnumBusinessType.BeiJian) + { + invlist = await MakeInvoice(dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); + } + else + { + invlist = await SecInvoice(dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType); + } + + if (invlist.Count == 0) { return false; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/NOT_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/NOT_SA_MNG.cs deleted file mode 100644 index d034a33b..00000000 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/NOT_SA_MNG.cs +++ /dev/null @@ -1,89 +0,0 @@ -using SettleAccount.Bases; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.Abp.Domain.Services; -using Volo.Abp; -using Win.Sfs.Shared.RepositoryBase; -using Win.Sfs.SettleAccount.Bases; -using EFCore.BulkExtensions; - -namespace Win.Sfs.SettleAccount.Entities.BQ.Managers -{ - /// - /// 不能結算管理 - /// - /// - /// - /// - public class NOT_SA_MNG : DomainService - where TEntity : SA_CAN_BASE_MAIN, new() - where TEntityDetail : SA_CAN_BASE, new() - where TNOTDetail : SA_NOT_BASE - { - private readonly INormalEfCoreRepository _repository; - private readonly INormalEfCoreRepository _detailRepository; - private readonly INormalEfCoreRepository _notRepository; - - public NOT_SA_MNG() - { - } - - public NOT_SA_MNG - ( - INormalEfCoreRepository repository, - INormalEfCoreRepository detailRepository, - INormalEfCoreRepository notRepository - ) - { - _repository = repository; - _detailRepository = detailRepository; - _notRepository = notRepository; - } - - - - public virtual async Task GenerateSettlementOrder(List p_list, Action> p_action = null) - { - - var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); - var _entity = new TEntity(); - _entity.BillNum = billNumber; - _entity.InvGroupNum = billNumber; - _entity.Version = DateTime.Now.Year + DateTime.Now.Month; - _entity.State = SettleBillState.未结状态; - _entity.SettleBillNum = string.Empty; - var _entityList = new List(); - foreach (var itm in p_list) - { - var _detailEntity = new TEntityDetail(); - { - _detailEntity.SettleBillNum = itm.SettleBillNum; - _detailEntity.BillNum = billNumber; - _detailEntity.InvGroupNum = billNumber; - _detailEntity.LU = itm.LU; - _detailEntity.PN = itm.PN; - _detailEntity.GroupNum = itm.GroupNum; - _detailEntity.KeyCode = itm.KeyCode; - _detailEntity.Price = itm.Price; - _detailEntity.Version = itm.Version; - }; - _entityList.Add(_detailEntity); - } - if (_entityList.Count > 0) - { - p_action(_entityList);//对不一样类型结算数据进行处理 - } - await _notRepository.DbContext.BulkDeleteAsync(p_list); - await _repository.DbContext.BulkInsertAsync(new List() { _entity }); - await _repository.DbContext.BulkInsertAsync(_entityList); - - - return true; - } - - - } -} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_ADJ_DETAIL.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_ADJ_DETAIL.cs index 5c69b5e2..b8e954b8 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_ADJ_DETAIL.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/PUB_ADJ_DETAIL.cs @@ -71,10 +71,11 @@ public class PUB_ADJ_DETAIL : SA_NOT_BASE public string InvBillNum { get; set; } - public PUB_ADJ_DETAIL(string keyCode, int version, string settleBillNum, string lU, string pN, + public PUB_ADJ_DETAIL(Guid id, string keyCode, int version, string settleBillNum, string lU, string pN, string site, decimal qty, string extend1, decimal price, string invGroupNum, DateTime settleDate, EnumBusinessType businessType, string groupNum,string oldinv,string inv) { + Id= id; KeyCode = keyCode; Version = version; SettleBillNum = settleBillNum; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs index e33fc8de..36531c54 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs @@ -184,3 +184,16 @@ public class TEMP_NOT_SA_DETAIL : SA_NOT_BASE } + + + +public class TEMP_PD_SW +{ + public string LU { set; get; } + public string PN { set; get; } + public string RepLU { set; get; } + public string BusinessType { set; get; } + public string KeyCode { set; get; } + + +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs index 8be265d7..bb130304 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/EnumBillState.cs @@ -41,7 +41,9 @@ namespace Win.Sfs.SettleAccount 报废 = 2, [Description("替换")] 替换 = 3, - + + [Description("提交")] + 提交 = 3, diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs new file mode 100644 index 00000000..7801d0fc --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/PendingDeduction/PendingDeductionDapperRepository.cs @@ -0,0 +1,370 @@ +using Dapper; +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.EntityFrameworkCore; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Domain.Repositories.Dapper; +using Volo.Abp.EntityFrameworkCore; +using Win.Sfs.SettleAccount.Entities; +using Win.Sfs.SettleAccount.Entities.BQ.Temp; +using Win.Sfs.SettleAccount.Entities.Prices; +using Win.Sfs.SettleAccount.Reports; +using Win.Sfs.SettleAccount.Reports.InvoiceSettledDiffs; + +namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report +{ + + /// + /// 2.大众发票与结算核对明细表-准时化 + /// + public class PendingDeductionDapperRepository : DapperRepository, ITransientDependency + { + public PendingDeductionDapperRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + /// + /// BBAC生成待扣减 + /// + /// + /// + public Dictionary> GenerationPendingDeductionBBAC(string p_invGroup) + { + var sqljis = "WITH t1 AS(\n" + + "SELECT\n" + + "DISTINCT sa.KeyCode,\n" + + "sa.LU,\n" + + "sa.PN,\n" + + "sa.BusinessType\n" + + "FROM\n" + + "(\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_BBAC_CAN_SA_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}'\n" + + "UNION ALL\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_PUB_ADJ_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}') sa\n" + + "LEFT JOIN\n" + + "Set_BBAC_SE_DETAIL se ON\n" + + "sa.KeyCode = se.KeyCode\n" + + "WHERE\n" + + "se.PN IS NULL\n" + + ")\n" + + "select tmp1.* from\n" + + "(\n" + + "SELECT\n" + + "t1.LU,\n" + + "t1.PN,\n" + + "t2.RepLU,\n" + + "t1.BusinessType,\n" + + "(t1.PN + t2.RepLU) KeyCode\n" + + "FROM\n" + + "t1\n" + + "INNER JOIN Set_TB_RePartsRelationship t2\n" + + "ON\n" + + "t1.LU = t2.LU\n" + + "AND t1.BusinessType = t2.BusinessType) tmp1\n" + + "INNER JOIN Set_BBAC_SE_DETAIL tmp2 ON\n" + + "tmp1.KeyCode = tmp2.KeyCode\n"; + + var inv = DbConnection.Query($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); + Dictionary> result = new Dictionary>(); + + var detail = DbConnection.Query($"select * from set_BBAC_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); + var main = DbConnection.Query($"select * from set_BBAC_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); + + var entity = main; + if (entity == null) + { + var templist = DbConnection.Query(string.Format(sqljis, p_invGroup)); + + var entityDetail = detail; + var bbac = new BBAC_PD( + guid: entity.Id, + version: entity.Version, + billNum: entity.BillNum, + settleBillNum: entity.SettleBillNum, + state: SettleBillState.客户已收票, + invGroupNum: entity.InvGroupNum, + site: entity.Site + ); + + var query = from itm in detail + join itm1 in templist on itm.KeyCode equals itm1.KeyCode + into temp1 + from tm1 in temp1.DefaultIfEmpty() + select new BBAC_PD_DETAIL( + guid: itm.Id, + keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, + version: itm.Version, + billNum: itm.BillNum, + lU: itm.LU, + rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, + pN: itm.PN, + rEPN: itm.PN, + site: itm.Site, + qty: itm.Qty, + price: 0, + invGroupNum: itm.InvGroupNum, + settleDate: itm.SettleDate, + groupNum: itm.GroupNum, + extend1: string.Empty, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + ); + var bbacDetail = query.ToList(); + + result.Add(bbac, bbacDetail); + } + return result; + } + + /// + /// BBAC生成待扣减 + /// + /// + /// + public Dictionary> GenerationPendingDeductionHBPO(string p_invGroup) + { + + var sqljis = "WITH t1 AS(\n" + + "SELECT\n" + + "DISTINCT sa.KeyCode,\n" + + "sa.LU,\n" + + "sa.PN,\n" + + "sa.BusinessType\n" + + "FROM\n" + + "(\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_HBPO_CAN_SA_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}'\n" + + "UNION ALL\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_PUB_ADJ_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}') sa\n" + + "LEFT JOIN\n" + + "Set_HBPO_SE_DETAIL se ON\n" + + "sa.KeyCode = se.KeyCode\n" + + "WHERE\n" + + "se.PN IS NULL\n" + + ")\n" + + "select tmp1.* from\n" + + "(\n" + + "SELECT\n" + + "t1.LU,\n" + + "t1.PN,\n" + + "t2.RepLU,\n" + + "t1.BusinessType,\n" + + "(t1.PN + t2.RepLU) KeyCode\n" + + "FROM\n" + + "t1\n" + + "INNER JOIN Set_TB_RePartsRelationship t2\n" + + "ON\n" + + "t1.LU = t2.LU\n" + + "AND t1.BusinessType = t2.BusinessType) tmp1\n" + + "INNER JOIN Set_HBPO_SE_DETAIL tmp2 ON\n" + + "tmp1.KeyCode = tmp2.KeyCode\n"; + + var inv = DbConnection.Query($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); + Dictionary> result = new Dictionary>(); + var detail = DbConnection.Query($"select * from set_HBPO_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); + var main = DbConnection.Query($"select * from set_HBPO_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); + + var entity = main; + if (entity == null) + { + var templist = DbConnection.Query(string.Format(sqljis, p_invGroup)); + + var entityDetail = detail; + var bbac = new HBPO_PD( + guid: entity.Id, + version: entity.Version, + billNum: entity.BillNum, + settleBillNum: entity.SettleBillNum, + state: SettleBillState.客户已收票, + invGroupNum: entity.InvGroupNum, + site: entity.Site + ); + + var query = from itm in detail + join itm1 in templist on itm.KeyCode equals itm1.KeyCode + into temp1 + from tm1 in temp1.DefaultIfEmpty() + select new HBPO_PD_DETAIL( + guid: itm.Id, + keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, + version: itm.Version, + billNum: itm.BillNum, + lU: itm.LU, + rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, + pN: itm.PN, + rEPN: itm.PN, + site: itm.Site, + qty: itm.Qty, + price: 0, + invGroupNum: itm.InvGroupNum, + settleDate: itm.SettleDate, + groupNum: itm.GroupNum, + extend1: string.Empty, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + ); + var bbacDetail = query.ToList(); + + result.Add(bbac, bbacDetail); + } + return result; + + } + + + /// + /// 其他业务生成待扣减 + /// + /// + /// + public Dictionary> GenerationPendingDeductionPUB(string p_invGroup) + { + + var sqljis = "WITH t1 AS(\n" + + "SELECT\n" + + "DISTINCT sa.KeyCode,\n" + + "sa.LU,\n" + + "sa.PN,\n" + + "sa.BusinessType\n" + + "FROM\n" + + "(\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_PUB_CAN_SA_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}'\n" + + "UNION ALL\n" + + "SELECT\n" + + "keycode,\n" + + "LU,\n" + + "PN,\n" + + "BusinessType\n" + + "FROM\n" + + "Set_PUB_ADJ_DETAIL\n" + + "WHERE\n" + + "InvGroupNum = '{0}') sa\n" + + "LEFT JOIN\n" + + "Set_PUB_SE_DETAIL se ON\n" + + "sa.KeyCode = se.KeyCode\n" + + "WHERE\n" + + "se.PN IS NULL\n" + + ")\n" + + "select tmp1.* from\n" + + "(\n" + + "SELECT\n" + + "distinct " + + "t1.LU,\n" + + "t1.PN,\n" + + "t2.RepLU,\n" + + "t1.BusinessType,\n" + + "(t1.PN + t2.RepLU) KeyCode\n" + + "FROM\n" + + "t1\n" + + "INNER JOIN Set_TB_RePartsRelationship t2\n" + + "ON\n" + + "t1.LU = t2.LU\n" + + "AND t1.BusinessType = t2.BusinessType) tmp1\n" + + "INNER JOIN Set_PUB_SE_DETAIL tmp2 ON\n" + + "tmp1.KeyCode = tmp2.KeyCode\n"; + + var inv = DbConnection.Query($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); + Dictionary> result = new Dictionary>(); + var detail = DbConnection.Query($"select * from set_PUB_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); + var main = DbConnection.Query($"select * from set_PUB_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); + + var entity = main; + if (entity == null) + { + var templist = DbConnection.Query(string.Format(sqljis, p_invGroup)); + var entityDetail = detail; + var bbac = new PUB_PD( + guid: entity.Id, + version: entity.Version, + billNum: entity.BillNum, + settleBillNum: entity.SettleBillNum, + state: SettleBillState.客户已收票, + invGroupNum: entity.InvGroupNum, + site: entity.Site + ); + var query = from itm in detail + join itm1 in templist on itm.KeyCode equals itm1.KeyCode + into temp1 + from tm1 in temp1.DefaultIfEmpty() + select new PUB_PD_DETAIL( + guid: itm.Id, + keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, + version: itm.Version, + billNum: itm.BillNum, + lU: itm.LU, + rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, + pN: itm.PN, + rEPN: itm.PN, + site: itm.Site, + qty: itm.Qty, + price: 0, + invGroupNum: itm.InvGroupNum, + settleDate: itm.SettleDate, + groupNum: itm.GroupNum, + extend1: string.Empty, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty, + businessType:itm.BusinessType + ); + var bbacDetail = query.ToList(); + result.Add(bbac, bbacDetail); + } + return result; + } + + + } +} + diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/PD_SERVICE.cs new file mode 100644 index 00000000..cfc780f2 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/PD_SERVICE.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Data.Common; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using EFCore.BulkExtensions; +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using NPOI.OpenXmlFormats.Spreadsheet; +using SettleAccount.Domain.BQ; +using TaskJob.EventArgs; +using TaskJob.Interfaces; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Domain.Repositories; +using Win.Sfs.SettleAccount; +using Win.Sfs.SettleAccount.Entities.BQ.Managers; +using Win.Sfs.SettleAccount.Entities.SettleAccounts; +using Win.Sfs.SettleAccount.ExportReports; +using Win.Sfs.SettleAccount.Repository.SettleAccount; +using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; +using Win.Sfs.Shared.RepositoryBase; + +namespace SettleAccount.Job.Services +{ + public class PD_SERVICE : ITransientDependency, IExportJob + { + private readonly PendingDeductionDapperRepository _dapper; + private readonly INormalEfCoreRepository _invRepository; + + public PD_SERVICE(PendingDeductionDapperRepository dapper, + + INormalEfCoreRepository invRepository + + ) + { + _dapper = dapper; + _invRepository = invRepository; + } + /// + /// 执行发票待开任务 + /// + /// + /// + /// + /// + public string ExportFile(Guid id, List exportName, List customConditions) + { + var invgroup = customConditions.Where(p => p.Name == "InvoiceGroupNum").FirstOrDefault().Value; + var ls = _invRepository.Where(p => p.InvGroupNum == invgroup).ToList(); + if (ls != null && ls.Count>0) + { + var first=ls.FirstOrDefault(); + if (first.BusinessType == EnumBusinessType.JisHBPO) + { + var pd = _dapper.GenerationPendingDeductionHBPO(invgroup); + if (pd.Count > 0) + { + foreach (var c in pd) + { + var main = c.Key; + var detail = c.Value; + _invRepository.DbContext.BulkInsert(new List() { main }); + _invRepository.DbContext.BulkInsert(detail); + } + } + else + { + + } + } + else if (first.BusinessType == EnumBusinessType.JisBBAC) + { + var pd = _dapper.GenerationPendingDeductionBBAC(invgroup); + if (pd.Count > 0) + { + foreach (var c in pd) + { + var main = c.Key; + var detail = c.Value; + _invRepository.DbContext.BulkInsert(new List() { main }); + _invRepository.DbContext.BulkInsert(detail); + } + } + else + { + + } + } + else + { + var pd = _dapper.GenerationPendingDeductionPUB(invgroup); + if (pd.Count > 0) + { + foreach (var c in pd) + { + var main = c.Key; + var detail = c.Value; + _invRepository.DbContext.BulkInsert(new List() { main }); + _invRepository.DbContext.BulkInsert(detail); + } + } + else + { + + } + } + } + return id.ToString(); + } + + + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDetailDiffExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDetailDiffExportService.cs index 31c9913a..2fc90975 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDetailDiffExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDetailDiffExportService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleDoorPanelExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleDoorPanelExportService.cs index 1fedcaca..0e05314b 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleDoorPanelExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleDoorPanelExportService.cs @@ -1,4 +1,4 @@ -using Magicodes.ExporterAndImporter.Excel; +using Magicodes.ExporterAndImporter.Excel; using Shouldly; using System; using System.Collections.Generic; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/UnInvoiceSettledDetailDiffExportService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/UnInvoiceSettledDetailDiffExportService.cs index 2624afbd..cba5f713 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/UnInvoiceSettledDetailDiffExportService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/UnInvoiceSettledDetailDiffExportService.cs @@ -1,4 +1,4 @@ -using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Excel; using Shouldly; using System;