Browse Source

更新明细接口

master
学 赵 1 year ago
parent
commit
a50c18dd87
  1. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs
  2. 121
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs
  3. 65
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs
  4. 315
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs
  5. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs
  6. 295
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs
  7. 299
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs
  8. 5
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs
  9. 11
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs
  10. 32
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs
  11. 1284
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG_EXT.cs
  12. 11
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs
  13. 23
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs

2
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_ADJ_DETAIL_DTO.cs

@ -83,8 +83,6 @@ public class PUB_ADJ_DETAIL_IMP_DTO
[ImporterHeader(Name = "厂内零件号")] [ImporterHeader(Name = "厂内零件号")]
public string PartCode { get; set; } public string PartCode { get; set; }
[ImporterHeader(Name = "标识号")] [ImporterHeader(Name = "标识号")]
public string PN { get; set; } public string PN { get; set; }
[ImporterHeader(Name = "数量")] [ImporterHeader(Name = "数量")]

121
code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/ADJ_SERVICE.cs

@ -21,6 +21,7 @@ using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Bases; namespace Win.Sfs.SettleAccount.Bases;
@ -34,18 +35,21 @@ public class ADJ_SERVICE : BASE_SERVICE
protected readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _repository; protected readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _repository;
protected readonly BaseDomainService _baseDomainService; protected readonly BaseDomainService _baseDomainService;
protected readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _invRepository; protected readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _invRepository;
protected readonly INormalEfCoreRepository<MaterialRelationship, Guid> _relRepository;
public ADJ_SERVICE( public ADJ_SERVICE(
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> repository, INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> repository,
BaseDomainService baseDomainService, BaseDomainService baseDomainService,
IExcelImportAppService excelImportService, IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator, ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager, ICommonManager commonManager,
INormalEfCoreRepository<INVOICE_GRP, Guid> invRepository INormalEfCoreRepository<INVOICE_GRP, Guid> invRepository,
INormalEfCoreRepository<MaterialRelationship, Guid> relRepository
) )
: base(excelImportService, snowflakeIdGenerator, commonManager) : base(excelImportService, snowflakeIdGenerator, commonManager)
{ {
_relRepository = relRepository;
_invRepository = invRepository; _invRepository = invRepository;
_repository = repository; _repository = repository;
_baseDomainService = baseDomainService; _baseDomainService = baseDomainService;
@ -64,6 +68,7 @@ public class ADJ_SERVICE : BASE_SERVICE
var dtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(entitys); var dtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(entitys);
return new PagedResultDto<PUB_ADJ_DETAIL_DTO>(totalCount, dtos); return new PagedResultDto<PUB_ADJ_DETAIL_DTO>(totalCount, dtos);
} }
/// <summary> /// <summary>
/// 导入文件 /// 导入文件
/// </summary> /// </summary>
@ -81,10 +86,11 @@ public class ADJ_SERVICE : BASE_SERVICE
{ {
throw new BusinessException("8989", "导入数据记录为0条"); throw new BusinessException("8989", "导入数据记录为0条");
} }
var invs=result.Select(p => p.OldInvBillNum).ToList();//所有发票号 var relation = _relRepository.ToList();
var deletels = _repository.Where(p =>invs.Contains(p.OldInvBillNum) ).ToList();//所有关联发票号的调整表 var invs = result.Select(p => p.OldInvBillNum).ToList();//所有发票号
var invlist= _invRepository.Where(p => invs.Contains(p.InvbillNum)).ToList();//所有发票 var deletels = _repository.Where(p => invs.Contains(p.OldInvBillNum)).ToList();//所有关联发票号的调整表
var dlists= deletels.Where(p=>string.IsNullOrEmpty(p.InvBillNum)).ToList();//所有新发票号不为空的调整记录 var invlist = _invRepository.Where(p => invs.Contains(p.InvbillNum)).ToList();//所有发票
var dlists = deletels.Where(p => string.IsNullOrEmpty(p.InvBillNum)).ToList();//所有新发票号不为空的调整记录
foreach (var itm in dlists) foreach (var itm in dlists)
{ {
errorList.Add(new ErrorExportDto() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}记录已经被重新开票,新发票号为:{itm.InvBillNum}" }); errorList.Add(new ErrorExportDto() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}记录已经被重新开票,新发票号为:{itm.InvBillNum}" });
@ -112,13 +118,14 @@ public class ADJ_SERVICE : BASE_SERVICE
} }
var query = from itm in entityList var query = from itm in entityList
join itm1 in invlist join itm1 in invlist
on itm.InvBillNum equals itm1.InvbillNum on itm.InvBillNum equals itm1.InvbillNum
join itm2 in relation on itm.LU equals itm2.SettleMaterialCode
select new PUB_ADJ_DETAIL( select new PUB_ADJ_DETAIL(
id: GuidGenerator.Create(), id: GuidGenerator.Create(),
keyCode: itm.PN + itm.LU, keyCode: itm.PN + itm.LU,
version: itm.Version, version: itm.Version,
settleBillNum: itm.SettleBillNum, settleBillNum: itm.SettleBillNum,
lU: itm.LU, lU: itm2.ErpMaterialCode,
pN: itm.PN, pN: itm.PN,
site: itm.Site, site: itm.Site,
qty: itm.Qty, qty: itm.Qty,
@ -130,13 +137,107 @@ public class ADJ_SERVICE : BASE_SERVICE
groupNum: itm.GroupNum, groupNum: itm.GroupNum,
oldinv: itm.InvBillNum, oldinv: itm.InvBillNum,
inv: string.Empty, inv: string.Empty,
partcode:itm.PartCode partcode: itm.PartCode
); );
await _repository.DbContext.BulkDeleteAsync(deletels);//删除发票下所有调整明细 await _repository.DbContext.BulkDeleteAsync(deletels);//删除发票下所有调整明细
await _repository.DbContext.BulkInsertAsync(query.ToList()); await _repository.DbContext.BulkInsertAsync(query.ToList());
return ApplicationConsts.SuccessStr; return ApplicationConsts.SuccessStr;
} }
/// <summary>
/// 导入文件
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost]
[DisableRequestSizeLimit]
public async Task<string> CheckImport(List<PUB_ADJ_DETAIL_DTO> p_list)
{
List<ERR_EXP_DTO> errorList = new List<ERR_EXP_DTO>();
//ExportImporter _exportImporter = new ExportImporter();
//var result = await _exportImporter.UploadExcelImport<PUB_ADJ_DETAIL_IMP_DTO>(files, _excelImportService);
//if (result.Count == 0)
//{
// throw new BusinessException("8989", "导入数据记录为0条");
//}
// var invs= p_list.Select(p => p.InvBillNum).ToList();//所有发票号
//var deletels = _repository.Where(p =>invs.Contains(p.OldInvBillNum) ).ToList();//所有关联发票号的调整表
// var invlist= _invRepository.Where(p => invs.Contains(p.InvbillNum)).ToList();//所有旧发票
// var dlists= deletels.Where(p=>string.IsNullOrEmpty(p.InvBillNum)).ToList();//所有新发票号不为空的调整记录
//foreach (var itm in dlists)
//{
// errorList.Add(new ERR_EXP_DTO() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}记录已经被重新开票,新发票号为:{itm.InvBillNum}" });
//}
//var first = deletels.FirstOrDefault();
//if (!string.IsNullOrEmpty(first.InvBillNum))
//{
// throw new BusinessException("8989", $"调整记录已经生成新发票号:{first.InvBillNum}");
//}
var entityList = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
var codelist = entityList.Select(p => p.LU).ToList();
var errors = await _baseDomainService.CheckBase(codelist, new BASE_CONF() { IsRelationShip = true });
foreach (var itm in errors)
{
errorList.Add(
new ERR_EXP_DTO() { ItemCode = $"{itm}", Message = $"[客户零件关系表]不存在客户零件号{itm}" });
}
var errorEntitylist = await _baseDomainService.CheckPriceList(entityList);
if (errorEntitylist.Count > 0)
{
foreach (var itm in errorEntitylist)
{
errorList.Add(new ERR_EXP_DTO() { ItemCode = $"{itm.LU}", Message = $"客户零件号{itm.LU}标识号{itm.PN}下线日期{itm.SettleDate}不存在价格单记录" });
}
}
if (errorList.Count > 0)
{
return await ExportErrorReportAsync(errorList);
}
//var query = from itm in entityList
// join itm1 in invlist
// on itm.InvBillNum equals itm1.InvbillNum
// select new PUB_ADJ_DETAIL(
// id: GuidGenerator.Create(),
// keyCode: itm.PN + itm.LU,
// version: itm.Version,
// settleBillNum: itm.SettleBillNum,
// lU: itm.LU,
// pN: itm.PN,
// site: itm.Site,
// qty: itm.Qty,
// extend1: string.Empty,
// price: 0,
// invGroupNum: itm1.InvGroupNum,
// settleDate: itm.SettleDate,
// businessType: itm1.BusinessType,
// groupNum: itm.GroupNum,
// oldinv: itm.InvBillNum,
// inv: string.Empty,
// partcode:itm.PartCode
// );
//await _repository.DbContext.BulkDeleteAsync(deletels);//删除发票下所有调整明细
//await _repository.DbContext.BulkInsertAsync(query.ToList());
return ApplicationConsts.SuccessStr;
}
} }

