Ejemplo n.º 1
0
 public MemoryLookupValues()
 {
     Frequencies = _lookupBusiness.GetFreqTypeAll();
     Products    = _lookupBusiness.GetProductAll();
     Statuses    = _lookupBusiness.GetStatusAll();
     Portfolios  = _lookupBusiness.GetPortfolioAll();
     Limits      = _lookupBusiness.GetLimitAll();
     Currencies  = _lookupBusiness.GetCurrencyAll();
 }
Ejemplo n.º 2
0
        public static List <FIDealModel> GetDealInternalByProcessDate(SessionInfo sessioninfo)
        {
            DealBusiness       _dealBusiness   = new DealBusiness();
            UserBusiness       _userBusiness   = new UserBusiness();
            LookupBusiness     _lookupBusiness = new LookupBusiness();
            List <MA_CURRENCY> ccys            = _lookupBusiness.GetCurrencyAll();
            List <MA_USER>     users           = _userBusiness.GetAll();
            Guid          productID            = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            List <DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate);

            return((from t in trns.Where(a => a.PRODUCT_ID.Value == productID && a.DA_TMBA_EXTENSION != null)
                    join user in users on t.LOG.INSERTBYUSERID equals user.ID into ljuser
                    from inputuser in ljuser.DefaultIfEmpty()
                    join tempccy1 in ccys on t.FIRST.CCY_ID equals tempccy1.ID into ljccy1
                    from ccy1 in ljccy1.DefaultIfEmpty()
                    join tbmauser in users on t.DA_TMBA_EXTENSION.SENDER_ID equals tbmauser.ID into ljtbmauser
                    from tbmainputuser in ljtbmauser.DefaultIfEmpty()
                    orderby t.LOG.INSERTDATE descending
                    select new FIDealModel
            {
                ID = t.ID,
                DMK_NO = t.INT_DEAL_NO,
                OPICS_NO = t.EXT_DEAL_NO,
                InsertState = t.MA_STATUS.LABEL == StatusCode.CANCELLED.ToString()
                                            ? "Cancelled"
                                            : t.DA_TMBA_EXTENSION.SEND_DATE != null
                                                ? "Sent"
                                                : 1800 - DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds <= 0
                                                    ? "Late"
                                                    : (1800 - Math.Round(DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds)).ToString(),
                TradeDate = t.TRADE_DATE.Value,
                MaturityDate = t.MATURITY_DATE,
                Instrument = t.MA_INSRUMENT.LABEL,
                BuySell = t.FLAG_BUYSELL,
                Portfolio = t.MA_PORTFOLIO.LABEL,
                Counterparty = t.MA_COUTERPARTY.SNAME,
                Yield = t.FIRST.RATE.Value,
                GrossValue = t.FIRST.NOTIONAL.Value,
                CCY = ccy1 != null ? ccy1.LABEL : null,
                Trader = inputuser != null ? inputuser.USERCODE : null,
                Status = t.MA_STATUS.LABEL,
                PCE = t.KK_CONTRIBUTE.HasValue ? t.KK_CONTRIBUTE.Value : 0,
                Sender = tbmainputuser != null ? tbmainputuser.USERCODE : null,
                Unit = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.UNIT : 0,
                CleanPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.CLEAN_PRICE : 0,
                GrossPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.GROSS_PRICE : 0,
                YieldType = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.YIELD_TYPE : string.Empty,
                ReporyBy = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.IS_REPORT_CLEAN ? "Clean Price" : "Gross Price" : string.Empty,
                Purpose = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.PURPOSE : string.Empty,
                Term = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.TERM.HasValue ? t.DA_TMBA_EXTENSION.TERM.Value : 0,
                Rate = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.RATE.HasValue ? t.DA_TMBA_EXTENSION.RATE.Value : 0,
                TBMA_Remark = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.REMARK : string.Empty,
                SendTime = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.SEND_DATE.HasValue ? t.DA_TMBA_EXTENSION.SEND_DATE.Value.ToString("dd MMM yyy HH:mm") : string.Empty : string.Empty,
                PrimaryMarket = t.FLAG_PCE.Value ? "Yes" : "No",
                NonDVP = t.FLAG_SETTLE.Value ? "Yes" : "No"
            }).ToList());
        }
Ejemplo n.º 3
0
 public static object GetPCCFFXSpotByLabel(SessionInfo sessioninfo, string CCYPairLabel)
 {
     StaticDataBusiness _staticBusiness = new StaticDataBusiness();
     LookupBusiness _lookupBusiness = new LookupBusiness();
     var productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID;
     MA_PCCF pccf = _staticBusiness.GetPCCFByLabelProduct(sessioninfo, CCYPairLabel, productID);
     if (pccf != null)
     {
         return null;// new { CURRENCY1 = pccf.MA_CURRENCY1.LABEL, CURRENCY2 = pccf.MA_CURRENCY2.LABEL, CURRENCYID1 = pccf.MA_CURRENCY1.ID, CURRENCYID2 = pccf.MA_CURRENCY2.ID, FLAG_MULTIPLY = pccf.FLAG_MULTIPLY };
     }
     else {
         throw new Exception("Invalid currency pair.");
     }
 }
