结算增加机构银行ID

dev
嵇文龙 1 month ago
parent 10edf0066e
commit 839a10cc52

@ -705,6 +705,9 @@ public static class MultiLanguageConst
[Description("税率不一致,禁止提交")]
public const string InconsistentTaxRates= "Inconsistent_Tax_Rates";
[Description("发票或其明细已进入结算流程,请先取消结算后再删除")]
public const string InvoiceIsSettled = "Invoice_Is_Settled";
#endregion
#region 预订舱API

@ -51,6 +51,11 @@ namespace DS.WMS.Core.Application.Dtos
/// </summary>
public long CustomerId { get; set; }
/// <summary>
/// 费用对象名称
/// </summary>
public string? CustomerName { get; set; }
/// <summary>
/// 汇率信息
/// </summary>

@ -1,8 +1,7 @@
using DS.WMS.Core.Application.Dtos;
using System.Linq.Expressions;
using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Entity;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Fee.Entity;
using System.Linq.Expressions;
using DS.WMS.Core.Fee.Method;
using DS.WMS.Core.Op.Entity;
using SqlSugar;
@ -35,8 +34,7 @@ namespace DS.WMS.Core.Application.Method
.InnerJoin<FeeRecord>((d, f) => d.RecordId == f.Id)
.LeftJoin<SeaExport>((d, f, s) => f.BusinessId == s.Id && f.BusinessType == BusinessType.OceanShippingExport)
.WhereIF(expr1 != null, expr1)
.LeftJoin<CodeSource>((d, f, s, cs) => s.SourceId == cs.Id)
.Select((d, f, s, cs) => new ApplicationDetailDto
.Select((d, f, s) => new ApplicationDetailDto
{
//---------------明细表--------------
Id = d.Id,
@ -45,7 +43,6 @@ namespace DS.WMS.Core.Application.Method
RefId = d.RefId,
RecordId = d.RecordId,
FeeType = d.FeeType,
CustomerName = d.CustomerName,
FeeId = d.FeeId,
FeeName = d.FeeName,
Currency = d.Currency,
@ -60,30 +57,30 @@ namespace DS.WMS.Core.Application.Method
Amount = f.Amount,
AccTaxRate = f.AccTaxRate,
CustomerId = f.CustomerId,//费用对象ID
CustomerName = f.CustomerName,
OrderAmount = f.OrderAmount,
InvoiceAmount = f.InvoiceAmount,
SettlementAmount = f.SettlementAmount,
OrderSettlementAmount = f.OrderSettlementAmount,
OrderInvSettlementAmount = f.OrderInvSettlementAmount,
BusinessId = f.BusinessId,
BusinessType = f.BusinessType,
//---------------业务表--------------
BusinessId = s.Id,
BusinessType = BusinessType.OceanShippingExport,
AccountDate = s.AccountDate,
CntrTotal = s.CntrTotal,
CustomerNo = s.CustomerNo,
ClientName = s.CustomerName, //委托单位
//DischargePort = s.DischargePort,
ETD = s.ETD,
HBLNO = s.HBLNO,
LoadPort = s.LoadPort,
//DischargePort = s.DischargePort,
MBLNO = s.MBLNO,
SaleDeptId = s.SaleDeptId,
SaleName = s.Sale,//揽货人
Vessel = s.Vessel,//船名
Voyage = s.Voyno,//航次
BookingNo = s.BookingNo,
//---------------附加表--------------
SourceName = cs.SourceName
SourceName = s.SourceName
});
//海运进口

@ -105,12 +105,15 @@ namespace DS.WMS.Core.Invoice.Method
OriginalCurrency = x.OriginalCurrency, //原始币别
ExchangeRate = x.ExchangeRate, //折算汇率
OriginalAmount = x.OriginalAmount, //原始金额
SaleName = x.SaleName,
CustomerNo = x.CustomerNo,
MBLNO = x.MBLNO,
HBLNO = x.HBLNO,
SaleName = x.SaleName,
ClientName = x.ClientName,
ETD = x.ETD,
SourceName = x.SourceName,
AuditTime = y.AuditTime
}).ToListAsync();
@ -146,7 +149,7 @@ namespace DS.WMS.Core.Invoice.Method
protected override Task PostSaveAsync(Entity.Invoice invoice)
{
return Task.Factory.StartNew(UpdateInvoiceApplications, new List<Entity.Invoice> { invoice });
return RefreshApplicationStatus([invoice], null);
}
protected override async Task OnDeleteDetailAsync(List<Entity.Invoice> invoices, DeleteOption deleteOption)
@ -205,42 +208,59 @@ namespace DS.WMS.Core.Invoice.Method
protected override Task PostDeleteAsync(List<Entity.Invoice> invoices, DeleteOption deleteOption)
{
return Task.Factory.StartNew(UpdateInvoiceApplications, invoices);
////获取关联的发票申请的ID
//var ids = invoices.SelectMany(x => x.Details).Where(x => x.RefId.HasValue).Select(x => x.RefId.GetValueOrDefault()).Distinct();
//if (deleteOption == DeleteOption.Entire)
//{
// return TenantDb.Updateable<InvoiceApplication>()
// .SetColumns(x => x.Status == InvoiceApplicationStatus.AuditPassed)
// .Where(x => ids.Contains(x.Id))
// .ExecuteCommandAsync();
//}
//else if (deleteOption == DeleteOption.DetailOnly)
//{
// //获取关联的发票申请的明细ID
// var ids2 = invoices.SelectMany(x => x.Details).Where(x => x.DetailId.HasValue).Select(x => x.DetailId.GetValueOrDefault()).Distinct();
//}
//return Task.CompletedTask;
return RefreshApplicationStatus(invoices, deleteOption);
}
//更新发票申请的状态
void UpdateInvoiceApplications(object? state)
private async Task RefreshApplicationStatus(List<Entity.Invoice> invoices, DeleteOption? deleteOption)
{
var list = state as IEnumerable<Entity.Invoice>;
if (list == null || !list.Any())
if (invoices == null || !invoices.Any())
return;
var ids = list.SelectMany(x => x.Details).Where(x => x.RefId.HasValue).Select(x => x.RefId.GetValueOrDefault()).Distinct().ToList();
var appDetails = TenantDb.Queryable<ApplicationDetail>().Where(d => ids.Contains(d.ApplicationId))
//获取关联的发票申请的ID
var ids = invoices.SelectMany(x => x.Details).Where(x => x.RefId.HasValue).Select(x => x.RefId.GetValueOrDefault()).Distinct().ToList();
var appDetails = await TenantDb.Queryable<ApplicationDetail>().Where(d => ids.Contains(d.ApplicationId))
.Select(d => new ApplicationDetail
{
Id = d.Id,
Category = d.Category,
ApplicationId = d.ApplicationId,
OriginalAmount = d.OriginalAmount,
OriginalProcessedAmount = d.OriginalProcessedAmount
}).ToList();
}).ToListAsync();
List<InvoiceApplication> list2 = new(ids.Count);
foreach (var id in ids)
{
var entity = new InvoiceApplication { Id = id };
var inv = list.FirstOrDefault(x => x.Details.Any(y => y.RefId == id));
entity.AcutalInvoiceNO = inv?.InvoiceNO;
var details = appDetails.FindAll(x => x.ApplicationId == id);
if (details.All(x => x.OriginalAmount == x.OriginalAmount - x.OriginalProcessedAmount))
{
entity.Status = InvoiceApplicationStatus.Invoiced;
entity.Status = deleteOption.HasValue ? InvoiceApplicationStatus.AuditPassed : InvoiceApplicationStatus.Invoiced;
list2.Add(entity);
}
else if (details.All(x => x.OriginalAmount - x.OriginalProcessedAmount == 0))
{
entity.Status = InvoiceApplicationStatus.AuditPassed;
entity.Status = deleteOption == null ? InvoiceApplicationStatus.Invoiced : InvoiceApplicationStatus.AuditPassed;
list2.Add(entity);
}
else if (details.Exists(x => x.OriginalAmount != x.OriginalAmount - x.OriginalProcessedAmount))
@ -250,7 +270,8 @@ namespace DS.WMS.Core.Invoice.Method
}
}
TenantDb.Updateable(list2).UpdateColumns(x => new { x.Status, x.AcutalInvoiceNO }).ExecuteCommand();
await TenantDb.Updateable(list2).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
}
}
}