65
code/src/Modules/SettleAccount/src/SettleAccount.Application/Bases/BA_SERVICE.cs

@ -322,6 +322,71 @@ namespace Win.Sfs.SettleAccount.Bases
throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容"); throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容");
} }
/// <summary>
/// hbpo、jit、备件等
/// </summary>
/// <param name="dtos">可结算明细列表</param>
/// <param name="p_version">版本号</param>
/// <param name="p_InvGroupNum">发票分组</param>
/// <param name="p_parentInvBillNum">原发票号</param>
protected async Task<List<INVOICE_WAIT_DETAIL>> ReissueSecInvoiceExtend<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> p_tmplist, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
{
var ls = await _invMng.ReissueSecInvoiceExtend(p_list, p_adjlist, p_tmplist, p_parentInvBillNum, p_version);
if (ls.Count>0)
{
return ls;
}
throw new BusinessException("8989", "生成失败,请检查调发票整表和旧发票内容");
}
/// <summary>
/// 第一次开票
/// </summary>
/// <param name="dtos"></param>
/// <param name="p_notlist"></param>
/// <param name="p_version"></param>
/// <param name="p_InvGroupNum"></param>
/// <param name="p_parentInvBillNum">要作废的发票号</param>
/// <param name="businessType"></param>
/// <returns></returns>
protected async Task<List<INVOICE_WAIT_DETAIL>> ReissueFirstInvoiceExtend<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
{
var ls = await _invMng.ReissueFirstInvoiceExtend(p_list, p_adjlist, dtos, p_parentInvBillNum, p_version);
if (ls.Count>0)
{
return ls;
}
throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容");
}
/// <summary> /// <summary>
/// 校验规则 /// 校验规则

