@ -5,6 +5,8 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using SettleAccount.Domain.BQ ;
using SettleAccount.Domain.BQ ;
using SettleAccount.Job.Services ;
using TaskJob.EventArgs ;
using Volo.Abp.Uow ;
using Volo.Abp.Uow ;
using Win.Abp.Snowflakes ;
using Win.Abp.Snowflakes ;
using Win.Sfs.BaseData.ImportExcelCommon ;
using Win.Sfs.BaseData.ImportExcelCommon ;
@ -14,8 +16,10 @@ 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.Dtos ;
using Win.Sfs.SettleAccount.Entities.BQ.Managers ;
using Win.Sfs.SettleAccount.Entities.BQ.Managers ;
using Win.Sfs.SettleAccount.Entities.BQ.Syncs ;
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 ;
using Win.Sfs.SettleAccount.Entities.TaskJobs ;
using Win.Sfs.Shared.RepositoryBase ;
using Win.Sfs.Shared.RepositoryBase ;
namespace Win.Sfs.SettleAccount.Entities.BQ
namespace Win.Sfs.SettleAccount.Entities.BQ
@ -40,6 +44,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
private readonly INormalEfCoreRepository < HBPO_NOT_SA_DETAIL , Guid > _ notRepository ;
private readonly INormalEfCoreRepository < HBPO_NOT_SA_DETAIL , Guid > _ notRepository ;
private readonly INormalEfCoreRepository < PriceList , Guid > _ priceRepository ;
private readonly INormalEfCoreRepository < PriceList , Guid > _ priceRepository ;
private readonly HBPO_CAN_SA_MNG _ hbpoMng ;
private readonly HBPO_CAN_SA_MNG _ hbpoMng ;
private readonly TaskJobService _ service ;
public HBPO_CAN_SA_SERVICE ( IExcelImportAppService excelImportService ,
public HBPO_CAN_SA_SERVICE ( IExcelImportAppService excelImportService ,
ISnowflakeIdGenerator snowflakeIdGenerator ,
ISnowflakeIdGenerator snowflakeIdGenerator ,
@ -50,13 +57,15 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
INormalEfCoreRepository < HBPO_NOT_SA_DETAIL , Guid > notRepository ,
INormalEfCoreRepository < HBPO_NOT_SA_DETAIL , Guid > notRepository ,
INormalEfCoreRepository < PriceList , Guid > priceRepository ,
INormalEfCoreRepository < PriceList , Guid > priceRepository ,
HBPO_CAN_SA_MNG hbpoMng ,
HBPO_CAN_SA_MNG hbpoMng ,
BaseDomainService baseservice
BaseDomainService baseservice ,
TaskJobService service
) : base ( excelImportService , snowflakeIdGenerator , commonManager , repository , detailRepository , invmng , baseservice )
) : base ( excelImportService , snowflakeIdGenerator , commonManager , repository , detailRepository , invmng , baseservice )
{
{
_ priceRepository = priceRepository ;
_ priceRepository = priceRepository ;
_ notRepository = notRepository ;
_ notRepository = notRepository ;
_ hbpoMng = hbpoMng ;
_ hbpoMng = hbpoMng ;
_ service = service ;
}
}
/// <summary>
/// <summary>
/// 生成发票
/// 生成发票
@ -83,68 +92,80 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{
{
return new JsonResult ( new { Code = ApplicationConsts . ImportFailCode , Message = "错误提示文件已下载,请打开文件查看" , fileName = await ExportErrorReportAsync ( errorList ) . ConfigureAwait ( false ) } ) ;
return new JsonResult ( new { Code = ApplicationConsts . ImportFailCode , Message = "错误提示文件已下载,请打开文件查看" , fileName = await ExportErrorReportAsync ( errorList ) . ConfigureAwait ( false ) } ) ;
}
}
if ( await _ hbpoMng . SetForwardState ( main , SettleBillState . 已 开 票 ) . ConfigureAwait ( false ) )
List < CustomCondition > customConditionList = new List < CustomCondition > ( ) ;
customConditionList . Add ( new CustomCondition ( ) { Name = "BillNum" , Value = invbillnum } ) ;
customConditionList . Add ( new CustomCondition ( ) { Name = "BussinessType" , Value = main . BusinessType . ToString ( ) } ) ;
await _ hbpoMng . SetWaitingState ( invbillnum ) ;
var _ taskid = await _ service . ExportEnqueueAsync ( "生成发票任务" , ExportExtentsion . Excel , string . Empty , string . Empty , CurrentUser , typeof ( GenerateJisInvoiceService ) , customConditionList , ( rs ) = >
{
{
var groupNumList = entitys . Select ( p = > p . GroupNum ) . Distinct ( ) . ToList ( ) ;
} ) . ConfigureAwait ( false ) ;
var notQuery = _ notRepository . Where ( p = > p . SettleBillNum = = main . SettleBillNum ) . ToList ( ) ;
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 . LU equals p . LU
where d . SettleDate > = p . BeginTime & & d . SettleDate < = p . EndTime & & p . IsCancel = = false & & p . ClientCode = = main . Site
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 = "no" ,
BeginDate = p . BeginTime ,
EndDate = p . EndTime ,
PartCode = d . PartCode
} ;
return new JsonResult ( new { Code = 2 0 0 , Message = "生成发票任务" } ) ;
var dtos = q . ToList ( ) ;
if ( dtos ! = null & & dtos . Count > 0 )
{
if ( invbillnum . Substring ( 0 , 1 ) = = "C" ) //一次开票
{
var notlist = notQuery . Select ( p = > new TEMP_NOT_SA_DETAIL
{
KeyCode = p . KeyCode ,
Version = p . Version ,
SettleBillNum = p . SettleBillNum ,
LU = p . LU ,
PN = p . PN ,
Site = p . Site ,
Qty = p . Qty ,
Price = p . Price ,
BusinessType = p . BusinessType ,
IsReturn = "" ,
InvGroupNum = p . InvGroupNum ,
SettleDate = p . SettleDate ,
GroupNum = p . GroupNum ,
ContractDocID = string . Empty ,
PartCode = p . PartCode
} ) . ToList ( ) ; //不能结算
var falg = await FirstInvoice ( entitys , new List < PUB_ADJ_DETAIL > ( ) , dtos , notlist , main . Version , main . InvGroupNum , string . Empty , main . BusinessType ) . ConfigureAwait ( false ) ;
}
else //二次开票
{
var flag = await SecInvoice ( entitys , new List < PUB_ADJ_DETAIL > ( ) , dtos , main . Version , main . InvGroupNum , string . Empty , main . BusinessType ) . ConfigureAwait ( false ) ;
}
}
//if (await _hbpoMng.SetForwardState(main, SettleBillState.已开票).ConfigureAwait(false))
}
//{
// var groupNumList = entitys.Select(p => p.GroupNum).Distinct().ToList();
// var notQuery = _notRepository.Where(p => p.SettleBillNum == main.SettleBillNum).ToList();
// 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.LU equals p.LU
// where d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime && p.IsCancel == false && p.ClientCode == main.Site
// 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 = "no",
// BeginDate = p.BeginTime,
// EndDate = p.EndTime,
// PartCode = d.PartCode
// };
// var dtos = q.ToList();
// if (dtos != null && dtos.Count > 0)
// {
// if (invbillnum.Substring(0, 1) == "C")//一次开票
// {
// var notlist = notQuery.Select(p => new TEMP_NOT_SA_DETAIL
// {
// KeyCode = p.KeyCode,
// Version = p.Version,
// SettleBillNum = p.SettleBillNum,
// LU = p.LU,
// PN = p.PN,
// Site = p.Site,
// Qty = p.Qty,
// Price = p.Price,
// BusinessType = p.BusinessType,
// IsReturn = "",
// InvGroupNum = p.InvGroupNum,
// SettleDate = p.SettleDate,
// GroupNum = p.GroupNum,
// ContractDocID = string.Empty,
// PartCode = p.PartCode
// }).ToList();//不能结算
// var falg = await FirstInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, notlist, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false);
// }
// else//二次开票
// {
// var flag = await SecInvoice(entitys, new List<PUB_ADJ_DETAIL>(), dtos, main.Version, main.InvGroupNum, string.Empty, main.BusinessType).ConfigureAwait(false);
// }
// }
//}
}
}
else
else
{
{