Ejemplo n.º 1
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.º 2
0
 public MemoryLookupValues()
 {
     Frequencies = _lookupBusiness.GetFreqTypeAll();
     Products    = _lookupBusiness.GetProductAll();
     Statuses    = _lookupBusiness.GetStatusAll();
     Portfolios  = _lookupBusiness.GetPortfolioAll();
     Limits      = _lookupBusiness.GetLimitAll();
     Currencies  = _lookupBusiness.GetCurrencyAll();
 }
Ejemplo n.º 3
0
        public static object GetCurrencyOptions(SessionInfo sessioninfo)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var currencies     = _lookupBusiness.GetCurrencyAll().Select(c => new { DisplayText = c.LABEL, Value = c.ID.ToString() });
                var currenciesList = currencies.ToList();

                currenciesList.Insert(0, new { DisplayText = "Please select", Value = string.Empty });
                //Return result to jTable
                return(new { Result = "OK", Options = currenciesList });
            }
            catch (Exception ex)
            {
                return(new { Result = "ERROR", Message = ex.Message });
            }
        }
Ejemplo n.º 4
0
        public static List<DealViewModel> GetDealInquiryData(SessionInfo sessioninfo
                                                            , string strDMKNo
                                                            , string strOPICNo
                                                            , string strProduct
                                                            , string strCtpy
                                                            , string strPortfolio
                                                            , string strTradeDate
                                                            , string strEffDate
                                                            , string strMatDate
                                                            , string strInstrument
                                                            , string strUser
                                                            , string strStatus
                                                            , string strOverStatus
                                                            , string strProcDate
                                                            , string strSettleStatus)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            UserBusiness _userBusiness = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();

            //Get data from database
            List<DA_TRN> trns = _dealBusiness.GetDealInquiryByFilter(sessioninfo
                                                                        , strDMKNo
                                                                        , strOPICNo
                                                                        , strProduct
                                                                        , strCtpy
                                                                        , strPortfolio
                                                                        , strTradeDate
                                                                        , strEffDate
                                                                        , strMatDate
                                                                        , strInstrument
                                                                        , strUser
                                                                        , strStatus
                                                                        , strProcDate);
            //Get user data
            List<MA_USER> users = _userBusiness.GetAll();
            List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();
            List<MA_FREQ_TYPE> freq = _lookupBusiness.GetFreqTypeAll();

            return (from t in trns
                         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 tempccy2 in ccys on t.SECOND.CCY_ID equals tempccy2.ID into ljccy2
                         from ccy2 in ljccy2.DefaultIfEmpty()
                         join f1 in freq on t.FIRST.FREQTYPE_ID equals f1.ID into fg1
                         from subfg1 in fg1.DefaultIfEmpty()
                         join f2 in freq on t.SECOND.FREQTYPE_ID equals f2.ID into fg2
                         from subfg2 in fg2.DefaultIfEmpty()
                         select new DealViewModel
                         {
                             ID = t.ID,
                             EntryDate = t.LOG.INSERTDATE,
                             DMK_NO = t.INT_DEAL_NO,
                             OPICS_NO = t.EXT_DEAL_NO,
                             TradeDate = t.TRADE_DATE.Value,
                             EffectiveDate = t.START_DATE,
                             Instrument = t.MA_INSRUMENT.LABEL,
                             MaturityDate = t.MATURITY_DATE,
                             BuySell = t.FLAG_BUYSELL,
                             Product = t.MA_PRODUCT.LABEL,
                             Portfolio = t.MA_PORTFOLIO.LABEL,
                             Counterparty = t.MA_COUTERPARTY.SNAME,
                             Notional1 = t.FIRST.NOTIONAL,
                             PayRec1 = t.FIRST.FLAG_PAYREC,
                             FixedFloat1 = !t.FIRST.FLAG_FIXED.HasValue ? null : t.FIRST.FLAG_FIXED.Value ? "FIXED" : "FLOAT",
                             Rate1 = t.FIRST.RATE,
                             Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                             SwapPoint1 = t.FIRST.SWAP_POINT,
                             Notional2 = t.SECOND.NOTIONAL,
                             PayRec2 = t.SECOND.FLAG_PAYREC,
                             FixedFloat2 = !t.SECOND.FLAG_FIXED.HasValue ? null : t.SECOND.FLAG_FIXED == true ? "FIXED" : "FLOAT",
                             Rate2 = t.SECOND.RATE,
                             Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                             SwapPoint2 = t.SECOND.SWAP_POINT,
                             Status = t.MA_STATUS.LABEL,
                             KKContribute = t.KK_CONTRIBUTE,
                             BotContribute = t.BOT_CONTRIBUTE                             ,
                             LimitOverwrite = string.IsNullOrEmpty(t.OVER_APPROVER) ? "No" : t.OVER_AMOUNT > 0 && t.OVER_SETTL_AMOUNT > 0 ? "Yes" : t.OVER_AMOUNT > 0 ? "PCE" : "SET",
                             LimitApprover = t.OVER_APPROVER,
                             Trader = inputuser != null ? inputuser.USERCODE : null,
                             Remark = t.REMARK,
                             CCY1 = ccy1 != null ? ccy1.LABEL : null,
                             CCY2 = ccy2 != null ? ccy2.LABEL : null,
                             SettlementLimit = !t.FLAG_SETTLE.HasValue || !t.FLAG_SETTLE.Value ? "No" : "Yes",
                             Freq1 = subfg1 != null ? subfg1.USERCODE : null,
                             Freq2 = subfg2 != null ? subfg2.USERCODE : null,
                             OpicsTrader = t.INSERT_BY_EXT,
                             TBMA_SENT = t.DA_TMBA_EXTENSION == null ? "N/A" : t.DA_TMBA_EXTENSION.SEND_DATE != null ? "Yes" : "No"
                         }).Where(p => p.LimitOverwrite == strOverStatus || String.IsNullOrEmpty(strOverStatus))
                         .Where(t => t.SettlementLimit == strSettleStatus || string.IsNullOrEmpty(strSettleStatus)).ToList();
        }