315
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_BA_SERVICE.cs

@ -1,4 +1,5 @@
using DocumentFormat.OpenXml.Spreadsheet;
using EFCore.BulkExtensions; using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -12,6 +13,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.ObjectMapping;
using Win.Abp.Snowflakes; using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.Bases; using Win.Sfs.SettleAccount.Bases;
@ -65,18 +67,152 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
/// <returns></returns> /// <returns></returns>
public override async Task<string> ReissueInvoice(string p_invbillnum) public override async Task<string> ReissueInvoice(string p_invbillnum)
{ {
var mappingList= await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 //var mappingList= await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
if (mappingList != null && mappingList.Count() > 0) //if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum);
var settle = await _bbacMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{ {
var version=int.Parse(DateTime.Now.ToString("yyyymm")); throw new UserFriendlyException($"选择发票:{p_invbillnum}对应的可结算单不在请检查!");
var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv= await GetInvoiceGroupByInvBillNum(p_invbillnum); }
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new UserFriendlyException($"选择发票:{p_invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException($"选择发票:{p_invbillnum}状态在财务审核后可以报废重开,之前不能重开可以退回!");
}
var bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0)
{
foreach (var itm in adjlist)
{
bbaclist.Add(new BBAC_CAN_SA_DETAIL(
guid: itm.Id,
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
category: itm.BusinessType,
isReturn: itm.Qty > 0 ? false : true,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
contactid: itm.Extend1,//生产号
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
//var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算
var priceList = _priceRepository.ToList();//价格单
var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
if (errorList.Count() > 0)
{
return await ExportErrorReportAsync(errorList);
}
var dto1s = ObjectMapper.Map<List<BBAC_CAN_SA_DETAIL>, List<BBAC_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in dto1s
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime//客户零件号
select new TEMP_CAN_SA_DETAIL
{
Id = d.Id,
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = d.ContractDocID,
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (p_invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
await ReissueFirstInvoice(bbaclist, adjlist, dtos, version, p_invbillnum);
}
else//二次开票
{
await ReissueSecInvoice(bbaclist, adjlist, dtos, version, p_invbillnum);
}
}
}
else
{
throw new UserFriendlyException($"不存发票号为:{p_invbillnum}发票");
}
//}
//else
//{
// throw new UserFriendlyException( $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr;
}
[HttpPost]
/// <summary>
/// 发票重开
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<string> ReissueInvoiceExtend(List<PUB_ADJ_DETAIL_DTO> p_list)
{
var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count == 0)
{
throw new UserFriendlyException($"调整表无数据!");
}
var first = p_list.FirstOrDefault();
var invbillnum = first.InvBillNum;
//var mappingList= await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version=int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv= await GetInvoiceGroupByInvBillNum(invbillnum);
var settle =await _bbacMng.GetMainAsync(inv.InvGroupNum); var settle =await _bbacMng.GetMainAsync(inv.InvGroupNum);
if(settle==null) if(settle==null)
{ {
throw new BusinessException("8989", $"选择发票:{p_invbillnum}对应的可结算单不在请检查!"); throw new UserFriendlyException( $"选择发票:{invbillnum}对应的可结算单不在请检查!");
} }
version=settle.Version; version=settle.Version;
@ -84,10 +220,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{ {
if (inv.InvoiceState == InvoiceBillState.) if (inv.InvoiceState == InvoiceBillState.)
{ {
throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!"); throw new UserFriendlyException( $"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException( $"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前不能重开可以退回!");
} }
var bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件
var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 var bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
// var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0) if (adjlist != null && adjlist.Count() > 0)
{ {
foreach (var itm in adjlist) foreach (var itm in adjlist)
@ -153,26 +294,166 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
var dtos = q.ToList(); var dtos = q.ToList();
if (dtos != null && dtos.Count > 0) if (dtos != null && dtos.Count > 0)
{ {
if (p_invbillnum.Substring(0, 3) == "INV")//一次开票重开 if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{ {
await ReissueFirstInvoice(bbaclist,adjlist,dtos,version, p_invbillnum); await ReissueFirstInvoice(bbaclist,adjlist,dtos,version, invbillnum);
} }
else//二次开票 else//二次开票
{ {
await ReissueSecInvoice(bbaclist,adjlist,dtos,version, p_invbillnum); await ReissueSecInvoice(bbaclist,adjlist,dtos,version, invbillnum);
} }
} }
} }
else else
{ {
throw new BusinessException("8989", $"不存发票号为:{p_invbillnum}发票"); throw new UserFriendlyException( $"不存发票号为:{invbillnum}发票");
} }
} //}
else //else
//{
// throw new UserFriendlyException( $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr;
}
[HttpPost]
/// <summary>
/// 发票重开列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<List<INVOICE_WAIT_DETAIL_DTO>> ReissueInvoiceList(List<PUB_ADJ_DETAIL_DTO> p_list)
{
List<INVOICE_WAIT_DETAIL_DTO> ls = new List<INVOICE_WAIT_DETAIL_DTO>();
var adjlist=ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count==0)
{ {
throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号"); throw new UserFriendlyException($"调整表无数据!");
} }
return ApplicationConsts.SuccessStr; var first = p_list.FirstOrDefault();
var invbillnum = first.InvBillNum;
//var mappingList = await GetMapGroupAsync(invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(invbillnum);
var settle = await _bbacMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{
throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不在请检查!");
}
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前请退回重开!");
}
var bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
//var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0)
{
foreach (var itm in adjlist)
{
bbaclist.Add(new BBAC_CAN_SA_DETAIL(
guid: itm.Id,
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
category: itm.BusinessType,
isReturn: itm.Qty > 0 ? false : true,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
contactid: itm.Extend1,//生产号
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
var priceList = _priceRepository.ToList();//价格单
//var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
//if (errorList.Count() > 0)
//{
// return await ExportErrorReportAsync(errorList);
//}
var dto1s = ObjectMapper.Map<List<BBAC_CAN_SA_DETAIL>, List<BBAC_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in dto1s
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime//客户零件号
select new TEMP_CAN_SA_DETAIL
{
Id = d.Id,
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = d.ContractDocID,
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
var entities=await ReissueFirstInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls= ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
else//二次开票
{
var entities = await ReissueSecInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls=ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
}
}
else
{
throw new UserFriendlyException($"不存发票号为:{invbillnum}发票");
}
//}
//else
//{
// throw new UserFriendlyException($"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ls;
} }
} }
} }