Ejemplo n.º 4
0
        public static object GetPCCFFXSpotByLabel(SessionInfo sessioninfo, string CCYPairLabel)
        {
            StaticDataBusiness _staticBusiness = new StaticDataBusiness();
            LookupBusiness     _lookupBusiness = new LookupBusiness();
            var     productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID;
            MA_PCCF pccf      = _staticBusiness.GetPCCFByLabelProduct(sessioninfo, CCYPairLabel, productID);

            if (pccf != null)
            {
                return(null);// new { CURRENCY1 = pccf.MA_CURRENCY1.LABEL, CURRENCY2 = pccf.MA_CURRENCY2.LABEL, CURRENCYID1 = pccf.MA_CURRENCY1.ID, CURRENCYID2 = pccf.MA_CURRENCY2.ID, FLAG_MULTIPLY = pccf.FLAG_MULTIPLY };
            }
            else
            {
                throw new Exception("Invalid currency pair.");
            }
        }
Ejemplo n.º 5
0
        public static object SendFIReport(SessionInfo sessioninfo, string IDs)
        {
            try
            {
                string[]       TrnsID          = IDs.Split(',');
                DealBusiness   _dealBusiness   = new DealBusiness();
                LookupBusiness _lookupBusiness = new LookupBusiness();
                MA_TBMA_CONFIG config          = _lookupBusiness.GetTBMAConfig(sessioninfo);
                Guid           productID       = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
                List <DA_TRN>  trns            = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate)
                                                 .Where(a => a.PRODUCT_ID.Value == productID && TrnsID.Contains(a.ID.ToString()) && a.DA_TMBA_EXTENSION.SEND_DATE == null).ToList();
                var validateTBMA_NAME = (from o1 in trns
                                         where string.IsNullOrEmpty(o1.MA_COUTERPARTY.TBMA_NAME)
                                         select o1.MA_COUTERPARTY.SNAME).Distinct().ToArray();

                //verify required info
                if (validateTBMA_NAME.Length > 0)
                {
                    throw CreateException(new Exception(), "TBMA_NAME can't be empty. Please input TBMA_NAME on counterparty " + string.Join(",", validateTBMA_NAME));
                }
                if (config == null)
                {
                    throw CreateException(new Exception(), "Cannot get configurations. Please contact administrator");
                }

                foreach (DA_TRN trn in trns)
                {
                    _dealBusiness.CreatingTBMAReportFile(sessioninfo, trn, config);
                }

                Guid[] TrnsIDSend = trns.Select(t => t.ID).ToArray();
                _dealBusiness.UpdateFISendReport(sessioninfo, TrnsIDSend);
                return(new
                {
                    Result = "OK",
                    Message = String.Format("Sending report completed")
                });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 6
0
        public static object GetCSAByCtpyID(SessionInfo sessioninfo, Guid ID)
        {
            try
            {
                CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
                LookupBusiness       _lookupBusiness       = new LookupBusiness();
                //Get data from database
                List <CSAAgreementModel> results = new List <CSAAgreementModel>();
                var csa      = _counterpartyBusiness.GetCSAByCtpyID(sessioninfo, ID);
                var products = _lookupBusiness.GetProductAll();

                if (csa != null)
                {
                    var csaproduct = from c in csa.MA_CSA_PRODUCT
                                     join product in products on c.PRODUCT_ID equals product.ID
                                     select new
                    {
                        LABEL = product.LABEL
                    };

                    CSAAgreementModel ca = new CSAAgreementModel();
                    ca.CSA_TYPE_ID = csa.CSA_TYPE_ID;
                    ca.ID          = csa.ID;
                    ca.ISACTIVE    = csa.ISACTIVE;
                    ca.PRODUCTS    = String.Join(",", csaproduct.Select(p => p.LABEL));

                    results.Add(ca);
                }

                //Return result to jTable
                return(new { Result = "OK", Records = results, TotalRecordCount = results.Count });
            }
            catch (BusinessWorkflowsException bex)
            {
                return(new { Result = "ERROR", Message = bex.Message });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 7
0
        public static object GetProductOptions(SessionInfo sessioninfo, string except_product = "")
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var products = _lookupBusiness.GetProductAll().Where(t => t.ISACTIVE == true);

                if (except_product != "")
                {
                    products = products.Where(p => p.LABEL != except_product);
                }

                //Return result to jTable
                return(new { Result = "OK", Options = products.OrderBy(t => t.LABEL).Select(c => new { DisplayText = c.LABEL, Value = c.ID }) });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 8
0
        public static object GetProductOptions(SessionInfo sessioninfo, string except_product = "")
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var products = _lookupBusiness.GetProductAll().Where(t => t.ISACTIVE == true);

                if (except_product != "")
                {
                    products = products.Where(p => p.LABEL != except_product);
                }

                //Return result to jTable
                return new { Result = "OK", Options = products.OrderBy(t => t.LABEL).Select(c => new { DisplayText = c.LABEL, Value = c.ID }) };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Ejemplo n.º 9
0
        public static object SendFIReport(SessionInfo sessioninfo, string IDs)
        {
            try
                {

                    string[] TrnsID = IDs.Split(',');
                    DealBusiness _dealBusiness = new DealBusiness();
                    LookupBusiness _lookupBusiness = new LookupBusiness();
                    MA_TBMA_CONFIG config = _lookupBusiness.GetTBMAConfig(sessioninfo);
                    Guid productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
                    List<DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate)
                                       .Where(a => a.PRODUCT_ID.Value == productID && TrnsID.Contains(a.ID.ToString()) && a.DA_TMBA_EXTENSION.SEND_DATE == null).ToList();
                    var validateTBMA_NAME = (from o1 in trns
                                            where string.IsNullOrEmpty(o1.MA_COUTERPARTY.TBMA_NAME)
                                            select o1.MA_COUTERPARTY.SNAME).Distinct().ToArray();

                    //verify required info
                    if (validateTBMA_NAME.Length > 0) {
                        throw CreateException(new Exception(), "TBMA_NAME can't be empty. Please input TBMA_NAME on counterparty " + string.Join(",", validateTBMA_NAME));
                    }
                    if (config == null)
                        throw CreateException(new Exception(), "Cannot get configurations. Please contact administrator");

                    foreach (DA_TRN trn in trns)
                    {
                        _dealBusiness.CreatingTBMAReportFile(sessioninfo, trn, config);
                    }

                    Guid[] TrnsIDSend = trns.Select(t => t.ID).ToArray();
                    _dealBusiness.UpdateFISendReport(sessioninfo, TrnsIDSend);
                    return new
                    {
                        Result = "OK",
                        Message = String.Format("Sending report completed")
                    };
                }
                catch (Exception ex)
                {
                    return new { Result = "ERROR", Message = ex.Message };
                }
        }
Ejemplo n.º 10
0
        public static object GetCSAByCtpyID(SessionInfo sessioninfo, Guid ID)
        {
            try
            {
                CounterpartyBusiness _counterpartyBusiness = new CounterpartyBusiness();
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                List<CSAAgreementModel> results = new List<CSAAgreementModel>();
                var csa = _counterpartyBusiness.GetCSAByCtpyID(sessioninfo, ID);
                var products = _lookupBusiness.GetProductAll();

                if (csa != null)
                {
                    var csaproduct = from c in csa.MA_CSA_PRODUCT
                                     join product in products on c.PRODUCT_ID equals product.ID
                                     select new
                                     {
                                         LABEL = product.LABEL
                                     };

                    CSAAgreementModel ca = new CSAAgreementModel();
                    ca.CSA_TYPE_ID = csa.CSA_TYPE_ID;
                    ca.ID = csa.ID;
                    ca.ISACTIVE = csa.ISACTIVE;
                    ca.PRODUCTS = String.Join(",", csaproduct.Select(p => p.LABEL));

                    results.Add(ca);
                }

                //Return result to jTable
                return new { Result = "OK", Records = results, TotalRecordCount = results.Count };
            }
            catch (BusinessWorkflowsException bex)
            {
                return new { Result = "ERROR", Message = bex.Message };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Ejemplo n.º 11
0
        public static List<FIDealModel> GetDealInternalByProcessDate(SessionInfo sessioninfo)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            UserBusiness _userBusiness = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();
            List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();
            List<MA_USER> users = _userBusiness.GetAll();
            Guid productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            List<DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate);

            return (from t in trns.Where(a => a.PRODUCT_ID.Value == productID && a.DA_TMBA_EXTENSION != null)
                      join user in users on t.LOG.INSERTBYUSERID equals user.ID into ljuser
                      from inputuser in ljuser.DefaultIfEmpty()
                      join tempccy1 in ccys on t.FIRST.CCY_ID equals tempccy1.ID  into ljccy1
                      from ccy1 in ljccy1.DefaultIfEmpty()
                      join tbmauser in users on  t.DA_TMBA_EXTENSION.SENDER_ID equals tbmauser.ID  into ljtbmauser
                      from tbmainputuser in ljtbmauser.DefaultIfEmpty()
                      orderby t.LOG.INSERTDATE descending
                      select new FIDealModel
                      {
                          ID = t.ID,
                          DMK_NO = t.INT_DEAL_NO,
                          OPICS_NO = t.EXT_DEAL_NO,
                          InsertState = t.MA_STATUS.LABEL == StatusCode.CANCELLED.ToString()
                                            ? "Cancelled"
                                            : t.DA_TMBA_EXTENSION.SEND_DATE != null
                                                ? "Sent"
                                                : 1800 - DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds <=0
                                                    ? "Late"
                                                    : (1800 - Math.Round( DateTime.Now.Subtract(t.LOG.INSERTDATE).TotalSeconds)).ToString() ,
                          TradeDate = t.TRADE_DATE.Value,
                          MaturityDate = t.MATURITY_DATE,
                          Instrument = t.MA_INSRUMENT.LABEL,
                          BuySell = t.FLAG_BUYSELL,
                          Portfolio = t.MA_PORTFOLIO.LABEL,
                          Counterparty = t.MA_COUTERPARTY.SNAME,
                          Yield = t.FIRST.RATE.Value,
                          GrossValue = t.FIRST.NOTIONAL.Value,
                          CCY = ccy1 != null ? ccy1.LABEL : null,
                          Trader = inputuser != null ? inputuser.USERCODE : null,
                          Status = t.MA_STATUS.LABEL,
                          PCE = t.KK_CONTRIBUTE.HasValue ? t.KK_CONTRIBUTE.Value : 0,
                          Sender = tbmainputuser != null ? tbmainputuser.USERCODE : null,
                          Unit = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.UNIT : 0,
                          CleanPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.CLEAN_PRICE : 0,
                          GrossPrice = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.GROSS_PRICE : 0,
                          YieldType = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.YIELD_TYPE : string.Empty,
                          ReporyBy = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.IS_REPORT_CLEAN ? "Clean Price" : "Gross Price" : string.Empty,
                          Purpose = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.PURPOSE : string.Empty,
                          Term = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.TERM.HasValue ? t.DA_TMBA_EXTENSION.TERM.Value : 0,
                          Rate = t.DA_TMBA_EXTENSION != null && t.DA_TMBA_EXTENSION.RATE.HasValue ? t.DA_TMBA_EXTENSION.RATE.Value : 0,
                          TBMA_Remark = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.REMARK : string.Empty,
                          SendTime = t.DA_TMBA_EXTENSION != null ? t.DA_TMBA_EXTENSION.SEND_DATE.HasValue ? t.DA_TMBA_EXTENSION.SEND_DATE.Value.ToString("dd MMM yyy HH:mm") : string.Empty : string.Empty,
                          PrimaryMarket = t.FLAG_PCE.Value ? "Yes" : "No",
                          NonDVP = t.FLAG_SETTLE.Value ? "Yes" : "No"
                      }).ToList();
        }
Ejemplo n.º 12
0
        public DA_TRN GenerateFXSpotTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strSpotDate, string strCtpy, string strPortfolio
														, string strCurrencyPair, string strBS, string strContractCcy, string strCounterCcy
                                                        , string strSpotRate, string strContractAmt, string strCounterAmt, string strRemark, bool settleFlag, string strProductId)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn  = null;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp)) {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ID = Guid.NewGuid();
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
            trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
            trn.START_DATE = trn.TRADE_DATE;
            trn.MATURITY_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null);
            trn.CTPY_ID = Guid.Parse(strCtpy);
            trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
            trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair);
            trn.FIRST.CCY_ID = Guid.Parse(strContractCcy);
            trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy);
            trn.FIRST.RATE = Convert.ToDecimal(strSpotRate);
            trn.FLAG_BUYSELL = strBS;
            trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmt) : -Convert.ToDecimal(strContractAmt);
            trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmt) : Convert.ToDecimal(strCounterAmt);
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            trn.SOURCE = SourceType.INT.ToString();
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSPOT.ToString()).ID;
            trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P";
            trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R";
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.FLAG_SETTLE = !settleFlag;
            trn.REMARK = strRemark;
            var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
            var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID  && p.LABEL == "THB");
            var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID  && p.LABEL == "THB");
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            if (n1 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value);
            else if (n2 != null)
                trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value);
            else
            {
                var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);

                if (firstRate != null && secondRate != null)
                {
                    if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                        trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                    else
                        trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
             }

            //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
            //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn);
            //trn.KK_CONTRIBUTE = trn.NOTIONAL_THB.Value * trn.KK_PCCF / 100;

            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.RATE = trn.FIRST.RATE;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL;
            if (n1 != null)
                flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null){
                    flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
                }
                else{
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }

            }
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

            flow2.ID = Guid.NewGuid();
            flow2.DA_TRN_ID = trn.ID;
            flow2.FLAG_FIRST = false;
            flow2.FLOW_DATE = trn.MATURITY_DATE;
            flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL;
            if (n2 != null)
                flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
            else
            {
                var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                if (a != null)
                {
                    flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE);
                }
                else
                {
                    var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID);
                    throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                }
            }

            flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

            trn.DA_TRN_FLOW.Add(flow1);
            trn.DA_TRN_FLOW.Add(flow2);
            return trn;
        }