Ejemplo n.º 5
0
        public static List<DealViewModel> GetLimitOverwriteData(SessionInfo sessioninfo, string strReportDate, string strCtpy)
        {
            ReportBusiness _reportBusiness = new ReportBusiness();
            UserBusiness _userBusiness = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();
            char[] trimchar = { '/' };
            List<DA_TRN> trns =  _reportBusiness.GetLimitOverwriteReport(sessioninfo,strReportDate,strCtpy);
            List<MA_USER> users = _userBusiness.GetAll();
            List<MA_CURRENCY> ccys =  _lookupBusiness.GetCurrencyAll();
            var query = (from t in trns
                            join user in users on t.LOG.INSERTBYUSERID equals user.ID into ljuser
                            join ccy in ccys on t.FIRST.CCY_ID equals ccy.ID
                            from inputuser in ljuser.DefaultIfEmpty()
                            select new DealViewModel
                            {
                                EngineDate = t.ENGINE_DATE,
                                Trader = inputuser != null ? inputuser.USERCODE : "",
                                LimitApprover = t.OVER_APPROVER,
                                Remark = t.OVER_COMMENT,
                                DMK_NO = t.INT_DEAL_NO,
                                Counterparty = t.MA_COUTERPARTY.SNAME,
                                Product = t.MA_PRODUCT.LABEL,
                                Instrument = t.MA_INSRUMENT.LABEL,
                                Notional1 = t.FIRST.NOTIONAL,
                                CCY1 = ccy.LABEL,
                                KKContribute = t.KK_CONTRIBUTE,
                                LimitOverwrite = string.Concat(t.OVER_AMOUNT > 0 ? "PCE/" : "", t.OVER_SETTL_AMOUNT > 0 ? "SET/" : "", t.OVER_COUNTRY_AMOUNT > 0 ? "COUNTRY/" : "").TrimEnd(trimchar),
                                LimitOverAmount = ((t.OVER_AMOUNT > 0 ? "PCE: " + t.OVER_AMOUNT.Value.ToString("#,##0") : string.Empty)
                                                    + (t.OVER_SETTL_AMOUNT > 0 ? " SET: " + t.OVER_SETTL_AMOUNT.Value.ToString("#,##0") : string.Empty)
                                                    + (t.OVER_COUNTRY_AMOUNT > 0 ? " COUNTRY: " + t.OVER_COUNTRY_AMOUNT.Value.ToString("#,##0") : string.Empty)).Trim()
                            }).OrderBy(t=>t.EngineDate).ToList();

            return query;
        }
