自由开票bug修复

dev
嵇文龙 2 weeks ago
parent adcbf33c99
commit e58ad4edcd

@ -98,7 +98,7 @@ namespace DS.WMS.Core.Fee.Dtos
/// <summary>
/// 操作员
/// </summary>
public string? Operator { get; set; }
public string? OperatorName { get; set; }
/// <summary>
/// 录入人ID

@ -163,7 +163,7 @@ namespace DS.WMS.Core.Application.Dtos
/// </summary>
public long CreateBy { get; set; }
public string CreateByName { get; set; }
public string? CreateByName { get; set; }
/// <summary>
/// 创建时间

@ -214,7 +214,7 @@ namespace DS.WMS.Core.Application.Method
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
if (item.OperatorId.HasValue)
item.Operator = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
item.OperatorName = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
}

@ -343,7 +343,7 @@ namespace DS.WMS.Core.Application.Method
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
if (item.OperatorId.HasValue)
item.Operator = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
item.OperatorName = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
}

@ -173,7 +173,7 @@ namespace DS.WMS.Core.Fee.Dtos
/// <summary>
/// 操作员
/// </summary>
public string? Operator { get; set; }
public string? OperatorName { get; set; }
/// <summary>
/// 起运港
@ -414,39 +414,64 @@ namespace DS.WMS.Core.Fee.Dtos
public decimal CommissionRate { get; set; }
/// <summary>
/// 结算金额
/// 结算金额
/// </summary>
public decimal SettlementAmount { get; set; }
/// <summary>
/// 开票金额
/// 开票金额
/// </summary>
public decimal InvoiceAmount { get; set; }
/// <summary>
/// 申请金额
/// 费用申请金额
/// </summary>
public decimal OrderAmount { get; set; }
/// <summary>
/// 申请开票金额
/// 发票申请金额
/// </summary>
public decimal OrderInvoiceAmount { get; set; }
/// <summary>
/// 申请结算金额
/// 申请金额已结算
/// </summary>
public decimal OrderSettlementAmount { get; set; }
/// <summary>
/// 申请发票开票金额
/// 发票申请金额已开票
/// </summary>
public decimal OrderInvSettlementAmount { get; set; }
///// <summary>
///// 未开票金额
///// </summary>
//public decimal InvoiceAmountRest { get; set; }
/// <summary>
/// 剩余人民币结算金额
/// </summary>
public decimal RestStlAmountRMB { get; set; }
/// <summary>
/// 剩余美金结算金额
/// </summary>
public decimal RestStlAmountUSD { get; set; }
/// <summary>
/// 剩余其他结算金额
/// </summary>
public decimal RestStlAmountOther { get; set; }
/// <summary>
/// 剩余人民币开票金额
/// </summary>
public decimal RestInvAmountRMB { get; set; }
/// <summary>
/// 剩余美金开票金额
/// </summary>
public decimal RestInvAmountUSD { get; set; }
/// <summary>
/// 剩余其他开票金额
/// </summary>
public decimal RestInvAmountOther { get; set; }
/// <summary>
/// 是否机密费用

