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 0849859f..6841213d 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 @@ -247,11 +247,11 @@ namespace Win.Sfs.SettleAccount.Bases /// protected async Task> CheckInvoiceGenerationRules(List dto1s, string p_site, List p_pricelist, EnumBusinessType p_businessType) where T : SA_CAN_BASE { - //var maxDate = p_pricelist.Max(p => p.Date); - var first = dto1s.FirstOrDefault(); + var usepriceList = p_pricelist.Where(p => p.ClientCode == first.Site && p.IsCancel == false).ToList(); + var errorlist = _baseservice.CheckPriceListContinuity(usepriceList); var prices = p_pricelist.Where(p => p.ClientCode == p_site && p.IsCancel == false).ToList(); @@ -262,13 +262,13 @@ namespace Win.Sfs.SettleAccount.Bases d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.ClientCode == d.Site && p.IsCancel == false select d; var ls = inner.ToList(); + var left = from d in dto1s join p in inner on new { d.LU, d.PN } equals new { p.LU, p.PN } into temp from tm in temp.DefaultIfEmpty()//校验错误项 where tm == null select d; - List errorList = new List(); string name = string.Empty; string keyname = string.Empty; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs index 46cec725..8a5a1556 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs @@ -31,11 +31,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ [Route("api/settleaccount/[controller]/[action]")] public class BBAC_BA_SERVICE : BA_SERVICE { - private readonly INormalEfCoreRepository _priceRepository; private readonly INormalEfCoreRepository _pdRepository; private readonly INormalEfCoreRepository _relationRepository; - private readonly ADJ_SERVICE _adjservice; public BBAC_BA_SERVICE(IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, @@ -137,13 +135,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据 var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); //var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算 var priceList = _priceRepository.Where(p => p.IsCancel == false).ToList();//价格单 - // priceList.GroupBy(p => new { p.BeginTime, p.EndTime }).Select(p => p.First()); - var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType).ConfigureAwait(false); if (errorList.Count > 0) { @@ -326,20 +321,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ return new JsonResult(new { Code = 200, Message = "重开成功" }); ; } - - - - - - - - - - - - - - [HttpPost] [UnitOfWork(false)] /// @@ -638,7 +619,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ throw new UserFriendlyException($"不存发票号为:{invbillnum}发票", "400"); } } - var als = invBilllist.Where(p => string.IsNullOrEmpty(p.LU)).ToList(); var invlist = invBilllist.OrderBy(p => p.LU).ToList(); return new JsonResult(new { Code = 200, Data = invlist }); @@ -678,9 +658,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 var inv = await GetInvoiceGroupByInvBillNum(invbillnum).ConfigureAwait(false); - - - if (inv == null) { throw new UserFriendlyException($"无原发票记录!", "400"); @@ -698,10 +675,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ throw new UserFriendlyException($"发票只有在财务已审核、红冲状态下可以报废!", "400"); } - - - - var settle = await _bbacMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); if (settle == null) 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 00061dfa..efe44a65 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 @@ -3,10 +3,14 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DocumentFormat.OpenXml.Bibliography; using LinqToDB; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Org.BouncyCastle.Asn1.Ocsp; using SettleAccount.Domain.BQ; +using SettleAccount.Job.Services; +using TaskJob.EventArgs; using Volo.Abp.Uow; using Win.Abp.Snowflakes; using Win.Sfs.BaseData.ImportExcelCommon; @@ -16,8 +20,10 @@ 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.Entities.BQ.Syncs; using Win.Sfs.SettleAccount.Entities.BQ.Temp; using Win.Sfs.SettleAccount.Entities.Prices; +using Win.Sfs.SettleAccount.Entities.TaskJobs; using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ @@ -43,6 +49,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ private readonly INormalEfCoreRepository _priceRepository; + + private readonly TaskJobService _service; + private readonly BBAC_CAN_SA_MNG _bbacMng; public BBAC_CAN_SA_SERVICE(IExcelImportAppService excelImportService, @@ -54,10 +63,12 @@ namespace Win.Sfs.SettleAccount.Entities.BQ INormalEfCoreRepository notRepository, INormalEfCoreRepository priceRepository, BBAC_CAN_SA_MNG bbacMng, - BaseDomainService baseservice + BaseDomainService baseservice, + TaskJobService service ) : base(excelImportService, snowflakeIdGenerator, commonManager, repository, detailRepository, invmng, baseservice) { + _service = service; _notRepository = notRepository; _bbacMng = bbacMng; _priceRepository = priceRepository; @@ -89,67 +100,80 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, Message = "错误提示文件已下载,请打开文件查看", fileName = await ExportErrorReportAsync(errorList).ConfigureAwait(false) }); } - if (await _bbacMng.SetForwardState(main, SettleBillState.已开票).ConfigureAwait(false)) + + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "BillNum", Value = invbillNum }); + customConditionList.Add(new CustomCondition() { Name = "BussinessType", Value = main.BusinessType.ToString() }); + + //main.State = SettleBillState.发票生成中; + await _bbacMng.SetWaitingState(invbillNum); + var _taskid = await _service.ExportEnqueueAsync("生成发票任务", ExportExtentsion.Excel, string.Empty, string.Empty, CurrentUser, typeof(GenerateJisInvoiceService), customConditionList, (rs) => { - var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - var notQuery = await _notRepository.Where(p => p.SettleBillNum == main.SettleBillNum).ToListAsync().ConfigureAwait(false); - var dto1s = ObjectMapper.Map, List>(entitys); - var q = from d in dto1s - join p in priceList on d.LU equals p.LU - where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == main.Site - select new TEMP_CAN_SA_DETAIL - { - SettleBillNum = d.SettleBillNum, - Site = d.Site, - Version = d.Version, - Price = p.Price, - BillNum = d.BillNum, - SettleDate = d.SettleDate, - InvGroupNum = d.InvGroupNum, - LU = d.LU, - MaterialDesc = d.MaterialDesc, - PN = d.PN, - Qty = d.Qty, - GroupNum = d.GroupNum, - Amt = Math.Round(d.Qty * p.Price, 2), - ContractDocID = d.ContractDocID, - BeginDate = p.BeginTime, - EndDate = p.EndTime, - PartCode = d.PartCode - }; - var dtos = q.ToList(); + }).ConfigureAwait(false); + - if (dtos != null && dtos.Count > 0) - { - if (invbillNum.Substring(0, 1) == "C")//一次开票 - { - var notlist = notQuery.Select(p => new TEMP_NOT_SA_DETAIL - { - KeyCode = p.KeyCode, - Version = p.Version, - SettleBillNum = p.SettleBillNum, - LU = p.LU, - PN = p.PN, - Site = p.Site, - Qty = p.Qty, - Price = p.Price, - BusinessType = p.BusinessType, - IsReturn = "", - InvGroupNum = p.InvGroupNum, - SettleDate = p.SettleDate, - GroupNum = p.GroupNum, - ContractDocID = string.Empty, - PartCode = p.PartCode - }).ToList();//不能结算 - await FirstInvoice(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false); - } - else//二次开票 - { - await SecInvoice(entitys, new List(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false); - } - } - } + //if (await _bbacMng.SetForwardState(main, SettleBillState.已开票).ConfigureAwait(false)) + //{ + // var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); + // var notQuery = await _notRepository.Where(p => p.SettleBillNum == main.SettleBillNum).ToListAsync().ConfigureAwait(false); + // var dto1s = ObjectMapper.Map, List>(entitys); + // var q = from d in dto1s + // join p in priceList on d.LU equals p.LU + // where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == main.Site + // select new TEMP_CAN_SA_DETAIL + // { + // SettleBillNum = d.SettleBillNum, + // Site = d.Site, + // Version = d.Version, + // Price = p.Price, + // BillNum = d.BillNum, + // SettleDate = d.SettleDate, + // InvGroupNum = d.InvGroupNum, + // LU = d.LU, + // MaterialDesc = d.MaterialDesc, + // PN = d.PN, + // Qty = d.Qty, + // GroupNum = d.GroupNum, + // Amt = Math.Round(d.Qty * p.Price, 2), + // ContractDocID = d.ContractDocID, + // BeginDate = p.BeginTime, + // EndDate = p.EndTime, + // PartCode = d.PartCode + // }; + // var dtos = q.ToList(); + + // if (dtos != null && dtos.Count > 0) + // { + // if (invbillNum.Substring(0, 1) == "C")//一次开票 + // { + // var notlist = notQuery.Select(p => new TEMP_NOT_SA_DETAIL + // { + // KeyCode = p.KeyCode, + // Version = p.Version, + // SettleBillNum = p.SettleBillNum, + // LU = p.LU, + // PN = p.PN, + // Site = p.Site, + // Qty = p.Qty, + // Price = p.Price, + // BusinessType = p.BusinessType, + // IsReturn = "", + // InvGroupNum = p.InvGroupNum, + // SettleDate = p.SettleDate, + // GroupNum = p.GroupNum, + // ContractDocID = string.Empty, + // PartCode = p.PartCode + + // }).ToList();//不能结算 + // await FirstInvoice(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false); + // } + // else//二次开票 + // { + // await SecInvoice(entitys, new List(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false); + // } + // } + //} } else { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs index c7c27d99..6a091635 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs @@ -114,11 +114,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs public string ExportFile(Guid id, List exportName, List property) { var billNum = property.Where(p => p.Name == "BillNum").FirstOrDefault().Value; - var BussinessType = property.Where(p => p.Name == "BussinessType").FirstOrDefault().Value; - - if (BussinessType == "BBACJIS") + if (BussinessType == "JisBBAC") { var main = _dbcontext.Set().FirstOrDefault(p => p.InvGroupNum == billNum); //var main = await _bbacMng.GetMainAsync(invbillNum); @@ -177,13 +175,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs PartCode = p.PartCode }).ToList();//不能结算 - var invs= FirstInvoice(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); + var invs = FirstInvoice(entitys, new List(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType); if (invs.Count > 0) { main.State = SettleBillState.已开票; } - - } else//二次开票 { @@ -195,11 +191,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } } _dbcontext.BulkUpdate(new List() { main }); - - } } - if(BussinessType=="HBPOJIS") + if(BussinessType== "JisHBPO") { var main = _dbcontext.Set().FirstOrDefault(p => p.InvGroupNum == billNum); //var main = await _bbacMng.GetMainAsync(invbillNum); @@ -278,7 +272,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } return id.ToString(); } - public List SecInvoice(List p_list, List p_ajdlist, List dtos, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType) where TDetail : SA_CAN_BASE { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs index 8e46e6c6..515c588f 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs @@ -85,7 +85,13 @@ namespace Win.Sfs.SettleAccount { return implementationFactory.GetService(); } + if (key.Equals(typeof(GenerateJisInvoiceService).FullName)) + { + return implementationFactory.GetService(); + } + + else { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_CAN_SA.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_CAN_SA.cs index b50d3e1c..0cad5d93 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_CAN_SA.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_CAN_SA.cs @@ -11,12 +11,10 @@ namespace SettleAccount.Domain.BQ //[Display(Name = "期间")] //public int Version { get; set; } - //[Display(Name = "结算单据")] //public string BillNum { get; set; } = null!; //[Display(Name = "关联结算单号")] //public string SettleBillNum { get; set; } = null!; - ///// ///// 1、新建 2、已有出库3、已有扣减寄售库 ///// @@ -47,7 +45,6 @@ namespace SettleAccount.Domain.BQ } } - [Display(Name = "BBAC可结算导入明细")] public class BBAC_CAN_SA_DETAIL : SA_CAN_BASE { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs index a860d19a..c85ee5b9 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs @@ -205,6 +205,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers return false; ; } + public virtual async Task SetWaitingState(string billNum) + { + + var entity = await GetMainAsync(billNum).ConfigureAwait(false); + if (entity != null) + { + entity.State = SettleBillState.发票生成中; + await _repository.UpdateAsync(entity).ConfigureAwait(false); + return true; + } + return false; + ; + } + + + /// /// 获得所有明细 ///