2
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_CAN_SA_SERVICE.cs

@ -159,7 +159,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
else else
{ {
throw new BusinessException("8989", string.Format("{0}不存在该可结算单号", input.BillNum)); throw new UserFriendlyException(string.Format("{0}不存在该可结算单号", input.BillNum));
} }
return ApplicationConsts.SuccessStr; return ApplicationConsts.SuccessStr;
} }

295
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_BA_SERVICE.cs

@ -56,25 +56,29 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
/// <returns></returns> /// <returns></returns>
public override async Task<string> ReissueInvoice(string p_invbillnum) public override async Task<string> ReissueInvoice(string p_invbillnum)
{ {
var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 //var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
if (mappingList != null && mappingList.Count() > 0) //if (mappingList != null && mappingList.Count() > 0)
{ //{
var version = int.Parse(DateTime.Now.ToString("yyyymm")); var version = int.Parse(DateTime.Now.ToString("yyyymm"));
var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum); var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum);
var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum); var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum);
if (settle == null) if (settle == null)
{ {
throw new BusinessException("8989", $"选择发票:{p_invbillnum}对应的可结算单不在请检查!"); throw new UserFriendlyException( $"选择发票:{p_invbillnum}对应的可结算单不在请检查!");
} }
version = settle.Version; version = settle.Version;
if (inv != null) if (inv != null)
{ {
if (inv.InvoiceState == InvoiceBillState.) if (inv.InvoiceState == InvoiceBillState.)
{ {
throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!"); throw new UserFriendlyException( $"选择发票:{p_invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException( $"选择发票:{p_invbillnum}状态在财务审核后可以报废重开,之前请退回重开!");
} }
var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件 var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count > 0) if (adjlist != null && adjlist.Count > 0)
{ {
@ -150,15 +154,288 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
else else
{ {
throw new BusinessException("8989", $"不存发票号为:{p_invbillnum}发票"); throw new UserFriendlyException( $"不存发票号为:{p_invbillnum}发票");
}
//}
//else
//{
// throw new UserFriendlyException( $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr;
}
[HttpPost]
/// <summary>
/// 发票重开
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<string> ReissueInvoiceExtend(List<PUB_ADJ_DETAIL_DTO> p_list)
{
var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count == 0)
{
throw new UserFriendlyException($"调整表无数据!");
}
var first = p_list.FirstOrDefault();
var invbillnum = first.InvBillNum;
//var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(invbillnum);
var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{
throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不存在请检查!");
}
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前请退回重开!");
}
var hbpolist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
// var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count > 0)
{
foreach (var itm in adjlist)
{
hbpolist.Add(new HBPO_CAN_SA_DETAIL(
guid: GuidGenerator.Create(),
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = hbpolist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
//var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算
var priceList = _priceRepository.ToList();//价格单
var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
if (errorList.Count() > 0)
{
return await ExportErrorReportAsync(errorList);
}
// var dto1s = ObjectMapper.Map<List<HBPO_CAN_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in entitys
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime
select new TEMP_CAN_SA_DETAIL
{
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
// MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = "n",
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
await ReissueFirstInvoice(hbpolist, adjlist, dtos, version, invbillnum);
}
else//二次开票
{
await ReissueSecInvoice(hbpolist, adjlist, dtos, version, invbillnum);
}
} }
} }
else else
{ {
throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号"); throw new UserFriendlyException($"不存发票号为:{invbillnum}发票");
} }
//}
//else
//{
// throw new UserFriendlyException( $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr; return ApplicationConsts.SuccessStr;
} }
[HttpPost]
/// 发票重开列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<List<INVOICE_WAIT_DETAIL_DTO>> ReissueInvoiceList( List<PUB_ADJ_DETAIL_DTO> p_list)
{
List<INVOICE_WAIT_DETAIL_DTO> ls = new List<INVOICE_WAIT_DETAIL_DTO>();
var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count == 0)
{
throw new UserFriendlyException($"调整表无数据!");
}
var first = p_list.FirstOrDefault();
var invbillnum = first.InvBillNum;
//var mappingList = await GetMapGroupAsync(invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(invbillnum);
var settle = await _hbpoMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{
throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不在请检查!");
}
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前请退回重开!");
}
var bbaclist = await _hbpoMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
//var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0)
{
foreach (var itm in adjlist)
{
bbaclist.Add(new HBPO_CAN_SA_DETAIL(
guid: itm.Id,
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
var priceList = _priceRepository.ToList();//价格单
//var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
//if (errorList.Count() > 0)
//{
// return await ExportErrorReportAsync(errorList);
//}
var dto1s = ObjectMapper.Map<List<HBPO_CAN_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in dto1s
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime//客户零件号
select new TEMP_CAN_SA_DETAIL
{
Id = d.Id,
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = "N",
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
var entities = await ReissueFirstInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
else//二次开票
{
var entities = await ReissueSecInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
}
}
else
{
throw new UserFriendlyException($"不存发票号为:{invbillnum}发票");
}
//}
//else
//{
// throw new UserFriendlyException($"不存发票号:{invbillnum}对应的结算分组号");
//}
return ls;
}
} }
} }

