学 赵
1 year ago
28 changed files with 1446 additions and 875 deletions
@ -1,269 +0,0 @@ |
|||
using EFCore.BulkExtensions; |
|||
using Hangfire.Annotations; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using SettleAccount.Bases; |
|||
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 CAN_SA_MNG<TEntity, TEntityDetail> : DomainService,ITransientDependency |
|||
where TEntity : SA_CAN_BASE_MAIN,new() |
|||
where TEntityDetail : SA_CAN_BASE,new() |
|||
{ |
|||
private readonly INormalEfCoreRepository<TEntity, Guid> _repository; |
|||
private readonly INormalEfCoreRepository<TEntityDetail, Guid> _detailRepository; |
|||
public CAN_SA_MNG |
|||
( |
|||
INormalEfCoreRepository<TEntity, Guid> repository, |
|||
INormalEfCoreRepository<TEntityDetail, Guid> detailRepository |
|||
) |
|||
{ |
|||
_repository = repository; |
|||
_detailRepository = detailRepository; |
|||
} |
|||
|
|||
public CAN_SA_MNG() |
|||
{ |
|||
} |
|||
|
|||
public virtual async Task<bool> SetForwardState(TEntity p_entiy, SettleBillState state) |
|||
{ |
|||
if (await SetForwardState(p_entiy.InvGroupNum, state) == true) |
|||
{ |
|||
return true; |
|||
} |
|||
return false; |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
/// <summary>
|
|||
/// 向前流程
|
|||
/// </summary>
|
|||
/// <param name="p_billNum"></param>
|
|||
/// <param name="state"></param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="BusinessException"></exception>
|
|||
public virtual async Task<bool> 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; |
|||
} |
|||
/// <summary>
|
|||
/// 向后流程
|
|||
/// </summary>
|
|||
/// <param name="p_billNum"></param>
|
|||
/// <param name="state"></param>
|
|||
/// <returns></returns>
|
|||
/// <exception cref="BusinessException"></exception>
|
|||
public virtual async Task<bool> 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<bool> SetNewState(TEntity p_entiy) |
|||
{ |
|||
|
|||
return await SetNewState(p_entiy.BillNum); |
|||
} |
|||
|
|||
public virtual async Task<bool> SetNewState(string billNum) |
|||
{ |
|||
|
|||
var entity= await GetMainAsync(billNum); |
|||
if (entity != null ) |
|||
{ |
|||
|
|||
entity.State = SettleBillState.未结状态; |
|||
|
|||
|
|||
await _repository.UpdateAsync(entity); |
|||
return true; |
|||
} |
|||
return false; |
|||
; |
|||
} |
|||
/// <summary>
|
|||
/// 获得所有明细
|
|||
/// </summary>
|
|||
/// <param name="billNum"></param>
|
|||
/// <returns></returns>
|
|||
public virtual async Task<List<TEntityDetail>> GetDetalListAsync(string billNum) |
|||
{ |
|||
return await _detailRepository.Where(p=>p.InvGroupNum==billNum).ToListAsync(); |
|||
} |
|||
/// <summary>
|
|||
/// 获得主表信息
|
|||
/// </summary>
|
|||
/// <param name="billNum"></param>
|
|||
/// <returns></returns>
|
|||
public virtual async Task<TEntity> GetMainAsync(string billNum) |
|||
{ |
|||
return await _repository.Where(p => p.InvGroupNum == billNum).FirstOrDefaultAsync(); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -1,89 +0,0 @@ |
|||
using SettleAccount.Bases; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Abp; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
using Win.Sfs.SettleAccount.Bases; |
|||
using EFCore.BulkExtensions; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Entities.BQ.Managers |
|||
{ |
|||
/// <summary>
|
|||
/// 不能結算管理
|
|||
/// </summary>
|
|||
/// <typeparam name="TEntity"></typeparam>
|
|||
/// <typeparam name="TEntityDetail"></typeparam>
|
|||
/// <typeparam name="TNOTDetail"></typeparam>
|
|||
public class NOT_SA_MNG<TEntity, TEntityDetail, TNOTDetail> : DomainService |
|||
where TEntity : SA_CAN_BASE_MAIN, new() |
|||
where TEntityDetail : SA_CAN_BASE, new() |
|||
where TNOTDetail : SA_NOT_BASE |
|||
{ |
|||
private readonly INormalEfCoreRepository<TEntity, Guid> _repository; |
|||
private readonly INormalEfCoreRepository<TEntityDetail, Guid> _detailRepository; |
|||
private readonly INormalEfCoreRepository<TNOTDetail, Guid> _notRepository; |
|||
|
|||
public NOT_SA_MNG() |
|||
{ |
|||
} |
|||
|
|||
public NOT_SA_MNG |
|||
( |
|||
INormalEfCoreRepository<TEntity, Guid> repository, |
|||
INormalEfCoreRepository<TEntityDetail, Guid> detailRepository, |
|||
INormalEfCoreRepository<TNOTDetail, Guid> notRepository |
|||
) |
|||
{ |
|||
_repository = repository; |
|||
_detailRepository = detailRepository; |
|||
_notRepository = notRepository; |
|||
} |
|||
|
|||
|
|||
|
|||
public virtual async Task<bool> GenerateSettlementOrder(List<TNOTDetail> p_list, Action<List<TEntityDetail>> p_action = null) |
|||
{ |
|||
|
|||
var billNumber = OrderNumberGenerator.GenerateOrderNumber("N"); |
|||
var _entity = new TEntity(); |
|||
_entity.BillNum = billNumber; |
|||
_entity.InvGroupNum = billNumber; |
|||
_entity.Version = DateTime.Now.Year + DateTime.Now.Month; |
|||
_entity.State = SettleBillState.未结状态; |
|||
_entity.SettleBillNum = string.Empty; |
|||
var _entityList = new List<TEntityDetail>(); |
|||
foreach (var itm in p_list) |
|||
{ |
|||
var _detailEntity = new TEntityDetail(); |
|||
{ |
|||
_detailEntity.SettleBillNum = itm.SettleBillNum; |
|||
_detailEntity.BillNum = billNumber; |
|||
_detailEntity.InvGroupNum = billNumber; |
|||
_detailEntity.LU = itm.LU; |
|||
_detailEntity.PN = itm.PN; |
|||
_detailEntity.GroupNum = itm.GroupNum; |
|||
_detailEntity.KeyCode = itm.KeyCode; |
|||
_detailEntity.Price = itm.Price; |
|||
_detailEntity.Version = itm.Version; |
|||
}; |
|||
_entityList.Add(_detailEntity); |
|||
} |
|||
if (_entityList.Count > 0) |
|||
{ |
|||
p_action(_entityList);//对不一样类型结算数据进行处理
|
|||
} |
|||
await _notRepository.DbContext.BulkDeleteAsync(p_list); |
|||
await _repository.DbContext.BulkInsertAsync(new List<TEntity>() { _entity }); |
|||
await _repository.DbContext.BulkInsertAsync(_entityList); |
|||
|
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
@ -0,0 +1,370 @@ |
|||
using Dapper; |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
|||
using SettleAccount.Bases; |
|||
using SettleAccount.Domain.BQ; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data.Common; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Domain.Repositories.Dapper; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win.Sfs.SettleAccount.Entities; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Temp; |
|||
using Win.Sfs.SettleAccount.Entities.Prices; |
|||
using Win.Sfs.SettleAccount.Reports; |
|||
using Win.Sfs.SettleAccount.Reports.InvoiceSettledDiffs; |
|||
|
|||
namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report |
|||
{ |
|||
|
|||
/// <summary>
|
|||
/// 2.大众发票与结算核对明细表-准时化
|
|||
/// </summary>
|
|||
public class PendingDeductionDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency |
|||
{ |
|||
public PendingDeductionDapperRepository(IDbContextProvider<SettleAccountDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
/// <summary>
|
|||
/// BBAC生成待扣减
|
|||
/// </summary>
|
|||
/// <param name="p_invGroup"></param>
|
|||
/// <returns></returns>
|
|||
public Dictionary<BBAC_PD, List<BBAC_PD_DETAIL>> GenerationPendingDeductionBBAC(string p_invGroup) |
|||
{ |
|||
var sqljis = "WITH t1 AS(\n" + |
|||
"SELECT\n" + |
|||
"DISTINCT sa.KeyCode,\n" + |
|||
"sa.LU,\n" + |
|||
"sa.PN,\n" + |
|||
"sa.BusinessType\n" + |
|||
"FROM\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_BBAC_CAN_SA_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}'\n" + |
|||
"UNION ALL\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_PUB_ADJ_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}') sa\n" + |
|||
"LEFT JOIN\n" + |
|||
"Set_BBAC_SE_DETAIL se ON\n" + |
|||
"sa.KeyCode = se.KeyCode\n" + |
|||
"WHERE\n" + |
|||
"se.PN IS NULL\n" + |
|||
")\n" + |
|||
"select tmp1.* from\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"t1.LU,\n" + |
|||
"t1.PN,\n" + |
|||
"t2.RepLU,\n" + |
|||
"t1.BusinessType,\n" + |
|||
"(t1.PN + t2.RepLU) KeyCode\n" + |
|||
"FROM\n" + |
|||
"t1\n" + |
|||
"INNER JOIN Set_TB_RePartsRelationship t2\n" + |
|||
"ON\n" + |
|||
"t1.LU = t2.LU\n" + |
|||
"AND t1.BusinessType = t2.BusinessType) tmp1\n" + |
|||
"INNER JOIN Set_BBAC_SE_DETAIL tmp2 ON\n" + |
|||
"tmp1.KeyCode = tmp2.KeyCode\n"; |
|||
|
|||
var inv = DbConnection.Query<INVOICE_GRP>($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); |
|||
Dictionary<BBAC_PD, List<BBAC_PD_DETAIL>> result = new Dictionary<BBAC_PD, List<BBAC_PD_DETAIL>>(); |
|||
|
|||
var detail = DbConnection.Query<BBAC_CAN_SA_DETAIL>($"select * from set_BBAC_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); |
|||
var main = DbConnection.Query<BBAC_CAN_SA>($"select * from set_BBAC_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); |
|||
|
|||
var entity = main; |
|||
if (entity == null) |
|||
{ |
|||
var templist = DbConnection.Query<TEMP_PD_SW>(string.Format(sqljis, p_invGroup)); |
|||
|
|||
var entityDetail = detail; |
|||
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 query = from itm in detail |
|||
join itm1 in templist on itm.KeyCode equals itm1.KeyCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new BBAC_PD_DETAIL( |
|||
guid: itm.Id, |
|||
keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, |
|||
version: itm.Version, |
|||
billNum: itm.BillNum, |
|||
lU: itm.LU, |
|||
rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, |
|||
pN: itm.PN, |
|||
rEPN: itm.PN, |
|||
site: itm.Site, |
|||
qty: itm.Qty, |
|||
price: 0, |
|||
invGroupNum: itm.InvGroupNum, |
|||
settleDate: itm.SettleDate, |
|||
groupNum: itm.GroupNum, |
|||
extend1: string.Empty, |
|||
extend2: string.Empty, |
|||
extend3: string.Empty, |
|||
extend4: string.Empty |
|||
); |
|||
var bbacDetail = query.ToList(); |
|||
|
|||
result.Add(bbac, bbacDetail); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// BBAC生成待扣减
|
|||
/// </summary>
|
|||
/// <param name="p_invGroup"></param>
|
|||
/// <returns></returns>
|
|||
public Dictionary<HBPO_PD, List<HBPO_PD_DETAIL>> GenerationPendingDeductionHBPO(string p_invGroup) |
|||
{ |
|||
|
|||
var sqljis = "WITH t1 AS(\n" + |
|||
"SELECT\n" + |
|||
"DISTINCT sa.KeyCode,\n" + |
|||
"sa.LU,\n" + |
|||
"sa.PN,\n" + |
|||
"sa.BusinessType\n" + |
|||
"FROM\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_HBPO_CAN_SA_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}'\n" + |
|||
"UNION ALL\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_PUB_ADJ_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}') sa\n" + |
|||
"LEFT JOIN\n" + |
|||
"Set_HBPO_SE_DETAIL se ON\n" + |
|||
"sa.KeyCode = se.KeyCode\n" + |
|||
"WHERE\n" + |
|||
"se.PN IS NULL\n" + |
|||
")\n" + |
|||
"select tmp1.* from\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"t1.LU,\n" + |
|||
"t1.PN,\n" + |
|||
"t2.RepLU,\n" + |
|||
"t1.BusinessType,\n" + |
|||
"(t1.PN + t2.RepLU) KeyCode\n" + |
|||
"FROM\n" + |
|||
"t1\n" + |
|||
"INNER JOIN Set_TB_RePartsRelationship t2\n" + |
|||
"ON\n" + |
|||
"t1.LU = t2.LU\n" + |
|||
"AND t1.BusinessType = t2.BusinessType) tmp1\n" + |
|||
"INNER JOIN Set_HBPO_SE_DETAIL tmp2 ON\n" + |
|||
"tmp1.KeyCode = tmp2.KeyCode\n"; |
|||
|
|||
var inv = DbConnection.Query<INVOICE_GRP>($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); |
|||
Dictionary<HBPO_PD, List<HBPO_PD_DETAIL>> result = new Dictionary<HBPO_PD, List<HBPO_PD_DETAIL>>(); |
|||
var detail = DbConnection.Query<HBPO_CAN_SA_DETAIL>($"select * from set_HBPO_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); |
|||
var main = DbConnection.Query<HBPO_CAN_SA>($"select * from set_HBPO_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); |
|||
|
|||
var entity = main; |
|||
if (entity == null) |
|||
{ |
|||
var templist = DbConnection.Query<TEMP_PD_SW>(string.Format(sqljis, p_invGroup)); |
|||
|
|||
var entityDetail = detail; |
|||
var bbac = new HBPO_PD( |
|||
guid: entity.Id, |
|||
version: entity.Version, |
|||
billNum: entity.BillNum, |
|||
settleBillNum: entity.SettleBillNum, |
|||
state: SettleBillState.客户已收票, |
|||
invGroupNum: entity.InvGroupNum, |
|||
site: entity.Site |
|||
); |
|||
|
|||
var query = from itm in detail |
|||
join itm1 in templist on itm.KeyCode equals itm1.KeyCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new HBPO_PD_DETAIL( |
|||
guid: itm.Id, |
|||
keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, |
|||
version: itm.Version, |
|||
billNum: itm.BillNum, |
|||
lU: itm.LU, |
|||
rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, |
|||
pN: itm.PN, |
|||
rEPN: itm.PN, |
|||
site: itm.Site, |
|||
qty: itm.Qty, |
|||
price: 0, |
|||
invGroupNum: itm.InvGroupNum, |
|||
settleDate: itm.SettleDate, |
|||
groupNum: itm.GroupNum, |
|||
extend1: string.Empty, |
|||
extend2: string.Empty, |
|||
extend3: string.Empty, |
|||
extend4: string.Empty |
|||
); |
|||
var bbacDetail = query.ToList(); |
|||
|
|||
result.Add(bbac, bbacDetail); |
|||
} |
|||
return result; |
|||
|
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 其他业务生成待扣减
|
|||
/// </summary>
|
|||
/// <param name="p_invGroup"></param>
|
|||
/// <returns></returns>
|
|||
public Dictionary<PUB_PD, List<PUB_PD_DETAIL>> GenerationPendingDeductionPUB(string p_invGroup) |
|||
{ |
|||
|
|||
var sqljis = "WITH t1 AS(\n" + |
|||
"SELECT\n" + |
|||
"DISTINCT sa.KeyCode,\n" + |
|||
"sa.LU,\n" + |
|||
"sa.PN,\n" + |
|||
"sa.BusinessType\n" + |
|||
"FROM\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_PUB_CAN_SA_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}'\n" + |
|||
"UNION ALL\n" + |
|||
"SELECT\n" + |
|||
"keycode,\n" + |
|||
"LU,\n" + |
|||
"PN,\n" + |
|||
"BusinessType\n" + |
|||
"FROM\n" + |
|||
"Set_PUB_ADJ_DETAIL\n" + |
|||
"WHERE\n" + |
|||
"InvGroupNum = '{0}') sa\n" + |
|||
"LEFT JOIN\n" + |
|||
"Set_PUB_SE_DETAIL se ON\n" + |
|||
"sa.KeyCode = se.KeyCode\n" + |
|||
"WHERE\n" + |
|||
"se.PN IS NULL\n" + |
|||
")\n" + |
|||
"select tmp1.* from\n" + |
|||
"(\n" + |
|||
"SELECT\n" + |
|||
"distinct " + |
|||
"t1.LU,\n" + |
|||
"t1.PN,\n" + |
|||
"t2.RepLU,\n" + |
|||
"t1.BusinessType,\n" + |
|||
"(t1.PN + t2.RepLU) KeyCode\n" + |
|||
"FROM\n" + |
|||
"t1\n" + |
|||
"INNER JOIN Set_TB_RePartsRelationship t2\n" + |
|||
"ON\n" + |
|||
"t1.LU = t2.LU\n" + |
|||
"AND t1.BusinessType = t2.BusinessType) tmp1\n" + |
|||
"INNER JOIN Set_PUB_SE_DETAIL tmp2 ON\n" + |
|||
"tmp1.KeyCode = tmp2.KeyCode\n"; |
|||
|
|||
var inv = DbConnection.Query<INVOICE_GRP>($"select * from set_INVOICE_GRP where InvGroupNum='{p_invGroup}'").FirstOrDefault(); |
|||
Dictionary<PUB_PD, List<PUB_PD_DETAIL>> result = new Dictionary<PUB_PD, List<PUB_PD_DETAIL>>(); |
|||
var detail = DbConnection.Query<PUB_CAN_SA_DETAIL>($"select * from set_PUB_CAN_SA_DETAIL where billNum='{p_invGroup}'").ToList(); |
|||
var main = DbConnection.Query<PUB_CAN_SA>($"select * from set_PUB_CAN_SA where billNum='{p_invGroup}'").FirstOrDefault(); |
|||
|
|||
var entity = main; |
|||
if (entity == null) |
|||
{ |
|||
var templist = DbConnection.Query<TEMP_PD_SW>(string.Format(sqljis, p_invGroup)); |
|||
var entityDetail = detail; |
|||
var bbac = new PUB_PD( |
|||
guid: entity.Id, |
|||
version: entity.Version, |
|||
billNum: entity.BillNum, |
|||
settleBillNum: entity.SettleBillNum, |
|||
state: SettleBillState.客户已收票, |
|||
invGroupNum: entity.InvGroupNum, |
|||
site: entity.Site |
|||
); |
|||
var query = from itm in detail |
|||
join itm1 in templist on itm.KeyCode equals itm1.KeyCode |
|||
into temp1 |
|||
from tm1 in temp1.DefaultIfEmpty() |
|||
select new PUB_PD_DETAIL( |
|||
guid: itm.Id, |
|||
keyCode: string.IsNullOrEmpty(tm1.KeyCode) ? tm1.KeyCode : itm.KeyCode, |
|||
version: itm.Version, |
|||
billNum: itm.BillNum, |
|||
lU: itm.LU, |
|||
rELU: string.IsNullOrEmpty(tm1.RepLU) ? tm1.RepLU : itm.LU, |
|||
pN: itm.PN, |
|||
rEPN: itm.PN, |
|||
site: itm.Site, |
|||
qty: itm.Qty, |
|||
price: 0, |
|||
invGroupNum: itm.InvGroupNum, |
|||
settleDate: itm.SettleDate, |
|||
groupNum: itm.GroupNum, |
|||
extend1: string.Empty, |
|||
extend2: string.Empty, |
|||
extend3: string.Empty, |
|||
extend4: string.Empty, |
|||
businessType:itm.BusinessType |
|||
); |
|||
var bbacDetail = query.ToList(); |
|||
result.Add(bbac, bbacDetail); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
|
@ -0,0 +1,117 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data.Common; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Text.RegularExpressions; |
|||
using System.Threading.Tasks; |
|||
using EFCore.BulkExtensions; |
|||
using Magicodes.ExporterAndImporter.Core; |
|||
using Magicodes.ExporterAndImporter.Excel; |
|||
using NPOI.OpenXmlFormats.Spreadsheet; |
|||
using SettleAccount.Domain.BQ; |
|||
using TaskJob.EventArgs; |
|||
using TaskJob.Interfaces; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Win.Sfs.SettleAccount; |
|||
using Win.Sfs.SettleAccount.Entities.BQ.Managers; |
|||
using Win.Sfs.SettleAccount.Entities.SettleAccounts; |
|||
using Win.Sfs.SettleAccount.ExportReports; |
|||
using Win.Sfs.SettleAccount.Repository.SettleAccount; |
|||
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
|||
using Win.Sfs.Shared.RepositoryBase; |
|||
|
|||
namespace SettleAccount.Job.Services |
|||
{ |
|||
public class PD_SERVICE : ITransientDependency, IExportJob |
|||
{ |
|||
private readonly PendingDeductionDapperRepository _dapper; |
|||
private readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _invRepository; |
|||
|
|||
public PD_SERVICE(PendingDeductionDapperRepository dapper, |
|||
|
|||
INormalEfCoreRepository<INVOICE_GRP, Guid> invRepository |
|||
|
|||
) |
|||
{ |
|||
_dapper = dapper; |
|||
_invRepository = invRepository; |
|||
} |
|||
/// <summary>
|
|||
/// 执行发票待开任务
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="exportName"></param>
|
|||
/// <param name="customConditions"></param>
|
|||
/// <returns></returns>
|
|||
public string ExportFile(Guid id, List<string> exportName, List<CustomCondition> customConditions) |
|||
{ |
|||
var invgroup = customConditions.Where(p => p.Name == "InvoiceGroupNum").FirstOrDefault().Value; |
|||
var ls = _invRepository.Where(p => p.InvGroupNum == invgroup).ToList(); |
|||
if (ls != null && ls.Count>0) |
|||
{ |
|||
var first=ls.FirstOrDefault(); |
|||
if (first.BusinessType == EnumBusinessType.JisHBPO) |
|||
{ |
|||
var pd = _dapper.GenerationPendingDeductionHBPO(invgroup); |
|||
if (pd.Count > 0) |
|||
{ |
|||
foreach (var c in pd) |
|||
{ |
|||
var main = c.Key; |
|||
var detail = c.Value; |
|||
_invRepository.DbContext.BulkInsert(new List<HBPO_PD>() { main }); |
|||
_invRepository.DbContext.BulkInsert(detail); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
} |
|||
else if (first.BusinessType == EnumBusinessType.JisBBAC) |
|||
{ |
|||
var pd = _dapper.GenerationPendingDeductionBBAC(invgroup); |
|||
if (pd.Count > 0) |
|||
{ |
|||
foreach (var c in pd) |
|||
{ |
|||
var main = c.Key; |
|||
var detail = c.Value; |
|||
_invRepository.DbContext.BulkInsert(new List<BBAC_PD>() { main }); |
|||
_invRepository.DbContext.BulkInsert(detail); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
} |
|||
else |
|||
{ |
|||
var pd = _dapper.GenerationPendingDeductionPUB(invgroup); |
|||
if (pd.Count > 0) |
|||
{ |
|||
foreach (var c in pd) |
|||
{ |
|||
var main = c.Key; |
|||
var detail = c.Value; |
|||
_invRepository.DbContext.BulkInsert(new List<PUB_PD>() { main }); |
|||
_invRepository.DbContext.BulkInsert(detail); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
return id.ToString(); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
Loading…
Reference in new issue