|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using AngleSharp.Dom;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
@ -14,6 +13,7 @@ using DS.WMS.Core.Flow.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using LanguageExt;
|
|
|
|
|
using LanguageExt.Pipes;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Masuit.Tools.Systems;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
@ -27,7 +27,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
public class FeeRecordService : IFeeRecordService
|
|
|
|
|
{
|
|
|
|
|
const long PERMISSION_ID = 1793490768447541248;
|
|
|
|
|
readonly string DefaultCurrency = "CNY";
|
|
|
|
|
readonly string DefaultCurrency = "CNY";//默认本币
|
|
|
|
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
@ -53,10 +53,11 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
public DataResult<List<FeeRecordRes>> GetListByPage(PageRequest request)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
long userId = long.Parse(user.UserId);
|
|
|
|
|
//序列化查询条件
|
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
|
var data = tenantDb.Queryable<FeeRecord>()
|
|
|
|
|
.Where(x => x.IsOpen || (!x.IsOpen && x.CreateBy == userId))
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.Select<FeeRecordRes>()
|
|
|
|
|
.ToQueryPage(request.PageCondition);
|
|
|
|
@ -92,7 +93,8 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
public DataResult<List<FeeRecord>> GetList(string query)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var src = tenantDb.Queryable<FeeRecord>();
|
|
|
|
|
long userId = long.Parse(user.UserId);
|
|
|
|
|
var src = tenantDb.Queryable<FeeRecord>().Where(x => x.IsOpen || (!x.IsOpen && x.CreateBy == userId));
|
|
|
|
|
if (!query.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
//序列化查询条件
|
|
|
|
@ -221,35 +223,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取汇率
|
|
|
|
|
void FetchExchangeRate(SqlSugarScopeProvider tenantDb, IEnumerable<FeeRecord> records)
|
|
|
|
|
{
|
|
|
|
|
var exRecords = records.Where(x => !x.ExchangeRate.HasValue && x.Currency != DefaultCurrency).ToList();
|
|
|
|
|
if (exRecords.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var codes = exRecords.Select(x => x.Currency).Distinct().ToList();
|
|
|
|
|
var currencies = tenantDb.Queryable<FeeCurrency>().Where(x => codes.Contains(x.CodeName)).Includes(x => x.Exchanges).ToList();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var item in exRecords)
|
|
|
|
|
{
|
|
|
|
|
var currency = currencies.Find(x => x.CodeName == item.Currency);
|
|
|
|
|
if (currency != null)
|
|
|
|
|
{
|
|
|
|
|
item.ExchangeRate = currency.DefaultRate;
|
|
|
|
|
if (currency.Exchanges != null)
|
|
|
|
|
{
|
|
|
|
|
//取当前时间范围内的最新一条
|
|
|
|
|
var exchange = currency.Exchanges.FindAll(x => x.Status == StatusEnum.Enable &&
|
|
|
|
|
x.StartDate >= dtNow && x.EndDate <= dtNow).OrderByDescending(x => x.UpdateTime).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (exchange != null)
|
|
|
|
|
item.ExchangeRate = item.FeeType == FeeType.Receivable ? exchange.DRValue : exchange.CRValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据模板ID创建
|
|
|
|
|
/// </summary>
|
|
|
|
@ -338,9 +311,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// 发起审批/申请删除工作流
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="auditType">审批类型</param>
|
|
|
|
|
/// <param name="remark">备注</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SubmitForApproval(FeeAuditType auditType, params long[] idArray)
|
|
|
|
|
public DataResult SubmitForApproval(FeeAuditType auditType, string remark, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var fees = tenantDb.Queryable<FeeRecord>().Where(x => idArray.Contains(x.Id)).Select(
|
|
|
|
@ -377,7 +351,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
else if (auditType == FeeAuditType.ApplyDeletion)
|
|
|
|
|
{
|
|
|
|
|
result = ApplyDelete(tenantDb, fees);
|
|
|
|
|
result = ApplyDelete(tenantDb, fees, remark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
@ -450,7 +424,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//审核通过->申请删除
|
|
|
|
|
DataResult ApplyDelete(SqlSugarScopeProvider tenantDb, List<FeeRecord> fees)
|
|
|
|
|
DataResult ApplyDelete(SqlSugarScopeProvider tenantDb, List<FeeRecord> fees, string reason)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
foreach (var fe in fees)
|
|
|
|
@ -487,6 +461,7 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
item.SubmitBy = long.Parse(user.UserId);
|
|
|
|
|
item.SubmitDate = dtNow;
|
|
|
|
|
item.FlowId = instance.Id;
|
|
|
|
|
item.Note = reason;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -545,8 +520,8 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
//变更状态为申请修改
|
|
|
|
|
fee.FeeStatus = FeeStatus.ApplyModification;
|
|
|
|
|
fee.SubmitBy = long.Parse(user.UserId);
|
|
|
|
|
fee.SubmitDate = dtNow;
|
|
|
|
|
//fee.SubmitBy = long.Parse(user.UserId);
|
|
|
|
|
//fee.SubmitDate = dtNow;
|
|
|
|
|
fee.FlowId = instance.Id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -618,7 +593,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.AuditBy,
|
|
|
|
|
x.AuditDate,
|
|
|
|
@ -649,7 +623,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
fm.DeleteBy = long.Parse(user.UserId);
|
|
|
|
|
tenantDb.Updateable(fm).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteTime
|
|
|
|
@ -660,7 +633,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
fee.FeeStatus = FeeStatus.RejectApplication;
|
|
|
|
|
tenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
@ -671,7 +643,20 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
case FeeAuditType.ApplyDeletion:
|
|
|
|
|
if (callback.FlowStatus == FlowStatusEnum.Approve)
|
|
|
|
|
{
|
|
|
|
|
tenantDb.Deleteable(fee).ExecuteCommand();
|
|
|
|
|
fee.Deleted = true;
|
|
|
|
|
fee.DeleteBy = long.Parse(user.UserId);
|
|
|
|
|
fee.DeleteTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.DeleteBy,
|
|
|
|
|
x.Deleted,
|
|
|
|
|
x.DeleteTime,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
|
}).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
//tenantDb.Deleteable(fee).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -679,7 +664,6 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
|
|
|
|
|
tenantDb.Updateable(fee).UpdateColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
x.Id,
|
|
|
|
|
x.FeeStatus,
|
|
|
|
|
x.Reason,
|
|
|
|
|
x.FlowId
|
|
|
|
@ -814,10 +798,10 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 整单审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">业务类型</param>
|
|
|
|
|
/// <param name="bid">业务ID</param>
|
|
|
|
|
/// <param name="type">业务类型</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult AuditBusiness(BusinessType type, long bid)
|
|
|
|
|
public DataResult AuditBusiness(long bid, BusinessType type)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var entity = tenantDb.Queryable<BusinessFeeStatus>().Where(x => x.BusinessId == bid &&
|
|
|
|
@ -872,6 +856,129 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
return DataResult.Failed("创建工作流失败", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置发票启用状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="enabled">是否启用</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SetInvoiceEnabled(bool enabled, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
var list = idArray.Select(x => new FeeRecord { Id = x, IsInvoice = enabled }).ToList();
|
|
|
|
|
int rows = tenantDb.Updateable(list).UpdateColumns(x => new { x.IsInvoice }).ExecuteCommand();
|
|
|
|
|
return rows > 0 ? DataResult.Successed("设置成功!", MultiLanguageConst.DataUpdateSuccess) : DataResult.Failed("设置失败!", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取费用核算单打印信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="businessType">业务类型</param>
|
|
|
|
|
/// <param name="idArray">费用记录ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult<CostAccountingForm> GetPrintInfo(BusinessType businessType, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
CostAccountingForm form = null;
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
switch (businessType)
|
|
|
|
|
{
|
|
|
|
|
//case BusinessType.ChangeOrder:
|
|
|
|
|
// break;
|
|
|
|
|
case BusinessType.OceanShippingExport:
|
|
|
|
|
form = GetOceanShippingExportForm(tenantDb, idArray);
|
|
|
|
|
break;
|
|
|
|
|
case BusinessType.OceanShippingImport:
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return DataResult<CostAccountingForm>.Failed(
|
|
|
|
|
$"不支持业务类型为【{businessType.GetDescription()}】的费用打印", MultiLanguageConst.Operation_Failed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (form != null)
|
|
|
|
|
{
|
|
|
|
|
long userId = long.Parse(user.UserId);
|
|
|
|
|
form.Creator = db.Queryable<SysUser>().Where(x => x.Id == userId).Select(x => x.NickName).First();
|
|
|
|
|
|
|
|
|
|
form.ReceivableRMB = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == "CNY").Sum(x => x.Amount);
|
|
|
|
|
form.PayableRMB = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == "CNY").Sum(x => x.Amount);
|
|
|
|
|
form.ReceivableUSD = form.Details.FindAll(x => x.Type == FeeType.Receivable && x.Currency == "USD").Sum(x => x.Amount);
|
|
|
|
|
form.PayableUSD = form.Details.FindAll(x => x.Type == FeeType.Payable && x.Currency == "USD").Sum(x => x.Amount);
|
|
|
|
|
form.ReceivableOther = form.Details.FindAll(x => x.Type == FeeType.Receivable && (x.Currency != "CNY" && x.Currency != "USD")).Sum(x => x.Amount);
|
|
|
|
|
form.PayableOther = form.Details.FindAll(x => x.Type == FeeType.Payable && (x.Currency == "CNY" && x.Currency != "USD")).Sum(x => x.Amount);
|
|
|
|
|
|
|
|
|
|
//获取美元汇率
|
|
|
|
|
var fees = new List<FeeRecord> {
|
|
|
|
|
new FeeRecord { Currency = "USD", FeeType = FeeType.Receivable },
|
|
|
|
|
new FeeRecord { Currency = "USD", FeeType = FeeType.Payable }
|
|
|
|
|
};
|
|
|
|
|
FetchExchangeRate(tenantDb, fees);
|
|
|
|
|
form.ExchangeRate = fees[0].ExchangeRate.HasValue ? fees[0].ExchangeRate.Value : 1;
|
|
|
|
|
form.TotalReceivable = Math.Round(form.ReceivableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.ReceivableRMB + form.ReceivableOther;
|
|
|
|
|
form.TotalPayable = Math.Round(form.PayableUSD * form.ExchangeRate, 4, MidpointRounding.ToEven) + form.PayableRMB + form.PayableOther;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<CostAccountingForm>.Success(form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CostAccountingForm GetOceanShippingExportForm(SqlSugarScopeProvider tenantDb, params long[] idArray)
|
|
|
|
|
{
|
|
|
|
|
CostAccountingForm form = null;
|
|
|
|
|
var list = tenantDb.Queryable<FeeRecord>().InnerJoin<SeaExport>((x, y) => x.BusinessId == y.Id)
|
|
|
|
|
.Where((x, y) => idArray.Contains(x.Id)
|
|
|
|
|
//&& x.FeeStatus == FeeStatus.SettlementCompleted
|
|
|
|
|
).Select((x, y) => new
|
|
|
|
|
{
|
|
|
|
|
x.FeeType,
|
|
|
|
|
x.FeeName,
|
|
|
|
|
x.Currency,
|
|
|
|
|
x.ExchangeRate,
|
|
|
|
|
x.Amount,
|
|
|
|
|
x.CustomerName,
|
|
|
|
|
y.CustomerNo, //业务编号
|
|
|
|
|
y.AccountDate, //会计期间
|
|
|
|
|
y.ETA,
|
|
|
|
|
y.ETD,
|
|
|
|
|
y.Voyno,
|
|
|
|
|
y.MBLNO,
|
|
|
|
|
y.Carrier,
|
|
|
|
|
y.LoadPort,
|
|
|
|
|
y.DischargePort,
|
|
|
|
|
y.CntrTotal, //Volume
|
|
|
|
|
y.IssueType //放单方式
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
return form;
|
|
|
|
|
|
|
|
|
|
var item = list[0];
|
|
|
|
|
form = new CostAccountingForm
|
|
|
|
|
{
|
|
|
|
|
BusinessNo = item.CustomerNo,
|
|
|
|
|
AccountingPeriod = item.AccountDate,
|
|
|
|
|
ETA = item.ETA,
|
|
|
|
|
ETD = item.ETD,
|
|
|
|
|
Voy = item.Voyno,
|
|
|
|
|
MBLNo = item.MBLNO,
|
|
|
|
|
Carrier = item.Carrier,
|
|
|
|
|
POL = item.LoadPort,
|
|
|
|
|
POD = item.DischargePort,
|
|
|
|
|
Volume = item.CntrTotal,
|
|
|
|
|
ReleaseType = item.IssueType,
|
|
|
|
|
PrintTime = DateTime.Now,
|
|
|
|
|
Details = list.Select(x => new CostAccountingDetail
|
|
|
|
|
{
|
|
|
|
|
Amount = x.Amount.GetValueOrDefault(),
|
|
|
|
|
Currency = x.Currency,
|
|
|
|
|
CustomerName = x.CustomerName,
|
|
|
|
|
FeeName = x.FeeName,
|
|
|
|
|
Type = x.FeeType
|
|
|
|
|
}).ToList()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return form;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//回写业务主表的费用状态
|
|
|
|
|
void WriteBackStatus(SqlSugarScopeProvider tenantDb, long businessId, BusinessType businessType)
|
|
|
|
@ -884,6 +991,11 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
FeeType = x.FeeType,
|
|
|
|
|
FeeStatus = x.FeeStatus
|
|
|
|
|
}).ToList();
|
|
|
|
|
if (fees.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var arFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Receivable));
|
|
|
|
|
var apFeeStatus = DetermineStatus(fees.FindAll(x => x.FeeType == FeeType.Payable));
|
|
|
|
|
|
|
|
|
@ -965,5 +1077,34 @@ namespace DS.WMS.Core.Fee.Method
|
|
|
|
|
x.AuditType == auditType).First();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取汇率
|
|
|
|
|
void FetchExchangeRate(SqlSugarScopeProvider tenantDb, IEnumerable<FeeRecord> items)
|
|
|
|
|
{
|
|
|
|
|
var exRecords = items.Where(x => !x.ExchangeRate.HasValue && x.Currency != DefaultCurrency).ToList();
|
|
|
|
|
if (exRecords.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var codes = exRecords.Select(x => x.Currency).Distinct().ToList();
|
|
|
|
|
var currencies = tenantDb.Queryable<FeeCurrency>().Where(x => codes.Contains(x.CodeName)).Includes(x => x.Exchanges).ToList();
|
|
|
|
|
DateTime dtNow = DateTime.Now;
|
|
|
|
|
foreach (var item in exRecords)
|
|
|
|
|
{
|
|
|
|
|
var currency = currencies.Find(x => x.CodeName == item.Currency);
|
|
|
|
|
if (currency != null)
|
|
|
|
|
{
|
|
|
|
|
item.ExchangeRate = currency.DefaultRate;
|
|
|
|
|
if (!currency.Exchanges.IsNullOrEmpty())
|
|
|
|
|
{
|
|
|
|
|
//取当前时间范围内的最新一条
|
|
|
|
|
var exchange = currency.Exchanges.FindAll(x => x.Status == StatusEnum.Enable &&
|
|
|
|
|
x.StartDate >= dtNow && x.EndDate <= dtNow).OrderByDescending(x => x.UpdateTime).FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (exchange != null)
|
|
|
|
|
item.ExchangeRate = item.FeeType == FeeType.Receivable ? exchange.DRValue : exchange.CRValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|