299
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_BA_SERVICE.cs

@ -15,6 +15,7 @@ using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.Bases; using Win.Sfs.SettleAccount.Bases;
using Win.Sfs.SettleAccount.CommonManagers; using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.BQ.Managers; using Win.Sfs.SettleAccount.Entities.BQ.Managers;
using Win.Sfs.SettleAccount.Entities.BQ.Temp; using Win.Sfs.SettleAccount.Entities.BQ.Temp;
using Win.Sfs.SettleAccount.Entities.Prices; using Win.Sfs.SettleAccount.Entities.Prices;
@ -43,6 +44,138 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
} }
/// <summary>
/// 提交发票
/// </summary>
/// <param name="p_list"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
/// <exception cref="BusinessException"></exception>
[HttpPost]
public virtual async Task<string> ReissueInvoiceExtend(List<PUB_ADJ_DETAIL_DTO> p_list)
{
var first = p_list.FirstOrDefault();
var invbillnum = first.InvBillNum;
List<INVOICE_WAIT_DETAIL_DTO> ls = new List<INVOICE_WAIT_DETAIL_DTO>();
var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count == 0)
{
throw new UserFriendlyException($"调整表无数据!");
}
//var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(invbillnum);
var settle = await _pubMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{
throw new BusinessException("8989", $"选择发票:{invbillnum}对应的可结算单不在请检查!");
}
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new BusinessException("8989", $"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new BusinessException("8989", $"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前不能重开可以退回!");
}
var publist = await _pubMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
//var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0)
{
foreach (var itm in adjlist)
{
publist.Add(new PUB_CAN_SA_DETAIL(
guid: GuidGenerator.Create(),
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = publist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
//var groupNumList = entitys.Select(p => new { p.GroupNum).Distinct().ToList();
//var notList = _notRepository.Where(p => gNumList.Contains(p.GroupNum)).ToList();//不能结算
var priceList = _priceRepository.ToList();//价格单
var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
if (errorList.Count > 0)
{
return await ExportErrorReportAsync(errorList);
}
// var dto1s = ObjectMapper.Map<List<HBPO_CAN_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in entitys
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime
select new TEMP_CAN_SA_DETAIL
{
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
// MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = "n",
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
await ReissueFirstInvoice(publist, adjlist, dtos, version, invbillnum);
}
else//二次开票
{
await ReissueSecInvoice(publist, adjlist, dtos, version, invbillnum);
}
}
}
else
{
throw new BusinessException("8989", $"不存发票号为:{invbillnum}发票");
}
//}
//else
//{
// throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr;
}
@ -55,11 +188,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public override async Task<string> ReissueInvoice(string p_invbillnum) public override async Task<string> ReissueInvoice(string p_invbillnum)
{ {
var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组 //var mappingList = await GetMapGroupAsync(p_invbillnum);//发票对应结算分组
if (mappingList != null && mappingList.Count() > 0) //if (mappingList != null && mappingList.Count() > 0)
{ //{
var version = int.Parse(DateTime.Now.ToString("yyyymm")); var version = int.Parse(DateTime.Now.ToString("yyyymm"));
var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组 //var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum); var inv = await GetInvoiceGroupByInvBillNum(p_invbillnum);
var settle = await _pubMng.GetMainAsync(inv.InvGroupNum); var settle = await _pubMng.GetMainAsync(inv.InvGroupNum);
@ -75,7 +208,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{ {
throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!"); throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态为报废状态不能重开!");
} }
var publist = await _pubMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件 if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new BusinessException("8989", $"选择发票:{p_invbillnum}状态在财务审核后可以报废重开,之前不能重开可以退回!");
}
var publist = await _pubMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细 var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0) if (adjlist != null && adjlist.Count() > 0)
{ {
@ -156,12 +293,156 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{ {
throw new BusinessException("8989", $"不存发票号为:{p_invbillnum}发票"); throw new BusinessException("8989", $"不存发票号为:{p_invbillnum}发票");
} }
} //}
else //else
//{
// throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号");
//}
return ApplicationConsts.SuccessStr;
}
[HttpPost]
/// 发票重开列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public virtual async Task<List<INVOICE_WAIT_DETAIL_DTO>> ReissueInvoiceList(List<PUB_ADJ_DETAIL_DTO> p_list)
{
var first=p_list.FirstOrDefault();
var invbillnum=first.InvBillNum;
List<INVOICE_WAIT_DETAIL_DTO> ls = new List<INVOICE_WAIT_DETAIL_DTO>();
var adjlist = ObjectMapper.Map<List<PUB_ADJ_DETAIL_DTO>, List<PUB_ADJ_DETAIL>>(p_list);
if (adjlist == null && adjlist.Count == 0)
{ {
throw new BusinessException("8989", $"不存发票号:{p_invbillnum}对应的结算分组号"); throw new UserFriendlyException($"调整表无数据!");
} }
return ApplicationConsts.SuccessStr;
//var mappingList = await GetMapGroupAsync(invbillnum);//发票对应结算分组
//if (mappingList != null && mappingList.Count() > 0)
//{
var version = int.Parse(DateTime.Now.ToString("yyyymm"));
//var gList = mappingList.Select(p => p.SettleGroupNum).ToList();//获取发票所有结算分组
var inv = await GetInvoiceGroupByInvBillNum(invbillnum);
var settle = await _pubMng.GetMainAsync(inv.InvGroupNum);
if (settle == null)
{
throw new UserFriendlyException($"选择发票:{invbillnum}对应的可结算单不在请检查!");
}
version = settle.Version;
if (inv != null)
{
if (inv.InvoiceState == InvoiceBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态为报废状态不能重开!");
}
if (inv.State == SettleBillState. || inv.State == SettleBillState.)
{
throw new UserFriendlyException($"选择发票:{invbillnum}状态在财务审核后可以报废重开,之前请退回重开!");
}
var bbaclist = await _pubMng.GetContainsAsync(inv.InvbillNum);//结算分组对应结算零件
//var adjlist = await _adjRepository.Where(p => p.OldInvBillNum == inv.InvbillNum).ToListAsync();//调整表明细
if (adjlist != null && adjlist.Count() > 0)
{
foreach (var itm in adjlist)
{
bbaclist.Add(new PUB_CAN_SA_DETAIL(
guid: itm.Id,
keyCode: itm.KeyCode,
version: itm.Version,
billNum: itm.InvGroupNum,
settleBillNum: itm.SettleBillNum,
lU: itm.LU,
pN: itm.PN,
site: itm.Site,
qty: itm.Qty,
price: itm.Price,
businessType: itm.BusinessType,
settleDate: itm.SettleDate,
groupNum: itm.GroupNum,
invGroupNum: itm.InvGroupNum,
invbillnum: string.Empty,
partcode: itm.PartCode
));
}
}
var entitys = bbaclist;//合并库存调整单和就发票可结算明细数据
var gNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
var priceList = _priceRepository.ToList();//价格单
//var errorList = await CheckInvoiceGenerationRules(entitys, priceList, inv.BusinessType);
//if (errorList.Count() > 0)
//{
// return await ExportErrorReportAsync(errorList);
//}
var dto1s = ObjectMapper.Map<List<PUB_CAN_SA_DETAIL>, List<PUB_CAN_SA_DETAIL_DTO>>(entitys);
var q = from d in dto1s
join p in priceList on d.PartCode equals p.LU
where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime//客户零件号
select new TEMP_CAN_SA_DETAIL
{
Id = d.Id,
SettleBillNum = d.SettleBillNum,
Site = d.Site,
Version = d.Version,
Price = p.Price,
BillNum = d.BillNum,
SettleDate = d.SettleDate,
InvGroupNum = d.InvGroupNum,
LU = d.LU,
MaterialDesc = d.MaterialDesc,
PN = d.PN,
Qty = d.Qty,
GroupNum = d.GroupNum,
Amt = Math.Round(d.Qty * p.Price, 2),
ContractDocID = "N",
BeginDate = p.BeginTime,
EndDate = p.EndTime,
PartCode = d.PartCode
};
var dtos = q.ToList();
if (dtos != null && dtos.Count > 0)
{
if (invbillnum.Substring(0, 3) == "INV")//一次开票重开
{
var entities = await ReissueFirstInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
else//二次开票
{
var entities = await ReissueSecInvoiceExtend(bbaclist, adjlist, dtos, version, invbillnum);
ls = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(entities);
}
}
}
else
{
throw new UserFriendlyException($"不存发票号为:{invbillnum}发票");
}
//}
//else
//{
// throw new UserFriendlyException($"不存发票号:{invbillnum}对应的结算分组号");
//}
return ls;
} }
} }
} }

