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.

130 lines
5.3 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.Fee.Entity;
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
{
public override TaskBaseTypeEnum AuditType => TaskBaseTypeEnum.APPLICATION_INVOICE_AUDIT;
/// <summary>
/// 初始化
/// </summary>
/// <param name="serviceProvider"></param>
public InvoiceApplicationAuditService(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
/// <summary>
/// 获取待审核列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <remarks>注意!!【仅查看待审核】需要通过 OtherQueryCondition 属性传入</remarks>
public async Task<DataResult<List<InvoiceApplicationDto>>> GetListAsync(PageRequest<bool?> request)
{
var query = CreateListQuery();
if (!request.QueryCondition.IsNullOrEmpty())
{
var whereList = request.GetConditionalModels(Db);
query = query.Where(whereList);
}
//设置了状态筛选
if (request.OtherQueryCondition.GetValueOrDefault())
query = query.Where(a => a.Status == InvoiceApplicationStatus.AuditSubmittd);
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>()
.InnerJoin<ApplicationDetail>((a, d) => a.Id == d.ApplicationId)
.InnerJoin<FeeRecord>((a, d, f) => d.RecordId == f.Id)
//.LeftJoin<SeaExport>((a, d, f, s) => f.BusinessId == s.Id)
//.LeftJoin<InfoClientBank>((a, d, f, s, b) => a.CustomerBankId == b.Id)
.GroupBy(a => a.Id)
.Select((a, d, f) => 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,
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;
if (auditType != TaskBaseTypeEnum.APPLICATION_INVOICE_AUDIT)
return;
if (callback.FlowStatus == FlowStatusEnum.Approve)
{
application.Status = InvoiceApplicationStatus.AuditPassed;
application.Reason = string.Empty;
}
else if (callback.FlowStatus == FlowStatusEnum.Reject)
{
application.Status = InvoiceApplicationStatus.AuditRejected;
application.Reason = callback.RejectReason;
}
await base.OnUpdateStatusAsync(callback, application);
}
}
}