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.
83 lines
3.6 KiB
C#
83 lines
3.6 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.Invoice.Interface;
|
|
using DS.WMS.Core.Sys.Entity;
|
|
using SqlSugar;
|
|
|
|
namespace DS.WMS.Core.Invoice.Method
|
|
{
|
|
/// <summary>
|
|
/// 标准(按申请)开票实现
|
|
/// </summary>
|
|
public class GeneralInvoiceService : InvoiceService<Entity.Invoice>, IGeneralInvoiceService
|
|
{
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="provider"></param>
|
|
public GeneralInvoiceService(IServiceProvider provider) : base(provider)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取付费申请分页列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
public async Task<DataResult<List<InvoiceApplicationDto>>> GetApplicationListAsync(PageRequest request)
|
|
{
|
|
var query = TenantDb.Queryable<InvoiceApplication>().Where(x => x.Status == InvoiceApplicationStatus.AuditPassed || x.Status == InvoiceApplicationStatus.PartialInvoiced)
|
|
.InnerJoin<ApplicationDetail>((a, d) => a.Id == d.ApplicationId && (d.OriginalAmount - d.OriginalProcessedAmount) != 0)
|
|
.Select(a => new InvoiceApplicationDto
|
|
{
|
|
Id = a.Id,
|
|
ApplicationNO = a.ApplicationNO,
|
|
Status = a.Status,
|
|
CustomerId = a.CustomerId,
|
|
CustomerName = a.CustomerName, //结算单位
|
|
InvoiceHeader = a.InvoiceHeader,
|
|
ApplyAmount = a.ApplyAmount,
|
|
InvoiceAmount = a.InvoiceAmount,
|
|
Currency = a.Currency,
|
|
Category = a.Category,
|
|
OrgId = a.OrgId, //所属部门
|
|
SaleDeptId = a.SaleDeptId, //所属分部
|
|
CreateBy = a.CreateBy, //申请人
|
|
CreateTime = a.CreateTime, //申请日期
|
|
InvoiceRemark = a.InvoiceRemark, //开票要求
|
|
Note = a.Note,
|
|
//原币金额
|
|
OriginalAmountList = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId)
|
|
.GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = y.OriginalAmount })
|
|
});
|
|
|
|
var whereList = request.GetConditionalModels(Db);
|
|
var result = await query.Where(whereList).ToQueryPageAsync(request.PageCondition);
|
|
|
|
if (result.Data.Count > 0)
|
|
{
|
|
var userIds = result.Data.Select(x => x.CreateBy).Distinct();
|
|
var users = await Db.Queryable<SysUser>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync();
|
|
|
|
var orgIds = result.Data.Where(x => x.SaleDeptId.HasValue).Select(x => x.SaleDeptId)
|
|
.Union(result.Data.Where(x => x.OrgId.HasValue).Select(x => x.OrgId))
|
|
.Distinct();
|
|
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.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
|
|
|
|
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
|
|
item.OrgName = orgs.Find(x => x.Id == item.OrgId)?.OrgName;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|