@ -6,6 +6,7 @@ using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Fee.Interface;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
@ -46,6 +47,7 @@ namespace DS.WMS.Core.Fee.Method
AccountDate = s.AccountDate,
CntrTotal = s.CntrTotal,
CreateBy = s.CreateBy,
CreateByName = s.CreateUserName,
CustomerNo = s.CustomerNo,
ClientName = s.CustomerName, //委托单位
ETD = s.ETD,
@ -55,7 +57,9 @@ namespace DS.WMS.Core.Fee.Method
DischargePort = s.DischargePort,
OperatorId = s.OperatorId,
OperatorName = s.OperatorName,
SaleDeptId = s.SaleDeptId,
SaleDeptName = s.SaleDeptName,
SaleId = s.SaleId,
Sale = s.Sale,//揽货人
Vessel = s.Vessel,//船名
@ -87,6 +91,15 @@ namespace DS.WMS.Core.Fee.Method
DebitNo = f.DebitNo,
IsInvoice = f.IsInvoice,
SaleOrgId = f.SaleOrgId,
//-----统计项-----
RestStlAmountRMB = f.Currency == FeeCurrency.RMB_CODE ? f.Amount - f.SettlementAmount : 0,
RestStlAmountUSD = f.Currency == FeeCurrency.USD_CODE ? f.Amount - f.SettlementAmount : 0,
RestStlAmountOther = f.Currency != FeeCurrency.RMB_CODE && f.Currency != FeeCurrency.USD_CODE ? f.Amount - f.SettlementAmount : 0,
RestInvAmountRMB = f.Currency == FeeCurrency.RMB_CODE ? f.Amount - f.InvoiceAmount : 0,
RestInvAmountUSD = f.Currency == FeeCurrency.USD_CODE ? f.Amount - f.InvoiceAmount : 0,
RestInvAmountOther = f.Currency != FeeCurrency.RMB_CODE && f.Currency != FeeCurrency.USD_CODE ? f.Amount - f.InvoiceAmount : 0
});
//海运进口

@ -62,9 +62,14 @@ namespace DS.WMS.Core.Invoice.Dtos
public string? BankName { get; set; }
/// <summary>
/// 申请金额(费用明细的合计)
/// RMB申请金额
/// </summary>
public decimal ApplyAmount { get; set; }
public decimal ApplyAmountRMB { get; set; }
/// <summary>
/// USD申请金额
/// </summary>
public decimal ApplyAmountUSD { get; set; }
/// <summary>
/// 币别
@ -145,12 +150,12 @@ namespace DS.WMS.Core.Invoice.Dtos
/// <summary>
/// 税额
/// </summary>
public decimal Tax => ApplyAmount - ApplyAmount * TaxRate;
public decimal Tax => InvoiceAmount * TaxRate;
/// <summary>
/// 不含税金额
/// </summary>
public decimal NoTaxAmount => ApplyAmount - Tax;
public decimal NoTaxAmount => InvoiceAmount - Tax;
/// <summary>
/// 所属机构(公司)

