|
|
|
@ -203,6 +203,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
var custIds = request.Documents.Select(x => x.CustomerId);
|
|
|
|
|
details1 = await TenantDb.Queryable<FeeRecord>().Where(f => ids.Contains(f.BusinessId) && types.Contains(f.BusinessType) && custIds.Contains(f.CustomerId) &&
|
|
|
|
|
(f.FeeStatus == FeeStatus.AuditPassed || f.FeeStatus == FeeStatus.PartialSettlement) && (f.Amount - f.SettlementAmount - f.OrderAmount + f.OrderSettlementAmount) != 0)
|
|
|
|
|
.Where(request.GetConditionalModels(Db))
|
|
|
|
|
.Select(f => new ApplicationDetail
|
|
|
|
|
{
|
|
|
|
|
ApplicationId = settlement.Id,
|
|
|
|
@ -322,7 +323,7 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
if (settlement.Details.Exists(x => x.OriginalCurrency.IsNullOrEmpty()))
|
|
|
|
|
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.OriginalCurrencyCanNotNull));
|
|
|
|
|
|
|
|
|
|
settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
//settlement.Amount = settlement.Details.Sum(x => x.ApplyAmount);
|
|
|
|
|
result = await PreSaveAsync(settlement);
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
return DataResult<TEntity>.Failed(result.Message, result.MultiCode);
|
|
|
|
@ -379,6 +380,11 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//重新计算结算总金额
|
|
|
|
|
settlement.Amount = await TenantDb.Queryable<ApplicationDetail>().Where(x => x.ApplicationId == settlement.Id)
|
|
|
|
|
.SumAsync(x => x.ApplyAmount);
|
|
|
|
|
await TenantDb.Updateable(settlement).UpdateColumns(x => x.Amount).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await TenantDb.Ado.CommitTranAsync();
|
|
|
|
|
await PostSaveAsync(settlement);
|
|
|
|
|
return DataResult<TEntity>.Success(settlement);
|
|
|
|
@ -585,6 +591,112 @@ namespace DS.WMS.Core.Settlement.Method
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新费用及其业务的结算状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">费用记录ID</param>
|
|
|
|
|
/// <remarks>此方法内部将始终异步执行,请确保在调用前已提交数据库事务等必要的操作。</remarks>
|
|
|
|
|
protected internal void UpdateFeeStatus(IEnumerable<long> ids)
|
|
|
|
|
{
|
|
|
|
|
var task1 = Task.Factory.StartNew(UpdateFeeStatusCore, ids, CancellationToken.None);
|
|
|
|
|
task1.ContinueWith(t => UpdateBizStatusCore(t.Result), TaskContinuationOptions.OnlyOnRanToCompletion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<FeeRecord> UpdateFeeStatusCore(object? state)
|
|
|
|
|
{
|
|
|
|
|
if (state == null)
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
var ids = (IEnumerable<long>)state;
|
|
|
|
|
var fees = TenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id))
|
|
|
|
|
.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
BusinessId = x.BusinessId,
|
|
|
|
|
BusinessType = x.BusinessType,
|
|
|
|
|
FeeStatus = x.FeeStatus,
|
|
|
|
|
Amount = x.Amount,
|
|
|
|
|
SettlementAmount = x.SettlementAmount,
|
|
|
|
|
OrderAmount = x.OrderAmount,
|
|
|
|
|
OrderSettlementAmount = x.OrderSettlementAmount
|
|
|
|
|
}).ToList();
|
|
|
|
|
if (fees.Count == 0)
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
List<FeeRecord> list = new(fees.Count);
|
|
|
|
|
foreach (var item in fees)
|
|
|
|
|
{
|
|
|
|
|
var restAmount = item.Amount - item.SettlementAmount - item.OrderAmount + item.OrderSettlementAmount;
|
|
|
|
|
if (restAmount == 0)
|
|
|
|
|
{
|
|
|
|
|
item.FeeStatus = FeeStatus.SettlementCompleted;
|
|
|
|
|
list.Add(item);
|
|
|
|
|
}
|
|
|
|
|
else if (restAmount != item.Amount)
|
|
|
|
|
{
|
|
|
|
|
item.FeeStatus = FeeStatus.PartialSettlement;
|
|
|
|
|
list.Add(item);
|
|
|
|
|
}
|
|
|
|
|
else if (restAmount == item.Amount)
|
|
|
|
|
{
|
|
|
|
|
item.FeeStatus = FeeStatus.AuditPassed;
|
|
|
|
|
list.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
TenantDb.Updateable(list).UpdateColumns(x => new { x.FeeStatus }).ExecuteCommand();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBizStatusCore(List<FeeRecord> list)
|
|
|
|
|
{
|
|
|
|
|
var bizIds = list.Select(x => x.BusinessId);
|
|
|
|
|
var types = list.Select(x => x.BusinessType).Distinct();
|
|
|
|
|
var fees2 = TenantDb.Queryable<FeeRecord>().Where(x => bizIds.Contains(x.BusinessId) && types.Contains(x.BusinessType))
|
|
|
|
|
.Select(x => new { x.BusinessId, x.BusinessType, x.FeeType, x.FeeStatus }).ToList();
|
|
|
|
|
if (fees2.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var gpList = fees2.GroupBy(x => new { x.BusinessId, x.BusinessType });
|
|
|
|
|
foreach (var gp in gpList)
|
|
|
|
|
{
|
|
|
|
|
BusinessFeeStatus biz = new() { BusinessId = gp.Key.BusinessId, BusinessType = gp.Key.BusinessType };
|
|
|
|
|
var upt = TenantDb.Updateable(biz).WhereColumns(x => new { x.BusinessId, x.BusinessType });
|
|
|
|
|
//应收
|
|
|
|
|
var arList = gp.Where(x => x.FeeType == FeeType.Receivable).ToList();
|
|
|
|
|
if (arList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (arList.All(x => x.FeeStatus == FeeStatus.SettlementCompleted))
|
|
|
|
|
{
|
|
|
|
|
biz.ARFeeStatus = BillFeeStatus.SettlementCompleted;
|
|
|
|
|
upt = upt.UpdateColumns(x => x.ARFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
else if (arList.Any(x => x.FeeStatus == FeeStatus.PartialSettlement))
|
|
|
|
|
{
|
|
|
|
|
biz.ARFeeStatus = BillFeeStatus.PartialSettlement;
|
|
|
|
|
upt = upt.UpdateColumns(x => x.ARFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//应付
|
|
|
|
|
var apList = gp.Where(x => x.FeeType == FeeType.Payable).ToList();
|
|
|
|
|
if (apList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
if (apList.All(x => x.FeeStatus == FeeStatus.SettlementCompleted))
|
|
|
|
|
{
|
|
|
|
|
biz.APFeeStatus = BillFeeStatus.SettlementCompleted;
|
|
|
|
|
upt = upt.UpdateColumns(x => x.APFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
else if (apList.Any(x => x.FeeStatus == FeeStatus.PartialSettlement))
|
|
|
|
|
{
|
|
|
|
|
biz.APFeeStatus = BillFeeStatus.PartialSettlement;
|
|
|
|
|
upt = upt.UpdateColumns(x => x.APFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upt.ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置结算单的锁定状态
|
|
|
|
|
/// </summary>
|
|
|
|
|