Ejemplo n.º 13
0
        public DA_TRN GenerateFITransactionObject(SessionInfo sessionInfo
                                                    , string strTradeDate
                                                    , string strBuySell
                                                    , string strInstrument
                                                    , string strCtpy
                                                    , string strPortfolio
                                                    , string strSettlementDate
                                                    , string strYield
                                                    , string strUnit
                                                    , string strCleanPrice
                                                    , string strGrossPrice
                                                    , string strNotional
                                                    , string strCCY
                                                    , string strPceFlag
                                                    , string strSettleFlag
                                                    , string strYeildType
                                                    , string strReportBy
                                                    , string strPurpose
                                                    , string strTerm
                                                    , string strRate
                                                    , string strTBMARemark
                                                    , string strRemark
                                                    , string strProductId)
        {
            //Validate business logics here
            //throw error to UI if fail validation
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn = null;
            DateTime dteTemp;
            Decimal decTemp;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp))
            {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;

            if (strCtpy == "null")
                throw this.CreateException(new Exception(), "Please input counterparty.");
            else
                trn.CTPY_ID = Guid.Parse(strCtpy);

            if (String.IsNullOrEmpty(strTradeDate))
                throw this.CreateException(new Exception(), "Please input trade date.");
            else if (!DateTime.TryParseExact(strTradeDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid trade date.");
            else
                trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);

            if (String.IsNullOrEmpty(strSettlementDate))
                throw this.CreateException(new Exception(), "Please input settlement date.");
            else if (!DateTime.TryParseExact(strSettlementDate, "dd/MM/yyyy", null, DateTimeStyles.None, out dteTemp))
                throw this.CreateException(new Exception(), "Invalid settlement date.");
            else
            {
                trn.MATURITY_DATE = DateTime.ParseExact(strSettlementDate, "dd/MM/yyyy", null);
                trn.START_DATE = trn.MATURITY_DATE;
            }

            if (strInstrument == "null")
                throw this.CreateException(new Exception(), "Please input instrument.");
            else
                trn.INSTRUMENT_ID = Guid.Parse(strInstrument);

            if (String.IsNullOrEmpty(strNotional))
                throw this.CreateException(new Exception(), "Please input notional amount.");
            else if (!Decimal.TryParse(strNotional, out decTemp))
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else if (Convert.ToDecimal(strNotional) <= 0)
                throw this.CreateException(new Exception(), "Invalid notional amount.");
            else
                trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional);

            if (strPortfolio == "-1")
                throw this.CreateException(new Exception(), "Please select portfolio.");
            else
                trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);

            if (trn.MATURITY_DATE < trn.TRADE_DATE)
            {
                throw this.CreateException(new Exception(), "Settlement date cannot be before trade date.");
            }
            if ((strPurpose.Trim() == TBMA_PURPOSE.FIN.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINB.ToString() || strPurpose.Trim() == TBMA_PURPOSE.FINP.ToString()) && (strTBMARemark.Trim() == string.Empty || strRate.Trim() == string.Empty || strTerm.Trim() == string.Empty))
            {
                throw this.CreateException(new Exception(), "Please input Term, Rate and Remark.");
            }
            if (lastrn != null) {
                if (strRemark == "")
                    throw this.CreateException(new Exception(), "Please input comment.");
                else trn.REMARK = strRemark;
            }
            trn.ID = Guid.NewGuid();
            trn.FLAG_SETTLE = strSettleFlag == "1" ? true : false;
            trn.FLAG_BUYSELL = strBuySell;
            trn.FIRST.CCY_ID = Guid.Parse(strCCY);
            trn.FIRST.RATE = Convert.ToDecimal(strYield);
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID;
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.SOURCE = SourceType.INT.ToString();
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == trn.TRADE_DATE);
            if (a == null)
            {
                var ccys = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                throw this.CreateException(new Exception(), "Error : There is no " + ccys.LABEL + " spot rate on " + strTradeDate + " trade date.");
            }
            trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
            trn.FLAG_PCE = strPceFlag == "1" ? true : false;
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();
            flow1.ID = Guid.NewGuid();
            flow1.DA_TRN_ID = trn.ID;
            flow1.FLAG_FIRST = true;
            flow1.FLOW_DATE = trn.MATURITY_DATE;
            flow1.FLOW_AMOUNT = trn.FLAG_BUYSELL == "B" ? -trn.FIRST.NOTIONAL : trn.FIRST.NOTIONAL;
            flow1.FLOW_AMOUNT_THB = trn.FLAG_BUYSELL == "B" ? -trn.NOTIONAL_THB : trn.NOTIONAL_THB;
            flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
            flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;
            trn.DA_TRN_FLOW.Add(flow1);

            DA_TMBA_EXTENSION tbma = new DA_TMBA_EXTENSION();
            tbma.ID = trn.ID;
            tbma.PURPOSE = strPurpose;
            tbma.YIELD_TYPE = strYeildType;
            tbma.CLEAN_PRICE = Convert.ToDecimal(strCleanPrice);
            tbma.GROSS_PRICE = Convert.ToDecimal(strGrossPrice);
            tbma.UNIT = Convert.ToInt32(strUnit);
            if (strTerm != string.Empty)
                tbma.TERM = Convert.ToInt32(strTerm);
            if (strRate != string.Empty)
                tbma.RATE = Convert.ToDecimal(strRate);
            if (strTBMARemark != string.Empty)
                tbma.REMARK = strTBMARemark;
            tbma.IS_REPORT_CLEAN = strReportBy == "0" ? true : false;

            if (lastrn != null)
            {
                tbma.SEND_DATE = lastrn.DA_TMBA_EXTENSION.SEND_DATE;
                tbma.SENDER_ID = lastrn.DA_TMBA_EXTENSION.SENDER_ID;
            }

            trn.DA_TMBA_EXTENSION = tbma;
            return trn;
        }