@ -6,9 +6,14 @@
public class InvoiceList
{
/// <summary>
/// 申请金额
/// RMB申请金额
/// </summary>
public decimal? ApplyAmount => List?.Sum(x => x.ApplyAmount);
public decimal? ApplyAmountRMB => List?.Sum(x => x.ApplyAmountRMB);
/// <summary>
/// USD申请金额
/// </summary>
public decimal? ApplyAmountUSD => List?.Sum(x => x.ApplyAmountUSD);
/// <summary>
/// 开票金额

@ -66,17 +66,17 @@ namespace DS.WMS.Core.Invoice.Entity
[SugarColumn(ColumnDescription = "收款单位账号", Length = 100, IsNullable = true)]
public string? Account { get; set; }
/// <summary>
/// 申请金额(费用明细的合计)
/// </summary>
[SugarColumn(ColumnDescription = "申请金额")]
public decimal ApplyAmount { get; set; }
///// <summary>
///// 申请金额
///// </summary>
//[SugarColumn(ColumnDescription = "申请金额", IsNullable = true)]
//public decimal? ApplyAmount { get; set; }
/// <summary>
/// 申请金额大写
/// </summary>
[SugarColumn(ColumnDescription = "申请金额大写", Length = 100, IsNullable = true)]
public string? AmountUppercase { get; set; }
///// <summary>
///// 申请金额大写
///// </summary>
//[SugarColumn(ColumnDescription = "申请金额大写", Length = 100, IsNullable = true)]
//public string? AmountUppercase { get; set; }
/// <summary>
/// 币别

@ -10,6 +10,7 @@ using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Invoice.Interface;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
using NPOI.Util;
using SqlSugar;
namespace DS.WMS.Core.Invoice.Method
@ -46,11 +47,11 @@ namespace DS.WMS.Core.Invoice.Method
switch (request.OtherQueryCondition.Value)
{
case FeeRange.Unsettled:
expr = expr.And((s, f) => f.SettlementAmount == 0);
expr = expr.And((s, f) => f.Amount - f.SettlementAmount != 0);
break;
case FeeRange.Settled:
expr = expr.And((s, f) => f.SettlementAmount > 0);
expr = expr.And((s, f) => f.Amount - f.SettlementAmount == 0);
break;
}
}
@ -62,59 +63,39 @@ namespace DS.WMS.Core.Invoice.Method
query = query.Where(whereList);
}
var result = await query.GroupBy(x => x.BusinessId).Select(x => new BizInvoiceApplication
{
Id = x.BusinessId,
BusinessType = x.BusinessType,
AccountDate = x.AccountDate,
CntrTotal = x.CntrTotal,
CreateBy = x.CreateBy,
CustomerNo = x.CustomerNo,
ClientName = x.ClientName,
CustomerId = x.CustomerId,
CustomerName = x.CustomerName,
DischargePort = x.DischargePort,
ETD = x.ETD,
HBLNO = x.HBLNO,
LoadPort = x.LoadPort,
MBLNO = x.MBLNO,
OperatorId = x.OperatorId,
SaleDeptId = x.SaleDeptId,
SaleId = x.SaleId,
SaleName = x.Sale,
Vessel = x.Vessel,
Voyage = x.Voyage,
BookingNo = x.BookingNo,
//未开票金额=金额-已开票金额-申请开票金额+申请开票金额已开票
UnBilledRMB = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == x.BusinessId && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency == FeeCurrency.RMB_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount)),
UnBilledUSD = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == x.BusinessId && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency == FeeCurrency.USD_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount)),
UnBilledOther = SqlFunc.Subqueryable<FeeRecord>().Where(f => f.BusinessId == x.BusinessId && f.FeeStatus == FeeStatus.AuditPassed
&& f.Currency != FeeCurrency.RMB_CODE && f.Currency != FeeCurrency.USD_CODE).Select(f => SqlFunc.AggregateSum(f.Amount - f.InvoiceAmount)),
}).ToQueryPageAsync(request.PageCondition);
if (result.Data.Count > 0)
{
//关联用户名称
var userIds = result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value)
.Union(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.Select(x => x.SaleDeptId).Distinct();
var orgs = await Db.Queryable<SysOrg>().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync();
foreach (var item in result.Data)
var result = await query.GroupBy(x => new { x.BusinessId, x.BusinessType, x.CustomerId })
.Select(x => new BizInvoiceApplication
{
item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName;
if (item.OperatorId.HasValue)
item.Operator = users.Find(x => x.Id == item.OperatorId.Value)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
}
}
Id = x.BusinessId,
BusinessType = x.BusinessType,
AccountDate = x.AccountDate,
CntrTotal = x.CntrTotal,
CreateBy = x.CreateBy,
CreateByName = x.CreateByName,
CustomerNo = x.CustomerNo,
ClientName = x.ClientName,
CustomerId = x.CustomerId,
CustomerName = x.CustomerName,
DischargePort = x.DischargePort,
ETD = x.ETD,
HBLNO = x.HBLNO,
LoadPort = x.LoadPort,
MBLNO = x.MBLNO,
OperatorId = x.OperatorId,
OperatorName = x.OperatorName,
SaleDeptId = x.SaleDeptId,
SaleDeptName = x.SaleDeptName,
SaleId = x.SaleId,
SaleName = x.Sale,
Vessel = x.Vessel,
Voyage = x.Voyage,
BookingNo = x.BookingNo,
//未开票金额
UnBilledRMB = SqlFunc.AggregateSum(x.RestInvAmountRMB),
UnBilledUSD = SqlFunc.AggregateSum(x.RestInvAmountUSD),
UnBilledOther = SqlFunc.AggregateSum(x.RestInvAmountOther)
}).ToQueryPageAsync(request.PageCondition);
return result;
}