5
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/BBAC_CAN_SA_MNG.cs

@ -253,7 +253,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
return await _detailRepository.Where(p =>p.InvbillNum== p_invbillnum && p_list.Contains(p.GroupNum)).ToListAsync(); return await _detailRepository.Where(p =>p.InvbillNum== p_invbillnum && p_list.Contains(p.GroupNum)).ToListAsync();
} }
public virtual async Task<List<BBAC_CAN_SA_DETAIL>> GetContainsAsync(string p_invbillnum)
{
return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum).ToListAsync();
}
/// <summary> /// <summary>
/// 通过发票号获取结算数据 /// 通过发票号获取结算数据
/// </summary> /// </summary>

11
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/HBPO_CAN_SA_MNG.cs

@ -263,6 +263,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum && p_list.Contains(p.GroupNum)).ToListAsync(); return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum && p_list.Contains(p.GroupNum)).ToListAsync();
} }
/// <summary>
/// 获取发票对应结算分组所有零件
/// </summary>
/// <param name="billNum"></param>
/// <returns></returns>
public virtual async Task<List<HBPO_CAN_SA_DETAIL>> GetContainsAsync(string p_invbillnum)
{
return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum).ToListAsync();
}
/// <summary> /// <summary>
/// 通过发票号获取结算数据 /// 通过发票号获取结算数据

