|
|
@ -316,32 +316,20 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
Currency = invoice.Currency,
|
|
|
|
Currency = invoice.Currency,
|
|
|
|
OriginalCurrency = item.Currency,
|
|
|
|
OriginalCurrency = item.Currency,
|
|
|
|
ApplyAmount = item.ApplyAmount - item.ProcessedAmount,
|
|
|
|
ApplyAmount = item.ApplyAmount - item.ProcessedAmount,
|
|
|
|
OriginalAmount = item.OriginalAmount - item.OriginalProcessedAmount
|
|
|
|
OriginalAmount = item.OriginalAmount - item.OriginalProcessedAmount,
|
|
|
|
|
|
|
|
ExchangeRate = 1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var app = request.Applications.Find(x => x.ApplicationId == item.ApplicationId);
|
|
|
|
var app = request.Applications.Find(x => x.ApplicationId == item.ApplicationId);
|
|
|
|
if (app != null)
|
|
|
|
if (app != null) //设置汇率
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (app.Currency == invoice.Currency)
|
|
|
|
var er = app.ExchangeRates?.FirstOrDefault(x => x.Currency == detail.OriginalCurrency);
|
|
|
|
|
|
|
|
if (er != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
detail.ExchangeRate = er.ExchangeRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (string.IsNullOrEmpty(app.Currency)) //原币申请
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(x => x.Currency == item.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
detail.ExchangeRate = app.ExchangeRates.FirstOrDefault(x => x.Currency == invoice.Currency)?.ExchangeRate;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!detail.ExchangeRate.HasValue)
|
|
|
|
|
|
|
|
detail.ExchangeRate = 1m;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (detail.ExchangeRate.HasValue)
|
|
|
|
|
|
|
|
detail.ApplyAmount *= detail.ExchangeRate.Value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
invoice.Details.Add(detail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -598,20 +586,22 @@ namespace DS.WMS.Core.Invoice.Method
|
|
|
|
if (invoiceAmount == 0)
|
|
|
|
if (invoiceAmount == 0)
|
|
|
|
return DataResult.Failed("开票金额不能为零");
|
|
|
|
return DataResult.Failed("开票金额不能为零");
|
|
|
|
|
|
|
|
|
|
|
|
var totalRMB = details.Sum(x => x.ApplyAmount);
|
|
|
|
var totalAmount = details.Sum(x => x.OriginalAmount);
|
|
|
|
if (Math.Abs(invoiceAmount) > totalRMB)
|
|
|
|
if (Math.Abs(invoiceAmount) > totalAmount)
|
|
|
|
return DataResult.Failed("申请开票金额不能大于剩余开票金额");
|
|
|
|
return DataResult.Failed("申请开票金额不能大于剩余开票金额");
|
|
|
|
|
|
|
|
|
|
|
|
if (totalRMB != invoiceAmount) //非全额开票
|
|
|
|
if (totalAmount != invoiceAmount) //非全额开票
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var rest = totalRMB - invoiceAmount;
|
|
|
|
var rest = totalAmount - invoiceAmount;
|
|
|
|
foreach (var detail in details)
|
|
|
|
foreach (var detail in details)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (rest == 0)
|
|
|
|
if (rest == 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
detail.ApplyAmount = detail.ApplyAmount - rest;
|
|
|
|
detail.OriginalAmount = detail.OriginalAmount - rest;
|
|
|
|
rest = detail.ApplyAmount - rest;
|
|
|
|
rest = detail.OriginalAmount - rest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detail.ApplyAmount = detail.OriginalAmount * detail.ExchangeRate.GetValueOrDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|