From 42f0ea52401957e8fb65f60ac8c59e54cd46aa02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Tue, 25 Jul 2023 15:30:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs | 5 + .../Bases/BA_SERVICE.cs | 12 +- .../Bases/CAN_SA_SERVICE.cs | 230 +++++++- .../Entities/BQ/BBAC_CAN_SA_SERVICE.cs | 520 +++++++++++------- .../Entities/BQ/HBPO_CAN_SA_SERVICE.cs | 471 ++++++++++------ .../Entities/BQ/PUB_CAN_SA_SERVICE.cs | 8 +- .../SettleAccount.Domain/Bases/EntityBase.cs | 65 ++- .../Entities/BQ/BBAC_CAN_SA.cs | 11 +- .../Entities/BQ/BBAC_SA.cs | 15 +- .../Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs | 269 +++++++++ .../Entities/BQ/Managers/CAN_SA_MNG.cs | 15 +- .../Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs | 269 +++++++++ .../Entities/BQ/Managers/INV_MNG.cs | 147 +---- .../Entities/BQ/Managers/NOT_SA_MNG.cs | 10 +- .../Entities/BQ/Managers/PD_MNG.cs | 3 + .../Entities/BQ/Managers/PUB_CAN_SA_MNG.cs | 269 +++++++++ 16 files changed, 1795 insertions(+), 524 deletions(-) create mode 100644 code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs create mode 100644 code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs create mode 100644 code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs index ea0386fb..c303a71a 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_CAN_SA_DTO.cs @@ -102,6 +102,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos public string ContractDocID { set; get; } + + + + + } public class BBAC_CAN_SA_DETAIL_EXP_DTO { 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 205310aa..328c169b 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 @@ -35,9 +35,9 @@ namespace Win.Sfs.SettleAccount.Bases private readonly INormalEfCoreRepository _wRepository; private readonly INormalEfCoreRepository _sRepository; private readonly INormalEfCoreRepository _mRepository; - private readonly CAN_SA_MNG _pubMng; - private readonly CAN_SA_MNG _bbacMng; - private readonly CAN_SA_MNG _hbpoMng; + private readonly BBAC_CAN_SA_MNG _pubMng; + private readonly HBPO_CAN_SA_MNG _bbacMng; + private readonly PUB_CAN_SA_MNG _hbpoMng; private readonly INV_MNG _invMng; @@ -51,9 +51,9 @@ namespace Win.Sfs.SettleAccount.Bases INormalEfCoreRepository sRepository, INormalEfCoreRepository mRepository, IExcelImportAppService excelImportService, - CAN_SA_MNG pubMng, - CAN_SA_MNG bbacMng, - CAN_SA_MNG hbpoMng, + BBAC_CAN_SA_MNG pubMng, + HBPO_CAN_SA_MNG bbacMng, + PUB_CAN_SA_MNG hbpoMng, INV_MNG invMng //INormalEfCoreRepository detailRepository 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 153c90c7..f58852b7 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 @@ -3,7 +3,9 @@ using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Csv; using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; using SettleAccount.Bases; +using SettleAccount.Domain.BQ; using Shouldly; using System; using System.Collections.Generic; @@ -12,6 +14,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Entities; @@ -30,7 +33,7 @@ using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Bases { public abstract class CAN_SA_SERVICE : BASE_SERVICE - where TEntity : class, IEntity + where TEntity : SA_CAN_BASE_MAIN where TEntityDetail:SA_CAN_BASE where TEntityDto : class, IEntityDto, new() where TEntityDetailDto : class, IEntityDto, new() @@ -43,14 +46,23 @@ namespace Win.Sfs.SettleAccount.Bases protected readonly INormalEfCoreRepository _detailRepository; private readonly IExcelImportAppService _excelImportService; protected readonly INV_MNG _invmng; + + //private readonly CAN_SA_MNG _bbacMng; + + + protected CAN_SA_SERVICE( INormalEfCoreRepository repository, IExcelImportAppService excelImportService, INormalEfCoreRepository detailRepository, - INV_MNG invmng + //CAN_SA_MNG bbacMng, + + + INV_MNG invmng ) { + _invmng= invmng; _excelImportService = excelImportService; _repository = repository; @@ -139,7 +151,219 @@ namespace Win.Sfs.SettleAccount.Bases return new PagedResultDto(totalCount, dtos); } - + //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.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs index 8cd02a62..dcc5e538 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,8 +3,11 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using NPOI.SS.Formula.Functions; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Finance; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SettleAccount.Domain.BQ; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -18,9 +21,22 @@ using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.Shared.RepositoryBase; +using System.Text.Json; +using Newtonsoft.Json; namespace Win.Sfs.SettleAccount.Entities.BQ { + public class TMEP_INV + { + public string LU { set; get; } + public string ContractDocID { set; get; } + public decimal Amt { set; get; } + public decimal Qty { set; get; } + public decimal Price { set; get; } + } + + + /// /// BBAC-JIS可结算单 @@ -39,219 +55,351 @@ namespace Win.Sfs.SettleAccount.Entities.BQ > { private readonly INormalEfCoreRepository _notRepository; + private readonly BBAC_CAN_SA_MNG _bbacMng; + + public BBAC_CAN_SA_SERVICE( INormalEfCoreRepository repository, IExcelImportAppService excelImportService, INormalEfCoreRepository detailRepository, INormalEfCoreRepository notRepository, - INV_MNG invmng) : base(repository, excelImportService, detailRepository, invmng) + BBAC_CAN_SA_MNG bbacMng, + INV_MNG invmng) : base(repository, excelImportService, detailRepository, invmng) { _notRepository = notRepository; + _bbacMng = bbacMng; + } - - - - - - - - /// /// 生成发票 /// /// /// [HttpPost] - //[Route("generateinvoice")] + public async override Task GenerateInvoice(BBAC_CAN_SA_REQ_DTO input) { - - var main=_repository.Where(p => p.InvGroupNum == input.Filters.Where(p => p.Column == "BillNum").FirstOrDefault().Value).FirstOrDefault(); - var entitys = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);//可结算 - - var groupNumList= entitys.Select(p=>p.GroupNum).Distinct().ToList(); - - //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); - - var notList =_notRepository.Where(p => groupNumList.Contains(p.GroupNum)).ToList();//不能结算 - - var dtos = ObjectMapper.Map, List>(entitys); - - dtos.ForEach(dto => + var main =await _bbacMng.GetMainAsync(input.BillNum); + if (main != null) { - dto.Amt = Math.Round(dto.Price * dto.Qty, 2); - }); - - // dtos = dtos.OrderBy(p => p.SettleDate).ToList(); - var _query= dtos.GroupBy(p => new { p.GroupNum }).Select(p =>new {GroupNum=p.Key.GroupNum, Amt=p.Sum(itm=>itm.Amt)}); - - Dictionary dic = new Dictionary();//原本 - - Dictionary copyDic = new Dictionary();//变换数组副本 - - foreach (var itm in _query.ToList()) - { - dic.Add(itm.GroupNum, itm.Amt); - copyDic.Add(itm.GroupNum, itm.Amt); - } - Dictionary> invoiceMap=new Dictionary>(); - foreach (var itm in dic) - { - string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); - List invoiceGroupNumList = new List();//每个发票对应的结算分组号 - List List = new List(); - decimal sum = itm.Value;//初始分组合计金额 - List luList= dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU+p.ContractDocID ).Distinct().ToList(); //初始LU种类 - if (copyDic.ContainsKey(itm.Key)==true)//是否存在分组 + if (await _bbacMng.SetForwardState(main,SettleBillState.已开票)) { - foreach (var _itm1 in copyDic) + var entitys = await _bbacMng.GetDetalListAsync(input.BillNum);//可结算 + var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); + //var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList(); + var notList = _notRepository.Where(p => groupNumList.Contains(p.GroupNum)).ToList();//不能结算 + var dtos = ObjectMapper.Map, List>(entitys); + dtos.ForEach(dto => { - if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化 - { - invoiceGroupNumList.Add(itm.Key); - continue; - } - var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU + p.ContractDocID).Distinct().ToList();//每项LU种类 - luList.AddRange(grouplist); - luList = luList.Distinct().ToList(); - if (luList.Count > 20)//累加零件不超过20种 + dto.Amt = Math.Round(dto.Price * dto.Qty, 2); + }); + if (dtos != null && dtos.Count > 0) + { + if (input.BillNum.Substring(0, 1) != "C")//一次开票 { - continue; + // dtos = dtos.OrderBy(p => p.SettleDate).ToList(); + var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).OrderBy(p=>p.Amt); + Dictionary dic = new Dictionary();//原本 + Dictionary copyDic = new Dictionary();//变换数组副本 + foreach (var itm in _query.ToList()) + { + dic.Add(itm.GroupNum, itm.Amt); + copyDic.Add(itm.GroupNum, itm.Amt); + } + Dictionary> invoiceMap = new Dictionary>(); + foreach (var itm in dic) + { + if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组 + { + string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + List invoiceGroupNumList = new List();//每个发票对应的结算分组号 + List List = new List(); + decimal sum = itm.Value;//初始分组合计金额 + //List luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU + p.ContractDocID).Distinct().ToList(); //初始LU种类 + + foreach (var _itm1 in copyDic) + { + if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化 + { + invoiceGroupNumList.Add(itm.Key); + continue; + } + //var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU + p.ContractDocID).Distinct().ToList();//每项LU种类 + //luList.AddRange(grouplist); + //luList = luList.Distinct().ToList(); + //if (luList.Count > 20)//累加零件不超过20种 + //{ + // continue; + //} + sum += _itm1.Value; + if (sum > 10000000) + { + break; + } + + invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系 + } + invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系 + foreach (var rem in invoiceGroupNumList)//移除已经开票分组 + { + copyDic.Remove(rem); + } + } + } + if (invoiceMap.Keys.Count > 0) + { + var groupList = new List(); + var notDetialList = new List(); + var detailList = new List(); + var invlist = new List(); + + // string str = JsonConvert.SerializeObject(invoiceMap); + + foreach (var itm in invoiceMap)//分组影响和 + { + var key = itm.Key;//发票票号 + var ls = itm.Value;//结算分组号列表 + var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.LU, p.Price, p.ContractDocID }) + .Select(itm => new + { + InvGroupNum = itm.Key.InvGroupNum, + LU = itm.Key.LU, + ContactDocID = itm.Key.ContractDocID, + Price = itm.Key.Price, + Amt =itm.Sum(p=>p.Amt), + Qty = itm.Sum(k => k.Qty) + }) + .ToList(); + decimal amt = detailDtos.Sum(k => k.Amt); + decimal txtAmt = Math.Round(detailDtos.Sum(k => k.Amt) * 0.13m, 2); + var mapList = new List(); + foreach (var groupnum in ls) + { + //amt = dtos.Where(p => p.GroupNum == groupnum).Sum(p => p.Amt); + mapList.Add(new INVOICE_MAP_GROUP( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + settleGroupNum: groupnum, + amt: 0, + extend1: string.Empty, + extend2: string.Empty + ) + ); + } + if (mapList.Count > 0) + { + groupList.AddRange(mapList); + } + List _entityDetailList = new List(); + foreach (var detail in detailDtos) + { + _entityDetailList.Add( + new INVOICE_WAIT_DETAIL( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + lU: detail.LU, + qty: detail.Qty, + bussiessType: EnumBusinessType.BBAC, + amt: detail.Amt, + pRICE: detail.Price, + extend1: detail.ContactDocID, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + )); + } + if (_entityDetailList.Count > 0) + { + detailList.AddRange(_entityDetailList); + } + var notls = 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) }); + var innotls = new List(); + foreach (var nitm in notls) + { + innotls.Add(new INVOICE_NOT_SETTLE( + guid: GuidGenerator.Create(), + version: main.Version, + invGroupNum: main.InvGroupNum, + settleGroupNum: nitm.GroupNum, + lU: string.Empty, + lU1: nitm.LU, + extend1: string.Empty, + extend2: string.Empty, + qty: nitm.Qty + )); + } + if (innotls.Count > 0) + { + notDetialList.AddRange(innotls); + } + var invbill = new INVOICE_GRP + (guid: GuidGenerator.Create(), + realnvBillNum: string.Empty, + invbillNum: key, + amt: amt, + taxAmt: txtAmt, + fileName: string.Empty, + businessType: EnumBusinessType.BBAC, + invGroupNum: main.InvGroupNum, + state: SettleBillState.已开票, + invoiceBillState: InvoiceBillState.正常 + ); + invlist.Add(invbill); + } + await _repository.DbContext.BulkInsertAsync(invlist); + await _repository.DbContext.BulkInsertAsync(groupList); + await _repository.DbContext.BulkInsertAsync(detailList); + await _repository.DbContext.BulkInsertAsync(notDetialList); + } } - if (sum > 10000000) + else//二次开票 { - break; - } - sum += _itm1.Value; - invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系 - } - invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系 - foreach (var rem in invoiceGroupNumList)//移除已经开票分组 - { - copyDic.Remove(rem); - } - } - } - if(invoiceMap.Keys.Count>0) { - - var groupList = new List(); - var notDetialList = new List(); - var detailList = new List(); - var invlist = new List(); - foreach (var itm in invoiceMap)//分组影响和 - { - var key = itm.Key;//发票票号 - var ls = itm.Value;//结算分组号列表 - var detailDtos= dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p=>new {p.InvGroupNum, p.LU,p.Price,p.ContractDocID }) - .Select(itm=>new { - InvGroupNum=itm.Key.InvGroupNum, - LU=itm.Key.LU, - ContactDocID=itm.Key.ContractDocID, - Price=itm.Key.Price, - Amt=Math.Round(itm.Sum(k=>k.Qty)*itm.Key.Price,2) , - Qty= itm.Sum(k => k.Qty) - }) - .ToList(); - decimal amt=detailDtos.Sum(k=>k.Amt); - decimal txtAmt=Math.Round(detailDtos.Sum(k => k.Amt),2); - var mapList= new List(); - foreach (var groupnum in ls) - { - amt=dtos.Where(p => p.GroupNum == groupnum).Sum(p => p.Amt); - mapList.Add(new INVOICE_MAP_GROUP( - guid: GuidGenerator.Create(), - version: main.Version, - invbillNum: key, - invGroupNum: main.InvGroupNum, - settleGroupNum:groupnum, - amt:amt, - extend1:string.Empty, - extend2:string.Empty - ) - ); - } - if(mapList.Count > 0) - { - groupList.AddRange(mapList); + var groups1 = dtos.GroupBy(p => new { p.LU, p.ContractDocID, p.Price }).Select(p => new TMEP_INV + { + LU = p.Key.LU, + ContractDocID = p.Key.ContractDocID, + Amt = p.Sum(itm => itm.Amt), + Qty = p.Sum(itm => itm.Qty), + Price = p.Key.Price + }).ToList();//汇总记录不出现重复值 + var groups = dtos.GroupBy(p => new { p.LU, p.ContractDocID, p.Price }).Select(p => new TMEP_INV + { + LU = p.Key.LU, + ContractDocID = p.Key.ContractDocID, + Amt = p.Sum(itm => itm.Amt), + Qty = p.Sum(itm => itm.Qty), + Price = p.Key.Price + }).ToList();//汇总记录不出现重复值 + Dictionary> invoiceMap = new Dictionary>();//发票和发票明细关系 + foreach (var group in groups) + { + int i = groups1.Count(p => p.LU == group.LU && p.ContractDocID == group.ContractDocID); + if (i > 0) + { + string 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 && group1.ContractDocID == group.ContractDocID) + { + tempList.Add(group1); + partCount++;//符合条件加入到零件中 + continue; + } + partCount++; + if (partCount > 30) + { + continue; + } + sum += group1.Amt; + if (sum > 10000000) + { + break; + } + tempList.Add(group1); + } + invoiceMap.Add(invoiceBillNum, tempList); + var query = from itm in groups1 + join itm1 in tempList + on new { itm.LU, itm.ContractDocID } equals new { itm1.LU, itm1.ContractDocID } into temp + from tm in temp + select new TMEP_INV { LU = itm.LU, ContractDocID = itm.ContractDocID, Amt = itm.Amt, Qty = itm.Qty }; + 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: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + lU: detail.LU, + qty: detail.Qty, + bussiessType: EnumBusinessType.BBAC, + amt: detail.Amt, + pRICE: detail.Price, + extend1: detail.ContractDocID, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + )); + } + 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(); + List group1 = new List(); + + foreach (var en in _groupList) + { + group1.Add( + new INVOICE_MAP_GROUP( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.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: EnumBusinessType.BBAC, + invGroupNum: main.InvGroupNum, + state: SettleBillState.已开票, + invoiceBillState: InvoiceBillState.正常 + ); + invlist.Add(invbill); + } + await _repository.DbContext.BulkInsertAsync(invlist); + await _repository.DbContext.BulkInsertAsync(groupList); + await _repository.DbContext.BulkInsertAsync(detailList); + //await _repository.DbContext.BulkInsertAsync(notDetialList); + + } + } } - List _entityDetailList = new List(); - foreach (var detail in detailDtos) - { - _entityDetailList.Add( - new INVOICE_WAIT_DETAIL( - guid: GuidGenerator.Create(), - version:main.Version, - invbillNum: key, - invGroupNum: main.InvGroupNum, - lU: detail.LU, - qty: detail.Qty, - bussiessType: EnumBusinessType.BBAC, - amt: detail.Amt, - pRICE:detail.Price, - extend1: detail.ContactDocID, - extend2: string.Empty, - extend3: string.Empty, - extend4: string.Empty - )); - } - if (_entityDetailList.Count > 0) - { - detailList.AddRange(_entityDetailList); - } - - var notls= 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) }); - - var innotls= new List(); - foreach (var nitm in notls) - { - innotls.Add(new INVOICE_NOT_SETTLE( - guid: GuidGenerator.Create(), - version: main.Version, - invGroupNum: main.InvGroupNum, - settleGroupNum: nitm.GroupNum, - lU: string.Empty, - lU1: nitm.LU, - extend1: string.Empty, - extend2: string.Empty, - qty: nitm.Qty - )); - } - if (innotls.Count > 0) - { - notDetialList.AddRange(innotls); - } - var invbill = new INVOICE_GRP - (guid: GuidGenerator.Create(), - realnvBillNum: string.Empty, - invbillNum: key, - amt:amt, - taxAmt:txtAmt, - fileName: string.Empty, - businessType: EnumBusinessType.BBAC, - invGroupNum: main.InvGroupNum, - state: SettleBillState.已开票, - invoiceBillState: InvoiceBillState.正常 - - ); - invlist.Add( invbill ); - } - await _repository.DbContext.BulkInsertAsync(invlist); - await _repository.DbContext.BulkInsertAsync(groupList); - await _repository.DbContext.BulkInsertAsync(detailList); - await _repository.DbContext.BulkInsertAsync(notDetialList); } - - - - - - return ApplicationConsts.SuccessStr; + return ApplicationConsts.SuccessStr; } - - - } } 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 f2bb5a20..af008c70 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 @@ -38,16 +38,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ > { private INormalEfCoreRepository _notRepository; + private readonly HBPO_CAN_SA_MNG _hbpoMng; public HBPO_CAN_SA_SERVICE(INormalEfCoreRepository repository, IExcelImportAppService excelImportService, INormalEfCoreRepository detailRepository, INV_MNG invmng, - INormalEfCoreRepository notRepository + INormalEfCoreRepository notRepository, + HBPO_CAN_SA_MNG hbpoMng ) : base(repository, excelImportService, detailRepository, invmng) { _notRepository = notRepository; + _hbpoMng = hbpoMng; } /// /// 生成发票 @@ -59,187 +62,329 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public async override Task GenerateInvoice(HBPO_CAN_SA_REQ_DTO input) { - var main = _repository.Where(p => p.InvGroupNum == input.Filters.Where(p => p.Column == "BillNum").FirstOrDefault().Value).FirstOrDefault(); - var entitys = await _detailRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);//可结算 + var main =await _hbpoMng.GetMainAsync(input.BillNum); - var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - - var notList = _notRepository.Where(p => groupNumList.Contains(p.InvGroupNum)).ToList();//不能结算 - - var dtos = ObjectMapper.Map, List>(entitys); - - dtos.ForEach(dto => + if (main != null) { - dto.Amt = Math.Round(dto.Price * dto.Qty, 2); - }); + if (await _hbpoMng.SetForwardState(main, SettleBillState.已开票)) + { + var entitys = await _hbpoMng.GetDetalListAsync(input.BillNum); - var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); + if (await _hbpoMng.SetForwardState(main, SettleBillState.已开票)) + { + var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList(); - Dictionary dic = new Dictionary();//原本 + var notList = _notRepository.Where(p => groupNumList.Contains(p.InvGroupNum)).ToList();//不能结算 - Dictionary copyDic = new Dictionary();//变换数组副本 + var dtos = ObjectMapper.Map, List>(entitys); - foreach (var itm in _query.ToList()) - { - dic.Add(itm.GroupNum, itm.Amt); - copyDic.Add(itm.GroupNum, itm.Amt); - } - Dictionary> invoiceMap = new Dictionary>(); - foreach (var itm in dic) - { - string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); - List invoiceGroupNumList = new List();//每个发票对应的结算分组号 - List List = new List(); - decimal sum = itm.Value;//初始分组合计金额 - List luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类 - - if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组 - { - foreach (var _itm1 in copyDic) - { - if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化 + dtos.ForEach(dto => { - invoiceGroupNumList.Add(itm.Key); - continue; - } - var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类 - luList.AddRange(grouplist); - luList = luList.Distinct().ToList(); - if (luList.Count > 20)//累加零件不超过20种 - { - continue; - } - if (sum > 10000000) + dto.Amt = Math.Round(dto.Price * dto.Qty, 2); + }); + + if (dtos != null && dtos.Count > 0) { - break; - } - sum += _itm1.Value; - invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系 - } + if (input.BillNum.Substring(0, 1) != "C")//一次开票 + { + var _query = dtos.GroupBy(p => new { p.GroupNum }).Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }); + Dictionary dic = new Dictionary();//原本 + Dictionary copyDic = new Dictionary();//变换数组副本 + foreach (var itm in _query.ToList()) + { + dic.Add(itm.GroupNum, itm.Amt); + copyDic.Add(itm.GroupNum, itm.Amt); + } + Dictionary> invoiceMap = new Dictionary>(); + foreach (var itm in dic) + { + string invoiceBillNum = OrderNumberGenerator.GenerateOrderNumber("INV"); + List invoiceGroupNumList = new List();//每个发票对应的结算分组号 + List List = new List(); + decimal sum = itm.Value;//初始分组合计金额 + List luList = dtos.Where(p => p.GroupNum == itm.Key).Select(p => p.LU).Distinct().ToList(); //初始LU种类 - invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系 - foreach (var rem in invoiceGroupNumList)//移除 - { - copyDic.Remove(rem); - } - } - } - if (invoiceMap.Keys.Count > 0) - { + if (copyDic.ContainsKey(itm.Key) == true)//是否存在分组 + { + foreach (var _itm1 in copyDic) + { + if (itm.Key == _itm1.Key)//相同结算分组项不计算,已初始化 + { + invoiceGroupNumList.Add(itm.Key); + continue; + } + var grouplist = dtos.Where(p => p.GroupNum == _itm1.Key).Select(p => p.LU).Distinct().ToList();//每项LU种类 + luList.AddRange(grouplist); + luList = luList.Distinct().ToList(); + if (luList.Count > 20)//累加零件不超过20种 + { + continue; + } + sum += _itm1.Value; + if (sum > 10000000) + { + break; + } + invoiceGroupNumList.Add(_itm1.Key);//所有条件都满足添加发票和结算分组对应关系 + } + invoiceMap.Add(invoiceBillNum, invoiceGroupNumList);//记录发票对应关系 + foreach (var rem in invoiceGroupNumList)//移除 + { + copyDic.Remove(rem); + } + } + } + if (invoiceMap.Keys.Count > 0) + { - var groupList = new List(); - var notDetialList = new List(); - var detailList = new List(); - var invlist = new List(); - foreach (var itm in invoiceMap)//分组影响和 - { - var key = itm.Key;//发票票号 - var ls = itm.Value;//结算分组号列表 - var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.LU, p.Price }) - .Select(itm => new { - InvGroupNum = itm.Key.InvGroupNum, - LU = itm.Key.LU, - - Price = itm.Key.Price, - Amt = Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2), - Qty = itm.Sum(k => k.Qty) - }) - .ToList(); - decimal amt = detailDtos.Sum(k => k.Amt); - decimal txtAmt = Math.Round(detailDtos.Sum(k => k.Amt), 2); - var mapList = new List(); - foreach (var groupnum in ls) - { - amt = dtos.Where(p => p.GroupNum == groupnum).Sum(p => p.Amt); - mapList.Add(new INVOICE_MAP_GROUP( - guid: GuidGenerator.Create(), - version: main.Version, - invbillNum: key, - invGroupNum: main.InvGroupNum, - settleGroupNum: groupnum, - amt: amt, - extend1: string.Empty, - extend2: string.Empty - ) - ); - } - if (mapList.Count > 0) - { - groupList.AddRange(mapList); + var groupList = new List(); + var notDetialList = new List(); + var detailList = new List(); + var invlist = new List(); + foreach (var itm in invoiceMap)//分组影响和 + { + var key = itm.Key;//发票票号 + var ls = itm.Value;//结算分组号列表 + var detailDtos = dtos.Where(p => ls.Contains(p.GroupNum)).GroupBy(p => new { p.InvGroupNum, p.LU, p.Price }) + .Select(itm => new + { + InvGroupNum = itm.Key.InvGroupNum, + LU = itm.Key.LU, + Price = itm.Key.Price, + Amt = Math.Round(itm.Sum(k => k.Qty) * itm.Key.Price, 2), + Qty = itm.Sum(k => k.Qty) + }) + .ToList(); + decimal amt = detailDtos.Sum(k => k.Amt); + decimal txtAmt = Math.Round(detailDtos.Sum(k => k.Amt), 2); + var mapList = new List(); + foreach (var groupnum in ls) + { - } - List _entityDetailList = new List(); - foreach (var detail in detailDtos) - { - _entityDetailList.Add( - new INVOICE_WAIT_DETAIL( - guid: GuidGenerator.Create(), - version: main.Version, - invbillNum: key, - invGroupNum: main.InvGroupNum, - lU: detail.LU, - qty: detail.Qty, - bussiessType: EnumBusinessType.HBPO, - amt: detail.Amt, - pRICE: detail.Price, - extend1: string.Empty, - extend2: string.Empty, - extend3: string.Empty, - extend4: string.Empty - )); - } - if (_entityDetailList.Count > 0) - { - detailList.AddRange(_entityDetailList); - } + mapList.Add(new INVOICE_MAP_GROUP( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + settleGroupNum: groupnum, + amt: 0, + extend1: string.Empty, + extend2: string.Empty + ) + ); + } + if (mapList.Count > 0) + { + groupList.AddRange(mapList); - var notls = 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) }); + } + List _entityDetailList = new List(); + foreach (var detail in detailDtos) + { + _entityDetailList.Add( + new INVOICE_WAIT_DETAIL( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + lU: detail.LU, + qty: detail.Qty, + bussiessType: EnumBusinessType.HBPO, + amt: detail.Amt, + pRICE: detail.Price, + extend1: string.Empty, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + )); + } + if (_entityDetailList.Count > 0) + { + detailList.AddRange(_entityDetailList); + } - var innotls = new List(); - foreach (var nitm in notls) - { - innotls.Add(new INVOICE_NOT_SETTLE( - guid: GuidGenerator.Create(), - version: main.Version, - invGroupNum: main.InvGroupNum, - settleGroupNum: nitm.GroupNum, - lU: string.Empty, - lU1: nitm.LU, - extend1: string.Empty, - extend2: string.Empty, - qty: nitm.Qty - )); - } - if (innotls.Count > 0) - { - notDetialList.AddRange(innotls); - } - var invbill = new INVOICE_GRP - (guid: GuidGenerator.Create(), - realnvBillNum: string.Empty, - invbillNum: key, - amt: amt, - taxAmt: txtAmt, - fileName: string.Empty, - businessType: EnumBusinessType.HBPO, - invGroupNum: main.InvGroupNum, - state: SettleBillState.已开票, - invoiceBillState: InvoiceBillState.正常 - - ); - invlist.Add(invbill); + var notls = 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) }); + var innotls = new List(); + foreach (var nitm in notls) + { + innotls.Add(new INVOICE_NOT_SETTLE( + guid: GuidGenerator.Create(), + version: main.Version, + invGroupNum: main.InvGroupNum, + settleGroupNum: nitm.GroupNum, + lU: string.Empty, + lU1: nitm.LU, + extend1: string.Empty, + extend2: string.Empty, + qty: nitm.Qty + )); + } + if (innotls.Count > 0) + { + notDetialList.AddRange(innotls); + } + var invbill = new INVOICE_GRP + (guid: GuidGenerator.Create(), + realnvBillNum: string.Empty, + invbillNum: key, + amt: amt, + taxAmt: txtAmt, + fileName: string.Empty, + businessType: EnumBusinessType.HBPO, + invGroupNum: main.InvGroupNum, + state: SettleBillState.已开票, + invoiceBillState: InvoiceBillState.正常 - } + ); + invlist.Add(invbill); + } + await _repository.DbContext.BulkInsertAsync(invlist); + await _repository.DbContext.BulkInsertAsync(groupList); + await _repository.DbContext.BulkInsertAsync(detailList); + await _repository.DbContext.BulkInsertAsync(notDetialList); + } + } + else//二次开票 + { + var groups1 = dtos.GroupBy(p => new { p.LU, p.Price }).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 + }).ToList();//汇总记录不出现重复值 + var groups = dtos.GroupBy(p => new { p.LU, p.Price }).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 + }).ToList();//汇总记录不出现重复值 + Dictionary> invoiceMap = new Dictionary>();//发票和发票明细关系 + foreach (var group in groups) + { + int i = groups1.Count(p => p.LU == group.LU && p.ContractDocID == group.ContractDocID); + if (i > 0) + { + string 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 && 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.ContractDocID } equals new { itm1.LU, itm1.ContractDocID } into temp + from tm in temp + select new TMEP_INV { LU = itm.LU, ContractDocID = itm.ContractDocID, Amt = itm.Amt, Qty = itm.Qty }; + 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: main.Version, + invbillNum: key, + invGroupNum: main.InvGroupNum, + lU: detail.LU, + qty: detail.Qty, + bussiessType: EnumBusinessType.BBAC, + amt: detail.Amt, + pRICE: detail.Price, + extend1: detail.ContractDocID, + extend2: string.Empty, + extend3: string.Empty, + extend4: string.Empty + )); + } + 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.GroupBy(p => new { p.GroupNum }) + .Select(p => new { GroupNum = p.Key.GroupNum, Amt = p.Sum(itm => itm.Amt) }).Distinct(); + List group1 = new List(); - await _repository.DbContext.BulkInsertAsync(invlist); - await _repository.DbContext.BulkInsertAsync(groupList); - await _repository.DbContext.BulkInsertAsync(detailList); - await _repository.DbContext.BulkInsertAsync(notDetialList); - } + foreach (var en in _groupList) + { + group1.Add( + new INVOICE_MAP_GROUP( + guid: GuidGenerator.Create(), + version: main.Version, + invbillNum: key, + invGroupNum: main.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: EnumBusinessType.BBAC, + invGroupNum: main.InvGroupNum, + state: SettleBillState.已开票, + invoiceBillState: InvoiceBillState.正常 + ); + invlist.Add(invbill); + } + await _repository.DbContext.BulkInsertAsync(invlist); + await _repository.DbContext.BulkInsertAsync(groupList); + await _repository.DbContext.BulkInsertAsync(detailList); + //await _repository.DbContext.BulkInsertAsync(notDetialList); + } + } + } + } + } + } return ApplicationConsts.SuccessStr; } 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 95560c1d..6810c6db 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 @@ -11,6 +11,7 @@ using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.Bases; +using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.Shared.RepositoryBase; @@ -37,5 +38,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ public PUB_CAN_SA_SERVICE(INormalEfCoreRepository repository, IExcelImportAppService excelImportService, INormalEfCoreRepository detailRepository, INV_MNG invmng) : base(repository, excelImportService, detailRepository, invmng) { } - } + [HttpPost] + public async override Task GenerateInvoice(BBAC_CAN_SA_REQ_DTO input) + { + + return ApplicationConsts.SuccessStr; + } } diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs index c07ed12b..f2fc6551 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Bases/EntityBase.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Domain.Entities.Auditing; +using Volo.Abp.Validation; using Win.Sfs.SettleAccount; using Win.Sfs.SettleAccount.Entities.SettleAccountDomain; using static System.Runtime.CompilerServices.RuntimeHelpers; @@ -41,6 +42,10 @@ namespace SettleAccount.Bases public class SA_CAN_BASE_MAIN : FullAuditedAggregateRoot { + public SA_CAN_BASE_MAIN() { } + public SA_CAN_BASE_MAIN(Guid id) : base(id) { } + + [Display(Name = "期间")] public virtual int Version { get; set; } @@ -64,11 +69,15 @@ namespace SettleAccount.Bases public virtual string Site { get; set; } + } public class PD_BASE_MAIN : FullAuditedAggregateRoot { + public PD_BASE_MAIN() + { + } [Display(Name = "期间")] public virtual int Version { get; set; } @@ -206,6 +215,10 @@ namespace SettleAccount.Bases public class RE_BASE :FullAuditedAggregateRoot, IRE_BASE { + public RE_BASE() + { + } + /// 发货时间 /// public DateTime ShippingDate { set; get; } @@ -316,59 +329,61 @@ namespace SettleAccount.Bases public class SA_BASE : FullAuditedAggregateRoot, ISA_BASE { + + + public SA_BASE() { } + public SA_BASE(Guid id) : base(id) { } + /// /// 期间 /// - public int Version { set; get; } + public virtual int Version { set; get; } /// /// 单价 /// - public decimal Price { set; get; } + public virtual decimal Price { set; get; } /// /// 结算单 /// - public string BillNum { set; get; } + public virtual string BillNum { set; get; } /// /// 结算日期 /// - public DateTime SettleDate { set; get; } + public virtual DateTime SettleDate { set; get; } /// /// 零件號 /// - public string LU { get ; set ; } + public virtual string LU { get ; set ; } /// /// 生產號 /// - public string PN { get; set ; } + public virtual string PN { get; set ; } /// /// 組合鍵值(LU+PN) /// - public string KeyCode { get ; set ; } + public virtual string KeyCode { get ; set ; } /// /// 數量 /// - public decimal Qty { get ; set ; } + public virtual decimal Qty { get ; set ; } /// /// 結算分組號 /// - public string GroupNum { get ; set ; } + public virtual string GroupNum { get ; set ; } + + + + + + - //public SA_BASE(int version, decimal price, string billNum, DateTime settleDate, string lU, string pN, string keyCode, decimal qty, string groupNum) - //{ - // Version = version; - // Price = price; - // BillNum = billNum; - // SettleDate = settleDate; - // LU = lU; - // PN = pN; - // KeyCode = keyCode; - // Qty = qty; - // GroupNum = groupNum; - //} } public class SA_CAN_BASE : FullAuditedAggregateRoot, ISA_CAN_BASE { + protected SA_CAN_BASE() { } + public SA_CAN_BASE(Guid id) : base(id) { } + /// /// 期间 /// @@ -430,6 +445,10 @@ namespace SettleAccount.Bases } public class SA_NOT_BASE : FullAuditedAggregateRoot, ISA_NOT_BASE { + public SA_NOT_BASE() + { + } + /// /// 单价 /// @@ -521,6 +540,10 @@ namespace SettleAccount.Bases } public class PD_BASE : FullAuditedAggregateRoot, ISBASE { + public PD_BASE() + { + } + /// /// 期间 /// 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 db7d3ffa..f026484b 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 @@ -35,9 +35,9 @@ public class BBAC_CAN_SA : SA_CAN_BASE_MAIN - public BBAC_CAN_SA(Guid guid, int version, string billNum, string settleBillNum, SettleBillState state, string invGroupNum,string site) + public BBAC_CAN_SA(Guid guid, int version, string billNum, string settleBillNum, SettleBillState state, string invGroupNum,string site):base(guid) { - Id = guid; + Version = version; BillNum = billNum; SettleBillNum = settleBillNum; @@ -136,15 +136,12 @@ public class BBAC_CAN_SA_DETAIL: SA_CAN_BASE } - - - public BBAC_CAN_SA_DETAIL(Guid guid,string keyCode, int version, string billNum, string settleBillNum, string lU, string pN, string site, decimal qty, decimal price, EnumBusinessType category, string isReturn, DateTime settleDate, string groupNum, string invGroupNum ,string contactid - ) + ):base(guid) { - Id = guid; + KeyCode = keyCode; Version = version; BillNum = billNum; diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs index bbc31cf2..6755f078 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs @@ -1,4 +1,4 @@ -using SettleAccount.Bases; +using SettleAccount.Bases; using System; using System.ComponentModel.DataAnnotations; using Volo.Abp.Domain.Entities.Auditing; @@ -31,16 +31,17 @@ public class BBAC_SA:FullAuditedAggregateRoot [Display(Name = "工厂地点")] public string Site { get; set; } = null!; - public BBAC_SA(Guid guid, int version, string billNum, string dNBillNum, string state) + public BBAC_SA(Guid guid, int version, string billNum, string dNBillNum, string state):base(guid) { - Id = guid; + Version = version; BillNum = billNum; DNBillNum = dNBillNum; State = state; } - public BBAC_SA() + public BBAC_SA() : base() { + } @@ -125,9 +126,9 @@ public class BBAC_SA_DETAIL:SA_BASE //[Display(Name = "发票分组号")] //public string InvGroupNum { get; set; } = null!; - public BBAC_SA_DETAIL(Guid p_guid, string keyCode, int version, string billNum, string lU, string pN, string site, decimal qty, decimal price, string category, string isReturn, DateTime settleDate, string groupNum, string invGroupNum) + public BBAC_SA_DETAIL(Guid p_guid, string keyCode, int version, string billNum, string lU, string pN, string site, decimal qty, decimal price, string category, string isReturn, DateTime settleDate, string groupNum, string invGroupNum):base(p_guid) { - Id = p_guid; + KeyCode = keyCode; Version = version; BillNum = billNum; @@ -143,7 +144,7 @@ public class BBAC_SA_DETAIL:SA_BASE //InvGroupNum = invGroupNum; } - public BBAC_SA_DETAIL() + public BBAC_SA_DETAIL():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 new file mode 100644 index 00000000..4a3bf854 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs @@ -0,0 +1,269 @@ +using EFCore.BulkExtensions; +using Hangfire.Annotations; +using Microsoft.EntityFrameworkCore; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +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 BBAC_CAN_SA_MNG: DomainService + + { + private readonly INormalEfCoreRepository _repository; + private readonly INormalEfCoreRepository _detailRepository; + public BBAC_CAN_SA_MNG + ( + INormalEfCoreRepository repository, + INormalEfCoreRepository detailRepository + ) + { + _repository = repository; + _detailRepository = detailRepository; + } + + public BBAC_CAN_SA_MNG() + { + } + + public virtual async Task SetForwardState(BBAC_CAN_SA 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 (BBAC_CAN_SA p_entiy in ls) + { + switch (state) + { + case SettleBillState.财务已审核: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】,无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【商务已审核】"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.未结状态) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【未结状态】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.已扣减: + if (p_entiy.State == SettleBillState.客户已收票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[客户收票],无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.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 (BBAC_CAN_SA p_entiy in ls) + { + + switch (state) + { + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.财务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【财务已审核】,无法设置成【商务已审核】状态"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.未结状态: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【未结状态】"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.State == SettleBillState.已扣减) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[财务已审核],无法设置成【财务已审核客户收票】状态"); + } + break; + case SettleBillState.财务已审核: + if (p_entiy.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(BBAC_CAN_SA 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/CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/CAN_SA_MNG.cs index e3269444..4ca2c9cf 100644 --- 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 @@ -8,6 +8,7 @@ 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; @@ -20,9 +21,9 @@ using Win.Sfs.Shared.RepositoryBase; namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { - public class CAN_SA_MNG : DomainService - where TEntity : SA_CAN_BASE_MAIN - where TEntityDetail : SA_CAN_BASE + 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; @@ -35,6 +36,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers _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) @@ -45,6 +51,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } + + + /// /// 向前流程 /// diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs new file mode 100644 index 00000000..c446f60d --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs @@ -0,0 +1,269 @@ +using EFCore.BulkExtensions; +using Hangfire.Annotations; +using Microsoft.EntityFrameworkCore; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +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 HBPO_CAN_SA_MNG: DomainService + + { + private readonly INormalEfCoreRepository _repository; + private readonly INormalEfCoreRepository _detailRepository; + public HBPO_CAN_SA_MNG + ( + INormalEfCoreRepository repository, + INormalEfCoreRepository detailRepository + ) + { + _repository = repository; + _detailRepository = detailRepository; + } + + public HBPO_CAN_SA_MNG() + { + } + + public virtual async Task SetForwardState(HBPO_CAN_SA 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 (HBPO_CAN_SA p_entiy in ls) + { + switch (state) + { + case SettleBillState.财务已审核: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】,无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【商务已审核】"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.未结状态) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【未结状态】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.已扣减: + if (p_entiy.State == SettleBillState.客户已收票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[客户收票],无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.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 (HBPO_CAN_SA p_entiy in ls) + { + + switch (state) + { + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.财务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【财务已审核】,无法设置成【商务已审核】状态"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.未结状态: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【未结状态】"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.State == SettleBillState.已扣减) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[财务已审核],无法设置成【财务已审核客户收票】状态"); + } + break; + case SettleBillState.财务已审核: + if (p_entiy.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(HBPO_CAN_SA 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 a928473c..5a96557a 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 @@ -22,10 +22,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { //private readonly INormalEfCoreRepository _canRepository; private readonly INormalEfCoreRepository _repository; - - - - private readonly INormalEfCoreRepository _groupRepository; private readonly INormalEfCoreRepository _detailRepository; private readonly INormalEfCoreRepository _notRepository; @@ -56,6 +52,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers _hbpoMng = hbpoMng; } + + public INV_MNG() + { + } + public virtual async Task SetForwardState(string p_groupBillnum , SettleBillState p_State) { var _first=_repository.Where(p => p.InvbillNum == p_groupBillnum).FirstOrDefault(); @@ -97,60 +98,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { isSucc = await _bbacMng.SetBackwardState(p_entiy.InvGroupNum, p_State); } - //switch ((int)p_State) - //{ - // case (int)SettleBillState.财务已审核: - // if (IsForward == true) - // { - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.财务已审核); - // } - // else - // { - // isSucc = await _bbacMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.财务已审核); - // } - // break; - // case (int)SettleBillState.商务已审核: - // if (IsForward == true) - // { - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.商务已审核); - // } - // else - // { - // isSucc = await _bbacMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.商务已审核); - // } - // break; - // case (int)SettleBillState.已开票: - // if (IsForward == true) - // { - - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已开票); - // } - // else - // { - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已开票); - // } - // break; - // case (int)SettleBillState.客户已收票: - // if (IsForward == true) - // { - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.客户已收票); - // } - // else - // { - // isSucc = await _bbacMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.客户已收票); - // } - // break; - // case (int)SettleBillState.已扣减: - // if (IsForward == true) - // { - // isSucc = await _bbacMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已扣减); - // } - // else - // { - // isSucc = await _bbacMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.已扣减); - // } - // break; - //} return isSucc; } @@ -166,60 +113,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers { isSucc = await _hbpoMng.SetBackwardState(p_entiy.InvGroupNum, p_State); } - //switch ((int)p_State) - //{ - // case (int)SettleBillState.财务已审核: - // if (IsForward == true) - // { - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.财务已审核); - // } - // else - // { - // isSucc = await _hbpoMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.财务已审核); - // } - // break; - // case (int)SettleBillState.商务已审核: - // if (IsForward == true) - // { - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.商务已审核); - // } - // else - // { - // isSucc = await _hbpoMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.商务已审核); - // } - // break; - // case (int)SettleBillState.已开票: - // if (IsForward == true) - // { - - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已开票); - // } - // else - // { - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已开票); - // } - // break; - // case (int)SettleBillState.客户已收票: - // if (IsForward == true) - // { - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.客户已收票); - // } - // else - // { - // isSucc = await _hbpoMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.客户已收票); - // } - // break; - // case (int)SettleBillState.已扣减: - // if (IsForward == true) - // { - // isSucc = await _hbpoMng.SetForwardState(p_entiy.InvGroupNum, SettleBillState.已扣减); - // } - // else - // { - // isSucc = await _hbpoMng.SetBackwardState(p_entiy.InvGroupNum, SettleBillState.已扣减); - // } - // break; - //} + return isSucc; } return false; @@ -234,10 +128,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers public virtual async Task SetForwardState(INVOICE_GRP p_entiy, SettleBillState p_State) { var state = p_State; - switch (p_entiy.State) + switch (p_State) { case SettleBillState.财务已审核: - if (state == SettleBillState.商务已审核) + if (p_entiy.State == SettleBillState.商务已审核) { p_entiy.State = state; } @@ -247,7 +141,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } break; case SettleBillState.商务已审核: - if (state == SettleBillState.已开票) + if (p_entiy.State == SettleBillState.已开票) { p_entiy.State = state; } @@ -257,7 +151,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } break; case SettleBillState.已扣减: - if (state == SettleBillState.客户已收票) + if (p_entiy.State == SettleBillState.客户已收票) { p_entiy.State = state; } @@ -289,10 +183,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers public virtual async Task SetBackwardState(INVOICE_GRP p_entiy, SettleBillState p_State) { var state = p_State; - switch (p_entiy.State) + switch (state) { case SettleBillState.商务已审核: - if (state == SettleBillState.财务已审核) + if (p_entiy.State == SettleBillState.财务已审核) { p_entiy.State = state; } @@ -302,7 +196,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } break; case SettleBillState.已开票: - if (state == SettleBillState.商务已审核) + if (p_entiy.State == SettleBillState.商务已审核) { p_entiy.State = state; } @@ -312,7 +206,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } break; case SettleBillState.客户已收票: - if (state == SettleBillState.已扣减) + if (p_entiy.State == SettleBillState.已扣减) { p_entiy.State = state; } @@ -374,6 +268,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers site: entity.Site ); var bbacDetail = new List(); + + + + + foreach (var itm in entityDetail) { bbacDetail.Add( @@ -397,6 +296,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers extend3: string.Empty, extend4: string.Empty )); + + await _repository.DbContext.BulkInsertAsync(new List() { bbac }); await _repository.DbContext.BulkInsertAsync(bbacDetail); return true; @@ -502,14 +403,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers } } } - return false; - } - - - - public virtual async Task Reject(INVOICE_GRP p_entity) { 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 index 83a6b7b7..d034a33b 100644 --- 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 @@ -1,4 +1,4 @@ -using SettleAccount.Bases; +using SettleAccount.Bases; using System; using System.Collections.Generic; using System.Linq; @@ -26,6 +26,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers private readonly INormalEfCoreRepository _repository; private readonly INormalEfCoreRepository _detailRepository; private readonly INormalEfCoreRepository _notRepository; + + public NOT_SA_MNG() + { + } + public NOT_SA_MNG ( INormalEfCoreRepository repository, @@ -37,6 +42,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers _detailRepository = detailRepository; _notRepository = notRepository; } + + + public virtual async Task GenerateSettlementOrder(List p_list, Action> p_action = null) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PD_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PD_MNG.cs index e85fb8c5..430c55bb 100644 --- a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PD_MNG.cs +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PD_MNG.cs @@ -36,6 +36,9 @@ public class PD_MNG:DomainService } + public PD_MNG() + { + } public virtual async Task GetMainAsync(string billNum) { diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs new file mode 100644 index 00000000..c2ed5609 --- /dev/null +++ b/code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs @@ -0,0 +1,269 @@ +using EFCore.BulkExtensions; +using Hangfire.Annotations; +using Microsoft.EntityFrameworkCore; +using SettleAccount.Bases; +using SettleAccount.Domain.BQ; +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 PUB_CAN_SA_MNG: DomainService + + { + private readonly INormalEfCoreRepository _repository; + private readonly INormalEfCoreRepository _detailRepository; + public PUB_CAN_SA_MNG + ( + INormalEfCoreRepository repository, + INormalEfCoreRepository detailRepository + ) + { + _repository = repository; + _detailRepository = detailRepository; + } + + public PUB_CAN_SA_MNG() + { + } + + public virtual async Task SetForwardState(PUB_CAN_SA 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 (PUB_CAN_SA p_entiy in ls) + { + switch (state) + { + case SettleBillState.财务已审核: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】,无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【商务已审核】"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.未结状态) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【未结状态】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.已扣减: + if (p_entiy.State == SettleBillState.客户已收票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[客户收票],无法设置成【财务已审核】状态"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.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 (PUB_CAN_SA p_entiy in ls) + { + + switch (state) + { + case SettleBillState.商务已审核: + if (p_entiy.State == SettleBillState.财务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【财务已审核】,无法设置成【商务已审核】状态"); + } + break; + case SettleBillState.已开票: + if (p_entiy.State == SettleBillState.商务已审核) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【商务已审核】状态,无法设置成【已开票】"); + } + break; + case SettleBillState.未结状态: + if (p_entiy.State == SettleBillState.已开票) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是【已开票】状态,无法设置成【未结状态】"); + } + break; + case SettleBillState.客户已收票: + if (p_entiy.State == SettleBillState.已扣减) + { + p_entiy.State = state; + } + else + { + throw new BusinessException("8989", "当前状态不是[财务已审核],无法设置成【财务已审核客户收票】状态"); + } + break; + case SettleBillState.财务已审核: + if (p_entiy.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(PUB_CAN_SA 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(); + } + + + + + + } + + +} + + + + + + + + + + +