Ejemplo n.º 6
0
        public static List<DealViewModel> GetPCEDetailData(SessionInfo sessioninfo, string strReportDate, string strCtpy, string strProduct, string strSource)
        {
            try
            {
                ReportBusiness _reportBusiness = new ReportBusiness();
                LookupBusiness _lookupBusiness = new LookupBusiness();
                CountryBusiness _countryBusiness = new CountryBusiness();
                CounterpartyBusiness _ctpyBusiness = new CounterpartyBusiness();

                List<DA_TRN> trns = _reportBusiness.GetPCEDetailReport(sessioninfo, strReportDate, strCtpy, strProduct, strSource);
                List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();
                List<MA_CSA_PRODUCT> csaproducts = _ctpyBusiness.GetCSAProductAll(sessioninfo);
                List<MA_COUNTRY> country = _countryBusiness.GetCountryAll();

                var report = (from trn in trns
                              join ct in country on trn.MA_COUTERPARTY.COUNTRY_ID equals ct.ID
                              join ccy1 in ccys on trn.FIRST.CCY_ID equals ccy1.ID into ljccy1
                              from subccy1 in ljccy1.DefaultIfEmpty()
                              join ccy2 in ccys on trn.SECOND.CCY_ID equals ccy2.ID into ljccy2
                              from subccy2 in ljccy2.DefaultIfEmpty()
                              join csaproduct in csaproducts on new { CTPY_ID = trn.CTPY_ID, PRODUCT_ID = trn.PRODUCT_ID.Value } equals new { CTPY_ID = csaproduct.CSA_AGREEMENT_ID, PRODUCT_ID = csaproduct.PRODUCT_ID } into ljcsa
                              from subcsa in ljcsa.DefaultIfEmpty()
                              select new DealViewModel
                              {
                                  EngineDate = trn.ENGINE_DATE,
                                  DMK_NO = trn.INT_DEAL_NO,
                                  OPICS_NO = trn.EXT_DEAL_NO,
                                  Source = trn.SOURCE == "INT" ? "DMK" : "OPICS",
                                  Product = trn.MA_PRODUCT.LABEL,
                                  Portfolio = trn.MA_PORTFOLIO.LABEL,
                                  TradeDate = trn.TRADE_DATE.Value,
                                  EffectiveDate = trn.START_DATE,
                                  MaturityDate = trn.MATURITY_DATE,
                                  Instrument = trn.MA_INSRUMENT.LABEL,
                                  Counterparty = trn.MA_COUTERPARTY.SNAME,
                                  Notional1 = trn.FIRST.NOTIONAL,
                                  Notional2 = trn.SECOND.NOTIONAL,
                                  FixedFloat1 = !trn.FIRST.FLAG_FIXED.HasValue ? "-" : trn.FIRST.FLAG_FIXED.Value ? trn.FIRST.FLAG_PAYREC + "-FIXED" : trn.FIRST.FLAG_PAYREC + "-FLOAT",
                                  FixedFloat2 = !trn.SECOND.FLAG_FIXED.HasValue ? "-" : trn.SECOND.FLAG_FIXED.Value ? trn.SECOND.FLAG_PAYREC + "-FIXED" : trn.SECOND.FLAG_PAYREC + "-FLOAT",
                                  KKPCCF = trn.KK_PCCF,
                                  KKContribute = trn.KK_CONTRIBUTE,
                                  CCY1 = subccy1 != null ? subccy1.LABEL : "-",
                                  CCY2 = subccy2 != null ? subccy2.LABEL : "-",
                                  CSA = subcsa != null ? "Yes" : "No",
                                  Country = ct.LABEL
                              }).OrderBy(p => p.DMK_NO).ToList();

                return report;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        public static List <DealViewModel> GetDealInquiryData(SessionInfo sessioninfo
                                                              , string strDMKNo
                                                              , string strOPICNo
                                                              , string strProduct
                                                              , string strCtpy
                                                              , string strPortfolio
                                                              , string strTradeDate
                                                              , string strEffDate
                                                              , string strMatDate
                                                              , string strInstrument
                                                              , string strUser
                                                              , string strStatus
                                                              , string strOverStatus
                                                              , string strProcDate
                                                              , string strSettleStatus)
        {
            DealBusiness   _dealBusiness   = new DealBusiness();
            UserBusiness   _userBusiness   = new UserBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();

            //Get data from database
            List <DA_TRN> trns = _dealBusiness.GetDealInquiryByFilter(sessioninfo
                                                                      , strDMKNo
                                                                      , strOPICNo
                                                                      , strProduct
                                                                      , strCtpy
                                                                      , strPortfolio
                                                                      , strTradeDate
                                                                      , strEffDate
                                                                      , strMatDate
                                                                      , strInstrument
                                                                      , strUser
                                                                      , strStatus
                                                                      , strProcDate);
            //Get user data
            List <MA_USER>      users = _userBusiness.GetAll();
            List <MA_CURRENCY>  ccys  = _lookupBusiness.GetCurrencyAll();
            List <MA_FREQ_TYPE> freq  = _lookupBusiness.GetFreqTypeAll();

            return((from t in trns
                    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 tempccy2 in ccys on t.SECOND.CCY_ID equals tempccy2.ID into ljccy2
                    from ccy2 in ljccy2.DefaultIfEmpty()
                    join f1 in freq on t.FIRST.FREQTYPE_ID equals f1.ID into fg1
                    from subfg1 in fg1.DefaultIfEmpty()
                    join f2 in freq on t.SECOND.FREQTYPE_ID equals f2.ID into fg2
                    from subfg2 in fg2.DefaultIfEmpty()
                    select new DealViewModel
            {
                ID = t.ID,
                EntryDate = t.LOG.INSERTDATE,
                DMK_NO = t.INT_DEAL_NO,
                OPICS_NO = t.EXT_DEAL_NO,
                TradeDate = t.TRADE_DATE.Value,
                EffectiveDate = t.START_DATE,
                Instrument = t.MA_INSRUMENT.LABEL,
                MaturityDate = t.MATURITY_DATE,
                BuySell = t.FLAG_BUYSELL,
                Product = t.MA_PRODUCT.LABEL,
                Portfolio = t.MA_PORTFOLIO.LABEL,
                Counterparty = t.MA_COUTERPARTY.SNAME,
                Notional1 = t.FIRST.NOTIONAL,
                PayRec1 = t.FIRST.FLAG_PAYREC,
                FixedFloat1 = !t.FIRST.FLAG_FIXED.HasValue ? null : t.FIRST.FLAG_FIXED.Value ? "FIXED" : "FLOAT",
                Rate1 = t.FIRST.RATE,
                Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                SwapPoint1 = t.FIRST.SWAP_POINT,
                Notional2 = t.SECOND.NOTIONAL,
                PayRec2 = t.SECOND.FLAG_PAYREC,
                FixedFloat2 = !t.SECOND.FLAG_FIXED.HasValue ? null : t.SECOND.FLAG_FIXED == true ? "FIXED" : "FLOAT",
                Rate2 = t.SECOND.RATE,
                Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                SwapPoint2 = t.SECOND.SWAP_POINT,
                Status = t.MA_STATUS.LABEL,
                KKContribute = t.KK_CONTRIBUTE,
                BotContribute = t.BOT_CONTRIBUTE,
                LimitOverwrite = string.IsNullOrEmpty(t.OVER_APPROVER) ? "No" : t.OVER_AMOUNT > 0 && t.OVER_SETTL_AMOUNT > 0 ? "Yes" : t.OVER_AMOUNT > 0 ? "PCE" : "SET",
                LimitApprover = t.OVER_APPROVER,
                Trader = inputuser != null ? inputuser.USERCODE : null,
                Remark = t.REMARK,
                CCY1 = ccy1 != null ? ccy1.LABEL : null,
                CCY2 = ccy2 != null ? ccy2.LABEL : null,
                SettlementLimit = !t.FLAG_SETTLE.HasValue || !t.FLAG_SETTLE.Value ? "No" : "Yes",
                Freq1 = subfg1 != null ? subfg1.USERCODE : null,
                Freq2 = subfg2 != null ? subfg2.USERCODE : null,
                OpicsTrader = t.INSERT_BY_EXT,
                TBMA_SENT = t.DA_TMBA_EXTENSION == null ? "N/A" : t.DA_TMBA_EXTENSION.SEND_DATE != null ? "Yes" : "No"
            }).Where(p => p.LimitOverwrite == strOverStatus || String.IsNullOrEmpty(strOverStatus))
                   .Where(t => t.SettlementLimit == strSettleStatus || string.IsNullOrEmpty(strSettleStatus)).ToList());
        }
Ejemplo n.º 8
0
        public static object GetCurrencyOptions(SessionInfo sessioninfo)
        {
            try
            {
                LookupBusiness _lookupBusiness = new LookupBusiness();
                //Get data from database
                var currencies = _lookupBusiness.GetCurrencyAll().Select(c => new { DisplayText = c.LABEL, Value = c.ID.ToString() });
                var currenciesList = currencies.ToList();

                currenciesList.Insert(0, new { DisplayText = "Please select", Value = string.Empty });
                //Return result to jTable
                return new { Result = "OK", Options = currenciesList };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }
Ejemplo n.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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;
        }
Ejemplo n.º 15
0
        public static object GetDealByProcessDateStatusCode(SessionInfo sessioninfo, DateTime processdate, StatusCode statuscode, int startIndex, int count, string sorting)
        {
            DealBusiness _dealBusiness = new DealBusiness();
            OpicsBusiness _opicsBusiness = new OpicsBusiness();
            LookupBusiness _lookupBusiness = new LookupBusiness();
            List<DA_TRN> deals = null;
            List<DA_TRN> dealExts = null;
            List<DEALModel> opicdeals = null;

            try
            {
                //Get data from database
                if (statuscode == StatusCode.MATCHED)
                {
                    LoggingHelper.Debug("Get DMK Deal is matched on " + processdate.ToString());

                    deals = _dealBusiness.GetDealByProcessDate(processdate, StatusCode.MATCHED);
                    dealExts = _dealBusiness.GetImportedDealsByProcessDate(sessioninfo.Process.NextDate);

                }
                else
                {
                    LoggingHelper.Debug("Get DMK Deal is not matched on " + processdate.ToString());
                    //Get data from database
                    opicdeals = _opicsBusiness.GetOPICSDealExternal(processdate);

                    //auto match with OPICS deal
                    AutoMatchAndUpdateDeals(sessioninfo, processdate, opicdeals, out deals);
                }

                if (dealExts == null)
                    dealExts = new List<DA_TRN>();

                List<MA_FREQ_TYPE> freq = _lookupBusiness.GetFreqTypeAll();
                List<MA_CURRENCY> ccys = _lookupBusiness.GetCurrencyAll();

                //Sorting
                string[] sortsp = sorting.Split(' ');
                List<DealViewModel> dealviews = (from t in deals
                                                 join p in dealExts on new { t.INT_DEAL_NO, t.FLAG_NEARFAR } equals new { p.INT_DEAL_NO, p.FLAG_NEARFAR } into ps
                                                 join f1 in freq on t.FIRST.FREQTYPE_ID equals f1.ID into fg1
                                                 from subfg1 in fg1.DefaultIfEmpty()
                                                 join f2 in freq on t.SECOND.FREQTYPE_ID equals f2.ID into fg2
                                                 from subfg2 in fg2.DefaultIfEmpty()
                                                 join tempccy1 in ccys on t.FIRST.CCY_ID equals tempccy1.ID into ljccy1
                                                 from ccy1 in ljccy1.DefaultIfEmpty()
                                                 join tempccy2 in ccys on t.SECOND.CCY_ID equals tempccy2.ID into ljccy2
                                                 from ccy2 in ljccy2.DefaultIfEmpty()
                                                 where t.MA_STATUS.LABEL.Contains(statuscode.ToString()) && t.MATURITY_DATE.HasValue ? t.MATURITY_DATE.Value > sessioninfo.Process.CurrentDate : true
                                                 select new DealViewModel
                                                 {
                                                     ID = t.ID,
                                                     EntryDate = t.LOG.INSERTDATE,
                                                     DMK_NO = t.INT_DEAL_NO,
                                                     OPICS_NO = ps == null ? t.EXT_DEAL_NO : string.Join(",", ps.Select(i => i.EXT_DEAL_NO)),
                                                     TradeDate = t.TRADE_DATE.Value,
                                                     EffectiveDate = t.START_DATE,
                                                     Instrument = t.MA_INSRUMENT.LABEL,
                                                     MaturityDate = t.MATURITY_DATE.HasValue ? t.MATURITY_DATE : null,
                                                     BuySell = t.FLAG_BUYSELL,
                                                     Product = t.MA_PRODUCT.LABEL,
                                                     Portfolio = t.MA_PORTFOLIO.LABEL,
                                                     Counterparty = t.MA_COUTERPARTY.SNAME,
                                                     Notional1 = t.FIRST.NOTIONAL,
                                                     PayRec1 = t.FIRST.FLAG_PAYREC,
                                                     FixedFloat1 = !t.FIRST.FLAG_FIXED.HasValue ? null : t.FIRST.FLAG_FIXED == true ? "FIXED" : "FLOAT",
                                                     Fixing1 = t.FIRST.FIRSTFIXINGAMT,
                                                     Rate1 = t.FIRST.RATE,
                                                     SwapPoint1 = t.FIRST.SWAP_POINT,
                                                     Notional2 = t.SECOND.NOTIONAL,
                                                     PayRec2 = t.SECOND.FLAG_PAYREC,
                                                     FixedFloat2 = !t.SECOND.FLAG_FIXED.HasValue ? null : t.SECOND.FLAG_FIXED == true ? "FIXED" : "FLOAT",
                                                     Fixing2 = t.SECOND.FIRSTFIXINGAMT,
                                                     Rate2 = t.SECOND.RATE,
                                                     SwapPoint2 = t.SECOND.SWAP_POINT,
                                                     Status = t.MA_STATUS.LABEL,
                                                     KKContribute = t.KK_CONTRIBUTE,
                                                     BotContribute = t.BOT_CONTRIBUTE,
                                                     Remark = t.REMARK,
                                                     Freq1 = subfg1 != null ? subfg1.USERCODE : null,
                                                     Freq2 = subfg2 != null ? subfg2.USERCODE : null,
                                                     CCY1 = ccy1 != null ? ccy1.LABEL : null,
                                                     CCY2 = ccy2 != null ? ccy2.LABEL : null
                                                 }).AsQueryable().OrderBy(sortsp[0], sortsp[1]).ToList();

                //Return result to jTable
                return new
                {
                    Result = "OK",
                    Records = dealviews.Count > 0 ? dealviews.Skip(startIndex).Take(count).ToList() : dealviews,
                    TotalRecordCount = dealviews.Count
                };
            }
            catch (Exception ex)
            {
                return new { Result = "ERROR", Message = ex.Message };
            }
        }