Ejemplo n.º 14
0
        public DA_TRN GenerateSwapTransactionObject(SessionInfo sessionInfo, string strTradeDate, string strInstrument, string strCtpy, string strPortfolio
															, string strEffDate, string strMatDate, string strNotional1
															, string strCCY1 , string strFFL1, string strFFix1, string strRate1, string strFreq1
															, string strNotional2, string strCCY2, string strFFL2, string strFFix2, string strRate2, string strFreq2
															, int intDaySpan,string strRemark, string strProductId)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
            DA_TRN trn = new DA_TRN();
            DA_TRN lastrn = null;
            Guid guTemp;
            if (Guid.TryParse(strProductId, out guTemp))
            {
                lastrn = new DA_TRN();
                lastrn = GetByID(guTemp);
            }
            trn.ID = Guid.NewGuid();
            trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
            trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
            trn.INSTRUMENT_ID = Guid.Parse(strInstrument);
            trn.CTPY_ID = Guid.Parse(strCtpy);
            trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
            trn.START_DATE = DateTime.ParseExact(strEffDate, "dd/MM/yyyy", null);
            trn.MATURITY_DATE = DateTime.ParseExact(strMatDate, "dd/MM/yyyy", null);
            trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional1);
            trn.SECOND.NOTIONAL  = Convert.ToDecimal(strNotional2);
            //Fix Currency Type
            trn.FIRST.CCY_ID =  Guid.Parse(strCCY1);
            trn.SECOND.CCY_ID= Guid.Parse(strCCY2);
            trn.FIRST.FLAG_PAYREC = "P";
            trn.FIRST.FLAG_FIXED = strFFL1 == "1" ? true : false;

            if (!trn.FIRST.FLAG_FIXED.Value)
            {
                trn.FIRST.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix1);
            }
            trn.FIRST.RATE = Convert.ToDecimal(strRate1);
            trn.FIRST.FREQTYPE_ID = Guid.Parse(strFreq1);
            trn.SECOND.FLAG_PAYREC = "R";
            trn.SECOND.FLAG_FIXED = strFFL2 == "1" ? true : false;

            if (!trn.SECOND.FLAG_FIXED.Value)
            {
                trn.SECOND.FIRSTFIXINGAMT = Convert.ToDecimal(strFFix2);
            }
            trn.SECOND.RATE = Convert.ToDecimal(strRate2);
            trn.SECOND.FREQTYPE_ID = Guid.Parse(strFreq2);

            if (lastrn != null)
            {
                if (strRemark == "")
                    throw this.CreateException(new Exception(), "Please input comment.");
                else trn.REMARK = strRemark;
            }
            trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.SWAP.ToString()).ID;
            trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
            trn.SOURCE = SourceType.INT.ToString();
            trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
            trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
            trn.FLAG_SETTLE = true;
            trn.LOG.INSERTDATE = DateTime.Now;
            trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
            var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
            var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB");
            var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB");
            var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
            var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
            var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
            if (firstRate == null || secondRate == null)
            {
                var ccylabel = ccys.Where(p => (p.ID == trn.FIRST.CCY_ID && firstRate == null) || (p.ID == trn.SECOND.CCY_ID && secondRate == null)).Select(p => p.LABEL);
                var strCCY = string.Join(" and ",ccylabel);
                throw this.CreateException(new Exception(), "Error : There is no " + strCCY + " spot rate.");
            }
            if (n1 != null)
                trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
            else if (n2 != null)
                trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
            else
            {
                if (Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                    trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                else
                    trn.NOTIONAL_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
            }
            GenerateCashFlows(sessionInfo, trn, intDaySpan, firstRate.RATE, secondRate.RATE);

            return trn;
        }
