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 d2c3200d..4ff28d13 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 @@ -9,6 +9,7 @@ using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using SettleAccount.Bases; +using SettleAccount.Domain.BQ; using SettleAccount.Job.Services; using Shouldly; using System; @@ -35,6 +36,7 @@ using Win.Sfs.SettleAccount.Entities.TaskJobs; using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.Shared.RepositoryBase; +using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; namespace Win.Sfs.SettleAccount.Bases { @@ -50,10 +52,10 @@ namespace Win.Sfs.SettleAccount.Bases protected readonly VmiAppService _vimservice; protected readonly INormalEfCoreRepository _repository; protected readonly INormalEfCoreRepository _detailRepository; - protected readonly INormalEfCoreRepository _bbacSecRepository; protected readonly INormalEfCoreRepository _hbpoSecRepository; protected readonly INormalEfCoreRepository _pubSecRepository; + protected readonly INormalEfCoreRepository _invRepository; private readonly TaskJobService _service; public PD_SERVICE( @@ -66,7 +68,8 @@ namespace Win.Sfs.SettleAccount.Bases INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, - TaskJobService service + TaskJobService service, + INormalEfCoreRepository invRepository ) : base(excelImportService, snowflakeIdGenerator, commonManager) { _service = service; @@ -76,6 +79,7 @@ namespace Win.Sfs.SettleAccount.Bases _bbacSecRepository = bbacSecRepository; _pubSecRepository = pubSecRepository; _hbpoSecRepository = hbpoSecRepository; + _invRepository = invRepository; } /// @@ -136,30 +140,59 @@ namespace Win.Sfs.SettleAccount.Bases [UnitOfWork(false)] public virtual async Task ApprovalPassed(List p_list) { - var bussinessType=p_list.FirstOrDefault(); - - - - - return await InvokePD(p_list, _service); } [HttpPost] [UnitOfWork(false)] public virtual async Task RejectAsync(List p_list) { - return await InvokePD(p_list, _service); + var invlist = _repository.Where(p => p_list.Contains(p.BillNum)).ToList(); + var states = invlist.Select(p => p.State).Distinct().ToList(); + if (states.Count > 1) + { + throw new UserFriendlyException($"发票不是同一状态", "400"); + } + var first = invlist.FirstOrDefault();//发票状态 + if (first.State == SettleBillState.客户已收票) + { + //var _taskid = await _service.ExportEnqueueAsync($"{first.BillNum}待扣减删除任务", ExportExtentsion.Excel, DateTime.Now.ToString("yyyyMM"), string.Empty, CurrentUser, typeof(PendingDeductionService), customConditionList, (rs) => + //{ + //}); + var pdList = _repository.Where(p => p_list.Contains(p.BillNum)).ToList();//扣减单内容 + var pdDetailList = _detailRepository.Where(p => p_list.Contains(p.BillNum)).ToList();//扣减单内容 + var pdinvList = _invRepository.Where(p => p_list.Contains(p.InvbillNum)).ToList(); + if (pdList.Count > 0) + { + await _repository.DbContext.BulkDeleteAsync(pdList);//删除待扣减 + await _repository.DbContext.BulkDeleteAsync(pdDetailList); + foreach (var itm in pdinvList) + { + itm.State = SettleBillState.财务已审核; + } + await _repository.DbContext.BulkUpdateAsync(pdinvList);//更新发票为关联发票 + } + return "OK"; + } + else + { + return await InvokePD(p_list, _service); + + } } - /// - /// 调用扣减 - /// - /// - /// - /// - /// - /// - [UnitOfWork(false)] + + + + + /// + /// 调用扣减 + /// + /// + /// + /// + /// + /// + [UnitOfWork(false)] protected async Task InvokePD(List p_list, TaskJobService p_service, bool isback=false) { var invlist=_repository.Where(p=>p_list.Contains(p.BillNum)).ToList(); @@ -174,6 +207,8 @@ namespace Win.Sfs.SettleAccount.Bases { throw new UserFriendlyException($"当前发票状态不是【客户已收票】或【已扣减状态】不能进行出库扣减或撤销扣减操作", "400"); } + + if (first.State == SettleBillState.客户已收票) { isback = false; 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 619f8a0f..41a811c8 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 @@ -349,6 +349,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ { return new JsonResult(new { Code = 400, Message = "请下载错误模版", fileName = result }); } + var invBilllist = new List(); var adjlist = ObjectMapper.Map, List>(p_list); if (adjlist == null && adjlist.Count == 0) @@ -364,6 +365,26 @@ 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"); + } + if (inv.InvoiceState == InvoiceBillState.报废) + { + throw new UserFriendlyException($"已经报废发票不能再次报废!", "400"); + } + if ( inv.State!= SettleBillState.已扣减 + && inv.State!=SettleBillState.已提交QAD + && inv.State!=SettleBillState.财务已审核 + && inv.State != SettleBillState.客户已收票 + ) + { + throw new UserFriendlyException($"发票只有在财务已审核、客户已收票、已扣减、已提交QAD状态下可以报废!", "400"); + } + + + + var settle = await _bbacMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); if (settle == null) @@ -503,6 +524,27 @@ 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"); + } + if (inv.InvoiceState == InvoiceBillState.报废) + { + throw new UserFriendlyException($"已经报废发票不能再次报废!", "400"); + } + if (inv.State != SettleBillState.已扣减 + && inv.State != SettleBillState.已提交QAD + && inv.State != SettleBillState.财务已审核 + && inv.State != SettleBillState.客户已收票 + ) + { + throw new UserFriendlyException($"发票只有在财务已审核、客户已收票、已扣减、已提交QAD状态下可以报废!", "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_PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_PD_SERVICE.cs index fbd7e6b8..c6b52550 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 @@ -30,8 +30,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ BBAC_PD_DETAIL, BBAC_PD_DETAIL_DTO, BBAC_PD_REQ_DTO, BBAC_PD_DETAIL_REQ_DTO, BBAC_PD_DETAIL_EXP_DTO> { - - public BBAC_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service) + public BBAC_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service, INormalEfCoreRepository invRepository) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service, invRepository) { } } 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 42191652..f5627800 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 @@ -325,6 +325,27 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var invbillnum = first.InvBillNum; var version = int.Parse(DateTime.Now.ToString("yyyymm")); var inv = await GetInvoiceGroupByInvBillNum(invbillnum).ConfigureAwait(false); + + if (inv == null) + { + throw new UserFriendlyException($"无原发票记录!", "400"); + } + if (inv.InvoiceState == InvoiceBillState.报废) + { + throw new UserFriendlyException($"已经报废发票不能再次报废!", "400"); + } + if (inv.State != SettleBillState.已扣减 + && inv.State != SettleBillState.已提交QAD + && inv.State != SettleBillState.财务已审核 + && inv.State != SettleBillState.客户已收票 + ) + { + throw new UserFriendlyException($"发票只有在财务已审核、客户已收票、已扣减、已提交QAD状态下可以报废!", "400"); + } + + + + var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); if (settle == null) { 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 44c215a4..6ee928af 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 @@ -25,7 +25,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ HBPO_PD_DETAIL, HBPO_PD_DETAIL_DTO, HBPO_PD_REQ_DTO, HBPO_PD_DETAIL_REQ_DTO, HBPO_PD_DETAIL_EXP_DTO> { - public HBPO_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service) + public HBPO_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service, INormalEfCoreRepository invRepository) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service, invRepository) { } } 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 a64ab96d..ec2e4791 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 @@ -350,6 +350,26 @@ 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"); + } + if (inv.InvoiceState == InvoiceBillState.报废) + { + throw new UserFriendlyException($"已经报废发票不能再次报废!", "400"); + } + if (inv.State != SettleBillState.已扣减 + && inv.State != SettleBillState.已提交QAD + && inv.State != SettleBillState.财务已审核 + && inv.State != SettleBillState.客户已收票 + ) + { + throw new UserFriendlyException($"发票只有在财务已审核、客户已收票、已扣减、已提交QAD状态下可以报废!", "400"); + } + + + + var settle = await _pubMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); if (settle == null) @@ -524,6 +544,26 @@ namespace Win.Sfs.SettleAccount.Entities.BQ var version = int.Parse(DateTime.Now.ToString("yyyymm")); //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 var inv = await GetInvoiceGroupByInvBillNum(invbillnum).ConfigureAwait(false); + if (inv == null) + { + throw new UserFriendlyException($"无原发票记录!", "400"); + } + if (inv.InvoiceState == InvoiceBillState.报废) + { + throw new UserFriendlyException($"已经报废发票不能再次报废!", "400"); + } + if (inv.State != SettleBillState.已扣减 + && inv.State != SettleBillState.已提交QAD + && inv.State != SettleBillState.财务已审核 + && inv.State != SettleBillState.客户已收票 + ) + { + throw new UserFriendlyException($"发票只有在财务已审核、客户已收票、已扣减、已提交QAD状态下可以报废!", "400"); + } + + + + var settle = await _pubMng.GetMainAsync(inv.InvGroupNum).ConfigureAwait(false); if (settle == null) { 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 84c0726f..abac4de1 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 @@ -94,9 +94,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ } if (await _pubMng.SetForwardState(main, SettleBillState.已开票).ConfigureAwait(false)) { - - - var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); entitys = entitys.OrderBy(p => p.IndexNum).ToList(); var dto1s = ObjectMapper.Map, List>(entitys); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_PD_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_PD_SERVICE.cs index 1244d5d0..e84151ae 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_PD_SERVICE.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_PD_SERVICE.cs @@ -26,7 +26,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ PUB_PD_DETAIL, PUB_PD_DETAIL_DTO, PUB_PD_REQ_DTO, PUB_PD_DETAIL_REQ_DTO, PUB_PD_DETAIL_EXP_DTO> { - public PUB_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service) + public PUB_PD_SERVICE(INormalEfCoreRepository bbacSecRepository, INormalEfCoreRepository hbpoSecRepository, INormalEfCoreRepository pubSecRepository, IExcelImportAppService excelImportService, ISnowflakeIdGenerator snowflakeIdGenerator, ICommonManager commonManager, INormalEfCoreRepository repository, VmiAppService vimservice, INormalEfCoreRepository detailRepository, TaskJobService service, INormalEfCoreRepository invRepository) : base(bbacSecRepository, hbpoSecRepository, pubSecRepository, excelImportService, snowflakeIdGenerator, commonManager, repository, vimservice, detailRepository, service, invRepository) { } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionDelService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionDelService.cs new file mode 100644 index 00000000..43a331fa --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionDelService.cs @@ -0,0 +1,374 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using EFCore.BulkExtensions; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +using TaskJob.EventArgs; +using TaskJob.Interfaces; +using Volo.Abp.Application.Services; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Emailing; +using Volo.Abp.Uow; +using Win.Sfs.SettleAccount.Entities.BQ.Vmi; +using Win.Sfs.SettleAccount.Entities.CodeSettings; + +namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs +{ + public class PendingDeductionDelService : ApplicationService, ITransientDependency, IExportJob + { + + protected readonly SettleAccountDbContext _dbcontext; + + private readonly IEmailSender _emailSender; + + public PendingDeductionDelService( + SettleAccountDbContext dbcontext, + IEmailSender emailSender + ) + { + _emailSender = emailSender; + _dbcontext = dbcontext; + + } + [UnitOfWork(false)] + public string ExportFile(Guid id, List exportName, List property) + { + + var billList = property.Where(p => p.Name == "BillNumList").FirstOrDefault().Value; + var type = property.Where(p => p.Name == "Type").FirstOrDefault().Value; + var isout = property.Where(p => p.Name == "IsOut").FirstOrDefault().Value; + var email = string.Empty; + // property.Where(p => p.Name == "CurrentUserEmail").FirstOrDefault().Value; + var list = billList.Split(","); + var projectList = _dbcontext.Set().Where(p => p.Project == "库位"); + if (type == "JisBBAC" || type == "ZhiGongJianBBAC" || type == "MaiDanJianBBAC" || type == "BeiJian") + { + var jisdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisBBAC);//jis + if (jisdetail != null && jisdetail.Count() > 0) + { + foreach (var itm in jisdetail) + { + if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC").Description; + } + else + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC顺义").Description; + } + } + Sync(jisdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); + } + var mdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianBBAC);//买单件 + if (mdetail != null && mdetail.Count() > 0) + { + foreach (var itm in jisdetail) + { + if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC").Description; + } + else + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "JisBBAC顺义").Description; + } + } + Sync(mdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); + } + var detailist1 = _dbcontext.Set().Where(p => list.Contains(p.BillNum)).ToList(); + + if (detailist1.Count > 0) + { + var zgbbaclist = detailist1.Where(p => p.BusinessType == EnumBusinessType.ZhiGongJianBBAC).ToList(); + foreach (var itm in zgbbaclist) + { + if (itm.Site == "1040" && string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "ZhiGongJianBBAC").Description; + } + else + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "ZhiGongJianBBAC顺义").Description; + } + } + Sync(zgbbaclist, EnumDeliverBjBmpBillType.JIT直供件, email, isout == "out" ? true : false); + var ydlist = detailist1.Where(p => p.BusinessType == EnumBusinessType.YinDuJian).ToList(); + if (ydlist.Count > 0) + { + foreach (var itm in zgbbaclist) + { + if (string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "YinDuJian").Description; + } + } + Sync(ydlist, EnumDeliverBjBmpBillType.印度件, email, isout == "out" ? true : false); + } + var bjlist = detailist1.Where(p => p.BusinessType == EnumBusinessType.BeiJian).ToList(); + if (bjlist.Count > 0) + { + foreach (var itm in bjlist) + { + if (string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = projectList.FirstOrDefault(p => p.Value == "BeiJian").Description; + } + } + Sync(bjlist, EnumDeliverBjBmpBillType.北汽4S备件, email, isout == "out" ? true : false); + } + } + } + else if (type == "JisHBPO" || type == "ZhiGongJianHBPO" || type == "MaiDanJianHBPO") + { + var detailist = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.JisHBPO).ToList(); + foreach (var itm in detailist) + { + if (string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = "CC017"; + } + } + if(detailist.Count>0) + { + Sync(detailist, EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); + } + + var mdetail = _dbcontext.Set().Where(p => list.Contains(p.BillNum) && p.BusinessType == EnumBusinessType.MaiDanJianHBPO).ToList();//买单件 + foreach (var itm in mdetail) + { + if (string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = "CC017"; + } + } + if (mdetail.Count > 0) + { + Sync(mdetail.ToList(), EnumDeliverBjBmpBillType.JIS件, email, isout == "out" ? true : false); + } + + var detailist1 = _dbcontext.Set().Where(p => list.Contains(p.BillNum)).ToList(); + var zgbbaclist = detailist1.Where(p => p.BusinessType == EnumBusinessType.ZhiGongJianHBPO).ToList(); + foreach (var itm in zgbbaclist) + { + if (string.IsNullOrEmpty(itm.Extend2)) + { + itm.Extend2 = "CC017"; + } + } + if (zgbbaclist.Count > 0) + { + + Sync(zgbbaclist, EnumDeliverBjBmpBillType.JIT直供件, email, isout == "out" ? true : false); + } + + } + return id.ToString(); + } + //public List GetPagedData(List dataList, int pageNumber, int pageSize) + //{ + // int startIndex = (pageNumber - 1) * pageSize; + + // return dataList.Skip(startIndex).Take(pageSize).ToList(); + //} + //public int CalculatePageCount(int totalCount, int pageSize) + //{ + // int pageCount = totalCount / pageSize; + // if (totalCount % pageSize != 0) + // { + // pageCount += 1; + // } + // return pageCount; + //} + [UnitOfWork(false)] + public void Sync(List p_ls, EnumDeliverBjBmpBillType bussinessType, string p_email, bool flag = true) where T : PD_BASE, new() + { + var query = from itm in p_ls + select new VmiLog() + { + + CodeType = string.Empty, + BillTime = DateTime.Now, + ChangedTime = DateTime.Now, + Qty = itm.Qty, + RealPartCode = itm.RELU,//替换件 结算数据 RealPartCode->RELU + RealCode = itm.RELU, + LogType = Entities.BQ.Vmi.VmiLogType.Type200, + ChangedQty = (flag == true) ? -itm.Qty : itm.Qty, + ChangedType = VmiType.Out, + //SubBillType = EnumDeliverSubBillType.小件BBAC, + //BillType = EnumDeliverBjBmpBillType.JIS件, + CustPartCode = itm.LU, + SettlementVinCode = itm.PN, + DeliverBillType = bussinessType, + VinCode = itm.PN, + OrderNum = itm.GroupNum, + ErpToLoc = itm.Extend2, //寄售库 + }; + var ls = query.ToList(); + foreach (var itm in ls) + { + itm.SetId(GuidGenerator.Create()); + } + var _first = p_ls.FirstOrDefault(); + bool issucess = true; + using (var transaction = _dbcontext.Database.BeginTransaction()) + { + try + { + // 执行批量数据操作 + if (ls != null && ls.Count > 0) + { + var messagelist = new List(); + foreach (var item in ls) + { + var message = new VmiMessage + { + Message = System.Text.Json.JsonSerializer.Serialize(item), + }; + messagelist.Add(message); + } + _dbcontext.BulkInsert(messagelist); + _dbcontext.BulkInsert(ls, new BulkConfig() { }); + var billList = p_ls.Select(p => p.BillNum).Distinct().ToList();//同步数据的发票号 + var pdList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList();//扣减单内容 + var pdinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList(); + if (pdList.Count > 0) + { + if (flag == true) + { + foreach (var item in pdList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in pdinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(pdList); + _dbcontext.BulkUpdate(pdinvList); + + } + else + { + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); + } + } + var bbacList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + var bbacinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList(); + if (bbacList.Count > 0) + { + if (flag == true) + { + foreach (var item in bbacList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in bbacinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(bbacList); + _dbcontext.BulkUpdate(bbacinvList); + + } + else + { + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); + } + } + var hbpoList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + var hbpoinvList = _dbcontext.Set().Where(p => billList.Contains(p.InvbillNum)).ToList();//发票 + if (hbpoList.Count > 0) + { + if (flag == true) + { + foreach (var item in hbpoList) + { + item.State = SettleBillState.已扣减; + } + foreach (var item in hbpoinvList) + { + item.State = SettleBillState.已扣减; + } + _dbcontext.BulkUpdate(hbpoList); + _dbcontext.BulkUpdate(hbpoinvList); + + } + else + { + _dbcontext.BulkDelete(pdList); + _dbcontext.BulkDelete(p_ls); + } + } + } + // _emailSender.SendAsync(e) + // 提交事务 + transaction.Commit(); + } + catch (Exception) + { + issucess = false; + // 回滚事务 + transaction.Rollback(); + } + } + if (issucess ==false) + { + var billList = p_ls.Select(p => p.BillNum).Distinct().ToList(); + var pdList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + if (pdList.Count > 0) + { + foreach (var item in pdList) + { + if (flag == true) + { + item.State = SettleBillState.客户已收票; + } + else + { + item.State = SettleBillState.已扣减; + + } + } + _dbcontext.BulkUpdate(pdList); + } + var bbacList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + if (bbacList.Count > 0) + { + foreach (var item in bbacList) + { + if (flag == true) + { + item.State = SettleBillState.客户已收票; + } + else + { + item.State = SettleBillState.已扣减; + } + } + _dbcontext.BulkUpdate(bbacList); + } + var hbpoList = _dbcontext.Set().Where(p => billList.Contains(p.BillNum)).ToList(); + if (hbpoList.Count > 0) + { + foreach (var item in hbpoList) + { + if (flag == true) + { + item.State = SettleBillState.客户已收票; + } + else + { + item.State = SettleBillState.已扣减; + } + } + _dbcontext.BulkUpdate(hbpoList); + } + } + } + + } +} diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs index 187a3e16..ba63bd67 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/PendingDeductionService.cs @@ -34,13 +34,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs [UnitOfWork(false)] public string ExportFile(Guid id, List exportName, List property) { - var billList = property.Where(p => p.Name == "BillNumList").FirstOrDefault().Value; var type = property.Where(p => p.Name == "Type").FirstOrDefault().Value; var isout = property.Where(p => p.Name == "IsOut").FirstOrDefault().Value; var email = string.Empty; // property.Where(p => p.Name == "CurrentUserEmail").FirstOrDefault().Value; var list = billList.Split(","); + var projectList = _dbcontext.Set().Where(p => p.Project == "库位"); if (type == "JisBBAC" || type == "ZhiGongJianBBAC" || type == "MaiDanJianBBAC" || type == "BeiJian") { @@ -78,6 +78,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs } var detailist1 = _dbcontext.Set().Where(p => list.Contains(p.BillNum)).ToList(); + + + if (detailist1.Count > 0) { var zgbbaclist = detailist1.Where(p => p.BusinessType == EnumBusinessType.ZhiGongJianBBAC).ToList(); diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs index 5565299c..8e46e6c6 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationModule.cs @@ -81,6 +81,12 @@ namespace Win.Sfs.SettleAccount { return implementationFactory.GetService(); } + if (key.Equals(typeof(PendingDeductionDelService).FullName)) + { + return implementationFactory.GetService(); + } + + else { throw new ArgumentException($"Not Support key:{key}");