|
|
@ -1,4 +1,6 @@ |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Hangfire; |
|
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using NPOI.SS.Formula.Functions; |
|
|
|
using SettleAccount.Bases; |
|
|
@ -9,6 +11,7 @@ using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Volo.Abp.Domain.Services; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
@ -18,11 +21,22 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
{ |
|
|
|
//private readonly INormalEfCoreRepository<TCAN_SA, Guid> _canRepository;
|
|
|
|
private readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _repository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> _groupRepository; |
|
|
|
private readonly INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> _detailRepository; |
|
|
|
private readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _notRepository; |
|
|
|
private readonly CAN_SA_MNG<PUB_CAN_SA, PUB_CAN_SA_DETAIL> _pubMng; |
|
|
|
private readonly CAN_SA_MNG<BBAC_CAN_SA, BBAC_CAN_SA_DETAIL> _bbacMng; |
|
|
|
private readonly CAN_SA_MNG<HBPO_CAN_SA, HBPO_CAN_SA_DETAIL> _hbpoMng; |
|
|
|
|
|
|
|
public INV_MNG |
|
|
|
( |
|
|
|
CAN_SA_MNG<PUB_CAN_SA, PUB_CAN_SA_DETAIL> pubMng, |
|
|
|
CAN_SA_MNG<BBAC_CAN_SA, BBAC_CAN_SA_DETAIL> bbacMng, |
|
|
|
CAN_SA_MNG<HBPO_CAN_SA, HBPO_CAN_SA_DETAIL> hbpoMng, |
|
|
|
//INormalEfCoreRepository<TCAN_SA, Guid> canRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> groupRepository, |
|
|
@ -36,7 +50,23 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
_detailRepository = detailRepository; |
|
|
|
_groupRepository = groupRepository; |
|
|
|
_notRepository = notRepository; |
|
|
|
_pubMng = pubMng; |
|
|
|
_bbacMng = bbacMng; |
|
|
|
_hbpoMng = hbpoMng; |
|
|
|
|
|
|
|
} |
|
|
|
public virtual async Task<bool> SetForwardState(string p_groupBillnum , InvoiceBillState p_State) |
|
|
|
{ |
|
|
|
var _first=_repository.Where(p => p.InvbillNum == p_groupBillnum).FirstOrDefault(); |
|
|
|
if (_first != null) |
|
|
|
{ |
|
|
|
return await SetForwardState(_first, p_State); |
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task<bool> SetForwardState(INVOICE_GRP p_entiy, InvoiceBillState p_State) |
|
|
|
{ |
|
|
|
var state = p_State; |
|
|
@ -63,13 +93,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
} |
|
|
|
break; |
|
|
|
case InvoiceBillState.已扣减: |
|
|
|
if (state == InvoiceBillState.财务已审核) |
|
|
|
if (state == InvoiceBillState.客户已收票) |
|
|
|
{ |
|
|
|
p_entiy.State = state; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", "当前状态不是【商务已审核】,无法设置成【财务已审核】状态"); |
|
|
|
throw new BusinessException("8989", "当前状态不是【客户已收票】状态,无法设置成【已扣减】状态"); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
@ -77,11 +107,176 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<INVOICE_GRP> GetEntityByBillNum(string p_billNum) |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获得发票主表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_billNum"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<INVOICE_GRP> GetMainAsync(string p_groupbillNum) |
|
|
|
{ |
|
|
|
return await _repository.Where(p => p.InvbillNum == p_groupbillNum).FirstOrDefaultAsync(); |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 已收票
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_groupbillnum">发票分组号</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<bool> ReceivedAsync(string p_groupbillnum) |
|
|
|
{ |
|
|
|
var inv = _repository.Where(p => p.InvGroupNum == p_groupbillnum).FirstOrDefault(); |
|
|
|
if (inv.BusinessType == EnumBusinessType.BBAC) |
|
|
|
{ |
|
|
|
var entity = await _bbacMng.GetMainAsync(inv.InvGroupNum); |
|
|
|
if (entity == null) |
|
|
|
{ |
|
|
|
|
|
|
|
var entityDetail = await _bbacMng.GetDetalListAsync(inv.InvGroupNum); |
|
|
|
var bbac = new BBAC_PD( |
|
|
|
guid: entity.Id, |
|
|
|
version: entity.Version, |
|
|
|
billNum: entity.BillNum, |
|
|
|
settleBillNum: entity.SettleBillNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: entity.InvGroupNum, |
|
|
|
site: entity.Site |
|
|
|
); |
|
|
|
var bbacDetail = new List<BBAC_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityDetail) |
|
|
|
{ |
|
|
|
bbacDetail.Add( |
|
|
|
new BBAC_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: itm.Price, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
await _repository.DbContext.BulkInsertAsync(new List<BBAC_PD>() { bbac }); |
|
|
|
await _repository.DbContext.BulkInsertAsync(bbacDetail); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (inv.BusinessType == EnumBusinessType.HBPO) |
|
|
|
{ |
|
|
|
var entity = await _hbpoMng.GetMainAsync(inv.InvGroupNum); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
|
|
|
|
|
var entityDetail = await _hbpoMng.GetDetalListAsync(inv.InvGroupNum); |
|
|
|
if (entityDetail != null && entityDetail.Count() > 0) |
|
|
|
{ |
|
|
|
var hbpo = new HBPO_PD( |
|
|
|
guid: entity.Id, |
|
|
|
version: entity.Version, |
|
|
|
billNum: entity.BillNum, |
|
|
|
settleBillNum: entity.SettleBillNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: entity.InvGroupNum, |
|
|
|
site: entity.Site |
|
|
|
); |
|
|
|
var hbpoDetail = new List<HBPO_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityDetail) |
|
|
|
{ |
|
|
|
hbpoDetail.Add( |
|
|
|
new HBPO_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: itm.Price, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty |
|
|
|
)); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(new List<HBPO_PD>() { hbpo }); |
|
|
|
await _repository.DbContext.BulkInsertAsync(hbpoDetail); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var entity = await _pubMng.GetMainAsync(inv.InvGroupNum); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
|
var entityDetail = await _pubMng.GetDetalListAsync(inv.InvGroupNum); |
|
|
|
if (entityDetail != null && entityDetail.Count() > 0) |
|
|
|
{ |
|
|
|
return await _repository.Where(p => p.InvGroupNum == p_billNum).FirstOrDefaultAsync(); |
|
|
|
var pub = new PUB_PD( |
|
|
|
guid: entity.Id, |
|
|
|
version: entity.Version, |
|
|
|
billNum: entity.BillNum, |
|
|
|
settleBillNum: entity.SettleBillNum, |
|
|
|
state: SettleBillState.客户已收票, |
|
|
|
invGroupNum: entity.InvGroupNum, |
|
|
|
site: entity.Site |
|
|
|
); |
|
|
|
var pubDetail = new List<PUB_PD_DETAIL>(); |
|
|
|
foreach (var itm in entityDetail) |
|
|
|
{ |
|
|
|
pubDetail.Add( |
|
|
|
new PUB_PD_DETAIL( |
|
|
|
guid: itm.Id, |
|
|
|
keyCode: itm.KeyCode, |
|
|
|
version: itm.Version, |
|
|
|
billNum: itm.BillNum, |
|
|
|
lU: itm.LU, |
|
|
|
rELU: string.Empty, |
|
|
|
pN: itm.PN, |
|
|
|
rEPN: string.Empty, |
|
|
|
site: itm.Site, |
|
|
|
qty: itm.Qty, |
|
|
|
price: itm.Price, |
|
|
|
invGroupNum: itm.InvGroupNum, |
|
|
|
settleDate: itm.SettleDate, |
|
|
|
groupNum: itm.GroupNum, |
|
|
|
extend1: string.Empty, |
|
|
|
extend2: string.Empty, |
|
|
|
extend3: string.Empty, |
|
|
|
extend4: string.Empty, |
|
|
|
businessType: itm.BusinessType |
|
|
|
)); |
|
|
|
} |
|
|
|
await _repository.DbContext.BulkInsertAsync(new List<PUB_PD>() { pub }); |
|
|
|
await _repository.DbContext.BulkInsertAsync(pubDetail); |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task<bool> Reject(INVOICE_GRP p_entity) |
|
|
@ -95,11 +290,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<bool> Reject(string billNum) |
|
|
|
/// <summary>
|
|
|
|
/// 退回
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="billNum">发票分组号</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<bool> Reject(string groupbillNum) |
|
|
|
{ |
|
|
|
|
|
|
|
var _ls=await _repository.Where(p => p.InvGroupNum == billNum).ToListAsync(); |
|
|
|
var _ls=await _repository.Where(p => p.InvGroupNum == groupbillNum).ToListAsync(); |
|
|
|
|
|
|
|
if (_ls != null && _ls.Count > 0) |
|
|
|
{ |
|
|
@ -145,6 +344,74 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 返回到财务审核状态
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="billNum"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<bool> Back(string billNum) |
|
|
|
{ |
|
|
|
|
|
|
|
var _ls = await _repository.Where(p => p.InvGroupNum == billNum).ToListAsync(); |
|
|
|
if (_ls != null && _ls.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var p_entity in _ls) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (_ls != null && _ls.Count > 0)
|
|
|
|
//{
|
|
|
|
// foreach (var p_entity in _ls)
|
|
|
|
// {
|
|
|
|
// if (p_entity.State == InvoiceBillState.财务已审核
|
|
|
|
// || p_entity.State == InvoiceBillState.已开票 || p_entity.State == InvoiceBillState.商务已审核)
|
|
|
|
// {
|
|
|
|
// var entList = _repository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
// var groupList = _groupRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
// var notList = _notRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
// var detailList = _detailRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
// //var canList = _canRepository.Where(p => p.InvGroupNum == p_entity.InvGroupNum).ToList();
|
|
|
|
// //foreach (var itm in canList)
|
|
|
|
// //{
|
|
|
|
// // itm.State = SettleBillState.未结状态;
|
|
|
|
// //}
|
|
|
|
// await _repository.DbContext.BulkDeleteAsync(entList);
|
|
|
|
// await _repository.DbContext.BulkDeleteAsync(groupList);
|
|
|
|
// await _repository.DbContext.BulkDeleteAsync(notList);
|
|
|
|
// await _repository.DbContext.BulkDeleteAsync(detailList);
|
|
|
|
// //await _repository.DbContext.BulkUpdateAsync(canList);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
// if (p_entity.State == InvoiceBillState.已扣减)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
//else
|
|
|
|
//{
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|