32
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG.cs

@ -28,7 +28,7 @@ using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
{ {
public class INV_MNG : DomainService public partial class INV_MNG : DomainService
{ {
//private readonly INormalEfCoreRepository<TCAN_SA, Guid> _canRepository; //private readonly INormalEfCoreRepository<TCAN_SA, Guid> _canRepository;
private readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _repository; private readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _repository;
@ -1385,6 +1385,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
); );
invlist.Add(invbill); invlist.Add(invbill);
} }
await _repository.DbContext.BulkInsertAsync(invlist); await _repository.DbContext.BulkInsertAsync(invlist);
await _repository.DbContext.BulkInsertAsync(groupList); await _repository.DbContext.BulkInsertAsync(groupList);
await _repository.DbContext.BulkInsertAsync(detailList); await _repository.DbContext.BulkInsertAsync(detailList);
@ -1900,10 +1905,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
switch (inv.BusinessType) switch (inv.BusinessType)
{ {
case EnumBusinessType.MaiDanJianHBPO: case EnumBusinessType.MaiDanJianHBPO:
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);
break; break;
case EnumBusinessType.MaiDanJianBBAC: case EnumBusinessType.MaiDanJianBBAC:
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true); invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);
break; break;
case EnumBusinessType.ZhiGongJianBBAC: case EnumBusinessType.ZhiGongJianBBAC:
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);//重开可以变多张发票 invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, true);//重开可以变多张发票
@ -1926,23 +1931,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
} }
//if (inv.BusinessType == EnumBusinessType.MaiDanJianHBPO)
//{
// invlist = await MakeInvoice(p_list,p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true);
//}
//if (inv.BusinessType == EnumBusinessType.BeiJian)
//{
// invlist = await BJInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, true);
//}
//else
//{
// invlist = await FirstInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType);//重开可以变多张发票
//}
if (invlist.Count == 0) if (invlist.Count == 0)
{ {
return false; return false;
@ -2239,10 +2227,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
switch (inv.BusinessType) switch (inv.BusinessType)
{ {
case EnumBusinessType.MaiDanJianHBPO: case EnumBusinessType.MaiDanJianHBPO:
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, false);
break; break;
case EnumBusinessType.MaiDanJianBBAC: case EnumBusinessType.MaiDanJianBBAC:
invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, string.Empty, inv.BusinessType, false); invlist = await MakeInvoice(p_list, p_adjlist, dtos, p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType, false);
break; break;
case EnumBusinessType.ZhiGongJianBBAC: case EnumBusinessType.ZhiGongJianBBAC:
invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType,false);//重开可以变多张发票 invlist = await JITInvoice(p_list, p_adjlist, dtos, new List<TEMP_NOT_SA_DETAIL>(), p_version, inv.InvGroupNum, inv.InvbillNum, inv.BusinessType,false);//重开可以变多张发票

1284
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/INV_MNG_EXT.cs

File diff suppressed because it is too large

11
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Managers/PUB_CAN_SA_MNG.cs

@ -255,6 +255,17 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers
} }
/// <summary>
/// 获取发票对应结算分组所有零件
/// </summary>
/// <param name="billNum"></param>
/// <returns></returns>
public virtual async Task<List<PUB_CAN_SA_DETAIL>> GetContainsAsync(string p_invbillnum)
{
return await _detailRepository.Where(p => p.InvbillNum == p_invbillnum).ToListAsync();
}
/// <summary> /// <summary>
/// 通过发票号获取结算数据 /// 通过发票号获取结算数据

23
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/Temp/TempClass.cs

@ -5,6 +5,8 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SettleAccount.Bases; using SettleAccount.Bases;
using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Dtos;
namespace Win.Sfs.SettleAccount.Entities.BQ.Temp; namespace Win.Sfs.SettleAccount.Entities.BQ.Temp;
public class TMEP_INV public class TMEP_INV
@ -27,6 +29,27 @@ public class TMEP_INV
/// </summary> /// </summary>
public DateTime EndDate { get; set; } public DateTime EndDate { get; set; }
} }
public class INVOICE_GRP_DETAIL
{
/// <summary>
/// 发票明细
/// </summary>
public List<INVOICE_WAIT_DETAIL> INVOICE_DETAIL { get; set; }
/// <summary>
/// 发票和结算分组对应关系
/// </summary>
public List<INVOICE_MAP_GROUP> INVOICE_MAP_GROUP { get; set; }
/// <summary>
/// 发票调整明细
/// </summary>
public List<PUB_ADJ_DETAIL> ADJ_DETAIL { get; set; }
}
public class TEMP_CAN_SA_DETAIL public class TEMP_CAN_SA_DETAIL
{ {

Loading…
Cancel
Save