|
|
@ -1,10 +1,15 @@ |
|
|
|
using System; |
|
|
|
using System.Collections; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
|
using System.DirectoryServices.ActiveDirectory; |
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using System.Security.Policy; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using DocumentFormat.OpenXml.Spreadsheet; |
|
|
|
using DocumentFormat.OpenXml.Drawing; |
|
|
|
using DocumentFormat.OpenXml.Wordprocessing; |
|
|
|
using EFCore.BulkExtensions; |
|
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
|
using Magicodes.ExporterAndImporter.Csv; |
|
|
@ -12,11 +17,13 @@ using Magicodes.ExporterAndImporter.Excel; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.CodeAnalysis.Operations; |
|
|
|
using Microsoft.OpenApi.Writers; |
|
|
|
using SettleAccount.Domain.BQ; |
|
|
|
using ShardingCore.Extensions; |
|
|
|
using Shouldly; |
|
|
|
using SqlSugar; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Application.Services; |
|
|
|
using Volo.Abp.Data; |
|
|
@ -28,12 +35,19 @@ using Win.Sfs.SettleAccount.Bases; |
|
|
|
using Win.Sfs.SettleAccount.Bases.DomainServices; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
|
using Win.Sfs.SettleAccount.Constant; |
|
|
|
using Win.Sfs.SettleAccount.Customers; |
|
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
|
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.Invoices; |
|
|
|
using Win.Sfs.SettleAccount.EntityFrameworkCore; |
|
|
|
using Win.Sfs.SettleAccount.ExcelImporter; |
|
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using Win.Sfs.Shared.Filter; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
using static Dm.parser.LVal; |
|
|
|
using static LinqToDB.Sql; |
|
|
|
using Win.Sfs.Shared.Filter; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
{ |
|
|
@ -41,6 +55,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class INVOICE_SERVICE : BASE_SERVICE |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 数据上下文
|
|
|
|
/// </summary>
|
|
|
|
private readonly SettleAccountDbContext _settleAccountDbContext; |
|
|
|
/// <summary>
|
|
|
|
/// WMS数据上下文
|
|
|
|
/// </summary>
|
|
|
|
private readonly WMSBJBMPTDbContext _wmsBJBMPTContext; |
|
|
|
/// <summary>
|
|
|
|
/// 数据中心S数据上下文
|
|
|
|
/// </summary>
|
|
|
|
private readonly ExChangeCenterDbContext _exChangeCenterDbContext; |
|
|
|
|
|
|
|
private readonly INormalEfCoreRepository<INVOICE_GRP, Guid> _repository; |
|
|
|
private readonly INormalEfCoreRepository<INVOICE_WAIT_DETAIL, Guid> _wRepository; |
|
|
|
private readonly INormalEfCoreRepository<INVOICE_NOT_SETTLE, Guid> _sRepository; |
|
|
@ -51,7 +78,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
private readonly HBPO_CAN_SA_MNG _hbpoMng; |
|
|
|
private readonly INV_MNG _invMng; |
|
|
|
private readonly BaseDomainService _baseservice; |
|
|
|
public INVOICE_SERVICE(IExcelImportAppService excelImportService, |
|
|
|
public INVOICE_SERVICE( |
|
|
|
SettleAccountDbContext settleAccountDbContext, |
|
|
|
WMSBJBMPTDbContext wmsBJBMPTContext, |
|
|
|
ExChangeCenterDbContext exChangeCenterDbContext, |
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager, |
|
|
|
INormalEfCoreRepository<INVOICE_GRP, Guid> repository, |
|
|
@ -67,6 +98,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
|
|
|
|
) : base(excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
|
_wmsBJBMPTContext = wmsBJBMPTContext; |
|
|
|
_exChangeCenterDbContext = exChangeCenterDbContext; |
|
|
|
_baseservice = baseservice; |
|
|
|
_repository = repository; |
|
|
|
_wRepository = wRepository; |
|
|
@ -79,6 +113,116 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
_invMng = invMng; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 提交到QAD
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 已扣减发票提交到QAD
|
|
|
|
/// </remarks>
|
|
|
|
[HttpPost] |
|
|
|
public virtual async Task<IActionResult> SubmitToQad(List<string> invbillNums) |
|
|
|
{ |
|
|
|
var invoiceGrps = _settleAccountDbContext.Set<INVOICE_GRP>() |
|
|
|
.Where(t => invbillNums.Contains(t.InvbillNum)) |
|
|
|
.Where(t => t.State == SettleBillState.已扣减) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
invbillNums = invoiceGrps.Select(t => t.InvbillNum).ToList(); |
|
|
|
|
|
|
|
var invoiceGrpDetails = _settleAccountDbContext.Set<INVOICE_WAIT_DETAIL>() |
|
|
|
.Where(t => invbillNums.Contains(t.InvbillNum)) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
var taskId = GuidGenerator.Create(); |
|
|
|
var teaTaskSub = new TEA_TASK_SUB() |
|
|
|
{ |
|
|
|
GUID = taskId, |
|
|
|
TaskState = 0, |
|
|
|
TaskID = taskId, |
|
|
|
TableName = "TED_SA_INV", |
|
|
|
Creator = "SAS", |
|
|
|
Subscriber = "QAD", |
|
|
|
Domain = "BJBMPT", |
|
|
|
Site = "BJ02", |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
UpdateTime = DateTime.Now, |
|
|
|
}; |
|
|
|
|
|
|
|
var tedSaInvs = invoiceGrpDetails.Join(invoiceGrps, x => x.InvbillNum, y => y.InvbillNum, (x, y) => |
|
|
|
{ |
|
|
|
return new TED_SA_INV() |
|
|
|
{ |
|
|
|
GUID = GuidGenerator.Create(), |
|
|
|
TaskID = taskId, |
|
|
|
InvoiceNumber = y.RealnvBillNum, |
|
|
|
SASInvoiceNumber = y.InvbillNum, |
|
|
|
Customer = y.ClientCode, |
|
|
|
BillTo = y.ClientCode, |
|
|
|
InvoiceDate = y.CreationTime, |
|
|
|
Site = "BJ02", |
|
|
|
TYPE = default, |
|
|
|
PartNumber = x.LU, |
|
|
|
InvoiceQuatity = x.Qty, |
|
|
|
Price = x.PRICE, |
|
|
|
Supplier = default, |
|
|
|
Remark = default, |
|
|
|
InvoiceNetAmount = x.Amt, |
|
|
|
InvoiceTaxAmount = x.Amt * 0.13m, |
|
|
|
TaxRate = 0.13m, |
|
|
|
Location = $"C{y.ClientCode}", |
|
|
|
InvoiceNet = default, |
|
|
|
InvoiceTax = default, |
|
|
|
begintime = x.BeginDate, |
|
|
|
endtime = x.EndDate, |
|
|
|
Domain = "BJBMPT" |
|
|
|
}; |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
var invoiceGrpTedSaInvs = invoiceGrps.Select(t => |
|
|
|
{ |
|
|
|
return new TED_SA_INV() |
|
|
|
{ |
|
|
|
GUID = GuidGenerator.Create(), |
|
|
|
TaskID = taskId, |
|
|
|
UID = default, |
|
|
|
InvoiceNumber = t.RealnvBillNum, |
|
|
|
SASInvoiceNumber = t.InvbillNum, |
|
|
|
Customer = t.ClientCode, |
|
|
|
BillTo = t.ClientCode, |
|
|
|
InvoiceDate = t.CreationTime, |
|
|
|
Site = "BJ02", |
|
|
|
TYPE = default, |
|
|
|
PartNumber = default, |
|
|
|
InvoiceQuatity = default, |
|
|
|
Price = default, |
|
|
|
Supplier = default, |
|
|
|
Remark = default, |
|
|
|
InvoiceNetAmount = default, |
|
|
|
InvoiceTaxAmount = default, |
|
|
|
TaxRate = 0.13m, |
|
|
|
Location = $"C{t.ClientCode}", |
|
|
|
InvoiceNet = t.Amt, |
|
|
|
InvoiceTax = default, |
|
|
|
begintime = default, |
|
|
|
endtime = default, |
|
|
|
Domain = "BJBMPT" |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
tedSaInvs.AddRange(invoiceGrpTedSaInvs); |
|
|
|
if (tedSaInvs.Any()) |
|
|
|
{ |
|
|
|
await _exChangeCenterDbContext.Set<TEA_TASK_SUB>().AddAsync(teaTaskSub).ConfigureAwait(false); |
|
|
|
await _exChangeCenterDbContext.Set<TED_SA_INV>().AddRangeAsync(tedSaInvs).ConfigureAwait(false); |
|
|
|
await _exChangeCenterDbContext.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
invoiceGrps.ForEach(t => t.State = SettleBillState.已提交QAD); |
|
|
|
await _settleAccountDbContext.SaveChangesAsync().ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
|
return new OkResult(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 通过审核
|
|
|
|
/// </summary>
|
|
|
@ -154,19 +298,16 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
public virtual async Task<INVOICE_GRP_DETAIL_DTO> DetailQueryAsync(INVOICE_GRP_REQ_DTO input) |
|
|
|
{ |
|
|
|
INVOICE_GRP_DETAIL_DTO entity = new INVOICE_GRP_DETAIL_DTO(); |
|
|
|
|
|
|
|
input.Filters.Add(new FilterCondition("InvoiceState", "1", EnumFilterAction.Equal, EnumFilterLogic.And)); |
|
|
|
|
|
|
|
|
|
|
|
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 first = invs.FirstOrDefault(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var materialList = await _baseservice.GetMaterialList(first.BusinessType).ConfigureAwait(false); |
|
|
|
//if (materialList.Count == 0)
|
|
|
|
//{
|
|
|
|
// throw new UserFriendlyException($" 零件关系表无对应业务,零件关系记录!", "400");
|
|
|
|
//}
|
|
|
|
if (invs.FirstOrDefault().BusinessType == EnumBusinessType.JisBBAC) |
|
|
|
{ |
|
|
|
var A = await _wRepository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, input.SkipCount).ConfigureAwait(false); |
|
|
@ -178,7 +319,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
select |
|
|
|
new INVOICE_WAIT_DETAIL_BBAC_DTO() |
|
|
|
{ |
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc, |
|
|
|
PartDesc = tm == null ? string.Empty : tm.MaterialDesc, |
|
|
|
InvDate = itm1.CreationTime, |
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum, |
|
|
|
Version = itm.Version, |
|
|
@ -286,7 +427,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
select |
|
|
|
new INVOICE_WAIT_DETAIL_DTO() |
|
|
|
{ |
|
|
|
PartDesc = tm == null ? string.Empty : itm.PartDesc, |
|
|
|
PartDesc = tm == null ? string.Empty : tm.MaterialDesc, |
|
|
|
InvDate = itm1.CreationTime, |
|
|
|
RealInvbillNum = string.IsNullOrEmpty(itm1.RealnvBillNum) ? string.Empty : itm1.RealnvBillNum, |
|
|
|
Version = itm.Version, |
|
|
@ -397,7 +538,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
List<MAIDAN_HBPO_UNSETTLED_DETAIL_DTO> unsettle = new List<MAIDAN_HBPO_UNSETTLED_DETAIL_DTO>(); |
|
|
|
foreach (var itm in sdtos) |
|
|
|
{ |
|
|
|
unsettle.Add(new MAIDAN_HBPO_UNSETTLED_DETAIL_DTO() { |
|
|
|
unsettle.Add(new MAIDAN_HBPO_UNSETTLED_DETAIL_DTO() |
|
|
|
{ |
|
|
|
GroupNum = itm.SettleGroupNum, |
|
|
|
LU = itm.LU, |
|
|
|
PN = itm.Extend1, |
|
|
@ -456,7 +598,7 @@ namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
|
{ |
|
|
|
IExporter _csv = new CsvExporter(); |
|
|
|
ExcelExporter _excel = new ExcelExporter(); |
|
|
|
var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false); |
|
|
|
// var materialList = await _baseservice.GetMaterialList().ConfigureAwait(false);
|
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true).ConfigureAwait(false); |
|
|
|
var first = entities.FirstOrDefault(); |
|
|
|
var dtoDetails = ObjectMapper.Map<List<INVOICE_GRP>, List<INVOICE_GRP_EXP_DTO>>(entities); |
|
|
|