Ejemplo n.º 15
0
        public DA_TRN GenerateRepoTransactionObject(SessionInfo sessionInfo
														   , string strTradeDate
														   , string strBuySell
														   , string strInstrument
														   , string strCtpy
														   , string strPortfolio
														   , string strEffectiveDate
														   , string strMaturityDate
														   , string strNotional
														   , string strProductId
														   , string strRemark)
        {
            //Validate business logics here
             //throw error to UI if fail validation
             LookupBusiness _lookupBusiness = new LookupBusiness();
             DA_TRN trn = new DA_TRN();
             DA_TRN lastrn = null;
             Guid guTemp;
             if (Guid.TryParse(strProductId, out guTemp))
             {
                 lastrn = new DA_TRN();
                 lastrn = GetByID(guTemp);
             }
             trn.ID = Guid.NewGuid();
             trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
             trn.INT_DEAL_NO = lastrn == null ? null : lastrn.INT_DEAL_NO;
             trn.VERSION = lastrn == null ? 1 : lastrn.VERSION + 1;
             trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.REPO.ToString()).ID;
             trn.SOURCE = SourceType.INT.ToString();
             trn.CTPY_ID = Guid.Parse(strCtpy);
             trn.INSTRUMENT_ID = Guid.Parse(strInstrument);
             trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
             trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
             trn.START_DATE = DateTime.ParseExact(strEffectiveDate, "dd/MM/yyyy", null);
             trn.MATURITY_DATE = DateTime.ParseExact(strMaturityDate, "dd/MM/yyyy", null);
             trn.FLAG_BUYSELL = strBuySell;
             trn.FIRST.NOTIONAL = Convert.ToDecimal(strNotional);
             trn.FIRST.CCY_ID = _lookupBusiness.GetCurrencyAll().FirstOrDefault(p => p.LABEL == "THB").ID;
             trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
             trn.NOTIONAL_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
             trn.FLAG_SETTLE = false;

             if (lastrn != null)
             {
                 if (strRemark == "")
                     throw this.CreateException(new Exception(), "Please input comment.");
                 else trn.REMARK = strRemark;
             }
             trn.LOG.INSERTDATE = DateTime.Now;
             trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
             return trn;
        }
