120 lines
5.1 KiB
C#
120 lines
5.1 KiB
C#
using YLErp.BLL.MarginCalculation;
|
|
using YLErp.Commons;
|
|
using YLErp.DBModels.Consts;
|
|
using YLErp.Model;
|
|
using YLErp.Modules;
|
|
using YLErp.Modules.DataProviderModule;
|
|
using YLErp.Modules.TradeModule;
|
|
|
|
namespace YLErp.BLL.GenerateDocument
|
|
{
|
|
public class GeneralGenerateSettleBill : BaseGenerate
|
|
{
|
|
public GeneralGenerateSettleBill(trade_contract_group tradeContractGroup, string docType, int optId, string optName) : base(tradeContractGroup, docType, optId, optName)
|
|
{ }
|
|
|
|
protected override string ContractType => ContractTypeEnum.Clearing;
|
|
|
|
public override string TemplateFile => $"到期结算单模板.{DocType.ToLower()}";
|
|
|
|
public override string ContractNOSeed => "GTJASettlement";
|
|
|
|
public override ReturnInfo<Dictionary<string, string>> AppendDictionary()
|
|
{
|
|
var dic = CurrentContractDataSet.ModelDic;
|
|
var tradeContractGroup = CurrentContractDataSet.ContractGroup;
|
|
|
|
var trade = tradeContractGroup.trade;
|
|
var tradeCash = tradeContractGroup.trade_cash;
|
|
var tradeContractR = tradeContractGroup.ConfirmContractR;
|
|
|
|
var underlying = DataCacheProvider.GetUnderlyingDataSource().GetData(trade.UnderlyingCode);
|
|
var variety = DataCacheProvider.GetVarietyDataSource().GetData(underlying.UnderlyingTypeId);
|
|
|
|
string strUnit = variety.QuoteUnitSingle;
|
|
double tradeNotional = trade.Notional;
|
|
|
|
dic["{{支付时间}}"] = "买方终止 / 到期时支付";
|
|
|
|
//期末价格
|
|
double endPrice = underlying.Price ?? 0;
|
|
//交割金额
|
|
double tradeCashAmount = 0;
|
|
double notional = 0;
|
|
if (tradeCash != null)
|
|
{
|
|
endPrice = tradeCash.FinalPrice ?? 0;
|
|
tradeCashAmount = tradeCash.Amount;
|
|
notional = tradeCash.Action == "系统操作-行权费" ? tradeCash.Notional : tradeCash.UnwindNotional ?? 0;
|
|
}
|
|
|
|
dic["{{执行价格}}"] = $"{(trade.ActualStrike ?? 0):f2}元/{strUnit}";
|
|
dic["{{期初价格}}"] = $"{(trade.SpotPrice ?? 0):f2}元/{strUnit}";
|
|
dic["{{期权收益}}"] = $"{Math.Abs(tradeCashAmount / tradeNotional):f2}元/{strUnit}";
|
|
dic["{{期末数量}}"] = $"{tradeNotional}{strUnit}";
|
|
dic["{{结算价}}"] = $"{Math.Abs(tradeCashAmount):f2}元";
|
|
dic["{{终止日}}"] = trade.UnWindDate?.ToString("yyyy年M月d日");
|
|
var req = new RunMarginCalculationReq(GetOptUser())
|
|
{
|
|
tradeList = new List<trade> { trade },
|
|
settleDate = trade.UnWindDate.Value,
|
|
PriceProvider = new SinglePriceProvider(trade.UnderlyingCode, endPrice)
|
|
};
|
|
if (trade.IsGroup == 1)
|
|
{
|
|
req.tradeList = db.trade.Where(x => x.ParentTradeId == trade.id).ToList();
|
|
}
|
|
var tradeSpans = MarginDefault.RunMarginCalculation(req);
|
|
if (tradeSpans?.Count > 0)
|
|
{
|
|
var margin = trade.IsGroup == 1 ? tradeSpans.Sum(x => x.WorstCastClientPayable ?? 0) : (tradeSpans[0].WorstCastClientPayable ?? 0);
|
|
dic["{{预付金}}"] = $"{Math.Abs(margin):f2}元";
|
|
}
|
|
else
|
|
{
|
|
dic["{{预付金}}"] = "0元";
|
|
}
|
|
dic["{{结算价格}}"] = dic["{{期权收益}}"];
|
|
|
|
var isGJBuyer = trade.BuySell == "买入";
|
|
double incomes;
|
|
if (isGJBuyer)
|
|
{
|
|
incomes = tradeCashAmount - (notional * trade.TradeSinglePrice) ?? 0;
|
|
}
|
|
else
|
|
{
|
|
incomes = tradeCashAmount + (notional * trade.TradeSinglePrice) ?? 0;
|
|
}
|
|
dic["{{结算净额}}"] = $"{Math.Abs(incomes):f2}元";
|
|
dic["{{结算方式}}"] = incomes > 0 ? "贵司向我司支付结算净额" : "我司向贵司支付结算净额";
|
|
dic["{{到期盈亏}}"] = $"{Math.Abs(incomes):f2}元";
|
|
dic["{{合同时间}}"] = DateTime.Now.ToString("yyyy年M月d日");
|
|
dic["{{确认书编号}}"] = tradeContractR.ContractCode;
|
|
|
|
return Return.Success(dic);
|
|
}
|
|
|
|
protected override string GetContractIndex(trade_contract_group tradeContractGroup)
|
|
{
|
|
var trade = tradeContractGroup.trade;
|
|
var contractBLL = new TradeContractBLL(OptId, OptName);
|
|
var contractIndex = contractBLL.GetContractNo(ContractNOSeed);
|
|
return contractIndex;
|
|
}
|
|
|
|
protected override string GetContractNO(trade_contract_group tradeContractGroup, string contractIndex)
|
|
{
|
|
var trade = tradeContractGroup.trade;
|
|
var client = DataCacheProvider.GetClientDataSource().GetData(trade.ClientId);
|
|
return $"{client?.Number}C{contractIndex}S";
|
|
}
|
|
|
|
protected override string GetOutputFileName(trade_contract_group tradeContractGroup, string contractIndex)
|
|
{
|
|
var trade = tradeContractGroup.trade;
|
|
return $"{trade.ClientName}到期结算单C{contractIndex}S.{DocType.ToLower()}";
|
|
}
|
|
}
|
|
}
|