You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
5.9 KiB
C#
142 lines
5.9 KiB
C#
using DS.Module.Core;
|
|
using DS.Module.Core.Enums;
|
|
using DS.Module.Core.Extensions;
|
|
using DS.WMS.Core.Application.Dtos;
|
|
using DS.WMS.Core.Application.Entity;
|
|
using DS.WMS.Core.Application.Interface;
|
|
using DS.WMS.Core.Flow.Dtos;
|
|
using DS.WMS.Core.Info.Entity;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Application.Method
|
|
{
|
|
/// <summary>
|
|
/// 费用申请单审核服务
|
|
/// </summary>
|
|
public class InvoiceApplicationAuditService : ApplicationAuditService<InvoiceApplication>, IInvoiceApplicationAuditService
|
|
{
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="serviceProvider"></param>
|
|
public InvoiceApplicationAuditService(IServiceProvider serviceProvider) : base(serviceProvider)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取待审核列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<List<InvoiceApplicationDto>>> GetListAsync(PageRequest request)
|
|
{
|
|
var query = CreateListQuery();
|
|
|
|
if (!request.QueryCondition.IsNullOrEmpty())
|
|
{
|
|
var whereList = Db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
int? index = null;
|
|
foreach (var item in whereList)
|
|
{
|
|
ConditionalModel? model = item as ConditionalModel;
|
|
if (model == null)
|
|
continue;
|
|
|
|
//设置了状态筛选
|
|
if (string.Equals(model.FieldName, nameof(InvoiceApplicationDto.IsAudited)) && bool.TryParse(model.FieldValue, out bool isAudited))
|
|
{
|
|
if (isAudited)
|
|
query = query.Where(x => x.Status == InvoiceApplicationStatus.AuditPassed || x.Status == InvoiceApplicationStatus.AuditRejected);
|
|
else
|
|
query = query.Where(x => x.Status == InvoiceApplicationStatus.AuditSubmittd);
|
|
|
|
index = whereList.IndexOf(item);
|
|
break;
|
|
}
|
|
}
|
|
if (index.HasValue)
|
|
whereList.RemoveAt(index.Value);
|
|
|
|
|
|
query = query.Where(whereList);
|
|
}
|
|
|
|
var result = await query.GroupBy(x => x.Id).ToQueryPageAsync(request.PageCondition);
|
|
if (result.Data.Count > 0)
|
|
{
|
|
var orgIds = result.Data.Select(x => x.SaleDeptId).Distinct().ToList();
|
|
var orgs = await Db.Queryable<SysOrg>().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync();
|
|
foreach (var item in result.Data)
|
|
{
|
|
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
internal ISugarQueryable<InvoiceApplicationDto> CreateListQuery()
|
|
{
|
|
var query1 = TenantDb.Queryable<InvoiceApplication>().Where(x => x.Status == InvoiceApplicationStatus.AuditSubmittd)
|
|
.InnerJoin<ApplicationDetail>((a, d) => a.Id == d.ApplicationId)
|
|
.LeftJoin<SeaExport>((a, d, s) => d.BusinessId == s.Id)
|
|
.LeftJoin<InfoClientBank>((a, d, s, b) => a.CustomerBankId == b.Id)
|
|
.Select((a, d, s, b) => new InvoiceApplicationDto
|
|
{
|
|
Id = a.Id,
|
|
ApplicationNO = a.ApplicationNO,
|
|
Status = a.Status,
|
|
CustomerId = a.CustomerId,
|
|
CustomerName = a.CustomerName, //委托单位
|
|
InvoiceHeader = a.InvoiceHeader,
|
|
Currency = a.Currency,
|
|
ApplyAmount = a.ApplyAmount,
|
|
InvoiceAmount = a.InvoiceAmount,
|
|
InvoiceCurrency = a.InvoiceCurrency,
|
|
CreateTime = a.CreateTime,//申请开票日期+申请时间
|
|
CreateBy = a.CreateBy, //申请人
|
|
Category = a.Category, //申请类型
|
|
TaxRate = a.TaxRate, //发票税率
|
|
InvoiceNO = a.InvoiceNO, //发票号
|
|
Note = a.Note,
|
|
InvoiceRemark = a.InvoiceRemark, //开票要求
|
|
SaleDeptId = a.SaleDeptId,
|
|
//原币金额
|
|
OriginalAmountList = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId)
|
|
.GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = y.OriginalAmount }),
|
|
});
|
|
|
|
return TenantDb.UnionAll(new List<ISugarQueryable<InvoiceApplicationDto>> { query1 });
|
|
}
|
|
|
|
|
|
protected override DataResult PreAudit(List<InvoiceApplication> applications)
|
|
{
|
|
if (applications.Exists(x => x.Status != InvoiceApplicationStatus.AuditSubmittd))
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.ApplicationIsNotAuditing));
|
|
|
|
return DataResult.Success;
|
|
}
|
|
|
|
protected override async Task OnUpdateStatusAsync(FlowCallback callback, InvoiceApplication application)
|
|
{
|
|
var auditType = callback.AuditType.ToEnum<AuditType>();
|
|
if (auditType != AuditType.PaidApplication)
|
|
return;
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
{
|
|
application.Status = InvoiceApplicationStatus.AuditPassed;
|
|
application.Reason = string.Empty;
|
|
}
|
|
else if (callback.FlowStatus == FlowStatusEnum.Reject)
|
|
application.Status = InvoiceApplicationStatus.AuditRejected;
|
|
|
|
await base.OnUpdateStatusAsync(callback, application);
|
|
}
|
|
}
|
|
}
|