Ejemplo n.º 16
0
        public DA_TRN GenerateFXSwapTransactionObject2(SessionInfo sessionInfo, string strTradeDate, string strCtpy, string strPortfolio, string strCurrencyPair
																, string strContractCcy, string strCounterCcy, string strSpotRate
																, string strBSFar, string strSetDateFar, string strSwapPointFar
                                                                , string strContractAmtFar, string strCounterAmtFar, string strSpotDate, string strRemark, bool settleFlag, int Version)
        {
            LookupBusiness _lookupBusiness = new LookupBusiness();
             DA_TRN trn = new DA_TRN();

             trn.ID = Guid.NewGuid();
             trn.ENGINE_DATE = sessionInfo.Process.CurrentDate;
             //trn.INT_DEAL_NO = strDealNo;
             trn.SOURCE = SourceType.INT.ToString();
             trn.VERSION = Version;
             trn.PRODUCT_ID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL.Replace(" ", string.Empty) == ProductCode.FXSWAP.ToString()).ID;
             trn.CTPY_ID = Guid.Parse(strCtpy);
             trn.PORTFOLIO_ID = Guid.Parse(strPortfolio);
             trn.INSTRUMENT_ID = Guid.Parse(strCurrencyPair);
             trn.TRADE_DATE = DateTime.ParseExact(strTradeDate, "dd/MM/yyyy", null);
             trn.SPOT_DATE = DateTime.ParseExact(strSpotDate, "dd/MM/yyyy", null);

             //If settle after spot date (forward deal) then bucket is count from spot -> settlement date
             //else (O/N or T/N deal) no need to count bucket so start date will be null
             if (DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null) > trn.SPOT_DATE)
                 trn.START_DATE = trn.SPOT_DATE;
             else
                 trn.START_DATE = trn.TRADE_DATE;

             trn.MATURITY_DATE = DateTime.ParseExact(strSetDateFar, "dd/MM/yyyy", null);
             trn.FLAG_BUYSELL = strBSFar;
             trn.FLAG_NEARFAR = "F";
             trn.FIRST.NOTIONAL = trn.FLAG_BUYSELL == "B" ? Convert.ToDecimal(strContractAmtFar) : -Convert.ToDecimal(strContractAmtFar);
             trn.FIRST.CCY_ID = Guid.Parse(strContractCcy);
             trn.FIRST.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "R" : "P";
             trn.FIRST.RATE = Convert.ToDecimal(strSpotRate) + Convert.ToDecimal(strSwapPointFar);
             trn.FIRST.SWAP_POINT = Convert.ToDecimal(strSwapPointFar);
             trn.SECOND.NOTIONAL = trn.FLAG_BUYSELL == "B" ? -Convert.ToDecimal(strCounterAmtFar) : Convert.ToDecimal(strCounterAmtFar);
             trn.SECOND.CCY_ID = Guid.Parse(strCounterCcy);
             trn.SECOND.FLAG_PAYREC = trn.FLAG_BUYSELL == "B" ? "P" : "R";
             trn.LOG.INSERTDATE = DateTime.Now;
             trn.LOG.INSERTBYUSERID = sessionInfo.CurrentUserId;
             trn.STATUS_ID = _lookupBusiness.GetStatusAll().FirstOrDefault(p => p.LABEL == StatusCode.OPEN.ToString()).ID;
             trn.FLAG_SETTLE = !settleFlag;
             trn.REMARK = strRemark;
             var ccys = _lookupBusiness.GetCurrencyAll().AsQueryable();
             var n1 = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID && p.LABEL == "THB");
             var n2 = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID && p.LABEL == "THB");
             var spotrate = _lookupBusiness.GetSpotRateAll().AsQueryable();
             if (n1 != null)
                 trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value);
             else if (n2 != null)
                 trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value);
             else
             {
                 var firstRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 var secondRate = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);

                 if (firstRate != null && secondRate != null)
                 {
                     if (Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE) > Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE))
                         trn.NOTIONAL_THB = Math.Abs(trn.FIRST.NOTIONAL.Value * firstRate.RATE);
                     else
                         trn.NOTIONAL_THB = Math.Abs(trn.SECOND.NOTIONAL.Value * secondRate.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }
             }

             //StaticDataBusiness _staticdataBusiness = new StaticDataBusiness();
             //trn.KK_PCCF = _staticdataBusiness.GetFXPCCF(sessionInfo, trn);
             //trn.KK_CONTRIBUTE = Math.Abs(trn.NOTIONAL_THB.Value) * trn.KK_PCCF / 100;

             DA_TRN_CASHFLOW flow1 = new DA_TRN_CASHFLOW();

             flow1.ID = Guid.NewGuid();
             flow1.DA_TRN_ID = trn.ID;
             flow1.FLAG_FIRST = true;
             flow1.RATE = trn.FIRST.RATE + trn.FIRST.SWAP_POINT;
             flow1.FLOW_DATE = trn.MATURITY_DATE;
             flow1.FLOW_AMOUNT = trn.FIRST.NOTIONAL;
             if (n1 != null)
                 flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value);
             else
             {
                 var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.FIRST.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 if (a != null)
                 {
                     flow1.FLOW_AMOUNT_THB = Math.Ceiling(trn.FIRST.NOTIONAL.Value * a.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.FIRST.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }

             }
             flow1.LOG.INSERTDATE = trn.LOG.INSERTDATE;
             flow1.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

             DA_TRN_CASHFLOW flow2 = new DA_TRN_CASHFLOW();

             flow2.ID = Guid.NewGuid();
             flow2.DA_TRN_ID = trn.ID;
             flow2.FLAG_FIRST = false;
             flow2.FLOW_DATE = trn.MATURITY_DATE;
             flow2.FLOW_AMOUNT = trn.SECOND.NOTIONAL;
             if (n2 != null)
                 flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value);
             else
             {
                 var a = spotrate.FirstOrDefault(p => p.CURRENCY_ID == trn.SECOND.CCY_ID && p.PROC_DATE == sessionInfo.Process.CurrentDate);
                 if (a != null)
                 {
                     flow2.FLOW_AMOUNT_THB = Math.Ceiling(trn.SECOND.NOTIONAL.Value * a.RATE);
                 }
                 else
                 {
                     var ccylabel = ccys.FirstOrDefault(p => p.ID == trn.SECOND.CCY_ID);
                     throw this.CreateException(new Exception(), "Error : There is no " + ccylabel.LABEL + " spot rate.");
                 }
             }

             flow2.LOG.INSERTDATE = trn.LOG.INSERTDATE;
             flow2.LOG.INSERTBYUSERID = trn.LOG.INSERTBYUSERID;

             trn.DA_TRN_FLOW.Add(flow1);
             trn.DA_TRN_FLOW.Add(flow2);
             return trn;
        }