@ -9,13 +9,11 @@ using DS.WMS.Core.Fee.Entity;
using DS.WMS.Core.Info.Entity;
using DS.WMS.Core.Invoice.Dtos;
using DS.WMS.Core.Invoice.Interface;
using DS.WMS.Core.Settlement.Entity;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.Sys.Interface;
using LanguageExt.Pretty;
using Mapster;
using Masuit.Tools.Models;
using Microsoft.Extensions.DependencyInjection;
using Org.BouncyCastle.Asn1.Cmp;
using SqlSugar;
namespace DS.WMS.Core.Invoice.Method
@ -227,7 +225,8 @@ namespace DS.WMS.Core.Invoice.Method
if (invoice.PushModeValues.Length > 0)
invoice.PushMode = string.Join(",", invoice.PushModeValues.Select(x => (int)x));
if (request.Invoice.Mode == InvoiceMode.Applcation && request.Applications != null && request.Applications.Count > 0) //按发票申请开出
//按申请开票
if (request.Invoice.Mode == InvoiceMode.Applcation && request.Applications?.Count > 0)
{
var ids = request.Applications.Select(x => x.ApplicationId);
var details = await TenantDb.Queryable<ApplicationDetail>()
@ -339,21 +338,36 @@ namespace DS.WMS.Core.Invoice.Method
invoice.Details.Add(detail);
}
DataResult result2;
//执行开票金额分配
foreach (var app in request.Applications)
{
var details2 = invoice.Details.Where(x => x.RefId == app.ApplicationId).OrderBy(x => x.ApplyAmount).ToList();
if (app.AmountRMB.HasValue)
{
result2 = AssignAmount(details2.FindAll(x => x.OriginalCurrency == FeeCurrency.RMB_CODE), app.AmountRMB.Value);
if (!result2.Succeeded)
return DataResult<TEntity>.Failed(result2.Message, result2.MultiCode);
}
if (app.AmountUSD.HasValue)
{
result2 = AssignAmount(details2.FindAll(x => x.OriginalCurrency == FeeCurrency.USD_CODE), app.AmountUSD.Value);
if (!result2.Succeeded)
return DataResult<TEntity>.Failed(result2.Message, result2.MultiCode);
}
////执行开票金额分配
//foreach (var app in request.Applications)
//{
// var details2 = invoice.Details.Where(x => x.RefId == app.ApplicationId).OrderBy(x => x.ApplyAmount).ToList();
// if (app.AmountRMB.HasValue)
// {
// var result2 = AssignAmount(details2.FindAll(x => x.OriginalCurrency == FeeCurrency.RMB_CODE), app.AmountRMB.Value);
// if (!result2.Succeeded)
// return DataResult<TEntity>.Failed(result2.Message, result2.MultiCode);
// }
if (app.AmountOther.HasValue)
{
result2 = AssignAmount(details2.FindAll(x => x.OriginalCurrency != FeeCurrency.RMB_CODE && x.OriginalCurrency != FeeCurrency.USD_CODE), app.AmountOther.Value);
if (!result2.Succeeded)
return DataResult<TEntity>.Failed(result2.Message, result2.MultiCode);
}
//}
}
}
else if (request.Invoice.Mode == InvoiceMode.Free) //自由开票
//自由开票
else if (request.Invoice.Mode == InvoiceMode.Free)
{
if (request.BizList?.Count > 0)
{
@ -409,32 +423,32 @@ namespace DS.WMS.Core.Invoice.Method
OriginalAmount = x.OriginalAmount,
OriginalCurrency = x.OriginalCurrency ?? (invoice.Currency.IsNullOrEmpty() ? x.Currency : invoice.Currency),
}).ToList();
//补充购方信息
invoice.CustomerTaxID = await TenantDb.Queryable<InfoClient>().Where(x => x.Id == invoice.CustomerId).Select(x => x.TaxNo).FirstAsync();
var header = await TenantDb.Queryable<InvoiceHeader>().Where(x => x.RelativeId == invoice.CustomerId)
.OrderByDescending(x => x.Id).FirstAsync();
if (header != null)
{
invoice.InvoiceHeader = header.Header;
invoice.CustomerAddressTel = header.AddressTel;
}
var clientBank = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == invoice.CustomerId && x.Currency == invoice.Currency)
.OrderByDescending(x => x.IsInvoiceDefault).Select(x => new
{
x.Account,
x.BankName
}).FirstAsync();
if (clientBank != null)
{
invoice.CustomerAccount = clientBank.Account;
invoice.CustomerBankName = clientBank.BankName;
}
}
}
if (invoice.Id == 0)
{
//补充购方信息
invoice.CustomerTaxID = await TenantDb.Queryable<InfoClient>().Where(x => x.Id == invoice.CustomerId).Select(x => x.TaxNo).FirstAsync();
var header = await TenantDb.Queryable<InvoiceHeader>().Where(x => x.RelativeId == invoice.CustomerId)
.OrderByDescending(x => x.Id).FirstAsync();
if (header != null)
{
invoice.InvoiceHeader = header.Header;
invoice.CustomerAddressTel = header.AddressTel;
}
var clientBank = await TenantDb.Queryable<InfoClientBank>().Where(x => x.ClientId == invoice.CustomerId && x.Currency == invoice.Currency)
.OrderByDescending(x => x.IsInvoiceDefault).Select(x => new
{
x.Account,
x.BankName
}).FirstAsync();
if (clientBank != null)
{
invoice.CustomerAccount = clientBank.Account;
invoice.CustomerBankName = clientBank.BankName;
}
//补充销方信息
var org = await Db.Queryable<SysOrg>().Where(x => x.Id == User.OrgId).Select(x => new { x.OrgFullName, x.LicenseCode }).FirstAsync();
if (org != null)
@ -877,6 +891,10 @@ namespace DS.WMS.Core.Invoice.Method
if (invoices.Any(x => !string.IsNullOrEmpty(x.ApiCode)))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsIssued));
var ids = invoices.Select(x => x.Id);
if (TenantDb.Queryable<ApplicationDetail>().Any(x => ids.Contains(x.RefId.Value) && x.Category == DetailCategory.InvoiceSettlement))
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsSettled));
return DataResult.Success;
}
@ -888,12 +906,12 @@ namespace DS.WMS.Core.Invoice.Method
/// <returns></returns>
protected virtual async Task OnDeleteDetailAsync(List<TEntity> invoices, DeleteOption deleteOption)
{
var appIds = invoices.Select(x => x.Id);
var ids = invoices.Select(x => x.Id);
if (deleteOption == DeleteOption.DetailOnly)
{
var excludeIds = invoices.SelectMany(x => x.Details).Select(x => x.Id);
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && !excludeIds.Contains(x.Id))
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => ids.Contains(x.ApplicationId) && !excludeIds.Contains(x.Id))
.Select(x => new ApplicationDetail
{
Id = x.Id,
@ -919,7 +937,7 @@ namespace DS.WMS.Core.Invoice.Method
else if (deleteOption == DeleteOption.Entire)
{
//删除发票主表则同时删除对应发票明细
await TenantDb.Deleteable<InvoiceDetail>().Where(x => appIds.Contains(x.ApplicationId)).ExecuteCommandAsync();
await TenantDb.Deleteable<InvoiceDetail>().Where(x => ids.Contains(x.ApplicationId)).ExecuteCommandAsync();
}
foreach (var item in invoices)

@ -89,9 +89,9 @@ namespace DS.WMS.Core.Settlement.Dtos
public string BillTypeText => BillType.GetDescription();
/// <summary>
/// 结算银行账户
/// 机构银行ID
/// </summary>
public string? Account { get; set; }
public long? OrgBankId { get; set; }
/// <summary>
/// 结算业务类别

@ -6,7 +6,7 @@ namespace DS.WMS.Core.Settlement.Entity
/// <summary>
/// 结算表
/// </summary>
[SugarTable("application_payment_settlement", TableDescription = "结算表")]
[SugarTable("application_settlement", TableDescription = "结算表")]
public class ApplicationSettlement : SettlementBase
{
/// <summary>

@ -53,10 +53,10 @@ namespace DS.WMS.Core.Settlement.Entity
public decimal Amount { get; set; }
/// <summary>
/// 结算银行账户
/// 机构银行账户ID
/// </summary>
[SugarColumn(ColumnDescription = "结算银行账户", Length = 50, IsNullable = true)]
public string? Account { get; set; }
[SugarColumn(ColumnDescription = "机构银行账户ID", IsNullable = true)]
public long? OrgBankId { get; set; }
/// <summary>
/// 结算业务类别

@ -44,6 +44,6 @@ namespace DS.WMS.Core.Settlement.Interface
/// </summary>
/// <param name="items">业务ID与业务类型</param>
/// <returns></returns>
Task<DataResult<List<FeeClient>>> GetCurrenciesAsync(params FeeClient[] items);
Task<DataResult<List<FeeClient>>> GetCurrenciesAsync(List<FeeClient> items);
}
}

@ -187,7 +187,7 @@ namespace DS.WMS.Core.Settlement.Method
/// </summary>
/// <param name="items">业务ID与业务类型</param>
/// <returns></returns>
public async Task<DataResult<List<FeeClient>>> GetCurrenciesAsync(params FeeClient[] items)
public async Task<DataResult<List<FeeClient>>> GetCurrenciesAsync(List<FeeClient> items)
{
var bizIds = items.Select(x => x.Id).Distinct();
var types = items.Select(x => x.BusinessType).Distinct();
@ -205,19 +205,17 @@ namespace DS.WMS.Core.Settlement.Method
f.ExchangeRate
}).ToListAsync();
var currencies = list.GroupBy(x => new { x.BusinessId, x.BusinessType, x.CustomerId }).Select(x => new FeeClient
foreach (var item in items)
{
Id = x.Key.BusinessId,
BusinessType = x.Key.BusinessType,
CustomerId = x.Key.CustomerId,
ExchangeRates = x.GroupBy(y => y.Currency).Select(y => new CurrencyExchangeRate
{
Currency = y.Key,
ExchangeRate = x.Where(z => z.Currency == y.Key).Select(z => z.ExchangeRate).FirstOrDefault()
}).ToList()
}).ToList();
item.ExchangeRates = list.Where(x => x.BusinessId == item.Id && x.BusinessType == item.BusinessType && x.CustomerId == item.CustomerId)
.GroupBy(x => x.Currency).Select(x => new CurrencyExchangeRate
{
Currency = x.Key,
ExchangeRate = x.First().ExchangeRate
}).ToList();
}
return DataResult<List<FeeClient>>.Success(currencies);
return DataResult<List<FeeClient>>.Success(items);
}
/// <summary>
@ -229,46 +227,10 @@ namespace DS.WMS.Core.Settlement.Method
{
var model = await TenantDb.Queryable<ApplicationSettlement>().Select(x => new ApplicationSettlementDto
{
Id = x.Id,
ApplicationNO = x.ApplicationNO, //申请编号
SettlementNO = x.SettlementNO, //结算单号
CustomerId = x.CustomerId, //结算单位
CustomerName = x.CustomerName,
Mode = x.Mode, //结算类型
SettlementDate = x.SettlementDate, //结算日期
SettlementTypeId = x.SettlementTypeId, //结算方式
CustomerBankId = x.CustomerBankId, //客户银行
Account = x.Account, //客户账户
Currency = x.Currency, //币别
Amount = x.Amount, //金额
ExchangeRate = x.ExchangeRate, //汇率
IsLocked = x.IsLocked, //锁定状态
SaleDeptId = x.SaleDeptId, //所属分部
BillType = x.BillType, //单据类型
Category = x.Category, //业务类别
LedgerVoucherNO = x.LedgerVoucherNO, //总账凭证号
RelativeNO = x.RelativeNO, //相关号码
InvoiceAmount = x.InvoiceAmount,
InvoiceDate = x.InvoiceDate,
InvoiceNO = x.InvoiceNO,
Note = x.Note, //备注
AccountAmount = x.AccountAmount, //记账资料
AccountCurrency = x.AccountCurrency,
AccountRate = x.AccountRate,
PrePayAmount = x.PrePayAmount, //预付支资料
PrePayCurrency = x.PrePayCurrency,
PrePayRate = x.PrePayRate,
AHSRAmount = x.AHSRAmount, //实收支资料
AHSRCurrency = x.AHSRCurrency,
AHSRRate = x.AHSRRate,
FinancialAmount = x.FinancialAmount,//财务费用
FinancialCurrency = x.FinancialCurrency,
FinancialRate = x.FinancialRate,
AdvanceAmount = x.AdvanceAmount, //预收支资料
AdvanceCurrency = x.AdvanceCurrency,
AdvanceRate = x.AdvanceRate,
}).FirstAsync(x => x.Id == id && x.Mode == SettlementMode.FreeSettlement);
SettlementTypeName = x.SettlementType.StlName, //结算方式
CustomerBankName = x.CustomerBank.BankName,
CustomerAccount = x.CustomerBank.Account
}, true).FirstAsync(x => x.Id == id && x.Mode == SettlementMode.FreeSettlement);
var templist = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == id).ToListAsync();

@ -88,7 +88,7 @@ namespace DS.WMS.FeeApi.Controllers
/// <param name="items">业务ID与业务类型</param>
/// <returns></returns>
[HttpPost, Route("GetCurrencies")]
public async Task<DataResult<List<FeeClient>>> GetCurrenciesAsync([FromBody] FeeClient[] items)
public async Task<DataResult<List<FeeClient>>> GetCurrenciesAsync([FromBody] List<FeeClient> items)
{
return await _service.GetCurrenciesAsync(items);
}

Loading…
Cancel
Save