@ -37,9 +37,9 @@ namespace DS.WMS.Core.Invoice.Method
SqlFunc.Subqueryable<ApplicationDetail>().Where(d => d.ApplicationId == a.Id && d.Category == DetailCategory.InvoiceApplication && (d.OriginalAmount - d.OriginalProcessedAmount) != 0).Any())
.Select(a => new InvoiceApplicationDto
{
AmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount),
AmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount),
AmountOther = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency != FeeCurrency.RMB_CODE && y.Currency != FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount),
AmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount),
AmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount),
AmountOther = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId && y.Currency != FeeCurrency.RMB_CODE && y.Currency != FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount - y.ProcessedAmount),
//原币金额
OriginalAmountList = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => a.Id == y.ApplicationId)
.GroupBy(y => y.OriginalCurrency).ToList(y => new CurrencyAmount { Currency = y.OriginalCurrency, Amount = SqlFunc.AggregateSum(y.OriginalAmount) })

@ -160,7 +160,7 @@ namespace DS.WMS.Core.Invoice.Method
if (invResult.code == 1)
return await InitiateAsync(ids);
return DataResult.Failed(invResult.msg);
return DataResult.Failed("开票API返回错误" + invResult.msg);
}
}
@ -429,12 +429,12 @@ namespace DS.WMS.Core.Invoice.Method
request.orderNo = blueInvoice.BillNO; //蓝票业务号
var result = await api.PostAsync<InvoiceResult<SetRedConfirmation>>(AppSetting.app(["InvoiceApi", "BaseUrl"]) + "/api/Invoice/RedInvoicing", request);
if (result.Data == null || !result.Data.success)
return DataResult.Failed(result.Data == null ? "请求失败" : result.Data.msg);
return DataResult.Failed(result.Data == null ? "请求失败" : "开票API返回错误" + result.Data.msg);
request.qrlx = "Y";
result = await api.PostAsync<InvoiceResult<SetRedConfirmation>>(AppSetting.app(["InvoiceApi", "BaseUrl"]) + "/api/Invoice/RedInvoicing", request);
if (result.Data == null || !result.Data.success)
return DataResult.Failed(result.Data == null ? "请求失败" : result.Data.msg);
return DataResult.Failed(result.Data == null ? "请求失败" : "开票API返回错误" + result.Data.msg);
await TenantDb.Ado.CommitTranAsync();
var result2 = DataResult.Success;
@ -466,7 +466,7 @@ namespace DS.WMS.Core.Invoice.Method
if (inv == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.EmptyData));
if (!string.IsNullOrEmpty(inv.InvoiceNO))
if (string.IsNullOrEmpty(inv.InvoiceNO))
return DataResult.Failed("发票尚未开出");
//如果开票中所属机构为空,则取用户的orgId
@ -478,7 +478,7 @@ namespace DS.WMS.Core.Invoice.Method
api.DefaultHeaders.Add("USER_SECRET", orgauthinfo.Secret);
var result = await api.PostAsync<InvoiceResult<SetRedConfirmation>>(AppSetting.app(["InvoiceApi", "BaseUrl"]) + "/api/Invoice/InvoiceToEmil", inv);
if (result.Data == null || !result.Data.success)
return DataResult.Failed(result.Data == null ? "请求失败" : result.Data.msg);
return DataResult.Failed(result.Data == null ? "请求失败" : "开票API返回错误" + result.Data.msg);
return DataResult.Success;
}

