|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Magicodes.ExporterAndImporter.Core;
|
|
|
|
using Magicodes.ExporterAndImporter.Csv;
|
|
|
|
using Magicodes.ExporterAndImporter.Excel;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using SettleAccount.Bases;
|
|
|
|
using SettleAccount.Domain.BQ;
|
|
|
|
using Shouldly;
|
|
|
|
using Volo.Abp;
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
using Volo.Abp.Uow;
|
|
|
|
using Win.Abp.Snowflakes;
|
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon;
|
|
|
|
using Win.Sfs.SettleAccount.Bases.DomainServices;
|
|
|
|
using Win.Sfs.SettleAccount.CommonManagers;
|
|
|
|
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.Entities.TaskJobs;
|
|
|
|
using Win.Sfs.SettleAccount.ExportReports;
|
|
|
|
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;
|
|
|
|
private readonly TaskJobService _service;
|
|
|
|
private readonly BaseDomainService _baseservice;
|
|
|
|
|
|
|
|
protected BA_SERVICE(IExcelImportAppService excelImportService,
|
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator,
|
|
|
|
ICommonManager commonManager,
|
|
|
|
|
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository,
|
|
|
|
INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> wRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> sRepository,
|
|
|
|
INormalEfCoreRepository<INVOICE_MAP_GROUP, Guid> mRepository,
|
|
|
|
INormalEfCoreRepository<PUB_ADJ_DETAIL, Guid> adjRepository,
|
|
|
|
BBAC_CAN_SA_MNG bbacMng,
|
|
|
|
HBPO_CAN_SA_MNG hbpoMng,
|
|
|
|
PUB_CAN_SA_MNG pubMng,
|
|
|
|
INV_MNG invMng,
|
|
|
|
TaskJobService service,
|
|
|
|
BaseDomainService baseservice
|
|
|
|
|
|
|
|
) :
|
|
|
|
base(excelImportService, snowflakeIdGenerator, commonManager)
|
|
|
|
{
|
|
|
|
_service = service;
|
|
|
|
_repository = repository;
|
|
|
|
_wRepository = wRepository;
|
|
|
|
_mRepository = mRepository;
|
|
|
|
_sRepository = sRepository;
|
|
|
|
_adjRepository = adjRepository;
|
|
|
|
_pubMng = pubMng;
|
|
|
|
_bbacMng = bbacMng;
|
|
|
|
_hbpoMng = hbpoMng;
|
|
|
|
_invMng = invMng;
|
|
|
|
_baseservice = baseservice;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 审核通过
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<IActionResult> GenerateInvoice(List<string> p_invs)
|
|
|
|
{
|
|
|
|
var issucess = await _invMng.SetForwardState(p_invs, SettleBillState.商务已审核).ConfigureAwait(false);
|
|
|
|
if (issucess == true)
|
|
|
|
{
|
|
|
|
return new JsonResult(new { Code = 200, Message = "审核成功" });
|
|
|
|
}
|
|
|
|
return new JsonResult(new { Code = 400, Message = "审核失败" });
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 发票重开
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<IActionResult> ReissueInvoice([FromBody] string input)
|
|
|
|
{
|
|
|
|
return new JsonResult(new { Code = 200, Message = "重开成功" });
|
|
|
|
}
|
|
|
|
/// <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).ConfigureAwait(false);
|
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false);
|
|
|
|
var dtos = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_DTO>>(entitys);
|
|
|
|
foreach (var itm in dtos)
|
|
|
|
{
|
|
|
|
itm.TaxAmtDiff = itm.TaxAmt + itm.TaxDiff;
|
|
|
|
}
|
|
|
|
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 materialList = await _baseservice.GetMaterialList().ConfigureAwait(false);
|
|
|
|
var invs = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var m = await _mRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var mdtos = ObjectMapper.Map<List<INVOICE_MAP_GROUP>, List<INVOICE_MAP_GROUP_DTO>>(m);
|
|
|
|
var s = await _sRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var sdtos = ObjectMapper.Map<List<INVOICE_NOT_SETTLE>, List<INVOICE_NOT_SETTLE_DTO>>(s);
|
|
|
|
if (invs.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC)
|
|
|
|
{
|
|
|
|
var A = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var AMap = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_BBAC_DTO>>(A);
|
|
|
|
var wquery = from itm in AMap
|
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum
|
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp
|
|
|
|
from tm in temp.DefaultIfEmpty()
|
|
|
|
select
|
|
|
|
new INVOICE_WAIT_DETAIL_BBAC_DTO()
|
|
|
|
{
|
|
|
|
|
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc,
|
|
|
|
InvDate = itm1.CreationTime,
|
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
Version = itm.Version,
|
|
|
|
InvbillNum = itm.InvbillNum,
|
|
|
|
InvGroupNum = itm.InvGroupNum,
|
|
|
|
LU = itm.LU,
|
|
|
|
PartCode = itm.PartCode,
|
|
|
|
PRICE = itm.PRICE,
|
|
|
|
Qty = itm.Qty,
|
|
|
|
Amt = itm.Amt,
|
|
|
|
|
|
|
|
Extend1 = itm.Extend1,
|
|
|
|
BeginDate = itm.BeginDate,
|
|
|
|
EndDate = itm.EndDate,
|
|
|
|
};
|
|
|
|
entity.INVOICE_WAIT_DETAIL_BBAC = wquery.ToList();
|
|
|
|
}
|
|
|
|
else if (invs.FirstOrDefault().BusinessType == EnumBusinessType.BeiJian)
|
|
|
|
{
|
|
|
|
var B = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var BMap = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_BJ_DTO>>(B);
|
|
|
|
|
|
|
|
var wquery = from itm in BMap
|
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum
|
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp
|
|
|
|
from tm in temp.DefaultIfEmpty()
|
|
|
|
select
|
|
|
|
new INVOICE_WAIT_DETAIL_BJ_DTO()
|
|
|
|
{
|
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc,
|
|
|
|
InvDate = itm1.CreationTime,
|
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
Version = itm.Version,
|
|
|
|
InvbillNum = itm.InvbillNum,
|
|
|
|
InvGroupNum = itm.InvGroupNum,
|
|
|
|
LU = itm.LU,
|
|
|
|
PartCode = itm.PartCode,
|
|
|
|
PRICE = itm.PRICE,
|
|
|
|
Qty = itm.Qty,
|
|
|
|
Amt = itm.Amt,
|
|
|
|
|
|
|
|
Extend1 = itm.Extend1,
|
|
|
|
BeginDate = itm.BeginDate,
|
|
|
|
EndDate = itm.EndDate,
|
|
|
|
};
|
|
|
|
entity.INVOICE_WAIT_DETAIL_BJ = wquery.ToList();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var w = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false);
|
|
|
|
var wdtos = ObjectMapper.Map<List<INVOICE_WAIT_DETAIL>, List<INVOICE_WAIT_DETAIL_DTO>>(w);
|
|
|
|
var wquery = from itm in wdtos
|
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum
|
|
|
|
join itm2 in materialList on itm.LU equals itm2.SettleMaterialCode into temp
|
|
|
|
from tm in temp.DefaultIfEmpty()
|
|
|
|
select
|
|
|
|
new INVOICE_WAIT_DETAIL_DTO()
|
|
|
|
{
|
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc,
|
|
|
|
InvDate = itm1.CreationTime,
|
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
Version = itm.Version,
|
|
|
|
InvbillNum = itm.InvbillNum,
|
|
|
|
InvGroupNum = itm.InvGroupNum,
|
|
|
|
LU = itm.LU,
|
|
|
|
PartCode = itm.PartCode,
|
|
|
|
PRICE = itm.PRICE,
|
|
|
|
Qty = itm.Qty,
|
|
|
|
Amt = itm.Amt,
|
|
|
|
BussiessType = itm.BussiessType,
|
|
|
|
// Extend1 = itm.Extend1,
|
|
|
|
BeginDate = itm.BeginDate,
|
|
|
|
EndDate = itm.EndDate,
|
|
|
|
};
|
|
|
|
entity.INVOICE_WAIT_DETAIL = wdtos;
|
|
|
|
}
|
|
|
|
var notquery = from itm in sdtos
|
|
|
|
join itm1 in invs on itm.InvBillNum equals itm1.InvbillNum
|
|
|
|
select
|
|
|
|
new INVOICE_NOT_SETTLE_DTO()
|
|
|
|
{
|
|
|
|
InvDate = itm1.CreationTime,
|
|
|
|
RealInvBillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
InvBillNum = itm.InvBillNum,
|
|
|
|
InvGroupNum = itm.InvGroupNum,
|
|
|
|
SettleGroupNum = itm.SettleGroupNum,
|
|
|
|
LU = itm.LU,
|
|
|
|
Qty = itm.Qty,
|
|
|
|
Extend1 = itm.Extend1,
|
|
|
|
};
|
|
|
|
var mquery = from itm in mdtos
|
|
|
|
join itm1 in invs on itm.InvbillNum equals itm1.InvbillNum
|
|
|
|
select
|
|
|
|
new INVOICE_MAP_GROUP_DTO()
|
|
|
|
{
|
|
|
|
InvDate = itm1.CreationTime,
|
|
|
|
RealInvBillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
InvbillNum = itm.InvbillNum,
|
|
|
|
InvGroupNum = itm.InvGroupNum,
|
|
|
|
SettleGroupNum = itm.SettleGroupNum
|
|
|
|
};
|
|
|
|
var adjs = await _adjRepository.GetListByFilterAsync(input.Filters).ConfigureAwait(false);
|
|
|
|
var adjdtos = ObjectMapper.Map<List<PUB_ADJ_DETAIL>, List<PUB_ADJ_DETAIL_DTO>>(adjs);
|
|
|
|
var adjQuery = from itm in adjdtos
|
|
|
|
join itm1 in invs on itm.InvBillNum equals itm1.InvbillNum
|
|
|
|
select
|
|
|
|
new PUB_ADJ_DETAIL_DTO()
|
|
|
|
{
|
|
|
|
RealInvBillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum,
|
|
|
|
InvBillNum = itm.InvBillNum,
|
|
|
|
SettleDate = itm.SettleDate,
|
|
|
|
LU = itm.LU,
|
|
|
|
PN = itm.PN,
|
|
|
|
Qty = itm.Qty,
|
|
|
|
GroupNum = itm.GroupNum,
|
|
|
|
KeyCode = itm.KeyCode,
|
|
|
|
Price = itm.Price
|
|
|
|
};
|
|
|
|
entity.INVOICE_NOT_SETTLE = notquery.ToList();
|
|
|
|
entity.INVOICE_MAP_GROUP = mquery.ToList();
|
|
|
|
entity.ADJ_DETAIL = adjQuery.ToList();
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
var dtoDetails = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_EXP_DTO>>(entities);
|
|
|
|
foreach (var itm in dtoDetails)
|
|
|
|
{
|
|
|
|
itm.TaxAmtDiff = itm.TaxAmt + itm.TaxDiff;
|
|
|
|
}
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
result = await _excel.ExportAsByteArray(dtoDetails).ConfigureAwait(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result.ShouldNotBeNull();
|
|
|
|
|
|
|
|
//保存导出文件到服务器存成二进制
|
|
|
|
await _excelImportService.SaveBlobAsync(
|
|
|
|
new SaveExcelImportInputDto
|
|
|
|
{
|
|
|
|
Name = _fileName,
|
|
|
|
Content = result
|
|
|
|
}
|
|
|
|
).ConfigureAwait(false);
|
|
|
|
return _fileName;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 退回
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="input">主表查询条件</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<IActionResult> RejectAsync([FromBody] string p_invGroupNum)
|
|
|
|
{
|
|
|
|
bool issuc = await _invMng.Reject(p_invGroupNum).ConfigureAwait(false);
|
|
|
|
if (issuc == true)
|
|
|
|
{
|
|
|
|
return new JsonResult(new { Code = 200, Message = "退回成功" });
|
|
|
|
}
|
|
|
|
return new JsonResult(new { Code = 400, Message = "退回失败" });
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
|
|
public virtual async Task<IActionResult> ReceivedAsync(List<string> p_ins)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool issuc = await _invMng.ReceivedAsync(p_ins).ConfigureAwait(false);
|
|
|
|
if (issuc == true)
|
|
|
|
{
|
|
|
|
return new JsonResult(new { Code = 200, Message = "收票成功" });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return new JsonResult(new { Code = 400, Message = "收票失败" });
|
|
|
|
}
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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).ConfigureAwait(false);
|
|
|
|
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<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> p_tmplist, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
|
|
|
|
{
|
|
|
|
var flag = await _invMng.ReissueSecInvoice(p_list, p_adjlist, p_tmplist, p_parentInvBillNum, p_version).ConfigureAwait(false);
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new BusinessException("8989", "生成失败,请检查调发票整表和旧发票内容");
|
|
|
|
|
|
|
|
}
|
|
|
|
[UnitOfWork(false)]
|
|
|
|
/// <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<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
|
|
|
|
{
|
|
|
|
var flag = await _invMng.ReissueFirstInvoice(p_list, p_adjlist, dtos, p_parentInvBillNum, p_version).ConfigureAwait(false);
|
|
|
|
if (flag == true)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容");
|
|
|
|
}
|
|
|
|
[UnitOfWork(false)]
|
|
|
|
/// <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<List<INVOICE_WAIT_DETAIL>> ReissueSecInvoiceExtend<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> p_tmplist, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
|
|
|
|
{
|
|
|
|
var ls = await _invMng.ReissueSecInvoiceExtend(p_list, p_adjlist, p_tmplist, p_parentInvBillNum, p_version).ConfigureAwait(false);
|
|
|
|
if (ls.Count > 0)
|
|
|
|
{
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new BusinessException("8989", "生成失败,请检查调发票整表和旧发票内容");
|
|
|
|
|
|
|
|
}
|
|
|
|
[UnitOfWork(false)]
|
|
|
|
/// <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<List<INVOICE_WAIT_DETAIL>> ReissueFirstInvoiceExtend<TDetail>(List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, int p_version, string p_parentInvBillNum) where TDetail : SA_CAN_BASE
|
|
|
|
{
|
|
|
|
var ls = await _invMng.ReissueFirstInvoiceExtend(p_list, p_adjlist, dtos, p_parentInvBillNum, p_version).ConfigureAwait(false);
|
|
|
|
if (ls.Count > 0)
|
|
|
|
{
|
|
|
|
return ls;
|
|
|
|
}
|
|
|
|
throw new BusinessException("8989", "生成失败,请检查调整表和旧发票内容");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 检查是否有重复
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="p_list">调整明细数据</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
protected async Task<List<ERR_EXP_DTO>> CheckRepeat(List<PUB_ADJ_DETAIL_DTO> p_list)
|
|
|
|
{
|
|
|
|
var errorlist = p_list.GroupBy(p => new { p.PN, p.LU }).Where(p => p.Count() > 1).Select(p => new { p.Key.PN, p.Key.LU }).ToList();
|
|
|
|
|
|
|
|
List<ERR_EXP_DTO> errors = new List<ERR_EXP_DTO>();
|
|
|
|
|
|
|
|
foreach (var itm in errorlist)
|
|
|
|
{
|
|
|
|
errors.Add(new ERR_EXP_DTO() { Message = $"零件号{itm.LU},标识号(生产码){itm.PN}有重复数据!" });
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <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 first = dto1s.FirstOrDefault();
|
|
|
|
var usepriceList = p_pricelist.Where(p => p.ClientCode == first.Site && p.IsCancel == false).ToList();
|
|
|
|
var errorlist = _baseservice.CheckPriceListContinuity(usepriceList);
|
|
|
|
|
|
|
|
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 && d.Site == p.ClientCode && p.IsCancel == false
|
|
|
|
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 errorlist)
|
|
|
|
{
|
|
|
|
errorList.Add(new ERR_EXP_DTO() { ItemCode = error.LU, CustomCode = $"{name}", Message = $"LU:{error.LU},价格表开始日期:{error.BeginTime}价格表结束日期:{error.EndTime}在用价格时间段有交集或价格时间不连续!" });
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|