|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using AngleSharp.Dom;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
@ -107,9 +108,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// 检查业务是否已费用锁定
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bid">业务ID</param>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="type">锁定范围</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
bool IsFeeLocked(long bid, FeeType type = FeeType.All)
|
|
|
|
|
bool IsFeeLocked(long bid, BusinessType businessType, FeeType type = FeeType.All)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
bool? isFeeLocking = null;
|
|
|
|
@ -120,23 +122,24 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
case FeeType.Payable:
|
|
|
|
|
break;
|
|
|
|
|
case FeeType.All:
|
|
|
|
|
isFeeLocking = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == bid).Select(x => x.IsFeeLocking).First();
|
|
|
|
|
isFeeLocking = tenantDb.Queryable<BusinessFeeStatus>().Where(
|
|
|
|
|
x => x.BusinessId == bid && x.BusinessType == businessType).Select(x => x.IsFeeLocking).First();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return isFeeLocking.GetValueOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交
|
|
|
|
|
/// 费用提交
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bid">业务ID</param>
|
|
|
|
|
/// <param name="items">要提交的费用记录</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult InsertOrUpdate(long bid, IEnumerable<FeeRecord> items)
|
|
|
|
|
public DataResult InsertOrUpdate(IEnumerable<FeeRecord> items)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (IsFeeLocked(bid))
|
|
|
|
|
var first = items.Select(x => new { x.BusinessType, x.BusinessId }).FirstOrDefault();
|
|
|
|
|
if (IsFeeLocked(first.BusinessId, first.BusinessType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止提交", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
@ -178,7 +181,8 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
if (item.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
item.BusinessId = bid;
|
|
|
|
|
item.BusinessId = first.BusinessId;
|
|
|
|
|
item.BusinessType = first.BusinessType;
|
|
|
|
|
tenantDb.Insertable(item).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -211,7 +215,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
return DataResult.Failed("保存失败", MultiLanguageConst.DataUpdateFailed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
WriteBackStatus(tenantDb, first.BusinessId, first.BusinessType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取汇率
|
|
|
|
@ -247,9 +254,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// 根据模板ID创建
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bid">业务ID</param>
|
|
|
|
|
/// <param name="type">业务类型</param>
|
|
|
|
|
/// <param name="tidArray">模板ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult CreateByTemplate(long bid, params long[] tidArray)
|
|
|
|
|
public DataResult CreateByTemplate(long bid, BusinessType type, params long[] tidArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
@ -297,6 +305,9 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
FetchExchangeRate(tenantDb, records);
|
|
|
|
|
|
|
|
|
|
int result = tenantDb.Insertable(records).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
WriteBackStatus(tenantDb, bid, type);
|
|
|
|
|
|
|
|
|
|
return result > 0 ? DataResult.Successed("保存成功", records, MultiLanguageConst.DataCreateSuccess) : DataResult.Successed("操作失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -321,14 +332,17 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var bid = tenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => x.BusinessId).First();
|
|
|
|
|
if (IsFeeLocked(bid))
|
|
|
|
|
var model = tenantDb.Queryable<FeeRecord>().Where(x => ids.Contains(x.Id)).Select(x => new { x.BusinessId, x.BusinessType }).First();
|
|
|
|
|
if (IsFeeLocked(model.BusinessId, model.BusinessType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止修改", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
if (tenantDb.Queryable<FeeRecord>().Any(x => ids.Contains(x.Id) && (x.FeeStatus != FeeStatus.Entering && x.FeeStatus != FeeStatus.RejectSubmission)))
|
|
|
|
|
return DataResult.Failed("只能删除状态为‘录入’或‘驳回提交’的费用", MultiLanguageConst.FeeRecordDelete);
|
|
|
|
|
|
|
|
|
|
int result = tenantDb.Deleteable<FeeRecord>(x => ids.Contains(x.Id)).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
WriteBackStatus(tenantDb, model.BusinessId, model.BusinessType);
|
|
|
|
|
|
|
|
|
|
return result > 0 ? DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess) : DataResult.Failed("删除失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -352,8 +366,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
if (fees.IsNullOrEmpty())
|
|
|
|
|
return DataResult.Failed($"未能获取费用信息,提交失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
var bid = fees[0].BusinessId;
|
|
|
|
|
var bType = fees[0].BusinessType;
|
|
|
|
|
//业务状态检测
|
|
|
|
|
if (IsFeeLocked(fees[0].BusinessId))
|
|
|
|
|
if (IsFeeLocked(bid, bType))
|
|
|
|
|
return DataResult.Failed("当前业务已费用锁定,禁止修改", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
if (fees.Any(x => x.FlowId.HasValue))
|
|
|
|
@ -389,7 +405,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
x.SubmitDate,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
tenantDb.Ado.CommitTran();
|
|
|
|
|
return DataResult.Successed("提交成功!", MultiLanguageConst.DataUpdateSuccess);
|
|
|
|
|
}
|
|
|
|
@ -423,7 +438,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var item in fees)
|
|
|
|
|
{
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq { BusinessId = item.Id, TemplateId = template.Id });
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq
|
|
|
|
|
{
|
|
|
|
|
BusinessId = item.Id,
|
|
|
|
|
BusinessType = item.BusinessType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
});
|
|
|
|
|
if (result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
var instance = result.Data as FlowInstance;
|
|
|
|
@ -462,7 +482,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var item in fees)
|
|
|
|
|
{
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq { BusinessId = item.Id, TemplateId = template.Id });
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq
|
|
|
|
|
{
|
|
|
|
|
BusinessId = item.Id,
|
|
|
|
|
BusinessType = item.BusinessType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
});
|
|
|
|
|
if (result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
var instance = result.Data as FlowInstance;
|
|
|
|
@ -488,7 +513,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
var idList = items.Select(x => x.FeeRecordId).Distinct().ToList();
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Select(x => new FeeRecord
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => idList.Contains(x.Id)).Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
@ -517,7 +542,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
{
|
|
|
|
|
foreach (var fee in fees)
|
|
|
|
|
{
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq { BusinessId = fee.Id, TemplateId = template.Id });
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq
|
|
|
|
|
{
|
|
|
|
|
BusinessId = fee.Id,
|
|
|
|
|
BusinessType = fee.BusinessType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
});
|
|
|
|
|
if (result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
var instance = result.Data as FlowInstance;
|
|
|
|
@ -678,7 +708,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable<FeeRecord>().
|
|
|
|
|
SetColumns(x => x.FeeStatus == status).
|
|
|
|
|
SetColumns(x=>x.FlowId == null).
|
|
|
|
|
SetColumns(x => x.FlowId == null).
|
|
|
|
|
Where(x => x.BusinessId == businessFee.BusinessId &&
|
|
|
|
|
(x.FeeStatus == FeeStatus.Entering || x.FeeStatus == FeeStatus.RejectSubmission)).ExecuteCommand();
|
|
|
|
|
|
|
|
|
@ -708,6 +738,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
ex.Log(db);
|
|
|
|
|
return DataResult.Failed("提交失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
WriteBackStatus(tenantDb, callback.BusinessId, callback.BusinessType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -809,7 +843,12 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
if (template == null)
|
|
|
|
|
return DataResult.Failed("未能找到审批模板", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq { BusinessId = entity.Id, TemplateId = template.Id });
|
|
|
|
|
var result = flowService.CreateFlowInstance(new CreateFlowInstanceReq
|
|
|
|
|
{
|
|
|
|
|
BusinessId = entity.Id,
|
|
|
|
|
BusinessType = entity.BusinessType,
|
|
|
|
|
TemplateId = template.Id
|
|
|
|
|
});
|
|
|
|
|
if (result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
var instance = result.Data as FlowInstance;
|
|
|
|
@ -836,9 +875,82 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//回写业务主表的费用状态
|
|
|
|
|
void WriteBackStatus(SqlSugarScopeProvider tenantDb, List<FeeRecord> fees)
|
|
|
|
|
void WriteBackStatus(SqlSugarScopeProvider tenantDb, long businessId, BusinessType businessType)
|
|
|
|
|
{
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => x.BusinessId == businessId && x.BusinessType == businessType)
|
|
|
|
|
.Select(x => new FeeRecord
|
|
|
|
|
{
|
|
|
|
|
//BusinessId = businessId,
|
|
|
|
|
//BusinessType = businessType,
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
FeeStatus = x.FeeStatus
|
|
|
|
|
}).ToList();
|
|
|
|
|
var arFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Receivable));
|
|
|
|
|
var apFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Payable));
|
|
|
|
|
|
|
|
|
|
if (arFeeStatus != null || apFeeStatus != null)
|
|
|
|
|
{
|
|
|
|
|
var upt = tenantDb.Updateable<BusinessFeeStatus>();
|
|
|
|
|
if (arFeeStatus != null)
|
|
|
|
|
{
|
|
|
|
|
upt = upt.SetColumns(x => x.ARFeeStatus == arFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
if (apFeeStatus != null)
|
|
|
|
|
{
|
|
|
|
|
upt = upt.SetColumns(x => x.APFeeStatus == apFeeStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
upt.Where(x => x.BusinessType == businessType && x.BusinessId == businessId)
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//业务表费用状态判定
|
|
|
|
|
static BillFeeStatus? DetermineStatus(List<FeeRecord> fees)
|
|
|
|
|
{
|
|
|
|
|
BillFeeStatus? billFeeStatus = null;
|
|
|
|
|
if (fees.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.NotEntered;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.Entering))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.Entering;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.AuditSubmitted))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.AuditSubmitted;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.AuditPassed))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.AuditPassed;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.RejectSubmission))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.RejectSubmission;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.PartialSettlement))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.PartialSettlement;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.All(x => x.FeeStatus == FeeStatus.SettlementCompleted))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.SettlementCompleted;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.Any(x => x.FeeStatus == FeeStatus.Entering))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.PartialEntering;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.Any(x => x.FeeStatus == FeeStatus.AuditSubmitted))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.PartialSubmitted;
|
|
|
|
|
}
|
|
|
|
|
else if (fees.Any(x => x.FeeStatus == FeeStatus.AuditPassed))
|
|
|
|
|
{
|
|
|
|
|
billFeeStatus = BillFeeStatus.PartialAudited;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return billFeeStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|