@ -9,7 +9,6 @@ using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Invoice.Entity;
using DS.WMS.Core.Invoice.Interface;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Sys.Entity;
@ -47,56 +46,38 @@ namespace DS.WMS.Core.Invoice.Method
public async Task<DataResult<InvoiceList>> GetListAsync(PageRequest<NumberQuery> request)
{
var query = TenantDb.Queryable<Entity.Invoice>()
.WhereIF(!string.IsNullOrEmpty(request.OtherQueryCondition?.Number), x =>
.LeftJoin<SysOrg>((i, s) => i.SaleDeptId == s.Id, "shippingweb8_dev.sys_org")
.LeftJoin<SysUser>((i, s, u1) => i.LockUserId == s.Id, "shippingweb8_dev.sys_user")
.LeftJoin<SysUser>((i, s, u1, u2) => i.OperatorId == s.Id, "shippingweb8_dev.sys_user")
.WhereIF(!string.IsNullOrEmpty(request.OtherQueryCondition?.Number), i => i.BillNO.Contains(request.OtherQueryCondition.Number) || i.InvoiceNO.Contains(request.OtherQueryCondition.Number) ||
SqlFunc.Subqueryable<ApplicationDetail>().InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id && f.BusinessType == BusinessType.OceanShippingExport)
.InnerJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id).Where((d, f, s) =>
s.CustomerNo.Contains(request.OtherQueryCondition.Number) || s.BookingNo.Contains(request.OtherQueryCondition.Number) ||
s.MBLNO.Contains(request.OtherQueryCondition.Number) || s.CustomerNum.Contains(request.OtherQueryCondition.Number)).Any())
.Select((i) => new InvoiceDto
.Select((i, s, u1, u2) => new InvoiceDto
{
Details = SqlFunc.Subqueryable<ApplicationDetail>().Where(d => d.ApplicationId == i.Id)
.ToList(d => new ApplicationDetailDto
{
Currency = d.Currency,
ProcessedAmount = d.ProcessedAmount,
ExchangeRate = d.ExchangeRate,
OriginalCurrency = d.OriginalCurrency,
OriginalAmount = d.OriginalAmount,
OriginalProcessedAmount = d.OriginalProcessedAmount
}),
CreateByName = i.CreateUserName,
SaleDeptName = s.OrgName,
LockUserName = u1.UserName,
OperatorName = u2.UserName,
InvoiceApplicationList = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<InvoiceApplication>((d, a) =>
d.ApplicationId == i.Id && d.RefId == a.Id)
.WhereIF(request.OtherQueryCondition != null && !string.IsNullOrEmpty(request.OtherQueryCondition.Number),
(d, a) => a.ApplicationNO.Contains(request.OtherQueryCondition.Number))
.GroupBy((d, a) => a.ApplicationNO).ToList((d, a) => a.ApplicationNO)
//.WhereIF(request.OtherQueryCondition != null && !string.IsNullOrEmpty(request.OtherQueryCondition.Number),
// (d, a) => a.ApplicationNO.Contains(request.OtherQueryCondition.Number))
.GroupBy((d, a) => a.ApplicationNO).ToList((d, a) => a.ApplicationNO),
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.RMB_CODE)
.Sum((d1, d2) => d1.ApplyAmount),
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.USD_CODE)
.Sum((d1, d2) => d1.ApplyAmount)
}, true).MergeTable();
//if (!string.IsNullOrEmpty(request.OtherQueryCondition?.Number))
// query = query.Where(i => i.InvoiceNO.Contains(request.OtherQueryCondition.Number) || i.BillNO.Contains(request.OtherQueryCondition.Number));
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)
.Union(result.Data.Where(x => x.LockUserId.HasValue).Select(x => x.LockUserId.Value))
.Union(result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value))
.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.Value)
.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.LockUserName = users.Find(x => x.Id == item.LockUserId)?.UserName;
item.OperatorName = users.Find(x => x.Id == item.OperatorId)?.UserName;
item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName;
}
}
InvoiceList list = new() { List = result.Data };
@ -113,11 +94,25 @@ namespace DS.WMS.Core.Invoice.Method
public async Task<DataResult<InvoiceDto>> GetAsync(long id)
{
var invoice = await TenantDb.Queryable<Entity.Invoice>()
.LeftJoin<Entity.Invoice>((x, y) => x.RedId == y.Id)
.Select((x, y) => new InvoiceDto
.LeftJoin<Entity.Invoice>((i, ri) => i.RedId == ri.Id)
.LeftJoin<SysOrg>((i, ri, s) => i.SaleDeptId == s.Id, "shippingweb8_dev.sys_org")
.LeftJoin<SysUser>((i, ri, s, u1) => i.LockUserId == s.Id, "shippingweb8_dev.sys_user")
.LeftJoin<SysUser>((i, ri, s, u1, u2) => i.OperatorId == s.Id, "shippingweb8_dev.sys_user")
.Select((i, ri, s, u1, u2) => new InvoiceDto
{
RedNO = y.InvoiceNO
}, true).FirstAsync(x => x.Id == id);
RedNO = ri.InvoiceNO,
CreateByName = i.CreateUserName,
SaleDeptName = s.OrgName,
LockUserName = u1.UserName,
OperatorName = u2.UserName,
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.RMB_CODE)
.Sum((d1, d2) => d1.ApplyAmount),
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().LeftJoin<ApplicationDetail>((d1, d2) =>
d1.Id == d2.DetailId).Where((d1, d2) => d2.ApplicationId == i.Id && d1.Currency == FeeCurrency.USD_CODE)
.Sum((d1, d2) => d1.ApplyAmount)
}, true).FirstAsync(i => i.Id == id);
if (invoice != null)
{
if (!string.IsNullOrEmpty(invoice.PushMode))
@ -126,12 +121,6 @@ namespace DS.WMS.Core.Invoice.Method
.Select(x => (PushMode)int.Parse(x)).ToArray();
}
if (invoice.OperatorId.HasValue)
{
invoice.OperatorName = await Db.Queryable<SysUser>().Where(x => x.Id == invoice.OperatorId.Value)
.Select(x => x.UserName).FirstAsync();
}
invoice.Details = await CreateApplicationDetailQuery((d, f, s) => d.ApplicationId == id && d.Category == DetailCategory.InvoiceIssuance)
.Select(x => new ApplicationDetailDto
{
@ -156,8 +145,7 @@ namespace DS.WMS.Core.Invoice.Method
SourceName = x.SourceName,
LoadPort = x.LoadPort,
Vessel = x.Vessel,
Voyage = x.Voyage,
Voyage = x.Voyage
}).ToListAsync();
invoice.Summary = invoice.Details.GroupBy(x => new { x.FeeType, x.Currency }).Select(x => new SummaryItem
@ -171,8 +159,7 @@ namespace DS.WMS.Core.Invoice.Method
{
var ids = invoice.Details.Where(x => x.RefId.HasValue).Select(x => x.RefId).Distinct();
invoice.Applications = await TenantDb.Queryable<InvoiceApplication>().Where(x => ids.Contains(x.Id))
.LeftJoin<SysUser>((x, y) => x.CreateBy == y.Id, "shippingweb8_dev.sys_user")
.Select((x, y) => new InvoiceApplicationDto
.Select(x => new InvoiceApplicationDto
{
Id = x.Id,
ApplicationNO = x.ApplicationNO,
@ -180,7 +167,7 @@ namespace DS.WMS.Core.Invoice.Method
Currency = x.Currency,
InvoiceRemark = x.InvoiceRemark,
CreateBy = x.CreateBy,
CreateByName = y.UserName,
CreateByName = x.CreateUserName,
ApplyAmountRMB = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.RMB_CODE).Sum(y => y.ApplyAmount),
ApplyAmountUSD = SqlFunc.Subqueryable<ApplicationDetail>().Where(y => x.Id == y.ApplicationId && y.Currency == FeeCurrency.USD_CODE).Sum(y => y.ApplyAmount)
}).ToListAsync();
@ -480,11 +467,7 @@ namespace DS.WMS.Core.Invoice.Method
}
if (!string.IsNullOrEmpty(invRemark))
{
invoice.Note += Environment.NewLine + invRemark;
invoice.InvoiceRemark += Environment.NewLine + invRemark;
}
}
//筛选出新增的费用明细
@ -627,8 +610,15 @@ namespace DS.WMS.Core.Invoice.Method
if (detail.Currency == currency)
{
if (detail.Currency == detail.OriginalCurrency)
{
detail.OriginalAmount = detail.ApplyAmount;
}
else
{
detail.OriginalAmount = detail.ApplyAmount / detail.ExchangeRate.Value;
}
detail.ExchangeRate = 1;
detail.OriginalAmount = detail.ApplyAmount;
}
else //开票币别与费用币别不一致
{
@ -738,19 +728,13 @@ namespace DS.WMS.Core.Invoice.Method
foreach (var invoice in invoices)
{
var currDetails = details.FindAll(x => x.ApplicationId == invoice.Id);
invoice.ApplyAmount = currDetails.Sum(x => x.ApplyAmount);
invoice.AmountUppercase = new Money(invoice.ApplyAmount).ToString();
invoice.OriginalAmount = currDetails.Sum(x => x.OriginalAmount);
invoice.OtherInvoiceAmount = currDetails.FindAll(x => x.Currency != FeeCurrency.RMB_CODE).Sum(x => x.OriginalAmount);
invoice.InvoiceAmount = invDetails.FindAll(x => x.ApplicationId == invoice.Id).Sum(x => x.Amount);
}
return await TenantDb.Updateable(invoices).UpdateColumns(x => new
{
x.ApplyAmount,
x.AmountUppercase,
x.OriginalAmount,
x.OtherInvoiceAmount,
x.InvoiceAmount
@ -995,15 +979,8 @@ namespace DS.WMS.Core.Invoice.Method
{
//重新设置申请明细与总金额
item.Details = details.FindAll(x => x.ApplicationId == item.Id);
item.ApplyAmount = item.Details.Sum(x => x.ApplyAmount);
item.AmountUppercase = new Money(item.ApplyAmount).ToString();
//item.InvoiceAmount = item.InvoiceDetails.Sum(x => x.Amount);
}
await TenantDb.Updateable(invoices).UpdateColumns(x => new
{
x.ApplyAmount,
x.AmountUppercase
}).ExecuteCommandAsync();
}
else if (deleteOption == DeleteOption.Entire)
{

@ -45,11 +45,6 @@ namespace DS.WMS.Core.Settlement.Dtos
/// </summary>
public decimal SettlementAmount { get; set; }
/// <summary>
/// 发票申请金额
/// </summary>
public decimal InvoiceApplyAmount { get; set; }
/// <summary>
/// 发票开票金额
/// </summary>

@ -205,10 +205,10 @@ namespace DS.WMS.Core.Settlement.Method
.Select((i, d1, d2) => new SettlementDetailGroup
{
Id = i.Id,
InvoiceApplyAmount = i.ApplyAmount,
InvoiceAmount = i.InvoiceAmount,
SettlementAmount = SqlFunc.Subqueryable<ApplicationDetail>().Where(d3 => d3.ApplicationId == i.Id).Sum(d3 => d3.ApplyAmount),
ApplicationNOList = SqlFunc.Subqueryable<InvoiceApplication>().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO)
ApplicationNOList = SqlFunc.Subqueryable<InvoiceApplication>().Where(a => a.Id == d1.RefId).ToList(a => a.ApplicationNO),
}, true).ToListAsync();
return list;

@ -70,8 +70,15 @@ namespace DS.WMS.Core.Settlement.Method
if (detail.Currency == currency)
{
if (detail.Currency == detail.OriginalCurrency)
{
detail.OriginalAmount = detail.ApplyAmount;
}
else
{
detail.OriginalAmount = detail.ApplyAmount / detail.ExchangeRate.Value;
}
detail.ExchangeRate = 1;
detail.OriginalAmount = detail.ApplyAmount;
}
else //结算币别与费用币别不一致
{

Loading…
Cancel
Save