|
@ -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,19 @@ 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 _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($"选择发票:{p_invbillnum}对应的可结算单不在请检查!"); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
version = settle.Version; |
|
|
version = settle.Version; |
|
@ -84,9 +87,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
{ |
|
|
{ |
|
|
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 bbaclist = await _bbacMng.GetContainsAsync(inv.InvbillNum, gList);//结算分组对应结算零件
|
|
|
|
|
|
|
|
|
var bbaclist = await _bbacMng.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) |
|
|
{ |
|
|
{ |
|
@ -165,14 +173,287 @@ 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 _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 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 (invbillnum.Substring(0, 3) == "INV")//一次开票重开
|
|
|
|
|
|
{ |
|
|
|
|
|
await ReissueFirstInvoice(bbaclist,adjlist,dtos,version, invbillnum); |
|
|
|
|
|
} |
|
|
|
|
|
else//二次开票
|
|
|
|
|
|
{ |
|
|
|
|
|
await ReissueSecInvoice(bbaclist,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>
|
|
|
|
|
|
/// 发票重开列表
|
|
|
|
|
|
/// </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 _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; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|