|
|
|
using CodeArts.Db.Lts;
|
|
|
|
using DocumentFormat.OpenXml.Bibliography;
|
|
|
|
using EFCore.BulkExtensions;
|
|
|
|
using Magicodes.ExporterAndImporter.Core;
|
|
|
|
using Magicodes.ExporterAndImporter.Csv;
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
using SettleAccount.Bases;
|
|
|
|
using SettleAccount.Domain.BQ;
|
|
|
|
using Shouldly;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
|
|
|
using System.LinqAsync;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Volo.Abp;
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
using Volo.Abp.Domain.Entities;
|
|
|
|
using Win.Abp.Snowflakes;
|
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon;
|
|
|
|
using Win.Sfs.SettleAccount.CommonManagers;
|
|
|
|
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.Temp;
|
|
|
|
using Win.Sfs.SettleAccount.Entities.Prices;
|
|
|
|
using Win.Sfs.SettleAccount.ExcelImporter;
|
|
|
|
using Win.Sfs.SettleAccount.ExportReports;
|
|
|
|
using Win.Sfs.SettleAccount.Migrations;
|
|
|
|
using Win.Sfs.Shared.Filter;
|
|
|
|
using Win.Sfs.Shared.RepositoryBase;
|
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Bases
|
|
|
|
{
|
|
|
|
public abstract class BA_SERVICE
|
|
|
|
|
|
|
|
: BASE_SERVICE
|
|
|
|
{
|
|
|
|
protected readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _repository;
|
|
|
|
protected readonly INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> _wRepository;
|
|
|
|
protected readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _sRepository;
|
|
|
|
protected readonly INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> _mRepository;
|
|
|
|
protected readonly INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> _adjRepository;
|
|
|
|
protected readonly HBPO_CAN_SA_MNG _hbpoMng;
|
|
|
|
protected readonly BBAC_CAN_SA_MNG _bbacMng;
|
|
|
|
protected readonly PUB_CAN_SA_MNG _pubMng;
|
|
|
|
protected readonly INV_MNG _invMng;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected BA_SERVICE(
|
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository,
|
|
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> wRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository,
|
|
|
|
IExcelImportAppService excelImportService,
|
|
|
|
HBPO_CAN_SA_MNG hbpoMng,
|
|
|
|
BBAC_CAN_SA_MNG bbacMng,
|
|
|
|
PUB_CAN_SA_MNG pubMng,
|
|
|
|
INV_MNG invMng
|
|
|
|
|
|
|
|
//INormalEfCoreRepository<TEntityDetail, Guid> detailRepository
|
|
|
|
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
_repository = repository;
|
|
|
|
_wRepository = wRepository;
|
|
|
|
_mRepository = mRepository;
|
|
|
|
_sRepository = sRepository;
|
|
|
|
_adjRepository = adjRepository;
|
|
|
|
_pubMng = pubMng;
|
|
|
|
_bbacMng = bbacMng;
|
|
|
|
_hbpoMng = hbpoMng;
|
|
|
|
_invMng = invMng;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected BA_SERVICE(IExcelImportAppService excelImportService,
|
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
|
|
ICommonManager commonManager,
|
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> pubRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository,
|
|
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> wRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository,
|
|
|
|
|
|
|
|
BBAC_CAN_SA_MNG pubMng,
|
|
|
|
HBPO_CAN_SA_MNG bbacMng,
|
|
|
|
PUB_CAN_SA_MNG hbpoMng,
|
|
|
|
INV_MNG invMng
|
|
|
|
|
|
|
|
|
|
|
|
) :
|
|
|
|
base(excelImportService, snowflakeIdGenerator, commonManager)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 审核通过
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<string> GenerateInvoice(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
|
|
|
|
await _invMng.SetForwardState(input.InvGroupNum, SettleBillState.商务已审核);
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 发票重开
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<string> ReissueInvoice(string input)
|
|
|
|
{
|
|
|
|
|
|
|
|
// await _invMng.SetForwardState(input.InvGroupNum, SettleBillState.商务已审核);
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr;
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 主表查询
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input">主表查询条件</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
//[Route("mainquery")]
|
|
|
|
public virtual async Task<PagedResultDto<INVOICE_GRP_DTO>> MainQueryAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var entitys = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount);
|
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters);
|
|
|
|
var dtos = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_DTO>>(entitys);
|
|
|
|
return new PagedResultDto<INVOICE_GRP_DTO>(totalCount, dtos);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 查询明细明细
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input">明细查询条件</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<INVOICE_GRP_DETAIL_DTO> DetailQueryAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
|
|
|
|
INVOICE_GRP_DETAIL_DTO entity = new INVOICE_GRP_DETAIL_DTO();
|
|
|
|
var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var mdtos = ObjectMapper.Map<List<INVOICE_MAP_GROUP>, List<INVOICE_MAP_GROUP_DTO>>(m);
|
|
|
|
var w = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var wdtos = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(w);
|
|
|
|
var s = await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var sdtos = ObjectMapper.Map<List<INVOICE_NOT_SETTLE>, List<INVOICE_NOT_SETTLE_DTO>>(s);
|
|
|
|
entity.INVOICE_NOT_SETTLE = sdtos;
|
|
|
|
entity.INVOICE_WAIT_DETAIL = wdtos;
|
|
|
|
entity.INVOICE_MAP_GROUP = mdtos;
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 导出文件
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input">主表查询条件</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<string> ExportAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
IExporter _csv = new CsvExporter();
|
|
|
|
IExporter _excel = new ExcelExporter();
|
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true);
|
|
|
|
var dtoDetails = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_EXP_DTO>>(entities);
|
|
|
|
var classDisplayName = typeof(INVOICE_GRP_DTO).GetCustomAttribute<DisplayAttribute>()?.Name ?? typeof(INVOICE_GRP_DTO).Name;
|
|
|
|
string _fileName = $"{classDisplayName}_{Guid.NewGuid().ToString()}.xlsx";
|
|
|
|
byte[] result = null;
|
|
|
|
|
|
|
|
switch (input.FileType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
result = await _csv.ExportAsByteArray(dtoDetails);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
result = await _excel.ExportAsByteArray(dtoDetails);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result.ShouldNotBeNull();
|
|
|
|
|
|
|
|
//保存导出文件到服务器存成二进制
|
|
|
|
await _excelImportService.SaveBlobAsync(
|
|
|
|
new SaveExcelImportInputDto
|
|
|
|
{
|
|
|
|
Name = _fileName,
|
|
|
|
Content = result
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return _fileName;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 退回
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input">主表查询条件</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<string> RejectAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
|
|
|
|
await _invMng.Reject(input.InvGroupNum);
|
|
|
|
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<string> ReceivedAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var entity = await _invMng.GetMainAsync(input.InvGroupNum);
|
|
|
|
if (entity != null)
|
|
|
|
{
|
|
|
|
bool flag = await _invMng.ReceivedAsync(entity.InvGroupNum);
|
|
|
|
if (flag == true)
|
|
|
|
{
|
|
|
|
await _invMng.SetForwardState(entity, SettleBillState.客户已收票);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ApplicationConsts.SuccessStr;
|
|
|
|
}
|
|
|
|
protected virtual async Task<List<INVOICE_MAP_GROUP_DTO>> GetMapGroupAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var mdtos = ObjectMapper.Map<List<INVOICE_MAP_GROUP>, List<INVOICE_MAP_GROUP_DTO>>(m);
|
|
|
|
return mdtos;
|
|
|
|
}
|
|
|
|
protected virtual async Task<List<INVOICE_WAIT_DETAIL_DTO>> GetDetailAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var w = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var wdtos = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(w);
|
|
|
|
return wdtos;
|
|
|
|
}
|
|
|
|
protected virtual async Task<List<INVOICE_NOT_SETTLE_DTO>> GetNotDetailAsync(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var s = await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var sdtos = ObjectMapper.Map<List<INVOICE_NOT_SETTLE>, List<INVOICE_NOT_SETTLE_DTO>>(s);
|
|
|
|
return sdtos;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual async Task<List<INVOICE_NOT_SETTLE>> GetNotDetailAsync(string p_invbillNum)
|
|
|
|
{
|
|
|
|
List<FilterCondition> filters = new List<FilterCondition>();
|
|
|
|
|
|
|
|
filters.Add(new FilterCondition("InvBillNum", p_invbillNum, EnumFilterAction.Equal, EnumFilterLogic.And));
|
|
|
|
return await _sRepository.GetListByFilterAsync(filters);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual async Task<List<PUB_ADJ_DETAIL_DTO>> GetAjdmentDetail(INVOICE_GRP_REQ_DTO input)
|
|
|
|
{
|
|
|
|
var s = await _adjRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount);
|
|
|
|
var sdtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(s);
|
|
|
|
return sdtos;
|
|
|
|
}
|
|
|
|
protected virtual async Task<List<PUB_ADJ_DETAIL_DTO>> GetAjdmentDetail(string p_invbillNum)
|
|
|
|
{
|
|
|
|
List<FilterCondition> filters = new List<FilterCondition>();
|
|
|
|
filters.Add(new FilterCondition("InvBillNum", p_invbillNum, EnumFilterAction.Equal, EnumFilterLogic.And));
|
|
|
|
|
|
|
|
var s = await _adjRepository.GetListByFilterAsync(filters);
|
|
|
|
var sdtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(s);
|
|
|
|
return sdtos;
|
|
|
|
}
|
|
|
|
protected virtual async Task<List<INVOICE_MAP_GROUP_DTO>> GetMapGroupAsync(string p_invbillNum)
|
|
|
|
{
|
|
|
|
List<FilterCondition> filters = new List<FilterCondition>();
|
|
|
|
|
|
|
|
filters.Add(new FilterCondition("InvBillNum", p_invbillNum, EnumFilterAction.Equal, EnumFilterLogic.And));
|
|
|
|
var m = await _mRepository.GetListByFilterAsync(filters);
|
|
|
|
var mdtos = ObjectMapper.Map<List<INVOICE_MAP_GROUP>, List<INVOICE_MAP_GROUP_DTO>>(m);
|
|
|
|
return mdtos;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 通过发票号获取发票
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_invbillNum"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected virtual async Task<INVOICE_GRP> GetInvoiceGroupByInvBillNum(string p_invbillNum)
|
|
|
|
{
|
|
|
|
List<FilterCondition> filters = new List<FilterCondition>();
|
|
|
|
|
|
|
|
filters.Add(new FilterCondition("InvBillNum", p_invbillNum, EnumFilterAction.Equal, EnumFilterLogic.And));
|
|
|
|
var ls = await _repository.GetListByFilterAsync(filters);
|
|
|
|
if (ls != null && ls.Count() > 0)
|
|
|
|
{
|
|
|
|
return ls.FirstOrDefault();
|
|
|
|
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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<bool> ReissueSecInvoice(List<TEMP_CAN_SA_DETAIL> p_list, List<PUB_ADJ_DETAIL> p_adjlist, int p_version, string p_parentInvBillNum)
|
|
|
|
{
|
|
|
|
|
|
|
|
return await _invMng.ReissueSecInvoice(p_list,p_adjlist,p_parentInvBillNum, p_version);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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<bool> ReissueFirstInvoice(List<TEMP_CAN_SA_DETAIL> dtos, List<PUB_ADJ_DETAIL> p_adjlist, int p_version, string p_parentInvBillNum)
|
|
|
|
{
|
|
|
|
return await _invMng.ReissueFirstInvoice(dtos,p_adjlist,p_parentInvBillNum,p_version);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 校验规则
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dto1s"></param>
|
|
|
|
/// <param name="p_pricelist"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected async Task<List<ERR_EXP_DTO>> CheckInvoiceGenerationRules<T>(List<T> dto1s, List<PriceList> p_pricelist, EnumBusinessType p_businessType) where T : SA_CAN_BASE
|
|
|
|
{
|
|
|
|
var inner = from d in dto1s
|
|
|
|
join p in p_pricelist on d.LU equals p.LU
|
|
|
|
where
|
|
|
|
d.SettleDate >= p.BeginTime && d.SettleDate <= p.EndTime
|
|
|
|
select d;
|
|
|
|
var left = from d in dto1s
|
|
|
|
join p in inner on new { d.LU, d.PN } equals new { p.LU, p.PN }
|
|
|
|
into temp
|
|
|
|
from tm in temp.DefaultIfEmpty()//校验错误项
|
|
|
|
where tm == null
|
|
|
|
select d;
|
|
|
|
|
|
|
|
List<ERR_EXP_DTO> errorList = new List<ERR_EXP_DTO>();
|
|
|
|
|
|
|
|
string name = string.Empty;
|
|
|
|
string keyname = string.Empty;
|
|
|
|
switch (p_businessType)
|
|
|
|
{
|
|
|
|
case EnumBusinessType.MaiDanJianHBPO:
|
|
|
|
name = "HBPO买单件";
|
|
|
|
keyname = "生产码";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.ZhiGongJianHBPO:
|
|
|
|
name = "HBPO直供件";
|
|
|
|
keyname = "发货单号";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.ZhiGongJianBBAC:
|
|
|
|
name = "BBAC直供件";
|
|
|
|
keyname = "发货单号";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.YinDuJian:
|
|
|
|
name = "HBPO印度件";
|
|
|
|
keyname = "发货单号";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.JisBBAC:
|
|
|
|
name = "BBAC-JIS";
|
|
|
|
keyname = "生产码";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.JisHBPO:
|
|
|
|
name = "HBPO-JIS";
|
|
|
|
keyname = "生产码";
|
|
|
|
break;
|
|
|
|
case EnumBusinessType.BeiJian:
|
|
|
|
name = "备件";
|
|
|
|
keyname = "交付识别号";
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var error in left)
|
|
|
|
{
|
|
|
|
errorList.Add(new ERR_EXP_DTO() { ItemCode = error.LU, CustomCode = $"{name}", Message = $"LU:{error.LU}{keyname}:{error.PN},下线日期:{error.SettleDate}没有对应区间销售价格表!" });
|
|
|
|
}
|
|
|
|
return errorList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|